Skip to contentSkip to conversation

usb patch queue

GIT PULL In review Gerd Hoffmann 3 participants 17 messages Mar 13, 2012 Kbuild

lore
Share & tools
lore
#0 lore raw

Hi,

This pull brings in the bug usb rename, i.e. move all usb emulation source code into hw/usb/. Also UHCI got some love, featuring some cleanups, some small fixes and full tracing support. Beside that it brings the usual bunch of little fixes here and there.

please pull,
Gerd

The following changes since commit cb72b75824c0362e5cb32eb8796930f29fa36d17:

Merge remote-tracking branch 'mdroth/qga-pull-3-12-2012' into staging (2012-03-12 20:52:34 -0500)

are available in the git repository at:

git://git.kraxel.org/qemu usb.44

Benjamin Herrenschmidt (1):
Endian fix an assertion in usb-msd

Gerd Hoffmann (11):
usb: the big rename
usb: zap hw/ush-{ohic,uhci}.h + init wrappers
usb: improve packet state sanity checks
uhci: pass addr to uhci_async_alloc
uhci: fix uhci_async_cancel_all
uhci: cancel on schedule stop.
uhci: tracing support
uhci: use enum for uhci_handle_td return codes
uhci: renumber uhci_handle_td return codes
uhci: new uhci_handle_td return code for tds still in flight
uhci: alloc can't fail, drop check.

Hans de Goede (1):
usb-ehci: drop unused isoch_pause variable

Wei Yang (1):
usb-ohci: DMA writeback bug fixes

 Makefile.objs                                 |   24 ++--
 Makefile.target                               |    2 +-
 configure                                     |    4 +-
 hw/alpha_sys.h                                |    1 -
 hw/mips_fulong2e.c                            |    7 +-
 hw/mips_malta.c                               |    3 +-
 hw/pc_piix.c                                  |    4 +-
 hw/ppc_newworld.c                             |    3 +-
 hw/ppc_oldworld.c                             |    3 +-
 hw/ppc_prep.c                                 |    3 +-
 hw/realview.c                                 |    3 +-
 hw/usb-ohci.h                                 |    9 --
 hw/usb-uhci.h                                 |   10 --
 hw/usb.h                                      |    1 +
 hw/{usb-bus.c => usb/bus.c}                   |    6 +-
 hw/{usb.c => usb/core.c}                      |   39 +++++-
 hw/{usb-desc.c => usb/desc.c}                 |    4 +-
 hw/{usb-desc.h => usb/desc.h}                 |    0
 hw/{usb-audio.c => usb/dev-audio.c}           |    8 +-
 hw/{usb-bt.c => usb/dev-bluetooth.c}          |    6 +-
 hw/{usb-hid.c => usb/dev-hid.c}               |    8 +-
 hw/{usb-hub.c => usb/dev-hub.c}               |    4 +-
 hw/{usb-net.c => usb/dev-network.c}           |    4 +-
 hw/{usb-serial.c => usb/dev-serial.c}         |    4 +-
 hw/{usb-ccid.c => usb/dev-smartcard-reader.c} |    4 +-
 hw/{usb-msd.c => usb/dev-storage.c}           |   12 +-
 hw/{usb-wacom.c => usb/dev-wacom.c}           |    6 +-
 hw/{usb-ehci.c => usb/hcd-ehci.c}             |   12 +--
 hw/{usb-musb.c => usb/hcd-musb.c}             |    6 +-
 hw/{usb-ohci.c => usb/hcd-ohci.c}             |   33 +++--
 hw/{usb-uhci.c => usb/hcd-uhci.c}             |  156 ++++++++++---------------
 hw/{usb-xhci.c => usb/hcd-xhci.c}             |   10 +-
 usb-bsd.c => hw/usb/host-bsd.c                |    0
 usb-linux.c => hw/usb/host-linux.c            |    0
 usb-stub.c => hw/usb/host-stub.c              |    0
 hw/{usb-libhw.c => usb/libhw.c}               |    2 +-
 usb-redir.c => hw/usb/redirect.c              |    0
 hw/versatilepb.c                              |    3 +-
 trace-events                                  |   40 ++++++-
 39 files changed, 226 insertions(+), 218 deletions(-)
 delete mode 100644 hw/usb-ohci.h
 delete mode 100644 hw/usb-uhci.h
 rename hw/{usb-bus.c => usb/bus.c} (99%)
 rename hw/{usb.c => usb/core.c} (95%)
 rename hw/{usb-desc.c => usb/desc.c} (99%)
 rename hw/{usb-desc.h => usb/desc.h} (100%)
 rename hw/{usb-audio.c => usb/dev-audio.c} (99%)
 rename hw/{usb-bt.c => usb/dev-bluetooth.c} (99%)
 rename hw/{usb-hid.c => usb/dev-hid.c} (99%)
 rename hw/{usb-hub.c => usb/dev-hub.c} (99%)
 rename hw/{usb-net.c => usb/dev-network.c} (99%)
 rename hw/{usb-serial.c => usb/dev-serial.c} (99%)
 rename hw/{usb-ccid.c => usb/dev-smartcard-reader.c} (99%)
 rename hw/{usb-msd.c => usb/dev-storage.c} (98%)
 rename hw/{usb-wacom.c => usb/dev-wacom.c} (99%)
 rename hw/{usb-ehci.c => usb/hcd-ehci.c} (99%)
 rename hw/{usb-musb.c => usb/hcd-musb.c} (99%)
 rename hw/{usb-ohci.c => usb/hcd-ohci.c} (98%)
 rename hw/{usb-uhci.c => usb/hcd-uhci.c} (91%)
 rename hw/{usb-xhci.c => usb/hcd-xhci.c} (99%)
 rename usb-bsd.c => hw/usb/host-bsd.c (100%)
 rename usb-linux.c => hw/usb/host-linux.c (100%)
 rename usb-stub.c => hw/usb/host-stub.c (100%)
 rename hw/{usb-libhw.c => usb/libhw.c} (99%)
 rename usb-redir.c => hw/usb/redirect.c (100%)
#1 lore raw

PATCH 1/14 usb: the big rename

Reorganize usb source files. Create a new hw/usb/ directory and move all usb source code to that place. Also make filenames a bit more descriptive. Host adapters are prefixed with "hch-" now, usb device emulations are prefixed with "dev-". Fixup paths Makefile and include paths to make it compile. No code changes.

---
 Makefile.objs                                 |   24 +++++++++++++-----------
 Makefile.target                               |    2 +-
 configure                                     |    4 +++-
 hw/{usb-bus.c => usb/bus.c}                   |    6 +++---
 hw/{usb.c => usb/core.c}                      |    2 +-
 hw/{usb-desc.c => usb/desc.c}                 |    4 ++--
 hw/{usb-desc.h => usb/desc.h}                 |    0
 hw/{usb-audio.c => usb/dev-audio.c}           |    8 ++++----
 hw/{usb-bt.c => usb/dev-bluetooth.c}          |    6 +++---
 hw/{usb-hid.c => usb/dev-hid.c}               |    8 ++++----
 hw/{usb-hub.c => usb/dev-hub.c}               |    4 ++--
 hw/{usb-net.c => usb/dev-network.c}           |    4 ++--
 hw/{usb-serial.c => usb/dev-serial.c}         |    4 ++--
 hw/{usb-ccid.c => usb/dev-smartcard-reader.c} |    4 ++--
 hw/{usb-msd.c => usb/dev-storage.c}           |    6 +++---
 hw/{usb-wacom.c => usb/dev-wacom.c}           |    6 +++---
 hw/{usb-ehci.c => usb/hcd-ehci.c}             |    6 +++---
 hw/{usb-musb.c => usb/hcd-musb.c}             |    6 +++---
 hw/{usb-ohci.c => usb/hcd-ohci.c}             |   12 ++++++------
 hw/{usb-uhci.c => usb/hcd-uhci.c}             |    8 ++++----
 hw/{usb-xhci.c => usb/hcd-xhci.c}             |   10 +++++-----
 usb-bsd.c => hw/usb/host-bsd.c                |    0
 usb-linux.c => hw/usb/host-linux.c            |    0
 usb-stub.c => hw/usb/host-stub.c              |    0
 hw/{usb-libhw.c => usb/libhw.c}               |    2 +-
 usb-redir.c => hw/usb/redirect.c              |    0
 trace-events                                  |    8 ++++----
 27 files changed, 74 insertions(+), 70 deletions(-)
 rename hw/{usb-bus.c => usb/bus.c} (99%)
 rename hw/{usb.c => usb/core.c} (99%)
 rename hw/{usb-desc.c => usb/desc.c} (99%)
 rename hw/{usb-desc.h => usb/desc.h} (100%)
 rename hw/{usb-audio.c => usb/dev-audio.c} (99%)
 rename hw/{usb-bt.c => usb/dev-bluetooth.c} (99%)
 rename hw/{usb-hid.c => usb/dev-hid.c} (99%)
 rename hw/{usb-hub.c => usb/dev-hub.c} (99%)
 rename hw/{usb-net.c => usb/dev-network.c} (99%)
 rename hw/{usb-serial.c => usb/dev-serial.c} (99%)
 rename hw/{usb-ccid.c => usb/dev-smartcard-reader.c} (99%)
 rename hw/{usb-msd.c => usb/dev-storage.c} (99%)
 rename hw/{usb-wacom.c => usb/dev-wacom.c} (99%)
 rename hw/{usb-ehci.c => usb/hcd-ehci.c} (99%)
 rename hw/{usb-musb.c => usb/hcd-musb.c} (99%)
 rename hw/{usb-ohci.c => usb/hcd-ohci.c} (99%)
 rename hw/{usb-uhci.c => usb/hcd-uhci.c} (99%)
 rename hw/{usb-xhci.c => usb/hcd-xhci.c} (99%)
 rename usb-bsd.c => hw/usb/host-bsd.c (100%)
 rename usb-linux.c => hw/usb/host-linux.c (100%)
 rename usb-stub.c => hw/usb/host-stub.c (100%)
 rename hw/{usb-libhw.c => usb/libhw.c} (99%)
 rename usb-redir.c => hw/usb/redirect.c (100%)
Makefile.objs +13 -11
index 5f0b3f7..1eca4a8 100644
@@ -107,13 +107,15 @@ common-obj-y += eeprom93xx.o
 common-obj-y += scsi-disk.o cdrom.o
 common-obj-y += scsi-generic.o scsi-bus.o
 common-obj-y += hid.o
-common-obj-y += usb.o usb-hub.o usb-$(HOST_USB).o usb-hid.o usb-msd.o usb-wacom.o
-common-obj-y += usb-serial.o usb-net.o usb-bus.o usb-desc.o usb-audio.o
+common-obj-y += usb/core.o usb/bus.o usb/desc.o usb/dev-hub.o
+common-obj-y += usb/host-$(HOST_USB).o
+common-obj-y += usb/dev-hid.o usb/dev-storage.o usb/dev-wacom.o
+common-obj-y += usb/dev-serial.o usb/dev-network.o usb/dev-audio.o
 common-obj-$(CONFIG_SSI) += ssi.o
 common-obj-$(CONFIG_SSI_SD) += ssi-sd.o
 common-obj-$(CONFIG_SD) += sd.o
-common-obj-y += bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o usb-bt.o
-common-obj-y += bt-hci-csr.o
+common-obj-y += bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o
+common-obj-y += bt-hci-csr.o usb/dev-bluetooth.o
 common-obj-y += buffered_file.o migration.o migration-tcp.o
 common-obj-y += qemu-char.o #aio.o
 common-obj-y += msmouse.o ps2.o
@@ -194,7 +196,7 @@ user-obj-y += $(trace-obj-y)
 hw-obj-y =
 hw-obj-y += vl.o loader.o
 hw-obj-$(CONFIG_VIRTIO) += virtio-console.o
-hw-obj-y += usb-libhw.o
+hw-obj-y += usb/libhw.o
 hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
 hw-obj-y += fw_cfg.o
 hw-obj-$(CONFIG_PCI) += pci.o pci_bridge.o
@@ -217,10 +219,10 @@ hw-obj-$(CONFIG_PARALLEL) += parallel.o
 hw-obj-$(CONFIG_I8254) += i8254_common.o i8254.o
 hw-obj-$(CONFIG_PCSPK) += pcspk.o
 hw-obj-$(CONFIG_PCKBD) += pckbd.o
-hw-obj-$(CONFIG_USB_UHCI) += usb-uhci.o
-hw-obj-$(CONFIG_USB_OHCI) += usb-ohci.o
-hw-obj-$(CONFIG_USB_EHCI) += usb-ehci.o
-hw-obj-$(CONFIG_USB_XHCI) += usb-xhci.o
+hw-obj-$(CONFIG_USB_UHCI) += usb/hcd-uhci.o
+hw-obj-$(CONFIG_USB_OHCI) += usb/hcd-ohci.o
+hw-obj-$(CONFIG_USB_EHCI) += usb/hcd-ehci.o
+hw-obj-$(CONFIG_USB_XHCI) += usb/hcd-xhci.o
 hw-obj-$(CONFIG_FDC) += fdc.o
 hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o
 hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
@@ -228,9 +230,9 @@ hw-obj-$(CONFIG_DMA) += dma.o
 hw-obj-$(CONFIG_I82374) += i82374.o
 hw-obj-$(CONFIG_HPET) += hpet.o
 hw-obj-$(CONFIG_APPLESMC) += applesmc.o
-hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o
+hw-obj-$(CONFIG_SMARTCARD) += usb/dev-smartcard-reader.o ccid-card-passthru.o
 hw-obj-$(CONFIG_SMARTCARD_NSS) += ccid-card-emulated.o
