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