27
27
#include "qemu-queue.h"
29
/* Constants related to the USB / PCI interaction */
30
#define USB_SBRN 0x60 /* Serial Bus Release Number Register */
31
#define USB_RELEASE_1 0x10 /* USB 1.0 */
32
#define USB_RELEASE_2 0x20 /* USB 2.0 */
33
#define USB_RELEASE_3 0x30 /* USB 3.0 */
35
29
#define USB_TOKEN_SETUP 0x2d
36
30
#define USB_TOKEN_IN 0x69 /* device -> host */
37
31
#define USB_TOKEN_OUT 0xe1 /* host -> device */
130
124
#define USB_DT_ENDPOINT 0x05
131
125
#define USB_DT_DEVICE_QUALIFIER 0x06
132
126
#define USB_DT_OTHER_SPEED_CONFIG 0x07
133
#define USB_DT_DEBUG 0x0A
134
#define USB_DT_INTERFACE_ASSOC 0x0B
136
128
#define USB_ENDPOINT_XFER_CONTROL 0
137
129
#define USB_ENDPOINT_XFER_ISOC 1
139
131
#define USB_ENDPOINT_XFER_INT 3
141
133
typedef struct USBBus USBBus;
142
typedef struct USBBusOps USBBusOps;
143
134
typedef struct USBPort USBPort;
144
135
typedef struct USBDevice USBDevice;
145
136
typedef struct USBDeviceInfo USBDeviceInfo;
149
140
typedef struct USBDescID USBDescID;
150
141
typedef struct USBDescDevice USBDescDevice;
151
142
typedef struct USBDescConfig USBDescConfig;
152
typedef struct USBDescIfaceAssoc USBDescIfaceAssoc;
153
143
typedef struct USBDescIface USBDescIface;
154
144
typedef struct USBDescEndpoint USBDescEndpoint;
155
145
typedef struct USBDescOther USBDescOther;
205
192
int (*handle_packet)(USBDevice *dev, USBPacket *p);
208
* Called when a packet is canceled.
210
void (*cancel_packet)(USBDevice *dev, USBPacket *p);
213
195
* Called when device is destroyed.
215
197
void (*handle_destroy)(USBDevice *dev);
231
213
* Returns length or one of the USB_RET_ codes.
233
int (*handle_control)(USBDevice *dev, USBPacket *p, int request, int value,
215
int (*handle_control)(USBDevice *dev, int request, int value,
234
216
int index, int length, uint8_t *data);
252
234
typedef struct USBPortOps {
253
235
void (*attach)(USBPort *port);
254
236
void (*detach)(USBPort *port);
256
* This gets called when a device downstream from the device attached to
257
* the port (iow attached through a hub) gets detached.
259
void (*child_detach)(USBPort *port, USBDevice *child);
260
void (*wakeup)(USBPort *port);
262
* Note that port->dev will be different then the device from which
263
* the packet originated when a hub is involved, if you want the orginating
264
* device use p->owner
266
void (*complete)(USBPort *port, USBPacket *p);
237
void (*wakeup)(USBDevice *dev);
269
240
/* USB port on which a device can be connected */
289
int result; /* transfer length or USB_RET_* status code */
290
261
/* Internal use by the USB layer. */
262
USBCallback *complete_cb;
263
void *complete_opaque;
264
USBCallback *cancel_cb;
294
void usb_packet_init(USBPacket *p);
295
void usb_packet_setup(USBPacket *p, int pid, uint8_t addr, uint8_t ep);
296
void usb_packet_addbuf(USBPacket *p, void *ptr, size_t len);
297
int usb_packet_map(USBPacket *p, QEMUSGList *sgl);
298
void usb_packet_unmap(USBPacket *p);
299
void usb_packet_copy(USBPacket *p, void *ptr, size_t bytes);
300
void usb_packet_skip(USBPacket *p, size_t bytes);
301
void usb_packet_cleanup(USBPacket *p);
303
int usb_handle_packet(USBDevice *dev, USBPacket *p);
304
void usb_packet_complete(USBDevice *dev, USBPacket *p);
305
void usb_cancel_packet(USBPacket * p);
268
/* Defer completion of a USB packet. The hadle_packet routine should then
269
return USB_RET_ASYNC. Packets that complete immediately (before
270
handle_packet returns) should not call this method. */
271
static inline void usb_defer_packet(USBPacket *p, USBCallback *cancel,
274
p->cancel_cb = cancel;
275
p->cancel_opaque = opaque;
278
/* Notify the controller that an async packet is complete. This should only
279
be called for packets previously deferred with usb_defer_packet, and
280
should never be called from within handle_packet. */
281
static inline void usb_packet_complete(USBPacket *p)
283
p->complete_cb(p, p->complete_opaque);
286
/* Cancel an active packet. The packed must have been deferred with
287
usb_defer_packet, and not yet completed. */
288
static inline void usb_cancel_packet(USBPacket * p)
290
p->cancel_cb(p, p->cancel_opaque);
307
293
void usb_attach(USBPort *port, USBDevice *dev);
308
294
void usb_wakeup(USBDevice *dev);
309
295
int usb_generic_handle_packet(USBDevice *s, USBPacket *p);
310
void usb_generic_async_ctrl_complete(USBDevice *s, USBPacket *p);
311
296
int set_usb_string(uint8_t *buf, const char *str);
312
297
void usb_send_msg(USBDevice *dev, int msg);
363
347
QTAILQ_ENTRY(USBBus) next;
367
int (*register_companion)(USBBus *bus, USBPort *ports[],
368
uint32_t portcount, uint32_t firstport);
371
void usb_bus_new(USBBus *bus, USBBusOps *ops, DeviceState *host);
350
void usb_bus_new(USBBus *bus, DeviceState *host);
372
351
USBBus *usb_bus_find(int busnr);
373
352
void usb_qdev_register(USBDeviceInfo *info);
374
353
void usb_qdev_register_many(USBDeviceInfo *info);
377
356
USBDevice *usbdevice_create(const char *cmdline);
378
357
void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
379
358
USBPortOps *ops, int speedmask);
380
int usb_register_companion(const char *masterbus, USBPort *ports[],
381
uint32_t portcount, uint32_t firstport,
382
void *opaque, USBPortOps *ops, int speedmask);
383
359
void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr);
384
360
void usb_unregister_port(USBBus *bus, USBPort *port);
385
361
int usb_device_attach(USBDevice *dev);