gm107.c 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright 2014 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. gm107_ltc_cbc_clear(struct nvkm_ltc *ltc, u32 start, u32 limit)
  29. {
  30. struct nvkm_device *device = ltc->subdev.device;
  31. nvkm_wr32(device, 0x17e270, start);
  32. nvkm_wr32(device, 0x17e274, limit);
  33. nvkm_mask(device, 0x17e26c, 0x00000000, 0x00000004);
  34. }
  35. void
  36. gm107_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 = 0x14046c + (c * 0x2000) + (s * 0x200);
  43. nvkm_wait_msec(device, 2000, addr,
  44. 0x00000004, 0x00000000);
  45. }
  46. }
  47. }
  48. void
  49. gm107_ltc_zbc_clear_color(struct nvkm_ltc *ltc, int i, const u32 color[4])
  50. {
  51. struct nvkm_device *device = ltc->subdev.device;
  52. nvkm_mask(device, 0x17e338, 0x0000000f, i);
  53. nvkm_wr32(device, 0x17e33c, color[0]);
  54. nvkm_wr32(device, 0x17e340, color[1]);
  55. nvkm_wr32(device, 0x17e344, color[2]);
  56. nvkm_wr32(device, 0x17e348, color[3]);
  57. }
  58. void
  59. gm107_ltc_zbc_clear_depth(struct nvkm_ltc *ltc, int i, const u32 depth)
  60. {
  61. struct nvkm_device *device = ltc->subdev.device;
  62. nvkm_mask(device, 0x17e338, 0x0000000f, i);
  63. nvkm_wr32(device, 0x17e34c, depth);
  64. }
  65. void
  66. gm107_ltc_intr_lts(struct nvkm_ltc *ltc, int c, int s)
  67. {
  68. struct nvkm_subdev *subdev = &ltc->subdev;
  69. struct nvkm_device *device = subdev->device;
  70. u32 base = 0x140400 + (c * 0x2000) + (s * 0x200);
  71. u32 intr = nvkm_rd32(device, base + 0x00c);
  72. u16 stat = intr & 0x0000ffff;
  73. char msg[128];
  74. if (stat) {
  75. nvkm_snprintbf(msg, sizeof(msg), gf100_ltc_lts_intr_name, stat);
  76. nvkm_error(subdev, "LTC%d_LTS%d: %08x [%s]\n", c, s, intr, msg);
  77. }
  78. nvkm_wr32(device, base + 0x00c, intr);
  79. }
  80. void
  81. gm107_ltc_intr(struct nvkm_ltc *ltc)
  82. {
  83. struct nvkm_device *device = ltc->subdev.device;
  84. u32 mask;
  85. mask = nvkm_rd32(device, 0x00017c);
  86. while (mask) {
  87. u32 s, c = __ffs(mask);
  88. for (s = 0; s < ltc->lts_nr; s++)
  89. gm107_ltc_intr_lts(ltc, c, s);
  90. mask &= ~(1 << c);
  91. }
  92. }
  93. static int
  94. gm107_ltc_oneinit(struct nvkm_ltc *ltc)
  95. {
  96. struct nvkm_device *device = ltc->subdev.device;
  97. const u32 parts = nvkm_rd32(device, 0x022438);
  98. const u32 mask = nvkm_rd32(device, 0x021c14);
  99. const u32 slice = nvkm_rd32(device, 0x17e280) >> 28;
  100. int i;
  101. for (i = 0; i < parts; i++) {
  102. if (!(mask & (1 << i)))
  103. ltc->ltc_nr++;
  104. }
  105. ltc->lts_nr = slice;
  106. return gf100_ltc_oneinit_tag_ram(ltc);
  107. }
  108. static void
  109. gm107_ltc_init(struct nvkm_ltc *ltc)
  110. {
  111. struct nvkm_device *device = ltc->subdev.device;
  112. u32 lpg128 = !(nvkm_rd32(device, 0x100c80) & 0x00000001);
  113. nvkm_wr32(device, 0x17e27c, ltc->ltc_nr);
  114. nvkm_wr32(device, 0x17e278, ltc->tag_base);
  115. nvkm_mask(device, 0x17e264, 0x00000002, lpg128 ? 0x00000002 : 0x00000000);
  116. }
  117. static const struct nvkm_ltc_func
  118. gm107_ltc = {
  119. .oneinit = gm107_ltc_oneinit,
  120. .init = gm107_ltc_init,
  121. .intr = gm107_ltc_intr,
  122. .cbc_clear = gm107_ltc_cbc_clear,
  123. .cbc_wait = gm107_ltc_cbc_wait,
  124. .zbc = 16,
  125. .zbc_clear_color = gm107_ltc_zbc_clear_color,
  126. .zbc_clear_depth = gm107_ltc_zbc_clear_depth,
  127. .invalidate = gf100_ltc_invalidate,
  128. .flush = gf100_ltc_flush,
  129. };
  130. int
  131. gm107_ltc_new(struct nvkm_device *device, int index, struct nvkm_ltc **pltc)
  132. {
  133. return nvkm_ltc_new_(&gm107_ltc, device, index, pltc);
  134. }