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