From c4ec7ac3584affec3d002ef1bb550ff356758077 Mon Sep 17 00:00:00 2001 From: Kaige Fu Date: Thu, 4 Apr 2019 10:29:45 +0000 Subject: [PATCH] DM: Keep consistency between HV and DM about PM1A_CNT_ADDR To keep consistency between HV and DM about PM1A_CNT_ADDR, it is better to replace the PM1A_CNT related MACROs used in DM with VIRTUAL_PM1A_CNT related MACROs in acrn_common.h. Tracked-On: #2865 Signed-off-by: Kaige Fu Acked-by: Eddie Dong --- devicemodel/arch/x86/pm.c | 23 +++++++++-------------- devicemodel/hw/platform/acpi/acpi.c | 4 ++-- devicemodel/include/acpi.h | 1 - hypervisor/include/public/acrn_common.h | 8 +++++--- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/devicemodel/arch/x86/pm.c b/devicemodel/arch/x86/pm.c index dc8f3f143..bf0c870f2 100644 --- a/devicemodel/arch/x86/pm.c +++ b/devicemodel/arch/x86/pm.c @@ -149,11 +149,6 @@ static uint16_t pm1_enable, pm1_status; */ static uint16_t pm1_control; -#define PM1_SCI_EN 0x0001 -#define PM1_SLP_TYP 0x1c00 -#define PM1_SLP_EN 0x2000 -#define PM1_ALWAYS_ZERO 0xc003 - static void sci_update(struct vmctx *ctx) { @@ -163,7 +158,7 @@ sci_update(struct vmctx *ctx) * Followed ACPI spec, should trigger SMI if SCI_EN is zero. * Return directly due to ACRN do not support SMI so far. */ - if (!(pm1_control & PM1_SCI_EN)) + if (!(pm1_control & VIRTUAL_PM1A_SCI_EN)) return; /* See if the SCI should be active or not. */ @@ -296,20 +291,20 @@ pm1_control_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, * to zero in pm1_control. Always preserve SCI_EN as OSPM * can never change it. */ - pm1_control = (pm1_control & PM1_SCI_EN) | - (*eax & ~(PM1_SLP_EN | PM1_ALWAYS_ZERO)); + pm1_control = (pm1_control & VIRTUAL_PM1A_SCI_EN) | + (*eax & ~(VIRTUAL_PM1A_SLP_EN | VIRTUAL_PM1A_ALWAYS_ZERO)); /* * If SLP_EN is set, check for S5. ACRN-DM's _S5_ method * says that '5' should be stored in SLP_TYP for S5. */ - if (*eax & PM1_SLP_EN) { - if ((pm1_control & PM1_SLP_TYP) >> 10 == 5) { + if (*eax & VIRTUAL_PM1A_SLP_EN) { + if ((pm1_control & VIRTUAL_PM1A_SLP_TYP) >> 10 == 5) { error = vm_suspend(ctx, VM_SUSPEND_POWEROFF); assert(error == 0 || errno == EALREADY); } - if ((pm1_control & PM1_SLP_TYP) >> 10 == 3) { + if ((pm1_control & VIRTUAL_PM1A_SLP_TYP) >> 10 == 3) { error = vm_suspend(ctx, VM_SUSPEND_SUSPEND); assert(error == 0 || errno == EALREADY); } @@ -317,7 +312,7 @@ pm1_control_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, } return 0; } -INOUT_PORT(pm1_control, PM1A_CNT_ADDR, IOPORT_F_INOUT, pm1_control_handler); +INOUT_PORT(pm1_control, VIRTUAL_PM1A_CNT_ADDR, IOPORT_F_INOUT, pm1_control_handler); SYSRES_IO(PM1A_EVT_ADDR, 8); static int @@ -464,7 +459,7 @@ smi_cmd_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, pthread_mutex_lock(&pm_lock); switch (*eax) { case ACPI_ENABLE: - pm1_control |= PM1_SCI_EN; + pm1_control |= VIRTUAL_PM1A_SCI_EN; /* * FIXME: ACPI_ENABLE/ACPI_DISABLE only impacts SCI_EN via SMI * command register, not impact power button emulation. so need @@ -507,7 +502,7 @@ smi_cmd_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, } break; case ACPI_DISABLE: - pm1_control &= ~PM1_SCI_EN; + pm1_control &= ~VIRTUAL_PM1A_SCI_EN; if (power_button != NULL) { mevent_delete(power_button); power_button = NULL; diff --git a/devicemodel/hw/platform/acpi/acpi.c b/devicemodel/hw/platform/acpi/acpi.c index e27a00779..150f84c16 100644 --- a/devicemodel/hw/platform/acpi/acpi.c +++ b/devicemodel/hw/platform/acpi/acpi.c @@ -364,7 +364,7 @@ basl_fwrite_fadt(FILE *fp, struct vmctx *ctx) PM1A_EVT_ADDR); EFPRINTF(fp, "[0004]\t\tPM1B Event Block Address : 00000000\n"); EFPRINTF(fp, "[0004]\t\tPM1A Control Block Address : %08X\n", - PM1A_CNT_ADDR); + VIRTUAL_PM1A_CNT_ADDR); EFPRINTF(fp, "[0004]\t\tPM1B Control Block Address : 00000000\n"); EFPRINTF(fp, "[0004]\t\tPM2 Control Block Address : 00000000\n"); EFPRINTF(fp, "[0004]\t\tPM Timer Block Address : %08X\n", @@ -466,7 +466,7 @@ basl_fwrite_fadt(FILE *fp, struct vmctx *ctx) EFPRINTF(fp, "[0001]\t\tBit Offset : 00\n"); EFPRINTF(fp, "[0001]\t\tEncoded Access Width : 02 [Word Access:16]\n"); EFPRINTF(fp, "[0008]\t\tAddress : 00000000%08X\n", - PM1A_CNT_ADDR); + VIRTUAL_PM1A_CNT_ADDR); EFPRINTF(fp, "\n"); EFPRINTF(fp, diff --git a/devicemodel/include/acpi.h b/devicemodel/include/acpi.h index ae4415ee1..6097a3a50 100644 --- a/devicemodel/include/acpi.h +++ b/devicemodel/include/acpi.h @@ -36,7 +36,6 @@ #define ACPI_DISABLE 0xa1 #define PM1A_EVT_ADDR 0x400 -#define PM1A_CNT_ADDR 0x404 #define IO_PMTMR 0x408 /* 4-byte i/o port for the timer */ diff --git a/hypervisor/include/public/acrn_common.h b/hypervisor/include/public/acrn_common.h index 1193dd849..192254015 100644 --- a/hypervisor/include/public/acrn_common.h +++ b/hypervisor/include/public/acrn_common.h @@ -55,9 +55,11 @@ #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 VIRTUAL_PM1A_CNT_ADDR 0x404U -#define VIRTUAL_PM1A_SLP_TYP 0x1c00U -#define VIRTUAL_PM1A_SLP_EN 0x2000U +#define VIRTUAL_PM1A_CNT_ADDR 0x404U +#define VIRTUAL_PM1A_SCI_EN 0x0001 +#define VIRTUAL_PM1A_SLP_TYP 0x1c00U +#define VIRTUAL_PM1A_SLP_EN 0x2000U +#define VIRTUAL_PM1A_ALWAYS_ZERO 0xc003 /** * @brief Hypercall