Blame SOURCES/0041-Support-IORT-in-a-big-endian-world.patch

9897bb
From 5bd43bca1708a56d32e63da0278e04caf2865927 Mon Sep 17 00:00:00 2001
9897bb
From: Al Stone <ahs3@redhat.com>
9897bb
Date: Tue, 29 Jun 2021 17:38:20 -0600
9897bb
Subject: [PATCH 41/45] Support IORT in a big-endian world
9897bb
9897bb
Signed-off-by: Al Stone <ahs3@redhat.com>
9897bb
---
9897bb
 source/common/dmtbdump2.c  | 85 ++++++++++++++++++++++----------------
9897bb
 source/compiler/dttable1.c | 40 ++++++++++--------
9897bb
 2 files changed, 72 insertions(+), 53 deletions(-)
9897bb
9897bb
Index: acpica-unix2-20210604/source/common/dmtbdump2.c
9897bb
===================================================================
9897bb
--- acpica-unix2-20210604.orig/source/common/dmtbdump2.c
9897bb
+++ acpica-unix2-20210604/source/common/dmtbdump2.c
9897bb
@@ -77,17 +77,20 @@ AcpiDmDumpIort (
9897bb
     ACPI_IORT_RMR           *IortRmr = NULL;
9897bb
     UINT32                  Offset;
9897bb
     UINT32                  NodeOffset;
9897bb
+    UINT32                  NodeLength;
9897bb
     UINT32                  Length;
9897bb
     ACPI_DMTABLE_INFO       *InfoTable;
9897bb
     char                    *String;
9897bb
     UINT32                  i;
9897bb
     UINT32                  MappingByteLength;
9897bb
     UINT8                   Revision;
9897bb
+    UINT32                  MappingCount;
9897bb
+    UINT32                  TableLength = AcpiUtReadUint32 (&Table->Length);
9897bb
 
9897bb
 
9897bb
     /* Main table */
9897bb
 
9897bb
-    Status = AcpiDmDumpTable (Table->Length, 0, Table, 0, AcpiDmTableInfoIort);
9897bb
+    Status = AcpiDmDumpTable (TableLength, 0, Table, 0, AcpiDmTableInfoIort);
9897bb
     if (ACPI_FAILURE (Status))
9897bb
     {
9897bb
         return;
9897bb
@@ -109,18 +112,19 @@ AcpiDmDumpIort (
9897bb
 
9897bb
     /* Dump the OptionalPadding (optional) */
9897bb
 
9897bb
-    if (Iort->NodeOffset > Offset)
9897bb
+    NodeOffset = AcpiUtReadUint32 (&Iort->NodeOffset);
9897bb
+    if (NodeOffset > Offset)
9897bb
     {
9897bb
-        Status = AcpiDmDumpTable (Table->Length, Offset, Table,
9897bb
-            Iort->NodeOffset - Offset, AcpiDmTableInfoIortPad);
9897bb
+        Status = AcpiDmDumpTable (TableLength, Offset, Table,
9897bb
+            NodeOffset - Offset, AcpiDmTableInfoIortPad);
9897bb
         if (ACPI_FAILURE (Status))
9897bb
         {
9897bb
             return;
9897bb
         }
9897bb
     }
9897bb
 
9897bb
-    Offset = Iort->NodeOffset;
9897bb
-    while (Offset < Table->Length)
9897bb
+    Offset = AcpiUtReadUint32 (&Iort->NodeOffset);
9897bb
+    while (Offset < TableLength)
9897bb
     {
9897bb
         /* Common subtable header */
9897bb
 
9897bb
@@ -130,12 +134,12 @@ AcpiDmDumpIort (
9897bb
 
9897bb
         if (Revision == 0)
9897bb
         {
9897bb
-            Status = AcpiDmDumpTable (Table->Length, Offset,
9897bb
+            Status = AcpiDmDumpTable (TableLength, Offset,
9897bb
                 IortNode, Length, AcpiDmTableInfoIortHdr);
9897bb
         }
9897bb
         else if (Revision >= 3)
9897bb
         {
9897bb
-            Status = AcpiDmDumpTable (Table->Length, Offset,
9897bb
+            Status = AcpiDmDumpTable (TableLength, Offset,
9897bb
                 IortNode, Length, AcpiDmTableInfoIortHdr3);
9897bb
         }
9897bb
 
9897bb
@@ -166,7 +170,7 @@ AcpiDmDumpIort (
9897bb
         case ACPI_IORT_NODE_PCI_ROOT_COMPLEX:
9897bb
 
9897bb
             InfoTable = AcpiDmTableInfoIort2;
9897bb
-            Length = IortNode->Length - NodeOffset;
9897bb
+            Length = AcpiUtReadUint16 (&IortNode->Length) - NodeOffset;
9897bb
             break;
9897bb
 
9897bb
         case ACPI_IORT_NODE_SMMU:
9897bb
@@ -179,19 +183,19 @@ AcpiDmDumpIort (
9897bb
         case ACPI_IORT_NODE_SMMU_V3:
9897bb
 
9897bb
             InfoTable = AcpiDmTableInfoIort4;
9897bb
-            Length = IortNode->Length - NodeOffset;
9897bb
+            Length = AcpiUtReadUint16 (&IortNode->Length) - NodeOffset;
9897bb
             break;
9897bb
 
9897bb
         case ACPI_IORT_NODE_PMCG:
9897bb
 
9897bb
             InfoTable = AcpiDmTableInfoIort5;
9897bb
-            Length = IortNode->Length - NodeOffset;
9897bb
+            Length = AcpiUtReadUint16 (&IortNode->Length) - NodeOffset;
9897bb
             break;
9897bb
 
9897bb
         case ACPI_IORT_NODE_RMR:
9897bb
 
9897bb
             InfoTable = AcpiDmTableInfoIort6;
9897bb
-            Length = IortNode->Length - NodeOffset;
9897bb
+            Length = AcpiUtReadUint16 (&IortNode->Length) - NodeOffset;
9897bb
             IortRmr = ACPI_ADD_PTR (ACPI_IORT_RMR, IortNode, NodeOffset);
9897bb
             break;
9897bb
 
9897bb
@@ -202,7 +206,7 @@ AcpiDmDumpIort (
9897bb
 
9897bb
             /* Attempt to continue */
9897bb
 
9897bb
-            if (!IortNode->Length)
9897bb
+            if (!AcpiUtReadUint16 (&IortNode->Length))
9897bb
             {
9897bb
                 AcpiOsPrintf ("Invalid zero length IORT node\n");
9897bb
                 return;
9897bb
@@ -213,7 +217,7 @@ AcpiDmDumpIort (
9897bb
         /* Dump the node subtable header */
9897bb
 
9897bb
         AcpiOsPrintf ("\n");
9897bb
-        Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
9897bb
+        Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
9897bb
             ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
9897bb
             Length, InfoTable);
9897bb
         if (ACPI_FAILURE (Status))
9897bb
@@ -233,9 +237,10 @@ AcpiDmDumpIort (
9897bb
 
9897bb
             if (IortItsGroup)
9897bb
             {
9897bb
-                for (i = 0; i < IortItsGroup->ItsCount; i++)
9897bb
+	        UINT32 ItsCount = AcpiUtReadUint32 (&IortItsGroup->ItsCount);
9897bb
+                for (i = 0; i < ItsCount; i++)
9897bb
                 {
9897bb
-                    Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
9897bb
+                    Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
9897bb
                         ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
9897bb
                         4, AcpiDmTableInfoIort0a);
9897bb
                     if (ACPI_FAILURE (Status))
9897bb
@@ -252,12 +257,14 @@ AcpiDmDumpIort (
9897bb
 
9897bb
             /* Dump the Padding (optional) */
9897bb
 
9897bb
-            if (IortNode->Length > NodeOffset)
9897bb
+            NodeLength = AcpiUtReadUint16 (&IortNode->Length);
9897bb
+            if (NodeLength > NodeOffset)
9897bb
             {
9897bb
                 MappingByteLength =
9897bb
-                    IortNode->MappingCount * sizeof (ACPI_IORT_ID_MAPPING);
9897bb
-                Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
9897bb
-                    Table, IortNode->Length - NodeOffset - MappingByteLength,
9897bb
+                    AcpiUtReadUint32 (&IortNode->MappingCount) *
9897bb
+		    sizeof (ACPI_IORT_ID_MAPPING);
9897bb
+                Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
9897bb
+                    Table, NodeLength - NodeOffset - MappingByteLength,
9897bb
                     AcpiDmTableInfoIort1a);
9897bb
                 if (ACPI_FAILURE (Status))
9897bb
                 {
9897bb
@@ -274,9 +281,11 @@ AcpiDmDumpIort (
9897bb
 
9897bb
             if (IortSmmu)
9897bb
             {
9897bb
+	        UINT32 InterruptCount;
9897bb
+
9897bb
                 Length = 2 * sizeof (UINT64);
9897bb
-                NodeOffset = IortSmmu->GlobalInterruptOffset;
9897bb
-                Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
9897bb
+                NodeOffset = AcpiUtReadUint32 (&IortSmmu->GlobalInterruptOffset);
9897bb
+                Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
9897bb
                     ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
9897bb
                     Length, AcpiDmTableInfoIort3a);
9897bb
                 if (ACPI_FAILURE (Status))
9897bb
@@ -284,10 +293,11 @@ AcpiDmDumpIort (
9897bb
                     return;
9897bb
                 }
9897bb
 
9897bb
-                NodeOffset = IortSmmu->ContextInterruptOffset;
9897bb
-                for (i = 0; i < IortSmmu->ContextInterruptCount; i++)
9897bb
+                NodeOffset = AcpiUtReadUint32 (&IortSmmu->ContextInterruptOffset);
9897bb
+                InterruptCount = AcpiUtReadUint32 (&IortSmmu->ContextInterruptCount);
9897bb
+                for (i = 0; i < InterruptCount; i++)
9897bb
                 {
9897bb
-                    Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
9897bb
+                    Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
9897bb
                         ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
9897bb
                         8, AcpiDmTableInfoIort3b);
9897bb
                     if (ACPI_FAILURE (Status))
9897bb
@@ -298,10 +308,11 @@ AcpiDmDumpIort (
9897bb
                     NodeOffset += 8;
9897bb
                 }
9897bb
 
9897bb
-                NodeOffset = IortSmmu->PmuInterruptOffset;
9897bb
-                for (i = 0; i < IortSmmu->PmuInterruptCount; i++)
9897bb
+                NodeOffset = AcpiUtReadUint32 (&IortSmmu->PmuInterruptOffset);
9897bb
+                InterruptCount = AcpiUtReadUint32 (&IortSmmu->PmuInterruptCount);
9897bb
+                for (i = 0; i < InterruptCount; i++)
9897bb
                 {
9897bb
-                    Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
9897bb
+                    Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
9897bb
                         ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
9897bb
                         8, AcpiDmTableInfoIort3c);
9897bb
                     if (ACPI_FAILURE (Status))
9897bb
@@ -319,12 +330,15 @@ AcpiDmDumpIort (
9897bb
             /* Validate IortRmr to avoid compiler warnings */
9897bb
             if (IortRmr)
9897bb
             {
9897bb
-                NodeOffset = IortRmr->RmrOffset;
9897bb
+	        UINT32 RmrCount;
9897bb
+
9897bb
+                NodeOffset = AcpiUtReadUint32 (&IortRmr->RmrOffset);
9897bb
+                RmrCount = AcpiUtReadUint32 (&IortRmr->RmrCount);
9897bb
                 Length = sizeof (ACPI_IORT_RMR_DESC);
9897bb
-                for (i = 0; i < IortRmr->RmrCount; i++)
9897bb
+                for (i = 0; i < RmrCount; i++)
9897bb
                 {
9897bb
                     AcpiOsPrintf ("\n");
9897bb
-                    Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
9897bb
+                    Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
9897bb
                         ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
9897bb
                         Length, AcpiDmTableInfoIort6a);
9897bb
                     if (ACPI_FAILURE (Status))
9897bb
@@ -344,12 +358,13 @@ AcpiDmDumpIort (
9897bb
 
9897bb
         /* Dump the ID mappings */
9897bb
 
9897bb
-        NodeOffset = IortNode->MappingOffset;
9897bb
-        for (i = 0; i < IortNode->MappingCount; i++)
9897bb
+        NodeOffset = AcpiUtReadUint32 (&IortNode->MappingOffset);
9897bb
+        MappingCount = AcpiUtReadUint32 (&IortNode->MappingCount);
9897bb
+        for (i = 0; i < MappingCount; i++)
9897bb
         {
9897bb
             AcpiOsPrintf ("\n");
9897bb
             Length = sizeof (ACPI_IORT_ID_MAPPING);
9897bb
-            Status = AcpiDmDumpTable (Table->Length, Offset + NodeOffset,
9897bb
+            Status = AcpiDmDumpTable (TableLength, Offset + NodeOffset,
9897bb
                 ACPI_ADD_PTR (ACPI_IORT_NODE, IortNode, NodeOffset),
9897bb
                 Length, AcpiDmTableInfoIortMap);
9897bb
             if (ACPI_FAILURE (Status))
9897bb
@@ -363,7 +378,7 @@ AcpiDmDumpIort (
9897bb
 NextSubtable:
9897bb
         /* Point to next node subtable */
9897bb
 
9897bb
-        Offset += IortNode->Length;
9897bb
+        Offset += AcpiUtReadUint16 (&IortNode->Length);
9897bb
     }
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
@@ -1592,6 +1592,7 @@ DtCompileIort (
9897bb
     ACPI_IORT_ITS_GROUP     *IortItsGroup;
9897bb
     ACPI_IORT_SMMU          *IortSmmu;
9897bb
     ACPI_IORT_RMR           *IortRmr;
9897bb
+    UINT32                  IortNodeOffset;
9897bb
     UINT32                  NodeNumber;
9897bb
     UINT32                  NodeLength;
9897bb
     UINT32                  IdMappingNumber;
9897bb
@@ -1637,7 +1638,7 @@ DtCompileIort (
9897bb
      * Optionally allows the generic data types to be used for filling
9897bb
      * this field.
9897bb
      */
9897bb
-    Iort->NodeOffset = sizeof (ACPI_TABLE_IORT);
9897bb
+    IortNodeOffset = sizeof (ACPI_TABLE_IORT);
9897bb
     Status = DtCompileTable (PFieldList, AcpiDmTableInfoIortPad,
9897bb
         &Subtable);
9897bb
     if (ACPI_FAILURE (Status))
9897bb
@@ -1647,7 +1648,7 @@ DtCompileIort (
9897bb
     if (Subtable)
9897bb
     {
9897bb
         DtInsertSubtable (ParentTable, Subtable);
9897bb
-        Iort->NodeOffset += Subtable->Length;
9897bb
+        IortNodeOffset += Subtable->Length;
9897bb
     }
9897bb
     else
9897bb
     {
9897bb
@@ -1657,7 +1658,7 @@ DtCompileIort (
9897bb
         {
9897bb
             return (Status);
9897bb
         }
9897bb
-        Iort->NodeOffset += PaddingLength;
9897bb
+        IortNodeOffset += PaddingLength;
9897bb
     }
9897bb
 
9897bb
     NodeNumber = 0;
9897bb
@@ -1721,7 +1722,7 @@ DtCompileIort (
9897bb
                 ItsNumber++;
9897bb
             }
9897bb
 
9897bb
-            IortItsGroup->ItsCount = ItsNumber;
9897bb
+            IortItsGroup->ItsCount = AcpiUtReadUint32 (&ItsNumber);
9897bb
             break;
9897bb
 
9897bb
         case ACPI_IORT_NODE_NAMED_COMPONENT:
9897bb
@@ -1755,15 +1756,18 @@ DtCompileIort (
9897bb
             }
9897bb
             else
9897bb
             {
9897bb
-                if (NodeLength > IortNode->MappingOffset)
9897bb
+	        UINT32 MappingOffset;
9897bb
+
9897bb
+                MappingOffset = IortNode->MappingOffset;
9897bb
+                if (NodeLength > MappingOffset)
9897bb
                 {
9897bb
                     return (AE_BAD_DATA);
9897bb
                 }
9897bb
 
9897bb
-                if (NodeLength < IortNode->MappingOffset)
9897bb
+                if (NodeLength < MappingOffset)
9897bb
                 {
9897bb
                     Status = DtCompilePadding (
9897bb
-                        IortNode->MappingOffset - NodeLength,
9897bb
+                        MappingOffset - NodeLength,
9897bb
                         &Subtable);
9897bb
                     if (ACPI_FAILURE (Status))
9897bb
                     {
9897bb
@@ -1771,7 +1775,7 @@ DtCompileIort (
9897bb
                     }
9897bb
 
9897bb
                     DtInsertSubtable (ParentTable, Subtable);
9897bb
-                    NodeLength = IortNode->MappingOffset;
9897bb
+                    NodeLength = MappingOffset;
9897bb
                 }
9897bb
             }
9897bb
             break;
9897bb
@@ -1804,7 +1808,7 @@ DtCompileIort (
9897bb
 
9897bb
             /* Compile global interrupt array */
9897bb
 
9897bb
-            IortSmmu->GlobalInterruptOffset = NodeLength;
9897bb
+            IortSmmu->GlobalInterruptOffset = AcpiUtReadUint32 (&NodeLength);
9897bb
             Status = DtCompileTable (PFieldList, AcpiDmTableInfoIort3a,
9897bb
                 &Subtable);
9897bb
             if (ACPI_FAILURE (Status))
9897bb
@@ -1818,7 +1822,7 @@ DtCompileIort (
9897bb
             /* Compile context interrupt array */
9897bb
 
9897bb
             ContextIrptNumber = 0;
9897bb
-            IortSmmu->ContextInterruptOffset = NodeLength;
9897bb
+            IortSmmu->ContextInterruptOffset = AcpiUtReadUint32 (&NodeLength);
9897bb
             while (*PFieldList)
9897bb
             {
9897bb
                 Status = DtCompileTable (PFieldList, AcpiDmTableInfoIort3b,
9897bb
@@ -1838,12 +1842,12 @@ DtCompileIort (
9897bb
                 ContextIrptNumber++;
9897bb
             }
9897bb
 
9897bb
-            IortSmmu->ContextInterruptCount = ContextIrptNumber;
9897bb
+            IortSmmu->ContextInterruptCount = AcpiUtReadUint32 (&ContextIrptNumber);
9897bb
 
9897bb
             /* Compile PMU interrupt array */
9897bb
 
9897bb
             PmuIrptNumber = 0;
9897bb
-            IortSmmu->PmuInterruptOffset = NodeLength;
9897bb
+            IortSmmu->PmuInterruptOffset = AcpiUtReadUint32 (&NodeLength);
9897bb
             while (*PFieldList)
9897bb
             {
9897bb
                 Status = DtCompileTable (PFieldList, AcpiDmTableInfoIort3c,
9897bb
@@ -1863,7 +1867,7 @@ DtCompileIort (
9897bb
                 PmuIrptNumber++;
9897bb
             }
9897bb
 
9897bb
-            IortSmmu->PmuInterruptCount = PmuIrptNumber;
9897bb
+            IortSmmu->PmuInterruptCount = AcpiUtReadUint32 (&PmuIrptNumber);
9897bb
             break;
9897bb
 
9897bb
         case ACPI_IORT_NODE_SMMU_V3:
9897bb
@@ -1908,7 +1912,7 @@ DtCompileIort (
9897bb
             /* Compile RMR Descriptors */
9897bb
 
9897bb
             RmrCount = 0;
9897bb
-            IortRmr->RmrOffset = NodeLength;
9897bb
+            IortRmr->RmrOffset = AcpiUtReadUint32 (&NodeLength);
9897bb
             while (*PFieldList)
9897bb
             {
9897bb
                 Status = DtCompileTable (PFieldList, AcpiDmTableInfoIort6a,
9897bb
@@ -1928,7 +1932,7 @@ DtCompileIort (
9897bb
                 RmrCount++;
9897bb
             }
9897bb
 
9897bb
-            IortRmr->RmrCount = RmrCount;
9897bb
+            IortRmr->RmrCount = AcpiUtReadUint32 (&RmrCount);
9897bb
             break;
9897bb
 
9897bb
 	default:
9897bb
@@ -1939,7 +1943,7 @@ DtCompileIort (
9897bb
 
9897bb
         /* Compile Array of ID mappings */
9897bb
 
9897bb
-        IortNode->MappingOffset = NodeLength;
9897bb
+        IortNode->MappingOffset = AcpiUtReadUint32 (&NodeLength);
9897bb
         IdMappingNumber = 0;
9897bb
         while (*PFieldList)
9897bb
         {
9897bb
@@ -1960,7 +1964,7 @@ DtCompileIort (
9897bb
             IdMappingNumber++;
9897bb
         }
9897bb
 
9897bb
-        IortNode->MappingCount = IdMappingNumber;
9897bb
+        IortNode->MappingCount = AcpiUtReadUint32 (&IdMappingNumber);
9897bb
         if (!IdMappingNumber)
9897bb
         {
9897bb
             IortNode->MappingOffset = 0;
9897bb
@@ -1975,7 +1979,7 @@ DtCompileIort (
9897bb
         NodeNumber++;
9897bb
     }
9897bb
 
9897bb
-    Iort->NodeCount = NodeNumber;
9897bb
+    Iort->NodeCount = AcpiUtReadUint32 (&NodeNumber);
9897bb
     return (AE_OK);
9897bb
 }
9897bb