]> git.proxmox.com Git - mirror_edk2.git/commitdiff
OvmfPkg/SMBIOS: Add QEMU support to OVMF SMBIOS driver
authorGabriel Somlo <somlo@cmu.edu>
Tue, 20 May 2014 16:33:19 +0000 (16:33 +0000)
committerjljusten <jljusten@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 20 May 2014 16:33:19 +0000 (16:33 +0000)
Locate QEMU SMBIOS data in fw_cfg and install it via the
SMBIOS protocol.

Starting with qemu-2.1, on pc/x86 machines of type >= 2.1, full
SMBIOS tables are generated and inserted into fw_cfg (i.e., no
per-field patching of locally generated structures is required).

Aside from new code to extract a SMBIOS blob from fw_cfg, this
patch utilizes the pre-existing infrastructure (already used by
Xen) to handle final SMBIOS table creation.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Gabriel Somlo <somlo@cmu.edu>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15542 6f19259b-4bc3-4df7-8a09-765794883524

OvmfPkg/SmbiosPlatformDxe/Qemu.c [new file with mode: 0644]
OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.h
OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf

diff --git a/OvmfPkg/SmbiosPlatformDxe/Qemu.c b/OvmfPkg/SmbiosPlatformDxe/Qemu.c
new file mode 100644 (file)
index 0000000..f7ace4f
--- /dev/null
@@ -0,0 +1,66 @@
+/** @file\r
+  Find and extract QEMU SMBIOS data from fw_cfg.\r
+\r
+  Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>\r
+\r
+  This program and the accompanying materials are licensed and made\r
+  available under the terms and conditions of the BSD License which\r
+  accompanies this distribution.   The full text of the license may\r
+  be found at 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
+#include "SmbiosPlatformDxe.h"\r
+#include <Library/QemuFwCfgLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
+\r
+/**\r
+  Locates and extracts the QEMU SMBIOS data if present in fw_cfg\r
+\r
+  @return                 Address of extracted QEMU SMBIOS data\r
+\r
+**/\r
+UINT8 *\r
+GetQemuSmbiosTables (\r
+  VOID\r
+  )\r
+{\r
+  SMBIOS_TABLE_ENTRY_POINT QemuAnchor;\r
+  FIRMWARE_CONFIG_ITEM     Anchor, Tables;\r
+  UINTN                    AnchorSize, TablesSize;\r
+  UINT8                    *QemuTables;\r
+\r
+  if (EFI_ERROR (QemuFwCfgFindFile (\r
+                   "etc/smbios/smbios-anchor", &Anchor, &AnchorSize)) ||\r
+      EFI_ERROR (QemuFwCfgFindFile (\r
+                   "etc/smbios/smbios-tables", &Tables, &TablesSize)) ||\r
+      AnchorSize != sizeof (QemuAnchor) ||\r
+      TablesSize == 0) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // We copy the entry point structure to perform some additional checks,\r
+  // but discard it upon return.\r
+  //\r
+  QemuFwCfgSelectItem (Anchor);\r
+  QemuFwCfgReadBytes (AnchorSize, &QemuAnchor);\r
+\r
+  if (AsciiStrnCmp ((CHAR8 *)QemuAnchor.AnchorString, "_SM_", 4) ||\r
+      AsciiStrnCmp ((CHAR8 *)QemuAnchor.IntermediateAnchorString, "_DMI_", 5) ||\r
+      TablesSize != QemuAnchor.TableLength) {\r
+    return NULL;\r
+  }\r
+\r
+  QemuTables = AllocatePool (TablesSize);\r
+  if (QemuTables == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  QemuFwCfgSelectItem (Tables);\r
+  QemuFwCfgReadBytes (TablesSize, QemuTables);\r
+\r
+  return QemuTables;\r
+}\r
index ac48fb720819292092c6eba44cd9aaa7fef6db22..626f7dbbfb95ba65852e2ca480b2769e861d5239 100644 (file)
@@ -84,20 +84,20 @@ SmbiosTableLength (
   Install all structures from the given SMBIOS structures block\r
 \r
   @param  Smbios               SMBIOS protocol\r
-  @param  EntryPointStructure  SMBIOS entry point structures block\r
+  @param  TableAddress         SMBIOS tables starting address\r
 \r
 **/\r
 EFI_STATUS\r
 InstallAllStructures (\r
   IN EFI_SMBIOS_PROTOCOL       *Smbios,\r
-  IN SMBIOS_TABLE_ENTRY_POINT  *EntryPointStructure\r
+  IN UINT8                     *TableAddress\r
   )\r
 {\r
   EFI_STATUS                Status;\r
   SMBIOS_STRUCTURE_POINTER  SmbiosTable;\r
   EFI_SMBIOS_HANDLE         SmbiosHandle;\r
 \r
-  SmbiosTable.Raw = (UINT8*)(UINTN) EntryPointStructure->TableAddress;\r
+  SmbiosTable.Raw = TableAddress;\r
   if (SmbiosTable.Raw == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -145,6 +145,7 @@ SmbiosTablePublishEntry (
   EFI_STATUS                Status;\r
   EFI_SMBIOS_PROTOCOL       *Smbios;\r
   SMBIOS_TABLE_ENTRY_POINT  *EntryPointStructure;\r
+  UINT8                     *SmbiosTables;\r
 \r
   //\r
   // Find the SMBIOS protocol\r
@@ -159,11 +160,24 @@ SmbiosTablePublishEntry (
   }\r
 \r
   //\r
-  // Add Xen SMBIOS data if found\r
+  // Add Xen or QEMU SMBIOS data if found\r
   //\r
   EntryPointStructure = GetXenSmbiosTables ();\r
   if (EntryPointStructure != NULL) {\r
-    Status = InstallAllStructures (Smbios, EntryPointStructure);\r
+    SmbiosTables = (UINT8*)(UINTN)EntryPointStructure->TableAddress;\r
+  } else {\r
+    SmbiosTables = GetQemuSmbiosTables ();\r
+  }\r
+\r
+  if (SmbiosTables != NULL) {\r
+    Status = InstallAllStructures (Smbios, SmbiosTables);\r
+\r
+    //\r
+    // Free SmbiosTables if allocated by Qemu (i.e., NOT by Xen):\r
+    //\r
+    if (EntryPointStructure == NULL) {\r
+      FreePool (SmbiosTables);\r
+    }\r
   }\r
 \r
   return Status;\r
index bf99e43ba3dbc4bd1981cd0fe295763681c6ce09..e2606e1de8cbf0569a92d5954cabb8ac632231e9 100644 (file)
@@ -25,6 +25,7 @@
 #include <Library/BaseLib.h>\r
 #include <Library/BaseMemoryLib.h>\r
 #include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/MemoryAllocationLib.h>\r
 \r
 \r
 /**\r
@@ -39,6 +40,18 @@ GetXenSmbiosTables (
   );\r
 \r
 \r
+/**\r
+  Locates and extracts the QEMU SMBIOS table data if present in fw_cfg\r
+\r
+  @return             Address of extracted QEMU SMBIOS data\r
+\r
+**/\r
+UINT8 *\r
+GetQemuSmbiosTables (\r
+  VOID\r
+  );\r
+\r
+\r
 /**\r
   Validates the SMBIOS entry point structure\r
 \r
index 70582849447c90d8df26c506209124f4ec717a06..65963920951219dbfe86c6bc9846c82d07966566 100644 (file)
@@ -32,6 +32,7 @@
   SmbiosPlatformDxe.h\r
   SmbiosPlatformDxe.c\r
   Xen.c\r
+  Qemu.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
@@ -45,6 +46,8 @@
   UefiDriverEntryPoint\r
   DebugLib\r
   HobLib\r
+  QemuFwCfgLib\r
+  MemoryAllocationLib\r
 \r
 [Protocols]\r
   gEfiSmbiosProtocolGuid                      # PROTOCOL ALWAYS_CONSUMED\r