Can I pass through a USB Port via qemu Command Line?

49,494

For some reason this is not documented on the Qemu 2.12.50 User Doc and I had to learn what I learned from this guy

They mention:

-device usb-host,hostbus=bus,hostaddr=addr
Pass through the host device identified by bus and addr 

-device usb-host,vendorid=vendor,productid=product
Pass through the host device identified by vendor and product ID 

But they don't mention that you can also do:

-device usb-host,hostbus=bus,hostport=port

For example...

Running lsusb -t, I get:

/:  Bus 03.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/14p, 480M
|__ Port 10: Dev 8, If 0, Class=Human Interface Device, Driver=usbhid, 12M
|__ Port 11: Dev 6, If 0, Class=Human Interface Device, Driver=usbhid, 12M

I could decide to pass these with:

-device usb-host,hostbus=3,hostport=10 \
-device usb-host,hostbus=3,hostport=11 \

And those correspond to the physical slots.

However the bus and port will differ for a USB 3.0 slot depending on if a USB 2.0 device or USB 3.0 device is plugged into it, but the port for each device will remain consistent.

Such variance does not exist for USB 2.0 slots.

With USB hubs, use dots to separate the ports. So if you had ...

/:  Bus 03
|__ Port 2: some stuff
    |__ Port 1: some stuff

You would use -device usb-host,hostbus=3,hostport=2.1

Share:
49,494

Related videos on Youtube

DeepDeadpool
Author by

DeepDeadpool

Updated on September 18, 2022

Comments

  • DeepDeadpool
    DeepDeadpool over 1 year

    I'm launching a VM using qemu-system-x86_64. I know two ways to pass through a USB device.

    Say for example, I had a mouse that showed up in lsusb like

    Bus 003 Device 011: ID 6ade:9582 Amazing Mouse Maker
    

    I could pass it through using

    -device usb-host,vendorid=0x6ade,productid=0x9582
    

    or

    -device usb-host,hostbus=3,hostaddr=11
    

    Neither of these I really like. If I grab it by Vendor/Product ID then I will never be able to reclaim that mouse until the VM is turned off.

    If I grab it by BUS and Device number, then I will have to tell Qemu to reacquire it if I unplug it.

    Is it possible for me to send it by Port (the actual physical slot)? Say it's plugged in to Bus 3 Port 2. Can I pass it by that?

  • Kornelis
    Kornelis almost 4 years
    I tried this and got an error: "No 'usb-bus' bus found for device 'usb-host'" using qemu 3.1.0 on Debian Buster. I found out that you need -usb on the command line as well.
  • DeepDeadpool
    DeepDeadpool almost 4 years
    Looks like they updated the major number, so they may have broken the interface
  • driz
    driz over 3 years
    old thing here, but i was having a ton of issues after introducing a usb hub into the mix, moving from vendor/product to the updated usbhost shown fixed my issues!
  • DUO Labs
    DUO Labs over 2 years
    This worked perfectly -- for Macbooks, there is only one port per bus, the one furthest in the back is port 0.
  • mh-cbon
    mh-cbon about 2 years
    -usb -device usb-host,host...