2 * Arm PrimeCell PL190 Vector Interrupt Controller
4 * Copyright (c) 2006 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licensed under the GPL.
12 /* The number of virtual priority levels. 16 user vectors plus the
13 unvectored IRQ. Chained interrupts would require an additional level
16 #define PL190_NUM_PRIO 17
25 uint8_t vect_control
[16];
26 uint32_t vect_addr
[PL190_NUM_PRIO
];
27 /* Mask containing interrupts with higher priority than this one. */
28 uint32_t prio_mask
[PL190_NUM_PRIO
+ 1];
30 /* Current priority level. */
32 int prev_prio
[PL190_NUM_PRIO
];
37 static const unsigned char pl190_id
[] =
38 { 0x90, 0x11, 0x04, 0x00, 0x0D, 0xf0, 0x05, 0xb1 };
40 static inline uint32_t pl190_irq_level(pl190_state
*s
)
42 return (s
->level
| s
->soft_level
) & s
->irq_enable
& ~s
->fiq_select
;
45 /* Update interrupts. */
46 static void pl190_update(pl190_state
*s
)
48 uint32_t level
= pl190_irq_level(s
);
51 set
= (level
& s
->prio_mask
[s
->priority
]) != 0;
52 qemu_set_irq(s
->irq
, set
);
53 set
= ((s
->level
| s
->soft_level
) & s
->fiq_select
) != 0;
54 qemu_set_irq(s
->fiq
, set
);
57 static void pl190_set_irq(void *opaque
, int irq
, int level
)
59 pl190_state
*s
= (pl190_state
*)opaque
;
62 s
->level
|= 1u << irq
;
64 s
->level
&= ~(1u << irq
);
68 static void pl190_update_vectors(pl190_state
*s
)
75 for (i
= 0; i
< 16; i
++)
77 s
->prio_mask
[i
] = mask
;
78 if (s
->vect_control
[i
] & 0x20)
80 n
= s
->vect_control
[i
] & 0x1f;
84 s
->prio_mask
[16] = mask
;
88 static uint64_t pl190_read(void *opaque
, target_phys_addr_t offset
,
91 pl190_state
*s
= (pl190_state
*)opaque
;
94 if (offset
>= 0xfe0 && offset
< 0x1000) {
95 return pl190_id
[(offset
- 0xfe0) >> 2];
97 if (offset
>= 0x100 && offset
< 0x140) {
98 return s
->vect_addr
[(offset
- 0x100) >> 2];
100 if (offset
>= 0x200 && offset
< 0x240) {
101 return s
->vect_control
[(offset
- 0x200) >> 2];
103 switch (offset
>> 2) {
104 case 0: /* IRQSTATUS */
105 return pl190_irq_level(s
);
106 case 1: /* FIQSATUS */
107 return (s
->level
| s
->soft_level
) & s
->fiq_select
;
108 case 2: /* RAWINTR */
109 return s
->level
| s
->soft_level
;
110 case 3: /* INTSELECT */
111 return s
->fiq_select
;
112 case 4: /* INTENABLE */
113 return s
->irq_enable
;
114 case 6: /* SOFTINT */
115 return s
->soft_level
;
116 case 8: /* PROTECTION */
118 case 12: /* VECTADDR */
119 /* Read vector address at the start of an ISR. Increases the
120 current priority level to that of the current interrupt. */
121 for (i
= 0; i
< s
->priority
; i
++)
123 if ((s
->level
| s
->soft_level
) & s
->prio_mask
[i
])
126 /* Reading this value with no pending interrupts is undefined.
127 We return the default address. */
128 if (i
== PL190_NUM_PRIO
)
129 return s
->vect_addr
[16];
132 s
->prev_prio
[i
] = s
->priority
;
136 return s
->vect_addr
[s
->priority
];
137 case 13: /* DEFVECTADDR */
138 return s
->vect_addr
[16];
140 hw_error("pl190_read: Bad offset %x\n", (int)offset
);
145 static void pl190_write(void *opaque
, target_phys_addr_t offset
,
146 uint64_t val
, unsigned size
)
148 pl190_state
*s
= (pl190_state
*)opaque
;
150 if (offset
>= 0x100 && offset
< 0x140) {
151 s
->vect_addr
[(offset
- 0x100) >> 2] = val
;
152 pl190_update_vectors(s
);
155 if (offset
>= 0x200 && offset
< 0x240) {
156 s
->vect_control
[(offset
- 0x200) >> 2] = val
;
157 pl190_update_vectors(s
);
160 switch (offset
>> 2) {
162 /* This is a readonly register, but linux tries to write to it
163 anyway. Ignore the write. */
165 case 3: /* INTSELECT */
168 case 4: /* INTENABLE */
169 s
->irq_enable
|= val
;
171 case 5: /* INTENCLEAR */
172 s
->irq_enable
&= ~val
;
174 case 6: /* SOFTINT */
175 s
->soft_level
|= val
;
177 case 7: /* SOFTINTCLEAR */
178 s
->soft_level
&= ~val
;
180 case 8: /* PROTECTION */
181 /* TODO: Protection (supervisor only access) is not implemented. */
182 s
->protected = val
& 1;
184 case 12: /* VECTADDR */
185 /* Restore the previous priority level. The value written is
187 if (s
->priority
< PL190_NUM_PRIO
)
188 s
->priority
= s
->prev_prio
[s
->priority
];
190 case 13: /* DEFVECTADDR */
191 s
->vect_addr
[16] = val
;
193 case 0xc0: /* ITCR */
195 hw_error("pl190: Test mode not implemented\n");
199 hw_error("pl190_write: Bad offset %x\n", (int)offset
);
205 static const MemoryRegionOps pl190_ops
= {
207 .write
= pl190_write
,
208 .endianness
= DEVICE_NATIVE_ENDIAN
,
211 static void pl190_reset(DeviceState
*d
)
213 pl190_state
*s
= DO_UPCAST(pl190_state
, busdev
.qdev
, d
);
216 for (i
= 0; i
< 16; i
++)
219 s
->vect_control
[i
] = 0;
221 s
->vect_addr
[16] = 0;
222 s
->prio_mask
[17] = 0xffffffff;
223 s
->priority
= PL190_NUM_PRIO
;
224 pl190_update_vectors(s
);
227 static int pl190_init(SysBusDevice
*dev
)
229 pl190_state
*s
= FROM_SYSBUS(pl190_state
, dev
);
231 memory_region_init_io(&s
->iomem
, &pl190_ops
, s
, "pl190", 0x1000);
232 sysbus_init_mmio(dev
, &s
->iomem
);
233 qdev_init_gpio_in(&dev
->qdev
, pl190_set_irq
, 32);
234 sysbus_init_irq(dev
, &s
->irq
);
235 sysbus_init_irq(dev
, &s
->fiq
);
239 static const VMStateDescription vmstate_pl190
= {
242 .minimum_version_id
= 1,
243 .fields
= (VMStateField
[]) {
244 VMSTATE_UINT32(level
, pl190_state
),
245 VMSTATE_UINT32(soft_level
, pl190_state
),
246 VMSTATE_UINT32(irq_enable
, pl190_state
),
247 VMSTATE_UINT32(fiq_select
, pl190_state
),
248 VMSTATE_UINT8_ARRAY(vect_control
, pl190_state
, 16),
249 VMSTATE_UINT32_ARRAY(vect_addr
, pl190_state
, PL190_NUM_PRIO
),
250 VMSTATE_UINT32_ARRAY(prio_mask
, pl190_state
, PL190_NUM_PRIO
+1),
251 VMSTATE_INT32(protected, pl190_state
),
252 VMSTATE_INT32(priority
, pl190_state
),
253 VMSTATE_INT32_ARRAY(prev_prio
, pl190_state
, PL190_NUM_PRIO
),
254 VMSTATE_END_OF_LIST()
258 static SysBusDeviceInfo pl190_info
= {
260 .qdev
.name
= "pl190",
261 .qdev
.size
= sizeof(pl190_state
),
262 .qdev
.vmsd
= &vmstate_pl190
,
263 .qdev
.reset
= pl190_reset
,
267 static void pl190_register_devices(void)
269 sysbus_register_withprop(&pl190_info
);
272 device_init(pl190_register_devices
)