core.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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@suse.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/sched.h> /* wake_up() */
  24. #include <asm/semaphore.h> /* struct semaphore */
  25. #include <linux/rwsem.h> /* struct rw_semaphore */
  26. #include <linux/workqueue.h> /* struct workqueue_struct */
  27. #include <linux/pm.h> /* pm_message_t */
  28. /* forward declarations */
  29. #ifdef CONFIG_PCI
  30. struct pci_dev;
  31. #endif
  32. #ifdef CONFIG_SBUS
  33. struct sbus_dev;
  34. #endif
  35. /* device allocation stuff */
  36. #define SNDRV_DEV_TYPE_RANGE_SIZE 0x1000
  37. typedef int __bitwise snd_device_type_t;
  38. #define SNDRV_DEV_TOPLEVEL ((__force snd_device_type_t) 0)
  39. #define SNDRV_DEV_CONTROL ((__force snd_device_type_t) 1)
  40. #define SNDRV_DEV_LOWLEVEL_PRE ((__force snd_device_type_t) 2)
  41. #define SNDRV_DEV_LOWLEVEL_NORMAL ((__force snd_device_type_t) 0x1000)
  42. #define SNDRV_DEV_PCM ((__force snd_device_type_t) 0x1001)
  43. #define SNDRV_DEV_RAWMIDI ((__force snd_device_type_t) 0x1002)
  44. #define SNDRV_DEV_TIMER ((__force snd_device_type_t) 0x1003)
  45. #define SNDRV_DEV_SEQUENCER ((__force snd_device_type_t) 0x1004)
  46. #define SNDRV_DEV_HWDEP ((__force snd_device_type_t) 0x1005)
  47. #define SNDRV_DEV_INFO ((__force snd_device_type_t) 0x1006)
  48. #define SNDRV_DEV_BUS ((__force snd_device_type_t) 0x1007)
  49. #define SNDRV_DEV_CODEC ((__force snd_device_type_t) 0x1008)
  50. #define SNDRV_DEV_LOWLEVEL ((__force snd_device_type_t) 0x2000)
  51. typedef int __bitwise snd_device_state_t;
  52. #define SNDRV_DEV_BUILD ((__force snd_device_state_t) 0)
  53. #define SNDRV_DEV_REGISTERED ((__force snd_device_state_t) 1)
  54. #define SNDRV_DEV_DISCONNECTED ((__force snd_device_state_t) 2)
  55. typedef int __bitwise snd_device_cmd_t;
  56. #define SNDRV_DEV_CMD_PRE ((__force snd_device_cmd_t) 0)
  57. #define SNDRV_DEV_CMD_NORMAL ((__force snd_device_cmd_t) 1)
  58. #define SNDRV_DEV_CMD_POST ((__force snd_device_cmd_t) 2)
  59. struct snd_device;
  60. struct snd_device_ops {
  61. int (*dev_free)(struct snd_device *dev);
  62. int (*dev_register)(struct snd_device *dev);
  63. int (*dev_disconnect)(struct snd_device *dev);
  64. int (*dev_unregister)(struct snd_device *dev);
  65. };
  66. struct snd_device {
  67. struct list_head list; /* list of registered devices */
  68. struct snd_card *card; /* card which holds this device */
  69. snd_device_state_t state; /* state of the device */
  70. snd_device_type_t type; /* device type */
  71. void *device_data; /* device structure */
  72. struct snd_device_ops *ops; /* operations */
  73. };
  74. #define snd_device(n) list_entry(n, struct snd_device, list)
  75. /* monitor files for graceful shutdown (hotplug) */
  76. struct snd_monitor_file {
  77. struct file *file;
  78. struct snd_monitor_file *next;
  79. };
  80. struct snd_shutdown_f_ops; /* define it later in init.c */
  81. /* main structure for soundcard */
  82. struct snd_card {
  83. int number; /* number of soundcard (index to
  84. snd_cards) */
  85. char id[16]; /* id string of this card */
  86. char driver[16]; /* driver name */
  87. char shortname[32]; /* short name of this soundcard */
  88. char longname[80]; /* name of this soundcard */
  89. char mixername[80]; /* mixer name */
  90. char components[80]; /* card components delimited with
  91. space */
  92. struct module *module; /* top-level module */
  93. void *private_data; /* private data for soundcard */
  94. void (*private_free) (struct snd_card *card); /* callback for freeing of
  95. private data */
  96. struct list_head devices; /* devices */
  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 snd_info_entry *proc_root; /* root for soundcard specific files */
  105. struct snd_info_entry *proc_id; /* the card id */
  106. struct proc_dir_entry *proc_root_link; /* number link to real id */
  107. struct snd_monitor_file *files; /* all files associated to this card */
  108. struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown
  109. state */
  110. spinlock_t files_lock; /* lock the files for this card */
  111. int shutdown; /* this card is going down */
  112. wait_queue_head_t shutdown_sleep;
  113. struct work_struct free_workq; /* for free in workqueue */
  114. struct device *dev;
  115. #ifdef CONFIG_PM
  116. unsigned int power_state; /* power state */
  117. struct semaphore power_lock; /* power lock */
  118. wait_queue_head_t power_sleep;
  119. #endif
  120. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
  121. struct snd_mixer_oss *mixer_oss;
  122. int mixer_oss_change_count;
  123. #endif
  124. };
  125. #ifdef CONFIG_PM
  126. static inline void snd_power_lock(struct snd_card *card)
  127. {
  128. down(&card->power_lock);
  129. }
  130. static inline void snd_power_unlock(struct snd_card *card)
  131. {
  132. up(&card->power_lock);
  133. }
  134. static inline unsigned int snd_power_get_state(struct snd_card *card)
  135. {
  136. return card->power_state;
  137. }
  138. static inline void snd_power_change_state(struct snd_card *card, unsigned int state)
  139. {
  140. card->power_state = state;
  141. wake_up(&card->power_sleep);
  142. }
  143. /* init.c */
  144. int snd_power_wait(struct snd_card *card, unsigned int power_state, struct file *file);
  145. #else /* ! CONFIG_PM */
  146. #define snd_power_lock(card) do { (void)(card); } while (0)
  147. #define snd_power_unlock(card) do { (void)(card); } while (0)
  148. static inline int snd_power_wait(struct snd_card *card, unsigned int state, struct file *file) { return 0; }
  149. #define snd_power_get_state(card) SNDRV_CTL_POWER_D0
  150. #define snd_power_change_state(card, state) do { (void)(card); } while (0)
  151. #endif /* CONFIG_PM */
  152. struct snd_minor {
  153. int type; /* SNDRV_DEVICE_TYPE_XXX */
  154. int card; /* card number */
  155. int device; /* device number */
  156. struct file_operations *f_ops; /* file operations */
  157. void *private_data; /* private data for f_ops->open */
  158. char name[0]; /* device name (keep at the end of
  159. structure) */
  160. };
  161. /* sound.c */
  162. extern int snd_major;
  163. extern int snd_ecards_limit;
  164. void snd_request_card(int card);
  165. int snd_register_device(int type, struct snd_card *card, int dev,
  166. struct file_operations *f_ops, void *private_data,
  167. const char *name);
  168. int snd_unregister_device(int type, struct snd_card *card, int dev);
  169. void *snd_lookup_minor_data(unsigned int minor, int type);
  170. #ifdef CONFIG_SND_OSSEMUL
  171. int snd_register_oss_device(int type, struct snd_card *card, int dev,
  172. struct file_operations *f_ops, void *private_data,
  173. const char *name);
  174. int snd_unregister_oss_device(int type, struct snd_card *card, int dev);
  175. void *snd_lookup_oss_minor_data(unsigned int minor, int type);
  176. #endif
  177. int snd_minor_info_init(void);
  178. int snd_minor_info_done(void);
  179. /* sound_oss.c */
  180. #ifdef CONFIG_SND_OSSEMUL
  181. int snd_minor_info_oss_init(void);
  182. int snd_minor_info_oss_done(void);
  183. #else
  184. #define snd_minor_info_oss_init() /*NOP*/
  185. #define snd_minor_info_oss_done() /*NOP*/
  186. #endif
  187. /* memory.c */
  188. int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
  189. int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
  190. /* init.c */
  191. extern unsigned int snd_cards_lock;
  192. extern struct snd_card *snd_cards[SNDRV_CARDS];
  193. extern rwlock_t snd_card_rwlock;
  194. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
  195. #define SND_MIXER_OSS_NOTIFY_REGISTER 0
  196. #define SND_MIXER_OSS_NOTIFY_DISCONNECT 1
  197. #define SND_MIXER_OSS_NOTIFY_FREE 2
  198. extern int (*snd_mixer_oss_notify_callback)(struct snd_card *card, int cmd);
  199. #endif
  200. struct snd_card *snd_card_new(int idx, const char *id,
  201. struct module *module, int extra_size);
  202. int snd_card_disconnect(struct snd_card *card);
  203. int snd_card_free(struct snd_card *card);
  204. int snd_card_free_in_thread(struct snd_card *card);
  205. int snd_card_register(struct snd_card *card);
  206. int snd_card_info_init(void);
  207. int snd_card_info_done(void);
  208. int snd_component_add(struct snd_card *card, const char *component);
  209. int snd_card_file_add(struct snd_card *card, struct file *file);
  210. int snd_card_file_remove(struct snd_card *card, struct file *file);
  211. #ifndef snd_card_set_dev
  212. #define snd_card_set_dev(card,devptr) ((card)->dev = (devptr))
  213. #endif
  214. /* device.c */
  215. int snd_device_new(struct snd_card *card, snd_device_type_t type,
  216. void *device_data, struct snd_device_ops *ops);
  217. int snd_device_register(struct snd_card *card, void *device_data);
  218. int snd_device_register_all(struct snd_card *card);
  219. int snd_device_disconnect(struct snd_card *card, void *device_data);
  220. int snd_device_disconnect_all(struct snd_card *card);
  221. int snd_device_free(struct snd_card *card, void *device_data);
  222. int snd_device_free_all(struct snd_card *card, snd_device_cmd_t cmd);
  223. /* isadma.c */
  224. #ifdef CONFIG_ISA_DMA_API
  225. #define DMA_MODE_NO_ENABLE 0x0100
  226. void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode);
  227. void snd_dma_disable(unsigned long dma);
  228. unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
  229. #endif
  230. /* misc.c */
  231. struct resource;
  232. void release_and_free_resource(struct resource *res);
  233. #ifdef CONFIG_SND_VERBOSE_PRINTK
  234. void snd_verbose_printk(const char *file, int line, const char *format, ...)
  235. __attribute__ ((format (printf, 3, 4)));
  236. #endif
  237. #if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK)
  238. void snd_verbose_printd(const char *file, int line, const char *format, ...)
  239. __attribute__ ((format (printf, 3, 4)));
  240. #endif
  241. /* --- */
  242. #ifdef CONFIG_SND_VERBOSE_PRINTK
  243. /**
  244. * snd_printk - printk wrapper
  245. * @fmt: format string
  246. *
  247. * Works like print() but prints the file and the line of the caller
  248. * when configured with CONFIG_SND_VERBOSE_PRINTK.
  249. */
  250. #define snd_printk(fmt, args...) \
  251. snd_verbose_printk(__FILE__, __LINE__, fmt ,##args)
  252. #else
  253. #define snd_printk(fmt, args...) \
  254. printk(fmt ,##args)
  255. #endif
  256. #ifdef CONFIG_SND_DEBUG
  257. #define __ASTRING__(x) #x
  258. #ifdef CONFIG_SND_VERBOSE_PRINTK
  259. /**
  260. * snd_printd - debug printk
  261. * @fmt: format string
  262. *
  263. * Compiled only when Works like snd_printk() for debugging purpose.
  264. * Ignored when CONFIG_SND_DEBUG is not set.
  265. */
  266. #define snd_printd(fmt, args...) \
  267. snd_verbose_printd(__FILE__, __LINE__, fmt ,##args)
  268. #else
  269. #define snd_printd(fmt, args...) \
  270. printk(fmt ,##args)
  271. #endif
  272. /**
  273. * snd_assert - run-time assertion macro
  274. * @expr: expression
  275. *
  276. * This macro checks the expression in run-time and invokes the commands
  277. * given in the rest arguments if the assertion is failed.
  278. * When CONFIG_SND_DEBUG is not set, the expression is executed but
  279. * not checked.
  280. */
  281. #define snd_assert(expr, args...) do { \
  282. if (unlikely(!(expr))) { \
  283. snd_printk(KERN_ERR "BUG? (%s)\n", __ASTRING__(expr)); \
  284. dump_stack(); \
  285. args; \
  286. } \
  287. } while (0)
  288. #define snd_BUG() do { \
  289. snd_printk(KERN_ERR "BUG?\n"); \
  290. dump_stack(); \
  291. } while (0)
  292. #else /* !CONFIG_SND_DEBUG */
  293. #define snd_printd(fmt, args...) /* nothing */
  294. #define snd_assert(expr, args...) (void)(expr)
  295. #define snd_BUG() /* nothing */
  296. #endif /* CONFIG_SND_DEBUG */
  297. #ifdef CONFIG_SND_DEBUG_DETECT
  298. /**
  299. * snd_printdd - debug printk
  300. * @format: format string
  301. *
  302. * Compiled only when Works like snd_printk() for debugging purpose.
  303. * Ignored when CONFIG_SND_DEBUG_DETECT is not set.
  304. */
  305. #define snd_printdd(format, args...) snd_printk(format, ##args)
  306. #else
  307. #define snd_printdd(format, args...) /* nothing */
  308. #endif
  309. #define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) /* 3.8.1a */
  310. /* for easier backward-porting */
  311. #if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE)
  312. #ifndef gameport_set_dev_parent
  313. #define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev))
  314. #define gameport_set_port_data(gp,r) ((gp)->port_data = (r))
  315. #define gameport_get_port_data(gp) (gp)->port_data
  316. #endif
  317. #endif
  318. #include "typedefs.h"
  319. #endif /* __SOUND_CORE_H */