The branch main has been updated by christos:

URL: 
https://cgit.FreeBSD.org/src/commit/?id=2aa16666e2fa5c98be8d330cd0c32c9dc3801ba7

commit 2aa16666e2fa5c98be8d330cd0c32c9dc3801ba7
Author:     Christos Margiolis <[email protected]>
AuthorDate: 2026-01-02 16:56:46 +0000
Commit:     Christos Margiolis <[email protected]>
CommitDate: 2026-01-02 16:58:06 +0000

    sound: Take device type into account in sndstat
    
    sndstat will be extended to work with MIDI devices as well, so separate
    functionality based on the device type.
    
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Reviewed by:    markj
    Differential Revision:  https://reviews.freebsd.org/D54141
---
 sys/dev/sound/pcm/sound.c |  2 +-
 sys/dev/sound/sndstat.c   | 84 ++++++++++++++++++++++-------------------------
 sys/dev/sound/sndstat.h   |  7 +++-
 3 files changed, 47 insertions(+), 46 deletions(-)

diff --git a/sys/dev/sound/pcm/sound.c b/sys/dev/sound/pcm/sound.c
index 1e4b2eebdcaa..8ce369bfce5e 100644
--- a/sys/dev/sound/pcm/sound.c
+++ b/sys/dev/sound/pcm/sound.c
@@ -427,7 +427,7 @@ pcm_register(device_t dev, char *str)
        else if (snd_unit_auto == 1)
                snd_unit = pcm_best_unit(snd_unit);
 
-       sndstat_register(dev, d->status);
+       sndstat_register(dev, SNDST_TYPE_PCM, d->status);
 
        return (dsp_make_dev(dev));
 }
diff --git a/sys/dev/sound/sndstat.c b/sys/dev/sound/sndstat.c
index eee9e0b18108..b0ac7f7d0824 100644
--- a/sys/dev/sound/sndstat.c
+++ b/sys/dev/sound/sndstat.c
@@ -52,9 +52,6 @@
 
 #include "feeder_if.h"
 
-#define        SS_TYPE_PCM             1
-#define        SS_TYPE_MIDI            2
-
 static d_open_t sndstat_open;
 static void sndstat_close(void *);
 static d_read_t sndstat_read;
