public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Jeff Brasen" <jbrasen@nvidia.com>
To: <devel@edk2.groups.io>
Cc: <Pierre.Gondois@arm.com>, <Sami.Mujawar@arm.com>,
	<Alexei.Fedorov@arm.com>, Jeff Brasen <jbrasen@nvidia.com>
Subject: [PATCH 4/4] DynamicTablesPkg: AcpiSsdtPcieLibArm: Add support for override protocol
Date: Thu, 30 Jun 2022 09:48:51 -0600	[thread overview]
Message-ID: <45abcaa79586b025205269d17957537d613c9bc2.1656603839.git.jbrasen@nvidia.com> (raw)
In-Reply-To: <cover.1656603839.git.jbrasen@nvidia.com>

Some platfoms may want to modify the ACPI table created.
Add support for protocol that can provide an alternative implementation.

Signed-off-by: Jeff Brasen <jbrasen@nvidia.com>
---
 DynamicTablesPkg/DynamicTablesPkg.dec         |  3 +
 .../Protocol/SsdtPcieOverrideProtocol.h       | 63 +++++++++++++++++++
 .../AcpiSsdtPcieLibArm/SsdtPcieGenerator.c    | 31 ++++++++-
 .../Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.inf |  4 ++
 4 files changed, 98 insertions(+), 3 deletions(-)
 create mode 100644 DynamicTablesPkg/Include/Protocol/SsdtPcieOverrideProtocol.h

diff --git a/DynamicTablesPkg/DynamicTablesPkg.dec b/DynamicTablesPkg/DynamicTablesPkg.dec
index a890a048be..bb66bdaf14 100644
--- a/DynamicTablesPkg/DynamicTablesPkg.dec
+++ b/DynamicTablesPkg/DynamicTablesPkg.dec
@@ -43,6 +43,9 @@
   # Dynamic Table Factory Protocol GUID
   gEdkiiDynamicTableFactoryProtocolGuid = { 0x91d1e327, 0xfe5a, 0x49b8, { 0xab, 0x65, 0xe, 0xce, 0x2d, 0xdb, 0x45, 0xec } }
 
+  # Protocol to override PCI SSDT table generation
+  gEdkiiDynamicTableSsdtPcieOverrideProtocolGuid = { 0x962e8b44, 0x23b3, 0x41da, { 0x9f, 0x36, 0xca, 0xde, 0x68, 0x49, 0xfb, 0xf6 } }
+
 [PcdsFixedAtBuild]
 
   # Maximum number of Custom ACPI Generators
diff --git a/DynamicTablesPkg/Include/Protocol/SsdtPcieOverrideProtocol.h b/DynamicTablesPkg/Include/Protocol/SsdtPcieOverrideProtocol.h
new file mode 100644
index 0000000000..29568a0159
--- /dev/null
+++ b/DynamicTablesPkg/Include/Protocol/SsdtPcieOverrideProtocol.h
@@ -0,0 +1,63 @@
+/** @file
+
+  Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef SSDT_PCIE_OVERRIDE_PROTOCOL_H_
+#define SSDT_PCIE_OVERRIDE_PROTOCOL_H_
+
+#include <ArmNameSpaceObjects.h>
+#include <Library/AmlLib/AmlLib.h>
+
+/** This macro defines the SSDT PCI Override Protocol GUID.
+
+  GUID: {D85A4835-5A82-4894-AC02-706F43D5978E}
+*/
+#define EDKII_SSDT_PCI_OVERRIDE_PROTOCOL_GUID           \
+  { 0x962e8b44, 0x23b3, 0x41da,                         \
+    { 0x9f, 0x36, 0xca, 0xde, 0x68, 0x49, 0xfb, 0xf6 }  \
+  };
+
+/**
+  Forward declarations:
+*/
+typedef struct SsdtOverridePciProtocol EDKII_SSDT_PCI_OVERRIDE_PROTOCOL;
+
+/** The UpdateTable function allows the override protocol to update the
+ *   PCIe SSDT table prior to being created.
+
+  @param [in]      This    Pointer to the SSDT PCI Override Protocol.
+  @param [in]      PciInfo The PCIe configuration info for this node.
+  @param [in]      Uid     UID that was selected for this PCIe node.
+  @param [in, out] PciNode Pointer to the PCI node of this ACPI table.
+
+  @retval EFI_SUCCESS           Success.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_DEVICE_ERROR      Failed to update the table.
+**/
+typedef
+EFI_STATUS
+(EFIAPI *EDKII_SSDT_PCI_OVERRIDE_PROTOCOL_UPDATE_TABLE)(
+  IN      CONST EDKII_SSDT_PCI_OVERRIDE_PROTOCOL  *CONST  This,
+  IN      CONST CM_ARM_PCI_CONFIG_SPACE_INFO              *PciInfo,
+  IN            UINT32                                    Uid,
+  IN  OUT       AML_ROOT_NODE_HANDLE                      *PciNode
+  );
+
+/** The EDKII_CONFIGURATION_MANAGER_PROTOCOL structure describes the
+    Configuration Manager Protocol interface.
+*/
+typedef struct SsdtOverridePciProtocol {
+  /** The interface used to update the ACPI table for PCI.
+  */
+  EDKII_SSDT_PCI_OVERRIDE_PROTOCOL_UPDATE_TABLE    UpdateTable;
+} EDKII_SSDT_PCI_OVERRIDE_PROTOCOL;
+
+/** The SSDT PCI Override Protocol GUID.
+*/
+extern EFI_GUID  gEdkiiDynamicTableSsdtPcieOverrideProtocolGuid;
+
+#endif // SSDT_PCIE_OVERRIDE_PROTOCOL_H_
diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerator.c b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerator.c
index c5b23d91d0..d5982c24ff 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieGenerator.c
@@ -20,6 +20,7 @@
 #include <Library/BaseMemoryLib.h>
 #include <Library/DebugLib.h>
 #include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
 #include <Protocol/AcpiTable.h>
 
 // Module specific include files.
