at v2.6.13-rc2 503 lines 16 kB view raw
1#ifndef __SOUND_CORE_H 2#define __SOUND_CORE_H 3 4/* 5 * Main header file for the ALSA driver 6 * Copyright (c) 1994-2001 by Jaroslav Kysela <perex@suse.cz> 7 * 8 * 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. 13 * 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. 18 * 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 22 * 23 */ 24 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 */ 29#include <linux/pm.h> /* pm_message_t */ 30 31/* Typedef's */ 32typedef struct timespec snd_timestamp_t; 33typedef struct sndrv_interval snd_interval_t; 34typedef enum sndrv_card_type snd_card_type; 35typedef struct sndrv_xferi snd_xferi_t; 36typedef struct sndrv_xfern snd_xfern_t; 37typedef struct sndrv_xferv snd_xferv_t; 38 39/* forward declarations */ 40#ifdef CONFIG_PCI 41struct pci_dev; 42#endif 43#ifdef CONFIG_SBUS 44struct sbus_dev; 45#endif 46 47/* device allocation stuff */ 48 49#define SNDRV_DEV_TYPE_RANGE_SIZE 0x1000 50 51typedef enum { 52 SNDRV_DEV_TOPLEVEL = (0*SNDRV_DEV_TYPE_RANGE_SIZE), 53 SNDRV_DEV_CONTROL, 54 SNDRV_DEV_LOWLEVEL_PRE, 55 SNDRV_DEV_LOWLEVEL_NORMAL = (1*SNDRV_DEV_TYPE_RANGE_SIZE), 56 SNDRV_DEV_PCM, 57 SNDRV_DEV_RAWMIDI, 58 SNDRV_DEV_TIMER, 59 SNDRV_DEV_SEQUENCER, 60 SNDRV_DEV_HWDEP, 61 SNDRV_DEV_INFO, 62 SNDRV_DEV_BUS, 63 SNDRV_DEV_CODEC, 64 SNDRV_DEV_LOWLEVEL = (2*SNDRV_DEV_TYPE_RANGE_SIZE) 65} snd_device_type_t; 66 67typedef enum { 68 SNDRV_DEV_BUILD, 69 SNDRV_DEV_REGISTERED, 70 SNDRV_DEV_DISCONNECTED 71} snd_device_state_t; 72 73typedef enum { 74 SNDRV_DEV_CMD_PRE = 0, 75 SNDRV_DEV_CMD_NORMAL = 1, 76 SNDRV_DEV_CMD_POST = 2 77} snd_device_cmd_t; 78 79typedef struct _snd_card snd_card_t; 80typedef struct _snd_device snd_device_t; 81 82typedef int (snd_dev_free_t)(snd_device_t *device); 83typedef int (snd_dev_register_t)(snd_device_t *device); 84typedef int (snd_dev_disconnect_t)(snd_device_t *device); 85typedef int (snd_dev_unregister_t)(snd_device_t *device); 86 87typedef struct { 88 snd_dev_free_t *dev_free; 89 snd_dev_register_t *dev_register; 90 snd_dev_disconnect_t *dev_disconnect; 91 snd_dev_unregister_t *dev_unregister; 92} snd_device_ops_t; 93 94struct _snd_device { 95 struct list_head list; /* list of registered devices */ 96 snd_card_t *card; /* card which holds this device */ 97 snd_device_state_t state; /* state of the device */ 98 snd_device_type_t type; /* device type */ 99 void *device_data; /* device structure */ 100 snd_device_ops_t *ops; /* operations */ 101}; 102 103#define snd_device(n) list_entry(n, snd_device_t, list) 104 105/* various typedefs */ 106 107typedef struct snd_info_entry snd_info_entry_t; 108typedef struct _snd_pcm snd_pcm_t; 109typedef struct _snd_pcm_str snd_pcm_str_t; 110typedef struct _snd_pcm_substream snd_pcm_substream_t; 111typedef struct _snd_mixer snd_kmixer_t; 112typedef struct _snd_rawmidi snd_rawmidi_t; 113typedef struct _snd_ctl_file snd_ctl_file_t; 114typedef struct _snd_kcontrol snd_kcontrol_t; 115typedef struct _snd_timer snd_timer_t; 116typedef struct _snd_timer_instance snd_timer_instance_t; 117typedef struct _snd_hwdep snd_hwdep_t; 118#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) 119typedef struct _snd_oss_mixer snd_mixer_oss_t; 120#endif 121 122/* monitor files for graceful shutdown (hotplug) */ 123 124struct snd_monitor_file { 125 struct file *file; 126 struct snd_monitor_file *next; 127}; 128 129struct snd_shutdown_f_ops; /* define it later */ 130 131/* main structure for soundcard */ 132 133struct _snd_card { 134 int number; /* number of soundcard (index to snd_cards) */ 135 136 char id[16]; /* id string of this card */ 137 char driver[16]; /* driver name */ 138 char shortname[32]; /* short name of this soundcard */ 139 char longname[80]; /* name of this soundcard */ 140 char mixername[80]; /* mixer name */ 141 char components[80]; /* card components delimited with space */ 142 143 struct module *module; /* top-level module */ 144 145 void *private_data; /* private data for soundcard */ 146 void (*private_free) (snd_card_t *card); /* callback for freeing of private data */ 147 148 struct list_head devices; /* devices */ 149 150 unsigned int last_numid; /* last used numeric ID */ 151 struct rw_semaphore controls_rwsem; /* controls list lock */ 152 rwlock_t ctl_files_rwlock; /* ctl_files list lock */ 153 int controls_count; /* count of all controls */ 154 int user_ctl_count; /* count of all user controls */ 155 struct list_head controls; /* all controls for this card */ 156 struct list_head ctl_files; /* active control files */ 157 158 snd_info_entry_t *proc_root; /* root for soundcard specific files */ 159 snd_info_entry_t *proc_id; /* the card id */ 160 struct proc_dir_entry *proc_root_link; /* number link to real id */ 161 162 struct snd_monitor_file *files; /* all files associated to this card */ 163 struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown state */ 164 spinlock_t files_lock; /* lock the files for this card */ 165 int shutdown; /* this card is going down */ 166 wait_queue_head_t shutdown_sleep; 167 struct work_struct free_workq; /* for free in workqueue */ 168 struct device *dev; 169 170#ifdef CONFIG_PM 171 int (*pm_suspend)(snd_card_t *card, pm_message_t state); 172 int (*pm_resume)(snd_card_t *card); 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; 177#ifdef CONFIG_SND_GENERIC_PM 178 struct snd_generic_device *pm_dev; /* for ISA */ 179#endif 180#endif 181 182#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) 183 snd_mixer_oss_t *mixer_oss; 184 int mixer_oss_change_count; 185#endif 186}; 187 188#ifdef CONFIG_PM 189static inline void snd_power_lock(snd_card_t *card) 190{ 191 down(&card->power_lock); 192} 193 194static inline void snd_power_unlock(snd_card_t *card) 195{ 196 up(&card->power_lock); 197} 198 199int snd_power_wait(snd_card_t *card, unsigned int power_state, struct file *file); 200 201static inline unsigned int snd_power_get_state(snd_card_t *card) 202{ 203 return card->power_state; 204} 205 206static inline void snd_power_change_state(snd_card_t *card, unsigned int state) 207{ 208 card->power_state = state; 209 wake_up(&card->power_sleep); 210} 211int snd_card_set_pm_callback(snd_card_t *card, 212 int (*suspend)(snd_card_t *, pm_message_t), 213 int (*resume)(snd_card_t *), 214 void *private_data); 215int snd_card_set_generic_pm_callback(snd_card_t *card, 216 int (*suspend)(snd_card_t *, pm_message_t), 217 int (*resume)(snd_card_t *), 218 void *private_data); 219#define snd_card_set_isa_pm_callback(card,suspend,resume,data) \ 220 snd_card_set_generic_pm_callback(card, suspend, resume, data) 221struct pci_dev; 222int snd_card_pci_suspend(struct pci_dev *dev, pm_message_t state); 223int snd_card_pci_resume(struct pci_dev *dev); 224#define SND_PCI_PM_CALLBACKS \ 225 .suspend = snd_card_pci_suspend, .resume = snd_card_pci_resume 226 227#else /* ! CONFIG_PM */ 228 229#define snd_power_lock(card) do { (void)(card); } while (0) 230#define snd_power_unlock(card) do { (void)(card); } while (0) 231static inline int snd_power_wait(snd_card_t *card, unsigned int state, struct file *file) { return 0; } 232#define snd_power_get_state(card) SNDRV_CTL_POWER_D0 233#define snd_power_change_state(card, state) do { (void)(card); } while (0) 234#define snd_card_set_pm_callback(card,suspend,resume,data) 235#define snd_card_set_generic_pm_callback(card,suspend,resume,data) 236#define snd_card_set_isa_pm_callback(card,suspend,resume,data) 237#define SND_PCI_PM_CALLBACKS 238 239#endif /* CONFIG_PM */ 240 241/* device.c */ 242 243struct _snd_minor { 244 struct list_head list; /* list of all minors per card */ 245 int number; /* minor number */ 246 int device; /* device number */ 247 const char *comment; /* for /proc/asound/devices */ 248 struct file_operations *f_ops; /* file operations */ 249 char name[0]; /* device name (keep at the end of structure) */ 250}; 251 252typedef struct _snd_minor snd_minor_t; 253 254/* sound.c */ 255 256extern int snd_ecards_limit; 257 258void snd_request_card(int card); 259 260int snd_register_device(int type, snd_card_t *card, int dev, snd_minor_t *reg, const char *name); 261int snd_unregister_device(int type, snd_card_t *card, int dev); 262 263#ifdef CONFIG_SND_OSSEMUL 264int snd_register_oss_device(int type, snd_card_t *card, int dev, snd_minor_t *reg, const char *name); 265int snd_unregister_oss_device(int type, snd_card_t *card, int dev); 266#endif 267 268int snd_minor_info_init(void); 269int snd_minor_info_done(void); 270 271/* sound_oss.c */ 272 273#ifdef CONFIG_SND_OSSEMUL 274int snd_minor_info_oss_init(void); 275int snd_minor_info_oss_done(void); 276int snd_oss_init_module(void); 277#else 278#define snd_minor_info_oss_init() /*NOP*/ 279#define snd_minor_info_oss_done() /*NOP*/ 280#define snd_oss_init_module() 0 281#endif 282 283/* memory.c */ 284 285#ifdef CONFIG_SND_DEBUG_MEMORY 286void snd_memory_init(void); 287void snd_memory_done(void); 288int snd_memory_info_init(void); 289int snd_memory_info_done(void); 290void *snd_hidden_kmalloc(size_t size, int flags); 291void *snd_hidden_kcalloc(size_t n, size_t size, int flags); 292void snd_hidden_kfree(const void *obj); 293void *snd_hidden_vmalloc(unsigned long size); 294void snd_hidden_vfree(void *obj); 295char *snd_hidden_kstrdup(const char *s, int flags); 296#define kmalloc(size, flags) snd_hidden_kmalloc(size, flags) 297#define kcalloc(n, size, flags) snd_hidden_kcalloc(n, size, flags) 298#define kfree(obj) snd_hidden_kfree(obj) 299#define vmalloc(size) snd_hidden_vmalloc(size) 300#define vfree(obj) snd_hidden_vfree(obj) 301#define kmalloc_nocheck(size, flags) snd_wrapper_kmalloc(size, flags) 302#define vmalloc_nocheck(size) snd_wrapper_vmalloc(size) 303#define kfree_nocheck(obj) snd_wrapper_kfree(obj) 304#define vfree_nocheck(obj) snd_wrapper_vfree(obj) 305#define kstrdup(s, flags) snd_hidden_kstrdup(s, flags) 306#else 307#define snd_memory_init() /*NOP*/ 308#define snd_memory_done() /*NOP*/ 309#define snd_memory_info_init() /*NOP*/ 310#define snd_memory_info_done() /*NOP*/ 311#define kmalloc_nocheck(size, flags) kmalloc(size, flags) 312#define vmalloc_nocheck(size) vmalloc(size) 313#define kfree_nocheck(obj) kfree(obj) 314#define vfree_nocheck(obj) vfree(obj) 315#endif 316int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count); 317int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count); 318 319/* init.c */ 320 321extern unsigned int snd_cards_lock; 322extern snd_card_t *snd_cards[SNDRV_CARDS]; 323extern rwlock_t snd_card_rwlock; 324#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE) 325#define SND_MIXER_OSS_NOTIFY_REGISTER 0 326#define SND_MIXER_OSS_NOTIFY_DISCONNECT 1 327#define SND_MIXER_OSS_NOTIFY_FREE 2 328extern int (*snd_mixer_oss_notify_callback)(snd_card_t *card, int cmd); 329#endif 330 331snd_card_t *snd_card_new(int idx, const char *id, 332 struct module *module, int extra_size); 333int snd_card_disconnect(snd_card_t *card); 334int snd_card_free(snd_card_t *card); 335int snd_card_free_in_thread(snd_card_t *card); 336int snd_card_register(snd_card_t *card); 337int snd_card_info_init(void); 338int snd_card_info_done(void); 339int snd_component_add(snd_card_t *card, const char *component); 340int snd_card_file_add(snd_card_t *card, struct file *file); 341int snd_card_file_remove(snd_card_t *card, struct file *file); 342 343#ifndef snd_card_set_dev 344#define snd_card_set_dev(card,devptr) ((card)->dev = (devptr)) 345#endif 346 347/* device.c */ 348 349int snd_device_new(snd_card_t *card, snd_device_type_t type, 350 void *device_data, snd_device_ops_t *ops); 351int snd_device_register(snd_card_t *card, void *device_data); 352int snd_device_register_all(snd_card_t *card); 353int snd_device_disconnect(snd_card_t *card, void *device_data); 354int snd_device_disconnect_all(snd_card_t *card); 355int snd_device_free(snd_card_t *card, void *device_data); 356int snd_device_free_all(snd_card_t *card, snd_device_cmd_t cmd); 357 358/* isadma.c */ 359 360#define DMA_MODE_NO_ENABLE 0x0100 361 362void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode); 363void snd_dma_disable(unsigned long dma); 364unsigned int snd_dma_pointer(unsigned long dma, unsigned int size); 365 366/* misc.c */ 367 368int snd_task_name(struct task_struct *task, char *name, size_t size); 369#ifdef CONFIG_SND_VERBOSE_PRINTK 370void snd_verbose_printk(const char *file, int line, const char *format, ...) 371 __attribute__ ((format (printf, 3, 4))); 372#endif 373#if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK) 374void snd_verbose_printd(const char *file, int line, const char *format, ...) 375 __attribute__ ((format (printf, 3, 4))); 376#endif 377 378/* --- */ 379 380#ifdef CONFIG_SND_VERBOSE_PRINTK 381/** 382 * snd_printk - printk wrapper 383 * @fmt: format string 384 * 385 * Works like print() but prints the file and the line of the caller 386 * when configured with CONFIG_SND_VERBOSE_PRINTK. 387 */ 388#define snd_printk(fmt, args...) \ 389 snd_verbose_printk(__FILE__, __LINE__, fmt ,##args) 390#else 391#define snd_printk(fmt, args...) \ 392 printk(fmt ,##args) 393#endif 394 395#ifdef CONFIG_SND_DEBUG 396 397#define __ASTRING__(x) #x 398 399#ifdef CONFIG_SND_VERBOSE_PRINTK 400/** 401 * snd_printd - debug printk 402 * @format: format string 403 * 404 * Compiled only when Works like snd_printk() for debugging purpose. 405 * Ignored when CONFIG_SND_DEBUG is not set. 406 */ 407#define snd_printd(fmt, args...) \ 408 snd_verbose_printd(__FILE__, __LINE__, fmt ,##args) 409#else 410#define snd_printd(fmt, args...) \ 411 printk(fmt ,##args) 412#endif 413/** 414 * snd_assert - run-time assersion macro 415 * @expr: expression 416 * @args...: the action 417 * 418 * This macro checks the expression in run-time and invokes the commands 419 * given in the rest arguments if the assertion is failed. 420 * When CONFIG_SND_DEBUG is not set, the expression is executed but 421 * not checked. 422 */ 423#define snd_assert(expr, args...) do {\ 424 if (unlikely(!(expr))) { \ 425 snd_printk(KERN_ERR "BUG? (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\ 426 args;\ 427 }\ 428} while (0) 429/** 430 * snd_runtime_check - run-time assersion macro 431 * @expr: expression 432 * @args...: the action 433 * 434 * This macro checks the expression in run-time and invokes the commands 435 * given in the rest arguments if the assertion is failed. 436 * Unlike snd_assert(), the action commands are executed even if 437 * CONFIG_SND_DEBUG is not set but without any error messages. 438 */ 439#define snd_runtime_check(expr, args...) do {\ 440 if (unlikely(!(expr))) { \ 441 snd_printk(KERN_ERR "ERROR (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\ 442 args;\ 443 }\ 444} while (0) 445 446#else /* !CONFIG_SND_DEBUG */ 447 448#define snd_printd(fmt, args...) /* nothing */ 449#define snd_assert(expr, args...) (void)(expr) 450#define snd_runtime_check(expr, args...) do { if (!(expr)) { args; } } while (0) 451 452#endif /* CONFIG_SND_DEBUG */ 453 454#ifdef CONFIG_SND_DEBUG_DETECT 455/** 456 * snd_printdd - debug printk 457 * @format: format string 458 * 459 * Compiled only when Works like snd_printk() for debugging purpose. 460 * Ignored when CONFIG_SND_DEBUG_DETECT is not set. 461 */ 462#define snd_printdd(format, args...) snd_printk(format, ##args) 463#else 464#define snd_printdd(format, args...) /* nothing */ 465#endif 466 467#define snd_BUG() snd_assert(0, ) 468 469 470static inline void snd_timestamp_now(struct timespec *tstamp, int timespec) 471{ 472 struct timeval val; 473 /* FIXME: use a linear time source */ 474 do_gettimeofday(&val); 475 tstamp->tv_sec = val.tv_sec; 476 tstamp->tv_nsec = val.tv_usec; 477 if (timespec) 478 tstamp->tv_nsec *= 1000L; 479} 480 481static inline void snd_timestamp_zero(struct timespec *tstamp) 482{ 483 tstamp->tv_sec = 0; 484 tstamp->tv_nsec = 0; 485} 486 487static inline int snd_timestamp_null(struct timespec *tstamp) 488{ 489 return tstamp->tv_sec == 0 && tstamp->tv_nsec == 0; 490} 491 492#define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) /* 3.8.1a */ 493 494/* for easier backward-porting */ 495#if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE) 496#ifndef gameport_set_dev_parent 497#define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev)) 498#define gameport_set_port_data(gp,r) ((gp)->port_data = (r)) 499#define gameport_get_port_data(gp) (gp)->port_data 500#endif 501#endif 502 503#endif /* __SOUND_CORE_H */