Many changes:
[Marmot.git] / apic.c
blobd3dbee43486ef636c206e500b391550ac202b4b8
1 /*
2 * apic.c
4 * Check for APIC support and initialize external interrupts to use it.
5 */
7 #include <marmot.h>
9 Bool usingAPIC;
11 void
12 InitPIC(void)
14 usingAPIC = FALSE;
17 VA apicBase, ioapicBase;
19 /* uint64 tval, tval2; */
21 void
22 InitAPIC(void)
24 uint64 apicBaseReg;
25 char deviceName[] = {'l', 'a', 'p', 'i', 'c', 0, 0, 0, 0};
27 if (!CPU_GetFeature(CPU_APIC_ENABLED)) {
28 InitPIC();
29 return;
32 usingAPIC = TRUE;
34 rdmsr(APIC_BASE_MSR, apicBaseReg);
35 /* VPROBE_TEST(APIC_BASE_MSR, apicBaseReg); */
37 apicBase = (VA)(apicBaseReg & 0x000ffffffffff000);
38 if (apicBase & (1 << 8)) {
39 deviceName[5] = 'B';
40 deviceName[6] = 'S';
41 deviceName[7] = 'P';
42 } else {
43 deviceName[5] = 'A';
44 deviceName[6] = 'P';
47 MapIORegion((PA)apicBase, (PA)apicBase + PAGE_SIZE, deviceName);
49 /* init IO APIC (part of chipset) */
50 ioapicBase = (VA)0xfec00000; // real address is in APICBASE on chipset