stos/amd64: mp: Add multiprocessing groundwork
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026, Chloe M.
|
||||||
|
* Provided under the BSD-3 clause.
|
||||||
|
*
|
||||||
|
* Description: MP bringup
|
||||||
|
* Author: Chloe M.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdef.h>
|
||||||
|
#include <hal/mp.h>
|
||||||
|
#include <hal/prim.h>
|
||||||
|
#include <ex/trace.h>
|
||||||
|
#include <machine/irqchip.h>
|
||||||
|
#include <machine/hpet.h>
|
||||||
|
#include <machine/lapic.h>
|
||||||
|
#include <units.h>
|
||||||
|
|
||||||
|
/* Limit used to prevent log spam */
|
||||||
|
#define MP_LOG_CAP 4
|
||||||
|
#define MP_DEBUG 1
|
||||||
|
|
||||||
|
#define DTRACE(Fmt, ...) \
|
||||||
|
TRACE("[ MP ]: " Fmt, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#if MP_DEBUG
|
||||||
|
#define MP_DTRACE(...) \
|
||||||
|
if (ProcessorsUp < MP_LOG_CAP) { \
|
||||||
|
DTRACE(__VA_ARGS__); \
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
#define MP_DTRACE(...) (VOID)0
|
||||||
|
#endif /* MP_DEBUG */
|
||||||
|
|
||||||
|
static USIZE ProcessorsUp = 0;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bring up a single application processor
|
||||||
|
*
|
||||||
|
* @Lapic: Local APIC of processor to bring up
|
||||||
|
*/
|
||||||
|
static VOID
|
||||||
|
ApKick(ACPI_LOCAL_APIC *Lapic)
|
||||||
|
{
|
||||||
|
UQUAD UsecCur, UsecGoal;
|
||||||
|
ULONG BspId;
|
||||||
|
|
||||||
|
if (Lapic == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Don't nuke ourselves */
|
||||||
|
BspId = MdLapicId();
|
||||||
|
if (Lapic->ApicId == BspId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Send an INIT IPI to the processor */
|
||||||
|
MdLapicSendIpi(
|
||||||
|
0,
|
||||||
|
Lapic->ApicId,
|
||||||
|
0,
|
||||||
|
IPI_XND_NONE,
|
||||||
|
IPI_DELMOD_INIT
|
||||||
|
);
|
||||||
|
|
||||||
|
/* MP spec states to wait 10 usec */
|
||||||
|
UsecCur = MdHpetTimeUsec();
|
||||||
|
UsecGoal = UsecCur + (USEC_PER_MSEC * 10);
|
||||||
|
while (MdHpetTimeUsec() < UsecGoal) {
|
||||||
|
HalCpuSpinWait();
|
||||||
|
}
|
||||||
|
|
||||||
|
DTRACE("sent init to apic%d\n", Lapic->ApicId);
|
||||||
|
++ProcessorsUp;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID
|
||||||
|
HalMpBringUp(VOID)
|
||||||
|
{
|
||||||
|
ACPI_LOCAL_APIC *LocalApic;
|
||||||
|
USIZE Idx;
|
||||||
|
|
||||||
|
/* Bring up each AP */
|
||||||
|
for (Idx = 0;; ++Idx) {
|
||||||
|
LocalApic = MdLapicByIndex(Idx);
|
||||||
|
if (LocalApic == NULL) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
ApKick(LocalApic);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2026, Chloe M.
|
||||||
|
* Provided under the BSD-3 clause.
|
||||||
|
*
|
||||||
|
* Description: MP bringup HAL layer
|
||||||
|
* Author: Chloe M.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _HAL_MP_H_
|
||||||
|
#define _HAL_MP_H_ 1
|
||||||
|
|
||||||
|
#include <stdef.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Bring the application processors up
|
||||||
|
*/
|
||||||
|
VOID HalMpBringUp(VOID);
|
||||||
|
|
||||||
|
#endif /* !_HAL_MP_H_ */
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
#include <hal/serial.h>
|
#include <hal/serial.h>
|
||||||
#include <hal/kpcr.h>
|
#include <hal/kpcr.h>
|
||||||
#include <hal/board.h>
|
#include <hal/board.h>
|
||||||
|
#include <hal/mp.h>
|
||||||
#include <ob/object.h>
|
#include <ob/object.h>
|
||||||
#include <drivers/bootvid/fbio.h>
|
#include <drivers/bootvid/fbio.h>
|
||||||
#include <drivers/acpi/acpi.h>
|
#include <drivers/acpi/acpi.h>
|
||||||
@@ -89,4 +90,7 @@ KiKernelEntry(VOID)
|
|||||||
|
|
||||||
/* Phase 3 initialization of the bootstrap core */
|
/* Phase 3 initialization of the bootstrap core */
|
||||||
HalKpcrP3Init(&BootstrapCore);
|
HalKpcrP3Init(&BootstrapCore);
|
||||||
|
|
||||||
|
/* Bring up all other cores */
|
||||||
|
HalMpBringUp();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,4 +14,5 @@ qemu-system-x86_64 \
|
|||||||
-serial stdio \
|
-serial stdio \
|
||||||
-device virtio-vga-gl \
|
-device virtio-vga-gl \
|
||||||
-display sdl,gl=on \
|
-display sdl,gl=on \
|
||||||
|
-smp 4 \
|
||||||
-cpu host
|
-cpu host
|
||||||
|
|||||||
Reference in New Issue
Block a user