[PATCH 36/43] OvmfPkg/SmbiosPlatformDxe: clean up #includes and INF #includes


Laszlo Ersek
 

- Sort all sections in the INF file.

- Remove unused packages (MdeModulePkg) and lib classes (BaseMemoryLib)
from the INF file.

- Restrict some lib classes (BaseLib, HobLib) and GUIDs (gEfiXenInfoGuid)
to IA32 and X64, in the INF file; only the IA32/X64 Xen implementation
requires these.

- Don't make "SmbiosPlatformDxe.h" #include everything just as a
convenience. Spell out directly needed #includes in every file (annotate
each with an example identifier consumed), drop unused #includes.

- Keep #includes sorted.

- Remove the leading underscore from the #include guard macro name in
"SmbiosPlatformDxe.h".

Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Julien Grall <julien@xen.org>
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>
---
OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf | 20 ++++++++++----------
OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.h | 15 +++------------
OvmfPkg/SmbiosPlatformDxe/Qemu.c | 8 +++++---
OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c | 6 ++++++
OvmfPkg/SmbiosPlatformDxe/X86Xen.c | 6 ++++--
5 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
index 8b56d90cf805..6063c0c9f609 100644
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
@@ -21,44 +21,44 @@ [Defines]
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64 EBC ARM AARCH64
#

[Sources]
- SmbiosPlatformDxe.h
- SmbiosPlatformDxe.c
Qemu.c
+ SmbiosPlatformDxe.c
+ SmbiosPlatformDxe.h

[Sources.IA32, Sources.X64]
X86Xen.c

[Sources.ARM, Sources.AARCH64]
ArmXen.c

[Packages]
MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
OvmfPkg/OvmfPkg.dec

[LibraryClasses]
- UefiBootServicesTableLib
- BaseMemoryLib
- BaseLib
- UefiDriverEntryPoint
DebugLib
- HobLib
- QemuFwCfgLib
MemoryAllocationLib
PcdLib
+ QemuFwCfgLib
+ UefiBootServicesTableLib
+ UefiDriverEntryPoint
+
+[LibraryClasses.IA32, LibraryClasses.X64]
+ BaseLib
+ HobLib

[Pcd]
gUefiOvmfPkgTokenSpaceGuid.PcdQemuSmbiosValidated

[Protocols]
gEfiSmbiosProtocolGuid # PROTOCOL ALWAYS_CONSUMED

-[Guids]
+[Guids.IA32, Guids.X64]
gEfiXenInfoGuid

[Depex]
gEfiSmbiosProtocolGuid

diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.h b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.h
index 21aa916d7784..ad42a326418c 100644
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.h
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.h
@@ -5,25 +5,16 @@
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent

**/

-#ifndef _SMBIOS_PLATFORM_DXE_H_
-#define _SMBIOS_PLATFORM_DXE_H_
-
-#include <PiDxe.h>
-
-#include <Protocol/Smbios.h>
-#include <IndustryStandard/SmBios.h>
-#include <Library/DebugLib.h>
-#include <Library/BaseLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/MemoryAllocationLib.h>
+#ifndef SMBIOS_PLATFORM_DXE_H_
+#define SMBIOS_PLATFORM_DXE_H_

+#include <IndustryStandard/SmBios.h> // SMBIOS_TABLE_ENTRY_POINT

/**
Locates the Xen SMBIOS data if it exists

@return SMBIOS_TABLE_ENTRY_POINT Address of Xen SMBIOS data

diff --git a/OvmfPkg/SmbiosPlatformDxe/Qemu.c b/OvmfPkg/SmbiosPlatformDxe/Qemu.c
index e34658238123..fcfc3e33c28c 100644
--- a/OvmfPkg/SmbiosPlatformDxe/Qemu.c
+++ b/OvmfPkg/SmbiosPlatformDxe/Qemu.c
@@ -3,16 +3,18 @@

Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>

SPDX-License-Identifier: BSD-2-Clause-Patent
**/

+#include <Library/DebugLib.h> // ASSERT_EFI_ERROR()
+#include <Library/MemoryAllocationLib.h> // AllocatePool()
+#include <Library/PcdLib.h> // PcdGetBool()
+#include <Library/QemuFwCfgLib.h> // QemuFwCfgFindFile()
+
#include "SmbiosPlatformDxe.h"
-#include <Library/QemuFwCfgLib.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/PcdLib.h>

/**
Locates and extracts the QEMU SMBIOS data if present in fw_cfg

@return Address of extracted QEMU SMBIOS data

diff --git a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
index 7991a19dc9c6..9bfc9f14f1a5 100644
--- a/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
+++ b/OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c
@@ -5,12 +5,18 @@
Copyright (c) 2011 - 2015, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent

**/

+#include <IndustryStandard/SmBios.h> // SMBIOS_TABLE_TYPE0
+#include <Library/DebugLib.h> // ASSERT_EFI_ERROR()
+#include <Library/MemoryAllocationLib.h> // FreePool()
+#include <Library/UefiBootServicesTableLib.h> // gBS
+#include <Protocol/Smbios.h> // EFI_SMBIOS_PROTOCOL
+
#include "SmbiosPlatformDxe.h"

#define TYPE0_STRINGS \
"EFI Development Kit II / OVMF\0" /* Vendor */ \
"0.0.0\0" /* BiosVersion */ \
"02/06/2015\0" /* BiosReleaseDate */
diff --git a/OvmfPkg/SmbiosPlatformDxe/X86Xen.c b/OvmfPkg/SmbiosPlatformDxe/X86Xen.c
index bead810efddb..e0b1b29f80db 100644
--- a/OvmfPkg/SmbiosPlatformDxe/X86Xen.c
+++ b/OvmfPkg/SmbiosPlatformDxe/X86Xen.c
@@ -5,15 +5,17 @@
Copyright (c) 2011, Intel Corporation. All rights reserved.<BR>

SPDX-License-Identifier: BSD-2-Clause-Patent

**/

+#include <Library/BaseLib.h> // AsciiStrnCmp()
+#include <Library/HobLib.h> // GetFirstGuidHob()
+#include <Pi/PiHob.h> // EFI_HOB_GUID_TYPE
+
#include "SmbiosPlatformDxe.h"
-#include <Library/HobLib.h>
-#include <Guid/XenInfo.h>

#define XEN_SMBIOS_PHYSICAL_ADDRESS 0x000EB000
#define XEN_SMBIOS_PHYSICAL_END 0x000F0000

/**
Validates the SMBIOS entry point structure
--
2.19.1.3.g30247aa5d201


Philippe Mathieu-Daudé
 

On 5/26/21 10:14 PM, Laszlo Ersek wrote:
- Sort all sections in the INF file.

- Remove unused packages (MdeModulePkg) and lib classes (BaseMemoryLib)
from the INF file.

- Restrict some lib classes (BaseLib, HobLib) and GUIDs (gEfiXenInfoGuid)
to IA32 and X64, in the INF file; only the IA32/X64 Xen implementation
requires these.

- Don't make "SmbiosPlatformDxe.h" #include everything just as a
convenience. Spell out directly needed #includes in every file (annotate
each with an example identifier consumed), drop unused #includes.

- Keep #includes sorted.

- Remove the leading underscore from the #include guard macro name in
"SmbiosPlatformDxe.h".

Cc: Anthony Perard <anthony.perard@citrix.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Jordan Justen <jordan.l.justen@intel.com>
Cc: Julien Grall <julien@xen.org>
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>
---
OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.inf | 20 ++++++++++----------
OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.h | 15 +++------------
OvmfPkg/SmbiosPlatformDxe/Qemu.c | 8 +++++---
OvmfPkg/SmbiosPlatformDxe/SmbiosPlatformDxe.c | 6 ++++++
OvmfPkg/SmbiosPlatformDxe/X86Xen.c | 6 ++++--
5 files changed, 28 insertions(+), 27 deletions(-)
Reviewed-by: Philippe Mathieu-Daude <philmd@redhat.com>