| 489 | } |
| 490 | |
| 491 | EFI_STATUS InsertTable(VOID* TableEntry, UINTN Length) |
| 492 | { |
| 493 | if (!TableEntry) { |
| 494 | return EFI_NOT_FOUND; |
| 495 | } |
| 496 | |
| 497 | EFI_PHYSICAL_ADDRESS BufferPtr = EFI_SYSTEM_TABLE_MAX_ADDRESS; |
| 498 | EFI_STATUS Status = gBS->AllocatePages ( |
| 499 | AllocateMaxAddress, |
| 500 | EfiACPIReclaimMemory, |
| 501 | EFI_SIZE_TO_PAGES(Length), |
| 502 | &BufferPtr |
| 503 | ); |
| 504 | //if success insert table pointer into ACPI tables |
| 505 | if(!EFI_ERROR(Status)) { |
| 506 | // DBG("page is allocated, write SSDT into\n"); |
| 507 | EFI_ACPI_DESCRIPTION_HEADER* TableHeader = (EFI_ACPI_DESCRIPTION_HEADER*)(UINTN)BufferPtr; |
| 508 | CopyMem(TableHeader, TableEntry, Length); |
| 509 | // Now is a good time to fix the table header and checksum |
| 510 | PatchTableHeader(TableHeader); |
| 511 | FixChecksum(TableHeader); |
| 512 | |
| 513 | //insert into RSDT |
| 514 | if (Rsdt) { |
| 515 | UINT32* Ptr = RsdtEntryPtrFromIndex(RsdtTableCount()); |
| 516 | *Ptr = (UINT32)(UINTN)BufferPtr; |
| 517 | Rsdt->Header.Length += sizeof(UINT32); |
| 518 | //DBG("Rsdt->Length = %d\n", Rsdt->Header.Length); |
| 519 | } |
| 520 | //insert into XSDT |
| 521 | if (Xsdt) { |
| 522 | UINT64* Ptr = XsdtEntryPtrFromIndex(XsdtTableCount()); |
| 523 | WriteUnaligned64(Ptr, BufferPtr); |
| 524 | Xsdt->Header.Length += sizeof(UINT64); |
| 525 | //DBG("Xsdt->Length = %d\n", Xsdt->Header.Length); |
| 526 | } |
| 527 | } |
| 528 | return Status; |
| 529 | } |
| 530 | |
| 531 | UINTN IndexFromFileName(CONST CHAR16* FileName) |
| 532 | { |
no test coverage detected