root / hw / pxa2xx_pic.c @ c0b1905b
History | View | Annotate | Download (9.3 kB)
1 | c1713132 | balrog | /*
|
---|---|---|---|
2 | c1713132 | balrog | * Intel XScale PXA Programmable Interrupt Controller.
|
3 | c1713132 | balrog | *
|
4 | c1713132 | balrog | * Copyright (c) 2006 Openedhand Ltd.
|
5 | c1713132 | balrog | * Copyright (c) 2006 Thorsten Zitterell
|
6 | c1713132 | balrog | * Written by Andrzej Zaborowski <balrog@zabor.org>
|
7 | c1713132 | balrog | *
|
8 | c1713132 | balrog | * This code is licenced under the GPL.
|
9 | c1713132 | balrog | */
|
10 | c1713132 | balrog | |
11 | 87ecb68b | pbrook | #include "hw.h" |
12 | 87ecb68b | pbrook | #include "pxa.h" |
13 | c1713132 | balrog | |
14 | c1713132 | balrog | #define ICIP 0x00 /* Interrupt Controller IRQ Pending register */ |
15 | c1713132 | balrog | #define ICMR 0x04 /* Interrupt Controller Mask register */ |
16 | c1713132 | balrog | #define ICLR 0x08 /* Interrupt Controller Level register */ |
17 | c1713132 | balrog | #define ICFP 0x0c /* Interrupt Controller FIQ Pending register */ |
18 | c1713132 | balrog | #define ICPR 0x10 /* Interrupt Controller Pending register */ |
19 | c1713132 | balrog | #define ICCR 0x14 /* Interrupt Controller Control register */ |
20 | c1713132 | balrog | #define ICHP 0x18 /* Interrupt Controller Highest Priority register */ |
21 | c1713132 | balrog | #define IPR0 0x1c /* Interrupt Controller Priority register 0 */ |
22 | c1713132 | balrog | #define IPR31 0x98 /* Interrupt Controller Priority register 31 */ |
23 | c1713132 | balrog | #define ICIP2 0x9c /* Interrupt Controller IRQ Pending register 2 */ |
24 | c1713132 | balrog | #define ICMR2 0xa0 /* Interrupt Controller Mask register 2 */ |
25 | c1713132 | balrog | #define ICLR2 0xa4 /* Interrupt Controller Level register 2 */ |
26 | c1713132 | balrog | #define ICFP2 0xa8 /* Interrupt Controller FIQ Pending register 2 */ |
27 | c1713132 | balrog | #define ICPR2 0xac /* Interrupt Controller Pending register 2 */ |
28 | c1713132 | balrog | #define IPR32 0xb0 /* Interrupt Controller Priority register 32 */ |
29 | c1713132 | balrog | #define IPR39 0xcc /* Interrupt Controller Priority register 39 */ |
30 | c1713132 | balrog | |
31 | c1713132 | balrog | #define PXA2XX_PIC_SRCS 40 |
32 | c1713132 | balrog | |
33 | bc24a225 | Paul Brook | typedef struct { |
34 | c1713132 | balrog | CPUState *cpu_env; |
35 | c1713132 | balrog | uint32_t int_enabled[2];
|
36 | c1713132 | balrog | uint32_t int_pending[2];
|
37 | c1713132 | balrog | uint32_t is_fiq[2];
|
38 | c1713132 | balrog | uint32_t int_idle; |
39 | c1713132 | balrog | uint32_t priority[PXA2XX_PIC_SRCS]; |
40 | bc24a225 | Paul Brook | } PXA2xxPICState; |
41 | c1713132 | balrog | |
42 | c1713132 | balrog | static void pxa2xx_pic_update(void *opaque) |
43 | c1713132 | balrog | { |
44 | c1713132 | balrog | uint32_t mask[2];
|
45 | bc24a225 | Paul Brook | PXA2xxPICState *s = (PXA2xxPICState *) opaque; |
46 | c1713132 | balrog | |
47 | c1713132 | balrog | if (s->cpu_env->halted) {
|
48 | c1713132 | balrog | mask[0] = s->int_pending[0] & (s->int_enabled[0] | s->int_idle); |
49 | c1713132 | balrog | mask[1] = s->int_pending[1] & (s->int_enabled[1] | s->int_idle); |
50 | c1713132 | balrog | if (mask[0] || mask[1]) |
51 | c1713132 | balrog | cpu_interrupt(s->cpu_env, CPU_INTERRUPT_EXITTB); |
52 | c1713132 | balrog | } |
53 | c1713132 | balrog | |
54 | c1713132 | balrog | mask[0] = s->int_pending[0] & s->int_enabled[0]; |
55 | c1713132 | balrog | mask[1] = s->int_pending[1] & s->int_enabled[1]; |
56 | c1713132 | balrog | |
57 | c1713132 | balrog | if ((mask[0] & s->is_fiq[0]) || (mask[1] & s->is_fiq[1])) |
58 | c1713132 | balrog | cpu_interrupt(s->cpu_env, CPU_INTERRUPT_FIQ); |
59 | c1713132 | balrog | else
|
60 | c1713132 | balrog | cpu_reset_interrupt(s->cpu_env, CPU_INTERRUPT_FIQ); |
61 | c1713132 | balrog | |
62 | c1713132 | balrog | if ((mask[0] & ~s->is_fiq[0]) || (mask[1] & ~s->is_fiq[1])) |
63 | c1713132 | balrog | cpu_interrupt(s->cpu_env, CPU_INTERRUPT_HARD); |
64 | c1713132 | balrog | else
|
65 | c1713132 | balrog | cpu_reset_interrupt(s->cpu_env, CPU_INTERRUPT_HARD); |
66 | c1713132 | balrog | } |
67 | c1713132 | balrog | |
68 | c1713132 | balrog | /* Note: Here level means state of the signal on a pin, not
|
69 | c1713132 | balrog | * IRQ/FIQ distinction as in PXA Developer Manual. */
|
70 | c1713132 | balrog | static void pxa2xx_pic_set_irq(void *opaque, int irq, int level) |
71 | c1713132 | balrog | { |
72 | bc24a225 | Paul Brook | PXA2xxPICState *s = (PXA2xxPICState *) opaque; |
73 | c1713132 | balrog | int int_set = (irq >= 32); |
74 | c1713132 | balrog | irq &= 31;
|
75 | c1713132 | balrog | |
76 | c1713132 | balrog | if (level)
|
77 | c1713132 | balrog | s->int_pending[int_set] |= 1 << irq;
|
78 | c1713132 | balrog | else
|
79 | c1713132 | balrog | s->int_pending[int_set] &= ~(1 << irq);
|
80 | c1713132 | balrog | |
81 | c1713132 | balrog | pxa2xx_pic_update(opaque); |
82 | c1713132 | balrog | } |
83 | c1713132 | balrog | |
84 | bc24a225 | Paul Brook | static inline uint32_t pxa2xx_pic_highest(PXA2xxPICState *s) { |
85 | c1713132 | balrog | int i, int_set, irq;
|
86 | c1713132 | balrog | uint32_t bit, mask[2];
|
87 | c1713132 | balrog | uint32_t ichp = 0x003f003f; /* Both IDs invalid */ |
88 | c1713132 | balrog | |
89 | c1713132 | balrog | mask[0] = s->int_pending[0] & s->int_enabled[0]; |
90 | c1713132 | balrog | mask[1] = s->int_pending[1] & s->int_enabled[1]; |
91 | c1713132 | balrog | |
92 | c1713132 | balrog | for (i = PXA2XX_PIC_SRCS - 1; i >= 0; i --) { |
93 | c1713132 | balrog | irq = s->priority[i] & 0x3f;
|
94 | c1713132 | balrog | if ((s->priority[i] & (1 << 31)) && irq < PXA2XX_PIC_SRCS) { |
95 | c1713132 | balrog | /* Source peripheral ID is valid. */
|
96 | c1713132 | balrog | bit = 1 << (irq & 31); |
97 | c1713132 | balrog | int_set = (irq >= 32);
|
98 | c1713132 | balrog | |
99 | c1713132 | balrog | if (mask[int_set] & bit & s->is_fiq[int_set]) {
|
100 | c1713132 | balrog | /* FIQ asserted */
|
101 | c1713132 | balrog | ichp &= 0xffff0000;
|
102 | c1713132 | balrog | ichp |= (1 << 15) | irq; |
103 | c1713132 | balrog | } |
104 | c1713132 | balrog | |
105 | c1713132 | balrog | if (mask[int_set] & bit & ~s->is_fiq[int_set]) {
|
106 | c1713132 | balrog | /* IRQ asserted */
|
107 | c1713132 | balrog | ichp &= 0x0000ffff;
|
108 | c1713132 | balrog | ichp |= (1 << 31) | (irq << 16); |
109 | c1713132 | balrog | } |
110 | c1713132 | balrog | } |
111 | c1713132 | balrog | } |
112 | c1713132 | balrog | |
113 | c1713132 | balrog | return ichp;
|
114 | c1713132 | balrog | } |
115 | c1713132 | balrog | |
116 | c227f099 | Anthony Liguori | static uint32_t pxa2xx_pic_mem_read(void *opaque, target_phys_addr_t offset) |
117 | c1713132 | balrog | { |
118 | bc24a225 | Paul Brook | PXA2xxPICState *s = (PXA2xxPICState *) opaque; |
119 | c1713132 | balrog | |
120 | c1713132 | balrog | switch (offset) {
|
121 | c1713132 | balrog | case ICIP: /* IRQ Pending register */ |
122 | c1713132 | balrog | return s->int_pending[0] & ~s->is_fiq[0] & s->int_enabled[0]; |
123 | c1713132 | balrog | case ICIP2: /* IRQ Pending register 2 */ |
124 | c1713132 | balrog | return s->int_pending[1] & ~s->is_fiq[1] & s->int_enabled[1]; |
125 | c1713132 | balrog | case ICMR: /* Mask register */ |
126 | c1713132 | balrog | return s->int_enabled[0]; |
127 | c1713132 | balrog | case ICMR2: /* Mask register 2 */ |
128 | c1713132 | balrog | return s->int_enabled[1]; |
129 | c1713132 | balrog | case ICLR: /* Level register */ |
130 | c1713132 | balrog | return s->is_fiq[0]; |
131 | c1713132 | balrog | case ICLR2: /* Level register 2 */ |
132 | c1713132 | balrog | return s->is_fiq[1]; |
133 | c1713132 | balrog | case ICCR: /* Idle mask */ |
134 | c1713132 | balrog | return (s->int_idle == 0); |
135 | c1713132 | balrog | case ICFP: /* FIQ Pending register */ |
136 | c1713132 | balrog | return s->int_pending[0] & s->is_fiq[0] & s->int_enabled[0]; |
137 | c1713132 | balrog | case ICFP2: /* FIQ Pending register 2 */ |
138 | c1713132 | balrog | return s->int_pending[1] & s->is_fiq[1] & s->int_enabled[1]; |
139 | c1713132 | balrog | case ICPR: /* Pending register */ |
140 | c1713132 | balrog | return s->int_pending[0]; |
141 | c1713132 | balrog | case ICPR2: /* Pending register 2 */ |
142 | c1713132 | balrog | return s->int_pending[1]; |
143 | c1713132 | balrog | case IPR0 ... IPR31:
|
144 | c1713132 | balrog | return s->priority[0 + ((offset - IPR0 ) >> 2)]; |
145 | c1713132 | balrog | case IPR32 ... IPR39:
|
146 | c1713132 | balrog | return s->priority[32 + ((offset - IPR32) >> 2)]; |
147 | c1713132 | balrog | case ICHP: /* Highest Priority register */ |
148 | c1713132 | balrog | return pxa2xx_pic_highest(s);
|
149 | c1713132 | balrog | default:
|
150 | c1713132 | balrog | printf("%s: Bad register offset " REG_FMT "\n", __FUNCTION__, offset); |
151 | c1713132 | balrog | return 0; |
152 | c1713132 | balrog | } |
153 | c1713132 | balrog | } |
154 | c1713132 | balrog | |
155 | c227f099 | Anthony Liguori | static void pxa2xx_pic_mem_write(void *opaque, target_phys_addr_t offset, |
156 | c1713132 | balrog | uint32_t value) |
157 | c1713132 | balrog | { |
158 | bc24a225 | Paul Brook | PXA2xxPICState *s = (PXA2xxPICState *) opaque; |
159 | c1713132 | balrog | |
160 | c1713132 | balrog | switch (offset) {
|
161 | c1713132 | balrog | case ICMR: /* Mask register */ |
162 | c1713132 | balrog | s->int_enabled[0] = value;
|
163 | c1713132 | balrog | break;
|
164 | c1713132 | balrog | case ICMR2: /* Mask register 2 */ |
165 | c1713132 | balrog | s->int_enabled[1] = value;
|
166 | c1713132 | balrog | break;
|
167 | c1713132 | balrog | case ICLR: /* Level register */ |
168 | c1713132 | balrog | s->is_fiq[0] = value;
|
169 | c1713132 | balrog | break;
|
170 | c1713132 | balrog | case ICLR2: /* Level register 2 */ |
171 | c1713132 | balrog | s->is_fiq[1] = value;
|
172 | c1713132 | balrog | break;
|
173 | c1713132 | balrog | case ICCR: /* Idle mask */ |
174 | c1713132 | balrog | s->int_idle = (value & 1) ? 0 : ~0; |
175 | c1713132 | balrog | break;
|
176 | c1713132 | balrog | case IPR0 ... IPR31:
|
177 | c1713132 | balrog | s->priority[0 + ((offset - IPR0 ) >> 2)] = value & 0x8000003f; |
178 | c1713132 | balrog | break;
|
179 | c1713132 | balrog | case IPR32 ... IPR39:
|
180 | c1713132 | balrog | s->priority[32 + ((offset - IPR32) >> 2)] = value & 0x8000003f; |
181 | c1713132 | balrog | break;
|
182 | c1713132 | balrog | default:
|
183 | c1713132 | balrog | printf("%s: Bad register offset " REG_FMT "\n", __FUNCTION__, offset); |
184 | c1713132 | balrog | return;
|
185 | c1713132 | balrog | } |
186 | c1713132 | balrog | pxa2xx_pic_update(opaque); |
187 | c1713132 | balrog | } |
188 | c1713132 | balrog | |
189 | c1713132 | balrog | /* Interrupt Controller Coprocessor Space Register Mapping */
|
190 | c1713132 | balrog | static const int pxa2xx_cp_reg_map[0x10] = { |
191 | c1713132 | balrog | [0x0 ... 0xf] = -1, |
192 | c1713132 | balrog | [0x0] = ICIP,
|
193 | c1713132 | balrog | [0x1] = ICMR,
|
194 | c1713132 | balrog | [0x2] = ICLR,
|
195 | c1713132 | balrog | [0x3] = ICFP,
|
196 | c1713132 | balrog | [0x4] = ICPR,
|
197 | c1713132 | balrog | [0x5] = ICHP,
|
198 | c1713132 | balrog | [0x6] = ICIP2,
|
199 | c1713132 | balrog | [0x7] = ICMR2,
|
200 | c1713132 | balrog | [0x8] = ICLR2,
|
201 | c1713132 | balrog | [0x9] = ICFP2,
|
202 | c1713132 | balrog | [0xa] = ICPR2,
|
203 | c1713132 | balrog | }; |
204 | c1713132 | balrog | |
205 | c1713132 | balrog | static uint32_t pxa2xx_pic_cp_read(void *opaque, int op2, int reg, int crm) |
206 | c1713132 | balrog | { |
207 | c227f099 | Anthony Liguori | target_phys_addr_t offset; |
208 | c1713132 | balrog | |
209 | c1713132 | balrog | if (pxa2xx_cp_reg_map[reg] == -1) { |
210 | c1713132 | balrog | printf("%s: Bad register 0x%x\n", __FUNCTION__, reg);
|
211 | c1713132 | balrog | return 0; |
212 | c1713132 | balrog | } |
213 | c1713132 | balrog | |
214 | 8da3ff18 | pbrook | offset = pxa2xx_cp_reg_map[reg]; |
215 | c1713132 | balrog | return pxa2xx_pic_mem_read(opaque, offset);
|
216 | c1713132 | balrog | } |
217 | c1713132 | balrog | |
218 | c1713132 | balrog | static void pxa2xx_pic_cp_write(void *opaque, int op2, int reg, int crm, |
219 | c1713132 | balrog | uint32_t value) |
220 | c1713132 | balrog | { |
221 | c227f099 | Anthony Liguori | target_phys_addr_t offset; |
222 | c1713132 | balrog | |
223 | c1713132 | balrog | if (pxa2xx_cp_reg_map[reg] == -1) { |
224 | c1713132 | balrog | printf("%s: Bad register 0x%x\n", __FUNCTION__, reg);
|
225 | c1713132 | balrog | return;
|
226 | c1713132 | balrog | } |
227 | c1713132 | balrog | |
228 | 8da3ff18 | pbrook | offset = pxa2xx_cp_reg_map[reg]; |
229 | c1713132 | balrog | pxa2xx_pic_mem_write(opaque, offset, value); |
230 | c1713132 | balrog | } |
231 | c1713132 | balrog | |
232 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pxa2xx_pic_readfn[] = { |
233 | c1713132 | balrog | pxa2xx_pic_mem_read, |
234 | c1713132 | balrog | pxa2xx_pic_mem_read, |
235 | c1713132 | balrog | pxa2xx_pic_mem_read, |
236 | c1713132 | balrog | }; |
237 | c1713132 | balrog | |
238 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pxa2xx_pic_writefn[] = { |
239 | c1713132 | balrog | pxa2xx_pic_mem_write, |
240 | c1713132 | balrog | pxa2xx_pic_mem_write, |
241 | c1713132 | balrog | pxa2xx_pic_mem_write, |
242 | c1713132 | balrog | }; |
243 | c1713132 | balrog | |
244 | aa941b94 | balrog | static void pxa2xx_pic_save(QEMUFile *f, void *opaque) |
245 | aa941b94 | balrog | { |
246 | bc24a225 | Paul Brook | PXA2xxPICState *s = (PXA2xxPICState *) opaque; |
247 | aa941b94 | balrog | int i;
|
248 | aa941b94 | balrog | |
249 | aa941b94 | balrog | for (i = 0; i < 2; i ++) |
250 | aa941b94 | balrog | qemu_put_be32s(f, &s->int_enabled[i]); |
251 | aa941b94 | balrog | for (i = 0; i < 2; i ++) |
252 | aa941b94 | balrog | qemu_put_be32s(f, &s->int_pending[i]); |
253 | aa941b94 | balrog | for (i = 0; i < 2; i ++) |
254 | aa941b94 | balrog | qemu_put_be32s(f, &s->is_fiq[i]); |
255 | aa941b94 | balrog | qemu_put_be32s(f, &s->int_idle); |
256 | aa941b94 | balrog | for (i = 0; i < PXA2XX_PIC_SRCS; i ++) |
257 | aa941b94 | balrog | qemu_put_be32s(f, &s->priority[i]); |
258 | aa941b94 | balrog | } |
259 | aa941b94 | balrog | |
260 | aa941b94 | balrog | static int pxa2xx_pic_load(QEMUFile *f, void *opaque, int version_id) |
261 | aa941b94 | balrog | { |
262 | bc24a225 | Paul Brook | PXA2xxPICState *s = (PXA2xxPICState *) opaque; |
263 | aa941b94 | balrog | int i;
|
264 | aa941b94 | balrog | |
265 | aa941b94 | balrog | for (i = 0; i < 2; i ++) |
266 | aa941b94 | balrog | qemu_get_be32s(f, &s->int_enabled[i]); |
267 | aa941b94 | balrog | for (i = 0; i < 2; i ++) |
268 | aa941b94 | balrog | qemu_get_be32s(f, &s->int_pending[i]); |
269 | aa941b94 | balrog | for (i = 0; i < 2; i ++) |
270 | aa941b94 | balrog | qemu_get_be32s(f, &s->is_fiq[i]); |
271 | aa941b94 | balrog | qemu_get_be32s(f, &s->int_idle); |
272 | aa941b94 | balrog | for (i = 0; i < PXA2XX_PIC_SRCS; i ++) |
273 | aa941b94 | balrog | qemu_get_be32s(f, &s->priority[i]); |
274 | aa941b94 | balrog | |
275 | aa941b94 | balrog | pxa2xx_pic_update(opaque); |
276 | aa941b94 | balrog | return 0; |
277 | aa941b94 | balrog | } |
278 | aa941b94 | balrog | |
279 | c227f099 | Anthony Liguori | qemu_irq *pxa2xx_pic_init(target_phys_addr_t base, CPUState *env) |
280 | c1713132 | balrog | { |
281 | bc24a225 | Paul Brook | PXA2xxPICState *s; |
282 | c1713132 | balrog | int iomemtype;
|
283 | c1713132 | balrog | qemu_irq *qi; |
284 | c1713132 | balrog | |
285 | bc24a225 | Paul Brook | s = (PXA2xxPICState *) |
286 | bc24a225 | Paul Brook | qemu_mallocz(sizeof(PXA2xxPICState));
|
287 | c1713132 | balrog | if (!s)
|
288 | c1713132 | balrog | return NULL; |
289 | c1713132 | balrog | |
290 | c1713132 | balrog | s->cpu_env = env; |
291 | c1713132 | balrog | |
292 | c1713132 | balrog | s->int_pending[0] = 0; |
293 | c1713132 | balrog | s->int_pending[1] = 0; |
294 | c1713132 | balrog | s->int_enabled[0] = 0; |
295 | c1713132 | balrog | s->int_enabled[1] = 0; |
296 | c1713132 | balrog | s->is_fiq[0] = 0; |
297 | c1713132 | balrog | s->is_fiq[1] = 0; |
298 | c1713132 | balrog | |
299 | c1713132 | balrog | qi = qemu_allocate_irqs(pxa2xx_pic_set_irq, s, PXA2XX_PIC_SRCS); |
300 | c1713132 | balrog | |
301 | c1713132 | balrog | /* Enable IC memory-mapped registers access. */
|
302 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pxa2xx_pic_readfn, |
303 | c1713132 | balrog | pxa2xx_pic_writefn, s); |
304 | 187337f8 | pbrook | cpu_register_physical_memory(base, 0x00100000, iomemtype);
|
305 | c1713132 | balrog | |
306 | c1713132 | balrog | /* Enable IC coprocessor access. */
|
307 | c1713132 | balrog | cpu_arm_set_cp_io(env, 6, pxa2xx_pic_cp_read, pxa2xx_pic_cp_write, s);
|
308 | c1713132 | balrog | |
309 | aa941b94 | balrog | register_savevm("pxa2xx_pic", 0, 0, pxa2xx_pic_save, pxa2xx_pic_load, s); |
310 | aa941b94 | balrog | |
311 | c1713132 | balrog | return qi;
|
312 | c1713132 | balrog | } |