Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 5 Jun 2006 12:47:12 GMT
From:      Hans Petter Selasky <hselasky@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 98543 for review
Message-ID:  <200606051247.k55ClCbp083189@repoman.freebsd.org>

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

Change 98543 by hselasky@hselasky_mini_itx on 2006/06/05 12:47:03

	Commit of the new "cdev" abstraction layer, USB cdev, that can
	be used to create devices under /dev/... . The USB cdev 
	abstraction layer handles everything related to waiting for devices
	to close during detach, and so can save the programmer some headache
	when programming USB device drivers. The abstraction layer resides
	in the file "usb_cdev.c" and is rather complicated. This is due to the
	fact that it allows two threads to open each device. One read thread, 
	and one write thread. The API of the USB cdev layer is not frozen yet:
	
	usb_cdev_sleep(..):
		This function is used when the code wants to sleep
		during "open()" or "ioctl()".
	
	usb_cdev_wakeup(..):
		This function is used to wakeup a sleeping thread.
	
	usb_cdev_attach(..):
		Attach a new USB CDEV.
	
	usb_cdev_detach(..):
		Detach a USB CDEV.
	
	usb_cdev_put_data(..):
		Write data to a USB CDEV.
	
	usb_cdev_put_data_error(..):
		Signal permanent write error.
	
	usb_cdev_get_data(..):
		Read data from a USB CDEV.
	
	usb_cdev_get_data_error(..):
		Signal permanent read error.

Affected files ...

.. //depot/projects/usb/src/sys/conf/files#5 edit
.. //depot/projects/usb/src/sys/dev/usb/usb_cdev.c#1 add
.. //depot/projects/usb/src/sys/dev/usb/usb_subr.h#7 edit

Differences ...

==== //depot/projects/usb/src/sys/conf/files#5 (text+ko) ====

@@ -989,6 +989,7 @@
 dev/usb/usb_if.m		optional usb
 dev/usb/usb_quirks.c		optional usb
 dev/usb/usb_hid.c		optional usb
+dev/usb/usb_cdev.c		optional usb
 dev/usb/ugen.c			optional ugen
 dev/usb/ulpt.c			optional ulpt
 dev/usb/ums.c			optional ums

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

@@ -704,7 +704,18 @@
 usbd_do_request_flags(struct usbd_device *udev, usb_device_request_t *req,
 		      void *data, u_int32_t flags, int *actlen,
 		      u_int32_t timeout);
-
+void
+usbd_fill_get_report(usb_device_request_t *req, u_int8_t iface_no, 
+		     u_int8_t type, u_int8_t id, u_int16_t size);
+void
+usbd_fill_set_report(usb_device_request_t *req, u_int8_t iface_no,
+		     u_int8_t type, u_int8_t id, u_int16_t size);
+void
+usbd_clear_stall_tr_setup(struct usbd_xfer *xfer1, 
+			  struct usbd_xfer *xfer2);
+void
+usbd_clear_stall_tr_transferred(struct usbd_xfer *xfer1, 
+				struct usbd_xfer *xfer2);
 void
 usbd_clearstall_callback(struct usbd_xfer *xfer);
 
@@ -930,4 +941,132 @@
 #define POINTER_TO_UNSIGNED(ptr) \
   (((u_int8_t *)(ptr)) - ((u_int8_t *)0))
 
