Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 4 Jun 2007 07:08:06 GMT
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 120882 for review
Message-ID:  <200706040708.l54786Zf035447@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=120882

Change 120882 by hselasky@hselasky_mini_itx on 2007/06/04 07:08:00

	Add a new function, usb_cdev_opened(). Some other small
	nits.

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb/usb_cdev.c#13 edit
.. //depot/projects/usb/src/sys/dev/usb/usb_subr.h#39 edit

Differences ...

==== //depot/projects/usb/src/sys/dev/usb/usb_cdev.c#13 (text+ko) ====

@@ -1,3 +1,6 @@
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/sys/dev/usb/usb_cdev.c $");
+
 /*-
  * Copyright (c) 2006 Hans Petter Selasky. All rights reserved.
  * 
@@ -27,13 +30,10 @@
  *
  */
 
-#include <sys/cdefs.h>
 #include <sys/param.h>
 #include <sys/systm.h>
 #include <sys/kernel.h>
 #include <sys/malloc.h>
-#include <sys/ioccom.h>
-#include <sys/filio.h>
 #include <sys/tty.h>
 #include <sys/file.h>
 #include <sys/vnode.h>
@@ -45,11 +45,9 @@
 #include <dev/usb/usb.h>
 #include <dev/usb/usb_subr.h>
 
-__FBSDID("$FreeBSD: src/sys/dev/usb/usb_cdev.c $");
-
 #ifdef USB_DEBUG
-#define DPRINTF(n,fmt,...)						\
-  do { if (usb_cdev_debug > (n)) {						\
+#define DPRINTF(n,fmt,...)	\
+  do { if (usb_cdev_debug > (n)) {	\
       printf("%s: " fmt, __FUNCTION__,## __VA_ARGS__); } } while (0)
 
 static int usb_cdev_debug = 0;
@@ -190,8 +188,8 @@
 
 	sc->sc_flags |= context_bit;
 
-	error = mtx_sleep(ident, sc->sc_mtx_ptr, PRIBIO|PCATCH, 
-		       "usb_cdev_msleep", 0);
+	error = mtx_sleep(ident, sc->sc_mtx_ptr, PCATCH, 
+			  "usb_cdev_msleep", 0);
 
 	return usb_cdev_exit_context(sc, context_bit, error);
 }
@@ -205,8 +203,8 @@
 			USB_CDEV_FLAG_SLEEP_IOCTL_WR|
 			USB_CDEV_FLAG_WAKEUP_IOCTL_RD|
 			USB_CDEV_FLAG_WAKEUP_IOCTL_WR);
-	return usb_cdev_msleep(sc, &(sc->sc_wakeup_ioctl), context_bit, 
-			       timeout);
+	return usb_cdev_msleep(sc, &(sc->sc_wakeup_ioctl),
+			       context_bit, timeout);
 }
 
 void
@@ -251,13 +249,13 @@
 }
 
 /*
- * the synchronization part is a little more
+ * The synchronization part is a little more
  * complicated, hence there are two modes:
  *
  * 1) read only and write only, two threads
  * 2) read and write, one thread
  *
- * the job of the following function is to ensure
+ * The job of the following function is to ensure
  * that only one thread enters a piece of code at
  * a time:
  */
@@ -326,6 +324,20 @@
 	return;
 }
 
+uint8_t
+usb_cdev_opened(struct usb_cdev *sc)
+{
+	uint8_t temp;
+	mtx_lock(sc->sc_mtx_ptr);
+	temp = 
+	  (sc->sc_flags &
+	   (USB_CDEV_FLAG_OPEN_READ|
+	    USB_CDEV_FLAG_OPEN_WRITE|
+	    USB_CDEV_FLAG_GONE)) ? 1 : 0;
+	mtx_unlock(sc->sc_mtx_ptr);
+	return temp;
+}
+
 static int32_t
 usb_cdev_open(struct cdev *dev, int32_t oflags, int32_t devtype, 
 	      struct thread *td)
