2 * Digital Audio (PCM) abstract layer / OSS compatible
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 #include <linux/init.h>
30 #include <linux/slab.h>
31 #include <linux/time.h>
32 #include <linux/vmalloc.h>
33 #include <linux/module.h>
34 #include <linux/math64.h>
35 #include <linux/string.h>
36 #include <sound/core.h>
37 #include <sound/minors.h>
38 #include <sound/pcm.h>
39 #include <sound/pcm_params.h>
40 #include "pcm_plugin.h"
41 #include <sound/info.h>
42 #include <linux/soundcard.h>
43 #include <sound/initval.h>
44 #include <sound/mixer_oss.h>
46 #define OSS_ALSAEMULVER _SIOR ('M', 249, int)
48 static int dsp_map[SNDRV_CARDS];
49 static int adsp_map[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)] = 1};
50 static int nonblock_open = 1;
52 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, Abramo Bagnara <abramo@alsa-project.org>");
53 MODULE_DESCRIPTION("PCM OSS emulation for ALSA.");
54 MODULE_LICENSE("GPL");
55 module_param_array(dsp_map, int, NULL, 0444);
56 MODULE_PARM_DESC(dsp_map, "PCM device number assigned to 1st OSS device.");
57 module_param_array(adsp_map, int, NULL, 0444);
58 MODULE_PARM_DESC(adsp_map, "PCM device number assigned to 2nd OSS device.");
59 module_param(nonblock_open, bool, 0644);
60 MODULE_PARM_DESC(nonblock_open, "Don't block opening busy PCM devices.");
61 MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_PCM);
62 MODULE_ALIAS_SNDRV_MINOR(SNDRV_MINOR_OSS_PCM1);
64 static int snd_pcm_oss_get_rate(struct snd_pcm_oss_file *pcm_oss_file);
65 static int snd_pcm_oss_get_channels(struct snd_pcm_oss_file *pcm_oss_file);
66 static int snd_pcm_oss_get_format(struct snd_pcm_oss_file *pcm_oss_file);
68 static inline mm_segment_t snd_enter_user(void)
70 mm_segment_t fs = get_fs();
75 static inline void snd_leave_user(mm_segment_t fs)
81 * helper functions to process hw_params
83 static int snd_interval_refine_min(struct snd_interval *i, unsigned int min, int openmin)
90 } else if (i->min == min && !i->openmin && openmin) {
100 if (snd_interval_checkempty(i)) {
101 snd_interval_none(i);
107 static int snd_interval_refine_max(struct snd_interval *i, unsigned int max, int openmax)
112 i->openmax = openmax;
114 } else if (i->max == max && !i->openmax && openmax) {
124 if (snd_interval_checkempty(i)) {
125 snd_interval_none(i);
131 static int snd_interval_refine_set(struct snd_interval *i, unsigned int val)
133 struct snd_interval t;
136 t.openmin = t.openmax = 0;
138 return snd_interval_refine(i, &t);
142 * snd_pcm_hw_param_value_min
143 * @params: the hw_params instance
144 * @var: parameter to retrieve
145 * @dir: pointer to the direction (-1,0,1) or NULL
147 * Return the minimum value for field PAR.
150 snd_pcm_hw_param_value_min(const struct snd_pcm_hw_params *params,
151 snd_pcm_hw_param_t var, int *dir)
153 if (hw_is_mask(var)) {
156 return snd_mask_min(hw_param_mask_c(params, var));
158 if (hw_is_interval(var)) {
159 const struct snd_interval *i = hw_param_interval_c(params, var);
162 return snd_interval_min(i);
168 * snd_pcm_hw_param_value_max
169 * @params: the hw_params instance
170 * @var: parameter to retrieve
171 * @dir: pointer to the direction (-1,0,1) or NULL
173 * Return the maximum value for field PAR.
176 snd_pcm_hw_param_value_max(const struct snd_pcm_hw_params *params,
177 snd_pcm_hw_param_t var, int *dir)
179 if (hw_is_mask(var)) {
182 return snd_mask_max(hw_param_mask_c(params, var));
184 if (hw_is_interval(var)) {
185 const struct snd_interval *i = hw_param_interval_c(params, var);
187 *dir = - (int) i->openmax;
188 return snd_interval_max(i);
193 static int _snd_pcm_hw_param_mask(struct snd_pcm_hw_params *params,
194 snd_pcm_hw_param_t var,
195 const struct snd_mask *val)
198 changed = snd_mask_refine(hw_param_mask(params, var), val);
200 params->cmask |= 1 << var;
201 params->rmask |= 1 << var;
206 static int snd_pcm_hw_param_mask(struct snd_pcm_substream *pcm,
207 struct snd_pcm_hw_params *params,
208 snd_pcm_hw_param_t var,
209 const struct snd_mask *val)
211 int changed = _snd_pcm_hw_param_mask(params, var, val);
215 int err = snd_pcm_hw_refine(pcm, params);
222 static int _snd_pcm_hw_param_min(struct snd_pcm_hw_params *params,
223 snd_pcm_hw_param_t var, unsigned int val,
231 } else if (dir < 0) {
239 changed = snd_mask_refine_min(hw_param_mask(params, var),
241 else if (hw_is_interval(var))
242 changed = snd_interval_refine_min(hw_param_interval(params, var),
247 params->cmask |= 1 << var;
248 params->rmask |= 1 << var;
254 * snd_pcm_hw_param_min
256 * @params: the hw_params instance
257 * @var: parameter to retrieve
258 * @val: minimal value
259 * @dir: pointer to the direction (-1,0,1) or NULL
261 * Inside configuration space defined by PARAMS remove from PAR all
262 * values < VAL. Reduce configuration space accordingly.
263 * Return new minimum or -EINVAL if the configuration space is empty
265 static int snd_pcm_hw_param_min(struct snd_pcm_substream *pcm,
266 struct snd_pcm_hw_params *params,
267 snd_pcm_hw_param_t var, unsigned int val,
270 int changed = _snd_pcm_hw_param_min(params, var, val, dir ? *dir : 0);
274 int err = snd_pcm_hw_refine(pcm, params);
278 return snd_pcm_hw_param_value_min(params, var, dir);
281 static int _snd_pcm_hw_param_max(struct snd_pcm_hw_params *params,
282 snd_pcm_hw_param_t var, unsigned int val,
290 } else if (dir > 0) {
295 if (hw_is_mask(var)) {
296 if (val == 0 && open) {
297 snd_mask_none(hw_param_mask(params, var));
300 changed = snd_mask_refine_max(hw_param_mask(params, var),
302 } else if (hw_is_interval(var))
303 changed = snd_interval_refine_max(hw_param_interval(params, var),
308 params->cmask |= 1 << var;
309 params->rmask |= 1 << var;
315 * snd_pcm_hw_param_max
317 * @params: the hw_params instance
318 * @var: parameter to retrieve
319 * @val: maximal value
320 * @dir: pointer to the direction (-1,0,1) or NULL
322 * Inside configuration space defined by PARAMS remove from PAR all
323 * values >= VAL + 1. Reduce configuration space accordingly.
324 * Return new maximum or -EINVAL if the configuration space is empty
326 static int snd_pcm_hw_param_max(struct snd_pcm_substream *pcm,
327 struct snd_pcm_hw_params *params,
328 snd_pcm_hw_param_t var, unsigned int val,
331 int changed = _snd_pcm_hw_param_max(params, var, val, dir ? *dir : 0);
335 int err = snd_pcm_hw_refine(pcm, params);
339 return snd_pcm_hw_param_value_max(params, var, dir);
342 static int boundary_sub(int a, int adir,
346 adir = adir < 0 ? -1 : (adir > 0 ? 1 : 0);
347 bdir = bdir < 0 ? -1 : (bdir > 0 ? 1 : 0);
352 } else if (*cdir == 2) {
358 static int boundary_lt(unsigned int a, int adir,
359 unsigned int b, int bdir)
371 return a < b || (a == b && adir < bdir);
374 /* Return 1 if min is nearer to best than max */
375 static int boundary_nearer(int min, int mindir,
376 int best, int bestdir,
381 boundary_sub(best, bestdir, min, mindir, &dmin, &dmindir);
382 boundary_sub(max, maxdir, best, bestdir, &dmax, &dmaxdir);
383 return boundary_lt(dmin, dmindir, dmax, dmaxdir);
387 * snd_pcm_hw_param_near
389 * @params: the hw_params instance
390 * @var: parameter to retrieve
391 * @best: value to set
392 * @dir: pointer to the direction (-1,0,1) or NULL
394 * Inside configuration space defined by PARAMS set PAR to the available value
395 * nearest to VAL. Reduce configuration space accordingly.
396 * This function cannot be called for SNDRV_PCM_HW_PARAM_ACCESS,
397 * SNDRV_PCM_HW_PARAM_FORMAT, SNDRV_PCM_HW_PARAM_SUBFORMAT.
398 * Return the value found.
400 static int snd_pcm_hw_param_near(struct snd_pcm_substream *pcm,
401 struct snd_pcm_hw_params *params,
402 snd_pcm_hw_param_t var, unsigned int best,
405 struct snd_pcm_hw_params *save = NULL;
407 unsigned int saved_min;
411 int valdir = dir ? *dir : 0;
416 mindir = maxdir = valdir;
419 else if (maxdir == 0)
425 save = kmalloc(sizeof(*save), GFP_KERNEL);
430 min = snd_pcm_hw_param_min(pcm, params, var, min, &mindir);
432 struct snd_pcm_hw_params *params1;
435 if ((unsigned int)min == saved_min && mindir == valdir)
437 params1 = kmalloc(sizeof(*params1), GFP_KERNEL);
438 if (params1 == NULL) {
443 max = snd_pcm_hw_param_max(pcm, params1, var, max, &maxdir);
448 if (boundary_nearer(max, maxdir, best, valdir, min, mindir)) {
455 max = snd_pcm_hw_param_max(pcm, params, var, max, &maxdir);
465 v = snd_pcm_hw_param_last(pcm, params, var, dir);
467 v = snd_pcm_hw_param_first(pcm, params, var, dir);
471 static int _snd_pcm_hw_param_set(struct snd_pcm_hw_params *params,
472 snd_pcm_hw_param_t var, unsigned int val,
476 if (hw_is_mask(var)) {
477 struct snd_mask *m = hw_param_mask(params, var);
478 if (val == 0 && dir < 0) {
486 changed = snd_mask_refine_set(hw_param_mask(params, var), val);
488 } else if (hw_is_interval(var)) {
489 struct snd_interval *i = hw_param_interval(params, var);
490 if (val == 0 && dir < 0) {
492 snd_interval_none(i);
494 changed = snd_interval_refine_set(i, val);
496 struct snd_interval t;
508 changed = snd_interval_refine(i, &t);
513 params->cmask |= 1 << var;
514 params->rmask |= 1 << var;
520 * snd_pcm_hw_param_set
522 * @params: the hw_params instance
523 * @var: parameter to retrieve
525 * @dir: pointer to the direction (-1,0,1) or NULL
527 * Inside configuration space defined by PARAMS remove from PAR all
528 * values != VAL. Reduce configuration space accordingly.
529 * Return VAL or -EINVAL if the configuration space is empty
531 static int snd_pcm_hw_param_set(struct snd_pcm_substream *pcm,
532 struct snd_pcm_hw_params *params,
533 snd_pcm_hw_param_t var, unsigned int val,
536 int changed = _snd_pcm_hw_param_set(params, var, val, dir);
540 int err = snd_pcm_hw_refine(pcm, params);
544 return snd_pcm_hw_param_value(params, var, NULL);
547 static int _snd_pcm_hw_param_setinteger(struct snd_pcm_hw_params *params,
548 snd_pcm_hw_param_t var)
551 changed = snd_interval_setinteger(hw_param_interval(params, var));
553 params->cmask |= 1 << var;
554 params->rmask |= 1 << var;
563 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
564 static int snd_pcm_oss_plugin_clear(struct snd_pcm_substream *substream)
566 struct snd_pcm_runtime *runtime = substream->runtime;
567 struct snd_pcm_plugin *plugin, *next;
569 plugin = runtime->oss.plugin_first;
572 snd_pcm_plugin_free(plugin);
575 runtime->oss.plugin_first = runtime->oss.plugin_last = NULL;
579 static int snd_pcm_plugin_insert(struct snd_pcm_plugin *plugin)
581 struct snd_pcm_runtime *runtime = plugin->plug->runtime;
582 plugin->next = runtime->oss.plugin_first;
584 if (runtime->oss.plugin_first) {
585 runtime->oss.plugin_first->prev = plugin;
586 runtime->oss.plugin_first = plugin;
588 runtime->oss.plugin_last =
589 runtime->oss.plugin_first = plugin;
594 int snd_pcm_plugin_append(struct snd_pcm_plugin *plugin)
596 struct snd_pcm_runtime *runtime = plugin->plug->runtime;
598 plugin->prev = runtime->oss.plugin_last;
599 if (runtime->oss.plugin_last) {
600 runtime->oss.plugin_last->next = plugin;
601 runtime->oss.plugin_last = plugin;
603 runtime->oss.plugin_last =
604 runtime->oss.plugin_first = plugin;
608 #endif /* CONFIG_SND_PCM_OSS_PLUGINS */
610 static long snd_pcm_oss_bytes(struct snd_pcm_substream *substream, long frames)
612 struct snd_pcm_runtime *runtime = substream->runtime;
613 long buffer_size = snd_pcm_lib_buffer_bytes(substream);
614 long bytes = frames_to_bytes(runtime, frames);
615 if (buffer_size == runtime->oss.buffer_bytes)
617 #if BITS_PER_LONG >= 64
618 return runtime->oss.buffer_bytes * bytes / buffer_size;
621 u64 bsize = (u64)runtime->oss.buffer_bytes * (u64)bytes;
622 return div_u64(bsize, buffer_size);
627 static long snd_pcm_alsa_frames(struct snd_pcm_substream *substream, long bytes)
629 struct snd_pcm_runtime *runtime = substream->runtime;
630 long buffer_size = snd_pcm_lib_buffer_bytes(substream);
631 if (buffer_size == runtime->oss.buffer_bytes)
632 return bytes_to_frames(runtime, bytes);
633 return bytes_to_frames(runtime, (buffer_size * bytes) / runtime->oss.buffer_bytes);
637 snd_pcm_uframes_t get_hw_ptr_period(struct snd_pcm_runtime *runtime)
639 return runtime->hw_ptr_interrupt;
642 /* define extended formats in the recent OSS versions (if any) */
644 #define AFMT_S32_LE 0x00001000
645 #define AFMT_S32_BE 0x00002000
646 #define AFMT_S24_LE 0x00008000
647 #define AFMT_S24_BE 0x00010000
648 #define AFMT_S24_PACKED 0x00040000
650 /* other supported formats */
651 #define AFMT_FLOAT 0x00004000
652 #define AFMT_SPDIF_RAW 0x00020000
654 /* unsupported formats */
655 #define AFMT_AC3 0x00000400
656 #define AFMT_VORBIS 0x00000800
658 static snd_pcm_format_t snd_pcm_oss_format_from(int format)
661 case AFMT_MU_LAW: return SNDRV_PCM_FORMAT_MU_LAW;
662 case AFMT_A_LAW: return SNDRV_PCM_FORMAT_A_LAW;
663 case AFMT_IMA_ADPCM: return SNDRV_PCM_FORMAT_IMA_ADPCM;
664 case AFMT_U8: return SNDRV_PCM_FORMAT_U8;
665 case AFMT_S16_LE: return SNDRV_PCM_FORMAT_S16_LE;
666 case AFMT_S16_BE: return SNDRV_PCM_FORMAT_S16_BE;
667 case AFMT_S8: return SNDRV_PCM_FORMAT_S8;
668 case AFMT_U16_LE: return SNDRV_PCM_FORMAT_U16_LE;
669 case AFMT_U16_BE: return SNDRV_PCM_FORMAT_U16_BE;
670 case AFMT_MPEG: return SNDRV_PCM_FORMAT_MPEG;
671 case AFMT_S32_LE: return SNDRV_PCM_FORMAT_S32_LE;
672 case AFMT_S32_BE: return SNDRV_PCM_FORMAT_S32_BE;
673 case AFMT_S24_LE: return SNDRV_PCM_FORMAT_S24_LE;
674 case AFMT_S24_BE: return SNDRV_PCM_FORMAT_S24_BE;
675 case AFMT_S24_PACKED: return SNDRV_PCM_FORMAT_S24_3LE;
676 case AFMT_FLOAT: return SNDRV_PCM_FORMAT_FLOAT;
677 case AFMT_SPDIF_RAW: return SNDRV_PCM_FORMAT_IEC958_SUBFRAME;
678 default: return SNDRV_PCM_FORMAT_U8;
682 static int snd_pcm_oss_format_to(snd_pcm_format_t format)
685 case SNDRV_PCM_FORMAT_MU_LAW: return AFMT_MU_LAW;
686 case SNDRV_PCM_FORMAT_A_LAW: return AFMT_A_LAW;
687 case SNDRV_PCM_FORMAT_IMA_ADPCM: return AFMT_IMA_ADPCM;
688 case SNDRV_PCM_FORMAT_U8: return AFMT_U8;
689 case SNDRV_PCM_FORMAT_S16_LE: return AFMT_S16_LE;
690 case SNDRV_PCM_FORMAT_S16_BE: return AFMT_S16_BE;
691 case SNDRV_PCM_FORMAT_S8: return AFMT_S8;
692 case SNDRV_PCM_FORMAT_U16_LE: return AFMT_U16_LE;
693 case SNDRV_PCM_FORMAT_U16_BE: return AFMT_U16_BE;
694 case SNDRV_PCM_FORMAT_MPEG: return AFMT_MPEG;
695 case SNDRV_PCM_FORMAT_S32_LE: return AFMT_S32_LE;
696 case SNDRV_PCM_FORMAT_S32_BE: return AFMT_S32_BE;
697 case SNDRV_PCM_FORMAT_S24_LE: return AFMT_S24_LE;
698 case SNDRV_PCM_FORMAT_S24_BE: return AFMT_S24_BE;
699 case SNDRV_PCM_FORMAT_S24_3LE: return AFMT_S24_PACKED;
700 case SNDRV_PCM_FORMAT_FLOAT: return AFMT_FLOAT;
701 case SNDRV_PCM_FORMAT_IEC958_SUBFRAME: return AFMT_SPDIF_RAW;
702 default: return -EINVAL;
706 static int snd_pcm_oss_period_size(struct snd_pcm_substream *substream,
707 struct snd_pcm_hw_params *oss_params,
708 struct snd_pcm_hw_params *slave_params)
711 size_t oss_buffer_size, oss_period_size, oss_periods;
712 size_t min_period_size, max_period_size;
713 struct snd_pcm_runtime *runtime = substream->runtime;
714 size_t oss_frame_size;
716 oss_frame_size = snd_pcm_format_physical_width(params_format(oss_params)) *
717 params_channels(oss_params) / 8;
719 oss_buffer_size = snd_pcm_plug_client_size(substream,
720 snd_pcm_hw_param_value_max(slave_params, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, NULL)) * oss_frame_size;
721 oss_buffer_size = 1 << ld2(oss_buffer_size);
722 if (atomic_read(&substream->mmap_count)) {
723 if (oss_buffer_size > runtime->oss.mmap_bytes)
724 oss_buffer_size = runtime->oss.mmap_bytes;
727 if (substream->oss.setup.period_size > 16)
728 oss_period_size = substream->oss.setup.period_size;
729 else if (runtime->oss.fragshift) {
730 oss_period_size = 1 << runtime->oss.fragshift;
731 if (oss_period_size > oss_buffer_size / 2)
732 oss_period_size = oss_buffer_size / 2;
735 size_t bytes_per_sec = params_rate(oss_params) * snd_pcm_format_physical_width(params_format(oss_params)) * params_channels(oss_params) / 8;
737 oss_period_size = oss_buffer_size;
739 oss_period_size /= 2;
740 } while (oss_period_size > bytes_per_sec);
741 if (runtime->oss.subdivision == 0) {
743 if (oss_period_size / sd > 4096)
745 if (oss_period_size / sd < 4096)
748 sd = runtime->oss.subdivision;
749 oss_period_size /= sd;
750 if (oss_period_size < 16)
751 oss_period_size = 16;
754 min_period_size = snd_pcm_plug_client_size(substream,
755 snd_pcm_hw_param_value_min(slave_params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, NULL));
756 min_period_size *= oss_frame_size;
757 min_period_size = 1 << (ld2(min_period_size - 1) + 1);
758 if (oss_period_size < min_period_size)
759 oss_period_size = min_period_size;
761 max_period_size = snd_pcm_plug_client_size(substream,
762 snd_pcm_hw_param_value_max(slave_params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, NULL));
763 max_period_size *= oss_frame_size;
764 max_period_size = 1 << ld2(max_period_size);
765 if (oss_period_size > max_period_size)
766 oss_period_size = max_period_size;
768 oss_periods = oss_buffer_size / oss_period_size;
770 if (substream->oss.setup.periods > 1)
771 oss_periods = substream->oss.setup.periods;
773 s = snd_pcm_hw_param_value_max(slave_params, SNDRV_PCM_HW_PARAM_PERIODS, NULL);
774 if (runtime->oss.maxfrags && s > runtime->oss.maxfrags)
775 s = runtime->oss.maxfrags;
779 s = snd_pcm_hw_param_value_min(slave_params, SNDRV_PCM_HW_PARAM_PERIODS, NULL);
785 while (oss_period_size * oss_periods > oss_buffer_size)
786 oss_period_size /= 2;
788 if (oss_period_size < 16)
790 runtime->oss.period_bytes = oss_period_size;
791 runtime->oss.period_frames = 1;
792 runtime->oss.periods = oss_periods;
796 static int choose_rate(struct snd_pcm_substream *substream,
797 struct snd_pcm_hw_params *params, unsigned int best_rate)
799 struct snd_interval *it;
800 struct snd_pcm_hw_params *save;
801 unsigned int rate, prev;
803 save = kmalloc(sizeof(*save), GFP_KERNEL);
807 it = hw_param_interval(save, SNDRV_PCM_HW_PARAM_RATE);
809 /* try multiples of the best rate */
812 if (it->max < rate || (it->max == rate && it->openmax))
814 if (it->min < rate || (it->min == rate && !it->openmin)) {
816 ret = snd_pcm_hw_param_set(substream, params,
817 SNDRV_PCM_HW_PARAM_RATE,
819 if (ret == (int)rate) {
831 /* not found, use the nearest rate */
833 return snd_pcm_hw_param_near(substream, params, SNDRV_PCM_HW_PARAM_RATE, best_rate, NULL);
836 static int snd_pcm_oss_change_params(struct snd_pcm_substream *substream,
839 struct snd_pcm_runtime *runtime = substream->runtime;
840 struct snd_pcm_hw_params *params, *sparams;
841 struct snd_pcm_sw_params *sw_params;
842 ssize_t oss_buffer_size, oss_period_size;
843 size_t oss_frame_size;
846 snd_pcm_format_t format, sformat;
848 struct snd_mask sformat_mask;
849 struct snd_mask mask;
852 if (!(mutex_trylock(&runtime->oss.params_lock)))
854 } else if (mutex_lock_interruptible(&runtime->oss.params_lock))
856 sw_params = kmalloc(sizeof(*sw_params), GFP_KERNEL);
857 params = kmalloc(sizeof(*params), GFP_KERNEL);
858 sparams = kmalloc(sizeof(*sparams), GFP_KERNEL);
859 if (!sw_params || !params || !sparams) {
860 snd_printd("No memory\n");
865 if (atomic_read(&substream->mmap_count))
868 direct = substream->oss.setup.direct;
870 _snd_pcm_hw_params_any(sparams);
871 _snd_pcm_hw_param_setinteger(sparams, SNDRV_PCM_HW_PARAM_PERIODS);
872 _snd_pcm_hw_param_min(sparams, SNDRV_PCM_HW_PARAM_PERIODS, 2, 0);
873 snd_mask_none(&mask);
874 if (atomic_read(&substream->mmap_count))
875 snd_mask_set(&mask, (__force int)SNDRV_PCM_ACCESS_MMAP_INTERLEAVED);
877 snd_mask_set(&mask, (__force int)SNDRV_PCM_ACCESS_RW_INTERLEAVED);
879 snd_mask_set(&mask, (__force int)SNDRV_PCM_ACCESS_RW_NONINTERLEAVED);
881 err = snd_pcm_hw_param_mask(substream, sparams, SNDRV_PCM_HW_PARAM_ACCESS, &mask);
883 snd_printd("No usable accesses\n");
887 choose_rate(substream, sparams, runtime->oss.rate);
888 snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_CHANNELS, runtime->oss.channels, NULL);
890 format = snd_pcm_oss_format_from(runtime->oss.format);
892 sformat_mask = *hw_param_mask(sparams, SNDRV_PCM_HW_PARAM_FORMAT);
896 sformat = snd_pcm_plug_slave_format(format, &sformat_mask);
898 if ((__force int)sformat < 0 ||
899 !snd_mask_test(&sformat_mask, (__force int)sformat)) {
900 for (sformat = (__force snd_pcm_format_t)0;
901 (__force int)sformat <= (__force int)SNDRV_PCM_FORMAT_LAST;
902 sformat = (__force snd_pcm_format_t)((__force int)sformat + 1)) {
903 if (snd_mask_test(&sformat_mask, (__force int)sformat) &&
904 snd_pcm_oss_format_to(sformat) >= 0)
907 if ((__force int)sformat > (__force int)SNDRV_PCM_FORMAT_LAST) {
908 snd_printd("Cannot find a format!!!\n");
913 err = _snd_pcm_hw_param_set(sparams, SNDRV_PCM_HW_PARAM_FORMAT, (__force int)sformat, 0);
918 memcpy(params, sparams, sizeof(*params));
920 _snd_pcm_hw_params_any(params);
921 _snd_pcm_hw_param_set(params, SNDRV_PCM_HW_PARAM_ACCESS,
922 (__force int)SNDRV_PCM_ACCESS_RW_INTERLEAVED, 0);
923 _snd_pcm_hw_param_set(params, SNDRV_PCM_HW_PARAM_FORMAT,
924 (__force int)snd_pcm_oss_format_from(runtime->oss.format), 0);
925 _snd_pcm_hw_param_set(params, SNDRV_PCM_HW_PARAM_CHANNELS,
926 runtime->oss.channels, 0);
927 _snd_pcm_hw_param_set(params, SNDRV_PCM_HW_PARAM_RATE,
928 runtime->oss.rate, 0);
929 pdprintf("client: access = %i, format = %i, channels = %i, rate = %i\n",
930 params_access(params), params_format(params),
931 params_channels(params), params_rate(params));
933 pdprintf("slave: access = %i, format = %i, channels = %i, rate = %i\n",
934 params_access(sparams), params_format(sparams),
935 params_channels(sparams), params_rate(sparams));
937 oss_frame_size = snd_pcm_format_physical_width(params_format(params)) *
938 params_channels(params) / 8;
940 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
941 snd_pcm_oss_plugin_clear(substream);
943 /* add necessary plugins */
944 snd_pcm_oss_plugin_clear(substream);
945 if ((err = snd_pcm_plug_format_plugins(substream,
948 snd_printd("snd_pcm_plug_format_plugins failed: %i\n", err);
949 snd_pcm_oss_plugin_clear(substream);
952 if (runtime->oss.plugin_first) {
953 struct snd_pcm_plugin *plugin;
954 if ((err = snd_pcm_plugin_build_io(substream, sparams, &plugin)) < 0) {
955 snd_printd("snd_pcm_plugin_build_io failed: %i\n", err);
956 snd_pcm_oss_plugin_clear(substream);
959 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
960 err = snd_pcm_plugin_append(plugin);
962 err = snd_pcm_plugin_insert(plugin);
965 snd_pcm_oss_plugin_clear(substream);
972 err = snd_pcm_oss_period_size(substream, params, sparams);
976 n = snd_pcm_plug_slave_size(substream, runtime->oss.period_bytes / oss_frame_size);
977 err = snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, n, NULL);
981 err = snd_pcm_hw_param_near(substream, sparams, SNDRV_PCM_HW_PARAM_PERIODS,
982 runtime->oss.periods, NULL);
986 snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);
988 if ((err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_HW_PARAMS, sparams)) < 0) {
989 snd_printd("HW_PARAMS failed: %i\n", err);
993 memset(sw_params, 0, sizeof(*sw_params));
994 if (runtime->oss.trigger) {
995 sw_params->start_threshold = 1;
997 sw_params->start_threshold = runtime->boundary;
999 if (atomic_read(&substream->mmap_count) ||
1000 substream->stream == SNDRV_PCM_STREAM_CAPTURE)
1001 sw_params->stop_threshold = runtime->boundary;
1003 sw_params->stop_threshold = runtime->buffer_size;
1004 sw_params->tstamp_mode = SNDRV_PCM_TSTAMP_NONE;
1005 sw_params->period_step = 1;
1006 sw_params->avail_min = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
1007 1 : runtime->period_size;
1008 if (atomic_read(&substream->mmap_count) ||
1009 substream->oss.setup.nosilence) {
1010 sw_params->silence_threshold = 0;
1011 sw_params->silence_size = 0;
1013 snd_pcm_uframes_t frames;
1014 frames = runtime->period_size + 16;
1015 if (frames > runtime->buffer_size)
1016 frames = runtime->buffer_size;
1017 sw_params->silence_threshold = frames;
1018 sw_params->silence_size = frames;
1021 if ((err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_SW_PARAMS, sw_params)) < 0) {
1022 snd_printd("SW_PARAMS failed: %i\n", err);
1026 runtime->oss.periods = params_periods(sparams);
1027 oss_period_size = snd_pcm_plug_client_size(substream, params_period_size(sparams));
1028 if (oss_period_size < 0) {
1032 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
1033 if (runtime->oss.plugin_first) {
1034 err = snd_pcm_plug_alloc(substream, oss_period_size);
1039 oss_period_size *= oss_frame_size;
1041 oss_buffer_size = oss_period_size * runtime->oss.periods;
1042 if (oss_buffer_size < 0) {
1047 runtime->oss.period_bytes = oss_period_size;
1048 runtime->oss.buffer_bytes = oss_buffer_size;
1050 pdprintf("oss: period bytes = %i, buffer bytes = %i\n",
1051 runtime->oss.period_bytes,
1052 runtime->oss.buffer_bytes);
1053 pdprintf("slave: period_size = %i, buffer_size = %i\n",
1054 params_period_size(sparams),
1055 params_buffer_size(sparams));
1057 runtime->oss.format = snd_pcm_oss_format_to(params_format(params));
1058 runtime->oss.channels = params_channels(params);
1059 runtime->oss.rate = params_rate(params);
1061 vfree(runtime->oss.buffer);
1062 runtime->oss.buffer = vmalloc(runtime->oss.period_bytes);
1063 if (!runtime->oss.buffer) {
1068 runtime->oss.params = 0;
1069 runtime->oss.prepare = 1;
1070 runtime->oss.buffer_used = 0;
1071 if (runtime->dma_area)
1072 snd_pcm_format_set_silence(runtime->format, runtime->dma_area, bytes_to_samples(runtime, runtime->dma_bytes));
1074 runtime->oss.period_frames = snd_pcm_alsa_frames(substream, oss_period_size);
1081 mutex_unlock(&runtime->oss.params_lock);
1085 static int snd_pcm_oss_get_active_substream(struct snd_pcm_oss_file *pcm_oss_file, struct snd_pcm_substream **r_substream)
1088 struct snd_pcm_substream *asubstream = NULL, *substream;
1090 for (idx = 0; idx < 2; idx++) {
1091 substream = pcm_oss_file->streams[idx];
1092 if (substream == NULL)
1094 if (asubstream == NULL)
1095 asubstream = substream;
1096 if (substream->runtime->oss.params) {
1097 err = snd_pcm_oss_change_params(substream, false);
1105 *r_substream = asubstream;
1109 static int snd_pcm_oss_prepare(struct snd_pcm_substream *substream)
1112 struct snd_pcm_runtime *runtime = substream->runtime;
1114 err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_PREPARE, NULL);
1116 snd_printd("snd_pcm_oss_prepare: SNDRV_PCM_IOCTL_PREPARE failed\n");
1119 runtime->oss.prepare = 0;
1120 runtime->oss.prev_hw_ptr_period = 0;
1121 runtime->oss.period_ptr = 0;
1122 runtime->oss.buffer_used = 0;
1127 static int snd_pcm_oss_make_ready(struct snd_pcm_substream *substream)
1129 struct snd_pcm_runtime *runtime;
1132 if (substream == NULL)
1134 runtime = substream->runtime;
1135 if (runtime->oss.params) {
1136 err = snd_pcm_oss_change_params(substream, false);
1140 if (runtime->oss.prepare) {
1141 err = snd_pcm_oss_prepare(substream);
1148 static int snd_pcm_oss_capture_position_fixup(struct snd_pcm_substream *substream, snd_pcm_sframes_t *delay)
1150 struct snd_pcm_runtime *runtime;
1151 snd_pcm_uframes_t frames;
1155 err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DELAY, delay);
1158 runtime = substream->runtime;
1159 if (*delay <= (snd_pcm_sframes_t)runtime->buffer_size)
1161 /* in case of overrun, skip whole periods like OSS/Linux driver does */
1162 /* until avail(delay) <= buffer_size */
1163 frames = (*delay - runtime->buffer_size) + runtime->period_size - 1;
1164 frames /= runtime->period_size;
1165 frames *= runtime->period_size;
1166 err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_FORWARD, &frames);
1173 snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const char *ptr, snd_pcm_uframes_t frames, int in_kernel)
1175 struct snd_pcm_runtime *runtime = substream->runtime;
1178 if (runtime->status->state == SNDRV_PCM_STATE_XRUN ||
1179 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
1181 if (runtime->status->state == SNDRV_PCM_STATE_XRUN)
1182 printk(KERN_DEBUG "pcm_oss: write: "
1183 "recovering from XRUN\n");
1185 printk(KERN_DEBUG "pcm_oss: write: "
1186 "recovering from SUSPEND\n");
1188 ret = snd_pcm_oss_prepare(substream);
1194 fs = snd_enter_user();
1195 ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
1198 ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
1200 if (ret != -EPIPE && ret != -ESTRPIPE)
1202 /* test, if we can't store new data, because the stream */
1203 /* has not been started */
1204 if (runtime->status->state == SNDRV_PCM_STATE_PREPARED)
1210 snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *ptr, snd_pcm_uframes_t frames, int in_kernel)
1212 struct snd_pcm_runtime *runtime = substream->runtime;
1213 snd_pcm_sframes_t delay;
1216 if (runtime->status->state == SNDRV_PCM_STATE_XRUN ||
1217 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
1219 if (runtime->status->state == SNDRV_PCM_STATE_XRUN)
1220 printk(KERN_DEBUG "pcm_oss: read: "
1221 "recovering from XRUN\n");
1223 printk(KERN_DEBUG "pcm_oss: read: "
1224 "recovering from SUSPEND\n");
1226 ret = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DRAIN, NULL);
1229 } else if (runtime->status->state == SNDRV_PCM_STATE_SETUP) {
1230 ret = snd_pcm_oss_prepare(substream);
1234 ret = snd_pcm_oss_capture_position_fixup(substream, &delay);
1239 fs = snd_enter_user();
1240 ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
1243 ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
1245 if (ret == -EPIPE) {
1246 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
1247 ret = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);
1253 if (ret != -ESTRPIPE)
1259 snd_pcm_sframes_t snd_pcm_oss_writev3(struct snd_pcm_substream *substream, void **bufs, snd_pcm_uframes_t frames, int in_kernel)
1261 struct snd_pcm_runtime *runtime = substream->runtime;
1264 if (runtime->status->state == SNDRV_PCM_STATE_XRUN ||
1265 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
1267 if (runtime->status->state == SNDRV_PCM_STATE_XRUN)
1268 printk(KERN_DEBUG "pcm_oss: writev: "
1269 "recovering from XRUN\n");
1271 printk(KERN_DEBUG "pcm_oss: writev: "
1272 "recovering from SUSPEND\n");
1274 ret = snd_pcm_oss_prepare(substream);
1280 fs = snd_enter_user();
1281 ret = snd_pcm_lib_writev(substream, (void __user **)bufs, frames);
1284 ret = snd_pcm_lib_writev(substream, (void __user **)bufs, frames);
1286 if (ret != -EPIPE && ret != -ESTRPIPE)
1289 /* test, if we can't store new data, because the stream */
1290 /* has not been started */
1291 if (runtime->status->state == SNDRV_PCM_STATE_PREPARED)
1297 snd_pcm_sframes_t snd_pcm_oss_readv3(struct snd_pcm_substream *substream, void **bufs, snd_pcm_uframes_t frames, int in_kernel)
1299 struct snd_pcm_runtime *runtime = substream->runtime;
1302 if (runtime->status->state == SNDRV_PCM_STATE_XRUN ||
1303 runtime->status->state == SNDRV_PCM_STATE_SUSPENDED) {
1305 if (runtime->status->state == SNDRV_PCM_STATE_XRUN)
1306 printk(KERN_DEBUG "pcm_oss: readv: "
1307 "recovering from XRUN\n");
1309 printk(KERN_DEBUG "pcm_oss: readv: "
1310 "recovering from SUSPEND\n");
1312 ret = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DRAIN, NULL);
1315 } else if (runtime->status->state == SNDRV_PCM_STATE_SETUP) {
1316 ret = snd_pcm_oss_prepare(substream);
1322 fs = snd_enter_user();
1323 ret = snd_pcm_lib_readv(substream, (void __user **)bufs, frames);
1326 ret = snd_pcm_lib_readv(substream, (void __user **)bufs, frames);
1328 if (ret != -EPIPE && ret != -ESTRPIPE)
1334 static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const char *buf, size_t bytes, int in_kernel)
1336 struct snd_pcm_runtime *runtime = substream->runtime;
1337 snd_pcm_sframes_t frames, frames1;
1338 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
1339 if (runtime->oss.plugin_first) {
1340 struct snd_pcm_plugin_channel *channels;
1341 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
1343 if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
1345 buf = runtime->oss.buffer;
1347 frames = bytes / oss_frame_bytes;
1348 frames1 = snd_pcm_plug_client_channels_buf(substream, (char *)buf, frames, &channels);
1351 frames1 = snd_pcm_plug_write_transfer(substream, channels, frames1);
1354 bytes = frames1 * oss_frame_bytes;
1358 frames = bytes_to_frames(runtime, bytes);
1359 frames1 = snd_pcm_oss_write3(substream, buf, frames, in_kernel);
1362 bytes = frames_to_bytes(runtime, frames1);
1367 static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const char __user *buf, size_t bytes)
1371 struct snd_pcm_runtime *runtime = substream->runtime;
1373 if (atomic_read(&substream->mmap_count))
1376 if ((tmp = snd_pcm_oss_make_ready(substream)) < 0)
1379 if (mutex_lock_interruptible(&runtime->oss.params_lock)) {
1383 if (bytes < runtime->oss.period_bytes || runtime->oss.buffer_used > 0) {
1385 if (tmp + runtime->oss.buffer_used > runtime->oss.period_bytes)
1386 tmp = runtime->oss.period_bytes - runtime->oss.buffer_used;
1388 if (copy_from_user(runtime->oss.buffer + runtime->oss.buffer_used, buf, tmp)) {
1393 runtime->oss.buffer_used += tmp;
1397 if (substream->oss.setup.partialfrag ||
1398 runtime->oss.buffer_used == runtime->oss.period_bytes) {
1399 tmp = snd_pcm_oss_write2(substream, runtime->oss.buffer + runtime->oss.period_ptr,
1400 runtime->oss.buffer_used - runtime->oss.period_ptr, 1);
1403 runtime->oss.bytes += tmp;
1404 runtime->oss.period_ptr += tmp;
1405 runtime->oss.period_ptr %= runtime->oss.period_bytes;
1406 if (runtime->oss.period_ptr == 0 ||
1407 runtime->oss.period_ptr == runtime->oss.buffer_used)
1408 runtime->oss.buffer_used = 0;
1409 else if ((substream->f_flags & O_NONBLOCK) != 0) {
1415 tmp = snd_pcm_oss_write2(substream,
1416 (const char __force *)buf,
1417 runtime->oss.period_bytes, 0);
1420 runtime->oss.bytes += tmp;
1424 if ((substream->f_flags & O_NONBLOCK) != 0 &&
1425 tmp != runtime->oss.period_bytes)
1429 mutex_unlock(&runtime->oss.params_lock);
1432 if (signal_pending(current)) {
1438 return xfer > 0 ? (snd_pcm_sframes_t)xfer : tmp;
1441 static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf, size_t bytes, int in_kernel)
1443 struct snd_pcm_runtime *runtime = substream->runtime;
1444 snd_pcm_sframes_t frames, frames1;
1445 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
1446 char __user *final_dst = (char __force __user *)buf;
1447 if (runtime->oss.plugin_first) {
1448 struct snd_pcm_plugin_channel *channels;
1449 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
1451 buf = runtime->oss.buffer;
1452 frames = bytes / oss_frame_bytes;
1453 frames1 = snd_pcm_plug_client_channels_buf(substream, buf, frames, &channels);
1456 frames1 = snd_pcm_plug_read_transfer(substream, channels, frames1);
1459 bytes = frames1 * oss_frame_bytes;
1460 if (!in_kernel && copy_to_user(final_dst, buf, bytes))
1465 frames = bytes_to_frames(runtime, bytes);
1466 frames1 = snd_pcm_oss_read3(substream, buf, frames, in_kernel);
1469 bytes = frames_to_bytes(runtime, frames1);
1474 static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __user *buf, size_t bytes)
1478 struct snd_pcm_runtime *runtime = substream->runtime;
1480 if (atomic_read(&substream->mmap_count))
1483 if ((tmp = snd_pcm_oss_make_ready(substream)) < 0)
1486 if (mutex_lock_interruptible(&runtime->oss.params_lock)) {
1490 if (bytes < runtime->oss.period_bytes || runtime->oss.buffer_used > 0) {
1491 if (runtime->oss.buffer_used == 0) {
1492 tmp = snd_pcm_oss_read2(substream, runtime->oss.buffer, runtime->oss.period_bytes, 1);
1495 runtime->oss.bytes += tmp;
1496 runtime->oss.period_ptr = tmp;
1497 runtime->oss.buffer_used = tmp;
1500 if ((size_t) tmp > runtime->oss.buffer_used)
1501 tmp = runtime->oss.buffer_used;
1502 if (copy_to_user(buf, runtime->oss.buffer + (runtime->oss.period_ptr - runtime->oss.buffer_used), tmp)) {
1509 runtime->oss.buffer_used -= tmp;
1511 tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
1512 runtime->oss.period_bytes, 0);
1515 runtime->oss.bytes += tmp;
1521 mutex_unlock(&runtime->oss.params_lock);
1524 if (signal_pending(current)) {
1530 return xfer > 0 ? (snd_pcm_sframes_t)xfer : tmp;
1533 static int snd_pcm_oss_reset(struct snd_pcm_oss_file *pcm_oss_file)
1535 struct snd_pcm_substream *substream;
1536 struct snd_pcm_runtime *runtime;
1539 for (i = 0; i < 2; i++) {
1540 substream = pcm_oss_file->streams[i];
1543 runtime = substream->runtime;
1544 snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);
1545 runtime->oss.prepare = 1;
1546 runtime->oss.buffer_used = 0;
1547 runtime->oss.prev_hw_ptr_period = 0;
1548 runtime->oss.period_ptr = 0;
1553 static int snd_pcm_oss_post(struct snd_pcm_oss_file *pcm_oss_file)
1555 struct snd_pcm_substream *substream;
1558 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
1559 if (substream != NULL) {
1560 if ((err = snd_pcm_oss_make_ready(substream)) < 0)
1562 snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_START, NULL);
1564 /* note: all errors from the start action are ignored */
1565 /* OSS apps do not know, how to handle them */
1569 static int snd_pcm_oss_sync1(struct snd_pcm_substream *substream, size_t size)
1571 struct snd_pcm_runtime *runtime;
1573 snd_pcm_state_t state;
1577 runtime = substream->runtime;
1578 init_waitqueue_entry(&wait, current);
1579 add_wait_queue(&runtime->sleep, &wait);
1581 printk(KERN_DEBUG "sync1: size = %li\n", size);
1584 result = snd_pcm_oss_write2(substream, runtime->oss.buffer, size, 1);
1586 runtime->oss.buffer_used = 0;
1590 if (result != 0 && result != -EAGAIN)
1593 set_current_state(TASK_INTERRUPTIBLE);
1594 snd_pcm_stream_lock_irq(substream);
1595 state = runtime->status->state;
1596 snd_pcm_stream_unlock_irq(substream);
1597 if (state != SNDRV_PCM_STATE_RUNNING) {
1598 set_current_state(TASK_RUNNING);
1601 res = schedule_timeout(10 * HZ);
1602 if (signal_pending(current)) {
1603 result = -ERESTARTSYS;
1607 snd_printk(KERN_ERR "OSS sync error - DMA timeout\n");
1612 remove_wait_queue(&runtime->sleep, &wait);
1616 static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
1619 unsigned int saved_f_flags;
1620 struct snd_pcm_substream *substream;
1621 struct snd_pcm_runtime *runtime;
1622 snd_pcm_format_t format;
1623 unsigned long width;
1626 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
1627 if (substream != NULL) {
1628 runtime = substream->runtime;
1629 if (atomic_read(&substream->mmap_count))
1631 if ((err = snd_pcm_oss_make_ready(substream)) < 0)
1633 format = snd_pcm_oss_format_from(runtime->oss.format);
1634 width = snd_pcm_format_physical_width(format);
1635 mutex_lock(&runtime->oss.params_lock);
1636 if (runtime->oss.buffer_used > 0) {
1638 printk(KERN_DEBUG "sync: buffer_used\n");
1640 size = (8 * (runtime->oss.period_bytes - runtime->oss.buffer_used) + 7) / width;
1641 snd_pcm_format_set_silence(format,
1642 runtime->oss.buffer + runtime->oss.buffer_used,
1644 err = snd_pcm_oss_sync1(substream, runtime->oss.period_bytes);
1646 mutex_unlock(&runtime->oss.params_lock);
1649 } else if (runtime->oss.period_ptr > 0) {
1651 printk(KERN_DEBUG "sync: period_ptr\n");
1653 size = runtime->oss.period_bytes - runtime->oss.period_ptr;
1654 snd_pcm_format_set_silence(format,
1655 runtime->oss.buffer,
1657 err = snd_pcm_oss_sync1(substream, size);
1659 mutex_unlock(&runtime->oss.params_lock);
1664 * The ALSA's period might be a bit large than OSS one.
1665 * Fill the remain portion of ALSA period with zeros.
1667 size = runtime->control->appl_ptr % runtime->period_size;
1669 size = runtime->period_size - size;
1670 if (runtime->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
1671 size = (runtime->frame_bits * size) / 8;
1674 size_t size1 = size < runtime->oss.period_bytes ? size : runtime->oss.period_bytes;
1677 size1 /= runtime->sample_bits;
1678 snd_pcm_format_set_silence(runtime->format,
1679 runtime->oss.buffer,
1681 size1 /= runtime->channels; /* frames */
1682 fs = snd_enter_user();
1683 snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
1686 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
1687 void __user *buffers[runtime->channels];
1688 memset(buffers, 0, runtime->channels * sizeof(void *));
1689 snd_pcm_lib_writev(substream, buffers, size);
1692 mutex_unlock(&runtime->oss.params_lock);
1694 * finish sync: drain the buffer
1697 saved_f_flags = substream->f_flags;
1698 substream->f_flags &= ~O_NONBLOCK;
1699 err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DRAIN, NULL);
1700 substream->f_flags = saved_f_flags;
1703 runtime->oss.prepare = 1;
1706 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
1707 if (substream != NULL) {
1708 if ((err = snd_pcm_oss_make_ready(substream)) < 0)
1710 runtime = substream->runtime;
1711 err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DROP, NULL);
1714 runtime->oss.buffer_used = 0;
1715 runtime->oss.prepare = 1;
1720 static int snd_pcm_oss_set_rate(struct snd_pcm_oss_file *pcm_oss_file, int rate)
1724 for (idx = 1; idx >= 0; --idx) {
1725 struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
1726 struct snd_pcm_runtime *runtime;
1727 if (substream == NULL)
1729 runtime = substream->runtime;
1732 else if (rate > 192000)
1734 if (runtime->oss.rate != rate) {
1735 runtime->oss.params = 1;
1736 runtime->oss.rate = rate;
1739 return snd_pcm_oss_get_rate(pcm_oss_file);
1742 static int snd_pcm_oss_get_rate(struct snd_pcm_oss_file *pcm_oss_file)
1744 struct snd_pcm_substream *substream;
1747 if ((err = snd_pcm_oss_get_active_substream(pcm_oss_file, &substream)) < 0)
1749 return substream->runtime->oss.rate;
1752 static int snd_pcm_oss_set_channels(struct snd_pcm_oss_file *pcm_oss_file, unsigned int channels)
1759 for (idx = 1; idx >= 0; --idx) {
1760 struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
1761 struct snd_pcm_runtime *runtime;
1762 if (substream == NULL)
1764 runtime = substream->runtime;
1765 if (runtime->oss.channels != channels) {
1766 runtime->oss.params = 1;
1767 runtime->oss.channels = channels;
1770 return snd_pcm_oss_get_channels(pcm_oss_file);
1773 static int snd_pcm_oss_get_channels(struct snd_pcm_oss_file *pcm_oss_file)
1775 struct snd_pcm_substream *substream;
1778 if ((err = snd_pcm_oss_get_active_substream(pcm_oss_file, &substream)) < 0)
1780 return substream->runtime->oss.channels;
1783 static int snd_pcm_oss_get_block_size(struct snd_pcm_oss_file *pcm_oss_file)
1785 struct snd_pcm_substream *substream;
1788 if ((err = snd_pcm_oss_get_active_substream(pcm_oss_file, &substream)) < 0)
1790 return substream->runtime->oss.period_bytes;
1793 static int snd_pcm_oss_get_formats(struct snd_pcm_oss_file *pcm_oss_file)
1795 struct snd_pcm_substream *substream;
1798 struct snd_pcm_hw_params *params;
1799 unsigned int formats = 0;
1800 struct snd_mask format_mask;
1803 if ((err = snd_pcm_oss_get_active_substream(pcm_oss_file, &substream)) < 0)
1805 if (atomic_read(&substream->mmap_count))
1808 direct = substream->oss.setup.direct;
1810 return AFMT_MU_LAW | AFMT_U8 |
1811 AFMT_S16_LE | AFMT_S16_BE |
1812 AFMT_S8 | AFMT_U16_LE |
1814 AFMT_S32_LE | AFMT_S32_BE |
1815 AFMT_S24_LE | AFMT_S24_BE |
1817 params = kmalloc(sizeof(*params), GFP_KERNEL);
1820 _snd_pcm_hw_params_any(params);
1821 err = snd_pcm_hw_refine(substream, params);
1822 format_mask = *hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
1826 for (fmt = 0; fmt < 32; ++fmt) {
1827 if (snd_mask_test(&format_mask, fmt)) {
1828 int f = snd_pcm_oss_format_to(fmt);
1836 static int snd_pcm_oss_set_format(struct snd_pcm_oss_file *pcm_oss_file, int format)
1840 if (format != AFMT_QUERY) {
1841 formats = snd_pcm_oss_get_formats(pcm_oss_file);
1844 if (!(formats & format))
1846 for (idx = 1; idx >= 0; --idx) {
1847 struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
1848 struct snd_pcm_runtime *runtime;
1849 if (substream == NULL)
1851 runtime = substream->runtime;
1852 if (runtime->oss.format != format) {
1853 runtime->oss.params = 1;
1854 runtime->oss.format = format;
1858 return snd_pcm_oss_get_format(pcm_oss_file);
1861 static int snd_pcm_oss_get_format(struct snd_pcm_oss_file *pcm_oss_file)
1863 struct snd_pcm_substream *substream;
1866 if ((err = snd_pcm_oss_get_active_substream(pcm_oss_file, &substream)) < 0)
1868 return substream->runtime->oss.format;
1871 static int snd_pcm_oss_set_subdivide1(struct snd_pcm_substream *substream, int subdivide)
1873 struct snd_pcm_runtime *runtime;
1875 if (substream == NULL)
1877 runtime = substream->runtime;
1878 if (subdivide == 0) {
1879 subdivide = runtime->oss.subdivision;
1884 if (runtime->oss.subdivision || runtime->oss.fragshift)
1886 if (subdivide != 1 && subdivide != 2 && subdivide != 4 &&
1887 subdivide != 8 && subdivide != 16)
1889 runtime->oss.subdivision = subdivide;
1890 runtime->oss.params = 1;
1894 static int snd_pcm_oss_set_subdivide(struct snd_pcm_oss_file *pcm_oss_file, int subdivide)
1896 int err = -EINVAL, idx;
1898 for (idx = 1; idx >= 0; --idx) {
1899 struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
1900 if (substream == NULL)
1902 if ((err = snd_pcm_oss_set_subdivide1(substream, subdivide)) < 0)
1908 static int snd_pcm_oss_set_fragment1(struct snd_pcm_substream *substream, unsigned int val)
1910 struct snd_pcm_runtime *runtime;
1912 if (substream == NULL)
1914 runtime = substream->runtime;
1915 if (runtime->oss.subdivision || runtime->oss.fragshift)
1917 runtime->oss.fragshift = val & 0xffff;
1918 runtime->oss.maxfrags = (val >> 16) & 0xffff;
1919 if (runtime->oss.fragshift < 4) /* < 16 */
1920 runtime->oss.fragshift = 4;
1921 if (runtime->oss.maxfrags < 2)
1922 runtime->oss.maxfrags = 2;
1923 runtime->oss.params = 1;
1927 static int snd_pcm_oss_set_fragment(struct snd_pcm_oss_file *pcm_oss_file, unsigned int val)
1929 int err = -EINVAL, idx;
1931 for (idx = 1; idx >= 0; --idx) {
1932 struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
1933 if (substream == NULL)
1935 if ((err = snd_pcm_oss_set_fragment1(substream, val)) < 0)
1941 static int snd_pcm_oss_nonblock(struct file * file)
1943 spin_lock(&file->f_lock);
1944 file->f_flags |= O_NONBLOCK;
1945 spin_unlock(&file->f_lock);
1949 static int snd_pcm_oss_get_caps1(struct snd_pcm_substream *substream, int res)
1952 if (substream == NULL) {
1953 res &= ~DSP_CAP_DUPLEX;
1956 #ifdef DSP_CAP_MULTI
1957 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1958 if (substream->pstr->substream_count > 1)
1959 res |= DSP_CAP_MULTI;
1961 /* DSP_CAP_REALTIME is set all times: */
1962 /* all ALSA drivers can return actual pointer in ring buffer */
1963 #if defined(DSP_CAP_REALTIME) && 0
1965 struct snd_pcm_runtime *runtime = substream->runtime;
1966 if (runtime->info & (SNDRV_PCM_INFO_BLOCK_TRANSFER|SNDRV_PCM_INFO_BATCH))
1967 res &= ~DSP_CAP_REALTIME;
1973 static int snd_pcm_oss_get_caps(struct snd_pcm_oss_file *pcm_oss_file)
1977 result = DSP_CAP_TRIGGER | DSP_CAP_MMAP | DSP_CAP_DUPLEX | DSP_CAP_REALTIME;
1978 for (idx = 0; idx < 2; idx++) {
1979 struct snd_pcm_substream *substream = pcm_oss_file->streams[idx];
1980 result = snd_pcm_oss_get_caps1(substream, result);
1982 result |= 0x0001; /* revision - same as SB AWE 64 */
1986 static void snd_pcm_oss_simulate_fill(struct snd_pcm_substream *substream,
1987 snd_pcm_uframes_t hw_ptr)
1989 struct snd_pcm_runtime *runtime = substream->runtime;
1990 snd_pcm_uframes_t appl_ptr;
1991 appl_ptr = hw_ptr + runtime->buffer_size;
1992 appl_ptr %= runtime->boundary;
1993 runtime->control->appl_ptr = appl_ptr;
1996 static int snd_pcm_oss_set_trigger(struct snd_pcm_oss_file *pcm_oss_file, int trigger)
1998 struct snd_pcm_runtime *runtime;
1999 struct snd_pcm_substream *psubstream = NULL, *csubstream = NULL;
2003 printk(KERN_DEBUG "pcm_oss: trigger = 0x%x\n", trigger);
2006 psubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
2007 csubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
2010 if ((err = snd_pcm_oss_make_ready(psubstream)) < 0)
2014 if ((err = snd_pcm_oss_make_ready(csubstream)) < 0)
2018 runtime = psubstream->runtime;
2019 if (trigger & PCM_ENABLE_OUTPUT) {
2020 if (runtime->oss.trigger)
2022 if (atomic_read(&psubstream->mmap_count))
2023 snd_pcm_oss_simulate_fill(psubstream,
2024 get_hw_ptr_period(runtime));
2025 runtime->oss.trigger = 1;
2026 runtime->start_threshold = 1;
2027 cmd = SNDRV_PCM_IOCTL_START;
2029 if (!runtime->oss.trigger)
2031 runtime->oss.trigger = 0;
2032 runtime->start_threshold = runtime->boundary;
2033 cmd = SNDRV_PCM_IOCTL_DROP;
2034 runtime->oss.prepare = 1;
2036 err = snd_pcm_kernel_ioctl(psubstream, cmd, NULL);
2042 runtime = csubstream->runtime;
2043 if (trigger & PCM_ENABLE_INPUT) {
2044 if (runtime->oss.trigger)
2046 runtime->oss.trigger = 1;
2047 runtime->start_threshold = 1;
2048 cmd = SNDRV_PCM_IOCTL_START;
2050 if (!runtime->oss.trigger)
2052 runtime->oss.trigger = 0;
2053 runtime->start_threshold = runtime->boundary;
2054 cmd = SNDRV_PCM_IOCTL_DROP;
2055 runtime->oss.prepare = 1;
2057 err = snd_pcm_kernel_ioctl(csubstream, cmd, NULL);
2065 static int snd_pcm_oss_get_trigger(struct snd_pcm_oss_file *pcm_oss_file)
2067 struct snd_pcm_substream *psubstream = NULL, *csubstream = NULL;
2070 psubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
2071 csubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
2072 if (psubstream && psubstream->runtime && psubstream->runtime->oss.trigger)
2073 result |= PCM_ENABLE_OUTPUT;
2074 if (csubstream && csubstream->runtime && csubstream->runtime->oss.trigger)
2075 result |= PCM_ENABLE_INPUT;
2079 static int snd_pcm_oss_get_odelay(struct snd_pcm_oss_file *pcm_oss_file)
2081 struct snd_pcm_substream *substream;
2082 struct snd_pcm_runtime *runtime;
2083 snd_pcm_sframes_t delay;
2086 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
2087 if (substream == NULL)
2089 if ((err = snd_pcm_oss_make_ready(substream)) < 0)
2091 runtime = substream->runtime;
2092 if (runtime->oss.params || runtime->oss.prepare)
2094 err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DELAY, &delay);
2096 delay = 0; /* hack for broken OSS applications */
2099 return snd_pcm_oss_bytes(substream, delay);
2102 static int snd_pcm_oss_get_ptr(struct snd_pcm_oss_file *pcm_oss_file, int stream, struct count_info __user * _info)
2104 struct snd_pcm_substream *substream;
2105 struct snd_pcm_runtime *runtime;
2106 snd_pcm_sframes_t delay;
2108 struct count_info info;
2113 substream = pcm_oss_file->streams[stream];
2114 if (substream == NULL)
2116 if ((err = snd_pcm_oss_make_ready(substream)) < 0)
2118 runtime = substream->runtime;
2119 if (runtime->oss.params || runtime->oss.prepare) {
2120 memset(&info, 0, sizeof(info));
2121 if (copy_to_user(_info, &info, sizeof(info)))
2125 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
2126 err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DELAY, &delay);
2127 if (err == -EPIPE || err == -ESTRPIPE || (! err && delay < 0)) {
2132 fixup = runtime->oss.buffer_used;
2135 err = snd_pcm_oss_capture_position_fixup(substream, &delay);
2136 fixup = -runtime->oss.buffer_used;
2140 info.ptr = snd_pcm_oss_bytes(substream, runtime->status->hw_ptr % runtime->buffer_size);
2141 if (atomic_read(&substream->mmap_count)) {
2142 snd_pcm_sframes_t n;
2143 delay = get_hw_ptr_period(runtime);
2144 n = delay - runtime->oss.prev_hw_ptr_period;
2146 n += runtime->boundary;
2147 info.blocks = n / runtime->period_size;
2148 runtime->oss.prev_hw_ptr_period = delay;
2149 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
2150 snd_pcm_oss_simulate_fill(substream, delay);
2151 info.bytes = snd_pcm_oss_bytes(substream, runtime->status->hw_ptr) & INT_MAX;
2153 delay = snd_pcm_oss_bytes(substream, delay);
2154 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
2155 if (substream->oss.setup.buggyptr)
2156 info.blocks = (runtime->oss.buffer_bytes - delay - fixup) / runtime->oss.period_bytes;
2158 info.blocks = (delay + fixup) / runtime->oss.period_bytes;
2159 info.bytes = (runtime->oss.bytes - delay) & INT_MAX;
2162 info.blocks = delay / runtime->oss.period_bytes;
2163 info.bytes = (runtime->oss.bytes + delay) & INT_MAX;
2166 if (copy_to_user(_info, &info, sizeof(info)))
2171 static int snd_pcm_oss_get_space(struct snd_pcm_oss_file *pcm_oss_file, int stream, struct audio_buf_info __user *_info)
2173 struct snd_pcm_substream *substream;
2174 struct snd_pcm_runtime *runtime;
2175 snd_pcm_sframes_t avail;
2177 struct audio_buf_info info;
2182 substream = pcm_oss_file->streams[stream];
2183 if (substream == NULL)
2185 runtime = substream->runtime;
2187 if (runtime->oss.params &&
2188 (err = snd_pcm_oss_change_params(substream, false)) < 0)
2191 info.fragsize = runtime->oss.period_bytes;
2192 info.fragstotal = runtime->periods;
2193 if (runtime->oss.prepare) {
2194 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
2195 info.bytes = runtime->oss.period_bytes * runtime->oss.periods;
2196 info.fragments = runtime->oss.periods;
2202 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
2203 err = snd_pcm_kernel_ioctl(substream, SNDRV_PCM_IOCTL_DELAY, &avail);
2204 if (err == -EPIPE || err == -ESTRPIPE || (! err && avail < 0)) {
2205 avail = runtime->buffer_size;
2209 avail = runtime->buffer_size - avail;
2210 fixup = -runtime->oss.buffer_used;
2213 err = snd_pcm_oss_capture_position_fixup(substream, &avail);
2214 fixup = runtime->oss.buffer_used;
2218 info.bytes = snd_pcm_oss_bytes(substream, avail) + fixup;
2219 info.fragments = info.bytes / runtime->oss.period_bytes;
2223 printk(KERN_DEBUG "pcm_oss: space: bytes = %i, fragments = %i, "
2224 "fragstotal = %i, fragsize = %i\n",
2225 info.bytes, info.fragments, info.fragstotal, info.fragsize);
2227 if (copy_to_user(_info, &info, sizeof(info)))
2232 static int snd_pcm_oss_get_mapbuf(struct snd_pcm_oss_file *pcm_oss_file, int stream, struct buffmem_desc __user * _info)
2234 // it won't be probably implemented
2235 // snd_printd("TODO: snd_pcm_oss_get_mapbuf\n");
2239 static const char *strip_task_path(const char *path)
2241 const char *ptr, *ptrl = NULL;
2242 for (ptr = path; *ptr; ptr++) {
2249 static void snd_pcm_oss_look_for_setup(struct snd_pcm *pcm, int stream,
2250 const char *task_name,
2251 struct snd_pcm_oss_setup *rsetup)
2253 struct snd_pcm_oss_setup *setup;
2255 mutex_lock(&pcm->streams[stream].oss.setup_mutex);
2257 for (setup = pcm->streams[stream].oss.setup_list; setup;
2258 setup = setup->next) {
2259 if (!strcmp(setup->task_name, task_name))
2262 } while ((task_name = strip_task_path(task_name)) != NULL);
2266 mutex_unlock(&pcm->streams[stream].oss.setup_mutex);
2269 static void snd_pcm_oss_release_substream(struct snd_pcm_substream *substream)
2271 struct snd_pcm_runtime *runtime;
2272 runtime = substream->runtime;
2273 vfree(runtime->oss.buffer);
2274 runtime->oss.buffer = NULL;
2275 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
2276 snd_pcm_oss_plugin_clear(substream);
2278 substream->oss.oss = 0;
2281 static void snd_pcm_oss_init_substream(struct snd_pcm_substream *substream,
2282 struct snd_pcm_oss_setup *setup,
2285 struct snd_pcm_runtime *runtime;
2287 substream->oss.oss = 1;
2288 substream->oss.setup = *setup;
2289 if (setup->nonblock)
2290 substream->f_flags |= O_NONBLOCK;
2291 else if (setup->block)
2292 substream->f_flags &= ~O_NONBLOCK;
2293 runtime = substream->runtime;
2294 runtime->oss.params = 1;
2295 runtime->oss.trigger = 1;
2296 runtime->oss.rate = 8000;
2297 mutex_init(&runtime->oss.params_lock);
2298 switch (SNDRV_MINOR_OSS_DEVICE(minor)) {
2299 case SNDRV_MINOR_OSS_PCM_8:
2300 runtime->oss.format = AFMT_U8;
2302 case SNDRV_MINOR_OSS_PCM_16:
2303 runtime->oss.format = AFMT_S16_LE;
2306 runtime->oss.format = AFMT_MU_LAW;
2308 runtime->oss.channels = 1;
2309 runtime->oss.fragshift = 0;
2310 runtime->oss.maxfrags = 0;
2311 runtime->oss.subdivision = 0;
2312 substream->pcm_release = snd_pcm_oss_release_substream;
2315 static int snd_pcm_oss_release_file(struct snd_pcm_oss_file *pcm_oss_file)
2320 for (cidx = 0; cidx < 2; ++cidx) {
2321 struct snd_pcm_substream *substream = pcm_oss_file->streams[cidx];
2323 snd_pcm_release_substream(substream);
2325 kfree(pcm_oss_file);
2329 static int snd_pcm_oss_open_file(struct file *file,
2330 struct snd_pcm *pcm,
2331 struct snd_pcm_oss_file **rpcm_oss_file,
2333 struct snd_pcm_oss_setup *setup)
2336 struct snd_pcm_oss_file *pcm_oss_file;
2337 struct snd_pcm_substream *substream;
2338 fmode_t f_mode = file->f_mode;
2341 *rpcm_oss_file = NULL;
2343 pcm_oss_file = kzalloc(sizeof(*pcm_oss_file), GFP_KERNEL);
2344 if (pcm_oss_file == NULL)
2347 if ((f_mode & (FMODE_WRITE|FMODE_READ)) == (FMODE_WRITE|FMODE_READ) &&
2348 (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX))
2349 f_mode = FMODE_WRITE;
2351 file->f_flags &= ~O_APPEND;
2352 for (idx = 0; idx < 2; idx++) {
2353 if (setup[idx].disable)
2355 if (! pcm->streams[idx].substream_count)
2356 continue; /* no matching substream */
2357 if (idx == SNDRV_PCM_STREAM_PLAYBACK) {
2358 if (! (f_mode & FMODE_WRITE))
2361 if (! (f_mode & FMODE_READ))
2364 err = snd_pcm_open_substream(pcm, idx, file, &substream);
2366 snd_pcm_oss_release_file(pcm_oss_file);
2370 pcm_oss_file->streams[idx] = substream;
2371 substream->file = pcm_oss_file;
2372 snd_pcm_oss_init_substream(substream, &setup[idx], minor);
2375 if (!pcm_oss_file->streams[0] && !pcm_oss_file->streams[1]) {
2376 snd_pcm_oss_release_file(pcm_oss_file);
2380 file->private_data = pcm_oss_file;
2382 *rpcm_oss_file = pcm_oss_file;
2387 static int snd_task_name(struct task_struct *task, char *name, size_t size)
2391 if (snd_BUG_ON(!task || !name || size < 2))
2393 for (idx = 0; idx < sizeof(task->comm) && idx + 1 < size; idx++)
2394 name[idx] = task->comm[idx];
2399 static int snd_pcm_oss_open(struct inode *inode, struct file *file)
2403 struct snd_pcm *pcm;
2404 struct snd_pcm_oss_file *pcm_oss_file;
2405 struct snd_pcm_oss_setup setup[2];
2409 err = nonseekable_open(inode, file);
2413 pcm = snd_lookup_oss_minor_data(iminor(inode),
2414 SNDRV_OSS_DEVICE_TYPE_PCM);
2419 err = snd_card_file_add(pcm->card, file);
2422 if (!try_module_get(pcm->card->module)) {
2426 if (snd_task_name(current, task_name, sizeof(task_name)) < 0) {
2430 memset(setup, 0, sizeof(setup));
2431 if (file->f_mode & FMODE_WRITE)
2432 snd_pcm_oss_look_for_setup(pcm, SNDRV_PCM_STREAM_PLAYBACK,
2433 task_name, &setup[0]);
2434 if (file->f_mode & FMODE_READ)
2435 snd_pcm_oss_look_for_setup(pcm, SNDRV_PCM_STREAM_CAPTURE,
2436 task_name, &setup[1]);
2438 nonblock = !!(file->f_flags & O_NONBLOCK);
2440 nonblock = nonblock_open;
2442 init_waitqueue_entry(&wait, current);
2443 add_wait_queue(&pcm->open_wait, &wait);
2444 mutex_lock(&pcm->open_mutex);
2446 err = snd_pcm_oss_open_file(file, pcm, &pcm_oss_file,
2447 iminor(inode), setup);
2450 if (err == -EAGAIN) {
2457 set_current_state(TASK_INTERRUPTIBLE);
2458 mutex_unlock(&pcm->open_mutex);
2460 mutex_lock(&pcm->open_mutex);
2461 if (pcm->card->shutdown) {
2465 if (signal_pending(current)) {
2470 remove_wait_queue(&pcm->open_wait, &wait);
2471 mutex_unlock(&pcm->open_mutex);
2474 snd_card_unref(pcm->card);
2478 module_put(pcm->card->module);
2480 snd_card_file_remove(pcm->card, file);
2483 snd_card_unref(pcm->card);
2487 static int snd_pcm_oss_release(struct inode *inode, struct file *file)
2489 struct snd_pcm *pcm;
2490 struct snd_pcm_substream *substream;
2491 struct snd_pcm_oss_file *pcm_oss_file;
2493 pcm_oss_file = file->private_data;
2494 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
2495 if (substream == NULL)
2496 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
2497 if (snd_BUG_ON(!substream))
2499 pcm = substream->pcm;
2500 if (!pcm->card->shutdown)
2501 snd_pcm_oss_sync(pcm_oss_file);
2502 mutex_lock(&pcm->open_mutex);
2503 snd_pcm_oss_release_file(pcm_oss_file);
2504 mutex_unlock(&pcm->open_mutex);
2505 wake_up(&pcm->open_wait);
2506 module_put(pcm->card->module);
2507 snd_card_file_remove(pcm->card, file);
2511 static long snd_pcm_oss_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
2513 struct snd_pcm_oss_file *pcm_oss_file;
2514 int __user *p = (int __user *)arg;
2517 pcm_oss_file = file->private_data;
2518 if (cmd == OSS_GETVERSION)
2519 return put_user(SNDRV_OSS_VERSION, p);
2520 if (cmd == OSS_ALSAEMULVER)
2521 return put_user(1, p);
2522 #if defined(CONFIG_SND_MIXER_OSS) || (defined(MODULE) && defined(CONFIG_SND_MIXER_OSS_MODULE))
2523 if (((cmd >> 8) & 0xff) == 'M') { /* mixer ioctl - for OSS compatibility */
2524 struct snd_pcm_substream *substream;
2526 for (idx = 0; idx < 2; ++idx) {
2527 substream = pcm_oss_file->streams[idx];
2528 if (substream != NULL)
2531 if (snd_BUG_ON(idx >= 2))
2533 return snd_mixer_oss_ioctl_card(substream->pcm->card, cmd, arg);
2536 if (((cmd >> 8) & 0xff) != 'P')
2539 printk(KERN_DEBUG "pcm_oss: ioctl = 0x%x\n", cmd);
2542 case SNDCTL_DSP_RESET:
2543 return snd_pcm_oss_reset(pcm_oss_file);
2544 case SNDCTL_DSP_SYNC:
2545 return snd_pcm_oss_sync(pcm_oss_file);
2546 case SNDCTL_DSP_SPEED:
2547 if (get_user(res, p))
2549 if ((res = snd_pcm_oss_set_rate(pcm_oss_file, res))<0)
2551 return put_user(res, p);
2552 case SOUND_PCM_READ_RATE:
2553 res = snd_pcm_oss_get_rate(pcm_oss_file);
2556 return put_user(res, p);
2557 case SNDCTL_DSP_STEREO:
2558 if (get_user(res, p))
2560 res = res > 0 ? 2 : 1;
2561 if ((res = snd_pcm_oss_set_channels(pcm_oss_file, res)) < 0)
2563 return put_user(--res, p);
2564 case SNDCTL_DSP_GETBLKSIZE:
2565 res = snd_pcm_oss_get_block_size(pcm_oss_file);
2568 return put_user(res, p);
2569 case SNDCTL_DSP_SETFMT:
2570 if (get_user(res, p))
2572 res = snd_pcm_oss_set_format(pcm_oss_file, res);
2575 return put_user(res, p);
2576 case SOUND_PCM_READ_BITS:
2577 res = snd_pcm_oss_get_format(pcm_oss_file);
2580 return put_user(res, p);
2581 case SNDCTL_DSP_CHANNELS:
2582 if (get_user(res, p))
2584 res = snd_pcm_oss_set_channels(pcm_oss_file, res);
2587 return put_user(res, p);
2588 case SOUND_PCM_READ_CHANNELS:
2589 res = snd_pcm_oss_get_channels(pcm_oss_file);
2592 return put_user(res, p);
2593 case SOUND_PCM_WRITE_FILTER:
2594 case SOUND_PCM_READ_FILTER:
2596 case SNDCTL_DSP_POST:
2597 return snd_pcm_oss_post(pcm_oss_file);
2598 case SNDCTL_DSP_SUBDIVIDE:
2599 if (get_user(res, p))
2601 res = snd_pcm_oss_set_subdivide(pcm_oss_file, res);
2604 return put_user(res, p);
2605 case SNDCTL_DSP_SETFRAGMENT:
2606 if (get_user(res, p))
2608 return snd_pcm_oss_set_fragment(pcm_oss_file, res);
2609 case SNDCTL_DSP_GETFMTS:
2610 res = snd_pcm_oss_get_formats(pcm_oss_file);
2613 return put_user(res, p);
2614 case SNDCTL_DSP_GETOSPACE:
2615 case SNDCTL_DSP_GETISPACE:
2616 return snd_pcm_oss_get_space(pcm_oss_file,
2617 cmd == SNDCTL_DSP_GETISPACE ?
2618 SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK,
2619 (struct audio_buf_info __user *) arg);
2620 case SNDCTL_DSP_NONBLOCK:
2621 return snd_pcm_oss_nonblock(file);
2622 case SNDCTL_DSP_GETCAPS:
2623 res = snd_pcm_oss_get_caps(pcm_oss_file);
2626 return put_user(res, p);
2627 case SNDCTL_DSP_GETTRIGGER:
2628 res = snd_pcm_oss_get_trigger(pcm_oss_file);
2631 return put_user(res, p);
2632 case SNDCTL_DSP_SETTRIGGER:
2633 if (get_user(res, p))
2635 return snd_pcm_oss_set_trigger(pcm_oss_file, res);
2636 case SNDCTL_DSP_GETIPTR:
2637 case SNDCTL_DSP_GETOPTR:
2638 return snd_pcm_oss_get_ptr(pcm_oss_file,
2639 cmd == SNDCTL_DSP_GETIPTR ?
2640 SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK,
2641 (struct count_info __user *) arg);
2642 case SNDCTL_DSP_MAPINBUF:
2643 case SNDCTL_DSP_MAPOUTBUF:
2644 return snd_pcm_oss_get_mapbuf(pcm_oss_file,
2645 cmd == SNDCTL_DSP_MAPINBUF ?
2646 SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK,
2647 (struct buffmem_desc __user *) arg);
2648 case SNDCTL_DSP_SETSYNCRO:
2649 /* stop DMA now.. */
2651 case SNDCTL_DSP_SETDUPLEX:
2652 if (snd_pcm_oss_get_caps(pcm_oss_file) & DSP_CAP_DUPLEX)
2655 case SNDCTL_DSP_GETODELAY:
2656 res = snd_pcm_oss_get_odelay(pcm_oss_file);
2658 /* it's for sure, some broken apps don't check for error codes */
2662 return put_user(res, p);
2663 case SNDCTL_DSP_PROFILE:
2664 return 0; /* silently ignore */
2666 snd_printd("pcm_oss: unknown command = 0x%x\n", cmd);
2671 #ifdef CONFIG_COMPAT
2672 /* all compatible */
2673 #define snd_pcm_oss_ioctl_compat snd_pcm_oss_ioctl
2675 #define snd_pcm_oss_ioctl_compat NULL
2678 static ssize_t snd_pcm_oss_read(struct file *file, char __user *buf, size_t count, loff_t *offset)
2680 struct snd_pcm_oss_file *pcm_oss_file;
2681 struct snd_pcm_substream *substream;
2683 pcm_oss_file = file->private_data;
2684 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
2685 if (substream == NULL)
2687 substream->f_flags = file->f_flags & O_NONBLOCK;
2689 return snd_pcm_oss_read1(substream, buf, count);
2692 ssize_t res = snd_pcm_oss_read1(substream, buf, count);
2693 printk(KERN_DEBUG "pcm_oss: read %li bytes "
2694 "(returned %li bytes)\n", (long)count, (long)res);
2700 static ssize_t snd_pcm_oss_write(struct file *file, const char __user *buf, size_t count, loff_t *offset)
2702 struct snd_pcm_oss_file *pcm_oss_file;
2703 struct snd_pcm_substream *substream;
2706 pcm_oss_file = file->private_data;
2707 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
2708 if (substream == NULL)
2710 substream->f_flags = file->f_flags & O_NONBLOCK;
2711 result = snd_pcm_oss_write1(substream, buf, count);
2713 printk(KERN_DEBUG "pcm_oss: write %li bytes (wrote %li bytes)\n",
2714 (long)count, (long)result);
2719 static int snd_pcm_oss_playback_ready(struct snd_pcm_substream *substream)
2721 struct snd_pcm_runtime *runtime = substream->runtime;
2722 if (atomic_read(&substream->mmap_count))
2723 return runtime->oss.prev_hw_ptr_period !=
2724 get_hw_ptr_period(runtime);
2726 return snd_pcm_playback_avail(runtime) >=
2727 runtime->oss.period_frames;
2730 static int snd_pcm_oss_capture_ready(struct snd_pcm_substream *substream)
2732 struct snd_pcm_runtime *runtime = substream->runtime;
2733 if (atomic_read(&substream->mmap_count))
2734 return runtime->oss.prev_hw_ptr_period !=
2735 get_hw_ptr_period(runtime);
2737 return snd_pcm_capture_avail(runtime) >=
2738 runtime->oss.period_frames;
2741 static unsigned int snd_pcm_oss_poll(struct file *file, poll_table * wait)
2743 struct snd_pcm_oss_file *pcm_oss_file;
2745 struct snd_pcm_substream *psubstream = NULL, *csubstream = NULL;
2747 pcm_oss_file = file->private_data;
2749 psubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
2750 csubstream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
2753 if (psubstream != NULL) {
2754 struct snd_pcm_runtime *runtime = psubstream->runtime;
2755 poll_wait(file, &runtime->sleep, wait);
2756 snd_pcm_stream_lock_irq(psubstream);
2757 if (runtime->status->state != SNDRV_PCM_STATE_DRAINING &&
2758 (runtime->status->state != SNDRV_PCM_STATE_RUNNING ||
2759 snd_pcm_oss_playback_ready(psubstream)))
2760 mask |= POLLOUT | POLLWRNORM;
2761 snd_pcm_stream_unlock_irq(psubstream);
2763 if (csubstream != NULL) {
2764 struct snd_pcm_runtime *runtime = csubstream->runtime;
2765 snd_pcm_state_t ostate;
2766 poll_wait(file, &runtime->sleep, wait);
2767 snd_pcm_stream_lock_irq(csubstream);
2768 if ((ostate = runtime->status->state) != SNDRV_PCM_STATE_RUNNING ||
2769 snd_pcm_oss_capture_ready(csubstream))
2770 mask |= POLLIN | POLLRDNORM;
2771 snd_pcm_stream_unlock_irq(csubstream);
2772 if (ostate != SNDRV_PCM_STATE_RUNNING && runtime->oss.trigger) {
2773 struct snd_pcm_oss_file ofile;
2774 memset(&ofile, 0, sizeof(ofile));
2775 ofile.streams[SNDRV_PCM_STREAM_CAPTURE] = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
2776 runtime->oss.trigger = 0;
2777 snd_pcm_oss_set_trigger(&ofile, PCM_ENABLE_INPUT);
2784 static int snd_pcm_oss_mmap(struct file *file, struct vm_area_struct *area)
2786 struct snd_pcm_oss_file *pcm_oss_file;
2787 struct snd_pcm_substream *substream = NULL;
2788 struct snd_pcm_runtime *runtime;
2792 printk(KERN_DEBUG "pcm_oss: mmap begin\n");
2794 pcm_oss_file = file->private_data;
2795 switch ((area->vm_flags & (VM_READ | VM_WRITE))) {
2796 case VM_READ | VM_WRITE:
2797 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
2802 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_CAPTURE];
2805 substream = pcm_oss_file->streams[SNDRV_PCM_STREAM_PLAYBACK];
2810 /* set VM_READ access as well to fix memset() routines that do
2811 reads before writes (to improve performance) */
2812 area->vm_flags |= VM_READ;
2813 if (substream == NULL)
2815 runtime = substream->runtime;
2816 if (!(runtime->info & SNDRV_PCM_INFO_MMAP_VALID))
2818 if (runtime->info & SNDRV_PCM_INFO_INTERLEAVED)
2819 runtime->access = SNDRV_PCM_ACCESS_MMAP_INTERLEAVED;
2823 if (runtime->oss.params) {
2824 /* use mutex_trylock() for params_lock for avoiding a deadlock
2825 * between mmap_sem and params_lock taken by
2826 * copy_from/to_user() in snd_pcm_oss_write/read()
2828 err = snd_pcm_oss_change_params(substream, true);
2832 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
2833 if (runtime->oss.plugin_first != NULL)
2837 if (area->vm_pgoff != 0)
2840 err = snd_pcm_mmap_data(substream, file, area);
2843 runtime->oss.mmap_bytes = area->vm_end - area->vm_start;
2844 runtime->silence_threshold = 0;
2845 runtime->silence_size = 0;
2847 printk(KERN_DEBUG "pcm_oss: mmap ok, bytes = 0x%x\n",
2848 runtime->oss.mmap_bytes);
2850 /* In mmap mode we never stop */
2851 runtime->stop_threshold = runtime->boundary;
2856 #ifdef CONFIG_SND_VERBOSE_PROCFS
2861 static void snd_pcm_oss_proc_read(struct snd_info_entry *entry,
2862 struct snd_info_buffer *buffer)
2864 struct snd_pcm_str *pstr = entry->private_data;
2865 struct snd_pcm_oss_setup *setup = pstr->oss.setup_list;
2866 mutex_lock(&pstr->oss.setup_mutex);
2868 snd_iprintf(buffer, "%s %u %u%s%s%s%s%s%s\n",
2872 setup->disable ? " disable" : "",
2873 setup->direct ? " direct" : "",
2874 setup->block ? " block" : "",
2875 setup->nonblock ? " non-block" : "",
2876 setup->partialfrag ? " partial-frag" : "",
2877 setup->nosilence ? " no-silence" : "");
2878 setup = setup->next;
2880 mutex_unlock(&pstr->oss.setup_mutex);
2883 static void snd_pcm_oss_proc_free_setup_list(struct snd_pcm_str * pstr)
2885 struct snd_pcm_oss_setup *setup, *setupn;
2887 for (setup = pstr->oss.setup_list, pstr->oss.setup_list = NULL;
2888 setup; setup = setupn) {
2889 setupn = setup->next;
2890 kfree(setup->task_name);
2893 pstr->oss.setup_list = NULL;
2896 static void snd_pcm_oss_proc_write(struct snd_info_entry *entry,
2897 struct snd_info_buffer *buffer)
2899 struct snd_pcm_str *pstr = entry->private_data;
2900 char line[128], str[32], task_name[32];
2903 struct snd_pcm_oss_setup *setup, *setup1, template;
2905 while (!snd_info_get_line(buffer, line, sizeof(line))) {
2906 mutex_lock(&pstr->oss.setup_mutex);
2907 memset(&template, 0, sizeof(template));
2908 ptr = snd_info_get_str(task_name, line, sizeof(task_name));
2909 if (!strcmp(task_name, "clear") || !strcmp(task_name, "erase")) {
2910 snd_pcm_oss_proc_free_setup_list(pstr);
2911 mutex_unlock(&pstr->oss.setup_mutex);
2914 for (setup = pstr->oss.setup_list; setup; setup = setup->next) {
2915 if (!strcmp(setup->task_name, task_name)) {
2920 ptr = snd_info_get_str(str, ptr, sizeof(str));
2921 template.periods = simple_strtoul(str, NULL, 10);
2922 ptr = snd_info_get_str(str, ptr, sizeof(str));
2923 template.period_size = simple_strtoul(str, NULL, 10);
2924 for (idx1 = 31; idx1 >= 0; idx1--)
2925 if (template.period_size & (1 << idx1))
2927 for (idx1--; idx1 >= 0; idx1--)
2928 template.period_size &= ~(1 << idx1);
2930 ptr = snd_info_get_str(str, ptr, sizeof(str));
2931 if (!strcmp(str, "disable")) {
2932 template.disable = 1;
2933 } else if (!strcmp(str, "direct")) {
2934 template.direct = 1;
2935 } else if (!strcmp(str, "block")) {
2937 } else if (!strcmp(str, "non-block")) {
2938 template.nonblock = 1;
2939 } else if (!strcmp(str, "partial-frag")) {
2940 template.partialfrag = 1;
2941 } else if (!strcmp(str, "no-silence")) {
2942 template.nosilence = 1;
2943 } else if (!strcmp(str, "buggy-ptr")) {
2944 template.buggyptr = 1;
2947 if (setup == NULL) {
2948 setup = kmalloc(sizeof(*setup), GFP_KERNEL);
2950 buffer->error = -ENOMEM;
2951 mutex_unlock(&pstr->oss.setup_mutex);
2954 if (pstr->oss.setup_list == NULL)
2955 pstr->oss.setup_list = setup;
2957 for (setup1 = pstr->oss.setup_list;
2958 setup1->next; setup1 = setup1->next);
2959 setup1->next = setup;
2961 template.task_name = kstrdup(task_name, GFP_KERNEL);
2962 if (! template.task_name) {
2964 buffer->error = -ENOMEM;
2965 mutex_unlock(&pstr->oss.setup_mutex);
2970 mutex_unlock(&pstr->oss.setup_mutex);
2974 static void snd_pcm_oss_proc_init(struct snd_pcm *pcm)
2977 for (stream = 0; stream < 2; ++stream) {
2978 struct snd_info_entry *entry;
2979 struct snd_pcm_str *pstr = &pcm->streams[stream];
2980 if (pstr->substream_count == 0)
2982 if ((entry = snd_info_create_card_entry(pcm->card, "oss", pstr->proc_root)) != NULL) {
2983 entry->content = SNDRV_INFO_CONTENT_TEXT;
2984 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
2985 entry->c.text.read = snd_pcm_oss_proc_read;
2986 entry->c.text.write = snd_pcm_oss_proc_write;
2987 entry->private_data = pstr;
2988 if (snd_info_register(entry) < 0) {
2989 snd_info_free_entry(entry);
2993 pstr->oss.proc_entry = entry;
2997 static void snd_pcm_oss_proc_done(struct snd_pcm *pcm)
3000 for (stream = 0; stream < 2; ++stream) {
3001 struct snd_pcm_str *pstr = &pcm->streams[stream];
3002 snd_info_free_entry(pstr->oss.proc_entry);
3003 pstr->oss.proc_entry = NULL;
3004 snd_pcm_oss_proc_free_setup_list(pstr);
3007 #else /* !CONFIG_SND_VERBOSE_PROCFS */
3008 #define snd_pcm_oss_proc_init(pcm)
3009 #define snd_pcm_oss_proc_done(pcm)
3010 #endif /* CONFIG_SND_VERBOSE_PROCFS */
3016 static const struct file_operations snd_pcm_oss_f_reg =
3018 .owner = THIS_MODULE,
3019 .read = snd_pcm_oss_read,
3020 .write = snd_pcm_oss_write,
3021 .open = snd_pcm_oss_open,
3022 .release = snd_pcm_oss_release,
3023 .llseek = no_llseek,
3024 .poll = snd_pcm_oss_poll,
3025 .unlocked_ioctl = snd_pcm_oss_ioctl,
3026 .compat_ioctl = snd_pcm_oss_ioctl_compat,
3027 .mmap = snd_pcm_oss_mmap,
3030 static void register_oss_dsp(struct snd_pcm *pcm, int index)
3033 sprintf(name, "dsp%i%i", pcm->card->number, pcm->device);
3034 if (snd_register_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM,
3035 pcm->card, index, &snd_pcm_oss_f_reg,
3037 snd_printk(KERN_ERR "unable to register OSS PCM device %i:%i\n",
3038 pcm->card->number, pcm->device);
3042 static int snd_pcm_oss_register_minor(struct snd_pcm *pcm)
3045 if (dsp_map[pcm->card->number] == (int)pcm->device) {
3048 register_oss_dsp(pcm, 0);
3049 duplex = (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream_count > 0 &&
3050 pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream_count &&
3051 !(pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX));
3052 sprintf(name, "%s%s", pcm->name, duplex ? " (DUPLEX)" : "");
3053 #ifdef SNDRV_OSS_INFO_DEV_AUDIO
3054 snd_oss_info_register(SNDRV_OSS_INFO_DEV_AUDIO,
3059 pcm->oss.reg_mask |= 1;
3061 if (adsp_map[pcm->card->number] == (int)pcm->device) {
3062 register_oss_dsp(pcm, 1);
3064 pcm->oss.reg_mask |= 2;
3068 snd_pcm_oss_proc_init(pcm);
3073 static int snd_pcm_oss_disconnect_minor(struct snd_pcm *pcm)
3076 if (pcm->oss.reg_mask & 1) {
3077 pcm->oss.reg_mask &= ~1;
3078 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM,
3081 if (pcm->oss.reg_mask & 2) {
3082 pcm->oss.reg_mask &= ~2;
3083 snd_unregister_oss_device(SNDRV_OSS_DEVICE_TYPE_PCM,
3086 if (dsp_map[pcm->card->number] == (int)pcm->device) {
3087 #ifdef SNDRV_OSS_INFO_DEV_AUDIO
3088 snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_AUDIO, pcm->card->number);
3096 static int snd_pcm_oss_unregister_minor(struct snd_pcm *pcm)
3098 snd_pcm_oss_disconnect_minor(pcm);
3099 snd_pcm_oss_proc_done(pcm);
3103 static struct snd_pcm_notify snd_pcm_oss_notify =
3105 .n_register = snd_pcm_oss_register_minor,
3106 .n_disconnect = snd_pcm_oss_disconnect_minor,
3107 .n_unregister = snd_pcm_oss_unregister_minor,
3110 static int __init alsa_pcm_oss_init(void)
3115 /* check device map table */
3116 for (i = 0; i < SNDRV_CARDS; i++) {
3117 if (dsp_map[i] < 0 || dsp_map[i] >= SNDRV_PCM_DEVICES) {
3118 snd_printk(KERN_ERR "invalid dsp_map[%d] = %d\n",
3122 if (adsp_map[i] < 0 || adsp_map[i] >= SNDRV_PCM_DEVICES) {
3123 snd_printk(KERN_ERR "invalid adsp_map[%d] = %d\n",
3128 if ((err = snd_pcm_notify(&snd_pcm_oss_notify, 0)) < 0)
3133 static void __exit alsa_pcm_oss_exit(void)
3135 snd_pcm_notify(&snd_pcm_oss_notify, 1);
3138 module_init(alsa_pcm_oss_init)
3139 module_exit(alsa_pcm_oss_exit)