From fbbf4206c13e95d54ace7646d508523adae4b126 Mon Sep 17 00:00:00 2001 From: "Henz, Patrick" Date: Tue, 31 Oct 2023 11:51:14 -0500 Subject: MdeModulePkg/XhciDxe: Non-zero start/stop values in XhcGetElapsedTicks REF:https://bugzilla.tianocore.org/show_bug.cgi?id=4578 The implementation of XhcGetElapsedTicks did not account for non-zero start and stop values for the performance counter timer, potentially resulting in an incorrect elapsed tick count getting returned to the caller. Account for non-zero start and stop values when calculating the elapsed tick count. Cc: Hao A Wu Cc: Ray Ni Signed-off-by: Patrick Henz Reviewed-by: Laszlo Ersek Acked-by: Hao A Wu Message-ID: Resolve rebase conflict from commit ff4c49a5ee38 ("MdeModulePkg/Bus: Fix XhciDxe Linker Issues", 2023-12-06): rename "mPerformanceCounter*" to "mXhciPerformanceCounter*". Signed-off-by: Laszlo Ersek --- MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'MdeModulePkg') diff --git a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c index a9d7e3616e..c830db66a1 100644 --- a/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c +++ b/MdeModulePkg/Bus/Pci/XhciDxe/Xhci.c @@ -2397,7 +2397,7 @@ XhcGetElapsedTicks ( // Counter counts upwards, check for an overflow condition // if (*PreviousTick > CurrentTick) { - Delta = (mXhciPerformanceCounterEndValue - *PreviousTick) + CurrentTick; + Delta = (CurrentTick - mXhciPerformanceCounterStartValue) + (mXhciPerformanceCounterEndValue - *PreviousTick); } else { Delta = CurrentTick - *PreviousTick; } @@ -2406,7 +2406,7 @@ XhcGetElapsedTicks ( // Counter counts downwards, check for an underflow condition // if (*PreviousTick < CurrentTick) { - Delta = (mXhciPerformanceCounterStartValue - CurrentTick) + *PreviousTick; + Delta = (mXhciPerformanceCounterStartValue - CurrentTick) + (*PreviousTick - mXhciPerformanceCounterEndValue); } else { Delta = *PreviousTick - CurrentTick; } -- cgit