Insert a default, OVMF-specific Type 0 (BIOS Information) structure
into the SMBIOS table, unless the underlying guest VM supplies its
own, overriding instance.

As an example, QEMU, while allowing the user to specifically force
generation of a Type 0 structure, will not generate one by default,
considering that task to be the responsibility of the BIOS itself.

Based on an earlier out-of-tree patch by Laszlo Ersek <[email protected]>

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Gabriel Somlo <[email protected]>
---

Type 0 is one of the required SMBIOS structures, but QEMU will only
generate one if the user forces it to do so, via the command line. The
default attitude of QEMU is that the "BIOS Information" table should be
the BIOS's responsibility.

I'm having trouble finding the exact set of posts on the list archive,
but I remember recording the result of these conversations in the qemu
source (hw/i386/smbios.c, function smbios_build_type_0_table, first
comment stating "optional, leave up to BIOS"). Also, in the corresponding
SeaBIOS commit blurb (d85c22e44ee4e24f2be19d579ea8fa0066a85fbb), the
statement about the need to insert a Type 0 structure being "the expected
common case".

If the SMBIOS table shipping with the underlying VM contains a Type 0
structure, we simply do nothing. Otherwise, we really should add our
own Type 0 structure, and this patch takes care of that.

Thanks,
  Gabriel

 OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c | 66 +++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)

diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c 
b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
index 626f7db..4f76121 100644
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
@@ -16,6 +16,51 @@
 
 #include "SmbiosPlatformDxe.h"
 
+//
+// Type definition and contents of the default Type 0 SMBIOS table.
+//
+#pragma pack(1)
+typedef struct {
+  SMBIOS_TABLE_TYPE0 Base;
+  UINT8              Strings[];
+} OVMF_TYPE0;
+#pragma pack()
+
+STATIC CONST OVMF_TYPE0 mOvmfDefaultType0 = {
+  {
+    // SMBIOS_STRUCTURE Hdr
+    {
+      EFI_SMBIOS_TYPE_BIOS_INFORMATION, // UINT8 Type
+      sizeof (SMBIOS_TABLE_TYPE0),      // UINT8 Length
+    },
+    1,     // SMBIOS_TABLE_STRING       Vendor
+    2,     // SMBIOS_TABLE_STRING       BiosVersion
+    0xE800,// UINT16                    BiosSegment
+    3,     // SMBIOS_TABLE_STRING       BiosReleaseDate
+    0,     // UINT8                     BiosSize
+    {      // MISC_BIOS_CHARACTERISTICS BiosCharacteristics
+      0,     // Reserved                                      :2
+      0,     // Unknown                                       :1
+      1,     // BiosCharacteristicsNotSupported               :1
+             // Remaining BiosCharacteristics bits left unset :60
+    },
+    {      // BIOSCharacteristicsExtensionBytes[2]
+      0,     // BiosReserved
+      0x1C   // SystemReserved = VirtualMachineSupported |
+             //                  UefiSpecificationSupported |
+             //                  TargetContentDistributionEnabled
+    },
+    0,     // UINT8                     SystemBiosMajorRelease
+    0,     // UINT8                     SystemBiosMinorRelease
+    0xFF,  // UINT8                     EmbeddedControllerFirmwareMajorRelease
+    0xFF   // UINT8                     EmbeddedControllerFirmwareMinorRelease
+  },
+  // Text strings (unformatted area)
+  "EFI Development Kit II / OVMF\0"     // Vendor
+  "0.1\0"                               // BiosVersion
+  "02/06/2015\0"                        // BiosReleaseDate
+};
+
 
 /**
   Validates the SMBIOS entry point structure
@@ -96,12 +141,15 @@ InstallAllStructures (
   EFI_STATUS                Status;
   SMBIOS_STRUCTURE_POINTER  SmbiosTable;
   EFI_SMBIOS_HANDLE         SmbiosHandle;
+  BOOLEAN                   NeedSmbiosType0;
 
   SmbiosTable.Raw = TableAddress;
   if (SmbiosTable.Raw == NULL) {
     return EFI_INVALID_PARAMETER;
   }
 
+  NeedSmbiosType0 = TRUE;
+
   while (SmbiosTable.Hdr->Type != 127) {
     //
     // Log the SMBIOS data for this structure
@@ -115,12 +163,30 @@ InstallAllStructures (
                        );
     ASSERT_EFI_ERROR (Status);
 
+    if (SmbiosTable.Hdr->Type == 0) {
+      NeedSmbiosType0 = FALSE;
+    }
+
     //
     // Get the next structure address
     //
     SmbiosTable.Raw = (UINT8 *)(SmbiosTable.Raw + SmbiosTableLength 
(SmbiosTable));
   }
 
+  if (NeedSmbiosType0) {
+    //
+    // Add OVMF default Type 0 (BIOS Information) table
+    //
+    SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;
+    Status = Smbios->Add (
+                       Smbios,
+                       NULL,
+                       &SmbiosHandle,
+                       (EFI_SMBIOS_TABLE_HEADER*) &mOvmfDefaultType0
+                       );
+    ASSERT_EFI_ERROR (Status);
+  }
+
   return EFI_SUCCESS;
 }
 
-- 
2.1.0


------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
edk2-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to