OvmfPkg/SmbiosPlatformDxe: locate SMBIOS protocol in InstallAllStructures()

Locate the SMBIOS protocol internally to the InstallAllStructures()
function. This has no performance impact (InstallAllStructures() is only
called once), but moving the code from the entry point function makes the
latter smaller. And that will be useful when we split the entry point
function to two versions.

Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=2122
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20210526201446.12554-39-lersek@redhat.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
index 6d73173..757bec8 100644
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
@@ -95,21 +95,32 @@
 /**

   Install all structures from the given SMBIOS structures block

 

-  @param  Smbios               SMBIOS protocol

   @param  TableAddress         SMBIOS tables starting address

 

 **/

 EFI_STATUS

 InstallAllStructures (

-  IN EFI_SMBIOS_PROTOCOL       *Smbios,

   IN UINT8                     *TableAddress

   )

 {

+  EFI_SMBIOS_PROTOCOL       *Smbios;

   EFI_STATUS                Status;

   SMBIOS_STRUCTURE_POINTER  SmbiosTable;

   EFI_SMBIOS_HANDLE         SmbiosHandle;

   BOOLEAN                   NeedSmbiosType0;

 

+  //

+  // Find the SMBIOS protocol

+  //

+  Status = gBS->LocateProtocol (

+                  &gEfiSmbiosProtocolGuid,

+                  NULL,

+                  (VOID**)&Smbios

+                  );

+  if (EFI_ERROR (Status)) {

+    return Status;

+  }

+

   SmbiosTable.Raw = TableAddress;

   if (SmbiosTable.Raw == NULL) {

     return EFI_INVALID_PARAMETER;

@@ -176,22 +187,9 @@
   )

 {

   EFI_STATUS                Status;

-  EFI_SMBIOS_PROTOCOL       *Smbios;

   SMBIOS_TABLE_ENTRY_POINT  *EntryPointStructure;

   UINT8                     *SmbiosTables;

 

-  //

-  // Find the SMBIOS protocol

-  //

-  Status = gBS->LocateProtocol (

-                  &gEfiSmbiosProtocolGuid,

-                  NULL,

-                  (VOID**)&Smbios

-                  );

-  if (EFI_ERROR (Status)) {

-    return Status;

-  }

-

   Status = EFI_NOT_FOUND;

   //

   // Add Xen or QEMU SMBIOS data if found

@@ -204,7 +202,7 @@
   }

 

   if (SmbiosTables != NULL) {

-    Status = InstallAllStructures (Smbios, SmbiosTables);

+    Status = InstallAllStructures (SmbiosTables);

 

     //

     // Free SmbiosTables if allocated by Qemu (i.e., NOT by Xen):