From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id E7FD2AC08EC for ; Fri, 11 Aug 2023 01:45:14 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=nt9PhO93VOIxhksC+Jn3p6Ivhs2RvtH8FcD6o/9tYFo=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1691718313; v=1; b=tP9ViqWZ8JxAgdxA8zFXpbyf2XuXsIhUn//eHewJ6FWRb1un3UoTAvtvKEtSopvZmmR87aGJ RtnuM0UV0venjR1VYQON6uc5eX4uv575z2czAa4aqA5yvYNkjF8gbPf9dq5/ZaHWSkOK/lKDFwI NfGaOH2P/aPhYM2hLkyCsbKg= X-Received: by 127.0.0.2 with SMTP id IgF9YY7687511xQWOXH9b6RF; Thu, 10 Aug 2023 18:45:13 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.65]) by mx.groups.io with SMTP id smtpd.web10.34504.1691718312536390147 for ; Thu, 10 Aug 2023 18:45:12 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10798"; a="375281473" X-IronPort-AV: E=Sophos;i="6.01,164,1684825200"; d="scan'208";a="375281473" X-Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Aug 2023 18:43:18 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10798"; a="822488773" X-IronPort-AV: E=Sophos;i="6.01,164,1684825200"; d="scan'208";a="822488773" X-Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by FMSMGA003.fm.intel.com with ESMTP; 10 Aug 2023 18:43:17 -0700 X-Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 10 Aug 2023 18:43:11 -0700 X-Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Thu, 10 Aug 2023 18:43:11 -0700 X-Received: from ORSEDG601.ED.cps.intel.com (10.7.248.6) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Thu, 10 Aug 2023 18:43:11 -0700 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.40) by edgegateway.intel.com (134.134.137.102) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.27; Thu, 10 Aug 2023 18:43:08 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e2xSf9IYnfktzI2RM4nZjPY/oGAx5S2JSIJo4dg2x0nuWYPXXMsplsKlxB0W/0yg19uwourvczK9WGcRAFj3xriamm5So3zaX3yYpgctSmHgQ6ABTG6h/f9Wpy7lqwEB0Ze79f03uDaImITavG1uTlM/akQhqp1PVHqQHD+QPvDX3xvF6F5k1+7wS6h6cPHzgXQvrUsDpyAQt2QKV5FlE6y+wGb58teVvuBtWJZTzi15vbGQGy3mvNRmC2lY1pan9KPu/2w0+6IGf0TMew+gquQEfUQ00xhpGJ/JLG+77qYIY0XOTaQpSIQlc+0dGSCy0zswSCQlIkzxU/VfHH5A1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=m16j30zXS2TB1P6Y9Z4am/L+XQLpaMAr0QebE414nws=; b=icOLTbhm4mqIpHowtRlWMxcvwVpt48IT5KtJeLIGLqeyeJWqltphZ+lTv+VPUVTOMiWzuNj+tL/jbd2YhcL1HGUdb6v4yK6wRNeDrah4Io/Hp8kVM2OBSJ0G3iY3TRJLtTFAMZGfJ8phOQf6wKXHMagJtzQd98e/cMan4K5UoY8NULIiTYsG2UFnVqpj9eKgm5mfFJZ0iZ1yB0gUsPofHrigF8guvK0E2FGIhA0UOpBuz/ru2i+uSrdsRyxmN6FWkaoP+Y9u62TQ1GiAeuOsiVK0AtkoTYzlyEMZFI3gB4lu334Kz4nNJBrN2wLCIiXPP7ZCNb9MytDRcxvurcjPtw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none X-Received: from DM6PR11MB4025.namprd11.prod.outlook.com (2603:10b6:5:197::31) by BL1PR11MB5511.namprd11.prod.outlook.com (2603:10b6:208:317::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6678.19; Fri, 11 Aug 2023 01:43:01 +0000 X-Received: from DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::ebe2:341b:4ed7:d19b]) by DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::ebe2:341b:4ed7:d19b%6]) with mapi id 15.20.6652.029; Fri, 11 Aug 2023 01:43:01 +0000 From: "Wu, Hao A" To: "Henz, Patrick" , "devel@edk2.groups.io" , Michael Brown Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts Thread-Topic: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts Thread-Index: AQHZr32iafvIU0JyA0+vZWQmCs2v8a/TT1yggBEKMoCAADEbgA== Date: Fri, 11 Aug 2023 01:43:01 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM6PR11MB4025:EE_|BL1PR11MB5511:EE_ x-ms-office365-filtering-correlation-id: 5211d3f3-534d-4dd6-8496-08db9a0c4c75 x-ld-processed: 46c98d88-e344-4ed4-8496-4ed7712e255d,ExtAddr x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: rEb5R13mcUZwrUVTmK+87GwASTbuS6ITpCtbs9/mksI9TgdlFEFsqwhVv91+pdpfSDIC8cckrE6W9A5dGNz0C+qxgljD++diZ3hspJChqmOWCTDgXiJ/J+GoRoICBwQNF6N9q8uWtPSry+XH+GHJxMIw8FxEnto4XwQcT49O+yx90K870f+DQ/QH8jPe60xS4ElbyOiQz8YE1H5l44XjP9I112NjG5scswx4AH7IliPil5VaadN39TmllsAbgw3wHGZkKTc7YPKHjQsJ4Vmz1ujzAjbKU04TS5ebHgEnVB7bLuuDvkjxNVH0x9dulxG0dlu5trem/QioEWge8cXqinG9W2disSY1N7Sb0mq8P23ZR9+Q1vwbrDFHcdUoKDsWcnrt+F60He2qZWqUhRXF+2JxXGuPdRhtfz/8Y2Mlk3iWRobgO3VMbmImLBW3FMthMv2LmTQT9SKqz0bD5xZlsx2LPiHKZ7okj0ma6qh5Vg/O7lh2b3NGxMSkGkc4KPvQ3lROOYdX89C29b80NIoKNJY8YH361P7I20OdN/Ep0Szmq2RxCg69CyrMlsTx/U9DZnHWQrqzB/V50ppgKbRuzyfG3kAcJPEFACr1nBzxURZJr8mHpD2mYIwl57SgLn/Ux1KHY0Hqt73QUzj/XOdIyA== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?T1JySqRtKJ92QTcK6Wvpj6rnK/6XG9Y7ZowD3jYy9jU04VX8ENmsIz/s8pK7?= =?us-ascii?Q?JN88zqg/xlBq2U3PyRyzNpb0IxkwZ6S5qKHQrCXJASXHDupRWw2ijs3evsz7?= =?us-ascii?Q?jtJpyuKhU/Nu73oasD11rY7xxMe27WRLAa79js0tCYz81s3TeUkeMJjUkySz?= =?us-ascii?Q?rKGlqh/YLGub76zz+7Ck+grkkzQTUgXIBB/vT8R0NV0vDXZH4wv/qvrAOZsb?= =?us-ascii?Q?Ilfq9k/6kOA505U2uKZsEZ/XWzFtTTxHg4vYLwo+x92OAVbIuDGlm962YqQ2?= =?us-ascii?Q?O7U+gQ5j8gmrGQI9lO4C7KekrJDReGMqhmSXoVtMD/5ngi+koRBPh0f/qj3s?= =?us-ascii?Q?7+uUSxUVkab17tTG4ljLkEhjAvk+6PgbZC8kVTg6YantB0OswoA8pFg3SDAF?= =?us-ascii?Q?iNOkRmGcjnKinS4l9cGlRZoI45cYjesZ9rc5dMpNK9s/nRbV38rzbduosGWg?= =?us-ascii?Q?m8FVcY5AHStFvVK5ZuMKZYr7oqy/SFQMZxA5u52QHNDH1YpcaqeZfkjQFbGs?= =?us-ascii?Q?mYe5uulVQDbd5ISz76w/KnawhqX7vmb2Zehx6KQgivSPseTHawV0BqzLaZ5C?= =?us-ascii?Q?s9WROLZiRWOLODF8p3YpPNQZZeNCC5LwyatYaTxyYNZPdmYPVY2Xwnvje4a6?= =?us-ascii?Q?clIQ2ElxJrVLpiiAcoCdtvsxeBul5H4vNSL+kvYjH/ELqJaJ9q2AIi5x6rab?= =?us-ascii?Q?Cq3vwOrQznOvqx4hO6/GD0GMamflV+PPQVetVnO8dg45XW5lO2PWRYsNBTIe?= =?us-ascii?Q?uFqLabcx3EXGu/hcsS3h0r7DiI96iBTTjR6Rx9bipB38SPQh55Z775UxVp24?= =?us-ascii?Q?gHDEJRYPF1CJx4bNCh9ofZk9sQFAnX2kE6TwgC7P6iiv7UggwMNQX5ylqNAL?= =?us-ascii?Q?nFl8/XAOyreU2QYUASeXcSd0OhIsCgYdeCB1VbOxrI0EDzGWoGhx3T6Gtu1e?= =?us-ascii?Q?WYbrJMU0nx/rn3a93eowCw5cvMu0lTJB8T0eKnklXEB9ykc6tI9gMzX50Epz?= =?us-ascii?Q?oQyOxDlZw1HNuEpMZQSORC7HdBEno5tx+K3lD4vCWJzT6LuAmc/hque9HbW+?= =?us-ascii?Q?wFHXdgrguJxBUrIluGPHiPILfBr5NTAkmJOvxsKPNlVugeROMaMyb9UDnSuN?= =?us-ascii?Q?JxMQEBGpktjvJtXpATc6mFEecoy6SLICo1krDjqf0AzIpD2QsRPd3Qp5HaHL?= =?us-ascii?Q?y7EyZabQNp1WuulKWcItvqgh4qJRHUqe0+gh3ftRzom0w66hQTFVP0LBc5bX?= =?us-ascii?Q?dlIC/AYe50OIIQ4y8F0u0baTGcVAvVJ1fxftYvsEOjqnf5MyLGNhv/zukePV?= =?us-ascii?Q?WZvGq1BlXLCI0bNKjYFmHAD18KA+jFQ40M4SZwr/Nu0bSzzVu8kYIs19TfZ+?= =?us-ascii?Q?shrmb3EL8LhbXOzP+AEG2scuSRK0zZCgrK9MBoQ2fVAgwUI+3pCIMj3iMrfC?= =?us-ascii?Q?Nc9a0sgDVG7XAC8JU3sSjNvzodMJXAqATIkgWwG3OcU+c6uC6vQhGMmD1OrI?= =?us-ascii?Q?gYOD+k/EsvmA6n8dYHTf6HuBYXs+KhbBUECFlykqV1L+eq3wW1mOx6XAVnH+?= =?us-ascii?Q?EWFcS/L7geZ6vcgiPdP3s0MV2ceim0lFzmLQ5BHj?= MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR11MB4025.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5211d3f3-534d-4dd6-8496-08db9a0c4c75 X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Aug 2023 01:43:01.5734 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: tU/YYOoNIPfAISwuYlRDaDWVwsZlON/w8ZfPhSRbaCQxJEzVq5hUTkgHz9om6CfgfPw0PWwaPjjV/MRDPQ2dog== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL1PR11MB5511 X-OriginatorOrg: intel.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,hao.a.wu@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: j5HCxXle9f64dGepgkO9qB3ox7686176AA= Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=tP9ViqWZ; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io My personal preference is to do this as two steps. Address the issue in XhciDxe first. Then add new TimerLib API to replace al= l driver/library internal implementations. Best Regards, Hao Wu > -----Original Message----- > From: Henz, Patrick > Sent: Friday, August 11, 2023 6:45 AM > To: devel@edk2.groups.io; Wu, Hao A ; Michael Brown > > Subject: RE: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance > Timer for XHCI Timeouts >=20 > I can certainly make that change. >=20 > For what it's worth I have been working on adding the new function, > GetElapsedTicks, to the various implementations of TimerLib. I've finishe= d up > testing, I would just need to clean up the commits for a patch. Should I = move > forward with that, or would we rather I just add XhcGetElapsedTime to > XhciDxe for the time being? >=20 > Thanks, > Patrick Henz >=20 > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Wu, Hao > A > Sent: Sunday, July 30, 2023 9:57 PM > To: devel@edk2.groups.io; Henz, Patrick ; Michael > Brown > Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance > Timer for XHCI Timeouts >=20 > For the 2 occurrences of in XhcWaitOpRegBit & XhcExecTransfer: > TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND (Timeout * > XHC_1_MILLISECOND); How about changing them to: > TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND ((UINT64) Timeout > * XHC_1_MILLISECOND); to address possible overflow during "Timeout * > XHC_1_MILLISECOND"? >=20 > For extending XhcGetElapsedTime as a TimerLib API, I am fine to put it in > XhciDxe at this moment. > If package maintainers suggest to make it as a public library API, my tak= e is > that this should be done in a separate commit. >=20 > Best Regards, > Hao Wu >=20 > > -----Original Message----- > > From: devel@edk2.groups.io On Behalf Of Henz, > > Patrick > > Sent: Thursday, July 6, 2023 4:16 AM > > To: devel@edk2.groups.io > > Cc: Henz, Patrick > > Subject: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance > > Timer for XHCI Timeouts > > > > REF:https://urldefense.com/v3/__https://bugzilla.tianocore.org/show_bu > > g.cgi?id=3D2948__;!!NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU- > NKbMjOV-lctg5 > > _B3K1Lcta452Gx-1twRt8At3cueAYDq_n$ > > > > XhciDxe uses the timer functionality provided by the boot services > > table to detect timeout conditions. This breaks the driver's > > ExitBootServices call back, as CoreExitBootServices halts the timer > > before signaling the ExitBootServices event. If the host controller > > fails to halt in the call back, the timeout condition will never occur > > and the boot gets stuck in an indefinite spin loop. Use the free > > running timer provided by TimerLib to calculate timeouts, avoiding the > > potential hang. > > > > Signed-off-by: Patrick Henz > > Reviewed-by: > > --- > > MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 56 +++++++++++++++++++ > > MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h | 22 ++++++++ > > MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf | 2 + > > MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c | 67 +++++++++-------------- > > MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 68 > > +++++++++--------------- > > 5 files changed, 129 insertions(+), 86 deletions(-) > > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c > > b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c > > index 62682dd27c..1dcbe20512 100644 > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c > > @@ -1,6 +1,7 @@ > > /** @file > > > > The XHCI controller driver. > > > > > > > > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > Copyright (c) 2011 - 2022, Intel Corporation. All rights > > reserved.
> > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > @@ -2294,3 +2295,58 @@ XhcDriverBindingStop ( > > > > > > return EFI_SUCCESS; > > > > } > > > > + > > > > +/** > > > > + Computes and returns the elapsed time in nanoseconds since > > > > + PreviousTick. The value of PreviousTick is overwritten with the > > > > + current performance counter value. > > > > + > > > > + @param PreviousTick Pointer to PreviousTick count. > > > > + @return The elapsed time in nanoseconds since PreviousCount. > > > > + PreviousCount is overwritten with the current performance > > > > + counter value. > > > > +**/ > > > > +UINT64 > > > > +XhcGetElapsedTime ( > > > > + IN OUT UINT64 *PreviousTick > > > > + ) > > > > +{ > > > > + UINT64 StartValue; > > > > + UINT64 EndValue; > > > > + UINT64 CurrentTick; > > > > + UINT64 Delta; > > > > + > > > > + GetPerformanceCounterProperties (&StartValue, &EndValue); > > > > + > > > > + CurrentTick =3D GetPerformanceCounter (); > > > > + > > > > + // > > > > + // Determine if the counter is counting up or down > > > > + // > > > > + if (StartValue < EndValue) { > > > > + // > > > > + // Counter counts upwards, check for an overflow condition > > > > + // > > > > + if (*PreviousTick > CurrentTick) { > > > > + Delta =3D (EndValue - *PreviousTick) + CurrentTick; > > > > + } else { > > > > + Delta =3D CurrentTick - *PreviousTick; > > > > + } > > > > + } else { > > > > + // > > > > + // Counter counts downwards, check for an underflow condition > > > > + // > > > > + if (*PreviousTick < CurrentTick) { > > > > + Delta =3D (StartValue - CurrentTick) + *PreviousTick; > > > > + } else { > > > > + Delta =3D *PreviousTick - CurrentTick; > > > > + } > > > > + } > > > > + > > > > + // > > > > + // Set PreviousTick to CurrentTick > > > > + // > > > > + *PreviousTick =3D CurrentTick; > > > > + > > > > + return GetTimeInNanoSecond (Delta); > > > > +} > > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h > > b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h > > index ca223bd20c..77feb66647 100644 > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h > > @@ -2,6 +2,7 @@ > > > > > > Provides some data structure definitions used by the XHCI host > > controller driver. > > > > > > > > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > Copyright (c) 2011 - 2017, Intel Corporation. All rights > > reserved.
> > > > Copyright (c) Microsoft Corporation.
> > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > @@ -26,6 +27,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent > > #include > > > > #include > > > > #include > > > > +#include > > > > > > > > #include > > > > > > > > @@ -37,6 +39,10 @@ typedef struct _USB_DEV_CONTEXT > USB_DEV_CONTEXT; > > #include "ComponentName.h" > > > > #include "UsbHcMem.h" > > > > > > > > +// > > > > +// Converts a count from microseconds to nanoseconds > > > > +// > > > > +#define XHC_MICROSECOND_TO_NANOSECOND(Time) ((UINT64)(Time) * > > 1000) > > > > // > > > > // The unit is microsecond, setting it as 1us. > > > > // > > > > @@ -720,4 +726,20 @@ XhcAsyncIsochronousTransfer ( > > IN VOID *Context > > > > ); > > > > > > > > +/** > > > > + Computes and returns the elapsed time in nanoseconds since > > > > + PreviousTick. The value of PreviousTick is overwritten with the > > > > + current performance counter value. > > > > + > > > > + @param PreviousTick Pointer to PreviousTick count. > > > > + before calling this function. > > > > + @return The elapsed time in nanoseconds since PreviousCount. > > > > + PreviousCount is overwritten with the current performance > > > > + counter value. > > > > +**/ > > > > +UINT64 > > > > +XhcGetElapsedTime ( > > > > + IN OUT UINT64 *PreviousTick > > > > + ); > > > > + > > > > #endif > > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf > > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf > > index 5865d86822..18ef87916a 100644 > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf > > @@ -3,6 +3,7 @@ > > # It implements the interfaces of monitoring the status of all ports > > and transferring > > > > # Control, Bulk, Interrupt and Isochronous requests to those > > attached usb LS/FS/HS/SS devices. > > > > # > > > > +# (C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > # Copyright (c) 2011 - 2018, Intel Corporation. All rights > > reserved.
> > > > # > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > @@ -54,6 +55,7 @@ > > BaseMemoryLib > > > > DebugLib > > > > ReportStatusCodeLib > > > > + TimerLib > > > > > > > > [Guids] > > > > gEfiEventExitBootServicesGuid ## SOMETIMES_CONSUMES = ## > > Event > > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > index 5700fc5fb8..2499698715 100644 > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > @@ -2,6 +2,7 @@ > > > > > > The XHCI register operation routines. > > > > > > > > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > Copyright (c) 2011 - 2017, Intel Corporation. All rights > > reserved.
> > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > @@ -417,15 +418,14 @@ XhcClearOpRegBit ( > > Wait the operation register's bit as specified by Bit > > > > to become set (or clear). > > > > > > > > - @param Xhc The XHCI Instance. > > > > - @param Offset The offset of the operation register. > > > > - @param Bit The bit of the register to wait for. > > > > - @param WaitToSet Wait the bit to set or clear. > > > > - @param Timeout The time to wait before abort (in mil= lisecond, > > ms). > > > > + @param Xhc The XHCI Instance. > > > > + @param Offset The offset of the operation register. > > > > + @param Bit The bit of the register to wait for. > > > > + @param WaitToSet Wait the bit to set or clear. > > > > + @param Timeout The time to wait before abort (in millisecond, = ms). > > > > > > > > - @retval EFI_SUCCESS The bit successfully changed by host > controller. > > > > - @retval EFI_TIMEOUT The time out occurred. > > > > - @retval EFI_OUT_OF_RESOURCES Memory for the timer event could not > > be allocated. > > > > + @retval EFI_SUCCESS The bit successfully changed by host controller= . > > > > + @retval EFI_TIMEOUT The time out occurred. > > > > > > > > **/ > > > > EFI_STATUS > > > > @@ -437,54 +437,35 @@ XhcWaitOpRegBit ( > > IN UINT32 Timeout > > > > ) > > > > { > > > > - EFI_STATUS Status; > > > > - EFI_EVENT TimeoutEvent; > > > > - > > > > - TimeoutEvent =3D NULL; > > > > + UINT64 TimeoutTime; > > > > + UINT64 ElapsedTime; > > > > + UINT64 TimeDelta; > > > > + UINT64 CurrentTick; > > > > > > > > if (Timeout =3D=3D 0) { > > > > return EFI_TIMEOUT; > > > > } > > > > > > > > - Status =3D gBS->CreateEvent ( > > > > - EVT_TIMER, > > > > - TPL_CALLBACK, > > > > - NULL, > > > > - NULL, > > > > - &TimeoutEvent > > > > - ); > > > > - > > > > - if (EFI_ERROR (Status)) { > > > > - goto DONE; > > > > - } > > > > - > > > > - Status =3D gBS->SetTimer ( > > > > - TimeoutEvent, > > > > - TimerRelative, > > > > - EFI_TIMER_PERIOD_MILLISECONDS (Timeout) > > > > - ); > > > > - > > > > - if (EFI_ERROR (Status)) { > > > > - goto DONE; > > > > - } > > > > + TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND (Timeout * > > XHC_1_MILLISECOND); > > > > + ElapsedTime =3D 0; > > > > + CurrentTick =3D GetPerformanceCounter (); > > > > > > > > do { > > > > if (XHC_REG_BIT_IS_SET (Xhc, Offset, Bit) =3D=3D WaitToSet) { > > > > - Status =3D EFI_SUCCESS; > > > > - goto DONE; > > > > + return EFI_SUCCESS; > > > > } > > > > > > > > gBS->Stall (XHC_1_MICROSECOND); > > > > - } while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))); > > > > - > > > > - Status =3D EFI_TIMEOUT; > > > > + TimeDelta =3D XhcGetElapsedTime (&CurrentTick); > > > > + // Ensure that ElapsedTime is always incremented to avoid > > + indefinite > > hangs > > > > + if (TimeDelta =3D=3D 0) { > > > > + TimeDelta =3D XHC_MICROSECOND_TO_NANOSECOND > > (XHC_1_MICROSECOND); > > > > + } > > > > > > > > -DONE: > > > > - if (TimeoutEvent !=3D NULL) { > > > > - gBS->CloseEvent (TimeoutEvent); > > > > - } > > > > + ElapsedTime +=3D TimeDelta; > > > > + } while (ElapsedTime < TimeoutTime); > > > > > > > > - return Status; > > > > + return EFI_TIMEOUT; > > > > } > > > > > > > > /** > > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > index 298fb88b81..5177886e52 100644 > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > > @@ -2,6 +2,7 @@ > > > > > > XHCI transfer scheduling routines. > > > > > > > > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > Copyright (c) 2011 - 2020, Intel Corporation. All rights > > reserved.
> > > > Copyright (c) Microsoft Corporation.
> > > > Copyright (C) 2022 Advanced Micro Devices, Inc. All rights > > reserved.
> > > > @@ -1273,15 +1274,14 @@ EXIT: > > /** > > > > Execute the transfer by polling the URB. This is a synchronous opera= tion. > > > > > > > > - @param Xhc The XHCI Instance. > > > > - @param CmdTransfer The executed URB is for cmd transfer = or not. > > > > - @param Urb The URB to execute. > > > > - @param Timeout The time to wait before abort, in mil= lisecond. > > > > + @param Xhc The XHCI Instance. > > > > + @param CmdTransfer The executed URB is for cmd transfer or no= t. > > > > + @param Urb The URB to execute. > > > > + @param Timeout The time to wait before abort, in millisec= ond. > > > > > > > > - @return EFI_DEVICE_ERROR The transfer failed due to transfer e= rror. > > > > - @return EFI_TIMEOUT The transfer failed due to time out. > > > > - @return EFI_SUCCESS The transfer finished OK. > > > > - @retval EFI_OUT_OF_RESOURCES Memory for the timer event could not > > be allocated. > > > > + @return EFI_DEVICE_ERROR The transfer failed due to transfer error. > > > > + @return EFI_TIMEOUT The transfer failed due to time out. > > > > + @return EFI_SUCCESS The transfer finished OK. > > > > > > > > **/ > > > > EFI_STATUS > > > > @@ -1296,12 +1296,14 @@ XhcExecTransfer ( > > UINT8 SlotId; > > > > UINT8 Dci; > > > > BOOLEAN Finished; > > > > - EFI_EVENT TimeoutEvent; > > > > + UINT64 TimeoutTime; > > > > + UINT64 ElapsedTime; > > > > + UINT64 TimeDelta; > > > > + UINT64 CurrentTick; > > > > BOOLEAN IndefiniteTimeout; > > > > > > > > Status =3D EFI_SUCCESS; > > > > Finished =3D FALSE; > > > > - TimeoutEvent =3D NULL; > > > > IndefiniteTimeout =3D FALSE; > > > > > > > > if (CmdTransfer) { > > > > @@ -1319,34 +1321,14 @@ XhcExecTransfer ( > > > > > > if (Timeout =3D=3D 0) { > > > > IndefiniteTimeout =3D TRUE; > > > > - goto RINGDOORBELL; > > > > - } > > > > - > > > > - Status =3D gBS->CreateEvent ( > > > > - EVT_TIMER, > > > > - TPL_CALLBACK, > > > > - NULL, > > > > - NULL, > > > > - &TimeoutEvent > > > > - ); > > > > - > > > > - if (EFI_ERROR (Status)) { > > > > - goto DONE; > > > > } > > > > > > > > - Status =3D gBS->SetTimer ( > > > > - TimeoutEvent, > > > > - TimerRelative, > > > > - EFI_TIMER_PERIOD_MILLISECONDS (Timeout) > > > > - ); > > > > - > > > > - if (EFI_ERROR (Status)) { > > > > - goto DONE; > > > > - } > > > > - > > > > -RINGDOORBELL: > > > > XhcRingDoorBell (Xhc, SlotId, Dci); > > > > > > > > + TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND (Timeout * > > XHC_1_MILLISECOND); > > > > + ElapsedTime =3D 0; > > > > + CurrentTick =3D GetPerformanceCounter (); > > > > + > > > > do { > > > > Finished =3D XhcCheckUrbResult (Xhc, Urb); > > > > if (Finished) { > > > > @@ -1354,22 +1336,22 @@ RINGDOORBELL: > > } > > > > > > > > gBS->Stall (XHC_1_MICROSECOND); > > > > - } while (IndefiniteTimeout || EFI_ERROR (gBS->CheckEvent > > (TimeoutEvent))); > > > > + TimeDelta =3D XhcGetElapsedTime (&CurrentTick); > > > > + // Ensure that ElapsedTime is always incremented to avoid > > + indefinite > > hangs > > > > + if (TimeDelta =3D=3D 0) { > > > > + TimeDelta =3D XHC_MICROSECOND_TO_NANOSECOND > > (XHC_1_MICROSECOND); > > > > + } > > > > > > > > -DONE: > > > > - if (EFI_ERROR (Status)) { > > > > - Urb->Result =3D EFI_USB_ERR_NOTEXECUTE; > > > > - } else if (!Finished) { > > > > + ElapsedTime +=3D TimeDelta; > > > > + } while (IndefiniteTimeout || ElapsedTime < TimeoutTime); > > > > + > > > > + if (!Finished) { > > > > Urb->Result =3D EFI_USB_ERR_TIMEOUT; > > > > Status =3D EFI_TIMEOUT; > > > > } else if (Urb->Result !=3D EFI_USB_NOERROR) { > > > > Status =3D EFI_DEVICE_ERROR; > > > > } > > > > > > > > - if (TimeoutEvent !=3D NULL) { > > > > - gBS->CloseEvent (TimeoutEvent); > > > > - } > > > > - > > > > return Status; > > > > } > > > > > > > > -- > > 2.34.1 > > > > > > > > -=3D-=3D-=3D-=3D-=3D-=3D > > Groups.io Links: You receive all messages sent to this group. > > View/Reply Online (#106668): > > https://urldefense.com/v3/__https://edk2.groups.io/g/devel/message/106 > > 668__;!!NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-NKbMjOV- > lctg5_B3K1Lcta4 > > 52Gx-1twRt8At3cuWxQsO18$ Mute This Topic: > > https://urldefense.com/v3/__https://groups.io/mt/99972791/1768737__;!! > > NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-NKbMjOV- > lctg5_B3K1Lcta452Gx-1tw > > Rt8At3cubh2HDyk$ Group Owner: devel+owner@edk2.groups.io > > Unsubscribe: > > https://urldefense.com/v3/__https://edk2.groups.io/g/devel/unsub__;!!N > > pxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-NKbMjOV- > lctg5_B3K1Lcta452Gx-1twR > > t8At3cuWYMMXVU$ [hao.a.wu@intel.com] -=3D-=3D-=3D-=3D-=3D-=3D > > >=20 >=20 >=20 >=20 >=20 >=20 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#107704): https://edk2.groups.io/g/devel/message/107704 Mute This Topic: https://groups.io/mt/99972791/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-