Revision: 14003
          http://edk2.svn.sourceforge.net/edk2/?rev=14003&view=rev
Author:   jljusten
Date:     2012-12-17 02:13:14 +0000 (Mon, 17 Dec 2012)
Log Message:
-----------
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 <[email protected]>
    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 <[email protected]>
        Signed-off-by: Anthony Liguori <[email protected]>

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <[email protected]>
Reviewed-by: Jordan Justen <[email protected]>

Modified Paths:
--------------
    trunk/edk2/OvmfPkg/AcpiPlatformDxe/Qemu.c
    trunk/edk2/OvmfPkg/AcpiTables/Dsdt.asl

Modified: trunk/edk2/OvmfPkg/AcpiPlatformDxe/Qemu.c
===================================================================
--- trunk/edk2/OvmfPkg/AcpiPlatformDxe/Qemu.c   2012-12-17 02:13:00 UTC (rev 
14002)
+++ trunk/edk2/OvmfPkg/AcpiPlatformDxe/Qemu.c   2012-12-17 02:13:14 UTC (rev 
14003)
@@ -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 @@
   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()
 
 
@@ -296,6 +312,80 @@
 
 
 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
 QemuInstallAcpiSsdtTable (
@@ -312,10 +402,16 @@
 
   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 @@
         *(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);

Modified: trunk/edk2/OvmfPkg/AcpiTables/Dsdt.asl
===================================================================
--- trunk/edk2/OvmfPkg/AcpiTables/Dsdt.asl      2012-12-17 02:13:00 UTC (rev 
14002)
+++ trunk/edk2/OvmfPkg/AcpiTables/Dsdt.asl      2012-12-17 02:13:14 UTC (rev 
14003)
@@ -16,9 +16,10 @@
   //
   // 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
 
   //

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
LogMeIn Rescue: Anywhere, Anytime Remote support for IT. Free Trial
Remotely access PCs and mobile devices and provide instant support
Improve your efficiency, and focus on delivering more value-add services
Discover what IT Professionals Know. Rescue delivers
http://p.sf.net/sfu/logmein_12329d2d
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to