hpios.h 4.0 KB

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