Module Name: src Committed By: pgoyette Date: Thu Jun 1 09:44:30 UTC 2017
Modified Files: src/sys/dev: auconv.c audio.c midi.c sequencer.c spkr.c src/sys/dev/pad: pad.c src/sys/rump/dev/lib/libaudio: Makefile audio_component.c Log Message: Add infrastructure for modularization of audio, midi, and sequencer To generate a diff of this commit: cvs rdiff -u -r1.25 -r1.26 src/sys/dev/auconv.c cvs rdiff -u -r1.356 -r1.357 src/sys/dev/audio.c cvs rdiff -u -r1.85 -r1.86 src/sys/dev/midi.c cvs rdiff -u -r1.65 -r1.66 src/sys/dev/sequencer.c cvs rdiff -u -r1.6 -r1.7 src/sys/dev/spkr.c cvs rdiff -u -r1.31 -r1.32 src/sys/dev/pad/pad.c cvs rdiff -u -r1.5 -r1.6 src/sys/rump/dev/lib/libaudio/Makefile cvs rdiff -u -r1.3 -r1.4 src/sys/rump/dev/lib/libaudio/audio_component.c 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/auconv.c diff -u src/sys/dev/auconv.c:1.25 src/sys/dev/auconv.c:1.26 --- src/sys/dev/auconv.c:1.25 Wed Nov 23 23:07:31 2011 +++ src/sys/dev/auconv.c Thu Jun 1 09:44:30 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: auconv.c,v 1.25 2011/11/23 23:07:31 jmcneill Exp $ */ +/* $NetBSD: auconv.c,v 1.26 2017/06/01 09:44:30 pgoyette Exp $ */ /* * Copyright (c) 1996 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: auconv.c,v 1.25 2011/11/23 23:07:31 jmcneill Exp $"); +__KERNEL_RCSID(0, "$NetBSD: auconv.c,v 1.26 2017/06/01 09:44:30 pgoyette Exp $"); #include <sys/types.h> #include <sys/audioio.h> @@ -56,8 +56,10 @@ __KERNEL_RCSID(0, "$NetBSD: auconv.c,v 1 #include <stdbool.h> #endif +#ifdef _KERNEL_OPT #include <aurateconv.h> /* generated by config(8) */ #include <mulaw.h> /* generated by config(8) */ +#endif /* #define AUCONV_DEBUG */ #ifdef AUCONV_DEBUG Index: src/sys/dev/audio.c diff -u src/sys/dev/audio.c:1.356 src/sys/dev/audio.c:1.357 --- src/sys/dev/audio.c:1.356 Thu Jun 1 02:45:08 2017 +++ src/sys/dev/audio.c Thu Jun 1 09:44:30 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: audio.c,v 1.356 2017/06/01 02:45:08 chs Exp $ */ +/* $NetBSD: audio.c,v 1.357 2017/06/01 09:44:30 pgoyette Exp $ */ /*- * Copyright (c) 2016 Nathanial Sloss <nathanialsl...@yahoo.com.au> @@ -148,9 +148,13 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.356 2017/06/01 02:45:08 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: audio.c,v 1.357 2017/06/01 09:44:30 pgoyette Exp $"); +#ifdef _KERNEL_OPT #include "audio.h" +#include "midi.h" +#endif + #if NAUDIO > 0 #include <sys/types.h> @@ -165,6 +169,7 @@ __KERNEL_RCSID(0, "$NetBSD: audio.c,v 1. #include <sys/kauth.h> #include <sys/kmem.h> #include <sys/malloc.h> +#include <sys/module.h> #include <sys/proc.h> #include <sys/queue.h> #include <sys/stat.h> @@ -309,6 +314,8 @@ static int audioactivate(device_t, enum static void audiochilddet(device_t, device_t); static int audiorescan(device_t, const char *, const int *); +static int audio_modcmd(modcmd_t, void *); + #ifdef AUDIO_PM_IDLE static void audio_idle(void *); static void audio_activity(device_t, devactive_t); @@ -5136,8 +5143,6 @@ mixer_ioctl(struct audio_softc *sc, u_lo } #endif /* NAUDIO > 0 */ -#include "midi.h" - #if NAUDIO == 0 && (NMIDI > 0 || NMIDIBUS > 0) #include <sys/param.h> #include <sys/systm.h> @@ -6130,3 +6135,50 @@ shrink_mixer_states(struct audio_softc * } #endif /* NAUDIO > 0 */ + +#ifdef _MODULE + +extern struct cfdriver audio_cd; +devmajor_t audio_bmajor = -1, audio_cmajor = -1; + +#include "ioconf.c" + +#endif + +MODULE(MODULE_CLASS_DRIVER, audio, NULL); + +static int +audio_modcmd(modcmd_t cmd, void *arg) +{ + int error = 0; + +#ifdef _MODULE + switch (cmd) { + case MODULE_CMD_INIT: + error = devsw_attach(audio_cd.cd_name, NULL, &audio_bmajor, + &audio_cdevsw, &audio_cmajor); + if (error) + break; + + error = config_init_component(cfdriver_ioconf_audio, + cfattach_ioconf_audio, cfdata_ioconf_audio); + if (error) { + devsw_detach(NULL, &audio_cdevsw); + } + break; + case MODULE_CMD_FINI: + devsw_detach(NULL, &audio_cdevsw); + error = config_fini_component(cfdriver_ioconf_audio, + cfattach_ioconf_audio, cfdata_ioconf_audio); + if (error) + devsw_attach(audio_cd.cd_name, NULL, &audio_bmajor, + &audio_cdevsw, &audio_cmajor); + break; + default: + error = ENOTTY; + break; + } +#endif + + return error; +} Index: src/sys/dev/midi.c diff -u src/sys/dev/midi.c:1.85 src/sys/dev/midi.c:1.86 --- src/sys/dev/midi.c:1.85 Thu Jul 14 10:19:05 2016 +++ src/sys/dev/midi.c Thu Jun 1 09:44:30 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: midi.c,v 1.85 2016/07/14 10:19:05 msaitoh Exp $ */ +/* $NetBSD: midi.c,v 1.86 2017/06/01 09:44:30 pgoyette Exp $ */ /* * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc. @@ -31,10 +31,12 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.85 2016/07/14 10:19:05 msaitoh Exp $"); +__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.86 2017/06/01 09:44:30 pgoyette Exp $"); +#ifdef _KERNEL_OPT #include "midi.h" #include "sequencer.h" +#endif #include <sys/param.h> #include <sys/ioctl.h> @@ -53,6 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.8 #include <sys/midiio.h> #include <sys/device.h> #include <sys/intr.h> +#include <sys/module.h> #include <dev/audio_if.h> #include <dev/midi_if.h> @@ -1887,3 +1890,48 @@ midi_attach_mi(const struct midi_hw_if * } #endif /* NMIDI > 0 || NMIDIBUS > 0 */ + +#ifdef _MODULE +extern struct cfdriver midi_cd; +#include "ioconf.c" + +devmajor_t midi_bmajor = -1, midi_cmajor = -1; +#endif + +MODULE(MODULE_CLASS_DRIVER, midi, "audio"); + +static int +midi_modcmd(modcmd_t cmd, void *arg) +{ + int error = 0; + +#ifdef _MODULE + switch (cmd) { + case MODULE_CMD_INIT: + error = devsw_attach(midi_cd.cd_name, NULL, &midi_bmajor, + &midi_cdevsw, &midi_cmajor); + if (error) + break; + + error = config_init_component(cfdriver_ioconf_midi, + cfattach_ioconf_midi, cfdata_ioconf_midi); + if (error) { + devsw_detach(NULL, &midi_cdevsw); + } + break; + case MODULE_CMD_FINI: + devsw_detach(NULL, &midi_cdevsw); + error = config_fini_component(cfdriver_ioconf_midi, + cfattach_ioconf_midi, cfdata_ioconf_midi); + if (error) + devsw_attach(midi_cd.cd_name, NULL, &midi_bmajor, + &midi_cdevsw, &midi_cmajor); + break; + default: + error = ENOTTY; + break; + } +#endif + + return error; +} Index: src/sys/dev/sequencer.c diff -u src/sys/dev/sequencer.c:1.65 src/sys/dev/sequencer.c:1.66 --- src/sys/dev/sequencer.c:1.65 Thu Jun 1 02:45:09 2017 +++ src/sys/dev/sequencer.c Thu Jun 1 09:44:30 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: sequencer.c,v 1.65 2017/06/01 02:45:09 chs Exp $ */ +/* $NetBSD: sequencer.c,v 1.66 2017/06/01 09:44:30 pgoyette Exp $ */ /* * Copyright (c) 1998, 2008 The NetBSD Foundation, Inc. @@ -55,9 +55,12 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.65 2017/06/01 02:45:09 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sequencer.c,v 1.66 2017/06/01 09:44:30 pgoyette Exp $"); +#ifdef _KERNEL_OPT #include "sequencer.h" +#include "midi.h" +#endif #include <sys/param.h> #include <sys/ioctl.h> @@ -80,6 +83,7 @@ __KERNEL_RCSID(0, "$NetBSD: sequencer.c, #include <sys/pcq.h> #include <sys/vnode.h> #include <sys/kauth.h> +#include <sys/module.h> #include <dev/midi_if.h> #include <dev/midivar.h> @@ -1603,7 +1607,6 @@ midiseq_loadpatch(struct midi_dev *md, return error; } -#include "midi.h" #if NMIDI == 0 static dev_type_open(midiopen); static dev_type_close(midiclose); @@ -1661,3 +1664,50 @@ midi_writebytes(int unit, u_char *bf, in return (ENXIO); } #endif /* NMIDI == 0 */ + +#ifdef _MODULE +extern struct cfdriver sequencer_cd; +#include "ioconf.c" + +devmajor_t sequencer_bmajor = -1, sequencer_cmajor = -1; +#endif + +MODULE(MODULE_CLASS_DRIVER, sequencer, "midi"); + +static int +sequencer_modcmd(modcmd_t cmd, void *arg) +{ + int error = 0; + +#ifdef _MODULE + switch (cmd) { + case MODULE_CMD_INIT: + error = devsw_attach(sequencer_cd.cd_name, + NULL, &sequencer_bmajor, + &sequencer_cdevsw, &sequencer_cmajor); + if (error) + break; + + error = config_init_component(cfdriver_ioconf_sequencer, + cfattach_ioconf_sequencer, cfdata_ioconf_sequencer); + if (error) { + devsw_detach(NULL, &sequencer_cdevsw); + } + break; + case MODULE_CMD_FINI: + devsw_detach(NULL, &sequencer_cdevsw); + error = config_fini_component(cfdriver_ioconf_sequencer, + cfattach_ioconf_sequencer, cfdata_ioconf_sequencer); + if (error) + devsw_attach(sequencer_cd.cd_name, + NULL, &sequencer_bmajor, + &sequencer_cdevsw, &sequencer_cmajor); + break; + default: + error = ENOTTY; + break; + } +#endif + + return error; +} Index: src/sys/dev/spkr.c diff -u src/sys/dev/spkr.c:1.6 src/sys/dev/spkr.c:1.7 --- src/sys/dev/spkr.c:1.6 Fri Jan 6 09:32:08 2017 +++ src/sys/dev/spkr.c Thu Jun 1 09:44:30 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: spkr.c,v 1.6 2017/01/06 09:32:08 pgoyette Exp $ */ +/* $NetBSD: spkr.c,v 1.7 2017/06/01 09:44:30 pgoyette Exp $ */ /* * Copyright (c) 1990 Eric S. Raymond (e...@snark.thyrsus.com) @@ -43,7 +43,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.6 2017/01/06 09:32:08 pgoyette Exp $"); +__KERNEL_RCSID(0, "$NetBSD: spkr.c,v 1.7 2017/06/01 09:44:30 pgoyette Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -494,7 +494,7 @@ extern struct cfdriver spkr_cd; #include "ioconf.c" #endif -MODULE(MODULE_CLASS_DRIVER, spkr, "" /* audio and/or pcppi */ ); +MODULE(MODULE_CLASS_DRIVER, spkr, "audio" /* and/or pcppi */ ); int spkr_modcmd(modcmd_t cmd, void *arg) Index: src/sys/dev/pad/pad.c diff -u src/sys/dev/pad/pad.c:1.31 src/sys/dev/pad/pad.c:1.32 --- src/sys/dev/pad/pad.c:1.31 Thu Jun 1 02:45:10 2017 +++ src/sys/dev/pad/pad.c Thu Jun 1 09:44:30 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: pad.c,v 1.31 2017/06/01 02:45:10 chs Exp $ */ +/* $NetBSD: pad.c,v 1.32 2017/06/01 09:44:30 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.31 2017/06/01 02:45:10 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pad.c,v 1.32 2017/06/01 09:44:30 pgoyette Exp $"); #include <sys/types.h> #include <sys/param.h> @@ -99,6 +99,8 @@ static stream_filter_t *pad_swvol_filter const audio_params_t *, const audio_params_t *); static void pad_swvol_dtor(stream_filter_t *); +static bool pad_is_attached; /* Do we have an audio* child? */ + static const struct audio_hw_if pad_hw_if = { .open = pad_audio_open, .query_encoding = pad_query_encoding, @@ -275,6 +277,7 @@ pad_attach(device_t parent, device_t sel if (!pmf_device_register(self, NULL, NULL)) aprint_error_dev(self, "couldn't establish power handler\n"); + pad_is_attached = true; return; } @@ -284,6 +287,9 @@ pad_detach(device_t self, int flags) pad_softc_t *sc = device_private(self); int cmaj, mn, rc; + if (!pad_is_attached) + return ENXIO; + cmaj = cdevsw_lookup_major(&pad_cdevsw); mn = device_unit(self); vdevgone(cmaj, mn, mn, VCHR); @@ -299,6 +305,7 @@ pad_detach(device_t self, int flags) auconv_delete_encodings(sc->sc_encodings); + pad_is_attached = false; return 0; } @@ -721,7 +728,7 @@ pad_swvol_dtor(stream_filter_t *this) #ifdef _MODULE -MODULE(MODULE_CLASS_DRIVER, pad, NULL); +MODULE(MODULE_CLASS_DRIVER, pad, "audio"); static const struct cfiattrdata audiobuscf_iattrdata = { "audiobus", 0, { { NULL, NULL, 0 }, } Index: src/sys/rump/dev/lib/libaudio/Makefile diff -u src/sys/rump/dev/lib/libaudio/Makefile:1.5 src/sys/rump/dev/lib/libaudio/Makefile:1.6 --- src/sys/rump/dev/lib/libaudio/Makefile:1.5 Tue Jan 26 23:12:14 2016 +++ src/sys/rump/dev/lib/libaudio/Makefile Thu Jun 1 09:44:30 2017 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.5 2016/01/26 23:12:14 pooka Exp $ +# $NetBSD: Makefile,v 1.6 2017/06/01 09:44:30 pgoyette Exp $ # .PATH: ${.CURDIR}/../../../../dev @@ -11,5 +11,7 @@ IOCONF= AUDIO.ioconf SRCS= audio.c auconv.c aurateconv.c auvolconv.c mulaw.c SRCS+= audio_component.c +CPPFLAGS+= -DNAUDIO=1 -DNAURATECONV=1 -DNMULAW=1 + .include <bsd.lib.mk> .include <bsd.klinks.mk> Index: src/sys/rump/dev/lib/libaudio/audio_component.c diff -u src/sys/rump/dev/lib/libaudio/audio_component.c:1.3 src/sys/rump/dev/lib/libaudio/audio_component.c:1.4 --- src/sys/rump/dev/lib/libaudio/audio_component.c:1.3 Tue Jan 26 23:12:14 2016 +++ src/sys/rump/dev/lib/libaudio/audio_component.c Thu Jun 1 09:44:30 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: audio_component.c,v 1.3 2016/01/26 23:12:14 pooka Exp $ */ +/* $NetBSD: audio_component.c,v 1.4 2017/06/01 09:44:30 pgoyette Exp $ */ /* * Copyright (c) 2010 Antti Kantee. All Rights Reserved. @@ -26,7 +26,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: audio_component.c,v 1.3 2016/01/26 23:12:14 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: audio_component.c,v 1.4 2017/06/01 09:44:30 pgoyette Exp $"); #include <sys/param.h> #include <sys/conf.h> @@ -36,42 +36,37 @@ __KERNEL_RCSID(0, "$NetBSD: audio_compon #include <dev/audio_if.h> -#include "ioconf.c" - #include <rump-sys/kern.h> #include <rump-sys/vfs.h> RUMP_COMPONENT(RUMP_COMPONENT_DEV) { extern const struct cdevsw audio_cdevsw; - devmajor_t bmaj, cmaj; + extern devmajor_t audio_bmajor, audio_cmajor; int error; - config_init_component(cfdriver_ioconf_audio, - cfattach_ioconf_audio, cfdata_ioconf_audio); - - bmaj = cmaj = NODEVMAJOR; - if ((error = devsw_attach("audio", NULL, &bmaj, - &audio_cdevsw, &cmaj)) != 0) + if ((error = devsw_attach("audio", NULL, &audio_bmajor, + &audio_cdevsw, &audio_cmajor)) != 0) panic("audio devsw attach failed: %d", error); if ((error = rump_vfs_makedevnodes(S_IFCHR, "/dev/audio", '0', - cmaj, AUDIO_DEVICE, 4)) !=0) + audio_cmajor, AUDIO_DEVICE, 4)) !=0) panic("cannot create audio device nodes: %d", error); if ((error = rump_vfs_makesymlink("audio0", "/dev/audio")) != 0) panic("cannot create audio symlink: %d", error); if ((error = rump_vfs_makedevnodes(S_IFCHR, "/dev/sound", '0', - cmaj, SOUND_DEVICE, 4)) !=0) + audio_cmajor, SOUND_DEVICE, 4)) !=0) panic("cannot create sound device nodes: %d", error); if ((error = rump_vfs_makesymlink("sound0", "/dev/sound")) != 0) panic("cannot create sound symlink: %d", error); if ((error = rump_vfs_makedevnodes(S_IFCHR, "/dev/audioctl", '0', - cmaj, AUDIOCTL_DEVICE, 4)) !=0) + audio_cmajor, AUDIOCTL_DEVICE, 4)) !=0) panic("cannot create audioctl device nodes: %d", error); if ((error = rump_vfs_makesymlink("audioctl0", "/dev/audioctl")) != 0) panic("cannot create audioctl symlink: %d", error); if ((error = rump_vfs_makedevnodes(S_IFCHR, "/dev/mixer", '0', - cmaj, MIXER_DEVICE, 4)) !=0) + audio_cmajor, MIXER_DEVICE, 4)) !=0) panic("cannot create mixer device nodes: %d", error); if ((error = rump_vfs_makesymlink("mixer0", "/dev/mixer")) != 0) panic("cannot create mixer symlink: %d", error); + devsw_detach(NULL, &audio_cdevsw); }