summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorpgoyette <pgoyette@NetBSD.org>2017-06-01 09:44:30 +0000
committerpgoyette <pgoyette@NetBSD.org>2017-06-01 09:44:30 +0000
commitf309403ecaf75c98c14b8f8dc0ff769ee2767ab2 (patch)
tree3bb364564ed421d2a3a34ff841fa9997fe4feece /sys/dev
parent1195b3a6ab7a87627f4be6f3250cffe246306b32 (diff)
Add infrastructure for modularization of audio, midi, and sequencer
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/auconv.c6
-rw-r--r--sys/dev/audio.c60
-rw-r--r--sys/dev/midi.c52
-rw-r--r--sys/dev/pad/pad.c13
-rw-r--r--sys/dev/sequencer.c56
-rw-r--r--sys/dev/spkr.c6
6 files changed, 176 insertions, 17 deletions
diff --git a/sys/dev/auconv.c b/sys/dev/auconv.c
index 9300eb76e6c..8ea6af10c57 100644
--- a/sys/dev/auconv.c
+++ b/sys/dev/auconv.c
@@ -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.25 2011/11/23 23:07:31 jmcneill Exp $")
#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
diff --git a/sys/dev/audio.c b/sys/dev/audio.c
index 7d4c7ff0ff3..3fe6be3d82a 100644
--- a/sys/dev/audio.c
+++ b/sys/dev/audio.c
@@ -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 <nathanialsloss@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.356 2017/06/01 02:45:08 chs Exp $");
#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 devact);
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_long cmd, void *addr, int flag,
}
#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 *sc, int count)
}
#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;
+}
diff --git a/sys/dev/midi.c b/sys/dev/midi.c
index cbb6d61ec62..9c3591374ac 100644
--- a/sys/dev/midi.c
+++ b/sys/dev/midi.c
@@ -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.85 2016/07/14 10:19:05 msaitoh Exp $");
#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 *mhwp, void *hdlp, device_t dev)
}
#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;
+}
diff --git a/sys/dev/pad/pad.c b/sys/dev/pad/pad.c
index 9693cfe6b16..6de00c71cc9 100644
--- a/sys/dev/pad/pad.c
+++ b/sys/dev/pad/pad.c
@@ -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 <jmcneill@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_be(struct audio_softc *,
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 self, void *opaque)
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 }, }
diff --git a/sys/dev/sequencer.c b/sys/dev/sequencer.c
index 965566579a6..2e673e262be 100644
--- a/sys/dev/sequencer.c
+++ b/sys/dev/sequencer.c
@@ -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,v 1.65 2017/06/01 02:45:09 chs Exp $");
#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, int cc)
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;
+}
diff --git a/sys/dev/spkr.c b/sys/dev/spkr.c
index bed93eaea0e..4b18a1ef200 100644
--- a/sys/dev/spkr.c
+++ b/sys/dev/spkr.c
@@ -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 (esr@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)