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 97672AC087B for ; Mon, 25 Sep 2023 02:58:11 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=GzUWdCJGhf8DUO0VXDrAs/F3Z1BLLuJpMdt3XAW55Lk=; 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=1695610690; v=1; b=fQ2VFNGI7dqhE7xtBUOGGTxFlJcbWGeTKGzdXzvEOHaYdHLiIBw/KnOJ6dN2qagn2oDGc4j2 UcFFc2nLqOIXZRB3roZqCzJYVKRGIj04cB6rwemVrZNz6X1vwhx7adSv4gYqKyUzAFy5QeqT5Hz ZLSUDA60YYvxXoGBOBa+D2Y0= X-Received: by 127.0.0.2 with SMTP id rh1DYY7687511x18KqBLbXTz; Sun, 24 Sep 2023 19:58:10 -0700 X-Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web10.53403.1695610689273961802 for ; Sun, 24 Sep 2023 19:58:09 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="381061294" X-IronPort-AV: E=Sophos;i="6.03,174,1694761200"; d="scan'208";a="381061294" X-Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2023 19:58:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10843"; a="818453448" X-IronPort-AV: E=Sophos;i="6.03,174,1694761200"; d="scan'208";a="818453448" X-Received: from orsmsx603.amr.corp.intel.com ([10.22.229.16]) by fmsmga004.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 24 Sep 2023 19:58:08 -0700 X-Received: from orsmsx611.amr.corp.intel.com (10.22.229.24) 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.32; Sun, 24 Sep 2023 19:58:07 -0700 X-Received: from orsmsx610.amr.corp.intel.com (10.22.229.23) by ORSMSX611.amr.corp.intel.com (10.22.229.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32; Sun, 24 Sep 2023 19:58:07 -0700 X-Received: from orsedg603.ED.cps.intel.com (10.7.248.4) by orsmsx610.amr.corp.intel.com (10.22.229.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.32 via Frontend Transport; Sun, 24 Sep 2023 19:58:07 -0700 X-Received: from NAM11-CO1-obe.outbound.protection.outlook.com (104.47.56.174) 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.32; Sun, 24 Sep 2023 19:58:07 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CgGH1P5QgRm5LL5uEsoeneFoFa84cYu+EHLM1/bNsgtJY99+VRfNuHY8cgnnrTlDVNXlHHvKRQyjFayOx2TUq2lv3/YDv8ScpBTDeA4dyIQEC3EpC2eWO+wd1fqhSyvMxp3vdrbmXZ2m6WIGd/etghJYjclGHcK+1VQG224z1c63czKJ2BASvl0llI/ByGFmdJJJD5BNDMBr5+p0ay8Ei/diCSqqig/CnZDwGFPfvR0yzZn+lDz9f8+QZrCDV0KHbNnEoQqa0e74lmivCJdsTGyx48py/U+2AkNuKSRNDNV4pAHGqjm/N0KaXjgEPkkL9kKQt97ztTfnUCpr6MQKrQ== 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=PwWJ8xE4zB0/8rZ+CIglcz3VL+C5r7yxSYwaiImskzU=; b=h6J3iJx3ouwOaZ1ZfQyc+JSd4zNC53I8UXCQubOuze/b0DoQrGxIEYiM11yp0DG3mNFsEYDXkoXiLjLO3cQ/ml1gqgpgUKw5z3pJCUXaMHcmqP9CR3swYGvGCZ6fPS66eky7CSQKii8aPIXvGmEJz+3z6BHn1oeSG/vxrJwXFgkJzLPxSFVhNIXY9ytl214lSWqzoZ1DUZ61c9G+KeW/PApHKZ/rhDnmHXn+ZHAp10T4CyQ2QYPnsCanpYYgFRG+wwdSzAfbLnpsIN3h8934vF5O6ZRnqlPgBd+IegLV12NPcEvmRXibS41IA2+eyojzHwN6r7vxk6P4XNCnB1OQNw== 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 MN0PR11MB6254.namprd11.prod.outlook.com (2603:10b6:208:3c5::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6813.23; Mon, 25 Sep 2023 02:58:04 +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.6813.027; Mon, 25 Sep 2023 02:58:04 +0000 From: "Wu, Hao A" To: "devel@edk2.groups.io" , "Wu, Hao A" , "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: AQHZ5cV8N5X9tqYmm0iSCQ9AOvYUw7AjW1KQgAeRIvA= Date: Mon, 25 Sep 2023 02:58:04 +0000 Message-ID: References: <382ea3abf9d4e410cfcde1bcff453eac409e350b.1694541645.git.patrick.henz@hpe.com> 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_|MN0PR11MB6254:EE_ x-ms-office365-filtering-correlation-id: c7c8d8dc-19c7-4b33-4470-08dbbd733cc7 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: 3a4/bYzTl1+dsQsDRBa15NgDBjMYkvJRznWXHYlBIXMgJofg3vpGLtpfmCiyVsmK4pEW/2eGs/onafe8dlunp3+9/TmbjGEX2J7xyWHZ6YOSH7OibItrMYKztYdPXqLT4JEIn3cXMflL21veF1fYOoM6NTPil2mBsGQ/oJoNgIJDlSXFigDMht+zawJcGakLBqEF/eHGDDxSjH6hGGPggBvfWxc0Y4UsYgeOpQZG796SDXaD+kCWu/qK6J0Ctej4/XUcae3iu/JP7hBesyoB/gHyE6c9CuEKkL9GVt7QeVNVmAzyqSsnwp+E/XuuhLpb7sigcEssGGR93HSIN/quAa9IeooKgQKS0JY47M1npdRqJxnJhUeNwXaTPUNiJYKMgDwyAS3t9pnvPh8dEjqvym91m39VtWB89Sk/bkE/yjesERySzsVSSjcEiIUC+ItmC7Skvb25RuUBP1BgCjnYSRVegSuKkOO0WNBK60TbCr3pCoco4BSjJlakI+e1c3X4vGWFU4iYmw+hibhoSz10AQ4QnjuetuHBn5i87N2YDwYL+tRHy+QAhHWRd9HZSxpfNCRro8B7IIKGL+PLC+IMHoJu9mLmMYAN6HRkU+2jgm4xu/6CToUleEADqVn8qHrvUMMfawOFfVE7ukAan/BlOw== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?4uhwLoz+QqJsSKeGNHtuwh3lXhowC1PprOvCHcsiEcMknLA3OToTVHxDcD3X?= =?us-ascii?Q?mAxLuOPGxdOWgjWhpD9ZIi4enEWMLJ05VTlzxSTVWXzdvHaD5gRfbvYn+NWY?= =?us-ascii?Q?yLCM6EQYPGLraPqDFjEIyD/lENt6w/D6xtnBCD2k6YRX5iLJxDDQugx4OsE+?= =?us-ascii?Q?D6emiYhERO+ARHcOemeLWlDc8M9/TQdTrLelal2/Pu+Uz9k2bzcib9S5bAKR?= =?us-ascii?Q?ZwfLJM8FOdo9Ex7GsZLIvDTOJNFBMwwkMcHkWZCJa3m46kl2SoQ5cFeEt1Eg?= =?us-ascii?Q?T/vsFzMPQgPOj79XXSbTGCdt1M/NfdUT1LSxTSScV5yeGP6fLE2u8Qfd2RHd?= =?us-ascii?Q?oKrC5QBjWdmwnts68H/t6WngFzcW9uZJhl5G2lXSeDMxlWN9dN7AsEFKW54d?= =?us-ascii?Q?2SdfNa39ahSsszfjLWSnphsLgBi4JQpOeXl3pR7puGqIri0wzJpI4EYgg9xb?= =?us-ascii?Q?C/XjM28rjZThBAlC3Z+3r88wtuUjKROzCSa7MOk5lwXcT5NZBuskZt+tV05D?= =?us-ascii?Q?BjCIm31FwVMYdFh2X6aMauVFpbSbJa7cAFN0iqyj3sIzTno2CRWf4R97d+nP?= =?us-ascii?Q?+79wOhDde7jS86RXswxhxjWny3zDzsteo85T9parGmjRJNTnB2BZyLAsTM11?= =?us-ascii?Q?+GDnVKiUTFAgwf2OCK/KflrJkWrWYz5a/IxgB04eWkYByDY8u1ptFzFLHOfs?= =?us-ascii?Q?YMv71TKxRH1WdQZZASjRakLwRkcsVWyIgAglzPOYC+gceMswVSt0UqrZeQM9?= =?us-ascii?Q?W+3sqzEIZU9HGijdFbz+bVpm0UsnaA1v+ZcILUScYVsMxr4mVY130Yf6l2DE?= =?us-ascii?Q?jHF6ILzgfqds3mQAycKFUmrXHI7X1WxwZV42/FzX1g/8flv6UVWqvLdmhtxy?= =?us-ascii?Q?b6M3HbG19yb6Xm6dY3KhYLcMEHxbG8i77UmXF24LELJH5r0jr+LImRKfoJyy?= =?us-ascii?Q?mXjaqkT8AJJUYwQgIrRmOMIlX6oVpVJdfuSxBspCGotJcTwWhmbVXCvuz2Xn?= =?us-ascii?Q?ODpzpDxeqJiHp55512G2PIKGO6s1Fv6lEVNl6VACcFhiZWamM4/0g2RElQao?= =?us-ascii?Q?B/kQ7FLLHG4KLOdyBcv71IlUytuMOoglUXhnmxabegex//ZRP3hgR31BJn7q?= =?us-ascii?Q?Hq7X44cZvIMqedFOWsn0z98/vSKQ5vAjCfDBpvGxDNjDS4/Mq4cJsKJJLu0n?= =?us-ascii?Q?/iFet24/zOimcC9Hmly2kF2F+2bkaG8HloPAdxvvIGKlu9PK1LUcH5yPzKmG?= =?us-ascii?Q?LT2Ub8BhRty99RbfQc+aIWYGvjn+zfkOFAmgDIejfP3NpoUo0qq00WhRbfpA?= =?us-ascii?Q?9Wve47mEiFFNfBS1iZ2AlHVIYeCNheFY8K+Y8vZB/1Xpya5dV80KsDdeCIjZ?= =?us-ascii?Q?DJ4FeneH44qbsyiohbMOiKzOIlgqzTQl7NfqneddDWej4g5ojEk6aG59Yugc?= =?us-ascii?Q?Ilr6n2PJ9nV4eLu1BsX6UT5hofqBu807/n/44cD7AJ4idXOXi1NXd/2A0rXq?= =?us-ascii?Q?tLYBJsoWquJf5V1GaSwYhZQ7iMvFzE7mtI9xikaMZlsW4UyznGlQDwwsXF8+?= =?us-ascii?Q?Kn4yAKXhJDaVKCBRUPMwoMl/h2/ptXniAv3+FZmr?= 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: c7c8d8dc-19c7-4b33-4470-08dbbd733cc7 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Sep 2023 02:58:04.1546 (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: pDQRvITfEtqqaA+CmogIoWgmq9ac/B7UYmOFwwUmyofxI9i3U3+fPMGwkb+qXSGEUTAwwgHKF20mH1cc9GvgHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN0PR11MB6254 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: VXQMaoGBr2fYe9MI3qOnKsTOx7686176AA= 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=fQ2VFNGI; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); 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 Merged via: PR - https://github.com/tianocore/edk2/pull/4862 Commit - https://github.com/tianocore/edk2/commit/43dcf453fc15ca152945ca41d= cce7f2f43a14313 Best Regards, Hao Wu > -----Original Message----- > From: devel@edk2.groups.io On Behalf Of Wu, Hao > A > Sent: Wednesday, September 20, 2023 3:24 PM > To: devel@edk2.groups.io; Henz, Patrick > Cc: Ni, Ray > Subject: Re: [edk2-devel] [PATCH v3] MdeModulePkg/XhciDxe: Use > Performance Timer for XHCI Timeouts >=20 > Reviewed-by: Hao A Wu >=20 > Best Regards, > Hao Wu >=20 > > -----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 > > > > REF:https://bugzilla.tianocore.org/show_bug.cgi?id=3D2948 > > > > 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. > > > > 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(-) > > > > 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 > > > > The XHCI controller driver. > > > > > > > > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.
> > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > @@ -85,6 +86,11 @@ EFI_USB2_HC_PROTOCOL gXhciUsb2HcTemplate =3D { > > 0x0 > > > > }; > > > > > > > > +UINT64 mPerformanceCounterStartValue; > > > > +UINT64 mPerformanceCounterEndValue; > > > > +UINT64 mPerformanceCounterFrequency; > > > > +BOOLEAN mPerformanceCounterValuesCached =3D FALSE; > > > > + > > > > /** > > > > Retrieves the capability of root hub ports. > > > > > > > > @@ -2294,3 +2300,114 @@ XhcDriverBindingStop ( > > > > > > return EFI_SUCCESS; > > > > } > > > > + > > > > +/** > > > > + Converts a time in nanoseconds to a performance counter tick count. > > > > + > > > > + @param Time The time in nanoseconds to be converted to performance > > counter ticks. > > > > + @return Time in nanoseconds converted to ticks. > > > > +**/ > > > > +UINT64 > > > > +XhcConvertTimeToTicks ( > > > > + IN UINT64 Time > > > > + ) > > > > +{ > > > > + UINT64 Ticks; > > > > + UINT64 Remainder; > > > > + UINT64 Divisor; > > > > + UINTN Shift; > > > > + > > > > + // Cache the return values to avoid repeated calls to > > GetPerformanceCounterProperties () > > > > + if (!mPerformanceCounterValuesCached) { > > > > + mPerformanceCounterFrequency =3D GetPerformanceCounterProperties ( > > > > + &mPerformanceCounterStartValue, > > > > + &mPerformanceCounterEndValue > > > > + ); > > > > + > > > > + mPerformanceCounterValuesCached =3D TRUE; > > > > + } > > > > + > > > > + // Prevent returning a tick value of 0, unless Time is already 0 > > > > + if (0 =3D=3D mPerformanceCounterFrequency) { > > > > + return Time; > > > > + } > > > > + > > > > + // Nanoseconds per second > > > > + Divisor =3D 1000000000; > > > > + > > > > + // > > > > + // Frequency > > > > + // Ticks =3D ------------- x Time > > > > + // 1,000,000,000 > > > > + // > > > > + Ticks =3D MultU64x64 ( > > > > + DivU64x64Remainder ( > > > > + mPerformanceCounterFrequency, > > > > + Divisor, > > > > + &Remainder > > > > + ), > > > > + Time > > > > + ); > > > > + > > > > + // > > > > + // Ensure (Remainder * Time) will not overflow 64-bit. > > > > + // > > > > + // HighBitSet64 (Remainder) + 1 + HighBitSet64 (Time) + 1 <=3D 64 > > > > + // > > > > + Shift =3D MAX (0, HighBitSet64 (Remainder) + HighBitSet64 (Time)= - 62); > > > > + Remainder =3D RShiftU64 (Remainder, (UINTN)Shift); > > > > + Divisor =3D RShiftU64 (Divisor, (UINTN)Shift); > > > > + Ticks +=3D DivU64x64Remainder (MultU64x64 (Remainder, Time), Divi= sor, > > NULL); > > > > + > > > > + return Ticks; > > > > +} > > > > + > > > > +/** > > > > + Computes and returns the elapsed ticks since PreviousTick. The > > > > + value of PreviousTick is overwritten with the current performance > > > > + counter value. > > > > + > > > > + @param PreviousTick Pointer to PreviousTick count. > > > > + @return The elapsed ticks since PreviousCount. PreviousCount is > > > > + overwritten with the current performance counter value. > > > > +**/ > > > > +UINT64 > > > > +XhcGetElapsedTicks ( > > > > + IN OUT UINT64 *PreviousTick > > > > + ) > > > > +{ > > > > + UINT64 CurrentTick; > > > > + UINT64 Delta; > > > > + > > > > + CurrentTick =3D GetPerformanceCounter (); > > > > + > > > > + // > > > > + // Determine if the counter is counting up or down > > > > + // > > > > + if (mPerformanceCounterStartValue < mPerformanceCounterEndValue) { > > > > + // > > > > + // Counter counts upwards, check for an overflow condition > > > > + // > > > > + if (*PreviousTick > CurrentTick) { > > > > + Delta =3D (mPerformanceCounterEndValue - *PreviousTick) + Curren= tTick; > > > > + } else { > > > > + Delta =3D CurrentTick - *PreviousTick; > > > > + } > > > > + } else { > > > > + // > > > > + // Counter counts downwards, check for an underflow condition > > > > + // > > > > + if (*PreviousTick < CurrentTick) { > > > > + Delta =3D (mPerformanceCounterStartValue - CurrentTick) + > *PreviousTick; > > > > + } else { > > > > + Delta =3D *PreviousTick - CurrentTick; > > > > + } > > > > + } > > > > + > > > > + // > > > > + // Set PreviousTick to CurrentTick > > > > + // > > > > + *PreviousTick =3D CurrentTick; > > > > + > > > > + return Delta; > > > > +} > > > > 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 @@ > > > > > > Provides some data structure definitions used by the XHCI host contr= oller > > driver. > > > > > > > > +(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 > > > > #include > > > > #include > > > > +#include > > > > > > > > #include > > > > > > > > @@ -37,6 +39,11 @@ typedef struct _USB_DEV_CONTEXT > > USB_DEV_CONTEXT; > > #include "ComponentName.h" > > > > #include "UsbHcMem.h" > > > > > > > > +// > > > > +// Converts a count from microseconds to nanoseconds > > > > +// > > > > +#define XHC_MICROSECOND_TO_NANOSECOND(Time) > > (MultU64x32((Time), 1000)) > > > > + > > > > // > > > > // The unit is microsecond, setting it as 1us. > > > > // > > > > @@ -720,4 +727,29 @@ XhcAsyncIsochronousTransfer ( > > IN VOID *Context > > > > ); > > > > > > > > +/** > > > > + Converts a time in nanoseconds to a performance counter tick count. > > > > + > > > > + @param Time The time in nanoseconds to be converted to performance > > counter ticks. > > > > + @return Time in nanoseconds converted to ticks. > > > > +**/ > > > > +UINT64 > > > > +XhcConvertTimeToTicks ( > > > > + UINT64 Time > > > > + ); > > > > + > > > > +/** > > > > + Computes and returns the elapsed ticks since PreviousTick. The > > > > + value of PreviousTick is overwritten with the current performance > > > > + counter value. > > > > + > > > > + @param PreviousTick Pointer to PreviousTick count. > > > > + @return The elapsed ticks since PreviousCount. PreviousCount is > > > > + overwritten with the current performance counter value. > > > > +**/ > > > > +UINT64 > > > > +XhcGetElapsedTicks ( > > > > + 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 = and > > transferring > > > > # Control, Bulk, Interrupt and Isochronous requests to those attached= usb > > LS/FS/HS/SS devices. > > > > # > > > > +# (C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > # Copyright (c) 2011 - 2018, Intel Corporation. All rights reserved.<= BR> > > > > # > > > > # SPDX-License-Identifier: BSD-2-Clause-Patent > > > > @@ -54,6 +55,7 @@ > > BaseMemoryLib > > > > DebugLib > > > > ReportStatusCodeLib > > > > + TimerLib > > > > > > > > [Guids] > > > > gEfiEventExitBootServicesGuid ## SOMETIMES_CONSUMES = ## > > Event > > > > diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > index 5700fc5fb8..40f2f1f227 100644 > > --- a/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > +++ b/MdeModulePkg/Bus/Pci/XhciDxe/XhciReg.c > > @@ -2,6 +2,7 @@ > > > > > > The XHCI register operation routines. > > > > > > > > +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
> > > > Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.
> > > > SPDX-License-Identifier: BSD-2-Clause-Patent > > > > > > > > @@ -417,15 +418,14 @@ XhcClearOpRegBit ( > > Wait the operation register's bit as specified by Bit > > > > to become set (or clear). > > > > > > > > - @param Xhc The XHCI Instance. > > > > - @param Offset The offset of the operation register. > > > > - @param Bit The bit of the register to wait for. > > > > - @param WaitToSet Wait the bit to set or clear. > > > > - @param Timeout The time to wait before abort (in mil= lisecond, > > ms). > > > > + @param Xhc The XHCI Instance. > > > > + @param Offset The offset of the operation register. > > > > + @param Bit The bit of the register to wait for. > > > > + @param WaitToSet Wait the bit to set or clear. > > > > + @param Timeout The time to wait before abort (in millisecond, = ms). > > > > > > > > - @retval EFI_SUCCESS The bit successfully changed by host > controller. > > > > - @retval EFI_TIMEOUT The time out occurred. > > > > - @retval EFI_OUT_OF_RESOURCES Memory for the timer event could not > > be allocated. > > > > + @retval EFI_SUCCESS The bit successfully changed by host controller= . > > > > + @retval EFI_TIMEOUT The time out occurred. > > > > > > > > **/ > > > > EFI_STATUS > > > > @@ -437,54 +437,34 @@ XhcWaitOpRegBit ( > > IN UINT32 Timeout > > > > ) > > > > { > > > > - EFI_STATUS Status; > > > > - EFI_EVENT TimeoutEvent; > > > > - > > > > - TimeoutEvent =3D NULL; > > > > + UINT64 TimeoutTicks; > > > > + UINT64 ElapsedTicks; > > > > + UINT64 TicksDelta; > > > > + UINT64 CurrentTick; > > > > > > > > if (Timeout =3D=3D 0) { > > > > return EFI_TIMEOUT; > > > > } > > > > > > > > - Status =3D gBS->CreateEvent ( > > > > - EVT_TIMER, > > > > - TPL_CALLBACK, > > > > - NULL, > > > > - NULL, > > > > - &TimeoutEvent > > > > - ); > > > > - > > > > - if (EFI_ERROR (Status)) { > > > > - goto DONE; > > > > - } > > > > - > > > > - Status =3D gBS->SetTimer ( > > > > - TimeoutEvent, > > > > - TimerRelative, > > > > - EFI_TIMER_PERIOD_MILLISECONDS (Timeout) > > > > - ); > > > > - > > > > - if (EFI_ERROR (Status)) { > > > > - goto DONE; > > > > - } > > > > - > > > > + TimeoutTicks =3D XhcConvertTimeToTicks > > (XHC_MICROSECOND_TO_NANOSECOND (Timeout * > XHC_1_MILLISECOND)); > > > > + ElapsedTicks =3D 0; > > > > + CurrentTick =3D GetPerformanceCounter (); > > > > do { > > > > if (XHC_REG_BIT_IS_SET (Xhc, Offset, Bit) =3D=3D WaitToSet) { > > > > - Status =3D EFI_SUCCESS; > > > > - goto DONE; > > > > + return EFI_SUCCESS; > > > > } > > > > > > > > gBS->Stall (XHC_1_MICROSECOND); > > > > - } while (EFI_ERROR (gBS->CheckEvent (TimeoutEvent))); > > > > - > > > > - Status =3D EFI_TIMEOUT; > > > > + TicksDelta =3D XhcGetElapsedTicks (&CurrentTick); > > > > + // Ensure that ElapsedTicks is always incremented to avoid indefin= ite > > hangs > > > > + if (TicksDelta =3D=3D 0) { > > > > + TicksDelta =3D XhcConvertTimeToTicks > > (XHC_MICROSECOND_TO_NANOSECOND (XHC_1_MICROSECOND)); > > > > + } > > > > > > > > -DONE: > > > > - if (TimeoutEvent !=3D NULL) { > > > > - gBS->CloseEvent (TimeoutEvent); > > > > - } > > > > + ElapsedTicks +=3D TicksDelta; > > > > + } while (ElapsedTicks < TimeoutTicks); > > > > > > > > - return Status; > > > > + return EFI_TIMEOUT; > > > > } > > > > > > > > /** > > > > 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 @@ > > > > > > XHCI transfer scheduling routines. > > > > > > > > +(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 Micro Devices, Inc. All rights reserved. > > > > @@ -1276,15 +1277,14 @@ EXIT: > > /** > > > > Execute the transfer by polling the URB. This is a synchronous opera= tion. > > > > > > > > - @param Xhc The XHCI Instance. > > > > - @param CmdTransfer The executed URB is for cmd transfer = or not. > > > > - @param Urb The URB to execute. > > > > - @param Timeout The time to wait before abort, in mil= lisecond. > > > > + @param Xhc The XHCI Instance. > > > > + @param CmdTransfer The executed URB is for cmd transfer or no= t. > > > > + @param Urb The URB to execute. > > > > + @param Timeout The time to wait before abort, in millisec= ond. > > > > > > > > - @return EFI_DEVICE_ERROR The transfer failed due to transfer e= rror. > > > > - @return EFI_TIMEOUT The transfer failed due to time out. > > > > - @return EFI_SUCCESS The transfer finished OK. > > > > - @retval EFI_OUT_OF_RESOURCES Memory for the timer event could not > > be allocated. > > > > + @return EFI_DEVICE_ERROR The transfer failed due to transfer error. > > > > + @return EFI_TIMEOUT The transfer failed due to time out. > > > > + @return EFI_SUCCESS The transfer finished OK. > > > > > > > > **/ > > > > EFI_STATUS > > > > @@ -1299,12 +1299,14 @@ XhcExecTransfer ( > > UINT8 SlotId; > > > > UINT8 Dci; > > > > BOOLEAN Finished; > > > > - EFI_EVENT TimeoutEvent; > > > > + UINT64 TimeoutTicks; > > > > + UINT64 ElapsedTicks; > > > > + UINT64 TicksDelta; > > > > + UINT64 CurrentTick; > > > > BOOLEAN IndefiniteTimeout; > > > > > > > > Status =3D EFI_SUCCESS; > > > > Finished =3D FALSE; > > > > - TimeoutEvent =3D NULL; > > > > IndefiniteTimeout =3D FALSE; > > > > > > > > if (CmdTransfer) { > > > > @@ -1322,34 +1324,18 @@ XhcExecTransfer ( > > > > > > if (Timeout =3D=3D 0) { > > > > IndefiniteTimeout =3D TRUE; > > > > - goto RINGDOORBELL; > > > > - } > > > > - > > > > - Status =3D gBS->CreateEvent ( > > > > - EVT_TIMER, > > > > - TPL_CALLBACK, > > > > - NULL, > > > > - NULL, > > > > - &TimeoutEvent > > > > - ); > > > > - > > > > - if (EFI_ERROR (Status)) { > > > > - goto DONE; > > > > - } > > > > - > > > > - Status =3D gBS->SetTimer ( > > > > - TimeoutEvent, > > > > - TimerRelative, > > > > - EFI_TIMER_PERIOD_MILLISECONDS (Timeout) > > > > - ); > > > > - > > > > - if (EFI_ERROR (Status)) { > > > > - goto DONE; > > > > } > > > > > > > > -RINGDOORBELL: > > > > XhcRingDoorBell (Xhc, SlotId, Dci); > > > > > > > > + TimeoutTicks =3D XhcConvertTimeToTicks ( > > > > + XHC_MICROSECOND_TO_NANOSECOND ( > > > > + Timeout * XHC_1_MILLISECOND > > > > + ) > > > > + ); > > > > + ElapsedTicks =3D 0; > > > > + CurrentTick =3D GetPerformanceCounter (); > > > > + > > > > do { > > > > Finished =3D XhcCheckUrbResult (Xhc, Urb); > > > > if (Finished) { > > > > @@ -1357,22 +1343,22 @@ RINGDOORBELL: > > } > > > > > > > > gBS->Stall (XHC_1_MICROSECOND); > > > > - } while (IndefiniteTimeout || EFI_ERROR (gBS->CheckEvent > > (TimeoutEvent))); > > > > + TicksDelta =3D XhcGetElapsedTicks (&CurrentTick); > > > > + // Ensure that ElapsedTicks is always incremented to avoid indefin= ite > > hangs > > > > + if (TicksDelta =3D=3D 0) { > > > > + TicksDelta =3D XhcConvertTimeToTicks > > (XHC_MICROSECOND_TO_NANOSECOND (XHC_1_MICROSECOND)); > > > > + } > > > > > > > > -DONE: > > > > - if (EFI_ERROR (Status)) { > > > > - Urb->Result =3D EFI_USB_ERR_NOTEXECUTE; > > > > - } else if (!Finished) { > > > > + ElapsedTicks +=3D TicksDelta; > > > > + } while (IndefiniteTimeout || ElapsedTicks < TimeoutTicks); > > > > + > > > > + if (!Finished) { > > > > Urb->Result =3D EFI_USB_ERR_TIMEOUT; > > > > Status =3D EFI_TIMEOUT; > > > > } else if (Urb->Result !=3D EFI_USB_NOERROR) { > > > > Status =3D EFI_DEVICE_ERROR; > > > > } > > > > > > > > - if (TimeoutEvent !=3D NULL) { > > > > - gBS->CloseEvent (TimeoutEvent); > > > > - } > > > > - > > > > return Status; > > > > } > > > > > > > > -- > > 2.34.1 > > > > > > > > -=3D-=3D-=3D-=3D-=3D-=3D > > Groups.io Links: You receive all messages sent to this group. > > View/Reply Online (#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 >=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 (#109030): https://edk2.groups.io/g/devel/message/109030 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-