OvmfPkg: create \_S3 and \_S4 packages dynamically

Move these states from the DSDT to the SSDT. Override the default
configuration if the host has the following qemu commit:

    commit 459ae5ea5ad682c2b3220beb244d4102c1a4e332
    Author: Gleb Natapov <gleb@redhat.com>
    Date:   Mon Jun 4 14:31:55 2012 +0300

        Add PIIX4 properties to control PM system states.

        This patch adds two things. First it allows QEMU to distinguish
        between regular powerdown and S4 powerdown. Later separate QMP
        notification will be added for S4 powerdown. Second it allows
        S3/S4 states to be disabled from QEMU command line. Some guests
        known to be broken with regards to power management, but allow to
        use it anyway. Using new properties management will be able to
        disable S3/S4 for such guests.

        Supported system state are passed to a firmware using new fw_cfg
        file. The file contains  6 byte array. Each byte represents one
        system state. If byte at offset X has its MSB set it means that
        system state X is supported and to enter it guest should use the
        value from lowest 3 bits.

        Signed-off-by: Gleb Natapov <gleb@redhat.com>
        Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14003 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
jljusten 2012-12-17 02:13:14 +00:00
parent fb8a1b44a8
commit 14430c55c8
2 changed files with 110 additions and 5 deletions

View File

@ -2,6 +2,9 @@
OVMF ACPI QEMU support
Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>
Copyright (C) 2012, Red Hat, Inc.
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
@ -196,6 +199,19 @@ typedef struct {
PCI_WINDOW PciWindow64;
} FIRMWARE_DATA;
typedef struct {
UINT8 NameOp;
UINT8 RootChar;
UINT8 NameChar[4];
UINT8 PackageOp;
UINT8 PkgLength;
UINT8 NumElements;
UINT8 DWordPrefix;
UINT8 Pm1aCntSlpTyp;
UINT8 Pm1bCntSlpTyp;
UINT8 Reserved[2];
} SYSTEM_STATE_PACKAGE;
#pragma pack()
@ -295,6 +311,80 @@ PopulateFwData(
}
STATIC
VOID
EFIAPI
GetSuspendStates (
UINTN *SuspendToRamSize,
SYSTEM_STATE_PACKAGE *SuspendToRam,
UINTN *SuspendToDiskSize,
SYSTEM_STATE_PACKAGE *SuspendToDisk
)
{
STATIC CONST SYSTEM_STATE_PACKAGE Template = {
0x08, // NameOp
'\\', // RootChar
{ '_', 'S', 'x', '_' }, // NameChar[4]
0x12, // PackageOp
0x07, // PkgLength
0x01, // NumElements
0x0c, // DWordPrefix
0x00, // Pm1aCntSlpTyp
0x00, // Pm1bCntSlpTyp -- we don't support it
{ 0x00, 0x00 } // Reserved
};
RETURN_STATUS Status;
FIRMWARE_CONFIG_ITEM FwCfgItem;
UINTN FwCfgSize;
UINT8 SystemStates[6];
//
// configure defaults
//
*SuspendToRamSize = sizeof Template;
CopyMem (SuspendToRam, &Template, sizeof Template);
SuspendToRam->NameChar[2] = '3'; // S3
SuspendToRam->Pm1aCntSlpTyp = 1; // PIIX4: STR
*SuspendToDiskSize = sizeof Template;
CopyMem (SuspendToDisk, &Template, sizeof Template);
SuspendToDisk->NameChar[2] = '4'; // S4
SuspendToDisk->Pm1aCntSlpTyp = 2; // PIIX4: POSCL
//
// check for overrides
//
Status = QemuFwCfgFindFile ("etc/system-states", &FwCfgItem, &FwCfgSize);
if (Status != RETURN_SUCCESS || FwCfgSize != sizeof SystemStates) {
DEBUG ((DEBUG_INFO, "ACPI using S3/S4 defaults\n"));
return;
}
QemuFwCfgSelectItem (FwCfgItem);
QemuFwCfgReadBytes (sizeof SystemStates, SystemStates);
//
// Each byte corresponds to a system state. In each byte, the MSB tells us
// whether the given state is enabled. If so, the three LSBs specify the
// value to be written to the PM control register's SUS_TYP bits.
//
if (SystemStates[3] & BIT7) {
SuspendToRam->Pm1aCntSlpTyp = SystemStates[3] & (BIT2 | BIT1 | BIT0);
DEBUG ((DEBUG_INFO, "ACPI S3 value: %d\n", SuspendToRam->Pm1aCntSlpTyp));
} else {
*SuspendToRamSize = 0;
DEBUG ((DEBUG_INFO, "ACPI S3 disabled\n"));
}
if (SystemStates[4] & BIT7) {
SuspendToDisk->Pm1aCntSlpTyp = SystemStates[4] & (BIT2 | BIT1 | BIT0);
DEBUG ((DEBUG_INFO, "ACPI S4 value: %d\n", SuspendToDisk->Pm1aCntSlpTyp));
} else {
*SuspendToDiskSize = 0;
DEBUG ((DEBUG_INFO, "ACPI S4 disabled\n"));
}
}
STATIC
EFI_STATUS
EFIAPI
@ -312,10 +402,16 @@ QemuInstallAcpiSsdtTable (
FwData = AllocateReservedPool (sizeof (*FwData));
if (FwData != NULL) {
UINTN SsdtSize;
UINT8 *Ssdt;
UINTN SuspendToRamSize;
SYSTEM_STATE_PACKAGE SuspendToRam;
UINTN SuspendToDiskSize;
SYSTEM_STATE_PACKAGE SuspendToDisk;
UINTN SsdtSize;
UINT8 *Ssdt;
SsdtSize = AcpiTableBufferSize + 17;
GetSuspendStates (&SuspendToRamSize, &SuspendToRam,
&SuspendToDiskSize, &SuspendToDisk);
SsdtSize = AcpiTableBufferSize + 17 + SuspendToRamSize + SuspendToDiskSize;
Ssdt = AllocatePool (SsdtSize);
if (Ssdt != NULL) {
@ -352,6 +448,14 @@ QemuInstallAcpiSsdtTable (
*(UINT32*) SsdtPtr = sizeof (*FwData);
SsdtPtr += 4;
//
// add suspend system states
//
CopyMem (SsdtPtr, &SuspendToRam, SuspendToRamSize);
SsdtPtr += SuspendToRamSize;
CopyMem (SsdtPtr, &SuspendToDisk, SuspendToDiskSize);
SsdtPtr += SuspendToDiskSize;
ASSERT((UINTN) (SsdtPtr - Ssdt) == SsdtSize);
((EFI_ACPI_DESCRIPTION_HEADER *) Ssdt)->Length = (UINT32) SsdtSize;
Status = InstallAcpiTable (AcpiProtocol, Ssdt, SsdtSize, TableKey);

View File

@ -16,9 +16,10 @@ DefinitionBlock ("Dsdt.aml", "DSDT", 1, "INTEL ", "OVMF ", 4) {
//
// System Sleep States
//
// We build S3 and S4 with GetSuspendStates() in
// "OvmfPkg/AcpiPlatformDxe/Qemu.c".
//
Name (\_S0, Package () {5, 0, 0, 0}) // Working
Name (\_S3, Package () {1, 0, 0, 0}) // Suspend to Ram (PIIX4: STR)
Name (\_S4, Package () {2, 0, 0, 0}) // Suspend to Disk (PIIX4: POSCL)
Name (\_S5, Package () {0, 0, 0, 0}) // Soft Off
//