-hw-obj-$(CONFIG_USB_REDIR) += usb-redir.o
+hw-obj-$(CONFIG_USB_REDIR) += usb/redirect.o
 hw-obj-$(CONFIG_I8259) += i8259_common.o i8259.o
 
 # PPC devices
Makefile.target +1 -1
index 1bd25a8..ed76952 100644
@@ -370,7 +370,7 @@ obj-arm-y += omap1.o omap_lcdc.o omap_dma.o omap_clk.o omap_mmc.o omap_i2c.o \
 obj-arm-y += omap2.o omap_dss.o soc_dma.o omap_gptimer.o omap_synctimer.o \
 		omap_gpmc.o omap_sdrc.o omap_spi.o omap_tap.o omap_l4.o
 obj-arm-y += omap_sx1.o palm.o tsc210x.o
-obj-arm-y += nseries.o blizzard.o onenand.o cbus.o tusb6010.o usb-musb.o
+obj-arm-y += nseries.o blizzard.o onenand.o cbus.o tusb6010.o usb/hcd-musb.o
 obj-arm-y += mst_fpga.o mainstone.o
 obj-arm-y += z2.o
 obj-arm-y += musicpal.o bitbang_i2c.o marvell_88w8618_audio.o
configure +3 -1
index d7631ed..fe4fc4f 100755
@@ -3447,6 +3447,7 @@ mkdir -p $target_dir
 mkdir -p $target_dir/fpu
 mkdir -p $target_dir/tcg
 mkdir -p $target_dir/ide
+mkdir -p $target_dir/usb
 mkdir -p $target_dir/9pfs
 mkdir -p $target_dir/kvm
 if test "$target" = "arm-linux-user" -o "$target" = "armeb-linux-user" -o "$target" = "arm-bsd-user" -o "$target" = "armeb-bsd-user" ; then
@@ -3863,7 +3864,7 @@ done # for target in $targets
 DIRS="tests tests/tcg tests/tcg/cris slirp audio block net pc-bios/optionrom"
 DIRS="$DIRS pc-bios/spapr-rtas"
 DIRS="$DIRS roms/seabios roms/vgabios"
-DIRS="$DIRS fsdev ui"
+DIRS="$DIRS fsdev ui usb"
 DIRS="$DIRS qapi qapi-generated"
 DIRS="$DIRS qga trace qom"
 FILES="Makefile tests/tcg/Makefile qdict-test-data.txt"
@@ -3904,6 +3905,7 @@ for hwlib in 32 64; do
   d=libhw$hwlib
   mkdir -p $d
   mkdir -p $d/ide
+  mkdir -p $d/usb
   symlink $source_path/Makefile.hw $d/Makefile
   mkdir -p $d/9pfs
   echo "QEMU_CFLAGS+=-DTARGET_PHYS_ADDR_BITS=$hwlib" > $d/config.mak
hw/usb/bus.c renamed from hw/usb-bus.c +3 -3
similarity index 99%
rename from hw/usb-bus.c
rename to hw/usb/bus.c
index 70b7ebc..d3f8358 100644
@@ -1,6 +1,6 @@
-#include "hw.h"
-#include "usb.h"
-#include "qdev.h"
+#include "hw/hw.h"
+#include "hw/usb.h"
+#include "hw/qdev.h"
 #include "sysemu.h"
 #include "monitor.h"
 #include "trace.h"
hw/usb/core.c renamed from hw/usb.c +1 -1
similarity index 99%
rename from hw/usb.c
rename to hw/usb/core.c
index 1ec2e90..494989a 100644
@@ -24,7 +24,7 @@
  * THE SOFTWARE.
  */
 #include "qemu-common.h"
-#include "usb.h"
+#include "hw/usb.h"
 #include "iov.h"
 #include "trace.h"
 
hw/usb/desc.c renamed from hw/usb-desc.c +2 -2
similarity index 99%
rename from hw/usb-desc.c
rename to hw/usb/desc.c
index ccf85ad..9847a75 100644
@@ -1,5 +1,5 @@
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
 #include "trace.h"
 
 /* ------------------------------------------------------------------ */
hw/usb/desc.h renamed from hw/usb-desc.h +0 -0
similarity index 100%
rename from hw/usb-desc.h
rename to hw/usb/desc.h
hw/usb/dev-audio.c renamed from hw/usb-audio.c +4 -4
similarity index 99%
rename from hw/usb-audio.c
rename to hw/usb/dev-audio.c
index fed1361..426b95c 100644
@@ -30,10 +30,10 @@
  */
 
 #include "qemu-common.h"
-#include "usb.h"
-#include "usb-desc.h"
-#include "hw.h"
-#include "audiodev.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
+#include "hw/hw.h"
+#include "hw/audiodev.h"
 #include "audio/audio.h"
 
 #define USBAUDIO_VENDOR_NUM     0x46f4 /* CRC16() of "QEMU" */
hw/usb/dev-bluetooth.c renamed from hw/usb-bt.c +3 -3
similarity index 99%
rename from hw/usb-bt.c
rename to hw/usb/dev-bluetooth.c
index 23c39ec..195370c 100644
@@ -19,10 +19,10 @@
  */
 
 #include "qemu-common.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
 #include "net.h"
-#include "bt.h"
+#include "hw/bt.h"
 
 struct USBBtState {
     USBDevice dev;
hw/usb/dev-hid.c renamed from hw/usb-hid.c +4 -4
similarity index 99%
rename from hw/usb-hid.c
rename to hw/usb/dev-hid.c
index 37bca78..f29544d 100644
@@ -22,12 +22,12 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include "hw.h"
+#include "hw/hw.h"
 #include "console.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
 #include "qemu-timer.h"
-#include "hid.h"
+#include "hw/hid.h"
 
 /* HID interface requests */
 #define GET_REPORT   0xa101
hw/usb/dev-hub.c renamed from hw/usb-hub.c +2 -2
similarity index 99%
rename from hw/usb-hub.c
rename to hw/usb/dev-hub.c
index a12856e..eb4e711 100644
@@ -22,8 +22,8 @@
  * THE SOFTWARE.
  */
 #include "qemu-common.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
 
 //#define DEBUG
 
hw/usb/dev-network.c renamed from hw/usb-net.c +2 -2
similarity index 99%
rename from hw/usb-net.c
rename to hw/usb/dev-network.c
index 22b8201..cff55f2 100644
@@ -24,8 +24,8 @@
  */
 
 #include "qemu-common.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
 #include "net.h"
 #include "qemu-queue.h"
 #include "sysemu.h"
hw/usb/dev-serial.c renamed from hw/usb-serial.c +2 -2
similarity index 99%
rename from hw/usb-serial.c
rename to hw/usb/dev-serial.c
index 0aae379..8dcac8b 100644
@@ -10,8 +10,8 @@
 
 #include "qemu-common.h"
 #include "qemu-error.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
 #include "qemu-char.h"
 
 //#define DEBUG_Serial
hw/usb/dev-smartcard-reader.c renamed from hw/usb-ccid.c +2 -2
similarity index 99%
rename from hw/usb-ccid.c
rename to hw/usb/dev-smartcard-reader.c
index ced687f..8e66675 100644
@@ -36,8 +36,8 @@
 
 #include "qemu-common.h"
 #include "qemu-error.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
 #include "monitor.h"
 
 #include "hw/ccid.h"
hw/usb/dev-storage.c renamed from hw/usb-msd.c +3 -3
similarity index 99%
rename from hw/usb-msd.c
rename to hw/usb/dev-storage.c
index c6f08a0..6ffaf70 100644
@@ -10,9 +10,9 @@
 #include "qemu-common.h"
 #include "qemu-option.h"
 #include "qemu-config.h"
-#include "usb.h"
-#include "usb-desc.h"
-#include "scsi.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
+#include "hw/scsi.h"
 #include "console.h"
 #include "monitor.h"
 #include "sysemu.h"
hw/usb/dev-wacom.c renamed from hw/usb-wacom.c +3 -3
similarity index 99%
rename from hw/usb-wacom.c
rename to hw/usb/dev-wacom.c
index 197e2dc..c1cfd74 100644
@@ -25,10 +25,10 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include "hw.h"
+#include "hw/hw.h"
 #include "console.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
 
 /* Interface requests */
 #define WACOM_GET_REPORT	0x2101
hw/usb/hcd-ehci.c renamed from hw/usb-ehci.c +3 -3
similarity index 99%
rename from hw/usb-ehci.c
rename to hw/usb/hcd-ehci.c
index df742f7..58811d3 100644
@@ -22,10 +22,10 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "hw.h"
+#include "hw/hw.h"
 #include "qemu-timer.h"
-#include "usb.h"
-#include "pci.h"
+#include "hw/usb.h"
+#include "hw/pci.h"
 #include "monitor.h"
 #include "trace.h"
 #include "dma.h"
hw/usb/hcd-musb.c renamed from hw/usb-musb.c +3 -3
similarity index 99%
rename from hw/usb-musb.c
rename to hw/usb/hcd-musb.c
index 820907a..fa9385e 100644
@@ -22,9 +22,9 @@
  */
 #include "qemu-common.h"
 #include "qemu-timer.h"
-#include "usb.h"
-#include "irq.h"
-#include "hw.h"
+#include "hw/usb.h"
+#include "hw/irq.h"
+#include "hw/hw.h"
 
 /* Common USB registers */
 #define MUSB_HDRC_FADDR		0x00	/* 8-bit */
hw/usb/hcd-ohci.c renamed from hw/usb-ohci.c +6 -6
similarity index 99%
rename from hw/usb-ohci.c
rename to hw/usb/hcd-ohci.c
index 20aaa74..dd79cef 100644
@@ -26,13 +26,13 @@
  *  o BIOS work to boot from USB storage
 */
 
-#include "hw.h"
+#include "hw/hw.h"
 #include "qemu-timer.h"
-#include "usb.h"
-#include "pci.h"
-#include "usb-ohci.h"
-#include "sysbus.h"
-#include "qdev-addr.h"
+#include "hw/usb.h"
+#include "hw/pci.h"
+#include "hw/usb-ohci.h"
+#include "hw/sysbus.h"
+#include "hw/qdev-addr.h"
 
 //#define DEBUG_OHCI
 /* Dump packet contents.  */
hw/usb/hcd-uhci.c renamed from hw/usb-uhci.c +4 -4
similarity index 99%
rename from hw/usb-uhci.c
rename to hw/usb/hcd-uhci.c
index 304b84b..7c2e9b3 100644
@@ -25,11 +25,11 @@
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  * THE SOFTWARE.
  */
-#include "hw.h"
-#include "usb.h"
-#include "pci.h"
+#include "hw/hw.h"
+#include "hw/usb.h"
+#include "hw/pci.h"
 #include "qemu-timer.h"
-#include "usb-uhci.h"
+#include "hw/usb-uhci.h"
 #include "iov.h"
 #include "dma.h"
 
hw/usb/hcd-xhci.c renamed from hw/usb-xhci.c +5 -5
similarity index 99%
rename from hw/usb-xhci.c
rename to hw/usb/hcd-xhci.c
index e8f1b6e..73b0c7f 100644
@@ -18,12 +18,12 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  */
-#include "hw.h"
+#include "hw/hw.h"
 #include "qemu-timer.h"
-#include "usb.h"
-#include "pci.h"
-#include "qdev-addr.h"
-#include "msi.h"
+#include "hw/usb.h"
+#include "hw/pci.h"
+#include "hw/qdev-addr.h"
+#include "hw/msi.h"
 
 //#define DEBUG_XHCI
 //#define DEBUG_DATA
hw/usb/host-bsd.c renamed from usb-bsd.c +0 -0
similarity index 100%
rename from usb-bsd.c
rename to hw/usb/host-bsd.c
hw/usb/host-linux.c renamed from usb-linux.c +0 -0
similarity index 100%
rename from usb-linux.c
rename to hw/usb/host-linux.c
hw/usb/host-stub.c renamed from usb-stub.c +0 -0
similarity index 100%
rename from usb-stub.c
rename to hw/usb/host-stub.c
hw/usb/libhw.c renamed from hw/usb-libhw.c +1 -1
similarity index 99%
rename from hw/usb-libhw.c
rename to hw/usb/libhw.c
index 162b42b..2462351 100644
@@ -21,7 +21,7 @@
  */
 #include "qemu-common.h"
 #include "cpu-common.h"
-#include "usb.h"
+#include "hw/usb.h"
 #include "dma.h"
 
 int usb_packet_map(USBPacket *p, QEMUSGList *sgl)
hw/usb/redirect.c renamed from usb-redir.c +0 -0
similarity index 100%
rename from usb-redir.c
rename to hw/usb/redirect.c
trace-events +4 -4
index 74bb92a..bcfe13a 100644
@@ -227,16 +227,16 @@ sun4m_iommu_page_get_flags(uint64_t pa, uint64_t iopte, uint32_t ret) "get flags
 sun4m_iommu_translate_pa(uint64_t addr, uint64_t pa, uint32_t iopte) "xlate dva %"PRIx64" => pa %"PRIx64" iopte = %x"
 sun4m_iommu_bad_addr(uint64_t addr) "bad addr %"PRIx64
 
-# hw/usb.c
+# hw/usb/core.c
 usb_packet_state_change(int bus, const char *port, int ep, void *p, const char *o, const char *n) "bus %d, port %s, ep %d, packet %p, state %s -> %s"
 
-# hw/usb-bus.c
+# hw/usb/bus.c
 usb_port_claim(int bus, const char *port) "bus %d, port %s"
 usb_port_attach(int bus, const char *port) "bus %d, port %s"
 usb_port_detach(int bus, const char *port) "bus %d, port %s"
 usb_port_release(int bus, const char *port) "bus %d, port %s"
 
-# hw/usb-ehci.c
+# hw/usb/hcd-ehci.c
 usb_ehci_reset(void) "=== RESET ==="
 usb_ehci_mmio_readl(uint32_t addr, const char *str, uint32_t val) "rd mmio %04x [%s] = %x"
 usb_ehci_mmio_writel(uint32_t addr, const char *str, uint32_t val) "wr mmio %04x [%s] = %x"
@@ -269,7 +269,7 @@ usb_set_interface(int addr, int iface, int alt, int ret) "dev %d, interface %d,
 usb_clear_device_feature(int addr, int feature, int ret) "dev %d, feature %d, ret %d"
 usb_set_device_feature(int addr, int feature, int ret) "dev %d, feature %d, ret %d"
 
-# usb-linux.c
+# hw/usb/host-linux.c
 usb_host_open_started(int bus, int addr) "dev %d:%d"
 usb_host_open_success(int bus, int addr) "dev %d:%d"
 usb_host_open_failure(int bus, int addr) "dev %d:%d"
Signature · 1 line
1.7.1
#2 lore raw

Re: [Qemu-devel] [PATCH 01/14] usb: the big rename

Hi,

Quoted 3 lines · Gerd Hoffmann

Reorganize usb source files. Create a new hw/usb/ directory and move all usb source code to that place. Also make filenames a bit more descriptive. Host adapters are prefixed with "hch-" now,

2 small nitpicks here:
1) The commit message says hch, but the actual renames are to hcd
2) hcd is used a lot in USB spec documents and stands for host controller driver, which is a part of the guest usb stack, so I'm not sure if that is a good prefix to choose. May I suggest using simply hc instead?

