pcm.h 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129
  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. #ifdef SNDRV_LITTLE_ENDIAN
  168. #define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_LE
  169. #define SNDRV_PCM_FMTBIT_U16 SNDRV_PCM_FMTBIT_U16_LE
  170. #define SNDRV_PCM_FMTBIT_S24 SNDRV_PCM_FMTBIT_S24_LE
  171. #define SNDRV_PCM_FMTBIT_U24 SNDRV_PCM_FMTBIT_U24_LE
  172. #define SNDRV_PCM_FMTBIT_S32 SNDRV_PCM_FMTBIT_S32_LE
  173. #define SNDRV_PCM_FMTBIT_U32 SNDRV_PCM_FMTBIT_U32_LE
  174. #define SNDRV_PCM_FMTBIT_FLOAT SNDRV_PCM_FMTBIT_FLOAT_LE
  175. #define SNDRV_PCM_FMTBIT_FLOAT64 SNDRV_PCM_FMTBIT_FLOAT64_LE
  176. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
  177. #endif
  178. #ifdef SNDRV_BIG_ENDIAN
  179. #define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_BE
  180. #define SNDRV_PCM_FMTBIT_U16 SNDRV_PCM_FMTBIT_U16_BE
  181. #define SNDRV_PCM_FMTBIT_S24 SNDRV_PCM_FMTBIT_S24_BE
  182. #define SNDRV_PCM_FMTBIT_U24 SNDRV_PCM_FMTBIT_U24_BE
  183. #define SNDRV_PCM_FMTBIT_S32 SNDRV_PCM_FMTBIT_S32_BE
  184. #define SNDRV_PCM_FMTBIT_U32 SNDRV_PCM_FMTBIT_U32_BE
  185. #define SNDRV_PCM_FMTBIT_FLOAT SNDRV_PCM_FMTBIT_FLOAT_BE
  186. #define SNDRV_PCM_FMTBIT_FLOAT64 SNDRV_PCM_FMTBIT_FLOAT64_BE
  187. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
  188. #endif
  189. struct snd_pcm_file {
  190. struct snd_pcm_substream *substream;
  191. int no_compat_mmap;
  192. };
  193. struct snd_pcm_hw_rule;
  194. typedef int (*snd_pcm_hw_rule_func_t)(struct snd_pcm_hw_params *params,
  195. struct snd_pcm_hw_rule *rule);
  196. struct snd_pcm_hw_rule {
  197. unsigned int cond;
  198. snd_pcm_hw_rule_func_t func;
  199. int var;
  200. int deps[4];
  201. void *private;
  202. };
  203. struct snd_pcm_hw_constraints {
  204. struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK -
  205. SNDRV_PCM_HW_PARAM_FIRST_MASK + 1];
  206. struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL -
  207. SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1];
  208. unsigned int rules_num;
  209. unsigned int rules_all;
  210. struct snd_pcm_hw_rule *rules;
  211. };
  212. static inline struct snd_mask *constrs_mask(struct snd_pcm_hw_constraints *constrs,
  213. snd_pcm_hw_param_t var)
  214. {
  215. return &constrs->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  216. }
  217. static inline struct snd_interval *constrs_interval(struct snd_pcm_hw_constraints *constrs,
  218. snd_pcm_hw_param_t var)
  219. {
  220. return &constrs->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  221. }
  222. struct snd_ratnum {
  223. unsigned int num;
  224. unsigned int den_min, den_max, den_step;
  225. };
  226. struct snd_ratden {
  227. unsigned int num_min, num_max, num_step;
  228. unsigned int den;
  229. };
  230. struct snd_pcm_hw_constraint_ratnums {
  231. int nrats;
  232. struct snd_ratnum *rats;
  233. };
  234. struct snd_pcm_hw_constraint_ratdens {
  235. int nrats;
  236. struct snd_ratden *rats;
  237. };
  238. struct snd_pcm_hw_constraint_list {
  239. unsigned int count;
  240. const unsigned int *list;
  241. unsigned int mask;
  242. };
  243. struct snd_pcm_hwptr_log;
  244. struct snd_pcm_runtime {
  245. /* -- Status -- */
  246. struct snd_pcm_substream *trigger_master;
  247. struct timespec trigger_tstamp; /* trigger timestamp */
  248. int overrange;
  249. snd_pcm_uframes_t avail_max;
  250. snd_pcm_uframes_t hw_ptr_base; /* Position at buffer restart */
  251. snd_pcm_uframes_t hw_ptr_interrupt; /* Position at interrupt time */
  252. unsigned long hw_ptr_jiffies; /* Time when hw_ptr is updated */
  253. unsigned long hw_ptr_buffer_jiffies; /* buffer time in jiffies */
  254. snd_pcm_sframes_t delay; /* extra delay; typically FIFO size */
  255. u64 hw_ptr_wrap; /* offset for hw_ptr due to boundary wrap-around */
  256. /* -- HW params -- */
  257. snd_pcm_access_t access; /* access mode */
  258. snd_pcm_format_t format; /* SNDRV_PCM_FORMAT_* */
  259. snd_pcm_subformat_t subformat; /* subformat */
  260. unsigned int rate; /* rate in Hz */
  261. unsigned int channels; /* channels */
  262. snd_pcm_uframes_t period_size; /* period size */
  263. unsigned int periods; /* periods */
  264. snd_pcm_uframes_t buffer_size; /* buffer size */
  265. snd_pcm_uframes_t min_align; /* Min alignment for the format */
  266. size_t byte_align;
  267. unsigned int frame_bits;
  268. unsigned int sample_bits;
  269. unsigned int info;
  270. unsigned int rate_num;
  271. unsigned int rate_den;
  272. unsigned int no_period_wakeup: 1;
  273. /* -- SW params -- */
  274. int tstamp_mode; /* mmap timestamp is updated */
  275. unsigned int period_step;
  276. snd_pcm_uframes_t start_threshold;
  277. snd_pcm_uframes_t stop_threshold;
  278. snd_pcm_uframes_t silence_threshold; /* Silence filling happens when
  279. noise is nearest than this */
  280. snd_pcm_uframes_t silence_size; /* Silence filling size */
  281. snd_pcm_uframes_t boundary; /* pointers wrap point */
  282. snd_pcm_uframes_t silence_start; /* starting pointer to silence area */
  283. snd_pcm_uframes_t silence_filled; /* size filled with silence */
  284. union snd_pcm_sync_id sync; /* hardware synchronization ID */
  285. /* -- mmap -- */
  286. struct snd_pcm_mmap_status *status;
  287. struct snd_pcm_mmap_control *control;
  288. /* -- locking / scheduling -- */
  289. snd_pcm_uframes_t twake; /* do transfer (!poll) wakeup if non-zero */
  290. wait_queue_head_t sleep; /* poll sleep */
  291. wait_queue_head_t tsleep; /* transfer sleep */
  292. struct fasync_struct *fasync;
  293. /* -- private section -- */
  294. void *private_data;
  295. void (*private_free)(struct snd_pcm_runtime *runtime);
  296. /* -- hardware description -- */
  297. struct snd_pcm_hardware hw;
  298. struct snd_pcm_hw_constraints hw_constraints;
  299. /* -- interrupt callbacks -- */
  300. void (*transfer_ack_begin)(struct snd_pcm_substream *substream);
  301. void (*transfer_ack_end)(struct snd_pcm_substream *substream);
  302. /* -- timer -- */
  303. unsigned int timer_resolution; /* timer resolution */
  304. int tstamp_type; /* timestamp type */
  305. /* -- DMA -- */
  306. unsigned char *dma_area; /* DMA area */
  307. dma_addr_t dma_addr; /* physical bus address (not accessible from main CPU) */
  308. size_t dma_bytes; /* size of DMA area */
  309. struct snd_dma_buffer *dma_buffer_p; /* allocated buffer */
  310. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  311. /* -- OSS things -- */
  312. struct snd_pcm_oss_runtime oss;
  313. #endif
  314. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  315. struct snd_pcm_hwptr_log *hwptr_log;
  316. #endif
  317. };
  318. struct snd_pcm_group { /* keep linked substreams */
  319. spinlock_t lock;
  320. struct list_head substreams;
  321. int count;
  322. };
  323. struct pid;
  324. struct snd_pcm_substream {
  325. struct snd_pcm *pcm;
  326. struct snd_pcm_str *pstr;
  327. void *private_data; /* copied from pcm->private_data */
  328. int number;
  329. char name[32]; /* substream name */
  330. int stream; /* stream (direction) */
  331. struct pm_qos_request latency_pm_qos_req; /* pm_qos request */
  332. size_t buffer_bytes_max; /* limit ring buffer size */
  333. struct snd_dma_buffer dma_buffer;
  334. unsigned int dma_buf_id;
  335. size_t dma_max;
  336. /* -- hardware operations -- */
  337. struct snd_pcm_ops *ops;
  338. /* -- runtime information -- */
  339. struct snd_pcm_runtime *runtime;
  340. /* -- timer section -- */
  341. struct snd_timer *timer; /* timer */
  342. unsigned timer_running: 1; /* time is running */
  343. /* -- next substream -- */
  344. struct snd_pcm_substream *next;
  345. /* -- linked substreams -- */
  346. struct list_head link_list; /* linked list member */
  347. struct snd_pcm_group self_group; /* fake group for non linked substream (with substream lock inside) */
  348. struct snd_pcm_group *group; /* pointer to current group */
  349. /* -- assigned files -- */
  350. void *file;
  351. int ref_count;
  352. atomic_t mmap_count;
  353. unsigned int f_flags;
  354. void (*pcm_release)(struct snd_pcm_substream *);
  355. struct pid *pid;
  356. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  357. /* -- OSS things -- */
  358. struct snd_pcm_oss_substream oss;
  359. #endif
  360. #ifdef CONFIG_SND_VERBOSE_PROCFS
  361. struct snd_info_entry *proc_root;
  362. struct snd_info_entry *proc_info_entry;
  363. struct snd_info_entry *proc_hw_params_entry;
  364. struct snd_info_entry *proc_sw_params_entry;
  365. struct snd_info_entry *proc_status_entry;
  366. struct snd_info_entry *proc_prealloc_entry;
  367. struct snd_info_entry *proc_prealloc_max_entry;
  368. #endif
  369. /* misc flags */
  370. unsigned int hw_opened: 1;
  371. };
  372. #define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
  373. struct snd_pcm_str {
  374. int stream; /* stream (direction) */
  375. struct snd_pcm *pcm;
  376. /* -- substreams -- */
  377. unsigned int substream_count;
  378. unsigned int substream_opened;
  379. struct snd_pcm_substream *substream;
  380. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  381. /* -- OSS things -- */
  382. struct snd_pcm_oss_stream oss;
  383. #endif
  384. #ifdef CONFIG_SND_VERBOSE_PROCFS
  385. struct snd_info_entry *proc_root;
  386. struct snd_info_entry *proc_info_entry;
  387. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  388. unsigned int xrun_debug; /* 0 = disabled, 1 = verbose, 2 = stacktrace */
  389. struct snd_info_entry *proc_xrun_debug_entry;
  390. #endif
  391. #endif
  392. struct snd_kcontrol *chmap_kctl; /* channel-mapping controls */
  393. };
  394. struct snd_pcm {
  395. struct snd_card *card;
  396. struct list_head list;
  397. int device; /* device number */
  398. unsigned int info_flags;
  399. unsigned short dev_class;
  400. unsigned short dev_subclass;
  401. char id[64];
  402. char name[80];
  403. struct snd_pcm_str streams[2];
  404. struct mutex open_mutex;
  405. wait_queue_head_t open_wait;
  406. void *private_data;
  407. void (*private_free) (struct snd_pcm *pcm);
  408. struct device *dev; /* actual hw device this belongs to */
  409. bool internal; /* pcm is for internal use only */
  410. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  411. struct snd_pcm_oss oss;
  412. #endif
  413. };
  414. struct snd_pcm_notify {
  415. int (*n_register) (struct snd_pcm * pcm);
  416. int (*n_disconnect) (struct snd_pcm * pcm);
  417. int (*n_unregister) (struct snd_pcm * pcm);
  418. struct list_head list;
  419. };
  420. /*
  421. * Registering
  422. */
  423. extern const struct file_operations snd_pcm_f_ops[2];
  424. int snd_pcm_new(struct snd_card *card, const char *id, int device,
  425. int playback_count, int capture_count,
  426. struct snd_pcm **rpcm);
  427. int snd_pcm_new_internal(struct snd_card *card, const char *id, int device,
  428. int playback_count, int capture_count,
  429. struct snd_pcm **rpcm);
  430. int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count);
  431. int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree);
  432. /*
  433. * Native I/O
  434. */
  435. extern rwlock_t snd_pcm_link_rwlock;
  436. int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info);
  437. int snd_pcm_info_user(struct snd_pcm_substream *substream,
  438. struct snd_pcm_info __user *info);
  439. int snd_pcm_status(struct snd_pcm_substream *substream,
  440. struct snd_pcm_status *status);
  441. int snd_pcm_start(struct snd_pcm_substream *substream);
  442. int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t status);
  443. int snd_pcm_drain_done(struct snd_pcm_substream *substream);
  444. #ifdef CONFIG_PM
  445. int snd_pcm_suspend(struct snd_pcm_substream *substream);
  446. int snd_pcm_suspend_all(struct snd_pcm *pcm);
  447. #endif
  448. int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
  449. int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file,
  450. struct snd_pcm_substream **rsubstream);
  451. void snd_pcm_release_substream(struct snd_pcm_substream *substream);
  452. int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, struct file *file,
  453. struct snd_pcm_substream **rsubstream);
  454. void snd_pcm_detach_substream(struct snd_pcm_substream *substream);
  455. void snd_pcm_vma_notify_data(void *client, void *data);
  456. int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area);
  457. #ifdef CONFIG_SND_DEBUG
  458. void snd_pcm_debug_name(struct snd_pcm_substream *substream,
  459. char *name, size_t len);
  460. #else
  461. static inline void
  462. snd_pcm_debug_name(struct snd_pcm_substream *substream, char *buf, size_t size)
  463. {
  464. *buf = 0;
  465. }
  466. #endif
  467. /*
  468. * PCM library
  469. */
  470. static inline int snd_pcm_stream_linked(struct snd_pcm_substream *substream)
  471. {
  472. return substream->group != &substream->self_group;
  473. }
  474. static inline void snd_pcm_stream_lock(struct snd_pcm_substream *substream)
  475. {
  476. read_lock(&snd_pcm_link_rwlock);
  477. spin_lock(&substream->self_group.lock);
  478. }
  479. static inline void snd_pcm_stream_unlock(struct snd_pcm_substream *substream)
  480. {
  481. spin_unlock(&substream->self_group.lock);
  482. read_unlock(&snd_pcm_link_rwlock);
  483. }
  484. static inline void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
  485. {
  486. read_lock_irq(&snd_pcm_link_rwlock);
  487. spin_lock(&substream->self_group.lock);
  488. }
  489. static inline void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream)
  490. {
  491. spin_unlock(&substream->self_group.lock);
  492. read_unlock_irq(&snd_pcm_link_rwlock);
  493. }
  494. #define snd_pcm_stream_lock_irqsave(substream, flags) \
  495. do { \
  496. read_lock_irqsave(&snd_pcm_link_rwlock, (flags)); \
  497. spin_lock(&substream->self_group.lock); \
  498. } while (0)
  499. #define snd_pcm_stream_unlock_irqrestore(substream, flags) \
  500. do { \
  501. spin_unlock(&substream->self_group.lock); \
  502. read_unlock_irqrestore(&snd_pcm_link_rwlock, (flags)); \
  503. } while (0)
  504. #define snd_pcm_group_for_each_entry(s, substream) \
  505. list_for_each_entry(s, &substream->group->substreams, link_list)
  506. static inline int snd_pcm_running(struct snd_pcm_substream *substream)
  507. {
  508. return (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING ||
  509. (substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
  510. substream->stream == SNDRV_PCM_STREAM_PLAYBACK));
  511. }
  512. static inline ssize_t bytes_to_samples(struct snd_pcm_runtime *runtime, ssize_t size)
  513. {
  514. return size * 8 / runtime->sample_bits;
  515. }
  516. static inline snd_pcm_sframes_t bytes_to_frames(struct snd_pcm_runtime *runtime, ssize_t size)
  517. {
  518. return size * 8 / runtime->frame_bits;
  519. }
  520. static inline ssize_t samples_to_bytes(struct snd_pcm_runtime *runtime, ssize_t size)
  521. {
  522. return size * runtime->sample_bits / 8;
  523. }
  524. static inline ssize_t frames_to_bytes(struct snd_pcm_runtime *runtime, snd_pcm_sframes_t size)
  525. {
  526. return size * runtime->frame_bits / 8;
  527. }
  528. static inline int frame_aligned(struct snd_pcm_runtime *runtime, ssize_t bytes)
  529. {
  530. return bytes % runtime->byte_align == 0;
  531. }
  532. static inline size_t snd_pcm_lib_buffer_bytes(struct snd_pcm_substream *substream)
  533. {
  534. struct snd_pcm_runtime *runtime = substream->runtime;
  535. return frames_to_bytes(runtime, runtime->buffer_size);
  536. }
  537. static inline size_t snd_pcm_lib_period_bytes(struct snd_pcm_substream *substream)
  538. {
  539. struct snd_pcm_runtime *runtime = substream->runtime;
  540. return frames_to_bytes(runtime, runtime->period_size);
  541. }
  542. /*
  543. * result is: 0 ... (boundary - 1)
  544. */
  545. static inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *runtime)
  546. {
  547. snd_pcm_sframes_t avail = runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_ptr;
  548. if (avail < 0)
  549. avail += runtime->boundary;
  550. else if ((snd_pcm_uframes_t) avail >= runtime->boundary)
  551. avail -= runtime->boundary;
  552. return avail;
  553. }
  554. /*
  555. * result is: 0 ... (boundary - 1)
  556. */
  557. static inline snd_pcm_uframes_t snd_pcm_capture_avail(struct snd_pcm_runtime *runtime)
  558. {
  559. snd_pcm_sframes_t avail = runtime->status->hw_ptr - runtime->control->appl_ptr;
  560. if (avail < 0)
  561. avail += runtime->boundary;
  562. return avail;
  563. }
  564. static inline snd_pcm_sframes_t snd_pcm_playback_hw_avail(struct snd_pcm_runtime *runtime)
  565. {
  566. return runtime->buffer_size - snd_pcm_playback_avail(runtime);
  567. }
  568. static inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(struct snd_pcm_runtime *runtime)
  569. {
  570. return runtime->buffer_size - snd_pcm_capture_avail(runtime);
  571. }
  572. /**
  573. * snd_pcm_playback_ready - check whether the playback buffer is available
  574. * @substream: the pcm substream instance
  575. *
  576. * Checks whether enough free space is available on the playback buffer.
  577. *
  578. * Returns non-zero if available, or zero if not.
  579. */
  580. static inline int snd_pcm_playback_ready(struct snd_pcm_substream *substream)
  581. {
  582. struct snd_pcm_runtime *runtime = substream->runtime;
  583. return snd_pcm_playback_avail(runtime) >= runtime->control->avail_min;
  584. }
  585. /**
  586. * snd_pcm_capture_ready - check whether the capture buffer is available
  587. * @substream: the pcm substream instance
  588. *
  589. * Checks whether enough capture data is available on the capture buffer.
  590. *
  591. * Returns non-zero if available, or zero if not.
  592. */
  593. static inline int snd_pcm_capture_ready(struct snd_pcm_substream *substream)
  594. {
  595. struct snd_pcm_runtime *runtime = substream->runtime;
  596. return snd_pcm_capture_avail(runtime) >= runtime->control->avail_min;
  597. }
  598. /**
  599. * snd_pcm_playback_data - check whether any data exists on the playback buffer
  600. * @substream: the pcm substream instance
  601. *
  602. * Checks whether any data exists on the playback buffer. If stop_threshold
  603. * is bigger or equal to boundary, then this function returns always non-zero.
  604. *
  605. * Returns non-zero if exists, or zero if not.
  606. */
  607. static inline int snd_pcm_playback_data(struct snd_pcm_substream *substream)
  608. {
  609. struct snd_pcm_runtime *runtime = substream->runtime;
  610. if (runtime->stop_threshold >= runtime->boundary)
  611. return 1;
  612. return snd_pcm_playback_avail(runtime) < runtime->buffer_size;
  613. }
  614. /**
  615. * snd_pcm_playback_empty - check whether the playback buffer is empty
  616. * @substream: the pcm substream instance
  617. *
  618. * Checks whether the playback buffer is empty.
  619. *
  620. * Returns non-zero if empty, or zero if not.
  621. */
  622. static inline int snd_pcm_playback_empty(struct snd_pcm_substream *substream)
  623. {
  624. struct snd_pcm_runtime *runtime = substream->runtime;
  625. return snd_pcm_playback_avail(runtime) >= runtime->buffer_size;
  626. }
  627. /**
  628. * snd_pcm_capture_empty - check whether the capture buffer is empty
  629. * @substream: the pcm substream instance
  630. *
  631. * Checks whether the capture buffer is empty.
  632. *
  633. * Returns non-zero if empty, or zero if not.
  634. */
  635. static inline int snd_pcm_capture_empty(struct snd_pcm_substream *substream)
  636. {
  637. struct snd_pcm_runtime *runtime = substream->runtime;
  638. return snd_pcm_capture_avail(runtime) == 0;
  639. }
  640. static inline void snd_pcm_trigger_done(struct snd_pcm_substream *substream,
  641. struct snd_pcm_substream *master)
  642. {
  643. substream->runtime->trigger_master = master;
  644. }
  645. static inline int hw_is_mask(int var)
  646. {
  647. return var >= SNDRV_PCM_HW_PARAM_FIRST_MASK &&
  648. var <= SNDRV_PCM_HW_PARAM_LAST_MASK;
  649. }
  650. static inline int hw_is_interval(int var)
  651. {
  652. return var >= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL &&
  653. var <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL;
  654. }
  655. static inline struct snd_mask *hw_param_mask(struct snd_pcm_hw_params *params,
  656. snd_pcm_hw_param_t var)
  657. {
  658. return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  659. }
  660. static inline struct snd_interval *hw_param_interval(struct snd_pcm_hw_params *params,
  661. snd_pcm_hw_param_t var)
  662. {
  663. return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  664. }
  665. static inline const struct snd_mask *hw_param_mask_c(const struct snd_pcm_hw_params *params,
  666. snd_pcm_hw_param_t var)
  667. {
  668. return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  669. }
  670. static inline const struct snd_interval *hw_param_interval_c(const struct snd_pcm_hw_params *params,
  671. snd_pcm_hw_param_t var)
  672. {
  673. return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  674. }
  675. #define params_channels(p) \
  676. (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_CHANNELS)->min)
  677. #define params_rate(p) \
  678. (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_RATE)->min)
  679. #define params_period_size(p) \
  680. (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min)
  681. #define params_periods(p) \
  682. (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_PERIODS)->min)
  683. #define params_buffer_size(p) \
  684. (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min)
  685. #define params_buffer_bytes(p) \
  686. (hw_param_interval_c((p), SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min)
  687. int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v);
  688. void snd_interval_mul(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c);
  689. void snd_interval_div(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c);
  690. void snd_interval_muldivk(const struct snd_interval *a, const struct snd_interval *b,
  691. unsigned int k, struct snd_interval *c);
  692. void snd_interval_mulkdiv(const struct snd_interval *a, unsigned int k,
  693. const struct snd_interval *b, struct snd_interval *c);
  694. int snd_interval_list(struct snd_interval *i, unsigned int count,
  695. const unsigned int *list, unsigned int mask);
  696. int snd_interval_ratnum(struct snd_interval *i,
  697. unsigned int rats_count, struct snd_ratnum *rats,
  698. unsigned int *nump, unsigned int *denp);
  699. void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params);
  700. void _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var);
  701. int snd_pcm_hw_params_choose(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
  702. int snd_pcm_hw_refine(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
  703. int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream);
  704. int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream);
  705. int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  706. u_int32_t mask);
  707. int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  708. u_int64_t mask);
  709. int snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  710. unsigned int min, unsigned int max);
  711. int snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var);
  712. int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime,
  713. unsigned int cond,
  714. snd_pcm_hw_param_t var,
  715. const struct snd_pcm_hw_constraint_list *l);
  716. int snd_pcm_hw_constraint_ratnums(struct snd_pcm_runtime *runtime,
  717. unsigned int cond,
  718. snd_pcm_hw_param_t var,
  719. struct snd_pcm_hw_constraint_ratnums *r);
  720. int snd_pcm_hw_constraint_ratdens(struct snd_pcm_runtime *runtime,
  721. unsigned int cond,
  722. snd_pcm_hw_param_t var,
  723. struct snd_pcm_hw_constraint_ratdens *r);
  724. int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime,
  725. unsigned int cond,
  726. unsigned int width,
  727. unsigned int msbits);
  728. int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
  729. unsigned int cond,
  730. snd_pcm_hw_param_t var,
  731. unsigned long step);
  732. int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
  733. unsigned int cond,
  734. snd_pcm_hw_param_t var);
  735. int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
  736. unsigned int base_rate);
  737. int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime,
  738. unsigned int cond,
  739. int var,
  740. snd_pcm_hw_rule_func_t func, void *private,
  741. int dep, ...);
  742. int snd_pcm_format_signed(snd_pcm_format_t format);
  743. int snd_pcm_format_unsigned(snd_pcm_format_t format);
  744. int snd_pcm_format_linear(snd_pcm_format_t format);
  745. int snd_pcm_format_little_endian(snd_pcm_format_t format);
  746. int snd_pcm_format_big_endian(snd_pcm_format_t format);
  747. #if 0 /* just for DocBook */
  748. /**
  749. * snd_pcm_format_cpu_endian - Check the PCM format is CPU-endian
  750. * @format: the format to check
  751. *
  752. * Returns 1 if the given PCM format is CPU-endian, 0 if
  753. * opposite, or a negative error code if endian not specified.
  754. */
  755. int snd_pcm_format_cpu_endian(snd_pcm_format_t format);
  756. #endif /* DocBook */
  757. #ifdef SNDRV_LITTLE_ENDIAN
  758. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_little_endian(format)
  759. #else
  760. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_big_endian(format)
  761. #endif
  762. int snd_pcm_format_width(snd_pcm_format_t format); /* in bits */
  763. int snd_pcm_format_physical_width(snd_pcm_format_t format); /* in bits */
  764. ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
  765. const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format);
  766. int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
  767. snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsigned, int big_endian);
  768. void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, struct snd_pcm_ops *ops);
  769. void snd_pcm_set_sync(struct snd_pcm_substream *substream);
  770. int snd_pcm_lib_interleave_len(struct snd_pcm_substream *substream);
  771. int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  772. unsigned int cmd, void *arg);
  773. int snd_pcm_update_state(struct snd_pcm_substream *substream,
  774. struct snd_pcm_runtime *runtime);
  775. int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream);
  776. int snd_pcm_playback_xrun_check(struct snd_pcm_substream *substream);
  777. int snd_pcm_capture_xrun_check(struct snd_pcm_substream *substream);
  778. int snd_pcm_playback_xrun_asap(struct snd_pcm_substream *substream);
  779. int snd_pcm_capture_xrun_asap(struct snd_pcm_substream *substream);
  780. void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_uframes_t new_hw_ptr);
  781. void snd_pcm_period_elapsed(struct snd_pcm_substream *substream);
  782. snd_pcm_sframes_t snd_pcm_lib_write(struct snd_pcm_substream *substream,
  783. const void __user *buf,
  784. snd_pcm_uframes_t frames);
  785. snd_pcm_sframes_t snd_pcm_lib_read(struct snd_pcm_substream *substream,
  786. void __user *buf, snd_pcm_uframes_t frames);
  787. snd_pcm_sframes_t snd_pcm_lib_writev(struct snd_pcm_substream *substream,
  788. void __user **bufs, snd_pcm_uframes_t frames);
  789. snd_pcm_sframes_t snd_pcm_lib_readv(struct snd_pcm_substream *substream,
  790. void __user **bufs, snd_pcm_uframes_t frames);
  791. extern const struct snd_pcm_hw_constraint_list snd_pcm_known_rates;
  792. int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime);
  793. unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate);
  794. unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit);
  795. static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substream,
  796. struct snd_dma_buffer *bufp)
  797. {
  798. struct snd_pcm_runtime *runtime = substream->runtime;
  799. if (bufp) {
  800. runtime->dma_buffer_p = bufp;
  801. runtime->dma_area = bufp->area;
  802. runtime->dma_addr = bufp->addr;
  803. runtime->dma_bytes = bufp->bytes;
  804. } else {
  805. runtime->dma_buffer_p = NULL;
  806. runtime->dma_area = NULL;
  807. runtime->dma_addr = 0;
  808. runtime->dma_bytes = 0;
  809. }
  810. }
  811. /*
  812. * Timer interface
  813. */
  814. void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream);
  815. void snd_pcm_timer_init(struct snd_pcm_substream *substream);
  816. void snd_pcm_timer_done(struct snd_pcm_substream *substream);
  817. static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
  818. struct timespec *tv)
  819. {
  820. if (runtime->tstamp_type == SNDRV_PCM_TSTAMP_TYPE_MONOTONIC)
  821. do_posix_clock_monotonic_gettime(tv);
  822. else
  823. getnstimeofday(tv);
  824. }
  825. /*
  826. * Memory
  827. */
  828. int snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream);
  829. int snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm);
  830. int snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
  831. int type, struct device *data,
  832. size_t size, size_t max);
  833. int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
  834. int type, void *data,
  835. size_t size, size_t max);
  836. int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size);
  837. int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream);
  838. int _snd_pcm_lib_alloc_vmalloc_buffer(struct snd_pcm_substream *substream,
  839. size_t size, gfp_t gfp_flags);
  840. int snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream);
  841. struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream,
  842. unsigned long offset);
  843. #if 0 /* for kernel-doc */
  844. /**
  845. * snd_pcm_lib_alloc_vmalloc_buffer - allocate virtual DMA buffer
  846. * @substream: the substream to allocate the buffer to
  847. * @size: the requested buffer size, in bytes
  848. *
  849. * Allocates the PCM substream buffer using vmalloc(), i.e., the memory is
  850. * contiguous in kernel virtual space, but not in physical memory. Use this
  851. * if the buffer is accessed by kernel code but not by device DMA.
  852. *
  853. * Returns 1 if the buffer was changed, 0 if not changed, or a negative error
  854. * code.
  855. */
  856. static int snd_pcm_lib_alloc_vmalloc_buffer
  857. (struct snd_pcm_substream *substream, size_t size);
  858. /**
  859. * snd_pcm_lib_alloc_vmalloc_32_buffer - allocate 32-bit-addressable buffer
  860. * @substream: the substream to allocate the buffer to
  861. * @size: the requested buffer size, in bytes
  862. *
  863. * This function works like snd_pcm_lib_alloc_vmalloc_buffer(), but uses
  864. * vmalloc_32(), i.e., the pages are allocated from 32-bit-addressable memory.
  865. */
  866. static int snd_pcm_lib_alloc_vmalloc_32_buffer
  867. (struct snd_pcm_substream *substream, size_t size);
  868. #endif
  869. #define snd_pcm_lib_alloc_vmalloc_buffer(subs, size) \
  870. _snd_pcm_lib_alloc_vmalloc_buffer \
  871. (subs, size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO)
  872. #define snd_pcm_lib_alloc_vmalloc_32_buffer(subs, size) \
  873. _snd_pcm_lib_alloc_vmalloc_buffer \
  874. (subs, size, GFP_KERNEL | GFP_DMA32 | __GFP_ZERO)
  875. #define snd_pcm_get_dma_buf(substream) ((substream)->runtime->dma_buffer_p)
  876. #ifdef CONFIG_SND_DMA_SGBUF
  877. /*
  878. * SG-buffer handling
  879. */
  880. #define snd_pcm_substream_sgbuf(substream) \
  881. snd_pcm_get_dma_buf(substream)->private_data
  882. struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream,
  883. unsigned long offset);
  884. #else /* !SND_DMA_SGBUF */
  885. /*
  886. * fake using a continuous buffer
  887. */
  888. #define snd_pcm_sgbuf_ops_page NULL
  889. #endif /* SND_DMA_SGBUF */
  890. static inline dma_addr_t
  891. snd_pcm_sgbuf_get_addr(struct snd_pcm_substream *substream, unsigned int ofs)
  892. {
  893. return snd_sgbuf_get_addr(snd_pcm_get_dma_buf(substream), ofs);
  894. }
  895. static inline void *
  896. snd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs)
  897. {
  898. return snd_sgbuf_get_ptr(snd_pcm_get_dma_buf(substream), ofs);
  899. }
  900. static inline unsigned int
  901. snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream,
  902. unsigned int ofs, unsigned int size)
  903. {
  904. return snd_sgbuf_get_chunk_size(snd_pcm_get_dma_buf(substream), ofs, size);
  905. }
  906. /* handle mmap counter - PCM mmap callback should handle this counter properly */
  907. static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area)
  908. {
  909. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  910. atomic_inc(&substream->mmap_count);
  911. }
  912. static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area)
  913. {
  914. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  915. atomic_dec(&substream->mmap_count);
  916. }
  917. int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
  918. struct vm_area_struct *area);
  919. /* mmap for io-memory area */
  920. #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
  921. #define SNDRV_PCM_INFO_MMAP_IOMEM SNDRV_PCM_INFO_MMAP
  922. int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, struct vm_area_struct *area);
  923. #else
  924. #define SNDRV_PCM_INFO_MMAP_IOMEM 0
  925. #define snd_pcm_lib_mmap_iomem NULL
  926. #endif
  927. #define snd_pcm_lib_mmap_vmalloc NULL
  928. static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
  929. {
  930. *max = dma < 4 ? 64 * 1024 : 128 * 1024;
  931. }
  932. /*
  933. * Misc
  934. */
  935. #define SNDRV_PCM_DEFAULT_CON_SPDIF (IEC958_AES0_CON_EMPHASIS_NONE|\
  936. (IEC958_AES1_CON_ORIGINAL<<8)|\
  937. (IEC958_AES1_CON_PCM_CODER<<8)|\
  938. (IEC958_AES3_CON_FS_48000<<24))
  939. #define PCM_RUNTIME_CHECK(sub) snd_BUG_ON(!(sub) || !(sub)->runtime)
  940. const char *snd_pcm_format_name(snd_pcm_format_t format);
  941. /**
  942. * snd_pcm_stream_str - Get a string naming the direction of a stream
  943. * @substream: the pcm substream instance
  944. */
  945. static inline const char *snd_pcm_stream_str(struct snd_pcm_substream *substream)
  946. {
  947. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  948. return "Playback";
  949. else
  950. return "Capture";
  951. }
  952. /*
  953. * PCM channel-mapping control API
  954. */
  955. /* array element of channel maps */
  956. struct snd_pcm_chmap_elem {
  957. unsigned char channels;
  958. unsigned char map[15];
  959. };
  960. /* channel map information; retrieved via snd_kcontrol_chip() */
  961. struct snd_pcm_chmap {
  962. struct snd_pcm *pcm; /* assigned PCM instance */
  963. int stream; /* PLAYBACK or CAPTURE */
  964. struct snd_kcontrol *kctl;
  965. const struct snd_pcm_chmap_elem *chmap;
  966. unsigned int max_channels;
  967. unsigned int channel_mask; /* optional: active channels bitmask */
  968. void *private_data; /* optional: private data pointer */
  969. };
  970. /* get the PCM substream assigned to the given chmap info */
  971. static inline struct snd_pcm_substream *
  972. snd_pcm_chmap_substream(struct snd_pcm_chmap *info, unsigned int idx)
  973. {
  974. struct snd_pcm_substream *s;
  975. for (s = info->pcm->streams[info->stream].substream; s; s = s->next)
  976. if (s->number == idx)
  977. return s;
  978. return NULL;
  979. }
  980. /* ALSA-standard channel maps (RL/RR prior to C/LFE) */
  981. extern const struct snd_pcm_chmap_elem snd_pcm_std_chmaps[];
  982. /* Other world's standard channel maps (C/LFE prior to RL/RR) */
  983. extern const struct snd_pcm_chmap_elem snd_pcm_alt_chmaps[];
  984. /* bit masks to be passed to snd_pcm_chmap.channel_mask field */
  985. #define SND_PCM_CHMAP_MASK_24 ((1U << 2) | (1U << 4))
  986. #define SND_PCM_CHMAP_MASK_246 (SND_PCM_CHMAP_MASK_24 | (1U << 6))
  987. #define SND_PCM_CHMAP_MASK_2468 (SND_PCM_CHMAP_MASK_246 | (1U << 8))
  988. int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
  989. const struct snd_pcm_chmap_elem *chmap,
  990. int max_channels,
  991. unsigned long private_value,
  992. struct snd_pcm_chmap **info_ret);
  993. #endif /* __SOUND_PCM_H */