0001
0002 #ifndef __SOUND_CORE_H
0003 #define __SOUND_CORE_H
0004
0005
0006
0007
0008
0009
0010 #include <linux/device.h>
0011 #include <linux/sched.h> /* wake_up() */
0012 #include <linux/mutex.h> /* struct mutex */
0013 #include <linux/rwsem.h> /* struct rw_semaphore */
0014 #include <linux/pm.h> /* pm_message_t */
0015 #include <linux/stringify.h>
0016 #include <linux/printk.h>
0017 #include <linux/xarray.h>
0018
0019
0020 #ifdef CONFIG_SND_DYNAMIC_MINORS
0021 #define SNDRV_CARDS CONFIG_SND_MAX_CARDS
0022 #else
0023 #define SNDRV_CARDS 8
0024 #endif
0025
0026 #define CONFIG_SND_MAJOR 116
0027
0028
0029 struct pci_dev;
0030 struct module;
0031 struct completion;
0032
0033
0034
0035
0036
0037
0038 enum snd_device_type {
0039 SNDRV_DEV_LOWLEVEL,
0040 SNDRV_DEV_INFO,
0041 SNDRV_DEV_BUS,
0042 SNDRV_DEV_CODEC,
0043 SNDRV_DEV_PCM,
0044 SNDRV_DEV_COMPRESS,
0045 SNDRV_DEV_RAWMIDI,
0046 SNDRV_DEV_TIMER,
0047 SNDRV_DEV_SEQUENCER,
0048 SNDRV_DEV_HWDEP,
0049 SNDRV_DEV_JACK,
0050 SNDRV_DEV_CONTROL,
0051 };
0052
0053 enum snd_device_state {
0054 SNDRV_DEV_BUILD,
0055 SNDRV_DEV_REGISTERED,
0056 SNDRV_DEV_DISCONNECTED,
0057 };
0058
0059 struct snd_device;
0060
0061 struct snd_device_ops {
0062 int (*dev_free)(struct snd_device *dev);
0063 int (*dev_register)(struct snd_device *dev);
0064 int (*dev_disconnect)(struct snd_device *dev);
0065 };
0066
0067 struct snd_device {
0068 struct list_head list;
0069 struct snd_card *card;
0070 enum snd_device_state state;
0071 enum snd_device_type type;
0072 void *device_data;
0073 const struct snd_device_ops *ops;
0074 };
0075
0076 #define snd_device(n) list_entry(n, struct snd_device, list)
0077
0078
0079
0080 struct snd_card {
0081 int number;
0082
0083
0084 char id[16];
0085 char driver[16];
0086 char shortname[32];
0087 char longname[80];
0088 char irq_descr[32];
0089 char mixername[80];
0090 char components[128];
0091
0092 struct module *module;
0093
0094 void *private_data;
0095 void (*private_free) (struct snd_card *card);
0096
0097 struct list_head devices;
0098
0099 struct device ctl_dev;
0100 unsigned int last_numid;
0101 struct rw_semaphore controls_rwsem;
0102 rwlock_t ctl_files_rwlock;
0103 int controls_count;
0104 size_t user_ctl_alloc_size;
0105 struct list_head controls;
0106 struct list_head ctl_files;
0107 #ifdef CONFIG_SND_CTL_FAST_LOOKUP
0108 struct xarray ctl_numids;
0109 struct xarray ctl_hash;
0110 bool ctl_hash_collision;
0111 #endif
0112
0113 struct snd_info_entry *proc_root;
0114 struct proc_dir_entry *proc_root_link;
0115
0116 struct list_head files_list;
0117 struct snd_shutdown_f_ops *s_f_ops;
0118
0119 spinlock_t files_lock;
0120 int shutdown;
0121 struct completion *release_completion;
0122 struct device *dev;
0123 struct device card_dev;
0124 const struct attribute_group *dev_groups[4];
0125 bool registered;
0126 bool managed;
0127 bool releasing;
0128 int sync_irq;
0129 wait_queue_head_t remove_sleep;
0130
0131 size_t total_pcm_alloc_bytes;
0132 struct mutex memory_mutex;
0133 #ifdef CONFIG_SND_DEBUG
0134 struct dentry *debugfs_root;
0135 #endif
0136
0137 #ifdef CONFIG_PM
0138 unsigned int power_state;
0139 atomic_t power_ref;
0140 wait_queue_head_t power_sleep;
0141 wait_queue_head_t power_ref_sleep;
0142 #endif
0143
0144 #if IS_ENABLED(CONFIG_SND_MIXER_OSS)
0145 struct snd_mixer_oss *mixer_oss;
0146 int mixer_oss_change_count;
0147 #endif
0148 };
0149
0150 #define dev_to_snd_card(p) container_of(p, struct snd_card, card_dev)
0151
0152 #ifdef CONFIG_PM
0153 static inline unsigned int snd_power_get_state(struct snd_card *card)
0154 {
0155 return READ_ONCE(card->power_state);
0156 }
0157
0158 static inline void snd_power_change_state(struct snd_card *card, unsigned int state)
0159 {
0160 WRITE_ONCE(card->power_state, state);
0161 wake_up(&card->power_sleep);
0162 }
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172 static inline void snd_power_ref(struct snd_card *card)
0173 {
0174 atomic_inc(&card->power_ref);
0175 }
0176
0177
0178
0179
0180
0181 static inline void snd_power_unref(struct snd_card *card)
0182 {
0183 if (atomic_dec_and_test(&card->power_ref))
0184 wake_up(&card->power_ref_sleep);
0185 }
0186
0187
0188
0189
0190
0191
0192
0193
0194 static inline void snd_power_sync_ref(struct snd_card *card)
0195 {
0196 wait_event(card->power_ref_sleep, !atomic_read(&card->power_ref));
0197 }
0198
0199
0200 int snd_power_wait(struct snd_card *card);
0201 int snd_power_ref_and_wait(struct snd_card *card);
0202
0203 #else
0204
0205 static inline int snd_power_wait(struct snd_card *card) { return 0; }
0206 static inline void snd_power_ref(struct snd_card *card) {}
0207 static inline void snd_power_unref(struct snd_card *card) {}
0208 static inline int snd_power_ref_and_wait(struct snd_card *card) { return 0; }
0209 static inline void snd_power_sync_ref(struct snd_card *card) {}
0210 #define snd_power_get_state(card) ({ (void)(card); SNDRV_CTL_POWER_D0; })
0211 #define snd_power_change_state(card, state) do { (void)(card); } while (0)
0212
0213 #endif
0214
0215 struct snd_minor {
0216 int type;
0217 int card;
0218 int device;
0219 const struct file_operations *f_ops;
0220 void *private_data;
0221 struct device *dev;
0222 struct snd_card *card_ptr;
0223 };
0224
0225
0226 static inline struct device *snd_card_get_device_link(struct snd_card *card)
0227 {
0228 return card ? &card->card_dev : NULL;
0229 }
0230
0231
0232
0233 extern int snd_major;
0234 extern int snd_ecards_limit;
0235 extern struct class *sound_class;
0236 #ifdef CONFIG_SND_DEBUG
0237 extern struct dentry *sound_debugfs_root;
0238 #endif
0239
0240 void snd_request_card(int card);
0241
0242 void snd_device_initialize(struct device *dev, struct snd_card *card);
0243
0244 int snd_register_device(int type, struct snd_card *card, int dev,
0245 const struct file_operations *f_ops,
0246 void *private_data, struct device *device);
0247 int snd_unregister_device(struct device *dev);
0248 void *snd_lookup_minor_data(unsigned int minor, int type);
0249
0250 #ifdef CONFIG_SND_OSSEMUL
0251 int snd_register_oss_device(int type, struct snd_card *card, int dev,
0252 const struct file_operations *f_ops, void *private_data);
0253 int snd_unregister_oss_device(int type, struct snd_card *card, int dev);
0254 void *snd_lookup_oss_minor_data(unsigned int minor, int type);
0255 #endif
0256
0257 int snd_minor_info_init(void);
0258
0259
0260
0261 #ifdef CONFIG_SND_OSSEMUL
0262 int snd_minor_info_oss_init(void);
0263 #else
0264 static inline int snd_minor_info_oss_init(void) { return 0; }
0265 #endif
0266
0267
0268
0269 int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
0270 int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
0271
0272
0273
0274 int snd_card_locked(int card);
0275 #if IS_ENABLED(CONFIG_SND_MIXER_OSS)
0276 #define SND_MIXER_OSS_NOTIFY_REGISTER 0
0277 #define SND_MIXER_OSS_NOTIFY_DISCONNECT 1
0278 #define SND_MIXER_OSS_NOTIFY_FREE 2
0279 extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
0280 #endif
0281
0282 int snd_card_new(struct device *parent, int idx, const char *xid,
0283 struct module *module, int extra_size,
0284 struct snd_card **card_ret);
0285 int snd_devm_card_new(struct device *parent, int idx, const char *xid,
0286 struct module *module, size_t extra_size,
0287 struct snd_card **card_ret);
0288
0289 int snd_card_disconnect(struct snd_card *card);
0290 void snd_card_disconnect_sync(struct snd_card *card);
0291 int snd_card_free(struct snd_card *card);
0292 int snd_card_free_when_closed(struct snd_card *card);
0293 int snd_card_free_on_error(struct device *dev, int ret);
0294 void snd_card_set_id(struct snd_card *card, const char *id);
0295 int snd_card_register(struct snd_card *card);
0296 int snd_card_info_init(void);
0297 int snd_card_add_dev_attr(struct snd_card *card,
0298 const struct attribute_group *group);
0299 int snd_component_add(struct snd_card *card, const char *component);
0300 int snd_card_file_add(struct snd_card *card, struct file *file);
0301 int snd_card_file_remove(struct snd_card *card, struct file *file);
0302
0303 struct snd_card *snd_card_ref(int card);
0304
0305
0306
0307
0308
0309
0310
0311
0312 static inline void snd_card_unref(struct snd_card *card)
0313 {
0314 put_device(&card->card_dev);
0315 }
0316
0317 #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
0318
0319
0320
0321 int snd_device_new(struct snd_card *card, enum snd_device_type type,
0322 void *device_data, const struct snd_device_ops *ops);
0323 int snd_device_register(struct snd_card *card, void *device_data);
0324 int snd_device_register_all(struct snd_card *card);
0325 void snd_device_disconnect(struct snd_card *card, void *device_data);
0326 void snd_device_disconnect_all(struct snd_card *card);
0327 void snd_device_free(struct snd_card *card, void *device_data);
0328 void snd_device_free_all(struct snd_card *card);
0329 int snd_device_get_state(struct snd_card *card, void *device_data);
0330
0331
0332
0333 #ifdef CONFIG_ISA_DMA_API
0334 #define DMA_MODE_NO_ENABLE 0x0100
0335
0336 void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode);
0337 void snd_dma_disable(unsigned long dma);
0338 unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
0339 int snd_devm_request_dma(struct device *dev, int dma, const char *name);
0340 #endif
0341
0342
0343 struct resource;
0344 void release_and_free_resource(struct resource *res);
0345
0346
0347
0348
0349 enum {
0350 SND_PR_ALWAYS,
0351 SND_PR_DEBUG,
0352 SND_PR_VERBOSE,
0353 };
0354
0355 #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
0356 __printf(4, 5)
0357 void __snd_printk(unsigned int level, const char *file, int line,
0358 const char *format, ...);
0359 #else
0360 #define __snd_printk(level, file, line, format, ...) \
0361 printk(format, ##__VA_ARGS__)
0362 #endif
0363
0364
0365
0366
0367
0368
0369
0370
0371 #define snd_printk(fmt, ...) \
0372 __snd_printk(0, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
0373
0374 #ifdef CONFIG_SND_DEBUG
0375
0376
0377
0378
0379
0380
0381
0382 #define snd_printd(fmt, ...) \
0383 __snd_printk(1, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
0384 #define _snd_printd(level, fmt, ...) \
0385 __snd_printk(level, __FILE__, __LINE__, fmt, ##__VA_ARGS__)
0386
0387
0388
0389
0390
0391
0392
0393 #define snd_BUG() WARN(1, "BUG?\n")
0394
0395
0396
0397
0398
0399 #define snd_printd_ratelimit() printk_ratelimit()
0400
0401
0402
0403
0404
0405
0406
0407
0408 #define snd_BUG_ON(cond) WARN_ON((cond))
0409
0410 #else
0411
0412 __printf(1, 2)
0413 static inline void snd_printd(const char *format, ...) {}
0414 __printf(2, 3)
0415 static inline void _snd_printd(int level, const char *format, ...) {}
0416
0417 #define snd_BUG() do { } while (0)
0418
0419 #define snd_BUG_ON(condition) ({ \
0420 int __ret_warn_on = !!(condition); \
0421 unlikely(__ret_warn_on); \
0422 })
0423
0424 static inline bool snd_printd_ratelimit(void) { return false; }
0425
0426 #endif
0427
0428 #ifdef CONFIG_SND_DEBUG_VERBOSE
0429
0430
0431
0432
0433
0434
0435
0436 #define snd_printdd(format, ...) \
0437 __snd_printk(2, __FILE__, __LINE__, format, ##__VA_ARGS__)
0438 #else
0439 __printf(1, 2)
0440 static inline void snd_printdd(const char *format, ...) {}
0441 #endif
0442
0443
0444 #define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0))
0445
0446
0447 #if IS_ENABLED(CONFIG_GAMEPORT)
0448 #define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev))
0449 #define gameport_set_port_data(gp,r) ((gp)->port_data = (r))
0450 #define gameport_get_port_data(gp) (gp)->port_data
0451 #endif
0452
0453
0454 struct snd_pci_quirk {
0455 unsigned short subvendor;
0456 unsigned short subdevice;
0457 unsigned short subdevice_mask;
0458 int value;
0459 #ifdef CONFIG_SND_DEBUG_VERBOSE
0460 const char *name;
0461 #endif
0462 };
0463
0464 #define _SND_PCI_QUIRK_ID_MASK(vend, mask, dev) \
0465 .subvendor = (vend), .subdevice = (dev), .subdevice_mask = (mask)
0466 #define _SND_PCI_QUIRK_ID(vend, dev) \
0467 _SND_PCI_QUIRK_ID_MASK(vend, 0xffff, dev)
0468 #define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)}
0469 #ifdef CONFIG_SND_DEBUG_VERBOSE
0470 #define SND_PCI_QUIRK(vend,dev,xname,val) \
0471 {_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)}
0472 #define SND_PCI_QUIRK_VENDOR(vend, xname, val) \
0473 {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val), .name = (xname)}
0474 #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \
0475 {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), \
0476 .value = (val), .name = (xname)}
0477 #define snd_pci_quirk_name(q) ((q)->name)
0478 #else
0479 #define SND_PCI_QUIRK(vend,dev,xname,val) \
0480 {_SND_PCI_QUIRK_ID(vend, dev), .value = (val)}
0481 #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \
0482 {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), .value = (val)}
0483 #define SND_PCI_QUIRK_VENDOR(vend, xname, val) \
0484 {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val)}
0485 #define snd_pci_quirk_name(q) ""
0486 #endif
0487
0488 #ifdef CONFIG_PCI
0489 const struct snd_pci_quirk *
0490 snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list);
0491
0492 const struct snd_pci_quirk *
0493 snd_pci_quirk_lookup_id(u16 vendor, u16 device,
0494 const struct snd_pci_quirk *list);
0495 #else
0496 static inline const struct snd_pci_quirk *
0497 snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list)
0498 {
0499 return NULL;
0500 }
0501
0502 static inline const struct snd_pci_quirk *
0503 snd_pci_quirk_lookup_id(u16 vendor, u16 device,
0504 const struct snd_pci_quirk *list)
0505 {
0506 return NULL;
0507 }
0508 #endif
0509
0510
0511 struct snd_fasync;
0512
0513 int snd_fasync_helper(int fd, struct file *file, int on,
0514 struct snd_fasync **fasyncp);
0515 void snd_kill_fasync(struct snd_fasync *fasync, int signal, int poll);
0516 void snd_fasync_free(struct snd_fasync *fasync);
0517
0518 #endif