@@ -492,8 +504,8 @@
 		    wakeup(&(sc->sc_wakeup_ioctl));
 		}
 
-		error = mtx_sleep(&(sc->sc_wakeup_close_read), sc->sc_mtx_ptr, 
-			       PRIBIO, "usb_cdev_sync_read", 0);
+		error = mtx_sleep(&(sc->sc_wakeup_close_read), sc->sc_mtx_ptr,
+				  0, "usb_cdev_sync_read", 0);
 	    }
 
 	    if (sc->sc_flags & USB_CDEV_FLAG_SELECT_READ) {
@@ -537,7 +549,7 @@
 		while (sc->sc_flags & USB_CDEV_FLAG_FLUSHING_WRITE) {
 
 		    error = mtx_sleep(&(sc->sc_wakeup_flush), sc->sc_mtx_ptr, 
-				   PRIBIO|PCATCH, "usb_cdev_flush", 0);
+				      PCATCH, "usb_cdev_flush", 0);
 
 		    if (error || (sc->sc_flags & context_bit &
 				  (USB_CDEV_FLAG_GONE|
@@ -578,7 +590,7 @@
 		}
 
 		error = mtx_sleep(&(sc->sc_wakeup_close_write), sc->sc_mtx_ptr, 
-			       PRIBIO, "usb_cdev_sync_write", 0);
+				  0, "usb_cdev_sync_write", 0);
 	    }
 
 	    if (sc->sc_flags & USB_CDEV_FLAG_SELECT_WRITE) {
@@ -821,7 +833,11 @@
 		        error = EBUSY;
 			break;
 		    }
+#if defined(__NetBSD__)
+		    sc->sc_async_rd = td;
+#else
 		    sc->sc_async_rd = td->td_proc;
+#endif
 		} else {
 		    sc->sc_async_rd = NULL;
 		}
@@ -832,7 +848,11 @@
 		        error = EBUSY;
 			break;
 		    }
+#if defined(__NetBSD__)
+		    sc->sc_async_wr = td;
+#else
 		    sc->sc_async_wr = td->td_proc;
+#endif
 		} else {
 		    sc->sc_async_wr = NULL;
 		}
@@ -1014,7 +1034,7 @@
 		const char **pp_dev,
 		uid_t _uid,
 		gid_t _gid,
-		int _perms,
+		int32_t _perms,
 		u_int32_t rd_size, 
 		u_int16_t rd_packets,
 		u_int32_t wr_size,
@@ -1068,7 +1088,9 @@
 			   rd_size, rd_packets);
 
 	if (sc->sc_rdq_pointer == NULL) {
-	    goto detach;
+	    if (rd_size || rd_packets) {
+	        goto detach;
+	    }
 	}
 
  	sc->sc_wrq_pointer = 
@@ -1076,7 +1098,9 @@
 			   wr_size, wr_packets);
 
 	if (sc->sc_wrq_pointer == NULL) {
-	    goto detach;
+	    if (wr_size || wr_packets) {
+	        goto detach;
+	    }
 	}
 
 	for (n = 0; n < USB_CDEV_COUNT; n++) {
@@ -1161,7 +1185,7 @@
 			       USB_CDEV_FLAG_OPEN_WRITE)) {
 
 	    error = mtx_sleep(&(sc->sc_wakeup_detach), sc->sc_mtx_ptr, 
-			   PRIBIO, "usb_cdev_sync_detach", 0);
+			      0, "usb_cdev_sync_detach", 0);
 	}
 	mtx_unlock(sc->sc_mtx_ptr);
 

==== //depot/projects/usb/src/sys/dev/usb/usb_subr.h#39 (text+ko) ====

@@ -73,6 +73,7 @@
 struct usbd_xfer;
 struct usbd_pipe;
 struct usbd_bus;
+struct usbd_clone;
 struct usbd_config;
 struct usbd_device;
 struct usbd_interface;
