Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Mar 2000 14:19:37 -0700
From:      Warner Losh <imp@village.org>
To:        new-bus@freebsd.org
Subject:   Comments on the hints driver
Message-ID:  <200003232119.OAA43780@harmony.village.org>

next in thread | raw e-mail | index | archive | help

I've create a simple little hint driver, patch attached, that will
read in all of the kernel environment variables and process some of
them.

If you have

	hint.aic.0.irq=#10

then for aic0 the irq hint is set to 10.

If you have

	hint.ed.0.sensitive=#0

then ed devices aren't treated as senstive and probed first.

You could even have something like

	hint.wintv.-1.format=PAL

which makes PAL the default format for wintv driver.

One could entend this to include sysctls as well:

	sysctl.net.ip.tcp.log_in_vain=1

and we could have a way of setting sysctls from the boot blocks.  My
code doesn't do this last bit yet.  Note, that I've had to make the
printcap-like #number syntax for the hints because otherwise I
wouldn't know which resource hint routine to call.  This wouldn't be
needed with sysctl since the type is encoded, iirc, in the sysctl data
structure.

The code has been lightly tested, and appears to work.  Properly
applied, I think this could be the basis for a better userconfig
editor.  One would then just save the hints to get the persistance
that is needed for some applications.

It would certainly move us more steps away from the reliance on config
to propigate hint information into the kernel.

Comments?  Well, other than this shouldn't be in subr_bus.c :-)

Warner

Index: subr_bus.c
===================================================================
RCS file: /base/FreeBSD-tsc-4/sys/kern/subr_bus.c,v
retrieving revision 1.5
diff -u -r1.5 subr_bus.c
--- subr_bus.c	2000/03/01 21:17:29	1.5
+++ subr_bus.c	2000/03/23 19:38:54
@@ -2473,3 +2473,111 @@
 }
 
 #endif
+
+/*
+ * I'm not sure this is the best place for this, but this is where I'm doing
+ * it :-)
+ */
+
+static devclass_t	hints_devclass;
+
+/*
+ * We use the identify routine to get the hints for all the other devices
+ *
+ * hint.aha.0.bus_speedup=#1
+ * hint.aha.1.irq=#10
+ * hint.wl.0.netid="PLUG"
+ * hint.wl.1.netid="XYZZY"
+ */
+
+/*
+ * Find the next entry after the one which (cp) falls within, return a
+ * pointer to its start or NULL if there are no more.
+ */
+static char *
+kernenv_next(char *cp)
+{
+    if (cp != NULL) {
+	while (*cp != 0)
+	    cp++;
+	cp++;
+	if (*cp == 0)
+	    cp = NULL;
+    }
+    return(cp);
+}
+
+static void
+hints_identify(driver_t *driver, device_t parent)
+{
+	char	*cp, *ep, *op, *walker;
+	int	len;
+	int	val;
+	char	name[20];
+	int	unit;
+	char	resname[255];
+    
+	for (cp = kern_envp; cp != NULL; cp = kernenv_next(cp)) {
+		for (ep = cp; (*ep != '=') && (*ep != 0); ep++)
+			;
+		len = ep - cp;
+		if (*ep == '=')
+			ep++;
+		if (strncmp(cp, "hint.", 5) == 0) {
+			walker = cp;
+			walker += 5;
+			op = walker;
+			while (*walker && *walker != '.')
+				walker++;
+			if (*walker != '.')
+				continue;
+			if (walker - op > sizeof(name))
+				continue;
+			strncpy(name, op, walker - op - 1);
+			name[walker - op - 1] = '\0';
+			walker++;
+			op = walker;
+			while (*walker && *walker != '.')
+				walker++;
+			if (*walker != '.')
+				continue;
+			unit = strtol(op, &walker, NULL);
+			if (*walker != '.')
+				continue;
+			walker++;
+			op = walker;
+			while (*walker && *walker != '.')
+				walker++;
+			if (*walker != '.')
+				continue;
+			if (walker - op > sizeof(resname))
+				continue;
+			strncpy(resname, op, walker - op - 1);
+			resname[walker - op - 1] = '\0';
+			walker++;
+			if (walker + 1 != ep)
+				continue;
+			if (*ep == '#') {
+				val = strtol(ep + 1, NULL, NULL);
+				resource_set_int(name, unit, resname, val);
+			} else {
+				resource_set_string(name, unit, resname, ep);
+			}
+		}
+	}
+}
+
+static device_method_t hints_methods[] = {
+	/* Device interface */
+	DEVMETHOD(device_identify,	hints_identify),
+
+	{ 0, 0 }
+};
+
+static driver_t hints_driver = {
+	"hints",
+	hints_methods,
+	1,			/* no softc */
+};
+
+DRIVER_MODULE(nexus, hints, hints_driver, hints_devclass, 0, 0);


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-new-bus" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200003232119.OAA43780>