VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/PcAtChipsetPkg/Library/AcpiTimerLib/DxeStandaloneMmAcpiTimerLib.c@ 107064

Last change on this file since 107064 was 105670, checked in by vboxsync, 6 months ago

Devices/EFI/FirmwareNew: Merge edk2-stable-202405 and make it build on aarch64, bugref:4643

  • Property svn:eol-style set to native
File size: 2.2 KB
Line 
1/** @file
2 ACPI Timer implements one instance of Timer Library.
3
4 Copyright (c) 2013 - 2023, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7**/
8
9#include <PiDxe.h>
10#include <Library/TimerLib.h>
11#include <Library/BaseLib.h>
12#include <Library/HobLib.h>
13
14//
15// Cached performance counter frequency
16//
17static UINT64 mAcpiTimerLibTscFrequency = 0;
18
19extern GUID mFrequencyHobGuid;
20
21/**
22 The constructor function enables ACPI IO space.
23
24 If ACPI I/O space not enabled, this function will enable it.
25 It will always return RETURN_SUCCESS.
26
27 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
28
29**/
30RETURN_STATUS
31EFIAPI
32AcpiTimerLibConstructor (
33 VOID
34 );
35
36/**
37 Calculate TSC frequency.
38
39 The TSC counting frequency is determined by comparing how far it counts
40 during a 101.4 us period as determined by the ACPI timer.
41 The ACPI timer is used because it counts at a known frequency.
42 The TSC is sampled, followed by waiting 363 counts of the ACPI timer,
43 or 101.4 us. The TSC is then sampled again. The difference multiplied by
44 9861 is the TSC frequency. There will be a small error because of the
45 overhead of reading the ACPI timer. An attempt is made to determine and
46 compensate for this error.
47
48 @return The number of TSC counts per second.
49
50**/
51UINT64
52InternalCalculateTscFrequency (
53 VOID
54 );
55
56/**
57 Internal function to retrieves the 64-bit frequency in Hz.
58
59 Internal function to retrieves the 64-bit frequency in Hz.
60
61 @return The frequency in Hz.
62
63**/
64UINT64
65InternalGetPerformanceCounterFrequency (
66 VOID
67 )
68{
69 return mAcpiTimerLibTscFrequency;
70}
71
72/**
73 The constructor function enables ACPI IO space, and caches PerformanceCounterFrequency.
74
75 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
76
77**/
78EFI_STATUS
79CommonAcpiTimerLibConstructor (
80 VOID
81 )
82{
83 EFI_HOB_GUID_TYPE *GuidHob;
84
85 //
86 // Enable ACPI IO space.
87 //
88 AcpiTimerLibConstructor ();
89
90 //
91 // Initialize PerformanceCounterFrequency
92 //
93 GuidHob = GetFirstGuidHob (&mFrequencyHobGuid);
94 if (GuidHob != NULL) {
95 mAcpiTimerLibTscFrequency = *(UINT64 *)GET_GUID_HOB_DATA (GuidHob);
96 } else {
97 mAcpiTimerLibTscFrequency = InternalCalculateTscFrequency ();
98 }
99
100 return EFI_SUCCESS;
101}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette