Commit graph

99 commits

Author SHA1 Message Date
Gerd Hoffmann 70fc20d4dc usb: kill usb_send_msg
No users left.  Zap it.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 11:12:04 +01:00
Gerd Hoffmann d28f4e2d86 usb: kill USB_MSG_RESET
The USB subsystem pipes internal reset notifications through
usb_handle_packet() with a special magic PID.  This indirection
is a pretty pointless excercise as it ends up being handled by
usb_generic_handle_packet anyway.

Replace the USB_MSG_RESET with a usb_device_reset() function
which can be called directly.  Also rename the existing usb_reset()
function to usb_port_reset() to avoid confusion.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 11:12:04 +01:00
Gerd Hoffmann d1f8b53618 usb: kill USB_MSG_{ATTACH,DETACH}
The USB subsystem pipes internal attach/detach notifications through
usb_handle_packet() with a special magic PID.  This indirection is a
pretty pointless excercise as it ends up being handled by
usb_generic_handle_packet anyway.  Remove it.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-02-10 11:12:04 +01:00
Anthony Liguori 39bffca203 qdev: register all types natively through QEMU Object Model
This was done in a mostly automated fashion.  I did it in three steps and then
rebased it into a single step which avoids repeatedly touching every file in
the tree.

The first step was a sed-based addition of the parent type to the subclass
registration functions.

The second step was another sed-based removal of subclass registration functions
while also adding virtual functions from the base class into a class_init
function as appropriate.

Finally, a python script was used to convert the DeviceInfo structures and
qdev_register_subclass functions to TypeInfo structures, class_init functions,
and type_register_static calls.

We are almost fully converted to QOM after this commit.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03 10:41:06 -06:00
Anthony Liguori ba02430f1a usb: separate out legacy usb registration from type registration
Type registeration is going to get turned into a QOM call so decouple the
legacy support.

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03 10:41:03 -06:00
Anthony Liguori 62aed76583 usb: convert to QEMU Object Model
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-27 10:50:47 -06:00
Anthony Liguori 9ca2140ab1 Merge remote-tracking branch 'kraxel/usb.37' into staging
* kraxel/usb.37:
  usb-redir: Improve some debugging messages
  usb-redir: Try to keep our buffer size near the target size
  usb-redir: Pre-fill our isoc input buffer before sending pkts to the host
  usb-redir: Dynamically adjust iso buffering size based on ep interval
  usb-redir: Clear iso / irq error when stopping the stream
  usb: link packets to endpoints not devices
  usb: add max_packet_size to USBEndpoint
  usb/debug: add usb_ep_dump
  usb-desc: USBEndpoint support
  usb: add ifnum to USBEndpoint
  usb: add USBEndpoint
  xhci: Initial xHCI implementation
  usb: add audio device model
  usb-desc: audio endpoint support
  usb: track altsetting in USBDevice
  usb: track configuration and interface count in USBDevice.
  usb-host: rip out legacy procfs support
2012-01-19 08:34:38 -06:00
Gerd Hoffmann 25d5de7d81 usb: link packets to endpoints not devices
Add USBEndpoint for the control endpoint to USBDevices.  Link async
packets to the USBEndpoint instead of the USBDevice.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-17 09:44:50 +01:00
Gerd Hoffmann f003397ce9 usb: add max_packet_size to USBEndpoint
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-17 09:44:50 +01:00
Gerd Hoffmann 5b6780d045 usb/debug: add usb_ep_dump
Add function to dump endpoint data, for debugging purposes.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-17 09:44:50 +01:00
Gerd Hoffmann 82f02fe965 usb: add ifnum to USBEndpoint
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-17 09:44:50 +01:00
Gerd Hoffmann d8e17efdec usb: add USBEndpoint
Start maintaining endpoint state at USBDevice level.  Add USBEndpoint
struct and some helper functions to deal with it.  For now it contains
the endpoint type only.  Moved over some bits from usb-linux.c

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-17 09:44:50 +01:00
Paolo Bonzini 701a8f76aa vmstate: extract declarations out of hw/hw.h
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-13 10:20:51 -06:00
H. Peter Anvin b870472db5 usb: add audio device model
This brings a usb audio device to qemu.  Output only, fixed at
16bit stereo @ 480000 Hz.  Based on a patch from
H. Peter Anvin <hpa@linux.intel.com>

Usage: add '-device usb-audio' to your qemu command line.

Works sorta ok on a idle machine.  Known issues:

 * Is *very* sensitive to latencies.
 * Burns quite some CPU due to usb polling.

In short:  It brings the qemu usb emulation to its limits.  Enjoy!

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-13 10:25:44 +01:00
Gerd Hoffmann 1de14d43e2 usb: track altsetting in USBDevice
Also handle {GET,SET}_INTERFACE in common code (usb-desc.c).

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2012-01-13 10:25:44 +01:00
Gerd Hoffmann 65360511a2 usb: track configuration and interface count in USBDevice.
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>
2012-01-13 10:25:44 +01:00
Gerd Hoffmann e0b8e72dd9 usb: fix port reset
commit 891fb2cd45 removed the implicit
detach before (re-)attaching in usb_attach().  Some usb host controllers
used that behavior though to do a port reset by a detach+attach
sequence.

This patch establishes old behavior by adding a new usb_reset() function
for port resets and putting it into use, thereby also unifying port
reset behavior of all host controllers.  The patch also adds asserts to
usb_attach() and usb_detach() to make sure the calls are symmetrical.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-10-13 12:58:51 +02:00
Juha Riihimäki 5b1cdb4ead usb-musb: Add reset function
Add a separate reset function musb_reset() to the usb-musb interface,
so that users who implement a reset function can also reset usb-musb.
Use this in tusb6010.

Signed-off-by: Juha Riihimäki <juha.riihimaki@nokia.com>
[Riku Voipio: Fixes and restructuring patchset]
Signed-off-by: Riku Voipio <riku.voipio@iki.fi>
[Peter Maydell: More fixes and cleanups for upstream submission]
Signed-off-by:  Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07 09:58:27 +02:00
Peter Maydell 406c20754a usb-musb: Take a DeviceState* in init function
Initialise usb-musb by passing it a DeviceState* and the offset of the
IRQs in its gpio array, rather than a plain pointer to an irq array.
This is simpler for callers and also allows us to pass in a valid parent
to usb_bus_new(), so the USB bus actually appears in the qdev tree.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07 09:58:27 +02:00
Peter Maydell 9147b75288 usb: Remove leading underscores from __musb_irq_max
Identifiers with double leading underscore are reserved, so rename
__musb_irq_max so we don't encroach on reserved namespace.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07 09:58:27 +02:00
Gerd Hoffmann 891fb2cd45 usb: claim port at device initialization time.
This patch makes qemu assign a port when creating the device, not when
attaching it.  For most usb devices this isn't a noticable difference
because they are in attached state all the time.

The change affects usb-host devices which live in detached state while
the real device is unplugged from the host.  They have a fixed port
assigned all the time now instead of getting grabbing one on attach and
releasing it at detach, i.e. they stop floating around at the usb bus.

The change also allows to simplify usb-hub.  It doesn't need the
handle_attach() callback any more to configure the downstream ports.
This can be done at device initialitation time now.  The changed
initialization order (first grab upstream port, then register downstream
ports) also fixes some icky corner cases.  For example it is not possible
any more to plug the hub into one of its own downstream ports.

The usb host adapters must care too.  USBPort->dev being non-NULL
doesn't imply any more the device is in attached state.  The host
adapters must additionally check the USBPort->dev->attached flag.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-09-07 09:58:26 +02:00
Gerd Hoffmann f3aaaa242e usb-hid: remove usb_hid_datain_cb
No users left, all migrated over to hw/hid.[ch].
Yea!  Zap it!

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-08-10 14:14:00 +02:00
Gerd Hoffmann 4f4321c11f usb: use iovecs in USBPacket
Zap data pointer from USBPacket, add a QEMUIOVector instead.
Add a bunch of helper functions to manage USBPacket data.
Switch over users to the new interface.

Note that USBPacket->len was used for two purposes:  First to
pass in the buffer size and second to return the number of
transfered bytes or the status code on async transfers.  There
is a new result variable for the latter.  A new status code
was added to catch uninitialized result.

