MdeModulePkg/Bus: Fix XhciDxe Linker Issues

The DXE & MM standalone variant of AcpiTimerLib defines a global
named mPerformanceCounterFrequency. A global with an identical
name is also present in MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c

Since XhciDxe has a dependency on TimerLib, this can cause link
errors due to the same symbol being defined twice if the platform
DSC chooses to use AcpiTimerLib as the TimerLib implementation for
any given platform.

To resolve this, I noted that some of the globals in Xhci.c are not
used outside of the Xhci.c compilation unit:

- mPerformanceCounterStartValue
- mPerformanceCounterEndValue
- mPerformanceCounterFrequency
- mPerformanceCounterValuesCached

I have changed the definition for all of these to static and added
an Xhci prefix. Since they are not used outside of the Xhci.c
compilation unit, there is no reason to have them exported as
globals.

Reviewed-by: Ray Ni <ray.ni@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
This commit is contained in:
Nate DeSimone 2023-11-30 17:47:00 -08:00 committed by mergify[bot]
parent df2ec2aab0
commit ff4c49a5ee

View File

@ -2,7 +2,7 @@
The XHCI controller driver. The XHCI controller driver.
(C) Copyright 2023 Hewlett Packard Enterprise Development LP<BR> (C) Copyright 2023 Hewlett Packard Enterprise Development LP<BR>
Copyright (c) 2011 - 2022, Intel Corporation. All rights reserved.<BR> Copyright (c) 2011 - 2023, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent SPDX-License-Identifier: BSD-2-Clause-Patent
**/ **/
@ -86,10 +86,10 @@ EFI_USB2_HC_PROTOCOL gXhciUsb2HcTemplate = {
0x0 0x0
}; };
UINT64 mPerformanceCounterStartValue; static UINT64 mXhciPerformanceCounterStartValue;
UINT64 mPerformanceCounterEndValue; static UINT64 mXhciPerformanceCounterEndValue;
UINT64 mPerformanceCounterFrequency; static UINT64 mXhciPerformanceCounterFrequency;
BOOLEAN mPerformanceCounterValuesCached = FALSE; static BOOLEAN mXhciPerformanceCounterValuesCached = FALSE;
/** /**
Retrieves the capability of root hub ports. Retrieves the capability of root hub ports.
@ -2318,17 +2318,17 @@ XhcConvertTimeToTicks (
UINTN Shift; UINTN Shift;
// Cache the return values to avoid repeated calls to GetPerformanceCounterProperties () // Cache the return values to avoid repeated calls to GetPerformanceCounterProperties ()
if (!mPerformanceCounterValuesCached) { if (!mXhciPerformanceCounterValuesCached) {
mPerformanceCounterFrequency = GetPerformanceCounterProperties ( mXhciPerformanceCounterFrequency = GetPerformanceCounterProperties (
&mPerformanceCounterStartValue, &mXhciPerformanceCounterStartValue,
&mPerformanceCounterEndValue &mXhciPerformanceCounterEndValue
); );
mPerformanceCounterValuesCached = TRUE; mXhciPerformanceCounterValuesCached = TRUE;
} }
// Prevent returning a tick value of 0, unless Time is already 0 // Prevent returning a tick value of 0, unless Time is already 0
if (0 == mPerformanceCounterFrequency) { if (0 == mXhciPerformanceCounterFrequency) {
return Time; return Time;
} }
@ -2342,7 +2342,7 @@ XhcConvertTimeToTicks (
// //
Ticks = MultU64x64 ( Ticks = MultU64x64 (
DivU64x64Remainder ( DivU64x64Remainder (
mPerformanceCounterFrequency, mXhciPerformanceCounterFrequency,
Divisor, Divisor,
&Remainder &Remainder
), ),
@ -2384,12 +2384,12 @@ XhcGetElapsedTicks (
// //
// Determine if the counter is counting up or down // Determine if the counter is counting up or down
// //
if (mPerformanceCounterStartValue < mPerformanceCounterEndValue) { if (mXhciPerformanceCounterStartValue < mXhciPerformanceCounterEndValue) {
// //
// Counter counts upwards, check for an overflow condition // Counter counts upwards, check for an overflow condition
// //
if (*PreviousTick > CurrentTick) { if (*PreviousTick > CurrentTick) {
Delta = (mPerformanceCounterEndValue - *PreviousTick) + CurrentTick; Delta = (mXhciPerformanceCounterEndValue - *PreviousTick) + CurrentTick;
} else { } else {
Delta = CurrentTick - *PreviousTick; Delta = CurrentTick - *PreviousTick;
} }
@ -2398,7 +2398,7 @@ XhcGetElapsedTicks (
// Counter counts downwards, check for an underflow condition // Counter counts downwards, check for an underflow condition
// //
if (*PreviousTick < CurrentTick) { if (*PreviousTick < CurrentTick) {
Delta = (mPerformanceCounterStartValue - CurrentTick) + *PreviousTick; Delta = (mXhciPerformanceCounterStartValue - CurrentTick) + *PreviousTick;
} else { } else {
Delta = *PreviousTick - CurrentTick; Delta = *PreviousTick - CurrentTick;
} }