This commit was manufactured by cvs2svn to create branch
[linux-2.6.git] / include / sound / pcm.h
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;
284         snd_timestamp_t trigger_tstamp; /* trigger timestamp */
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 -- */
309         int tstamp_timespec;            /* use timeval (0) or timespec (1) */
310         snd_pcm_tstamp_t tstamp_mode;   /* mmap timestamp is updated */
311         unsigned int period_step;
312         unsigned int sleep_min;         /* min ticks to sleep */
313         snd_pcm_uframes_t xfer_align;   /* xfer size need to be a multiple */
314         snd_pcm_uframes_t start_threshold;
315         snd_pcm_uframes_t stop_threshold;
316         snd_pcm_uframes_t silence_threshold; /* Silence filling happens when
317                                                 noise is nearest than this */
318         snd_pcm_uframes_t silence_size; /* Silence filling size */
319         snd_pcm_uframes_t boundary;     /* pointers wrap point */
320
321         snd_pcm_uframes_t silence_start; /* starting pointer to silence area */
322         snd_pcm_uframes_t silence_filled; /* size filled with silence */
323
324         snd_pcm_sync_id_t sync;         /* hardware synchronization ID */
325
326         /* -- mmap -- */
327         volatile snd_pcm_mmap_status_t *status;
328         volatile snd_pcm_mmap_control_t *control;
329         atomic_t mmap_count;
330
331         /* -- locking / scheduling -- */
332         wait_queue_head_t sleep;
333         struct timer_list tick_timer;
334         struct fasync_struct *fasync;
335
336         /* -- private section -- */
337         void *private_data;
338         void (*private_free)(snd_pcm_runtime_t *runtime);
339
340         /* -- hardware description -- */
341         snd_pcm_hardware_t hw;
342         snd_pcm_hw_constraints_t hw_constraints;
343
344         /* -- interrupt callbacks -- */
345         void (*transfer_ack_begin)(snd_pcm_substream_t *substream);
346         void (*transfer_ack_end)(snd_pcm_substream_t *substream);
347
348         /* -- timer -- */
349         unsigned int timer_resolution;  /* timer resolution */
350
351         /* -- DMA -- */           
352         unsigned char *dma_area;        /* DMA area */
353         dma_addr_t dma_addr;            /* physical bus address (not accessible from main CPU) */
354         size_t dma_bytes;               /* size of DMA area */
355
356         struct snd_dma_buffer *dma_buffer_p;    /* allocated buffer */
357
358 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
359         /* -- OSS things -- */
360         snd_pcm_oss_runtime_t oss;
361 #endif
362 };
363
364 typedef struct _snd_pcm_group {         /* keep linked substreams */
365         spinlock_t lock;
366         struct list_head substreams;
367         int count;
368 } snd_pcm_group_t;
369
370 struct _snd_pcm_substream {
371         snd_pcm_t *pcm;
372         snd_pcm_str_t *pstr;
373         void *private_data;             /* copied from pcm->private_data */
374         int number;
375         char name[32];                  /* substream name */
376         int stream;                     /* stream (direction) */
377         size_t buffer_bytes_max;        /* limit ring buffer size */
378         struct snd_dma_buffer dma_buffer;
379         unsigned int dma_buf_id;
380         size_t dma_max;
381         /* -- hardware operations -- */
382         unsigned int open_flag: 1;      /* lowlevel device has been opened */
383         snd_pcm_ops_t *ops;
384         /* -- runtime information -- */
385         snd_pcm_runtime_t *runtime;
386         /* -- timer section -- */
387         snd_timer_t *timer;             /* timer */
388         unsigned timer_running: 1;      /* time is running */
389         spinlock_t timer_lock;
390         /* -- next substream -- */
391         snd_pcm_substream_t *next;
392         /* -- linked substreams -- */
393         struct list_head link_list;     /* linked list member */
394         snd_pcm_group_t self_group;     /* fake group for non linked substream (with substream lock inside) */
395         snd_pcm_group_t *group;         /* pointer to current group */
396         /* -- assigned files -- */
397         snd_pcm_file_t *file;
398         struct file *ffile;
399 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
400         /* -- OSS things -- */
401         snd_pcm_oss_substream_t oss;
402 #endif
403         snd_info_entry_t *proc_root;
404         snd_info_entry_t *proc_info_entry;
405         snd_info_entry_t *proc_hw_params_entry;
406         snd_info_entry_t *proc_sw_params_entry;
407         snd_info_entry_t *proc_status_entry;
408         snd_info_entry_t *proc_prealloc_entry;
409         /* misc flags */
410         unsigned int no_mmap_ctrl: 1;
411 };
412
413 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
414 #define SUBSTREAM_BUSY(substream) ((substream)->file != NULL || ((substream)->oss.file != NULL))
415 #else
416 #define SUBSTREAM_BUSY(substream) ((substream)->file != NULL)
417 #endif
418
419
420 struct _snd_pcm_str {
421         int stream;                             /* stream (direction) */
422         snd_pcm_t *pcm;
423         /* -- substreams -- */
424         unsigned int substream_count;
425         unsigned int substream_opened;
426         snd_pcm_substream_t *substream;
427 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
428         /* -- OSS things -- */
429         snd_pcm_oss_stream_t oss;
430 #endif
431         snd_pcm_file_t *files;
432         snd_minor_t *reg;
433         snd_info_entry_t *proc_root;
434         snd_info_entry_t *proc_info_entry;
435 #ifdef CONFIG_SND_DEBUG
436         unsigned int xrun_debug;        /* 0 = disabled, 1 = verbose, 2 = stacktrace */
437         snd_info_entry_t *proc_xrun_debug_entry;
438 #endif
439 };
440
441 struct _snd_pcm {
442         snd_card_t *card;
443         unsigned int device;    /* device number */
444         unsigned int info_flags;
445         unsigned short dev_class;
446         unsigned short dev_subclass;
447         char id[64];
448         char name[80];
449         snd_pcm_str_t streams[2];
450         struct semaphore open_mutex;
451         wait_queue_head_t open_wait;
452         void *private_data;
453         void (*private_free) (snd_pcm_t *pcm);
454 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
455         snd_pcm_oss_t oss;
456 #endif
457 };
458
459 typedef struct _snd_pcm_notify {
460         int (*n_register) (snd_pcm_t * pcm);
461         int (*n_disconnect) (snd_pcm_t * pcm);
462         int (*n_unregister) (snd_pcm_t * pcm);
463         struct list_head list;
464 } snd_pcm_notify_t;
465
466 /*
467  *  Registering
468  */
469
470 extern snd_pcm_t *snd_pcm_devices[];
471 extern snd_minor_t snd_pcm_reg[2];
472
473 int snd_pcm_new(snd_card_t * card, char *id, int device,
474                 int playback_count, int capture_count,
475                 snd_pcm_t **rpcm);
476 int snd_pcm_new_stream(snd_pcm_t *pcm, int stream, int substream_count);
477
478 int snd_pcm_notify(snd_pcm_notify_t *notify, int nfree);
479
480 /*
481  *  Native I/O
482  */
483
484 extern rwlock_t snd_pcm_link_rwlock;
485
486 int snd_pcm_info(snd_pcm_substream_t * substream, snd_pcm_info_t *info);
487 int snd_pcm_info_user(snd_pcm_substream_t * substream, snd_pcm_info_t __user *info);
488 int snd_pcm_status(snd_pcm_substream_t * substream, snd_pcm_status_t *status);
489 int snd_pcm_prepare(snd_pcm_substream_t *substream);
490 int snd_pcm_start(snd_pcm_substream_t *substream);
491 int snd_pcm_stop(snd_pcm_substream_t *substream, int status);
492 int snd_pcm_drain_done(snd_pcm_substream_t *substream);
493 #ifdef CONFIG_PM
494 int snd_pcm_suspend(snd_pcm_substream_t *substream);
495 int snd_pcm_suspend_all(snd_pcm_t *pcm);
496 #endif
497 int snd_pcm_kernel_playback_ioctl(snd_pcm_substream_t *substream, unsigned int cmd, void *arg);
498 int snd_pcm_kernel_capture_ioctl(snd_pcm_substream_t *substream, unsigned int cmd, void *arg);
499 int snd_pcm_kernel_ioctl(snd_pcm_substream_t *substream, unsigned int cmd, void *arg);
500 int snd_pcm_open(struct inode *inode, struct file *file);
501 int snd_pcm_release(struct inode *inode, struct file *file);
502 unsigned int snd_pcm_playback_poll(struct file *file, poll_table * wait);
503 unsigned int snd_pcm_capture_poll(struct file *file, poll_table * wait);
504 int snd_pcm_open_substream(snd_pcm_t *pcm, int stream, snd_pcm_substream_t **rsubstream);
505 void snd_pcm_release_substream(snd_pcm_substream_t *substream);
506 void snd_pcm_vma_notify_data(void *client, void *data);
507 int snd_pcm_mmap_data(snd_pcm_substream_t *substream, struct file *file, struct vm_area_struct *area);
508
509 #if BITS_PER_LONG >= 64
510
511 static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
512 {
513         *rem = *n % div;
514         *n /= div;
515 }
516
517 #elif defined(i386)
518
519 static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
520 {
521         u_int32_t low, high;
522         low = *n & 0xffffffff;
523         high = *n >> 32;
524         if (high) {
525                 u_int32_t high1 = high % div;
526                 high /= div;
527                 asm("divl %2":"=a" (low), "=d" (*rem):"rm" (div), "a" (low), "d" (high1));
528                 *n = (u_int64_t)high << 32 | low;
529         } else {
530                 *n = low / div;
531                 *rem = low % div;
532         }
533 }
534 #else
535
536 static inline void divl(u_int32_t high, u_int32_t low,
537                         u_int32_t div,
538                         u_int32_t *q, u_int32_t *r)
539 {
540         u_int64_t n = (u_int64_t)high << 32 | low;
541         u_int64_t d = (u_int64_t)div << 31;
542         u_int32_t q1 = 0;
543         int c = 32;
544         while (n > 0xffffffffU) {
545                 q1 <<= 1;
546                 if (n >= d) {
547                         n -= d;
548                         q1 |= 1;
549                 }
550                 d >>= 1;
551                 c--;
552         }
553         q1 <<= c;
554         if (n) {
555                 low = n;
556                 *q = q1 | (low / div);
557                 *r = low % div;
558         } else {
559                 *r = 0;
560                 *q = q1;
561         }
562         return;
563 }
564
565 static inline void div64_32(u_int64_t *n, u_int32_t div, u_int32_t *rem)
566 {
567         u_int32_t low, high;
568         low = *n & 0xffffffff;
569         high = *n >> 32;
570         if (high) {
571                 u_int32_t high1 = high % div;
572                 u_int32_t low1 = low;
573                 high /= div;
574                 divl(high1, low1, div, &low, rem);
575                 *n = (u_int64_t)high << 32 | low;
576         } else {
577                 *n = low / div;
578                 *rem = low % div;
579         }
580 }
581 #endif
582
583 /*
584  *  PCM library
585  */
586
587 static inline int snd_pcm_stream_linked(snd_pcm_substream_t *substream)
588 {
589         return substream->group != &substream->self_group;
590 }
591
592 static inline void snd_pcm_stream_lock(snd_pcm_substream_t *substream)
593 {
594         read_lock(&snd_pcm_link_rwlock);
595         spin_lock(&substream->self_group.lock);
596 }
597
598 static inline void snd_pcm_stream_unlock(snd_pcm_substream_t *substream)
599 {
600         spin_unlock(&substream->self_group.lock);
601         read_unlock(&snd_pcm_link_rwlock);
602 }
603
604 static inline void snd_pcm_stream_lock_irq(snd_pcm_substream_t *substream)
605 {
606         read_lock_irq(&snd_pcm_link_rwlock);
607         spin_lock(&substream->self_group.lock);
608 }
609
610 static inline void snd_pcm_stream_unlock_irq(snd_pcm_substream_t *substream)
611 {
612         spin_unlock(&substream->self_group.lock);
613         read_unlock_irq(&snd_pcm_link_rwlock);
614 }
615
616 #define snd_pcm_stream_lock_irqsave(substream, flags) \
617 do { \
618         read_lock_irqsave(&snd_pcm_link_rwlock, (flags)); \
619         spin_lock(&substream->self_group.lock); \
620 } while (0)
621
622 #define snd_pcm_stream_unlock_irqrestore(substream, flags) \
623 do { \
624         spin_unlock(&substream->self_group.lock); \
625         read_unlock_irqrestore(&snd_pcm_link_rwlock, (flags)); \
626 } while (0)
627
628 #define snd_pcm_group_for_each(pos, substream) \
629         list_for_each(pos, &substream->group->substreams)
630
631 #define snd_pcm_group_substream_entry(pos) \
632         list_entry(pos, snd_pcm_substream_t, link_list)
633
634 static inline int snd_pcm_running(snd_pcm_substream_t *substream)
635 {
636         return (substream->runtime->status->state == SNDRV_PCM_STATE_RUNNING ||
637                 (substream->runtime->status->state == SNDRV_PCM_STATE_DRAINING &&
638                  substream->stream == SNDRV_PCM_STREAM_PLAYBACK));
639 }
640
641 static inline ssize_t bytes_to_samples(snd_pcm_runtime_t *runtime, ssize_t size)
642 {
643         return size * 8 / runtime->sample_bits;
644 }
645
646 static inline snd_pcm_sframes_t bytes_to_frames(snd_pcm_runtime_t *runtime, ssize_t size)
647 {
648         return size * 8 / runtime->frame_bits;
649 }
650
651 static inline ssize_t samples_to_bytes(snd_pcm_runtime_t *runtime, ssize_t size)
652 {
653         return size * runtime->sample_bits / 8;
654 }
655
656 static inline ssize_t frames_to_bytes(snd_pcm_runtime_t *runtime, snd_pcm_sframes_t size)
657 {
658         return size * runtime->frame_bits / 8;
659 }
660
661 static inline int frame_aligned(snd_pcm_runtime_t *runtime, ssize_t bytes)
662 {
663         return bytes % runtime->byte_align == 0;
664 }
665
666 static inline size_t snd_pcm_lib_buffer_bytes(snd_pcm_substream_t *substream)
667 {
668         snd_pcm_runtime_t *runtime = substream->runtime;
669         return frames_to_bytes(runtime, runtime->buffer_size);
670 }
671
672 static inline size_t snd_pcm_lib_period_bytes(snd_pcm_substream_t *substream)
673 {
674         snd_pcm_runtime_t *runtime = substream->runtime;
675         return frames_to_bytes(runtime, runtime->period_size);
676 }
677
678 /*
679  *  result is: 0 ... (boundary - 1)
680  */
681 static inline snd_pcm_uframes_t snd_pcm_playback_avail(snd_pcm_runtime_t *runtime)
682 {
683         snd_pcm_sframes_t avail = runtime->status->hw_ptr + runtime->buffer_size - runtime->control->appl_ptr;
684         if (avail < 0)
685                 avail += runtime->boundary;
686         else if ((snd_pcm_uframes_t) avail >= runtime->boundary)
687                 avail -= runtime->boundary;
688         return avail;
689 }
690
691 /*
692  *  result is: 0 ... (boundary - 1)
693  */
694 static inline snd_pcm_uframes_t snd_pcm_capture_avail(snd_pcm_runtime_t *runtime)
695 {
696         snd_pcm_sframes_t avail = runtime->status->hw_ptr - runtime->control->appl_ptr;
697         if (avail < 0)
698                 avail += runtime->boundary;
699         return avail;
700 }
701
702 static inline snd_pcm_sframes_t snd_pcm_playback_hw_avail(snd_pcm_runtime_t *runtime)
703 {
704         return runtime->buffer_size - snd_pcm_playback_avail(runtime);
705 }
706
707 static inline snd_pcm_sframes_t snd_pcm_capture_hw_avail(snd_pcm_runtime_t *runtime)
708 {
709         return runtime->buffer_size - snd_pcm_capture_avail(runtime);
710 }
711
712 static inline void snd_pcm_trigger_done(snd_pcm_substream_t *substream, 
713                                         snd_pcm_substream_t *master)
714 {
715         substream->runtime->trigger_master = master;
716 }
717
718 static inline int hw_is_mask(int var)
719 {
720         return var >= SNDRV_PCM_HW_PARAM_FIRST_MASK &&
721                 var <= SNDRV_PCM_HW_PARAM_LAST_MASK;
722 }
723
724 static inline int hw_is_interval(int var)
725 {
726         return var >= SNDRV_PCM_HW_PARAM_FIRST_INTERVAL &&
727                 var <= SNDRV_PCM_HW_PARAM_LAST_INTERVAL;
728 }
729
730 static inline snd_mask_t *hw_param_mask(snd_pcm_hw_params_t *params,
731                                      snd_pcm_hw_param_t var)
732 {
733         return &params->masks[var - SNDRV_PCM_HW_PARAM_FIRST_MASK];
734 }
735
736 static inline snd_interval_t *hw_param_interval(snd_pcm_hw_params_t *params,
737                                              snd_pcm_hw_param_t var)
738 {
739         return &params->intervals[var - SNDRV_PCM_HW_PARAM_FIRST_INTERVAL];
740 }
741
742 static inline const snd_mask_t *hw_param_mask_c(const snd_pcm_hw_params_t *params,
743                                              snd_pcm_hw_param_t var)
744 {
745         return (const snd_mask_t *)hw_param_mask((snd_pcm_hw_params_t*) params, var);
746 }
747
748 static inline const snd_interval_t *hw_param_interval_c(const snd_pcm_hw_params_t *params,
749                                                      snd_pcm_hw_param_t var)
750 {
751         return (const snd_interval_t *)hw_param_interval((snd_pcm_hw_params_t*) params, var);
752 }
753
754 #define params_access(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_ACCESS))
755 #define params_format(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_FORMAT))
756 #define params_subformat(p) snd_mask_min(hw_param_mask((p), SNDRV_PCM_HW_PARAM_SUBFORMAT))
757 #define params_channels(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_CHANNELS)->min
758 #define params_rate(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_RATE)->min
759 #define params_period_size(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_PERIOD_SIZE)->min
760 #define params_period_bytes(p) ((params_period_size(p)*snd_pcm_format_physical_width(params_format(p))*params_channels(p))/8)
761 #define params_periods(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_PERIODS)->min
762 #define params_buffer_size(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_SIZE)->min
763 #define params_buffer_bytes(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_BUFFER_BYTES)->min
764 #define params_tick_time(p) hw_param_interval((p), SNDRV_PCM_HW_PARAM_TICK_TIME)->min
765
766
767 int snd_interval_refine(snd_interval_t *i, const snd_interval_t *v);
768 void snd_interval_mul(const snd_interval_t *a, const snd_interval_t *b, snd_interval_t *c);
769 void snd_interval_div(const snd_interval_t *a, const snd_interval_t *b, snd_interval_t *c);
770 void snd_interval_muldivk(const snd_interval_t *a, const snd_interval_t *b, 
771                           unsigned int k, snd_interval_t *c);
772 void snd_interval_mulkdiv(const snd_interval_t *a, unsigned int k,
773                           const snd_interval_t *b, snd_interval_t *c);
774 int snd_interval_list(snd_interval_t *i, unsigned int count, unsigned int *list, unsigned int mask);
775 int snd_interval_step(snd_interval_t *i, unsigned int min, unsigned int step);
776 int snd_interval_ratnum(snd_interval_t *i,
777                         unsigned int rats_count, ratnum_t *rats,
778                         unsigned int *nump, unsigned int *denp);
779 int snd_interval_ratden(snd_interval_t *i,
780                         unsigned int rats_count, ratden_t *rats,
781                         unsigned int *nump, unsigned int *denp);
782
783 void _snd_pcm_hw_params_any(snd_pcm_hw_params_t *params);
784 void _snd_pcm_hw_param_setempty(snd_pcm_hw_params_t *params, snd_pcm_hw_param_t var);
785 int snd_pcm_hw_param_min(snd_pcm_substream_t *substream, 
786                          snd_pcm_hw_params_t *params,
787                          snd_pcm_hw_param_t var,
788                          unsigned int val, int *dir);
789 int snd_pcm_hw_param_max(snd_pcm_substream_t *substream, 
790                          snd_pcm_hw_params_t *params,
791                          snd_pcm_hw_param_t var,
792                          unsigned int val, int *dir);
793 int snd_pcm_hw_param_setinteger(snd_pcm_substream_t *substream, 
794                                 snd_pcm_hw_params_t *params,
795                                 snd_pcm_hw_param_t var);
796 int snd_pcm_hw_param_first(snd_pcm_substream_t *substream, 
797                            snd_pcm_hw_params_t *params,
798                            snd_pcm_hw_param_t var, int *dir);
799 int snd_pcm_hw_param_last(snd_pcm_substream_t *substream, 
800                           snd_pcm_hw_params_t *params,
801                           snd_pcm_hw_param_t var, int *dir);
802 int snd_pcm_hw_param_near(snd_pcm_substream_t *substream, 
803                           snd_pcm_hw_params_t *params,
804                           snd_pcm_hw_param_t var, 
805                           unsigned int val, int *dir);
806 int snd_pcm_hw_param_set(snd_pcm_substream_t *pcm,
807                          snd_pcm_hw_params_t *params,
808                          snd_pcm_hw_param_t var,
809                          unsigned int val, int dir);
810 int snd_pcm_hw_params_choose(snd_pcm_substream_t *substream, snd_pcm_hw_params_t *params);
811
812 int snd_pcm_hw_refine(snd_pcm_substream_t *substream, snd_pcm_hw_params_t *params);
813 int snd_pcm_hw_params(snd_pcm_substream_t *substream, snd_pcm_hw_params_t *params);
814
815 int snd_pcm_hw_constraints_init(snd_pcm_substream_t *substream);
816 int snd_pcm_hw_constraints_complete(snd_pcm_substream_t *substream);
817
818 int snd_pcm_hw_constraint_mask(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var,
819                                u_int32_t mask);
820 int snd_pcm_hw_constraint_mask64(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var,
821                                  u_int64_t mask);
822 int snd_pcm_hw_constraint_minmax(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var,
823                                  unsigned int min, unsigned int max);
824 int snd_pcm_hw_constraint_integer(snd_pcm_runtime_t *runtime, snd_pcm_hw_param_t var);
825 int snd_pcm_hw_constraint_list(snd_pcm_runtime_t *runtime, 
826                                unsigned int cond,
827                                snd_pcm_hw_param_t var,
828                                snd_pcm_hw_constraint_list_t *l);
829 int snd_pcm_hw_constraint_ratnums(snd_pcm_runtime_t *runtime, 
830                                   unsigned int cond,
831                                   snd_pcm_hw_param_t var,
832                                   snd_pcm_hw_constraint_ratnums_t *r);
833 int snd_pcm_hw_constraint_ratdens(snd_pcm_runtime_t *runtime, 
834                                   unsigned int cond,
835                                   snd_pcm_hw_param_t var,
836                                   snd_pcm_hw_constraint_ratdens_t *r);
837 int snd_pcm_hw_constraint_msbits(snd_pcm_runtime_t *runtime, 
838                                  unsigned int cond,
839                                  unsigned int width,
840                                  unsigned int msbits);
841 int snd_pcm_hw_constraint_step(snd_pcm_runtime_t *runtime,
842                                unsigned int cond,
843                                snd_pcm_hw_param_t var,
844                                unsigned long step);
845 int snd_pcm_hw_constraint_pow2(snd_pcm_runtime_t *runtime,
846                                unsigned int cond,
847                                snd_pcm_hw_param_t var);
848 int snd_pcm_hw_rule_add(snd_pcm_runtime_t *runtime,
849                         unsigned int cond,
850                         int var,
851                         snd_pcm_hw_rule_func_t func, void *private,
852                         int dep, ...);
853
854 int snd_pcm_format_signed(snd_pcm_format_t format);
855 int snd_pcm_format_unsigned(snd_pcm_format_t format);
856 int snd_pcm_format_linear(snd_pcm_format_t format);
857 int snd_pcm_format_little_endian(snd_pcm_format_t format);
858 int snd_pcm_format_big_endian(snd_pcm_format_t format);
859 int snd_pcm_format_width(snd_pcm_format_t format);                      /* in bits */
860 int snd_pcm_format_physical_width(snd_pcm_format_t format);             /* in bits */
861 const unsigned char *snd_pcm_format_silence_64(snd_pcm_format_t format);
862 int snd_pcm_format_set_silence(snd_pcm_format_t format, void *buf, unsigned int frames);
863 snd_pcm_format_t snd_pcm_build_linear_format(int width, int unsignd, int big_endian);
864 ssize_t snd_pcm_format_size(snd_pcm_format_t format, size_t samples);
865 const char *snd_pcm_format_name(snd_pcm_format_t format);
866 const char *snd_pcm_subformat_name(snd_pcm_subformat_t subformat);
867
868 void snd_pcm_set_ops(snd_pcm_t * pcm, int direction, snd_pcm_ops_t *ops);
869 void snd_pcm_set_sync(snd_pcm_substream_t * substream);
870 int snd_pcm_lib_interleave_len(snd_pcm_substream_t *substream);
871 int snd_pcm_lib_ioctl(snd_pcm_substream_t *substream,
872                       unsigned int cmd, void *arg);                      
873 int snd_pcm_update_hw_ptr(snd_pcm_substream_t *substream);
874 int snd_pcm_playback_xrun_check(snd_pcm_substream_t *substream);
875 int snd_pcm_capture_xrun_check(snd_pcm_substream_t *substream);
876 int snd_pcm_playback_xrun_asap(snd_pcm_substream_t *substream);
877 int snd_pcm_capture_xrun_asap(snd_pcm_substream_t *substream);
878 void snd_pcm_playback_silence(snd_pcm_substream_t *substream, snd_pcm_uframes_t new_hw_ptr);
879 int snd_pcm_playback_ready(snd_pcm_substream_t *substream);
880 int snd_pcm_capture_ready(snd_pcm_substream_t *substream);
881 long snd_pcm_playback_ready_jiffies(snd_pcm_substream_t *substream);
882 long snd_pcm_capture_ready_jiffies(snd_pcm_substream_t *substream);
883 int snd_pcm_playback_data(snd_pcm_substream_t *substream);
884 int snd_pcm_playback_empty(snd_pcm_substream_t *substream);
885 int snd_pcm_capture_empty(snd_pcm_substream_t *substream);
886 void snd_pcm_tick_prepare(snd_pcm_substream_t *substream);
887 void snd_pcm_tick_set(snd_pcm_substream_t *substream, unsigned long ticks);
888 void snd_pcm_tick_elapsed(snd_pcm_substream_t *substream);
889 void snd_pcm_period_elapsed(snd_pcm_substream_t *substream);
890 snd_pcm_sframes_t snd_pcm_lib_write(snd_pcm_substream_t *substream,
891                                     const void __user *buf,
892                                     snd_pcm_uframes_t frames);
893 snd_pcm_sframes_t snd_pcm_lib_read(snd_pcm_substream_t *substream,
894                                    void __user *buf, snd_pcm_uframes_t frames);
895 snd_pcm_sframes_t snd_pcm_lib_writev(snd_pcm_substream_t *substream,
896                                      void __user **bufs, snd_pcm_uframes_t frames);
897 snd_pcm_sframes_t snd_pcm_lib_readv(snd_pcm_substream_t *substream,
898                                     void __user **bufs, snd_pcm_uframes_t frames);
899
900 int snd_pcm_limit_hw_rates(snd_pcm_runtime_t *runtime);
901
902 static inline void snd_pcm_set_runtime_buffer(snd_pcm_substream_t *substream,
903                                               struct snd_dma_buffer *bufp)
904 {
905         snd_pcm_runtime_t *runtime = substream->runtime;
906         if (bufp) {
907                 runtime->dma_buffer_p = bufp;
908                 runtime->dma_area = bufp->area;
909                 runtime->dma_addr = bufp->addr;
910                 runtime->dma_bytes = bufp->bytes;
911         } else {
912                 runtime->dma_buffer_p = NULL;
913                 runtime->dma_area = NULL;
914                 runtime->dma_addr = 0;
915                 runtime->dma_bytes = 0;
916         }
917 }
918
919 /*
920  *  Timer interface
921  */
922
923 void snd_pcm_timer_resolution_change(snd_pcm_substream_t *substream);
924 void snd_pcm_timer_init(snd_pcm_substream_t * substream);
925 void snd_pcm_timer_done(snd_pcm_substream_t * substream);
926
927 /*
928  *  Memory
929  */
930
931 int snd_pcm_lib_preallocate_free(snd_pcm_substream_t *substream);
932 int snd_pcm_lib_preallocate_free_for_all(snd_pcm_t *pcm);
933 int snd_pcm_lib_preallocate_pages(snd_pcm_substream_t *substream,
934                                   int type, struct device *data,
935                                   size_t size, size_t max);
936 int snd_pcm_lib_preallocate_pages_for_all(snd_pcm_t *pcm,
937                                           int type, void *data,
938                                           size_t size, size_t max);
939 int snd_pcm_lib_malloc_pages(snd_pcm_substream_t *substream, size_t size);
940 int snd_pcm_lib_free_pages(snd_pcm_substream_t *substream);
941
942 #define snd_pcm_substream_sgbuf(substream) ((substream)->runtime->dma_buffer_p->private_data)
943 #define snd_pcm_sgbuf_pages(size) snd_sgbuf_aligned_pages(size)
944 #define snd_pcm_sgbuf_get_addr(sgbuf,ofs) snd_sgbuf_get_addr(sgbuf,ofs)
945 struct page *snd_pcm_sgbuf_ops_page(snd_pcm_substream_t *substream, unsigned long offset);
946
947 /* handle mmap counter - PCM mmap callback should handle this counter properly */
948 static inline void snd_pcm_mmap_data_open(struct vm_area_struct *area)
949 {
950         snd_pcm_substream_t *substream = (snd_pcm_substream_t *)area->vm_private_data;
951         atomic_inc(&substream->runtime->mmap_count);
952 }
953
954 static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area)
955 {
956         snd_pcm_substream_t *substream = (snd_pcm_substream_t *)area->vm_private_data;
957         atomic_dec(&substream->runtime->mmap_count);
958 }
959
960 /* mmap for io-memory area */
961 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
962 #define SNDRV_PCM_INFO_MMAP_IOMEM       SNDRV_PCM_INFO_MMAP
963 int snd_pcm_lib_mmap_iomem(snd_pcm_substream_t *substream, struct vm_area_struct *area);
964 #else
965 #define SNDRV_PCM_INFO_MMAP_IOMEM       0
966 #define snd_pcm_lib_mmap_iomem  NULL
967 #endif
968
969 static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
970 {
971         *max = dma < 4 ? 64 * 1024 : 128 * 1024;
972 }
973
974 /*
975  *  Misc
976  */
977
978 #define SNDRV_PCM_DEFAULT_CON_SPDIF     (IEC958_AES0_CON_EMPHASIS_NONE|\
979                                          (IEC958_AES1_CON_ORIGINAL<<8)|\
980                                          (IEC958_AES1_CON_PCM_CODER<<8)|\
981                                          (IEC958_AES3_CON_FS_48000<<24))
982
983 #endif /* __SOUND_PCM_H */