From owner-acpi-jp@jp.freebsd.org  Wed Sep  5 08:36:32 2001
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id IAA80911;
	Wed, 5 Sep 2001 08:36:32 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from mail.wrs.com (unknown-1-11.windriver.com [147.11.1.11])
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) with ESMTP id IAA80905
	for <acpi-jp@jp.FreeBSD.org>; Wed, 5 Sep 2001 08:36:31 +0900 (JST)
	(envelope-from jhb@FreeBSD.org)
Received: from laptop.baldwin.cx (john@[147.11.46.201])
	by mail.wrs.com (8.9.3/8.9.1) with ESMTP id QAA17461
	for <acpi-jp@jp.FreeBSD.org>; Tue, 4 Sep 2001 16:35:58 -0700 (PDT)
Message-ID: <XFMail.010904163555.jhb@FreeBSD.org>
X-Mailer: XFMail 1.4.0 on FreeBSD
X-Priority: 3 (Normal)
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 8bit
MIME-Version: 1.0
Date: Tue, 04 Sep 2001 16:35:55 -0700 (PDT)
From: John Baldwin <jhb@FreeBSD.org>
To: acpi-jp@jp.FreeBSD.org
Reply-To: acpi-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+010328
X-Sequence: acpi-jp 1243
Subject: [acpi-jp 1243] Patch for parsing ints
Errors-To: owner-acpi-jp@jp.freebsd.org
Sender: owner-acpi-jp@jp.freebsd.org
X-Originator: jhb@FreeBSD.org

The included patch (http://www.FreeBSD.org/~jhb/patches/acpi_int.patch) is
needed for a quad xeon Acer test box I have to properly enumerate its PCI
busses.  The ACPI dump for this machine is at www.freebsd.org/~jhb/acpi-xeon


Index: acpi.c
===================================================================
RCS file: /host/cvs/usr/home/ncvs/src/sys/dev/acpica/acpi.c,v
retrieving revision 1.29
diff -u -r1.29 acpi.c
--- acpi.c      3 Aug 2001 08:38:11 -0000       1.29
+++ acpi.c      9 Aug 2001 22:42:30 -0000
@@ -915,12 +915,18 @@
 {
     ACPI_STATUS        error;
     ACPI_BUFFER        buf;
-    ACPI_OBJECT        param;
+    ACPI_OBJECT        param, *p;
+    int                i;
 
     ACPI_ASSERTLOCK;
 
     if (handle == NULL)
        handle = ACPI_ROOT_OBJECT;
+
+    /*
+     * Assume that what we've been pointed at is an Integer object, or
+     * a method that will return an Integer.
+     */
     buf.Pointer = &param;
     buf.Length = sizeof(param);
     if ((error = AcpiEvaluateObject(handle, path, NULL, &buf)) == AE_OK) {
@@ -929,6 +935,36 @@
        } else {
            error = AE_TYPE;
        }
+    }
+
+    /* 
+     * In some applications, a method that's expected to return an Integer
+     * may instead return a Buffer (probably to simplify some internal
+     * arithmetic).  We'll try to fetch whatever it is, and if it's a Buffer,
+     * convert it into an Integer as best we can.
+     *
+     * This is a hack.
+     */
+    if (error == AE_BUFFER_OVERFLOW) {
+       if ((buf.Pointer = AcpiOsCallocate(buf.Length)) == NULL) {
+           error = AE_NO_MEMORY;
+       } else {
+           if ((error = AcpiEvaluateObject(handle, path, NULL, &buf)) ==
AE_OK) {
+               p = (ACPI_OBJECT *)buf.Pointer;
+               if (p->Type != ACPI_TYPE_BUFFER) {
+                   error = AE_TYPE;
+               } else {
+                   if (p->Buffer.Length > sizeof(int)) {
+                       error = AE_BAD_DATA;
+                   } else {
+                       *number = 0;
+                       for (i = 0; i < p->Buffer.Length; i++)
+                           *number += (*(p->Buffer.Pointer + i) << (i * 8));
+                   }
+               }
+           }
+       }
+       AcpiOsFree(buf.Pointer);
     }
     return(error);
 }

-- 

John Baldwin <jhb@FreeBSD.org> -- http://www.FreeBSD.org/~jhb/
PGP Key: http://www.baldwin.cx/~john/pgpkey.asc
"Power Users Use the Power to Serve!"  -  http://www.FreeBSD.org/