Nobody creates iovecs with more than one element (yet).
Some users are (temporarely) limited to iovecs with a single
element to keep the patch size as small as possible.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-08-04 15:51:22 +02:00
Hans de Goede 4706ab6cc0 usb: Replace device_destroy bus op with a child_detach port op
Note this fixes 2 things in one go, first of all the device_destroy bus
op should be a device_detach bus op, as pending async packets from the
device should be cancelled on detach not on destroy.

Secondly having this as a bus op won't work with companion controllers, since
then there will be 1 bus driven by the ehci controller and thus 1 set of bus
ops, but the device being detached may be downstream of a handed over port.
Making the detach of a downstream device a port op allows the ehci controller
to forward this to the companion controller port for handed over ports.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-07-05 15:09:02 +02:00
Hans de Goede d47e59b8b8 usb: Make port wakeup and complete ops take a USBPort instead of a Device
This makes them consistent with the attach and detach ops, and in general
it makes sense to make portops take a port as argument. This also makes
adding support for a companion controller easier / cleaner.

[ kraxel: fix usb-musb.c build ]

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-07-05 15:09:02 +02:00
Hans de Goede ae60fea97c usb: Add a register_companion USB bus op.
This is a preparation patch for adding support for USB companion controllers.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-07-05 15:09:02 +02:00
Gerd Hoffmann a7fb71d1b2 usb: ignore USB_DT_DEBUG
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-23 17:15:55 +02:00
Hans de Goede ba3f9bfba9 usb: Add a speedmask to devices
This is used to indicate at which speed[s] the device can operate,
so that this can be checked to match the ports capabilities when it gets
attached to a bus.

Note that currently all usb1 emulated device claim to be fullspeed, this
seems to not cause any problems, but still seems wrong, because with real
hardware keyboards, mice and tablets usually are lo-speed, so reporting these
as fullspeed devices seems wrong.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-23 11:28:06 +02:00
Brad Hards 8e257816b0 usb: Add defines for USB Serial Bus Release Number register
Signed-off-by: Brad Hards <bradh@frogmouth.net>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-14 12:56:50 +02:00
Gerd Hoffmann 07771f6fce usb: cancel async packets on unplug
This patch adds USBBusOps struct with (for now) only a single callback
which is called when a device is about to be destroyed.  The USB Host
adapters are implementing this callback and use it to cancel any async
requests which might be in flight before the device actually goes away.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-06-14 12:56:49 +02:00
Gerd Hoffmann eb5e680ae5 usb: move cancel callback to USBDeviceInfo
Remove the cancel callback from the USBPacket struct, move it over
to USBDeviceInfo.  Zap usb_defer_packet() which is obsolete now.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-26 11:55:03 +02:00
Gerd Hoffmann 4ff658fb6c usb: keep track of packet owner.
Keep track of the device which owns the usb packet for async processing.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-26 11:55:03 +02:00
Gerd Hoffmann 53aa8c0e2a usb: add usb_handle_packet
Add a usb_handle_packet function, put it into use everywhere.
Right now it just calls dev->info->handle_packet(), that will
change in future patches though.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-26 11:55:03 +02:00
Hans de Goede 50b7963e72 usb-linux: use usb_generic_handle_packet()
Make the linux usb host passthrough code use the usb_generic_handle_packet()
function, rather then the curent DYI code. This removes 200 lines of almost
identical code.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-26 11:55:02 +02:00
Hans de Goede 007fd62f4d usb: Pass the packet to the device's handle_control callback
This allows using the generic usb_generic_handle_packet function from
device code which does ASYNC control requests (such as the linux host
pass through code).

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-26 11:55:02 +02:00
Brad Hards 6e625fc704 usb: add support for "grouped" interfaces and the Interface Association Descriptor
This is used for some devices that have multiple interfaces that form a logic
device. An example is Video Class, which has a Control interface and a
Streaming interface. There can be additional interfaces on the same (physical)
devices (e.g. a microphone), and Interface Association Descriptor handles this
case.

