Saturday, April 08, 2006

USB HID--The perfect match for virtualization?

An interesting discussion has emerged on qemu-devel about a topic dear to my heart. Anyone who has done anything with input device emulation knows that mice are a big pain to virtualize as PS/2 only supports relative input coordinates. This requires the all-to-familar "input grabbing" mode that things like QEmu and VMware both require since the emulator has no idea where the mouse actually is within the guest (and therefore doesn't know when the mouse "leaves" the window).

The most accepted solution to this is to paravirtualize the input driver. This is the approach VMware takes and is the approach I'm currently taking in Xen. Another approach that I've explored is emulating a drawing tablet. These devices use absolute coordinates (as you want exactly what you draw to appear on the screen). I even implemented a proof-of-concept Wacom emulator for QEmu. Alas, these devices tend to be serial-based so you get no automatic probing on guest install. This means users have to manually configure the devices which is a no-go for a large set of our target user-base.

Someone on qemu-devel pointed out that the USB HID specification allows devices to be either relative or absolute. A compliant HID driver would therefore Just Work. Best of all, USB tends to be probed automatically so it satisfies that requirement. This got me thinking about how useful HID could be in general. Besides keyboards and mice, the HID also specifies things like USB speakers. This may be a practical way of having cross-platform plug-n-play sound. Plus, with things like USB over IP, there's an awful lot of potential for remoting these things.