summaryrefslogtreecommitdiffstats
path: root/sys/kern/subr_bus.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>2001-07-14 08:25:18 +0000
committerpeter <peter@FreeBSD.org>2001-07-14 08:25:18 +0000
commit7c0cabdf7fdacc033b9ae99ee0f885e3c2b3aed3 (patch)
tree71f0f1fb0b28428e5ec53d9707604fecd854384c /sys/kern/subr_bus.c
parentb0af9b0f7302cbdb4730206f8b1240d233fdeab5 (diff)
downloadFreeBSD-src-7c0cabdf7fdacc033b9ae99ee0f885e3c2b3aed3.zip
FreeBSD-src-7c0cabdf7fdacc033b9ae99ee0f885e3c2b3aed3.tar.gz
Move the hints gunk to a seperate file. It isn't really part of the
newbus structure (no more than subr_rman.c is anyway).
Diffstat (limited to 'sys/kern/subr_bus.c')
-rw-r--r--sys/kern/subr_bus.c299
1 files changed, 0 insertions, 299 deletions
diff --git a/sys/kern/subr_bus.c b/sys/kern/subr_bus.c
index 67819b2..098b89b 100644
--- a/sys/kern/subr_bus.c
+++ b/sys/kern/subr_bus.c
@@ -2126,302 +2126,3 @@ bus_data_generation_update(void)
{
bus_data_generation++;
}
-
-/*======================================*/
-/*
- * Access functions for device resources.
- */
-
-extern char static_hints[]; /* by config for now */
-extern int hintmode; /* 0 = off. 1 = config, 2 = fallback */
-static char *hintp;
-
-/*
- * Evil wildcarding resource string lookup.
- * This walks the supplied env string table and returns a match.
- * The start point can be remembered for incremental searches.
- */
-static int
-res_find(int *line, int *startln,
- const char *name, int *unit, const char *resname, const char *value,
- const char **ret_name, int *ret_namelen, int *ret_unit,
- const char **ret_resname, int *ret_resnamelen, const char **ret_value)
-{
- int n = 0, hit;
- char r_name[32];
- int r_unit;
- char r_resname[32];
- char r_value[128];
- const char *s, *cp;
- char *p;
-
- if (hintp == NULL) {
- switch (hintmode) {
- case 0: /* config supplied nothing */
- hintp = kern_envp;
- break;
- case 1: /* static hints only */
- hintp = static_hints;
- break;
- case 2: /* fallback mode */
- cp = kern_envp;
- while (cp) {
- if (strncmp(cp, "hint.", 5) == 0) {
- cp = NULL;
- hintp = kern_envp;
- break;
- }
- while (*cp != '\0')
- cp++;
- cp++;
- if (*cp == '\0') {
- cp = NULL;
- hintp = static_hints;
- break;
- }
- }
- break;
- default:
- break;
- }
- if (hintp == NULL)
- hintp = kern_envp;
- }
-
- cp = hintp;
- while (cp) {
- hit = 1;
- (*line)++;
- if (strncmp(cp, "hint.", 5) != 0)
- hit = 0;
- else
- n = sscanf(cp, "hint.%32[^.].%d.%32[^=]=%128s",
- r_name, &r_unit, r_resname, r_value);
- if (hit && n != 4) {
- printf("CONFIG: invalid hint '%s'\n", cp);
- /* XXX: abuse bogus index() declaration */
- p = index(cp, 'h');
- *p = 'H';
- hit = 0;
- }
- if (hit && startln && *startln >= 0 && *line < *startln)
- hit = 0;
- if (hit && name && strcmp(name, r_name) != 0)
- hit = 0;
- if (hit && unit && *unit != r_unit)
- hit = 0;
- if (hit && resname && strcmp(resname, r_resname) != 0)
- hit = 0;
- if (hit && value && strcmp(value, r_value) != 0)
- hit = 0;
- if (hit)
- break;
- while (*cp != '\0')
- cp++;
- cp++;
- if (*cp == '\0') {
- cp = NULL;
- break;
- }
- }
- if (cp == NULL)
- return ENOENT;
-
- s = cp;
- /* This is a bit of a hack, but at least is reentrant */
- /* Note that it returns some !unterminated! strings. */
- s = index(s, '.') + 1; /* start of device */
- if (ret_name)
- *ret_name = s;
- s = index(s, '.') + 1; /* start of unit */
- if (ret_namelen)
- *ret_namelen = s - *ret_name - 1; /* device length */
- if (ret_unit)
- *ret_unit = r_unit;
- s = index(s, '.') + 1; /* start of resname */
- if (ret_resname)
- *ret_resname = s;
- s = index(s, '=') + 1; /* start of value */
- if (ret_resnamelen)
- *ret_resnamelen = s - *ret_resname - 1; /* value len */
- if (ret_value)
- *ret_value = s;
- if (startln) /* line number for anchor */
- *startln = *line + 1;
- return 0;
-}
-
-/*
- * Search all the data sources for matches to our query. We look for
- * dynamic hints first as overrides for static or fallback hints.
- */
-static int
-resource_find(int *line, int *startln,
- const char *name, int *unit, const char *resname, const char *value,
- const char **ret_name, int *ret_namelen, int *ret_unit,
- const char **ret_resname, int *ret_resnamelen, const char **ret_value)
-{
- int i;
- int un;
-
- *line = 0;
-
- /* Search for exact unit matches first */
- i = res_find(line, startln, name, unit, resname, value,
- ret_name, ret_namelen, ret_unit, ret_resname, ret_resnamelen,
- ret_value);
- if (i == 0)
- return 0;
- if (unit == NULL)
- return ENOENT;
- /* If we are still here, search for wildcard matches */
- un = -1;
- i = res_find(line, startln, name, &un, resname, value,
- ret_name, ret_namelen, ret_unit, ret_resname, ret_resnamelen,
- ret_value);
- if (i == 0)
- return 0;
- return ENOENT;
-}
-
-int
-resource_int_value(const char *name, int unit, const char *resname, int *result)
-{
- int error;
- const char *str;
- char *op;
- unsigned long val;
- int line;
-
- line = 0;
- error = resource_find(&line, NULL, name, &unit, resname, NULL,
- NULL, NULL, NULL, NULL, NULL, &str);
- if (error)
- return error;
- if (*str == '\0')
- return EFTYPE;
- val = strtoul(str, &op, 0);
- if (*op != '\0')
- return EFTYPE;
- *result = val;
- return 0;
-}
-
-int
-resource_long_value(const char *name, int unit, const char *resname,
- long *result)
-{
- int error;
- const char *str;
- char *op;
- unsigned long val;
- int line;
-
- line = 0;
- error = resource_find(&line, NULL, name, &unit, resname, NULL,
- NULL, NULL, NULL, NULL, NULL, &str);
- if (error)
- return error;
- if (*str == '\0')
- return EFTYPE;
- val = strtoul(str, &op, 0);
- if (*op != '\0')
- return EFTYPE;
- *result = val;
- return 0;
-}
-
-int
-resource_string_value(const char *name, int unit, const char *resname,
- const char **result)
-{
- int error;
- const char *str;
- int line;
-
- line = 0;
- error = resource_find(&line, NULL, name, &unit, resname, NULL,
- NULL, NULL, NULL, NULL, NULL, &str);
- if (error)
- return error;
- *result = str;
- return 0;
-}
-
-/*
- * This is a bit nasty, but allows us to not modify the env strings.
- */
-static const char *
-resource_string_copy(const char *s, int len)
-{
- static char stringbuf[256];
- static int offset = 0;
- const char *ret;
-
- if (len == 0)
- len = strlen(s);
- if (len > 255)
- return NULL;
- if ((offset + len + 1) > 255)
- offset = 0;
- bcopy(s, &stringbuf[offset], len);
- stringbuf[offset + len] = '\0';
- ret = &stringbuf[offset];
- offset += len + 1;
- return ret;
-}
-
-/*
- * err = resource_find_at(&anchor, &name, &unit, resname, value)
- * Iteratively fetch a list of devices wired "at" something
- * res and value are restrictions. eg: "at", "scbus0".
- * For practical purposes, res = required, value = optional.
- * *name and *unit are set.
- * set *anchor to zero before starting.
- */
-int
-resource_find_match(int *anchor, const char **name, int *unit,
- const char *resname, const char *value)
-{
- const char *found_name;
- int found_namelen;
- int found_unit;
- int ret;
- int newln;
-
- newln = *anchor;
- ret = resource_find(anchor, &newln, NULL, NULL, resname, value,
- &found_name, &found_namelen, &found_unit, NULL, NULL, NULL);
- if (ret == 0) {
- *name = resource_string_copy(found_name, found_namelen);
- *unit = found_unit;
- }
- *anchor = newln;
- return ret;
-}
-
-
-/*
- * err = resource_find_dev(&anchor, name, &unit, res, value);
- * Iterate through a list of devices, returning their unit numbers.
- * res and value are optional restrictions. eg: "at", "scbus0".
- * *unit is set to the value.
- * set *anchor to zero before starting.
- */
-int
-resource_find_dev(int *anchor, const char *name, int *unit,
- const char *resname, const char *value)
-{
- int found_unit;
- int newln;
- int ret;
-
- newln = *anchor;
- ret = resource_find(anchor, &newln, name, NULL, resname, value,
- NULL, NULL, &found_unit, NULL, NULL, NULL);
- if (ret == 0) {
- *unit = found_unit;
- }
- *anchor = newln;
- return ret;
-}
OpenPOWER on IntegriCloud