From 336ed72250cfaa71d8ca952f937eda5fdd0c5d17 Mon Sep 17 00:00:00 2001 From: Kaige Fu Date: Mon, 1 Apr 2019 17:00:24 +0000 Subject: [PATCH] HV: Minor refinement about RTVM pm MACRO and comments This patch mainly does the following: - Replace prefix RT_VM_ with VIRTUAL_. - Remove the check of "addr != RT_VM_PM1A_CNT_ADDR" as the handler is specific for this addr. - Add comments about the meaning of return value. Tracked-On: #2865 Signed-off-by: Kaige Fu Acked-by: Eddie Dong --- hypervisor/arch/x86/guest/pm.c | 12 ++++++---- hypervisor/include/arch/x86/guest/io_emul.h | 26 ++++++++++----------- hypervisor/include/public/acrn_common.h | 6 ++--- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/hypervisor/arch/x86/guest/pm.c b/hypervisor/arch/x86/guest/pm.c index 54e3d4c55..c7830cf68 100644 --- a/hypervisor/arch/x86/guest/pm.c +++ b/hypervisor/arch/x86/guest/pm.c @@ -222,12 +222,16 @@ static bool rt_vm_pm1a_io_read(__unused struct acrn_vm *vm, __unused struct acrn return false; } +/* + * retval true means that we complete the emulation in HV and no need to re-inject the request to DM. + * retval false means that we should re-inject the request to DM. + */ static bool rt_vm_pm1a_io_write(struct acrn_vm *vm, uint16_t addr, size_t width, uint32_t v) { - if ((addr != RT_VM_PM1A_CNT_ADDR) || (width != 2U)) { + if (width != 2U) { pr_dbg("Invalid address (0x%x) or width (0x%x)", addr, width); } else { - if (((v & RT_VM_PM1A_SLP_EN) && (((v & RT_VM_PM1A_SLP_TYP) >> 10U) == 5U)) != 0U) { + if (((v & VIRTUAL_PM1A_SLP_EN) && (((v & VIRTUAL_PM1A_SLP_TYP) >> 10U) == 5U)) != 0U) { vm->state = VM_POWERING_OFF; } } @@ -240,9 +244,9 @@ void register_rt_vm_pm1a_ctl_handler(struct acrn_vm *vm) struct vm_io_range io_range; io_range.flags = IO_ATTR_RW; - io_range.base = RT_VM_PM1A_CNT_ADDR; + io_range.base = VIRTUAL_PM1A_CNT_ADDR; io_range.len = 1U; - register_pio_emulation_handler(vm, RT_VM_PM1A_CNT_PIO_IDX, &io_range, + register_pio_emulation_handler(vm, VIRTUAL_PM1A_CNT_PIO_IDX, &io_range, &rt_vm_pm1a_io_read, &rt_vm_pm1a_io_write); } diff --git a/hypervisor/include/arch/x86/guest/io_emul.h b/hypervisor/include/arch/x86/guest/io_emul.h index 1de32168f..842590af8 100644 --- a/hypervisor/include/arch/x86/guest/io_emul.h +++ b/hypervisor/include/arch/x86/guest/io_emul.h @@ -10,19 +10,19 @@ #include /* Define emulated port IO index */ -#define PIC_MASTER_PIO_IDX 0U -#define PIC_SLAVE_PIO_IDX (PIC_MASTER_PIO_IDX + 1U) -#define PIC_ELC_PIO_IDX (PIC_SLAVE_PIO_IDX + 1U) -#define PCI_CFGADDR_PIO_IDX (PIC_ELC_PIO_IDX + 1U) -#define PCI_CFGDATA_PIO_IDX (PCI_CFGADDR_PIO_IDX + 1U) -#define UART_PIO_IDX (PCI_CFGDATA_PIO_IDX + 1U) -#define PM1A_EVT_PIO_IDX (UART_PIO_IDX + 1U) -#define PM1A_CNT_PIO_IDX (PM1A_EVT_PIO_IDX + 1U) -#define PM1B_EVT_PIO_IDX (PM1A_CNT_PIO_IDX + 1U) -#define PM1B_CNT_PIO_IDX (PM1B_EVT_PIO_IDX + 1U) -#define RTC_PIO_IDX (PM1B_CNT_PIO_IDX + 1U) -#define RT_VM_PM1A_CNT_PIO_IDX (RTC_PIO_IDX + 1U) -#define EMUL_PIO_IDX_MAX (RT_VM_PM1A_CNT_PIO_IDX + 1U) +#define PIC_MASTER_PIO_IDX 0U +#define PIC_SLAVE_PIO_IDX (PIC_MASTER_PIO_IDX + 1U) +#define PIC_ELC_PIO_IDX (PIC_SLAVE_PIO_IDX + 1U) +#define PCI_CFGADDR_PIO_IDX (PIC_ELC_PIO_IDX + 1U) +#define PCI_CFGDATA_PIO_IDX (PCI_CFGADDR_PIO_IDX + 1U) +#define UART_PIO_IDX (PCI_CFGDATA_PIO_IDX + 1U) +#define PM1A_EVT_PIO_IDX (UART_PIO_IDX + 1U) +#define PM1A_CNT_PIO_IDX (PM1A_EVT_PIO_IDX + 1U) +#define PM1B_EVT_PIO_IDX (PM1A_CNT_PIO_IDX + 1U) +#define PM1B_CNT_PIO_IDX (PM1B_EVT_PIO_IDX + 1U) +#define RTC_PIO_IDX (PM1B_CNT_PIO_IDX + 1U) +#define VIRTUAL_PM1A_CNT_PIO_IDX (RTC_PIO_IDX + 1U) +#define EMUL_PIO_IDX_MAX (VIRTUAL_PM1A_CNT_PIO_IDX + 1U) /** * @brief The handler of VM exits on I/O instructions diff --git a/hypervisor/include/public/acrn_common.h b/hypervisor/include/public/acrn_common.h index e0dced4e4..1193dd849 100644 --- a/hypervisor/include/public/acrn_common.h +++ b/hypervisor/include/public/acrn_common.h @@ -55,9 +55,9 @@ #define GUEST_FLAG_RT (1UL << 5U) /* Whether the vm is RT-VM */ /* TODO: We may need to get this addr from guest ACPI instead of hardcode here */ -#define RT_VM_PM1A_CNT_ADDR 0x404U -#define RT_VM_PM1A_SLP_TYP 0x1c00U -#define RT_VM_PM1A_SLP_EN 0x2000U +#define VIRTUAL_PM1A_CNT_ADDR 0x404U +#define VIRTUAL_PM1A_SLP_TYP 0x1c00U +#define VIRTUAL_PM1A_SLP_EN 0x2000U /** * @brief Hypercall