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