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.c90
1 files changed, 46 insertions, 44 deletions
diff --git a/sound/pci/asihpi/hpioctl.c b/sound/pci/asihpi/hpioctl.c
index 22dbd91811a4..cd624f13ff8e 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) {
@@ -155,8 +156,13 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
155 goto out; 156 goto out;
156 } 157 }
157 158
159 if (hm->h.adapter_index >= HPI_MAX_ADAPTERS) {
160 err = -EINVAL;
161 goto out;
162 }
163
158 pa = &adapters[hm->h.adapter_index]; 164 pa = &adapters[hm->h.adapter_index];
159 hr->h.size = 0; 165 hr->h.size = res_max_size;
160 if (hm->h.object == HPI_OBJ_SUBSYSTEM) { 166 if (hm->h.object == HPI_OBJ_SUBSYSTEM) {
161 switch (hm->h.function) { 167 switch (hm->h.function) {
162 case HPI_SUBSYS_CREATE_ADAPTER: 168 case HPI_SUBSYS_CREATE_ADAPTER:
@@ -216,7 +222,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
216 */ 222 */
217 if (pa->buffer_size < size) { 223 if (pa->buffer_size < size) {
218 HPI_DEBUG_LOG(DEBUG, 224 HPI_DEBUG_LOG(DEBUG,
219 "realloc adapter %d stream " 225 "Realloc adapter %d stream "
220 "buffer from %zd to %d\n", 226 "buffer from %zd to %d\n",
221 hm->h.adapter_index, 227 hm->h.adapter_index,
222 pa->buffer_size, size); 228 pa->buffer_size, size);
@@ -259,7 +265,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
259 copy_from_user(pa->p_buffer, ptr, size); 265 copy_from_user(pa->p_buffer, ptr, size);
260 if (uncopied_bytes) 266 if (uncopied_bytes)
261 HPI_DEBUG_LOG(WARNING, 267 HPI_DEBUG_LOG(WARNING,
262 "missed %d of %d " 268 "Missed %d of %d "
263 "bytes from user\n", uncopied_bytes, 269 "bytes from user\n", uncopied_bytes,
264 size); 270 size);
265 } 271 }
@@ -271,7 +277,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
271 copy_to_user(ptr, pa->p_buffer, size); 277 copy_to_user(ptr, pa->p_buffer, size);
272 if (uncopied_bytes) 278 if (uncopied_bytes)
273 HPI_DEBUG_LOG(WARNING, 279 HPI_DEBUG_LOG(WARNING,
274 "missed %d of %d " "bytes to user\n", 280 "Missed %d of %d " "bytes to user\n",
275 uncopied_bytes, size); 281 uncopied_bytes, size);
276 } 282 }
277 283
@@ -290,9 +296,9 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
290 if (hr->h.size > res_max_size) { 296 if (hr->h.size > res_max_size) {
291 HPI_DEBUG_LOG(ERROR, "response too big %d %d\n", hr->h.size, 297 HPI_DEBUG_LOG(ERROR, "response too big %d %d\n", hr->h.size,
292 res_max_size); 298 res_max_size);
293 /*HPI_DEBUG_MESSAGE(ERROR, hm); */ 299 hr->h.error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
294 err = -EFAULT; 300 hr->h.specific_error = hr->h.size;
295 goto out; 301 hr->h.size = sizeof(hr->h);
296 } 302 }
297 303
298 uncopied_bytes = copy_to_user(puhr, hr, hr->h.size); 304 uncopied_bytes = copy_to_user(puhr, hr, hr->h.size);
@@ -320,18 +326,26 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
320 326
321 memset(&adapter, 0, sizeof(adapter)); 327 memset(&adapter, 0, sizeof(adapter));
322 328
323 printk(KERN_DEBUG "probe PCI device (%04x:%04x,%04x:%04x,%04x)\n", 329 dev_printk(KERN_DEBUG, &pci_dev->dev,
324 pci_dev->vendor, pci_dev->device, pci_dev->subsystem_vendor, 330 "probe %04x:%04x,%04x:%04x,%04x\n", pci_dev->vendor,
331 pci_dev->device, pci_dev->subsystem_vendor,
325 pci_dev->subsystem_device, pci_dev->devfn); 332 pci_dev->subsystem_device, pci_dev->devfn);
326 333
334 if (pci_enable_device(pci_dev) < 0) {
335 dev_printk(KERN_ERR, &pci_dev->dev,
336 "pci_enable_device failed, disabling device\n");
337 return -EIO;
338 }
339
340 pci_set_master(pci_dev); /* also sets latency timer if < 16 */
341
327 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, 342 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
328 HPI_SUBSYS_CREATE_ADAPTER); 343 HPI_SUBSYS_CREATE_ADAPTER);
329 hpi_init_response(&hr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_CREATE_ADAPTER, 344 hpi_init_response(&hr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_CREATE_ADAPTER,
330 HPI_ERROR_PROCESSING_MESSAGE); 345 HPI_ERROR_PROCESSING_MESSAGE);
331 346
332 hm.adapter_index = -1; /* an invalid index */ 347 hm.adapter_index = HPI_ADAPTER_INDEX_INVALID;
333 348
334 /* fill in HPI_PCI information from kernel provided information */
335 adapter.pci = pci_dev; 349 adapter.pci = pci_dev;
336 350
337 nm = HPI_MAX_ADAPTER_MEM_SPACES; 351 nm = HPI_MAX_ADAPTER_MEM_SPACES;
@@ -359,19 +373,7 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
359 pci.ap_mem_base[idx] = adapter.ap_remapped_mem_base[idx]; 373 pci.ap_mem_base[idx] = adapter.ap_remapped_mem_base[idx];
360 } 374 }
361 375
362 /* could replace Pci with direct pointer to pci_dev for linux 376 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; 377 hm.u.s.resource.bus_type = HPI_BUS_PCI;
376 hm.u.s.resource.r.pci = &pci; 378 hm.u.s.resource.r.pci = &pci;
377 379
@@ -392,10 +394,10 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
392 } 394 }
393 395
394 adapter.index = hr.u.s.adapter_index; 396 adapter.index = hr.u.s.adapter_index;
395 adapter.type = hr.u.s.aw_adapter_list[adapter.index]; 397 adapter.type = hr.u.s.adapter_type;
396 hm.adapter_index = adapter.index; 398 hm.adapter_index = adapter.index;
397 399
398 err = hpi_adapter_open(NULL, adapter.index); 400 err = hpi_adapter_open(adapter.index);
399 if (err) 401 if (err)
400 goto err; 402 goto err;
401 403
@@ -407,8 +409,9 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
407 mutex_init(&adapters[adapter.index].mutex); 409 mutex_init(&adapters[adapter.index].mutex);
408 pci_set_drvdata(pci_dev, &adapters[adapter.index]); 410 pci_set_drvdata(pci_dev, &adapters[adapter.index]);
409 411
410 printk(KERN_INFO "probe found adapter ASI%04X HPI index #%d.\n", 412 dev_printk(KERN_INFO, &pci_dev->dev,
411 adapter.type, adapter.index); 413 "probe succeeded for ASI%04X HPI index %d\n", adapter.type,
414 adapter.index);
412 415
413 return 0; 416 return 0;
414 417
@@ -439,7 +442,8 @@ void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev)
439 442
440 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM, 443 hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
441 HPI_SUBSYS_DELETE_ADAPTER); 444 HPI_SUBSYS_DELETE_ADAPTER);
442 hm.adapter_index = pa->index; 445 hm.obj_index = pa->index;
446 hm.adapter_index = HPI_ADAPTER_INDEX_INVALID;
443 hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL); 447 hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
444 448
445 /* unmap PCI memory space, mapped during device init. */ 449 /* unmap PCI memory space, mapped during device init. */
@@ -450,20 +454,18 @@ void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev)
450 } 454 }
451 } 455 }
452 456
453 if (pa->p_buffer) { 457 if (pa->p_buffer)
454 pa->buffer_size = 0;
455 vfree(pa->p_buffer); 458 vfree(pa->p_buffer);
456 }
457 459
458 pci_set_drvdata(pci_dev, NULL); 460 pci_set_drvdata(pci_dev, NULL);
459 /* 461 if (1)
460 printk(KERN_INFO "PCI device (%04x:%04x,%04x:%04x,%04x)," 462 dev_printk(KERN_INFO, &pci_dev->dev,
461 " HPI index # %d, removed.\n", 463 "remove %04x:%04x,%04x:%04x,%04x," " HPI index %d.\n",
462 pci_dev->vendor, pci_dev->device, 464 pci_dev->vendor, pci_dev->device,
463 pci_dev->subsystem_vendor, 465 pci_dev->subsystem_vendor, pci_dev->subsystem_device,
464 pci_dev->subsystem_device, pci_dev->devfn, 466 pci_dev->devfn, pa->index);
465 pa->index); 467
466 */ 468 memset(pa, 0, sizeof(*pa));
467} 469}
468 470
469void __init asihpi_init(void) 471void __init asihpi_init(void)