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 E4D81AC16CF for ; Wed, 6 Sep 2023 20:37:14 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=HJ94EUztlvZZyZL9kuOV3/GrNP2EEoBh8tBeUyGxosg=; 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=1694032633; v=1; b=NoKvEgx4M6ofBjoxjzNuw3tOdYUdlyotEIqn9jUpfJZa081oqK87f6hbnVomcptEnXuRs+lS +FQc1c8OVua5tH7FclrVp+fE7FSgesLsb8goQdPtKHj2oyu5F29Xzoa0Hk4G1H61kkY9NNCHLJ5 QPF8JhUffCBtlysGJIJKp2OE= X-Received: by 127.0.0.2 with SMTP id nADmYY7687511xJEbeWH62wn; Wed, 06 Sep 2023 13:37:13 -0700 X-Received: from mx0b-002e3701.pphosted.com (mx0b-002e3701.pphosted.com [148.163.143.35]) by mx.groups.io with SMTP id smtpd.web11.844.1694032631682099914 for ; Wed, 06 Sep 2023 13:37:12 -0700 X-Received: from pps.filterd (m0150245.ppops.net [127.0.0.1]) by mx0b-002e3701.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 386H2Al2014274 for ; Wed, 6 Sep 2023 20:37:11 GMT X-Received: from p1lg14879.it.hpe.com ([16.230.97.200]) by mx0b-002e3701.pphosted.com (PPS) with ESMTPS id 3sxqtmvnh4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 06 Sep 2023 20:37:10 +0000 X-Received: from p1wg14923.americas.hpqcorp.net (unknown [10.119.18.111]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by p1lg14879.it.hpe.com (Postfix) with ESMTPS id 33450131A4 for ; Wed, 6 Sep 2023 20:37:05 +0000 (UTC) X-Received: from p1wg14927.americas.hpqcorp.net (10.119.18.117) by p1wg14923.americas.hpqcorp.net (10.119.18.111) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Wed, 6 Sep 2023 08:36:39 -1200 X-Received: from p1wg14924.americas.hpqcorp.net (10.119.18.113) by p1wg14927.americas.hpqcorp.net (10.119.18.117) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Wed, 6 Sep 2023 08:36:39 -1200 X-Received: from p1wg14921.americas.hpqcorp.net (16.230.19.124) by p1wg14924.americas.hpqcorp.net (10.119.18.113) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42 via Frontend Transport; Wed, 6 Sep 2023 08:36:39 -1200 X-Received: from NAM10-BN7-obe.outbound.protection.outlook.com (192.58.206.35) by edge.it.hpe.com (16.230.19.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.42; Wed, 6 Sep 2023 08:36:38 -1200 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RK05XlBwQ3oxVLlWb1pvN37LW4/wNoTqDc0F8ibRIppx2+BXPbkXpH1zoecClxOzGBFsmaLS773FoSUA/NbX/J6xAIBt5oRcDfyDf4KTO6yJ6emdoN73UFFP4LUE412rtvcCGm/UziSG/zk0Jg/ZbIPU1JAddqtyGEpzykz12Y8m3KAhHj409nK351ZtUTGXY5jtAgkQ8GoearWvjuRELKmGBnr2BGBeL9HkvaZZY0ZF1Gl/793Dq6B3u9bAu2H9+S1/8OTSyC5/ahSa1JJip0X9gx5iqaP7MUOt0X7IIXEMfKX75qCgheYraLZVoVdb7nYMf+cHUqq37ECRefu1tA== 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=9ZyZsPZ2m3bcaUBwvrw9Z1oKgWCEF4paV0psEKOOwJY=; b=ka8L3hIRsLJLrUYwqSNraA4SegxYD/BRFPOgWZ5F2UeTACW/ikH6TJJszsjcKsOOOawxTLMeUOu0aoUpGz/61GSQYCGnmPyC8c54d25LeT5d8euwAj70TpKx/mspNAe7qxfXQHYEOueI7vdfBePUm214Z8QracOhzgyGhnpCIKPrpmSHa6htlBcdfxBU8AyXSjExIVnEVi+1pbV5rxougVEBe4CzcrcKYRHurXworUhse4Ya1lKt6L8KDm/KPyCsT7MdbyhmrSOXzMJkEsY+IktNxx/prz+f4tG9eVIcHRsN7Robi//bVQA18E2Pze9kdpgoFA3ZkDS0vnYO9PsHaw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=hpe.com; dmarc=pass action=none header.from=hpe.com; dkim=pass header.d=hpe.com; arc=none X-Received: from PH0PR84MB1478.NAMPRD84.PROD.OUTLOOK.COM (2603:10b6:510:171::21) by PH0PR84MB1382.NAMPRD84.PROD.OUTLOOK.COM (2603:10b6:510:171::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.34; Wed, 6 Sep 2023 20:36:36 +0000 X-Received: from PH0PR84MB1478.NAMPRD84.PROD.OUTLOOK.COM ([fe80::55a0:89f4:ef4:bcba]) by PH0PR84MB1478.NAMPRD84.PROD.OUTLOOK.COM ([fe80::55a0:89f4:ef4:bcba%4]) with mapi id 15.20.6745.034; Wed, 6 Sep 2023 20:36:36 +0000 From: "Henz, Patrick" To: "devel@edk2.groups.io" 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: AQHZzseBJIO8HXAamkWgXd40zbxjr7AOZHvg Date: Wed, 6 Sep 2023 20:36:35 +0000 Message-ID: References: <177B4AD1F8C3A6A2.8497@groups.io> In-Reply-To: <177B4AD1F8C3A6A2.8497@groups.io> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PH0PR84MB1478:EE_|PH0PR84MB1382:EE_ x-ms-office365-filtering-correlation-id: 6c81ca3a-6a6d-44f4-d76e-08dbaf18f6e9 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: SZ16/9N95IM5+ZMDrnvcr7s6SslZBD+eWcU+WTfY0sIj+edxtuYVYSBGshpNgsjzmxlmyZkkLCOYQhJI1izm4qSt/tJSAoxun/wqYnlw5pyP98+x0BNYj6dohGUQh9B3CKIRwyIjHcLizt1W6Upvsk4vgkgAr4EZac6db/foitDIfWW9G5IyYwJG66R1iZzG6cPx2H76JV9RA8ctO+s8WqSjaxVsg/qiPNZViSrB3U74c27jTx0IvRUHwDJUON8ulPh4zUc6/yT9eRZHZmc6JV1H6id//C1rhLlJRVeLpY9e2DyKtu2Xmeq8dJO8EOgRZRywtdbqIdRS4CZJnGRlAXz77w+ox0pW+hJJaVVSlTS9GeVlSfCp1LDF4ySCSbQ2iZaP0eGWXsdShVA4kz/XH3tWCvR/D9GZauqNyCXJYNo9ZfQnke27TZokZlfhiOMiLctqhXOgNFqZP+ZehzxyiBGexMVQcOWZAcL6a3ofx445pIdvqQDtPj0zSBz8mRJbjYT6zU7NaBKxq39Qgdw60GbrvAD/af6TOu90BTXF2WJlwD9Mttdcdk8L5I02sbkIuxi9Z+qEe5pxu+jI6OCk4qgnYyxYCSKe1lgVi9z6MyM= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?xdd9+IWmtUILSx/jje71SE+ZjtHSuH6y+bydhV0STntIfO6dQXfYMRDZRyy7?= =?us-ascii?Q?yAvfwNM0uk9BJU+RYpfl5D4n4OZMg0w6aNqq3792pkvMGQsorM73fN3LjCax?= =?us-ascii?Q?zfJQKGwR98dYorrqhC/ulU+Cm8jDs3CANMyouHykiPafvYRcVFV8wAb4lTHd?= =?us-ascii?Q?+0n1m24mvTakvXpc5BvBfeq+tChaFrVTrEHi752IhPamcG7GIdHGNki8GZ1c?= =?us-ascii?Q?Y8Vnuxs2ULY1dHdNtsJMxVDXg1lkHxH5noxgJz+5nCT8oOwtFlbyC+2Ng+YC?= =?us-ascii?Q?yErdbqQpQFyVu1q55iZvi4ds4Dqra27JX+ScadcSpBVUsbK5f0vLoVNL071E?= =?us-ascii?Q?0OU98z67Fy7V0k+Va5O1FFEIyP11k3sB1uC52ToVySHJQflDs06+Qo4MNRSM?= =?us-ascii?Q?5LzYA5is6AkWMTvddat9VdP1AYtuEEWabN+5rmMhYYR94mdS6VhGU03pkJSn?= =?us-ascii?Q?kJlpQXFlPXrgelpwprTFSE17Nbomd56CMw6jltMkdGEHhftbXULLassYUYwg?= =?us-ascii?Q?POC+BF8IZ84xqoM7Jg9yWcdn6ZkT9bsxsCxQBSY2j1gUafyA5CXVqBKpSmHS?= =?us-ascii?Q?+r7nqoXVKLdfmfjGGcO4EBJ8Dxl4CnYcWDuxsvBroeDuhzUB89O4vPqPos27?= =?us-ascii?Q?pYgIpfw6SdTlFuHMmkGwlll7kTU+cXo5IHAlrsGybRjrQS68+CgYarrcYK8s?= =?us-ascii?Q?RuOnDyVytnBp42sOnXCsnpzBQduz2m+TtZNJgzZA8rsc/0L2wQe/NLl3D733?= =?us-ascii?Q?kdXD8koGMbIr4I95pYWyFNhpO4LUzvDf8URUxUB65hPDNICxUmxDhLue1EmK?= =?us-ascii?Q?MtuxbRNn/KuQcNrmEv+YqGCi7GE7Mfz5X2A46/PfLSDE9O8cDEegC9O+Oud/?= =?us-ascii?Q?j/Dl1Bd5D9iSF6thoDNS6hDZhHVlo9qherWL4rHZMTzNzJzdGHtqdyaqacSY?= =?us-ascii?Q?h3QvXw3lxJH8DPxv2cRlOs8YFmprce7pl7nch1zOTGdv4IuBLWzK8d7A8LLa?= =?us-ascii?Q?zPjeMFJbimS4RIy668dV4G0bCizCXCZaRPgnsWpgWkajNnxgFKElB3LmzlVw?= =?us-ascii?Q?e2lorvOKAyr62TVCekBHw46o/MGTJfD5kWgJyzaMGVyCe0agidIjne8OLVEy?= =?us-ascii?Q?8nU92X6gIXjlYGL1heUX056yrbj5wF1XQg3129rBBOYP1iSJiD8f2/et5yHV?= =?us-ascii?Q?U/gHQfDWwRPpO2aXyl5+jmH4kjYRdwtEi9U8+EcdxNFqoP8mLVhh3MGKAUrH?= =?us-ascii?Q?+ARrotL6kRkW8iVY/Yl7qbA6+KpBJaqPciJtI08Uuc1A1ID/bzj12Y4PQkqs?= =?us-ascii?Q?fIQ412PA4jFV43eyeW9dVLND8nBE6A4G/pwE/Iv+JL+o2JYBtOTXOQlFGTkk?= =?us-ascii?Q?L7zpwssQchqCrALsLhuhV9+crimEP8jUvmwM/KYgxdsGoKn6xu1QY24WnDDB?= =?us-ascii?Q?yXsNfmnk5NZ3rK71qdl7fyrDG0I490pErjkEJbWXcM1qmjIm7qGplkTEnofj?= =?us-ascii?Q?klz118jerLnyh1+hLQGGNmbJr40izH9kXPKt/7CepEwfa5HC4pT+nPNsUVV0?= =?us-ascii?Q?M6MWFnbSc2VqIEvrf+lPp46iGMkizKVjihtNoAKV?= X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: PH0PR84MB1478.NAMPRD84.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: 6c81ca3a-6a6d-44f4-d76e-08dbaf18f6e9 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Sep 2023 20:36:35.9209 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 105b2061-b669-4b31-92ac-24d304d195dc X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: BSIxemR7YlW2WfyilR1cS6IbJo7zw/xwl5A/4Cm+6/37wu7n85dSW4u6yceIQeP/jOlXRvq6W2c76n4MUqhp6A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH0PR84MB1382 X-OriginatorOrg: hpe.com X-Proofpoint-ORIG-GUID: nrMHa--MH72CdDCEVs1-qkWnl6GTAj4- X-Proofpoint-GUID: nrMHa--MH72CdDCEVs1-qkWnl6GTAj4- X-Proofpoint-UnRewURL: 4 URL's were un-rewritten MIME-Version: 1.0 X-HPE-SCL: -1 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,patrick.henz@hpe.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: wcR8xwL9bep1guH1Kr7GYipVx7686176AA= 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=NoKvEgx4; arc=reject ("signature check failed: fail, {[1] = sig:microsoft.com:reject}"); dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=hpe.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io I sent this patch out a few weeks ago now but haven't seen a reply, just ch= ecking in to make sure it didn't get missed. Thanks, Patrick Henz -----Original Message----- From: devel@edk2.groups.io On Behalf Of Henz, Patric= k 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 Time= r for XHCI Timeouts 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 ExitBoot= Services 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 ti= meouts, avoiding the potential hang. 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(-) diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/Xhc= iDxe/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=20 + (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/Xhc= iDxe/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 controlle= r driver. =20 +(C) Copyright 2023 Hewlett Packard Enterprise Development LP
Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.
Co= pyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent @@ -26,6 +27,7 @@ SPDX-Licens= e-Identifier: BSD-2-Clause-Patent #include #include <= Library/DebugLib.h> #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=20 +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/Pc= i/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.
= # # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -54,6 +55,7 @@ BaseMemoryLib DebugLib ReportStatusCodeLib + TimerLib =20 [Guids] gEfiEventExitBootServicesGuid ## SOMETIMES_CONSUMES ## E= vent 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 millise= cond, 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 cont= roller. - @retval EFI_TIMEOUT The time out occurred. - @retval EFI_OUT_OF_RESOURCES Memory for the timer event could not be a= llocated. + @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 *=20 + XHC_1_MILLISECOND); ElapsedTime =3D 0; CurrentTick =3D=20 + 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 h= angs + 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/Pc= i/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.
Co= pyright (c) Microsoft Corporation.
Copyright (C) 2022 Advanced Micro D= evices, Inc. All rights reserved.
@@ -1276,15 +1277,14 @@ EXIT: /** Execute the transfer by polling the URB. This is a synchronous operation= . =20 - @param Xhc The XHCI Instance. - @param CmdTransfer The executed URB is for cmd transfer or n= ot. - @param Urb The URB to execute. - @param Timeout The time to wait before abort, in millise= cond. + @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 millisecond. =20 - @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. - @retval EFI_OUT_OF_RESOURCES Memory for the timer event could not be a= llocated. + @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 *=20 + XHC_1_MILLISECOND); ElapsedTime =3D 0; CurrentTick =3D=20 + 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 h= angs + 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 -=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 (#108340): https://edk2.groups.io/g/devel/message/108340 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-