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