pcm.h 37 KB

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