Module Name:    src
Committed By:   thorpej
Date:           Fri Apr 30 02:34:13 UTC 2021

Modified Files:
        src/sys/dev/ofw: ofbus.c

Log Message:
If we're enumerating the root bus, skip some well-known nodes that
don't have any useful device child nodes:

        aliases
        options
        openprom
        chosen
        packages

...and also allow machdep additions to this list (XXX which are temporarily
declared here for arm32 until there's a consistent machine/ofw_machdep.h
header file).


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/ofw/ofbus.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/ofw/ofbus.c
diff -u src/sys/dev/ofw/ofbus.c:1.28 src/sys/dev/ofw/ofbus.c:1.29
--- src/sys/dev/ofw/ofbus.c:1.28	Tue Apr 27 20:31:01 2021
+++ src/sys/dev/ofw/ofbus.c	Fri Apr 30 02:34:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofbus.c,v 1.28 2021/04/27 20:31:01 thorpej Exp $	*/
+/*	$NetBSD: ofbus.c,v 1.29 2021/04/30 02:34:12 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofbus.c,v 1.28 2021/04/27 20:31:01 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofbus.c,v 1.29 2021/04/30 02:34:12 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -71,6 +71,46 @@ ofbus_match(device_t parent, cfdata_t cf
 	return (1);
 }
 
+#if defined(__arm32__)		/* XXX temporary */
+#define	_OFBUS_ROOT_MACHDEP_SKIPNAMES					\
+	"udp",								\
+	"cpus",								\
+	"mmu",								\
+	"memory"
+#endif /* __arm32__ */
+
+/*
+ * Skip some well-known nodes in the root that contain no useful
+ * child devices.
+ */
+static bool
+ofbus_skip_node_in_root(int phandle, char *name, size_t namesize)
+{
+	static const char * const skip_names[] = {
+		"aliases",
+		"options",
+		"openprom",
+		"chosen",
+		"packages",
+#ifdef _OFBUS_ROOT_MACHDEP_SKIPNAMES
+		_OFBUS_ROOT_MACHDEP_SKIPNAMES
+#endif
+	};
+	u_int i;
+
+	name[0] = '\0';
+	if (OF_getprop(phandle, "name", name, namesize) <= 0) {
+		return false;
+	}
+
+	for (i = 0; i < __arraycount(skip_names); i++) {
+		if (strcmp(name, skip_names[i]) == 0) {
+			return true;
+		}
+	}
+	return false;
+}
+
 void
 ofbus_attach(device_t parent, device_t dev, void *aux)
 {
@@ -78,12 +118,15 @@ ofbus_attach(device_t parent, device_t d
 	struct ofbus_attach_args oba2;
 	char name[64], type[64];
 	int child, units;
+	bool rootbus;
+
+	rootbus = oba->oba_phandle == OF_finddevice("/");
 
 	/*
 	 * If we are the OFW root, get the banner-name and model
 	 * properties and display them for informational purposes.
 	 */
-	if (oba->oba_phandle == OF_finddevice("/")) {
+	if (rootbus) {
 		int model_len, banner_len;
 
 		model_len = OF_getprop(oba->oba_phandle, "model",
@@ -152,6 +195,10 @@ ofbus_attach(device_t parent, device_t d
 			if (strncmp(type, "display", sizeof(type)) == 0)
 				continue;
 		}
+		if (rootbus &&
+		    ofbus_skip_node_in_root(child, name, sizeof(name))) {
+			continue;
+		}
 		of_packagename(child, name, sizeof name);
 		oba2.oba_phandle = child;
 		for (oba2.oba_unit = 0; oba2.oba_unit < units;
@@ -169,5 +216,4 @@ ofbus_attach(device_t parent, device_t d
 			    CFARG_EOL);
 		}
 	}
-
 }

Reply via email to