aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>2006-07-19 18:06:15 +0000
committerbellard <bellard@c046a42c-6fe2-441c-8c8c-71466251a162>2006-07-19 18:06:15 +0000
commit059809e45160fda714edf645902db95e262886e9 (patch)
tree06c7c0c578bbbf43e8c8d843c61a63dec484dd4e
parent3b2ccc57c74a3a7405dabd36f7abacd3eff46b46 (diff)
usb destroy API change (Lonnie Mendez)
git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@2066 c046a42c-6fe2-441c-8c8c-71466251a162
-rw-r--r--hw/usb-hid.c18
-rw-r--r--hw/usb-hub.c12
-rw-r--r--hw/usb-msd.c16
-rw-r--r--hw/usb.c5
-rw-r--r--hw/usb.h5
-rw-r--r--usb-linux.c20
-rw-r--r--vl.c3
7 files changed, 48 insertions, 31 deletions
diff --git a/hw/usb-hid.c b/hw/usb-hid.c
index 93f46dbf92..8fc0b744b7 100644
--- a/hw/usb-hid.c
+++ b/hw/usb-hid.c
@@ -323,16 +323,10 @@ static int usb_tablet_poll(USBMouseState *s, uint8_t *buf, int len)
return l;
}
-static void usb_mouse_handle_reset(USBDevice *dev, int destroy)
+static void usb_mouse_handle_reset(USBDevice *dev)
{
USBMouseState *s = (USBMouseState *)dev;
- if (destroy) {
- qemu_add_mouse_event_handler(NULL, NULL, 0);
- qemu_free(s);
- return;
- }
-
s->dx = 0;
s->dy = 0;
s->dz = 0;
@@ -506,6 +500,14 @@ static int usb_mouse_handle_data(USBDevice *dev, int pid,
return ret;
}
+static void usb_mouse_handle_destroy(USBDevice *dev)
+{
+ USBMouseState *s = (USBMouseState *)dev;
+
+ qemu_add_mouse_event_handler(NULL, NULL, 0);
+ qemu_free(s);
+}
+
USBDevice *usb_tablet_init(void)
{
USBMouseState *s;
@@ -519,6 +521,7 @@ USBDevice *usb_tablet_init(void)
s->dev.handle_reset = usb_mouse_handle_reset;
s->dev.handle_control = usb_mouse_handle_control;
s->dev.handle_data = usb_mouse_handle_data;
+ s->dev.handle_destroy = usb_mouse_handle_destroy;
s->kind = USB_TABLET;
pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Tablet");
@@ -539,6 +542,7 @@ USBDevice *usb_mouse_init(void)
s->dev.handle_reset = usb_mouse_handle_reset;
s->dev.handle_control = usb_mouse_handle_control;
s->dev.handle_data = usb_mouse_handle_data;
+ s->dev.handle_destroy = usb_mouse_handle_destroy;
s->kind = USB_MOUSE;
pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Mouse");
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index 2eba905ff5..8350931be6 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -199,11 +199,9 @@ static void usb_hub_attach(USBPort *port1, USBDevice *dev)
}
}
-static void usb_hub_handle_reset(USBDevice *dev, int destroy)
+static void usb_hub_handle_reset(USBDevice *dev)
{
/* XXX: do it */
- if (destroy)
- qemu_free(dev);
}
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,
return usb_generic_handle_packet(dev, pid, devaddr, devep, data, len);
}
+static void usb_hub_handle_destroy(USBDevice *dev)
+{
+ USBHubState *s = (USBHubState *)dev;
+
+ qemu_free(s);
+}
+
USBDevice *usb_hub_init(int nb_ports)
{
USBHubState *s;
@@ -543,6 +548,7 @@ USBDevice *usb_hub_init(int nb_ports)
s->dev.handle_reset = usb_hub_handle_reset;
s->dev.handle_control = usb_hub_handle_control;
s->dev.handle_data = usb_hub_handle_data;
+ s->dev.handle_destroy = usb_hub_handle_destroy;
pstrcpy(s->dev.devname, sizeof(s->dev.devname), "QEMU USB Hub");
diff --git a/hw/usb-msd.c b/hw/usb-msd.c
index 3dccfb9555..ff2047d4b2 100644
--- a/hw/usb-msd.c
+++ b/hw/usb-msd.c
@@ -112,16 +112,12 @@ static void usb_msd_command_complete(void *opaque, uint32_t tag, int fail)
s->mode = USB_MSDM_CSW;
}
-static void usb_msd_handle_reset(USBDevice *dev, int destroy)
+static void usb_msd_handle_reset(USBDevice *dev)
{
MSDState *s = (MSDState *)dev;
DPRINTF("Reset\n");
s->mode = USB_MSDM_CBW;
- if (destroy) {
- scsi_disk_destroy(s->scsi_dev);
- qemu_free(s);
- }
}
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,
return ret;
}
+static void usb_msd_handle_destroy(USBDevice *dev)
+{
+ MSDState *s = (MSDState *)dev;
+
+ scsi_disk_destroy(s->scsi_dev);
+ qemu_free(s);
+}
USBDevice *usb_msd_init(const char *filename)
{
@@ -388,11 +391,12 @@ USBDevice *usb_msd_init(const char *filename)
s->dev.handle_reset = usb_msd_handle_reset;
s->dev.handle_control = usb_msd_handle_control;
s->dev.handle_data = usb_msd_handle_data;
+ s->dev.handle_destroy = usb_msd_handle_destroy;
snprintf(s->dev.devname, sizeof(s->dev.devname), "QEMU USB MSD(%.16s)",
filename);
s->scsi_dev = scsi_disk_init(bdrv, usb_msd_command_complete, s);
- usb_msd_handle_reset((USBDevice *)s, 0);
+ usb_msd_handle_reset((USBDevice *)s);
return (USBDevice *)s;
}
diff --git a/hw/usb.c b/hw/usb.c
index a00d945327..34aac5fa9b 100644
--- a/hw/usb.c
+++ b/hw/usb.c
@@ -55,10 +55,7 @@ int usb_generic_handle_packet(USBDevice *s, int pid,
s->remote_wakeup = 0;
s->addr = 0;
s->state = USB_STATE_DEFAULT;
- s->handle_reset(s, 0);
- break;
- case USB_MSG_DESTROY:
- s->handle_reset(s, 1);
+ s->handle_reset(s);
break;
case USB_TOKEN_SETUP:
if (s->state < USB_STATE_DEFAULT || devaddr != s->addr)
diff --git a/hw/usb.h b/hw/usb.h
index b0887d6802..98fde06569 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -29,7 +29,6 @@
#define USB_MSG_ATTACH 0x100
#define USB_MSG_DETACH 0x101
#define USB_MSG_RESET 0x102
-#define USB_MSG_DESTROY 0x103
#define USB_RET_NODEV (-1)
#define USB_RET_NAK (-2)
@@ -117,12 +116,14 @@ struct USBDevice {
int (*handle_packet)(USBDevice *dev, int pid,
uint8_t devaddr, uint8_t devep,
uint8_t *data, int len);
+ void (*handle_destroy)(USBDevice *dev);
+
int speed;
/* The following fields are used by the generic USB device
layer. They are here just to avoid creating a new structure for
them. */
- void (*handle_reset)(USBDevice *dev, int destroy);
+ void (*handle_reset)(USBDevice *dev);
int (*handle_control)(USBDevice *dev, int request, int value,
int index, int length, uint8_t *data);
int (*handle_data)(USBDevice *dev, int pid, uint8_t devep,
diff --git a/usb-linux.c b/usb-linux.c
index 420382be92..0a13753d48 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -58,16 +58,8 @@ typedef struct USBHostDevice {
int fd;
} USBHostDevice;
-static void usb_host_handle_reset(USBDevice *dev, int destroy)
+static void usb_host_handle_reset(USBDevice *dev)
{
- USBHostDevice *s = (USBHostDevice *)dev;
-
- if (destroy) {
- if (s->fd >= 0)
- close(s->fd);
- qemu_free(s);
- return;
- }
#if 0
USBHostDevice *s = (USBHostDevice *)dev;
/* 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)
#endif
}
+static void usb_host_handle_destroy(USBDevice *dev)
+{
+ USBHostDevice *s = (USBHostDevice *)dev;
+
+ if (s->fd >= 0)
+ close(s->fd);
+ qemu_free(s);
+}
+
static int usb_host_handle_control(USBDevice *dev,
int request,
int value,
@@ -244,6 +245,7 @@ USBDevice *usb_host_device_open(const char *devname)
dev->dev.handle_reset = usb_host_handle_reset;
dev->dev.handle_control = usb_host_handle_control;
dev->dev.handle_data = usb_host_handle_data;
+ dev->dev.handle_destroy = usb_host_handle_destroy;
if (product_name[0] == '\0')
snprintf(dev->dev.devname, sizeof(dev->dev.devname),
diff --git a/vl.c b/vl.c
index 042e12180f..657116b005 100644
--- a/vl.c
+++ b/vl.c
@@ -3781,6 +3781,7 @@ static int usb_device_del(const char *devname)
{
USBPort *port;
USBPort **lastp;
+ USBDevice *dev;
int bus_num, addr;
const char *p;
@@ -3805,8 +3806,10 @@ static int usb_device_del(const char *devname)
if (!port)
return -1;
+ dev = port->dev;
*lastp = port->next;
usb_attach(port, NULL);
+ dev->handle_destroy(dev);
port->next = free_usb_ports;
free_usb_ports = port;
return 0;