]> git.proxmox.com Git - mirror_edk2.git/blame - OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c
OvmfPkg: consolidate POWER_MGMT_REGISTER_Q35() on "Q35MchIch9.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
GS
24#define PMBA_RTE BIT0\r
25#define PIIX4_PMIOSE BIT0\r
170ef2d9
GS
26\r
27//\r
28// Offset in the Power Management Base Address to the ACPI Timer\r
29//\r
30#define ACPI_TIMER_OFFSET 0x8\r
31\r
32//\r
33// Cached ACPI Timer IO Address\r
34//\r
35STATIC UINT32 mAcpiTimerIoAddr;\r
36\r
37/**\r
f122712b
GS
38 The constructor function caches the ACPI tick counter address, and,\r
39 if necessary, enables ACPI IO space.\r
170ef2d9
GS
40\r
41 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.\r
42\r
43**/\r
44RETURN_STATUS\r
45EFIAPI\r
46AcpiTimerLibConstructor (\r
47 VOID\r
48 )\r
49{\r
50 UINT16 HostBridgeDevId;\r
51 UINTN Pmba;\r
e2ab3f81
GS
52 UINTN AcpiCtlReg;\r
53 UINT8 AcpiEnBit;\r
170ef2d9
GS
54\r
55 //\r
56 // Query Host Bridge DID to determine platform type\r
57 //\r
58 HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);\r
59 switch (HostBridgeDevId) {\r
60 case INTEL_82441_DEVICE_ID:\r
e2ab3f81
GS
61 Pmba = POWER_MGMT_REGISTER_PIIX4 (0x40);\r
62 AcpiCtlReg = POWER_MGMT_REGISTER_PIIX4 (0x80); // PMREGMISC\r
63 AcpiEnBit = PIIX4_PMIOSE;\r
170ef2d9
GS
64 break;\r
65 case INTEL_Q35_MCH_DEVICE_ID:\r
bc9d05d6
LE
66 Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);\r
67 AcpiCtlReg = POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL);\r
68 AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN;\r
170ef2d9
GS
69 break;\r
70 default:\r
71 DEBUG ((EFI_D_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",\r
72 __FUNCTION__, HostBridgeDevId));\r
73 ASSERT (FALSE);\r
74 return RETURN_UNSUPPORTED;\r
75 }\r
76\r
77 mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET;\r
78\r
f122712b
GS
79 //\r
80 // Check to see if the Power Management Base Address is already enabled\r
81 //\r
e2ab3f81 82 if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) {\r
f122712b
GS
83 //\r
84 // If the Power Management Base Address is not programmed,\r
85 // then program the Power Management Base Address from a PCD.\r
86 //\r
87 PciAndThenOr32 (Pmba, (UINT32) ~0xFFC0, PcdGet16 (PcdAcpiPmBaseAddress));\r
88\r
89 //\r
e2ab3f81 90 // Enable PMBA I/O port decodes\r
f122712b 91 //\r
e2ab3f81 92 PciOr8 (AcpiCtlReg, AcpiEnBit);\r
f122712b
GS
93 }\r
94\r
170ef2d9
GS
95 return RETURN_SUCCESS;\r
96}\r
97\r
98/**\r
99 Internal function to read the current tick counter of ACPI.\r
100\r
101 Read the current ACPI tick counter using the counter address cached\r
102 by this instance's constructor.\r
103\r
104 @return The tick counter read.\r
105\r
106**/\r
107UINT32\r
108InternalAcpiGetTimerTick (\r
109 VOID\r
110 )\r
111{\r
112 //\r
113 // Return the current ACPI timer value.\r
114 //\r
115 return IoRead32 (mAcpiTimerIoAddr);\r
116}\r