1#ifndef __SOUND_CORE_H
2#define __SOUND_CORE_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include <linux/module.h>
26#include <linux/sched.h>
27#include <linux/mutex.h>
28#include <linux/rwsem.h>
29#include <linux/pm.h>
30#include <linux/device.h>
31
32
33#ifdef CONFIG_SND_DYNAMIC_MINORS
34#define SNDRV_CARDS 32
35#else
36#define SNDRV_CARDS 8
37#endif
38
39#define CONFIG_SND_MAJOR 116
40
41
42#ifdef CONFIG_PCI
43struct pci_dev;
44#endif
45#ifdef CONFIG_SBUS
46struct sbus_dev;
47#endif
48
49
50
51#define SNDRV_DEV_TYPE_RANGE_SIZE 0x1000
52
53typedef int __bitwise snd_device_type_t;
54#define SNDRV_DEV_TOPLEVEL ((__force snd_device_type_t) 0)
55#define SNDRV_DEV_CONTROL ((__force snd_device_type_t) 1)
56#define SNDRV_DEV_LOWLEVEL_PRE ((__force snd_device_type_t) 2)
57#define SNDRV_DEV_LOWLEVEL_NORMAL ((__force snd_device_type_t) 0x1000)
58#define SNDRV_DEV_PCM ((__force snd_device_type_t) 0x1001)
59#define SNDRV_DEV_RAWMIDI ((__force snd_device_type_t) 0x1002)
60#define SNDRV_DEV_TIMER ((__force snd_device_type_t) 0x1003)
61#define SNDRV_DEV_SEQUENCER ((__force snd_device_type_t) 0x1004)
62#define SNDRV_DEV_HWDEP ((__force snd_device_type_t) 0x1005)
63#define SNDRV_DEV_INFO ((__force snd_device_type_t) 0x1006)
64#define SNDRV_DEV_BUS ((__force snd_device_type_t) 0x1007)
65#define SNDRV_DEV_CODEC ((__force snd_device_type_t) 0x1008)
66#define SNDRV_DEV_LOWLEVEL ((__force snd_device_type_t) 0x2000)
67
68typedef int __bitwise snd_device_state_t;
69#define SNDRV_DEV_BUILD ((__force snd_device_state_t) 0)
70#define SNDRV_DEV_REGISTERED ((__force snd_device_state_t) 1)
71#define SNDRV_DEV_DISCONNECTED ((__force snd_device_state_t) 2)
72
73typedef int __bitwise snd_device_cmd_t;
74#define SNDRV_DEV_CMD_PRE ((__force snd_device_cmd_t) 0)
75#define SNDRV_DEV_CMD_NORMAL ((__force snd_device_cmd_t) 1)
76#define SNDRV_DEV_CMD_POST ((__force snd_device_cmd_t) 2)
77
78struct snd_device;
79
80struct snd_device_ops {
81 int (*dev_free)(struct snd_device *dev);
82 int (*dev_register)(struct snd_device *dev);
83 int (*dev_disconnect)(struct snd_device *dev);
84};
85
86struct snd_device {
87 struct list_head list;
88 struct snd_card *card;
89 snd_device_state_t state;
90 snd_device_type_t type;
91 void *device_data;
92 struct snd_device_ops *ops;
93};
94
95#define snd_device(n) list_entry(n, struct snd_device, list)
96
97
98
99struct snd_monitor_file {
100 struct file *file;
101 struct snd_monitor_file *next;
102 const struct file_operations *disconnected_f_op;
103 struct list_head shutdown_list;
104};
105
106
107
108struct snd_card {
109 int number;
110
111
112 char id[16];
113 char driver[16];
114 char shortname[32];
115 char longname[80];
116 char mixername[80];
117 char components[80];
118
119 struct module *module;
120
121 void *private_data;
122 void (*private_free) (struct snd_card *card);
123
124 struct list_head devices;
125
126 unsigned int last_numid;
127 struct rw_semaphore controls_rwsem;
128 rwlock_t ctl_files_rwlock;
129 int controls_count;
130 int user_ctl_count;
131 struct list_head controls;
132 struct list_head ctl_files;
133
134 struct snd_info_entry *proc_root;
135 struct snd_info_entry *proc_id;
136 struct proc_dir_entry *proc_root_link;
137
138 struct snd_monitor_file *files;
139 struct snd_shutdown_f_ops *s_f_ops;
140
141 spinlock_t files_lock;
142 int shutdown;
143 int free_on_last_close;
144 wait_queue_head_t shutdown_sleep;
145 struct device *dev;
146#ifndef CONFIG_SYSFS_DEPRECATED
147 struct device *card_dev;
148#endif
149
150#ifdef CONFIG_PM
151 unsigned int power_state;
152 struct mutex power_lock;
153 wait_queue_head_t power_sleep;
154#endif
155
156#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
157 struct snd_mixer_oss *mixer_oss;
158 int mixer_oss_change_count;
159#endif
160};
161
162#ifdef CONFIG_PM
163static inline void snd_power_lock(struct snd_card *card)
164{
165 mutex_lock(&card->power_lock);
166}
167
168static inline void snd_power_unlock(struct snd_card *card)
169{
170 mutex_unlock(&card->power_lock);
171}
172
173static inline unsigned int snd_power_get_state(struct snd_card *card)
174{
175 return card->power_state;
176}
177
178static inline void snd_power_change_state(struct snd_card *card, unsigned int state)
179{
180 card->power_state = state;
181 wake_up(&card->power_sleep);
182}
183
184
185int snd_power_wait(struct snd_card *card, unsigned int power_state);
186
187#else
188
189#define snd_power_lock(card) do { (void)(card); } while (0)
190#define snd_power_unlock(card) do { (void)(card); } while (0)
191static inline int snd_power_wait(struct snd_card *card, unsigned int state) { return 0; }
192#define snd_power_get_state(card) SNDRV_CTL_POWER_D0
193#define snd_power_change_state(card, state) do { (void)(card); } while (0)
194
195#endif
196
197struct snd_minor {
198 int type;
199 int card;
200 int device;
201 const struct file_operations *f_ops;
202 void *private_data;
203 struct device *dev;
204};
205
206
207static inline struct device *snd_card_get_device_link(struct snd_card *card)
208{
209#ifdef CONFIG_SYSFS_DEPRECATED
210 return card ? card->dev : NULL;
211#else
212 return card ? card->card_dev : NULL;
213#endif
214}
215
216
217
218extern int snd_major;
219extern int snd_ecards_limit;
220extern struct class *sound_class;
221
222void snd_request_card(int card);
223
224int snd_register_device_for_dev(int type, struct snd_card *card,
225 int dev,
226 const struct file_operations *f_ops,
227 void *private_data,
228 const char *name,
229 struct device *device);
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248static inline int snd_register_device(int type, struct snd_card *card, int dev,
249 const struct file_operations *f_ops,
250 void *private_data,
251 const char *name)
252{
253 return snd_register_device_for_dev(type, card, dev, f_ops,
254 private_data, name,
255 snd_card_get_device_link(card));
256}
257
258int snd_unregister_device(int type, struct snd_card *card, int dev);
259void *snd_lookup_minor_data(unsigned int minor, int type);
260int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev,
261 struct device_attribute *attr);
262
263#ifdef CONFIG_SND_OSSEMUL
264int snd_register_oss_device(int type, struct snd_card *card, int dev,
265 const struct file_operations *f_ops, void *private_data,
266 const char *name);
267int snd_unregister_oss_device(int type, struct snd_card *card, int dev);
268void *snd_lookup_oss_minor_data(unsigned int minor, int type);
269#endif
270
271int snd_minor_info_init(void);
272int snd_minor_info_done(void);
273
274
275
276#ifdef CONFIG_SND_OSSEMUL
277int snd_minor_info_oss_init(void);
278int snd_minor_info_oss_done(void);
279#else
280static inline int snd_minor_info_oss_init(void) { return 0; }
281static inline int snd_minor_info_oss_done(void) { return 0; }
282#endif
283
284
285
286int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
287int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
288
289
290
291extern struct snd_card *snd_cards[SNDRV_CARDS];
292int snd_card_locked(int card);
293#if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
294#define SND_MIXER_OSS_NOTIFY_REGISTER 0
295#define SND_MIXER_OSS_NOTIFY_DISCONNECT 1
296#define SND_MIXER_OSS_NOTIFY_FREE 2
297extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
298#endif
299
300struct snd_card *snd_card_new(int idx, const char *id,
301 struct module *module, int extra_size);
302int snd_card_disconnect(struct snd_card *card);
303int snd_card_free(struct snd_card *card);
304int snd_card_free_when_closed(struct snd_card *card);
305int snd_card_register(struct snd_card *card);
306int snd_card_info_init(void);
307int snd_card_info_done(void);
308int snd_component_add(struct snd_card *card, const char *component);
309int snd_card_file_add(struct snd_card *card, struct file *file);
310int snd_card_file_remove(struct snd_card *card, struct file *file);
311
312#ifndef snd_card_set_dev
313#define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
314#endif
315
316
317
318int snd_device_new(struct snd_card *card, snd_device_type_t type,
319 void *device_data, struct snd_device_ops *ops);
320int snd_device_register(struct snd_card *card, void *device_data);
321int snd_device_register_all(struct snd_card *card);
322int snd_device_disconnect(struct snd_card *card, void *device_data);
323int snd_device_disconnect_all(struct snd_card *card);
324int snd_device_free(struct snd_card *card, void *device_data);
325int snd_device_free_all(struct snd_card *card, snd_device_cmd_t cmd);
326
327
328
329#ifdef CONFIG_ISA_DMA_API
330#define DMA_MODE_NO_ENABLE 0x0100
331
332void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode);
333void snd_dma_disable(unsigned long dma);
334unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
335#endif
336
337
338struct resource;
339void release_and_free_resource(struct resource *res);
340
341#ifdef CONFIG_SND_VERBOSE_PRINTK
342void snd_verbose_printk(const char *file, int line, const char *format, ...)
343 __attribute__ ((format (printf, 3, 4)));
344#endif
345#if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK)
346void snd_verbose_printd(const char *file, int line, const char *format, ...)
347 __attribute__ ((format (printf, 3, 4)));
348#endif
349
350
351
352#ifdef CONFIG_SND_VERBOSE_PRINTK
353
354
355
356
357
358
359
360#define snd_printk(fmt, args...) \
361 snd_verbose_printk(__FILE__, __LINE__, fmt ,##args)
362#else
363#define snd_printk(fmt, args...) \
364 printk(fmt ,##args)
365#endif
366
367#ifdef CONFIG_SND_DEBUG
368
369#define __ASTRING__(x) #x
370
371#ifdef CONFIG_SND_VERBOSE_PRINTK
372
373
374
375
376
377
378
379#define snd_printd(fmt, args...) \
380 snd_verbose_printd(__FILE__, __LINE__, fmt ,##args)
381#else
382#define snd_printd(fmt, args...) \
383 printk(fmt ,##args)
384#endif
385
386
387
388
389
390
391
392
393
394#define snd_assert(expr, args...) do { \
395 if (unlikely(!(expr))) { \
396 snd_printk(KERN_ERR "BUG? (%s)\n", __ASTRING__(expr)); \
397 dump_stack(); \
398 args; \
399 } \
400} while (0)
401
402#define snd_BUG() do { \
403 snd_printk(KERN_ERR "BUG?\n"); \
404 dump_stack(); \
405} while (0)
406
407#else
408
409#define snd_printd(fmt, args...)
410#define snd_assert(expr, args...) (void)(expr)
411#define snd_BUG()
412
413#endif
414
415#ifdef CONFIG_SND_DEBUG_VERBOSE
416
417
418
419
420
421
422
423#define snd_printdd(format, args...) snd_printk(format, ##args)
424#else
425#define snd_printdd(format, args...)
426#endif
427
428
429#define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0))
430
431
432#if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE)
433#ifndef gameport_set_dev_parent
434#define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev))
435#define gameport_set_port_data(gp,r) ((gp)->port_data = (r))
436#define gameport_get_port_data(gp) (gp)->port_data
437#endif
438#endif
439
440
441struct snd_pci_quirk {
442 unsigned short subvendor;
443 unsigned short subdevice;
444 int value;
445#ifdef CONFIG_SND_DEBUG_VERBOSE
446 const char *name;
447#endif
448};
449
450#define _SND_PCI_QUIRK_ID(vend,dev) \
451 .subvendor = (vend), .subdevice = (dev)
452#define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)}
453#ifdef CONFIG_SND_DEBUG_VERBOSE
454#define SND_PCI_QUIRK(vend,dev,xname,val) \
455 {_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)}
456#else
457#define SND_PCI_QUIRK(vend,dev,xname,val) \
458 {_SND_PCI_QUIRK_ID(vend, dev), .value = (val)}
459#endif
460
461const struct snd_pci_quirk *
462snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list);
463
464
465#endif
466