@@ -75,7 +72,8 @@ struct sndstat_entry {
        TAILQ_ENTRY(sndstat_entry) link;
        device_t dev;
        char *str;
-       int type, unit;
+       enum sndstat_type type;
+       int unit;
 };
 
 struct sndstat_userdev {
@@ -688,22 +686,26 @@ sndstat_create_devs_nvlist(nvlist_t **nvlp)
                return (ENOMEM);
 
        TAILQ_FOREACH(ent, &sndstat_devlist, link) {
-               struct snddev_info *d;
-               nvlist_t *di;
+               if (ent->type == SNDST_TYPE_PCM) {
+                       struct snddev_info *d;
+                       nvlist_t *di;
 
-               d = device_get_softc(ent->dev);
-               if (!PCM_REGISTERED(d))
-                       continue;
+                       d = device_get_softc(ent->dev);
+                       if (!PCM_REGISTERED(d))
+                               continue;
 
-               err = sndstat_build_sound4_nvlist(d, &di);
-               if (err)
-                       goto done;
+                       err = sndstat_build_sound4_nvlist(d, &di);
+                       if (err)
+                               goto done;
 
-               nvlist_append_nvlist_array(nvl, SNDST_DSPS, di);
-               nvlist_destroy(di);
-               err = nvlist_error(nvl);
-               if (err)
-                       goto done;
+                       nvlist_append_nvlist_array(nvl, SNDST_DSPS, di);
+                       nvlist_destroy(di);
+                       err = nvlist_error(nvl);
+                       if (err)
+                               goto done;
+               } else if (ent->type == SNDST_TYPE_MIDI) {
+                       /* TODO */
+               }
        }
 
        TAILQ_FOREACH(pf, &sndstat_filelist, entry) {
@@ -1154,22 +1156,14 @@ fail:
 
 /************************************************************************/
 
-int
-sndstat_register(device_t dev, char *str)
+void
+sndstat_register(device_t dev, enum sndstat_type type, char *str)
 {
        struct sndstat_entry *ent;
        struct sndstat_entry *pre;
-       const char *devtype;
-       int type, unit;
+       int unit;
 
        unit = device_get_unit(dev);
-       devtype = device_get_name(dev);
-       if (!strcmp(devtype, "pcm"))
-               type = SS_TYPE_PCM;
-       else if (!strcmp(devtype, "midi"))
-               type = SS_TYPE_MIDI;
-       else
-               return (EINVAL);
 
        ent = malloc(sizeof *ent, M_DEVBUF, M_WAITOK | M_ZERO);
        ent->dev = dev;
@@ -1195,8 +1189,6 @@ sndstat_register(device_t dev, char *str)
                TAILQ_INSERT_BEFORE(pre, ent, link);
        }
        SNDSTAT_UNLOCK();
-
-       return (0);
 }
 
 int
@@ -1388,20 +1380,24 @@ sndstat_prepare(struct sndstat_file *pf_self)
        /* generate list of installed devices */
        k = 0;
        TAILQ_FOREACH(ent, &sndstat_devlist, link) {
-               d = device_get_softc(ent->dev);
-               if (!PCM_REGISTERED(d))
-                       continue;
-               if (!k++)
-                       sbuf_printf(s, "Installed devices:\n");
-               sbuf_printf(s, "%s:", device_get_nameunit(ent->dev));
-               sbuf_printf(s, " <%s>", device_get_desc(ent->dev));
-               if (snd_verbose > 0)
-                       sbuf_printf(s, " %s", ent->str);
-               /* XXX Need Giant magic entry ??? */
-               PCM_ACQUIRE_QUICK(d);
-               sndstat_prepare_pcm(s, ent->dev, snd_verbose);
-               PCM_RELEASE_QUICK(d);
-               sbuf_printf(s, "\n");
+               if (ent->type == SNDST_TYPE_PCM) {
+                       d = device_get_softc(ent->dev);
+                       if (!PCM_REGISTERED(d))
+                               continue;
+                       if (!k++)
+                               sbuf_printf(s, "Installed devices:\n");
+                       sbuf_printf(s, "%s:", device_get_nameunit(ent->dev));
+                       sbuf_printf(s, " <%s>", device_get_desc(ent->dev));
+                       if (snd_verbose > 0)
+                               sbuf_printf(s, " %s", ent->str);
+                       /* XXX Need Giant magic entry ??? */
+                       PCM_ACQUIRE_QUICK(d);
+                       sndstat_prepare_pcm(s, ent->dev, snd_verbose);
+                       PCM_RELEASE_QUICK(d);
+                       sbuf_printf(s, "\n");
+               } else if (ent->type == SNDST_TYPE_MIDI) {
+                       /* TODO */
+               }
        }
        if (k == 0)
                sbuf_printf(s, "No devices installed.\n");
diff --git a/sys/dev/sound/sndstat.h b/sys/dev/sound/sndstat.h
index d6735f74af31..3ac0cf48f5a8 100644
--- a/sys/dev/sound/sndstat.h
+++ b/sys/dev/sound/sndstat.h
@@ -31,7 +31,12 @@
 #ifndef _SNDSTAT_H_
 #define _SNDSTAT_H_
 
-int sndstat_register(device_t dev, char *str);
+enum sndstat_type {
+       SNDST_TYPE_PCM,
+       SNDST_TYPE_MIDI,
+};
+
+void sndstat_register(device_t dev, enum sndstat_type type, char *str);
 int sndstat_unregister(device_t dev);
 
 #endif /* _SNDSTAT_H_ */

Reply via email to