Blame SOURCES/0011-Support-DBG2-table-in-a-big-endian-world.patch

9897bb
From 2cb0b87a15682da4f19f707fa3ffece504f94b5a Mon Sep 17 00:00:00 2001
9897bb
From: Al Stone <ahs3@redhat.com>
9897bb
Date: Sat, 19 Sep 2020 13:37:38 -0600
9897bb
Subject: [PATCH 11/45] Support DBG2 table in a big-endian world
9897bb
9897bb
Signed-off-by: Al Stone <ahs3@redhat.com>
9897bb
---
9897bb
 source/common/dmtbdump1.c  | 37 ++++++++++++++++++--------------
9897bb
 source/compiler/dttable1.c | 43 ++++++++++++++++++++++++--------------
9897bb
 2 files changed, 48 insertions(+), 32 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
@@ -374,7 +374,7 @@ AcpiDmDumpCsrt (
9897bb
     ACPI_CSRT_GROUP         *Subtable;
9897bb
     ACPI_CSRT_SHARED_INFO   *SharedInfoTable;
9897bb
     ACPI_CSRT_DESCRIPTOR    *SubSubtable;
9897bb
-    UINT32                  Length = Table->Length;
9897bb
+    UINT32                  Length = AcpiUtReadUint32 (&Table->Length);
9897bb
     UINT32                  Offset = sizeof (ACPI_TABLE_CSRT);
9897bb
     UINT32                  SubOffset;
9897bb
     UINT32                  SubSubOffset;
9897bb
@@ -386,7 +386,7 @@ AcpiDmDumpCsrt (
9897bb
     /* Subtables (Resource Groups) */
9897bb
 
9897bb
     Subtable = ACPI_ADD_PTR (ACPI_CSRT_GROUP, Table, Offset);
9897bb
-    while (Offset < Table->Length)
9897bb
+    while (Offset < Length)
9897bb
     {
9897bb
         /* Resource group subtable */
9897bb
 
9897bb
@@ -420,7 +420,7 @@ AcpiDmDumpCsrt (
9897bb
             Offset + SubOffset);
9897bb
 
9897bb
         while ((SubOffset < Subtable->Length) &&
9897bb
-              ((Offset + SubOffset) < Table->Length))
9897bb
+              ((Offset + SubOffset) < Length))
9897bb
         {
9897bb
             AcpiOsPrintf ("\n");
9897bb
             Status = AcpiDmDumpTable (Length, Offset + SubOffset, SubSubtable,
9897bb
@@ -481,12 +481,13 @@ AcpiDmDumpDbg2 (
9897bb
 {
9897bb
     ACPI_STATUS             Status;
9897bb
     ACPI_DBG2_DEVICE        *Subtable;
9897bb
-    UINT32                  Length = Table->Length;
9897bb
+    UINT32                  Length = AcpiUtReadUint32 (&Table->Length);
9897bb
     UINT32                  Offset = sizeof (ACPI_TABLE_DBG2);
9897bb
     UINT32                  i;
9897bb
     UINT32                  ArrayOffset;
9897bb
     UINT32                  AbsoluteOffset;
9897bb
     UINT8                   *Array;
9897bb
+    UINT16                  SubtableLength;
9897bb
 
9897bb
 
9897bb
     /* Main table */
9897bb
@@ -500,11 +501,12 @@ AcpiDmDumpDbg2 (
9897bb
     /* Subtables */
9897bb
 
9897bb
     Subtable = ACPI_ADD_PTR (ACPI_DBG2_DEVICE, Table, Offset);
9897bb
-    while (Offset < Table->Length)
9897bb
+    while (Offset < Length)
9897bb
     {
9897bb
         AcpiOsPrintf ("\n");
9897bb
+        SubtableLength = AcpiUtReadUint16 (&Subtable->Length);
9897bb
         Status = AcpiDmDumpTable (Length, Offset, Subtable,
9897bb
-            Subtable->Length, AcpiDmTableInfoDbg2Device);
9897bb
+            SubtableLength, AcpiDmTableInfoDbg2Device);
9897bb
         if (ACPI_FAILURE (Status))
9897bb
         {
9897bb
             return;
9897bb
@@ -514,13 +516,13 @@ AcpiDmDumpDbg2 (
9897bb
 
9897bb
         for (i = 0; i < Subtable->RegisterCount; i++)
9897bb
         {
9897bb
-            ArrayOffset = Subtable->BaseAddressOffset +
9897bb
+            ArrayOffset = AcpiUtReadUint16 (&Subtable->BaseAddressOffset) +
9897bb
                 (sizeof (ACPI_GENERIC_ADDRESS) * i);
9897bb
             AbsoluteOffset = Offset + ArrayOffset;
9897bb
             Array = (UINT8 *) Subtable + ArrayOffset;
9897bb
 
9897bb
             Status = AcpiDmDumpTable (Length, AbsoluteOffset, Array,
9897bb
-                Subtable->Length, AcpiDmTableInfoDbg2Addr);
9897bb
+                SubtableLength, AcpiDmTableInfoDbg2Addr);
9897bb
             if (ACPI_FAILURE (Status))
9897bb
             {
9897bb
                 return;
9897bb
@@ -531,13 +533,13 @@ AcpiDmDumpDbg2 (
9897bb
 
9897bb
         for (i = 0; i < Subtable->RegisterCount; i++)
9897bb
         {
9897bb
-            ArrayOffset = Subtable->AddressSizeOffset +
9897bb
+            ArrayOffset = AcpiUtReadUint16 (&Subtable->AddressSizeOffset) +
9897bb
                 (sizeof (UINT32) * i);
9897bb
             AbsoluteOffset = Offset + ArrayOffset;
9897bb
             Array = (UINT8 *) Subtable + ArrayOffset;
9897bb
 
9897bb
             Status = AcpiDmDumpTable (Length, AbsoluteOffset, Array,
9897bb
-                Subtable->Length, AcpiDmTableInfoDbg2Size);
9897bb
+                SubtableLength, AcpiDmTableInfoDbg2Size);
9897bb
             if (ACPI_FAILURE (Status))
9897bb
             {
9897bb
                 return;
9897bb
@@ -547,12 +549,12 @@ AcpiDmDumpDbg2 (
9897bb
         /* Dump the Namestring (required) */
9897bb
 
9897bb
         AcpiOsPrintf ("\n");
9897bb
-        ArrayOffset = Subtable->NamepathOffset;
9897bb
+        ArrayOffset = AcpiUtReadUint16 (&Subtable->NamepathOffset);
9897bb
         AbsoluteOffset = Offset + ArrayOffset;
9897bb
         Array = (UINT8 *) Subtable + ArrayOffset;
9897bb
 
9897bb
         Status = AcpiDmDumpTable (Length, AbsoluteOffset, Array,
9897bb
-            Subtable->Length, AcpiDmTableInfoDbg2Name);
9897bb
+            SubtableLength, AcpiDmTableInfoDbg2Name);
9897bb
         if (ACPI_FAILURE (Status))
9897bb
         {
9897bb
             return;
9897bb
@@ -562,8 +564,11 @@ AcpiDmDumpDbg2 (
9897bb
 
9897bb
         if (Subtable->OemDataOffset)
9897bb
         {
9897bb
-            Status = AcpiDmDumpTable (Length, Offset + Subtable->OemDataOffset,
9897bb
-                Table, Subtable->OemDataLength,
9897bb
+            Array = (UINT8 *) Subtable + AcpiUtReadUint16 (&Subtable->OemDataOffset);
9897bb
+
9897bb
+            Status = AcpiDmDumpTable (Length,
9897bb
+                Offset + AcpiUtReadUint16 (&Subtable->OemDataOffset),
9897bb
+                Array, AcpiUtReadUint16 (&Subtable->OemDataLength),
9897bb
                 AcpiDmTableInfoDbg2OemData);
9897bb
             if (ACPI_FAILURE (Status))
9897bb
             {
9897bb
@@ -573,9 +578,9 @@ AcpiDmDumpDbg2 (
9897bb
 
9897bb
         /* Point to next subtable */
9897bb
 
9897bb
-        Offset += Subtable->Length;
9897bb
+        Offset += SubtableLength;
9897bb
         Subtable = ACPI_ADD_PTR (ACPI_DBG2_DEVICE, Subtable,
9897bb
-            Subtable->Length);
9897bb
+            SubtableLength);
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
@@ -355,6 +355,7 @@ DtCompileCsrt (
9897bb
     DT_FIELD                **PFieldList = (DT_FIELD **) List;
9897bb
     UINT32                  DescriptorCount;
9897bb
     UINT32                  GroupLength;
9897bb
+    UINT32                  Tmp;
9897bb
 
9897bb
 
9897bb
     /* Subtables (Resource Groups) */
9897bb
@@ -373,12 +374,13 @@ DtCompileCsrt (
9897bb
 
9897bb
         /* Compute the number of resource descriptors */
9897bb
 
9897bb
-        GroupLength =
9897bb
-            (ACPI_CAST_PTR (ACPI_CSRT_GROUP,
9897bb
-                Subtable->Buffer))->Length -
9897bb
-            (ACPI_CAST_PTR (ACPI_CSRT_GROUP,
9897bb
-                Subtable->Buffer))->SharedInfoLength -
9897bb
-            sizeof (ACPI_CSRT_GROUP);
9897bb
+        Tmp = AcpiUtReadUint32 (&(ACPI_CAST_PTR (ACPI_CSRT_GROUP,
9897bb
+                                Subtable->Buffer))->Length);
9897bb
+        GroupLength = Tmp;
9897bb
+        Tmp = AcpiUtReadUint32 (&(ACPI_CAST_PTR (ACPI_CSRT_GROUP,
9897bb
+                                Subtable->Buffer))->SharedInfoLength);
9897bb
+        GroupLength -= Tmp;
9897bb
+        GroupLength -= sizeof (ACPI_CSRT_GROUP);
9897bb
 
9897bb
         DescriptorCount = (GroupLength  /
9897bb
             sizeof (ACPI_CSRT_DESCRIPTOR));
9897bb
@@ -466,6 +468,7 @@ DtCompileDbg2 (
9897bb
     ACPI_DBG2_DEVICE        *DeviceInfo;
9897bb
     UINT16                  CurrentOffset;
9897bb
     UINT32                  i;
9897bb
+    UINT32                  Tmp;
9897bb
 
9897bb
 
9897bb
     /* Main table */
9897bb
@@ -482,10 +485,12 @@ DtCompileDbg2 (
9897bb
     /* Main table fields */
9897bb
 
9897bb
     Dbg2Header = ACPI_CAST_PTR (ACPI_DBG2_HEADER, Subtable->Buffer);
9897bb
-    Dbg2Header->InfoOffset = sizeof (ACPI_TABLE_HEADER) + ACPI_PTR_DIFF (
9897bb
-        ACPI_ADD_PTR (UINT8, Dbg2Header, sizeof (ACPI_DBG2_HEADER)), Dbg2Header);
9897bb
+    Tmp = sizeof (ACPI_TABLE_HEADER) + ACPI_PTR_DIFF (
9897bb
+       ACPI_ADD_PTR (UINT8, Dbg2Header, sizeof (ACPI_DBG2_HEADER)), Dbg2Header);
9897bb
+    AcpiUtWriteUint (&Dbg2Header->InfoOffset, sizeof (UINT32),
9897bb
+            &Tmp, sizeof (UINT32));
9897bb
 
9897bb
-    SubtableCount = Dbg2Header->InfoCount;
9897bb
+    SubtableCount = Tmp;
9897bb
     DtPushSubtable (Subtable);
9897bb
 
9897bb
     /* Process all Device Information subtables (Count = InfoCount) */
9897bb
@@ -512,7 +517,8 @@ DtCompileDbg2 (
9897bb
 
9897bb
         /* BaseAddressRegister GAS array (Required, size is RegisterCount) */
9897bb
 
9897bb
-        DeviceInfo->BaseAddressOffset = CurrentOffset;
9897bb
+        AcpiUtWriteUint (&DeviceInfo->BaseAddressOffset, sizeof (UINT16),
9897bb
+                &CurrentOffset, sizeof (UINT16));
9897bb
         for (i = 0; *PFieldList && (i < DeviceInfo->RegisterCount); i++)
9897bb
         {
9897bb
             Status = DtCompileTable (PFieldList, AcpiDmTableInfoDbg2Addr,
9897bb
@@ -528,7 +534,8 @@ DtCompileDbg2 (
9897bb
 
9897bb
         /* AddressSize array (Required, size = RegisterCount) */
9897bb
 
9897bb
-        DeviceInfo->AddressSizeOffset = CurrentOffset;
9897bb
+        AcpiUtWriteUint (&DeviceInfo->AddressSizeOffset, sizeof (UINT16),
9897bb
+                &CurrentOffset, sizeof (UINT16));
9897bb
         for (i = 0; *PFieldList && (i < DeviceInfo->RegisterCount); i++)
9897bb
         {
9897bb
             Status = DtCompileTable (PFieldList, AcpiDmTableInfoDbg2Size,
9897bb
@@ -544,7 +551,8 @@ DtCompileDbg2 (
9897bb
 
9897bb
         /* NamespaceString device identifier (Required, size = NamePathLength) */
9897bb
 
9897bb
-        DeviceInfo->NamepathOffset = CurrentOffset;
9897bb
+        AcpiUtWriteUint (&DeviceInfo->NamepathOffset, sizeof (UINT16),
9897bb
+            &CurrentOffset, sizeof (UINT16));
9897bb
         Status = DtCompileTable (PFieldList, AcpiDmTableInfoDbg2Name,
9897bb
             &Subtable);
9897bb
         if (ACPI_FAILURE (Status))
9897bb
@@ -554,8 +562,9 @@ DtCompileDbg2 (
9897bb
 
9897bb
         /* Update the device info header */
9897bb
 
9897bb
-        DeviceInfo->NamepathLength = (UINT16) Subtable->Length;
9897bb
-        CurrentOffset += (UINT16) DeviceInfo->NamepathLength;
9897bb
+        AcpiUtWriteUint (&DeviceInfo->NamepathLength, sizeof (UINT16),
9897bb
+            &Subtable->Length, sizeof (UINT32));
9897bb
+        CurrentOffset += AcpiUtReadUint16 (&DeviceInfo->NamepathLength);
9897bb
         DtInsertSubtable (ParentTable, Subtable);
9897bb
 
9897bb
         /* OemData - Variable-length data (Optional, size = OemDataLength) */
9897bb
@@ -582,8 +591,10 @@ DtCompileDbg2 (
9897bb
 
9897bb
         if (Subtable && Subtable->Length)
9897bb
         {
9897bb
-            DeviceInfo->OemDataOffset = CurrentOffset;
9897bb
-            DeviceInfo->OemDataLength = (UINT16) Subtable->Length;
9897bb
+            AcpiUtWriteUint (&DeviceInfo->OemDataOffset, sizeof (UINT16),
9897bb
+                &CurrentOffset, sizeof (UINT16));
9897bb
+            AcpiUtWriteUint (&DeviceInfo->OemDataLength, sizeof (UINT16),
9897bb
+                &Subtable->Length, sizeof (UINT32));
9897bb
 
9897bb
             DtInsertSubtable (ParentTable, Subtable);
9897bb
         }