CS350 COS
COS
Loading...
Searching...
No Matches
lapic.h File Reference

Go to the source code of this file.

Functions

void LAPIC_Init ()
 
uint32_t LAPIC_CPU ()
 
void LAPIC_SendEOI ()
 
void LAPIC_StartAP (uint8_t apicid, uint32_t addr)
 
int LAPIC_Broadcast (int vector)
 
int LAPIC_BroadcastNMI (int vector)
 
void LAPIC_Periodic (uint64_t rate)
 

Function Documentation

◆ LAPIC_Broadcast()

int LAPIC_Broadcast ( int  vector)

Definition at line 143 of file lapic.c.

144{
145 int i = 0;
147
149 pause();
150
151 if (i > 1000000) {
152 kprintf("IPI not delivered?\n");
153 return -1;
154 }
155 }
156
157 return 0;
158}
static INLINE void pause()
Definition: amd64op.h:24
int kprintf(const char *fmt,...)
Definition: printf.c:210
#define LAPIC_ICR_EXCSELF
Definition: lapic.c:44
#define LAPIC_ICR_LO
Definition: lapic.c:34
#define LAPIC_ICR_DELIVERY_PENDING
Definition: lapic.c:45
uint32_t LAPIC_Read(uint16_t reg)
Definition: lapic.c:76
void LAPIC_Write(uint16_t reg, uint32_t val)
Definition: lapic.c:84
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LAPIC_BroadcastNMI()

int LAPIC_BroadcastNMI ( int  vector)

Definition at line 161 of file lapic.c.

162{
163 int i = 0;
165
167 pause();
168
169 if (i > 1000000) {
170 kprintf("IPI not delivered?\n");
171 return -1;
172 }
173 }
174
175 return 0;
176}
#define LAPIC_ICR_NMI
Definition: lapic.c:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LAPIC_CPU()

uint32_t LAPIC_CPU ( )

Definition at line 93 of file lapic.c.

94{
96 return LAPIC_Read(LAPIC_ID) >> 24;
97 else
98 return 0;
99}
bool lapicInitialized
Definition: lapic.c:65
#define LAPIC_ID
Definition: lapic.c:22
Here is the call graph for this function:

◆ LAPIC_Init()

void LAPIC_Init ( )

Definition at line 179 of file lapic.c.

