core.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. /* Typedef's */
  29. typedef struct timespec snd_timestamp_t;
  30. typedef struct sndrv_interval snd_interval_t;
  31. typedef enum sndrv_card_type snd_card_type;
  32. typedef struct sndrv_xferi snd_xferi_t;
  33. typedef struct sndrv_xfern snd_xfern_t;
  34. typedef struct sndrv_xferv snd_xferv_t;
  35. /* forward declarations */
  36. #ifdef CONFIG_PCI
  37. struct pci_dev;
  38. #endif
  39. #ifdef CONFIG_SBUS
  40. struct sbus_dev;
  41. #endif
  42. /* device allocation stuff */
  43. #define SNDRV_DEV_TYPE_RANGE_SIZE 0x1000
  44. typedef enum {
  45. SNDRV_DEV_TOPLEVEL = (0*SNDRV_DEV_TYPE_RANGE_SIZE),
  46. SNDRV_DEV_CONTROL,
  47. SNDRV_DEV_LOWLEVEL_PRE,
  48. SNDRV_DEV_LOWLEVEL_NORMAL = (1*SNDRV_DEV_TYPE_RANGE_SIZE),
  49. SNDRV_DEV_PCM,
  50. SNDRV_DEV_RAWMIDI,
  51. SNDRV_DEV_TIMER,
  52. SNDRV_DEV_SEQUENCER,
  53. SNDRV_DEV_HWDEP,
  54. SNDRV_DEV_INFO,
  55. SNDRV_DEV_BUS,
  56. SNDRV_DEV_CODEC,
  57. SNDRV_DEV_LOWLEVEL = (2*SNDRV_DEV_TYPE_RANGE_SIZE)
  58. } snd_device_type_t;
  59. typedef enum {
  60. SNDRV_DEV_BUILD,
  61. SNDRV_DEV_REGISTERED,
  62. SNDRV_DEV_DISCONNECTED
  63. } snd_device_state_t;
  64. typedef enum {
  65. SNDRV_DEV_CMD_PRE = 0,
  66. SNDRV_DEV_CMD_NORMAL = 1,
  67. SNDRV_DEV_CMD_POST = 2
  68. } snd_device_cmd_t;
  69. typedef struct _snd_card snd_card_t;
  70. typedef struct _snd_device snd_device_t;
  71. typedef int (snd_dev_free_t)(snd_device_t *device);
  72. typedef int (snd_dev_register_t)(snd_device_t *device);
  73. typedef int (snd_dev_disconnect_t)(snd_device_t *device);
  74. typedef int (snd_dev_unregister_t)(snd_device_t *device);
  75. typedef struct {
  76. snd_dev_free_t *dev_free;
  77. snd_dev_register_t *dev_register;
  78. snd_dev_disconnect_t *dev_disconnect;
  79. snd_dev_unregister_t *dev_unregister;
  80. } snd_device_ops_t;
  81. struct _snd_device {
  82. struct list_head list; /* list of registered devices */
  83. snd_card_t *card; /* card which holds this device */
  84. snd_device_state_t state; /* state of the device */
  85. snd_device_type_t type; /* device type */
  86. void *device_data; /* device structure */
  87. snd_device_ops_t *ops; /* operations */
  88. };
  89. #define snd_device(n) list_entry(n, snd_device_t, list)
  90. /* various typedefs */
  91. typedef struct snd_info_entry snd_info_entry_t;
  92. typedef struct _snd_pcm snd_pcm_t;
  93. typedef struct _snd_pcm_str snd_pcm_str_t;
  94. typedef struct _snd_pcm_substream snd_pcm_substream_t;
  95. typedef struct _snd_mixer snd_kmixer_t;
  96. typedef struct _snd_rawmidi snd_rawmidi_t;
  97. typedef struct _snd_ctl_file snd_ctl_file_t;
  98. typedef struct _snd_kcontrol snd_kcontrol_t;
  99. typedef struct _snd_timer snd_timer_t;
  100. typedef struct _snd_timer_instance snd_timer_instance_t;
  101. typedef struct _snd_hwdep snd_hwdep_t;
  102. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
  103. typedef struct _snd_oss_mixer snd_mixer_oss_t;
  104. #endif
  105. /* monitor files for graceful shutdown (hotplug) */
  106. struct snd_monitor_file {
  107. struct file *file;
  108. struct snd_monitor_file *next;
  109. };
  110. struct snd_shutdown_f_ops; /* define it later in init.c */
  111. /* main structure for soundcard */
  112. struct _snd_card {
  113. int number; /* number of soundcard (index to
  114. snd_cards) */
  115. char id[16]; /* id string of this card */
  116. char driver[16]; /* driver name */
  117. char shortname[32]; /* short name of this soundcard */
  118. char longname[80]; /* name of this soundcard */
  119. char mixername[80]; /* mixer name */
  120. char components[80]; /* card components delimited with
  121. space */
  122. struct module *module; /* top-level module */
  123. void *private_data; /* private data for soundcard */
  124. void (*private_free) (snd_card_t *card); /* callback for freeing of
  125. private data */
  126. struct list_head devices; /* devices */
  127. unsigned int last_numid; /* last used numeric ID */
  128. struct rw_semaphore controls_rwsem; /* controls list lock */
  129. rwlock_t ctl_files_rwlock; /* ctl_files list lock */
  130. int controls_count; /* count of all controls */
  131. int user_ctl_count; /* count of all user controls */
  132. struct list_head controls; /* all controls for this card */
  133. struct list_head ctl_files; /* active control files */
  134. snd_info_entry_t *proc_root; /* root for soundcard specific files */
  135. snd_info_entry_t *proc_id; /* the card id */
  136. struct proc_dir_entry *proc_root_link; /* number link to real id */
  137. struct snd_monitor_file *files; /* all files associated to this card */
  138. struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown
  139. state */
  140. spinlock_t files_lock; /* lock the files for this card */
  141. int shutdown; /* this card is going down */
  142. wait_queue_head_t shutdown_sleep;
  143. struct work_struct free_workq; /* for free in workqueue */
  144. struct device *dev;
  145. #ifdef CONFIG_PM
  146. int (*pm_suspend)(snd_card_t *card, pm_message_t state);
  147. int (*pm_resume)(snd_card_t *card);
  148. void *pm_private_data;
  149. unsigned int power_state; /* power state */
  150. struct semaphore power_lock; /* power lock */
  151. wait_queue_head_t power_sleep;
  152. #ifdef CONFIG_SND_GENERIC_PM
  153. struct snd_generic_device *pm_dev; /* for ISA */
  154. #endif
  155. #endif
  156. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
  157. snd_mixer_oss_t *mixer_oss;
  158. int mixer_oss_change_count;
  159. #endif
  160. };
  161. #ifdef CONFIG_PM
  162. static inline void snd_power_lock(snd_card_t *card)
  163. {
  164. down(&card->power_lock);
  165. }
  166. static inline void snd_power_unlock(snd_card_t *card)
  167. {
  168. up(&card->power_lock);
  169. }
  170. static inline unsigned int snd_power_get_state(snd_card_t *card)
  171. {
  172. return card->power_state;
  173. }
  174. static inline void snd_power_change_state(snd_card_t *card, unsigned int state)
  175. {
  176. card->power_state = state;
  177. wake_up(&card->power_sleep);
  178. }
  179. /* init.c */
  180. int snd_power_wait(snd_card_t *card, unsigned int power_state, struct file *file);
  181. int snd_card_set_pm_callback(snd_card_t *card,
  182. int (*suspend)(snd_card_t *, pm_message_t),
  183. int (*resume)(snd_card_t *),
  184. void *private_data);
  185. int snd_card_set_generic_pm_callback(snd_card_t *card,
  186. int (*suspend)(snd_card_t *, pm_message_t),
  187. int (*resume)(snd_card_t *),
  188. void *private_data);
  189. #define snd_card_set_isa_pm_callback(card,suspend,resume,data) \
  190. snd_card_set_generic_pm_callback(card, suspend, resume, data)
  191. struct pci_dev;
  192. int snd_card_pci_suspend(struct pci_dev *dev, pm_message_t state);
  193. int snd_card_pci_resume(struct pci_dev *dev);
  194. #define SND_PCI_PM_CALLBACKS \
  195. .suspend = snd_card_pci_suspend, .resume = snd_card_pci_resume
  196. #else /* ! CONFIG_PM */
  197. #define snd_power_lock(card) do { (void)(card); } while (0)
  198. #define snd_power_unlock(card) do { (void)(card); } while (0)
  199. static inline int snd_power_wait(snd_card_t *card, unsigned int state, struct file *file) { return 0; }
  200. #define snd_power_get_state(card) SNDRV_CTL_POWER_D0
  201. #define snd_power_change_state(card, state) do { (void)(card); } while (0)
  202. #define snd_card_set_pm_callback(card,suspend,resume,data)
  203. #define snd_card_set_generic_pm_callback(card,suspend,resume,data)
  204. #define snd_card_set_isa_pm_callback(card,suspend,resume,data)
  205. #define SND_PCI_PM_CALLBACKS
  206. #endif /* CONFIG_PM */
  207. struct _snd_minor {
  208. struct list_head list; /* list of all minors per card */
  209. int number; /* minor number */
  210. int device; /* device number */
  211. const char *comment; /* for /proc/asound/devices */
  212. struct file_operations *f_ops; /* file operations */
  213. char name[0]; /* device name (keep at the end of
  214. structure) */
  215. };
  216. typedef struct _snd_minor snd_minor_t;
  217. /* sound.c */
  218. extern int snd_ecards_limit;
  219. void snd_request_card(int card);
  220. int snd_register_device(int type, snd_card_t *card, int dev, snd_minor_t *reg, const char *name);
  221. int snd_unregister_device(int type, snd_card_t *card, int dev);
  222. #ifdef CONFIG_SND_OSSEMUL
  223. int snd_register_oss_device(int type, snd_card_t *card, int dev, snd_minor_t *reg, const char *name);
  224. int snd_unregister_oss_device(int type, snd_card_t *card, int dev);
  225. #endif
  226. int snd_minor_info_init(void);
  227. int snd_minor_info_done(void);
  228. /* sound_oss.c */
  229. #ifdef CONFIG_SND_OSSEMUL
  230. int snd_minor_info_oss_init(void);
  231. int snd_minor_info_oss_done(void);
  232. int snd_oss_init_module(void);
  233. #else
  234. #define snd_minor_info_oss_init() /*NOP*/
  235. #define snd_minor_info_oss_done() /*NOP*/
  236. #define snd_oss_init_module() 0
  237. #endif
  238. /* memory.c */
  239. #ifdef CONFIG_SND_DEBUG_MEMORY
  240. void snd_memory_init(void);
  241. void snd_memory_done(void);
  242. int snd_memory_info_init(void);
  243. int snd_memory_info_done(void);
  244. void *snd_hidden_kmalloc(size_t size, unsigned int __nocast flags);
  245. void *snd_hidden_kzalloc(size_t size, unsigned int __nocast flags);
  246. void *snd_hidden_kcalloc(size_t n, size_t size, unsigned int __nocast flags);
  247. void snd_hidden_kfree(const void *obj);
  248. void *snd_hidden_vmalloc(unsigned long size);
  249. void snd_hidden_vfree(void *obj);
  250. char *snd_hidden_kstrdup(const char *s, unsigned int __nocast flags);
  251. #define kmalloc(size, flags) snd_hidden_kmalloc(size, flags)
  252. #define kzalloc(size, flags) snd_hidden_kzalloc(size, flags)
  253. #define kcalloc(n, size, flags) snd_hidden_kcalloc(n, size, flags)
  254. #define kfree(obj) snd_hidden_kfree(obj)
  255. #define vmalloc(size) snd_hidden_vmalloc(size)
  256. #define vfree(obj) snd_hidden_vfree(obj)
  257. #define kmalloc_nocheck(size, flags) snd_wrapper_kmalloc(size, flags)
  258. #define vmalloc_nocheck(size) snd_wrapper_vmalloc(size)
  259. #define kfree_nocheck(obj) snd_wrapper_kfree(obj)
  260. #define vfree_nocheck(obj) snd_wrapper_vfree(obj)
  261. #define kstrdup(s, flags) snd_hidden_kstrdup(s, flags)
  262. #else
  263. #define snd_memory_init() /*NOP*/
  264. #define snd_memory_done() /*NOP*/
  265. #define snd_memory_info_init() /*NOP*/
  266. #define snd_memory_info_done() /*NOP*/
  267. #define kmalloc_nocheck(size, flags) kmalloc(size, flags)
  268. #define vmalloc_nocheck(size) vmalloc(size)
  269. #define kfree_nocheck(obj) kfree(obj)
  270. #define vfree_nocheck(obj) vfree(obj)
  271. #endif
  272. int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
  273. int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
  274. /* init.c */
  275. extern unsigned int snd_cards_lock;
  276. extern snd_card_t *snd_cards[SNDRV_CARDS];
  277. extern rwlock_t snd_card_rwlock;
  278. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
  279. #define SND_MIXER_OSS_NOTIFY_REGISTER 0
  280. #define SND_MIXER_OSS_NOTIFY_DISCONNECT 1
  281. #define SND_MIXER_OSS_NOTIFY_FREE 2
  282. extern int (*snd_mixer_oss_notify_callback)(snd_card_t *card, int cmd);
  283. #endif
  284. snd_card_t *snd_card_new(int idx, const char *id,
  285. struct module *module, int extra_size);
  286. int snd_card_disconnect(snd_card_t *card);
  287. int snd_card_free(snd_card_t *card);
  288. int snd_card_free_in_thread(snd_card_t *card);
  289. int snd_card_register(snd_card_t *card);
  290. int snd_card_info_init(void);
  291. int snd_card_info_done(void);
  292. int snd_component_add(snd_card_t *card, const char *component);
  293. int snd_card_file_add(snd_card_t *card, struct file *file);
  294. int snd_card_file_remove(snd_card_t *card, struct file *file);
  295. #ifndef snd_card_set_dev
  296. #define snd_card_set_dev(card,devptr) ((card)->dev = (devptr))
  297. #endif
  298. /* device.c */
  299. int snd_device_new(snd_card_t *card, snd_device_type_t type,
  300. void *device_data, snd_device_ops_t *ops);
  301. int snd_device_register(snd_card_t *card, void *device_data);
  302. int snd_device_register_all(snd_card_t *card);
  303. int snd_device_disconnect(snd_card_t *card, void *device_data);
  304. int snd_device_disconnect_all(snd_card_t *card);
  305. int snd_device_free(snd_card_t *card, void *device_data);
  306. int snd_device_free_all(snd_card_t *card, snd_device_cmd_t cmd);
  307. /* isadma.c */
  308. #ifdef CONFIG_ISA_DMA_API
  309. #define DMA_MODE_NO_ENABLE 0x0100
  310. void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode);
  311. void snd_dma_disable(unsigned long dma);
  312. unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
  313. #endif
  314. /* misc.c */
  315. int snd_task_name(struct task_struct *task, char *name, size_t size);
  316. #ifdef CONFIG_SND_VERBOSE_PRINTK
  317. void snd_verbose_printk(const char *file, int line, const char *format, ...)
  318. __attribute__ ((format (printf, 3, 4)));
  319. #endif
  320. #if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK)
  321. void snd_verbose_printd(const char *file, int line, const char *format, ...)
  322. __attribute__ ((format (printf, 3, 4)));
  323. #endif
  324. /* --- */
  325. #ifdef CONFIG_SND_VERBOSE_PRINTK
  326. /**
  327. * snd_printk - printk wrapper
  328. * @fmt: format string
  329. *
  330. * Works like print() but prints the file and the line of the caller
  331. * when configured with CONFIG_SND_VERBOSE_PRINTK.
  332. */
  333. #define snd_printk(fmt, args...) \
  334. snd_verbose_printk(__FILE__, __LINE__, fmt ,##args)
  335. #else
  336. #define snd_printk(fmt, args...) \
  337. printk(fmt ,##args)
  338. #endif
  339. #ifdef CONFIG_SND_DEBUG
  340. #define __ASTRING__(x) #x
  341. #ifdef CONFIG_SND_VERBOSE_PRINTK
  342. /**
  343. * snd_printd - debug printk
  344. * @format: format string
  345. *
  346. * Compiled only when Works like snd_printk() for debugging purpose.
  347. * Ignored when CONFIG_SND_DEBUG is not set.
  348. */
  349. #define snd_printd(fmt, args...) \
  350. snd_verbose_printd(__FILE__, __LINE__, fmt ,##args)
  351. #else
  352. #define snd_printd(fmt, args...) \
  353. printk(fmt ,##args)
  354. #endif
  355. /**
  356. * snd_assert - run-time assertion macro
  357. * @expr: expression
  358. * @args...: the action
  359. *
  360. * This macro checks the expression in run-time and invokes the commands
  361. * given in the rest arguments if the assertion is failed.
  362. * When CONFIG_SND_DEBUG is not set, the expression is executed but
  363. * not checked.
  364. */
  365. #define snd_assert(expr, args...) do {\
  366. if (unlikely(!(expr))) { \
  367. snd_printk(KERN_ERR "BUG? (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\
  368. args;\
  369. }\
  370. } while (0)
  371. /**
  372. * snd_runtime_check - run-time assertion macro
  373. * @expr: expression
  374. * @args...: the action
  375. *
  376. * This macro checks the expression in run-time and invokes the commands
  377. * given in the rest arguments if the assertion is failed.
  378. * Unlike snd_assert(), the action commands are executed even if
  379. * CONFIG_SND_DEBUG is not set but without any error messages.
  380. */
  381. #define snd_runtime_check(expr, args...) do {\
  382. if (unlikely(!(expr))) { \
  383. snd_printk(KERN_ERR "ERROR (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\
  384. args;\
  385. }\
  386. } while (0)
  387. #else /* !CONFIG_SND_DEBUG */
  388. #define snd_printd(fmt, args...) /* nothing */
  389. #define snd_assert(expr, args...) (void)(expr)
  390. #define snd_runtime_check(expr, args...) do { if (!(expr)) { args; } } while (0)
  391. #endif /* CONFIG_SND_DEBUG */
  392. #ifdef CONFIG_SND_DEBUG_DETECT
  393. /**
  394. * snd_printdd - debug printk
  395. * @format: format string
  396. *
  397. * Compiled only when Works like snd_printk() for debugging purpose.
  398. * Ignored when CONFIG_SND_DEBUG_DETECT is not set.
  399. */
  400. #define snd_printdd(format, args...) snd_printk(format, ##args)
  401. #else
  402. #define snd_printdd(format, args...) /* nothing */
  403. #endif
  404. #define snd_BUG() snd_assert(0, )
  405. static inline void snd_timestamp_now(struct timespec *tstamp, int timespec)
  406. {
  407. struct timeval val;
  408. /* FIXME: use a linear time source */
  409. do_gettimeofday(&val);
  410. tstamp->tv_sec = val.tv_sec;
  411. tstamp->tv_nsec = val.tv_usec;
  412. if (timespec)
  413. tstamp->tv_nsec *= 1000L;
  414. }
  415. static inline void snd_timestamp_zero(struct timespec *tstamp)
  416. {
  417. tstamp->tv_sec = 0;
  418. tstamp->tv_nsec = 0;
  419. }
  420. static inline int snd_timestamp_null(struct timespec *tstamp)
  421. {
  422. return tstamp->tv_sec == 0 && tstamp->tv_nsec == 0;
  423. }
  424. #define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) /* 3.8.1a */
  425. /* for easier backward-porting */
  426. #if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE)
  427. #ifndef gameport_set_dev_parent
  428. #define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev))
  429. #define gameport_set_port_data(gp,r) ((gp)->port_data = (r))
  430. #define gameport_get_port_data(gp) (gp)->port_data
  431. #endif
  432. #endif
  433. #endif /* __SOUND_CORE_H */