23 #include <linux/slab.h>
24 #include <linux/module.h>
25 #include <linux/time.h>
27 #include <linux/device.h>
42 static int snd_pcm_free(
struct snd_pcm *pcm);
52 if (pcm->
card == card && pcm->
device == device)
58 static int snd_pcm_next(
struct snd_card *card,
int device)
71 static int snd_pcm_add(
struct snd_pcm *newpcm)
78 if (pcm->
card->number > newpcm->
card->number ||
81 list_add(&newpcm->
list, pcm->
list.prev);
89 static int snd_pcm_control_ioctl(
struct snd_card *card,
91 unsigned int cmd,
unsigned long arg)
98 if (
get_user(device, (
int __user *)arg))
101 device = snd_pcm_next(card, device);
103 if (
put_user(device, (
int __user *)arg))
122 if (stream < 0 || stream > 1)
127 pcm = snd_pcm_get(card, device);
141 for (substream = pstr->
substream; substream;
142 substream = substream->
next)
143 if (substream->
number == (
int)subdevice)
145 if (substream ==
NULL) {
158 if (
get_user(val, (
int __user *)arg))
167 #define FORMAT(v) [SNDRV_PCM_FORMAT_##v] = #v
169 static char *snd_pcm_format_names[] = {
188 FORMAT(IEC958_SUBFRAME_LE),
189 FORMAT(IEC958_SUBFRAME_BE),
218 return snd_pcm_format_names[(
__force unsigned int)format];
222 #ifdef CONFIG_SND_VERBOSE_PROCFS
224 #define STATE(v) [SNDRV_PCM_STATE_##v] = #v
225 #define STREAM(v) [SNDRV_PCM_STREAM_##v] = #v
226 #define READY(v) [SNDRV_PCM_READY_##v] = #v
227 #define XRUN(v) [SNDRV_PCM_XRUN_##v] = #v
228 #define SILENCE(v) [SNDRV_PCM_SILENCE_##v] = #v
229 #define TSTAMP(v) [SNDRV_PCM_TSTAMP_##v] = #v
230 #define ACCESS(v) [SNDRV_PCM_ACCESS_##v] = #v
231 #define START(v) [SNDRV_PCM_START_##v] = #v
232 #define SUBFORMAT(v) [SNDRV_PCM_SUBFORMAT_##v] = #v
234 static char *snd_pcm_stream_names[] = {
239 static char *snd_pcm_state_names[] = {
250 static char *snd_pcm_access_names[] = {
251 ACCESS(MMAP_INTERLEAVED),
252 ACCESS(MMAP_NONINTERLEAVED),
253 ACCESS(MMAP_COMPLEX),
254 ACCESS(RW_INTERLEAVED),
255 ACCESS(RW_NONINTERLEAVED),
258 static char *snd_pcm_subformat_names[] = {
262 static char *snd_pcm_tstamp_mode_names[] = {
267 static const char *snd_pcm_stream_name(
int stream)
269 return snd_pcm_stream_names[
stream];
274 return snd_pcm_access_names[(
__force int)access];
279 return snd_pcm_subformat_names[(
__force int)subformat];
282 static const char *snd_pcm_tstamp_mode_name(
int mode)
284 return snd_pcm_tstamp_mode_names[
mode];
289 return snd_pcm_state_names[(
__force int)state];
292 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
293 #include <linux/soundcard.h>
295 static const char *snd_pcm_oss_format_name(
int format)
341 snd_iprintf(buffer,
"error %d\n", err);
345 snd_iprintf(buffer,
"card: %d\n", info->
card);
346 snd_iprintf(buffer,
"device: %d\n", info->
device);
347 snd_iprintf(buffer,
"subdevice: %d\n", info->
subdevice);
348 snd_iprintf(buffer,
"stream: %s\n", snd_pcm_stream_name(info->
stream));
349 snd_iprintf(buffer,
"id: %s\n", info->
id);
350 snd_iprintf(buffer,
"name: %s\n", info->
name);
351 snd_iprintf(buffer,
"subname: %s\n", info->
subname);
352 snd_iprintf(buffer,
"class: %d\n", info->
dev_class);
353 snd_iprintf(buffer,
"subclass: %d\n", info->
dev_subclass);
366 static void snd_pcm_substream_proc_info_read(
struct snd_info_entry *entry,
372 static void snd_pcm_substream_proc_hw_params_read(
struct snd_info_entry *entry,
381 snd_iprintf(buffer,
"closed\n");
385 snd_iprintf(buffer,
"no setup\n");
388 snd_iprintf(buffer,
"access: %s\n", snd_pcm_access_name(runtime->
access));
390 snd_iprintf(buffer,
"subformat: %s\n", snd_pcm_subformat_name(runtime->
subformat));
391 snd_iprintf(buffer,
"channels: %u\n", runtime->
channels);
393 snd_iprintf(buffer,
"period_size: %lu\n", runtime->
period_size);
394 snd_iprintf(buffer,
"buffer_size: %lu\n", runtime->
buffer_size);
395 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
396 if (substream->oss.oss) {
397 snd_iprintf(buffer,
"OSS format: %s\n", snd_pcm_oss_format_name(runtime->oss.
format));
398 snd_iprintf(buffer,
"OSS channels: %u\n", runtime->oss.
channels);
399 snd_iprintf(buffer,
"OSS rate: %u\n", runtime->oss.
rate);
400 snd_iprintf(buffer,
"OSS period bytes: %lu\n", (
unsigned long)runtime->oss.period_bytes);
401 snd_iprintf(buffer,
"OSS periods: %u\n", runtime->oss.
periods);
402 snd_iprintf(buffer,
"OSS period frames: %lu\n", (
unsigned long)runtime->oss.period_frames);
409 static void snd_pcm_substream_proc_sw_params_read(
struct snd_info_entry *entry,
418 snd_iprintf(buffer,
"closed\n");
422 snd_iprintf(buffer,
"no setup\n");
425 snd_iprintf(buffer,
"tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(runtime->
tstamp_mode));
426 snd_iprintf(buffer,
"period_step: %u\n", runtime->
period_step);
427 snd_iprintf(buffer,
"avail_min: %lu\n", runtime->
control->avail_min);
428 snd_iprintf(buffer,
"start_threshold: %lu\n", runtime->
start_threshold);
429 snd_iprintf(buffer,
"stop_threshold: %lu\n", runtime->
stop_threshold);
431 snd_iprintf(buffer,
"silence_size: %lu\n", runtime->
silence_size);
432 snd_iprintf(buffer,
"boundary: %lu\n", runtime->
boundary);
437 static void snd_pcm_substream_proc_status_read(
struct snd_info_entry *entry,
448 snd_iprintf(buffer,
"closed\n");
454 snd_iprintf(buffer,
"error %d\n", err);
457 snd_iprintf(buffer,
"state: %s\n", snd_pcm_state_name(
status.state));
458 snd_iprintf(buffer,
"owner_pid : %d\n",
pid_vnr(substream->
pid));
459 snd_iprintf(buffer,
"trigger_time: %ld.%09ld\n",
460 status.trigger_tstamp.tv_sec,
status.trigger_tstamp.tv_nsec);
461 snd_iprintf(buffer,
"tstamp : %ld.%09ld\n",
463 snd_iprintf(buffer,
"delay : %ld\n",
status.delay);
464 snd_iprintf(buffer,
"avail : %ld\n",
status.avail);
465 snd_iprintf(buffer,
"avail_max : %ld\n",
status.avail_max);
466 snd_iprintf(buffer,
"-----\n");
467 snd_iprintf(buffer,
"hw_ptr : %ld\n", runtime->
status->hw_ptr);
468 snd_iprintf(buffer,
"appl_ptr : %ld\n", runtime->
control->appl_ptr);
473 #ifdef CONFIG_SND_PCM_XRUN_DEBUG
478 snd_iprintf(buffer,
"%d\n", pstr->xrun_debug);
481 static void snd_pcm_xrun_debug_write(
struct snd_info_entry *entry,
486 if (!snd_info_get_line(buffer, line,
sizeof(line)))
491 static int snd_pcm_stream_proc_init(
struct snd_pcm_str *pstr)
499 if ((entry = snd_info_create_card_entry(pcm->
card, name, pcm->
card->proc_root)) ==
NULL)
502 if (snd_info_register(entry) < 0) {
503 snd_info_free_entry(entry);
506 pstr->proc_root =
entry;
508 if ((entry = snd_info_create_card_entry(pcm->
card,
"info", pstr->proc_root)) !=
NULL) {
509 snd_info_set_text_ops(entry, pstr, snd_pcm_stream_proc_info_read);
510 if (snd_info_register(entry) < 0) {
511 snd_info_free_entry(entry);
515 pstr->proc_info_entry =
entry;
517 #ifdef CONFIG_SND_PCM_XRUN_DEBUG
518 if ((entry = snd_info_create_card_entry(pcm->
card,
"xrun_debug",
519 pstr->proc_root)) !=
NULL) {
520 entry->
c.
text.read = snd_pcm_xrun_debug_read;
521 entry->
c.
text.write = snd_pcm_xrun_debug_write;
524 if (snd_info_register(entry) < 0) {
525 snd_info_free_entry(entry);
529 pstr->proc_xrun_debug_entry =
entry;
534 static int snd_pcm_stream_proc_done(
struct snd_pcm_str *pstr)
536 #ifdef CONFIG_SND_PCM_XRUN_DEBUG
537 snd_info_free_entry(pstr->proc_xrun_debug_entry);
538 pstr->proc_xrun_debug_entry =
NULL;
540 snd_info_free_entry(pstr->proc_info_entry);
541 pstr->proc_info_entry =
NULL;
542 snd_info_free_entry(pstr->proc_root);
543 pstr->proc_root =
NULL;
553 card = substream->
pcm->card;
556 if ((entry = snd_info_create_card_entry(card, name, substream->
pstr->proc_root)) ==
NULL)
559 if (snd_info_register(entry) < 0) {
560 snd_info_free_entry(entry);
563 substream->proc_root =
entry;
565 if ((entry = snd_info_create_card_entry(card,
"info", substream->proc_root)) !=
NULL) {
566 snd_info_set_text_ops(entry, substream,
567 snd_pcm_substream_proc_info_read);
568 if (snd_info_register(entry) < 0) {
569 snd_info_free_entry(entry);
573 substream->proc_info_entry =
entry;
575 if ((entry = snd_info_create_card_entry(card,
"hw_params", substream->proc_root)) !=
NULL) {
576 snd_info_set_text_ops(entry, substream,
577 snd_pcm_substream_proc_hw_params_read);
578 if (snd_info_register(entry) < 0) {
579 snd_info_free_entry(entry);
583 substream->proc_hw_params_entry =
entry;
585 if ((entry = snd_info_create_card_entry(card,
"sw_params", substream->proc_root)) !=
NULL) {
586 snd_info_set_text_ops(entry, substream,
587 snd_pcm_substream_proc_sw_params_read);
588 if (snd_info_register(entry) < 0) {
589 snd_info_free_entry(entry);
593 substream->proc_sw_params_entry =
entry;
595 if ((entry = snd_info_create_card_entry(card,
"status", substream->proc_root)) !=
NULL) {
596 snd_info_set_text_ops(entry, substream,
597 snd_pcm_substream_proc_status_read);
598 if (snd_info_register(entry) < 0) {
599 snd_info_free_entry(entry);
603 substream->proc_status_entry =
entry;
610 snd_info_free_entry(substream->proc_info_entry);
611 substream->proc_info_entry =
NULL;
612 snd_info_free_entry(substream->proc_hw_params_entry);
613 substream->proc_hw_params_entry =
NULL;
614 snd_info_free_entry(substream->proc_sw_params_entry);
615 substream->proc_sw_params_entry =
NULL;
616 snd_info_free_entry(substream->proc_status_entry);
617 substream->proc_status_entry =
NULL;
618 snd_info_free_entry(substream->proc_root);
619 substream->proc_root =
NULL;
623 static inline int snd_pcm_stream_proc_init(
struct snd_pcm_str *pstr) {
return 0; }
624 static inline int snd_pcm_stream_proc_done(
struct snd_pcm_str *pstr) {
return 0; }
625 static inline int snd_pcm_substream_proc_init(
struct snd_pcm_substream *substream) {
return 0; }
626 static inline int snd_pcm_substream_proc_done(
struct snd_pcm_substream *substream) {
return 0; }
648 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
654 if (substream_count > 0 && !pcm->
internal) {
655 err = snd_pcm_stream_proc_init(pstr);
662 for (idx = 0, prev =
NULL; idx < substream_count; idx++) {
663 substream = kzalloc(
sizeof(*substream),
GFP_KERNEL);
664 if (substream ==
NULL) {
677 prev->
next = substream;
680 err = snd_pcm_substream_proc_init(substream);
693 INIT_LIST_HEAD(&substream->
self_group.substreams);
703 static int _snd_pcm_new(
struct snd_card *card,
const char *
id,
int device,
704 int playback_count,
int capture_count,
bool internal,
710 .dev_free = snd_pcm_dev_free,
711 .dev_register = snd_pcm_dev_register,
712 .dev_disconnect = snd_pcm_dev_disconnect,
765 int playback_count,
int capture_count,
struct snd_pcm **rpcm)
767 return _snd_pcm_new(card,
id, device, playback_count, capture_count,
793 int playback_count,
int capture_count,
796 return _snd_pcm_new(card,
id, device, playback_count, capture_count,
801 static void snd_pcm_free_stream(
struct snd_pcm_str * pstr)
804 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
809 substream_next = substream->
next;
811 snd_pcm_substream_proc_done(substream);
813 substream = substream_next;
815 snd_pcm_stream_proc_done(pstr);
816 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
817 for (setup = pstr->oss.setup_list; setup; setup = setupn) {
818 setupn = setup->
next;
825 static int snd_pcm_free(
struct snd_pcm *pcm)
843 static int snd_pcm_dev_free(
struct snd_device *device)
846 return snd_pcm_free(pcm);
858 int prefer_subdevice = -1;
873 if (prefer_subdevice != -1)
901 if (prefer_subdevice < 0) {
906 for (substream = pstr->
substream; substream;
907 substream = substream->
next)
908 if (substream->
number == prefer_subdevice)
916 *rsubstream = substream;
920 if (prefer_subdevice >= 0) {
921 for (substream = pstr->
substream; substream; substream = substream->
next)
925 for (substream = pstr->
substream; substream; substream = substream->
next)
929 if (substream ==
NULL)
932 runtime = kzalloc(
sizeof(*runtime),
GFP_KERNEL);
965 *rsubstream = substream;
983 #ifdef CONFIG_SND_PCM_XRUN_DEBUG
984 if (runtime->hwptr_log)
985 kfree(runtime->hwptr_log);
991 substream->
pstr->substream_opened--;
994 static ssize_t show_pcm_class(
struct device *
dev,
1017 static int snd_pcm_dev_register(
struct snd_device *device)
1030 err = snd_pcm_add(pcm);
1035 for (cidx = 0; cidx < 2; cidx++) {
1054 dev = snd_card_get_device_link(pcm->
card);
1067 for (substream = pcm->
streams[cidx].substream; substream; substream = substream->
next)
1072 notify->n_register(pcm);
1080 struct snd_pcm *pcm = device->device_data;
1086 if (list_empty(&pcm->
list))
1091 list_del_init(&pcm->
list);
1092 for (cidx = 0; cidx < 2; cidx++)
1093 for (substream = pcm->
streams[cidx].substream; substream; substream = substream->
next) {
1094 snd_pcm_stream_lock_irq(substream);
1100 snd_pcm_stream_unlock_irq(substream);
1105 for (cidx = 0; cidx < 2; cidx++) {
1116 if (pcm->
streams[cidx].chmap_kctl) {
1152 #ifdef CONFIG_PROC_FS
1164 snd_iprintf(buffer,
"%02i-%02i: %s : %s",
1167 snd_iprintf(buffer,
" : playback %i",
1170 snd_iprintf(buffer,
" : capture %i",
1172 snd_iprintf(buffer,
"\n");
1184 snd_info_set_text_ops(entry,
NULL, snd_pcm_proc_read);
1185 if (snd_info_register(entry) < 0) {
1186 snd_info_free_entry(entry);
1190 snd_pcm_proc_entry =
entry;
1195 snd_info_free_entry(snd_pcm_proc_entry);
1199 #define snd_pcm_proc_init()
1200 #define snd_pcm_proc_done()
1208 static int __init alsa_pcm_init(
void)
1216 static void __exit alsa_pcm_exit(
void)