Module Name: src Committed By: thorpej Date: Sat Apr 3 16:09:44 UTC 2021
Modified Files: src/sys/kern [thorpej-cfargs]: subr_autoconf.c src/sys/sys [thorpej-cfargs]: device.h Log Message: Add CFARG_DEVHANDLE, allowing direct configuration using e.g. ACPI or OpenFirmware / FDT to associate the handle with the device_t. To generate a diff of this commit: cvs rdiff -u -r1.277.2.9 -r1.277.2.10 src/sys/kern/subr_autoconf.c cvs rdiff -u -r1.167.2.6 -r1.167.2.7 src/sys/sys/device.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/kern/subr_autoconf.c diff -u src/sys/kern/subr_autoconf.c:1.277.2.9 src/sys/kern/subr_autoconf.c:1.277.2.10 --- src/sys/kern/subr_autoconf.c:1.277.2.9 Sat Apr 3 15:37:07 2021 +++ src/sys/kern/subr_autoconf.c Sat Apr 3 16:09:44 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: subr_autoconf.c,v 1.277.2.9 2021/04/03 15:37:07 thorpej Exp $ */ +/* $NetBSD: subr_autoconf.c,v 1.277.2.10 2021/04/03 16:09:44 thorpej Exp $ */ /* * Copyright (c) 1996, 2000 Christopher G. Demetriou @@ -77,7 +77,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.277.2.9 2021/04/03 15:37:07 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.277.2.10 2021/04/03 16:09:44 thorpej Exp $"); #ifdef _KERNEL_OPT #include "opt_ddb.h" @@ -1025,11 +1025,15 @@ config_get_cfargs(cfarg_t tag, cfsubmatch_t *fnp, /* output */ const char **ifattrp, /* output */ const int **locsp, /* output */ + devhandle_t *handlep, /* output */ va_list ap) { cfsubmatch_t fn = NULL; const char *ifattr = NULL; const int *locs = NULL; + devhandle_t handle; + + devhandle_invalidate(&handle); while (tag != CFARG_EOL) { switch (tag) { @@ -1045,6 +1049,10 @@ config_get_cfargs(cfarg_t tag, locs = va_arg(ap, const int *); break; + case CFARG_DEVHANDLE: + handle = va_arg(ap, devhandle_t); + break; + default: /* XXX panic? */ /* XXX dump stack backtrace? */ @@ -1062,6 +1070,8 @@ config_get_cfargs(cfarg_t tag, *ifattrp = ifattr; if (locsp != NULL) *locsp = locs; + if (handlep != NULL) + *handlep = handle; } /* @@ -1085,7 +1095,7 @@ config_vsearch(device_t parent, void *au cfdata_t cf; struct matchinfo m; - config_get_cfargs(tag, &fn, &ifattr, &locs, ap); + config_get_cfargs(tag, &fn, &ifattr, &locs, NULL, ap); KASSERT(config_initialized); KASSERT(!ifattr || cfdriver_get_iattr(parent->dv_cfdriver, ifattr)); @@ -1471,8 +1481,6 @@ config_vdevalloc(const device_t parent, device_lock_t dvl; const int *locs; - config_get_cfargs(tag, NULL, NULL, &locs, ap); - cd = config_cfdriver_lookup(cf->cf_name); if (cd == NULL) return NULL; @@ -1490,6 +1498,13 @@ config_vdevalloc(const device_t parent, } dev = kmem_zalloc(sizeof(*dev), KM_SLEEP); + /* + * If a handle was supplied to config_attach(), we'll get it + * assigned automatically here. If not, then we'll get the + * default invalid handle. + */ + config_get_cfargs(tag, NULL, NULL, &locs, &dev->dv_handle, ap); + dev->dv_class = cd->cd_class; dev->dv_cfdata = cf; dev->dv_cfdriver = cd; Index: src/sys/sys/device.h diff -u src/sys/sys/device.h:1.167.2.6 src/sys/sys/device.h:1.167.2.7 --- src/sys/sys/device.h:1.167.2.6 Sat Apr 3 06:54:29 2021 +++ src/sys/sys/device.h Sat Apr 3 16:09:44 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: device.h,v 1.167.2.6 2021/04/03 06:54:29 thorpej Exp $ */ +/* $NetBSD: device.h,v 1.167.2.7 2021/04/03 16:09:44 thorpej Exp $ */ /* * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -532,6 +532,7 @@ typedef enum { CFARG_SUBMATCH = 0, /* submatch function */ CFARG_IATTR = 1, /* interface attribute */ CFARG_LOCATORS = 2, /* locators array */ + CFARG_DEVHANDLE = 3, /* devhandle_t (by value) */ CFARG_EOL = 0xffffffff } cfarg_t;