MdeModulePkg/XhciDxe: Use Performance Timer for XHCI Timeouts

REF:https://bugzilla.tianocore.org/show_bug.cgi?id=2948

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 <hao.a.wu@intel.com>
Cc: Ray Ni <ray.ni@intel.com>
Signed-off-by: Patrick Henz <patrick.henz@hpe.com>
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
This commit is contained in:
Henz, Patrick
2023-09-13 02:05:57 +08:00
committed by mergify[bot]
parent 8b2e6b90b8
commit 43dcf453fc
5 changed files with 204 additions and 87 deletions

View File

@@ -2,6 +2,7 @@
Provides some data structure definitions used by the XHCI host controller driver.
(C) Copyright 2023 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2011 - 2017, Intel Corporation. All rights reserved.<BR>
Copyright (c) Microsoft Corporation.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -26,6 +27,7 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include <Library/UefiLib.h>
#include <Library/DebugLib.h>
#include <Library/ReportStatusCodeLib.h>
#include <Library/TimerLib.h>
#include <IndustryStandard/Pci.h>
@@ -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