summaryrefslogtreecommitdiffstats
path: root/src/arch/x86/transitions/librm_mgmt.c
diff options
context:
space:
mode:
authorMichael Brown2024-03-15 14:12:22 +0100
committerMichael Brown2024-03-15 14:27:06 +0100
commita67f913d6635772af746fc215066e3d510ae25d1 (patch)
tree8a398a6478b31fed595c77b31e700e2999fe91b1 /src/arch/x86/transitions/librm_mgmt.c
parent[efi] Provide a multiprocessor API for EFI (diff)
downloadipxe-a67f913d6635772af746fc215066e3d510ae25d1.tar.gz
ipxe-a67f913d6635772af746fc215066e3d510ae25d1.tar.xz
ipxe-a67f913d6635772af746fc215066e3d510ae25d1.zip
[librm] Add support for installing a startup IPI handler
Application processors are started via INIT and SIPI interprocessor interrupts: the INIT places the processor into a "wait for SIPI" state, and the SIPI then starts the processor in real mode at a page-aligned address derived from the SIPI vector number. Add support for installing a real-mode SIPI handler that will switch the CPU into protected mode with flat physical addressing, load initial register contents, and then jump to the address of a protected-mode SIPI handler. No stack pointer is set up, to avoid the need to allocate stack space for each available processor. We use 32-bit physical addressing in order to minimise the changes required for a 64-bit build. The existing long mode transition code relies on the existence of the stack, so we cannot easily switch the application processor into long mode. We could use 32-bit virtual addressing, but this runtime environment does not currently exist outside of librm.S itself in a 64-bit build, and using it would complicate the implementation of the protected-mode SIPI handler. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/arch/x86/transitions/librm_mgmt.c')
-rw-r--r--src/arch/x86/transitions/librm_mgmt.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/arch/x86/transitions/librm_mgmt.c b/src/arch/x86/transitions/librm_mgmt.c
index da221e8b..b3820589 100644
--- a/src/arch/x86/transitions/librm_mgmt.c
+++ b/src/arch/x86/transitions/librm_mgmt.c
@@ -45,6 +45,9 @@ struct idtr64 idtr64 = {
.limit = ( sizeof ( idt64 ) - 1 ),
};
+/** Startup IPI register state */
+struct i386_regs sipi_regs;
+
/** Length of stack dump */
#define STACK_DUMP_LEN 128
@@ -402,6 +405,29 @@ __asmcall void check_fxsr ( struct i386_all_regs *regs ) {
( ( regs->flags & CF ) ? " not" : "" ) );
}
+/**
+ * Set up startup IPI handler
+ *
+ * @v vector Startup IPI vector
+ * @v handler Protected-mode startup IPI handler physical address
+ * @v regs Initial register state
+ */
+void setup_sipi ( unsigned int vector, uint32_t handler,
+ struct i386_regs *regs ) {
+
+ /* Record protected-mode handler */
+ sipi_handler = handler;
+
+ /* Update copy of rm_ds */
+ sipi_ds = rm_ds;
+
+ /* Save register state */
+ memcpy ( &sipi_regs, regs, sizeof ( sipi_regs ) );
+
+ /* Copy real-mode handler */
+ copy_to_real ( ( vector << 8 ), 0, sipi, ( ( size_t ) sipi_len ) );
+}
+
PROVIDE_UACCESS_INLINE ( librm, phys_to_user );
PROVIDE_UACCESS_INLINE ( librm, user_to_phys );
PROVIDE_UACCESS_INLINE ( librm, virt_to_user );