--- /dev/null
+/** @file\r
+\r
+ Stateless fw_cfg library implementation.\r
+\r
+ Clients must call QemuFwCfgIsAvailable() first.\r
+\r
+ Copyright (C) 2013, Red Hat, Inc.\r
+ Copyright (c) 2011 - 2013, Intel Corporation. All rights reserved.<BR>\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/DebugLib.h>\r
+#include <Library/QemuFwCfgLib.h>\r
+\r
+\r
+/**\r
+ Returns a boolean indicating if the firmware configuration interface\r
+ is available or not.\r
+\r
+ This function may change fw_cfg state.\r
+\r
+ @retval TRUE The interface is available\r
+ @retval FALSE The interface is not available\r
+\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+QemuFwCfgIsAvailable (\r
+ VOID\r
+ )\r
+{\r
+ UINT32 Signature;\r
+ UINT32 Revision;\r
+\r
+ QemuFwCfgSelectItem (QemuFwCfgItemSignature);\r
+ Signature = QemuFwCfgRead32 ();\r
+ DEBUG ((EFI_D_INFO, "FW CFG Signature: 0x%x\n", Signature));\r
+ QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion);\r
+ Revision = QemuFwCfgRead32 ();\r
+ DEBUG ((EFI_D_INFO, "FW CFG Revision: 0x%x\n", Revision));\r
+ if ((Signature != SIGNATURE_32 ('Q', 'E', 'M', 'U')) ||\r
+ (Revision < 1)\r
+ ) {\r
+ DEBUG ((EFI_D_INFO, "QemuFwCfg interface not supported.\n"));\r
+ return FALSE;\r
+ }\r
+\r
+ DEBUG ((EFI_D_INFO, "QemuFwCfg interface is supported.\n"));\r
+ return TRUE;\r
+}\r
+\r
+\r
+/**\r
+ Returns a boolean indicating if the firmware configuration interface is\r
+ available for library-internal purposes.\r
+\r
+ This function never changes fw_cfg state.\r
+\r
+ @retval TRUE The interface is available internally.\r
+ @retval FALSE The interface is not available internally.\r
+**/\r
+BOOLEAN\r
+EFIAPI\r
+InternalQemuFwCfgIsAvailable (\r
+ VOID\r
+ )\r
+{\r
+ //\r
+ // We always return TRUE, because the consumer of this library ought to have\r
+ // called QemuFwCfgIsAvailable before making other calls which would hit this\r
+ // path.\r
+ //\r
+ return TRUE;\r
+}\r
--- /dev/null
+## @file\r
+#\r
+# Stateless fw_cfg library that must be queried before use.\r
+#\r
+# Copyright (C) 2013, Red Hat, Inc.\r
+# Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.<BR>\r
+#\r
+# This program and the accompanying materials\r
+# are licensed and made available under the terms and conditions of the BSD License\r
+# which accompanies this 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,\r
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+#\r
+##\r
+\r
+[Defines]\r
+ INF_VERSION = 0x00010005\r
+ BASE_NAME = QemuFwCfgSecLib\r
+ FILE_GUID = 60a910e5-7443-413d-9a30-97e57497cd1b\r
+ MODULE_TYPE = BASE\r
+ VERSION_STRING = 1.0\r
+ LIBRARY_CLASS = QemuFwCfgLib|SEC\r
+\r
+#\r
+# The following information is for reference only and not required by the build tools.\r
+#\r
+# VALID_ARCHITECTURES = IA32 X64\r
+#\r
+\r
+[Sources]\r
+ QemuFwCfgLib.c\r
+ QemuFwCfgSec.c\r
+\r
+[Sources.IA32]\r
+ Ia32/IoLibExAsm.asm\r
+ Ia32/IoLibExAsm.S\r
+\r
+[Sources.X64]\r
+ X64/IoLibExAsm.asm\r
+ X64/IoLibExAsm.S\r
+\r
+[Packages]\r
+ MdePkg/MdePkg.dec\r
+ OvmfPkg/OvmfPkg.dec\r
+\r
+[LibraryClasses]\r
+ BaseLib\r
+ BaseMemoryLib\r
+ DebugLib\r
+ IoLib\r
+ MemoryAllocationLib\r
+\r