BaseAcpiTimerLib.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /** @file
  2. ACPI Timer implements one instance of Timer Library.
  3. Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Base.h>
  7. #include <Library/TimerLib.h>
  8. #include <Library/BaseLib.h>
  9. /**
  10. Calculate TSC frequency.
  11. The TSC counting frequency is determined by comparing how far it counts
  12. during a 101.4 us period as determined by the ACPI timer.
  13. The ACPI timer is used because it counts at a known frequency.
  14. The TSC is sampled, followed by waiting 363 counts of the ACPI timer,
  15. or 101.4 us. The TSC is then sampled again. The difference multiplied by
  16. 9861 is the TSC frequency. There will be a small error because of the
  17. overhead of reading the ACPI timer. An attempt is made to determine and
  18. compensate for this error.
  19. @return The number of TSC counts per second.
  20. **/
  21. UINT64
  22. InternalCalculateTscFrequency (
  23. VOID
  24. );
  25. /**
  26. Internal function to retrieves the 64-bit frequency in Hz.
  27. Internal function to retrieves the 64-bit frequency in Hz.
  28. @return The frequency in Hz.
  29. **/
  30. UINT64
  31. InternalGetPerformanceCounterFrequency (
  32. VOID
  33. )
  34. {
  35. return InternalCalculateTscFrequency ();
  36. }