FreeBSD on QEMU and mouse

Host: Kubuntu
Guest (QEMU): FreeBSD 15.1

On host wireless usb mouse.

On guest mouse not present!!!

Code:
/usr/bin/qemu-system-x86_64 \
    -monitor stdio \
    -cpu qemu64 \
    -machine accel=tcg \
    -m 2048 \
    -drive file=hdd/freebsd-15.1.img,format=raw \
    -virtfs local,id=shared_folder_dev_0,path=shara,security_model=none,mount_tag=shared0 \
    -boot order=c \
    -rtc base=localtime \
    -name "FreeBSD" \
    -netdev bridge,br=br0,id=net0 \
    -device rtl8139,netdev=net0 \
    -device qemu-xhci,id=xhci \
    -device usb-tablet,bus=xhci.0

Detected:
ls -l /dev/psm0
Not detected:
ls -l /dev/ums*

I think, must present usb mouse?

Code:
-device qemu-xhci,id=xhci \
-device usb-tablet,bus=xhci.0

How to set up any mouse on console FreeBSD?
 
A short web search points to problems in QEMU not to drive the ps/2 devices actively - they stay, but are defunct - when USB pointer devices are defined. Maybe you could remove the tablet emulation and try again?
 
I don't have way of testing it right now but is there a reason you explicitly metioned these options?
Code:
    -cpu qemu64 \
    -machine accel=tcg \
    -boot order=c \
I suffered the 8139 realtek chips 25 years ago at uni, glad I don't use them now. Any reason why specifically targeting this device? Similarly why explicitly going for qemu-xhci but leaving out virtio drivers?
Same goes with other options - leaving them out would probably lead to better defaults.
 
Remove that usb-tablet device, it's the wrong one. Qemu will automagically add a PS/2 mouse (which is the psm(4) that got detected). Use usb-mouse if you want a USB mouse attached to the guest (ums(4)).
 
for me it works but only if you press the mouse capture combo. otherwise is stuck. as i understand seamless desktop mouse needs qemu usb tablet but default moused won't work
i somehow debugged the problem and the device is recognized as touch screen and only "mouse" and "touchpad" is supported
i hacked moused to work but it is kind of ugly
Diff:
[$ diff -ubsw moused.c.orig moused.c
--- moused.c.orig    2026-11-26 23:12:05.498166000 +0200
+++ moused.c    2026-11-26 23:16:36.745905000 +0200
@@ -1949,6 +1949,7 @@
         return (NULL);
     case DEVICE_TYPE_MOUSE:
     case DEVICE_TYPE_TOUCHPAD:
+    case DEVICE_TYPE_TOUCHSCREEN:
         break;
     default:
         debug("unsupported device type: %s on %s",
@@ -1965,6 +1966,18 @@
     switch (iftype) {
     case DEVICE_IF_EVDEV:
         err = r_init_dev_evdev(fd, &dev);
+        if (!err && type == DEVICE_TYPE_TOUCHSCREEN) {
+            if (!strcmp(dev.name, "QEMU QEMU USB Tablet")) {
+                type = DEVICE_TYPE_MOUSE;
+                dev.type = DEVICE_TYPE_MOUSE;
+            } else {
+                debug("unsupported device type: %s on %s",
+                    r_name(type), path);
+                errno = ENXIO;
+                close(fd);
+                return (NULL);
+            }
+        }
         break;
     case DEVICE_IF_SYSMOUSE:
         err = r_init_dev_sysmouse(fd, &dev);

Code:
$ tail -5 /etc/moused.conf
[QEMU]
MatchName=QEMU QEMU USB Tablet

MousedLinearAccelX=0.07          # float
MousedLinearAccelY=0.07          # float

so the patch is necessary only for seamless dekstop integration of the vm. if you want to press the capture key then you don't need it. also evdev moused needs 15.x, won't work with 14
 
I didn't test this in code but I observed interesting moused issue. As mentioned in my first thread I started it as simple as possible and let qemu be in its defaults.
Started it as simple as possible, started moused and .. nothing. No cursor.
Code:
(host)$ qemu-system-x86_64 -M q35 -hda FreeBSD-15.1-RELEASE-amd64-BASIC-CI-ufs.raw

Daemon is running. Guest has ps/2 mouse:
Code:
root@freebsd:~ # dmesg|grep -i psm
psm0: <PS/2 Mouse> irq 12 on atkbdc0
psm0: [GIANT-LOCKED]
WARNING: Device "psm" is Giant locked and may be deleted before FreeBSD 16.0.
psm0: model IntelliMouse Explorer, device ID 4
root@freebsd:~ #

Quick checks show that irq is firing:
Code:
root@freebsd:~ # vmstat -i|grep psm
irq12: psm0                          404          5
root@freebsd:~ #

root@freebsd:~ # sysctl debug.psm.loglevel=2
debug.psm.loglevel: 0 -> 2
root@freebsd:~ # dmesg
..
psmintr: 38 f7 fb 00 00 00
psmintr: 18 ff 00 00 00 00

root@freebsd:~ # moused -d -f -p /dev/psm0
...
moused: property added: MousedDriftAfter from [Mouse drift termination] (moused.conf)
moused: 87 00 00 00 00 00 00 7f
moused: 87 fa 03 fb 04 00 00 7f
moused: ts:  74 953113999
moused: flags:80000000 buttons:00000000 obuttons:00000000
moused: activity : buttons 0x00000000  dx -11  dy -7  dz 0
moused is even registering mouse movements. But no cursor is displayed.

However, if I start the vm in uefi:
Code:
(host)$ qemu-system-x86_64 -M q35 -m 1024 -hda FreeBSD-15.1-RELEASE-amd64-BASIC-CI-ufs.raw -drive if=pflash,format=raw,file=QEMU_UEFI-x86_64.fd
moused is working just fine.

Now I don't know what is the reason behind torsar's explicit avoidance of kvm on Linux by choosing tcg, maybe there's one. Due to performance gain I'd normally stick to virtio:
Code:
qemu-system-x86_64 -M q35 -m 2048 \
-accel kvm \
-drive if=pflash,format=raw,file=QEMU_UEFI-x86_64.fd \
-device virtio-blk-pci,drive=hd0 -drive if=none,id=hd0,format=raw,file=FreeBSD-15.1-RELEASE-amd64-BASIC-CI-ufs.raw
 
on the mac i don't have psm in the default utm virt settings, but both usb mouse and usb tablet. without the patch only usm aka /dev/input/eventX works and you need to press the guest mouse capture key in the guest, otherwise it wont. with the patch both work / there are 2 moused copies running on both /dev/input/eventX and /dev/input/eventY and you don't need to use the guest input capture key to activate it.
 
on the mac i don't have psm in the default utm virt settings
If you are running it from UTM UI my guess is it preselected the qemu options. I'm running qemu from cli. My output is from osx (intel mac), I changed my commands before sharing, hvf to kvm as torsar is on Linux. qemu is from ports, downgraded to 10.2.2 due to some other regression bugs.
But I will check on apple silicon with UTM, just out of curiosity.

I tested the usb mouse too, moused saw it as additional output but didn't work under legacy. I wonder why as moused is seeing those events (vt vs sc? ; wild guess).
 
Back
Top