Blame SOURCES/0046-Support-PHAT-in-a-big-endian-world.patch

214d7a
From 5fd729c8f6c4ce295edd142fc41e03e831ba4afb Mon Sep 17 00:00:00 2001
214d7a
From: Al Stone <ahs3@redhat.com>
214d7a
Date: Mon, 12 Jul 2021 09:39:38 -0600
214d7a
Subject: [PATCH] Support PHAT in a big-endian world
214d7a
214d7a
Signed-off-by: Al Stone <ahs3@redhat.com>
214d7a
---
214d7a
 source/common/dmtbdump2.c  | 36 ++++++++++++++++++++----------------
214d7a
 source/compiler/dttable2.c | 12 +++++++++---
214d7a
 2 files changed, 29 insertions(+), 19 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
@@ -1573,39 +1573,41 @@ AcpiDmDumpPhat (
214d7a
     ACPI_PHAT_HEADER        *Subtable;
214d7a
     ACPI_PHAT_VERSION_DATA  *VersionData;
214d7a
     UINT32                  RecordCount;
214d7a
-    UINT32                  Length = Table->Length;
214d7a
+    UINT32                  TableLength = AcpiUtReadUint32 (&Table->Length);
214d7a
     UINT32                  Offset = sizeof (ACPI_TABLE_PHAT);
214d7a
-    UINT32                  SubtableLength;
214d7a
+    UINT16                  SubtableLength;
214d7a
     UINT32                  PathLength;
214d7a
     UINT32                  VendorLength;
214d7a
+    UINT16                  SubtableType;
214d7a
 
214d7a
 
214d7a
     Subtable = ACPI_ADD_PTR (ACPI_PHAT_HEADER, Table, sizeof (ACPI_TABLE_PHAT));
214d7a
 
214d7a
-    while (Offset < Table->Length)
214d7a
+    while (Offset < TableLength)
214d7a
     {
214d7a
         /* Common subtable header */
214d7a
 
214d7a
+        SubtableType = AcpiUtReadUint16 (&Subtable->Type);
214d7a
+        SubtableLength = AcpiUtReadUint16 (&Subtable->Length);
214d7a
+
214d7a
         AcpiOsPrintf ("\n");
214d7a
-        Status = AcpiDmDumpTable (Length, 0, Subtable,
214d7a
+        Status = AcpiDmDumpTable (TableLength, 0, Subtable,
214d7a
             sizeof (ACPI_PHAT_HEADER), AcpiDmTableInfoPhatHdr);
214d7a
         if (ACPI_FAILURE (Status))
214d7a
         {
214d7a
             return;
214d7a
         }
214d7a
 
214d7a
-        switch (Subtable->Type)
214d7a
+        switch (SubtableType)
214d7a
         {
214d7a
         case ACPI_PHAT_TYPE_FW_VERSION_DATA:
214d7a
 
214d7a
             InfoTable = AcpiDmTableInfoPhat0;
214d7a
-            SubtableLength = sizeof (ACPI_PHAT_VERSION_DATA);
214d7a
             break;
214d7a
 
214d7a
         case ACPI_PHAT_TYPE_FW_HEALTH_DATA:
214d7a
 
214d7a
             InfoTable = AcpiDmTableInfoPhat1;
214d7a
-            SubtableLength = sizeof (ACPI_PHAT_HEALTH_DATA);
214d7a
             break;
214d7a
 
214d7a
         default:
214d7a
@@ -1616,22 +1618,22 @@ AcpiDmDumpPhat (
214d7a
             return;
214d7a
         }
214d7a
 
214d7a
-        Status = AcpiDmDumpTable (Length, 0, Subtable,
214d7a
+        Status = AcpiDmDumpTable (TableLength, 0, Subtable,
214d7a
             SubtableLength, InfoTable);
214d7a
         if (ACPI_FAILURE (Status))
214d7a
         {
214d7a
             return;
214d7a
         }
214d7a
 
214d7a
-        switch (Subtable->Type)
214d7a
+        switch (SubtableType)
214d7a
         {
214d7a
         case ACPI_PHAT_TYPE_FW_VERSION_DATA:
214d7a
 
214d7a
             VersionData = ACPI_CAST_PTR (ACPI_PHAT_VERSION_DATA, Subtable);
214d7a
-            RecordCount = VersionData->ElementCount;
214d7a
+            RecordCount = AcpiUtReadUint32 (&VersionData->ElementCount);
214d7a
             while (RecordCount)
214d7a
             {
214d7a
-                Status = AcpiDmDumpTable (Length, Offset,
214d7a
+                Status = AcpiDmDumpTable (TableLength, Offset,
214d7a
                     ACPI_ADD_PTR (ACPI_PHAT_HEADER, Subtable, sizeof (ACPI_PHAT_VERSION_DATA)),
214d7a
                     sizeof (ACPI_PHAT_VERSION_ELEMENT), AcpiDmTableInfoPhat0a);
214d7a
                 if (ACPI_FAILURE (Status))
214d7a
@@ -1649,7 +1651,7 @@ AcpiDmDumpPhat (
214d7a
             /* account for the null terminator */
214d7a
 
214d7a
             PathLength = strlen (ACPI_ADD_PTR (char, Subtable, sizeof (ACPI_PHAT_HEALTH_DATA))) + 1;
214d7a
-            Status = AcpiDmDumpTable (Length, Offset,
214d7a
+            Status = AcpiDmDumpTable (TableLength, Offset,
214d7a
                 ACPI_ADD_PTR (ACPI_PHAT_HEADER, Subtable, sizeof (ACPI_PHAT_HEALTH_DATA)),
214d7a
                 PathLength, AcpiDmTableInfoPhat1a);
214d7a
             if (ACPI_FAILURE (Status))
214d7a
@@ -1660,8 +1662,8 @@ AcpiDmDumpPhat (
214d7a
             /* Get vendor data - data length is the remaining subtable length */
214d7a
 
214d7a
             VendorLength =
214d7a
-                Subtable->Length - sizeof (ACPI_PHAT_HEALTH_DATA) - PathLength;
214d7a
-            Status = AcpiDmDumpTable (Length, 0,
214d7a
+                SubtableLength - sizeof (ACPI_PHAT_HEALTH_DATA) - PathLength;
214d7a
+            Status = AcpiDmDumpTable (TableLength, 0,
214d7a
                 ACPI_ADD_PTR (ACPI_PHAT_HEADER, Subtable, sizeof (ACPI_PHAT_HEALTH_DATA) + PathLength),
214d7a
                 VendorLength, AcpiDmTableInfoPhat1b);
214d7a
             if (ACPI_FAILURE (Status))
214d7a
@@ -1673,15 +1675,15 @@ AcpiDmDumpPhat (
214d7a
         default:
214d7a
 
214d7a
             AcpiOsPrintf ("\n**** Unknown PHAT subtable type 0x%X\n\n",
214d7a
-                Subtable->Type);
214d7a
+                SubtableType);
214d7a
             return;
214d7a
         }
214d7a
 
214d7a
         /* Next subtable */
214d7a
 
214d7a
-        Offset += Subtable->Length;
214d7a
+        Offset += SubtableLength;
214d7a
         Subtable = ACPI_ADD_PTR (ACPI_PHAT_HEADER, Subtable,
214d7a
-            Subtable->Length);
214d7a
+            SubtableLength);
214d7a
     }
214d7a
 }
214d7a
 
214d7a
Index: acpica-unix2-20210604/source/compiler/dttable2.c
214d7a
===================================================================
214d7a
--- acpica-unix2-20210604.orig/source/compiler/dttable2.c
214d7a
+++ acpica-unix2-20210604/source/compiler/dttable2.c
214d7a
@@ -870,6 +870,8 @@ DtCompilePhat (
214d7a
     ACPI_DMTABLE_INFO       *Info;
214d7a
     ACPI_PHAT_VERSION_DATA  *VersionData;
214d7a
     UINT32                  RecordCount;
214d7a
+    UINT16                  SubtableType;
214d7a
+    UINT16                  Tmp16;
214d7a
 
214d7a
 
214d7a
     /* The table consist of subtables */
214d7a
@@ -887,8 +889,9 @@ DtCompilePhat (
214d7a
         DtPushSubtable (Subtable);
214d7a
 
214d7a
         PhatHeader = ACPI_CAST_PTR (ACPI_PHAT_HEADER, Subtable->Buffer);
214d7a
+	SubtableType = AcpiUtReadUint16 (&PhatHeader->Type);
214d7a
 
214d7a
-        switch (PhatHeader->Type)
214d7a
+        switch (SubtableType)
214d7a
         {
214d7a
         case ACPI_PHAT_TYPE_FW_VERSION_DATA:
214d7a
 
214d7a
@@ -919,13 +922,13 @@ DtCompilePhat (
214d7a
         ParentTable = DtPeekSubtable ();
214d7a
         DtInsertSubtable (ParentTable, Subtable);
214d7a
 
214d7a
-        switch (PhatHeader->Type)
214d7a
+        switch (SubtableType)
214d7a
         {
214d7a
         case ACPI_PHAT_TYPE_FW_VERSION_DATA:
214d7a
 
214d7a
             VersionData = ACPI_CAST_PTR (ACPI_PHAT_VERSION_DATA,
214d7a
                 (Subtable->Buffer - sizeof (ACPI_PHAT_HEADER)));
214d7a
-            RecordCount = VersionData->ElementCount;
214d7a
+            RecordCount = AcpiUtReadUint32 (&VersionData->ElementCount);
214d7a
 
214d7a
             while (RecordCount)
214d7a
             {
214d7a
@@ -976,6 +979,9 @@ DtCompilePhat (
214d7a
             DtFatal (ASL_MSG_UNKNOWN_SUBTABLE, *PFieldList, "PHAT");
214d7a
             return (AE_ERROR);
214d7a
         }
214d7a
+
214d7a
+	Tmp16 = AcpiUtReadUint16 (&PhatHeader->Length);
214d7a
+	PhatHeader->Length = Tmp16;
214d7a
     }
214d7a
 
214d7a
     return (Status);