pcm.h 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. #ifndef __SOUND_PCM_H
  2. #define __SOUND_PCM_H
  3. /*
  4. * Digital Audio (PCM) abstract layer
  5. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  6. * Abramo Bagnara <abramo@alsa-project.org>
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. */
  24. #include <sound/asound.h>
  25. #include <sound/memalloc.h>
  26. #include <sound/minors.h>
  27. #include <linux/poll.h>
  28. #include <linux/mm.h>
  29. #include <linux/bitops.h>
  30. #include <linux/pm_qos.h>
  31. #define snd_pcm_substream_chip(substream) ((substream)->private_data)
  32. #define snd_pcm_chip(pcm) ((pcm)->private_data)
  33. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  34. #include <sound/pcm_oss.h>
  35. #endif
  36. /*
  37. * Hardware (lowlevel) section
  38. */
  39. struct snd_pcm_hardware {
  40. unsigned int info; /* SNDRV_PCM_INFO_* */
  41. u64 formats; /* SNDRV_PCM_FMTBIT_* */
  42. unsigned int rates; /* SNDRV_PCM_RATE_* */
  43. unsigned int rate_min; /* min rate */
  44. unsigned int rate_max; /* max rate */
  45. unsigned int channels_min; /* min channels */
  46. unsigned int channels_max; /* max channels */
  47. size_t buffer_bytes_max; /* max buffer size */
  48. size_t period_bytes_min; /* min period size */
  49. size_t period_bytes_max; /* max period size */
  50. unsigned int periods_min; /* min # of periods */
  51. unsigned int periods_max; /* max # of periods */
  52. size_t fifo_size; /* fifo size in bytes */
  53. };
  54. struct snd_pcm_substream;
  55. struct snd_pcm_ops {
  56. int (*open)(struct snd_pcm_substream *substream);
  57. int (*close)(struct snd_pcm_substream *substream);
  58. int (*ioctl)(struct snd_pcm_substream * substream,
  59. unsigned int cmd, void *arg);
  60. int (*hw_params)(struct snd_pcm_substream *substream,
  61. struct snd_pcm_hw_params *params);
  62. int (*hw_free)(struct snd_pcm_substream *substream);
  63. int (*prepare)(struct snd_pcm_substream *substream);
  64. int (*trigger)(struct snd_pcm_substream *substream, int cmd);
  65. snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream);
  66. int (*wall_clock)(struct snd_pcm_substream *substream,
  67. struct timespec *audio_ts);
  68. int (*copy)(struct snd_pcm_substream *substream, int channel,
  69. snd_pcm_uframes_t pos,
  70. void __user *buf, snd_pcm_uframes_t count);
  71. int (*silence)(struct snd_pcm_substream *substream, int channel,
  72. snd_pcm_uframes_t pos, snd_pcm_uframes_t count);
  73. struct page *(*page)(struct snd_pcm_substream *substream,
  74. unsigned long offset);
  75. int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
  76. int (*ack)(struct snd_pcm_substream *substream);
  77. };
  78. /*
  79. *
  80. */
  81. #if defined(CONFIG_SND_DYNAMIC_MINORS)
  82. #define SNDRV_PCM_DEVICES (SNDRV_OS_MINORS-2)
  83. #else
  84. #define SNDRV_PCM_DEVICES 8
  85. #endif
  86. #define SNDRV_PCM_IOCTL1_FALSE ((void *)0)
  87. #define SNDRV_PCM_IOCTL1_TRUE ((void *)1)
  88. #define SNDRV_PCM_IOCTL1_RESET 0
  89. #define SNDRV_PCM_IOCTL1_INFO 1
  90. #define SNDRV_PCM_IOCTL1_CHANNEL_INFO 2
  91. #define SNDRV_PCM_IOCTL1_GSTATE 3
  92. #define SNDRV_PCM_IOCTL1_FIFO_SIZE 4
  93. #define SNDRV_PCM_TRIGGER_STOP 0
  94. #define SNDRV_PCM_TRIGGER_START 1
  95. #define SNDRV_PCM_TRIGGER_PAUSE_PUSH 3
  96. #define SNDRV_PCM_TRIGGER_PAUSE_RELEASE 4
  97. #define SNDRV_PCM_TRIGGER_SUSPEND 5
  98. #define SNDRV_PCM_TRIGGER_RESUME 6
  99. #define SNDRV_PCM_POS_XRUN ((snd_pcm_uframes_t)-1)
  100. /* If you change this don't forget to change rates[] table in pcm_native.c */
  101. #define SNDRV_PCM_RATE_5512 (1<<0) /* 5512Hz */
  102. #define SNDRV_PCM_RATE_8000 (1<<1) /* 8000Hz */
  103. #define SNDRV_PCM_RATE_11025 (1<<2) /* 11025Hz */
  104. #define SNDRV_PCM_RATE_16000 (1<<3) /* 16000Hz */
  105. #define SNDRV_PCM_RATE_22050 (1<<4) /* 22050Hz */
  106. #define SNDRV_PCM_RATE_32000 (1<<5) /* 32000Hz */
  107. #define SNDRV_PCM_RATE_44100 (1<<6) /* 44100Hz */
  108. #define SNDRV_PCM_RATE_48000 (1<<7) /* 48000Hz */
  109. #define SNDRV_PCM_RATE_64000 (1<<8) /* 64000Hz */
  110. #define SNDRV_PCM_RATE_88200 (1<<9) /* 88200Hz */
  111. #define SNDRV_PCM_RATE_96000 (1<<10) /* 96000Hz */
  112. #define SNDRV_PCM_RATE_176400 (1<<11) /* 176400Hz */
  113. #define SNDRV_PCM_RATE_192000 (1<<12) /* 192000Hz */
  114. #define SNDRV_PCM_RATE_CONTINUOUS (1<<30) /* continuous range */
  115. #define SNDRV_PCM_RATE_KNOT (1<<31) /* supports more non-continuos rates */
  116. #define SNDRV_PCM_RATE_8000_44100 (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_11025|\
  117. SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_22050|\
  118. SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100)
  119. #define SNDRV_PCM_RATE_8000_48000 (SNDRV_PCM_RATE_8000_44100|SNDRV_PCM_RATE_48000)
  120. #define SNDRV_PCM_RATE_8000_96000 (SNDRV_PCM_RATE_8000_48000|SNDRV_PCM_RATE_64000|\
  121. SNDRV_PCM_RATE_88200|SNDRV_PCM_RATE_96000)
  122. #define SNDRV_PCM_RATE_8000_192000 (SNDRV_PCM_RATE_8000_96000|SNDRV_PCM_RATE_176400|\
  123. SNDRV_PCM_RATE_192000)
  124. #define _SNDRV_PCM_FMTBIT(fmt) (1ULL << (__force int)SNDRV_PCM_FORMAT_##fmt)
  125. #define SNDRV_PCM_FMTBIT_S8 _SNDRV_PCM_FMTBIT(S8)
  126. #define SNDRV_PCM_FMTBIT_U8 _SNDRV_PCM_FMTBIT(U8)
  127. #define SNDRV_PCM_FMTBIT_S16_LE _SNDRV_PCM_FMTBIT(S16_LE)
  128. #define SNDRV_PCM_FMTBIT_S16_BE _SNDRV_PCM_FMTBIT(S16_BE)
  129. #define SNDRV_PCM_FMTBIT_U16_LE _SNDRV_PCM_FMTBIT(U16_LE)
  130. #define SNDRV_PCM_FMTBIT_U16_BE _SNDRV_PCM_FMTBIT(U16_BE)
  131. #define SNDRV_PCM_FMTBIT_S24_LE _SNDRV_PCM_FMTBIT(S24_LE)
  132. #define SNDRV_PCM_FMTBIT_S24_BE _SNDRV_PCM_FMTBIT(S24_BE)
  133. #define SNDRV_PCM_FMTBIT_U24_LE _SNDRV_PCM_FMTBIT(U24_LE)
  134. #define SNDRV_PCM_FMTBIT_U24_BE _SNDRV_PCM_FMTBIT(U24_BE)
  135. #define SNDRV_PCM_FMTBIT_S32_LE _SNDRV_PCM_FMTBIT(S32_LE)
  136. #define SNDRV_PCM_FMTBIT_S32_BE _SNDRV_PCM_FMTBIT(S32_BE)
  137. #define SNDRV_PCM_FMTBIT_U32_LE _SNDRV_PCM_FMTBIT(U32_LE)
  138. #define SNDRV_PCM_FMTBIT_U32_BE _SNDRV_PCM_FMTBIT(U32_BE)
  139. #define SNDRV_PCM_FMTBIT_FLOAT_LE _SNDRV_PCM_FMTBIT(FLOAT_LE)
  140. #define SNDRV_PCM_FMTBIT_FLOAT_BE _SNDRV_PCM_FMTBIT(FLOAT_BE)
  141. #define SNDRV_PCM_FMTBIT_FLOAT64_LE _SNDRV_PCM_FMTBIT(FLOAT64_LE)
  142. #define SNDRV_PCM_FMTBIT_FLOAT64_BE _SNDRV_PCM_FMTBIT(FLOAT64_BE)
  143. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE _SNDRV_PCM_FMTBIT(IEC958_SUBFRAME_LE)
  144. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE _SNDRV_PCM_FMTBIT(IEC958_SUBFRAME_BE)
  145. #define SNDRV_PCM_FMTBIT_MU_LAW _SNDRV_PCM_FMTBIT(MU_LAW)
  146. #define SNDRV_PCM_FMTBIT_A_LAW _SNDRV_PCM_FMTBIT(A_LAW)
  147. #define SNDRV_PCM_FMTBIT_IMA_ADPCM _SNDRV_PCM_FMTBIT(IMA_ADPCM)
  148. #define SNDRV_PCM_FMTBIT_MPEG _SNDRV_PCM_FMTBIT(MPEG)
  149. #define SNDRV_PCM_FMTBIT_GSM _SNDRV_PCM_FMTBIT(GSM)
  150. #define SNDRV_PCM_FMTBIT_SPECIAL _SNDRV_PCM_FMTBIT(SPECIAL)
  151. #define SNDRV_PCM_FMTBIT_S24_3LE _SNDRV_PCM_FMTBIT(S24_3LE)
  152. #define SNDRV_PCM_FMTBIT_U24_3LE _SNDRV_PCM_FMTBIT(U24_3LE)
  153. #define SNDRV_PCM_FMTBIT_S24_3BE _SNDRV_PCM_FMTBIT(S24_3BE)
  154. #define SNDRV_PCM_FMTBIT_U24_3BE _SNDRV_PCM_FMTBIT(U24_3BE)
  155. #define SNDRV_PCM_FMTBIT_S20_3LE _SNDRV_PCM_FMTBIT(S20_3LE)
  156. #define SNDRV_PCM_FMTBIT_U20_3LE _SNDRV_PCM_FMTBIT(U20_3LE)
  157. #define SNDRV_PCM_FMTBIT_S20_3BE _SNDRV_PCM_FMTBIT(S20_3BE)
  158. #define SNDRV_PCM_FMTBIT_U20_3BE _SNDRV_PCM_FMTBIT(U20_3BE)
  159. #define SNDRV_PCM_FMTBIT_S18_3LE _SNDRV_PCM_FMTBIT(S18_3LE)
  160. #define SNDRV_PCM_FMTBIT_U18_3LE _SNDRV_PCM_FMTBIT(U18_3LE)
  161. #define SNDRV_PCM_FMTBIT_S18_3BE _SNDRV_PCM_FMTBIT(S18_3BE)
  162. #define SNDRV_PCM_FMTBIT_U18_3BE _SNDRV_PCM_FMTBIT(U18_3BE)
  163. #define SNDRV_PCM_FMTBIT_G723_24 _SNDRV_PCM_FMTBIT(G723_24)
  164. #define SNDRV_PCM_FMTBIT_G723_24_1B _SNDRV_PCM_FMTBIT(G723_24_1B)
  165. #define SNDRV_PCM_FMTBIT_G723_40 _SNDRV_PCM_FMTBIT(G723_40)
  166. #define SNDRV_PCM_FMTBIT_G723_40_1B _SNDRV_PCM_FMTBIT(G723_40_1B)
  167. #define SNDRV_PCM_FMTBIT_DSD_U8 _SNDRV_PCM_FMTBIT(DSD_U8)
  168. #define SNDRV_PCM_FMTBIT_DSD_U16_LE _SNDRV_PCM_FMTBIT(DSD_U16_LE)
  169. #ifdef SNDRV_LITTLE_ENDIAN
  170. #define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_LE
  171. #define SNDRV_PCM_FMTBIT_U16 SNDRV_PCM_FMTBIT_U16_LE
  172. #define SNDRV_PCM_FMTBIT_S24 SNDRV_PCM_FMTBIT_S24_LE
  173. #define SNDRV_PCM_FMTBIT_U24 SNDRV_PCM_FMTBIT_U24_LE
  174. #define SNDRV_PCM_FMTBIT_S32 SNDRV_PCM_FMTBIT_S32_LE
  175. #define SNDRV_PCM_FMTBIT_U32 SNDRV_PCM_FMTBIT_U32_LE
  176. #define SNDRV_PCM_FMTBIT_FLOAT SNDRV_PCM_FMTBIT_FLOAT_LE
  177. #define SNDRV_PCM_FMTBIT_FLOAT64 SNDRV_PCM_FMTBIT_FLOAT64_LE
  178. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
  179. #endif
  180. #ifdef SNDRV_BIG_ENDIAN
  181. #define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_BE
  182. #define SNDRV_PCM_FMTBIT_U16 SNDRV_PCM_FMTBIT_U16_BE
  183. #define SNDRV_PCM_FMTBIT_S24 SNDRV_PCM_FMTBIT_S24_BE
  184. #define SNDRV_PCM_FMTBIT_U24 SNDRV_PCM_FMTBIT_U24_BE
  185. #define SNDRV_PCM_FMTBIT_S32 SNDRV_PCM_FMTBIT_S32_BE
  186. #define SNDRV_PCM_FMTBIT_U32 SNDRV_PCM_FMTBIT_U32_BE
  187. #define SNDRV_PCM_FMTBIT_FLOAT SNDRV_PCM_FMTBIT_FLOAT_BE
  188. #define SNDRV_PCM_FMTBIT_FLOAT64 SNDRV_PCM_FMTBIT_FLOAT64_BE
  189. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
  190. #endif
  191. struct snd_pcm_file {
  192. struct snd_pcm_substream *substream;
  193. int no_compat_mmap;
  194. };
  195. struct snd_pcm_hw_rule;
  196. typedef int (*snd_pcm_hw_rule_func_t)(struct snd_pcm_hw_params *params,
  197. struct snd_pcm_hw_rule *rule);
  198. struct snd_pcm_hw_rule {
  199. unsigned int cond;
  200. snd_pcm_hw_rule_func_t func;
  201. int var;
  202. int deps[4];
  203. void *private;
  204. };
  205. struct snd_pcm_hw_constraints {
  206. struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK -
  207. SNDRV_PCM_HW_PARAM_FIRST_MASK + 1];
  208. struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL -
  209. SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1];
  210. unsigned int rules_num;
  211. unsigned int rules_all;
  212. struct snd_pcm_hw_rule *rules;
  213. };
  214. static inline struct snd_mask *constrs_mask(struct snd_pcm_hw_constraints *constrs,
  215. snd_pcm_hw_param_t var)
  216. {
  217. return &constrs->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  218. }
  219. static inline struct snd_interval *constrs_interval(struct snd_pcm_hw_constraints *constrs,
  220. snd_pcm_hw_param_t var)
  221. {
  222. return &constrs->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  223. }
  224. struct snd_ratnum {
  225. unsigned int num;
  226. unsigned int den_min, den_max, den_step;
  227. };
  228. struct snd_ratden {
  229. unsigned int num_min, num_max, num_step;
  230. unsigned int den;
  231. };
  232. struct snd_pcm_hw_constraint_ratnums {
  233. int nrats;
  234. struct snd_ratnum *rats;
  235. };
  236. struct snd_pcm_hw_constraint_ratdens {
  237. int nrats;
  238. struct snd_ratden *rats;
  239. };
  240. struct snd_pcm_hw_constraint_list {
  241. unsigned int count;
  242. const unsigned int *list;
  243. unsigned int mask;
  244. };
  245. struct snd_pcm_hwptr_log;
  246. struct snd_pcm_runtime {
  247. /* -- Status -- */
  248. struct snd_pcm_substream *trigger_master;
  249. struct timespec trigger_tstamp; /* trigger timestamp */
  250. int overrange;
  251. snd_pcm_uframes_t avail_max;
  252. snd_pcm_uframes_t hw_ptr_base; /* Position at buffer restart */
  253. snd_pcm_uframes_t hw_ptr_interrupt; /* Position at interrupt time */
  254. unsigned long hw_ptr_jiffies; /* Time when hw_ptr is updated */
  255. unsigned long hw_ptr_buffer_jiffies; /* buffer time in jiffies */
  256. snd_pcm_sframes_t delay; /* extra delay; typically FIFO size */
  257. u64 hw_ptr_wrap; /* offset for hw_ptr due to boundary wrap-around */
  258. /* -- HW params -- */
  259. snd_pcm_access_t access; /* access mode */
  260. snd_pcm_format_t format; /* SNDRV_PCM_FORMAT_* */
  261. snd_pcm_subformat_t subformat; /* subformat */
  262. unsigned int rate; /* rate in Hz */
  263. unsigned int channels; /* channels */
  264. snd_pcm_uframes_t period_size; /* period size */
  265. unsigned int periods; /* periods */
  266. snd_pcm_uframes_t buffer_size; /* buffer size */
  267. snd_pcm_uframes_t min_align; /* Min alignment for the format */
  268. size_t byte_align;
  269. unsigned int frame_bits;
  270. unsigned int sample_bits;
  271. unsigned int info;
  272. unsigned int rate_num;
  273. unsigned int rate_den;
  274. unsigned int no_period_wakeup: 1;
  275. /* -- SW params -- */
  276. int tstamp_mode; /* mmap timestamp is updated */
  277. unsigned int period_step;
  278. snd_pcm_uframes_t start_threshold;
  279. snd_pcm_uframes_t stop_threshold;
  280. snd_pcm_uframes_t silence_threshold; /* Silence filling happens when
  281. noise is nearest than this */
  282. snd_pcm_uframes_t silence_size; /* Silence filling size */
  283. snd_pcm_uframes_t boundary; /* pointers wrap point */
  284. snd_pcm_uframes_t silence_start; /* starting pointer to silence area */
  285. snd_pcm_uframes_t silence_filled; /* size filled with silence */
  286. union snd_pcm_sync_id sync; /* hardware synchronization ID */
  287. /* -- mmap -- */
  288. struct snd_pcm_mmap_status *status;
  289. struct snd_pcm_mmap_control *control;
  290. /* -- locking / scheduling -- */
  291. snd_pcm_uframes_t twake; /* do transfer (!poll) wakeup if non-zero */
  292. wait_queue_head_t sleep; /* poll sleep */
  293. wait_queue_head_t tsleep; /* transfer sleep */
  294. struct fasync_struct *fasync;
  295. /* -- private section -- */
  296. void *private_data;
  297. void (*private_free)(struct snd_pcm_runtime *runtime);
  298. /* -- hardware description -- */
  299. struct snd_pcm_hardware hw;
  300. struct snd_pcm_hw_constraints hw_constraints;
  301. /* -- interrupt callbacks -- */
  302. void (*transfer_ack_begin)(struct snd_pcm_substream *substream);
  303. void (*transfer_ack_end)(struct snd_pcm_substream *substream);
  304. /* -- timer -- */
  305. unsigned int timer_resolution; /* timer resolution */
  306. int tstamp_type; /* timestamp type */
  307. /* -- DMA -- */
  308. unsigned char *dma_area; /* DMA area */
  309. dma_addr_t dma_addr; /* physical bus address (not accessible from main CPU) */
  310. size_t dma_bytes; /* size of DMA area */
  311. struct snd_dma_buffer *dma_buffer_p; /* allocated buffer */
  312. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  313. /* -- OSS things -- */
  314. struct snd_pcm_oss_runtime oss;
  315. #endif
  316. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  317. struct snd_pcm_hwptr_log *hwptr_log;
  318. #endif
  319. };
  320. struct snd_pcm_group { /* keep linked substreams */
  321. spinlock_t lock;
  322. struct list_head substreams;
  323. int count;
  324. };
  325. struct pid;
  326. struct snd_pcm_substream {
  327. struct snd_pcm *pcm;
  328. struct snd_pcm_str *pstr;
  329. void *private_data; /* copied from pcm->private_data */
  330. int number;
  331. char name[32]; /* substream name */
  332. int stream; /* stream (direction) */
  333. struct pm_qos_request latency_pm_qos_req; /* pm_qos request */
  334. size_t buffer_bytes_max; /* limit ring buffer size */
  335. struct snd_dma_buffer dma_buffer;
  336. size_t dma_max;
  337. /* -- hardware operations -- */
  338. const struct snd_pcm_ops *ops;
  339. /* -- runtime information -- */
  340. struct snd_pcm_runtime *runtime;
  341. /* -- timer section -- */
  342. struct snd_timer *timer; /* timer */
  343. unsigned timer_running: 1; /* time is running */
  344. /* -- next substream -- */
  345. struct snd_pcm_substream *next;
  346. /* -- linked substreams -- */
  347. struct list_head link_list; /* linked list member */
  348. struct snd_pcm_group self_group; /* fake group for non linked substream (with substream lock inside) */
  349. struct snd_pcm_group *group; /* pointer to current group */
  350. /* -- assigned files -- */
  351. void *file;
  352. int ref_count;
  353. atomic_t mmap_count;
  354. unsigned int f_flags;
  355. void (*pcm_release)(struct snd_pcm_substream *);
  356. struct pid *pid;
  357. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  358. /* -- OSS things -- */
  359. struct snd_pcm_oss_substream oss;
  360. #endif
  361. #ifdef CONFIG_SND_VERBOSE_PROCFS
  362. struct snd_info_entry *proc_root;
  363. struct snd_info_entry *proc_info_entry;
  364. struct snd_info_entry *proc_hw_params_entry;
  365. struct snd_info_entry *proc_sw_params_entry;
  366. struct snd_info_entry *proc_status_entry;
  367. struct snd_info_entry *proc_prealloc_entry;
  368. struct snd_info_entry *proc_prealloc_max_entry;
  369. #endif
  370. /* misc flags */
  371. unsigned int hw_opened: 1;
  372. };
  373. #define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
  374. struct snd_pcm_str {
  375. int stream; /* stream (direction) */
  376. struct snd_pcm *pcm;
  377. /* -- substreams -- */
  378. unsigned int substream_count;
  379. unsigned int substream_opened;
  380. struct snd_pcm_substream *substream;
  381. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  382. /* -- OSS things -- */
  383. struct snd_pcm_oss_stream oss;
  384. #endif
  385. #ifdef CONFIG_SND_VERBOSE_PROCFS
  386. struct snd_info_entry *proc_root;
  387. struct snd_info_entry *proc_info_entry;
  388. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  389. unsigned int xrun_debug; /* 0 = disabled, 1 = verbose, 2 = stacktrace */
  390. struct snd_info_entry *proc_xrun_debug_entry;
  391. #endif
  392. #endif
  393. struct snd_kcontrol *chmap_kctl; /* channel-mapping controls */
  394. };
  395. struct snd_pcm {
  396. struct snd_card *card;
  397. struct list_head list;
  398. int device; /* device number */
  399. unsigned int info_flags;
  400. unsigned short dev_class;
  401. unsigned short dev_subclass;
  402. char id[64];
  403. char name[80];
  404. struct snd_pcm_str streams[2];
  405. struct mutex open_mutex;
  406. wait_queue_head_t open_wait;
  407. void *private_data;
  408. void (*private_free) (struct snd_pcm *pcm);
  409. struct device *dev; /* actual hw device this belongs to */
  410. bool internal; /* pcm is for internal use only */
  411. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  412. struct snd_pcm_oss oss;
  413. #endif
  414. };
  415. struct snd_pcm_notify {
  416. int (*n_register) (struct snd_pcm * pcm);
  417. int (*n_disconnect) (struct snd_pcm * pcm);
  418. int (*n_unregister) (struct snd_pcm * pcm);
  419. struct list_head list;
  420. };
  421. /*
  422. * Registering
  423. */
  424. extern const struct file_operations snd_pcm_f_ops[2];
  425. int snd_pcm_new(struct snd_card *card, const char *id, int device,
  426. int playback_count, int capture_count,
  427. struct snd_pcm **rpcm);
  428. int snd_pcm_new_internal(struct snd_card *card, const char *id, int device,
  429. int playback_count, int capture_count,
  430. struct snd_pcm **rpcm);
  431. int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count);
  432. int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree);
  433. /*
  434. * Native I/O
  435. */
  436. extern rwlock_t snd_pcm_link_rwlock;
  437. int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info);
  438. int snd_pcm_info_user(struct snd_pcm_substream *substream,
  439. struct snd_pcm_info __user *info);
  440. int snd_pcm_status(struct snd_pcm_substream *substream,
  441. struct snd_pcm_status *status);
  442. int snd_pcm_start(struct snd_pcm_substream *substream);
  443. int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t status);
  444. int snd_pcm_drain_done(struct snd_pcm_substream *substream);
  445. #ifdef CONFIG_PM
  446. int snd_pcm_suspend(struct snd_pcm_substream *substream);
  447. int snd_pcm_suspend_all(struct snd_pcm *pcm);
  448. #endif
  449. int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
  450. int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file,
  451. struct snd_pcm_substream **rsubstream);
  452. void snd_pcm_release_substream(struct snd_pcm_substream *substream);
  453. int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, struct file *file,
  454. struct snd_pcm_substream **rsubstream);
  455. void snd_pcm_detach_substream(struct snd_pcm_substream *substream);
  456. void snd_pcm_vma_notify_data(void *client, void *data);
  457. int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area);
  458. #ifdef CONFIG_SND_DEBUG
  459. void snd_pcm_debug_name(struct snd_pcm_substream *substream,
  460. char *name, size_t len);
  461. #else
  462. static inline void
  463. snd_pcm_debug_name(struct snd_pcm_substream *substream, char *buf, size_t size)
  464. {
  465. *buf = 0;
  466. }
  467. #endif
  468. /*
  469. * PCM library
  470. */
  471. static inline int snd_pcm_stream_linked(struct snd_pcm_substream *substream)
  472. {
  473. return substream->group != &substream->self_group;
  474. }
  475. static inline void snd_pcm_stream_lock(struct snd_pcm_substream *substream)
  476. {
  477. read_lock(&snd_pcm_link_rwlock);
  478. spin_lock(&substream->self_group.lock);
  479. }
  480. static inline void snd_pcm_stream_unlock(struct snd_pcm_substream *substream)
  481. {
  482. spin_unlock(&substream->self_group.lock);
  483. read_unlock(&snd_pcm_link_rwlock);
  484. }
  485. static inline void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
  486. {
  487. read_lock_irq(&snd_pcm_link_rwlock);
  488. spin_lock(&substream->self_group.lock);
  489. }
  490. static inline void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream)
  491. {
  492. spin_unlock(&substream->self_group.lock);
  493. read_unlock_irq(&snd_pcm_link_rwlock);
  494. }
  495. #define snd_pcm_stream_lock_irqsave(substream, flags) \
  496. do { \
  497. read_lock_irqsave(&snd_pcm_link_rwlock, (flags)); \
  498. spin_lock(&substream->self_group.lock); \
  499. } while (0)
  500. #define snd_pcm_stream_unlock_irqrestore(substream, flags) \
  501. do { \
  502. spin_unlock(&substream->self_group.lock); \
  503. read_unlock_irqrestore(&snd_pcm_link_rwlock, (flags)); \
  504. } while (0)
  505. #define snd_pcm_group_for_each_entry(s, substream) \
  506. list_for_each_entry(s, &substream->group->substreams, link_list)
  507. static inline int snd_pcm_running(struct snd_pcm_substream *substream)
  508. {
  509. return (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING ||
  510. (substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
  511. substream->stream == SNDRV_PCM_STREAM_PLAYBACK));
  512. }
  513. static inline ssize_t bytes_to_samples(struct snd_pcm_runtime *runtime, ssize_t size)
  514. {
  515. return size * 8 / runtime->sample_bits;
  516. }
  517. static inline snd_pcm_sframes_t bytes_to_frames(struct snd_pcm_runtime *runtime, ssize_t size)
  518. {
  519. return size * 8 / runtime->frame_bits;
  520. }
  521. static inline ssize_t samples_to_bytes(struct snd_pcm_runtime *runtime, ssize_t size)
  522. {
  523. return size * runtime->sample_bits / 8;
  524. }
  525. static inline ssize_t frames_to_bytes(struct snd_pcm_runtime *runtime, snd_pcm_sframes_t size)
  526. {
  527. return size * runtime->frame_bits / 8;
  528. }
  529. static inline int frame_aligned(struct snd_pcm_runtime *runtime, ssize_t bytes)
  530. {
  531. return bytes % runtime->byte_align == 0;
  532. }
  533. static inline size_t snd_pcm_lib_buffer_bytes(struct snd_pcm_substream *substream)
  534. {
  535. struct snd_pcm_runtime *runtime = substream->runtime;
  536. return frames_to_bytes(runtime, runtime->buffer_size);
  537. }
  538. static inline size_t snd_pcm_lib_period_bytes(struct snd_pcm_substream *substream)
  539. {
  540. struct snd_pcm_runtime *runtime = substream->runtime;
  541. return frames_to_bytes(runtime, runtime->period_size);
  542. }
  543. /*
  544. * result is: 0 ... (boundary - 1)
  545. */
  546. static inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *runtime)
  547. {
  548. snd_pcm_sframes_t avail = runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_ptr;
  549. if (avail < 0)
  550. avail += runtime->boundary;
  551. else if ((snd_pcm_uframes_t) avail >= runtime->boundary)
  552. avail -= runtime->boundary;
  553. return avail;
  554. }
  555. /*
  556. * result is: 0 ... (boundary - 1)
  557. */
  558. static inline snd_pcm_uframes_t snd_pcm_capture_avail(struct snd_pcm_runtime *runtime)
  559. {
  560. snd_pcm_sframes_t avail = runtime->status->hw_ptr - runtime->control->appl_ptr;
  561. if (avail < 0)
  562. avail += runtime->boundary;
  563. return avail;
  564. }
  565. static inline snd_pcm_sframes_t snd_pcm_playback_hw_avail(struct snd_pcm_runtime *runtime)
  566. {
  567. return runtime->buffer_size - snd_pcm_playback_avail(runtime);
  568. }
  569. static inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(struct snd_pcm_runtime *runtime)
  570. {
  571. return runtime->buffer_size - snd_pcm_capture_avail(runtime);
  572. }
  573. /**
  574. * snd_pcm_playback_ready - check whether the playback buffer is available
  575. * @substream: the pcm substream instance
  576. *
  577. * Checks whether enough free space is available on the playback buffer.
  578. *
  579. * Return: Non-zero if available, or zero if not.
  580. */
  581. static inline int snd_pcm_playback_ready(struct snd_pcm_substream *substream)
  582. {
  583. struct snd_pcm_runtime *runtime = substream->runtime;
  584. return snd_pcm_playback_avail(runtime) >= runtime->control->avail_min;
  585. }
  586. /**
  587. * snd_pcm_capture_ready - check whether the capture buffer is available
  588. * @substream: the pcm substream instance
  589. *
  590. * Checks whether enough capture data is available on the capture buffer.
  591. *
  592. * Return: Non-zero if available, or zero if not.
  593. */
  594. static inline int snd_pcm_capture_ready(struct snd_pcm_substream *substream)
  595. {
  596. struct snd_pcm_runtime *runtime = substream->runtime;
  597. return snd_pcm_capture_avail(runtime) >= runtime->control->avail_min;
  598. }
  599. /**
  600. * snd_pcm_playback_data - check whether any data exists on the playback buffer
  601. * @substream: the pcm substream instance
  602. *
  603. * Checks whether any data exists on the playback buffer.
  604. *
  605. * Return: Non-zero if any data exists, or zero if not. If stop_threshold
  606. * is bigger or equal to boundary, then this function returns always non-zero.
  607. */
  608. static inline int snd_pcm_playback_data(struct snd_pcm_substream *substream)
  609. {
  610. struct snd_pcm_runtime *runtime = substream->runtime;
  611. if (runtime->stop_threshold >= runtime->boundary)
  612. return 1;
  613. return snd_pcm_playback_avail(runtime) < runtime->buffer_size;
  614. }
  615. /**
  616. * snd_pcm_playback_empty - check whether the playback buffer is empty
  617. * @substream: the pcm substream instance
  618. *
  619. * Checks whether the playback buffer is empty.
  620. *
  621. * Return: Non-zero if empty, or zero if not.
  622. */
  623. static inline int snd_pcm_playback_empty(struct snd_pcm_substream *substream)
  624. {
  625. struct snd_pcm_runtime *runtime = substream->runtime;
  626. return snd_pcm_playback_avail(runtime) >= runtime->buffer_size;
  627. }
  628. /**
  629. * snd_pcm_capture_empty - check whether the capture buffer is empty
  630. * @substream: the pcm substream instance
  631. *
  632. * Checks whether the capture buffer is empty.
  633. *
  634. * Return: Non-zero if empty, or zero if not.
  635. */
  636. static inline int snd_pcm_capture_empty(struct snd_pcm_substream *substream)
  637. {
  638. struct snd_pcm_runtime *runtime = substream->runtime;
  639. return snd_pcm_capture_avail(runtime) == 0;
  640. }
  641. static inline void snd_pcm_trigger_done(struct snd_pcm_substream *substream,
  642. struct snd_pcm_substream *master)
  643. {
  644. substream->runtime->trigger_master = master;
  645. }
  646. static inline int hw_is_mask(int var)
  647. {
  648. return var >= SNDRV_PCM_HW_PARAM_FIRST_MASK &&
  649. var <= SNDRV_PCM_HW_PARAM_LAST_MASK;
  650. }
  651. static inline int hw_is_interval(int var)
  652. {
  653. return var >= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL &&
  654. var <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL;
  655. }
  656. static inline struct snd_mask *hw_param_mask(struct snd_pcm_hw_params *params,
  657. snd_pcm_hw_param_t var)
  658. {
  659. return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  660. }
  661. static inline struct snd_interval *hw_param_interval(struct snd_pcm_hw_params *params,
  662. snd_pcm_hw_param_t var)
  663. {
  664. return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  665. }
  666. static inline const struct snd_mask *hw_param_mask_c(const struct snd_pcm_hw_params *params,
  667. snd_pcm_hw_param_t var)
  668. {
  669. return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  670. }
  671. static inline const struct snd_interval *hw_param_interval_c(const struct snd_pcm_hw_params *params,
  672. snd_pcm_hw_param_t var)
  673. {
  674. return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  675. }
  676. #define params_channels(p) \
  677. (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_CHANNELS)->min)
  678. #define params_rate(p) \
  679. (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_RATE)->min)
  680. #define params_period_size(p) \
  681. (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min)
  682. #define params_periods(p) \
  683. (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_PERIODS)->min)
  684. #define params_buffer_size(p) \
  685. (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min)
  686. #define params_buffer_bytes(p) \
  687. (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min)
  688. int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v);
  689. void snd_interval_mul(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c);
  690. void snd_interval_div(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c);
  691. void snd_interval_muldivk(const struct snd_interval *a, const struct snd_interval *b,
  692. unsigned int k, struct snd_interval *c);
  693. void snd_interval_mulkdiv(const struct snd_interval *a, unsigned int k,
  694. const struct snd_interval *b, struct snd_interval *c);
  695. int snd_interval_list(struct snd_interval *i, unsigned int count,
  696. const unsigned int *list, unsigned int mask);
  697. int snd_interval_ratnum(struct snd_interval *i,
  698. unsigned int rats_count, struct snd_ratnum *rats,
  699. unsigned int *nump, unsigned int *denp);
  700. void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params);
  701. void _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var);
  702. int snd_pcm_hw_params_choose(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
  703. int snd_pcm_hw_refine(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
  704. int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream);
  705. int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream);
  706. int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  707. u_int32_t mask);
  708. int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  709. u_int64_t mask);
  710. int snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  711. unsigned int min, unsigned int max);
  712. int snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var);
  713. int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime,
  714. unsigned int cond,
  715. snd_pcm_hw_param_t var,
  716. const struct snd_pcm_hw_constraint_list *l);
  717. int snd_pcm_hw_constraint_ratnums(struct snd_pcm_runtime *runtime,
  718. unsigned int cond,
  719. snd_pcm_hw_param_t var,
  720. struct snd_pcm_hw_constraint_ratnums *r);
  721. int snd_pcm_hw_constraint_ratdens(struct snd_pcm_runtime *runtime,
  722. unsigned int cond,
  723. snd_pcm_hw_param_t var,
  724. struct snd_pcm_hw_constraint_ratdens *r);
  725. int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime,
  726. unsigned int cond,
  727. unsigned int width,
  728. unsigned int msbits);
  729. int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
  730. unsigned int cond,
  731. snd_pcm_hw_param_t var,
  732. unsigned long step);
  733. int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
  734. unsigned int cond,
  735. snd_pcm_hw_param_t var);
  736. int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
  737. unsigned int base_rate);
  738. int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime,
  739. unsigned int cond,
  740. int var,
  741. snd_pcm_hw_rule_func_t func, void *private,
  742. int dep, ...);
  743. int snd_pcm_format_signed(snd_pcm_format_t format);
  744. int snd_pcm_format_unsigned(snd_pcm_format_t format);
  745. int snd_pcm_format_linear(snd_pcm_format_t format);
  746. int snd_pcm_format_little_endian(snd_pcm_format_t format);
  747. int snd_pcm_format_big_endian(snd_pcm_format_t format);
  748. #if 0 /* just for DocBook */
  749. /**
  750. * snd_pcm_format_cpu_endian - Check the PCM format is CPU-endian
  751. * @format: the format to check
  752. *
  753. * Return: 1 if the given PCM format is CPU-endian, 0 if
  754. * opposite, or a negative error code if endian not specified.
  755. */
  756. int snd_pcm_format_cpu_endian(snd_pcm_format_t format);
  757. #endif /* DocBook */
  758. #ifdef SNDRV_LITTLE_ENDIAN
  759. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_little_endian(format)
  760. #else
  761. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_big_endian(format)
  762. #endif
  763. int snd_pcm_format_width(snd_pcm_format_t format); /* in bits */
  764. int snd_pcm_format_physical_width(snd_pcm_format_t format); /* in bits */
  765. ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
  766. const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format);
  767. int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
  768. snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsigned, int big_endian);
  769. void snd_pcm_set_ops(struct snd_pcm * pcm, int direction,
  770. const struct snd_pcm_ops *ops);
  771. void snd_pcm_set_sync(struct snd_pcm_substream *substream);
  772. int snd_pcm_lib_interleave_len(struct snd_pcm_substream *substream);
  773. int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  774. unsigned int cmd, void *arg);
  775. int snd_pcm_update_state(struct snd_pcm_substream *substream,
  776. struct snd_pcm_runtime *runtime);
  777. int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream);
  778. int snd_pcm_playback_xrun_check(struct snd_pcm_substream *substream);
  779. int snd_pcm_capture_xrun_check(struct snd_pcm_substream *substream);
  780. int snd_pcm_playback_xrun_asap(struct snd_pcm_substream *substream);
  781. int snd_pcm_capture_xrun_asap(struct snd_pcm_substream *substream);
  782. void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_uframes_t new_hw_ptr);
  783. void snd_pcm_period_elapsed(struct snd_pcm_substream *substream);
  784. snd_pcm_sframes_t snd_pcm_lib_write(struct snd_pcm_substream *substream,
  785. const void __user *buf,
  786. snd_pcm_uframes_t frames);
  787. snd_pcm_sframes_t snd_pcm_lib_read(struct snd_pcm_substream *substream,
  788. void __user *buf, snd_pcm_uframes_t frames);
  789. snd_pcm_sframes_t snd_pcm_lib_writev(struct snd_pcm_substream *substream,
  790. void __user **bufs, snd_pcm_uframes_t frames);
  791. snd_pcm_sframes_t snd_pcm_lib_readv(struct snd_pcm_substream *substream,
  792. void __user **bufs, snd_pcm_uframes_t frames);
  793. extern const struct snd_pcm_hw_constraint_list snd_pcm_known_rates;
  794. int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime);
  795. unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate);
  796. unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit);
  797. unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
  798. unsigned int rates_b);
  799. static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substream,
  800. struct snd_dma_buffer *bufp)
  801. {
  802. struct snd_pcm_runtime *runtime = substream->runtime;
  803. if (bufp) {
  804. runtime->dma_buffer_p = bufp;
  805. runtime->dma_area = bufp->area;
  806. runtime->dma_addr = bufp->addr;
  807. runtime->dma_bytes = bufp->bytes;
  808. } else {
  809. runtime->dma_buffer_p = NULL;
  810. runtime->dma_area = NULL;
  811. runtime->dma_addr = 0;
  812. runtime->dma_bytes = 0;
  813. }
  814. }
  815. /*
  816. * Timer interface
  817. */
  818. void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream);
  819. void snd_pcm_timer_init(struct snd_pcm_substream *substream);
  820. void snd_pcm_timer_done(struct snd_pcm_substream *substream);
  821. static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
  822. struct timespec *tv)
  823. {
  824. if (runtime->tstamp_type == SNDRV_PCM_TSTAMP_TYPE_MONOTONIC)
  825. ktime_get_ts(tv);
  826. else
  827. getnstimeofday(tv);
  828. }
  829. /*
  830. * Memory
  831. */
  832. int snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream);
  833. int snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm);
  834. int snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
  835. int type, struct device *data,
  836. size_t size, size_t max);
  837. int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
  838. int type, void *data,
  839. size_t size, size_t max);
  840. int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size);
  841. int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream);
  842. int _snd_pcm_lib_alloc_vmalloc_buffer(struct snd_pcm_substream *substream,
  843. size_t size, gfp_t gfp_flags);
  844. int snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream);
  845. struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream,
  846. unsigned long offset);
  847. #if 0 /* for kernel-doc */
  848. /**
  849. * snd_pcm_lib_alloc_vmalloc_buffer - allocate virtual DMA buffer
  850. * @substream: the substream to allocate the buffer to
  851. * @size: the requested buffer size, in bytes
  852. *
  853. * Allocates the PCM substream buffer using vmalloc(), i.e., the memory is
  854. * contiguous in kernel virtual space, but not in physical memory. Use this
  855. * if the buffer is accessed by kernel code but not by device DMA.
  856. *
  857. * Return: 1 if the buffer was changed, 0 if not changed, or a negative error
  858. * code.
  859. */
  860. static int snd_pcm_lib_alloc_vmalloc_buffer
  861. (struct snd_pcm_substream *substream, size_t size);
  862. /**
  863. * snd_pcm_lib_alloc_vmalloc_32_buffer - allocate 32-bit-addressable buffer
  864. * @substream: the substream to allocate the buffer to
  865. * @size: the requested buffer size, in bytes
  866. *
  867. * This function works like snd_pcm_lib_alloc_vmalloc_buffer(), but uses
  868. * vmalloc_32(), i.e., the pages are allocated from 32-bit-addressable memory.
  869. *
  870. * Return: 1 if the buffer was changed, 0 if not changed, or a negative error
  871. * code.
  872. */
  873. static int snd_pcm_lib_alloc_vmalloc_32_buffer
  874. (struct snd_pcm_substream *substream, size_t size);
  875. #endif
  876. #define snd_pcm_lib_alloc_vmalloc_buffer(subs, size) \
  877. _snd_pcm_lib_alloc_vmalloc_buffer \
  878. (subs, size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO)
  879. #define snd_pcm_lib_alloc_vmalloc_32_buffer(subs, size) \
  880. _snd_pcm_lib_alloc_vmalloc_buffer \
  881. (subs, size, GFP_KERNEL | GFP_DMA32 | __GFP_ZERO)
  882. #define snd_pcm_get_dma_buf(substream) ((substream)->runtime->dma_buffer_p)
  883. #ifdef CONFIG_SND_DMA_SGBUF
  884. /*
  885. * SG-buffer handling
  886. */
  887. #define snd_pcm_substream_sgbuf(substream) \
  888. snd_pcm_get_dma_buf(substream)->private_data
  889. struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream,
  890. unsigned long offset);
  891. #else /* !SND_DMA_SGBUF */
  892. /*
  893. * fake using a continuous buffer
  894. */
  895. #define snd_pcm_sgbuf_ops_page NULL
  896. #endif /* SND_DMA_SGBUF */
  897. static inline dma_addr_t
  898. snd_pcm_sgbuf_get_addr(struct snd_pcm_substream *substream, unsigned int ofs)
  899. {
  900. return snd_sgbuf_get_addr(snd_pcm_get_dma_buf(substream), ofs);
  901. }
  902. static inline void *
  903. snd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs)
  904. {
  905. return snd_sgbuf_get_ptr(snd_pcm_get_dma_buf(substream), ofs);
  906. }
  907. static inline unsigned int
  908. snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream,
  909. unsigned int ofs, unsigned int size)
  910. {
  911. return snd_sgbuf_get_chunk_size(snd_pcm_get_dma_buf(substream), ofs, size);
  912. }
  913. /* handle mmap counter - PCM mmap callback should handle this counter properly */
  914. static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area)
  915. {
  916. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  917. atomic_inc(&substream->mmap_count);
  918. }
  919. static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area)
  920. {
  921. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  922. atomic_dec(&substream->mmap_count);
  923. }
  924. int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
  925. struct vm_area_struct *area);
  926. /* mmap for io-memory area */
  927. #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
  928. #define SNDRV_PCM_INFO_MMAP_IOMEM SNDRV_PCM_INFO_MMAP
  929. int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, struct vm_area_struct *area);
  930. #else
  931. #define SNDRV_PCM_INFO_MMAP_IOMEM 0
  932. #define snd_pcm_lib_mmap_iomem NULL
  933. #endif
  934. #define snd_pcm_lib_mmap_vmalloc NULL
  935. static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
  936. {
  937. *max = dma < 4 ? 64 * 1024 : 128 * 1024;
  938. }
  939. /*
  940. * Misc
  941. */
  942. #define SNDRV_PCM_DEFAULT_CON_SPDIF (IEC958_AES0_CON_EMPHASIS_NONE|\
  943. (IEC958_AES1_CON_ORIGINAL<<8)|\
  944. (IEC958_AES1_CON_PCM_CODER<<8)|\
  945. (IEC958_AES3_CON_FS_48000<<24))
  946. #define PCM_RUNTIME_CHECK(sub) snd_BUG_ON(!(sub) || !(sub)->runtime)
  947. const char *snd_pcm_format_name(snd_pcm_format_t format);
  948. /**
  949. * snd_pcm_stream_str - Get a string naming the direction of a stream
  950. * @substream: the pcm substream instance
  951. *
  952. * Return: A string naming the direction of the stream.
  953. */
  954. static inline const char *snd_pcm_stream_str(struct snd_pcm_substream *substream)
  955. {
  956. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  957. return "Playback";
  958. else
  959. return "Capture";
  960. }
  961. /*
  962. * PCM channel-mapping control API
  963. */
  964. /* array element of channel maps */
  965. struct snd_pcm_chmap_elem {
  966. unsigned char channels;
  967. unsigned char map[15];
  968. };
  969. /* channel map information; retrieved via snd_kcontrol_chip() */
  970. struct snd_pcm_chmap {
  971. struct snd_pcm *pcm; /* assigned PCM instance */
  972. int stream; /* PLAYBACK or CAPTURE */
  973. struct snd_kcontrol *kctl;
  974. const struct snd_pcm_chmap_elem *chmap;
  975. unsigned int max_channels;
  976. unsigned int channel_mask; /* optional: active channels bitmask */
  977. void *private_data; /* optional: private data pointer */
  978. };
  979. /* get the PCM substream assigned to the given chmap info */
  980. static inline struct snd_pcm_substream *
  981. snd_pcm_chmap_substream(struct snd_pcm_chmap *info, unsigned int idx)
  982. {
  983. struct snd_pcm_substream *s;
  984. for (s = info->pcm->streams[info->stream].substream; s; s = s->next)
  985. if (s->number == idx)
  986. return s;
  987. return NULL;
  988. }
  989. /* ALSA-standard channel maps (RL/RR prior to C/LFE) */
  990. extern const struct snd_pcm_chmap_elem snd_pcm_std_chmaps[];
  991. /* Other world's standard channel maps (C/LFE prior to RL/RR) */
  992. extern const struct snd_pcm_chmap_elem snd_pcm_alt_chmaps[];
  993. /* bit masks to be passed to snd_pcm_chmap.channel_mask field */
  994. #define SND_PCM_CHMAP_MASK_24 ((1U << 2) | (1U << 4))
  995. #define SND_PCM_CHMAP_MASK_246 (SND_PCM_CHMAP_MASK_24 | (1U << 6))
  996. #define SND_PCM_CHMAP_MASK_2468 (SND_PCM_CHMAP_MASK_246 | (1U << 8))
  997. int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
  998. const struct snd_pcm_chmap_elem *chmap,
  999. int max_channels,
  1000. unsigned long private_value,
  1001. struct snd_pcm_chmap **info_ret);
  1002. /* Strong-typed conversion of pcm_format to bitwise */
  1003. static inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format)
  1004. {
  1005. return 1ULL << (__force int) pcm_format;
  1006. }
  1007. /* printk helpers */
  1008. #define pcm_err(pcm, fmt, args...) \
  1009. dev_err((pcm)->card->dev, fmt, ##args)
  1010. #define pcm_warn(pcm, fmt, args...) \
  1011. dev_warn((pcm)->card->dev, fmt, ##args)
  1012. #define pcm_dbg(pcm, fmt, args...) \
  1013. dev_dbg((pcm)->card->dev, fmt, ##args)
  1014. #endif /* __SOUND_PCM_H */