CS350 COS
COS
Loading...
Searching...
No Matches
ioapic.c
Go to the documentation of this file.
1/*
2 * IOAPIC
3 */
4
5#include <stdbool.h>
6#include <stdint.h>
7
8#include <sys/kassert.h>
9#include <sys/kdebug.h>
10#include <sys/cdefs.h>
11
12#include <machine/amd64.h>
13#include <machine/pmap.h>
14#include <machine/trap.h>
15
16#define IOAPICBASE 0xFEC00000
17
18#define IOAPICID 0x00 /* IOAPIC ID */
19#define IOAPICVER 0x01 /* IOAPIC Version */
20#define IOAPICARB 0x02 /* IOAPIC Arbitration ID */
21#define IOREDTBL0 0x10
22#define IOREDTBL23 0x3E
23
24#define IOREDTBL_LEN 24
25
26#define IOREDTBL_MASK 0x00010000
27#define IOREDTBL_LOGICAL 0x00000800
28
31{
32 uint32_t volatile *addr = (uint32_t volatile *)DMPA2VA(IOAPICBASE);
33 uint32_t volatile *cmd = (uint32_t volatile *)DMPA2VA(IOAPICBASE + 0x10);
34
35 ASSERT(reg <= 0xFF);
36
37 *addr = reg;
38 return *cmd;
39}
40
41void
43{
44 uint32_t volatile *addr = (uint32_t volatile *)DMPA2VA(IOAPICBASE);
45 uint32_t volatile *cmd = (uint32_t volatile *)DMPA2VA(IOAPICBASE + 0x10);
46
47 ASSERT(reg <= 0xFF);
48
49 *addr = reg;
50 *cmd = val;
51}
52
53void
55{
56 int i;
57 uint32_t id = (IOAPIC_Read(IOAPICID) >> 24) & 0x0F;
58 uint32_t maxInts = (IOAPIC_Read(IOAPICVER) >> 16) & 0xFF;
59
60 kprintf("IOAPIC: ID:%d Max Interrupts: %d\n", id, maxInts);
61
62 for (i = 0; i < IOREDTBL_LEN; i++)
63 {
65 IOAPIC_Write(IOREDTBL0 + 2*i + 1, 0);
66 }
67}
68
69void
71{
74}
75
76void
78{
81}
82
83static void
84Debug_IOAPIC(int argc, const char *argv[])
85{
86 int i;
87
88 kprintf("IOAPIC ID: %08x\n", IOAPIC_Read(IOAPICID));
89 kprintf("IOAPIC VERSION: %08x\n", IOAPIC_Read(IOAPICVER));
90
91 for (i = 0; i < IOREDTBL_LEN; i++)
92 {
93 uint32_t irqInfo = IOAPIC_Read(IOREDTBL0 + 2*i);
94 uint32_t cpuInfo = IOAPIC_Read(IOREDTBL0 + 2*i + 1);
95 kprintf("%02x: %08x %08x\n", i, irqInfo, cpuInfo);
96 }
97}
98
99REGISTER_DBGCMD(ioapic, "IOAPIC Dump", Debug_IOAPIC);
100
#define IOAPICBASE
Definition: ioapic.c:16
static void Debug_IOAPIC(int argc, const char *argv[])
Definition: ioapic.c:84
void IOAPIC_Init()
Definition: ioapic.c:54
void IOAPIC_Write(uint32_t reg, uint32_t val)
Definition: ioapic.c:42
#define IOAPICID
Definition: ioapic.c:18
uint32_t IOAPIC_Read(uint32_t reg)
Definition: ioapic.c:30
#define IOREDTBL0
Definition: ioapic.c:21
void IOAPIC_Enable(int irq)
Definition: ioapic.c:70
#define IOAPICVER
Definition: ioapic.c:19
#define IOREDTBL_LEN
Definition: ioapic.c:24
#define IOREDTBL_MASK
Definition: ioapic.c:26
void IOAPIC_Disable(int irq)
Definition: ioapic.c:77
#define ASSERT(_x)
Definition: kassert.h:8
int kprintf(const char *fmt,...)
Definition: printf.c:210
#define REGISTER_DBGCMD(_NAME, _DESC, _FUNC)
Definition: kdebug.h:11
uint64_t addr
Definition: multiboot.h:1
#define DMPA2VA(pa)
Definition: pmap.h:48
static uint8_t irq
Definition: sercons.c:38
#define T_IRQ_BASE
Definition: trap.h:28
unsigned int uint32_t
Definition: types.h:12