g84.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. /*
  2. * Copyright 2015 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs <bskeggs@redhat.com>
  23. */
  24. #include "priv.h"
  25. #include <core/pci.h>
  26. static int
  27. g84_pcie_version_supported(struct nvkm_pci *pci)
  28. {
  29. /* g84 and g86 report wrong information about what they support */
  30. return 1;
  31. }
  32. int
  33. g84_pcie_version(struct nvkm_pci *pci)
  34. {
  35. struct nvkm_device *device = pci->subdev.device;
  36. return (nvkm_rd32(device, 0x00154c) & 0x1) + 1;
  37. }
  38. void
  39. g84_pcie_set_version(struct nvkm_pci *pci, u8 ver)
  40. {
  41. struct nvkm_device *device = pci->subdev.device;
  42. nvkm_mask(device, 0x00154c, 0x1, (ver >= 2 ? 0x1 : 0x0));
  43. }
  44. static void
  45. g84_pcie_set_cap_speed(struct nvkm_pci *pci, bool full_speed)
  46. {
  47. struct nvkm_device *device = pci->subdev.device;
  48. nvkm_mask(device, 0x00154c, 0x80, full_speed ? 0x80 : 0x0);
  49. }
  50. enum nvkm_pcie_speed
  51. g84_pcie_cur_speed(struct nvkm_pci *pci)
  52. {
  53. u32 reg_v = nvkm_pci_rd32(pci, 0x88) & 0x30000;
  54. switch (reg_v) {
  55. case 0x30000:
  56. return NVKM_PCIE_SPEED_8_0;
  57. case 0x20000:
  58. return NVKM_PCIE_SPEED_5_0;
  59. case 0x10000:
  60. default:
  61. return NVKM_PCIE_SPEED_2_5;
  62. }
  63. }
  64. enum nvkm_pcie_speed
  65. g84_pcie_max_speed(struct nvkm_pci *pci)
  66. {
  67. u32 reg_v = nvkm_pci_rd32(pci, 0x460) & 0x3300;
  68. if (reg_v == 0x2200)
  69. return NVKM_PCIE_SPEED_5_0;
  70. return NVKM_PCIE_SPEED_2_5;
  71. }
  72. void
  73. g84_pcie_set_link_speed(struct nvkm_pci *pci, enum nvkm_pcie_speed speed)
  74. {
  75. u32 mask_value;
  76. if (speed == NVKM_PCIE_SPEED_5_0)
  77. mask_value = 0x20;
  78. else
  79. mask_value = 0x10;
  80. nvkm_pci_mask(pci, 0x460, 0x30, mask_value);
  81. nvkm_pci_mask(pci, 0x460, 0x1, 0x1);
  82. }
  83. int
  84. g84_pcie_set_link(struct nvkm_pci *pci, enum nvkm_pcie_speed speed, u8 width)
  85. {
  86. g84_pcie_set_cap_speed(pci, speed == NVKM_PCIE_SPEED_5_0);
  87. g84_pcie_set_link_speed(pci, speed);
  88. return 0;
  89. }
  90. void
  91. g84_pci_init(struct nvkm_pci *pci)
  92. {
  93. /* The following only concerns PCIe cards. */
  94. if (!pci_is_pcie(pci->pdev))
  95. return;
  96. /* Tag field is 8-bit long, regardless of EXT_TAG.
  97. * However, if EXT_TAG is disabled, only the lower 5 bits of the tag
  98. * field should be used, limiting the number of request to 32.
  99. *
  100. * Apparently, 0x041c stores some limit on the number of requests
  101. * possible, so if EXT_TAG is disabled, limit that requests number to
  102. * 32
  103. *
  104. * Fixes fdo#86537
  105. */
  106. if (nvkm_pci_rd32(pci, 0x007c) & 0x00000020)
  107. nvkm_pci_mask(pci, 0x0080, 0x00000100, 0x00000100);
  108. else
  109. nvkm_pci_mask(pci, 0x041c, 0x00000060, 0x00000000);
  110. }
  111. int
  112. g84_pcie_init(struct nvkm_pci *pci)
  113. {
  114. bool full_speed = g84_pcie_cur_speed(pci) == NVKM_PCIE_SPEED_5_0;
  115. g84_pcie_set_cap_speed(pci, full_speed);
  116. return 0;
  117. }
  118. static const struct nvkm_pci_func
  119. g84_pci_func = {
  120. .init = g84_pci_init,
  121. .rd32 = nv40_pci_rd32,
  122. .wr08 = nv40_pci_wr08,
  123. .wr32 = nv40_pci_wr32,
  124. .msi_rearm = nv46_pci_msi_rearm,
  125. .pcie.init = g84_pcie_init,
  126. .pcie.set_link = g84_pcie_set_link,
  127. .pcie.max_speed = g84_pcie_max_speed,
  128. .pcie.cur_speed = g84_pcie_cur_speed,
  129. .pcie.set_version = g84_pcie_set_version,
  130. .pcie.version = g84_pcie_version,
  131. .pcie.version_supported = g84_pcie_version_supported,
  132. };
  133. int
  134. g84_pci_new(struct nvkm_device *device, int index, struct nvkm_pci **ppci)
  135. {
  136. return nvkm_pci_new_(&g84_pci_func, device, index, ppci);
  137. }