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 62876740037 for ; Wed, 20 Sep 2023 07:24:18 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=Y6Hv/2wlP2QkhsWt3hwa6LvBDxJBfKyHc0PXvHhATXE=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC: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=1695194657; v=1; b=ARQFkPP68h3HCVHbJZbHU1FFob7yr/tCJCdPXEnkHRxGaTeP2ZzkPFhoByHLdpDgLgTn2p7K 5UEimrMsoNrG3Wh2cbX0h/irnV0WY9RkYfQS8RPNrlMPRJzK4UW9/Lg4S/GsR29bUvlAG5+BA99 eLt6gNdIfkhH078ElbaS2ZVY= X-Received: by 127.0.0.2 with SMTP id AVDDYY7687511xRxqSOoaNs0; Wed, 20 Sep 2023 00:24:17 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web11.31624.1695194655930149604 for ; Wed, 20 Sep 2023 00:24:16 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="382894795" X-IronPort-AV: E=Sophos;i="6.02,161,1688454000"; d="scan'208";a="382894795" X-Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Sep 2023 00:24:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10838"; a="746540426" X-IronPort-AV: E=Sophos;i="6.02,161,1688454000"; d="scan'208";a="746540426" X-Received: from fmsmsx601.amr.corp.intel.com ([10.18.126.81]) by orsmga002.jf.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 20 Sep 2023 00:24:15 -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, 20 Sep 2023 00:24:14 -0700 X-Received: from FMSEDG603.ED.cps.intel.com (10.1.192.133) 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.32 via Frontend Transport; Wed, 20 Sep 2023 00:24:14 -0700 X-Received: from NAM02-SN1-obe.outbound.protection.outlook.com (104.47.57.40) by edgegateway.intel.com (192.55.55.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.32; Wed, 20 Sep 2023 00:24:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gPixnrXA4+GbRRtnfuCfB1ymBO5l0Cnv7zDNCNDLbiglaWAjuTMKu1mRfJWhjE/iUZprigtCGI4Yoizc9X06jHkkSbRbpuoyBd/Ez+K8oxWS6vbZK02S9bQbiyR2pWs0FUkZJqLBvjaz8EtUKEtyrfM33o88o6VijRZY2waJtr9KAPWBS58D9JizUeHSHrRN4+uPk12UZY0b1BmEmgU1Y9rZA5GPWgoURbaFH/8IBLKj6Drr3ESROLcW2U/79TaSXbtYh23F5Xn2acZe8uS4/V6LUGpfuhhu8Igh17vPgetNAoMXDSSsSzhFKKLbeXSMJ22sCaPre1q/FnniwHtrDQ== 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=zPyppQKYzWzBTCuriqwpCK5fb1PZP1iGwbdifdNbCBA=; b=ibdH9loVXY3ekR2nOrKURLxUs0aBZfNDV4RJL4EKo8CZXnl2mln5qqWdkEnKLIW2zVaafxOe0B1hOkWXmm36dduPIWPn5jCexn7Xd0HehC/Ivn94AD3fK5NuSfuzZTC1HZFbAQRnh38vZfN/VC7qdhXxHaX/01uTVmdFXlhVPp9zGYTZyvmF3PpEHgg4/t6szVYr4z8iW67edQyAIXfxajtEC/PaQJq264fFOZlyH65YNaEGajSv7yFhsfBojDxbwwB+wne9m9X4I0pcfpWROl9rfjjmp00YmuT+A6bK8Rt4bZ9DxZvE3qa6FKSQ6mQOUMS5tH4LYnUK6AMhCo7k8A== 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 CYYPR11MB8388.namprd11.prod.outlook.com (2603:10b6:930:c2::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Wed, 20 Sep 2023 07:24:11 +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.6792.026; Wed, 20 Sep 2023 07:24:11 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "Henz, Patrick" CC: "Ni, Ray" Subject: Re: [edk2-devel] [PATCH v3] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts Thread-Topic: [edk2-devel] [PATCH v3] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts Thread-Index: AQHZ5cV8N5X9tqYmm0iSCQ9AOvYUw7AjW1KQ Date: Wed, 20 Sep 2023 07:24:11 +0000 Message-ID: References: <382ea3abf9d4e410cfcde1bcff453eac409e350b.1694541645.git.patrick.henz@hpe.com> In-Reply-To: <382ea3abf9d4e410cfcde1bcff453eac409e350b.1694541645.git.patrick.henz@hpe.com> Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM6PR11MB4025:EE_|CYYPR11MB8388:EE_ x-ms-office365-filtering-correlation-id: bb6bdaf2-4be6-49e5-905f-08dbb9aa9610 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: UYiagFxx3SrH6KHtXW1nmiffTayWI8W+guGFqPBJiK43VLwjNMw4rehXG6qc1AqeY25R2jKkZ5c32IUhz7TcMBK98fNlEM0yd6lMzMhb0io7smk/fddmF16G68wLMwGFsgYtwheDYG66jdYgN5JlBYtG8BWZkfbXu3h3dqAyS8B4qlh47fdRVULaKP5JN3ERs6La6KFs9tIAOBibZNsQSDyW8QUB+Hny066oOinNl1gLguDB7ae0bFf1hJFezmcBcSHvXp1ZqvSEozPMjSrIhui1ddUsJefcw7SqsrkNxdlKUj3WZgGSWUghF7r1z+FCThmABm02iOg82RomUXsWuUFzzAgo8nqcLPkWUh2iZnMeSQCE57PYL/8Nox++AIhJKfzUTwlQVoxeFOrVKZbfrF2FyUlbqxGn/mZ31uGtJZFH6T05gYVnhcQ8QasRn6pvD3GtYQulunJE7e+01r4m4tyNQcYR+tYvdKlobkKRa4JISGCEitavJxFUhqf6OYpNXUi9xYAsq1OgYEdvg7D6VzgnzS+horLNgzDvoOqI4i2B5qkYQDn2NRIX++sJ7JHg9YOce/t6gkWJe2bWvRaIRO/iKfArc3rIz0wOEZkqAoxWbCaxhdxA3Mom0LtPqg8wyeu5kQHbZ077Qzdubx8D/w== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?Zv3tSDGc8tYGsePt/8/0LEF5wZ/OfcXB8Vrd9fIC1Ou9vagKoP3dsICP28//?= =?us-ascii?Q?3ENvB627p+cWeNEpFjHgC2eWEPfU6ScfbAgnqRCMwv83QyziDeTlEMguXeje?= =?us-ascii?Q?zxT8ikY0VVNFCby/pN1/60oeK+1FiAngSqO+5mBCNllqNoGUC+vTe8e1+dl8?= =?us-ascii?Q?TbFmPSRSXwK97VIHpF+a2KiYiXALQge2jVp7XF3fW4zhfn3tik8OGoh3GT6H?= =?us-ascii?Q?OrBgHuUbWspvjyGON5wQX/jCCKGl+e08exB6Z6Y7KCfEvRrYKzNTrtxRmSXi?= =?us-ascii?Q?nur9r6iTFTcCCRWWtLlDOhCzARq/l22x979kwbsb4veVjgxbxsyPpq+s//Vk?= =?us-ascii?Q?uZ084+FHF3vFLFugY8E7c96Ot9xUBMUlEP0347LGQMMOII59Xic3Hgwl7wGl?= =?us-ascii?Q?h1TpJNFaEk02G3alUvY3MZu4+isR5LXgBrbyAk4ivCT6YOzaLdL1FYfFRxUc?= =?us-ascii?Q?FvWWgjr54HOd5/5O6xO8+TCyPu9vq/tf7vcAQBvgM6BDypNf4AIGai0/GfAj?= =?us-ascii?Q?/FvhFlvlKzAr9tZt1gEzsi6p9QLZjH5CespGafqdwXV9eydW7t2BXYk152Wq?= =?us-ascii?Q?VbOjCUJ9PrWoRPktM2iMPB3hP14+Y7o+0N8uAeRUgR/WbfDahcnx5r5xaayp?= =?us-ascii?Q?mTBYTAEzjCs4XT5v9mFuRrC8ILP1/509vQXUw035gwDyGqzqNDpwAfOMF7Bm?= =?us-ascii?Q?mM8BIwx9KxuLzqWQjlgjuzLJIY9sVQv+1K6BNp/KcreIo7L1T/lxn5rDy7R3?= =?us-ascii?Q?bODCB/zvqUp7LBdqw47toTYZoLmy+nk3lSD0vyuAjUt0tCajMBcVSXvf0Q42?= =?us-ascii?Q?zgdqyDTMyEfaPSmsbam1LRFeh3bMbDvT6UTNbu0Cv3ViWCJUkEzwTMycpPKf?= =?us-ascii?Q?uBtGNFrv3rGG7XT/NDRurCA7ECR5JJYrwFC9+TKclAWmSCK0e9S5eZOW2ITg?= =?us-ascii?Q?AHnznGuYyJluHQ01ty9Ch5M9L6Px40gePGlQyI3ZjI+TLAtQvaT/9K4cmP3g?= =?us-ascii?Q?5ukbX/3JVclh6aX0nfrKb3EeqaCgk7tZ8maiCV3Bojakrx9uwsvjYt9V74Xv?= =?us-ascii?Q?LwGJtPcPdpZ3r2xSe3oFYHY78LVLuPeNhdhO82l+y+pqM7PZ0Ax1dKcHV01u?= =?us-ascii?Q?7EuOqIVIYOGCOEtNy3f/ZvmemfYEVJrTqpVFErJfeJY9yd9MLbDZUlXN5wp3?= =?us-ascii?Q?wgfXW9rifOqp8fxiWjQQ893cFeezDO/SSKQxo8cJv8Z7l57lTyQkVC6U02jx?= =?us-ascii?Q?lU8LPteVWE4nRMOiPxD7ksZoqONRU1zF/XAGC1xyv+HXPganVjCXO9RzUmOS?= =?us-ascii?Q?v90jyw+cvNRFYc8953BtKBn9NnuZb/t1YrDOSFauRXqWSXrkqjjHR+lmPH18?= =?us-ascii?Q?pwisCybLWbadYVw7W9jW6zKSjjlciKRPLMWDkjkFpLewfwE3tJyLFAT2iB71?= =?us-ascii?Q?mLX05uJREKZwmSlfwksSF8oaFTsjCyXq7OUxDuSh/gyLyFhOUHFm3UAhl9a1?= =?us-ascii?Q?HuxBI4pfwQxtLA0k2XTwHcK9PieHTAyReC90UxQHmD31Bq4XngXd55TO/w?= =?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: bb6bdaf2-4be6-49e5-905f-08dbb9aa9610 X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Sep 2023 07:24:11.6077 (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: X8hBRMM5Phy9UxiX6D9qHvLBa5i9e7KKcvOdXkvdSIppt999JQCrWUsNe8yvsQSxeklAYX73c2vGLV4Os0kF4Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CYYPR11MB8388 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: s1ihr3zuIFz1JR4lmsFMy0Tgx7686176AA= 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=ARQFkPP6; 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; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}") Reviewed-by: Hao A Wu Best Regards, Hao Wu > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Henz, > Patrick > Sent: Wednesday, September 13, 2023 2:06 AM > To: devel@edk2.groups.io > Cc: Wu, Hao A ; Ni, Ray ; Henz, > Patrick > Subject: [edk2-devel] [PATCH v3] 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 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. >=20 > Cc: Hao A Wu > Cc: Ray Ni > Signed-off-by: Patrick Henz > Reviewed-by: > --- > MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 117 > +++++++++++++++++++++++ > MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h | 32 +++++++ > MdeModulePkg/Bus/Pci/XhciDxe/XhciDxe.inf | 2 + > MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c | 68 +++++-------- > MdeModulePkg/Bus/Pci/XhciDxe/XhciSched.c | 72 ++++++-------- > 5 files changed, 204 insertions(+), 87 deletions(-) >=20 > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c > b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c > index 62682dd27c..7a2e32a9dd 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 reserved.
>=20 > SPDX-License-Identifier: BSD-2-Clause-Patent >=20 >=20 >=20 > @@ -85,6 +86,11 @@ EFI_USB2_HC_PROTOCOL gXhciUsb2HcTemplate =3D { > 0x0 >=20 > }; >=20 >=20 >=20 > +UINT64 mPerformanceCounterStartValue; >=20 > +UINT64 mPerformanceCounterEndValue; >=20 > +UINT64 mPerformanceCounterFrequency; >=20 > +BOOLEAN mPerformanceCounterValuesCached =3D FALSE; >=20 > + >=20 > /** >=20 > Retrieves the capability of root hub ports. >=20 >=20 >=20 > @@ -2294,3 +2300,114 @@ XhcDriverBindingStop ( >=20 >=20 > return EFI_SUCCESS; >=20 > } >=20 > + >=20 > +/** >=20 > + Converts a time in nanoseconds to a performance counter tick count. >=20 > + >=20 > + @param Time The time in nanoseconds to be converted to performance > counter ticks. >=20 > + @return Time in nanoseconds converted to ticks. >=20 > +**/ >=20 > +UINT64 >=20 > +XhcConvertTimeToTicks ( >=20 > + IN UINT64 Time >=20 > + ) >=20 > +{ >=20 > + UINT64 Ticks; >=20 > + UINT64 Remainder; >=20 > + UINT64 Divisor; >=20 > + UINTN Shift; >=20 > + >=20 > + // Cache the return values to avoid repeated calls to > GetPerformanceCounterProperties () >=20 > + if (!mPerformanceCounterValuesCached) { >=20 > + mPerformanceCounterFrequency =3D GetPerformanceCounterProperties ( >=20 > + &mPerformanceCounterStartValue, >=20 > + &mPerformanceCounterEndValue >=20 > + ); >=20 > + >=20 > + mPerformanceCounterValuesCached =3D TRUE; >=20 > + } >=20 > + >=20 > + // Prevent returning a tick value of 0, unless Time is already 0 >=20 > + if (0 =3D=3D mPerformanceCounterFrequency) { >=20 > + return Time; >=20 > + } >=20 > + >=20 > + // Nanoseconds per second >=20 > + Divisor =3D 1000000000; >=20 > + >=20 > + // >=20 > + // Frequency >=20 > + // Ticks =3D ------------- x Time >=20 > + // 1,000,000,000 >=20 > + // >=20 > + Ticks =3D MultU64x64 ( >=20 > + DivU64x64Remainder ( >=20 > + mPerformanceCounterFrequency, >=20 > + Divisor, >=20 > + &Remainder >=20 > + ), >=20 > + Time >=20 > + ); >=20 > + >=20 > + // >=20 > + // Ensure (Remainder * Time) will not overflow 64-bit. >=20 > + // >=20 > + // HighBitSet64 (Remainder) + 1 + HighBitSet64 (Time) + 1 <=3D 64 >=20 > + // >=20 > + Shift =3D MAX (0, HighBitSet64 (Remainder) + HighBitSet64 (Time) -= 62); >=20 > + Remainder =3D RShiftU64 (Remainder, (UINTN)Shift); >=20 > + Divisor =3D RShiftU64 (Divisor, (UINTN)Shift); >=20 > + Ticks +=3D DivU64x64Remainder (MultU64x64 (Remainder, Time), Diviso= r, > NULL); >=20 > + >=20 > + return Ticks; >=20 > +} >=20 > + >=20 > +/** >=20 > + Computes and returns the elapsed ticks since PreviousTick. The >=20 > + value of PreviousTick is overwritten with the current performance >=20 > + counter value. >=20 > + >=20 > + @param PreviousTick Pointer to PreviousTick count. >=20 > + @return The elapsed ticks since PreviousCount. PreviousCount is >=20 > + overwritten with the current performance counter value. >=20 > +**/ >=20 > +UINT64 >=20 > +XhcGetElapsedTicks ( >=20 > + IN OUT UINT64 *PreviousTick >=20 > + ) >=20 > +{ >=20 > + UINT64 CurrentTick; >=20 > + UINT64 Delta; >=20 > + >=20 > + CurrentTick =3D GetPerformanceCounter (); >=20 > + >=20 > + // >=20 > + // Determine if the counter is counting up or down >=20 > + // >=20 > + if (mPerformanceCounterStartValue < mPerformanceCounterEndValue) { >=20 > + // >=20 > + // Counter counts upwards, check for an overflow condition >=20 > + // >=20 > + if (*PreviousTick > CurrentTick) { >=20 > + Delta =3D (mPerformanceCounterEndValue - *PreviousTick) + CurrentT= ick; >=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 (mPerformanceCounterStartValue - CurrentTick) + *Previou= sTick; >=20 > + } else { >=20 > + Delta =3D *PreviousTick - CurrentTick; >=20 > + } >=20 > + } >=20 > + >=20 > + // >=20 > + // Set PreviousTick to CurrentTick >=20 > + // >=20 > + *PreviousTick =3D CurrentTick; >=20 > + >=20 > + return Delta; >=20 > +} >=20 > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h > b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.h > index ca223bd20c..4401675872 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 control= ler > driver. >=20 >=20 >=20 > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
>=20 > Copyright (c) 2011 - 2017, Intel Corporation. All rights 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 > #include >=20 > #include >=20 > #include >=20 > +#include >=20 >=20 >=20 > #include >=20 >=20 >=20 > @@ -37,6 +39,11 @@ typedef struct _USB_DEV_CONTEXT > USB_DEV_CONTEXT; > #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) > (MultU64x32((Time), 1000)) >=20 > + >=20 > // >=20 > // The unit is microsecond, setting it as 1us. >=20 > // >=20 > @@ -720,4 +727,29 @@ XhcAsyncIsochronousTransfer ( > IN VOID *Context >=20 > ); >=20 >=20 >=20 > +/** >=20 > + Converts a time in nanoseconds to a performance counter tick count. >=20 > + >=20 > + @param Time The time in nanoseconds to be converted to performance > counter ticks. >=20 > + @return Time in nanoseconds converted to ticks. >=20 > +**/ >=20 > +UINT64 >=20 > +XhcConvertTimeToTicks ( >=20 > + UINT64 Time >=20 > + ); >=20 > + >=20 > +/** >=20 > + Computes and returns the elapsed ticks since PreviousTick. The >=20 > + value of PreviousTick is overwritten with the current performance >=20 > + counter value. >=20 > + >=20 > + @param PreviousTick Pointer to PreviousTick count. >=20 > + @return The elapsed ticks since PreviousCount. PreviousCount is >=20 > + overwritten with the current performance counter value. >=20 > +**/ >=20 > +UINT64 >=20 > +XhcGetElapsedTicks ( >=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 an= d > transferring >=20 > # Control, Bulk, Interrupt and Isochronous requests to those attached u= sb > LS/FS/HS/SS devices. >=20 > # >=20 > +# (C) Copyright 2023 Hewlett Packard Enterprise Development LP
>=20 > # Copyright (c) 2011 - 2018, Intel Corporation. All rights 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..40f2f1f227 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 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,34 @@ XhcWaitOpRegBit ( > IN UINT32 Timeout >=20 > ) >=20 > { >=20 > - EFI_STATUS Status; >=20 > - EFI_EVENT TimeoutEvent; >=20 > - >=20 > - TimeoutEvent =3D NULL; >=20 > + UINT64 TimeoutTicks; >=20 > + UINT64 ElapsedTicks; >=20 > + UINT64 TicksDelta; >=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 > - >=20 > + TimeoutTicks =3D XhcConvertTimeToTicks > (XHC_MICROSECOND_TO_NANOSECOND (Timeout * XHC_1_MILLISECOND)); >=20 > + ElapsedTicks =3D 0; >=20 > + CurrentTick =3D GetPerformanceCounter (); >=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 > + TicksDelta =3D XhcGetElapsedTicks (&CurrentTick); >=20 > + // Ensure that ElapsedTicks is always incremented to avoid indefinit= e > hangs >=20 > + if (TicksDelta =3D=3D 0) { >=20 > + TicksDelta =3D XhcConvertTimeToTicks > (XHC_MICROSECOND_TO_NANOSECOND (XHC_1_MICROSECOND)); >=20 > + } >=20 >=20 >=20 > -DONE: >=20 > - if (TimeoutEvent !=3D NULL) { >=20 > - gBS->CloseEvent (TimeoutEvent); >=20 > - } >=20 > + ElapsedTicks +=3D TicksDelta; >=20 > + } while (ElapsedTicks < TimeoutTicks); >=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 53421e64a8..613b1485f1 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 reserved.
>=20 > Copyright (c) Microsoft Corporation.
>=20 > Copyright (C) 2022 Advanced Micro Devices, Inc. All rights reserved.
>=20 > @@ -1276,15 +1277,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 > @@ -1299,12 +1299,14 @@ XhcExecTransfer ( > UINT8 SlotId; >=20 > UINT8 Dci; >=20 > BOOLEAN Finished; >=20 > - EFI_EVENT TimeoutEvent; >=20 > + UINT64 TimeoutTicks; >=20 > + UINT64 ElapsedTicks; >=20 > + UINT64 TicksDelta; >=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 > @@ -1322,34 +1324,18 @@ 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 > - 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 >=20 > -RINGDOORBELL: >=20 > XhcRingDoorBell (Xhc, SlotId, Dci); >=20 >=20 >=20 > + TimeoutTicks =3D XhcConvertTimeToTicks ( >=20 > + XHC_MICROSECOND_TO_NANOSECOND ( >=20 > + Timeout * XHC_1_MILLISECOND >=20 > + ) >=20 > + ); >=20 > + ElapsedTicks =3D 0; >=20 > + CurrentTick =3D GetPerformanceCounter (); >=20 > + >=20 > do { >=20 > Finished =3D XhcCheckUrbResult (Xhc, Urb); >=20 > if (Finished) { >=20 > @@ -1357,22 +1343,22 @@ RINGDOORBELL: > } >=20 >=20 >=20 > gBS->Stall (XHC_1_MICROSECOND); >=20 > - } while (IndefiniteTimeout || EFI_ERROR (gBS->CheckEvent > (TimeoutEvent))); >=20 > + TicksDelta =3D XhcGetElapsedTicks (&CurrentTick); >=20 > + // Ensure that ElapsedTicks is always incremented to avoid indefinit= e > hangs >=20 > + if (TicksDelta =3D=3D 0) { >=20 > + TicksDelta =3D XhcConvertTimeToTicks > (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 > + ElapsedTicks +=3D TicksDelta; >=20 > + } while (IndefiniteTimeout || ElapsedTicks < TimeoutTicks); >=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 (#108549): > https://edk2.groups.io/g/devel/message/108549 > Mute This Topic: https://groups.io/mt/101320913/1768737 > Group Owner: devel+owner@edk2.groups.io > Unsubscribe: https://edk2.groups.io/g/devel/unsub [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 (#108899): https://edk2.groups.io/g/devel/message/108899 Mute This Topic: https://groups.io/mt/101320913/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-