]>
git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c
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
28 // Offset in the Power Management Base Address to the ACPI Timer
30 #define ACPI_TIMER_OFFSET 0x8
33 The constructor function enables ACPI IO space.
35 If ACPI I/O space not enabled, this function will enable it.
36 It will always return RETURN_SUCCESS.
38 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
43 AcpiTimerLibConstructor (
47 UINT16 HostBridgeDevId
;
53 // Query Host Bridge DID to determine platform type
55 HostBridgeDevId
= PciRead16 (OVMF_HOSTBRIDGE_DID
);
56 switch (HostBridgeDevId
) {
57 case INTEL_82441_DEVICE_ID
:
58 Pmba
= POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA
);
59 AcpiCtlReg
= POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMREGMISC
);
60 AcpiEnBit
= PIIX4_PMREGMISC_PMIOSE
;
62 case INTEL_Q35_MCH_DEVICE_ID
:
63 Pmba
= POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE
);
64 AcpiCtlReg
= POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL
);
65 AcpiEnBit
= ICH9_ACPI_CNTL_ACPI_EN
;
68 DEBUG ((EFI_D_ERROR
, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
69 __FUNCTION__
, HostBridgeDevId
));
71 return RETURN_UNSUPPORTED
;
75 // Check to see if the Power Management Base Address is already enabled
77 if ((PciRead8 (AcpiCtlReg
) & AcpiEnBit
) == 0) {
79 // If the Power Management Base Address is not programmed,
80 // then program the Power Management Base Address from a PCD.
82 PciAndThenOr32 (Pmba
, (UINT32
) ~0xFFC0, PcdGet16 (PcdAcpiPmBaseAddress
));
85 // Enable PMBA I/O port decodes
87 PciOr8 (AcpiCtlReg
, AcpiEnBit
);
90 return RETURN_SUCCESS
;
94 Internal function to read the current tick counter of ACPI.
96 Dynamically compute the address of the ACPI tick counter based on the
97 properties of the underlying platform, to avoid relying on global variables.
99 @return The tick counter read.
103 InternalAcpiGetTimerTick (
107 UINT16 HostBridgeDevId
;
111 // Query Host Bridge DID to determine platform type
113 HostBridgeDevId
= PciRead16 (OVMF_HOSTBRIDGE_DID
);
114 switch (HostBridgeDevId
) {
115 case INTEL_82441_DEVICE_ID
:
116 Pmba
= POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA
);
118 case INTEL_Q35_MCH_DEVICE_ID
:
119 Pmba
= POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE
);
122 DEBUG ((EFI_D_ERROR
, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
123 __FUNCTION__
, HostBridgeDevId
));
129 // Read PMBA to read and return the current ACPI timer value.
131 return IoRead32 ((PciRead32 (Pmba
) & ~PMBA_RTE
) + ACPI_TIMER_OFFSET
);