Module Name: src Committed By: nonaka Date: Sat Nov 30 05:28:28 UTC 2019
Modified Files: src/sys/arch/x86/include: genfb_machdep.h src/sys/arch/x86/x86: genfb_machdep.c hyperv.c Log Message: Prevent panic when attaching genfb if using a serial console with Hyper-V Gen.2. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/sys/arch/x86/include/genfb_machdep.h cvs rdiff -u -r1.14 -r1.15 src/sys/arch/x86/x86/genfb_machdep.c cvs rdiff -u -r1.4 -r1.5 src/sys/arch/x86/x86/hyperv.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.3 src/sys/arch/x86/include/genfb_machdep.h:1.4 --- src/sys/arch/x86/include/genfb_machdep.h:1.3 Wed Feb 9 13:24:23 2011 +++ src/sys/arch/x86/include/genfb_machdep.h Sat Nov 30 05:28:28 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: genfb_machdep.h,v 1.3 2011/02/09 13:24:23 jmcneill Exp $ */ +/* $NetBSD: genfb_machdep.h,v 1.4 2019/11/30 05:28:28 nonaka Exp $ */ /*- * Copyright (c) 2009 Jared D. McNeill <jmcne...@invisible.ca> @@ -29,6 +29,7 @@ #ifndef _X86_GENFB_MACHDEP_H #define _X86_GENFB_MACHDEP_H +int x86_genfb_init(void); int x86_genfb_cnattach(void); void x86_genfb_mtrr_init(uint64_t, uint32_t); void x86_genfb_set_console_dev(device_t); Index: src/sys/arch/x86/x86/genfb_machdep.c diff -u src/sys/arch/x86/x86/genfb_machdep.c:1.14 src/sys/arch/x86/x86/genfb_machdep.c:1.15 --- src/sys/arch/x86/x86/genfb_machdep.c:1.14 Tue Oct 1 18:00:08 2019 +++ src/sys/arch/x86/x86/genfb_machdep.c Sat Nov 30 05:28:28 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: genfb_machdep.c,v 1.14 2019/10/01 18:00:08 chs Exp $ */ +/* $NetBSD: genfb_machdep.c,v 1.15 2019/11/30 05:28:28 nonaka 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.14 2019/10/01 18:00:08 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: genfb_machdep.c,v 1.15 2019/11/30 05:28:28 nonaka Exp $"); #include "opt_mtrr.h" @@ -136,23 +136,19 @@ x86_genfb_mtrr_init(uint64_t physaddr, u } int -x86_genfb_cnattach(void) +x86_genfb_init(void) { - static int ncalls = 0; + static int inited, attached; struct rasops_info *ri = &x86_genfb_console_screen.scr_ri; const struct btinfo_framebuffer *fbinfo; bus_space_tag_t t = x86_bus_space_mem; bus_space_handle_t h; void *bits; - long defattr; int err; - /* XXX jmcneill - * Defer console initialization until UVM is initialized - */ - ++ncalls; - if (ncalls < 3) - return -1; + if (inited) + return attached; + inited = 1; memset(&x86_genfb_console_screen, 0, sizeof(x86_genfb_console_screen)); @@ -202,6 +198,27 @@ x86_genfb_cnattach(void) x86_genfb_stdscreen.textops = &ri->ri_ops; x86_genfb_stdscreen.capabilities = ri->ri_caps; + attached = 1; + return 1; +} + +int +x86_genfb_cnattach(void) +{ + static int ncalls = 0; + struct rasops_info *ri = &x86_genfb_console_screen.scr_ri; + long defattr; + + /* XXX jmcneill + * Defer console initialization until UVM is initialized + */ + ++ncalls; + if (ncalls < 3) + return -1; + + if (!x86_genfb_init()) + return 0; + ri->ri_ops.allocattr(ri, 0, 0, 0, &defattr); wsdisplay_preattach(&x86_genfb_stdscreen, ri, 0, 0, defattr); @@ -209,6 +226,12 @@ x86_genfb_cnattach(void) } #else /* NWSDISPLAY > 0 && NGENFB > 0 */ int +x86_genfb_init(void) +{ + return 0; +} + +int x86_genfb_cnattach(void) { return 0; Index: src/sys/arch/x86/x86/hyperv.c diff -u src/sys/arch/x86/x86/hyperv.c:1.4 src/sys/arch/x86/x86/hyperv.c:1.5 --- src/sys/arch/x86/x86/hyperv.c:1.4 Mon Jun 3 09:51:04 2019 +++ src/sys/arch/x86/x86/hyperv.c Sat Nov 30 05:28:28 2019 @@ -1,4 +1,4 @@ -/* $NetBSD: hyperv.c,v 1.4 2019/06/03 09:51:04 nonaka Exp $ */ +/* $NetBSD: hyperv.c,v 1.5 2019/11/30 05:28:28 nonaka Exp $ */ /*- * Copyright (c) 2009-2012,2016-2017 Microsoft Corp. @@ -33,7 +33,7 @@ */ #include <sys/cdefs.h> #ifdef __KERNEL_RCSID -__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.4 2019/06/03 09:51:04 nonaka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.5 2019/11/30 05:28:28 nonaka Exp $"); #endif #ifdef __FBSDID __FBSDID("$FreeBSD: head/sys/dev/hyperv/vmbus/hyperv.c 331757 2018-03-30 02:25:12Z emaste $"); @@ -70,7 +70,7 @@ __FBSDID("$FreeBSD: head/sys/dev/hyperv/ #include <x86/efi.h> #include <dev/wsfb/genfbvar.h> -#include <arch/x86/include/genfb_machdep.h> +#include <x86/genfb_machdep.h> #include <x86/x86/hypervreg.h> #include <x86/x86/hypervvar.h> @@ -1103,6 +1103,9 @@ device_hyperv_register(device_t dev, voi sizeof(*aa->aa_type)) == 0) { prop_dictionary_t dict = device_properties(dev); + /* Initialize genfb for serial console */ + x86_genfb_init(); + /* * framebuffer drivers other than genfb can work * without the address property