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 4A2A2940E44 for ; Thu, 7 Sep 2023 01:27:54 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=iXw1v5MgxjsnOQarMrdnNqvarJZz7/7mq5rgCFkXUAQ=; 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=1694050072; v=1; b=V/tFSNyghyPVv2vQO4f/C1jGh+L6ATXCnAgYM2lgolDatkrulvLEtirU5fJLkVPpxHPDZEC/ WZuj91zYVix56uoFCxhFGxRiNHCRwnjfM+UQmAmZp2q2BbTKm8BF19b+r6Is4OSPO9GUvTw4847 /Ex+ijCO+VzdA3L+wXHttnwc= X-Received: by 127.0.0.2 with SMTP id OZtiYY7687511xAmcFYeYERi; Wed, 06 Sep 2023 18:27:52 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.43]) by mx.groups.io with SMTP id smtpd.web11.3842.1694050072101178676 for ; Wed, 06 Sep 2023 18:27:52 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10825"; a="463608789" X-IronPort-AV: E=Sophos;i="6.02,233,1688454000"; d="scan'208";a="463608789" X-Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Sep 2023 18:27:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10825"; a="771045620" X-IronPort-AV: E=Sophos;i="6.02,233,1688454000"; d="scan'208";a="771045620" X-Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga008.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 06 Sep 2023 18:27:50 -0700 X-Received: from fmsmsx611.amr.corp.intel.com (10.18.126.91) by fmsmsx601.amr.corp.intel.com (10.18.126.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Wed, 6 Sep 2023 18:27:49 -0700 X-Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx611.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Wed, 6 Sep 2023 18:27:49 -0700 X-Received: from fmsedg602.ED.cps.intel.com (10.1.192.136) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Wed, 6 Sep 2023 18:27:49 -0700 X-Received: from NAM12-DM6-obe.outbound.protection.outlook.com (104.47.59.170) by edgegateway.intel.com (192.55.55.71) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.27; Wed, 6 Sep 2023 18:27:48 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=f3SfLSRMHHzRHr9W4MovcrPGD1glG4b1HFgySgujMJA6a0qHXmqrplEvd+xegwKEN+Di8eyzKXR9jjRjoPgIhZLR/oZYEhWzZ2r3UBr+uhG0PArsexjhgw7Kk2t1BgxR2caGCOVIjd25OsjSTJJXceinvOKUTw47sC59LLqts9jfFfWnO1+7vjyS36VjlDXzeGEXTQobsyfqDsDTVq2c4UnYg93qzXzIhvA6qx7MjW9zsaJKV7QfD72Ry99/Nc9MD7roiBH9D3gqGjE5r2U9b/m3eYpoXx72bQnmA1BVpPw5Sjn/1svAOOpA6TQt3UYmLcQYpGmuiovVgBtsf5695g== 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=bzZI4jbMs3Uu3mpX21DGPWPQow0DSzHwvmrmZm5HOEA=; b=R/PzLeuyn0dnZDGhCYki+290MknI+csZfAp+ST1p21KlxX/jDOGpgqn1X2alXwrZsx8joy6k0YCJdWxRXKALWEy0JvEckdvKoxd3nA+S7KwF58NdlrYvrJBo7A62ujL3OsB0Gwayi9ifcz9pjTq8oP7ppqjJl7SOgnH605qBSti7j5rcNRZl47hYhu/J7PjDhN82hv+XNeoZndcNQI4vmhHAuGKJV7yWwJx4aMExqKxOR9Vn7grBMNYN0FXJ7+8f9XTC47fjZGPqfvZN0Li5gXsHxKeSEt8XvocLd4g1M+3rygD9VqZ7Y/4epiJIyNjU/R5zUr0f+eCafGR0jxLbcw== 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 IA0PR11MB7377.namprd11.prod.outlook.com (2603:10b6:208:433::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Thu, 7 Sep 2023 01:27:45 +0000 X-Received: from DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::38c3:ed7c:3562:2e18]) by DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::38c3:ed7c:3562:2e18%4]) with mapi id 15.20.6745.035; Thu, 7 Sep 2023 01:27:44 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "Henz, Patrick" Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts Thread-Topic: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts Thread-Index: AQHZzseBJIO8HXAamkWgXd40zbxjr7AOZHvggABS3cA= Date: Thu, 7 Sep 2023 01:27:44 +0000 Message-ID: References: <177B4AD1F8C3A6A2.8497@groups.io> 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_|IA0PR11MB7377:EE_ x-ms-office365-filtering-correlation-id: ba2ff09e-64e2-4ba8-46b3-08dbaf41a2ef 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: gElvwPmdci11PqcJ9oDomf3B2tM6lyudGJBfoqSw0D9P12QvXMaMkm+kVr1ElXOmO3sLT6SE9nm5YHD3ajSQiRlHU9exqJi4eD4YS85JT8FQQipg7Imb5iHRvuTRnGJuqcioRhSYsSCVZX5Kg33XQwjqvT+q7xkbmCVwRtu1MNlWoXpyAW9Nyiauu1Tx+TCxlkKs1gJ4bSvqKCa5VS7HhjkXfQvIkdM+UeKLF30CU54PD6aMfahW1Dflg7YzmtvvWKs5G2BWxYWLNw5WWliiL09+0rwe3ZUiibTxh51vn4BMvEQuE4qv6ZUicGypkVbG6JZgDTGpeMZWOwSH6LtjmpGuLOhDX/1rTUDaEBMRBIPf3+xuwpJKgsx90YJn7IfxjsAk12r8Rzwu7fY2jvKK7np8UD/YMdCIcH8QBT8xOaZx/DVBsu44HVuftGcopQMBqyYStCQXcge+C6w20ypOsFjdfdARSNf6V+afBdPuagZgRZXg64dB9JDePXrO0vZSAlMJBEsuWguh09MhXdTqGWgdllre0NWLbx3DCjOTR7LePzhZ41HbQlm64XDFCWNX4abQ8REBFmjR+9O6L/W5YmNxEDTixB7Lx06uCpF1G8mETJ6tvXUu+FfOTGaQcjG98dBtCvjRk4uVO460e66kVg== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?XTbpUu9vcSNz6wqKiBV6Ojmnn35OlMsnNvOPKzoFNaUZCjNZP1adySKupxpS?= =?us-ascii?Q?rzgdCfKtDmd4xpsfN4oxos78z0NTilfHOnkU85KXu7QBX6SaIn2OXx1djTQ1?= =?us-ascii?Q?ULOXpVxBN8JR7kp1eQbPaNVNiFyZa1hNjZn4sLL848CCWIjWW2MzQ3v5pnE2?= =?us-ascii?Q?+o7Nm7npNabtW/Xz0hnIHEr9KU71oLycepuzQnTXPqpkDiq5b27PSLHOs2nb?= =?us-ascii?Q?rQGvVEAS9iR8Z3hUFSL8fyPBTznIa0FgDvXp2kC0OkhWZT1/YMOz4me8Cx1C?= =?us-ascii?Q?N3mPnkoNgzRUWnewFzhkI7ELzU0WaawKch5QLdaIsHmorFwSEUGGuTnjgAn3?= =?us-ascii?Q?dYz9N9QCYMUXbVlyBmQqVPISkCU1KqnxpDvNY/JXEQ1so3PxCAvLEZ6oBWMU?= =?us-ascii?Q?Uw93mQ/5v/Yt6TYMfMjx6Ekyb3SL7kktOeCj2p4gtLnVcBFq7LeN1e292YWp?= =?us-ascii?Q?Orsoqs+koffqjIEgb4gGZio0zgJ2XhaYuCGv0VMIIF59nb8JukH6TC3gpVhs?= =?us-ascii?Q?e8pZfXEVTiKaCcxbfk4b+wdUUSEyfdr0eE9PDU25zkEGBKBzXax1CD7HeJdy?= =?us-ascii?Q?eRqBnf7gdzn7s1B7e5viFqsuINwmVBz+jYpbKISNh6dwu6QSHWumyVhcWthI?= =?us-ascii?Q?rZMdY0gh+t2RX0Snr1aHFvw2AUZtsom+KvQSv5IcrsDZ+g64sZCmEmR3WuGh?= =?us-ascii?Q?VdXsirtwFulWtgFQBX5YcmWoIE91FmITwB/Irn/KAGnYt17NECtLwQFmnBDF?= =?us-ascii?Q?Dkms3FmqKD3EKxdNWlN1L0UXBTgiqURE6X8JlUVfceFeNwDttn5YtiOlpLta?= =?us-ascii?Q?0LKfiEOXc7lqucJ1kWqFE55o7lquJo7OlFVot1URi/hqswfP/MfiYmnVwhwm?= =?us-ascii?Q?kWwbteG67sNZDdwfyaJdIGEeRbZUPtIDmwSGY9+WR+XLqnht5A84nYwkyeT0?= =?us-ascii?Q?D7E/8SPXxdB84T8Dd28i4XOTlzZwgYDeMJUI+llQAqDpgTgRt/nt6DqJ06Hf?= =?us-ascii?Q?kYxsQgNjKYfLf99W1A02SYzXOXSfopJsvsOVBKGF7t3Cm5PrfIDAXfv4lWBF?= =?us-ascii?Q?5kOaZr6aEwfwhpy2QwlmfNmSdKpEXODeU99ZYrXUUgIB2fYFXXPG7XoZnszY?= =?us-ascii?Q?dmLEWh8Quq+g2D9+pcXXYS0cx0R46qrjGotldr9KpS5VLlLagvRkPOedLTm/?= =?us-ascii?Q?ktXIjGegiJqNL9z+vwu0uJlCH3Ckr0LC8phFNabuRNvGpumt5YaugZnij3Vt?= =?us-ascii?Q?td9Z3KSEaqavSsfAcIqM3I2DEXs4gmMBIgp1SD2G9lAEEHUMeFn/ZwWj1LGe?= =?us-ascii?Q?jW0PDm1LRuf/nNJ3+rzivemlbvsqj4xho52sp+Jpx4iU410VM2iWjUKfumUQ?= =?us-ascii?Q?FUTOHnVxe6zcg48vHeX4oDkOAPVYAVw/anbCkQ8KFCrlj07g6MEDMlKrXo3V?= =?us-ascii?Q?PSrErio8PTXkepJbK2DgAlVNc0ATi5JNZZKeTMOFYEohajTmz3uvm0yHf+lB?= =?us-ascii?Q?Ds5pcw46BPeBbUEOwrYiLISX3Ymx4Y9nwv+pY6gzPK5RbRWni50alqApxg?= =?us-ascii?Q?=3D=3D?= 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: ba2ff09e-64e2-4ba8-46b3-08dbaf41a2ef X-MS-Exchange-CrossTenant-originalarrivaltime: 07 Sep 2023 01:27:44.3794 (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: 4POWPV+kHngHsRsiID2E5l5CIYPgykZn6W9DO9qzf3dCn2am39dEgv2o18qIOi5X6FJ81z0xIuy//FFC9cDApQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR11MB7377 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: i8zq0yju4s40AYKaJ806AEpwx7686176AA= 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="V/tFSNyg"; 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 Sorry for the late response. Reviewed-by: Hao A Wu Best Regards, Hao Wu > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Henz, > Patrick > Sent: Thursday, September 7, 2023 4:37 AM > To: devel@edk2.groups.io > Subject: Re: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use > Performance Timer for XHCI Timeouts >=20 > I sent this patch out a few weeks ago now but haven't seen a reply, just > checking in to make sure it didn't get missed. >=20 > Thanks, > Patrick Henz >=20 > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Henz, > Patrick > Sent: Monday, August 14, 2023 10:52 AM > To: devel@edk2.groups.io > Cc: Henz, Patrick > Subject: [edk2-devel] [PATCH v2] MdeModulePkg/XhciDxe: Use Performance > Timer for XHCI Timeouts >=20 > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2948 >=20 > 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 ExitBootServ= ices > 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 t= he > 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 +++++++++--------------- > 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 > The XHCI controller driver. >=20 > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.
> SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -2294,3 +2295,58 @@ XhcDriverBindingStop ( >=20 > 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 @@ >=20 > Provides some data structure definitions used by the XHCI host control= ler > driver. >=20 > +(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 #i= nclude > #include > +#include >=20 > #include >=20 > @@ -37,6 +39,10 @@ typedef struct _USB_DEV_CONTEXT > USB_DEV_CONTEXT; > #include "ComponentName.h" > #include "UsbHcMem.h" >=20 > +// > +// 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 > ); >=20 > +/** > + 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 an= d > transferring # Control, Bulk, Interrupt and Isochronous requests to tho= se > 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 >=20 > [Guids] > gEfiEventExitBootServicesGuid ## SOMETIMES_CONSUMES ## > Event > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > index 5700fc5fb8..07e57772b6 100644 > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > @@ -2,6 +2,7 @@ >=20 > The XHCI register operation routines. >=20 > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.
> SPDX-License-Identifier: BSD-2-Clause-Patent >=20 > @@ -417,15 +418,14 @@ XhcClearOpRegBit ( > Wait the operation register's bit as specified by Bit > to become set (or clear). >=20 > - @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 milli= second, > 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= ). >=20 > - @retval EFI_SUCCESS The bit successfully changed by host co= ntroller. > - @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. >=20 > **/ > 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; >=20 > if (Timeout =3D=3D 0) { > return EFI_TIMEOUT; > } >=20 > - 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 ((UINT64)Timeout > * > + XHC_1_MILLISECOND); ElapsedTime =3D 0; CurrentTick =3D > + GetPerformanceCounter (); >=20 > do { > if (XHC_REG_BIT_IS_SET (Xhc, Offset, Bit) =3D=3D WaitToSet) { > - Status =3D EFI_SUCCESS; > - goto DONE; > + return EFI_SUCCESS; > } >=20 > 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); > + } >=20 > -DONE: > - if (TimeoutEvent !=3D NULL) { > - gBS->CloseEvent (TimeoutEvent); > - } > + ElapsedTime +=3D TimeDelta; > + } while (ElapsedTime < TimeoutTime); >=20 > - return Status; > + return EFI_TIMEOUT; > } >=20 > /** > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > index 53421e64a8..7d4b7a769d 100644 > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c > @@ -2,6 +2,7 @@ >=20 > XHCI transfer scheduling routines. >=20 > +(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 Mic= ro > Devices, Inc. All rights reserved.
@@ -1276,15 +1277,14 @@ EXIT: > /** > Execute the transfer by polling the URB. This is a synchronous operati= on. >=20 > - @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 milli= second. > + @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 millisecon= d. >=20 > - @return EFI_DEVICE_ERROR The transfer failed due to transfer err= or. > - @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. >=20 > **/ > EFI_STATUS > @@ -1299,12 +1299,14 @@ XhcExecTransfer ( > UINT8 SlotId; > UINT8 Dci; > BOOLEAN Finished; > - EFI_EVENT TimeoutEvent; > + UINT64 TimeoutTime; > + UINT64 ElapsedTime; > + UINT64 TimeDelta; > + UINT64 CurrentTick; > BOOLEAN IndefiniteTimeout; >=20 > Status =3D EFI_SUCCESS; > Finished =3D FALSE; > - TimeoutEvent =3D NULL; > IndefiniteTimeout =3D FALSE; >=20 > if (CmdTransfer) { > @@ -1322,34 +1324,14 @@ XhcExecTransfer ( >=20 > 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; > } >=20 > - Status =3D gBS->SetTimer ( > - TimeoutEvent, > - TimerRelative, > - EFI_TIMER_PERIOD_MILLISECONDS (Timeout) > - ); > - > - if (EFI_ERROR (Status)) { > - goto DONE; > - } > - > -RINGDOORBELL: > XhcRingDoorBell (Xhc, SlotId, Dci); >=20 > + TimeoutTime =3D XHC_MICROSECOND_TO_NANOSECOND ((UINT64)Timeout > * > + XHC_1_MILLISECOND); ElapsedTime =3D 0; CurrentTick =3D > + GetPerformanceCounter (); > + > do { > Finished =3D XhcCheckUrbResult (Xhc, Urb); > if (Finished) { > @@ -1357,22 +1339,22 @@ RINGDOORBELL: > } >=20 > 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); > + } >=20 > -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; > } >=20 > - if (TimeoutEvent !=3D NULL) { > - gBS->CloseEvent (TimeoutEvent); > - } > - > return Status; > } >=20 > -- > 2.34.1 >=20 >=20 >=20 >=20 >=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 (#108348): https://edk2.groups.io/g/devel/message/108348 Mute This Topic: https://groups.io/mt/100739508/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-