5 * Main header file for the ALSA driver
6 * Copyright (c) 1994-2001 by Jaroslav Kysela <perex@suse.cz>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include <linux/sched.h> /* wake_up() */
26 #include <asm/semaphore.h> /* struct semaphore */
27 #include <linux/rwsem.h> /* struct rw_semaphore */
28 #include <linux/workqueue.h> /* struct workqueue_struct */
31 typedef struct timespec snd_timestamp_t;
32 typedef struct sndrv_interval snd_interval_t;
33 typedef enum sndrv_card_type snd_card_type;
34 typedef struct sndrv_xferi snd_xferi_t;
35 typedef struct sndrv_xfern snd_xfern_t;
36 typedef struct sndrv_xferv snd_xferv_t;
38 /* forward declarations */
46 /* device allocation stuff */
48 #define SNDRV_DEV_TYPE_RANGE_SIZE 0x1000
51 SNDRV_DEV_TOPLEVEL = (0*SNDRV_DEV_TYPE_RANGE_SIZE),
53 SNDRV_DEV_LOWLEVEL_PRE,
54 SNDRV_DEV_LOWLEVEL_NORMAL = (1*SNDRV_DEV_TYPE_RANGE_SIZE),
63 SNDRV_DEV_LOWLEVEL = (2*SNDRV_DEV_TYPE_RANGE_SIZE)
69 SNDRV_DEV_DISCONNECTED
73 SNDRV_DEV_CMD_PRE = 0,
74 SNDRV_DEV_CMD_NORMAL = 1,
75 SNDRV_DEV_CMD_POST = 2
78 typedef struct _snd_card snd_card_t;
79 typedef struct _snd_device snd_device_t;
81 typedef int (snd_dev_free_t)(snd_device_t *device);
82 typedef int (snd_dev_register_t)(snd_device_t *device);
83 typedef int (snd_dev_disconnect_t)(snd_device_t *device);
84 typedef int (snd_dev_unregister_t)(snd_device_t *device);
87 snd_dev_free_t *dev_free;
88 snd_dev_register_t *dev_register;
89 snd_dev_disconnect_t *dev_disconnect;
90 snd_dev_unregister_t *dev_unregister;
94 struct list_head list; /* list of registered devices */
95 snd_card_t *card; /* card which holds this device */
96 snd_device_state_t state; /* state of the device */
97 snd_device_type_t type; /* device type */
98 void *device_data; /* device structure */
99 snd_device_ops_t *ops; /* operations */
102 #define snd_device(n) list_entry(n, snd_device_t, list)
104 /* various typedefs */
106 typedef struct snd_info_entry snd_info_entry_t;
107 typedef struct _snd_pcm snd_pcm_t;
108 typedef struct _snd_pcm_str snd_pcm_str_t;
109 typedef struct _snd_pcm_substream snd_pcm_substream_t;
110 typedef struct _snd_mixer snd_kmixer_t;
111 typedef struct _snd_rawmidi snd_rawmidi_t;
112 typedef struct _snd_ctl_file snd_ctl_file_t;
113 typedef struct _snd_kcontrol snd_kcontrol_t;
114 typedef struct _snd_timer snd_timer_t;
115 typedef struct _snd_timer_instance snd_timer_instance_t;
116 typedef struct _snd_hwdep snd_hwdep_t;
117 #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
118 typedef struct _snd_oss_mixer snd_mixer_oss_t;
121 /* monitor files for graceful shutdown (hotplug) */
123 struct snd_monitor_file {
125 struct snd_monitor_file *next;
128 struct snd_shutdown_f_ops; /* define it later */
130 /* main structure for soundcard */
133 int number; /* number of soundcard (index to snd_cards) */
135 char id[16]; /* id string of this card */
136 char driver[16]; /* driver name */
137 char shortname[32]; /* short name of this soundcard */
138 char longname[80]; /* name of this soundcard */
139 char mixername[80]; /* mixer name */
140 char components[80]; /* card components delimited with space */
142 struct module *module; /* top-level module */
144 void *private_data; /* private data for soundcard */
145 void (*private_free) (snd_card_t *card); /* callback for freeing of private data */
147 struct list_head devices; /* devices */
149 unsigned int last_numid; /* last used numeric ID */
150 struct rw_semaphore controls_rwsem; /* controls list lock */
151 rwlock_t ctl_files_rwlock; /* ctl_files list lock */
152 int controls_count; /* count of all controls */
153 int user_ctl_count; /* count of all user controls */
154 struct list_head controls; /* all controls for this card */
155 struct list_head ctl_files; /* active control files */
157 snd_info_entry_t *proc_root; /* root for soundcard specific files */
158 snd_info_entry_t *proc_id; /* the card id */
159 struct proc_dir_entry *proc_root_link; /* number link to real id */
161 struct snd_monitor_file *files; /* all files associated to this card */
162 struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown state */
163 spinlock_t files_lock; /* lock the files for this card */
164 int shutdown; /* this card is going down */
165 wait_queue_head_t shutdown_sleep;
166 struct work_struct free_workq; /* for free in workqueue */
170 int (*pm_suspend)(snd_card_t *card, unsigned int state);
171 int (*pm_resume)(snd_card_t *card, unsigned int state);
172 struct pm_dev *pm_dev; /* for ISA */
173 void *pm_private_data;
174 unsigned int power_state; /* power state */
175 struct semaphore power_lock; /* power lock */
176 wait_queue_head_t power_sleep;
179 #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
180 snd_mixer_oss_t *mixer_oss;
181 int mixer_oss_change_count;
186 static inline void snd_power_lock(snd_card_t *card)
188 down(&card->power_lock);
191 static inline void snd_power_unlock(snd_card_t *card)
193 up(&card->power_lock);
196 int snd_power_wait(snd_card_t *card, unsigned int power_state, struct file *file);
198 static inline unsigned int snd_power_get_state(snd_card_t *card)
200 return card->power_state;
203 static inline void snd_power_change_state(snd_card_t *card, unsigned int state)
205 card->power_state = state;
206 wake_up(&card->power_sleep);
208 int snd_card_set_pm_callback(snd_card_t *card,
209 int (*suspend)(snd_card_t *, unsigned int),
210 int (*resume)(snd_card_t *, unsigned int),
212 int snd_card_set_dev_pm_callback(snd_card_t *card, int type,
213 int (*suspend)(snd_card_t *, unsigned int),
214 int (*resume)(snd_card_t *, unsigned int),
216 #define snd_card_set_isa_pm_callback(card,suspend,resume,data) \
217 snd_card_set_dev_pm_callback(card, PM_ISA_DEV, suspend, resume, data)
219 #ifndef SND_PCI_PM_CALLBACKS
220 int snd_card_pci_suspend(struct pci_dev *dev, u32 state);
221 int snd_card_pci_resume(struct pci_dev *dev);
222 #define SND_PCI_PM_CALLBACKS \
223 .suspend = snd_card_pci_suspend, .resume = snd_card_pci_resume
227 #define snd_power_lock(card) do { (void)(card); } while (0)
228 #define snd_power_unlock(card) do { (void)(card); } while (0)
229 static inline int snd_power_wait(snd_card_t *card, unsigned int state, struct file *file) { return 0; }
230 #define snd_power_get_state(card) SNDRV_CTL_POWER_D0
231 #define snd_power_change_state(card, state) do { (void)(card); } while (0)
232 #define snd_card_set_pm_callback(card,suspend,resume,data)
233 #define snd_card_set_dev_pm_callback(card,suspend,resume,data)
234 #define snd_card_set_isa_pm_callback(card,suspend,resume,data)
236 #define SND_PCI_PM_CALLBACKS
243 struct list_head list; /* list of all minors per card */
244 int number; /* minor number */
245 int device; /* device number */
246 const char *comment; /* for /proc/asound/devices */
247 struct file_operations *f_ops; /* file operations */
248 char name[0]; /* device name (keep at the end of structure) */
251 typedef struct _snd_minor snd_minor_t;
255 extern int snd_ecards_limit;
257 void snd_request_card(int card);
259 int snd_register_device(int type, snd_card_t *card, int dev, snd_minor_t *reg, const char *name);
260 int snd_unregister_device(int type, snd_card_t *card, int dev);
262 #ifdef CONFIG_SND_OSSEMUL
263 int snd_register_oss_device(int type, snd_card_t *card, int dev, snd_minor_t *reg, const char *name);
264 int snd_unregister_oss_device(int type, snd_card_t *card, int dev);
267 int snd_minor_info_init(void);
268 int snd_minor_info_done(void);
272 #ifdef CONFIG_SND_OSSEMUL
273 int snd_minor_info_oss_init(void);
274 int snd_minor_info_oss_done(void);
275 int snd_oss_init_module(void);
277 #define snd_minor_info_oss_init() /*NOP*/
278 #define snd_minor_info_oss_done() /*NOP*/
279 #define snd_oss_init_module() 0
284 #ifdef CONFIG_SND_DEBUG_MEMORY
285 void snd_memory_init(void);
286 void snd_memory_done(void);
287 int snd_memory_info_init(void);
288 int snd_memory_info_done(void);
289 void *snd_hidden_kmalloc(size_t size, int flags);
290 void *snd_hidden_kcalloc(size_t n, size_t size, int flags);
291 void snd_hidden_kfree(const void *obj);
292 void *snd_hidden_vmalloc(unsigned long size);
293 void snd_hidden_vfree(void *obj);
294 #define kmalloc(size, flags) snd_hidden_kmalloc(size, flags)
295 #define kcalloc(n, size, flags) snd_hidden_kcalloc(n, size, flags)
296 #define kfree(obj) snd_hidden_kfree(obj)
297 #define vmalloc(size) snd_hidden_vmalloc(size)
298 #define vfree(obj) snd_hidden_vfree(obj)
299 #define kmalloc_nocheck(size, flags) snd_wrapper_kmalloc(size, flags)
300 #define vmalloc_nocheck(size) snd_wrapper_vmalloc(size)
301 #define kfree_nocheck(obj) snd_wrapper_kfree(obj)
302 #define vfree_nocheck(obj) snd_wrapper_vfree(obj)
304 #define snd_memory_init() /*NOP*/
305 #define snd_memory_done() /*NOP*/
306 #define snd_memory_info_init() /*NOP*/
307 #define snd_memory_info_done() /*NOP*/
308 #define kmalloc_nocheck(size, flags) kmalloc(size, flags)
309 #define vmalloc_nocheck(size) vmalloc(size)
310 #define kfree_nocheck(obj) kfree(obj)
311 #define vfree_nocheck(obj) vfree(obj)
313 char *snd_kmalloc_strdup(const char *string, int flags);
314 int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
315 int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
319 extern unsigned int snd_cards_lock;
320 extern snd_card_t *snd_cards[SNDRV_CARDS];
321 extern rwlock_t snd_card_rwlock;
322 #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
323 #define SND_MIXER_OSS_NOTIFY_REGISTER 0
324 #define SND_MIXER_OSS_NOTIFY_DISCONNECT 1
325 #define SND_MIXER_OSS_NOTIFY_FREE 2
326 extern int (*snd_mixer_oss_notify_callback)(snd_card_t *card, int cmd);
329 snd_card_t *snd_card_new(int idx, const char *id,
330 struct module *module, int extra_size);
331 int snd_card_disconnect(snd_card_t *card);
332 int snd_card_free(snd_card_t *card);
333 int snd_card_free_in_thread(snd_card_t *card);
334 int snd_card_register(snd_card_t *card);
335 int snd_card_info_init(void);
336 int snd_card_info_done(void);
337 int snd_component_add(snd_card_t *card, const char *component);
338 int snd_card_file_add(snd_card_t *card, struct file *file);
339 int snd_card_file_remove(snd_card_t *card, struct file *file);
341 #ifndef snd_card_set_dev
342 #define snd_card_set_dev(card,devptr) ((card)->dev = (devptr))
347 int snd_device_new(snd_card_t *card, snd_device_type_t type,
348 void *device_data, snd_device_ops_t *ops);
349 int snd_device_register(snd_card_t *card, void *device_data);
350 int snd_device_register_all(snd_card_t *card);
351 int snd_device_disconnect(snd_card_t *card, void *device_data);
352 int snd_device_disconnect_all(snd_card_t *card);
353 int snd_device_free(snd_card_t *card, void *device_data);
354 int snd_device_free_all(snd_card_t *card, snd_device_cmd_t cmd);
358 #define DMA_MODE_NO_ENABLE 0x0100
360 void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode);
361 void snd_dma_disable(unsigned long dma);
362 unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
366 int snd_task_name(struct task_struct *task, char *name, size_t size);
367 #ifdef CONFIG_SND_VERBOSE_PRINTK
368 void snd_verbose_printk(const char *file, int line, const char *format, ...)
369 __attribute__ ((format (printf, 3, 4)));
371 #if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK)
372 void snd_verbose_printd(const char *file, int line, const char *format, ...)
373 __attribute__ ((format (printf, 3, 4)));
378 #ifdef CONFIG_SND_VERBOSE_PRINTK
380 * snd_printk - printk wrapper
381 * @fmt: format string
383 * Works like print() but prints the file and the line of the caller
384 * when configured with CONFIG_SND_VERBOSE_PRINTK.
386 #define snd_printk(fmt, args...) \
387 snd_verbose_printk(__FILE__, __LINE__, fmt ,##args)
389 #define snd_printk(fmt, args...) \
393 #ifdef CONFIG_SND_DEBUG
395 #define __ASTRING__(x) #x
397 #ifdef CONFIG_SND_VERBOSE_PRINTK
399 * snd_printd - debug printk
400 * @format: format string
402 * Compiled only when Works like snd_printk() for debugging purpose.
403 * Ignored when CONFIG_SND_DEBUG is not set.
405 #define snd_printd(fmt, args...) \
406 snd_verbose_printd(__FILE__, __LINE__, fmt ,##args)
408 #define snd_printd(fmt, args...) \
412 * snd_assert - run-time assersion macro
414 * @args...: the action
416 * This macro checks the expression in run-time and invokes the commands
417 * given in the rest arguments if the assertion is failed.
418 * When CONFIG_SND_DEBUG is not set, the expression is executed but
421 #define snd_assert(expr, args...) do {\
422 if (unlikely(!(expr))) { \
423 snd_printk(KERN_ERR "BUG? (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\
428 * snd_runtime_check - run-time assersion macro
430 * @args...: the action
432 * This macro checks the expression in run-time and invokes the commands
433 * given in the rest arguments if the assertion is failed.
434 * Unlike snd_assert(), the action commands are executed even if
435 * CONFIG_SND_DEBUG is not set but without any error messages.
437 #define snd_runtime_check(expr, args...) do {\
438 if (unlikely(!(expr))) { \
439 snd_printk(KERN_ERR "ERROR (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\
444 #else /* !CONFIG_SND_DEBUG */
446 #define snd_printd(fmt, args...) /* nothing */
447 #define snd_assert(expr, args...) (void)(expr)
448 #define snd_runtime_check(expr, args...) do { if (!(expr)) { args; } } while (0)
450 #endif /* CONFIG_SND_DEBUG */
452 #ifdef CONFIG_SND_DEBUG_DETECT
454 * snd_printdd - debug printk
455 * @format: format string
457 * Compiled only when Works like snd_printk() for debugging purpose.
458 * Ignored when CONFIG_SND_DEBUG_DETECT is not set.
460 #define snd_printdd(format, args...) snd_printk(format, ##args)
462 #define snd_printdd(format, args...) /* nothing */
465 #define snd_BUG() snd_assert(0, )
468 static inline void snd_timestamp_now(struct timespec *tstamp, int timespec)
471 /* FIXME: use a linear time source */
472 do_gettimeofday(&val);
473 tstamp->tv_sec = val.tv_sec;
474 tstamp->tv_nsec = val.tv_usec;
476 tstamp->tv_nsec *= 1000L;
479 static inline void snd_timestamp_zero(struct timespec *tstamp)
485 static inline int snd_timestamp_null(struct timespec *tstamp)
487 return tstamp->tv_sec == 0 && tstamp->tv_nsec == 0;
490 #define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) /* 3.8.1a */
492 #endif /* __SOUND_CORE_H */