Blame SOURCES/0028-Support-HMAT-in-a-big-endian-world.patch

9897bb
From 915b8b70726fd01befdeac0c8630db528ac40552 Mon Sep 17 00:00:00 2001
9897bb
From: Al Stone <ahs3@redhat.com>
9897bb
Date: Fri, 25 Sep 2020 16:56:55 -0600
9897bb
Subject: [PATCH 28/45] Support HMAT in a big-endian world
9897bb
9897bb
Signed-off-by: Al Stone <ahs3@redhat.com>
9897bb
---
9897bb
 source/common/dmtbdump1.c  | 70 ++++++++++++++++++++++----------------
9897bb
 source/compiler/dttable1.c | 24 ++++++++++---
9897bb
 2 files changed, 59 insertions(+), 35 deletions(-)
9897bb
9897bb
Index: acpica-unix2-20210604/source/common/dmtbdump1.c
9897bb
===================================================================
9897bb
--- acpica-unix2-20210604.orig/source/common/dmtbdump1.c
9897bb
+++ acpica-unix2-20210604/source/common/dmtbdump1.c
9897bb
@@ -1379,37 +1379,45 @@ AcpiDmDumpHmat (
9897bb
     UINT32                  Length;
9897bb
     ACPI_DMTABLE_INFO       *InfoTable;
9897bb
     UINT32                  i, j;
9897bb
+    UINT32                  TableLength = AcpiUtReadUint32 (&Table->Length);
9897bb
+    UINT16                  HmatStructType;
9897bb
+    UINT32                  HmatStructLength;
9897bb
+    UINT32                  InitPDs;
9897bb
+    UINT32                  TgtPDs;
9897bb
+    UINT16                  SMBIOSHandles;
9897bb
 
9897bb
 
9897bb
     /* Main table */
9897bb
 
9897bb
-    Status = AcpiDmDumpTable (Table->Length, 0, Table, 0, AcpiDmTableInfoHmat);
9897bb
+    Status = AcpiDmDumpTable (TableLength, 0, Table, 0, AcpiDmTableInfoHmat);
9897bb
     if (ACPI_FAILURE (Status))
9897bb
     {
9897bb
         return;
9897bb
     }
9897bb
     Offset = sizeof (ACPI_TABLE_HMAT);
9897bb
 
9897bb
-    while (Offset < Table->Length)
9897bb
+    while (Offset < TableLength)
9897bb
     {
9897bb
         AcpiOsPrintf ("\n");
9897bb
 
9897bb
         /* Dump HMAT structure header */
9897bb
 
9897bb
         HmatStruct = ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, Table, Offset);
9897bb
-        if (HmatStruct->Length < sizeof (ACPI_HMAT_STRUCTURE))
9897bb
+        HmatStructLength = AcpiUtReadUint32 (&HmatStruct->Length);
9897bb
+        if (HmatStructLength < sizeof (ACPI_HMAT_STRUCTURE))
9897bb
         {
9897bb
             AcpiOsPrintf ("Invalid HMAT structure length\n");
9897bb
             return;
9897bb
         }
9897bb
-        Status = AcpiDmDumpTable (Table->Length, Offset, HmatStruct,
9897bb
-            HmatStruct->Length, AcpiDmTableInfoHmatHdr);
9897bb
+        Status = AcpiDmDumpTable (TableLength, Offset, HmatStruct,
9897bb
+            HmatStructLength, AcpiDmTableInfoHmatHdr);
9897bb
         if (ACPI_FAILURE (Status))
9897bb
         {
9897bb
             return;
9897bb
         }
9897bb
 
9897bb
-        switch (HmatStruct->Type)
9897bb
+        HmatStructType = AcpiUtReadUint16 (&HmatStruct->Type);
9897bb
+        switch (HmatStructType)
9897bb
         {
9897bb
         case ACPI_HMAT_TYPE_ADDRESS_RANGE:
9897bb
 
9897bb
@@ -1432,7 +1440,7 @@ AcpiDmDumpHmat (
9897bb
         default:
9897bb
 
9897bb
             AcpiOsPrintf ("\n**** Unknown HMAT structure type 0x%X\n",
9897bb
-                HmatStruct->Type);
9897bb
+                HmatStructType);
9897bb
 
9897bb
             /* Attempt to continue */
9897bb
 
9897bb
@@ -1441,13 +1449,13 @@ AcpiDmDumpHmat (
9897bb
 
9897bb
         /* Dump HMAT structure body */
9897bb
 
9897bb
-        if (HmatStruct->Length < Length)
9897bb
+        if (HmatStructLength < Length)
9897bb
         {
9897bb
             AcpiOsPrintf ("Invalid HMAT structure length\n");
9897bb
             return;
9897bb
         }
9897bb
-        Status = AcpiDmDumpTable (Table->Length, Offset, HmatStruct,
9897bb
-            HmatStruct->Length, InfoTable);
9897bb
+        Status = AcpiDmDumpTable (TableLength, Offset, HmatStruct,
9897bb
+            HmatStructLength, InfoTable);
9897bb
         if (ACPI_FAILURE (Status))
9897bb
         {
9897bb
             return;
9897bb
@@ -1455,7 +1463,7 @@ AcpiDmDumpHmat (
9897bb
 
9897bb
         /* Dump HMAT structure additionals */
9897bb
 
9897bb
-        switch (HmatStruct->Type)
9897bb
+        switch (HmatStructType)
9897bb
         {
9897bb
         case ACPI_HMAT_TYPE_LOCALITY:
9897bb
 
9897bb
@@ -1464,15 +1472,16 @@ AcpiDmDumpHmat (
9897bb
 
9897bb
             /* Dump initiator proximity domains */
9897bb
 
9897bb
-            if ((UINT32)(HmatStruct->Length - SubtableOffset) <
9897bb
-                (UINT32)(HmatLocality->NumberOfInitiatorPDs * 4))
9897bb
+            InitPDs = AcpiUtReadUint32 (&HmatLocality->NumberOfInitiatorPDs);
9897bb
+            if ((UINT32) (HmatStructLength - SubtableOffset) <
9897bb
+                (UINT32) (InitPDs * 4))
9897bb
             {
9897bb
                 AcpiOsPrintf ("Invalid initiator proximity domain number\n");
9897bb
                 return;
9897bb
             }
9897bb
-            for (i = 0; i < HmatLocality->NumberOfInitiatorPDs; i++)
9897bb
+            for (i = 0; i < InitPDs; i++)
9897bb
             {
9897bb
-                Status = AcpiDmDumpTable (Table->Length, Offset + SubtableOffset,
9897bb
+                Status = AcpiDmDumpTable (TableLength, Offset + SubtableOffset,
9897bb
                     ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, HmatStruct, SubtableOffset),
9897bb
                     4, AcpiDmTableInfoHmat1a);
9897bb
                 if (ACPI_FAILURE (Status))
9897bb
@@ -1485,15 +1494,16 @@ AcpiDmDumpHmat (
9897bb
 
9897bb
             /* Dump target proximity domains */
9897bb
 
9897bb
-            if ((UINT32)(HmatStruct->Length - SubtableOffset) <
9897bb
-                (UINT32)(HmatLocality->NumberOfTargetPDs * 4))
9897bb
+            TgtPDs = AcpiUtReadUint32 (&HmatLocality->NumberOfTargetPDs);
9897bb
+            if ((UINT32) (HmatStructLength - SubtableOffset) <
9897bb
+                (UINT32) (TgtPDs * 4))
9897bb
             {
9897bb
                 AcpiOsPrintf ("Invalid target proximity domain number\n");
9897bb
                 return;
9897bb
             }
9897bb
-            for (i = 0; i < HmatLocality->NumberOfTargetPDs; i++)
9897bb
+            for (i = 0; i < TgtPDs; i++)
9897bb
             {
9897bb
-                Status = AcpiDmDumpTable (Table->Length, Offset + SubtableOffset,
9897bb
+                Status = AcpiDmDumpTable (TableLength, Offset + SubtableOffset,
9897bb
                     ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, HmatStruct, SubtableOffset),
9897bb
                     4, AcpiDmTableInfoHmat1b);
9897bb
                 if (ACPI_FAILURE (Status))
9897bb
@@ -1506,18 +1516,17 @@ AcpiDmDumpHmat (
9897bb
 
9897bb
             /* Dump latency/bandwidth entris */
9897bb
 
9897bb
-            if ((UINT32)(HmatStruct->Length - SubtableOffset) <
9897bb
-                (UINT32)(HmatLocality->NumberOfInitiatorPDs *
9897bb
-                         HmatLocality->NumberOfTargetPDs * 2))
9897bb
+            if ((UINT32) (HmatStructLength - SubtableOffset) <
9897bb
+                (UINT32) (InitPDs * TgtPDs * 2))
9897bb
             {
9897bb
                 AcpiOsPrintf ("Invalid latency/bandwidth entry number\n");
9897bb
                 return;
9897bb
             }
9897bb
-            for (i = 0; i < HmatLocality->NumberOfInitiatorPDs; i++)
9897bb
+            for (i = 0; i < InitPDs; i++)
9897bb
             {
9897bb
-                for (j = 0; j < HmatLocality->NumberOfTargetPDs; j++)
9897bb
+                for (j = 0; j < TgtPDs; j++)
9897bb
                 {
9897bb
-                    Status = AcpiDmDumpTable (Table->Length, Offset + SubtableOffset,
9897bb
+                    Status = AcpiDmDumpTable (TableLength, Offset + SubtableOffset,
9897bb
                         ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, HmatStruct, SubtableOffset),
9897bb
                         2, AcpiDmTableInfoHmat1c);
9897bb
                     if (ACPI_FAILURE(Status))
9897bb
@@ -1537,15 +1546,16 @@ AcpiDmDumpHmat (
9897bb
 
9897bb
             /* Dump SMBIOS handles */
9897bb
 
9897bb
-            if ((UINT32)(HmatStruct->Length - SubtableOffset) <
9897bb
-                (UINT32)(HmatCache->NumberOfSMBIOSHandles * 2))
9897bb
+            SMBIOSHandles = AcpiUtReadUint16 (&HmatCache->NumberOfSMBIOSHandles);
9897bb
+            if ((UINT32) (HmatStructLength - SubtableOffset) <
9897bb
+                (UINT32) (SMBIOSHandles * 2))
9897bb
             {
9897bb
                 AcpiOsPrintf ("Invalid SMBIOS handle number\n");
9897bb
                 return;
9897bb
             }
9897bb
-            for (i = 0; i < HmatCache->NumberOfSMBIOSHandles; i++)
9897bb
+            for (i = 0; i < SMBIOSHandles; i++)
9897bb
             {
9897bb
-                Status = AcpiDmDumpTable (Table->Length, Offset + SubtableOffset,
9897bb
+                Status = AcpiDmDumpTable (TableLength, Offset + SubtableOffset,
9897bb
                     ACPI_ADD_PTR (ACPI_HMAT_STRUCTURE, HmatStruct, SubtableOffset),
9897bb
                     2, AcpiDmTableInfoHmat2a);
9897bb
                 if (ACPI_FAILURE (Status))
9897bb
@@ -1565,6 +1575,6 @@ AcpiDmDumpHmat (
9897bb
 NextSubtable:
9897bb
         /* Point to next HMAT structure subtable */
9897bb
 
9897bb
-        Offset += (HmatStruct->Length);
9897bb
+        Offset += (HmatStructLength);
9897bb
     }
9897bb
 }
9897bb
Index: acpica-unix2-20210604/source/compiler/dttable1.c
9897bb
===================================================================
9897bb
--- acpica-unix2-20210604.orig/source/compiler/dttable1.c
9897bb
+++ acpica-unix2-20210604/source/compiler/dttable1.c
9897bb
@@ -1369,6 +1369,8 @@ DtCompileHmat (
9897bb
     UINT32                  TgtPDNumber;
9897bb
     UINT64                  EntryNumber;
9897bb
     UINT16                  SMBIOSHandleNumber;
9897bb
+    UINT16                  HmatStructType;
9897bb
+    UINT32                  Length;
9897bb
 
9897bb
 
9897bb
     ParentTable = DtPeekSubtable ();
9897bb
@@ -1399,7 +1401,8 @@ DtCompileHmat (
9897bb
 
9897bb
         /* Compile HMAT structure body */
9897bb
 
9897bb
-        switch (HmatStruct->Type)
9897bb
+        HmatStructType = AcpiUtReadUint16 (&HmatStruct->Type);
9897bb
+        switch (HmatStructType)
9897bb
         {
9897bb
         case ACPI_HMAT_TYPE_ADDRESS_RANGE:
9897bb
 
9897bb
@@ -1432,7 +1435,7 @@ DtCompileHmat (
9897bb
 
9897bb
         /* Compile HMAT structure additionals */
9897bb
 
9897bb
-        switch (HmatStruct->Type)
9897bb
+        switch (HmatStructType)
9897bb
         {
9897bb
         case ACPI_HMAT_TYPE_LOCALITY:
9897bb
 
9897bb
@@ -1458,7 +1461,7 @@ DtCompileHmat (
9897bb
                 HmatStruct->Length += Subtable->Length;
9897bb
                 IntPDNumber++;
9897bb
             }
9897bb
-            HmatLocality->NumberOfInitiatorPDs = IntPDNumber;
9897bb
+            HmatLocality->NumberOfInitiatorPDs = AcpiUtReadUint32 (&IntPDNumber);
9897bb
 
9897bb
             /* Compile target proximity domain list */
9897bb
 
9897bb
@@ -1479,7 +1482,7 @@ DtCompileHmat (
9897bb
                 HmatStruct->Length += Subtable->Length;
9897bb
                 TgtPDNumber++;
9897bb
             }
9897bb
-            HmatLocality->NumberOfTargetPDs = TgtPDNumber;
9897bb
+            HmatLocality->NumberOfTargetPDs = AcpiUtReadUint32 (&TgtPDNumber);
9897bb
 
9897bb
             /* Save start of the entries for reporting errors */
9897bb
 
9897bb
@@ -1505,6 +1508,9 @@ DtCompileHmat (
9897bb
                 EntryNumber++;
9897bb
             }
9897bb
 
9897bb
+            Length = AcpiUtReadUint32 (&HmatStruct->Length);
9897bb
+            HmatStruct->Length = Length;
9897bb
+
9897bb
             /* Validate number of entries */
9897bb
 
9897bb
             if (EntryNumber !=
9897bb
@@ -1538,11 +1544,19 @@ DtCompileHmat (
9897bb
                 HmatStruct->Length += Subtable->Length;
9897bb
                 SMBIOSHandleNumber++;
9897bb
             }
9897bb
-            HmatCache->NumberOfSMBIOSHandles = SMBIOSHandleNumber;
9897bb
+            HmatCache->NumberOfSMBIOSHandles =
9897bb
+                    AcpiUtReadUint16 (&SMBIOSHandleNumber);
9897bb
+
9897bb
+            Length = AcpiUtReadUint32 (&HmatStruct->Length);
9897bb
+            HmatStruct->Length = Length;
9897bb
+
9897bb
             break;
9897bb
 
9897bb
         default:
9897bb
 
9897bb
+        Length = AcpiUtReadUint32(&HmatStruct->Length);
9897bb
+        HmatStruct->Length = Length;
9897bb
+
9897bb
             break;
9897bb
         }
9897bb
     }