X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=OvmfPkg%2FLibrary%2FAcpiTimerLib%2FAcpiTimerLib.c;h=938b77cdc66ca26b60ca4c59d699be4eb6b01fca;hb=61a044c6c15f5806a30ff23409ba5287d9d07163;hp=6c5cccc27305104d01508c1ac91d19ceb121c494;hpb=550486ed3be702a9bd759fedd4e23e4d89c58432;p=mirror_edk2.git diff --git a/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c b/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c index 6c5cccc273..938b77cdc6 100644 --- a/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c +++ b/OvmfPkg/Library/AcpiTimerLib/AcpiTimerLib.c @@ -1,89 +1,29 @@ /** @file ACPI Timer implements one instance of Timer Library. - Copyright (c) 2008 - 2011, Intel Corporation. All rights reserved.
+ Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
Copyright (c) 2011, Andrei Warkentin This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php - + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -**/ +**/ -#include -#include -#include -#include -#include #include +#include +#include + +#include "AcpiTimerLib.h" // -// PIIX4 Power Management Base Address +// The ACPI Time is a 24-bit counter // -UINT32 mPmba = 0x401; - -#define PCI_BAR_IO 0x1 -#define ACPI_TIMER_FREQUENCY 3579545 -#define ACPI_TIMER_COUNT_SIZE 0x01000000 -#define ACPI_TIMER_OFFSET 0x8 - -/** - The constructor function enables ACPI IO space. - - If ACPI I/O space not enabled, this function will enable it. - It will always return RETURN_SUCCESS. - - @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS. - -**/ -RETURN_STATUS -EFIAPI -AcpiTimerLibConstructor ( - VOID - ) -{ - UINT8 Device; - - Device = 1; - // Device = 7; - - if (PciRead8 (PCI_LIB_ADDRESS (0,Device,3,0x80)) & 1) { - mPmba = PciRead32 (PCI_LIB_ADDRESS (0,Device,3,0x40)); - ASSERT (mPmba & PCI_BAR_IO); - mPmba &= ~PCI_BAR_IO; - } else { - PciAndThenOr32 (PCI_LIB_ADDRESS (0,Device,3,0x40), - (UINT32) ~0xfc0, mPmba); - PciOr8 (PCI_LIB_ADDRESS (0,Device,3,0x04), 0x01); - } - - // - // ACPI Timer enable is in Bus 0, Device ?, Function 3 - // - PciOr8 (PCI_LIB_ADDRESS (0,Device,3,0x80), 0x01); - return RETURN_SUCCESS; -} - -/** - Internal function to read the current tick counter of ACPI. - - Internal function to read the current tick counter of ACPI. - - @return The tick counter read. - -**/ -STATIC -UINT32 -InternalAcpiGetTimerTick ( - VOID - ) -{ - return IoRead32 (mPmba + ACPI_TIMER_OFFSET); -} +#define ACPI_TIMER_COUNT_SIZE BIT24 /** Stalls the CPU for at least the given number of ticks. @@ -94,7 +34,6 @@ InternalAcpiGetTimerTick ( @param Delay A period of time to delay in ticks. **/ -STATIC VOID InternalAcpiDelay ( IN UINT32 Delay @@ -239,3 +178,39 @@ GetPerformanceCounterProperties ( return ACPI_TIMER_FREQUENCY; } + +/** + Converts elapsed ticks of performance counter to time in nanoseconds. + + This function converts the elapsed ticks of running performance counter to + time value in unit of nanoseconds. + + @param Ticks The number of elapsed ticks of running performance counter. + + @return The elapsed time in nanoseconds. + +**/ +UINT64 +EFIAPI +GetTimeInNanoSecond ( + IN UINT64 Ticks + ) +{ + UINT64 NanoSeconds; + UINT32 Remainder; + + // + // Ticks + // Time = --------- x 1,000,000,000 + // Frequency + // + NanoSeconds = MultU64x32 (DivU64x32Remainder (Ticks, ACPI_TIMER_FREQUENCY, &Remainder), 1000000000u); + + // + // Frequency < 0x100000000, so Remainder < 0x100000000, then (Remainder * 1,000,000,000) + // will not overflow 64-bit. + // + NanoSeconds += DivU64x32 (MultU64x32 ((UINT64) Remainder, 1000000000u), ACPI_TIMER_FREQUENCY); + + return NanoSeconds; +}