Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/thorpej-cfargs]: src/sys Add CFARG_DEVHANDLE, allowing direct configurat...



details:   https://anonhg.NetBSD.org/src/rev/a9e9a50709de
branches:  thorpej-cfargs
changeset: 1019750:a9e9a50709de
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sat Apr 03 16:09:44 2021 +0000

description:
Add CFARG_DEVHANDLE, allowing direct configuration using e.g. ACPI or
OpenFirmware / FDT to associate the handle with the device_t.

diffstat:

 sys/kern/subr_autoconf.c |  25 ++++++++++++++++++++-----
 sys/sys/device.h         |   3 ++-
 2 files changed, 22 insertions(+), 6 deletions(-)

diffs (103 lines):

diff -r 7d98239c612f -r a9e9a50709de sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c  Sat Apr 03 15:37:07 2021 +0000
+++ b/sys/kern/subr_autoconf.c  Sat Apr 03 16:09:44 2021 +0000
@@ -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 @@
                  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 @@
                        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 @@
                *ifattrp = ifattr;
        if (locsp != NULL)
                *locsp = locs;
+       if (handlep != NULL)
+               *handlep = handle;
 }
 
 /*
@@ -1085,7 +1095,7 @@
        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 @@
        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 @@
        }
        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;
diff -r 7d98239c612f -r a9e9a50709de sys/sys/device.h
--- a/sys/sys/device.h  Sat Apr 03 15:37:07 2021 +0000
+++ b/sys/sys/device.h  Sat Apr 03 16:09:44 2021 +0000
@@ -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 @@
        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;



Home | Main Index | Thread Index | Old Index