if (cf->cf_fstate == FSTATE_DNOTFOUND |
if (cf->cf_fstate == FSTATE_DNOTFOUND ||
static char *number __P((char *, int));static void mapply __P((struct matchinfo *, struct cfdata *));struct devicelist alldevs;		/* list of all devices */struct evcntlist allevents;		/* list of all event counters *//* * Initialize autoconfiguration data structures.  This occurs before console * initialization as that might require use of this subsystem.  Furthermore * this means that malloc et al. isn't yet available. */voidconfig_init(){	TAILQ_INIT(&alldevs);	TAILQ_INIT(&allevents);	TAILQ_INIT(&allcftables);	TAILQ_INSERT_TAIL(&allcftables, &staticcftable, list);}/* * Apply the matching function and choose the best.  This is used * a few times and we want to keep the code small. */static voidmapply(m, cf)	register struct matchinfo *m;	register struct cfdata *cf;{	register int pri;	void *match;	if (m->indirect)		match = config_make_softc(m->parent, cf);	else		match = cf;	if (m->fn != NULL)		pri = (*m->fn)(m->parent, match, m->aux);	else {	        if (cf->cf_attach->ca_match == NULL) {			panic("mapply: no match function for '%s' device\n",			    cf->cf_driver->cd_name);		}		pri = (*cf->cf_attach->ca_match)(m->parent, match, m->aux);	}	if (pri > m->pri) {		if (m->indirect && m->match)			free(m->match, M_DEVBUF);		m->match = match;		m->pri = pri;	} else {		if (m->indirect)			free(match, M_DEVBUF);	}}/* * Iterate over all potential children of some device, calling the given * function (default being the child's match function) for each one. * Nonzero returns are matches; the highest value returned is considered * the best match.  Return the `found child' if we got a match, or NULL * otherwise.  The `aux' pointer is simply passed on through. * * Note that this function is designed so that it can be used to apply * an arbitrary function to all potential children (its return value * can be ignored). */void *config_search(fn, parent, aux)	cfmatch_t fn;	register struct device *parent;	void *aux;{	register struct cfdata *cf;	register short *p;	struct matchinfo m;	struct cftable *t;	m.fn = fn;	m.parent = parent;	m.match = NULL;	m.aux = aux;	m.indirect = parent && parent->dv_cfdata->cf_driver->cd_indirect;	m.pri = 0;	for(t = allcftables.tqh_first; t; t = t->list.tqe_next){	  for (cf = t->tab; cf->cf_driver; cf++) {	    /*	     * Skip cf if no longer eligible, otherwise scan through	     * parents for one matching `parent', and try match function.	     */	    if (cf->cf_fstate == FSTATE_FOUND)	      continue;	    if (cf->cf_fstate == FSTATE_DNOTFOUND |		cf->cf_fstate == FSTATE_DSTAR)	      continue;	    for (p = cf->cf_parents; *p >= 0; p++)	      if (parent->dv_cfdata == &(t->tab)[*p])		mapply(&m, cf);	  }	}	return (m.match);}/* * Iterate over all potential children of some device, calling the given * function for each one. * * Note that this function is designed so that it can be used to apply * an arbitrary function to all potential children (its return value * can be ignored). */voidconfig_scan(fn, parent)	cfscan_t fn;	register struct device *parent;{	register struct cfdata *cf;	register short *p;	void *match;	int indirect;	struct cftable *t;	indirect = parent && parent->dv_cfdata->cf_driver->cd_indirect;	for (t = allcftables.tqh_first; t; t = t->list.tqe_next) {	  for (cf = t->tab; cf->cf_driver; cf++) {	    /*	     * Skip cf if no longer eligible, otherwise scan through	     * parents for one matching `parent', and try match function.	     */	    if (cf->cf_fstate == FSTATE_FOUND)	      continue;	    if (cf->cf_fstate == FSTATE_DNOTFOUND |		cf->cf_fstate == FSTATE_DSTAR)	      continue;	    for (p = cf->cf_parents; *p >= 0; p++)	      if (parent->dv_cfdata == &(t->tab)[*p]) {		if (indirect)		  match = config_make_softc(parent, cf);		else		  match = cf;		(*fn)(parent, match);	      }	  }	}}/* * Find the given root device. * This is much like config_search, but there is no parent. */void *config_rootsearch(fn, rootname, aux)	register cfmatch_t fn;	register char *rootname;	register void *aux;{	register struct cfdata *cf;	register short *p;	struct matchinfo m;	m.fn = fn;	m.parent = ROOT;	m.match = NULL;	m.aux = aux;	m.indirect = 0;	m.pri = 0;	/*	 * Look at root entries for matching name.  We do not bother	 * with found-state here since only one root should ever be	 * searched (and it must be done first).	 */	for (p = cfroots; *p >= 0; p++) {		cf = &cfdata[*p];		if (strcmp(cf->cf_driver->cd_name, rootname) == 0)			mapply(&m, cf);	}	return (m.match);}static char *msgs[3] = { "", " not configured\n", " unsupported\n" };/* * The given `aux' argument describes a device that has been found * on the given parent, but not necessarily configured.  Locate the * configuration data for that device (using the submatch function * provided, or using candidates' cd_match configuration driver * functions) and attach it, and return true.  If the device was * not configured, call the given `print' function and return 0. */struct device *config_found_sm(parent, aux, print, submatch)	struct device *parent;	void *aux;	cfprint_t print;	cfmatch_t submatch;{	void *match;	if ((match = config_search(submatch, parent, aux)) != NULL)		return (config_attach(parent, match, aux, print));	if (print)		printf(msgs[(*print)(aux, parent->dv_xname)]);	return (NULL);}/* * As above, but for root devices. */struct device *config_rootfound(rootname, aux)	char *rootname;	void *aux;{	void *match;	if ((match = config_rootsearch((cfmatch_t)NULL, rootname, aux)) != NULL)		return (config_attach(ROOT, match, aux, (cfprint_t)NULL));	printf("root device %s not configured\n", rootname);	return (NULL);}/* just like sprintf(buf, "%d") except that it works from the end */static char *number(ep, n)	register char *ep;	register int n;{	*--ep = 0;	while (n >= 10) {		*--ep = (n % 10) + '0';		n /= 10;	}	*--ep = n + '0';	return (ep);}