pcm.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  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. unsigned long hw_ptr_jiffies; /* Time when hw_ptr is updated */
  243. snd_pcm_sframes_t delay; /* extra delay; typically FIFO size */
  244. /* -- HW params -- */
  245. snd_pcm_access_t access; /* access mode */
  246. snd_pcm_format_t format; /* SNDRV_PCM_FORMAT_* */
  247. snd_pcm_subformat_t subformat; /* subformat */
  248. unsigned int rate; /* rate in Hz */
  249. unsigned int channels; /* channels */
  250. snd_pcm_uframes_t period_size; /* period size */
  251. unsigned int periods; /* periods */
  252. snd_pcm_uframes_t buffer_size; /* buffer size */
  253. snd_pcm_uframes_t min_align; /* Min alignment for the format */
  254. size_t byte_align;
  255. unsigned int frame_bits;
  256. unsigned int sample_bits;
  257. unsigned int info;
  258. unsigned int rate_num;
  259. unsigned int rate_den;
  260. /* -- SW params -- */
  261. int tstamp_mode; /* mmap timestamp is updated */
  262. unsigned int period_step;
  263. snd_pcm_uframes_t start_threshold;
  264. snd_pcm_uframes_t stop_threshold;
  265. snd_pcm_uframes_t silence_threshold; /* Silence filling happens when
  266. noise is nearest than this */
  267. snd_pcm_uframes_t silence_size; /* Silence filling size */
  268. snd_pcm_uframes_t boundary; /* pointers wrap point */
  269. snd_pcm_uframes_t silence_start; /* starting pointer to silence area */
  270. snd_pcm_uframes_t silence_filled; /* size filled with silence */
  271. union snd_pcm_sync_id sync; /* hardware synchronization ID */
  272. /* -- mmap -- */
  273. struct snd_pcm_mmap_status *status;
  274. struct snd_pcm_mmap_control *control;
  275. /* -- locking / scheduling -- */
  276. wait_queue_head_t sleep;
  277. struct fasync_struct *fasync;
  278. /* -- private section -- */
  279. void *private_data;
  280. void (*private_free)(struct snd_pcm_runtime *runtime);
  281. /* -- hardware description -- */
  282. struct snd_pcm_hardware hw;
  283. struct snd_pcm_hw_constraints hw_constraints;
  284. /* -- interrupt callbacks -- */
  285. void (*transfer_ack_begin)(struct snd_pcm_substream *substream);
  286. void (*transfer_ack_end)(struct snd_pcm_substream *substream);
  287. /* -- timer -- */
  288. unsigned int timer_resolution; /* timer resolution */
  289. int tstamp_type; /* timestamp type */
  290. /* -- DMA -- */
  291. unsigned char *dma_area; /* DMA area */
  292. dma_addr_t dma_addr; /* physical bus address (not accessible from main CPU) */
  293. size_t dma_bytes; /* size of DMA area */
  294. struct snd_dma_buffer *dma_buffer_p; /* allocated buffer */
  295. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  296. /* -- OSS things -- */
  297. struct snd_pcm_oss_runtime oss;
  298. #endif
  299. };
  300. struct snd_pcm_group { /* keep linked substreams */
  301. spinlock_t lock;
  302. struct list_head substreams;
  303. int count;
  304. };
  305. struct snd_pcm_substream {
  306. struct snd_pcm *pcm;
  307. struct snd_pcm_str *pstr;
  308. void *private_data; /* copied from pcm->private_data */
  309. int number;
  310. char name[32]; /* substream name */
  311. int stream; /* stream (direction) */
  312. char latency_id[20]; /* latency identifier */
  313. size_t buffer_bytes_max; /* limit ring buffer size */
  314. struct snd_dma_buffer dma_buffer;
  315. unsigned int dma_buf_id;
  316. size_t dma_max;
  317. /* -- hardware operations -- */
  318. struct snd_pcm_ops *ops;
  319. /* -- runtime information -- */
  320. struct snd_pcm_runtime *runtime;
  321. /* -- timer section -- */
  322. struct snd_timer *timer; /* timer */
  323. unsigned timer_running: 1; /* time is running */
  324. /* -- next substream -- */
  325. struct snd_pcm_substream *next;
  326. /* -- linked substreams -- */
  327. struct list_head link_list; /* linked list member */
  328. struct snd_pcm_group self_group; /* fake group for non linked substream (with substream lock inside) */
  329. struct snd_pcm_group *group; /* pointer to current group */
  330. /* -- assigned files -- */
  331. void *file;
  332. int ref_count;
  333. atomic_t mmap_count;
  334. unsigned int f_flags;
  335. void (*pcm_release)(struct snd_pcm_substream *);
  336. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  337. /* -- OSS things -- */
  338. struct snd_pcm_oss_substream oss;
  339. #endif
  340. #ifdef CONFIG_SND_VERBOSE_PROCFS
  341. struct snd_info_entry *proc_root;
  342. struct snd_info_entry *proc_info_entry;
  343. struct snd_info_entry *proc_hw_params_entry;
  344. struct snd_info_entry *proc_sw_params_entry;
  345. struct snd_info_entry *proc_status_entry;
  346. struct snd_info_entry *proc_prealloc_entry;
  347. struct snd_info_entry *proc_prealloc_max_entry;
  348. #endif
  349. /* misc flags */
  350. unsigned int hw_opened: 1;
  351. };
  352. #define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
  353. struct snd_pcm_str {
  354. int stream; /* stream (direction) */
  355. struct snd_pcm *pcm;
  356. /* -- substreams -- */
  357. unsigned int substream_count;
  358. unsigned int substream_opened;
  359. struct snd_pcm_substream *substream;
  360. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  361. /* -- OSS things -- */
  362. struct snd_pcm_oss_stream oss;
  363. #endif
  364. #ifdef CONFIG_SND_VERBOSE_PROCFS
  365. struct snd_info_entry *proc_root;
  366. struct snd_info_entry *proc_info_entry;
  367. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  368. unsigned int xrun_debug; /* 0 = disabled, 1 = verbose, 2 = stacktrace */
  369. struct snd_info_entry *proc_xrun_debug_entry;
  370. #endif
  371. #endif
  372. };
  373. struct snd_pcm {
  374. struct snd_card *card;
  375. struct list_head list;
  376. int device; /* device number */
  377. unsigned int info_flags;
  378. unsigned short dev_class;
  379. unsigned short dev_subclass;
  380. char id[64];
  381. char name[80];
  382. struct snd_pcm_str streams[2];
  383. struct mutex open_mutex;
  384. wait_queue_head_t open_wait;
  385. void *private_data;
  386. void (*private_free) (struct snd_pcm *pcm);
  387. struct device *dev; /* actual hw device this belongs to */
  388. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  389. struct snd_pcm_oss oss;
  390. #endif
  391. };
  392. struct snd_pcm_notify {
  393. int (*n_register) (struct snd_pcm * pcm);
  394. int (*n_disconnect) (struct snd_pcm * pcm);
  395. int (*n_unregister) (struct snd_pcm * pcm);
  396. struct list_head list;
  397. };
  398. /*
  399. * Registering
  400. */
  401. extern const struct file_operations snd_pcm_f_ops[2];
  402. int snd_pcm_new(struct snd_card *card, const char *id, int device,
  403. int playback_count, int capture_count,
  404. struct snd_pcm **rpcm);
  405. int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count);
  406. int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree);
  407. /*
  408. * Native I/O
  409. */
  410. extern rwlock_t snd_pcm_link_rwlock;
  411. int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info);
  412. int snd_pcm_info_user(struct snd_pcm_substream *substream,
  413. struct snd_pcm_info __user *info);
  414. int snd_pcm_status(struct snd_pcm_substream *substream,
  415. struct snd_pcm_status *status);
  416. int snd_pcm_start(struct snd_pcm_substream *substream);
  417. int snd_pcm_stop(struct snd_pcm_substream *substream, int status);
  418. int snd_pcm_drain_done(struct snd_pcm_substream *substream);
  419. #ifdef CONFIG_PM
  420. int snd_pcm_suspend(struct snd_pcm_substream *substream);
  421. int snd_pcm_suspend_all(struct snd_pcm *pcm);
  422. #endif
  423. int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
  424. int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file,
  425. struct snd_pcm_substream **rsubstream);
  426. void snd_pcm_release_substream(struct snd_pcm_substream *substream);
  427. int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, struct file *file,
  428. struct snd_pcm_substream **rsubstream);
  429. void snd_pcm_detach_substream(struct snd_pcm_substream *substream);
  430. void snd_pcm_vma_notify_data(void *client, void *data);
  431. int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area);
  432. #if BITS_PER_LONG >= 64
  433. static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
  434. {
  435. *rem = *n % div;
  436. *n /= div;
  437. }
  438. #elif defined(i386)
  439. static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
  440. {
  441. u_int32_t low, high;
  442. low = *n & 0xffffffff;
  443. high = *n >> 32;
  444. if (high) {
  445. u_int32_t high1 = high % div;
  446. high /= div;
  447. asm("divl %2":"=a" (low), "=d" (*rem):"rm" (div), "a" (low), "d" (high1));
  448. *n = (u_int64_t)high << 32 | low;
  449. } else {
  450. *n = low / div;
  451. *rem = low % div;
  452. }
  453. }
  454. #else
  455. static inline void divl(u_int32_t high, u_int32_t low,
  456. u_int32_t div,
  457. u_int32_t *q, u_int32_t *r)
  458. {
  459. u_int64_t n = (u_int64_t)high << 32 | low;
  460. u_int64_t d = (u_int64_t)div << 31;
  461. u_int32_t q1 = 0;
  462. int c = 32;
  463. while (n > 0xffffffffU) {
  464. q1 <<= 1;
  465. if (n >= d) {
  466. n -= d;
  467. q1 |= 1;
  468. }
  469. d >>= 1;
  470. c--;
  471. }
  472. q1 <<= c;
  473. if (n) {
  474. low = n;
  475. *q = q1 | (low / div);
  476. *r = low % div;
  477. } else {
  478. *r = 0;
  479. *q = q1;
  480. }
  481. return;
  482. }
  483. static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
  484. {
  485. u_int32_t low, high;
  486. low = *n & 0xffffffff;
  487. high = *n >> 32;
  488. if (high) {
  489. u_int32_t high1 = high % div;
  490. u_int32_t low1 = low;
  491. high /= div;
  492. divl(high1, low1, div, &low, rem);
  493. *n = (u_int64_t)high << 32 | low;
  494. } else {
  495. *n = low / div;
  496. *rem = low % div;
  497. }
  498. }
  499. #endif
  500. /*
  501. * PCM library
  502. */
  503. static inline int snd_pcm_stream_linked(struct snd_pcm_substream *substream)
  504. {
  505. return substream->group != &substream->self_group;
  506. }
  507. static inline void snd_pcm_stream_lock(struct snd_pcm_substream *substream)
  508. {
  509. read_lock(&snd_pcm_link_rwlock);
  510. spin_lock(&substream->self_group.lock);
  511. }
  512. static inline void snd_pcm_stream_unlock(struct snd_pcm_substream *substream)
  513. {
  514. spin_unlock(&substream->self_group.lock);
  515. read_unlock(&snd_pcm_link_rwlock);
  516. }
  517. static inline void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
  518. {
  519. read_lock_irq(&snd_pcm_link_rwlock);
  520. spin_lock(&substream->self_group.lock);
  521. }
  522. static inline void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream)
  523. {
  524. spin_unlock(&substream->self_group.lock);
  525. read_unlock_irq(&snd_pcm_link_rwlock);
  526. }
  527. #define snd_pcm_stream_lock_irqsave(substream, flags) \
  528. do { \
  529. read_lock_irqsave(&snd_pcm_link_rwlock, (flags)); \
  530. spin_lock(&substream->self_group.lock); \
  531. } while (0)
  532. #define snd_pcm_stream_unlock_irqrestore(substream, flags) \
  533. do { \
  534. spin_unlock(&substream->self_group.lock); \
  535. read_unlock_irqrestore(&snd_pcm_link_rwlock, (flags)); \
  536. } while (0)
  537. #define snd_pcm_group_for_each_entry(s, substream) \
  538. list_for_each_entry(s, &substream->group->substreams, link_list)
  539. static inline int snd_pcm_running(struct snd_pcm_substream *substream)
  540. {
  541. return (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING ||
  542. (substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
  543. substream->stream == SNDRV_PCM_STREAM_PLAYBACK));
  544. }
  545. static inline ssize_t bytes_to_samples(struct snd_pcm_runtime *runtime, ssize_t size)
  546. {
  547. return size * 8 / runtime->sample_bits;
  548. }
  549. static inline snd_pcm_sframes_t bytes_to_frames(struct snd_pcm_runtime *runtime, ssize_t size)
  550. {
  551. return size * 8 / runtime->frame_bits;
  552. }
  553. static inline ssize_t samples_to_bytes(struct snd_pcm_runtime *runtime, ssize_t size)
  554. {
  555. return size * runtime->sample_bits / 8;
  556. }
  557. static inline ssize_t frames_to_bytes(struct snd_pcm_runtime *runtime, snd_pcm_sframes_t size)
  558. {
  559. return size * runtime->frame_bits / 8;
  560. }
  561. static inline int frame_aligned(struct snd_pcm_runtime *runtime, ssize_t bytes)
  562. {
  563. return bytes % runtime->byte_align == 0;
  564. }
  565. static inline size_t snd_pcm_lib_buffer_bytes(struct snd_pcm_substream *substream)
  566. {
  567. struct snd_pcm_runtime *runtime = substream->runtime;
  568. return frames_to_bytes(runtime, runtime->buffer_size);
  569. }
  570. static inline size_t snd_pcm_lib_period_bytes(struct snd_pcm_substream *substream)
  571. {
  572. struct snd_pcm_runtime *runtime = substream->runtime;
  573. return frames_to_bytes(runtime, runtime->period_size);
  574. }
  575. /*
  576. * result is: 0 ... (boundary - 1)
  577. */
  578. static inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *runtime)
  579. {
  580. snd_pcm_sframes_t avail = runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_ptr;
  581. if (avail < 0)
  582. avail += runtime->boundary;
  583. else if ((snd_pcm_uframes_t) avail >= runtime->boundary)
  584. avail -= runtime->boundary;
  585. return avail;
  586. }
  587. /*
  588. * result is: 0 ... (boundary - 1)
  589. */
  590. static inline snd_pcm_uframes_t snd_pcm_capture_avail(struct snd_pcm_runtime *runtime)
  591. {
  592. snd_pcm_sframes_t avail = runtime->status->hw_ptr - runtime->control->appl_ptr;
  593. if (avail < 0)
  594. avail += runtime->boundary;
  595. return avail;
  596. }
  597. static inline snd_pcm_sframes_t snd_pcm_playback_hw_avail(struct snd_pcm_runtime *runtime)
  598. {
  599. return runtime->buffer_size - snd_pcm_playback_avail(runtime);
  600. }
  601. static inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(struct snd_pcm_runtime *runtime)
  602. {
  603. return runtime->buffer_size - snd_pcm_capture_avail(runtime);
  604. }
  605. /**
  606. * snd_pcm_playback_ready - check whether the playback buffer is available
  607. * @substream: the pcm substream instance
  608. *
  609. * Checks whether enough free space is available on the playback buffer.
  610. *
  611. * Returns non-zero if available, or zero if not.
  612. */
  613. static inline int snd_pcm_playback_ready(struct snd_pcm_substream *substream)
  614. {
  615. struct snd_pcm_runtime *runtime = substream->runtime;
  616. return snd_pcm_playback_avail(runtime) >= runtime->control->avail_min;
  617. }
  618. /**
  619. * snd_pcm_capture_ready - check whether the capture buffer is available
  620. * @substream: the pcm substream instance
  621. *
  622. * Checks whether enough capture data is available on the capture buffer.
  623. *
  624. * Returns non-zero if available, or zero if not.
  625. */
  626. static inline int snd_pcm_capture_ready(struct snd_pcm_substream *substream)
  627. {
  628. struct snd_pcm_runtime *runtime = substream->runtime;
  629. return snd_pcm_capture_avail(runtime) >= runtime->control->avail_min;
  630. }
  631. /**
  632. * snd_pcm_playback_data - check whether any data exists on the playback buffer
  633. * @substream: the pcm substream instance
  634. *
  635. * Checks whether any data exists on the playback buffer. If stop_threshold
  636. * is bigger or equal to boundary, then this function returns always non-zero.
  637. *
  638. * Returns non-zero if exists, or zero if not.
  639. */
  640. static inline int snd_pcm_playback_data(struct snd_pcm_substream *substream)
  641. {
  642. struct snd_pcm_runtime *runtime = substream->runtime;
  643. if (runtime->stop_threshold >= runtime->boundary)
  644. return 1;
  645. return snd_pcm_playback_avail(runtime) < runtime->buffer_size;
  646. }
  647. /**
  648. * snd_pcm_playback_empty - check whether the playback buffer is empty
  649. * @substream: the pcm substream instance
  650. *
  651. * Checks whether the playback buffer is empty.
  652. *
  653. * Returns non-zero if empty, or zero if not.
  654. */
  655. static inline int snd_pcm_playback_empty(struct snd_pcm_substream *substream)
  656. {
  657. struct snd_pcm_runtime *runtime = substream->runtime;
  658. return snd_pcm_playback_avail(runtime) >= runtime->buffer_size;
  659. }
  660. /**
  661. * snd_pcm_capture_empty - check whether the capture buffer is empty
  662. * @substream: the pcm substream instance
  663. *
  664. * Checks whether the capture buffer is empty.
  665. *
  666. * Returns non-zero if empty, or zero if not.
  667. */
  668. static inline int snd_pcm_capture_empty(struct snd_pcm_substream *substream)
  669. {
  670. struct snd_pcm_runtime *runtime = substream->runtime;
  671. return snd_pcm_capture_avail(runtime) == 0;
  672. }
  673. static inline void snd_pcm_trigger_done(struct snd_pcm_substream *substream,
  674. struct snd_pcm_substream *master)
  675. {
  676. substream->runtime->trigger_master = master;
  677. }
  678. static inline int hw_is_mask(int var)
  679. {
  680. return var >= SNDRV_PCM_HW_PARAM_FIRST_MASK &&
  681. var <= SNDRV_PCM_HW_PARAM_LAST_MASK;
  682. }
  683. static inline int hw_is_interval(int var)
  684. {
  685. return var >= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL &&
  686. var <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL;
  687. }
  688. static inline struct snd_mask *hw_param_mask(struct snd_pcm_hw_params *params,
  689. snd_pcm_hw_param_t var)
  690. {
  691. return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  692. }
  693. static inline struct snd_interval *hw_param_interval(struct snd_pcm_hw_params *params,
  694. snd_pcm_hw_param_t var)
  695. {
  696. return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  697. }
  698. static inline const struct snd_mask *hw_param_mask_c(const struct snd_pcm_hw_params *params,
  699. snd_pcm_hw_param_t var)
  700. {
  701. return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  702. }
  703. static inline const struct snd_interval *hw_param_interval_c(const struct snd_pcm_hw_params *params,
  704. snd_pcm_hw_param_t var)
  705. {
  706. return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  707. }
  708. #define params_access(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_ACCESS))
  709. #define params_format(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_FORMAT))
  710. #define params_subformat(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_SUBFORMAT))
  711. #define params_channels(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_CHANNELS)->min
  712. #define params_rate(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_RATE)->min
  713. #define params_period_size(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min
  714. #define params_period_bytes(p) ((params_period_size(p)*snd_pcm_format_physical_width(params_format(p))*params_channels(p))/8)
  715. #define params_periods(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_PERIODS)->min
  716. #define params_buffer_size(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min
  717. #define params_buffer_bytes(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min
  718. int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v);
  719. void snd_interval_mul(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c);
  720. void snd_interval_div(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c);
  721. void snd_interval_muldivk(const struct snd_interval *a, const struct snd_interval *b,
  722. unsigned int k, struct snd_interval *c);
  723. void snd_interval_mulkdiv(const struct snd_interval *a, unsigned int k,
  724. const struct snd_interval *b, struct snd_interval *c);
  725. int snd_interval_list(struct snd_interval *i, unsigned int count, unsigned int *list, unsigned int mask);
  726. int snd_interval_ratnum(struct snd_interval *i,
  727. unsigned int rats_count, struct snd_ratnum *rats,
  728. unsigned int *nump, unsigned int *denp);
  729. void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params);
  730. void _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var);
  731. int snd_pcm_hw_params_choose(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
  732. int snd_pcm_hw_refine(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
  733. int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream);
  734. int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream);
  735. int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  736. u_int32_t mask);
  737. int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  738. u_int64_t mask);
  739. int snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  740. unsigned int min, unsigned int max);
  741. int snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var);
  742. int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime,
  743. unsigned int cond,
  744. snd_pcm_hw_param_t var,
  745. struct snd_pcm_hw_constraint_list *l);
  746. int snd_pcm_hw_constraint_ratnums(struct snd_pcm_runtime *runtime,
  747. unsigned int cond,
  748. snd_pcm_hw_param_t var,
  749. struct snd_pcm_hw_constraint_ratnums *r);
  750. int snd_pcm_hw_constraint_ratdens(struct snd_pcm_runtime *runtime,
  751. unsigned int cond,
  752. snd_pcm_hw_param_t var,
  753. struct snd_pcm_hw_constraint_ratdens *r);
  754. int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime,
  755. unsigned int cond,
  756. unsigned int width,
  757. unsigned int msbits);
  758. int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
  759. unsigned int cond,
  760. snd_pcm_hw_param_t var,
  761. unsigned long step);
  762. int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
  763. unsigned int cond,
  764. snd_pcm_hw_param_t var);
  765. int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime,
  766. unsigned int cond,
  767. int var,
  768. snd_pcm_hw_rule_func_t func, void *private,
  769. int dep, ...);
  770. int snd_pcm_format_signed(snd_pcm_format_t format);
  771. int snd_pcm_format_unsigned(snd_pcm_format_t format);
  772. int snd_pcm_format_linear(snd_pcm_format_t format);
  773. int snd_pcm_format_little_endian(snd_pcm_format_t format);
  774. int snd_pcm_format_big_endian(snd_pcm_format_t format);
  775. #if 0 /* just for DocBook */
  776. /**
  777. * snd_pcm_format_cpu_endian - Check the PCM format is CPU-endian
  778. * @format: the format to check
  779. *
  780. * Returns 1 if the given PCM format is CPU-endian, 0 if
  781. * opposite, or a negative error code if endian not specified.
  782. */
  783. int snd_pcm_format_cpu_endian(snd_pcm_format_t format);
  784. #endif /* DocBook */
  785. #ifdef SNDRV_LITTLE_ENDIAN
  786. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_little_endian(format)
  787. #else
  788. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_big_endian(format)
  789. #endif
  790. int snd_pcm_format_width(snd_pcm_format_t format); /* in bits */
  791. int snd_pcm_format_physical_width(snd_pcm_format_t format); /* in bits */
  792. ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
  793. const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format);
  794. int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
  795. snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsignd, int big_endian);
  796. void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, struct snd_pcm_ops *ops);
  797. void snd_pcm_set_sync(struct snd_pcm_substream *substream);
  798. int snd_pcm_lib_interleave_len(struct snd_pcm_substream *substream);
  799. int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  800. unsigned int cmd, void *arg);
  801. int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream);
  802. int snd_pcm_playback_xrun_check(struct snd_pcm_substream *substream);
  803. int snd_pcm_capture_xrun_check(struct snd_pcm_substream *substream);
  804. int snd_pcm_playback_xrun_asap(struct snd_pcm_substream *substream);
  805. int snd_pcm_capture_xrun_asap(struct snd_pcm_substream *substream);
  806. void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_uframes_t new_hw_ptr);
  807. void snd_pcm_period_elapsed(struct snd_pcm_substream *substream);
  808. snd_pcm_sframes_t snd_pcm_lib_write(struct snd_pcm_substream *substream,
  809. const void __user *buf,
  810. snd_pcm_uframes_t frames);
  811. snd_pcm_sframes_t snd_pcm_lib_read(struct snd_pcm_substream *substream,
  812. void __user *buf, snd_pcm_uframes_t frames);
  813. snd_pcm_sframes_t snd_pcm_lib_writev(struct snd_pcm_substream *substream,
  814. void __user **bufs, snd_pcm_uframes_t frames);
  815. snd_pcm_sframes_t snd_pcm_lib_readv(struct snd_pcm_substream *substream,
  816. void __user **bufs, snd_pcm_uframes_t frames);
  817. extern const struct snd_pcm_hw_constraint_list snd_pcm_known_rates;
  818. int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime);
  819. unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate);
  820. static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substream,
  821. struct snd_dma_buffer *bufp)
  822. {
  823. struct snd_pcm_runtime *runtime = substream->runtime;
  824. if (bufp) {
  825. runtime->dma_buffer_p = bufp;
  826. runtime->dma_area = bufp->area;
  827. runtime->dma_addr = bufp->addr;
  828. runtime->dma_bytes = bufp->bytes;
  829. } else {
  830. runtime->dma_buffer_p = NULL;
  831. runtime->dma_area = NULL;
  832. runtime->dma_addr = 0;
  833. runtime->dma_bytes = 0;
  834. }
  835. }
  836. /*
  837. * Timer interface
  838. */
  839. void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream);
  840. void snd_pcm_timer_init(struct snd_pcm_substream *substream);
  841. void snd_pcm_timer_done(struct snd_pcm_substream *substream);
  842. static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
  843. struct timespec *tv)
  844. {
  845. if (runtime->tstamp_type == SNDRV_PCM_TSTAMP_TYPE_MONOTONIC)
  846. do_posix_clock_monotonic_gettime(tv);
  847. else
  848. getnstimeofday(tv);
  849. }
  850. /*
  851. * Memory
  852. */
  853. int snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream);
  854. int snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm);
  855. int snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
  856. int type, struct device *data,
  857. size_t size, size_t max);
  858. int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
  859. int type, void *data,
  860. size_t size, size_t max);
  861. int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size);
  862. int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream);
  863. /*
  864. * SG-buffer handling
  865. */
  866. #define snd_pcm_substream_sgbuf(substream) \
  867. ((substream)->runtime->dma_buffer_p->private_data)
  868. static inline dma_addr_t
  869. snd_pcm_sgbuf_get_addr(struct snd_pcm_substream *substream, unsigned int ofs)
  870. {
  871. struct snd_sg_buf *sg = snd_pcm_substream_sgbuf(substream);
  872. return snd_sgbuf_get_addr(sg, ofs);
  873. }
  874. static inline void *
  875. snd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs)
  876. {
  877. struct snd_sg_buf *sg = snd_pcm_substream_sgbuf(substream);
  878. return snd_sgbuf_get_ptr(sg, ofs);
  879. }
  880. struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream,
  881. unsigned long offset);
  882. unsigned int snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream,
  883. unsigned int ofs, unsigned int size);
  884. /* handle mmap counter - PCM mmap callback should handle this counter properly */
  885. static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area)
  886. {
  887. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  888. atomic_inc(&substream->mmap_count);
  889. }
  890. static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area)
  891. {
  892. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  893. atomic_dec(&substream->mmap_count);
  894. }
  895. /* mmap for io-memory area */
  896. #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
  897. #define SNDRV_PCM_INFO_MMAP_IOMEM SNDRV_PCM_INFO_MMAP
  898. int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, struct vm_area_struct *area);
  899. #else
  900. #define SNDRV_PCM_INFO_MMAP_IOMEM 0
  901. #define snd_pcm_lib_mmap_iomem NULL
  902. #endif
  903. static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
  904. {
  905. *max = dma < 4 ? 64 * 1024 : 128 * 1024;
  906. }
  907. /*
  908. * Misc
  909. */
  910. #define SNDRV_PCM_DEFAULT_CON_SPDIF (IEC958_AES0_CON_EMPHASIS_NONE|\
  911. (IEC958_AES1_CON_ORIGINAL<<8)|\
  912. (IEC958_AES1_CON_PCM_CODER<<8)|\
  913. (IEC958_AES3_CON_FS_48000<<24))
  914. #define PCM_RUNTIME_CHECK(sub) snd_BUG_ON(!(sub) || !(sub)->runtime)
  915. #endif /* __SOUND_PCM_H */