From owner-acpi-jp@jp.FreeBSD.org Sat Jul 12 12:58:32 2003
Received: (from daemon@localhost)
	by castle.jp.FreeBSD.org (8.11.6p2+3.4W/8.11.3) id h6C3wWT79357;
	Sat, 12 Jul 2003 12:58:32 +0900 (JST)
	(envelope-from owner-acpi-jp@jp.FreeBSD.org)
Received: from mta03.fuse.net (mx3.fuse.net [216.68.1.123])
	by castle.jp.FreeBSD.org (8.11.6p2+3.4W/8.11.3) with ESMTP/inet id h6C3wVT79352
	for <acpi-jp@jp.FreeBSD.org>; Sat, 12 Jul 2003 12:58:31 +0900 (JST)
	(envelope-from mistry.7@osu.edu)
Received: from [192.168.1.100] ([66.42.172.210]) by mta03.fuse.net
          (InterMail vM.5.01.05.27 201-253-122-126-127-20021220) with ESMTP
          id <20030712035827.YMG2095.mta03.fuse.net@[192.168.1.100]>;
          Fri, 11 Jul 2003 23:58:27 -0400
From: Anish Mistry <mistry.7@osu.edu>
To: Nate Lawson <nate@root.org>
User-Agent: KMail/1.5
References: <20030701010230.U86209@root.org> <200307112012.11202.mistry.7@osu.edu> <20030711174800.A9023@root.org>
In-Reply-To: <20030711174800.A9023@root.org>
Cc: freebsd-current@freebsd.org, acpi-jp@jp.FreeBSD.org, imp@bsdimp.com
MIME-Version: 1.0
Content-Type: Multipart/Mixed;
  boundary="Boundary-00=_ce4D/+TO67fRxYS"
Message-Id: <200307112359.36205.mistry.7@osu.edu>
Reply-To: acpi-jp@jp.FreeBSD.org
Precedence: list
Date: Fri, 11 Jul 2003 23:59:24 -0400
X-Sequence: acpi-jp 2409
Subject: [acpi-jp 2409] Re: Updated ec-burst.diff patch
Sender: owner-acpi-jp@jp.FreeBSD.org
X-Originator: mistry.7@osu.edu
X-Distribute: distribute version 2.1 (Alpha) patchlevel 24e+030702


--Boundary-00=_ce4D/+TO67fRxYS
Content-Type: Text/Plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Description: clearsigned data
Content-Disposition: inline

=2D----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Attached is some hokey magic, which will cause your system to panic if you=
=20
have a device plugged in a being access when you go into suspend.  The pani=
c=20
will be on resume.  I think it is because the usb interrupts change at leas=
t=20
that is what i gather from gdb.  It is only for ohci since that's all I hav=
e,=20
but I'm sure the same stuff will work for uhci and ehci.
If there is a way to force all the usb device to detach right before we=20
suspend then there is a good chance that this could work without causing=20
panics.

=2D --=20
Anish Mistry
=2D----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (FreeBSD)

iD8DBQE/D4enxqA5ziudZT0RAjvTAKDSxYlsr4Psrb2qHPWMKoiSeucAMACdHqac
wrk2eRCKrC3EJiQlRVrZhRk=3D
=3DJEYV
=2D----END PGP SIGNATURE-----

--Boundary-00=_ce4D/+TO67fRxYS
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="ohci-usb-sr.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="ohci-usb-sr.patch"

diff -u usb.orig/ohci.c usb/ohci.c
--- usb.orig/ohci.c	Fri Jul 11 23:24:24 2003
+++ usb/ohci.c	Fri Jul 11 23:19:16 2003
@@ -998,7 +998,7 @@
 	DPRINTF(("ohci_shutdown: stopping the HC\n"));
 	OWRITE4(sc, OHCI_CONTROL, OHCI_HCFS_RESET);
 }
-
+#endif
 /*
  * Handle suspend/resume.
  *
@@ -1006,6 +1006,27 @@
  * called from an intterupt context.  This is all right since we
  * are almost suspended anyway.
  */
+usbd_status ohci_resume(struct ohci_softc *sc)
+{
+	return ohci_init(sc);
+}
+
+usbd_status ohci_suspend(struct ohci_softc *sc)
+{
+       u_int32_t ctl,i;
+       /* free the memory */
+       for (i = 0; i < OHCI_NO_EDS; i++)
+               ohci_free_sed(sc, sc->sc_eds[i]);
+	ohci_free_sed(sc,sc->sc_ctrl_head);
+	ohci_free_sed(sc,sc->sc_bulk_head);
+	ohci_free_sed(sc,sc->sc_isoc_head);
+
+	usb_freemem(&sc->sc_bus, &sc->sc_hccadma);
+
+        return (USBD_NORMAL_COMPLETION);
+}
+
+#if defined(__NetBSD__) || defined(__OpenBSD__)
 void
 ohci_power(int why, void *v)
 {
diff -u usb.orig/ohci_pci.c usb/ohci_pci.c
--- usb.orig/ohci_pci.c	Fri Jul 11 23:24:12 2003
+++ usb/ohci_pci.c	Fri Jul 11 23:43:35 2003
@@ -295,11 +295,43 @@
 	return 0;
 }
 
+/* implement suspend and resume */
+static int
+ohci_pci_suspend(device_t self)
+{
+       int err;
+       ohci_softc_t *sc = device_get_softc(self);
+       device_printf(self, "ohci_pci_suspend: power_state = 0x%08x\n",
+                                       pci_get_powerstate(self));
+       err = bus_generic_suspend(self);
+       if (err)
+               return err;
+       ohci_suspend(sc);
+       usb_delay_ms(&sc->sc_bus, USB_RESUME_WAIT);
+       return 0;
+}
+
+static int
+ohci_pci_resume(device_t self)
+{
+       ohci_softc_t *sc = device_get_softc(self);
+       device_printf(self, "ohci_pci_resume: power_state = 0x%08x\n",
+                                       pci_get_powerstate(self));
+       ohci_resume(sc);
+       usb_delay_ms(&sc->sc_bus, USB_RESUME_DELAY);
+       usb_delay_ms(&sc->sc_bus, USB_RESUME_RECOVERY);
+	bus_generic_resume(self);
+
+       return 0;
+}
+
 static device_method_t ohci_methods[] = {
 	/* Device interface */
 	DEVMETHOD(device_probe, ohci_pci_probe),
 	DEVMETHOD(device_attach, ohci_pci_attach),
-	DEVMETHOD(device_shutdown, bus_generic_shutdown),
+	DEVMETHOD(device_suspend, ohci_pci_suspend),
+	DEVMETHOD(device_resume, ohci_pci_resume),
+ 	DEVMETHOD(device_shutdown, bus_generic_shutdown),
 
 	/* Bus interface */
 	DEVMETHOD(bus_print_child, bus_generic_print_child),
diff -u usb.orig/ohcivar.h usb/ohcivar.h
--- usb.orig/ohcivar.h	Fri Jul 11 23:24:41 2003
+++ usb/ohcivar.h	Fri Jul 11 23:25:48 2003
@@ -154,6 +154,8 @@
 #define OXFER(xfer) ((struct ehci_xfer *)(xfer))
 
 usbd_status	ohci_init(ohci_softc_t *);
+usbd_status	ohci_suspend(ohci_softc_t *);
+usbd_status	ohci_resume(ohci_softc_t *);
 int		ohci_intr(void *);
 #if defined(__NetBSD__) || defined(__OpenBSD__)
 int		ohci_detach(ohci_softc_t *, int);

--Boundary-00=_ce4D/+TO67fRxYS--