Regards,

Hans

usb device

Quoted 572 lines

emulations are prefixed with "dev-". Fixup paths Makefile and include paths to make it compile. No code changes.

---
  Makefile.objs                                 |   24 +++++++++++++-----------
  Makefile.target                               |    2 +-
  configure                                     |    4 +++-
  hw/{usb-bus.c =>  usb/bus.c}                   |    6 +++---
  hw/{usb.c =>  usb/core.c}                      |    2 +-
  hw/{usb-desc.c =>  usb/desc.c}                 |    4 ++--
  hw/{usb-desc.h =>  usb/desc.h}                 |    0
  hw/{usb-audio.c =>  usb/dev-audio.c}           |    8 ++++----
  hw/{usb-bt.c =>  usb/dev-bluetooth.c}          |    6 +++---
  hw/{usb-hid.c =>  usb/dev-hid.c}               |    8 ++++----
  hw/{usb-hub.c =>  usb/dev-hub.c}               |    4 ++--
  hw/{usb-net.c =>  usb/dev-network.c}           |    4 ++--
  hw/{usb-serial.c =>  usb/dev-serial.c}         |    4 ++--
  hw/{usb-ccid.c =>  usb/dev-smartcard-reader.c} |    4 ++--
  hw/{usb-msd.c =>  usb/dev-storage.c}           |    6 +++---
  hw/{usb-wacom.c =>  usb/dev-wacom.c}           |    6 +++---
  hw/{usb-ehci.c =>  usb/hcd-ehci.c}             |    6 +++---
  hw/{usb-musb.c =>  usb/hcd-musb.c}             |    6 +++---
  hw/{usb-ohci.c =>  usb/hcd-ohci.c}             |   12 ++++++------
  hw/{usb-uhci.c =>  usb/hcd-uhci.c}             |    8 ++++----
  hw/{usb-xhci.c =>  usb/hcd-xhci.c}             |   10 +++++-----
  usb-bsd.c =>  hw/usb/host-bsd.c                |    0
  usb-linux.c =>  hw/usb/host-linux.c            |    0
  usb-stub.c =>  hw/usb/host-stub.c              |    0
  hw/{usb-libhw.c =>  usb/libhw.c}               |    2 +-
  usb-redir.c =>  hw/usb/redirect.c              |    0
  trace-events                                  |    8 ++++----
  27 files changed, 74 insertions(+), 70 deletions(-)
  rename hw/{usb-bus.c =>  usb/bus.c} (99%)
  rename hw/{usb.c =>  usb/core.c} (99%)
  rename hw/{usb-desc.c =>  usb/desc.c} (99%)
  rename hw/{usb-desc.h =>  usb/desc.h} (100%)
  rename hw/{usb-audio.c =>  usb/dev-audio.c} (99%)
  rename hw/{usb-bt.c =>  usb/dev-bluetooth.c} (99%)
  rename hw/{usb-hid.c =>  usb/dev-hid.c} (99%)
  rename hw/{usb-hub.c =>  usb/dev-hub.c} (99%)
  rename hw/{usb-net.c =>  usb/dev-network.c} (99%)
  rename hw/{usb-serial.c =>  usb/dev-serial.c} (99%)
  rename hw/{usb-ccid.c =>  usb/dev-smartcard-reader.c} (99%)
  rename hw/{usb-msd.c =>  usb/dev-storage.c} (99%)
  rename hw/{usb-wacom.c =>  usb/dev-wacom.c} (99%)
  rename hw/{usb-ehci.c =>  usb/hcd-ehci.c} (99%)
  rename hw/{usb-musb.c =>  usb/hcd-musb.c} (99%)
  rename hw/{usb-ohci.c =>  usb/hcd-ohci.c} (99%)
  rename hw/{usb-uhci.c =>  usb/hcd-uhci.c} (99%)
  rename hw/{usb-xhci.c =>  usb/hcd-xhci.c} (99%)

rename usb-bsd.c => hw/usb/host-bsd.c (100%) rename usb-linux.c => hw/usb/host-linux.c (100%) rename usb-stub.c => hw/usb/host-stub.c (100%) rename hw/{usb-libhw.c => usb/libhw.c} (99%) rename usb-redir.c => hw/usb/redirect.c (100%)

Makefile.objs +13 -11
index 5f0b3f7..1eca4a8 100644
@@ -107,13 +107,15 @@ common-obj-y += eeprom93xx.o
  common-obj-y += scsi-disk.o cdrom.o
  common-obj-y += scsi-generic.o scsi-bus.o
  common-obj-y += hid.o
-common-obj-y += usb.o usb-hub.o usb-$(HOST_USB).o usb-hid.o usb-msd.o usb-wacom.o
-common-obj-y += usb-serial.o usb-net.o usb-bus.o usb-desc.o usb-audio.o
+common-obj-y += usb/core.o usb/bus.o usb/desc.o usb/dev-hub.o
+common-obj-y += usb/host-$(HOST_USB).o
+common-obj-y += usb/dev-hid.o usb/dev-storage.o usb/dev-wacom.o
+common-obj-y += usb/dev-serial.o usb/dev-network.o usb/dev-audio.o
  common-obj-$(CONFIG_SSI) += ssi.o
  common-obj-$(CONFIG_SSI_SD) += ssi-sd.o
  common-obj-$(CONFIG_SD) += sd.o
-common-obj-y += bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o usb-bt.o
-common-obj-y += bt-hci-csr.o
+common-obj-y += bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o
+common-obj-y += bt-hci-csr.o usb/dev-bluetooth.o
  common-obj-y += buffered_file.o migration.o migration-tcp.o
  common-obj-y += qemu-char.o #aio.o
  common-obj-y += msmouse.o ps2.o
@@ -194,7 +196,7 @@ user-obj-y += $(trace-obj-y)
  hw-obj-y =
  hw-obj-y += vl.o loader.o
  hw-obj-$(CONFIG_VIRTIO) += virtio-console.o
-hw-obj-y += usb-libhw.o
+hw-obj-y += usb/libhw.o
  hw-obj-$(CONFIG_VIRTIO_PCI) += virtio-pci.o
  hw-obj-y += fw_cfg.o
  hw-obj-$(CONFIG_PCI) += pci.o pci_bridge.o
@@ -217,10 +219,10 @@ hw-obj-$(CONFIG_PARALLEL) += parallel.o
  hw-obj-$(CONFIG_I8254) += i8254_common.o i8254.o
  hw-obj-$(CONFIG_PCSPK) += pcspk.o
  hw-obj-$(CONFIG_PCKBD) += pckbd.o
-hw-obj-$(CONFIG_USB_UHCI) += usb-uhci.o
-hw-obj-$(CONFIG_USB_OHCI) += usb-ohci.o
-hw-obj-$(CONFIG_USB_EHCI) += usb-ehci.o
-hw-obj-$(CONFIG_USB_XHCI) += usb-xhci.o
+hw-obj-$(CONFIG_USB_UHCI) += usb/hcd-uhci.o
+hw-obj-$(CONFIG_USB_OHCI) += usb/hcd-ohci.o
+hw-obj-$(CONFIG_USB_EHCI) += usb/hcd-ehci.o
+hw-obj-$(CONFIG_USB_XHCI) += usb/hcd-xhci.o
  hw-obj-$(CONFIG_FDC) += fdc.o
  hw-obj-$(CONFIG_ACPI) += acpi.o acpi_piix4.o
  hw-obj-$(CONFIG_APM) += pm_smbus.o apm.o
@@ -228,9 +230,9 @@ hw-obj-$(CONFIG_DMA) += dma.o
  hw-obj-$(CONFIG_I82374) += i82374.o
  hw-obj-$(CONFIG_HPET) += hpet.o
  hw-obj-$(CONFIG_APPLESMC) += applesmc.o
-hw-obj-$(CONFIG_SMARTCARD) += usb-ccid.o ccid-card-passthru.o
+hw-obj-$(CONFIG_SMARTCARD) += usb/dev-smartcard-reader.o ccid-card-passthru.o
  hw-obj-$(CONFIG_SMARTCARD_NSS) += ccid-card-emulated.o
-hw-obj-$(CONFIG_USB_REDIR) += usb-redir.o
+hw-obj-$(CONFIG_USB_REDIR) += usb/redirect.o
  hw-obj-$(CONFIG_I8259) += i8259_common.o i8259.o
 
  # PPC devices
Makefile.target +1 -1
index 1bd25a8..ed76952 100644
@@ -370,7 +370,7 @@ obj-arm-y += omap1.o omap_lcdc.o omap_dma.o omap_clk.o omap_mmc.o omap_i2c.o \
  obj-arm-y += omap2.o omap_dss.o soc_dma.o omap_gptimer.o omap_synctimer.o \
  		omap_gpmc.o omap_sdrc.o omap_spi.o omap_tap.o omap_l4.o
  obj-arm-y += omap_sx1.o palm.o tsc210x.o
-obj-arm-y += nseries.o blizzard.o onenand.o cbus.o tusb6010.o usb-musb.o
+obj-arm-y += nseries.o blizzard.o onenand.o cbus.o tusb6010.o usb/hcd-musb.o
  obj-arm-y += mst_fpga.o mainstone.o
  obj-arm-y += z2.o
  obj-arm-y += musicpal.o bitbang_i2c.o marvell_88w8618_audio.o
configure +3 -1
index d7631ed..fe4fc4f 100755
@@ -3447,6 +3447,7 @@ mkdir -p $target_dir
  mkdir -p $target_dir/fpu
  mkdir -p $target_dir/tcg
  mkdir -p $target_dir/ide
+mkdir -p $target_dir/usb
  mkdir -p $target_dir/9pfs
  mkdir -p $target_dir/kvm
  if test "$target" = "arm-linux-user" -o "$target" = "armeb-linux-user" -o "$target" = "arm-bsd-user" -o "$target" = "armeb-bsd-user" ; then
@@ -3863,7 +3864,7 @@ done # for target in $targets
  DIRS="tests tests/tcg tests/tcg/cris slirp audio block net pc-bios/optionrom"
  DIRS="$DIRS pc-bios/spapr-rtas"
  DIRS="$DIRS roms/seabios roms/vgabios"
-DIRS="$DIRS fsdev ui"
+DIRS="$DIRS fsdev ui usb"
  DIRS="$DIRS qapi qapi-generated"
  DIRS="$DIRS qga trace qom"
  FILES="Makefile tests/tcg/Makefile qdict-test-data.txt"
@@ -3904,6 +3905,7 @@ for hwlib in 32 64; do
    d=libhw$hwlib
    mkdir -p $d
    mkdir -p $d/ide
+  mkdir -p $d/usb
    symlink $source_path/Makefile.hw $d/Makefile
    mkdir -p $d/9pfs
    echo "QEMU_CFLAGS+=-DTARGET_PHYS_ADDR_BITS=$hwlib">  $d/config.mak
hw/usb/bus.c renamed from hw/usb-bus.c +3 -3
similarity index 99%
rename from hw/usb-bus.c
rename to hw/usb/bus.c
index 70b7ebc..d3f8358 100644
@@ -1,6 +1,6 @@
-#include "hw.h"
-#include "usb.h"
-#include "qdev.h"
+#include "hw/hw.h"
+#include "hw/usb.h"
+#include "hw/qdev.h"
  #include "sysemu.h"
  #include "monitor.h"
  #include "trace.h"
hw/usb/core.c renamed from hw/usb.c +1 -1
similarity index 99%
rename from hw/usb.c
rename to hw/usb/core.c
index 1ec2e90..494989a 100644
@@ -24,7 +24,7 @@
   * THE SOFTWARE.
   */
  #include "qemu-common.h"
-#include "usb.h"
+#include "hw/usb.h"
  #include "iov.h"
  #include "trace.h"
 
hw/usb/desc.c renamed from hw/usb-desc.c +2 -2
similarity index 99%
rename from hw/usb-desc.c
rename to hw/usb/desc.c
index ccf85ad..9847a75 100644
@@ -1,5 +1,5 @@
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
  #include "trace.h"
 
  /* ------------------------------------------------------------------ */