+/* routines from "usb_cdev.c" */
+
+struct usb_cdev;
+struct cdev;
+struct mtx;
+
+extern int32_t
+usb_cdev_sleep(struct usb_cdev *sc, int32_t fflags);
+
+extern void
+usb_cdev_wakeup(struct usb_cdev *sc);
+
+extern int32_t
+usb_cdev_attach(struct usb_cdev *sc, 
+		void *priv_sc, 
+		struct mtx *priv_mtx,
+		const char **pp_dev,
+		uid_t _uid,
+		gid_t _gid,
+		int _perms,
+		u_int32_t rd_size, 
+		u_int16_t rd_packets,
+		u_int32_t wr_size,
+		u_int16_t wr_packets);
+
+extern void
+usb_cdev_detach(struct usb_cdev *sc);
+
+extern void
+usb_cdev_put_data(struct usb_cdev *sc, u_int8_t *buf, u_int32_t len, 
+		  u_int8_t what);
+extern void
+usb_cdev_put_data_error(struct usb_cdev *sc);
+
+extern u_int8_t
+usb_cdev_get_data(struct usb_cdev *sc, u_int8_t *buf, u_int32_t len, 
+		  u_int32_t *actlen, u_int8_t what);
+extern void
+usb_cdev_get_data_error(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);
+
+typedef void (usb_cdev_cmd_t)(struct usb_cdev *sc);
+
+struct usb_cdev {
+
+    struct usbd_ifqueue     sc_rdq_free;
+    struct usbd_ifqueue     sc_rdq_used;
+    struct usbd_ifqueue     sc_wrq_free;
+    struct usbd_ifqueue     sc_wrq_used;
+    struct selinfo          sc_read_sel;
+    struct selinfo          sc_write_sel;
+
+    /* various pointers */
+
+    void *                  sc_rdq_pointer;
+    void *                  sc_wrq_pointer;
+    struct mtx *            sc_mtx_ptr;
+    void *                  sc_priv_ptr;
+#define USB_CDEV_COUNT 4
+    struct cdev *           sc_cdev[USB_CDEV_COUNT];
+    struct cdev *           sc_last_cdev;
+    struct proc *           sc_async_rd; /* process that wants SIGIO */
+    struct proc *           sc_async_wr; /* process that wants SIGIO */
+
+    /* multiplexer functions */
+
+    usb_cdev_open_t *       sc_open;
+    usb_cdev_ioctl_t *      sc_ioctl;
+    usb_cdev_cmd_t *        sc_start_read;
+    usb_cdev_cmd_t *        sc_stop_read;
+    usb_cdev_cmd_t *        sc_start_write;
+    usb_cdev_cmd_t *        sc_stop_write;
+
+    u_int32_t               sc_cur_context;
+    u_int32_t               sc_flags;
+
+  /* synchronization flags */
+
+#define USB_CDEV_FLAG_GONE            0x00000001
+#define USB_CDEV_FLAG_FLUSHING_WRITE  0x00000002
+
+#define USB_CDEV_FLAG_OPEN_READ       0x00000004
+#define USB_CDEV_FLAG_OPEN_WRITE      0x00000008
+
+#define USB_CDEV_FLAG_SLEEP_READ      0x00000010
+#define USB_CDEV_FLAG_SLEEP_WRITE     0x00000020
+
+#define USB_CDEV_FLAG_SLEEP_IOCTL_RD  0x00000040
+#define USB_CDEV_FLAG_SLEEP_IOCTL_WR  0x00000080
+
+#define USB_CDEV_FLAG_WAKEUP_READ     0x00000100
+#define USB_CDEV_FLAG_WAKEUP_WRITE    0x00000200
+
+#define USB_CDEV_FLAG_WAKEUP_IOCTL_RD 0x00000400
+#define USB_CDEV_FLAG_WAKEUP_IOCTL_WR 0x00000800
+
+#define USB_CDEV_FLAG_SELECT_READ     0x00001000
+#define USB_CDEV_FLAG_SELECT_WRITE    0x00002000
+
+#define USB_CDEV_FLAG_CLOSING_READ    0x00004000
+#define USB_CDEV_FLAG_CLOSING_WRITE   0x00008000
+
+#define USB_CDEV_FLAG_ERROR_READ      0x00010000 /* can be set to indicate error */
+#define USB_CDEV_FLAG_ERROR_WRITE     0x00020000 /* can be set to indicate error */
+
+  /* other flags */
+
+#define USB_CDEV_FLAG_FWD_SHORT       0x00040000 /* can be set to forward short transfers */
+#define USB_CDEV_FLAG_READ_ONLY       0x00080000 /* device is read only */
+#define USB_CDEV_FLAG_WRITE_ONLY      0x00100000 /* device is read only */
+#define USB_CDEV_FLAG_WAKEUP_RD_IMMED 0x00200000 /* wakeup read thread immediately */
+#define USB_CDEV_FLAG_WAKEUP_WR_IMMED 0x00400000 /* wakeup write thread immediately */
+
+    u_int8_t                sc_wakeup_read; /* dummy */
+    u_int8_t                sc_wakeup_write; /* dummy */
+    u_int8_t                sc_wakeup_flush; /* dummy */
+    u_int8_t                sc_wakeup_close_read; /* dummy */
+    u_int8_t                sc_wakeup_close_write; /* dummy */
+    u_int8_t                sc_wakeup_detach; /* dummy */
+    u_int8_t                sc_wakeup_ioctl; /* dummy */
+    u_int8_t                sc_wakeup_ioctl_rdwr; /* dummy */
+};
+
 #endif /* _USB_SUBR_H_ */



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