From andy@CRWdog.demon.co.uk  Sun Jun 10 19:30:52 2001
Return-Path: <andy@CRWdog.demon.co.uk>
Received: from CRWdog.demon.co.uk (crwdog.demon.co.uk [193.237.46.84])
	by hub.freebsd.org (Postfix) with ESMTP id 0600837B403
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 10 Jun 2001 19:30:51 -0700 (PDT)
	(envelope-from andy@CRWdog.demon.co.uk)
Received: by CRWdog.demon.co.uk (Postfix, from userid 1001)
	id 5B8A03E96; Mon, 11 Jun 2001 03:30:48 +0100 (BST)
Message-Id: <20010611023048.5B8A03E96@CRWdog.demon.co.uk>
Date: Mon, 11 Jun 2001 03:30:48 +0100 (BST)
From: spadger@best.com
Reply-To: spadger@best.com
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Rage 128 Suspend issues
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         28026
>Category:       bin
>Synopsis:       Graphics mode suspend causes weird hang on laptop with Rage card
>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:   Sun Jun 10 19:40:01 PDT 2001
>Closed-Date:    Fri Feb 8 13:56:00 PST 2002
>Last-Modified:  Fri Feb 08 13:56:26 PST 2002
>Originator:     Andy Sparrow
>Release:        FreeBSD 4.3-RELEASE i386
>Organization:
>Environment:
System: FreeBSD omni.geek4food.org 4.3-RELEASE FreeBSD 4.3-RELEASE #52: Sat Jun 9 23:31:24 BST 2001 root@omni.geek4food.org:/usr/src/sys/compile/o6k i386

	Omnibook 6000, Compaq Armada, multiple machines with Rage
	Mobility chipset (maybe others), believed most (all?)
	versions of FreeBSD 4.x with XFree86 3.3.x (at least
	4.[23]-STABLE, 4.3-RELEASE with 3.3.6)

>Description:

	On machines that support suspend-to-ram or suspend-to-disk
	(not as extensively tested), it has been observed that
	suspending (via either the 'apm' binary or closing the lid,
	pressing suspend button etc.) whilst in graphics mode (e.g.
	running an X server, either XF86_SVGA or XF86_Mach64) will
	put the machine in a strange state, where the display is
	very dim (but still barely visible), but machine will not
	respond to keyboard, power button or network, and the
	machine is still using mucho power (e.g. gets v.hot in
	bag).

	The only recourse then is to reset, with the attendant loss
	of uptime and filesystem checks. Sometimes, it can be harder
	to find a paperclip than you think...

	Switching to a text mode VT first avoids this problem, the
	machine will suspend and resume as expected.

>How-To-Repeat:

	On such a machine as described (laptop with APM enabled
	and Rage Mobility chipset), suspend the machine, either
	via hardware or via 'apm', whilst running X.

>Fix:

	It is possible to hack around the problem by calling a
	binary (e.g. from 'rc.suspend') that switches to text mode
	first, before issuing the suspend call.

	This obviously leaves two files that need to be maintained,
	particularly when cvsup'ing regularly it is inevitable that
	this extra step will be overlooked sooner or later.

	Also, a better way to address this issue (if not in the X
	server itself), seems to be in the 'apm' binary, which
	should DTRT.

	I attach for your consideration some example patches to
	'apm' and its Makefile, and some (commented-out) options
	with descriptive commands for 'etc/defaults/make.conf'
	(intended to be activated in '/etc/make.conf', naturally).

	In this way, it is as unobtrusive as possible on machine/systems
	that don't need this, yet fixes the problems for machines
	that do.

	Thanks.


*** usr.sbin/apm/apm.c.orig	Tue Apr 17 23:53:48 2001
--- usr.sbin/apm/apm.c	Mon Apr 30 23:55:31 2001
***************
*** 36,41 ****
--- 36,47 ----
  
  #define APMDEV	"/dev/apm"
  
+ #ifdef WANT_TEXTMODE_SUSPEND
+ #define	VGADEV	"/dev/vga"
+ #include <sys/wait.h>
+ #include <machine/console.h>
+ #endif
+ 
  #define xh(a)	(((a) & 0xff00) >> 8)
  #define xl(a)	((a) & 0xff)
  #define APMERR(a) xh(a)
***************
*** 126,131 ****
--- 132,168 ----
  		err(1, "ioctl(APMIO_STANDBY)");
  }
  
