pcm.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  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/time.h>
  24. #include <linux/mutex.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@perex.cz>, Abramo Bagnara <abramo@alsa-project.org>");
  31. MODULE_DESCRIPTION("Midlevel PCM code for ALSA.");
  32. MODULE_LICENSE("GPL");
  33. static LIST_HEAD(snd_pcm_devices);
  34. static LIST_HEAD(snd_pcm_notify_list);
  35. static DEFINE_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 struct snd_pcm *snd_pcm_get(struct snd_card *card, int device)
  41. {
  42. struct snd_pcm *pcm;
  43. list_for_each_entry(pcm, &snd_pcm_devices, list) {
  44. if (pcm->card == card && pcm->device == device)
  45. return pcm;
  46. }
  47. return NULL;
  48. }
  49. static int snd_pcm_next(struct snd_card *card, int device)
  50. {
  51. struct snd_pcm *pcm;
  52. list_for_each_entry(pcm, &snd_pcm_devices, list) {
  53. if (pcm->card == card && pcm->device > device)
  54. return pcm->device;
  55. else if (pcm->card->number > card->number)
  56. return -1;
  57. }
  58. return -1;
  59. }
  60. static int snd_pcm_add(struct snd_pcm *newpcm)
  61. {
  62. struct snd_pcm *pcm;
  63. list_for_each_entry(pcm, &snd_pcm_devices, list) {
  64. if (pcm->card == newpcm->card && pcm->device == newpcm->device)
  65. return -EBUSY;
  66. if (pcm->card->number > newpcm->card->number ||
  67. (pcm->card == newpcm->card &&
  68. pcm->device > newpcm->device)) {
  69. list_add(&newpcm->list, pcm->list.prev);
  70. return 0;
  71. }
  72. }
  73. list_add_tail(&newpcm->list, &snd_pcm_devices);
  74. return 0;
  75. }
  76. static int snd_pcm_control_ioctl(struct snd_card *card,
  77. struct snd_ctl_file *control,
  78. unsigned int cmd, unsigned long arg)
  79. {
  80. switch (cmd) {
  81. case SNDRV_CTL_IOCTL_PCM_NEXT_DEVICE:
  82. {
  83. int device;
  84. if (get_user(device, (int __user *)arg))
  85. return -EFAULT;
  86. mutex_lock(&register_mutex);
  87. device = snd_pcm_next(card, device);
  88. mutex_unlock(&register_mutex);
  89. if (put_user(device, (int __user *)arg))
  90. return -EFAULT;
  91. return 0;
  92. }
  93. case SNDRV_CTL_IOCTL_PCM_INFO:
  94. {
  95. struct snd_pcm_info __user *info;
  96. unsigned int device, subdevice;
  97. int stream;
  98. struct snd_pcm *pcm;
  99. struct snd_pcm_str *pstr;
  100. struct snd_pcm_substream *substream;
  101. int err;
  102. info = (struct snd_pcm_info __user *)arg;
  103. if (get_user(device, &info->device))
  104. return -EFAULT;
  105. if (get_user(stream, &info->stream))
  106. return -EFAULT;
  107. if (stream < 0 || stream > 1)
  108. return -EINVAL;
  109. if (get_user(subdevice, &info->subdevice))
  110. return -EFAULT;
  111. mutex_lock(&register_mutex);
  112. pcm = snd_pcm_get(card, device);
  113. if (pcm == NULL) {
  114. err = -ENXIO;
  115. goto _error;
  116. }
  117. pstr = &pcm->streams[stream];
  118. if (pstr->substream_count == 0) {
  119. err = -ENOENT;
  120. goto _error;
  121. }
  122. if (subdevice >= pstr->substream_count) {
  123. err = -ENXIO;
  124. goto _error;
  125. }
  126. for (substream = pstr->substream; substream;
  127. substream = substream->next)
  128. if (substream->number == (int)subdevice)
  129. break;
  130. if (substream == NULL) {
  131. err = -ENXIO;
  132. goto _error;
  133. }
  134. err = snd_pcm_info_user(substream, info);
  135. _error:
  136. mutex_unlock(&register_mutex);
  137. return err;
  138. }
  139. case SNDRV_CTL_IOCTL_PCM_PREFER_SUBDEVICE:
  140. {
  141. int val;
  142. if (get_user(val, (int __user *)arg))
  143. return -EFAULT;
  144. control->prefer_pcm_subdevice = val;
  145. return 0;
  146. }
  147. }
  148. return -ENOIOCTLCMD;
  149. }
  150. #define FORMAT(v) [SNDRV_PCM_FORMAT_##v] = #v
  151. static char *snd_pcm_format_names[] = {
  152. FORMAT(S8),
  153. FORMAT(U8),
  154. FORMAT(S16_LE),
  155. FORMAT(S16_BE),
  156. FORMAT(U16_LE),
  157. FORMAT(U16_BE),
  158. FORMAT(S24_LE),
  159. FORMAT(S24_BE),
  160. FORMAT(U24_LE),
  161. FORMAT(U24_BE),
  162. FORMAT(S32_LE),
  163. FORMAT(S32_BE),
  164. FORMAT(U32_LE),
  165. FORMAT(U32_BE),
  166. FORMAT(FLOAT_LE),
  167. FORMAT(FLOAT_BE),
  168. FORMAT(FLOAT64_LE),
  169. FORMAT(FLOAT64_BE),
  170. FORMAT(IEC958_SUBFRAME_LE),
  171. FORMAT(IEC958_SUBFRAME_BE),
  172. FORMAT(MU_LAW),
  173. FORMAT(A_LAW),
  174. FORMAT(IMA_ADPCM),
  175. FORMAT(MPEG),
  176. FORMAT(GSM),
  177. FORMAT(SPECIAL),
  178. FORMAT(S24_3LE),
  179. FORMAT(S24_3BE),
  180. FORMAT(U24_3LE),
  181. FORMAT(U24_3BE),
  182. FORMAT(S20_3LE),
  183. FORMAT(S20_3BE),
  184. FORMAT(U20_3LE),
  185. FORMAT(U20_3BE),
  186. FORMAT(S18_3LE),
  187. FORMAT(S18_3BE),
  188. FORMAT(U18_3LE),
  189. FORMAT(U18_3BE),
  190. FORMAT(G723_24),
  191. FORMAT(G723_24_1B),
  192. FORMAT(G723_40),
  193. FORMAT(G723_40_1B),
  194. };
  195. const char *snd_pcm_format_name(snd_pcm_format_t format)
  196. {
  197. if (format >= ARRAY_SIZE(snd_pcm_format_names))
  198. return "Unknown";
  199. return snd_pcm_format_names[format];
  200. }
  201. EXPORT_SYMBOL_GPL(snd_pcm_format_name);
  202. #ifdef CONFIG_SND_VERBOSE_PROCFS
  203. #define STATE(v) [SNDRV_PCM_STATE_##v] = #v
  204. #define STREAM(v) [SNDRV_PCM_STREAM_##v] = #v
  205. #define READY(v) [SNDRV_PCM_READY_##v] = #v
  206. #define XRUN(v) [SNDRV_PCM_XRUN_##v] = #v
  207. #define SILENCE(v) [SNDRV_PCM_SILENCE_##v] = #v
  208. #define TSTAMP(v) [SNDRV_PCM_TSTAMP_##v] = #v
  209. #define ACCESS(v) [SNDRV_PCM_ACCESS_##v] = #v
  210. #define START(v) [SNDRV_PCM_START_##v] = #v
  211. #define SUBFORMAT(v) [SNDRV_PCM_SUBFORMAT_##v] = #v
  212. static char *snd_pcm_stream_names[] = {
  213. STREAM(PLAYBACK),
  214. STREAM(CAPTURE),
  215. };
  216. static char *snd_pcm_state_names[] = {
  217. STATE(OPEN),
  218. STATE(SETUP),
  219. STATE(PREPARED),
  220. STATE(RUNNING),
  221. STATE(XRUN),
  222. STATE(DRAINING),
  223. STATE(PAUSED),
  224. STATE(SUSPENDED),
  225. };
  226. static char *snd_pcm_access_names[] = {
  227. ACCESS(MMAP_INTERLEAVED),
  228. ACCESS(MMAP_NONINTERLEAVED),
  229. ACCESS(MMAP_COMPLEX),
  230. ACCESS(RW_INTERLEAVED),
  231. ACCESS(RW_NONINTERLEAVED),
  232. };
  233. static char *snd_pcm_subformat_names[] = {
  234. SUBFORMAT(STD),
  235. };
  236. static char *snd_pcm_tstamp_mode_names[] = {
  237. TSTAMP(NONE),
  238. TSTAMP(ENABLE),
  239. };
  240. static const char *snd_pcm_stream_name(int stream)
  241. {
  242. return snd_pcm_stream_names[stream];
  243. }
  244. static const char *snd_pcm_access_name(snd_pcm_access_t access)
  245. {
  246. return snd_pcm_access_names[access];
  247. }
  248. static const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat)
  249. {
  250. return snd_pcm_subformat_names[subformat];
  251. }
  252. static const char *snd_pcm_tstamp_mode_name(int mode)
  253. {
  254. return snd_pcm_tstamp_mode_names[mode];
  255. }
  256. static const char *snd_pcm_state_name(snd_pcm_state_t state)
  257. {
  258. return snd_pcm_state_names[state];
  259. }
  260. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  261. #include <linux/soundcard.h>
  262. static const char *snd_pcm_oss_format_name(int format)
  263. {
  264. switch (format) {
  265. case AFMT_MU_LAW:
  266. return "MU_LAW";
  267. case AFMT_A_LAW:
  268. return "A_LAW";
  269. case AFMT_IMA_ADPCM:
  270. return "IMA_ADPCM";
  271. case AFMT_U8:
  272. return "U8";
  273. case AFMT_S16_LE:
  274. return "S16_LE";
  275. case AFMT_S16_BE:
  276. return "S16_BE";
  277. case AFMT_S8:
  278. return "S8";
  279. case AFMT_U16_LE:
  280. return "U16_LE";
  281. case AFMT_U16_BE:
  282. return "U16_BE";
  283. case AFMT_MPEG:
  284. return "MPEG";
  285. default:
  286. return "unknown";
  287. }
  288. }
  289. #endif
  290. static void snd_pcm_proc_info_read(struct snd_pcm_substream *substream,
  291. struct snd_info_buffer *buffer)
  292. {
  293. struct snd_pcm_info *info;
  294. int err;
  295. if (! substream)
  296. return;
  297. info = kmalloc(sizeof(*info), GFP_KERNEL);
  298. if (! info) {
  299. printk(KERN_DEBUG "snd_pcm_proc_info_read: cannot malloc\n");
  300. return;
  301. }
  302. err = snd_pcm_info(substream, info);
  303. if (err < 0) {
  304. snd_iprintf(buffer, "error %d\n", err);
  305. kfree(info);
  306. return;
  307. }
  308. snd_iprintf(buffer, "card: %d\n", info->card);
  309. snd_iprintf(buffer, "device: %d\n", info->device);
  310. snd_iprintf(buffer, "subdevice: %d\n", info->subdevice);
  311. snd_iprintf(buffer, "stream: %s\n", snd_pcm_stream_name(info->stream));
  312. snd_iprintf(buffer, "id: %s\n", info->id);
  313. snd_iprintf(buffer, "name: %s\n", info->name);
  314. snd_iprintf(buffer, "subname: %s\n", info->subname);
  315. snd_iprintf(buffer, "class: %d\n", info->dev_class);
  316. snd_iprintf(buffer, "subclass: %d\n", info->dev_subclass);
  317. snd_iprintf(buffer, "subdevices_count: %d\n", info->subdevices_count);
  318. snd_iprintf(buffer, "subdevices_avail: %d\n", info->subdevices_avail);
  319. kfree(info);
  320. }
  321. static void snd_pcm_stream_proc_info_read(struct snd_info_entry *entry,
  322. struct snd_info_buffer *buffer)
  323. {
  324. snd_pcm_proc_info_read(((struct snd_pcm_str *)entry->private_data)->substream,
  325. buffer);
  326. }
  327. static void snd_pcm_substream_proc_info_read(struct snd_info_entry *entry,
  328. struct snd_info_buffer *buffer)
  329. {
  330. snd_pcm_proc_info_read((struct snd_pcm_substream *)entry->private_data,
  331. 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) {
  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. err = snd_pcm_substream_proc_init(substream);
  617. if (err < 0) {
  618. snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n");
  619. if (prev == NULL)
  620. pstr->substream = NULL;
  621. else
  622. prev->next = NULL;
  623. kfree(substream);
  624. return err;
  625. }
  626. substream->group = &substream->self_group;
  627. spin_lock_init(&substream->self_group.lock);
  628. INIT_LIST_HEAD(&substream->self_group.substreams);
  629. list_add_tail(&substream->link_list, &substream->self_group.substreams);
  630. atomic_set(&substream->mmap_count, 0);
  631. prev = substream;
  632. }
  633. return 0;
  634. }
  635. EXPORT_SYMBOL(snd_pcm_new_stream);
  636. /**
  637. * snd_pcm_new - create a new PCM instance
  638. * @card: the card instance
  639. * @id: the id string
  640. * @device: the device index (zero based)
  641. * @playback_count: the number of substreams for playback
  642. * @capture_count: the number of substreams for capture
  643. * @rpcm: the pointer to store the new pcm instance
  644. *
  645. * Creates a new PCM instance.
  646. *
  647. * The pcm operators have to be set afterwards to the new instance
  648. * via snd_pcm_set_ops().
  649. *
  650. * Returns zero if successful, or a negative error code on failure.
  651. */
  652. int snd_pcm_new(struct snd_card *card, const char *id, int device,
  653. int playback_count, int capture_count,
  654. struct snd_pcm ** rpcm)
  655. {
  656. struct snd_pcm *pcm;
  657. int err;
  658. static struct snd_device_ops ops = {
  659. .dev_free = snd_pcm_dev_free,
  660. .dev_register = snd_pcm_dev_register,
  661. .dev_disconnect = snd_pcm_dev_disconnect,
  662. };
  663. if (snd_BUG_ON(!card))
  664. return -ENXIO;
  665. if (rpcm)
  666. *rpcm = NULL;
  667. pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
  668. if (pcm == NULL) {
  669. snd_printk(KERN_ERR "Cannot allocate PCM\n");
  670. return -ENOMEM;
  671. }
  672. pcm->card = card;
  673. pcm->device = device;
  674. if (id)
  675. strlcpy(pcm->id, id, sizeof(pcm->id));
  676. if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) {
  677. snd_pcm_free(pcm);
  678. return err;
  679. }
  680. if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_CAPTURE, capture_count)) < 0) {
  681. snd_pcm_free(pcm);
  682. return err;
  683. }
  684. mutex_init(&pcm->open_mutex);
  685. init_waitqueue_head(&pcm->open_wait);
  686. if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) {
  687. snd_pcm_free(pcm);
  688. return err;
  689. }
  690. if (rpcm)
  691. *rpcm = pcm;
  692. return 0;
  693. }
  694. EXPORT_SYMBOL(snd_pcm_new);
  695. static void snd_pcm_free_stream(struct snd_pcm_str * pstr)
  696. {
  697. struct snd_pcm_substream *substream, *substream_next;
  698. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  699. struct snd_pcm_oss_setup *setup, *setupn;
  700. #endif
  701. substream = pstr->substream;
  702. while (substream) {
  703. substream_next = substream->next;
  704. snd_pcm_timer_done(substream);
  705. snd_pcm_substream_proc_done(substream);
  706. kfree(substream);
  707. substream = substream_next;
  708. }
  709. snd_pcm_stream_proc_done(pstr);
  710. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  711. for (setup = pstr->oss.setup_list; setup; setup = setupn) {
  712. setupn = setup->next;
  713. kfree(setup->task_name);
  714. kfree(setup);
  715. }
  716. #endif
  717. }
  718. static int snd_pcm_free(struct snd_pcm *pcm)
  719. {
  720. struct snd_pcm_notify *notify;
  721. if (!pcm)
  722. return 0;
  723. list_for_each_entry(notify, &snd_pcm_notify_list, list) {
  724. notify->n_unregister(pcm);
  725. }
  726. if (pcm->private_free)
  727. pcm->private_free(pcm);
  728. snd_pcm_lib_preallocate_free_for_all(pcm);
  729. snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_PLAYBACK]);
  730. snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_CAPTURE]);
  731. kfree(pcm);
  732. return 0;
  733. }
  734. static int snd_pcm_dev_free(struct snd_device *device)
  735. {
  736. struct snd_pcm *pcm = device->device_data;
  737. return snd_pcm_free(pcm);
  738. }
  739. int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
  740. struct file *file,
  741. struct snd_pcm_substream **rsubstream)
  742. {
  743. struct snd_pcm_str * pstr;
  744. struct snd_pcm_substream *substream;
  745. struct snd_pcm_runtime *runtime;
  746. struct snd_ctl_file *kctl;
  747. struct snd_card *card;
  748. int prefer_subdevice = -1;
  749. size_t size;
  750. if (snd_BUG_ON(!pcm || !rsubstream))
  751. return -ENXIO;
  752. *rsubstream = NULL;
  753. pstr = &pcm->streams[stream];
  754. if (pstr->substream == NULL || pstr->substream_count == 0)
  755. return -ENODEV;
  756. card = pcm->card;
  757. read_lock(&card->ctl_files_rwlock);
  758. list_for_each_entry(kctl, &card->ctl_files, list) {
  759. if (kctl->pid == task_pid(current)) {
  760. prefer_subdevice = kctl->prefer_pcm_subdevice;
  761. if (prefer_subdevice != -1)
  762. break;
  763. }
  764. }
  765. read_unlock(&card->ctl_files_rwlock);
  766. switch (stream) {
  767. case SNDRV_PCM_STREAM_PLAYBACK:
  768. if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) {
  769. for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next) {
  770. if (SUBSTREAM_BUSY(substream))
  771. return -EAGAIN;
  772. }
  773. }
  774. break;
  775. case SNDRV_PCM_STREAM_CAPTURE:
  776. if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) {
  777. for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) {
  778. if (SUBSTREAM_BUSY(substream))
  779. return -EAGAIN;
  780. }
  781. }
  782. break;
  783. default:
  784. return -EINVAL;
  785. }
  786. if (file->f_flags & O_APPEND) {
  787. if (prefer_subdevice < 0) {
  788. if (pstr->substream_count > 1)
  789. return -EINVAL; /* must be unique */
  790. substream = pstr->substream;
  791. } else {
  792. for (substream = pstr->substream; substream;
  793. substream = substream->next)
  794. if (substream->number == prefer_subdevice)
  795. break;
  796. }
  797. if (! substream)
  798. return -ENODEV;
  799. if (! SUBSTREAM_BUSY(substream))
  800. return -EBADFD;
  801. substream->ref_count++;
  802. *rsubstream = substream;
  803. return 0;
  804. }
  805. if (prefer_subdevice >= 0) {
  806. for (substream = pstr->substream; substream; substream = substream->next)
  807. if (!SUBSTREAM_BUSY(substream) && substream->number == prefer_subdevice)
  808. goto __ok;
  809. }
  810. for (substream = pstr->substream; substream; substream = substream->next)
  811. if (!SUBSTREAM_BUSY(substream))
  812. break;
  813. __ok:
  814. if (substream == NULL)
  815. return -EAGAIN;
  816. runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
  817. if (runtime == NULL)
  818. return -ENOMEM;
  819. size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status));
  820. runtime->status = snd_malloc_pages(size, GFP_KERNEL);
  821. if (runtime->status == NULL) {
  822. kfree(runtime);
  823. return -ENOMEM;
  824. }
  825. memset((void*)runtime->status, 0, size);
  826. size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control));
  827. runtime->control = snd_malloc_pages(size, GFP_KERNEL);
  828. if (runtime->control == NULL) {
  829. snd_free_pages((void*)runtime->status,
  830. PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
  831. kfree(runtime);
  832. return -ENOMEM;
  833. }
  834. memset((void*)runtime->control, 0, size);
  835. init_waitqueue_head(&runtime->sleep);
  836. init_waitqueue_head(&runtime->tsleep);
  837. runtime->status->state = SNDRV_PCM_STATE_OPEN;
  838. substream->runtime = runtime;
  839. substream->private_data = pcm->private_data;
  840. substream->ref_count = 1;
  841. substream->f_flags = file->f_flags;
  842. substream->pid = get_pid(task_pid(current));
  843. pstr->substream_opened++;
  844. *rsubstream = substream;
  845. return 0;
  846. }
  847. void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
  848. {
  849. struct snd_pcm_runtime *runtime;
  850. if (PCM_RUNTIME_CHECK(substream))
  851. return;
  852. runtime = substream->runtime;
  853. if (runtime->private_free != NULL)
  854. runtime->private_free(runtime);
  855. snd_free_pages((void*)runtime->status,
  856. PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
  857. snd_free_pages((void*)runtime->control,
  858. PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)));
  859. kfree(runtime->hw_constraints.rules);
  860. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  861. if (runtime->hwptr_log)
  862. kfree(runtime->hwptr_log);
  863. #endif
  864. kfree(runtime);
  865. substream->runtime = NULL;
  866. put_pid(substream->pid);
  867. substream->pid = NULL;
  868. substream->pstr->substream_opened--;
  869. }
  870. static ssize_t show_pcm_class(struct device *dev,
  871. struct device_attribute *attr, char *buf)
  872. {
  873. struct snd_pcm *pcm;
  874. const char *str;
  875. static const char *strs[SNDRV_PCM_CLASS_LAST + 1] = {
  876. [SNDRV_PCM_CLASS_GENERIC] = "generic",
  877. [SNDRV_PCM_CLASS_MULTI] = "multi",
  878. [SNDRV_PCM_CLASS_MODEM] = "modem",
  879. [SNDRV_PCM_CLASS_DIGITIZER] = "digitizer",
  880. };
  881. if (! (pcm = dev_get_drvdata(dev)) ||
  882. pcm->dev_class > SNDRV_PCM_CLASS_LAST)
  883. str = "none";
  884. else
  885. str = strs[pcm->dev_class];
  886. return snprintf(buf, PAGE_SIZE, "%s\n", str);
  887. }
  888. static struct device_attribute pcm_attrs =
  889. __ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL);
  890. static int snd_pcm_dev_register(struct snd_device *device)
  891. {
  892. int cidx, err;
  893. struct snd_pcm_substream *substream;
  894. struct snd_pcm_notify *notify;
  895. char str[16];
  896. struct snd_pcm *pcm;
  897. struct device *dev;
  898. if (snd_BUG_ON(!device || !device->device_data))
  899. return -ENXIO;
  900. pcm = device->device_data;
  901. mutex_lock(&register_mutex);
  902. err = snd_pcm_add(pcm);
  903. if (err) {
  904. mutex_unlock(&register_mutex);
  905. return err;
  906. }
  907. for (cidx = 0; cidx < 2; cidx++) {
  908. int devtype = -1;
  909. if (pcm->streams[cidx].substream == NULL)
  910. continue;
  911. switch (cidx) {
  912. case SNDRV_PCM_STREAM_PLAYBACK:
  913. sprintf(str, "pcmC%iD%ip", pcm->card->number, pcm->device);
  914. devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK;
  915. break;
  916. case SNDRV_PCM_STREAM_CAPTURE:
  917. sprintf(str, "pcmC%iD%ic", pcm->card->number, pcm->device);
  918. devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE;
  919. break;
  920. }
  921. /* device pointer to use, pcm->dev takes precedence if
  922. * it is assigned, otherwise fall back to card's device
  923. * if possible */
  924. dev = pcm->dev;
  925. if (!dev)
  926. dev = snd_card_get_device_link(pcm->card);
  927. /* register pcm */
  928. err = snd_register_device_for_dev(devtype, pcm->card,
  929. pcm->device,
  930. &snd_pcm_f_ops[cidx],
  931. pcm, str, dev);
  932. if (err < 0) {
  933. list_del(&pcm->list);
  934. mutex_unlock(&register_mutex);
  935. return err;
  936. }
  937. snd_add_device_sysfs_file(devtype, pcm->card, pcm->device,
  938. &pcm_attrs);
  939. for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
  940. snd_pcm_timer_init(substream);
  941. }
  942. list_for_each_entry(notify, &snd_pcm_notify_list, list)
  943. notify->n_register(pcm);
  944. mutex_unlock(&register_mutex);
  945. return 0;
  946. }
  947. static int snd_pcm_dev_disconnect(struct snd_device *device)
  948. {
  949. struct snd_pcm *pcm = device->device_data;
  950. struct snd_pcm_notify *notify;
  951. struct snd_pcm_substream *substream;
  952. int cidx, devtype;
  953. mutex_lock(&register_mutex);
  954. if (list_empty(&pcm->list))
  955. goto unlock;
  956. list_del_init(&pcm->list);
  957. for (cidx = 0; cidx < 2; cidx++)
  958. for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
  959. if (substream->runtime)
  960. substream->runtime->status->state = SNDRV_PCM_STATE_DISCONNECTED;
  961. list_for_each_entry(notify, &snd_pcm_notify_list, list) {
  962. notify->n_disconnect(pcm);
  963. }
  964. for (cidx = 0; cidx < 2; cidx++) {
  965. devtype = -1;
  966. switch (cidx) {
  967. case SNDRV_PCM_STREAM_PLAYBACK:
  968. devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK;
  969. break;
  970. case SNDRV_PCM_STREAM_CAPTURE:
  971. devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE;
  972. break;
  973. }
  974. snd_unregister_device(devtype, pcm->card, pcm->device);
  975. }
  976. unlock:
  977. mutex_unlock(&register_mutex);
  978. return 0;
  979. }
  980. int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree)
  981. {
  982. struct snd_pcm *pcm;
  983. if (snd_BUG_ON(!notify ||
  984. !notify->n_register ||
  985. !notify->n_unregister ||
  986. !notify->n_disconnect))
  987. return -EINVAL;
  988. mutex_lock(&register_mutex);
  989. if (nfree) {
  990. list_del(&notify->list);
  991. list_for_each_entry(pcm, &snd_pcm_devices, list)
  992. notify->n_unregister(pcm);
  993. } else {
  994. list_add_tail(&notify->list, &snd_pcm_notify_list);
  995. list_for_each_entry(pcm, &snd_pcm_devices, list)
  996. notify->n_register(pcm);
  997. }
  998. mutex_unlock(&register_mutex);
  999. return 0;
  1000. }
  1001. EXPORT_SYMBOL(snd_pcm_notify);
  1002. #ifdef CONFIG_PROC_FS
  1003. /*
  1004. * Info interface
  1005. */
  1006. static void snd_pcm_proc_read(struct snd_info_entry *entry,
  1007. struct snd_info_buffer *buffer)
  1008. {
  1009. struct snd_pcm *pcm;
  1010. mutex_lock(&register_mutex);
  1011. list_for_each_entry(pcm, &snd_pcm_devices, list) {
  1012. snd_iprintf(buffer, "%02i-%02i: %s : %s",
  1013. pcm->card->number, pcm->device, pcm->id, pcm->name);
  1014. if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream)
  1015. snd_iprintf(buffer, " : playback %i",
  1016. pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream_count);
  1017. if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream)
  1018. snd_iprintf(buffer, " : capture %i",
  1019. pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream_count);
  1020. snd_iprintf(buffer, "\n");
  1021. }
  1022. mutex_unlock(&register_mutex);
  1023. }
  1024. static struct snd_info_entry *snd_pcm_proc_entry;
  1025. static void snd_pcm_proc_init(void)
  1026. {
  1027. struct snd_info_entry *entry;
  1028. if ((entry = snd_info_create_module_entry(THIS_MODULE, "pcm", NULL)) != NULL) {
  1029. snd_info_set_text_ops(entry, NULL, snd_pcm_proc_read);
  1030. if (snd_info_register(entry) < 0) {
  1031. snd_info_free_entry(entry);
  1032. entry = NULL;
  1033. }
  1034. }
  1035. snd_pcm_proc_entry = entry;
  1036. }
  1037. static void snd_pcm_proc_done(void)
  1038. {
  1039. snd_info_free_entry(snd_pcm_proc_entry);
  1040. }
  1041. #else /* !CONFIG_PROC_FS */
  1042. #define snd_pcm_proc_init()
  1043. #define snd_pcm_proc_done()
  1044. #endif /* CONFIG_PROC_FS */
  1045. /*
  1046. * ENTRY functions
  1047. */
  1048. static int __init alsa_pcm_init(void)
  1049. {
  1050. snd_ctl_register_ioctl(snd_pcm_control_ioctl);
  1051. snd_ctl_register_ioctl_compat(snd_pcm_control_ioctl);
  1052. snd_pcm_proc_init();
  1053. return 0;
  1054. }
  1055. static void __exit alsa_pcm_exit(void)
  1056. {
  1057. snd_ctl_unregister_ioctl(snd_pcm_control_ioctl);
  1058. snd_ctl_unregister_ioctl_compat(snd_pcm_control_ioctl);
  1059. snd_pcm_proc_done();
  1060. }
  1061. module_init(alsa_pcm_init)
  1062. module_exit(alsa_pcm_exit)