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 v5 12/30] JadePkg: Add BoardPcieLib library instance
Date: Wed, 17 Nov 2021 23:47:09 +0700	[thread overview]
Message-ID: <20211117164727.10922-13-nhi@os.amperecomputing.com> (raw)
In-Reply-To: <20211117164727.10922-1-nhi@os.amperecomputing.com>

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

Provide Mt. Jade specific segment number for each Root Complex and
function to handle the PCIe PERST.

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                              |   2 +-
 Platform/Ampere/JadePkg/Library/BoardPcieLib/BoardPcieLib.inf |  27 +++++
 Platform/Ampere/JadePkg/Library/BoardPcieLib/BoardPcieLib.c   | 117 ++++++++++++++++++++
 3 files changed, 145 insertions(+), 1 deletion(-)

diff --git a/Platform/Ampere/JadePkg/Jade.dsc b/Platform/Ampere/JadePkg/Jade.dsc
index 23a297d0dbeb..9315c1c71cc7 100644
--- a/Platform/Ampere/JadePkg/Jade.dsc
+++ b/Platform/Ampere/JadePkg/Jade.dsc
@@ -85,7 +85,7 @@ [LibraryClasses]
   #
   # Pcie Board
   #
-  BoardPcieLib|Silicon/Ampere/AmpereAltraPkg/Library/BoardPcieLibNull/BoardPcieLibNull.inf
+  BoardPcieLib|Platform/Ampere/JadePkg/Library/BoardPcieLib/BoardPcieLib.inf
 
 ################################################################################
 #
diff --git a/Platform/Ampere/JadePkg/Library/BoardPcieLib/BoardPcieLib.inf b/Platform/Ampere/JadePkg/Library/BoardPcieLib/BoardPcieLib.inf
new file mode 100644
index 000000000000..1d722bceff2c
--- /dev/null
+++ b/Platform/Ampere/JadePkg/Library/BoardPcieLib/BoardPcieLib.inf
@@ -0,0 +1,27 @@
+## @file
+#
+# Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x0001001B
+  BASE_NAME                      = BoardPcieLib
+  FILE_GUID                      = 062191A6-E113-4FD6-84C7-E400B4B34759
+  MODULE_TYPE                    = BASE
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = BoardPcieLib
+
+[Sources]
+  BoardPcieLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec
+
+[LibraryClasses]
+  DebugLib
+  GpioLib
+  TimerLib
diff --git a/Platform/Ampere/JadePkg/Library/BoardPcieLib/BoardPcieLib.c b/Platform/Ampere/JadePkg/Library/BoardPcieLib/BoardPcieLib.c
new file mode 100644
index 000000000000..f49764097219
--- /dev/null
+++ b/Platform/Ampere/JadePkg/Library/BoardPcieLib/BoardPcieLib.c
@@ -0,0 +1,117 @@
+/** @file
+  Pcie board specific driver to handle asserting PERST signal to Endpoint
+  card. PERST asserting is via group of GPIO pins to CPLD as Platform Specification.
+
+  Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <PiDxe.h>
+
+#include <Guid/RootComplexInfoHob.h>
+#include <Library/DebugLib.h>
+#include <Library/GpioLib.h>
+#include <Library/TimerLib.h>
+#include <Platform/Ac01.h>
+
+#define RCA_MAX_PERST_GROUPVAL          62
+#define RCB_MAX_PERST_GROUPVAL          46
+#define DEFAULT_SEGMENT_NUMBER          0x0F
+
+VOID
+BoardPcieReleaseAllPerst (
+  IN UINT8 SocketId
+  )
+{
+  UINT32 GpioIndex, GpioPin;
+
+  // Write 1 to all GPIO[16..21] to release all PERST
+  GpioPin = AC01_GPIO_PINS_PER_SOCKET * SocketId + 16;
+  for (GpioIndex = 0; GpioIndex < 6; GpioIndex++) {
+    GpioModeConfig (GpioPin + GpioIndex, GpioConfigOutHigh);
+  }
+}
+
+/**
+  Assert PERST of PCIe controller
+
+  @param[in]  RootComplex           Root Complex instance.
+  @param[in]  PcieIndex             PCIe controller index of input Root Complex.
+  @param[in]  IsPullToHigh          Target status for the PERST.
+
+  @retval RETURN_SUCCESS            The operation is successful.
+  @retval Others                    An error occurred.
+**/
+RETURN_STATUS
+EFIAPI
+BoardPcieAssertPerst (
+  IN AC01_ROOT_COMPLEX *RootComplex,
+  IN UINT8             PcieIndex,
+  IN BOOLEAN           IsPullToHigh
+  )
+{
+  UINT32 GpioGroupVal, Val, GpioIndex, GpioPin;
+
+  if (!IsPullToHigh) {
+    if (RootComplex->Type == RootComplexTypeA) {
+      //
+      // RootComplexTypeA: RootComplex->ID: 0->3 ; PcieIndex: 0->3
+      //
+      GpioGroupVal = RCA_MAX_PERST_GROUPVAL - PcieIndex
+                     - RootComplex->ID * MaxPcieControllerOfRootComplexA;
+    } else {
+      //
+      // RootComplexTypeB: RootComplex->ID: 4->7 ; PcieIndex: 0->7
+      //
+      GpioGroupVal = RCB_MAX_PERST_GROUPVAL - PcieIndex
+                     - (RootComplex->ID - MaxRootComplexA) * MaxPcieControllerOfRootComplexB;
+    }
+
+    // Update the value of GPIO[16..21]. Corresponding PERST line will be decoded by CPLD.
+    GpioPin = AC01_GPIO_PINS_PER_SOCKET * RootComplex->Socket + 16;
+    for (GpioIndex = 0; GpioIndex < 6; GpioIndex++) {
+      Val = (GpioGroupVal & 0x3F) & (1 << GpioIndex);
+      if (Val == 0) {
+        GpioModeConfig (GpioPin + GpioIndex, GpioConfigOutLow);
+      } else {
+        GpioModeConfig (GpioPin + GpioIndex, GpioConfigOutHigh);
+      }
+    }
+
+    // Keep reset as low as 100 ms as specification
+    MicroSecondDelay (100 * 1000);
+  } else {
+    BoardPcieReleaseAllPerst (RootComplex->Socket);
+  }
+
+  return RETURN_SUCCESS;
+}
+
+/**
+  Override the segment number for a root complex with a board specific number.
+
+  @param[in]  RootComplex           Root Complex instance with properties.
+
+  @retval Segment number corresponding to the input root complex.
+          Default segment number is 0x0F.
+**/
+UINT16
+BoardPcieGetSegmentNumber (
+  IN  AC01_ROOT_COMPLEX *RootComplex
+  )
+{
+  UINT8 Ac01BoardSegment[PLATFORM_CPU_MAX_SOCKET][AC01_PCIE_MAX_ROOT_COMPLEX] =
+                          {
+                            { 0x0C, 0x0D, 0x01, 0x00, 0x02, 0x03, 0x04, 0x05 },
+                            { 0x10, 0x11, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B }
+                          };
+
+  if (RootComplex->Socket < PLATFORM_CPU_MAX_SOCKET
+      && RootComplex->ID < AC01_PCIE_MAX_ROOT_COMPLEX) {
+    return Ac01BoardSegment[RootComplex->Socket][RootComplex->ID];
+  }
+
+  return DEFAULT_SEGMENT_NUMBER;
+}
-- 
2.17.1


  parent reply	other threads:[~2021-11-17 16:50 UTC|newest]

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

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=20211117164727.10922-13-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