diff options
author | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2018-05-26 10:16:15 +0000 |
---|---|---|
committer | Alexandre Ratchov <ratchov@cvs.openbsd.org> | 2018-05-26 10:16:15 +0000 |
commit | 2b9c730866c5160b4b1c190c07bb5b0f0d16d5a7 (patch) | |
tree | da3267bdc692d86888ea3fd1abc92db983fed833 | |
parent | 56c7c476f8191c9750adf4c9a5847cad92e74c02 (diff) |
In addition to "on" and "off", allow the audio "record.enable" mixer
knob to take the new "sysctl" value, which is the default. In this
case, the device behavior is determined by the new "kern.audio.record"
sysctl(2), which defaults to zero.
ok florian
-rw-r--r-- | sbin/sysctl/sysctl.c | 29 | ||||
-rw-r--r-- | sys/dev/audio.c | 21 | ||||
-rw-r--r-- | sys/kern/kern_sysctl.c | 21 | ||||
-rw-r--r-- | sys/sys/sysctl.h | 19 |
4 files changed, 82 insertions, 8 deletions
diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index c27c1ae22a7..98463345dd7 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.c,v 1.231 2018/03/06 20:56:36 tim Exp $ */ +/* $OpenBSD: sysctl.c,v 1.232 2018/05/26 10:16:14 ratchov Exp $ */ /* $NetBSD: sysctl.c,v 1.9 1995/09/30 07:12:50 thorpej Exp $ */ /* @@ -129,6 +129,7 @@ struct ctlname *vfsname; struct ctlname machdepname[] = CTL_MACHDEP_NAMES; #endif struct ctlname ddbname[] = CTL_DDB_NAMES; +struct ctlname audioname[] = CTL_KERN_AUDIO_NAMES; char names[BUFSIZ]; int lastused; @@ -212,6 +213,7 @@ void print_sensor(struct sensor *); #ifdef CPU_CHIPSET int sysctl_chipset(char *, char **, int *, int, int *); #endif +int sysctl_audio(char *, char **, int *, int, int *); void vfsinit(void); char *equ = "="; @@ -495,6 +497,11 @@ parse(char *string, int flags) case KERN_SOMINCONN: special |= UNSIGNED; break; + case KERN_AUDIO: + len = sysctl_audio(string, &bufp, mib, flags, &type); + if (len < 0) + return; + break; } break; @@ -1704,6 +1711,7 @@ struct list semlist = { semname, KERN_SEMINFO_MAXID }; struct list shmlist = { shmname, KERN_SHMINFO_MAXID }; struct list watchdoglist = { watchdogname, KERN_WATCHDOG_MAXID }; struct list tclist = { tcname, KERN_TIMECOUNTER_MAXID }; +struct list audiolist = { audioname, KERN_AUDIO_MAXID }; /* * handle vfs namei cache statistics @@ -2695,6 +2703,25 @@ print_sensor(struct sensor *s) } /* + * Handle audio support + */ +int +sysctl_audio(char *string, char **bufpp, int mib[], int flags, int *typep) +{ + int indx; + + if (*bufpp == NULL) { + listall(string, &audiolist); + return (-1); + } + if ((indx = findname(string, "third", bufpp, &audiolist)) == -1) + return (-1); + mib[2] = indx; + *typep = audiolist.list[indx].ctl_type; + return (3); +} + +/* * Scan a list of names searching for a particular name. */ int diff --git a/sys/dev/audio.c b/sys/dev/audio.c index 30260cc69a4..7bd6247d9a4 100644 --- a/sys/dev/audio.c +++ b/sys/dev/audio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: audio.c,v 1.170 2018/05/26 10:13:18 ratchov Exp $ */ +/* $OpenBSD: audio.c,v 1.171 2018/05/26 10:16:13 ratchov Exp $ */ /* * Copyright (c) 2015 Alexandre Ratchov <alex@caoua.org> * @@ -62,6 +62,7 @@ #define MIXER_RECORD_ENABLE 1 /* record.enable control */ #define MIXER_RECORD_ENABLE_OFF 0 /* record.enable=off value */ #define MIXER_RECORD_ENABLE_ON 1 /* record.enable=on value */ +#define MIXER_RECORD_ENABLE_SYSCTL 2 /* record.enable=sysctl val */ /* * dma buffer @@ -164,6 +165,12 @@ struct cfdriver audio_cd = { */ struct mutex audio_lock = MUTEX_INITIALIZER(IPL_AUDIO); +/* + * Global flag to control if audio recording is enabled when the + * mixerctl setting is record.enable=sysctl + */ +int audio_record_enable = 0; + #ifdef AUDIO_DEBUG /* * 0 - nothing, as if AUDIO_DEBUG isn't defined @@ -472,7 +479,9 @@ audio_rintr(void *addr) } sc->rec.pos += sc->rec.blksz; - if (sc->record_enable == MIXER_RECORD_ENABLE_OFF) { + if ((sc->record_enable == MIXER_RECORD_ENABLE_SYSCTL && + !audio_record_enable) || + sc->record_enable == MIXER_RECORD_ENABLE_OFF) { ptr = audio_buf_wgetblk(&sc->rec, &count); audio_fill_sil(sc, ptr, sc->rec.blksz); } @@ -1070,7 +1079,7 @@ audio_attach(struct device *parent, struct device *self, void *aux) sc->round = 960; sc->nblks = 2; sc->play.pos = sc->play.xrun = sc->rec.pos = sc->rec.xrun = 0; - sc->record_enable = MIXER_RECORD_ENABLE_OFF; + sc->record_enable = MIXER_RECORD_ENABLE_SYSCTL; /* * allocate an array of mixer_ctrl structures to save the @@ -1634,13 +1643,16 @@ audio_mixer_devinfo(struct audio_softc *sc, struct mixer_devinfo *devinfo) strlcpy(devinfo->label.name, "enable", MAX_AUDIO_DEV_LEN); devinfo->type = AUDIO_MIXER_ENUM; devinfo->mixer_class = MIXER_RECORD + sc->mix_nent; - devinfo->un.e.num_mem = 2; + devinfo->un.e.num_mem = 3; devinfo->un.e.member[0].ord = MIXER_RECORD_ENABLE_OFF; strlcpy(devinfo->un.e.member[0].label.name, "off", MAX_AUDIO_DEV_LEN); devinfo->un.e.member[1].ord = MIXER_RECORD_ENABLE_ON; strlcpy(devinfo->un.e.member[1].label.name, "on", MAX_AUDIO_DEV_LEN); + devinfo->un.e.member[2].ord = MIXER_RECORD_ENABLE_SYSCTL; + strlcpy(devinfo->un.e.member[2].label.name, "sysctl", + MAX_AUDIO_DEV_LEN); break; default: return EINVAL; @@ -1689,6 +1701,7 @@ audio_mixer_write(struct audio_softc *sc, struct mixer_ctrl *c, struct proc *p) switch (c->un.ord) { case MIXER_RECORD_ENABLE_OFF: case MIXER_RECORD_ENABLE_ON: + case MIXER_RECORD_ENABLE_SYSCTL: break; default: return EINVAL; diff --git a/sys/kern/kern_sysctl.c b/sys/kern/kern_sysctl.c index 439fa57fe7d..ee0313f2fbc 100644 --- a/sys/kern/kern_sysctl.c +++ b/sys/kern/kern_sysctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kern_sysctl.c,v 1.337 2018/05/16 14:53:43 visa Exp $ */ +/* $OpenBSD: kern_sysctl.c,v 1.338 2018/05/26 10:16:14 ratchov Exp $ */ /* $NetBSD: kern_sysctl.c,v 1.17 1996/05/20 17:49:05 mrg Exp $ */ /*- @@ -120,6 +120,7 @@ extern struct disklist_head disklist; extern fixpt_t ccpu; extern long numvnodes; extern u_int net_livelocks; +extern int audio_record_enable; int allowkmem; @@ -134,6 +135,7 @@ int sysctl_proc_vmmap(int *, u_int, void *, size_t *, struct proc *); int sysctl_intrcnt(int *, u_int, void *, size_t *); int sysctl_sensors(int *, u_int, void *, size_t *, void *, size_t); int sysctl_cptime2(int *, u_int, void *, size_t *, void *, size_t); +int sysctl_audio(int *, u_int, void *, size_t *, void *, size_t); void fill_file(struct kinfo_file *, struct file *, struct filedesc *, int, struct vnode *, struct process *, struct proc *, struct socket *, int); @@ -302,6 +304,7 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, case KERN_TIMECOUNTER: case KERN_CPTIME2: case KERN_FILE: + case KERN_AUDIO: break; default: return (ENOTDIR); /* overloaded */ @@ -655,6 +658,9 @@ kern_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, void *newp, case KERN_WITNESSWATCH: return witness_sysctl_watch(oldp, oldlenp, newp, newlen); #endif + case KERN_AUDIO: + return (sysctl_audio(name + 1, namelen - 1, oldp, oldlenp, + newp, newlen)); default: return (EOPNOTSUPP); } @@ -2368,3 +2374,16 @@ sysctl_cptime2(int *name, u_int namelen, void *oldp, size_t *oldlenp, &ci->ci_schedstate.spc_cp_time, sizeof(ci->ci_schedstate.spc_cp_time))); } + +int +sysctl_audio(int *name, u_int namelen, void *oldp, size_t *oldlenp, + void *newp, size_t newlen) +{ + if (namelen != 1) + return (ENOTDIR); + + if (name[0] != KERN_AUDIO_RECORD) + return (ENOENT); + + return (sysctl_int(oldp, oldlenp, newp, newlen, &audio_record_enable)); +} diff --git a/sys/sys/sysctl.h b/sys/sys/sysctl.h index 04e8d0d7f39..3618891b06c 100644 --- a/sys/sys/sysctl.h +++ b/sys/sys/sysctl.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sysctl.h,v 1.176 2018/05/16 14:53:43 visa Exp $ */ +/* $OpenBSD: sysctl.h,v 1.177 2018/05/26 10:16:14 ratchov Exp $ */ /* $NetBSD: sysctl.h,v 1.16 1996/04/09 20:55:36 cgd Exp $ */ /* @@ -184,7 +184,8 @@ struct ctlname { #define KERN_GLOBAL_PTRACE 81 /* allow ptrace globally */ #define KERN_CONSBUFSIZE 82 /* int: console message buffer size */ #define KERN_CONSBUF 83 /* console message buffer */ -#define KERN_MAXID 84 /* number of valid kern ids */ +#define KERN_AUDIO 84 /* struct: audio properties */ +#define KERN_MAXID 85 /* number of valid kern ids */ #define CTL_KERN_NAMES { \ { 0, 0 }, \ @@ -269,6 +270,9 @@ struct ctlname { { "proc_nobroadcastkill", CTLTYPE_NODE }, \ { "proc_vmmap", CTLTYPE_NODE }, \ { "global_ptrace", CTLTYPE_INT }, \ + { "gap", 0 }, \ + { "gap", 0 }, \ + { "audio", CTLTYPE_STRUCT }, \ } /* @@ -300,6 +304,17 @@ struct ctlname { #define KERN_PROC_NENV 4 /* + * KERN_AUDIO + */ +#define KERN_AUDIO_RECORD 1 +#define KERN_AUDIO_MAXID 2 + +#define CTL_KERN_AUDIO_NAMES { \ + { 0, 0 }, \ + { "record", CTLTYPE_INT }, \ +} + +/* * KERN_PROC subtype ops return arrays of relatively fixed size * structures of process info. Use 8 byte alignment, and new * elements should only be added to the end of this structure so |