VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/OvmfPkg/Library/AcpiTimerLib/BaseRomAcpiTimerLib.c@ 105681

Last change on this file since 105681 was 101291, checked in by vboxsync, 19 months ago

EFI/FirmwareNew: Make edk2-stable202308 build on all supported platforms (using gcc at least, msvc not tested yet), bugref:4643

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1/** @file
2 Provide constructor and GetTick for BaseRom instance of ACPI Timer Library
3
4 Copyright (c) 2008 - 2012, Intel Corporation. All rights reserved.
5 Copyright (c) 2011, Andrei Warkentin <[email protected]>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8**/
9
10#include <Library/DebugLib.h>
11#include <Library/IoLib.h>
12#include <Library/PciLib.h>
13#include <OvmfPlatforms.h>
14
15/**
16 The constructor function enables ACPI IO space.
17
18 If ACPI I/O space not enabled, this function will enable it.
19 It will always return RETURN_SUCCESS.
20
21 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
22
23**/
24RETURN_STATUS
25EFIAPI
26AcpiTimerLibConstructor (
27 VOID
28 )
29{
30 UINT16 HostBridgeDevId;
31 UINTN Pmba;
32 UINT32 PmbaAndVal;
33 UINT32 PmbaOrVal;
34 UINTN AcpiCtlReg;
35 UINT8 AcpiEnBit;
36
37 //
38 // Query Host Bridge DID to determine platform type
39 //
40 HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
41 switch (HostBridgeDevId) {
42 case INTEL_82441_DEVICE_ID:
43#ifdef VBOX
44 // HACK ALERT! There is no host bridge device in the PCIe chipset, and the same PIIX4 PM device is used.
45 // But there might be some other device at 0:0.0.
46 default:
47#endif
48 Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
49 PmbaAndVal = ~(UINT32)PIIX4_PMBA_MASK;
50 PmbaOrVal = PIIX4_PMBA_VALUE;
51 AcpiCtlReg = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMREGMISC);
52 AcpiEnBit = PIIX4_PMREGMISC_PMIOSE;
53 break;
54 case INTEL_Q35_MCH_DEVICE_ID:
55 Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);
56 PmbaAndVal = ~(UINT32)ICH9_PMBASE_MASK;
57 PmbaOrVal = ICH9_PMBASE_VALUE;
58 AcpiCtlReg = POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL);
59 AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN;
60 break;
61 case CLOUDHV_DEVICE_ID:
62 return RETURN_SUCCESS;
63#ifndef VBOX
64 default:
65 DEBUG ((
66 DEBUG_ERROR,
67 "%a: Unknown Host Bridge Device ID: 0x%04x\n",
68 __func__,
69 HostBridgeDevId
70 ));
71 ASSERT (FALSE);
72 return RETURN_UNSUPPORTED;
73#endif
74 }
75
76 //
77 // Check to see if the Power Management Base Address is already enabled
78 //
79 if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) {
80 //
81 // If the Power Management Base Address is not programmed,
82 // then program it now.
83 //
84 PciAndThenOr32 (Pmba, PmbaAndVal, PmbaOrVal);
85
86 //
87 // Enable PMBA I/O port decodes
88 //
89 PciOr8 (AcpiCtlReg, AcpiEnBit);
90 }
91
92 return RETURN_SUCCESS;
93}
94
95/**
96 Internal function to read the current tick counter of ACPI.
97
98 Dynamically compute the address of the ACPI tick counter based on the
99 properties of the underlying platform, to avoid relying on global variables.
100
101 @return The tick counter read.
102
103**/
104UINT32
105InternalAcpiGetTimerTick (
106 VOID
107 )
108{
109 UINT16 HostBridgeDevId;
110 UINTN Pmba;
111
112 //
113 // Query Host Bridge DID to determine platform type
114 //
115 HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
116 switch (HostBridgeDevId) {
117 case INTEL_82441_DEVICE_ID:
118 Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
119 break;
120 case INTEL_Q35_MCH_DEVICE_ID:
121 Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);
122 break;
123 case CLOUDHV_DEVICE_ID:
124 return IoRead32 (CLOUDHV_ACPI_TIMER_IO_ADDRESS);
125 default:
126 DEBUG ((
127 DEBUG_ERROR,
128 "%a: Unknown Host Bridge Device ID: 0x%04x\n",
129 __func__,
130 HostBridgeDevId
131 ));
132 ASSERT (FALSE);
133 return 0;
134 }
135
136 //
137 // Read PMBA to read and return the current ACPI timer value.
138 //
139 return IoRead32 ((PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET);
140}
Note: See TracBrowser for help on using the repository browser.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette