summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_bus.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2000-06-13 22:28:50 +0000
committerpeter <peter@FreeBSD.org>2000-06-13 22:28:50 +0000
commit647ef85d48424b2f17b827cdc91e595b17c66455 (patch)
tree356af9076580e616e17aaffdac3db15319e62b95 /sys/kern/subr_bus.c
parentc859e3ccfbf4963472ba1374f7ea67b524d43395 (diff)
downloadFreeBSD-src-647ef85d48424b2f17b827cdc91e595b17c66455.zip
FreeBSD-src-647ef85d48424b2f17b827cdc91e595b17c66455.tar.gz
Borrow phk's axe and apply the next stage of config(8)'s evolution.
Use Warner Losh's "hint" driver to decode ascii strings to fill the resource table at boot time. config(8) no longer generates an ioconf.c table - ie: the configuration no longer has to be compiled into the kernel. You can reconfigure your isa devices with the likes of this at loader(8) time: set hint.ed.0.port=0x320 userconfig will be rewritten to use this style interface one day and will move to /boot/userconfig.4th or something like that. It is still possible to statically compile in a set of hints into a kernel if you do not wish to use loader(8). See the "hints" directive in GENERIC as an example. All device wiring has been moved out of config(8). There is a set of helper scripts (see i386/conf/gethints.pl, and the same for alpha and pc98) that extract the 'at isa? port foo irq bar' from the old files and produces a hints file. If you install this file as /boot/device.hints (and update /boot/defaults/loader.conf - You can do a build/install in sys/boot) then loader will load it automatically for you. You can also compile in the hints directly with: hints "device.hints" as well. There are a few things that I'm not too happy with yet. Under this scheme, things like LINT would no longer be useful as "documentation" of settings. I have renamed this file to 'NOTES' and stored the example hints strings in it. However... this is not something that config(8) understands, so there is a script that extracts the build-specific data from the documentation file (NOTES) to produce a LINT that can be config'ed and built. A stack of man4 pages will need updating. :-/ Also, since there is no longer a difference between 'device' and 'pseudo-device' I collapsed the two together, and the resulting 'device' takes a 'number of units' for devices that still have it statically allocated. eg: 'device fe 4' will compile the fe driver with NFE set to 4. You can then set hints for 4 units (0 - 3). Also note that 'device fe0' will be interpreted as "zero units of 'fe'" which would be bad, so there is a config warning for this. This is only needed for old drivers that still have static limits on numbers of units. All the statically limited drivers that I could find were marked. Please exercise EXTREME CAUTION when transitioning! Moral support by: phk, msmith, dfr, asmodai, imp, and others
Diffstat (limited to 'sys/kern/subr_bus.c')
-rw-r--r--sys/kern/subr_bus.c159
1 files changed, 97 insertions, 62 deletions
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
index 03abd48..c530e5c 100644
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -1208,12 +1208,9 @@ device_unregister_oids(device_t dev)
* Access functions for device resources.
*/
-/* Supplied by config(8) in ioconf.c */
-extern struct config_device config_devtab[];
-extern int devtab_count;
-
/* Runtime version */
-struct config_device *devtab = config_devtab;
+static struct config_device *devtab;
+static int devtab_count = 0;
static int
resource_new_name(const char *name, int unit)
@@ -1492,68 +1489,106 @@ resource_set_string(const char *name, int unit, const char *resname,
return 0;
}
+/*
+ * We use the identify routine to get the hints for all the other devices.
+ * Strings that are all digits or begin with 0x are integers.
+ *
+ * hint.aha.0.bus_speedup=1
+ * hint.aha.1.irq=10
+ * hint.wl.0.netid=PLUG
+ * hint.wl.1.netid=XYZZY
+ */
+static void
+hint_load(char *cp)
+{
+ char *ep, *op, *walker;
+ int len;
+ int val;
+ char name[20];
+ int unit;
+ char resname[255];
+
+ for (ep = cp; (*ep != '=') && (*ep != 0); ep++)
+ ;
+ len = ep - cp;
+ if (*ep == '=')
+ ep++;
+ if (strncmp(cp, "hint.", 5) != 0)
+ return;
+ walker = cp;
+ walker += 5;
+ op = walker;
+ while (*walker && *walker != '.')
+ walker++;
+ if (*walker != '.')
+ return;
+ if (walker - op > sizeof(name))
+ return;
+ strncpy(name, op, walker - op);
+ name[walker - op] = '\0';
+ walker++;
+ op = walker;
+ while (*walker && *walker != '.')
+ walker++;
+ if (*walker != '.')
+ return;
+ unit = strtol(op, &walker, 0);
+ if (*walker != '.')
+ return;
+ walker++;
+ op = walker;
+ while (*walker && *walker != '=')
+ walker++;
+ if (*walker != '=')
+ return;
+ if (walker - op > sizeof(resname))
+ return;
+ strncpy(resname, op, walker - op);
+ resname[walker - op] = '\0';
+ walker++;
+ if (walker != ep)
+ return;
+ if (1 || bootverbose)
+ printf("Setting %s %d %s to ", name, unit, resname);
+ val = strtol(ep, &op, 0);
+ if (*ep != '\0' && *op == '\0') {
+ resource_set_int(name, unit, resname, val);
+ if (1 || bootverbose)
+ printf("%d (int)\n", val);
+ } else {
+ resource_set_string(name, unit, resname, ep);
+ if (1 || bootverbose)
+ printf("%s (string)\n", ep);
+ }
+}
+
+extern char static_hints[];
static void
-resource_cfgload(void *dummy __unused)
+hints_load(void *dummy __unused)
{
- struct config_resource *res, *cfgres;
- int i, j;
- int error;
- char *name, *resname;
- int unit;
- resource_type type;
- char *stringval;
- int config_devtab_count;
-
- config_devtab_count = devtab_count;
- devtab = NULL;
- devtab_count = 0;
-
- for (i = 0; i < config_devtab_count; i++) {
- name = config_devtab[i].name;
- unit = config_devtab[i].unit;
-
- for (j = 0; j < config_devtab[i].resource_count; j++) {
- cfgres = config_devtab[i].resources;
- resname = cfgres[j].name;
- type = cfgres[j].type;
- error = resource_create(name, unit, resname, type,
- &res);
- if (error) {
- printf("create resource %s%d: error %d\n",
- name, unit, error);
- continue;
- }
- if (res->type != type) {
- printf("type mismatch %s%d: %d != %d\n",
- name, unit, res->type, type);
- continue;
- }
- switch (type) {
- case RES_INT:
- res->u.intval = cfgres[j].u.intval;
- break;
- case RES_LONG:
- res->u.longval = cfgres[j].u.longval;
- break;
- case RES_STRING:
- if (res->u.stringval)
- free(res->u.stringval, M_TEMP);
- stringval = cfgres[j].u.stringval;
- res->u.stringval = malloc(strlen(stringval) + 1,
- M_TEMP, M_NOWAIT);
- if (res->u.stringval == NULL)
- break;
- strcpy(res->u.stringval, stringval);
- break;
- default:
- panic("unknown resource type %d\n", type);
- }
- }
+ char *cp;
+
+ cp = static_hints;
+ while (cp) {
+ hint_load(cp);
+ while (*cp != 0)
+ cp++;
+ cp++;
+ if (*cp == 0)
+ break;
+ }
+ cp = kern_envp;
+ while (cp) {
+ hint_load(cp);
+ while (*cp != 0)
+ cp++;
+ cp++;
+ if (*cp == 0)
+ break;
}
}
-SYSINIT(cfgload, SI_SUB_KMEM, SI_ORDER_ANY + 50, resource_cfgload, 0)
-
+SYSINIT(cfghints, SI_SUB_KMEM, SI_ORDER_ANY + 60, hints_load, 0)
/*======================================*/
/*
OpenPOWER on IntegriCloud