@@ -84,6 +85,7 @@
 struct proc;
 struct usb_hid_descriptor;
 struct usb_device; /* Linux compat */
+struct cdev;
 
 typedef uint8_t usbd_status;
 
@@ -173,9 +175,12 @@
 
 	device_t		bdev; /* filled by HC driver */
 	bus_dma_tag_t		dma_tag; /* filled by HC driver */
+	eventhandler_tag	usb_clone_tag;
 	struct usbd_bus_methods	*methods; /* filled by HC driver */
 	struct usbd_device	*devices[USB_MAX_DEVICES];
  	struct proc		*event_thread;
+	struct cdev		*usb_cdev;
+	struct usbd_clone	*usb_clone_root;
 
  	uint32_t		no_intrs;
 
@@ -190,12 +195,17 @@
 					       */
 	uint8_t			use_polling;
 	uint8_t			usbrev;	/* USB revision */
+	uint8_t			usb_clone_count;
+#define	USB_BUS_MAX_CLONES 128
+
 #define	USBREV_UNKNOWN	0
 #define	USBREV_PRE_1_0	1
 #define	USBREV_1_0	2
 #define	USBREV_1_1	3
 #define	USBREV_2_0	4
-#define	USBREV_STR { "unknown", "pre 1.0", "1.0", "1.1", "2.0" }
+#define	USBREV_2_5	5
+#define	USBREV_STR { "unknown", "pre 1.0", "1.0", "1.1", "2.0", "2.5" }
+	uint8_t			usb_name[32];
 };
 
 struct usbd_interface {
@@ -235,7 +245,8 @@
 	device_t                subdevs_end[0];
 	struct usb_device 	*linux_dev;
 
-	usb_event_cookie_t	cookie;	       /* unique connection id */
+	uint16_t		refcount;
+#define USB_DEV_REFCOUNT_MAX 0xffff
 
 	uint16_t 		power;         /* mA the device uses */
 	int16_t			langid;	       /* language for strings */
@@ -265,6 +276,7 @@
 #define	USBD_PROBED_GENERIC_AND_FOUND    3
 
 	uint8_t			serial[32]; /* serial number */
+	uint8_t			detaching;
 };
 
 struct usbd_config {
@@ -556,8 +568,8 @@
 usbd_status	usbd_probe_and_attach(device_t parent, int32_t port, struct usbd_port *up);
 usbd_status	usbd_new_device(device_t parent, struct usbd_bus *bus, int32_t depth, int32_t speed, int32_t port, struct usbd_port *up);
 void		usbd_free_device(struct usbd_port *up, uint8_t free_subdev);
-void		usb_detach_wait(device_t dv);
-void		usb_detach_wakeup(device_t dv);
+struct usbd_device *usbd_ref_device(struct usbd_bus *bus, uint8_t addr);
+void		usbd_unref_device(struct usbd_device *udev);
 struct usbd_interface *usbd_get_iface(struct usbd_device *udev, uint8_t iface_index);
 void		usbd_set_desc(device_t dev, struct usbd_device *udev);
 void *		usbd_alloc_mbufs(struct malloc_type *type, struct usbd_ifqueue *ifq, uint32_t block_size, uint16_t block_number);
@@ -609,8 +621,6 @@
 
 extern uint8_t usb_driver_added_refcount;
 
-void		usbd_add_dev_event(int32_t type, struct usbd_device *udev);
-void		usbd_add_drv_event(int32_t type, struct usbd_device *udev, device_t dev);
 void		usb_needs_explore(struct usbd_device *udev);
 void		usb_needs_probe_and_attach(void);
 
@@ -657,18 +667,17 @@
 void		usbd_clearstall_callback(struct usbd_xfer *xfer);
 void		usbd_do_poll(struct usbd_device *udev);
 void		usbd_set_polling(struct usbd_device *udev, int32_t on);
-int32_t		usbd_ratecheck(struct timeval *last);
 const struct usb_devno * usb_match_device(const struct usb_devno *tbl, uint32_t nentries, uint32_t size, uint16_t vendor, uint16_t product);
 int32_t		usbd_driver_load(struct module *mod, int32_t what, void *arg);
 
 /* prototypes from usb_requests.c */
 
 usbd_status	usbreq_reset_port(struct usbd_device *udev, int32_t port, usb_port_status_t *ps);
-usbd_status	usbreq_get_desc(struct usbd_device *udev, int32_t type, int32_t index, int32_t len, void *desc, int32_t timeout);
-usbd_status	usbreq_get_string_any(struct usbd_device *udev, int32_t si, char *buf, int32_t len);
-usbd_status	usbreq_get_string_desc(struct usbd_device *udev, int32_t sindex, int32_t langid, usb_string_descriptor_t *sdesc, int32_t *plen);
-usbd_status	usbreq_get_config_desc(struct usbd_device *udev, int32_t confidx, usb_config_descriptor_t *d);
-usbd_status	usbreq_get_config_desc_full(struct usbd_device *udev, int32_t conf, void *d, int32_t size);
+usbd_status	usbreq_get_desc(struct usbd_device *udev, uint8_t type, uint8_t index, uint16_t len, void *desc, uint32_t timeout);
+usbd_status	usbreq_get_string_any(struct usbd_device *udev, uint8_t si, char *buf, uint16_t len);
+usbd_status	usbreq_get_string_desc(struct usbd_device *udev, uint8_t sindex, uint16_t langid, usb_string_descriptor_t *sdesc, uint8_t *plen);
+usbd_status	usbreq_get_config_desc(struct usbd_device *udev, uint8_t confidx, usb_config_descriptor_t *d);
+usbd_status	usbreq_get_config_desc_full(struct usbd_device *udev, uint8_t conf, void *d, uint16_t size);
 usbd_status	usbreq_get_device_desc(struct usbd_device *udev, usb_device_descriptor_t *d);
 usbd_status	usbreq_get_interface(struct usbd_device *udev, uint8_t iface_index, uint8_t *aiface);
 usbd_status	usbreq_set_interface(struct usbd_device *udev, uint8_t iface_index, uint8_t altno);
@@ -720,6 +729,7 @@
 void		usb_cdev_put_data_error(struct usb_cdev *sc);
 uint8_t		usb_cdev_get_data(struct usb_cdev *sc, uint8_t *buf, uint32_t len, uint32_t *actlen, uint8_t what);
 void		usb_cdev_get_data_error(struct usb_cdev *sc);
+uint8_t		usb_cdev_opened(struct usb_cdev *sc);
 
 typedef int32_t (usb_cdev_open_t)(struct usb_cdev *sc, int32_t fflags, int32_t mode, struct thread *td);
 typedef int32_t (usb_cdev_ioctl_t)(struct usb_cdev *sc, u_long cmd, caddr_t addr, int32_t fflags, struct thread *td);
@@ -739,6 +749,7 @@
 	void 			*sc_wrq_pointer;
 	struct mtx 		*sc_mtx_ptr;
 	void 			*sc_priv_ptr;
+	void			*sc_fifo_ptr;
 #define	USB_CDEV_COUNT 4
 	struct cdev 		*sc_cdev[USB_CDEV_COUNT];
 	struct cdev 		*sc_last_cdev;
@@ -808,4 +819,15 @@
 /* prototypes from "usb_compat_linux.c" */
 void	usb_linux_free_usb_device(struct usb_device *dev);
 
+/* USB clone support */
+struct usbd_clone {
+    struct mtx mtx;
+    struct usb_cdev cdev;
+
+    struct usbd_bus *bus;
+    struct usbd_clone *next;
+
+    uint8_t unit;
+};
+
 #endif /* _USB_SUBR_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200706040708.l54786Zf035447>