root / hw / pl190.c @ a8a358bf
History | View | Annotate | Download (6.4 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
2 | cdbdb648 | pbrook | * Arm PrimeCell PL190 Vector Interrupt Controller
|
3 | cdbdb648 | pbrook | *
|
4 | cdbdb648 | pbrook | * Copyright (c) 2006 CodeSourcery.
|
5 | cdbdb648 | pbrook | * Written by Paul Brook
|
6 | cdbdb648 | pbrook | *
|
7 | cdbdb648 | pbrook | * This code is licenced under the GPL.
|
8 | cdbdb648 | pbrook | */
|
9 | cdbdb648 | pbrook | |
10 | 97aff481 | Paul Brook | #include "sysbus.h" |
11 | cdbdb648 | pbrook | |
12 | cdbdb648 | pbrook | /* The number of virtual priority levels. 16 user vectors plus the
|
13 | cdbdb648 | pbrook | unvectored IRQ. Chained interrupts would require an additional level
|
14 | cdbdb648 | pbrook | if implemented. */
|
15 | cdbdb648 | pbrook | |
16 | cdbdb648 | pbrook | #define PL190_NUM_PRIO 17 |
17 | cdbdb648 | pbrook | |
18 | cdbdb648 | pbrook | typedef struct { |
19 | 97aff481 | Paul Brook | SysBusDevice busdev; |
20 | cdbdb648 | pbrook | uint32_t level; |
21 | cdbdb648 | pbrook | uint32_t soft_level; |
22 | cdbdb648 | pbrook | uint32_t irq_enable; |
23 | cdbdb648 | pbrook | uint32_t fiq_select; |
24 | cdbdb648 | pbrook | uint32_t default_addr; |
25 | cdbdb648 | pbrook | uint8_t vect_control[16];
|
26 | cdbdb648 | pbrook | uint32_t vect_addr[PL190_NUM_PRIO]; |
27 | cdbdb648 | pbrook | /* Mask containing interrupts with higher priority than this one. */
|
28 | cdbdb648 | pbrook | uint32_t prio_mask[PL190_NUM_PRIO + 1];
|
29 | cdbdb648 | pbrook | int protected;
|
30 | cdbdb648 | pbrook | /* Current priority level. */
|
31 | cdbdb648 | pbrook | int priority;
|
32 | cdbdb648 | pbrook | int prev_prio[PL190_NUM_PRIO];
|
33 | d537cf6c | pbrook | qemu_irq irq; |
34 | d537cf6c | pbrook | qemu_irq fiq; |
35 | cdbdb648 | pbrook | } pl190_state; |
36 | cdbdb648 | pbrook | |
37 | cdbdb648 | pbrook | static const unsigned char pl190_id[] = |
38 | cdbdb648 | pbrook | { 0x90, 0x11, 0x04, 0x00, 0x0D, 0xf0, 0x05, 0xb1 }; |
39 | cdbdb648 | pbrook | |
40 | cdbdb648 | pbrook | static inline uint32_t pl190_irq_level(pl190_state *s) |
41 | cdbdb648 | pbrook | { |
42 | cdbdb648 | pbrook | return (s->level | s->soft_level) & s->irq_enable & ~s->fiq_select;
|
43 | cdbdb648 | pbrook | } |
44 | cdbdb648 | pbrook | |
45 | cdbdb648 | pbrook | /* Update interrupts. */
|
46 | cdbdb648 | pbrook | static void pl190_update(pl190_state *s) |
47 | cdbdb648 | pbrook | { |
48 | cdbdb648 | pbrook | uint32_t level = pl190_irq_level(s); |
49 | cdbdb648 | pbrook | int set;
|
50 | cdbdb648 | pbrook | |
51 | cdbdb648 | pbrook | set = (level & s->prio_mask[s->priority]) != 0;
|
52 | d537cf6c | pbrook | qemu_set_irq(s->irq, set); |
53 | cdbdb648 | pbrook | set = ((s->level | s->soft_level) & s->fiq_select) != 0;
|
54 | d537cf6c | pbrook | qemu_set_irq(s->fiq, set); |
55 | cdbdb648 | pbrook | } |
56 | cdbdb648 | pbrook | |
57 | cdbdb648 | pbrook | static void pl190_set_irq(void *opaque, int irq, int level) |
58 | cdbdb648 | pbrook | { |
59 | cdbdb648 | pbrook | pl190_state *s = (pl190_state *)opaque; |
60 | cdbdb648 | pbrook | |
61 | cdbdb648 | pbrook | if (level)
|
62 | cdbdb648 | pbrook | s->level |= 1u << irq;
|
63 | cdbdb648 | pbrook | else
|
64 | cdbdb648 | pbrook | s->level &= ~(1u << irq);
|
65 | cdbdb648 | pbrook | pl190_update(s); |
66 | cdbdb648 | pbrook | } |
67 | cdbdb648 | pbrook | |
68 | cdbdb648 | pbrook | static void pl190_update_vectors(pl190_state *s) |
69 | cdbdb648 | pbrook | { |
70 | cdbdb648 | pbrook | uint32_t mask; |
71 | cdbdb648 | pbrook | int i;
|
72 | cdbdb648 | pbrook | int n;
|
73 | cdbdb648 | pbrook | |
74 | cdbdb648 | pbrook | mask = 0;
|
75 | cdbdb648 | pbrook | for (i = 0; i < 16; i++) |
76 | cdbdb648 | pbrook | { |
77 | cdbdb648 | pbrook | s->prio_mask[i] = mask; |
78 | cdbdb648 | pbrook | if (s->vect_control[i] & 0x20) |
79 | cdbdb648 | pbrook | { |
80 | cdbdb648 | pbrook | n = s->vect_control[i] & 0x1f;
|
81 | cdbdb648 | pbrook | mask |= 1 << n;
|
82 | cdbdb648 | pbrook | } |
83 | cdbdb648 | pbrook | } |
84 | cdbdb648 | pbrook | s->prio_mask[16] = mask;
|
85 | cdbdb648 | pbrook | pl190_update(s); |
86 | cdbdb648 | pbrook | } |
87 | cdbdb648 | pbrook | |
88 | cdbdb648 | pbrook | static uint32_t pl190_read(void *opaque, target_phys_addr_t offset) |
89 | cdbdb648 | pbrook | { |
90 | cdbdb648 | pbrook | pl190_state *s = (pl190_state *)opaque; |
91 | cdbdb648 | pbrook | int i;
|
92 | cdbdb648 | pbrook | |
93 | cdbdb648 | pbrook | if (offset >= 0xfe0 && offset < 0x1000) { |
94 | cdbdb648 | pbrook | return pl190_id[(offset - 0xfe0) >> 2]; |
95 | cdbdb648 | pbrook | } |
96 | cdbdb648 | pbrook | if (offset >= 0x100 && offset < 0x140) { |
97 | cdbdb648 | pbrook | return s->vect_addr[(offset - 0x100) >> 2]; |
98 | cdbdb648 | pbrook | } |
99 | cdbdb648 | pbrook | if (offset >= 0x200 && offset < 0x240) { |
100 | cdbdb648 | pbrook | return s->vect_control[(offset - 0x200) >> 2]; |
101 | cdbdb648 | pbrook | } |
102 | cdbdb648 | pbrook | switch (offset >> 2) { |
103 | cdbdb648 | pbrook | case 0: /* IRQSTATUS */ |
104 | cdbdb648 | pbrook | return pl190_irq_level(s);
|
105 | cdbdb648 | pbrook | case 1: /* FIQSATUS */ |
106 | cdbdb648 | pbrook | return (s->level | s->soft_level) & s->fiq_select;
|
107 | cdbdb648 | pbrook | case 2: /* RAWINTR */ |
108 | cdbdb648 | pbrook | return s->level | s->soft_level;
|
109 | cdbdb648 | pbrook | case 3: /* INTSELECT */ |
110 | cdbdb648 | pbrook | return s->fiq_select;
|
111 | cdbdb648 | pbrook | case 4: /* INTENABLE */ |
112 | cdbdb648 | pbrook | return s->irq_enable;
|
113 | cdbdb648 | pbrook | case 6: /* SOFTINT */ |
114 | cdbdb648 | pbrook | return s->soft_level;
|
115 | cdbdb648 | pbrook | case 8: /* PROTECTION */ |
116 | cdbdb648 | pbrook | return s->protected;
|
117 | cdbdb648 | pbrook | case 12: /* VECTADDR */ |
118 | cdbdb648 | pbrook | /* Read vector address at the start of an ISR. Increases the
|
119 | cdbdb648 | pbrook | current priority level to that of the current interrupt. */
|
120 | cdbdb648 | pbrook | for (i = 0; i < s->priority; i++) |
121 | cdbdb648 | pbrook | { |
122 | cdbdb648 | pbrook | if ((s->level | s->soft_level) & s->prio_mask[i])
|
123 | cdbdb648 | pbrook | break;
|
124 | cdbdb648 | pbrook | } |
125 | cdbdb648 | pbrook | /* Reading this value with no pending interrupts is undefined.
|
126 | cdbdb648 | pbrook | We return the default address. */
|
127 | cdbdb648 | pbrook | if (i == PL190_NUM_PRIO)
|
128 | cdbdb648 | pbrook | return s->vect_addr[16]; |
129 | cdbdb648 | pbrook | if (i < s->priority)
|
130 | cdbdb648 | pbrook | { |
131 | cdbdb648 | pbrook | s->prev_prio[i] = s->priority; |
132 | cdbdb648 | pbrook | s->priority = i; |
133 | cdbdb648 | pbrook | pl190_update(s); |
134 | cdbdb648 | pbrook | } |
135 | cdbdb648 | pbrook | return s->vect_addr[s->priority];
|
136 | cdbdb648 | pbrook | case 13: /* DEFVECTADDR */ |
137 | cdbdb648 | pbrook | return s->vect_addr[16]; |
138 | cdbdb648 | pbrook | default:
|
139 | 2ac71179 | Paul Brook | hw_error("pl190_read: Bad offset %x\n", (int)offset); |
140 | cdbdb648 | pbrook | return 0; |
141 | cdbdb648 | pbrook | } |
142 | cdbdb648 | pbrook | } |
143 | cdbdb648 | pbrook | |
144 | cdbdb648 | pbrook | static void pl190_write(void *opaque, target_phys_addr_t offset, uint32_t val) |
145 | cdbdb648 | pbrook | { |
146 | cdbdb648 | pbrook | pl190_state *s = (pl190_state *)opaque; |
147 | cdbdb648 | pbrook | |
148 | cdbdb648 | pbrook | if (offset >= 0x100 && offset < 0x140) { |
149 | cdbdb648 | pbrook | s->vect_addr[(offset - 0x100) >> 2] = val; |
150 | cdbdb648 | pbrook | pl190_update_vectors(s); |
151 | cdbdb648 | pbrook | return;
|
152 | cdbdb648 | pbrook | } |
153 | cdbdb648 | pbrook | if (offset >= 0x200 && offset < 0x240) { |
154 | cdbdb648 | pbrook | s->vect_control[(offset - 0x200) >> 2] = val; |
155 | cdbdb648 | pbrook | pl190_update_vectors(s); |
156 | cdbdb648 | pbrook | return;
|
157 | cdbdb648 | pbrook | } |
158 | cdbdb648 | pbrook | switch (offset >> 2) { |
159 | cdbdb648 | pbrook | case 0: /* SELECT */ |
160 | cdbdb648 | pbrook | /* This is a readonly register, but linux tries to write to it
|
161 | cdbdb648 | pbrook | anyway. Ignore the write. */
|
162 | cdbdb648 | pbrook | break;
|
163 | cdbdb648 | pbrook | case 3: /* INTSELECT */ |
164 | cdbdb648 | pbrook | s->fiq_select = val; |
165 | cdbdb648 | pbrook | break;
|
166 | cdbdb648 | pbrook | case 4: /* INTENABLE */ |
167 | cdbdb648 | pbrook | s->irq_enable |= val; |
168 | cdbdb648 | pbrook | break;
|
169 | cdbdb648 | pbrook | case 5: /* INTENCLEAR */ |
170 | cdbdb648 | pbrook | s->irq_enable &= ~val; |
171 | cdbdb648 | pbrook | break;
|
172 | cdbdb648 | pbrook | case 6: /* SOFTINT */ |
173 | cdbdb648 | pbrook | s->soft_level |= val; |
174 | cdbdb648 | pbrook | break;
|
175 | cdbdb648 | pbrook | case 7: /* SOFTINTCLEAR */ |
176 | cdbdb648 | pbrook | s->soft_level &= ~val; |
177 | cdbdb648 | pbrook | break;
|
178 | cdbdb648 | pbrook | case 8: /* PROTECTION */ |
179 | cdbdb648 | pbrook | /* TODO: Protection (supervisor only access) is not implemented. */
|
180 | cdbdb648 | pbrook | s->protected = val & 1;
|
181 | cdbdb648 | pbrook | break;
|
182 | cdbdb648 | pbrook | case 12: /* VECTADDR */ |
183 | cdbdb648 | pbrook | /* Restore the previous priority level. The value written is
|
184 | cdbdb648 | pbrook | ignored. */
|
185 | cdbdb648 | pbrook | if (s->priority < PL190_NUM_PRIO)
|
186 | cdbdb648 | pbrook | s->priority = s->prev_prio[s->priority]; |
187 | cdbdb648 | pbrook | break;
|
188 | cdbdb648 | pbrook | case 13: /* DEFVECTADDR */ |
189 | cdbdb648 | pbrook | s->default_addr = val; |
190 | cdbdb648 | pbrook | break;
|
191 | cdbdb648 | pbrook | case 0xc0: /* ITCR */ |
192 | 2ac71179 | Paul Brook | if (val) {
|
193 | 2ac71179 | Paul Brook | hw_error("pl190: Test mode not implemented\n");
|
194 | 2ac71179 | Paul Brook | } |
195 | cdbdb648 | pbrook | break;
|
196 | cdbdb648 | pbrook | default:
|
197 | 2ac71179 | Paul Brook | hw_error("pl190_write: Bad offset %x\n", (int)offset); |
198 | cdbdb648 | pbrook | return;
|
199 | cdbdb648 | pbrook | } |
200 | cdbdb648 | pbrook | pl190_update(s); |
201 | cdbdb648 | pbrook | } |
202 | cdbdb648 | pbrook | |
203 | d60efc6b | Blue Swirl | static CPUReadMemoryFunc * const pl190_readfn[] = { |
204 | cdbdb648 | pbrook | pl190_read, |
205 | cdbdb648 | pbrook | pl190_read, |
206 | cdbdb648 | pbrook | pl190_read |
207 | cdbdb648 | pbrook | }; |
208 | cdbdb648 | pbrook | |
209 | d60efc6b | Blue Swirl | static CPUWriteMemoryFunc * const pl190_writefn[] = { |
210 | cdbdb648 | pbrook | pl190_write, |
211 | cdbdb648 | pbrook | pl190_write, |
212 | cdbdb648 | pbrook | pl190_write |
213 | cdbdb648 | pbrook | }; |
214 | cdbdb648 | pbrook | |
215 | 9596ebb7 | pbrook | static void pl190_reset(pl190_state *s) |
216 | cdbdb648 | pbrook | { |
217 | cdbdb648 | pbrook | int i;
|
218 | cdbdb648 | pbrook | |
219 | cdbdb648 | pbrook | for (i = 0; i < 16; i++) |
220 | cdbdb648 | pbrook | { |
221 | cdbdb648 | pbrook | s->vect_addr[i] = 0;
|
222 | cdbdb648 | pbrook | s->vect_control[i] = 0;
|
223 | cdbdb648 | pbrook | } |
224 | cdbdb648 | pbrook | s->vect_addr[16] = 0; |
225 | cdbdb648 | pbrook | s->prio_mask[17] = 0xffffffff; |
226 | cdbdb648 | pbrook | s->priority = PL190_NUM_PRIO; |
227 | cdbdb648 | pbrook | pl190_update_vectors(s); |
228 | cdbdb648 | pbrook | } |
229 | cdbdb648 | pbrook | |
230 | 97aff481 | Paul Brook | static void pl190_init(SysBusDevice *dev) |
231 | cdbdb648 | pbrook | { |
232 | 97aff481 | Paul Brook | pl190_state *s = FROM_SYSBUS(pl190_state, dev); |
233 | cdbdb648 | pbrook | int iomemtype;
|
234 | cdbdb648 | pbrook | |
235 | 1eed09cb | Avi Kivity | iomemtype = cpu_register_io_memory(pl190_readfn, |
236 | cdbdb648 | pbrook | pl190_writefn, s); |
237 | 97aff481 | Paul Brook | sysbus_init_mmio(dev, 0x1000, iomemtype);
|
238 | 067a3ddc | Paul Brook | qdev_init_gpio_in(&dev->qdev, pl190_set_irq, 32);
|
239 | 97aff481 | Paul Brook | sysbus_init_irq(dev, &s->irq); |
240 | 97aff481 | Paul Brook | sysbus_init_irq(dev, &s->fiq); |
241 | cdbdb648 | pbrook | pl190_reset(s); |
242 | cdbdb648 | pbrook | /* ??? Save/restore. */
|
243 | cdbdb648 | pbrook | } |
244 | 97aff481 | Paul Brook | |
245 | 97aff481 | Paul Brook | static void pl190_register_devices(void) |
246 | 97aff481 | Paul Brook | { |
247 | 97aff481 | Paul Brook | sysbus_register_dev("pl190", sizeof(pl190_state), pl190_init); |
248 | 97aff481 | Paul Brook | } |
249 | 97aff481 | Paul Brook | |
250 | 97aff481 | Paul Brook | device_init(pl190_register_devices) |