pci.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /*
  2. * Intel I/OAT DMA Linux driver
  3. * Copyright(c) 2007 - 2009 Intel Corporation.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. * more details.
  13. *
  14. * You should have received a copy of the GNU General Public License along with
  15. * this program; if not, write to the Free Software Foundation, Inc.,
  16. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  17. *
  18. * The full GNU General Public License is included in this distribution in
  19. * the file called "COPYING".
  20. *
  21. */
  22. /*
  23. * This driver supports an Intel I/OAT DMA engine, which does asynchronous
  24. * copy operations.
  25. */
  26. #include <linux/init.h>
  27. #include <linux/module.h>
  28. #include <linux/pci.h>
  29. #include <linux/interrupt.h>
  30. #include <linux/dca.h>
  31. #include "dma.h"
  32. #include "registers.h"
  33. #include "hw.h"
  34. MODULE_VERSION(IOAT_DMA_VERSION);
  35. MODULE_LICENSE("GPL");
  36. MODULE_AUTHOR("Intel Corporation");
  37. static struct pci_device_id ioat_pci_tbl[] = {
  38. /* I/OAT v1 platforms */
  39. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT) },
  40. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_CNB) },
  41. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SCNB) },
  42. { PCI_DEVICE(PCI_VENDOR_ID_UNISYS, PCI_DEVICE_ID_UNISYS_DMA_DIRECTOR) },
  43. /* I/OAT v2 platforms */
  44. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SNB) },
  45. /* I/OAT v3 platforms */
  46. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG0) },
  47. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG1) },
  48. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG2) },
  49. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG3) },
  50. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG4) },
  51. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG5) },
  52. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG6) },
  53. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG7) },
  54. { 0, }
  55. };
  56. static int __devinit ioat_pci_probe(struct pci_dev *pdev,
  57. const struct pci_device_id *id);
  58. static void __devexit ioat_remove(struct pci_dev *pdev);
  59. static int ioat_dca_enabled = 1;
  60. module_param(ioat_dca_enabled, int, 0644);
  61. MODULE_PARM_DESC(ioat_dca_enabled, "control support of dca service (default: 1)");
  62. #define DRV_NAME "ioatdma"
  63. static struct pci_driver ioat_pci_driver = {
  64. .name = DRV_NAME,
  65. .id_table = ioat_pci_tbl,
  66. .probe = ioat_pci_probe,
  67. .remove = __devexit_p(ioat_remove),
  68. };
  69. static struct ioatdma_device *
  70. alloc_ioatdma(struct pci_dev *pdev, void __iomem *iobase)
  71. {
  72. struct device *dev = &pdev->dev;
  73. struct ioatdma_device *d = devm_kzalloc(dev, sizeof(*d), GFP_KERNEL);
  74. if (!d)
  75. return NULL;
  76. d->pdev = pdev;
  77. d->reg_base = iobase;
  78. return d;
  79. }
  80. static int __devinit ioat_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  81. {
  82. void __iomem * const *iomap;
  83. struct device *dev = &pdev->dev;
  84. struct ioatdma_device *device;
  85. int err;
  86. err = pcim_enable_device(pdev);
  87. if (err)
  88. return err;
  89. err = pcim_iomap_regions(pdev, 1 << IOAT_MMIO_BAR, DRV_NAME);
  90. if (err)
  91. return err;
  92. iomap = pcim_iomap_table(pdev);
  93. if (!iomap)
  94. return -ENOMEM;
  95. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  96. if (err)
  97. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  98. if (err)
  99. return err;
  100. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  101. if (err)
  102. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  103. if (err)
  104. return err;
  105. device = devm_kzalloc(dev, sizeof(*device), GFP_KERNEL);
  106. if (!device)
  107. return -ENOMEM;
  108. pci_set_master(pdev);
  109. device = alloc_ioatdma(pdev, iomap[IOAT_MMIO_BAR]);
  110. if (!device)
  111. return -ENOMEM;
  112. pci_set_drvdata(pdev, device);
  113. device->version = readb(device->reg_base + IOAT_VER_OFFSET);
  114. if (device->version == IOAT_VER_1_2)
  115. err = ioat1_dma_probe(device, ioat_dca_enabled);
  116. else if (device->version == IOAT_VER_2_0)
  117. err = ioat2_dma_probe(device, ioat_dca_enabled);
  118. else if (device->version >= IOAT_VER_3_0)
  119. err = ioat3_dma_probe(device, ioat_dca_enabled);
  120. else
  121. return -ENODEV;
  122. if (err) {
  123. dev_err(dev, "Intel(R) I/OAT DMA Engine init failed\n");
  124. return -ENODEV;
  125. }
  126. return 0;
  127. }
  128. static void __devexit ioat_remove(struct pci_dev *pdev)
  129. {
  130. struct ioatdma_device *device = pci_get_drvdata(pdev);
  131. if (!device)
  132. return;
  133. dev_err(&pdev->dev, "Removing dma and dca services\n");
  134. if (device->dca) {
  135. unregister_dca_provider(device->dca);
  136. free_dca_provider(device->dca);
  137. device->dca = NULL;
  138. }
  139. ioat_dma_remove(device);
  140. }
  141. static int __init ioat_init_module(void)
  142. {
  143. return pci_register_driver(&ioat_pci_driver);
  144. }
  145. module_init(ioat_init_module);
  146. static void __exit ioat_exit_module(void)
  147. {
  148. pci_unregister_driver(&ioat_pci_driver);
  149. }
  150. module_exit(ioat_exit_module);