hw/usb/desc.h renamed from hw/usb-desc.h +0 -0
similarity index 100%
rename from hw/usb-desc.h
rename to hw/usb/desc.h
hw/usb/dev-audio.c renamed from hw/usb-audio.c +4 -4
similarity index 99%
rename from hw/usb-audio.c
rename to hw/usb/dev-audio.c
index fed1361..426b95c 100644
@@ -30,10 +30,10 @@
   */
 
  #include "qemu-common.h"
-#include "usb.h"
-#include "usb-desc.h"
-#include "hw.h"
-#include "audiodev.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
+#include "hw/hw.h"
+#include "hw/audiodev.h"
  #include "audio/audio.h"
 
  #define USBAUDIO_VENDOR_NUM     0x46f4 /* CRC16() of "QEMU" */
hw/usb/dev-bluetooth.c renamed from hw/usb-bt.c +3 -3
similarity index 99%
rename from hw/usb-bt.c
rename to hw/usb/dev-bluetooth.c
index 23c39ec..195370c 100644
@@ -19,10 +19,10 @@
   */
 
  #include "qemu-common.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
  #include "net.h"
-#include "bt.h"
+#include "hw/bt.h"
 
  struct USBBtState {
      USBDevice dev;
hw/usb/dev-hid.c renamed from hw/usb-hid.c +4 -4
similarity index 99%
rename from hw/usb-hid.c
rename to hw/usb/dev-hid.c
index 37bca78..f29544d 100644
@@ -22,12 +22,12 @@
   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   * THE SOFTWARE.
   */
-#include "hw.h"
+#include "hw/hw.h"
  #include "console.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
  #include "qemu-timer.h"
-#include "hid.h"
+#include "hw/hid.h"
 
  /* HID interface requests */
  #define GET_REPORT   0xa101
hw/usb/dev-hub.c renamed from hw/usb-hub.c +2 -2
similarity index 99%
rename from hw/usb-hub.c
rename to hw/usb/dev-hub.c
index a12856e..eb4e711 100644
@@ -22,8 +22,8 @@
   * THE SOFTWARE.
   */
  #include "qemu-common.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
 
  //#define DEBUG
 
hw/usb/dev-network.c renamed from hw/usb-net.c +2 -2
similarity index 99%
rename from hw/usb-net.c
rename to hw/usb/dev-network.c
index 22b8201..cff55f2 100644
@@ -24,8 +24,8 @@
   */
 
  #include "qemu-common.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
  #include "net.h"
  #include "qemu-queue.h"
  #include "sysemu.h"
hw/usb/dev-serial.c renamed from hw/usb-serial.c +2 -2
similarity index 99%
rename from hw/usb-serial.c
rename to hw/usb/dev-serial.c
index 0aae379..8dcac8b 100644
@@ -10,8 +10,8 @@
 
  #include "qemu-common.h"
  #include "qemu-error.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
  #include "qemu-char.h"
 
  //#define DEBUG_Serial
hw/usb/dev-smartcard-reader.c renamed from hw/usb-ccid.c +2 -2
similarity index 99%
rename from hw/usb-ccid.c
rename to hw/usb/dev-smartcard-reader.c
index ced687f..8e66675 100644
@@ -36,8 +36,8 @@
 
  #include "qemu-common.h"
  #include "qemu-error.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
  #include "monitor.h"
 
  #include "hw/ccid.h"
hw/usb/dev-storage.c renamed from hw/usb-msd.c +3 -3
similarity index 99%
rename from hw/usb-msd.c
rename to hw/usb/dev-storage.c
index c6f08a0..6ffaf70 100644
@@ -10,9 +10,9 @@
  #include "qemu-common.h"
  #include "qemu-option.h"
  #include "qemu-config.h"
-#include "usb.h"
-#include "usb-desc.h"
-#include "scsi.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
+#include "hw/scsi.h"
  #include "console.h"
  #include "monitor.h"
  #include "sysemu.h"
hw/usb/dev-wacom.c renamed from hw/usb-wacom.c +3 -3
similarity index 99%
rename from hw/usb-wacom.c
rename to hw/usb/dev-wacom.c
index 197e2dc..c1cfd74 100644
@@ -25,10 +25,10 @@
   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   * THE SOFTWARE.
   */
-#include "hw.h"
+#include "hw/hw.h"
  #include "console.h"
-#include "usb.h"
-#include "usb-desc.h"
+#include "hw/usb.h"
+#include "hw/usb/desc.h"
 
  /* Interface requests */
  #define WACOM_GET_REPORT	0x2101
hw/usb/hcd-ehci.c renamed from hw/usb-ehci.c +3 -3
similarity index 99%
rename from hw/usb-ehci.c
rename to hw/usb/hcd-ehci.c
index df742f7..58811d3 100644
@@ -22,10 +22,10 @@
   * along with this program; if not, see<http://www.gnu.org/licenses/>.
   */
 
-#include "hw.h"
+#include "hw/hw.h"
  #include "qemu-timer.h"
-#include "usb.h"
-#include "pci.h"
+#include "hw/usb.h"
+#include "hw/pci.h"
  #include "monitor.h"
  #include "trace.h"
  #include "dma.h"
hw/usb/hcd-musb.c renamed from hw/usb-musb.c +3 -3
similarity index 99%
rename from hw/usb-musb.c
rename to hw/usb/hcd-musb.c
index 820907a..fa9385e 100644
@@ -22,9 +22,9 @@
   */
  #include "qemu-common.h"
  #include "qemu-timer.h"
-#include "usb.h"
-#include "irq.h"
-#include "hw.h"
+#include "hw/usb.h"
+#include "hw/irq.h"
+#include "hw/hw.h"
 
  /* Common USB registers */
  #define MUSB_HDRC_FADDR		0x00	/* 8-bit */
hw/usb/hcd-ohci.c renamed from hw/usb-ohci.c +6 -6
similarity index 99%
rename from hw/usb-ohci.c
rename to hw/usb/hcd-ohci.c
index 20aaa74..dd79cef 100644
@@ -26,13 +26,13 @@
   *  o BIOS work to boot from USB storage
  */
 
-#include "hw.h"
+#include "hw/hw.h"
  #include "qemu-timer.h"
-#include "usb.h"
-#include "pci.h"
-#include "usb-ohci.h"
-#include "sysbus.h"
-#include "qdev-addr.h"
+#include "hw/usb.h"
+#include "hw/pci.h"
+#include "hw/usb-ohci.h"
+#include "hw/sysbus.h"
+#include "hw/qdev-addr.h"
 
  //#define DEBUG_OHCI
  /* Dump packet contents.  */
hw/usb/hcd-uhci.c renamed from hw/usb-uhci.c +4 -4
similarity index 99%
rename from hw/usb-uhci.c
rename to hw/usb/hcd-uhci.c
index 304b84b..7c2e9b3 100644
@@ -25,11 +25,11 @@
   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
   * THE SOFTWARE.
   */
-#include "hw.h"
-#include "usb.h"
-#include "pci.h"
+#include "hw/hw.h"
+#include "hw/usb.h"
+#include "hw/pci.h"
  #include "qemu-timer.h"
-#include "usb-uhci.h"
+#include "hw/usb-uhci.h"
  #include "iov.h"
  #include "dma.h"
 
hw/usb/hcd-xhci.c renamed from hw/usb-xhci.c +5 -5
similarity index 99%
rename from hw/usb-xhci.c
rename to hw/usb/hcd-xhci.c
index e8f1b6e..73b0c7f 100644
@@ -18,12 +18,12 @@
   * You should have received a copy of the GNU Lesser General Public
   * License along with this library; if not, see<http://www.gnu.org/licenses/>.
   */
-#include "hw.h"
+#include "hw/hw.h"
  #include "qemu-timer.h"
-#include "usb.h"
-#include "pci.h"
-#include "qdev-addr.h"
-#include "msi.h"
+#include "hw/usb.h"
+#include "hw/pci.h"
+#include "hw/qdev-addr.h"
+#include "hw/msi.h"
 
  //#define DEBUG_XHCI
  //#define DEBUG_DATA
hw/usb/host-bsd.c renamed from usb-bsd.c +0 -0
similarity index 100%
rename from usb-bsd.c
rename to hw/usb/host-bsd.c
hw/usb/host-linux.c renamed from usb-linux.c +0 -0
similarity index 100%
rename from usb-linux.c
rename to hw/usb/host-linux.c
hw/usb/host-stub.c renamed from usb-stub.c +0 -0
similarity index 100%
rename from usb-stub.c
rename to hw/usb/host-stub.c
hw/usb/libhw.c renamed from hw/usb-libhw.c +1 -1
similarity index 99%
rename from hw/usb-libhw.c
rename to hw/usb/libhw.c
index 162b42b..2462351 100644
@@ -21,7 +21,7 @@
   */
  #include "qemu-common.h"
  #include "cpu-common.h"
-#include "usb.h"
+#include "hw/usb.h"
  #include "dma.h"
 
  int usb_packet_map(USBPacket *p, QEMUSGList *sgl)
hw/usb/redirect.c renamed from usb-redir.c +0 -0
similarity index 100%
rename from usb-redir.c
rename to hw/usb/redirect.c
trace-events +4 -4
index 74bb92a..bcfe13a 100644
@@ -227,16 +227,16 @@ sun4m_iommu_page_get_flags(uint64_t pa, uint64_t iopte, uint32_t ret) "get flags
  sun4m_iommu_translate_pa(uint64_t addr, uint64_t pa, uint32_t iopte) "xlate dva %"PRIx64" =>  pa %"PRIx64" iopte = %x"
  sun4m_iommu_bad_addr(uint64_t addr) "bad addr %"PRIx64
 
-# hw/usb.c
+# hw/usb/core.c
  usb_packet_state_change(int bus, const char *port, int ep, void *p, const char *o, const char *n) "bus %d, port %s, ep %d, packet %p, state %s ->  %s"
 
-# hw/usb-bus.c
+# hw/usb/bus.c
  usb_port_claim(int bus, const char *port) "bus %d, port %s"
  usb_port_attach(int bus, const char *port) "bus %d, port %s"
  usb_port_detach(int bus, const char *port) "bus %d, port %s"
  usb_port_release(int bus, const char *port) "bus %d, port %s"
 
-# hw/usb-ehci.c
+# hw/usb/hcd-ehci.c
  usb_ehci_reset(void) "=== RESET ==="
  usb_ehci_mmio_readl(uint32_t addr, const char *str, uint32_t val) "rd mmio %04x [%s] = %x"
  usb_ehci_mmio_writel(uint32_t addr, const char *str, uint32_t val) "wr mmio %04x [%s] = %x"
@@ -269,7 +269,7 @@ usb_set_interface(int addr, int iface, int alt, int ret) "dev %d, interface %d,
  usb_clear_device_feature(int addr, int feature, int ret) "dev %d, feature %d, ret %d"
  usb_set_device_feature(int addr, int feature, int ret) "dev %d, feature %d, ret %d"
 
-# usb-linux.c
+# hw/usb/host-linux.c
  usb_host_open_started(int bus, int addr) "dev %d:%d"
  usb_host_open_success(int bus, int addr) "dev %d:%d"
  usb_host_open_failure(int bus, int addr) "dev %d:%d"
#3 lore raw

PATCH 2/14 usb: zap hw/ush-{ohic, uhci}.h + init wrappers

In reply to Gerd Hoffmann

Remove the uhci and ohci init wrappers, which all wrapped a pci_create_simple() one-liner. Switch callsites to call pci_create_simple directly. Remove the header files where the wrappers where declared.

---
 hw/alpha_sys.h     |    1 -
 hw/mips_fulong2e.c |    7 ++++---
 hw/mips_malta.c    |    3 +--
 hw/pc_piix.c       |    4 +---
 hw/ppc_newworld.c  |    3 +--
 hw/ppc_oldworld.c  |    3 +--
 hw/ppc_prep.c      |    3 +--
 hw/realview.c      |    3 +--
 hw/usb-ohci.h      |    9 ---------
 hw/usb-uhci.h      |   10 ----------
 hw/usb/hcd-ohci.c  |    6 ------
 hw/usb/hcd-uhci.c  |   16 ----------------
 hw/versatilepb.c   |    3 +--
 13 files changed, 11 insertions(+), 60 deletions(-)
 delete mode 100644 hw/usb-ohci.h
 delete mode 100644 hw/usb-uhci.h
hw/alpha_sys.h +0 -1
index d54b18f..f9506c6 100644
@@ -8,7 +8,6 @@
 #include "ide.h"
 #include "net.h"
 #include "pc.h"
-#include "usb-ohci.h"
 #include "irq.h"
 
 
hw/mips_fulong2e.c +4 -3
index e3ba9dd..efdfdc2 100644
@@ -29,7 +29,6 @@
 #include "mips.h"
 #include "mips_cpudevs.h"
 #include "pci.h"
-#include "usb-uhci.h"
 #include "qemu-char.h"
 #include "sysemu.h"
 #include "audio/audio.h"
@@ -355,8 +354,10 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
     isa_bus_irqs(isa_bus, i8259);
 
     vt82c686b_ide_init(pci_bus, hd, PCI_DEVFN(FULONG2E_VIA_SLOT, 1));
-    usb_uhci_vt82c686b_init(pci_bus, PCI_DEVFN(FULONG2E_VIA_SLOT, 2));
-    usb_uhci_vt82c686b_init(pci_bus, PCI_DEVFN(FULONG2E_VIA_SLOT, 3));
+    pci_create_simple(pci_bus, PCI_DEVFN(FULONG2E_VIA_SLOT, 2),
+                      "vt82c686b-usb-uhci");
+    pci_create_simple(pci_bus, PCI_DEVFN(FULONG2E_VIA_SLOT, 3),
+                      "vt82c686b-usb-uhci");
 
     smbus = vt82c686b_pm_init(pci_bus, PCI_DEVFN(FULONG2E_VIA_SLOT, 4),
                               0xeee1, NULL);
hw/mips_malta.c +1 -2
index b1563ed..866699d 100644
@@ -33,7 +33,6 @@
 #include "mips.h"
 #include "mips_cpudevs.h"
 #include "pci.h"
-#include "usb-uhci.h"
 #include "vmware_vga.h"
 #include "qemu-char.h"
 #include "sysemu.h"
@@ -965,7 +964,7 @@ void mips_malta_init (ram_addr_t ram_size,
 
     isa_bus_irqs(isa_bus, s->i8259);
     pci_piix4_ide_init(pci_bus, hd, piix4_devfn + 1);
-    usb_uhci_piix4_init(pci_bus, piix4_devfn + 2);
+    pci_create_simple(pci_bus, piix4_devfn + 2, "piix4-usb-uhci");
     smbus = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100,
                           isa_get_irq(NULL, 9), NULL, 0);
     /* TODO: Populate SPD eeprom data.  */
hw/pc_piix.c +1 -3
index 6c5c40f..3f99f9a 100644
@@ -28,8 +28,6 @@
 #include "pc.h"
 #include "apic.h"
 #include "pci.h"
-#include "usb-uhci.h"
-#include "usb-ohci.h"
 #include "net.h"
 #include "boards.h"
 #include "ide.h"
@@ -284,7 +282,7 @@ static void pc_init1(MemoryRegion *system_memory,
                  floppy, idebus[0], idebus[1], rtc_state);
 
     if (pci_enabled && usb_enabled) {
-        usb_uhci_piix3_init(pci_bus, piix3_devfn + 2);
+        pci_create_simple(pci_bus, piix3_devfn + 2, "piix3-usb-uhci");
     }
 
     if (pci_enabled && acpi_enabled) {
hw/ppc_newworld.c +1 -2
index 506187b..2fec5b4 100644
@@ -54,7 +54,6 @@
 #include "nvram.h"
 #include "pc.h"
 #include "pci.h"
-#include "usb-ohci.h"
 #include "net.h"
 #include "sysemu.h"
 #include "boards.h"
@@ -352,7 +351,7 @@ static void ppc_core99_init (ram_addr_t ram_size,
                dbdma_mem, cuda_mem, NULL, 3, ide_mem, escc_bar);
 
     if (usb_enabled) {
-        usb_ohci_init_pci(pci_bus, -1);
+        pci_create_simple(pci_bus, -1, "pci-ohci");
     }
 
     /* U3 needs to use USB for input because Linux doesn't support via-cuda
hw/ppc_oldworld.c +1 -2
index 9295a34..49c2c97 100644
@@ -34,7 +34,6 @@
 #include "net.h"
 #include "isa.h"
 #include "pci.h"
-#include "usb-ohci.h"
 #include "boards.h"
 #include "fw_cfg.h"
 #include "escc.h"
@@ -278,7 +277,7 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
                dbdma_mem, cuda_mem, nvr, 2, ide_mem, escc_bar);
 
     if (usb_enabled) {
-        usb_ohci_init_pci(pci_bus, -1);
+        pci_create_simple(pci_bus, -1, "pci-ohci");
     }
 
     if (graphic_depth != 15 && graphic_depth != 32 && graphic_depth != 8)
hw/ppc_prep.c +1 -2
index eb43fb5..dc9edd7 100644
@@ -30,7 +30,6 @@
 #include "isa.h"
 #include "pci.h"
 #include "pci_host.h"
-#include "usb-ohci.h"
 #include "ppc.h"
 #include "boards.h"
 #include "qemu-log.h"
@@ -688,7 +687,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
 #endif
 
     if (usb_enabled) {
-        usb_ohci_init_pci(pci_bus, -1);
+        pci_create_simple(pci_bus, -1, "pci-ohci");
     }
 
     m48t59 = m48t59_init_isa(isa_bus, 0x0074, NVRAM_SIZE, 59);
hw/realview.c +1 -2
index ae1bbcd..50ea67c 100644
@@ -12,7 +12,6 @@
 #include "primecell.h"
 #include "devices.h"
 #include "pci.h"
-#include "usb-ohci.h"
 #include "net.h"
 #include "sysemu.h"
 #include "boards.h"
@@ -305,7 +304,7 @@ static void realview_init(ram_addr_t ram_size,
         sysbus_connect_irq(busdev, 3, pic[51]);
         pci_bus = (PCIBus *)qdev_get_child_bus(dev, "pci");
         if (usb_enabled) {
-            usb_ohci_init_pci(pci_bus, -1);
+            pci_create_simple(pci_bus, -1, "pci-ohci");
         }
         n = drive_get_max_bus(IF_SCSI);
         while (n >= 0) {
hw/usb-ohci.h deleted +0 -9
deleted file mode 100644
index eefcef3..0000000
@@ -1,9 +0,0 @@
-#ifndef QEMU_USB_OHCI_H
-#define QEMU_USB_OHCI_H
-
-#include "qemu-common.h"
-
-void usb_ohci_init_pci(struct PCIBus *bus, int devfn);
-
-#endif
-
hw/usb-uhci.h deleted +0 -10
deleted file mode 100644
index 3e4d377..0000000
@@ -1,10 +0,0 @@
-#ifndef QEMU_USB_UHCI_H
-#define QEMU_USB_UHCI_H
-
-#include "qemu-common.h"
-
-void usb_uhci_piix3_init(PCIBus *bus, int devfn);
-void usb_uhci_piix4_init(PCIBus *bus, int devfn);
-void usb_uhci_vt82c686b_init(PCIBus *bus, int devfn);
-
-#endif
hw/usb/hcd-ohci.c +0 -6
index dd79cef..51fa111 100644
@@ -30,7 +30,6 @@
 #include "qemu-timer.h"
 #include "hw/usb.h"
 #include "hw/pci.h"
-#include "hw/usb-ohci.h"
 #include "hw/sysbus.h"
 #include "hw/qdev-addr.h"
 
@@ -1815,11 +1814,6 @@ static int usb_ohci_initfn_pci(struct PCIDevice *dev)
     return 0;
 }
 
-void usb_ohci_init_pci(struct PCIBus *bus, int devfn)
-{
-    pci_create_simple(bus, devfn, "pci-ohci");
-}
-
 typedef struct {
     SysBusDevice busdev;
     OHCIState ohci;
hw/usb/hcd-uhci.c +0 -16
index 7c2e9b3..5c708cf 100644
@@ -29,7 +29,6 @@
 #include "hw/usb.h"
 #include "hw/pci.h"
 #include "qemu-timer.h"
-#include "hw/usb-uhci.h"
 #include "iov.h"
 #include "dma.h"
 
@@ -1391,18 +1390,3 @@ static void uhci_register_types(void)
 }
 
 type_init(uhci_register_types)
-
-void usb_uhci_piix3_init(PCIBus *bus, int devfn)
-{
-    pci_create_simple(bus, devfn, "piix3-usb-uhci");
-}
-
-void usb_uhci_piix4_init(PCIBus *bus, int devfn)
-{
-    pci_create_simple(bus, devfn, "piix4-usb-uhci");
-}
-
-void usb_uhci_vt82c686b_init(PCIBus *bus, int devfn)
-{
-    pci_create_simple(bus, devfn, "vt82c686b-usb-uhci");
-}
hw/versatilepb.c +1 -2
index b9102f4..c1687a5 100644
@@ -13,7 +13,6 @@
 #include "net.h"
 #include "sysemu.h"
 #include "pci.h"
-#include "usb-ohci.h"
 #include "boards.h"
 #include "blockdev.h"
 #include "exec-memory.h"
@@ -240,7 +239,7 @@ static void versatile_init(ram_addr_t ram_size,
         }
     }
     if (usb_enabled) {
-        usb_ohci_init_pci(pci_bus, -1);
+        pci_create_simple(pci_bus, -1, "pci-ohci");
     }
     n = drive_get_max_bus(IF_SCSI);
     while (n >= 0) {
Signature · 1 line
1.7.1
#4 lore raw

PATCH 3/14 usb-ehci: drop unused isoch_pause variable

In reply to Gerd Hoffmann

From: Hans de Goede <[email protected]>

---
 hw/usb/hcd-ehci.c |    6 +-----
 1 files changed, 1 insertions(+), 5 deletions(-)
hw/usb/hcd-ehci.c +1 -5
index 58811d3..60f9f5b 100644
@@ -419,7 +419,6 @@ struct EHCIState {
 
     USBPacket ipacket;
     QEMUSGList isgl;
-    int isoch_pause;
 
     uint64_t last_run_ns;
 };
@@ -907,7 +906,6 @@ static void ehci_reset(void *opaque)
 
     s->astate = EST_INACTIVE;
     s->pstate = EST_INACTIVE;
-    s->isoch_pause = -1;
     s->attach_poll_counter = 0;
 
     for(i = 0; i < NB_PORTS; i++) {
@@ -2150,9 +2148,7 @@ static void ehci_frame_timer(void *opaque)
 
     for (i = 0; i < frames; i++) {
         if ( !(ehci->usbsts & USBSTS_HALT)) {
-            if (ehci->isoch_pause <= 0) {
-                ehci->frindex += 8;
-            }
+            ehci->frindex += 8;
 
             if (ehci->frindex > 0x00001fff) {
                 ehci->frindex = 0;
Signature · 1 line
1.7.1
#5 lore raw

PATCH 4/14 usb-ohci: DMA writeback bug fixes

In reply to Gerd Hoffmann

From: Wei Yang <[email protected]>

This patch fixes two bugs in the OHCI device where the device writes back data to system memory that should be exclusively under the control of the guest side driver.

In OHCI specification Section 5.2.7, it mentioned "In all cases, Host Controller Driver is responsible for the insertion and removal of all Endpoint Descriptors in the various Host Controller Endpoint Descriptor lists". In the ohci_frame_boundary(), ohci_put_hcca() writes the entire hcca back including the interrupt ED lists which should be under driver control. This violates the specification and can race with a host driver updating that list at the same time.

In the OHCI Spec Section 4.6, Transfer Descriptor Queue Processing, it mentioned "Since the TD pointed to by TailP is not accessed by the HC, the Host Controller Driver can initialize that TD and link at least one other to it without creating a coherency or synchronization problem". While the function ohci_put_ed() writes the entire endpoint descriptor back including the TailP which should under driver control. This violate the specification and can race with a host driver updating the TD list at the same time.

In each case the solution is to make sure we don't write data which is under driver control.

Cc Gerd Hoffman <[email protected]>
---
 hw/usb/hcd-ohci.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
hw/usb/hcd-ohci.c +15 -2
index 51fa111..1a1cc88 100644
@@ -121,6 +121,11 @@ struct ohci_hcca {
     uint16_t frame, pad;
     uint32_t done;
 };
+#define HCCA_WRITEBACK_OFFSET   offsetof(struct ohci_hcca, frame)
+#define HCCA_WRITEBACK_SIZE     8 /* frame, pad, done */
+
+#define ED_WBACK_OFFSET offsetof(struct ohci_ed, head)
+#define ED_WBACK_SIZE   4
 
 static void ohci_bus_stop(OHCIState *ohci);
 static void ohci_async_cancel_device(OHCIState *ohci, USBDevice *dev);
@@ -568,7 +573,13 @@ static inline int ohci_read_hcca(OHCIState *ohci,
 static inline int ohci_put_ed(OHCIState *ohci,
                               uint32_t addr, struct ohci_ed *ed)
 {
-    return put_dwords(ohci, addr, (uint32_t *)ed, sizeof(*ed) >> 2);
+    /* ed->tail is under control of the HCD.
+     * Since just ed->head is changed by HC, just write back this
+     */
+
+    return put_dwords(ohci, addr + ED_WBACK_OFFSET,
+                      (uint32_t *)((char *)ed + ED_WBACK_OFFSET),
+                      ED_WBACK_SIZE >> 2);
 }
 
 static inline int ohci_put_td(OHCIState *ohci,
@@ -587,7 +598,9 @@ static inline int ohci_put_iso_td(OHCIState *ohci,
 static inline int ohci_put_hcca(OHCIState *ohci,
                                 uint32_t addr, struct ohci_hcca *hcca)
 {
-    cpu_physical_memory_write(addr + ohci->localmem_base, hcca, sizeof(*hcca));
+    cpu_physical_memory_write(addr + ohci->localmem_base + HCCA_WRITEBACK_OFFSET,
+                              (char *)hcca + HCCA_WRITEBACK_OFFSET,
+                              HCCA_WRITEBACK_SIZE);
     return 1;
 }
 
Signature · 1 line
1.7.1
#6 lore raw

PATCH 5/14 usb: improve packet state sanity checks

In reply to Gerd Hoffmann

Add a new function to check whenever the packet state is as expected, log more informations in case it isn't.

---
 hw/usb.h      |    1 +
 hw/usb/core.c |   37 +++++++++++++++++++++++++++++++------
 trace-events  |    1 +
 3 files changed, 33 insertions(+), 6 deletions(-)
hw/usb.h +1 -0
index d60d03d..e95085f 100644
@@ -336,6 +336,7 @@ struct USBPacket {
 
 void usb_packet_init(USBPacket *p);
 void usb_packet_set_state(USBPacket *p, USBPacketState state);
+void usb_packet_check_state(USBPacket *p, USBPacketState expected);
 void usb_packet_setup(USBPacket *p, int pid, USBEndpoint *ep);
 void usb_packet_addbuf(USBPacket *p, void *ptr, size_t len);
 int usb_packet_map(USBPacket *p, QEMUSGList *sgl);
hw/usb/core.c +31 -6
index 494989a..a4048fe 100644
@@ -378,7 +378,7 @@ int usb_handle_packet(USBDevice *dev, USBPacket *p)
     }
     assert(dev == p->ep->dev);
     assert(dev->state == USB_STATE_DEFAULT);
-    assert(p->state == USB_PACKET_SETUP);
+    usb_packet_check_state(p, USB_PACKET_SETUP);
     assert(p->ep != NULL);
 
     if (QTAILQ_EMPTY(&p->ep->queue) || p->ep->pipeline) {
@@ -406,7 +406,7 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p)
     USBEndpoint *ep = p->ep;
     int ret;
 
-    assert(p->state == USB_PACKET_ASYNC);
+    usb_packet_check_state(p, USB_PACKET_ASYNC);
     assert(QTAILQ_FIRST(&ep->queue) == p);
     usb_packet_set_state(p, USB_PACKET_COMPLETE);
     QTAILQ_REMOVE(&ep->queue, p, queue);
@@ -417,7 +417,7 @@ void usb_packet_complete(USBDevice *dev, USBPacket *p)
         if (p->state == USB_PACKET_ASYNC) {
             break;
         }
-        assert(p->state == USB_PACKET_QUEUED);
+        usb_packet_check_state(p, USB_PACKET_QUEUED);
         ret = usb_process_one(p);
         if (ret == USB_RET_ASYNC) {
             usb_packet_set_state(p, USB_PACKET_ASYNC);
@@ -450,7 +450,7 @@ void usb_packet_init(USBPacket *p)
     qemu_iovec_init(&p->iov, 1);
 }
 
-void usb_packet_set_state(USBPacket *p, USBPacketState state)
+static const char *usb_packet_state_name(USBPacketState state)
 {
     static const char *name[] = {
         [USB_PACKET_UNDEFINED] = "undef",
@@ -460,11 +460,36 @@ void usb_packet_set_state(USBPacket *p, USBPacketState state)
         [USB_PACKET_COMPLETE]  = "complete",
         [USB_PACKET_CANCELED]  = "canceled",
     };
+    if (state < ARRAY_SIZE(name)) {
+        return name[state];
+    }
+    return "INVALID";
+}
+
+void usb_packet_check_state(USBPacket *p, USBPacketState expected)
+{
+    USBDevice *dev;
+    USBBus *bus;
+
+    if (p->state == expected) {
+        return;
+    }
+    dev = p->ep->dev;
+    bus = usb_bus_from_device(dev);
+    trace_usb_packet_state_fault(bus->busnr, dev->port->path, p->ep->nr, p,
+                                 usb_packet_state_name(p->state),
+                                 usb_packet_state_name(expected));
+    assert(!"usb packet state check failed");
+}
+
+void usb_packet_set_state(USBPacket *p, USBPacketState state)
+{
     USBDevice *dev = p->ep->dev;
     USBBus *bus = usb_bus_from_device(dev);
 
-    trace_usb_packet_state_change(bus->busnr, dev->port->path, p->ep->nr,
-                                  p, name[p->state], name[state]);
+    trace_usb_packet_state_change(bus->busnr, dev->port->path, p->ep->nr, p,
+                                  usb_packet_state_name(p->state),
+                                  usb_packet_state_name(state));
     p->state = state;
 }
 
trace-events +1 -0
index bcfe13a..301374e 100644
@@ -229,6 +229,7 @@ sun4m_iommu_bad_addr(uint64_t addr) "bad addr %"PRIx64
 
 # hw/usb/core.c
 usb_packet_state_change(int bus, const char *port, int ep, void *p, const char *o, const char *n) "bus %d, port %s, ep %d, packet %p, state %s -> %s"
+usb_packet_state_fault(int bus, const char *port, int ep, void *p, const char *o, const char *n) "bus %d, port %s, ep %d, packet %p, state %s, expected %s"
 
 # hw/usb/bus.c
 usb_port_claim(int bus, const char *port) "bus %d, port %s"
Signature · 1 line
1.7.1
#7 lore raw

PATCH 6/14 uhci: pass addr to uhci_async_alloc

In reply to Gerd Hoffmann

Also do async->td initialization in uhci_async_alloc now. Prepares for adding tracepoints.

---
 hw/usb/hcd-uhci.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
hw/usb/hcd-uhci.c +3 -3
index 5c708cf..476db1f 100644
@@ -198,11 +198,12 @@ static void uhci_queue_free(UHCIQueue *queue)
     g_free(queue);
 }
 
-static UHCIAsync *uhci_async_alloc(UHCIQueue *queue)
+static UHCIAsync *uhci_async_alloc(UHCIQueue *queue, uint32_t addr)
 {
     UHCIAsync *async = g_new0(UHCIAsync, 1);
 
     async->queue = queue;
+    async->td = addr;
     usb_packet_init(&async->packet);
     pci_dma_sglist_init(&async->sgl, &queue->uhci->dev, 1);
 
@@ -814,7 +815,7 @@ static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *in
     }
 
     /* Allocate new packet */
-    async = uhci_async_alloc(uhci_queue_get(s, td));
+    async = uhci_async_alloc(uhci_queue_get(s, td), addr);
     if (!async)
         return 1;
 
@@ -822,7 +823,6 @@ static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *in
      * for initial isochronous requests
      */
     async->queue->valid = 32;
-    async->td    = addr;
     async->isoc  = td->ctrl & TD_CTRL_IOS;
 
     max_len = ((td->token >> 21) + 1) & 0x7ff;
Signature · 1 line
1.7.1
#8 lore raw

PATCH 7/14 uhci: fix uhci_async_cancel_all

In reply to Gerd Hoffmann

It should also free all queues.

---
 hw/usb/hcd-uhci.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/usb/hcd-uhci.c +1 -0
index 476db1f..416f703 100644
@@ -300,6 +300,7 @@ static void uhci_async_cancel_all(UHCIState *s)
             uhci_async_unlink(curr);
             uhci_async_cancel(curr);
         }
+        uhci_queue_free(queue);
     }
 }
 
Signature · 1 line
1.7.1
#9 lore raw

PATCH 8/14 uhci: cancel on schedule stop.

In reply to Gerd Hoffmann

Cancel any in-flight transaction when the guest stops the uhci schedule.

---
 hw/usb/hcd-uhci.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/usb/hcd-uhci.c +1 -0
index 416f703..5177e33 100644
@@ -1126,6 +1126,7 @@ static void uhci_frame_timer(void *opaque)
     if (!(s->cmd & UHCI_CMD_RS)) {
         /* Full stop */
         qemu_del_timer(s->frame_timer);
+        uhci_async_cancel_all(s);
         /* set hchalted bit in status - UHCI11D 2.1.2 */
         s->status |= UHCI_STS_HCHALTED;
 
Signature · 1 line
1.7.1
#10 lore raw

PATCH 9/14 uhci: tracing support

In reply to Gerd Hoffmann

Zap DPRINTF, add tracepoints instead.

---
 hw/usb/hcd-uhci.c |   87 +++++++++++++++++++---------------------------------
 trace-events      |   31 +++++++++++++++++++
 2 files changed, 63 insertions(+), 55 deletions(-)
hw/usb/hcd-uhci.c +32 -55
index 5177e33..054ae19 100644
@@ -31,6 +31,7 @@
 #include "qemu-timer.h"
 #include "iov.h"
 #include "dma.h"
+#include "trace.h"
 
 //#define DEBUG
 //#define DEBUG_DUMP_DATA
@@ -76,23 +77,6 @@
 
 #define NB_PORTS 2
 
-#ifdef DEBUG
-#define DPRINTF printf
-
-static const char *pid2str(int pid)
-{
-    switch (pid) {
-    case USB_TOKEN_SETUP: return "SETUP";
-    case USB_TOKEN_IN:    return "IN";
-    case USB_TOKEN_OUT:   return "OUT";
-    }
-    return "?";
-}
-
-#else
-#define DPRINTF(...)
-#endif
-
 typedef struct UHCIState UHCIState;
 typedef struct UHCIAsync UHCIAsync;
 typedef struct UHCIQueue UHCIQueue;
@@ -187,6 +171,7 @@ static UHCIQueue *uhci_queue_get(UHCIState *s, UHCI_TD *td)
     queue->token = token;
     QTAILQ_INIT(&queue->asyncs);
     QTAILQ_INSERT_HEAD(&s->queues, queue, next);
+    trace_usb_uhci_queue_add(queue->token);
     return queue;
 }
 
@@ -194,6 +179,7 @@ static void uhci_queue_free(UHCIQueue *queue)
 {
     UHCIState *s = queue->uhci;
 
+    trace_usb_uhci_queue_del(queue->token);
     QTAILQ_REMOVE(&s->queues, queue, next);
     g_free(queue);
 }
@@ -206,12 +192,14 @@ static UHCIAsync *uhci_async_alloc(UHCIQueue *queue, uint32_t addr)
     async->td = addr;
     usb_packet_init(&async->packet);
     pci_dma_sglist_init(&async->sgl, &queue->uhci->dev, 1);
+    trace_usb_uhci_packet_add(async->queue->token, async->td);
 
     return async;
 }
 
 static void uhci_async_free(UHCIAsync *async)
 {
+    trace_usb_uhci_packet_del(async->queue->token, async->td);
     usb_packet_cleanup(&async->packet);
     qemu_sglist_destroy(&async->sgl);
     g_free(async);
@@ -221,19 +209,19 @@ static void uhci_async_link(UHCIAsync *async)
 {
     UHCIQueue *queue = async->queue;
     QTAILQ_INSERT_TAIL(&queue->asyncs, async, next);
+    trace_usb_uhci_packet_link_async(async->queue->token, async->td);
 }
 
 static void uhci_async_unlink(UHCIAsync *async)
 {
     UHCIQueue *queue = async->queue;
     QTAILQ_REMOVE(&queue->asyncs, async, next);
+    trace_usb_uhci_packet_unlink_async(async->queue->token, async->td);
 }
 
 static void uhci_async_cancel(UHCIAsync *async)
 {
-    DPRINTF("uhci: cancel td 0x%x token 0x%x done %u\n",
-           async->td, async->token, async->done);
-
+    trace_usb_uhci_packet_cancel(async->queue->token, async->td, async->done);
     if (!async->done)
         usb_cancel_packet(&async->packet);
     uhci_async_free(async);
@@ -351,7 +339,7 @@ static void uhci_reset(void *opaque)
     int i;
     UHCIPort *port;
 
-    DPRINTF("uhci: full reset\n");
+    trace_usb_uhci_reset();
 
     pci_conf = s->dev.config;
 
@@ -451,12 +439,13 @@ static void uhci_ioport_writew(void *opaque, uint32_t addr, uint32_t val)
     UHCIState *s = opaque;
 
     addr &= 0x1f;
-    DPRINTF("uhci: writew port=0x%04x val=0x%04x\n", addr, val);
+    trace_usb_uhci_mmio_writew(addr, val);
 
     switch(addr) {
     case 0x00:
         if ((val & UHCI_CMD_RS) && !(s->cmd & UHCI_CMD_RS)) {
             /* start frame processing */
+            trace_usb_uhci_schedule_start();
             s->expire_time = qemu_get_clock_ns(vm_clock) +
                 (get_ticks_per_sec() / FRAME_TIMER_FREQ);
             qemu_mod_timer(s->frame_timer, qemu_get_clock_ns(vm_clock));
@@ -561,7 +550,7 @@ static uint32_t uhci_ioport_readw(void *opaque, uint32_t addr)
         break;
     }
 
-    DPRINTF("uhci: readw port=0x%04x val=0x%04x\n", addr, val);
+    trace_usb_uhci_mmio_readw(addr, val);
 
     return val;
 }
@@ -571,7 +560,7 @@ static void uhci_ioport_writel(void *opaque, uint32_t addr, uint32_t val)
     UHCIState *s = opaque;
 
     addr &= 0x1f;
-    DPRINTF("uhci: writel port=0x%04x val=0x%08x\n", addr, val);
+    trace_usb_uhci_mmio_writel(addr, val);
 
     switch(addr) {
     case 0x08:
@@ -594,6 +583,7 @@ static uint32_t uhci_ioport_readl(void *opaque, uint32_t addr)
         val = 0xffffffff;
         break;
     }
+    trace_usb_uhci_mmio_readl(addr, val);
     return val;
 }
 
@@ -729,12 +719,14 @@ static int uhci_complete_td(UHCIState *s, UHCI_TD *td, UHCIAsync *async, uint32_
         if ((td->ctrl & TD_CTRL_SPD) && len < max_len) {
             *int_mask |= 0x02;
             /* short packet: do not update QH */
-            DPRINTF("uhci: short packet. td 0x%x token 0x%x\n", async->td, async->token);
+            trace_usb_uhci_packet_complete_shortxfer(async->queue->token,
+                                                    async->td);
             return 1;
         }
     }
 
     /* success */
+    trace_usb_uhci_packet_complete_success(async->queue->token, async->td);
     return 0;
 
 out:
@@ -747,6 +739,7 @@ out:
             *int_mask |= 0x01;
         }
         uhci_update_irq(s);
+        trace_usb_uhci_packet_complete_stall(async->queue->token, async->td);
         return 1;
 
     case USB_RET_BABBLE:
@@ -758,6 +751,7 @@ out:
         }
         uhci_update_irq(s);
         /* frame interrupted */
+        trace_usb_uhci_packet_complete_babble(async->queue->token, async->td);
         return -1;
 
     case USB_RET_NAK:
@@ -784,6 +778,8 @@ out:
             if (td->ctrl & TD_CTRL_IOC)
                 *int_mask |= 0x01;
             uhci_update_irq(s);
+            trace_usb_uhci_packet_complete_error(async->queue->token,
+                                                 async->td);
         }
     }
     td->ctrl = (td->ctrl & ~(3 << TD_CTRL_ERROR_SHIFT)) |
@@ -874,8 +870,6 @@ static void uhci_async_complete(USBPort *port, USBPacket *packet)
     UHCIAsync *async = container_of(packet, UHCIAsync, packet);
     UHCIState *s = async->queue->uhci;
 
-    DPRINTF("uhci: async complete. td 0x%x token 0x%x\n", async->td, async->token);
-
     if (async->isoc) {
         UHCI_TD td;
         uint32_t link = async->td;
@@ -963,6 +957,7 @@ static void uhci_fill_queue(UHCIState *s, UHCI_TD *td)
         if (uhci_queue_token(&ptd) != token) {
             break;
         }
+        trace_usb_uhci_td_queue(plink & ~0xf, ptd.ctrl, ptd.token);
         ret = uhci_handle_td(s, plink, &ptd, &int_mask);
         assert(ret == 2); /* got USB_RET_ASYNC */
         assert(int_mask == 0);
@@ -981,8 +976,6 @@ static void uhci_process_frame(UHCIState *s)
 
     frame_addr = s->fl_base_addr + ((s->frnum & 0x3ff) << 2);
 
-    DPRINTF("uhci: processing frame %d addr 0x%x\n" , s->frnum, frame_addr);
-
     pci_dma_read(&s->dev, frame_addr, &link, 4);
     le32_to_cpus(&link);
 
@@ -994,6 +987,7 @@ static void uhci_process_frame(UHCIState *s)
     for (cnt = FRAME_MAX_LOOPS; is_valid(link) && cnt; cnt--) {
         if (is_qh(link)) {
             /* QH */
+            trace_usb_uhci_qh_load(link & ~0xf);
 
             if (qhdb_insert(&qhdb, link)) {
                 /*
@@ -1006,14 +1000,14 @@ static void uhci_process_frame(UHCIState *s)
                  *  (b) we've reached the usb 1.1 bandwidth, which is
                  *      1280 bytes/frame.
                  */
-                DPRINTF("uhci: detected loop. qh 0x%x\n", link);
                 if (td_count == 0) {
-                    DPRINTF("uhci: no transaction last round, stop\n");
+                    trace_usb_uhci_frame_loop_stop_idle();
                     break;
                 } else if (bytes_count >= 1280) {
-                    DPRINTF("uhci: bandwidth limit reached, stop\n");
+                    trace_usb_uhci_frame_loop_stop_bandwidth();
                     break;
                 } else {
+                    trace_usb_uhci_frame_loop_continue();
                     td_count = 0;
                     qhdb_reset(&qhdb);
                     qhdb_insert(&qhdb, link);
@@ -1024,9 +1018,6 @@ static void uhci_process_frame(UHCIState *s)
             le32_to_cpus(&qh.link);
             le32_to_cpus(&qh.el_link);
 
-            DPRINTF("uhci: QH 0x%x load. link 0x%x elink 0x%x\n",
-                    link, qh.link, qh.el_link);
-
             if (!is_valid(qh.el_link)) {
                 /* QH w/o elements */
                 curr_qh = 0;
@@ -1045,9 +1036,7 @@ static void uhci_process_frame(UHCIState *s)
         le32_to_cpus(&td.ctrl);
         le32_to_cpus(&td.token);
         le32_to_cpus(&td.buffer);
-
-        DPRINTF("uhci: TD 0x%x load. link 0x%x ctrl 0x%x token 0x%x qh 0x%x\n", 
-                link, td.link, td.ctrl, td.token, curr_qh);
+        trace_usb_uhci_td_load(curr_qh & ~0xf, link & ~0xf, td.ctrl, td.token);
 
         old_td_ctrl = td.ctrl;
         ret = uhci_handle_td(s, link, &td, &int_mask);
@@ -1062,16 +1051,12 @@ static void uhci_process_frame(UHCIState *s)
             goto out;
 
         case 1: /* goto next queue */
-            DPRINTF("uhci: TD 0x%x skip. "
-                    "link 0x%x ctrl 0x%x token 0x%x qh 0x%x\n",
-                    link, td.link, td.ctrl, td.token, curr_qh);
+            trace_usb_uhci_td_nextqh(curr_qh & ~0xf, link & ~0xf);
             link = curr_qh ? qh.link : td.link;
             continue;
 
         case 2: /* got USB_RET_ASYNC */
-            DPRINTF("uhci: TD 0x%x async. "
-                    "link 0x%x ctrl 0x%x token 0x%x qh 0x%x\n",
-                    link, td.link, td.ctrl, td.token, curr_qh);
+            trace_usb_uhci_td_async(curr_qh & ~0xf, link & ~0xf);
             if (is_valid(td.link)) {
                 uhci_fill_queue(s, &td);
             }
@@ -1079,10 +1064,7 @@ static void uhci_process_frame(UHCIState *s)
             continue;
 
         case 0: /* completed TD */
-            DPRINTF("uhci: TD 0x%x done. "
-                    "link 0x%x ctrl 0x%x token 0x%x qh 0x%x\n",
-                    link, td.link, td.ctrl, td.token, curr_qh);
-
+            trace_usb_uhci_td_complete(curr_qh & ~0xf, link & ~0xf);
             link = td.link;
             td_count++;
             bytes_count += (td.ctrl & 0x7ff) + 1;
@@ -1095,10 +1077,6 @@ static void uhci_process_frame(UHCIState *s)
 
                 if (!depth_first(link)) {
                     /* done with this QH */
-
-                    DPRINTF("uhci: QH 0x%x done. link 0x%x elink 0x%x\n",
-                            curr_qh, qh.link, qh.el_link);
-
                     curr_qh = 0;
                     link    = qh.link;
                 }
@@ -1125,12 +1103,11 @@ static void uhci_frame_timer(void *opaque)
 
     if (!(s->cmd & UHCI_CMD_RS)) {
         /* Full stop */
+        trace_usb_uhci_schedule_stop();
         qemu_del_timer(s->frame_timer);
         uhci_async_cancel_all(s);
         /* set hchalted bit in status - UHCI11D 2.1.2 */
         s->status |= UHCI_STS_HCHALTED;
-
-        DPRINTF("uhci: halted\n");
         return;
     }
 
@@ -1145,7 +1122,7 @@ static void uhci_frame_timer(void *opaque)
     /* Start new frame */
     s->frnum = (s->frnum + 1) & 0x7ff;
 
-    DPRINTF("uhci: new frame #%u\n" , s->frnum);
+    trace_usb_uhci_frame_start(s->frnum);
 
     uhci_async_validate_begin(s);
 
trace-events +31 -0
index 301374e..c8317a0 100644
@@ -258,6 +258,37 @@ usb_ehci_port_reset(uint32_t port, int enable) "reset port #%d - %d"
 usb_ehci_data(int rw, uint32_t cpage, uint32_t offset, uint32_t addr, uint32_t len, uint32_t bufpos) "write %d, cpage %d, offset 0x%03x, addr 0x%08x, len %d, bufpos %d"
 usb_ehci_queue_action(void *q, const char *action) "q %p: %s"
 
+# hw/usb/hcd-uhci.c
+usb_uhci_reset(void) "=== RESET ==="
+usb_uhci_schedule_start(void) ""
+usb_uhci_schedule_stop(void) ""
+usb_uhci_frame_start(uint32_t num) "nr %d"
+usb_uhci_frame_loop_stop_idle(void) ""
+usb_uhci_frame_loop_stop_bandwidth(void) ""
+usb_uhci_frame_loop_continue(void) ""
+usb_uhci_mmio_readw(uint32_t addr, uint32_t val) "addr %04x, ret 0x04%x"
+usb_uhci_mmio_writew(uint32_t addr, uint32_t val) "addr %04x, val 0x04%x"
+usb_uhci_mmio_readl(uint32_t addr, uint32_t val) "addr %04x, ret 0x08%x"
+usb_uhci_mmio_writel(uint32_t addr, uint32_t val) "addr %04x, val 0x08%x"
+usb_uhci_queue_add(uint32_t token) "token 0x%x"
+usb_uhci_queue_del(uint32_t token) "token 0x%x"
+usb_uhci_packet_add(uint32_t token, uint32_t addr) "token 0x%x, td 0x%x"
+usb_uhci_packet_link_async(uint32_t token, uint32_t addr) "token 0x%x, td 0x%x"
+usb_uhci_packet_unlink_async(uint32_t token, uint32_t addr) "token 0x%x, td 0x%x"
+usb_uhci_packet_cancel(uint32_t token, uint32_t addr, int done) "token 0x%x, td 0x%x, done %d"
+usb_uhci_packet_complete_success(uint32_t token, uint32_t addr) "token 0x%x, td 0x%x"
+usb_uhci_packet_complete_shortxfer(uint32_t token, uint32_t addr) "token 0x%x, td 0x%x"
+usb_uhci_packet_complete_stall(uint32_t token, uint32_t addr) "token 0x%x, td 0x%x"
+usb_uhci_packet_complete_babble(uint32_t token, uint32_t addr) "token 0x%x, td 0x%x"
+usb_uhci_packet_complete_error(uint32_t token, uint32_t addr) "token 0x%x, td 0x%x"
+usb_uhci_packet_del(uint32_t token, uint32_t addr) "token 0x%x, td 0x%x"
+usb_uhci_qh_load(uint32_t qh) "qh 0x%x"
+usb_uhci_td_load(uint32_t qh, uint32_t td, uint32_t ctrl, uint32_t token) "qh 0x%x, td 0x%x, ctrl 0x%x, token 0x%x"
+usb_uhci_td_queue(uint32_t td, uint32_t ctrl, uint32_t token) "td 0x%x, ctrl 0x%x, token 0x%x"
+usb_uhci_td_nextqh(uint32_t qh, uint32_t td) "qh 0x%x, td 0x%x"
+usb_uhci_td_async(uint32_t qh, uint32_t td) "qh 0x%x, td 0x%x"
+usb_uhci_td_complete(uint32_t qh, uint32_t td) "qh 0x%x, td 0x%x"
+
 # hw/usb-desc.c
 usb_desc_device(int addr, int len, int ret) "dev %d query device, len %d, ret %d"
 usb_desc_device_qualifier(int addr, int len, int ret) "dev %d query device qualifier, len %d, ret %d"
Signature · 1 line
1.7.1
#11 lore raw

PATCH 10/14 uhci: use enum for uhci_handle_td return codes

In reply to Gerd Hoffmann

Step #1 (separate for better bisectability): replace numbers with names.

---
 hw/usb/hcd-uhci.c |   39 +++++++++++++++++++++++----------------
 1 files changed, 23 insertions(+), 16 deletions(-)
hw/usb/hcd-uhci.c +23 -16
index 054ae19..25dfc2b 100644
@@ -77,6 +77,13 @@
 
 #define NB_PORTS 2
 
+enum {
+    TD_RESULT_STOP_FRAME = -1,
+    TD_RESULT_COMPLETE   = 0,
+    TD_RESULT_NEXT_QH    = 1,
+    TD_RESULT_ASYNC      = 2,
+};
+
 typedef struct UHCIState UHCIState;
 typedef struct UHCIAsync UHCIAsync;
 typedef struct UHCIQueue UHCIQueue;
@@ -721,13 +728,13 @@ static int uhci_complete_td(UHCIState *s, UHCI_TD *td, UHCIAsync *async, uint32_
             /* short packet: do not update QH */
             trace_usb_uhci_packet_complete_shortxfer(async->queue->token,
                                                     async->td);
-            return 1;
+            return TD_RESULT_NEXT_QH;
         }
     }
 
     /* success */
     trace_usb_uhci_packet_complete_success(async->queue->token, async->td);
-    return 0;
+    return TD_RESULT_COMPLETE;
 
 out:
     switch(ret) {
@@ -740,7 +747,7 @@ out:
         }
         uhci_update_irq(s);
         trace_usb_uhci_packet_complete_stall(async->queue->token, async->td);
-        return 1;
+        return TD_RESULT_NEXT_QH;
 
     case USB_RET_BABBLE:
         td->ctrl |= TD_CTRL_BABBLE | TD_CTRL_STALL;
@@ -752,13 +759,13 @@ out:
         uhci_update_irq(s);
         /* frame interrupted */
         trace_usb_uhci_packet_complete_babble(async->queue->token, async->td);
-        return -1;
+        return TD_RESULT_STOP_FRAME;
 
     case USB_RET_NAK:
         td->ctrl |= TD_CTRL_NAK;
         if (pid == USB_TOKEN_SETUP)
             break;
-	return 1;
+        return TD_RESULT_NEXT_QH;
 
     case USB_RET_IOERROR:
     case USB_RET_NODEV:
@@ -784,7 +791,7 @@ out:
     }
     td->ctrl = (td->ctrl & ~(3 << TD_CTRL_ERROR_SHIFT)) |
         (err << TD_CTRL_ERROR_SHIFT);
-    return 1;
+    return TD_RESULT_NEXT_QH;
 }
 
 static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *int_mask)
@@ -797,7 +804,7 @@ static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *in
 
     /* Is active ? */
     if (!(td->ctrl & TD_CTRL_ACTIVE))
-        return 1;
+        return TD_RESULT_NEXT_QH;
 
     async = uhci_async_find_td(s, addr, td);
     if (async) {
@@ -805,7 +812,7 @@ static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *in
         async->queue->valid = 32;
 
         if (!async->done)
-            return 1;
+            return TD_RESULT_NEXT_QH;
 
         uhci_async_unlink(async);
         goto done;
@@ -814,7 +821,7 @@ static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *in
     /* Allocate new packet */
     async = uhci_async_alloc(uhci_queue_get(s, td), addr);
     if (!async)
-        return 1;
+        return TD_RESULT_NEXT_QH;
 
     /* valid needs to be large enough to handle 10 frame delay
      * for initial isochronous requests
@@ -848,12 +855,12 @@ static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *in
         uhci_async_free(async);
         s->status |= UHCI_STS_HCPERR;
         uhci_update_irq(s);
-        return -1;
+        return TD_RESULT_STOP_FRAME;
     }
  
     if (len == USB_RET_ASYNC) {
         uhci_async_link(async);
-        return 2;
+        return TD_RESULT_ASYNC;
     }
 
     async->packet.result = len;
@@ -959,7 +966,7 @@ static void uhci_fill_queue(UHCIState *s, UHCI_TD *td)
         }
         trace_usb_uhci_td_queue(plink & ~0xf, ptd.ctrl, ptd.token);
         ret = uhci_handle_td(s, plink, &ptd, &int_mask);
-        assert(ret == 2); /* got USB_RET_ASYNC */
+        assert(ret == TD_RESULT_ASYNC);
         assert(int_mask == 0);
         plink = ptd.link;
     }
@@ -1047,15 +1054,15 @@ static void uhci_process_frame(UHCIState *s)
         }
 
         switch (ret) {
-        case -1: /* interrupted frame */
+        case TD_RESULT_STOP_FRAME: /* interrupted frame */
             goto out;
 
-        case 1: /* goto next queue */
+        case TD_RESULT_NEXT_QH:
             trace_usb_uhci_td_nextqh(curr_qh & ~0xf, link & ~0xf);
             link = curr_qh ? qh.link : td.link;
             continue;
 
-        case 2: /* got USB_RET_ASYNC */
+        case TD_RESULT_ASYNC:
             trace_usb_uhci_td_async(curr_qh & ~0xf, link & ~0xf);
             if (is_valid(td.link)) {
                 uhci_fill_queue(s, &td);
@@ -1063,7 +1070,7 @@ static void uhci_process_frame(UHCIState *s)
             link = curr_qh ? qh.link : td.link;
             continue;
 
-        case 0: /* completed TD */
+        case TD_RESULT_COMPLETE:
             trace_usb_uhci_td_complete(curr_qh & ~0xf, link & ~0xf);
             link = td.link;
             td_count++;
Signature · 1 line
1.7.1
#12 lore raw

PATCH 11/14 uhci: renumber uhci_handle_td return codes

In reply to Gerd Hoffmann

Step #2 (separate for better bisectability): renumber so the silly '-1' goes away. Pick a range which doesn't overlap the old values.

---
 hw/usb/hcd-uhci.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)
hw/usb/hcd-uhci.c +4 -4
index 25dfc2b..fd50be1 100644
@@ -78,10 +78,10 @@
 #define NB_PORTS 2
 
 enum {
-    TD_RESULT_STOP_FRAME = -1,
-    TD_RESULT_COMPLETE   = 0,
-    TD_RESULT_NEXT_QH    = 1,
-    TD_RESULT_ASYNC      = 2,
+    TD_RESULT_STOP_FRAME = 10,
+    TD_RESULT_COMPLETE,
+    TD_RESULT_NEXT_QH,
+    TD_RESULT_ASYNC,
 };
 
 typedef struct UHCIState UHCIState;
Signature · 1 line
1.7.1
#13 lore raw

PATCH 12/14 uhci: new uhci_handle_td return code for tds still in flight

In reply to Gerd Hoffmann
---
 hw/usb/hcd-uhci.c |   12 +++++++-----
 1 files changed, 7 insertions(+), 5 deletions(-)
hw/usb/hcd-uhci.c +7 -5
index fd50be1..8e34961 100644
@@ -81,7 +81,8 @@ enum {
     TD_RESULT_STOP_FRAME = 10,
     TD_RESULT_COMPLETE,
     TD_RESULT_NEXT_QH,
-    TD_RESULT_ASYNC,
+    TD_RESULT_ASYNC_START,
+    TD_RESULT_ASYNC_CONT,
 };
 
 typedef struct UHCIState UHCIState;
@@ -812,7 +813,7 @@ static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *in
         async->queue->valid = 32;
 
         if (!async->done)
-            return TD_RESULT_NEXT_QH;
+            return TD_RESULT_ASYNC_CONT;
 
         uhci_async_unlink(async);
         goto done;
@@ -860,7 +861,7 @@ static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *in
  
     if (len == USB_RET_ASYNC) {
         uhci_async_link(async);
-        return TD_RESULT_ASYNC;
+        return TD_RESULT_ASYNC_START;
     }
 
     async->packet.result = len;
@@ -966,7 +967,7 @@ static void uhci_fill_queue(UHCIState *s, UHCI_TD *td)
         }
         trace_usb_uhci_td_queue(plink & ~0xf, ptd.ctrl, ptd.token);
         ret = uhci_handle_td(s, plink, &ptd, &int_mask);
-        assert(ret == TD_RESULT_ASYNC);
+        assert(ret == TD_RESULT_ASYNC_START);
         assert(int_mask == 0);
         plink = ptd.link;
     }
