From 4ac47ccf8d369437c39dadc740e585bc52495203 Mon Sep 17 00:00:00 2001
From: Sascha Wildner <saw@online.de>
Date: Mon, 12 Dec 2016 09:59:15 +0100
Subject: [PATCH] kernel/acpica: Revert some parser commits to fix shutdown.

---
 .../dev/acpica/source/components/parser/psargs.c   | 77 ++++++++++------------
 .../dev/acpica/source/components/parser/psloop.c   |  3 -
 .../dev/acpica/source/components/parser/psobject.c |  8 +--
 .../dev/acpica/source/components/parser/pstree.c   | 10 ++-
 .../acpica/source/components/utilities/utresrc.c   | 19 ++----
 sys/contrib/dev/acpica/source/include/acopcode.h   |  8 +--
 6 files changed, 48 insertions(+), 77 deletions(-)

diff --git a/sys/contrib/dev/acpica/source/components/parser/psargs.c b/sys/contrib/dev/acpica/source/components/parser/psargs.c
index 5cc3286..a4745c3 100644
--- a/sys/contrib/dev/acpica/source/components/parser/psargs.c
+++ b/sys/contrib/dev/acpica/source/components/parser/psargs.c
@@ -298,12 +298,23 @@ AcpiPsGetNextNamepath (
         PossibleMethodCall &&
         (Node->Type == ACPI_TYPE_METHOD))
     {
+        if (WalkState->Opcode == AML_UNLOAD_OP)
+        {
+            /*
+             * AcpiPsGetNextNamestring has increased the AML pointer,
+             * so we need to restore the saved AML pointer for method call.
+             */
+            WalkState->ParserState.Aml = Start;
+            WalkState->ArgCount = 1;
+            AcpiPsInitOp (Arg, AML_INT_METHODCALL_OP);
+            return_ACPI_STATUS (AE_OK);
+        }
+
         /* This name is actually a control method invocation */
 
         MethodDesc = AcpiNsGetAttachedObject (Node);
         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
-            "Control Method invocation %4.4s - %p Desc %p Path=%p\n",
-            Node->Name.Ascii, Node, MethodDesc, Path));
+            "Control Method - %p Desc %p Path=%p\n", Node, MethodDesc, Path));
 
         NameOp = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, Start);
         if (!NameOp)
@@ -760,10 +771,6 @@ AcpiPsGetNextArg (
     ACPI_FUNCTION_TRACE_PTR (PsGetNextArg, ParserState);
 
 
-    ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
-        "Expected argument type ARGP: %s (%2.2X)\n",
-        AcpiUtGetArgumentTypeName (ArgType), ArgType));
-
     switch (ArgType)
     {
     case ARGP_BYTEDATA:
@@ -847,13 +854,11 @@ AcpiPsGetNextArg (
         }
         break;
 
+    case ARGP_TARGET:
+    case ARGP_SUPERNAME:
     case ARGP_SIMPLENAME:
     case ARGP_NAME_OR_REF:
 
-        ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
-            "**** SimpleName/NameOrRef: %s (%2.2X)\n",
-            AcpiUtGetArgumentTypeName (ArgType), ArgType));
-
         Subop = AcpiPsPeekOpcode (ParserState);
         if (Subop == 0                  ||
             AcpiPsIsLeadingChar (Subop) ||
@@ -868,37 +873,28 @@ AcpiPsGetNextArg (
                 return_ACPI_STATUS (AE_NO_MEMORY);
             }
 
-            Status = AcpiPsGetNextNamepath (WalkState, ParserState,
-                Arg, ACPI_NOT_METHOD_CALL);
-        }
-        else
-        {
-            /* Single complex argument, nothing returned */
+            /* To support SuperName arg of Unload */
 
-            WalkState->ArgCount = 1;
-        }
-        break;
-
-    case ARGP_TARGET:
-    case ARGP_SUPERNAME:
-
-        ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
-            "**** Target/Supername: %s (%2.2X)\n",
-            AcpiUtGetArgumentTypeName (ArgType), ArgType));
-
-        Subop = AcpiPsPeekOpcode (ParserState);
-        if (Subop == 0)
-        {
-            /* NULL target (zero). Convert to a NULL namepath */
-
-            Arg = AcpiPsAllocOp (AML_INT_NAMEPATH_OP, ParserState->Aml);
-            if (!Arg)
+            if (WalkState->Opcode == AML_UNLOAD_OP)
             {
-                return_ACPI_STATUS (AE_NO_MEMORY);
+                Status = AcpiPsGetNextNamepath (WalkState, ParserState,
+                    Arg, ACPI_POSSIBLE_METHOD_CALL);
+
+                /*
+                 * If the SuperName argument is a method call, we have
+                 * already restored the AML pointer, just free this Arg
+                 */
+                if (Arg->Common.AmlOpcode == AML_INT_METHODCALL_OP)
+                {
+                    AcpiPsFreeOp (Arg);
+                    Arg = NULL;
+                }
+            }
+            else
+            {
+                Status = AcpiPsGetNextNamepath (WalkState, ParserState,
+                    Arg, ACPI_NOT_METHOD_CALL);
             }
-
-            Status = AcpiPsGetNextNamepath (WalkState, ParserState,
-                Arg, ACPI_POSSIBLE_METHOD_CALL);
         }
         else
         {
@@ -911,11 +907,6 @@ AcpiPsGetNextArg (
     case ARGP_DATAOBJ:
     case ARGP_TERMARG:
 
-
-    ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
-        "**** TermArg/DataObj: %s (%2.2X)\n",
-        AcpiUtGetArgumentTypeName (ArgType), ArgType));
-
         /* Single complex argument, nothing returned */
 
         WalkState->ArgCount = 1;
