]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/Acpi/AcpiSupportDxe/AcpiSupportAcpiSupportProtocol.c
Create PCDs in MdeModulePkg for ACPI table OEM_ID/OEM_TABLE_ID/OEM_REVISION/CREATOR_I...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / Acpi / AcpiSupportDxe / AcpiSupportAcpiSupportProtocol.c
1 /** @file
2 ACPI Support Protocol implementation
3
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
11
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
14
15 **/
16
17 //
18 // Includes
19 //
20 #include "AcpiSupport.h"
21 //
22 // The maximum number of tables that pre-allocated.
23 //
24 UINTN mEfiAcpiMaxNumTables = EFI_ACPI_MAX_NUM_TABLES;
25 /**
26 This function adds an ACPI table to the table list. It will detect FACS and
27 allocate the correct type of memory and properly align the table.
28
29 @param AcpiSupportInstance Instance of the protocol.
30 @param Table Table to add.
31 @param Checksum Does the table require checksumming.
32 @param Version The version of the list to add the table to.
33 @param Handle Pointer for returning the handle.
34
35 @return EFI_SUCCESS The function completed successfully.
36 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
37 @return EFI_ABORTED The table is a duplicate of a table that is required
38 to be unique.
39 **/
40 EFI_STATUS
41 AddTableToList (
42 IN EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance,
43 IN VOID *Table,
44 IN BOOLEAN Checksum,
45 IN EFI_ACPI_TABLE_VERSION Version,
46 OUT UINTN *Handle
47 );
48 /**
49 This function finds and removes the table specified by the handle.
50
51 @param AcpiSupportInstance Instance of the protocol.
52 @param Version Bitmask of which versions to remove.
53 @param Handle Table to remove.
54
55 @return EFI_SUCCESS The function completed successfully.
56 @return EFI_ABORTED An error occurred.
57 @return EFI_NOT_FOUND Handle not found in table list.
58 **/
59 EFI_STATUS
60 RemoveTableFromList (
61 IN EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance,
62 IN EFI_ACPI_TABLE_VERSION Version,
63 IN UINTN Handle
64 );
65 /**
66 This function calculates and updates an UINT8 checksum.
67
68 @param Buffer Pointer to buffer to checksum
69 @param Size Number of bytes to checksum
70 @param ChecksumOffset Offset to place the checksum result in
71
72 @return EFI_SUCCESS The function completed successfully.
73 **/
74 EFI_STATUS
75 AcpiPlatformChecksum (
76 IN VOID *Buffer,
77 IN UINTN Size,
78 IN UINTN ChecksumOffset
79 );
80 /**
81 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
82
83 @param AcpiSupportInstance Protocol instance private data.
84
85 @return EFI_SUCCESS The function completed successfully.
86
87 **/
88 EFI_STATUS
89 ChecksumCommonTables (
90 IN OUT EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance
91 );
92
93 /**
94 This function returns a table specified by an index if it exists.
95
96 The function returns a buffer containing the table that the caller must free.
97 The function also returns a handle used to identify the table for update or
98 deletion using the SetAcpiTable function.
99
100 @param This Instance of the protocol.
101 @param Index Zero-based index of the table to retrieve.
102 @param Table Returned pointer to the table.
103 @param Version Versions that the table is currently used in.
104 @param Handle Handle of the table, used in updating tables.
105
106 @retval EFI_SUCCESS The function completed successfully.
107 @retval EFI_NOT_FOUND The requested table does not exist.
108
109 **/
110 EFI_STATUS
111 EFIAPI
112 GetAcpiTable (
113 IN EFI_ACPI_SUPPORT_PROTOCOL *This,
114 IN INTN Index,
115 OUT VOID **Table,
116 OUT EFI_ACPI_TABLE_VERSION *Version,
117 OUT UINTN *Handle
118 )
119
120 {
121 EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance;
122 INTN TempIndex;
123 LIST_ENTRY *CurrentLink;
124 LIST_ENTRY *StartLink;
125 EFI_ACPI_TABLE_LIST *CurrentTable;
126
127 //
128 // Check for invalid input parameters
129 //
130 ASSERT (This);
131 ASSERT (Table);
132 ASSERT (Handle);
133
134 //
135 // Get the instance of the protocol
136 //
137 AcpiSupportInstance = EFI_ACPI_SUPPORT_INSTANCE_FROM_ACPI_SUPPORT_THIS (This);
138
139 //
140 // Find the table
141 //
142 CurrentLink = AcpiSupportInstance->TableList.ForwardLink;
143 StartLink = &AcpiSupportInstance->TableList;
144 for (TempIndex = 0; (TempIndex < Index) && (CurrentLink != StartLink) && (CurrentLink != NULL); TempIndex++) {
145 CurrentLink = CurrentLink->ForwardLink;
146 }
147
148 if (TempIndex != Index || CurrentLink == StartLink) {
149 return EFI_NOT_FOUND;
150 }
151 //
152 // Get handle and version
153 //
154 CurrentTable = EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink);
155 *Handle = CurrentTable->Handle;
156 *Version = CurrentTable->Version;
157
158 //
159 // Copy the table
160 //
161 *Table = AllocateCopyPool (CurrentTable->Table->Length, CurrentTable->Table);
162 ASSERT (*Table);
163
164 return EFI_SUCCESS;
165 }
166 /**
167 This function adds, removes, or updates ACPI tables. If the address is not
168 null and the handle value is null, the table is added. If both the address and
169 handle are not null, the table at handle is updated with the table at address.
170 If the address is null and the handle is not, the table at handle is deleted.
171
172 @param This Pointer of the protocol.
173 @param Table Pointer to a table.
174 @param Checksum Boolean indicating if the checksum should be calculated.
175 @param Version Version(s) to set.
176 @param Handle Handle of the table.
177
178 @return EFI_SUCCESS The function completed successfully.
179 @return EFI_INVALID_PARAMETER Both the Table and *Handle were NULL.
180 @return EFI_ABORTED Could not complete the desired request.
181
182 **/
183 EFI_STATUS
184 EFIAPI
185 SetAcpiTable (
186 IN EFI_ACPI_SUPPORT_PROTOCOL *This,
187 IN VOID *Table OPTIONAL,
188 IN BOOLEAN Checksum,
189 IN EFI_ACPI_TABLE_VERSION Version,
190 IN OUT UINTN *Handle
191 )
192 {
193 EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance;
194 UINTN SavedHandle;
195 EFI_STATUS Status;
196
197 //
198 // Check for invalid input parameters
199 //
200 ASSERT (This);
201 ASSERT (Handle != NULL);
202
203 //
204 // Get the instance of the protocol
205 //
206 AcpiSupportInstance = EFI_ACPI_SUPPORT_INSTANCE_FROM_ACPI_SUPPORT_THIS (This);
207
208 //
209 // Initialize locals
210 //
211 //
212 // Determine desired action
213 //
214 if (*Handle == 0) {
215 if (Table == NULL) {
216 //
217 // Invalid parameter combination
218 //
219 return EFI_INVALID_PARAMETER;
220 } else {
221 //
222 // Add table
223 //
224 Status = AddTableToList (AcpiSupportInstance, Table, Checksum, Version, Handle);
225 }
226 } else {
227 if (Table != NULL) {
228 //
229 // Update table
230 //
231 //
232 // Delete the table list entry
233 //
234 Status = RemoveTableFromList (AcpiSupportInstance, Version, *Handle);
235 if (EFI_ERROR (Status)) {
236 //
237 // Should not get an error here ever, but abort if we do.
238 //
239 return EFI_ABORTED;
240 }
241 //
242 // Set the handle to replace the table at the same handle
243 //
244 SavedHandle = AcpiSupportInstance->CurrentHandle;
245 AcpiSupportInstance->CurrentHandle = *Handle;
246
247 //
248 // Add the table
249 //
250 Status = AddTableToList (AcpiSupportInstance, Table, Checksum, Version, Handle);
251
252 //
253 // Restore the saved current handle
254 //
255 AcpiSupportInstance->CurrentHandle = SavedHandle;
256 } else {
257 //
258 // Delete table
259 //
260 Status = RemoveTableFromList (AcpiSupportInstance, Version, *Handle);
261 }
262 }
263
264 if (EFI_ERROR (Status)) {
265 //
266 // Should not get an error here ever, but abort if we do.
267 //
268 return EFI_ABORTED;
269 }
270 //
271 // Done
272 //
273 return EFI_SUCCESS;
274 }
275 /**
276 This function publishes the specified versions of the ACPI tables by
277 installing EFI configuration table entries for them. Any combination of
278 table versions can be published.
279
280 @param This Pointer of the protocol.
281 @param Version Version(s) to publish.
282
283 @return EFI_SUCCESS The function completed successfully.
284 @return EFI_ABORTED The function could not complete successfully.
285
286 **/
287 EFI_STATUS
288 EFIAPI
289 PublishTables (
290 IN EFI_ACPI_SUPPORT_PROTOCOL *This,
291 IN EFI_ACPI_TABLE_VERSION Version
292 )
293 {
294 EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance;
295 EFI_STATUS Status;
296 UINT32 *CurrentRsdtEntry;
297 VOID *CurrentXsdtEntry;
298 UINT64 Buffer64;
299
300 //
301 // Get the instance of the protocol
302 //
303 AcpiSupportInstance = EFI_ACPI_SUPPORT_INSTANCE_FROM_ACPI_SUPPORT_THIS (This);
304
305 //
306 // Reorder tables as some operating systems don't seem to find the
307 // FADT correctly if it is not in the first few entries
308 //
309
310 //
311 // Add FADT as the first entry
312 //
313 if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
314 CurrentRsdtEntry = (UINT32 *) ((UINT8 *) AcpiSupportInstance->Rsdt1 + sizeof (EFI_ACPI_DESCRIPTION_HEADER));
315 *CurrentRsdtEntry = (UINT32) (UINTN) AcpiSupportInstance->Fadt1;
316 }
317 if ((Version & EFI_ACPI_TABLE_VERSION_2_0) != 0 || (Version & EFI_ACPI_TABLE_VERSION_3_0) != 0) {
318 CurrentRsdtEntry = (UINT32 *) ((UINT8 *) AcpiSupportInstance->Rsdt3 + sizeof (EFI_ACPI_DESCRIPTION_HEADER));
319 *CurrentRsdtEntry = (UINT32) (UINTN) AcpiSupportInstance->Fadt3;
320 CurrentXsdtEntry = (VOID *) ((UINT8 *) AcpiSupportInstance->Xsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER));
321 //
322 // Add entry to XSDT, XSDT expects 64 bit pointers, but
323 // the table pointers in XSDT are not aligned on 8 byte boundary.
324 //
325 Buffer64 = (UINT64) (UINTN) AcpiSupportInstance->Fadt3;
326 CopyMem (
327 CurrentXsdtEntry,
328 &Buffer64,
329 sizeof (UINT64)
330 );
331 }
332
333 //
334 // Do checksum again because Dsdt/Xsdt is updated.
335 //
336 ChecksumCommonTables (AcpiSupportInstance);
337
338 //
339 // Add the RSD_PTR to the system table and store that we have installed the
340 // tables.
341 //
342 if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0 && !AcpiSupportInstance->TablesInstalled1) {
343 Status = gBS->InstallConfigurationTable (&gEfiAcpi10TableGuid, AcpiSupportInstance->Rsdp1);
344 if (EFI_ERROR (Status)) {
345 return EFI_ABORTED;
346 }
347
348 AcpiSupportInstance->TablesInstalled1 = TRUE;
349 }
350
351 if (((Version & EFI_ACPI_TABLE_VERSION_2_0) != 0 || (Version & EFI_ACPI_TABLE_VERSION_3_0) != 0) &&
352 !AcpiSupportInstance->TablesInstalled3) {
353 Status = gBS->InstallConfigurationTable (&gEfiAcpiTableGuid, AcpiSupportInstance->Rsdp3);
354 if (EFI_ERROR (Status)) {
355 return EFI_ABORTED;
356 }
357
358 AcpiSupportInstance->TablesInstalled3= TRUE;
359 }
360
361 return EFI_SUCCESS;
362 }
363 /**
364 Installs an ACPI table into the RSDT/XSDT.
365 Note that the ACPI table should be checksumed before installing it.
366 Otherwise it will assert.
367
368 @param This Protocol instance pointer.
369 @param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
370 @param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
371 @param TableKey Reurns a key to refer to the ACPI table.
372
373 @return EFI_SUCCESS The table was successfully inserted.
374 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
375 and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
376 are not in sync.
377 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
378
379 **/
380 EFI_STATUS
381 EFIAPI
382 InstallAcpiTable (
383 IN EFI_ACPI_TABLE_PROTOCOL *This,
384 IN VOID *AcpiTableBuffer,
385 IN UINTN AcpiTableBufferSize,
386 OUT UINTN *TableKey
387 )
388 {
389 EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance;
390 EFI_ACPI_SUPPORT_PROTOCOL *AcpiSupport;
391 EFI_STATUS Status;
392 VOID *AcpiTableBufferConst;
393
394 //
395 // Check for invalid input parameters
396 //
397 if ((AcpiTableBuffer == NULL) || (TableKey == NULL)
398 || (((EFI_ACPI_DESCRIPTION_HEADER *) AcpiTableBuffer)->Length != AcpiTableBufferSize)) {
399 return EFI_INVALID_PARAMETER;
400 }
401
402 //
403 // Get the instance of the ACPI support protocol
404 //
405 AcpiSupportInstance = EFI_ACPI_TABLE_INSTANCE_FROM_ACPI_SUPPORT_THIS (This);
406 AcpiSupport = &AcpiSupportInstance->AcpiSupport;
407
408 //
409 // Install the ACPI table by using ACPI support protocol
410 //
411 AcpiTableBufferConst = AllocateCopyPool (AcpiTableBufferSize, AcpiTableBuffer);
412 *TableKey = 0;
413 Status = AcpiSupport->SetAcpiTable (
414 AcpiSupport,
415 AcpiTableBufferConst,
416 TRUE,
417 EFI_ACPI_TABLE_VERSION_1_0B | EFI_ACPI_TABLE_VERSION_2_0 | EFI_ACPI_TABLE_VERSION_3_0,
418 TableKey
419 );
420 if (!EFI_ERROR (Status)) {
421 Status = AcpiSupport->PublishTables (
422 AcpiSupport,
423 EFI_ACPI_TABLE_VERSION_1_0B | EFI_ACPI_TABLE_VERSION_2_0 | EFI_ACPI_TABLE_VERSION_3_0
424 );
425 }
426 FreePool (AcpiTableBufferConst);
427
428 return Status;
429 }
430 /**
431 Removes an ACPI table from the RSDT/XSDT.
432
433 @param This Protocol instance pointer.
434 @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
435
436 @return EFI_SUCCESS The table was successfully uninstalled.
437 @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
438
439 **/
440 EFI_STATUS
441 EFIAPI
442 UninstallAcpiTable (
443 IN EFI_ACPI_TABLE_PROTOCOL *This,
444 IN UINTN TableKey
445 )
446 {
447 EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance;
448 EFI_ACPI_SUPPORT_PROTOCOL *AcpiSupport;
449 EFI_STATUS Status;
450
451 //
452 // Get the instance of the ACPI support protocol
453 //
454 AcpiSupportInstance = EFI_ACPI_TABLE_INSTANCE_FROM_ACPI_SUPPORT_THIS (This);
455 AcpiSupport = &AcpiSupportInstance->AcpiSupport;
456
457 //
458 // Uninstall the ACPI table by using ACPI support protocol
459 //
460 Status = AcpiSupport->SetAcpiTable (
461 AcpiSupport,
462 NULL,
463 FALSE,
464 EFI_ACPI_TABLE_VERSION_1_0B | EFI_ACPI_TABLE_VERSION_2_0 | EFI_ACPI_TABLE_VERSION_3_0,
465 &TableKey
466 );
467 if (!EFI_ERROR (Status)) {
468 Status = AcpiSupport->PublishTables (
469 AcpiSupport,
470 EFI_ACPI_TABLE_VERSION_1_0B | EFI_ACPI_TABLE_VERSION_2_0 | EFI_ACPI_TABLE_VERSION_3_0
471 );
472 }
473
474 if (EFI_ERROR (Status)) {
475 return EFI_NOT_FOUND;
476 } else {
477 return EFI_SUCCESS;
478 }
479 }
480 /**
481 If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
482
483 @param AcpiSupportInstance ACPI support protocol instance data structure
484
485 @return EFI_SUCCESS reallocate the table beffer successfully.
486 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
487
488 **/
489 EFI_STATUS
490 ReallocateAcpiTableBuffer (
491 IN EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance
492 )
493 {
494 UINTN NewMaxTableNumber;
495 UINTN TotalSize;
496 UINT8 *Pointer;
497 EFI_PHYSICAL_ADDRESS PageAddress;
498 EFI_ACPI_SUPPORT_INSTANCE TempPrivateData;
499 EFI_STATUS Status;
500 UINT64 CurrentData;
501
502 CopyMem (&TempPrivateData, AcpiSupportInstance, sizeof (EFI_ACPI_SUPPORT_INSTANCE));
503 //
504 // Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
505 //
506 NewMaxTableNumber = mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES;
507 //
508 // Create RSDT, XSDT structures and allocate buffers.
509 //
510 TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 1.0 RSDT
511 NewMaxTableNumber * sizeof (UINT32) +
512 sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 RSDT
513 NewMaxTableNumber * sizeof (UINT32) +
514 sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 XSDT
515 NewMaxTableNumber * sizeof (UINT64);
516
517 //
518 // Allocate memory in the lower 32 bit of address range for
519 // compatibility with ACPI 1.0 OS.
520 //
521 // This is done because ACPI 1.0 pointers are 32 bit values.
522 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
523 // There is no architectural reason these should be below 4GB, it is purely
524 // for convenience of implementation that we force memory below 4GB.
525 //
526 PageAddress = 0xFFFFFFFF;
527 Status = gBS->AllocatePages (
528 AllocateMaxAddress,
529 EfiACPIReclaimMemory,
530 EFI_SIZE_TO_PAGES (TotalSize),
531 &PageAddress
532 );
533
534 if (EFI_ERROR (Status)) {
535 return EFI_OUT_OF_RESOURCES;
536 }
537
538 Pointer = (UINT8 *) (UINTN) PageAddress;
539 ZeroMem (Pointer, TotalSize);
540
541 AcpiSupportInstance->Rsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *) Pointer;
542 Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + NewMaxTableNumber * sizeof (UINT32));
543 AcpiSupportInstance->Rsdt3 = (EFI_ACPI_DESCRIPTION_HEADER *) Pointer;
544 Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + NewMaxTableNumber * sizeof (UINT32));
545 AcpiSupportInstance->Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *) Pointer;
546
547 //
548 // Update RSDP to point to the new Rsdt and Xsdt address.
549 //
550 AcpiSupportInstance->Rsdp1->RsdtAddress = (UINT32) (UINTN) AcpiSupportInstance->Rsdt1;
551 AcpiSupportInstance->Rsdp3->RsdtAddress = (UINT32) (UINTN) AcpiSupportInstance->Rsdt3;
552 CurrentData = (UINT64) (UINTN) AcpiSupportInstance->Xsdt;
553 CopyMem (&AcpiSupportInstance->Rsdp3->XsdtAddress, &CurrentData, sizeof (UINT64));
554
555 //
556 // copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
557 //
558 CopyMem (AcpiSupportInstance->Rsdt1, TempPrivateData.Rsdt1, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT32)));
559 CopyMem (AcpiSupportInstance->Rsdt3, TempPrivateData.Rsdt3, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT32)));
560 CopyMem (AcpiSupportInstance->Xsdt, TempPrivateData.Xsdt, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT64)));
561
562 //
563 // Calculate orignal ACPI table buffer size
564 //
565 TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 1.0 RSDT
566 mEfiAcpiMaxNumTables * sizeof (UINT32) +
567 sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 RSDT
568 mEfiAcpiMaxNumTables * sizeof (UINT32) +
569 sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 XSDT
570 mEfiAcpiMaxNumTables * sizeof (UINT64);
571 gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)TempPrivateData.Rsdt1, EFI_SIZE_TO_PAGES (TotalSize));
572
573 //
574 // Update the Max ACPI table number
575 //
576 mEfiAcpiMaxNumTables = NewMaxTableNumber;
577 return EFI_SUCCESS;
578 }
579 /**
580 This function adds an ACPI table to the table list. It will detect FACS and
581 allocate the correct type of memory and properly align the table.
582
583 @param AcpiSupportInstance Instance of the protocol.
584 @param Table Table to add.
585 @param Checksum Does the table require checksumming.
586 @param Version The version of the list to add the table to.
587 @param Handle Pointer for returning the handle.
588
589 @return EFI_SUCCESS The function completed successfully.
590 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
591 @return EFI_ABORTED The table is a duplicate of a table that is required
592 to be unique.
593 **/
594 EFI_STATUS
595 AddTableToList (
596 IN EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance,
597 IN VOID *Table,
598 IN BOOLEAN Checksum,
599 IN EFI_ACPI_TABLE_VERSION Version,
600 OUT UINTN *Handle
601 )
602 {
603 EFI_STATUS Status;
604 EFI_ACPI_TABLE_LIST *CurrentTableList;
605 UINT32 CurrentTableSignature;
606 UINT32 CurrentTableSize;
607 UINT32 *CurrentRsdtEntry;
608 VOID *CurrentXsdtEntry;
609 UINT64 Buffer64;
610 BOOLEAN AddToRsdt;
611
612 //
613 // Check for invalid input parameters
614 //
615 ASSERT (AcpiSupportInstance);
616 ASSERT (Table);
617 ASSERT (Handle);
618
619 //
620 // Init locals
621 //
622 AddToRsdt = TRUE;
623
624 //
625 // Create a new list entry
626 //
627 CurrentTableList = AllocatePool (sizeof (EFI_ACPI_TABLE_LIST));
628 ASSERT (CurrentTableList);
629
630 //
631 // Determine table type and size
632 //
633 CurrentTableSignature = ((EFI_ACPI_COMMON_HEADER *) Table)->Signature;
634 CurrentTableSize = ((EFI_ACPI_COMMON_HEADER *) Table)->Length;
635
636 //
637 // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
638 // for backwards compatibility with ACPI 1.0 OS.
639 //
640 // This is done because ACPI 1.0 pointers are 32 bit values.
641 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
642 // There is no architectural reason these should be below 4GB, it is purely
643 // for convenience of implementation that we force memory below 4GB.
644 //
645 CurrentTableList->PageAddress = 0xFFFFFFFF;
646 CurrentTableList->NumberOfPages = EFI_SIZE_TO_PAGES (CurrentTableSize);
647
648 //
649 // Allocation memory type depends on the type of the table
650 //
651 if ((CurrentTableSignature == EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) ||
652 (CurrentTableSignature == EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE)) {
653 //
654 // Allocate memory for the FACS. This structure must be aligned
655 // on a 64 byte boundary and must be ACPI NVS memory.
656 // Using AllocatePages should ensure that it is always aligned.
657 // Do not change signature for new ACPI version because they are same.
658 //
659 // UEFI table also need to be in ACPI NVS memory, because some data field
660 // could be updated by OS present agent. For example, BufferPtrAddress in
661 // SMM communication ACPI table.
662 //
663 ASSERT ((EFI_PAGE_SIZE % 64) == 0);
664 Status = gBS->AllocatePages (
665 AllocateMaxAddress,
666 EfiACPIMemoryNVS,
667 CurrentTableList->NumberOfPages,
668 &CurrentTableList->PageAddress
669 );
670 } else {
671 //
672 // All other tables are ACPI reclaim memory, no alignment requirements.
673 //
674 Status = gBS->AllocatePages (
675 AllocateMaxAddress,
676 EfiACPIReclaimMemory,
677 CurrentTableList->NumberOfPages,
678 &CurrentTableList->PageAddress
679 );
680 }
681 //
682 // Check return value from memory alloc.
683 //
684 if (EFI_ERROR (Status)) {
685 gBS->FreePool (CurrentTableList);
686 return EFI_OUT_OF_RESOURCES;
687 }
688 //
689 // Update the table pointer with the allocated memory start
690 //
691 CurrentTableList->Table = (EFI_ACPI_COMMON_HEADER *) (UINTN) CurrentTableList->PageAddress;
692
693 //
694 // Initialize the table contents
695 //
696 CurrentTableList->Signature = EFI_ACPI_TABLE_LIST_SIGNATURE;
697 CopyMem (CurrentTableList->Table, Table, CurrentTableSize);
698 CurrentTableList->Handle = AcpiSupportInstance->CurrentHandle++;
699 *Handle = CurrentTableList->Handle;
700 CurrentTableList->Version = Version;
701
702 //
703 // Update internal pointers if this is a required table. If it is a required
704 // table and a table of that type already exists, return an error.
705 //
706 // Calculate the checksum if the table is not FACS.
707 //
708 switch (CurrentTableSignature) {
709
710 case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE:
711 //
712 // We don't add the FADT in the standard way because some
713 // OS expect the FADT to be early in the table list.
714 // So we always add it as the first element in the list.
715 //
716 AddToRsdt = FALSE;
717
718 //
719 // Check that the table has not been previously added.
720 //
721 if (((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0 && AcpiSupportInstance->Fadt1 != NULL) ||
722 ((Version & EFI_ACPI_TABLE_VERSION_2_0) != 0 && AcpiSupportInstance->Fadt3 != NULL) ||
723 ((Version & EFI_ACPI_TABLE_VERSION_3_0) != 0 && AcpiSupportInstance->Fadt3 != NULL)
724 ) {
725 gBS->FreePages (CurrentTableList->PageAddress, CurrentTableList->NumberOfPages);
726 gBS->FreePool (CurrentTableList);
727 return EFI_ABORTED;
728 }
729 //
730 // Add the table to the appropriate table version
731 //
732 if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
733 //
734 // Save a pointer to the table
735 //
736 AcpiSupportInstance->Fadt1 = (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE *) CurrentTableList->Table;
737
738 //
739 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
740 //
741 AcpiSupportInstance->Fadt1->FirmwareCtrl = (UINT32) (UINTN) AcpiSupportInstance->Facs1;
742 AcpiSupportInstance->Fadt1->Dsdt = (UINT32) (UINTN) AcpiSupportInstance->Dsdt1;
743
744 //
745 // RSDP OEM information is updated to match the FADT OEM information
746 //
747 CopyMem (
748 &AcpiSupportInstance->Rsdp1->OemId,
749 &AcpiSupportInstance->Fadt1->Header.OemId,
750 6
751 );
752
753 //
754 // RSDT OEM information is updated to match the FADT OEM information.
755 //
756 CopyMem (
757 &AcpiSupportInstance->Rsdt1->OemId,
758 &AcpiSupportInstance->Fadt1->Header.OemId,
759 6
760 );
761
762 CopyMem (
763 &AcpiSupportInstance->Rsdt1->OemTableId,
764 &AcpiSupportInstance->Fadt1->Header.OemTableId,
765 sizeof (UINT64)
766 );
767 AcpiSupportInstance->Rsdt1->OemRevision = AcpiSupportInstance->Fadt1->Header.OemRevision;
768 }
769
770 if ((Version & EFI_ACPI_TABLE_VERSION_2_0) != 0 ||
771 (Version & EFI_ACPI_TABLE_VERSION_3_0) != 0) {
772 //
773 // Save a pointer to the table
774 //
775 AcpiSupportInstance->Fadt3 = (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *) CurrentTableList->Table;
776
777 //
778 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
779 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
780 // vice-versa.
781 //
782 if ((UINT64)(UINTN)AcpiSupportInstance->Facs3 < BASE_4GB) {
783 AcpiSupportInstance->Fadt3->FirmwareCtrl = (UINT32) (UINTN) AcpiSupportInstance->Facs3;
784 ZeroMem (
785 &AcpiSupportInstance->Fadt3->XFirmwareCtrl,
786 sizeof (UINT64)
787 );
788 } else {
789 AcpiSupportInstance->Fadt3->FirmwareCtrl = 0;
790 Buffer64 = (UINT64) (UINTN) AcpiSupportInstance->Facs3;
791 CopyMem (
792 &AcpiSupportInstance->Fadt3->XFirmwareCtrl,
793 &Buffer64,
794 sizeof (UINT64)
795 );
796 }
797 AcpiSupportInstance->Fadt3->Dsdt = (UINT32) (UINTN) AcpiSupportInstance->Dsdt3;
798 Buffer64 = (UINT64) (UINTN) AcpiSupportInstance->Dsdt3;
799 CopyMem (
800 &AcpiSupportInstance->Fadt3->XDsdt,
801 &Buffer64,
802 sizeof (UINT64)
803 );
804
805 //
806 // RSDP OEM information is updated to match the FADT OEM information
807 //
808 CopyMem (
809 &AcpiSupportInstance->Rsdp3->OemId,
810 &AcpiSupportInstance->Fadt3->Header.OemId,
811 6
812 );
813
814 //
815 // RSDT OEM information is updated to match FADT OEM information.
816 //
817 CopyMem (
818 &AcpiSupportInstance->Rsdt3->OemId,
819 &AcpiSupportInstance->Fadt3->Header.OemId,
820 6
821 );
822 CopyMem (
823 &AcpiSupportInstance->Rsdt3->OemTableId,
824 &AcpiSupportInstance->Fadt3->Header.OemTableId,
825 sizeof (UINT64)
826 );
827 AcpiSupportInstance->Rsdt3->OemRevision = AcpiSupportInstance->Fadt3->Header.OemRevision;
828
829 //
830 // XSDT OEM information is updated to match FADT OEM information.
831 //
832 CopyMem (
833 &AcpiSupportInstance->Xsdt->OemId,
834 &AcpiSupportInstance->Fadt3->Header.OemId,
835 6
836 );
837 CopyMem (
838 &AcpiSupportInstance->Xsdt->OemTableId,
839 &AcpiSupportInstance->Fadt3->Header.OemTableId,
840 sizeof (UINT64)
841 );
842 AcpiSupportInstance->Xsdt->OemRevision = AcpiSupportInstance->Fadt3->Header.OemRevision;
843 }
844
845 //
846 // Checksum the table
847 //
848 if (Checksum) {
849 AcpiPlatformChecksum (
850 CurrentTableList->Table,
851 CurrentTableList->Table->Length,
852 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
853 Checksum)
854 );
855 }
856 break;
857
858 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE:
859 //
860 // Check that the table has not been previously added.
861 //
862 if (((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0 && AcpiSupportInstance->Facs1 != NULL) ||
863 ((Version & EFI_ACPI_TABLE_VERSION_2_0) != 0 && AcpiSupportInstance->Facs3 != NULL) ||
864 ((Version & EFI_ACPI_TABLE_VERSION_3_0) != 0 && AcpiSupportInstance->Facs3 != NULL)
865 ) {
866 gBS->FreePages (CurrentTableList->PageAddress, CurrentTableList->NumberOfPages);
867 gBS->FreePool (CurrentTableList);
868 return EFI_ABORTED;
869 }
870 //
871 // FACS is referenced by FADT and is not part of RSDT
872 //
873 AddToRsdt = FALSE;
874
875 //
876 // Add the table to the appropriate table version
877 //
878 if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
879 //
880 // Save a pointer to the table
881 //
882 AcpiSupportInstance->Facs1 = (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *) CurrentTableList->Table;
883
884 //
885 // If FADT already exists, update table pointers.
886 //
887 if (AcpiSupportInstance->Fadt1 != NULL) {
888 AcpiSupportInstance->Fadt1->FirmwareCtrl = (UINT32) (UINTN) AcpiSupportInstance->Facs1;
889
890 //
891 // Checksum FADT table
892 //
893 AcpiPlatformChecksum (
894 AcpiSupportInstance->Fadt1,
895 AcpiSupportInstance->Fadt1->Header.Length,
896 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
897 Checksum)
898 );
899 }
900 }
901
902 if ((Version & EFI_ACPI_TABLE_VERSION_2_0) != 0 ||
903 (Version & EFI_ACPI_TABLE_VERSION_3_0) != 0) {
904 //
905 // Save a pointer to the table
906 //
907 AcpiSupportInstance->Facs3 = (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *) CurrentTableList->Table;
908
909 //
910 // If FADT already exists, update table pointers.
911 //
912 if (AcpiSupportInstance->Fadt3 != NULL) {
913 //
914 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
915 // vice-versa.
916 //
917 if ((UINT64)(UINTN)AcpiSupportInstance->Facs3 < BASE_4GB) {
918 AcpiSupportInstance->Fadt3->FirmwareCtrl = (UINT32) (UINTN) AcpiSupportInstance->Facs3;
919 } else {
920 Buffer64 = (UINT64) (UINTN) AcpiSupportInstance->Facs3;
921 CopyMem (
922 &AcpiSupportInstance->Fadt3->XFirmwareCtrl,
923 &Buffer64,
924 sizeof (UINT64)
925 );
926 }
927
928 //
929 // Checksum FADT table
930 //
931 AcpiPlatformChecksum (
932 AcpiSupportInstance->Fadt3,
933 AcpiSupportInstance->Fadt3->Header.Length,
934 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
935 Checksum)
936 );
937 }
938 }
939
940 break;
941
942 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE:
943 //
944 // Check that the table has not been previously added.
945 //
946 if (((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0 && AcpiSupportInstance->Dsdt1 != NULL) ||
947 ((Version & EFI_ACPI_TABLE_VERSION_2_0) != 0 && AcpiSupportInstance->Dsdt3 != NULL) ||
948 ((Version & EFI_ACPI_TABLE_VERSION_3_0) != 0 && AcpiSupportInstance->Dsdt3 != NULL)
949 ) {
950 gBS->FreePages (CurrentTableList->PageAddress, CurrentTableList->NumberOfPages);
951 gBS->FreePool (CurrentTableList);
952 return EFI_ABORTED;
953 }
954 //
955 // DSDT is referenced by FADT and is not part of RSDT
956 //
957 AddToRsdt = FALSE;
958
959 //
960 // Add the table to the appropriate table version
961 //
962 if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
963 //
964 // Save a pointer to the table
965 //
966 AcpiSupportInstance->Dsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *) CurrentTableList->Table;
967
968 //
969 // If FADT already exists, update table pointers.
970 //
971 if (AcpiSupportInstance->Fadt1 != NULL) {
972 AcpiSupportInstance->Fadt1->Dsdt = (UINT32) (UINTN) AcpiSupportInstance->Dsdt1;
973
974 //
975 // Checksum FADT table
976 //
977 AcpiPlatformChecksum (
978 AcpiSupportInstance->Fadt1,
979 AcpiSupportInstance->Fadt1->Header.Length,
980 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
981 Checksum)
982 );
983 }
984 }
985
986 if ((Version & EFI_ACPI_TABLE_VERSION_2_0) != 0 ||
987 (Version & EFI_ACPI_TABLE_VERSION_3_0) != 0) {
988 //
989 // Save a pointer to the table
990 //
991 AcpiSupportInstance->Dsdt3 = (EFI_ACPI_DESCRIPTION_HEADER *) CurrentTableList->Table;
992
993 //
994 // If FADT already exists, update table pointers.
995 //
996 if (AcpiSupportInstance->Fadt3 != NULL) {
997 AcpiSupportInstance->Fadt3->Dsdt = (UINT32) (UINTN) AcpiSupportInstance->Dsdt3;
998 Buffer64 = (UINT64) (UINTN) AcpiSupportInstance->Dsdt3;
999 CopyMem (
1000 &AcpiSupportInstance->Fadt3->XDsdt,
1001 &Buffer64,
1002 sizeof (UINT64)
1003 );
1004
1005 //
1006 // Checksum FADT table
1007 //
1008 AcpiPlatformChecksum (
1009 AcpiSupportInstance->Fadt3,
1010 AcpiSupportInstance->Fadt3->Header.Length,
1011 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
1012 Checksum)
1013 );
1014 }
1015 }
1016 //
1017 // Checksum the table
1018 //
1019 if (Checksum) {
1020 AcpiPlatformChecksum (
1021 CurrentTableList->Table,
1022 CurrentTableList->Table->Length,
1023 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
1024 Checksum)
1025 );
1026 }
1027 break;
1028
1029 default:
1030 //
1031 // Checksum the table
1032 //
1033 if (Checksum) {
1034 AcpiPlatformChecksum (
1035 CurrentTableList->Table,
1036 CurrentTableList->Table->Length,
1037 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
1038 Checksum)
1039 );
1040 }
1041 break;
1042 }
1043 //
1044 // Add the table to the current list of tables
1045 //
1046 InsertTailList (&AcpiSupportInstance->TableList, &CurrentTableList->Link);
1047
1048 //
1049 // Add the table to RSDT and/or XSDT table entry lists.
1050 //
1051 //
1052 // Add to ACPI 1.0b table tree
1053 //
1054 if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
1055 if (AddToRsdt) {
1056 //
1057 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
1058 //
1059 if (AcpiSupportInstance->NumberOfTableEntries1 >= mEfiAcpiMaxNumTables) {
1060 Status = ReallocateAcpiTableBuffer (AcpiSupportInstance);
1061 ASSERT_EFI_ERROR (Status);
1062 }
1063 CurrentRsdtEntry = (UINT32 *)
1064 (
1065 (UINT8 *) AcpiSupportInstance->Rsdt1 +
1066 sizeof (EFI_ACPI_DESCRIPTION_HEADER) +
1067 AcpiSupportInstance->NumberOfTableEntries1 *
1068 sizeof (UINT32)
1069 );
1070
1071 //
1072 // Add entry to the RSDT unless its the FACS or DSDT
1073 //
1074 *CurrentRsdtEntry = (UINT32) (UINTN) CurrentTableList->Table;
1075
1076 //
1077 // Update RSDT length
1078 //
1079 AcpiSupportInstance->Rsdt1->Length = AcpiSupportInstance->Rsdt1->Length + sizeof (UINT32);
1080
1081 AcpiSupportInstance->NumberOfTableEntries1++;
1082 }
1083 }
1084 //
1085 // Add to ACPI 2.0/3.0 table tree
1086 //
1087 if ((Version & EFI_ACPI_TABLE_VERSION_2_0) != 0 || (Version & EFI_ACPI_TABLE_VERSION_3_0) != 0) {
1088 if (AddToRsdt) {
1089 //
1090 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
1091 //
1092 if (AcpiSupportInstance->NumberOfTableEntries3 >= mEfiAcpiMaxNumTables) {
1093 Status = ReallocateAcpiTableBuffer (AcpiSupportInstance);
1094 ASSERT_EFI_ERROR (Status);
1095 }
1096 //
1097 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1098 // If it becomes necessary to maintain separate table lists, changes will be required.
1099 //
1100 CurrentRsdtEntry = (UINT32 *)
1101 (
1102 (UINT8 *) AcpiSupportInstance->Rsdt3 +
1103 sizeof (EFI_ACPI_DESCRIPTION_HEADER) +
1104 AcpiSupportInstance->NumberOfTableEntries3 *
1105 sizeof (UINT32)
1106 );
1107
1108 //
1109 // This pointer must not be directly dereferenced as the XSDT entries may not
1110 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1111 //
1112 CurrentXsdtEntry = (VOID *)
1113 (
1114 (UINT8 *) AcpiSupportInstance->Xsdt +
1115 sizeof (EFI_ACPI_DESCRIPTION_HEADER) +
1116 AcpiSupportInstance->NumberOfTableEntries3 *
1117 sizeof (UINT64)
1118 );
1119
1120 //
1121 // Add entry to the RSDT
1122 //
1123 *CurrentRsdtEntry = (UINT32) (UINTN) CurrentTableList->Table;
1124
1125 //
1126 // Update RSDT length
1127 //
1128 AcpiSupportInstance->Rsdt3->Length = AcpiSupportInstance->Rsdt3->Length + sizeof (UINT32);
1129
1130 //
1131 // Add entry to XSDT, XSDT expects 64 bit pointers, but
1132 // the table pointers in XSDT are not aligned on 8 byte boundary.
1133 //
1134 Buffer64 = (UINT64) (UINTN) CurrentTableList->Table;
1135 CopyMem (
1136 CurrentXsdtEntry,
1137 &Buffer64,
1138 sizeof (UINT64)
1139 );
1140
1141 //
1142 // Update length
1143 //
1144 AcpiSupportInstance->Xsdt->Length = AcpiSupportInstance->Xsdt->Length + sizeof (UINT64);
1145
1146 AcpiSupportInstance->NumberOfTableEntries3++;
1147 }
1148 }
1149
1150 ChecksumCommonTables (AcpiSupportInstance);
1151 return EFI_SUCCESS;
1152 }
1153 /**
1154 This function finds the table specified by the handle and returns a pointer to it.
1155 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
1156 undefined.
1157
1158 @param Handle Table to find.
1159 @param TableList Table list to search
1160 @param Table Pointer to table found.
1161
1162 @return EFI_SUCCESS The function completed successfully.
1163 @return EFI_NOT_FOUND No table found matching the handle specified.
1164
1165 **/
1166 EFI_STATUS
1167 FindTableByHandle (
1168 IN UINTN Handle,
1169 IN LIST_ENTRY *TableList,
1170 OUT EFI_ACPI_TABLE_LIST **Table
1171 )
1172 {
1173 LIST_ENTRY *CurrentLink;
1174 EFI_ACPI_TABLE_LIST *CurrentTable;
1175
1176 //
1177 // Check for invalid input parameters
1178 //
1179 ASSERT (Table);
1180
1181 //
1182 // Find the table
1183 //
1184 CurrentLink = TableList->ForwardLink;
1185
1186 while (CurrentLink != TableList) {
1187 CurrentTable = EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink);
1188 if (CurrentTable->Handle == Handle) {
1189 //
1190 // Found handle, so return this table.
1191 //
1192 *Table = CurrentTable;
1193 return EFI_SUCCESS;
1194 }
1195
1196 CurrentLink = CurrentLink->ForwardLink;
1197 }
1198 //
1199 // Table not found
1200 //
1201 return EFI_NOT_FOUND;
1202 }
1203 /**
1204 This function removes a basic table from the RSDT and/or XSDT.
1205 For Acpi 1.0 tables, pass in the Rsdt.
1206 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1207
1208 @param Table Pointer to table found.
1209 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1210 @param Rsdt Pointer to the RSDT to remove from
1211 @param Xsdt Pointer to the Xsdt to remove from
1212
1213 @return EFI_SUCCESS The function completed successfully.
1214 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1215
1216 **/
1217 EFI_STATUS
1218 RemoveTableFromRsdt (
1219 IN OUT EFI_ACPI_TABLE_LIST * Table,
1220 IN OUT UINTN *NumberOfTableEntries,
1221 IN OUT EFI_ACPI_DESCRIPTION_HEADER * Rsdt,
1222 IN OUT EFI_ACPI_DESCRIPTION_HEADER * Xsdt OPTIONAL
1223 )
1224 {
1225 UINT32 *CurrentRsdtEntry;
1226 VOID *CurrentXsdtEntry;
1227 UINT64 CurrentTablePointer64;
1228 UINTN TempIndex;
1229
1230 //
1231 // Check for invalid input parameters
1232 //
1233 ASSERT (Table);
1234 ASSERT (NumberOfTableEntries);
1235 ASSERT (Rsdt);
1236
1237 //
1238 // Find the table entry in the RSDT and XSDT
1239 //
1240 for (TempIndex = 0; TempIndex < *NumberOfTableEntries; TempIndex++) {
1241 //
1242 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1243 // If it becomes necessary to maintain separate table lists, changes will be required.
1244 //
1245 CurrentRsdtEntry = (UINT32 *) ((UINT8 *) Rsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + TempIndex * sizeof (UINT32));
1246 if (Xsdt != NULL) {
1247 //
1248 // This pointer must not be directly dereferenced as the XSDT entries may not
1249 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1250 //
1251 CurrentXsdtEntry = (VOID *) ((UINT8 *) Xsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + TempIndex * sizeof (UINT64));
1252
1253 //
1254 // Read the entry value out of the XSDT
1255 //
1256 CopyMem (&CurrentTablePointer64, CurrentXsdtEntry, sizeof (UINT64));
1257 } else {
1258 //
1259 // Initialize to NULL
1260 //
1261 CurrentXsdtEntry = 0;
1262 CurrentTablePointer64 = 0;
1263 }
1264 //
1265 // Check if we have found the corresponding entry in both RSDT and XSDT
1266 //
1267 if (*CurrentRsdtEntry == (UINT32) (UINTN) Table->Table &&
1268 ((Xsdt == NULL) || CurrentTablePointer64 == (UINT64) (UINTN) Table->Table)
1269 ) {
1270 //
1271 // Found entry, so copy all following entries and shrink table
1272 // We actually copy all + 1 to copy the initialized value of memory over
1273 // the last entry.
1274 //
1275 CopyMem (CurrentRsdtEntry, CurrentRsdtEntry + 1, (*NumberOfTableEntries - TempIndex) * sizeof (UINT32));
1276 Rsdt->Length = Rsdt->Length - sizeof (UINT32);
1277 if (Xsdt != NULL) {
1278 CopyMem (CurrentXsdtEntry, ((UINT64 *) CurrentXsdtEntry) + 1, (*NumberOfTableEntries - TempIndex) * sizeof (UINT64));
1279 Xsdt->Length = Xsdt->Length - sizeof (UINT64);
1280 }
1281 break;
1282 } else if (TempIndex + 1 == *NumberOfTableEntries) {
1283 //
1284 // At the last entry, and table not found
1285 //
1286 return EFI_INVALID_PARAMETER;
1287 }
1288 }
1289 //
1290 // Checksum the tables
1291 //
1292 AcpiPlatformChecksum (
1293 Rsdt,
1294 Rsdt->Length,
1295 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
1296 Checksum)
1297 );
1298
1299 if (Xsdt != NULL) {
1300 AcpiPlatformChecksum (
1301 Xsdt,
1302 Xsdt->Length,
1303 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
1304 Checksum)
1305 );
1306 }
1307 //
1308 // Decrement the number of tables
1309 //
1310 (*NumberOfTableEntries)--;
1311
1312 return EFI_SUCCESS;
1313 }
1314 /**
1315 This function removes a table and frees any associated memory.
1316
1317 @param AcpiSupportInstance Instance of the protocol.
1318 @param Version Version(s) to delete.
1319 @param Table Pointer to table found.
1320
1321 @return EFI_SUCCESS The function completed successfully.
1322
1323 **/
1324 EFI_STATUS
1325 DeleteTable (
1326 IN EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance,
1327 IN EFI_ACPI_TABLE_VERSION Version,
1328 IN OUT EFI_ACPI_TABLE_LIST *Table
1329 )
1330 {
1331 UINT32 CurrentTableSignature;
1332 BOOLEAN RemoveFromRsdt;
1333
1334 //
1335 // Check for invalid input parameters
1336 //
1337 ASSERT (AcpiSupportInstance);
1338 ASSERT (Table);
1339
1340 //
1341 // Init locals
1342 //
1343 RemoveFromRsdt = TRUE;
1344
1345 if (Table->Table != NULL) {
1346 CurrentTableSignature = ((EFI_ACPI_COMMON_HEADER *) Table->Table)->Signature;
1347
1348 //
1349 // Basic tasks to accomplish delete are:
1350 // Determine removal requirements (in RSDT/XSDT or not)
1351 // Remove entry from RSDT/XSDT
1352 // Remove any table references to the table
1353 // If no one is using the table
1354 // Free the table (removing pointers from private data and tables)
1355 // Remove from list
1356 // Free list structure
1357 //
1358 //
1359 // Determine if this table is in the RSDT or XSDT
1360 //
1361 if ((CurrentTableSignature == EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) ||
1362 (CurrentTableSignature == EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) ||
1363 (CurrentTableSignature == EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE)
1364 ) {
1365 RemoveFromRsdt = FALSE;
1366 }
1367 //
1368 // We don't remove the FADT in the standard way because some
1369 // OS expect the FADT to be early in the table list.
1370 // So we always put it as the first element in the list.
1371 //
1372 if (CurrentTableSignature == EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
1373 RemoveFromRsdt = FALSE;
1374 }
1375
1376 //
1377 // Remove the table from RSDT and XSDT
1378 //
1379
1380 //
1381 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1382 //
1383 if (Version & EFI_ACPI_TABLE_VERSION_NONE & Table->Version) {
1384 //
1385 // Remove this version from the table
1386 //
1387 Table->Version = Table->Version &~EFI_ACPI_TABLE_VERSION_NONE;
1388 }
1389
1390 if (Version & EFI_ACPI_TABLE_VERSION_1_0B & Table->Version) {
1391 //
1392 // Remove this version from the table
1393 //
1394 Table->Version = Table->Version &~EFI_ACPI_TABLE_VERSION_1_0B;
1395
1396 //
1397 // Remove from Rsdt. We don't care about the return value because it is
1398 // acceptable for the table to not exist in Rsdt.
1399 // We didn't add some tables so we don't remove them.
1400 //
1401 if (RemoveFromRsdt) {
1402 RemoveTableFromRsdt (
1403 Table,
1404 &AcpiSupportInstance->NumberOfTableEntries1,
1405 AcpiSupportInstance->Rsdt1,
1406 NULL
1407 );
1408 }
1409 }
1410
1411 if ((Version & EFI_ACPI_TABLE_VERSION_2_0 & Table->Version) ||
1412 (Version & EFI_ACPI_TABLE_VERSION_3_0 & Table->Version)) {
1413 //
1414 // Remove this version from the table
1415 //
1416 if (Version & EFI_ACPI_TABLE_VERSION_2_0 & Table->Version) {
1417 Table->Version = Table->Version &~EFI_ACPI_TABLE_VERSION_2_0;
1418 }
1419 if (Version & EFI_ACPI_TABLE_VERSION_3_0 & Table->Version) {
1420 Table->Version = Table->Version &~EFI_ACPI_TABLE_VERSION_3_0;
1421 }
1422
1423 //
1424 // Remove from Rsdt and Xsdt. We don't care about the return value
1425 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1426 // We didn't add some tables so we don't remove them.
1427 //
1428 if (RemoveFromRsdt) {
1429 RemoveTableFromRsdt (
1430 Table,
1431 &AcpiSupportInstance->NumberOfTableEntries3,
1432 AcpiSupportInstance->Rsdt3,
1433 AcpiSupportInstance->Xsdt
1434 );
1435 }
1436 }
1437 //
1438 // Free the table, clean up any dependent tables and our private data pointers.
1439 //
1440 switch (Table->Table->Signature) {
1441
1442 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE:
1443 if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
1444 AcpiSupportInstance->Fadt1 = NULL;
1445 }
1446
1447 if ((Version & EFI_ACPI_TABLE_VERSION_2_0) != 0 ||
1448 (Version & EFI_ACPI_TABLE_VERSION_3_0) != 0) {
1449 AcpiSupportInstance->Fadt3 = NULL;
1450 }
1451 break;
1452
1453 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE:
1454 if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
1455 AcpiSupportInstance->Facs1 = NULL;
1456
1457 //
1458 // Update FADT table pointers
1459 //
1460 if (AcpiSupportInstance->Fadt1 != NULL) {
1461 AcpiSupportInstance->Fadt1->FirmwareCtrl = 0;
1462
1463 //
1464 // Checksum table
1465 //
1466 AcpiPlatformChecksum (
1467 AcpiSupportInstance->Fadt1,
1468 AcpiSupportInstance->Fadt1->Header.Length,
1469 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
1470 Checksum)
1471 );
1472 }
1473 }
1474
1475 if ((Version & EFI_ACPI_TABLE_VERSION_2_0) != 0 ||
1476 (Version & EFI_ACPI_TABLE_VERSION_3_0) != 0) {
1477 AcpiSupportInstance->Facs3 = NULL;
1478
1479 //
1480 // Update FADT table pointers
1481 //
1482 if (AcpiSupportInstance->Fadt3 != NULL) {
1483 AcpiSupportInstance->Fadt3->FirmwareCtrl = 0;
1484 ZeroMem (&AcpiSupportInstance->Fadt3->XFirmwareCtrl, sizeof (UINT64));
1485
1486 //
1487 // Checksum table
1488 //
1489 AcpiPlatformChecksum (
1490 AcpiSupportInstance->Fadt3,
1491 AcpiSupportInstance->Fadt3->Header.Length,
1492 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
1493 Checksum)
1494 );
1495 }
1496 }
1497 break;
1498
1499 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE:
1500 if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
1501 AcpiSupportInstance->Dsdt1 = NULL;
1502
1503 //
1504 // Update FADT table pointers
1505 //
1506 if (AcpiSupportInstance->Fadt1 != NULL) {
1507 AcpiSupportInstance->Fadt1->Dsdt = 0;
1508
1509 //
1510 // Checksum table
1511 //
1512 AcpiPlatformChecksum (
1513 AcpiSupportInstance->Fadt1,
1514 AcpiSupportInstance->Fadt1->Header.Length,
1515 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
1516 Checksum)
1517 );
1518 }
1519 }
1520
1521
1522 if ((Version & EFI_ACPI_TABLE_VERSION_2_0) != 0 ||
1523 (Version & EFI_ACPI_TABLE_VERSION_3_0) != 0) {
1524 AcpiSupportInstance->Dsdt3 = NULL;
1525
1526 //
1527 // Update FADT table pointers
1528 //
1529 if (AcpiSupportInstance->Fadt3 != NULL) {
1530 AcpiSupportInstance->Fadt3->Dsdt = 0;
1531 ZeroMem (&AcpiSupportInstance->Fadt3->XDsdt, sizeof (UINT64));
1532
1533 //
1534 // Checksum table
1535 //
1536 AcpiPlatformChecksum (
1537 AcpiSupportInstance->Fadt3,
1538 AcpiSupportInstance->Fadt3->Header.Length,
1539 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
1540 Checksum)
1541 );
1542 }
1543 }
1544 break;
1545
1546 default:
1547 //
1548 // Do nothing
1549 //
1550 break;
1551 }
1552 }
1553 //
1554 // If no version is using this table anymore, remove and free list entry.
1555 //
1556 if (Table->Version == 0) {
1557 //
1558 // Free the Table
1559 //
1560 gBS->FreePages (Table->PageAddress, Table->NumberOfPages);
1561 RemoveEntryList (&(Table->Link));
1562 gBS->FreePool (Table);
1563 }
1564 //
1565 // Done
1566 //
1567 return EFI_SUCCESS;
1568 }
1569 /**
1570 This function finds and removes the table specified by the handle.
1571
1572 @param AcpiSupportInstance Instance of the protocol.
1573 @param Version Bitmask of which versions to remove.
1574 @param Handle Table to remove.
1575
1576 @return EFI_SUCCESS The function completed successfully.
1577 @return EFI_ABORTED An error occurred.
1578 @return EFI_NOT_FOUND Handle not found in table list.
1579 **/
1580 EFI_STATUS
1581 RemoveTableFromList (
1582 IN EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance,
1583 IN EFI_ACPI_TABLE_VERSION Version,
1584 IN UINTN Handle
1585 )
1586 {
1587 EFI_ACPI_TABLE_LIST *Table;
1588 EFI_STATUS Status;
1589
1590 Table = NULL;
1591
1592 //
1593 // Check for invalid input parameters
1594 //
1595 ASSERT (AcpiSupportInstance);
1596
1597 //
1598 // Find the table
1599 //
1600 Status = FindTableByHandle (
1601 Handle,
1602 &AcpiSupportInstance->TableList,
1603 &Table
1604 );
1605 if (EFI_ERROR (Status)) {
1606 return EFI_NOT_FOUND;
1607 }
1608 //
1609 // Remove the table
1610 //
1611 Status = DeleteTable (AcpiSupportInstance, Version, Table);
1612 if (EFI_ERROR (Status)) {
1613 return EFI_ABORTED;
1614 }
1615 //
1616 // Completed successfully
1617 //
1618 return EFI_SUCCESS;
1619 }
1620 /**
1621 This function calculates and updates an UINT8 checksum.
1622
1623 @param Buffer Pointer to buffer to checksum
1624 @param Size Number of bytes to checksum
1625 @param ChecksumOffset Offset to place the checksum result in
1626
1627 @return EFI_SUCCESS The function completed successfully.
1628
1629 **/
1630 EFI_STATUS
1631 AcpiPlatformChecksum (
1632 IN VOID *Buffer,
1633 IN UINTN Size,
1634 IN UINTN ChecksumOffset
1635 )
1636 {
1637 UINT8 Sum;
1638 UINT8 *Ptr;
1639
1640 Sum = 0;
1641 //
1642 // Initialize pointer
1643 //
1644 Ptr = Buffer;
1645
1646 //
1647 // set checksum to 0 first
1648 //
1649 Ptr[ChecksumOffset] = 0;
1650
1651 //
1652 // add all content of buffer
1653 //
1654 while ((Size--) != 0) {
1655 Sum = (UINT8) (Sum + (*Ptr++));
1656 }
1657 //
1658 // set checksum
1659 //
1660 Ptr = Buffer;
1661 Ptr[ChecksumOffset] = (UINT8) (0xff - Sum + 1);
1662
1663 return EFI_SUCCESS;
1664 }
1665 /**
1666 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1667
1668 @param AcpiSupportInstance Protocol instance private data.
1669
1670 @return EFI_SUCCESS The function completed successfully.
1671
1672 **/
1673 EFI_STATUS
1674 ChecksumCommonTables (
1675 IN OUT EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance
1676 )
1677 {
1678 //
1679 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1680 //
1681 AcpiPlatformChecksum (
1682 AcpiSupportInstance->Rsdp1,
1683 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER),
1684 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER,
1685 Checksum)
1686 );
1687
1688 //
1689 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1690 //
1691 AcpiPlatformChecksum (
1692 AcpiSupportInstance->Rsdp3,
1693 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER),
1694 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER,
1695 Checksum)
1696 );
1697
1698 //
1699 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1700 //
1701 AcpiPlatformChecksum (
1702 AcpiSupportInstance->Rsdp3,
1703 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER),
1704 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER,
1705 ExtendedChecksum)
1706 );
1707
1708 //
1709 // RSDT checksums
1710 //
1711 AcpiPlatformChecksum (
1712 AcpiSupportInstance->Rsdt1,
1713 AcpiSupportInstance->Rsdt1->Length,
1714 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
1715 Checksum)
1716 );
1717
1718 AcpiPlatformChecksum (
1719 AcpiSupportInstance->Rsdt3,
1720 AcpiSupportInstance->Rsdt3->Length,
1721 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
1722 Checksum)
1723 );
1724
1725 //
1726 // XSDT checksum
1727 //
1728 AcpiPlatformChecksum (
1729 AcpiSupportInstance->Xsdt,
1730 AcpiSupportInstance->Xsdt->Length,
1731 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER,
1732 Checksum)
1733 );
1734
1735 return EFI_SUCCESS;
1736 }
1737 /**
1738 Constructor for the ACPI support protocol to initializes instance data.
1739
1740 @param AcpiSupportInstance Instance to construct
1741
1742 @retval EFI_SUCCESS Instance initialized.
1743 @retval EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1744 **/
1745 EFI_STATUS
1746 AcpiSupportAcpiSupportConstructor (
1747 IN EFI_ACPI_SUPPORT_INSTANCE *AcpiSupportInstance
1748 )
1749 {
1750 EFI_STATUS Status;
1751 UINT64 CurrentData;
1752 UINTN TotalSize;
1753 UINTN RsdpTableSize;
1754 UINT8 *Pointer;
1755 EFI_PHYSICAL_ADDRESS PageAddress;
1756
1757 //
1758 // Check for invalid input parameters
1759 //
1760 ASSERT (AcpiSupportInstance);
1761
1762 InitializeListHead (&AcpiSupportInstance->TableList);
1763 AcpiSupportInstance->CurrentHandle = 1;
1764 AcpiSupportInstance->AcpiSupport.GetAcpiTable = GetAcpiTable;
1765 AcpiSupportInstance->AcpiSupport.SetAcpiTable = SetAcpiTable;
1766 AcpiSupportInstance->AcpiSupport.PublishTables = PublishTables;
1767
1768 AcpiSupportInstance->AcpiTableProtocol.InstallAcpiTable = InstallAcpiTable;
1769 AcpiSupportInstance->AcpiTableProtocol.UninstallAcpiTable = UninstallAcpiTable;
1770
1771 //
1772 // Create RSDP table
1773 //
1774 RsdpTableSize = sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER) +
1775 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
1776
1777 PageAddress = 0xFFFFFFFF;
1778 Status = gBS->AllocatePages (
1779 AllocateMaxAddress,
1780 EfiACPIReclaimMemory,
1781 EFI_SIZE_TO_PAGES (RsdpTableSize),
1782 &PageAddress
1783 );
1784
1785 if (EFI_ERROR (Status)) {
1786 return EFI_OUT_OF_RESOURCES;
1787 }
1788
1789 Pointer = (UINT8 *) (UINTN) PageAddress;
1790 ZeroMem (Pointer, RsdpTableSize);
1791
1792 AcpiSupportInstance->Rsdp1 = (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER *) Pointer;
1793 Pointer += sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
1794 AcpiSupportInstance->Rsdp3 = (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *) Pointer;
1795
1796 //
1797 // Create RSDT, XSDT structures
1798 //
1799 TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 1.0 RSDT
1800 mEfiAcpiMaxNumTables * sizeof (UINT32) +
1801 sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 RSDT
1802 mEfiAcpiMaxNumTables * sizeof (UINT32) +
1803 sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 XSDT
1804 mEfiAcpiMaxNumTables * sizeof (UINT64);
1805
1806 //
1807 // Allocate memory in the lower 32 bit of address range for
1808 // compatibility with ACPI 1.0 OS.
1809 //
1810 // This is done because ACPI 1.0 pointers are 32 bit values.
1811 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1812 // There is no architectural reason these should be below 4GB, it is purely
1813 // for convenience of implementation that we force memory below 4GB.
1814 //
1815 PageAddress = 0xFFFFFFFF;
1816 Status = gBS->AllocatePages (
1817 AllocateMaxAddress,
1818 EfiACPIReclaimMemory,
1819 EFI_SIZE_TO_PAGES (TotalSize),
1820 &PageAddress
1821 );
1822
1823 if (EFI_ERROR (Status)) {
1824 gBS->FreePages ((EFI_PHYSICAL_ADDRESS)(UINTN)AcpiSupportInstance->Rsdp1, EFI_SIZE_TO_PAGES (RsdpTableSize));
1825 return EFI_OUT_OF_RESOURCES;
1826 }
1827
1828 Pointer = (UINT8 *) (UINTN) PageAddress;
1829 ZeroMem (Pointer, TotalSize);
1830
1831 AcpiSupportInstance->Rsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *) Pointer;
1832 Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + EFI_ACPI_MAX_NUM_TABLES * sizeof (UINT32));
1833 AcpiSupportInstance->Rsdt3 = (EFI_ACPI_DESCRIPTION_HEADER *) Pointer;
1834 Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + EFI_ACPI_MAX_NUM_TABLES * sizeof (UINT32));
1835 AcpiSupportInstance->Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *) Pointer;
1836
1837 //
1838 // Initialize RSDP
1839 //
1840 CurrentData = EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE;
1841 CopyMem (&AcpiSupportInstance->Rsdp1->Signature, &CurrentData, sizeof (UINT64));
1842 CopyMem (AcpiSupportInstance->Rsdp1->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiSupportInstance->Rsdp1->OemId));
1843 AcpiSupportInstance->Rsdp1->Reserved = EFI_ACPI_RESERVED_BYTE;
1844 AcpiSupportInstance->Rsdp1->RsdtAddress = (UINT32) (UINTN) AcpiSupportInstance->Rsdt1;
1845
1846 CurrentData = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE;
1847 CopyMem (&AcpiSupportInstance->Rsdp3->Signature, &CurrentData, sizeof (UINT64));
1848 CopyMem (AcpiSupportInstance->Rsdp3->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiSupportInstance->Rsdp3->OemId));
1849 AcpiSupportInstance->Rsdp3->Revision = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION;
1850 AcpiSupportInstance->Rsdp3->RsdtAddress = (UINT32) (UINTN) AcpiSupportInstance->Rsdt3;
1851 AcpiSupportInstance->Rsdp3->Length = sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
1852 CurrentData = (UINT64) (UINTN) AcpiSupportInstance->Xsdt;
1853 CopyMem (&AcpiSupportInstance->Rsdp3->XsdtAddress, &CurrentData, sizeof (UINT64));
1854 SetMem (AcpiSupportInstance->Rsdp3->Reserved, 3, EFI_ACPI_RESERVED_BYTE);
1855
1856 //
1857 // Initialize Rsdt
1858 //
1859 // Note that we "reserve" one entry for the FADT so it can always be
1860 // at the beginning of the list of tables. Some OS don't seem
1861 // to find it correctly if it is too far down the list.
1862 //
1863 AcpiSupportInstance->Rsdt1->Signature = EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE;
1864 AcpiSupportInstance->Rsdt1->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER);
1865 AcpiSupportInstance->Rsdt1->Revision = EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION;
1866 CopyMem (AcpiSupportInstance->Rsdt1->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiSupportInstance->Rsdt1->OemId));
1867 CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
1868 CopyMem (&AcpiSupportInstance->Rsdt1->OemTableId, &CurrentData, sizeof (UINT64));
1869 AcpiSupportInstance->Rsdt1->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
1870 AcpiSupportInstance->Rsdt1->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
1871 AcpiSupportInstance->Rsdt1->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
1872 //
1873 // We always reserve first one for FADT
1874 //
1875 AcpiSupportInstance->NumberOfTableEntries1 = 1;
1876 AcpiSupportInstance->Rsdt1->Length = AcpiSupportInstance->Rsdt1->Length + sizeof(UINT32);
1877
1878 AcpiSupportInstance->Rsdt3->Signature = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE;
1879 AcpiSupportInstance->Rsdt3->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER);
1880 AcpiSupportInstance->Rsdt3->Revision = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION;
1881 CopyMem (AcpiSupportInstance->Rsdt3->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiSupportInstance->Rsdt3->OemId));
1882 CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
1883 CopyMem (&AcpiSupportInstance->Rsdt3->OemTableId, &CurrentData, sizeof (UINT64));
1884 AcpiSupportInstance->Rsdt3->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
1885 AcpiSupportInstance->Rsdt3->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
1886 AcpiSupportInstance->Rsdt3->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
1887 //
1888 // We always reserve first one for FADT
1889 //
1890 AcpiSupportInstance->NumberOfTableEntries3 = 1;
1891 AcpiSupportInstance->Rsdt3->Length = AcpiSupportInstance->Rsdt3->Length + sizeof(UINT32);
1892
1893 //
1894 // Initialize Xsdt
1895 //
1896 AcpiSupportInstance->Xsdt->Signature = EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE;
1897 AcpiSupportInstance->Xsdt->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER);
1898 AcpiSupportInstance->Xsdt->Revision = EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION;
1899 CopyMem (AcpiSupportInstance->Xsdt->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiSupportInstance->Xsdt->OemId));
1900 CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
1901 CopyMem (&AcpiSupportInstance->Xsdt->OemTableId, &CurrentData, sizeof (UINT64));
1902 AcpiSupportInstance->Xsdt->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
1903 AcpiSupportInstance->Xsdt->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
1904 AcpiSupportInstance->Xsdt->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
1905 //
1906 // We always reserve first one for FADT
1907 //
1908 AcpiSupportInstance->Xsdt->Length = AcpiSupportInstance->Xsdt->Length + sizeof(UINT64);
1909
1910 ChecksumCommonTables (AcpiSupportInstance);
1911
1912 //
1913 // Completed successfully
1914 //
1915 return EFI_SUCCESS;
1916 }