Deleted Added
full compact
pci.h (276749) pci.h (277302)
1/*-
2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 395 unchanged lines hidden (view full) ---

404static inline int
405pci_write_config_dword(struct pci_dev *pdev, int where, u32 val)
406{
407
408 pci_write_config(pdev->dev.bsddev, where, val, 4);
409 return (0);
410}
411
1/*-
2 * Copyright (c) 2010 Isilon Systems, Inc.
3 * Copyright (c) 2010 iX Systems, Inc.
4 * Copyright (c) 2010 Panasas, Inc.
5 * Copyright (c) 2013, 2014 Mellanox Technologies, Ltd.
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 395 unchanged lines hidden (view full) ---

404static inline int
405pci_write_config_dword(struct pci_dev *pdev, int where, u32 val)
406{
407
408 pci_write_config(pdev->dev.bsddev, where, val, 4);
409 return (0);
410}
411
412static struct pci_driver *
413linux_pci_find(device_t dev, const struct pci_device_id **idp)
414{
415 const struct pci_device_id *id;
416 struct pci_driver *pdrv;
417 uint16_t vendor;
418 uint16_t device;
412extern int pci_register_driver(struct pci_driver *pdrv);
413extern void pci_unregister_driver(struct pci_driver *pdrv);
419
414
420 vendor = pci_get_vendor(dev);
421 device = pci_get_device(dev);
422
423 spin_lock(&pci_lock);
424 list_for_each_entry(pdrv, &pci_drivers, links) {
425 for (id = pdrv->id_table; id->vendor != 0; id++) {
426 if (vendor == id->vendor && device == id->device) {
427 *idp = id;
428 spin_unlock(&pci_lock);
429 return (pdrv);
430 }
431 }
432 }
433 spin_unlock(&pci_lock);
434 return (NULL);
435}
436
437static inline int
438linux_pci_probe(device_t dev)
439{
440 const struct pci_device_id *id;
441 struct pci_driver *pdrv;
442
443 if ((pdrv = linux_pci_find(dev, &id)) == NULL)
444 return (ENXIO);
445 if (device_get_driver(dev) != &pdrv->driver)
446 return (ENXIO);
447 device_set_desc(dev, pdrv->name);
448 return (0);
449}
450
451static inline int
452linux_pci_attach(device_t dev)
453{
454 struct resource_list_entry *rle;
455 struct pci_dev *pdev;
456 struct pci_driver *pdrv;
457 const struct pci_device_id *id;
458 int error;
459
460 pdrv = linux_pci_find(dev, &id);
461 pdev = device_get_softc(dev);
462 pdev->dev.parent = &linux_rootdev;
463 pdev->dev.bsddev = dev;
464 INIT_LIST_HEAD(&pdev->dev.irqents);
465 pdev->device = id->device;
466 pdev->vendor = id->vendor;
467 pdev->dev.dma_mask = &pdev->dma_mask;
468 pdev->pdrv = pdrv;
469 kobject_init(&pdev->dev.kobj, &dev_ktype);
470 kobject_set_name(&pdev->dev.kobj, device_get_nameunit(dev));
471 kobject_add(&pdev->dev.kobj, &linux_rootdev.kobj,
472 kobject_name(&pdev->dev.kobj));
473 rle = _pci_get_rle(pdev, SYS_RES_IRQ, 0);
474 if (rle)
475 pdev->dev.irq = rle->start;
476 else
477 pdev->dev.irq = 0;
478 pdev->irq = pdev->dev.irq;
479 mtx_unlock(&Giant);
480 spin_lock(&pci_lock);
481 list_add(&pdev->links, &pci_devices);
482 spin_unlock(&pci_lock);
483 error = pdrv->probe(pdev, id);
484 mtx_lock(&Giant);
485 if (error) {
486 spin_lock(&pci_lock);
487 list_del(&pdev->links);
488 spin_unlock(&pci_lock);
489 put_device(&pdev->dev);
490 return (-error);
491 }
492 return (0);
493}
494
495static inline int
496linux_pci_detach(device_t dev)
497{
498 struct pci_dev *pdev;
499
500 pdev = device_get_softc(dev);
501 mtx_unlock(&Giant);
502 pdev->pdrv->remove(pdev);
503 mtx_lock(&Giant);
504 spin_lock(&pci_lock);
505 list_del(&pdev->links);
506 spin_unlock(&pci_lock);
507 put_device(&pdev->dev);
508
509 return (0);
510}
511
512static device_method_t pci_methods[] = {
513 DEVMETHOD(device_probe, linux_pci_probe),
514 DEVMETHOD(device_attach, linux_pci_attach),
515 DEVMETHOD(device_detach, linux_pci_detach),
516 {0, 0}
517};
518
519static inline int
520pci_register_driver(struct pci_driver *pdrv)
521{
522 devclass_t bus;
523 int error;
524
525 spin_lock(&pci_lock);
526 list_add(&pdrv->links, &pci_drivers);
527 spin_unlock(&pci_lock);
528 bus = devclass_find("pci");
529 pdrv->driver.name = pdrv->name;
530 pdrv->driver.methods = pci_methods;
531 pdrv->driver.size = sizeof(struct pci_dev);
532 mtx_lock(&Giant);
533 error = devclass_add_driver(bus, &pdrv->driver, BUS_PASS_DEFAULT,
534 &pdrv->bsdclass);
535 mtx_unlock(&Giant);
536 if (error)
537 return (-error);
538 return (0);
539}
540
541static inline void
542pci_unregister_driver(struct pci_driver *pdrv)
543{
544 devclass_t bus;
545
546 list_del(&pdrv->links);
547 bus = devclass_find("pci");
548 mtx_lock(&Giant);
549 devclass_delete_driver(bus, &pdrv->driver);
550 mtx_unlock(&Giant);
551}
552
553struct msix_entry {
554 int entry;
555 int vector;
556};
557
558/*
559 * Enable msix, positive errors indicate actual number of available
560 * vectors. Negative errors are failures.

--- 271 unchanged lines hidden (view full) ---

832 return -EINVAL;
833
834 if (!pcie_capability_reg_implemented(dev, pos))
835 return 0;
836
837 return pci_write_config_word(dev, pci_pcie_cap(dev) + pos, val);
838}
839
415struct msix_entry {
416 int entry;
417 int vector;
418};
419
420/*
421 * Enable msix, positive errors indicate actual number of available
422 * vectors. Negative errors are failures.

--- 271 unchanged lines hidden (view full) ---

694 return -EINVAL;
695
696 if (!pcie_capability_reg_implemented(dev, pos))
697 return 0;
698
699 return pci_write_config_word(dev, pci_pcie_cap(dev) + pos, val);
700}
701
840
841#endif /* _LINUX_PCI_H_ */
702#endif /* _LINUX_PCI_H_ */