3 * - By John Hodge (thePowersGang)
17 extern void *gpIRQHandler;
20 typedef void (*tIRQ_Handler)(int, void*);
23 int GIC_Install(char **Arguments);
24 void GIC_IRQHandler(void);
27 MODULE_DEFINE(0, 0x100, armv7_GIC, GIC_Install, NULL, NULL);
28 Uint32 *gpGIC_DistributorBase;
29 Uint32 *gpGIC_InterfaceBase;
30 tPAddr gGIC_DistributorAddr;
31 tPAddr gGIC_InterfaceAddr;
32 tIRQ_Handler gaIRQ_Handlers[N_IRQS];
33 void *gaIRQ_HandlerData[N_IRQS];
36 int GIC_Install(char **Arguments)
39 gGIC_InterfaceAddr = 0x1e000000;
40 gGIC_DistributorAddr = 0x1e001000;
43 gpGIC_InterfaceBase = (void*)MM_MapHWPages(gGIC_InterfaceAddr, 1);
44 gpGIC_DistributorBase = (void*)MM_MapHWPages(gGIC_DistributorAddr, 1);
46 gpGIC_InterfaceBase[GICC_PMR] = 0xFF;
47 gpGIC_InterfaceBase[GICC_CTLR] = 1; // Enable CPU
48 gpGIC_DistributorBase[GICD_CTLR] = 1; // Enable Distributor
50 gpIRQHandler = GIC_IRQHandler;
52 __asm__ __volatile__ ("cpsie if"); // Enable IRQs and FIQs
57 void GIC_IRQHandler(void)
59 Uint32 num = gpGIC_InterfaceBase[GICC_IAR];
60 // Log_Debug("GIC", "IRQ 0x%x", num);
61 gaIRQ_Handlers[num]( num, gaIRQ_HandlerData[num] );
62 gpGIC_InterfaceBase[GICC_EOIR] = num;
65 int IRQ_AddHandler(int IRQ, tIRQ_Handler Handler, void *Ptr)
67 if( IRQ < 0 || IRQ >= N_IRQS-32 ) {
72 IRQ += 32; // 32 internal IRQs
73 LOG("IRQ = %i (after adjust)", IRQ);
74 LOG("mask = 0x%x", 1 << (IRQ & (31-1)));
75 gpGIC_DistributorBase[GICD_ISENABLER0+IRQ/32] = 1 << (IRQ & (32-1));
76 ((Uint8*)&gpGIC_DistributorBase[GICD_ITARGETSR0])[IRQ] = 1;
78 // Log_Warning("GIC", "TODO: Implement IRQ_AddHandler");
80 if( gaIRQ_Handlers[IRQ] )
83 gaIRQ_Handlers[IRQ] = Handler;
84 gaIRQ_HandlerData[IRQ] = Ptr;