]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / Library / AcpiTimerLib / DxeAcpiTimerLib.c
CommitLineData
170ef2d9
GS
1/** @file\r
2 Provide constructor and GetTick for Dxe instance of ACPI Timer Library\r
3\r
4 Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>\r
5\r
b26f0cf9 6 SPDX-License-Identifier: BSD-2-Clause-Patent\r
170ef2d9
GS
7**/\r
8\r
9#include <Library/DebugLib.h>\r
10#include <Library/IoLib.h>\r
11#include <Library/PcdLib.h>\r
12#include <Library/PciLib.h>\r
13#include <OvmfPlatforms.h>\r
14\r
170ef2d9
GS
15//\r
16// Cached ACPI Timer IO Address\r
17//\r
ac0a286f 18STATIC UINT32 mAcpiTimerIoAddr;\r
170ef2d9
GS
19\r
20/**\r
21 The constructor function caches the ACPI tick counter address\r
22\r
23 At the time this constructor runs (DXE_CORE or later), ACPI IO space\r
24 has already been enabled by either PlatformPei or by the "Base"\r
25 instance of this library.\r
26 In order to avoid querying the underlying platform type during each\r
27 tick counter read operation, we cache the counter address during\r
28 initialization of this instance of the Timer Library.\r
29\r
30 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r
31\r
32**/\r
33RETURN_STATUS\r
34EFIAPI\r
35AcpiTimerLibConstructor (\r
36 VOID\r
37 )\r
38{\r
ac0a286f
MK
39 UINT16 HostBridgeDevId;\r
40 UINTN Pmba;\r
170ef2d9
GS
41\r
42 //\r
43 // Query Host Bridge DID to determine platform type\r
44 //\r
45 HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId);\r
46 switch (HostBridgeDevId) {\r
47 case INTEL_82441_DEVICE_ID:\r
da372167 48 Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);\r
170ef2d9
GS
49 break;\r
50 case INTEL_Q35_MCH_DEVICE_ID:\r
bc9d05d6 51 Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);\r
170ef2d9
GS
52 break;\r
53 default:\r
ac0a286f
MK
54 DEBUG ((\r
55 DEBUG_ERROR,\r
56 "%a: Unknown Host Bridge Device ID: 0x%04x\n",\r
57 __FUNCTION__,\r
58 HostBridgeDevId\r
59 ));\r
170ef2d9
GS
60 ASSERT (FALSE);\r
61 return RETURN_UNSUPPORTED;\r
62 }\r
63\r
64 mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET;\r
65\r
66 return RETURN_SUCCESS;\r
67}\r
68\r
69/**\r
70 Internal function to read the current tick counter of ACPI.\r
71\r
72 Read the current ACPI tick counter using the counter address cached\r
73 by this instance's constructor.\r
74\r
75 @return The tick counter read.\r
76\r
77**/\r
78UINT32\r
79InternalAcpiGetTimerTick (\r
80 VOID\r
81 )\r
82{\r
83 //\r
84 // Return the current ACPI timer value.\r
85 //\r
86 return IoRead32 (mAcpiTimerIoAddr);\r
87}\r