|
|
9ae3a8 |
From b853920b298d19a1905d106c7d965bda29b7a26c Mon Sep 17 00:00:00 2001
|
|
|
9ae3a8 |
From: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
9ae3a8 |
Date: Mon, 2 Sep 2013 13:26:15 +0200
|
|
|
9ae3a8 |
Subject: [PATCH 09/29] usb: add serial bus property
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
RH-Author: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
9ae3a8 |
Message-id: <1378128376-25930-2-git-send-email-kraxel@redhat.com>
|
|
|
9ae3a8 |
Patchwork-id: 53989
|
|
|
9ae3a8 |
O-Subject: [RHEL-7 qemu-kvm PATCH 1/2] usb: add serial bus property
|
|
|
9ae3a8 |
Bugzilla: 953304
|
|
|
9ae3a8 |
RH-Acked-by: Markus Armbruster <armbru@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Hans de Goede <hdegoede@redhat.com>
|
|
|
9ae3a8 |
RH-Acked-by: Paolo Bonzini <pbonzini@redhat.com>
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
This patch adds a serial property for all usb devices, which can be
|
|
|
9ae3a8 |
used to set the serial number of a usb device (as listed by lsusb -v)
|
|
|
9ae3a8 |
to a specific value. Applies to emulated devices only.
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
|
|
|
9ae3a8 |
(cherry picked from commit 71938a09d2b9fd4007515fec6c395916cb08f868)
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
hw/usb/bus.c | 1 +
|
|
|
9ae3a8 |
hw/usb/desc.c | 6 ++++++
|
|
|
9ae3a8 |
hw/usb/dev-hid.c | 3 +++
|
|
|
9ae3a8 |
hw/usb/dev-storage.c | 13 +++----------
|
|
|
9ae3a8 |
include/hw/usb.h | 1 +
|
|
|
9ae3a8 |
5 files changed, 14 insertions(+), 10 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
9ae3a8 |
---
|
|
|
9ae3a8 |
hw/usb/bus.c | 1 +
|
|
|
9ae3a8 |
hw/usb/desc.c | 6 ++++++
|
|
|
9ae3a8 |
hw/usb/dev-hid.c | 3 +++
|
|
|
9ae3a8 |
hw/usb/dev-storage.c | 13 +++----------
|
|
|
9ae3a8 |
include/hw/usb.h | 1 +
|
|
|
9ae3a8 |
5 files changed, 14 insertions(+), 10 deletions(-)
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
diff --git a/hw/usb/bus.c b/hw/usb/bus.c
|
|
|
9ae3a8 |
index d1827be..f83d1de 100644
|
|
|
9ae3a8 |
--- a/hw/usb/bus.c
|
|
|
9ae3a8 |
+++ b/hw/usb/bus.c
|
|
|
9ae3a8 |
@@ -13,6 +13,7 @@ static int usb_qdev_exit(DeviceState *qdev);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static Property usb_props[] = {
|
|
|
9ae3a8 |
DEFINE_PROP_STRING("port", USBDevice, port_path),
|
|
|
9ae3a8 |
+ DEFINE_PROP_STRING("serial", USBDevice, serial),
|
|
|
9ae3a8 |
DEFINE_PROP_BIT("full-path", USBDevice, flags,
|
|
|
9ae3a8 |
USB_DEV_FLAG_FULL_PATH, true),
|
|
|
9ae3a8 |
DEFINE_PROP_END_OF_LIST()
|
|
|
9ae3a8 |
diff --git a/hw/usb/desc.c b/hw/usb/desc.c
|
|
|
9ae3a8 |
index fce303e..bf6c522 100644
|
|
|
9ae3a8 |
--- a/hw/usb/desc.c
|
|
|
9ae3a8 |
+++ b/hw/usb/desc.c
|
|
|
9ae3a8 |
@@ -566,6 +566,12 @@ void usb_desc_create_serial(USBDevice *dev)
|
|
|
9ae3a8 |
char *path;
|
|
|
9ae3a8 |
int dst;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+ if (dev->serial) {
|
|
|
9ae3a8 |
+ /* 'serial' usb bus property has priority if present */
|
|
|
9ae3a8 |
+ usb_desc_set_string(dev, index, dev->serial);
|
|
|
9ae3a8 |
+ return;
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
+
|
|
|
9ae3a8 |
assert(index != 0 && desc->str[index] != NULL);
|
|
|
9ae3a8 |
dst = snprintf(serial, sizeof(serial), "%s", desc->str[index]);
|
|
|
9ae3a8 |
path = qdev_get_dev_path(hcd);
|
|
|
9ae3a8 |
diff --git a/hw/usb/dev-hid.c b/hw/usb/dev-hid.c
|
|
|
9ae3a8 |
index b48899d..31f3cde 100644
|
|
|
9ae3a8 |
--- a/hw/usb/dev-hid.c
|
|
|
9ae3a8 |
+++ b/hw/usb/dev-hid.c
|
|
|
9ae3a8 |
@@ -560,6 +560,9 @@ static int usb_hid_initfn(USBDevice *dev, int kind)
|
|
|
9ae3a8 |
{
|
|
|
9ae3a8 |
USBHIDState *us = DO_UPCAST(USBHIDState, dev, dev);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
+ if (dev->serial) {
|
|
|
9ae3a8 |
+ usb_desc_set_string(dev, STR_SERIALNUMBER, dev->serial);
|
|
|
9ae3a8 |
+ }
|
|
|
9ae3a8 |
usb_desc_init(dev);
|
|
|
9ae3a8 |
us->intr = usb_ep_get(dev, USB_TOKEN_IN, 1);
|
|
|
9ae3a8 |
hid_init(&us->hid, kind, usb_hid_changed);
|
|
|
9ae3a8 |
diff --git a/hw/usb/dev-storage.c b/hw/usb/dev-storage.c
|
|
|
9ae3a8 |
index 1073901..fe914ab 100644
|
|
|
9ae3a8 |
--- a/hw/usb/dev-storage.c
|
|
|
9ae3a8 |
+++ b/hw/usb/dev-storage.c
|
|
|
9ae3a8 |
@@ -58,7 +58,6 @@ typedef struct {
|
|
|
9ae3a8 |
USBPacket *packet;
|
|
|
9ae3a8 |
/* usb-storage only */
|
|
|
9ae3a8 |
BlockConf conf;
|
|
|
9ae3a8 |
- char *serial;
|
|
|
9ae3a8 |
uint32_t removable;
|
|
|
9ae3a8 |
} MSDState;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
@@ -602,7 +601,7 @@ static int usb_msd_initfn_storage(USBDevice *dev)
|
|
|
9ae3a8 |
return -1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- blkconf_serial(&s->conf, &s->serial);
|
|
|
9ae3a8 |
+ blkconf_serial(&s->conf, &dev->serial);
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
/*
|
|
|
9ae3a8 |
* Hack alert: this pretends to be a block device, but it's really
|
|
|
9ae3a8 |
@@ -616,16 +615,11 @@ static int usb_msd_initfn_storage(USBDevice *dev)
|
|
|
9ae3a8 |
bdrv_detach_dev(bs, &s->dev.qdev);
|
|
|
9ae3a8 |
s->conf.bs = NULL;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
- if (s->serial) {
|
|
|
9ae3a8 |
- usb_desc_set_string(dev, STR_SERIALNUMBER, s->serial);
|
|
|
9ae3a8 |
- } else {
|
|
|
9ae3a8 |
- usb_desc_create_serial(dev);
|
|
|
9ae3a8 |
- }
|
|
|
9ae3a8 |
-
|
|
|
9ae3a8 |
+ usb_desc_create_serial(dev);
|
|
|
9ae3a8 |
usb_desc_init(dev);
|
|
|
9ae3a8 |
scsi_bus_new(&s->bus, &s->dev.qdev, &usb_msd_scsi_info_storage, NULL);
|
|
|
9ae3a8 |
scsi_dev = scsi_bus_legacy_add_drive(&s->bus, bs, 0, !!s->removable,
|
|
|
9ae3a8 |
- s->conf.bootindex, s->serial);
|
|
|
9ae3a8 |
+ s->conf.bootindex, dev->serial);
|
|
|
9ae3a8 |
if (!scsi_dev) {
|
|
|
9ae3a8 |
return -1;
|
|
|
9ae3a8 |
}
|
|
|
9ae3a8 |
@@ -734,7 +728,6 @@ static const VMStateDescription vmstate_usb_msd = {
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
static Property msd_properties[] = {
|
|
|
9ae3a8 |
DEFINE_BLOCK_PROPERTIES(MSDState, conf),
|
|
|
9ae3a8 |
- DEFINE_PROP_STRING("serial", MSDState, serial),
|
|
|
9ae3a8 |
DEFINE_PROP_BIT("removable", MSDState, removable, 0, false),
|
|
|
9ae3a8 |
DEFINE_PROP_END_OF_LIST(),
|
|
|
9ae3a8 |
};
|
|
|
9ae3a8 |
diff --git a/include/hw/usb.h b/include/hw/usb.h
|
|
|
9ae3a8 |
index 4d9d05e..901b0da 100644
|
|
|
9ae3a8 |
--- a/include/hw/usb.h
|
|
|
9ae3a8 |
+++ b/include/hw/usb.h
|
|
|
9ae3a8 |
@@ -205,6 +205,7 @@ struct USBDevice {
|
|
|
9ae3a8 |
DeviceState qdev;
|
|
|
9ae3a8 |
USBPort *port;
|
|
|
9ae3a8 |
char *port_path;
|
|
|
9ae3a8 |
+ char *serial;
|
|
|
9ae3a8 |
void *opaque;
|
|
|
9ae3a8 |
uint32_t flags;
|
|
|
9ae3a8 |
|
|
|
9ae3a8 |
--
|
|
|
9ae3a8 |
1.7.1
|
|
|
9ae3a8 |
|