VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/FirmwareNew/OvmfPkg/Library/AcpiTimerLib/BaseAcpiTimerLib.c@ 99396

Last change on this file since 99396 was 85718, checked in by vboxsync, 5 years ago

Devices/EFI: Merge edk-stable202005 and make it build, bugref:4643

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1/** @file
2 Provide constructor and GetTick for Base instance of ACPI Timer Library
3
4 Copyright (C) 2014, Gabriel L. Somlo <[email protected]>
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#ifndef VBOX
64 default:
65 DEBUG ((DEBUG_ERROR, "%a: Unknown Host Bridge Device ID: 0x%04x\n",
66 __FUNCTION__, HostBridgeDevId));
67 ASSERT (FALSE);
68 return RETURN_UNSUPPORTED;
69#endif
70 }
71
72 //
73 // Check to see if the Power Management Base Address is already enabled
74 //
75 if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) {
76 //
77 // If the Power Management Base Address is not programmed,
78 // then program it now.
79 //
80 PciAndThenOr32 (Pmba, PmbaAndVal, PmbaOrVal);
81
82 //
83 // Enable PMBA I/O port decodes
84 //
85 PciOr8 (AcpiCtlReg, AcpiEnBit);
86 }
87
88 mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET;
89 return RETURN_SUCCESS;
90}
91
92/**
93 Internal function to read the current tick counter of ACPI.
94
95 Read the current ACPI tick counter using the counter address cached
96 by this instance's constructor.
97
98 @return The tick counter read.
99
100**/
101UINT32
102InternalAcpiGetTimerTick (
103 VOID
104 )
105{
106 //
107 // Return the current ACPI timer value.
108 //
109 return IoRead32 (mAcpiTimerIoAddr);
110}
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