From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web09.4361.1655965312315944364 for ; Wed, 22 Jun 2022 23:21:53 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=gAMjprgi; spf=pass (domain: intel.com, ip: 192.55.52.43, mailfrom: ian.chiu@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655965312; x=1687501312; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=WstFIDCj9fO9VqrTV6EEFOsC6dKUnV08QQMHgBwVSFg=; b=gAMjprgiBN5Nytgsa2YZ8R6AdsXPSRy09R0msnpRixXA2tlwOgse/42m YJ1v2rmNxX8/FSM/cJebqb3dZ542FZJ6iwcDESD+aMF5xEW/RJBMYVR4b Ia4hnBB14ZAHAc0s6032PDLuTu32GDAFCkK8lymh7J+/LjxcQqNbLBFin rHKGNpDV6tt3zxkWS+TyTzXrlI0Lbkb3bdssnFak+Zmq4TeXMIQjWBOqM GVEbWylP17+4zmCtUjnlK5OEdYBj2BoyaSWyrtENNc8WCAKEiVvjBsxqK 6Zhv1Qx9iZ26nFfhSHC08oQS71BWKulH+eShP9NU4far3Ca/ZKlWSe9tf w==; X-IronPort-AV: E=McAfee;i="6400,9594,10386"; a="366957710" X-IronPort-AV: E=Sophos;i="5.92,215,1650956400"; d="scan'208";a="366957710" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2022 23:21:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,215,1650956400"; d="scan'208";a="677922374" Received: from jliu28x-desk3.gar.corp.intel.com ([10.5.215.163]) by FMSMGA003.fm.intel.com with ESMTP; 22 Jun 2022 23:21:49 -0700 From: ian.chiu@intel.com To: devel@edk2.groups.io Cc: Ian Chiu , Jenny Huang , More Shih , Hao A Wu , Ray Ni Subject: [PATCH v4] MdeModulePkg/XhciDxe: Add access xHCI Extended Capabilities Pointer Date: Thu, 23 Jun 2022 14:21:45 +0800 Message-Id: <20220623062145.1388-1-ian.chiu@intel.com> X-Mailer: git-send-email 2.26.2.windows.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Ian Chiu Add support process Port Speed field value of PORTSC according to Supported Protocol Capability (define in xHCI spec 1.1) REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D3914 The value of Port Speed field in PORTSC bit[10:13] (xHCI spec 1.1 section 5.4.8) should be change to use this value to query thru Protocol Speed ID (PSI) (xHCI spec 1.1 section 7.2.1) in xHCI Supported Protocol Capability and return the value according the Protocol Speed ID (PSIV) Dword. With this mechanism may able to detect more kind of Protocol Speed in USB3 and also compatiable with three kind of speed of USB2. Cc: Jenny Huang Cc: More Shih Cc: Hao A Wu Cc: Ray Ni Signed-off-by: Ian Chiu --- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 39 +++-- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h | 2 + MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c | 178 ++++++++++++++++++++ MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.h | 92 +++++++++- 4 files changed, 295 insertions(+), 16 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/Xhc= iDxe/Xhci.c index 381d7a9536..c05431ff30 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c @@ -399,24 +399,31 @@ XhcGetRootHubPortStatus ( =0D //=0D // According to XHCI 1.1 spec November 2017,=0D - // bit 10~13 of the root port status register identifies the speed of th= e attached device.=0D + // Section 7.2 xHCI Support Protocol Capability=0D //=0D - switch ((State & XHC_PORTSC_PS) >> 10) {=0D - case 2:=0D - PortStatus->PortStatus |=3D USB_PORT_STAT_LOW_SPEED;=0D - break;=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 =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 @@ -1826,6 +1833,8 @@ XhcCreateUsbHc ( Xhc->ExtCapRegBase =3D ExtCapReg << 2;=0D Xhc->UsbLegSupOffset =3D XhcGetCapabilityAddr (Xhc, XHC_CAP_USB_LEGACY= );=0D Xhc->DebugCapSupOffset =3D XhcGetCapabilityAddr (Xhc, XHC_CAP_USB_DEBUG)= ;=0D + Xhc->Usb2SupOffset =3D XhcGetSupportedProtocolCapabilityAddr (Xhc, X= HC_SUPPORTED_PROTOCOL_DW0_MAJOR_REVISION_USB2);=0D + Xhc->Usb3SupOffset =3D XhcGetSupportedProtocolCapabilityAddr (Xhc, X= HC_SUPPORTED_PROTOCOL_DW0_MAJOR_REVISION_USB3);=0D =0D DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: Capability length 0x%x\n", Xhc->Ca= pLength));=0D DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: HcSParams1 0x%x\n", Xhc->HcSParams= 1));=0D @@ -1835,6 +1844,8 @@ XhcCreateUsbHc ( DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: RTSOff 0x%x\n", Xhc->RTSOff));=0D DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: UsbLegSupOffset 0x%x\n", Xhc->UsbL= egSupOffset));=0D DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: DebugCapSupOffset 0x%x\n", Xhc->De= bugCapSupOffset));=0D + DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: Usb2SupOffset 0x%x\n", Xhc->Usb2Su= pOffset));=0D + DEBUG ((DEBUG_INFO, "XhcCreateUsb3Hc: Usb3SupOffset 0x%x\n", Xhc->Usb3Su= pOffset));=0D =0D //=0D // Create AsyncRequest Polling Timer=0D diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h b/MdeModulePkg/Bus/Pci/Xhc= iDxe/Xhci.h index 5054d796b1..ca223bd20c 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h @@ -227,6 +227,8 @@ struct _USB_XHCI_INSTANCE { UINT32 ExtCapRegBase;=0D UINT32 UsbLegSupOffset;=0D UINT32 DebugCapSupOffset;=0D + UINT32 Usb2SupOffset;=0D + UINT32 Usb3SupOffset;=0D UINT64 *DCBAA;=0D VOID *DCBAAMap;=0D UINT32 MaxSlotsEn;=0D diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c b/MdeModulePkg/Bus/Pci/= XhciDxe/XhciReg.c index 80be3311d4..2b4a4b2444 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c @@ -575,6 +575,184 @@ XhcGetCapabilityAddr ( return 0xFFFFFFFF;=0D }=0D =0D +/**=0D + Calculate the offset of the xHCI Supported Protocol Capability.=0D +=0D + @param Xhc The XHCI Instance.=0D + @param MajorVersion The USB Major Version in xHCI Support Protocol Cap= ability Field=0D +=0D + @return The offset of xHCI Supported Protocol capability register.=0D +=0D +**/=0D +UINT32=0D +XhcGetSupportedProtocolCapabilityAddr (=0D + IN USB_XHCI_INSTANCE *Xhc,=0D + IN UINT8 MajorVersion=0D + )=0D +{=0D + UINT32 ExtCapOffset;=0D + UINT8 NextExtCapReg;=0D + UINT32 Data;=0D + UINT32 NameString;=0D + XHC_SUPPORTED_PROTOCOL_DW0 UsbSupportDw0;=0D +=0D + if (Xhc =3D=3D NULL) {=0D + return 0;=0D + }=0D +=0D + ExtCapOffset =3D 0;=0D +=0D + do {=0D + //=0D + // Check if the extended capability register's capability id is USB Le= gacy Support.=0D + //=0D + Data =3D XhcReadExtCapReg (Xhc, ExtCapOffset);=0D + UsbSupportDw0.Dword =3D Data;=0D + if ((Data & 0xFF) =3D=3D XHC_CAP_USB_SUPPORTED_PROTOCOL) {=0D + if (UsbSupportDw0.Data.RevMajor =3D=3D MajorVersion) {=0D + NameString =3D XhcReadExtCapReg (Xhc, ExtCapOffset + XHC_SUPPORTED= _PROTOCOL_NAME_STRING_OFFSET);=0D + if (NameString =3D=3D XHC_SUPPORTED_PROTOCOL_NAME_STRING_VALUE) {= =0D + //=0D + // Ensure Name String field is xHCI supported protocols in xHCI = Supported Protocol Capability Offset 04h=0D + //=0D + return ExtCapOffset;=0D + }=0D + }=0D + }=0D +=0D + //=0D + // If not, then traverse all of the ext capability registers till find= ing out it.=0D + //=0D + NextExtCapReg =3D (UINT8)((Data >> 8) & 0xFF);=0D + ExtCapOffset +=3D (NextExtCapReg << 2);=0D + } while (NextExtCapReg !=3D 0);=0D +=0D + return 0xFFFFFFFF;=0D +}=0D +=0D +/**=0D + Find PortSpeed value match Protocol Speed ID Value (PSIV).=0D +=0D + @param Xhc The XHCI Instance.=0D + @param ExtCapOffset The USB Major Version in xHCI Support Protocol Ca= pability Field=0D + @param PortSpeed The Port Speed Field in USB PortSc register=0D +=0D + @return The Protocol Speed ID (PSI) from xHCI Supported Protocol capabil= ity register.=0D +=0D +**/=0D +UINT32=0D +XhciPsivGetPsid (=0D + IN USB_XHCI_INSTANCE *Xhc,=0D + IN UINT32 ExtCapOffset,=0D + IN UINT8 PortSpeed=0D + )=0D +{=0D + XHC_SUPPORTED_PROTOCOL_DW2 PortId;=0D + XHC_SUPPORTED_PROTOCOL_PROTOCOL_SPEED_ID Reg;=0D + UINT32 Count;=0D +=0D + if ((Xhc =3D=3D NULL) || (ExtCapOffset =3D=3D 0xFFFFFFFF)) {=0D + return 0;=0D + }=0D +=0D + //=0D + // According to XHCI 1.1 spec November 2017,=0D + // Section 7.2 xHCI Supported Protocol Capability=0D + // 1. Get the PSIC(Protocol Speed ID Count) value.=0D + // 2. The PSID register boundary should be Base address + PSIC * 0x04=0D + //=0D + PortId.Dword =3D XhcReadExtCapReg (Xhc, ExtCapOffset + XHC_SUPPORTED_PRO= TOCOL_DW2_OFFSET);=0D +=0D + for (Count =3D 0; Count < PortId.Data.Psic; Count++) {=0D + Reg.Dword =3D XhcReadExtCapReg (Xhc, ExtCapOffset + XHC_SUPPORTED_PROT= OCOL_PSI_OFFSET + (Count << 2));=0D + if (Reg.Data.Psiv =3D=3D PortSpeed) {=0D + return Reg.Dword;=0D + }=0D + }=0D +=0D + return 0;=0D +}=0D +=0D +/**=0D + Find PortSpeed value match case in XHCI Supported Protocol Capability=0D +=0D + @param Xhc The XHCI Instance.=0D + @param PortSpeed The Port Speed Field in USB PortSc register=0D +=0D + @return The USB Port Speed.=0D +=0D +**/=0D +UINT16=0D +XhcCheckUsbPortSpeedUsedPsic (=0D + IN USB_XHCI_INSTANCE *Xhc,=0D + IN UINT8 PortSpeed=0D + )=0D +{=0D + XHC_SUPPORTED_PROTOCOL_PROTOCOL_SPEED_ID SpField;=0D + UINT16 UsbSpeedIdMap;=0D +=0D + if (Xhc =3D=3D NULL) {=0D + return 0;=0D + }=0D +=0D + SpField.Dword =3D 0;=0D + UsbSpeedIdMap =3D 0;=0D +=0D + //=0D + // Check xHCI Supported Protocol Capability, find the PSIV field to matc= h=0D + // PortSpeed definition when the Major Revision is 03h.=0D + //=0D + if (Xhc->Usb3SupOffset !=3D 0xFFFFFFFF) {=0D + SpField.Dword =3D XhciPsivGetPsid (Xhc, Xhc->Usb3SupOffset, PortSpeed)= ;=0D + if (SpField.Dword !=3D 0) {=0D + //=0D + // Found the corresponding PORTSC value in PSIV field of USB3 offset= .=0D + //=0D + UsbSpeedIdMap =3D USB_PORT_STAT_SUPER_SPEED;=0D + }=0D + }=0D +=0D + //=0D + // Check xHCI Supported Protocol Capability, find the PSIV field to matc= h=0D + // PortSpeed definition when the Major Revision is 02h.=0D + //=0D + if ((UsbSpeedIdMap =3D=3D 0) && (Xhc->Usb2SupOffset !=3D 0xFFFFFFFF)) {= =0D + SpField.Dword =3D XhciPsivGetPsid (Xhc, Xhc->Usb2SupOffset, PortSpeed)= ;=0D + if (SpField.Dword !=3D 0) {=0D + //=0D + // Found the corresponding PORTSC value in PSIV field of USB2 offset= .=0D + //=0D + if (SpField.Data.Psie =3D=3D 2) {=0D + //=0D + // According to XHCI 1.1 spec November 2017,=0D + // Section 7.2.1 the Protocol Speed ID Exponent (PSIE) field defin= ition,=0D + // PSIE value shall be applied to Protocol Speed ID Mantissa when = calculating, value 2 shall represent bit rate in Mb/s=0D + //=0D + if (SpField.Data.Psim =3D=3D XHC_SUPPORTED_PROTOCOL_USB2_HIGH_SPEE= D_PSIM) {=0D + //=0D + // PSIM shows as default High-speed protocol, apply to High-spee= d mapping=0D + //=0D + UsbSpeedIdMap =3D USB_PORT_STAT_HIGH_SPEED;=0D + }=0D + } else if (SpField.Data.Psie =3D=3D 1) {=0D + //=0D + // According to XHCI 1.1 spec November 2017,=0D + // Section 7.2.1 the Protocol Speed ID Exponent (PSIE) field defin= ition,=0D + // PSIE value shall be applied to Protocol Speed ID Mantissa when = calculating, value 1 shall represent bit rate in Kb/s=0D + //=0D + if (SpField.Data.Psim =3D=3D XHC_SUPPORTED_PROTOCOL_USB2_LOW_SPEED= _PSIM) {=0D + //=0D + // PSIM shows as default Low-speed protocol, apply to Low-speed = mapping=0D + //=0D + UsbSpeedIdMap =3D USB_PORT_STAT_LOW_SPEED;=0D + }=0D + }=0D + }=0D + }=0D +=0D + return UsbSpeedIdMap;=0D +}=0D +=0D /**=0D Whether the XHCI host controller is halted.=0D =0D diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.h b/MdeModulePkg/Bus/Pci/= XhciDxe/XhciReg.h index 4950eed272..94b53c8335 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.h +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.h @@ -25,8 +25,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define USB_HUB_CLASS_CODE 0x09=0D #define USB_HUB_SUBCLASS_CODE 0x00=0D =0D -#define XHC_CAP_USB_LEGACY 0x01=0D -#define XHC_CAP_USB_DEBUG 0x0A=0D +#define XHC_CAP_USB_LEGACY 0x01=0D +#define XHC_CAP_USB_DEBUG 0x0A=0D +#define XHC_CAP_USB_SUPPORTED_PROTOCOL 0x02=0D =0D // =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D//=0D // XHCI register offset //=0D @@ -74,6 +75,18 @@ SPDX-License-Identifier: BSD-2-Clause-Patent #define USBLEGSP_BIOS_SEMAPHORE BIT16 // HC BIOS Owned Semaphor= e=0D #define USBLEGSP_OS_SEMAPHORE BIT24 // HC OS Owned Semaphore= =0D =0D +//=0D +// xHCI Supported Protocol Capability=0D +//=0D +#define XHC_SUPPORTED_PROTOCOL_DW0_MAJOR_REVISION_USB2 0x02=0D +#define XHC_SUPPORTED_PROTOCOL_DW0_MAJOR_REVISION_USB3 0x03=0D +#define XHC_SUPPORTED_PROTOCOL_NAME_STRING_OFFSET 0x04=0D +#define XHC_SUPPORTED_PROTOCOL_NAME_STRING_VALUE 0x20425355=0D +#define XHC_SUPPORTED_PROTOCOL_DW2_OFFSET 0x08=0D +#define XHC_SUPPORTED_PROTOCOL_PSI_OFFSET 0x10=0D +#define XHC_SUPPORTED_PROTOCOL_USB2_HIGH_SPEED_PSIM 480=0D +#define XHC_SUPPORTED_PROTOCOL_USB2_LOW_SPEED_PSIM 1500=0D +=0D #pragma pack (1)=0D typedef struct {=0D UINT8 MaxSlots; // Number of Device Slots=0D @@ -130,6 +143,52 @@ typedef union { HCCPARAMS Data;=0D } XHC_HCCPARAMS;=0D =0D +//=0D +// xHCI Supported Protocol Cabability=0D +//=0D +typedef struct {=0D + UINT8 CapId;=0D + UINT8 NextExtCapReg;=0D + UINT8 RevMinor;=0D + UINT8 RevMajor;=0D +} SUPPORTED_PROTOCOL_DW0;=0D +=0D +typedef union {=0D + UINT32 Dword;=0D + SUPPORTED_PROTOCOL_DW0 Data;=0D +} XHC_SUPPORTED_PROTOCOL_DW0;=0D +=0D +typedef struct {=0D + UINT32 NameString;=0D +} XHC_SUPPORTED_PROTOCOL_DW1;=0D +=0D +typedef struct {=0D + UINT8 CompPortOffset;=0D + UINT8 CompPortCount;=0D + UINT16 ProtocolDef : 12;=0D + UINT16 Psic : 4;=0D +} SUPPORTED_PROTOCOL_DW2;=0D +=0D +typedef union {=0D + UINT32 Dword;=0D + SUPPORTED_PROTOCOL_DW2 Data;=0D +} XHC_SUPPORTED_PROTOCOL_DW2;=0D +=0D +typedef struct {=0D + UINT16 Psiv : 4;=0D + UINT16 Psie : 2;=0D + UINT16 Plt : 2;=0D + UINT16 Pfd : 1;=0D + UINT16 RsvdP : 5;=0D + UINT16 Lp : 2;=0D + UINT16 Psim;=0D +} SUPPORTED_PROTOCOL_PROTOCOL_SPEED_ID;=0D +=0D +typedef union {=0D + UINT32 Dword;=0D + SUPPORTED_PROTOCOL_PROTOCOL_SPEED_ID Data;=0D +} XHC_SUPPORTED_PROTOCOL_PROTOCOL_SPEED_ID;=0D +=0D #pragma pack ()=0D =0D //=0D @@ -546,4 +605,33 @@ XhcGetCapabilityAddr ( IN UINT8 CapId=0D );=0D =0D +/**=0D + Calculate the offset of the xHCI Supported Protocol Capability.=0D +=0D + @param Xhc The XHCI Instance.=0D + @param MajorVersion The USB Major Version in xHCI Support Protocol Cap= ability Field=0D +=0D + @return The offset of xHCI Supported Protocol capability register.=0D +=0D +**/=0D +UINT32=0D +XhcGetSupportedProtocolCapabilityAddr (=0D + IN USB_XHCI_INSTANCE *Xhc,=0D + IN UINT8 MajorVersion=0D + );=0D +=0D +/**=0D + Find SpeedField value match with Port Speed ID value.=0D +=0D + @param Xhc The XHCI Instance.=0D + @param Speed The Port Speed filed in USB PortSc register=0D +=0D + @return The USB Port Speed.=0D +=0D +**/=0D +UINT16=0D +XhcCheckUsbPortSpeedUsedPsic (=0D + IN USB_XHCI_INSTANCE *Xhc,=0D + IN UINT8 Speed=0D + );=0D #endif=0D --=20 2.26.2.windows.1