From owner-acpi-jp@jp.FreeBSD.org Fri Jul 19 11:50:49 2002
Received: (from daemon@localhost)
	by castle.jp.FreeBSD.org (8.11.6+3.4W/8.11.3) id g6J2onD26524;
	Fri, 19 Jul 2002 11:50:49 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from porthos.spock.org (root@alb-66-67-128-5.nycap.rr.com [66.67.128.5])
	by castle.jp.FreeBSD.org (8.11.6+3.4W/8.11.3) with ESMTP/inet id g6J2oln26519
	for <acpi-jp@jp.FreeBSD.org>; Fri, 19 Jul 2002 11:50:48 +0900 (JST)
	(envelope-from jon@porthos.spock.org)
Received: from porthos.spock.org (0@localhost [127.0.0.1])
	by porthos.spock.org  with ESMTP serial EF600Q3T-B7F8823g6J2ogS8015904F7T
	for <acpi-jp@jp.FreeBSD.org>; Thu, 18 Jul 2002 22:50:43 -0400 (EDT)
	(envelope-from jon@porthos.spock.org)
X-OrigTo: <acpi-jp@jp.FreeBSD.org>
Received: (from jon@localhost)
	by porthos.spock.org (8.12.4/8.12.3/Submit) id g6J2ofW8015902
	for acpi-jp@jp.FreeBSD.org; Thu, 18 Jul 2002 22:50:41 -0400 (EDT)
	(envelope-from jon)
Date: Thu, 18 Jul 2002 22:50:41 -0400
From: Jonathan Chen <jon@freebsd.org>
To: acpi-jp@jp.FreeBSD.org
Message-ID: <20020718225041.J46307@porthos.spock.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
User-Agent: telnet/1.1x
Reply-To: acpi-jp@jp.FreeBSD.org
Precedence: list
X-Sequence: acpi-jp 1689
Subject: [acpi-jp 1689] simple acpi fixes, and some questions
Errors-To: owner-acpi-jp@jp.FreeBSD.org
Sender: owner-acpi-jp@jp.FreeBSD.org
X-Originator: jon@freebsd.org
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+020717

It took me a while to get ACPI working on my new Thinkpad T30, and I 
noticed a couple of things while playing:


First, it seems that AcpiEvaluateObject() can sometimes return OK but leave
the output buffer NULL.  The patch to acpi_cmbat.c fixes the resulting
panics I was seeing.  I'm not sure if AcpiEvaluateObject()'s behavior is
intended or not.  If this patch looks okay, let me know and I can commit
it; or if you think something else is wrong here, let me know what and I
can play with it some more.

Secondly, there is a very minor typo in sys/contrib/dev/acpica/psparse.c,
resulting in panics when debugging for parsing is turned on.  This probably
doesn't need to go in the FreeBSD tree yet, but perhaps someone at Intel
can fix it in their tree.

Also, I have some general questions as well.  The main problem I had with
getting ACPI to work was some mysterious panics in the UFS code whenever
ACPI was enabled.  I finally was able to track the problem down, which was
caused by running the _INI method for \_SB_.PCI0.PCI1.CBS0 or
\_SB_.PCI0.PCI1.CBS1.  The simple fix was to set debug.acpi.avoid="" (ie
flags=ACPI_NO_DEVICE_INIT when running AcpiEnableSubsystem()).  NetBSD
appears to have this as the default, does anyone know why they skip running
_INI and we don't?  In any case, can I/how do I find out what CBS0/CBS1 are
doing in the _INI method?  I don't have too much experience with ACPI, but
I'm guessing this might have something to do with PCI1 not being properly
initialized, might that be the case?  Or do I need to use _REG to turn on
some regions in PCI1 before I can _INI the children?  (incidentally, does
_REG affect things globally or just for one device?)  I'm reading the 
ACPI2.0 specs, which says that we must enable a bunch of regions, yet I do 
not see _REG used anywhere in the FreeBSD ACPI code.  Is this an oversight, 
or am I missing something?

Thanks.
-Jon


[patch 1]

Index: sys/dev/acpica/acpi_cmbat.c
===================================================================
RCS file: /exports/ncvs/src/sys/dev/acpica/acpi_cmbat.c,v
retrieving revision 1.16
diff -u -r1.16 acpi_cmbat.c
--- sys/dev/acpica/acpi_cmbat.c	12 Mar 2002 00:15:06 -0000	1.16
+++ sys/dev/acpica/acpi_cmbat.c	17 Jul 2002 18:41:34 -0000
@@ -193,7 +193,7 @@
 
 	res = (ACPI_OBJECT *)bst_buffer.Pointer;
 
-	if ((res->Type != ACPI_TYPE_PACKAGE) || (res->Package.Count != 4)) {
+	if ((res == NULL) || (res->Type != ACPI_TYPE_PACKAGE) || (res->Package.Count != 4)) {
 		ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
 		    "battery status corrupted\n");
 		goto end;
@@ -244,7 +244,7 @@
 
 	res = (ACPI_OBJECT *)bif_buffer.Pointer;
 
-	if ((res->Type != ACPI_TYPE_PACKAGE) || (res->Package.Count != 13)) {
+	if ((res == NULL) || (res->Type != ACPI_TYPE_PACKAGE) || (res->Package.Count != 13)) {
 		ACPI_VPRINT(dev, acpi_device_get_parent_softc(dev),
 		    "battery info corrupted\n");
 		goto end;


[patch 2]

Index: sys/contrib/dev/acpica/psparse.c
===================================================================
RCS file: /exports/ncvs/src/sys/contrib/dev/acpica/psparse.c,v
retrieving revision 1.16
diff -u -r1.16 psparse.c
--- sys/contrib/dev/acpica/psparse.c	9 Jul 2002 17:53:51 -0000	1.16
+++ sys/contrib/dev/acpica/psparse.c	16 Jul 2002 22:00:01 -0000
@@ -824,7 +824,7 @@
             if (WalkState->OpInfo)
             {
                 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
-                    "Opcode %4.4hX [%s] Op %p Aml %p AmlOffset %5.5X\n",
+                    "Opcode %4.4X [%s] Op %p Aml %p AmlOffset %5.5X\n",
                      Op->Common.AmlOpcode, WalkState->OpInfo->Name, 
                      Op, ParserState->Aml, Op->Common.AmlOffset));
             }


--
Jonathan Chen		+	(518)961-2662
jon@cs.rpi.edu		+	Research Programmer / System Administrator
301 Lally		+	Department of Computer Science, RPI

