pci.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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 "dma_v2.h"
  33. #include "registers.h"
  34. #include "hw.h"
  35. MODULE_VERSION(IOAT_DMA_VERSION);
  36. MODULE_LICENSE("GPL");
  37. MODULE_AUTHOR("Intel Corporation");
  38. static struct pci_device_id ioat_pci_tbl[] = {
  39. /* I/OAT v1 platforms */
  40. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT) },
  41. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_CNB) },
  42. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SCNB) },
  43. { PCI_DEVICE(PCI_VENDOR_ID_UNISYS, PCI_DEVICE_ID_UNISYS_DMA_DIRECTOR) },
  44. /* I/OAT v2 platforms */
  45. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_SNB) },
  46. /* I/OAT v3 platforms */
  47. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG0) },
  48. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG1) },
  49. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG2) },
  50. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG3) },
  51. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG4) },
  52. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG5) },
  53. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG6) },
  54. { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IOAT_TBG7) },
  55. { 0, }
  56. };
  57. static int __devinit ioat_pci_probe(struct pci_dev *pdev,
  58. const struct pci_device_id *id);
  59. static void __devexit ioat_remove(struct pci_dev *pdev);
  60. static int ioat_dca_enabled = 1;
  61. module_param(ioat_dca_enabled, int, 0644);
  62. MODULE_PARM_DESC(ioat_dca_enabled, "control support of dca service (default: 1)");
  63. #define DRV_NAME "ioatdma"
  64. static struct pci_driver ioat_pci_driver = {
  65. .name = DRV_NAME,
  66. .id_table = ioat_pci_tbl,
  67. .probe = ioat_pci_probe,
  68. .remove = __devexit_p(ioat_remove),
  69. };
  70. static struct ioatdma_device *
  71. alloc_ioatdma(struct pci_dev *pdev, void __iomem *iobase)
  72. {
  73. struct device *dev = &pdev->dev;
  74. struct ioatdma_device *d = devm_kzalloc(dev, sizeof(*d), GFP_KERNEL);
  75. if (!d)
  76. return NULL;
  77. d->pdev = pdev;
  78. d->reg_base = iobase;
  79. return d;
  80. }
  81. static int __devinit ioat_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
  82. {
  83. void __iomem * const *iomap;
  84. struct device *dev = &pdev->dev;
  85. struct ioatdma_device *device;
  86. int err;
  87. err = pcim_enable_device(pdev);
  88. if (err)
  89. return err;
  90. err = pcim_iomap_regions(pdev, 1 << IOAT_MMIO_BAR, DRV_NAME);
  91. if (err)
  92. return err;
  93. iomap = pcim_iomap_table(pdev);
  94. if (!iomap)
  95. return -ENOMEM;
  96. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(64));
  97. if (err)
  98. err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
  99. if (err)
  100. return err;
  101. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64));
  102. if (err)
  103. err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
  104. if (err)
  105. return err;
  106. device = devm_kzalloc(dev, sizeof(*device), GFP_KERNEL);
  107. if (!device)
  108. return -ENOMEM;
  109. pci_set_master(pdev);
  110. device = alloc_ioatdma(pdev, iomap[IOAT_MMIO_BAR]);
  111. if (!device)
  112. return -ENOMEM;
  113. pci_set_drvdata(pdev, device);
  114. device->version = readb(device->reg_base + IOAT_VER_OFFSET);
  115. if (device->version == IOAT_VER_1_2)
  116. err = ioat1_dma_probe(device, ioat_dca_enabled);
  117. else if (device->version == IOAT_VER_2_0)
  118. err = ioat2_dma_probe(device, ioat_dca_enabled);
  119. else if (device->version >= IOAT_VER_3_0)
  120. err = ioat3_dma_probe(device, ioat_dca_enabled);
  121. else
  122. return -ENODEV;
  123. if (err) {
  124. dev_err(dev, "Intel(R) I/OAT DMA Engine init failed\n");
  125. return -ENODEV;
  126. }
  127. return 0;
  128. }
  129. static void __devexit ioat_remove(struct pci_dev *pdev)
  130. {
  131. struct ioatdma_device *device = pci_get_drvdata(pdev);
  132. if (!device)
  133. return;
  134. dev_err(&pdev->dev, "Removing dma and dca services\n");
  135. if (device->dca) {
  136. unregister_dca_provider(device->dca);
  137. free_dca_provider(device->dca);
  138. device->dca = NULL;
  139. }
  140. ioat_dma_remove(device);
  141. }
  142. static int __init ioat_init_module(void)
  143. {
  144. return pci_register_driver(&ioat_pci_driver);
  145. }
  146. module_init(ioat_init_module);
  147. static void __exit ioat_exit_module(void)
  148. {
  149. pci_unregister_driver(&ioat_pci_driver);
  150. }
  151. module_exit(ioat_exit_module);