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