Commit 059809e45160fda714edf645902db95e262886e9

Authored by bellard
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
hw/usb-hid.c
... ... @@ -323,16 +323,10 @@ static int usb_tablet_poll(USBMouseState *s, uint8_t *buf, int len)
323 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 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 330 s->dx = 0;
337 331 s->dy = 0;
338 332 s->dz = 0;
... ... @@ -506,6 +500,14 @@ static int usb_mouse_handle_data(USBDevice *dev, int pid,
506 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 511 USBDevice *usb_tablet_init(void)
510 512 {
511 513 USBMouseState *s;
... ... @@ -519,6 +521,7 @@ USBDevice *usb_tablet_init(void)
519 521 s->dev.handle_reset = usb_mouse_handle_reset;
520 522 s->dev.handle_control = usb_mouse_handle_control;
521 523 s->dev.handle_data = usb_mouse_handle_data;
  524 + s->dev.handle_destroy = usb_mouse_handle_destroy;
522 525 s->kind = USB_TABLET;
523 526  
524 527 pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Tablet");
... ... @@ -539,6 +542,7 @@ USBDevice *usb_mouse_init(void)
539 542 s->dev.handle_reset = usb_mouse_handle_reset;
540 543 s->dev.handle_control = usb_mouse_handle_control;
541 544 s->dev.handle_data = usb_mouse_handle_data;
  545 + s->dev.handle_destroy = usb_mouse_handle_destroy;
542 546 s->kind = USB_MOUSE;
543 547  
544 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 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 204 /* XXX: do it */
205   - if (destroy)
206   - qemu_free(dev);
207 205 }
208 206  
209 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 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 533 USBDevice *usb_hub_init(int nb_ports)
529 534 {
530 535 USBHubState *s;
... ... @@ -543,6 +548,7 @@ USBDevice *usb_hub_init(int nb_ports)
543 548 s->dev.handle_reset = usb_hub_handle_reset;
544 549 s->dev.handle_control = usb_hub_handle_control;
545 550 s->dev.handle_data = usb_hub_handle_data;
  551 + s->dev.handle_destroy = usb_hub_handle_destroy;
546 552  
547 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 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 117 MSDState *s = (MSDState *)dev;
118 118  
119 119 DPRINTF("Reset\n");
120 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 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 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 376 USBDevice *usb_msd_init(const char *filename)
374 377 {
... ... @@ -388,11 +391,12 @@ USBDevice *usb_msd_init(const char *filename)
388 391 s->dev.handle_reset = usb_msd_handle_reset;
389 392 s->dev.handle_control = usb_msd_handle_control;
390 393 s->dev.handle_data = usb_msd_handle_data;
  394 + s->dev.handle_destroy = usb_msd_handle_destroy;
391 395  
392 396 snprintf(s->dev.devname, sizeof(s->dev.devname), "QEMU USB MSD(%.16s)",
393 397 filename);
394 398  
395 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 401 return (USBDevice *)s;
398 402 }
... ...
hw/usb.c
... ... @@ -55,10 +55,7 @@ int usb_generic_handle_packet(USBDevice *s, int pid,
55 55 s->remote_wakeup = 0;
56 56 s->addr = 0;
57 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 59 break;
63 60 case USB_TOKEN_SETUP:
64 61 if (s->state < USB_STATE_DEFAULT || devaddr != s->addr)
... ...
hw/usb.h
... ... @@ -29,7 +29,6 @@
29 29 #define USB_MSG_ATTACH 0x100
30 30 #define USB_MSG_DETACH 0x101
31 31 #define USB_MSG_RESET 0x102
32   -#define USB_MSG_DESTROY 0x103
33 32  
34 33 #define USB_RET_NODEV (-1)
35 34 #define USB_RET_NAK (-2)
... ... @@ -117,12 +116,14 @@ struct USBDevice {
117 116 int (*handle_packet)(USBDevice *dev, int pid,
118 117 uint8_t devaddr, uint8_t devep,
119 118 uint8_t *data, int len);
  119 + void (*handle_destroy)(USBDevice *dev);
  120 +
120 121 int speed;
121 122  
122 123 /* The following fields are used by the generic USB device
123 124 layer. They are here just to avoid creating a new structure for
124 125 them. */
125   - void (*handle_reset)(USBDevice *dev, int destroy);
  126 + void (*handle_reset)(USBDevice *dev);
126 127 int (*handle_control)(USBDevice *dev, int request, int value,
127 128 int index, int length, uint8_t *data);
128 129 int (*handle_data)(USBDevice *dev, int pid, uint8_t devep,
... ...
usb-linux.c
... ... @@ -58,16 +58,8 @@ typedef struct USBHostDevice {
58 58 int fd;
59 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 63 #if 0
72 64 USBHostDevice *s = (USBHostDevice *)dev;
73 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 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 80 static int usb_host_handle_control(USBDevice *dev,
80 81 int request,
81 82 int value,
... ... @@ -244,6 +245,7 @@ USBDevice *usb_host_device_open(const char *devname)
244 245 dev->dev.handle_reset = usb_host_handle_reset;
245 246 dev->dev.handle_control = usb_host_handle_control;
246 247 dev->dev.handle_data = usb_host_handle_data;
  248 + dev->dev.handle_destroy = usb_host_handle_destroy;
247 249  
248 250 if (product_name[0] == '\0')
249 251 snprintf(dev->dev.devname, sizeof(dev->dev.devname),
... ...
... ... @@ -3781,6 +3781,7 @@ static int usb_device_del(const char *devname)
3781 3781 {
3782 3782 USBPort *port;
3783 3783 USBPort **lastp;
  3784 + USBDevice *dev;
3784 3785 int bus_num, addr;
3785 3786 const char *p;
3786 3787  
... ... @@ -3805,8 +3806,10 @@ static int usb_device_del(const char *devname)
3805 3806 if (!port)
3806 3807 return -1;
3807 3808  
  3809 + dev = port->dev;
3808 3810 *lastp = port->next;
3809 3811 usb_attach(port, NULL);
  3812 + dev->handle_destroy(dev);
3810 3813 port->next = free_usb_ports;
3811 3814 free_usb_ports = port;
3812 3815 return 0;
... ...