]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c
OvmfPkg: replace old EFI_D_ debug levels with new DEBUG_ ones
[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
30 UINT16 HostBridgeDevId;\r
31 UINTN Pmba;\r
1466b76f
LE
32 UINT32 PmbaAndVal;\r
33 UINT32 PmbaOrVal;\r
e2ab3f81
GS
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
70d5086c 57 DEBUG ((DEBUG_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",\r
170ef2d9
GS
58 __FUNCTION__, HostBridgeDevId));\r
59 ASSERT (FALSE);\r
60 return RETURN_UNSUPPORTED;\r
61 }\r
62\r
63 //\r
64 // Check to see if the Power Management Base Address is already enabled\r
65 //\r
e2ab3f81 66 if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) {\r
170ef2d9
GS
67 //\r
68 // If the Power Management Base Address is not programmed,\r
b2f4da39 69 // then program it now.\r
170ef2d9 70 //\r
1466b76f 71 PciAndThenOr32 (Pmba, PmbaAndVal, PmbaOrVal);\r
170ef2d9
GS
72\r
73 //\r
e2ab3f81 74 // Enable PMBA I/O port decodes\r
170ef2d9 75 //\r
e2ab3f81 76 PciOr8 (AcpiCtlReg, AcpiEnBit);\r
170ef2d9
GS
77 }\r
78\r
79 return RETURN_SUCCESS;\r
80}\r
81\r
82/**\r
83 Internal function to read the current tick counter of ACPI.\r
84\r
85 Dynamically compute the address of the ACPI tick counter based on the\r
86 properties of the underlying platform, to avoid relying on global variables.\r
87\r
88 @return The tick counter read.\r
89\r
90**/\r
91UINT32\r
92InternalAcpiGetTimerTick (\r
93 VOID\r
94 )\r
95{\r
96 UINT16 HostBridgeDevId;\r
97 UINTN Pmba;\r
98\r
99 //\r
100 // Query Host Bridge DID to determine platform type\r
101 //\r
102 HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);\r
103 switch (HostBridgeDevId) {\r
104 case INTEL_82441_DEVICE_ID:\r
da372167 105 Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);\r
170ef2d9
GS
106 break;\r
107 case INTEL_Q35_MCH_DEVICE_ID:\r
bc9d05d6 108 Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);\r
170ef2d9
GS
109 break;\r
110 default:\r
70d5086c 111 DEBUG ((DEBUG_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",\r
170ef2d9
GS
112 __FUNCTION__, HostBridgeDevId));\r
113 ASSERT (FALSE);\r
114 return 0;\r
115 }\r
116\r
117 //\r
118 // Read PMBA to read and return the current ACPI timer value.\r
119 //\r
120 return IoRead32 ((PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET);\r
121}\r