public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Sean Rhodes" <sean@starlabs.systems>
To: devel@edk2.groups.io
Cc: Matt DeVillier <matt.devillier@gmail.com>,
	Hao A Wu <hao.a.wu@intel.com>, Ray Ni <ray.ni@intel.com>,
	Sean Rhodes <sean@starlabs.systems>
Subject: [PATCH 2/3] MdeModulePkg/XhciDxe/Xhci: Don't check for invalid PSIV
Date: Fri,  9 Dec 2022 20:45:39 +0000	[thread overview]
Message-ID: <618cba614165100a6834c7fd4760bfe328ae7d80.1670618740.git.sean@starlabs.systems> (raw)
In-Reply-To: <b41622b3f396829cb95d0928f60e0a2db68b0443.1670618740.git.sean@starlabs.systems>

From: Matt DeVillier <matt.devillier@gmail.com>

PSID matching relies on comparing the PSIV against the PortSpeed
value. This patch stops edk2 from checking for a PSIV of 0, as it
is not valid; this reduces the number of register access by
approximately 6 per second.

Cc: Hao A Wu <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Reviewed-by: Sean Rhodes <sean@starlabs.systems>
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Change-Id: If15c55ab66d2e7faa832ce8576d2e5b47157cc9a
---
 MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 44 ++++++++++++++++-------------
 1 file changed, 25 insertions(+), 19 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
index 15fb49f28f..8dd7a8fbb7 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
@@ -371,6 +371,7 @@ XhcGetRootHubPortStatus (
   UINT32             TotalPort;
   UINTN              Index;
   UINTN              MapSize;
+  UINT8              PortSpeed;
   EFI_STATUS         Status;
   USB_DEV_ROUTE      ParentRouteChart;
   EFI_TPL            OldTpl;
@@ -397,32 +398,37 @@ XhcGetRootHubPortStatus (
 
   State = XhcReadOpReg (Xhc, Offset);
 
+  PortSpeed = (State & XHC_PORTSC_PS) >> 10;
+
   //
   // According to XHCI 1.1 spec November 2017,
   // Section 7.2 xHCI Support Protocol Capability
   //
-  PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc, ((State & XHC_PORTSC_PS) >> 10));
-  if (PortStatus->PortStatus == 0) {
-    //
-    // According to XHCI 1.1 spec November 2017,
-    // bit 10~13 of the root port status register identifies the speed of the attached device.
-    //
-    switch ((State & XHC_PORTSC_PS) >> 10) {
-      case 2:
-        PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
-        break;
+  if (PortSpeed > 0) {
+    PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc, PortSpeed);
+    // If no match found in ext cap reg, fall back to PORTSC
+    if (PortStatus->PortStatus == 0) {
+      //
+      // According to XHCI 1.1 spec November 2017,
+      // bit 10~13 of the root port status register identifies the speed of the attached device.
+      //
+      switch (PortSpeed) {
+        case 2:
+          PortStatus->PortStatus |= USB_PORT_STAT_LOW_SPEED;
+          break;
 
-      case 3:
-        PortStatus->PortStatus |= USB_PORT_STAT_HIGH_SPEED;
-        break;
+        case 3:
+          PortStatus->PortStatus |= USB_PORT_STAT_HIGH_SPEED;
+          break;
 
-      case 4:
-      case 5:
-        PortStatus->PortStatus |= USB_PORT_STAT_SUPER_SPEED;
-        break;
+        case 4:
+        case 5:
+          PortStatus->PortStatus |= USB_PORT_STAT_SUPER_SPEED;
+          break;
 
-      default:
-        break;
+        default:
+          break;
+      }
     }
   }
 
-- 
2.37.2


  reply	other threads:[~2022-12-09 20:45 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-09 20:45 [PATCH 1/3] MdeModulePkg/BmBoot: Skip removable media if it is not present Sean Rhodes
2022-12-09 20:45 ` Sean Rhodes [this message]
2022-12-15  0:26   ` [PATCH 2/3] MdeModulePkg/XhciDxe/Xhci: Don't check for invalid PSIV Wu, Hao A
2022-12-09 20:45 ` [PATCH 3/3] MdeModulePkg/Bus/Pci/XhciDxe: Handle incorrect PSIV indices Sean Rhodes
2022-12-15  0:26   ` [edk2-devel] " Wu, Hao A
  -- strict thread matches above, loose matches on Subject: below --
2022-12-16  8:58 [PATCH 1/3] MdeModulePkg/BmBoot: Skip removable media if it is not present Sean Rhodes
2022-12-16  8:58 ` [PATCH 2/3] MdeModulePkg/XhciDxe/Xhci: Don't check for invalid PSIV Sean Rhodes
2022-12-19  6:16   ` Wu, Hao A

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=618cba614165100a6834c7fd4760bfe328ae7d80.1670618740.git.sean@starlabs.systems \
    --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