[PATCH v3 02/13] x86/acpi: Add a helper function to get a pointer to the wakeup mailbox

From: Ricardo Neri
Date: Sat May 03 2025 - 15:10:39 EST


In preparation to move the functionality to wake secondary CPUs up out
of the ACPI code, add a helper function to get a pointer to the mailbox.

Use this helper function only in the portions of the code for which the
variable acpi_mp_wake_mailbox will be out of scope once it is relocated
out of the ACPI directory.

The wakeup mailbox is only supported for CONFIG_X86_64 and needed only
with CONFIG_SMP.

Signed-off-by: Ricardo Neri <ricardo.neri-calderon@xxxxxxxxxxxxxxx>
---
Changes since v2:
- Introduced this patch.

Changes since v1:
- N/A
---
arch/x86/include/asm/smp.h | 1 +
arch/x86/kernel/acpi/madt_wakeup.c | 12 +++++++++---
2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
index 3622951d2ee0..97bfbd0d24d4 100644
--- a/arch/x86/include/asm/smp.h
+++ b/arch/x86/include/asm/smp.h
@@ -148,6 +148,7 @@ static inline struct cpumask *cpu_l2c_shared_mask(int cpu)

#ifdef CONFIG_X86_64
void setup_mp_wakeup_mailbox(u64 addr);
+struct acpi_madt_multiproc_wakeup_mailbox *get_mp_wakeup_mailbox(void);
#endif

#else /* !CONFIG_SMP */
diff --git a/arch/x86/kernel/acpi/madt_wakeup.c b/arch/x86/kernel/acpi/madt_wakeup.c
index 04de3db307de..6b9e41a24574 100644
--- a/arch/x86/kernel/acpi/madt_wakeup.c
+++ b/arch/x86/kernel/acpi/madt_wakeup.c
@@ -37,6 +37,7 @@ static void acpi_mp_play_dead(void)

static void acpi_mp_cpu_die(unsigned int cpu)
{
+ struct acpi_madt_multiproc_wakeup_mailbox *mailbox = get_mp_wakeup_mailbox();
u32 apicid = per_cpu(x86_cpu_to_apicid, cpu);
unsigned long timeout;

@@ -46,13 +47,13 @@ static void acpi_mp_cpu_die(unsigned int cpu)
*
* BIOS has to clear 'command' field of the mailbox.
*/
- acpi_mp_wake_mailbox->apic_id = apicid;
- smp_store_release(&acpi_mp_wake_mailbox->command,
+ mailbox->apic_id = apicid;
+ smp_store_release(&mailbox->command,
ACPI_MP_WAKE_COMMAND_TEST);

/* Don't wait longer than a second. */
timeout = USEC_PER_SEC;
- while (READ_ONCE(acpi_mp_wake_mailbox->command) && --timeout)
+ while (READ_ONCE(mailbox->command) && --timeout)
udelay(1);

if (!timeout)
@@ -251,3 +252,8 @@ void __init setup_mp_wakeup_mailbox(u64 mailbox_paddr)
acpi_mp_wake_mailbox_paddr = mailbox_paddr;
apic_update_callback(wakeup_secondary_cpu_64, acpi_wakeup_cpu);
}
+
+struct acpi_madt_multiproc_wakeup_mailbox *get_mp_wakeup_mailbox(void)
+{
+ return acpi_mp_wake_mailbox;
+}
--
2.43.0