xref: /linux/include/sound/core.h (revision 3a39d672e7f48b8d6b91a09afa4b55352773b4b5)
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 
996a66b01dSTakashi 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) */
102*38ea4c3dSTakashi Iwai 	rwlock_t controls_rwlock;	/* lock for lookup and ctl_files list */
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
snd_power_get_state(struct snd_card * card)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 
snd_power_change_state(struct snd_card * card,unsigned int state)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  */
snd_power_ref(struct snd_card * card)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  */
snd_power_unref(struct snd_card * card)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  */
snd_power_sync_ref(struct snd_card * card)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 
snd_power_wait(struct snd_card * card)205b6cc78daSTakashi Iwai static inline int snd_power_wait(struct snd_card *card) { return 0; }
snd_power_ref(struct snd_card * card)206e94fdbd7STakashi Iwai static inline void snd_power_ref(struct snd_card *card) {}
snd_power_unref(struct snd_card * card)207e94fdbd7STakashi Iwai static inline void snd_power_unref(struct snd_card *card) {}
snd_power_ref_and_wait(struct snd_card * card)208e94fdbd7STakashi Iwai static inline int snd_power_ref_and_wait(struct snd_card *card) { return 0; }
snd_power_sync_ref(struct snd_card * card)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 */
snd_card_get_device_link(struct snd_card * card)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;
2358d0cf150SIvan 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 
2427f018db1STakashi Iwai int snd_device_alloc(struct device **dev_p, 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
snd_minor_info_oss_init(void)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  */
snd_card_unref(struct snd_card * card)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 
3481da177e4SLinus Torvalds #ifdef CONFIG_SND_DEBUG
3491da177e4SLinus Torvalds /**
350f66fcedcSTakashi Iwai  * snd_BUG - give a BUG warning message and stack trace
351f66fcedcSTakashi Iwai  *
352f66fcedcSTakashi Iwai  * Calls WARN() if CONFIG_SND_DEBUG is set.
353f66fcedcSTakashi Iwai  * Ignored when CONFIG_SND_DEBUG is not set.
354f66fcedcSTakashi Iwai  */
355bdbecf50STakashi Iwai #define snd_BUG()		WARN(1, "BUG?\n")
356f66fcedcSTakashi Iwai 
357f66fcedcSTakashi Iwai /**
358f66fcedcSTakashi Iwai  * snd_BUG_ON - debugging check macro
359f66fcedcSTakashi Iwai  * @cond: condition to evaluate
360f66fcedcSTakashi Iwai  *
361d5702162SChristine Spang  * Has the same behavior as WARN_ON when CONFIG_SND_DEBUG is set,
362d5702162SChristine Spang  * otherwise just evaluates the conditional and returns the value.
363f66fcedcSTakashi Iwai  */
364d5702162SChristine Spang #define snd_BUG_ON(cond)	WARN_ON((cond))
3651da177e4SLinus Torvalds 
3661da177e4SLinus Torvalds #else /* !CONFIG_SND_DEBUG */
3671da177e4SLinus Torvalds 
368fcef7836SAndrew Morton #define snd_BUG()			do { } while (0)
369d5702162SChristine Spang 
370d5702162SChristine Spang #define snd_BUG_ON(condition) ({ \
371d5702162SChristine Spang 	int __ret_warn_on = !!(condition); \
372d5702162SChristine Spang 	unlikely(__ret_warn_on); \
373d5702162SChristine Spang })
3741da177e4SLinus Torvalds 
3751da177e4SLinus Torvalds #endif /* CONFIG_SND_DEBUG */
3761da177e4SLinus Torvalds 
3771da177e4SLinus Torvalds #define SNDRV_OSS_VERSION         ((3<<16)|(8<<8)|(1<<4)|(0))	/* 3.8.1a */
3781da177e4SLinus Torvalds 
3791da177e4SLinus Torvalds /* for easier backward-porting */
3806d2412b8STakashi Iwai #if IS_ENABLED(CONFIG_GAMEPORT)
3811da177e4SLinus Torvalds #define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev))
3821da177e4SLinus Torvalds #define gameport_set_port_data(gp,r) ((gp)->port_data = (r))
3831da177e4SLinus Torvalds #define gameport_get_port_data(gp) (gp)->port_data
3841da177e4SLinus Torvalds #endif
3851da177e4SLinus Torvalds 
386d9ea472cSTakashi Iwai /* PCI quirk list helper */
387d9ea472cSTakashi Iwai struct snd_pci_quirk {
388d9ea472cSTakashi Iwai 	unsigned short subvendor;	/* PCI subvendor ID */
389d9ea472cSTakashi Iwai 	unsigned short subdevice;	/* PCI subdevice ID */
3908bd4bb7aSTakashi Iwai 	unsigned short subdevice_mask;	/* bitmask to match */
391d9ea472cSTakashi Iwai 	int value;			/* value */
39262cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE
393d9ea472cSTakashi Iwai 	const char *name;		/* name of the device (optional) */
394d9ea472cSTakashi Iwai #endif
395d9ea472cSTakashi Iwai };
396d9ea472cSTakashi Iwai 
3978bd4bb7aSTakashi Iwai #define _SND_PCI_QUIRK_ID_MASK(vend, mask, dev)	\
3988bd4bb7aSTakashi Iwai 	.subvendor = (vend), .subdevice = (dev), .subdevice_mask = (mask)
399d9ea472cSTakashi Iwai #define _SND_PCI_QUIRK_ID(vend, dev) \
4008bd4bb7aSTakashi Iwai 	_SND_PCI_QUIRK_ID_MASK(vend, 0xffff, dev)
401d9ea472cSTakashi Iwai #define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)}
40262cf872aSTakashi Iwai #ifdef CONFIG_SND_DEBUG_VERBOSE
403d9ea472cSTakashi Iwai #define SND_PCI_QUIRK(vend,dev,xname,val) \
404d9ea472cSTakashi Iwai 	{_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)}
4058bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_VENDOR(vend, xname, val)			\
4068bd4bb7aSTakashi Iwai 	{_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val), .name = (xname)}
4078bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val)			\
4088bd4bb7aSTakashi Iwai 	{_SND_PCI_QUIRK_ID_MASK(vend, mask, dev),			\
4098bd4bb7aSTakashi Iwai 			.value = (val), .name = (xname)}
41086b27237STakashi Iwai #define snd_pci_quirk_name(q)	((q)->name)
411d9ea472cSTakashi Iwai #else
412d9ea472cSTakashi Iwai #define SND_PCI_QUIRK(vend,dev,xname,val) \
413d9ea472cSTakashi Iwai 	{_SND_PCI_QUIRK_ID(vend, dev), .value = (val)}
4148bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val)			\
4158bd4bb7aSTakashi Iwai 	{_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), .value = (val)}
4168bd4bb7aSTakashi Iwai #define SND_PCI_QUIRK_VENDOR(vend, xname, val)			\
4178bd4bb7aSTakashi Iwai 	{_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val)}
41886b27237STakashi Iwai #define snd_pci_quirk_name(q)	""
419d9ea472cSTakashi Iwai #endif
420d9ea472cSTakashi Iwai 
421f0a220deSDylan Reid #ifdef CONFIG_PCI
422d9ea472cSTakashi Iwai const struct snd_pci_quirk *
423d9ea472cSTakashi Iwai snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list);
424d9ea472cSTakashi Iwai 
425d1458279STakashi Iwai const struct snd_pci_quirk *
426d1458279STakashi Iwai snd_pci_quirk_lookup_id(u16 vendor, u16 device,
427d1458279STakashi Iwai 			const struct snd_pci_quirk *list);
428f0a220deSDylan Reid #else
429f0a220deSDylan Reid static inline const struct snd_pci_quirk *
snd_pci_quirk_lookup(struct pci_dev * pci,const struct snd_pci_quirk * list)430f0a220deSDylan Reid snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list)
431f0a220deSDylan Reid {
432f0a220deSDylan Reid 	return NULL;
433f0a220deSDylan Reid }
434f0a220deSDylan Reid 
435f0a220deSDylan Reid static inline const struct snd_pci_quirk *
snd_pci_quirk_lookup_id(u16 vendor,u16 device,const struct snd_pci_quirk * list)436f0a220deSDylan Reid snd_pci_quirk_lookup_id(u16 vendor, u16 device,
437f0a220deSDylan Reid 			const struct snd_pci_quirk *list)
438f0a220deSDylan Reid {
439f0a220deSDylan Reid 	return NULL;
440f0a220deSDylan Reid }
4418422fa11SAxel Lin #endif
442d9ea472cSTakashi Iwai 
443ef34a0aeSTakashi Iwai /* async signal helpers */
444ef34a0aeSTakashi Iwai struct snd_fasync;
445ef34a0aeSTakashi Iwai 
446ef34a0aeSTakashi Iwai int snd_fasync_helper(int fd, struct file *file, int on,
447ef34a0aeSTakashi Iwai 		      struct snd_fasync **fasyncp);
448ef34a0aeSTakashi Iwai void snd_kill_fasync(struct snd_fasync *fasync, int signal, int poll);
449ef34a0aeSTakashi Iwai void snd_fasync_free(struct snd_fasync *fasync);
450ef34a0aeSTakashi Iwai 
4511da177e4SLinus Torvalds #endif /* __SOUND_CORE_H */
452