gf100.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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 "priv.h"
  25. #include <subdev/fb.h>
  26. #include <subdev/timer.h>
  27. void
  28. gf100_ltc_cbc_clear(struct nvkm_ltc *ltc, u32 start, u32 limit)
  29. {
  30. struct nvkm_device *device = ltc->subdev.device;
  31. nvkm_wr32(device, 0x17e8cc, start);
  32. nvkm_wr32(device, 0x17e8d0, limit);
  33. nvkm_wr32(device, 0x17e8c8, 0x00000004);
  34. }
  35. void
  36. gf100_ltc_cbc_wait(struct nvkm_ltc *ltc)
  37. {
  38. struct nvkm_device *device = ltc->subdev.device;
  39. int c, s;
  40. for (c = 0; c < ltc->ltc_nr; c++) {
  41. for (s = 0; s < ltc->lts_nr; s++) {
  42. const u32 addr = 0x1410c8 + (c * 0x2000) + (s * 0x400);
  43. nvkm_msec(device, 2000,
  44. if (!nvkm_rd32(device, addr))
  45. break;
  46. );
  47. }
  48. }
  49. }
  50. void
  51. gf100_ltc_zbc_clear_color(struct nvkm_ltc *ltc, int i, const u32 color[4])
  52. {
  53. struct nvkm_device *device = ltc->subdev.device;
  54. nvkm_mask(device, 0x17ea44, 0x0000000f, i);
  55. nvkm_wr32(device, 0x17ea48, color[0]);
  56. nvkm_wr32(device, 0x17ea4c, color[1]);
  57. nvkm_wr32(device, 0x17ea50, color[2]);
  58. nvkm_wr32(device, 0x17ea54, color[3]);
  59. }
  60. void
  61. gf100_ltc_zbc_clear_depth(struct nvkm_ltc *ltc, int i, const u32 depth)
  62. {
  63. struct nvkm_device *device = ltc->subdev.device;
  64. nvkm_mask(device, 0x17ea44, 0x0000000f, i);
  65. nvkm_wr32(device, 0x17ea58, depth);
  66. }
  67. const struct nvkm_bitfield
  68. gf100_ltc_lts_intr_name[] = {
  69. { 0x00000001, "IDLE_ERROR_IQ" },
  70. { 0x00000002, "IDLE_ERROR_CBC" },
  71. { 0x00000004, "IDLE_ERROR_TSTG" },
  72. { 0x00000008, "IDLE_ERROR_DSTG" },
  73. { 0x00000010, "EVICTED_CB" },
  74. { 0x00000020, "ILLEGAL_COMPSTAT" },
  75. { 0x00000040, "BLOCKLINEAR_CB" },
  76. { 0x00000100, "ECC_SEC_ERROR" },
  77. { 0x00000200, "ECC_DED_ERROR" },
  78. { 0x00000400, "DEBUG" },
  79. { 0x00000800, "ATOMIC_TO_Z" },
  80. { 0x00001000, "ILLEGAL_ATOMIC" },
  81. { 0x00002000, "BLKACTIVITY_ERR" },
  82. {}
  83. };
  84. static void
  85. gf100_ltc_lts_intr(struct nvkm_ltc *ltc, int c, int s)
  86. {
  87. struct nvkm_subdev *subdev = &ltc->subdev;
  88. struct nvkm_device *device = subdev->device;
  89. u32 base = 0x141000 + (c * 0x2000) + (s * 0x400);
  90. u32 intr = nvkm_rd32(device, base + 0x020);
  91. u32 stat = intr & 0x0000ffff;
  92. char msg[128];
  93. if (stat) {
  94. nvkm_snprintbf(msg, sizeof(msg), gf100_ltc_lts_intr_name, stat);
  95. nvkm_error(subdev, "LTC%d_LTS%d: %08x [%s]\n", c, s, stat, msg);
  96. }
  97. nvkm_wr32(device, base + 0x020, intr);
  98. }
  99. void
  100. gf100_ltc_intr(struct nvkm_ltc *ltc)
  101. {
  102. struct nvkm_device *device = ltc->subdev.device;
  103. u32 mask;
  104. mask = nvkm_rd32(device, 0x00017c);
  105. while (mask) {
  106. u32 s, c = __ffs(mask);
  107. for (s = 0; s < ltc->lts_nr; s++)
  108. gf100_ltc_lts_intr(ltc, c, s);
  109. mask &= ~(1 << c);
  110. }
  111. }
  112. void
  113. gf100_ltc_invalidate(struct nvkm_ltc *ltc)
  114. {
  115. struct nvkm_device *device = ltc->subdev.device;
  116. s64 taken;
  117. nvkm_wr32(device, 0x70004, 0x00000001);
  118. taken = nvkm_wait_msec(device, 2000, 0x70004, 0x00000003, 0x00000000);
  119. if (taken > 0)
  120. nvkm_debug(&ltc->subdev, "LTC invalidate took %lld ns\n", taken);
  121. }
  122. void
  123. gf100_ltc_flush(struct nvkm_ltc *ltc)
  124. {
  125. struct nvkm_device *device = ltc->subdev.device;
  126. s64 taken;
  127. nvkm_wr32(device, 0x70010, 0x00000001);
  128. taken = nvkm_wait_msec(device, 2000, 0x70010, 0x00000003, 0x00000000);
  129. if (taken > 0)
  130. nvkm_debug(&ltc->subdev, "LTC flush took %lld ns\n", taken);
  131. }
  132. /* TODO: Figure out tag memory details and drop the over-cautious allocation.
  133. */
  134. int
  135. gf100_ltc_oneinit_tag_ram(struct nvkm_ltc *ltc)
  136. {
  137. struct nvkm_ram *ram = ltc->subdev.device->fb->ram;
  138. u32 tag_size, tag_margin, tag_align;
  139. int ret;
  140. /* No VRAM, no tags for now. */
  141. if (!ram) {
  142. ltc->num_tags = 0;
  143. goto mm_init;
  144. }
  145. /* tags for 1/4 of VRAM should be enough (8192/4 per GiB of VRAM) */
  146. ltc->num_tags = (ram->size >> 17) / 4;
  147. if (ltc->num_tags > (1 << 17))
  148. ltc->num_tags = 1 << 17; /* we have 17 bits in PTE */
  149. ltc->num_tags = (ltc->num_tags + 63) & ~63; /* round up to 64 */
  150. tag_align = ltc->ltc_nr * 0x800;
  151. tag_margin = (tag_align < 0x6000) ? 0x6000 : tag_align;
  152. /* 4 part 4 sub: 0x2000 bytes for 56 tags */
  153. /* 3 part 4 sub: 0x6000 bytes for 168 tags */
  154. /*
  155. * About 147 bytes per tag. Let's be safe and allocate x2, which makes
  156. * 0x4980 bytes for 64 tags, and round up to 0x6000 bytes for 64 tags.
  157. *
  158. * For 4 GiB of memory we'll have 8192 tags which makes 3 MiB, < 0.1 %.
  159. */
  160. tag_size = (ltc->num_tags / 64) * 0x6000 + tag_margin;
  161. tag_size += tag_align;
  162. tag_size = (tag_size + 0xfff) >> 12; /* round up */
  163. ret = nvkm_mm_tail(&ram->vram, 1, 1, tag_size, tag_size, 1,
  164. &ltc->tag_ram);
  165. if (ret) {
  166. ltc->num_tags = 0;
  167. } else {
  168. u64 tag_base = ((u64)ltc->tag_ram->offset << 12) + tag_margin;
  169. tag_base += tag_align - 1;
  170. do_div(tag_base, tag_align);
  171. ltc->tag_base = tag_base;
  172. }
  173. mm_init:
  174. return nvkm_mm_init(&ltc->tags, 0, ltc->num_tags, 1);
  175. }
  176. int
  177. gf100_ltc_oneinit(struct nvkm_ltc *ltc)
  178. {
  179. struct nvkm_device *device = ltc->subdev.device;
  180. const u32 parts = nvkm_rd32(device, 0x022438);
  181. const u32 mask = nvkm_rd32(device, 0x022554);
  182. const u32 slice = nvkm_rd32(device, 0x17e8dc) >> 28;
  183. int i;
  184. for (i = 0; i < parts; i++) {
  185. if (!(mask & (1 << i)))
  186. ltc->ltc_nr++;
  187. }
  188. ltc->lts_nr = slice;
  189. return gf100_ltc_oneinit_tag_ram(ltc);
  190. }
  191. static void
  192. gf100_ltc_init(struct nvkm_ltc *ltc)
  193. {
  194. struct nvkm_device *device = ltc->subdev.device;
  195. u32 lpg128 = !(nvkm_rd32(device, 0x100c80) & 0x00000001);
  196. nvkm_mask(device, 0x17e820, 0x00100000, 0x00000000); /* INTR_EN &= ~0x10 */
  197. nvkm_wr32(device, 0x17e8d8, ltc->ltc_nr);
  198. nvkm_wr32(device, 0x17e8d4, ltc->tag_base);
  199. nvkm_mask(device, 0x17e8c0, 0x00000002, lpg128 ? 0x00000002 : 0x00000000);
  200. }
  201. static const struct nvkm_ltc_func
  202. gf100_ltc = {
  203. .oneinit = gf100_ltc_oneinit,
  204. .init = gf100_ltc_init,
  205. .intr = gf100_ltc_intr,
  206. .cbc_clear = gf100_ltc_cbc_clear,
  207. .cbc_wait = gf100_ltc_cbc_wait,
  208. .zbc = 16,
  209. .zbc_clear_color = gf100_ltc_zbc_clear_color,
  210. .zbc_clear_depth = gf100_ltc_zbc_clear_depth,
  211. .invalidate = gf100_ltc_invalidate,
  212. .flush = gf100_ltc_flush,
  213. };
  214. int
  215. gf100_ltc_new(struct nvkm_device *device, int index, struct nvkm_ltc **pltc)
  216. {
  217. return nvkm_ltc_new_(&gf100_ltc, device, index, pltc);
  218. }