2 * ARM Generic/Distributed Interrupt Controller
4 * Copyright (c) 2006-2007 CodeSourcery.
5 * Written by Paul Brook
7 * This code is licensed under the GPL.
10 /* This file contains implementation code for the RealView EB interrupt
11 controller, MPCore distributed interrupt controller and ARMv7-M
12 Nested Vectored Interrupt Controller. */
17 #define DPRINTF(fmt, ...) \
18 do { printf("arm_gic: " fmt , ## __VA_ARGS__); } while (0)
20 #define DPRINTF(fmt, ...) do {} while(0)
24 static const uint8_t gic_id
[] =
25 { 0x00, 0xb0, 0x1b, 0x00, 0x0d, 0xe0, 0x05, 0xb1 };
26 /* The NVIC has 16 internal vectors. However these are not exposed
27 through the normal GIC interface. */
28 #define GIC_BASE_IRQ 32
30 static const uint8_t gic_id
[] =
31 { 0x90, 0x13, 0x04, 0x00, 0x0d, 0xf0, 0x05, 0xb1 };
32 #define GIC_BASE_IRQ 0
35 #define FROM_SYSBUSGIC(type, dev) \
36 DO_UPCAST(type, gic, FROM_SYSBUS(gic_state, dev))
38 typedef struct gic_irq_state
40 /* The enable bits are only banked for per-cpu interrupts. */
41 unsigned enabled
:NCPU
;
42 unsigned pending
:NCPU
;
45 unsigned model
:1; /* 0 = N:N, 1 = 1:N */
46 unsigned trigger
:1; /* nonzero = edge triggered. */
49 #define ALL_CPU_MASK ((1 << NCPU) - 1)
51 #define NUM_CPU(s) ((s)->num_cpu)
56 #define GIC_SET_ENABLED(irq, cm) s->irq_state[irq].enabled |= (cm)
57 #define GIC_CLEAR_ENABLED(irq, cm) s->irq_state[irq].enabled &= ~(cm)
58 #define GIC_TEST_ENABLED(irq, cm) ((s->irq_state[irq].enabled & (cm)) != 0)
59 #define GIC_SET_PENDING(irq, cm) s->irq_state[irq].pending |= (cm)
60 #define GIC_CLEAR_PENDING(irq, cm) s->irq_state[irq].pending &= ~(cm)
61 #define GIC_TEST_PENDING(irq, cm) ((s->irq_state[irq].pending & (cm)) != 0)
62 #define GIC_SET_ACTIVE(irq, cm) s->irq_state[irq].active |= (cm)
63 #define GIC_CLEAR_ACTIVE(irq, cm) s->irq_state[irq].active &= ~(cm)
64 #define GIC_TEST_ACTIVE(irq, cm) ((s->irq_state[irq].active & (cm)) != 0)
65 #define GIC_SET_MODEL(irq) s->irq_state[irq].model = 1
66 #define GIC_CLEAR_MODEL(irq) s->irq_state[irq].model = 0
67 #define GIC_TEST_MODEL(irq) s->irq_state[irq].model
68 #define GIC_SET_LEVEL(irq, cm) s->irq_state[irq].level = (cm)
69 #define GIC_CLEAR_LEVEL(irq, cm) s->irq_state[irq].level &= ~(cm)
70 #define GIC_TEST_LEVEL(irq, cm) ((s->irq_state[irq].level & (cm)) != 0)
71 #define GIC_SET_TRIGGER(irq) s->irq_state[irq].trigger = 1
72 #define GIC_CLEAR_TRIGGER(irq) s->irq_state[irq].trigger = 0
73 #define GIC_TEST_TRIGGER(irq) s->irq_state[irq].trigger
74 #define GIC_GET_PRIORITY(irq, cpu) \
75 (((irq) < 32) ? s->priority1[irq][cpu] : s->priority2[(irq) - 32])
77 #define GIC_TARGET(irq) 1
79 #define GIC_TARGET(irq) s->irq_target[irq]
82 typedef struct gic_state
85 qemu_irq parent_irq
[NCPU
];
87 int cpu_enabled
[NCPU
];
89 gic_irq_state irq_state
[GIC_NIRQ
];
91 int irq_target
[GIC_NIRQ
];
93 int priority1
[32][NCPU
];
94 int priority2
[GIC_NIRQ
- 32];
95 int last_active
[GIC_NIRQ
][NCPU
];
97 int priority_mask
[NCPU
];
98 int running_irq
[NCPU
];
99 int running_priority
[NCPU
];
100 int current_pending
[NCPU
];
106 MemoryRegion iomem
; /* Distributor */
108 /* This is just so we can have an opaque pointer which identifies
109 * both this GIC and which CPU interface we should be accessing.
111 struct gic_state
*backref
[NCPU
];
112 MemoryRegion cpuiomem
[NCPU
+1]; /* CPU interfaces */
116 /* TODO: Many places that call this routine could be optimized. */
117 /* Update interrupt status after enabled or pending bits have been changed. */
118 static void gic_update(gic_state
*s
)
127 for (cpu
= 0; cpu
< NUM_CPU(s
); cpu
++) {
129 s
->current_pending
[cpu
] = 1023;
130 if (!s
->enabled
|| !s
->cpu_enabled
[cpu
]) {
131 qemu_irq_lower(s
->parent_irq
[cpu
]);
136 for (irq
= 0; irq
< GIC_NIRQ
; irq
++) {
137 if (GIC_TEST_ENABLED(irq
, cm
) && GIC_TEST_PENDING(irq
, cm
)) {
138 if (GIC_GET_PRIORITY(irq
, cpu
) < best_prio
) {
139 best_prio
= GIC_GET_PRIORITY(irq
, cpu
);
145 if (best_prio
<= s
->priority_mask
[cpu
]) {
146 s
->current_pending
[cpu
] = best_irq
;
147 if (best_prio
< s
->running_priority
[cpu
]) {
148 DPRINTF("Raised pending IRQ %d\n", best_irq
);
152 qemu_set_irq(s
->parent_irq
[cpu
], level
);
156 static void __attribute__((unused
))
157 gic_set_pending_private(gic_state
*s
, int cpu
, int irq
)
161 if (GIC_TEST_PENDING(irq
, cm
))
164 DPRINTF("Set %d pending cpu %d\n", irq
, cpu
);
165 GIC_SET_PENDING(irq
, cm
);
169 /* Process a change in an external IRQ input. */
170 static void gic_set_irq(void *opaque
, int irq
, int level
)
172 gic_state
*s
= (gic_state
*)opaque
;
173 /* The first external input line is internal interrupt 32. */
175 if (level
== GIC_TEST_LEVEL(irq
, ALL_CPU_MASK
))
179 GIC_SET_LEVEL(irq
, ALL_CPU_MASK
);
180 if (GIC_TEST_TRIGGER(irq
) || GIC_TEST_ENABLED(irq
, ALL_CPU_MASK
)) {
181 DPRINTF("Set %d pending mask %x\n", irq
, GIC_TARGET(irq
));
182 GIC_SET_PENDING(irq
, GIC_TARGET(irq
));
185 GIC_CLEAR_LEVEL(irq
, ALL_CPU_MASK
);
190 static void gic_set_running_irq(gic_state
*s
, int cpu
, int irq
)
192 s
->running_irq
[cpu
] = irq
;
194 s
->running_priority
[cpu
] = 0x100;
196 s
->running_priority
[cpu
] = GIC_GET_PRIORITY(irq
, cpu
);
201 static uint32_t gic_acknowledge_irq(gic_state
*s
, int cpu
)
205 new_irq
= s
->current_pending
[cpu
];
207 || GIC_GET_PRIORITY(new_irq
, cpu
) >= s
->running_priority
[cpu
]) {
208 DPRINTF("ACK no pending IRQ\n");
211 s
->last_active
[new_irq
][cpu
] = s
->running_irq
[cpu
];
212 /* Clear pending flags for both level and edge triggered interrupts.
213 Level triggered IRQs will be reasserted once they become inactive. */
214 GIC_CLEAR_PENDING(new_irq
, GIC_TEST_MODEL(new_irq
) ? ALL_CPU_MASK
: cm
);
215 gic_set_running_irq(s
, cpu
, new_irq
);
216 DPRINTF("ACK %d\n", new_irq
);
220 static void gic_complete_irq(gic_state
* s
, int cpu
, int irq
)
224 DPRINTF("EOI %d\n", irq
);
225 if (irq
>= GIC_NIRQ
) {
226 /* This handles two cases:
227 * 1. If software writes the ID of a spurious interrupt [ie 1023]
228 * to the GICC_EOIR, the GIC ignores that write.
229 * 2. If software writes the number of a non-existent interrupt
230 * this must be a subcase of "value written does not match the last
231 * valid interrupt value read from the Interrupt Acknowledge
232 * register" and so this is UNPREDICTABLE. We choose to ignore it.
236 if (s
->running_irq
[cpu
] == 1023)
237 return; /* No active IRQ. */
238 /* Mark level triggered interrupts as pending if they are still
240 if (!GIC_TEST_TRIGGER(irq
) && GIC_TEST_ENABLED(irq
, cm
)
241 && GIC_TEST_LEVEL(irq
, cm
) && (GIC_TARGET(irq
) & cm
) != 0) {
242 DPRINTF("Set %d pending mask %x\n", irq
, cm
);
243 GIC_SET_PENDING(irq
, cm
);
246 if (irq
!= s
->running_irq
[cpu
]) {
247 /* Complete an IRQ that is not currently running. */
248 int tmp
= s
->running_irq
[cpu
];
249 while (s
->last_active
[tmp
][cpu
] != 1023) {
250 if (s
->last_active
[tmp
][cpu
] == irq
) {
251 s
->last_active
[tmp
][cpu
] = s
->last_active
[irq
][cpu
];
254 tmp
= s
->last_active
[tmp
][cpu
];
260 /* Complete the current running IRQ. */
261 gic_set_running_irq(s
, cpu
, s
->last_active
[s
->running_irq
[cpu
]][cpu
]);
265 static uint32_t gic_dist_readb(void *opaque
, target_phys_addr_t offset
)
267 gic_state
*s
= (gic_state
*)opaque
;
275 cpu
= gic_get_current_cpu();
277 if (offset
< 0x100) {
282 return ((GIC_NIRQ
/ 32) - 1) | ((NUM_CPU(s
) - 1) << 5);
287 } else if (offset
< 0x200) {
288 /* Interrupt Set/Clear Enable. */
290 irq
= (offset
- 0x100) * 8;
292 irq
= (offset
- 0x180) * 8;
297 for (i
= 0; i
< 8; i
++) {
298 if (GIC_TEST_ENABLED(irq
+ i
, cm
)) {
302 } else if (offset
< 0x300) {
303 /* Interrupt Set/Clear Pending. */
305 irq
= (offset
- 0x200) * 8;
307 irq
= (offset
- 0x280) * 8;
312 mask
= (irq
< 32) ? cm
: ALL_CPU_MASK
;
313 for (i
= 0; i
< 8; i
++) {
314 if (GIC_TEST_PENDING(irq
+ i
, mask
)) {
318 } else if (offset
< 0x400) {
319 /* Interrupt Active. */
320 irq
= (offset
- 0x300) * 8 + GIC_BASE_IRQ
;
324 mask
= (irq
< 32) ? cm
: ALL_CPU_MASK
;
325 for (i
= 0; i
< 8; i
++) {
326 if (GIC_TEST_ACTIVE(irq
+ i
, mask
)) {
330 } else if (offset
< 0x800) {
331 /* Interrupt Priority. */
332 irq
= (offset
- 0x400) + GIC_BASE_IRQ
;
335 res
= GIC_GET_PRIORITY(irq
, cpu
);
337 } else if (offset
< 0xc00) {
338 /* Interrupt CPU Target. */
339 irq
= (offset
- 0x800) + GIC_BASE_IRQ
;
342 if (irq
>= 29 && irq
<= 31) {
345 res
= GIC_TARGET(irq
);
347 } else if (offset
< 0xf00) {
348 /* Interrupt Configuration. */
349 irq
= (offset
- 0xc00) * 2 + GIC_BASE_IRQ
;
353 for (i
= 0; i
< 4; i
++) {
354 if (GIC_TEST_MODEL(irq
+ i
))
355 res
|= (1 << (i
* 2));
356 if (GIC_TEST_TRIGGER(irq
+ i
))
357 res
|= (2 << (i
* 2));
360 } else if (offset
< 0xfe0) {
362 } else /* offset >= 0xfe0 */ {
366 res
= gic_id
[(offset
- 0xfe0) >> 2];
371 hw_error("gic_dist_readb: Bad offset %x\n", (int)offset
);
375 static uint32_t gic_dist_readw(void *opaque
, target_phys_addr_t offset
)
378 val
= gic_dist_readb(opaque
, offset
);
379 val
|= gic_dist_readb(opaque
, offset
+ 1) << 8;
383 static uint32_t gic_dist_readl(void *opaque
, target_phys_addr_t offset
)
387 gic_state
*s
= (gic_state
*)opaque
;
390 if (addr
< 0x100 || addr
> 0xd00)
391 return nvic_readl(s
, addr
);
393 val
= gic_dist_readw(opaque
, offset
);
394 val
|= gic_dist_readw(opaque
, offset
+ 2) << 16;
398 static void gic_dist_writeb(void *opaque
, target_phys_addr_t offset
,
401 gic_state
*s
= (gic_state
*)opaque
;
406 cpu
= gic_get_current_cpu();
407 if (offset
< 0x100) {
412 s
->enabled
= (value
& 1);
413 DPRINTF("Distribution %sabled\n", s
->enabled
? "En" : "Dis");
414 } else if (offset
< 4) {
420 } else if (offset
< 0x180) {
421 /* Interrupt Set Enable. */
422 irq
= (offset
- 0x100) * 8 + GIC_BASE_IRQ
;
427 for (i
= 0; i
< 8; i
++) {
428 if (value
& (1 << i
)) {
429 int mask
= (irq
< 32) ? (1 << cpu
) : GIC_TARGET(irq
);
430 int cm
= (irq
< 32) ? (1 << cpu
) : ALL_CPU_MASK
;
432 if (!GIC_TEST_ENABLED(irq
+ i
, cm
)) {
433 DPRINTF("Enabled IRQ %d\n", irq
+ i
);
435 GIC_SET_ENABLED(irq
+ i
, cm
);
436 /* If a raised level triggered IRQ enabled then mark
438 if (GIC_TEST_LEVEL(irq
+ i
, mask
)
439 && !GIC_TEST_TRIGGER(irq
+ i
)) {
440 DPRINTF("Set %d pending mask %x\n", irq
+ i
, mask
);
441 GIC_SET_PENDING(irq
+ i
, mask
);
445 } else if (offset
< 0x200) {
446 /* Interrupt Clear Enable. */
447 irq
= (offset
- 0x180) * 8 + GIC_BASE_IRQ
;
452 for (i
= 0; i
< 8; i
++) {
453 if (value
& (1 << i
)) {
454 int cm
= (irq
< 32) ? (1 << cpu
) : ALL_CPU_MASK
;
456 if (GIC_TEST_ENABLED(irq
+ i
, cm
)) {
457 DPRINTF("Disabled IRQ %d\n", irq
+ i
);
459 GIC_CLEAR_ENABLED(irq
+ i
, cm
);
462 } else if (offset
< 0x280) {
463 /* Interrupt Set Pending. */
464 irq
= (offset
- 0x200) * 8 + GIC_BASE_IRQ
;
470 for (i
= 0; i
< 8; i
++) {
471 if (value
& (1 << i
)) {
472 GIC_SET_PENDING(irq
+ i
, GIC_TARGET(irq
));
475 } else if (offset
< 0x300) {
476 /* Interrupt Clear Pending. */
477 irq
= (offset
- 0x280) * 8 + GIC_BASE_IRQ
;
480 for (i
= 0; i
< 8; i
++) {
481 /* ??? This currently clears the pending bit for all CPUs, even
482 for per-CPU interrupts. It's unclear whether this is the
484 if (value
& (1 << i
)) {
485 GIC_CLEAR_PENDING(irq
+ i
, ALL_CPU_MASK
);
488 } else if (offset
< 0x400) {
489 /* Interrupt Active. */
491 } else if (offset
< 0x800) {
492 /* Interrupt Priority. */
493 irq
= (offset
- 0x400) + GIC_BASE_IRQ
;
497 s
->priority1
[irq
][cpu
] = value
;
499 s
->priority2
[irq
- 32] = value
;
502 } else if (offset
< 0xc00) {
503 /* Interrupt CPU Target. */
504 irq
= (offset
- 0x800) + GIC_BASE_IRQ
;
510 value
= ALL_CPU_MASK
;
511 s
->irq_target
[irq
] = value
& ALL_CPU_MASK
;
512 } else if (offset
< 0xf00) {
513 /* Interrupt Configuration. */
514 irq
= (offset
- 0xc00) * 4 + GIC_BASE_IRQ
;
519 for (i
= 0; i
< 4; i
++) {
520 if (value
& (1 << (i
* 2))) {
521 GIC_SET_MODEL(irq
+ i
);
523 GIC_CLEAR_MODEL(irq
+ i
);
525 if (value
& (2 << (i
* 2))) {
526 GIC_SET_TRIGGER(irq
+ i
);
528 GIC_CLEAR_TRIGGER(irq
+ i
);
533 /* 0xf00 is only handled for 32-bit writes. */
539 hw_error("gic_dist_writeb: Bad offset %x\n", (int)offset
);
542 static void gic_dist_writew(void *opaque
, target_phys_addr_t offset
,
545 gic_dist_writeb(opaque
, offset
, value
& 0xff);
546 gic_dist_writeb(opaque
, offset
+ 1, value
>> 8);
549 static void gic_dist_writel(void *opaque
, target_phys_addr_t offset
,
552 gic_state
*s
= (gic_state
*)opaque
;
556 if (addr
< 0x100 || (addr
> 0xd00 && addr
!= 0xf00)) {
557 nvic_writel(s
, addr
, value
);
561 if (offset
== 0xf00) {
566 cpu
= gic_get_current_cpu();
568 switch ((value
>> 24) & 3) {
570 mask
= (value
>> 16) & ALL_CPU_MASK
;
573 mask
= ALL_CPU_MASK
^ (1 << cpu
);
579 DPRINTF("Bad Soft Int target filter\n");
583 GIC_SET_PENDING(irq
, mask
);
587 gic_dist_writew(opaque
, offset
, value
& 0xffff);
588 gic_dist_writew(opaque
, offset
+ 2, value
>> 16);
591 static const MemoryRegionOps gic_dist_ops
= {
593 .read
= { gic_dist_readb
, gic_dist_readw
, gic_dist_readl
, },
594 .write
= { gic_dist_writeb
, gic_dist_writew
, gic_dist_writel
, },
596 .endianness
= DEVICE_NATIVE_ENDIAN
,
600 static uint32_t gic_cpu_read(gic_state
*s
, int cpu
, int offset
)
603 case 0x00: /* Control */
604 return s
->cpu_enabled
[cpu
];
605 case 0x04: /* Priority mask */
606 return s
->priority_mask
[cpu
];
607 case 0x08: /* Binary Point */
608 /* ??? Not implemented. */
610 case 0x0c: /* Acknowledge */
611 return gic_acknowledge_irq(s
, cpu
);
612 case 0x14: /* Running Priority */
613 return s
->running_priority
[cpu
];
614 case 0x18: /* Highest Pending Interrupt */
615 return s
->current_pending
[cpu
];
617 hw_error("gic_cpu_read: Bad offset %x\n", (int)offset
);
622 static void gic_cpu_write(gic_state
*s
, int cpu
, int offset
, uint32_t value
)
625 case 0x00: /* Control */
626 s
->cpu_enabled
[cpu
] = (value
& 1);
627 DPRINTF("CPU %d %sabled\n", cpu
, s
->cpu_enabled
? "En" : "Dis");
629 case 0x04: /* Priority mask */
630 s
->priority_mask
[cpu
] = (value
& 0xff);
632 case 0x08: /* Binary Point */
633 /* ??? Not implemented. */
635 case 0x10: /* End Of Interrupt */
636 return gic_complete_irq(s
, cpu
, value
& 0x3ff);
638 hw_error("gic_cpu_write: Bad offset %x\n", (int)offset
);
644 /* Wrappers to read/write the GIC CPU interface for the current CPU */
645 static uint64_t gic_thiscpu_read(void *opaque
, target_phys_addr_t addr
,
648 gic_state
*s
= (gic_state
*)opaque
;
649 return gic_cpu_read(s
, gic_get_current_cpu(), addr
& 0xff);
652 static void gic_thiscpu_write(void *opaque
, target_phys_addr_t addr
,
653 uint64_t value
, unsigned size
)
655 gic_state
*s
= (gic_state
*)opaque
;
656 gic_cpu_write(s
, gic_get_current_cpu(), addr
& 0xff, value
);
659 /* Wrappers to read/write the GIC CPU interface for a specific CPU.
660 * These just decode the opaque pointer into gic_state* + cpu id.
662 static uint64_t gic_do_cpu_read(void *opaque
, target_phys_addr_t addr
,
665 gic_state
**backref
= (gic_state
**)opaque
;
666 gic_state
*s
= *backref
;
667 int id
= (backref
- s
->backref
);
668 return gic_cpu_read(s
, id
, addr
& 0xff);
671 static void gic_do_cpu_write(void *opaque
, target_phys_addr_t addr
,
672 uint64_t value
, unsigned size
)
674 gic_state
**backref
= (gic_state
**)opaque
;
675 gic_state
*s
= *backref
;
676 int id
= (backref
- s
->backref
);
677 gic_cpu_write(s
, id
, addr
& 0xff, value
);
680 static const MemoryRegionOps gic_thiscpu_ops
= {
681 .read
= gic_thiscpu_read
,
682 .write
= gic_thiscpu_write
,
683 .endianness
= DEVICE_NATIVE_ENDIAN
,
686 static const MemoryRegionOps gic_cpu_ops
= {
687 .read
= gic_do_cpu_read
,
688 .write
= gic_do_cpu_write
,
689 .endianness
= DEVICE_NATIVE_ENDIAN
,
693 static void gic_reset(gic_state
*s
)
696 memset(s
->irq_state
, 0, GIC_NIRQ
* sizeof(gic_irq_state
));
697 for (i
= 0 ; i
< NUM_CPU(s
); i
++) {
698 s
->priority_mask
[i
] = 0xf0;
699 s
->current_pending
[i
] = 1023;
700 s
->running_irq
[i
] = 1023;
701 s
->running_priority
[i
] = 0x100;
703 /* The NVIC doesn't have per-cpu interfaces, so enable by default. */
704 s
->cpu_enabled
[i
] = 1;
706 s
->cpu_enabled
[i
] = 0;
709 for (i
= 0; i
< 16; i
++) {
710 GIC_SET_ENABLED(i
, ALL_CPU_MASK
);
714 /* The NVIC is always enabled. */
721 static void gic_save(QEMUFile
*f
, void *opaque
)
723 gic_state
*s
= (gic_state
*)opaque
;
727 qemu_put_be32(f
, s
->enabled
);
728 for (i
= 0; i
< NUM_CPU(s
); i
++) {
729 qemu_put_be32(f
, s
->cpu_enabled
[i
]);
730 for (j
= 0; j
< 32; j
++)
731 qemu_put_be32(f
, s
->priority1
[j
][i
]);
732 for (j
= 0; j
< GIC_NIRQ
; j
++)
733 qemu_put_be32(f
, s
->last_active
[j
][i
]);
734 qemu_put_be32(f
, s
->priority_mask
[i
]);
735 qemu_put_be32(f
, s
->running_irq
[i
]);
736 qemu_put_be32(f
, s
->running_priority
[i
]);
737 qemu_put_be32(f
, s
->current_pending
[i
]);
739 for (i
= 0; i
< GIC_NIRQ
- 32; i
++) {
740 qemu_put_be32(f
, s
->priority2
[i
]);
742 for (i
= 0; i
< GIC_NIRQ
; i
++) {
744 qemu_put_be32(f
, s
->irq_target
[i
]);
746 qemu_put_byte(f
, s
->irq_state
[i
].enabled
);
747 qemu_put_byte(f
, s
->irq_state
[i
].pending
);
748 qemu_put_byte(f
, s
->irq_state
[i
].active
);
749 qemu_put_byte(f
, s
->irq_state
[i
].level
);
750 qemu_put_byte(f
, s
->irq_state
[i
].model
);
751 qemu_put_byte(f
, s
->irq_state
[i
].trigger
);
755 static int gic_load(QEMUFile
*f
, void *opaque
, int version_id
)
757 gic_state
*s
= (gic_state
*)opaque
;
764 s
->enabled
= qemu_get_be32(f
);
765 for (i
= 0; i
< NUM_CPU(s
); i
++) {
766 s
->cpu_enabled
[i
] = qemu_get_be32(f
);
767 for (j
= 0; j
< 32; j
++)
768 s
->priority1
[j
][i
] = qemu_get_be32(f
);
769 for (j
= 0; j
< GIC_NIRQ
; j
++)
770 s
->last_active
[j
][i
] = qemu_get_be32(f
);
771 s
->priority_mask
[i
] = qemu_get_be32(f
);
772 s
->running_irq
[i
] = qemu_get_be32(f
);
773 s
->running_priority
[i
] = qemu_get_be32(f
);
774 s
->current_pending
[i
] = qemu_get_be32(f
);
776 for (i
= 0; i
< GIC_NIRQ
- 32; i
++) {
777 s
->priority2
[i
] = qemu_get_be32(f
);
779 for (i
= 0; i
< GIC_NIRQ
; i
++) {
781 s
->irq_target
[i
] = qemu_get_be32(f
);
783 s
->irq_state
[i
].enabled
= qemu_get_byte(f
);
784 s
->irq_state
[i
].pending
= qemu_get_byte(f
);
785 s
->irq_state
[i
].active
= qemu_get_byte(f
);
786 s
->irq_state
[i
].level
= qemu_get_byte(f
);
787 s
->irq_state
[i
].model
= qemu_get_byte(f
);
788 s
->irq_state
[i
].trigger
= qemu_get_byte(f
);
795 static void gic_init(gic_state
*s
, int num_cpu
)
797 static void gic_init(gic_state
*s
)
803 s
->num_cpu
= num_cpu
;
805 qdev_init_gpio_in(&s
->busdev
.qdev
, gic_set_irq
, GIC_NIRQ
- 32);
806 for (i
= 0; i
< NUM_CPU(s
); i
++) {
807 sysbus_init_irq(&s
->busdev
, &s
->parent_irq
[i
]);
809 memory_region_init_io(&s
->iomem
, &gic_dist_ops
, s
, "gic_dist", 0x1000);
811 /* Memory regions for the CPU interfaces (NVIC doesn't have these):
812 * a region for "CPU interface for this core", then a region for
813 * "CPU interface for core 0", "for core 1", ...
814 * NB that the memory region size of 0x100 applies for the 11MPCore
815 * and also cores following the GIC v1 spec (ie A9).
816 * GIC v2 defines a larger memory region (0x1000) so this will need
817 * to be extended when we implement A15.
819 memory_region_init_io(&s
->cpuiomem
[0], &gic_thiscpu_ops
, s
,
821 for (i
= 0; i
< NUM_CPU(s
); i
++) {
823 memory_region_init_io(&s
->cpuiomem
[i
+1], &gic_cpu_ops
, &s
->backref
[i
],
829 register_savevm(NULL
, "arm_gic", -1, 2, gic_save
, gic_load
, s
);