On some platforms, including Sky Lake and Kaby Lake, the PSIV (Protocol
Speed ID Value) indices are shared between Protocol Speed ID DWORD' in
the extended capabilities registers for both USB2 (Full Speed) and USB3
(Super Speed).
An example can be found below:
XhcCheckUsbPortSpeedUsedPsic: checking for USB2 ext caps
XhciPsivGetPsid: found 3 PSID entries
XhciPsivGetPsid: looking for port speed 1
XhciPsivGetPsid: PSIV 1 PSIE 2 PLT 0 PSIM 12
XhciPsivGetPsid: PSIV 2 PSIE 1 PLT 0 PSIM 1500
XhciPsivGetPsid: PSIV 3 PSIE 2 PLT 0 PSIM 480
XhcCheckUsbPortSpeedUsedPsic: checking for USB3 ext caps
XhciPsivGetPsid: found 3 PSID entries
XhciPsivGetPsid: looking for port speed 1
XhciPsivGetPsid: PSIV 1 PSIE 3 PLT 0 PSIM 5
XhciPsivGetPsid: PSIV 2 PSIE 3 PLT 0 PSIM 10
XhciPsivGetPsid: PSIV 34 PSIE 2 PLT 0 PSIM 1248
The result is edk2 detecting USB2 devices as USB3 devices, which
consequently causes enumeration to fail.
To avoid incorrect detection, check the Compatible Port Offset to find
the starting Port of Root Hubs that support the protocol.
Signed-off-by: Sean Rhodes <sean@starlabs.systems>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
// Section 7.2 xHCI Support Protocol Capability\r
//\r
if (PortSpeed > 0) {\r
// Section 7.2 xHCI Support Protocol Capability\r
//\r
if (PortSpeed > 0) {\r
- PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc, PortSpeed);\r
+ PortStatus->PortStatus = XhcCheckUsbPortSpeedUsedPsic (Xhc, PortSpeed, PortNumber);\r
// If no match found in ext cap reg, fall back to PORTSC\r
if (PortStatus->PortStatus == 0) {\r
//\r
// If no match found in ext cap reg, fall back to PORTSC\r
if (PortStatus->PortStatus == 0) {\r
//\r
@param Xhc The XHCI Instance.\r
@param ExtCapOffset The USB Major Version in xHCI Support Protocol Capability Field\r
@param PortSpeed The Port Speed Field in USB PortSc register\r
@param Xhc The XHCI Instance.\r
@param ExtCapOffset The USB Major Version in xHCI Support Protocol Capability Field\r
@param PortSpeed The Port Speed Field in USB PortSc register\r
+ @param PortNumber The Port Number (0-indexed)\r
\r
@return The Protocol Speed ID (PSI) from xHCI Supported Protocol capability register.\r
\r
\r
@return The Protocol Speed ID (PSI) from xHCI Supported Protocol capability register.\r
\r
XhciPsivGetPsid (\r
IN USB_XHCI_INSTANCE *Xhc,\r
IN UINT32 ExtCapOffset,\r
XhciPsivGetPsid (\r
IN USB_XHCI_INSTANCE *Xhc,\r
IN UINT32 ExtCapOffset,\r
+ IN UINT8 PortSpeed,\r
+ IN UINT8 PortNumber\r
)\r
{\r
XHC_SUPPORTED_PROTOCOL_DW2 PortId;\r
XHC_SUPPORTED_PROTOCOL_PROTOCOL_SPEED_ID Reg;\r
UINT32 Count;\r
)\r
{\r
XHC_SUPPORTED_PROTOCOL_DW2 PortId;\r
XHC_SUPPORTED_PROTOCOL_PROTOCOL_SPEED_ID Reg;\r
UINT32 Count;\r
+ UINT32 MinPortIndex;\r
+ UINT32 MaxPortIndex;\r
\r
if ((Xhc == NULL) || (ExtCapOffset == 0xFFFFFFFF)) {\r
return 0;\r
\r
if ((Xhc == NULL) || (ExtCapOffset == 0xFFFFFFFF)) {\r
return 0;\r
//\r
PortId.Dword = XhcReadExtCapReg (Xhc, ExtCapOffset + XHC_SUPPORTED_PROTOCOL_DW2_OFFSET);\r
\r
//\r
PortId.Dword = XhcReadExtCapReg (Xhc, ExtCapOffset + XHC_SUPPORTED_PROTOCOL_DW2_OFFSET);\r
\r
+ //\r
+ // According to XHCI 1.1 spec November 2017, valid values\r
+ // for CompPortOffset are 1 to CompPortCount - 1.\r
+ //\r
+ // PortNumber is zero-indexed, so subtract 1.\r
+ //\r
+ if ((PortId.Data.CompPortOffset == 0) || (PortId.Data.CompPortCount == 0)) {\r
+ return 0;\r
+ }\r
+\r
+ MinPortIndex = PortId.Data.CompPortOffset - 1;\r
+ MaxPortIndex = MinPortIndex + PortId.Data.CompPortCount - 1;\r
+\r
+ if ((PortNumber < MinPortIndex) || (PortNumber > MaxPortIndex)) {\r
+ return 0;\r
+ }\r
+\r
for (Count = 0; Count < PortId.Data.Psic; Count++) {\r
Reg.Dword = XhcReadExtCapReg (Xhc, ExtCapOffset + XHC_SUPPORTED_PROTOCOL_PSI_OFFSET + (Count << 2));\r
if (Reg.Data.Psiv == PortSpeed) {\r
for (Count = 0; Count < PortId.Data.Psic; Count++) {\r
Reg.Dword = XhcReadExtCapReg (Xhc, ExtCapOffset + XHC_SUPPORTED_PROTOCOL_PSI_OFFSET + (Count << 2));\r
if (Reg.Data.Psiv == PortSpeed) {\r
/**\r
Find PortSpeed value match case in XHCI Supported Protocol Capability\r
\r
/**\r
Find PortSpeed value match case in XHCI Supported Protocol Capability\r
\r
- @param Xhc The XHCI Instance.\r
- @param PortSpeed The Port Speed Field in USB PortSc register\r
+ @param Xhc The XHCI Instance.\r
+ @param PortSpeed The Port Speed Field in USB PortSc register\r
+ @param PortNumber The Port Number (0-indexed)\r
\r
@return The USB Port Speed.\r
\r
\r
@return The USB Port Speed.\r
\r
UINT16\r
XhcCheckUsbPortSpeedUsedPsic (\r
IN USB_XHCI_INSTANCE *Xhc,\r
UINT16\r
XhcCheckUsbPortSpeedUsedPsic (\r
IN USB_XHCI_INSTANCE *Xhc,\r
+ IN UINT8 PortSpeed,\r
+ IN UINT8 PortNumber\r
)\r
{\r
XHC_SUPPORTED_PROTOCOL_PROTOCOL_SPEED_ID SpField;\r
)\r
{\r
XHC_SUPPORTED_PROTOCOL_PROTOCOL_SPEED_ID SpField;\r
// PortSpeed definition when the Major Revision is 03h.\r
//\r
if (Xhc->Usb3SupOffset != 0xFFFFFFFF) {\r
// PortSpeed definition when the Major Revision is 03h.\r
//\r
if (Xhc->Usb3SupOffset != 0xFFFFFFFF) {\r
- SpField.Dword = XhciPsivGetPsid (Xhc, Xhc->Usb3SupOffset, PortSpeed);\r
+ SpField.Dword = XhciPsivGetPsid (Xhc, Xhc->Usb3SupOffset, PortSpeed, PortNumber);\r
if (SpField.Dword != 0) {\r
//\r
// Found the corresponding PORTSC value in PSIV field of USB3 offset.\r
if (SpField.Dword != 0) {\r
//\r
// Found the corresponding PORTSC value in PSIV field of USB3 offset.\r
// PortSpeed definition when the Major Revision is 02h.\r
//\r
if ((UsbSpeedIdMap == 0) && (Xhc->Usb2SupOffset != 0xFFFFFFFF)) {\r
// PortSpeed definition when the Major Revision is 02h.\r
//\r
if ((UsbSpeedIdMap == 0) && (Xhc->Usb2SupOffset != 0xFFFFFFFF)) {\r
- SpField.Dword = XhciPsivGetPsid (Xhc, Xhc->Usb2SupOffset, PortSpeed);\r
+ SpField.Dword = XhciPsivGetPsid (Xhc, Xhc->Usb2SupOffset, PortSpeed, PortNumber);\r
if (SpField.Dword != 0) {\r
//\r
// Found the corresponding PORTSC value in PSIV field of USB2 offset.\r
if (SpField.Dword != 0) {\r
//\r
// Found the corresponding PORTSC value in PSIV field of USB2 offset.\r
- Find SpeedField value match with Port Speed ID value.\r
+ Find PortSpeed value match case in XHCI Supported Protocol Capability\r
- @param Xhc The XHCI Instance.\r
- @param Speed The Port Speed filed in USB PortSc register\r
+ @param Xhc The XHCI Instance.\r
+ @param PortSpeed The Port Speed Field in USB PortSc register\r
+ @param PortNumber The Port Number (0-indexed)\r
\r
@return The USB Port Speed.\r
\r
\r
@return The USB Port Speed.\r
\r
UINT16\r
XhcCheckUsbPortSpeedUsedPsic (\r
IN USB_XHCI_INSTANCE *Xhc,\r
UINT16\r
XhcCheckUsbPortSpeedUsedPsic (\r
IN USB_XHCI_INSTANCE *Xhc,\r
+ IN UINT8 PortSpeed,\r
+ IN UINT8 PortNumber\r