+ #ifdef WANT_TEXTMODE_SUSPEND
+ void
+ apm_wrapper(int fd, void (*fptr)(int))
+ {
+ 	int myfd, vt, status;
+ 
+ 	myfd = open(VGADEV, O_RDONLY);
+ 	if(myfd < 0)
+ 		err(1, "open %s", VGADEV);
+ 	if(ioctl(myfd, VT_GETACTIVE, &vt) < 0)
+ 		err(1, "ioctl VT_GETACTIVE");
+ 	if(ioctl(myfd, VT_ACTIVATE, 1) < 0)
+ 		err(1, "ioctl VT_ACTIVATE");
+ 
+ 	switch(fork()) {
+ 	case -1:
+ 		err(1, "fork");
+ 	case 0:
+ 		fptr (fd);
+ 		break;
+ 	default:
+ 		wait(&status);
+ 		if(!WIFEXITED(status) || WEXITSTATUS(status))
+ 			errx(1, "apm -z failed");
+ 	}
+ 	sleep(2);
+ 	if(ioctl(myfd, VT_ACTIVATE, vt) < 0)
+ 		err(1, "ioctl VT_ACTIVATE");
+ }
+ #endif
+ 
  void 
  apm_getinfo(int fd, apm_info_t aip)
  {
***************
*** 483,492 ****
--- 520,535 ----
  		apm_haltcpu(fd, haltcpu);
  	if (delta)
  		apm_set_timer(fd, delta);
+ #ifdef WANT_TEXTMODE_SUSPEND
+ 	if (sleep || standby) {
+ 		apm_wrapper( fd, (sleep?apm_suspend:apm_standby) );
+ 	}
+ #else
  	if (sleep)
  		apm_suspend(fd);
  	else if (standby)
  		apm_standby(fd);
+ #endif
  	else if (delta == 0) {
  		struct apm_info info;
  

*** usr.sbin/apm/Makefile.orig	Wed Apr 18 00:45:22 2001
--- usr.sbin/apm/Makefile	Wed Apr 18 01:05:41 2001
***************
*** 5,8 ****
--- 5,20 ----
  MAN8=		apm.8
  MLINKS=		apm.8 apmconf.8 apm.8 zzz.8
  
+ 
+ .if defined(WANT_TEXTMODE_SUSPEND)
+ CFLAGS+= -DWANT_TEXTMODE_SUSPEND
+ .endif
+ 
+ .if defined(NOSUID) || !defined(ALLOW_USER_SUSPEND)
+ BINMODE=555
+ .else
+ BINMODE=4555
+ BINOWN= root
+ .endif
+ 
  .include <bsd.prog.mk>



*** etc/defaults/make.conf.orig	Thu Apr 19 15:16:43 2001
--- etc/defaults/make.conf	Thu Apr 19 15:24:49 2001
***************
*** 140,145 ****
--- 140,159 ----
  #NOMANCOMPRESS=	true
  #
  #
+ # Some machines (e.g. laptops) with certain graphics devices (notably
+ # ATI Rage Mobility) react badly to being suspended when in graphics
+ # mode (e.g. in X) and lock the machine entirely. If you suffer from
+ # this, try uncommenting the following:
+ #
+ #WANT_TEXTMODE_SUSPEND= true
+ #
+ #
+ # If you uncomment the above, you might want/need to uncomment the
+ # following to permit suspends by users. (Makes apm(8) SUID root).
+ #
+ #ALLOW_USER_SUSPEND= true
+ #
+ #
  # If you want the "compat" shared libraries installed as part of your normal
  # builds, uncomment these:
  #
>Release-Note:
>Audit-Trail:

From: Josef Karthauser <joe@tao.org.uk>
To: spadger@best.com
Cc: FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/28026: Rage 128 Suspend issues
Date: Thu, 14 Jun 2001 15:50:42 +0100

 --EVF5PPMfhYS0aIcm
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Mon, Jun 11, 2001 at 03:30:48AM +0100, spadger@best.com wrote:
 >=20
 > 	On such a machine as described (laptop with APM enabled
 > 	and Rage Mobility chipset), suspend the machine, either
 > 	via hardware or via 'apm', whilst running X.
 >=20
 
 I also have a similar problem with a Dell Inspiron 5000e with the same
 video chipset.  I'm running -current and acpi.
 
 Joe
 
 --EVF5PPMfhYS0aIcm
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.6 (FreeBSD)
 Comment: For info see http://www.gnupg.org
 
 iEYEARECAAYFAjsoz0EACgkQXVIcjOaxUBbnhwCg7l/mByGzGvXSWDRHyEWcDhgz
 vtIAnj34BM7aP7dRXbalpxu599kmPnuM
 =LFBo
 -----END PGP SIGNATURE-----
 
 --EVF5PPMfhYS0aIcm--

From: Andy Sparrow <spadger@best.com>
To: freebsd-gnats-submit@FreeBSD.org, spadger@best.com
Cc: Josef Karthauser <joe@tao.org.uk>
Subject: Re: bin/28026: Graphics mode suspend causes weird hang on laptop with 
 Rage card
Date: Mon, 22 Oct 2001 23:31:05 -0700

 --==_Exmh_1855427384P
 Content-Type: text/plain; charset=us-ascii
 
 
 Hi,
 
 This no longer happens for me on -STABLE from Oct 19th and XFree86 4.1.0_7 
 from ports (yes, I forgot to apply local patches and suspended anyway :-)
 
 Thanks,
 
 AS
 
 
 
 
 --==_Exmh_1855427384P
 Content-Type: application/pgp-signature
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.0.6 (FreeBSD)
 Comment: Exmh version 2.5 07/13/2001
 
 iD8DBQE71Q6pPHh895bDXeQRAk3LAJ42i+H6bfAj4z4LOmqon1BpLrci+QCcC8tH
 qFQ3VcGcQIHT9yEDw+6YahM=
 =GVlH
 -----END PGP SIGNATURE-----
 
 --==_Exmh_1855427384P--
State-Changed-From-To: open->closed 
State-Changed-By: ashp 
State-Changed-When: Fri Feb 8 13:56:00 PST 2002 
State-Changed-Why:  
Originator states this is no longer an issue, as of -STABLE from Oct 19th. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28026 
>Unformatted:
