Page MenuHomeFreeBSD

bhyve: let the PS/2 keyboard work for a guest loaded without firmware
Needs ReviewPublic

Authored by wanpengqian_gmail.com on Fri, Oct 2, 10:56 AM.
Tags
None
Referenced Files
F174677932: D60244.id188387.diff
Mon, Oct 5, 3:33 AM
F174673747: D60244.id188387.diff
Mon, Oct 5, 2:57 AM
Unknown Object (File)
Sat, Oct 3, 2:42 PM
Unknown Object (File)
Sat, Oct 3, 6:35 AM
Unknown Object (File)
Sat, Oct 3, 3:48 AM
Unknown Object (File)
Sat, Oct 3, 3:45 AM
Unknown Object (File)
Fri, Oct 2, 8:20 PM
Unknown Object (File)
Fri, Oct 2, 8:20 PM
Subscribers

Details

Reviewers
None
Group Reviewers
bhyve
Summary

The keyboard did not send scancodes until it got the Enable command,
not even after a reset, and the controller started with scancode
translation off. A PS/2 keyboard scans after its power-on reset and
after the Reset command, and PC firmware leaves the controller
translating to scancode set 1.

A guest started with the UEFI firmware does not notice, as the firmware
sends Enable and turns the translation on. FreeBSD's atkbd(4) does
neither: it resets the keyboard and keeps the translation as it finds
it. So a FreeBSD guest loaded with bhyveload(8) got no key at all from
a VNC client, and, with the keyboard enabled by hand, scancodes of set 2
that it took for set 1.

Start with the keyboard scanning and the translation on, and let the
Reset command turn scanning on.

Signed-off-by: Wanpeng Qian <wanpengqian@gmail.com>
Sponsored by: keelos.dev

Test Plan

main (f958aa7e7), FreeBSD 16.0-CURRENT guest loaded with bhyveload, with -s 29,fbuf,tcp=127.0.0.1:5900. A VNC client types "abc"; in the guest a small program prints the key events of the AT keyboard's evdev device (/dev/input/event2) as "code value".

Before: no event. (With the keyboard enabled by hand, by writing 0xf4 to port 0x60 in the guest, the same keys gave 28 1 28 2 50 1 50 2 ...: the scancodes of set 2, 0x1c for "a", read as set 1, where 0x1c is Enter, and the break prefixes not understood.)

After:

30 1 30 0 48 1 48 0 46 1 46 0

KEY_A, KEY_B and KEY_C, each pressed and released.

The same guest started with the UEFI firmware (edk2-bhyve) gives these events before and after the change.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 77617
Build 74500: arc lint + arc unit