From nobody@FreeBSD.org  Fri Aug 24 01:10:30 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 959C1106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 24 Aug 2012 01:10:30 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id 6834C8FC17
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 24 Aug 2012 01:10:30 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q7O1AUZn080160
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 24 Aug 2012 01:10:30 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q7O1AUHJ080159;
	Fri, 24 Aug 2012 01:10:30 GMT
	(envelope-from nobody)
Message-Id: <201208240110.q7O1AUHJ080159@red.freebsd.org>
Date: Fri, 24 Aug 2012 01:10:30 GMT
From: Brandon Gooch <jamesbrandongooch@gmail.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] Use DRIVER_MODULE_ORDERED and SI_ORDER_ANY in vga_isa.c to ensure driver ordering  
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         170949
>Category:       kern
>Synopsis:       [vga] [patch] Use DRIVER_MODULE_ORDERED and SI_ORDER_ANY in vga_isa.c to ensure driver ordering
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Aug 24 01:20:03 UTC 2012
>Closed-Date:    
>Last-Modified:  Fri Aug 24 01:56:38 UTC 2012
>Originator:     Brandon Gooch
>Release:        10-CURRENT
>Organization:
>Environment:
FreeBSD m6500.local 10.0-CURRENT FreeBSD 10.0-CURRENT #0 r239550M: Wed Aug 22 00:35:46 CDT 2012     root@m6500.local:/usr/obj/usr/src/sys/DELL_M6500  amd64

>Description:
The vgapm device driver must register after the NVIDIA device driver to allow for a functional ACPI suspend and resume cycle.

This patch makes use of the DRIVER_MODULE_ORDERED macro and SI_ORDER_ANY constants to ensure the ordering of device driver registration.

I have used this patch on a variety of systems with success.
>How-To-Repeat:
Use the NVIDIA driver (from ports or from vendor-supplied tarball) with power management enabled. Attempt an ACPI suspend and resume cycle. The video card is not reinitialized properly due to the device driver ordering of vgapm0 and nvidia0:

    pcib0 pnpinfo _HID=PNP0A03 _UID=0 at handle=\_SB_.PCI0
      pci0
        hostb0 pnpinfo vendor=0x8086 device=0xd132 subvendor=0x1028 subdevice=0x02ef class=0x060000 at slot=0 function=0
        pcib1 pnpinfo vendor=0x8086 device=0xd138 subvendor=0x1028 subdevice=0x02ef class=0x060400 at slot=3 function=0 handle=\_SB_.PCI0.AGP1
          pci1
            vgapci0 pnpinfo vendor=0x10de device=0x061f subvendor=0x1028 subdevice=0x02ef class=0x030000 at slot=0 function=0 handle=\_SB_.PCI0.AGP1.VID_
              vgapm0
              nvidia0

>Fix:
After applying the attached patch, rebuild the kernel (install, and reboot). After boot, notice the vgapm0 device driver is registered after the nvidia0 device driver:

    pcib0 pnpinfo _HID=PNP0A03 _UID=0 at handle=\_SB_.PCI0
      pci0
        hostb0 pnpinfo vendor=0x8086 device=0xd132 subvendor=0x1028 subdevice=0x02ef class=0x060000 at slot=0 function=0
        pcib1 pnpinfo vendor=0x8086 device=0xd138 subvendor=0x1028 subdevice=0x02ef class=0x060400 at slot=3 function=0 handle=\_SB_.PCI0.AGP1
          pci1
            vgapci0 pnpinfo vendor=0x10de device=0x061f subvendor=0x1028 subdevice=0x02ef class=0x030000 at slot=0 function=0 handle=\_SB_.PCI0.AGP1.VID_
              nvidia0
              vgapm0

You should be able to perform and suspend/resume cycle successfully.

Patch attached with submission follows:

Index: sys/isa/vga_isa.c
===================================================================
--- sys/isa/vga_isa.c	(revision 239550)
+++ sys/isa/vga_isa.c	(working copy)
@@ -379,4 +379,4 @@
 	0
 };
 
-DRIVER_MODULE(vgapm, vgapci, vgapm_driver, vgapm_devclass, 0, 0);
+DRIVER_MODULE_ORDERED(vgapm, vgapci, vgapm_driver, vgapm_devclass, NULL, NULL, SI_ORDER_ANY);


>Release-Note:
>Audit-Trail:
>Unformatted:
