From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 21/24] usb: add usb_desc_attach
Date: Thu, 9 Dec 2010 13:30:24 +0100 [thread overview]
Message-ID: <1291897827-11424-22-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1291897827-11424-1-git-send-email-kraxel@redhat.com>
Add usb_desc_attach() which sets up the device according to the speed
the usb port is able to handle. This function can be hooked into the
handle_attach callback.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/usb-desc.c | 36 +++++++++++++++++++++++++++++++++---
hw/usb-desc.h | 1 +
2 files changed, 34 insertions(+), 3 deletions(-)
diff --git a/hw/usb-desc.c b/hw/usb-desc.c
index 56ef734..f01e1cf 100644
--- a/hw/usb-desc.c
+++ b/hw/usb-desc.c
@@ -153,16 +153,46 @@ int usb_desc_other(const USBDescOther *desc, uint8_t *dest, size_t len)
/* ------------------------------------------------------------------ */
-void usb_desc_init(USBDevice *dev)
+static void usb_desc_setdefaults(USBDevice *dev)
{
const USBDesc *desc = dev->info->usb_desc;
assert(desc != NULL);
- dev->speed = USB_SPEED_FULL;
- dev->device = desc->full;
+ switch (dev->speed) {
+ case USB_SPEED_LOW:
+ case USB_SPEED_FULL:
+ dev->device = desc->full;
+ break;
+ case USB_SPEED_HIGH:
+ dev->device = desc->high;
+ break;
+ }
dev->config = dev->device->confs;
}
+void usb_desc_init(USBDevice *dev)
+{
+ dev->speed = USB_SPEED_FULL;
+ usb_desc_setdefaults(dev);
+}
+
+void usb_desc_attach(USBDevice *dev)
+{
+ const USBDesc *desc = dev->info->usb_desc;
+
+ assert(desc != NULL);
+ if (desc->high && (dev->port->speedmask & USB_SPEED_MASK_HIGH)) {
+ dev->speed = USB_SPEED_HIGH;
+ } else if (desc->full && (dev->port->speedmask & USB_SPEED_MASK_FULL)) {
+ dev->speed = USB_SPEED_FULL;
+ } else {
+ fprintf(stderr, "usb: port/device speed mismatch for \"%s\"\n",
+ dev->info->product_desc);
+ return;
+ }
+ usb_desc_setdefaults(dev);
+}
+
void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str)
{
USBDescString *s;
diff --git a/hw/usb-desc.h b/hw/usb-desc.h
index d441725..484c7c7 100644
--- a/hw/usb-desc.h
+++ b/hw/usb-desc.h
@@ -79,6 +79,7 @@ int usb_desc_other(const USBDescOther *desc, uint8_t *dest, size_t len);
/* control message emulation helpers */
void usb_desc_init(USBDevice *dev);
+void usb_desc_attach(USBDevice *dev);
void usb_desc_set_string(USBDevice *dev, uint8_t index, const char *str);
const char *usb_desc_get_string(USBDevice *dev, uint8_t index);
int usb_desc_string(USBDevice *dev, int index, uint8_t *dest, size_t len);
--
1.7.1
next prev parent reply other threads:[~2010-12-09 12:31 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-09 12:30 [Qemu-devel] [PATCH 00/24] usb descriptor overhaul Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 01/24] usb: data structs and helpers for usb descriptors Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 02/24] usb hid: use new descriptor infrastructure Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 03/24] usb serial: " Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 04/24] usb storage: " Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 05/24] usb wacom: " Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 06/24] usb bluetooth: " Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 07/24] usb hub: " Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 08/24] usb descriptors: add settable strings Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 09/24] usb storage: serial number support Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 10/24] usb network: use new descriptor infrastructure Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 11/24] usb: move USB_REQ_SET_ADDRESS handling to common code Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 12/24] usb: move USB_REQ_{GET, SET}_CONFIGURATION " Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 13/24] usb: move remote wakeup " Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 14/24] usb: create USBPortOps, move attach there Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 15/24] usb: rework attach/detach workflow Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 16/24] usb: add usb_wakeup() + wakeup callback to port ops Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 17/24] usb: uhci: remote wakeup support Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 18/24] usb: hid: " Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 19/24] usb: add speed mask to ports Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 20/24] usb: add attach callback Gerd Hoffmann
2010-12-09 12:30 ` Gerd Hoffmann [this message]
2010-12-09 12:30 ` [Qemu-devel] [PATCH 22/24] usb: add device qualifier support Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 23/24] usb storage: high speed support Gerd Hoffmann
2010-12-09 12:30 ` [Qemu-devel] [PATCH 24/24] usb storage: fix status reporting Gerd Hoffmann
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=1291897827-11424-22-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).