3 * - By John Hodge (thePowersGang)
15 extern void *gpIRQHandler;
18 int GIC_Install(char **Arguments);
19 void GIC_IRQHandler(void);
22 MODULE_DEFINE(0, 0x100, armv7_GIC, GIC_Install, NULL, NULL);
23 Uint32 *gpGIC_DistributorBase;
24 Uint32 *gpGIC_InterfaceBase;
25 tPAddr gGIC_DistributorAddr;
26 tPAddr gGIC_InterfaceAddr;
29 int GIC_Install(char **Arguments)
32 gGIC_InterfaceAddr = 0x1e000000;
33 gGIC_DistributorAddr = 0x1e001000;
36 gpGIC_InterfaceBase = (void*)MM_MapHWPages(gGIC_InterfaceAddr, 1);
37 gpGIC_DistributorBase = (void*)MM_MapHWPages(gGIC_DistributorAddr, 1);
39 gpGIC_InterfaceBase[GICC_PMR] = 0xFF;
40 gpGIC_InterfaceBase[GICC_CTLR] = 1; // Enable CPU
41 gpGIC_DistributorBase[GICD_CTLR] = 1; // Enable Distributor
43 gpIRQHandler = GIC_IRQHandler;
45 __asm__ __volatile__ ("cpsie if"); // Enable IRQs and FIQs
50 void GIC_IRQHandler(void)
52 Uint32 num = gpGIC_InterfaceBase[GICC_IAR];
53 Log_Debug("GIC", "IRQ 0x%x", num);
54 gpGIC_InterfaceBase[GICC_EOIR] = 1;
57 int IRQ_AddHandler(int IRQ, void (*Handler)(int, void*), void *Ptr)
60 IRQ += 32; // 32 internal IRQs
61 LOG("IRQ = %i (after adjust)", IRQ);
62 LOG("mask = 0x%x", 1 << (IRQ & (31-1)));
63 gpGIC_DistributorBase[GICD_ISENABLER0+IRQ/32] = 1 << (IRQ & (32-1));
64 ((Uint8*)&gpGIC_DistributorBase[GICD_ITARGETSR0])[IRQ] = 1;
65 Log_Warning("GIC", "TODO: Implement IRQ_AddHandler");