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

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