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