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 7D0F2740034 for ; Mon, 30 Oct 2023 20:36:34 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=WuDOFwviJbYBViYlWV42L8ZlvpDuYM5NPyKQp7T7gtQ=; 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=1698698193; v=1; b=CH+rAVvn261hfuSYw4w4YHhXghkw0stOhW1Zd42mAH3GUBaLDHPi1s4bE8j2KQHllsTS3eVc l6XHbm4j0QSCHWkrhaI1J3qlGzVvfaNl7QrgXRCoC5nJgb0tcWwmHViDi8wQvOK6I1YVXrcA+6/ Pf8kqB+RfeG53ON7LlG9+lYE= X-Received: by 127.0.0.2 with SMTP id gPgxYY7687511x4cEE4udc49; Mon, 30 Oct 2023 13:36:33 -0700 X-Received: from mx0a-002e3701.pphosted.com (mx0a-002e3701.pphosted.com [148.163.147.86]) by mx.groups.io with SMTP id smtpd.web10.169377.1698698192320808586 for ; Mon, 30 Oct 2023 13:36:32 -0700 X-Received: from pps.filterd (m0134420.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39UJXApg020204; Mon, 30 Oct 2023 20:36:32 GMT X-Received: from p1lg14881.it.hpe.com ([16.230.97.202]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3u2eyh36ub-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 30 Oct 2023 20:36:31 +0000 X-Received: from p1wg14925.americas.hpqcorp.net (unknown [10.119.18.114]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by p1lg14881.it.hpe.com (Postfix) with ESMTPS id DBFAF805662; Mon, 30 Oct 2023 20:36:30 +0000 (UTC) X-Received: from p1wg14926.americas.hpqcorp.net (10.119.18.115) by p1wg14925.americas.hpqcorp.net (10.119.18.114) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 30 Oct 2023 08:36:30 -1200 X-Received: from p1wg14919.americas.hpqcorp.net (16.230.19.122) by p1wg14926.americas.hpqcorp.net (10.119.18.115) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42 via Frontend Transport; Mon, 30 Oct 2023 08:36:30 -1200 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (192.58.206.35) by edge.it.hpe.com (16.230.19.122) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Mon, 30 Oct 2023 08:36:30 -1200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bF8GAlwkZ8J2M55PUIXJ5FT9jz2A937XLneNAFJCCZyr77YOVfJ7FvsSwp90k6JnHHCwhNaVEz/Ytan5MALowEfiEA5shB7AVbkoKQJAGxVDCt4Zt9xXi3TypWf6kmU5Ev+nZHGExDp79V042G8b1D9uaZ4RJ1pEha8Q5ECBVDk4fyO3AYGp+4e+gxD1eXS4DO8fyknC64MnCSX0PLKLLWMgA1a+CUJdMC+BQMUK71bhz/jgMHWjYHaPGUeNCxJ8oFNwoOqtJCRxZggox18LYh19N9OPCiW9L/PfjnCHgeN7gC1ptF6bq2F3UEqWSv2DwXaZgCWGafXzx7uEtVlxzA== 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=cScnvCjwzksoPF+U+RZA75lpPZvfc85xKZiGv93qa/o=; b=Ero5Z7Lmi1q/vmtt15COWhxVOvEgrW6rTEj2BSv/ZYWic716DrcHNwRRVnYBRTd2cgnB7b3ib2jqGiZOeWopT6EvxRi5wM4j0LdmVvbBebSj9vabb1IPy7+bDcyh33hkl/6KLkFka0jrvXCQreTiwhMbiGXmOIcxE908Nf5YM7ZZoDKOQZwd75O39zUGOnrv5jVri0mF/FvwiGg0ElmnsOM6WNgkgg679c5vgLJ4XmakFqr+QdN1FouY7aoJlfIHNH53s2Df5qyMS18YJf3JiwtWErkXU3fWV7/0CX5pKS15c8MUy4dg4ZJeIXC+W31ydQDCzscJ6Lu5c+WTcd14oA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hpe.com; dmarc=pass action=none header.from=hpe.com; dkim=pass header.d=hpe.com; arc=none X-Received: from PH0PR84MB1478.NAMPRD84.PROD.OUTLOOK.COM (2603:10b6:510:171::21) by PH8PR84MB3188.NAMPRD84.PROD.OUTLOOK.COM (2603:10b6:510:1cf::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6933.28; Mon, 30 Oct 2023 20:36:26 +0000 X-Received: from PH0PR84MB1478.NAMPRD84.PROD.OUTLOOK.COM ([fe80::b646:9f64:f96a:9940]) by PH0PR84MB1478.NAMPRD84.PROD.OUTLOOK.COM ([fe80::b646:9f64:f96a:9940%4]) with mapi id 15.20.6933.027; Mon, 30 Oct 2023 20:36:26 +0000 From: "Henz, Patrick" To: "Wu, Hao A" , "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: AQHZr2NSqpSbBpZ/S0qxd+WtKwKDk6/TVrOAgBEBLPCAADOtgIB+8BYQ Date: Mon, 30 Oct 2023 20:36:26 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PH0PR84MB1478:EE_|PH8PR84MB3188:EE_ x-ms-office365-filtering-correlation-id: 6646471e-2dcf-4ddd-2b1a-08dbd987e3b4 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: 11mfiZqMgF/5mC1X63wbfUy/JrEYTgXb9aGIwkb5yrnhxI5OJSRze6ngGwJk8eFenqXSvlNWyML0IDlKO1OWRbDNqs2JY4EKLW7nW8ouJHw2pvq9apmXHhEkddPnCr8ok4ywFl0rO0QcU/WhVSRRH5YeAjQJZ4Yck4cJbysZRvJ8hZ+2nFlsCtsMtKxbwMAZyCYqM/+MY3Ut6MRW3MCS0VXIX7hRMknfxB9jMNSjFNfUx5QmZ/ctJ9DsCMdl1LH+LplISM9+5qcOz8LsZdIyOf0cCH2/r8i83awCm57eAFPie9DlCXjrN8B751rekGMHvjzY+3o3iqCYgK12oRso2dSdqkjJW12EzWBi3OCaVrDoBkxSONngig5hpN5WIp4yTVLatLTi3UVaUZ4swt/ZL9S6s6P/Yw9vrFw3twGi81SDktuRzS/gknO8nP0HTnabMlZU03CDSg69UHGKi78pwUwzWyBciEJfZperHEw1KUhoK6Kh9tnwwCYB1buB/HqpTPQMeWWhnzTMYhDokJfB2NDufdbLVyZKykZUt0yKG7Mg4Yv2bCK55y3i/TsANBNSx3hJTP2ZGNqpxwK+CHpEQ7O7A+pOyRlApv4uz0ovR7gtJoXIqzoq3Ehu1KXqPZN5KVsjk/nDbpCj1IDR1jHaKw== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?Zv+kthml1tK7xGcB814scskAABhe2SzARBD2iNf6WhQ/L6d9Mc6l8SeIgc7e?= =?us-ascii?Q?71jivyI3igeHice/xbMPSJsqQlMBn7CCe/uHX2YE7qOgk+EGzauo89q6L4Uy?= =?us-ascii?Q?5em1fMK5Rmnu5osWi/poK2Hlg5AqUcTTnzoCWnv3974coFHABjgxAjhLg3yP?= =?us-ascii?Q?oe617N9HT4oa7ImRSzeg+VSODmJx5OjbjxbNKj7JDrH70g+lscDA5qiSFTTo?= =?us-ascii?Q?53lM9vHu40soJykdvu5+ng2LmTx5aQ2fcUAgpoqU0UvwiXkGNinE7hnlxmku?= =?us-ascii?Q?5bk2ytkqdF126/J0eRmFzPZNxaO+olVHixGrvDgn7klWrkwREhcQxIe6i2gu?= =?us-ascii?Q?71sVMi4/x1dNi1zo0YcJeRnApA6t/f5Bb0ThJRucSCl0PCD8+D1cJh28eZRI?= =?us-ascii?Q?TiIRIF0iGkndKTGPZmq2DtXABtPNScIH0NVMlYXwmSJv8oagakddzHUXkXT2?= =?us-ascii?Q?AdOuYMTPopiCaRUblOWmGLUhuCz/7cB/spdDY1N5e3BxKRu8OniSt1RWuLOt?= =?us-ascii?Q?cQnh3c5ro10FamDTniWabY7zC5q8CZ8u30G9j0MYC4roygIIE5viWEp2hbt2?= =?us-ascii?Q?WXMxE/0vQFfVgowKn50b+f5je8KYw7V5IME8+76l2ScjqdjZMNej5ITMobkl?= =?us-ascii?Q?tJViwNxra4cTk1FGYBbuhBxapbj/MFLGi1i3Yyzwcd2bgWW4PYQ2d42InZGS?= =?us-ascii?Q?EXuYmNphwpFPlFNtyaZ/UPAtB8K0yffr1PEgSsXskrf4bWPV6m/oj0Tb/+cu?= =?us-ascii?Q?Fb0ngsSWf+5TWV5pdOWCqPYlekq+xouNa0KebFErGczOPZK+KXyTtmIv6Ted?= =?us-ascii?Q?mebnhiZJ02+6YG4TrxxvYlBC8wpqHxNyS1zNieOghcTI1aNBsHptrooltM3j?= =?us-ascii?Q?8G8U5SEKqSIWhvqneq680PRdxKlqNDxxOclxvNyv3zGzEEpva2M4YdSt4yEL?= =?us-ascii?Q?Fl73oAKwZ+ftKMSoK/JUem/5BVnENVTdPsHutTEWyKu8077ToHWT2GHD1BMY?= =?us-ascii?Q?Bsa+JY6/jSjpE7bR4KneuBYk5udB+Y8IVqFgJcycAPzL9WB4Cbz8l0Ljs+nF?= =?us-ascii?Q?xUiNW1PbOR2BMepHOFjc0PpnkB09ytBlEeMzWVXV0z2zvDl4UHtHz8B7qG+r?= =?us-ascii?Q?1QmYdN/ACdtJmOll9ScZ0oLLXvtDcYUA3e16sgNA9VYXlEgvM4bwNjYU0yIa?= =?us-ascii?Q?kqA4sMW9EvC9apxiHswlqyo5NK/TOiF9xHRVFJ8Jbb61RtqmAiVP0Xr7TBYK?= =?us-ascii?Q?Ju8eb5NXh4TKAVpi2MJZggQ/bcsQeRN4ylJTLAeHzGbZyb4Nt/+sMK9HHo5L?= =?us-ascii?Q?03f6/WRP/Ub++zXksMBY4lLSfAwRIno4xQo0suvEZK7Ae0grGLiaexoC6u0w?= =?us-ascii?Q?or4Q9hmSI66KCxB6OOIjKoS7KdJhQhmPm9Agb/zjf4IeBbY/v6uYhg5aOZlP?= =?us-ascii?Q?8+dwkuYGcOLRKiyoikdKFIDcWfGhdZMyWE0JcQeo7OM9U/rrUZPjbT3z9Uek?= =?us-ascii?Q?a+ybkxutK9d60o4o9H69t5MSBQmFrXCNhzZQrWiGGu40Q/pHmB5Qb209zEDh?= =?us-ascii?Q?3q7cAgGqGpmpGN+5O8ql/daNrDEvwJDonay7t1/0?= X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH0PR84MB1478.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 6646471e-2dcf-4ddd-2b1a-08dbd987e3b4 X-MS-Exchange-CrossTenant-originalarrivaltime: 30 Oct 2023 20:36:26.6525 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: b4lmsNKVxBbY/UuvXcayXY7ezSTCwfkbXWiit+FHCz0SBXdKV1jXcN3/x2A2OlwOLDfG2Upxa+zRg9c4BI6dEQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH8PR84MB3188 X-OriginatorOrg: hpe.com X-Proofpoint-GUID: vcCDk7MDjS5bXe8UBJT_DajOjX816tFV X-Proofpoint-ORIG-GUID: vcCDk7MDjS5bXe8UBJT_DajOjX816tFV X-Proofpoint-UnRewURL: 4 URL's were un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 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,patrick.henz@hpe.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Fr8e6aSEfegKwnofWYRYcJqqx7686176AA= 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=CH+rAVvn; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=hpe.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; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") My changes have been in for a little over a month now, I've been looking in= to updating the TimerLib API but I'm questioning if it still makes sense to= go down that path. The functions I had implemented, XhcGetElapsedTicks ()= and XhcConvertTimeToTicks (), now rely heavily on the use of global variab= les for caching return values from GetPerformanceCounterProperties. As-is t= hese functions won't work for all instances of TimerLib, specifically if th= e instance is used before memory (RAM) is available. I could implement the = functions as they originally were, but I wouldn't be able to replace the Xh= c functions without adding additional parameters to said TimerLib functions= (e.g. adding Frequency, StartValue, StopValue to ConvertTimeToTicks), whic= h feels clunky to me. Would a new library make sense here? Something that s= its between the driver and the TimerLib library? Or do we just leave things= as they currently are? Thanks, Patrick Henz -----Original Message----- From: Wu, Hao A =20 Sent: Thursday, August 10, 2023 8:43 PM To: Henz, Patrick ; devel@edk2.groups.io; Michael Bro= wn Subject: RE: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance Tim= er for XHCI Timeouts 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=20 > Brown > Subject: RE: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use=20 > 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,=20 > GetElapsedTicks, to the various implementations of TimerLib. I've=20 > finished up testing, I would just need to clean up the commits for a=20 > patch. Should I move forward with that, or would we rather I just add=20 > XhcGetElapsedTime to XhciDxe for the time being? >=20 > Thanks, > Patrick Henz >=20 > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Wu, Hao=20 > A > Sent: Sunday, July 30, 2023 9:57 PM > To: devel@edk2.groups.io; Henz, Patrick ;=20 > Michael Brown > Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use=20 > Performance Timer for XHCI Timeouts >=20 > For the 2 occurrences of in XhcWaitOpRegBit & XhcExecTransfer: > TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND (Timeout *=20 > 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 *=20 > XHC_1_MILLISECOND"? >=20 > For extending XhcGetElapsedTime as a TimerLib API, I am fine to put it=20 > in XhciDxe at this moment. > If package maintainers suggest to make it as a public library API, my=20 > take 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,=20 > > 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=20 > > Timer for XHCI Timeouts > > > > REF:INVALID URI REMOVED > > bu > > g.cgi?id=3D2948__;!!NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU- > NKbMjOV-lctg5 > > _B3K1Lcta452Gx-1twRt8At3cueAYDq_n$ > > > > XhciDxe uses the timer functionality provided by the boot services=20 > > table to detect timeout conditions. This breaks the driver's=20 > > ExitBootServices call back, as CoreExitBootServices halts the timer=20 > > before signaling the ExitBootServices event. If the host controller=20 > > fails to halt in the call back, the timeout condition will never=20 > > occur and the boot gets stuck in an indefinite spin loop. Use the=20 > > free running timer provided by TimerLib to calculate timeouts,=20 > > 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=20 > > 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=20 > > controller driver. > > > > > > > > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > Copyright (c) 2011 - 2017, Intel Corporation. All rights=20 > > reserved.
> > > > Copyright (c) Microsoft Corporation.
> > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > @@ -26,6 +27,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent=20 > > #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=20 > > ports and transferring > > > > # Control, Bulk, Interrupt and Isochronous requests to those=20 > > attached usb LS/FS/HS/SS devices. > > > > # > > > > +# (C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > # Copyright (c) 2011 - 2018, Intel Corporation. All rights=20 > > 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=20 > > 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=20 > > + 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=20 > > reserved.
> > > > Copyright (c) Microsoft Corporation.
> > > > Copyright (C) 2022 Advanced Micro Devices, Inc. All rights=20 > > 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=20 > > (TimeoutEvent))); > > > > + TimeDelta =3D XhcGetElapsedTime (&CurrentTick); > > > > + // Ensure that ElapsedTime is always incremented to avoid=20 > > + 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): > > INVALID URI REMOVED > > 06 > > 668__;!!NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-NKbMjOV- > lctg5_B3K1Lcta4 > > 52Gx-1twRt8At3cuWxQsO18$ Mute This Topic: > > https://groups.io/mt/99972791/1768737 > > NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-NKbMjOV- > lctg5_B3K1Lcta452Gx-1tw > > Rt8At3cubh2HDyk$ Group Owner: devel+owner@edk2.groups.io > > Unsubscribe: > > 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 (#110344): https://edk2.groups.io/g/devel/message/110344 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-