Signed-off-by: Brad Hards <bradh@frogmouth.net>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-26 11:55:02 +02:00
Brad Hards c6d3ad0fad usb: Add Interface Association Descriptor descriptor type
Signed-off-by: Brad Hards <bradh@frogmouth.net>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-05-26 11:55:02 +02:00
Gerd Hoffmann 13a9a0d3e2 usb: move complete callback to port ops 2011-05-04 14:11:08 +02:00
Hans de Goede 19f3322379 usb: control buffer fixes
Windows allows control transfers to pass up to 4k of data, so raise our
control buffer size to 4k. For control out transfers the usb core code copies
the control request data to a buffer before calling the device's handle_control
callback. Add a check for overflowing the buffer before copying the data.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
2011-05-04 12:25:52 +02:00
Gerd Hoffmann c1ecb40a61 usb core: add migration support
Yes, seriously.  There is no migration support at all for usb devices.
They loose state, especially the device address, and stop responding
because of that.  Oops.

Luckily there is so much broken usb hardware out there that the guest
usually just kicks the device hard (via port reset and
reinitialization), then continues without a hitch.  So we got away with
that in a surprising high number of cases.

The arrival of remote wakeup (which enables autosuspend support) changes
that picture though.  The usb devices also forget that it they are
supposed to wakeup, so they don't do that.  The host also doesn't notice
the device stopped working in case it suspended the device and thus
expects it waking up instead of polling it.  Result is that your mouse
is dead.

Lets start fixing that.  Add a vmstate struct for USBDevice.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-24 17:21:34 +01:00
Gerd Hoffmann ace1318b8e usb: zap pdev from usbport
It isn't needed any more.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-12 11:40:04 +01:00
Gerd Hoffmann 5f69076b8d usb: add port property.
This allows to explictily set the physical port where you want to
plug the usb device.  Example:

  -device usb-tablet,bus=usb.0,port=2

With explicit port addressing qemu can and will not automagically add
USB Hubs.  This means that:

  (a) You can plug two devices of your choice into the two uhci
      root ports.
  (b) If you want plug in more that two devices you have to care
      about adding a hub yourself.

Plugging a hub works this way:

  -device usb-hub,bus=usb.0,port=1

Use this to add a device to the hub:

  -device usb-tablet,bus=usb.0,port=1.1

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-11 17:27:44 +01:00
Gerd Hoffmann c7a2196a4f usb: keep track of physical port address.
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>
2011-01-11 17:24:42 +01:00
Gerd Hoffmann 25620cba94 usb: add device qualifier support
Add support for device_qualifier and other_speed_config descriptors.
These are used to query the "other speed" configuration of usb 2.0
devices, i.e. in high-speed mode they return the full-speed
configuration and visa versa.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-11 17:15:24 +01:00
Gerd Hoffmann b6f77fbe23 usb: add attach callback
Add handle_attach() callback to USBDeviceInfo which is called by the
generic package handler when the device is attached to the usb bus
(i.e. plugged into a port).

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-11 17:15:24 +01:00
Gerd Hoffmann 843d4e0c63 usb: add speed mask to ports
Add a field to usb ports indicating the speed(s) they are
able to handle.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-11 17:15:23 +01:00
Gerd Hoffmann 01eacab6e9 usb: add usb_wakeup() + wakeup callback to port ops
Add wakeup callback to port ops for remote wakeup handling.
Also add a usb_wakeup() function for devices which want
trigger a remote wakeup.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-11 17:01:02 +01:00
Gerd Hoffmann 618c169b57 usb: rework attach/detach workflow
Add separate detach callback to USBPortOps, split
uhci/ohci/musb/usbhub attach functions into two.

Move common code to the usb_attach() function, only
the hardware-specific bits remain in the attach/detach
callbacks.

Keep track of the port it is attached to for each usb device.

[ v3: fix tyops in usb-musb.c ]

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-11 17:01:02 +01:00
Gerd Hoffmann 0d86d2bebb usb: create USBPortOps, move attach there.
Create USBPortOps struct, move the attach function to that struct.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-11 17:01:02 +01:00
Gerd Hoffmann a980a065fb usb: move USB_REQ_{GET,SET}_CONFIGURATION handling to common code
This patch adds fields to the USBDevice struct for the current
speed (hard-wired to full speed for now) and current device
configuration.  Also a init function is added which inializes
these fields.  This allows USB_REQ_{GET,SET}_CONFIGURATION
handling to be moved to common code.

For most drivers the conversion is trivial ad they support a single
configuration only anyway.  One exception is bluetooth where some
device-specific setup code runs after get/set configuration.  The
other is usb-net which actually has two configurations so the
the code to check for the active configuration has been adapted.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
2011-01-11 15:56:01 +01:00