]> git.proxmox.com Git - mirror_edk2.git/blobdiff - OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3PeiDxe.c
OvmfPkg/QemuFwCfgS3Lib: add initial PEI and DXE fw_cfg library instances
[mirror_edk2.git] / OvmfPkg / Library / QemuFwCfgS3Lib / QemuFwCfgS3PeiDxe.c
diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3PeiDxe.c b/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3PeiDxe.c
new file mode 100644 (file)
index 0000000..f87d6b8
--- /dev/null
@@ -0,0 +1,48 @@
+/** @file\r
+  Shared code for the PEI fw_cfg and DXE fw_cfg instances of the QemuFwCfgS3Lib\r
+  class.\r
+\r
+  Copyright (C) 2017, Red Hat, Inc.\r
+\r
+  This program and the accompanying materials are licensed and made available\r
+  under the terms and conditions of the BSD License which accompanies this\r
+  distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT\r
+  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+**/\r
+\r
+#include <Library/QemuFwCfgLib.h>\r
+#include <Library/QemuFwCfgS3Lib.h>\r
+\r
+/**\r
+  Determine if S3 support is explicitly enabled.\r
+\r
+  @retval  TRUE   If S3 support is explicitly enabled. Other functions in this\r
+                  library may be called (subject to their individual\r
+                  restrictions).\r
+\r
+           FALSE  Otherwise. This includes unavailability of the firmware\r
+                  configuration interface. No other function in this library\r
+                  must be called.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+QemuFwCfgS3Enabled (\r
+  VOID\r
+  )\r
+{\r
+  RETURN_STATUS        Status;\r
+  FIRMWARE_CONFIG_ITEM FwCfgItem;\r
+  UINTN                FwCfgSize;\r
+  UINT8                SystemStates[6];\r
+\r
+  Status = QemuFwCfgFindFile ("etc/system-states", &FwCfgItem, &FwCfgSize);\r
+  if (Status != RETURN_SUCCESS || FwCfgSize != sizeof SystemStates) {\r
+    return FALSE;\r
+  }\r
+  QemuFwCfgSelectItem (FwCfgItem);\r
+  QemuFwCfgReadBytes (sizeof SystemStates, SystemStates);\r
+  return (BOOLEAN) (SystemStates[3] & BIT7);\r
+}\r