Module Name:    src
Committed By:   riastradh
Date:           Thu Sep  1 17:54:48 UTC 2022

Modified Files:
        src/sys/external/bsd/drm2/drm: drmfb.c

Log Message:
drmfb: Rework console detection and takeover.

While here, simplify logic by removing an unreachable error branch so
we never have to contemplate unwinding claiming of the console.


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/sys/external/bsd/drm2/drm/drmfb.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/external/bsd/drm2/drm/drmfb.c
diff -u src/sys/external/bsd/drm2/drm/drmfb.c:1.15 src/sys/external/bsd/drm2/drm/drmfb.c:1.16
--- src/sys/external/bsd/drm2/drm/drmfb.c:1.15	Thu Sep  1 12:01:36 2022
+++ src/sys/external/bsd/drm2/drm/drmfb.c	Thu Sep  1 17:54:47 2022
@@ -1,4 +1,4 @@
-/*	$NetBSD: drmfb.c,v 1.15 2022/09/01 12:01:36 riastradh Exp $	*/
+/*	$NetBSD: drmfb.c,v 1.16 2022/09/01 17:54:47 riastradh Exp $	*/
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -39,7 +39,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: drmfb.c,v 1.15 2022/09/01 12:01:36 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: drmfb.c,v 1.16 2022/09/01 17:54:47 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "vga.h"
@@ -94,9 +94,8 @@ drmfb_attach(struct drmfb_softc *sc, con
 #endif
 	static const struct genfb_ops zero_genfb_ops;
 	struct genfb_ops genfb_ops = zero_genfb_ops;
-	enum { CONS_VGA, CONS_GENFB, CONS_NONE } what_was_cons;
 	bool is_console;
-	int error;
+	int error __diagused;
 
 	/* genfb requires this.  */
 	KASSERTMSG((void *)&sc->sc_genfb == device_private(da->da_dev),
@@ -116,29 +115,35 @@ drmfb_attach(struct drmfb_softc *sc, con
 	prop_dictionary_set_uint64(dict, "mode_callback",
 	    (uint64_t)(uintptr_t)&drmfb_genfb_mode_callback);
 
+	/*
+	 * Determine whether MD firmware logic has set the console to
+	 * go through this device.
+	 */
 	if (prop_dictionary_get_bool(pdict, "is_console", &is_console)) {
-		what_was_cons = CONS_NONE;
-		prop_dictionary_set_bool(dict, "is_console", is_console);
+		/* nothing */
+	} else if (genfb_is_console() && genfb_is_enabled()) {
+		is_console = true;
 	} else {
-		/* XXX Whattakludge!  */
+		is_console = false;
+	}
+
 #if NVGA > 0
-		if ((da->da_params->dp_is_vga_console != NULL) &&
-		    (*da->da_params->dp_is_vga_console)(dev)) {
-			what_was_cons = CONS_VGA;
-			prop_dictionary_set_bool(dict, "is_console", true);
-			vga_cndetach();
-			if (da->da_params->dp_disable_vga)
-				(*da->da_params->dp_disable_vga)(dev);
-		} else
-#endif
-		if (genfb_is_console() && genfb_is_enabled()) {
-			what_was_cons = CONS_GENFB;
-			prop_dictionary_set_bool(dict, "is_console", true);
-		} else {
-			what_was_cons = CONS_NONE;
-			prop_dictionary_set_bool(dict, "is_console", false);
-		}
+	/*
+	 * Whether or not we were told to be the console, if the
+	 * console was configured to go through a vga resource that we
+	 * now own and that vga(4) is not going to take over, kick out
+	 * the vga console before we take over as genfb console.
+	 */
+	if ((da->da_params->dp_is_vga_console != NULL) &&
+	    (*da->da_params->dp_is_vga_console)(dev)) {
+		vga_cndetach();
+		if (da->da_params->dp_disable_vga)
+			(*da->da_params->dp_disable_vga)(dev);
+		is_console = true;
 	}
+#endif
+
+	prop_dictionary_set_bool(dict, "is_console", is_console);
 
 	/* Make the first EDID we find available to wsfb */
 	drm_connector_list_iter_begin(da->da_fb_helper->dev, &conn_iter);
@@ -162,28 +167,10 @@ drmfb_attach(struct drmfb_softc *sc, con
 	KERNEL_LOCK(1, NULL);
 	error = genfb_attach(&sc->sc_genfb, &genfb_ops);
 	KERNEL_UNLOCK_ONE(NULL);
-	if (error) {
-		aprint_error_dev(sc->sc_da.da_dev,
-		    "failed to attach genfb: %d\n", error);
-		goto fail0;
-	}
+	KASSERTMSG(error == 0, "genfb_attach failed, error=%d", error);
 
 	/* Success!  */
 	return 0;
-
-fail0:	KASSERT(error);
-	/* XXX Restore console...  */
-	switch (what_was_cons) {
-	case CONS_VGA:
-		break;
-	case CONS_GENFB:
-		break;
-	case CONS_NONE:
-		break;
-	default:
-		break;
-	}
-	return error;
 }
 
 int

Reply via email to