2 * Arm PrimeCell PL190 Vector Interrupt Controller
4 * Copyright (c) 2006 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licenced under the GPL.
13 /* The number of virtual priority levels. 16 user vectors plus the
14 unvectored IRQ. Chained interrupts would require an additional level
17 #define PL190_NUM_PRIO 17
20 arm_pic_handler handler
;
27 uint32_t default_addr
;
28 uint8_t vect_control
[16];
29 uint32_t vect_addr
[PL190_NUM_PRIO
];
30 /* Mask containing interrupts with higher priority than this one. */
31 uint32_t prio_mask
[PL190_NUM_PRIO
+ 1];
33 /* Current priority level. */
35 int prev_prio
[PL190_NUM_PRIO
];
41 static const unsigned char pl190_id
[] =
42 { 0x90, 0x11, 0x04, 0x00, 0x0D, 0xf0, 0x05, 0xb1 };
44 static inline uint32_t pl190_irq_level(pl190_state
*s
)
46 return (s
->level
| s
->soft_level
) & s
->irq_enable
& ~s
->fiq_select
;
49 /* Update interrupts. */
50 static void pl190_update(pl190_state
*s
)
52 uint32_t level
= pl190_irq_level(s
);
55 set
= (level
& s
->prio_mask
[s
->priority
]) != 0;
56 pic_set_irq_new(s
->parent
, s
->irq
, set
);
57 set
= ((s
->level
| s
->soft_level
) & s
->fiq_select
) != 0;
58 pic_set_irq_new(s
->parent
, s
->fiq
, set
);
61 static void pl190_set_irq(void *opaque
, int irq
, int level
)
63 pl190_state
*s
= (pl190_state
*)opaque
;
66 s
->level
|= 1u << irq
;
68 s
->level
&= ~(1u << irq
);
72 static void pl190_update_vectors(pl190_state
*s
)
79 for (i
= 0; i
< 16; i
++)
81 s
->prio_mask
[i
] = mask
;
82 if (s
->vect_control
[i
] & 0x20)
84 n
= s
->vect_control
[i
] & 0x1f;
88 s
->prio_mask
[16] = mask
;
92 static uint32_t pl190_read(void *opaque
, target_phys_addr_t offset
)
94 pl190_state
*s
= (pl190_state
*)opaque
;
98 if (offset
>= 0xfe0 && offset
< 0x1000) {
99 return pl190_id
[(offset
- 0xfe0) >> 2];
101 if (offset
>= 0x100 && offset
< 0x140) {
102 return s
->vect_addr
[(offset
- 0x100) >> 2];
104 if (offset
>= 0x200 && offset
< 0x240) {
105 return s
->vect_control
[(offset
- 0x200) >> 2];
107 switch (offset
>> 2) {
108 case 0: /* IRQSTATUS */
109 return pl190_irq_level(s
);
110 case 1: /* FIQSATUS */
111 return (s
->level
| s
->soft_level
) & s
->fiq_select
;
112 case 2: /* RAWINTR */
113 return s
->level
| s
->soft_level
;
114 case 3: /* INTSELECT */
115 return s
->fiq_select
;
116 case 4: /* INTENABLE */
117 return s
->irq_enable
;
118 case 6: /* SOFTINT */
119 return s
->soft_level
;
120 case 8: /* PROTECTION */
122 case 12: /* VECTADDR */
123 /* Read vector address at the start of an ISR. Increases the
124 current priority level to that of the current interrupt. */
125 for (i
= 0; i
< s
->priority
; i
++)
127 if ((s
->level
| s
->soft_level
) & s
->prio_mask
[i
])
130 /* Reading this value with no pending interrupts is undefined.
131 We return the default address. */
132 if (i
== PL190_NUM_PRIO
)
133 return s
->vect_addr
[16];
136 s
->prev_prio
[i
] = s
->priority
;
140 return s
->vect_addr
[s
->priority
];
141 case 13: /* DEFVECTADDR */
142 return s
->vect_addr
[16];
144 cpu_abort (cpu_single_env
, "pl190_read: Bad offset %x\n", offset
);
149 static void pl190_write(void *opaque
, target_phys_addr_t offset
, uint32_t val
)
151 pl190_state
*s
= (pl190_state
*)opaque
;
154 if (offset
>= 0x100 && offset
< 0x140) {
155 s
->vect_addr
[(offset
- 0x100) >> 2] = val
;
156 pl190_update_vectors(s
);
159 if (offset
>= 0x200 && offset
< 0x240) {
160 s
->vect_control
[(offset
- 0x200) >> 2] = val
;
161 pl190_update_vectors(s
);
164 switch (offset
>> 2) {
166 /* This is a readonly register, but linux tries to write to it
167 anyway. Ignore the write. */
169 case 3: /* INTSELECT */
172 case 4: /* INTENABLE */
173 s
->irq_enable
|= val
;
175 case 5: /* INTENCLEAR */
176 s
->irq_enable
&= ~val
;
178 case 6: /* SOFTINT */
179 s
->soft_level
|= val
;
181 case 7: /* SOFTINTCLEAR */
182 s
->soft_level
&= ~val
;
184 case 8: /* PROTECTION */
185 /* TODO: Protection (supervisor only access) is not implemented. */
186 s
->protected = val
& 1;
188 case 12: /* VECTADDR */
189 /* Restore the previous priority level. The value written is
191 if (s
->priority
< PL190_NUM_PRIO
)
192 s
->priority
= s
->prev_prio
[s
->priority
];
194 case 13: /* DEFVECTADDR */
195 s
->default_addr
= val
;
197 case 0xc0: /* ITCR */
199 cpu_abort(cpu_single_env
, "pl190: Test mode not implemented\n");
202 cpu_abort(cpu_single_env
, "pl190_write: Bad offset %x\n", offset
);
208 static CPUReadMemoryFunc
*pl190_readfn
[] = {
214 static CPUWriteMemoryFunc
*pl190_writefn
[] = {
220 void pl190_reset(pl190_state
*s
)
224 for (i
= 0; i
< 16; i
++)
227 s
->vect_control
[i
] = 0;
229 s
->vect_addr
[16] = 0;
230 s
->prio_mask
[17] = 0xffffffff;
231 s
->priority
= PL190_NUM_PRIO
;
232 pl190_update_vectors(s
);
235 void *pl190_init(uint32_t base
, void *parent
, int irq
, int fiq
)
240 s
= (pl190_state
*)qemu_mallocz(sizeof(pl190_state
));
241 iomemtype
= cpu_register_io_memory(0, pl190_readfn
,
243 cpu_register_physical_memory(base
, 0x00000fff, iomemtype
);
244 s
->handler
= pl190_set_irq
;
250 /* ??? Save/restore. */