From 43a09e86a7fe0176ee623eb2f59067b1a2f38b9e Mon Sep 17 00:00:00 2001 From: Yifan Liu Date: Fri, 26 Sep 2025 04:54:17 +0000 Subject: [PATCH] hv: host_pm: Move two common APIs to common scope Move shutdown_system to common (and rename to shutdown_host) Move reset_host to common Tracked-On: #8830 Signed-off-by: Yifan Liu Reviewed-by: Fei Li Acked-by: Wang Yu1 --- hypervisor/arch/x86/guest/vm_reset.c | 4 ++-- hypervisor/arch/x86/pm.c | 4 ++-- hypervisor/common/vm.c | 6 ++--- hypervisor/debug/x86/x86_shell.c | 2 +- hypervisor/include/arch/riscv/asm/guest/vm.h | 7 ------ hypervisor/include/arch/riscv/asm/host_pm.h | 14 +++++++++++ hypervisor/include/arch/x86/asm/host_pm.h | 8 +++---- hypervisor/include/common/host_pm.h | 25 ++++++++++++++++++++ 8 files changed, 50 insertions(+), 20 deletions(-) create mode 100644 hypervisor/include/arch/riscv/asm/host_pm.h create mode 100644 hypervisor/include/common/host_pm.h diff --git a/hypervisor/arch/x86/guest/vm_reset.c b/hypervisor/arch/x86/guest/vm_reset.c index fd222584a..365ccdc40 100644 --- a/hypervisor/arch/x86/guest/vm_reset.c +++ b/hypervisor/arch/x86/guest/vm_reset.c @@ -6,7 +6,7 @@ #include #include -#include +#include #include #include #include @@ -49,7 +49,7 @@ void triple_fault_shutdown_vm(struct acrn_vcpu *vcpu) pause_vm(pl_vm); (void)destroy_vm(pl_vm); if (is_ready_for_system_shutdown()) { - shutdown_system(); + shutdown_host(); } } put_vm_lock(pl_vm); diff --git a/hypervisor/arch/x86/pm.c b/hypervisor/arch/x86/pm.c index cac7b74b6..f1e324d2c 100644 --- a/hypervisor/arch/x86/pm.c +++ b/hypervisor/arch/x86/pm.c @@ -160,7 +160,7 @@ void save_s5_reg_val(uint32_t pm1a_cnt_val, uint32_t pm1b_cnt_val) system_pm1b_cnt_val = pm1b_cnt_val; } -void shutdown_system(void) +void arch_shutdown_host(void) { struct pm_s_state_data *sx_data = get_host_sstate_data(); do_acpi_sx(sx_data, system_pm1a_cnt_val, system_pm1b_cnt_val); @@ -245,7 +245,7 @@ void host_enter_s3(const struct pm_s_state_data *sstate_data, uint32_t pm1a_cnt_ resume_console(); } -void reset_host(bool warm) +void arch_reset_host(bool warm) { struct acrn_acpi_generic_address *gas = &(host_reset_reg.reg); uint8_t reboot_code = warm ? CF9_RESET_WARM : CF9_RESET_COLD; diff --git a/hypervisor/common/vm.c b/hypervisor/common/vm.c index 1d3d209f3..5e0902139 100644 --- a/hypervisor/common/vm.c +++ b/hypervisor/common/vm.c @@ -7,11 +7,12 @@ #include #include #include +#include #include #include #include #include -#include +#include static struct acrn_vm vm_array[CONFIG_MAX_VM_NUM] __aligned(PAGE_SIZE); @@ -341,7 +342,6 @@ int32_t destroy_vm(struct acrn_vm *vm) memset(vm_config->name, 0U, MAX_VM_NAME_LEN); } - /* Return status to caller */ return ret; } @@ -457,7 +457,7 @@ void shutdown_vm_from_idle(uint16_t pcpu_id) if (is_paused_vm(vm)) { (void)destroy_vm(vm); if (is_ready_for_system_shutdown()) { - shutdown_system(); + shutdown_host(); } } put_vm_lock(vm); diff --git a/hypervisor/debug/x86/x86_shell.c b/hypervisor/debug/x86/x86_shell.c index f06bbb9e1..0fcbc7929 100644 --- a/hypervisor/debug/x86/x86_shell.c +++ b/hypervisor/debug/x86/x86_shell.c @@ -19,7 +19,7 @@ #include #include #include -#include +#include #include #include "debug/shell_priv.h" diff --git a/hypervisor/include/arch/riscv/asm/guest/vm.h b/hypervisor/include/arch/riscv/asm/guest/vm.h index 14c44521b..5d5d19798 100644 --- a/hypervisor/include/arch/riscv/asm/guest/vm.h +++ b/hypervisor/include/arch/riscv/asm/guest/vm.h @@ -18,11 +18,4 @@ struct vm_arch { }; -/* FIXME: riscv dummy function */ -static inline bool need_shutdown_vm(uint16_t pcpu_id) -{ - (void)pcpu_id; - return false; -} - #endif /* RISCV_VM_H_ */ diff --git a/hypervisor/include/arch/riscv/asm/host_pm.h b/hypervisor/include/arch/riscv/asm/host_pm.h new file mode 100644 index 000000000..a9b2f654b --- /dev/null +++ b/hypervisor/include/arch/riscv/asm/host_pm.h @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2018-2025 Intel Corporation. + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef RISCV_HOST_PM_H +#define RISCV_HOST_PM_H + +/* FIXME: To be implemented */ +static inline void arch_shutdown_host(void) { } +/* FIXME: To be implemented */ +static inline void arch_reset_host(bool warm) { (void)warm; } + +#endif /* RISCV_HOST_PM_H */ diff --git a/hypervisor/include/arch/x86/asm/host_pm.h b/hypervisor/include/arch/x86/asm/host_pm.h index d70f504db..44f5265fd 100644 --- a/hypervisor/include/arch/x86/asm/host_pm.h +++ b/hypervisor/include/arch/x86/asm/host_pm.h @@ -3,8 +3,8 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#ifndef HOST_PM_H -#define HOST_PM_H +#ifndef X86_HOST_PM_H +#define X86_HOST_PM_H #include @@ -34,15 +34,13 @@ struct acpi_reset_reg { struct pm_s_state_data *get_host_sstate_data(void); void host_enter_s3(const struct pm_s_state_data *sstate_data, uint32_t pm1a_cnt_val, uint32_t pm1b_cnt_val); -void shutdown_system(void); void save_s5_reg_val(uint32_t pm1a_cnt_val, uint32_t pm1b_cnt_val); void do_acpi_sx(const struct pm_s_state_data *sstate_data, uint32_t pm1a_cnt_val, uint32_t pm1b_cnt_val); extern void asm_enter_s3(const struct pm_s_state_data *sstate_data, uint32_t pm1a_cnt_val, uint32_t pm1b_cnt_val); extern void restore_s3_context(void); struct cpu_state_info *get_cpu_pm_state_info(void); struct acpi_reset_reg *get_host_reset_reg_data(void); -void reset_host(bool warm); void init_frequency_policy(void); void apply_frequency_policy(void); -#endif /* HOST_PM_H */ +#endif /* X86_HOST_PM_H */ diff --git a/hypervisor/include/common/host_pm.h b/hypervisor/include/common/host_pm.h new file mode 100644 index 000000000..11c945d4e --- /dev/null +++ b/hypervisor/include/common/host_pm.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2018-2025 Intel Corporation. + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef HOST_PM_H +#define HOST_PM_H + +#include +#include + +void arch_shutdown_host(void); +void arch_reset_host(bool warm); + +static inline void shutdown_host(void) { + pr_info("Shutting down ACRN"); + arch_shutdown_host(); +} + +static inline void reset_host(bool warm) { + pr_info("%s resetting ACRN", warm ? "Warm" : "Cold"); + arch_reset_host(warm); +} + +#endif /* HOST_PM_H */