usb: add hotplug support for usb-bot and usb-uas.

-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2.0.22 (GNU/Linux)
 
 iQIcBAABAgAGBQJXanpqAAoJEEy22O7T6HE4DzcP/iNmFptX4i74v97bQs1Htcql
 kEV/D9tzvM0SFWMOudDHZ0coxh3sQZs5Qmw/JLPYm59RWWQe2CLhddr+Rndd3z5y
 QiC18cgjTHniraEbjSFGT1WLdlLT7YF8T+ym6h5iy2XBiCka3PnThlFidzOXWg6O
 GCiddGFcIp8KpFdmheNPgFTCO3cWke84pfRW7UwqazHCYZ6nUuUE2bskkW2nCXC5
 Y/DMvIHA+opqQDVXHRM77Qf25POM140RyOTpx893q4A6tM6MGiQ+FK5ifszsXPaY
 w/V9I4/w3aAZIui7SFfU6NCmKJOfKWRzYOn4tU2P2F56IeU0vGfo6VDB9gtftFVB
 XFe9rtG3xvGPDctA47hMWA9FwxBlUR5J9dG+sTPlj4uGmc4ay3JqYWURCpYHlw5w
 g8mP2JjeqGc129zKVz1qN0Dfn7lR/Uz2CwDsJPr1DgA6IAXGkxC1W4M9RmFN9cWo
 3cWV1EsO51o6fJqlmPTi0a9jm0EE2MBKDx+Nk0+ykM/1/5zvUYDniC2NJ+1pdjZj
 RCZjQLdwj+oC3F6cuwZJpw7fk5z9N0W7j7gd4D0AT+0iKoPpFtHyaM+Txc3Jgkci
 NfnwXSlRARP7QuokfZBonA+AcV9nVDrXpb7Wp8vp62qBf4z5GJteJpssLnCEIMp4
 pGhEg2VFd78NywGaWfCt
 =csfS
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/kraxel/tags/pull-usb-20160622-2' into staging

usb: add hotplug support for usb-bot and usb-uas.

# gpg: Signature made Wed 22 Jun 2016 12:45:46 BST
# gpg:                using RSA key 0x4CB6D8EED3E87138
# gpg: Good signature from "Gerd Hoffmann (work) <kraxel@redhat.com>"
# gpg:                 aka "Gerd Hoffmann <gerd@kraxel.org>"
# gpg:                 aka "Gerd Hoffmann (private) <kraxel@gmail.com>"
# Primary key fingerprint: A032 8CFF B93A 17A7 9901  FE7D 4CB6 D8EE D3E8 7138

* remotes/kraxel/tags/pull-usb-20160622-2:
  usb-uas: hotplug support
  usb-bot: hotplug support
  usb: Add QOM property "attached".
  usb: make USBDevice->attached bool
  usb-storage: qcow2 encryption support is finally gone, zap dead code

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2016-06-23 11:18:57 +01:00
commit c6eb076aec
4 changed files with 60 additions and 41 deletions

View File

@ -55,9 +55,9 @@ static int usb_device_post_load(void *opaque, int version_id)
USBDevice *dev = opaque;
if (dev->state == USB_STATE_NOTATTACHED) {
dev->attached = 0;
dev->attached = false;
} else {
dev->attached = 1;
dev->attached = true;
}
if (dev->setup_index < 0 ||
dev->setup_len < 0 ||
@ -533,7 +533,7 @@ void usb_device_attach(USBDevice *dev, Error **errp)
return;
}
dev->attached++;
dev->attached = true;
usb_attach(port);
}
@ -547,7 +547,7 @@ int usb_device_detach(USBDevice *dev)
trace_usb_port_detach(bus->busnr, port->path);
usb_detach(port);
dev->attached--;
dev->attached = false;
return 0;
}
@ -736,6 +736,48 @@ USBDevice *usbdevice_create(const char *cmdline)
return dev;
}
static bool usb_get_attached(Object *obj, Error **errp)
{
USBDevice *dev = USB_DEVICE(obj);
return dev->attached;
}
static void usb_set_attached(Object *obj, bool value, Error **errp)
{
USBDevice *dev = USB_DEVICE(obj);
Error *err = NULL;
if (dev->attached == value) {
return;
}
if (value) {
usb_device_attach(dev, &err);
if (err) {
error_propagate(errp, err);
}
} else {
usb_device_detach(dev);
}
}
static void usb_device_instance_init(Object *obj)
{
USBDevice *dev = USB_DEVICE(obj);
USBDeviceClass *klass = USB_DEVICE_GET_CLASS(dev);
if (klass->attached_settable) {
object_property_add_bool(obj, "attached",
usb_get_attached, usb_set_attached,
NULL);
} else {
object_property_add_bool(obj, "attached",
usb_get_attached, NULL,
NULL);
}
}
static void usb_device_class_init(ObjectClass *klass, void *data)
{
DeviceClass *k = DEVICE_CLASS(klass);
@ -749,6 +791,7 @@ static const TypeInfo usb_device_type_info = {
.name = TYPE_USB_DEVICE,
.parent = TYPE_DEVICE,
.instance_size = sizeof(USBDevice),
.instance_init = usb_device_instance_init,
.abstract = true,
.class_size = sizeof(USBDeviceClass),
.class_init = usb_device_class_init,

View File

@ -556,21 +556,6 @@ static void usb_msd_handle_data(USBDevice *dev, USBPacket *p)
}
}
static void usb_msd_password_cb(void *opaque, int err)
{
MSDState *s = opaque;
Error *local_err = NULL;
if (!err) {
usb_device_attach(&s->dev, &local_err);
}
if (local_err) {
error_report_err(local_err);
qdev_unplug(&s->dev.qdev, NULL);
}
}
static void *usb_msd_load_request(QEMUFile *f, SCSIRequest *req)
{
MSDState *s = DO_UPCAST(MSDState, dev.qdev, req->bus->qbus.parent);
@ -616,25 +601,6 @@ static void usb_msd_realize_storage(USBDevice *dev, Error **errp)
return;
}
if (blk_bs(blk)) {
bdrv_add_key(blk_bs(blk), NULL, &err);
if (err) {
if (monitor_cur_is_qmp()) {
error_propagate(errp, err);
return;
}
error_free(err);
err = NULL;
if (cur_mon) {
monitor_read_bdrv_key_start(cur_mon, blk_bs(blk),
usb_msd_password_cb, s);
s->dev.auto_attach = 0;
} else {
autostart = 0;
}
}
}
blkconf_serial(&s->conf, &dev->serial);
blkconf_blocksizes(&s->conf);
@ -668,9 +634,14 @@ static void usb_msd_realize_storage(USBDevice *dev, Error **errp)
static void usb_msd_realize_bot(USBDevice *dev, Error **errp)
{
MSDState *s = USB_STORAGE_DEV(dev);
DeviceState *d = DEVICE(dev);
usb_desc_create_serial(dev);
usb_desc_init(dev);
if (d->hotplugged) {
s->dev.auto_attach = 0;
}
scsi_bus_new(&s->bus, sizeof(s->bus), DEVICE(dev),
&usb_msd_scsi_info_bot, NULL);
usb_msd_handle_reset(dev);
@ -840,10 +811,9 @@ static void usb_msd_instance_init(Object *obj)
static void usb_msd_class_initfn_bot(ObjectClass *klass, void *data)
{
USBDeviceClass *uc = USB_DEVICE_CLASS(klass);
DeviceClass *dc = DEVICE_CLASS(klass);
uc->realize = usb_msd_realize_bot;
dc->hotpluggable = false;
uc->attached_settable = true;
}
static const TypeInfo msd_info = {

View File

@ -900,9 +900,13 @@ static void usb_uas_handle_destroy(USBDevice *dev)
static void usb_uas_realize(USBDevice *dev, Error **errp)
{
UASDevice *uas = USB_UAS(dev);
DeviceState *d = DEVICE(dev);
usb_desc_create_serial(dev);
usb_desc_init(dev);
if (d->hotplugged) {
uas->dev.auto_attach = 0;
}
QTAILQ_INIT(&uas->results);
QTAILQ_INIT(&uas->requests);
@ -940,6 +944,7 @@ static void usb_uas_class_initfn(ObjectClass *klass, void *data)
uc->handle_control = usb_uas_handle_control;
uc->handle_data = usb_uas_handle_data;
uc->handle_destroy = usb_uas_handle_destroy;
uc->attached_settable = true;
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
dc->fw_name = "storage";
dc->vmsd = &vmstate_usb_uas;

View File

@ -235,7 +235,7 @@ struct USBDevice {
uint8_t addr;
char product_desc[32];
int auto_attach;
int attached;
bool attached;
int32_t state;
uint8_t setup_buf[8];
@ -347,6 +347,7 @@ typedef struct USBDeviceClass {
const char *product_desc;
const USBDesc *usb_desc;
bool attached_settable;
} USBDeviceClass;
typedef struct USBPortOps {