Skip to content

Commit

Permalink
DM: Keep consistency between HV and DM about PM1A_CNT_ADDR
Browse files Browse the repository at this point in the history
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: projectacrn#2865
Signed-off-by: Kaige Fu <[email protected]>
Acked-by: Eddie Dong <[email protected]>
  • Loading branch information
KaigeFu authored and dongyaozu committed Apr 4, 2019
1 parent ede5987 commit c4ec7ac
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 20 deletions.
23 changes: 9 additions & 14 deletions devicemodel/arch/x86/pm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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. */
Expand Down Expand Up @@ -296,28 +291,28 @@ 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);
}
}
}
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions devicemodel/hw/platform/acpi/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion devicemodel/include/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down
8 changes: 5 additions & 3 deletions hypervisor/include/public/acrn_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c4ec7ac

Please sign in to comment.