From 47016cc15609864414d83f1a0745e95c1db04db5 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Fri, 26 Sep 2025 14:10:34 -0400 Subject: kern/amd64: Support APIC inter-processor interrupts This commit introduces support for sending inter-processor interrupts on the mainbus to other cores on the machine. Signed-off-by: Ian Moffett --- src/sys/include/arch/amd64/lapic.h | 60 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'src/sys/include') diff --git a/src/sys/include/arch/amd64/lapic.h b/src/sys/include/arch/amd64/lapic.h index 3cb2f3a..c75e70c 100644 --- a/src/sys/include/arch/amd64/lapic.h +++ b/src/sys/include/arch/amd64/lapic.h @@ -33,6 +33,66 @@ #define LAPIC_TIMER_VEC 0x81 +/* + * Represents the possible values for the ICR + * destination shorthand register for IPIs + * + * @IPI_SHAND_NONE: No shorthand + * @IPI_SHAND_SELF: Send IPI to self + * @IPI_SHAND_AIS: Send IPI to all including self + * @IPI_SHAND_AXS: Send IPI to all excluding self + */ +typedef enum { + IPI_SHAND_NONE, + IPI_SHAND_SELF, + IPI_SHAND_AIS, + IPI_SHAND_AXS +} ipi_shand_t; + +/* + * Represents the possible values for the ICR + * delivery mode + */ +#define IPI_DELMOD_FIXED 0x0 /* Fixed */ +#define IPI_DELMOD_LOWPRI 0x1 /* Lowest priority */ +#define IPI_DELMOD_INIT 0x5 /* Init (for bootstrap) */ +#define IPI_DELMOD_STARTUP 0x6 /* Startup (for bootstrap) */ + +/* See above */ +typedef uint8_t ipi_delmod_t; + +/* Destination mode */ +#define IPI_DESTMODE_PHYSICAL 0x0 +#define IPI_DESTMODE_LOGICAL 0x01 + +/* + * Represents parameters used for generating + * IPIs on the mainbus + * + * @shorthand: Destination shorthand + * @delmod: Delivery mode + * @vector: Interrupt vector to trigger + * @dest_mode: Destination mode + */ +struct lapic_ipi { + ipi_shand_t shorthand; + ipi_delmod_t delmod; + uint8_t vector; + uint8_t apic_id; + uint8_t dest_mode : 1; +}; + +/* + * Transmit an IPI on the main bus to another processor, + * self, or both + * + * @ipip: IPI descriptor + * + * Returns zero on success, otherwise a less than zero value + * on failure. + */ +int lapic_tx_ipi(const struct lapic_ipi *ipip); + /* * Initialize the local APIC on the current * processor. -- cgit v1.2.3