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