core.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  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/module.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/device.h>
  29. #include <linux/stringify.h>
  30. /* number of supported soundcards */
  31. #ifdef CONFIG_SND_DYNAMIC_MINORS
  32. #define SNDRV_CARDS 32
  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. #ifdef CONFIG_PCI
  39. struct pci_dev;
  40. #endif
  41. /* device allocation stuff */
  42. #define SNDRV_DEV_TYPE_RANGE_SIZE 0x1000
  43. typedef int __bitwise snd_device_type_t;
  44. #define SNDRV_DEV_TOPLEVEL ((__force snd_device_type_t) 0)
  45. #define SNDRV_DEV_CONTROL ((__force snd_device_type_t) 1)
  46. #define SNDRV_DEV_LOWLEVEL_PRE ((__force snd_device_type_t) 2)
  47. #define SNDRV_DEV_LOWLEVEL_NORMAL ((__force snd_device_type_t) 0x1000)
  48. #define SNDRV_DEV_PCM ((__force snd_device_type_t) 0x1001)
  49. #define SNDRV_DEV_RAWMIDI ((__force snd_device_type_t) 0x1002)
  50. #define SNDRV_DEV_TIMER ((__force snd_device_type_t) 0x1003)
  51. #define SNDRV_DEV_SEQUENCER ((__force snd_device_type_t) 0x1004)
  52. #define SNDRV_DEV_HWDEP ((__force snd_device_type_t) 0x1005)
  53. #define SNDRV_DEV_INFO ((__force snd_device_type_t) 0x1006)
  54. #define SNDRV_DEV_BUS ((__force snd_device_type_t) 0x1007)
  55. #define SNDRV_DEV_CODEC ((__force snd_device_type_t) 0x1008)
  56. #define SNDRV_DEV_JACK ((__force snd_device_type_t) 0x1009)
  57. #define SNDRV_DEV_LOWLEVEL ((__force snd_device_type_t) 0x2000)
  58. typedef int __bitwise snd_device_state_t;
  59. #define SNDRV_DEV_BUILD ((__force snd_device_state_t) 0)
  60. #define SNDRV_DEV_REGISTERED ((__force snd_device_state_t) 1)
  61. #define SNDRV_DEV_DISCONNECTED ((__force snd_device_state_t) 2)
  62. typedef int __bitwise snd_device_cmd_t;
  63. #define SNDRV_DEV_CMD_PRE ((__force snd_device_cmd_t) 0)
  64. #define SNDRV_DEV_CMD_NORMAL ((__force snd_device_cmd_t) 1)
  65. #define SNDRV_DEV_CMD_POST ((__force snd_device_cmd_t) 2)
  66. struct snd_device;
  67. struct snd_device_ops {
  68. int (*dev_free)(struct snd_device *dev);
  69. int (*dev_register)(struct snd_device *dev);
  70. int (*dev_disconnect)(struct snd_device *dev);
  71. };
  72. struct snd_device {
  73. struct list_head list; /* list of registered devices */
  74. struct snd_card *card; /* card which holds this device */
  75. snd_device_state_t state; /* state of the device */
  76. snd_device_type_t type; /* device type */
  77. void *device_data; /* device structure */
  78. struct snd_device_ops *ops; /* operations */
  79. };
  80. #define snd_device(n) list_entry(n, struct snd_device, list)
  81. /* monitor files for graceful shutdown (hotplug) */
  82. struct snd_monitor_file {
  83. struct file *file;
  84. struct snd_monitor_file *next;
  85. const struct file_operations *disconnected_f_op;
  86. struct list_head shutdown_list;
  87. };
  88. /* main structure for soundcard */
  89. struct snd_card {
  90. int number; /* number of soundcard (index to
  91. snd_cards) */
  92. char id[16]; /* id string of this card */
  93. char driver[16]; /* driver name */
  94. char shortname[32]; /* short name of this soundcard */
  95. char longname[80]; /* name of this soundcard */
  96. char mixername[80]; /* mixer name */
  97. char components[128]; /* card components delimited with
  98. space */
  99. struct module *module; /* top-level module */
  100. void *private_data; /* private data for soundcard */
  101. void (*private_free) (struct snd_card *card); /* callback for freeing of
  102. private data */
  103. struct list_head devices; /* devices */
  104. unsigned int last_numid; /* last used numeric ID */
  105. struct rw_semaphore controls_rwsem; /* controls list lock */
  106. rwlock_t ctl_files_rwlock; /* ctl_files list lock */
  107. int controls_count; /* count of all controls */
  108. int user_ctl_count; /* count of all user controls */
  109. struct list_head controls; /* all controls for this card */
  110. struct list_head ctl_files; /* active control files */
  111. struct snd_info_entry *proc_root; /* root for soundcard specific files */
  112. struct snd_info_entry *proc_id; /* the card id */
  113. struct proc_dir_entry *proc_root_link; /* number link to real id */
  114. struct snd_monitor_file *files; /* all files associated to this card */
  115. struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown
  116. state */
  117. spinlock_t files_lock; /* lock the files for this card */
  118. int shutdown; /* this card is going down */
  119. int free_on_last_close; /* free in context of file_release */
  120. wait_queue_head_t shutdown_sleep;
  121. struct device *dev; /* device assigned to this card */
  122. #ifndef CONFIG_SYSFS_DEPRECATED
  123. struct device *card_dev; /* cardX object for sysfs */
  124. #endif
  125. #ifdef CONFIG_PM
  126. unsigned int power_state; /* power state */
  127. struct mutex power_lock; /* power lock */
  128. wait_queue_head_t power_sleep;
  129. #endif
  130. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
  131. struct snd_mixer_oss *mixer_oss;
  132. int mixer_oss_change_count;
  133. #endif
  134. };
  135. #ifdef CONFIG_PM
  136. static inline void snd_power_lock(struct snd_card *card)
  137. {
  138. mutex_lock(&card->power_lock);
  139. }
  140. static inline void snd_power_unlock(struct snd_card *card)
  141. {
  142. mutex_unlock(&card->power_lock);
  143. }
  144. static inline unsigned int snd_power_get_state(struct snd_card *card)
  145. {
  146. return card->power_state;
  147. }
  148. static inline void snd_power_change_state(struct snd_card *card, unsigned int state)
  149. {
  150. card->power_state = state;
  151. wake_up(&card->power_sleep);
  152. }
  153. /* init.c */
  154. int snd_power_wait(struct snd_card *card, unsigned int power_state);
  155. #else /* ! CONFIG_PM */
  156. #define snd_power_lock(card) do { (void)(card); } while (0)
  157. #define snd_power_unlock(card) do { (void)(card); } while (0)
  158. static inline int snd_power_wait(struct snd_card *card, unsigned int state) { return 0; }
  159. #define snd_power_get_state(card) SNDRV_CTL_POWER_D0
  160. #define snd_power_change_state(card, state) do { (void)(card); } while (0)
  161. #endif /* CONFIG_PM */
  162. struct snd_minor {
  163. int type; /* SNDRV_DEVICE_TYPE_XXX */
  164. int card; /* card number */
  165. int device; /* device number */
  166. const struct file_operations *f_ops; /* file operations */
  167. void *private_data; /* private data for f_ops->open */
  168. struct device *dev; /* device for sysfs */
  169. };
  170. /* return a device pointer linked to each sound device as a parent */
  171. static inline struct device *snd_card_get_device_link(struct snd_card *card)
  172. {
  173. #ifdef CONFIG_SYSFS_DEPRECATED
  174. return card ? card->dev : NULL;
  175. #else
  176. return card ? card->card_dev : NULL;
  177. #endif
  178. }
  179. /* sound.c */
  180. extern int snd_major;
  181. extern int snd_ecards_limit;
  182. extern struct class *sound_class;
  183. void snd_request_card(int card);
  184. int snd_register_device_for_dev(int type, struct snd_card *card,
  185. int dev,
  186. const struct file_operations *f_ops,
  187. void *private_data,
  188. const char *name,
  189. struct device *device);
  190. /**
  191. * snd_register_device - Register the ALSA device file for the card
  192. * @type: the device type, SNDRV_DEVICE_TYPE_XXX
  193. * @card: the card instance
  194. * @dev: the device index
  195. * @f_ops: the file operations
  196. * @private_data: user pointer for f_ops->open()
  197. * @name: the device file name
  198. *
  199. * Registers an ALSA device file for the given card.
  200. * The operators have to be set in reg parameter.
  201. *
  202. * This function uses the card's device pointer to link to the
  203. * correct &struct device.
  204. *
  205. * Returns zero if successful, or a negative error code on failure.
  206. */
  207. static inline int snd_register_device(int type, struct snd_card *card, int dev,
  208. const struct file_operations *f_ops,
  209. void *private_data,
  210. const char *name)
  211. {
  212. return snd_register_device_for_dev(type, card, dev, f_ops,
  213. private_data, name,
  214. snd_card_get_device_link(card));
  215. }
  216. int snd_unregister_device(int type, struct snd_card *card, int dev);
  217. void *snd_lookup_minor_data(unsigned int minor, int type);
  218. int snd_add_device_sysfs_file(int type, struct snd_card *card, int dev,
  219. struct device_attribute *attr);
  220. #ifdef CONFIG_SND_OSSEMUL
  221. int snd_register_oss_device(int type, struct snd_card *card, int dev,
  222. const struct file_operations *f_ops, void *private_data,
  223. const char *name);
  224. int snd_unregister_oss_device(int type, struct snd_card *card, int dev);
  225. void *snd_lookup_oss_minor_data(unsigned int minor, int type);
  226. #endif
  227. int snd_minor_info_init(void);
  228. int snd_minor_info_done(void);
  229. /* sound_oss.c */
  230. #ifdef CONFIG_SND_OSSEMUL
  231. int snd_minor_info_oss_init(void);
  232. int snd_minor_info_oss_done(void);
  233. #else
  234. static inline int snd_minor_info_oss_init(void) { return 0; }
  235. static inline int snd_minor_info_oss_done(void) { return 0; }
  236. #endif
  237. /* memory.c */
  238. int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
  239. int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
  240. /* init.c */
  241. extern struct snd_card *snd_cards[SNDRV_CARDS];
  242. int snd_card_locked(int card);
  243. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
  244. #define SND_MIXER_OSS_NOTIFY_REGISTER 0
  245. #define SND_MIXER_OSS_NOTIFY_DISCONNECT 1
  246. #define SND_MIXER_OSS_NOTIFY_FREE 2
  247. extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
  248. #endif
  249. struct snd_card *snd_card_new(int idx, const char *id,
  250. struct module *module, int extra_size);
  251. int snd_card_disconnect(struct snd_card *card);
  252. int snd_card_free(struct snd_card *card);
  253. int snd_card_free_when_closed(struct snd_card *card);
  254. int snd_card_register(struct snd_card *card);
  255. int snd_card_info_init(void);
  256. int snd_card_info_done(void);
  257. int snd_component_add(struct snd_card *card, const char *component);
  258. int snd_card_file_add(struct snd_card *card, struct file *file);
  259. int snd_card_file_remove(struct snd_card *card, struct file *file);
  260. #ifndef snd_card_set_dev
  261. #define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
  262. #endif
  263. /* device.c */
  264. int snd_device_new(struct snd_card *card, snd_device_type_t type,
  265. void *device_data, struct snd_device_ops *ops);
  266. int snd_device_register(struct snd_card *card, void *device_data);
  267. int snd_device_register_all(struct snd_card *card);
  268. int snd_device_disconnect(struct snd_card *card, void *device_data);
  269. int snd_device_disconnect_all(struct snd_card *card);
  270. int snd_device_free(struct snd_card *card, void *device_data);
  271. int snd_device_free_all(struct snd_card *card, snd_device_cmd_t cmd);
  272. /* isadma.c */
  273. #ifdef CONFIG_ISA_DMA_API
  274. #define DMA_MODE_NO_ENABLE 0x0100
  275. void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode);
  276. void snd_dma_disable(unsigned long dma);
  277. unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
  278. #endif
  279. /* misc.c */
  280. struct resource;
  281. void release_and_free_resource(struct resource *res);
  282. #ifdef CONFIG_SND_VERBOSE_PRINTK
  283. void snd_verbose_printk(const char *file, int line, const char *format, ...)
  284. __attribute__ ((format (printf, 3, 4)));
  285. #endif
  286. #if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK)
  287. void snd_verbose_printd(const char *file, int line, const char *format, ...)
  288. __attribute__ ((format (printf, 3, 4)));
  289. #endif
  290. /* --- */
  291. #ifdef CONFIG_SND_VERBOSE_PRINTK
  292. /**
  293. * snd_printk - printk wrapper
  294. * @fmt: format string
  295. *
  296. * Works like print() but prints the file and the line of the caller
  297. * when configured with CONFIG_SND_VERBOSE_PRINTK.
  298. */
  299. #define snd_printk(fmt, args...) \
  300. snd_verbose_printk(__FILE__, __LINE__, fmt ,##args)
  301. #else
  302. #define snd_printk(fmt, args...) \
  303. printk(fmt ,##args)
  304. #endif
  305. #ifdef CONFIG_SND_DEBUG
  306. #ifdef CONFIG_SND_VERBOSE_PRINTK
  307. /**
  308. * snd_printd - debug printk
  309. * @fmt: format string
  310. *
  311. * Works like snd_printk() for debugging purposes.
  312. * Ignored when CONFIG_SND_DEBUG is not set.
  313. */
  314. #define snd_printd(fmt, args...) \
  315. snd_verbose_printd(__FILE__, __LINE__, fmt ,##args)
  316. #else
  317. #define snd_printd(fmt, args...) \
  318. printk(fmt ,##args)
  319. #endif
  320. #define snd_BUG() WARN(1, "BUG?\n")
  321. #define snd_BUG_ON(cond) WARN((cond), "BUG? (%s)\n", __stringify(cond))
  322. #else /* !CONFIG_SND_DEBUG */
  323. #define snd_printd(fmt, args...) do { } while (0)
  324. #define snd_BUG() do { } while (0)
  325. static inline int __snd_bug_on(void)
  326. {
  327. return 0;
  328. }
  329. #define snd_BUG_ON(cond) __snd_bug_on() /* always false */
  330. #endif /* CONFIG_SND_DEBUG */
  331. #ifdef CONFIG_SND_DEBUG_VERBOSE
  332. /**
  333. * snd_printdd - debug printk
  334. * @format: format string
  335. *
  336. * Works like snd_printk() for debugging purposes.
  337. * Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
  338. */
  339. #define snd_printdd(format, args...) snd_printk(format, ##args)
  340. #else
  341. #define snd_printdd(format, args...) /* nothing */
  342. #endif
  343. #define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) /* 3.8.1a */
  344. /* for easier backward-porting */
  345. #if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE)
  346. #ifndef gameport_set_dev_parent
  347. #define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev))
  348. #define gameport_set_port_data(gp,r) ((gp)->port_data = (r))
  349. #define gameport_get_port_data(gp) (gp)->port_data
  350. #endif
  351. #endif
  352. /* PCI quirk list helper */
  353. struct snd_pci_quirk {
  354. unsigned short subvendor; /* PCI subvendor ID */
  355. unsigned short subdevice; /* PCI subdevice ID */
  356. int value; /* value */
  357. #ifdef CONFIG_SND_DEBUG_VERBOSE
  358. const char *name; /* name of the device (optional) */
  359. #endif
  360. };
  361. #define _SND_PCI_QUIRK_ID(vend,dev) \
  362. .subvendor = (vend), .subdevice = (dev)
  363. #define SND_PCI_QUIRK_ID(vend,dev) {_SND_PCI_QUIRK_ID(vend, dev)}
  364. #ifdef CONFIG_SND_DEBUG_VERBOSE
  365. #define SND_PCI_QUIRK(vend,dev,xname,val) \
  366. {_SND_PCI_QUIRK_ID(vend, dev), .value = (val), .name = (xname)}
  367. #else
  368. #define SND_PCI_QUIRK(vend,dev,xname,val) \
  369. {_SND_PCI_QUIRK_ID(vend, dev), .value = (val)}
  370. #endif
  371. const struct snd_pci_quirk *
  372. snd_pci_quirk_lookup(struct pci_dev *pci, const struct snd_pci_quirk *list);
  373. #endif /* __SOUND_CORE_H */