root / hw / sh_intc.c @ 979ba184
History | View | Annotate | Download (11.9 kB)
1 | 80f515e6 | balrog | /*
|
---|---|---|---|
2 | 80f515e6 | balrog | * SuperH interrupt controller module
|
3 | 80f515e6 | balrog | *
|
4 | 80f515e6 | balrog | * Copyright (c) 2007 Magnus Damm
|
5 | 80f515e6 | balrog | * Based on sh_timer.c and arm_timer.c by Paul Brook
|
6 | 80f515e6 | balrog | * Copyright (c) 2005-2006 CodeSourcery.
|
7 | 80f515e6 | balrog | *
|
8 | 80f515e6 | balrog | * This code is licenced under the GPL.
|
9 | 80f515e6 | balrog | */
|
10 | 80f515e6 | balrog | |
11 | 80f515e6 | balrog | #include "sh_intc.h" |
12 | 87ecb68b | pbrook | #include "hw.h" |
13 | 87ecb68b | pbrook | #include "sh.h" |
14 | 80f515e6 | balrog | |
15 | 80f515e6 | balrog | //#define DEBUG_INTC
|
16 | e96e2044 | ths | //#define DEBUG_INTC_SOURCES
|
17 | 80f515e6 | balrog | |
18 | 80f515e6 | balrog | #define INTC_A7(x) ((x) & 0x1fffffff) |
19 | 80f515e6 | balrog | |
20 | e96e2044 | ths | void sh_intc_toggle_source(struct intc_source *source, |
21 | e96e2044 | ths | int enable_adj, int assert_adj) |
22 | e96e2044 | ths | { |
23 | e96e2044 | ths | int enable_changed = 0; |
24 | e96e2044 | ths | int pending_changed = 0; |
25 | e96e2044 | ths | int old_pending;
|
26 | e96e2044 | ths | |
27 | e96e2044 | ths | if ((source->enable_count == source->enable_max) && (enable_adj == -1)) |
28 | e96e2044 | ths | enable_changed = -1;
|
29 | e96e2044 | ths | |
30 | e96e2044 | ths | source->enable_count += enable_adj; |
31 | e96e2044 | ths | |
32 | e96e2044 | ths | if (source->enable_count == source->enable_max)
|
33 | e96e2044 | ths | enable_changed = 1;
|
34 | e96e2044 | ths | |
35 | e96e2044 | ths | source->asserted += assert_adj; |
36 | e96e2044 | ths | |
37 | e96e2044 | ths | old_pending = source->pending; |
38 | e96e2044 | ths | source->pending = source->asserted && |
39 | e96e2044 | ths | (source->enable_count == source->enable_max); |
40 | e96e2044 | ths | |
41 | e96e2044 | ths | if (old_pending != source->pending)
|
42 | e96e2044 | ths | pending_changed = 1;
|
43 | e96e2044 | ths | |
44 | e96e2044 | ths | if (pending_changed) {
|
45 | e96e2044 | ths | if (source->pending) {
|
46 | e96e2044 | ths | source->parent->pending++; |
47 | e96e2044 | ths | if (source->parent->pending == 1) |
48 | e96e2044 | ths | cpu_interrupt(first_cpu, CPU_INTERRUPT_HARD); |
49 | e96e2044 | ths | } |
50 | e96e2044 | ths | else {
|
51 | e96e2044 | ths | source->parent->pending--; |
52 | e96e2044 | ths | if (source->parent->pending == 0) |
53 | e96e2044 | ths | cpu_reset_interrupt(first_cpu, CPU_INTERRUPT_HARD); |
54 | e96e2044 | ths | } |
55 | e96e2044 | ths | } |
56 | e96e2044 | ths | |
57 | e96e2044 | ths | if (enable_changed || assert_adj || pending_changed) {
|
58 | e96e2044 | ths | #ifdef DEBUG_INTC_SOURCES
|
59 | e96e2044 | ths | printf("sh_intc: (%d/%d/%d/%d) interrupt source 0x%x %s%s%s\n",
|
60 | e96e2044 | ths | source->parent->pending, |
61 | e96e2044 | ths | source->asserted, |
62 | e96e2044 | ths | source->enable_count, |
63 | e96e2044 | ths | source->enable_max, |
64 | e96e2044 | ths | source->vect, |
65 | e96e2044 | ths | source->asserted ? "asserted " :
|
66 | e96e2044 | ths | assert_adj ? "deasserted" : "", |
67 | e96e2044 | ths | enable_changed == 1 ? "enabled " : |
68 | e96e2044 | ths | enable_changed == -1 ? "disabled " : "", |
69 | e96e2044 | ths | source->pending ? "pending" : ""); |
70 | e96e2044 | ths | #endif
|
71 | e96e2044 | ths | } |
72 | e96e2044 | ths | } |
73 | e96e2044 | ths | |
74 | b79e1752 | aurel32 | static void sh_intc_set_irq (void *opaque, int n, int level) |
75 | 96e2fc41 | aurel32 | { |
76 | 96e2fc41 | aurel32 | struct intc_desc *desc = opaque;
|
77 | 96e2fc41 | aurel32 | struct intc_source *source = &(desc->sources[n]);
|
78 | 96e2fc41 | aurel32 | |
79 | 4e7ed2d1 | aurel32 | if (level && !source->asserted)
|
80 | 4e7ed2d1 | aurel32 | sh_intc_toggle_source(source, 0, 1); |
81 | 4e7ed2d1 | aurel32 | else if (!level && source->asserted) |
82 | 4e7ed2d1 | aurel32 | sh_intc_toggle_source(source, 0, -1); |
83 | 96e2fc41 | aurel32 | } |
84 | 96e2fc41 | aurel32 | |
85 | e96e2044 | ths | int sh_intc_get_pending_vector(struct intc_desc *desc, int imask) |
86 | e96e2044 | ths | { |
87 | e96e2044 | ths | unsigned int i; |
88 | e96e2044 | ths | |
89 | e96e2044 | ths | /* slow: use a linked lists of pending sources instead */
|
90 | e96e2044 | ths | /* wrong: take interrupt priority into account (one list per priority) */
|
91 | e96e2044 | ths | |
92 | e96e2044 | ths | if (imask == 0x0f) { |
93 | e96e2044 | ths | return -1; /* FIXME, update code to include priority per source */ |
94 | e96e2044 | ths | } |
95 | e96e2044 | ths | |
96 | e96e2044 | ths | for (i = 0; i < desc->nr_sources; i++) { |
97 | e96e2044 | ths | struct intc_source *source = desc->sources + i;
|
98 | e96e2044 | ths | |
99 | e96e2044 | ths | if (source->pending) {
|
100 | e96e2044 | ths | #ifdef DEBUG_INTC_SOURCES
|
101 | e96e2044 | ths | printf("sh_intc: (%d) returning interrupt source 0x%x\n",
|
102 | e96e2044 | ths | desc->pending, source->vect); |
103 | e96e2044 | ths | #endif
|
104 | e96e2044 | ths | return source->vect;
|
105 | e96e2044 | ths | } |
106 | e96e2044 | ths | } |
107 | e96e2044 | ths | |
108 | e96e2044 | ths | assert(0);
|
109 | e96e2044 | ths | } |
110 | e96e2044 | ths | |
111 | 80f515e6 | balrog | #define INTC_MODE_NONE 0 |
112 | 80f515e6 | balrog | #define INTC_MODE_DUAL_SET 1 |
113 | 80f515e6 | balrog | #define INTC_MODE_DUAL_CLR 2 |
114 | 80f515e6 | balrog | #define INTC_MODE_ENABLE_REG 3 |
115 | 80f515e6 | balrog | #define INTC_MODE_MASK_REG 4 |
116 | 80f515e6 | balrog | #define INTC_MODE_IS_PRIO 8 |
117 | 80f515e6 | balrog | |
118 | 80f515e6 | balrog | static unsigned int sh_intc_mode(unsigned long address, |
119 | 80f515e6 | balrog | unsigned long set_reg, unsigned long clr_reg) |
120 | 80f515e6 | balrog | { |
121 | 80f515e6 | balrog | if ((address != INTC_A7(set_reg)) &&
|
122 | 80f515e6 | balrog | (address != INTC_A7(clr_reg))) |
123 | 80f515e6 | balrog | return INTC_MODE_NONE;
|
124 | 80f515e6 | balrog | |
125 | 80f515e6 | balrog | if (set_reg && clr_reg) {
|
126 | 80f515e6 | balrog | if (address == INTC_A7(set_reg))
|
127 | 80f515e6 | balrog | return INTC_MODE_DUAL_SET;
|
128 | 80f515e6 | balrog | else
|
129 | 80f515e6 | balrog | return INTC_MODE_DUAL_CLR;
|
130 | 80f515e6 | balrog | } |
131 | 80f515e6 | balrog | |
132 | 80f515e6 | balrog | if (set_reg)
|
133 | 80f515e6 | balrog | return INTC_MODE_ENABLE_REG;
|
134 | 80f515e6 | balrog | else
|
135 | 80f515e6 | balrog | return INTC_MODE_MASK_REG;
|
136 | 80f515e6 | balrog | } |
137 | 80f515e6 | balrog | |
138 | 80f515e6 | balrog | static void sh_intc_locate(struct intc_desc *desc, |
139 | 80f515e6 | balrog | unsigned long address, |
140 | 80f515e6 | balrog | unsigned long **datap, |
141 | 80f515e6 | balrog | intc_enum **enums, |
142 | 80f515e6 | balrog | unsigned int *first, |
143 | 80f515e6 | balrog | unsigned int *width, |
144 | 80f515e6 | balrog | unsigned int *modep) |
145 | 80f515e6 | balrog | { |
146 | 80f515e6 | balrog | unsigned int i, mode; |
147 | 80f515e6 | balrog | |
148 | 80f515e6 | balrog | /* this is slow but works for now */
|
149 | 80f515e6 | balrog | |
150 | 80f515e6 | balrog | if (desc->mask_regs) {
|
151 | 80f515e6 | balrog | for (i = 0; i < desc->nr_mask_regs; i++) { |
152 | 80f515e6 | balrog | struct intc_mask_reg *mr = desc->mask_regs + i;
|
153 | 80f515e6 | balrog | |
154 | 80f515e6 | balrog | mode = sh_intc_mode(address, mr->set_reg, mr->clr_reg); |
155 | 80f515e6 | balrog | if (mode == INTC_MODE_NONE)
|
156 | 80f515e6 | balrog | continue;
|
157 | 80f515e6 | balrog | |
158 | 80f515e6 | balrog | *modep = mode; |
159 | 80f515e6 | balrog | *datap = &mr->value; |
160 | 80f515e6 | balrog | *enums = mr->enum_ids; |
161 | 80f515e6 | balrog | *first = mr->reg_width - 1;
|
162 | 80f515e6 | balrog | *width = 1;
|
163 | 80f515e6 | balrog | return;
|
164 | 80f515e6 | balrog | } |
165 | 80f515e6 | balrog | } |
166 | 80f515e6 | balrog | |
167 | 80f515e6 | balrog | if (desc->prio_regs) {
|
168 | 80f515e6 | balrog | for (i = 0; i < desc->nr_prio_regs; i++) { |
169 | 80f515e6 | balrog | struct intc_prio_reg *pr = desc->prio_regs + i;
|
170 | 80f515e6 | balrog | |
171 | 80f515e6 | balrog | mode = sh_intc_mode(address, pr->set_reg, pr->clr_reg); |
172 | 80f515e6 | balrog | if (mode == INTC_MODE_NONE)
|
173 | 80f515e6 | balrog | continue;
|
174 | 80f515e6 | balrog | |
175 | 80f515e6 | balrog | *modep = mode | INTC_MODE_IS_PRIO; |
176 | 80f515e6 | balrog | *datap = &pr->value; |
177 | 80f515e6 | balrog | *enums = pr->enum_ids; |
178 | 80f515e6 | balrog | *first = (pr->reg_width / pr->field_width) - 1;
|
179 | 80f515e6 | balrog | *width = pr->field_width; |
180 | 80f515e6 | balrog | return;
|
181 | 80f515e6 | balrog | } |
182 | 80f515e6 | balrog | } |
183 | 80f515e6 | balrog | |
184 | 80f515e6 | balrog | assert(0);
|
185 | 80f515e6 | balrog | } |
186 | 80f515e6 | balrog | |
187 | e96e2044 | ths | static void sh_intc_toggle_mask(struct intc_desc *desc, intc_enum id, |
188 | e96e2044 | ths | int enable, int is_group) |
189 | 80f515e6 | balrog | { |
190 | 80f515e6 | balrog | struct intc_source *source = desc->sources + id;
|
191 | 80f515e6 | balrog | |
192 | 80f515e6 | balrog | if (!id)
|
193 | 80f515e6 | balrog | return;
|
194 | 80f515e6 | balrog | |
195 | 80f515e6 | balrog | if (!source->next_enum_id && (!source->enable_max || !source->vect)) {
|
196 | e96e2044 | ths | #ifdef DEBUG_INTC_SOURCES
|
197 | 80f515e6 | balrog | printf("sh_intc: reserved interrupt source %d modified\n", id);
|
198 | 80f515e6 | balrog | #endif
|
199 | 80f515e6 | balrog | return;
|
200 | 80f515e6 | balrog | } |
201 | 80f515e6 | balrog | |
202 | e96e2044 | ths | if (source->vect)
|
203 | e96e2044 | ths | sh_intc_toggle_source(source, enable ? 1 : -1, 0); |
204 | 80f515e6 | balrog | |
205 | 80f515e6 | balrog | #ifdef DEBUG_INTC
|
206 | 80f515e6 | balrog | else {
|
207 | 80f515e6 | balrog | printf("setting interrupt group %d to %d\n", id, !!enable);
|
208 | 80f515e6 | balrog | } |
209 | 80f515e6 | balrog | #endif
|
210 | 80f515e6 | balrog | |
211 | 80f515e6 | balrog | if ((is_group || !source->vect) && source->next_enum_id) {
|
212 | e96e2044 | ths | sh_intc_toggle_mask(desc, source->next_enum_id, enable, 1);
|
213 | 80f515e6 | balrog | } |
214 | 80f515e6 | balrog | |
215 | 80f515e6 | balrog | #ifdef DEBUG_INTC
|
216 | 80f515e6 | balrog | if (!source->vect) {
|
217 | 80f515e6 | balrog | printf("setting interrupt group %d to %d - done\n", id, !!enable);
|
218 | 80f515e6 | balrog | } |
219 | 80f515e6 | balrog | #endif
|
220 | 80f515e6 | balrog | } |
221 | 80f515e6 | balrog | |
222 | 80f515e6 | balrog | static uint32_t sh_intc_read(void *opaque, target_phys_addr_t offset) |
223 | 80f515e6 | balrog | { |
224 | 80f515e6 | balrog | struct intc_desc *desc = opaque;
|
225 | 80f515e6 | balrog | intc_enum *enum_ids = NULL;
|
226 | 80f515e6 | balrog | unsigned int first = 0; |
227 | 80f515e6 | balrog | unsigned int width = 0; |
228 | 80f515e6 | balrog | unsigned int mode = 0; |
229 | 80f515e6 | balrog | unsigned long *valuep; |
230 | 80f515e6 | balrog | |
231 | 80f515e6 | balrog | #ifdef DEBUG_INTC
|
232 | 80f515e6 | balrog | printf("sh_intc_read 0x%lx\n", (unsigned long) offset); |
233 | 80f515e6 | balrog | #endif
|
234 | 80f515e6 | balrog | |
235 | 80f515e6 | balrog | sh_intc_locate(desc, (unsigned long)offset, &valuep, |
236 | 80f515e6 | balrog | &enum_ids, &first, &width, &mode); |
237 | 80f515e6 | balrog | return *valuep;
|
238 | 80f515e6 | balrog | } |
239 | 80f515e6 | balrog | |
240 | 80f515e6 | balrog | static void sh_intc_write(void *opaque, target_phys_addr_t offset, |
241 | 80f515e6 | balrog | uint32_t value) |
242 | 80f515e6 | balrog | { |
243 | 80f515e6 | balrog | struct intc_desc *desc = opaque;
|
244 | 80f515e6 | balrog | intc_enum *enum_ids = NULL;
|
245 | 80f515e6 | balrog | unsigned int first = 0; |
246 | 80f515e6 | balrog | unsigned int width = 0; |
247 | 80f515e6 | balrog | unsigned int mode = 0; |
248 | 80f515e6 | balrog | unsigned int k; |
249 | 80f515e6 | balrog | unsigned long *valuep; |
250 | 80f515e6 | balrog | unsigned long mask; |
251 | 80f515e6 | balrog | |
252 | 80f515e6 | balrog | #ifdef DEBUG_INTC
|
253 | 80f515e6 | balrog | printf("sh_intc_write 0x%lx 0x%08x\n", (unsigned long) offset, value); |
254 | 80f515e6 | balrog | #endif
|
255 | 80f515e6 | balrog | |
256 | 80f515e6 | balrog | sh_intc_locate(desc, (unsigned long)offset, &valuep, |
257 | 80f515e6 | balrog | &enum_ids, &first, &width, &mode); |
258 | 80f515e6 | balrog | |
259 | 80f515e6 | balrog | switch (mode) {
|
260 | 80f515e6 | balrog | case INTC_MODE_ENABLE_REG | INTC_MODE_IS_PRIO: break; |
261 | 80f515e6 | balrog | case INTC_MODE_DUAL_SET: value |= *valuep; break; |
262 | 80f515e6 | balrog | case INTC_MODE_DUAL_CLR: value = *valuep & ~value; break; |
263 | 80f515e6 | balrog | default: assert(0); |
264 | 80f515e6 | balrog | } |
265 | 80f515e6 | balrog | |
266 | 80f515e6 | balrog | for (k = 0; k <= first; k++) { |
267 | 80f515e6 | balrog | mask = ((1 << width) - 1) << ((first - k) * width); |
268 | 80f515e6 | balrog | |
269 | 80f515e6 | balrog | if ((*valuep & mask) == (value & mask))
|
270 | 80f515e6 | balrog | continue;
|
271 | 80f515e6 | balrog | #if 0
|
272 | 80f515e6 | balrog | printf("k = %d, first = %d, enum = %d, mask = 0x%08x\n",
|
273 | 80f515e6 | balrog | k, first, enum_ids[k], (unsigned int)mask);
|
274 | 80f515e6 | balrog | #endif
|
275 | e96e2044 | ths | sh_intc_toggle_mask(desc, enum_ids[k], value & mask, 0);
|
276 | 80f515e6 | balrog | } |
277 | 80f515e6 | balrog | |
278 | 80f515e6 | balrog | *valuep = value; |
279 | 80f515e6 | balrog | |
280 | 80f515e6 | balrog | #ifdef DEBUG_INTC
|
281 | 80f515e6 | balrog | printf("sh_intc_write 0x%lx -> 0x%08x\n", (unsigned long) offset, value); |
282 | 80f515e6 | balrog | #endif
|
283 | 80f515e6 | balrog | } |
284 | 80f515e6 | balrog | |
285 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const sh_intc_readfn[] = { |
286 | 80f515e6 | balrog | sh_intc_read, |
287 | 80f515e6 | balrog | sh_intc_read, |
288 | 80f515e6 | balrog | sh_intc_read |
289 | 80f515e6 | balrog | }; |
290 | 80f515e6 | balrog | |
291 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const sh_intc_writefn[] = { |
292 | 80f515e6 | balrog | sh_intc_write, |
293 | 80f515e6 | balrog | sh_intc_write, |
294 | 80f515e6 | balrog | sh_intc_write |
295 | 80f515e6 | balrog | }; |
296 | 80f515e6 | balrog | |
297 | 80f515e6 | balrog | struct intc_source *sh_intc_source(struct intc_desc *desc, intc_enum id) |
298 | 80f515e6 | balrog | { |
299 | 80f515e6 | balrog | if (id)
|
300 | 80f515e6 | balrog | return desc->sources + id;
|
301 | 80f515e6 | balrog | |
302 | 80f515e6 | balrog | return NULL; |
303 | 80f515e6 | balrog | } |
304 | 80f515e6 | balrog | |
305 | 80f515e6 | balrog | static void sh_intc_register(struct intc_desc *desc, |
306 | 80f515e6 | balrog | unsigned long address) |
307 | 80f515e6 | balrog | { |
308 | 5c16736a | balrog | if (address) {
|
309 | 5c16736a | balrog | cpu_register_physical_memory_offset(P4ADDR(address), 4,
|
310 | 8da3ff18 | pbrook | desc->iomemtype, INTC_A7(address)); |
311 | 5c16736a | balrog | cpu_register_physical_memory_offset(A7ADDR(address), 4,
|
312 | 5c16736a | balrog | desc->iomemtype, INTC_A7(address)); |
313 | 5c16736a | balrog | } |
314 | 80f515e6 | balrog | } |
315 | 80f515e6 | balrog | |
316 | 80f515e6 | balrog | static void sh_intc_register_source(struct intc_desc *desc, |
317 | 80f515e6 | balrog | intc_enum source, |
318 | 80f515e6 | balrog | struct intc_group *groups,
|
319 | 80f515e6 | balrog | int nr_groups)
|
320 | 80f515e6 | balrog | { |
321 | 80f515e6 | balrog | unsigned int i, k; |
322 | 80f515e6 | balrog | struct intc_source *s;
|
323 | 80f515e6 | balrog | |
324 | 80f515e6 | balrog | if (desc->mask_regs) {
|
325 | 80f515e6 | balrog | for (i = 0; i < desc->nr_mask_regs; i++) { |
326 | 80f515e6 | balrog | struct intc_mask_reg *mr = desc->mask_regs + i;
|
327 | 80f515e6 | balrog | |
328 | b1503cda | malc | for (k = 0; k < ARRAY_SIZE(mr->enum_ids); k++) { |
329 | 80f515e6 | balrog | if (mr->enum_ids[k] != source)
|
330 | 80f515e6 | balrog | continue;
|
331 | 80f515e6 | balrog | |
332 | 80f515e6 | balrog | s = sh_intc_source(desc, mr->enum_ids[k]); |
333 | 80f515e6 | balrog | if (s)
|
334 | 80f515e6 | balrog | s->enable_max++; |
335 | 80f515e6 | balrog | } |
336 | 80f515e6 | balrog | } |
337 | 80f515e6 | balrog | } |
338 | 80f515e6 | balrog | |
339 | 80f515e6 | balrog | if (desc->prio_regs) {
|
340 | 80f515e6 | balrog | for (i = 0; i < desc->nr_prio_regs; i++) { |
341 | 80f515e6 | balrog | struct intc_prio_reg *pr = desc->prio_regs + i;
|
342 | 80f515e6 | balrog | |
343 | b1503cda | malc | for (k = 0; k < ARRAY_SIZE(pr->enum_ids); k++) { |
344 | 80f515e6 | balrog | if (pr->enum_ids[k] != source)
|
345 | 80f515e6 | balrog | continue;
|
346 | 80f515e6 | balrog | |
347 | 80f515e6 | balrog | s = sh_intc_source(desc, pr->enum_ids[k]); |
348 | 80f515e6 | balrog | if (s)
|
349 | 80f515e6 | balrog | s->enable_max++; |
350 | 80f515e6 | balrog | } |
351 | 80f515e6 | balrog | } |
352 | 80f515e6 | balrog | } |
353 | 80f515e6 | balrog | |
354 | 80f515e6 | balrog | if (groups) {
|
355 | 80f515e6 | balrog | for (i = 0; i < nr_groups; i++) { |
356 | 80f515e6 | balrog | struct intc_group *gr = groups + i;
|
357 | 80f515e6 | balrog | |
358 | b1503cda | malc | for (k = 0; k < ARRAY_SIZE(gr->enum_ids); k++) { |
359 | 80f515e6 | balrog | if (gr->enum_ids[k] != source)
|
360 | 80f515e6 | balrog | continue;
|
361 | 80f515e6 | balrog | |
362 | 80f515e6 | balrog | s = sh_intc_source(desc, gr->enum_ids[k]); |
363 | 80f515e6 | balrog | if (s)
|
364 | 80f515e6 | balrog | s->enable_max++; |
365 | 80f515e6 | balrog | } |
366 | 80f515e6 | balrog | } |
367 | 80f515e6 | balrog | } |
368 | 80f515e6 | balrog | |
369 | 80f515e6 | balrog | } |
370 | 80f515e6 | balrog | |
371 | 80f515e6 | balrog | void sh_intc_register_sources(struct intc_desc *desc, |
372 | 80f515e6 | balrog | struct intc_vect *vectors,
|
373 | 80f515e6 | balrog | int nr_vectors,
|
374 | 80f515e6 | balrog | struct intc_group *groups,
|
375 | 80f515e6 | balrog | int nr_groups)
|
376 | 80f515e6 | balrog | { |
377 | 80f515e6 | balrog | unsigned int i, k; |
378 | 80f515e6 | balrog | struct intc_source *s;
|
379 | 80f515e6 | balrog | |
380 | 80f515e6 | balrog | for (i = 0; i < nr_vectors; i++) { |
381 | 80f515e6 | balrog | struct intc_vect *vect = vectors + i;
|
382 | 80f515e6 | balrog | |
383 | 80f515e6 | balrog | sh_intc_register_source(desc, vect->enum_id, groups, nr_groups); |
384 | 80f515e6 | balrog | s = sh_intc_source(desc, vect->enum_id); |
385 | 80f515e6 | balrog | if (s)
|
386 | 80f515e6 | balrog | s->vect = vect->vect; |
387 | 80f515e6 | balrog | |
388 | e96e2044 | ths | #ifdef DEBUG_INTC_SOURCES
|
389 | 80f515e6 | balrog | printf("sh_intc: registered source %d -> 0x%04x (%d/%d)\n",
|
390 | 80f515e6 | balrog | vect->enum_id, s->vect, s->enable_count, s->enable_max); |
391 | 80f515e6 | balrog | #endif
|
392 | 80f515e6 | balrog | } |
393 | 80f515e6 | balrog | |
394 | 80f515e6 | balrog | if (groups) {
|
395 | 80f515e6 | balrog | for (i = 0; i < nr_groups; i++) { |
396 | 80f515e6 | balrog | struct intc_group *gr = groups + i;
|
397 | 80f515e6 | balrog | |
398 | 80f515e6 | balrog | s = sh_intc_source(desc, gr->enum_id); |
399 | 80f515e6 | balrog | s->next_enum_id = gr->enum_ids[0];
|
400 | 80f515e6 | balrog | |
401 | b1503cda | malc | for (k = 1; k < ARRAY_SIZE(gr->enum_ids); k++) { |
402 | 80f515e6 | balrog | if (!gr->enum_ids[k])
|
403 | 80f515e6 | balrog | continue;
|
404 | 80f515e6 | balrog | |
405 | 80f515e6 | balrog | s = sh_intc_source(desc, gr->enum_ids[k - 1]);
|
406 | 80f515e6 | balrog | s->next_enum_id = gr->enum_ids[k]; |
407 | 80f515e6 | balrog | } |
408 | 80f515e6 | balrog | |
409 | e96e2044 | ths | #ifdef DEBUG_INTC_SOURCES
|
410 | 80f515e6 | balrog | printf("sh_intc: registered group %d (%d/%d)\n",
|
411 | 80f515e6 | balrog | gr->enum_id, s->enable_count, s->enable_max); |
412 | 80f515e6 | balrog | #endif
|
413 | 80f515e6 | balrog | } |
414 | 80f515e6 | balrog | } |
415 | 80f515e6 | balrog | } |
416 | 80f515e6 | balrog | |
417 | 80f515e6 | balrog | int sh_intc_init(struct intc_desc *desc, |
418 | 80f515e6 | balrog | int nr_sources,
|
419 | 80f515e6 | balrog | struct intc_mask_reg *mask_regs,
|
420 | 80f515e6 | balrog | int nr_mask_regs,
|
421 | 80f515e6 | balrog | struct intc_prio_reg *prio_regs,
|
422 | 80f515e6 | balrog | int nr_prio_regs)
|
423 | 80f515e6 | balrog | { |
424 | 80f515e6 | balrog | unsigned int i; |
425 | 80f515e6 | balrog | |
426 | e96e2044 | ths | desc->pending = 0;
|
427 | 80f515e6 | balrog | desc->nr_sources = nr_sources; |
428 | 80f515e6 | balrog | desc->mask_regs = mask_regs; |
429 | 80f515e6 | balrog | desc->nr_mask_regs = nr_mask_regs; |
430 | 80f515e6 | balrog | desc->prio_regs = prio_regs; |
431 | 80f515e6 | balrog | desc->nr_prio_regs = nr_prio_regs; |
432 | 80f515e6 | balrog | |
433 | 80f515e6 | balrog | i = sizeof(struct intc_source) * nr_sources; |
434 | 487414f1 | aliguori | desc->sources = qemu_malloc(i); |
435 | 80f515e6 | balrog | |
436 | 80f515e6 | balrog | memset(desc->sources, 0, i);
|
437 | e96e2044 | ths | for (i = 0; i < desc->nr_sources; i++) { |
438 | e96e2044 | ths | struct intc_source *source = desc->sources + i;
|
439 | e96e2044 | ths | |
440 | e96e2044 | ths | source->parent = desc; |
441 | e96e2044 | ths | } |
442 | 96e2fc41 | aurel32 | |
443 | 96e2fc41 | aurel32 | desc->irqs = qemu_allocate_irqs(sh_intc_set_irq, desc, nr_sources); |
444 | 80f515e6 | balrog | |
445 | 1eed09cb | Avi Kivity | desc->iomemtype = cpu_register_io_memory(sh_intc_readfn, |
446 | 80f515e6 | balrog | sh_intc_writefn, desc); |
447 | 80f515e6 | balrog | if (desc->mask_regs) {
|
448 | 80f515e6 | balrog | for (i = 0; i < desc->nr_mask_regs; i++) { |
449 | 80f515e6 | balrog | struct intc_mask_reg *mr = desc->mask_regs + i;
|
450 | 80f515e6 | balrog | |
451 | 80f515e6 | balrog | sh_intc_register(desc, mr->set_reg); |
452 | 80f515e6 | balrog | sh_intc_register(desc, mr->clr_reg); |
453 | 80f515e6 | balrog | } |
454 | 80f515e6 | balrog | } |
455 | 80f515e6 | balrog | |
456 | 80f515e6 | balrog | if (desc->prio_regs) {
|
457 | 80f515e6 | balrog | for (i = 0; i < desc->nr_prio_regs; i++) { |
458 | 80f515e6 | balrog | struct intc_prio_reg *pr = desc->prio_regs + i;
|
459 | 80f515e6 | balrog | |
460 | 80f515e6 | balrog | sh_intc_register(desc, pr->set_reg); |
461 | 80f515e6 | balrog | sh_intc_register(desc, pr->clr_reg); |
462 | 80f515e6 | balrog | } |
463 | 80f515e6 | balrog | } |
464 | 80f515e6 | balrog | |
465 | 80f515e6 | balrog | return 0; |
466 | 80f515e6 | balrog | } |
467 | c6d86a33 | balrog | |
468 | c6d86a33 | balrog | /* Assert level <n> IRL interrupt.
|
469 | c6d86a33 | balrog | 0:deassert. 1:lowest priority,... 15:highest priority. */
|
470 | c6d86a33 | balrog | void sh_intc_set_irl(void *opaque, int n, int level) |
471 | c6d86a33 | balrog | { |
472 | c6d86a33 | balrog | struct intc_source *s = opaque;
|
473 | c6d86a33 | balrog | int i, irl = level ^ 15; |
474 | c6d86a33 | balrog | for (i = 0; (s = sh_intc_source(s->parent, s->next_enum_id)); i++) { |
475 | c6d86a33 | balrog | if (i == irl)
|
476 | c6d86a33 | balrog | sh_intc_toggle_source(s, s->enable_count?0:1, s->asserted?0:1); |
477 | c6d86a33 | balrog | else
|
478 | c6d86a33 | balrog | if (s->asserted)
|
479 | c6d86a33 | balrog | sh_intc_toggle_source(s, 0, -1); |
480 | c6d86a33 | balrog | } |
481 | c6d86a33 | balrog | } |