pcm.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  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, "trigger_time: %ld.%09ld\n",
  399. status.trigger_tstamp.tv_sec, status.trigger_tstamp.tv_nsec);
  400. snd_iprintf(buffer, "tstamp : %ld.%09ld\n",
  401. status.tstamp.tv_sec, status.tstamp.tv_nsec);
  402. snd_iprintf(buffer, "delay : %ld\n", status.delay);
  403. snd_iprintf(buffer, "avail : %ld\n", status.avail);
  404. snd_iprintf(buffer, "avail_max : %ld\n", status.avail_max);
  405. snd_iprintf(buffer, "-----\n");
  406. snd_iprintf(buffer, "hw_ptr : %ld\n", runtime->status->hw_ptr);
  407. snd_iprintf(buffer, "appl_ptr : %ld\n", runtime->control->appl_ptr);
  408. }
  409. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  410. static void snd_pcm_xrun_debug_read(struct snd_info_entry *entry,
  411. struct snd_info_buffer *buffer)
  412. {
  413. struct snd_pcm_str *pstr = entry->private_data;
  414. snd_iprintf(buffer, "%d\n", pstr->xrun_debug);
  415. }
  416. static void snd_pcm_xrun_debug_write(struct snd_info_entry *entry,
  417. struct snd_info_buffer *buffer)
  418. {
  419. struct snd_pcm_str *pstr = entry->private_data;
  420. char line[64];
  421. if (!snd_info_get_line(buffer, line, sizeof(line)))
  422. pstr->xrun_debug = simple_strtoul(line, NULL, 10);
  423. }
  424. #endif
  425. static int snd_pcm_stream_proc_init(struct snd_pcm_str *pstr)
  426. {
  427. struct snd_pcm *pcm = pstr->pcm;
  428. struct snd_info_entry *entry;
  429. char name[16];
  430. sprintf(name, "pcm%i%c", pcm->device,
  431. pstr->stream == SNDRV_PCM_STREAM_PLAYBACK ? 'p' : 'c');
  432. if ((entry = snd_info_create_card_entry(pcm->card, name, pcm->card->proc_root)) == NULL)
  433. return -ENOMEM;
  434. entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
  435. if (snd_info_register(entry) < 0) {
  436. snd_info_free_entry(entry);
  437. return -ENOMEM;
  438. }
  439. pstr->proc_root = entry;
  440. if ((entry = snd_info_create_card_entry(pcm->card, "info", pstr->proc_root)) != NULL) {
  441. snd_info_set_text_ops(entry, pstr, snd_pcm_stream_proc_info_read);
  442. if (snd_info_register(entry) < 0) {
  443. snd_info_free_entry(entry);
  444. entry = NULL;
  445. }
  446. }
  447. pstr->proc_info_entry = entry;
  448. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  449. if ((entry = snd_info_create_card_entry(pcm->card, "xrun_debug",
  450. pstr->proc_root)) != NULL) {
  451. entry->c.text.read = snd_pcm_xrun_debug_read;
  452. entry->c.text.write = snd_pcm_xrun_debug_write;
  453. entry->mode |= S_IWUSR;
  454. entry->private_data = pstr;
  455. if (snd_info_register(entry) < 0) {
  456. snd_info_free_entry(entry);
  457. entry = NULL;
  458. }
  459. }
  460. pstr->proc_xrun_debug_entry = entry;
  461. #endif
  462. return 0;
  463. }
  464. static int snd_pcm_stream_proc_done(struct snd_pcm_str *pstr)
  465. {
  466. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  467. snd_info_free_entry(pstr->proc_xrun_debug_entry);
  468. pstr->proc_xrun_debug_entry = NULL;
  469. #endif
  470. snd_info_free_entry(pstr->proc_info_entry);
  471. pstr->proc_info_entry = NULL;
  472. snd_info_free_entry(pstr->proc_root);
  473. pstr->proc_root = NULL;
  474. return 0;
  475. }
  476. static int snd_pcm_substream_proc_init(struct snd_pcm_substream *substream)
  477. {
  478. struct snd_info_entry *entry;
  479. struct snd_card *card;
  480. char name[16];
  481. card = substream->pcm->card;
  482. sprintf(name, "sub%i", substream->number);
  483. if ((entry = snd_info_create_card_entry(card, name, substream->pstr->proc_root)) == NULL)
  484. return -ENOMEM;
  485. entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
  486. if (snd_info_register(entry) < 0) {
  487. snd_info_free_entry(entry);
  488. return -ENOMEM;
  489. }
  490. substream->proc_root = entry;
  491. if ((entry = snd_info_create_card_entry(card, "info", substream->proc_root)) != NULL) {
  492. snd_info_set_text_ops(entry, substream,
  493. snd_pcm_substream_proc_info_read);
  494. if (snd_info_register(entry) < 0) {
  495. snd_info_free_entry(entry);
  496. entry = NULL;
  497. }
  498. }
  499. substream->proc_info_entry = entry;
  500. if ((entry = snd_info_create_card_entry(card, "hw_params", substream->proc_root)) != NULL) {
  501. snd_info_set_text_ops(entry, substream,
  502. snd_pcm_substream_proc_hw_params_read);
  503. if (snd_info_register(entry) < 0) {
  504. snd_info_free_entry(entry);
  505. entry = NULL;
  506. }
  507. }
  508. substream->proc_hw_params_entry = entry;
  509. if ((entry = snd_info_create_card_entry(card, "sw_params", substream->proc_root)) != NULL) {
  510. snd_info_set_text_ops(entry, substream,
  511. snd_pcm_substream_proc_sw_params_read);
  512. if (snd_info_register(entry) < 0) {
  513. snd_info_free_entry(entry);
  514. entry = NULL;
  515. }
  516. }
  517. substream->proc_sw_params_entry = entry;
  518. if ((entry = snd_info_create_card_entry(card, "status", substream->proc_root)) != NULL) {
  519. snd_info_set_text_ops(entry, substream,
  520. snd_pcm_substream_proc_status_read);
  521. if (snd_info_register(entry) < 0) {
  522. snd_info_free_entry(entry);
  523. entry = NULL;
  524. }
  525. }
  526. substream->proc_status_entry = entry;
  527. return 0;
  528. }
  529. static int snd_pcm_substream_proc_done(struct snd_pcm_substream *substream)
  530. {
  531. snd_info_free_entry(substream->proc_info_entry);
  532. substream->proc_info_entry = NULL;
  533. snd_info_free_entry(substream->proc_hw_params_entry);
  534. substream->proc_hw_params_entry = NULL;
  535. snd_info_free_entry(substream->proc_sw_params_entry);
  536. substream->proc_sw_params_entry = NULL;
  537. snd_info_free_entry(substream->proc_status_entry);
  538. substream->proc_status_entry = NULL;
  539. snd_info_free_entry(substream->proc_root);
  540. substream->proc_root = NULL;
  541. return 0;
  542. }
  543. #else /* !CONFIG_SND_VERBOSE_PROCFS */
  544. static inline int snd_pcm_stream_proc_init(struct snd_pcm_str *pstr) { return 0; }
  545. static inline int snd_pcm_stream_proc_done(struct snd_pcm_str *pstr) { return 0; }
  546. static inline int snd_pcm_substream_proc_init(struct snd_pcm_substream *substream) { return 0; }
  547. static inline int snd_pcm_substream_proc_done(struct snd_pcm_substream *substream) { return 0; }
  548. #endif /* CONFIG_SND_VERBOSE_PROCFS */
  549. /**
  550. * snd_pcm_new_stream - create a new PCM stream
  551. * @pcm: the pcm instance
  552. * @stream: the stream direction, SNDRV_PCM_STREAM_XXX
  553. * @substream_count: the number of substreams
  554. *
  555. * Creates a new stream for the pcm.
  556. * The corresponding stream on the pcm must have been empty before
  557. * calling this, i.e. zero must be given to the argument of
  558. * snd_pcm_new().
  559. *
  560. * Returns zero if successful, or a negative error code on failure.
  561. */
  562. int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count)
  563. {
  564. int idx, err;
  565. struct snd_pcm_str *pstr = &pcm->streams[stream];
  566. struct snd_pcm_substream *substream, *prev;
  567. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  568. mutex_init(&pstr->oss.setup_mutex);
  569. #endif
  570. pstr->stream = stream;
  571. pstr->pcm = pcm;
  572. pstr->substream_count = substream_count;
  573. if (substream_count > 0) {
  574. err = snd_pcm_stream_proc_init(pstr);
  575. if (err < 0) {
  576. snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n");
  577. return err;
  578. }
  579. }
  580. prev = NULL;
  581. for (idx = 0, prev = NULL; idx < substream_count; idx++) {
  582. substream = kzalloc(sizeof(*substream), GFP_KERNEL);
  583. if (substream == NULL) {
  584. snd_printk(KERN_ERR "Cannot allocate PCM substream\n");
  585. return -ENOMEM;
  586. }
  587. substream->pcm = pcm;
  588. substream->pstr = pstr;
  589. substream->number = idx;
  590. substream->stream = stream;
  591. sprintf(substream->name, "subdevice #%i", idx);
  592. snprintf(substream->latency_id, sizeof(substream->latency_id),
  593. "ALSA-PCM%d-%d%c%d", pcm->card->number, pcm->device,
  594. (stream ? 'c' : 'p'), idx);
  595. substream->buffer_bytes_max = UINT_MAX;
  596. if (prev == NULL)
  597. pstr->substream = substream;
  598. else
  599. prev->next = substream;
  600. err = snd_pcm_substream_proc_init(substream);
  601. if (err < 0) {
  602. snd_printk(KERN_ERR "Error in snd_pcm_stream_proc_init\n");
  603. if (prev == NULL)
  604. pstr->substream = NULL;
  605. else
  606. prev->next = NULL;
  607. kfree(substream);
  608. return err;
  609. }
  610. substream->group = &substream->self_group;
  611. spin_lock_init(&substream->self_group.lock);
  612. INIT_LIST_HEAD(&substream->self_group.substreams);
  613. list_add_tail(&substream->link_list, &substream->self_group.substreams);
  614. atomic_set(&substream->mmap_count, 0);
  615. prev = substream;
  616. }
  617. return 0;
  618. }
  619. EXPORT_SYMBOL(snd_pcm_new_stream);
  620. /**
  621. * snd_pcm_new - create a new PCM instance
  622. * @card: the card instance
  623. * @id: the id string
  624. * @device: the device index (zero based)
  625. * @playback_count: the number of substreams for playback
  626. * @capture_count: the number of substreams for capture
  627. * @rpcm: the pointer to store the new pcm instance
  628. *
  629. * Creates a new PCM instance.
  630. *
  631. * The pcm operators have to be set afterwards to the new instance
  632. * via snd_pcm_set_ops().
  633. *
  634. * Returns zero if successful, or a negative error code on failure.
  635. */
  636. int snd_pcm_new(struct snd_card *card, const char *id, int device,
  637. int playback_count, int capture_count,
  638. struct snd_pcm ** rpcm)
  639. {
  640. struct snd_pcm *pcm;
  641. int err;
  642. static struct snd_device_ops ops = {
  643. .dev_free = snd_pcm_dev_free,
  644. .dev_register = snd_pcm_dev_register,
  645. .dev_disconnect = snd_pcm_dev_disconnect,
  646. };
  647. if (snd_BUG_ON(!card))
  648. return -ENXIO;
  649. if (rpcm)
  650. *rpcm = NULL;
  651. pcm = kzalloc(sizeof(*pcm), GFP_KERNEL);
  652. if (pcm == NULL) {
  653. snd_printk(KERN_ERR "Cannot allocate PCM\n");
  654. return -ENOMEM;
  655. }
  656. pcm->card = card;
  657. pcm->device = device;
  658. if (id)
  659. strlcpy(pcm->id, id, sizeof(pcm->id));
  660. if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_PLAYBACK, playback_count)) < 0) {
  661. snd_pcm_free(pcm);
  662. return err;
  663. }
  664. if ((err = snd_pcm_new_stream(pcm, SNDRV_PCM_STREAM_CAPTURE, capture_count)) < 0) {
  665. snd_pcm_free(pcm);
  666. return err;
  667. }
  668. mutex_init(&pcm->open_mutex);
  669. init_waitqueue_head(&pcm->open_wait);
  670. if ((err = snd_device_new(card, SNDRV_DEV_PCM, pcm, &ops)) < 0) {
  671. snd_pcm_free(pcm);
  672. return err;
  673. }
  674. if (rpcm)
  675. *rpcm = pcm;
  676. return 0;
  677. }
  678. EXPORT_SYMBOL(snd_pcm_new);
  679. static void snd_pcm_free_stream(struct snd_pcm_str * pstr)
  680. {
  681. struct snd_pcm_substream *substream, *substream_next;
  682. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  683. struct snd_pcm_oss_setup *setup, *setupn;
  684. #endif
  685. substream = pstr->substream;
  686. while (substream) {
  687. substream_next = substream->next;
  688. snd_pcm_timer_done(substream);
  689. snd_pcm_substream_proc_done(substream);
  690. kfree(substream);
  691. substream = substream_next;
  692. }
  693. snd_pcm_stream_proc_done(pstr);
  694. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  695. for (setup = pstr->oss.setup_list; setup; setup = setupn) {
  696. setupn = setup->next;
  697. kfree(setup->task_name);
  698. kfree(setup);
  699. }
  700. #endif
  701. }
  702. static int snd_pcm_free(struct snd_pcm *pcm)
  703. {
  704. struct snd_pcm_notify *notify;
  705. if (!pcm)
  706. return 0;
  707. list_for_each_entry(notify, &snd_pcm_notify_list, list) {
  708. notify->n_unregister(pcm);
  709. }
  710. if (pcm->private_free)
  711. pcm->private_free(pcm);
  712. snd_pcm_lib_preallocate_free_for_all(pcm);
  713. snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_PLAYBACK]);
  714. snd_pcm_free_stream(&pcm->streams[SNDRV_PCM_STREAM_CAPTURE]);
  715. kfree(pcm);
  716. return 0;
  717. }
  718. static int snd_pcm_dev_free(struct snd_device *device)
  719. {
  720. struct snd_pcm *pcm = device->device_data;
  721. return snd_pcm_free(pcm);
  722. }
  723. int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,
  724. struct file *file,
  725. struct snd_pcm_substream **rsubstream)
  726. {
  727. struct snd_pcm_str * pstr;
  728. struct snd_pcm_substream *substream;
  729. struct snd_pcm_runtime *runtime;
  730. struct snd_ctl_file *kctl;
  731. struct snd_card *card;
  732. int prefer_subdevice = -1;
  733. size_t size;
  734. if (snd_BUG_ON(!pcm || !rsubstream))
  735. return -ENXIO;
  736. *rsubstream = NULL;
  737. pstr = &pcm->streams[stream];
  738. if (pstr->substream == NULL || pstr->substream_count == 0)
  739. return -ENODEV;
  740. card = pcm->card;
  741. read_lock(&card->ctl_files_rwlock);
  742. list_for_each_entry(kctl, &card->ctl_files, list) {
  743. if (kctl->pid == current->pid) {
  744. prefer_subdevice = kctl->prefer_pcm_subdevice;
  745. if (prefer_subdevice != -1)
  746. break;
  747. }
  748. }
  749. read_unlock(&card->ctl_files_rwlock);
  750. switch (stream) {
  751. case SNDRV_PCM_STREAM_PLAYBACK:
  752. if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) {
  753. for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next) {
  754. if (SUBSTREAM_BUSY(substream))
  755. return -EAGAIN;
  756. }
  757. }
  758. break;
  759. case SNDRV_PCM_STREAM_CAPTURE:
  760. if (pcm->info_flags & SNDRV_PCM_INFO_HALF_DUPLEX) {
  761. for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next) {
  762. if (SUBSTREAM_BUSY(substream))
  763. return -EAGAIN;
  764. }
  765. }
  766. break;
  767. default:
  768. return -EINVAL;
  769. }
  770. if (file->f_flags & O_APPEND) {
  771. if (prefer_subdevice < 0) {
  772. if (pstr->substream_count > 1)
  773. return -EINVAL; /* must be unique */
  774. substream = pstr->substream;
  775. } else {
  776. for (substream = pstr->substream; substream;
  777. substream = substream->next)
  778. if (substream->number == prefer_subdevice)
  779. break;
  780. }
  781. if (! substream)
  782. return -ENODEV;
  783. if (! SUBSTREAM_BUSY(substream))
  784. return -EBADFD;
  785. substream->ref_count++;
  786. *rsubstream = substream;
  787. return 0;
  788. }
  789. if (prefer_subdevice >= 0) {
  790. for (substream = pstr->substream; substream; substream = substream->next)
  791. if (!SUBSTREAM_BUSY(substream) && substream->number == prefer_subdevice)
  792. goto __ok;
  793. }
  794. for (substream = pstr->substream; substream; substream = substream->next)
  795. if (!SUBSTREAM_BUSY(substream))
  796. break;
  797. __ok:
  798. if (substream == NULL)
  799. return -EAGAIN;
  800. runtime = kzalloc(sizeof(*runtime), GFP_KERNEL);
  801. if (runtime == NULL)
  802. return -ENOMEM;
  803. size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status));
  804. runtime->status = snd_malloc_pages(size, GFP_KERNEL);
  805. if (runtime->status == NULL) {
  806. kfree(runtime);
  807. return -ENOMEM;
  808. }
  809. memset((void*)runtime->status, 0, size);
  810. size = PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control));
  811. runtime->control = snd_malloc_pages(size, GFP_KERNEL);
  812. if (runtime->control == NULL) {
  813. snd_free_pages((void*)runtime->status,
  814. PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
  815. kfree(runtime);
  816. return -ENOMEM;
  817. }
  818. memset((void*)runtime->control, 0, size);
  819. init_waitqueue_head(&runtime->sleep);
  820. runtime->status->state = SNDRV_PCM_STATE_OPEN;
  821. substream->runtime = runtime;
  822. substream->private_data = pcm->private_data;
  823. substream->ref_count = 1;
  824. substream->f_flags = file->f_flags;
  825. pstr->substream_opened++;
  826. *rsubstream = substream;
  827. return 0;
  828. }
  829. void snd_pcm_detach_substream(struct snd_pcm_substream *substream)
  830. {
  831. struct snd_pcm_runtime *runtime;
  832. if (PCM_RUNTIME_CHECK(substream))
  833. return;
  834. runtime = substream->runtime;
  835. if (runtime->private_free != NULL)
  836. runtime->private_free(runtime);
  837. snd_free_pages((void*)runtime->status,
  838. PAGE_ALIGN(sizeof(struct snd_pcm_mmap_status)));
  839. snd_free_pages((void*)runtime->control,
  840. PAGE_ALIGN(sizeof(struct snd_pcm_mmap_control)));
  841. kfree(runtime->hw_constraints.rules);
  842. kfree(runtime);
  843. substream->runtime = NULL;
  844. substream->pstr->substream_opened--;
  845. }
  846. static ssize_t show_pcm_class(struct device *dev,
  847. struct device_attribute *attr, char *buf)
  848. {
  849. struct snd_pcm *pcm;
  850. const char *str;
  851. static const char *strs[SNDRV_PCM_CLASS_LAST + 1] = {
  852. [SNDRV_PCM_CLASS_GENERIC] = "generic",
  853. [SNDRV_PCM_CLASS_MULTI] = "multi",
  854. [SNDRV_PCM_CLASS_MODEM] = "modem",
  855. [SNDRV_PCM_CLASS_DIGITIZER] = "digitizer",
  856. };
  857. if (! (pcm = dev_get_drvdata(dev)) ||
  858. pcm->dev_class > SNDRV_PCM_CLASS_LAST)
  859. str = "none";
  860. else
  861. str = strs[pcm->dev_class];
  862. return snprintf(buf, PAGE_SIZE, "%s\n", str);
  863. }
  864. static struct device_attribute pcm_attrs =
  865. __ATTR(pcm_class, S_IRUGO, show_pcm_class, NULL);
  866. static int snd_pcm_dev_register(struct snd_device *device)
  867. {
  868. int cidx, err;
  869. struct snd_pcm_substream *substream;
  870. struct snd_pcm_notify *notify;
  871. char str[16];
  872. struct snd_pcm *pcm = device->device_data;
  873. struct device *dev;
  874. if (snd_BUG_ON(!pcm || !device))
  875. return -ENXIO;
  876. mutex_lock(&register_mutex);
  877. err = snd_pcm_add(pcm);
  878. if (err) {
  879. mutex_unlock(&register_mutex);
  880. return err;
  881. }
  882. for (cidx = 0; cidx < 2; cidx++) {
  883. int devtype = -1;
  884. if (pcm->streams[cidx].substream == NULL)
  885. continue;
  886. switch (cidx) {
  887. case SNDRV_PCM_STREAM_PLAYBACK:
  888. sprintf(str, "pcmC%iD%ip", pcm->card->number, pcm->device);
  889. devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK;
  890. break;
  891. case SNDRV_PCM_STREAM_CAPTURE:
  892. sprintf(str, "pcmC%iD%ic", pcm->card->number, pcm->device);
  893. devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE;
  894. break;
  895. }
  896. /* device pointer to use, pcm->dev takes precedence if
  897. * it is assigned, otherwise fall back to card's device
  898. * if possible */
  899. dev = pcm->dev;
  900. if (!dev)
  901. dev = snd_card_get_device_link(pcm->card);
  902. /* register pcm */
  903. err = snd_register_device_for_dev(devtype, pcm->card,
  904. pcm->device,
  905. &snd_pcm_f_ops[cidx],
  906. pcm, str, dev);
  907. if (err < 0) {
  908. list_del(&pcm->list);
  909. mutex_unlock(&register_mutex);
  910. return err;
  911. }
  912. snd_add_device_sysfs_file(devtype, pcm->card, pcm->device,
  913. &pcm_attrs);
  914. for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
  915. snd_pcm_timer_init(substream);
  916. }
  917. list_for_each_entry(notify, &snd_pcm_notify_list, list)
  918. notify->n_register(pcm);
  919. mutex_unlock(&register_mutex);
  920. return 0;
  921. }
  922. static int snd_pcm_dev_disconnect(struct snd_device *device)
  923. {
  924. struct snd_pcm *pcm = device->device_data;
  925. struct snd_pcm_notify *notify;
  926. struct snd_pcm_substream *substream;
  927. int cidx, devtype;
  928. mutex_lock(&register_mutex);
  929. if (list_empty(&pcm->list))
  930. goto unlock;
  931. list_del_init(&pcm->list);
  932. for (cidx = 0; cidx < 2; cidx++)
  933. for (substream = pcm->streams[cidx].substream; substream; substream = substream->next)
  934. if (substream->runtime)
  935. substream->runtime->status->state = SNDRV_PCM_STATE_DISCONNECTED;
  936. list_for_each_entry(notify, &snd_pcm_notify_list, list) {
  937. notify->n_disconnect(pcm);
  938. }
  939. for (cidx = 0; cidx < 2; cidx++) {
  940. devtype = -1;
  941. switch (cidx) {
  942. case SNDRV_PCM_STREAM_PLAYBACK:
  943. devtype = SNDRV_DEVICE_TYPE_PCM_PLAYBACK;
  944. break;
  945. case SNDRV_PCM_STREAM_CAPTURE:
  946. devtype = SNDRV_DEVICE_TYPE_PCM_CAPTURE;
  947. break;
  948. }
  949. snd_unregister_device(devtype, pcm->card, pcm->device);
  950. }
  951. unlock:
  952. mutex_unlock(&register_mutex);
  953. return 0;
  954. }
  955. int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree)
  956. {
  957. struct snd_pcm *pcm;
  958. if (snd_BUG_ON(!notify ||
  959. !notify->n_register ||
  960. !notify->n_unregister ||
  961. !notify->n_disconnect))
  962. return -EINVAL;
  963. mutex_lock(&register_mutex);
  964. if (nfree) {
  965. list_del(&notify->list);
  966. list_for_each_entry(pcm, &snd_pcm_devices, list)
  967. notify->n_unregister(pcm);
  968. } else {
  969. list_add_tail(&notify->list, &snd_pcm_notify_list);
  970. list_for_each_entry(pcm, &snd_pcm_devices, list)
  971. notify->n_register(pcm);
  972. }
  973. mutex_unlock(&register_mutex);
  974. return 0;
  975. }
  976. EXPORT_SYMBOL(snd_pcm_notify);
  977. #ifdef CONFIG_PROC_FS
  978. /*
  979. * Info interface
  980. */
  981. static void snd_pcm_proc_read(struct snd_info_entry *entry,
  982. struct snd_info_buffer *buffer)
  983. {
  984. struct snd_pcm *pcm;
  985. mutex_lock(&register_mutex);
  986. list_for_each_entry(pcm, &snd_pcm_devices, list) {
  987. snd_iprintf(buffer, "%02i-%02i: %s : %s",
  988. pcm->card->number, pcm->device, pcm->id, pcm->name);
  989. if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream)
  990. snd_iprintf(buffer, " : playback %i",
  991. pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream_count);
  992. if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream)
  993. snd_iprintf(buffer, " : capture %i",
  994. pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream_count);
  995. snd_iprintf(buffer, "\n");
  996. }
  997. mutex_unlock(&register_mutex);
  998. }
  999. static struct snd_info_entry *snd_pcm_proc_entry;
  1000. static void snd_pcm_proc_init(void)
  1001. {
  1002. struct snd_info_entry *entry;
  1003. if ((entry = snd_info_create_module_entry(THIS_MODULE, "pcm", NULL)) != NULL) {
  1004. snd_info_set_text_ops(entry, NULL, snd_pcm_proc_read);
  1005. if (snd_info_register(entry) < 0) {
  1006. snd_info_free_entry(entry);
  1007. entry = NULL;
  1008. }
  1009. }
  1010. snd_pcm_proc_entry = entry;
  1011. }
  1012. static void snd_pcm_proc_done(void)
  1013. {
  1014. snd_info_free_entry(snd_pcm_proc_entry);
  1015. }
  1016. #else /* !CONFIG_PROC_FS */
  1017. #define snd_pcm_proc_init()
  1018. #define snd_pcm_proc_done()
  1019. #endif /* CONFIG_PROC_FS */
  1020. /*
  1021. * ENTRY functions
  1022. */
  1023. static int __init alsa_pcm_init(void)
  1024. {
  1025. snd_ctl_register_ioctl(snd_pcm_control_ioctl);
  1026. snd_ctl_register_ioctl_compat(snd_pcm_control_ioctl);
  1027. snd_pcm_proc_init();
  1028. return 0;
  1029. }
  1030. static void __exit alsa_pcm_exit(void)
  1031. {
  1032. snd_ctl_unregister_ioctl(snd_pcm_control_ioctl);
  1033. snd_ctl_unregister_ioctl_compat(snd_pcm_control_ioctl);
  1034. snd_pcm_proc_done();
  1035. }
  1036. module_init(alsa_pcm_init)
  1037. module_exit(alsa_pcm_exit)