[edk2-devel] [PATCH] OvmfPkg/SmbiosPlatformDxe: Always add BIOS Information structure

Ammar Ratnani posted 1 patch 1 year, 8 months ago
Failed in applying to current master (apply log)
OvmfPkg/SmbiosPlatformDxe/EntryPoint.c        | 11 ++++
OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c | 59 +++++++++++--------
2 files changed, 44 insertions(+), 26 deletions(-)
[edk2-devel] [PATCH] OvmfPkg/SmbiosPlatformDxe: Always add BIOS Information structure
Posted by Ammar Ratnani 1 year, 8 months ago
If OVMF is not running on Cloud Hypervisor nor QEMU, previously no SMBIOS
structures would be registered with the EFI_SMBIOS_PROTOCOL. This patch
instead registers the default BIOS Information (Type 0) structure, defined
as mOvmfDefaultType0 in SmbiosPlatformDxe.c.

This change appeases (at least) the Windows Deployment Services client,
which requires some SMBIOS data to be present.

Signed-off-by: Ammar Ratnani <ammrat13@gmail.com>
---
 OvmfPkg/SmbiosPlatformDxe/EntryPoint.c        | 11 ++++
 OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c | 59 +++++++++++--------
 2 files changed, 44 insertions(+), 26 deletions(-)

diff --git a/OvmfPkg/SmbiosPlatformDxe/EntryPoint.c b/OvmfPkg/SmbiosPlatformDxe/EntryPoint.c
index e55d135504..4f82cf5da8 100644
--- a/OvmfPkg/SmbiosPlatformDxe/EntryPoint.c
+++ b/OvmfPkg/SmbiosPlatformDxe/EntryPoint.c
@@ -48,5 +48,16 @@ SmbiosTablePublishEntry (
     }
   }
 
+  //
+  // If Status still reads EFI_NOT_FOUND, either there are no drivers
+  // implementing EFI_SMBIOS_PROTOCOL, or none of the above codepaths ran. In
+  // the second case, call InstallAllStructures with NULL so that the default
+  // Type 0 (BIOS Information) structure is installed. In the first case,
+  // calling InstallAllStructures is harmless because it'll fail immediately.
+  //
+  if (Status == EFI_NOT_FOUND) {
+    Status = InstallAllStructures (NULL);
+  }
+
   return Status;
 }
diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
index 94249d3ff1..e575a5f141 100644
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
@@ -93,12 +93,17 @@ SmbiosTableLength (
 /**
   Install all structures from the given SMBIOS structures block
 
+  Notice that the SMBIOS table address is optional. If it's not provided, this
+  function will function as if the first structure encountered is an
+  End-of-Table (Type 127). Importantly, in that case it will still install
+  mOvmfDefaultType0.
+
   @param  TableAddress         SMBIOS tables starting address
 
 **/
 EFI_STATUS
 InstallAllStructures (
-  IN UINT8  *TableAddress
+  IN UINT8  *TableAddress  OPTIONAL
   )
 {
   EFI_SMBIOS_PROTOCOL       *Smbios;
@@ -119,34 +124,36 @@ InstallAllStructures (
     return Status;
   }
 
-  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
-    //
-    SmbiosHandle = SmbiosTable.Hdr->Handle;
-    Status       = Smbios->Add (
-                             Smbios,
-                             NULL,
-                             &SmbiosHandle,
-                             (EFI_SMBIOS_TABLE_HEADER *)SmbiosTable.Raw
-                             );
-    ASSERT_EFI_ERROR (Status);
-
-    if (SmbiosTable.Hdr->Type == 0) {
-      NeedSmbiosType0 = FALSE;
+  //
+  // If the TableAddress is NULL, that's not an error. Just don't try to loop
+  // over it.
+  //
+  SmbiosTable.Raw = TableAddress;
+  if (SmbiosTable.Raw != NULL) {
+    while (SmbiosTable.Hdr->Type != 127) {
+      //
+      // Log the SMBIOS data for this structure
+      //
+      SmbiosHandle = SmbiosTable.Hdr->Handle;
+      Status       = Smbios->Add (
+                               Smbios,
+                               NULL,
+                               &SmbiosHandle,
+                               (EFI_SMBIOS_TABLE_HEADER *)SmbiosTable.Raw
+                               );
+      ASSERT_EFI_ERROR (Status);
+
+      if (SmbiosTable.Hdr->Type == 0) {
+        NeedSmbiosType0 = FALSE;
+      }
+
+      //
+      // Get the next structure address
+      //
+      SmbiosTable.Raw = (UINT8 *)(SmbiosTable.Raw + SmbiosTableLength (SmbiosTable));
     }
-
-    //
-    // Get the next structure address
-    //
-    SmbiosTable.Raw = (UINT8 *)(SmbiosTable.Raw + SmbiosTableLength (SmbiosTable));
   }
 
   if (NeedSmbiosType0) {
-- 
2.37.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#91993): https://edk2.groups.io/g/devel/message/91993
Mute This Topic: https://groups.io/mt/92721482/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-