pcm.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  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. };
  191. const char *snd_pcm_format_name(snd_pcm_format_t format)
  192. {
  193. return snd_pcm_format_names[format];
  194. }
  195. EXPORT_SYMBOL_GPL(snd_pcm_format_name);
  196. #ifdef CONFIG_SND_VERBOSE_PROCFS
  197. #define STATE(v) [SNDRV_PCM_STATE_##v] = #v
  198. #define STREAM(v) [SNDRV_PCM_STREAM_##v] = #v
  199. #define READY(v) [SNDRV_PCM_READY_##v] = #v
  200. #define XRUN(v) [SNDRV_PCM_XRUN_##v] = #v
  201. #define SILENCE(v) [SNDRV_PCM_SILENCE_##v] = #v
  202. #define TSTAMP(v) [SNDRV_PCM_TSTAMP_##v] = #v
  203. #define ACCESS(v) [SNDRV_PCM_ACCESS_##v] = #v
  204. #define START(v) [SNDRV_PCM_START_##v] = #v
  205. #define SUBFORMAT(v) [SNDRV_PCM_SUBFORMAT_##v] = #v
  206. static char *snd_pcm_stream_names[] = {
  207. STREAM(PLAYBACK),
  208. STREAM(CAPTURE),
  209. };
  210. static char *snd_pcm_state_names[] = {
  211. STATE(OPEN),
  212. STATE(SETUP),
  213. STATE(PREPARED),
  214. STATE(RUNNING),
  215. STATE(XRUN),
  216. STATE(DRAINING),
  217. STATE(PAUSED),
  218. STATE(SUSPENDED),
  219. };
  220. static char *snd_pcm_access_names[] = {
  221. ACCESS(MMAP_INTERLEAVED),
  222. ACCESS(MMAP_NONINTERLEAVED),
  223. ACCESS(MMAP_COMPLEX),
  224. ACCESS(RW_INTERLEAVED),
  225. ACCESS(RW_NONINTERLEAVED),
  226. };
  227. static char *snd_pcm_subformat_names[] = {
  228. SUBFORMAT(STD),
  229. };
  230. static char *snd_pcm_tstamp_mode_names[] = {
  231. TSTAMP(NONE),
  232. TSTAMP(ENABLE),
  233. };
  234. static const char *snd_pcm_stream_name(int stream)
  235. {
  236. return snd_pcm_stream_names[stream];
  237. }
  238. static const char *snd_pcm_access_name(snd_pcm_access_t access)
  239. {
  240. return snd_pcm_access_names[access];
  241. }
  242. static const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat)
  243. {
  244. return snd_pcm_subformat_names[subformat];
  245. }
  246. static const char *snd_pcm_tstamp_mode_name(int mode)
  247. {
  248. return snd_pcm_tstamp_mode_names[mode];
  249. }
  250. static const char *snd_pcm_state_name(snd_pcm_state_t state)
  251. {
  252. return snd_pcm_state_names[state];
  253. }
  254. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  255. #include <linux/soundcard.h>
  256. static const char *snd_pcm_oss_format_name(int format)
  257. {
  258. switch (format) {
  259. case AFMT_MU_LAW:
  260. return "MU_LAW";
  261. case AFMT_A_LAW:
  262. return "A_LAW";
  263. case AFMT_IMA_ADPCM:
  264. return "IMA_ADPCM";
  265. case AFMT_U8:
  266. return "U8";
  267. case AFMT_S16_LE:
  268. return "S16_LE";
  269. case AFMT_S16_BE:
  270. return "S16_BE";
  271. case AFMT_S8:
  272. return "S8";
  273. case AFMT_U16_LE:
  274. return "U16_LE";
  275. case AFMT_U16_BE:
  276. return "U16_BE";
  277. case AFMT_MPEG:
  278. return "MPEG";
  279. default:
  280. return "unknown";
  281. }
  282. }
  283. #endif
  284. static void snd_pcm_proc_info_read(struct snd_pcm_substream *substream,
  285. struct snd_info_buffer *buffer)
  286. {
  287. struct snd_pcm_info *info;
  288. int err;
  289. if (! substream)
  290. return;
  291. info = kmalloc(sizeof(*info), GFP_KERNEL);
  292. if (! info) {
  293. printk(KERN_DEBUG "snd_pcm_proc_info_read: cannot malloc\n");
  294. return;
  295. }
  296. err = snd_pcm_info(substream, info);
  297. if (err < 0) {
  298. snd_iprintf(buffer, "error %d\n", err);
  299. kfree(info);
  300. return;
  301. }
  302. snd_iprintf(buffer, "card: %d\n", info->card);
  303. snd_iprintf(buffer, "device: %d\n", info->device);
  304. snd_iprintf(buffer, "subdevice: %d\n", info->subdevice);
  305. snd_iprintf(buffer, "stream: %s\n", snd_pcm_stream_name(info->stream));
  306. snd_iprintf(buffer, "id: %s\n", info->id);
  307. snd_iprintf(buffer, "name: %s\n", info->name);
  308. snd_iprintf(buffer, "subname: %s\n", info->subname);
  309. snd_iprintf(buffer, "class: %d\n", info->dev_class);
  310. snd_iprintf(buffer, "subclass: %d\n", info->dev_subclass);
  311. snd_iprintf(buffer, "subdevices_count: %d\n", info->subdevices_count);
  312. snd_iprintf(buffer, "subdevices_avail: %d\n", info->subdevices_avail);
  313. kfree(info);
  314. }
  315. static void snd_pcm_stream_proc_info_read(struct snd_info_entry *entry,
  316. struct snd_info_buffer *buffer)
  317. {
  318. snd_pcm_proc_info_read(((struct snd_pcm_str *)entry->private_data)->substream,
  319. buffer);
  320. }
  321. static void snd_pcm_substream_proc_info_read(struct snd_info_entry *entry,
  322. struct snd_info_buffer *buffer)
  323. {
  324. snd_pcm_proc_info_read((struct snd_pcm_substream *)entry->private_data,
  325. buffer);
  326. }
  327. static void snd_pcm_substream_proc_hw_params_read(struct snd_info_entry *entry,
  328. struct snd_info_buffer *buffer)
  329. {
  330. struct snd_pcm_substream *substream = entry->private_data;
  331. struct snd_pcm_runtime *runtime = substream->runtime;
  332. if (!runtime) {
  333. snd_iprintf(buffer, "closed\n");
  334. return;
  335. }
  336. if (runtime->status->state == SNDRV_PCM_STATE_OPEN) {
  337. snd_iprintf(buffer, "no setup\n");
  338. return;
  339. }
  340. snd_iprintf(buffer, "access: %s\n", snd_pcm_access_name(runtime->access));
  341. snd_iprintf(buffer, "format: %s\n", snd_pcm_format_name(runtime->format));
  342. snd_iprintf(buffer, "subformat: %s\n", snd_pcm_subformat_name(runtime->subformat));
  343. snd_iprintf(buffer, "channels: %u\n", runtime->channels);
  344. snd_iprintf(buffer, "rate: %u (%u/%u)\n", runtime->rate, runtime->rate_num, runtime->rate_den);
  345. snd_iprintf(buffer, "period_size: %lu\n", runtime->period_size);
  346. snd_iprintf(buffer, "buffer_size: %lu\n", runtime->buffer_size);
  347. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  348. if (substream->oss.oss) {
  349. snd_iprintf(buffer, "OSS format: %s\n", snd_pcm_oss_format_name(runtime->oss.format));
  350. snd_iprintf(buffer, "OSS channels: %u\n", runtime->oss.channels);
  351. snd_iprintf(buffer, "OSS rate: %u\n", runtime->oss.rate);
  352. snd_iprintf(buffer, "OSS period bytes: %lu\n", (unsigned long)runtime->oss.period_bytes);
  353. snd_iprintf(buffer, "OSS periods: %u\n", runtime->oss.periods);
  354. snd_iprintf(buffer, "OSS period frames: %lu\n", (unsigned long)runtime->oss.period_frames);
  355. }
  356. #endif
  357. }
  358. static void snd_pcm_substream_proc_sw_params_read(struct snd_info_entry *entry,
  359. struct snd_info_buffer *buffer)
  360. {
  361. struct snd_pcm_substream *substream = entry->private_data;
  362. struct snd_pcm_runtime *runtime = substream->runtime;
  363. if (!runtime) {
  364. snd_iprintf(buffer, "closed\n");
  365. return;
  366. }
  367. if (runtime->status->state == SNDRV_PCM_STATE_OPEN) {
  368. snd_iprintf(buffer, "no setup\n");
  369. return;
  370. }
  371. snd_iprintf(buffer, "tstamp_mode: %s\n", snd_pcm_tstamp_mode_name(runtime->tstamp_mode));
  372. snd_iprintf(buffer, "period_step: %u\n", runtime->period_step);
  373. snd_iprintf(buffer, "avail_min: %lu\n", runtime->control->avail_min);
  374. snd_iprintf(buffer, "start_threshold: %lu\n", runtime->start_threshold);
  375. snd_iprintf(buffer, "stop_threshold: %lu\n", runtime->stop_threshold);
  376. snd_iprintf(buffer, "silence_threshold: %lu\n", runtime->silence_threshold);
  377. snd_iprintf(buffer, "silence_size: %lu\n", runtime->silence_size);
  378. snd_iprintf(buffer, "boundary: %lu\n", runtime->boundary);
  379. }
  380. static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry,
  381. struct snd_info_buffer *buffer)
  382. {
  383. struct snd_pcm_substream *substream = entry->private_data;
  384. struct snd_pcm_runtime *runtime = substream->runtime;
  385. struct snd_pcm_status status;
  386. int err;
  387. if (!runtime) {
  388. snd_iprintf(buffer, "closed\n");
  389. return;
  390. }
  391. memset(&status, 0, sizeof(status));
  392. err = snd_pcm_status(substream, &status);
  393. if (err < 0) {
  394. snd_iprintf(buffer, "error %d\n", err);
  395. return;
  396. }
  397. snd_iprintf(buffer, "state: %s\n", snd_pcm_state_name(status.state));
  398. snd_iprintf(buffer, "owner_pid : %d\n", pid_vnr(substream->pid));
  399. snd_iprintf(buffer, "trigger_time: %ld.%09ld\n",
  400. status.trigger_tstamp.tv_sec, status.trigger_tstamp.tv_nsec);
  401. snd_iprintf(buffer, "tstamp : %ld.%09ld\n",
  402. status.tstamp.tv_sec, status.tstamp.tv_nsec);
  403. snd_iprintf(buffer, "delay : %ld\n", status.delay);
  404. snd_iprintf(buffer, "avail : %ld\n", status.avail);
  405. snd_iprintf(buffer, "avail_max : %ld\n", status.avail_max);
  406. snd_iprintf(buffer, "-----\n");
  407. snd_iprintf(buffer, "hw_ptr : %ld\n", runtime->status->hw_ptr);
  408. snd_iprintf(buffer, "appl_ptr : %ld\n", runtime->control->appl_ptr);
  409. }
  410. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  411. static void snd_pcm_xrun_debug_read(struct snd_info_entry *entry,
  412. struct snd_info_buffer *buffer)
  413. {
  414. struct snd_pcm_str *pstr = entry->private_data;
  415. snd_iprintf(buffer, "%d\n", pstr->xrun_debug);
  416. }
  417. static void snd_pcm_xrun_debug_write(struct snd_info_entry *entry,
  418. struct snd_info_buffer *buffer)
  419. {
  420. struct snd_pcm_str *pstr = entry->private_data;
  421. char line[64];
  422. if (!snd_info_get_line(buffer, line, sizeof(line)))
  423. pstr->xrun_debug = simple_strtoul(line, NULL, 10);
  424. }
  425. #endif
  426. static int snd_pcm_stream_proc_init(struct snd_pcm_str *pstr)
  427. {
  428. struct snd_pcm *pcm = pstr->pcm;
  429. struct snd_info_entry *entry;
  430. char name[16];
  431. sprintf(name, "pcm%i%c", pcm->device,
  432. pstr->stream == SNDRV_PCM_STREAM_PLAYBACK ? 'p' : 'c');
  433. if ((entry = snd_info_create_card_entry(pcm->card, name, pcm->card->proc_root)) == NULL)
  434. return -ENOMEM;
  435. entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
  436. if (snd_info_register(entry) < 0) {
  437. snd_info_free_entry(entry);
  438. return -ENOMEM;
  439. }
  440. pstr->proc_root = entry;
  441. if ((entry = snd_info_create_card_entry(pcm->card, "info", pstr->proc_root)) != NULL) {
  442. snd_info_set_text_ops(entry, pstr, snd_pcm_stream_proc_info_read);
  443. if (snd_info_register(entry) < 0) {
  444. snd_info_free_entry(entry);
  445. entry = NULL;
  446. }
  447. }
  448. pstr->proc_info_entry = entry;
  449. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  450. if ((entry = snd_info_create_card_entry(pcm->card, "xrun_debug",
  451. pstr->proc_root)) != NULL) {
  452. entry->c.text.read = snd_pcm_xrun_debug_read;
  453. entry->c.text.write = snd_pcm_xrun_debug_write;
  454. entry->mode |= S_IWUSR;
  455. entry->private_data = pstr;
  456. if (snd_info_register(entry) < 0) {
  457. snd_info_free_entry(entry);
  458. entry = NULL;
  459. }
  460. }
  461. pstr->proc_xrun_debug_entry = entry;
  462. #endif
  463. return 0;
  464. }
  465. static int snd_pcm_stream_proc_done(struct snd_pcm_str *pstr)
  466. {
  467. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  468. snd_info_free_entry(pstr->proc_xrun_debug_entry);
  469. pstr->proc_xrun_debug_entry = NULL;
  470. #endif
  471. snd_info_free_entry(pstr->proc_info_entry);
  472. pstr->proc_info_entry = NULL;
  473. snd_info_free_entry(pstr->proc_root);
  474. pstr->proc_root = NULL;
  475. return 0;
  476. }
  477. static int snd_pcm_substream_proc_init(struct snd_pcm_substream *substream)
  478. {
  479. struct snd_info_entry *entry;
  480. struct snd_card *card;
  481. char name[16];
  482. card = substream->pcm->card;
  483. sprintf(name, "sub%i", substream->number);
  484. if ((entry = snd_info_create_card_entry(card, name, substream->pstr->proc_root)) == NULL)
  485. return -ENOMEM;
  486. entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
  487. if (snd_info_register(entry) < 0) {
  488. snd_info_free_entry(entry);
  489. return -ENOMEM;
  490. }
  491. substream->proc_root = entry;
  492. if ((entry = snd_info_create_card_entry(card, "info", substream->proc_root)) != NULL) {
  493. snd_info_set_text_ops(entry, substream,
  494. snd_pcm_substream_proc_info_read);
  495. if (snd_info_register(entry) < 0) {
  496. snd_info_free_entry(entry);
  497. entry = NULL;
  498. }
  499. }
  500. substream->proc_info_entry = entry;
  501. if ((entry = snd_info_create_card_entry(card, "hw_params", substream->proc_root)) != NULL) {
  502. snd_info_set_text_ops(entry, substream,
  503. snd_pcm_substream_proc_hw_params_read);
  504. if (snd_info_register(entry) < 0) {
  505. snd_info_free_entry(entry);
  506. entry = NULL;
  507. }
  508. }
  509. substream->proc_hw_params_entry = entry;
  510. if ((entry = snd_info_create_card_entry(card, "sw_params", substream->proc_root)) != NULL) {
  511. snd_info_set_text_ops(entry, substream,
  512. snd_pcm_substream_proc_sw_params_read);
  513. if (snd_info_register(entry) < 0) {
  514. snd_info_free_entry(entry);
  515. entry = NULL;
  516. }
  517. }
  518. substream->proc_sw_params_entry = entry;
  519. if ((entry = snd_info_create_card_entry(card, "status", substream->proc_root)) != NULL) {
  520. snd_info_set_text_ops(entry, substream,
  521. snd_pcm_substream_proc_status_read);
  522. if (snd_info_register(entry) < 0) {
  523. snd_info_free_entry(entry);
  524. entry = NULL;
  525. }
  526. }
  527. substream->proc_status_entry = entry;
  528. return 0;
  529. }
  530. static int snd_pcm_substream_proc_done(struct snd_pcm_substream *substream)
  531. {
  532. snd_info_free_entry(substream->proc_info_entry);
  533. substream->proc_info_entry = NULL;
  534. snd_info_free_entry(substream->proc_hw_params_entry);
  535. substream->proc_hw_params_entry = NULL;
  536. snd_info_free_entry(substream->proc_sw_params_entry);
  537. substream->proc_sw_params_entry = NULL;
  538. snd_info_free_entry(substream->proc_status_entry);
  539. substream->proc_status_entry = NULL;
  540. snd_info_free_entry(substream->proc_root);
  541. substream->proc_root = NULL;
  542. return 0;
  543. }
  544. #else /* !CONFIG_SND_VERBOSE_PROCFS */
  545. static inline int snd_pcm_stream_proc_init(struct snd_pcm_str *pstr) { return 0; }
  546. static inline int snd_pcm_stream_proc_done(struct snd_pcm_str *pstr) { return 0; }
  547. static inline int snd_pcm_substream_proc_init(struct snd_pcm_substream *substream) { return 0; }
  548. static inline int snd_pcm_substream_proc_done(struct snd_pcm_substream *substream) { return 0; }
  549. #endif /* CONFIG_SND_VERBOSE_PROCFS */
  550. /**
  551. * snd_pcm_new_stream - create a new PCM stream
  552. * @pcm: the pcm instance
  553. * @stream: the stream direction, SNDRV_PCM_STREAM_XXX
  554. * @substream_count: the number of substreams
  555. *
  556. * Creates a new stream for the pcm.
  557. * The corresponding stream on the pcm must have been empty before
  558. * calling this, i.e. zero must be given to the argument of
  559. * snd_pcm_new().
  560. *
  561. * Returns zero if successful, or a negative error code on failure.
  562. */
  563. int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
  564. {
  565. int idx, err;
  566. struct snd_pcm_str *pstr = &pcm->streams[stream];
  567. struct snd_pcm_substream *substream, *prev;
  568. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  569. mutex_init(&pstr->oss.setup_mutex);
  570. #endif
  571. pstr->stream = stream;
  572. pstr->pcm = pcm;
  573. pstr->substream_count = substream_count;
  574. if (substream_count > 0) {
  575. err = snd_pcm_stream_proc_init(pstr);
  576. if (err < 0) {
  577. snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n");
  578. return err;
  579. }
  580. }
  581. prev = NULL;
  582. for (idx = 0, prev = NULL; idx < substream_count; idx++) {
  583. substream = kzalloc(sizeof(*substream), GFP_KERNEL);
  584. if (substream == NULL) {
  585. snd_printk(KERN_ERR "Cannot allocate PCM substream\n");
  586. return -ENOMEM;
  587. }
  588. substream->pcm = pcm;
  589. substream->pstr = pstr;
  590. substream->number = idx;
  591. substream->stream = stream;
  592. sprintf(substream->name, "subdevice #%i", idx);
  593. snprintf(substream->latency_id, sizeof(substream->latency_id),
  594. "ALSA-PCM%d-%d%c%d", pcm->card->number, pcm->device,
  595. (stream ? 'c' : 'p'), idx);
  596. substream->buffer_bytes_max = UINT_MAX;
  597. if (prev == NULL)
  598. pstr->substream = substream;
  599. else
  600. prev->next = substream;
  601. err = snd_pcm_substream_proc_init(substream);
  602. if (err < 0) {
  603. snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n");
  604. if (prev == NULL)
  605. pstr->substream = NULL;
  606. else
  607. prev->next = NULL;
  608. kfree(substream);
  609. return err;
  610. }
  611. substream->group = &substream->self_group;
  612. spin_lock_init(&substream->self_group.lock);
  613. INIT_LIST_HEAD(&substream->self_group.substreams);
  614. list_add_tail(&substream->link_list, &substream->self_group.substreams);
  615. atomic_set(&substream->mmap_count, 0);
  616. prev = substream;
  617. }
  618. return 0;
  619. }
  620. EXPORT_SYMBOL(snd_pcm_new_stream);
  621. /**
  622. * snd_pcm_new - create a new PCM instance
  623. * @card: the card instance
  624. * @id: the id string
  625. * @device: the device index (zero based)
  626. * @playback_count: the number of substreams for playback
  627. * @capture_count: the number of substreams for capture
  628. * @rpcm: the pointer to store the new pcm instance
  629. *
  630. * Creates a new PCM instance.
  631. *
  632. * The pcm operators have to be set afterwards to the new instance
  633. * via snd_pcm_set_ops().
  634. *
  635. * Returns zero if successful, or a negative error code on failure.
  636. */
  637. int snd_pcm_new(struct snd_card *card, const char *id, int device,
  638. int playback_count, int capture_count,
  639. struct snd_pcm ** rpcm)
  640. {
  641. struct snd_pcm *pcm;
  642. int err;
  643. static struct snd_device_ops ops = {
  644. .dev_free = snd_pcm_dev_free,
  645. .dev_register = snd_pcm_dev_register,
  646. .dev_disconnect = snd_pcm_dev_disconnect,
  647. };
  648. if (snd_BUG_ON(!card))
  649. return -ENXIO;
  650. if (rpcm)
  651. *rpcm = NULL;
  652. pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
  653. if (pcm == NULL) {
  654. snd_printk(KERN_ERR "Cannot allocate PCM\n");
  655. return -ENOMEM;
  656. }
  657. pcm->card = card;
  658. pcm->device = device;
  659. if (id)
  660. strlcpy(pcm->id, id, sizeof(pcm->id));
  661. if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) {
  662. snd_pcm_free(pcm);
  663. return err;
  664. }
  665. if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_CAPTURE, capture_count)) < 0) {
  666. snd_pcm_free(pcm);
  667. return err;
  668. }
  669. mutex_init(&pcm->open_mutex);
  670. init_waitqueue_head(&pcm->open_wait);
  671. if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) {
  672. snd_pcm_free(pcm);
  673. return err;
  674. }
  675. if (rpcm)
  676. *rpcm = pcm;
  677. return 0;
  678. }
  679. EXPORT_SYMBOL(snd_pcm_new);
  680. static void snd_pcm_free_stream(struct snd_pcm_str * pstr)
  681. {
  682. struct snd_pcm_substream *substream, *substream_next;
  683. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  684. struct snd_pcm_oss_setup *setup, *setupn;
  685. #endif
  686. substream = pstr->substream;
  687. while (substream) {
  688. substream_next = substream->next;
  689. snd_pcm_timer_done(substream);
  690. snd_pcm_substream_proc_done(substream);
  691. kfree(substream);
  692. substream = substream_next;
  693. }
  694. snd_pcm_stream_proc_done(pstr);
  695. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  696. for (setup = pstr->oss.setup_list; setup; setup = setupn) {
  697. setupn = setup->next;
  698. kfree(setup->task_name);
  699. kfree(setup);
  700. }
  701. #endif
  702. }
  703. static int snd_pcm_free(struct snd_pcm *pcm)
  704. {
  705. struct snd_pcm_notify *notify;
  706. if (!pcm)
  707. return 0;
  708. list_for_each_entry(notify, &snd_pcm_notify_list, list) {
  709. notify->n_unregister(pcm);
  710. }
  711. if (pcm->private_free)
  712. pcm->private_free(pcm);
  713. snd_pcm_lib_preallocate_free_for_all(pcm);
  714. snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_PLAYBACK]);
  715. snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_CAPTURE]);
  716. kfree(pcm);
  717. return 0;
  718. }
  719. static int snd_pcm_dev_free(struct snd_device *device)
  720. {
  721. struct snd_pcm *pcm = device->device_data;
  722. return snd_pcm_free(pcm);
  723. }
  724. int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
  725. struct file *file,
  726. struct snd_pcm_substream **rsubstream)
  727. {
  728. struct snd_pcm_str * pstr;
  729. struct snd_pcm_substream *substream;
  730. struct snd_pcm_runtime *runtime;
  731. struct snd_ctl_file *kctl;
  732. struct snd_card *card;
  733. int prefer_subdevice = -1;
  734. size_t size;
  735. if (snd_BUG_ON(!pcm || !rsubstream))
  736. return -ENXIO;
  737. *rsubstream = NULL;
  738. pstr = &pcm->streams[stream];
  739. if (pstr->substream == NULL || pstr->substream_count == 0)
  740. return -ENODEV;
  741. card = pcm->card;
  742. read_lock(&card->ctl_files_rwlock);
  743. list_for_each_entry(kctl, &card->ctl_files, list) {
  744. if (kctl->pid == task_pid(current)) {
  745. prefer_subdevice = kctl->prefer_pcm_subdevice;
  746. if (prefer_subdevice != -1)
  747. break;
  748. }
  749. }
  750. read_unlock(&card->ctl_files_rwlock);
  751. switch (stream) {
  752. case SNDRV_PCM_STREAM_PLAYBACK:
  753. if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) {
  754. for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next) {
  755. if (SUBSTREAM_BUSY(substream))
  756. return -EAGAIN;
  757. }
  758. }
  759. break;
  760. case SNDRV_PCM_STREAM_CAPTURE:
  761. if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) {
  762. for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) {
  763. if (SUBSTREAM_BUSY(substream))
  764. return -EAGAIN;
  765. }
  766. }
  767. break;
  768. default:
  769. return -EINVAL;
  770. }
  771. if (file->f_flags & O_APPEND) {
  772. if (prefer_subdevice < 0) {
  773. if (pstr->substream_count > 1)
  774. return -EINVAL; /* must be unique */
  775. substream = pstr->substream;
  776. } else {
  777. for (substream = pstr->substream; substream;
  778. substream = substream->next)
  779. if (substream->number == prefer_subdevice)
  780. break;
  781. }
  782. if (! substream)
  783. return -ENODEV;
  784. if (! SUBSTREAM_BUSY(substream))
  785. return -EBADFD;
  786. substream->ref_count++;
  787. *rsubstream = substream;
  788. return 0;
  789. }
  790. if (prefer_subdevice >= 0) {
  791. for (substream = pstr->substream; substream; substream = substream->next)
  792. if (!SUBSTREAM_BUSY(substream) && substream->number == prefer_subdevice)
  793. goto __ok;
  794. }
  795. for (substream = pstr->substream; substream; substream = substream->next)
  796. if (!SUBSTREAM_BUSY(substream))
  797. break;
  798. __ok:
  799. if (substream == NULL)
  800. return -EAGAIN;
  801. runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
  802. if (runtime == NULL)
  803. return -ENOMEM;
  804. size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status));
  805. runtime->status = snd_malloc_pages(size, GFP_KERNEL);
  806. if (runtime->status == NULL) {
  807. kfree(runtime);
  808. return -ENOMEM;
  809. }
  810. memset((void*)runtime->status, 0, size);
  811. size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control));
  812. runtime->control = snd_malloc_pages(size, GFP_KERNEL);
  813. if (runtime->control == NULL) {
  814. snd_free_pages((void*)runtime->status,
  815. PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
  816. kfree(runtime);
  817. return -ENOMEM;
  818. }
  819. memset((void*)runtime->control, 0, size);
  820. init_waitqueue_head(&runtime->sleep);
  821. runtime->status->state = SNDRV_PCM_STATE_OPEN;
  822. substream->runtime = runtime;
  823. substream->private_data = pcm->private_data;
  824. substream->ref_count = 1;
  825. substream->f_flags = file->f_flags;
  826. substream->pid = get_pid(task_pid(current));
  827. pstr->substream_opened++;
  828. *rsubstream = substream;
  829. return 0;
  830. }
  831. void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
  832. {
  833. struct snd_pcm_runtime *runtime;
  834. if (PCM_RUNTIME_CHECK(substream))
  835. return;
  836. runtime = substream->runtime;
  837. if (runtime->private_free != NULL)
  838. runtime->private_free(runtime);
  839. snd_free_pages((void*)runtime->status,
  840. PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
  841. snd_free_pages((void*)runtime->control,
  842. PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)));
  843. kfree(runtime->hw_constraints.rules);
  844. kfree(runtime);
  845. substream->runtime = NULL;
  846. put_pid(substream->pid);
  847. substream->pid = NULL;
  848. substream->pstr->substream_opened--;
  849. }
  850. static ssize_t show_pcm_class(struct device *dev,
  851. struct device_attribute *attr, char *buf)
  852. {
  853. struct snd_pcm *pcm;
  854. const char *str;
  855. static const char *strs[SNDRV_PCM_CLASS_LAST + 1] = {
  856. [SNDRV_PCM_CLASS_GENERIC] = "generic",
  857. [SNDRV_PCM_CLASS_MULTI] = "multi",
  858. [SNDRV_PCM_CLASS_MODEM] = "modem",
  859. [SNDRV_PCM_CLASS_DIGITIZER] = "digitizer",
  860. };
  861. if (! (pcm = dev_get_drvdata(dev)) ||
  862. pcm->dev_class > SNDRV_PCM_CLASS_LAST)
  863. str = "none";
  864. else
  865. str = strs[pcm->dev_class];
  866. return snprintf(buf, PAGE_SIZE, "%s\n", str);
  867. }
  868. static struct device_attribute pcm_attrs =
  869. __ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL);
  870. static int snd_pcm_dev_register(struct snd_device *device)
  871. {
  872. int cidx, err;
  873. struct snd_pcm_substream *substream;
  874. struct snd_pcm_notify *notify;
  875. char str[16];
  876. struct snd_pcm *pcm;
  877. struct device *dev;
  878. if (snd_BUG_ON(!device || !device->device_data))
  879. return -ENXIO;
  880. pcm = device->device_data;
  881. mutex_lock(&register_mutex);
  882. err = snd_pcm_add(pcm);
  883. if (err) {
  884. mutex_unlock(&register_mutex);
  885. return err;
  886. }
  887. for (cidx = 0; cidx < 2; cidx++) {
  888. int devtype = -1;
  889. if (pcm->streams[cidx].substream == NULL)
  890. continue;
  891. switch (cidx) {
  892. case SNDRV_PCM_STREAM_PLAYBACK:
  893. sprintf(str, "pcmC%iD%ip", pcm->card->number, pcm->device);
  894. devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK;
  895. break;
  896. case SNDRV_PCM_STREAM_CAPTURE:
  897. sprintf(str, "pcmC%iD%ic", pcm->card->number, pcm->device);
  898. devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE;
  899. break;
  900. }
  901. /* device pointer to use, pcm->dev takes precedence if
  902. * it is assigned, otherwise fall back to card's device
  903. * if possible */
  904. dev = pcm->dev;
  905. if (!dev)
  906. dev = snd_card_get_device_link(pcm->card);
  907. /* register pcm */
  908. err = snd_register_device_for_dev(devtype, pcm->card,
  909. pcm->device,
  910. &snd_pcm_f_ops[cidx],
  911. pcm, str, dev);
  912. if (err < 0) {
  913. list_del(&pcm->list);
  914. mutex_unlock(&register_mutex);
  915. return err;
  916. }
  917. snd_add_device_sysfs_file(devtype, pcm->card, pcm->device,
  918. &pcm_attrs);
  919. for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
  920. snd_pcm_timer_init(substream);
  921. }
  922. list_for_each_entry(notify, &snd_pcm_notify_list, list)
  923. notify->n_register(pcm);
  924. mutex_unlock(&register_mutex);
  925. return 0;
  926. }
  927. static int snd_pcm_dev_disconnect(struct snd_device *device)
  928. {
  929. struct snd_pcm *pcm = device->device_data;
  930. struct snd_pcm_notify *notify;
  931. struct snd_pcm_substream *substream;
  932. int cidx, devtype;
  933. mutex_lock(&register_mutex);
  934. if (list_empty(&pcm->list))
  935. goto unlock;
  936. list_del_init(&pcm->list);
  937. for (cidx = 0; cidx < 2; cidx++)
  938. for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
  939. if (substream->runtime)
  940. substream->runtime->status->state = SNDRV_PCM_STATE_DISCONNECTED;
  941. list_for_each_entry(notify, &snd_pcm_notify_list, list) {
  942. notify->n_disconnect(pcm);
  943. }
  944. for (cidx = 0; cidx < 2; cidx++) {
  945. devtype = -1;
  946. switch (cidx) {
  947. case SNDRV_PCM_STREAM_PLAYBACK:
  948. devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK;
  949. break;
  950. case SNDRV_PCM_STREAM_CAPTURE:
  951. devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE;
  952. break;
  953. }
  954. snd_unregister_device(devtype, pcm->card, pcm->device);
  955. }
  956. unlock:
  957. mutex_unlock(&register_mutex);
  958. return 0;
  959. }
  960. int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree)
  961. {
  962. struct snd_pcm *pcm;
  963. if (snd_BUG_ON(!notify ||
  964. !notify->n_register ||
  965. !notify->n_unregister ||
  966. !notify->n_disconnect))
  967. return -EINVAL;
  968. mutex_lock(&register_mutex);
  969. if (nfree) {
  970. list_del(&notify->list);
  971. list_for_each_entry(pcm, &snd_pcm_devices, list)
  972. notify->n_unregister(pcm);
  973. } else {
  974. list_add_tail(&notify->list, &snd_pcm_notify_list);
  975. list_for_each_entry(pcm, &snd_pcm_devices, list)
  976. notify->n_register(pcm);
  977. }
  978. mutex_unlock(&register_mutex);
  979. return 0;
  980. }
  981. EXPORT_SYMBOL(snd_pcm_notify);
  982. #ifdef CONFIG_PROC_FS
  983. /*
  984. * Info interface
  985. */
  986. static void snd_pcm_proc_read(struct snd_info_entry *entry,
  987. struct snd_info_buffer *buffer)
  988. {
  989. struct snd_pcm *pcm;
  990. mutex_lock(&register_mutex);
  991. list_for_each_entry(pcm, &snd_pcm_devices, list) {
  992. snd_iprintf(buffer, "%02i-%02i: %s : %s",
  993. pcm->card->number, pcm->device, pcm->id, pcm->name);
  994. if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream)
  995. snd_iprintf(buffer, " : playback %i",
  996. pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream_count);
  997. if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream)
  998. snd_iprintf(buffer, " : capture %i",
  999. pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream_count);
  1000. snd_iprintf(buffer, "\n");
  1001. }
  1002. mutex_unlock(&register_mutex);
  1003. }
  1004. static struct snd_info_entry *snd_pcm_proc_entry;
  1005. static void snd_pcm_proc_init(void)
  1006. {
  1007. struct snd_info_entry *entry;
  1008. if ((entry = snd_info_create_module_entry(THIS_MODULE, "pcm", NULL)) != NULL) {
  1009. snd_info_set_text_ops(entry, NULL, snd_pcm_proc_read);
  1010. if (snd_info_register(entry) < 0) {
  1011. snd_info_free_entry(entry);
  1012. entry = NULL;
  1013. }
  1014. }
  1015. snd_pcm_proc_entry = entry;
  1016. }
  1017. static void snd_pcm_proc_done(void)
  1018. {
  1019. snd_info_free_entry(snd_pcm_proc_entry);
  1020. }
  1021. #else /* !CONFIG_PROC_FS */
  1022. #define snd_pcm_proc_init()
  1023. #define snd_pcm_proc_done()
  1024. #endif /* CONFIG_PROC_FS */
  1025. /*
  1026. * ENTRY functions
  1027. */
  1028. static int __init alsa_pcm_init(void)
  1029. {
  1030. snd_ctl_register_ioctl(snd_pcm_control_ioctl);
  1031. snd_ctl_register_ioctl_compat(snd_pcm_control_ioctl);
  1032. snd_pcm_proc_init();
  1033. return 0;
  1034. }
  1035. static void __exit alsa_pcm_exit(void)
  1036. {
  1037. snd_ctl_unregister_ioctl(snd_pcm_control_ioctl);
  1038. snd_ctl_unregister_ioctl_compat(snd_pcm_control_ioctl);
  1039. snd_pcm_proc_done();
  1040. }
  1041. module_init(alsa_pcm_init)
  1042. module_exit(alsa_pcm_exit)