11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 21da177e4SLinus Torvalds #ifndef __SOUND_CORE_H 31da177e4SLinus Torvalds #define __SOUND_CORE_H 41da177e4SLinus Torvalds 51da177e4SLinus Torvalds /* 61da177e4SLinus Torvalds * Main header file for the ALSA driver 7c1017a4cSJaroslav Kysela * Copyright (c) 1994-2001 by Jaroslav Kysela <perex@perex.cz> 81da177e4SLinus Torvalds */ 91da177e4SLinus Torvalds 108bfb181cSTakashi Iwai #include <linux/device.h> 111da177e4SLinus Torvalds #include <linux/sched.h> /* wake_up() */ 121a60d4c5SIngo Molnar #include <linux/mutex.h> /* struct mutex */ 131da177e4SLinus Torvalds #include <linux/rwsem.h> /* struct rw_semaphore */ 141da177e4SLinus Torvalds #include <linux/pm.h> /* pm_message_t */ 155ef03460STakashi Iwai #include <linux/stringify.h> 16bcbb1553STim Gardner #include <linux/printk.h> 17c27e1efbSTakashi Iwai #include <linux/xarray.h> 181da177e4SLinus Torvalds 199004acc7STakashi Iwai /* number of supported soundcards */ 209004acc7STakashi Iwai #ifdef CONFIG_SND_DYNAMIC_MINORS 217bb2491bSTakashi Iwai #define SNDRV_CARDS CONFIG_SND_MAX_CARDS 229004acc7STakashi Iwai #else 239004acc7STakashi Iwai #define SNDRV_CARDS 8 /* don't change - minor numbers */ 249004acc7STakashi Iwai #endif 259004acc7STakashi Iwai 269004acc7STakashi Iwai #define CONFIG_SND_MAJOR 116 /* standard configuration */ 279004acc7STakashi Iwai 281da177e4SLinus Torvalds /* forward declarations */ 291da177e4SLinus Torvalds struct pci_dev; 30de477254SPaul Gortmaker struct module; 31f2464064STakashi Iwai struct completion; 321da177e4SLinus Torvalds 331da177e4SLinus Torvalds /* device allocation stuff */ 341da177e4SLinus Torvalds 35289ca025STakashi Iwai /* type of the object used in snd_device_*() 36289ca025STakashi Iwai * this also defines the calling order 37289ca025STakashi Iwai */ 389ce50543STakashi Iwai enum snd_device_type { 39289ca025STakashi Iwai SNDRV_DEV_LOWLEVEL, 40289ca025STakashi Iwai SNDRV_DEV_INFO, 41289ca025STakashi Iwai SNDRV_DEV_BUS, 42289ca025STakashi Iwai SNDRV_DEV_CODEC, 439ce50543STakashi Iwai SNDRV_DEV_PCM, 44289ca025STakashi Iwai SNDRV_DEV_COMPRESS, 459ce50543STakashi Iwai SNDRV_DEV_RAWMIDI, 469ce50543STakashi Iwai SNDRV_DEV_TIMER, 479ce50543STakashi Iwai SNDRV_DEV_SEQUENCER, 489ce50543STakashi Iwai SNDRV_DEV_HWDEP, 499ce50543STakashi Iwai SNDRV_DEV_JACK, 50dc82e524STakashi Iwai SNDRV_DEV_CONTROL, /* NOTE: this must be the last one */ 519ce50543STakashi Iwai }; 521da177e4SLinus Torvalds 539ce50543STakashi Iwai enum snd_device_state { 549ce50543STakashi Iwai SNDRV_DEV_BUILD, 559ce50543STakashi Iwai SNDRV_DEV_REGISTERED, 569ce50543STakashi Iwai SNDRV_DEV_DISCONNECTED, 579ce50543STakashi Iwai }; 581da177e4SLinus Torvalds 59512bbd6aSTakashi Iwai struct snd_device; 601da177e4SLinus Torvalds 61512bbd6aSTakashi Iwai struct snd_device_ops { 62512bbd6aSTakashi Iwai int (*dev_free)(struct snd_device *dev); 63512bbd6aSTakashi Iwai int (*dev_register)(struct snd_device *dev); 64512bbd6aSTakashi Iwai int (*dev_disconnect)(struct snd_device *dev); 65512bbd6aSTakashi Iwai }; 661da177e4SLinus Torvalds 67512bbd6aSTakashi Iwai struct snd_device { 681da177e4SLinus Torvalds struct list_head list; /* list of registered devices */ 69512bbd6aSTakashi Iwai struct snd_card *card; /* card which holds this device */ 709ce50543STakashi Iwai enum snd_device_state state; /* state of the device */ 719ce50543STakashi Iwai enum snd_device_type type; /* device type */ 721da177e4SLinus Torvalds void *device_data; /* device structure */ 738b575824STakashi Iwai const struct snd_device_ops *ops; /* operations */ 741da177e4SLinus Torvalds }; 751da177e4SLinus Torvalds 76512bbd6aSTakashi Iwai #define snd_device(n) list_entry(n, struct snd_device, list) 771da177e4SLinus Torvalds 781da177e4SLinus Torvalds /* main structure for soundcard */ 791da177e4SLinus Torvalds 80512bbd6aSTakashi Iwai struct snd_card { 81d5750f67SHenrik Kretzschmar int number; /* number of soundcard (index to 82d5750f67SHenrik Kretzschmar snd_cards) */ 831da177e4SLinus Torvalds 841da177e4SLinus Torvalds char id[16]; /* id string of this card */ 851da177e4SLinus Torvalds char driver[16]; /* driver name */ 861da177e4SLinus Torvalds char shortname[32]; /* short name of this soundcard */ 871da177e4SLinus Torvalds char longname[80]; /* name of this soundcard */ 88de65360bSHeiner Kallweit char irq_descr[32]; /* Interrupt description */ 891da177e4SLinus Torvalds char mixername[80]; /* mixer name */ 90ff33f230STakashi Iwai char components[128]; /* card components delimited with 91d5750f67SHenrik Kretzschmar space */ 921da177e4SLinus Torvalds struct module *module; /* top-level module */ 931da177e4SLinus Torvalds 941da177e4SLinus Torvalds void *private_data; /* private data for soundcard */ 95512bbd6aSTakashi Iwai void (*private_free) (struct snd_card *card); /* callback for freeing of 96d5750f67SHenrik Kretzschmar private data */ 971da177e4SLinus Torvalds struct list_head devices; /* devices */ 981da177e4SLinus Torvalds 990fcd9f4bSTakashi Iwai struct device ctl_dev; /* control device */ 1001da177e4SLinus Torvalds unsigned int last_numid; /* last used numeric ID */ 10137bb927dSOswald Buddenhagen struct rw_semaphore controls_rwsem; /* controls lock (list and values) */ 1021da177e4SLinus Torvalds rwlock_t ctl_files_rwlock; /* ctl_files list lock */ 1031da177e4SLinus Torvalds int controls_count; /* count of all controls */ 10466c6d1efSTakashi Sakamoto size_t user_ctl_alloc_size; // current memory allocation by user controls. 1051da177e4SLinus Torvalds struct list_head controls; /* all controls for this card */ 1061da177e4SLinus Torvalds struct list_head ctl_files; /* active control files */ 107c27e1efbSTakashi Iwai #ifdef CONFIG_SND_CTL_FAST_LOOKUP 108c27e1efbSTakashi Iwai struct xarray ctl_numids; /* hash table for numids */ 109c27e1efbSTakashi Iwai struct xarray ctl_hash; /* hash table for ctl id matching */ 110c27e1efbSTakashi Iwai bool ctl_hash_collision; /* ctl_hash collision seen? */ 111c27e1efbSTakashi Iwai #endif 1121da177e4SLinus Torvalds 113512bbd6aSTakashi Iwai struct snd_info_entry *proc_root; /* root for soundcard specific files */ 1141da177e4SLinus Torvalds struct proc_dir_entry *proc_root_link; /* number link to real id */ 1151da177e4SLinus Torvalds 116118dd6bfSTakashi Iwai struct list_head files_list; /* all files associated to this card */ 117d5750f67SHenrik Kretzschmar struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown 118d5750f67SHenrik Kretzschmar state */ 1191da177e4SLinus Torvalds spinlock_t files_lock; /* lock the files for this card */ 1201da177e4SLinus Torvalds int shutdown; /* this card is going down */ 121f2464064STakashi Iwai struct completion *release_completion; 1227d2aae1eSTakashi Iwai struct device *dev; /* device assigned to this card */ 1238bfb181cSTakashi Iwai struct device card_dev; /* cardX object for sysfs */ 1246bbc7fedSTakashi Iwai const struct attribute_group *dev_groups[4]; /* assigned sysfs attr */ 1258bfb181cSTakashi Iwai bool registered; /* card_dev is registered? */ 126e8ad415bSTakashi Iwai bool managed; /* managed via devres */ 127e8ad415bSTakashi Iwai bool releasing; /* during card free process */ 128fabb26dcSTakashi Iwai int sync_irq; /* assigned irq, used for PCM sync */ 129c44027c8STakashi Iwai wait_queue_head_t remove_sleep; 1301da177e4SLinus Torvalds 131d4cfb30fSTakashi Iwai size_t total_pcm_alloc_bytes; /* total amount of allocated buffers */ 132d4cfb30fSTakashi Iwai struct mutex memory_mutex; /* protection for the above */ 1332d670ea2SHui Wang #ifdef CONFIG_SND_DEBUG 1342d670ea2SHui Wang struct dentry *debugfs_root; /* debugfs root for card */ 1352d670ea2SHui Wang #endif 136d4cfb30fSTakashi Iwai 1371da177e4SLinus Torvalds #ifdef CONFIG_PM 1381da177e4SLinus Torvalds unsigned int power_state; /* power state */ 139e94fdbd7STakashi Iwai atomic_t power_ref; 1401da177e4SLinus Torvalds wait_queue_head_t power_sleep; 141e94fdbd7STakashi Iwai wait_queue_head_t power_ref_sleep; 1421da177e4SLinus Torvalds #endif 1431da177e4SLinus Torvalds 1446d2412b8STakashi Iwai #if IS_ENABLED(CONFIG_SND_MIXER_OSS) 145512bbd6aSTakashi Iwai struct snd_mixer_oss *mixer_oss; 1461da177e4SLinus Torvalds int mixer_oss_change_count; 1471da177e4SLinus Torvalds #endif 1481da177e4SLinus Torvalds }; 1491da177e4SLinus Torvalds 1508bfb181cSTakashi Iwai #define dev_to_snd_card(p) container_of(p, struct snd_card, card_dev) 1518bfb181cSTakashi Iwai 1521da177e4SLinus Torvalds #ifdef CONFIG_PM 153512bbd6aSTakashi Iwai static inline unsigned int snd_power_get_state(struct snd_card *card) 1541da177e4SLinus Torvalds { 155533a7ed9STakashi Iwai return READ_ONCE(card->power_state); 1561da177e4SLinus Torvalds } 1571da177e4SLinus Torvalds 158512bbd6aSTakashi Iwai static inline void snd_power_change_state(struct snd_card *card, unsigned int state) 1591da177e4SLinus Torvalds { 160533a7ed9STakashi Iwai WRITE_ONCE(card->power_state, state); 1611da177e4SLinus Torvalds wake_up(&card->power_sleep); 1621da177e4SLinus Torvalds } 163d5750f67SHenrik Kretzschmar 164e94fdbd7STakashi Iwai /** 165e94fdbd7STakashi Iwai * snd_power_ref - Take the reference count for power control 166e94fdbd7STakashi Iwai * @card: sound card object 167e94fdbd7STakashi Iwai * 168e94fdbd7STakashi Iwai * The power_ref reference of the card is used for managing to block 169e94fdbd7STakashi Iwai * the snd_power_sync_ref() operation. This function increments the reference. 170e94fdbd7STakashi Iwai * The counterpart snd_power_unref() has to be called appropriately later. 171e94fdbd7STakashi Iwai */ 172e94fdbd7STakashi Iwai static inline void snd_power_ref(struct snd_card *card) 173e94fdbd7STakashi Iwai { 174e94fdbd7STakashi Iwai atomic_inc(&card->power_ref); 175e94fdbd7STakashi Iwai } 176e94fdbd7STakashi Iwai 177e94fdbd7STakashi Iwai /** 178e94fdbd7STakashi Iwai * snd_power_unref - Release the reference count for power control 179e94fdbd7STakashi Iwai * @card: sound card object 180e94fdbd7STakashi Iwai */ 181e94fdbd7STakashi Iwai static inline void snd_power_unref(struct snd_card *card) 182e94fdbd7STakashi Iwai { 183e94fdbd7STakashi Iwai if (atomic_dec_and_test(&card->power_ref)) 184e94fdbd7STakashi Iwai wake_up(&card->power_ref_sleep); 185e94fdbd7STakashi Iwai } 186e94fdbd7STakashi Iwai 187e94fdbd7STakashi Iwai /** 188e94fdbd7STakashi Iwai * snd_power_sync_ref - wait until the card power_ref is freed 189e94fdbd7STakashi Iwai * @card: sound card object 190e94fdbd7STakashi Iwai * 191e94fdbd7STakashi Iwai * This function is used to synchronize with the pending power_ref being 192e94fdbd7STakashi Iwai * released. 193e94fdbd7STakashi Iwai */ 194e94fdbd7STakashi Iwai static inline void snd_power_sync_ref(struct snd_card *card) 195e94fdbd7STakashi Iwai { 196e94fdbd7STakashi Iwai wait_event(card->power_ref_sleep, !atomic_read(&card->power_ref)); 197e94fdbd7STakashi Iwai } 198e94fdbd7STakashi Iwai 199d5750f67SHenrik Kretzschmar /* init.c */ 200b6cc78daSTakashi Iwai int snd_power_wait(struct snd_card *card); 201e94fdbd7STakashi Iwai int snd_power_ref_and_wait(struct snd_card *card); 202d5750f67SHenrik Kretzschmar 2031da177e4SLinus Torvalds #else /* ! CONFIG_PM */ 2041da177e4SLinus Torvalds 205b6cc78daSTakashi Iwai static inline int snd_power_wait(struct snd_card *card) { return 0; } 206e94fdbd7STakashi Iwai static inline void snd_power_ref(struct snd_card *card) {} 207e94fdbd7STakashi Iwai static inline void snd_power_unref(struct snd_card *card) {} 208e94fdbd7STakashi Iwai static inline int snd_power_ref_and_wait(struct snd_card *card) { return 0; } 209e94fdbd7STakashi Iwai static inline void snd_power_sync_ref(struct snd_card *card) {} 210363129eaSMike Frysinger #define snd_power_get_state(card) ({ (void)(card); SNDRV_CTL_POWER_D0; }) 2111da177e4SLinus Torvalds #define snd_power_change_state(card, state) do { (void)(card); } while (0) 2121da177e4SLinus Torvalds 2131da177e4SLinus Torvalds #endif /* CONFIG_PM */ 2141da177e4SLinus Torvalds 215512bbd6aSTakashi Iwai struct snd_minor { 2162af677fcSClemens Ladisch int type; /* SNDRV_DEVICE_TYPE_XXX */ 2176983b724SClemens Ladisch int card; /* card number */ 2181da177e4SLinus Torvalds int device; /* device number */ 21999ac48f5SArjan van de Ven const struct file_operations *f_ops; /* file operations */ 220f87135f5SClemens Ladisch void *private_data; /* private data for f_ops->open */ 221d80f19faSGreg Kroah-Hartman struct device *dev; /* device for sysfs */ 222a0830dbdSTakashi Iwai struct snd_card *card_ptr; /* assigned card instance */ 2231da177e4SLinus Torvalds }; 2241da177e4SLinus Torvalds 2257d2aae1eSTakashi Iwai /* return a device pointer linked to each sound device as a parent */ 2267d2aae1eSTakashi Iwai static inline struct device *snd_card_get_device_link(struct snd_card *card) 2277d2aae1eSTakashi Iwai { 2288bfb181cSTakashi Iwai return card ? &card->card_dev : NULL; 2297d2aae1eSTakashi Iwai } 2307d2aae1eSTakashi Iwai 2311da177e4SLinus Torvalds /* sound.c */ 2321da177e4SLinus Torvalds 233f1902860SClemens Ladisch extern int snd_major; 2341da177e4SLinus Torvalds extern int snd_ecards_limit; 235*8d0cf150SIvan Orlov extern const struct class sound_class; 2362d670ea2SHui Wang #ifdef CONFIG_SND_DEBUG 2372d670ea2SHui Wang extern struct dentry *sound_debugfs_root; 2382d670ea2SHui Wang #endif 2391da177e4SLinus Torvalds 2401da177e4SLinus Torvalds void snd_request_card(int card); 2411da177e4SLinus Torvalds 2424b440be6STakashi Iwai void snd_device_initialize(struct device *dev, struct snd_card *card); 2434b440be6STakashi Iwai 24440a4b263STakashi Iwai int snd_register_device(int type, struct snd_card *card, int dev, 24512b131c4SJohannes Berg const struct file_operations *f_ops, 24640a4b263STakashi Iwai void *private_data, struct device *device); 24740a4b263STakashi Iwai int snd_unregister_device(struct device *dev); 248f87135f5SClemens Ladisch void *snd_lookup_minor_data(unsigned int minor, int type); 2491da177e4SLinus Torvalds 2501da177e4SLinus Torvalds #ifdef CONFIG_SND_OSSEMUL 2512af677fcSClemens Ladisch int snd_register_oss_device(int type, struct snd_card *card, int dev, 25280d7d771STakashi Iwai const struct file_operations *f_ops, void *private_data); 253512bbd6aSTakashi Iwai int snd_unregister_oss_device(int type, struct snd_card *card, int dev); 254f87135f5SClemens Ladisch void *snd_lookup_oss_minor_data(unsigned int minor, int type); 2551da177e4SLinus Torvalds #endif 2561da177e4SLinus Torvalds 2571da177e4SLinus Torvalds int snd_minor_info_init(void); 2581da177e4SLinus Torvalds 2591da177e4SLinus Torvalds /* sound_oss.c */ 2601da177e4SLinus Torvalds 2611da177e4SLinus Torvalds #ifdef CONFIG_SND_OSSEMUL 2621da177e4SLinus Torvalds int snd_minor_info_oss_init(void); 2631da177e4SLinus Torvalds #else 264ad5fada5SPavel Machek static inline int snd_minor_info_oss_init(void) { return 0; } 2651da177e4SLinus Torvalds #endif 2661da177e4SLinus Torvalds 2671da177e4SLinus Torvalds /* memory.c */ 2681da177e4SLinus Torvalds 2691da177e4SLinus Torvalds int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count); 2701da177e4SLinus Torvalds int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count); 2711da177e4SLinus Torvalds 2721da177e4SLinus Torvalds /* init.c */ 2731da177e4SLinus Torvalds 274746df948STakashi Iwai int snd_card_locked(int card); 2756d2412b8STakashi Iwai #if IS_ENABLED(CONFIG_SND_MIXER_OSS) 2761da177e4SLinus Torvalds #define SND_MIXER_OSS_NOTIFY_REGISTER 0 2771da177e4SLinus Torvalds #define SND_MIXER_OSS_NOTIFY_DISCONNECT 1 2781da177e4SLinus Torvalds #define SND_MIXER_OSS_NOTIFY_FREE 2 279512bbd6aSTakashi Iwai extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd); 2801da177e4SLinus Torvalds #endif 2811da177e4SLinus Torvalds 282393aa9c1STakashi Iwai int snd_card_new(struct device *parent, int idx, const char *xid, 28353fb1e63STakashi Iwai struct module *module, int extra_size, 28453fb1e63STakashi Iwai struct snd_card **card_ret); 285e8ad415bSTakashi Iwai int snd_devm_card_new(struct device *parent, int idx, const char *xid, 286e8ad415bSTakashi Iwai struct module *module, size_t extra_size, 287e8ad415bSTakashi Iwai struct snd_card **card_ret); 28853fb1e63STakashi Iwai 289663f922fSUwe Kleine-König void snd_card_disconnect(struct snd_card *card); 290c44027c8STakashi Iwai void snd_card_disconnect_sync(struct snd_card *card); 29125a5a77aSUwe Kleine-König void snd_card_free(struct snd_card *card); 29273c5685cSUwe Kleine-König void snd_card_free_when_closed(struct snd_card *card); 293fee2b871STakashi Iwai int snd_card_free_on_error(struct device *dev, int ret); 29410a8ebbbSJaroslav Kysela void snd_card_set_id(struct snd_card *card, const char *id); 295512bbd6aSTakashi Iwai int snd_card_register(struct snd_card *card); 2961da177e4SLinus Torvalds int snd_card_info_init(void); 2976bbc7fedSTakashi Iwai int snd_card_add_dev_attr(struct snd_card *card, 2986bbc7fedSTakashi Iwai const struct attribute_group *group); 299512bbd6aSTakashi Iwai int snd_component_add(struct snd_card *card, const char *component); 300512bbd6aSTakashi Iwai int snd_card_file_add(struct snd_card *card, struct file *file); 301512bbd6aSTakashi Iwai int snd_card_file_remove(struct snd_card *card, struct file *file); 302f4fa9689STakashi Iwai 303f4fa9689STakashi Iwai struct snd_card *snd_card_ref(int card); 304f4fa9689STakashi Iwai 305f4fa9689STakashi Iwai /** 306f4fa9689STakashi Iwai * snd_card_unref - Unreference the card object 307f4fa9689STakashi Iwai * @card: the card object to unreference 308f4fa9689STakashi Iwai * 309f4fa9689STakashi Iwai * Call this function for the card object that was obtained via snd_card_ref() 310f4fa9689STakashi Iwai * or snd_lookup_minor_data(). 311f4fa9689STakashi Iwai */ 312f4fa9689STakashi Iwai static inline void snd_card_unref(struct snd_card *card) 313f4fa9689STakashi Iwai { 314f4fa9689STakashi Iwai put_device(&card->card_dev); 315f4fa9689STakashi Iwai } 3161da177e4SLinus Torvalds 3177d2aae1eSTakashi Iwai #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr)) 3181da177e4SLinus Torvalds 3191da177e4SLinus Torvalds /* device.c */ 3201da177e4SLinus Torvalds 3219ce50543STakashi Iwai int snd_device_new(struct snd_card *card, enum snd_device_type type, 3228b575824STakashi Iwai void *device_data, const struct snd_device_ops *ops); 323512bbd6aSTakashi Iwai int snd_device_register(struct snd_card *card, void *device_data); 324512bbd6aSTakashi Iwai int snd_device_register_all(struct snd_card *card); 325e086e303STakashi Iwai void snd_device_disconnect(struct snd_card *card, void *device_data); 326e086e303STakashi Iwai void snd_device_disconnect_all(struct snd_card *card); 32772620d60STakashi Iwai void snd_device_free(struct snd_card *card, void *device_data); 32872620d60STakashi Iwai void snd_device_free_all(struct snd_card *card); 329c208a533STakashi Iwai int snd_device_get_state(struct snd_card *card, void *device_data); 3301da177e4SLinus Torvalds 3311da177e4SLinus Torvalds /* isadma.c */ 3321da177e4SLinus Torvalds 333276bd31cSAl Viro #ifdef CONFIG_ISA_DMA_API 3341da177e4SLinus Torvalds #define DMA_MODE_NO_ENABLE 0x0100 3351da177e4SLinus Torvalds 3361da177e4SLinus Torvalds void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode); 3371da177e4SLinus Torvalds void snd_dma_disable(unsigned long dma); 3381da177e4SLinus Torvalds unsigned int snd_dma_pointer(unsigned long dma, unsigned int size); 339c2b94954STakashi Iwai int snd_devm_request_dma(struct device *dev, int dma, const char *name); 340276bd31cSAl Viro #endif 3411da177e4SLinus Torvalds 3421da177e4SLinus Torvalds /* misc.c */ 343b709e574STakashi Iwai struct resource; 344b1d5776dSTakashi Iwai void release_and_free_resource(struct resource *res); 3451da177e4SLinus Torvalds 3461da177e4SLinus Torvalds /* --- */ 3471da177e4SLinus Torvalds 348fae3d88aSFengguang Wu /* sound printk debug levels */ 349fae3d88aSFengguang Wu enum { 350fae3d88aSFengguang Wu SND_PR_ALWAYS, 351fae3d88aSFengguang Wu SND_PR_DEBUG, 352fae3d88aSFengguang Wu SND_PR_VERBOSE, 353fae3d88aSFengguang Wu }; 354fae3d88aSFengguang Wu 35536ce99c1STakashi Iwai #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK) 356b9075fa9SJoe Perches __printf(4, 5) 35736ce99c1STakashi Iwai void __snd_printk(unsigned int level, const char *file, int line, 358b9075fa9SJoe Perches const char *format, ...); 35936ce99c1STakashi Iwai #else 36043e575faSTakashi Iwai #define __snd_printk(level, file, line, format, ...) \ 36143e575faSTakashi Iwai printk(format, ##__VA_ARGS__) 36236ce99c1STakashi Iwai #endif 36336ce99c1STakashi Iwai 3641da177e4SLinus Torvalds /** 3651da177e4SLinus Torvalds * snd_printk - printk wrapper 3661da177e4SLinus Torvalds * @fmt: format string 3671da177e4SLinus Torvalds * 368f66fcedcSTakashi Iwai * Works like printk() but prints the file and the line of the caller 3691da177e4SLinus Torvalds * when configured with CONFIG_SND_VERBOSE_PRINTK. 3701da177e4SLinus Torvalds */ 37143e575faSTakashi Iwai #define snd_printk(fmt, ...) \ 37243e575faSTakashi Iwai __snd_printk(0, __FILE__, __LINE__, fmt, ##__VA_ARGS__) 3731da177e4SLinus Torvalds 3741da177e4SLinus Torvalds #ifdef CONFIG_SND_DEBUG 3751da177e4SLinus Torvalds /** 3761da177e4SLinus Torvalds * snd_printd - debug printk 3770863afb3SMartin Waitz * @fmt: format string 3781da177e4SLinus Torvalds * 379edab938eSPavel Machek * Works like snd_printk() for debugging purposes. 3801da177e4SLinus Torvalds * Ignored when CONFIG_SND_DEBUG is not set. 3811da177e4SLinus Torvalds */ 38243e575faSTakashi Iwai #define snd_printd(fmt, ...) \ 38343e575faSTakashi Iwai __snd_printk(1, __FILE__, __LINE__, fmt, ##__VA_ARGS__) 38443e575faSTakashi Iwai #define _snd_printd(level, fmt, ...) \ 38543e575faSTakashi Iwai __snd_printk(level, __FILE__, __LINE__, fmt, ##__VA_ARGS__) 3867c22f1aaSTakashi Iwai 387f66fcedcSTakashi Iwai /** 388f66fcedcSTakashi Iwai * snd_BUG - give a BUG warning message and stack trace 389f66fcedcSTakashi Iwai * 390f66fcedcSTakashi Iwai * Calls WARN() if CONFIG_SND_DEBUG is set. 391f66fcedcSTakashi Iwai * Ignored when CONFIG_SND_DEBUG is not set. 392f66fcedcSTakashi Iwai */ 393bdbecf50STakashi Iwai #define snd_BUG() WARN(1, "BUG?\n") 394f66fcedcSTakashi Iwai 395f66fcedcSTakashi Iwai /** 396f7b6603cSMauro Carvalho Chehab * snd_printd_ratelimit - Suppress high rates of output when 397f7b6603cSMauro Carvalho Chehab * CONFIG_SND_DEBUG is enabled. 398bcbb1553STim Gardner */ 399bcbb1553STim Gardner #define snd_printd_ratelimit() printk_ratelimit() 400bcbb1553STim Gardner 401bcbb1553STim Gardner /** 402f66fcedcSTakashi Iwai * snd_BUG_ON - debugging check macro 403f66fcedcSTakashi Iwai * @cond: condition to evaluate 404f66fcedcSTakashi Iwai * 405d5702162SChristine Spang * Has the same behavior as WARN_ON when CONFIG_SND_DEBUG is set, 406d5702162SChristine Spang * otherwise just evaluates the conditional and returns the value. 407f66fcedcSTakashi Iwai */ 408d5702162SChristine Spang #define snd_BUG_ON(cond) WARN_ON((cond)) 4091da177e4SLinus Torvalds 4101da177e4SLinus Torvalds #else /* !CONFIG_SND_DEBUG */ 4111da177e4SLinus Torvalds 41286b27237STakashi Iwai __printf(1, 2) 41386b27237STakashi Iwai static inline void snd_printd(const char *format, ...) {} 41486b27237STakashi Iwai __printf(2, 3) 41586b27237STakashi Iwai static inline void _snd_printd(int level, const char *format, ...) {} 41686b27237STakashi Iwai 417fcef7836SAndrew Morton #define snd_BUG() do { } while (0) 418d5702162SChristine Spang 419d5702162SChristine Spang #define snd_BUG_ON(condition) ({ \ 420d5702162SChristine Spang int __ret_warn_on = !!(condition); \ 421d5702162SChristine Spang unlikely(__ret_warn_on); \ 422d5702162SChristine Spang }) 4231da177e4SLinus Torvalds 424bcbb1553STim Gardner static inline bool snd_printd_ratelimit(void) { return false; } 425bcbb1553STim Gardner 4261da177e4SLinus Torvalds #endif /* CONFIG_SND_DEBUG */ 4271da177e4SLinus Torvalds 42862cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE 4291da177e4SLinus Torvalds /** 4301da177e4SLinus Torvalds * snd_printdd - debug printk 4311da177e4SLinus Torvalds * @format: format string 4321da177e4SLinus Torvalds * 433edab938eSPavel Machek * Works like snd_printk() for debugging purposes. 43462cf872aSTakashi Iwai * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set. 4351da177e4SLinus Torvalds */ 43643e575faSTakashi Iwai #define snd_printdd(format, ...) \ 43743e575faSTakashi Iwai __snd_printk(2, __FILE__, __LINE__, format, ##__VA_ARGS__) 4381da177e4SLinus Torvalds #else 43986b27237STakashi Iwai __printf(1, 2) 44086b27237STakashi Iwai static inline void snd_printdd(const char *format, ...) {} 4411da177e4SLinus Torvalds #endif 4421da177e4SLinus Torvalds 4431da177e4SLinus Torvalds 4441da177e4SLinus Torvalds #define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) /* 3.8.1a */ 4451da177e4SLinus Torvalds 4461da177e4SLinus Torvalds /* for easier backward-porting */ 4476d2412b8STakashi Iwai #if IS_ENABLED(CONFIG_GAMEPORT) 4481da177e4SLinus Torvalds #define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev)) 4491da177e4SLinus Torvalds #define gameport_set_port_data(gp,r) ((gp)->port_data = (r)) 4501da177e4SLinus Torvalds #define gameport_get_port_data(gp) (gp)->port_data 4511da177e4SLinus Torvalds #endif 4521da177e4SLinus Torvalds 453d9ea472cSTakashi Iwai /* PCI quirk list helper */ 454d9ea472cSTakashi Iwai struct snd_pci_quirk { 455d9ea472cSTakashi Iwai unsigned short subvendor; /* PCI subvendor ID */ 456d9ea472cSTakashi Iwai unsigned short subdevice; /* PCI subdevice ID */ 4578bd4bb7aSTakashi Iwai unsigned short subdevice_mask; /* bitmask to match */ 458d9ea472cSTakashi Iwai int value; /* value */ 45962cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE 460d9ea472cSTakashi Iwai const char *name; /* name of the device (optional) */ 461d9ea472cSTakashi Iwai #endif 462d9ea472cSTakashi Iwai }; 463d9ea472cSTakashi Iwai 4648bd4bb7aSTakashi Iwai #define _SND_PCI_QUIRK_ID_MASK(vend, mask, dev) \ 4658bd4bb7aSTakashi Iwai .subvendor = (vend), .subdevice = (dev), .subdevice_mask = (mask) 466d9ea472cSTakashi Iwai #define _SND_PCI_QUIRK_ID(vend, dev) \ 4678bd4bb7aSTakashi Iwai _SND_PCI_QUIRK_ID_MASK(vend, 0xffff, dev) 468d9ea472cSTakashi Iwai #define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)} 46962cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE 470d9ea472cSTakashi Iwai #define SND_PCI_QUIRK(vend,dev,xname,val) \ 471d9ea472cSTakashi Iwai {_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)} 4728bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_VENDOR(vend, xname, val) \ 4738bd4bb7aSTakashi Iwai {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val), .name = (xname)} 4748bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \ 4758bd4bb7aSTakashi Iwai {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), \ 4768bd4bb7aSTakashi Iwai .value = (val), .name = (xname)} 47786b27237STakashi Iwai #define snd_pci_quirk_name(q) ((q)->name) 478d9ea472cSTakashi Iwai #else 479d9ea472cSTakashi Iwai #define SND_PCI_QUIRK(vend,dev,xname,val) \ 480d9ea472cSTakashi Iwai {_SND_PCI_QUIRK_ID(vend, dev), .value = (val)} 4818bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \ 4828bd4bb7aSTakashi Iwai {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), .value = (val)} 4838bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_VENDOR(vend, xname, val) \ 4848bd4bb7aSTakashi Iwai {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val)} 48586b27237STakashi Iwai #define snd_pci_quirk_name(q) "" 486d9ea472cSTakashi Iwai #endif 487d9ea472cSTakashi Iwai 488f0a220deSDylan Reid #ifdef CONFIG_PCI 489d9ea472cSTakashi Iwai const struct snd_pci_quirk * 490d9ea472cSTakashi Iwai snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list); 491d9ea472cSTakashi Iwai 492d1458279STakashi Iwai const struct snd_pci_quirk * 493d1458279STakashi Iwai snd_pci_quirk_lookup_id(u16 vendor, u16 device, 494d1458279STakashi Iwai const struct snd_pci_quirk *list); 495f0a220deSDylan Reid #else 496f0a220deSDylan Reid static inline const struct snd_pci_quirk * 497f0a220deSDylan Reid snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list) 498f0a220deSDylan Reid { 499f0a220deSDylan Reid return NULL; 500f0a220deSDylan Reid } 501f0a220deSDylan Reid 502f0a220deSDylan Reid static inline const struct snd_pci_quirk * 503f0a220deSDylan Reid snd_pci_quirk_lookup_id(u16 vendor, u16 device, 504f0a220deSDylan Reid const struct snd_pci_quirk *list) 505f0a220deSDylan Reid { 506f0a220deSDylan Reid return NULL; 507f0a220deSDylan Reid } 5088422fa11SAxel Lin #endif 509d9ea472cSTakashi Iwai 510ef34a0aeSTakashi Iwai /* async signal helpers */ 511ef34a0aeSTakashi Iwai struct snd_fasync; 512ef34a0aeSTakashi Iwai 513ef34a0aeSTakashi Iwai int snd_fasync_helper(int fd, struct file *file, int on, 514ef34a0aeSTakashi Iwai struct snd_fasync **fasyncp); 515ef34a0aeSTakashi Iwai void snd_kill_fasync(struct snd_fasync *fasync, int signal, int poll); 516ef34a0aeSTakashi Iwai void snd_fasync_free(struct snd_fasync *fasync); 517ef34a0aeSTakashi Iwai 5181da177e4SLinus Torvalds #endif /* __SOUND_CORE_H */ 519