public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Nate DeSimone" <nathaniel.l.desimone@intel.com>
To: devel@edk2.groups.io
Cc: Ray Ni <ray.ni@intel.com>, Michael D Kinney <michael.d.kinney@intel.com>
Subject: [edk2-devel] [PATCH v2] MdeModulePkg/Bus: Fix XhciDxe Linker Issues
Date: Mon,  4 Dec 2023 10:47:50 -0800	[thread overview]
Message-ID: <20231204184751.348-1-nathaniel.l.desimone@intel.com> (raw)

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.

Cc: 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>
---
 MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 32 ++++++++++++++---------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
index 7a2e32a9dd..f4e61d223c 100644
--- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
+++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c
@@ -2,7 +2,7 @@
   The XHCI controller driver.
 
 (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
 
 **/
@@ -86,10 +86,10 @@ EFI_USB2_HC_PROTOCOL  gXhciUsb2HcTemplate = {
   0x0
 };
 
-UINT64   mPerformanceCounterStartValue;
-UINT64   mPerformanceCounterEndValue;
-UINT64   mPerformanceCounterFrequency;
-BOOLEAN  mPerformanceCounterValuesCached = FALSE;
+static UINT64   mXhciPerformanceCounterStartValue;
+static UINT64   mXhciPerformanceCounterEndValue;
+static UINT64   mXhciPerformanceCounterFrequency;
+static BOOLEAN  mXhciPerformanceCounterValuesCached = FALSE;
 
 /**
   Retrieves the capability of root hub ports.
@@ -2318,17 +2318,17 @@ XhcConvertTimeToTicks (
   UINTN   Shift;
 
   // Cache the return values to avoid repeated calls to GetPerformanceCounterProperties ()
-  if (!mPerformanceCounterValuesCached) {
-    mPerformanceCounterFrequency = GetPerformanceCounterProperties (
-                                     &mPerformanceCounterStartValue,
-                                     &mPerformanceCounterEndValue
-                                     );
+  if (!mXhciPerformanceCounterValuesCached) {
+    mXhciPerformanceCounterFrequency = GetPerformanceCounterProperties (
+                                         &mXhciPerformanceCounterStartValue,
+                                         &mXhciPerformanceCounterEndValue
+                                         );
 
-    mPerformanceCounterValuesCached = TRUE;
+    mXhciPerformanceCounterValuesCached = TRUE;
   }
 
   // Prevent returning a tick value of 0, unless Time is already 0
-  if (0 == mPerformanceCounterFrequency) {
+  if (0 == mXhciPerformanceCounterFrequency) {
     return Time;
   }
 
@@ -2342,7 +2342,7 @@ XhcConvertTimeToTicks (
   //
   Ticks = MultU64x64 (
             DivU64x64Remainder (
-              mPerformanceCounterFrequency,
+              mXhciPerformanceCounterFrequency,
               Divisor,
               &Remainder
               ),
@@ -2384,12 +2384,12 @@ XhcGetElapsedTicks (
   //
   // Determine if the counter is counting up or down
   //
-  if (mPerformanceCounterStartValue < mPerformanceCounterEndValue) {
+  if (mXhciPerformanceCounterStartValue < mXhciPerformanceCounterEndValue) {
     //
     // Counter counts upwards, check for an overflow condition
     //
     if (*PreviousTick > CurrentTick) {
-      Delta = (mPerformanceCounterEndValue - *PreviousTick) + CurrentTick;
+      Delta = (mXhciPerformanceCounterEndValue - *PreviousTick) + CurrentTick;
     } else {
       Delta = CurrentTick - *PreviousTick;
     }
@@ -2398,7 +2398,7 @@ XhcGetElapsedTicks (
     // Counter counts downwards, check for an underflow condition
     //
     if (*PreviousTick < CurrentTick) {
-      Delta = (mPerformanceCounterStartValue - CurrentTick) + *PreviousTick;
+      Delta = (mXhciPerformanceCounterStartValue - CurrentTick) + *PreviousTick;
     } else {
       Delta = *PreviousTick - CurrentTick;
     }
-- 
2.39.2.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112049): https://edk2.groups.io/g/devel/message/112049
Mute This Topic: https://groups.io/mt/102976787/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



             reply	other threads:[~2023-12-04 18:48 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-04 18:47 Nate DeSimone [this message]
2023-12-04 18:47 ` [edk2-devel] [PATCH v2] PcAtChipsetPkg: Fix AcpiTimerLib incompatibility with XhciDxe Nate DeSimone
2023-12-04 19:59   ` Pedro Falcato
2023-12-04 22:13     ` Nate DeSimone
2023-12-05  8:18       ` Ni, Ray
     [not found] ` <179DB5683F38928F.24600@groups.io>
2023-12-06 22:50   ` Nate DeSimone

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231204184751.348-1-nathaniel.l.desimone@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox