CVS commit: src/sys/dev/wsfb

2024-01-19 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan 20 00:24:58 UTC 2024

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
wsfb: add support for optional "devcmap" property

A hardware driver can supply a pointer to a 16x 32-bit array to override
the default rasops device colour map in the "devcmap" property.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/dev/wsfb/genfb.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/dev/wsfb/genfb.c
diff -u src/sys/dev/wsfb/genfb.c:1.90 src/sys/dev/wsfb/genfb.c:1.91
--- src/sys/dev/wsfb/genfb.c:1.90	Mon Aug  1 23:30:10 2022
+++ src/sys/dev/wsfb/genfb.c	Sat Jan 20 00:24:58 2024
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfb.c,v 1.90 2022/08/01 23:30:10 riastradh Exp $ */
+/*	$NetBSD: genfb.c,v 1.91 2024/01/20 00:24:58 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.90 2022/08/01 23:30:10 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.91 2024/01/20 00:24:58 jmcneill Exp $");
 
 #include 
 #include 
@@ -85,6 +85,7 @@ struct genfb_private {
 	struct genfb_parameter_callback *sc_backlight;
 	struct genfb_parameter_callback *sc_brightness;
 	struct genfb_mode_callback *sc_modecb;
+	uint32_t *sc_devcmap;
 	int sc_backlight_level, sc_backlight_on;
 	void *sc_shadowfb;
 	bool sc_enable_shadowfb;
@@ -167,7 +168,7 @@ genfb_init(struct genfb_softc *sc)
 {
 	struct genfb_private *scp;
 	prop_dictionary_t dict;
-	uint64_t cmap_cb, pmf_cb, mode_cb, bl_cb, br_cb, fbaddr;
+	uint64_t cmap_cb, pmf_cb, mode_cb, bl_cb, br_cb, devcmap, fbaddr;
 	uint64_t fboffset;
 	bool console;
 
@@ -225,6 +226,13 @@ genfb_init(struct genfb_softc *sc)
 
 	sc->sc_fbsize = sc->sc_height * sc->sc_stride;
 
+	/* optional device colour map */
+	scp->sc_devcmap = NULL;
+	if (prop_dictionary_get_uint64(dict, "devcmap", )) {
+		if (devcmap != 0)
+			scp->sc_devcmap = (uint32_t *)(uintptr_t)devcmap;
+	}
+
 	/* optional colour map callback */
 	scp->sc_cmcb = NULL;
 	if (prop_dictionary_get_uint64(dict, "cmap_callback", _cb)) {
@@ -721,6 +729,10 @@ genfb_init_screen(void *cookie, struct v
 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
 	sc->sc_width / ri->ri_font->fontwidth);
 
+	if (scp->sc_devcmap != NULL) {
+		memcpy(ri->ri_devcmap, scp->sc_devcmap, sizeof(ri->ri_devcmap));
+	}
+
 	ri->ri_hw = scr;
 #if GENFB_GLYPHCACHE > 0
 	scp->sc_putchar = ri->ri_ops.putchar;



CVS commit: src/sys/dev/wsfb

2024-01-19 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Sat Jan 20 00:24:58 UTC 2024

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
wsfb: add support for optional "devcmap" property

A hardware driver can supply a pointer to a 16x 32-bit array to override
the default rasops device colour map in the "devcmap" property.


To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.91 src/sys/dev/wsfb/genfb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/wsfb

2022-08-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug  1 23:30:10 UTC 2022

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
genfb: Handle uninitialized softc in genfb_enable/disable_polling.

This can happen due to janky MD kludgerosity like x86
x86_genfb_ddb_trap_callback, which should really be cleaned up, but
at least this might help with the recursive traps we've been seeing
in syzbot.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/dev/wsfb/genfb.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/dev/wsfb/genfb.c
diff -u src/sys/dev/wsfb/genfb.c:1.89 src/sys/dev/wsfb/genfb.c:1.90
--- src/sys/dev/wsfb/genfb.c:1.89	Sun Jul 17 13:10:54 2022
+++ src/sys/dev/wsfb/genfb.c	Mon Aug  1 23:30:10 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfb.c,v 1.89 2022/07/17 13:10:54 riastradh Exp $ */
+/*	$NetBSD: genfb.c,v 1.90 2022/08/01 23:30:10 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.89 2022/07/17 13:10:54 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.90 2022/08/01 23:30:10 riastradh Exp $");
 
 #include 
 #include 
@@ -985,6 +985,9 @@ genfb_enable_polling(device_t dev)
 	struct genfb_softc *sc = device_private(dev);
 	struct genfb_private *scp = sc->sc_private;
 
+	if (scp == NULL)
+		return;
+
 	if (scp->sc_console_screen.scr_vd) {
 		SCREEN_ENABLE_DRAWING(>sc_console_screen);
 		vcons_hard_switch(>sc_console_screen);
@@ -1000,6 +1003,9 @@ genfb_disable_polling(device_t dev)
 	struct genfb_softc *sc = device_private(dev);
 	struct genfb_private *scp = sc->sc_private;
 
+	if (scp == NULL)
+		return;
+
 	if (scp->sc_console_screen.scr_vd) {
 		if (scp->sc_ops.genfb_disable_polling)
 			(*scp->sc_ops.genfb_disable_polling)(sc);



CVS commit: src/sys/dev/wsfb

2022-08-01 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Mon Aug  1 23:30:10 UTC 2022

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
genfb: Handle uninitialized softc in genfb_enable/disable_polling.

This can happen due to janky MD kludgerosity like x86
x86_genfb_ddb_trap_callback, which should really be cleaned up, but
at least this might help with the recursive traps we've been seeing
in syzbot.


To generate a diff of this commit:
cvs rdiff -u -r1.89 -r1.90 src/sys/dev/wsfb/genfb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/wsfb

2022-07-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul 17 13:10:54 UTC 2022

Modified Files:
src/sys/dev/wsfb: genfb.c genfbvar.h

Log Message:
genfb(4): Make internal parts of struct genfb_softc private.

This way the ABI has no ifdefs, so it has a chance to be usable in
modules.  This also makes genfb much easier to maintain without
worrying about ABI breakage.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/dev/wsfb/genfb.c
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/wsfb/genfbvar.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/dev/wsfb/genfb.c
diff -u src/sys/dev/wsfb/genfb.c:1.88 src/sys/dev/wsfb/genfb.c:1.89
--- src/sys/dev/wsfb/genfb.c:1.88	Sun Jul 17 13:10:04 2022
+++ src/sys/dev/wsfb/genfb.c	Sun Jul 17 13:10:54 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfb.c,v 1.88 2022/07/17 13:10:04 riastradh Exp $ */
+/*	$NetBSD: genfb.c,v 1.89 2022/07/17 13:10:54 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.88 2022/07/17 13:10:04 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.89 2022/07/17 13:10:54 riastradh Exp $");
 
 #include 
 #include 
@@ -75,6 +75,64 @@ __KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.
 #define GENFB_BRIGHTNESS_STEP 15
 #define	GENFB_CHAR_WIDTH_MM 3
 
+struct genfb_private {
+	struct genfb_ops sc_ops;
+	struct vcons_screen sc_console_screen;
+	struct wsscreen_descr sc_defaultscreen_descr;
+	const struct wsscreen_descr *sc_screens[1];
+	struct wsscreen_list sc_screenlist;
+	struct genfb_colormap_callback *sc_cmcb;
+	struct genfb_parameter_callback *sc_backlight;
+	struct genfb_parameter_callback *sc_brightness;
+	struct genfb_mode_callback *sc_modecb;
+	int sc_backlight_level, sc_backlight_on;
+	void *sc_shadowfb;
+	bool sc_enable_shadowfb;
+	int sc_mode;
+	u_char sc_cmap_red[256];
+	u_char sc_cmap_green[256];
+	u_char sc_cmap_blue[256];
+	bool sc_want_clear;
+#ifdef SPLASHSCREEN
+	struct splash_info sc_splash;
+#endif
+	struct wsdisplay_accessops sc_accessops;
+#if GENFB_GLYPHCACHE > 0
+	/*
+	 * The generic glyphcache code makes a bunch of assumptions that are
+	 * true for most graphics hardware with a directly supported blitter.
+	 * For example it assume that
+	 * - VRAM access from the host is expensive
+	 * - copying data around in VRAM is cheap and can happen in parallel
+	 *   to the host CPU
+	 * -> therefore we draw glyphs normally if we have to, so the ( assumed
+	 *to be hardware assisted ) driver supplied putchar() method doesn't
+	 *need to be glyphcache aware, then copy them away for later use
+	 * for genfb things are a bit different. On most hardware:
+	 * - VRAM access from the host is still expensive
+	 * - copying data around in VRAM is also expensive since we don't have
+	 *   a blitter and VRAM is mapped uncached
+	 * - VRAM reads are usually slower than writes ( write combining and
+	 *   such help writes but not reads, and VRAM might be behind an
+	 *   asymmetric bus like AGP ) and must be avoided, both are much
+	 *   slower than main memory
+	 * -> therefore we cache glyphs in main memory, no reason to map it
+	 *uncached, we draw into the cache first and then copy the glyph
+	 *into video memory to avoid framebuffer reads and to allow more
+	 *efficient write accesses than putchar() would offer
+	 * Because of this we can't use the generic code but we can recycle a
+	 * few data structures.
+	 */
+	uint8_t *sc_cache;
+	struct rasops_info sc_cache_ri;
+	void (*sc_putchar)(void *, int, int, u_int, long);
+	int sc_cache_cells;
+	int sc_nbuckets;	/* buckets allocated */
+	gc_bucket *sc_buckets;	/* we allocate as many as we can get into ram */
+	int sc_attrmap[256];	/* mapping a colour attribute to a bucket */
+#endif
+};
+
 static int	genfb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
 static paddr_t	genfb_mmap(void *, void *, off_t, int);
 static void	genfb_pollc(void *, int);
