From owner-freebsd-new-bus Thu Mar 23 13:19:48 2000 Delivered-To: freebsd-new-bus@freebsd.org Received: from rover.village.org (rover.village.org [204.144.255.49]) by hub.freebsd.org (Postfix) with ESMTP id E7DB037BA8D for ; Thu, 23 Mar 2000 13:19:42 -0800 (PST) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (harmony.village.org [10.0.0.6]) by rover.village.org (8.9.3/8.9.3) with ESMTP id OAA35812 for ; Thu, 23 Mar 2000 14:19:41 -0700 (MST) (envelope-from imp@harmony.village.org) Received: from harmony.village.org (localhost.village.org [127.0.0.1]) by harmony.village.org (8.9.3/8.8.3) with ESMTP id OAA43780 for ; Thu, 23 Mar 2000 14:19:37 -0700 (MST) Message-Id: <200003232119.OAA43780@harmony.village.org> To: new-bus@freebsd.org Subject: Comments on the hints driver Date: Thu, 23 Mar 2000 14:19:37 -0700 From: Warner Losh Sender: owner-freebsd-new-bus@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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