Commit 3285ea10 authored by Eliot Blennerhassett's avatar Eliot Blennerhassett Committed by Takashi Iwai

ALSA: asihpi - Interrelated HPI tidy up.

Remove many unused functions.
Update some message and cache structs.
Use pci info directly from pci_dev.
Allow control cache elements with variable size, and handle
large message/response from dsp.
hpi6000 and hpi6205: fix error path when adapter bootload fails.
hpimsgx.c get rid of code duplicated in hpicmn.c
Signed-off-by: default avatarEliot Blennerhassett <eblennerhassett@audioscience.com>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent ad210ad1
This diff is collapsed.
This diff is collapsed.
...@@ -78,8 +78,8 @@ struct bus_master_interface { ...@@ -78,8 +78,8 @@ struct bus_master_interface {
u32 dsp_ack; u32 dsp_ack;
u32 transfer_size_in_bytes; u32 transfer_size_in_bytes;
union { union {
struct hpi_message message_buffer; struct hpi_message_header message_buffer;
struct hpi_response response_buffer; struct hpi_response_header response_buffer;
u8 b_data[HPI6205_SIZEOF_DATA]; u8 b_data[HPI6205_SIZEOF_DATA];
} u; } u;
struct controlcache_6205 control_cache; struct controlcache_6205 control_cache;
......
This diff is collapsed.
This diff is collapsed.
...@@ -40,8 +40,7 @@ struct hpi_control_cache { ...@@ -40,8 +40,7 @@ struct hpi_control_cache {
struct hpi_control_cache_info struct hpi_control_cache_info
**p_info; /**< pointer to allocated memory of **p_info; /**< pointer to allocated memory of
lookup pointers. */ lookup pointers. */
struct hpi_control_cache_single u8 *p_cache; /**< pointer to DSP's control cache. */
*p_cache; /**< pointer to DSP's control cache. */
}; };
struct hpi_adapter_obj *hpi_find_adapter(u16 adapter_index); struct hpi_adapter_obj *hpi_find_adapter(u16 adapter_index);
...@@ -52,12 +51,10 @@ void hpi_delete_adapter(struct hpi_adapter_obj *pao); ...@@ -52,12 +51,10 @@ void hpi_delete_adapter(struct hpi_adapter_obj *pao);
short hpi_check_control_cache(struct hpi_control_cache *pC, short hpi_check_control_cache(struct hpi_control_cache *pC,
struct hpi_message *phm, struct hpi_response *phr); struct hpi_message *phm, struct hpi_response *phr);
struct hpi_control_cache *hpi_alloc_control_cache(const u32 struct hpi_control_cache *hpi_alloc_control_cache(const u32
number_of_controls, const u32 size_in_bytes, number_of_controls, const u32 size_in_bytes, u8 *pDSP_control_buffer);
struct hpi_control_cache_info
*pDSP_control_buffer);
void hpi_free_control_cache(struct hpi_control_cache *p_cache); void hpi_free_control_cache(struct hpi_control_cache *p_cache);
void hpi_sync_control_cache(struct hpi_control_cache *pC, void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *pC,
struct hpi_message *phm, struct hpi_response *phr); struct hpi_message *phm, struct hpi_response *phr);
u16 hpi_validate_response(struct hpi_message *phm, struct hpi_response *phr); u16 hpi_validate_response(struct hpi_message *phm, struct hpi_response *phr);
short hpi_check_buffer_mapping(struct hpi_control_cache *p_cache, short hpi_check_buffer_mapping(struct hpi_control_cache *p_cache,
......
This diff is collapsed.
...@@ -50,7 +50,7 @@ static void hpi_init_message(struct hpi_message *phm, u16 object, ...@@ -50,7 +50,7 @@ static void hpi_init_message(struct hpi_message *phm, u16 object,
phm->object = object; phm->object = object;
phm->function = function; phm->function = function;
phm->version = 0; phm->version = 0;
phm->adapter_index = 0xFFFF; phm->adapter_index = HPI_ADAPTER_INDEX_INVALID;
/* Expect actual adapter index to be set by caller */ /* Expect actual adapter index to be set by caller */
} }
......
This diff is collapsed.
...@@ -30,6 +30,7 @@ Common Linux HPI ioctl and module probe/remove functions ...@@ -30,6 +30,7 @@ Common Linux HPI ioctl and module probe/remove functions
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/pci.h>
#include <linux/stringify.h> #include <linux/stringify.h>
#ifdef MODULE_FIRMWARE #ifdef MODULE_FIRMWARE
...@@ -45,7 +46,7 @@ MODULE_FIRMWARE("asihpi/dsp8900.bin"); ...@@ -45,7 +46,7 @@ MODULE_FIRMWARE("asihpi/dsp8900.bin");
static int prealloc_stream_buf; static int prealloc_stream_buf;
module_param(prealloc_stream_buf, int, S_IRUGO); module_param(prealloc_stream_buf, int, S_IRUGO);
MODULE_PARM_DESC(prealloc_stream_buf, MODULE_PARM_DESC(prealloc_stream_buf,
"preallocate size for per-adapter stream buffer"); "Preallocate size for per-adapter stream buffer");
/* Allow the debug level to be changed after module load. /* Allow the debug level to be changed after module load.
E.g. echo 2 > /sys/module/asihpi/parameters/hpiDebugLevel E.g. echo 2 > /sys/module/asihpi/parameters/hpiDebugLevel
...@@ -121,8 +122,8 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -121,8 +122,8 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
phpi_ioctl_data = (struct hpi_ioctl_linux __user *)arg; phpi_ioctl_data = (struct hpi_ioctl_linux __user *)arg;
/* Read the message and response pointers from user space. */ /* Read the message and response pointers from user space. */
if (get_user(puhm, &phpi_ioctl_data->phm) || if (get_user(puhm, &phpi_ioctl_data->phm)
get_user(puhr, &phpi_ioctl_data->phr)) { || get_user(puhr, &phpi_ioctl_data->phr)) {
err = -EFAULT; err = -EFAULT;
goto out; goto out;
} }
...@@ -135,7 +136,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -135,7 +136,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
if (hm->h.size > sizeof(*hm)) if (hm->h.size > sizeof(*hm))
hm->h.size = sizeof(*hm); hm->h.size = sizeof(*hm);
/*printk(KERN_INFO "message size %d\n", hm->h.wSize); */ /* printk(KERN_INFO "message size %d\n", hm->h.wSize); */
uncopied_bytes = copy_from_user(hm, puhm, hm->h.size); uncopied_bytes = copy_from_user(hm, puhm, hm->h.size);
if (uncopied_bytes) { if (uncopied_bytes) {
...@@ -156,7 +157,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -156,7 +157,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
} }
pa = &adapters[hm->h.adapter_index]; pa = &adapters[hm->h.adapter_index];
hr->h.size = 0; hr->h.size = res_max_size;
if (hm->h.object == HPI_OBJ_SUBSYSTEM) { if (hm->h.object == HPI_OBJ_SUBSYSTEM) {
switch (hm->h.function) { switch (hm->h.function) {
case HPI_SUBSYS_CREATE_ADAPTER: case HPI_SUBSYS_CREATE_ADAPTER:
...@@ -216,7 +217,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -216,7 +217,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
*/ */
if (pa->buffer_size < size) { if (pa->buffer_size < size) {
HPI_DEBUG_LOG(DEBUG, HPI_DEBUG_LOG(DEBUG,
"realloc adapter %d stream " "Realloc adapter %d stream "
"buffer from %zd to %d\n", "buffer from %zd to %d\n",
hm->h.adapter_index, hm->h.adapter_index,
pa->buffer_size, size); pa->buffer_size, size);
...@@ -259,7 +260,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -259,7 +260,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
copy_from_user(pa->p_buffer, ptr, size); copy_from_user(pa->p_buffer, ptr, size);
if (uncopied_bytes) if (uncopied_bytes)
HPI_DEBUG_LOG(WARNING, HPI_DEBUG_LOG(WARNING,
"missed %d of %d " "Missed %d of %d "
"bytes from user\n", uncopied_bytes, "bytes from user\n", uncopied_bytes,
size); size);
} }
...@@ -271,7 +272,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -271,7 +272,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
copy_to_user(ptr, pa->p_buffer, size); copy_to_user(ptr, pa->p_buffer, size);
if (uncopied_bytes) if (uncopied_bytes)
HPI_DEBUG_LOG(WARNING, HPI_DEBUG_LOG(WARNING,
"missed %d of %d " "bytes to user\n", "Missed %d of %d " "bytes to user\n",
uncopied_bytes, size); uncopied_bytes, size);
} }
...@@ -290,9 +291,9 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ...@@ -290,9 +291,9 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
if (hr->h.size > res_max_size) { if (hr->h.size > res_max_size) {
HPI_DEBUG_LOG(ERROR, "response too big %d %d\n", hr->h.size, HPI_DEBUG_LOG(ERROR, "response too big %d %d\n", hr->h.size,
res_max_size); res_max_size);
/*HPI_DEBUG_MESSAGE(ERROR, hm); */ hr->h.error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
err = -EFAULT; hr->h.specific_error = hr->h.size;
goto out; hr->h.size = sizeof(hr->h);
} }
uncopied_bytes = copy_to_user(puhr, hr, hr->h.size); uncopied_bytes = copy_to_user(puhr, hr, hr->h.size);
...@@ -320,18 +321,26 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev, ...@@ -320,18 +321,26 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
memset(&adapter, 0, sizeof(adapter)); memset(&adapter, 0, sizeof(adapter));
printk(KERN_DEBUG "probe PCI device (%04x:%04x,%04x:%04x,%04x)\n", dev_printk(KERN_DEBUG, &pci_dev->dev,
pci_dev->vendor, pci_dev->device, pci_dev->subsystem_vendor, "probe %04x:%04x,%04x:%04x,%04x\n", pci_dev->vendor,
pci_dev->device, pci_dev->subsystem_vendor,
pci_dev->subsystem_device, pci_dev->devfn); pci_dev->subsystem_device, pci_dev->devfn);
if (pci_enable_device(pci_dev) < 0) {
dev_printk(KERN_ERR, &pci_dev->dev,
"pci_enable_device failed, disabling device\n");
return -EIO;
}
pci_set_master(pci_dev); /* also sets latency timer if < 16 */
hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
HPI_SUBSYS_CREATE_ADAPTER); HPI_SUBSYS_CREATE_ADAPTER);
hpi_init_response(&hr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_CREATE_ADAPTER, hpi_init_response(&hr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_CREATE_ADAPTER,
HPI_ERROR_PROCESSING_MESSAGE); HPI_ERROR_PROCESSING_MESSAGE);
hm.adapter_index = -1; /* an invalid index */ hm.adapter_index = HPI_ADAPTER_INDEX_INVALID;
/* fill in HPI_PCI information from kernel provided information */
adapter.pci = pci_dev; adapter.pci = pci_dev;
nm = HPI_MAX_ADAPTER_MEM_SPACES; nm = HPI_MAX_ADAPTER_MEM_SPACES;
...@@ -359,19 +368,7 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev, ...@@ -359,19 +368,7 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
pci.ap_mem_base[idx] = adapter.ap_remapped_mem_base[idx]; pci.ap_mem_base[idx] = adapter.ap_remapped_mem_base[idx];
} }
/* could replace Pci with direct pointer to pci_dev for linux pci.pci_dev = pci_dev;
Instead wrap accessor functions for IDs etc.
Would it work for windows?
*/
pci.bus_number = pci_dev->bus->number;
pci.vendor_id = (u16)pci_dev->vendor;
pci.device_id = (u16)pci_dev->device;
pci.subsys_vendor_id = (u16)(pci_dev->subsystem_vendor & 0xffff);
pci.subsys_device_id = (u16)(pci_dev->subsystem_device & 0xffff);
pci.device_number = pci_dev->devfn;
pci.interrupt = pci_dev->irq;
pci.p_os_data = pci_dev;
hm.u.s.resource.bus_type = HPI_BUS_PCI; hm.u.s.resource.bus_type = HPI_BUS_PCI;
hm.u.s.resource.r.pci = &pci; hm.u.s.resource.r.pci = &pci;
...@@ -407,8 +404,9 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev, ...@@ -407,8 +404,9 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
mutex_init(&adapters[adapter.index].mutex); mutex_init(&adapters[adapter.index].mutex);
pci_set_drvdata(pci_dev, &adapters[adapter.index]); pci_set_drvdata(pci_dev, &adapters[adapter.index]);
printk(KERN_INFO "probe found adapter ASI%04X HPI index #%d.\n", dev_printk(KERN_INFO, &pci_dev->dev,
adapter.type, adapter.index); "probe succeeded for ASI%04X HPI index %d\n", adapter.type,
adapter.index);
return 0; return 0;
...@@ -439,7 +437,8 @@ void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev) ...@@ -439,7 +437,8 @@ void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev)
hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
HPI_SUBSYS_DELETE_ADAPTER); HPI_SUBSYS_DELETE_ADAPTER);
hm.adapter_index = pa->index; hm.obj_index = pa->index;
hm.adapter_index = HPI_ADAPTER_INDEX_INVALID;
hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL); hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
/* unmap PCI memory space, mapped during device init. */ /* unmap PCI memory space, mapped during device init. */
...@@ -456,14 +455,12 @@ void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev) ...@@ -456,14 +455,12 @@ void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev)
} }
pci_set_drvdata(pci_dev, NULL); pci_set_drvdata(pci_dev, NULL);
/* if (1)
printk(KERN_INFO "PCI device (%04x:%04x,%04x:%04x,%04x)," dev_printk(KERN_INFO, &pci_dev->dev,
" HPI index # %d, removed.\n", "remove %04x:%04x,%04x:%04x,%04x," " HPI index %d.\n",
pci_dev->vendor, pci_dev->device, pci_dev->vendor, pci_dev->device,
pci_dev->subsystem_vendor, pci_dev->subsystem_vendor, pci_dev->subsystem_device,
pci_dev->subsystem_device, pci_dev->devfn, pci_dev->devfn, pa->index);
pa->index);
*/
} }
void __init asihpi_init(void) void __init asihpi_init(void)
......
...@@ -135,7 +135,7 @@ static inline void cond_unlock(struct hpios_spinlock *l) ...@@ -135,7 +135,7 @@ static inline void cond_unlock(struct hpios_spinlock *l)
#define hpios_msgxlock_init(obj) spin_lock_init(&(obj)->lock) #define hpios_msgxlock_init(obj) spin_lock_init(&(obj)->lock)
#define hpios_msgxlock_lock(obj) cond_lock(obj) #define hpios_msgxlock_lock(obj) cond_lock(obj)
#define hpios_msgxlock_un_lock(obj) cond_unlock(obj) #define hpios_msgxlock_unlock(obj) cond_unlock(obj)
#define hpios_dsplock_init(obj) spin_lock_init(&(obj)->dsp_lock.lock) #define hpios_dsplock_init(obj) spin_lock_init(&(obj)->dsp_lock.lock)
#define hpios_dsplock_lock(obj) cond_lock(&(obj)->dsp_lock) #define hpios_dsplock_lock(obj) cond_lock(&(obj)->dsp_lock)
...@@ -148,7 +148,7 @@ static inline void cond_unlock(struct hpios_spinlock *l) ...@@ -148,7 +148,7 @@ static inline void cond_unlock(struct hpios_spinlock *l)
#define HPI_ALIST_LOCKING #define HPI_ALIST_LOCKING
#define hpios_alistlock_init(obj) spin_lock_init(&((obj)->list_lock.lock)) #define hpios_alistlock_init(obj) spin_lock_init(&((obj)->list_lock.lock))
#define hpios_alistlock_lock(obj) spin_lock(&((obj)->list_lock.lock)) #define hpios_alistlock_lock(obj) spin_lock(&((obj)->list_lock.lock))
#define hpios_alistlock_un_lock(obj) spin_unlock(&((obj)->list_lock.lock)) #define hpios_alistlock_unlock(obj) spin_unlock(&((obj)->list_lock.lock))
struct hpi_adapter { struct hpi_adapter {
/* mutex prevents contention for one card /* mutex prevents contention for one card
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment