Files
acrn-hypervisor/hypervisor/arch/x86/notify.c
Shiqing Gao a5e46a70ff hv: smpcall: abstract a common SMP call framework
This patch:
 - abstracts the common logic from existing x86 implementation
 - moves x86-specific logic to arch/x86/notify.c

A new common/notify.{c,h} is introduced to provide a common SMP call framework for
multi-arch support in ACRN.
arch-specific files such as arch/{x86,riscv}/notify.c is aim to provide the
corresponding implementations respectively.

The framework provides the following common APIs:
 - init_smp_call(): initialize the SMP call support during pCPU initialization
 - handle_smp_call(): execute the SMP call notification handler
 - smp_call_function(): trigger the SMP call request to target pCPUs

Other SW modules should invoke these common APIs to perform arch-independent
SMP operations.

Two arch-specific hooks are abstracted:
 - arch_smp_call_kick_pcpu():
    - On x86, special handling is required when LAPIC is passthrough.
    - On RISC-V, a plain IPI is sufficient to kick the target pCPU.
 - arch_init_smp_call():
   - On x86, CPU initialization reserves dedicated vectors and
     registers callback handlers for purposes such as notifications
     or posted interrupts.
   - On RISC-V, no special handling is required at present; this
     can be extended in the future if needed.

----------
Changelog:
 * Merged the following two patches into one:
     [RFC PATCH v2 4/7] hv: introduce common/smp.{c,h}
     [RFC PATCH v2 5/7] hv: smpcall: x86: adapt to common SMP call
Tracked-On: #8786
Signed-off-by: Shiqing Gao <shiqing.gao@intel.com>
Acked-by: Wang, Yu1 <yu1.wang@intel.com>
2025-09-09 16:37:04 +08:00

97 lines
2.2 KiB
C

/*
* Copyright (C) 2018-2025 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include <types.h>
#include <errno.h>
#include <asm/lib/bits.h>
#include <asm/lib/atomic.h>
#include <asm/irq.h>
#include <asm/cpu.h>
#include <asm/per_cpu.h>
#include <asm/lapic.h>
#include <asm/guest/vm.h>
#include <asm/guest/virq.h>
#include <common/notify.h>
static uint32_t notification_irq = IRQ_INVALID;
static int32_t request_notification_irq(irq_action_t func, void *data)
{
int32_t retval;
if (notification_irq != IRQ_INVALID) {
pr_info("%s, Notification vector already allocated on this CPU", __func__);
retval = -EBUSY;
} else {
/* all cpu register the same notification vector */
retval = request_irq(NOTIFY_VCPU_IRQ, func, data, IRQF_NONE);
if (retval < 0) {
pr_err("Failed to add notify isr");
retval = -ENODEV;
} else {
notification_irq = (uint32_t)retval;
}
}
return retval;
}
/*
* @pre be called only by BSP initialization process
*/
static void setup_notification(void)
{
/* support IPI notification, Service VM will register all CPU */
if (request_notification_irq(kick_notification, NULL) < 0) {
pr_err("Failed to setup notification");
}
dev_dbg(DBG_LEVEL_PTIRQ, "NOTIFY: irq[%d] setup vector %x",
notification_irq, irq_to_vector(notification_irq));
}
/*
* posted interrupt handler
* @pre (irq - POSTED_INTR_IRQ) < CONFIG_MAX_VM_NUM
*/
static void handle_pi_notification(uint32_t irq, __unused void *data)
{
uint32_t vcpu_index = irq - POSTED_INTR_IRQ;
ASSERT(vcpu_index < CONFIG_MAX_VM_NUM, "");
vcpu_handle_pi_notification(vcpu_index);
}
/*pre-condition: be called only by BSP initialization proccess*/
static void setup_pi_notification(void)
{
uint32_t i;
for (i = 0U; i < CONFIG_MAX_VM_NUM; i++) {
if (request_irq(POSTED_INTR_IRQ + i, handle_pi_notification, NULL, IRQF_NONE) < 0) {
pr_err("Failed to setup pi notification");
break;
}
}
}
void arch_init_smp_call(void)
{
setup_notification();
setup_pi_notification();
}
void arch_smp_call_kick_pcpu(uint16_t pcpu_id)
{
struct acrn_vcpu *vcpu = get_ever_run_vcpu(pcpu_id);
if ((vcpu != NULL) && (is_lapic_pt_enabled(vcpu))) {
vcpu_make_request(vcpu, ACRN_REQUEST_SMP_CALL);
} else {
arch_send_single_ipi(pcpu_id, NOTIFY_VCPU_VECTOR);
}
}