pcm.h 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054
  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_params.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 "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 (*copy)(struct snd_pcm_substream *substream, int channel,
  67. snd_pcm_uframes_t pos,
  68. void __user *buf, snd_pcm_uframes_t count);
  69. int (*silence)(struct snd_pcm_substream *substream, int channel,
  70. snd_pcm_uframes_t pos, snd_pcm_uframes_t count);
  71. struct page *(*page)(struct snd_pcm_substream *substream,
  72. unsigned long offset);
  73. int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
  74. int (*ack)(struct snd_pcm_substream *substream);
  75. };
  76. /*
  77. *
  78. */
  79. #if defined(CONFIG_SND_DYNAMIC_MINORS)
  80. #define SNDRV_PCM_DEVICES (SNDRV_OS_MINORS-2)
  81. #else
  82. #define SNDRV_PCM_DEVICES 8
  83. #endif
  84. #define SNDRV_PCM_IOCTL1_FALSE ((void *)0)
  85. #define SNDRV_PCM_IOCTL1_TRUE ((void *)1)
  86. #define SNDRV_PCM_IOCTL1_RESET 0
  87. #define SNDRV_PCM_IOCTL1_INFO 1
  88. #define SNDRV_PCM_IOCTL1_CHANNEL_INFO 2
  89. #define SNDRV_PCM_IOCTL1_GSTATE 3
  90. #define SNDRV_PCM_IOCTL1_FIFO_SIZE 4
  91. #define SNDRV_PCM_TRIGGER_STOP 0
  92. #define SNDRV_PCM_TRIGGER_START 1
  93. #define SNDRV_PCM_TRIGGER_PAUSE_PUSH 3
  94. #define SNDRV_PCM_TRIGGER_PAUSE_RELEASE 4
  95. #define SNDRV_PCM_TRIGGER_SUSPEND 5
  96. #define SNDRV_PCM_TRIGGER_RESUME 6
  97. #define SNDRV_PCM_POS_XRUN ((snd_pcm_uframes_t)-1)
  98. /* If you change this don't forget to change rates[] table in pcm_native.c */
  99. #define SNDRV_PCM_RATE_5512 (1<<0) /* 5512Hz */
  100. #define SNDRV_PCM_RATE_8000 (1<<1) /* 8000Hz */
  101. #define SNDRV_PCM_RATE_11025 (1<<2) /* 11025Hz */
  102. #define SNDRV_PCM_RATE_16000 (1<<3) /* 16000Hz */
  103. #define SNDRV_PCM_RATE_22050 (1<<4) /* 22050Hz */
  104. #define SNDRV_PCM_RATE_32000 (1<<5) /* 32000Hz */
  105. #define SNDRV_PCM_RATE_44100 (1<<6) /* 44100Hz */
  106. #define SNDRV_PCM_RATE_48000 (1<<7) /* 48000Hz */
  107. #define SNDRV_PCM_RATE_64000 (1<<8) /* 64000Hz */
  108. #define SNDRV_PCM_RATE_88200 (1<<9) /* 88200Hz */
  109. #define SNDRV_PCM_RATE_96000 (1<<10) /* 96000Hz */
  110. #define SNDRV_PCM_RATE_176400 (1<<11) /* 176400Hz */
  111. #define SNDRV_PCM_RATE_192000 (1<<12) /* 192000Hz */
  112. #define SNDRV_PCM_RATE_CONTINUOUS (1<<30) /* continuous range */
  113. #define SNDRV_PCM_RATE_KNOT (1<<31) /* supports more non-continuos rates */
  114. #define SNDRV_PCM_RATE_8000_44100 (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_11025|\
  115. SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_22050|\
  116. SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100)
  117. #define SNDRV_PCM_RATE_8000_48000 (SNDRV_PCM_RATE_8000_44100|SNDRV_PCM_RATE_48000)
  118. #define SNDRV_PCM_RATE_8000_96000 (SNDRV_PCM_RATE_8000_48000|SNDRV_PCM_RATE_64000|\
  119. SNDRV_PCM_RATE_88200|SNDRV_PCM_RATE_96000)
  120. #define SNDRV_PCM_RATE_8000_192000 (SNDRV_PCM_RATE_8000_96000|SNDRV_PCM_RATE_176400|\
  121. SNDRV_PCM_RATE_192000)
  122. #define SNDRV_PCM_FMTBIT_S8 (1ULL << SNDRV_PCM_FORMAT_S8)
  123. #define SNDRV_PCM_FMTBIT_U8 (1ULL << SNDRV_PCM_FORMAT_U8)
  124. #define SNDRV_PCM_FMTBIT_S16_LE (1ULL << SNDRV_PCM_FORMAT_S16_LE)
  125. #define SNDRV_PCM_FMTBIT_S16_BE (1ULL << SNDRV_PCM_FORMAT_S16_BE)
  126. #define SNDRV_PCM_FMTBIT_U16_LE (1ULL << SNDRV_PCM_FORMAT_U16_LE)
  127. #define SNDRV_PCM_FMTBIT_U16_BE (1ULL << SNDRV_PCM_FORMAT_U16_BE)
  128. #define SNDRV_PCM_FMTBIT_S24_LE (1ULL << SNDRV_PCM_FORMAT_S24_LE)
  129. #define SNDRV_PCM_FMTBIT_S24_BE (1ULL << SNDRV_PCM_FORMAT_S24_BE)
  130. #define SNDRV_PCM_FMTBIT_U24_LE (1ULL << SNDRV_PCM_FORMAT_U24_LE)
  131. #define SNDRV_PCM_FMTBIT_U24_BE (1ULL << SNDRV_PCM_FORMAT_U24_BE)
  132. #define SNDRV_PCM_FMTBIT_S32_LE (1ULL << SNDRV_PCM_FORMAT_S32_LE)
  133. #define SNDRV_PCM_FMTBIT_S32_BE (1ULL << SNDRV_PCM_FORMAT_S32_BE)
  134. #define SNDRV_PCM_FMTBIT_U32_LE (1ULL << SNDRV_PCM_FORMAT_U32_LE)
  135. #define SNDRV_PCM_FMTBIT_U32_BE (1ULL << SNDRV_PCM_FORMAT_U32_BE)
  136. #define SNDRV_PCM_FMTBIT_FLOAT_LE (1ULL << SNDRV_PCM_FORMAT_FLOAT_LE)
  137. #define SNDRV_PCM_FMTBIT_FLOAT_BE (1ULL << SNDRV_PCM_FORMAT_FLOAT_BE)
  138. #define SNDRV_PCM_FMTBIT_FLOAT64_LE (1ULL << SNDRV_PCM_FORMAT_FLOAT64_LE)
  139. #define SNDRV_PCM_FMTBIT_FLOAT64_BE (1ULL << SNDRV_PCM_FORMAT_FLOAT64_BE)
  140. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE (1ULL << SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE)
  141. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE (1ULL << SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE)
  142. #define SNDRV_PCM_FMTBIT_MU_LAW (1ULL << SNDRV_PCM_FORMAT_MU_LAW)
  143. #define SNDRV_PCM_FMTBIT_A_LAW (1ULL << SNDRV_PCM_FORMAT_A_LAW)
  144. #define SNDRV_PCM_FMTBIT_IMA_ADPCM (1ULL << SNDRV_PCM_FORMAT_IMA_ADPCM)
  145. #define SNDRV_PCM_FMTBIT_MPEG (1ULL << SNDRV_PCM_FORMAT_MPEG)
  146. #define SNDRV_PCM_FMTBIT_GSM (1ULL << SNDRV_PCM_FORMAT_GSM)
  147. #define SNDRV_PCM_FMTBIT_SPECIAL (1ULL << SNDRV_PCM_FORMAT_SPECIAL)
  148. #define SNDRV_PCM_FMTBIT_S24_3LE (1ULL << SNDRV_PCM_FORMAT_S24_3LE)
  149. #define SNDRV_PCM_FMTBIT_U24_3LE (1ULL << SNDRV_PCM_FORMAT_U24_3LE)
  150. #define SNDRV_PCM_FMTBIT_S24_3BE (1ULL << SNDRV_PCM_FORMAT_S24_3BE)
  151. #define SNDRV_PCM_FMTBIT_U24_3BE (1ULL << SNDRV_PCM_FORMAT_U24_3BE)
  152. #define SNDRV_PCM_FMTBIT_S20_3LE (1ULL << SNDRV_PCM_FORMAT_S20_3LE)
  153. #define SNDRV_PCM_FMTBIT_U20_3LE (1ULL << SNDRV_PCM_FORMAT_U20_3LE)
  154. #define SNDRV_PCM_FMTBIT_S20_3BE (1ULL << SNDRV_PCM_FORMAT_S20_3BE)
  155. #define SNDRV_PCM_FMTBIT_U20_3BE (1ULL << SNDRV_PCM_FORMAT_U20_3BE)
  156. #define SNDRV_PCM_FMTBIT_S18_3LE (1ULL << SNDRV_PCM_FORMAT_S18_3LE)
  157. #define SNDRV_PCM_FMTBIT_U18_3LE (1ULL << SNDRV_PCM_FORMAT_U18_3LE)
  158. #define SNDRV_PCM_FMTBIT_S18_3BE (1ULL << SNDRV_PCM_FORMAT_S18_3BE)
  159. #define SNDRV_PCM_FMTBIT_U18_3BE (1ULL << SNDRV_PCM_FORMAT_U18_3BE)
  160. #define SNDRV_PCM_FMTBIT_G723_24 (1ULL << SNDRV_PCM_FORMAT_G723_24)
  161. #define SNDRV_PCM_FMTBIT_G723_24_1B (1ULL << SNDRV_PCM_FORMAT_G723_24_1B)
  162. #define SNDRV_PCM_FMTBIT_G723_40 (1ULL << SNDRV_PCM_FORMAT_G723_40)
  163. #define SNDRV_PCM_FMTBIT_G723_40_1B (1ULL << SNDRV_PCM_FORMAT_G723_40_1B)
  164. #ifdef SNDRV_LITTLE_ENDIAN
  165. #define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_LE
  166. #define SNDRV_PCM_FMTBIT_U16 SNDRV_PCM_FMTBIT_U16_LE
  167. #define SNDRV_PCM_FMTBIT_S24 SNDRV_PCM_FMTBIT_S24_LE
  168. #define SNDRV_PCM_FMTBIT_U24 SNDRV_PCM_FMTBIT_U24_LE
  169. #define SNDRV_PCM_FMTBIT_S32 SNDRV_PCM_FMTBIT_S32_LE
  170. #define SNDRV_PCM_FMTBIT_U32 SNDRV_PCM_FMTBIT_U32_LE
  171. #define SNDRV_PCM_FMTBIT_FLOAT SNDRV_PCM_FMTBIT_FLOAT_LE
  172. #define SNDRV_PCM_FMTBIT_FLOAT64 SNDRV_PCM_FMTBIT_FLOAT64_LE
  173. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
  174. #endif
  175. #ifdef SNDRV_BIG_ENDIAN
  176. #define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_BE
  177. #define SNDRV_PCM_FMTBIT_U16 SNDRV_PCM_FMTBIT_U16_BE
  178. #define SNDRV_PCM_FMTBIT_S24 SNDRV_PCM_FMTBIT_S24_BE
  179. #define SNDRV_PCM_FMTBIT_U24 SNDRV_PCM_FMTBIT_U24_BE
  180. #define SNDRV_PCM_FMTBIT_S32 SNDRV_PCM_FMTBIT_S32_BE
  181. #define SNDRV_PCM_FMTBIT_U32 SNDRV_PCM_FMTBIT_U32_BE
  182. #define SNDRV_PCM_FMTBIT_FLOAT SNDRV_PCM_FMTBIT_FLOAT_BE
  183. #define SNDRV_PCM_FMTBIT_FLOAT64 SNDRV_PCM_FMTBIT_FLOAT64_BE
  184. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
  185. #endif
  186. struct snd_pcm_file {
  187. struct snd_pcm_substream *substream;
  188. int no_compat_mmap;
  189. };
  190. struct snd_pcm_hw_rule;
  191. typedef int (*snd_pcm_hw_rule_func_t)(struct snd_pcm_hw_params *params,
  192. struct snd_pcm_hw_rule *rule);
  193. struct snd_pcm_hw_rule {
  194. unsigned int cond;
  195. snd_pcm_hw_rule_func_t func;
  196. int var;
  197. int deps[4];
  198. void *private;
  199. };
  200. struct snd_pcm_hw_constraints {
  201. struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK -
  202. SNDRV_PCM_HW_PARAM_FIRST_MASK + 1];
  203. struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL -
  204. SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1];
  205. unsigned int rules_num;
  206. unsigned int rules_all;
  207. struct snd_pcm_hw_rule *rules;
  208. };
  209. static inline struct snd_mask *constrs_mask(struct snd_pcm_hw_constraints *constrs,
  210. snd_pcm_hw_param_t var)
  211. {
  212. return &constrs->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  213. }
  214. static inline struct snd_interval *constrs_interval(struct snd_pcm_hw_constraints *constrs,
  215. snd_pcm_hw_param_t var)
  216. {
  217. return &constrs->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  218. }
  219. struct snd_ratnum {
  220. unsigned int num;
  221. unsigned int den_min, den_max, den_step;
  222. };
  223. struct snd_ratden {
  224. unsigned int num_min, num_max, num_step;
  225. unsigned int den;
  226. };
  227. struct snd_pcm_hw_constraint_ratnums {
  228. int nrats;
  229. struct snd_ratnum *rats;
  230. };
  231. struct snd_pcm_hw_constraint_ratdens {
  232. int nrats;
  233. struct snd_ratden *rats;
  234. };
  235. struct snd_pcm_hw_constraint_list {
  236. unsigned int count;
  237. unsigned int *list;
  238. unsigned int mask;
  239. };
  240. struct snd_pcm_hwptr_log;
  241. struct snd_pcm_runtime {
  242. /* -- Status -- */
  243. struct snd_pcm_substream *trigger_master;
  244. struct timespec trigger_tstamp; /* trigger timestamp */
  245. int overrange;
  246. snd_pcm_uframes_t avail_max;
  247. snd_pcm_uframes_t hw_ptr_base; /* Position at buffer restart */
  248. snd_pcm_uframes_t hw_ptr_interrupt; /* Position at interrupt time */
  249. unsigned long hw_ptr_jiffies; /* Time when hw_ptr is updated */
  250. unsigned long hw_ptr_buffer_jiffies; /* buffer time in jiffies */
  251. snd_pcm_sframes_t delay; /* extra delay; typically FIFO size */
  252. /* -- HW params -- */
  253. snd_pcm_access_t access; /* access mode */
  254. snd_pcm_format_t format; /* SNDRV_PCM_FORMAT_* */
  255. snd_pcm_subformat_t subformat; /* subformat */
  256. unsigned int rate; /* rate in Hz */
  257. unsigned int channels; /* channels */
  258. snd_pcm_uframes_t period_size; /* period size */
  259. unsigned int periods; /* periods */
  260. snd_pcm_uframes_t buffer_size; /* buffer size */
  261. snd_pcm_uframes_t min_align; /* Min alignment for the format */
  262. size_t byte_align;
  263. unsigned int frame_bits;
  264. unsigned int sample_bits;
  265. unsigned int info;
  266. unsigned int rate_num;
  267. unsigned int rate_den;
  268. /* -- SW params -- */
  269. int tstamp_mode; /* mmap timestamp is updated */
  270. unsigned int period_step;
  271. snd_pcm_uframes_t start_threshold;
  272. snd_pcm_uframes_t stop_threshold;
  273. snd_pcm_uframes_t silence_threshold; /* Silence filling happens when
  274. noise is nearest than this */
  275. snd_pcm_uframes_t silence_size; /* Silence filling size */
  276. snd_pcm_uframes_t boundary; /* pointers wrap point */
  277. snd_pcm_uframes_t silence_start; /* starting pointer to silence area */
  278. snd_pcm_uframes_t silence_filled; /* size filled with silence */
  279. union snd_pcm_sync_id sync; /* hardware synchronization ID */
  280. /* -- mmap -- */
  281. struct snd_pcm_mmap_status *status;
  282. struct snd_pcm_mmap_control *control;
  283. /* -- locking / scheduling -- */
  284. snd_pcm_uframes_t twake; /* do transfer (!poll) wakeup if non-zero */
  285. wait_queue_head_t sleep; /* poll sleep */
  286. wait_queue_head_t tsleep; /* transfer sleep */
  287. struct fasync_struct *fasync;
  288. /* -- private section -- */
  289. void *private_data;
  290. void (*private_free)(struct snd_pcm_runtime *runtime);
  291. /* -- hardware description -- */
  292. struct snd_pcm_hardware hw;
  293. struct snd_pcm_hw_constraints hw_constraints;
  294. /* -- interrupt callbacks -- */
  295. void (*transfer_ack_begin)(struct snd_pcm_substream *substream);
  296. void (*transfer_ack_end)(struct snd_pcm_substream *substream);
  297. /* -- timer -- */
  298. unsigned int timer_resolution; /* timer resolution */
  299. int tstamp_type; /* timestamp type */
  300. /* -- DMA -- */
  301. unsigned char *dma_area; /* DMA area */
  302. dma_addr_t dma_addr; /* physical bus address (not accessible from main CPU) */
  303. size_t dma_bytes; /* size of DMA area */
  304. struct snd_dma_buffer *dma_buffer_p; /* allocated buffer */
  305. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  306. /* -- OSS things -- */
  307. struct snd_pcm_oss_runtime oss;
  308. #endif
  309. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  310. struct snd_pcm_hwptr_log *hwptr_log;
  311. #endif
  312. };
  313. struct snd_pcm_group { /* keep linked substreams */
  314. spinlock_t lock;
  315. struct list_head substreams;
  316. int count;
  317. };
  318. struct pid;
  319. struct snd_pcm_substream {
  320. struct snd_pcm *pcm;
  321. struct snd_pcm_str *pstr;
  322. void *private_data; /* copied from pcm->private_data */
  323. int number;
  324. char name[32]; /* substream name */
  325. int stream; /* stream (direction) */
  326. struct pm_qos_request_list latency_pm_qos_req; /* pm_qos request */
  327. size_t buffer_bytes_max; /* limit ring buffer size */
  328. struct snd_dma_buffer dma_buffer;
  329. unsigned int dma_buf_id;
  330. size_t dma_max;
  331. /* -- hardware operations -- */
  332. struct snd_pcm_ops *ops;
  333. /* -- runtime information -- */
  334. struct snd_pcm_runtime *runtime;
  335. /* -- timer section -- */
  336. struct snd_timer *timer; /* timer */
  337. unsigned timer_running: 1; /* time is running */
  338. /* -- next substream -- */
  339. struct snd_pcm_substream *next;
  340. /* -- linked substreams -- */
  341. struct list_head link_list; /* linked list member */
  342. struct snd_pcm_group self_group; /* fake group for non linked substream (with substream lock inside) */
  343. struct snd_pcm_group *group; /* pointer to current group */
  344. /* -- assigned files -- */
  345. void *file;
  346. int ref_count;
  347. atomic_t mmap_count;
  348. unsigned int f_flags;
  349. void (*pcm_release)(struct snd_pcm_substream *);
  350. struct pid *pid;
  351. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  352. /* -- OSS things -- */
  353. struct snd_pcm_oss_substream oss;
  354. #endif
  355. #ifdef CONFIG_SND_VERBOSE_PROCFS
  356. struct snd_info_entry *proc_root;
  357. struct snd_info_entry *proc_info_entry;
  358. struct snd_info_entry *proc_hw_params_entry;
  359. struct snd_info_entry *proc_sw_params_entry;
  360. struct snd_info_entry *proc_status_entry;
  361. struct snd_info_entry *proc_prealloc_entry;
  362. struct snd_info_entry *proc_prealloc_max_entry;
  363. #endif
  364. /* misc flags */
  365. unsigned int hw_opened: 1;
  366. };
  367. #define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
  368. struct snd_pcm_str {
  369. int stream; /* stream (direction) */
  370. struct snd_pcm *pcm;
  371. /* -- substreams -- */
  372. unsigned int substream_count;
  373. unsigned int substream_opened;
  374. struct snd_pcm_substream *substream;
  375. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  376. /* -- OSS things -- */
  377. struct snd_pcm_oss_stream oss;
  378. #endif
  379. #ifdef CONFIG_SND_VERBOSE_PROCFS
  380. struct snd_info_entry *proc_root;
  381. struct snd_info_entry *proc_info_entry;
  382. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  383. unsigned int xrun_debug; /* 0 = disabled, 1 = verbose, 2 = stacktrace */
  384. struct snd_info_entry *proc_xrun_debug_entry;
  385. #endif
  386. #endif
  387. };
  388. struct snd_pcm {
  389. struct snd_card *card;
  390. struct list_head list;
  391. int device; /* device number */
  392. unsigned int info_flags;
  393. unsigned short dev_class;
  394. unsigned short dev_subclass;
  395. char id[64];
  396. char name[80];
  397. struct snd_pcm_str streams[2];
  398. struct mutex open_mutex;
  399. wait_queue_head_t open_wait;
  400. void *private_data;
  401. void (*private_free) (struct snd_pcm *pcm);
  402. struct device *dev; /* actual hw device this belongs to */
  403. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  404. struct snd_pcm_oss oss;
  405. #endif
  406. };
  407. struct snd_pcm_notify {
  408. int (*n_register) (struct snd_pcm * pcm);
  409. int (*n_disconnect) (struct snd_pcm * pcm);
  410. int (*n_unregister) (struct snd_pcm * pcm);
  411. struct list_head list;
  412. };
  413. /*
  414. * Registering
  415. */
  416. extern const struct file_operations snd_pcm_f_ops[2];
  417. int snd_pcm_new(struct snd_card *card, const char *id, int device,
  418. int playback_count, int capture_count,
  419. struct snd_pcm **rpcm);
  420. int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count);
  421. int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree);
  422. /*
  423. * Native I/O
  424. */
  425. extern rwlock_t snd_pcm_link_rwlock;
  426. int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info);
  427. int snd_pcm_info_user(struct snd_pcm_substream *substream,
  428. struct snd_pcm_info __user *info);
  429. int snd_pcm_status(struct snd_pcm_substream *substream,
  430. struct snd_pcm_status *status);
  431. int snd_pcm_start(struct snd_pcm_substream *substream);
  432. int snd_pcm_stop(struct snd_pcm_substream *substream, int status);
  433. int snd_pcm_drain_done(struct snd_pcm_substream *substream);
  434. #ifdef CONFIG_PM
  435. int snd_pcm_suspend(struct snd_pcm_substream *substream);
  436. int snd_pcm_suspend_all(struct snd_pcm *pcm);
  437. #endif
  438. int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
  439. int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file,
  440. struct snd_pcm_substream **rsubstream);
  441. void snd_pcm_release_substream(struct snd_pcm_substream *substream);
  442. int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, struct file *file,
  443. struct snd_pcm_substream **rsubstream);
  444. void snd_pcm_detach_substream(struct snd_pcm_substream *substream);
  445. void snd_pcm_vma_notify_data(void *client, void *data);
  446. int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area);
  447. /*
  448. * PCM library
  449. */
  450. static inline int snd_pcm_stream_linked(struct snd_pcm_substream *substream)
  451. {
  452. return substream->group != &substream->self_group;
  453. }
  454. static inline void snd_pcm_stream_lock(struct snd_pcm_substream *substream)
  455. {
  456. read_lock(&snd_pcm_link_rwlock);
  457. spin_lock(&substream->self_group.lock);
  458. }
  459. static inline void snd_pcm_stream_unlock(struct snd_pcm_substream *substream)
  460. {
  461. spin_unlock(&substream->self_group.lock);
  462. read_unlock(&snd_pcm_link_rwlock);
  463. }
  464. static inline void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
  465. {
  466. read_lock_irq(&snd_pcm_link_rwlock);
  467. spin_lock(&substream->self_group.lock);
  468. }
  469. static inline void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream)
  470. {
  471. spin_unlock(&substream->self_group.lock);
  472. read_unlock_irq(&snd_pcm_link_rwlock);
  473. }
  474. #define snd_pcm_stream_lock_irqsave(substream, flags) \
  475. do { \
  476. read_lock_irqsave(&snd_pcm_link_rwlock, (flags)); \
  477. spin_lock(&substream->self_group.lock); \
  478. } while (0)
  479. #define snd_pcm_stream_unlock_irqrestore(substream, flags) \
  480. do { \
  481. spin_unlock(&substream->self_group.lock); \
  482. read_unlock_irqrestore(&snd_pcm_link_rwlock, (flags)); \
  483. } while (0)
  484. #define snd_pcm_group_for_each_entry(s, substream) \
  485. list_for_each_entry(s, &substream->group->substreams, link_list)
  486. static inline int snd_pcm_running(struct snd_pcm_substream *substream)
  487. {
  488. return (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING ||
  489. (substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
  490. substream->stream == SNDRV_PCM_STREAM_PLAYBACK));
  491. }
  492. static inline ssize_t bytes_to_samples(struct snd_pcm_runtime *runtime, ssize_t size)
  493. {
  494. return size * 8 / runtime->sample_bits;
  495. }
  496. static inline snd_pcm_sframes_t bytes_to_frames(struct snd_pcm_runtime *runtime, ssize_t size)
  497. {
  498. return size * 8 / runtime->frame_bits;
  499. }
  500. static inline ssize_t samples_to_bytes(struct snd_pcm_runtime *runtime, ssize_t size)
  501. {
  502. return size * runtime->sample_bits / 8;
  503. }
  504. static inline ssize_t frames_to_bytes(struct snd_pcm_runtime *runtime, snd_pcm_sframes_t size)
  505. {
  506. return size * runtime->frame_bits / 8;
  507. }
  508. static inline int frame_aligned(struct snd_pcm_runtime *runtime, ssize_t bytes)
  509. {
  510. return bytes % runtime->byte_align == 0;
  511. }
  512. static inline size_t snd_pcm_lib_buffer_bytes(struct snd_pcm_substream *substream)
  513. {
  514. struct snd_pcm_runtime *runtime = substream->runtime;
  515. return frames_to_bytes(runtime, runtime->buffer_size);
  516. }
  517. static inline size_t snd_pcm_lib_period_bytes(struct snd_pcm_substream *substream)
  518. {
  519. struct snd_pcm_runtime *runtime = substream->runtime;
  520. return frames_to_bytes(runtime, runtime->period_size);
  521. }
  522. /*
  523. * result is: 0 ... (boundary - 1)
  524. */
  525. static inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *runtime)
  526. {
  527. snd_pcm_sframes_t avail = runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_ptr;
  528. if (avail < 0)
  529. avail += runtime->boundary;
  530. else if ((snd_pcm_uframes_t) avail >= runtime->boundary)
  531. avail -= runtime->boundary;
  532. return avail;
  533. }
  534. /*
  535. * result is: 0 ... (boundary - 1)
  536. */
  537. static inline snd_pcm_uframes_t snd_pcm_capture_avail(struct snd_pcm_runtime *runtime)
  538. {
  539. snd_pcm_sframes_t avail = runtime->status->hw_ptr - runtime->control->appl_ptr;
  540. if (avail < 0)
  541. avail += runtime->boundary;
  542. return avail;
  543. }
  544. static inline snd_pcm_sframes_t snd_pcm_playback_hw_avail(struct snd_pcm_runtime *runtime)
  545. {
  546. return runtime->buffer_size - snd_pcm_playback_avail(runtime);
  547. }
  548. static inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(struct snd_pcm_runtime *runtime)
  549. {
  550. return runtime->buffer_size - snd_pcm_capture_avail(runtime);
  551. }
  552. /**
  553. * snd_pcm_playback_ready - check whether the playback buffer is available
  554. * @substream: the pcm substream instance
  555. *
  556. * Checks whether enough free space is available on the playback buffer.
  557. *
  558. * Returns non-zero if available, or zero if not.
  559. */
  560. static inline int snd_pcm_playback_ready(struct snd_pcm_substream *substream)
  561. {
  562. struct snd_pcm_runtime *runtime = substream->runtime;
  563. return snd_pcm_playback_avail(runtime) >= runtime->control->avail_min;
  564. }
  565. /**
  566. * snd_pcm_capture_ready - check whether the capture buffer is available
  567. * @substream: the pcm substream instance
  568. *
  569. * Checks whether enough capture data is available on the capture buffer.
  570. *
  571. * Returns non-zero if available, or zero if not.
  572. */
  573. static inline int snd_pcm_capture_ready(struct snd_pcm_substream *substream)
  574. {
  575. struct snd_pcm_runtime *runtime = substream->runtime;
  576. return snd_pcm_capture_avail(runtime) >= runtime->control->avail_min;
  577. }
  578. /**
  579. * snd_pcm_playback_data - check whether any data exists on the playback buffer
  580. * @substream: the pcm substream instance
  581. *
  582. * Checks whether any data exists on the playback buffer. If stop_threshold
  583. * is bigger or equal to boundary, then this function returns always non-zero.
  584. *
  585. * Returns non-zero if exists, or zero if not.
  586. */
  587. static inline int snd_pcm_playback_data(struct snd_pcm_substream *substream)
  588. {
  589. struct snd_pcm_runtime *runtime = substream->runtime;
  590. if (runtime->stop_threshold >= runtime->boundary)
  591. return 1;
  592. return snd_pcm_playback_avail(runtime) < runtime->buffer_size;
  593. }
  594. /**
  595. * snd_pcm_playback_empty - check whether the playback buffer is empty
  596. * @substream: the pcm substream instance
  597. *
  598. * Checks whether the playback buffer is empty.
  599. *
  600. * Returns non-zero if empty, or zero if not.
  601. */
  602. static inline int snd_pcm_playback_empty(struct snd_pcm_substream *substream)
  603. {
  604. struct snd_pcm_runtime *runtime = substream->runtime;
  605. return snd_pcm_playback_avail(runtime) >= runtime->buffer_size;
  606. }
  607. /**
  608. * snd_pcm_capture_empty - check whether the capture buffer is empty
  609. * @substream: the pcm substream instance
  610. *
  611. * Checks whether the capture buffer is empty.
  612. *
  613. * Returns non-zero if empty, or zero if not.
  614. */
  615. static inline int snd_pcm_capture_empty(struct snd_pcm_substream *substream)
  616. {
  617. struct snd_pcm_runtime *runtime = substream->runtime;
  618. return snd_pcm_capture_avail(runtime) == 0;
  619. }
  620. static inline void snd_pcm_trigger_done(struct snd_pcm_substream *substream,
  621. struct snd_pcm_substream *master)
  622. {
  623. substream->runtime->trigger_master = master;
  624. }
  625. static inline int hw_is_mask(int var)
  626. {
  627. return var >= SNDRV_PCM_HW_PARAM_FIRST_MASK &&
  628. var <= SNDRV_PCM_HW_PARAM_LAST_MASK;
  629. }
  630. static inline int hw_is_interval(int var)
  631. {
  632. return var >= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL &&
  633. var <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL;
  634. }
  635. static inline struct snd_mask *hw_param_mask(struct snd_pcm_hw_params *params,
  636. snd_pcm_hw_param_t var)
  637. {
  638. return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  639. }
  640. static inline struct snd_interval *hw_param_interval(struct snd_pcm_hw_params *params,
  641. snd_pcm_hw_param_t var)
  642. {
  643. return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  644. }
  645. static inline const struct snd_mask *hw_param_mask_c(const struct snd_pcm_hw_params *params,
  646. snd_pcm_hw_param_t var)
  647. {
  648. return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  649. }
  650. static inline const struct snd_interval *hw_param_interval_c(const struct snd_pcm_hw_params *params,
  651. snd_pcm_hw_param_t var)
  652. {
  653. return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  654. }
  655. #define params_access(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_ACCESS))
  656. #define params_format(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_FORMAT))
  657. #define params_subformat(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_SUBFORMAT))
  658. #define params_channels(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_CHANNELS)->min
  659. #define params_rate(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_RATE)->min
  660. #define params_period_size(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min
  661. #define params_period_bytes(p) ((params_period_size(p)*snd_pcm_format_physical_width(params_format(p))*params_channels(p))/8)
  662. #define params_periods(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_PERIODS)->min
  663. #define params_buffer_size(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min
  664. #define params_buffer_bytes(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min
  665. int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v);
  666. void snd_interval_mul(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c);
  667. void snd_interval_div(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c);
  668. void snd_interval_muldivk(const struct snd_interval *a, const struct snd_interval *b,
  669. unsigned int k, struct snd_interval *c);
  670. void snd_interval_mulkdiv(const struct snd_interval *a, unsigned int k,
  671. const struct snd_interval *b, struct snd_interval *c);
  672. int snd_interval_list(struct snd_interval *i, unsigned int count, unsigned int *list, unsigned int mask);
  673. int snd_interval_ratnum(struct snd_interval *i,
  674. unsigned int rats_count, struct snd_ratnum *rats,
  675. unsigned int *nump, unsigned int *denp);
  676. void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params);
  677. void _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var);
  678. int snd_pcm_hw_params_choose(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
  679. int snd_pcm_hw_refine(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
  680. int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream);
  681. int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream);
  682. int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  683. u_int32_t mask);
  684. int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  685. u_int64_t mask);
  686. int snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  687. unsigned int min, unsigned int max);
  688. int snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var);
  689. int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime,
  690. unsigned int cond,
  691. snd_pcm_hw_param_t var,
  692. struct snd_pcm_hw_constraint_list *l);
  693. int snd_pcm_hw_constraint_ratnums(struct snd_pcm_runtime *runtime,
  694. unsigned int cond,
  695. snd_pcm_hw_param_t var,
  696. struct snd_pcm_hw_constraint_ratnums *r);
  697. int snd_pcm_hw_constraint_ratdens(struct snd_pcm_runtime *runtime,
  698. unsigned int cond,
  699. snd_pcm_hw_param_t var,
  700. struct snd_pcm_hw_constraint_ratdens *r);
  701. int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime,
  702. unsigned int cond,
  703. unsigned int width,
  704. unsigned int msbits);
  705. int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
  706. unsigned int cond,
  707. snd_pcm_hw_param_t var,
  708. unsigned long step);
  709. int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
  710. unsigned int cond,
  711. snd_pcm_hw_param_t var);
  712. int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime,
  713. unsigned int cond,
  714. int var,
  715. snd_pcm_hw_rule_func_t func, void *private,
  716. int dep, ...);
  717. int snd_pcm_format_signed(snd_pcm_format_t format);
  718. int snd_pcm_format_unsigned(snd_pcm_format_t format);
  719. int snd_pcm_format_linear(snd_pcm_format_t format);
  720. int snd_pcm_format_little_endian(snd_pcm_format_t format);
  721. int snd_pcm_format_big_endian(snd_pcm_format_t format);
  722. #if 0 /* just for DocBook */
  723. /**
  724. * snd_pcm_format_cpu_endian - Check the PCM format is CPU-endian
  725. * @format: the format to check
  726. *
  727. * Returns 1 if the given PCM format is CPU-endian, 0 if
  728. * opposite, or a negative error code if endian not specified.
  729. */
  730. int snd_pcm_format_cpu_endian(snd_pcm_format_t format);
  731. #endif /* DocBook */
  732. #ifdef SNDRV_LITTLE_ENDIAN
  733. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_little_endian(format)
  734. #else
  735. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_big_endian(format)
  736. #endif
  737. int snd_pcm_format_width(snd_pcm_format_t format); /* in bits */
  738. int snd_pcm_format_physical_width(snd_pcm_format_t format); /* in bits */
  739. ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
  740. const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format);
  741. int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
  742. snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsignd, int big_endian);
  743. void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, struct snd_pcm_ops *ops);
  744. void snd_pcm_set_sync(struct snd_pcm_substream *substream);
  745. int snd_pcm_lib_interleave_len(struct snd_pcm_substream *substream);
  746. int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  747. unsigned int cmd, void *arg);
  748. int snd_pcm_update_state(struct snd_pcm_substream *substream,
  749. struct snd_pcm_runtime *runtime);
  750. int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream);
  751. int snd_pcm_playback_xrun_check(struct snd_pcm_substream *substream);
  752. int snd_pcm_capture_xrun_check(struct snd_pcm_substream *substream);
  753. int snd_pcm_playback_xrun_asap(struct snd_pcm_substream *substream);
  754. int snd_pcm_capture_xrun_asap(struct snd_pcm_substream *substream);
  755. void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_uframes_t new_hw_ptr);
  756. void snd_pcm_period_elapsed(struct snd_pcm_substream *substream);
  757. snd_pcm_sframes_t snd_pcm_lib_write(struct snd_pcm_substream *substream,
  758. const void __user *buf,
  759. snd_pcm_uframes_t frames);
  760. snd_pcm_sframes_t snd_pcm_lib_read(struct snd_pcm_substream *substream,
  761. void __user *buf, snd_pcm_uframes_t frames);
  762. snd_pcm_sframes_t snd_pcm_lib_writev(struct snd_pcm_substream *substream,
  763. void __user **bufs, snd_pcm_uframes_t frames);
  764. snd_pcm_sframes_t snd_pcm_lib_readv(struct snd_pcm_substream *substream,
  765. void __user **bufs, snd_pcm_uframes_t frames);
  766. extern const struct snd_pcm_hw_constraint_list snd_pcm_known_rates;
  767. int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime);
  768. unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate);
  769. static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substream,
  770. struct snd_dma_buffer *bufp)
  771. {
  772. struct snd_pcm_runtime *runtime = substream->runtime;
  773. if (bufp) {
  774. runtime->dma_buffer_p = bufp;
  775. runtime->dma_area = bufp->area;
  776. runtime->dma_addr = bufp->addr;
  777. runtime->dma_bytes = bufp->bytes;
  778. } else {
  779. runtime->dma_buffer_p = NULL;
  780. runtime->dma_area = NULL;
  781. runtime->dma_addr = 0;
  782. runtime->dma_bytes = 0;
  783. }
  784. }
  785. /*
  786. * Timer interface
  787. */
  788. void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream);
  789. void snd_pcm_timer_init(struct snd_pcm_substream *substream);
  790. void snd_pcm_timer_done(struct snd_pcm_substream *substream);
  791. static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
  792. struct timespec *tv)
  793. {
  794. if (runtime->tstamp_type == SNDRV_PCM_TSTAMP_TYPE_MONOTONIC)
  795. do_posix_clock_monotonic_gettime(tv);
  796. else
  797. getnstimeofday(tv);
  798. }
  799. /*
  800. * Memory
  801. */
  802. int snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream);
  803. int snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm);
  804. int snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
  805. int type, struct device *data,
  806. size_t size, size_t max);
  807. int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
  808. int type, void *data,
  809. size_t size, size_t max);
  810. int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size);
  811. int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream);
  812. int _snd_pcm_lib_alloc_vmalloc_buffer(struct snd_pcm_substream *substream,
  813. size_t size, gfp_t gfp_flags);
  814. int snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream);
  815. struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream,
  816. unsigned long offset);
  817. #if 0 /* for kernel-doc */
  818. /**
  819. * snd_pcm_lib_alloc_vmalloc_buffer - allocate virtual DMA buffer
  820. * @substream: the substream to allocate the buffer to
  821. * @size: the requested buffer size, in bytes
  822. *
  823. * Allocates the PCM substream buffer using vmalloc(), i.e., the memory is
  824. * contiguous in kernel virtual space, but not in physical memory. Use this
  825. * if the buffer is accessed by kernel code but not by device DMA.
  826. *
  827. * Returns 1 if the buffer was changed, 0 if not changed, or a negative error
  828. * code.
  829. */
  830. static int snd_pcm_lib_alloc_vmalloc_buffer
  831. (struct snd_pcm_substream *substream, size_t size);
  832. /**
  833. * snd_pcm_lib_alloc_vmalloc_32_buffer - allocate 32-bit-addressable buffer
  834. * @substream: the substream to allocate the buffer to
  835. * @size: the requested buffer size, in bytes
  836. *
  837. * This function works like snd_pcm_lib_alloc_vmalloc_buffer(), but uses
  838. * vmalloc_32(), i.e., the pages are allocated from 32-bit-addressable memory.
  839. */
  840. static int snd_pcm_lib_alloc_vmalloc_32_buffer
  841. (struct snd_pcm_substream *substream, size_t size);
  842. #endif
  843. #define snd_pcm_lib_alloc_vmalloc_buffer(subs, size) \
  844. _snd_pcm_lib_alloc_vmalloc_buffer \
  845. (subs, size, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO)
  846. #define snd_pcm_lib_alloc_vmalloc_32_buffer(subs, size) \
  847. _snd_pcm_lib_alloc_vmalloc_buffer \
  848. (subs, size, GFP_KERNEL | GFP_DMA32 | __GFP_ZERO)
  849. #ifdef CONFIG_SND_DMA_SGBUF
  850. /*
  851. * SG-buffer handling
  852. */
  853. #define snd_pcm_substream_sgbuf(substream) \
  854. ((substream)->runtime->dma_buffer_p->private_data)
  855. static inline dma_addr_t
  856. snd_pcm_sgbuf_get_addr(struct snd_pcm_substream *substream, unsigned int ofs)
  857. {
  858. struct snd_sg_buf *sg = snd_pcm_substream_sgbuf(substream);
  859. return snd_sgbuf_get_addr(sg, ofs);
  860. }
  861. static inline void *
  862. snd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs)
  863. {
  864. struct snd_sg_buf *sg = snd_pcm_substream_sgbuf(substream);
  865. return snd_sgbuf_get_ptr(sg, ofs);
  866. }
  867. struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream,
  868. unsigned long offset);
  869. unsigned int snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream,
  870. unsigned int ofs, unsigned int size);
  871. #else /* !SND_DMA_SGBUF */
  872. /*
  873. * fake using a continuous buffer
  874. */
  875. static inline dma_addr_t
  876. snd_pcm_sgbuf_get_addr(struct snd_pcm_substream *substream, unsigned int ofs)
  877. {
  878. return substream->runtime->dma_addr + ofs;
  879. }
  880. static inline void *
  881. snd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs)
  882. {
  883. return substream->runtime->dma_area + ofs;
  884. }
  885. #define snd_pcm_sgbuf_ops_page NULL
  886. #define snd_pcm_sgbuf_get_chunk_size(subs, ofs, size) (size)
  887. #endif /* SND_DMA_SGBUF */
  888. /* handle mmap counter - PCM mmap callback should handle this counter properly */
  889. static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area)
  890. {
  891. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  892. atomic_inc(&substream->mmap_count);
  893. }
  894. static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area)
  895. {
  896. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  897. atomic_dec(&substream->mmap_count);
  898. }
  899. /* mmap for io-memory area */
  900. #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
  901. #define SNDRV_PCM_INFO_MMAP_IOMEM SNDRV_PCM_INFO_MMAP
  902. int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, struct vm_area_struct *area);
  903. #else
  904. #define SNDRV_PCM_INFO_MMAP_IOMEM 0
  905. #define snd_pcm_lib_mmap_iomem NULL
  906. #endif
  907. int snd_pcm_lib_mmap_noncached(struct snd_pcm_substream *substream,
  908. struct vm_area_struct *area);
  909. #define snd_pcm_lib_mmap_vmalloc snd_pcm_lib_mmap_noncached
  910. static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
  911. {
  912. *max = dma < 4 ? 64 * 1024 : 128 * 1024;
  913. }
  914. /*
  915. * Misc
  916. */
  917. #define SNDRV_PCM_DEFAULT_CON_SPDIF (IEC958_AES0_CON_EMPHASIS_NONE|\
  918. (IEC958_AES1_CON_ORIGINAL<<8)|\
  919. (IEC958_AES1_CON_PCM_CODER<<8)|\
  920. (IEC958_AES3_CON_FS_48000<<24))
  921. #define PCM_RUNTIME_CHECK(sub) snd_BUG_ON(!(sub) || !(sub)->runtime)
  922. const char *snd_pcm_format_name(snd_pcm_format_t format);
  923. #endif /* __SOUND_PCM_H */