pcm.h 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013
  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. struct snd_pcm_file *file;
  327. struct file *ffile;
  328. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  329. /* -- OSS things -- */
  330. struct snd_pcm_oss_substream oss;
  331. #endif
  332. struct snd_info_entry *proc_root;
  333. struct snd_info_entry *proc_info_entry;
  334. struct snd_info_entry *proc_hw_params_entry;
  335. struct snd_info_entry *proc_sw_params_entry;
  336. struct snd_info_entry *proc_status_entry;
  337. struct snd_info_entry *proc_prealloc_entry;
  338. /* misc flags */
  339. unsigned int no_mmap_ctrl: 1;
  340. };
  341. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  342. #define SUBSTREAM_BUSY(substream) ((substream)->file != NULL || ((substream)->oss.file != NULL))
  343. #else
  344. #define SUBSTREAM_BUSY(substream) ((substream)->file != NULL)
  345. #endif
  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. struct snd_minor *reg;
  359. struct snd_info_entry *proc_root;
  360. struct snd_info_entry *proc_info_entry;
  361. #ifdef CONFIG_SND_DEBUG
  362. unsigned int xrun_debug; /* 0 = disabled, 1 = verbose, 2 = stacktrace */
  363. struct snd_info_entry *proc_xrun_debug_entry;
  364. #endif
  365. };
  366. struct snd_pcm {
  367. struct snd_card *card;
  368. unsigned int device; /* device number */
  369. unsigned int info_flags;
  370. unsigned short dev_class;
  371. unsigned short dev_subclass;
  372. char id[64];
  373. char name[80];
  374. struct snd_pcm_str streams[2];
  375. struct semaphore open_mutex;
  376. wait_queue_head_t open_wait;
  377. void *private_data;
  378. void (*private_free) (struct snd_pcm *pcm);
  379. #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
  380. struct snd_pcm_oss oss;
  381. #endif
  382. };
  383. struct snd_pcm_notify {
  384. int (*n_register) (struct snd_pcm * pcm);
  385. int (*n_disconnect) (struct snd_pcm * pcm);
  386. int (*n_unregister) (struct snd_pcm * pcm);
  387. struct list_head list;
  388. };
  389. /*
  390. * Registering
  391. */
  392. extern struct snd_pcm *snd_pcm_devices[];
  393. extern struct snd_minor snd_pcm_reg[2];
  394. int snd_pcm_new(struct snd_card *card, char *id, int device,
  395. int playback_count, int capture_count,
  396. struct snd_pcm **rpcm);
  397. int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count);
  398. int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree);
  399. /*
  400. * Native I/O
  401. */
  402. extern rwlock_t snd_pcm_link_rwlock;
  403. int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info);
  404. int snd_pcm_info_user(struct snd_pcm_substream *substream,
  405. struct snd_pcm_info __user *info);
  406. int snd_pcm_status(struct snd_pcm_substream *substream,
  407. struct snd_pcm_status *status);
  408. int snd_pcm_prepare(struct snd_pcm_substream *substream);
  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_playback_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
  417. int snd_pcm_kernel_capture_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
  418. int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
  419. int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct snd_pcm_substream **rsubstream);
  420. void snd_pcm_release_substream(struct snd_pcm_substream *substream);
  421. void snd_pcm_vma_notify_data(void *client, void *data);
  422. int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area);
  423. #if BITS_PER_LONG >= 64
  424. static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
  425. {
  426. *rem = *n % div;
  427. *n /= div;
  428. }
  429. #elif defined(i386)
  430. static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
  431. {
  432. u_int32_t low, high;
  433. low = *n & 0xffffffff;
  434. high = *n >> 32;
  435. if (high) {
  436. u_int32_t high1 = high % div;
  437. high /= div;
  438. asm("divl %2":"=a" (low), "=d" (*rem):"rm" (div), "a" (low), "d" (high1));
  439. *n = (u_int64_t)high << 32 | low;
  440. } else {
  441. *n = low / div;
  442. *rem = low % div;
  443. }
  444. }
  445. #else
  446. static inline void divl(u_int32_t high, u_int32_t low,
  447. u_int32_t div,
  448. u_int32_t *q, u_int32_t *r)
  449. {
  450. u_int64_t n = (u_int64_t)high << 32 | low;
  451. u_int64_t d = (u_int64_t)div << 31;
  452. u_int32_t q1 = 0;
  453. int c = 32;
  454. while (n > 0xffffffffU) {
  455. q1 <<= 1;
  456. if (n >= d) {
  457. n -= d;
  458. q1 |= 1;
  459. }
  460. d >>= 1;
  461. c--;
  462. }
  463. q1 <<= c;
  464. if (n) {
  465. low = n;
  466. *q = q1 | (low / div);
  467. *r = low % div;
  468. } else {
  469. *r = 0;
  470. *q = q1;
  471. }
  472. return;
  473. }
  474. static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
  475. {
  476. u_int32_t low, high;
  477. low = *n & 0xffffffff;
  478. high = *n >> 32;
  479. if (high) {
  480. u_int32_t high1 = high % div;
  481. u_int32_t low1 = low;
  482. high /= div;
  483. divl(high1, low1, div, &low, rem);
  484. *n = (u_int64_t)high << 32 | low;
  485. } else {
  486. *n = low / div;
  487. *rem = low % div;
  488. }
  489. }
  490. #endif
  491. /*
  492. * PCM library
  493. */
  494. static inline int snd_pcm_stream_linked(struct snd_pcm_substream *substream)
  495. {
  496. return substream->group != &substream->self_group;
  497. }
  498. static inline void snd_pcm_stream_lock(struct snd_pcm_substream *substream)
  499. {
  500. read_lock(&snd_pcm_link_rwlock);
  501. spin_lock(&substream->self_group.lock);
  502. }
  503. static inline void snd_pcm_stream_unlock(struct snd_pcm_substream *substream)
  504. {
  505. spin_unlock(&substream->self_group.lock);
  506. read_unlock(&snd_pcm_link_rwlock);
  507. }
  508. static inline void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream)
  509. {
  510. read_lock_irq(&snd_pcm_link_rwlock);
  511. spin_lock(&substream->self_group.lock);
  512. }
  513. static inline void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream)
  514. {
  515. spin_unlock(&substream->self_group.lock);
  516. read_unlock_irq(&snd_pcm_link_rwlock);
  517. }
  518. #define snd_pcm_stream_lock_irqsave(substream, flags) \
  519. do { \
  520. read_lock_irqsave(&snd_pcm_link_rwlock, (flags)); \
  521. spin_lock(&substream->self_group.lock); \
  522. } while (0)
  523. #define snd_pcm_stream_unlock_irqrestore(substream, flags) \
  524. do { \
  525. spin_unlock(&substream->self_group.lock); \
  526. read_unlock_irqrestore(&snd_pcm_link_rwlock, (flags)); \
  527. } while (0)
  528. #define snd_pcm_group_for_each(pos, substream) \
  529. list_for_each(pos, &substream->group->substreams)
  530. #define snd_pcm_group_substream_entry(pos) \
  531. list_entry(pos, struct snd_pcm_substream, link_list)
  532. static inline int snd_pcm_running(struct snd_pcm_substream *substream)
  533. {
  534. return (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING ||
  535. (substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
  536. substream->stream == SNDRV_PCM_STREAM_PLAYBACK));
  537. }
  538. static inline ssize_t bytes_to_samples(struct snd_pcm_runtime *runtime, ssize_t size)
  539. {
  540. return size * 8 / runtime->sample_bits;
  541. }
  542. static inline snd_pcm_sframes_t bytes_to_frames(struct snd_pcm_runtime *runtime, ssize_t size)
  543. {
  544. return size * 8 / runtime->frame_bits;
  545. }
  546. static inline ssize_t samples_to_bytes(struct snd_pcm_runtime *runtime, ssize_t size)
  547. {
  548. return size * runtime->sample_bits / 8;
  549. }
  550. static inline ssize_t frames_to_bytes(struct snd_pcm_runtime *runtime, snd_pcm_sframes_t size)
  551. {
  552. return size * runtime->frame_bits / 8;
  553. }
  554. static inline int frame_aligned(struct snd_pcm_runtime *runtime, ssize_t bytes)
  555. {
  556. return bytes % runtime->byte_align == 0;
  557. }
  558. static inline size_t snd_pcm_lib_buffer_bytes(struct snd_pcm_substream *substream)
  559. {
  560. struct snd_pcm_runtime *runtime = substream->runtime;
  561. return frames_to_bytes(runtime, runtime->buffer_size);
  562. }
  563. static inline size_t snd_pcm_lib_period_bytes(struct snd_pcm_substream *substream)
  564. {
  565. struct snd_pcm_runtime *runtime = substream->runtime;
  566. return frames_to_bytes(runtime, runtime->period_size);
  567. }
  568. /*
  569. * result is: 0 ... (boundary - 1)
  570. */
  571. static inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *runtime)
  572. {
  573. snd_pcm_sframes_t avail = runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_ptr;
  574. if (avail < 0)
  575. avail += runtime->boundary;
  576. else if ((snd_pcm_uframes_t) avail >= runtime->boundary)
  577. avail -= runtime->boundary;
  578. return avail;
  579. }
  580. /*
  581. * result is: 0 ... (boundary - 1)
  582. */
  583. static inline snd_pcm_uframes_t snd_pcm_capture_avail(struct snd_pcm_runtime *runtime)
  584. {
  585. snd_pcm_sframes_t avail = runtime->status->hw_ptr - runtime->control->appl_ptr;
  586. if (avail < 0)
  587. avail += runtime->boundary;
  588. return avail;
  589. }
  590. static inline snd_pcm_sframes_t snd_pcm_playback_hw_avail(struct snd_pcm_runtime *runtime)
  591. {
  592. return runtime->buffer_size - snd_pcm_playback_avail(runtime);
  593. }
  594. static inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(struct snd_pcm_runtime *runtime)
  595. {
  596. return runtime->buffer_size - snd_pcm_capture_avail(runtime);
  597. }
  598. /**
  599. * snd_pcm_playback_ready - check whether the playback buffer is available
  600. * @substream: the pcm substream instance
  601. *
  602. * Checks whether enough free space is available on the playback buffer.
  603. *
  604. * Returns non-zero if available, or zero if not.
  605. */
  606. static inline int snd_pcm_playback_ready(struct snd_pcm_substream *substream)
  607. {
  608. struct snd_pcm_runtime *runtime = substream->runtime;
  609. return snd_pcm_playback_avail(runtime) >= runtime->control->avail_min;
  610. }
  611. /**
  612. * snd_pcm_capture_ready - check whether the capture buffer is available
  613. * @substream: the pcm substream instance
  614. *
  615. * Checks whether enough capture data is available on the capture buffer.
  616. *
  617. * Returns non-zero if available, or zero if not.
  618. */
  619. static inline int snd_pcm_capture_ready(struct snd_pcm_substream *substream)
  620. {
  621. struct snd_pcm_runtime *runtime = substream->runtime;
  622. return snd_pcm_capture_avail(runtime) >= runtime->control->avail_min;
  623. }
  624. /**
  625. * snd_pcm_playback_data - check whether any data exists on the playback buffer
  626. * @substream: the pcm substream instance
  627. *
  628. * Checks whether any data exists on the playback buffer. If stop_threshold
  629. * is bigger or equal to boundary, then this function returns always non-zero.
  630. *
  631. * Returns non-zero if exists, or zero if not.
  632. */
  633. static inline int snd_pcm_playback_data(struct snd_pcm_substream *substream)
  634. {
  635. struct snd_pcm_runtime *runtime = substream->runtime;
  636. if (runtime->stop_threshold >= runtime->boundary)
  637. return 1;
  638. return snd_pcm_playback_avail(runtime) < runtime->buffer_size;
  639. }
  640. /**
  641. * snd_pcm_playback_empty - check whether the playback buffer is empty
  642. * @substream: the pcm substream instance
  643. *
  644. * Checks whether the playback buffer is empty.
  645. *
  646. * Returns non-zero if empty, or zero if not.
  647. */
  648. static inline int snd_pcm_playback_empty(struct snd_pcm_substream *substream)
  649. {
  650. struct snd_pcm_runtime *runtime = substream->runtime;
  651. return snd_pcm_playback_avail(runtime) >= runtime->buffer_size;
  652. }
  653. /**
  654. * snd_pcm_capture_empty - check whether the capture buffer is empty
  655. * @substream: the pcm substream instance
  656. *
  657. * Checks whether the capture buffer is empty.
  658. *
  659. * Returns non-zero if empty, or zero if not.
  660. */
  661. static inline int snd_pcm_capture_empty(struct snd_pcm_substream *substream)
  662. {
  663. struct snd_pcm_runtime *runtime = substream->runtime;
  664. return snd_pcm_capture_avail(runtime) == 0;
  665. }
  666. static inline void snd_pcm_trigger_done(struct snd_pcm_substream *substream,
  667. struct snd_pcm_substream *master)
  668. {
  669. substream->runtime->trigger_master = master;
  670. }
  671. static inline int hw_is_mask(int var)
  672. {
  673. return var >= SNDRV_PCM_HW_PARAM_FIRST_MASK &&
  674. var <= SNDRV_PCM_HW_PARAM_LAST_MASK;
  675. }
  676. static inline int hw_is_interval(int var)
  677. {
  678. return var >= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL &&
  679. var <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL;
  680. }
  681. static inline struct snd_mask *hw_param_mask(struct snd_pcm_hw_params *params,
  682. snd_pcm_hw_param_t var)
  683. {
  684. return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  685. }
  686. static inline struct snd_interval *hw_param_interval(struct snd_pcm_hw_params *params,
  687. snd_pcm_hw_param_t var)
  688. {
  689. return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  690. }
  691. static inline const struct snd_mask *hw_param_mask_c(const struct snd_pcm_hw_params *params,
  692. snd_pcm_hw_param_t var)
  693. {
  694. return (const struct snd_mask *)hw_param_mask((struct snd_pcm_hw_params*) params, var);
  695. }
  696. static inline const struct snd_interval *hw_param_interval_c(const struct snd_pcm_hw_params *params,
  697. snd_pcm_hw_param_t var)
  698. {
  699. return (const struct snd_interval *)hw_param_interval((struct snd_pcm_hw_params*) params, var);
  700. }
  701. #define params_access(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_ACCESS))
  702. #define params_format(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_FORMAT))
  703. #define params_subformat(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_SUBFORMAT))
  704. #define params_channels(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_CHANNELS)->min
  705. #define params_rate(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_RATE)->min
  706. #define params_period_size(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min
  707. #define params_period_bytes(p) ((params_period_size(p)*snd_pcm_format_physical_width(params_format(p))*params_channels(p))/8)
  708. #define params_periods(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_PERIODS)->min
  709. #define params_buffer_size(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min
  710. #define params_buffer_bytes(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min
  711. #define params_tick_time(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_TICK_TIME)->min
  712. int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v);
  713. void snd_interval_mul(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c);
  714. void snd_interval_div(const struct snd_interval *a, const struct snd_interval *b, struct snd_interval *c);
  715. void snd_interval_muldivk(const struct snd_interval *a, const struct snd_interval *b,
  716. unsigned int k, struct snd_interval *c);
  717. void snd_interval_mulkdiv(const struct snd_interval *a, unsigned int k,
  718. const struct snd_interval *b, struct snd_interval *c);
  719. int snd_interval_list(struct snd_interval *i, unsigned int count, unsigned int *list, unsigned int mask);
  720. int snd_interval_ratnum(struct snd_interval *i,
  721. unsigned int rats_count, struct snd_ratnum *rats,
  722. unsigned int *nump, unsigned int *denp);
  723. void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params);
  724. void _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var);
  725. int snd_pcm_hw_param_near(struct snd_pcm_substream *substream,
  726. struct snd_pcm_hw_params *params,
  727. snd_pcm_hw_param_t var,
  728. unsigned int val, int *dir);
  729. int snd_pcm_hw_param_set(struct snd_pcm_substream *pcm,
  730. struct snd_pcm_hw_params *params,
  731. snd_pcm_hw_param_t var,
  732. unsigned int val, int dir);
  733. int snd_pcm_hw_params_choose(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
  734. int snd_pcm_hw_refine(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
  735. int snd_pcm_hw_constraints_init(struct snd_pcm_substream *substream);
  736. int snd_pcm_hw_constraints_complete(struct snd_pcm_substream *substream);
  737. int snd_pcm_hw_constraint_mask(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  738. u_int32_t mask);
  739. int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  740. u_int64_t mask);
  741. int snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  742. unsigned int min, unsigned int max);
  743. int snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var);
  744. int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime,
  745. unsigned int cond,
  746. snd_pcm_hw_param_t var,
  747. struct snd_pcm_hw_constraint_list *l);
  748. int snd_pcm_hw_constraint_ratnums(struct snd_pcm_runtime *runtime,
  749. unsigned int cond,
  750. snd_pcm_hw_param_t var,
  751. struct snd_pcm_hw_constraint_ratnums *r);
  752. int snd_pcm_hw_constraint_ratdens(struct snd_pcm_runtime *runtime,
  753. unsigned int cond,
  754. snd_pcm_hw_param_t var,
  755. struct snd_pcm_hw_constraint_ratdens *r);
  756. int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime,
  757. unsigned int cond,
  758. unsigned int width,
  759. unsigned int msbits);
  760. int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
  761. unsigned int cond,
  762. snd_pcm_hw_param_t var,
  763. unsigned long step);
  764. int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
  765. unsigned int cond,
  766. snd_pcm_hw_param_t var);
  767. int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime,
  768. unsigned int cond,
  769. int var,
  770. snd_pcm_hw_rule_func_t func, void *private,
  771. int dep, ...);
  772. int snd_pcm_format_signed(snd_pcm_format_t format);
  773. int snd_pcm_format_unsigned(snd_pcm_format_t format);
  774. int snd_pcm_format_linear(snd_pcm_format_t format);
  775. int snd_pcm_format_little_endian(snd_pcm_format_t format);
  776. int snd_pcm_format_big_endian(snd_pcm_format_t format);
  777. #if 0 /* just for DocBook */
  778. /**
  779. * snd_pcm_format_cpu_endian - Check the PCM format is CPU-endian
  780. * @format: the format to check
  781. *
  782. * Returns 1 if the given PCM format is CPU-endian, 0 if
  783. * opposite, or a negative error code if endian not specified.
  784. */
  785. int snd_pcm_format_cpu_endian(snd_pcm_format_t format);
  786. #endif /* DocBook */
  787. #ifdef SNDRV_LITTLE_ENDIAN
  788. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_little_endian(format)
  789. #else
  790. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_big_endian(format)
  791. #endif
  792. int snd_pcm_format_width(snd_pcm_format_t format); /* in bits */
  793. int snd_pcm_format_physical_width(snd_pcm_format_t format); /* in bits */
  794. ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
  795. const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format);
  796. int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
  797. snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsignd, int big_endian);
  798. const char *snd_pcm_format_name(snd_pcm_format_t format);
  799. void snd_pcm_set_ops(struct snd_pcm * pcm, int direction, struct snd_pcm_ops *ops);
  800. void snd_pcm_set_sync(struct snd_pcm_substream *substream);
  801. int snd_pcm_lib_interleave_len(struct snd_pcm_substream *substream);
  802. int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  803. unsigned int cmd, void *arg);
  804. int snd_pcm_update_hw_ptr(struct snd_pcm_substream *substream);
  805. int snd_pcm_playback_xrun_check(struct snd_pcm_substream *substream);
  806. int snd_pcm_capture_xrun_check(struct snd_pcm_substream *substream);
  807. int snd_pcm_playback_xrun_asap(struct snd_pcm_substream *substream);
  808. int snd_pcm_capture_xrun_asap(struct snd_pcm_substream *substream);
  809. void snd_pcm_playback_silence(struct snd_pcm_substream *substream, snd_pcm_uframes_t new_hw_ptr);
  810. void snd_pcm_tick_prepare(struct snd_pcm_substream *substream);
  811. void snd_pcm_tick_set(struct snd_pcm_substream *substream, unsigned long ticks);
  812. void snd_pcm_tick_elapsed(struct snd_pcm_substream *substream);
  813. void snd_pcm_period_elapsed(struct snd_pcm_substream *substream);
  814. snd_pcm_sframes_t snd_pcm_lib_write(struct snd_pcm_substream *substream,
  815. const void __user *buf,
  816. snd_pcm_uframes_t frames);
  817. snd_pcm_sframes_t snd_pcm_lib_read(struct snd_pcm_substream *substream,
  818. void __user *buf, snd_pcm_uframes_t frames);
  819. snd_pcm_sframes_t snd_pcm_lib_writev(struct snd_pcm_substream *substream,
  820. void __user **bufs, snd_pcm_uframes_t frames);
  821. snd_pcm_sframes_t snd_pcm_lib_readv(struct snd_pcm_substream *substream,
  822. void __user **bufs, snd_pcm_uframes_t frames);
  823. int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime);
  824. static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substream,
  825. struct snd_dma_buffer *bufp)
  826. {
  827. struct snd_pcm_runtime *runtime = substream->runtime;
  828. if (bufp) {
  829. runtime->dma_buffer_p = bufp;
  830. runtime->dma_area = bufp->area;
  831. runtime->dma_addr = bufp->addr;
  832. runtime->dma_bytes = bufp->bytes;
  833. } else {
  834. runtime->dma_buffer_p = NULL;
  835. runtime->dma_area = NULL;
  836. runtime->dma_addr = 0;
  837. runtime->dma_bytes = 0;
  838. }
  839. }
  840. /*
  841. * Timer interface
  842. */
  843. void snd_pcm_timer_resolution_change(struct snd_pcm_substream *substream);
  844. void snd_pcm_timer_init(struct snd_pcm_substream *substream);
  845. void snd_pcm_timer_done(struct snd_pcm_substream *substream);
  846. /*
  847. * Memory
  848. */
  849. int snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream);
  850. int snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm);
  851. int snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
  852. int type, struct device *data,
  853. size_t size, size_t max);
  854. int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
  855. int type, void *data,
  856. size_t size, size_t max);
  857. int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size);
  858. int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream);
  859. #define snd_pcm_substream_sgbuf(substream) ((substream)->runtime->dma_buffer_p->private_data)
  860. #define snd_pcm_sgbuf_pages(size) snd_sgbuf_aligned_pages(size)
  861. #define snd_pcm_sgbuf_get_addr(sgbuf,ofs) snd_sgbuf_get_addr(sgbuf,ofs)
  862. struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream, unsigned long offset);
  863. /* handle mmap counter - PCM mmap callback should handle this counter properly */
  864. static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area)
  865. {
  866. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  867. atomic_inc(&substream->runtime->mmap_count);
  868. }
  869. static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area)
  870. {
  871. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  872. atomic_dec(&substream->runtime->mmap_count);
  873. }
  874. /* mmap for io-memory area */
  875. #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
  876. #define SNDRV_PCM_INFO_MMAP_IOMEM SNDRV_PCM_INFO_MMAP
  877. int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, struct vm_area_struct *area);
  878. #else
  879. #define SNDRV_PCM_INFO_MMAP_IOMEM 0
  880. #define snd_pcm_lib_mmap_iomem NULL
  881. #endif
  882. static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
  883. {
  884. *max = dma < 4 ? 64 * 1024 : 128 * 1024;
  885. }
  886. /*
  887. * Misc
  888. */
  889. #define SNDRV_PCM_DEFAULT_CON_SPDIF (IEC958_AES0_CON_EMPHASIS_NONE|\
  890. (IEC958_AES1_CON_ORIGINAL<<8)|\
  891. (IEC958_AES1_CON_PCM_CODER<<8)|\
  892. (IEC958_AES3_CON_FS_48000<<24))
  893. #endif /* __SOUND_PCM_H */