Source-Changes-HG archive

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

[src/trunk]: src/sys/arch/x86/pci Factor out the fbinfo setting code, to make...



details:   https://anonhg.NetBSD.org/src/rev/b0c2c3f12cb3
branches:  trunk
changeset: 451357:b0c2c3f12cb3
user:      christos <christos%NetBSD.org@localhost>
date:      Fri May 17 18:34:33 2019 +0000

description:
Factor out the fbinfo setting code, to make it more readable, and use
memcpy to properly align the structure (although it does not matter on x86).

diffstat:

 sys/arch/x86/pci/pci_machdep.c |  137 +++++++++++++++++++---------------------
 1 files changed, 66 insertions(+), 71 deletions(-)

diffs (185 lines):

diff -r e1848b76433b -r b0c2c3f12cb3 sys/arch/x86/pci/pci_machdep.c
--- a/sys/arch/x86/pci/pci_machdep.c    Fri May 17 13:51:36 2019 +0000
+++ b/sys/arch/x86/pci/pci_machdep.c    Fri May 17 18:34:33 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci_machdep.c,v 1.84 2019/02/11 14:59:33 cherry Exp $  */
+/*     $NetBSD: pci_machdep.c,v 1.85 2019/05/17 18:34:33 christos 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.84 2019/02/11 14:59:33 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.85 2019/05/17 18:34:33 christos Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -1054,6 +1054,66 @@
        return true;
 }
 
+static void
+populate_fbinfo(device_t dev, prop_dictionary_t dict)
+{
+#if NWSDISPLAY > 0 && NGENFB > 0
+       extern struct vcons_screen x86_genfb_console_screen;
+       struct rasops_info *ri = &x86_genfb_console_screen.scr_ri;
+#endif
+       const void *fbptr = lookup_bootinfo(BTINFO_FRAMEBUFFER);
+       struct btinfo_framebuffer fbinfo;
+
+       if (fbptr == NULL)
+               return;
+
+       memcpy(&fbinfo, fbptr, sizeof(fbinfo));
+
+       if (fbinfo.physaddr != 0) {
+               prop_dictionary_set_uint32(dict, "width", fbinfo.width);
+               prop_dictionary_set_uint32(dict, "height", fbinfo.height);
+               prop_dictionary_set_uint8(dict, "depth", fbinfo.depth);
+               prop_dictionary_set_uint16(dict, "linebytes", fbinfo.stride);
+
+               prop_dictionary_set_uint64(dict, "address", fbinfo.physaddr);
+#if NWSDISPLAY > 0 && NGENFB > 0
+               if (ri->ri_bits != NULL) {
+                       prop_dictionary_set_uint64(dict, "virtual_address",
+                           ri->ri_hwbits != NULL ?
+                           (vaddr_t)ri->ri_hworigbits :
+                           (vaddr_t)ri->ri_origbits);
+               }
+#endif
+       }
+#if notyet
+       prop_dictionary_set_bool(dict, "splash", 
+           (fbinfo.flags & BI_FB_SPLASH) != 0);
+#endif
+       if (fbinfo.depth == 8) {
+               gfb_cb.gcc_cookie = NULL;
+               gfb_cb.gcc_set_mapreg = x86_genfb_set_mapreg;
+               prop_dictionary_set_uint64(dict, "cmap_callback",
+                   (uint64_t)(uintptr_t)&gfb_cb);
+       }
+       if (fbinfo.physaddr != 0) {
+               mode_cb.gmc_setmode = x86_genfb_setmode;
+               prop_dictionary_set_uint64(dict, "mode_callback",
+                   (uint64_t)(uintptr_t)&mode_cb);
+       }
+
+#if NWSDISPLAY > 0 && NGENFB > 0
+       if (device_is_a(dev, "genfb")) {
+               prop_dictionary_set_bool(dict, "enable_shadowfb",
+                   ri->ri_hwbits != NULL);
+
+               x86_genfb_set_console_dev(dev);
+#ifdef DDB
+               db_trap_callback = x86_genfb_ddb_trap_callback;
+#endif
+       }
+#endif
+}
+
 device_t
 device_pci_register(device_t dev, void *aux)
 {
@@ -1112,82 +1172,16 @@
        }
        if (parent && device_is_a(parent, "pci") &&
            found_console == false) {
-               struct btinfo_framebuffer *fbinfo;
                struct pci_attach_args *pa = aux;
-               prop_dictionary_t dict;
 
                if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY) {
-#if NWSDISPLAY > 0 && NGENFB > 0
-                       extern struct vcons_screen x86_genfb_console_screen;
-                       struct rasops_info *ri;
-
-                       ri = &x86_genfb_console_screen.scr_ri;
-#endif
-
-                       fbinfo = lookup_bootinfo(BTINFO_FRAMEBUFFER);
-                       dict = device_properties(dev);
+                       prop_dictionary_t dict = device_properties(dev);
                        /*
                         * framebuffer drivers other than genfb can work
                         * without the address property
                         */
