]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c
OvmfPkg: consolidate POWER_MGMT_REGISTER_PIIX4() on "I440FxPiix4.h" macros
[mirror_edk2.git] / OvmfPkg / Library / AcpiTimerLib / BaseAcpiTimerLib.c
CommitLineData
170ef2d9
GS
1/** @file\r
2 Provide constructor and GetTick for Base instance of ACPI Timer Library\r
3\r
4 Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>\r
5\r
6 This program and the accompanying materials are licensed and made\r
7 available under the terms and conditions of the BSD License which\r
8 accompanies this distribution. The full text of the license may\r
9 be found at http://opensource.org/licenses/bsd-license.php\r
10\r
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13**/\r
14\r
15#include <Library/DebugLib.h>\r
16#include <Library/IoLib.h>\r
17#include <Library/PciLib.h>\r
f122712b 18#include <Library/PcdLib.h>\r
170ef2d9
GS
19#include <OvmfPlatforms.h>\r
20\r
21//\r
22// Power Management PCI Configuration Register fields\r
23//\r
e2ab3f81 24#define PMBA_RTE BIT0\r
170ef2d9
GS
25\r
26//\r
27// Offset in the Power Management Base Address to the ACPI Timer\r
28//\r
29#define ACPI_TIMER_OFFSET 0x8\r
30\r
31//\r
32// Cached ACPI Timer IO Address\r
33//\r
34STATIC UINT32 mAcpiTimerIoAddr;\r
35\r
36/**\r
f122712b
GS
37 The constructor function caches the ACPI tick counter address, and,\r
38 if necessary, enables ACPI IO space.\r
170ef2d9
GS
39\r
40 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r
41\r
42**/\r
43RETURN_STATUS\r
44EFIAPI\r
45AcpiTimerLibConstructor (\r
46 VOID\r
47 )\r
48{\r
49 UINT16 HostBridgeDevId;\r
50 UINTN Pmba;\r
e2ab3f81
GS
51 UINTN AcpiCtlReg;\r
52 UINT8 AcpiEnBit;\r
170ef2d9
GS
53\r
54 //\r
55 // Query Host Bridge DID to determine platform type\r
56 //\r
57 HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);\r
58 switch (HostBridgeDevId) {\r
59 case INTEL_82441_DEVICE_ID:\r
da372167
LE
60 Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);\r
61 AcpiCtlReg = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMREGMISC);\r
62 AcpiEnBit = PIIX4_PMREGMISC_PMIOSE;\r
170ef2d9
GS
63 break;\r
64 case INTEL_Q35_MCH_DEVICE_ID:\r
bc9d05d6
LE
65 Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);\r
66 AcpiCtlReg = POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL);\r
67 AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN;\r
170ef2d9
GS
68 break;\r
69 default:\r
70 DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",\r
71 __FUNCTION__, HostBridgeDevId));\r
72 ASSERT (FALSE);\r
73 return RETURN_UNSUPPORTED;\r
74 }\r
75\r
76 mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET;\r
77\r
f122712b
GS
78 //\r
79 // Check to see if the Power Management Base Address is already enabled\r
80 //\r
e2ab3f81 81 if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) {\r
f122712b
GS
82 //\r
83 // If the Power Management Base Address is not programmed,\r
84 // then program the Power Management Base Address from a PCD.\r
85 //\r
86 PciAndThenOr32 (Pmba, (UINT32) ~0xFFC0, PcdGet16 (PcdAcpiPmBaseAddress));\r
87\r
88 //\r
e2ab3f81 89 // Enable PMBA I/O port decodes\r
f122712b 90 //\r
e2ab3f81 91 PciOr8 (AcpiCtlReg, AcpiEnBit);\r
f122712b
GS
92 }\r
93\r
170ef2d9
GS
94 return RETURN_SUCCESS;\r
95}\r
96\r
97/**\r
98 Internal function to read the current tick counter of ACPI.\r
99\r
100 Read the current ACPI tick counter using the counter address cached\r
101 by this instance's constructor.\r
102\r
103 @return The tick counter read.\r
104\r
105**/\r
106UINT32\r
107InternalAcpiGetTimerTick (\r
108 VOID\r
109 )\r
110{\r
111 //\r
112 // Return the current ACPI timer value.\r
113 //\r
114 return IoRead32 (mAcpiTimerIoAddr);\r
115}\r