TianoCore EDK2 master
Loading...
Searching...
No Matches
AcpiSsdtHpetLib.c
Go to the documentation of this file.
1
11#include <Library/BaseLib.h>
13#include <Library/DebugLib.h>
15#include <Protocol/AcpiTable.h>
16
17// Module specific include files.
18#include <AcpiTableGenerator.h>
25#include <Library/IoLib.h>
26
29#define HPET_VALID_PAGE_PROTECTION \
30 (EFI_ACPI_NO_PAGE_PROTECTION | \
31 EFI_ACPI_4KB_PAGE_PROTECTION | \
32 EFI_ACPI_64KB_PAGE_PROTECTION)
33
41 );
42
60EFIAPI
64 )
65{
66 CM_X64_HPET_INFO *HpetInfo;
68 EFI_STATUS Status;
71 UINT32 EisaId;
72
73 ASSERT (CfgMgrProtocol != NULL);
74
75 // Get the HPET information from the Platform Configuration Manager
76 Status = GetEX64ObjHpetInfo (
77 CfgMgrProtocol,
79 &HpetInfo,
80 NULL
81 );
82 if (EFI_ERROR (Status)) {
83 DEBUG ((
84 DEBUG_ERROR,
85 "ERROR: HPET: Failed to get HPET information." \
86 " Status = %r\n",
87 Status
88 ));
89 return Status;
90 }
91
92 DEBUG ((
93 DEBUG_INFO,
94 "HPET: Device base address = 0x%x\n"
95 " : Minimum clock tick in periodic mode = 0x%x\n"
96 " : Page protection and Oem flags = 0x%x\n",
97 HpetInfo->BaseAddressLower32Bit,
98 HpetInfo->MainCounterMinimumClockTickInPeriodicMode,
99 HpetInfo->PageProtectionAndOemAttribute
100 ));
101
102 // Validate the page protection flags bit0 to bit3
103 if (((HpetInfo->PageProtectionAndOemAttribute & 0xF) & ~HPET_VALID_PAGE_PROTECTION) != 0) {
104 DEBUG ((
105 DEBUG_ERROR,
106 "ERROR: HPET: unsupported page protection flags = 0x%x\n",
107 HpetInfo->PageProtectionAndOemAttribute
108 ));
109 ASSERT_EFI_ERROR (EFI_UNSUPPORTED);
110 return EFI_UNSUPPORTED;
111 }
112
113 // Get HPET Capabilities ID register value and test if HPET is enabled
114 HpetBlockId.Uint32 = MmioRead32 (HpetInfo->BaseAddressLower32Bit);
115
116 // If mmio address is not mapped
117 if ((HpetBlockId.Uint32 == MAX_UINT32) || (HpetBlockId.Uint32 == 0)) {
118 DEBUG ((DEBUG_ERROR, "HPET Capabilities register read failed.\n"));
119 ASSERT_EFI_ERROR (EFI_NOT_FOUND);
120 return EFI_NOT_FOUND;
121 }
122
123 // Validate Reserved and Revision ID
124 if (HpetBlockId.Bits.Reserved != 0) {
125 DEBUG ((DEBUG_ERROR, "HPET Reserved bit is set.\n"));
126 ASSERT_EFI_ERROR (EFI_UNSUPPORTED);
127 return EFI_UNSUPPORTED;
128 }
129
130 if (HpetBlockId.Bits.Revision == 0) {
131 DEBUG ((DEBUG_ERROR, "HPET Revision is not set.\n"));
132 ASSERT_EFI_ERROR (EFI_UNSUPPORTED);
133 return EFI_UNSUPPORTED;
134 }
135
136 Status = AmlCodeGenDevice ("HPET", ScopeNode, &HpetNode);
137 if (EFI_ERROR (Status)) {
138 ASSERT_EFI_ERROR (Status);
139 return Status;
140 }
141
142 Status = AmlGetEisaIdFromString ("PNP0103", &EisaId);
143 if (EFI_ERROR (Status)) {
144 ASSERT_EFI_ERROR (Status);
145 return Status;
146 }
147
148 Status = AmlCodeGenNameInteger ("_HID", EisaId, HpetNode, NULL);
149 if (EFI_ERROR (Status)) {
150 ASSERT_EFI_ERROR (Status);
151 return Status;
152 }
153
154 Status = AmlCodeGenNameInteger ("_UID", 0x00, HpetNode, NULL);
155 if (EFI_ERROR (Status)) {
156 ASSERT_EFI_ERROR (Status);
157 return Status;
158 }
159
160 Status = AmlCodeGenNameResourceTemplate ("_CRS", HpetNode, &CrsNode);
161 if (EFI_ERROR (Status)) {
162 ASSERT_EFI_ERROR (Status);
163 return Status;
164 }
165
167 FALSE,
168 HpetInfo->BaseAddressLower32Bit,
169 SIZE_1KB,
170 CrsNode,
171 NULL
172 );
173 if (EFI_ERROR (Status)) {
174 ASSERT_EFI_ERROR (Status);
175 return Status;
176 }
177
178 if ((HpetInfo->PageProtectionAndOemAttribute & 0xF) != 0) {
179 Status = AmlCodeGenNameInteger (
180 "PAGE",
181 (HpetInfo->PageProtectionAndOemAttribute & 0xF),
182 HpetNode,
183 NULL
184 );
185 if (EFI_ERROR (Status)) {
186 ASSERT_EFI_ERROR (Status);
187 return Status;
188 }
189 }
190
191 if ((HpetInfo->PageProtectionAndOemAttribute >> 4) != 0) {
192 Status = AmlCodeGenNameInteger (
193 "ATTR",
194 (HpetInfo->PageProtectionAndOemAttribute >> 4),
195 HpetNode,
196 NULL
197 );
198 if (EFI_ERROR (Status)) {
199 ASSERT_EFI_ERROR (Status);
200 return Status;
201 }
202 }
203
204 return Status;
205}
206
228STATIC
230EFIAPI
236 )
237{
238 EFI_STATUS Status;
239 AML_ROOT_NODE_HANDLE RootNode;
240 AML_OBJECT_NODE_HANDLE ScopeNode;
241
242 ASSERT (This != NULL);
243 ASSERT (AcpiTableInfo != NULL);
244 ASSERT (CfgMgrProtocol != NULL);
245 ASSERT (Table != NULL);
246 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);
247 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);
248
249 if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) ||
250 (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision))
251 {
252 DEBUG ((
253 DEBUG_ERROR,
254 "ERROR: HPET: Requested table revision = %d, is not supported."
255 "Supported table revision: Minimum = %d, Maximum = %d\n",
256 AcpiTableInfo->AcpiTableRevision,
257 This->MinAcpiTableRevision,
258 This->AcpiTableRevision
259 ));
260 return EFI_INVALID_PARAMETER;
261 }
262
263 *Table = NULL;
264
265 Status = AddSsdtAcpiHeader (
266 CfgMgrProtocol,
267 This,
268 AcpiTableInfo,
269 &RootNode
270 );
271 if (EFI_ERROR (Status)) {
272 return Status;
273 }
274
275 Status = AmlCodeGenScope ("\\_SB_", RootNode, &ScopeNode);
276 if (EFI_ERROR (Status)) {
277 ASSERT_EFI_ERROR (Status);
278 goto exit_handler;
279 }
280
281 // Update HPET table info
282 Status = SsdtHpetUpdateTableInfo (CfgMgrProtocol, ScopeNode);
283 if (EFI_ERROR (Status)) {
284 ASSERT_EFI_ERROR (Status);
285 goto exit_handler;
286 }
287
289 RootNode,
290 Table
291 );
292 if (EFI_ERROR (Status)) {
293 ASSERT_EFI_ERROR (Status);
294 DEBUG ((
295 DEBUG_ERROR,
296 "ERROR: SSDT-HPET: Failed to Serialize SSDT Table Data."
297 " Status = %r\n",
298 Status
299 ));
300 }
301
302exit_handler:
303 // Delete the RootNode and its attached children.
304 AmlDeleteTree (RootNode);
305 return Status;
306}
307
320STATIC
322EFIAPI
328 )
329{
330 ASSERT (This != NULL);
331 ASSERT (AcpiTableInfo != NULL);
332 ASSERT (CfgMgrProtocol != NULL);
333 ASSERT (AcpiTableInfo->TableGeneratorId == This->GeneratorID);
334 ASSERT (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature);
335
336 if ((Table == NULL) || (*Table == NULL)) {
337 DEBUG ((DEBUG_ERROR, "ERROR: SSDT-HPET: Invalid Table Pointer\n"));
338 ASSERT ((Table != NULL) && (*Table != NULL));
339 return EFI_INVALID_PARAMETER;
340 }
341
342 FreePool (*Table);
343 *Table = NULL;
344 return EFI_SUCCESS;
345}
346
349#define HPET_GENERATOR_REVISION CREATE_REVISION (1, 0)
350
353STATIC
354CONST
356 // Generator ID
358 // Generator Description
359 L"ACPI.STD.SSDT.HPET.GENERATOR",
360 // ACPI Table Signature
362 // ACPI Table Revision supported by this Generator
363 0,
364 // Minimum supported ACPI Table Revision
365 0,
366 // Creator ID
368 // Creator Revision
370 // Build Table function
372 // Free Resource function
374 // Extended build function not needed
375 NULL,
376 // Extended build function not implemented by the generator.
377 // Hence extended free resource function is not required.
378 NULL
379};
380
392EFIAPI
394 IN EFI_HANDLE ImageHandle,
395 IN EFI_SYSTEM_TABLE *SystemTable
396 )
397{
398 EFI_STATUS Status;
399
401 DEBUG ((DEBUG_INFO, "HPET: Register Generator. Status = %r\n", Status));
402 ASSERT_EFI_ERROR (Status);
403 return Status;
404}
405
416EFIAPI
418 IN EFI_HANDLE ImageHandle,
419 IN EFI_SYSTEM_TABLE *SystemTable
420 )
421{
422 EFI_STATUS Status;
423
425 DEBUG ((DEBUG_INFO, "HPET: Deregister Generator. Status = %r\n", Status));
426 ASSERT_EFI_ERROR (Status);
427 return Status;
428}
#define EFI_ACPI_6_5_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
Definition: Acpi65.h:3182
EFI_STATUS EFIAPI AmlGetEisaIdFromString(IN CONST CHAR8 *EisaIdStr, OUT UINT32 *EisaIdInt)
Definition: AcpiHelper.c:155
EFI_STATUS EFIAPI AcpiSsdtHpetLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
STATIC EFI_STATUS EFIAPI FreeSsdtHpetTableResources(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, IN OUT EFI_ACPI_DESCRIPTION_HEADER **CONST Table)
#define HPET_VALID_PAGE_PROTECTION
#define HPET_GENERATOR_REVISION
EFI_STATUS EFIAPI AcpiSsdtHpetLibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
STATIC EFI_STATUS EFIAPI SsdtHpetUpdateTableInfo(IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, IN OUT AML_OBJECT_NODE_HANDLE ScopeNode)
STATIC EFI_STATUS EFIAPI BuildSsdtHpetTable(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)
STATIC CONST ACPI_TABLE_GENERATOR SsdtHpetGenerator
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
@ EStdAcpiTableIdSsdtHpet
SSDT HPET Generator.
void * AML_ROOT_NODE_HANDLE
Definition: AmlLib.h:51
EFI_STATUS EFIAPI AmlCodeGenDevice(IN CONST CHAR8 *NameString, IN AML_NODE_HANDLE ParentNode OPTIONAL, OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL)
EFI_STATUS EFIAPI AmlCodeGenNameResourceTemplate(IN CONST CHAR8 *NameString, IN AML_NODE_HANDLE ParentNode, OPTIONAL OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL)
EFI_STATUS EFIAPI AmlCodeGenScope(IN CONST CHAR8 *NameString, IN AML_NODE_HANDLE ParentNode OPTIONAL, OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL)
EFI_STATUS EFIAPI AmlCodeGenNameInteger(IN CONST CHAR8 *NameString, IN UINT64 Integer, IN AML_NODE_HANDLE ParentNode OPTIONAL, OUT AML_OBJECT_NODE_HANDLE *NewObjectNode OPTIONAL)
void * AML_OBJECT_NODE_HANDLE
Definition: AmlLib.h:55
EFI_STATUS EFIAPI AmlCodeGenRdMemory32Fixed(BOOLEAN IsReadWrite, UINT32 Address, UINT32 RangeLength, AML_OBJECT_NODE_HANDLE NameOpNode, AML_DATA_NODE_HANDLE *NewMemNode)
#define GET_OBJECT_LIST(CmObjectNameSpace, CmObjectId, Type)
@ EObjNameSpaceX64
X64 Objects Namespace.
VOID EFIAPI FreePool(IN VOID *Buffer)
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 FALSE
Definition: Base.h:307
#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 AddSsdtAcpiHeader(IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, IN CONST ACPI_TABLE_GENERATOR *CONST Generator, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, OUT AML_ROOT_NODE_HANDLE *RootNode)
Definition: TableHelper.c:221
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
@ EX64ObjHpetInfo
11 - HPET device info
EFI_STATUS EFIAPI AmlDeleteTree(IN AML_NODE_HANDLE Node)
EFI_STATUS EFIAPI AmlSerializeDefinitionBlock(IN AML_ROOT_NODE_HANDLE RootNode, OUT EFI_ACPI_DESCRIPTION_HEADER **Table)