Module Name: src Committed By: martin Date: Wed Oct 18 16:53:04 UTC 2023
Modified Files: src/sys/arch/amd64/conf [netbsd-10]: XEN3_DOM0 src/sys/arch/i386/conf [netbsd-10]: XEN3PAE_DOM0 src/sys/arch/x86/include [netbsd-10]: genfb_machdep.h src/sys/arch/x86/pci [netbsd-10]: pci_machdep.c src/sys/arch/x86/x86 [netbsd-10]: consinit.c genfb_machdep.c src/sys/arch/xen/conf [netbsd-10]: files.xen src/sys/arch/xen/include [netbsd-10]: hypervisor.h src/sys/arch/xen/x86 [netbsd-10]: autoconf.c consinit.c pvh_consinit.c src/sys/arch/xen/xen [netbsd-10]: xen_machdep.c src/sys/external/mit/xen-include-public/dist/xen/include/public [netbsd-10]: platform.h xen.h Added Files: src/sys/arch/xen/xen [netbsd-10]: genfb_xen.c Log Message: Pull up following revision(s) (requested by bouyer in ticket #428): sys/arch/xen/xen/xen_machdep.c: revision 1.28 sys/arch/x86/pci/pci_machdep.c: revision 1.97 sys/arch/xen/xen/genfb_xen.c: revision 1.1 sys/arch/xen/xen/genfb_xen.c: revision 1.2 sys/arch/xen/include/hypervisor.h: revision 1.59 sys/arch/i386/conf/XEN3PAE_DOM0: revision 1.41 (patch) sys/arch/x86/x86/genfb_machdep.c: revision 1.22 sys/arch/xen/x86/consinit.c: revision 1.18 sys/arch/xen/x86/autoconf.c: revision 1.26 sys/external/mit/xen-include-public/dist/xen/include/public/platform.h: revision 1.2 sys/arch/xen/conf/files.xen: revision 1.188 sys/arch/x86/x86/consinit.c: revision 1.37 sys/arch/xen/conf/files.xen: revision 1.189 sys/arch/x86/x86/consinit.c: revision 1.38 sys/external/mit/xen-include-public/dist/xen/include/public/xen.h: revision 1.2 sys/arch/x86/include/genfb_machdep.h: revision 1.7 sys/arch/xen/x86/pvh_consinit.c: revision 1.5 sys/arch/xen/x86/pvh_consinit.c: revision 1.6 sys/arch/amd64/conf/XEN3_DOM0: revision 1.201 Move the pvh_xencons so xen_machdep.c as early_xencons, so it can be used in the future as early ouput for plain PV guests too. 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. Make sure to always fall back to xen_early_console, even for dom0 Enable genfb in DOM0 kernels Add ext_lfb_base to dom0_vga_console_info, from recent Xen. We know if it's present or not by checking dom0.info_size Add XENPF_get_dom0_console, which gets a dom0_vga_console_info stucture from the hypervisor. To be used by PVH dom0 kernels. XENPVH option is not used. Fix consinit.c to use XENPVHVM as intended and XENPVH from defflag for a dom0 PVH, the dom0_vga_console_info structure has to be retrieved using a platform hypercall; do so in the XENPVHVM case. Now genfb works in a PVH dom0 running on Xen 4.18 (Xen 4.15 doesn't support this platoform op, so no way to make it work here). To generate a diff of this commit: cvs rdiff -u -r1.197.4.2 -r1.197.4.3 src/sys/arch/amd64/conf/XEN3_DOM0 cvs rdiff -u -r1.36.4.1 -r1.36.4.2 src/sys/arch/i386/conf/XEN3PAE_DOM0 cvs rdiff -u -r1.5.18.1 -r1.5.18.2 src/sys/arch/x86/include/genfb_machdep.h cvs rdiff -u -r1.93.4.2 -r1.93.4.3 src/sys/arch/x86/pci/pci_machdep.c cvs rdiff -u -r1.35.4.1 -r1.35.4.2 src/sys/arch/x86/x86/consinit.c cvs rdiff -u -r1.19.4.1 -r1.19.4.2 src/sys/arch/x86/x86/genfb_machdep.c cvs rdiff -u -r1.187 -r1.187.4.1 src/sys/arch/xen/conf/files.xen cvs rdiff -u -r1.55.4.2 -r1.55.4.3 src/sys/arch/xen/include/hypervisor.h cvs rdiff -u -r1.25 -r1.25.20.1 src/sys/arch/xen/x86/autoconf.c cvs rdiff -u -r1.16 -r1.16.68.1 src/sys/arch/xen/x86/consinit.c cvs rdiff -u -r1.2.20.1 -r1.2.20.2 src/sys/arch/xen/x86/pvh_consinit.c cvs rdiff -u -r0 -r1.2.2.2 src/sys/arch/xen/xen/genfb_xen.c cvs rdiff -u -r1.27 -r1.27.4.1 src/sys/arch/xen/xen/xen_machdep.c cvs rdiff -u -r1.1.1.1 -r1.1.1.1.32.1 \ src/sys/external/mit/xen-include-public/dist/xen/include/public/platform.h \ src/sys/external/mit/xen-include-public/dist/xen/include/public/xen.h 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/amd64/conf/XEN3_DOM0 diff -u src/sys/arch/amd64/conf/XEN3_DOM0:1.197.4.2 src/sys/arch/amd64/conf/XEN3_DOM0:1.197.4.3 --- src/sys/arch/amd64/conf/XEN3_DOM0:1.197.4.2 Mon Oct 9 23:33:45 2023 +++ src/sys/arch/amd64/conf/XEN3_DOM0 Wed Oct 18 16:53:04 2023 @@ -1,4 +1,4 @@ -# $NetBSD: XEN3_DOM0,v 1.197.4.2 2023/10/09 23:33:45 snj Exp $ +# $NetBSD: XEN3_DOM0,v 1.197.4.3 2023/10/18 16:53:04 martin Exp $ # XEN3_DOM0 machine description file # @@ -14,7 +14,7 @@ include "arch/amd64/conf/std.xen" options INCLUDE_CONFIG_FILE # embed config file in kernel binary -#ident "XEN3_DOM0-$Revision: 1.197.4.2 $" +#ident "XEN3_DOM0-$Revision: 1.197.4.3 $" maxusers 32 # estimated number of users @@ -439,8 +439,8 @@ options PMS_SYNAPTICS_TOUCHPAD # Enable options PMS_ELANTECH_TOUCHPAD # Enable support for Elantech Touchpads options PMS_ALPS_TOUCHPAD # Enable support for Alps Touchpads vga* at pci? dev ? function ? -#genfb* at pci? dev ? function ?# Needs acpi_md_vesa_modenum - # in acpi_wakeup.c (!xenpv) +genfb* at pci? dev ? function ? + #options VCONS_DRAW_INTR #wsdisplay* at vga? console ? wsdisplay* at wsemuldisplaydev? Index: src/sys/arch/i386/conf/XEN3PAE_DOM0 diff -u src/sys/arch/i386/conf/XEN3PAE_DOM0:1.36.4.1 src/sys/arch/i386/conf/XEN3PAE_DOM0:1.36.4.2 --- src/sys/arch/i386/conf/XEN3PAE_DOM0:1.36.4.1 Mon Oct 9 23:33:46 2023 +++ src/sys/arch/i386/conf/XEN3PAE_DOM0 Wed Oct 18 16:53:03 2023 @@ -1,4 +1,4 @@ -# $NetBSD: XEN3PAE_DOM0,v 1.36.4.1 2023/10/09 23:33:46 snj Exp $ +# $NetBSD: XEN3PAE_DOM0,v 1.36.4.2 2023/10/18 16:53:03 martin Exp $ # # XEN3_0: Xen 3.0 domain0 kernel @@ -526,6 +526,7 @@ pms* at pckbc? # PS/2 mouse for wsmous options PMS_SYNAPTICS_TOUCHPAD # Enable support for Synaptics Touchpads #vga0 at isa? vga* at pci? dev ? function ? +genfb* at pci? dev ? function ? #pcdisplay0 at isa? # CGA, MDA, EGA, HGA #machfb* at pci? dev ? function ? # ATI Mach64 framebuffer driver wsdisplay* at vga? console ? Index: src/sys/arch/x86/include/genfb_machdep.h diff -u src/sys/arch/x86/include/genfb_machdep.h:1.5.18.1 src/sys/arch/x86/include/genfb_machdep.h:1.5.18.2 --- src/sys/arch/x86/include/genfb_machdep.h:1.5.18.1 Wed Oct 18 15:14:24 2023 +++ src/sys/arch/x86/include/genfb_machdep.h Wed Oct 18 16:53:04 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: genfb_machdep.h,v 1.5.18.1 2023/10/18 15:14:24 martin Exp $ */ +/* $NetBSD: genfb_machdep.h,v 1.5.18.2 2023/10/18 16:53:04 martin 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.93.4.2 src/sys/arch/x86/pci/pci_machdep.c:1.93.4.3 --- src/sys/arch/x86/pci/pci_machdep.c:1.93.4.2 Wed Oct 18 15:14:24 2023 +++ src/sys/arch/x86/pci/pci_machdep.c Wed Oct 18 16:53:03 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: pci_machdep.c,v 1.93.4.2 2023/10/18 15:14:24 martin Exp $ */ +/* $NetBSD: pci_machdep.c,v 1.93.4.3 2023/10/18 16:53:03 martin 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.93.4.2 2023/10/18 15:14:24 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.93.4.3 2023/10/18 16:53:03 martin 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.35.4.1 src/sys/arch/x86/x86/consinit.c:1.35.4.2 --- src/sys/arch/x86/x86/consinit.c:1.35.4.1 Thu Mar 30 11:45:34 2023 +++ src/sys/arch/x86/x86/consinit.c Wed Oct 18 16:53:03 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: consinit.c,v 1.35.4.1 2023/03/30 11:45:34 martin Exp $ */ +/* $NetBSD: consinit.c,v 1.35.4.2 2023/10/18 16:53:03 martin Exp $ */ /* * Copyright (c) 1998 @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.35.4.1 2023/03/30 11:45:34 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.35.4.2 2023/10/18 16:53:03 martin Exp $"); #include "opt_kgdb.h" #include "opt_puc.h" @@ -100,6 +100,7 @@ __KERNEL_RCSID(0, "$NetBSD: consinit.c,v #endif #ifdef XENPVHVM +#include <xen/hypervisor.h> #include <xen/xen.h> #endif @@ -164,7 +165,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 +190,12 @@ consinit(void) consinfo = &default_consinfo; #if (NGENFB > 0) - fbinfo = lookup_bootinfo(BTINFO_FRAMEBUFFER); +#if defined(XENPVHVM) && 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.19.4.1 src/sys/arch/x86/x86/genfb_machdep.c:1.19.4.2 --- src/sys/arch/x86/x86/genfb_machdep.c:1.19.4.1 Wed Oct 18 15:14:24 2023 +++ src/sys/arch/x86/x86/genfb_machdep.c Wed Oct 18 16:53:03 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: genfb_machdep.c,v 1.19.4.1 2023/10/18 15:14:24 martin Exp $ */ +/* $NetBSD: genfb_machdep.c,v 1.19.4.2 2023/10/18 16:53:03 martin 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.19.4.1 2023/10/18 15:14:24 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: genfb_machdep.c,v 1.19.4.2 2023/10/18 16:53:03 martin 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.187.4.1 --- src/sys/arch/xen/conf/files.xen:1.187 Wed Aug 31 12:51:56 2022 +++ src/sys/arch/xen/conf/files.xen Wed Oct 18 16:53:03 2023 @@ -1,6 +1,6 @@ -# $NetBSD: files.xen,v 1.187 2022/08/31 12:51:56 bouyer Exp $ +# $NetBSD: files.xen,v 1.187.4.1 2023/10/18 16:53:03 martin Exp $ -defflag opt_xen.h XEN XENPVH XENPVHVM PAE DOM0OPS +defflag opt_xen.h XEN XENPVHVM PAE DOM0OPS file arch/xen/x86/hypervisor_machdep.c xen file arch/xen/x86/xen_intr.c xen @@ -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/include/hypervisor.h diff -u src/sys/arch/xen/include/hypervisor.h:1.55.4.2 src/sys/arch/xen/include/hypervisor.h:1.55.4.3 --- src/sys/arch/xen/include/hypervisor.h:1.55.4.2 Wed Oct 18 15:19:08 2023 +++ src/sys/arch/xen/include/hypervisor.h Wed Oct 18 16:53:03 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: hypervisor.h,v 1.55.4.2 2023/10/18 15:19:08 martin Exp $ */ +/* $NetBSD: hypervisor.h,v 1.55.4.3 2023/10/18 16:53:03 martin Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -214,4 +214,6 @@ hypervisor_notify_via_evtchn(unsigned in void xen_init_ksyms(void); void xen_map_vcpu(struct cpu_info *); +void xen_early_console(void); + #endif /* _XEN_HYPERVISOR_H_ */ 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.25.20.1 --- src/sys/arch/xen/x86/autoconf.c:1.25 Sat May 2 16:44:36 2020 +++ src/sys/arch/xen/x86/autoconf.c Wed Oct 18 16:53:03 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: autoconf.c,v 1.25 2020/05/02 16:44:36 bouyer Exp $ */ +/* $NetBSD: autoconf.c,v 1.25.20.1 2023/10/18 16:53:03 martin 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.25.20.1 2023/10/18 16:53:03 martin 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.16 src/sys/arch/xen/x86/consinit.c:1.16.68.1 --- src/sys/arch/xen/x86/consinit.c:1.16 Sat Oct 13 17:58:55 2012 +++ src/sys/arch/xen/x86/consinit.c Wed Oct 18 16:53:03 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: consinit.c,v 1.16 2012/10/13 17:58:55 jdc Exp $ */ +/* $NetBSD: consinit.c,v 1.16.68.1 2023/10/18 16:53:03 martin 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.16 2012/10/13 17:58:55 jdc Exp $"); +__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.16.68.1 2023/10/18 16:53:03 martin 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> @@ -145,14 +151,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 || @@ -162,9 +180,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); Index: src/sys/arch/xen/x86/pvh_consinit.c diff -u src/sys/arch/xen/x86/pvh_consinit.c:1.2.20.1 src/sys/arch/xen/x86/pvh_consinit.c:1.2.20.2 --- src/sys/arch/xen/x86/pvh_consinit.c:1.2.20.1 Thu Mar 30 11:45:34 2023 +++ src/sys/arch/xen/x86/pvh_consinit.c Wed Oct 18 16:53:03 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: pvh_consinit.c,v 1.2.20.1 2023/03/30 11:45:34 martin Exp $ */ +/* $NetBSD: pvh_consinit.c,v 1.2.20.2 2023/10/18 16:53:03 martin Exp $ */ /* * Copyright (c) 2020 Manuel Bouyer. @@ -26,7 +26,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pvh_consinit.c,v 1.2.20.1 2023/03/30 11:45:34 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pvh_consinit.c,v 1.2.20.2 2023/10/18 16:53:03 martin Exp $"); #include "xencons.h" #include <sys/param.h> @@ -41,16 +41,6 @@ __KERNEL_RCSID(0, "$NetBSD: pvh_consinit #include <xen/include/public/hvm/hvm_op.h> #include <xen/include/public/hvm/params.h> -static int pvh_xenconscn_getc(dev_t); -static void pvh_xenconscn_putc(dev_t, int); -static void pvh_xenconscn_pollc(dev_t, int); - -static struct consdev pvh_xencons = { - NULL, NULL, pvh_xenconscn_getc, pvh_xenconscn_putc, pvh_xenconscn_pollc, - NULL, NULL, NULL, NODEV, CN_NORMAL -}; - - int xen_pvh_consinit(void) { @@ -59,6 +49,11 @@ xen_pvh_consinit(void) * boot stage. */ static int initted = 0; + + if (initted == 0) { + /* fall back to printk() until we can setup our console */ + xen_early_console(); + } if (xendomain_is_dom0()) { union xen_cmdline_parseinfo xcp; xen_parse_cmdline(XEN_PARSE_CONSOLE, &xcp); @@ -69,12 +64,12 @@ xen_pvh_consinit(void) if (strcmp(xcp.xcp_console, "tty0") == 0 || /* linux name */ strcmp(xcp.xcp_console, "pc") == 0) { /* NetBSD name */ #endif /* CONS_OVERRIDE */ + initted++; return 0; /* native console code will do it */ } } if (initted == 0 && !xendomain_is_dom0()) { - /* pmap not up yet, fall back to printk() */ - cn_tab = &pvh_xencons; + /* pmap not up yet */ initted++; return 1; } else if (initted > 1) { @@ -114,23 +109,3 @@ xen_pvh_consinit(void) #endif return 1; } - -static int -pvh_xenconscn_getc(dev_t dev) -{ - while(1) - ; - return -1; -} - -static void -pvh_xenconscn_putc(dev_t dev, int c) -{ - printk("%c", c); -} - -static void -pvh_xenconscn_pollc(dev_t dev, int on) -{ - return; -} Index: src/sys/arch/xen/xen/xen_machdep.c diff -u src/sys/arch/xen/xen/xen_machdep.c:1.27 src/sys/arch/xen/xen/xen_machdep.c:1.27.4.1 --- src/sys/arch/xen/xen/xen_machdep.c:1.27 Sat Aug 20 23:48:51 2022 +++ src/sys/arch/xen/xen/xen_machdep.c Wed Oct 18 16:53:03 2023 @@ -1,4 +1,4 @@ -/* $NetBSD: xen_machdep.c,v 1.27 2022/08/20 23:48:51 riastradh Exp $ */ +/* $NetBSD: xen_machdep.c,v 1.27.4.1 2023/10/18 16:53:03 martin Exp $ */ /* * Copyright (c) 2006 Manuel Bouyer. @@ -53,7 +53,7 @@ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.27 2022/08/20 23:48:51 riastradh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: xen_machdep.c,v 1.27.4.1 2023/10/18 16:53:03 martin Exp $"); #include "opt_xen.h" @@ -70,6 +70,8 @@ __KERNEL_RCSID(0, "$NetBSD: xen_machdep. #include <sys/pmf.h> #include <sys/xcall.h> +#include <dev/cons.h> + #include <xen/intr.h> #include <xen/hypervisor.h> #include <xen/shutdown_xenbus.h> @@ -440,6 +442,41 @@ printk(const char *fmt, ...) (void)HYPERVISOR_console_io(CONSOLEIO_write, ret, buf); } +static int early_xenconscn_getc(dev_t); +static void early_xenconscn_putc(dev_t, int); +static void early_xenconscn_pollc(dev_t, int); + +static struct consdev early_xencons = { + NULL, NULL, + early_xenconscn_getc, early_xenconscn_putc, early_xenconscn_pollc, + NULL, NULL, NULL, NODEV, CN_NORMAL +}; + +void +xen_early_console(void) +{ + cn_tab = &early_xencons; /* fallback console */ +} + +static int +early_xenconscn_getc(dev_t dev) +{ + while(1) + ; + return -1; +} + +static void +early_xenconscn_putc(dev_t dev, int c) +{ + printk("%c", c); +} + +static void +early_xenconscn_pollc(dev_t dev, int on) +{ + return; +} bool xen_feature_tables[XENFEAT_NR_SUBMAPS * 32]; void Index: src/sys/external/mit/xen-include-public/dist/xen/include/public/platform.h diff -u src/sys/external/mit/xen-include-public/dist/xen/include/public/platform.h:1.1.1.1 src/sys/external/mit/xen-include-public/dist/xen/include/public/platform.h:1.1.1.1.32.1 --- src/sys/external/mit/xen-include-public/dist/xen/include/public/platform.h:1.1.1.1 Sat Feb 2 08:03:48 2019 +++ src/sys/external/mit/xen-include-public/dist/xen/include/public/platform.h Wed Oct 18 16:53:03 2023 @@ -615,6 +615,15 @@ typedef struct xenpf_symdata xenpf_symda DEFINE_XEN_GUEST_HANDLE(xenpf_symdata_t); /* + * Fetch the video console information and mode setup by Xen. A non- + * negative return value indicates the size of the (part of the) structure + * which was filled. + */ +#define XENPF_get_dom0_console 64 +typedef struct dom0_vga_console_info xenpf_dom0_console_t; +DEFINE_XEN_GUEST_HANDLE(xenpf_dom0_console_t); + +/* * ` enum neg_errnoval * ` HYPERVISOR_platform_op(const struct xen_platform_op*); */ @@ -644,6 +653,7 @@ struct xen_platform_op { struct xenpf_core_parking core_parking; struct xenpf_resource_op resource_op; struct xenpf_symdata symdata; + xenpf_dom0_console_t dom0_console; uint8_t pad[128]; } u; }; Index: src/sys/external/mit/xen-include-public/dist/xen/include/public/xen.h diff -u src/sys/external/mit/xen-include-public/dist/xen/include/public/xen.h:1.1.1.1 src/sys/external/mit/xen-include-public/dist/xen/include/public/xen.h:1.1.1.1.32.1 --- src/sys/external/mit/xen-include-public/dist/xen/include/public/xen.h:1.1.1.1 Sat Feb 2 08:03:48 2019 +++ src/sys/external/mit/xen-include-public/dist/xen/include/public/xen.h Wed Oct 18 16:53:03 2023 @@ -922,6 +922,8 @@ typedef struct dom0_vga_console_info { uint32_t gbl_caps; /* Mode attributes (offset 0x0, VESA command 0x4f01). */ uint16_t mode_attrs; + /* high 32 bits of lfb_base */ + uint32_t ext_lfb_base; #endif } vesa_lfb; } u; Added files: Index: src/sys/arch/xen/xen/genfb_xen.c diff -u /dev/null src/sys/arch/xen/xen/genfb_xen.c:1.2.2.2 --- /dev/null Wed Oct 18 16:53:04 2023 +++ src/sys/arch/xen/xen/genfb_xen.c Wed Oct 18 16:53:03 2023 @@ -0,0 +1,95 @@ +/* $NetBSD: genfb_xen.c,v 1.2.2.2 2023/10/18 16:53:03 martin 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.2.2.2 2023/10/18 16:53:03 martin 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; + int info_size; + + if (!xendomain_is_dom0()) + return NULL; + + if (_xen_genfb_btinfo.common.type == BTINFO_FRAMEBUFFER) + return &_xen_genfb_btinfo; + +#ifdef XENPVHVM + struct xen_platform_op op = { + .cmd = XENPF_get_dom0_console, + }; + info_size = HYPERVISOR_platform_op(&op); + if (info_size < sizeof(dom0_vga_console_info_t)) { + printf("XENPF_get_dom0_console fail %d\n", info_size); + return NULL; + } + d0_consi = &op.u.dom0_console; +#else + d0_consi = (void *)((char *)&xen_start_info + + xen_start_info.console.dom0.info_off); + info_size = xen_start_info.console.dom0.info_size; +#endif + + 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 (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; +}