⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usb.h

📁 * This driver is to be used as a skeleton driver to be able to create a * USB driver quickly. The
💻 H
📖 第 1 页 / 共 3 页
字号:
	int (*submit_urb) (struct urb* purb);	int (*unlink_urb) (struct urb* purb);};#define DEVNUM_ROUND_ROBIN	/***** OPTION *****//* * Allocated per bus we have */struct usb_bus {	int busnum;			/* Bus number (in order of reg) */	char *bus_name;			/* stable id (PCI slot_name etc) */#ifdef DEVNUM_ROUND_ROBIN	int devnum_next;                /* Next open device number in round-robin allocation */#endif /* DEVNUM_ROUND_ROBIN */	struct usb_devmap devmap;       /* Device map */	struct usb_operations *op;      /* Operations (specific to the HC) */	struct usb_device *root_hub;    /* Root hub */	struct list_head bus_list;	void *hcpriv;                   /* Host Controller private data */	int bandwidth_allocated;	/* on this Host Controller; */					  /* applies to Int. and Isoc. pipes; */					  /* measured in microseconds/frame; */					  /* range is 0..900, where 900 = */					  /* 90% of a 1-millisecond frame */	int bandwidth_int_reqs;		/* number of Interrupt requesters */	int bandwidth_isoc_reqs;	/* number of Isoc. requesters */	/* usbdevfs inode list */	struct list_head inodes;	atomic_t refcnt;};/* * As of USB 2.0, full/low speed devices are segregated into trees. * One type grows from USB 1.1 host controllers (OHCI, UHCI etc). * The other type grows from high speed hubs when they connect to * full/low speed devices using "Transaction Translators" (TTs). * * TTs should only be known to the hub driver, and high speed bus * drivers (only EHCI for now).  They affect periodic scheduling and * sometimes control/bulk error recovery. */struct usb_tt {	struct usb_device	*hub;	/* upstream highspeed hub */	int			multi;	/* true means one TT per port */};/* This is arbitrary. * From USB 2.0 spec Table 11-13, offset 7, a hub can * have up to 255 ports. The most yet reported is 10. */#define USB_MAXCHILDREN		(16)struct usb_device {	int		devnum;		/* Address on USB bus */	char		devpath [16];	/* Use in messages: /port/port/... */	enum {		USB_SPEED_UNKNOWN = 0,			/* enumerating */		USB_SPEED_LOW, USB_SPEED_FULL,		/* usb 1.1 */		USB_SPEED_HIGH				/* usb 2.0 */	} speed;	struct usb_tt	*tt; 		/* low/full speed dev, highspeed hub */	int		ttport;		/* device port on that tt hub */	atomic_t refcnt;		/* Reference count */	struct semaphore serialize;	unsigned int toggle[2];		/* one bit for each endpoint ([0] = IN, [1] = OUT) */	unsigned int halted[2];		/* endpoint halts; one bit per endpoint # & direction; */					/* [0] = IN, [1] = OUT */	int epmaxpacketin[16];		/* INput endpoint specific maximums */	int epmaxpacketout[16];		/* OUTput endpoint specific maximums */	struct usb_device *parent;	struct usb_bus *bus;		/* Bus we're part of */	struct usb_device_descriptor descriptor;/* Descriptor */	struct usb_config_descriptor *config;	/* All of the configs */	struct usb_config_descriptor *actconfig;/* the active configuration */	char **rawdescriptors;		/* Raw descriptors for each config */	int have_langid;		/* whether string_langid is valid yet */	int string_langid;		/* language ID for strings */  	void *hcpriv;			/* Host Controller private data */	        /* usbdevfs inode list */	struct list_head inodes;	struct list_head filelist;	/*	 * Child devices - these can be either new devices	 * (if this is a hub device), or different instances	 * of this same device.	 *	 * Each instance needs its own set of data structures.	 */	int maxchild;			/* Number of ports if hub */	struct usb_device *children[USB_MAXCHILDREN];};extern struct usb_interface *usb_ifnum_to_if(struct usb_device *dev, unsigned ifnum);extern struct usb_endpoint_descriptor *usb_epnum_to_ep_desc(struct usb_device *dev, unsigned epnum);extern int usb_register(struct usb_driver *);extern void usb_deregister(struct usb_driver *);extern void usb_scan_devices(void);/* used these for multi-interface device registration */extern void usb_driver_claim_interface(struct usb_driver *driver, struct usb_interface *iface, void* priv);extern int usb_interface_claimed(struct usb_interface *iface);extern void usb_driver_release_interface(struct usb_driver *driver, struct usb_interface *iface);const struct usb_device_id *usb_match_id(struct usb_device *dev,					 struct usb_interface *interface,					 const struct usb_device_id *id);extern struct usb_bus *usb_alloc_bus(struct usb_operations *);extern void usb_free_bus(struct usb_bus *);extern void usb_register_bus(struct usb_bus *);extern void usb_deregister_bus(struct usb_bus *);extern struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *);extern void usb_free_dev(struct usb_device *);extern void usb_inc_dev_use(struct usb_device *);#define usb_dec_dev_use usb_free_devextern int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request, __u8 requesttype, __u16 value, __u16 index, void *data, __u16 size, int timeout);extern int usb_root_hub_string(int id, int serial, char *type, __u8 *data, int len);extern void usb_connect(struct usb_device *dev);extern void usb_disconnect(struct usb_device **);extern void usb_destroy_configuration(struct usb_device *dev);int usb_get_current_frame_number (struct usb_device *usb_dev);/** * usb_make_path - returns stable device path in the usb tree * @dev: the device whose path is being constructed * @buf: where to put the string * @size: how big is "buf"? * * Returns length of the string (> 0) or negative if size was too small. * * This identifier is intended to be "stable", reflecting physical paths in * hardware such as physical bus addresses for host controllers or ports on * USB hubs.  That makes it stay the same until systems are physically * reconfigured, by re-cabling a tree of USB devices or by moving USB host * controllers.  Adding and removing devices, including virtual root hubs * in host controller driver modules, does not change these path identifers; * neither does rebooting or re-enumerating.  These are more useful identifiers * than changeable ("unstable") ones like bus numbers or device addresses. * (The stability of the id depends on stability of the bus_name associated * with the bus the device uses; that is normally stable.) * * With a partial exception for devices connected to USB 2.0 root hubs, these * identifiers are also predictable.  So long as the device tree isn't changed, * plugging any USB device into a given hub port always gives it the same path. * Because of the use of "companion" controllers, devices connected to ports on * USB 2.0 root hubs (EHCI host controllers) will get one path ID if they are * high speed, and a different one if they are full or low speed. */static inline int usb_make_path (struct usb_device *dev, char *buf, size_t size){	int actual;	actual = snprintf (buf, size, "usb-%s-%s",		dev->bus->bus_name, dev->devpath);	return (actual >= size) ? -1 : actual;}/* * Calling this entity a "pipe" is glorifying it. A USB pipe * is something embarrassingly simple: it basically consists * of the following information: *  - device number (7 bits) *  - endpoint number (4 bits) *  - current Data0/1 state (1 bit) *  - direction (1 bit) *  - speed (1 bit) *  - max packet size (2 bits: 8, 16, 32 or 64) [Historical; now gone.] *  - pipe type (2 bits: control, interrupt, bulk, isochronous) * * That's 18 bits. Really. Nothing more. And the USB people have * documented these eighteen bits as some kind of glorious * virtual data structure. * * Let's not fall in that trap. We'll just encode it as a simple * unsigned int. The encoding is: * *  - max size:		bits 0-1	(00 = 8, 01 = 16, 10 = 32, 11 = 64) [Historical; now gone.] *  - direction:	bit 7		(0 = Host-to-Device [Out], 1 = Device-to-Host [In]) *  - device:		bits 8-14 *  - endpoint:		bits 15-18 *  - Data0/1:		bit 19 *  - speed:		bit 26		(0 = Full, 1 = Low Speed) *  - pipe type:	bits 30-31	(00 = isochronous, 01 = interrupt, 10 = control, 11 = bulk) * * Why? Because it's arbitrary, and whatever encoding we select is really * up to us. This one happens to share a lot of bit positions with the UHCI * specification, so that much of the uhci driver can just mask the bits * appropriately. * * NOTE:  there's no encoding (yet?) for a "high speed" endpoint; treat them * like full speed devices. */#define PIPE_ISOCHRONOUS		0#define PIPE_INTERRUPT			1#define PIPE_CONTROL			2#define PIPE_BULK			3#define usb_maxpacket(dev, pipe, out)	(out \				? (dev)->epmaxpacketout[usb_pipeendpoint(pipe)] \				: (dev)->epmaxpacketin [usb_pipeendpoint(pipe)] )#define usb_packetid(pipe)	(((pipe) & USB_DIR_IN) ? USB_PID_IN : USB_PID_OUT)#define usb_pipeout(pipe)	((((pipe) >> 7) & 1) ^ 1)#define usb_pipein(pipe)	(((pipe) >> 7) & 1)#define usb_pipedevice(pipe)	(((pipe) >> 8) & 0x7f)#define usb_pipe_endpdev(pipe)	(((pipe) >> 8) & 0x7ff)#define usb_pipeendpoint(pipe)	(((pipe) >> 15) & 0xf)#define usb_pipedata(pipe)	(((pipe) >> 19) & 1)#define usb_pipeslow(pipe)	(((pipe) >> 26) & 1)#define usb_pipetype(pipe)	(((pipe) >> 30) & 3)#define usb_pipeisoc(pipe)	(usb_pipetype((pipe)) == PIPE_ISOCHRONOUS)#define usb_pipeint(pipe)	(usb_pipetype((pipe)) == PIPE_INTERRUPT)#define usb_pipecontrol(pipe)	(usb_pipetype((pipe)) == PIPE_CONTROL)#define usb_pipebulk(pipe)	(usb_pipetype((pipe)) == PIPE_BULK)#define PIPE_DEVEP_MASK		0x0007ff00/* The D0/D1 toggle bits */#define usb_gettoggle(dev, ep, out) (((dev)->toggle[out] >> (ep)) & 1)#define	usb_dotoggle(dev, ep, out)  ((dev)->toggle[out] ^= (1 << (ep)))static inline void usb_settoggle(struct usb_device *dev,				 unsigned int ep, 				 unsigned int out,				 int bit){	dev->toggle[out] &= ~(1 << ep);	dev->toggle[out] |= bit << ep;}/* Endpoint halt control/status */#define usb_endpoint_out(ep_dir)	(((ep_dir >> 7) & 1) ^ 1)#define usb_endpoint_halt(dev, ep, out) ((dev)->halted[out] |= (1 << (ep)))#define usb_endpoint_running(dev, ep, out) ((dev)->halted[out] &= ~(1 << (ep)))#define usb_endpoint_halted(dev, ep, out) ((dev)->halted[out] & (1 << (ep)))static inline unsigned int __create_pipe(struct usb_device *dev, unsigned int endpoint){	return (dev->devnum << 8) | (endpoint << 15) |		((dev->speed == USB_SPEED_LOW) << 26);}static inline unsigned int __default_pipe(struct usb_device *dev){	return ((dev->speed == USB_SPEED_LOW) << 26);}/* Create various pipes... */#define usb_sndctrlpipe(dev,endpoint)	((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint))#define usb_rcvctrlpipe(dev,endpoint)	((PIPE_CONTROL << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)#define usb_sndisocpipe(dev,endpoint)	((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint))#define usb_rcvisocpipe(dev,endpoint)	((PIPE_ISOCHRONOUS << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)#define usb_sndbulkpipe(dev,endpoint)	((PIPE_BULK << 30) | __create_pipe(dev,endpoint))#define usb_rcvbulkpipe(dev,endpoint)	((PIPE_BULK << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)#define usb_sndintpipe(dev,endpoint)	((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint))#define usb_rcvintpipe(dev,endpoint)	((PIPE_INTERRUPT << 30) | __create_pipe(dev,endpoint) | USB_DIR_IN)#define usb_snddefctrl(dev)		((PIPE_CONTROL << 30) | __default_pipe(dev))#define usb_rcvdefctrl(dev)		((PIPE_CONTROL << 30) | __default_pipe(dev) | USB_DIR_IN)/* * Send and receive control messages.. */int usb_new_device(struct usb_device *dev);int usb_reset_device(struct usb_device *dev);int usb_set_address(struct usb_device *dev);int usb_get_descriptor(struct usb_device *dev, unsigned char desctype,	unsigned char descindex, void *buf, int size);int usb_get_class_descriptor(struct usb_device *dev, int ifnum, unsigned char desctype,	unsigned char descindex, void *buf, int size);int usb_get_device_descriptor(struct usb_device *dev);int __usb_get_extra_descriptor(char *buffer, unsigned size, unsigned char type, void **ptr);int usb_get_status(struct usb_device *dev, int type, int target, void *data);int usb_get_configuration(struct usb_device *dev);int usb_get_protocol(struct usb_device *dev, int ifnum);int usb_set_protocol(struct usb_device *dev, int ifnum, int protocol);int usb_set_interface(struct usb_device *dev, int ifnum, int alternate);int usb_set_idle(struct usb_device *dev, int ifnum, int duration, int report_id);int usb_set_configuration(struct usb_device *dev, int configuration);int usb_get_report(struct usb_device *dev, int ifnum, unsigned char type,	unsigned char id, void *buf, int size);int usb_set_report(struct usb_device *dev, int ifnum, unsigned char type,	unsigned char id, void *buf, int size);int usb_string(struct usb_device *dev, int index, char *buf, size_t size);int usb_clear_halt(struct usb_device *dev, int pipe);void usb_set_maxpacket(struct usb_device *dev);#define usb_get_extra_descriptor(ifpoint,type,ptr)\	__usb_get_extra_descriptor((ifpoint)->extra,(ifpoint)->extralen,type,(void**)ptr)/* * Debugging helpers.. */void usb_show_device_descriptor(struct usb_device_descriptor *);void usb_show_config_descriptor(struct usb_config_descriptor *);void usb_show_interface_descriptor(struct usb_interface_descriptor *);void usb_show_endpoint_descriptor(struct usb_endpoint_descriptor *);void usb_show_device(struct usb_device *);void usb_show_string(struct usb_device *dev, char *id, int index);#ifdef DEBUG#define dbg(format, arg...) printk(KERN_DEBUG __FILE__ ": " format "\n" , ## arg)#else#define dbg(format, arg...) do {} while (0)#endif#define err(format, arg...) printk(KERN_ERR __FILE__ ": " format "\n" , ## arg)#define info(format, arg...) printk(KERN_INFO __FILE__ ": " format "\n" , ## arg)#define warn(format, arg...) printk(KERN_WARNING __FILE__ ": " format "\n" , ## arg)/* * bus and driver list */extern struct list_head usb_driver_list;extern struct list_head usb_bus_list;extern struct semaphore usb_bus_list_lock;/* * USB device fs stuff */#ifdef CONFIG_USB_DEVICEFS/* * these are expected to be called from the USB core/hub thread * with the kernel lock held */extern void usbdevfs_add_bus(struct usb_bus *bus);extern void usbdevfs_remove_bus(struct usb_bus *bus);extern void usbdevfs_add_device(struct usb_device *dev);extern void usbdevfs_remove_device(struct usb_device *dev);extern int usbdevfs_init(void);extern void usbdevfs_cleanup(void);#else /* CONFIG_USB_DEVICEFS */static inline void usbdevfs_add_bus(struct usb_bus *bus) {}static inline void usbdevfs_remove_bus(struct usb_bus *bus) {}static inline void usbdevfs_add_device(struct usb_device *dev) {}static inline void usbdevfs_remove_device(struct usb_device *dev) {}static inline int usbdevfs_init(void) { return 0; }static inline void usbdevfs_cleanup(void) { }#endif /* CONFIG_USB_DEVICEFS */#endif  /* __KERNEL__ */#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -