gf100.c 6.2 KB

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