~ubuntu-branches/ubuntu/oneiric/qemu-linaro/oneiric

« back to all changes in this revision

Viewing changes to hw/usb.h

  • Committer: Package Import Robot
  • Author(s): Steve Langasek
  • Date: 2011-04-11 22:26:38 UTC
  • mfrom: (12860.1.6 natty)
  • Revision ID: package-import@ubuntu.com-20110411222638-1zk3pjkmd9zcj0d2
debian/rules: include i386 and x86_64 in the list of possible
binfmt-misc targets, since qemu-user-static does include
qemu-i386-static and qemu-x86_64-static and we want these to work on
non-x86 archs by default.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#include "qdev.h"
27
27
#include "qemu-queue.h"
28
28
 
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 */
34
 
 
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
135
127
 
136
128
#define USB_ENDPOINT_XFER_CONTROL       0
137
129
#define USB_ENDPOINT_XFER_ISOC          1
139
131
#define USB_ENDPOINT_XFER_INT           3
140
132
 
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;
169
159
    char *port_path;
170
160
    void *opaque;
171
161
 
172
 
    /* Actual connected speed */
173
162
    int speed;
174
 
    /* Supported speeds, not in info because it may be variable (hostdevs) */
175
 
    int speedmask;
176
163
    uint8_t addr;
177
164
    char product_desc[32];
178
165
    int auto_attach;
180
167
 
181
168
    int32_t state;
182
169
    uint8_t setup_buf[8];
183
 
    uint8_t data_buf[4096];
 
170
    uint8_t data_buf[1024];
184
171
    int32_t remote_wakeup;
185
172
    int32_t setup_state;
186
173
    int32_t setup_len;
205
192
    int (*handle_packet)(USBDevice *dev, USBPacket *p);
206
193
 
207
194
    /*
208
 
     * Called when a packet is canceled.
209
 
     */
210
 
    void (*cancel_packet)(USBDevice *dev, USBPacket *p);
211
 
 
212
 
    /*
213
195
     * Called when device is destroyed.
214
196
     */
215
197
    void (*handle_destroy)(USBDevice *dev);
230
212
     *
231
213
     * Returns length or one of the USB_RET_ codes.
232
214
     */
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);
235
217
 
236
218
    /*
252
234
typedef struct USBPortOps {
253
235
    void (*attach)(USBPort *port);
254
236
    void (*detach)(USBPort *port);
255
 
    /*
256
 
     * This gets called when a device downstream from the device attached to
257
 
     * the port (iow attached through a hub) gets detached.
258
 
     */
259
 
    void (*child_detach)(USBPort *port, USBDevice *child);
260
 
    void (*wakeup)(USBPort *port);
261
 
    /*
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
265
 
     */
266
 
    void (*complete)(USBPort *port, USBPacket *p);
 
237
    void (*wakeup)(USBDevice *dev);
267
238
} USBPortOps;
268
239
 
269
240
/* USB port on which a device can be connected */
285
256
    int pid;
286
257
    uint8_t devaddr;
287
258
    uint8_t devep;
288
 
    QEMUIOVector iov;
289
 
    int result; /* transfer length or USB_RET_* status code */
 
259
    uint8_t *data;
 
260
    int len;
290
261
    /* Internal use by the USB layer.  */
291
 
    USBDevice *owner;
 
262
    USBCallback *complete_cb;
 
263
    void *complete_opaque;
 
264
    USBCallback *cancel_cb;
 
265
    void *cancel_opaque;
292
266
};
293
267
 
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);
302
 
 
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,
 
272
                                    void * opaque)
 
273
{
 
274
    p->cancel_cb = cancel;
 
275
    p->cancel_opaque = opaque;
 
276
}
 
277
 
 
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)
 
282
{
 
283
    p->complete_cb(p, p->complete_opaque);
 
284
}
 
285
 
 
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)
 
289
{
 
290
    p->cancel_cb(p, p->cancel_opaque);
 
291
}
306
292
 
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);
313
298
 
354
339
 
355
340
struct USBBus {
356
341
    BusState qbus;
357
 
    USBBusOps *ops;
358
342
    int busnr;
359
343
    int nfree;
360
344
    int nused;
363
347
    QTAILQ_ENTRY(USBBus) next;
364
348
};
365
349
 
366
 
struct USBBusOps {
367
 
    int (*register_companion)(USBBus *bus, USBPort *ports[],
368
 
                              uint32_t portcount, uint32_t firstport);
369
 
};
370
 
 
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);