| 329 | } |
| 330 | |
| 331 | void DropTableFromXSDT(UINT32 Signature, UINT64 TableId, UINT32 Length) |
| 332 | { |
| 333 | if (!Xsdt || (0 == Signature && 0 == TableId)) { |
| 334 | return; |
| 335 | } |
| 336 | |
| 337 | CHAR8 sign[5], OTID[9]; |
| 338 | sign[4] = 0; |
| 339 | OTID[8] = 0; |
| 340 | CopyMem(&sign[0], &Signature, 4); |
| 341 | CopyMem(&OTID[0], &TableId, 8); |
| 342 | DBG("Drop tables from XSDT, SIGN=%s TableID=%s Length=%d\n", sign, OTID, (INT32)Length); |
| 343 | |
| 344 | UINT32 Count = XsdtTableCount(); |
| 345 | //DBG(" Xsdt has tables count=%d\n", Count); |
| 346 | UINT64* Ptr = XsdtEntryPtrFromIndex(0); |
| 347 | UINT64* EndPtr = XsdtEntryPtrFromIndex(Count); |
| 348 | for (; Ptr < EndPtr; Ptr++) { |
| 349 | EFI_ACPI_DESCRIPTION_HEADER* Table = (EFI_ACPI_DESCRIPTION_HEADER*)(UINTN)ReadUnaligned64(Ptr); |
| 350 | if (!Table) { |
| 351 | // skip NULL entry |
| 352 | continue; |
| 353 | } |
| 354 | CopyMem(&sign[0], &Table->Signature, 4); |
| 355 | CopyMem(&OTID[0], &Table->OemTableId, 8); |
| 356 | //DBG(" Found table: %s %s\n", sign, OTID); |
| 357 | if (!((Signature && Table->Signature == Signature) && |
| 358 | (!TableId || Table->OemTableId == TableId) && |
| 359 | (!Length || Table->Length == Length))) { |
| 360 | continue; |
| 361 | } |
| 362 | if (IsXsdtEntryMerged(IndexFromXsdtEntryPtr(Ptr))) { |
| 363 | DBG(" attempt to drop already merged table[%d]: %s %s %d ignored\n", IndexFromXsdtEntryPtr(Ptr), sign, OTID, (INT32)Table->Length); |
| 364 | continue; |
| 365 | } |
| 366 | // drop matching table by simply replacing entry with NULL |
| 367 | WriteUnaligned64(Ptr, 0); |
| 368 | DBG(" Table[%d]: %s %s %d dropped\n", IndexFromXsdtEntryPtr(Ptr), sign, OTID, (INT32)Table->Length); |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | |
| 373 | // by cecekpawon, edited by Slice, further edits by RehabMan |
no test coverage detected