public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Nhi Pham" <nhi@os.amperecomputing.com>
To: devel@edk2.groups.io
Cc: patches@amperecomputing.com, nhi@os.amperecomputing.com,
	vunguyen@os.amperecomputing.com,
	Thang Nguyen <thang@os.amperecomputing.com>,
	Chuong Tran <chuong@os.amperecomputing.com>,
	Phong Vo <phong@os.amperecomputing.com>,
	Leif Lindholm <leif@nuviainc.com>,
	Michael D Kinney <michael.d.kinney@intel.com>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Nate DeSimone <nathaniel.l.desimone@intel.com>
Subject: [edk2-platforms][PATCH v4 18/31] JadePkg: Add PciPlatformDxe driver
Date: Fri, 22 Oct 2021 13:17:56 +0700	[thread overview]
Message-ID: <20211022061809.31087-19-nhi@os.amperecomputing.com> (raw)
In-Reply-To: <20211022061809.31087-1-nhi@os.amperecomputing.com>

From: Vu Nguyen <vunguyen@os.amperecomputing.com>

Registers the Platform NotifyPhase() to prevent unexpected issues
caused by the enabled PCIe controllers with unstable link.

Cc: Thang Nguyen <thang@os.amperecomputing.com>
Cc: Chuong Tran <chuong@os.amperecomputing.com>
Cc: Phong Vo <phong@os.amperecomputing.com>
Cc: Leif Lindholm <leif@nuviainc.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Ard Biesheuvel <ardb+tianocore@kernel.org>
Cc: Nate DeSimone <nathaniel.l.desimone@intel.com>

Signed-off-by: Nhi Pham <nhi@os.amperecomputing.com>
Reviewed-by: Leif Lindholm <leif@nuviainc.com>
---
 Platform/Ampere/JadePkg/Jade.dsc                                  |   5 +
 Platform/Ampere/JadePkg/Jade.fdf                                  |   1 +
 Platform/Ampere/JadePkg/Drivers/PciPlatformDxe/PciPlatformDxe.inf |  41 ++++
 Platform/Ampere/JadePkg/Drivers/PciPlatformDxe/PciPlatformDxe.c   | 258 ++++++++++++++++++++
 4 files changed, 305 insertions(+)

diff --git a/Platform/Ampere/JadePkg/Jade.dsc b/Platform/Ampere/JadePkg/Jade.dsc
index 9315c1c71cc7..ffba757a6130 100644
--- a/Platform/Ampere/JadePkg/Jade.dsc
+++ b/Platform/Ampere/JadePkg/Jade.dsc
@@ -129,3 +129,8 @@ [Components.common]
   Platform/Ampere/JadePkg/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
   Silicon/Ampere/AmpereAltraPkg/AcpiCommonTables/AcpiCommonTables.inf
   Platform/Ampere/JadePkg/AcpiTables/AcpiTables.inf
+
+  #
+  # PCIe
+  #
+  Platform/Ampere/JadePkg/Drivers/PciPlatformDxe/PciPlatformDxe.inf
diff --git a/Platform/Ampere/JadePkg/Jade.fdf b/Platform/Ampere/JadePkg/Jade.fdf
index 00184f105e6f..19e7cf16697e 100644
--- a/Platform/Ampere/JadePkg/Jade.fdf
+++ b/Platform/Ampere/JadePkg/Jade.fdf
@@ -299,6 +299,7 @@ [FV.FvMain]
   #
   INF MdeModulePkg/Bus/Pci/PciBusDxe/PciBusDxe.inf
   INF MdeModulePkg/Bus/Pci/PciHostBridgeDxe/PciHostBridgeDxe.inf
+  INF Platform/Ampere/JadePkg/Drivers/PciPlatformDxe/PciPlatformDxe.inf
 
   #
   # UEFI application (Shell Embedded Boot Loader)
diff --git a/Platform/Ampere/JadePkg/Drivers/PciPlatformDxe/PciPlatformDxe.inf b/Platform/Ampere/JadePkg/Drivers/PciPlatformDxe/PciPlatformDxe.inf
new file mode 100644
index 000000000000..ddf6eeb759eb
--- /dev/null
+++ b/Platform/Ampere/JadePkg/Drivers/PciPlatformDxe/PciPlatformDxe.inf
@@ -0,0 +1,41 @@
+## @file
+#
+# Copyright (c) 2021, Ampere Computing LLC. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[defines]
+  INF_VERSION          = 0x0001001B
+  BASE_NAME            = PciPlatformDxe
+  FILE_GUID            = 73276F3D-DCBC-49B2-9890-7564F917501D
+  MODULE_TYPE          = DXE_DRIVER
+  VERSION_STRING       = 1.0
+  ENTRY_POINT          = PciPlatformDriverEntry
+
+[Sources]
+  PciPlatformDxe.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec
+
+[LibraryClasses]
+  Ac01PcieLib
+  DebugLib
+  HobLib
+  TimerLib
+  UefiBootServicesTableLib
+  UefiDriverEntryPoint
+
+[Protocols]
+  gEfiDevicePathProtocolGuid
+  gEfiPciHostBridgeResourceAllocationProtocolGuid
+  gEfiPciPlatformProtocolGuid
+
+[Guids]
+  gRootComplexInfoHobGuid
+
+[Depex]
+  TRUE
diff --git a/Platform/Ampere/JadePkg/Drivers/PciPlatformDxe/PciPlatformDxe.c b/Platform/Ampere/JadePkg/Drivers/PciPlatformDxe/PciPlatformDxe.c
new file mode 100644
index 000000000000..865dfb891a24
--- /dev/null
+++ b/Platform/Ampere/JadePkg/Drivers/PciPlatformDxe/PciPlatformDxe.c
@@ -0,0 +1,258 @@
+/** @file
+
+  Copyright (c) 2021, Ampere Computing LLC. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+
+#include <Guid/RootComplexInfoHob.h>
+#include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/Ac01PcieLib.h>
+#include <Library/TimerLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Protocol/DevicePath.h>
+#include <Protocol/PciHostBridgeResourceAllocation.h>
+#include <Protocol/PciPlatform.h>
+
+#pragma pack(1)
+typedef struct {
+  ACPI_HID_DEVICE_PATH     AcpiDevicePath;
+  EFI_DEVICE_PATH_PROTOCOL EndDevicePath;
+} EFI_PCI_ROOT_BRIDGE_DEVICE_PATH;
+#pragma pack ()
+
+/**
+  Callback funciton for EndEnumeration notification from PCI stack.
+
+  @param[in]  RootBridgeIndex       Index to identify of PCIE Root bridge.
+  @param[in]  Phase                 The phase of enumeration as informed from PCI stack.
+**/
+VOID
+NotifyPhaseCallBack (
+  IN UINTN                                         RootBridgeIndex,
+  IN EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE Phase
+  )
+{
+  AC01_ROOT_COMPLEX *RootComplexList;
+  VOID              *Hob;
+
+  Hob = GetFirstGuidHob (&gRootComplexInfoHobGuid);
+  if (Hob == NULL) {
+    return;
+  }
+
+  RootComplexList = (AC01_ROOT_COMPLEX *)GET_GUID_HOB_DATA (Hob);
+
+  switch (Phase) {
+  case EfiPciHostBridgeEndEnumeration:
+    Ac01PcieCoreEndEnumeration (&RootComplexList[RootBridgeIndex]);
+    break;
+
+  case EfiPciHostBridgeBeginEnumeration:
+    // 100ms that help fixing completion timeout issue
+    MicroSecondDelay (100000);
+    break;
+
+  case EfiPciHostBridgeBeginBusAllocation:
+  case EfiPciHostBridgeEndBusAllocation:
+  case EfiPciHostBridgeBeginResourceAllocation:
+  case EfiPciHostBridgeAllocateResources:
+  case EfiPciHostBridgeSetResources:
+  case EfiPciHostBridgeFreeResources:
+  case EfiPciHostBridgeEndResourceAllocation:
+  case EfiMaxPciHostBridgeEnumerationPhase:
+    break;
+  }
+}
+
+/**
+
+  Perform initialization by the phase indicated.
+
+  @param This                        Pointer to the EFI_PCI_PLATFORM_PROTOCOL instance.
+  @param HostBridge                  The associated PCI host bridge handle.
+  @param Phase                       The phase of the PCI controller enumeration.
+  @param ChipsetPhase                Defines the execution phase of the PCI chipset driver.
+
+  @retval EFI_SUCCESS                Must return with success.
+
+**/
+EFI_STATUS
+EFIAPI
+PhaseNotify (
+  IN  EFI_PCI_PLATFORM_PROTOCOL                      *This,
+  IN  EFI_HANDLE                                     HostBridge,
+  IN  EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PHASE  Phase,
+  IN  EFI_PCI_CHIPSET_EXECUTION_PHASE                ChipsetPhase
+  )
+{
+  EFI_PCI_ROOT_BRIDGE_DEVICE_PATH                   *RootBridgeDevPath;
+  EFI_HANDLE                                        RootBridgeHandle = NULL;
+  EFI_PCI_HOST_BRIDGE_RESOURCE_ALLOCATION_PROTOCOL  *ResAlloc = NULL;
+  EFI_STATUS                                        Status;
+
+  if (ChipsetPhase != ChipsetExit) {
+    return EFI_SUCCESS;
+  }
+
+  //
+  // Get HostBridgeInstance from HostBridge handle.
+  //
+  Status = gBS->HandleProtocol (
+                  HostBridge,
+                  &gEfiPciHostBridgeResourceAllocationProtocolGuid,
+                  (VOID **)&ResAlloc
+                  );
+
+  while (TRUE) {
+    Status = ResAlloc->GetNextRootBridge (ResAlloc, &RootBridgeHandle);
+    if (EFI_ERROR (Status)) {
+      break;
+    }
+
+    Status = gBS->HandleProtocol (
+                    RootBridgeHandle,
+                    &gEfiDevicePathProtocolGuid,
+                    (VOID **)&RootBridgeDevPath
+                    );
+    if (EFI_ERROR (Status)) {
+      DEBUG ((DEBUG_ERROR, "%a %d: Failed to locate RootBridge DevicePath\n", __FUNCTION__, __LINE__));
+      break;
+    }
+
+    NotifyPhaseCallBack (RootBridgeDevPath->AcpiDevicePath.UID, Phase);
+  }
+
+  return EFI_SUCCESS;
+}
+
+/**
+
+  The PlatformPrepController() function can be used to notify the platform driver so that
+  it can perform platform-specific actions. No specific actions are required.
+  Several notification points are defined at this time. More synchronization points may be
+  added as required in the future. The PCI bus driver calls the platform driver twice for
+  every PCI controller-once before the PCI Host Bridge Resource Allocation Protocol driver
+  is notified, and once after the PCI Host Bridge Resource Allocation Protocol driver has
+  been notified.
+  This member function may not perform any error checking on the input parameters. It also
+  does not return any error codes. If this member function detects any error condition, it
+  needs to handle those errors on its own because there is no way to surface any errors to
+  the caller.
+
+  @param This                       Pointer to the EFI_PCI_PLATFORM_PROTOCOL instance.
+  @param HostBridge                 The associated PCI host bridge handle.
+  @param RootBridge                 The associated PCI root bridge handle.
+  @param PciAddress                 The address of the PCI device on the PCI bus.
+  @param Phase                      The phase of the PCI controller enumeration.
+  @param ChipsetPhase               Defines the execution phase of the PCI chipset driver.
+
+  @retval EFI_SUCCESS               The function completed successfully.
+  @retval EFI_UNSUPPORTED           Not supported.
+
+**/
+EFI_STATUS
+EFIAPI
+PlatformPrepController (
+  IN  EFI_PCI_PLATFORM_PROTOCOL                      *This,
+  IN  EFI_HANDLE                                     HostBridge,
+  IN  EFI_HANDLE                                     RootBridge,
+  IN  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_PCI_ADDRESS    PciAddress,
+  IN  EFI_PCI_CONTROLLER_RESOURCE_ALLOCATION_PHASE   Phase,
+  IN  EFI_PCI_CHIPSET_EXECUTION_PHASE                ChipsetPhase
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+/**
+  Set the PciPolicy as EFI_RESERVE_ISA_IO_NO_ALIAS | EFI_RESERVE_VGA_IO_NO_ALIAS.
+
+  @param This                        The pointer to the Protocol itself.
+  @param PciPolicy                   The returned Policy.
+
+  @retval EFI_UNSUPPORTED            Function not supported.
+  @retval EFI_INVALID_PARAMETER      Invalid PciPolicy value.
+
+**/
+EFI_STATUS
+EFIAPI
+GetPlatformPolicy (
+  IN  CONST EFI_PCI_PLATFORM_PROTOCOL   *This,
+  OUT EFI_PCI_PLATFORM_POLICY           *PciPolicy
+  )
+{
+  return EFI_UNSUPPORTED;
+}
+
+/**
+
+  Return a PCI ROM image for the onboard device represented by PciHandle.
+
+  @param This                        Protocol instance pointer.
+  @param PciHandle                   PCI device to return the ROM image for.
+  @param RomImage                    PCI Rom Image for onboard device.
+  @param RomSize                     Size of RomImage in bytes.
+
+  @retval EFI_SUCCESS                RomImage is valid.
+  @retval EFI_NOT_FOUND              No RomImage.
+
+**/
+EFI_STATUS
+EFIAPI
+GetPciRom (
+  IN  CONST EFI_PCI_PLATFORM_PROTOCOL   *This,
+  IN  EFI_HANDLE                        PciHandle,
+  OUT VOID                              **RomImage,
+  OUT UINTN                             *RomSize
+  )
+{
+  return EFI_NOT_FOUND;
+}
+
+//
+// Interface defintion of PCI Platform protocol.
+//
+EFI_PCI_PLATFORM_PROTOCOL mPciPlatformProtocol = {
+  .PlatformNotify             = PhaseNotify,
+  .PlatformPrepController     = PlatformPrepController,
+  .GetPlatformPolicy          = GetPlatformPolicy,
+  .GetPciRom                  = GetPciRom
+};
+
+/**
+
+  The Entry point of the Pci Platform Driver.
+
+  @param ImageHandle                 Handle to the image.
+  @param SystemTable                 Handle to System Table.
+
+  @retval EFI_STATUS                 Status of the function calling.
+
+**/
+EFI_STATUS
+PciPlatformDriverEntry (
+  IN EFI_HANDLE                         ImageHandle,
+  IN EFI_SYSTEM_TABLE                   *SystemTable
+  )
+{
+  EFI_STATUS                Status;
+  EFI_HANDLE                PciPlatformHandle;
+
+  //
+  // Install on a new handle
+  //
+  PciPlatformHandle = NULL;
+  Status = gBS->InstallMultipleProtocolInterfaces (
+                  &PciPlatformHandle,
+                  &gEfiPciPlatformProtocolGuid,
+                  &mPciPlatformProtocol,
+                  NULL
+                  );
+
+  return Status;
+}
-- 
2.17.1


  parent reply	other threads:[~2021-10-22  6:20 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-10-22  6:17 [edk2-platforms][PATCH v4 00/31] Add new Ampere Mt. Jade platform Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 01/31] Ampere: Initial support for Ampere Altra processor and " Nhi Pham
2021-10-26 11:14   ` Leif Lindholm
2021-11-03  9:31     ` Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 02/31] AmpereAltraPkg: Add FlashLib library instance Nhi Pham
2021-10-26 11:25   ` Leif Lindholm
2021-11-03  9:32     ` Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 03/31] AmpereAltraPkg: Add FailSafe and WDT support Nhi Pham
2021-10-26 12:15   ` Leif Lindholm
2021-11-03  9:35     ` Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 04/31] AmpereAltraPkg: Add DwI2cLib library instance Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 05/31] AmpereAltraPkg: Add DwGpioLib " Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 06/31] JadePkg: Implement RealTimeClockLib for PCF85063 Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 07/31] AmpereAltraPkg: Add BootProgress support Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 08/31] AmpereAltraPkg: Support UEFI non-volatile variable Nhi Pham
2021-10-26 12:21   ` Leif Lindholm
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 09/31] AmpereSiliconPkg: Add PlatformManagerUiLib library instance Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 10/31] AmpereAltraPkg, JadePkg: Add ACPI support Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 11/31] AmpereAltraPkg: Add Root Complex HOB data structures Nhi Pham
2021-10-26 12:23   ` Leif Lindholm
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 12/31] AmpereAltraPkg: Add Ac01PcieLib library instance Nhi Pham
2021-10-26 12:45   ` Leif Lindholm
2021-11-03  9:33     ` Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 13/31] JadePkg: Add BoardPcieLib " Nhi Pham
2021-10-26 12:46   ` Leif Lindholm
2021-11-03  9:33     ` Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 14/31] AmpereAltraPkg: Add driver to initialize PCIe Root Complex Nhi Pham
2021-10-26 12:49   ` Leif Lindholm
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 15/31] AmpereAltraPkg: Add PciHostBridgeLib library instance Nhi Pham
2021-10-26 12:49   ` Leif Lindholm
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 16/31] AmpereAltraPkg: Add PciSegmentLib " Nhi Pham
2021-10-26 12:53   ` Leif Lindholm
2021-11-03  9:35     ` Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 17/31] JadePkg: Enable PciHostBridgeDxe driver Nhi Pham
2021-10-22  6:17 ` Nhi Pham [this message]
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 19/31] JadePkg: Add ACPI tables to support PCIe Nhi Pham
2021-10-26 12:54   ` Leif Lindholm
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 20/31] JadePkg: Add ASpeed GOP driver Nhi Pham
2021-10-22  6:17 ` [edk2-platforms][PATCH v4 21/31] AmpereAltraPkg: Add Random Number Generator Support Nhi Pham
2021-10-22  6:18 ` [edk2-platforms][PATCH v4 22/31] JadePkg: Add SMBIOS tables support Nhi Pham
2021-10-22  6:18 ` [edk2-platforms][PATCH v4 23/31] AmpereAltraPkg: Add DebugInfoPei module Nhi Pham
2021-10-22  6:18 ` [edk2-platforms][PATCH v4 24/31] AmpereAltraPkg: Add configuration screen for PCIe Nhi Pham
2021-10-26 12:56   ` Leif Lindholm
2021-10-22  6:18 ` [edk2-platforms][PATCH v4 25/31] Ampere: Utilize the PCIe User setting Nhi Pham
2021-10-26 12:57   ` Leif Lindholm
2021-10-22  6:18 ` [edk2-platforms][PATCH v4 26/31] AmpereAltraPkg: Add platform info screen Nhi Pham
2021-10-22  6:18 ` [edk2-platforms][PATCH v4 27/31] AmpereAltraPkg: Add configuration screen for Memory Nhi Pham
2021-10-26 12:58   ` Leif Lindholm
2021-10-22  6:18 ` [edk2-platforms][PATCH v4 28/31] AmpereAltraPkg: Add configuration screen for CPU Nhi Pham
2021-10-22  6:18 ` [edk2-platforms][PATCH v4 29/31] AmpereAltraPkg: Add configuration screen for ACPI Nhi Pham
2021-10-22  6:18 ` [edk2-platforms][PATCH v4 30/31] AmpereAltraPkg: Add configuration screen for RAS Nhi Pham
2021-10-22  6:18 ` [edk2-platforms][PATCH v4 31/31] AmpereAltraPkg: Add configuration screen for Watchdog timer Nhi Pham
2021-10-26 13:03   ` Leif Lindholm
2021-11-03  9:36     ` Nhi Pham
2021-10-26 13:08 ` [edk2-platforms][PATCH v4 00/31] Add new Ampere Mt. Jade platform Leif Lindholm
2021-11-03  9:37   ` Nhi Pham

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=20211022061809.31087-19-nhi@os.amperecomputing.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