Loading [MathJax]/extensions/tex2jax.js
CS350 COS
COS
All Data Structures Files Functions Variables Typedefs Macros
mp.h File Reference

Go to the source code of this file.

Macros

#define CPUSTATE_NOT_PRESENT   0
 
#define CPUSTATE_BOOTED   1
 
#define CPUSTATE_HALTED   2
 
#define CPUSTATE_MAX   2
 
#define THISCPU   LAPIC_CPU
 

Typedefs

typedef int(* CrossCallCB) (void *)
 

Functions

void MP_Init ()
 
void MP_InitAP ()
 
void MP_SetState (int state)
 
int MP_GetCPUs ()
 
void MP_CrossCallTrap ()
 
int MP_CrossCall (CrossCallCB cb, void *arg)
 
uint32_t LAPIC_CPU ()
 

Macro Definition Documentation

◆ CPUSTATE_BOOTED

#define CPUSTATE_BOOTED   1

Definition at line 6 of file mp.h.

◆ CPUSTATE_HALTED

#define CPUSTATE_HALTED   2

Definition at line 7 of file mp.h.

◆ CPUSTATE_MAX

#define CPUSTATE_MAX   2

Definition at line 8 of file mp.h.

◆ CPUSTATE_NOT_PRESENT

#define CPUSTATE_NOT_PRESENT   0

Definition at line 5 of file mp.h.

◆ THISCPU

#define THISCPU   LAPIC_CPU

Definition at line 21 of file mp.h.

Typedef Documentation

◆ CrossCallCB

typedef int(* CrossCallCB) (void *)

Definition at line 16 of file mp.h.

Function Documentation

◆ 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
uint32_t LAPIC_Read(uint16_t reg)
Definition: lapic.c:76
#define LAPIC_ID
Definition: lapic.c:22

◆ MP_CrossCall()

int MP_CrossCall ( CrossCallCB  cb,
void *  arg 
)

Definition at line 168 of file mp.c.

169{
170 volatile CrossCallFrame frame;
171
172 // Setup frame
173 memset((void *)&frame, 0, sizeof(frame));
174 frame.cb = cb;
175 frame.arg = arg;
176 frame.count = 1;
177
179
180 cpus[CPU()].frame = (CrossCallFrame *)&frame;
181 cpuid(0, 0, 0, 0, 0);
182
184 return -1;
185
186 // Run on the local CPU
187 frame.status[CPU()] = cb(arg);
188 frame.done[CPU()] = 1;
189
190 // Wait for all to respond
191 while (frame.count < lastCPU) {
192 // Check for timeout
193
194 // XXX: Should dump the crosscall frame
195 }
196 cpus[CPU()].frame = NULL;
197 cpuid(0, 0, 0, 0, 0);
198
200
201 return 0;
202}
static INLINE void cpuid(uint32_t info, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx)
Definition: amd64op.h:85
void Critical_Exit()
Definition: critical.c:35
void Critical_Enter()
Definition: critical.c:28
#define CPU
Definition: mp.h:7
int LAPIC_Broadcast(int vector)
Definition: lapic.c:143
static volatile int lastCPU
Definition: mp.c:48
static volatile CPUState cpus[MAX_CPUS]
Definition: mp.c:49
CrossCallFrame * frame
Definition: mp.c:44
#define NULL
Definition: stddef.h:6
void * memset(void *dst, int c, size_t len)
Definition: string.c:164
#define T_CROSSCALL
Definition: trap.h:43
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MP_CrossCallTrap()

void MP_CrossCallTrap ( )

Definition at line 140 of file mp.c.

141{
142 int c;
143
144 cpuid(0, 0, 0, 0, 0);
145
147
148 for (c = 0; c <= lastCPU; c++) {
149 CrossCallFrame *frame = cpus[c].frame;
150 if (frame == NULL)
151 continue;
152
153 if (frame->done[CPU()] == 1)
154 continue;
155
156 frame->status[CPU()] = (frame->cb)(frame->arg);
157 frame->done[CPU()] = 1;
158
159 // Increment
160 __sync_add_and_fetch(&frame->count, 1);
161 }
162
164}
volatile int status[MAX_CPUS]
Definition: mp.c:32
volatile int done[MAX_CPUS]
Definition: mp.c:31
volatile int count
Definition: mp.c:30
void * arg
Definition: mp.c:29
CrossCallCB cb
Definition: mp.c:28
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MP_GetCPUs()

int MP_GetCPUs ( )

Definition at line 134 of file mp.c.

135{
136 return lastCPU;
137}
Here is the caller graph for this function:

◆ MP_Init()

void MP_Init ( )

Definition at line 91 of file mp.c.

92{
93 int i;
94 kprintf("Booting on CPU %u\n", CPU());
95
97 cpus[CPU()].frame = NULL;
98
99 for (i = 1; i < MAX_CPUS; i++) {
101 cpus[i].frame = NULL;
102 }
103
104 /*
105 * XXX: We really should read from the MP Table, but this appears to be
106 * reliable for now.
107 */
108 lastCPU = 0;
109 for (i = 1; i < MAX_CPUS; i++) {
110 if (MPBootAP(i) < 0)
111 break;
112
113 lastCPU = i;
114 }
115 lastCPU++;
116}
#define CPUSTATE_NOT_PRESENT
Definition: mp.h:5
#define CPUSTATE_BOOTED
Definition: mp.h:6
int kprintf(const char *fmt,...)
Definition: printf.c:210
#define MAX_CPUS
Definition: kconfig.h:8
int state
Definition: mp.c:42
static int MPBootAP(int procNo)
Definition: mp.c:52
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MP_InitAP()

void MP_InitAP ( )

Definition at line 119 of file mp.c.

120{
121 kprintf("AP %d booted!\n", CPU());
123 booted = 1;
124}
static volatile bool booted
Definition: mp.c:47
Here is the call graph for this function:
Here is the caller graph for this function:

◆ MP_SetState()

void MP_SetState ( int  state)

Definition at line 127 of file mp.c.

128{
129 ASSERT(state > 0 && state <= CPUSTATE_MAX);
130 cpus[CPU()].state = state;
131}
#define CPUSTATE_MAX
Definition: mp.h:8
#define ASSERT(_x)
Definition: kassert.h:8
Here is the caller graph for this function: