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