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