Blame SOURCES/0026-Support-NFIT-in-a-big-endian-world.patch

9897bb
From 5aec8511fc433a71cb8b6d26be464355d0c3f5cc Mon Sep 17 00:00:00 2001
9897bb
From: Al Stone <ahs3@redhat.com>
9897bb
Date: Thu, 24 Sep 2020 15:25:53 -0600
9897bb
Subject: [PATCH 26/45] Support NFIT in a big-endian world
9897bb
9897bb
NB: this required correcting the starting pointer for the NFIT
9897bb
SMBIOS subtable; otherwise, disassembly did not work properly.
9897bb
9897bb
Signed-off-by: Al Stone <ahs3@redhat.com>
9897bb
---
9897bb
 source/common/dmtable.c    |  4 ++--
9897bb
 source/common/dmtbdump2.c  | 49 ++++++++++++++++++++++----------------
9897bb
 source/compiler/dttable2.c | 11 ++++++---
9897bb
 3 files changed, 39 insertions(+), 25 deletions(-)
9897bb
9897bb
Index: acpica-unix2-20210604/source/common/dmtable.c
9897bb
===================================================================
9897bb
--- acpica-unix2-20210604.orig/source/common/dmtable.c
9897bb
+++ acpica-unix2-20210604/source/common/dmtable.c
9897bb
@@ -1526,13 +1526,13 @@ AcpiDmDumpTable (
9897bb
 
9897bb
             /* NFIT subtable types */
9897bb
 
9897bb
-            Temp16 = ACPI_GET16 (Target);
9897bb
+            Temp16 = AcpiUtReadUint16 (Target);
9897bb
             if (Temp16 > ACPI_NFIT_TYPE_RESERVED)
9897bb
             {
9897bb
                 Temp16 = ACPI_NFIT_TYPE_RESERVED;
9897bb
             }
9897bb
 
9897bb
-            AcpiOsPrintf (UINT16_FORMAT, ACPI_GET16 (Target),
9897bb
+            AcpiOsPrintf (UINT16_FORMAT, Temp16,
9897bb
                 AcpiDmNfitSubnames[Temp16]);
9897bb
             break;
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
@@ -1192,18 +1192,23 @@ AcpiDmDumpNfit (
9897bb
     ACPI_STATUS             Status;
9897bb
     UINT32                  Offset = sizeof (ACPI_TABLE_NFIT);
9897bb
     UINT32                  FieldOffset = 0;
9897bb
-    UINT32                  Length;
9897bb
+    UINT32                  TableLength = AcpiUtReadUint32 (&Table->Length);
9897bb
     ACPI_NFIT_HEADER        *Subtable;
9897bb
     ACPI_DMTABLE_INFO       *InfoTable;
9897bb
     ACPI_NFIT_INTERLEAVE    *Interleave = NULL;
9897bb
     ACPI_NFIT_SMBIOS        *SmbiosInfo = NULL;
9897bb
     ACPI_NFIT_FLUSH_ADDRESS *Hint = NULL;
9897bb
     UINT32                  i;
9897bb
+    UINT32                  Length;
9897bb
+    UINT32                  LineCount;
9897bb
+    UINT16                  SubtableLength;
9897bb
+    UINT16                  SubtableType;
9897bb
+    UINT16                  HintCount;
9897bb
 
9897bb
 
9897bb
     /* Main table */
9897bb
 
9897bb
-    Status = AcpiDmDumpTable (Table->Length, 0, Table, 0, AcpiDmTableInfoNfit);
9897bb
+    Status = AcpiDmDumpTable (TableLength, 0, Table, 0, AcpiDmTableInfoNfit);
9897bb
     if (ACPI_FAILURE (Status))
9897bb
     {
9897bb
         return;
9897bb
@@ -1212,19 +1217,21 @@ AcpiDmDumpNfit (
9897bb
     /* Subtables */
9897bb
 
9897bb
     Subtable = ACPI_ADD_PTR (ACPI_NFIT_HEADER, Table, Offset);
9897bb
-    while (Offset < Table->Length)
9897bb
+    while (Offset < TableLength)
9897bb
     {
9897bb
         /* NFIT subtable header */
9897bb
 
9897bb
         AcpiOsPrintf ("\n");
9897bb
-        Status = AcpiDmDumpTable (Table->Length, Offset, Subtable,
9897bb
-            Subtable->Length, AcpiDmTableInfoNfitHdr);
9897bb
+        SubtableType = AcpiUtReadUint16 (&Subtable->Type);
9897bb
+        SubtableLength = AcpiUtReadUint16 (&Subtable->Length);
9897bb
+        Status = AcpiDmDumpTable (TableLength, Offset, Subtable,
9897bb
+            SubtableLength, AcpiDmTableInfoNfitHdr);
9897bb
         if (ACPI_FAILURE (Status))
9897bb
         {
9897bb
             return;
9897bb
         }
9897bb
 
9897bb
-        switch (Subtable->Type)
9897bb
+        switch (SubtableType)
9897bb
         {
9897bb
         case ACPI_NFIT_TYPE_SYSTEM_ADDRESS:
9897bb
 
9897bb
@@ -1275,11 +1282,11 @@ AcpiDmDumpNfit (
9897bb
 
9897bb
         default:
9897bb
             AcpiOsPrintf ("\n**** Unknown NFIT subtable type 0x%X\n",
9897bb
-                Subtable->Type);
9897bb
+                SubtableType);
9897bb
 
9897bb
             /* Attempt to continue */
9897bb
 
9897bb
-            if (!Subtable->Length)
9897bb
+            if (!SubtableLength)
9897bb
             {
9897bb
                 AcpiOsPrintf ("Invalid zero length subtable\n");
9897bb
                 return;
9897bb
@@ -1288,8 +1295,8 @@ AcpiDmDumpNfit (
9897bb
         }
9897bb
 
9897bb
         AcpiOsPrintf ("\n");
9897bb
-        Status = AcpiDmDumpTable (Table->Length, Offset, Subtable,
9897bb
-            Subtable->Length, InfoTable);
9897bb
+        Status = AcpiDmDumpTable (TableLength, Offset, Subtable,
9897bb
+            SubtableLength, InfoTable);
9897bb
         if (ACPI_FAILURE (Status))
9897bb
         {
9897bb
             return;
9897bb
@@ -1297,14 +1304,15 @@ AcpiDmDumpNfit (
9897bb
 
9897bb
         /* Per-subtable variable-length fields */
9897bb
 
9897bb
-        switch (Subtable->Type)
9897bb
+        switch (SubtableType)
9897bb
         {
9897bb
         case ACPI_NFIT_TYPE_INTERLEAVE:
9897bb
 
9897bb
             Interleave = ACPI_CAST_PTR (ACPI_NFIT_INTERLEAVE, Subtable);
9897bb
-            for (i = 0; i < Interleave->LineCount; i++)
9897bb
+            LineCount = AcpiUtReadUint32 (&Interleave->LineCount);
9897bb
+            for (i = 0; i < LineCount; i++)
9897bb
             {
9897bb
-                Status = AcpiDmDumpTable (Table->Length, Offset + FieldOffset,
9897bb
+                Status = AcpiDmDumpTable (TableLength, Offset + FieldOffset,
9897bb
                     &Interleave->LineOffset[i],
9897bb
                     sizeof (UINT32), AcpiDmTableInfoNfit2a);
9897bb
                 if (ACPI_FAILURE (Status))
9897bb
@@ -1318,14 +1326,14 @@ AcpiDmDumpNfit (
9897bb
 
9897bb
         case ACPI_NFIT_TYPE_SMBIOS:
9897bb
 
9897bb
-            Length = Subtable->Length -
9897bb
+            Length = SubtableLength -
9897bb
                 sizeof (ACPI_NFIT_SMBIOS) + sizeof (UINT8);
9897bb
 
9897bb
             if (Length)
9897bb
             {
9897bb
-                Status = AcpiDmDumpTable (Table->Length,
9897bb
+                Status = AcpiDmDumpTable (TableLength,
9897bb
                     sizeof (ACPI_NFIT_SMBIOS) - sizeof (UINT8),
9897bb
-                    SmbiosInfo,
9897bb
+                    SmbiosInfo + Offset,
9897bb
                     Length, AcpiDmTableInfoNfit3a);
9897bb
                 if (ACPI_FAILURE (Status))
9897bb
                 {
9897bb
@@ -1338,9 +1346,10 @@ AcpiDmDumpNfit (
9897bb
         case ACPI_NFIT_TYPE_FLUSH_ADDRESS:
9897bb
 
9897bb
             Hint = ACPI_CAST_PTR (ACPI_NFIT_FLUSH_ADDRESS, Subtable);
9897bb
-            for (i = 0; i < Hint->HintCount; i++)
9897bb
+            HintCount = AcpiUtReadUint16 (&Hint->HintCount);
9897bb
+            for (i = 0; i < HintCount; i++)
9897bb
             {
9897bb
-                Status = AcpiDmDumpTable (Table->Length, Offset + FieldOffset,
9897bb
+                Status = AcpiDmDumpTable (TableLength, Offset + FieldOffset,
9897bb
                     &Hint->HintAddress[i],
9897bb
                     sizeof (UINT64), AcpiDmTableInfoNfit6a);
9897bb
                 if (ACPI_FAILURE (Status))
9897bb
@@ -1359,8 +1368,8 @@ AcpiDmDumpNfit (
9897bb
 NextSubtable:
9897bb
         /* Point to next subtable */
9897bb
 
9897bb
-        Offset += Subtable->Length;
9897bb
-        Subtable = ACPI_ADD_PTR (ACPI_NFIT_HEADER, Subtable, Subtable->Length);
9897bb
+        Offset += SubtableLength;
9897bb
+        Subtable = ACPI_ADD_PTR (ACPI_NFIT_HEADER, Subtable, SubtableLength);
9897bb
     }
9897bb
 }
9897bb
 
9897bb
Index: acpica-unix2-20210604/source/compiler/dttable2.c
9897bb
===================================================================
9897bb
--- acpica-unix2-20210604.orig/source/compiler/dttable2.c
9897bb
+++ acpica-unix2-20210604/source/compiler/dttable2.c
9897bb
@@ -497,6 +497,7 @@ DtCompileNfit (
9897bb
     UINT32                  Count;
9897bb
     ACPI_NFIT_INTERLEAVE    *Interleave = NULL;
9897bb
     ACPI_NFIT_FLUSH_ADDRESS *Hint = NULL;
9897bb
+    UINT16                  NfitHeaderType;
9897bb
 
9897bb
 
9897bb
     /* Main table */
9897bb
@@ -530,7 +531,8 @@ DtCompileNfit (
9897bb
 
9897bb
         NfitHeader = ACPI_CAST_PTR (ACPI_NFIT_HEADER, Subtable->Buffer);
9897bb
 
9897bb
-        switch (NfitHeader->Type)
9897bb
+        NfitHeaderType = AcpiUtReadUint16 (&NfitHeader->Type);
9897bb
+        switch (NfitHeaderType)
9897bb
         {
9897bb
         case ACPI_NFIT_TYPE_SYSTEM_ADDRESS:
9897bb
 
9897bb
@@ -590,7 +592,7 @@ DtCompileNfit (
9897bb
         DtInsertSubtable (ParentTable, Subtable);
9897bb
         DtPopSubtable ();
9897bb
 
9897bb
-        switch (NfitHeader->Type)
9897bb
+        switch (NfitHeaderType)
9897bb
         {
9897bb
         case ACPI_NFIT_TYPE_INTERLEAVE:
9897bb
 
9897bb
@@ -616,7 +618,8 @@ DtCompileNfit (
9897bb
                 Count++;
9897bb
             }
9897bb
 
9897bb
-            Interleave->LineCount = Count;
9897bb
+            AcpiUtWriteUint (&Interleave->LineCount, sizeof (UINT32),
9897bb
+                &Count, sizeof (UINT32));
9897bb
             break;
9897bb
 
9897bb
         case ACPI_NFIT_TYPE_SMBIOS:
9897bb
@@ -662,6 +665,8 @@ DtCompileNfit (
9897bb
             }
9897bb
 
9897bb
             Hint->HintCount = (UINT16) Count;
9897bb
+            AcpiUtWriteUint (&Hint->HintCount, sizeof (UINT16),
9897bb
+                &Count, sizeof (UINT32));
9897bb
             break;
9897bb
 
9897bb
         default: