TianoCore EDK2 master
Loading...
Searching...
No Matches
BaseRomAcpiTimerLib.c
Go to the documentation of this file.
1
10#include <Library/DebugLib.h>
11#include <Library/IoLib.h>
12#include <Library/PciLib.h>
13#include <OvmfPlatforms.h>
14
24RETURN_STATUS
25EFIAPI
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 Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
44 PmbaAndVal = ~(UINT32)PIIX4_PMBA_MASK;
45 PmbaOrVal = PIIX4_PMBA_VALUE;
46 AcpiCtlReg = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMREGMISC);
47 AcpiEnBit = PIIX4_PMREGMISC_PMIOSE;
48 break;
49 case INTEL_Q35_MCH_DEVICE_ID:
50 Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);
51 PmbaAndVal = ~(UINT32)ICH9_PMBASE_MASK;
52 PmbaOrVal = ICH9_PMBASE_VALUE;
53 AcpiCtlReg = POWER_MGMT_REGISTER_Q35 (ICH9_ACPI_CNTL);
54 AcpiEnBit = ICH9_ACPI_CNTL_ACPI_EN;
55 break;
56 case CLOUDHV_DEVICE_ID:
57 return RETURN_SUCCESS;
58 default:
59 DEBUG ((
60 DEBUG_ERROR,
61 "%a: Unknown Host Bridge Device ID: 0x%04x\n",
62 __func__,
63 HostBridgeDevId
64 ));
65 ASSERT (FALSE);
66 return RETURN_UNSUPPORTED;
67 }
68
69 //
70 // Check to see if the Power Management Base Address is already enabled
71 //
72 if ((PciRead8 (AcpiCtlReg) & AcpiEnBit) == 0) {
73 //
74 // If the Power Management Base Address is not programmed,
75 // then program it now.
76 //
77 PciAndThenOr32 (Pmba, PmbaAndVal, PmbaOrVal);
78
79 //
80 // Enable PMBA I/O port decodes
81 //
82 PciOr8 (AcpiCtlReg, AcpiEnBit);
83 }
84
85 return RETURN_SUCCESS;
86}
87
97UINT32
99 VOID
100 )
101{
102 UINT16 HostBridgeDevId;
103 UINTN Pmba;
104
105 //
106 // Query Host Bridge DID to determine platform type
107 //
108 HostBridgeDevId = PciRead16 (OVMF_HOSTBRIDGE_DID);
109 switch (HostBridgeDevId) {
110 case INTEL_82441_DEVICE_ID:
111 Pmba = POWER_MGMT_REGISTER_PIIX4 (PIIX4_PMBA);
112 break;
113 case INTEL_Q35_MCH_DEVICE_ID:
114 Pmba = POWER_MGMT_REGISTER_Q35 (ICH9_PMBASE);
115 break;
116 case CLOUDHV_DEVICE_ID:
117 return IoRead32 (CLOUDHV_ACPI_TIMER_IO_ADDRESS);
118 default:
119 DEBUG ((
120 DEBUG_ERROR,
121 "%a: Unknown Host Bridge Device ID: 0x%04x\n",
122 __func__,
123 HostBridgeDevId
124 ));
125 ASSERT (FALSE);
126 return 0;
127 }
128
129 //
130 // Read PMBA to read and return the current ACPI timer value.
131 //
132 return IoRead32 ((PciRead32 (Pmba) & ~PMBA_RTE) + ACPI_TIMER_OFFSET);
133}
UINT64 UINTN
UINT32 InternalAcpiGetTimerTick(VOID)
RETURN_STATUS EFIAPI AcpiTimerLibConstructor(VOID)
UINT32 EFIAPI IoRead32(IN UINTN Port)
Definition: IoLibArmVirt.c:275
#define RETURN_UNSUPPORTED
Definition: Base.h:1081
#define RETURN_SUCCESS
Definition: Base.h:1066
#define FALSE
Definition: Base.h:307
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINT32 EFIAPI PciAndThenOr32(IN UINTN Address, IN UINT32 AndData, IN UINT32 OrData)
Definition: PciLib.c:860
UINT32 EFIAPI PciRead32(IN UINTN Address)
Definition: PciLib.c:739
UINT8 EFIAPI PciRead8(IN UINTN Address)
Definition: PciLib.c:62
UINT8 EFIAPI PciOr8(IN UINTN Address, IN UINT8 OrData)
Definition: PciLib.c:117
UINT16 EFIAPI PciRead16(IN UINTN Address)
Definition: PciLib.c:396