core.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503
  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 */
  111. /* main structure for soundcard */
  112. struct _snd_card {
  113. int number; /* number of soundcard (index to snd_cards) */
  114. char id[16]; /* id string of this card */
  115. char driver[16]; /* driver name */
  116. char shortname[32]; /* short name of this soundcard */
  117. char longname[80]; /* name of this soundcard */
  118. char mixername[80]; /* mixer name */
  119. char components[80]; /* card components delimited with space */
  120. struct module *module; /* top-level module */
  121. void *private_data; /* private data for soundcard */
  122. void (*private_free) (snd_card_t *card); /* callback for freeing of private data */
  123. struct list_head devices; /* devices */
  124. unsigned int last_numid; /* last used numeric ID */
  125. struct rw_semaphore controls_rwsem; /* controls list lock */
  126. rwlock_t ctl_files_rwlock; /* ctl_files list lock */
  127. int controls_count; /* count of all controls */
  128. int user_ctl_count; /* count of all user controls */
  129. struct list_head controls; /* all controls for this card */
  130. struct list_head ctl_files; /* active control files */
  131. snd_info_entry_t *proc_root; /* root for soundcard specific files */
  132. snd_info_entry_t *proc_id; /* the card id */
  133. struct proc_dir_entry *proc_root_link; /* number link to real id */
  134. struct snd_monitor_file *files; /* all files associated to this card */
  135. struct snd_shutdown_f_ops *s_f_ops; /* file operations in the shutdown state */
  136. spinlock_t files_lock; /* lock the files for this card */
  137. int shutdown; /* this card is going down */
  138. wait_queue_head_t shutdown_sleep;
  139. struct work_struct free_workq; /* for free in workqueue */
  140. struct device *dev;
  141. #ifdef CONFIG_PM
  142. int (*pm_suspend)(snd_card_t *card, pm_message_t state);
  143. int (*pm_resume)(snd_card_t *card);
  144. void *pm_private_data;
  145. unsigned int power_state; /* power state */
  146. struct semaphore power_lock; /* power lock */
  147. wait_queue_head_t power_sleep;
  148. #ifdef CONFIG_SND_GENERIC_PM
  149. struct snd_generic_device *pm_dev; /* for ISA */
  150. #endif
  151. #endif
  152. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
  153. snd_mixer_oss_t *mixer_oss;
  154. int mixer_oss_change_count;
  155. #endif
  156. };
  157. #ifdef CONFIG_PM
  158. static inline void snd_power_lock(snd_card_t *card)
  159. {
  160. down(&card->power_lock);
  161. }
  162. static inline void snd_power_unlock(snd_card_t *card)
  163. {
  164. up(&card->power_lock);
  165. }
  166. int snd_power_wait(snd_card_t *card, unsigned int power_state, struct file *file);
  167. static inline unsigned int snd_power_get_state(snd_card_t *card)
  168. {
  169. return card->power_state;
  170. }
  171. static inline void snd_power_change_state(snd_card_t *card, unsigned int state)
  172. {
  173. card->power_state = state;
  174. wake_up(&card->power_sleep);
  175. }
  176. int snd_card_set_pm_callback(snd_card_t *card,
  177. int (*suspend)(snd_card_t *, pm_message_t),
  178. int (*resume)(snd_card_t *),
  179. void *private_data);
  180. int snd_card_set_generic_pm_callback(snd_card_t *card,
  181. int (*suspend)(snd_card_t *, pm_message_t),
  182. int (*resume)(snd_card_t *),
  183. void *private_data);
  184. #define snd_card_set_isa_pm_callback(card,suspend,resume,data) \
  185. snd_card_set_generic_pm_callback(card, suspend, resume, data)
  186. struct pci_dev;
  187. int snd_card_pci_suspend(struct pci_dev *dev, pm_message_t state);
  188. int snd_card_pci_resume(struct pci_dev *dev);
  189. #define SND_PCI_PM_CALLBACKS \
  190. .suspend = snd_card_pci_suspend, .resume = snd_card_pci_resume
  191. #else /* ! CONFIG_PM */
  192. #define snd_power_lock(card) do { (void)(card); } while (0)
  193. #define snd_power_unlock(card) do { (void)(card); } while (0)
  194. static inline int snd_power_wait(snd_card_t *card, unsigned int state, struct file *file) { return 0; }
  195. #define snd_power_get_state(card) SNDRV_CTL_POWER_D0
  196. #define snd_power_change_state(card, state) do { (void)(card); } while (0)
  197. #define snd_card_set_pm_callback(card,suspend,resume,data)
  198. #define snd_card_set_generic_pm_callback(card,suspend,resume,data)
  199. #define snd_card_set_isa_pm_callback(card,suspend,resume,data)
  200. #define SND_PCI_PM_CALLBACKS
  201. #endif /* CONFIG_PM */
  202. /* device.c */
  203. struct _snd_minor {
  204. struct list_head list; /* list of all minors per card */
  205. int number; /* minor number */
  206. int device; /* device number */
  207. const char *comment; /* for /proc/asound/devices */
  208. struct file_operations *f_ops; /* file operations */
  209. char name[0]; /* device name (keep at the end of structure) */
  210. };
  211. typedef struct _snd_minor snd_minor_t;
  212. /* sound.c */
  213. extern int snd_ecards_limit;
  214. void snd_request_card(int card);
  215. int snd_register_device(int type, snd_card_t *card, int dev, snd_minor_t *reg, const char *name);
  216. int snd_unregister_device(int type, snd_card_t *card, int dev);
  217. #ifdef CONFIG_SND_OSSEMUL
  218. int snd_register_oss_device(int type, snd_card_t *card, int dev, snd_minor_t *reg, const char *name);
  219. int snd_unregister_oss_device(int type, snd_card_t *card, int dev);
  220. #endif
  221. int snd_minor_info_init(void);
  222. int snd_minor_info_done(void);
  223. /* sound_oss.c */
  224. #ifdef CONFIG_SND_OSSEMUL
  225. int snd_minor_info_oss_init(void);
  226. int snd_minor_info_oss_done(void);
  227. int snd_oss_init_module(void);
  228. #else
  229. #define snd_minor_info_oss_init() /*NOP*/
  230. #define snd_minor_info_oss_done() /*NOP*/
  231. #define snd_oss_init_module() 0
  232. #endif
  233. /* memory.c */
  234. #ifdef CONFIG_SND_DEBUG_MEMORY
  235. void snd_memory_init(void);
  236. void snd_memory_done(void);
  237. int snd_memory_info_init(void);
  238. int snd_memory_info_done(void);
  239. void *snd_hidden_kmalloc(size_t size, int flags);
  240. void *snd_hidden_kcalloc(size_t n, size_t size, int flags);
  241. void snd_hidden_kfree(const void *obj);
  242. void *snd_hidden_vmalloc(unsigned long size);
  243. void snd_hidden_vfree(void *obj);
  244. char *snd_hidden_kstrdup(const char *s, int flags);
  245. #define kmalloc(size, flags) snd_hidden_kmalloc(size, flags)
  246. #define kcalloc(n, size, flags) snd_hidden_kcalloc(n, size, flags)
  247. #define kfree(obj) snd_hidden_kfree(obj)
  248. #define vmalloc(size) snd_hidden_vmalloc(size)
  249. #define vfree(obj) snd_hidden_vfree(obj)
  250. #define kmalloc_nocheck(size, flags) snd_wrapper_kmalloc(size, flags)
  251. #define vmalloc_nocheck(size) snd_wrapper_vmalloc(size)
  252. #define kfree_nocheck(obj) snd_wrapper_kfree(obj)
  253. #define vfree_nocheck(obj) snd_wrapper_vfree(obj)
  254. #define kstrdup(s, flags) snd_hidden_kstrdup(s, flags)
  255. #else
  256. #define snd_memory_init() /*NOP*/
  257. #define snd_memory_done() /*NOP*/
  258. #define snd_memory_info_init() /*NOP*/
  259. #define snd_memory_info_done() /*NOP*/
  260. #define kmalloc_nocheck(size, flags) kmalloc(size, flags)
  261. #define vmalloc_nocheck(size) vmalloc(size)
  262. #define kfree_nocheck(obj) kfree(obj)
  263. #define vfree_nocheck(obj) vfree(obj)
  264. #endif
  265. int copy_to_user_fromio(void __user *dst, const volatile void __iomem *src, size_t count);
  266. int copy_from_user_toio(volatile void __iomem *dst, const void __user *src, size_t count);
  267. /* init.c */
  268. extern unsigned int snd_cards_lock;
  269. extern snd_card_t *snd_cards[SNDRV_CARDS];
  270. extern rwlock_t snd_card_rwlock;
  271. #if defined(CONFIG_SND_MIXER_OSS) || defined(CONFIG_SND_MIXER_OSS_MODULE)
  272. #define SND_MIXER_OSS_NOTIFY_REGISTER 0
  273. #define SND_MIXER_OSS_NOTIFY_DISCONNECT 1
  274. #define SND_MIXER_OSS_NOTIFY_FREE 2
  275. extern int (*snd_mixer_oss_notify_callback)(snd_card_t *card, int cmd);
  276. #endif
  277. snd_card_t *snd_card_new(int idx, const char *id,
  278. struct module *module, int extra_size);
  279. int snd_card_disconnect(snd_card_t *card);
  280. int snd_card_free(snd_card_t *card);
  281. int snd_card_free_in_thread(snd_card_t *card);
  282. int snd_card_register(snd_card_t *card);
  283. int snd_card_info_init(void);
  284. int snd_card_info_done(void);
  285. int snd_component_add(snd_card_t *card, const char *component);
  286. int snd_card_file_add(snd_card_t *card, struct file *file);
  287. int snd_card_file_remove(snd_card_t *card, struct file *file);
  288. #ifndef snd_card_set_dev
  289. #define snd_card_set_dev(card,devptr) ((card)->dev = (devptr))
  290. #endif
  291. /* device.c */
  292. int snd_device_new(snd_card_t *card, snd_device_type_t type,
  293. void *device_data, snd_device_ops_t *ops);
  294. int snd_device_register(snd_card_t *card, void *device_data);
  295. int snd_device_register_all(snd_card_t *card);
  296. int snd_device_disconnect(snd_card_t *card, void *device_data);
  297. int snd_device_disconnect_all(snd_card_t *card);
  298. int snd_device_free(snd_card_t *card, void *device_data);
  299. int snd_device_free_all(snd_card_t *card, snd_device_cmd_t cmd);
  300. /* isadma.c */
  301. #define DMA_MODE_NO_ENABLE 0x0100
  302. void snd_dma_program(unsigned long dma, unsigned long addr, unsigned int size, unsigned short mode);
  303. void snd_dma_disable(unsigned long dma);
  304. unsigned int snd_dma_pointer(unsigned long dma, unsigned int size);
  305. /* misc.c */
  306. int snd_task_name(struct task_struct *task, char *name, size_t size);
  307. #ifdef CONFIG_SND_VERBOSE_PRINTK
  308. void snd_verbose_printk(const char *file, int line, const char *format, ...)
  309. __attribute__ ((format (printf, 3, 4)));
  310. #endif
  311. #if defined(CONFIG_SND_DEBUG) && defined(CONFIG_SND_VERBOSE_PRINTK)
  312. void snd_verbose_printd(const char *file, int line, const char *format, ...)
  313. __attribute__ ((format (printf, 3, 4)));
  314. #endif
  315. /* --- */
  316. #ifdef CONFIG_SND_VERBOSE_PRINTK
  317. /**
  318. * snd_printk - printk wrapper
  319. * @fmt: format string
  320. *
  321. * Works like print() but prints the file and the line of the caller
  322. * when configured with CONFIG_SND_VERBOSE_PRINTK.
  323. */
  324. #define snd_printk(fmt, args...) \
  325. snd_verbose_printk(__FILE__, __LINE__, fmt ,##args)
  326. #else
  327. #define snd_printk(fmt, args...) \
  328. printk(fmt ,##args)
  329. #endif
  330. #ifdef CONFIG_SND_DEBUG
  331. #define __ASTRING__(x) #x
  332. #ifdef CONFIG_SND_VERBOSE_PRINTK
  333. /**
  334. * snd_printd - debug printk
  335. * @format: format string
  336. *
  337. * Compiled only when Works like snd_printk() for debugging purpose.
  338. * Ignored when CONFIG_SND_DEBUG is not set.
  339. */
  340. #define snd_printd(fmt, args...) \
  341. snd_verbose_printd(__FILE__, __LINE__, fmt ,##args)
  342. #else
  343. #define snd_printd(fmt, args...) \
  344. printk(fmt ,##args)
  345. #endif
  346. /**
  347. * snd_assert - run-time assersion macro
  348. * @expr: expression
  349. * @args...: the action
  350. *
  351. * This macro checks the expression in run-time and invokes the commands
  352. * given in the rest arguments if the assertion is failed.
  353. * When CONFIG_SND_DEBUG is not set, the expression is executed but
  354. * not checked.
  355. */
  356. #define snd_assert(expr, args...) do {\
  357. if (unlikely(!(expr))) { \
  358. snd_printk(KERN_ERR "BUG? (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\
  359. args;\
  360. }\
  361. } while (0)
  362. /**
  363. * snd_runtime_check - run-time assersion macro
  364. * @expr: expression
  365. * @args...: the action
  366. *
  367. * This macro checks the expression in run-time and invokes the commands
  368. * given in the rest arguments if the assertion is failed.
  369. * Unlike snd_assert(), the action commands are executed even if
  370. * CONFIG_SND_DEBUG is not set but without any error messages.
  371. */
  372. #define snd_runtime_check(expr, args...) do {\
  373. if (unlikely(!(expr))) { \
  374. snd_printk(KERN_ERR "ERROR (%s) (called from %p)\n", __ASTRING__(expr), __builtin_return_address(0));\
  375. args;\
  376. }\
  377. } while (0)
  378. #else /* !CONFIG_SND_DEBUG */
  379. #define snd_printd(fmt, args...) /* nothing */
  380. #define snd_assert(expr, args...) (void)(expr)
  381. #define snd_runtime_check(expr, args...) do { if (!(expr)) { args; } } while (0)
  382. #endif /* CONFIG_SND_DEBUG */
  383. #ifdef CONFIG_SND_DEBUG_DETECT
  384. /**
  385. * snd_printdd - debug printk
  386. * @format: format string
  387. *
  388. * Compiled only when Works like snd_printk() for debugging purpose.
  389. * Ignored when CONFIG_SND_DEBUG_DETECT is not set.
  390. */
  391. #define snd_printdd(format, args...) snd_printk(format, ##args)
  392. #else
  393. #define snd_printdd(format, args...) /* nothing */
  394. #endif
  395. #define snd_BUG() snd_assert(0, )
  396. static inline void snd_timestamp_now(struct timespec *tstamp, int timespec)
  397. {
  398. struct timeval val;
  399. /* FIXME: use a linear time source */
  400. do_gettimeofday(&val);
  401. tstamp->tv_sec = val.tv_sec;
  402. tstamp->tv_nsec = val.tv_usec;
  403. if (timespec)
  404. tstamp->tv_nsec *= 1000L;
  405. }
  406. static inline void snd_timestamp_zero(struct timespec *tstamp)
  407. {
  408. tstamp->tv_sec = 0;
  409. tstamp->tv_nsec = 0;
  410. }
  411. static inline int snd_timestamp_null(struct timespec *tstamp)
  412. {
  413. return tstamp->tv_sec == 0 && tstamp->tv_nsec == 0;
  414. }
  415. #define SNDRV_OSS_VERSION ((3<<16)|(8<<8)|(1<<4)|(0)) /* 3.8.1a */
  416. /* for easier backward-porting */
  417. #if defined(CONFIG_GAMEPORT) || defined(CONFIG_GAMEPORT_MODULE)
  418. #ifndef gameport_set_dev_parent
  419. #define gameport_set_dev_parent(gp,xdev) ((gp)->dev.parent = (xdev))
  420. #define gameport_set_port_data(gp,r) ((gp)->port_data = (r))
  421. #define gameport_get_port_data(gp) (gp)->port_data
  422. #endif
  423. #endif
  424. #endif /* __SOUND_CORE_H */