/alps/pcitool

To get this branch, use:
bzr branch http://darksoft.org/webbzr/alps/pcitool

« back to all changes in this revision

Viewing changes to driver/base.c

  • Committer: Vasilii Chernov
  • Date: 2016-03-02 07:48:24 UTC
  • mfrom: (359 pcitool)
  • mto: This revision was merged to the branch mainline in revision 367.
  • Revision ID: vchernov@inr.ru-20160302074824-gcpwar3f33n5353q
1. Merge with http://ufo.kit.edu/ufo/log/csa/pcitool 359 revision
2. Move api_server to html server

Show diffs side-by-side

added added

removed removed

Lines of Context:
210
210
/* Module class */
211
211
static struct class_compat *pcidriver_class;
212
212
 
 
213
#ifdef PCIDRIVER_DUMMY_DEVICE
 
214
pcidriver_privdata_t *pcidriver_privdata = NULL;
 
215
#endif /* PCIDRIVER_DUMMY_DEVICE */
 
216
 
213
217
/**
214
218
 *
215
219
 * Called when loading the driver
217
221
 */
218
222
static int __init pcidriver_init(void)
219
223
{
220
 
        int err;
 
224
        int err = 0;
221
225
 
222
226
        /* Initialize the device count */
223
227
        atomic_set(&pcidriver_deviceCount, 0);
239
243
 
240
244
        /* Register PCI driver. This function returns the number of devices on some
241
245
         * systems, therefore check for errors as < 0. */
 
246
#ifdef PCIDRIVER_DUMMY_DEVICE
 
247
        if ((err = pcidriver_probe(NULL, NULL)) < 0) {
 
248
#else /* PCIDRIVER_DUMMY_DEVICE */
242
249
        if ((err = pci_register_driver(&pcidriver_driver)) < 0) {
 
250
#endif /* PCIDRIVER_DUMMY_DEVICE */
243
251
                mod_info("Couldn't register PCI driver. Module not loaded.\n");
244
252
                goto init_pcireg_fail;
245
253
        }
268
276
 */
269
277
static void pcidriver_exit(void)
270
278
{
 
279
#ifdef PCIDRIVER_DUMMY_DEVICE
 
280
        pcidriver_remove(NULL);
 
281
#else
271
282
        pci_unregister_driver(&pcidriver_driver);
 
283
#endif /* PCIDRIVER_DUMMY_DEVICE */
 
284
 
272
285
        unregister_chrdev_region(pcidriver_devt, MAXDEVICES);
273
286
 
274
287
        if (pcidriver_class != NULL)
286
299
 * Will be registered at module init.
287
300
 *
288
301
 */
 
302
#ifndef PCIDRIVER_DUMMY_DEVICE
289
303
static struct pci_driver pcidriver_driver = {
290
304
        .name = MODNAME,
291
305
        .id_table = pcidriver_ids,
292
306
        .probe = pcidriver_probe,
293
307
        .remove = pcidriver_remove,
294
308
};
 
309
#endif /* ! PCIDRIVER_DUMMY_DEVICE */
295
310
 
296
311
/**
297
312
 *
301
316
 */
302
317
static int __devinit pcidriver_probe(struct pci_dev *pdev, const struct pci_device_id *id)
303
318
{
304
 
        int err;
 
319
        int err = 0;
305
320
        int devno;
306
321
        pcidriver_privdata_t *privdata;
307
322
        int devid;
311
326
         *
312
327
         * However, there is some difference in the interrupt handling functions.
313
328
         */
 
329
#ifdef PCIDRIVER_DUMMY_DEVICE
 
330
        mod_info("Emulated device\n");
 
331
#else /* PCIDRIVER_DUMMY_DEVICE */
314
332
        if (id->vendor == PCIE_XILINX_VENDOR_ID) {
315
333
            if (id->device == PCIE_ML605_DEVICE_ID) {
316
334
                mod_info("Found ML605 board at %s\n", dev_name(&pdev->dev));
323
341
            }
324
342
        } else {
325
343
            /* It is something else */
326
 
            mod_info( "Found unknown board (%x:%x) at %s\n", id->vendor, id->device, dev_name(&pdev->dev));
 
344
            mod_info("Found unknown board (%x:%x) at %s\n", id->vendor, id->device, dev_name(&pdev->dev));
327
345
        }
328
346
 
329
347
        /* Enable the device */
343
361
 
344
362
        /* Set Memory-Write-Invalidate support */
345
363
        if ((err = pci_set_mwi(pdev)) != 0)
346
 
                mod_info("MWI not supported. Continue without enabling MWI.\n");
 
364
            mod_info("MWI not supported. Continue without enabling MWI.\n");
 
365
#endif /* PCIDRIVER_DUMMY_DEVICE */
347
366
 
348
367
        /* Get / Increment the device id */
349
368
        devid = atomic_inc_return(&pcidriver_deviceCount) - 1;
367
386
        spin_lock_init(&(privdata->umemlist_lock));
368
387
        atomic_set(&privdata->umem_count, 0);
369
388
 
370
 
        pci_set_drvdata( pdev, privdata );
 
389
#ifdef PCIDRIVER_DUMMY_DEVICE
 
390
        pcidriver_privdata = privdata;
 
391
#else /* PCIDRIVER_DUMMY_DEVICE */
 
392
        pci_set_drvdata(pdev, privdata);
371
393
        privdata->pdev = pdev;
 
394
#endif /* PCIDRIVER_DUMMY_DEVICE */
372
395
 
373
396
        /* Device add to sysfs */
374
397
        devno = MKDEV(MAJOR(pcidriver_devt), MINOR(pcidriver_devt) + devid);
375
398
        privdata->devno = devno;
376
 
        if (pcidriver_class != NULL) {
377
 
                /* FIXME: some error checking missing here */
378
 
                privdata->class_dev = class_device_create(pcidriver_class, NULL, devno, &(pdev->dev), NODENAMEFMT, MINOR(pcidriver_devt) + devid, privdata);
379
 
                class_set_devdata( privdata->class_dev, privdata );
380
 
                mod_info("Device /dev/%s%d added\n",NODENAME,MINOR(pcidriver_devt) + devid);
381
 
        }
382
 
 
 
399
 
 
400
        /* FIXME: some error checking missing here */
 
401
#ifdef PCIDRIVER_DUMMY_DEVICE
 
402
        privdata->class_dev = class_device_create(pcidriver_class, NULL, devno, NULL, NODENAMEFMT, MINOR(pcidriver_devt) + devid, privdata);
 
403
#else /* PCIDRIVER_DUMMY_DEVICE */
 
404
        privdata->class_dev = class_device_create(pcidriver_class, NULL, devno, &(pdev->dev), NODENAMEFMT, MINOR(pcidriver_devt) + devid, privdata);
 
405
#endif /* PCIDRIVER_DUMMY_DEVICE */
 
406
        class_set_devdata( privdata->class_dev, privdata );
 
407
        mod_info("Device /dev/%s%d added\n",NODENAME,MINOR(pcidriver_devt) + devid);
 
408
 
 
409
#ifndef PCIDRIVER_DUMMY_DEVICE
383
410
        /* Setup mmaped BARs into kernel space */
384
411
        if ((err = pcidriver_probe_irq(privdata)) != 0)
385
412
                goto probe_irq_probe_fail;
 
413
#endif /* ! PCIDRIVER_DUMMY_DEVICE */
386
414
 
387
415
        /* Populate sysfs attributes for the class device */
388
416
        /* TODO: correct errorhandling. ewww. must remove the files in reversed order :-( */
419
447
 
420
448
probe_device_create_fail:
421
449
probe_cdevadd_fail:
 
450
#ifndef PCIDRIVER_DUMMY_DEVICE
422
451
probe_irq_probe_fail:
423
452
        pcidriver_irq_unmap_bars(privdata);
 
453
#endif /* ! PCIDRIVER_DUMMY_DEVICE */
424
454
        kfree(privdata);
425
455
probe_nomem:
426
456
        atomic_dec(&pcidriver_deviceCount);
427
457
probe_maxdevices_fail:
 
458
#ifndef PCIDRIVER_DUMMY_DEVICE
428
459
probe_dma_fail:
429
460
        pci_disable_device(pdev);
430
461
probe_pcien_fail:
 
462
#endif /* ! PCIDRIVER_DUMMY_DEVICE */
431
463
        return err;
432
464
}
433
465
 
440
472
{
441
473
        pcidriver_privdata_t *privdata;
442
474
 
 
475
#ifdef PCIDRIVER_DUMMY_DEVICE
 
476
        privdata = pcidriver_privdata;
 
477
        pcidriver_privdata = NULL;
 
478
#else /* PCIDRIVER_DUMMY_DEVICE */
443
479
        /* Get private data from the device */
444
480
        privdata = pci_get_drvdata(pdev);
 
481
#endif /* PCIDRIVER_DUMMY_DEVICE */
445
482
 
446
483
        /* Removing sysfs attributes from class device */
447
484
        #define sysfs_attr(name) do { \
465
502
        /* Free all allocated kmem buffers before leaving */
466
503
        pcidriver_kmem_free_all( privdata );
467
504
 
468
 
#ifdef ENABLE_IRQ
 
505
#ifndef PCIDRIVER_DUMMY_DEVICE
 
506
# ifdef ENABLE_IRQ
469
507
        pcidriver_remove_irq(privdata);
470
 
#endif
 
508
# endif
 
509
#endif /* ! PCIDRIVER_DUMMY_DEVICE */
471
510
 
472
511
        /* Removing Character device */
473
512
        cdev_del(&(privdata->cdev));
478
517
        /* Releasing privdata */
479
518
        kfree(privdata);
480
519
 
 
520
#ifdef PCIDRIVER_DUMMY_DEVICE
 
521
        mod_info("Device at " NODENAMEFMT " removed\n", 0);
 
522
#else /* PCIDRIVER_DUMMY_DEVICE */
481
523
        /* Disabling PCI device */
482
524
        pci_disable_device(pdev);
483
 
 
484
525
        mod_info("Device at %s removed\n", dev_name(&pdev->dev));
 
526
#endif /* PCIDRIVER_DUMMY_DEVICE */
 
527
 
485
528
}
486
529
 
487
530
/*************************************************************************/
613
656
/* Internal driver functions */
614
657
int pcidriver_mmap_pci(pcidriver_privdata_t *privdata, struct vm_area_struct *vmap, int bar)
615
658
{
 
659
#ifdef PCIDRIVER_DUMMY_DEVICE
 
660
        return -ENXIO;
 
661
#else /* PCIDRIVER_DUMMY_DEVICE */
616
662
        int ret = 0;
617
663
        unsigned long bar_addr;
618
664
        unsigned long bar_length, vma_size;
620
666
 
621
667
        mod_info_dbg("Entering mmap_pci\n");
622
668
 
 
669
 
623
670
        /* Get info of the BAR to be mapped */
624
671
        bar_addr = pci_resource_start(privdata->pdev, bar);
625
672
        bar_length = pci_resource_len(privdata->pdev, bar);
680
727
        }
681
728
 
682
729
        return 0;       /* success */
 
730
#endif /* PCIDRIVER_DUMMY_DEVICE */
683
731
}