Module Name:    src
Committed By:   christos
Date:           Fri May 17 18:34:33 UTC 2019

Modified Files:
        src/sys/arch/x86/pci: pci_machdep.c

Log Message:
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).


To generate a diff of this commit:
cvs rdiff -u -r1.84 -r1.85 src/sys/arch/x86/pci/pci_machdep.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/pci/pci_machdep.c
diff -u src/sys/arch/x86/pci/pci_machdep.c:1.84 src/sys/arch/x86/pci/pci_machdep.c:1.85
--- src/sys/arch/x86/pci/pci_machdep.c:1.84	Mon Feb 11 09:59:33 2019
+++ src/sys/arch/x86/pci/pci_machdep.c	Fri May 17 14:34:33 2019
@@ -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 @@ x86_genfb_resume(device_t dev, const pmf
 	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 @@ device_pci_register(device_t dev, void *
 	}
 	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);
-
-				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);
+			populate_fbinfo(dev, dict);
 
-					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 @@ device_pci_register(device_t dev, void *
 
 			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;

Reply via email to