g84.c 5.1 KB

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