2 * Intel XScale PXA Programmable Interrupt Controller.
4 * Copyright (c) 2006 Openedhand Ltd.
5 * Copyright (c) 2006 Thorsten Zitterell
6 * Written by Andrzej Zaborowski <balrog@zabor.org>
8 * This code is licensed under the GPL.
15 #define ICIP 0x00 /* Interrupt Controller IRQ Pending register */
16 #define ICMR 0x04 /* Interrupt Controller Mask register */
17 #define ICLR 0x08 /* Interrupt Controller Level register */
18 #define ICFP 0x0c /* Interrupt Controller FIQ Pending register */
19 #define ICPR 0x10 /* Interrupt Controller Pending register */
20 #define ICCR 0x14 /* Interrupt Controller Control register */
21 #define ICHP 0x18 /* Interrupt Controller Highest Priority register */
22 #define IPR0 0x1c /* Interrupt Controller Priority register 0 */
23 #define IPR31 0x98 /* Interrupt Controller Priority register 31 */
24 #define ICIP2 0x9c /* Interrupt Controller IRQ Pending register 2 */
25 #define ICMR2 0xa0 /* Interrupt Controller Mask register 2 */
26 #define ICLR2 0xa4 /* Interrupt Controller Level register 2 */
27 #define ICFP2 0xa8 /* Interrupt Controller FIQ Pending register 2 */
28 #define ICPR2 0xac /* Interrupt Controller Pending register 2 */
29 #define IPR32 0xb0 /* Interrupt Controller Priority register 32 */
30 #define IPR39 0xcc /* Interrupt Controller Priority register 39 */
32 #define PXA2XX_PIC_SRCS 40
38 uint32_t int_enabled
[2];
39 uint32_t int_pending
[2];
42 uint32_t priority
[PXA2XX_PIC_SRCS
];
45 static void pxa2xx_pic_update(void *opaque
)
48 PXA2xxPICState
*s
= (PXA2xxPICState
*) opaque
;
50 if (s
->cpu_env
->halted
) {
51 mask
[0] = s
->int_pending
[0] & (s
->int_enabled
[0] | s
->int_idle
);
52 mask
[1] = s
->int_pending
[1] & (s
->int_enabled
[1] | s
->int_idle
);
53 if (mask
[0] || mask
[1])
54 cpu_interrupt(s
->cpu_env
, CPU_INTERRUPT_EXITTB
);
57 mask
[0] = s
->int_pending
[0] & s
->int_enabled
[0];
58 mask
[1] = s
->int_pending
[1] & s
->int_enabled
[1];
60 if ((mask
[0] & s
->is_fiq
[0]) || (mask
[1] & s
->is_fiq
[1]))
61 cpu_interrupt(s
->cpu_env
, CPU_INTERRUPT_FIQ
);
63 cpu_reset_interrupt(s
->cpu_env
, CPU_INTERRUPT_FIQ
);
65 if ((mask
[0] & ~s
->is_fiq
[0]) || (mask
[1] & ~s
->is_fiq
[1]))
66 cpu_interrupt(s
->cpu_env
, CPU_INTERRUPT_HARD
);
68 cpu_reset_interrupt(s
->cpu_env
, CPU_INTERRUPT_HARD
);
71 /* Note: Here level means state of the signal on a pin, not
72 * IRQ/FIQ distinction as in PXA Developer Manual. */
73 static void pxa2xx_pic_set_irq(void *opaque
, int irq
, int level
)
75 PXA2xxPICState
*s
= (PXA2xxPICState
*) opaque
;
76 int int_set
= (irq
>= 32);
80 s
->int_pending
[int_set
] |= 1 << irq
;
82 s
->int_pending
[int_set
] &= ~(1 << irq
);
84 pxa2xx_pic_update(opaque
);
87 static inline uint32_t pxa2xx_pic_highest(PXA2xxPICState
*s
) {
89 uint32_t bit
, mask
[2];
90 uint32_t ichp
= 0x003f003f; /* Both IDs invalid */
92 mask
[0] = s
->int_pending
[0] & s
->int_enabled
[0];
93 mask
[1] = s
->int_pending
[1] & s
->int_enabled
[1];
95 for (i
= PXA2XX_PIC_SRCS
- 1; i
>= 0; i
--) {
96 irq
= s
->priority
[i
] & 0x3f;
97 if ((s
->priority
[i
] & (1 << 31)) && irq
< PXA2XX_PIC_SRCS
) {
98 /* Source peripheral ID is valid. */
99 bit
= 1 << (irq
& 31);
100 int_set
= (irq
>= 32);
102 if (mask
[int_set
] & bit
& s
->is_fiq
[int_set
]) {
105 ichp
|= (1 << 15) | irq
;
108 if (mask
[int_set
] & bit
& ~s
->is_fiq
[int_set
]) {
111 ichp
|= (1 << 31) | (irq
<< 16);
119 static uint64_t pxa2xx_pic_mem_read(void *opaque
, target_phys_addr_t offset
,
122 PXA2xxPICState
*s
= (PXA2xxPICState
*) opaque
;
125 case ICIP
: /* IRQ Pending register */
126 return s
->int_pending
[0] & ~s
->is_fiq
[0] & s
->int_enabled
[0];
127 case ICIP2
: /* IRQ Pending register 2 */
128 return s
->int_pending
[1] & ~s
->is_fiq
[1] & s
->int_enabled
[1];
129 case ICMR
: /* Mask register */
130 return s
->int_enabled
[0];
131 case ICMR2
: /* Mask register 2 */
132 return s
->int_enabled
[1];
133 case ICLR
: /* Level register */
135 case ICLR2
: /* Level register 2 */
137 case ICCR
: /* Idle mask */
138 return (s
->int_idle
== 0);
139 case ICFP
: /* FIQ Pending register */
140 return s
->int_pending
[0] & s
->is_fiq
[0] & s
->int_enabled
[0];
141 case ICFP2
: /* FIQ Pending register 2 */
142 return s
->int_pending
[1] & s
->is_fiq
[1] & s
->int_enabled
[1];
143 case ICPR
: /* Pending register */
144 return s
->int_pending
[0];
145 case ICPR2
: /* Pending register 2 */
146 return s
->int_pending
[1];
148 return s
->priority
[0 + ((offset
- IPR0
) >> 2)];
149 case IPR32
... IPR39
:
150 return s
->priority
[32 + ((offset
- IPR32
) >> 2)];
151 case ICHP
: /* Highest Priority register */
152 return pxa2xx_pic_highest(s
);
154 printf("%s: Bad register offset " REG_FMT
"\n", __FUNCTION__
, offset
);
159 static void pxa2xx_pic_mem_write(void *opaque
, target_phys_addr_t offset
,
160 uint64_t value
, unsigned size
)
162 PXA2xxPICState
*s
= (PXA2xxPICState
*) opaque
;
165 case ICMR
: /* Mask register */
166 s
->int_enabled
[0] = value
;
168 case ICMR2
: /* Mask register 2 */
169 s
->int_enabled
[1] = value
;
171 case ICLR
: /* Level register */
172 s
->is_fiq
[0] = value
;
174 case ICLR2
: /* Level register 2 */
175 s
->is_fiq
[1] = value
;
177 case ICCR
: /* Idle mask */
178 s
->int_idle
= (value
& 1) ? 0 : ~0;
181 s
->priority
[0 + ((offset
- IPR0
) >> 2)] = value
& 0x8000003f;
183 case IPR32
... IPR39
:
184 s
->priority
[32 + ((offset
- IPR32
) >> 2)] = value
& 0x8000003f;
187 printf("%s: Bad register offset " REG_FMT
"\n", __FUNCTION__
, offset
);
190 pxa2xx_pic_update(opaque
);
193 /* Interrupt Controller Coprocessor Space Register Mapping */
194 static const int pxa2xx_cp_reg_map
[0x10] = {
209 static uint32_t pxa2xx_pic_cp_read(void *opaque
, int op2
, int reg
, int crm
)
211 target_phys_addr_t offset
;
213 if (pxa2xx_cp_reg_map
[reg
] == -1) {
214 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
218 offset
= pxa2xx_cp_reg_map
[reg
];
219 return pxa2xx_pic_mem_read(opaque
, offset
, 4);
222 static void pxa2xx_pic_cp_write(void *opaque
, int op2
, int reg
, int crm
,
225 target_phys_addr_t offset
;
227 if (pxa2xx_cp_reg_map
[reg
] == -1) {
228 printf("%s: Bad register 0x%x\n", __FUNCTION__
, reg
);
232 offset
= pxa2xx_cp_reg_map
[reg
];
233 pxa2xx_pic_mem_write(opaque
, offset
, value
, 4);
236 static const MemoryRegionOps pxa2xx_pic_ops
= {
237 .read
= pxa2xx_pic_mem_read
,
238 .write
= pxa2xx_pic_mem_write
,
239 .endianness
= DEVICE_NATIVE_ENDIAN
,
242 static int pxa2xx_pic_post_load(void *opaque
, int version_id
)
244 pxa2xx_pic_update(opaque
);
248 DeviceState
*pxa2xx_pic_init(target_phys_addr_t base
, CPUState
*env
)
250 DeviceState
*dev
= qdev_create(NULL
, "pxa2xx_pic");
251 PXA2xxPICState
*s
= FROM_SYSBUS(PXA2xxPICState
, sysbus_from_qdev(dev
));
255 s
->int_pending
[0] = 0;
256 s
->int_pending
[1] = 0;
257 s
->int_enabled
[0] = 0;
258 s
->int_enabled
[1] = 0;
262 qdev_init_nofail(dev
);
264 qdev_init_gpio_in(dev
, pxa2xx_pic_set_irq
, PXA2XX_PIC_SRCS
);
266 /* Enable IC memory-mapped registers access. */
267 memory_region_init_io(&s
->iomem
, &pxa2xx_pic_ops
, s
,
268 "pxa2xx-pic", 0x00100000);
269 sysbus_init_mmio(sysbus_from_qdev(dev
), &s
->iomem
);
270 sysbus_mmio_map(sysbus_from_qdev(dev
), 0, base
);
272 /* Enable IC coprocessor access. */
273 cpu_arm_set_cp_io(env
, 6, pxa2xx_pic_cp_read
, pxa2xx_pic_cp_write
, s
);
278 static VMStateDescription vmstate_pxa2xx_pic_regs
= {
279 .name
= "pxa2xx_pic",
281 .minimum_version_id
= 0,
282 .minimum_version_id_old
= 0,
283 .post_load
= pxa2xx_pic_post_load
,
284 .fields
= (VMStateField
[]) {
285 VMSTATE_UINT32_ARRAY(int_enabled
, PXA2xxPICState
, 2),
286 VMSTATE_UINT32_ARRAY(int_pending
, PXA2xxPICState
, 2),
287 VMSTATE_UINT32_ARRAY(is_fiq
, PXA2xxPICState
, 2),
288 VMSTATE_UINT32(int_idle
, PXA2xxPICState
),
289 VMSTATE_UINT32_ARRAY(priority
, PXA2xxPICState
, PXA2XX_PIC_SRCS
),
290 VMSTATE_END_OF_LIST(),
294 static int pxa2xx_pic_initfn(SysBusDevice
*dev
)
299 static void pxa2xx_pic_class_init(ObjectClass
*klass
, void *data
)
301 DeviceClass
*dc
= DEVICE_CLASS(klass
);
302 SysBusDeviceClass
*k
= SYS_BUS_DEVICE_CLASS(klass
);
304 k
->init
= pxa2xx_pic_initfn
;
305 dc
->desc
= "PXA2xx PIC";
306 dc
->vmsd
= &vmstate_pxa2xx_pic_regs
;
309 static TypeInfo pxa2xx_pic_info
= {
310 .name
= "pxa2xx_pic",
311 .parent
= TYPE_SYS_BUS_DEVICE
,
312 .instance_size
= sizeof(PXA2xxPICState
),
313 .class_init
= pxa2xx_pic_class_init
,
316 static void pxa2xx_pic_register_types(void)
318 type_register_static(&pxa2xx_pic_info
);
321 type_init(pxa2xx_pic_register_types
)