From owner-acpi-jp@jp.freebsd.org  Mon Oct  9 15:01:53 2000
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id PAA35523;
	Mon, 9 Oct 2000 15:01:53 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from tasogare.imasy.or.jp (daemon@tasogare.imasy.or.jp [202.227.24.5])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id PAA35516
	for <acpi-jp@jp.freebsd.org>; Mon, 9 Oct 2000 15:01:51 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
Received: from localhost (iwasaki.imasy.or.jp [202.227.24.92])
	by tasogare.imasy.or.jp (8.10.2+3.3W/3.7W-tasogare/smtpfeed 1.07) with ESMTP id e9961nr28131;
	Mon, 9 Oct 2000 15:01:49 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
To: andrew.grover@intel.com
Cc: acpi-jp@jp.freebsd.org
X-Mailer: Mew version 1.94.1 on Emacs 19.34 / Mule 2.3 (SUETSUMUHANA)
Mime-Version: 1.0
Content-Type: Text/Plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Message-Id: <20001009150148F.iwasaki@jp.FreeBSD.org>
Date: Mon, 09 Oct 2000 15:01:48 +0900
From: Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
X-Dispatcher: imput version 20000228(IM140)
Lines: 80
Reply-To: acpi-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+000315
X-Sequence: acpi-jp 834
Subject: [acpi-jp 834] Another ACPICA workaround: default return value
Errors-To: owner-acpi-jp@jp.freebsd.org
Sender: owner-acpi-jp@jp.freebsd.org
X-Originator: iwasaki@jp.freebsd.org

Hi, Andrew

I've noticed that some method caller expects return value without
explicit ReturnOp in some AML code.  Here is example ASL of TOSHIBA
Portege 3110CT.

Scope(\_SB) {
    Device(LNKA) {
        Name(_HID, 0xf0cd041)
        Name(_UID, 0x1)
        Method(_STA) {
            STAL(0x60)		<----------- this one.
        }
		:
Method(STAL, 1) {
    Store(Arg0, \_SB.MEM.IEDI)
    SMBR(0xfe00, 0x38b108, 0x0, 0x0, 0xb2)
    If(LEqual(\_SB.MEM.OECX, 0x80)) {
        Return(0x9)
    }
    Else {
        Return(0xb)
    }
}

I couldn't find the description how we should treat this in ACPI spec,
but I guess that above code expects the method (_STA) should return the
last evaluated value (return value from STAL) if the method doesn't
have ReturnOp like other programming languages (e.g. perl).
I've just made a patch for this by quick hack, but I'm not sure this
is a right solution because I'm not familiar with ACPICA parser yet.
Could you review this patch?

Regards,

Index: Parser/psparse.c
===================================================================
RCS file: /home/iwasaki/cvs/acpica-bsd/contrib/dev/acpica/Subsystem/Parser/psparse.c,v
retrieving revision 1.1.1.1
diff -u -r1.1.1.1 psparse.c
--- Parser/psparse.c	2000/10/04 03:00:40	1.1.1.1
+++ Parser/psparse.c	2000/10/09 05:33:40
@@ -1250,6 +1250,7 @@
     ACPI_NAMESPACE_NODE     *Node = NULL;
     ACPI_WALK_LIST          *PrevWalkList = AcpiGbl_CurrentWalkList;
     ACPI_OPERAND_OBJECT     *ReturnDesc;
+    ACPI_OPERAND_OBJECT     *EffectiveReturnDesc = NULL;
     ACPI_OPERAND_OBJECT     *MthDesc = NULL;
     ACPI_NAMESPACE_NODE     *StartNode;
 
@@ -1393,6 +1394,12 @@
         /* Extract return value before we delete WalkState */
 
         ReturnDesc = WalkState->ReturnDesc;
+        /* Save the last effective return value */
+        if (CallerReturnDesc && ReturnDesc)
+        {
+            EffectiveReturnDesc = ReturnDesc;
+            AcpiCmAddReference (EffectiveReturnDesc);
+        }
 
         DEBUG_PRINT (TRACE_PARSE,
             ("PsParseAml: ReturnValue=%p, State=%p\n",
@@ -1442,6 +1449,16 @@
 
         else if (CallerReturnDesc)
         {
+            /*
+             * Some AML code expects return value w/o ReturnOp.
+             * Return the saved effective return value instead.
+             */
+            if (ReturnDesc == NULL && EffectiveReturnDesc != NULL)
+            {
+                AcpiCmRemoveReference (ReturnDesc);
+                ReturnDesc = EffectiveReturnDesc;
+            }
+
             *CallerReturnDesc = ReturnDesc; /* NULL if no return value */
         }
 