@@ -30,6 +31,7 @@
 #include <Library/TableHelperLib.h>
 #include <Library/AmlLib/AmlLib.h>
 #include <Protocol/ConfigurationManagerProtocol.h>
+#include <Protocol/SsdtPcieOverrideProtocol.h>
 
 #include "SsdtPcieGenerator.h"
 
@@ -798,9 +800,10 @@ GeneratePciDevice (
 {
   EFI_STATUS  Status;
 
-  CHAR8                   AslName[AML_NAME_SEG_SIZE + 1];
-  AML_OBJECT_NODE_HANDLE  ScopeNode;
-  AML_OBJECT_NODE_HANDLE  PciNode;
+  CHAR8                             AslName[AML_NAME_SEG_SIZE + 1];
+  AML_OBJECT_NODE_HANDLE            ScopeNode;
+  AML_OBJECT_NODE_HANDLE            PciNode;
+  EDKII_SSDT_PCI_OVERRIDE_PROTOCOL  *OverrideProtocol;
 
   ASSERT (Generator != NULL);
   ASSERT (CfgMgrProtocol != NULL);
@@ -860,6 +863,28 @@ GeneratePciDevice (
 
   // Add the template _OSC method.
   Status = AddOscMethod (PciNode);
+  if (EFI_ERROR (Status)) {
+    ASSERT (0);
+    return Status;
+  }
+
+  Status = gBS->LocateProtocol (
+                  &gEdkiiDynamicTableSsdtPcieOverrideProtocolGuid,
+                  NULL,
+                  (VOID **)&OverrideProtocol
+                  );
+  if (!EFI_ERROR (Status)) {
+    Status = OverrideProtocol->UpdateTable (
+                                 OverrideProtocol,
+                                 PciInfo,
+                                 Uid,
+                                 PciNode
+                                 );
+  } else {
+    // Not an error if override protocol is not found
+    Status = EFI_SUCCESS;
+  }
+
   ASSERT_EFI_ERROR (Status);
   return Status;
 }
diff --git a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.inf b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.inf
index 431e32a777..8e916f15e9 100644
--- a/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.inf
+++ b/DynamicTablesPkg/Library/Acpi/Arm/AcpiSsdtPcieLibArm/SsdtPcieLibArm.inf
@@ -30,6 +30,10 @@
   AcpiHelperLib
   AmlLib
   BaseLib
+  UefiBootServicesTableLib
 
 [Pcd]
   gEdkiiDynamicTablesPkgTokenSpaceGuid.PcdPciUseSegmentAsUid
+
+[Protocols]
+  gEdkiiDynamicTableSsdtPcieOverrideProtocolGuid
-- 
2.25.1


  parent reply	other threads:[~2022-06-30 15:49 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-30 15:48 [PATCH 0/4] DynamicTablesPkg: Pcie generation updates Jeff Brasen
2022-06-30 15:48 ` [PATCH 1/4] DynamicTablesPkg: AcpiSsdtPcieLibArm: Correct translation value Jeff Brasen
2022-07-01 12:40   ` PierreGondois
2022-07-01 15:48     ` Jeff Brasen
2022-06-30 15:48 ` [PATCH 2/4] DynamicTablesPkg: AcpiSsdtPcieLibArm: Allow use of segment number as UID Jeff Brasen
2022-07-01 12:42   ` PierreGondois
2022-07-01 15:54     ` Jeff Brasen
2022-07-04  8:37       ` PierreGondois
2022-07-08 15:24         ` Jeff Brasen
2022-06-30 15:48 ` [PATCH 3/4] DynamicTablesPkg: AcpiSsdtPcieLibArm: Support UID > 0xF Jeff Brasen
2022-06-30 15:48 ` Jeff Brasen [this message]
2022-07-01 12:39   ` [PATCH 4/4] DynamicTablesPkg: AcpiSsdtPcieLibArm: Add support for override protocol PierreGondois
2022-07-01 15:52     ` Jeff Brasen
2022-07-04  8:47       ` PierreGondois
2022-07-08 15:36         ` Jeff Brasen
2022-07-11 15:01           ` PierreGondois
2022-07-11 15:32             ` Jeff Brasen
2022-07-11 17:14               ` PierreGondois
2022-07-11 17:56                 ` Jeff Brasen

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=45abcaa79586b025205269d17957537d613c9bc2.1656603839.git.jbrasen@nvidia.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