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