hpios.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /******************************************************************************
  2. AudioScience HPI driver
  3. Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License as
  6. published by the Free Software Foundation;
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. HPI Operating System Specific macros for Linux Kernel driver
  15. (C) Copyright AudioScience Inc. 1997-2003
  16. ******************************************************************************/
  17. #ifndef _HPIOS_H_
  18. #define _HPIOS_H_
  19. #undef HPI_OS_LINUX_KERNEL
  20. #define HPI_OS_LINUX_KERNEL
  21. #define HPI_OS_DEFINED
  22. #define HPI_BUILD_KERNEL_MODE
  23. #include <linux/io.h>
  24. #include <linux/ioctl.h>
  25. #include <linux/kernel.h>
  26. #include <linux/string.h>
  27. #include <linux/device.h>
  28. #include <linux/firmware.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/pci.h>
  31. #include <linux/mutex.h>
  32. #define HPI_NO_OS_FILE_OPS
  33. /** Details of a memory area allocated with pci_alloc_consistent
  34. Need all info for parameters to pci_free_consistent
  35. */
  36. struct consistent_dma_area {
  37. struct device *pdev;
  38. /* looks like dma-mapping dma_devres ?! */
  39. size_t size;
  40. void *vaddr;
  41. dma_addr_t dma_handle;
  42. };
  43. static inline u16 hpios_locked_mem_get_phys_addr(struct consistent_dma_area
  44. *locked_mem_handle, u32 *p_physical_addr)
  45. {
  46. *p_physical_addr = locked_mem_handle->dma_handle;
  47. return 0;
  48. }
  49. static inline u16 hpios_locked_mem_get_virt_addr(struct consistent_dma_area
  50. *locked_mem_handle, void **pp_virtual_addr)
  51. {
  52. *pp_virtual_addr = locked_mem_handle->vaddr;
  53. return 0;
  54. }
  55. static inline u16 hpios_locked_mem_valid(struct consistent_dma_area
  56. *locked_mem_handle)
  57. {
  58. return locked_mem_handle->size != 0;
  59. }
  60. struct hpi_ioctl_linux {
  61. void __user *phm;
  62. void __user *phr;
  63. };
  64. /* Conflict?: H is already used by a number of drivers hid, bluetooth hci,
  65. and some sound drivers sb16, hdsp, emu10k. AFAIK 0xFC is ununsed command
  66. */
  67. #define HPI_IOCTL_LINUX _IOWR('H', 0xFC, struct hpi_ioctl_linux)
  68. #define HPI_DEBUG_FLAG_ERROR KERN_ERR
  69. #define HPI_DEBUG_FLAG_WARNING KERN_WARNING
  70. #define HPI_DEBUG_FLAG_NOTICE KERN_NOTICE
  71. #define HPI_DEBUG_FLAG_INFO KERN_INFO
  72. #define HPI_DEBUG_FLAG_DEBUG KERN_DEBUG
  73. #define HPI_DEBUG_FLAG_VERBOSE KERN_DEBUG /* kernel has no verbose */
  74. #include <linux/spinlock.h>
  75. #define HPI_LOCKING
  76. struct hpios_spinlock {
  77. spinlock_t lock; /* SEE hpios_spinlock */
  78. int lock_context;
  79. };
  80. /* The reason for all this evilness is that ALSA calls some of a drivers
  81. * operators in atomic context, and some not. But all our functions channel
  82. * through the HPI_Message conduit, so we can't handle the different context
  83. * per function
  84. */
  85. #define IN_LOCK_BH 1
  86. #define IN_LOCK_IRQ 0
  87. static inline void cond_lock(struct hpios_spinlock *l)
  88. {
  89. if (irqs_disabled()) {
  90. /* NO bh or isr can execute on this processor,
  91. so ordinary lock will do
  92. */
  93. spin_lock(&((l)->lock));
  94. l->lock_context = IN_LOCK_IRQ;
  95. } else {
  96. spin_lock_bh(&((l)->lock));
  97. l->lock_context = IN_LOCK_BH;
  98. }
  99. }
  100. static inline void cond_unlock(struct hpios_spinlock *l)
  101. {
  102. if (l->lock_context == IN_LOCK_BH)
  103. spin_unlock_bh(&((l)->lock));
  104. else
  105. spin_unlock(&((l)->lock));
  106. }
  107. #define hpios_msgxlock_init(obj) spin_lock_init(&(obj)->lock)
  108. #define hpios_msgxlock_lock(obj) cond_lock(obj)
  109. #define hpios_msgxlock_unlock(obj) cond_unlock(obj)
  110. #define hpios_dsplock_init(obj) spin_lock_init(&(obj)->dsp_lock.lock)
  111. #define hpios_dsplock_lock(obj) cond_lock(&(obj)->dsp_lock)
  112. #define hpios_dsplock_unlock(obj) cond_unlock(&(obj)->dsp_lock)
  113. #ifdef CONFIG_SND_DEBUG
  114. #define HPI_BUILD_DEBUG
  115. #endif
  116. #define HPI_ALIST_LOCKING
  117. #define hpios_alistlock_init(obj) spin_lock_init(&((obj)->list_lock.lock))
  118. #define hpios_alistlock_lock(obj) spin_lock(&((obj)->list_lock.lock))
  119. #define hpios_alistlock_unlock(obj) spin_unlock(&((obj)->list_lock.lock))
  120. struct snd_card;
  121. /** pci drvdata points to an instance of this struct */
  122. struct hpi_adapter {
  123. struct hpi_adapter_obj *adapter;
  124. struct snd_card *snd_card;
  125. int irq;
  126. int interrupt_mode;
  127. void (*interrupt_callback) (struct hpi_adapter *);
  128. /* mutex prevents contention for one card
  129. between multiple user programs (via ioctl) */
  130. struct mutex mutex;
  131. char *p_buffer;
  132. size_t buffer_size;
  133. };
  134. #endif