1 | /** @file
|
---|
2 | ACPI Timer implements one instance of Timer Library.
|
---|
3 |
|
---|
4 | Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
|
---|
5 | This program and the accompanying materials
|
---|
6 | are licensed and made available under the terms and conditions of the BSD License
|
---|
7 | which accompanies this distribution. The full text of the license may be found at
|
---|
8 | http://opensource.org/licenses/bsd-license.php
|
---|
9 |
|
---|
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
|
---|
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
---|
12 |
|
---|
13 | **/
|
---|
14 |
|
---|
15 | #include <PiPei.h>
|
---|
16 | #include <Library/TimerLib.h>
|
---|
17 | #include <Library/BaseLib.h>
|
---|
18 | #include <Library/HobLib.h>
|
---|
19 | #include <Library/DebugLib.h>
|
---|
20 |
|
---|
21 | extern GUID mFrequencyHobGuid;
|
---|
22 |
|
---|
23 | /**
|
---|
24 | Calculate TSC frequency.
|
---|
25 |
|
---|
26 | The TSC counting frequency is determined by comparing how far it counts
|
---|
27 | during a 101.4 us period as determined by the ACPI timer.
|
---|
28 | The ACPI timer is used because it counts at a known frequency.
|
---|
29 | The TSC is sampled, followed by waiting 363 counts of the ACPI timer,
|
---|
30 | or 101.4 us. The TSC is then sampled again. The difference multiplied by
|
---|
31 | 9861 is the TSC frequency. There will be a small error because of the
|
---|
32 | overhead of reading the ACPI timer. An attempt is made to determine and
|
---|
33 | compensate for this error.
|
---|
34 |
|
---|
35 | @return The number of TSC counts per second.
|
---|
36 |
|
---|
37 | **/
|
---|
38 | UINT64
|
---|
39 | InternalCalculateTscFrequency (
|
---|
40 | VOID
|
---|
41 | );
|
---|
42 |
|
---|
43 | /**
|
---|
44 | Internal function to retrieves the 64-bit frequency in Hz.
|
---|
45 |
|
---|
46 | Internal function to retrieves the 64-bit frequency in Hz.
|
---|
47 |
|
---|
48 | @return The frequency in Hz.
|
---|
49 |
|
---|
50 | **/
|
---|
51 | UINT64
|
---|
52 | InternalGetPerformanceCounterFrequency (
|
---|
53 | VOID
|
---|
54 | )
|
---|
55 | {
|
---|
56 | UINT64 *PerformanceCounterFrequency;
|
---|
57 | EFI_HOB_GUID_TYPE *GuidHob;
|
---|
58 |
|
---|
59 | PerformanceCounterFrequency = NULL;
|
---|
60 | GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);
|
---|
61 | if (GuidHob == NULL) {
|
---|
62 | PerformanceCounterFrequency = (UINT64*)BuildGuidHob(&mFrequencyHobGuid, sizeof (*PerformanceCounterFrequency));
|
---|
63 | ASSERT (PerformanceCounterFrequency != NULL);
|
---|
64 | *PerformanceCounterFrequency = InternalCalculateTscFrequency ();
|
---|
65 | } else {
|
---|
66 | PerformanceCounterFrequency = (UINT64*)GET_GUID_HOB_DATA (GuidHob);
|
---|
67 | }
|
---|
68 |
|
---|
69 | return *PerformanceCounterFrequency;
|
---|
70 | }
|
---|