From owner-acpi-jp@jp.freebsd.org  Fri Oct 13 01:19:48 2000
Received: (from daemon@localhost)
	by castle.jp.freebsd.org (8.9.3+3.2W/8.7.3) id BAA52624;
	Fri, 13 Oct 2000 01:19:48 +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 BAA52619
	for <acpi-jp@jp.freebsd.org>; Fri, 13 Oct 2000 01:19:47 +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 e9CGJbr24868
	for <acpi-jp@jp.freebsd.org>; Fri, 13 Oct 2000 01:19:37 +0900 (JST)
	(envelope-from iwasaki@jp.FreeBSD.org)
To: acpi-jp@jp.freebsd.org
In-Reply-To: <20001012011625K.iwasaki@jp.FreeBSD.org>
References: <200010090509.e9959rL00685@lavender.sanpei.org>
	<200010090602.PAA64394@shidahara1.planet.sci.kobe-u.ac.jp>
	<20001012011625K.iwasaki@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: <20001013011936B.iwasaki@jp.FreeBSD.org>
Date: Fri, 13 Oct 2000 01:19:36 +0900
From: Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
X-Dispatcher: imput version 20000228(IM140)
Lines: 190
Reply-To: acpi-jp@jp.freebsd.org
Precedence: list
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+000315
X-Sequence: acpi-jp 856
Subject: [acpi-jp 856] Re: [report] ACPICA with MobioNX
Errors-To: owner-acpi-jp@jp.freebsd.org
Sender: owner-acpi-jp@jp.freebsd.org
X-Originator: iwasaki@jp.freebsd.org

Hi,

> > >	- apm (probe and suspend)	NG
> > >		apm was not probed at boot time :-<
> > 
> > Shall we change probe order : apm then acpi and if apm is probed,
> > disable apm and don't enable until acpi is disabled.
> 
> Hmmm, I'm sure we were able to co-exist apm and acpi with older code.
> If we give up with this problem, it means retrogression...
> I think we should not prevent any other device drivers from probing
> during boot process if we have solutions.
> How about disabling acpi at the end of the initialization for acpi, 
> then enabling it from userland?  Maybe I can implement it easily.

Here is the patch.  This requires my new OSI functions in [acpi-jp 855].
This patch was tested by Matsuda-san and Sanpei-san and confirmed that
apm and acpi can be initialized w/o any interference to the other.
These can co-exist and be switched by acpiconf -e and -d.
Also this includes a patch for stopping event generation in
acpi_shutdown_pre_sync().  Stopping events in shutdown_final handler
seems to be too late, the system reboots... :-(
It seems that certain period after stopping event generation is
required for stable S5 transition.

Index: acpi.c
===================================================================
RCS file: /home/iwasaki/cvs/acpica-bsd/dev/acpica/acpi.c,v
retrieving revision 1.1.1.5
diff -u -r1.1.1.5 acpi.c
--- acpi.c	2000/10/08 13:50:10	1.1.1.5
+++ acpi.c	2000/10/12 16:02:12
@@ -100,6 +100,11 @@
 static void	acpi_shutdown_pre_sync(void *arg, int howto);
 static void	acpi_shutdown_final(void *arg, int howto);
 
+static ACPI_STATUS acpi_enable_events(struct acpi_softc *sc);
+static ACPI_STATUS acpi_disable_events(struct acpi_softc *sc);
+
+static void	acpi_setup_fixed_events(struct acpi_softc *sc);
+
 #ifdef ACPI_DEBUG
 static void	acpi_set_debugging(void);
 #endif
@@ -295,18 +300,7 @@
     sc->acpi_lid_switch_sx = ACPI_LID_SWITCH_DEFAULT_SX;
 
     /* Enable and clear fixed events and install handlers. */
-    if (AcpiGbl_FACP != NULL && AcpiGbl_FACP->PwrButton == 0) {
-	AcpiEnableEvent(ACPI_EVENT_POWER_BUTTON, ACPI_EVENT_FIXED);
-	AcpiClearEvent(ACPI_EVENT_POWER_BUTTON, ACPI_EVENT_FIXED);
-	AcpiInstallFixedEventHandler(ACPI_EVENT_POWER_BUTTON, acpi_eventhandler_power_button_for_sleep, sc);
-	device_printf(dev, "power button is handled as a fixed feature programming model.\n");
-    }
-    if (AcpiGbl_FACP != NULL && AcpiGbl_FACP->SleepButton == 0) {
-	AcpiEnableEvent(ACPI_EVENT_SLEEP_BUTTON, ACPI_EVENT_FIXED);
-	AcpiClearEvent(ACPI_EVENT_SLEEP_BUTTON, ACPI_EVENT_FIXED);
-	AcpiInstallFixedEventHandler(ACPI_EVENT_SLEEP_BUTTON, acpi_eventhandler_sleep_button_for_sleep, sc);
-	device_printf(dev, "sleep button is handled as a fixed feature programming model.\n");
-    }
+    acpi_setup_fixed_events(sc);
 
     /*
      * Scan the namespace and attach/initialise children.
@@ -346,6 +340,12 @@
     if (debugpoint && !strcmp(debugpoint, "running"))
 	acpi_EnterDebugger();
 #endif
+
+    /*
+     * Just in case, disable ACPI temporally in order to probe other devices
+     */
+    acpi_Disable(sc);
+
     return(0);
 }
 
@@ -639,7 +639,7 @@
      *     before powering down, since we may still need ACPI during the
      *     shutdown process.
      */
-    acpi_Disable((struct acpi_softc *)arg);
+    acpi_disable_events((struct acpi_softc *)arg);
 }
 
 static void
@@ -773,6 +773,63 @@
 /*
  * Enable/Disable ACPI
  */
+
+static ACPI_STATUS
+acpi_enable_events(struct acpi_softc *sc)
+{
+    ACPI_STATUS	status;
+
+    if ((status = AcpiEnableFixedEvents(sc->acpi_fixed_events)) != AE_OK)
+	goto out;
+    if ((status = AcpiEnableGpeEvents(sc->acpi_gpe_events)) != AE_OK)
+	goto out;
+
+out:
+    if (status != AE_OK)
+	device_printf(sc->acpi_dev, "acpi_enable_events: %s\n", acpi_strerror(status));
+
+    return(status);
+}
+
+static ACPI_STATUS
+acpi_disable_events(struct acpi_softc *sc)
+{
+    ACPI_STATUS	status;
+
+    if ((status = AcpiGetFixedEventsEnabled(&(sc->acpi_fixed_events))) != AE_OK)
+	goto out;
+    if ((status = AcpiDisableFixedEvents(sc->acpi_fixed_events)) != AE_OK)
+	goto out;
+    if ((status = AcpiGetGpeEventsEnabled(sc->acpi_gpe_events)) != AE_OK)
+	goto out;
+    if ((status = AcpiDisableGpeEvents(sc->acpi_gpe_events)) != AE_OK)
+	goto out;
+
+out:
+    if (status != AE_OK)
+	device_printf(sc->acpi_dev, "acpi_disable_events: %s\n", acpi_strerror(status));
+
+    return(status);
+}
+
+static void
+acpi_setup_fixed_events(struct acpi_softc *sc)
+{
+    /* Enable and clear fixed events and install handlers. */
+    if (AcpiGbl_FACP != NULL && AcpiGbl_FACP->PwrButton == 0) {
+	AcpiEnableEvent(ACPI_EVENT_POWER_BUTTON, ACPI_EVENT_FIXED);
+	AcpiClearEvent(ACPI_EVENT_POWER_BUTTON, ACPI_EVENT_FIXED);
+	AcpiInstallFixedEventHandler(ACPI_EVENT_POWER_BUTTON, acpi_eventhandler_power_button_for_sleep, sc);
+	device_printf(sc->acpi_dev, "power button is handled as a fixed feature programming model.\n");
+    }
+    if (AcpiGbl_FACP != NULL && AcpiGbl_FACP->SleepButton == 0) {
+	AcpiEnableEvent(ACPI_EVENT_SLEEP_BUTTON, ACPI_EVENT_FIXED);
+	AcpiClearEvent(ACPI_EVENT_SLEEP_BUTTON, ACPI_EVENT_FIXED);
+	AcpiInstallFixedEventHandler(ACPI_EVENT_SLEEP_BUTTON, acpi_eventhandler_sleep_button_for_sleep, sc);
+	device_printf(sc->acpi_dev, "sleep button is handled as a fixed feature programming model.\n");
+    }
+}
+
 ACPI_STATUS
 acpi_Enable(struct acpi_softc *sc)
 {
@@ -782,7 +839,10 @@
     flags = ACPI_NO_ADDRESS_SPACE_INIT | ACPI_NO_HARDWARE_INIT |
             ACPI_NO_DEVICE_INIT | ACPI_NO_OBJECT_INIT;
     if (!sc->acpi_enabled) {
-	status = AcpiEnableSubsystem(flags);
+	if ((status = AcpiEnableSubsystem(flags)) == AE_OK) {
+	    acpi_setup_fixed_events(sc);
+	    status = acpi_enable_events(sc);
+	}
     } else {
 	status = AE_OK;
     }
@@ -797,7 +857,9 @@
     ACPI_STATUS	status;
 
     if (sc->acpi_enabled) {
-	status = AcpiDisable();
+	if ((status = acpi_disable_events(sc)) == AE_OK)
+	    status = AcpiDisable();
+	    AcpiSetMode(SYS_MODE_LEGACY);
     } else {
 	status = AE_OK;
     }
Index: acpivar.h
===================================================================
RCS file: /home/iwasaki/cvs/acpica-bsd/dev/acpica/acpivar.h,v
retrieving revision 1.1.1.5
diff -u -r1.1.1.5 acpivar.h
--- acpivar.h	2000/10/08 13:50:11	1.1.1.5
+++ acpivar.h	2000/10/11 13:32:02
@@ -50,6 +50,9 @@
     int			acpi_power_button_sx;
     int			acpi_sleep_button_sx;
     int			acpi_lid_switch_sx;
+
+    UINT32		acpi_fixed_events;
+    UINT8		acpi_gpe_events[NUM_GPE];
 };
 
 struct acpi_device {
