pci.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * Intel(R) Trace Hub pci driver
  3. *
  4. * Copyright (C) 2014-2015 Intel Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. */
  15. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  16. #include <linux/types.h>
  17. #include <linux/module.h>
  18. #include <linux/device.h>
  19. #include <linux/sysfs.h>
  20. #include <linux/pci.h>
  21. #include "intel_th.h"
  22. #define DRIVER_NAME "intel_th_pci"
  23. #define BAR_MASK (BIT(TH_MMIO_CONFIG) | BIT(TH_MMIO_SW))
  24. #define PCI_REG_NPKDSC 0x80
  25. #define NPKDSC_TSACT BIT(5)
  26. static int intel_th_pci_activate(struct intel_th *th)
  27. {
  28. struct pci_dev *pdev = to_pci_dev(th->dev);
  29. u32 npkdsc;
  30. int err;
  31. if (!INTEL_TH_CAP(th, tscu_enable))
  32. return 0;
  33. err = pci_read_config_dword(pdev, PCI_REG_NPKDSC, &npkdsc);
  34. if (!err) {
  35. npkdsc |= NPKDSC_TSACT;
  36. err = pci_write_config_dword(pdev, PCI_REG_NPKDSC, npkdsc);
  37. }
  38. if (err)
  39. dev_err(&pdev->dev, "failed to read NPKDSC register\n");
  40. return err;
  41. }
  42. static void intel_th_pci_deactivate(struct intel_th *th)
  43. {
  44. struct pci_dev *pdev = to_pci_dev(th->dev);
  45. u32 npkdsc;
  46. int err;
  47. if (!INTEL_TH_CAP(th, tscu_enable))
  48. return;
  49. err = pci_read_config_dword(pdev, PCI_REG_NPKDSC, &npkdsc);
  50. if (!err) {
  51. npkdsc |= NPKDSC_TSACT;
  52. err = pci_write_config_dword(pdev, PCI_REG_NPKDSC, npkdsc);
  53. }
  54. if (err)
  55. dev_err(&pdev->dev, "failed to read NPKDSC register\n");
  56. }
  57. static int intel_th_pci_probe(struct pci_dev *pdev,
  58. const struct pci_device_id *id)
  59. {
  60. struct intel_th_drvdata *drvdata = (void *)id->driver_data;
  61. struct intel_th *th;
  62. int err;
  63. err = pcim_enable_device(pdev);
  64. if (err)
  65. return err;
  66. err = pcim_iomap_regions_request_all(pdev, BAR_MASK, DRIVER_NAME);
  67. if (err)
  68. return err;
  69. th = intel_th_alloc(&pdev->dev, drvdata, pdev->resource,
  70. DEVICE_COUNT_RESOURCE, pdev->irq);
  71. if (IS_ERR(th))
  72. return PTR_ERR(th);
  73. th->activate = intel_th_pci_activate;
  74. th->deactivate = intel_th_pci_deactivate;
  75. pci_set_master(pdev);
  76. return 0;
  77. }
  78. static void intel_th_pci_remove(struct pci_dev *pdev)
  79. {
  80. struct intel_th *th = pci_get_drvdata(pdev);
  81. intel_th_free(th);
  82. }
  83. static const struct intel_th_drvdata intel_th_2x = {
  84. .tscu_enable = 1,
  85. };
  86. static const struct pci_device_id intel_th_pci_id_table[] = {
  87. {
  88. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x9d26),
  89. .driver_data = (kernel_ulong_t)0,
  90. },
  91. {
  92. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa126),
  93. .driver_data = (kernel_ulong_t)0,
  94. },
  95. {
  96. /* Apollo Lake */
  97. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x5a8e),
  98. .driver_data = (kernel_ulong_t)0,
  99. },
  100. {
  101. /* Broxton */
  102. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x0a80),
  103. .driver_data = (kernel_ulong_t)0,
  104. },
  105. {
  106. /* Broxton B-step */
  107. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x1a8e),
  108. .driver_data = (kernel_ulong_t)0,
  109. },
  110. {
  111. /* Kaby Lake PCH-H */
  112. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa2a6),
  113. .driver_data = (kernel_ulong_t)0,
  114. },
  115. {
  116. /* Denverton */
  117. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x19e1),
  118. .driver_data = (kernel_ulong_t)0,
  119. },
  120. {
  121. /* Lewisburg PCH */
  122. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa1a6),
  123. .driver_data = (kernel_ulong_t)0,
  124. },
  125. {
  126. /* Gemini Lake */
  127. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x318e),
  128. .driver_data = (kernel_ulong_t)&intel_th_2x,
  129. },
  130. {
  131. /* Cannon Lake H */
  132. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0xa326),
  133. .driver_data = (kernel_ulong_t)&intel_th_2x,
  134. },
  135. {
  136. /* Cannon Lake LP */
  137. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x9da6),
  138. .driver_data = (kernel_ulong_t)&intel_th_2x,
  139. },
  140. {
  141. /* Cedar Fork PCH */
  142. PCI_DEVICE(PCI_VENDOR_ID_INTEL, 0x18e1),
  143. .driver_data = (kernel_ulong_t)&intel_th_2x,
  144. },
  145. { 0 },
  146. };
  147. MODULE_DEVICE_TABLE(pci, intel_th_pci_id_table);
  148. static struct pci_driver intel_th_pci_driver = {
  149. .name = DRIVER_NAME,
  150. .id_table = intel_th_pci_id_table,
  151. .probe = intel_th_pci_probe,
  152. .remove = intel_th_pci_remove,
  153. };
  154. module_pci_driver(intel_th_pci_driver);
  155. MODULE_LICENSE("GPL v2");
  156. MODULE_DESCRIPTION("Intel(R) Trace Hub PCI controller driver");
  157. MODULE_AUTHOR("Alexander Shishkin <alexander.shishkin@intel.com>");