]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / Library / AcpiTimerLib / BaseRomAcpiTimerLib.c
CommitLineData
170ef2d9
GS
1/** @file\r
2 Provide constructor and GetTick for BaseRom instance of ACPI Timer Library\r
3\r
4 Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.\r
5 Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>\r
6\r
b26f0cf9 7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
170ef2d9
GS
8**/\r
9\r
10#include <Library/DebugLib.h>\r
11#include <Library/IoLib.h>\r
12#include <Library/PciLib.h>\r
170ef2d9
GS
13#include <OvmfPlatforms.h>\r
14\r
170ef2d9
GS
15/**\r
16 The constructor function enables ACPI IO space.\r
17\r
18 If ACPI I/O space not enabled, this function will enable it.\r
19 It will always return RETURN_SUCCESS.\r
20\r
21 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r
22\r
23**/\r
24RETURN_STATUS\r
25EFIAPI\r
26AcpiTimerLibConstructor (\r
27 VOID\r
28 )\r
29{\r
ac0a286f
MK
30 UINT16 HostBridgeDevId;\r
31 UINTN Pmba;\r
32 UINT32 PmbaAndVal;\r
33 UINT32 PmbaOrVal;\r
34 UINTN AcpiCtlReg;\r
35 UINT8 AcpiEnBit;\r
170ef2d9
GS
36\r
37 //\r
38 // Query Host Bridge DID to determine platform type\r
39 //\r
40 HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);\r
41 switch (HostBridgeDevId) {\r
42 case INTEL_82441_DEVICE_ID:\r
da372167 43 Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);\r
1466b76f
LE
44 PmbaAndVal = ~(UINT32)PIIX4_PMBA_MASK;\r
45 PmbaOrVal = PIIX4_PMBA_VALUE;\r
da372167
LE
46 AcpiCtlReg = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMREGMISC);\r
47 AcpiEnBit = PIIX4_PMREGMISC_PMIOSE;\r
170ef2d9
GS
48 break;\r
49 case INTEL_Q35_MCH_DEVICE_ID:\r
bc9d05d6 50 Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);\r
1466b76f
LE
51 PmbaAndVal = ~(UINT32)ICH9_PMBASE_MASK;\r
52 PmbaOrVal = ICH9_PMBASE_VALUE;\r
bc9d05d6
LE
53 AcpiCtlReg = POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL);\r
54 AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN;\r
170ef2d9
GS
55 break;\r
56 default:\r
ac0a286f
MK
57 DEBUG ((\r
58 DEBUG_ERROR,\r
59 "%a: Unknown Host Bridge Device ID: 0x%04x\n",\r
60 __FUNCTION__,\r
61 HostBridgeDevId\r
62 ));\r
170ef2d9
GS
63 ASSERT (FALSE);\r
64 return RETURN_UNSUPPORTED;\r
65 }\r
66\r
67 //\r
68 // Check to see if the Power Management Base Address is already enabled\r
69 //\r
e2ab3f81 70 if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) {\r
170ef2d9
GS
71 //\r
72 // If the Power Management Base Address is not programmed,\r
b2f4da39 73 // then program it now.\r
170ef2d9 74 //\r
1466b76f 75 PciAndThenOr32 (Pmba, PmbaAndVal, PmbaOrVal);\r
170ef2d9
GS
76\r
77 //\r
e2ab3f81 78 // Enable PMBA I/O port decodes\r
170ef2d9 79 //\r
e2ab3f81 80 PciOr8 (AcpiCtlReg, AcpiEnBit);\r
170ef2d9
GS
81 }\r
82\r
83 return RETURN_SUCCESS;\r
84}\r
85\r
86/**\r
87 Internal function to read the current tick counter of ACPI.\r
88\r
89 Dynamically compute the address of the ACPI tick counter based on the\r
90 properties of the underlying platform, to avoid relying on global variables.\r
91\r
92 @return The tick counter read.\r
93\r
94**/\r
95UINT32\r
96InternalAcpiGetTimerTick (\r
97 VOID\r
98 )\r
99{\r
ac0a286f
MK
100 UINT16 HostBridgeDevId;\r
101 UINTN Pmba;\r
170ef2d9
GS
102\r
103 //\r
104 // Query Host Bridge DID to determine platform type\r
105 //\r
106 HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);\r
107 switch (HostBridgeDevId) {\r
108 case INTEL_82441_DEVICE_ID:\r
da372167 109 Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);\r
170ef2d9
GS
110 break;\r
111 case INTEL_Q35_MCH_DEVICE_ID:\r
bc9d05d6 112 Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);\r
170ef2d9
GS
113 break;\r
114 default:\r
ac0a286f
MK
115 DEBUG ((\r
116 DEBUG_ERROR,\r
117 "%a: Unknown Host Bridge Device ID: 0x%04x\n",\r
118 __FUNCTION__,\r
119 HostBridgeDevId\r
120 ));\r
170ef2d9
GS
121 ASSERT (FALSE);\r
122 return 0;\r
123 }\r
124\r
125 //\r
126 // Read PMBA to read and return the current ACPI timer value.\r
127 //\r
128 return IoRead32 ((PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET);\r
129}\r