vtcon(4) only created a userland tty; kernel printf/panic never reached
the virtio console, so on hypervisors whose only usable console is the
virtio console (e.g. Apple's Virtualization.framework: no UART, and a
Blt-only virtio-gpu with no linear framebuffer for vt_efifb) the kernel
booted blind.
Register the console port as a low-level console via cnadd(9), like
Linux's hvc0: the sole port of a non-multiport device, or the port the
host marks with VIRTIO_CONSOLE_CONSOLE_PORT. Registration happens in
the virtio_attach_completed method, after the transport has set
DRIVER_OK: the device processes no virtqueue before that, so a console
write from vtcon_attach() would wait for the host forever (seen with
boot_verbose, which prints in that window).
Output: cn_putc reuses the polled vtcon_port_out(). Console and tty
output share the port's out virtqueue and are serialized by a spin
mutex, since cn_putc may run with spin locks held; in panic/kdb no lock
is taken. The console port is looked up under that mutex and teardown
clears it under the same mutex, so no console write is in flight once
the port is gone.
Input: cn_grab disables the in virtqueue interrupt and, on a live
system (mountroot prompt, geli passphrase), takes the port lock so an
in-flight vtcon_port_in() is waited out and cannot re-enable the
interrupt. cn_getc polls the in virtqueue. cn_ungrab requeues a
partially consumed buffer and delivers input that arrived meanwhile.
hw.vtcon.console_enable=0 keeps the previous behaviour (documented in
virtio_console.4, new LOADER TUNABLES section).
This is one of a small series that lets stock FreeBSD/arm64 boot under
Apple's Virtualization.framework; the GIC-version fix (GICD_PIDR2 when
the MADT reports Version 0) is submitted separately. This change is
independent of it and applies to any virtio console user (QEMU,
bhyve, ...).