4 * This file is part of Xen USB backend driver.
6 * Copyright (C) 2009, FUJITSU LABORATORIES LTD.
7 * Author: Noboru Iwamatsu <n_iwamatsu@jp.fujitsu.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <http://www.gnu.org/licenses/>.
24 * When distributed separately from the Linux kernel or incorporated into
25 * other software packages, subject to the following license:
27 * Permission is hereby granted, free of charge, to any person obtaining a copy
28 * of this software and associated documentation files (the "Software"), to
29 * deal in the Software without restriction, including without limitation the
30 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
31 * sell copies of the Software, and to permit persons to whom the Software is
32 * furnished to do so, subject to the following conditions:
34 * The above copyright notice and this permission notice shall be included in
35 * all copies or substantial portions of the Software.
37 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
38 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
39 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
40 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
41 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
42 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
43 * DEALINGS IN THE SOFTWARE.
46 #ifndef __XEN_USBBACK_H__
47 #define __XEN_USBBACK_H__
49 #include <linux/module.h>
50 #include <linux/interrupt.h>
51 #include <linux/slab.h>
52 #include <linux/usb.h>
53 #include <linux/kthread.h>
54 #include <linux/wait.h>
55 #include <linux/list.h>
56 #include <linux/kref.h>
57 #include <xen/xenbus.h>
58 #include <xen/interface/event_channel.h>
59 #include <xen/interface/io/usbif.h>
64 #define USBBACK_BUS_ID_SIZE 20
66 #define USBBACK_BUS_ID_SIZE BUS_ID_SIZE
69 #define USB_DEV_ADDR_SIZE 128
71 typedef struct usbif_st {
75 enum usb_spec_version usb_ver;
77 struct xenbus_device *xbdev;
78 struct list_head usbif_list;
82 usbif_urb_back_ring_t urb_ring;
83 usbif_conn_back_ring_t conn_ring;
84 struct vm_struct *urb_ring_area;
85 struct vm_struct *conn_ring_area;
87 spinlock_t urb_ring_lock;
88 spinlock_t conn_ring_lock;
91 struct xenbus_watch backend_watch;
93 /* device address lookup table */
94 struct usbstub *addr_table[USB_DEV_ADDR_SIZE];
97 /* connected device list */
98 struct list_head stub_list;
101 /* request schedule */
102 struct task_struct *xenusbd;
103 unsigned int waiting_reqs;
104 wait_queue_head_t waiting_to_free;
105 wait_queue_head_t wq;
108 struct vusb_port_id {
109 struct list_head id_list;
111 char phys_bus[USBBACK_BUS_ID_SIZE];
115 unsigned is_connected:1;
120 struct list_head dev_list;
122 struct vusb_port_id *portid;
123 struct usb_device *udev;
127 struct list_head submitting_list;
128 spinlock_t submitting_lock;
131 usbif_t *usbif_alloc(domid_t domid, unsigned int handle);
132 void usbif_disconnect(usbif_t *usbif);
133 void usbif_free(usbif_t *usbif);
134 int usbif_map(usbif_t *usbif, grant_ref_t urb_ring_ref,
135 grant_ref_t conn_ring_ref, evtchn_port_t);
137 #define usbif_get(_b) (atomic_inc(&(_b)->refcnt))
138 #define usbif_put(_b) \
140 if (atomic_dec_and_test(&(_b)->refcnt)) \
141 wake_up(&(_b)->waiting_to_free); \
144 usbif_t *find_usbif(domid_t domid, unsigned int handle);
145 int usbback_xenbus_init(void);
146 void usbback_xenbus_exit(void);
147 struct vusb_port_id *find_portid_by_busid(const char *busid);
148 struct vusb_port_id *find_portid(const domid_t domid,
149 const unsigned int handle,
151 int portid_add(const char *busid,
153 const unsigned int handle,
155 int portid_remove(const domid_t domid,
156 const unsigned int handle,
158 irqreturn_t usbbk_be_int(int irq, void *dev_id);
159 int usbbk_schedule(void *arg);
160 struct usbstub *find_attached_device(usbif_t *usbif, int port);
161 void usbbk_attach_device(usbif_t *usbif, struct usbstub *stub);
162 void usbbk_detach_device(usbif_t *usbif, struct usbstub *stub);
163 void usbbk_hotplug_notify(usbif_t *usbif, int portnum, int speed);
164 void detach_device_without_lock(usbif_t *usbif, struct usbstub *stub);
165 void usbbk_unlink_urbs(struct usbstub *stub);
167 int usbstub_init(void);
168 void usbstub_exit(void);
170 #endif /* __XEN_USBBACK_H__ */