From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 02/17] usb: track configuration and interface count in USBDevice.
Date: Fri, 13 Jan 2012 11:18:19 +0100 [thread overview]
Message-ID: <1326449914-8591-3-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1326449914-8591-1-git-send-email-kraxel@redhat.com>
Move fields from USBHostDevice to USBDevice.
Add bits to usb-desc.c to fill them for emulated devices too.
Also allow to set configuration 0 (== None) for emulated devices.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/usb-desc.c | 34 ++++++++++++++++++++++++++--------
hw/usb.h | 3 +++
usb-linux.c | 21 +++++++++------------
3 files changed, 38 insertions(+), 20 deletions(-)
diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index ae2d384..b52561a 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -223,6 +223,29 @@ int usb_desc_other(const USBDescOther *desc, uint8_t *dest, size_t len)
/* ------------------------------------------------------------------ */
+static int usb_desc_set_config(USBDevice *dev, int value)
+{
+ int i;
+
+ if (value == 0) {
+ dev->configuration = 0;
+ dev->ninterfaces = 0;
+ dev->config = NULL;
+ } else {
+ for (i = 0; i < dev->device->bNumConfigurations; i++) {
+ if (dev->device->confs[i].bConfigurationValue == value) {
+ dev->configuration = value;
+ dev->ninterfaces = dev->device->confs[i].bNumInterfaces;
+ dev->config = dev->device->confs + i;
+ }
+ }
+ if (i < dev->device->bNumConfigurations) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
static void usb_desc_setdefaults(USBDevice *dev)
{
const USBDesc *desc = dev->info->usb_desc;
@@ -237,7 +260,7 @@ static void usb_desc_setdefaults(USBDevice *dev)
dev->device = desc->high;
break;
}
- dev->config = dev->device->confs;
+ usb_desc_set_config(dev, 0);
}
void usb_desc_init(USBDevice *dev)
@@ -408,7 +431,7 @@ int usb_desc_handle_control(USBDevice *dev, USBPacket *p,
int request, int value, int index, int length, uint8_t *data)
{
const USBDesc *desc = dev->info->usb_desc;
- int i, ret = -1;
+ int ret = -1;
assert(desc != NULL);
switch(request) {
@@ -427,12 +450,7 @@ int usb_desc_handle_control(USBDevice *dev, USBPacket *p,
ret = 1;
break;
case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
- for (i = 0; i < dev->device->bNumConfigurations; i++) {
- if (dev->device->confs[i].bConfigurationValue == value) {
- dev->config = dev->device->confs + i;
- ret = 0;
- }
- }
+ ret = usb_desc_set_config(dev, value);
trace_usb_set_config(dev->addr, value, ret);
break;
diff --git a/hw/usb.h b/hw/usb.h
index c6e1870..1ef53a1 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -188,6 +188,9 @@ struct USBDevice {
QLIST_HEAD(, USBDescString) strings;
const USBDescDevice *device;
+
+ int configuration;
+ int ninterfaces;
const USBDescConfig *config;
};
diff --git a/usb-linux.c b/usb-linux.c
index c68e194..3aaa93b 100644
--- a/usb-linux.c
+++ b/usb-linux.c
@@ -106,8 +106,6 @@ typedef struct USBHostDevice {
uint8_t descr[8192];
int descr_len;
- int configuration;
- int ninterfaces;
int closing;
uint32_t iso_urb_count;
Notifier exit;
@@ -547,8 +545,8 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
int ret, i;
if (configuration == 0) { /* address state - ignore */
- dev->ninterfaces = 0;
- dev->configuration = 0;
+ dev->dev.ninterfaces = 0;
+ dev->dev.configuration = 0;
return 1;
}
@@ -606,8 +604,8 @@ static int usb_host_claim_interfaces(USBHostDevice *dev, int configuration)
trace_usb_host_claim_interfaces(dev->bus_num, dev->addr,
nb_interfaces, configuration);
- dev->ninterfaces = nb_interfaces;
- dev->configuration = configuration;
+ dev->dev.ninterfaces = nb_interfaces;
+ dev->dev.configuration = configuration;
return 1;
fail:
@@ -624,7 +622,7 @@ static int usb_host_release_interfaces(USBHostDevice *s)
trace_usb_host_release_interfaces(s->bus_num, s->addr);
- for (i = 0; i < s->ninterfaces; i++) {
+ for (i = 0; i < s->dev.ninterfaces; i++) {
ret = ioctl(s->fd, USBDEVFS_RELEASEINTERFACE, &i);
if (ret < 0) {
perror("USBDEVFS_RELEASEINTERFACE");
@@ -1123,7 +1121,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
s->ep_out[i].type = INVALID_EP_TYPE;
}
- if (s->configuration == 0) {
+ if (s->dev.configuration == 0) {
/* not configured yet -- leave all endpoints disabled */
return 0;
}
@@ -1138,12 +1136,11 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
if (descriptors[i + 1] != USB_DT_CONFIG) {
fprintf(stderr, "invalid descriptor data\n");
return 1;
- } else if (descriptors[i + 5] != s->configuration) {
- DPRINTF("not requested configuration %d\n", s->configuration);
+ } else if (descriptors[i + 5] != s->dev.configuration) {
+ DPRINTF("not requested configuration %d\n", s->dev.configuration);
i += (descriptors[i + 3] << 8) + descriptors[i + 2];
continue;
}
-
i += descriptors[i];
if (descriptors[i + 1] != USB_DT_INTERFACE ||
@@ -1154,7 +1151,7 @@ static int usb_linux_update_endp_table(USBHostDevice *s)
}
interface = descriptors[i + 2];
- alt_interface = usb_linux_get_alt_setting(s, s->configuration,
+ alt_interface = usb_linux_get_alt_setting(s, s->dev.configuration,
interface);
/* the current interface descriptor is the active interface
--
1.7.1
next prev parent reply other threads:[~2012-01-13 11:36 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-01-13 10:18 [Qemu-devel] [PULL 00/17] usb patch queue: audio, xhci, usbredir Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 01/17] usb-host: rip out legacy procfs support Gerd Hoffmann
2012-01-13 10:18 ` Gerd Hoffmann [this message]
2012-01-13 10:18 ` [Qemu-devel] [PATCH 03/17] usb: track altsetting in USBDevice Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 04/17] usb-desc: audio endpoint support Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 05/17] usb: add audio device model Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 06/17] xhci: Initial xHCI implementation Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 07/17] usb: add USBEndpoint Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 08/17] usb: add ifnum to USBEndpoint Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 09/17] usb-desc: USBEndpoint support Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 10/17] usb/debug: add usb_ep_dump Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 11/17] usb: add max_packet_size to USBEndpoint Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 12/17] usb: link packets to endpoints not devices Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 13/17] usb-redir: Clear iso / irq error when stopping the stream Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 14/17] usb-redir: Dynamically adjust iso buffering size based on ep interval Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 15/17] usb-redir: Pre-fill our isoc input buffer before sending pkts to the host Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 16/17] usb-redir: Try to keep our buffer size near the target size Gerd Hoffmann
2012-01-13 10:18 ` [Qemu-devel] [PATCH 17/17] usb-redir: Improve some debugging messages Gerd Hoffmann
2012-01-13 15:19 ` [Qemu-devel] [PULL 00/17] usb patch queue: audio, xhci, usbredir Anthony Liguori
2012-01-17 9:06 ` Gerd Hoffmann
2012-01-19 18:48 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1326449914-8591-3-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).