Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/x86 Prevent panic when attaching genfb if using a s...



details:   https://anonhg.NetBSD.org/src/rev/cbaee35d46e6
branches:  trunk
changeset: 461563:cbaee35d46e6
user:      nonaka <nonaka%NetBSD.org@localhost>
date:      Sat Nov 30 05:28:28 2019 +0000

description:
Prevent panic when attaching genfb if using a serial console with Hyper-V Gen.2.

diffstat:

 sys/arch/x86/include/genfb_machdep.h |   3 +-
 sys/arch/x86/x86/genfb_machdep.c     |  45 +++++++++++++++++++++++++++--------
 sys/arch/x86/x86/hyperv.c            |   9 ++++--
 3 files changed, 42 insertions(+), 15 deletions(-)

diffs (142 lines):

diff -r ff3679a85fea -r cbaee35d46e6 sys/arch/x86/include/genfb_machdep.h
--- a/sys/arch/x86/include/genfb_machdep.h      Sat Nov 30 04:06:22 2019 +0000
+++ b/sys/arch/x86/include/genfb_machdep.h      Sat Nov 30 05:28:28 2019 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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);
diff -r ff3679a85fea -r cbaee35d46e6 sys/arch/x86/x86/genfb_machdep.c
--- a/sys/arch/x86/x86/genfb_machdep.c  Sat Nov 30 04:06:22 2019 +0000
+++ b/sys/arch/x86/x86/genfb_machdep.c  Sat Nov 30 05:28:28 2019 +0000
@@ -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 <jmcneill%invisible.ca@localhost>
@@ -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 @@
 }
 
 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_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 @@
 }
 #else  /* NWSDISPLAY > 0 && NGENFB > 0 */
 int
+x86_genfb_init(void)
+{
+       return 0;
+}
+
+int
 x86_genfb_cnattach(void)
 {
        return 0;
diff -r ff3679a85fea -r cbaee35d46e6 sys/arch/x86/x86/hyperv.c
--- a/sys/arch/x86/x86/hyperv.c Sat Nov 30 04:06:22 2019 +0000
+++ b/sys/arch/x86/x86/hyperv.c Sat Nov 30 05:28:28 2019 +0000
@@ -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 @@
 #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 @@
                    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



Home | Main Index | Thread Index | Old Index