]>
git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c
55f3572eef2f619d3c96dc3a00348dbfe6927431
2 Provide constructor and GetTick for BaseRom instance of ACPI Timer Library
4 Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
5 Copyright (c) 2011, Andrei Warkentin <andreiw@motorola.com>
7 This program and the accompanying materials are licensed and made
8 available under the terms and conditions of the BSD License which
9 accompanies this distribution. The full text of the license may
10 be found at http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <Library/DebugLib.h>
17 #include <Library/IoLib.h>
18 #include <Library/PciLib.h>
19 #include <Library/PcdLib.h>
20 #include <OvmfPlatforms.h>
23 // Power Management PCI Configuration Register fields
26 #define PIIX4_PMIOSE BIT0
29 // Offset in the Power Management Base Address to the ACPI Timer
31 #define ACPI_TIMER_OFFSET 0x8
34 The constructor function enables ACPI IO space.
36 If ACPI I/O space not enabled, this function will enable it.
37 It will always return RETURN_SUCCESS.
39 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
44 AcpiTimerLibConstructor (
48 UINT16 HostBridgeDevId
;
54 // Query Host Bridge DID to determine platform type
56 HostBridgeDevId
= PciRead16 (OVMF_HOSTBRIDGE_DID
);
57 switch (HostBridgeDevId
) {
58 case INTEL_82441_DEVICE_ID
:
59 Pmba
= POWER_MGMT_REGISTER_PIIX4 (0x40);
60 AcpiCtlReg
= POWER_MGMT_REGISTER_PIIX4 (0x80); // PMREGMISC
61 AcpiEnBit
= PIIX4_PMIOSE
;
63 case INTEL_Q35_MCH_DEVICE_ID
:
64 Pmba
= POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE
);
65 AcpiCtlReg
= POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL
);
66 AcpiEnBit
= ICH9_ACPI_CNTL_ACPI_EN
;
69 DEBUG ((EFI_D_ERROR
, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
70 __FUNCTION__
, HostBridgeDevId
));
72 return RETURN_UNSUPPORTED
;
76 // Check to see if the Power Management Base Address is already enabled
78 if ((PciRead8 (AcpiCtlReg
) & AcpiEnBit
) == 0) {
80 // If the Power Management Base Address is not programmed,
81 // then program the Power Management Base Address from a PCD.
83 PciAndThenOr32 (Pmba
, (UINT32
) ~0xFFC0, PcdGet16 (PcdAcpiPmBaseAddress
));
86 // Enable PMBA I/O port decodes
88 PciOr8 (AcpiCtlReg
, AcpiEnBit
);
91 return RETURN_SUCCESS
;
95 Internal function to read the current tick counter of ACPI.
97 Dynamically compute the address of the ACPI tick counter based on the
98 properties of the underlying platform, to avoid relying on global variables.
100 @return The tick counter read.
104 InternalAcpiGetTimerTick (
108 UINT16 HostBridgeDevId
;
112 // Query Host Bridge DID to determine platform type
114 HostBridgeDevId
= PciRead16 (OVMF_HOSTBRIDGE_DID
);
115 switch (HostBridgeDevId
) {
116 case INTEL_82441_DEVICE_ID
:
117 Pmba
= POWER_MGMT_REGISTER_PIIX4 (0x40);
119 case INTEL_Q35_MCH_DEVICE_ID
:
120 Pmba
= POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE
);
123 DEBUG ((EFI_D_ERROR
, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
124 __FUNCTION__
, HostBridgeDevId
));
130 // Read PMBA to read and return the current ACPI timer value.
132 return IoRead32 ((PciRead32 (Pmba
) & ~PMBA_RTE
) + ACPI_TIMER_OFFSET
);