blob: ad5fa0338f498631ca71350b198830b3f80ac3fb [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);
Oliver Neukum7ceec1f2007-01-26 14:26:21 +010016extern void usb_detect_quirks(struct usb_device *udev);
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
18extern int usb_get_device_descriptor(struct usb_device *dev,
19 unsigned int size);
Alan Stern4f62efe2005-10-24 16:24:14 -040020extern char *usb_cache_string(struct usb_device *udev, int index);
Linus Torvalds1da177e2005-04-16 15:20:36 -070021extern int usb_set_configuration(struct usb_device *dev, int configuration);
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023extern void usb_kick_khubd(struct usb_device *dev);
Greg Kroah-Hartmanbb417022007-01-26 14:26:21 +010024extern int usb_match_device(struct usb_device *dev,
25 const struct usb_device_id *id);
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Greg KH6d5e8252005-04-18 17:39:24 -070027extern int usb_hub_init(void);
28extern void usb_hub_cleanup(void);
29extern int usb_major_init(void);
30extern void usb_major_cleanup(void);
31extern int usb_host_init(void);
32extern void usb_host_cleanup(void);
33
Alan Sternd388dab2006-07-01 22:14:24 -040034#ifdef CONFIG_PM
35
Alan Stern718efa62007-03-09 15:41:13 -050036extern void usb_autosuspend_work(struct work_struct *work);
Alan Stern140d8f62006-07-01 22:07:21 -040037extern int usb_port_suspend(struct usb_device *dev);
38extern int usb_port_resume(struct usb_device *dev);
Alan Stern6b157c92007-03-13 16:37:30 -040039extern int usb_external_suspend_device(struct usb_device *udev,
40 pm_message_t msg);
41extern int usb_external_resume_device(struct usb_device *udev);
David Brownell5edbfb72005-09-22 22:45:26 -070042
Alan Sterne0318eb2006-09-26 14:50:20 -040043static inline void usb_pm_lock(struct usb_device *udev)
44{
45 mutex_lock_nested(&udev->pm_mutex, udev->level);
46}
47
48static inline void usb_pm_unlock(struct usb_device *udev)
49{
50 mutex_unlock(&udev->pm_mutex);
51}
52
Alan Sternd388dab2006-07-01 22:14:24 -040053#else
54
Alan Stern4956ecc2007-05-30 16:51:28 -040055static inline int usb_port_suspend(struct usb_device *udev)
56{
57 return 0;
58}
59
60static inline int usb_port_resume(struct usb_device *udev)
61{
62 return 0;
63}
64
Alan Sterne0318eb2006-09-26 14:50:20 -040065static inline void usb_pm_lock(struct usb_device *udev) {}
66static inline void usb_pm_unlock(struct usb_device *udev) {}
Alan Sternd388dab2006-07-01 22:14:24 -040067
68#endif
69
Alan Stern645daaa2006-08-30 15:47:02 -040070#ifdef CONFIG_USB_SUSPEND
71
Alan Stern94fcda12006-11-20 11:38:46 -050072extern void usb_autosuspend_device(struct usb_device *udev);
Alan Stern19c26232007-02-20 15:03:32 -050073extern void usb_try_autosuspend_device(struct usb_device *udev);
Alan Stern94fcda12006-11-20 11:38:46 -050074extern int usb_autoresume_device(struct usb_device *udev);
Alan Stern645daaa2006-08-30 15:47:02 -040075
76#else
77
Alan Stern19c26232007-02-20 15:03:32 -050078#define usb_autosuspend_device(udev) do {} while (0)
79#define usb_try_autosuspend_device(udev) do {} while (0)
Alan Stern94fcda12006-11-20 11:38:46 -050080static inline int usb_autoresume_device(struct usb_device *udev)
Alan Sterne0318eb2006-09-26 14:50:20 -040081{
82 return 0;
83}
Alan Stern645daaa2006-08-30 15:47:02 -040084
85#endif
86
Alan Sternbd859282006-09-19 10:14:07 -040087extern struct workqueue_struct *ksuspend_usb_wq;
Alan Stern36e56a32006-07-01 22:08:06 -040088extern struct bus_type usb_bus_type;
Kay Sievers9f8b17e2007-03-13 15:59:31 +010089extern struct device_type usb_device_type;
90extern struct device_type usb_if_device_type;
Alan Stern8bb54ab2006-07-01 22:08:49 -040091extern struct usb_device_driver usb_generic_driver;
92
Luiz Fernando N. Capitulino095bc332006-08-26 23:48:11 -030093static inline int is_usb_device(const struct device *dev)
Alan Stern8bb54ab2006-07-01 22:08:49 -040094{
Kay Sievers9f8b17e2007-03-13 15:59:31 +010095 return dev->type == &usb_device_type;
Alan Stern8bb54ab2006-07-01 22:08:49 -040096}
97
98/* Do the same for device drivers and interface drivers. */
99
100static inline int is_usb_device_driver(struct device_driver *drv)
101{
102 return container_of(drv, struct usbdrv_wrap, driver)->
103 for_devices;
104}
David Brownell5edbfb72005-09-22 22:45:26 -0700105
David Brownelldb690872005-09-13 19:56:33 -0700106/* Interfaces and their "power state" are owned by usbcore */
107
108static inline void mark_active(struct usb_interface *f)
109{
Alan Stern4d064c02006-07-01 22:11:44 -0400110 f->is_active = 1;
Alan Stern784a6e12007-05-04 11:49:57 -0400111 f->dev.power.power_state.event = PM_EVENT_ON;
David Brownelldb690872005-09-13 19:56:33 -0700112}
113
114static inline void mark_quiesced(struct usb_interface *f)
115{
Alan Stern4d064c02006-07-01 22:11:44 -0400116 f->is_active = 0;
Alan Stern784a6e12007-05-04 11:49:57 -0400117 f->dev.power.power_state.event = PM_EVENT_SUSPEND;
David Brownelldb690872005-09-13 19:56:33 -0700118}
119
Luiz Fernando N. Capitulino095bc332006-08-26 23:48:11 -0300120static inline int is_active(const struct usb_interface *f)
David Brownelldb690872005-09-13 19:56:33 -0700121{
Alan Stern4d064c02006-07-01 22:11:44 -0400122 return f->is_active;
David Brownelldb690872005-09-13 19:56:33 -0700123}
124
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126/* for labeling diagnostics */
127extern const char *usbcore_name;
128
129/* usbfs stuff */
Alan Stern4a2a8a22006-07-01 22:05:01 -0400130extern struct mutex usbfs_mutex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131extern struct usb_driver usbfs_driver;
Luiz Fernando N. Capitulino066202d2006-08-05 20:37:11 -0300132extern const struct file_operations usbfs_devices_fops;
Kay Sievers9f8b17e2007-03-13 15:59:31 +0100133extern const struct file_operations usbdev_file_operations;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134extern void usbfs_conn_disc_event(void);
135
Kay Sievers9f8b17e2007-03-13 15:59:31 +0100136extern int usb_devio_init(void);
137extern void usb_devio_cleanup(void);
Greg KH6d5e8252005-04-18 17:39:24 -0700138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139struct dev_state {
140 struct list_head list; /* state list */
141 struct usb_device *dev;
142 struct file *file;
143 spinlock_t lock; /* protects the async urb lists */
144 struct list_head async_pending;
145 struct list_head async_completed;
146 wait_queue_head_t wait; /* wake up if a request completed */
147 unsigned int discsignr;
Eric W. Biederman2425c082006-10-02 02:17:28 -0700148 struct pid *disc_pid;
Linus Torvaldsd7dd8a72005-10-10 16:31:30 -0700149 uid_t disc_uid, disc_euid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 void __user *disccontext;
151 unsigned long ifclaimed;
David Quigley7a019552006-06-30 01:55:48 -0700152 u32 secid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153};
154
Greg Kroah-Hartman3099e752005-06-20 21:15:16 -0700155/* internal notify stuff */
156extern void usb_notify_add_device(struct usb_device *udev);
157extern void usb_notify_remove_device(struct usb_device *udev);
158extern void usb_notify_add_bus(struct usb_bus *ubus);
159extern void usb_notify_remove_bus(struct usb_bus *ubus);
160