Pass-through of input devices
Input via mouse and keyboard can be transferred to the virtual machine via a virtio-input device. In this case, the entire USB controller does not have to be passed through via PCI Device Passthrough so that other USB interfaces are still available to the TwinCAT/BSD host.
To forward input to the virtual machine via virtio-input, the input events of the connected device /dev/input/eventN
must be transferred to the virtio-input
device.
The following sample call transfers the integrated GPU using PCI-Device Passthrough and the input events /dev/input/event4
and /dev/input/event3
via virtio-net
.
doas bhyve \
-c sockets=1,cores=2,threads=1 \
-m 4G \
-l bootrom,/vms/samplevm/UEFI.fd,/vms/samplevm/EFI_VARS.fd,fwcfg=qemu \
-s 0,hostbridge \
-s 2,passthru,0/2/0,rom=/vms/samplevm/gop.rom \
-s 3,virtio-input,/dev/input/event4 \
-s 4,virtio-input,/dev/input/event3 \
-s 10,nvme,/vms/samplevm/disk0.img \
-s 31,lpc \
-o pci.0.31.0.pcireg.vendor=host \
-o pci.0.31.0.pcireg.device=host \
-o pci.0.31.0.pcireg.revid=host \
-o pci.0.31.0.pcireg.subvendor=host \
-o pci.0.31.0.pcireg.subdevice=host \
-A -H -P samplevm
Identification of input events of connected USB devices
The sysctl kern.evdev.input
command can be used to list connected input devices and their IDs in order to determine the assignment between the input device and /dev/input/event<ID>
.
The following sample shows a USB mouse (ums0
) with Input ID 4 and a USB keyboard (ukbd0
) with Input ID 3.
kern.evdev.input.4.uniq: 2057366C5943
kern.evdev.input.4.phys: ukbd1
kern.evdev.input.4.id: { bustype = 0x0003, vendor = 0x046d, product = 0xc093, version = 0x0000 }
kern.evdev.input.4.name: Logitech Advanced Corded Mouse M500s, class 0/0, rev 2.00/53.00, addr 2
kern.evdev.input.3.uniq:
kern.evdev.input.3.phys: ukbd0
kern.evdev.input.3.id: { bustype = 0x0003, vendor = 0x046d, product = 0xc328, version = 0x0000 }
kern.evdev.input.3.name: Logitech USB Keyboard, class 0/0, rev 1.10/86.00, addr 1
kern.evdev.input.2.uniq:
kern.evdev.input.2.phys: acpi_button0
kern.evdev.input.2.id: { bustype = 0x0019, vendor = 0x0000, product = 0x0000, version = 0x0001 }
kern.evdev.input.2.name: Sleep Button
kern.evdev.input.1.uniq:
kern.evdev.input.1.phys: sysmouse
kern.evdev.input.1.id: { bustype = 0x0006, vendor = 0x0000, product = 0x0000, version = 0x0000 }
kern.evdev.input.1.name: System mouse
kern.evdev.input.0.uniq:
kern.evdev.input.0.phys: kbdmux0
kern.evdev.input.0.id: { bustype = 0x0006, vendor = 0x0000, product = 0x0000, version = 0x0000 }
kern.evdev.input.0.name: System keyboard multiplexer
Accordingly, as in the sample above, the input events from the mouse and keyboard can be transferred to the virtual machine.