1 /******************************************************************************
3 AudioScience HPI driver
4 Copyright (C) 1997-2011 AudioScience Inc. <support@audioscience.com>
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;
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.
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
19 HPI Operating System Specific macros for Linux Kernel driver
21 (C) Copyright AudioScience Inc. 1997-2003
22 ******************************************************************************/
26 #undef HPI_OS_LINUX_KERNEL
27 #define HPI_OS_LINUX_KERNEL
29 #define HPI_OS_DEFINED
30 #define HPI_BUILD_KERNEL_MODE
33 #include <linux/ioctl.h>
34 #include <linux/kernel.h>
35 #include <linux/string.h>
36 #include <linux/device.h>
37 #include <linux/firmware.h>
38 #include <linux/interrupt.h>
39 #include <linux/pci.h>
40 #include <linux/mutex.h>
42 #define HPI_NO_OS_FILE_OPS
44 /** Details of a memory area allocated with pci_alloc_consistent
45 Need all info for parameters to pci_free_consistent
47 struct consistent_dma_area
{
49 /* looks like dma-mapping dma_devres ?! */
52 dma_addr_t dma_handle
;
55 static inline u16
hpios_locked_mem_get_phys_addr(struct consistent_dma_area
56 *locked_mem_handle
, u32
*p_physical_addr
)
58 *p_physical_addr
= locked_mem_handle
->dma_handle
;
62 static inline u16
hpios_locked_mem_get_virt_addr(struct consistent_dma_area
63 *locked_mem_handle
, void **pp_virtual_addr
)
65 *pp_virtual_addr
= locked_mem_handle
->vaddr
;
69 static inline u16
hpios_locked_mem_valid(struct consistent_dma_area
72 return locked_mem_handle
->size
!= 0;
75 struct hpi_ioctl_linux
{
80 /* Conflict?: H is already used by a number of drivers hid, bluetooth hci,
81 and some sound drivers sb16, hdsp, emu10k. AFAIK 0xFC is ununsed command
83 #define HPI_IOCTL_LINUX _IOWR('H', 0xFC, struct hpi_ioctl_linux)
85 #define HPI_DEBUG_FLAG_ERROR KERN_ERR
86 #define HPI_DEBUG_FLAG_WARNING KERN_WARNING
87 #define HPI_DEBUG_FLAG_NOTICE KERN_NOTICE
88 #define HPI_DEBUG_FLAG_INFO KERN_INFO
89 #define HPI_DEBUG_FLAG_DEBUG KERN_DEBUG
90 #define HPI_DEBUG_FLAG_VERBOSE KERN_DEBUG /* kernel has no verbose */
92 #include <linux/spinlock.h>
96 struct hpios_spinlock
{
97 spinlock_t lock
; /* SEE hpios_spinlock */
101 /* The reason for all this evilness is that ALSA calls some of a drivers
102 * operators in atomic context, and some not. But all our functions channel
103 * through the HPI_Message conduit, so we can't handle the different context
107 #define IN_LOCK_IRQ 0
108 static inline void cond_lock(struct hpios_spinlock
*l
)
110 if (irqs_disabled()) {
111 /* NO bh or isr can execute on this processor,
112 so ordinary lock will do
114 spin_lock(&((l
)->lock
));
115 l
->lock_context
= IN_LOCK_IRQ
;
117 spin_lock_bh(&((l
)->lock
));
118 l
->lock_context
= IN_LOCK_BH
;
122 static inline void cond_unlock(struct hpios_spinlock
*l
)
124 if (l
->lock_context
== IN_LOCK_BH
)
125 spin_unlock_bh(&((l
)->lock
));
127 spin_unlock(&((l
)->lock
));
130 #define hpios_msgxlock_init(obj) spin_lock_init(&(obj)->lock)
131 #define hpios_msgxlock_lock(obj) cond_lock(obj)
132 #define hpios_msgxlock_unlock(obj) cond_unlock(obj)
134 #define hpios_dsplock_init(obj) spin_lock_init(&(obj)->dsp_lock.lock)
135 #define hpios_dsplock_lock(obj) cond_lock(&(obj)->dsp_lock)
136 #define hpios_dsplock_unlock(obj) cond_unlock(&(obj)->dsp_lock)
138 #ifdef CONFIG_SND_DEBUG
139 #define HPI_BUILD_DEBUG
142 #define HPI_ALIST_LOCKING
143 #define hpios_alistlock_init(obj) spin_lock_init(&((obj)->list_lock.lock))
144 #define hpios_alistlock_lock(obj) spin_lock(&((obj)->list_lock.lock))
145 #define hpios_alistlock_unlock(obj) spin_unlock(&((obj)->list_lock.lock))
149 /** pci drvdata points to an instance of this struct */
151 struct hpi_adapter_obj
*adapter
;
152 struct snd_card
*snd_card
;
156 void (*interrupt_callback
) (struct hpi_adapter
*);
158 /* mutex prevents contention for one card
159 between multiple user programs (via ioctl) */