Download raw body.
[PATCH 5/7] hidkbd: don't claim the console when another keyboard already has it
[PATCH 7/7] hvkbd: Hyper-V synthetic keyboard driver
New driver for the VMBus synthetic keyboard (protocol 1.0, set 1
scan codes) with console and DDB polling support, plus the man page.
Generation 2 VMs have no i8042, so this is their only keyboard.
Once the guest connects to the synthetic keyboard, the host stops
feeding the emulated i8042. So hvkbd(4) doesn't attach if another
keyboard is already the console keyboard, and pckbd(4) stays the
console keyboard on Generation 1 VMs with a display console. With a
serial console it attaches next to pckbd(4) and takes the keyboard
input.
On amd64 hvkbd(4) becomes a console keyboard candidate in
wscn_input_init() next to ukbd(4); the first keyboard to attach
wins. Protocol negotiation waits up to a second. Oversized
messages are dropped with hv_channel_skip(). Unicode key events
from the host are not supported.
---
distrib/sets/lists/man/mi | 1 +
share/man/man4/Makefile | 2 +-
share/man/man4/hvkbd.4 | 79 +++++
share/man/man4/hyperv.4 | 4 +-
sys/arch/amd64/amd64/wscons_machdep.c | 8 +
sys/arch/amd64/conf/GENERIC | 2 +
sys/arch/amd64/conf/RAMDISK_CD | 2 +
sys/dev/pckbc/files.pckbc | 2 +-
sys/dev/pv/files.pv | 5 +
sys/dev/pv/hvkbd.c | 436 ++++++++++++++++++++++++++
sys/dev/pv/hvkbdvar.h | 19 ++
sys/dev/pv/hyperv.c | 5 +-
sys/dev/pv/hypervvar.h | 2 +-
13 files changed, 562 insertions(+), 5 deletions(-)
create mode 100644 share/man/man4/hvkbd.4
create mode 100644 sys/dev/pv/hvkbd.c
create mode 100644 sys/dev/pv/hvkbdvar.h
diff --git distrib/sets/lists/man/mi distrib/sets/lists/man/mi
index 2d9fdc1c926..69181925529 100644
--- distrib/sets/lists/man/mi
+++ distrib/sets/lists/man/mi
@@ -1670,6 +1670,7 @@
./usr/share/man/man4/hppa/uturn.4
./usr/share/man/man4/hppa/wax.4
./usr/share/man/man4/hsq.4
+./usr/share/man/man4/hvkbd.4
./usr/share/man/man4/hvn.4
./usr/share/man/man4/hvs.4
./usr/share/man/man4/hyperv.4
diff --git share/man/man4/Makefile share/man/man4/Makefile
index 2519c97c0e4..8fb1d27423f 100644
--- share/man/man4/Makefile
+++ share/man/man4/Makefile
@@ -43,7 +43,7 @@ MAN= aac.4 abcrtc.4 abl.4 ac97.4 acphy.4 acrtc.4 \
gpioiic.4 gpiokeys.4 gpioleds.4 gpioow.4 graphaudio.4 gre.4 gscsio.4 \
hds.4 hiclock.4 hidwusb.4 hil.4 hilid.4 hilkbd.4 hilms.4 \
hireset.4 hitemp.4 hme.4 hotplug.4 hsq.4 \
- hvn.4 hvs.4 hyperv.4 \
+ hvkbd.4 hvn.4 hvs.4 hyperv.4 \
iasuskbd.4 iatp.4 iavf.4 icc.4 ice.4 ichiic.4 ichwdt.4 \
icmp.4 icmp6.4 icsphy.4 ietp.4 ifmedia.4 \
igc.4 iha.4 ihidev.4 iic.4 iicmux.4 ikbd.4 ims.4 imt.4 imxanatop.4 \
diff --git share/man/man4/hvkbd.4 share/man/man4/hvkbd.4
new file mode 100644
index 00000000000..ccd00c0877f
--- /dev/null
+++ share/man/man4/hvkbd.4
@@ -0,0 +1,79 @@
+.\" $OpenBSD$
+.\"
+.\" Copyright (c) 2026 Yamasaki Yuu <miagetegorann@gmail.com>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: November 9 2026 $
+.Dt HVKBD 4
+.Os
+.Sh NAME
+.Nm hvkbd
+.Nd Hyper-V synthetic keyboard
+.Sh SYNOPSIS
+.Cd "hvkbd* at hyperv?"
+.Cd "wskbd* at hvkbd? mux 1"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides access to the keyboard offered by the Hyper-V virtual
+machine bus.
+It negotiates version 1.0 of the synthetic keyboard protocol and translates
+set 1 scan codes into
+.Xr wskbd 4
+events.
+.Pp
+On amd64 Generation 2 virtual machines,
+.Nm
+provides console input when no legacy keyboard controller is available.
+The existing EFI framebuffer provides console output.
+.Pp
+The driver does not attach if another keyboard is already the console
+keyboard, so
+.Xr pckbd 4
+keeps that role on Generation 1 virtual machines with a display console.
+On Generation 1 virtual machines with a serial console
+.Nm
+attaches as well.
+.Sh SEE ALSO
+.Xr hyperv 4 ,
+.Xr wskbd 4 ,
+.Xr bsd.re-config 5 ,
+.Xr boot 8 ,
+.Xr boot_config 8 ,
+.Xr config 8 ,
+.Xr wsconsctl 8
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Ox 8.1 .
+.Sh CAVEATS
+Console input is available after the VMBus keyboard channel has been attached.
+The kernel configuration prompt entered with
+.Cm boot -c
+requires a serial console because it is reached before attachment.
+The UEFI boot loader uses the firmware keyboard interface.
+.Pp
+Device configuration changes can also be prepared using the
+.Fl e
+option of
+.Xr config 8
+or the
+.Xr bsd.re-config 5
+file.
+.Pp
+The driver accepts scan-code key events.
+Unicode text events injected by the host are not supported.
+Host-side text or clipboard injection must send individual key presses and
+releases instead, using the guest's keyboard layout.
diff --git share/man/man4/hyperv.4 share/man/man4/hyperv.4
index f7489a69dff..0c5e6cf2c05 100644
--- share/man/man4/hyperv.4
+++ share/man/man4/hyperv.4
@@ -70,4 +70,6 @@ based on the
driver by the Microsoft BSD Integration Services Team
.Aq Mt bsdic@microsoft.com .
.Sh CAVEATS
-Generation 2 Virtual Machines are currently not supported.
+Generation 2 Virtual Machines on amd64 require a UEFI boot loader and
+.Xr hvkbd 4
+for console input.
diff --git sys/arch/amd64/amd64/wscons_machdep.c sys/arch/amd64/amd64/wscons_machdep.c
index afa9a4dc3ef..1470e7bd285 100644
--- sys/arch/amd64/amd64/wscons_machdep.c
+++ sys/arch/amd64/amd64/wscons_machdep.c
@@ -60,6 +60,10 @@
#include <dev/ic/pckbcvar.h>
#endif
#include "pckbd.h"
+#include "hvkbd.h"
+#if NHVKBD > 0
+#include <dev/pv/hvkbdvar.h>
+#endif
#include "ukbd.h"
#if (NUKBD > 0)
#include <dev/usb/ukbdvar.h>
@@ -193,6 +197,10 @@ wscn_input_init(int pass)
pckbc_cnattach(X86_BUS_SPACE_IO, IO_KBD, KBCMDP, 0) == 0)
return;
#endif
+#if NHVKBD > 0
+ if (pass == 0)
+ hvkbd_cninit();
+#endif
#if (NUKBD > 0)
if (ukbd_cnattach() == 0)
return;
diff --git sys/arch/amd64/conf/GENERIC sys/arch/amd64/conf/GENERIC
index b1c28ce4c8a..b62fc42a441 100644
--- sys/arch/amd64/conf/GENERIC
+++ sys/arch/amd64/conf/GENERIC
@@ -106,6 +106,8 @@ xbf* at xen? # Xen Blkfront
hyperv0 at pvbus? # Hyper-V guest
hvn* at hyperv? # Hyper-V NetVSC
hvs* at hyperv? # Hyper-V StorVSC
+hvkbd* at hyperv? # Hyper-V keyboard
+wskbd* at hvkbd? mux 1
option PCIVERBOSE
option USBVERBOSE
diff --git sys/arch/amd64/conf/RAMDISK_CD sys/arch/amd64/conf/RAMDISK_CD
index 96bb646dd51..4baf56ff320 100644
--- sys/arch/amd64/conf/RAMDISK_CD
+++ sys/arch/amd64/conf/RAMDISK_CD
@@ -77,6 +77,8 @@ xspd0 at pci? # XenSource Platform Device
hyperv0 at pvbus? # Hyper-V guest
hvn* at hyperv? # Hyper-V NetVSC
hvs* at hyperv? # Hyper-V StorVSC
+hvkbd* at hyperv? # Hyper-V keyboard
+wskbd* at hvkbd? mux 1
pchb* at pci? # PCI-Host bridges
aapic* at pci? # AMD 8131 IO apic
diff --git sys/dev/pckbc/files.pckbc sys/dev/pckbc/files.pckbc
index 8b3d4e04dd9..4407d8170c2 100644
--- sys/dev/pckbc/files.pckbc
+++ sys/dev/pckbc/files.pckbc
@@ -5,7 +5,7 @@
device pckbd: wskbddev
attach pckbd at pckbcslot
file dev/pckbc/pckbd.c pckbd needs-flag
-file dev/pckbc/wskbdmap_mfii.c pckbd
+file dev/pckbc/wskbdmap_mfii.c pckbd | hvkbd
device pms: wsmousedev
attach pms at pckbcslot
diff --git sys/dev/pv/files.pv sys/dev/pv/files.pv
index acd7f056c67..dc2f8cdfd43 100644
--- sys/dev/pv/files.pv
+++ sys/dev/pv/files.pv
@@ -50,6 +50,11 @@ device hvs: scsi
attach hvs at hyperv
file dev/pv/hvs.c hvs
+# Hyper-V synthetic keyboard
+device hvkbd: wskbddev
+attach hvkbd at hyperv
+file dev/pv/hvkbd.c hvkbd needs-flag
+
# VirtIO
file dev/pv/virtio.c virtio
diff --git sys/dev/pv/hvkbd.c sys/dev/pv/hvkbd.c
new file mode 100644
index 00000000000..dcb261da463
--- /dev/null
+++ sys/dev/pv/hvkbd.c
@@ -0,0 +1,436 @@
+/* $OpenBSD$ */
+
+/*
+ * Copyright (c) 2026 Yamasaki Yuu <miagetegorann@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Hyper-V synthetic keyboard.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/atomic.h>
+#include <sys/device.h>
+#include <sys/task.h>
+
+#include <machine/bus.h>
+#include <machine/cpu.h>
+#include <dev/pv/hypervreg.h>
+#include <dev/pv/hypervvar.h>
+#include <dev/pv/hvkbdvar.h>
+#include <dev/wscons/wsconsio.h>
+#include <dev/wscons/wskbdvar.h>
+#include <dev/wscons/wsksymdef.h>
+#include <dev/wscons/wsksymvar.h>
+#include <dev/pckbc/wskbdmap_mfii.h>
+
+#define HVKBD_VERSION 0x00010000
+#define HVKBD_PROTOCOL_REQUEST 1
+#define HVKBD_PROTOCOL_RESPONSE 2
+#define HVKBD_EVENT 3
+#define HVKBD_ACCEPTED 0x0001
+#define HVKBD_UNICODE 0x0001
+#define HVKBD_BREAK 0x0002
+#define HVKBD_E0 0x0004
+#define HVKBD_E1 0x0008
+
+struct hvkbd_protocol {
+ uint32_t type;
+ uint32_t value;
+} __packed;
+
+struct hvkbd_event {
+ uint32_t type;
+ uint16_t code;
+ uint16_t reserved;
+ uint32_t info;
+} __packed;
+
+struct hvkbd_key {
+ u_int type;
+ int code;
+};
+
+struct hvkbd_softc {
+ struct device sc_dev;
+ struct hv_channel *sc_chan;
+ struct device *sc_wskbd;
+ volatile int sc_response;
+ uint32_t sc_status;
+ int sc_enabled;
+ int sc_polling;
+ int sc_leds;
+ int sc_pause;
+ uint8_t sc_down[32];
+ struct hvkbd_key sc_keys[64];
+ u_int sc_head;
+ u_int sc_tail;
+#ifdef WSDISPLAY_COMPAT_RAWKBD
+ int sc_raw;
+#endif
+};
+
+static struct hvkbd_console {
+ struct hvkbd_softc *sc;
+ int candidate;
+} hvkbd_console;
+
+int hvkbd_match(struct device *, void *, void *);
+void hvkbd_attach(struct device *, struct device *, void *);
+void hvkbd_intr(void *);
+void hvkbd_read(struct hvkbd_softc *);
+void hvkbd_input(struct hvkbd_softc *, struct hvkbd_event *);
+void hvkbd_reset(struct hvkbd_softc *);
+int hvkbd_enable(void *, int);
+void hvkbd_set_leds(void *, int);
+int hvkbd_ioctl(void *, u_long, caddr_t, int, struct proc *);
+void hvkbd_cngetc(void *, u_int *, int *);
+void hvkbd_cnpollc(void *, int);
+
+const struct cfattach hvkbd_ca = {
+ sizeof(struct hvkbd_softc), hvkbd_match, hvkbd_attach
+};
+
+struct cfdriver hvkbd_cd = {
+ NULL, "hvkbd", DV_DULL
+};
+
+const struct wskbd_mapdata hvkbd_keymapdata = {
+ pckbd_keydesctab, KB_US | KB_DEFAULT
+};
+
+const struct wskbd_accessops hvkbd_accessops = {
+ hvkbd_enable, hvkbd_set_leds, hvkbd_ioctl
+};
+
+const struct wskbd_consops hvkbd_consops = {
+ hvkbd_cngetc, hvkbd_cnpollc, NULL
+};
+
+int
+hvkbd_match(struct device *parent, void *match, void *aux)
+{
+ struct hv_attach_args *aa = aux;
+
+ if (memcmp(aa->aa_type, &hv_guid_kbd, sizeof(hv_guid_kbd)) != 0)
+ return (0);
+ /* Negotiation redirects input away from the existing console. */
+ return (!wskbd_cnattached());
+}
+
+void
+hvkbd_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct hvkbd_softc *sc = (struct hvkbd_softc *)self;
+ struct hv_attach_args *aa = aux;
+ struct wskbddev_attach_args wa;
+ struct hvkbd_protocol req;
+ int i, s;
+
+ sc->sc_chan = aa->aa_chan;
+ sc->sc_chan->ch_flags &= ~CHF_BATCHED;
+ printf(" channel %u", sc->sc_chan->ch_id);
+ if (hv_channel_open(sc->sc_chan, 16 * PAGE_SIZE, NULL, 0,
+ hvkbd_intr, sc)) {
+ printf(": failed to open channel\n");
+ return;
+ }
+
+ req.type = htole32(HVKBD_PROTOCOL_REQUEST);
+ req.value = htole32(HVKBD_VERSION);
+ if (hv_channel_send(sc->sc_chan, &req, sizeof(req), 0,
+ VMBUS_CHANPKT_TYPE_INBAND, 0) != 0)
+ goto fail;
+ for (i = 0; i < 1000 && !sc->sc_response; i++) {
+ hvkbd_intr(sc);
+ delay(1000);
+ }
+ if (!sc->sc_response || !(sc->sc_status & HVKBD_ACCEPTED))
+ goto fail;
+
+ hv_evcount_attach(sc->sc_chan, sc->sc_dev.dv_xname);
+ printf(": protocol 1.0\n");
+ sc->sc_enabled = 1;
+ memset(&wa, 0, sizeof(wa));
+ wa.console = hvkbd_console.candidate && !wskbd_cnattached();
+ if (wa.console) {
+ hvkbd_console.sc = sc;
+ wskbd_cnattach(&hvkbd_consops, &hvkbd_console,
+ &hvkbd_keymapdata);
+ }
+ wa.keymap = &hvkbd_keymapdata;
+ wa.accessops = &hvkbd_accessops;
+ wa.accesscookie = sc;
+ sc->sc_wskbd = config_found(self, &wa, wskbddevprint);
+ s = spltty();
+ /* No pre-attach input may survive into the newly attached consumer. */
+ hvkbd_reset(sc);
+ if (sc->sc_wskbd != NULL)
+ wskbd_input(sc->sc_wskbd, WSCONS_EVENT_ALL_KEYS_UP, 0);
+ splx(s);
+ if (sc->sc_wskbd == NULL) {
+ if (wa.console) {
+ wskbd_cndetach();
+ hvkbd_console.sc = NULL;
+ }
+ sc->sc_enabled = 0;
+ evcount_detach(&sc->sc_chan->ch_evcnt);
+ hv_channel_close(sc->sc_chan);
+ }
+ return;
+fail:
+ printf(": protocol negotiation failed\n");
+ hv_channel_close(sc->sc_chan);
+}
+
+void
+hvkbd_intr(void *arg)
+{
+ struct hvkbd_softc *sc = arg;
+ int s;
+
+ /* The upcall runs at IPL_NET; wscons and our state need IPL_TTY. */
+ KERNEL_LOCK();
+ s = spltty();
+ hvkbd_read(sc);
+ splx(s);
+ KERNEL_UNLOCK();
+}
+
+/* Called at IPL_TTY or higher, with the kernel lock or CPUs stopped in DDB. */
+void
+hvkbd_read(struct hvkbd_softc *sc)
+{
+ struct hvkbd_protocol *proto;
+ uint32_t buf[64], len;
+ uint64_t rid;
+ int rv;
+
+ for (;;) {
+ rv = hv_channel_recv(sc->sc_chan, buf, sizeof(buf), &len,
+ &rid, 0);
+ if (rv == EINVAL) {
+ /* Don't let an oversized message stall the channel. */
+ if (hv_channel_skip(sc->sc_chan) != 0)
+ break;
+ continue;
+ }
+ if (rv != 0)
+ break;
+ if (len < sizeof(uint32_t))
+ continue;
+ switch (letoh32(buf[0])) {
+ case HVKBD_PROTOCOL_RESPONSE:
+ if (len < sizeof(*proto))
+ break;
+ proto = (struct hvkbd_protocol *)buf;
+ sc->sc_status = letoh32(proto->value);
+ sc->sc_response = 1;
+ break;
+ case HVKBD_EVENT:
+ if (len >= sizeof(struct hvkbd_event))
+ hvkbd_input(sc, (struct hvkbd_event *)buf);
+ break;
+ }
+ }
+}
+
+void
+hvkbd_input(struct hvkbd_softc *sc, struct hvkbd_event *event)
+{
+ uint32_t info = letoh32(event->info);
+ int code = letoh16(event->code);
+ u_int type, next;
+ uint8_t mask;
+#ifdef WSDISPLAY_COMPAT_RAWKBD
+ u_char raw[3];
+ int n = 0;
+#endif
+
+ if (!sc->sc_enabled || (info & HVKBD_UNICODE) || code > 0x7f)
+ return;
+#ifdef WSDISPLAY_COMPAT_RAWKBD
+ if (sc->sc_raw && !sc->sc_polling && sc->sc_wskbd != NULL) {
+ if (info & HVKBD_E0)
+ raw[n++] = 0xe0;
+ if (info & HVKBD_E1)
+ raw[n++] = 0xe1;
+ raw[n++] = code | ((info & HVKBD_BREAK) ? 0x80 : 0);
+ wskbd_rawinput(sc->sc_wskbd, raw, n);
+ return;
+ }
+#endif
+ /* Pause is the set 1 E1 1D 45 sequence, mapped to key 127. */
+ if ((info & HVKBD_E1) && code == 0x1d) {
+ sc->sc_pause = 1;
+ return;
+ }
+ if (sc->sc_pause && code == 0x45)
+ code = 0x7f;
+ sc->sc_pause = 0;
+ if (info & HVKBD_E0)
+ code |= 0x80;
+ mask = 1U << (code & 7);
+ if (info & HVKBD_BREAK) {
+ if (!(sc->sc_down[code >> 3] & mask))
+ return;
+ sc->sc_down[code >> 3] &= ~mask;
+ type = WSCONS_EVENT_KEY_UP;
+ } else {
+ if (sc->sc_down[code >> 3] & mask)
+ return;
+ sc->sc_down[code >> 3] |= mask;
+ type = WSCONS_EVENT_KEY_DOWN;
+ }
+ if (sc->sc_polling || sc->sc_wskbd == NULL) {
+ next = (sc->sc_tail + 1) % nitems(sc->sc_keys);
+ if (next == sc->sc_head) {
+ /* Don't leave the translator with stuck keys. */
+ hvkbd_reset(sc);
+ sc->sc_keys[0].type = WSCONS_EVENT_ALL_KEYS_UP;
+ sc->sc_keys[0].code = 0;
+ sc->sc_tail = 1;
+ return;
+ }
+ sc->sc_keys[sc->sc_tail].type = type;
+ sc->sc_keys[sc->sc_tail].code = code;
+ sc->sc_tail = next;
+ } else {
+ wskbd_input(sc->sc_wskbd, type, code);
+ }
+}
+
+/* Discard incomplete input when changing consumers or losing events. */
+void
+hvkbd_reset(struct hvkbd_softc *sc)
+{
+ memset(sc->sc_down, 0, sizeof(sc->sc_down));
+ sc->sc_pause = 0;
+ sc->sc_head = sc->sc_tail = 0;
+}
+
+int
+hvkbd_enable(void *arg, int on)
+{
+ struct hvkbd_softc *sc = arg;
+ int s;
+
+ if (!on && hvkbd_console.sc == sc)
+ return (EBUSY);
+ s = spltty();
+ if (sc->sc_enabled != on) {
+ hvkbd_reset(sc);
+ if (sc->sc_wskbd != NULL)
+ wskbd_input(sc->sc_wskbd, WSCONS_EVENT_ALL_KEYS_UP, 0);
+ }
+ sc->sc_enabled = on;
+ splx(s);
+ return (0);
+}
+
+void
+hvkbd_set_leds(void *arg, int leds)
+{
+ struct hvkbd_softc *sc = arg;
+
+ sc->sc_leds = leds;
+}
+
+int
+hvkbd_ioctl(void *arg, u_long cmd, caddr_t data, int flag, struct proc *p)
+{
+ struct hvkbd_softc *sc = arg;
+#ifdef WSDISPLAY_COMPAT_RAWKBD
+ int raw, s;
+#endif
+
+ switch (cmd) {
+ case WSKBDIO_GTYPE:
+ *(int *)data = WSKBD_TYPE_PC_XT;
+ return (0);
+ case WSKBDIO_SETLEDS:
+ hvkbd_set_leds(sc, *(int *)data);
+ return (0);
+ case WSKBDIO_GETLEDS:
+ *(int *)data = sc->sc_leds;
+ return (0);
+#ifdef WSDISPLAY_COMPAT_RAWKBD
+ case WSKBDIO_SETMODE:
+ raw = *(int *)data == WSKBD_RAW;
+ s = spltty();
+ if (sc->sc_raw != raw) {
+ hvkbd_reset(sc);
+ sc->sc_raw = raw;
+ }
+ splx(s);
+ return (0);
+#endif
+ }
+ return (-1);
+}
+
+void
+hvkbd_cngetc(void *arg, u_int *type, int *data)
+{
+ struct hvkbd_console *console = arg;
+ struct hvkbd_softc *sc = console->sc;
+ int polling, s;
+
+ KASSERT(sc != NULL);
+ s = splhigh();
+ polling = sc->sc_polling;
+ sc->sc_polling = 1;
+ while (sc->sc_head == sc->sc_tail) {
+ hvkbd_read(sc);
+ if (sc->sc_head == sc->sc_tail)
+ delay(1000);
+ }
+ *type = sc->sc_keys[sc->sc_head].type;
+ *data = sc->sc_keys[sc->sc_head].code;
+ sc->sc_head = (sc->sc_head + 1) % nitems(sc->sc_keys);
+ sc->sc_polling = polling;
+ splx(s);
+}
+
+void
+hvkbd_cnpollc(void *arg, int on)
+{
+ struct hvkbd_console *console = arg;
+ struct hvkbd_softc *sc = console->sc;
+ int s;
+
+ s = spltty();
+ if (sc->sc_polling != on) {
+ /* Debugger typeahead belongs to this polling session only. */
+ hvkbd_reset(sc);
+ sc->sc_polling = on;
+ if (on) {
+ /* The translator may still hold DDB modifiers. */
+ sc->sc_keys[0].type = WSCONS_EVENT_ALL_KEYS_UP;
+ sc->sc_keys[0].code = 0;
+ sc->sc_tail = 1;
+ } else if (sc->sc_wskbd != NULL)
+ wskbd_input(sc->sc_wskbd, WSCONS_EVENT_ALL_KEYS_UP, 0);
+ }
+ splx(s);
+}
+
+void
+hvkbd_cninit(void)
+{
+ /* Keep USB eligible until an actual keyboard has attached. */
+ hvkbd_console.candidate = 1;
+}
diff --git sys/dev/pv/hvkbdvar.h sys/dev/pv/hvkbdvar.h
new file mode 100644
index 00000000000..9b3fe42524d
--- /dev/null
+++ sys/dev/pv/hvkbdvar.h
@@ -0,0 +1,19 @@
+/* $OpenBSD$ */
+
+/*
+ * Copyright (c) 2026 Yamasaki Yuu <miagetegorann@gmail.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+void hvkbd_cninit(void);
diff --git sys/dev/pv/hyperv.c sys/dev/pv/hyperv.c
index e28cbf73eb4..25eadcf15eb 100644
--- sys/dev/pv/hyperv.c
+++ sys/dev/pv/hyperv.c
@@ -203,11 +203,14 @@ const struct hv_guid hv_guid_mouse = {
0xb9, 0x8b, 0x8b, 0xa1, 0xa1, 0xf3, 0xf9, 0x5a }
};
+#endif
+
const struct hv_guid hv_guid_kbd = {
{ 0x6d, 0xad, 0x12, 0xf9, 0x17, 0x2b, 0xea, 0x48,
0xbd, 0x65, 0xf9, 0x27, 0xa6, 0x1c, 0x76, 0x84 }
};
+#ifdef HYPERV_DEBUG
const struct hv_guid hv_guid_video = {
{ 0x02, 0x78, 0x0a, 0xda, 0x77, 0xe3, 0xac, 0x4a,
0x8e, 0x77, 0x05, 0x58, 0xeb, 0x10, 0x73, 0xf8 }
@@ -950,11 +953,11 @@ hv_guid_sprint(struct hv_guid *guid, char *str, size_t size)
{ &hv_guid_timesync, "timesync" },
{ &hv_guid_heartbeat, "heartbeat" },
{ &hv_guid_kvp, "kvp" },
+ { &hv_guid_kbd, "keyboard" },
#ifdef HYPERV_DEBUG
{ &hv_guid_vss, "vss" },
{ &hv_guid_dynmem, "dynamic-memory" },
{ &hv_guid_mouse, "mouse" },
- { &hv_guid_kbd, "keyboard" },
{ &hv_guid_video, "video" },
{ &hv_guid_fc, "fiber-channel" },
{ &hv_guid_fcopy, "file-copy" },
diff --git sys/dev/pv/hypervvar.h sys/dev/pv/hypervvar.h
index bbe145bc14b..cdd2eadad82 100644
--- sys/dev/pv/hypervvar.h
+++ sys/dev/pv/hypervvar.h
@@ -188,11 +188,11 @@ extern const struct hv_guid hv_guid_shutdown;
extern const struct hv_guid hv_guid_timesync;
extern const struct hv_guid hv_guid_heartbeat;
extern const struct hv_guid hv_guid_kvp;
+extern const struct hv_guid hv_guid_kbd;
#ifdef HYPERV_DEBUG
extern const struct hv_guid hv_guid_vss;
extern const struct hv_guid hv_guid_dynmem;
extern const struct hv_guid hv_guid_mouse;
-extern const struct hv_guid hv_guid_kbd;
extern const struct hv_guid hv_guid_video;
extern const struct hv_guid hv_guid_fc;
extern const struct hv_guid hv_guid_fcopy;
[PATCH 5/7] hidkbd: don't claim the console when another keyboard already has it
[PATCH 7/7] hvkbd: Hyper-V synthetic keyboard driver