]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | #ifndef __SOUND_PCM_H |
2 | #define __SOUND_PCM_H | |
3 | ||
4 | /* | |
5 | * Digital Audio (PCM) abstract layer | |
6 | * Copyright (c) by Jaroslav Kysela <perex@suse.cz> | |
7 | * Abramo Bagnara <abramo@alsa-project.org> | |
8 | * | |
9 | * | |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 | * | |
24 | */ | |
25 | ||
26 | #include <sound/asound.h> | |
27 | #include <sound/memalloc.h> | |
28 | #include <linux/poll.h> | |
29 | #include <linux/bitops.h> | |
30 | ||
31 | typedef sndrv_pcm_uframes_t snd_pcm_uframes_t; | |
32 | typedef sndrv_pcm_sframes_t snd_pcm_sframes_t; | |
33 | typedef enum sndrv_pcm_class snd_pcm_class_t; | |
34 | typedef enum sndrv_pcm_subclass snd_pcm_subclass_t; | |
35 | typedef enum sndrv_pcm_stream snd_pcm_stream_t; | |
36 | typedef enum sndrv_pcm_access snd_pcm_access_t; | |
37 | typedef enum sndrv_pcm_format snd_pcm_format_t; | |
38 | typedef enum sndrv_pcm_subformat snd_pcm_subformat_t; | |
39 | typedef enum sndrv_pcm_state snd_pcm_state_t; | |
40 | typedef union sndrv_pcm_sync_id snd_pcm_sync_id_t; | |
41 | typedef struct sndrv_pcm_info snd_pcm_info_t; | |
42 | typedef enum sndrv_pcm_hw_param snd_pcm_hw_param_t; | |
43 | typedef struct sndrv_pcm_hw_params snd_pcm_hw_params_t; | |
44 | typedef enum sndrv_pcm_start snd_pcm_start_t; | |
45 | typedef enum sndrv_pcm_xrun snd_pcm_xrun_t; | |
46 | typedef enum sndrv_pcm_tstamp snd_pcm_tstamp_t; | |
47 | typedef struct sndrv_pcm_sw_params snd_pcm_sw_params_t; | |
48 | typedef struct sndrv_pcm_channel_info snd_pcm_channel_info_t; | |
49 | typedef struct sndrv_pcm_status snd_pcm_status_t; | |
50 | typedef struct sndrv_pcm_mmap_status snd_pcm_mmap_status_t; | |
51 | typedef struct sndrv_pcm_mmap_control snd_pcm_mmap_control_t; | |
52 | typedef struct sndrv_mask snd_mask_t; | |
53 | typedef struct snd_sg_buf snd_pcm_sgbuf_t; | |
54 | ||
55 | #define snd_pcm_substream_chip(substream) ((substream)->private_data) | |
56 | #define snd_pcm_chip(pcm) ((pcm)->private_data) | |
57 | ||
58 | typedef struct _snd_pcm_file snd_pcm_file_t; | |
59 | typedef struct _snd_pcm_runtime snd_pcm_runtime_t; | |
60 | ||
61 | #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) | |
62 | #include "pcm_oss.h" | |
63 | #endif | |
64 | ||
65 | /* | |
66 | * Hardware (lowlevel) section | |
67 | */ | |
68 | ||
69 | typedef struct _snd_pcm_hardware { | |
70 | unsigned int info; /* SNDRV_PCM_INFO_* */ | |
71 | u64 formats; /* SNDRV_PCM_FMTBIT_* */ | |
72 | unsigned int rates; /* SNDRV_PCM_RATE_* */ | |
73 | unsigned int rate_min; /* min rate */ | |
74 | unsigned int rate_max; /* max rate */ | |
75 | unsigned int channels_min; /* min channels */ | |
76 | unsigned int channels_max; /* max channels */ | |
77 | size_t buffer_bytes_max; /* max buffer size */ | |
78 | size_t period_bytes_min; /* min period size */ | |
79 | size_t period_bytes_max; /* max period size */ | |
80 | unsigned int periods_min; /* min # of periods */ | |
81 | unsigned int periods_max; /* max # of periods */ | |
82 | size_t fifo_size; /* fifo size in bytes */ | |
83 | } snd_pcm_hardware_t; | |
84 | ||
85 | typedef struct _snd_pcm_ops { | |
86 | int (*open)(snd_pcm_substream_t *substream); | |
87 | int (*close)(snd_pcm_substream_t *substream); | |
88 | int (*ioctl)(snd_pcm_substream_t * substream, | |
89 | unsigned int cmd, void *arg); | |
90 | int (*hw_params)(snd_pcm_substream_t * substream, snd_pcm_hw_params_t * params); | |
91 | int (*hw_free)(snd_pcm_substream_t *substream); | |
92 | int (*prepare)(snd_pcm_substream_t * substream); | |
93 | int (*trigger)(snd_pcm_substream_t * substream, int cmd); | |
94 | snd_pcm_uframes_t (*pointer)(snd_pcm_substream_t * substream); | |
95 | int (*copy)(snd_pcm_substream_t *substream, int channel, snd_pcm_uframes_t pos, | |
96 | void __user *buf, snd_pcm_uframes_t count); | |
97 | int (*silence)(snd_pcm_substream_t *substream, int channel, | |
98 | snd_pcm_uframes_t pos, snd_pcm_uframes_t count); | |
99 | struct page *(*page)(snd_pcm_substream_t *substream, unsigned long offset); | |
100 | int (*mmap)(snd_pcm_substream_t *substream, struct vm_area_struct *vma); | |
101 | int (*ack)(snd_pcm_substream_t *substream); | |
102 | } snd_pcm_ops_t; | |
103 | ||
104 | /* | |
105 | * | |
106 | */ | |
107 | ||
108 | #define SNDRV_PCM_DEVICES 8 | |
109 | ||
110 | #define SNDRV_PCM_IOCTL1_FALSE ((void *)0) | |
111 | #define SNDRV_PCM_IOCTL1_TRUE ((void *)1) | |
112 | ||
113 | #define SNDRV_PCM_IOCTL1_RESET 0 | |
114 | #define SNDRV_PCM_IOCTL1_INFO 1 | |
115 | #define SNDRV_PCM_IOCTL1_CHANNEL_INFO 2 | |
116 | #define SNDRV_PCM_IOCTL1_GSTATE 3 | |
117 | ||
118 | #define SNDRV_PCM_TRIGGER_STOP 0 | |
119 | #define SNDRV_PCM_TRIGGER_START 1 | |
120 | #define SNDRV_PCM_TRIGGER_PAUSE_PUSH 3 | |
121 | #define SNDRV_PCM_TRIGGER_PAUSE_RELEASE 4 | |
122 | #define SNDRV_PCM_TRIGGER_SUSPEND 5 | |
123 | #define SNDRV_PCM_TRIGGER_RESUME 6 | |
124 | ||
125 | #define SNDRV_PCM_POS_XRUN ((snd_pcm_uframes_t)-1) | |
126 | ||
127 | /* If you change this don't forget to change rates[] table in pcm_native.c */ | |
128 | #define SNDRV_PCM_RATE_5512 (1<<0) /* 5512Hz */ | |
129 | #define SNDRV_PCM_RATE_8000 (1<<1) /* 8000Hz */ | |
130 | #define SNDRV_PCM_RATE_11025 (1<<2) /* 11025Hz */ | |
131 | #define SNDRV_PCM_RATE_16000 (1<<3) /* 16000Hz */ | |
132 | #define SNDRV_PCM_RATE_22050 (1<<4) /* 22050Hz */ | |
133 | #define SNDRV_PCM_RATE_32000 (1<<5) /* 32000Hz */ | |
134 | #define SNDRV_PCM_RATE_44100 (1<<6) /* 44100Hz */ | |
135 | #define SNDRV_PCM_RATE_48000 (1<<7) /* 48000Hz */ | |
136 | #define SNDRV_PCM_RATE_64000 (1<<8) /* 64000Hz */ | |
137 | #define SNDRV_PCM_RATE_88200 (1<<9) /* 88200Hz */ | |
138 | #define SNDRV_PCM_RATE_96000 (1<<10) /* 96000Hz */ | |
139 | #define SNDRV_PCM_RATE_176400 (1<<11) /* 176400Hz */ | |
140 | #define SNDRV_PCM_RATE_192000 (1<<12) /* 192000Hz */ | |
141 | ||
142 | #define SNDRV_PCM_RATE_CONTINUOUS (1<<30) /* continuous range */ | |
143 | #define SNDRV_PCM_RATE_KNOT (1<<31) /* supports more non-continuos rates */ | |
144 | ||
145 | #define SNDRV_PCM_RATE_8000_44100 (SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_11025|\ | |
146 | SNDRV_PCM_RATE_16000|SNDRV_PCM_RATE_22050|\ | |
147 | SNDRV_PCM_RATE_32000|SNDRV_PCM_RATE_44100) | |
148 | #define SNDRV_PCM_RATE_8000_48000 (SNDRV_PCM_RATE_8000_44100|SNDRV_PCM_RATE_48000) | |
149 | #define SNDRV_PCM_RATE_8000_96000 (SNDRV_PCM_RATE_8000_48000|SNDRV_PCM_RATE_64000|\ | |
150 | SNDRV_PCM_RATE_88200|SNDRV_PCM_RATE_96000) | |
151 | #define SNDRV_PCM_RATE_8000_192000 (SNDRV_PCM_RATE_8000_96000|SNDRV_PCM_RATE_176400|\ | |
152 | SNDRV_PCM_RATE_192000) | |
153 | #define SNDRV_PCM_FMTBIT_S8 (1ULL << SNDRV_PCM_FORMAT_S8) | |
154 | #define SNDRV_PCM_FMTBIT_U8 (1ULL << SNDRV_PCM_FORMAT_U8) | |
155 | #define SNDRV_PCM_FMTBIT_S16_LE (1ULL << SNDRV_PCM_FORMAT_S16_LE) | |
156 | #define SNDRV_PCM_FMTBIT_S16_BE (1ULL << SNDRV_PCM_FORMAT_S16_BE) | |
157 | #define SNDRV_PCM_FMTBIT_U16_LE (1ULL << SNDRV_PCM_FORMAT_U16_LE) | |
158 | #define SNDRV_PCM_FMTBIT_U16_BE (1ULL << SNDRV_PCM_FORMAT_U16_BE) | |
159 | #define SNDRV_PCM_FMTBIT_S24_LE (1ULL << SNDRV_PCM_FORMAT_S24_LE) | |
160 | #define SNDRV_PCM_FMTBIT_S24_BE (1ULL << SNDRV_PCM_FORMAT_S24_BE) | |
161 | #define SNDRV_PCM_FMTBIT_U24_LE (1ULL << SNDRV_PCM_FORMAT_U24_LE) | |
162 | #define SNDRV_PCM_FMTBIT_U24_BE (1ULL << SNDRV_PCM_FORMAT_U24_BE) | |
163 | #define SNDRV_PCM_FMTBIT_S32_LE (1ULL << SNDRV_PCM_FORMAT_S32_LE) | |
164 | #define SNDRV_PCM_FMTBIT_S32_BE (1ULL << SNDRV_PCM_FORMAT_S32_BE) | |
165 | #define SNDRV_PCM_FMTBIT_U32_LE (1ULL << SNDRV_PCM_FORMAT_U32_LE) | |
166 | #define SNDRV_PCM_FMTBIT_U32_BE (1ULL << SNDRV_PCM_FORMAT_U32_BE) | |
167 | #define SNDRV_PCM_FMTBIT_FLOAT_LE (1ULL << SNDRV_PCM_FORMAT_FLOAT_LE) | |
168 | #define SNDRV_PCM_FMTBIT_FLOAT_BE (1ULL << SNDRV_PCM_FORMAT_FLOAT_BE) | |
169 | #define SNDRV_PCM_FMTBIT_FLOAT64_LE (1ULL << SNDRV_PCM_FORMAT_FLOAT64_LE) | |
170 | #define SNDRV_PCM_FMTBIT_FLOAT64_BE (1ULL << SNDRV_PCM_FORMAT_FLOAT64_BE) | |
171 | #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE (1ULL << SNDRV_PCM_FORMAT_IEC958_SUBFRAME_LE) | |
172 | #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE (1ULL << SNDRV_PCM_FORMAT_IEC958_SUBFRAME_BE) | |
173 | #define SNDRV_PCM_FMTBIT_MU_LAW (1ULL << SNDRV_PCM_FORMAT_MU_LAW) | |
174 | #define SNDRV_PCM_FMTBIT_A_LAW (1ULL << SNDRV_PCM_FORMAT_A_LAW) | |
175 | #define SNDRV_PCM_FMTBIT_IMA_ADPCM (1ULL << SNDRV_PCM_FORMAT_IMA_ADPCM) | |
176 | #define SNDRV_PCM_FMTBIT_MPEG (1ULL << SNDRV_PCM_FORMAT_MPEG) | |
177 | #define SNDRV_PCM_FMTBIT_GSM (1ULL << SNDRV_PCM_FORMAT_GSM) | |
178 | #define SNDRV_PCM_FMTBIT_SPECIAL (1ULL << SNDRV_PCM_FORMAT_SPECIAL) | |
179 | #define SNDRV_PCM_FMTBIT_S24_3LE (1ULL << SNDRV_PCM_FORMAT_S24_3LE) | |
180 | #define SNDRV_PCM_FMTBIT_U24_3LE (1ULL << SNDRV_PCM_FORMAT_U24_3LE) | |
181 | #define SNDRV_PCM_FMTBIT_S24_3BE (1ULL << SNDRV_PCM_FORMAT_S24_3BE) | |
182 | #define SNDRV_PCM_FMTBIT_U24_3BE (1ULL << SNDRV_PCM_FORMAT_U24_3BE) | |
183 | #define SNDRV_PCM_FMTBIT_S20_3LE (1ULL << SNDRV_PCM_FORMAT_S20_3LE) | |
184 | #define SNDRV_PCM_FMTBIT_U20_3LE (1ULL << SNDRV_PCM_FORMAT_U20_3LE) | |
185 | #define SNDRV_PCM_FMTBIT_S20_3BE (1ULL << SNDRV_PCM_FORMAT_S20_3BE) | |
186 | #define SNDRV_PCM_FMTBIT_U20_3BE (1ULL << SNDRV_PCM_FORMAT_U20_3BE) | |
187 | #define SNDRV_PCM_FMTBIT_S18_3LE (1ULL << SNDRV_PCM_FORMAT_S18_3LE) | |
188 | #define SNDRV_PCM_FMTBIT_U18_3LE (1ULL << SNDRV_PCM_FORMAT_U18_3LE) | |
189 | #define SNDRV_PCM_FMTBIT_S18_3BE (1ULL << SNDRV_PCM_FORMAT_S18_3BE) | |
190 | #define SNDRV_PCM_FMTBIT_U18_3BE (1ULL << SNDRV_PCM_FORMAT_U18_3BE) | |
191 | ||
192 | #ifdef SNDRV_LITTLE_ENDIAN | |
193 | #define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_LE | |
194 | #define SNDRV_PCM_FMTBIT_U16 SNDRV_PCM_FMTBIT_U16_LE | |
195 | #define SNDRV_PCM_FMTBIT_S24 SNDRV_PCM_FMTBIT_S24_LE | |
196 | #define SNDRV_PCM_FMTBIT_U24 SNDRV_PCM_FMTBIT_U24_LE | |
197 | #define SNDRV_PCM_FMTBIT_S32 SNDRV_PCM_FMTBIT_S32_LE | |
198 | #define SNDRV_PCM_FMTBIT_U32 SNDRV_PCM_FMTBIT_U32_LE | |
199 | #define SNDRV_PCM_FMTBIT_FLOAT SNDRV_PCM_FMTBIT_FLOAT_LE | |
200 | #define SNDRV_PCM_FMTBIT_FLOAT64 SNDRV_PCM_FMTBIT_FLOAT64_LE | |
201 | #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE | |
202 | #endif | |
203 | #ifdef SNDRV_BIG_ENDIAN | |
204 | #define SNDRV_PCM_FMTBIT_S16 SNDRV_PCM_FMTBIT_S16_BE | |
205 | #define SNDRV_PCM_FMTBIT_U16 SNDRV_PCM_FMTBIT_U16_BE | |
206 | #define SNDRV_PCM_FMTBIT_S24 SNDRV_PCM_FMTBIT_S24_BE | |
207 | #define SNDRV_PCM_FMTBIT_U24 SNDRV_PCM_FMTBIT_U24_BE | |
208 | #define SNDRV_PCM_FMTBIT_S32 SNDRV_PCM_FMTBIT_S32_BE | |
209 | #define SNDRV_PCM_FMTBIT_U32 SNDRV_PCM_FMTBIT_U32_BE | |
210 | #define SNDRV_PCM_FMTBIT_FLOAT SNDRV_PCM_FMTBIT_FLOAT_BE | |
211 | #define SNDRV_PCM_FMTBIT_FLOAT64 SNDRV_PCM_FMTBIT_FLOAT64_BE | |
212 | #define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE | |
213 | #endif | |
214 | ||
215 | struct _snd_pcm_file { | |
216 | snd_pcm_substream_t * substream; | |
217 | struct _snd_pcm_file * next; | |
218 | }; | |
219 | ||
220 | typedef struct _snd_pcm_hw_rule snd_pcm_hw_rule_t; | |
221 | ||
222 | typedef int (*snd_pcm_hw_rule_func_t)(snd_pcm_hw_params_t *params, | |
223 | snd_pcm_hw_rule_t *rule); | |
224 | ||
225 | struct _snd_pcm_hw_rule { | |
226 | unsigned int cond; | |
227 | snd_pcm_hw_rule_func_t func; | |
228 | int var; | |
229 | int deps[4]; | |
230 | void *private; | |
231 | }; | |
232 | ||
233 | typedef struct _snd_pcm_hw_constraints { | |
234 | snd_mask_t masks[SNDRV_PCM_HW_PARAM_LAST_MASK - | |
235 | SNDRV_PCM_HW_PARAM_FIRST_MASK + 1]; | |
236 | snd_interval_t intervals[SNDRV_PCM_HW_PARAM_LAST_INTERVAL - | |
237 | SNDRV_PCM_HW_PARAM_FIRST_INTERVAL + 1]; | |
238 | unsigned int rules_num; | |
239 | unsigned int rules_all; | |
240 | snd_pcm_hw_rule_t *rules; | |
241 | } snd_pcm_hw_constraints_t; | |
242 | ||
243 | static inline snd_mask_t *constrs_mask(snd_pcm_hw_constraints_t *constrs, | |
244 | snd_pcm_hw_param_t var) | |
245 | { | |
246 | return &constrs->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK]; | |
247 | } | |
248 | ||
249 | static inline snd_interval_t *constrs_interval(snd_pcm_hw_constraints_t *constrs, | |
250 | snd_pcm_hw_param_t var) | |
251 | { | |
252 | return &constrs->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL]; | |
253 | } | |
254 | ||
255 | typedef struct { | |
256 | unsigned int num; | |
257 | unsigned int den_min, den_max, den_step; | |
258 | } ratnum_t; | |
259 | ||
260 | typedef struct { | |
261 | unsigned int num_min, num_max, num_step; | |
262 | unsigned int den; | |
263 | } ratden_t; | |
264 | ||
265 | typedef struct { | |
266 | int nrats; | |
267 | ratnum_t *rats; | |
268 | } snd_pcm_hw_constraint_ratnums_t; | |
269 | ||
270 | typedef struct { | |
271 | int nrats; | |
272 | ratden_t *rats; | |
273 | } snd_pcm_hw_constraint_ratdens_t; | |
274 | ||
275 | typedef struct { | |
276 | unsigned int count; | |
277 | unsigned int *list; | |
278 | unsigned int mask; | |
279 | } snd_pcm_hw_constraint_list_t; | |
280 | ||
281 | struct _snd_pcm_runtime { | |
282 | /* -- Status -- */ | |
283 | snd_pcm_substream_t *trigger_master; | |
07799e75 | 284 | struct timespec trigger_tstamp; /* trigger timestamp */ |
1da177e4 LT |
285 | int overrange; |
286 | snd_pcm_uframes_t avail_max; | |
287 | snd_pcm_uframes_t hw_ptr_base; /* Position at buffer restart */ | |
288 | snd_pcm_uframes_t hw_ptr_interrupt; /* Position at interrupt time*/ | |
289 | ||
290 | /* -- HW params -- */ | |
291 | snd_pcm_access_t access; /* access mode */ | |
292 | snd_pcm_format_t format; /* SNDRV_PCM_FORMAT_* */ | |
293 | snd_pcm_subformat_t subformat; /* subformat */ | |
294 | unsigned int rate; /* rate in Hz */ | |
295 | unsigned int channels; /* channels */ | |
296 | snd_pcm_uframes_t period_size; /* period size */ | |
297 | unsigned int periods; /* periods */ | |
298 | snd_pcm_uframes_t buffer_size; /* buffer size */ | |
299 | unsigned int tick_time; /* tick time */ | |
300 | snd_pcm_uframes_t min_align; /* Min alignment for the format */ | |
301 | size_t byte_align; | |
302 | unsigned int frame_bits; | |
303 | unsigned int sample_bits; | |
304 | unsigned int info; | |
305 | unsigned int rate_num; | |
306 | unsigned int rate_den; | |
307 | ||
308 | /* -- SW params -- */ | |
1da177e4 LT |
309 | snd_pcm_tstamp_t tstamp_mode; /* mmap timestamp is updated */ |
310 | unsigned int period_step; | |
311 | unsigned int sleep_min; /* min ticks to sleep */ | |
312 | snd_pcm_uframes_t xfer_align; /* xfer size need to be a multiple */ | |
313 | snd_pcm_uframes_t start_threshold; | |
314 | snd_pcm_uframes_t stop_threshold; | |
315 | snd_pcm_uframes_t silence_threshold; /* Silence filling happens when | |
316 | noise is nearest than this */ | |
317 | snd_pcm_uframes_t silence_size; /* Silence filling size */ | |
318 | snd_pcm_uframes_t boundary; /* pointers wrap point */ | |
319 | ||
320 | snd_pcm_uframes_t silence_start; /* starting pointer to silence area */ | |
321 | snd_pcm_uframes_t silence_filled; /* size filled with silence */ | |
322 | ||
323 | snd_pcm_sync_id_t sync; /* hardware synchronization ID */ | |
324 | ||
325 | /* -- mmap -- */ | |
326 | volatile snd_pcm_mmap_status_t *status; | |
327 | volatile snd_pcm_mmap_control_t *control; | |
328 | atomic_t mmap_count; | |
329 | ||
330 | /* -- locking / scheduling -- */ | |
331 | wait_queue_head_t sleep; | |
332 | struct timer_list tick_timer; | |
333 | struct fasync_struct *fasync; | |
334 | ||
335 | /* -- private section -- */ | |
336 | void *private_data; | |
337 | void (*private_free)(snd_pcm_runtime_t *runtime); | |
338 | ||
339 | /* -- hardware description -- */ | |
340 | snd_pcm_hardware_t hw; | |
341 | snd_pcm_hw_constraints_t hw_constraints; | |
342 | ||
343 | /* -- interrupt callbacks -- */ | |
344 | void (*transfer_ack_begin)(snd_pcm_substream_t *substream); | |
345 | void (*transfer_ack_end)(snd_pcm_substream_t *substream); | |
346 | ||
347 | /* -- timer -- */ | |
348 | unsigned int timer_resolution; /* timer resolution */ | |
349 | ||
350 | /* -- DMA -- */ | |
351 | unsigned char *dma_area; /* DMA area */ | |
352 | dma_addr_t dma_addr; /* physical bus address (not accessible from main CPU) */ | |
353 | size_t dma_bytes; /* size of DMA area */ | |
354 | ||
355 | struct snd_dma_buffer *dma_buffer_p; /* allocated buffer */ | |
356 | ||
357 | #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) | |
358 | /* -- OSS things -- */ | |
359 | snd_pcm_oss_runtime_t oss; | |
360 | #endif | |
361 | }; | |
362 | ||
363 | typedef struct _snd_pcm_group { /* keep linked substreams */ | |
364 | spinlock_t lock; | |
365 | struct list_head substreams; | |
366 | int count; | |
367 | } snd_pcm_group_t; | |
368 | ||
369 | struct _snd_pcm_substream { | |
370 | snd_pcm_t *pcm; | |
371 | snd_pcm_str_t *pstr; | |
372 | void *private_data; /* copied from pcm->private_data */ | |
373 | int number; | |
374 | char name[32]; /* substream name */ | |
375 | int stream; /* stream (direction) */ | |
376 | size_t buffer_bytes_max; /* limit ring buffer size */ | |
377 | struct snd_dma_buffer dma_buffer; | |
378 | unsigned int dma_buf_id; | |
379 | size_t dma_max; | |
380 | /* -- hardware operations -- */ | |
1da177e4 LT |
381 | snd_pcm_ops_t *ops; |
382 | /* -- runtime information -- */ | |
383 | snd_pcm_runtime_t *runtime; | |
384 | /* -- timer section -- */ | |
385 | snd_timer_t *timer; /* timer */ | |
386 | unsigned timer_running: 1; /* time is running */ | |
387 | spinlock_t timer_lock; | |
388 | /* -- next substream -- */ | |
389 | snd_pcm_substream_t *next; | |
390 | /* -- linked substreams -- */ | |
391 | struct list_head link_list; /* linked list member */ | |
392 | snd_pcm_group_t self_group; /* fake group for non linked substream (with substream lock inside) */ | |
393 | snd_pcm_group_t *group; /* pointer to current group */ | |
394 | /* -- assigned files -- */ | |
395 | snd_pcm_file_t *file; | |
396 | struct file *ffile; | |
397 | #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) | |
398 | /* -- OSS things -- */ | |
399 | snd_pcm_oss_substream_t oss; | |
400 | #endif | |
401 | snd_info_entry_t *proc_root; | |
402 | snd_info_entry_t *proc_info_entry; | |
403 | snd_info_entry_t *proc_hw_params_entry; | |
404 | snd_info_entry_t *proc_sw_params_entry; | |
405 | snd_info_entry_t *proc_status_entry; | |
406 | snd_info_entry_t *proc_prealloc_entry; | |
407 | /* misc flags */ | |
408 | unsigned int no_mmap_ctrl: 1; | |
409 | }; | |
410 | ||
411 | #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) | |
412 | #define SUBSTREAM_BUSY(substream) ((substream)->file != NULL || ((substream)->oss.file != NULL)) | |
413 | #else | |
414 | #define SUBSTREAM_BUSY(substream) ((substream)->file != NULL) | |
415 | #endif | |
416 | ||
417 | ||
418 | struct _snd_pcm_str { | |
419 | int stream; /* stream (direction) */ | |
420 | snd_pcm_t *pcm; | |
421 | /* -- substreams -- */ | |
422 | unsigned int substream_count; | |
423 | unsigned int substream_opened; | |
424 | snd_pcm_substream_t *substream; | |
425 | #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) | |
426 | /* -- OSS things -- */ | |
427 | snd_pcm_oss_stream_t oss; | |
428 | #endif | |
429 | snd_pcm_file_t *files; | |
430 | snd_minor_t *reg; | |
431 | snd_info_entry_t *proc_root; | |
432 | snd_info_entry_t *proc_info_entry; | |
433 | #ifdef CONFIG_SND_DEBUG | |
434 | unsigned int xrun_debug; /* 0 = disabled, 1 = verbose, 2 = stacktrace */ | |
435 | snd_info_entry_t *proc_xrun_debug_entry; | |
436 | #endif | |
437 | }; | |
438 | ||
439 | struct _snd_pcm { | |
440 | snd_card_t *card; | |
441 | unsigned int device; /* device number */ | |
442 | unsigned int info_flags; | |
443 | unsigned short dev_class; | |
444 | unsigned short dev_subclass; | |
445 | char id[64]; | |
446 | char name[80]; | |
447 | snd_pcm_str_t streams[2]; | |
448 | struct semaphore open_mutex; | |
449 | wait_queue_head_t open_wait; | |
450 | void *private_data; | |
451 | void (*private_free) (snd_pcm_t *pcm); | |
452 | #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE) | |
453 | snd_pcm_oss_t oss; | |
454 | #endif | |
455 | }; | |
456 | ||
457 | typedef struct _snd_pcm_notify { | |
458 | int (*n_register) (snd_pcm_t * pcm); | |
459 | int (*n_disconnect) (snd_pcm_t * pcm); | |
460 | int (*n_unregister) (snd_pcm_t * pcm); | |
461 | struct list_head list; | |
462 | } snd_pcm_notify_t; | |
463 | ||
464 | /* | |
465 | * Registering | |
466 | */ | |
467 | ||
468 | extern snd_pcm_t *snd_pcm_devices[]; | |
469 | extern snd_minor_t snd_pcm_reg[2]; | |
470 | ||
471 | int snd_pcm_new(snd_card_t * card, char *id, int device, | |
472 | int playback_count, int capture_count, | |
473 | snd_pcm_t **rpcm); | |
474 | int snd_pcm_new_stream(snd_pcm_t *pcm, int stream, int substream_count); | |
475 | ||
476 | int snd_pcm_notify(snd_pcm_notify_t *notify, int nfree); | |
477 | ||
478 | /* | |
479 | * Native I/O | |
480 | */ | |
481 | ||
482 | extern rwlock_t snd_pcm_link_rwlock; | |
483 | ||
484 | int snd_pcm_info(snd_pcm_substream_t * substream, snd_pcm_info_t *info); | |
485 | int snd_pcm_info_user(snd_pcm_substream_t * substream, snd_pcm_info_t __user *info); | |
486 | int snd_pcm_status(snd_pcm_substream_t * substream, snd_pcm_status_t *status); | |
487 | int snd_pcm_prepare(snd_pcm_substream_t *substream); | |
488 | int snd_pcm_start(snd_pcm_substream_t *substream); | |
489 | int snd_pcm_stop(snd_pcm_substream_t *substream, int status); | |
490 | int snd_pcm_drain_done(snd_pcm_substream_t *substream); | |
491 | #ifdef CONFIG_PM | |
492 | int snd_pcm_suspend(snd_pcm_substream_t *substream); | |
493 | int snd_pcm_suspend_all(snd_pcm_t *pcm); | |
494 | #endif | |
495 | int snd_pcm_kernel_playback_ioctl(snd_pcm_substream_t *substream, unsigned int cmd, void *arg); | |
496 | int snd_pcm_kernel_capture_ioctl(snd_pcm_substream_t *substream, unsigned int cmd, void *arg); | |
497 | int snd_pcm_kernel_ioctl(snd_pcm_substream_t *substream, unsigned int cmd, void *arg); | |
498 | int snd_pcm_open_substream(snd_pcm_t *pcm, int stream, snd_pcm_substream_t **rsubstream); | |
499 | void snd_pcm_release_substream(snd_pcm_substream_t *substream); | |
500 | void snd_pcm_vma_notify_data(void *client, void *data); | |
501 | int snd_pcm_mmap_data(snd_pcm_substream_t *substream, struct file *file, struct vm_area_struct *area); | |
502 | ||
503 | #if BITS_PER_LONG >= 64 | |
504 | ||
505 | static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem) | |
506 | { | |
507 | *rem = *n % div; | |
508 | *n /= div; | |
509 | } | |
510 | ||
511 | #elif defined(i386) | |
512 | ||
513 | static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem) | |
514 | { | |
515 | u_int32_t low, high; | |
516 | low = *n & 0xffffffff; | |
517 | high = *n >> 32; | |
518 | if (high) { | |
519 | u_int32_t high1 = high % div; | |
520 | high /= div; | |
521 | asm("divl %2":"=a" (low), "=d" (*rem):"rm" (div), "a" (low), "d" (high1)); | |
522 | *n = (u_int64_t)high << 32 | low; | |
523 | } else { | |
524 | *n = low / div; | |
525 | *rem = low % div; | |
526 | } | |
527 | } | |
528 | #else | |
529 | ||
530 | static inline void divl(u_int32_t high, u_int32_t low, | |
531 | u_int32_t div, | |
532 | u_int32_t *q, u_int32_t *r) | |
533 | { | |
534 | u_int64_t n = (u_int64_t)high << 32 | low; | |
535 | u_int64_t d = (u_int64_t)div << 31; | |
536 | u_int32_t q1 = 0; | |
537 | int c = 32; | |
538 | while (n > 0xffffffffU) { | |
539 | q1 <<= 1; | |
540 | if (n >= d) { | |
541 | n -= d; | |
542 | q1 |= 1; | |
543 | } | |
544 | d >>= 1; | |
545 | c--; | |
546 | } | |
547 | q1 <<= c; | |
548 | if (n) { | |
549 | low = n; | |
550 | *q = q1 | (low / div); | |
551 | *r = low % div; | |
552 | } else { | |
553 | *r = 0; | |
554 | *q = q1; | |
555 | } | |
556 | return; | |
557 | } | |
558 | ||
559 | static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem) | |
560 | { | |
561 | u_int32_t low, high; | |
562 | low = *n & 0xffffffff; | |
563 | high = *n >> 32; | |
564 | if (high) { | |
565 | u_int32_t high1 = high % div; | |
566 | u_int32_t low1 = low; | |
567 | high /= div; | |
568 | divl(high1, low1, div, &low, rem); | |
569 | *n = (u_int64_t)high << 32 | low; | |
570 | } else { | |
571 | *n = low / div; | |
572 | *rem = low % div; | |
573 | } | |
574 | } | |
575 | #endif | |
576 | ||
577 | /* | |
578 | * PCM library | |
579 | */ | |
580 | ||
581 | static inline int snd_pcm_stream_linked(snd_pcm_substream_t *substream) | |
582 | { | |
583 | return substream->group != &substream->self_group; | |
584 | } | |
585 | ||
586 | static inline void snd_pcm_stream_lock(snd_pcm_substream_t *substream) | |
587 | { | |
588 | read_lock(&snd_pcm_link_rwlock); | |
589 | spin_lock(&substream->self_group.lock); | |
590 | } | |
591 | ||
592 | static inline void snd_pcm_stream_unlock(snd_pcm_substream_t *substream) | |
593 | { | |
594 | spin_unlock(&substream->self_group.lock); | |
595 | read_unlock(&snd_pcm_link_rwlock); | |
596 | } | |
597 | ||
598 | static inline void snd_pcm_stream_lock_irq(snd_pcm_substream_t *substream) | |
599 | { | |
600 | read_lock_irq(&snd_pcm_link_rwlock); | |
601 | spin_lock(&substream->self_group.lock); | |
602 | } | |
603 | ||
604 | static inline void snd_pcm_stream_unlock_irq(snd_pcm_substream_t *substream) | |
605 | { | |
606 | spin_unlock(&substream->self_group.lock); | |
607 | read_unlock_irq(&snd_pcm_link_rwlock); | |
608 | } | |
609 | ||
610 | #define snd_pcm_stream_lock_irqsave(substream, flags) \ | |
611 | do { \ | |
612 | read_lock_irqsave(&snd_pcm_link_rwlock, (flags)); \ | |
613 | spin_lock(&substream->self_group.lock); \ | |
614 | } while (0) | |
615 | ||
616 | #define snd_pcm_stream_unlock_irqrestore(substream, flags) \ | |
617 | do { \ | |
618 | spin_unlock(&substream->self_group.lock); \ | |
619 | read_unlock_irqrestore(&snd_pcm_link_rwlock, (flags)); \ | |
620 | } while (0) | |
621 | ||
622 | #define snd_pcm_group_for_each(pos, substream) \ | |
623 | list_for_each(pos, &substream->group->substreams) | |
624 | ||
625 | #define snd_pcm_group_substream_entry(pos) \ | |
626 | list_entry(pos, snd_pcm_substream_t, link_list) | |
627 | ||
628 | static inline int snd_pcm_running(snd_pcm_substream_t *substream) | |
629 | { | |
630 | return (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING || | |
631 | (substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING && | |
632 | substream->stream == SNDRV_PCM_STREAM_PLAYBACK)); | |
633 | } | |
634 | ||
635 | static inline ssize_t bytes_to_samples(snd_pcm_runtime_t *runtime, ssize_t size) | |
636 | { | |
637 | return size * 8 / runtime->sample_bits; | |
638 | } | |
639 | ||
640 | static inline snd_pcm_sframes_t bytes_to_frames(snd_pcm_runtime_t *runtime, ssize_t size) | |
641 | { | |
642 | return size * 8 / runtime->frame_bits; | |
643 | } | |
644 | ||
645 | static inline ssize_t samples_to_bytes(snd_pcm_runtime_t *runtime, ssize_t size) | |
646 | { | |
647 | return size * runtime->sample_bits / 8; | |
648 | } | |
649 | ||
650 | static inline ssize_t frames_to_bytes(snd_pcm_runtime_t *runtime, snd_pcm_sframes_t size) | |
651 | { | |
652 | return size * runtime->frame_bits / 8; | |
653 | } | |
654 | ||
655 | static inline int frame_aligned(snd_pcm_runtime_t *runtime, ssize_t bytes) | |
656 | { | |
657 | return bytes % runtime->byte_align == 0; | |
658 | } | |
659 | ||
660 | static inline size_t snd_pcm_lib_buffer_bytes(snd_pcm_substream_t *substream) | |
661 | { | |
662 | snd_pcm_runtime_t *runtime = substream->runtime; | |
663 | return frames_to_bytes(runtime, runtime->buffer_size); | |
664 | } | |
665 | ||
666 | static inline size_t snd_pcm_lib_period_bytes(snd_pcm_substream_t *substream) | |
667 | { | |
668 | snd_pcm_runtime_t *runtime = substream->runtime; | |
669 | return frames_to_bytes(runtime, runtime->period_size); | |
670 | } | |
671 | ||
672 | /* | |
673 | * result is: 0 ... (boundary - 1) | |
674 | */ | |
675 | static inline snd_pcm_uframes_t snd_pcm_playback_avail(snd_pcm_runtime_t *runtime) | |
676 | { | |
677 | snd_pcm_sframes_t avail = runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_ptr; | |
678 | if (avail < 0) | |
679 | avail += runtime->boundary; | |
680 | else if ((snd_pcm_uframes_t) avail >= runtime->boundary) | |
681 | avail -= runtime->boundary; | |
682 | return avail; | |
683 | } | |
684 | ||
685 | /* | |
686 | * result is: 0 ... (boundary - 1) | |
687 | */ | |
688 | static inline snd_pcm_uframes_t snd_pcm_capture_avail(snd_pcm_runtime_t *runtime) | |
689 | { | |
690 | snd_pcm_sframes_t avail = runtime->status->hw_ptr - runtime->control->appl_ptr; | |
691 | if (avail < 0) | |
692 | avail += runtime->boundary; | |
693 | return avail; | |
694 | } | |
695 | ||
696 | static inline snd_pcm_sframes_t snd_pcm_playback_hw_avail(snd_pcm_runtime_t *runtime) | |
697 | { | |
698 | return runtime->buffer_size - snd_pcm_playback_avail(runtime); | |
699 | } | |
700 | ||
701 | static inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(snd_pcm_runtime_t *runtime) | |
702 | { | |
703 | return runtime->buffer_size - snd_pcm_capture_avail(runtime); | |
704 | } | |
705 | ||
706 | /** | |
707 | * snd_pcm_playback_ready - check whether the playback buffer is available | |
708 | * @substream: the pcm substream instance | |
709 | * | |
710 | * Checks whether enough free space is available on the playback buffer. | |
711 | * | |
712 | * Returns non-zero if available, or zero if not. | |
713 | */ | |
714 | static inline int snd_pcm_playback_ready(snd_pcm_substream_t *substream) | |
715 | { | |
716 | snd_pcm_runtime_t *runtime = substream->runtime; | |
717 | return snd_pcm_playback_avail(runtime) >= runtime->control->avail_min; | |
718 | } | |
719 | ||
720 | /** | |
721 | * snd_pcm_capture_ready - check whether the capture buffer is available | |
722 | * @substream: the pcm substream instance | |
723 | * | |
724 | * Checks whether enough capture data is available on the capture buffer. | |
725 | * | |
726 | * Returns non-zero if available, or zero if not. | |
727 | */ | |
728 | static inline int snd_pcm_capture_ready(snd_pcm_substream_t *substream) | |
729 | { | |
730 | snd_pcm_runtime_t *runtime = substream->runtime; | |
731 | return snd_pcm_capture_avail(runtime) >= runtime->control->avail_min; | |
732 | } | |
733 | ||
734 | /** | |
735 | * snd_pcm_playback_data - check whether any data exists on the playback buffer | |
736 | * @substream: the pcm substream instance | |
737 | * | |
738 | * Checks whether any data exists on the playback buffer. If stop_threshold | |
739 | * is bigger or equal to boundary, then this function returns always non-zero. | |
740 | * | |
741 | * Returns non-zero if exists, or zero if not. | |
742 | */ | |
743 | static inline int snd_pcm_playback_data(snd_pcm_substream_t *substream) | |
744 | { | |
745 | snd_pcm_runtime_t *runtime = substream->runtime; | |
746 | ||
747 | if (runtime->stop_threshold >= runtime->boundary) | |
748 | return 1; | |
749 | return snd_pcm_playback_avail(runtime) < runtime->buffer_size; | |
750 | } | |
751 | ||
752 | /** | |
753 | * snd_pcm_playback_empty - check whether the playback buffer is empty | |
754 | * @substream: the pcm substream instance | |
755 | * | |
756 | * Checks whether the playback buffer is empty. | |
757 | * | |
758 | * Returns non-zero if empty, or zero if not. | |
759 | */ | |
760 | static inline int snd_pcm_playback_empty(snd_pcm_substream_t *substream) | |
761 | { | |
762 | snd_pcm_runtime_t *runtime = substream->runtime; | |
763 | return snd_pcm_playback_avail(runtime) >= runtime->buffer_size; | |
764 | } | |
765 | ||
766 | /** | |
767 | * snd_pcm_capture_empty - check whether the capture buffer is empty | |
768 | * @substream: the pcm substream instance | |
769 | * | |
770 | * Checks whether the capture buffer is empty. | |
771 | * | |
772 | * Returns non-zero if empty, or zero if not. | |
773 | */ | |
774 | static inline int snd_pcm_capture_empty(snd_pcm_substream_t *substream) | |
775 | { | |
776 | snd_pcm_runtime_t *runtime = substream->runtime; | |
777 | return snd_pcm_capture_avail(runtime) == 0; | |
778 | } | |
779 | ||
780 | static inline void snd_pcm_trigger_done(snd_pcm_substream_t *substream, | |
781 | snd_pcm_substream_t *master) | |
782 | { | |
783 | substream->runtime->trigger_master = master; | |
784 | } | |
785 | ||
786 | static inline int hw_is_mask(int var) | |
787 | { | |
788 | return var >= SNDRV_PCM_HW_PARAM_FIRST_MASK && | |
789 | var <= SNDRV_PCM_HW_PARAM_LAST_MASK; | |
790 | } | |
791 | ||
792 | static inline int hw_is_interval(int var) | |
793 | { | |
794 | return var >= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL && | |
795 | var <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL; | |
796 | } | |
797 | ||
798 | static inline snd_mask_t *hw_param_mask(snd_pcm_hw_params_t *params, | |
799 | snd_pcm_hw_param_t var) | |
800 | { | |
801 | return ¶ms->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK]; | |
802 | } | |
803 | ||
804 | static inline snd_interval_t *hw_param_interval(snd_pcm_hw_params_t *params, | |
805 | snd_pcm_hw_param_t var) | |
806 | { | |
807 | return ¶ms->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL]; | |
808 | } | |
809 | ||
810 | static inline const snd_mask_t *hw_param_mask_c(const snd_pcm_hw_params_t *params, | |
811 | snd_pcm_hw_param_t var) | |
812 | { | |
813 | return (const snd_mask_t *)hw_param_mask((snd_pcm_hw_params_t*) params, var); | |
814 | } | |
815 | ||
816 | static inline const snd_interval_t *hw_param_interval_c(const snd_pcm_hw_params_t *params, | |
817 | snd_pcm_hw_param_t var) | |
818 | { | |
819 | return (const snd_interval_t *)hw_param_interval((snd_pcm_hw_params_t*) params, var); | |
820 | } | |
821 | ||
822 | #define params_access(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_ACCESS)) | |
823 | #define params_format(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_FORMAT)) | |
824 | #define params_subformat(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_SUBFORMAT)) | |
825 | #define params_channels(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_CHANNELS)->min | |
826 | #define params_rate(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_RATE)->min | |
827 | #define params_period_size(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min | |
828 | #define params_period_bytes(p) ((params_period_size(p)*snd_pcm_format_physical_width(params_format(p))*params_channels(p))/8) | |
829 | #define params_periods(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_PERIODS)->min | |
830 | #define params_buffer_size(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min | |
831 | #define params_buffer_bytes(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min | |
832 | #define params_tick_time(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_TICK_TIME)->min | |
833 | ||
834 | ||
835 | int snd_interval_refine(snd_interval_t *i, const snd_interval_t *v); | |
836 | void snd_interval_mul(const snd_interval_t *a, const snd_interval_t *b, snd_interval_t *c); | |
837 | void snd_interval_div(const snd_interval_t *a, const snd_interval_t *b, snd_interval_t *c); | |
838 | void snd_interval_muldivk(const snd_interval_t *a, const snd_interval_t *b, | |
839 | unsigned int k, snd_interval_t *c); | |
840 | void snd_interval_mulkdiv(const snd_interval_t *a, unsigned int k, | |
841 | const snd_interval_t *b, snd_interval_t *c); | |
842 | int snd_interval_list(snd_interval_t *i, unsigned int count, unsigned int *list, unsigned int mask); | |
843 | int snd_interval_ratnum(snd_interval_t *i, | |
844 | unsigned int rats_count, ratnum_t *rats, | |
845 | unsigned int *nump, unsigned int *denp); | |
846 | ||
847 | void _snd_pcm_hw_params_any(snd_pcm_hw_params_t *params); | |
848 | void _snd_pcm_hw_param_setempty(snd_pcm_hw_params_t *params, snd_pcm_hw_param_t var); | |
1da177e4 LT |
849 | int snd_pcm_hw_param_near(snd_pcm_substream_t *substream, |
850 | snd_pcm_hw_params_t *params, | |
851 | snd_pcm_hw_param_t var, | |
852 | unsigned int val, int *dir); | |
853 | int snd_pcm_hw_param_set(snd_pcm_substream_t *pcm, | |
854 | snd_pcm_hw_params_t *params, | |
855 | snd_pcm_hw_param_t var, | |
856 | unsigned int val, int dir); | |
857 | int snd_pcm_hw_params_choose(snd_pcm_substream_t *substream, snd_pcm_hw_params_t *params); | |
858 | ||
859 | int snd_pcm_hw_refine(snd_pcm_substream_t *substream, snd_pcm_hw_params_t *params); | |
1da177e4 LT |
860 | |
861 | int snd_pcm_hw_constraints_init(snd_pcm_substream_t *substream); | |
862 | int snd_pcm_hw_constraints_complete(snd_pcm_substream_t *substream); | |
863 | ||
864 | int snd_pcm_hw_constraint_mask(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var, | |
865 | u_int32_t mask); | |
866 | int snd_pcm_hw_constraint_mask64(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var, | |
867 | u_int64_t mask); | |
868 | int snd_pcm_hw_constraint_minmax(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var, | |
869 | unsigned int min, unsigned int max); | |
870 | int snd_pcm_hw_constraint_integer(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var); | |
871 | int snd_pcm_hw_constraint_list(snd_pcm_runtime_t *runtime, | |
872 | unsigned int cond, | |
873 | snd_pcm_hw_param_t var, | |
874 | snd_pcm_hw_constraint_list_t *l); | |
875 | int snd_pcm_hw_constraint_ratnums(snd_pcm_runtime_t *runtime, | |
876 | unsigned int cond, | |
877 | snd_pcm_hw_param_t var, | |
878 | snd_pcm_hw_constraint_ratnums_t *r); | |
879 | int snd_pcm_hw_constraint_ratdens(snd_pcm_runtime_t *runtime, | |
880 | unsigned int cond, | |
881 | snd_pcm_hw_param_t var, | |
882 | snd_pcm_hw_constraint_ratdens_t *r); | |
883 | int snd_pcm_hw_constraint_msbits(snd_pcm_runtime_t *runtime, | |
884 | unsigned int cond, | |
885 | unsigned int width, | |
886 | unsigned int msbits); | |
887 | int snd_pcm_hw_constraint_step(snd_pcm_runtime_t *runtime, | |
888 | unsigned int cond, | |
889 | snd_pcm_hw_param_t var, | |
890 | unsigned long step); | |
891 | int snd_pcm_hw_constraint_pow2(snd_pcm_runtime_t *runtime, | |
892 | unsigned int cond, | |
893 | snd_pcm_hw_param_t var); | |
894 | int snd_pcm_hw_rule_add(snd_pcm_runtime_t *runtime, | |
895 | unsigned int cond, | |
896 | int var, | |
897 | snd_pcm_hw_rule_func_t func, void *private, | |
898 | int dep, ...); | |
899 | ||
900 | int snd_pcm_format_signed(snd_pcm_format_t format); | |
901 | int snd_pcm_format_unsigned(snd_pcm_format_t format); | |
902 | int snd_pcm_format_linear(snd_pcm_format_t format); | |
903 | int snd_pcm_format_little_endian(snd_pcm_format_t format); | |
904 | int snd_pcm_format_big_endian(snd_pcm_format_t format); | |
1b44c28d TI |
905 | #if 0 /* just for DocBook */ |
906 | /** | |
9502dcad TI |
907 | * snd_pcm_format_cpu_endian - Check the PCM format is CPU-endian |
908 | * @format: the format to check | |
909 | * | |
910 | * Returns 1 if the given PCM format is CPU-endian, 0 if | |
911 | * opposite, or a negative error code if endian not specified. | |
912 | */ | |
8cdfd251 | 913 | int snd_pcm_format_cpu_endian(snd_pcm_format_t format); |
1b44c28d | 914 | #endif /* DocBook */ |
9502dcad | 915 | #ifdef SNDRV_LITTLE_ENDIAN |
9d01a82e | 916 | #define snd_pcm_format_cpu_endian(format) snd_pcm_format_little_endian(format) |
9502dcad | 917 | #else |
9d01a82e | 918 | #define snd_pcm_format_cpu_endian(format) snd_pcm_format_big_endian(format) |
9502dcad | 919 | #endif |
1da177e4 LT |
920 | int snd_pcm_format_width(snd_pcm_format_t format); /* in bits */ |
921 | int snd_pcm_format_physical_width(snd_pcm_format_t format); /* in bits */ | |
9502dcad | 922 | ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples); |
1da177e4 LT |
923 | const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format); |
924 | int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames); | |
925 | snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsignd, int big_endian); | |
926 | const char *snd_pcm_format_name(snd_pcm_format_t format); | |
927 | ||
928 | void snd_pcm_set_ops(snd_pcm_t * pcm, int direction, snd_pcm_ops_t *ops); | |
929 | void snd_pcm_set_sync(snd_pcm_substream_t * substream); | |
930 | int snd_pcm_lib_interleave_len(snd_pcm_substream_t *substream); | |
931 | int snd_pcm_lib_ioctl(snd_pcm_substream_t *substream, | |
932 | unsigned int cmd, void *arg); | |
933 | int snd_pcm_update_hw_ptr(snd_pcm_substream_t *substream); | |
934 | int snd_pcm_playback_xrun_check(snd_pcm_substream_t *substream); | |
935 | int snd_pcm_capture_xrun_check(snd_pcm_substream_t *substream); | |
936 | int snd_pcm_playback_xrun_asap(snd_pcm_substream_t *substream); | |
937 | int snd_pcm_capture_xrun_asap(snd_pcm_substream_t *substream); | |
938 | void snd_pcm_playback_silence(snd_pcm_substream_t *substream, snd_pcm_uframes_t new_hw_ptr); | |
939 | void snd_pcm_tick_prepare(snd_pcm_substream_t *substream); | |
940 | void snd_pcm_tick_set(snd_pcm_substream_t *substream, unsigned long ticks); | |
941 | void snd_pcm_tick_elapsed(snd_pcm_substream_t *substream); | |
942 | void snd_pcm_period_elapsed(snd_pcm_substream_t *substream); | |
943 | snd_pcm_sframes_t snd_pcm_lib_write(snd_pcm_substream_t *substream, | |
944 | const void __user *buf, | |
945 | snd_pcm_uframes_t frames); | |
946 | snd_pcm_sframes_t snd_pcm_lib_read(snd_pcm_substream_t *substream, | |
947 | void __user *buf, snd_pcm_uframes_t frames); | |
948 | snd_pcm_sframes_t snd_pcm_lib_writev(snd_pcm_substream_t *substream, | |
949 | void __user **bufs, snd_pcm_uframes_t frames); | |
950 | snd_pcm_sframes_t snd_pcm_lib_readv(snd_pcm_substream_t *substream, | |
951 | void __user **bufs, snd_pcm_uframes_t frames); | |
952 | ||
953 | int snd_pcm_limit_hw_rates(snd_pcm_runtime_t *runtime); | |
954 | ||
955 | static inline void snd_pcm_set_runtime_buffer(snd_pcm_substream_t *substream, | |
956 | struct snd_dma_buffer *bufp) | |
957 | { | |
958 | snd_pcm_runtime_t *runtime = substream->runtime; | |
959 | if (bufp) { | |
960 | runtime->dma_buffer_p = bufp; | |
961 | runtime->dma_area = bufp->area; | |
962 | runtime->dma_addr = bufp->addr; | |
963 | runtime->dma_bytes = bufp->bytes; | |
964 | } else { | |
965 | runtime->dma_buffer_p = NULL; | |
966 | runtime->dma_area = NULL; | |
967 | runtime->dma_addr = 0; | |
968 | runtime->dma_bytes = 0; | |
969 | } | |
970 | } | |
971 | ||
972 | /* | |
973 | * Timer interface | |
974 | */ | |
975 | ||
976 | void snd_pcm_timer_resolution_change(snd_pcm_substream_t *substream); | |
977 | void snd_pcm_timer_init(snd_pcm_substream_t * substream); | |
978 | void snd_pcm_timer_done(snd_pcm_substream_t * substream); | |
979 | ||
980 | /* | |
981 | * Memory | |
982 | */ | |
983 | ||
984 | int snd_pcm_lib_preallocate_free(snd_pcm_substream_t *substream); | |
985 | int snd_pcm_lib_preallocate_free_for_all(snd_pcm_t *pcm); | |
986 | int snd_pcm_lib_preallocate_pages(snd_pcm_substream_t *substream, | |
987 | int type, struct device *data, | |
988 | size_t size, size_t max); | |
989 | int snd_pcm_lib_preallocate_pages_for_all(snd_pcm_t *pcm, | |
990 | int type, void *data, | |
991 | size_t size, size_t max); | |
992 | int snd_pcm_lib_malloc_pages(snd_pcm_substream_t *substream, size_t size); | |
993 | int snd_pcm_lib_free_pages(snd_pcm_substream_t *substream); | |
994 | ||
995 | #define snd_pcm_substream_sgbuf(substream) ((substream)->runtime->dma_buffer_p->private_data) | |
996 | #define snd_pcm_sgbuf_pages(size) snd_sgbuf_aligned_pages(size) | |
997 | #define snd_pcm_sgbuf_get_addr(sgbuf,ofs) snd_sgbuf_get_addr(sgbuf,ofs) | |
998 | struct page *snd_pcm_sgbuf_ops_page(snd_pcm_substream_t *substream, unsigned long offset); | |
999 | ||
1000 | /* handle mmap counter - PCM mmap callback should handle this counter properly */ | |
1001 | static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area) | |
1002 | { | |
1003 | snd_pcm_substream_t *substream = (snd_pcm_substream_t *)area->vm_private_data; | |
1004 | atomic_inc(&substream->runtime->mmap_count); | |
1005 | } | |
1006 | ||
1007 | static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area) | |
1008 | { | |
1009 | snd_pcm_substream_t *substream = (snd_pcm_substream_t *)area->vm_private_data; | |
1010 | atomic_dec(&substream->runtime->mmap_count); | |
1011 | } | |
1012 | ||
1013 | /* mmap for io-memory area */ | |
1014 | #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA) | |
1015 | #define SNDRV_PCM_INFO_MMAP_IOMEM SNDRV_PCM_INFO_MMAP | |
1016 | int snd_pcm_lib_mmap_iomem(snd_pcm_substream_t *substream, struct vm_area_struct *area); | |
1017 | #else | |
1018 | #define SNDRV_PCM_INFO_MMAP_IOMEM 0 | |
1019 | #define snd_pcm_lib_mmap_iomem NULL | |
1020 | #endif | |
1021 | ||
1022 | static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max) | |
1023 | { | |
1024 | *max = dma < 4 ? 64 * 1024 : 128 * 1024; | |
1025 | } | |
1026 | ||
1027 | /* | |
1028 | * Misc | |
1029 | */ | |
1030 | ||
1031 | #define SNDRV_PCM_DEFAULT_CON_SPDIF (IEC958_AES0_CON_EMPHASIS_NONE|\ | |
1032 | (IEC958_AES1_CON_ORIGINAL<<8)|\ | |
1033 | (IEC958_AES1_CON_PCM_CODER<<8)|\ | |
1034 | (IEC958_AES3_CON_FS_48000<<24)) | |
1035 | ||
1036 | #endif /* __SOUND_PCM_H */ |