]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Library/AcpiTimerLib/DxeAcpiTimerLib.c
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / Library / AcpiTimerLib / DxeAcpiTimerLib.c
1 /** @file
2 Provide constructor and GetTick for Dxe 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/PcdLib.h>
12 #include <Library/PciLib.h>
13 #include <OvmfPlatforms.h>
14
15 //
16 // Cached ACPI Timer IO Address
17 //
18 STATIC UINT32 mAcpiTimerIoAddr;
19
20 /**
21 The constructor function caches the ACPI tick counter address
22
23 At the time this constructor runs (DXE_CORE or later), ACPI IO space
24 has already been enabled by either PlatformPei or by the "Base"
25 instance of this library.
26 In order to avoid querying the underlying platform type during each
27 tick counter read operation, we cache the counter address during
28 initialization of this instance of the Timer Library.
29
30 @retval EFI_SUCCESS The constructor always returns RETURN_SUCCESS.
31
32 **/
33 RETURN_STATUS
34 EFIAPI
35 AcpiTimerLibConstructor (
36 VOID
37 )
38 {
39 UINT16 HostBridgeDevId;
40 UINTN Pmba;
41
42 //
43 // Query Host Bridge DID to determine platform type
44 //
45 HostBridgeDevId = PcdGet16 (PcdOvmfHostBridgePciDevId);
46 switch (HostBridgeDevId) {
47 case INTEL_82441_DEVICE_ID:
48 Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
49 break;
50 case INTEL_Q35_MCH_DEVICE_ID:
51 Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);
52 break;
53 default:
54 DEBUG ((
55 DEBUG_ERROR,
56 "%a: Unknown Host Bridge Device ID: 0x%04x\n",
57 __FUNCTION__,
58 HostBridgeDevId
59 ));
60 ASSERT (FALSE);
61 return RETURN_UNSUPPORTED;
62 }
63
64 mAcpiTimerIoAddr = (PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET;
65
66 return RETURN_SUCCESS;
67 }
68
69 /**
70 Internal function to read the current tick counter of ACPI.
71
72 Read the current ACPI tick counter using the counter address cached
73 by this instance's constructor.
74
75 @return The tick counter read.
76
77 **/
78 UINT32
79 InternalAcpiGetTimerTick (
80 VOID
81 )
82 {
83 //
84 // Return the current ACPI timer value.
85 //
86 return IoRead32 (mAcpiTimerIoAddr);
87 }