diff --git a/sys/contrib/dev/acpica/source/components/parser/psloop.c b/sys/contrib/dev/acpica/source/components/parser/psloop.c
index 5056cd1..e0839fd 100644
--- a/sys/contrib/dev/acpica/source/components/parser/psloop.c
+++ b/sys/contrib/dev/acpica/source/components/parser/psloop.c
@@ -104,9 +104,6 @@ AcpiPsGetArguments (
     ACPI_FUNCTION_TRACE_PTR (PsGetArguments, WalkState);
 
 
-    ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
-        "Get arguments for opcode [%s]\n", Op->Common.AmlOpName));
-
     switch (Op->Common.AmlOpcode)
     {
     case AML_BYTE_OP:       /* AML_BYTEDATA_ARG */
diff --git a/sys/contrib/dev/acpica/source/components/parser/psobject.c b/sys/contrib/dev/acpica/source/components/parser/psobject.c
index d027f6d..7edc39e 100644
--- a/sys/contrib/dev/acpica/source/components/parser/psobject.c
+++ b/sys/contrib/dev/acpica/source/components/parser/psobject.c
@@ -373,13 +373,7 @@ AcpiPsCreateOp (
                 Op->Common.Flags |= ACPI_PARSEOP_TARGET;
             }
         }
-
-        /*
-         * Special case for both Increment() and Decrement(), where
-         * the lone argument is both a source and a target.
-         */
-        else if ((ParentScope->Common.AmlOpcode == AML_INCREMENT_OP) ||
-                (ParentScope->Common.AmlOpcode == AML_DECREMENT_OP))
+        else if (ParentScope->Common.AmlOpcode == AML_INCREMENT_OP)
         {
             Op->Common.Flags |= ACPI_PARSEOP_TARGET;
         }
