public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Pranav Madhu" <pranav.madhu@arm.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Sami Mujawar <sami.mujawar@arm.com>
Subject: [edk2-platforms][PATCH V3 03/11] Platform/Sgi: Add Initial SMBIOS support
Date: Tue, 18 May 2021 22:03:40 +0530	[thread overview]
Message-ID: <20210518163348.16618-4-pranav.madhu@arm.com> (raw)
In-Reply-To: <20210518163348.16618-1-pranav.madhu@arm.com>

SMBIOS provides basic hardware and firmware configuration information
through table-driven data structure. This patch adds SMBIOS driver
support that allows for installation of multiple SMBIOS types. Also add
SMBIOS Type0 (BIOS Information) table, that include information about
BIOS vendor name, version, SMBIOS version and other information related
to BIOS.

Signed-off-by: Pranav Madhu <pranav.madhu@arm.com>
Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
---
 Platform/ARM/SgiPkg/SgiPlatform.dsc.inc                              |  10 ++
 Platform/ARM/SgiPkg/SgiPlatform.fdf                                  |   8 +-
 Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf  |  46 +++++++
 Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.h    |  32 +++++
 Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c    |  98 ++++++++++++++
 Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/Type0BiosInformation.c | 135 ++++++++++++++++++++
 6 files changed, 328 insertions(+), 1 deletion(-)

diff --git a/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc b/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc
index 42e3600d15f4..a0f217f5107c 100644
--- a/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc
+++ b/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc
@@ -109,6 +109,10 @@
   # ACPI Table Version
   gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions|0x20
 
+  # SMBIOS entry point version
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosVersion|0x0304
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSmbiosDocRev|0x0
+
   #
   # PCIe
   #
@@ -247,6 +251,12 @@
   MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
   MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
 
+  #
+  # SMBIOS/DMI
+  #
+  MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
+  Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
+
   #
   # platform driver
   #
diff --git a/Platform/ARM/SgiPkg/SgiPlatform.fdf b/Platform/ARM/SgiPkg/SgiPlatform.fdf
index da23804828e5..e11d943d6efc 100644
--- a/Platform/ARM/SgiPkg/SgiPlatform.fdf
+++ b/Platform/ARM/SgiPkg/SgiPlatform.fdf
@@ -1,5 +1,5 @@
 #
-#  Copyright (c) 2018, ARM Limited. All rights reserved.
+#  Copyright (c) 2018-2021, ARM Limited. All rights reserved.
 #
 #  SPDX-License-Identifier: BSD-2-Clause-Patent
 #
@@ -102,6 +102,12 @@ READ_LOCK_STATUS   = TRUE
   INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
 !include $(BOARD_DXE_FV_COMPONENTS)
 
+  #
+  # SMBIOS/DMI
+  #
+  INF MdeModulePkg/Universal/SmbiosDxe/SmbiosDxe.inf
+  INF Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
+
   # Required by PCI
   INF ArmPkg/Drivers/ArmPciCpuIo2Dxe/ArmPciCpuIo2Dxe.inf
 
diff --git a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
new file mode 100644
index 000000000000..3568380f8404
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.inf
@@ -0,0 +1,46 @@
+## @file
+#  This driver installs SMBIOS information for RD Platforms
+#
+#  Copyright (c) 2021, ARM Limited. All rights reserved.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001A
+  BASE_NAME                      = SmbiosPlatformDxe
+  FILE_GUID                      = 86e0aa8b-4f8d-44a5-a140-1f693d529c76
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = SmbiosTableEntryPoint
+
+[Sources]
+  SmbiosPlatformDxe.c
+  Type0BiosInformation.c
+
+[Packages]
+  ArmPkg/ArmPkg.dec
+  ArmPlatformPkg/ArmPlatformPkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  Platform/ARM/SgiPkg/SgiPlatform.dec
+
+[LibraryClasses]
+  ArmPlatformLib
+  DebugLib
+  HobLib
+  UefiDriverEntryPoint
+
+[Guids]
+  gEfiGlobalVariableGuid
+  gArmSgiPlatformIdDescriptorGuid
+
+[FixedPcd]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareRevision
+
+[Protocols]
+  gEfiSmbiosProtocolGuid                      # PROTOCOL ALWAYS_CONSUMED
+
+[Guids]
+
+[Depex]
+  gEfiSmbiosProtocolGuid
diff --git a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.h b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.h
new file mode 100644
index 000000000000..a09f89ebe5bc
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.h
@@ -0,0 +1,32 @@
+/** @file
+  Declarations required for SMBIOS DXE driver.
+
+  Functions declarations and data type declarations required for SMBIOS DXE
+  driver of the Arm Reference Design platforms.
+
+  Copyright (c) 2021, ARM Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef SMBIOS_PLATFORM_DXE_H_
+#define SMBIOS_PLATFORM_DXE_H_
+
+/**
+  Install SMBIOS BIOS information Table.
+
+  Install the SMBIOS BIOS information (type 0) table for Arm's reference design
+  platforms.
+
+  @param[in] Smbios   SMBIOS protocol.
+
+  @retval EFI_SUCCESS           Record was added.
+  @retval EFI_OUT_OF_RESOURCES  Record was not added.
+  @retval EFI_ALREADY_STARTED   The SmbiosHandle passed is already in use.
+**/
+EFI_STATUS
+EFIAPI
+InstallType0BiosInformation (
+  IN     EFI_SMBIOS_PROTOCOL    *Smbios
+  );
+
+#endif // SMBIOS_PLATFORM_DXE_H_
diff --git a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c
new file mode 100644
index 000000000000..20d4dedccb82
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/SmbiosPlatformDxe.c
@@ -0,0 +1,98 @@
+/** @file
+  Install SMBIOS tables for Arm's SGI/RD platforms.
+
+  This file is the driver entry point for installing SMBIOS tables on Arm's
+  Reference Design platforms. For each SMBIOS table installation handler
+  registered, the driver invokes the handler to register the respective table.
+
+  Copyright (c) 2021, ARM Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Specification Reference:
+    - SMBIOS Reference Specification 3.4.0
+**/
+
+#include <IndustryStandard/SmBios.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <PiDxe.h>
+#include <Protocol/Smbios.h>
+
+#include "SgiPlatform.h"
+#include "SmbiosPlatformDxe.h"
+
+typedef EFI_STATUS (*ARM_RD_SMBIOS_TABLE_INSTALL_FPTR)(EFI_SMBIOS_PROTOCOL *);
+
+STATIC CONST
+ARM_RD_SMBIOS_TABLE_INSTALL_FPTR mSmbiosTableList[] = {
+  &InstallType0BiosInformation,
+};
+
+/**
+  Driver entry point. Installs SMBIOS information.
+
+  For all the available SMBIOS table installation handlers, invoke each of
+  those handlers and let the handlers install the SMBIOS tables. The count
+  of handlers that fail to install the SMBIOS tables is maintained for
+  additional logging.
+
+  @param ImageHandle     Module's image handle.
+  @param SystemTable     Pointer of EFI_SYSTEM_TABLE.
+
+  @retval EFI_SUCCESS    All SMBIOS table install handlers invoked.
+  @retval EFI_NOT_FOUND  Unsupported platform.
+  @retval Others         Failed to invoke SMBIOS table install handlders.
+**/
+EFI_STATUS
+EFIAPI
+SmbiosTableEntryPoint (
+  IN     EFI_HANDLE             ImageHandle,
+  IN     EFI_SYSTEM_TABLE       *SystemTable
+  )
+{
+  EFI_STATUS Status;
+  EFI_SMBIOS_PROTOCOL *Smbios = NULL;
+  UINT8 CountFail = 0;
+  UINT8 Idx;
+
+  /* Install SMBIOS table only for supported product */
+  if (SgiGetProductId () == UnknownId) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "Failed to install SMBIOS: Unknown product\n"
+      ));
+    return EFI_NOT_FOUND;
+  }
+
+  /* Find the SMBIOS protocol */
+  Status = gBS->LocateProtocol (
+                  &gEfiSmbiosProtocolGuid,
+                  NULL,
+                  (VOID **)&Smbios
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "Failed to install SMBIOS: Unable to locate protocol\n"
+      ));
+    return Status;
+  }
+
+  /* Install the tables listed in mSmbiosTableList */
+  for (Idx = 0; Idx < ARRAY_SIZE (mSmbiosTableList); Idx++) {
+    Status = (*mSmbiosTableList[Idx]) (Smbios);
+    if (EFI_ERROR (Status)) {
+      CountFail++;
+    }
+  }
+
+  DEBUG ((
+    DEBUG_INFO,
+    "Installed %d of %d available SMBIOS tables\n",
+    ARRAY_SIZE (mSmbiosTableList) - CountFail,
+    ARRAY_SIZE (mSmbiosTableList)
+    ));
+
+  return EFI_SUCCESS;
+}
diff --git a/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/Type0BiosInformation.c b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/Type0BiosInformation.c
new file mode 100644
index 000000000000..f5c1b2366d04
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Drivers/SmbiosPlatformDxe/Type0BiosInformation.c
@@ -0,0 +1,135 @@
+/** @file
+  SMBIOS Type 0 (BIOS information) table for ARM RD platforms.
+
+  Install SMBIOS Type 0 (BIOS information) table for Arm's Reference Design
+  platforms.
+
+  Copyright (c) 2021, ARM Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Specification Reference:
+    - SMBIOS Reference Specification 3.4.0, Chapter 7.1
+**/
+
+#include <Library/DebugLib.h>
+#include <Protocol/Smbios.h>
+
+#define TYPE0_STRINGS                                   \
+  "ARM LTD\0"                   /* Vendor */            \
+  "EDK II\0"                    /* BiosVersion */       \
+  __DATE__"\0"                  /* BiosReleaseDate */   \
+  "\0"
+
+typedef enum {
+  VendorName = 1,
+  BiosVersion,
+  BiosReleaseDate
+} TYPE0_STRING_ELEMENTS;
+
+/* SMBIOS Type0 structure */
+#pragma pack(1)
+typedef struct {
+  SMBIOS_TABLE_TYPE0  Base;
+  CHAR8               Strings[sizeof (TYPE0_STRINGS)];
+} ARM_RD_SMBIOS_TYPE0;
+#pragma pack()
+
+/* BIOS information */
+STATIC ARM_RD_SMBIOS_TYPE0 mArmRdSmbiosType0 = {
+  {
+    {
+      // SMBIOS header
+      EFI_SMBIOS_TYPE_BIOS_INFORMATION, // Type 0
+      sizeof (SMBIOS_TABLE_TYPE0),      // Length
+      SMBIOS_HANDLE_PI_RESERVED,        // Assign an unused handle number
+    },
+    VendorName,       // String number of vendor name in TYPE0_STRINGS
+    BiosVersion,      // String number of BiosVersion
+    0,                // Bios starting address segment
+    BiosReleaseDate,  // String number of BiosReleaseDate
+    0xFF,             // Bios ROM size
+    {                 // MISC_BIOS_CHARACTERISTICS
+      0,              // Reserved
+      0,              // Unknown
+      0,              // BIOS Characteristics are not supported
+      0,              // ISA not supported
+      0,              // MCA not supported
+      0,              // EISA not supported
+      1,              // PCI supported
+      0,              // PC card (PCMCIA) not supported
+      1,              // Plug and Play is supported
+      0,              // APM not supported
+      1,              // BIOS upgradable
+      0,              // BIOS shadowing is not allowed
+      0,              // VL-VESA not supported
+      0,              // ESCD support is not available
+      0,              // Boot from CD not supported
+      1,              // selectable boot
+    },
+    {                 // BIOSCharacteristicsExtensionBytes
+      (
+        (1 << 0) |    // ACPI Supported
+        (1 << 1)      // Legacy USB supported
+      ),
+      (
+        (1 << 3) |    // Content distribution enabled
+        (1 << 4)      // UEFI spec supported
+      )
+    },
+    0,                // SMBIOS Major Release, updated dynamically
+    0,                // SMBIOS Minor Release, updated dynamically
+    0xFF,             // Embedded Controller Firmware Major Release
+    0xFF,             // Embedded Controller Firmware Minor Release
+    {                 // EXTENDED_BIOS_ROM_SIZE
+      64,             // Size
+      0               // Unit MB
+    }
+  },
+  // Text strings (unformatted area)
+  TYPE0_STRINGS
+};
+
+/**
+  Install SMBIOS BIOS information Table.
+
+  Install the SMBIOS BIOS information (type 0) table for Arm's reference design
+  platforms.
+
+  @param[in] Smbios   SMBIOS protocol.
+
+  @retval EFI_SUCCESS           Record was added.
+  @retval EFI_OUT_OF_RESOURCES  Record was not added.
+  @retval EFI_ALREADY_STARTED   The SmbiosHandle passed is already in use.
+**/
+EFI_STATUS
+InstallType0BiosInformation (
+  IN     EFI_SMBIOS_PROTOCOL    *Smbios
+  )
+{
+  EFI_STATUS Status;
+  EFI_SMBIOS_HANDLE SmbiosHandle;
+
+  SmbiosHandle = ((EFI_SMBIOS_TABLE_HEADER *)&mArmRdSmbiosType0)->Handle;
+
+  /* Update firmware revision */
+  mArmRdSmbiosType0.Base.SystemBiosMajorRelease =
+    (PcdGet32 (PcdFirmwareRevision) >> 16) & 0xFF;
+  mArmRdSmbiosType0.Base.SystemBiosMinorRelease =
+    PcdGet32 (PcdFirmwareRevision) & 0xFF;
+
+  /* Install type 0 table */
+  Status = Smbios->Add (
+                     Smbios,
+                     NULL,
+                     &SmbiosHandle,
+                     (EFI_SMBIOS_TABLE_HEADER *)&mArmRdSmbiosType0
+                     );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "SMBIOS: Failed to install Type0 SMBIOS table.\n"
+      ));
+  }
+
+  return Status;
+}
-- 
2.17.1


  parent reply	other threads:[~2021-05-18 16:34 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-05-18 16:33 [edk2-platforms][PATCH V3 00/11] Add SMBIOS tables for Arm's Reference Design platforms Pranav Madhu
2021-05-18 16:33 ` [edk2-platforms][PATCH V3 01/11] Platform/Sgi: Define RD-N2 platform id values Pranav Madhu
2021-05-18 16:33 ` [edk2-platforms][PATCH V3 02/11] Platform/Sgi: Add GetProductId API for SGI/RD Platforms Pranav Madhu
2021-05-18 16:33 ` Pranav Madhu [this message]
2021-05-18 16:33 ` [edk2-platforms][PATCH V3 04/11] Platform/Sgi: Add SMBIOS Type1 Table Pranav Madhu
2021-05-18 16:33 ` [edk2-platforms][PATCH V3 05/11] Platform/Sgi: Add SMBIOS Type3 Table Pranav Madhu
2021-05-18 16:33 ` [edk2-platforms][PATCH V3 06/11] Platform/Sgi: Add SMBIOS Type4 Table Pranav Madhu
2021-05-18 16:33 ` [edk2-platforms][PATCH V3 07/11] Platform/Sgi: Add SMBIOS Type7 Table Pranav Madhu
2021-05-18 16:33 ` [edk2-platforms][PATCH V3 08/11] Platform/Sgi: Add SMBIOS Type16 Table Pranav Madhu
2021-05-18 16:33 ` [edk2-platforms][PATCH V3 09/11] Platform/Sgi: Add SMBIOS Type17 Table Pranav Madhu
2021-05-18 16:33 ` [edk2-platforms][PATCH V3 10/11] Platform/Sgi: Add SMBIOS Type19 Table Pranav Madhu
2021-05-18 16:33 ` [edk2-platforms][PATCH V3 11/11] Platform/Sgi: Add SMBIOS Type32 Table Pranav Madhu
2021-05-19 11:30 ` [edk2-devel] [edk2-platforms][PATCH V3 00/11] Add SMBIOS tables for Arm's Reference Design platforms Thomas Abraham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210518163348.16618-4-pranav.madhu@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox