This source file includes following definitions.
- ioapicread
- ioapicwrite
- ioapicinit
- ioapicenable
1
2
3
4
5 #include "types.h"
6 #include "defs.h"
7 #include "traps.h"
8
9 #define IOAPIC 0xFEC00000
10
11 #define REG_ID 0x00
12 #define REG_VER 0x01
13 #define REG_TABLE 0x10
14
15
16
17
18
19
20 #define INT_DISABLED 0x00010000
21 #define INT_LEVEL 0x00008000
22 #define INT_ACTIVELOW 0x00002000
23 #define INT_LOGICAL 0x00000800
24
25 volatile struct ioapic *ioapic;
26
27
28 struct ioapic {
29 uint reg;
30 uint pad[3];
31 uint data;
32 };
33
34 static uint
35 ioapicread(int reg)
36 {
37 ioapic->reg = reg;
38 return ioapic->data;
39 }
40
41 static void
42 ioapicwrite(int reg, uint data)
43 {
44 ioapic->reg = reg;
45 ioapic->data = data;
46 }
47
48 void
49 ioapicinit(void)
50 {
51 int i, id, maxintr;
52
53 ioapic = (volatile struct ioapic*)IOAPIC;
54 maxintr = (ioapicread(REG_VER) >> 16) & 0xFF;
55 id = ioapicread(REG_ID) >> 24;
56 if(id != ioapicid)
57 cprintf("ioapicinit: id isn't equal to ioapicid; not a MP\n");
58
59
60
61 for(i = 0; i <= maxintr; i++){
62 ioapicwrite(REG_TABLE+2*i, INT_DISABLED | (T_IRQ0 + i));
63 ioapicwrite(REG_TABLE+2*i+1, 0);
64 }
65 }
66
67 void
68 ioapicenable(int irq, int cpunum)
69 {
70
71
72
73 ioapicwrite(REG_TABLE+2*irq, T_IRQ0 + irq);
74 ioapicwrite(REG_TABLE+2*irq+1, cpunum << 24);
75 }