00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "block.h"
00026
00027 #define USB_TOKEN_SETUP 0x2d
00028 #define USB_TOKEN_IN 0x69
00029 #define USB_TOKEN_OUT 0xe1
00030
00031
00032 #define USB_MSG_ATTACH 0x100
00033 #define USB_MSG_DETACH 0x101
00034 #define USB_MSG_RESET 0x102
00035
00036 #define USB_RET_NODEV (-1)
00037 #define USB_RET_NAK (-2)
00038 #define USB_RET_STALL (-3)
00039 #define USB_RET_BABBLE (-4)
00040 #define USB_RET_ASYNC (-5)
00041
00042 #define USB_SPEED_LOW 0
00043 #define USB_SPEED_FULL 1
00044 #define USB_SPEED_HIGH 2
00045
00046 #define USB_STATE_NOTATTACHED 0
00047 #define USB_STATE_ATTACHED 1
00048
00049 #define USB_STATE_DEFAULT 3
00050
00051
00052 #define USB_STATE_SUSPENDED 6
00053
00054 #define USB_CLASS_AUDIO 1
00055 #define USB_CLASS_COMM 2
00056 #define USB_CLASS_HID 3
00057 #define USB_CLASS_PHYSICAL 5
00058 #define USB_CLASS_STILL_IMAGE 6
00059 #define USB_CLASS_PRINTER 7
00060 #define USB_CLASS_MASS_STORAGE 8
00061 #define USB_CLASS_HUB 9
00062 #define USB_CLASS_CDC_DATA 0x0a
00063 #define USB_CLASS_CSCID 0x0b
00064 #define USB_CLASS_CONTENT_SEC 0x0d
00065 #define USB_CLASS_APP_SPEC 0xfe
00066 #define USB_CLASS_VENDOR_SPEC 0xff
00067
00068 #define USB_DIR_OUT 0
00069 #define USB_DIR_IN 0x80
00070
00071 #define USB_TYPE_MASK (0x03 << 5)
00072 #define USB_TYPE_STANDARD (0x00 << 5)
00073 #define USB_TYPE_CLASS (0x01 << 5)
00074 #define USB_TYPE_VENDOR (0x02 << 5)
00075 #define USB_TYPE_RESERVED (0x03 << 5)
00076
00077 #define USB_RECIP_MASK 0x1f
00078 #define USB_RECIP_DEVICE 0x00
00079 #define USB_RECIP_INTERFACE 0x01
00080 #define USB_RECIP_ENDPOINT 0x02
00081 #define USB_RECIP_OTHER 0x03
00082
00083 #define DeviceRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
00084 #define DeviceOutRequest ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_DEVICE)<<8)
00085 #define InterfaceRequest \
00086 ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
00087 #define InterfaceOutRequest \
00088 ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_INTERFACE)<<8)
00089 #define EndpointRequest ((USB_DIR_IN|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
00090 #define EndpointOutRequest \
00091 ((USB_DIR_OUT|USB_TYPE_STANDARD|USB_RECIP_ENDPOINT)<<8)
00092
00093 #define USB_REQ_GET_STATUS 0x00
00094 #define USB_REQ_CLEAR_FEATURE 0x01
00095 #define USB_REQ_SET_FEATURE 0x03
00096 #define USB_REQ_SET_ADDRESS 0x05
00097 #define USB_REQ_GET_DESCRIPTOR 0x06
00098 #define USB_REQ_SET_DESCRIPTOR 0x07
00099 #define USB_REQ_GET_CONFIGURATION 0x08
00100 #define USB_REQ_SET_CONFIGURATION 0x09
00101 #define USB_REQ_GET_INTERFACE 0x0A
00102 #define USB_REQ_SET_INTERFACE 0x0B
00103 #define USB_REQ_SYNCH_FRAME 0x0C
00104
00105 #define USB_DEVICE_SELF_POWERED 0
00106 #define USB_DEVICE_REMOTE_WAKEUP 1
00107
00108 #define USB_DT_DEVICE 0x01
00109 #define USB_DT_CONFIG 0x02
00110 #define USB_DT_STRING 0x03
00111 #define USB_DT_INTERFACE 0x04
00112 #define USB_DT_ENDPOINT 0x05
00113
00114 #define USB_ENDPOINT_XFER_CONTROL 0
00115 #define USB_ENDPOINT_XFER_ISOC 1
00116 #define USB_ENDPOINT_XFER_BULK 2
00117 #define USB_ENDPOINT_XFER_INT 3
00118
00119 typedef struct USBPort USBPort;
00120 typedef struct USBDevice USBDevice;
00121 typedef struct USBPacket USBPacket;
00122
00123
00124 struct USBDevice {
00125 void *opaque;
00126
00127
00128
00129
00130
00131
00132
00133
00134 int (*handle_packet)(USBDevice *dev, USBPacket *p);
00135
00136
00137
00138
00139 void (*handle_destroy)(USBDevice *dev);
00140
00141 int speed;
00142
00143
00144
00145
00146
00147
00148
00149
00150 void (*handle_reset)(USBDevice *dev);
00151
00152
00153
00154
00155
00156
00157
00158 int (*handle_control)(USBDevice *dev, int request, int value,
00159 int index, int length, uint8_t *data);
00160
00161
00162
00163
00164
00165
00166
00167 int (*handle_data)(USBDevice *dev, USBPacket *p);
00168
00169 uint8_t addr;
00170 char devname[32];
00171
00172 int state;
00173 uint8_t setup_buf[8];
00174 uint8_t data_buf[1024];
00175 int remote_wakeup;
00176 int setup_state;
00177 int setup_len;
00178 int setup_index;
00179 };
00180
00181 typedef void (*usb_attachfn)(USBPort *port, USBDevice *dev);
00182
00183
00184 struct USBPort {
00185 USBDevice *dev;
00186 usb_attachfn attach;
00187 void *opaque;
00188 int index;
00189 struct USBPort *next;
00190 };
00191
00192 typedef void USBCallback(USBPacket * packet, void *opaque);
00193
00194
00195 struct USBPacket {
00196
00197 int pid;
00198 uint8_t devaddr;
00199 uint8_t devep;
00200 uint8_t *data;
00201 int len;
00202
00203 USBCallback *complete_cb;
00204 void *complete_opaque;
00205 USBCallback *cancel_cb;
00206 void *cancel_opaque;
00207 };
00208
00209
00210
00211
00212 static inline void usb_defer_packet(USBPacket *p, USBCallback *cancel,
00213 void * opaque)
00214 {
00215 p->cancel_cb = cancel;
00216 p->cancel_opaque = opaque;
00217 }
00218
00219
00220
00221
00222 static inline void usb_packet_complete(USBPacket *p)
00223 {
00224 p->complete_cb(p, p->complete_opaque);
00225 }
00226
00227
00228
00229 static inline void usb_cancel_packet(USBPacket * p)
00230 {
00231 p->cancel_cb(p, p->cancel_opaque);
00232 }
00233
00234 int usb_device_add_dev(USBDevice *dev);
00235 int usb_device_del_addr(int bus_num, int addr);
00236 void usb_attach(USBPort *port, USBDevice *dev);
00237 int usb_generic_handle_packet(USBDevice *s, USBPacket *p);
00238 int set_usb_string(uint8_t *buf, const char *str);
00239 void usb_send_msg(USBDevice *dev, int msg);
00240
00241
00242 USBDevice *usb_hub_init(int nb_ports);
00243
00244
00245 USBDevice *usb_host_device_open(const char *devname);
00246 int usb_host_device_close(const char *devname);
00247 void usb_host_info(void);
00248
00249
00250 USBDevice *usb_mouse_init(void);
00251 USBDevice *usb_tablet_init(void);
00252 USBDevice *usb_keyboard_init(void);
00253 void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *));
00254
00255
00256 USBDevice *usb_msd_init(const char *filename, BlockDriverState **pbs);
00257
00258
00259 USBDevice *usb_net_init(NICInfo *nd);
00260
00261
00262 USBDevice *usb_bt_init(HCIInfo *hci);
00263
00264
00265 USBDevice *usb_wacom_init(void);
00266
00267
00268 USBDevice *usb_serial_init(const char *filename);
00269
00270
00271
00272 void qemu_register_usb_port(USBPort *port, void *opaque, int index,
00273 usb_attachfn attach);
00274
00275 #define VM_USB_HUB_SIZE 8
00276
00277
00278 enum musb_irq_source_e {
00279 musb_irq_suspend = 0,
00280 musb_irq_resume,
00281 musb_irq_rst_babble,
00282 musb_irq_sof,
00283 musb_irq_connect,
00284 musb_irq_disconnect,
00285 musb_irq_vbus_request,
00286 musb_irq_vbus_error,
00287 musb_irq_rx,
00288 musb_irq_tx,
00289 musb_set_vbus,
00290 musb_set_session,
00291 __musb_irq_max,
00292 };
00293
00294 struct musb_s;
00295 struct musb_s *musb_init(qemu_irq *irqs);
00296 uint32_t musb_core_intr_get(struct musb_s *s);
00297 void musb_core_intr_clear(struct musb_s *s, uint32_t mask);
00298 void musb_set_size(struct musb_s *s, int epnum, int size, int is_tx);