TianoCore EDK2 master
Loading...
Searching...
No Matches
AcpiHpetLib.c
Go to the documentation of this file.
1
11#include <AcpiTableGenerator.h>
15#include <Library/DebugLib.h>
17#include <Protocol/AcpiTable.h>
19#include <X64NameSpaceObjects.h>
20#include <Library/IoLib.h>
21
24#define HPET_VALID_PAGE_PROTECTION \
25 (EFI_ACPI_NO_PAGE_PROTECTION | \
26 EFI_ACPI_4KB_PAGE_PROTECTION | \
27 EFI_ACPI_64KB_PAGE_PROTECTION)
28
36 );
37
46 ),
47 // EventTimerBlockId,
48 0,
49 // BaseAddressLower32Bit
50 { EFI_ACPI_6_5_SYSTEM_MEMORY, 64,0, EFI_ACPI_RESERVED_BYTE, 0 },
51 // HpetNumber
52 0,
53 // MainCounterMinimumClockTickInPeriodicMode
54 0,
55 // PageProtectionAndOemAttribute
56 EFI_ACPI_NO_PAGE_PROTECTION
57};
58
75EFIAPI
78 )
79{
80 CM_X64_HPET_INFO *HpetInfo;
82 EFI_STATUS Status;
83
84 ASSERT (CfgMgrProtocol != NULL);
85
86 // Get the HPET information from the Platform Configuration Manager
87 Status = GetEX64ObjHpetInfo (
88 CfgMgrProtocol,
90 &HpetInfo,
91 NULL
92 );
93 if (EFI_ERROR (Status)) {
94 DEBUG ((
95 DEBUG_ERROR,
96 "ERROR: HPET: Failed to get HPET information." \
97 " Status = %r\n",
98 Status
99 ));
100 return Status;
101 }
102
103 DEBUG ((
104 DEBUG_INFO,
105 "HPET: Device base address = 0x%x\n"
106 " : Minimum clock tick in periodic mode = 0x%x\n"
107 " : Page protection and Oem flags = 0x%x\n",
108 HpetInfo->BaseAddressLower32Bit,
109 HpetInfo->MainCounterMinimumClockTickInPeriodicMode,
110 HpetInfo->PageProtectionAndOemAttribute
111 ));
112
113 // Validate the page protection flags bit0 to bit3
114 if (((HpetInfo->PageProtectionAndOemAttribute & 0xF) & ~HPET_VALID_PAGE_PROTECTION) != 0) {
115 DEBUG ((
116 DEBUG_ERROR,
117 "ERROR: HPET: unsupported page protection flags = 0x%x\n",
118 HpetInfo->PageProtectionAndOemAttribute
119 ));
120 ASSERT_EFI_ERROR (EFI_UNSUPPORTED);
121 return EFI_UNSUPPORTED;
122 }
123
124 // Get HPET Capabilities ID register value and test if HPET is enabled
125 HpetBlockId.Uint32 = MmioRead32 (HpetInfo->BaseAddressLower32Bit);
126
127 // If mmio address is not mapped
128 if ((HpetBlockId.Uint32 == MAX_UINT32) || (HpetBlockId.Uint32 == 0)) {
129 DEBUG ((DEBUG_ERROR, "HPET Capabilities register read failed.\n"));
130 ASSERT_EFI_ERROR (EFI_NOT_FOUND);
131 return EFI_NOT_FOUND;
132 }
133
134 // Validate Reserved and Revision ID
135 if (HpetBlockId.Bits.Reserved != 0) {
136 DEBUG ((DEBUG_ERROR, "HPET Reserved bit is set.\n"));
137 ASSERT_EFI_ERROR (EFI_UNSUPPORTED);
138 return EFI_UNSUPPORTED;
139 }
140
141 if (HpetBlockId.Bits.Revision == 0) {
142 DEBUG ((DEBUG_ERROR, "HPET Revision is not set.\n"));
143 ASSERT_EFI_ERROR (EFI_UNSUPPORTED);
144 return EFI_UNSUPPORTED;
145 }
146
147 // Fill the Event Timer Block ID
148 AcpiHpet.EventTimerBlockId = HpetBlockId.Uint32;
149
150 // Fill the Base Address
151 AcpiHpet.BaseAddressLower32Bit.Address = HpetInfo->BaseAddressLower32Bit;
152
153 // Minimum clock tick in periodic mode
154 AcpiHpet.MainCounterMinimumClockTickInPeriodicMode = HpetInfo->MainCounterMinimumClockTickInPeriodicMode;
155
156 // Page protection and OEM attribute
157 AcpiHpet.PageProtectionAndOemAttribute = HpetInfo->PageProtectionAndOemAttribute;
158
159 return Status;
160}
161
183STATIC
185EFIAPI
191 )
192{
193 EFI_STATUS Status;
194
195 ASSERT (This != NULL);
196 ASSERT (AcpiTableInfo != NULL);
197 ASSERT (CfgMgrProtocol != NULL);
198 ASSERT (Table != NULL);
199 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);
200 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);
201
202 if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) ||
203 (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision))
204 {
205 DEBUG ((
206 DEBUG_ERROR,
207 "ERROR: HPET: Requested table revision = %d, is not supported."
208 "Supported table revision: Minimum = %d, Maximum = %d\n",
209 AcpiTableInfo->AcpiTableRevision,
210 This->MinAcpiTableRevision,
211 This->AcpiTableRevision
212 ));
213 return EFI_INVALID_PARAMETER;
214 }
215
216 *Table = NULL;
217
218 Status = AddAcpiHeader (
219 CfgMgrProtocol,
220 This,
222 AcpiTableInfo,
224 );
225 if (EFI_ERROR (Status)) {
226 DEBUG ((
227 DEBUG_ERROR,
228 "ERROR: HPET: Failed to add ACPI header. Status = %r\n",
229 Status
230 ));
231 goto error_handler;
232 }
233
234 // Update HPET table info
235 Status = HpetUpdateTableInfo (CfgMgrProtocol);
236 if (EFI_ERROR (Status)) {
237 goto error_handler;
238 }
239
241error_handler:
242 return Status;
243}
244
247#define HPET_GENERATOR_REVISION CREATE_REVISION (1, 0)
248
251STATIC
252CONST
254 // Generator ID
256 // Generator Description
257 L"ACPI.STD.HPET.GENERATOR",
258 // ACPI Table Signature
260 // ACPI Table Revision supported by this Generator
262 // Minimum supported ACPI Table Revision
264 // Creator ID
266 // Creator Revision
268 // Build Table function
270 // No additional resources are allocated by the generator.
271 // Hence the Free Resource function is not required.
272 NULL,
273 // Extended build function not needed
274 NULL,
275 // Extended build function not implemented by the generator.
276 // Hence extended free resource function is not required.
277 NULL
278};
279
291EFIAPI
293 IN EFI_HANDLE ImageHandle,
294 IN EFI_SYSTEM_TABLE *SystemTable
295 )
296{
297 EFI_STATUS Status;
298
300 DEBUG ((DEBUG_INFO, "HPET: Register Generator. Status = %r\n", Status));
301 ASSERT_EFI_ERROR (Status);
302 return Status;
303}
304
315EFIAPI
317 IN EFI_HANDLE ImageHandle,
318 IN EFI_SYSTEM_TABLE *SystemTable
319 )
320{
321 EFI_STATUS Status;
322
324 DEBUG ((DEBUG_INFO, "HPET: Deregister Generator. Status = %r\n", Status));
325 ASSERT_EFI_ERROR (Status);
326 return Status;
327}
#define EFI_ACPI_6_5_HIGH_PRECISION_EVENT_TIMER_TABLE_SIGNATURE
Definition: Acpi65.h:3227
STATIC EFI_STATUS EFIAPI HpetUpdateTableInfo(IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol)
Definition: AcpiHpetLib.c:76
#define HPET_VALID_PAGE_PROTECTION
Definition: AcpiHpetLib.c:24
#define HPET_GENERATOR_REVISION
Definition: AcpiHpetLib.c:247
STATIC EFI_ACPI_HIGH_PRECISION_EVENT_TIMER_TABLE_HEADER AcpiHpet
Definition: AcpiHpetLib.c:41
STATIC EFI_STATUS EFIAPI BuildHpetTable(IN CONST ACPI_TABLE_GENERATOR *CONST This, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, OUT EFI_ACPI_DESCRIPTION_HEADER **CONST Table)
Definition: AcpiHpetLib.c:186
EFI_STATUS EFIAPI AcpiHpetLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: AcpiHpetLib.c:316
STATIC CONST ACPI_TABLE_GENERATOR HpetGenerator
Definition: AcpiHpetLib.c:253
EFI_STATUS EFIAPI AcpiHpetLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
Definition: AcpiHpetLib.c:292
EFI_STATUS EFIAPI RegisterAcpiTableGenerator(IN CONST ACPI_TABLE_GENERATOR *CONST Generator)
EFI_STATUS EFIAPI DeregisterAcpiTableGenerator(IN CONST ACPI_TABLE_GENERATOR *CONST Generator)
#define CREATE_STD_ACPI_TABLE_GEN_ID(TableId)
#define TABLE_GENERATOR_CREATOR_ID
@ EStdAcpiTableIdHpet
HPET Generator.
#define ACPI_HEADER(Signature, Type, Revision)
#define GET_OBJECT_LIST(CmObjectNameSpace, CmObjectId, Type)
@ EObjNameSpaceX64
X64 Objects Namespace.
#define EFI_ACPI_HIGH_PRECISION_EVENT_TIMER_TABLE_REVISION
UINT32 EFIAPI MmioRead32(IN UINTN Address)
Definition: IoLib.c:262
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define CM_NULL_TOKEN
EFI_STATUS EFIAPI AddAcpiHeader(IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, IN CONST ACPI_TABLE_GENERATOR *CONST Generator, IN OUT EFI_ACPI_DESCRIPTION_HEADER *CONST AcpiHeader, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, IN CONST UINT32 Length)
Definition: TableHelper.c:114
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
@ EX64ObjHpetInfo
11 - HPET device info