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

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