pcm.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090
  1. /*
  2. * Digital Audio (PCM) abstract layer
  3. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  4. *
  5. *
  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.
  10. *
  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.
  15. *
  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
  19. *
  20. */
  21. #include <sound/driver.h>
  22. #include <linux/init.h>
  23. #include <linux/slab.h>
  24. #include <linux/time.h>
  25. #include <sound/core.h>
  26. #include <sound/minors.h>
  27. #include <sound/pcm.h>
  28. #include <sound/control.h>
  29. #include <sound/info.h>
  30. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, Abramo Bagnara <abramo@alsa-project.org>");
  31. MODULE_DESCRIPTION("Midlevel PCM code for ALSA.");
  32. MODULE_LICENSE("GPL");
  33. struct snd_pcm *snd_pcm_devices[SNDRV_CARDS * SNDRV_PCM_DEVICES];
  34. static LIST_HEAD(snd_pcm_notify_list);
  35. static DECLARE_MUTEX(register_mutex);
  36. static int snd_pcm_free(struct snd_pcm *pcm);
  37. static int snd_pcm_dev_free(struct snd_device *device);
  38. static int snd_pcm_dev_register(struct snd_device *device);
  39. static int snd_pcm_dev_disconnect(struct snd_device *device);
  40. static int snd_pcm_dev_unregister(struct snd_device *device);
  41. static int snd_pcm_control_ioctl(struct snd_card *card,
  42. struct snd_ctl_file *control,
  43. unsigned int cmd, unsigned long arg)
  44. {
  45. unsigned int tmp;
  46. tmp = card->number * SNDRV_PCM_DEVICES;
  47. switch (cmd) {
  48. case SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE:
  49. {
  50. int device;
  51. if (get_user(device, (int __user *)arg))
  52. return -EFAULT;
  53. device = device < 0 ? 0 : device + 1;
  54. while (device < SNDRV_PCM_DEVICES) {
  55. if (snd_pcm_devices[tmp + device])
  56. break;
  57. device++;
  58. }
  59. if (device == SNDRV_PCM_DEVICES)
  60. device = -1;
  61. if (put_user(device, (int __user *)arg))
  62. return -EFAULT;
  63. return 0;
  64. }
  65. case SNDRV_CTL_IOCTL_PCM_INFO:
  66. {
  67. struct snd_pcm_info __user *info;
  68. unsigned int device, subdevice;
  69. int stream;
  70. struct snd_pcm *pcm;
  71. struct snd_pcm_str *pstr;
  72. struct snd_pcm_substream *substream;
  73. info = (struct snd_pcm_info __user *)arg;
  74. if (get_user(device, &info->device))
  75. return -EFAULT;
  76. if (device >= SNDRV_PCM_DEVICES)
  77. return -ENXIO;
  78. pcm = snd_pcm_devices[tmp + device];
  79. if (pcm == NULL)
  80. return -ENXIO;
  81. if (get_user(stream, &info->stream))
  82. return -EFAULT;
  83. if (stream < 0 || stream > 1)
  84. return -EINVAL;
  85. pstr = &pcm->streams[stream];
  86. if (pstr->substream_count == 0)
  87. return -ENOENT;
  88. if (get_user(subdevice, &info->subdevice))
  89. return -EFAULT;
  90. if (subdevice >= pstr->substream_count)
  91. return -ENXIO;
  92. for (substream = pstr->substream; substream; substream = substream->next)
  93. if (substream->number == (int)subdevice)
  94. break;
  95. if (substream == NULL)
  96. return -ENXIO;
  97. return snd_pcm_info_user(substream, info);
  98. }
  99. case SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE:
  100. {
  101. int val;
  102. if (get_user(val, (int __user *)arg))
  103. return -EFAULT;
  104. control->prefer_pcm_subdevice = val;
  105. return 0;
  106. }
  107. }
  108. return -ENOIOCTLCMD;
  109. }
  110. #define STATE(v) [SNDRV_PCM_STATE_##v] = #v
  111. #define STREAM(v) [SNDRV_PCM_STREAM_##v] = #v
  112. #define READY(v) [SNDRV_PCM_READY_##v] = #v
  113. #define XRUN(v) [SNDRV_PCM_XRUN_##v] = #v
  114. #define SILENCE(v) [SNDRV_PCM_SILENCE_##v] = #v
  115. #define TSTAMP(v) [SNDRV_PCM_TSTAMP_##v] = #v
  116. #define ACCESS(v) [SNDRV_PCM_ACCESS_##v] = #v
  117. #define START(v) [SNDRV_PCM_START_##v] = #v
  118. #define FORMAT(v) [SNDRV_PCM_FORMAT_##v] = #v
  119. #define SUBFORMAT(v) [SNDRV_PCM_SUBFORMAT_##v] = #v
  120. static char *snd_pcm_stream_names[] = {
  121. STREAM(PLAYBACK),
  122. STREAM(CAPTURE),
  123. };
  124. static char *snd_pcm_state_names[] = {
  125. STATE(OPEN),
  126. STATE(SETUP),
  127. STATE(PREPARED),
  128. STATE(RUNNING),
  129. STATE(XRUN),
  130. STATE(DRAINING),
  131. STATE(PAUSED),
  132. STATE(SUSPENDED),
  133. };
  134. static char *snd_pcm_access_names[] = {
  135. ACCESS(MMAP_INTERLEAVED),
  136. ACCESS(MMAP_NONINTERLEAVED),
  137. ACCESS(MMAP_COMPLEX),
  138. ACCESS(RW_INTERLEAVED),
  139. ACCESS(RW_NONINTERLEAVED),
  140. };
  141. static char *snd_pcm_format_names[] = {
  142. FORMAT(S8),
  143. FORMAT(U8),
  144. FORMAT(S16_LE),
  145. FORMAT(S16_BE),
  146. FORMAT(U16_LE),
  147. FORMAT(U16_BE),
  148. FORMAT(S24_LE),
  149. FORMAT(S24_BE),
  150. FORMAT(U24_LE),
  151. FORMAT(U24_BE),
  152. FORMAT(S32_LE),
  153. FORMAT(S32_BE),
  154. FORMAT(U32_LE),
  155. FORMAT(U32_BE),
  156. FORMAT(FLOAT_LE),
  157. FORMAT(FLOAT_BE),
  158. FORMAT(FLOAT64_LE),
  159. FORMAT(FLOAT64_BE),
  160. FORMAT(IEC958_SUBFRAME_LE),
  161. FORMAT(IEC958_SUBFRAME_BE),
  162. FORMAT(MU_LAW),
  163. FORMAT(A_LAW),
  164. FORMAT(IMA_ADPCM),
  165. FORMAT(MPEG),
  166. FORMAT(GSM),
  167. FORMAT(SPECIAL),
  168. FORMAT(S24_3LE),
  169. FORMAT(S24_3BE),
  170. FORMAT(U24_3LE),
  171. FORMAT(U24_3BE),
  172. FORMAT(S20_3LE),
  173. FORMAT(S20_3BE),
  174. FORMAT(U20_3LE),
  175. FORMAT(U20_3BE),
  176. FORMAT(S18_3LE),
  177. FORMAT(S18_3BE),
  178. FORMAT(U18_3LE),
  179. FORMAT(U18_3BE),
  180. };
  181. static char *snd_pcm_subformat_names[] = {
  182. SUBFORMAT(STD),
  183. };
  184. static char *snd_pcm_tstamp_mode_names[] = {
  185. TSTAMP(NONE),
  186. TSTAMP(MMAP),
  187. };
  188. static const char *snd_pcm_stream_name(int stream)
  189. {
  190. snd_assert(stream <= SNDRV_PCM_STREAM_LAST, return NULL);
  191. return snd_pcm_stream_names[stream];
  192. }
  193. static const char *snd_pcm_access_name(snd_pcm_access_t access)
  194. {
  195. return snd_pcm_access_names[access];
  196. }
  197. const char *snd_pcm_format_name(snd_pcm_format_t format)
  198. {
  199. return snd_pcm_format_names[format];
  200. }
  201. static const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat)
  202. {
  203. return snd_pcm_subformat_names[subformat];
  204. }
  205. static const char *snd_pcm_tstamp_mode_name(int mode)
  206. {
  207. snd_assert(mode <= SNDRV_PCM_TSTAMP_LAST, return NULL);
  208. return snd_pcm_tstamp_mode_names[mode];
  209. }
  210. static const char *snd_pcm_state_name(snd_pcm_state_t state)
  211. {
  212. return snd_pcm_state_names[state];
  213. }
  214. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  215. #include <linux/soundcard.h>
  216. static const char *snd_pcm_oss_format_name(int format)
  217. {
  218. switch (format) {
  219. case AFMT_MU_LAW:
  220. return "MU_LAW";
  221. case AFMT_A_LAW:
  222. return "A_LAW";
  223. case AFMT_IMA_ADPCM:
  224. return "IMA_ADPCM";
  225. case AFMT_U8:
  226. return "U8";
  227. case AFMT_S16_LE:
  228. return "S16_LE";
  229. case AFMT_S16_BE:
  230. return "S16_BE";
  231. case AFMT_S8:
  232. return "S8";
  233. case AFMT_U16_LE:
  234. return "U16_LE";
  235. case AFMT_U16_BE:
  236. return "U16_BE";
  237. case AFMT_MPEG:
  238. return "MPEG";
  239. default:
  240. return "unknown";
  241. }
  242. }
  243. #endif
  244. #ifdef CONFIG_PROC_FS
  245. static void snd_pcm_proc_info_read(struct snd_pcm_substream *substream,
  246. struct snd_info_buffer *buffer)
  247. {
  248. struct snd_pcm_info *info;
  249. int err;
  250. if (! substream)
  251. return;
  252. info = kmalloc(sizeof(*info), GFP_KERNEL);
  253. if (! info) {
  254. printk(KERN_DEBUG "snd_pcm_proc_info_read: cannot malloc\n");
  255. return;
  256. }
  257. err = snd_pcm_info(substream, info);
  258. if (err < 0) {
  259. snd_iprintf(buffer, "error %d\n", err);
  260. kfree(info);
  261. return;
  262. }
  263. snd_iprintf(buffer, "card: %d\n", info->card);
  264. snd_iprintf(buffer, "device: %d\n", info->device);
  265. snd_iprintf(buffer, "subdevice: %d\n", info->subdevice);
  266. snd_iprintf(buffer, "stream: %s\n", snd_pcm_stream_name(info->stream));
  267. snd_iprintf(buffer, "id: %s\n", info->id);
  268. snd_iprintf(buffer, "name: %s\n", info->name);
  269. snd_iprintf(buffer, "subname: %s\n", info->subname);
  270. snd_iprintf(buffer, "class: %d\n", info->dev_class);
  271. snd_iprintf(buffer, "subclass: %d\n", info->dev_subclass);
  272. snd_iprintf(buffer, "subdevices_count: %d\n", info->subdevices_count);
  273. snd_iprintf(buffer, "subdevices_avail: %d\n", info->subdevices_avail);
  274. kfree(info);
  275. }
  276. static void snd_pcm_stream_proc_info_read(struct snd_info_entry *entry,
  277. struct snd_info_buffer *buffer)
  278. {
  279. snd_pcm_proc_info_read(((struct snd_pcm_str *)entry->private_data)->substream,
  280. buffer);
  281. }
  282. static void snd_pcm_substream_proc_info_read(struct snd_info_entry *entry,
  283. struct snd_info_buffer *buffer)
  284. {
  285. snd_pcm_proc_info_read((struct snd_pcm_substream *)entry->private_data,
  286. buffer);
  287. }
  288. static void snd_pcm_substream_proc_hw_params_read(struct snd_info_entry *entry,
  289. struct snd_info_buffer *buffer)
  290. {
  291. struct snd_pcm_substream *substream = entry->private_data;
  292. struct snd_pcm_runtime *runtime = substream->runtime;
  293. if (!runtime) {
  294. snd_iprintf(buffer, "closed\n");
  295. return;
  296. }
  297. snd_pcm_stream_lock_irq(substream);
  298. if (runtime->status->state == SNDRV_PCM_STATE_OPEN) {
  299. snd_iprintf(buffer, "no setup\n");
  300. snd_pcm_stream_unlock_irq(substream);
  301. return;
  302. }
  303. snd_iprintf(buffer, "access: %s\n", snd_pcm_access_name(runtime->access));
  304. snd_iprintf(buffer, "format: %s\n", snd_pcm_format_name(runtime->format));
  305. snd_iprintf(buffer, "subformat: %s\n", snd_pcm_subformat_name(runtime->subformat));
  306. snd_iprintf(buffer, "channels: %u\n", runtime->channels);
  307. snd_iprintf(buffer, "rate: %u (%u/%u)\n", runtime->rate, runtime->rate_num, runtime->rate_den);
  308. snd_iprintf(buffer, "period_size: %lu\n", runtime->period_size);
  309. snd_iprintf(buffer, "buffer_size: %lu\n", runtime->buffer_size);
  310. snd_iprintf(buffer, "tick_time: %u\n", runtime->tick_time);
  311. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  312. if (substream->oss.oss) {
  313. snd_iprintf(buffer, "OSS format: %s\n", snd_pcm_oss_format_name(runtime->oss.format));
  314. snd_iprintf(buffer, "OSS channels: %u\n", runtime->oss.channels);
  315. snd_iprintf(buffer, "OSS rate: %u\n", runtime->oss.rate);
  316. snd_iprintf(buffer, "OSS period bytes: %lu\n", (unsigned long)runtime->oss.period_bytes);
  317. snd_iprintf(buffer, "OSS periods: %u\n", runtime->oss.periods);
  318. snd_iprintf(buffer, "OSS period frames: %lu\n", (unsigned long)runtime->oss.period_frames);
  319. }
  320. #endif
  321. snd_pcm_stream_unlock_irq(substream);
  322. }
  323. static void snd_pcm_substream_proc_sw_params_read(struct snd_info_entry *entry,
  324. struct snd_info_buffer *buffer)
  325. {
  326. struct snd_pcm_substream *substream = entry->private_data;
  327. struct snd_pcm_runtime *runtime = substream->runtime;
  328. if (!runtime) {
  329. snd_iprintf(buffer, "closed\n");
  330. return;
  331. }
  332. snd_pcm_stream_lock_irq(substream);
  333. if (runtime->status->state == SNDRV_PCM_STATE_OPEN) {
  334. snd_iprintf(buffer, "no setup\n");
  335. snd_pcm_stream_unlock_irq(substream);
  336. return;
  337. }
  338. snd_iprintf(buffer, "tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(runtime->tstamp_mode));
  339. snd_iprintf(buffer, "period_step: %u\n", runtime->period_step);
  340. snd_iprintf(buffer, "sleep_min: %u\n", runtime->sleep_min);
  341. snd_iprintf(buffer, "avail_min: %lu\n", runtime->control->avail_min);
  342. snd_iprintf(buffer, "xfer_align: %lu\n", runtime->xfer_align);
  343. snd_iprintf(buffer, "start_threshold: %lu\n", runtime->start_threshold);
  344. snd_iprintf(buffer, "stop_threshold: %lu\n", runtime->stop_threshold);
  345. snd_iprintf(buffer, "silence_threshold: %lu\n", runtime->silence_threshold);
  346. snd_iprintf(buffer, "silence_size: %lu\n", runtime->silence_size);
  347. snd_iprintf(buffer, "boundary: %lu\n", runtime->boundary);
  348. snd_pcm_stream_unlock_irq(substream);
  349. }
  350. static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry,
  351. struct snd_info_buffer *buffer)
  352. {
  353. struct snd_pcm_substream *substream = entry->private_data;
  354. struct snd_pcm_runtime *runtime = substream->runtime;
  355. struct snd_pcm_status status;
  356. int err;
  357. if (!runtime) {
  358. snd_iprintf(buffer, "closed\n");
  359. return;
  360. }
  361. memset(&status, 0, sizeof(status));
  362. err = snd_pcm_status(substream, &status);
  363. if (err < 0) {
  364. snd_iprintf(buffer, "error %d\n", err);
  365. return;
  366. }
  367. snd_iprintf(buffer, "state: %s\n", snd_pcm_state_name(status.state));
  368. snd_iprintf(buffer, "trigger_time: %ld.%09ld\n",
  369. status.trigger_tstamp.tv_sec, status.trigger_tstamp.tv_nsec);
  370. snd_iprintf(buffer, "tstamp : %ld.%09ld\n",
  371. status.tstamp.tv_sec, status.tstamp.tv_nsec);
  372. snd_iprintf(buffer, "delay : %ld\n", status.delay);
  373. snd_iprintf(buffer, "avail : %ld\n", status.avail);
  374. snd_iprintf(buffer, "avail_max : %ld\n", status.avail_max);
  375. snd_iprintf(buffer, "-----\n");
  376. snd_iprintf(buffer, "hw_ptr : %ld\n", runtime->status->hw_ptr);
  377. snd_iprintf(buffer, "appl_ptr : %ld\n", runtime->control->appl_ptr);
  378. }
  379. #endif
  380. #ifdef CONFIG_SND_DEBUG
  381. static void snd_pcm_xrun_debug_read(struct snd_info_entry *entry,
  382. struct snd_info_buffer *buffer)
  383. {
  384. struct snd_pcm_str *pstr = entry->private_data;
  385. snd_iprintf(buffer, "%d\n", pstr->xrun_debug);
  386. }
  387. static void snd_pcm_xrun_debug_write(struct snd_info_entry *entry,
  388. struct snd_info_buffer *buffer)
  389. {
  390. struct snd_pcm_str *pstr = entry->private_data;
  391. char line[64];
  392. if (!snd_info_get_line(buffer, line, sizeof(line)))
  393. pstr->xrun_debug = simple_strtoul(line, NULL, 10);
  394. }
  395. #endif
  396. static int snd_pcm_stream_proc_init(struct snd_pcm_str *pstr)
  397. {
  398. struct snd_pcm *pcm = pstr->pcm;
  399. struct snd_info_entry *entry;
  400. char name[16];
  401. sprintf(name, "pcm%i%c", pcm->device,
  402. pstr->stream == SNDRV_PCM_STREAM_PLAYBACK ? 'p' : 'c');
  403. if ((entry = snd_info_create_card_entry(pcm->card, name, pcm->card->proc_root)) == NULL)
  404. return -ENOMEM;
  405. entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
  406. if (snd_info_register(entry) < 0) {
  407. snd_info_free_entry(entry);
  408. return -ENOMEM;
  409. }
  410. pstr->proc_root = entry;
  411. if ((entry = snd_info_create_card_entry(pcm->card, "info", pstr->proc_root)) != NULL) {
  412. snd_info_set_text_ops(entry, pstr, 256, snd_pcm_stream_proc_info_read);
  413. if (snd_info_register(entry) < 0) {
  414. snd_info_free_entry(entry);
  415. entry = NULL;
  416. }
  417. }
  418. pstr->proc_info_entry = entry;
  419. #ifdef CONFIG_SND_DEBUG
  420. if ((entry = snd_info_create_card_entry(pcm->card, "xrun_debug",
  421. pstr->proc_root)) != NULL) {
  422. entry->c.text.read_size = 64;
  423. entry->c.text.read = snd_pcm_xrun_debug_read;
  424. entry->c.text.write_size = 64;
  425. entry->c.text.write = snd_pcm_xrun_debug_write;
  426. entry->mode |= S_IWUSR;
  427. entry->private_data = pstr;
  428. if (snd_info_register(entry) < 0) {
  429. snd_info_free_entry(entry);
  430. entry = NULL;
  431. }
  432. }
  433. pstr->proc_xrun_debug_entry = entry;
  434. #endif
  435. return 0;
  436. }
  437. static int snd_pcm_stream_proc_done(struct snd_pcm_str *pstr)
  438. {
  439. #ifdef CONFIG_SND_DEBUG
  440. if (pstr->proc_xrun_debug_entry) {
  441. snd_info_unregister(pstr->proc_xrun_debug_entry);
  442. pstr->proc_xrun_debug_entry = NULL;
  443. }
  444. #endif
  445. if (pstr->proc_info_entry) {
  446. snd_info_unregister(pstr->proc_info_entry);
  447. pstr->proc_info_entry = NULL;
  448. }
  449. if (pstr->proc_root) {
  450. snd_info_unregister(pstr->proc_root);
  451. pstr->proc_root = NULL;
  452. }
  453. return 0;
  454. }
  455. static int snd_pcm_substream_proc_init(struct snd_pcm_substream *substream)
  456. {
  457. struct snd_info_entry *entry;
  458. struct snd_card *card;
  459. char name[16];
  460. card = substream->pcm->card;
  461. sprintf(name, "sub%i", substream->number);
  462. if ((entry = snd_info_create_card_entry(card, name, substream->pstr->proc_root)) == NULL)
  463. return -ENOMEM;
  464. entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
  465. if (snd_info_register(entry) < 0) {
  466. snd_info_free_entry(entry);
  467. return -ENOMEM;
  468. }
  469. substream->proc_root = entry;
  470. if ((entry = snd_info_create_card_entry(card, "info", substream->proc_root)) != NULL) {
  471. snd_info_set_text_ops(entry, substream, 256, snd_pcm_substream_proc_info_read);
  472. if (snd_info_register(entry) < 0) {
  473. snd_info_free_entry(entry);
  474. entry = NULL;
  475. }
  476. }
  477. substream->proc_info_entry = entry;
  478. if ((entry = snd_info_create_card_entry(card, "hw_params", substream->proc_root)) != NULL) {
  479. snd_info_set_text_ops(entry, substream, 256, snd_pcm_substream_proc_hw_params_read);
  480. if (snd_info_register(entry) < 0) {
  481. snd_info_free_entry(entry);
  482. entry = NULL;
  483. }
  484. }
  485. substream->proc_hw_params_entry = entry;
  486. if ((entry = snd_info_create_card_entry(card, "sw_params", substream->proc_root)) != NULL) {
  487. snd_info_set_text_ops(entry, substream, 256, snd_pcm_substream_proc_sw_params_read);
  488. if (snd_info_register(entry) < 0) {
  489. snd_info_free_entry(entry);
  490. entry = NULL;
  491. }
  492. }
  493. substream->proc_sw_params_entry = entry;
  494. if ((entry = snd_info_create_card_entry(card, "status", substream->proc_root)) != NULL) {
  495. snd_info_set_text_ops(entry, substream, 256, snd_pcm_substream_proc_status_read);
  496. if (snd_info_register(entry) < 0) {
  497. snd_info_free_entry(entry);
  498. entry = NULL;
  499. }
  500. }
  501. substream->proc_status_entry = entry;
  502. return 0;
  503. }
  504. static int snd_pcm_substream_proc_done(struct snd_pcm_substream *substream)
  505. {
  506. if (substream->proc_info_entry) {
  507. snd_info_unregister(substream->proc_info_entry);
  508. substream->proc_info_entry = NULL;
  509. }
  510. if (substream->proc_hw_params_entry) {
  511. snd_info_unregister(substream->proc_hw_params_entry);
  512. substream->proc_hw_params_entry = NULL;
  513. }
  514. if (substream->proc_sw_params_entry) {
  515. snd_info_unregister(substream->proc_sw_params_entry);
  516. substream->proc_sw_params_entry = NULL;
  517. }
  518. if (substream->proc_status_entry) {
  519. snd_info_unregister(substream->proc_status_entry);
  520. substream->proc_status_entry = NULL;
  521. }
  522. if (substream->proc_root) {
  523. snd_info_unregister(substream->proc_root);
  524. substream->proc_root = NULL;
  525. }
  526. return 0;
  527. }
  528. /**
  529. * snd_pcm_new_stream - create a new PCM stream
  530. * @pcm: the pcm instance
  531. * @stream: the stream direction, SNDRV_PCM_STREAM_XXX
  532. * @substream_count: the number of substreams
  533. *
  534. * Creates a new stream for the pcm.
  535. * The corresponding stream on the pcm must have been empty before
  536. * calling this, i.e. zero must be given to the argument of
  537. * snd_pcm_new().
  538. *
  539. * Returns zero if successful, or a negative error code on failure.
  540. */
  541. int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
  542. {
  543. int idx, err;
  544. struct snd_pcm_str *pstr = &pcm->streams[stream];
  545. struct snd_pcm_substream *substream, *prev;
  546. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  547. init_MUTEX(&pstr->oss.setup_mutex);
  548. #endif
  549. pstr->stream = stream;
  550. pstr->pcm = pcm;
  551. pstr->substream_count = substream_count;
  552. pstr->reg = &snd_pcm_reg[stream];
  553. if (substream_count > 0) {
  554. err = snd_pcm_stream_proc_init(pstr);
  555. if (err < 0)
  556. return err;
  557. }
  558. prev = NULL;
  559. for (idx = 0, prev = NULL; idx < substream_count; idx++) {
  560. substream = kzalloc(sizeof(*substream), GFP_KERNEL);
  561. if (substream == NULL)
  562. return -ENOMEM;
  563. substream->pcm = pcm;
  564. substream->pstr = pstr;
  565. substream->number = idx;
  566. substream->stream = stream;
  567. sprintf(substream->name, "subdevice #%i", idx);
  568. substream->buffer_bytes_max = UINT_MAX;
  569. if (prev == NULL)
  570. pstr->substream = substream;
  571. else
  572. prev->next = substream;
  573. err = snd_pcm_substream_proc_init(substream);
  574. if (err < 0) {
  575. kfree(substream);
  576. return err;
  577. }
  578. substream->group = &substream->self_group;
  579. spin_lock_init(&substream->self_group.lock);
  580. INIT_LIST_HEAD(&substream->self_group.substreams);
  581. list_add_tail(&substream->link_list, &substream->self_group.substreams);
  582. spin_lock_init(&substream->timer_lock);
  583. prev = substream;
  584. }
  585. return 0;
  586. }
  587. /**
  588. * snd_pcm_new - create a new PCM instance
  589. * @card: the card instance
  590. * @id: the id string
  591. * @device: the device index (zero based)
  592. * @playback_count: the number of substreams for playback
  593. * @capture_count: the number of substreams for capture
  594. * @rpcm: the pointer to store the new pcm instance
  595. *
  596. * Creates a new PCM instance.
  597. *
  598. * The pcm operators have to be set afterwards to the new instance
  599. * via snd_pcm_set_ops().
  600. *
  601. * Returns zero if successful, or a negative error code on failure.
  602. */
  603. int snd_pcm_new(struct snd_card *card, char *id, int device,
  604. int playback_count, int capture_count,
  605. struct snd_pcm ** rpcm)
  606. {
  607. struct snd_pcm *pcm;
  608. int err;
  609. static struct snd_device_ops ops = {
  610. .dev_free = snd_pcm_dev_free,
  611. .dev_register = snd_pcm_dev_register,
  612. .dev_disconnect = snd_pcm_dev_disconnect,
  613. .dev_unregister = snd_pcm_dev_unregister
  614. };
  615. snd_assert(rpcm != NULL, return -EINVAL);
  616. *rpcm = NULL;
  617. snd_assert(card != NULL, return -ENXIO);
  618. pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
  619. if (pcm == NULL)
  620. return -ENOMEM;
  621. pcm->card = card;
  622. pcm->device = device;
  623. if (id) {
  624. strlcpy(pcm->id, id, sizeof(pcm->id));
  625. }
  626. if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) {
  627. snd_pcm_free(pcm);
  628. return err;
  629. }
  630. if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_CAPTURE, capture_count)) < 0) {
  631. snd_pcm_free(pcm);
  632. return err;
  633. }
  634. init_MUTEX(&pcm->open_mutex);
  635. init_waitqueue_head(&pcm->open_wait);
  636. if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) {
  637. snd_pcm_free(pcm);
  638. return err;
  639. }
  640. *rpcm = pcm;
  641. return 0;
  642. }
  643. static void snd_pcm_free_stream(struct snd_pcm_str * pstr)
  644. {
  645. struct snd_pcm_substream *substream, *substream_next;
  646. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  647. struct snd_pcm_oss_setup *setup, *setupn;
  648. #endif
  649. substream = pstr->substream;
  650. while (substream) {
  651. substream_next = substream->next;
  652. snd_pcm_substream_proc_done(substream);
  653. kfree(substream);
  654. substream = substream_next;
  655. }
  656. snd_pcm_stream_proc_done(pstr);
  657. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  658. for (setup = pstr->oss.setup_list; setup; setup = setupn) {
  659. setupn = setup->next;
  660. kfree(setup->task_name);
  661. kfree(setup);
  662. }
  663. #endif
  664. }
  665. static int snd_pcm_free(struct snd_pcm *pcm)
  666. {
  667. snd_assert(pcm != NULL, return -ENXIO);
  668. if (pcm->private_free)
  669. pcm->private_free(pcm);
  670. snd_pcm_lib_preallocate_free_for_all(pcm);
  671. snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_PLAYBACK]);
  672. snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_CAPTURE]);
  673. kfree(pcm);
  674. return 0;
  675. }
  676. static int snd_pcm_dev_free(struct snd_device *device)
  677. {
  678. struct snd_pcm *pcm = device->device_data;
  679. return snd_pcm_free(pcm);
  680. }
  681. static void snd_pcm_tick_timer_func(unsigned long data)
  682. {
  683. struct snd_pcm_substream *substream = (struct snd_pcm_substream *) data;
  684. snd_pcm_tick_elapsed(substream);
  685. }
  686. int snd_pcm_open_substream(struct snd_pcm *pcm, int stream,
  687. struct snd_pcm_substream **rsubstream)
  688. {
  689. struct snd_pcm_str * pstr;
  690. struct snd_pcm_substream *substream;
  691. struct snd_pcm_runtime *runtime;
  692. struct snd_ctl_file *kctl;
  693. struct snd_card *card;
  694. struct list_head *list;
  695. int prefer_subdevice = -1;
  696. size_t size;
  697. snd_assert(rsubstream != NULL, return -EINVAL);
  698. *rsubstream = NULL;
  699. snd_assert(pcm != NULL, return -ENXIO);
  700. pstr = &pcm->streams[stream];
  701. if (pstr->substream == NULL)
  702. return -ENODEV;
  703. card = pcm->card;
  704. down_read(&card->controls_rwsem);
  705. list_for_each(list, &card->ctl_files) {
  706. kctl = snd_ctl_file(list);
  707. if (kctl->pid == current->pid) {
  708. prefer_subdevice = kctl->prefer_pcm_subdevice;
  709. break;
  710. }
  711. }
  712. up_read(&card->controls_rwsem);
  713. if (pstr->substream_count == 0)
  714. return -ENODEV;
  715. switch (stream) {
  716. case SNDRV_PCM_STREAM_PLAYBACK:
  717. if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) {
  718. for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next) {
  719. if (SUBSTREAM_BUSY(substream))
  720. return -EAGAIN;
  721. }
  722. }
  723. break;
  724. case SNDRV_PCM_STREAM_CAPTURE:
  725. if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) {
  726. for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) {
  727. if (SUBSTREAM_BUSY(substream))
  728. return -EAGAIN;
  729. }
  730. }
  731. break;
  732. default:
  733. return -EINVAL;
  734. }
  735. if (prefer_subdevice >= 0) {
  736. for (substream = pstr->substream; substream; substream = substream->next)
  737. if (!SUBSTREAM_BUSY(substream) && substream->number == prefer_subdevice)
  738. goto __ok;
  739. }
  740. for (substream = pstr->substream; substream; substream = substream->next)
  741. if (!SUBSTREAM_BUSY(substream))
  742. break;
  743. __ok:
  744. if (substream == NULL)
  745. return -EAGAIN;
  746. runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
  747. if (runtime == NULL)
  748. return -ENOMEM;
  749. size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status));
  750. runtime->status = snd_malloc_pages(size, GFP_KERNEL);
  751. if (runtime->status == NULL) {
  752. kfree(runtime);
  753. return -ENOMEM;
  754. }
  755. memset((void*)runtime->status, 0, size);
  756. size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control));
  757. runtime->control = snd_malloc_pages(size, GFP_KERNEL);
  758. if (runtime->control == NULL) {
  759. snd_free_pages((void*)runtime->status,
  760. PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
  761. kfree(runtime);
  762. return -ENOMEM;
  763. }
  764. memset((void*)runtime->control, 0, size);
  765. init_waitqueue_head(&runtime->sleep);
  766. atomic_set(&runtime->mmap_count, 0);
  767. init_timer(&runtime->tick_timer);
  768. runtime->tick_timer.function = snd_pcm_tick_timer_func;
  769. runtime->tick_timer.data = (unsigned long) substream;
  770. runtime->status->state = SNDRV_PCM_STATE_OPEN;
  771. substream->runtime = runtime;
  772. substream->private_data = pcm->private_data;
  773. pstr->substream_opened++;
  774. *rsubstream = substream;
  775. return 0;
  776. }
  777. void snd_pcm_release_substream(struct snd_pcm_substream *substream)
  778. {
  779. struct snd_pcm_runtime *runtime;
  780. substream->file = NULL;
  781. runtime = substream->runtime;
  782. snd_assert(runtime != NULL, return);
  783. if (runtime->private_free != NULL)
  784. runtime->private_free(runtime);
  785. snd_free_pages((void*)runtime->status,
  786. PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
  787. snd_free_pages((void*)runtime->control,
  788. PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)));
  789. kfree(runtime->hw_constraints.rules);
  790. kfree(runtime);
  791. substream->runtime = NULL;
  792. substream->pstr->substream_opened--;
  793. }
  794. static int snd_pcm_dev_register(struct snd_device *device)
  795. {
  796. int idx, cidx, err;
  797. unsigned short minor;
  798. struct snd_pcm_substream *substream;
  799. struct list_head *list;
  800. char str[16];
  801. struct snd_pcm *pcm = device->device_data;
  802. snd_assert(pcm != NULL && device != NULL, return -ENXIO);
  803. down(&register_mutex);
  804. idx = (pcm->card->number * SNDRV_PCM_DEVICES) + pcm->device;
  805. if (snd_pcm_devices[idx]) {
  806. up(&register_mutex);
  807. return -EBUSY;
  808. }
  809. snd_pcm_devices[idx] = pcm;
  810. for (cidx = 0; cidx < 2; cidx++) {
  811. int devtype = -1;
  812. if (pcm->streams[cidx].substream == NULL)
  813. continue;
  814. switch (cidx) {
  815. case SNDRV_PCM_STREAM_PLAYBACK:
  816. sprintf(str, "pcmC%iD%ip", pcm->card->number, pcm->device);
  817. minor = SNDRV_MINOR_PCM_PLAYBACK + idx;
  818. devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK;
  819. break;
  820. case SNDRV_PCM_STREAM_CAPTURE:
  821. sprintf(str, "pcmC%iD%ic", pcm->card->number, pcm->device);
  822. minor = SNDRV_MINOR_PCM_CAPTURE + idx;
  823. devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE;
  824. break;
  825. }
  826. if ((err = snd_register_device(devtype, pcm->card, pcm->device, pcm->streams[cidx].reg, str)) < 0) {
  827. snd_pcm_devices[idx] = NULL;
  828. up(&register_mutex);
  829. return err;
  830. }
  831. for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
  832. snd_pcm_timer_init(substream);
  833. }
  834. list_for_each(list, &snd_pcm_notify_list) {
  835. struct snd_pcm_notify *notify;
  836. notify = list_entry(list, struct snd_pcm_notify, list);
  837. notify->n_register(pcm);
  838. }
  839. up(&register_mutex);
  840. return 0;
  841. }
  842. static int snd_pcm_dev_disconnect(struct snd_device *device)
  843. {
  844. struct snd_pcm *pcm = device->device_data;
  845. struct list_head *list;
  846. struct snd_pcm_substream *substream;
  847. int idx, cidx;
  848. down(&register_mutex);
  849. idx = (pcm->card->number * SNDRV_PCM_DEVICES) + pcm->device;
  850. snd_pcm_devices[idx] = NULL;
  851. for (cidx = 0; cidx < 2; cidx++)
  852. for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
  853. if (substream->runtime)
  854. substream->runtime->status->state = SNDRV_PCM_STATE_DISCONNECTED;
  855. list_for_each(list, &snd_pcm_notify_list) {
  856. struct snd_pcm_notify *notify;
  857. notify = list_entry(list, struct snd_pcm_notify, list);
  858. notify->n_disconnect(pcm);
  859. }
  860. up(&register_mutex);
  861. return 0;
  862. }
  863. static int snd_pcm_dev_unregister(struct snd_device *device)
  864. {
  865. int idx, cidx, devtype;
  866. struct snd_pcm_substream *substream;
  867. struct list_head *list;
  868. struct snd_pcm *pcm = device->device_data;
  869. snd_assert(pcm != NULL, return -ENXIO);
  870. down(&register_mutex);
  871. idx = (pcm->card->number * SNDRV_PCM_DEVICES) + pcm->device;
  872. snd_pcm_devices[idx] = NULL;
  873. for (cidx = 0; cidx < 2; cidx++) {
  874. devtype = -1;
  875. switch (cidx) {
  876. case SNDRV_PCM_STREAM_PLAYBACK:
  877. devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK;
  878. break;
  879. case SNDRV_PCM_STREAM_CAPTURE:
  880. devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE;
  881. break;
  882. }
  883. snd_unregister_device(devtype, pcm->card, pcm->device);
  884. for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
  885. snd_pcm_timer_done(substream);
  886. }
  887. list_for_each(list, &snd_pcm_notify_list) {
  888. struct snd_pcm_notify *notify;
  889. notify = list_entry(list, struct snd_pcm_notify, list);
  890. notify->n_unregister(pcm);
  891. }
  892. up(&register_mutex);
  893. return snd_pcm_free(pcm);
  894. }
  895. int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree)
  896. {
  897. int idx;
  898. snd_assert(notify != NULL && notify->n_register != NULL && notify->n_unregister != NULL, return -EINVAL);
  899. down(&register_mutex);
  900. if (nfree) {
  901. list_del(&notify->list);
  902. for (idx = 0; idx < SNDRV_CARDS * SNDRV_PCM_DEVICES; idx++) {
  903. if (snd_pcm_devices[idx] == NULL)
  904. continue;
  905. notify->n_unregister(snd_pcm_devices[idx]);
  906. }
  907. } else {
  908. list_add_tail(&notify->list, &snd_pcm_notify_list);
  909. for (idx = 0; idx < SNDRV_CARDS * SNDRV_PCM_DEVICES; idx++) {
  910. if (snd_pcm_devices[idx] == NULL)
  911. continue;
  912. notify->n_register(snd_pcm_devices[idx]);
  913. }
  914. }
  915. up(&register_mutex);
  916. return 0;
  917. }
  918. /*
  919. * Info interface
  920. */
  921. static void snd_pcm_proc_read(struct snd_info_entry *entry,
  922. struct snd_info_buffer *buffer)
  923. {
  924. int idx;
  925. struct snd_pcm *pcm;
  926. down(&register_mutex);
  927. for (idx = 0; idx < SNDRV_CARDS * SNDRV_PCM_DEVICES; idx++) {
  928. pcm = snd_pcm_devices[idx];
  929. if (pcm == NULL)
  930. continue;
  931. snd_iprintf(buffer, "%02i-%02i: %s : %s", idx / SNDRV_PCM_DEVICES,
  932. idx % SNDRV_PCM_DEVICES, pcm->id, pcm->name);
  933. if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream)
  934. snd_iprintf(buffer, " : playback %i",
  935. pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream_count);
  936. if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream)
  937. snd_iprintf(buffer, " : capture %i",
  938. pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream_count);
  939. snd_iprintf(buffer, "\n");
  940. }
  941. up(&register_mutex);
  942. }
  943. /*
  944. * ENTRY functions
  945. */
  946. static struct snd_info_entry *snd_pcm_proc_entry = NULL;
  947. static int __init alsa_pcm_init(void)
  948. {
  949. struct snd_info_entry *entry;
  950. snd_ctl_register_ioctl(snd_pcm_control_ioctl);
  951. snd_ctl_register_ioctl_compat(snd_pcm_control_ioctl);
  952. if ((entry = snd_info_create_module_entry(THIS_MODULE, "pcm", NULL)) != NULL) {
  953. snd_info_set_text_ops(entry, NULL, SNDRV_CARDS * SNDRV_PCM_DEVICES * 128,
  954. snd_pcm_proc_read);
  955. if (snd_info_register(entry) < 0) {
  956. snd_info_free_entry(entry);
  957. entry = NULL;
  958. }
  959. }
  960. snd_pcm_proc_entry = entry;
  961. return 0;
  962. }
  963. static void __exit alsa_pcm_exit(void)
  964. {
  965. snd_ctl_unregister_ioctl(snd_pcm_control_ioctl);
  966. snd_ctl_unregister_ioctl_compat(snd_pcm_control_ioctl);
  967. if (snd_pcm_proc_entry) {
  968. snd_info_unregister(snd_pcm_proc_entry);
  969. snd_pcm_proc_entry = NULL;
  970. }
  971. }
  972. module_init(alsa_pcm_init)
  973. module_exit(alsa_pcm_exit)
  974. EXPORT_SYMBOL(snd_pcm_devices);
  975. EXPORT_SYMBOL(snd_pcm_new);
  976. EXPORT_SYMBOL(snd_pcm_new_stream);
  977. EXPORT_SYMBOL(snd_pcm_notify);
  978. EXPORT_SYMBOL(snd_pcm_open_substream);
  979. EXPORT_SYMBOL(snd_pcm_release_substream);
  980. EXPORT_SYMBOL(snd_pcm_format_name);
  981. /* pcm_native.c */
  982. EXPORT_SYMBOL(snd_pcm_link_rwlock);
  983. #ifdef CONFIG_PM
  984. EXPORT_SYMBOL(snd_pcm_suspend);
  985. EXPORT_SYMBOL(snd_pcm_suspend_all);
  986. #endif
  987. EXPORT_SYMBOL(snd_pcm_kernel_playback_ioctl);
  988. EXPORT_SYMBOL(snd_pcm_kernel_capture_ioctl);
  989. EXPORT_SYMBOL(snd_pcm_kernel_ioctl);
  990. EXPORT_SYMBOL(snd_pcm_mmap_data);
  991. #if SNDRV_PCM_INFO_MMAP_IOMEM
  992. EXPORT_SYMBOL(snd_pcm_lib_mmap_iomem);
  993. #endif
  994. /* pcm_misc.c */
  995. EXPORT_SYMBOL(snd_pcm_format_signed);
  996. EXPORT_SYMBOL(snd_pcm_format_unsigned);
  997. EXPORT_SYMBOL(snd_pcm_format_linear);
  998. EXPORT_SYMBOL(snd_pcm_format_little_endian);
  999. EXPORT_SYMBOL(snd_pcm_format_big_endian);
  1000. EXPORT_SYMBOL(snd_pcm_format_width);
  1001. EXPORT_SYMBOL(snd_pcm_format_physical_width);
  1002. EXPORT_SYMBOL(snd_pcm_format_size);
  1003. EXPORT_SYMBOL(snd_pcm_format_silence_64);
  1004. EXPORT_SYMBOL(snd_pcm_format_set_silence);
  1005. EXPORT_SYMBOL(snd_pcm_build_linear_format);
  1006. EXPORT_SYMBOL(snd_pcm_limit_hw_rates);