From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (NAM11-CO1-obe.outbound.protection.outlook.com [40.107.220.45]) by mx.groups.io with SMTP id smtpd.web11.3064.1629490492393929263 for ; Fri, 20 Aug 2021 13:14:52 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@vmware.com header.s=selector2 header.b=zmq/9L72; spf=pass (domain: vmware.com, ip: 40.107.220.45, mailfrom: awarkentin@vmware.com) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aHjxpqkTlwodSx2QYuq1N1gbwjn4+FMwj0A+hki3TYVNkU0FYH8xIGBI180g6AbBHhni3BhTDdxJa2Yi/0gHXhBPPDCcZpPjg5WWbAfHXu6WRF9W0wGvrKQF3hOleZ1CXq3ioOReVq35+99gSYSp7Xh6DLl9+NwyKELeOavoohJHpw+f5bfBtXM6jVkPkIc5paXy1ZkSnp65eQZVBVWG86avFJ+DQ44Pu4i7UOsWYdE+1mLorGmDOK2t/uEADzC/iunWPAs40bH/AaOw/M9jisYY0lbxuzRtPvbA1SKda7p0jjvj+EKnEutI/w+/CCwsp7FWP+E1C7JKtq8XSqk+1w== 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=hNrVYjmlVlBC3yPJT8cjf8zN0M6YGvjum54g3CinTe0=; b=a5y4HZAvd7dUiYpYP9pQ3LJXOmb5OWP1H5oErVhDFc+ybva9HBLrOt0WUWxBWz6QBYaCl15LJlY1ZmmIWD9hstcv6BbJh0lTvyN6x0UjvCUoK5a3BAhl4o13eIa3d0DUNqXGKcsuZ8fKnE0ey5izvTSW87oQEe7xUKgwzB7/sVKu0pZIF9VKFvrBROH3xkAT0UzG4uI7o2bidhQOrjDC5rMkeSss1dBoC8EO4wwkd1jYlEvFM6Q0GiPTxcfovW6DzXFO9MQZUTcph1+htLxTDsm65HPD4qr+NQPkTZ1wP7ngVUTenHsK1IEpUNkfkIEp78a+fxmoq+CmbAzaSdwJGg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=vmware.com; dmarc=pass action=none header.from=vmware.com; dkim=pass header.d=vmware.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=hNrVYjmlVlBC3yPJT8cjf8zN0M6YGvjum54g3CinTe0=; b=zmq/9L720lrfNdyxo9Orm+Fo5eLASCFVsnGbYy88TDwkcweDlRQruL66rpfL0ugFL73u/OsDAjPvi0zuEzwrVJJXdSr8newT+oMRPn3pRWJQRKBoPUCUBCB//JcLGhV8t9eyi1HBRI9L3EM+3V/4wYX9ZyG6ijsnbuAucX57DCI= Received: from PH0PR05MB8702.namprd05.prod.outlook.com (2603:10b6:510:b2::21) by PH0PR05MB8139.namprd05.prod.outlook.com (2603:10b6:510:95::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.6; Fri, 20 Aug 2021 20:14:48 +0000 Received: from PH0PR05MB8702.namprd05.prod.outlook.com ([fe80::c88e:73c1:db37:5b94]) by PH0PR05MB8702.namprd05.prod.outlook.com ([fe80::c88e:73c1:db37:5b94%6]) with mapi id 15.20.4457.005; Fri, 20 Aug 2021 20:14:48 +0000 From: "Andrei Warkentin" To: Jeremy Linton , "devel@edk2.groups.io" CC: "pete@akeo.ie" , "ardb+tianocore@kernel.org" , "Sunny.Wang@arm.com" , "samer.el-haj-mahmoud@arm.com" Subject: Re: [PATCH v3 1/7] Platform/RaspberryPi: Add XHCI/PCI selection menu Thread-Topic: [PATCH v3 1/7] Platform/RaspberryPi: Add XHCI/PCI selection menu Thread-Index: AQHXlXokbgEtU+/hvEefMA+SA8BR3at81ROo Date: Fri, 20 Aug 2021 20:14:48 +0000 Message-ID: References: <20210820041619.87248-1-jeremy.linton@arm.com> <20210820041619.87248-2-jeremy.linton@arm.com> In-Reply-To: <20210820041619.87248-2-jeremy.linton@arm.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: arm.com; dkim=none (message not signed) header.d=none;arm.com; dmarc=none action=none header.from=vmware.com; x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: ddceb22d-b8ab-46b5-36ea-08d96417292c x-ms-traffictypediagnostic: PH0PR05MB8139: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: VxHgmkqeISRL76iLn7bW/ayooh9vu2Ld9+o73sHdcePI10x0nzTIT9+HkVJzEQNO/M2Y7yvb+VjsTTGXmR1vl6WRqxO+51O70nPxh2wOsSQ25nbkpiJtzvb2uxiIzgYiyy623f5EZcRXNtjHfZsnbA/7x+8tLU9vM2QDh+8/JJ6tAh4KKxpW/y6jco388NyCExzGP1L/Ja3dAlX1grvEi8h+qqfph6MWhNPCCvcXkmIyMP4WNWmoEklyGpvrL2Ngy9pcYCzox3fphLD41RAmfzygynn9c8yPL5PCu30priqAfpAigj1lUTqR6cP5oOFXp+bM36d/YTuYfx7SgdPpzZAtVny4wAWvH7kvuKkMt0sQsIB5uz4XTVftXeBl9aoxRYIe4bZV5r9eDAa/5M1Vd1IBSHILZj2JiZ07JabPvPDaHl2klvtyKuX/E+/qYorgApSe0hEYmt/OQRB4fwo1FfZXV3m5T7c5s4ywyHArnqkX8Kv2Q3GQILFJlU/UQNWx18rTnv5FpGXORH6Uas45ErWQkbrNRujKisUI2B8444ClH8MqufcVabxpfjjRX4FOt+v51LM+OwWuBMIhTPSxRKuBgBXKdetQmezKYlVDATN03+Jr/MlK3IrMjNgUuWZB1EndKwZqWMuuqnLeK9JK0f2RxvHDp+zB0heGBHuUMifgSkGrnF/FHlsMkwk1F5FWLAKz9r7zXuGv4MS9bQrFlg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PH0PR05MB8702.namprd05.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(366004)(316002)(66556008)(91956017)(66476007)(54906003)(64756008)(33656002)(38100700002)(52536014)(110136005)(7696005)(66446008)(76116006)(5660300002)(66946007)(53546011)(6506007)(38070700005)(8936002)(8676002)(71200400001)(122000001)(9686003)(19627235002)(55016002)(86362001)(186003)(2906002)(26005)(4326008)(83380400001)(19627405001)(508600001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?swJqZXBvrzrp+7+m9bY2OnwU1Zd6b+ul2xXGhYGWes4EB7D3Oo8eiI1RnD65?= =?us-ascii?Q?BXAaZk14Z2/02I+orYBWH6g5RRYWFQOs6PB349Ly2gGMS6BOfhmVx53BGhVi?= =?us-ascii?Q?hfoxZCqZnZZDbtr6igdNNPd4PelOjRf8/cxxbyZvf15iT1xi3zSWl/2lcV/n?= =?us-ascii?Q?QgP1pqkUF6sFwe5vKlW8XsO23YJiLjh/9OcVcXK8YM7M23ETCgxEW0R1PLIP?= =?us-ascii?Q?nhSXr0EZHq6ns8w4sxPIZDuDbL6iP2k3fqQBZfTb1Lgg5n9FmOszaQ/RriZz?= =?us-ascii?Q?z/8r4bKCqexrCOG1D+2c581pltVPg9TJUMFS0RpVG9zgWG1UV0vtvKX0Aqy4?= =?us-ascii?Q?k/0H46PHxKZaQvIdi1sBVkTXXdM+otcViF83CLocEV4xsMNnlGoBxBsd+Tf3?= =?us-ascii?Q?hAj1bkTLqFJTXbiHOyhM22EWp7cbRsyIXW+OGianPFdjYhXyLKTAw7D3j/2I?= =?us-ascii?Q?A6VGTaqkNxtU9/8Tu8UZVh5okH7gVThJ7z9iD6lx+9q7kX2UC0927E6xaT9W?= =?us-ascii?Q?Z3272yWc2iccaRBsqwvYskJpHFdLWh3oiCU56QR0T2jWfcX6QIGb9LF7DwQr?= =?us-ascii?Q?usJ+UB0I67h1tjB8SzzLyIUpDU0y3l4LcCOH7A40BbV4VN0QIkJzHZjy8zVS?= =?us-ascii?Q?mxQnGikjovsRUd2iivNa2JRI2q7pVxs7UqXMlnaguiO1Na12u0mh5+0N2MPU?= =?us-ascii?Q?Bdtc04puzoywomEUu5lPUL28ToAqcZpELWolFSHLlZwCfziIOQ0W6SWueYEM?= =?us-ascii?Q?+J8qc61NwKJyS7n8+4XyO3gxO4z2EG5DHqwoSNBkNHWq2nYB8uzZ/LjDVrFy?= =?us-ascii?Q?zmfi85u5sCe6/HKsWAlSEDX0fa19g3sZNnxjpbrYqV/Fw7+q//xJ1mPExph6?= =?us-ascii?Q?ep1JqM8ITQnT6YcSSH7EVuGGfFRwUj7CRImBKWAlPpvINWd5aOmSaFKqdkdz?= =?us-ascii?Q?iYp0XO2Sbs073mJdjK1inHzXzHBDvPfYkSmKQjhxzKfj2XsV63hXP7i0+qeW?= =?us-ascii?Q?2zwyLe/NDTTieEr6MqZHFWIySmCYw27BfEddA0/OtvSI3E9JrvnAldOrtM74?= =?us-ascii?Q?Ub+hxJPKfzcPgdV+JFgEwIVItLa1hn6WejlC/nc5zYoz2ELO/yPnQxGOccOC?= =?us-ascii?Q?2C6WeJNz2Jc1SXGvzL+vm7jXlQ8pv7SexBMjnzLIWIhVZQYMZiHt9NFz8FI9?= =?us-ascii?Q?v8YQXAtlSVuG3t+EoyTUBBlZpZpoM2u53UZ0+WFWeviZVPbbmak6MWk9KvPI?= =?us-ascii?Q?6MR8aDeeRE7SneTR7ZYf08imuD56z0xCe65zmZt97+zrAjU4C4v4ySThvMrl?= =?us-ascii?Q?hMMLZ9rk8yI1M9kGPVtBcwrO?= x-ms-exchange-transport-forked: True MIME-Version: 1.0 X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH0PR05MB8702.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ddceb22d-b8ab-46b5-36ea-08d96417292c X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Aug 2021 20:14:48.6100 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: Wy8W/g+bdIsnsXF/Jr8AAAh0NIpXoFTZkPOfUQJi1WQXPH/cBeZ0Wo0N8KK+g8hnn7hsJWkE/5wq06JGqfPrlA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR05MB8139 Content-Language: en-US Content-Type: multipart/alternative; boundary="_000_PH0PR05MB870210A586B866C8F29C5485B9C19PH0PR05MB8702namp_" --_000_PH0PR05MB870210A586B866C8F29C5485B9C19PH0PR05MB8702namp_ Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Reviewed-by: Andrei Warkentin ________________________________ From: Jeremy Linton Sent: Thursday, August 19, 2021 11:16 PM To: devel@edk2.groups.io Cc: pete@akeo.ie ; ardb+tianocore@kernel.org ; Andrei Warkentin ; Sunny.Wang@arm.com <= Sunny.Wang@arm.com>; samer.el-haj-mahmoud@arm.com ; Jeremy Linton Subject: [PATCH v3 1/7] Platform/RaspberryPi: Add XHCI/PCI selection menu Arm has standardized a PCI SMC conduit that can be used to access the PCI config space in a standardized way. This functionality doesn't yet exist in many OS/Distro's. Lets add another advanced config item that allows the user to toggle between presenting the XHCI on the base RPi4 as a platform device, or presenting this newer PCIe conduit. The CM4 doesn't have an attached XHCI controller soldered to the PCIe, so PCIe mode is the default. Signed-off-by: Jeremy Linton --- Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 42 ++++++++++++++++++= ++++ .../RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf | 1 + .../RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni | 5 +++ .../RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr | 17 +++++++++ Platform/RaspberryPi/Include/ConfigVars.h | 4 +++ Platform/RaspberryPi/RPi3/RPi3.dsc | 6 ++++ Platform/RaspberryPi/RPi4/RPi4.dsc | 8 +++++ Platform/RaspberryPi/RaspberryPi.dec | 1 + 8 files changed, 84 insertions(+) diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/= RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c index 9e78cb47ad..87f6b4e7bb 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c @@ -43,6 +43,7 @@ extern UINT8 ConfigDxeStrings[]; STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol; STATIC UINT32 mModelFamily =3D 0; STATIC UINT32 mModelInstalledMB =3D 0; +STATIC UINT32 mModelRevision =3D 0; STATIC EFI_MAC_ADDRESS mMacAddress; @@ -271,6 +272,40 @@ SetupVariables ( ASSERT_EFI_ERROR (Status); } + if (mModelFamily >=3D 4) { + if (((mModelRevision >> 4) & 0xFF) =3D=3D 0x14) { + /* + * Enable PCIe by default on CM4 + */ + Status =3D PcdSet32S (PcdXhciPci, 2); + ASSERT_EFI_ERROR (Status); + } else { + Size =3D sizeof (UINT32); + Status =3D gRT->GetVariable (L"XhciPci", + &gConfigDxeFormSetGuid, + NULL, &Size, &Var32); + if (EFI_ERROR (Status) || (Var32 =3D=3D 0)) { + /* + * Enable XHCI by default + */ + Status =3D PcdSet32S (PcdXhciPci, 0); + ASSERT_EFI_ERROR (Status); + } else { + /* + * Enable PCIe + */ + Status =3D PcdSet32S (PcdXhciPci, 1); + ASSERT_EFI_ERROR (Status); + } + } + } else { + /* + * Disable PCIe and XHCI + */ + Status =3D PcdSet32S (PcdXhciPci, 0); + ASSERT_EFI_ERROR (Status); + } + Size =3D sizeof (AssetTagVar); Status =3D gRT->GetVariable (L"AssetTag", &gConfigDxeFormSetGuid, @@ -888,6 +923,13 @@ ConfigInitialize ( DEBUG ((DEBUG_INFO, "Current Raspberry Pi installed RAM size is %d MB\= n", mModelInstalledMB)); } + Status =3D mFwProtocol->GetModelRevision (&mModelRevision); + if (Status !=3D EFI_SUCCESS) { + DEBUG ((DEBUG_ERROR, "Couldn't get the Raspberry Pi revision: %r\n", S= tatus)); + } else { + DEBUG ((DEBUG_INFO, "Current Raspberry Pi revision %x\n", mModelRevisi= on)); + } + Status =3D SetupVariables (); if (Status !=3D EFI_SUCCESS) { DEBUG ((DEBUG_ERROR, "Couldn't not setup NV vars: %r\n", Status)); diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platfor= m/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf index 4bb2d08550..e6e22ad82e 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf @@ -94,6 +94,7 @@ gRaspberryPiTokenSpaceGuid.PcdFanOnGpio gRaspberryPiTokenSpaceGuid.PcdFanTemp gRaspberryPiTokenSpaceGuid.PcdUartInUse + gRaspberryPiTokenSpaceGuid.PcdXhciPci [Depex] gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni index 466fa852cb..5ec17072c3 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni @@ -57,6 +57,11 @@ #string STR_ADVANCED_FANTEMP_PROMPT #language en-US "ACPI fan temperatur= e" #string STR_ADVANCED_FANTEMP_HELP #language en-US "Cycle a fan at C" +#string STR_ADVANCED_XHCIPCI_PROMPT #language en-US "ACPI XHCI/PCIe" +#string STR_ADVANCED_XHCIPCI_HELP #language en-US "OS sees XHCI USB pl= atform device or PCIe bridge" +#string STR_ADVANCED_XHCIPCI_XHCI #language en-US "XHCI" +#string STR_ADVANCED_XHCIPCI_PCIE #language en-US "PCIe" + #string STR_ADVANCED_ASSET_TAG_PROMPT #language en-US "Asset Tag" #string STR_ADVANCED_ASSET_TAG_HELP #language en-US "Set the system Asse= t Tag" diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr index fa34eab809..18b3ec726e 100644 --- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr +++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr @@ -56,6 +56,11 @@ formset name =3D FanTemp, guid =3D CONFIGDXE_FORM_SET_GUID; + efivarstore ADVANCED_XHCIPCI_VARSTORE_DATA, + attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE, + name =3D XhciPci, + guid =3D CONFIGDXE_FORM_SET_GUID; + efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA, attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME= _ACCESS | EFI_VARIABLE_NON_VOLATILE, name =3D SystemTableMode, @@ -212,6 +217,18 @@ formset default =3D 60, endnumeric; endif; + + suppressif ideqval XhciPci.Value =3D=3D 2; + grayoutif NOT ideqval SystemTableMode.Mode =3D=3D SYSTEM_TABLE_M= ODE_ACPI; + oneof varid =3D XhciPci.Value, + prompt =3D STRING_TOKEN(STR_ADVANCED_XHCIPCI_PROMPT), + help =3D STRING_TOKEN(STR_ADVANCED_XHCIPCI_HELP), + flags =3D NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRE= D, + option text =3D STRING_TOKEN(STR_ADVANCED_XHCIPCI_XHCI), val= ue =3D 0, flags =3D DEFAULT; + option text =3D STRING_TOKEN(STR_ADVANCED_XHCIPCI_PCIE), val= ue =3D 1, flags =3D 0; + endoneof; + endif; + endif; #endif string varid =3D AssetTag.AssetTag, prompt =3D STRING_TOKEN(STR_ADVANCED_ASSET_TAG_PROMPT), diff --git a/Platform/RaspberryPi/Include/ConfigVars.h b/Platform/Raspberry= Pi/Include/ConfigVars.h index 142317985a..a5b32b5284 100644 --- a/Platform/RaspberryPi/Include/ConfigVars.h +++ b/Platform/RaspberryPi/Include/ConfigVars.h @@ -77,6 +77,10 @@ typedef struct { } ADVANCED_FANTEMP_VARSTORE_DATA; typedef struct { + UINT32 Value; +} ADVANCED_XHCIPCI_VARSTORE_DATA; + +typedef struct { #define SYSTEM_TABLE_MODE_ACPI 0 #define SYSTEM_TABLE_MODE_BOTH 1 #define SYSTEM_TABLE_MODE_DT 2 diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3= /RPi3.dsc index 1c8a5408e7..6ab5d1ae6d 100644 --- a/Platform/RaspberryPi/RPi3/RPi3.dsc +++ b/Platform/RaspberryPi/RPi3/RPi3.dsc @@ -520,6 +520,12 @@ gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|L"ResetDelay"|gRaspberr= yPiTokenSpaceGuid|0x0|0 + # Select XHCI/PCIe mode (not valid on rpi3) + # + # 0 - DISABLED + # + gRaspberryPiTokenSpaceGuid.PcdXhciPci|L"XhciPci"|gConfigDxeFormSetGuid|0= x0|0 + # # Common UEFI ones. # diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4= /RPi4.dsc index dcf9bb5f11..babcbb2f41 100644 --- a/Platform/RaspberryPi/RPi4/RPi4.dsc +++ b/Platform/RaspberryPi/RPi4/RPi4.dsc @@ -536,6 +536,14 @@ gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|L"ResetDelay"|gRaspberr= yPiTokenSpaceGuid|0x0|0 + # Select XHCI/PCIe mode + # + # 0 - XHCI Enabled (default on !cm4) + # 1 - PCIe Enabled + # 2 - PCIe Enabled (default on cm4) + # + gRaspberryPiTokenSpaceGuid.PcdXhciPci|L"XhciPci"|gConfigDxeFormSetGuid|0= x0|0 + # # Common UEFI ones. # diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/Ra= spberryPi.dec index 2ca25ff9e6..797be59274 100644 --- a/Platform/RaspberryPi/RaspberryPi.dec +++ b/Platform/RaspberryPi/RaspberryPi.dec @@ -71,3 +71,4 @@ gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|0|UINT32|0x0000001E gRaspberryPiTokenSpaceGuid.PcdMmcEnableDma|0|UINT32|0x0000001F gRaspberryPiTokenSpaceGuid.PcdUartInUse|1|UINT32|0x00000021 + gRaspberryPiTokenSpaceGuid.PcdXhciPci|0|UINT32|0x00000022 -- 2.13.7 --_000_PH0PR05MB870210A586B866C8F29C5485B9C19PH0PR05MB8702namp_ Content-Type: text/html; charset="us-ascii" Content-Transfer-Encoding: quoted-printable
Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>

