core.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  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 mixername[80]; /* mixer name */
  88. char components[128]; /* card components delimited with
  89. space */
  90. struct module *module; /* top-level module */
  91. void *private_data; /* private data for soundcard */
  92. void (*private_free) (struct snd_card *card); /* callback for freeing of
  93. private data */
  94. struct list_head devices; /* devices */
  95. struct device ctl_dev; /* control device */
  96. unsigned int last_numid; /* last used numeric ID */
  97. struct rw_semaphore controls_rwsem; /* controls list lock */
  98. rwlock_t ctl_files_rwlock; /* ctl_files list lock */
  99. int controls_count; /* count of all controls */
  100. int user_ctl_count; /* count of all user controls */
  101. struct list_head controls; /* all controls for this card */
  102. struct list_head ctl_files; /* active control files */
  103. struct mutex user_ctl_lock; /* protects user controls against
  104. concurrent access */
  105. struct snd_info_entry *proc_root; /* root for soundcard specific files */
  106. struct snd_info_entry *proc_id; /* the card id */
  107. struct proc_dir_entry *proc_root_link; /* number link to real id */
  108. struct list_head files_list; /* all files associated to this card */
  109. struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown
  110. state */
  111. spinlock_t files_lock; /* lock the files for this card */
  112. int shutdown; /* this card is going down */
  113. struct completion *release_completion;
  114. struct device *dev; /* device assigned to this card */
  115. struct device card_dev; /* cardX object for sysfs */
  116. const struct attribute_group *dev_groups[4]; /* assigned sysfs attr */
  117. bool registered; /* card_dev is registered? */
  118. #ifdef CONFIG_PM
  119. unsigned int power_state; /* power state */
  120. struct mutex power_lock; /* power lock */
  121. wait_queue_head_t power_sleep;
  122. #endif
  123. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
  124. struct snd_mixer_oss *mixer_oss;
  125. int mixer_oss_change_count;
  126. #endif
  127. };
  128. #define dev_to_snd_card(p) container_of(p, struct snd_card, card_dev)
  129. #ifdef CONFIG_PM
  130. static inline void snd_power_lock(struct snd_card *card)
  131. {
  132. mutex_lock(&card->power_lock);
  133. }
  134. static inline void snd_power_unlock(struct snd_card *card)
  135. {
  136. mutex_unlock(&card->power_lock);
  137. }
  138. static inline unsigned int snd_power_get_state(struct snd_card *card)
  139. {
  140. return card->power_state;
  141. }
  142. static inline void snd_power_change_state(struct snd_card *card, unsigned int state)
  143. {
  144. card->power_state = state;
  145. wake_up(&card->power_sleep);
  146. }
  147. /* init.c */
  148. int snd_power_wait(struct snd_card *card, unsigned int power_state);
  149. #else /* ! CONFIG_PM */
  150. #define snd_power_lock(card) do { (void)(card); } while (0)
  151. #define snd_power_unlock(card) do { (void)(card); } while (0)
  152. static inline int snd_power_wait(struct snd_card *card, unsigned int state) { return 0; }
  153. #define snd_power_get_state(card) ({ (void)(card); SNDRV_CTL_POWER_D0; })
  154. #define snd_power_change_state(card, state) do { (void)(card); } while (0)
  155. #endif /* CONFIG_PM */
  156. struct snd_minor {
  157. int type; /* SNDRV_DEVICE_TYPE_XXX */
  158. int card; /* card number */
  159. int device; /* device number */
  160. const struct file_operations *f_ops; /* file operations */
  161. void *private_data; /* private data for f_ops->open */
  162. struct device *dev; /* device for sysfs */
  163. struct snd_card *card_ptr; /* assigned card instance */
  164. };
  165. /* return a device pointer linked to each sound device as a parent */
  166. static inline struct device *snd_card_get_device_link(struct snd_card *card)
  167. {
  168. return card ? &card->card_dev : NULL;
  169. }
  170. /* sound.c */
  171. extern int snd_major;
  172. extern int snd_ecards_limit;
  173. extern struct class *sound_class;
  174. void snd_request_card(int card);
  175. void snd_device_initialize(struct device *dev, struct snd_card *card);
  176. int snd_register_device(int type, struct snd_card *card, int dev,
  177. const struct file_operations *f_ops,
  178. void *private_data, struct device *device);
  179. int snd_unregister_device(struct device *dev);
  180. void *snd_lookup_minor_data(unsigned int minor, int type);
  181. #ifdef CONFIG_SND_OSSEMUL
  182. int snd_register_oss_device(int type, struct snd_card *card, int dev,
  183. const struct file_operations *f_ops, void *private_data);
  184. int snd_unregister_oss_device(int type, struct snd_card *card, int dev);
  185. void *snd_lookup_oss_minor_data(unsigned int minor, int type);
  186. #endif
  187. int snd_minor_info_init(void);
  188. /* sound_oss.c */
  189. #ifdef CONFIG_SND_OSSEMUL
  190. int snd_minor_info_oss_init(void);
  191. #else
  192. static inline int snd_minor_info_oss_init(void) { return 0; }
  193. #endif
  194. /* memory.c */
  195. int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
  196. int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
  197. /* init.c */
  198. extern struct snd_card *snd_cards[SNDRV_CARDS];
  199. int snd_card_locked(int card);
  200. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
  201. #define SND_MIXER_OSS_NOTIFY_REGISTER 0
  202. #define SND_MIXER_OSS_NOTIFY_DISCONNECT 1
  203. #define SND_MIXER_OSS_NOTIFY_FREE 2
  204. extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
  205. #endif
  206. int snd_card_new(struct device *parent, int idx, const char *xid,
  207. struct module *module, int extra_size,
  208. struct snd_card **card_ret);
  209. int snd_card_disconnect(struct snd_card *card);
  210. int snd_card_free(struct snd_card *card);
  211. int snd_card_free_when_closed(struct snd_card *card);
  212. void snd_card_set_id(struct snd_card *card, const char *id);
  213. int snd_card_register(struct snd_card *card);
  214. int snd_card_info_init(void);
  215. int snd_card_add_dev_attr(struct snd_card *card,
  216. const struct attribute_group *group);
  217. int snd_component_add(struct snd_card *card, const char *component);
  218. int snd_card_file_add(struct snd_card *card, struct file *file);
  219. int snd_card_file_remove(struct snd_card *card, struct file *file);
  220. #define snd_card_unref(card) put_device(&(card)->card_dev)
  221. #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
  222. /* device.c */
  223. int snd_device_new(struct snd_card *card, enum snd_device_type type,
  224. void *device_data, struct snd_device_ops *ops);
  225. int snd_device_register(struct snd_card *card, void *device_data);
  226. int snd_device_register_all(struct snd_card *card);
  227. void snd_device_disconnect(struct snd_card *card, void *device_data);
  228. void snd_device_disconnect_all(struct snd_card *card);
  229. void snd_device_free(struct snd_card *card, void *device_data);
  230. void snd_device_free_all(struct snd_card *card);
  231. /* isadma.c */
  232. #ifdef CONFIG_ISA_DMA_API
  233. #define DMA_MODE_NO_ENABLE 0x0100
  234. void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode);
  235. void snd_dma_disable(unsigned long dma);
  236. unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
  237. #endif
  238. /* misc.c */
  239. struct resource;
  240. void release_and_free_resource(struct resource *res);
  241. /* --- */
  242. /* sound printk debug levels */
  243. enum {
  244. SND_PR_ALWAYS,
  245. SND_PR_DEBUG,
  246. SND_PR_VERBOSE,
  247. };
  248. #if defined(CONFIG_SND_DEBUG) || defined(CONFIG_SND_VERBOSE_PRINTK)
  249. __printf(4, 5)
  250. void __snd_printk(unsigned int level, const char *file, int line,
  251. const char *format, ...);
  252. #else
  253. #define __snd_printk(level, file, line, format, args...) \
  254. printk(format, ##args)
  255. #endif
  256. /**
  257. * snd_printk - printk wrapper
  258. * @fmt: format string
  259. *
  260. * Works like printk() but prints the file and the line of the caller
  261. * when configured with CONFIG_SND_VERBOSE_PRINTK.
  262. */
  263. #define snd_printk(fmt, args...) \
  264. __snd_printk(0, __FILE__, __LINE__, fmt, ##args)
  265. #ifdef CONFIG_SND_DEBUG
  266. /**
  267. * snd_printd - debug printk
  268. * @fmt: format string
  269. *
  270. * Works like snd_printk() for debugging purposes.
  271. * Ignored when CONFIG_SND_DEBUG is not set.
  272. */
  273. #define snd_printd(fmt, args...) \
  274. __snd_printk(1, __FILE__, __LINE__, fmt, ##args)
  275. #define _snd_printd(level, fmt, args...) \
  276. __snd_printk(level, __FILE__, __LINE__, fmt, ##args)
  277. /**
  278. * snd_BUG - give a BUG warning message and stack trace
  279. *
  280. * Calls WARN() if CONFIG_SND_DEBUG is set.
  281. * Ignored when CONFIG_SND_DEBUG is not set.
  282. */
  283. #define snd_BUG() WARN(1, "BUG?\n")
  284. /**
  285. * Suppress high rates of output when CONFIG_SND_DEBUG is enabled.
  286. */
  287. #define snd_printd_ratelimit() printk_ratelimit()
  288. /**
  289. * snd_BUG_ON - debugging check macro
  290. * @cond: condition to evaluate
  291. *
  292. * Has the same behavior as WARN_ON when CONFIG_SND_DEBUG is set,
  293. * otherwise just evaluates the conditional and returns the value.
  294. */
  295. #define snd_BUG_ON(cond) WARN_ON((cond))
  296. #else /* !CONFIG_SND_DEBUG */
  297. __printf(1, 2)
  298. static inline void snd_printd(const char *format, ...) {}
  299. __printf(2, 3)
  300. static inline void _snd_printd(int level, const char *format, ...) {}
  301. #define snd_BUG() do { } while (0)
  302. #define snd_BUG_ON(condition) ({ \
  303. int __ret_warn_on = !!(condition); \
  304. unlikely(__ret_warn_on); \
  305. })
  306. static inline bool snd_printd_ratelimit(void) { return false; }
  307. #endif /* CONFIG_SND_DEBUG */
  308. #ifdef CONFIG_SND_DEBUG_VERBOSE
  309. /**
  310. * snd_printdd - debug printk
  311. * @format: format string
  312. *
  313. * Works like snd_printk() for debugging purposes.
  314. * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
  315. */
  316. #define snd_printdd(format, args...) \
  317. __snd_printk(2, __FILE__, __LINE__, format, ##args)
  318. #else
  319. __printf(1, 2)
  320. static inline void snd_printdd(const char *format, ...) {}
  321. #endif
  322. #define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) /* 3.8.1a */
  323. /* for easier backward-porting */
  324. #if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE)
  325. #define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev))
  326. #define gameport_set_port_data(gp,r) ((gp)->port_data = (r))
  327. #define gameport_get_port_data(gp) (gp)->port_data
  328. #endif
  329. /* PCI quirk list helper */
  330. struct snd_pci_quirk {
  331. unsigned short subvendor; /* PCI subvendor ID */
  332. unsigned short subdevice; /* PCI subdevice ID */
  333. unsigned short subdevice_mask; /* bitmask to match */
  334. int value; /* value */
  335. #ifdef CONFIG_SND_DEBUG_VERBOSE
  336. const char *name; /* name of the device (optional) */
  337. #endif
  338. };
  339. #define _SND_PCI_QUIRK_ID_MASK(vend, mask, dev) \
  340. .subvendor = (vend), .subdevice = (dev), .subdevice_mask = (mask)
  341. #define _SND_PCI_QUIRK_ID(vend, dev) \
  342. _SND_PCI_QUIRK_ID_MASK(vend, 0xffff, dev)
  343. #define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)}
  344. #ifdef CONFIG_SND_DEBUG_VERBOSE
  345. #define SND_PCI_QUIRK(vend,dev,xname,val) \
  346. {_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)}
  347. #define SND_PCI_QUIRK_VENDOR(vend, xname, val) \
  348. {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val), .name = (xname)}
  349. #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \
  350. {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), \
  351. .value = (val), .name = (xname)}
  352. #define snd_pci_quirk_name(q) ((q)->name)
  353. #else
  354. #define SND_PCI_QUIRK(vend,dev,xname,val) \
  355. {_SND_PCI_QUIRK_ID(vend, dev), .value = (val)}
  356. #define SND_PCI_QUIRK_MASK(vend, mask, dev, xname, val) \
  357. {_SND_PCI_QUIRK_ID_MASK(vend, mask, dev), .value = (val)}
  358. #define SND_PCI_QUIRK_VENDOR(vend, xname, val) \
  359. {_SND_PCI_QUIRK_ID_MASK(vend, 0, 0), .value = (val)}
  360. #define snd_pci_quirk_name(q) ""
  361. #endif
  362. #ifdef CONFIG_PCI
  363. const struct snd_pci_quirk *
  364. snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list);
  365. const struct snd_pci_quirk *
  366. snd_pci_quirk_lookup_id(u16 vendor, u16 device,
  367. const struct snd_pci_quirk *list);
  368. #else
  369. static inline const struct snd_pci_quirk *
  370. snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list)
  371. {
  372. return NULL;
  373. }
  374. static inline const struct snd_pci_quirk *
  375. snd_pci_quirk_lookup_id(u16 vendor, u16 device,
  376. const struct snd_pci_quirk *list)
  377. {
  378. return NULL;
  379. }
  380. #endif
  381. #endif /* __SOUND_CORE_H */