18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci#ifndef __SOUND_CORE_H
38c2ecf20Sopenharmony_ci#define __SOUND_CORE_H
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci/*
68c2ecf20Sopenharmony_ci *  Main header file for the ALSA driver
78c2ecf20Sopenharmony_ci *  Copyright (c) 1994-2001 by Jaroslav Kysela <perex@perex.cz>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/device.h>
118c2ecf20Sopenharmony_ci#include <linux/sched.h>		/* wake_up() */
128c2ecf20Sopenharmony_ci#include <linux/mutex.h>		/* struct mutex */
138c2ecf20Sopenharmony_ci#include <linux/rwsem.h>		/* struct rw_semaphore */
148c2ecf20Sopenharmony_ci#include <linux/pm.h>			/* pm_message_t */
158c2ecf20Sopenharmony_ci#include <linux/stringify.h>
168c2ecf20Sopenharmony_ci#include <linux/printk.h>
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci/* number of supported soundcards */
198c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_DYNAMIC_MINORS
208c2ecf20Sopenharmony_ci#define SNDRV_CARDS CONFIG_SND_MAX_CARDS
218c2ecf20Sopenharmony_ci#else
228c2ecf20Sopenharmony_ci#define SNDRV_CARDS 8		/* don't change - minor numbers */
238c2ecf20Sopenharmony_ci#endif
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define CONFIG_SND_MAJOR	116	/* standard configuration */
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* forward declarations */
288c2ecf20Sopenharmony_cistruct pci_dev;
298c2ecf20Sopenharmony_cistruct module;
308c2ecf20Sopenharmony_cistruct completion;
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci/* device allocation stuff */
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* type of the object used in snd_device_*()
358c2ecf20Sopenharmony_ci * this also defines the calling order
368c2ecf20Sopenharmony_ci */
378c2ecf20Sopenharmony_cienum snd_device_type {
388c2ecf20Sopenharmony_ci	SNDRV_DEV_LOWLEVEL,
398c2ecf20Sopenharmony_ci	SNDRV_DEV_INFO,
408c2ecf20Sopenharmony_ci	SNDRV_DEV_BUS,
418c2ecf20Sopenharmony_ci	SNDRV_DEV_CODEC,
428c2ecf20Sopenharmony_ci	SNDRV_DEV_PCM,
438c2ecf20Sopenharmony_ci	SNDRV_DEV_COMPRESS,
448c2ecf20Sopenharmony_ci	SNDRV_DEV_RAWMIDI,
458c2ecf20Sopenharmony_ci	SNDRV_DEV_TIMER,
468c2ecf20Sopenharmony_ci	SNDRV_DEV_SEQUENCER,
478c2ecf20Sopenharmony_ci	SNDRV_DEV_HWDEP,
488c2ecf20Sopenharmony_ci	SNDRV_DEV_JACK,
498c2ecf20Sopenharmony_ci	SNDRV_DEV_CONTROL,	/* NOTE: this must be the last one */
508c2ecf20Sopenharmony_ci};
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cienum snd_device_state {
538c2ecf20Sopenharmony_ci	SNDRV_DEV_BUILD,
548c2ecf20Sopenharmony_ci	SNDRV_DEV_REGISTERED,
558c2ecf20Sopenharmony_ci	SNDRV_DEV_DISCONNECTED,
568c2ecf20Sopenharmony_ci};
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistruct snd_device;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistruct snd_device_ops {
618c2ecf20Sopenharmony_ci	int (*dev_free)(struct snd_device *dev);
628c2ecf20Sopenharmony_ci	int (*dev_register)(struct snd_device *dev);
638c2ecf20Sopenharmony_ci	int (*dev_disconnect)(struct snd_device *dev);
648c2ecf20Sopenharmony_ci};
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_cistruct snd_device {
678c2ecf20Sopenharmony_ci	struct list_head list;		/* list of registered devices */
688c2ecf20Sopenharmony_ci	struct snd_card *card;		/* card which holds this device */
698c2ecf20Sopenharmony_ci	enum snd_device_state state;	/* state of the device */
708c2ecf20Sopenharmony_ci	enum snd_device_type type;	/* device type */
718c2ecf20Sopenharmony_ci	void *device_data;		/* device structure */
728c2ecf20Sopenharmony_ci	const struct snd_device_ops *ops;	/* operations */
738c2ecf20Sopenharmony_ci};
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci#define snd_device(n) list_entry(n, struct snd_device, list)
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci/* main structure for soundcard */
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistruct snd_card {
808c2ecf20Sopenharmony_ci	int number;			/* number of soundcard (index to
818c2ecf20Sopenharmony_ci								snd_cards) */
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	char id[16];			/* id string of this card */
848c2ecf20Sopenharmony_ci	char driver[16];		/* driver name */
858c2ecf20Sopenharmony_ci	char shortname[32];		/* short name of this soundcard */
868c2ecf20Sopenharmony_ci	char longname[80];		/* name of this soundcard */
878c2ecf20Sopenharmony_ci	char irq_descr[32];		/* Interrupt description */
888c2ecf20Sopenharmony_ci	char mixername[80];		/* mixer name */
898c2ecf20Sopenharmony_ci	char components[128];		/* card components delimited with
908c2ecf20Sopenharmony_ci								space */
918c2ecf20Sopenharmony_ci	struct module *module;		/* top-level module */
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci	void *private_data;		/* private data for soundcard */
948c2ecf20Sopenharmony_ci	void (*private_free) (struct snd_card *card); /* callback for freeing of
958c2ecf20Sopenharmony_ci								private data */
968c2ecf20Sopenharmony_ci	struct list_head devices;	/* devices */
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	struct device ctl_dev;		/* control device */
998c2ecf20Sopenharmony_ci	unsigned int last_numid;	/* last used numeric ID */
1008c2ecf20Sopenharmony_ci	struct rw_semaphore controls_rwsem;	/* controls list lock */
1018c2ecf20Sopenharmony_ci	rwlock_t ctl_files_rwlock;	/* ctl_files list lock */
1028c2ecf20Sopenharmony_ci	int controls_count;		/* count of all controls */
1038c2ecf20Sopenharmony_ci	int user_ctl_count;		/* count of all user controls */
1048c2ecf20Sopenharmony_ci	struct list_head controls;	/* all controls for this card */
1058c2ecf20Sopenharmony_ci	struct list_head ctl_files;	/* active control files */
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	struct snd_info_entry *proc_root;	/* root for soundcard specific files */
1088c2ecf20Sopenharmony_ci	struct proc_dir_entry *proc_root_link;	/* number link to real id */
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_ci	struct list_head files_list;	/* all files associated to this card */
1118c2ecf20Sopenharmony_ci	struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown
1128c2ecf20Sopenharmony_ci								state */
1138c2ecf20Sopenharmony_ci	spinlock_t files_lock;		/* lock the files for this card */
1148c2ecf20Sopenharmony_ci	int shutdown;			/* this card is going down */
1158c2ecf20Sopenharmony_ci	struct completion *release_completion;
1168c2ecf20Sopenharmony_ci	struct device *dev;		/* device assigned to this card */
1178c2ecf20Sopenharmony_ci	struct device card_dev;		/* cardX object for sysfs */
1188c2ecf20Sopenharmony_ci	const struct attribute_group *dev_groups[4]; /* assigned sysfs attr */
1198c2ecf20Sopenharmony_ci	bool registered;		/* card_dev is registered? */
1208c2ecf20Sopenharmony_ci	int sync_irq;			/* assigned irq, used for PCM sync */
1218c2ecf20Sopenharmony_ci	wait_queue_head_t remove_sleep;
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ci	size_t total_pcm_alloc_bytes;	/* total amount of allocated buffers */
1248c2ecf20Sopenharmony_ci	struct mutex memory_mutex;	/* protection for the above */
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
1278c2ecf20Sopenharmony_ci	unsigned int power_state;	/* power state */
1288c2ecf20Sopenharmony_ci	wait_queue_head_t power_sleep;
1298c2ecf20Sopenharmony_ci#endif
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_SND_MIXER_OSS)
1328c2ecf20Sopenharmony_ci	struct snd_mixer_oss *mixer_oss;
1338c2ecf20Sopenharmony_ci	int mixer_oss_change_count;
1348c2ecf20Sopenharmony_ci#endif
1358c2ecf20Sopenharmony_ci};
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci#define dev_to_snd_card(p)	container_of(p, struct snd_card, card_dev)
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci#ifdef CONFIG_PM
1408c2ecf20Sopenharmony_cistatic inline unsigned int snd_power_get_state(struct snd_card *card)
1418c2ecf20Sopenharmony_ci{
1428c2ecf20Sopenharmony_ci	return card->power_state;
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistatic inline void snd_power_change_state(struct snd_card *card, unsigned int state)
1468c2ecf20Sopenharmony_ci{
1478c2ecf20Sopenharmony_ci	card->power_state = state;
1488c2ecf20Sopenharmony_ci	wake_up(&card->power_sleep);
1498c2ecf20Sopenharmony_ci}
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_ci/* init.c */
1528c2ecf20Sopenharmony_ciint snd_power_wait(struct snd_card *card, unsigned int power_state);
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ci#else /* ! CONFIG_PM */
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_cistatic inline int snd_power_wait(struct snd_card *card, unsigned int state) { return 0; }
1578c2ecf20Sopenharmony_ci#define snd_power_get_state(card)	({ (void)(card); SNDRV_CTL_POWER_D0; })
1588c2ecf20Sopenharmony_ci#define snd_power_change_state(card, state)	do { (void)(card); } while (0)
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci#endif /* CONFIG_PM */
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_cistruct snd_minor {
1638c2ecf20Sopenharmony_ci	int type;			/* SNDRV_DEVICE_TYPE_XXX */
1648c2ecf20Sopenharmony_ci	int card;			/* card number */
1658c2ecf20Sopenharmony_ci	int device;			/* device number */
1668c2ecf20Sopenharmony_ci	const struct file_operations *f_ops;	/* file operations */
1678c2ecf20Sopenharmony_ci	void *private_data;		/* private data for f_ops->open */
1688c2ecf20Sopenharmony_ci	struct device *dev;		/* device for sysfs */
1698c2ecf20Sopenharmony_ci	struct snd_card *card_ptr;	/* assigned card instance */
1708c2ecf20Sopenharmony_ci};
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ci/* return a device pointer linked to each sound device as a parent */
1738c2ecf20Sopenharmony_cistatic inline struct device *snd_card_get_device_link(struct snd_card *card)
1748c2ecf20Sopenharmony_ci{
1758c2ecf20Sopenharmony_ci	return card ? &card->card_dev : NULL;
1768c2ecf20Sopenharmony_ci}
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci/* sound.c */
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_ciextern int snd_major;
1818c2ecf20Sopenharmony_ciextern int snd_ecards_limit;
1828c2ecf20Sopenharmony_ciextern struct class *sound_class;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_civoid snd_request_card(int card);
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_civoid snd_device_initialize(struct device *dev, struct snd_card *card);
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ciint snd_register_device(int type, struct snd_card *card, int dev,
1898c2ecf20Sopenharmony_ci			const struct file_operations *f_ops,
1908c2ecf20Sopenharmony_ci			void *private_data, struct device *device);
1918c2ecf20Sopenharmony_ciint snd_unregister_device(struct device *dev);
1928c2ecf20Sopenharmony_civoid *snd_lookup_minor_data(unsigned int minor, int type);
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_OSSEMUL
1958c2ecf20Sopenharmony_ciint snd_register_oss_device(int type, struct snd_card *card, int dev,
1968c2ecf20Sopenharmony_ci			    const struct file_operations *f_ops, void *private_data);
1978c2ecf20Sopenharmony_ciint snd_unregister_oss_device(int type, struct snd_card *card, int dev);
1988c2ecf20Sopenharmony_civoid *snd_lookup_oss_minor_data(unsigned int minor, int type);
1998c2ecf20Sopenharmony_ci#endif
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ciint snd_minor_info_init(void);
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci/* sound_oss.c */
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_OSSEMUL
2068c2ecf20Sopenharmony_ciint snd_minor_info_oss_init(void);
2078c2ecf20Sopenharmony_ci#else
2088c2ecf20Sopenharmony_cistatic inline int snd_minor_info_oss_init(void) { return 0; }
2098c2ecf20Sopenharmony_ci#endif
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_ci/* memory.c */
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ciint copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
2148c2ecf20Sopenharmony_ciint copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci/* init.c */
2178c2ecf20Sopenharmony_ci
2188c2ecf20Sopenharmony_ciint snd_card_locked(int card);
2198c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_SND_MIXER_OSS)
2208c2ecf20Sopenharmony_ci#define SND_MIXER_OSS_NOTIFY_REGISTER	0
2218c2ecf20Sopenharmony_ci#define SND_MIXER_OSS_NOTIFY_DISCONNECT	1
2228c2ecf20Sopenharmony_ci#define SND_MIXER_OSS_NOTIFY_FREE	2
2238c2ecf20Sopenharmony_ciextern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
2248c2ecf20Sopenharmony_ci#endif
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ciint snd_card_new(struct device *parent, int idx, const char *xid,
2278c2ecf20Sopenharmony_ci		 struct module *module, int extra_size,
2288c2ecf20Sopenharmony_ci		 struct snd_card **card_ret);
2298c2ecf20Sopenharmony_ci
2308c2ecf20Sopenharmony_ciint snd_card_disconnect(struct snd_card *card);
2318c2ecf20Sopenharmony_civoid snd_card_disconnect_sync(struct snd_card *card);
2328c2ecf20Sopenharmony_ciint snd_card_free(struct snd_card *card);
2338c2ecf20Sopenharmony_ciint snd_card_free_when_closed(struct snd_card *card);
2348c2ecf20Sopenharmony_civoid snd_card_set_id(struct snd_card *card, const char *id);
2358c2ecf20Sopenharmony_ciint snd_card_register(struct snd_card *card);
2368c2ecf20Sopenharmony_ciint snd_card_info_init(void);
2378c2ecf20Sopenharmony_ciint snd_card_add_dev_attr(struct snd_card *card,
2388c2ecf20Sopenharmony_ci			  const struct attribute_group *group);
2398c2ecf20Sopenharmony_ciint snd_component_add(struct snd_card *card, const char *component);
2408c2ecf20Sopenharmony_ciint snd_card_file_add(struct snd_card *card, struct file *file);
2418c2ecf20Sopenharmony_ciint snd_card_file_remove(struct snd_card *card, struct file *file);
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_cistruct snd_card *snd_card_ref(int card);
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci/**
2468c2ecf20Sopenharmony_ci * snd_card_unref - Unreference the card object
2478c2ecf20Sopenharmony_ci * @card: the card object to unreference
2488c2ecf20Sopenharmony_ci *
2498c2ecf20Sopenharmony_ci * Call this function for the card object that was obtained via snd_card_ref()
2508c2ecf20Sopenharmony_ci * or snd_lookup_minor_data().
2518c2ecf20Sopenharmony_ci */
2528c2ecf20Sopenharmony_cistatic inline void snd_card_unref(struct snd_card *card)
2538c2ecf20Sopenharmony_ci{
2548c2ecf20Sopenharmony_ci	put_device(&card->card_dev);
2558c2ecf20Sopenharmony_ci}
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci#define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
2588c2ecf20Sopenharmony_ci
2598c2ecf20Sopenharmony_ci/* device.c */
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ciint snd_device_new(struct snd_card *card, enum snd_device_type type,
2628c2ecf20Sopenharmony_ci		   void *device_data, const struct snd_device_ops *ops);
2638c2ecf20Sopenharmony_ciint snd_device_register(struct snd_card *card, void *device_data);
2648c2ecf20Sopenharmony_ciint snd_device_register_all(struct snd_card *card);
2658c2ecf20Sopenharmony_civoid snd_device_disconnect(struct snd_card *card, void *device_data);
2668c2ecf20Sopenharmony_civoid snd_device_disconnect_all(struct snd_card *card);
2678c2ecf20Sopenharmony_civoid snd_device_free(struct snd_card *card, void *device_data);
2688c2ecf20Sopenharmony_civoid snd_device_free_all(struct snd_card *card);
2698c2ecf20Sopenharmony_ciint snd_device_get_state(struct snd_card *card, void *device_data);
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_ci/* isadma.c */
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci#ifdef CONFIG_ISA_DMA_API
2748c2ecf20Sopenharmony_ci#define DMA_MODE_NO_ENABLE	0x0100
2758c2ecf20Sopenharmony_ci
2768c2ecf20Sopenharmony_civoid snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode);
2778c2ecf20Sopenharmony_civoid snd_dma_disable(unsigned long dma);
2788c2ecf20Sopenharmony_ciunsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
2798c2ecf20Sopenharmony_ci#endif
2808c2ecf20Sopenharmony_ci
2818c2ecf20Sopenharmony_ci/* misc.c */
2828c2ecf20Sopenharmony_cistruct resource;
2838c2ecf20Sopenharmony_civoid release_and_free_resource(struct resource *res);
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci/* --- */
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci/* sound printk debug levels */
2888c2ecf20Sopenharmony_cienum {
2898c2ecf20Sopenharmony_ci	SND_PR_ALWAYS,
2908c2ecf20Sopenharmony_ci	SND_PR_DEBUG,
2918c2ecf20Sopenharmony_ci	SND_PR_VERBOSE,
2928c2ecf20Sopenharmony_ci};
2938c2ecf20Sopenharmony_ci
2948c2ecf20Sopenharmony_ci#if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
2958c2ecf20Sopenharmony_ci__printf(4, 5)
2968c2ecf20Sopenharmony_civoid __snd_printk(unsigned int level, const char *file, int line,
2978c2ecf20Sopenharmony_ci		  const char *format, ...);
2988c2ecf20Sopenharmony_ci#else
2998c2ecf20Sopenharmony_ci#define __snd_printk(level, file, line, format, ...) \
3008c2ecf20Sopenharmony_ci	printk(format, ##__VA_ARGS__)
3018c2ecf20Sopenharmony_ci#endif
3028c2ecf20Sopenharmony_ci
3038c2ecf20Sopenharmony_ci/**
3048c2ecf20Sopenharmony_ci * snd_printk - printk wrapper
3058c2ecf20Sopenharmony_ci * @fmt: format string
3068c2ecf20Sopenharmony_ci *
3078c2ecf20Sopenharmony_ci * Works like printk() but prints the file and the line of the caller
3088c2ecf20Sopenharmony_ci * when configured with CONFIG_SND_VERBOSE_PRINTK.
3098c2ecf20Sopenharmony_ci */
3108c2ecf20Sopenharmony_ci#define snd_printk(fmt, ...) \
3118c2ecf20Sopenharmony_ci	__snd_printk(0, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_DEBUG
3148c2ecf20Sopenharmony_ci/**
3158c2ecf20Sopenharmony_ci * snd_printd - debug printk
3168c2ecf20Sopenharmony_ci * @fmt: format string
3178c2ecf20Sopenharmony_ci *
3188c2ecf20Sopenharmony_ci * Works like snd_printk() for debugging purposes.
3198c2ecf20Sopenharmony_ci * Ignored when CONFIG_SND_DEBUG is not set.
3208c2ecf20Sopenharmony_ci */
3218c2ecf20Sopenharmony_ci#define snd_printd(fmt, ...) \
3228c2ecf20Sopenharmony_ci	__snd_printk(1, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
3238c2ecf20Sopenharmony_ci#define _snd_printd(level, fmt, ...) \
3248c2ecf20Sopenharmony_ci	__snd_printk(level, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
3258c2ecf20Sopenharmony_ci
3268c2ecf20Sopenharmony_ci/**
3278c2ecf20Sopenharmony_ci * snd_BUG - give a BUG warning message and stack trace
3288c2ecf20Sopenharmony_ci *
3298c2ecf20Sopenharmony_ci * Calls WARN() if CONFIG_SND_DEBUG is set.
3308c2ecf20Sopenharmony_ci * Ignored when CONFIG_SND_DEBUG is not set.
3318c2ecf20Sopenharmony_ci */
3328c2ecf20Sopenharmony_ci#define snd_BUG()		WARN(1, "BUG?\n")
3338c2ecf20Sopenharmony_ci
3348c2ecf20Sopenharmony_ci/**
3358c2ecf20Sopenharmony_ci * snd_printd_ratelimit - Suppress high rates of output when
3368c2ecf20Sopenharmony_ci * 			  CONFIG_SND_DEBUG is enabled.
3378c2ecf20Sopenharmony_ci */
3388c2ecf20Sopenharmony_ci#define snd_printd_ratelimit() printk_ratelimit()
3398c2ecf20Sopenharmony_ci
3408c2ecf20Sopenharmony_ci/**
3418c2ecf20Sopenharmony_ci * snd_BUG_ON - debugging check macro
3428c2ecf20Sopenharmony_ci * @cond: condition to evaluate
3438c2ecf20Sopenharmony_ci *
3448c2ecf20Sopenharmony_ci * Has the same behavior as WARN_ON when CONFIG_SND_DEBUG is set,
3458c2ecf20Sopenharmony_ci * otherwise just evaluates the conditional and returns the value.
3468c2ecf20Sopenharmony_ci */
3478c2ecf20Sopenharmony_ci#define snd_BUG_ON(cond)	WARN_ON((cond))
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_ci#else /* !CONFIG_SND_DEBUG */
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci__printf(1, 2)
3528c2ecf20Sopenharmony_cistatic inline void snd_printd(const char *format, ...) {}
3538c2ecf20Sopenharmony_ci__printf(2, 3)
3548c2ecf20Sopenharmony_cistatic inline void _snd_printd(int level, const char *format, ...) {}
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ci#define snd_BUG()			do { } while (0)
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci#define snd_BUG_ON(condition) ({ \
3598c2ecf20Sopenharmony_ci	int __ret_warn_on = !!(condition); \
3608c2ecf20Sopenharmony_ci	unlikely(__ret_warn_on); \
3618c2ecf20Sopenharmony_ci})
3628c2ecf20Sopenharmony_ci
3638c2ecf20Sopenharmony_cistatic inline bool snd_printd_ratelimit(void) { return false; }
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci#endif /* CONFIG_SND_DEBUG */
3668c2ecf20Sopenharmony_ci
3678c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_DEBUG_VERBOSE
3688c2ecf20Sopenharmony_ci/**
3698c2ecf20Sopenharmony_ci * snd_printdd - debug printk
3708c2ecf20Sopenharmony_ci * @format: format string
3718c2ecf20Sopenharmony_ci *
3728c2ecf20Sopenharmony_ci * Works like snd_printk() for debugging purposes.
3738c2ecf20Sopenharmony_ci * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
3748c2ecf20Sopenharmony_ci */
3758c2ecf20Sopenharmony_ci#define snd_printdd(format, ...) \
3768c2ecf20Sopenharmony_ci	__snd_printk(2, __FILE__, __LINE__, format, ##__VA_ARGS__)
3778c2ecf20Sopenharmony_ci#else
3788c2ecf20Sopenharmony_ci__printf(1, 2)
3798c2ecf20Sopenharmony_cistatic inline void snd_printdd(const char *format, ...) {}
3808c2ecf20Sopenharmony_ci#endif
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_ci#define SNDRV_OSS_VERSION         ((3<<16)|(8<<8)|(1<<4)|(0))	/* 3.8.1a */
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci/* for easier backward-porting */
3868c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_GAMEPORT)
3878c2ecf20Sopenharmony_ci#define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev))
3888c2ecf20Sopenharmony_ci#define gameport_set_port_data(gp,r) ((gp)->port_data = (r))
3898c2ecf20Sopenharmony_ci#define gameport_get_port_data(gp) (gp)->port_data
3908c2ecf20Sopenharmony_ci#endif
3918c2ecf20Sopenharmony_ci
3928c2ecf20Sopenharmony_ci/* PCI quirk list helper */
3938c2ecf20Sopenharmony_cistruct snd_pci_quirk {
3948c2ecf20Sopenharmony_ci	unsigned short subvendor;	/* PCI subvendor ID */
3958c2ecf20Sopenharmony_ci	unsigned short subdevice;	/* PCI subdevice ID */
3968c2ecf20Sopenharmony_ci	unsigned short subdevice_mask;	/* bitmask to match */
3978c2ecf20Sopenharmony_ci	int value;			/* value */
3988c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_DEBUG_VERBOSE
3998c2ecf20Sopenharmony_ci	const char *name;		/* name of the device (optional) */
4008c2ecf20Sopenharmony_ci#endif
4018c2ecf20Sopenharmony_ci};
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci#define _SND_PCI_QUIRK_ID_MASK(vend, mask, dev)	\
4048c2ecf20Sopenharmony_ci	.subvendor = (vend), .subdevice = (dev), .subdevice_mask = (mask)
4058c2ecf20Sopenharmony_ci#define _SND_PCI_QUIRK_ID(vend, dev) \
4068c2ecf20Sopenharmony_ci	_SND_PCI_QUIRK_ID_MASK(vend, 0xffff, dev)
4078c2ecf20Sopenharmony_ci#define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)}
4088c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_DEBUG_VERBOSE
4098c2ecf20Sopenharmony_ci#define SND_PCI_QUIRK(vend,dev,xname,val) \
4108c2ecf20Sopenharmony_ci	{_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)}
4118c2ecf20Sopenharmony_ci#define SND_PCI_QUIRK_VENDOR(vend, xname, val)			\
4128c2ecf20Sopenharmony_ci	{_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val), .name = (xname)}
4138c2ecf20Sopenharmony_ci#define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val)			\
4148c2ecf20Sopenharmony_ci	{_SND_PCI_QUIRK_ID_MASK(vend, mask, dev),			\
4158c2ecf20Sopenharmony_ci			.value = (val), .name = (xname)}
4168c2ecf20Sopenharmony_ci#define snd_pci_quirk_name(q)	((q)->name)
4178c2ecf20Sopenharmony_ci#else
4188c2ecf20Sopenharmony_ci#define SND_PCI_QUIRK(vend,dev,xname,val) \
4198c2ecf20Sopenharmony_ci	{_SND_PCI_QUIRK_ID(vend, dev), .value = (val)}
4208c2ecf20Sopenharmony_ci#define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val)			\
4218c2ecf20Sopenharmony_ci	{_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), .value = (val)}
4228c2ecf20Sopenharmony_ci#define SND_PCI_QUIRK_VENDOR(vend, xname, val)			\
4238c2ecf20Sopenharmony_ci	{_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val)}
4248c2ecf20Sopenharmony_ci#define snd_pci_quirk_name(q)	""
4258c2ecf20Sopenharmony_ci#endif
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_ci#ifdef CONFIG_PCI
4288c2ecf20Sopenharmony_ciconst struct snd_pci_quirk *
4298c2ecf20Sopenharmony_cisnd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list);
4308c2ecf20Sopenharmony_ci
4318c2ecf20Sopenharmony_ciconst struct snd_pci_quirk *
4328c2ecf20Sopenharmony_cisnd_pci_quirk_lookup_id(u16 vendor, u16 device,
4338c2ecf20Sopenharmony_ci			const struct snd_pci_quirk *list);
4348c2ecf20Sopenharmony_ci#else
4358c2ecf20Sopenharmony_cistatic inline const struct snd_pci_quirk *
4368c2ecf20Sopenharmony_cisnd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list)
4378c2ecf20Sopenharmony_ci{
4388c2ecf20Sopenharmony_ci	return NULL;
4398c2ecf20Sopenharmony_ci}
4408c2ecf20Sopenharmony_ci
4418c2ecf20Sopenharmony_cistatic inline const struct snd_pci_quirk *
4428c2ecf20Sopenharmony_cisnd_pci_quirk_lookup_id(u16 vendor, u16 device,
4438c2ecf20Sopenharmony_ci			const struct snd_pci_quirk *list)
4448c2ecf20Sopenharmony_ci{
4458c2ecf20Sopenharmony_ci	return NULL;
4468c2ecf20Sopenharmony_ci}
4478c2ecf20Sopenharmony_ci#endif
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci/* async signal helpers */
4508c2ecf20Sopenharmony_cistruct snd_fasync;
4518c2ecf20Sopenharmony_ci
4528c2ecf20Sopenharmony_ciint snd_fasync_helper(int fd, struct file *file, int on,
4538c2ecf20Sopenharmony_ci		      struct snd_fasync **fasyncp);
4548c2ecf20Sopenharmony_civoid snd_kill_fasync(struct snd_fasync *fasync, int signal, int poll);
4558c2ecf20Sopenharmony_civoid snd_fasync_free(struct snd_fasync *fasync);
4568c2ecf20Sopenharmony_ci
4578c2ecf20Sopenharmony_ci#endif /* __SOUND_CORE_H */
458