Commit 059809e45160fda714edf645902db95e262886e9
1 parent
3b2ccc57
usb destroy API change (Lonnie Mendez)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2066 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
7 changed files
with
48 additions
and
31 deletions
hw/usb-hid.c
@@ -323,16 +323,10 @@ static int usb_tablet_poll(USBMouseState *s, uint8_t *buf, int len) | @@ -323,16 +323,10 @@ static int usb_tablet_poll(USBMouseState *s, uint8_t *buf, int len) | ||
323 | return l; | 323 | return l; |
324 | } | 324 | } |
325 | 325 | ||
326 | -static void usb_mouse_handle_reset(USBDevice *dev, int destroy) | 326 | +static void usb_mouse_handle_reset(USBDevice *dev) |
327 | { | 327 | { |
328 | USBMouseState *s = (USBMouseState *)dev; | 328 | USBMouseState *s = (USBMouseState *)dev; |
329 | 329 | ||
330 | - if (destroy) { | ||
331 | - qemu_add_mouse_event_handler(NULL, NULL, 0); | ||
332 | - qemu_free(s); | ||
333 | - return; | ||
334 | - } | ||
335 | - | ||
336 | s->dx = 0; | 330 | s->dx = 0; |
337 | s->dy = 0; | 331 | s->dy = 0; |
338 | s->dz = 0; | 332 | s->dz = 0; |
@@ -506,6 +500,14 @@ static int usb_mouse_handle_data(USBDevice *dev, int pid, | @@ -506,6 +500,14 @@ static int usb_mouse_handle_data(USBDevice *dev, int pid, | ||
506 | return ret; | 500 | return ret; |
507 | } | 501 | } |
508 | 502 | ||
503 | +static void usb_mouse_handle_destroy(USBDevice *dev) | ||
504 | +{ | ||
505 | + USBMouseState *s = (USBMouseState *)dev; | ||
506 | + | ||
507 | + qemu_add_mouse_event_handler(NULL, NULL, 0); | ||
508 | + qemu_free(s); | ||
509 | +} | ||
510 | + | ||
509 | USBDevice *usb_tablet_init(void) | 511 | USBDevice *usb_tablet_init(void) |
510 | { | 512 | { |
511 | USBMouseState *s; | 513 | USBMouseState *s; |
@@ -519,6 +521,7 @@ USBDevice *usb_tablet_init(void) | @@ -519,6 +521,7 @@ USBDevice *usb_tablet_init(void) | ||
519 | s->dev.handle_reset = usb_mouse_handle_reset; | 521 | s->dev.handle_reset = usb_mouse_handle_reset; |
520 | s->dev.handle_control = usb_mouse_handle_control; | 522 | s->dev.handle_control = usb_mouse_handle_control; |
521 | s->dev.handle_data = usb_mouse_handle_data; | 523 | s->dev.handle_data = usb_mouse_handle_data; |
524 | + s->dev.handle_destroy = usb_mouse_handle_destroy; | ||
522 | s->kind = USB_TABLET; | 525 | s->kind = USB_TABLET; |
523 | 526 | ||
524 | pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Tablet"); | 527 | pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Tablet"); |
@@ -539,6 +542,7 @@ USBDevice *usb_mouse_init(void) | @@ -539,6 +542,7 @@ USBDevice *usb_mouse_init(void) | ||
539 | s->dev.handle_reset = usb_mouse_handle_reset; | 542 | s->dev.handle_reset = usb_mouse_handle_reset; |
540 | s->dev.handle_control = usb_mouse_handle_control; | 543 | s->dev.handle_control = usb_mouse_handle_control; |
541 | s->dev.handle_data = usb_mouse_handle_data; | 544 | s->dev.handle_data = usb_mouse_handle_data; |
545 | + s->dev.handle_destroy = usb_mouse_handle_destroy; | ||
542 | s->kind = USB_MOUSE; | 546 | s->kind = USB_MOUSE; |
543 | 547 | ||
544 | pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Mouse"); | 548 | pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Mouse"); |
hw/usb-hub.c
@@ -199,11 +199,9 @@ static void usb_hub_attach(USBPort *port1, USBDevice *dev) | @@ -199,11 +199,9 @@ static void usb_hub_attach(USBPort *port1, USBDevice *dev) | ||
199 | } | 199 | } |
200 | } | 200 | } |
201 | 201 | ||
202 | -static void usb_hub_handle_reset(USBDevice *dev, int destroy) | 202 | +static void usb_hub_handle_reset(USBDevice *dev) |
203 | { | 203 | { |
204 | /* XXX: do it */ | 204 | /* XXX: do it */ |
205 | - if (destroy) | ||
206 | - qemu_free(dev); | ||
207 | } | 205 | } |
208 | 206 | ||
209 | static int usb_hub_handle_control(USBDevice *dev, int request, int value, | 207 | static int usb_hub_handle_control(USBDevice *dev, int request, int value, |
@@ -525,6 +523,13 @@ static int usb_hub_handle_packet(USBDevice *dev, int pid, | @@ -525,6 +523,13 @@ static int usb_hub_handle_packet(USBDevice *dev, int pid, | ||
525 | return usb_generic_handle_packet(dev, pid, devaddr, devep, data, len); | 523 | return usb_generic_handle_packet(dev, pid, devaddr, devep, data, len); |
526 | } | 524 | } |
527 | 525 | ||
526 | +static void usb_hub_handle_destroy(USBDevice *dev) | ||
527 | +{ | ||
528 | + USBHubState *s = (USBHubState *)dev; | ||
529 | + | ||
530 | + qemu_free(s); | ||
531 | +} | ||
532 | + | ||
528 | USBDevice *usb_hub_init(int nb_ports) | 533 | USBDevice *usb_hub_init(int nb_ports) |
529 | { | 534 | { |
530 | USBHubState *s; | 535 | USBHubState *s; |
@@ -543,6 +548,7 @@ USBDevice *usb_hub_init(int nb_ports) | @@ -543,6 +548,7 @@ USBDevice *usb_hub_init(int nb_ports) | ||
543 | s->dev.handle_reset = usb_hub_handle_reset; | 548 | s->dev.handle_reset = usb_hub_handle_reset; |
544 | s->dev.handle_control = usb_hub_handle_control; | 549 | s->dev.handle_control = usb_hub_handle_control; |
545 | s->dev.handle_data = usb_hub_handle_data; | 550 | s->dev.handle_data = usb_hub_handle_data; |
551 | + s->dev.handle_destroy = usb_hub_handle_destroy; | ||
546 | 552 | ||
547 | pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Hub"); | 553 | pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Hub"); |
548 | 554 |
hw/usb-msd.c
@@ -112,16 +112,12 @@ static void usb_msd_command_complete(void *opaque, uint32_t tag, int fail) | @@ -112,16 +112,12 @@ static void usb_msd_command_complete(void *opaque, uint32_t tag, int fail) | ||
112 | s->mode = USB_MSDM_CSW; | 112 | s->mode = USB_MSDM_CSW; |
113 | } | 113 | } |
114 | 114 | ||
115 | -static void usb_msd_handle_reset(USBDevice *dev, int destroy) | 115 | +static void usb_msd_handle_reset(USBDevice *dev) |
116 | { | 116 | { |
117 | MSDState *s = (MSDState *)dev; | 117 | MSDState *s = (MSDState *)dev; |
118 | 118 | ||
119 | DPRINTF("Reset\n"); | 119 | DPRINTF("Reset\n"); |
120 | s->mode = USB_MSDM_CBW; | 120 | s->mode = USB_MSDM_CBW; |
121 | - if (destroy) { | ||
122 | - scsi_disk_destroy(s->scsi_dev); | ||
123 | - qemu_free(s); | ||
124 | - } | ||
125 | } | 121 | } |
126 | 122 | ||
127 | static int usb_msd_handle_control(USBDevice *dev, int request, int value, | 123 | static int usb_msd_handle_control(USBDevice *dev, int request, int value, |
@@ -369,6 +365,13 @@ static int usb_msd_handle_data(USBDevice *dev, int pid, uint8_t devep, | @@ -369,6 +365,13 @@ static int usb_msd_handle_data(USBDevice *dev, int pid, uint8_t devep, | ||
369 | return ret; | 365 | return ret; |
370 | } | 366 | } |
371 | 367 | ||
368 | +static void usb_msd_handle_destroy(USBDevice *dev) | ||
369 | +{ | ||
370 | + MSDState *s = (MSDState *)dev; | ||
371 | + | ||
372 | + scsi_disk_destroy(s->scsi_dev); | ||
373 | + qemu_free(s); | ||
374 | +} | ||
372 | 375 | ||
373 | USBDevice *usb_msd_init(const char *filename) | 376 | USBDevice *usb_msd_init(const char *filename) |
374 | { | 377 | { |
@@ -388,11 +391,12 @@ USBDevice *usb_msd_init(const char *filename) | @@ -388,11 +391,12 @@ USBDevice *usb_msd_init(const char *filename) | ||
388 | s->dev.handle_reset = usb_msd_handle_reset; | 391 | s->dev.handle_reset = usb_msd_handle_reset; |
389 | s->dev.handle_control = usb_msd_handle_control; | 392 | s->dev.handle_control = usb_msd_handle_control; |
390 | s->dev.handle_data = usb_msd_handle_data; | 393 | s->dev.handle_data = usb_msd_handle_data; |
394 | + s->dev.handle_destroy = usb_msd_handle_destroy; | ||
391 | 395 | ||
392 | snprintf(s->dev.devname, sizeof(s->dev.devname), "QEMU USB MSD(%.16s)", | 396 | snprintf(s->dev.devname, sizeof(s->dev.devname), "QEMU USB MSD(%.16s)", |
393 | filename); | 397 | filename); |
394 | 398 | ||
395 | s->scsi_dev = scsi_disk_init(bdrv, usb_msd_command_complete, s); | 399 | s->scsi_dev = scsi_disk_init(bdrv, usb_msd_command_complete, s); |
396 | - usb_msd_handle_reset((USBDevice *)s, 0); | 400 | + usb_msd_handle_reset((USBDevice *)s); |
397 | return (USBDevice *)s; | 401 | return (USBDevice *)s; |
398 | } | 402 | } |
hw/usb.c
@@ -55,10 +55,7 @@ int usb_generic_handle_packet(USBDevice *s, int pid, | @@ -55,10 +55,7 @@ int usb_generic_handle_packet(USBDevice *s, int pid, | ||
55 | s->remote_wakeup = 0; | 55 | s->remote_wakeup = 0; |
56 | s->addr = 0; | 56 | s->addr = 0; |
57 | s->state = USB_STATE_DEFAULT; | 57 | s->state = USB_STATE_DEFAULT; |
58 | - s->handle_reset(s, 0); | ||
59 | - break; | ||
60 | - case USB_MSG_DESTROY: | ||
61 | - s->handle_reset(s, 1); | 58 | + s->handle_reset(s); |
62 | break; | 59 | break; |
63 | case USB_TOKEN_SETUP: | 60 | case USB_TOKEN_SETUP: |
64 | if (s->state < USB_STATE_DEFAULT || devaddr != s->addr) | 61 | if (s->state < USB_STATE_DEFAULT || devaddr != s->addr) |
hw/usb.h
@@ -29,7 +29,6 @@ | @@ -29,7 +29,6 @@ | ||
29 | #define USB_MSG_ATTACH 0x100 | 29 | #define USB_MSG_ATTACH 0x100 |
30 | #define USB_MSG_DETACH 0x101 | 30 | #define USB_MSG_DETACH 0x101 |
31 | #define USB_MSG_RESET 0x102 | 31 | #define USB_MSG_RESET 0x102 |
32 | -#define USB_MSG_DESTROY 0x103 | ||
33 | 32 | ||
34 | #define USB_RET_NODEV (-1) | 33 | #define USB_RET_NODEV (-1) |
35 | #define USB_RET_NAK (-2) | 34 | #define USB_RET_NAK (-2) |
@@ -117,12 +116,14 @@ struct USBDevice { | @@ -117,12 +116,14 @@ struct USBDevice { | ||
117 | int (*handle_packet)(USBDevice *dev, int pid, | 116 | int (*handle_packet)(USBDevice *dev, int pid, |
118 | uint8_t devaddr, uint8_t devep, | 117 | uint8_t devaddr, uint8_t devep, |
119 | uint8_t *data, int len); | 118 | uint8_t *data, int len); |
119 | + void (*handle_destroy)(USBDevice *dev); | ||
120 | + | ||
120 | int speed; | 121 | int speed; |
121 | 122 | ||
122 | /* The following fields are used by the generic USB device | 123 | /* The following fields are used by the generic USB device |
123 | layer. They are here just to avoid creating a new structure for | 124 | layer. They are here just to avoid creating a new structure for |
124 | them. */ | 125 | them. */ |
125 | - void (*handle_reset)(USBDevice *dev, int destroy); | 126 | + void (*handle_reset)(USBDevice *dev); |
126 | int (*handle_control)(USBDevice *dev, int request, int value, | 127 | int (*handle_control)(USBDevice *dev, int request, int value, |
127 | int index, int length, uint8_t *data); | 128 | int index, int length, uint8_t *data); |
128 | int (*handle_data)(USBDevice *dev, int pid, uint8_t devep, | 129 | int (*handle_data)(USBDevice *dev, int pid, uint8_t devep, |
usb-linux.c
@@ -58,16 +58,8 @@ typedef struct USBHostDevice { | @@ -58,16 +58,8 @@ typedef struct USBHostDevice { | ||
58 | int fd; | 58 | int fd; |
59 | } USBHostDevice; | 59 | } USBHostDevice; |
60 | 60 | ||
61 | -static void usb_host_handle_reset(USBDevice *dev, int destroy) | 61 | +static void usb_host_handle_reset(USBDevice *dev) |
62 | { | 62 | { |
63 | - USBHostDevice *s = (USBHostDevice *)dev; | ||
64 | - | ||
65 | - if (destroy) { | ||
66 | - if (s->fd >= 0) | ||
67 | - close(s->fd); | ||
68 | - qemu_free(s); | ||
69 | - return; | ||
70 | - } | ||
71 | #if 0 | 63 | #if 0 |
72 | USBHostDevice *s = (USBHostDevice *)dev; | 64 | USBHostDevice *s = (USBHostDevice *)dev; |
73 | /* USBDEVFS_RESET, but not the first time as it has already be | 65 | /* USBDEVFS_RESET, but not the first time as it has already be |
@@ -76,6 +68,15 @@ static void usb_host_handle_reset(USBDevice *dev, int destroy) | @@ -76,6 +68,15 @@ static void usb_host_handle_reset(USBDevice *dev, int destroy) | ||
76 | #endif | 68 | #endif |
77 | } | 69 | } |
78 | 70 | ||
71 | +static void usb_host_handle_destroy(USBDevice *dev) | ||
72 | +{ | ||
73 | + USBHostDevice *s = (USBHostDevice *)dev; | ||
74 | + | ||
75 | + if (s->fd >= 0) | ||
76 | + close(s->fd); | ||
77 | + qemu_free(s); | ||
78 | +} | ||
79 | + | ||
79 | static int usb_host_handle_control(USBDevice *dev, | 80 | static int usb_host_handle_control(USBDevice *dev, |
80 | int request, | 81 | int request, |
81 | int value, | 82 | int value, |
@@ -244,6 +245,7 @@ USBDevice *usb_host_device_open(const char *devname) | @@ -244,6 +245,7 @@ USBDevice *usb_host_device_open(const char *devname) | ||
244 | dev->dev.handle_reset = usb_host_handle_reset; | 245 | dev->dev.handle_reset = usb_host_handle_reset; |
245 | dev->dev.handle_control = usb_host_handle_control; | 246 | dev->dev.handle_control = usb_host_handle_control; |
246 | dev->dev.handle_data = usb_host_handle_data; | 247 | dev->dev.handle_data = usb_host_handle_data; |
248 | + dev->dev.handle_destroy = usb_host_handle_destroy; | ||
247 | 249 | ||
248 | if (product_name[0] == '\0') | 250 | if (product_name[0] == '\0') |
249 | snprintf(dev->dev.devname, sizeof(dev->dev.devname), | 251 | snprintf(dev->dev.devname, sizeof(dev->dev.devname), |
vl.c
@@ -3781,6 +3781,7 @@ static int usb_device_del(const char *devname) | @@ -3781,6 +3781,7 @@ static int usb_device_del(const char *devname) | ||
3781 | { | 3781 | { |
3782 | USBPort *port; | 3782 | USBPort *port; |
3783 | USBPort **lastp; | 3783 | USBPort **lastp; |
3784 | + USBDevice *dev; | ||
3784 | int bus_num, addr; | 3785 | int bus_num, addr; |
3785 | const char *p; | 3786 | const char *p; |
3786 | 3787 | ||
@@ -3805,8 +3806,10 @@ static int usb_device_del(const char *devname) | @@ -3805,8 +3806,10 @@ static int usb_device_del(const char *devname) | ||
3805 | if (!port) | 3806 | if (!port) |
3806 | return -1; | 3807 | return -1; |
3807 | 3808 | ||
3809 | + dev = port->dev; | ||
3808 | *lastp = port->next; | 3810 | *lastp = port->next; |
3809 | usb_attach(port, NULL); | 3811 | usb_attach(port, NULL); |
3812 | + dev->handle_destroy(dev); | ||
3810 | port->next = free_usb_ports; | 3813 | port->next = free_usb_ports; |
3811 | free_usb_ports = port; | 3814 | free_usb_ports = port; |
3812 | return 0; | 3815 | return 0; |