From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM12-MW2-obe.outbound.protection.outlook.com (NAM12-MW2-obe.outbound.protection.outlook.com [40.107.244.124]) by mx.groups.io with SMTP id smtpd.web09.9819.1637167815285594766 for ; Wed, 17 Nov 2021 08:50:15 -0800 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@os.amperecomputing.com header.s=selector2 header.b=Ueleh3j4; spf=pass (domain: os.amperecomputing.com, ip: 40.107.244.124, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VCaJDJ9/st1zoFrWM1nAosNmR4qgFoRj3PUCkVgg/VFhAJhlMAMBKdmrmbp7hD8+nBwfOEfCebsGFxMNr/fSHU01H/T5NB1QR5AHKb9V7LLGiU5UCfRRQOm2eUCuDVw2A7UvLnYkalumEP0g14eVUijgUJBBI6+LrVqOmOtSJxr8lcLaN0dXiRkcuUqQzxmiAPoaZJY9836lq5Qi/W0Yq6O1+eFJeJ7uyEHgZ56kw0acRCuUTdXOZDftCYPuS4n9MBcBgTnnQRlVLrLdeltLsvkQMkuaOe8guyS3cjIZkuGrJtCw9LQ37UW1mjMyCwyCfP1mM0lXe2zLZ29+3I4f5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=seLKvNSZimDUciAUYHHIT5Kx/9/0/P7BuRnE5reScGQ=; b=L6BgAbWvzn5n6qBCvUbvrvVSLGmI5C2DQFzgb8ISBIIDgDVwVt9RDoMRRf9yAOvPRhpvSu63rc7HIBSjURmXFACLqcXJRGvFbeyQ8A+vhPp7AJ8HfVbXH7PCSVCMCjr2xjt/Rai3I7NuI9UdYSc8I4BcC761nftgiI39aaGw1MYipDnvB9AZAL1duLCetDXHK7PrKlmctn+zQQDNzRISNCR8xVUD7ciVAVz2EaL4chkTKoajcgi5qxFttketuR7F4NRPRcjdjkZ71X5Oo27CdNyAyU0HBzCPotBDBGP5isWN4ZZetpAuh/4U4cYAdcrFlOGNfaqm/R0U6O/wssBXyw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=seLKvNSZimDUciAUYHHIT5Kx/9/0/P7BuRnE5reScGQ=; b=Ueleh3j4K2t2+kHixxjk0TRmnAB4ygyLWV5RpOzUbp2uW7a+lGMCVunxLh5WDadElYv5lD0y1POwrMg79W/nxJxxXEKEBq0sVIl3fwfZ7Y6VDQmougxGdSF368NUu4Qb4aann/YhRRTXQ6Y+UhCPAaNTb+zlrnS3351+ieY5gow= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=os.amperecomputing.com; Received: from PH0PR01MB7287.prod.exchangelabs.com (2603:10b6:510:10a::21) by PH0PR01MB6454.prod.exchangelabs.com (2603:10b6:510:1b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.20; Wed, 17 Nov 2021 16:50:14 +0000 Received: from PH0PR01MB7287.prod.exchangelabs.com ([fe80::254c:9533:7f35:aee]) by PH0PR01MB7287.prod.exchangelabs.com ([fe80::254c:9533:7f35:aee%4]) with mapi id 15.20.4713.019; Wed, 17 Nov 2021 16:50:14 +0000 From: "Nhi Pham" To: devel@edk2.groups.io CC: patches@amperecomputing.com, nhi@os.amperecomputing.com, vunguyen@os.amperecomputing.com, Thang Nguyen , Chuong Tran , Phong Vo , Leif Lindholm , Michael D Kinney , Ard Biesheuvel , Nate DeSimone Subject: [edk2-platforms][PATCH v5 12/30] JadePkg: Add BoardPcieLib library instance Date: Wed, 17 Nov 2021 23:47:09 +0700 Message-ID: <20211117164727.10922-13-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211117164727.10922-1-nhi@os.amperecomputing.com> References: <20211117164727.10922-1-nhi@os.amperecomputing.com> X-ClientProxiedBy: HKAPR04CA0001.apcprd04.prod.outlook.com (2603:1096:203:d0::11) To PH0PR01MB7287.prod.exchangelabs.com (2603:10b6:510:10a::21) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 Received: from sw004.amperecomputing.com (118.69.219.201) by HKAPR04CA0001.apcprd04.prod.outlook.com (2603:1096:203:d0::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.21 via Frontend Transport; Wed, 17 Nov 2021 16:50:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6a1cfa73-0673-4454-c8dc-08d9a9ea536f X-MS-TrafficTypeDiagnostic: PH0PR01MB6454: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xzZ/96hDK5XjHoAFDIA/40PZEXKXfKtcX7ExCg5TubGT9CI+bP0bqHIdX8tnx5kIJK0YhnW2rUARU2jcVtWFji3giSnAFTtPKQTmfol6N7LbkymFEua4JzfpssMnZdYsqtFYoniCk+R0FCLpl7ULwoCprvkkCaIWPE+E8DEjCWyH9VUH8KD2ITkGiwXaklgxR3TUSqI7MmgNEtFNnS+kqOKKturi6RN2/M4n8pCuI74bGflBBtr7mLp56DvdyRhQUI4KmbmStycDWd1g8542yy+f0kA4iwxMOFbdK1qR9TBwltVHF//XxUWGYAQDjr+wRk45FGnn+D/ZOeW8rtQhKPqGTxNPxiHfCP+J50/yleDhhjcqFSxpSqEuaWG/8S3frpdq8XTcWYF//zr5hISy0ozwwXgnE6z8FLkA0ztf0pCcOmfa23JujAg3Nd4ns2QV1vC109gqQnnFwUQJ7xtLBDlq+fAWapV8sAr3HkggAm04qYGK01P9osrs83yQ/2M9YoY5TYfAz9BdMvteAgWAhNWwY9PL7kpkd3LeuLwBlh8rB7ygrjgKGpN7oeTCb5Ha2hcpIA+psVTDq7veSQuP4BNAbM/8TPUJGM8Dl5xTmkFzvxgD3HT87PIIBzz5HjWb6myUgn2fqCF0i+2EnKBdp+YNrW6QfCkyMVGonVE9KTGw47ElP8XfEtE8O2JdRTz6MFs+vEbXMjoGoCg2f3Uegw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR01MB7287.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(8936002)(66476007)(52116002)(186003)(86362001)(2906002)(1076003)(83380400001)(54906003)(4326008)(66556008)(26005)(38100700002)(38350700002)(6506007)(6916009)(6486002)(2616005)(956004)(5660300002)(6512007)(316002)(8676002)(66946007)(508600001);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?uiqjePWNq9RCnUx86jbL7YGPlBSdcvgmi3mCgfXNt//mNy8nYM8sVKMidBkE?= =?us-ascii?Q?vgF9C6XrnOvSGgK0rpk01MiUACsDw4+RNvn1oAS0cu5Y0iMfKfICHIYYLMD3?= =?us-ascii?Q?ObN7lYKCip9+OqEHAeCsk/8XdPhf9ykVueae2ZzhGQ6BODszLN7nfGuTruHA?= =?us-ascii?Q?jJRj3oxulagfkbolbS8tNpJ+yuKGularJIRMI5N4Xz4iLQMm4momGJrfP/6m?= =?us-ascii?Q?/LZOhoDaask245cuT6HV/qp2fyYB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ghwXuBLBJBL+kx3Qa21qoJ+E6bXiK1P2uZlW/z13En/s/J2bowHEwH?= =?us-ascii?Q?zf0T+h8fzP9WvdkxCwguRvVexBJpoZBNBaSx820KGEgL30QjDy9BGuX8wdPG?= =?us-ascii?Q?iHk8VgoDwS4yEm/YIdSafsmX5MuQqGLbQFQkE58ggPl5gaNVD+auS52Z9R6I?= =?us-ascii?Q?ci1PAiFUFKyMqQYsbcWgH5dek9H0at9xsJe/EQOyIHqk6GyumDCJgV7bGMPf?= =?us-ascii?Q?USE3mGJ19/WeZqnh6yOcPTGfTvyfkXvXnOIfO5t7zen9TTGxLjU0byCRbPex?= =?us-ascii?Q?RbfFOrS50ktcHZvwbhKJ+Dy0/2FlBcBgurQnM3e+zt+pQAz85L/zhLrOjHcD?= =?us-ascii?Q?olK/6uCJsV+azT0AM6j+1cxUGTMLZjv0XEqNH9l7DW0iahQYSl3rMs10jHbi?= =?us-ascii?Q?7bERr7gNQckFjBu98NA/gADedOdvl9Z1Rhni+kcqixLf5NMw1lPdEt/Sk3dL?= =?us-ascii?Q?j3X8iYrq4xEY4nsz6yabT7KzQhlpFIf8zVulr845dupVllWRxWVBcIyKGb0L?= =?us-ascii?Q?AIldRHOMDsuuIwmHvb2OVoPD2wM=3D?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6a1cfa73-0673-4454-c8dc-08d9a9ea536f X-MS-Exchange-CrossTenant-AuthSource: PH0PR01MB7287.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Nov 2021 16:50:14.0615 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: PiSDNKtChz9WQel+GfU4YHwQBfhZ6OcdR5A/qDmlP910BmOJO69PNgsHiIZYdyAItm+4iHnawuJ+a0zrsovEQkyUwFAN+NMsjkGWSIqtXJY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR01MB6454 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain From: Vu Nguyen Provide Mt. Jade specific segment number for each Root Complex and function to handle the PCIe PERST. Cc: Thang Nguyen Cc: Chuong Tran Cc: Phong Vo Cc: Leif Lindholm Cc: Michael D Kinney Cc: Ard Biesheuvel Cc: Nate DeSimone Signed-off-by: Nhi Pham Reviewed-by: Leif Lindholm --- 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/Jad= e.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/Boar= dPcieLibNull.inf + BoardPcieLib|Platform/Ampere/JadePkg/Library/BoardPcieLib/BoardPcieLib.i= nf =20 ##########################################################################= ###### # 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. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D BoardPcieLib + FILE_GUID =3D 062191A6-E113-4FD6-84C7-E400B4B34759 + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D 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 Spec= ification. + + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include + +#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 =3D AC01_GPIO_PINS_PER_SOCKET * SocketId + 16; + for (GpioIndex =3D 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 Co= mplex. + @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 =3D=3D RootComplexTypeA) { + // + // RootComplexTypeA: RootComplex->ID: 0->3 ; PcieIndex: 0->3 + // + GpioGroupVal =3D RCA_MAX_PERST_GROUPVAL - PcieIndex + - RootComplex->ID * MaxPcieControllerOfRootComplexA; + } else { + // + // RootComplexTypeB: RootComplex->ID: 4->7 ; PcieIndex: 0->7 + // + GpioGroupVal =3D RCB_MAX_PERST_GROUPVAL - PcieIndex + - (RootComplex->ID - MaxRootComplexA) * MaxPcieContro= llerOfRootComplexB; + } + + // Update the value of GPIO[16..21]. Corresponding PERST line will be = decoded by CPLD. + GpioPin =3D AC01_GPIO_PINS_PER_SOCKET * RootComplex->Socket + 16; + for (GpioIndex =3D 0; GpioIndex < 6; GpioIndex++) { + Val =3D (GpioGroupVal & 0x3F) & (1 << GpioIndex); + if (Val =3D=3D 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 num= ber. + + @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_COMPL= EX] =3D + { + { 0x0C, 0x0D, 0x01, 0x00, 0x02, 0x03, 0x04, 0x= 05 }, + { 0x10, 0x11, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x= 0B } + }; + + if (RootComplex->Socket < PLATFORM_CPU_MAX_SOCKET + && RootComplex->ID < AC01_PCIE_MAX_ROOT_COMPLEX) { + return Ac01BoardSegment[RootComplex->Socket][RootComplex->ID]; + } + + return DEFAULT_SEGMENT_NUMBER; +} --=20 2.17.1