root / hw / arm_gic.c @ 9a6ee9fd
History | View | Annotate | Download (21.5 kB)
1 | 5fafdf24 | ths | /*
|
---|---|---|---|
2 | 9ee6e8bb | pbrook | * ARM Generic/Distributed Interrupt Controller
|
3 | e69954b9 | pbrook | *
|
4 | 9ee6e8bb | pbrook | * Copyright (c) 2006-2007 CodeSourcery.
|
5 | e69954b9 | pbrook | * Written by Paul Brook
|
6 | e69954b9 | pbrook | *
|
7 | 8e31bf38 | Matthew Fernandez | * This code is licensed under the GPL.
|
8 | e69954b9 | pbrook | */
|
9 | e69954b9 | pbrook | |
10 | 9ee6e8bb | pbrook | /* This file contains implementation code for the RealView EB interrupt
|
11 | 0d256bdc | Peter Maydell | * controller, MPCore distributed interrupt controller and ARMv7-M
|
12 | 0d256bdc | Peter Maydell | * Nested Vectored Interrupt Controller.
|
13 | 0d256bdc | Peter Maydell | * It is compiled in two ways:
|
14 | 0d256bdc | Peter Maydell | * (1) as a standalone file to produce a sysbus device which is a GIC
|
15 | 0d256bdc | Peter Maydell | * that can be used on the realview board and as one of the builtin
|
16 | 0d256bdc | Peter Maydell | * private peripherals for the ARM MP CPUs (11MPCore, A9, etc)
|
17 | 0d256bdc | Peter Maydell | * (2) by being directly #included into armv7m_nvic.c to produce the
|
18 | 0d256bdc | Peter Maydell | * armv7m_nvic device.
|
19 | 0d256bdc | Peter Maydell | */
|
20 | e69954b9 | pbrook | |
21 | 496dbcd1 | Peter Maydell | #include "sysbus.h" |
22 | 1e8cae4d | Peter Maydell | #include "arm_gic_internal.h" |
23 | 386e2955 | Peter Maydell | |
24 | e69954b9 | pbrook | //#define DEBUG_GIC
|
25 | e69954b9 | pbrook | |
26 | e69954b9 | pbrook | #ifdef DEBUG_GIC
|
27 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) \
|
28 | 5eb98401 | Peter A. G. Crosthwaite | do { fprintf(stderr, "arm_gic: " fmt , ## __VA_ARGS__); } while (0) |
29 | e69954b9 | pbrook | #else
|
30 | 001faf32 | Blue Swirl | #define DPRINTF(fmt, ...) do {} while(0) |
31 | e69954b9 | pbrook | #endif
|
32 | e69954b9 | pbrook | |
33 | 2a29ddee | Peter Maydell | static const uint8_t gic_id[] = { |
34 | 2a29ddee | Peter Maydell | 0x90, 0x13, 0x04, 0x00, 0x0d, 0xf0, 0x05, 0xb1 |
35 | 2a29ddee | Peter Maydell | }; |
36 | 2a29ddee | Peter Maydell | |
37 | c988bfad | Paul Brook | #define NUM_CPU(s) ((s)->num_cpu)
|
38 | 9ee6e8bb | pbrook | |
39 | fae15286 | Peter Maydell | static inline int gic_get_current_cpu(GICState *s) |
40 | 926c4aff | Peter Maydell | { |
41 | 926c4aff | Peter Maydell | if (s->num_cpu > 1) { |
42 | 55e5c285 | Andreas Färber | CPUState *cpu = ENV_GET_CPU(cpu_single_env); |
43 | 55e5c285 | Andreas Färber | return cpu->cpu_index;
|
44 | 926c4aff | Peter Maydell | } |
45 | 926c4aff | Peter Maydell | return 0; |
46 | 926c4aff | Peter Maydell | } |
47 | 926c4aff | Peter Maydell | |
48 | e69954b9 | pbrook | /* TODO: Many places that call this routine could be optimized. */
|
49 | e69954b9 | pbrook | /* Update interrupt status after enabled or pending bits have been changed. */
|
50 | fae15286 | Peter Maydell | void gic_update(GICState *s)
|
51 | e69954b9 | pbrook | { |
52 | e69954b9 | pbrook | int best_irq;
|
53 | e69954b9 | pbrook | int best_prio;
|
54 | e69954b9 | pbrook | int irq;
|
55 | 9ee6e8bb | pbrook | int level;
|
56 | 9ee6e8bb | pbrook | int cpu;
|
57 | 9ee6e8bb | pbrook | int cm;
|
58 | 9ee6e8bb | pbrook | |
59 | c988bfad | Paul Brook | for (cpu = 0; cpu < NUM_CPU(s); cpu++) { |
60 | 9ee6e8bb | pbrook | cm = 1 << cpu;
|
61 | 9ee6e8bb | pbrook | s->current_pending[cpu] = 1023;
|
62 | 9ee6e8bb | pbrook | if (!s->enabled || !s->cpu_enabled[cpu]) {
|
63 | c79981ce | Peter Maydell | qemu_irq_lower(s->parent_irq[cpu]); |
64 | 9ee6e8bb | pbrook | return;
|
65 | 9ee6e8bb | pbrook | } |
66 | 9ee6e8bb | pbrook | best_prio = 0x100;
|
67 | 9ee6e8bb | pbrook | best_irq = 1023;
|
68 | a32134aa | Mark Langsdorf | for (irq = 0; irq < s->num_irq; irq++) { |
69 | 41bf234d | Rabin Vincent | if (GIC_TEST_ENABLED(irq, cm) && GIC_TEST_PENDING(irq, cm)) {
|
70 | 9ee6e8bb | pbrook | if (GIC_GET_PRIORITY(irq, cpu) < best_prio) {
|
71 | 9ee6e8bb | pbrook | best_prio = GIC_GET_PRIORITY(irq, cpu); |
72 | 9ee6e8bb | pbrook | best_irq = irq; |
73 | 9ee6e8bb | pbrook | } |
74 | e69954b9 | pbrook | } |
75 | e69954b9 | pbrook | } |
76 | 9ee6e8bb | pbrook | level = 0;
|
77 | cad065f1 | Peter Maydell | if (best_prio < s->priority_mask[cpu]) {
|
78 | 9ee6e8bb | pbrook | s->current_pending[cpu] = best_irq; |
79 | 9ee6e8bb | pbrook | if (best_prio < s->running_priority[cpu]) {
|
80 | 8c815fb3 | Peter Crosthwaite | DPRINTF("Raised pending IRQ %d (cpu %d)\n", best_irq, cpu);
|
81 | 9ee6e8bb | pbrook | level = 1;
|
82 | 9ee6e8bb | pbrook | } |
83 | e69954b9 | pbrook | } |
84 | 9ee6e8bb | pbrook | qemu_set_irq(s->parent_irq[cpu], level); |
85 | e69954b9 | pbrook | } |
86 | e69954b9 | pbrook | } |
87 | e69954b9 | pbrook | |
88 | fae15286 | Peter Maydell | void gic_set_pending_private(GICState *s, int cpu, int irq) |
89 | 9ee6e8bb | pbrook | { |
90 | 9ee6e8bb | pbrook | int cm = 1 << cpu; |
91 | 9ee6e8bb | pbrook | |
92 | 9ee6e8bb | pbrook | if (GIC_TEST_PENDING(irq, cm))
|
93 | 9ee6e8bb | pbrook | return;
|
94 | 9ee6e8bb | pbrook | |
95 | 9ee6e8bb | pbrook | DPRINTF("Set %d pending cpu %d\n", irq, cpu);
|
96 | 9ee6e8bb | pbrook | GIC_SET_PENDING(irq, cm); |
97 | 9ee6e8bb | pbrook | gic_update(s); |
98 | 9ee6e8bb | pbrook | } |
99 | 9ee6e8bb | pbrook | |
100 | 9ee6e8bb | pbrook | /* Process a change in an external IRQ input. */
|
101 | e69954b9 | pbrook | static void gic_set_irq(void *opaque, int irq, int level) |
102 | e69954b9 | pbrook | { |
103 | 544d1afa | Peter Maydell | /* Meaning of the 'irq' parameter:
|
104 | 544d1afa | Peter Maydell | * [0..N-1] : external interrupts
|
105 | 544d1afa | Peter Maydell | * [N..N+31] : PPI (internal) interrupts for CPU 0
|
106 | 544d1afa | Peter Maydell | * [N+32..N+63] : PPI (internal interrupts for CPU 1
|
107 | 544d1afa | Peter Maydell | * ...
|
108 | 544d1afa | Peter Maydell | */
|
109 | fae15286 | Peter Maydell | GICState *s = (GICState *)opaque; |
110 | 544d1afa | Peter Maydell | int cm, target;
|
111 | 544d1afa | Peter Maydell | if (irq < (s->num_irq - GIC_INTERNAL)) {
|
112 | 544d1afa | Peter Maydell | /* The first external input line is internal interrupt 32. */
|
113 | 544d1afa | Peter Maydell | cm = ALL_CPU_MASK; |
114 | 544d1afa | Peter Maydell | irq += GIC_INTERNAL; |
115 | 544d1afa | Peter Maydell | target = GIC_TARGET(irq); |
116 | 544d1afa | Peter Maydell | } else {
|
117 | 544d1afa | Peter Maydell | int cpu;
|
118 | 544d1afa | Peter Maydell | irq -= (s->num_irq - GIC_INTERNAL); |
119 | 544d1afa | Peter Maydell | cpu = irq / GIC_INTERNAL; |
120 | 544d1afa | Peter Maydell | irq %= GIC_INTERNAL; |
121 | 544d1afa | Peter Maydell | cm = 1 << cpu;
|
122 | 544d1afa | Peter Maydell | target = cm; |
123 | 544d1afa | Peter Maydell | } |
124 | 544d1afa | Peter Maydell | |
125 | 544d1afa | Peter Maydell | if (level == GIC_TEST_LEVEL(irq, cm)) {
|
126 | e69954b9 | pbrook | return;
|
127 | 544d1afa | Peter Maydell | } |
128 | e69954b9 | pbrook | |
129 | e69954b9 | pbrook | if (level) {
|
130 | 544d1afa | Peter Maydell | GIC_SET_LEVEL(irq, cm); |
131 | 544d1afa | Peter Maydell | if (GIC_TEST_TRIGGER(irq) || GIC_TEST_ENABLED(irq, cm)) {
|
132 | 544d1afa | Peter Maydell | DPRINTF("Set %d pending mask %x\n", irq, target);
|
133 | 544d1afa | Peter Maydell | GIC_SET_PENDING(irq, target); |
134 | e69954b9 | pbrook | } |
135 | e69954b9 | pbrook | } else {
|
136 | 544d1afa | Peter Maydell | GIC_CLEAR_LEVEL(irq, cm); |
137 | e69954b9 | pbrook | } |
138 | e69954b9 | pbrook | gic_update(s); |
139 | e69954b9 | pbrook | } |
140 | e69954b9 | pbrook | |
141 | fae15286 | Peter Maydell | static void gic_set_running_irq(GICState *s, int cpu, int irq) |
142 | e69954b9 | pbrook | { |
143 | 9ee6e8bb | pbrook | s->running_irq[cpu] = irq; |
144 | 9ee6e8bb | pbrook | if (irq == 1023) { |
145 | 9ee6e8bb | pbrook | s->running_priority[cpu] = 0x100;
|
146 | 9ee6e8bb | pbrook | } else {
|
147 | 9ee6e8bb | pbrook | s->running_priority[cpu] = GIC_GET_PRIORITY(irq, cpu); |
148 | 9ee6e8bb | pbrook | } |
149 | e69954b9 | pbrook | gic_update(s); |
150 | e69954b9 | pbrook | } |
151 | e69954b9 | pbrook | |
152 | fae15286 | Peter Maydell | uint32_t gic_acknowledge_irq(GICState *s, int cpu)
|
153 | e69954b9 | pbrook | { |
154 | e69954b9 | pbrook | int new_irq;
|
155 | 9ee6e8bb | pbrook | int cm = 1 << cpu; |
156 | 9ee6e8bb | pbrook | new_irq = s->current_pending[cpu]; |
157 | 9ee6e8bb | pbrook | if (new_irq == 1023 |
158 | 9ee6e8bb | pbrook | || GIC_GET_PRIORITY(new_irq, cpu) >= s->running_priority[cpu]) { |
159 | e69954b9 | pbrook | DPRINTF("ACK no pending IRQ\n");
|
160 | e69954b9 | pbrook | return 1023; |
161 | e69954b9 | pbrook | } |
162 | 9ee6e8bb | pbrook | s->last_active[new_irq][cpu] = s->running_irq[cpu]; |
163 | 9ee6e8bb | pbrook | /* Clear pending flags for both level and edge triggered interrupts.
|
164 | 9ee6e8bb | pbrook | Level triggered IRQs will be reasserted once they become inactive. */
|
165 | 9ee6e8bb | pbrook | GIC_CLEAR_PENDING(new_irq, GIC_TEST_MODEL(new_irq) ? ALL_CPU_MASK : cm); |
166 | 9ee6e8bb | pbrook | gic_set_running_irq(s, cpu, new_irq); |
167 | e69954b9 | pbrook | DPRINTF("ACK %d\n", new_irq);
|
168 | e69954b9 | pbrook | return new_irq;
|
169 | e69954b9 | pbrook | } |
170 | e69954b9 | pbrook | |
171 | fae15286 | Peter Maydell | void gic_complete_irq(GICState *s, int cpu, int irq) |
172 | e69954b9 | pbrook | { |
173 | e69954b9 | pbrook | int update = 0; |
174 | 9ee6e8bb | pbrook | int cm = 1 << cpu; |
175 | df628ff1 | pbrook | DPRINTF("EOI %d\n", irq);
|
176 | a32134aa | Mark Langsdorf | if (irq >= s->num_irq) {
|
177 | 217bfb44 | Peter Maydell | /* This handles two cases:
|
178 | 217bfb44 | Peter Maydell | * 1. If software writes the ID of a spurious interrupt [ie 1023]
|
179 | 217bfb44 | Peter Maydell | * to the GICC_EOIR, the GIC ignores that write.
|
180 | 217bfb44 | Peter Maydell | * 2. If software writes the number of a non-existent interrupt
|
181 | 217bfb44 | Peter Maydell | * this must be a subcase of "value written does not match the last
|
182 | 217bfb44 | Peter Maydell | * valid interrupt value read from the Interrupt Acknowledge
|
183 | 217bfb44 | Peter Maydell | * register" and so this is UNPREDICTABLE. We choose to ignore it.
|
184 | 217bfb44 | Peter Maydell | */
|
185 | 217bfb44 | Peter Maydell | return;
|
186 | 217bfb44 | Peter Maydell | } |
187 | 9ee6e8bb | pbrook | if (s->running_irq[cpu] == 1023) |
188 | e69954b9 | pbrook | return; /* No active IRQ. */ |
189 | 217bfb44 | Peter Maydell | /* Mark level triggered interrupts as pending if they are still
|
190 | 217bfb44 | Peter Maydell | raised. */
|
191 | 217bfb44 | Peter Maydell | if (!GIC_TEST_TRIGGER(irq) && GIC_TEST_ENABLED(irq, cm)
|
192 | 217bfb44 | Peter Maydell | && GIC_TEST_LEVEL(irq, cm) && (GIC_TARGET(irq) & cm) != 0) {
|
193 | 217bfb44 | Peter Maydell | DPRINTF("Set %d pending mask %x\n", irq, cm);
|
194 | 217bfb44 | Peter Maydell | GIC_SET_PENDING(irq, cm); |
195 | 217bfb44 | Peter Maydell | update = 1;
|
196 | e69954b9 | pbrook | } |
197 | 9ee6e8bb | pbrook | if (irq != s->running_irq[cpu]) {
|
198 | e69954b9 | pbrook | /* Complete an IRQ that is not currently running. */
|
199 | 9ee6e8bb | pbrook | int tmp = s->running_irq[cpu];
|
200 | 9ee6e8bb | pbrook | while (s->last_active[tmp][cpu] != 1023) { |
201 | 9ee6e8bb | pbrook | if (s->last_active[tmp][cpu] == irq) {
|
202 | 9ee6e8bb | pbrook | s->last_active[tmp][cpu] = s->last_active[irq][cpu]; |
203 | e69954b9 | pbrook | break;
|
204 | e69954b9 | pbrook | } |
205 | 9ee6e8bb | pbrook | tmp = s->last_active[tmp][cpu]; |
206 | e69954b9 | pbrook | } |
207 | e69954b9 | pbrook | if (update) {
|
208 | e69954b9 | pbrook | gic_update(s); |
209 | e69954b9 | pbrook | } |
210 | e69954b9 | pbrook | } else {
|
211 | e69954b9 | pbrook | /* Complete the current running IRQ. */
|
212 | 9ee6e8bb | pbrook | gic_set_running_irq(s, cpu, s->last_active[s->running_irq[cpu]][cpu]); |
213 | e69954b9 | pbrook | } |
214 | e69954b9 | pbrook | } |
215 | e69954b9 | pbrook | |
216 | a8170e5e | Avi Kivity | static uint32_t gic_dist_readb(void *opaque, hwaddr offset) |
217 | e69954b9 | pbrook | { |
218 | fae15286 | Peter Maydell | GICState *s = (GICState *)opaque; |
219 | e69954b9 | pbrook | uint32_t res; |
220 | e69954b9 | pbrook | int irq;
|
221 | e69954b9 | pbrook | int i;
|
222 | 9ee6e8bb | pbrook | int cpu;
|
223 | 9ee6e8bb | pbrook | int cm;
|
224 | 9ee6e8bb | pbrook | int mask;
|
225 | e69954b9 | pbrook | |
226 | 926c4aff | Peter Maydell | cpu = gic_get_current_cpu(s); |
227 | 9ee6e8bb | pbrook | cm = 1 << cpu;
|
228 | e69954b9 | pbrook | if (offset < 0x100) { |
229 | e69954b9 | pbrook | if (offset == 0) |
230 | e69954b9 | pbrook | return s->enabled;
|
231 | e69954b9 | pbrook | if (offset == 4) |
232 | a32134aa | Mark Langsdorf | return ((s->num_irq / 32) - 1) | ((NUM_CPU(s) - 1) << 5); |
233 | e69954b9 | pbrook | if (offset < 0x08) |
234 | e69954b9 | pbrook | return 0; |
235 | b79f2265 | Rob Herring | if (offset >= 0x80) { |
236 | b79f2265 | Rob Herring | /* Interrupt Security , RAZ/WI */
|
237 | b79f2265 | Rob Herring | return 0; |
238 | b79f2265 | Rob Herring | } |
239 | e69954b9 | pbrook | goto bad_reg;
|
240 | e69954b9 | pbrook | } else if (offset < 0x200) { |
241 | e69954b9 | pbrook | /* Interrupt Set/Clear Enable. */
|
242 | e69954b9 | pbrook | if (offset < 0x180) |
243 | e69954b9 | pbrook | irq = (offset - 0x100) * 8; |
244 | e69954b9 | pbrook | else
|
245 | e69954b9 | pbrook | irq = (offset - 0x180) * 8; |
246 | 9ee6e8bb | pbrook | irq += GIC_BASE_IRQ; |
247 | a32134aa | Mark Langsdorf | if (irq >= s->num_irq)
|
248 | e69954b9 | pbrook | goto bad_reg;
|
249 | e69954b9 | pbrook | res = 0;
|
250 | e69954b9 | pbrook | for (i = 0; i < 8; i++) { |
251 | 41bf234d | Rabin Vincent | if (GIC_TEST_ENABLED(irq + i, cm)) {
|
252 | e69954b9 | pbrook | res |= (1 << i);
|
253 | e69954b9 | pbrook | } |
254 | e69954b9 | pbrook | } |
255 | e69954b9 | pbrook | } else if (offset < 0x300) { |
256 | e69954b9 | pbrook | /* Interrupt Set/Clear Pending. */
|
257 | e69954b9 | pbrook | if (offset < 0x280) |
258 | e69954b9 | pbrook | irq = (offset - 0x200) * 8; |
259 | e69954b9 | pbrook | else
|
260 | e69954b9 | pbrook | irq = (offset - 0x280) * 8; |
261 | 9ee6e8bb | pbrook | irq += GIC_BASE_IRQ; |
262 | a32134aa | Mark Langsdorf | if (irq >= s->num_irq)
|
263 | e69954b9 | pbrook | goto bad_reg;
|
264 | e69954b9 | pbrook | res = 0;
|
265 | 69253800 | Rusty Russell | mask = (irq < GIC_INTERNAL) ? cm : ALL_CPU_MASK; |
266 | e69954b9 | pbrook | for (i = 0; i < 8; i++) { |
267 | 9ee6e8bb | pbrook | if (GIC_TEST_PENDING(irq + i, mask)) {
|
268 | e69954b9 | pbrook | res |= (1 << i);
|
269 | e69954b9 | pbrook | } |
270 | e69954b9 | pbrook | } |
271 | e69954b9 | pbrook | } else if (offset < 0x400) { |
272 | e69954b9 | pbrook | /* Interrupt Active. */
|
273 | 9ee6e8bb | pbrook | irq = (offset - 0x300) * 8 + GIC_BASE_IRQ; |
274 | a32134aa | Mark Langsdorf | if (irq >= s->num_irq)
|
275 | e69954b9 | pbrook | goto bad_reg;
|
276 | e69954b9 | pbrook | res = 0;
|
277 | 69253800 | Rusty Russell | mask = (irq < GIC_INTERNAL) ? cm : ALL_CPU_MASK; |
278 | e69954b9 | pbrook | for (i = 0; i < 8; i++) { |
279 | 9ee6e8bb | pbrook | if (GIC_TEST_ACTIVE(irq + i, mask)) {
|
280 | e69954b9 | pbrook | res |= (1 << i);
|
281 | e69954b9 | pbrook | } |
282 | e69954b9 | pbrook | } |
283 | e69954b9 | pbrook | } else if (offset < 0x800) { |
284 | e69954b9 | pbrook | /* Interrupt Priority. */
|
285 | 9ee6e8bb | pbrook | irq = (offset - 0x400) + GIC_BASE_IRQ;
|
286 | a32134aa | Mark Langsdorf | if (irq >= s->num_irq)
|
287 | e69954b9 | pbrook | goto bad_reg;
|
288 | 9ee6e8bb | pbrook | res = GIC_GET_PRIORITY(irq, cpu); |
289 | e69954b9 | pbrook | } else if (offset < 0xc00) { |
290 | e69954b9 | pbrook | /* Interrupt CPU Target. */
|
291 | 6b9680bb | Peter Maydell | if (s->num_cpu == 1 && s->revision != REV_11MPCORE) { |
292 | 6b9680bb | Peter Maydell | /* For uniprocessor GICs these RAZ/WI */
|
293 | 6b9680bb | Peter Maydell | res = 0;
|
294 | 9ee6e8bb | pbrook | } else {
|
295 | 6b9680bb | Peter Maydell | irq = (offset - 0x800) + GIC_BASE_IRQ;
|
296 | 6b9680bb | Peter Maydell | if (irq >= s->num_irq) {
|
297 | 6b9680bb | Peter Maydell | goto bad_reg;
|
298 | 6b9680bb | Peter Maydell | } |
299 | 6b9680bb | Peter Maydell | if (irq >= 29 && irq <= 31) { |
300 | 6b9680bb | Peter Maydell | res = cm; |
301 | 6b9680bb | Peter Maydell | } else {
|
302 | 6b9680bb | Peter Maydell | res = GIC_TARGET(irq); |
303 | 6b9680bb | Peter Maydell | } |
304 | 9ee6e8bb | pbrook | } |
305 | e69954b9 | pbrook | } else if (offset < 0xf00) { |
306 | e69954b9 | pbrook | /* Interrupt Configuration. */
|
307 | 9ee6e8bb | pbrook | irq = (offset - 0xc00) * 2 + GIC_BASE_IRQ; |
308 | a32134aa | Mark Langsdorf | if (irq >= s->num_irq)
|
309 | e69954b9 | pbrook | goto bad_reg;
|
310 | e69954b9 | pbrook | res = 0;
|
311 | e69954b9 | pbrook | for (i = 0; i < 4; i++) { |
312 | e69954b9 | pbrook | if (GIC_TEST_MODEL(irq + i))
|
313 | e69954b9 | pbrook | res |= (1 << (i * 2)); |
314 | e69954b9 | pbrook | if (GIC_TEST_TRIGGER(irq + i))
|
315 | e69954b9 | pbrook | res |= (2 << (i * 2)); |
316 | e69954b9 | pbrook | } |
317 | e69954b9 | pbrook | } else if (offset < 0xfe0) { |
318 | e69954b9 | pbrook | goto bad_reg;
|
319 | e69954b9 | pbrook | } else /* offset >= 0xfe0 */ { |
320 | e69954b9 | pbrook | if (offset & 3) { |
321 | e69954b9 | pbrook | res = 0;
|
322 | e69954b9 | pbrook | } else {
|
323 | e69954b9 | pbrook | res = gic_id[(offset - 0xfe0) >> 2]; |
324 | e69954b9 | pbrook | } |
325 | e69954b9 | pbrook | } |
326 | e69954b9 | pbrook | return res;
|
327 | e69954b9 | pbrook | bad_reg:
|
328 | 8c8dc39f | Peter Maydell | qemu_log_mask(LOG_GUEST_ERROR, |
329 | 8c8dc39f | Peter Maydell | "gic_dist_readb: Bad offset %x\n", (int)offset); |
330 | e69954b9 | pbrook | return 0; |
331 | e69954b9 | pbrook | } |
332 | e69954b9 | pbrook | |
333 | a8170e5e | Avi Kivity | static uint32_t gic_dist_readw(void *opaque, hwaddr offset) |
334 | e69954b9 | pbrook | { |
335 | e69954b9 | pbrook | uint32_t val; |
336 | e69954b9 | pbrook | val = gic_dist_readb(opaque, offset); |
337 | e69954b9 | pbrook | val |= gic_dist_readb(opaque, offset + 1) << 8; |
338 | e69954b9 | pbrook | return val;
|
339 | e69954b9 | pbrook | } |
340 | e69954b9 | pbrook | |
341 | a8170e5e | Avi Kivity | static uint32_t gic_dist_readl(void *opaque, hwaddr offset) |
342 | e69954b9 | pbrook | { |
343 | e69954b9 | pbrook | uint32_t val; |
344 | e69954b9 | pbrook | val = gic_dist_readw(opaque, offset); |
345 | e69954b9 | pbrook | val |= gic_dist_readw(opaque, offset + 2) << 16; |
346 | e69954b9 | pbrook | return val;
|
347 | e69954b9 | pbrook | } |
348 | e69954b9 | pbrook | |
349 | a8170e5e | Avi Kivity | static void gic_dist_writeb(void *opaque, hwaddr offset, |
350 | e69954b9 | pbrook | uint32_t value) |
351 | e69954b9 | pbrook | { |
352 | fae15286 | Peter Maydell | GICState *s = (GICState *)opaque; |
353 | e69954b9 | pbrook | int irq;
|
354 | e69954b9 | pbrook | int i;
|
355 | 9ee6e8bb | pbrook | int cpu;
|
356 | e69954b9 | pbrook | |
357 | 926c4aff | Peter Maydell | cpu = gic_get_current_cpu(s); |
358 | e69954b9 | pbrook | if (offset < 0x100) { |
359 | e69954b9 | pbrook | if (offset == 0) { |
360 | e69954b9 | pbrook | s->enabled = (value & 1);
|
361 | e69954b9 | pbrook | DPRINTF("Distribution %sabled\n", s->enabled ? "En" : "Dis"); |
362 | e69954b9 | pbrook | } else if (offset < 4) { |
363 | e69954b9 | pbrook | /* ignored. */
|
364 | b79f2265 | Rob Herring | } else if (offset >= 0x80) { |
365 | b79f2265 | Rob Herring | /* Interrupt Security Registers, RAZ/WI */
|
366 | e69954b9 | pbrook | } else {
|
367 | e69954b9 | pbrook | goto bad_reg;
|
368 | e69954b9 | pbrook | } |
369 | e69954b9 | pbrook | } else if (offset < 0x180) { |
370 | e69954b9 | pbrook | /* Interrupt Set Enable. */
|
371 | 9ee6e8bb | pbrook | irq = (offset - 0x100) * 8 + GIC_BASE_IRQ; |
372 | a32134aa | Mark Langsdorf | if (irq >= s->num_irq)
|
373 | e69954b9 | pbrook | goto bad_reg;
|
374 | 9ee6e8bb | pbrook | if (irq < 16) |
375 | 9ee6e8bb | pbrook | value = 0xff;
|
376 | e69954b9 | pbrook | for (i = 0; i < 8; i++) { |
377 | e69954b9 | pbrook | if (value & (1 << i)) { |
378 | f47b48fb | Daniel Sangorrin | int mask =
|
379 | f47b48fb | Daniel Sangorrin | (irq < GIC_INTERNAL) ? (1 << cpu) : GIC_TARGET(irq + i);
|
380 | 69253800 | Rusty Russell | int cm = (irq < GIC_INTERNAL) ? (1 << cpu) : ALL_CPU_MASK; |
381 | 41bf234d | Rabin Vincent | |
382 | 41bf234d | Rabin Vincent | if (!GIC_TEST_ENABLED(irq + i, cm)) {
|
383 | e69954b9 | pbrook | DPRINTF("Enabled IRQ %d\n", irq + i);
|
384 | 41bf234d | Rabin Vincent | } |
385 | 41bf234d | Rabin Vincent | GIC_SET_ENABLED(irq + i, cm); |
386 | e69954b9 | pbrook | /* If a raised level triggered IRQ enabled then mark
|
387 | e69954b9 | pbrook | is as pending. */
|
388 | 9ee6e8bb | pbrook | if (GIC_TEST_LEVEL(irq + i, mask)
|
389 | 9ee6e8bb | pbrook | && !GIC_TEST_TRIGGER(irq + i)) { |
390 | 9ee6e8bb | pbrook | DPRINTF("Set %d pending mask %x\n", irq + i, mask);
|
391 | 9ee6e8bb | pbrook | GIC_SET_PENDING(irq + i, mask); |
392 | 9ee6e8bb | pbrook | } |
393 | e69954b9 | pbrook | } |
394 | e69954b9 | pbrook | } |
395 | e69954b9 | pbrook | } else if (offset < 0x200) { |
396 | e69954b9 | pbrook | /* Interrupt Clear Enable. */
|
397 | 9ee6e8bb | pbrook | irq = (offset - 0x180) * 8 + GIC_BASE_IRQ; |
398 | a32134aa | Mark Langsdorf | if (irq >= s->num_irq)
|
399 | e69954b9 | pbrook | goto bad_reg;
|
400 | 9ee6e8bb | pbrook | if (irq < 16) |
401 | 9ee6e8bb | pbrook | value = 0;
|
402 | e69954b9 | pbrook | for (i = 0; i < 8; i++) { |
403 | e69954b9 | pbrook | if (value & (1 << i)) { |
404 | 69253800 | Rusty Russell | int cm = (irq < GIC_INTERNAL) ? (1 << cpu) : ALL_CPU_MASK; |
405 | 41bf234d | Rabin Vincent | |
406 | 41bf234d | Rabin Vincent | if (GIC_TEST_ENABLED(irq + i, cm)) {
|
407 | e69954b9 | pbrook | DPRINTF("Disabled IRQ %d\n", irq + i);
|
408 | 41bf234d | Rabin Vincent | } |
409 | 41bf234d | Rabin Vincent | GIC_CLEAR_ENABLED(irq + i, cm); |
410 | e69954b9 | pbrook | } |
411 | e69954b9 | pbrook | } |
412 | e69954b9 | pbrook | } else if (offset < 0x280) { |
413 | e69954b9 | pbrook | /* Interrupt Set Pending. */
|
414 | 9ee6e8bb | pbrook | irq = (offset - 0x200) * 8 + GIC_BASE_IRQ; |
415 | a32134aa | Mark Langsdorf | if (irq >= s->num_irq)
|
416 | e69954b9 | pbrook | goto bad_reg;
|
417 | 9ee6e8bb | pbrook | if (irq < 16) |
418 | 9ee6e8bb | pbrook | irq = 0;
|
419 | 9ee6e8bb | pbrook | |
420 | e69954b9 | pbrook | for (i = 0; i < 8; i++) { |
421 | e69954b9 | pbrook | if (value & (1 << i)) { |
422 | f47b48fb | Daniel Sangorrin | GIC_SET_PENDING(irq + i, GIC_TARGET(irq + i)); |
423 | e69954b9 | pbrook | } |
424 | e69954b9 | pbrook | } |
425 | e69954b9 | pbrook | } else if (offset < 0x300) { |
426 | e69954b9 | pbrook | /* Interrupt Clear Pending. */
|
427 | 9ee6e8bb | pbrook | irq = (offset - 0x280) * 8 + GIC_BASE_IRQ; |
428 | a32134aa | Mark Langsdorf | if (irq >= s->num_irq)
|
429 | e69954b9 | pbrook | goto bad_reg;
|
430 | e69954b9 | pbrook | for (i = 0; i < 8; i++) { |
431 | 9ee6e8bb | pbrook | /* ??? This currently clears the pending bit for all CPUs, even
|
432 | 9ee6e8bb | pbrook | for per-CPU interrupts. It's unclear whether this is the
|
433 | 9ee6e8bb | pbrook | corect behavior. */
|
434 | e69954b9 | pbrook | if (value & (1 << i)) { |
435 | 9ee6e8bb | pbrook | GIC_CLEAR_PENDING(irq + i, ALL_CPU_MASK); |
436 | e69954b9 | pbrook | } |
437 | e69954b9 | pbrook | } |
438 | e69954b9 | pbrook | } else if (offset < 0x400) { |
439 | e69954b9 | pbrook | /* Interrupt Active. */
|
440 | e69954b9 | pbrook | goto bad_reg;
|
441 | e69954b9 | pbrook | } else if (offset < 0x800) { |
442 | e69954b9 | pbrook | /* Interrupt Priority. */
|
443 | 9ee6e8bb | pbrook | irq = (offset - 0x400) + GIC_BASE_IRQ;
|
444 | a32134aa | Mark Langsdorf | if (irq >= s->num_irq)
|
445 | e69954b9 | pbrook | goto bad_reg;
|
446 | 69253800 | Rusty Russell | if (irq < GIC_INTERNAL) {
|
447 | 9ee6e8bb | pbrook | s->priority1[irq][cpu] = value; |
448 | 9ee6e8bb | pbrook | } else {
|
449 | 69253800 | Rusty Russell | s->priority2[irq - GIC_INTERNAL] = value; |
450 | 9ee6e8bb | pbrook | } |
451 | e69954b9 | pbrook | } else if (offset < 0xc00) { |
452 | 6b9680bb | Peter Maydell | /* Interrupt CPU Target. RAZ/WI on uniprocessor GICs, with the
|
453 | 6b9680bb | Peter Maydell | * annoying exception of the 11MPCore's GIC.
|
454 | 6b9680bb | Peter Maydell | */
|
455 | 6b9680bb | Peter Maydell | if (s->num_cpu != 1 || s->revision == REV_11MPCORE) { |
456 | 6b9680bb | Peter Maydell | irq = (offset - 0x800) + GIC_BASE_IRQ;
|
457 | 6b9680bb | Peter Maydell | if (irq >= s->num_irq) {
|
458 | 6b9680bb | Peter Maydell | goto bad_reg;
|
459 | 6b9680bb | Peter Maydell | } |
460 | 6b9680bb | Peter Maydell | if (irq < 29) { |
461 | 6b9680bb | Peter Maydell | value = 0;
|
462 | 6b9680bb | Peter Maydell | } else if (irq < GIC_INTERNAL) { |
463 | 6b9680bb | Peter Maydell | value = ALL_CPU_MASK; |
464 | 6b9680bb | Peter Maydell | } |
465 | 6b9680bb | Peter Maydell | s->irq_target[irq] = value & ALL_CPU_MASK; |
466 | 6b9680bb | Peter Maydell | } |
467 | e69954b9 | pbrook | } else if (offset < 0xf00) { |
468 | e69954b9 | pbrook | /* Interrupt Configuration. */
|
469 | 9ee6e8bb | pbrook | irq = (offset - 0xc00) * 4 + GIC_BASE_IRQ; |
470 | a32134aa | Mark Langsdorf | if (irq >= s->num_irq)
|
471 | e69954b9 | pbrook | goto bad_reg;
|
472 | 69253800 | Rusty Russell | if (irq < GIC_INTERNAL)
|
473 | 9ee6e8bb | pbrook | value |= 0xaa;
|
474 | e69954b9 | pbrook | for (i = 0; i < 4; i++) { |
475 | e69954b9 | pbrook | if (value & (1 << (i * 2))) { |
476 | e69954b9 | pbrook | GIC_SET_MODEL(irq + i); |
477 | e69954b9 | pbrook | } else {
|
478 | e69954b9 | pbrook | GIC_CLEAR_MODEL(irq + i); |
479 | e69954b9 | pbrook | } |
480 | e69954b9 | pbrook | if (value & (2 << (i * 2))) { |
481 | e69954b9 | pbrook | GIC_SET_TRIGGER(irq + i); |
482 | e69954b9 | pbrook | } else {
|
483 | e69954b9 | pbrook | GIC_CLEAR_TRIGGER(irq + i); |
484 | e69954b9 | pbrook | } |
485 | e69954b9 | pbrook | } |
486 | e69954b9 | pbrook | } else {
|
487 | 9ee6e8bb | pbrook | /* 0xf00 is only handled for 32-bit writes. */
|
488 | e69954b9 | pbrook | goto bad_reg;
|
489 | e69954b9 | pbrook | } |
490 | e69954b9 | pbrook | gic_update(s); |
491 | e69954b9 | pbrook | return;
|
492 | e69954b9 | pbrook | bad_reg:
|
493 | 8c8dc39f | Peter Maydell | qemu_log_mask(LOG_GUEST_ERROR, |
494 | 8c8dc39f | Peter Maydell | "gic_dist_writeb: Bad offset %x\n", (int)offset); |
495 | e69954b9 | pbrook | } |
496 | e69954b9 | pbrook | |
497 | a8170e5e | Avi Kivity | static void gic_dist_writew(void *opaque, hwaddr offset, |
498 | e69954b9 | pbrook | uint32_t value) |
499 | e69954b9 | pbrook | { |
500 | e69954b9 | pbrook | gic_dist_writeb(opaque, offset, value & 0xff);
|
501 | e69954b9 | pbrook | gic_dist_writeb(opaque, offset + 1, value >> 8); |
502 | e69954b9 | pbrook | } |
503 | e69954b9 | pbrook | |
504 | a8170e5e | Avi Kivity | static void gic_dist_writel(void *opaque, hwaddr offset, |
505 | e69954b9 | pbrook | uint32_t value) |
506 | e69954b9 | pbrook | { |
507 | fae15286 | Peter Maydell | GICState *s = (GICState *)opaque; |
508 | 8da3ff18 | pbrook | if (offset == 0xf00) { |
509 | 9ee6e8bb | pbrook | int cpu;
|
510 | 9ee6e8bb | pbrook | int irq;
|
511 | 9ee6e8bb | pbrook | int mask;
|
512 | 9ee6e8bb | pbrook | |
513 | 926c4aff | Peter Maydell | cpu = gic_get_current_cpu(s); |
514 | 9ee6e8bb | pbrook | irq = value & 0x3ff;
|
515 | 9ee6e8bb | pbrook | switch ((value >> 24) & 3) { |
516 | 9ee6e8bb | pbrook | case 0: |
517 | 9ee6e8bb | pbrook | mask = (value >> 16) & ALL_CPU_MASK;
|
518 | 9ee6e8bb | pbrook | break;
|
519 | 9ee6e8bb | pbrook | case 1: |
520 | fa250144 | Adam Lackorzynski | mask = ALL_CPU_MASK ^ (1 << cpu);
|
521 | 9ee6e8bb | pbrook | break;
|
522 | 9ee6e8bb | pbrook | case 2: |
523 | fa250144 | Adam Lackorzynski | mask = 1 << cpu;
|
524 | 9ee6e8bb | pbrook | break;
|
525 | 9ee6e8bb | pbrook | default:
|
526 | 9ee6e8bb | pbrook | DPRINTF("Bad Soft Int target filter\n");
|
527 | 9ee6e8bb | pbrook | mask = ALL_CPU_MASK; |
528 | 9ee6e8bb | pbrook | break;
|
529 | 9ee6e8bb | pbrook | } |
530 | 9ee6e8bb | pbrook | GIC_SET_PENDING(irq, mask); |
531 | 9ee6e8bb | pbrook | gic_update(s); |
532 | 9ee6e8bb | pbrook | return;
|
533 | 9ee6e8bb | pbrook | } |
534 | e69954b9 | pbrook | gic_dist_writew(opaque, offset, value & 0xffff);
|
535 | e69954b9 | pbrook | gic_dist_writew(opaque, offset + 2, value >> 16); |
536 | e69954b9 | pbrook | } |
537 | e69954b9 | pbrook | |
538 | 755c0802 | Avi Kivity | static const MemoryRegionOps gic_dist_ops = { |
539 | 755c0802 | Avi Kivity | .old_mmio = { |
540 | 755c0802 | Avi Kivity | .read = { gic_dist_readb, gic_dist_readw, gic_dist_readl, }, |
541 | 755c0802 | Avi Kivity | .write = { gic_dist_writeb, gic_dist_writew, gic_dist_writel, }, |
542 | 755c0802 | Avi Kivity | }, |
543 | 755c0802 | Avi Kivity | .endianness = DEVICE_NATIVE_ENDIAN, |
544 | e69954b9 | pbrook | }; |
545 | e69954b9 | pbrook | |
546 | fae15286 | Peter Maydell | static uint32_t gic_cpu_read(GICState *s, int cpu, int offset) |
547 | e69954b9 | pbrook | { |
548 | e69954b9 | pbrook | switch (offset) {
|
549 | e69954b9 | pbrook | case 0x00: /* Control */ |
550 | 9ee6e8bb | pbrook | return s->cpu_enabled[cpu];
|
551 | e69954b9 | pbrook | case 0x04: /* Priority mask */ |
552 | 9ee6e8bb | pbrook | return s->priority_mask[cpu];
|
553 | e69954b9 | pbrook | case 0x08: /* Binary Point */ |
554 | e69954b9 | pbrook | /* ??? Not implemented. */
|
555 | e69954b9 | pbrook | return 0; |
556 | e69954b9 | pbrook | case 0x0c: /* Acknowledge */ |
557 | 9ee6e8bb | pbrook | return gic_acknowledge_irq(s, cpu);
|
558 | 66a0a2cb | Dong Xu Wang | case 0x14: /* Running Priority */ |
559 | 9ee6e8bb | pbrook | return s->running_priority[cpu];
|
560 | e69954b9 | pbrook | case 0x18: /* Highest Pending Interrupt */ |
561 | 9ee6e8bb | pbrook | return s->current_pending[cpu];
|
562 | e69954b9 | pbrook | default:
|
563 | 8c8dc39f | Peter Maydell | qemu_log_mask(LOG_GUEST_ERROR, |
564 | 8c8dc39f | Peter Maydell | "gic_cpu_read: Bad offset %x\n", (int)offset); |
565 | e69954b9 | pbrook | return 0; |
566 | e69954b9 | pbrook | } |
567 | e69954b9 | pbrook | } |
568 | e69954b9 | pbrook | |
569 | fae15286 | Peter Maydell | static void gic_cpu_write(GICState *s, int cpu, int offset, uint32_t value) |
570 | e69954b9 | pbrook | { |
571 | e69954b9 | pbrook | switch (offset) {
|
572 | e69954b9 | pbrook | case 0x00: /* Control */ |
573 | 9ee6e8bb | pbrook | s->cpu_enabled[cpu] = (value & 1);
|
574 | 9ab1b605 | Evgeny Voevodin | DPRINTF("CPU %d %sabled\n", cpu, s->cpu_enabled[cpu] ? "En" : "Dis"); |
575 | e69954b9 | pbrook | break;
|
576 | e69954b9 | pbrook | case 0x04: /* Priority mask */ |
577 | 9ee6e8bb | pbrook | s->priority_mask[cpu] = (value & 0xff);
|
578 | e69954b9 | pbrook | break;
|
579 | e69954b9 | pbrook | case 0x08: /* Binary Point */ |
580 | e69954b9 | pbrook | /* ??? Not implemented. */
|
581 | e69954b9 | pbrook | break;
|
582 | e69954b9 | pbrook | case 0x10: /* End Of Interrupt */ |
583 | 9ee6e8bb | pbrook | return gic_complete_irq(s, cpu, value & 0x3ff); |
584 | e69954b9 | pbrook | default:
|
585 | 8c8dc39f | Peter Maydell | qemu_log_mask(LOG_GUEST_ERROR, |
586 | 8c8dc39f | Peter Maydell | "gic_cpu_write: Bad offset %x\n", (int)offset); |
587 | e69954b9 | pbrook | return;
|
588 | e69954b9 | pbrook | } |
589 | e69954b9 | pbrook | gic_update(s); |
590 | e69954b9 | pbrook | } |
591 | e2c56465 | Peter Maydell | |
592 | e2c56465 | Peter Maydell | /* Wrappers to read/write the GIC CPU interface for the current CPU */
|
593 | a8170e5e | Avi Kivity | static uint64_t gic_thiscpu_read(void *opaque, hwaddr addr, |
594 | e2c56465 | Peter Maydell | unsigned size)
|
595 | e2c56465 | Peter Maydell | { |
596 | fae15286 | Peter Maydell | GICState *s = (GICState *)opaque; |
597 | 926c4aff | Peter Maydell | return gic_cpu_read(s, gic_get_current_cpu(s), addr);
|
598 | e2c56465 | Peter Maydell | } |
599 | e2c56465 | Peter Maydell | |
600 | a8170e5e | Avi Kivity | static void gic_thiscpu_write(void *opaque, hwaddr addr, |
601 | e2c56465 | Peter Maydell | uint64_t value, unsigned size)
|
602 | e2c56465 | Peter Maydell | { |
603 | fae15286 | Peter Maydell | GICState *s = (GICState *)opaque; |
604 | 926c4aff | Peter Maydell | gic_cpu_write(s, gic_get_current_cpu(s), addr, value); |
605 | e2c56465 | Peter Maydell | } |
606 | e2c56465 | Peter Maydell | |
607 | e2c56465 | Peter Maydell | /* Wrappers to read/write the GIC CPU interface for a specific CPU.
|
608 | fae15286 | Peter Maydell | * These just decode the opaque pointer into GICState* + cpu id.
|
609 | e2c56465 | Peter Maydell | */
|
610 | a8170e5e | Avi Kivity | static uint64_t gic_do_cpu_read(void *opaque, hwaddr addr, |
611 | e2c56465 | Peter Maydell | unsigned size)
|
612 | e2c56465 | Peter Maydell | { |
613 | fae15286 | Peter Maydell | GICState **backref = (GICState **)opaque; |
614 | fae15286 | Peter Maydell | GICState *s = *backref; |
615 | e2c56465 | Peter Maydell | int id = (backref - s->backref);
|
616 | 0e4a398a | Peter Maydell | return gic_cpu_read(s, id, addr);
|
617 | e2c56465 | Peter Maydell | } |
618 | e2c56465 | Peter Maydell | |
619 | a8170e5e | Avi Kivity | static void gic_do_cpu_write(void *opaque, hwaddr addr, |
620 | e2c56465 | Peter Maydell | uint64_t value, unsigned size)
|
621 | e2c56465 | Peter Maydell | { |
622 | fae15286 | Peter Maydell | GICState **backref = (GICState **)opaque; |
623 | fae15286 | Peter Maydell | GICState *s = *backref; |
624 | e2c56465 | Peter Maydell | int id = (backref - s->backref);
|
625 | 0e4a398a | Peter Maydell | gic_cpu_write(s, id, addr, value); |
626 | e2c56465 | Peter Maydell | } |
627 | e2c56465 | Peter Maydell | |
628 | e2c56465 | Peter Maydell | static const MemoryRegionOps gic_thiscpu_ops = { |
629 | e2c56465 | Peter Maydell | .read = gic_thiscpu_read, |
630 | e2c56465 | Peter Maydell | .write = gic_thiscpu_write, |
631 | e2c56465 | Peter Maydell | .endianness = DEVICE_NATIVE_ENDIAN, |
632 | e2c56465 | Peter Maydell | }; |
633 | e2c56465 | Peter Maydell | |
634 | e2c56465 | Peter Maydell | static const MemoryRegionOps gic_cpu_ops = { |
635 | e2c56465 | Peter Maydell | .read = gic_do_cpu_read, |
636 | e2c56465 | Peter Maydell | .write = gic_do_cpu_write, |
637 | e2c56465 | Peter Maydell | .endianness = DEVICE_NATIVE_ENDIAN, |
638 | e2c56465 | Peter Maydell | }; |
639 | e69954b9 | pbrook | |
640 | fae15286 | Peter Maydell | void gic_init_irqs_and_distributor(GICState *s, int num_irq) |
641 | e69954b9 | pbrook | { |
642 | 23e39294 | pbrook | int i;
|
643 | 41c1e2f5 | Rusty Russell | |
644 | 544d1afa | Peter Maydell | i = s->num_irq - GIC_INTERNAL; |
645 | 544d1afa | Peter Maydell | /* For the GIC, also expose incoming GPIO lines for PPIs for each CPU.
|
646 | 544d1afa | Peter Maydell | * GPIO array layout is thus:
|
647 | 544d1afa | Peter Maydell | * [0..N-1] SPIs
|
648 | 544d1afa | Peter Maydell | * [N..N+31] PPIs for CPU 0
|
649 | 544d1afa | Peter Maydell | * [N+32..N+63] PPIs for CPU 1
|
650 | 544d1afa | Peter Maydell | * ...
|
651 | 544d1afa | Peter Maydell | */
|
652 | 84e4fccb | Peter Maydell | if (s->revision != REV_NVIC) {
|
653 | 84e4fccb | Peter Maydell | i += (GIC_INTERNAL * s->num_cpu); |
654 | 84e4fccb | Peter Maydell | } |
655 | 544d1afa | Peter Maydell | qdev_init_gpio_in(&s->busdev.qdev, gic_set_irq, i); |
656 | c988bfad | Paul Brook | for (i = 0; i < NUM_CPU(s); i++) { |
657 | fe7e8758 | Paul Brook | sysbus_init_irq(&s->busdev, &s->parent_irq[i]); |
658 | e69954b9 | pbrook | } |
659 | 755c0802 | Avi Kivity | memory_region_init_io(&s->iomem, &gic_dist_ops, s, "gic_dist", 0x1000); |
660 | 2b518c56 | Peter Maydell | } |
661 | 2b518c56 | Peter Maydell | |
662 | 2b518c56 | Peter Maydell | static int arm_gic_init(SysBusDevice *dev) |
663 | 2b518c56 | Peter Maydell | { |
664 | 2b518c56 | Peter Maydell | /* Device instance init function for the GIC sysbus device */
|
665 | 2b518c56 | Peter Maydell | int i;
|
666 | fae15286 | Peter Maydell | GICState *s = FROM_SYSBUS(GICState, dev); |
667 | 1e8cae4d | Peter Maydell | ARMGICClass *agc = ARM_GIC_GET_CLASS(s); |
668 | 1e8cae4d | Peter Maydell | |
669 | 1e8cae4d | Peter Maydell | agc->parent_init(dev); |
670 | 1e8cae4d | Peter Maydell | |
671 | 2b518c56 | Peter Maydell | gic_init_irqs_and_distributor(s, s->num_irq); |
672 | 2b518c56 | Peter Maydell | |
673 | e2c56465 | Peter Maydell | /* Memory regions for the CPU interfaces (NVIC doesn't have these):
|
674 | e2c56465 | Peter Maydell | * a region for "CPU interface for this core", then a region for
|
675 | e2c56465 | Peter Maydell | * "CPU interface for core 0", "for core 1", ...
|
676 | e2c56465 | Peter Maydell | * NB that the memory region size of 0x100 applies for the 11MPCore
|
677 | e2c56465 | Peter Maydell | * and also cores following the GIC v1 spec (ie A9).
|
678 | e2c56465 | Peter Maydell | * GIC v2 defines a larger memory region (0x1000) so this will need
|
679 | e2c56465 | Peter Maydell | * to be extended when we implement A15.
|
680 | e2c56465 | Peter Maydell | */
|
681 | e2c56465 | Peter Maydell | memory_region_init_io(&s->cpuiomem[0], &gic_thiscpu_ops, s,
|
682 | e2c56465 | Peter Maydell | "gic_cpu", 0x100); |
683 | e2c56465 | Peter Maydell | for (i = 0; i < NUM_CPU(s); i++) { |
684 | e2c56465 | Peter Maydell | s->backref[i] = s; |
685 | e2c56465 | Peter Maydell | memory_region_init_io(&s->cpuiomem[i+1], &gic_cpu_ops, &s->backref[i],
|
686 | e2c56465 | Peter Maydell | "gic_cpu", 0x100); |
687 | e2c56465 | Peter Maydell | } |
688 | 496dbcd1 | Peter Maydell | /* Distributor */
|
689 | 496dbcd1 | Peter Maydell | sysbus_init_mmio(dev, &s->iomem); |
690 | 496dbcd1 | Peter Maydell | /* cpu interfaces (one for "current cpu" plus one per cpu) */
|
691 | 496dbcd1 | Peter Maydell | for (i = 0; i <= NUM_CPU(s); i++) { |
692 | 496dbcd1 | Peter Maydell | sysbus_init_mmio(dev, &s->cpuiomem[i]); |
693 | 496dbcd1 | Peter Maydell | } |
694 | 496dbcd1 | Peter Maydell | return 0; |
695 | 496dbcd1 | Peter Maydell | } |
696 | 496dbcd1 | Peter Maydell | |
697 | 496dbcd1 | Peter Maydell | static void arm_gic_class_init(ObjectClass *klass, void *data) |
698 | 496dbcd1 | Peter Maydell | { |
699 | 496dbcd1 | Peter Maydell | DeviceClass *dc = DEVICE_CLASS(klass); |
700 | 496dbcd1 | Peter Maydell | SysBusDeviceClass *sbc = SYS_BUS_DEVICE_CLASS(klass); |
701 | 1e8cae4d | Peter Maydell | ARMGICClass *agc = ARM_GIC_CLASS(klass); |
702 | 1e8cae4d | Peter Maydell | agc->parent_init = sbc->init; |
703 | 496dbcd1 | Peter Maydell | sbc->init = arm_gic_init; |
704 | 496dbcd1 | Peter Maydell | dc->no_user = 1;
|
705 | 496dbcd1 | Peter Maydell | } |
706 | 496dbcd1 | Peter Maydell | |
707 | 8c43a6f0 | Andreas Färber | static const TypeInfo arm_gic_info = { |
708 | 1e8cae4d | Peter Maydell | .name = TYPE_ARM_GIC, |
709 | 1e8cae4d | Peter Maydell | .parent = TYPE_ARM_GIC_COMMON, |
710 | fae15286 | Peter Maydell | .instance_size = sizeof(GICState),
|
711 | 496dbcd1 | Peter Maydell | .class_init = arm_gic_class_init, |
712 | 998a74bc | Peter Maydell | .class_size = sizeof(ARMGICClass),
|
713 | 496dbcd1 | Peter Maydell | }; |
714 | 496dbcd1 | Peter Maydell | |
715 | 496dbcd1 | Peter Maydell | static void arm_gic_register_types(void) |
716 | 496dbcd1 | Peter Maydell | { |
717 | 496dbcd1 | Peter Maydell | type_register_static(&arm_gic_info); |
718 | 496dbcd1 | Peter Maydell | } |
719 | 496dbcd1 | Peter Maydell | |
720 | 496dbcd1 | Peter Maydell | type_init(arm_gic_register_types) |