g84.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright 2012 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
  23. */
  24. #include "nv50.h"
  25. #include <subdev/timer.h>
  26. #include <nvif/class.h>
  27. static const struct nvkm_bitfield nv50_gr_status[] = {
  28. { 0x00000001, "BUSY" }, /* set when any bit is set */
  29. { 0x00000002, "DISPATCH" },
  30. { 0x00000004, "UNK2" },
  31. { 0x00000008, "UNK3" },
  32. { 0x00000010, "UNK4" },
  33. { 0x00000020, "UNK5" },
  34. { 0x00000040, "M2MF" },
  35. { 0x00000080, "UNK7" },
  36. { 0x00000100, "CTXPROG" },
  37. { 0x00000200, "VFETCH" },
  38. { 0x00000400, "CCACHE_PREGEOM" },
  39. { 0x00000800, "STRMOUT_VATTR_POSTGEOM" },
  40. { 0x00001000, "VCLIP" },
  41. { 0x00002000, "RATTR_APLANE" },
  42. { 0x00004000, "TRAST" },
  43. { 0x00008000, "CLIPID" },
  44. { 0x00010000, "ZCULL" },
  45. { 0x00020000, "ENG2D" },
  46. { 0x00040000, "RMASK" },
  47. { 0x00080000, "TPC_RAST" },
  48. { 0x00100000, "TPC_PROP" },
  49. { 0x00200000, "TPC_TEX" },
  50. { 0x00400000, "TPC_GEOM" },
  51. { 0x00800000, "TPC_MP" },
  52. { 0x01000000, "ROP" },
  53. {}
  54. };
  55. static const struct nvkm_bitfield
  56. nv50_gr_vstatus_0[] = {
  57. { 0x01, "VFETCH" },
  58. { 0x02, "CCACHE" },
  59. { 0x04, "PREGEOM" },
  60. { 0x08, "POSTGEOM" },
  61. { 0x10, "VATTR" },
  62. { 0x20, "STRMOUT" },
  63. { 0x40, "VCLIP" },
  64. {}
  65. };
  66. static const struct nvkm_bitfield
  67. nv50_gr_vstatus_1[] = {
  68. { 0x01, "TPC_RAST" },
  69. { 0x02, "TPC_PROP" },
  70. { 0x04, "TPC_TEX" },
  71. { 0x08, "TPC_GEOM" },
  72. { 0x10, "TPC_MP" },
  73. {}
  74. };
  75. static const struct nvkm_bitfield
  76. nv50_gr_vstatus_2[] = {
  77. { 0x01, "RATTR" },
  78. { 0x02, "APLANE" },
  79. { 0x04, "TRAST" },
  80. { 0x08, "CLIPID" },
  81. { 0x10, "ZCULL" },
  82. { 0x20, "ENG2D" },
  83. { 0x40, "RMASK" },
  84. { 0x80, "ROP" },
  85. {}
  86. };
  87. static void
  88. nvkm_gr_vstatus_print(struct nv50_gr *gr, int r,
  89. const struct nvkm_bitfield *units, u32 status)
  90. {
  91. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  92. u32 stat = status;
  93. u8 mask = 0x00;
  94. char msg[64];
  95. int i;
  96. for (i = 0; units[i].name && status; i++) {
  97. if ((status & 7) == 1)
  98. mask |= (1 << i);
  99. status >>= 3;
  100. }
  101. nvkm_snprintbf(msg, sizeof(msg), units, mask);
  102. nvkm_error(subdev, "PGRAPH_VSTATUS%d: %08x [%s]\n", r, stat, msg);
  103. }
  104. int
  105. g84_gr_tlb_flush(struct nvkm_gr *base)
  106. {
  107. struct nv50_gr *gr = nv50_gr(base);
  108. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  109. struct nvkm_device *device = subdev->device;
  110. struct nvkm_timer *tmr = device->timer;
  111. bool idle, timeout = false;
  112. unsigned long flags;
  113. char status[128];
  114. u64 start;
  115. u32 tmp;
  116. spin_lock_irqsave(&gr->lock, flags);
  117. nvkm_mask(device, 0x400500, 0x00000001, 0x00000000);
  118. start = nvkm_timer_read(tmr);
  119. do {
  120. idle = true;
  121. for (tmp = nvkm_rd32(device, 0x400380); tmp && idle; tmp >>= 3) {
  122. if ((tmp & 7) == 1)
  123. idle = false;
  124. }
  125. for (tmp = nvkm_rd32(device, 0x400384); tmp && idle; tmp >>= 3) {
  126. if ((tmp & 7) == 1)
  127. idle = false;
  128. }
  129. for (tmp = nvkm_rd32(device, 0x400388); tmp && idle; tmp >>= 3) {
  130. if ((tmp & 7) == 1)
  131. idle = false;
  132. }
  133. } while (!idle &&
  134. !(timeout = nvkm_timer_read(tmr) - start > 2000000000));
  135. if (timeout) {
  136. nvkm_error(subdev, "PGRAPH TLB flush idle timeout fail\n");
  137. tmp = nvkm_rd32(device, 0x400700);
  138. nvkm_snprintbf(status, sizeof(status), nv50_gr_status, tmp);
  139. nvkm_error(subdev, "PGRAPH_STATUS %08x [%s]\n", tmp, status);
  140. nvkm_gr_vstatus_print(gr, 0, nv50_gr_vstatus_0,
  141. nvkm_rd32(device, 0x400380));
  142. nvkm_gr_vstatus_print(gr, 1, nv50_gr_vstatus_1,
  143. nvkm_rd32(device, 0x400384));
  144. nvkm_gr_vstatus_print(gr, 2, nv50_gr_vstatus_2,
  145. nvkm_rd32(device, 0x400388));
  146. }
  147. nvkm_wr32(device, 0x100c80, 0x00000001);
  148. nvkm_msec(device, 2000,
  149. if (!(nvkm_rd32(device, 0x100c80) & 0x00000001))
  150. break;
  151. );
  152. nvkm_mask(device, 0x400500, 0x00000001, 0x00000001);
  153. spin_unlock_irqrestore(&gr->lock, flags);
  154. return timeout ? -EBUSY : 0;
  155. }
  156. static const struct nvkm_gr_func
  157. g84_gr = {
  158. .init = nv50_gr_init,
  159. .intr = nv50_gr_intr,
  160. .chan_new = nv50_gr_chan_new,
  161. .tlb_flush = g84_gr_tlb_flush,
  162. .units = nv50_gr_units,
  163. .sclass = {
  164. { -1, -1, NV_NULL_CLASS, &nv50_gr_object },
  165. { -1, -1, NV50_TWOD, &nv50_gr_object },
  166. { -1, -1, NV50_MEMORY_TO_MEMORY_FORMAT, &nv50_gr_object },
  167. { -1, -1, NV50_COMPUTE, &nv50_gr_object },
  168. { -1, -1, G82_TESLA, &nv50_gr_object },
  169. {}
  170. }
  171. };
  172. int
  173. g84_gr_new(struct nvkm_device *device, int index, struct nvkm_gr **pgr)
  174. {
  175. return nv50_gr_new_(&g84_gr, device, index, pgr);
  176. }