1/*- 2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <dev/sound/pcm/sound.h> 28 29#include "mixer_if.h" 30
| 1/*- 2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <dev/sound/pcm/sound.h> 28 29#include "mixer_if.h" 30
|
31SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/mixer.c 170235 2007-06-03 10:56:22Z ariff $");
| 31SND_DECLARE_FILE("$FreeBSD: head/sys/dev/sound/pcm/mixer.c 170815 2007-06-16 03:37:28Z ariff $");
|
32 33MALLOC_DEFINE(M_MIXER, "mixer", "mixer"); 34 35#define MIXER_NAMELEN 16 36struct snd_mixer { 37 KOBJ_FIELDS;
| 32 33MALLOC_DEFINE(M_MIXER, "mixer", "mixer"); 34 35#define MIXER_NAMELEN 16 36struct snd_mixer { 37 KOBJ_FIELDS;
|
38 const char *type;
| |
39 void *devinfo; 40 int busy; 41 int hwvol_muted; 42 int hwvol_mixer; 43 int hwvol_step;
| 38 void *devinfo; 39 int busy; 40 int hwvol_muted; 41 int hwvol_mixer; 42 int hwvol_step;
|
| 43 int type;
|
44 device_t dev; 45 u_int32_t hwvol_mute_level; 46 u_int32_t devs; 47 u_int32_t recdevs; 48 u_int32_t recsrc; 49 u_int16_t level[32]; 50 u_int8_t parent[32]; 51 u_int32_t child[32]; 52 u_int8_t realdev[32]; 53 char name[MIXER_NAMELEN]; 54 struct mtx *lock; 55 oss_mixer_enuminfo enuminfo; 56 /** 57 * Counter is incremented when applications change any of this 58 * mixer's controls. A change in value indicates that persistent 59 * mixer applications should update their displays. 60 */ 61 int modify_counter; 62}; 63 64static u_int16_t snd_mixerdefaults[SOUND_MIXER_NRDEVICES] = { 65 [SOUND_MIXER_VOLUME] = 75, 66 [SOUND_MIXER_BASS] = 50, 67 [SOUND_MIXER_TREBLE] = 50, 68 [SOUND_MIXER_SYNTH] = 75, 69 [SOUND_MIXER_PCM] = 75, 70 [SOUND_MIXER_SPEAKER] = 75, 71 [SOUND_MIXER_LINE] = 75, 72 [SOUND_MIXER_MIC] = 0, 73 [SOUND_MIXER_CD] = 75, 74 [SOUND_MIXER_IGAIN] = 0, 75 [SOUND_MIXER_LINE1] = 75, 76 [SOUND_MIXER_VIDEO] = 75, 77 [SOUND_MIXER_RECLEV] = 0, 78 [SOUND_MIXER_OGAIN] = 50, 79 [SOUND_MIXER_MONITOR] = 75, 80}; 81 82static char* snd_mixernames[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; 83 84static d_open_t mixer_open; 85static d_close_t mixer_close;
| 44 device_t dev; 45 u_int32_t hwvol_mute_level; 46 u_int32_t devs; 47 u_int32_t recdevs; 48 u_int32_t recsrc; 49 u_int16_t level[32]; 50 u_int8_t parent[32]; 51 u_int32_t child[32]; 52 u_int8_t realdev[32]; 53 char name[MIXER_NAMELEN]; 54 struct mtx *lock; 55 oss_mixer_enuminfo enuminfo; 56 /** 57 * Counter is incremented when applications change any of this 58 * mixer's controls. A change in value indicates that persistent 59 * mixer applications should update their displays. 60 */ 61 int modify_counter; 62}; 63 64static u_int16_t snd_mixerdefaults[SOUND_MIXER_NRDEVICES] = { 65 [SOUND_MIXER_VOLUME] = 75, 66 [SOUND_MIXER_BASS] = 50, 67 [SOUND_MIXER_TREBLE] = 50, 68 [SOUND_MIXER_SYNTH] = 75, 69 [SOUND_MIXER_PCM] = 75, 70 [SOUND_MIXER_SPEAKER] = 75, 71 [SOUND_MIXER_LINE] = 75, 72 [SOUND_MIXER_MIC] = 0, 73 [SOUND_MIXER_CD] = 75, 74 [SOUND_MIXER_IGAIN] = 0, 75 [SOUND_MIXER_LINE1] = 75, 76 [SOUND_MIXER_VIDEO] = 75, 77 [SOUND_MIXER_RECLEV] = 0, 78 [SOUND_MIXER_OGAIN] = 50, 79 [SOUND_MIXER_MONITOR] = 75, 80}; 81 82static char* snd_mixernames[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_NAMES; 83 84static d_open_t mixer_open; 85static d_close_t mixer_close;
|
| 86static d_ioctl_t mixer_ioctl;
|
86 87static struct cdevsw mixer_cdevsw = { 88 .d_version = D_VERSION,
| 87 88static struct cdevsw mixer_cdevsw = { 89 .d_version = D_VERSION,
|
89 .d_flags = D_NEEDGIANT,
| |
90 .d_open = mixer_open, 91 .d_close = mixer_close, 92 .d_ioctl = mixer_ioctl, 93 .d_name = "mixer", 94}; 95 96/** 97 * Keeps a count of mixer devices; used only by OSSv4 SNDCTL_SYSINFO ioctl. 98 */ 99int mixer_count = 0; 100 101#ifdef USING_DEVFS 102static eventhandler_tag mixer_ehtag = NULL; 103#endif 104 105static struct cdev * 106mixer_get_devt(device_t dev) 107{ 108 struct snddev_info *snddev; 109 110 snddev = device_get_softc(dev); 111 112 return snddev->mixer_dev; 113} 114 115#ifdef SND_DYNSYSCTL 116static int 117mixer_lookup(char *devname) 118{ 119 int i; 120 121 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) 122 if (strncmp(devname, snd_mixernames[i], 123 strlen(snd_mixernames[i])) == 0) 124 return i; 125 return -1; 126} 127#endif 128
| 90 .d_open = mixer_open, 91 .d_close = mixer_close, 92 .d_ioctl = mixer_ioctl, 93 .d_name = "mixer", 94}; 95 96/** 97 * Keeps a count of mixer devices; used only by OSSv4 SNDCTL_SYSINFO ioctl. 98 */ 99int mixer_count = 0; 100 101#ifdef USING_DEVFS 102static eventhandler_tag mixer_ehtag = NULL; 103#endif 104 105static struct cdev * 106mixer_get_devt(device_t dev) 107{ 108 struct snddev_info *snddev; 109 110 snddev = device_get_softc(dev); 111 112 return snddev->mixer_dev; 113} 114 115#ifdef SND_DYNSYSCTL 116static int 117mixer_lookup(char *devname) 118{ 119 int i; 120 121 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) 122 if (strncmp(devname, snd_mixernames[i], 123 strlen(snd_mixernames[i])) == 0) 124 return i; 125 return -1; 126} 127#endif 128
|
| 129#define MIXER_SET_UNLOCK(x, y) do { \ 130 if ((y) != 0) \ 131 snd_mtxunlock((x)->lock); \ 132} while(0) 133 134#define MIXER_SET_LOCK(x, y) do { \ 135 if ((y) != 0) \ 136 snd_mtxlock((x)->lock); \ 137} while(0) 138
|
129static int
| 139static int
|
130mixer_set_softpcmvol(struct snd_mixer *mixer, struct snddev_info *d, 131 unsigned left, unsigned right)
| 140mixer_set_softpcmvol(struct snd_mixer *m, struct snddev_info *d, 141 unsigned left, unsigned right)
|
132{ 133 struct pcm_channel *c;
| 142{ 143 struct pcm_channel *c;
|
134 int locked;
| 144 int dropmtx, acquiremtx;
|
135
| 145
|
136 locked = (mixer->lock != NULL && 137 mtx_owned((struct mtx *)(mixer->lock))) ? 1 : 0; 138 if (locked) 139 snd_mtxunlock(mixer->lock);
| 146 if (!PCM_REGISTERED(d)) 147 return (EINVAL);
|
140
| 148
|
| 149 if (mtx_owned(m->lock)) 150 dropmtx = 1; 151 else 152 dropmtx = 0; 153 154 if (!(d->flags & SD_F_MPSAFE) || mtx_owned(d->lock) != 0) 155 acquiremtx = 0; 156 else 157 acquiremtx = 1; 158 159 /* 160 * Be careful here. If we're coming from cdev ioctl, it is OK to 161 * not doing locking AT ALL (except on individual channel) since 162 * we've been heavily guarded by pcm cv, or if we're still 163 * under Giant influence. Since we also have mix_* calls, we cannot 164 * assume such protection and just do the lock as usuall. 165 */ 166 MIXER_SET_UNLOCK(m, dropmtx); 167 MIXER_SET_LOCK(d, acquiremtx); 168
|
141 if (CHN_EMPTY(d, channels.pcm.busy)) { 142 CHN_FOREACH(c, d, channels.pcm) { 143 CHN_LOCK(c); 144 if (c->direction == PCMDIR_PLAY && 145 (c->feederflags & (1 << FEEDER_VOLUME))) 146 chn_setvolume(c, left, right); 147 CHN_UNLOCK(c); 148 } 149 } else { 150 CHN_FOREACH(c, d, channels.pcm.busy) { 151 CHN_LOCK(c); 152 if (c->direction == PCMDIR_PLAY && 153 (c->feederflags & (1 << FEEDER_VOLUME))) 154 chn_setvolume(c, left, right); 155 CHN_UNLOCK(c); 156 } 157 } 158
| 169 if (CHN_EMPTY(d, channels.pcm.busy)) { 170 CHN_FOREACH(c, d, channels.pcm) { 171 CHN_LOCK(c); 172 if (c->direction == PCMDIR_PLAY && 173 (c->feederflags & (1 << FEEDER_VOLUME))) 174 chn_setvolume(c, left, right); 175 CHN_UNLOCK(c); 176 } 177 } else { 178 CHN_FOREACH(c, d, channels.pcm.busy) { 179 CHN_LOCK(c); 180 if (c->direction == PCMDIR_PLAY && 181 (c->feederflags & (1 << FEEDER_VOLUME))) 182 chn_setvolume(c, left, right); 183 CHN_UNLOCK(c); 184 } 185 } 186
|
159 if (locked) 160 snd_mtxlock(mixer->lock);
| 187 MIXER_SET_UNLOCK(d, acquiremtx); 188 MIXER_SET_LOCK(m, dropmtx);
|
161
| 189
|
162 return 0;
| 190 return (0);
|
163} 164 165static int 166mixer_set(struct snd_mixer *m, unsigned dev, unsigned lev) 167{ 168 struct snddev_info *d; 169 unsigned l, r, tl, tr; 170 u_int32_t parent = SOUND_MIXER_NONE, child = 0; 171 u_int32_t realdev;
| 191} 192 193static int 194mixer_set(struct snd_mixer *m, unsigned dev, unsigned lev) 195{ 196 struct snddev_info *d; 197 unsigned l, r, tl, tr; 198 u_int32_t parent = SOUND_MIXER_NONE, child = 0; 199 u_int32_t realdev;
|
172 int i;
| 200 int i, dropmtx;
|
173 174 if (m == NULL || dev >= SOUND_MIXER_NRDEVICES || 175 (0 == (m->devs & (1 << dev)))) 176 return -1; 177 178 l = min((lev & 0x00ff), 100); 179 r = min(((lev & 0xff00) >> 8), 100); 180 realdev = m->realdev[dev]; 181 182 d = device_get_softc(m->dev); 183 if (d == NULL) 184 return -1; 185
| 201 202 if (m == NULL || dev >= SOUND_MIXER_NRDEVICES || 203 (0 == (m->devs & (1 << dev)))) 204 return -1; 205 206 l = min((lev & 0x00ff), 100); 207 r = min(((lev & 0xff00) >> 8), 100); 208 realdev = m->realdev[dev]; 209 210 d = device_get_softc(m->dev); 211 if (d == NULL) 212 return -1; 213
|
| 214 /* It is safe to drop this mutex due to Giant. */ 215 if (!(d->flags & SD_F_MPSAFE) && mtx_owned(m->lock) != 0) 216 dropmtx = 1; 217 else 218 dropmtx = 0; 219 220 MIXER_SET_UNLOCK(m, dropmtx); 221
|
186 /* TODO: recursive handling */ 187 parent = m->parent[dev]; 188 if (parent >= SOUND_MIXER_NRDEVICES) 189 parent = SOUND_MIXER_NONE; 190 if (parent == SOUND_MIXER_NONE) 191 child = m->child[dev]; 192 193 if (parent != SOUND_MIXER_NONE) { 194 tl = (l * (m->level[parent] & 0x00ff)) / 100; 195 tr = (r * ((m->level[parent] & 0xff00) >> 8)) / 100; 196 if (dev == SOUND_MIXER_PCM && (d->flags & SD_F_SOFTPCMVOL))
| 222 /* TODO: recursive handling */ 223 parent = m->parent[dev]; 224 if (parent >= SOUND_MIXER_NRDEVICES) 225 parent = SOUND_MIXER_NONE; 226 if (parent == SOUND_MIXER_NONE) 227 child = m->child[dev]; 228 229 if (parent != SOUND_MIXER_NONE) { 230 tl = (l * (m->level[parent] & 0x00ff)) / 100; 231 tr = (r * ((m->level[parent] & 0xff00) >> 8)) / 100; 232 if (dev == SOUND_MIXER_PCM && (d->flags & SD_F_SOFTPCMVOL))
|
197 mixer_set_softpcmvol(m, d, tl, tr);
| 233 (void)mixer_set_softpcmvol(m, d, tl, tr);
|
198 else if (realdev != SOUND_MIXER_NONE &&
| 234 else if (realdev != SOUND_MIXER_NONE &&
|
199 MIXER_SET(m, realdev, tl, tr) < 0)
| 235 MIXER_SET(m, realdev, tl, tr) < 0) { 236 MIXER_SET_LOCK(m, dropmtx);
|
200 return -1;
| 237 return -1;
|
| 238 }
|
201 } else if (child != 0) { 202 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 203 if (!(child & (1 << i)) || m->parent[i] != dev) 204 continue; 205 realdev = m->realdev[i]; 206 tl = (l * (m->level[i] & 0x00ff)) / 100; 207 tr = (r * ((m->level[i] & 0xff00) >> 8)) / 100; 208 if (i == SOUND_MIXER_PCM && (d->flags & SD_F_SOFTPCMVOL))
| 239 } else if (child != 0) { 240 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 241 if (!(child & (1 << i)) || m->parent[i] != dev) 242 continue; 243 realdev = m->realdev[i]; 244 tl = (l * (m->level[i] & 0x00ff)) / 100; 245 tr = (r * ((m->level[i] & 0xff00) >> 8)) / 100; 246 if (i == SOUND_MIXER_PCM && (d->flags & SD_F_SOFTPCMVOL))
|
209 mixer_set_softpcmvol(m, d, tl, tr);
| 247 (void)mixer_set_softpcmvol(m, d, tl, tr);
|
210 else if (realdev != SOUND_MIXER_NONE) 211 MIXER_SET(m, realdev, tl, tr); 212 } 213 realdev = m->realdev[dev]; 214 if (realdev != SOUND_MIXER_NONE &&
| 248 else if (realdev != SOUND_MIXER_NONE) 249 MIXER_SET(m, realdev, tl, tr); 250 } 251 realdev = m->realdev[dev]; 252 if (realdev != SOUND_MIXER_NONE &&
|
215 MIXER_SET(m, realdev, l, r) < 0)
| 253 MIXER_SET(m, realdev, l, r) < 0) { 254 MIXER_SET_LOCK(m, dropmtx);
|
216 return -1;
| 255 return -1;
|
| 256 }
|
217 } else { 218 if (dev == SOUND_MIXER_PCM && (d->flags & SD_F_SOFTPCMVOL))
| 257 } else { 258 if (dev == SOUND_MIXER_PCM && (d->flags & SD_F_SOFTPCMVOL))
|
219 mixer_set_softpcmvol(m, d, l, r);
| 259 (void)mixer_set_softpcmvol(m, d, l, r);
|
220 else if (realdev != SOUND_MIXER_NONE &&
| 260 else if (realdev != SOUND_MIXER_NONE &&
|
221 MIXER_SET(m, realdev, l, r) < 0)
| 261 MIXER_SET(m, realdev, l, r) < 0) { 262 MIXER_SET_LOCK(m, dropmtx);
|
222 return -1;
| 263 return -1;
|
| 264 }
|
223 } 224 225 m->level[dev] = l | (r << 8); 226
| 265 } 266 267 m->level[dev] = l | (r << 8); 268
|
| 269 MIXER_SET_LOCK(m, dropmtx); 270
|
227 return 0; 228} 229 230static int 231mixer_get(struct snd_mixer *mixer, int dev) 232{ 233 if ((dev < SOUND_MIXER_NRDEVICES) && (mixer->devs & (1 << dev))) 234 return mixer->level[dev];
| 271 return 0; 272} 273 274static int 275mixer_get(struct snd_mixer *mixer, int dev) 276{ 277 if ((dev < SOUND_MIXER_NRDEVICES) && (mixer->devs & (1 << dev))) 278 return mixer->level[dev];
|
235 else return -1;
| 279 else 280 return -1;
|
236} 237 238static int 239mixer_setrecsrc(struct snd_mixer *mixer, u_int32_t src) 240{
| 281} 282 283static int 284mixer_setrecsrc(struct snd_mixer *mixer, u_int32_t src) 285{
|
| 286 struct snddev_info *d; 287 int dropmtx; 288 289 d = device_get_softc(mixer->dev); 290 if (d == NULL) 291 return -1; 292 if (!(d->flags & SD_F_MPSAFE) && mtx_owned(mixer->lock) != 0) 293 dropmtx = 1; 294 else 295 dropmtx = 0;
|
241 src &= mixer->recdevs; 242 if (src == 0) 243 src = SOUND_MASK_MIC;
| 296 src &= mixer->recdevs; 297 if (src == 0) 298 src = SOUND_MASK_MIC;
|
| 299 /* It is safe to drop this mutex due to Giant. */ 300 MIXER_SET_UNLOCK(mixer, dropmtx);
|
244 mixer->recsrc = MIXER_SETRECSRC(mixer, src);
| 301 mixer->recsrc = MIXER_SETRECSRC(mixer, src);
|
| 302 MIXER_SET_LOCK(mixer, dropmtx);
|
245 return 0; 246} 247 248static int 249mixer_getrecsrc(struct snd_mixer *mixer) 250{ 251 return mixer->recsrc; 252} 253 254/** 255 * @brief Retrieve the route number of the current recording device 256 * 257 * OSSv4 assigns routing numbers to recording devices, unlike the previous 258 * API which relied on a fixed table of device numbers and names. This 259 * function returns the routing number of the device currently selected 260 * for recording. 261 * 262 * For now, this function is kind of a goofy compatibility stub atop the 263 * existing sound system. (For example, in theory, the old sound system 264 * allows multiple recording devices to be specified via a bitmask.) 265 * 266 * @param m mixer context container thing 267 * 268 * @retval 0 success 269 * @retval EIDRM no recording device found (generally not possible) 270 * @todo Ask about error code 271 */ 272static int 273mixer_get_recroute(struct snd_mixer *m, int *route) 274{ 275 int i, cnt; 276 277 cnt = 0; 278 279 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 280 /** @todo can user set a multi-device mask? (== or &?) */ 281 if ((1 << i) == m->recsrc) 282 break; 283 if ((1 << i) & m->recdevs) 284 ++cnt; 285 } 286 287 if (i == SOUND_MIXER_NRDEVICES) 288 return EIDRM; 289 290 *route = cnt; 291 return 0; 292} 293 294/** 295 * @brief Select a device for recording 296 * 297 * This function sets a recording source based on a recording device's 298 * routing number. Said number is translated to an old school recdev 299 * mask and passed over mixer_setrecsrc. 300 * 301 * @param m mixer context container thing 302 * 303 * @retval 0 success(?) 304 * @retval EINVAL User specified an invalid device number 305 * @retval otherwise error from mixer_setrecsrc 306 */ 307static int 308mixer_set_recroute(struct snd_mixer *m, int route) 309{ 310 int i, cnt, ret; 311 312 ret = 0; 313 cnt = 0; 314 315 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 316 if ((1 << i) & m->recdevs) { 317 if (route == cnt) 318 break; 319 ++cnt; 320 } 321 } 322 323 if (i == SOUND_MIXER_NRDEVICES) 324 ret = EINVAL; 325 else 326 ret = mixer_setrecsrc(m, (1 << i)); 327 328 return ret; 329} 330 331void 332mix_setdevs(struct snd_mixer *m, u_int32_t v) 333{ 334 struct snddev_info *d; 335 int i; 336 337 if (m == NULL) 338 return; 339 340 d = device_get_softc(m->dev); 341 if (d != NULL && (d->flags & SD_F_SOFTPCMVOL)) 342 v |= SOUND_MASK_PCM; 343 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 344 if (m->parent[i] < SOUND_MIXER_NRDEVICES) 345 v |= 1 << m->parent[i]; 346 v |= m->child[i]; 347 } 348 m->devs = v; 349} 350 351/** 352 * @brief Record mask of available recording devices 353 * 354 * Calling functions are responsible for defining the mask of available 355 * recording devices. This function records that value in a structure 356 * used by the rest of the mixer code. 357 * 358 * This function also populates a structure used by the SNDCTL_DSP_*RECSRC* 359 * family of ioctls that are part of OSSV4. All recording device labels 360 * are concatenated in ascending order corresponding to their routing 361 * numbers. (Ex: a system might have 0 => 'vol', 1 => 'cd', 2 => 'line', 362 * etc.) For now, these labels are just the standard recording device 363 * names (cd, line1, etc.), but will eventually be fully dynamic and user 364 * controlled. 365 * 366 * @param m mixer device context container thing 367 * @param v mask of recording devices 368 */ 369void 370mix_setrecdevs(struct snd_mixer *m, u_int32_t v) 371{ 372 oss_mixer_enuminfo *ei; 373 char *loc; 374 int i, nvalues, nwrote, nleft, ncopied; 375 376 ei = &m->enuminfo; 377 378 nvalues = 0; 379 nwrote = 0; 380 nleft = sizeof(ei->strings); 381 loc = ei->strings; 382 383 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 384 if ((1 << i) & v) { 385 ei->strindex[nvalues] = nwrote; 386 ncopied = strlcpy(loc, snd_mixernames[i], nleft) + 1; 387 /* strlcpy retval doesn't include terminator */ 388 389 nwrote += ncopied; 390 nleft -= ncopied; 391 nvalues++; 392 393 /* 394 * XXX I don't think this should ever be possible. 395 * Even with a move to dynamic device/channel names, 396 * each label is limited to ~16 characters, so that'd 397 * take a LOT to fill this buffer. 398 */ 399 if ((nleft <= 0) || (nvalues >= OSS_ENUM_MAXVALUE)) { 400 device_printf(m->dev, 401 "mix_setrecdevs: Not enough room to store device names--please file a bug report.\n"); 402 device_printf(m->dev, 403 "mix_setrecdevs: Please include details about your sound hardware, OS version, etc.\n"); 404 break; 405 } 406 407 loc = &ei->strings[nwrote]; 408 } 409 } 410 411 /* 412 * NB: The SNDCTL_DSP_GET_RECSRC_NAMES ioctl ignores the dev 413 * and ctrl fields. 414 */ 415 ei->nvalues = nvalues; 416 m->recdevs = v; 417} 418 419void 420mix_setparentchild(struct snd_mixer *m, u_int32_t parent, u_int32_t childs) 421{ 422 u_int32_t mask = 0; 423 int i; 424 425 if (m == NULL || parent >= SOUND_MIXER_NRDEVICES) 426 return; 427 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 428 if (i == parent) 429 continue; 430 if (childs & (1 << i)) { 431 mask |= 1 << i; 432 if (m->parent[i] < SOUND_MIXER_NRDEVICES) 433 m->child[m->parent[i]] &= ~(1 << i); 434 m->parent[i] = parent; 435 m->child[i] = 0; 436 } 437 } 438 mask &= ~(1 << parent); 439 m->child[parent] = mask; 440} 441 442void 443mix_setrealdev(struct snd_mixer *m, u_int32_t dev, u_int32_t realdev) 444{ 445 if (m == NULL || dev >= SOUND_MIXER_NRDEVICES || 446 !(realdev == SOUND_MIXER_NONE || realdev < SOUND_MIXER_NRDEVICES)) 447 return; 448 m->realdev[dev] = realdev; 449} 450 451u_int32_t 452mix_getparent(struct snd_mixer *m, u_int32_t dev) 453{ 454 if (m == NULL || dev >= SOUND_MIXER_NRDEVICES) 455 return SOUND_MIXER_NONE; 456 return m->parent[dev]; 457} 458 459u_int32_t 460mix_getchild(struct snd_mixer *m, u_int32_t dev) 461{ 462 if (m == NULL || dev >= SOUND_MIXER_NRDEVICES) 463 return 0; 464 return m->child[dev]; 465} 466 467u_int32_t 468mix_getdevs(struct snd_mixer *m) 469{ 470 return m->devs; 471} 472 473u_int32_t 474mix_getrecdevs(struct snd_mixer *m) 475{ 476 return m->recdevs; 477} 478 479void * 480mix_getdevinfo(struct snd_mixer *m) 481{ 482 return m->devinfo; 483} 484
| 303 return 0; 304} 305 306static int 307mixer_getrecsrc(struct snd_mixer *mixer) 308{ 309 return mixer->recsrc; 310} 311 312/** 313 * @brief Retrieve the route number of the current recording device 314 * 315 * OSSv4 assigns routing numbers to recording devices, unlike the previous 316 * API which relied on a fixed table of device numbers and names. This 317 * function returns the routing number of the device currently selected 318 * for recording. 319 * 320 * For now, this function is kind of a goofy compatibility stub atop the 321 * existing sound system. (For example, in theory, the old sound system 322 * allows multiple recording devices to be specified via a bitmask.) 323 * 324 * @param m mixer context container thing 325 * 326 * @retval 0 success 327 * @retval EIDRM no recording device found (generally not possible) 328 * @todo Ask about error code 329 */ 330static int 331mixer_get_recroute(struct snd_mixer *m, int *route) 332{ 333 int i, cnt; 334 335 cnt = 0; 336 337 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 338 /** @todo can user set a multi-device mask? (== or &?) */ 339 if ((1 << i) == m->recsrc) 340 break; 341 if ((1 << i) & m->recdevs) 342 ++cnt; 343 } 344 345 if (i == SOUND_MIXER_NRDEVICES) 346 return EIDRM; 347 348 *route = cnt; 349 return 0; 350} 351 352/** 353 * @brief Select a device for recording 354 * 355 * This function sets a recording source based on a recording device's 356 * routing number. Said number is translated to an old school recdev 357 * mask and passed over mixer_setrecsrc. 358 * 359 * @param m mixer context container thing 360 * 361 * @retval 0 success(?) 362 * @retval EINVAL User specified an invalid device number 363 * @retval otherwise error from mixer_setrecsrc 364 */ 365static int 366mixer_set_recroute(struct snd_mixer *m, int route) 367{ 368 int i, cnt, ret; 369 370 ret = 0; 371 cnt = 0; 372 373 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 374 if ((1 << i) & m->recdevs) { 375 if (route == cnt) 376 break; 377 ++cnt; 378 } 379 } 380 381 if (i == SOUND_MIXER_NRDEVICES) 382 ret = EINVAL; 383 else 384 ret = mixer_setrecsrc(m, (1 << i)); 385 386 return ret; 387} 388 389void 390mix_setdevs(struct snd_mixer *m, u_int32_t v) 391{ 392 struct snddev_info *d; 393 int i; 394 395 if (m == NULL) 396 return; 397 398 d = device_get_softc(m->dev); 399 if (d != NULL && (d->flags & SD_F_SOFTPCMVOL)) 400 v |= SOUND_MASK_PCM; 401 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 402 if (m->parent[i] < SOUND_MIXER_NRDEVICES) 403 v |= 1 << m->parent[i]; 404 v |= m->child[i]; 405 } 406 m->devs = v; 407} 408 409/** 410 * @brief Record mask of available recording devices 411 * 412 * Calling functions are responsible for defining the mask of available 413 * recording devices. This function records that value in a structure 414 * used by the rest of the mixer code. 415 * 416 * This function also populates a structure used by the SNDCTL_DSP_*RECSRC* 417 * family of ioctls that are part of OSSV4. All recording device labels 418 * are concatenated in ascending order corresponding to their routing 419 * numbers. (Ex: a system might have 0 => 'vol', 1 => 'cd', 2 => 'line', 420 * etc.) For now, these labels are just the standard recording device 421 * names (cd, line1, etc.), but will eventually be fully dynamic and user 422 * controlled. 423 * 424 * @param m mixer device context container thing 425 * @param v mask of recording devices 426 */ 427void 428mix_setrecdevs(struct snd_mixer *m, u_int32_t v) 429{ 430 oss_mixer_enuminfo *ei; 431 char *loc; 432 int i, nvalues, nwrote, nleft, ncopied; 433 434 ei = &m->enuminfo; 435 436 nvalues = 0; 437 nwrote = 0; 438 nleft = sizeof(ei->strings); 439 loc = ei->strings; 440 441 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 442 if ((1 << i) & v) { 443 ei->strindex[nvalues] = nwrote; 444 ncopied = strlcpy(loc, snd_mixernames[i], nleft) + 1; 445 /* strlcpy retval doesn't include terminator */ 446 447 nwrote += ncopied; 448 nleft -= ncopied; 449 nvalues++; 450 451 /* 452 * XXX I don't think this should ever be possible. 453 * Even with a move to dynamic device/channel names, 454 * each label is limited to ~16 characters, so that'd 455 * take a LOT to fill this buffer. 456 */ 457 if ((nleft <= 0) || (nvalues >= OSS_ENUM_MAXVALUE)) { 458 device_printf(m->dev, 459 "mix_setrecdevs: Not enough room to store device names--please file a bug report.\n"); 460 device_printf(m->dev, 461 "mix_setrecdevs: Please include details about your sound hardware, OS version, etc.\n"); 462 break; 463 } 464 465 loc = &ei->strings[nwrote]; 466 } 467 } 468 469 /* 470 * NB: The SNDCTL_DSP_GET_RECSRC_NAMES ioctl ignores the dev 471 * and ctrl fields. 472 */ 473 ei->nvalues = nvalues; 474 m->recdevs = v; 475} 476 477void 478mix_setparentchild(struct snd_mixer *m, u_int32_t parent, u_int32_t childs) 479{ 480 u_int32_t mask = 0; 481 int i; 482 483 if (m == NULL || parent >= SOUND_MIXER_NRDEVICES) 484 return; 485 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 486 if (i == parent) 487 continue; 488 if (childs & (1 << i)) { 489 mask |= 1 << i; 490 if (m->parent[i] < SOUND_MIXER_NRDEVICES) 491 m->child[m->parent[i]] &= ~(1 << i); 492 m->parent[i] = parent; 493 m->child[i] = 0; 494 } 495 } 496 mask &= ~(1 << parent); 497 m->child[parent] = mask; 498} 499 500void 501mix_setrealdev(struct snd_mixer *m, u_int32_t dev, u_int32_t realdev) 502{ 503 if (m == NULL || dev >= SOUND_MIXER_NRDEVICES || 504 !(realdev == SOUND_MIXER_NONE || realdev < SOUND_MIXER_NRDEVICES)) 505 return; 506 m->realdev[dev] = realdev; 507} 508 509u_int32_t 510mix_getparent(struct snd_mixer *m, u_int32_t dev) 511{ 512 if (m == NULL || dev >= SOUND_MIXER_NRDEVICES) 513 return SOUND_MIXER_NONE; 514 return m->parent[dev]; 515} 516 517u_int32_t 518mix_getchild(struct snd_mixer *m, u_int32_t dev) 519{ 520 if (m == NULL || dev >= SOUND_MIXER_NRDEVICES) 521 return 0; 522 return m->child[dev]; 523} 524 525u_int32_t 526mix_getdevs(struct snd_mixer *m) 527{ 528 return m->devs; 529} 530 531u_int32_t 532mix_getrecdevs(struct snd_mixer *m) 533{ 534 return m->recdevs; 535} 536 537void * 538mix_getdevinfo(struct snd_mixer *m) 539{ 540 return m->devinfo; 541} 542
|
485int 486mixer_init(device_t dev, kobj_class_t cls, void *devinfo)
| 543static struct snd_mixer * 544mixer_obj_create(device_t dev, kobj_class_t cls, void *devinfo, 545 int type, const char *desc)
|
487{
| 546{
|
488 struct snddev_info *snddev;
| |
489 struct snd_mixer *m;
| 547 struct snd_mixer *m;
|
490 u_int16_t v; 491 struct cdev *pdev; 492 int i, unit, devunit, val;
| 548 int i;
|
493
| 549
|
| 550 KASSERT(dev != NULL && cls != NULL && devinfo != NULL, 551 ("%s(): NULL data dev=%p cls=%p devinfo=%p", 552 __func__, dev, cls, devinfo)); 553 KASSERT(type == MIXER_TYPE_PRIMARY || type == MIXER_TYPE_SECONDARY, 554 ("invalid mixer type=%d", type)); 555
|
494 m = (struct snd_mixer *)kobj_create(cls, M_MIXER, M_WAITOK | M_ZERO);
| 556 m = (struct snd_mixer *)kobj_create(cls, M_MIXER, M_WAITOK | M_ZERO);
|
495 snprintf(m->name, MIXER_NAMELEN, "%s:mixer", device_get_nameunit(dev)); 496 m->lock = snd_mtxcreate(m->name, "pcm mixer"); 497 m->type = cls->name;
| 557 snprintf(m->name, sizeof(m->name), "%s:mixer", 558 device_get_nameunit(dev)); 559 if (desc != NULL) { 560 strlcat(m->name, ":", sizeof(m->name)); 561 strlcat(m->name, desc, sizeof(m->name)); 562 } 563 m->lock = snd_mtxcreate(m->name, (type == MIXER_TYPE_PRIMARY) ? 564 "primary pcm mixer" : "secondary pcm mixer"); 565 m->type = type;
|
498 m->devinfo = devinfo; 499 m->busy = 0; 500 m->dev = dev;
| 566 m->devinfo = devinfo; 567 m->busy = 0; 568 m->dev = dev;
|
501 for (i = 0; i < 32; i++) {
| 569 for (i = 0; i < (sizeof(m->parent) / sizeof(m->parent[0])); i++) {
|
502 m->parent[i] = SOUND_MIXER_NONE; 503 m->child[i] = 0; 504 m->realdev[i] = i; 505 } 506
| 570 m->parent[i] = SOUND_MIXER_NONE; 571 m->child[i] = 0; 572 m->realdev[i] = i; 573 } 574
|
507 if (MIXER_INIT(m)) 508 goto bad;
| 575 if (MIXER_INIT(m)) { 576 snd_mtxlock(m->lock); 577 snd_mtxfree(m->lock); 578 kobj_delete((kobj_t)m, M_MIXER); 579 return (NULL); 580 }
|
509
| 581
|
| 582 return (m); 583} 584 585int 586mixer_delete(struct snd_mixer *m) 587{ 588 KASSERT(m != NULL, ("NULL snd_mixer")); 589 KASSERT(m->type == MIXER_TYPE_SECONDARY, 590 ("%s(): illegal mixer type=%d", __func__, m->type)); 591 592 snd_mtxlock(m->lock); 593 594 MIXER_UNINIT(m); 595 596 snd_mtxfree(m->lock); 597 kobj_delete((kobj_t)m, M_MIXER); 598 599 --mixer_count; 600 601 return (0); 602} 603 604struct snd_mixer * 605mixer_create(device_t dev, kobj_class_t cls, void *devinfo, const char *desc) 606{ 607 struct snd_mixer *m; 608 609 m = mixer_obj_create(dev, cls, devinfo, MIXER_TYPE_SECONDARY, desc); 610 611 if (m != NULL) 612 ++mixer_count; 613 614 return (m); 615} 616 617int 618mixer_init(device_t dev, kobj_class_t cls, void *devinfo) 619{ 620 struct snddev_info *snddev; 621 struct snd_mixer *m; 622 u_int16_t v; 623 struct cdev *pdev; 624 int i, unit, devunit, val; 625 626 m = mixer_obj_create(dev, cls, devinfo, MIXER_TYPE_PRIMARY, NULL); 627 if (m == NULL) 628 return (-1); 629
|
510 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 511 v = snd_mixerdefaults[i]; 512 513 if (resource_int_value(device_get_name(dev), 514 device_get_unit(dev), snd_mixernames[i], &val) == 0) { 515 if (val >= 0 && val <= 100) { 516 v = (u_int16_t) val; 517 } 518 } 519 520 mixer_set(m, i, v | (v << 8)); 521 } 522 523 mixer_setrecsrc(m, SOUND_MASK_MIC); 524 525 unit = device_get_unit(dev); 526 devunit = snd_mkunit(unit, SND_DEV_CTL, 0); 527 pdev = make_dev(&mixer_cdevsw, unit2minor(devunit), 528 UID_ROOT, GID_WHEEL, 0666, "mixer%d", unit); 529 pdev->si_drv1 = m; 530 snddev = device_get_softc(dev); 531 snddev->mixer_dev = pdev; 532 533 ++mixer_count; 534 535 if (bootverbose) { 536 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 537 if (!(m->devs & (1 << i))) 538 continue; 539 if (m->realdev[i] != i) { 540 device_printf(dev, "Mixer \"%s\" -> \"%s\":", 541 snd_mixernames[i], 542 (m->realdev[i] < SOUND_MIXER_NRDEVICES) ? 543 snd_mixernames[m->realdev[i]] : "none"); 544 } else { 545 device_printf(dev, "Mixer \"%s\":", 546 snd_mixernames[i]); 547 } 548 if (m->parent[i] < SOUND_MIXER_NRDEVICES) 549 printf(" parent=\"%s\"", 550 snd_mixernames[m->parent[i]]); 551 if (m->child[i] != 0) 552 printf(" child=0x%08x", m->child[i]); 553 printf("\n"); 554 } 555 if (snddev->flags & SD_F_SOFTPCMVOL) 556 device_printf(dev, "Soft PCM mixer ENABLED\n"); 557 } 558
| 630 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 631 v = snd_mixerdefaults[i]; 632 633 if (resource_int_value(device_get_name(dev), 634 device_get_unit(dev), snd_mixernames[i], &val) == 0) { 635 if (val >= 0 && val <= 100) { 636 v = (u_int16_t) val; 637 } 638 } 639 640 mixer_set(m, i, v | (v << 8)); 641 } 642 643 mixer_setrecsrc(m, SOUND_MASK_MIC); 644 645 unit = device_get_unit(dev); 646 devunit = snd_mkunit(unit, SND_DEV_CTL, 0); 647 pdev = make_dev(&mixer_cdevsw, unit2minor(devunit), 648 UID_ROOT, GID_WHEEL, 0666, "mixer%d", unit); 649 pdev->si_drv1 = m; 650 snddev = device_get_softc(dev); 651 snddev->mixer_dev = pdev; 652 653 ++mixer_count; 654 655 if (bootverbose) { 656 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) { 657 if (!(m->devs & (1 << i))) 658 continue; 659 if (m->realdev[i] != i) { 660 device_printf(dev, "Mixer \"%s\" -> \"%s\":", 661 snd_mixernames[i], 662 (m->realdev[i] < SOUND_MIXER_NRDEVICES) ? 663 snd_mixernames[m->realdev[i]] : "none"); 664 } else { 665 device_printf(dev, "Mixer \"%s\":", 666 snd_mixernames[i]); 667 } 668 if (m->parent[i] < SOUND_MIXER_NRDEVICES) 669 printf(" parent=\"%s\"", 670 snd_mixernames[m->parent[i]]); 671 if (m->child[i] != 0) 672 printf(" child=0x%08x", m->child[i]); 673 printf("\n"); 674 } 675 if (snddev->flags & SD_F_SOFTPCMVOL) 676 device_printf(dev, "Soft PCM mixer ENABLED\n"); 677 } 678
|
559 return 0; 560 561bad: 562 snd_mtxlock(m->lock); 563 snd_mtxfree(m->lock); 564 kobj_delete((kobj_t)m, M_MIXER); 565 return -1;
| 679 return (0);
|
566} 567 568int 569mixer_uninit(device_t dev) 570{ 571 int i; 572 struct snddev_info *d; 573 struct snd_mixer *m; 574 struct cdev *pdev; 575 576 d = device_get_softc(dev); 577 pdev = mixer_get_devt(dev); 578 if (d == NULL || pdev == NULL || pdev->si_drv1 == NULL) 579 return EBADF;
| 680} 681 682int 683mixer_uninit(device_t dev) 684{ 685 int i; 686 struct snddev_info *d; 687 struct snd_mixer *m; 688 struct cdev *pdev; 689 690 d = device_get_softc(dev); 691 pdev = mixer_get_devt(dev); 692 if (d == NULL || pdev == NULL || pdev->si_drv1 == NULL) 693 return EBADF;
|
| 694
|
580 m = pdev->si_drv1;
| 695 m = pdev->si_drv1;
|
| 696 KASSERT(m != NULL, ("NULL snd_mixer")); 697 KASSERT(m->type == MIXER_TYPE_PRIMARY, 698 ("%s(): illegal mixer type=%d", __func__, m->type)); 699
|
581 snd_mtxlock(m->lock); 582 583 if (m->busy) { 584 snd_mtxunlock(m->lock); 585 return EBUSY; 586 } 587 588 pdev->si_drv1 = NULL; 589 destroy_dev(pdev); 590 591 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) 592 mixer_set(m, i, 0); 593 594 mixer_setrecsrc(m, SOUND_MASK_MIC); 595 596 MIXER_UNINIT(m); 597 598 snd_mtxfree(m->lock); 599 kobj_delete((kobj_t)m, M_MIXER); 600 601 d->mixer_dev = NULL; 602 603 --mixer_count; 604 605 return 0; 606} 607 608int 609mixer_reinit(device_t dev) 610{ 611 struct snd_mixer *m; 612 struct cdev *pdev; 613 int i; 614 615 pdev = mixer_get_devt(dev); 616 m = pdev->si_drv1; 617 snd_mtxlock(m->lock); 618 619 i = MIXER_REINIT(m); 620 if (i) { 621 snd_mtxunlock(m->lock); 622 return i; 623 } 624 625 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) 626 mixer_set(m, i, m->level[i]); 627 628 mixer_setrecsrc(m, m->recsrc); 629 snd_mtxunlock(m->lock); 630 631 return 0; 632} 633 634#ifdef SND_DYNSYSCTL 635static int 636sysctl_hw_snd_hwvol_mixer(SYSCTL_HANDLER_ARGS) 637{ 638 char devname[32]; 639 int error, dev; 640 struct snd_mixer *m; 641 642 m = oidp->oid_arg1; 643 snd_mtxlock(m->lock); 644 strlcpy(devname, snd_mixernames[m->hwvol_mixer], sizeof(devname)); 645 snd_mtxunlock(m->lock); 646 error = sysctl_handle_string(oidp, &devname[0], sizeof(devname), req); 647 snd_mtxlock(m->lock); 648 if (error == 0 && req->newptr != NULL) { 649 dev = mixer_lookup(devname); 650 if (dev == -1) { 651 snd_mtxunlock(m->lock); 652 return EINVAL; 653 } 654 else if (dev != m->hwvol_mixer) { 655 m->hwvol_mixer = dev; 656 m->hwvol_muted = 0; 657 } 658 } 659 snd_mtxunlock(m->lock); 660 return error; 661} 662#endif 663 664int 665mixer_hwvol_init(device_t dev) 666{ 667 struct snd_mixer *m; 668 struct cdev *pdev; 669 670 pdev = mixer_get_devt(dev); 671 m = pdev->si_drv1; 672 673 m->hwvol_mixer = SOUND_MIXER_VOLUME; 674 m->hwvol_step = 5; 675#ifdef SND_DYNSYSCTL 676 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), 677 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 678 OID_AUTO, "hwvol_step", CTLFLAG_RW, &m->hwvol_step, 0, ""); 679 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 680 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 681 OID_AUTO, "hwvol_mixer", CTLTYPE_STRING | CTLFLAG_RW, m, 0, 682 sysctl_hw_snd_hwvol_mixer, "A", ""); 683#endif 684 return 0; 685} 686 687void 688mixer_hwvol_mute(device_t dev) 689{ 690 struct snd_mixer *m; 691 struct cdev *pdev; 692 693 pdev = mixer_get_devt(dev); 694 m = pdev->si_drv1; 695 snd_mtxlock(m->lock); 696 if (m->hwvol_muted) { 697 m->hwvol_muted = 0; 698 mixer_set(m, m->hwvol_mixer, m->hwvol_mute_level); 699 } else { 700 m->hwvol_muted++; 701 m->hwvol_mute_level = mixer_get(m, m->hwvol_mixer); 702 mixer_set(m, m->hwvol_mixer, 0); 703 } 704 snd_mtxunlock(m->lock); 705} 706 707void 708mixer_hwvol_step(device_t dev, int left_step, int right_step) 709{ 710 struct snd_mixer *m; 711 int level, left, right; 712 struct cdev *pdev; 713 714 pdev = mixer_get_devt(dev); 715 m = pdev->si_drv1; 716 snd_mtxlock(m->lock); 717 if (m->hwvol_muted) { 718 m->hwvol_muted = 0; 719 level = m->hwvol_mute_level; 720 } else 721 level = mixer_get(m, m->hwvol_mixer); 722 if (level != -1) { 723 left = level & 0xff; 724 right = level >> 8; 725 left += left_step * m->hwvol_step; 726 if (left < 0) 727 left = 0; 728 right += right_step * m->hwvol_step; 729 if (right < 0) 730 right = 0; 731 mixer_set(m, m->hwvol_mixer, left | right << 8); 732 } 733 snd_mtxunlock(m->lock); 734} 735
| 700 snd_mtxlock(m->lock); 701 702 if (m->busy) { 703 snd_mtxunlock(m->lock); 704 return EBUSY; 705 } 706 707 pdev->si_drv1 = NULL; 708 destroy_dev(pdev); 709 710 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) 711 mixer_set(m, i, 0); 712 713 mixer_setrecsrc(m, SOUND_MASK_MIC); 714 715 MIXER_UNINIT(m); 716 717 snd_mtxfree(m->lock); 718 kobj_delete((kobj_t)m, M_MIXER); 719 720 d->mixer_dev = NULL; 721 722 --mixer_count; 723 724 return 0; 725} 726 727int 728mixer_reinit(device_t dev) 729{ 730 struct snd_mixer *m; 731 struct cdev *pdev; 732 int i; 733 734 pdev = mixer_get_devt(dev); 735 m = pdev->si_drv1; 736 snd_mtxlock(m->lock); 737 738 i = MIXER_REINIT(m); 739 if (i) { 740 snd_mtxunlock(m->lock); 741 return i; 742 } 743 744 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) 745 mixer_set(m, i, m->level[i]); 746 747 mixer_setrecsrc(m, m->recsrc); 748 snd_mtxunlock(m->lock); 749 750 return 0; 751} 752 753#ifdef SND_DYNSYSCTL 754static int 755sysctl_hw_snd_hwvol_mixer(SYSCTL_HANDLER_ARGS) 756{ 757 char devname[32]; 758 int error, dev; 759 struct snd_mixer *m; 760 761 m = oidp->oid_arg1; 762 snd_mtxlock(m->lock); 763 strlcpy(devname, snd_mixernames[m->hwvol_mixer], sizeof(devname)); 764 snd_mtxunlock(m->lock); 765 error = sysctl_handle_string(oidp, &devname[0], sizeof(devname), req); 766 snd_mtxlock(m->lock); 767 if (error == 0 && req->newptr != NULL) { 768 dev = mixer_lookup(devname); 769 if (dev == -1) { 770 snd_mtxunlock(m->lock); 771 return EINVAL; 772 } 773 else if (dev != m->hwvol_mixer) { 774 m->hwvol_mixer = dev; 775 m->hwvol_muted = 0; 776 } 777 } 778 snd_mtxunlock(m->lock); 779 return error; 780} 781#endif 782 783int 784mixer_hwvol_init(device_t dev) 785{ 786 struct snd_mixer *m; 787 struct cdev *pdev; 788 789 pdev = mixer_get_devt(dev); 790 m = pdev->si_drv1; 791 792 m->hwvol_mixer = SOUND_MIXER_VOLUME; 793 m->hwvol_step = 5; 794#ifdef SND_DYNSYSCTL 795 SYSCTL_ADD_INT(device_get_sysctl_ctx(dev), 796 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 797 OID_AUTO, "hwvol_step", CTLFLAG_RW, &m->hwvol_step, 0, ""); 798 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 799 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 800 OID_AUTO, "hwvol_mixer", CTLTYPE_STRING | CTLFLAG_RW, m, 0, 801 sysctl_hw_snd_hwvol_mixer, "A", ""); 802#endif 803 return 0; 804} 805 806void 807mixer_hwvol_mute(device_t dev) 808{ 809 struct snd_mixer *m; 810 struct cdev *pdev; 811 812 pdev = mixer_get_devt(dev); 813 m = pdev->si_drv1; 814 snd_mtxlock(m->lock); 815 if (m->hwvol_muted) { 816 m->hwvol_muted = 0; 817 mixer_set(m, m->hwvol_mixer, m->hwvol_mute_level); 818 } else { 819 m->hwvol_muted++; 820 m->hwvol_mute_level = mixer_get(m, m->hwvol_mixer); 821 mixer_set(m, m->hwvol_mixer, 0); 822 } 823 snd_mtxunlock(m->lock); 824} 825 826void 827mixer_hwvol_step(device_t dev, int left_step, int right_step) 828{ 829 struct snd_mixer *m; 830 int level, left, right; 831 struct cdev *pdev; 832 833 pdev = mixer_get_devt(dev); 834 m = pdev->si_drv1; 835 snd_mtxlock(m->lock); 836 if (m->hwvol_muted) { 837 m->hwvol_muted = 0; 838 level = m->hwvol_mute_level; 839 } else 840 level = mixer_get(m, m->hwvol_mixer); 841 if (level != -1) { 842 left = level & 0xff; 843 right = level >> 8; 844 left += left_step * m->hwvol_step; 845 if (left < 0) 846 left = 0; 847 right += right_step * m->hwvol_step; 848 if (right < 0) 849 right = 0; 850 mixer_set(m, m->hwvol_mixer, left | right << 8); 851 } 852 snd_mtxunlock(m->lock); 853} 854
|
| 855int 856mixer_busy(struct snd_mixer *m) 857{ 858 KASSERT(m != NULL, ("NULL snd_mixer")); 859 860 return (m->busy); 861} 862 863int 864mix_set(struct snd_mixer *m, u_int dev, u_int left, u_int right) 865{ 866 int ret; 867 868 KASSERT(m != NULL, ("NULL snd_mixer")); 869 870 snd_mtxlock(m->lock); 871 ret = mixer_set(m, dev, left | (right << 8)); 872 snd_mtxunlock(m->lock); 873 874 return ((ret != 0) ? ENXIO : 0); 875} 876 877int 878mix_get(struct snd_mixer *m, u_int dev) 879{ 880 int ret; 881 882 KASSERT(m != NULL, ("NULL snd_mixer")); 883 884 snd_mtxlock(m->lock); 885 ret = mixer_get(m, dev); 886 snd_mtxunlock(m->lock); 887 888 return (ret); 889} 890 891int 892mix_setrecsrc(struct snd_mixer *m, u_int32_t src) 893{ 894 int ret; 895 896 KASSERT(m != NULL, ("NULL snd_mixer")); 897 898 snd_mtxlock(m->lock); 899 ret = mixer_setrecsrc(m, src); 900 snd_mtxunlock(m->lock); 901 902 return ((ret != 0) ? ENXIO : 0); 903} 904 905u_int32_t 906mix_getrecsrc(struct snd_mixer *m) 907{ 908 u_int32_t ret; 909 910 KASSERT(m != NULL, ("NULL snd_mixer")); 911 912 snd_mtxlock(m->lock); 913 ret = mixer_getrecsrc(m); 914 snd_mtxunlock(m->lock); 915 916 return (ret); 917} 918 919int 920mix_get_type(struct snd_mixer *m) 921{ 922 KASSERT(m != NULL, ("NULL snd_mixer")); 923 924 return (m->type); 925} 926
|
736/* ----------------------------------------------------------------------- */ 737 738static int 739mixer_open(struct cdev *i_dev, int flags, int mode, struct thread *td) 740{
| 927/* ----------------------------------------------------------------------- */ 928 929static int 930mixer_open(struct cdev *i_dev, int flags, int mode, struct thread *td) 931{
|
| 932 struct snddev_info *d;
|
741 struct snd_mixer *m; 742
| 933 struct snd_mixer *m; 934
|
| 935 936 if (i_dev == NULL || i_dev->si_drv1 == NULL) 937 return (EBADF); 938
|
743 m = i_dev->si_drv1;
| 939 m = i_dev->si_drv1;
|
744 snd_mtxlock(m->lock);
| 940 d = device_get_softc(m->dev); 941 if (!PCM_REGISTERED(d)) 942 return (EBADF);
|
745
| 943
|
746 m->busy = 1;
| 944 /* XXX Need Giant magic entry ??? */
|
747
| 945
|
| 946 snd_mtxlock(m->lock); 947 m->busy = 1;
|
748 snd_mtxunlock(m->lock);
| 948 snd_mtxunlock(m->lock);
|
749 return 0;
| 949 950 return (0);
|
750} 751 752static int 753mixer_close(struct cdev *i_dev, int flags, int mode, struct thread *td) 754{
| 951} 952 953static int 954mixer_close(struct cdev *i_dev, int flags, int mode, struct thread *td) 955{
|
| 956 struct snddev_info *d;
|
755 struct snd_mixer *m;
| 957 struct snd_mixer *m;
|
| 958 int ret;
|
756
| 959
|
| 960 if (i_dev == NULL || i_dev->si_drv1 == NULL) 961 return (EBADF); 962
|
757 m = i_dev->si_drv1;
| 963 m = i_dev->si_drv1;
|
758 snd_mtxlock(m->lock);
| 964 d = device_get_softc(m->dev); 965 if (!PCM_REGISTERED(d)) 966 return (EBADF);
|
759
| 967
|
760 if (!m->busy) { 761 snd_mtxunlock(m->lock); 762 return EBADF; 763 } 764 m->busy = 0;
| 968 /* XXX Need Giant magic entry ??? */
|
765
| 969
|
| 970 snd_mtxlock(m->lock); 971 ret = (m->busy == 0) ? EBADF : 0; 972 m->busy = 0;
|
766 snd_mtxunlock(m->lock);
| 973 snd_mtxunlock(m->lock);
|
767 return 0;
| 974 975 return (ret);
|
768} 769
| 976} 977
|
| 978static int 979mixer_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, 980 struct thread *td) 981{ 982 struct snddev_info *d; 983 int ret; 984 985 if (i_dev == NULL || i_dev->si_drv1 == NULL) 986 return (EBADF); 987 988 d = device_get_softc(((struct snd_mixer *)i_dev->si_drv1)->dev); 989 if (!PCM_REGISTERED(d)) 990 return (EBADF); 991 992 PCM_GIANT_ENTER(d); 993 PCM_ACQUIRE_QUICK(d); 994 995 ret = mixer_ioctl_cmd(i_dev, cmd, arg, mode, td, MIXER_CMD_CDEV); 996 997 PCM_RELEASE_QUICK(d); 998 PCM_GIANT_LEAVE(d); 999 1000 return (ret); 1001} 1002 1003/* 1004 * XXX Make sure you can guarantee concurrency safety before calling this 1005 * function, be it through Giant, PCM_CV_*, etc ! 1006 */
|
770int
| 1007int
|
771mixer_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *td)
| 1008mixer_ioctl_cmd(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, 1009 struct thread *td, int from)
|
772{ 773 struct snd_mixer *m; 774 int ret, *arg_i = (int *)arg; 775 int v = -1, j = cmd & 0xff; 776 777 m = i_dev->si_drv1; 778 779 if (m == NULL)
| 1010{ 1011 struct snd_mixer *m; 1012 int ret, *arg_i = (int *)arg; 1013 int v = -1, j = cmd & 0xff; 1014 1015 m = i_dev->si_drv1; 1016 1017 if (m == NULL)
|
780 return EBADF;
| 1018 return (EBADF);
|
781 782 snd_mtxlock(m->lock);
| 1019 1020 snd_mtxlock(m->lock);
|
783 if (mode != -1 && !m->busy) {
| 1021 if (from == MIXER_CMD_CDEV && !m->busy) {
|
784 snd_mtxunlock(m->lock);
| 1022 snd_mtxunlock(m->lock);
|
785 return EBADF;
| 1023 return (EBADF);
|
786 } 787 788 if (cmd == SNDCTL_MIXERINFO) { 789 snd_mtxunlock(m->lock);
| 1024 } 1025 1026 if (cmd == SNDCTL_MIXERINFO) { 1027 snd_mtxunlock(m->lock);
|
790 return mixer_oss_mixerinfo(i_dev, (oss_mixerinfo *)arg);
| 1028 return (mixer_oss_mixerinfo(i_dev, (oss_mixerinfo *)arg));
|
791 } 792 793 if ((cmd & MIXER_WRITE(0)) == MIXER_WRITE(0)) { 794 if (j == SOUND_MIXER_RECSRC) 795 ret = mixer_setrecsrc(m, *arg_i); 796 else 797 ret = mixer_set(m, j, *arg_i); 798 snd_mtxunlock(m->lock);
| 1029 } 1030 1031 if ((cmd & MIXER_WRITE(0)) == MIXER_WRITE(0)) { 1032 if (j == SOUND_MIXER_RECSRC) 1033 ret = mixer_setrecsrc(m, *arg_i); 1034 else 1035 ret = mixer_set(m, j, *arg_i); 1036 snd_mtxunlock(m->lock);
|
799 return (ret == 0)? 0 : ENXIO;
| 1037 return ((ret == 0) ? 0 : ENXIO);
|
800 } 801 802 if ((cmd & MIXER_READ(0)) == MIXER_READ(0)) { 803 switch (j) { 804 case SOUND_MIXER_DEVMASK: 805 case SOUND_MIXER_CAPS: 806 case SOUND_MIXER_STEREODEVS: 807 v = mix_getdevs(m); 808 break; 809 810 case SOUND_MIXER_RECMASK: 811 v = mix_getrecdevs(m); 812 break; 813 814 case SOUND_MIXER_RECSRC: 815 v = mixer_getrecsrc(m); 816 break; 817 818 default: 819 v = mixer_get(m, j); 820 } 821 *arg_i = v; 822 snd_mtxunlock(m->lock);
| 1038 } 1039 1040 if ((cmd & MIXER_READ(0)) == MIXER_READ(0)) { 1041 switch (j) { 1042 case SOUND_MIXER_DEVMASK: 1043 case SOUND_MIXER_CAPS: 1044 case SOUND_MIXER_STEREODEVS: 1045 v = mix_getdevs(m); 1046 break; 1047 1048 case SOUND_MIXER_RECMASK: 1049 v = mix_getrecdevs(m); 1050 break; 1051 1052 case SOUND_MIXER_RECSRC: 1053 v = mixer_getrecsrc(m); 1054 break; 1055 1056 default: 1057 v = mixer_get(m, j); 1058 } 1059 *arg_i = v; 1060 snd_mtxunlock(m->lock);
|
823 return (v != -1)? 0 : ENXIO;
| 1061 return ((v != -1) ? 0 : ENXIO);
|
824 } 825 826 ret = 0; 827 828 switch (cmd) { 829 /** @todo Double check return values, error codes. */ 830 case SNDCTL_SYSINFO:
| 1062 } 1063 1064 ret = 0; 1065 1066 switch (cmd) { 1067 /** @todo Double check return values, error codes. */ 1068 case SNDCTL_SYSINFO:
|
| 1069 snd_mtxunlock(m->lock);
|
831 sound_oss_sysinfo((oss_sysinfo *)arg);
| 1070 sound_oss_sysinfo((oss_sysinfo *)arg);
|
| 1071 return (ret);
|
832 break; 833 case SNDCTL_AUDIOINFO:
| 1072 break; 1073 case SNDCTL_AUDIOINFO:
|
834 ret = dsp_oss_audioinfo(i_dev, (oss_audioinfo *)arg);
| 1074 snd_mtxunlock(m->lock); 1075 return (dsp_oss_audioinfo(i_dev, (oss_audioinfo *)arg));
|
835 break; 836 case SNDCTL_DSP_GET_RECSRC_NAMES: 837 bcopy((void *)&m->enuminfo, arg, sizeof(oss_mixer_enuminfo)); 838 break; 839 case SNDCTL_DSP_GET_RECSRC: 840 ret = mixer_get_recroute(m, arg_i); 841 break; 842 case SNDCTL_DSP_SET_RECSRC: 843 ret = mixer_set_recroute(m, *arg_i); 844 break; 845 case OSS_GETVERSION: 846 *arg_i = SOUND_VERSION; 847 break; 848 default: 849 ret = ENXIO;
| 1076 break; 1077 case SNDCTL_DSP_GET_RECSRC_NAMES: 1078 bcopy((void *)&m->enuminfo, arg, sizeof(oss_mixer_enuminfo)); 1079 break; 1080 case SNDCTL_DSP_GET_RECSRC: 1081 ret = mixer_get_recroute(m, arg_i); 1082 break; 1083 case SNDCTL_DSP_SET_RECSRC: 1084 ret = mixer_set_recroute(m, *arg_i); 1085 break; 1086 case OSS_GETVERSION: 1087 *arg_i = SOUND_VERSION; 1088 break; 1089 default: 1090 ret = ENXIO;
|
| 1091 break;
|
850 } 851 852 snd_mtxunlock(m->lock);
| 1092 } 1093 1094 snd_mtxunlock(m->lock);
|
853 return ret;
| 1095 1096 return (ret);
|
854} 855 856#ifdef USING_DEVFS 857static void 858mixer_clone(void *arg, 859#if __FreeBSD_version >= 600034 860 struct ucred *cred, 861#endif 862 char *name, int namelen, struct cdev **dev) 863{ 864 struct snddev_info *d; 865 866 if (*dev != NULL) 867 return; 868 if (strcmp(name, "mixer") == 0) { 869 d = devclass_get_softc(pcm_devclass, snd_unit);
| 1097} 1098 1099#ifdef USING_DEVFS 1100static void 1101mixer_clone(void *arg, 1102#if __FreeBSD_version >= 600034 1103 struct ucred *cred, 1104#endif 1105 char *name, int namelen, struct cdev **dev) 1106{ 1107 struct snddev_info *d; 1108 1109 if (*dev != NULL) 1110 return; 1111 if (strcmp(name, "mixer") == 0) { 1112 d = devclass_get_softc(pcm_devclass, snd_unit);
|
870 if (d != NULL && d->mixer_dev != NULL) {
| 1113 if (PCM_REGISTERED(d) && d->mixer_dev != NULL) {
|
871 *dev = d->mixer_dev; 872 dev_ref(*dev); 873 } 874 } 875} 876 877static void 878mixer_sysinit(void *p) 879{ 880 if (mixer_ehtag != NULL) 881 return; 882 mixer_ehtag = EVENTHANDLER_REGISTER(dev_clone, mixer_clone, 0, 1000); 883} 884 885static void 886mixer_sysuninit(void *p) 887{ 888 if (mixer_ehtag == NULL) 889 return; 890 EVENTHANDLER_DEREGISTER(dev_clone, mixer_ehtag); 891 mixer_ehtag = NULL; 892} 893 894SYSINIT(mixer_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, mixer_sysinit, NULL); 895SYSUNINIT(mixer_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, mixer_sysuninit, NULL); 896#endif 897 898/** 899 * @brief Handler for SNDCTL_MIXERINFO 900 * 901 * This function searches for a mixer based on the numeric ID stored 902 * in oss_miserinfo::dev. If set to -1, then information about the 903 * current mixer handling the request is provided. Note, however, that 904 * this ioctl may be made with any sound device (audio, mixer, midi). 905 * 906 * @note Caller must not hold any PCM device, channel, or mixer locks. 907 * 908 * See http://manuals.opensound.com/developer/SNDCTL_MIXERINFO.html for 909 * more information. 910 * 911 * @param i_dev character device on which the ioctl arrived 912 * @param arg user argument (oss_mixerinfo *) 913 * 914 * @retval EINVAL oss_mixerinfo::dev specified a bad value 915 * @retval 0 success 916 */ 917int 918mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo *mi) 919{ 920 struct snddev_info *d; 921 struct snd_mixer *m;
| 1114 *dev = d->mixer_dev; 1115 dev_ref(*dev); 1116 } 1117 } 1118} 1119 1120static void 1121mixer_sysinit(void *p) 1122{ 1123 if (mixer_ehtag != NULL) 1124 return; 1125 mixer_ehtag = EVENTHANDLER_REGISTER(dev_clone, mixer_clone, 0, 1000); 1126} 1127 1128static void 1129mixer_sysuninit(void *p) 1130{ 1131 if (mixer_ehtag == NULL) 1132 return; 1133 EVENTHANDLER_DEREGISTER(dev_clone, mixer_ehtag); 1134 mixer_ehtag = NULL; 1135} 1136 1137SYSINIT(mixer_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, mixer_sysinit, NULL); 1138SYSUNINIT(mixer_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, mixer_sysuninit, NULL); 1139#endif 1140 1141/** 1142 * @brief Handler for SNDCTL_MIXERINFO 1143 * 1144 * This function searches for a mixer based on the numeric ID stored 1145 * in oss_miserinfo::dev. If set to -1, then information about the 1146 * current mixer handling the request is provided. Note, however, that 1147 * this ioctl may be made with any sound device (audio, mixer, midi). 1148 * 1149 * @note Caller must not hold any PCM device, channel, or mixer locks. 1150 * 1151 * See http://manuals.opensound.com/developer/SNDCTL_MIXERINFO.html for 1152 * more information. 1153 * 1154 * @param i_dev character device on which the ioctl arrived 1155 * @param arg user argument (oss_mixerinfo *) 1156 * 1157 * @retval EINVAL oss_mixerinfo::dev specified a bad value 1158 * @retval 0 success 1159 */ 1160int 1161mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo *mi) 1162{ 1163 struct snddev_info *d; 1164 struct snd_mixer *m;
|
922 struct cdev *t_cdev; 923 int nmix, ret, pcmunit, i;
| 1165 int nmix, i;
|
924 925 /* 926 * If probing the device handling the ioctl, make sure it's a mixer 927 * device. (This ioctl is valid on audio, mixer, and midi devices.) 928 */
| 1166 1167 /* 1168 * If probing the device handling the ioctl, make sure it's a mixer 1169 * device. (This ioctl is valid on audio, mixer, and midi devices.) 1170 */
|
929 if ((mi->dev == -1) && (i_dev->si_devsw != &mixer_cdevsw)) 930 return EINVAL;
| 1171 if (mi->dev == -1 && i_dev->si_devsw != &mixer_cdevsw) 1172 return (EINVAL);
|
931 932 d = NULL; 933 m = NULL;
| 1173 1174 d = NULL; 1175 m = NULL;
|
934 t_cdev = NULL;
| |
935 nmix = 0;
| 1176 nmix = 0;
|
936 ret = 0; 937 pcmunit = -1; /* pcmX */
| |
938 939 /* 940 * There's a 1:1 relationship between mixers and PCM devices, so 941 * begin by iterating over PCM devices and search for our mixer. 942 */ 943 for (i = 0; pcm_devclass != NULL && 944 i < devclass_get_maxunit(pcm_devclass); i++) { 945 d = devclass_get_softc(pcm_devclass, i);
| 1177 1178 /* 1179 * There's a 1:1 relationship between mixers and PCM devices, so 1180 * begin by iterating over PCM devices and search for our mixer. 1181 */ 1182 for (i = 0; pcm_devclass != NULL && 1183 i < devclass_get_maxunit(pcm_devclass); i++) { 1184 d = devclass_get_softc(pcm_devclass, i);
|
946 if (d == NULL)
| 1185 if (!PCM_REGISTERED(d))
|
947 continue; 948
| 1186 continue; 1187
|
| 1188 /* XXX Need Giant magic entry */ 1189
|
949 /* See the note in function docblock. */ 950 mtx_assert(d->lock, MA_NOTOWNED);
| 1190 /* See the note in function docblock. */ 1191 mtx_assert(d->lock, MA_NOTOWNED);
|
951 pcm_inprog(d, 1);
| |
952 pcm_lock(d); 953
| 1192 pcm_lock(d); 1193
|
954 if (d->mixer_dev != NULL) { 955 if (((mi->dev == -1) && (d->mixer_dev == i_dev)) || (mi->dev == nmix)) { 956 t_cdev = d->mixer_dev; 957 pcmunit = i; 958 break; 959 } 960 ++nmix; 961 }
| 1194 if (d->mixer_dev != NULL && d->mixer_dev->si_drv1 != NULL && 1195 ((mi->dev == -1 && d->mixer_dev == i_dev) || 1196 mi->dev == nmix)) { 1197 m = d->mixer_dev->si_drv1; 1198 mtx_lock(m->lock);
|
962
| 1199
|
963 pcm_unlock(d); 964 pcm_inprog(d, -1); 965 }
| 1200 /* 1201 * At this point, the following synchronization stuff 1202 * has happened: 1203 * - a specific PCM device is locked. 1204 * - a specific mixer device has been locked, so be 1205 * sure to unlock when existing. 1206 */ 1207 bzero((void *)mi, sizeof(*mi)); 1208 mi->dev = nmix; 1209 snprintf(mi->id, sizeof(mi->id), "mixer%d", i); 1210 strlcpy(mi->name, m->name, sizeof(mi->name)); 1211 mi->modify_counter = m->modify_counter; 1212 mi->card_number = i; 1213 /* 1214 * Currently, FreeBSD assumes 1:1 relationship between 1215 * a pcm and mixer devices, so this is hardcoded to 0. 1216 */ 1217 mi->port_number = 0;
|
966
| 1218
|
967 /* 968 * If t_cdev is NULL, then search was exhausted and device wasn't 969 * found. No locks are held, so just return. 970 */ 971 if (t_cdev == NULL) 972 return EINVAL;
| 1219 /** 1220 * @todo Fill in @sa oss_mixerinfo::mixerhandle. 1221 * @note From 4Front: "mixerhandle is an arbitrary 1222 * string that identifies the mixer better than 1223 * the device number (mixerinfo.dev). Device 1224 * numbers may change depending on the order the 1225 * drivers are loaded. However the handle should 1226 * remain the same provided that the sound card 1227 * is not moved to another PCI slot." 1228 */
|
973
| 1229
|
974 m = t_cdev->si_drv1; 975 mtx_lock(m->lock);
| 1230 /** 1231 * @note 1232 * @sa oss_mixerinfo::magic is a reserved field. 1233 * 1234 * @par 1235 * From 4Front: "magic is usually 0. However some 1236 * devices may have dedicated setup utilities and the 1237 * magic field may contain an unique driver specific 1238 * value (managed by [4Front])." 1239 */
|
976
| 1240
|
977 /* 978 * At this point, the following synchronization stuff has happened: 979 * - a specific PCM device is locked and its "in progress 980 * operations" counter has been incremented, so be sure to unlock 981 * and decrement when exiting; 982 * - a specific mixer device has been locked, so be sure to unlock 983 * when existing. 984 */
| 1241 mi->enabled = device_is_attached(m->dev) ? 1 : 0; 1242 /** 1243 * The only flag for @sa oss_mixerinfo::caps is 1244 * currently MIXER_CAP_VIRTUAL, which I'm not sure we 1245 * really worry about. 1246 */ 1247 /** 1248 * Mixer extensions currently aren't supported, so 1249 * leave @sa oss_mixerinfo::nrext blank for now. 1250 */ 1251 /** 1252 * @todo Fill in @sa oss_mixerinfo::priority (requires 1253 * touching drivers?) 1254 * @note The priority field is for mixer applets to 1255 * determine which mixer should be the default, with 0 1256 * being least preferred and 10 being most preferred. 1257 * From 4Front: "OSS drivers like ICH use higher 1258 * values (10) because such chips are known to be used 1259 * only on motherboards. Drivers for high end pro 1260 * devices use 0 because they will never be the 1261 * default mixer. Other devices use values 1 to 9 1262 * depending on the estimated probability of being the 1263 * default device. 1264 * 1265 * XXX Described by Hannu@4Front, but not found in 1266 * soundcard.h. 1267 strlcpy(mi->devnode, d->mixer_dev->si_name, 1268 sizeof(mi->devnode)); 1269 mi->legacy_device = i; 1270 */ 1271 mtx_unlock(m->lock); 1272 } else 1273 ++nmix;
|
985
| 1274
|
986 bzero((void *)mi, sizeof(*mi));
| 1275 pcm_unlock(d);
|
987
| 1276
|
988 mi->dev = nmix; 989 snprintf(mi->id, sizeof(mi->id), "mixer%d", dev2unit(t_cdev)); 990 strlcpy(mi->name, m->name, sizeof(mi->name)); 991 mi->modify_counter = m->modify_counter; 992 mi->card_number = pcmunit; 993 /* 994 * Currently, FreeBSD assumes 1:1 relationship between a pcm and 995 * mixer devices, so this is hardcoded to 0. 996 */ 997 mi->port_number = 0;
| 1277 if (m != NULL) 1278 return (0); 1279 }
|
998
| 1280
|
999 /** 1000 * @todo Fill in @sa oss_mixerinfo::mixerhandle. 1001 * @note From 4Front: "mixerhandle is an arbitrary string that 1002 * identifies the mixer better than the device number 1003 * (mixerinfo.dev). Device numbers may change depending on 1004 * the order the drivers are loaded. However the handle 1005 * should remain the same provided that the sound card is 1006 * not moved to another PCI slot." 1007 */ 1008 1009 /** 1010 * @note 1011 * @sa oss_mixerinfo::magic is a reserved field. 1012 * 1013 * @par 1014 * From 4Front: "magic is usually 0. However some devices may have 1015 * dedicated setup utilities and the magic field may contain an 1016 * unique driver specific value (managed by [4Front])." 1017 */ 1018 1019 mi->enabled = device_is_attached(m->dev) ? 1 : 0; 1020 /** 1021 * The only flag for @sa oss_mixerinfo::caps is currently 1022 * MIXER_CAP_VIRTUAL, which I'm not sure we really worry about. 1023 */ 1024 /** 1025 * Mixer extensions currently aren't supported, so leave 1026 * @sa oss_mixerinfo::nrext blank for now. 1027 */ 1028 /** 1029 * @todo Fill in @sa oss_mixerinfo::priority (requires touching 1030 * drivers?) 1031 * @note The priority field is for mixer applets to determine which 1032 * mixer should be the default, with 0 being least preferred and 10 1033 * being most preferred. From 4Front: "OSS drivers like ICH use 1034 * higher values (10) because such chips are known to be used only 1035 * on motherboards. Drivers for high end pro devices use 0 because 1036 * they will never be the default mixer. Other devices use values 1 1037 * to 9 depending on the estimated probability of being the default 1038 * device. 1039 * 1040 * XXX Described by Hannu@4Front, but not found in soundcard.h. 1041 strlcpy(mi->devnode, t_cdev->si_name, sizeof(mi->devnode)); 1042 mi->legacy_device = pcmunit; 1043 */ 1044 1045 mtx_unlock(m->lock); 1046 pcm_unlock(d); 1047 pcm_inprog(d, -1); 1048 1049 return ret;
| 1281 return (EINVAL);
|
1050}
| 1282}
|