aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/asihpi/hpioctl.c
diff options
context:
space:
mode:
Diffstat (limited to 'sound/pci/asihpi/hpioctl.c')
-rw-r--r--sound/pci/asihpi/hpioctl.c75
1 files changed, 36 insertions, 39 deletions
diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c
index 22dbd91811a4..dd8cadf1e686 100644
--- a/sound/pci/asihpi/hpioctl.c
+++ b/sound/pci/asihpi/hpioctl.c
@@ -30,6 +30,7 @@ Common Linux HPI ioctl and module probe/remove functions
30#include <linux/slab.h> 30#include <linux/slab.h>
31#include <linux/moduleparam.h> 31#include <linux/moduleparam.h>
32#include <asm/uaccess.h> 32#include <asm/uaccess.h>
33#include <linux/pci.h>
33#include <linux/stringify.h> 34#include <linux/stringify.h>
34 35
35#ifdef MODULE_FIRMWARE 36#ifdef MODULE_FIRMWARE
@@ -45,7 +46,7 @@ MODULE_FIRMWARE("asihpi/dsp8900.bin");
45static int prealloc_stream_buf; 46static int prealloc_stream_buf;
46module_param(prealloc_stream_buf, int, S_IRUGO); 47module_param(prealloc_stream_buf, int, S_IRUGO);
47MODULE_PARM_DESC(prealloc_stream_buf, 48MODULE_PARM_DESC(prealloc_stream_buf,
48 "preallocate size for per-adapter stream buffer"); 49 "Preallocate size for per-adapter stream buffer");
49 50
50/* Allow the debug level to be changed after module load. 51/* Allow the debug level to be changed after module load.
51 E.g. echo 2 > /sys/module/asihpi/parameters/hpiDebugLevel 52 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 phpi_ioctl_data = (struct hpi_ioctl_linux __user *)arg; 122 phpi_ioctl_data = (struct hpi_ioctl_linux __user *)arg;
122 123
123 /* Read the message and response pointers from user space. */ 124 /* Read the message and response pointers from user space. */
124 if (get_user(puhm, &phpi_ioctl_data->phm) || 125 if (get_user(puhm, &phpi_ioctl_data->phm)
125 get_user(puhr, &phpi_ioctl_data->phr)) { 126 || get_user(puhr, &phpi_ioctl_data->phr)) {
126 err = -EFAULT; 127 err = -EFAULT;
127 goto out; 128 goto out;
128 } 129 }
@@ -135,7 +136,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
135 if (hm->h.size > sizeof(*hm)) 136 if (hm->h.size > sizeof(*hm))
136 hm->h.size = sizeof(*hm); 137 hm->h.size = sizeof(*hm);
137 138
138 /*printk(KERN_INFO "message size %d\n", hm->h.wSize); */ 139 /* printk(KERN_INFO "message size %d\n", hm->h.wSize); */
139 140
140 uncopied_bytes = copy_from_user(hm, puhm, hm->h.size); 141 uncopied_bytes = copy_from_user(hm, puhm, hm->h.size);
141 if (uncopied_bytes) { 142 if (uncopied_bytes) {
@@ -156,7 +157,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
156 } 157 }
157 158
158 pa = &adapters[hm->h.adapter_index]; 159 pa = &adapters[hm->h.adapter_index];
159 hr->h.size = 0; 160 hr->h.size = res_max_size;
160 if (hm->h.object == HPI_OBJ_SUBSYSTEM) { 161 if (hm->h.object == HPI_OBJ_SUBSYSTEM) {
161 switch (hm->h.function) { 162 switch (hm->h.function) {
162 case HPI_SUBSYS_CREATE_ADAPTER: 163 case HPI_SUBSYS_CREATE_ADAPTER:
@@ -216,7 +217,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
216 */ 217 */
217 if (pa->buffer_size < size) { 218 if (pa->buffer_size < size) {
218 HPI_DEBUG_LOG(DEBUG, 219 HPI_DEBUG_LOG(DEBUG,
219 "realloc adapter %d stream " 220 "Realloc adapter %d stream "
220 "buffer from %zd to %d\n", 221 "buffer from %zd to %d\n",
221 hm->h.adapter_index, 222 hm->h.adapter_index,
222 pa->buffer_size, size); 223 pa->buffer_size, size);
@@ -259,7 +260,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
259 copy_from_user(pa->p_buffer, ptr, size); 260 copy_from_user(pa->p_buffer, ptr, size);
260 if (uncopied_bytes) 261 if (uncopied_bytes)
261 HPI_DEBUG_LOG(WARNING, 262 HPI_DEBUG_LOG(WARNING,
262 "missed %d of %d " 263 "Missed %d of %d "
263 "bytes from user\n", uncopied_bytes, 264 "bytes from user\n", uncopied_bytes,
264 size); 265 size);
265 } 266 }
@@ -271,7 +272,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
271 copy_to_user(ptr, pa->p_buffer, size); 272 copy_to_user(ptr, pa->p_buffer, size);
272 if (uncopied_bytes) 273 if (uncopied_bytes)
273 HPI_DEBUG_LOG(WARNING, 274 HPI_DEBUG_LOG(WARNING,
274 "missed %d of %d " "bytes to user\n", 275 "Missed %d of %d " "bytes to user\n",
275 uncopied_bytes, size); 276 uncopied_bytes, size);
276 } 277 }
277 278
@@ -290,9 +291,9 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
290 if (hr->h.size > res_max_size) { 291 if (hr->h.size > res_max_size) {
291 HPI_DEBUG_LOG(ERROR, "response too big %d %d\n", hr->h.size, 292 HPI_DEBUG_LOG(ERROR, "response too big %d %d\n", hr->h.size,
292 res_max_size); 293 res_max_size);
293 /*HPI_DEBUG_MESSAGE(ERROR, hm); */ 294 hr->h.error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
294 err = -EFAULT; 295 hr->h.specific_error = hr->h.size;
295 goto out; 296 hr->h.size = sizeof(hr->h);
296 } 297 }
297 298
298 uncopied_bytes = copy_to_user(puhr, hr, hr->h.size); 299 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 321
321 memset(&adapter, 0, sizeof(adapter)); 322 memset(&adapter, 0, sizeof(adapter));
322 323
323 printk(KERN_DEBUG "probe PCI device (%04x:%04x,%04x:%04x,%04x)\n", 324 dev_printk(KERN_DEBUG, &pci_dev->dev,
324 pci_dev->vendor, pci_dev->device, pci_dev->subsystem_vendor, 325 "probe %04x:%04x,%04x:%04x,%04x\n", pci_dev->vendor,
326 pci_dev->device, pci_dev->subsystem_vendor,
325 pci_dev->subsystem_device, pci_dev->devfn); 327 pci_dev->subsystem_device, pci_dev->devfn);
326 328
329 if (pci_enable_device(pci_dev) < 0) {
330 dev_printk(KERN_ERR, &pci_dev->dev,
331 "pci_enable_device failed, disabling device\n");
332 return -EIO;
333 }
334
335 pci_set_master(pci_dev); /* also sets latency timer if < 16 */
336
327 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, 337 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
328 HPI_SUBSYS_CREATE_ADAPTER); 338 HPI_SUBSYS_CREATE_ADAPTER);
329 hpi_init_response(&hr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_CREATE_ADAPTER, 339 hpi_init_response(&hr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_CREATE_ADAPTER,
330 HPI_ERROR_PROCESSING_MESSAGE); 340 HPI_ERROR_PROCESSING_MESSAGE);
331 341
332 hm.adapter_index = -1; /* an invalid index */ 342 hm.adapter_index = HPI_ADAPTER_INDEX_INVALID;
333 343
334 /* fill in HPI_PCI information from kernel provided information */
335 adapter.pci = pci_dev; 344 adapter.pci = pci_dev;
336 345
337 nm = HPI_MAX_ADAPTER_MEM_SPACES; 346 nm = HPI_MAX_ADAPTER_MEM_SPACES;
@@ -359,19 +368,7 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
359 pci.ap_mem_base[idx] = adapter.ap_remapped_mem_base[idx]; 368 pci.ap_mem_base[idx] = adapter.ap_remapped_mem_base[idx];
360 } 369 }
361 370
362 /* could replace Pci with direct pointer to pci_dev for linux 371 pci.pci_dev = pci_dev;
363 Instead wrap accessor functions for IDs etc.
364 Would it work for windows?
365 */
366 pci.bus_number = pci_dev->bus->number;
367 pci.vendor_id = (u16)pci_dev->vendor;
368 pci.device_id = (u16)pci_dev->device;
369 pci.subsys_vendor_id = (u16)(pci_dev->subsystem_vendor & 0xffff);
370 pci.subsys_device_id = (u16)(pci_dev->subsystem_device & 0xffff);
371 pci.device_number = pci_dev->devfn;
372 pci.interrupt = pci_dev->irq;
373 pci.p_os_data = pci_dev;
374
375 hm.u.s.resource.bus_type = HPI_BUS_PCI; 372 hm.u.s.resource.bus_type = HPI_BUS_PCI;
376 hm.u.s.resource.r.pci = &pci; 373 hm.u.s.resource.r.pci = &pci;
377 374
@@ -407,8 +404,9 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
407 mutex_init(&adapters[adapter.index].mutex); 404 mutex_init(&adapters[adapter.index].mutex);
408 pci_set_drvdata(pci_dev, &adapters[adapter.index]); 405 pci_set_drvdata(pci_dev, &adapters[adapter.index]);
409 406
410 printk(KERN_INFO "probe found adapter ASI%04X HPI index #%d.\n", 407 dev_printk(KERN_INFO, &pci_dev->dev,
411 adapter.type, adapter.index); 408 "probe succeeded for ASI%04X HPI index %d\n", adapter.type,
409 adapter.index);
412 410
413 return 0; 411 return 0;
414 412
@@ -439,7 +437,8 @@ void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev)
439 437
440 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, 438 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
441 HPI_SUBSYS_DELETE_ADAPTER); 439 HPI_SUBSYS_DELETE_ADAPTER);
442 hm.adapter_index = pa->index; 440 hm.obj_index = pa->index;
441 hm.adapter_index = HPI_ADAPTER_INDEX_INVALID;
443 hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL); 442 hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
444 443
445 /* unmap PCI memory space, mapped during device init. */ 444 /* unmap PCI memory space, mapped during device init. */
@@ -456,14 +455,12 @@ void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev)
456 } 455 }
457 456
458 pci_set_drvdata(pci_dev, NULL); 457 pci_set_drvdata(pci_dev, NULL);
459 /* 458 if (1)
460 printk(KERN_INFO "PCI device (%04x:%04x,%04x:%04x,%04x)," 459 dev_printk(KERN_INFO, &pci_dev->dev,
461 " HPI index # %d, removed.\n", 460 "remove %04x:%04x,%04x:%04x,%04x," " HPI index %d.\n",
462 pci_dev->vendor, pci_dev->device, 461 pci_dev->vendor, pci_dev->device,
463 pci_dev->subsystem_vendor, 462 pci_dev->subsystem_vendor, pci_dev->subsystem_device,
464 pci_dev->subsystem_device, pci_dev->devfn, 463 pci_dev->devfn, pa->index);
465 pa->index);
466 */
467} 464}
468 465
469void __init asihpi_init(void) 466void __init asihpi_init(void)