diff --git a/sys/contrib/dev/acpica/source/components/parser/pstree.c b/sys/contrib/dev/acpica/source/components/parser/pstree.c
index 0d6ab63..7298569 100644
--- a/sys/contrib/dev/acpica/source/components/parser/pstree.c
+++ b/sys/contrib/dev/acpica/source/components/parser/pstree.c
@@ -142,12 +142,12 @@ AcpiPsAppendArg (
     const ACPI_OPCODE_INFO  *OpInfo;
 
 
-    ACPI_FUNCTION_TRACE ("PsAppendArg");
+    ACPI_FUNCTION_ENTRY ();
 
 
     if (!Op)
     {
-        return_VOID;
+        return;
     }
 
     /* Get the info structure for this opcode */
@@ -159,7 +159,7 @@ AcpiPsAppendArg (
 
         ACPI_ERROR ((AE_INFO, "Invalid AML Opcode: 0x%2.2X",
             Op->Common.AmlOpcode));
-        return_VOID;
+        return;
     }
 
     /* Check if this opcode requires argument sub-objects */
@@ -168,7 +168,7 @@ AcpiPsAppendArg (
     {
         /* Has no linked argument objects */
 
-        return_VOID;
+        return;
     }
 
     /* Append the argument to the linked argument list */
@@ -200,8 +200,6 @@ AcpiPsAppendArg (
 
         Op->Common.ArgListLength++;
     }
-
-    return_VOID;
 }
 
 
diff --git a/sys/contrib/dev/acpica/source/components/utilities/utresrc.c b/sys/contrib/dev/acpica/source/components/utilities/utresrc.c
index 453369c..2de32b5 100644
--- a/sys/contrib/dev/acpica/source/components/utilities/utresrc.c
+++ b/sys/contrib/dev/acpica/source/components/utilities/utresrc.c
@@ -468,11 +468,9 @@ AcpiUtWalkAmlResources (
     ACPI_FUNCTION_TRACE (UtWalkAmlResources);
 
 
-    /*
-     * The absolute minimum resource template is one EndTag descriptor.
-     * However, we will treat a lone EndTag as just a simple buffer.
-     */
-    if (AmlLength <= sizeof (AML_RESOURCE_END_TAG))
+    /* The absolute minimum resource template is one EndTag descriptor */
+
+    if (AmlLength < sizeof (AML_RESOURCE_END_TAG))
     {
         return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
     }
@@ -505,8 +503,8 @@ AcpiUtWalkAmlResources (
 
         if (UserFunction)
         {
-            Status = UserFunction (Aml, Length, Offset,
-                ResourceIndex, Context);
+            Status = UserFunction (
+                Aml, Length, Offset, ResourceIndex, Context);
             if (ACPI_FAILURE (Status))
             {
                 return_ACPI_STATUS (Status);
@@ -533,13 +531,6 @@ AcpiUtWalkAmlResources (
                 *Context = Aml;
             }
 
-            /* Check if buffer is defined to be longer than the resource length */
-
-            if (AmlLength > (Offset + Length))
-            {
-                return_ACPI_STATUS (AE_AML_NO_RESOURCE_END_TAG);
-            }
-
             /* Normal exit */
 
             return_ACPI_STATUS (AE_OK);
diff --git a/sys/contrib/dev/acpica/source/include/acopcode.h b/sys/contrib/dev/acpica/source/include/acopcode.h
index e5c3525..5b499d7 100644
--- a/sys/contrib/dev/acpica/source/include/acopcode.h
+++ b/sys/contrib/dev/acpica/source/include/acopcode.h
@@ -93,7 +93,7 @@
 #define ARGP_BYTELIST_OP                ARGP_LIST1 (ARGP_NAMESTRING)
 #define ARGP_CONCAT_OP                  ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
 #define ARGP_CONCAT_RES_OP              ARGP_LIST3 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET)
-#define ARGP_COND_REF_OF_OP             ARGP_LIST2 (ARGP_SIMPLENAME, ARGP_TARGET)
+#define ARGP_COND_REF_OF_OP             ARGP_LIST2 (ARGP_NAME_OR_REF,ARGP_TARGET)
 #define ARGP_CONNECTFIELD_OP            ARGP_LIST1 (ARGP_NAMESTRING)
 #define ARGP_CONTINUE_OP                ARG_NONE
 #define ARGP_COPY_OP                    ARGP_LIST2 (ARGP_TERMARG,    ARGP_SIMPLENAME)
@@ -106,7 +106,7 @@
 #define ARGP_DATA_REGION_OP             ARGP_LIST4 (ARGP_NAME,       ARGP_TERMARG,       ARGP_TERMARG,   ARGP_TERMARG)
 #define ARGP_DEBUG_OP                   ARG_NONE
 #define ARGP_DECREMENT_OP               ARGP_LIST1 (ARGP_SUPERNAME)
-#define ARGP_DEREF_OF_OP                ARGP_LIST1 (ARGP_SUPERNAME)
+#define ARGP_DEREF_OF_OP                ARGP_LIST1 (ARGP_TERMARG)
 #define ARGP_DEVICE_OP                  ARGP_LIST3 (ARGP_PKGLENGTH,  ARGP_NAME,          ARGP_OBJLIST)
 #define ARGP_DIVIDE_OP                  ARGP_LIST4 (ARGP_TERMARG,    ARGP_TERMARG,       ARGP_TARGET,    ARGP_TARGET)
 #define ARGP_DWORD_OP                   ARGP_LIST1 (ARGP_DWORDDATA)
@@ -153,14 +153,14 @@
 #define ARGP_NAMEPATH_OP                ARGP_LIST1 (ARGP_NAMESTRING)
 #define ARGP_NOOP_OP                    ARG_NONE
 #define ARGP_NOTIFY_OP                  ARGP_LIST2 (ARGP_SUPERNAME,  ARGP_TERMARG)
-#define ARGP_OBJECT_TYPE_OP             ARGP_LIST1 (ARGP_SIMPLENAME)
+#define ARGP_OBJECT_TYPE_OP             ARGP_LIST1 (ARGP_NAME_OR_REF)
 #define ARGP_ONE_OP                     ARG_NONE
 #define ARGP_ONES_OP                    ARG_NONE
 #define ARGP_PACKAGE_OP                 ARGP_LIST3 (ARGP_PKGLENGTH,  ARGP_BYTEDATA,      ARGP_DATAOBJLIST)
 #define ARGP_POWER_RES_OP               ARGP_LIST5 (ARGP_PKGLENGTH,  ARGP_NAME,          ARGP_BYTEDATA,  ARGP_WORDDATA,  ARGP_OBJLIST)
 #define ARGP_PROCESSOR_OP               ARGP_LIST6 (ARGP_PKGLENGTH,  ARGP_NAME,          ARGP_BYTEDATA,  ARGP_DWORDDATA, ARGP_BYTEDATA,  ARGP_OBJLIST)
 #define ARGP_QWORD_OP                   ARGP_LIST1 (ARGP_QWORDDATA)
-#define ARGP_REF_OF_OP                  ARGP_LIST1 (ARGP_SIMPLENAME)
+#define ARGP_REF_OF_OP                  ARGP_LIST1 (ARGP_NAME_OR_REF)
 #define ARGP_REGION_OP                  ARGP_LIST4 (ARGP_NAME,       ARGP_BYTEDATA,      ARGP_TERMARG,   ARGP_TERMARG)
 #define ARGP_RELEASE_OP                 ARGP_LIST1 (ARGP_SUPERNAME)
 #define ARGP_RESERVEDFIELD_OP           ARGP_LIST1 (ARGP_NAMESTRING)
-- 
2.10.1

