From nobody@FreeBSD.org  Fri Sep 14 12:18:26 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id C596A16A417
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 14 Sep 2007 12:18:26 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id C72D813C45D
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 14 Sep 2007 12:18:26 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.1/8.14.1) with ESMTP id l8ECIPd1070188
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 14 Sep 2007 12:18:25 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.1/8.14.1/Submit) id l8ECIP2h070187;
	Fri, 14 Sep 2007 12:18:25 GMT
	(envelope-from nobody)
Message-Id: <200709141218.l8ECIP2h070187@www.freebsd.org>
Date: Fri, 14 Sep 2007 12:18:25 GMT
From: Marko Zec <zec@fer.hr>
To: freebsd-gnats-submit@FreeBSD.org
Subject: APM does not suspend USB devices
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         116347
>Category:       i386
>Synopsis:       [apm] [patch] APM does not suspend USB devices
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    zec
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Sep 14 12:20:03 GMT 2007
>Closed-Date:    Fri Oct 17 15:12:58 UTC 2008
>Last-Modified:  Fri Oct 17 15:12:58 UTC 2008
>Originator:     Marko Zec
>Release:        7.0-CURRENT
>Organization:
U. of Zagreb
>Environment:
FreeBSD tpx32.icir.org 7.0-CURRENT FreeBSD 7.0-CURRENT #6: Fri Sep 14 09:32:49 CEST 2007     marko@tpx32.icir.org:/u/marko/p4/vimage/src/sys/i386/compile/TPX32V  i386

>Description:
Any USB device attached to a machine running APM instead of ACPI won't
survive a suspend/resume cycle.
>How-To-Repeat:
Boot with ACPI disabled / APM enabled, plug in a USB device, suspend,
resume, done.
>Fix:
See the patch attached.

Patch attached with submission follows:

--- ../head/src/sys/i386/bios/apm.c	2007-08-31 03:47:17.000000000 +0200
+++ src/sys/i386/bios/apm.c	2007-09-14 10:20:46.000000000 +0200
@@ -485,7 +485,13 @@ apm_do_suspend(void)
 	apm_op_inprog = 0;
 	sc->suspends = sc->suspend_countdown = 0;
 
+	/*
+	 * Be sure to hold Giant across DEVICE_SUSPEND/RESUME since
+	 * non-MPSAFE drivers need this.
+	 */
+	mtx_lock(&Giant);
 	error = DEVICE_SUSPEND(root_bus);
+	mtx_unlock(&Giant);
 	if (error)
 		return;
 
@@ -496,7 +502,9 @@ apm_do_suspend(void)
 	} else {
 		/* Failure, 'resume' the system again */
 		apm_execute_hook(hook[APM_HOOK_RESUME]);
+		mtx_lock(&Giant);
 		DEVICE_RESUME(root_bus);
+		mtx_unlock(&Giant);
 	}
 	return;
 }
@@ -602,7 +610,9 @@ apm_resume(void)
 
 	sc->suspending = 0;
 	apm_execute_hook(hook[APM_HOOK_RESUME]);
+	mtx_lock(&Giant);
 	DEVICE_RESUME(root_bus);
+	mtx_unlock(&Giant);
 	return;
 }
 


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-i386 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Tue Jan 15 05:10:14 UTC 2008 
Responsible-Changed-Why:  
Recategorize. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=116347 
State-Changed-From-To: open->closed 
State-Changed-By: zec 
State-Changed-When: Fri Oct 17 15:06:45 UTC 2008 
State-Changed-Why:  
The patch was commited by julian 11 months ago in 
src/sys/i386/bios/apm.c 1.149 



Responsible-Changed-From-To: freebsd-i386->zec 
Responsible-Changed-By: zec 
Responsible-Changed-When: Fri Oct 17 15:06:45 UTC 2008 
Responsible-Changed-Why:  
The patch was commited by julian 11 months ago in 
src/sys/i386/bios/apm.c 1.149 

Suspending USB with APM seems to work fine in both head and releng/7 now. 


http://www.freebsd.org/cgi/query-pr.cgi?pr=116347 
>Unformatted:
