[edk2-devel] [edk2-platforms][PATCH v3 5/5] Platform/Sgi: Add platform error handling driver

Omkar Anand Kulkarni omkar.kulkarni at arm.com
Tue Aug 24 06:00:27 UTC 2021


Enables firmware first error handling on the given platform. Installs
and publishes the SDEI and HEST ACPI tables required for firmware first
error handling.

Signed-off-by: Omkar Anand Kulkarni <omkar.kulkarni at arm.com>
---
 Platform/ARM/SgiPkg/SgiPlatform.dsc.inc                                         |  10 ++
 Platform/ARM/SgiPkg/SgiPlatform.fdf                                             |   7 +
 Platform/ARM/SgiPkg/Drivers/PlatformErrorHandlerDxe/PlatformErrorHandlerDxe.inf |  51 ++++++
 Platform/ARM/SgiPkg/Drivers/PlatformErrorHandlerDxe/PlatformErrorHandlerDxe.c   | 171 ++++++++++++++++++++
 4 files changed, 239 insertions(+)

diff --git a/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc b/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc
index 102d7926bde1..20f003b96cdb 100644
--- a/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc
+++ b/Platform/ARM/SgiPkg/SgiPlatform.dsc.inc
@@ -24,6 +24,9 @@
   # To allow firmware first error handling, set this to TRUE.
   DEFINE ENABLE_GHES_MM                     = FALSE
 
+  # To allow firmware first error handling, set this to TRUE.
+  DEFINE ENABLE_FIRWARE_FIRST               = FALSE
+
 [BuildOptions]
   *_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES
 
@@ -326,6 +329,13 @@
   #
   Platform/ARM/SgiPkg/Drivers/PlatformDxe/PlatformDxe.inf
 
+  #
+  # platform error handler driver
+  #
+!if $(ENABLE_FIRMWARE_FIRST) == TRUE
+  Platform/ARM/SgiPkg/Drivers/PlatformErrorHandlerDxe/PlatformErrorHandlerDxe.inf
+!endif
+
   #
   # FAT filesystem + GPT/MBR partitioning
   #
diff --git a/Platform/ARM/SgiPkg/SgiPlatform.fdf b/Platform/ARM/SgiPkg/SgiPlatform.fdf
index d6e942e19b81..b1d088610c4c 100644
--- a/Platform/ARM/SgiPkg/SgiPlatform.fdf
+++ b/Platform/ARM/SgiPkg/SgiPlatform.fdf
@@ -190,6 +190,13 @@ READ_LOCK_STATUS   = TRUE
   #
   INF Platform/ARM/SgiPkg/Drivers/PlatformDxe/PlatformDxe.inf
 
+  #
+  # platform error handler driver
+  #
+!if $(ENABLE_FIRMWARE_FIRST) == TRUE
+  INF Platform/ARM/SgiPkg/Drivers/PlatformErrorHandlerDxe/PlatformErrorHandlerDxe.inf
+!endif
+
   #
   # Bds
   #
diff --git a/Platform/ARM/SgiPkg/Drivers/PlatformErrorHandlerDxe/PlatformErrorHandlerDxe.inf b/Platform/ARM/SgiPkg/Drivers/PlatformErrorHandlerDxe/PlatformErrorHandlerDxe.inf
new file mode 100644
index 000000000000..fe9ed4175b0b
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Drivers/PlatformErrorHandlerDxe/PlatformErrorHandlerDxe.inf
@@ -0,0 +1,51 @@
+## @file
+#  Dxe driver to handle platform errors.
+#
+#  This driver installs SDEI and HEST ACPI tables required for firmware first
+#  error handling.
+#
+#  Copyright (c) 2020 - 2021, ARM Limited. All rights reserved.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001A
+  BASE_NAME                      = PlatformErrorHandlerDxe
+  FILE_GUID                      = a3187ea4-feb4-415f-b11e-2312623ffa6f
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  ENTRY_POINT                    = PlatformErrorHandlerEntryPoint
+
+[Sources.common]
+  PlatformErrorHandlerDxe.c
+
+[Packages]
+  ArmPlatformPkg/ArmPlatformPkg.dec
+  EmbeddedPkg/EmbeddedPkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+  MdePkg/MdePkg.dec
+  Platform/ARM/SgiPkg/SgiPlatform.dec
+
+[LibraryClasses]
+  AcpiLib
+  BaseLib
+  DebugLib
+  UefiDriverEntryPoint
+
+[Guids]
+  gArmSgiAcpiTablesGuid
+
+[Protocols]
+  gEfiAcpiTableProtocolGuid         ## PROTOCOL ALWAYS_CONSUMED
+  gHestTableProtocolGuid            ## PROTOCOL ALWAYS_CONSUMED
+
+[FixedPcd]
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemId
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision
+  gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId
+
+[Depex]
+  AFTER gArmPlatformHestErrorSourcesGuid
diff --git a/Platform/ARM/SgiPkg/Drivers/PlatformErrorHandlerDxe/PlatformErrorHandlerDxe.c b/Platform/ARM/SgiPkg/Drivers/PlatformErrorHandlerDxe/PlatformErrorHandlerDxe.c
new file mode 100644
index 000000000000..25b29152f1bb
--- /dev/null
+++ b/Platform/ARM/SgiPkg/Drivers/PlatformErrorHandlerDxe/PlatformErrorHandlerDxe.c
@@ -0,0 +1,171 @@
+/** @file
+  Driver to handle and support all platform errors.
+
+  Installs the SDEI and HEST ACPI tables for firmware first error handling.
+
+  Copyright (c) 2020 - 2021, ARM Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Specification Reference:
+    - ACPI 6.3, Table 18-382, Hardware Error Source Table
+    - SDEI Platform Design Document, revision b, 10 Appendix C, ACPI table
+      definitions for SDEI
+**/
+
+#include <IndustryStandard/Acpi.h>
+
+#include <Library/AcpiLib.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+
+#include <Protocol/AcpiTable.h>
+#include <Protocol/HestTable.h>
+
+
+/**
+  Build and install the SDEI ACPI table.
+
+  For platforms that allow firmware-first platform error handling, SDEI is used
+  as the notification mechanism for those errors.
+
+  @retval EFI_SUCCESS  SDEI table installed successfully.
+  @retval Other        For any error during installation.
+**/
+STATIC
+EFI_STATUS
+InstallSdeiTable (VOID)
+{
+  EFI_ACPI_TABLE_PROTOCOL     *mAcpiTableProtocol = NULL;
+  EFI_ACPI_DESCRIPTION_HEADER Header;
+  EFI_STATUS                  Status;
+  UINTN                       AcpiTableHandle;
+
+  Header =
+    (EFI_ACPI_DESCRIPTION_HEADER) {
+     EFI_ACPI_6_3_SOFTWARE_DELEGATED_EXCEPTIONS_INTERFACE_TABLE_SIGNATURE,
+     sizeof (EFI_ACPI_DESCRIPTION_HEADER), // Length
+     0x01,                                 // Revision
+     0x00,                                 // Checksum
+     {'A', 'R', 'M', 'L', 'T', 'D'},       // OemId
+     0x4152464e49464552,                   // OemTableId:"REFINFRA"
+     0x20201027,                           // OemRevision
+     0x204d5241,                           // CreatorId:"ARM "
+     0x00000001,                           // CreatorRevision
+    };
+
+  Header.Checksum = CalculateCheckSum8 ((UINT8 *)&Header, Header.Length);
+  Status = gBS->LocateProtocol (
+                  &gEfiAcpiTableProtocolGuid,
+                  NULL,
+                  (VOID **)&mAcpiTableProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to locate ACPI table protocol, status: %r\n",
+      __FUNCTION__,
+      Status
+      ));
+    return Status;
+  }
+
+  Status = mAcpiTableProtocol->InstallAcpiTable (
+                                 mAcpiTableProtocol,
+                                 &Header,
+                                 Header.Length,
+                                 &AcpiTableHandle
+                                 );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to install SDEI ACPI table, status: %r\n",
+      __FUNCTION__,
+      Status
+      ));
+  }
+
+  return Status;
+}
+
+/**
+  Install the HEST ACPI table.
+
+  HEST ACPI table is used to list the platform errors for which the error
+  handling has been supported. Use the HEST table generation protocol to
+  install the HEST table.
+
+  @retval EFI_SUCCESS  HEST table installed successfully.
+  @retval Other        For any error during installation.
+**/
+STATIC
+EFI_STATUS
+InstallHestTable (VOID)
+{
+  HEST_TABLE_PROTOCOL *HestProtocol;
+  EFI_STATUS          Status;
+
+  Status = gBS->LocateProtocol (
+                  &gHestTableProtocolGuid,
+                  NULL,
+                  (VOID **)&HestProtocol
+                  );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to locate HEST DXE Protocol, status: %r\n",
+      __FUNCTION__,
+      Status
+      ));
+      return Status;
+  }
+
+  Status = HestProtocol->InstallHestTable ();
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "%a: Failed to install HEST table, status: %r\n",
+      __FUNCTION__,
+      Status
+      ));
+  }
+
+  return Status;
+}
+
+/**
+  Entry point for the DXE driver.
+
+  This function installs the HEST ACPI table, using the HEST table generation
+  protocol. Also creates and installs the SDEI ACPI table required for firmware
+  first error handling.
+
+  @param[in]  ImageHandle  Handle to the EFI image.
+  @param[in]  SystemTable  A pointer to the EFI System Table.
+
+  @retval  EFI_SUCCESS  On successful installation of ACPI tables
+  @retval  Other        On Failure
+**/
+EFI_STATUS
+EFIAPI
+PlatformErrorHandlerEntryPoint (
+  IN EFI_HANDLE       ImageHandle,
+  IN EFI_SYSTEM_TABLE *SystemTable
+  )
+{
+  EFI_STATUS Status;
+
+  // Build and install SDEI table.
+  Status = InstallSdeiTable ();
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  // Install the created HEST table.
+  Status = InstallHestTable ();
+  if (EFI_ERROR (Status)) {
+    return Status;
+  }
+
+  return EFI_SUCCESS;
+}
-- 
2.17.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#79754): https://edk2.groups.io/g/devel/message/79754
Mute This Topic: https://groups.io/mt/85104852/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-






More information about the edk2-devel-archive mailing list