VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c

Last change on this file was 101291, checked in by vboxsync, 17 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: 2.8 KB
Line 
1/** @file
2 Provide constructor and GetTick for Base instance of ACPI Timer Library
3
4 Copyright (C) 2014, Gabriel L. Somlo <somlo@cmu.edu>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7**/
8
9#include <Library/DebugLib.h>
10#include <Library/IoLib.h>
11#include <Library/PciLib.h>
12#include <OvmfPlatforms.h>
13
14//
15// Cached ACPI Timer IO Address
16//
17STATIC UINT32 mAcpiTimerIoAddr;
18
19/**
20 The constructor function caches the ACPI tick counter address, and,
21 if necessary, enables ACPI IO space.
22
23 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
24
25**/
26RETURN_STATUS
27EFIAPI
28AcpiTimerLibConstructor (
29 VOID
30 )
31{
32 UINT16 HostBridgeDevId;
33 UINTN Pmba;
34 UINT32 PmbaAndVal;
35 UINT32 PmbaOrVal;
36 UINTN AcpiCtlReg;
37 UINT8 AcpiEnBit;
38
39 //
40 // Query Host Bridge DID to determine platform type
41 //
42 HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
43 switch (HostBridgeDevId) {
44 case INTEL_82441_DEVICE_ID:
45#ifdef VBOX
46 // HACK ALERT! There is no host bridge device in the PCIe chipset, and the same PIIX4 PM device is used.
47 // But there might be some other device at 0:0.0.
48 default:
49#endif
50 Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
51 PmbaAndVal = ~(UINT32)PIIX4_PMBA_MASK;
52 PmbaOrVal = PIIX4_PMBA_VALUE;
53 AcpiCtlReg = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMREGMISC);
54 AcpiEnBit = PIIX4_PMREGMISC_PMIOSE;
55 break;
56 case INTEL_Q35_MCH_DEVICE_ID:
57 Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);
58 PmbaAndVal = ~(UINT32)ICH9_PMBASE_MASK;
59 PmbaOrVal = ICH9_PMBASE_VALUE;
60 AcpiCtlReg = POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL);
61 AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN;
62 break;
63 case CLOUDHV_DEVICE_ID:
64 mAcpiTimerIoAddr = CLOUDHV_ACPI_TIMER_IO_ADDRESS;
65 return RETURN_SUCCESS;
66#ifndef VBOX
67 default:
68 DEBUG ((
69 DEBUG_ERROR,
70 "%a: Unknown Host Bridge Device ID: 0x%04x\n",
71 __func__,
72 HostBridgeDevId
73 ));
74 ASSERT (FALSE);
75 return RETURN_UNSUPPORTED;
76#endif
77 }
78
79 //
80 // Check to see if the Power Management Base Address is already enabled
81 //
82 if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) {
83 //
84 // If the Power Management Base Address is not programmed,
85 // then program it now.
86 //
87 PciAndThenOr32 (Pmba, PmbaAndVal, PmbaOrVal);
88
89 //
90 // Enable PMBA I/O port decodes
91 //
92 PciOr8 (AcpiCtlReg, AcpiEnBit);
93 }
94
95 mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET;
96 return RETURN_SUCCESS;
97}
98
99/**
100 Internal function to read the current tick counter of ACPI.
101
102 Read the current ACPI tick counter using the counter address cached
103 by this instance's constructor.
104
105 @return The tick counter read.
106
107**/
108UINT32
109InternalAcpiGetTimerTick (
110 VOID
111 )
112{
113 //
114 // Return the current ACPI timer value.
115 //
116 return IoRead32 (mAcpiTimerIoAddr);
117}
Note: See TracBrowser for help on using the repository browser.

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