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