From nsayer@quack.kfu.com  Wed Sep  2 10:06:45 1998
Received: from quack.kfu.com (quack.kfu.com [170.1.70.2])
          by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id KAA24592
          for <FreeBSD-gnats-submit@freebsd.org>; Wed, 2 Sep 1998 10:06:44 -0700 (PDT)
          (envelope-from nsayer@quack.kfu.com)
Received: (from nsayer@localhost)
	by quack.kfu.com (8.8.7/8.8.5) id KAA24303;
	Wed, 2 Sep 1998 10:05:43 -0700 (PDT)
Message-Id: <199809021705.KAA24303@quack.kfu.com>
Date: Wed, 2 Sep 1998 10:05:43 -0700 (PDT)
From: Nick Sayer <nsayer@quack.kfu.com>
Reply-To: nsayer@quack.kfu.com
To: FreeBSD-gnats-submit@freebsd.org
Subject: APM machines should attempt to power down at halt
X-Send-Pr-Version: 3.2

>Number:         7812
>Category:       kern
>Synopsis:       APM machines should attempt to power down at halt
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Sep  2 10:10:00 PDT 1998
>Closed-Date:    Fri Mar 26 19:12:51 PST 1999
>Last-Modified:  Fri Mar 26 19:15:31 PST 1999
>Originator:     Nick Sayer
>Release:        FreeBSD 2.2.7-RELEASE i386
>Organization:
Just me
>Environment:

>Description:

Some laptops and ATX machines can power themselves off under APM
control. When such machines are halted, they should at least try
to power themselves off if APM events are enabled. If the attempt
fails, this code will fall through to the traditional 'press any
key to reboot' prompt.

>How-To-Repeat:

>Fix:

--- apm.c-	Mon Jul  6 22:22:36 1998
+++ apm.c	Wed Sep  2 10:00:07 1998
@@ -24,6 +24,7 @@
 #include <sys/devfsext.h>
 #endif /*DEVFS*/
 #include <sys/systm.h>
+#include <sys/reboot.h>
 #include <sys/time.h>
 #include <i386/isa/isa_device.h>
 #include <machine/apm_bios.h>
@@ -38,6 +39,7 @@
 static int apm_display __P((int newstate));
 static int apm_int __P((u_long *eax, u_long *ebx, u_long *ecx));
 static void apm_resume __P((void));
+static void apm_powerdown __P((int howlong,void *ignore));
 
 /* static data */
 struct apm_softc {
@@ -408,6 +410,23 @@
 		apm_execute_hook(hook[APM_HOOK_RESUME]);
 }
 
+/*
+ * Some latops and ATX machines can power themselves off.
+ */
+void
+apm_powerdown(int howto, void *ignore)
+{
+	u_long eax, ebx, ecx;
+
+	if (howto & RB_HALT)
+	{
+		eax = (APM_BIOS << 8) | APM_SETPWSTATE;
+		ebx = PMDV_ALLDEV;
+		ecx = PMST_OFF;
+
+		apm_int(&eax, &ebx, &ecx); /* ignore errors */
+	}
+}
 
 /* get APM information */
 static int
@@ -511,6 +530,7 @@
 	if (sc->initialized) {
 		sc->active = 1;
 		apm_timeout(sc);
+		at_shutdown(apm_powerdown,NULL,SHUTDOWN_POST_SYNC);
 	}
 }
 
@@ -526,6 +546,7 @@
 	if (sc->initialized) {
 		untimeout(apm_timeout, NULL);
 		sc->active = 0;
+		rm_at_shutdown(apm_powerdown,NULL);
 	}
 }
 
>Release-Note:
>Audit-Trail:

From: Niall Smart <rotel@indigo.ie>
To: nsayer@quack.kfu.com, FreeBSD-gnats-submit@FreeBSD.ORG
Cc:  Subject: Re: kern/7812: APM machines should attempt to power down at halt
Date: Wed, 2 Sep 1998 21:10:35 +0000

 On Sep 2, 10:05am, Nick Sayer wrote:
 } Subject: kern/7812: APM machines should attempt to power down at halt
 > 
 > >Number:         7812
 > >Category:       kern
 > >Synopsis:       APM machines should attempt to power down at halt
 
 Hi Nick,
 
 There have actually been several versions of this patch floating
 around.  However, each of them does it differently to how its done
 in -current, which is probably a bad thing.  I had merged the stuff
 in -current into a -stable tree but accidentally blew it away, but
 I'll redo it later today or tomorrow, perhaps it would be better
 to use these as outlined above.
 
 ( Or you could do it, see boot in kern_shutdown.c ;) )
 
 Niall
 
 
 -- 
 Niall Smart, rotel@indigo.ie.
 Amaze your friends and annoy your enemies:
 echo '#define if(x) if (!(x))' >> /usr/include/stdio.h

From: asami@FreeBSD.ORG (Satoshi Asami)
To: nsayer@quack.kfu.com
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: kern/7812: APM machines should attempt to power down at halt
Date: Thu, 3 Sep 1998 03:40:30 -0700 (PDT)

  * Some laptops and ATX machines can power themselves off under APM
  * control. When such machines are halted, they should at least try
  * to power themselves off if APM events are enabled. If the attempt
  * fails, this code will fall through to the traditional 'press any
  * key to reboot' prompt.
 
 I think this is a bad idea.  We have a whole bunch of boxes that are
 connected to serial consoles.  If they power off at halt, I'll have to 
 drive 50 miles to press the power button. :<
 
 What's wrong with having the user powering the machine off by himself?
 If he's there, he can do it; if he's not, this is just an added
 hassle.  (I can't really think of a reason why you would want to power
 off a machine remotely....)
 
 Satoshi
State-Changed-From-To: open->closed 
State-Changed-By: jkh 
State-Changed-When: Fri Mar 26 19:12:51 PST 1999 
State-Changed-Why:  
Author says it can be closed. 
>Unformatted:
