From alarson@switchanddata.com  Thu Apr 17 16:31:23 2003
Return-Path: <alarson@switchanddata.com>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 4F72C37B401
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 17 Apr 2003 16:31:23 -0700 (PDT)
Received: from ground1.paix.net (ground1.paix.net [128.177.247.249])
	by mx1.FreeBSD.org (Postfix) with ESMTP id C54E443FDD
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 17 Apr 2003 16:31:22 -0700 (PDT)
	(envelope-from alarson@switchanddata.com)
Received: (from larson@localhost) 
	by ground1.paix.net (8.11.5/8.9.1) id h3HNVMx72167; Thu, 17 Apr 2003 16:31:22 -0700 (PDT)
	env-from (alarson@switchanddata.com)
Message-Id: <200304172331.h3HNVMx72167@ground1.paix.net>
Date: Thu, 17 Apr 2003 16:31:22 -0700 (PDT)
From: Alan Larson <alarson@switchanddata.com>
Reply-To: Alan Larson <alarson@switchanddata.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: halt -p doesn't if apm not enabled.
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         51110
>Category:       kern
>Synopsis:       halt -p doesn't if apm not enabled.
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Apr 17 16:40:13 PDT 2003
>Closed-Date:    Sat Jun 21 23:18:51 PDT 2003
>Last-Modified:  Sat Jun 21 23:50:16 PDT 2003
>Originator:     Alan Larson
>Release:        FreeBSD 4.8-RELEASE i386
>Organization:
>Environment:
All distributed release versions, from 4.3 to 4.8, probably more.


>Description:
  halt -p would halt the system, but not power down.  Power down
was known to work for windows 2k.  Investigation revealed that
apm_power_off() in apm.c was testing the softc to see if it was
active.

  It appears to be unnecessary for the apm to be active to issue
the bios call to power the machine down.

  A context diff of the correction is included.

  This is rather safe, since it calls apm_bioscall(), which calls
apm_check_function_supported() right at the start.

  (Since the only requirement in the present code to get through to
power off the system is that apm_softc.active be true, and that is
set true by the ioctl to enable apm (without further testing), it
seems quite safe to attempt the power off even if apm hasn't been
enabled.  The enabled state gives us no assurances that we can power
the system off.)




>How-To-Repeat:
How to repeat the problem:
	su		# many fun things start with this.
	apm -e 0	# only needed if it was already on.
	halt -p		# you did save your work first, didn't you?


>Fix:

Fix to the problem:
  The following diff should do it just fine.

*** apm.ccO	Fri Mar 22 14:09:17 2002
--- apm.cc	Fri Mar 22 14:15:10 2002
***************
*** 285,293 ****
  {
  	struct apm_softc *sc = &apm_softc;
  
! 	/* Not halting powering off, or not active */
! 	if (!(howto & RB_POWEROFF) || !apm_softc.active)
! 		return;
  	sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
  	sc->bios.r.ebx = PMDV_ALLDEV;
  	sc->bios.r.ecx = PMST_OFF;
--- 285,292 ----
  {
  	struct apm_softc *sc = &apm_softc;
  
! 	if (!(howto & RB_POWEROFF))	/* Powering off? */
! 		return;			/* no */
  	sc->bios.r.eax = (APM_BIOS << 8) | APM_SETPWSTATE;
  	sc->bios.r.ebx = PMDV_ALLDEV;
  	sc->bios.r.ecx = PMST_OFF;

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: mdodd 
State-Changed-When: Sat Jun 21 23:18:03 PDT 2003 
State-Changed-Why:  
This is a feature. 

Enable APM if you wish to take advantage of its capabilities. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=51110 

From: "M. Warner Losh" <imp@village.org>
To: freebsd-gnats-submit@FreeBSD.org, alarson@switchanddata.com
Cc:  
Subject: Re: kern/51110: halt -p doesn't if apm not enabled.
Date: Sun, 22 Jun 2003 00:43:40 -0600

 Personally I don't think the current behavior is a bug and that this 
 patch introduce a bug.  However, it is an oft-requested 'bug' so the 
 folks that want it likely out-number the folks that are purists.  This 
 is safe because apm is always initialized when the driver attaches.
 
>Unformatted:
