hpios.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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. #ifdef CONFIG_64BIT
  34. #define HPI64BIT
  35. #endif
  36. /** Details of a memory area allocated with pci_alloc_consistent
  37. Need all info for parameters to pci_free_consistent
  38. */
  39. struct consistent_dma_area {
  40. struct device *pdev;
  41. /* looks like dma-mapping dma_devres ?! */
  42. size_t size;
  43. void *vaddr;
  44. dma_addr_t dma_handle;
  45. };
  46. static inline u16 hpios_locked_mem_get_phys_addr(struct consistent_dma_area
  47. *locked_mem_handle, u32 *p_physical_addr)
  48. {
  49. *p_physical_addr = locked_mem_handle->dma_handle;
  50. return 0;
  51. }
  52. static inline u16 hpios_locked_mem_get_virt_addr(struct consistent_dma_area
  53. *locked_mem_handle, void **pp_virtual_addr)
  54. {
  55. *pp_virtual_addr = locked_mem_handle->vaddr;
  56. return 0;
  57. }
  58. static inline u16 hpios_locked_mem_valid(struct consistent_dma_area
  59. *locked_mem_handle)
  60. {
  61. return locked_mem_handle->size != 0;
  62. }
  63. struct hpi_ioctl_linux {
  64. void __user *phm;
  65. void __user *phr;
  66. };
  67. /* Conflict?: H is already used by a number of drivers hid, bluetooth hci,
  68. and some sound drivers sb16, hdsp, emu10k. AFAIK 0xFC is ununsed command
  69. */
  70. #define HPI_IOCTL_LINUX _IOWR('H', 0xFC, struct hpi_ioctl_linux)
  71. #define HPI_DEBUG_FLAG_ERROR KERN_ERR
  72. #define HPI_DEBUG_FLAG_WARNING KERN_WARNING
  73. #define HPI_DEBUG_FLAG_NOTICE KERN_NOTICE
  74. #define HPI_DEBUG_FLAG_INFO KERN_INFO
  75. #define HPI_DEBUG_FLAG_DEBUG KERN_DEBUG
  76. #define HPI_DEBUG_FLAG_VERBOSE KERN_DEBUG /* kernel has no verbose */
  77. #include <linux/spinlock.h>
  78. #define HPI_LOCKING
  79. struct hpios_spinlock {
  80. spinlock_t lock; /* SEE hpios_spinlock */
  81. int lock_context;
  82. };
  83. /* The reason for all this evilness is that ALSA calls some of a drivers
  84. * operators in atomic context, and some not. But all our functions channel
  85. * through the HPI_Message conduit, so we can't handle the different context
  86. * per function
  87. */
  88. #define IN_LOCK_BH 1
  89. #define IN_LOCK_IRQ 0
  90. static inline void cond_lock(struct hpios_spinlock *l)
  91. {
  92. if (irqs_disabled()) {
  93. /* NO bh or isr can execute on this processor,
  94. so ordinary lock will do
  95. */
  96. spin_lock(&((l)->lock));
  97. l->lock_context = IN_LOCK_IRQ;
  98. } else {
  99. spin_lock_bh(&((l)->lock));
  100. l->lock_context = IN_LOCK_BH;
  101. }
  102. }
  103. static inline void cond_unlock(struct hpios_spinlock *l)
  104. {
  105. if (l->lock_context == IN_LOCK_BH)
  106. spin_unlock_bh(&((l)->lock));
  107. else
  108. spin_unlock(&((l)->lock));
  109. }
  110. #define hpios_msgxlock_init(obj) spin_lock_init(&(obj)->lock)
  111. #define hpios_msgxlock_lock(obj) cond_lock(obj)
  112. #define hpios_msgxlock_unlock(obj) cond_unlock(obj)
  113. #define hpios_dsplock_init(obj) spin_lock_init(&(obj)->dsp_lock.lock)
  114. #define hpios_dsplock_lock(obj) cond_lock(&(obj)->dsp_lock)
  115. #define hpios_dsplock_unlock(obj) cond_unlock(&(obj)->dsp_lock)
  116. #ifdef CONFIG_SND_DEBUG
  117. #define HPI_BUILD_DEBUG
  118. #endif
  119. #define HPI_ALIST_LOCKING
  120. #define hpios_alistlock_init(obj) spin_lock_init(&((obj)->list_lock.lock))
  121. #define hpios_alistlock_lock(obj) spin_lock(&((obj)->list_lock.lock))
  122. #define hpios_alistlock_unlock(obj) spin_unlock(&((obj)->list_lock.lock))
  123. struct snd_card;
  124. /** pci drvdata points to an instance of this struct */
  125. struct hpi_adapter {
  126. struct hpi_adapter_obj *adapter;
  127. struct snd_card *snd_card;
  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