Sun Apr 4 19:23:54 2021 UTC ()
Add a config_probe() function.  This is currently a synonym for config_match(),
but exists so as to make a distinction between probing (as is done in indirect
configuration) and matching (which is done in direct configuration).

The intention is for direct config "submatch" routines to use config_match()
and for indirect config "search" routines to use config_probe().


(thorpej)
diff -r1.277.2.11 -r1.277.2.12 src/sys/kern/subr_autoconf.c
diff -r1.167.2.8 -r1.167.2.9 src/sys/sys/device.h

cvs diff -r1.277.2.11 -r1.277.2.12 src/sys/kern/subr_autoconf.c (expand / switch to unified diff)

--- src/sys/kern/subr_autoconf.c 2021/04/04 19:12:27 1.277.2.11
+++ src/sys/kern/subr_autoconf.c 2021/04/04 19:23:53 1.277.2.12
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: subr_autoconf.c,v 1.277.2.11 2021/04/04 19:12:27 thorpej Exp $ */ 1/* $NetBSD: subr_autoconf.c,v 1.277.2.12 2021/04/04 19:23:53 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996, 2000 Christopher G. Demetriou 4 * Copyright (c) 1996, 2000 Christopher G. Demetriou
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -67,27 +67,27 @@ @@ -67,27 +67,27 @@
67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 * SUCH DAMAGE. 72 * SUCH DAMAGE.
73 * 73 *
74 * from: Header: subr_autoconf.c,v 1.12 93/02/01 19:31:48 torek Exp (LBL) 74 * from: Header: subr_autoconf.c,v 1.12 93/02/01 19:31:48 torek Exp (LBL)
75 * 75 *
76 * @(#)subr_autoconf.c 8.3 (Berkeley) 5/17/94 76 * @(#)subr_autoconf.c 8.3 (Berkeley) 5/17/94
77 */ 77 */
78 78
79#include <sys/cdefs.h> 79#include <sys/cdefs.h>
80__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.277.2.11 2021/04/04 19:12:27 thorpej Exp $"); 80__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.277.2.12 2021/04/04 19:23:53 thorpej Exp $");
81 81
82#ifdef _KERNEL_OPT 82#ifdef _KERNEL_OPT
83#include "opt_ddb.h" 83#include "opt_ddb.h"
84#include "drvctl.h" 84#include "drvctl.h"
85#endif 85#endif
86 86
87#include <sys/param.h> 87#include <sys/param.h>
88#include <sys/device.h> 88#include <sys/device.h>
89#include <sys/disklabel.h> 89#include <sys/disklabel.h>
90#include <sys/conf.h> 90#include <sys/conf.h>
91#include <sys/kauth.h> 91#include <sys/kauth.h>
92#include <sys/kmem.h> 92#include <sys/kmem.h>
93#include <sys/systm.h> 93#include <sys/systm.h>
@@ -994,42 +994,57 @@ config_cfdata_detach(cfdata_t cf) @@ -994,42 +994,57 @@ config_cfdata_detach(cfdata_t cf)
994 if (ct->ct_cfdata == cf) { 994 if (ct->ct_cfdata == cf) {
995 TAILQ_REMOVE(&allcftables, ct, ct_list); 995 TAILQ_REMOVE(&allcftables, ct, ct_list);
996 kmem_free(ct, sizeof(*ct)); 996 kmem_free(ct, sizeof(*ct));
997 return 0; 997 return 0;
998 } 998 }
999 } 999 }
1000 1000
1001 /* not found -- shouldn't happen */ 1001 /* not found -- shouldn't happen */
1002 return EINVAL; 1002 return EINVAL;
1003} 1003}
1004 1004
1005/* 1005/*
1006 * Invoke the "match" routine for a cfdata entry on behalf of 1006 * Invoke the "match" routine for a cfdata entry on behalf of
1007 * an external caller, usually a "submatch" routine. 1007 * an external caller, usually a direct config "submatch" routine.
1008 */ 1008 */
1009int 1009int
1010config_match(device_t parent, cfdata_t cf, void *aux) 1010config_match(device_t parent, cfdata_t cf, void *aux)
1011{ 1011{
1012 struct cfattach *ca; 1012 struct cfattach *ca;
1013 1013
1014 ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname); 1014 ca = config_cfattach_lookup(cf->cf_name, cf->cf_atname);
1015 if (ca == NULL) { 1015 if (ca == NULL) {
1016 /* No attachment for this entry, oh well. */ 1016 /* No attachment for this entry, oh well. */
1017 return 0; 1017 return 0;
1018 } 1018 }
1019 1019
1020 return (*ca->ca_match)(parent, cf, aux); 1020 return (*ca->ca_match)(parent, cf, aux);
1021} 1021}
1022 1022
 1023/*
 1024 * Invoke the "probe" routine for a cfdata entry on behalf of
 1025 * an external caller, usually an indirect config "search" routine.
 1026 */
 1027int
 1028config_probe(device_t parent, cfdata_t cf, void *aux)
 1029{
 1030 /*
 1031 * This is currently a synonym for config_match(), but this
 1032 * is an implementation detail; "match" and "probe" routines
 1033 * have different behaviors.
 1034 */
 1035 return config_match(parent, cf, aux);
 1036}
 1037
1023static void 1038static void
1024config_get_cfargs(cfarg_t tag, 1039config_get_cfargs(cfarg_t tag,
1025 cfsubmatch_t *fnp, /* output */ 1040 cfsubmatch_t *fnp, /* output */
1026 const char **ifattrp, /* output */ 1041 const char **ifattrp, /* output */
1027 const int **locsp, /* output */ 1042 const int **locsp, /* output */
1028 devhandle_t *handlep, /* output */ 1043 devhandle_t *handlep, /* output */
1029 va_list ap) 1044 va_list ap)
1030{ 1045{
1031 cfsubmatch_t fn = NULL; 1046 cfsubmatch_t fn = NULL;
1032 const char *ifattr = NULL; 1047 const char *ifattr = NULL;
1033 const int *locs = NULL; 1048 const int *locs = NULL;
1034 devhandle_t handle; 1049 devhandle_t handle;
1035 1050

cvs diff -r1.167.2.8 -r1.167.2.9 src/sys/sys/device.h (expand / switch to unified diff)

--- src/sys/sys/device.h 2021/04/04 19:12:28 1.167.2.8
+++ src/sys/sys/device.h 2021/04/04 19:23:53 1.167.2.9
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: device.h,v 1.167.2.8 2021/04/04 19:12:28 thorpej Exp $ */ 1/* $NetBSD: device.h,v 1.167.2.9 2021/04/04 19:23:53 thorpej Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2021 The NetBSD Foundation, Inc. 4 * Copyright (c) 2021 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer. 11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright 12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the 13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution. 14 * documentation and/or other materials provided with the distribution.
@@ -577,26 +577,27 @@ int config_cfdata_detach(cfdata_t); @@ -577,26 +577,27 @@ int config_cfdata_detach(cfdata_t);
577struct cfdriver *config_cfdriver_lookup(const char *); 577struct cfdriver *config_cfdriver_lookup(const char *);
578struct cfattach *config_cfattach_lookup(const char *, const char *); 578struct cfattach *config_cfattach_lookup(const char *, const char *);
579const struct cfiattrdata *cfiattr_lookup(const char *, const struct cfdriver *); 579const struct cfiattrdata *cfiattr_lookup(const char *, const struct cfdriver *);
580 580
581const char *cfdata_ifattr(const struct cfdata *); 581const char *cfdata_ifattr(const struct cfdata *);
582 582
583int config_stdsubmatch(device_t, cfdata_t, const int *, void *); 583int config_stdsubmatch(device_t, cfdata_t, const int *, void *);
584cfdata_t config_search(device_t, void *, cfarg_t, ...); 584cfdata_t config_search(device_t, void *, cfarg_t, ...);
585cfdata_t config_rootsearch(cfsubmatch_t, const char *, void *); 585cfdata_t config_rootsearch(cfsubmatch_t, const char *, void *);
586device_t config_found(device_t, void *, cfprint_t, cfarg_t, ...); 586device_t config_found(device_t, void *, cfprint_t, cfarg_t, ...);
587device_t config_rootfound(const char *, void *); 587device_t config_rootfound(const char *, void *);
588device_t config_attach(device_t, cfdata_t, void *, cfprint_t, cfarg_t, ...); 588device_t config_attach(device_t, cfdata_t, void *, cfprint_t, cfarg_t, ...);
589int config_match(device_t, cfdata_t, void *); 589int config_match(device_t, cfdata_t, void *);
 590int config_probe(device_t, cfdata_t, void *);
590 591
591bool ifattr_match(const char *, const char *); 592bool ifattr_match(const char *, const char *);
592 593
593device_t config_attach_pseudo(cfdata_t); 594device_t config_attach_pseudo(cfdata_t);
594 595
595int config_detach(device_t, int); 596int config_detach(device_t, int);
596int config_detach_children(device_t, int flags); 597int config_detach_children(device_t, int flags);
597bool config_detach_all(int); 598bool config_detach_all(int);
598int config_deactivate(device_t); 599int config_deactivate(device_t);
599void config_defer(device_t, void (*)(device_t)); 600void config_defer(device_t, void (*)(device_t));
600void config_deferred(device_t); 601void config_deferred(device_t);
601void config_interrupts(device_t, void (*)(device_t)); 602void config_interrupts(device_t, void (*)(device_t));
602void config_mountroot(device_t, void (*)(device_t)); 603void config_mountroot(device_t, void (*)(device_t));