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 EECC1940D23 for ; Mon, 31 Jul 2023 02:57:33 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=ASC8iEQ7R7eT9f1JOwOYGLiBuiXSG1fTx9kwdp8ZAak=; c=relaxed/simple; d=groups.io; h=X-Received:X-Received:X-IronPort-AV:X-IronPort-AV:X-Received:X-ExtLoop1:X-IronPort-AV:X-IronPort-AV:X-Received:X-Received:X-Received:X-Received:ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:X-Received:X-Received:From:To:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:X-MS-Has-Attach:X-MS-TNEF-Correlator:x-ms-publictraffictype:x-ms-traffictypediagnostic:x-ms-office365-filtering-correlation-id:x-ld-processed:x-ms-exchange-senderadcheck:x-ms-exchange-antispam-relay:x-microsoft-antispam-message-info:x-ms-exchange-antispam-messagedata-chunkcount:x-ms-exchange-antispam-messagedata-0:MIME-Version:X-MS-Exchange-CrossTenant-AuthAs:X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-Network-Message-Id:X-MS-Exchange-CrossTenant-originalarrivaltime:X-MS-Exchange-CrossTenant-fromentityheader:X-MS-Exchange-CrossTenant-id:X-MS-Exchange-CrossTenant-mailboxtype:X-MS-Exchange-CrossTenant-userprincipalname:X-MS-Exchange-Transport-CrossT enantHeadersStamped:X-OriginatorOrg:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:X-Gm-Message-State:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1690772252; v=1; b=n43TLXk1FFzOWccvEUxTrtEhSv+sSro4vnlxRoyIvf44VVzh/VZQAAnIxtBl4lYbMfb7QmZz I7NQnY+EUyc8PtPDukUvEmDqwGRAsXPSCturomX+UUigIegJQLqT7Z/7hDBvBlQw+4AVIiWktk3 xU+mtlSUAhtZw8vaF9MYvDSM= X-Received: by 127.0.0.2 with SMTP id ekhPYY7687511xtFuC0lzy3n; Sun, 30 Jul 2023 19:57:32 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.100]) by mx.groups.io with SMTP id smtpd.web10.86591.1690772251536498179 for ; Sun, 30 Jul 2023 19:57:31 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10787"; a="435205781" X-IronPort-AV: E=Sophos;i="6.01,243,1684825200"; d="scan'208";a="435205781" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Jul 2023 19:57:31 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10787"; a="731426520" X-IronPort-AV: E=Sophos;i="6.01,243,1684825200"; d="scan'208";a="731426520" X-Received: from orsmsx601.amr.corp.intel.com ([10.22.229.14]) by fmsmga007.fm.intel.com with ESMTP; 30 Jul 2023 19:57:30 -0700 X-Received: from orsmsx603.amr.corp.intel.com (10.22.229.16) by ORSMSX601.amr.corp.intel.com (10.22.229.14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27; Sun, 30 Jul 2023 19:57:30 -0700 X-Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx603.amr.corp.intel.com (10.22.229.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.27 via Frontend Transport; Sun, 30 Jul 2023 19:57:30 -0700 X-Received: from NAM04-BN8-obe.outbound.protection.outlook.com (104.47.74.46) by edgegateway.intel.com (134.134.137.100) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.27; Sun, 30 Jul 2023 19:57:30 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kDM5Z6nGmq8r8x6fYjbick/HET+0b0fVvB13u7mpz1cf8b3atPmSOx6LLKWmgiHQnWJjhPIf7h53zH5EXWDcRYtvg1cM9ezsCXvQaVbDYVxo0wwiY1Sjzoq6OieJbdlwCV+jXjjhw66TJX6eaJ7Y7BMj8IjNc8eSpCuJRSkmZXPZF43V08qeCI/Lxs2cAURh59ZNx23c4qf4ScOMxM7XCwkBCJnjFE60tmY8MRhB6jwcxcOT2CozBQzuZpyctCokS10Lmq9wfDHSFg5TEpxAqgy8R5ndkD1J0+QrQa1vjNI/E114a2+QEoVsmLHApSQSFwSpNcpRquFr9pxZTS40+A== 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=XbgWiFe9MJlSibbh3D296UXhaClNxMZAUXkiFBVt7MM=; b=hyOntrpVzOOSeM5kZBvaUvtIInE+lNFlY06U72+wW/kbrkxxhLxLGK7AHglHs4KCuZdRpzFCtNoE8ys12Hx5oAnPXoF4HEkddEd3soZC9Fw3rZDSyYlMmNfeVllItjRzxEIEPhzwx1k8jQKwHBW5jSfy7WR2Yr2kpxIPMmckaDkKccyustcBxU/ZXn3C5M0SxEN+AH/kBt2o//jlCstGAkWKeuhbTn05xg3SQH1gOg+L7VlhDNLj8sSZI+IDy0untY3XQ7yu4O2p2BotFNuVh/UI116s3r5wF0g6bfNiz7LOt9iCMOFdVl3v3/cD3ZkErDPvTa8Q4liPPQU2pVcAog== 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 IA0PR11MB7187.namprd11.prod.outlook.com (2603:10b6:208:441::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6631.43; Mon, 31 Jul 2023 02:57:27 +0000 X-Received: from DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::ebe2:341b:4ed7:d19b]) by DM6PR11MB4025.namprd11.prod.outlook.com ([fe80::ebe2:341b:4ed7:d19b%6]) with mapi id 15.20.6631.042; Mon, 31 Jul 2023 02:57:27 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "Henz, Patrick" , Michael Brown Subject: Re: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts Thread-Topic: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts Thread-Index: AQHZr32iafvIU0JyA0+vZWQmCs2v8a/TT1yg Date: Mon, 31 Jul 2023 02:57:27 +0000 Message-ID: References: In-Reply-To: Accept-Language: en-US, zh-CN X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM6PR11MB4025:EE_|IA0PR11MB7187:EE_ x-ms-office365-filtering-correlation-id: f8722aa7-a060-447a-c241-08db9171dfd0 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: umcxfxyLBs68iIZpIW8yV0gnDuRL9n0lCuKaZUIe+zp0uvDmZx/koleq29jBgfAzpxuPLBrjbUQJtYreI0TGMnyjWb5dYHghXPJh1li8TSNylL0HfK2lBqJXg87iQT7qs9OQxKUtZE95vlYq2vVQLflZCYj7LzXKNtET2QeY2OJ03gKPKk0t8VSzv96OGOQTz3hOUe3F7cg39/vENlO+saX+JrjTNn2Sz2aW6J9uyIMnCjOXTYS1ahxeQD01TDIy8ax0gEwMzmQFKwN9WRl5lVh8yzP1itocRMVk6PL6rpfDeyj/5FyMQp7gzag9dw86xQvWWKri4Zw2F9+wDEgi4xW1OqKiNoBiDjld1pUoMMPjF32NeYdVN0KvJoXfpDbfQC2yqChqR15FKaNJ/llBleImYXgz4IOaSQpHP/2vfWTvpyTCAOheF0/CN3B7pUHqD1vWzqe2yitsqVmgJwm8SMqteemSbYGtoOX4h8/2td+KGvxYAvSpNsHjufQJe/mqdZ4ElHNXLlKWfr652DcTsWWyM4qe4wYLtBUaqSCisY6uEYJ0F3JiMAxvNxZkXwFzhAmqzux+9Y5Eb2JcnqdSMCdZoKWRgB3AyzNGvqz2QQapP5N5Fg42p60sutCt8hWZTBUA3zG3v6bkGiI0HUB/Xw== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?Vx79PfN553BXmUQOwOBkLWP8Gpy69l+OJP9fs7+8SaXyhjyUIymyttEQvn1Z?= =?us-ascii?Q?7aAIYCMdf/BqYM2cMm/gdoVXXzM0Dii9JDCrT+byO/HxDTEKlyg0DOYtGNEd?= =?us-ascii?Q?lttUWAQX7toZJiNbLsWY/OpDkC3H1c01HBOOyIBjAJcXcAY2DVre1oPj/nNE?= =?us-ascii?Q?u9prDELFHLLSq6GhMJ3i3SeJa5DPtpuasRhNgvkU8VocaPMHMcsMxGpG7soW?= =?us-ascii?Q?5yKUI1moIikHQK/yilzr/S6ZDAp5y7/Jmt0rBxde5446D5YTBGpX//Cwxf4j?= =?us-ascii?Q?IXU9y8L3yAOYEwEZrwtsnzakZ7TB0QTFTC7FyUlPwufB0XPIJFiXjCHI2/TE?= =?us-ascii?Q?dr0US2Nqh0KdpcApucHr37OvAQg4J5FdC4jerpJvfDW4xiifpdE9BBE2dIrG?= =?us-ascii?Q?gUskDg2c4V2wr5pgMmrvRBg5UfXMv8LIgBhYTyHxIQpaEOS85VvzhMfAjBOr?= =?us-ascii?Q?kF7nwEPSpcn/XJYJWq8o+jKkVhg/TCRJWSuTDk9CBHPBCo62/DgeqRHUh4yk?= =?us-ascii?Q?xI5qvx9kQfCPysFVfOYqZlUWVhF9MKXMsRZF62YiKPBTFTm5RBhmBn5Q843t?= =?us-ascii?Q?hThhfvmz/IEJoRSHNTnemga9/U2k4XlJZdVisFrgc96Lx3BPAqQUek3gs3hG?= =?us-ascii?Q?wYntV/quIjq3LB7X4ofwghsoJG2IikyBoPjzdYtue5nYB9PPpft8rN+LFVEL?= =?us-ascii?Q?9hxh3ddTt9TKU8l9wUGeMxwpxb3M5Glv4X3SajsuDJ5uYyhdjujKr/cgyL0M?= =?us-ascii?Q?uZGDYliPHM1DchIcZtDAx9FO3wftr/WgcTaVY8ZzRQEcJKX75CV26LOVIBIE?= =?us-ascii?Q?3OI6fsGYAQILugmpkOdAnPw9Yfm5X2kPhuU6IyttHyyU2uQFbHJ635LI1l1Y?= =?us-ascii?Q?QIqjU3WlISBFDI8Y4WXedVV8KpAS7sWsdzcstV0L/vCCXCkvqqphisXcCWa1?= =?us-ascii?Q?k4vUK7i8H3RRVdO2Oqv3KMg9HzadAoFMgfKW18IK3JkU7HFJEqDj3FDIXAGy?= =?us-ascii?Q?+6ywJQZDWdu/jUNu3EBiBwSCDV3PHV0+AmmFCswqGf1IY7ul0oLVXRFA72FG?= =?us-ascii?Q?HqAKrYBixPH3rvUmQVzAYcTH0TIgc6TYVTfgaxHyC/HO5CYXIa7pRHxlVsF4?= =?us-ascii?Q?zGSunWs/e/kkjsqG6xD2hHjLWVTXgiqz57diHzM9oWmRsPNizYVGYLQ8QVM8?= =?us-ascii?Q?M4EmHaECjuzrYcUGHT8D1cXxCSSNjqwbAzQJXDCvZIu8rioWDGYcVygM21hM?= =?us-ascii?Q?oUjxuaxkZM4YtdTYBwqX9dvKvFibS8fis+nRydeo0LncnI1Mi5FeYYJixgRO?= =?us-ascii?Q?vh7Gaw+3+v5zITTPQUUf7jWCtynIOd5IMYJT99mi9LvGt/uzdxiyEE7iZw2F?= =?us-ascii?Q?tLI1KBgVLkz4tmRGvvaax5uuB6SHiw+B/WCRnWMvGWknapZ9IznPfYyOYLYr?= =?us-ascii?Q?g1InzlGPTCNZ87eRNYpb1LVU4rXLsB3ORWTXeXnvhufQOCKaWwPbF2urns/u?= =?us-ascii?Q?WMYei+5qB4scC4M5RnGCYG/JbMlw3PoVVfFWZJkxljhJu+tb+83vdYaDbO3C?= =?us-ascii?Q?c+67Z67+K63tTr0vbEDy6B9coIvQk3Kng8oRgD9n?= 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: f8722aa7-a060-447a-c241-08db9171dfd0 X-MS-Exchange-CrossTenant-originalarrivaltime: 31 Jul 2023 02:57:27.5043 (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: sB1H7AgvILVZbMU+l57C8jTisJJPdcInoMselgHhKNBagM9QbTlBQs+FCWzQ+ODwyVY/57LAbPvHgAkiq/zEKQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR11MB7187 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: kLgg7KAiQpdrBH00Ioc2SP6vx7686176AA= 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=n43TLXk1; 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 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_MILLISECOND"? 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, > Patrick > Sent: Thursday, July 6, 2023 4:16 AM > To: devel@edk2.groups.io > Cc: Henz, Patrick > Subject: [edk2-devel] [PATCH] MdeModulePkg/XhciDxe: Use Performance > Timer for XHCI Timeouts >=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 > 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 >=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 > @@ -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 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,10 @@ 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) ((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 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..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 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 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 reserved.
>=20 > Copyright (c) Microsoft Corporation.
>=20 > Copyright (C) 2022 Advanced Micro Devices, Inc. All rights 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 > (TimeoutEvent))); >=20 > + TimeDelta =3D XhcGetElapsedTime (&CurrentTick); >=20 > + // Ensure that ElapsedTime is always incremented to avoid 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): > https://edk2.groups.io/g/devel/message/106668 > Mute This Topic: https://groups.io/mt/99972791/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 (#107390): https://edk2.groups.io/g/devel/message/107390 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-