From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=star.zeng@intel.com; receiver=edk2-devel@lists.01.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C19B72111FE70 for ; Wed, 5 Sep 2018 18:37:42 -0700 (PDT) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Sep 2018 18:37:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,334,1531810800"; d="scan'208";a="88024492" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by orsmga001.jf.intel.com with ESMTP; 05 Sep 2018 18:35:44 -0700 Received: from fmsmsx101.amr.corp.intel.com (10.18.124.199) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 5 Sep 2018 18:35:44 -0700 Received: from shsmsx103.ccr.corp.intel.com (10.239.4.69) by fmsmsx101.amr.corp.intel.com (10.18.124.199) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 5 Sep 2018 18:35:43 -0700 Received: from shsmsx102.ccr.corp.intel.com ([169.254.2.226]) by SHSMSX103.ccr.corp.intel.com ([169.254.4.240]) with mapi id 14.03.0319.002; Thu, 6 Sep 2018 09:35:40 +0800 From: "Zeng, Star" To: Laszlo Ersek , edk2-devel-01 CC: "Ni, Ruiyu" , "Zeng, Star" Thread-Topic: [edk2] [PATCH] MdeModulePkg/EhciDxe: factor out EhcIsDebugPortInUse() Thread-Index: AQHURVEFeU4WZ4nOXUWCCSHXbS3xsqTiePHQ Date: Thu, 6 Sep 2018 01:35:39 +0000 Message-ID: <0C09AFA07DD0434D9E2A0C6AEB0483103BBB5A94@shsmsx102.ccr.corp.intel.com> References: <20180905194519.534-1-lersek@redhat.com> In-Reply-To: <20180905194519.534-1-lersek@redhat.com> Accept-Language: zh-CN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.239.127.40] MIME-Version: 1.0 Subject: Re: [PATCH] MdeModulePkg/EhciDxe: factor out EhcIsDebugPortInUse() X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Sep 2018 01:37:43 -0000 Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Thanks for the quick following up. :) Reviewed-by: Star Zeng Star -----Original Message----- From: edk2-devel [mailto:edk2-devel-bounces@lists.01.org] On Behalf Of Lasz= lo Ersek Sent: Thursday, September 6, 2018 3:45 AM To: edk2-devel-01 Cc: Ni, Ruiyu ; Zeng, Star Subject: [edk2] [PATCH] MdeModulePkg/EhciDxe: factor out EhcIsDebugPortInUs= e() The EhcReset(), EhcGetRootHubPortStatus() and EhcDriverBindingStart() funct= ions need to see whether the host controller (or a specific port on the hos= t controller) can be accessed, dependent on the controller having (or the s= pecific port being) an in-use debug port. Because the condition isn't simpl= e, extract it to a separate function. Cc: Ruiyu Ni Cc: Star Zeng Suggested-by: Star Zeng Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Laszlo Ersek --- Notes: Repo: https://github.com/lersek/edk2.git Branch: ehci_dbgport_in_use MdeModulePkg/Bus/Pci/EhciDxe/Ehci.h | 2 + MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.h | 27 ++++++---- MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c | 26 +++------ MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c | 55 +++++++++++++++++++- 4 files changed, 80 insertions(+), 30 deletions(-) diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.h b/MdeModulePkg/Bus/Pci/Ehc= iDxe/Ehci.h index f7556754f8ea..d7fbecb43003 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.h +++ b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.h @@ -77,6 +77,8 @@ typedef struct _USB2_HC_DEV USB2_HC_DEV; #define USB_DEBUG_PORT_IN_USE BIT10 #define USB_DEBUG_PORT_ENABLE BIT28 #define USB_DEBUG_PORT_OWNER BIT30 +#define USB_DEBUG_PORT_IN_USE_MASK (USB_DEBUG_PORT_IN_USE | \ + USB_DEBUG_PORT_OWNER) =20 // // EHC raises TPL to TPL_NOTIFY to serialize all its operations diff --git= a/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.h b/MdeModulePkg/Bus/Pci/EhciDxe/Eh= ciReg.h index 2347ee125fa7..1ee12455b8d0 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.h +++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.h @@ -137,19 +137,28 @@ EhcReadCapRegister ( ); =20 /** - Read EHCI debug port register. + Check whether the host controller has an in-use debug port. =20 - @param Ehc The EHCI device. - @param Offset Debug port register address. + @param[in] Ehc The Enhanced Host Controller to query. =20 - @return The register content read. - @retval If err, return 0xffff. + @param[in] PortNumber If PortNumber is not NULL, then query whether + PortNumber is an in-use debug port on Ehc. (PortN= umber + is taken in UEFI notation, i.e., zero-based.) + Otherwise, query whether Ehc has any in-use debug + port. =20 + @retval TRUE PortNumber is an in-use debug port on Ehc (if PortNumber = is + not NULL), or some port on Ehc is an in-use debug port + (otherwise). + + @retval FALSE PortNumber is not an in-use debug port on Ehc (if PortNum= ber + is not NULL), or no port on Ehc is an in-use debug port + (otherwise). **/ -UINT32 -EhcReadDbgRegister ( - IN USB2_HC_DEV *Ehc, - IN UINT32 Offset +BOOLEAN +EhcIsDebugPortInUse ( + IN CONST USB2_HC_DEV *Ehc, + IN CONST UINT8 *PortNumber OPTIONAL ); =20 /** diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c b/MdeModulePkg/Bus/Pci/Ehc= iDxe/Ehci.c index 89ed034b9093..50b5598df4fb 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/Ehci.c @@ -121,7 +121,6 @@ EhcReset ( USB2_HC_DEV *Ehc; EFI_TPL OldTpl; EFI_STATUS Status; - UINT32 DbgCtrlStatus; =20 Ehc =3D EHC_FROM_THIS (This); =20 @@ -147,12 +146,9 @@ EhcReset ( // // Host Controller must be Halt when Reset it // - if (Ehc->DebugPortNum !=3D 0) { - DbgCtrlStatus =3D EhcReadDbgRegister(Ehc, 0); - if ((DbgCtrlStatus & (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER))= =3D=3D (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) { - Status =3D EFI_SUCCESS; - goto ON_EXIT; - } + if (EhcIsDebugPortInUse (Ehc, NULL)) { + Status =3D EFI_SUCCESS; + goto ON_EXIT; } =20 if (!EhcIsHalt (Ehc)) { @@ -345,7 +341,6 @@ EhcGetRootHubPortStatus ( UINTN Index; UINTN MapSize; EFI_STATUS Status; - UINT32 DbgCtrlStatus; =20 if (PortStatus =3D=3D NULL) { return EFI_INVALID_PARAMETER; @@ -367,11 +362,8 @@ EhcGetRootHubPortStatus ( PortStatus->PortStatus =3D 0; PortStatus->PortChangeStatus =3D 0; =20 - if ((Ehc->DebugPortNum !=3D 0) && (PortNumber =3D=3D (Ehc->DebugPortNum = - 1))) { - DbgCtrlStatus =3D EhcReadDbgRegister(Ehc, 0); - if ((DbgCtrlStatus & (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) = =3D=3D (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) { - goto ON_EXIT; - } + if (EhcIsDebugPortInUse (Ehc, &PortNumber)) { + goto ON_EXIT; } =20 State =3D EhcReadOpReg (Ehc, Offset); @@ -1696,7 +1688,6 @@ EhcDriverBindingStart ( UINTN EhciBusNumber; UINTN EhciDeviceNumber; UINTN EhciFunctionNumber; - UINT32 State; EFI_DEVICE_PATH_PROTOCOL *HcDevicePath; =20 // @@ -1918,13 +1909,8 @@ EhcDriverBindingStart ( EhcClearLegacySupport (Ehc); } =20 - if (Ehc->DebugPortNum =3D=3D 0) { + if (!EhcIsDebugPortInUse (Ehc, NULL)) { EhcResetHC (Ehc, EHC_RESET_TIMEOUT); - } else { - State =3D EhcReadDbgRegister(Ehc, 0); - if ((State & (USB_DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) !=3D (USB= _DEBUG_PORT_IN_USE | USB_DEBUG_PORT_OWNER)) { - EhcResetHC (Ehc, EHC_RESET_TIMEOUT); - } } =20 Status =3D EhcInitHC (Ehc); diff --git a/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c b/MdeModulePkg/Bus/Pci/= EhciDxe/EhciReg.c index 59752d1bdc64..11c36132fd4f 100644 --- a/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c +++ b/MdeModulePkg/Bus/Pci/EhciDxe/EhciReg.c @@ -65,7 +65,7 @@ EhcReadCapRegister ( **/ UINT32 EhcReadDbgRegister ( - IN USB2_HC_DEV *Ehc, + IN CONST USB2_HC_DEV *Ehc, IN UINT32 Offset ) { @@ -90,6 +90,59 @@ EhcReadDbgRegister ( } =20 =20 +/** + Check whether the host controller has an in-use debug port. + + @param[in] Ehc The Enhanced Host Controller to query. + + @param[in] PortNumber If PortNumber is not NULL, then query whether + PortNumber is an in-use debug port on Ehc. (PortN= umber + is taken in UEFI notation, i.e., zero-based.) + Otherwise, query whether Ehc has any in-use debug + port. + + @retval TRUE PortNumber is an in-use debug port on Ehc (if PortNumber = is + not NULL), or some port on Ehc is an in-use debug port + (otherwise). + + @retval FALSE PortNumber is not an in-use debug port on Ehc (if PortNum= ber + is not NULL), or no port on Ehc is an in-use debug port + (otherwise). +**/ +BOOLEAN +EhcIsDebugPortInUse ( + IN CONST USB2_HC_DEV *Ehc, + IN CONST UINT8 *PortNumber OPTIONAL + ) +{ + UINT32 State; + + if (Ehc->DebugPortNum =3D=3D 0) { + // + // The host controller has no debug port. + // + return FALSE; + } + + // + // The Debug Port Number field in HCSPARAMS is one-based. + // + if (PortNumber !=3D NULL && *PortNumber !=3D Ehc->DebugPortNum - 1) { + // + // The caller specified a port, but it's not the debug port of the hos= t + // controller. + // + return FALSE; + } + + // + // Deduce usage from the Control Register. + // + State =3D EhcReadDbgRegister(Ehc, 0); + return (State & USB_DEBUG_PORT_IN_USE_MASK) =3D=3D=20 +USB_DEBUG_PORT_IN_USE_MASK; } + + /** Read EHCI Operation register. =20 -- 2.14.1.3.gb7cf6e02401b _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel