Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F140106284
D45967.id140971.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
10 KB
Referenced Files
None
Subscribers
None
D45967.id140971.diff
View Options
diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile
--- a/share/man/man4/Makefile
+++ b/share/man/man4/Makefile
@@ -529,6 +529,7 @@
snd_cmi.4 \
snd_cs4281.4 \
snd_csa.4 \
+ snd_dummy.4 \
snd_emu10k1.4 \
snd_emu10kx.4 \
snd_envy24.4 \
diff --git a/share/man/man4/snd_dummy.4 b/share/man/man4/snd_dummy.4
new file mode 100644
--- /dev/null
+++ b/share/man/man4/snd_dummy.4
@@ -0,0 +1,70 @@
+.\"-
+.\" SPDX-License-Identifier: BSD-2-Clause
+.\"
+.\" Copyright (c) 2024 The FreeBSD Foundation
+.\"
+.\" Portions of this software were developed by Christos Margiolis
+.\" <christos@FreeBSD.org> under sponsorship from the FreeBSD Foundation.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+.\" SUCH DAMAGE.
+.\"
+.Dd July 15, 2024
+.Dt SND_DUMMY 4
+.Os
+.Sh NAME
+.Nm snd_dummy
+.Nd Dummy audio driver
+.Sh SYNOPSIS
+To load the driver at boot time, place the following line in
+.Xr loader.conf 5 :
+.Bd -literal -offset indent
+snd_dummy_load="YES"
+.Ed
+.Sh DESCRIPTION
+The
+.Nm
+driver implements a virtual audio device, meaning it does not correspond to a
+physical sound card.
+It is intended for testing, so that test programs do not need to rely on
+hardware being present in the machine in order to run.
+.Pp
+The driver attaches as a regular PCM device, with two "physical" channels (one
+playback and one recording), as well as a mixer.
+.Sh SEE ALSO
+.Xr sound 4 ,
+.Xr loader.conf 5 ,
+.Xr loader 8
+.Sh AUTHORS
+The
+.Nm
+driver was implemented by
+.An Christos Margiolis Aq Mt christos@FreeBSD.org
+under sponsorship from the
+.Fx
+Foundation.
+.Sh CAVEATS
+Currently IO does not work and the channel(s) will simply timeout after
+.Va hw.snd.timeout
+seconds.
+.Pp
+Because the driver automatically attaches once the module is loaded, it can
+only be attached once.
diff --git a/sys/dev/sound/dummy.c b/sys/dev/sound/dummy.c
new file mode 100644
--- /dev/null
+++ b/sys/dev/sound/dummy.c
@@ -0,0 +1,273 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2024 The FreeBSD Foundation
+ *
+ * This software was developed by Christos Margiolis <christos@FreeBSD.org>
+ * under sponsorship from the FreeBSD Foundation.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/bus.h>
+
+#ifdef HAVE_KERNEL_OPTION_HEADERS
+#include "opt_snd.h"
+#endif
+
+#include <dev/sound/pcm/sound.h>
+#include <mixer_if.h>
+
+struct dummy_chan {
+ struct dummy_softc *sc;
+ struct pcm_channel *pcm_ch;
+ struct snd_dbuf *pcm_buf;
+ struct pcmchan_caps *caps;
+ uint32_t cap_fmts[4];
+ uint8_t *buf;
+ size_t bufsz;
+};
+
+struct dummy_softc {
+ device_t dev;
+ struct dummy_chan chan_play;
+ struct dummy_chan chan_rec;
+};
+
+static int
+dummy_chan_free(kobj_t obj, void *data)
+{
+ struct dummy_chan *ch = data;
+
+ free(ch->buf, M_DEVBUF);
+ free(ch->caps, M_DEVBUF);
+ ch->buf = NULL;
+ ch->caps = NULL;
+
+ return (0);
+}
+
+static void *
+dummy_chan_init(kobj_t obj, void *devinfo, struct snd_dbuf *b,
+ struct pcm_channel *c, int dir)
+{
+ struct dummy_softc *sc;
+ struct dummy_chan *ch;
+
+ sc = devinfo;
+
+ ch = dir == PCMDIR_PLAY ? &sc->chan_play : &sc->chan_rec;
+ ch->sc = sc;
+ ch->bufsz = 1024;
+ ch->pcm_ch = c;
+ ch->pcm_buf = b;
+ ch->cap_fmts[0] = SND_FORMAT(AFMT_S32_LE, 2, 0);
+ ch->cap_fmts[1] = SND_FORMAT(AFMT_S24_LE, 2, 0);
+ ch->cap_fmts[2] = SND_FORMAT(AFMT_S16_LE, 2, 0);
+ ch->cap_fmts[3] = 0;
+ ch->buf = malloc(ch->bufsz, M_DEVBUF, M_WAITOK | M_ZERO);
+ ch->caps = malloc(sizeof(struct pcmchan_caps), M_DEVBUF,
+ M_WAITOK | M_ZERO);
+ *(ch->caps) = (struct pcmchan_caps){
+ 8000, /* minspeed */
+ 96000, /* maxspeed */
+ ch->cap_fmts, /* fmtlist */
+ 0, /* caps */
+ };
+ if (sndbuf_setup(ch->pcm_buf, ch->buf, ch->bufsz) != 0) {
+ dummy_chan_free(obj, ch);
+ return (NULL);
+ }
+
+ return (ch);
+}
+
+static int
+dummy_chan_setformat(kobj_t obj, void *data, uint32_t format)
+{
+ struct dummy_chan *ch = data;
+ int i;
+
+ for (i = 0; i < nitems(ch->cap_fmts); i++)
+ if (format == ch->cap_fmts[i])
+ return (0);
+
+ return (EINVAL);
+}
+
+static uint32_t
+dummy_chan_setspeed(kobj_t obj, void *data, uint32_t speed)
+{
+ struct dummy_chan *ch = data;
+
+ RANGE(speed, ch->caps->minspeed, ch->caps->maxspeed);
+
+ return (speed);
+}
+
+static uint32_t
+dummy_chan_setblocksize(kobj_t obj, void *data, uint32_t blocksize)
+{
+ struct dummy_chan *ch = data;
+
+ return (sndbuf_getblksz(ch->pcm_buf));
+}
+
+static int
+dummy_chan_trigger(kobj_t obj, void *data, int go)
+{
+ switch (go) {
+ case PCMTRIG_START:
+ break;
+ case PCMTRIG_STOP:
+ case PCMTRIG_ABORT:
+ break;
+ case PCMTRIG_EMLDMAWR:
+ case PCMTRIG_EMLDMARD:
+ break;
+ }
+
+ return (0);
+}
+
+static uint32_t
+dummy_chan_getptr(kobj_t obj, void *data)
+{
+ return (0);
+}
+
+static struct pcmchan_caps *
+dummy_chan_getcaps(kobj_t obj, void *data)
+{
+ struct dummy_chan *ch = data;
+
+ return (ch->caps);
+}
+
+static kobj_method_t dummy_chan_methods[] = {
+ KOBJMETHOD(channel_init, dummy_chan_init),
+ KOBJMETHOD(channel_free, dummy_chan_free),
+ KOBJMETHOD(channel_setformat, dummy_chan_setformat),
+ KOBJMETHOD(channel_setspeed, dummy_chan_setspeed),
+ KOBJMETHOD(channel_setblocksize,dummy_chan_setblocksize),
+ KOBJMETHOD(channel_trigger, dummy_chan_trigger),
+ KOBJMETHOD(channel_getptr, dummy_chan_getptr),
+ KOBJMETHOD(channel_getcaps, dummy_chan_getcaps),
+ KOBJMETHOD_END
+};
+
+CHANNEL_DECLARE(dummy_chan);
+
+static int
+dummy_mixer_init(struct snd_mixer *m)
+{
+ struct dummy_softc *sc;
+
+ sc = mix_getdevinfo(m);
+ if (sc == NULL)
+ return (-1);
+
+ pcm_setflags(sc->dev, pcm_getflags(sc->dev) | SD_F_SOFTPCMVOL);
+ mix_setdevs(m, SOUND_MASK_PCM | SOUND_MASK_VOLUME | SOUND_MASK_RECLEV);
+
+ return (0);
+}
+
+static int
+dummy_mixer_set(struct snd_mixer *m, unsigned dev, unsigned left, unsigned right)
+{
+ return (0);
+}
+
+static kobj_method_t dummy_mixer_methods[] = {
+ KOBJMETHOD(mixer_init, dummy_mixer_init),
+ KOBJMETHOD(mixer_set, dummy_mixer_set),
+ KOBJMETHOD_END
+};
+
+MIXER_DECLARE(dummy_mixer);
+
+static void
+dummy_identify(driver_t *driver, device_t parent)
+{
+ if (device_find_child(parent, driver->name, -1) != NULL)
+ return;
+ if (BUS_ADD_CHILD(parent, 0, driver->name, -1) == NULL)
+ device_printf(parent, "add child failed\n");
+}
+
+static int
+dummy_probe(device_t dev)
+{
+ device_set_desc(dev, "Dummy Audio Device");
+
+ return (0);
+}
+
+static int
+dummy_attach(device_t dev)
+{
+ struct dummy_softc *sc;
+
+ sc = device_get_ivars(dev);
+ sc->dev = dev;
+
+ pcm_setflags(dev, pcm_getflags(dev) | SD_F_MPSAFE);
+ if (pcm_register(dev, sc, 1, 1))
+ return (ENXIO);
+ pcm_addchan(dev, PCMDIR_PLAY, &dummy_chan_class, sc);
+ pcm_addchan(dev, PCMDIR_REC, &dummy_chan_class, sc);
+ pcm_setstatus(dev, "on nexus");
+ mixer_init(dev, &dummy_mixer_class, sc);
+
+ return (0);
+}
+
+static int
+dummy_detach(device_t dev)
+{
+ return (pcm_unregister(dev));
+}
+
+static device_method_t dummy_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_identify, dummy_identify),
+ DEVMETHOD(device_probe, dummy_probe),
+ DEVMETHOD(device_attach, dummy_attach),
+ DEVMETHOD(device_detach, dummy_detach),
+ DEVMETHOD_END
+};
+
+static driver_t dummy_driver = {
+ "pcm",
+ dummy_methods,
+ PCM_SOFTC_SIZE,
+};
+
+DRIVER_MODULE(snd_dummy, nexus, dummy_driver, 0, 0);
+MODULE_DEPEND(snd_dummy, sound, SOUND_MINVER, SOUND_PREFVER, SOUND_MAXVER);
+MODULE_VERSION(snd_dummy, 1);
diff --git a/sys/modules/sound/driver/Makefile b/sys/modules/sound/driver/Makefile
--- a/sys/modules/sound/driver/Makefile
+++ b/sys/modules/sound/driver/Makefile
@@ -9,6 +9,7 @@
SUBDIR+= envy24 envy24ht es137x fm801 hda hdsp hdspe ich
SUBDIR+= ${_maestro3} neomagic solo spicds t4dwave via8233
SUBDIR+= via82c686 vibes driver uaudio
+SUBDIR+= dummy
.if ${MK_SOURCELESS_UCODE} != "no"
_csa= csa
diff --git a/sys/modules/sound/driver/dummy/Makefile b/sys/modules/sound/driver/dummy/Makefile
new file mode 100644
--- /dev/null
+++ b/sys/modules/sound/driver/dummy/Makefile
@@ -0,0 +1,7 @@
+.PATH: ${SRCTOP}/sys/dev/sound
+
+KMOD= snd_dummy
+SRCS= bus_if.h device_if.h
+SRCS+= dummy.c
+
+.include <bsd.kmod.mk>
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Dec 21, 7:41 AM (5 h, 12 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
27109719
Default Alt Text
D45967.id140971.diff (10 KB)
Attached To
Mode
D45967: sound: Implement dummy driver
Attached
Detach File
Event Timeline
Log In to Comment