public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Andrei Warkentin" <awarkentin@vmware.com>
To: Jeremy Linton <jeremy.linton@arm.com>,
	"devel@edk2.groups.io" <devel@edk2.groups.io>
Cc: "pete@akeo.ie" <pete@akeo.ie>,
	"ardb+tianocore@kernel.org" <ardb+tianocore@kernel.org>,
	"Sunny.Wang@arm.com" <Sunny.Wang@arm.com>,
	"samer.el-haj-mahmoud@arm.com" <samer.el-haj-mahmoud@arm.com>
Subject: Re: [PATCH v3 1/7] Platform/RaspberryPi: Add XHCI/PCI selection menu
Date: Fri, 20 Aug 2021 20:14:48 +0000	[thread overview]
Message-ID: <PH0PR05MB870210A586B866C8F29C5485B9C19@PH0PR05MB8702.namprd05.prod.outlook.com> (raw)
In-Reply-To: <20210820041619.87248-2-jeremy.linton@arm.com>

[-- Attachment #1: Type: text/plain, Size: 9202 bytes --]

Reviewed-by: Andrei Warkentin <awarkentin@vmware.com>
________________________________
From: Jeremy Linton <jeremy.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>; Sunny.Wang@arm.com <Sunny.Wang@arm.com>; samer.el-haj-mahmoud@arm.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    |  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 = 0;
 STATIC UINT32 mModelInstalledMB = 0;
+STATIC UINT32 mModelRevision = 0;

 STATIC EFI_MAC_ADDRESS  mMacAddress;

@@ -271,6 +272,40 @@ SetupVariables (
     ASSERT_EFI_ERROR (Status);
   }

+  if (mModelFamily >= 4) {
+    if (((mModelRevision >> 4) & 0xFF) == 0x14) {
+      /*
+       * Enable PCIe by default on CM4
+       */
+      Status = PcdSet32S (PcdXhciPci, 2);
+      ASSERT_EFI_ERROR (Status);
+    } else {
+      Size = sizeof (UINT32);
+      Status = gRT->GetVariable (L"XhciPci",
+                                 &gConfigDxeFormSetGuid,
+                                 NULL, &Size, &Var32);
+      if (EFI_ERROR (Status) || (Var32 == 0)) {
+        /*
+         * Enable XHCI by default
+         */
+        Status = PcdSet32S (PcdXhciPci, 0);
+        ASSERT_EFI_ERROR (Status);
+      } else {
+        /*
+         * Enable PCIe
+         */
+        Status = PcdSet32S (PcdXhciPci, 1);
+        ASSERT_EFI_ERROR (Status);
+      }
+    }
+  } else {
+    /*
+     * Disable PCIe and XHCI
+     */
+    Status = PcdSet32S (PcdXhciPci, 0);
+    ASSERT_EFI_ERROR (Status);
+  }
+
   Size = sizeof (AssetTagVar);
   Status = 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 = mFwProtocol->GetModelRevision (&mModelRevision);
+  if (Status != EFI_SUCCESS) {
+    DEBUG ((DEBUG_ERROR, "Couldn't get the Raspberry Pi revision: %r\n", Status));
+  } else {
+    DEBUG ((DEBUG_INFO, "Current Raspberry Pi revision %x\n", mModelRevision));
+  }
+
   Status = SetupVariables ();
   if (Status != EFI_SUCCESS) {
     DEBUG ((DEBUG_ERROR, "Couldn't not setup NV vars: %r\n", Status));
diff --git a/Platform/RaspberryPi/Drivers/ConfigDxe/ConfigDxe.inf b/Platform/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/Platform/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 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 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/Platform/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  = FanTemp,
       guid  = CONFIGDXE_FORM_SET_GUID;

+    efivarstore ADVANCED_XHCIPCI_VARSTORE_DATA,
+      attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
+      name  = XhciPci,
+      guid  = CONFIGDXE_FORM_SET_GUID;
+
     efivarstore SYSTEM_TABLE_MODE_VARSTORE_DATA,
       attribute = EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,
       name  = SystemTableMode,
@@ -212,6 +217,18 @@ formset
               default = 60,
           endnumeric;
         endif;
+
+        suppressif ideqval XhciPci.Value == 2;
+          grayoutif NOT ideqval SystemTableMode.Mode == SYSTEM_TABLE_MODE_ACPI;
+            oneof varid = XhciPci.Value,
+              prompt      = STRING_TOKEN(STR_ADVANCED_XHCIPCI_PROMPT),
+              help        = STRING_TOKEN(STR_ADVANCED_XHCIPCI_HELP),
+              flags       = NUMERIC_SIZE_4 | INTERACTIVE | RESET_REQUIRED,
+              option text = STRING_TOKEN(STR_ADVANCED_XHCIPCI_XHCI), value = 0, flags = DEFAULT;
+              option text = STRING_TOKEN(STR_ADVANCED_XHCIPCI_PCIE), value = 1, flags = 0;
+            endoneof;
+          endif;
+        endif;
 #endif
         string varid = AssetTag.AssetTag,
             prompt  = STRING_TOKEN(STR_ADVANCED_ASSET_TAG_PROMPT),
diff --git a/Platform/RaspberryPi/Include/ConfigVars.h b/Platform/RaspberryPi/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"|gRaspberryPiTokenSpaceGuid|0x0|0

+  # Select XHCI/PCIe mode (not valid on rpi3)
+  #
+  # 0  - DISABLED
+  #
+  gRaspberryPiTokenSpaceGuid.PcdXhciPci|L"XhciPci"|gConfigDxeFormSetGuid|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"ResetDelay"|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"|gConfigDxeFormSetGuid|0x0|0
+
   #
   # Common UEFI ones.
   #
diff --git a/Platform/RaspberryPi/RaspberryPi.dec b/Platform/RaspberryPi/RaspberryPi.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


[-- Attachment #2: Type: text/html, Size: 14576 bytes --]

  reply	other threads:[~2021-08-20 20:14 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-20  4:16 [PATCH v3 0/7] RPi4: Enable ACPI PCIe conduit Jeremy Linton
2021-08-20  4:16 ` [PATCH v3 1/7] Platform/RaspberryPi: Add XHCI/PCI selection menu Jeremy Linton
2021-08-20 20:14   ` Andrei Warkentin [this message]
2021-08-20 20:31   ` Samer El-Haj-Mahmoud
2021-08-20  4:16 ` [PATCH v3 2/7] Platform/RaspberryPi: Break XHCI into its own SSDT Jeremy Linton
2021-08-20 20:15   ` Andrei Warkentin
2021-08-20  4:16 ` [PATCH v3 3/7] Platform/RaspberryPi: Add PCIe SSDT Jeremy Linton
2021-08-20 20:15   ` Andrei Warkentin
2021-08-20  4:16 ` [PATCH v3 4/7] Silicon/Broadcom/Bcm27xx: Relax PCIe device restriction Jeremy Linton
2021-08-20 20:16   ` Andrei Warkentin
2021-08-20  4:16 ` [PATCH v3 5/7] Silicon/Broadcom/Bcm27xx: Move linkup check into the cfg accessor Jeremy Linton
2021-08-20 20:16   ` Andrei Warkentin
2021-08-22 13:37   ` Ard Biesheuvel
2021-08-22 13:47     ` Ard Biesheuvel
2021-08-20  4:16 ` [PATCH v3 6/7] Platform/RaspberryPi: Enable NVMe boot on CM4 Jeremy Linton
2021-08-20 20:16   ` Andrei Warkentin
2021-08-20 20:37   ` Samer El-Haj-Mahmoud
2021-08-20  4:16 ` [PATCH v3 7/7] Platform/RaspberryPi: Add Linux quirk support Jeremy Linton
2021-08-20 20:15   ` Andrei Warkentin
2021-08-20 20:35   ` Samer El-Haj-Mahmoud
2021-08-20 20:27 ` [PATCH v3 0/7] RPi4: Enable ACPI PCIe conduit Samer El-Haj-Mahmoud
     [not found]   ` <7d39c23-6578-6bb9-ab5f-9d242d7ff42d@invisible.ca>
2021-08-22 13:55     ` Ard Biesheuvel

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=PH0PR05MB870210A586B866C8F29C5485B9C19@PH0PR05MB8702.namprd05.prod.outlook.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