pcm.h 35 KB

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