HTC Vive + QEMU/KVM GPU Passthrough (VFIO): List of USB IDs + Passing bus.dev into QEMU

#!/bin/bash
...

vive_ids=`python3 - <<END

from subprocess import check_output
ids = {'0bb4:0306', '28de:2101', '0bb4:2c87', '28de:2000'}
special_id = '0bb4:2c87'
special_added = False

if __name__ == '__main__':
  busdevs = []
  usbs = check_output('lsusb').decode().strip().split('\n')
  special_bd = None
  for usb in usbs:
    usb = usb.split()
    usb_id = usb[5]
    if usb_id not in ids:
      continue
    bd = int(usb[1]), int(usb[3].replace(':', ''))
    if usb_id == special_id:
      if special_added:
        special_bd = bd
      special_added = True
    busdevs.append(bd)
  buf = ''
  for bd in busdevs:
    if bd == special_bd:
      buf += '-device usb-host,hostbus={},hostaddr={},bus=ehci.0 '.format(bd[0], bd[1])
    else:
      buf += '-device usb-host,hostbus={},hostaddr={},bus=xhci.0 '.format(bd[0], bd[1])
  print(buf)

END`

qemu-system-x86_64 \
  ...
  -device ich9-usb-uhci3,id=uhci \
  -device usb-ehci,id=ehci \
  -device nec-usb-xhci,id=xhci \
  ${vive_ids} \
  ...

The solution works fine. The tracking/performance is just perfect. except that unfortunately it fails if both 0bb4:2c87 is added, the VM will crash, which means the integreated camera can't be used...

The only solution for that is passing through a whole PCI USB controller...

The integreated camera can now be used.

Recommendations

Last modified: 2018-05-29 16:37:50
Powered by Simple Blog