From 7d553f27fce284805d7f94603932045ee3bbb979 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Fri, 19 Sep 2014 14:48:24 +0800 Subject: usb-bus: convert USBDeviceClass init to realize Add "realize/unrealize" in USBDeviceClass, which has errp as a parameter. So all the implementations now use error_setg instead of error_report for reporting error. Note: this patch still keep "init" in USBDeviceClass, and call kclass->init in usb_device_realize(), avoid breaking git bisect. After realize all usb devices, will be removed. Signed-off-by: Gonglei Signed-off-by: Gerd Hoffmann --- include/hw/usb.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'include') diff --git a/include/hw/usb.h b/include/hw/usb.h index 6b32a3bb70..612f09f8c1 100644 --- a/include/hw/usb.h +++ b/include/hw/usb.h @@ -267,11 +267,17 @@ struct USBDevice { #define USB_DEVICE_GET_CLASS(obj) \ OBJECT_GET_CLASS(USBDeviceClass, (obj), TYPE_USB_DEVICE) +typedef void (*USBDeviceRealize)(USBDevice *dev, Error **errp); +typedef void (*USBDeviceUnrealize)(USBDevice *dev, Error **errp); + typedef struct USBDeviceClass { DeviceClass parent_class; int (*init)(USBDevice *dev); + USBDeviceRealize realize; + USBDeviceUnrealize unrealize; + /* * Walk (enabled) downstream ports, check for a matching device. * Only hubs implement this. @@ -544,9 +550,9 @@ int usb_register_companion(const char *masterbus, USBPort *ports[], void *opaque, USBPortOps *ops, int speedmask); void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr); void usb_unregister_port(USBBus *bus, USBPort *port); -int usb_claim_port(USBDevice *dev); +void usb_claim_port(USBDevice *dev, Error **errp); void usb_release_port(USBDevice *dev); -int usb_device_attach(USBDevice *dev); +void usb_device_attach(USBDevice *dev, Error **errp); int usb_device_detach(USBDevice *dev); int usb_device_delete_addr(int busnr, int addr); -- cgit v1.2.3-55-g7522 From bd2ba2752d860d5a0b4f328332c3e0b79d275de8 Mon Sep 17 00:00:00 2001 From: Gonglei Date: Fri, 19 Sep 2014 14:48:41 +0800 Subject: usb-bus: remove "init" from USBDeviceClass struct All usb-bus devices are realized by realize(), remove init callback function from USBDeviceClass struct. Signed-off-by: Gonglei Reviewed-by: Paolo Bonzini Signed-off-by: Gerd Hoffmann --- hw/usb/bus.c | 2 -- include/hw/usb.h | 2 -- 2 files changed, 4 deletions(-) (limited to 'include') diff --git a/hw/usb/bus.c b/hw/usb/bus.c index 12881cbdd1..b375293529 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -113,8 +113,6 @@ static void usb_device_realize(USBDevice *dev, Error **errp) if (klass->realize) { klass->realize(dev, errp); - } else if (klass->init) { - klass->init(dev); } } diff --git a/include/hw/usb.h b/include/hw/usb.h index 612f09f8c1..8ffbba2174 100644 --- a/include/hw/usb.h +++ b/include/hw/usb.h @@ -273,8 +273,6 @@ typedef void (*USBDeviceUnrealize)(USBDevice *dev, Error **errp); typedef struct USBDeviceClass { DeviceClass parent_class; - int (*init)(USBDevice *dev); - USBDeviceRealize realize; USBDeviceUnrealize unrealize; -- cgit v1.2.3-55-g7522 From 594a53607e5bd4a2b7555a7a2908d2c406fea9aa Mon Sep 17 00:00:00 2001 From: Gonglei Date: Fri, 19 Sep 2014 15:25:20 +0800 Subject: usb-bus: introduce a wrapper function to check speed In this way, we can check speed directly, don't need call usb_device_attach(), which has other conditions, such as checking the chardev is open. Signed-off-by: Gonglei Reviewed-by: Paolo Bonzini Signed-off-by: Gerd Hoffmann --- hw/usb/bus.c | 14 +++++++++++++- include/hw/usb.h | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/hw/usb/bus.c b/hw/usb/bus.c index b375293529..da1eba9fbd 100644 --- a/hw/usb/bus.c +++ b/hw/usb/bus.c @@ -478,7 +478,7 @@ static void usb_mask_to_str(char *dest, size_t size, } } -void usb_device_attach(USBDevice *dev, Error **errp) +void usb_check_attach(USBDevice *dev, Error **errp) { USBBus *bus = usb_bus_from_device(dev); USBPort *port = dev->port; @@ -499,6 +499,18 @@ void usb_device_attach(USBDevice *dev, Error **errp) bus->qbus.name, port->path, portspeed); return; } +} + +void usb_device_attach(USBDevice *dev, Error **errp) +{ + USBPort *port = dev->port; + Error *local_err = NULL; + + usb_check_attach(dev, &local_err); + if (local_err) { + error_propagate(errp, local_err); + return; + } dev->attached++; usb_attach(port); diff --git a/include/hw/usb.h b/include/hw/usb.h index 8ffbba2174..b20b959123 100644 --- a/include/hw/usb.h +++ b/include/hw/usb.h @@ -553,6 +553,7 @@ void usb_release_port(USBDevice *dev); void usb_device_attach(USBDevice *dev, Error **errp); int usb_device_detach(USBDevice *dev); int usb_device_delete_addr(int busnr, int addr); +void usb_check_attach(USBDevice *dev, Error **errp); static inline USBBus *usb_bus_from_device(USBDevice *d) { -- cgit v1.2.3-55-g7522