pcm.c 33 KB

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