pcm.h 35 KB

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