pcm.h 36 KB

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