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