Module Name: src Committed By: pgoyette Date: Sat Dec 16 06:39:07 UTC 2017
Modified Files: src/sys/dev/pad: pad.c src/sys/modules/pad: Makefile Added Files: src/sys/modules/pad: pad.ioconf Log Message: Use config(1) and IOCONF= to generate most of the auto-config data structures. (Note that bin/52823 documents the reasons for still requiring hand-crafted cfattach structures.) To generate a diff of this commit: cvs rdiff -u -r1.47 -r1.48 src/sys/dev/pad/pad.c cvs rdiff -u -r1.2 -r1.3 src/sys/modules/pad/Makefile cvs rdiff -u -r0 -r1.1 src/sys/modules/pad/pad.ioconf Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/pad/pad.c diff -u src/sys/dev/pad/pad.c:1.47 src/sys/dev/pad/pad.c:1.48 --- src/sys/dev/pad/pad.c:1.47 Sat Dec 16 02:45:14 2017 +++ src/sys/dev/pad/pad.c Sat Dec 16 06:39:07 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: pad.c,v 1.47 2017/12/16 02:45:14 pgoyette Exp $ */ +/* $NetBSD: pad.c,v 1.48 2017/12/16 06:39:07 pgoyette Exp $ */ /*- * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca> @@ -27,7 +27,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.47 2017/12/16 02:45:14 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.48 2017/12/16 06:39:07 pgoyette Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -346,10 +346,11 @@ pad_open(dev_t dev, int flags, int fmt, cf->cf_unit = i; cf->cf_fstate = FSTATE_STAR; - if (device_lookup(&pad_cd, minor(dev)) == NULL) + paddev = device_lookup(&pad_cd, minor(dev)); + if (paddev == NULL) paddev = config_attach_pseudo(cf); - else - paddev = device_lookup(&pad_cd, minor(dev)); + if (paddev == NULL) + return ENXIO; sc = device_private(paddev); if (sc == NULL) @@ -903,39 +904,18 @@ MODULE(MODULE_CLASS_DRIVER, pad, "audio" #ifdef _MODULE -/* XXX These should really be created by config(1)'s IOCONF mechanism */ +#include "ioconf.c" -static const struct cfiattrdata audiobuscf_iattrdata = { - "audiobus", 0, { { NULL, NULL, 0 }, } -}; -static const struct cfiattrdata * const pad_attrs[] = { - &audiobuscf_iattrdata, NULL -}; - -CFDRIVER_DECL(pad, DV_DULL, pad_attrs); -extern struct cfattach pad_ca; -static int padloc[] = { -1, -1 }; - -static struct cfdata pad_cfdata[] = { - { - .cf_name = "pad", - .cf_atname = "pad", - .cf_unit = 0, - .cf_fstate = FSTATE_STAR, - .cf_loc = padloc, - .cf_flags = 0, - .cf_pspec = NULL, - }, - { NULL, NULL, 0, 0, NULL, 0, NULL } -}; +devmajor_t cmajor = NODEVMAJOR, bmajor = NODEVMAJOR; -/* provide the vectors required for config_{init,fini}_component() */ - -struct cfdriver * const pad_cfdriver[] = { &pad_cd, NULL }; +/* + * We need our own version of cfattach since config(1)'s ioconf does not + * generate what we need + */ -static struct cfattach * const pad_cfattachinit[] = { &pad_ca, NULL }; +static struct cfattach *pad_cfattachinit[] = { &pad_ca, NULL }; -static const struct cfattachinit pad_cfattach[] = { +static struct cfattachinit pad_cfattach[] = { { "pad", pad_cfattachinit }, { NULL, NULL } }; @@ -944,28 +924,25 @@ static const struct cfattachinit pad_cfa static int pad_modcmd(modcmd_t cmd, void *arg) { -#ifdef _MODULE - devmajor_t cmajor = NODEVMAJOR, bmajor = NODEVMAJOR; -#endif int error = 0; switch (cmd) { case MODULE_CMD_INIT: #ifdef _MODULE - error = config_init_component(pad_cfdriver, pad_cfattach, - pad_cfdata); + pad_cfattach[1] = cfattach_ioconf_pad[0]; + error = config_init_component(cfdriver_ioconf_pad, + pad_cfattach, cfdata_ioconf_pad); if (error) break; error = devsw_attach(pad_cd.cd_name, NULL, &bmajor, &pad_cdevsw, &cmajor); if (error) { - config_fini_component(pad_cfdriver, pad_cfattach, - pad_cfdata); + config_fini_component(cfdriver_ioconf_pad, + pad_cfattach, cfdata_ioconf_pad); break; } - (void)config_attach_pseudo(pad_cfdata); #endif break; @@ -975,8 +952,8 @@ pad_modcmd(modcmd_t cmd, void *arg) if (error) break; - error = config_fini_component(pad_cfdriver, pad_cfattach, - pad_cfdata); + error = config_fini_component(cfdriver_ioconf_pad, + pad_cfattach, cfdata_ioconf_pad); if (error) { error = devsw_attach(pad_cd.cd_name, NULL, &bmajor, &pad_cdevsw, &cmajor); Index: src/sys/modules/pad/Makefile diff -u src/sys/modules/pad/Makefile:1.2 src/sys/modules/pad/Makefile:1.3 --- src/sys/modules/pad/Makefile:1.2 Tue Nov 18 01:56:41 2014 +++ src/sys/modules/pad/Makefile Sat Dec 16 06:39:07 2017 @@ -1,10 +1,11 @@ -# $NetBSD: Makefile,v 1.2 2014/11/18 01:56:41 jmcneill Exp $ +# $NetBSD: Makefile,v 1.3 2017/12/16 06:39:07 pgoyette Exp $ .include "../Makefile.inc" .PATH: ${S}/dev/pad KMOD= pad +IOCONF= pad.ioconf SRCS= pad.c Added files: Index: src/sys/modules/pad/pad.ioconf diff -u /dev/null src/sys/modules/pad/pad.ioconf:1.1 --- /dev/null Sat Dec 16 06:39:07 2017 +++ src/sys/modules/pad/pad.ioconf Sat Dec 16 06:39:07 2017 @@ -0,0 +1,7 @@ +# $NetBSD: pad.ioconf,v 1.1 2017/12/16 06:39:07 pgoyette Exp $ + +ioconf pad + +include "conf/files" + +pseudo-device pad