pcm.h 36 KB

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