[PATCH 2/4] MdeModulePkg/XhciDxe/Xhci: Don't check for invalid PSIV


Sean Rhodes
 

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

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@...>
Cc: Ray Ni <ray.ni@...>
Reviewed-by: Sean Rhodes <sean@...>
Signed-off-by: Matt DeVillier <matt.devillier@...>
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/Xhc=
iDxe/Xhci.c
index c05431ff30..51ae57db21 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
@@ -371,6 +371,7 @@ XhcGetRootHubPortStatus (
UINT32 TotalPort;=0D
UINTN Index;=0D
UINTN MapSize;=0D
+ UINTN PortSpeed;=0D
EFI_STATUS Status;=0D
USB_DEV_ROUTE ParentRouteChart;=0D
EFI_TPL OldTpl;=0D
@@ -397,32 +398,37 @@ XhcGetRootHubPortStatus (
=0D
State =3D XhcReadOpReg (Xhc, Offset);=0D
=0D
+ PortSpeed =3D (State & XHC_PORTSC_PS) >> 10;=0D
+=0D
//=0D
// According to XHCI 1.1 spec November 2017,=0D
// Section 7.2 xHCI Support Protocol Capability=0D
//=0D
- PortStatus->PortStatus =3D XhcCheckUsbPortSpeedUsedPsic (Xhc, ((State & =
XHC_PORTSC_PS) >> 10));=0D
- if (PortStatus->PortStatus =3D=3D 0) {=0D
- //=0D
- // According to XHCI 1.1 spec November 2017,=0D
- // bit 10~13 of the root port status register identifies the speed of =
the attached device.=0D
- //=0D
- switch ((State & XHC_PORTSC_PS) >> 10) {=0D
- case 2:=0D
- PortStatus->PortStatus |=3D USB_PORT_STAT_LOW_SPEED;=0D
- break;=0D
+ if (PortSpeed > 0) {=0D
+ PortStatus->PortStatus =3D XhcCheckUsbPortSpeedUsedPsic (Xhc, PortSpee=
d);=0D
+ // If no match found in ext cap reg, fall back to PORTSC=0D
+ if (PortStatus->PortStatus =3D=3D 0) {=0D
+ //=0D
+ // According to XHCI 1.1 spec November 2017,=0D
+ // bit 10~13 of the root port status register identifies the speed o=
f the attached device.=0D
+ //=0D
+ switch (PortSpeed) {=0D
+ case 2:=0D
+ PortStatus->PortStatus |=3D USB_PORT_STAT_LOW_SPEED;=0D
+ break;=0D
=0D
- case 3:=0D
- PortStatus->PortStatus |=3D USB_PORT_STAT_HIGH_SPEED;=0D
- break;=0D
+ case 3:=0D
+ PortStatus->PortStatus |=3D USB_PORT_STAT_HIGH_SPEED;=0D
+ break;=0D
=0D
- case 4:=0D
- case 5:=0D
- PortStatus->PortStatus |=3D USB_PORT_STAT_SUPER_SPEED;=0D
- break;=0D
+ case 4:=0D
+ case 5:=0D
+ PortStatus->PortStatus |=3D USB_PORT_STAT_SUPER_SPEED;=0D
+ break;=0D
=0D
- default:=0D
- break;=0D
+ default:=0D
+ break;=0D
+ }=0D
}=0D
}=0D
=0D
--=20
2.37.2