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; }