public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Omkar Anand Kulkarni" <omkar.kulkarni@arm.com>
To: devel@edk2.groups.io
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Sami Mujawar <sami.mujawar@arm.com>
Subject: [edk2-platforms][PATCH v2 5/5] Platform/Sgi: Add platform error handling driver
Date: Sat, 10 Jul 2021 21:54:30 +0530	[thread overview]
Message-ID: <20210710162430.31691-6-omkar.kulkarni@arm.com> (raw)
In-Reply-To: <20210710162430.31691-1-omkar.kulkarni@arm.com>

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@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 87803c4e5785..f9bae632b1f6 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 a7100743bbc4..ecc99edf115b 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


      parent reply	other threads:[~2021-07-10 16:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-10 16:24 [edk2-platforms][PATCH v2 0/5] Platform/Sgi: Add platform support for firmware first error handling Omkar Anand Kulkarni
2021-07-10 16:24 ` [edk2-platforms][PATCH v2 1/5] Platform/ARM: Add DMC-620 ECC error handling driver Omkar Anand Kulkarni
2021-07-10 16:24 ` [edk2-platforms][PATCH v2 2/5] Platform/Sgi: dmc-620 firmware-first error handling Omkar Anand Kulkarni
2021-07-10 16:24 ` [edk2-platforms][PATCH v2 3/5] Platform/Sgi: define memory region for GHES error status block Omkar Anand Kulkarni
2021-07-10 16:24 ` [edk2-platforms][PATCH v2 4/5] Platform/Sgi: Define values for ACPI table header Omkar Anand Kulkarni
2021-07-10 16:24 ` Omkar Anand Kulkarni [this message]

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=20210710162430.31691-6-omkar.kulkarni@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