@@ -107,11 +165,14 @@ static struct genfb_softc *genfb_softc =
 void
 genfb_init(struct genfb_softc *sc)
 {
+	struct genfb_private *scp;
 	prop_dictionary_t dict;
 	uint64_t cmap_cb, pmf_cb, mode_cb, bl_cb, br_cb, fbaddr;
 	uint64_t fboffset;
 	bool console;
 
+	scp = sc->sc_private = kmem_zalloc(sizeof(*sc->sc_private), KM_SLEEP);
+
 	dict = device_properties(sc->sc_dev);
 #ifdef GENFB_DEBUG
 	printf("%s", prop_dictionary_externalize(dict));
@@ -120,20 +181,20 @@ genfb_init(struct genfb_softc *sc)
 
 	if (!prop_dictionary_get_uint32(dict, "width", >sc_width)) {
 		GPRINTF("no width property\n");
-		return;
+		goto bad;
 	}
 	if (!prop_dictionary_get_uint32(dict, "height", >sc_height)) {
 		GPRINTF("no height property\n");
-		return;
+		goto bad;
 	}
 	if (!prop_dictionary_get_uint32(dict, "depth", >sc_depth)) {
 		GPRINTF("no depth property\n");
-		return;
+		goto bad;
 	}
 
 	if (!prop_dictionary_get_uint64(dict, "address", 

CVS commit: src/sys/dev/wsfb

2022-07-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul 17 13:10:54 UTC 2022

Modified Files:
src/sys/dev/wsfb: genfb.c genfbvar.h

Log Message:
genfb(4): Make internal parts of struct genfb_softc private.

This way the ABI has no ifdefs, so it has a chance to be usable in
modules.  This also makes genfb much easier to maintain without
worrying about ABI breakage.


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.89 src/sys/dev/wsfb/genfb.c
cvs rdiff -u -r1.27 -r1.28 src/sys/dev/wsfb/genfbvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/wsfb

2022-07-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul 17 13:10:04 UTC 2022

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
genfb(4): KASSERT(a && b) -> KASSERT(a); KASSERT(b)

Better diagnostics.  No other functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/dev/wsfb/genfb.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/dev/wsfb/genfb.c
diff -u src/sys/dev/wsfb/genfb.c:1.87 src/sys/dev/wsfb/genfb.c:1.88
--- src/sys/dev/wsfb/genfb.c:1.87	Sat Jul  9 13:37:12 2022
+++ src/sys/dev/wsfb/genfb.c	Sun Jul 17 13:10:04 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfb.c,v 1.87 2022/07/09 13:37:12 rin Exp $ */
+/*	$NetBSD: genfb.c,v 1.88 2022/07/17 13:10:04 riastradh Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.87 2022/07/09 13:37:12 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.88 2022/07/17 13:10:04 riastradh Exp $");
 
 #include 
 #include 
@@ -608,7 +608,8 @@ genfb_init_screen(void *cookie, struct v
 			ri->ri_bpos = bits * 2;
 		} else if (is_swapped) {
 			/* byte-swapped, must be 32 bpp */
-			KASSERT(ri->ri_depth == 32 && bits == 8);
+			KASSERT(ri->ri_depth == 32);
+			KASSERT(bits == 8);
 			ri->ri_rpos = 8;
 			ri->ri_gpos = 16;
 			ri->ri_bpos = 24;
@@ -879,8 +880,8 @@ genfb_brightness_up(device_t dev)
 {
 	struct genfb_softc *sc = device_private(dev);
 
-	KASSERT(sc->sc_brightness != NULL &&
-		sc->sc_brightness->gpc_upd_parameter != NULL);
+	KASSERT(sc->sc_brightness != NULL);
+	KASSERT(sc->sc_brightness->gpc_upd_parameter != NULL);
 
 	(void)sc->sc_brightness->gpc_upd_parameter(
 	sc->sc_brightness->gpc_cookie, GENFB_BRIGHTNESS_STEP);
@@ -891,8 +892,8 @@ genfb_brightness_down(device_t dev)
 {
 	struct genfb_softc *sc = device_private(dev);
 
-	KASSERT(sc->sc_brightness != NULL &&
-		sc->sc_brightness->gpc_upd_parameter != NULL);
+	KASSERT(sc->sc_brightness != NULL);
+	KASSERT(sc->sc_brightness->gpc_upd_parameter != NULL);
 
 	(void)sc->sc_brightness->gpc_upd_parameter(
 	sc->sc_brightness->gpc_cookie, - GENFB_BRIGHTNESS_STEP);



CVS commit: src/sys/dev/wsfb

2022-07-17 Thread Taylor R Campbell
Module Name:src
Committed By:   riastradh
Date:   Sun Jul 17 13:10:04 UTC 2022

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
genfb(4): KASSERT(a && b) -> KASSERT(a); KASSERT(b)

Better diagnostics.  No other functional change.


To generate a diff of this commit:
cvs rdiff -u -r1.87 -r1.88 src/sys/dev/wsfb/genfb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/wsfb

2022-07-09 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Jul  9 13:37:13 UTC 2022

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
Fix GENFB_GLYPHCACHE with shadow fb.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/dev/wsfb/genfb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/wsfb

2022-07-09 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sat Jul  9 13:37:13 UTC 2022

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
Fix GENFB_GLYPHCACHE with shadow fb.


To generate a diff of this commit:
cvs rdiff -u -r1.86 -r1.87 src/sys/dev/wsfb/genfb.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/dev/wsfb/genfb.c
diff -u src/sys/dev/wsfb/genfb.c:1.86 src/sys/dev/wsfb/genfb.c:1.87
--- src/sys/dev/wsfb/genfb.c:1.86	Mon Mar 28 11:21:40 2022
+++ src/sys/dev/wsfb/genfb.c	Sat Jul  9 13:37:12 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfb.c,v 1.86 2022/03/28 11:21:40 mlelstv Exp $ */
+/*	$NetBSD: genfb.c,v 1.87 2022/07/09 13:37:12 rin Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.86 2022/03/28 11:21:40 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.87 2022/07/09 13:37:12 rin Exp $");
 
 #include 
 #include 
@@ -1004,7 +1004,7 @@ genfb_putchar(void *cookie, int row, int
 	struct rasops_info *ri = cookie;
 	struct vcons_screen *scr = ri->ri_hw;
 	struct genfb_softc *sc = scr->scr_cookie;
-	uint8_t *src, *dst;
+	uint8_t *src, *dst, *hwdst;
 	gc_bucket *b;
 	int i, idx, bi, cell;
 
@@ -1084,6 +1084,16 @@ genfb_putchar(void *cookie, int row, int
 		src += ri->ri_xscale;
 		dst += ri->ri_stride;
 	}
+	if (ri->ri_hwbits) {
+		src = sc->sc_cache + cell * sc->sc_cache_ri.ri_yscale;
+		hwdst = ri->ri_hwbits
+		+ row * ri->ri_yscale + col * ri->ri_xscale;
+		for (i = 0; i < ri->ri_font->fontheight; i++) {
+			memcpy(hwdst, src, ri->ri_xscale);
+			src += ri->ri_xscale;
+			hwdst += ri->ri_stride;
+		}
+	}
 	b->gb_lastread = time_uptime;
 	return;
 nope:



CVS commit: src/sys/dev/wsfb

2022-03-28 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Mar 28 11:21:40 UTC 2022

Modified Files:
src/sys/dev/wsfb: genfb.c genfbvar.h

Log Message:
Add helper to detach genfb console.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/dev/wsfb/genfb.c
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/wsfb/genfbvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/wsfb

2022-03-28 Thread Michael van Elst
Module Name:src
Committed By:   mlelstv
Date:   Mon Mar 28 11:21:40 UTC 2022

Modified Files:
src/sys/dev/wsfb: genfb.c genfbvar.h

Log Message:
Add helper to detach genfb console.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/dev/wsfb/genfb.c
cvs rdiff -u -r1.26 -r1.27 src/sys/dev/wsfb/genfbvar.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/dev/wsfb/genfb.c
diff -u src/sys/dev/wsfb/genfb.c:1.85 src/sys/dev/wsfb/genfb.c:1.86
--- src/sys/dev/wsfb/genfb.c:1.85	Fri Dec 24 18:12:58 2021
+++ src/sys/dev/wsfb/genfb.c	Mon Mar 28 11:21:40 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfb.c,v 1.85 2021/12/24 18:12:58 jmcneill Exp $ */
+/*	$NetBSD: genfb.c,v 1.86 2022/03/28 11:21:40 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.85 2021/12/24 18:12:58 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.86 2022/03/28 11:21:40 mlelstv Exp $");
 
 #include 
 #include 
@@ -835,6 +835,17 @@ genfb_cnattach(void)
 	genfb_cnattach_called = 1;
 }
 
+int
+genfb_cndetach(void)
+{
+
+	if (genfb_cnattach_called) {
+		genfb_cnattach_called = 0;
+		return 1;
+	}
+	return 0;
+}
+
 void
 genfb_disable(void)
 {

Index: src/sys/dev/wsfb/genfbvar.h
diff -u src/sys/dev/wsfb/genfbvar.h:1.26 src/sys/dev/wsfb/genfbvar.h:1.27
--- src/sys/dev/wsfb/genfbvar.h:1.26	Wed Jan 27 22:42:53 2021
+++ src/sys/dev/wsfb/genfbvar.h	Mon Mar 28 11:21:40 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfbvar.h,v 1.26 2021/01/27 22:42:53 macallan Exp $ */
+/*	$NetBSD: genfbvar.h,v 1.27 2022/03/28 11:21:40 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -167,6 +167,7 @@ struct genfb_softc {
 };
 
 void	genfb_cnattach(void);
+int	genfb_cndetach(void);
 void	genfb_disable(void);
 int	genfb_is_console(void);
 int	genfb_is_enabled(void);



Re: CVS commit: src/sys/dev/wsfb

2020-10-21 Thread Rin Okuyama

Hi,

On 2020/10/21 15:42, Michael wrote:

Hello,

On Sun, 18 Oct 2020 11:54:21 +
"Rin Okuyama"  wrote:


Module Name:src
Committed By:   rin
Date:   Sun Oct 18 11:54:21 UTC 2020

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
For WSDISPLAYIO_GET_FBINFO ioctl, set WSFB_VRAM_IS_RAM to fbi_flags
when shadow FB is used.


This flag is a hint for X, telling it that the memory used as
framebuffer is regular RAM ( where using a shadowfb in X would be a
waste of time and RAM ), not for example PCI RAM ( where a shadowfb
would be faster ).
In other words, it's supposed to tell X not to shadow the framebuffer.
This is why it's not set by genfb itself, which doesn't have such
knowledge about the hardware, but by drivers which do.
Shadow fb use in wsdisplay is completely private and mapping the
framebuffer through genfb will always give you whatever genfb thinks is
the actual device framebuffer.


Thank you for detailed explanation!

I already reverted this commit as jmcneill@ advised me:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/dev/wsfb/genfb.c#rev1.77

Thanks,
rin


Re: CVS commit: src/sys/dev/wsfb

2020-10-21 Thread Michael
Hello,

On Sun, 18 Oct 2020 11:54:21 +
"Rin Okuyama"  wrote:

> Module Name:  src
> Committed By: rin
> Date: Sun Oct 18 11:54:21 UTC 2020
> 
> Modified Files:
>   src/sys/dev/wsfb: genfb.c
> 
> Log Message:
> For WSDISPLAYIO_GET_FBINFO ioctl, set WSFB_VRAM_IS_RAM to fbi_flags
> when shadow FB is used.

This flag is a hint for X, telling it that the memory used as
framebuffer is regular RAM ( where using a shadowfb in X would be a
waste of time and RAM ), not for example PCI RAM ( where a shadowfb
would be faster ).
In other words, it's supposed to tell X not to shadow the framebuffer.
This is why it's not set by genfb itself, which doesn't have such
knowledge about the hardware, but by drivers which do.
Shadow fb use in wsdisplay is completely private and mapping the
framebuffer through genfb will always give you whatever genfb thinks is
the actual device framebuffer.

have fun
Michael


Re: CVS commit: src/sys/dev/wsfb

2020-10-18 Thread Rin Okuyama

On 2020/10/18 21:18, Jared McNeill wrote:

I think WSFB_VRAM_IS_RAM is meant to be a hint for what kind of memory you get 
when you mmap the device. When shadow FB is used, that is generally only used 
for rasops and mmap bypasses the shadow and uses device memory directly. So I 
think this could cause performance regressions on such hardware where shadow FB 
is enabled and reading VRAM is slow.

What problem are you attempting to solve with this change?


Ah, I misunderstood its intention. I will revert this commit.
Thank you for pointing out!

PS
I came across this flag bit when I was examining byte-order problems
of framebuffer on aarch64eb. I'm just going to send a message to you.
I will soon!

Thanks,
rin


Re: CVS commit: src/sys/dev/wsfb

2020-10-18 Thread Jared McNeill
I think WSFB_VRAM_IS_RAM is meant to be a hint for what kind of memory you 
get when you mmap the device. When shadow FB is used, that is generally 
only used for rasops and mmap bypasses the shadow and uses device memory 
directly. So I think this could cause performance regressions on such 
hardware where shadow FB is enabled and reading VRAM is slow.


What problem are you attempting to solve with this change?


On Sun, 18 Oct 2020, Rin Okuyama wrote:


Module Name:src
Committed By:   rin
Date:   Sun Oct 18 11:54:21 UTC 2020

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
For WSDISPLAYIO_GET_FBINFO ioctl, set WSFB_VRAM_IS_RAM to fbi_flags
when shadow FB is used.


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/sys/dev/wsfb/genfb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.




CVS commit: src/sys/dev/wsfb

2019-08-09 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Aug  9 17:22:02 UTC 2019

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
Fix bug introduced in rev. 1.69:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/dev/wsfb/genfb.c#rev1.69

is_bgr should be initialized to false. Otherwise, color becomes strange
for depths 24 and 32 unless backend explicitly set "is_bgr" property.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/dev/wsfb/genfb.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/dev/wsfb/genfb.c
diff -u src/sys/dev/wsfb/genfb.c:1.69 src/sys/dev/wsfb/genfb.c:1.70
--- src/sys/dev/wsfb/genfb.c:1.69	Wed Aug  7 13:23:12 2019
+++ src/sys/dev/wsfb/genfb.c	Fri Aug  9 17:22:02 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfb.c,v 1.69 2019/08/07 13:23:12 rin Exp $ */
+/*	$NetBSD: genfb.c,v 1.70 2019/08/09 17:22:02 rin Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.69 2019/08/07 13:23:12 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.70 2019/08/09 17:22:02 rin Exp $");
 
 #include 
 #include 
@@ -569,6 +569,7 @@ genfb_init_screen(void *cookie, struct v
 	case 24:
 		ri->ri_flg |= RI_ENABLE_ALPHA;
 
+		is_bgr = false;
 		prop_dictionary_get_bool(device_properties(sc->sc_dev),
 		"is_bgr", _bgr);
 		if (is_bgr) {



CVS commit: src/sys/dev/wsfb

2019-08-09 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Aug  9 17:22:02 UTC 2019

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
Fix bug introduced in rev. 1.69:
http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/dev/wsfb/genfb.c#rev1.69

is_bgr should be initialized to false. Otherwise, color becomes strange
for depths 24 and 32 unless backend explicitly set "is_bgr" property.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/sys/dev/wsfb/genfb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/wsfb

2019-08-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Aug  7 13:23:12 UTC 2019

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
We support anti-aliasing for depth 2.
Use switch appropriately.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/dev/wsfb/genfb.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/dev/wsfb/genfb.c
diff -u src/sys/dev/wsfb/genfb.c:1.68 src/sys/dev/wsfb/genfb.c:1.69
--- src/sys/dev/wsfb/genfb.c:1.68	Fri Aug  2 10:34:39 2019
+++ src/sys/dev/wsfb/genfb.c	Wed Aug  7 13:23:12 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfb.c,v 1.68 2019/08/02 10:34:39 rin Exp $ */
+/*	$NetBSD: genfb.c,v 1.69 2019/08/07 13:23:12 rin Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.68 2019/08/02 10:34:39 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.69 2019/08/07 13:23:12 rin Exp $");
 
 #include 
 #include 
@@ -541,6 +541,7 @@ genfb_init_screen(void *cookie, struct v
 	struct genfb_softc *sc = cookie;
 	struct rasops_info *ri = >scr_ri;
 	int wantcols;
+	bool is_bgr;
 
 	ri->ri_depth = sc->sc_depth;
 	ri->ri_width = sc->sc_width;
@@ -563,10 +564,11 @@ genfb_init_screen(void *cookie, struct v
 	if (existing && sc->sc_want_clear)
 		ri->ri_flg |= RI_CLEAR;
 
-	if (ri->ri_depth == 32 || ri->ri_depth == 24) {
+	switch (ri->ri_depth) {
+	case 32:
+	case 24:
 		ri->ri_flg |= RI_ENABLE_ALPHA;
 
-		bool is_bgr = false;
 		prop_dictionary_get_bool(device_properties(sc->sc_dev),
 		"is_bgr", _bgr);
 		if (is_bgr) {
@@ -586,13 +588,25 @@ genfb_init_screen(void *cookie, struct v
 			ri->ri_gpos = 8;
 			ri->ri_bpos = 0;
 		}
-	}
+		break;
 
-	if (ri->ri_depth == 16 || ri->ri_depth == 15)
+	case 16:
+	case 15:
 		ri->ri_flg |= RI_ENABLE_ALPHA;
+		break;
+
+	case 8:
+		if (sc->sc_cmcb != NULL)
+			ri->ri_flg |= RI_ENABLE_ALPHA | RI_8BIT_IS_RGB;
+		break;
 
-	if (ri->ri_depth == 8 && sc->sc_cmcb != NULL)
-		ri->ri_flg |= RI_ENABLE_ALPHA | RI_8BIT_IS_RGB;
+	case 2:
+		ri->ri_flg |= RI_ENABLE_ALPHA;
+		break;
+
+	default:
+		break;
+	}
 
 	wantcols = genfb_calc_cols(sc);
 



CVS commit: src/sys/dev/wsfb

2019-08-07 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Wed Aug  7 13:23:12 UTC 2019

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
We support anti-aliasing for depth 2.
Use switch appropriately.


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/sys/dev/wsfb/genfb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/wsfb

2019-08-02 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Aug  2 10:34:39 UTC 2019

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
Notify size of shadow framebuffer if enabled.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/dev/wsfb/genfb.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/dev/wsfb/genfb.c
diff -u src/sys/dev/wsfb/genfb.c:1.67 src/sys/dev/wsfb/genfb.c:1.68
--- src/sys/dev/wsfb/genfb.c:1.67	Mon Jul 29 14:07:37 2019
+++ src/sys/dev/wsfb/genfb.c	Fri Aug  2 10:34:39 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfb.c,v 1.67 2019/07/29 14:07:37 rin Exp $ */
+/*	$NetBSD: genfb.c,v 1.68 2019/08/02 10:34:39 rin Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.67 2019/07/29 14:07:37 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.68 2019/08/02 10:34:39 rin Exp $");
 
 #include 
 #include 
@@ -261,6 +261,9 @@ genfb_attach(struct genfb_softc *sc, str
 		sc->sc_shadowfb = kmem_alloc(sc->sc_fbsize, KM_SLEEP);
 		if (sc->sc_want_clear == false)
 			memcpy(sc->sc_shadowfb, sc->sc_fbaddr, sc->sc_fbsize);
+		aprint_verbose_dev(sc->sc_dev,
+		"shadow framebuffer enabled, size %zu KB\n",
+		sc->sc_fbsize >> 10);
 	}
 
 	vcons_init(>vd, sc, >sc_defaultscreen_descr,



CVS commit: src/sys/dev/wsfb

2019-08-02 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Fri Aug  2 10:34:39 UTC 2019

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
Notify size of shadow framebuffer if enabled.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/sys/dev/wsfb/genfb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/wsfb

2019-07-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Jul 29 14:07:37 UTC 2019

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
Enable anti-aliasing for depth 24.
Style.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/dev/wsfb/genfb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/wsfb

2019-07-29 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Mon Jul 29 14:07:37 UTC 2019

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
Enable anti-aliasing for depth 24.
Style.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/sys/dev/wsfb/genfb.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/dev/wsfb/genfb.c
diff -u src/sys/dev/wsfb/genfb.c:1.66 src/sys/dev/wsfb/genfb.c:1.67
--- src/sys/dev/wsfb/genfb.c:1.66	Sun Jul 28 02:42:48 2019
+++ src/sys/dev/wsfb/genfb.c	Mon Jul 29 14:07:37 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfb.c,v 1.66 2019/07/28 02:42:48 rin Exp $ */
+/*	$NetBSD: genfb.c,v 1.67 2019/07/29 14:07:37 rin Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.66 2019/07/28 02:42:48 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.67 2019/07/29 14:07:37 rin Exp $");
 
 #include 
 #include 
@@ -557,16 +557,13 @@ genfb_init_screen(void *cookie, struct v
 		scr->scr_flags |= VCONS_DONT_READ;
 	}
 
-	if (existing && sc->sc_want_clear) {
+	if (existing && sc->sc_want_clear)
 		ri->ri_flg |= RI_CLEAR;
-	}
 
 	if (ri->ri_depth == 32 || ri->ri_depth == 24) {
-		bool is_bgr = false;
+		ri->ri_flg |= RI_ENABLE_ALPHA;
 
-		if (ri->ri_depth == 32) {
-			ri->ri_flg |= RI_ENABLE_ALPHA;
-		}
+		bool is_bgr = false;
 		prop_dictionary_get_bool(device_properties(sc->sc_dev),
 		"is_bgr", _bgr);
 		if (is_bgr) {



CVS commit: src/sys/dev/wsfb

2019-07-27 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Jul 28 02:42:48 UTC 2019

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
sys/dev/rasops routines support anti-aliasing for depths 15 and 16.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/dev/wsfb/genfb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.



CVS commit: src/sys/dev/wsfb

2019-07-27 Thread Rin Okuyama
Module Name:src
Committed By:   rin
Date:   Sun Jul 28 02:42:48 UTC 2019

Modified Files:
src/sys/dev/wsfb: genfb.c

Log Message:
sys/dev/rasops routines support anti-aliasing for depths 15 and 16.


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/sys/dev/wsfb/genfb.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/dev/wsfb/genfb.c
diff -u src/sys/dev/wsfb/genfb.c:1.65 src/sys/dev/wsfb/genfb.c:1.66
--- src/sys/dev/wsfb/genfb.c:1.65	Fri May 31 01:35:56 2019
+++ src/sys/dev/wsfb/genfb.c	Sun Jul 28 02:42:48 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfb.c,v 1.65 2019/05/31 01:35:56 jmcneill Exp $ */
+/*	$NetBSD: genfb.c,v 1.66 2019/07/28 02:42:48 rin Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.65 2019/05/31 01:35:56 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.66 2019/07/28 02:42:48 rin Exp $");
 
 #include 
 #include 
@@ -588,6 +588,9 @@ genfb_init_screen(void *cookie, struct v
 		}
 	}
 
+	if (ri->ri_depth == 16 || ri->ri_depth == 15)
+		ri->ri_flg |= RI_ENABLE_ALPHA;
+
 	if (ri->ri_depth == 8 && sc->sc_cmcb != NULL)
 		ri->ri_flg |= RI_ENABLE_ALPHA | RI_8BIT_IS_RGB;
 



CVS commit: src/sys/dev/wsfb

2019-05-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri May 31 01:35:56 UTC 2019

Modified Files:
src/sys/dev/wsfb: files.wsfb genfb.c

Log Message:
If an EDID is available, attempt to use the screen size to influence font
selection by passing a "wantcols" value to rasops_init that is satisfied
by a font that is at least 3mm wide.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/wsfb/files.wsfb
cvs rdiff -u -r1.64 -r1.65 src/sys/dev/wsfb/genfb.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/dev/wsfb/files.wsfb
diff -u src/sys/dev/wsfb/files.wsfb:1.9 src/sys/dev/wsfb/files.wsfb:1.10
--- src/sys/dev/wsfb/files.wsfb:1.9	Fri May  1 02:00:41 2015
+++ src/sys/dev/wsfb/files.wsfb	Fri May 31 01:35:56 2019
@@ -1,4 +1,4 @@
-# $NetBSD: files.wsfb,v 1.9 2015/05/01 02:00:41 nat Exp $
+# $NetBSD: files.wsfb,v 1.10 2019/05/31 01:35:56 jmcneill Exp $
 
 #
 # wsdisplay framebuffer drivers
@@ -9,7 +9,7 @@ defflag opt_wsfb.h WSFB_FAKE_VGA_FB	# al
 defflag opt_wsfb.h WSFB_ALLOW_OTHERS	# allow to mmap() foreign ranges
 
 # a generic framebuffer console
-define genfb: rasops1, rasops2, rasops8, rasops15, rasops16, rasops24, rasops32, vcons
+define genfb: rasops1, rasops2, rasops8, rasops15, rasops16, rasops24, rasops32, vcons, edid
 device genfb: genfb, wsemuldisplaydev, drm, splash
 file	dev/wsfb/genfb.c	genfb	needs-flag
 defflag opt_genfb.h GENFB_DEBUG GENFB_SHADOWFB

Index: src/sys/dev/wsfb/genfb.c
diff -u src/sys/dev/wsfb/genfb.c:1.64 src/sys/dev/wsfb/genfb.c:1.65
--- src/sys/dev/wsfb/genfb.c:1.64	Mon Sep  3 16:29:34 2018
+++ src/sys/dev/wsfb/genfb.c	Fri May 31 01:35:56 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: genfb.c,v 1.64 2018/09/03 16:29:34 riastradh Exp $ */
+/*	$NetBSD: genfb.c,v 1.65 2019/05/31 01:35:56 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2007 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.64 2018/09/03 16:29:34 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.65 2019/05/31 01:35:56 jmcneill Exp $");
 
 #include 
 #include 
@@ -49,6 +49,9 @@ __KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.
 
 #include 
 
+#include 
+#include 
+
 #ifdef GENFB_DISABLE_TEXT
 #include 
 #define DISABLESPLASH (boothowto & (RB_SINGLE | RB_USERCONF | RB_ASKNAME | \
@@ -58,6 +61,7 @@ __KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.
 #ifdef _KERNEL_OPT
 #include "opt_genfb.h"
 #include "opt_wsfb.h"
+#include "opt_rasops.h"
 #endif
 
 #ifdef GENFB_DEBUG
@@ -67,12 +71,15 @@ __KERNEL_RCSID(0, "$NetBSD: genfb.c,v 1.
 #endif
 
 #define GENFB_BRIGHTNESS_STEP 15
+#define	GENFB_CHAR_WIDTH_MM 3
 
 static int	genfb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
 static paddr_t	genfb_mmap(void *, void *, off_t, int);
 static void	genfb_pollc(void *, int);
 
 static void	genfb_init_screen(void *, struct vcons_screen *, int, long *);
+static int	genfb_calc_hsize(struct genfb_softc *);
+static int	genfb_calc_cols(struct genfb_softc *);
 
 static int	genfb_putcmap(struct genfb_softc *, struct wsdisplay_cmap *);
 static int 	genfb_getcmap(struct genfb_softc *, struct wsdisplay_cmap *);
@@ -530,6 +537,7 @@ genfb_init_screen(void *cookie, struct v
 {
 	struct genfb_softc *sc = cookie;
 	struct rasops_info *ri = >scr_ri;
+	int wantcols;
 
 	ri->ri_depth = sc->sc_depth;
 	ri->ri_width = sc->sc_width;
@@ -583,8 +591,9 @@ genfb_init_screen(void *cookie, struct v
 	if (ri->ri_depth == 8 && sc->sc_cmcb != NULL)
 		ri->ri_flg |= RI_ENABLE_ALPHA | RI_8BIT_IS_RGB;
 
+	wantcols = genfb_calc_cols(sc);
 
-	rasops_init(ri, 0, 0);
+	rasops_init(ri, 0, wantcols);
 	ri->ri_caps = WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_UNDERLINE |
 		  WSSCREEN_RESIZE;
 	rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight,
@@ -599,6 +608,36 @@ genfb_init_screen(void *cookie, struct v
 #endif
 }
 
+/* Returns the width of the display in millimeters, or 0 if not known. */
+static int
+genfb_calc_hsize(struct genfb_softc *sc)
+{
+	device_t dev = sc->sc_dev;
+	prop_dictionary_t dict = device_properties(dev);
+	prop_data_t edid_data;
+	struct edid_info edid;
+	const char *edid_ptr;
+
+	edid_data = prop_dictionary_get(dict, "EDID");
+	if (edid_data == NULL || prop_data_size(edid_data) < 128)
+		return 0;
+
+	edid_ptr = prop_data_data_nocopy(edid_data);
+	if (edid_parse(__UNCONST(edid_ptr), ) != 0)
+		return 0;
+
+	return (int)edid.edid_max_hsize * 10;
+}
+
+/* Return the minimum number of character columns based on DPI */
+static int
+genfb_calc_cols(struct genfb_softc *sc)
+{
+	const int hsize = genfb_calc_hsize(sc);
+
+	return MAX(RASOPS_DEFAULT_WIDTH, hsize / GENFB_CHAR_WIDTH_MM);
+}
+
 static int
 genfb_putcmap(struct genfb_softc *sc, struct wsdisplay_cmap *cm)
 {



CVS commit: src/sys/dev/wsfb

2019-05-30 Thread Jared D. McNeill
Module Name:src
Committed By:   jmcneill
Date:   Fri May 31 01:35:56 UTC 2019

Modified Files:
src/sys/dev/wsfb: files.wsfb genfb.c

Log Message:
If an EDID is available, attempt to use the screen size to influence font
selection by passing a "wantcols" value to rasops_init that is satisfied
by a font that is at least 3mm wide.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/dev/wsfb/files.wsfb
cvs rdiff -u -r1.64 -r1.65 src/sys/dev/wsfb/genfb.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.