pcm.h 35 KB

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