pcm.h 54 KB

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