From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (NAM10-MW2-obe.outbound.protection.outlook.com [40.107.94.99]) by mx.groups.io with SMTP id smtpd.web08.5501.1622023961603761774 for ; Wed, 26 May 2021 03:12:41 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@os.amperecomputing.com header.s=selector2 header.b=h/MEOU8e; spf=pass (domain: os.amperecomputing.com, ip: 40.107.94.99, mailfrom: nhi@os.amperecomputing.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NUY1OkaTqlaOUUNZ4BTehQCcKBERocEg2Sq1Y9VcesZrv6bMzPKJxxdpeIP22oMmJiJLDjQr3ZkvQNq7gu1920hbJk+fAAG9FIp7n+4fwJcYgC0rAWZND4jteW/60PAXjRjfyNTtfMOwAb1o3iS9T/5M1VISQrtMCBYqcQUap5sEZJ8sBe4ACRERc4x0EqrwT+T/Ha1Q9JH6W5Pnap/3bUAXVLPVzcfHAEZ97S+jv2+m42Tq8KPlyNkEX6ofNASGrm7THKZLgmRpKNsXIV3VAa6pmdpFp+4KI/y163v0rcV6FGJEGtXYQiJOyON56EN/u+a73KEtvyxjQ4gV1199Lg== 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-SenderADCheck; bh=G/EQYs1ory5U+SML5o323cm5WqRHdDhUjKUnHmn4cOc=; b=kaubEVfgfwU/dW5KSmDxAB5s8fhN4Q0q9S9XIe7CE53GTVbFaqut/jd7sAbIcx63MHhjbkymfpBobIm3r8v/5ONzdZBvD73/AW8E5P5kd/CnCJb9w/8jYyQaTCQsaecuXJLsVnPz/e27QC7DClhdbCyus4LVUuNCgB2LflBQaRmOlO7KMUQEIf1rJaxpWyuEyB+MRWeBJKd2L406OCn4OMF6vrHneJ3ydrpUSXQInwuPp3qrPOxTx6oNklT1kq/IfpVu4zRCrnVn0yrnw+xaduPTUaeKjfTBQs24/4LM7YHVdr+Cf+Xkck11lB3pGbm1lF/WgDFinnNVgTnDLtY32A== 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=G/EQYs1ory5U+SML5o323cm5WqRHdDhUjKUnHmn4cOc=; b=h/MEOU8exKwQipjz7q5agiIK84DMC3E8BG41RSemlHxBxZq0gtN8dDylDuNtNZ3A5fyFRNqyxfni483HZcneAFJO6MeExQtqUpEgS5GMhwbnVfsaxdyuTfAQ8j0D3MwAgFr6e16bQuUqcCoBuUwDacFZ4hnz+t/ltBvwbAWH064= Authentication-Results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=os.amperecomputing.com; Received: from DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) by DM5PR01MB2426.prod.exchangelabs.com (2603:10b6:3:3b::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.27; Wed, 26 May 2021 10:12:39 +0000 Received: from DM6PR01MB5849.prod.exchangelabs.com ([fe80::60d2:86dd:1f1c:51dd]) by DM6PR01MB5849.prod.exchangelabs.com ([fe80::60d2:86dd:1f1c:51dd%7]) with mapi id 15.20.4173.020; Wed, 26 May 2021 10:12:39 +0000 From: "Nhi Pham" To: devel@edk2.groups.io CC: Vu Nguyen , Thang Nguyen , Chuong Tran , Phong Vo , Leif Lindholm , Michael D Kinney , Ard Biesheuvel , Nate DeSimone Subject: [edk2-platforms][PATCH v2 28/32] AmpereAltraPkg: Add configuration screen for Pcie Devices Date: Wed, 26 May 2021 17:07:20 +0700 Message-ID: <20210526100724.5359-30-nhi@os.amperecomputing.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210526100724.5359-1-nhi@os.amperecomputing.com> References: <20210526100724.5359-1-nhi@os.amperecomputing.com> X-Originating-IP: [118.69.219.201] X-ClientProxiedBy: HKAPR04CA0008.apcprd04.prod.outlook.com (2603:1096:203:d0::18) To DM6PR01MB5849.prod.exchangelabs.com (2603:10b6:5:205::20) Return-Path: nhi@os.amperecomputing.com MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (118.69.219.201) by HKAPR04CA0008.apcprd04.prod.outlook.com (2603:1096:203:d0::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Wed, 26 May 2021 10:12:37 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0e0c8847-4247-4ce2-de57-08d9202ecae8 X-MS-TrafficTypeDiagnostic: DM5PR01MB2426: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hNsyeztqtTpTEhZLvFSwyTRjzQbirv6DDmgZ9I9Z4AuGrTr9VO2M2Ri34d2EG0MVJ0y+E6A205emk8HXO0OV4xKyUSX3YGYEFjQiXwrjQlJwo6p6eo1/sW3RFHTZmJR21VDx6Nw8Zo6zt9x5I5mGhVttlrQhz0kAvHkCJ0dA7bXJAHDr/Zl5G6UfV2sShU6BTvvGOU1hh4KReO7jMkfrWWmirhPci9UiSJWG7voXYJeEOo54KJIcUIBDVycRG7q4AWSLoAXNzc0EcjsKYwS5Bi8f9MDDtOopBZA3wpmJMuBaUlgG799+DKuZ67WoMJyHiU2P8WtUffySKCJy3uobaXJJ3gkdfSu/eR0/Kvaw3py+YrwcdrCM6RsqEcMrYeWsdHXJ74W7yi3l77QeN/GA2OIGDp7MARVIZwqnwlvWGHadaTUpU7RhdneYR8aBLd1RfSdtqUDJxJ72iyf0ObLvuB4UCSZWZmBQjO2a8mwqr247Yvd4yR94OcS6eIMndVzkuTnTyRClgWSJx9myHDsWh/7Ebm8yg7jAaIybaikmVS2be1q5ZMTTDVfP7wEAKc5Pii5+OV2rktLXbfsfJfIg0rtKj4X4MTWA20x8qfX8HFaR7A1IlEXxAWZob97C8SRn4I1r7k5PFc7POyfbu1ciw0eqUn4OI/NbUI+LR5odTEwHW3CznltT2x4IwMuykB+Ne65TqEg2Nob3ijOM8ajxiw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR01MB5849.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(39850400004)(136003)(346002)(366004)(376002)(186003)(66476007)(6506007)(2616005)(6486002)(66946007)(52116002)(6916009)(16526019)(66574015)(38100700002)(38350700002)(1076003)(83380400001)(30864003)(66556008)(6512007)(956004)(316002)(478600001)(6666004)(4326008)(8676002)(5660300002)(26005)(86362001)(2906002)(8936002)(54906003)(290074003)(579004)(559001)(44824005);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData: =?us-ascii?Q?kZJUcUh6S4Iaus9PNuyCa4CnBxamCTaKt7Q6NPhIc1T6IbIBux8Xnk2b/YV7?= =?us-ascii?Q?x0UTbQTVJKKa9iNKVIsBWTYBiVV9bHbj9++WGhCdZhO+RfGr74GVrFx3Llkz?= =?us-ascii?Q?QkqTH1k1eWuOdviauQzpTVN83trclCqyYl8xtP6vlGJz/qTHN1D081VslQBc?= =?us-ascii?Q?zkIkT4l72bCAc1iFSLzaaxRTacmZhGirtiLw4r34S6sn59AjUFks55hq3URO?= =?us-ascii?Q?Z/Vhck3pf7pHOREVwDfVkpxyjR5WRiS++KxFSBRO3bbACYuaxNcJANqeoeTx?= =?us-ascii?Q?kVUg2YlrwRQiXfqdlA/VK1hstT8/JTYkGAshVFG7w6fHW80SjeWwigHDtpPT?= =?us-ascii?Q?l+7RIMdX8J3mNeatnFkZYWFIJEu48AmiaMJgjPYRjGLC5EhLGQREPfp5nUS3?= =?us-ascii?Q?viR7vzUFd98KlVfs1BXsmtbAvJVUxm8fwUHIrNUFcljxTipBJMjz7fMkuWS+?= =?us-ascii?Q?X/Q8kgI0TSIhjoH360X9RBljmfumPgJaNkMuuw7OWM27Od84WM7GCYhSUqWq?= =?us-ascii?Q?QlkOLZBYVSnkwnhyUG0noqeaChc0QW8fU52TtAAuWvSpqLSOu0lvlfjQjpAo?= =?us-ascii?Q?nQe2KiHKv8aQ4co6ItfMOKYl/8bfVYLBWKy5dKSE3Xjw3DaWaYhclCzwnP0t?= =?us-ascii?Q?3LztIeCCYBiJ+1dkZ0g6wUnjOCKa9MjZ01Xh04dlsLKxuD2x9IBUFYkavk9M?= =?us-ascii?Q?GmzmF0I5y6hJwJOoVw6yc2FcjEmjeQHjgOskDq2/G+um8IQAoIEPTh4RYA+n?= =?us-ascii?Q?rYIWEvOcm6fZjTB4TNaoW6oX3zy3xwOpafEbJ3g1HlYmXVcvEICSceiq2Zlm?= =?us-ascii?Q?w6Rdurkojw2wdm2/oKpfgtZqNwNLAWj8LTiuKbJQrIn83/Qpq0qjUHwIKmdY?= =?us-ascii?Q?6edS3Y3Cp4k0iARWjG8nQ02waFO09ceQZDkpBLGCW3rLAw5qqqulJluO3+87?= =?us-ascii?Q?340dRKgMfojGK5yifHSoykkHr3Nu8qqxQjz3n6djjUdwwboy0N8EQ4OPHExq?= =?us-ascii?Q?9mpeBWfuioDqKe2He7VwUT/cY9wOfZYEnb+AZQpYuOjMlROrAPQkc56QFKXl?= =?us-ascii?Q?U1QesIBDTFPRZciuaegoSTXkUhojVwAySRj+orVlXzMEccITsiYn2PKptDOT?= =?us-ascii?Q?8ObYgbP6hgeFzlQEMEGGNQRQzc/SsTwMwVnqV6zyTst3u3A6bwAAP7921TDv?= =?us-ascii?Q?2/a0/bUo49IDOT20leRcdorqTKF1fFiWDanhKJ8ikRKnhvvnY1IDufBqb2vY?= =?us-ascii?Q?FUiUIzhVYkh7ueW85W7LWBdmc3mTAo5BBujjcamFWs6AR188xraSioGFvD4R?= =?us-ascii?Q?6C5QqYxX9rcMA+RvVgN2ym3h?= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0e0c8847-4247-4ce2-de57-08d9202ecae8 X-MS-Exchange-CrossTenant-AuthSource: DM6PR01MB5849.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 May 2021 10:12:39.6627 (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: 42+0YdC91R5uan5W1dQAAbVdkgkdY+biMnzszQTstsk20O2d1AyQvZgRUPVDDhpCRmiPgZa888Y3pUQKGhnivubsCkBkf2xaIpgtA1NafUM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR01MB2426 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable From: Vu Nguyen This screen provide menu options to configure Max Payload and Max Read Request size for each PCIe device under Root Port. PCIe devices which attach to external switch are not supported yet. 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: Vu Nguyen --- Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec = | 3 + Platform/Ampere/JadePkg/Jade.dsc = | 1 + Platform/Ampere/JadePkg/Jade.fdf = | 1 + Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieDeviceConfig= Dxe.inf | 59 ++ Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/NVDataStruc.h = | 56 ++ Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieDeviceConfig= Dxe.h | 78 ++ Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieHelper.h = | 58 ++ Silicon/Ampere/AmpereAltraPkg/Include/Guid/PcieDeviceConfigHii.h = | 19 + Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/Vfr.vfr = | 50 + Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieDeviceConfig= Dxe.c | 1046 ++++++++++++++++++++ Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieHelper.c = | 191 ++++ Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieDeviceConfig= Dxe.uni | 24 + 12 files changed, 1586 insertions(+) diff --git a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec b/Silicon/Amp= ere/AmpereAltraPkg/AmpereAltraPkg.dec index 53930869f4f6..62e27c8b49b2 100644 --- a/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec +++ b/Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec @@ -59,6 +59,9 @@ [Guids] # GUID for the Watchdog HII configuration form gWatchdogConfigFormSetGuid =3D { 0xC3F8EC6E, 0x95EE, 0x460C, { 0xA4, 0= x8D, 0xEA, 0x54, 0x2F, 0xFF, 0x01, 0x61 } } =20 + # GUID for the Pcie Device HII configuration form + gPcieDeviceConfigFormSetGuid =3D { 0xEC7B1D21, 0x9167, 0x4B9D, { 0xF7, 0= x94, 0xCD, 0x1A, 0xEB, 0xBC, 0xB7, 0x59 } } + ## NVParam MM GUID gNVParamMmGuid =3D { 0xE4AC5024, 0x29BE, 0x4ADC, { 0x93, 0= x36, 0x87, 0xB5, 0xA0, 0x76, 0x23, 0x2D } } =20 diff --git a/Platform/Ampere/JadePkg/Jade.dsc b/Platform/Ampere/JadePkg/Jad= e.dsc index 391ff75e237c..9d787113e3b5 100755 --- a/Platform/Ampere/JadePkg/Jade.dsc +++ b/Platform/Ampere/JadePkg/Jade.dsc @@ -184,3 +184,4 @@ [Components.common] Silicon/Ampere/AmpereAltraPkg/Drivers/AcpiConfigDxe/AcpiConfigDxe.inf Silicon/Ampere/AmpereAltraPkg/Drivers/RasConfigDxe/RasConfigDxe.inf Silicon/Ampere/AmpereAltraPkg/Drivers/WatchdogConfigDxe/WatchdogConfigDx= e.inf + Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieDeviceConf= igDxe.inf diff --git a/Platform/Ampere/JadePkg/Jade.fdf b/Platform/Ampere/JadePkg/Jad= e.fdf index 431c9906e98e..b0c2894d00f8 100755 --- a/Platform/Ampere/JadePkg/Jade.fdf +++ b/Platform/Ampere/JadePkg/Jade.fdf @@ -359,5 +359,6 @@ [FV.FvMain] INF Silicon/Ampere/AmpereAltraPkg/Drivers/AcpiConfigDxe/AcpiConfigDxe.in= f INF Silicon/Ampere/AmpereAltraPkg/Drivers/RasConfigDxe/RasConfigDxe.inf INF Silicon/Ampere/AmpereAltraPkg/Drivers/WatchdogConfigDxe/WatchdogConf= igDxe.inf + INF Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieDevice= ConfigDxe.inf =20 !include Platform/Ampere/AmperePlatformPkg/FvRules.fdf.inc diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/Pcie= DeviceConfigDxe.inf b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfi= gDxe/PcieDeviceConfigDxe.inf new file mode 100644 index 000000000000..a04c79661842 --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieDeviceC= onfigDxe.inf @@ -0,0 +1,59 @@ +## @file +# +# Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
+# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x0001001B + BASE_NAME =3D PcieDeviceConfigDxe + FILE_GUID =3D 17E9369D-0A1B-45F4-A286-B1DED6D85D33 + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D PcieDeviceConfigEntryPoint + +[Sources.common] + NVDataStruc.h + PcieDeviceConfigDxe.c + PcieDeviceConfigDxe.h + PcieDeviceConfigDxe.uni + PcieHelper.c + PcieHelper.h + Vfr.vfr + +[Packages] + MdeModulePkg/MdeModulePkg.dec + MdePkg/MdePkg.dec + Silicon/Ampere/AmpereAltraPkg/AmpereAltraPkg.dec + Silicon/Ampere/AmpereSiliconPkg/AmpereSiliconPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + DevicePathLib + HiiLib + MemoryAllocationLib + PrintLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiLib + UefiRuntimeServicesTableLib + +[Protocols] + gEfiPciIoProtocolGuid + gEfiDevicePathProtocolGuid ## CONSUMES + gEfiHiiConfigRoutingProtocolGuid ## CONSUMES + gEfiHiiConfigAccessProtocolGuid ## PRODUCES + gEfiDevicePathToTextProtocolGuid + +[Guids] + gEfiIfrTianoGuid + gPcieDeviceConfigFormSetGuid + gPlatformManagerFormsetGuid + gPlatformManagerEntryEventGuid + +[Depex] + TRUE diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/NVDa= taStruc.h b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/NVDat= aStruc.h new file mode 100644 index 000000000000..fb168e495670 --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/NVDataStruc= .h @@ -0,0 +1,56 @@ +/** @file + + Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef NVDATASTRUC_H_ +#define NVDATASTRUC_H_ + +#include + +#define VARSTORE_NAME L"PcieDeviceConfigNVData" + +#define MAIN_FORM_ID 0x01 +#define DEVICE_FORM_ID 0x02 +#define VARSTORE_ID 0x03 + +#define MAIN_LABEL_UPDATE 0x21 +#define MAIN_LABEL_END 0x22 +#define DEVICE_LABEL_UPDATE 0x31 +#define DEVICE_LABEL_END 0x32 + +#define DEVICE_KEY 0x6000 +#define MPS_ONE_OF_KEY 0x7000 +#define MRR_ONE_OF_KEY 0x8000 + +#define MAX_DEVICE 40 + +#define DEFAULT_MPS 0x00 // Section 7.5.3.4 +#define DEFAULT_MRR 0x02 // Section 7.5.3.4 + +#define PCIE_ADD(Vid, Did, Seg, Bus, Dev) \ + (UINT64)(Vid) << 40 | (UINT64)(Did) << 24 | Seg << 16 | Bus << 8 |= Dev; + +#pragma pack(1) + +typedef struct { + UINT8 DEV; + UINT8 BUS; + UINT8 SEG; + UINT16 DID; + UINT16 VID; + UINT8 SlotId; +} SLOT_INFO; + +typedef struct { + UINT8 MPS[MAX_DEVICE]; + UINT8 MRR[MAX_DEVICE]; + UINT64 SlotInfo[MAX_DEVICE]; +} VARSTORE_DATA; + +#pragma pack() + +#endif // NVDATASTRUC_H_ diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/Pcie= DeviceConfigDxe.h b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigD= xe/PcieDeviceConfigDxe.h new file mode 100644 index 000000000000..40d7da1ef277 --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieDeviceC= onfigDxe.h @@ -0,0 +1,78 @@ +/** @file + + Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PCIE_DEVICE_CONFIG_H_ +#define PCIE_DEVICE_CONFIG_H_ + +#include + +#include +#include +#include +#include +#include +#include + +#include "NVDataStruc.h" + +#define MAX_STRING_SIZE 100 + +#define PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('P', 'E', 'D', 'C') +#define PRIVATE_DATA_FROM_THIS(a) \ + CR (a, PRIVATE_DATA, ConfigAccess, PRIVATE_DATA_SIGNATURE) + +#pragma pack(1) + +/// +/// HII specific Vendor Device Path definition. +/// +typedef struct { + VENDOR_DEVICE_PATH VendorDevicePath; + EFI_DEVICE_PATH_PROTOCOL End; +} HII_VENDOR_DEVICE_PATH; + +#pragma pack() + +// +// This is the generated IFR binary data for each formset defined in VFR. +// This data array is ready to be used as input of HiiAddPackages() to +// create a packagelist (which contains Form packages, String packages, et= c). +// +extern UINT8 VfrBin[]; + +// +// This is the generated String package data for all .UNI files. +// This data array is ready to be used as input of HiiAddPackages() to +// create a packagelist (which contains Form packages, String packages, et= c). +// +extern UINT8 PcieDeviceConfigDxeStrings[]; + +typedef struct { + UINTN Signature; + + EFI_HANDLE DriverHandle; + EFI_HII_HANDLE HiiHandle; + VARSTORE_DATA LastVarStoreConfig; + VARSTORE_DATA VarStoreConfig; + + // + // Consumed protocol + // + EFI_HII_DATABASE_PROTOCOL *HiiDatabase; + EFI_HII_STRING_PROTOCOL *HiiString; + EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; + EFI_CONFIG_KEYWORD_HANDLER_PROTOCOL *HiiKeywordHandler; + EFI_FORM_BROWSER2_PROTOCOL *FormBrowser2; + + // + // Produced protocol + // + EFI_HII_CONFIG_ACCESS_PROTOCOL ConfigAccess; +} PRIVATE_DATA; + +#endif // PCIE_DEVICE_CONFIG_H_ diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/Pcie= Helper.h b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieHe= lper.h new file mode 100644 index 000000000000..32787865119d --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieHelper.= h @@ -0,0 +1,58 @@ +/** @file + + Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PCIE_HELPER_H_ +#define PCIE_HELPER_H_ + +#define PCIE_MAX_PAYLOAD_MASK 0x07 +#define PCIE_CONTROL_MAX_PAYLOAD_OFF 5 +#define PCIE_MAX_READ_REQUEST_MASK 0x07 +#define PCIE_CONTROL_READ_REQUEST_OFF 12 + +#define PCI_EXPRESS_CAPABILITY_DEVICE_CAPABILITIES_REG 0x04 +#define PCI_EXPRESS_CAPABILITY_DEVICE_CONTROL_REG 0x08 + +#define FOR_EACH(Node, Tail, Type) \ + for (Node =3D Tail->Type; Node !=3D NULL; Node =3D Node->Type) + +struct _PCIE_NODE { + EFI_PCI_IO_PROTOCOL *PciIo; + UINT8 MaxMps; + UINT8 PcieCapOffset; + UINT16 Vid; + UINT16 Did; + UINT8 Seg; + UINT8 Bus; + UINT8 Dev; + UINT8 Fun; + struct _PCIE_NODE *Parent; + struct _PCIE_NODE *Brother; +}; + +typedef struct _PCIE_NODE PCIE_NODE; + +EFI_STATUS +WriteMps ( + PCIE_NODE *Node, + UINT8 Value + ); + +EFI_STATUS +WriteMrr ( + PCIE_NODE *Node, + UINT8 Value + ); + +EFI_STATUS +FindCapabilityPtr ( + IN EFI_PCI_IO_PROTOCOL *PciIo, + IN UINT8 CapabilityId, + OUT UINT8 *CapabilityPtr + ); + +#endif // PCIE_HELPER_H_ diff --git a/Silicon/Ampere/AmpereAltraPkg/Include/Guid/PcieDeviceConfigHii= .h b/Silicon/Ampere/AmpereAltraPkg/Include/Guid/PcieDeviceConfigHii.h new file mode 100644 index 000000000000..04b950abd49e --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Include/Guid/PcieDeviceConfigHii.h @@ -0,0 +1,19 @@ +/** @file + + Copyright (c) 2020 - 2021, Ampere Computing LLC. All rights reserved. + + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#ifndef PCIE_DEVICE_CONFIG_HII_H_ +#define PCIE_DEVICE_CONFIG_HII_H_ + +#define PCIE_DEVICE_CONFIG_FORMSET_GUID \ + { \ + 0xEC7B1D21, 0x9167, 0x4B9D, { 0xF7, 0x94, 0xCD, 0x1A, 0xEB, 0xBC, 0xB7= , 0x59 } \ + } + +extern EFI_GUID gPcieDeviceConfigFormSetGuid; + +#endif /* PCIE_DEVICE_CONFIG_HII_H_ */ diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/Vfr.= vfr b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/Vfr.vfr new file mode 100644 index 000000000000..b5b16802b23e --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/Vfr.vfr @@ -0,0 +1,50 @@ +/** @file + + Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include "NVDataStruc.h" + +formset + guid =3D PCIE_DEVICE_CONFIG_FORMSET_GUID, + title =3D STRING_TOKEN(STR_PCIE_DEVICE_CONFIG_FORM), + help =3D STRING_TOKEN(STR_PCIE_DEVICE_CONFIG_HELP), + classguid =3D gPlatformManagerFormsetGuid, + + // + // Define a variable Storage + // + varstore VARSTORE_DATA, + varid =3D VARSTORE_ID, + name =3D PcieDeviceConfigNVData, + guid =3D PCIE_DEVICE_CONFIG_FORMSET_GUID; + + form + formid =3D MAIN_FORM_ID, + title =3D STRING_TOKEN(STR_PCIE_DEVICE_CONFIG_FORM); + + subtitle text =3D STRING_TOKEN(STR_PCIE_DEVICE_CONFIG_FORM); + + label MAIN_LABEL_UPDATE; + // dynamic content here + label MAIN_LABEL_END; + + endform; + + form + formid =3D DEVICE_FORM_ID, + title =3D STRING_TOKEN(STR_DEVICE_FORM); + + subtitle text =3D STRING_TOKEN(STR_DEVICE_FORM); + + label DEVICE_LABEL_UPDATE; + // dynamic content here + label DEVICE_LABEL_END; + + endform; + +endformset; diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/Pcie= DeviceConfigDxe.c b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigD= xe/PcieDeviceConfigDxe.c new file mode 100644 index 000000000000..a04f789530c0 --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieDeviceC= onfigDxe.c @@ -0,0 +1,1046 @@ +/** @file + + Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "PcieDeviceConfigDxe.h" +#include "PcieHelper.h" + +VOID *mPciProtocolNotifyRegistration; +CHAR16 *mVariableName =3D VARSTORE_NAME; +PCIE_NODE *mDeviceBuf[MAX_DEVICE] =3D {NULL}; + +HII_VENDOR_DEVICE_PATH mHiiVendorDevicePath =3D { + { + { + HARDWARE_DEVICE_PATH, + HW_VENDOR_DP, + { + (UINT8)(sizeof (VENDOR_DEVICE_PATH)), + (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8) + } + }, + PCIE_DEVICE_CONFIG_FORMSET_GUID + }, + { + END_DEVICE_PATH_TYPE, + END_ENTIRE_DEVICE_PATH_SUBTYPE, + { + (UINT8)(END_DEVICE_PATH_LENGTH), + (UINT8)((END_DEVICE_PATH_LENGTH) >> 8) + } + } +}; + +VOID +FlushDeviceData ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + PCIE_NODE *Node; + PRIVATE_DATA *PrivateData; + UINT8 Index; + VARSTORE_DATA *LastVarStoreConfig; + VARSTORE_DATA *VarStoreConfig; + + PrivateData =3D (PRIVATE_DATA *)Context; + LastVarStoreConfig =3D &PrivateData->LastVarStoreConfig; + VarStoreConfig =3D &PrivateData->VarStoreConfig; + + // + // If config has changed, update NVRAM + // + if (CompareMem (VarStoreConfig, LastVarStoreConfig, sizeof (VARSTORE_DAT= A)) !=3D 0) { + DEBUG ((DEBUG_INFO, "%a Update Device Config Variable\n", __FUNCTION__= )); + Status =3D gRT->SetVariable ( + mVariableName, + &gPcieDeviceConfigFormSetGuid, + EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_A= CCESS, + sizeof (VARSTORE_DATA), + VarStoreConfig + ); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: Failed to set variable status %r", + __FUNCTION__, + Status + )); + return; + } + } + + // Iterate through the list, then write corresponding MPS MRR + for (Index =3D 0; Index < MAX_DEVICE; Index++) { + if (mDeviceBuf[Index] =3D=3D NULL) { + continue; + } + + // Write MPS value + WriteMps (mDeviceBuf[Index], VarStoreConfig->MPS[Index]); + + FOR_EACH (Node, mDeviceBuf[Index], Parent) { + WriteMps (Node, VarStoreConfig->MPS[Index]); + } + + FOR_EACH (Node, mDeviceBuf[Index], Brother) { + WriteMps (Node, VarStoreConfig->MPS[Index]); + } + + // Write MRR value + // FIXME: No need to update MRR of parent node + WriteMrr (mDeviceBuf[Index], VarStoreConfig->MRR[Index]); + + FOR_EACH (Node, mDeviceBuf[Index], Brother) { + WriteMrr (Node, VarStoreConfig->MRR[Index]); + } + } + + gBS->CloseEvent (Event); +} + +EFI_STATUS +UpdateDeviceForm ( + UINT8 Index, + PRIVATE_DATA *PrivateData + ) +{ + CHAR16 Str[MAX_STRING_SIZE]; + UINT8 MaxMps; + + VOID *StartOpCodeHandle; + EFI_IFR_GUID_LABEL *StartLabel; + VOID *EndOpCodeHandle; + EFI_IFR_GUID_LABEL *EndLabel; + VOID *MpsOpCodeHandle; + VOID *MrrOpCodeHandle; + PCIE_NODE *Node; + + if (mDeviceBuf[Index] =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + MaxMps =3D mDeviceBuf[Index]->MaxMps; + FOR_EACH (Node, mDeviceBuf[Index], Parent) { + if (Node->MaxMps < MaxMps) { + MaxMps =3D Node->MaxMps; + } + } + + UnicodeSPrint ( + Str, + sizeof (Str), + L"PCIe Device 0x%04x:0x%04x", + mDeviceBuf[Index]->Vid, + mDeviceBuf[Index]->Did + ); + + HiiSetString ( + PrivateData->HiiHandle, + STRING_TOKEN (STR_DEVICE_FORM), + Str, + NULL + ); + + // + // Initialize the container for dynamic opcodes + // + StartOpCodeHandle =3D HiiAllocateOpCodeHandle (); + ASSERT (StartOpCodeHandle !=3D NULL); + + EndOpCodeHandle =3D HiiAllocateOpCodeHandle (); + ASSERT (EndOpCodeHandle !=3D NULL); + + // + // Create Hii Extend Label OpCode as the start opcode + // + StartLabel =3D (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode ( + StartOpCodeHandle, + &gEfiIfrTianoGuid, + NULL, + sizeof (EFI_IFR_GUID_LABEL) + ); + StartLabel->ExtendOpCode =3D EFI_IFR_EXTEND_OP_LABEL; + StartLabel->Number =3D DEVICE_LABEL_UPDATE; + + // + // Create Hii Extend Label OpCode as the end opcode + // + EndLabel =3D (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode ( + EndOpCodeHandle, + &gEfiIfrTianoGuid, + NULL, + sizeof (EFI_IFR_GUID_LABEL) + ); + EndLabel->ExtendOpCode =3D EFI_IFR_EXTEND_OP_LABEL; + EndLabel->Number =3D DEVICE_LABEL_END; + + // Create Option OpCode for MPS selection + MpsOpCodeHandle =3D HiiAllocateOpCodeHandle (); + ASSERT (MpsOpCodeHandle !=3D NULL); + + switch (MaxMps) { + case 5: + HiiCreateOneOfOptionOpCode ( + MpsOpCodeHandle, + STRING_TOKEN (STR_4096), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 5 + ); + + case 4: + HiiCreateOneOfOptionOpCode ( + MpsOpCodeHandle, + STRING_TOKEN (STR_2048), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 4 + ); + + case 3: + HiiCreateOneOfOptionOpCode ( + MpsOpCodeHandle, + STRING_TOKEN (STR_1024), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 3 + ); + + case 2: + HiiCreateOneOfOptionOpCode ( + MpsOpCodeHandle, + STRING_TOKEN (STR_512), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 2 + ); + + case 1: + HiiCreateOneOfOptionOpCode ( + MpsOpCodeHandle, + STRING_TOKEN (STR_256), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 1 + ); + + case 0: + HiiCreateOneOfOptionOpCode ( + MpsOpCodeHandle, + STRING_TOKEN (STR_128), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 0 + ); + } + + // Create MPS OneOf + HiiCreateOneOfOpCode ( + StartOpCodeHandle, // Container for dynamic created opc= odes + (MPS_ONE_OF_KEY + Index), // Question ID (or call it "key") + VARSTORE_ID, // VarStore ID + Index, // Offset in Buffer Storage + STRING_TOKEN (STR_PCIE_MPS), // Question prompt text + STRING_TOKEN (STR_PCIE_MPS_HELP), // Question help text + EFI_IFR_FLAG_CALLBACK, // Question flag + EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value + MpsOpCodeHandle, // Option Opcode list + NULL // Default Opcode is NULl + ); + + // Create Option OpCode for MRR selection + MrrOpCodeHandle =3D HiiAllocateOpCodeHandle (); + ASSERT (MrrOpCodeHandle !=3D NULL); + + HiiCreateOneOfOptionOpCode ( + MrrOpCodeHandle, + STRING_TOKEN (STR_4096), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 5 + ); + + HiiCreateOneOfOptionOpCode ( + MrrOpCodeHandle, + STRING_TOKEN (STR_2048), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 4 + ); + + HiiCreateOneOfOptionOpCode ( + MrrOpCodeHandle, + STRING_TOKEN (STR_1024), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 3 + ); + + HiiCreateOneOfOptionOpCode ( + MrrOpCodeHandle, + STRING_TOKEN (STR_512), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 2 + ); + + HiiCreateOneOfOptionOpCode ( + MrrOpCodeHandle, + STRING_TOKEN (STR_256), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 1 + ); + + HiiCreateOneOfOptionOpCode ( + MrrOpCodeHandle, + STRING_TOKEN (STR_128), + 0, + EFI_IFR_NUMERIC_SIZE_1, + 0 + ); + + // Create MRR OneOf + HiiCreateOneOfOpCode ( + StartOpCodeHandle, // Container for dynamic created opc= odes + (MRR_ONE_OF_KEY + Index), // Question ID (or call it "key") + VARSTORE_ID, // VarStore ID + MAX_DEVICE + Index, // Offset in Buffer Storage + STRING_TOKEN (STR_PCIE_MRR), // Question prompt text + STRING_TOKEN (STR_PCIE_MRR_HELP), // Question help text + EFI_IFR_FLAG_CALLBACK, // Question flag + EFI_IFR_NUMERIC_SIZE_1, // Data type of Question Value + MrrOpCodeHandle, // Option Opcode list + NULL // Default Opcode is NULl + ); + + HiiUpdateForm ( + PrivateData->HiiHandle, // HII handle + &gPcieDeviceConfigFormSetGuid, // Formset GUID + DEVICE_FORM_ID, // Form ID + StartOpCodeHandle, // Label for where to insert opcodes + EndOpCodeHandle // Insert data + ); + + HiiFreeOpCodeHandle (StartOpCodeHandle); + HiiFreeOpCodeHandle (EndOpCodeHandle); + HiiFreeOpCodeHandle (MpsOpCodeHandle); + HiiFreeOpCodeHandle (MrrOpCodeHandle); + return EFI_SUCCESS; +} + +VOID +OnPciIoProtocolNotify ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_PCI_IO_PROTOCOL *PciIo; + EFI_STATUS Status; + EFI_HANDLE HandleBuffer; + PCI_TYPE00 Pci; + + UINTN BufferSize; + UINTN PciBusNumber; + UINTN PciDeviceNumber; + UINTN PciFunctionNumber; + UINTN PciSegment; + + UINT8 Idx; + UINT8 CapabilityPtr; + UINT16 TmpValue; + UINT64 SlotInfo; + + PCIE_NODE *Node; + PRIVATE_DATA *PrivateData; + STATIC PCIE_NODE *LastNode; + STATIC UINT8 Index; + STATIC UINT8 LastBus; + + VARSTORE_DATA *LastVarStoreConfig; + VARSTORE_DATA *VarStoreConfig; + + PrivateData =3D (PRIVATE_DATA *)Context; + LastVarStoreConfig =3D &PrivateData->LastVarStoreConfig; + VarStoreConfig =3D &PrivateData->VarStoreConfig; + + while (TRUE) { + BufferSize =3D sizeof (EFI_HANDLE); + Status =3D gBS->LocateHandle ( + ByRegisterNotify, + NULL, + mPciProtocolNotifyRegistration, + &BufferSize, + &HandleBuffer + ); + if (EFI_ERROR (Status)) { + break; + } + + Status =3D gBS->HandleProtocol ( + HandleBuffer, + &gEfiPciIoProtocolGuid, + (VOID **)&PciIo + ); + if (EFI_ERROR (Status)) { + break; + } + + // Get device bus location + Status =3D PciIo->GetLocation ( + PciIo, + &PciSegment, + &PciBusNumber, + &PciDeviceNumber, + &PciFunctionNumber + ); + if (EFI_ERROR (Status) || + ((PciBusNumber =3D=3D 0) && (PciDeviceNumber =3D=3D 0))) + { + // Filter out Host Bridge + DEBUG ((DEBUG_INFO, "Filter out Host Bridge %x\n", PciSegment)); + continue; + } + + DEBUG (( + DEBUG_INFO, + ">> Dev 0x%04x:0x%02x:0x%02x:0x%02x\n", + PciSegment, + PciBusNumber, + PciDeviceNumber, + PciFunctionNumber + )); + + Status =3D FindCapabilityPtr (PciIo, EFI_PCI_CAPABILITY_ID_PCIEXP, &Ca= pabilityPtr); + if (EFI_ERROR (Status)) { + DEBUG (( + DEBUG_ERROR, + "%a: PCI Express Capability not found\n", + __FUNCTION__ + )); + continue; + } + + // Get Device's max MPS support + Status =3D PciIo->Pci.Read ( + PciIo, + EfiPciIoWidthUint16, + CapabilityPtr + PCI_EXPRESS_CAPABILITY_DEVICE_CA= PABILITIES_REG, + 1, + &TmpValue + ); + if (EFI_ERROR (Status)) { + continue; + } + + // Read device's VID:PID + Status =3D PciIo->Pci.Read ( + PciIo, + EfiPciIoWidthUint32, + 0, + sizeof (Pci) / sizeof (UINT32), + &Pci + ); + if (EFI_ERROR (Status)) { + continue; + } + DEBUG (( + DEBUG_INFO, + "VendorId 0x%04x - DeviceId 0x%04x\n", + Pci.Hdr.VendorId, + Pci.Hdr.DeviceId + )); + + Node =3D AllocateZeroPool (sizeof (*Node)); + Node->MaxMps =3D TmpValue & PCIE_MAX_PAYLOAD_MASK; + Node->PcieCapOffset =3D CapabilityPtr; + Node->PciIo =3D PciIo; + Node->Seg =3D PciSegment; + Node->Bus =3D PciBusNumber; + Node->Dev =3D PciDeviceNumber; + Node->Fun =3D PciFunctionNumber; + Node->Vid =3D Pci.Hdr.VendorId; + Node->Did =3D Pci.Hdr.DeviceId; + SlotInfo =3D PCIE_ADD (Node->Vid, Node->Did, Node->Seg, Node->Bus, Nod= e->Dev); + + // Presume child devices were registered follow root port + if (PciBusNumber !=3D 0) { + if (LastBus =3D=3D 0) { + Node->Parent =3D LastNode; + mDeviceBuf[Index] =3D Node; + + VarStoreConfig->MPS[Index] =3D DEFAULT_MPS; + VarStoreConfig->MRR[Index] =3D DEFAULT_MRR; + VarStoreConfig->SlotInfo[Index] =3D SlotInfo; + + // Retrieve setting from previous variable + for (Idx =3D 0; Idx < MAX_DEVICE; Idx++) { + if (SlotInfo =3D=3D LastVarStoreConfig->SlotInfo[Idx]) { + VarStoreConfig->MPS[Index] =3D LastVarStoreConfig->MPS[Idx]; + VarStoreConfig->MRR[Index] =3D LastVarStoreConfig->MRR[Idx]; + break; + } + } + + Index++; + } else if (PciBusNumber =3D=3D LastBus) { + LastNode->Brother =3D Node; + } else { + // Ignore devices don't stay under root port + continue; + } + } + + LastBus =3D PciBusNumber; + LastNode =3D Node; + } +} + +VOID +UpdateMainForm ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + UINTN Index; + EFI_STRING_ID StrId; + CHAR16 Str[MAX_STRING_SIZE]; + VOID *StartOpCodeHandle; + EFI_IFR_GUID_LABEL *StartLabel; + VOID *EndOpCodeHandle; + EFI_IFR_GUID_LABEL *EndLabel; + PRIVATE_DATA *PrivateData; + + DEBUG ((DEBUG_INFO, "%a Entry ...\n", __FUNCTION__)); + + PrivateData =3D (PRIVATE_DATA *)Context; + + // + // Initialize the container for dynamic opcodes + // + StartOpCodeHandle =3D HiiAllocateOpCodeHandle (); + ASSERT (StartOpCodeHandle !=3D NULL); + + EndOpCodeHandle =3D HiiAllocateOpCodeHandle (); + ASSERT (EndOpCodeHandle !=3D NULL); + + // + // Create Hii Extend Label OpCode as the start opcode + // + StartLabel =3D (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode ( + StartOpCodeHandle, + &gEfiIfrTianoGuid, + NULL, + sizeof (EFI_IFR_GUID_LABEL) + ); + StartLabel->ExtendOpCode =3D EFI_IFR_EXTEND_OP_LABEL; + StartLabel->Number =3D MAIN_LABEL_UPDATE; + + // + // Create Hii Extend Label OpCode as the end opcode + // + EndLabel =3D (EFI_IFR_GUID_LABEL *)HiiCreateGuidOpCode ( + EndOpCodeHandle, + &gEfiIfrTianoGuid, + NULL, + sizeof (EFI_IFR_GUID_LABEL) + ); + EndLabel->ExtendOpCode =3D EFI_IFR_EXTEND_OP_LABEL; + EndLabel->Number =3D MAIN_LABEL_END; + + for (Index =3D 0; Index < MAX_DEVICE; Index++) { + if (mDeviceBuf[Index] =3D=3D NULL) { + break; + } + DEBUG ((DEBUG_INFO, ">> Add item %d\n", Index)); + + // TODO: convert and store in SlotID ex:SystemSlot(seg, bus, dev) + UnicodeSPrint ( + Str, + sizeof (Str), + L"PCIe Device 0x%04x:0x%04x - %04x:%02x:%02x", + mDeviceBuf[Index]->Vid, + mDeviceBuf[Index]->Did, + mDeviceBuf[Index]->Seg, + mDeviceBuf[Index]->Bus, + mDeviceBuf[Index]->Dev + ); + + StrId =3D HiiSetString (PrivateData->HiiHandle, 0, Str, NULL); + + // + // Create a Goto OpCode to device configuration + // + HiiCreateGotoOpCode ( + StartOpCodeHandle, // Container for dynamic create= d opcodes + DEVICE_FORM_ID, // Target Form ID + StrId, // Prompt text + STRING_TOKEN (STR_DEVICE_GOTO_HELP), // Help text + EFI_IFR_FLAG_CALLBACK, // Question flag + (DEVICE_KEY + Index) // Question ID + ); + } + + HiiUpdateForm ( + PrivateData->HiiHandle, // HII handle + &gPcieDeviceConfigFormSetGuid, // Formset GUID + MAIN_FORM_ID, // Form ID + StartOpCodeHandle, // Label for where to insert opcodes + EndOpCodeHandle // Insert data + ); + + HiiFreeOpCodeHandle (StartOpCodeHandle); + HiiFreeOpCodeHandle (EndOpCodeHandle); + + gBS->CloseEvent (Event); +} + +EFI_STATUS +EFIAPI +ExtractConfig ( + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN CONST EFI_STRING Request, + OUT EFI_STRING *Progress, + OUT EFI_STRING *Results + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + PRIVATE_DATA *PrivateData; + EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; + EFI_STRING ConfigRequest; + EFI_STRING ConfigRequestHdr; + UINTN Size; + CHAR16 *StrPointer; + BOOLEAN AllocatedRequest; + VARSTORE_DATA *VarStoreConfig; + + if (Progress =3D=3D NULL || Results =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + // + // Initialize the local variables. + // + ConfigRequestHdr =3D NULL; + ConfigRequest =3D NULL; + Size =3D 0; + *Progress =3D Request; + AllocatedRequest =3D FALSE; + + PrivateData =3D PRIVATE_DATA_FROM_THIS (This); + HiiConfigRouting =3D PrivateData->HiiConfigRouting; + VarStoreConfig =3D &PrivateData->VarStoreConfig; + ASSERT (VarStoreConfig !=3D NULL); + + BufferSize =3D sizeof (VARSTORE_DATA); + + if (Request =3D=3D NULL) { + // + // Request is set to NULL, construct full request string. + // + + // + // Allocate and fill a buffer large enough to hold the tem= plate + // followed by "&OFFSET=3D0&WIDTH=3DWWWWWWWWWWWWWWWW" followed by a + // Null-terminator + // + ConfigRequestHdr =3D HiiConstructConfigHdr ( + &gPcieDeviceConfigFormSetGuid, + mVariableName, + PrivateData->DriverHandle + ); + if (ConfigRequestHdr =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + Size =3D (StrLen (ConfigRequestHdr) + 32 + 1) * sizeof (CHAR16); + ConfigRequest =3D AllocateZeroPool (Size); + ASSERT (ConfigRequest !=3D NULL); + AllocatedRequest =3D TRUE; + UnicodeSPrint ( + ConfigRequest, + Size, + L"%s&OFFSET=3D0&WIDTH=3D%016LX", + ConfigRequestHdr, + (UINT64)BufferSize + ); + FreePool (ConfigRequestHdr); + ConfigRequestHdr =3D NULL; + } else { + // + // Check routing data in . + // Note: if only one Storage is used, then this checking could be skip= ped. + // + if (!HiiIsConfigHdrMatch (Request, &gPcieDeviceConfigFormSetGuid, NULL= )) { + return EFI_NOT_FOUND; + } + // + // Set Request to the unified request string. + // + ConfigRequest =3D Request; + + // + // Check whether Request includes Request Element. + // + if (StrStr (Request, L"OFFSET") =3D=3D NULL) { + // + // Check Request Element does exist in Request String + // + StrPointer =3D StrStr (Request, L"PATH"); + if (StrPointer =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + if (StrStr (StrPointer, L"&") =3D=3D NULL) { + Size =3D (StrLen (Request) + 32 + 1) * sizeof (CHAR16); + ConfigRequest =3D AllocateZeroPool (Size); + ASSERT (ConfigRequest !=3D NULL); + AllocatedRequest =3D TRUE; + UnicodeSPrint ( + ConfigRequest, + Size, + L"%s&OFFSET=3D0&WIDTH=3D%016LX", + Request, + (UINT64)BufferSize + ); + } + } + } + // + // Check if requesting Name/Value storage + // + if (StrStr (ConfigRequest, L"OFFSET") =3D=3D NULL) { + // + // Don't have any Name/Value storage names + // + Status =3D EFI_SUCCESS; + } else { + // + // Convert buffer data to by helper function BlockToConfi= g() + // + Status =3D HiiConfigRouting->BlockToConfig ( + HiiConfigRouting, + ConfigRequest, + (UINT8 *)VarStoreConfig, + BufferSize, + Results, + Progress + ); + } + // + // Free the allocated config request string. + // + if (AllocatedRequest) { + FreePool (ConfigRequest); + } + if (ConfigRequestHdr !=3D NULL) { + FreePool (ConfigRequestHdr); + } + // + // Set Progress string to the original request string. + // + if (Request =3D=3D NULL) { + *Progress =3D NULL; + } else if (StrStr (Request, L"OFFSET") =3D=3D NULL) { + *Progress =3D Request + StrLen (Request); + } + return Status; +} + +/** + This function processes the results of changes in configuration. + @param This Points to the EFI_HII_CONFIG_ACCESS_PROTO= COL. + @param Configuration A null-terminated Unicode string in + format. + @param Progress A pointer to a string filled in with the = offset of + the most recent '&' before the first fail= ing + name/value pair (or the beginning of the = string if + the failure is in the first name/value pa= ir) or + the terminating NULL if all was successfu= l. + @retval EFI_SUCCESS The Results is processed successfully. + @retval EFI_INVALID_PARAMETER Configuration is NULL. + @retval EFI_NOT_FOUND Routing data doesn't match any storage in= this + driver. +**/ +EFI_STATUS +EFIAPI +RouteConfig ( + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN CONST EFI_STRING Configuration, + OUT EFI_STRING *Progress + ) +{ + EFI_STATUS Status; + UINTN BufferSize; + PRIVATE_DATA *PrivateData; + EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; + VARSTORE_DATA *VarStoreConfig; + + if (Configuration =3D=3D NULL || Progress =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + PrivateData =3D PRIVATE_DATA_FROM_THIS (This); + HiiConfigRouting =3D PrivateData->HiiConfigRouting; + *Progress =3D Configuration; + VarStoreConfig =3D &PrivateData->VarStoreConfig; + ASSERT (VarStoreConfig !=3D NULL); + + // + // Check routing data in . + // Note: if only one Storage is used, then this checking could be skippe= d. + // + if (!HiiIsConfigHdrMatch ( + Configuration, + &gPcieDeviceConfigFormSetGuid, + NULL + )) + { + return EFI_NOT_FOUND; + } + + // + // Check if configuring Name/Value storage + // + if (StrStr (Configuration, L"OFFSET") =3D=3D NULL) { + // + // Don't have any Name/Value storage names + // + return EFI_SUCCESS; + } + // + // Convert to buffer data by helper function ConfigToBlock(= ) + // + BufferSize =3D sizeof (VARSTORE_DATA); + Status =3D HiiConfigRouting->ConfigToBlock ( + HiiConfigRouting, + Configuration, + (UINT8 *)VarStoreConfig, + &BufferSize, + Progress + ); + + return Status; +} + +/** + This function processes the results of changes in configuration. + @param This Points to the EFI_HII_CONFIG_ACCESS_PROTO= COL. + @param Action Specifies the type of action taken by the= browser. + @param QuestionId A unique value which is sent to the origi= nal + exporting driver so that it can identify = the type + of data to expect. + @param Type The type of value for the question. + @param Value A pointer to the data being sent to the o= riginal + exporting driver. + @param ActionRequest On return, points to the action requested= by the + callback function. + @retval EFI_SUCCESS The callback successfully handled the act= ion. + @retval EFI_INVALID_PARAMETER Configuration is NULL. + @retval EFI_UNSUPPORTED The specified Action is not supported by = the + callback. +**/ +EFI_STATUS +EFIAPI +DriverCallback ( + IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, + IN EFI_BROWSER_ACTION Action, + IN EFI_QUESTION_ID QuestionId, + IN UINT8 Type, + IN EFI_IFR_TYPE_VALUE *Value, + OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest + ) +{ + EFI_STATUS Status; + PRIVATE_DATA *PrivateData; + + if (((Value =3D=3D NULL) && + (Action !=3D EFI_BROWSER_ACTION_FORM_OPEN) && + (Action !=3D EFI_BROWSER_ACTION_FORM_CLOSE)) || + (ActionRequest =3D=3D NULL)) + { + return EFI_INVALID_PARAMETER; + } + + PrivateData =3D PRIVATE_DATA_FROM_THIS (This); + + switch (Action) { + case EFI_BROWSER_ACTION_CHANGING: + if ((QuestionId >=3D DEVICE_KEY) + & (QuestionId <=3D (DEVICE_KEY + MAX_DEVICE))) + { + Status =3D UpdateDeviceForm (QuestionId - DEVICE_KEY, PrivateData); + if (EFI_ERROR (Status)) { + return Status; + } + } + break; + + case EFI_BROWSER_ACTION_DEFAULT_STANDARD: + case EFI_BROWSER_ACTION_DEFAULT_MANUFACTURING: + if ((QuestionId >=3D MPS_ONE_OF_KEY) + & (QuestionId <=3D (MPS_ONE_OF_KEY + MAX_DEVICE))) + { + Value->u8 =3D DEFAULT_MPS; + } + + if ((QuestionId >=3D MRR_ONE_OF_KEY) + & (QuestionId <=3D (MRR_ONE_OF_KEY + MAX_DEVICE))) + { + Value->u8 =3D DEFAULT_MRR; + } + break; + + case EFI_BROWSER_ACTION_SUBMITTED: + break; + } + + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI +PcieDeviceConfigEntryPoint ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_HANDLE DriverHandle; + EFI_HII_CONFIG_ROUTING_PROTOCOL *HiiConfigRouting; + EFI_HII_HANDLE HiiHandle; + EFI_STATUS Status; + EFI_EVENT PlatformUiEntryEvent; + EFI_EVENT FlushDeviceEvent; + EFI_EVENT PciProtocolNotifyEvent; + PRIVATE_DATA *PrivateData; + UINTN BufferSize; + + DriverHandle =3D NULL; + PrivateData =3D AllocateZeroPool (sizeof (*PrivateData)); + if (PrivateData =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + PrivateData->Signature =3D PRIVATE_DATA_SIGNATURE; + + PrivateData->ConfigAccess.ExtractConfig =3D ExtractConfig; + PrivateData->ConfigAccess.RouteConfig =3D RouteConfig; + PrivateData->ConfigAccess.Callback =3D DriverCallback; + + // + // Locate ConfigRouting protocol + // + Status =3D gBS->LocateProtocol ( + &gEfiHiiConfigRoutingProtocolGuid, + NULL, + (VOID **)&HiiConfigRouting + ); + if (EFI_ERROR (Status)) { + goto Exit; + } + PrivateData->HiiConfigRouting =3D HiiConfigRouting; + + Status =3D gBS->InstallMultipleProtocolInterfaces ( + &DriverHandle, + &gEfiDevicePathProtocolGuid, + &mHiiVendorDevicePath, + &gEfiHiiConfigAccessProtocolGuid, + &PrivateData->ConfigAccess, + NULL + ); + if (EFI_ERROR (Status)) { + goto Exit; + } + + PrivateData->DriverHandle =3D DriverHandle; + + // + // Publish our HII data + // + HiiHandle =3D HiiAddPackages ( + &gPcieDeviceConfigFormSetGuid, + DriverHandle, + PcieDeviceConfigDxeStrings, + VfrBin, + NULL + ); + if (HiiHandle =3D=3D NULL) { + Status =3D EFI_OUT_OF_RESOURCES; + goto Exit; + } + PrivateData->HiiHandle =3D HiiHandle; + + // Event to fixup screen + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + UpdateMainForm, + (VOID *)PrivateData, + &gPlatformManagerEntryEventGuid, + &PlatformUiEntryEvent + ); + if (EFI_ERROR (Status)) { + goto Exit; + } + + // Event to collect PciIo + PciProtocolNotifyEvent =3D EfiCreateProtocolNotifyEvent ( + &gEfiPciIoProtocolGuid, + TPL_CALLBACK, + OnPciIoProtocolNotify, + (VOID *)PrivateData, + &mPciProtocolNotifyRegistration + ); + ASSERT (PciProtocolNotifyEvent !=3D NULL); + + // Event to flush device data + Status =3D gBS->CreateEventEx ( + EVT_NOTIFY_SIGNAL, + TPL_CALLBACK, + FlushDeviceData, + (VOID *)PrivateData, + &gEfiEventReadyToBootGuid, + &FlushDeviceEvent + ); + if (EFI_ERROR (Status)) { + goto Exit; + } + + // Verify varstore + BufferSize =3D sizeof (VARSTORE_DATA); + Status =3D gRT->GetVariable ( + mVariableName, + &gPcieDeviceConfigFormSetGuid, + NULL, + &BufferSize, + &PrivateData->LastVarStoreConfig + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: Last config is not found\n", __FUNCTION__)); + } + + return EFI_SUCCESS; + +Exit: + FreePool (PrivateData); + return Status; +} diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/Pcie= Helper.c b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieHe= lper.c new file mode 100644 index 000000000000..b4e918e2b786 --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieHelper.= c @@ -0,0 +1,191 @@ +/** @file + + Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
+ + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include + +#include +#include +#include +#include + +#include "PcieDeviceConfigDxe.h" +#include "PcieHelper.h" + +EFI_STATUS +FindCapabilityPtr ( + IN EFI_PCI_IO_PROTOCOL *PciIo, + IN UINT8 CapabilityId, + OUT UINT8 *CapabilityPtr + ) +{ + EFI_STATUS Status; + UINT8 NextPtr; + UINT16 TmpValue; + + ASSERT (PciIo !=3D NULL); + + // + // Get pointer to first PCI Capability header + // + Status =3D PciIo->Pci.Read ( + PciIo, + EfiPciIoWidthUint8, + PCI_CAPBILITY_POINTER_OFFSET, + 1, + &NextPtr + ); + if (EFI_ERROR (Status)) { + goto Exit; + } + + while (TRUE) { + if (NextPtr =3D=3D 0x00) { + Status =3D EFI_NOT_FOUND; + goto Exit; + } + + // + // Retrieve PCI Capability header + // + Status =3D PciIo->Pci.Read ( + PciIo, + EfiPciIoWidthUint16, + NextPtr, + 1, + &TmpValue + ); + if (EFI_ERROR (Status)) { + goto Exit; + } + + if ((TmpValue & 0xFF) =3D=3D CapabilityId) { + *CapabilityPtr =3D NextPtr; + Status =3D EFI_SUCCESS; + goto Exit; + } + + NextPtr =3D (TmpValue >> 8) & 0xFF; + } + +Exit: + return Status; +} + +EFI_STATUS +WriteMps ( + PCIE_NODE *Node, + UINT8 Value + ) +{ + EFI_PCI_IO_PROTOCOL *PciIo; + EFI_STATUS Status; + UINT16 TmpValue; + UINT8 PcieCapOffset; + + if (Node =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + PciIo =3D Node->PciIo; + PcieCapOffset =3D Node->PcieCapOffset; + + // Get current device control reg + Status =3D PciIo->Pci.Read ( + PciIo, + EfiPciIoWidthUint16, + PcieCapOffset + PCI_EXPRESS_CAPABILITY_DEVICE_CONT= ROL_REG, + 1, + &TmpValue + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // Update value and write to device + TmpValue =3D (TmpValue & ~(PCIE_MAX_PAYLOAD_MASK << PCIE_CONTROL_MAX_PAY= LOAD_OFF)) + | Value << PCIE_CONTROL_MAX_PAYLOAD_OFF; + Status =3D PciIo->Pci.Write ( + PciIo, + EfiPciIoWidthUint16, + PcieCapOffset + PCI_EXPRESS_CAPABILITY_DEVICE_CONT= ROL_REG, + 1, + &TmpValue + ); + if (EFI_ERROR (Status)) { + return Status; + } + DEBUG (( + DEBUG_INFO, + "%a: Write MPS %d to device 0x%04x:0x%02x:0x%02x:0x%02x\n", + __FUNCTION__, + Value, + Node->Seg, + Node->Bus, + Node->Dev, + Node->Fun + )); + + return EFI_SUCCESS; +} + +EFI_STATUS +WriteMrr ( + PCIE_NODE *Node, + UINT8 Value + ) +{ + EFI_PCI_IO_PROTOCOL *PciIo; + EFI_STATUS Status; + UINT16 TmpValue; + UINT8 PcieCapOffset; + + if (Node =3D=3D NULL) { + return EFI_INVALID_PARAMETER; + } + + PciIo =3D Node->PciIo; + PcieCapOffset =3D Node->PcieCapOffset; + + // Get current device control reg + Status =3D PciIo->Pci.Read ( + PciIo, + EfiPciIoWidthUint16, + PcieCapOffset + PCI_EXPRESS_CAPABILITY_DEVICE_CONT= ROL_REG, + 1, + &TmpValue + ); + if (EFI_ERROR (Status)) { + return Status; + } + + // Update value and write to device + TmpValue =3D (TmpValue & ~(PCIE_MAX_READ_REQUEST_MASK << PCIE_CONTROL_RE= AD_REQUEST_OFF)) + | Value << PCIE_CONTROL_READ_REQUEST_OFF; + Status =3D PciIo->Pci.Write ( + PciIo, + EfiPciIoWidthUint16, + PcieCapOffset + PCI_EXPRESS_CAPABILITY_DEVICE_CONT= ROL_REG, + 1, + &TmpValue + ); + if (EFI_ERROR (Status)) { + return Status; + } + DEBUG (( + DEBUG_INFO, + "%a: Write MRR %d to device 0x%04x:0x%02x:0x%02x:0x%02x\n", + __FUNCTION__, + Value, + Node->Seg, + Node->Bus, + Node->Dev, + Node->Fun + )); + + return EFI_SUCCESS; +} diff --git a/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/Pcie= DeviceConfigDxe.uni b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfi= gDxe/PcieDeviceConfigDxe.uni new file mode 100644 index 000000000000..f07b70c746a6 --- /dev/null +++ b/Silicon/Ampere/AmpereAltraPkg/Drivers/PcieDeviceConfigDxe/PcieDeviceC= onfigDxe.uni @@ -0,0 +1,24 @@ +=EF=BB=BF// +// Copyright (c) 2021, Ampere Computing LLC. All rights reserved.
+// +// SPDX-License-Identifier: BSD-2-Clause-Patent +// + +#langdef en-US "English" // English + +#string STR_PCIE_DEVICE_CONFIG_FORM #language en-US "PCIE Device Configura= tion" +#string STR_PCIE_DEVICE_CONFIG_HELP #language en-US "PCIE Device Configura= tion" + +#string STR_DEVICE_FORM #language en-US "PCIE Device Form" +#string STR_DEVICE_GOTO_HELP #language en-US "PCIE Device Configura= tion" + +#string STR_PCIE_MPS #language en-US "Max Payload Size" +#string STR_PCIE_MPS_HELP #language en-US "Max Payload Size" +#string STR_PCIE_MRR #language en-US "Max Read Request Size" +#string STR_PCIE_MRR_HELP #language en-US "Max Read Request Size" +#string STR_128 #language en-US "128 bytes" +#string STR_256 #language en-US "256 bytes" +#string STR_512 #language en-US "512 bytes" +#string STR_1024 #language en-US "1024 bytes" +#string STR_2048 #language en-US "2048 bytes" +#string STR_4096 #language en-US "4096 bytes" --=20 2.17.1