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