From owner-svn-src-all@FreeBSD.ORG Fri Jun 24 18:14:43 2011 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (unknown [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7FB0B1065670; Fri, 24 Jun 2011 18:14:43 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [69.147.83.44]) by mx1.freebsd.org (Postfix) with ESMTP id 6F8D58FC14; Fri, 24 Jun 2011 18:14:43 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p5OIEhqa065251; Fri, 24 Jun 2011 18:14:43 GMT (envelope-from hselasky@svn.freebsd.org) Received: (from hselasky@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p5OIEhXE065248; Fri, 24 Jun 2011 18:14:43 GMT (envelope-from hselasky@svn.freebsd.org) Message-Id: <201106241814.p5OIEhXE065248@svn.freebsd.org> From: Hans Petter Selasky Date: Fri, 24 Jun 2011 18:14:43 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r223512 - head/sys/dev/usb X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Jun 2011 18:14:43 -0000 Author: hselasky Date: Fri Jun 24 18:14:43 2011 New Revision: 223512 URL: http://svn.freebsd.org/changeset/base/223512 Log: - Move execution of event handlers into the probe and attach function so that dynamically loaded device drivers get a chance to run their event hooks. - Decouple the USB suspend and resume lock from witness. It produces some false warnings due to reusing the lock name among multiple devices. MFC after: 3 days Modified: head/sys/dev/usb/usb_device.c head/sys/dev/usb/usb_msctest.c Modified: head/sys/dev/usb/usb_device.c ============================================================================== --- head/sys/dev/usb/usb_device.c Fri Jun 24 18:11:55 2011 (r223511) +++ head/sys/dev/usb/usb_device.c Fri Jun 24 18:14:43 2011 (r223512) @@ -1297,6 +1297,21 @@ usb_probe_and_attach(struct usb_device * usb_init_attach_arg(udev, &uaa); + /* + * If the whole USB device is targeted, invoke the USB event + * handler(s): + */ + if (iface_index == USB_IFACE_INDEX_ANY) { + + EVENTHANDLER_INVOKE(usb_dev_configured, udev, &uaa); + + if (uaa.dev_state != UAA_DEV_READY) { + /* leave device unconfigured */ + usb_unconfigure(udev, 0); + goto done; + } + } + /* Check if only one interface should be probed: */ if (iface_index != USB_IFACE_INDEX_ANY) { i = iface_index; @@ -1526,7 +1541,7 @@ usb_alloc_device(device_t parent_dev, st /* initialise our SX-lock */ sx_init_flags(&udev->enum_sx, "USB config SX lock", SX_DUPOK); - sx_init_flags(&udev->sr_sx, "USB suspend and resume SX lock", SX_DUPOK); + sx_init_flags(&udev->sr_sx, "USB suspend and resume SX lock", SX_NOWITNESS); cv_init(&udev->ctrlreq_cv, "WCTRL"); cv_init(&udev->ref_cv, "UGONE"); @@ -1834,11 +1849,6 @@ repeat_set_config: } } } - EVENTHANDLER_INVOKE(usb_dev_configured, udev, &uaa); - if (uaa.dev_state != UAA_DEV_READY) { - /* leave device unconfigured */ - usb_unconfigure(udev, 0); - } config_done: DPRINTF("new dev (addr %d), udev=%p, parent_hub=%p\n", Modified: head/sys/dev/usb/usb_msctest.c ============================================================================== --- head/sys/dev/usb/usb_msctest.c Fri Jun 24 18:11:55 2011 (r223511) +++ head/sys/dev/usb/usb_msctest.c Fri Jun 24 18:14:43 2011 (r223512) @@ -489,6 +489,24 @@ bbb_attach(struct usb_device *udev, uint struct usb_interface_descriptor *id; struct bbb_transfer *sc; usb_error_t err; + uint8_t do_unlock; + + /* automatic locking */ + if (usbd_enum_is_locked(udev)) { + do_unlock = 0; + } else { + do_unlock = 1; + usbd_enum_lock(udev); + } + + /* + * Make sure any driver which is hooked up to this interface, + * like umass is gone: + */ + usb_detach_device(udev, iface_index, 0); + + if (do_unlock) + usbd_enum_unlock(udev); iface = usbd_get_iface(udev, iface_index); if (iface == NULL)