From: Jeremy Linton <jer= emy.linton@arm.com>
Sent: Thursday, August 19, 2021 11:16 PM
To: devel@edk2.groups.io <devel@edk2.groups.io>
Cc: pete@akeo.ie <pete@akeo.ie>; ardb+tianocore@kernel.org <= ;ardb+tianocore@kernel.org>; Andrei Warkentin <awarkentin@vmware.com&= gt;; Sunny.Wang@arm.com <Sunny.Wang@arm.com>; samer.el-haj-mahmoud@ar= m.com <samer.el-haj-mahmoud@arm.com>; Jeremy Linton <jeremy.linton= @arm.com>
Subject: [PATCH v3 1/7] Platform/RaspberryPi: Add XHCI/PCI selection= menu
 
Arm has standardized a PCI SMC conduit that can be= used
to access the PCI config space in a standardized way. This
functionality doesn't yet exist in many OS/Distro's. Lets
add another advanced config item that allows the user
to toggle between presenting the XHCI on the base RPi4
as a platform device, or presenting this newer PCIe
conduit. The CM4 doesn't have an attached XHCI controller
soldered to the PCIe, so PCIe mode is the default.

Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
 Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c | 42 +++++++++++++= +++++++++
 .../RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf    |&n= bsp; 1 +
 .../RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni |  5 +++
 .../RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr | 17 +++++++++
 Platform/RaspberryPi/Include/ConfigVars.h    &nbs= p;     |  4 +++
 Platform/RaspberryPi/RPi3/RPi3.dsc      = ;           |  6 +++= +
 Platform/RaspberryPi/RPi4/RPi4.dsc      = ;           |  8 +++= ++
 Platform/RaspberryPi/RaspberryPi.dec     &nb= sp;         |  1 +
 8 files changed, 84 insertions(+)

diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c b/Platform/= RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
index 9e78cb47ad..87f6b4e7bb 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.c
@@ -43,6 +43,7 @@ extern UINT8 ConfigDxeStrings[];
 STATIC RASPBERRY_PI_FIRMWARE_PROTOCOL *mFwProtocol;
 STATIC UINT32 mModelFamily =3D 0;
 STATIC UINT32 mModelInstalledMB =3D 0;
+STATIC UINT32 mModelRevision =3D 0;
 
 STATIC EFI_MAC_ADDRESS  mMacAddress;
 
@@ -271,6 +272,40 @@ SetupVariables (
     ASSERT_EFI_ERROR (Status);
   }
 
+  if (mModelFamily >=3D 4) {
+    if (((mModelRevision >> 4) & 0xFF) =3D=3D 0x1= 4) {
+      /*
+       * Enable PCIe by default on CM4
+       */
+      Status =3D PcdSet32S (PcdXhciPci, 2);
+      ASSERT_EFI_ERROR (Status);
+    } else {
+      Size =3D sizeof (UINT32);
+      Status =3D gRT->GetVariable (L"Xhci= Pci",
+            &n= bsp;            = ;        &gConfigDxeFormSetGuid,
+            &n= bsp;            = ;        NULL, &Size, &Var32); +      if (EFI_ERROR (Status) || (Var32 =3D=3D 0))= {
+        /*
+         * Enable XHCI by default<= br> +         */
+        Status =3D PcdSet32S (PcdXhciPc= i, 0);
+        ASSERT_EFI_ERROR (Status);
+      } else {
+        /*
+         * Enable PCIe
+         */
+        Status =3D PcdSet32S (PcdXhciPc= i, 1);
+        ASSERT_EFI_ERROR (Status);
+      }
+    }
+  } else {
+    /*
+     * Disable PCIe and XHCI
+     */
+    Status =3D PcdSet32S (PcdXhciPci, 0);
+    ASSERT_EFI_ERROR (Status);
+  }
+
   Size =3D sizeof (AssetTagVar);
   Status =3D gRT->GetVariable (L"AssetTag",
            &nb= sp;      &gConfigDxeFormSetGuid,
@@ -888,6 +923,13 @@ ConfigInitialize (
     DEBUG ((DEBUG_INFO, "Current Raspberry Pi ins= talled RAM size is %d MB\n", mModelInstalledMB));
   }
 
+  Status =3D mFwProtocol->GetModelRevision (&mModelRevision);<= br> +  if (Status !=3D EFI_SUCCESS) {
+    DEBUG ((DEBUG_ERROR, "Couldn't get the Raspberry P= i revision: %r\n", Status));
+  } else {
+    DEBUG ((DEBUG_INFO, "Current Raspberry Pi revision= %x\n", mModelRevision));
+  }
+
   Status =3D SetupVariables ();
   if (Status !=3D EFI_SUCCESS) {
     DEBUG ((DEBUG_ERROR, "Couldn't not setup NV v= ars: %r\n", Status));
diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platfor= m/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
index 4bb2d08550..e6e22ad82e 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf
@@ -94,6 +94,7 @@
   gRaspberryPiTokenSpaceGuid.PcdFanOnGpio
   gRaspberryPiTokenSpaceGuid.PcdFanTemp
   gRaspberryPiTokenSpaceGuid.PcdUartInUse
+  gRaspberryPiTokenSpaceGuid.PcdXhciPci
 
 [Depex]
   gPcdProtocolGuid AND gRaspberryPiFirmwareProtocolGuid
diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni
index 466fa852cb..5ec17072c3 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.uni
@@ -57,6 +57,11 @@
 #string STR_ADVANCED_FANTEMP_PROMPT   #language en-US "= ;ACPI fan temperature"
 #string STR_ADVANCED_FANTEMP_HELP     #language e= n-US "Cycle a fan at C"
 
+#string STR_ADVANCED_XHCIPCI_PROMPT   #language en-US "ACPI= XHCI/PCIe"
+#string STR_ADVANCED_XHCIPCI_HELP     #language en-US = "OS sees XHCI USB platform device or PCIe bridge"
+#string STR_ADVANCED_XHCIPCI_XHCI     #language en-US = "XHCI"
+#string STR_ADVANCED_XHCIPCI_PCIE     #language en-US = "PCIe"
+
 #string STR_ADVANCED_ASSET_TAG_PROMPT #language en-US "Asset Tag= "
 #string STR_ADVANCED_ASSET_TAG_HELP   #language en-US "= ;Set the system Asset Tag"
 
diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr b/Plat= form/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr
index fa34eab809..18b3ec726e 100644
--- a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr
+++ b/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxeHii.vfr
@@ -56,6 +56,11 @@ formset
       name  =3D FanTemp,
       guid  =3D CONFIGDXE_FORM_SET_GUID= ;
 
+    efivarstore ADVANCED_XHCIPCI_VARSTORE_DATA,
+      attribute =3D EFI_VARIABLE_BOOTSERVICE_ACCE= SS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  =3D XhciPci,
+      guid  =3D CONFIGDXE_FORM_SET_GUID;
+
     efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA,
       attribute =3D EFI_VARIABLE_BOOTSERVICE= _ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
       name  =3D SystemTableMode,
@@ -212,6 +217,18 @@ formset
            &nb= sp;  default =3D 60,
           endnumeric;          endif;
+
+        suppressif ideqval XhciPci.Valu= e =3D=3D 2;
+          grayoutif NOT ideqv= al SystemTableMode.Mode =3D=3D SYSTEM_TABLE_MODE_ACPI;
+            oneof v= arid =3D XhciPci.Value,
+            &n= bsp; prompt      =3D STRING_TOKEN(STR_ADVANCED_XHC= IPCI_PROMPT),
+            &n= bsp; help        =3D STRING_TOKEN(STR_AD= VANCED_XHCIPCI_HELP),
+            &n= bsp; flags       =3D NUMERIC_SIZE_4 | INTERAC= TIVE | RESET_REQUIRED,
+            &n= bsp; option text =3D STRING_TOKEN(STR_ADVANCED_XHCIPCI_XHCI), value =3D 0, = flags =3D DEFAULT;
+            &n= bsp; option text =3D STRING_TOKEN(STR_ADVANCED_XHCIPCI_PCIE), value =3D 1, = flags =3D 0;
+            endoneo= f;
+          endif;
+        endif;
 #endif
         string varid =3D AssetTag.= AssetTag,
             pr= ompt  =3D STRING_TOKEN(STR_ADVANCED_ASSET_TAG_PROMPT),
diff --git a/Platform/RaspberryPi/Include/ConfigVars.h b/Platform/Raspberry= Pi/Include/ConfigVars.h
index 142317985a..a5b32b5284 100644
--- a/Platform/RaspberryPi/Include/ConfigVars.h
+++ b/Platform/RaspberryPi/Include/ConfigVars.h
@@ -77,6 +77,10 @@ typedef struct {
 } ADVANCED_FANTEMP_VARSTORE_DATA;
 
 typedef struct {
+  UINT32 Value;
+} ADVANCED_XHCIPCI_VARSTORE_DATA;
+
+typedef struct {
 #define SYSTEM_TABLE_MODE_ACPI 0
 #define SYSTEM_TABLE_MODE_BOTH 1
 #define SYSTEM_TABLE_MODE_DT   2
diff --git a/Platform/RaspberryPi/RPi3/RPi3.dsc b/Platform/RaspberryPi/RPi3= /RPi3.dsc
index 1c8a5408e7..6ab5d1ae6d 100644
--- a/Platform/RaspberryPi/RPi3/RPi3.dsc
+++ b/Platform/RaspberryPi/RPi3/RPi3.dsc
@@ -520,6 +520,12 @@
 
   gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|L"ResetD= elay"|gRaspberryPiTokenSpaceGuid|0x0|0
 
+  # Select XHCI/PCIe mode (not valid on rpi3)
+  #
+  # 0  - DISABLED
+  #
+  gRaspberryPiTokenSpaceGuid.PcdXhciPci|L"XhciPci"|gConfigD= xeFormSetGuid|0x0|0
+
   #
   # Common UEFI ones.
   #
diff --git a/Platform/RaspberryPi/RPi4/RPi4.dsc b/Platform/RaspberryPi/RPi4= /RPi4.dsc
index dcf9bb5f11..babcbb2f41 100644
--- a/Platform/RaspberryPi/RPi4/RPi4.dsc
+++ b/Platform/RaspberryPi/RPi4/RPi4.dsc
@@ -536,6 +536,14 @@
 
   gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|L"ResetD= elay"|gRaspberryPiTokenSpaceGuid|0x0|0
 
+  # Select XHCI/PCIe mode
+  #
+  # 0  - XHCI Enabled (default on !cm4)
+  # 1  - PCIe Enabled
+  # 2  - PCIe Enabled (default on cm4)
+  #
+  gRaspberryPiTokenSpaceGuid.PcdXhciPci|L"XhciPci"|gConfigD= xeFormSetGuid|0x0|0
+
   #
   # Common UEFI ones.
   #
diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/Ra= spberryPi.dec
index 2ca25ff9e6..797be59274 100644
--- a/Platform/RaspberryPi/RaspberryPi.dec
+++ b/Platform/RaspberryPi/RaspberryPi.dec
@@ -71,3 +71,4 @@
   gRaspberryPiTokenSpaceGuid.PcdPlatformResetDelay|0|UINT32|0x00= 00001E
   gRaspberryPiTokenSpaceGuid.PcdMmcEnableDma|0|UINT32|0x0000001F=
   gRaspberryPiTokenSpaceGuid.PcdUartInUse|1|UINT32|0x00000021 +  gRaspberryPiTokenSpaceGuid.PcdXhciPci|0|UINT32|0x00000022
--
2.13.7

--_000_PH0PR05MB870210A586B866C8F29C5485B9C19PH0PR05MB8702namp_--