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).
 
looks that there is no easy way to add ps/2
On x86 it's part of the i8042 controller. That's a default for pc/q35 machine so just running qemu-system-x86_64 will provide ps/2. But this is true regardless of the host arch. Tested it and running it on m3 book gives me the same results.
UTM creates a bit more complicted qemu command, among others it does:
Code:
-machine q35,vmport=off,i8042=off,hpet=off
So it kills i8042, hence no PS/2.
 
Under UTM (on m1 mbp) I don't get a mouse cursor in text mode but as soon as I do startx, it works fine under X11. dmesg shows this:
hms0: <QEMU QEMU USB Tablet> on hidbus0
hms0: 3 buttons and [XYW] coordinates ID=0
hms1: <QEMU QEMU USB Mouse> on hidbus1
hms1: 5 buttons and [XYW] coordinates ID=0
Compared to the original /etc/rc.conf I see one addition due to "service dbus enable". But I don't recall doing anything special. I also have this in /boot/loader.conf for a bigger virtual screen:
virtio_gpu_qemu_load="YES"
hw.virtio_gpu_qemu.width=1920
hw.virtio_gpu_qemu.height=1080
 
Under UTM (on m1 mbp) I don't get a mouse cursor in text mode but as soon as I do startx, it works fine under X11. dmesg shows this:

Compared to the original /etc/rc.conf I see one addition due to "service dbus enable". But I don't recall doing anything special. I also have this in /boot/loader.conf for a bigger virtual screen:
if you are on 15.1 it should work if you start moused with -p auto and press ctrl option
 
Thanks. The cursor shows but no mouse movement. Even after enabling moused and restarting. "ps ax" shows:

2249 - Is 0:00.00 /usr/sbin/moused -p /dev/input/event5 -t evdev -I /var/run/moused.event5.pid
2836 - Ss 0:00.00 /usr/sbin/moused -p auto


I noticed (via "cat -vu") that /dev/input/event4 is connected to the touchpad. No idea why moused picks event5. Manually starting moused replacing event5 with event4 fails.
 
there are 2 devices the usb mouse and the usb tablet
the usb tablet won't work with moused without the patch i posted above
the mouse only works if you press the guest capture key in the utm console window (default is control-option)
then events start to flow thru event5
 
well i have tried with an arm image
I mean ok but that's not what's OP doing.

I wonder why as moused is seeing those events (vt vs sc? ; wild guess).
I was right about that - switching to sc made ps/2 mouse work out of the box (kern.vty=sc in /boot/loader.conf). It's not desired state of course but if torsar needs it it's a workaround.
Man page says moused is supported in vt, so there's something else going on.
 
Something is bothering vt do display the mouse cursor. I did find another workaround which may help some future googler. Goal was to keep the vm as simple as possible (i.e. no parameters, just load the disk). But this solution does require virtio gpu. As fewer options as possible (omitting even q35 specs):
Code:
qemu-system-x86_64 -m 8192 \
-device virtio-gpu-pci \
-device virtio-blk-pci,drive=hd0 -drive if=none,id=hd0,format=raw,file=FreeBSD-15.1-RELEASE-amd64-BASIC-CI-ufs.raw

Once image is booted I had to install virtio-gpu-qemu-kmod package and load it and reboot:
Code:
# pkg install -y virtio-gpu-qemu-kmod
# echo 'virtio_gpu_qemu_load="YES"' >> /boot/loader.conf

Now during the boot system will inform about the switch:
Code:
VT: Replacing driver "vga" with new "virtio_gpu_qemu".
WARNING: Device "fb" is Giant locked and may be deleted before FreeBSD 16.0.
VT: Driver priority 110 too low. Current 120
 vtgpu0: registered as a framebuffer device
In qemu UI this means to switch to View from "VGA" to "virtio-gpu-pci", in the same menu item where parallel and serial port are.
In this view moused works as expected also with default PS/2 mouse.
 
Back
Top