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