blob: 17830a81be141743e06f5ac837ff0747ab314652 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Functions local to drivers/usb/core/ */
2
Greg Kroah-Hartman1b21d5e2006-08-28 11:43:25 -07003extern int usb_create_sysfs_dev_files (struct usb_device *dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004extern void usb_remove_sysfs_dev_files (struct usb_device *dev);
Greg Kroah-Hartman1b21d5e2006-08-28 11:43:25 -07005extern int usb_create_sysfs_intf_files (struct usb_interface *intf);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006extern void usb_remove_sysfs_intf_files (struct usb_interface *intf);
Greg Kroah-Hartman1b21d5e2006-08-28 11:43:25 -07007extern int usb_create_ep_files(struct device *parent, struct usb_host_endpoint *endpoint,
Greg Kroah-Hartman84412f62006-06-14 12:14:34 -07008 struct usb_device *udev);
9extern void usb_remove_ep_files(struct usb_host_endpoint *endpoint);
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
11extern void usb_disable_endpoint (struct usb_device *dev, unsigned int epaddr);
12extern void usb_disable_interface (struct usb_device *dev,
13 struct usb_interface *intf);
14extern void usb_release_interface_cache(struct kref *ref);
15extern void usb_disable_device (struct usb_device *dev, int skip_ep0);
16
17extern int usb_get_device_descriptor(struct usb_device *dev,
18 unsigned int size);
Alan Stern4f62efe2005-10-24 16:24:14 -040019extern char *usb_cache_string(struct usb_device *udev, int index);
Linus Torvalds1da177e2005-04-16 15:20:36 -070020extern int usb_set_configuration(struct usb_device *dev, int configuration);
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022extern void usb_kick_khubd(struct usb_device *dev);
23extern void usb_resume_root_hub(struct usb_device *dev);
24
Greg KH6d5e8252005-04-18 17:39:24 -070025extern int usb_hub_init(void);
26extern void usb_hub_cleanup(void);
27extern int usb_major_init(void);
28extern void usb_major_cleanup(void);
29extern int usb_host_init(void);
30extern void usb_host_cleanup(void);
31
Alan Sternd388dab2006-07-01 22:14:24 -040032#ifdef CONFIG_PM
33
Alan Sterna8e7c562006-07-01 22:11:02 -040034extern int usb_suspend_both(struct usb_device *udev, pm_message_t msg);
35extern int usb_resume_both(struct usb_device *udev);
Alan Stern140d8f62006-07-01 22:07:21 -040036extern int usb_port_suspend(struct usb_device *dev);
37extern int usb_port_resume(struct usb_device *dev);
David Brownell5edbfb72005-09-22 22:45:26 -070038
Alan Sterne0318eb2006-09-26 14:50:20 -040039static inline void usb_pm_lock(struct usb_device *udev)
40{
41 mutex_lock_nested(&udev->pm_mutex, udev->level);
42}
43
44static inline void usb_pm_unlock(struct usb_device *udev)
45{
46 mutex_unlock(&udev->pm_mutex);
47}
48
Alan Sternd388dab2006-07-01 22:14:24 -040049#else
50
51#define usb_suspend_both(udev, msg) 0
Alexey Dobriyan42d8a2d2006-08-20 18:58:42 +040052static inline int usb_resume_both(struct usb_device *udev)
53{
54 return 0;
55}
Alan Sternd388dab2006-07-01 22:14:24 -040056#define usb_port_suspend(dev) 0
57#define usb_port_resume(dev) 0
Alan Sterne0318eb2006-09-26 14:50:20 -040058static inline void usb_pm_lock(struct usb_device *udev) {}
59static inline void usb_pm_unlock(struct usb_device *udev) {}
Alan Sternd388dab2006-07-01 22:14:24 -040060
61#endif
62
Alan Stern645daaa2006-08-30 15:47:02 -040063#ifdef CONFIG_USB_SUSPEND
64
65#define USB_AUTOSUSPEND_DELAY (HZ*2)
66
Alan Stern94fcda12006-11-20 11:38:46 -050067extern void usb_autosuspend_device(struct usb_device *udev);
68extern int usb_autoresume_device(struct usb_device *udev);
Alan Stern645daaa2006-08-30 15:47:02 -040069
70#else
71
Alan Stern94fcda12006-11-20 11:38:46 -050072#define usb_autosuspend_device(udev) do {} while (0)
73static inline int usb_autoresume_device(struct usb_device *udev)
Alan Sterne0318eb2006-09-26 14:50:20 -040074{
75 return 0;
76}
Alan Stern645daaa2006-08-30 15:47:02 -040077
78#endif
79
Alan Sternbd859282006-09-19 10:14:07 -040080extern struct workqueue_struct *ksuspend_usb_wq;
Alan Stern36e56a32006-07-01 22:08:06 -040081extern struct bus_type usb_bus_type;
Alan Stern8bb54ab2006-07-01 22:08:49 -040082extern struct usb_device_driver usb_generic_driver;
83
84/* Here's how we tell apart devices and interfaces. Luckily there's
85 * no such thing as a platform USB device, so we can steal the use
86 * of the platform_data field. */
87
Luiz Fernando N. Capitulino095bc332006-08-26 23:48:11 -030088static inline int is_usb_device(const struct device *dev)
Alan Stern8bb54ab2006-07-01 22:08:49 -040089{
90 return dev->platform_data == &usb_generic_driver;
91}
92
93/* Do the same for device drivers and interface drivers. */
94
95static inline int is_usb_device_driver(struct device_driver *drv)
96{
97 return container_of(drv, struct usbdrv_wrap, driver)->
98 for_devices;
99}
David Brownell5edbfb72005-09-22 22:45:26 -0700100
David Brownelldb690872005-09-13 19:56:33 -0700101/* Interfaces and their "power state" are owned by usbcore */
102
103static inline void mark_active(struct usb_interface *f)
104{
Alan Stern4d064c02006-07-01 22:11:44 -0400105 f->is_active = 1;
David Brownelldb690872005-09-13 19:56:33 -0700106}
107
108static inline void mark_quiesced(struct usb_interface *f)
109{
Alan Stern4d064c02006-07-01 22:11:44 -0400110 f->is_active = 0;
David Brownelldb690872005-09-13 19:56:33 -0700111}
112
Luiz Fernando N. Capitulino095bc332006-08-26 23:48:11 -0300113static inline int is_active(const struct usb_interface *f)
David Brownelldb690872005-09-13 19:56:33 -0700114{
Alan Stern4d064c02006-07-01 22:11:44 -0400115 return f->is_active;
David Brownelldb690872005-09-13 19:56:33 -0700116}
117
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119/* for labeling diagnostics */
120extern const char *usbcore_name;
121
122/* usbfs stuff */
Alan Stern4a2a8a22006-07-01 22:05:01 -0400123extern struct mutex usbfs_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124extern struct usb_driver usbfs_driver;
Luiz Fernando N. Capitulino066202d2006-08-05 20:37:11 -0300125extern const struct file_operations usbfs_devices_fops;
126extern const struct file_operations usbfs_device_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127extern void usbfs_conn_disc_event(void);
128
Kay Sieversfbf82fd2005-07-31 01:05:53 +0200129extern int usbdev_init(void);
130extern void usbdev_cleanup(void);
Greg KH6d5e8252005-04-18 17:39:24 -0700131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132struct dev_state {
133 struct list_head list; /* state list */
134 struct usb_device *dev;
135 struct file *file;
136 spinlock_t lock; /* protects the async urb lists */
137 struct list_head async_pending;
138 struct list_head async_completed;
139 wait_queue_head_t wait; /* wake up if a request completed */
140 unsigned int discsignr;
Eric W. Biederman2425c082006-10-02 02:17:28 -0700141 struct pid *disc_pid;
Linus Torvaldsd7dd8a72005-10-10 16:31:30 -0700142 uid_t disc_uid, disc_euid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 void __user *disccontext;
144 unsigned long ifclaimed;
David Quigley7a019552006-06-30 01:55:48 -0700145 u32 secid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146};
147
Greg Kroah-Hartman3099e752005-06-20 21:15:16 -0700148/* internal notify stuff */
149extern void usb_notify_add_device(struct usb_device *udev);
150extern void usb_notify_remove_device(struct usb_device *udev);
151extern void usb_notify_add_bus(struct usb_bus *ubus);
152extern void usb_notify_remove_bus(struct usb_bus *ubus);
153