Modules/armv7 - GIC support coming along
[tpg/acess2.git] / Modules / armv7 / GIC / gic.c
1 /*
2  * ARMv7 GIC Support
3  * - By John Hodge (thePowersGang)
4  * 
5  * gic.c
6  * - GIC Core
7  */
8 #define DEBUG   1
9
10 #include <acess.h>
11 #include <modules.h>
12 #include "gic.h"
13
14 // === IMPORTS ===
15 extern void     *gpIRQHandler;
16
17 // === PROTOTYPES ===
18  int    GIC_Install(char **Arguments);
19 void    GIC_IRQHandler(void);
20
21 // === GLOBALS ===
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;
27
28 // === CODE ===
29 int GIC_Install(char **Arguments)
30 {
31         // Realview PB
32         gGIC_InterfaceAddr   = 0x1e000000;
33         gGIC_DistributorAddr = 0x1e001000;
34
35         // Initialise
36         gpGIC_InterfaceBase = (void*)MM_MapHWPages(gGIC_InterfaceAddr, 1);
37         gpGIC_DistributorBase = (void*)MM_MapHWPages(gGIC_DistributorAddr, 1);
38
39         gpGIC_InterfaceBase[GICC_PMR] = 0xFF;   
40         gpGIC_InterfaceBase[GICC_CTLR] = 1;     // Enable CPU
41         gpGIC_DistributorBase[GICD_CTLR] = 1;   // Enable Distributor
42
43         gpIRQHandler = GIC_IRQHandler;
44
45         __asm__ __volatile__ ("cpsie if");      // Enable IRQs and FIQs
46
47         return MODULE_ERR_OK;
48 }
49
50 void GIC_IRQHandler(void)
51 {
52         Uint32  num = gpGIC_InterfaceBase[GICC_IAR];
53         Log_Debug("GIC", "IRQ 0x%x", num);
54         gpGIC_InterfaceBase[GICC_EOIR] = 1;
55 }
56
57 int IRQ_AddHandler(int IRQ, void (*Handler)(int, void*), void *Ptr)
58 {
59         LOG("IRQ = %i", IRQ);
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");
66         return 0;
67 }
68

UCC git Repository :: git.ucc.asn.au