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