@@ -1058,11 +1059,12 @@ static void uhci_process_frame(UHCIState *s)
             goto out;
 
         case TD_RESULT_NEXT_QH:
+        case TD_RESULT_ASYNC_CONT:
             trace_usb_uhci_td_nextqh(curr_qh & ~0xf, link & ~0xf);
             link = curr_qh ? qh.link : td.link;
             continue;
 
-        case TD_RESULT_ASYNC:
+        case TD_RESULT_ASYNC_START:
             trace_usb_uhci_td_async(curr_qh & ~0xf, link & ~0xf);
             if (is_valid(td.link)) {
                 uhci_fill_queue(s, &td);
Signature · 1 line
1.7.1
#14 lore raw

PATCH 13/14 uhci: alloc can't fail, drop check.

In reply to Gerd Hoffmann
---
 hw/usb/hcd-uhci.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
hw/usb/hcd-uhci.c +0 -2
index 8e34961..e55dad9 100644
@@ -821,8 +821,6 @@ static int uhci_handle_td(UHCIState *s, uint32_t addr, UHCI_TD *td, uint32_t *in
 
     /* Allocate new packet */
     async = uhci_async_alloc(uhci_queue_get(s, td), addr);
-    if (!async)
-        return TD_RESULT_NEXT_QH;
 
     /* valid needs to be large enough to handle 10 frame delay
      * for initial isochronous requests
Signature · 1 line
1.7.1
#15 lore raw

PATCH 14/14 Endian fix an assertion in usb-msd

In reply to Gerd Hoffmann

From: Benjamin Herrenschmidt <[email protected]>

This fixes a broken endian assumption in an assertion in usb-msd.

Cc Gerd Hoffman <[email protected]>
---
 hw/usb/dev-storage.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
hw/usb/dev-storage.c +3 -3
index 6ffaf70..bdbe7bd 100644
@@ -193,9 +193,9 @@ static void usb_msd_send_status(MSDState *s, USBPacket *p)
     int len;
 
     DPRINTF("Command status %d tag 0x%x, len %zd\n",
-            s->csw.status, s->csw.tag, p->iov.size);
+            s->csw.status, le32_to_cpu(s->csw.tag), p->iov.size);
 
-    assert(s->csw.sig == 0x53425355);
+    assert(s->csw.sig == cpu_to_le32(0x53425355));
     len = MIN(sizeof(s->csw), p->iov.size);
     usb_packet_copy(p, &s->csw, len);
     memset(&s->csw, 0, sizeof(s->csw));
@@ -233,7 +233,7 @@ static void usb_msd_command_complete(SCSIRequest *req, uint32_t status, size_t r
 
     s->csw.sig = cpu_to_le32(0x53425355);
     s->csw.tag = cpu_to_le32(req->tag);
-    s->csw.residue = s->residue;
+    s->csw.residue = cpu_to_le32(s->residue);
     s->csw.status = status != 0;
 
     if (s->packet) {
Signature · 1 line
1.7.1
#16 lore raw
In reply to Gerd Hoffmann
Quoted 9 lines · Gerd Hoffmann
   Hi,

This pull brings in the bug usb rename, i.e. move all usb emulation source code into hw/usb/. Also UHCI got some love, featuring some cleanups, some small fixes and full tracing support. Beside that it brings the usual bunch of little fixes here and there.

please pull,
Gerd

Pulled. Thanks.

Regards,

Anthony Liguori

Quoted 98 lines

The following changes since commit cb72b75824c0362e5cb32eb8796930f29fa36d17:

   Merge remote-tracking branch 'mdroth/qga-pull-3-12-2012' into staging (2012-03-12 20:52:34 -0500)

are available in the git repository at:

   git://git.kraxel.org/qemu usb.44

Benjamin Herrenschmidt (1):
Endian fix an assertion in usb-msd

Gerd Hoffmann (11):
usb: the big rename
usb: zap hw/ush-{ohic,uhci}.h + init wrappers
usb: improve packet state sanity checks
uhci: pass addr to uhci_async_alloc
uhci: fix uhci_async_cancel_all
uhci: cancel on schedule stop.
uhci: tracing support
uhci: use enum for uhci_handle_td return codes
uhci: renumber uhci_handle_td return codes
uhci: new uhci_handle_td return code for tds still in flight
uhci: alloc can't fail, drop check.

Hans de Goede (1):
usb-ehci: drop unused isoch_pause variable

Wei Yang (1):
usb-ohci: DMA writeback bug fixes

  Makefile.objs                                 |   24 ++--
  Makefile.target                               |    2 +-
  configure                                     |    4 +-
  hw/alpha_sys.h                                |    1 -
  hw/mips_fulong2e.c                            |    7 +-
  hw/mips_malta.c                               |    3 +-
  hw/pc_piix.c                                  |    4 +-
  hw/ppc_newworld.c                             |    3 +-
  hw/ppc_oldworld.c                             |    3 +-
  hw/ppc_prep.c                                 |    3 +-
  hw/realview.c                                 |    3 +-
  hw/usb-ohci.h                                 |    9 --
  hw/usb-uhci.h                                 |   10 --
  hw/usb.h                                      |    1 +
  hw/{usb-bus.c =>  usb/bus.c}                   |    6 +-
  hw/{usb.c =>  usb/core.c}                      |   39 +++++-
  hw/{usb-desc.c =>  usb/desc.c}                 |    4 +-
  hw/{usb-desc.h =>  usb/desc.h}                 |    0
  hw/{usb-audio.c =>  usb/dev-audio.c}           |    8 +-
  hw/{usb-bt.c =>  usb/dev-bluetooth.c}          |    6 +-
  hw/{usb-hid.c =>  usb/dev-hid.c}               |    8 +-
  hw/{usb-hub.c =>  usb/dev-hub.c}               |    4 +-
  hw/{usb-net.c =>  usb/dev-network.c}           |    4 +-
  hw/{usb-serial.c =>  usb/dev-serial.c}         |    4 +-
  hw/{usb-ccid.c =>  usb/dev-smartcard-reader.c} |    4 +-
  hw/{usb-msd.c =>  usb/dev-storage.c}           |   12 +-
  hw/{usb-wacom.c =>  usb/dev-wacom.c}           |    6 +-
  hw/{usb-ehci.c =>  usb/hcd-ehci.c}             |   12 +--
  hw/{usb-musb.c =>  usb/hcd-musb.c}             |    6 +-
  hw/{usb-ohci.c =>  usb/hcd-ohci.c}             |   33 +++--
  hw/{usb-uhci.c =>  usb/hcd-uhci.c}             |  156 ++++++++++---------------
  hw/{usb-xhci.c =>  usb/hcd-xhci.c}             |   10 +-
  usb-bsd.c =>  hw/usb/host-bsd.c                |    0
  usb-linux.c =>  hw/usb/host-linux.c            |    0
  usb-stub.c =>  hw/usb/host-stub.c              |    0
  hw/{usb-libhw.c =>  usb/libhw.c}               |    2 +-
  usb-redir.c =>  hw/usb/redirect.c              |    0
  hw/versatilepb.c                              |    3 +-
  trace-events                                  |   40 ++++++-
  39 files changed, 226 insertions(+), 218 deletions(-)
  delete mode 100644 hw/usb-ohci.h
  delete mode 100644 hw/usb-uhci.h
  rename hw/{usb-bus.c =>  usb/bus.c} (99%)
  rename hw/{usb.c =>  usb/core.c} (95%)
  rename hw/{usb-desc.c =>  usb/desc.c} (99%)
  rename hw/{usb-desc.h =>  usb/desc.h} (100%)
  rename hw/{usb-audio.c =>  usb/dev-audio.c} (99%)
  rename hw/{usb-bt.c =>  usb/dev-bluetooth.c} (99%)
  rename hw/{usb-hid.c =>  usb/dev-hid.c} (99%)
  rename hw/{usb-hub.c =>  usb/dev-hub.c} (99%)
  rename hw/{usb-net.c =>  usb/dev-network.c} (99%)
  rename hw/{usb-serial.c =>  usb/dev-serial.c} (99%)
  rename hw/{usb-ccid.c =>  usb/dev-smartcard-reader.c} (99%)
  rename hw/{usb-msd.c =>  usb/dev-storage.c} (98%)
  rename hw/{usb-wacom.c =>  usb/dev-wacom.c} (99%)
  rename hw/{usb-ehci.c =>  usb/hcd-ehci.c} (99%)
  rename hw/{usb-musb.c =>  usb/hcd-musb.c} (99%)
  rename hw/{usb-ohci.c =>  usb/hcd-ohci.c} (98%)
  rename hw/{usb-uhci.c =>  usb/hcd-uhci.c} (91%)
  rename hw/{usb-xhci.c =>  usb/hcd-xhci.c} (99%)

rename usb-bsd.c => hw/usb/host-bsd.c (100%) rename usb-linux.c => hw/usb/host-linux.c (100%) rename usb-stub.c => hw/usb/host-stub.c (100%) rename hw/{usb-libhw.c => usb/libhw.c} (99%) rename usb-redir.c => hw/usb/redirect.c (100%)