From 915b8b70726fd01befdeac0c8630db528ac40552 Mon Sep 17 00:00:00 2001 From: Al Stone Date: Fri, 25 Sep 2020 16:56:55 -0600 Subject: [PATCH 28/45] Support HMAT in a big-endian world Signed-off-by: Al Stone --- source/common/dmtbdump1.c | 70 ++++++++++++++++++++++---------------- source/compiler/dttable1.c | 24 ++++++++++--- 2 files changed, 59 insertions(+), 35 deletions(-) Index: acpica-unix2-20210730/source/common/dmtbdump1.c =================================================================== --- acpica-unix2-20210730.orig/source/common/dmtbdump1.c +++ acpica-unix2-20210730/source/common/dmtbdump1.c @@ -1598,37 +1598,45 @@ AcpiDmDumpHmat ( UINT32 Length; ACPI_DMTABLE_INFO *InfoTable; UINT32 i, j; + UINT32 TableLength = AcpiUtReadUint32 (&Table->Length); + UINT16 HmatStructType; + UINT32 HmatStructLength; + UINT32 InitPDs; + UINT32 TgtPDs; + UINT16 SMBIOSHandles; /* Main table */ - Status = AcpiDmDumpTable (Table->Length, 0, Table, 0, AcpiDmTableInfoHmat); + Status = AcpiDmDumpTable (TableLength, 0, Table, 0, AcpiDmTableInfoHmat); if (ACPI_FAILURE (Status)) { return; } Offset = sizeof (ACPI_TABLE_HMAT); - while (Offset < Table->Length) + while (Offset < TableLength) { AcpiOsPrintf ("\n"); /* Dump HMAT structure header */ HmatStruct = ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, Table, Offset); - if (HmatStruct->Length < sizeof (ACPI_HMAT_STRUCTURE)) + HmatStructLength = AcpiUtReadUint32 (&HmatStruct->Length); + if (HmatStructLength < sizeof (ACPI_HMAT_STRUCTURE)) { AcpiOsPrintf ("Invalid HMAT structure length\n"); return; } - Status = AcpiDmDumpTable (Table->Length, Offset, HmatStruct, - HmatStruct->Length, AcpiDmTableInfoHmatHdr); + Status = AcpiDmDumpTable (TableLength, Offset, HmatStruct, + HmatStructLength, AcpiDmTableInfoHmatHdr); if (ACPI_FAILURE (Status)) { return; } - switch (HmatStruct->Type) + HmatStructType = AcpiUtReadUint16 (&HmatStruct->Type); + switch (HmatStructType) { case ACPI_HMAT_TYPE_ADDRESS_RANGE: @@ -1651,7 +1659,7 @@ AcpiDmDumpHmat ( default: AcpiOsPrintf ("\n**** Unknown HMAT structure type 0x%X\n", - HmatStruct->Type); + HmatStructType); /* Attempt to continue */ @@ -1660,13 +1668,13 @@ AcpiDmDumpHmat ( /* Dump HMAT structure body */ - if (HmatStruct->Length < Length) + if (HmatStructLength < Length) { AcpiOsPrintf ("Invalid HMAT structure length\n"); return; } - Status = AcpiDmDumpTable (Table->Length, Offset, HmatStruct, - HmatStruct->Length, InfoTable); + Status = AcpiDmDumpTable (TableLength, Offset, HmatStruct, + HmatStructLength, InfoTable); if (ACPI_FAILURE (Status)) { return; @@ -1674,7 +1682,7 @@ AcpiDmDumpHmat ( /* Dump HMAT structure additionals */ - switch (HmatStruct->Type) + switch (HmatStructType) { case ACPI_HMAT_TYPE_LOCALITY: @@ -1683,15 +1691,16 @@ AcpiDmDumpHmat ( /* Dump initiator proximity domains */ - if ((UINT32)(HmatStruct->Length - SubtableOffset) < - (UINT32)(HmatLocality->NumberOfInitiatorPDs * 4)) + InitPDs = AcpiUtReadUint32 (&HmatLocality->NumberOfInitiatorPDs); + if ((UINT32) (HmatStructLength - SubtableOffset) < + (UINT32) (InitPDs * 4)) { AcpiOsPrintf ("Invalid initiator proximity domain number\n"); return; } - for (i = 0; i < HmatLocality->NumberOfInitiatorPDs; i++) + for (i = 0; i < InitPDs; i++) { - Status = AcpiDmDumpTable (Table->Length, Offset + SubtableOffset, + Status = AcpiDmDumpTable (TableLength, Offset + SubtableOffset, ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, HmatStruct, SubtableOffset), 4, AcpiDmTableInfoHmat1a); if (ACPI_FAILURE (Status)) @@ -1704,15 +1713,16 @@ AcpiDmDumpHmat ( /* Dump target proximity domains */ - if ((UINT32)(HmatStruct->Length - SubtableOffset) < - (UINT32)(HmatLocality->NumberOfTargetPDs * 4)) + TgtPDs = AcpiUtReadUint32 (&HmatLocality->NumberOfTargetPDs); + if ((UINT32) (HmatStructLength - SubtableOffset) < + (UINT32) (TgtPDs * 4)) { AcpiOsPrintf ("Invalid target proximity domain number\n"); return; } - for (i = 0; i < HmatLocality->NumberOfTargetPDs; i++) + for (i = 0; i < TgtPDs; i++) { - Status = AcpiDmDumpTable (Table->Length, Offset + SubtableOffset, + Status = AcpiDmDumpTable (TableLength, Offset + SubtableOffset, ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, HmatStruct, SubtableOffset), 4, AcpiDmTableInfoHmat1b); if (ACPI_FAILURE (Status)) @@ -1725,18 +1735,17 @@ AcpiDmDumpHmat ( /* Dump latency/bandwidth entris */ - if ((UINT32)(HmatStruct->Length - SubtableOffset) < - (UINT32)(HmatLocality->NumberOfInitiatorPDs * - HmatLocality->NumberOfTargetPDs * 2)) + if ((UINT32) (HmatStructLength - SubtableOffset) < + (UINT32) (InitPDs * TgtPDs * 2)) { AcpiOsPrintf ("Invalid latency/bandwidth entry number\n"); return; } - for (i = 0; i < HmatLocality->NumberOfInitiatorPDs; i++) + for (i = 0; i < InitPDs; i++) { - for (j = 0; j < HmatLocality->NumberOfTargetPDs; j++) + for (j = 0; j < TgtPDs; j++) { - Status = AcpiDmDumpTable (Table->Length, Offset + SubtableOffset, + Status = AcpiDmDumpTable (TableLength, Offset + SubtableOffset, ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, HmatStruct, SubtableOffset), 2, AcpiDmTableInfoHmat1c); if (ACPI_FAILURE(Status)) @@ -1756,15 +1765,16 @@ AcpiDmDumpHmat ( /* Dump SMBIOS handles */ - if ((UINT32)(HmatStruct->Length - SubtableOffset) < - (UINT32)(HmatCache->NumberOfSMBIOSHandles * 2)) + SMBIOSHandles = AcpiUtReadUint16 (&HmatCache->NumberOfSMBIOSHandles); + if ((UINT32) (HmatStructLength - SubtableOffset) < + (UINT32) (SMBIOSHandles * 2)) { AcpiOsPrintf ("Invalid SMBIOS handle number\n"); return; } - for (i = 0; i < HmatCache->NumberOfSMBIOSHandles; i++) + for (i = 0; i < SMBIOSHandles; i++) { - Status = AcpiDmDumpTable (Table->Length, Offset + SubtableOffset, + Status = AcpiDmDumpTable (TableLength, Offset + SubtableOffset, ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, HmatStruct, SubtableOffset), 2, AcpiDmTableInfoHmat2a); if (ACPI_FAILURE (Status)) @@ -1784,6 +1794,6 @@ AcpiDmDumpHmat ( NextSubtable: /* Point to next HMAT structure subtable */ - Offset += (HmatStruct->Length); + Offset += (HmatStructLength); } } Index: acpica-unix2-20210730/source/compiler/dttable1.c =================================================================== --- acpica-unix2-20210730.orig/source/compiler/dttable1.c +++ acpica-unix2-20210730/source/compiler/dttable1.c @@ -1586,6 +1586,8 @@ DtCompileHmat ( UINT32 TgtPDNumber; UINT64 EntryNumber; UINT16 SMBIOSHandleNumber; + UINT16 HmatStructType; + UINT32 Length; ParentTable = DtPeekSubtable (); @@ -1616,7 +1618,8 @@ DtCompileHmat ( /* Compile HMAT structure body */ - switch (HmatStruct->Type) + HmatStructType = AcpiUtReadUint16 (&HmatStruct->Type); + switch (HmatStructType) { case ACPI_HMAT_TYPE_ADDRESS_RANGE: @@ -1649,7 +1652,7 @@ DtCompileHmat ( /* Compile HMAT structure additionals */ - switch (HmatStruct->Type) + switch (HmatStructType) { case ACPI_HMAT_TYPE_LOCALITY: @@ -1675,7 +1678,7 @@ DtCompileHmat ( HmatStruct->Length += Subtable->Length; IntPDNumber++; } - HmatLocality->NumberOfInitiatorPDs = IntPDNumber; + HmatLocality->NumberOfInitiatorPDs = AcpiUtReadUint32 (&IntPDNumber); /* Compile target proximity domain list */ @@ -1696,7 +1699,7 @@ DtCompileHmat ( HmatStruct->Length += Subtable->Length; TgtPDNumber++; } - HmatLocality->NumberOfTargetPDs = TgtPDNumber; + HmatLocality->NumberOfTargetPDs = AcpiUtReadUint32 (&TgtPDNumber); /* Save start of the entries for reporting errors */ @@ -1722,6 +1725,9 @@ DtCompileHmat ( EntryNumber++; } + Length = AcpiUtReadUint32 (&HmatStruct->Length); + HmatStruct->Length = Length; + /* Validate number of entries */ if (EntryNumber != @@ -1755,11 +1761,19 @@ DtCompileHmat ( HmatStruct->Length += Subtable->Length; SMBIOSHandleNumber++; } - HmatCache->NumberOfSMBIOSHandles = SMBIOSHandleNumber; + HmatCache->NumberOfSMBIOSHandles = + AcpiUtReadUint16 (&SMBIOSHandleNumber); + + Length = AcpiUtReadUint32 (&HmatStruct->Length); + HmatStruct->Length = Length; + break; default: + Length = AcpiUtReadUint32(&HmatStruct->Length); + HmatStruct->Length = Length; + break; } }