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 743D9AC1B19 for ; Thu, 10 Aug 2023 22:45:03 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=QHc/CkJOir4U1S4pu/g3FNyG22ilQl0LftVnO9K84IA=; 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=1691707501; v=1; b=HG0JUjPQZ0Ztmt4vcL1Hr+F9E6nSEDjWGX14YeElqhVsz9xM/Z4nYIgDcy4cnj/gs9x/kRmD IK++8uK9bgdUWNU2WVvxxGFAaN1idltvci+4/7Mr6ZcE5ABw54lsDD1fZ4OcRSXoILiYnzqJcmn UgjajTVKwPlDQ0XnONr8UXIU= X-Received: by 127.0.0.2 with SMTP id nplKYY7687511xpYRiuiYanM; Thu, 10 Aug 2023 15:45:01 -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.31440.1691707500780911434 for ; Thu, 10 Aug 2023 15:45:01 -0700 X-Received: from pps.filterd (m0134421.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 37AMZJpX032023; Thu, 10 Aug 2023 22:45:00 GMT X-Received: from p1lg14878.it.hpe.com ([16.230.97.204]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3sd8tj01d1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 10 Aug 2023 22:45:00 +0000 X-Received: from p1wg14926.americas.hpqcorp.net (unknown [10.119.18.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by p1lg14878.it.hpe.com (Postfix) with ESMTPS id 4CFEED2E1; Thu, 10 Aug 2023 22:44:59 +0000 (UTC) X-Received: from p1wg14927.americas.hpqcorp.net (10.119.18.117) 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; Thu, 10 Aug 2023 10:44:53 -1200 X-Received: from p1wg14926.americas.hpqcorp.net (10.119.18.115) by p1wg14927.americas.hpqcorp.net (10.119.18.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Thu, 10 Aug 2023 10:44:52 -1200 X-Received: from p1wg14920.americas.hpqcorp.net (16.230.19.123) 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; Thu, 10 Aug 2023 10:44:52 -1200 X-Received: from NAM11-BN8-obe.outbound.protection.outlook.com (192.58.206.35) by edge.it.hpe.com (16.230.19.123) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Thu, 10 Aug 2023 10:44:52 -1200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DrycpIC6aVJ8INs/An/mRtc/N+fOu3SCEJsx8vlKKKokRi2OplwX1HsHETvLpQTyySUl8WtaSvDYMK3PS8X70zOiFmQT9MIcPtsJr30bbRBEJxeSLT9tkwHBqiPhvrXHX9NY0kBamJQ9bto50Y3JQKdidf9EDQFmsjPXrl7V9UNjlTw6LFlY1If4y1YV8TUC+qKIZQBMPzly9FE1Hyj9kyM1VmH0BoYmXeMWh4dU6cJRT/A3saFbKls9ISNw2+SEWeAbS7PJ1L8N86z4NOEG4jYz2RMKOGIzkhEJ507tAc9EN+ZSAglcsaJoa55VWZKMokuFMBfUzNVfZHIoYtIeVQ== 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=Hp5i4rnJZkmEr8UHV0cfEVUtW8w6i/c2b59DuUaPCXU=; b=FWuNVoPj/g2ygoWgjij+Rg1j5N6Y6kSd/3QThljI/UwTUvYnEBa27+DcBXgqf2LT4XyNbnHHqE6TTJjICsfOdLNQr7exunRh3FwPrcs3S2FcYcSXGGvS6Y94NyNtxFvoebIr3bEJADJP48AZZmtutHrU1tauULIO9LsHk3zXsvcTI4J7x3nkZhBpPhDoK1bpUuPhu6TkbcCQXobymmV+0LeRIGz4dOJ/biS25UtsO3tI5q+zJV4i0H1hiiFhDt0Lxyi5PvZk6xY56ucl6664L6TBM995kulbULOWtPnvB9DytMT1bEzdq0KoEMGuYn/5JYP1BVaHD3HisgtYML1v8A== 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 MW4PR84MB1588.NAMPRD84.PROD.OUTLOOK.COM (2603:10b6:303:1a7::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6652.30; Thu, 10 Aug 2023 22:44:49 +0000 X-Received: from PH0PR84MB1478.NAMPRD84.PROD.OUTLOOK.COM ([fe80::55a0:89f4:ef4:bcba]) by PH0PR84MB1478.NAMPRD84.PROD.OUTLOOK.COM ([fe80::55a0:89f4:ef4:bcba%4]) with mapi id 15.20.6652.029; Thu, 10 Aug 2023 22:44:49 +0000 From: "Henz, Patrick" To: "devel@edk2.groups.io" , "hao.a.wu@intel.com" , 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/TVrOAgBEBLPA= Date: Thu, 10 Aug 2023 22:44:49 +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_|MW4PR84MB1588:EE_ x-ms-office365-filtering-correlation-id: 7412e4a9-19e5-4a6e-5fd6-08db99f36749 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: ADNOb4++ucLlEO1eS/92XzDOGtB6f09zTJnGsbWcr/1P0eQbzfJsNd6TzK0cf5qUf9WeP7ibvmfufTwTC1XzUSrZQ28ud/WwuUN72wD5XNvjJDpWDkPxwKPAInJjszRhtCtoAE1VDmWFqKSNmVJPy4mNMVSZ9f5i7kS/P/E6z6uPUJjZfKUVZPZxjRguqcsmMsMHHFjN3k+dKwd/JYK0VuY0wncW75S/fVJiDyo2+AhnmMdeRG7B6qOrEe6zIIFYB7hINIB5rDG73tYYZ8dEUSk+KCCdAljBjjbhrltcGhqmuBZqd7u8Hm44bhRrAN1P5D6ZLWklxeVCsq0emRl9eKCG+botCILcBAH1yHmfrtjxz13hcmJPpy1vE/v8AKkxGaCLAxi/1drD7djlB+eACw8Be6Tj7jAa+O4v2rEMjIHXIZC15yO9VRVOdJjkPUKuDSRbUbIqGIr2vy7MrNOuZXMC13fEKryI2XTMmFeRgGe93fVCqe9ULyavvintcAnGWR1iN50xejqqX8hUR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L9Dryzl+EFtFnq16?= X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH0PR84MB1478.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 7412e4a9-19e5-4a6e-5fd6-08db99f36749 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Aug 2023 22:44:49.1543 (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: pQrT0va+CCeLeJyIKjbO+lh+8SR/+NP8tETVzOInpfXZjDWlxHlbfc/JvoFJdFQgX/Sat/zNZJkLT2oW8lmvyg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR84MB1588 X-OriginatorOrg: hpe.com X-Proofpoint-GUID: EZXg7sVzb1YRLxKJX0kyPSYigN9Uvuig X-Proofpoint-ORIG-GUID: EZXg7sVzb1YRLxKJX0kyPSYigN9Uvuig X-Proofpoint-UnRewURL: 5 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: 8g9HyeUs1iHLDrFMM5fGrSp8x7686176AA= 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=HG0JUjPQ; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); 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 I can certainly make that change. For what it's worth I have been working on adding the new function, GetElap= sedTicks, to the various implementations of TimerLib. I've finished up test= ing, I would just need to clean up the commits for a patch. Should I move f= orward with that, or would we rather I just add XhcGetElapsedTime to XhciDx= e for the time being? Thanks, Patrick Henz -----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 Bro= wn Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance Tim= er for XHCI Timeouts For the 2 occurrences of in XhcWaitOpRegBit & XhcExecTransfer: TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND (Timeout * XHC_1_MILLISECON= D); How about changing them to: TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND ((UINT64) Timeout * XHC_1_M= ILLISECOND); to address possible overflow during "Timeout * XHC_1_MILLISECO= ND"? For extending XhcGetElapsedTime as a TimerLib API, I am fine to put it in X= hciDxe at this moment. If package maintainers suggest to make it as a public library API, my take = is that this should be done in a separate commit. Best Regards, Hao Wu > -----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 >=20 > REF:INVALID URI REMOVED > g.cgi?id=3D2948__;!!NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-NKbMjOV-lctg5 > _B3K1Lcta452Gx-1twRt8At3cueAYDq_n$ >=20 > 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 occur=20 > and the boot gets stuck in an indefinite spin loop. Use the free=20 > running timer provided by TimerLib to calculate timeouts, avoiding the=20 > potential hang. >=20 > 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=20 > +++++++++--------------- > 5 files changed, 129 insertions(+), 86 deletions(-) >=20 > 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 >=20 > The XHCI controller driver. >=20 >=20 >=20 > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
>=20 > Copyright (c) 2011 - 2022, Intel Corporation. All rights=20 > reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > @@ -2294,3 +2295,58 @@ XhcDriverBindingStop ( >=20 >=20 > return EFI_SUCCESS; >=20 > } >=20 > + >=20 > +/** >=20 > + Computes and returns the elapsed time in nanoseconds since >=20 > + PreviousTick. The value of PreviousTick is overwritten with the >=20 > + current performance counter value. >=20 > + >=20 > + @param PreviousTick Pointer to PreviousTick count. >=20 > + @return The elapsed time in nanoseconds since PreviousCount. >=20 > + PreviousCount is overwritten with the current performance >=20 > + counter value. >=20 > +**/ >=20 > +UINT64 >=20 > +XhcGetElapsedTime ( >=20 > + IN OUT UINT64 *PreviousTick >=20 > + ) >=20 > +{ >=20 > + UINT64 StartValue; >=20 > + UINT64 EndValue; >=20 > + UINT64 CurrentTick; >=20 > + UINT64 Delta; >=20 > + >=20 > + GetPerformanceCounterProperties (&StartValue, &EndValue); >=20 > + >=20 > + CurrentTick =3D GetPerformanceCounter (); >=20 > + >=20 > + // >=20 > + // Determine if the counter is counting up or down >=20 > + // >=20 > + if (StartValue < EndValue) { >=20 > + // >=20 > + // Counter counts upwards, check for an overflow condition >=20 > + // >=20 > + if (*PreviousTick > CurrentTick) { >=20 > + Delta =3D (EndValue - *PreviousTick) + CurrentTick; >=20 > + } else { >=20 > + Delta =3D CurrentTick - *PreviousTick; >=20 > + } >=20 > + } else { >=20 > + // >=20 > + // Counter counts downwards, check for an underflow condition >=20 > + // >=20 > + if (*PreviousTick < CurrentTick) { >=20 > + Delta =3D (StartValue - CurrentTick) + *PreviousTick; >=20 > + } else { >=20 > + Delta =3D *PreviousTick - CurrentTick; >=20 > + } >=20 > + } >=20 > + >=20 > + // >=20 > + // Set PreviousTick to CurrentTick >=20 > + // >=20 > + *PreviousTick =3D CurrentTick; >=20 > + >=20 > + return GetTimeInNanoSecond (Delta); >=20 > +} >=20 > 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 @@ >=20 >=20 > Provides some data structure definitions used by the XHCI host=20 > controller driver. >=20 >=20 >=20 > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
>=20 > Copyright (c) 2011 - 2017, Intel Corporation. All rights=20 > reserved.
>=20 > Copyright (c) Microsoft Corporation.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -26,6 +27,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent =20 > #include >=20 > #include >=20 > #include >=20 > +#include >=20 >=20 >=20 > #include >=20 >=20 >=20 > @@ -37,6 +39,10 @@ typedef struct _USB_DEV_CONTEXT USB_DEV_CONTEXT; =20 > #include "ComponentName.h" >=20 > #include "UsbHcMem.h" >=20 >=20 >=20 > +// >=20 > +// Converts a count from microseconds to nanoseconds >=20 > +// >=20 > +#define XHC_MICROSECOND_TO_NANOSECOND(Time) ((UINT64)(Time) * > 1000) >=20 > // >=20 > // The unit is microsecond, setting it as 1us. >=20 > // >=20 > @@ -720,4 +726,20 @@ XhcAsyncIsochronousTransfer ( > IN VOID *Context >=20 > ); >=20 >=20 >=20 > +/** >=20 > + Computes and returns the elapsed time in nanoseconds since >=20 > + PreviousTick. The value of PreviousTick is overwritten with the >=20 > + current performance counter value. >=20 > + >=20 > + @param PreviousTick Pointer to PreviousTick count. >=20 > + before calling this function. >=20 > + @return The elapsed time in nanoseconds since PreviousCount. >=20 > + PreviousCount is overwritten with the current performance >=20 > + counter value. >=20 > +**/ >=20 > +UINT64 >=20 > +XhcGetElapsedTime ( >=20 > + IN OUT UINT64 *PreviousTick >=20 > + ); >=20 > + >=20 > #endif >=20 > 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=20 > and transferring >=20 > # Control, Bulk, Interrupt and Isochronous requests to those=20 > attached usb LS/FS/HS/SS devices. >=20 > # >=20 > +# (C) Copyright 2023 Hewlett Packard Enterprise Development LP
>=20 > # Copyright (c) 2011 - 2018, Intel Corporation. All rights=20 > reserved.
>=20 > # >=20 > # SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -54,6 +55,7 @@ > BaseMemoryLib >=20 > DebugLib >=20 > ReportStatusCodeLib >=20 > + TimerLib >=20 >=20 >=20 > [Guids] >=20 > gEfiEventExitBootServicesGuid ## SOMETIMES_CONSUMES ## > Event >=20 > 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 @@ >=20 >=20 > The XHCI register operation routines. >=20 >=20 >=20 > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
>=20 > Copyright (c) 2011 - 2017, Intel Corporation. All rights=20 > reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > @@ -417,15 +418,14 @@ XhcClearOpRegBit ( > Wait the operation register's bit as specified by Bit >=20 > to become set (or clear). >=20 >=20 >=20 > - @param Xhc The XHCI Instance. >=20 > - @param Offset The offset of the operation register. >=20 > - @param Bit The bit of the register to wait for. >=20 > - @param WaitToSet Wait the bit to set or clear. >=20 > - @param Timeout The time to wait before abort (in milli= second, > ms). >=20 > + @param Xhc The XHCI Instance. >=20 > + @param Offset The offset of the operation register. >=20 > + @param Bit The bit of the register to wait for. >=20 > + @param WaitToSet Wait the bit to set or clear. >=20 > + @param Timeout The time to wait before abort (in millisecond, ms= ). >=20 >=20 >=20 > - @retval EFI_SUCCESS The bit successfully changed by host co= ntroller. >=20 > - @retval EFI_TIMEOUT The time out occurred. >=20 > - @retval EFI_OUT_OF_RESOURCES Memory for the timer event could not > be allocated. >=20 > + @retval EFI_SUCCESS The bit successfully changed by host controller. >=20 > + @retval EFI_TIMEOUT The time out occurred. >=20 >=20 >=20 > **/ >=20 > EFI_STATUS >=20 > @@ -437,54 +437,35 @@ XhcWaitOpRegBit ( > IN UINT32 Timeout >=20 > ) >=20 > { >=20 > - EFI_STATUS Status; >=20 > - EFI_EVENT TimeoutEvent; >=20 > - >=20 > - TimeoutEvent =3D NULL; >=20 > + UINT64 TimeoutTime; >=20 > + UINT64 ElapsedTime; >=20 > + UINT64 TimeDelta; >=20 > + UINT64 CurrentTick; >=20 >=20 >=20 > if (Timeout =3D=3D 0) { >=20 > return EFI_TIMEOUT; >=20 > } >=20 >=20 >=20 > - Status =3D gBS->CreateEvent ( >=20 > - EVT_TIMER, >=20 > - TPL_CALLBACK, >=20 > - NULL, >=20 > - NULL, >=20 > - &TimeoutEvent >=20 > - ); >=20 > - >=20 > - if (EFI_ERROR (Status)) { >=20 > - goto DONE; >=20 > - } >=20 > - >=20 > - Status =3D gBS->SetTimer ( >=20 > - TimeoutEvent, >=20 > - TimerRelative, >=20 > - EFI_TIMER_PERIOD_MILLISECONDS (Timeout) >=20 > - ); >=20 > - >=20 > - if (EFI_ERROR (Status)) { >=20 > - goto DONE; >=20 > - } >=20 > + TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND (Timeout * > XHC_1_MILLISECOND); >=20 > + ElapsedTime =3D 0; >=20 > + CurrentTick =3D GetPerformanceCounter (); >=20 >=20 >=20 > do { >=20 > if (XHC_REG_BIT_IS_SET (Xhc, Offset, Bit) =3D=3D WaitToSet) { >=20 > - Status =3D EFI_SUCCESS; >=20 > - goto DONE; >=20 > + return EFI_SUCCESS; >=20 > } >=20 >=20 >=20 > gBS->Stall (XHC_1_MICROSECOND); >=20 > - } while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))); >=20 > - >=20 > - Status =3D EFI_TIMEOUT; >=20 > + TimeDelta =3D XhcGetElapsedTime (&CurrentTick); >=20 > + // Ensure that ElapsedTime is always incremented to avoid=20 > + indefinite > hangs >=20 > + if (TimeDelta =3D=3D 0) { >=20 > + TimeDelta =3D XHC_MICROSECOND_TO_NANOSECOND > (XHC_1_MICROSECOND); >=20 > + } >=20 >=20 >=20 > -DONE: >=20 > - if (TimeoutEvent !=3D NULL) { >=20 > - gBS->CloseEvent (TimeoutEvent); >=20 > - } >=20 > + ElapsedTime +=3D TimeDelta; >=20 > + } while (ElapsedTime < TimeoutTime); >=20 >=20 >=20 > - return Status; >=20 > + return EFI_TIMEOUT; >=20 > } >=20 >=20 >=20 > /** >=20 > 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 @@ >=20 >=20 > XHCI transfer scheduling routines. >=20 >=20 >=20 > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
>=20 > Copyright (c) 2011 - 2020, Intel Corporation. All rights=20 > reserved.
>=20 > Copyright (c) Microsoft Corporation.
>=20 > Copyright (C) 2022 Advanced Micro Devices, Inc. All rights=20 > reserved.
>=20 > @@ -1273,15 +1274,14 @@ EXIT: > /** >=20 > Execute the transfer by polling the URB. This is a synchronous operati= on. >=20 >=20 >=20 > - @param Xhc The XHCI Instance. >=20 > - @param CmdTransfer The executed URB is for cmd transfer or= not. >=20 > - @param Urb The URB to execute. >=20 > - @param Timeout The time to wait before abort, in milli= second. >=20 > + @param Xhc The XHCI Instance. >=20 > + @param CmdTransfer The executed URB is for cmd transfer or not. >=20 > + @param Urb The URB to execute. >=20 > + @param Timeout The time to wait before abort, in millisecon= d. >=20 >=20 >=20 > - @return EFI_DEVICE_ERROR The transfer failed due to transfer err= or. >=20 > - @return EFI_TIMEOUT The transfer failed due to time out. >=20 > - @return EFI_SUCCESS The transfer finished OK. >=20 > - @retval EFI_OUT_OF_RESOURCES Memory for the timer event could not > be allocated. >=20 > + @return EFI_DEVICE_ERROR The transfer failed due to transfer error. >=20 > + @return EFI_TIMEOUT The transfer failed due to time out. >=20 > + @return EFI_SUCCESS The transfer finished OK. >=20 >=20 >=20 > **/ >=20 > EFI_STATUS >=20 > @@ -1296,12 +1296,14 @@ XhcExecTransfer ( > UINT8 SlotId; >=20 > UINT8 Dci; >=20 > BOOLEAN Finished; >=20 > - EFI_EVENT TimeoutEvent; >=20 > + UINT64 TimeoutTime; >=20 > + UINT64 ElapsedTime; >=20 > + UINT64 TimeDelta; >=20 > + UINT64 CurrentTick; >=20 > BOOLEAN IndefiniteTimeout; >=20 >=20 >=20 > Status =3D EFI_SUCCESS; >=20 > Finished =3D FALSE; >=20 > - TimeoutEvent =3D NULL; >=20 > IndefiniteTimeout =3D FALSE; >=20 >=20 >=20 > if (CmdTransfer) { >=20 > @@ -1319,34 +1321,14 @@ XhcExecTransfer ( >=20 >=20 > if (Timeout =3D=3D 0) { >=20 > IndefiniteTimeout =3D TRUE; >=20 > - goto RINGDOORBELL; >=20 > - } >=20 > - >=20 > - Status =3D gBS->CreateEvent ( >=20 > - EVT_TIMER, >=20 > - TPL_CALLBACK, >=20 > - NULL, >=20 > - NULL, >=20 > - &TimeoutEvent >=20 > - ); >=20 > - >=20 > - if (EFI_ERROR (Status)) { >=20 > - goto DONE; >=20 > } >=20 >=20 >=20 > - Status =3D gBS->SetTimer ( >=20 > - TimeoutEvent, >=20 > - TimerRelative, >=20 > - EFI_TIMER_PERIOD_MILLISECONDS (Timeout) >=20 > - ); >=20 > - >=20 > - if (EFI_ERROR (Status)) { >=20 > - goto DONE; >=20 > - } >=20 > - >=20 > -RINGDOORBELL: >=20 > XhcRingDoorBell (Xhc, SlotId, Dci); >=20 >=20 >=20 > + TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND (Timeout * > XHC_1_MILLISECOND); >=20 > + ElapsedTime =3D 0; >=20 > + CurrentTick =3D GetPerformanceCounter (); >=20 > + >=20 > do { >=20 > Finished =3D XhcCheckUrbResult (Xhc, Urb); >=20 > if (Finished) { >=20 > @@ -1354,22 +1336,22 @@ RINGDOORBELL: > } >=20 >=20 >=20 > gBS->Stall (XHC_1_MICROSECOND); >=20 > - } while (IndefiniteTimeout || EFI_ERROR (gBS->CheckEvent=20 > (TimeoutEvent))); >=20 > + TimeDelta =3D XhcGetElapsedTime (&CurrentTick); >=20 > + // Ensure that ElapsedTime is always incremented to avoid=20 > + indefinite > hangs >=20 > + if (TimeDelta =3D=3D 0) { >=20 > + TimeDelta =3D XHC_MICROSECOND_TO_NANOSECOND > (XHC_1_MICROSECOND); >=20 > + } >=20 >=20 >=20 > -DONE: >=20 > - if (EFI_ERROR (Status)) { >=20 > - Urb->Result =3D EFI_USB_ERR_NOTEXECUTE; >=20 > - } else if (!Finished) { >=20 > + ElapsedTime +=3D TimeDelta; >=20 > + } while (IndefiniteTimeout || ElapsedTime < TimeoutTime); >=20 > + >=20 > + if (!Finished) { >=20 > Urb->Result =3D EFI_USB_ERR_TIMEOUT; >=20 > Status =3D EFI_TIMEOUT; >=20 > } else if (Urb->Result !=3D EFI_USB_NOERROR) { >=20 > Status =3D EFI_DEVICE_ERROR; >=20 > } >=20 >=20 >=20 > - if (TimeoutEvent !=3D NULL) { >=20 > - gBS->CloseEvent (TimeoutEvent); >=20 > - } >=20 > - >=20 > return Status; >=20 > } >=20 >=20 >=20 > -- > 2.34.1 >=20 >=20 >=20 > -=3D-=3D-=3D-=3D-=3D-=3D > Groups.io Links: You receive all messages sent to this group. > View/Reply Online (#106668): > INVALID URI REMOVED > 668__;!!NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-NKbMjOV-lctg5_B3K1Lcta4 > 52Gx-1twRt8At3cuWxQsO18$ Mute This Topic:=20 > https://groups.io/mt/99972791/1768737 > NpxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-NKbMjOV-lctg5_B3K1Lcta452Gx-1tw > Rt8At3cubh2HDyk$ Group Owner: devel+owner@edk2.groups.io > Unsubscribe:=20 > https://edk2.groups.io/g/devel/unsub > pxR!kyFQM5IkKYAG9CRBO4xphwBnzi_jhb2oU-NKbMjOV-lctg5_B3K1Lcta452Gx-1twR > t8At3cuWYMMXVU$ [hao.a.wu@intel.com] -=3D-=3D-=3D-=3D-=3D-=3D >=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 (#107702): https://edk2.groups.io/g/devel/message/107702 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-