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