Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. From f8a8c2abc45442acf0c7bca1fa8868140d9a2dc8 Mon Sep 17 00:00:00 2001
  2. From: =?UTF-8?q?Timur=20Krist=C3=B3f?= <timur.kristof@gmail.com>
  3. Date: Sun, 14 Jul 2019 13:07:05 +0200
  4. Subject: [PATCH] add pcie_bandwidth_cap_available
  5.  
  6. ---
  7. drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 2 +-
  8. drivers/pci/pci.c | 59 ++++++++++++++++++++++
  9. include/linux/pci.h | 3 ++
  10. 3 files changed, 63 insertions(+), 1 deletion(-)
  11.  
  12. diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
  13. index 7401bc95c15b..3e23c402a9a9 100644
  14. --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
  15. +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
  16. @@ -3871,7 +3871,7 @@ static void amdgpu_device_get_pcie_info(struct amdgpu_device *adev)
  17. if (adev->pm.pcie_gen_mask && adev->pm.pcie_mlw_mask)
  18. return;
  19.  
  20. - pcie_bandwidth_available(adev->pdev, NULL,
  21. + pcie_bandwidth_cap_available(adev->pdev, NULL,
  22. &platform_speed_cap, &platform_link_width);
  23.  
  24. if (adev->pm.pcie_gen_mask == 0) {
  25. diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
  26. index b1f563916036..7cf4edf04c2c 100644
  27. --- a/drivers/pci/pci.c
  28. +++ b/drivers/pci/pci.c
  29. @@ -5647,6 +5647,65 @@ u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
  30. }
  31. EXPORT_SYMBOL(pcie_bandwidth_available);
  32.  
  33. +/**
  34. + * pcie_bandwidth_cap_available - determine minimum link settings of a PCIe
  35. + * device and the maximum bandwidth it is capable of
  36. + * @dev: PCI device to query
  37. + * @limiting_dev: storage for device causing the bandwidth limitation
  38. + * @speed: storage for speed of limiting device
  39. + * @width: storage for width of limiting device
  40. + *
  41. + * Walk up the PCI device chain and find the point where the minimum
  42. + * link width and minimum bandwidth capability is available.
  43. + * Return the bandwidth available there and (if
  44. + * limiting_dev, speed, and width pointers are supplied) information about
  45. + * that point. The bandwidth returned is in Mb/s, i.e., megabits/second of
  46. + * raw bandwidth.
  47. + */
  48. +u32 pcie_bandwidth_cap_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
  49. + enum pci_bus_speed *speed,
  50. + enum pcie_link_width *width)
  51. +{
  52. + u16 lnksta;
  53. + enum pci_bus_speed next_speed;
  54. + enum pcie_link_width next_width;
  55. + u32 bw, next_bw;
  56. +
  57. + if (speed)
  58. + *speed = PCI_SPEED_UNKNOWN;
  59. + if (width)
  60. + *width = PCIE_LNK_WIDTH_UNKNOWN;
  61. +
  62. + bw = 0;
  63. +
  64. + while (dev) {
  65. + pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
  66. +
  67. + next_speed = pcie_get_speed_cap(dev);
  68. + next_width = (lnksta & PCI_EXP_LNKSTA_NLW) >>
  69. + PCI_EXP_LNKSTA_NLW_SHIFT;
  70. +
  71. + next_bw = next_width * PCIE_SPEED2MBS_ENC(next_speed);
  72. +
  73. + /* Check if current device limits the total bandwidth */
  74. + if (!bw || next_bw <= bw) {
  75. + bw = next_bw;
  76. +
  77. + if (limiting_dev)
  78. + *limiting_dev = dev;
  79. + if (speed)
  80. + *speed = next_speed;
  81. + if (width)
  82. + *width = next_width;
  83. + }
  84. +
  85. + dev = pci_upstream_bridge(dev);
  86. + }
  87. +
  88. + return bw;
  89. +}
  90. +EXPORT_SYMBOL(pcie_bandwidth_cap_available);
  91. +
  92. /**
  93. * pcie_get_speed_cap - query for the PCI device's link speed capability
  94. * @dev: PCI device to query
  95. diff --git a/include/linux/pci.h b/include/linux/pci.h
  96. index dd436da7eccc..c27b3bf70bc8 100644
  97. --- a/include/linux/pci.h
  98. +++ b/include/linux/pci.h
  99. @@ -1135,6 +1135,9 @@ int pcie_set_mps(struct pci_dev *dev, int mps);
  100. u32 pcie_bandwidth_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
  101. enum pci_bus_speed *speed,
  102. enum pcie_link_width *width);
  103. +u32 pcie_bandwidth_cap_available(struct pci_dev *dev, struct pci_dev **limiting_dev,
  104. + enum pci_bus_speed *speed,
  105. + enum pcie_link_width *width);
  106. void pcie_print_link_status(struct pci_dev *dev);
  107. bool pcie_has_flr(struct pci_dev *dev);
  108. int pcie_flr(struct pci_dev *dev);
  109. --
  110. 2.21.0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement