All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH v4 29/32] usb: keep track of physical port address.
Date: Wed, 12 Jan 2011 12:20:11 +0100	[thread overview]
Message-ID: <1294831214-4499-30-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1294831214-4499-1-git-send-email-kraxel@redhat.com>

Add a path string to USBPort.  Add usb_port_location() function to set
the physical location of the usb port.  Update all drivers implementing
usb ports to call it.  Update the monitor commands to print it.  Wind it
up in qdev.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/usb-bus.c  |   26 +++++++++++++++++++++++---
 hw/usb-hub.c  |   11 +++++++++++
 hw/usb-musb.c |    1 +
 hw/usb-ohci.c |    1 +
 hw/usb-uhci.c |    1 +
 hw/usb.h      |    2 ++
 6 files changed, 39 insertions(+), 3 deletions(-)

diff --git a/hw/usb-bus.c b/hw/usb-bus.c
index e94b88d..0cb03c9 100644
--- a/hw/usb-bus.c
+++ b/hw/usb-bus.c
@@ -5,12 +5,15 @@
 #include "monitor.h"
 
 static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent);
+
+static char *usb_get_dev_path(DeviceState *dev);
 static char *usbbus_get_fw_dev_path(DeviceState *dev);
 
 static struct BusInfo usb_bus_info = {
     .name      = "USB",
     .size      = sizeof(USBBus),
     .print_dev = usb_bus_dev_print,
+    .get_dev_path = usb_get_dev_path,
     .get_fw_dev_path = usbbus_get_fw_dev_path,
 };
 static int next_usb_bus = 0;
@@ -126,6 +129,16 @@ void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
     bus->nfree++;
 }
 
+void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr)
+{
+    if (upstream) {
+        snprintf(downstream->path, sizeof(downstream->path), "%s.%d",
+                 upstream->path, portnr);
+    } else {
+        snprintf(downstream->path, sizeof(downstream->path), "%d", portnr);
+    }
+}
+
 void usb_unregister_port(USBBus *bus, USBPort *port)
 {
     if (port->dev)
@@ -235,12 +248,19 @@ static void usb_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
     USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
     USBBus *bus = usb_bus_from_device(dev);
 
-    monitor_printf(mon, "%*saddr %d.%d, speed %s, name %s%s\n",
+    monitor_printf(mon, "%*saddr %d.%d, port %s, speed %s, name %s%s\n",
                    indent, "", bus->busnr, dev->addr,
+                   dev->port ? dev->port->path : "-",
                    usb_speed(dev->speed), dev->product_desc,
                    dev->attached ? ", attached" : "");
 }
 
+static char *usb_get_dev_path(DeviceState *qdev)
+{
+    USBDevice *dev = DO_UPCAST(USBDevice, qdev, qdev);
+    return qemu_strdup(dev->port->path);
+}
+
 void usb_info(Monitor *mon)
 {
     USBBus *bus;
@@ -257,8 +277,8 @@ void usb_info(Monitor *mon)
             dev = port->dev;
             if (!dev)
                 continue;
-            monitor_printf(mon, "  Device %d.%d, Speed %s Mb/s, Product %s\n",
-                           bus->busnr, dev->addr, usb_speed(dev->speed),
+            monitor_printf(mon, "  Device %d.%d, Port %s, Speed %s Mb/s, Product %s\n",
+                           bus->busnr, dev->addr, port->path, usb_speed(dev->speed),
                            dev->product_desc);
         }
     }
diff --git a/hw/usb-hub.c b/hw/usb-hub.c
index ba712d6..387c40c 100644
--- a/hw/usb-hub.c
+++ b/hw/usb-hub.c
@@ -256,6 +256,16 @@ static void usb_hub_wakeup(USBDevice *dev)
     }
 }
 
+static void usb_hub_handle_attach(USBDevice *dev)
+{
+    USBHubState *s = DO_UPCAST(USBHubState, dev, dev);
+    int i;
+
+    for (i = 0; i < NUM_PORTS; i++) {
+        usb_port_location(&s->ports[i].port, dev->port, i+1);
+    }
+}
+
 static void usb_hub_handle_reset(USBDevice *dev)
 {
     /* XXX: do it */
@@ -542,6 +552,7 @@ static struct USBDeviceInfo hub_info = {
     .usb_desc       = &desc_hub,
     .init           = usb_hub_initfn,
     .handle_packet  = usb_hub_handle_packet,
+    .handle_attach  = usb_hub_handle_attach,
     .handle_reset   = usb_hub_handle_reset,
     .handle_control = usb_hub_handle_control,
     .handle_data    = usb_hub_handle_data,
diff --git a/hw/usb-musb.c b/hw/usb-musb.c
index 87eb9ca..4b5f35b 100644
--- a/hw/usb-musb.c
+++ b/hw/usb-musb.c
@@ -351,6 +351,7 @@ struct MUSBState {
     usb_bus_new(&s->bus, NULL /* FIXME */);
     usb_register_port(&s->bus, &s->port, s, 0, NULL, &musb_port_ops,
                       USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
+    usb_port_location(&s->port, NULL, 1);
 
     return s;
 }
diff --git a/hw/usb-ohci.c b/hw/usb-ohci.c
index 0d42716..6344f81 100644
--- a/hw/usb-ohci.c
+++ b/hw/usb-ohci.c
@@ -1701,6 +1701,7 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState *dev,
     for (i = 0; i < num_ports; i++) {
         usb_register_port(&ohci->bus, &ohci->rhport[i].port, ohci, i, NULL, &ohci_port_ops,
                           USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
+        usb_port_location(&ohci->rhport[i].port, NULL, i+1);
     }
 
     ohci->async_td = 0;
diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 253561f..6db1960 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -1131,6 +1131,7 @@ static int usb_uhci_common_initfn(UHCIState *s)
     for(i = 0; i < NB_PORTS; i++) {
         usb_register_port(&s->bus, &s->ports[i].port, s, i, NULL, &uhci_port_ops,
                           USB_SPEED_MASK_LOW | USB_SPEED_MASK_FULL);
+        usb_port_location(&s->ports[i].port, NULL, i+1);
     }
     s->frame_timer = qemu_new_timer(vm_clock, uhci_frame_timer, s);
     s->expire_time = qemu_get_clock(vm_clock) +
diff --git a/hw/usb.h b/hw/usb.h
index 99139e2..8fdda29 100644
--- a/hw/usb.h
+++ b/hw/usb.h
@@ -240,6 +240,7 @@ typedef struct USBPortOps {
 struct USBPort {
     USBDevice *dev;
     int speedmask;
+    char path[16];
     USBPortOps *ops;
     void *opaque;
     USBDevice *pdev;
@@ -354,6 +355,7 @@ USBDevice *usb_create_simple(USBBus *bus, const char *name);
 USBDevice *usbdevice_create(const char *cmdline);
 void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index,
                        USBDevice *pdev, USBPortOps *ops, int speedmask);
+void usb_port_location(USBPort *downstream, USBPort *upstream, int portnr);
 void usb_unregister_port(USBBus *bus, USBPort *port);
 int usb_device_attach(USBDevice *dev);
 int usb_device_detach(USBDevice *dev);
-- 
1.7.1

  parent reply	other threads:[~2011-01-12 11:21 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-12 11:19 [Qemu-devel] [PATCH v4 00/32] usb descriptor overhaul + more Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 01/32] usb: update MAINTAINERS Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 02/32] usb: data structs and helpers for usb descriptors Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 03/32] usb hid: use new descriptor infrastructure Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 04/32] usb serial: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 05/32] usb storage: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 06/32] usb wacom: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 07/32] usb bluetooth: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 08/32] usb hub: " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 09/32] usb descriptors: add settable strings Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 10/32] usb storage: serial number support Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 11/32] usb network: use new descriptor infrastructure Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 12/32] usb: move USB_REQ_SET_ADDRESS handling to common code Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 13/32] usb: move USB_REQ_{GET, SET}_CONFIGURATION " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 14/32] usb: move remote wakeup " Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 15/32] usb: create USBPortOps, move attach there Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 16/32] usb: rework attach/detach workflow Gerd Hoffmann
2011-01-12 11:19 ` [Qemu-devel] [PATCH v4 17/32] usb: add usb_wakeup() + wakeup callback to port ops Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 18/32] usb: uhci: remote wakeup support Gerd Hoffmann
2011-01-12 12:25   ` Stefan Hajnoczi
2011-01-14 11:56     ` Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 19/32] usb: hub: " Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 20/32] usb: hid: " Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 21/32] usb: hid: change serial number to "42" Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 22/32] usb: add speed mask to ports Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 23/32] usb: add attach callback Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 24/32] usb: add usb_desc_attach Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 25/32] usb: add device qualifier support Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 26/32] usb storage: high speed support Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 27/32] usb storage: fix status reporting Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 28/32] usb storage: handle long responses Gerd Hoffmann
2011-01-12 11:20 ` Gerd Hoffmann [this message]
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 30/32] usb: add port property Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 31/32] usb: rewrite fw path, fix numbering Gerd Hoffmann
2011-01-12 11:20 ` [Qemu-devel] [PATCH v4 32/32] usb: zap pdev from usbport Gerd Hoffmann
2011-01-21 15:00 ` [Qemu-devel] Re: [PATCH v4 00/32] usb descriptor overhaul + more Gerd Hoffmann
2011-01-21 17:04   ` Aurelien Jarno

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=1294831214-4499-30-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.