180{
181 uint32_t version;
182 uint32_t lvts;
183 uint32_t edx;
185
186 cpuid(1, NULL, NULL, NULL, &edx);
187 if ((edx & CPUID_FLAG_APIC) == 0)
188 Panic("APIC is required!\n");
189
190 // Disable ATPIC
191 if (LAPIC_CPU() == 0) {
192 outb(0xA1, 0xFF);
193 outb(0x21, 0xFF);
194 }
195
196 // Enable LAPIC
199
200 // Convert to Direct Map Address
201 base = DMPA2VA(base);
202
203 lapicInitialized = true;
204
205 kprintf("LAPIC: CPU %d found at 0x%016llx\n", LAPIC_CPU(), base);
206
207 version = LAPIC_Read(LAPIC_VERSION);
208 lvts = (version & LAPIC_VERSION_LVTMASK) >> LAPIC_VERSION_LVTSHIFT;
209
210 // Enable interrupts
212
213 // Error Interrupt
215
216 // Setup LINT0/1
217 if (LAPIC_CPU() == 0) {
220 } else {
223 }
224
225 // Performance Counter Interrupt
226 if (lvts >= 4) {
228 }
229
230 // Thermal Interrupt
231 if (lvts >= 5) {
233 }
234
235 // Machine Check Interrupt
236 if (lvts >= 6) {
238 }
239
240 LAPIC_Periodic(10000000); // XXX: 100 Hz (changes must update trap.c as well)
241
242 // Clear any remaining errors
245
249 {
250 // XXX: Timeout
251 }
252
254
256}
static INLINE uint64_t rdmsr(uint32_t addr)
Definition: amd64op.h:114
static INLINE void outb(uint16_t port, uint8_t data)
Definition: amd64op.h:431
static INLINE void wrmsr(uint32_t addr, uint64_t val)
Definition: amd64op.h:104
static INLINE void cpuid(uint32_t info, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
Definition: amd64op.h:85
#define LAPIC_LVT_LINT1
Definition: lapic.c:54
#define LAPIC_SIV_ENABLE
Definition: lapic.c:29
#define LAPIC_LVT_THERMAL
Definition: lapic.c:51
#define LAPIC_VERSION_LVTMASK
Definition: lapic.c:24
#define LAPIC_LVT_FLAG_MASKED
Definition: lapic.c:56
#define CPUID_FLAG_APIC
Definition: lapic.c:16
#define IA32_APIC_BASE_MSR
Definition: lapic.c:18
#define LAPIC_LVT_PMCR
Definition: lapic.c:52
#define LAPIC_VERSION_LVTSHIFT
Definition: lapic.c:25
void LAPIC_Periodic(uint64_t rate)
Definition: lapic.c:108
#define LAPIC_TPR
Definition: lapic.c:26
#define LAPIC_VERSION
Definition: lapic.c:23
#define LAPIC_SIV
Definition: lapic.c:28
#define LAPIC_LVT_ERROR
Definition: lapic.c:55
#define LAPIC_ESR
Definition: lapic.c:31
#define LAPIC_LVT_FLAG_NMI
Definition: lapic.c:57
#define LAPIC_LVT_CMCI
Definition: lapic.c:32
uint32_t LAPIC_CPU()
Definition: lapic.c:93
#define LAPIC_LVT_FLAG_EXTINT
Definition: lapic.c:58
#define LAPIC_ICR_TRIG
Definition: lapic.c:41
void LAPIC_SendEOI()
Definition: lapic.c:102
#define IA32_APIC_BASE_MSR_ENABLE
Definition: lapic.c:20
#define LAPIC_ICR_INCSELF
Definition: lapic.c:43
#define LAPIC_LVT_LINT0
Definition: lapic.c:53
#define LAPIC_ICR_HI
Definition: lapic.c:35
#define LAPIC_ICR_INIT
Definition: lapic.c:38
#define DMPA2VA(pa)
Definition: pmap.h:48
static uint16_t base
Definition: sercons.c:37
#define NULL
Definition: stddef.h:6
#define T_IRQ_ERROR
Definition: trap.h:39
#define T_IRQ_THERMAL
Definition: trap.h:40
#define T_IRQ_SPURIOUS
Definition: trap.h:38
unsigned int uint32_t
Definition: types.h:12
unsigned long uint64_t
Definition: types.h:13
void Panic(const char *str)
Definition: vgacons.c:164
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LAPIC_Periodic()

void LAPIC_Periodic ( uint64_t  rate)

Definition at line 108 of file lapic.c.

109{
112 LAPIC_Write(LAPIC_TICR, rate);
113}
#define LAPIC_TDCR_X1
Definition: lapic.c:63
#define LAPIC_TDCR
Definition: lapic.c:62
#define LAPIC_LVT_TIMER
Definition: lapic.c:47
#define LAPIC_LVT_TIMER_PERIODIC
Definition: lapic.c:49
#define LAPIC_TICR
Definition: lapic.c:60
#define T_IRQ_TIMER
Definition: trap.h:32
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LAPIC_SendEOI()

void LAPIC_SendEOI ( )

Definition at line 102 of file lapic.c.

103{
105}
#define LAPIC_EOI
Definition: lapic.c:27
Here is the call graph for this function:
Here is the caller graph for this function:

◆ LAPIC_StartAP()

void LAPIC_StartAP ( uint8_t  apicid,
uint32_t  addr 
)

Definition at line 116 of file lapic.c.

117{
118 // Setup CMOS stuff
119 outb(0x70, 0x0F);
120 outb(0x71, 0x0A);
121 uint16_t *cmosStartup = (uint16_t *)DMPA2VA(0x467);
122 cmosStartup[0] = 0;
123 cmosStartup[1] = addr >> 4;
124
125 // Send INIT
126 LAPIC_Write(LAPIC_ICR_HI, apicid << 24);
128 // XXX: Delay
129 LAPIC_Write(LAPIC_ICR_HI, apicid << 24);
131 // XXX: Delay
132
133 // Send STARTUP
134 LAPIC_Write(LAPIC_ICR_HI, apicid << 24);
136 // XXX: Delay
137 LAPIC_Write(LAPIC_ICR_HI, apicid << 24);
139 // XXX: Delay
140}
#define LAPIC_ICR_STARTUP
Definition: lapic.c:39
#define LAPIC_ICR_ASSERT
Definition: lapic.c:40
uint64_t addr
Definition: multiboot.h:1
unsigned short uint16_t
Definition: types.h:11
Here is the call graph for this function:
Here is the caller graph for this function: