core.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461
  1. #ifndef __SOUND_CORE_H
  2. #define __SOUND_CORE_H
  3. /*
  4. * Main header file for the ALSA driver
  5. * Copyright (c) 1994-2001 by Jaroslav Kysela <perex@perex.cz>
  6. *
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. *
  22. */
  23. #include <linux/device.h>
  24. #include <linux/sched.h> /* wake_up() */
  25. #include <linux/mutex.h> /* struct mutex */
  26. #include <linux/rwsem.h> /* struct rw_semaphore */
  27. #include <linux/pm.h> /* pm_message_t */
  28. #include <linux/stringify.h>
  29. #include <linux/printk.h>
  30. /* number of supported soundcards */
  31. #ifdef CONFIG_SND_DYNAMIC_MINORS
  32. #define SNDRV_CARDS CONFIG_SND_MAX_CARDS
  33. #else
  34. #define SNDRV_CARDS 8 /* don't change - minor numbers */
  35. #endif
  36. #define CONFIG_SND_MAJOR 116 /* standard configuration */
  37. /* forward declarations */
  38. struct pci_dev;
  39. struct module;
  40. struct completion;
  41. /* device allocation stuff */
  42. /* type of the object used in snd_device_*()
  43. * this also defines the calling order
  44. */
  45. enum snd_device_type {
  46. SNDRV_DEV_LOWLEVEL,
  47. SNDRV_DEV_CONTROL,
  48. SNDRV_DEV_INFO,
  49. SNDRV_DEV_BUS,
  50. SNDRV_DEV_CODEC,
  51. SNDRV_DEV_PCM,
  52. SNDRV_DEV_COMPRESS,
  53. SNDRV_DEV_RAWMIDI,
  54. SNDRV_DEV_TIMER,
  55. SNDRV_DEV_SEQUENCER,
  56. SNDRV_DEV_HWDEP,
  57. SNDRV_DEV_JACK,
  58. };
  59. enum snd_device_state {
  60. SNDRV_DEV_BUILD,
  61. SNDRV_DEV_REGISTERED,
  62. SNDRV_DEV_DISCONNECTED,
  63. };
  64. struct snd_device;
  65. struct snd_device_ops {
  66. int (*dev_free)(struct snd_device *dev);
  67. int (*dev_register)(struct snd_device *dev);
  68. int (*dev_disconnect)(struct snd_device *dev);
  69. };
  70. struct snd_device {
  71. struct list_head list; /* list of registered devices */
  72. struct snd_card *card; /* card which holds this device */
  73. enum snd_device_state state; /* state of the device */
  74. enum snd_device_type type; /* device type */
  75. void *device_data; /* device structure */
  76. struct snd_device_ops *ops; /* operations */
  77. };
  78. #define snd_device(n) list_entry(n, struct snd_device, list)
  79. /* main structure for soundcard */
  80. struct snd_card {
  81. int number; /* number of soundcard (index to
  82. snd_cards) */
  83. char id[16]; /* id string of this card */
  84. char driver[16]; /* driver name */
  85. char shortname[32]; /* short name of this soundcard */
  86. char longname[80]; /* name of this soundcard */
  87. char irq_descr[32]; /* Interrupt description */
  88. char mixername[80]; /* mixer name */
  89. char components[128]; /* card components delimited with
  90. space */
  91. struct module *module; /* top-level module */
  92. void *private_data; /* private data for soundcard */
  93. void (*private_free) (struct snd_card *card); /* callback for freeing of
  94. private data */
  95. struct list_head devices; /* devices */
  96. struct device ctl_dev; /* control device */
  97. unsigned int last_numid; /* last used numeric ID */
  98. struct rw_semaphore controls_rwsem; /* controls list lock */
  99. rwlock_t ctl_files_rwlock; /* ctl_files list lock */
  100. int controls_count; /* count of all controls */
  101. int user_ctl_count; /* count of all user controls */
  102. struct list_head controls; /* all controls for this card */
  103. struct list_head ctl_files; /* active control files */
  104. struct mutex user_ctl_lock; /* protects user controls against
  105. concurrent access */
  106. struct snd_info_entry *proc_root; /* root for soundcard specific files */
  107. struct snd_info_entry *proc_id; /* the card id */
  108. struct proc_dir_entry *proc_root_link; /* number link to real id */
  109. struct list_head files_list; /* all files associated to this card */
  110. struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown
  111. state */
  112. spinlock_t files_lock; /* lock the files for this card */
  113. int shutdown; /* this card is going down */
  114. struct completion *release_completion;
  115. struct device *dev; /* device assigned to this card */
  116. struct device card_dev; /* cardX object for sysfs */
  117. const struct attribute_group *dev_groups[4]; /* assigned sysfs attr */
  118. bool registered; /* card_dev is registered? */
  119. #ifdef CONFIG_PM
  120. unsigned int power_state; /* power state */
  121. struct mutex power_lock; /* power lock */
  122. wait_queue_head_t power_sleep;
  123. #endif
  124. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
  125. struct snd_mixer_oss *mixer_oss;
  126. int mixer_oss_change_count;
  127. #endif
  128. };
  129. #define dev_to_snd_card(p) container_of(p, struct snd_card, card_dev)
  130. #ifdef CONFIG_PM
  131. static inline void snd_power_lock(struct snd_card *card)
  132. {
  133. mutex_lock(&card->power_lock);
  134. }
  135. static inline void snd_power_unlock(struct snd_card *card)
  136. {
  137. mutex_unlock(&card->power_lock);
  138. }
  139. static inline unsigned int snd_power_get_state(struct snd_card *card)
  140. {
  141. return card->power_state;
  142. }
  143. static inline void snd_power_change_state(struct snd_card *card, unsigned int state)
  144. {
  145. card->power_state = state;
  146. wake_up(&card->power_sleep);
  147. }
  148. /* init.c */
  149. int snd_power_wait(struct snd_card *card, unsigned int power_state);
  150. #else /* ! CONFIG_PM */
  151. #define snd_power_lock(card) do { (void)(card); } while (0)
  152. #define snd_power_unlock(card) do { (void)(card); } while (0)
  153. static inline int snd_power_wait(struct snd_card *card, unsigned int state) { return 0; }
  154. #define snd_power_get_state(card) ({ (void)(card); SNDRV_CTL_POWER_D0; })
  155. #define snd_power_change_state(card, state) do { (void)(card); } while (0)
  156. #endif /* CONFIG_PM */
  157. struct snd_minor {
  158. int type; /* SNDRV_DEVICE_TYPE_XXX */
  159. int card; /* card number */
  160. int device; /* device number */
  161. const struct file_operations *f_ops; /* file operations */
  162. void *private_data; /* private data for f_ops->open */
  163. struct device *dev; /* device for sysfs */
  164. struct snd_card *card_ptr; /* assigned card instance */
  165. };
  166. /* return a device pointer linked to each sound device as a parent */
  167. static inline struct device *snd_card_get_device_link(struct snd_card *card)
  168. {
  169. return card ? &card->card_dev : NULL;
  170. }
  171. /* sound.c */
  172. extern int snd_major;
  173. extern int snd_ecards_limit;
  174. extern struct class *sound_class;
  175. void snd_request_card(int card);
  176. void snd_device_initialize(struct device *dev, struct snd_card *card);
  177. int snd_register_device(int type, struct snd_card *card, int dev,
  178. const struct file_operations *f_ops,
  179. void *private_data, struct device *device);
  180. int snd_unregister_device(struct device *dev);
  181. void *snd_lookup_minor_data(unsigned int minor, int type);
  182. #ifdef CONFIG_SND_OSSEMUL
  183. int snd_register_oss_device(int type, struct snd_card *card, int dev,
  184. const struct file_operations *f_ops, void *private_data);
  185. int snd_unregister_oss_device(int type, struct snd_card *card, int dev);
  186. void *snd_lookup_oss_minor_data(unsigned int minor, int type);
  187. #endif
  188. int snd_minor_info_init(void);
  189. /* sound_oss.c */
  190. #ifdef CONFIG_SND_OSSEMUL
  191. int snd_minor_info_oss_init(void);
  192. #else
  193. static inline int snd_minor_info_oss_init(void) { return 0; }
  194. #endif
  195. /* memory.c */
  196. int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
  197. int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
  198. /* init.c */
  199. extern struct snd_card *snd_cards[SNDRV_CARDS];
  200. int snd_card_locked(int card);
  201. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
  202. #define SND_MIXER_OSS_NOTIFY_REGISTER 0
  203. #define SND_MIXER_OSS_NOTIFY_DISCONNECT 1
  204. #define SND_MIXER_OSS_NOTIFY_FREE 2
  205. extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
  206. #endif
  207. int snd_card_new(struct device *parent, int idx, const char *xid,
  208. struct module *module, int extra_size,
  209. struct snd_card **card_ret);
  210. int snd_card_disconnect(struct snd_card *card);
  211. int snd_card_free(struct snd_card *card);
  212. int snd_card_free_when_closed(struct snd_card *card);
  213. void snd_card_set_id(struct snd_card *card, const char *id);
  214. int snd_card_register(struct snd_card *card);
  215. int snd_card_info_init(void);
  216. int snd_card_add_dev_attr(struct snd_card *card,
  217. const struct attribute_group *group);
  218. int snd_component_add(struct snd_card *card, const char *component);
  219. int snd_card_file_add(struct snd_card *card, struct file *file);
  220. int snd_card_file_remove(struct snd_card *card, struct file *file);
  221. #define snd_card_unref(card) put_device(&(card)->card_dev)
  222. #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
  223. /* device.c */
  224. int snd_device_new(struct snd_card *card, enum snd_device_type type,
  225. void *device_data, struct snd_device_ops *ops);
  226. int snd_device_register(struct snd_card *card, void *device_data);
  227. int snd_device_register_all(struct snd_card *card);
  228. void snd_device_disconnect(struct snd_card *card, void *device_data);
  229. void snd_device_disconnect_all(struct snd_card *card);
  230. void snd_device_free(struct snd_card *card, void *device_data);
  231. void snd_device_free_all(struct snd_card *card);
  232. /* isadma.c */
  233. #ifdef CONFIG_ISA_DMA_API
  234. #define DMA_MODE_NO_ENABLE 0x0100
  235. void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode);
  236. void snd_dma_disable(unsigned long dma);
  237. unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
  238. #endif
  239. /* misc.c */
  240. struct resource;
  241. void release_and_free_resource(struct resource *res);
  242. /* --- */
  243. /* sound printk debug levels */
  244. enum {
  245. SND_PR_ALWAYS,
  246. SND_PR_DEBUG,
  247. SND_PR_VERBOSE,
  248. };
  249. #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
  250. __printf(4, 5)
  251. void __snd_printk(unsigned int level, const char *file, int line,
  252. const char *format, ...);
  253. #else
  254. #define __snd_printk(level, file, line, format, args...) \
  255. printk(format, ##args)
  256. #endif
  257. /**
  258. * snd_printk - printk wrapper
  259. * @fmt: format string
  260. *
  261. * Works like printk() but prints the file and the line of the caller
  262. * when configured with CONFIG_SND_VERBOSE_PRINTK.
  263. */
  264. #define snd_printk(fmt, args...) \
  265. __snd_printk(0, __FILE__, __LINE__, fmt, ##args)
  266. #ifdef CONFIG_SND_DEBUG
  267. /**
  268. * snd_printd - debug printk
  269. * @fmt: format string
  270. *
  271. * Works like snd_printk() for debugging purposes.
  272. * Ignored when CONFIG_SND_DEBUG is not set.
  273. */
  274. #define snd_printd(fmt, args...) \
  275. __snd_printk(1, __FILE__, __LINE__, fmt, ##args)
  276. #define _snd_printd(level, fmt, args...) \
  277. __snd_printk(level, __FILE__, __LINE__, fmt, ##args)
  278. /**
  279. * snd_BUG - give a BUG warning message and stack trace
  280. *
  281. * Calls WARN() if CONFIG_SND_DEBUG is set.
  282. * Ignored when CONFIG_SND_DEBUG is not set.
  283. */
  284. #define snd_BUG() WARN(1, "BUG?\n")
  285. /**
  286. * Suppress high rates of output when CONFIG_SND_DEBUG is enabled.
  287. */
  288. #define snd_printd_ratelimit() printk_ratelimit()
  289. /**
  290. * snd_BUG_ON - debugging check macro
  291. * @cond: condition to evaluate
  292. *
  293. * Has the same behavior as WARN_ON when CONFIG_SND_DEBUG is set,
  294. * otherwise just evaluates the conditional and returns the value.
  295. */
  296. #define snd_BUG_ON(cond) WARN_ON((cond))
  297. #else /* !CONFIG_SND_DEBUG */
  298. __printf(1, 2)
  299. static inline void snd_printd(const char *format, ...) {}
  300. __printf(2, 3)
  301. static inline void _snd_printd(int level, const char *format, ...) {}
  302. #define snd_BUG() do { } while (0)
  303. #define snd_BUG_ON(condition) ({ \
  304. int __ret_warn_on = !!(condition); \
  305. unlikely(__ret_warn_on); \
  306. })
  307. static inline bool snd_printd_ratelimit(void) { return false; }
  308. #endif /* CONFIG_SND_DEBUG */
  309. #ifdef CONFIG_SND_DEBUG_VERBOSE
  310. /**
  311. * snd_printdd - debug printk
  312. * @format: format string
  313. *
  314. * Works like snd_printk() for debugging purposes.
  315. * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
  316. */
  317. #define snd_printdd(format, args...) \
  318. __snd_printk(2, __FILE__, __LINE__, format, ##args)
  319. #else
  320. __printf(1, 2)
  321. static inline void snd_printdd(const char *format, ...) {}
  322. #endif
  323. #define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) /* 3.8.1a */
  324. /* for easier backward-porting */
  325. #if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE)
  326. #define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev))
  327. #define gameport_set_port_data(gp,r) ((gp)->port_data = (r))
  328. #define gameport_get_port_data(gp) (gp)->port_data
  329. #endif
  330. /* PCI quirk list helper */
  331. struct snd_pci_quirk {
  332. unsigned short subvendor; /* PCI subvendor ID */
  333. unsigned short subdevice; /* PCI subdevice ID */
  334. unsigned short subdevice_mask; /* bitmask to match */
  335. int value; /* value */
  336. #ifdef CONFIG_SND_DEBUG_VERBOSE
  337. const char *name; /* name of the device (optional) */
  338. #endif
  339. };
  340. #define _SND_PCI_QUIRK_ID_MASK(vend, mask, dev) \
  341. .subvendor = (vend), .subdevice = (dev), .subdevice_mask = (mask)
  342. #define _SND_PCI_QUIRK_ID(vend, dev) \
  343. _SND_PCI_QUIRK_ID_MASK(vend, 0xffff, dev)
  344. #define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)}
  345. #ifdef CONFIG_SND_DEBUG_VERBOSE
  346. #define SND_PCI_QUIRK(vend,dev,xname,val) \
  347. {_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)}
  348. #define SND_PCI_QUIRK_VENDOR(vend, xname, val) \
  349. {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val), .name = (xname)}
  350. #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \
  351. {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), \
  352. .value = (val), .name = (xname)}
  353. #define snd_pci_quirk_name(q) ((q)->name)
  354. #else
  355. #define SND_PCI_QUIRK(vend,dev,xname,val) \
  356. {_SND_PCI_QUIRK_ID(vend, dev), .value = (val)}
  357. #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \
  358. {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), .value = (val)}
  359. #define SND_PCI_QUIRK_VENDOR(vend, xname, val) \
  360. {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val)}
  361. #define snd_pci_quirk_name(q) ""
  362. #endif
  363. #ifdef CONFIG_PCI
  364. const struct snd_pci_quirk *
  365. snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list);
  366. const struct snd_pci_quirk *
  367. snd_pci_quirk_lookup_id(u16 vendor, u16 device,
  368. const struct snd_pci_quirk *list);
  369. #else
  370. static inline const struct snd_pci_quirk *
  371. snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list)
  372. {
  373. return NULL;
  374. }
  375. static inline const struct snd_pci_quirk *
  376. snd_pci_quirk_lookup_id(u16 vendor, u16 device,
  377. const struct snd_pci_quirk *list)
  378. {
  379. return NULL;
  380. }
  381. #endif
  382. #endif /* __SOUND_CORE_H */