]> git.proxmox.com Git - mirror_edk2.git/blob - PcAtChipsetPkg/Library/AcpiTimerLib/PeiAcpiTimerLib.c
PcAtChipsetPkg: Apply uncrustify changes
[mirror_edk2.git] / PcAtChipsetPkg / Library / AcpiTimerLib / PeiAcpiTimerLib.c
1 /** @file
2 ACPI Timer implements one instance of Timer Library.
3
4 Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <PiPei.h>
10 #include <Library/TimerLib.h>
11 #include <Library/BaseLib.h>
12 #include <Library/HobLib.h>
13 #include <Library/DebugLib.h>
14
15 extern GUID mFrequencyHobGuid;
16
17 /**
18 Calculate TSC frequency.
19
20 The TSC counting frequency is determined by comparing how far it counts
21 during a 101.4 us period as determined by the ACPI timer.
22 The ACPI timer is used because it counts at a known frequency.
23 The TSC is sampled, followed by waiting 363 counts of the ACPI timer,
24 or 101.4 us. The TSC is then sampled again. The difference multiplied by
25 9861 is the TSC frequency. There will be a small error because of the
26 overhead of reading the ACPI timer. An attempt is made to determine and
27 compensate for this error.
28
29 @return The number of TSC counts per second.
30
31 **/
32 UINT64
33 InternalCalculateTscFrequency (
34 VOID
35 );
36
37 /**
38 Internal function to retrieves the 64-bit frequency in Hz.
39
40 Internal function to retrieves the 64-bit frequency in Hz.
41
42 @return The frequency in Hz.
43
44 **/
45 UINT64
46 InternalGetPerformanceCounterFrequency (
47 VOID
48 )
49 {
50 UINT64 *PerformanceCounterFrequency;
51 EFI_HOB_GUID_TYPE *GuidHob;
52
53 PerformanceCounterFrequency = NULL;
54 GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);
55 if (GuidHob == NULL) {
56 PerformanceCounterFrequency = (UINT64 *)BuildGuidHob (&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency));
57 ASSERT (PerformanceCounterFrequency != NULL);
58 *PerformanceCounterFrequency = InternalCalculateTscFrequency ();
59 } else {
60 PerformanceCounterFrequency = (UINT64 *)GET_GUID_HOB_DATA (GuidHob);
61 }
62
63 return *PerformanceCounterFrequency;
64 }