Skip to content

Commit

Permalink
OcAcpiLib: Fix RSDP, RSDT, and XSDT header normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
Goldfish64 committed Apr 5, 2021
1 parent 6dcabf0 commit 9d7b7cc
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ OpenCore Changelog
- Support starting UEFI tools with argument support (e.g. `ControlMsrE2`) without arguments from picker
- Fixed OpenCanopy font height calculation, may reject previously working fonts and mitigate memory corruption
- Fixed incorrect identification of Xeon E5XXX/E5-XXXX and Xeon WXXXX/W-XXXX CPUs
- Added RSDP, RSDT, and XSDT handling to `NormalizeHeaders` ACPI quirk

#### v0.6.7
- Fixed ocvalidate return code to be non-zero when issues are found
Expand Down
80 changes: 80 additions & 0 deletions Library/OcAcpiLib/OcAcpiLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,55 @@ AcpiNormalizeTableHeaders (
return Modified;
}

/**
Cleanup RSDP table from unprintable symbols.
Reference: https://alextjam.es/debugging-appleacpiplatform/.
@param Rsdp RSDP table.
@param HasXsdt RSDP has XSDT and is extended.
**/
STATIC
BOOLEAN
AcpiNormalizeRsdp (
IN EFI_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp,
IN BOOLEAN HasXsdt
)
{
BOOLEAN Modified;
CHAR8 *Walker;
UINT32 Index;

Modified = FALSE;

Walker = (CHAR8 *) &Rsdp->OemId;
for (Index = 0; Index < sizeof (Rsdp->OemId); ++Index) {
if (!IsAsciiPrint (Walker[Index])) {
Walker[Index] = '?';
Modified = TRUE;
}
}

if (Modified) {
//
// Checksum is to be the first 0-19 bytes of RSDP.
// ExtendedChecksum is the entire table, only if newer than ACPI 1.0.
//
Rsdp->Checksum = 0;
Rsdp->Checksum = CalculateCheckSum8 (
(UINT8 *) Rsdp, 20
);

if (HasXsdt) {
Rsdp->ExtendedChecksum = 0;
Rsdp->ExtendedChecksum = CalculateCheckSum8 (
(UINT8 *) Rsdp, Rsdp->Length
);
}
}

return Modified;
}

EFI_STATUS
AcpiInitContext (
IN OUT OC_ACPI_CONTEXT *Context
Expand Down Expand Up @@ -1107,6 +1156,37 @@ AcpiNormalizeHeaders (
EFI_ACPI_COMMON_HEADER *NewTable;
UINT32 TablePrintSignature;

AcpiNormalizeRsdp (Context->Rsdp, Context->Xsdt != NULL);
DEBUG ((DEBUG_INFO, "OCA: Normalized RSDP\n"));

This comment has been minimized.

Copy link
@zhen-zen

zhen-zen Apr 5, 2021

Contributor

Maybe only print the message when AcpiNormalizeRsdp return that table is modified?

This comment has been minimized.

Copy link
@Goldfish64

Goldfish64 Apr 5, 2021

Author Member

Fixed, thanks.


if (Context->Xsdt != NULL) {
if (!AcpiIsTableWritable ((EFI_ACPI_COMMON_HEADER *) Context->Xsdt)) {
Status = AcpiAllocateCopyTable ((EFI_ACPI_COMMON_HEADER *) Context->Xsdt, 0, &NewTable);
if (EFI_ERROR (Status)) {
return;
}
Context->Xsdt = (OC_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE *) NewTable;
}

if (AcpiNormalizeTableHeaders ((EFI_ACPI_DESCRIPTION_HEADER *) Context->Xsdt)) {
DEBUG ((DEBUG_INFO, "OCA: Normalized XSDT of %u bytes headers\n", Context->Xsdt->Header.Length));
}
}

if (Context->Rsdt != NULL) {
if (!AcpiIsTableWritable ((EFI_ACPI_COMMON_HEADER *) Context->Rsdt)) {
Status = AcpiAllocateCopyTable ((EFI_ACPI_COMMON_HEADER *) Context->Rsdt, 0, &NewTable);
if (EFI_ERROR (Status)) {
return;
}
Context->Rsdt = (OC_ACPI_6_2_ROOT_SYSTEM_DESCRIPTION_TABLE *) NewTable;
}

if (AcpiNormalizeTableHeaders ((EFI_ACPI_DESCRIPTION_HEADER *) Context->Rsdt)) {
DEBUG ((DEBUG_INFO, "OCA: Normalized RSDT of %u bytes headers\n", Context->Rsdt->Header.Length));
}
}

if (Context->Dsdt != NULL) {
if (!AcpiIsTableWritable ((EFI_ACPI_COMMON_HEADER *) Context->Dsdt)) {
Status = AcpiAllocateCopyDsdt (Context, NULL);
Expand Down

0 comments on commit 9d7b7cc

Please sign in to comment.