pcm.h 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451
  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.h>
  31. #define snd_pcm_substream_chip(substream) ((substream)->private_data)
  32. #define snd_pcm_chip(pcm) ((pcm)->private_data)
  33. #if IS_ENABLED(CONFIG_SND_PCM_OSS)
  34. #include <sound/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_audio_tstamp_config; /* definitions further down */
  56. struct snd_pcm_audio_tstamp_report;
  57. struct snd_pcm_ops {
  58. int (*open)(struct snd_pcm_substream *substream);
  59. int (*close)(struct snd_pcm_substream *substream);
  60. int (*ioctl)(struct snd_pcm_substream * substream,
  61. unsigned int cmd, void *arg);
  62. int (*hw_params)(struct snd_pcm_substream *substream,
  63. struct snd_pcm_hw_params *params);
  64. int (*hw_free)(struct snd_pcm_substream *substream);
  65. int (*prepare)(struct snd_pcm_substream *substream);
  66. int (*trigger)(struct snd_pcm_substream *substream, int cmd);
  67. snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream);
  68. int (*get_time_info)(struct snd_pcm_substream *substream,
  69. struct timespec *system_ts, struct timespec *audio_ts,
  70. struct snd_pcm_audio_tstamp_config *audio_tstamp_config,
  71. struct snd_pcm_audio_tstamp_report *audio_tstamp_report);
  72. int (*fill_silence)(struct snd_pcm_substream *substream, int channel,
  73. unsigned long pos, unsigned long bytes);
  74. int (*copy_user)(struct snd_pcm_substream *substream, int channel,
  75. unsigned long pos, void __user *buf,
  76. unsigned long bytes);
  77. int (*copy_kernel)(struct snd_pcm_substream *substream, int channel,
  78. unsigned long pos, void *buf, unsigned long bytes);
  79. struct page *(*page)(struct snd_pcm_substream *substream,
  80. unsigned long offset);
  81. int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
  82. int (*ack)(struct snd_pcm_substream *substream);
  83. };
  84. /*
  85. *
  86. */
  87. #if defined(CONFIG_SND_DYNAMIC_MINORS)
  88. #define SNDRV_PCM_DEVICES (SNDRV_OS_MINORS-2)
  89. #else
  90. #define SNDRV_PCM_DEVICES 8
  91. #endif
  92. #define SNDRV_PCM_IOCTL1_RESET 0
  93. /* 1 is absent slot. */
  94. #define SNDRV_PCM_IOCTL1_CHANNEL_INFO 2
  95. /* 3 is absent slot. */
  96. #define SNDRV_PCM_IOCTL1_FIFO_SIZE 4
  97. #define SNDRV_PCM_TRIGGER_STOP 0
  98. #define SNDRV_PCM_TRIGGER_START 1
  99. #define SNDRV_PCM_TRIGGER_PAUSE_PUSH 3
  100. #define SNDRV_PCM_TRIGGER_PAUSE_RELEASE 4
  101. #define SNDRV_PCM_TRIGGER_SUSPEND 5
  102. #define SNDRV_PCM_TRIGGER_RESUME 6
  103. #define SNDRV_PCM_TRIGGER_DRAIN 7
  104. #define SNDRV_PCM_POS_XRUN ((snd_pcm_uframes_t)-1)
  105. /* If you change this don't forget to change rates[] table in pcm_native.c */
  106. #define SNDRV_PCM_RATE_5512 (1<<0) /* 5512Hz */
  107. #define SNDRV_PCM_RATE_8000 (1<<1) /* 8000Hz */
  108. #define SNDRV_PCM_RATE_11025 (1<<2) /* 11025Hz */
  109. #define SNDRV_PCM_RATE_16000 (1<<3) /* 16000Hz */
  110. #define SNDRV_PCM_RATE_22050 (1<<4) /* 22050Hz */
  111. #define SNDRV_PCM_RATE_32000 (1<<5) /* 32000Hz */
  112. #define SNDRV_PCM_RATE_44100 (1<<6) /* 44100Hz */
  113. #define SNDRV_PCM_RATE_48000 (1<<7) /* 48000Hz */
  114. #define SNDRV_PCM_RATE_64000 (1<<8) /* 64000Hz */
  115. #define SNDRV_PCM_RATE_88200 (1<<9) /* 88200Hz */
  116. #define SNDRV_PCM_RATE_96000 (1<<10) /* 96000Hz */
  117. #define SNDRV_PCM_RATE_176400 (1<<11) /* 176400Hz */
  118. #define SNDRV_PCM_RATE_192000 (1<<12) /* 192000Hz */
  119. #define SNDRV_PCM_RATE_CONTINUOUS (1<<30) /* continuous range */
  120. #define SNDRV_PCM_RATE_KNOT (1<<31) /* supports more non-continuos rates */
  121. #define SNDRV_PCM_RATE_8000_44100 (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_11025|\
  122. SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_22050|\
  123. SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100)
  124. #define SNDRV_PCM_RATE_8000_48000 (SNDRV_PCM_RATE_8000_44100|SNDRV_PCM_RATE_48000)
  125. #define SNDRV_PCM_RATE_8000_96000 (SNDRV_PCM_RATE_8000_48000|SNDRV_PCM_RATE_64000|\
  126. SNDRV_PCM_RATE_88200|SNDRV_PCM_RATE_96000)
  127. #define SNDRV_PCM_RATE_8000_192000 (SNDRV_PCM_RATE_8000_96000|SNDRV_PCM_RATE_176400|\
  128. SNDRV_PCM_RATE_192000)
  129. #define _SNDRV_PCM_FMTBIT(fmt) (1ULL << (__force int)SNDRV_PCM_FORMAT_##fmt)
  130. #define SNDRV_PCM_FMTBIT_S8 _SNDRV_PCM_FMTBIT(S8)
  131. #define SNDRV_PCM_FMTBIT_U8 _SNDRV_PCM_FMTBIT(U8)
  132. #define SNDRV_PCM_FMTBIT_S16_LE _SNDRV_PCM_FMTBIT(S16_LE)
  133. #define SNDRV_PCM_FMTBIT_S16_BE _SNDRV_PCM_FMTBIT(S16_BE)
  134. #define SNDRV_PCM_FMTBIT_U16_LE _SNDRV_PCM_FMTBIT(U16_LE)
  135. #define SNDRV_PCM_FMTBIT_U16_BE _SNDRV_PCM_FMTBIT(U16_BE)
  136. #define SNDRV_PCM_FMTBIT_S24_LE _SNDRV_PCM_FMTBIT(S24_LE)
  137. #define SNDRV_PCM_FMTBIT_S24_BE _SNDRV_PCM_FMTBIT(S24_BE)
  138. #define SNDRV_PCM_FMTBIT_U24_LE _SNDRV_PCM_FMTBIT(U24_LE)
  139. #define SNDRV_PCM_FMTBIT_U24_BE _SNDRV_PCM_FMTBIT(U24_BE)
  140. #define SNDRV_PCM_FMTBIT_S32_LE _SNDRV_PCM_FMTBIT(S32_LE)
  141. #define SNDRV_PCM_FMTBIT_S32_BE _SNDRV_PCM_FMTBIT(S32_BE)
  142. #define SNDRV_PCM_FMTBIT_U32_LE _SNDRV_PCM_FMTBIT(U32_LE)
  143. #define SNDRV_PCM_FMTBIT_U32_BE _SNDRV_PCM_FMTBIT(U32_BE)
  144. #define SNDRV_PCM_FMTBIT_FLOAT_LE _SNDRV_PCM_FMTBIT(FLOAT_LE)
  145. #define SNDRV_PCM_FMTBIT_FLOAT_BE _SNDRV_PCM_FMTBIT(FLOAT_BE)
  146. #define SNDRV_PCM_FMTBIT_FLOAT64_LE _SNDRV_PCM_FMTBIT(FLOAT64_LE)
  147. #define SNDRV_PCM_FMTBIT_FLOAT64_BE _SNDRV_PCM_FMTBIT(FLOAT64_BE)
  148. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE _SNDRV_PCM_FMTBIT(IEC958_SUBFRAME_LE)
  149. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE _SNDRV_PCM_FMTBIT(IEC958_SUBFRAME_BE)
  150. #define SNDRV_PCM_FMTBIT_MU_LAW _SNDRV_PCM_FMTBIT(MU_LAW)
  151. #define SNDRV_PCM_FMTBIT_A_LAW _SNDRV_PCM_FMTBIT(A_LAW)
  152. #define SNDRV_PCM_FMTBIT_IMA_ADPCM _SNDRV_PCM_FMTBIT(IMA_ADPCM)
  153. #define SNDRV_PCM_FMTBIT_MPEG _SNDRV_PCM_FMTBIT(MPEG)
  154. #define SNDRV_PCM_FMTBIT_GSM _SNDRV_PCM_FMTBIT(GSM)
  155. #define SNDRV_PCM_FMTBIT_S20_LE _SNDRV_PCM_FMTBIT(S20_LE)
  156. #define SNDRV_PCM_FMTBIT_U20_LE _SNDRV_PCM_FMTBIT(U20_LE)
  157. #define SNDRV_PCM_FMTBIT_S20_BE _SNDRV_PCM_FMTBIT(S20_BE)
  158. #define SNDRV_PCM_FMTBIT_U20_BE _SNDRV_PCM_FMTBIT(U20_BE)
  159. #define SNDRV_PCM_FMTBIT_SPECIAL _SNDRV_PCM_FMTBIT(SPECIAL)
  160. #define SNDRV_PCM_FMTBIT_S24_3LE _SNDRV_PCM_FMTBIT(S24_3LE)
  161. #define SNDRV_PCM_FMTBIT_U24_3LE _SNDRV_PCM_FMTBIT(U24_3LE)
  162. #define SNDRV_PCM_FMTBIT_S24_3BE _SNDRV_PCM_FMTBIT(S24_3BE)
  163. #define SNDRV_PCM_FMTBIT_U24_3BE _SNDRV_PCM_FMTBIT(U24_3BE)
  164. #define SNDRV_PCM_FMTBIT_S20_3LE _SNDRV_PCM_FMTBIT(S20_3LE)
  165. #define SNDRV_PCM_FMTBIT_U20_3LE _SNDRV_PCM_FMTBIT(U20_3LE)
  166. #define SNDRV_PCM_FMTBIT_S20_3BE _SNDRV_PCM_FMTBIT(S20_3BE)
  167. #define SNDRV_PCM_FMTBIT_U20_3BE _SNDRV_PCM_FMTBIT(U20_3BE)
  168. #define SNDRV_PCM_FMTBIT_S18_3LE _SNDRV_PCM_FMTBIT(S18_3LE)
  169. #define SNDRV_PCM_FMTBIT_U18_3LE _SNDRV_PCM_FMTBIT(U18_3LE)
  170. #define SNDRV_PCM_FMTBIT_S18_3BE _SNDRV_PCM_FMTBIT(S18_3BE)
  171. #define SNDRV_PCM_FMTBIT_U18_3BE _SNDRV_PCM_FMTBIT(U18_3BE)
  172. #define SNDRV_PCM_FMTBIT_G723_24 _SNDRV_PCM_FMTBIT(G723_24)
  173. #define SNDRV_PCM_FMTBIT_G723_24_1B _SNDRV_PCM_FMTBIT(G723_24_1B)
  174. #define SNDRV_PCM_FMTBIT_G723_40 _SNDRV_PCM_FMTBIT(G723_40)
  175. #define SNDRV_PCM_FMTBIT_G723_40_1B _SNDRV_PCM_FMTBIT(G723_40_1B)
  176. #define SNDRV_PCM_FMTBIT_DSD_U8 _SNDRV_PCM_FMTBIT(DSD_U8)
  177. #define SNDRV_PCM_FMTBIT_DSD_U16_LE _SNDRV_PCM_FMTBIT(DSD_U16_LE)
  178. #define SNDRV_PCM_FMTBIT_DSD_U32_LE _SNDRV_PCM_FMTBIT(DSD_U32_LE)
  179. #define SNDRV_PCM_FMTBIT_DSD_U16_BE _SNDRV_PCM_FMTBIT(DSD_U16_BE)
  180. #define SNDRV_PCM_FMTBIT_DSD_U32_BE _SNDRV_PCM_FMTBIT(DSD_U32_BE)
  181. #ifdef SNDRV_LITTLE_ENDIAN
  182. #define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_LE
  183. #define SNDRV_PCM_FMTBIT_U16 SNDRV_PCM_FMTBIT_U16_LE
  184. #define SNDRV_PCM_FMTBIT_S24 SNDRV_PCM_FMTBIT_S24_LE
  185. #define SNDRV_PCM_FMTBIT_U24 SNDRV_PCM_FMTBIT_U24_LE
  186. #define SNDRV_PCM_FMTBIT_S32 SNDRV_PCM_FMTBIT_S32_LE
  187. #define SNDRV_PCM_FMTBIT_U32 SNDRV_PCM_FMTBIT_U32_LE
  188. #define SNDRV_PCM_FMTBIT_FLOAT SNDRV_PCM_FMTBIT_FLOAT_LE
  189. #define SNDRV_PCM_FMTBIT_FLOAT64 SNDRV_PCM_FMTBIT_FLOAT64_LE
  190. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
  191. #define SNDRV_PCM_FMTBIT_S20 SNDRV_PCM_FMTBIT_S20_LE
  192. #define SNDRV_PCM_FMTBIT_U20 SNDRV_PCM_FMTBIT_U20_LE
  193. #endif
  194. #ifdef SNDRV_BIG_ENDIAN
  195. #define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_BE
  196. #define SNDRV_PCM_FMTBIT_U16 SNDRV_PCM_FMTBIT_U16_BE
  197. #define SNDRV_PCM_FMTBIT_S24 SNDRV_PCM_FMTBIT_S24_BE
  198. #define SNDRV_PCM_FMTBIT_U24 SNDRV_PCM_FMTBIT_U24_BE
  199. #define SNDRV_PCM_FMTBIT_S32 SNDRV_PCM_FMTBIT_S32_BE
  200. #define SNDRV_PCM_FMTBIT_U32 SNDRV_PCM_FMTBIT_U32_BE
  201. #define SNDRV_PCM_FMTBIT_FLOAT SNDRV_PCM_FMTBIT_FLOAT_BE
  202. #define SNDRV_PCM_FMTBIT_FLOAT64 SNDRV_PCM_FMTBIT_FLOAT64_BE
  203. #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE
  204. #define SNDRV_PCM_FMTBIT_S20 SNDRV_PCM_FMTBIT_S20_BE
  205. #define SNDRV_PCM_FMTBIT_U20 SNDRV_PCM_FMTBIT_U20_BE
  206. #endif
  207. struct snd_pcm_file {
  208. struct snd_pcm_substream *substream;
  209. int no_compat_mmap;
  210. unsigned int user_pversion; /* supported protocol version */
  211. };
  212. struct snd_pcm_hw_rule;
  213. typedef int (*snd_pcm_hw_rule_func_t)(struct snd_pcm_hw_params *params,
  214. struct snd_pcm_hw_rule *rule);
  215. struct snd_pcm_hw_rule {
  216. unsigned int cond;
  217. int var;
  218. int deps[4];
  219. snd_pcm_hw_rule_func_t func;
  220. void *private;
  221. };
  222. struct snd_pcm_hw_constraints {
  223. struct snd_mask masks[SNDRV_PCM_HW_PARAM_LAST_MASK -
  224. SNDRV_PCM_HW_PARAM_FIRST_MASK + 1];
  225. struct snd_interval intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL -
  226. SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1];
  227. unsigned int rules_num;
  228. unsigned int rules_all;
  229. struct snd_pcm_hw_rule *rules;
  230. };
  231. static inline struct snd_mask *constrs_mask(struct snd_pcm_hw_constraints *constrs,
  232. snd_pcm_hw_param_t var)
  233. {
  234. return &constrs->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  235. }
  236. static inline struct snd_interval *constrs_interval(struct snd_pcm_hw_constraints *constrs,
  237. snd_pcm_hw_param_t var)
  238. {
  239. return &constrs->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  240. }
  241. struct snd_ratnum {
  242. unsigned int num;
  243. unsigned int den_min, den_max, den_step;
  244. };
  245. struct snd_ratden {
  246. unsigned int num_min, num_max, num_step;
  247. unsigned int den;
  248. };
  249. struct snd_pcm_hw_constraint_ratnums {
  250. int nrats;
  251. const struct snd_ratnum *rats;
  252. };
  253. struct snd_pcm_hw_constraint_ratdens {
  254. int nrats;
  255. const struct snd_ratden *rats;
  256. };
  257. struct snd_pcm_hw_constraint_list {
  258. const unsigned int *list;
  259. unsigned int count;
  260. unsigned int mask;
  261. };
  262. struct snd_pcm_hw_constraint_ranges {
  263. unsigned int count;
  264. const struct snd_interval *ranges;
  265. unsigned int mask;
  266. };
  267. /*
  268. * userspace-provided audio timestamp config to kernel,
  269. * structure is for internal use only and filled with dedicated unpack routine
  270. */
  271. struct snd_pcm_audio_tstamp_config {
  272. /* 5 of max 16 bits used */
  273. u32 type_requested:4;
  274. u32 report_delay:1; /* add total delay to A/D or D/A */
  275. };
  276. static inline void snd_pcm_unpack_audio_tstamp_config(__u32 data,
  277. struct snd_pcm_audio_tstamp_config *config)
  278. {
  279. config->type_requested = data & 0xF;
  280. config->report_delay = (data >> 4) & 1;
  281. }
  282. /*
  283. * kernel-provided audio timestamp report to user-space
  284. * structure is for internal use only and read by dedicated pack routine
  285. */
  286. struct snd_pcm_audio_tstamp_report {
  287. /* 6 of max 16 bits used for bit-fields */
  288. /* for backwards compatibility */
  289. u32 valid:1;
  290. /* actual type if hardware could not support requested timestamp */
  291. u32 actual_type:4;
  292. /* accuracy represented in ns units */
  293. u32 accuracy_report:1; /* 0 if accuracy unknown, 1 if accuracy field is valid */
  294. u32 accuracy; /* up to 4.29s, will be packed in separate field */
  295. };
  296. static inline void snd_pcm_pack_audio_tstamp_report(__u32 *data, __u32 *accuracy,
  297. const struct snd_pcm_audio_tstamp_report *report)
  298. {
  299. u32 tmp;
  300. tmp = report->accuracy_report;
  301. tmp <<= 4;
  302. tmp |= report->actual_type;
  303. tmp <<= 1;
  304. tmp |= report->valid;
  305. *data &= 0xffff; /* zero-clear MSBs */
  306. *data |= (tmp << 16);
  307. *accuracy = report->accuracy;
  308. }
  309. struct snd_pcm_runtime {
  310. /* -- Status -- */
  311. struct snd_pcm_substream *trigger_master;
  312. struct timespec trigger_tstamp; /* trigger timestamp */
  313. bool trigger_tstamp_latched; /* trigger timestamp latched in low-level driver/hardware */
  314. int overrange;
  315. snd_pcm_uframes_t avail_max;
  316. snd_pcm_uframes_t hw_ptr_base; /* Position at buffer restart */
  317. snd_pcm_uframes_t hw_ptr_interrupt; /* Position at interrupt time */
  318. unsigned long hw_ptr_jiffies; /* Time when hw_ptr is updated */
  319. unsigned long hw_ptr_buffer_jiffies; /* buffer time in jiffies */
  320. snd_pcm_sframes_t delay; /* extra delay; typically FIFO size */
  321. u64 hw_ptr_wrap; /* offset for hw_ptr due to boundary wrap-around */
  322. /* -- HW params -- */
  323. snd_pcm_access_t access; /* access mode */
  324. snd_pcm_format_t format; /* SNDRV_PCM_FORMAT_* */
  325. snd_pcm_subformat_t subformat; /* subformat */
  326. unsigned int rate; /* rate in Hz */
  327. unsigned int channels; /* channels */
  328. snd_pcm_uframes_t period_size; /* period size */
  329. unsigned int periods; /* periods */
  330. snd_pcm_uframes_t buffer_size; /* buffer size */
  331. snd_pcm_uframes_t min_align; /* Min alignment for the format */
  332. size_t byte_align;
  333. unsigned int frame_bits;
  334. unsigned int sample_bits;
  335. unsigned int info;
  336. unsigned int rate_num;
  337. unsigned int rate_den;
  338. unsigned int no_period_wakeup: 1;
  339. /* -- SW params -- */
  340. int tstamp_mode; /* mmap timestamp is updated */
  341. unsigned int period_step;
  342. snd_pcm_uframes_t start_threshold;
  343. snd_pcm_uframes_t stop_threshold;
  344. snd_pcm_uframes_t silence_threshold; /* Silence filling happens when
  345. noise is nearest than this */
  346. snd_pcm_uframes_t silence_size; /* Silence filling size */
  347. snd_pcm_uframes_t boundary; /* pointers wrap point */
  348. snd_pcm_uframes_t silence_start; /* starting pointer to silence area */
  349. snd_pcm_uframes_t silence_filled; /* size filled with silence */
  350. union snd_pcm_sync_id sync; /* hardware synchronization ID */
  351. /* -- mmap -- */
  352. struct snd_pcm_mmap_status *status;
  353. struct snd_pcm_mmap_control *control;
  354. /* -- locking / scheduling -- */
  355. snd_pcm_uframes_t twake; /* do transfer (!poll) wakeup if non-zero */
  356. wait_queue_head_t sleep; /* poll sleep */
  357. wait_queue_head_t tsleep; /* transfer sleep */
  358. struct fasync_struct *fasync;
  359. /* -- private section -- */
  360. void *private_data;
  361. void (*private_free)(struct snd_pcm_runtime *runtime);
  362. /* -- hardware description -- */
  363. struct snd_pcm_hardware hw;
  364. struct snd_pcm_hw_constraints hw_constraints;
  365. /* -- timer -- */
  366. unsigned int timer_resolution; /* timer resolution */
  367. int tstamp_type; /* timestamp type */
  368. /* -- DMA -- */
  369. unsigned char *dma_area; /* DMA area */
  370. dma_addr_t dma_addr; /* physical bus address (not accessible from main CPU) */
  371. size_t dma_bytes; /* size of DMA area */
  372. struct snd_dma_buffer *dma_buffer_p; /* allocated buffer */
  373. /* -- audio timestamp config -- */
  374. struct snd_pcm_audio_tstamp_config audio_tstamp_config;
  375. struct snd_pcm_audio_tstamp_report audio_tstamp_report;
  376. struct timespec driver_tstamp;
  377. #if IS_ENABLED(CONFIG_SND_PCM_OSS)
  378. /* -- OSS things -- */
  379. struct snd_pcm_oss_runtime oss;
  380. #endif
  381. };
  382. struct snd_pcm_group { /* keep linked substreams */
  383. spinlock_t lock;
  384. struct mutex mutex;
  385. struct list_head substreams;
  386. int count;
  387. };
  388. struct pid;
  389. struct snd_pcm_substream {
  390. struct snd_pcm *pcm;
  391. struct snd_pcm_str *pstr;
  392. void *private_data; /* copied from pcm->private_data */
  393. int number;
  394. char name[32]; /* substream name */
  395. int stream; /* stream (direction) */
  396. struct pm_qos_request latency_pm_qos_req; /* pm_qos request */
  397. size_t buffer_bytes_max; /* limit ring buffer size */
  398. struct snd_dma_buffer dma_buffer;
  399. size_t dma_max;
  400. /* -- hardware operations -- */
  401. const struct snd_pcm_ops *ops;
  402. /* -- runtime information -- */
  403. struct snd_pcm_runtime *runtime;
  404. /* -- timer section -- */
  405. struct snd_timer *timer; /* timer */
  406. unsigned timer_running: 1; /* time is running */
  407. long wait_time; /* time in ms for R/W to wait for avail */
  408. /* -- next substream -- */
  409. struct snd_pcm_substream *next;
  410. /* -- linked substreams -- */
  411. struct list_head link_list; /* linked list member */
  412. struct snd_pcm_group self_group; /* fake group for non linked substream (with substream lock inside) */
  413. struct snd_pcm_group *group; /* pointer to current group */
  414. /* -- assigned files -- */
  415. void *file;
  416. int ref_count;
  417. atomic_t mmap_count;
  418. unsigned int f_flags;
  419. void (*pcm_release)(struct snd_pcm_substream *);
  420. struct pid *pid;
  421. #if IS_ENABLED(CONFIG_SND_PCM_OSS)
  422. /* -- OSS things -- */
  423. struct snd_pcm_oss_substream oss;
  424. #endif
  425. #ifdef CONFIG_SND_VERBOSE_PROCFS
  426. struct snd_info_entry *proc_root;
  427. struct snd_info_entry *proc_info_entry;
  428. struct snd_info_entry *proc_hw_params_entry;
  429. struct snd_info_entry *proc_sw_params_entry;
  430. struct snd_info_entry *proc_status_entry;
  431. struct snd_info_entry *proc_prealloc_entry;
  432. struct snd_info_entry *proc_prealloc_max_entry;
  433. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  434. struct snd_info_entry *proc_xrun_injection_entry;
  435. #endif
  436. #endif /* CONFIG_SND_VERBOSE_PROCFS */
  437. /* misc flags */
  438. unsigned int hw_opened: 1;
  439. };
  440. #define SUBSTREAM_BUSY(substream) ((substream)->ref_count > 0)
  441. struct snd_pcm_str {
  442. int stream; /* stream (direction) */
  443. struct snd_pcm *pcm;
  444. /* -- substreams -- */
  445. unsigned int substream_count;
  446. unsigned int substream_opened;
  447. struct snd_pcm_substream *substream;
  448. #if IS_ENABLED(CONFIG_SND_PCM_OSS)
  449. /* -- OSS things -- */
  450. struct snd_pcm_oss_stream oss;
  451. #endif
  452. #ifdef CONFIG_SND_VERBOSE_PROCFS
  453. struct snd_info_entry *proc_root;
  454. struct snd_info_entry *proc_info_entry;
  455. #ifdef CONFIG_SND_PCM_XRUN_DEBUG
  456. unsigned int xrun_debug; /* 0 = disabled, 1 = verbose, 2 = stacktrace */
  457. struct snd_info_entry *proc_xrun_debug_entry;
  458. #endif
  459. #endif
  460. struct snd_kcontrol *chmap_kctl; /* channel-mapping controls */
  461. struct device dev;
  462. };
  463. struct snd_pcm {
  464. struct snd_card *card;
  465. struct list_head list;
  466. int device; /* device number */
  467. unsigned int info_flags;
  468. unsigned short dev_class;
  469. unsigned short dev_subclass;
  470. char id[64];
  471. char name[80];
  472. struct snd_pcm_str streams[2];
  473. struct mutex open_mutex;
  474. wait_queue_head_t open_wait;
  475. void *private_data;
  476. void (*private_free) (struct snd_pcm *pcm);
  477. bool internal; /* pcm is for internal use only */
  478. bool nonatomic; /* whole PCM operations are in non-atomic context */
  479. #if IS_ENABLED(CONFIG_SND_PCM_OSS)
  480. struct snd_pcm_oss oss;
  481. #endif
  482. };
  483. /*
  484. * Registering
  485. */
  486. extern const struct file_operations snd_pcm_f_ops[2];
  487. int snd_pcm_new(struct snd_card *card, const char *id, int device,
  488. int playback_count, int capture_count,
  489. struct snd_pcm **rpcm);
  490. int snd_pcm_new_internal(struct snd_card *card, const char *id, int device,
  491. int playback_count, int capture_count,
  492. struct snd_pcm **rpcm);
  493. int snd_pcm_new_stream(struct snd_pcm *pcm, int stream, int substream_count);
  494. #if IS_ENABLED(CONFIG_SND_PCM_OSS)
  495. struct snd_pcm_notify {
  496. int (*n_register) (struct snd_pcm * pcm);
  497. int (*n_disconnect) (struct snd_pcm * pcm);
  498. int (*n_unregister) (struct snd_pcm * pcm);
  499. struct list_head list;
  500. };
  501. int snd_pcm_notify(struct snd_pcm_notify *notify, int nfree);
  502. #endif
  503. /*
  504. * Native I/O
  505. */
  506. int snd_pcm_info(struct snd_pcm_substream *substream, struct snd_pcm_info *info);
  507. int snd_pcm_info_user(struct snd_pcm_substream *substream,
  508. struct snd_pcm_info __user *info);
  509. int snd_pcm_status(struct snd_pcm_substream *substream,
  510. struct snd_pcm_status *status);
  511. int snd_pcm_start(struct snd_pcm_substream *substream);
  512. int snd_pcm_stop(struct snd_pcm_substream *substream, snd_pcm_state_t status);
  513. int snd_pcm_drain_done(struct snd_pcm_substream *substream);
  514. int snd_pcm_stop_xrun(struct snd_pcm_substream *substream);
  515. #ifdef CONFIG_PM
  516. int snd_pcm_suspend(struct snd_pcm_substream *substream);
  517. int snd_pcm_suspend_all(struct snd_pcm *pcm);
  518. #else
  519. static inline int snd_pcm_suspend(struct snd_pcm_substream *substream)
  520. {
  521. return 0;
  522. }
  523. static inline int snd_pcm_suspend_all(struct snd_pcm *pcm)
  524. {
  525. return 0;
  526. }
  527. #endif
  528. int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream, unsigned int cmd, void *arg);
  529. int snd_pcm_open_substream(struct snd_pcm *pcm, int stream, struct file *file,
  530. struct snd_pcm_substream **rsubstream);
  531. void snd_pcm_release_substream(struct snd_pcm_substream *substream);
  532. int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream, struct file *file,
  533. struct snd_pcm_substream **rsubstream);
  534. void snd_pcm_detach_substream(struct snd_pcm_substream *substream);
  535. int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file, struct vm_area_struct *area);
  536. #ifdef CONFIG_SND_DEBUG
  537. void snd_pcm_debug_name(struct snd_pcm_substream *substream,
  538. char *name, size_t len);
  539. #else
  540. static inline void
  541. snd_pcm_debug_name(struct snd_pcm_substream *substream, char *buf, size_t size)
  542. {
  543. *buf = 0;
  544. }
  545. #endif
  546. /*
  547. * PCM library
  548. */
  549. /**
  550. * snd_pcm_stream_linked - Check whether the substream is linked with others
  551. * @substream: substream to check
  552. *
  553. * Returns true if the given substream is being linked with others.
  554. */
  555. static inline int snd_pcm_stream_linked(struct snd_pcm_substream *substream)
  556. {
  557. return substream->group != &substream->self_group;
  558. }
  559. void snd_pcm_stream_lock(struct snd_pcm_substream *substream);
  560. void snd_pcm_stream_unlock(struct snd_pcm_substream *substream);
  561. void snd_pcm_stream_lock_irq(struct snd_pcm_substream *substream);
  562. void snd_pcm_stream_unlock_irq(struct snd_pcm_substream *substream);
  563. unsigned long _snd_pcm_stream_lock_irqsave(struct snd_pcm_substream *substream);
  564. /**
  565. * snd_pcm_stream_lock_irqsave - Lock the PCM stream
  566. * @substream: PCM substream
  567. * @flags: irq flags
  568. *
  569. * This locks the PCM stream like snd_pcm_stream_lock() but with the local
  570. * IRQ (only when nonatomic is false). In nonatomic case, this is identical
  571. * as snd_pcm_stream_lock().
  572. */
  573. #define snd_pcm_stream_lock_irqsave(substream, flags) \
  574. do { \
  575. typecheck(unsigned long, flags); \
  576. flags = _snd_pcm_stream_lock_irqsave(substream); \
  577. } while (0)
  578. void snd_pcm_stream_unlock_irqrestore(struct snd_pcm_substream *substream,
  579. unsigned long flags);
  580. /**
  581. * snd_pcm_group_for_each_entry - iterate over the linked substreams
  582. * @s: the iterator
  583. * @substream: the substream
  584. *
  585. * Iterate over the all linked substreams to the given @substream.
  586. * When @substream isn't linked with any others, this gives returns @substream
  587. * itself once.
  588. */
  589. #define snd_pcm_group_for_each_entry(s, substream) \
  590. list_for_each_entry(s, &substream->group->substreams, link_list)
  591. /**
  592. * snd_pcm_running - Check whether the substream is in a running state
  593. * @substream: substream to check
  594. *
  595. * Returns true if the given substream is in the state RUNNING, or in the
  596. * state DRAINING for playback.
  597. */
  598. static inline int snd_pcm_running(struct snd_pcm_substream *substream)
  599. {
  600. return (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING ||
  601. (substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
  602. substream->stream == SNDRV_PCM_STREAM_PLAYBACK));
  603. }
  604. /**
  605. * bytes_to_samples - Unit conversion of the size from bytes to samples
  606. * @runtime: PCM runtime instance
  607. * @size: size in bytes
  608. */
  609. static inline ssize_t bytes_to_samples(struct snd_pcm_runtime *runtime, ssize_t size)
  610. {
  611. return size * 8 / runtime->sample_bits;
  612. }
  613. /**
  614. * bytes_to_frames - Unit conversion of the size from bytes to frames
  615. * @runtime: PCM runtime instance
  616. * @size: size in bytes
  617. */
  618. static inline snd_pcm_sframes_t bytes_to_frames(struct snd_pcm_runtime *runtime, ssize_t size)
  619. {
  620. return size * 8 / runtime->frame_bits;
  621. }
  622. /**
  623. * samples_to_bytes - Unit conversion of the size from samples to bytes
  624. * @runtime: PCM runtime instance
  625. * @size: size in samples
  626. */
  627. static inline ssize_t samples_to_bytes(struct snd_pcm_runtime *runtime, ssize_t size)
  628. {
  629. return size * runtime->sample_bits / 8;
  630. }
  631. /**
  632. * frames_to_bytes - Unit conversion of the size from frames to bytes
  633. * @runtime: PCM runtime instance
  634. * @size: size in frames
  635. */
  636. static inline ssize_t frames_to_bytes(struct snd_pcm_runtime *runtime, snd_pcm_sframes_t size)
  637. {
  638. return size * runtime->frame_bits / 8;
  639. }
  640. /**
  641. * frame_aligned - Check whether the byte size is aligned to frames
  642. * @runtime: PCM runtime instance
  643. * @bytes: size in bytes
  644. */
  645. static inline int frame_aligned(struct snd_pcm_runtime *runtime, ssize_t bytes)
  646. {
  647. return bytes % runtime->byte_align == 0;
  648. }
  649. /**
  650. * snd_pcm_lib_buffer_bytes - Get the buffer size of the current PCM in bytes
  651. * @substream: PCM substream
  652. */
  653. static inline size_t snd_pcm_lib_buffer_bytes(struct snd_pcm_substream *substream)
  654. {
  655. struct snd_pcm_runtime *runtime = substream->runtime;
  656. return frames_to_bytes(runtime, runtime->buffer_size);
  657. }
  658. /**
  659. * snd_pcm_lib_period_bytes - Get the period size of the current PCM in bytes
  660. * @substream: PCM substream
  661. */
  662. static inline size_t snd_pcm_lib_period_bytes(struct snd_pcm_substream *substream)
  663. {
  664. struct snd_pcm_runtime *runtime = substream->runtime;
  665. return frames_to_bytes(runtime, runtime->period_size);
  666. }
  667. /**
  668. * snd_pcm_playback_avail - Get the available (writable) space for playback
  669. * @runtime: PCM runtime instance
  670. *
  671. * Result is between 0 ... (boundary - 1)
  672. */
  673. static inline snd_pcm_uframes_t snd_pcm_playback_avail(struct snd_pcm_runtime *runtime)
  674. {
  675. snd_pcm_sframes_t avail = runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_ptr;
  676. if (avail < 0)
  677. avail += runtime->boundary;
  678. else if ((snd_pcm_uframes_t) avail >= runtime->boundary)
  679. avail -= runtime->boundary;
  680. return avail;
  681. }
  682. /**
  683. * snd_pcm_playback_avail - Get the available (readable) space for capture
  684. * @runtime: PCM runtime instance
  685. *
  686. * Result is between 0 ... (boundary - 1)
  687. */
  688. static inline snd_pcm_uframes_t snd_pcm_capture_avail(struct snd_pcm_runtime *runtime)
  689. {
  690. snd_pcm_sframes_t avail = runtime->status->hw_ptr - runtime->control->appl_ptr;
  691. if (avail < 0)
  692. avail += runtime->boundary;
  693. return avail;
  694. }
  695. /**
  696. * snd_pcm_playback_hw_avail - Get the queued space for playback
  697. * @runtime: PCM runtime instance
  698. */
  699. static inline snd_pcm_sframes_t snd_pcm_playback_hw_avail(struct snd_pcm_runtime *runtime)
  700. {
  701. return runtime->buffer_size - snd_pcm_playback_avail(runtime);
  702. }
  703. /**
  704. * snd_pcm_capture_hw_avail - Get the free space for capture
  705. * @runtime: PCM runtime instance
  706. */
  707. static inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(struct snd_pcm_runtime *runtime)
  708. {
  709. return runtime->buffer_size - snd_pcm_capture_avail(runtime);
  710. }
  711. /**
  712. * snd_pcm_playback_ready - check whether the playback buffer is available
  713. * @substream: the pcm substream instance
  714. *
  715. * Checks whether enough free space is available on the playback buffer.
  716. *
  717. * Return: Non-zero if available, or zero if not.
  718. */
  719. static inline int snd_pcm_playback_ready(struct snd_pcm_substream *substream)
  720. {
  721. struct snd_pcm_runtime *runtime = substream->runtime;
  722. return snd_pcm_playback_avail(runtime) >= runtime->control->avail_min;
  723. }
  724. /**
  725. * snd_pcm_capture_ready - check whether the capture buffer is available
  726. * @substream: the pcm substream instance
  727. *
  728. * Checks whether enough capture data is available on the capture buffer.
  729. *
  730. * Return: Non-zero if available, or zero if not.
  731. */
  732. static inline int snd_pcm_capture_ready(struct snd_pcm_substream *substream)
  733. {
  734. struct snd_pcm_runtime *runtime = substream->runtime;
  735. return snd_pcm_capture_avail(runtime) >= runtime->control->avail_min;
  736. }
  737. /**
  738. * snd_pcm_playback_data - check whether any data exists on the playback buffer
  739. * @substream: the pcm substream instance
  740. *
  741. * Checks whether any data exists on the playback buffer.
  742. *
  743. * Return: Non-zero if any data exists, or zero if not. If stop_threshold
  744. * is bigger or equal to boundary, then this function returns always non-zero.
  745. */
  746. static inline int snd_pcm_playback_data(struct snd_pcm_substream *substream)
  747. {
  748. struct snd_pcm_runtime *runtime = substream->runtime;
  749. if (runtime->stop_threshold >= runtime->boundary)
  750. return 1;
  751. return snd_pcm_playback_avail(runtime) < runtime->buffer_size;
  752. }
  753. /**
  754. * snd_pcm_playback_empty - check whether the playback buffer is empty
  755. * @substream: the pcm substream instance
  756. *
  757. * Checks whether the playback buffer is empty.
  758. *
  759. * Return: Non-zero if empty, or zero if not.
  760. */
  761. static inline int snd_pcm_playback_empty(struct snd_pcm_substream *substream)
  762. {
  763. struct snd_pcm_runtime *runtime = substream->runtime;
  764. return snd_pcm_playback_avail(runtime) >= runtime->buffer_size;
  765. }
  766. /**
  767. * snd_pcm_capture_empty - check whether the capture buffer is empty
  768. * @substream: the pcm substream instance
  769. *
  770. * Checks whether the capture buffer is empty.
  771. *
  772. * Return: Non-zero if empty, or zero if not.
  773. */
  774. static inline int snd_pcm_capture_empty(struct snd_pcm_substream *substream)
  775. {
  776. struct snd_pcm_runtime *runtime = substream->runtime;
  777. return snd_pcm_capture_avail(runtime) == 0;
  778. }
  779. /**
  780. * snd_pcm_trigger_done - Mark the master substream
  781. * @substream: the pcm substream instance
  782. * @master: the linked master substream
  783. *
  784. * When multiple substreams of the same card are linked and the hardware
  785. * supports the single-shot operation, the driver calls this in the loop
  786. * in snd_pcm_group_for_each_entry() for marking the substream as "done".
  787. * Then most of trigger operations are performed only to the given master
  788. * substream.
  789. *
  790. * The trigger_master mark is cleared at timestamp updates at the end
  791. * of trigger operations.
  792. */
  793. static inline void snd_pcm_trigger_done(struct snd_pcm_substream *substream,
  794. struct snd_pcm_substream *master)
  795. {
  796. substream->runtime->trigger_master = master;
  797. }
  798. static inline int hw_is_mask(int var)
  799. {
  800. return var >= SNDRV_PCM_HW_PARAM_FIRST_MASK &&
  801. var <= SNDRV_PCM_HW_PARAM_LAST_MASK;
  802. }
  803. static inline int hw_is_interval(int var)
  804. {
  805. return var >= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL &&
  806. var <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL;
  807. }
  808. static inline struct snd_mask *hw_param_mask(struct snd_pcm_hw_params *params,
  809. snd_pcm_hw_param_t var)
  810. {
  811. return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  812. }
  813. static inline struct snd_interval *hw_param_interval(struct snd_pcm_hw_params *params,
  814. snd_pcm_hw_param_t var)
  815. {
  816. return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  817. }
  818. static inline const struct snd_mask *hw_param_mask_c(const struct snd_pcm_hw_params *params,
  819. snd_pcm_hw_param_t var)
  820. {
  821. return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
  822. }
  823. static inline const struct snd_interval *hw_param_interval_c(const struct snd_pcm_hw_params *params,
  824. snd_pcm_hw_param_t var)
  825. {
  826. return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
  827. }
  828. /**
  829. * params_channels - Get the number of channels from the hw params
  830. * @p: hw params
  831. */
  832. static inline unsigned int params_channels(const struct snd_pcm_hw_params *p)
  833. {
  834. return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_CHANNELS)->min;
  835. }
  836. /**
  837. * params_rate - Get the sample rate from the hw params
  838. * @p: hw params
  839. */
  840. static inline unsigned int params_rate(const struct snd_pcm_hw_params *p)
  841. {
  842. return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_RATE)->min;
  843. }
  844. /**
  845. * params_period_size - Get the period size (in frames) from the hw params
  846. * @p: hw params
  847. */
  848. static inline unsigned int params_period_size(const struct snd_pcm_hw_params *p)
  849. {
  850. return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min;
  851. }
  852. /**
  853. * params_periods - Get the number of periods from the hw params
  854. * @p: hw params
  855. */
  856. static inline unsigned int params_periods(const struct snd_pcm_hw_params *p)
  857. {
  858. return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_PERIODS)->min;
  859. }
  860. /**
  861. * params_buffer_size - Get the buffer size (in frames) from the hw params
  862. * @p: hw params
  863. */
  864. static inline unsigned int params_buffer_size(const struct snd_pcm_hw_params *p)
  865. {
  866. return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min;
  867. }
  868. /**
  869. * params_buffer_bytes - Get the buffer size (in bytes) from the hw params
  870. * @p: hw params
  871. */
  872. static inline unsigned int params_buffer_bytes(const struct snd_pcm_hw_params *p)
  873. {
  874. return hw_param_interval_c(p, SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min;
  875. }
  876. int snd_interval_refine(struct snd_interval *i, const struct snd_interval *v);
  877. int snd_interval_list(struct snd_interval *i, unsigned int count,
  878. const unsigned int *list, unsigned int mask);
  879. int snd_interval_ranges(struct snd_interval *i, unsigned int count,
  880. const struct snd_interval *list, unsigned int mask);
  881. int snd_interval_ratnum(struct snd_interval *i,
  882. unsigned int rats_count, const struct snd_ratnum *rats,
  883. unsigned int *nump, unsigned int *denp);
  884. void _snd_pcm_hw_params_any(struct snd_pcm_hw_params *params);
  885. void _snd_pcm_hw_param_setempty(struct snd_pcm_hw_params *params, snd_pcm_hw_param_t var);
  886. int snd_pcm_hw_refine(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params);
  887. int snd_pcm_hw_constraint_mask64(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  888. u_int64_t mask);
  889. int snd_pcm_hw_constraint_minmax(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  890. unsigned int min, unsigned int max);
  891. int snd_pcm_hw_constraint_integer(struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var);
  892. int snd_pcm_hw_constraint_list(struct snd_pcm_runtime *runtime,
  893. unsigned int cond,
  894. snd_pcm_hw_param_t var,
  895. const struct snd_pcm_hw_constraint_list *l);
  896. int snd_pcm_hw_constraint_ranges(struct snd_pcm_runtime *runtime,
  897. unsigned int cond,
  898. snd_pcm_hw_param_t var,
  899. const struct snd_pcm_hw_constraint_ranges *r);
  900. int snd_pcm_hw_constraint_ratnums(struct snd_pcm_runtime *runtime,
  901. unsigned int cond,
  902. snd_pcm_hw_param_t var,
  903. const struct snd_pcm_hw_constraint_ratnums *r);
  904. int snd_pcm_hw_constraint_ratdens(struct snd_pcm_runtime *runtime,
  905. unsigned int cond,
  906. snd_pcm_hw_param_t var,
  907. const struct snd_pcm_hw_constraint_ratdens *r);
  908. int snd_pcm_hw_constraint_msbits(struct snd_pcm_runtime *runtime,
  909. unsigned int cond,
  910. unsigned int width,
  911. unsigned int msbits);
  912. int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
  913. unsigned int cond,
  914. snd_pcm_hw_param_t var,
  915. unsigned long step);
  916. int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
  917. unsigned int cond,
  918. snd_pcm_hw_param_t var);
  919. int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
  920. unsigned int base_rate);
  921. int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime,
  922. unsigned int cond,
  923. int var,
  924. snd_pcm_hw_rule_func_t func, void *private,
  925. int dep, ...);
  926. /**
  927. * snd_pcm_hw_constraint_single() - Constrain parameter to a single value
  928. * @runtime: PCM runtime instance
  929. * @var: The hw_params variable to constrain
  930. * @val: The value to constrain to
  931. *
  932. * Return: Positive if the value is changed, zero if it's not changed, or a
  933. * negative error code.
  934. */
  935. static inline int snd_pcm_hw_constraint_single(
  936. struct snd_pcm_runtime *runtime, snd_pcm_hw_param_t var,
  937. unsigned int val)
  938. {
  939. return snd_pcm_hw_constraint_minmax(runtime, var, val, val);
  940. }
  941. int snd_pcm_format_signed(snd_pcm_format_t format);
  942. int snd_pcm_format_unsigned(snd_pcm_format_t format);
  943. int snd_pcm_format_linear(snd_pcm_format_t format);
  944. int snd_pcm_format_little_endian(snd_pcm_format_t format);
  945. int snd_pcm_format_big_endian(snd_pcm_format_t format);
  946. #if 0 /* just for kernel-doc */
  947. /**
  948. * snd_pcm_format_cpu_endian - Check the PCM format is CPU-endian
  949. * @format: the format to check
  950. *
  951. * Return: 1 if the given PCM format is CPU-endian, 0 if
  952. * opposite, or a negative error code if endian not specified.
  953. */
  954. int snd_pcm_format_cpu_endian(snd_pcm_format_t format);
  955. #endif /* DocBook */
  956. #ifdef SNDRV_LITTLE_ENDIAN
  957. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_little_endian(format)
  958. #else
  959. #define snd_pcm_format_cpu_endian(format) snd_pcm_format_big_endian(format)
  960. #endif
  961. int snd_pcm_format_width(snd_pcm_format_t format); /* in bits */
  962. int snd_pcm_format_physical_width(snd_pcm_format_t format); /* in bits */
  963. ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
  964. const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format);
  965. int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
  966. void snd_pcm_set_ops(struct snd_pcm * pcm, int direction,
  967. const struct snd_pcm_ops *ops);
  968. void snd_pcm_set_sync(struct snd_pcm_substream *substream);
  969. int snd_pcm_lib_ioctl(struct snd_pcm_substream *substream,
  970. unsigned int cmd, void *arg);
  971. void snd_pcm_period_elapsed(struct snd_pcm_substream *substream);
  972. snd_pcm_sframes_t __snd_pcm_lib_xfer(struct snd_pcm_substream *substream,
  973. void *buf, bool interleaved,
  974. snd_pcm_uframes_t frames, bool in_kernel);
  975. static inline snd_pcm_sframes_t
  976. snd_pcm_lib_write(struct snd_pcm_substream *substream,
  977. const void __user *buf, snd_pcm_uframes_t frames)
  978. {
  979. return __snd_pcm_lib_xfer(substream, (void __force *)buf, true, frames, false);
  980. }
  981. static inline snd_pcm_sframes_t
  982. snd_pcm_lib_read(struct snd_pcm_substream *substream,
  983. void __user *buf, snd_pcm_uframes_t frames)
  984. {
  985. return __snd_pcm_lib_xfer(substream, (void __force *)buf, true, frames, false);
  986. }
  987. static inline snd_pcm_sframes_t
  988. snd_pcm_lib_writev(struct snd_pcm_substream *substream,
  989. void __user **bufs, snd_pcm_uframes_t frames)
  990. {
  991. return __snd_pcm_lib_xfer(substream, (void *)bufs, false, frames, false);
  992. }
  993. static inline snd_pcm_sframes_t
  994. snd_pcm_lib_readv(struct snd_pcm_substream *substream,
  995. void __user **bufs, snd_pcm_uframes_t frames)
  996. {
  997. return __snd_pcm_lib_xfer(substream, (void *)bufs, false, frames, false);
  998. }
  999. static inline snd_pcm_sframes_t
  1000. snd_pcm_kernel_write(struct snd_pcm_substream *substream,
  1001. const void *buf, snd_pcm_uframes_t frames)
  1002. {
  1003. return __snd_pcm_lib_xfer(substream, (void *)buf, true, frames, true);
  1004. }
  1005. static inline snd_pcm_sframes_t
  1006. snd_pcm_kernel_read(struct snd_pcm_substream *substream,
  1007. void *buf, snd_pcm_uframes_t frames)
  1008. {
  1009. return __snd_pcm_lib_xfer(substream, buf, true, frames, true);
  1010. }
  1011. static inline snd_pcm_sframes_t
  1012. snd_pcm_kernel_writev(struct snd_pcm_substream *substream,
  1013. void **bufs, snd_pcm_uframes_t frames)
  1014. {
  1015. return __snd_pcm_lib_xfer(substream, bufs, false, frames, true);
  1016. }
  1017. static inline snd_pcm_sframes_t
  1018. snd_pcm_kernel_readv(struct snd_pcm_substream *substream,
  1019. void **bufs, snd_pcm_uframes_t frames)
  1020. {
  1021. return __snd_pcm_lib_xfer(substream, bufs, false, frames, true);
  1022. }
  1023. int snd_pcm_limit_hw_rates(struct snd_pcm_runtime *runtime);
  1024. unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate);
  1025. unsigned int snd_pcm_rate_bit_to_rate(unsigned int rate_bit);
  1026. unsigned int snd_pcm_rate_mask_intersect(unsigned int rates_a,
  1027. unsigned int rates_b);
  1028. unsigned int snd_pcm_rate_range_to_bits(unsigned int rate_min,
  1029. unsigned int rate_max);
  1030. /**
  1031. * snd_pcm_set_runtime_buffer - Set the PCM runtime buffer
  1032. * @substream: PCM substream to set
  1033. * @bufp: the buffer information, NULL to clear
  1034. *
  1035. * Copy the buffer information to runtime->dma_buffer when @bufp is non-NULL.
  1036. * Otherwise it clears the current buffer information.
  1037. */
  1038. static inline void snd_pcm_set_runtime_buffer(struct snd_pcm_substream *substream,
  1039. struct snd_dma_buffer *bufp)
  1040. {
  1041. struct snd_pcm_runtime *runtime = substream->runtime;
  1042. if (bufp) {
  1043. runtime->dma_buffer_p = bufp;
  1044. runtime->dma_area = bufp->area;
  1045. runtime->dma_addr = bufp->addr;
  1046. runtime->dma_bytes = bufp->bytes;
  1047. } else {
  1048. runtime->dma_buffer_p = NULL;
  1049. runtime->dma_area = NULL;
  1050. runtime->dma_addr = 0;
  1051. runtime->dma_bytes = 0;
  1052. }
  1053. }
  1054. /**
  1055. * snd_pcm_gettime - Fill the timespec depending on the timestamp mode
  1056. * @runtime: PCM runtime instance
  1057. * @tv: timespec to fill
  1058. */
  1059. static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
  1060. struct timespec *tv)
  1061. {
  1062. switch (runtime->tstamp_type) {
  1063. case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC:
  1064. ktime_get_ts(tv);
  1065. break;
  1066. case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
  1067. getrawmonotonic(tv);
  1068. break;
  1069. default:
  1070. getnstimeofday(tv);
  1071. break;
  1072. }
  1073. }
  1074. /*
  1075. * Memory
  1076. */
  1077. int snd_pcm_lib_preallocate_free(struct snd_pcm_substream *substream);
  1078. int snd_pcm_lib_preallocate_free_for_all(struct snd_pcm *pcm);
  1079. int snd_pcm_lib_preallocate_pages(struct snd_pcm_substream *substream,
  1080. int type, struct device *data,
  1081. size_t size, size_t max);
  1082. int snd_pcm_lib_preallocate_pages_for_all(struct snd_pcm *pcm,
  1083. int type, void *data,
  1084. size_t size, size_t max);
  1085. int snd_pcm_lib_malloc_pages(struct snd_pcm_substream *substream, size_t size);
  1086. int snd_pcm_lib_free_pages(struct snd_pcm_substream *substream);
  1087. int _snd_pcm_lib_alloc_vmalloc_buffer(struct snd_pcm_substream *substream,
  1088. size_t size, gfp_t gfp_flags);
  1089. int snd_pcm_lib_free_vmalloc_buffer(struct snd_pcm_substream *substream);
  1090. struct page *snd_pcm_lib_get_vmalloc_page(struct snd_pcm_substream *substream,
  1091. unsigned long offset);
  1092. /**
  1093. * snd_pcm_lib_alloc_vmalloc_buffer - allocate virtual DMA buffer
  1094. * @substream: the substream to allocate the buffer to
  1095. * @size: the requested buffer size, in bytes
  1096. *
  1097. * Allocates the PCM substream buffer using vmalloc(), i.e., the memory is
  1098. * contiguous in kernel virtual space, but not in physical memory. Use this
  1099. * if the buffer is accessed by kernel code but not by device DMA.
  1100. *
  1101. * Return: 1 if the buffer was changed, 0 if not changed, or a negative error
  1102. * code.
  1103. */
  1104. static inline int snd_pcm_lib_alloc_vmalloc_buffer
  1105. (struct snd_pcm_substream *substream, size_t size)
  1106. {
  1107. return _snd_pcm_lib_alloc_vmalloc_buffer(substream, size,
  1108. GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO);
  1109. }
  1110. /**
  1111. * snd_pcm_lib_alloc_vmalloc_32_buffer - allocate 32-bit-addressable buffer
  1112. * @substream: the substream to allocate the buffer to
  1113. * @size: the requested buffer size, in bytes
  1114. *
  1115. * This function works like snd_pcm_lib_alloc_vmalloc_buffer(), but uses
  1116. * vmalloc_32(), i.e., the pages are allocated from 32-bit-addressable memory.
  1117. *
  1118. * Return: 1 if the buffer was changed, 0 if not changed, or a negative error
  1119. * code.
  1120. */
  1121. static inline int snd_pcm_lib_alloc_vmalloc_32_buffer
  1122. (struct snd_pcm_substream *substream, size_t size)
  1123. {
  1124. return _snd_pcm_lib_alloc_vmalloc_buffer(substream, size,
  1125. GFP_KERNEL | GFP_DMA32 | __GFP_ZERO);
  1126. }
  1127. #define snd_pcm_get_dma_buf(substream) ((substream)->runtime->dma_buffer_p)
  1128. #ifdef CONFIG_SND_DMA_SGBUF
  1129. /*
  1130. * SG-buffer handling
  1131. */
  1132. #define snd_pcm_substream_sgbuf(substream) \
  1133. snd_pcm_get_dma_buf(substream)->private_data
  1134. struct page *snd_pcm_sgbuf_ops_page(struct snd_pcm_substream *substream,
  1135. unsigned long offset);
  1136. #else /* !SND_DMA_SGBUF */
  1137. /*
  1138. * fake using a continuous buffer
  1139. */
  1140. #define snd_pcm_sgbuf_ops_page NULL
  1141. #endif /* SND_DMA_SGBUF */
  1142. /**
  1143. * snd_pcm_sgbuf_get_addr - Get the DMA address at the corresponding offset
  1144. * @substream: PCM substream
  1145. * @ofs: byte offset
  1146. */
  1147. static inline dma_addr_t
  1148. snd_pcm_sgbuf_get_addr(struct snd_pcm_substream *substream, unsigned int ofs)
  1149. {
  1150. return snd_sgbuf_get_addr(snd_pcm_get_dma_buf(substream), ofs);
  1151. }
  1152. /**
  1153. * snd_pcm_sgbuf_get_ptr - Get the virtual address at the corresponding offset
  1154. * @substream: PCM substream
  1155. * @ofs: byte offset
  1156. */
  1157. static inline void *
  1158. snd_pcm_sgbuf_get_ptr(struct snd_pcm_substream *substream, unsigned int ofs)
  1159. {
  1160. return snd_sgbuf_get_ptr(snd_pcm_get_dma_buf(substream), ofs);
  1161. }
  1162. /**
  1163. * snd_pcm_sgbuf_chunk_size - Compute the max size that fits within the contig.
  1164. * page from the given size
  1165. * @substream: PCM substream
  1166. * @ofs: byte offset
  1167. * @size: byte size to examine
  1168. */
  1169. static inline unsigned int
  1170. snd_pcm_sgbuf_get_chunk_size(struct snd_pcm_substream *substream,
  1171. unsigned int ofs, unsigned int size)
  1172. {
  1173. return snd_sgbuf_get_chunk_size(snd_pcm_get_dma_buf(substream), ofs, size);
  1174. }
  1175. /**
  1176. * snd_pcm_mmap_data_open - increase the mmap counter
  1177. * @area: VMA
  1178. *
  1179. * PCM mmap callback should handle this counter properly
  1180. */
  1181. static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area)
  1182. {
  1183. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  1184. atomic_inc(&substream->mmap_count);
  1185. }
  1186. /**
  1187. * snd_pcm_mmap_data_close - decrease the mmap counter
  1188. * @area: VMA
  1189. *
  1190. * PCM mmap callback should handle this counter properly
  1191. */
  1192. static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area)
  1193. {
  1194. struct snd_pcm_substream *substream = (struct snd_pcm_substream *)area->vm_private_data;
  1195. atomic_dec(&substream->mmap_count);
  1196. }
  1197. int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
  1198. struct vm_area_struct *area);
  1199. /* mmap for io-memory area */
  1200. #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
  1201. #define SNDRV_PCM_INFO_MMAP_IOMEM SNDRV_PCM_INFO_MMAP
  1202. int snd_pcm_lib_mmap_iomem(struct snd_pcm_substream *substream, struct vm_area_struct *area);
  1203. #else
  1204. #define SNDRV_PCM_INFO_MMAP_IOMEM 0
  1205. #define snd_pcm_lib_mmap_iomem NULL
  1206. #endif
  1207. /**
  1208. * snd_pcm_limit_isa_dma_size - Get the max size fitting with ISA DMA transfer
  1209. * @dma: DMA number
  1210. * @max: pointer to store the max size
  1211. */
  1212. static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
  1213. {
  1214. *max = dma < 4 ? 64 * 1024 : 128 * 1024;
  1215. }
  1216. /*
  1217. * Misc
  1218. */
  1219. #define SNDRV_PCM_DEFAULT_CON_SPDIF (IEC958_AES0_CON_EMPHASIS_NONE|\
  1220. (IEC958_AES1_CON_ORIGINAL<<8)|\
  1221. (IEC958_AES1_CON_PCM_CODER<<8)|\
  1222. (IEC958_AES3_CON_FS_48000<<24))
  1223. #define PCM_RUNTIME_CHECK(sub) snd_BUG_ON(!(sub) || !(sub)->runtime)
  1224. const char *snd_pcm_format_name(snd_pcm_format_t format);
  1225. /**
  1226. * snd_pcm_stream_str - Get a string naming the direction of a stream
  1227. * @substream: the pcm substream instance
  1228. *
  1229. * Return: A string naming the direction of the stream.
  1230. */
  1231. static inline const char *snd_pcm_stream_str(struct snd_pcm_substream *substream)
  1232. {
  1233. if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
  1234. return "Playback";
  1235. else
  1236. return "Capture";
  1237. }
  1238. /*
  1239. * PCM channel-mapping control API
  1240. */
  1241. /* array element of channel maps */
  1242. struct snd_pcm_chmap_elem {
  1243. unsigned char channels;
  1244. unsigned char map[15];
  1245. };
  1246. /* channel map information; retrieved via snd_kcontrol_chip() */
  1247. struct snd_pcm_chmap {
  1248. struct snd_pcm *pcm; /* assigned PCM instance */
  1249. int stream; /* PLAYBACK or CAPTURE */
  1250. struct snd_kcontrol *kctl;
  1251. const struct snd_pcm_chmap_elem *chmap;
  1252. unsigned int max_channels;
  1253. unsigned int channel_mask; /* optional: active channels bitmask */
  1254. void *private_data; /* optional: private data pointer */
  1255. };
  1256. /**
  1257. * snd_pcm_chmap_substream - get the PCM substream assigned to the given chmap info
  1258. * @info: chmap information
  1259. * @idx: the substream number index
  1260. */
  1261. static inline struct snd_pcm_substream *
  1262. snd_pcm_chmap_substream(struct snd_pcm_chmap *info, unsigned int idx)
  1263. {
  1264. struct snd_pcm_substream *s;
  1265. for (s = info->pcm->streams[info->stream].substream; s; s = s->next)
  1266. if (s->number == idx)
  1267. return s;
  1268. return NULL;
  1269. }
  1270. /* ALSA-standard channel maps (RL/RR prior to C/LFE) */
  1271. extern const struct snd_pcm_chmap_elem snd_pcm_std_chmaps[];
  1272. /* Other world's standard channel maps (C/LFE prior to RL/RR) */
  1273. extern const struct snd_pcm_chmap_elem snd_pcm_alt_chmaps[];
  1274. /* bit masks to be passed to snd_pcm_chmap.channel_mask field */
  1275. #define SND_PCM_CHMAP_MASK_24 ((1U << 2) | (1U << 4))
  1276. #define SND_PCM_CHMAP_MASK_246 (SND_PCM_CHMAP_MASK_24 | (1U << 6))
  1277. #define SND_PCM_CHMAP_MASK_2468 (SND_PCM_CHMAP_MASK_246 | (1U << 8))
  1278. int snd_pcm_add_chmap_ctls(struct snd_pcm *pcm, int stream,
  1279. const struct snd_pcm_chmap_elem *chmap,
  1280. int max_channels,
  1281. unsigned long private_value,
  1282. struct snd_pcm_chmap **info_ret);
  1283. /**
  1284. * pcm_format_to_bits - Strong-typed conversion of pcm_format to bitwise
  1285. * @pcm_format: PCM format
  1286. */
  1287. static inline u64 pcm_format_to_bits(snd_pcm_format_t pcm_format)
  1288. {
  1289. return 1ULL << (__force int) pcm_format;
  1290. }
  1291. /* printk helpers */
  1292. #define pcm_err(pcm, fmt, args...) \
  1293. dev_err((pcm)->card->dev, fmt, ##args)
  1294. #define pcm_warn(pcm, fmt, args...) \
  1295. dev_warn((pcm)->card->dev, fmt, ##args)
  1296. #define pcm_dbg(pcm, fmt, args...) \
  1297. dev_dbg((pcm)->card->dev, fmt, ##args)
  1298. #endif /* __SOUND_PCM_H */