-                       if (fbinfo != NULL) {
-                               if (fbinfo->physaddr != 0) {
-                               prop_dictionary_set_uint32(dict, "width",
-                                   fbinfo->width);
-                               prop_dictionary_set_uint32(dict, "height",
-                                   fbinfo->height);
-                               prop_dictionary_set_uint8(dict, "depth",
-                                   fbinfo->depth);
-                               prop_dictionary_set_uint16(dict, "linebytes",
-                                   fbinfo->stride);
+                       populate_fbinfo(dev, dict);
 
-                               prop_dictionary_set_uint64(dict, "address",
-                                   fbinfo->physaddr);
-#if NWSDISPLAY > 0 && NGENFB > 0
-                               if (ri->ri_bits != NULL) {
-                                       prop_dictionary_set_uint64(dict,
-                                           "virtual_address",
-                                           ri->ri_hwbits != NULL ?
-                                           (vaddr_t)ri->ri_hworigbits :
-                                           (vaddr_t)ri->ri_origbits);
-                               }
-#endif
-                               }
-#if notyet
-                               prop_dictionary_set_bool(dict, "splash",
-                                   fbinfo->flags & BI_FB_SPLASH ?
-                                    true : false);
-#endif
-                               if (fbinfo->depth == 8) {
-                                       gfb_cb.gcc_cookie = NULL;
-                                       gfb_cb.gcc_set_mapreg =
-                                           x86_genfb_set_mapreg;
-                                       prop_dictionary_set_uint64(dict,
-                                           "cmap_callback",
-                                           (uint64_t)(uintptr_t)&gfb_cb);
-                               }
-                               if (fbinfo->physaddr != 0) {
-                                       mode_cb.gmc_setmode = x86_genfb_setmode;
-                                       prop_dictionary_set_uint64(dict,
-                                           "mode_callback",
-                                           (uint64_t)(uintptr_t)&mode_cb);
-                               }
-
-#if NWSDISPLAY > 0 && NGENFB > 0
-                               if (device_is_a(dev, "genfb")) {
-                                       prop_dictionary_set_bool(dict,
-                                           "enable_shadowfb",
-                                           ri->ri_hwbits != NULL ?
-                                             true : false);
-
-                                       x86_genfb_set_console_dev(dev);
-#ifdef DDB
-                                       db_trap_callback =
-                                           x86_genfb_ddb_trap_callback;
-#endif
-                               }
-#endif
-                       }
 #if 1 && NWSDISPLAY > 0 && NGENFB > 0
                        /* XXX */
                        if (device_is_a(dev, "genfb")) {
@@ -1199,12 +1193,13 @@
 
                        prop_dictionary_set_bool(dict, "clear-screen", false);
 #if NWSDISPLAY > 0 && NGENFB > 0
+                       extern struct vcons_screen x86_genfb_console_screen;
                        prop_dictionary_set_uint16(dict, "cursor-row",
                            x86_genfb_console_screen.scr_ri.ri_crow);
 #endif
 #if notyet
                        prop_dictionary_set_bool(dict, "splash",
-                           fbinfo->flags & BI_FB_SPLASH ? true : false);
+                           (fbinfo->flags & BI_FB_SPLASH) != 0);
 #endif
                        pmf_cb.gpc_suspend = x86_genfb_suspend;
                        pmf_cb.gpc_resume = x86_genfb_resume;



Home | Main Index | Thread Index | Old Index