Module Name: src Committed By: bouyer Date: Tue Oct 17 12:07:42 UTC 2023
Modified Files: src/sys/arch/x86/include: genfb_machdep.h src/sys/arch/x86/pci: pci_machdep.c src/sys/arch/x86/x86: consinit.c genfb_machdep.c src/sys/arch/xen/conf: files.xen src/sys/arch/xen/x86: autoconf.c consinit.c Added Files: src/sys/arch/xen/xen: genfb_xen.c Log Message: Support non-VGA framebuffers for Xen dom0. This is mandatory for graphic console on EFI-only hardware. Add a xen_genfb_getbtinfo() function which will return a btinfo_framebuffer structure, filled in with parameters provided by Xen when runing as a Xen dom0, call xen_genfb_getbtinfo() instead of lookup_bootinfo(BTINFO_FRAMEBUFFER) when adding properties to the PCI graphic device (when genfb is attached) and in x86_genfb_init() when genfb is used as console. x86/x86/consinit.c: If running as a Xen dom0, use xen_genfb_getbtinfo() to check if we have a genfb console xen/x86/consinit.c: support genfb as possible console xen/x86/consinit.c: use the hypervior IO as console until a better one is found. If the hypervisor is using a serial port for boot messages, we'll get NetBSD's boot message on the serial port too until the real console takes over. xen/x86/autoconf.c: rework device_register() to be closer to the x86 version. Especially make sure that device_pci_register() is called. To generate a diff of this commit: cvs rdiff -u -r1.6 -r1.7 src/sys/arch/x86/include/genfb_machdep.h cvs rdiff -u -r1.96 -r1.97 src/sys/arch/x86/pci/pci_machdep.c cvs rdiff -u -r1.36 -r1.37 src/sys/arch/x86/x86/consinit.c cvs rdiff -u -r1.21 -r1.22 src/sys/arch/x86/x86/genfb_machdep.c cvs rdiff -u -r1.187 -r1.188 src/sys/arch/xen/conf/files.xen cvs rdiff -u -r1.25 -r1.26 src/sys/arch/xen/x86/autoconf.c cvs rdiff -u -r1.17 -r1.18 src/sys/arch/xen/x86/consinit.c cvs rdiff -u -r0 -r1.1 src/sys/arch/xen/xen/genfb_xen.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/x86/include/genfb_machdep.h diff -u src/sys/arch/x86/include/genfb_machdep.h:1.6 src/sys/arch/x86/include/genfb_machdep.h:1.7 --- src/sys/arch/x86/include/genfb_machdep.h:1.6 Mon Oct 16 17:27:02 2023 +++ src/sys/arch/x86/include/genfb_machdep.h Tue Oct 17 12:07:42 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: genfb_machdep.h,v 1.6 2023/10/16 17:27:02 bouyer Exp $ */ +/* $NetBSD: genfb_machdep.h,v 1.7 2023/10/17 12:07:42 bouyer Exp $ */ /*- * Copyright (c) 2009 Jared D. McNeill <jmcne...@invisible.ca> @@ -34,6 +34,8 @@ int x86_genfb_cnattach(void); void x86_genfb_set_console_dev(device_t); void x86_genfb_ddb_trap_callback(int); +const struct btinfo_framebuffer * xen_genfb_getbtinfo(void); + extern int acpi_md_vesa_modenum; extern int acpi_md_vbios_reset; extern struct vcons_screen x86_genfb_console_screen; Index: src/sys/arch/x86/pci/pci_machdep.c diff -u src/sys/arch/x86/pci/pci_machdep.c:1.96 src/sys/arch/x86/pci/pci_machdep.c:1.97 --- src/sys/arch/x86/pci/pci_machdep.c:1.96 Mon Oct 16 17:27:02 2023 +++ src/sys/arch/x86/pci/pci_machdep.c Tue Oct 17 12:07:42 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: pci_machdep.c,v 1.96 2023/10/16 17:27:02 bouyer Exp $ */ +/* $NetBSD: pci_machdep.c,v 1.97 2023/10/17 12:07:42 bouyer Exp $ */ /*- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -73,7 +73,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.96 2023/10/16 17:27:02 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.97 2023/10/17 12:07:42 bouyer Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -103,6 +103,8 @@ __KERNEL_RCSID(0, "$NetBSD: pci_machdep. #include <dev/wsfb/genfbvar.h> #include <arch/x86/include/genfb_machdep.h> +#include <arch/xen/include/hypervisor.h> +#include <arch/xen/include/xen.h> #include <dev/ic/vgareg.h> #include "acpica.h" @@ -116,6 +118,7 @@ __KERNEL_RCSID(0, "$NetBSD: pci_machdep. #include "pci.h" #include "wsdisplay.h" #include "com.h" +#include "opt_xen.h" #ifdef DDB #include <machine/db_machdep.h> @@ -1110,9 +1113,18 @@ populate_fbinfo(device_t dev, prop_dicti #if NWSDISPLAY > 0 && NGENFB > 0 struct rasops_info *ri = &x86_genfb_console_screen.scr_ri; #endif - const void *fbptr = lookup_bootinfo(BTINFO_FRAMEBUFFER); + const void *fbptr = NULL; struct btinfo_framebuffer fbinfo; + +#if NWSDISPLAY > 0 && NGENFB > 0 && defined(XEN) && defined(DOM0OPS) + if ((vm_guest == VM_GUEST_XENPVH || vm_guest == VM_GUEST_XENPV) && + xendomain_is_dom0()) + fbptr = xen_genfb_getbtinfo(); +#endif + if (fbptr == NULL) + fbptr = lookup_bootinfo(BTINFO_FRAMEBUFFER); + if (fbptr == NULL) return; Index: src/sys/arch/x86/x86/consinit.c diff -u src/sys/arch/x86/x86/consinit.c:1.36 src/sys/arch/x86/x86/consinit.c:1.37 --- src/sys/arch/x86/x86/consinit.c:1.36 Fri Mar 24 12:28:42 2023 +++ src/sys/arch/x86/x86/consinit.c Tue Oct 17 12:07:42 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: consinit.c,v 1.36 2023/03/24 12:28:42 bouyer Exp $ */ +/* $NetBSD: consinit.c,v 1.37 2023/10/17 12:07:42 bouyer Exp $ */ /* * Copyright (c) 1998 @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.36 2023/03/24 12:28:42 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.37 2023/10/17 12:07:42 bouyer Exp $"); #include "opt_kgdb.h" #include "opt_puc.h" @@ -164,7 +164,7 @@ consinit(void) { const struct btinfo_console *consinfo; #if (NGENFB > 0) - const struct btinfo_framebuffer *fbinfo; + const struct btinfo_framebuffer *fbinfo = NULL; #endif static int initted; #if (NCOM > 0) @@ -189,7 +189,12 @@ consinit(void) consinfo = &default_consinfo; #if (NGENFB > 0) - fbinfo = lookup_bootinfo(BTINFO_FRAMEBUFFER); +#if defined(XENPVH) && defined(DOM0OPS) + if (vm_guest == VM_GUEST_XENPVH && xendomain_is_dom0()) + fbinfo = xen_genfb_getbtinfo(); + else +#endif /* XENPVHVM */ + fbinfo = lookup_bootinfo(BTINFO_FRAMEBUFFER); #endif if (!strcmp(consinfo->devname, "pc")) { Index: src/sys/arch/x86/x86/genfb_machdep.c diff -u src/sys/arch/x86/x86/genfb_machdep.c:1.21 src/sys/arch/x86/x86/genfb_machdep.c:1.22 --- src/sys/arch/x86/x86/genfb_machdep.c:1.21 Mon Oct 16 17:27:03 2023 +++ src/sys/arch/x86/x86/genfb_machdep.c Tue Oct 17 12:07:42 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: genfb_machdep.c,v 1.21 2023/10/16 17:27:03 bouyer Exp $ */ +/* $NetBSD: genfb_machdep.c,v 1.22 2023/10/17 12:07:42 bouyer Exp $ */ /*- * Copyright (c) 2009 Jared D. McNeill <jmcne...@invisible.ca> @@ -31,7 +31,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: genfb_machdep.c,v 1.21 2023/10/16 17:27:03 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: genfb_machdep.c,v 1.22 2023/10/17 12:07:42 bouyer Exp $"); #include <sys/param.h> #include <sys/conf.h> @@ -52,10 +52,13 @@ __KERNEL_RCSID(0, "$NetBSD: genfb_machde #include <dev/wsfb/genfbvar.h> #include <arch/x86/include/genfb_machdep.h> +#include <arch/xen/include/hypervisor.h> +#include <arch/xen/include/xen.h> #include "wsdisplay.h" #include "genfb.h" #include "acpica.h" +#include "opt_xen.h" #if NWSDISPLAY > 0 && NGENFB > 0 struct vcons_screen x86_genfb_console_screen; @@ -101,7 +104,7 @@ x86_genfb_init(void) { static int inited, attached; struct rasops_info *ri = &x86_genfb_console_screen.scr_ri; - const struct btinfo_framebuffer *fbinfo; + const struct btinfo_framebuffer *fbinfo = NULL; bus_space_tag_t t = x86_bus_space_mem; bus_space_handle_t h; void *bits; @@ -113,7 +116,14 @@ x86_genfb_init(void) memset(&x86_genfb_console_screen, 0, sizeof(x86_genfb_console_screen)); - fbinfo = lookup_bootinfo(BTINFO_FRAMEBUFFER); +#if defined(XEN) && defined(DOM0OPS) + if ((vm_guest == VM_GUEST_XENPVH || vm_guest == VM_GUEST_XENPV) && + xendomain_is_dom0()) + fbinfo = xen_genfb_getbtinfo(); +#endif + if (fbinfo == NULL) + fbinfo = lookup_bootinfo(BTINFO_FRAMEBUFFER); + if (fbinfo == NULL || fbinfo->physaddr == 0) return 0; Index: src/sys/arch/xen/conf/files.xen diff -u src/sys/arch/xen/conf/files.xen:1.187 src/sys/arch/xen/conf/files.xen:1.188 --- src/sys/arch/xen/conf/files.xen:1.187 Wed Aug 31 12:51:56 2022 +++ src/sys/arch/xen/conf/files.xen Tue Oct 17 12:07:42 2023 @@ -1,4 +1,4 @@ -# $NetBSD: files.xen,v 1.187 2022/08/31 12:51:56 bouyer Exp $ +# $NetBSD: files.xen,v 1.188 2023/10/17 12:07:42 bouyer Exp $ defflag opt_xen.h XEN XENPVH XENPVHVM PAE DOM0OPS @@ -11,6 +11,7 @@ file arch/xen/xen/xenmem.c xen & !xenp file arch/xen/x86/xen_mainbus.c xen file arch/xen/xen/xen_clock.c xen file arch/xen/x86/xen_bus_dma.c xen +file arch/xen/xen/genfb_xen.c xen & genfb file arch/xen/x86/pvh_consinit.c xenpvhvm Index: src/sys/arch/xen/x86/autoconf.c diff -u src/sys/arch/xen/x86/autoconf.c:1.25 src/sys/arch/xen/x86/autoconf.c:1.26 --- src/sys/arch/xen/x86/autoconf.c:1.25 Sat May 2 16:44:36 2020 +++ src/sys/arch/xen/x86/autoconf.c Tue Oct 17 12:07:42 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.c,v 1.25 2020/05/02 16:44:36 bouyer Exp $ */ +/* $NetBSD: autoconf.c,v 1.26 2023/10/17 12:07:42 bouyer Exp $ */ /* NetBSD: autoconf.c,v 1.75 2003/12/30 12:33:22 pk Exp */ /*- @@ -45,7 +45,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.25 2020/05/02 16:44:36 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.26 2023/10/17 12:07:42 bouyer Exp $"); #include "opt_xen.h" #include "opt_multiprocessor.h" @@ -82,6 +82,8 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v #include <machine/pcb.h> #include <machine/bootinfo.h> +#include <x86/autoconf.h> + struct disklist *x86_alldisks; int x86_ndisks; int x86_found_console; @@ -227,6 +229,12 @@ dom0_bootstatic_callback(struct nfs_disk void device_register(device_t dev, void *aux) { + device_t isaboot, pciboot; + device_t found = NULL; + + isaboot = device_isa_register(dev, aux); + pciboot = device_pci_register(dev, aux); + /* * Handle network interfaces here, the attachment information is * not available driver independently later. @@ -250,60 +258,25 @@ device_register(device_t dev, void *aux) if (strncmp(xcp.xcp_bootdev, device_xname(dev), sizeof(xcp.xcp_bootdev)) == 0) { - goto found; + found = dev; } } #endif - if (device_class(dev) == DV_IFNET) { - struct btinfo_netif *bin = lookup_bootinfo(BTINFO_NETIF); - if (bin == NULL) - return; - - /* - * We don't check the driver name against the device name - * passed by the boot ROM. The ROM should stay usable - * if the driver gets obsoleted. - * The physical attachment information (checked below) - * must be sufficient to identify the device. - */ - - if (bin->bus == BI_BUS_ISA && - device_is_a(device_parent(dev), "isa")) { - struct isa_attach_args *iaa = aux; - - /* compare IO base address */ - /* XXXJRT what about multiple I/O addrs? */ - if (iaa->ia_nio > 0 && - bin->addr.iobase == iaa->ia_io[0].ir_addr) - goto found; - } -#if NPCI > 0 - if (bin->bus == BI_BUS_PCI && - device_is_a(device_parent(dev), "pci")) { - struct pci_attach_args *paa = aux; - int b, d, f; - - /* - * Calculate BIOS representation of: - * - * <bus,device,function> - * - * and compare. - */ - pci_decompose_tag(paa->pa_pc, paa->pa_tag, &b, &d, &f); - if (bin->addr.tag == ((b << 8) | (d << 3) | f)) - goto found; - } -#endif + if (found == NULL) { + if (isaboot != NULL) + found = isaboot; + else if (pciboot != NULL) + found = pciboot; } - return; -found: - if (booted_device) { - /* XXX should be a "panic()" */ - printf("warning: double match for boot device (%s, %s)\n", - device_xname(booted_device), device_xname(dev)); - return; + if (found) { + if (booted_device) { + /* XXX should be a "panic()" */ + printf("warning: double match for boot device (%s, %s)\n", + device_xname(booted_device), device_xname(dev)); + return; + } + booted_device = found; + booted_method = "device/register"; } - booted_device = dev; } Index: src/sys/arch/xen/x86/consinit.c diff -u src/sys/arch/xen/x86/consinit.c:1.17 src/sys/arch/xen/x86/consinit.c:1.18 --- src/sys/arch/xen/x86/consinit.c:1.17 Sat Jul 22 19:13:17 2023 +++ src/sys/arch/xen/x86/consinit.c Tue Oct 17 12:07:42 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: consinit.c,v 1.17 2023/07/22 19:13:17 mrg Exp $ */ +/* $NetBSD: consinit.c,v 1.18 2023/10/17 12:07:42 bouyer Exp $ */ /* NetBSD: consinit.c,v 1.4 2004/03/13 17:31:34 bjh21 Exp */ /* @@ -28,7 +28,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.17 2023/07/22 19:13:17 mrg Exp $"); +__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.18 2023/10/17 12:07:42 bouyer Exp $"); #include "opt_kgdb.h" @@ -37,11 +37,13 @@ __KERNEL_RCSID(0, "$NetBSD: consinit.c,v #include <sys/device.h> #include <sys/bus.h> #include <machine/bootinfo.h> +#include <arch/x86/include/genfb_machdep.h> #include "xencons.h" #include "vga.h" #include "ega.h" #include "pcdisplay.h" +#include "genfb.h" #if (NVGA > 0) || (NEGA > 0) || (NPCDISPLAY > 0) #include <dev/ic/mc6845reg.h> #include <dev/ic/pcdisplayvar.h> @@ -70,6 +72,10 @@ __KERNEL_RCSID(0, "$NetBSD: consinit.c,v #include <dev/usb/ukbdvar.h> #endif +#if (NGENFB > 0) +#include <dev/wsfb/genfbvar.h> +#endif + #include "opt_xen.h" #if (XEN > 0) #include <xen/xen.h> @@ -146,14 +152,26 @@ consinit(void) { static int initted = 0; union xen_cmdline_parseinfo xcp; +#if (NGENFB > 0) + const struct btinfo_framebuffer *fbinfo = NULL; +#endif + if (initted) { return; } + + xen_early_console(); + +#if (NGENFB > 0) && defined(DOM0OPS) + if (xendomain_is_dom0()) + fbinfo = xen_genfb_getbtinfo(); +#endif + initted = 1; xen_parse_cmdline(XEN_PARSE_CONSOLE, &xcp); -#if (NVGA > 0) +#if (NVGA > 0) || (NGENFB > 0) if (xendomain_is_privileged()) { #ifdef CONS_OVERRIDE if (strcmp(default_consinfo.devname, "tty0") == 0 || @@ -163,9 +181,26 @@ consinit(void) strcmp(xcp.xcp_console, "pc") == 0) { /* NetBSD name */ #endif /* CONS_OVERRIDE */ int error; + +#if (NGENFB > 0) + if (fbinfo && fbinfo->physaddr > 0) { + if (x86_genfb_cnattach() == -1) { + initted = 0; /* defer */ + return; + } + genfb_cnattach(); + goto dokbd; + } else { + genfb_disable(); + } +#endif vga_cnattach(x86_bus_space_io, x86_bus_space_mem, -1, 1); +#if (NGENFB > 0) +dokbd: +#endif error = ENODEV; + #if (NPCKBC > 0) error = pckbc_cnattach(x86_bus_space_io, IO_KBD, KBCMDP, PCKBC_KBD_SLOT, 0); Added files: Index: src/sys/arch/xen/xen/genfb_xen.c diff -u /dev/null src/sys/arch/xen/xen/genfb_xen.c:1.1 --- /dev/null Tue Oct 17 12:07:42 2023 +++ src/sys/arch/xen/xen/genfb_xen.c Tue Oct 17 12:07:42 2023 @@ -0,0 +1,81 @@ +/* $NetBSD: genfb_xen.c,v 1.1 2023/10/17 12:07:42 bouyer Exp $ */ + +/* + * Copyright (c) 2023 Manuel Bouyer. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#include <sys/cdefs.h> +__KERNEL_RCSID(0, "$NetBSD: genfb_xen.c,v 1.1 2023/10/17 12:07:42 bouyer Exp $"); + + +#include <sys/device.h> +#include <xen/include/xen.h> +#include <xen/include/hypervisor.h> +#include <xen/include/public/xen.h> +#include <arch/x86/include/genfb_machdep.h> +#include <arch/x86/include/bootinfo.h> + +static struct btinfo_framebuffer _xen_genfb_btinfo = {0}; + +const struct btinfo_framebuffer * +xen_genfb_getbtinfo(void) +{ + dom0_vga_console_info_t *d0_consi; + + if (!xendomain_is_dom0()) + return NULL; + + if (_xen_genfb_btinfo.common.type == BTINFO_FRAMEBUFFER) + return &_xen_genfb_btinfo; + + d0_consi = (void *)((char *)&xen_start_info + + xen_start_info.console.dom0.info_off); + + if (d0_consi->video_type != XEN_VGATYPE_VESA_LFB && + d0_consi->video_type != XEN_VGATYPE_EFI_LFB) + return NULL; + + _xen_genfb_btinfo.common.type = BTINFO_FRAMEBUFFER; + _xen_genfb_btinfo.common.len = sizeof(struct btinfo_framebuffer); + _xen_genfb_btinfo.physaddr = d0_consi->u.vesa_lfb.lfb_base; + if (xen_start_info.console.dom0.info_size >= + offsetof(dom0_vga_console_info_t, u.vesa_lfb.ext_lfb_base)) { + _xen_genfb_btinfo.physaddr |= + (uint64_t)d0_consi->u.vesa_lfb.ext_lfb_base << 32; + } + _xen_genfb_btinfo.flags = 0; + _xen_genfb_btinfo.width = d0_consi->u.vesa_lfb.width; + _xen_genfb_btinfo.height = d0_consi->u.vesa_lfb.height; + _xen_genfb_btinfo.stride = d0_consi->u.vesa_lfb.bytes_per_line; + _xen_genfb_btinfo.depth = d0_consi->u.vesa_lfb.bits_per_pixel; + _xen_genfb_btinfo.rnum = d0_consi->u.vesa_lfb.red_pos; + _xen_genfb_btinfo.gnum = d0_consi->u.vesa_lfb.green_pos; + _xen_genfb_btinfo.bnum = d0_consi->u.vesa_lfb.blue_pos; + _xen_genfb_btinfo.rpos = d0_consi->u.vesa_lfb.red_size; + _xen_genfb_btinfo.gpos = d0_consi->u.vesa_lfb.green_size; + _xen_genfb_btinfo.bpos = d0_consi->u.vesa_lfb.blue_size; + _xen_genfb_btinfo.vbemode = 0; /* XXX */ + + return &_xen_genfb_btinfo; +}