gf100.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /*
  2. * Copyright 2013 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 "gf100.h"
  25. const struct nvkm_specsrc
  26. gf100_pbfb_sources[] = {
  27. { 0x10f100, (const struct nvkm_specmux[]) {
  28. { 0x1, 0, "unk0" },
  29. { 0x3f, 4, "unk4" },
  30. {}
  31. }, "pbfb_broadcast_pm_unk100" },
  32. {}
  33. };
  34. const struct nvkm_specsrc
  35. gf100_pmfb_sources[] = {
  36. { 0x140028, (const struct nvkm_specmux[]) {
  37. { 0x3fff, 0, "unk0" },
  38. { 0x7, 16, "unk16" },
  39. { 0x3, 24, "unk24" },
  40. { 0x2, 29, "unk29" },
  41. {}
  42. }, "pmfb0_pm_unk28" },
  43. {}
  44. };
  45. static const struct nvkm_specsrc
  46. gf100_l1_sources[] = {
  47. { 0x5044a8, (const struct nvkm_specmux[]) {
  48. { 0x3f, 0, "sel", true },
  49. {}
  50. }, "pgraph_gpc0_tpc0_l1_pm_mux" },
  51. {}
  52. };
  53. static const struct nvkm_specsrc
  54. gf100_tex_sources[] = {
  55. { 0x5042c0, (const struct nvkm_specmux[]) {
  56. { 0xf, 0, "sel0", true },
  57. { 0x7, 8, "sel1", true },
  58. {}
  59. }, "pgraph_gpc0_tpc0_tex_pm_mux_c_d" },
  60. {}
  61. };
  62. static const struct nvkm_specsrc
  63. gf100_unk400_sources[] = {
  64. { 0x50440c, (const struct nvkm_specmux[]) {
  65. { 0x3f, 0, "sel", true },
  66. {}
  67. }, "pgraph_gpc0_tpc0_unk400_pm_mux" },
  68. {}
  69. };
  70. static const struct nvkm_specdom
  71. gf100_pm_hub[] = {
  72. {}
  73. };
  74. const struct nvkm_specdom
  75. gf100_pm_gpc[] = {
  76. { 0xe0, (const struct nvkm_specsig[]) {
  77. { 0x00, "gpc00_l1_00", gf100_l1_sources },
  78. { 0x01, "gpc00_l1_01", gf100_l1_sources },
  79. { 0x02, "gpc00_l1_02", gf100_l1_sources },
  80. { 0x03, "gpc00_l1_03", gf100_l1_sources },
  81. { 0x05, "gpc00_l1_04", gf100_l1_sources },
  82. { 0x06, "gpc00_l1_05", gf100_l1_sources },
  83. { 0x0a, "gpc00_tex_00", gf100_tex_sources },
  84. { 0x0b, "gpc00_tex_01", gf100_tex_sources },
  85. { 0x0c, "gpc00_tex_02", gf100_tex_sources },
  86. { 0x0d, "gpc00_tex_03", gf100_tex_sources },
  87. { 0x0e, "gpc00_tex_04", gf100_tex_sources },
  88. { 0x0f, "gpc00_tex_05", gf100_tex_sources },
  89. { 0x10, "gpc00_tex_06", gf100_tex_sources },
  90. { 0x11, "gpc00_tex_07", gf100_tex_sources },
  91. { 0x12, "gpc00_tex_08", gf100_tex_sources },
  92. { 0x26, "gpc00_unk400_00", gf100_unk400_sources },
  93. {}
  94. }, &gf100_perfctr_func },
  95. {}
  96. };
  97. static const struct nvkm_specdom
  98. gf100_pm_part[] = {
  99. { 0xe0, (const struct nvkm_specsig[]) {
  100. { 0x0f, "part00_pbfb_00", gf100_pbfb_sources },
  101. { 0x10, "part00_pbfb_01", gf100_pbfb_sources },
  102. { 0x21, "part00_pmfb_00", gf100_pmfb_sources },
  103. { 0x04, "part00_pmfb_01", gf100_pmfb_sources },
  104. { 0x00, "part00_pmfb_02", gf100_pmfb_sources },
  105. { 0x02, "part00_pmfb_03", gf100_pmfb_sources },
  106. { 0x01, "part00_pmfb_04", gf100_pmfb_sources },
  107. { 0x2e, "part00_pmfb_05", gf100_pmfb_sources },
  108. { 0x2f, "part00_pmfb_06", gf100_pmfb_sources },
  109. { 0x1b, "part00_pmfb_07", gf100_pmfb_sources },
  110. { 0x1c, "part00_pmfb_08", gf100_pmfb_sources },
  111. { 0x1d, "part00_pmfb_09", gf100_pmfb_sources },
  112. { 0x1e, "part00_pmfb_0a", gf100_pmfb_sources },
  113. { 0x1f, "part00_pmfb_0b", gf100_pmfb_sources },
  114. {}
  115. }, &gf100_perfctr_func },
  116. {}
  117. };
  118. static void
  119. gf100_perfctr_init(struct nvkm_pm *pm, struct nvkm_perfdom *dom,
  120. struct nvkm_perfctr *ctr)
  121. {
  122. struct nvkm_device *device = pm->engine.subdev.device;
  123. u32 log = ctr->logic_op;
  124. u32 src = 0x00000000;
  125. int i;
  126. for (i = 0; i < 4; i++)
  127. src |= ctr->signal[i] << (i * 8);
  128. nvkm_wr32(device, dom->addr + 0x09c, 0x00040002 | (dom->mode << 3));
  129. nvkm_wr32(device, dom->addr + 0x100, 0x00000000);
  130. nvkm_wr32(device, dom->addr + 0x040 + (ctr->slot * 0x08), src);
  131. nvkm_wr32(device, dom->addr + 0x044 + (ctr->slot * 0x08), log);
  132. }
  133. static void
  134. gf100_perfctr_read(struct nvkm_pm *pm, struct nvkm_perfdom *dom,
  135. struct nvkm_perfctr *ctr)
  136. {
  137. struct nvkm_device *device = pm->engine.subdev.device;
  138. switch (ctr->slot) {
  139. case 0: ctr->ctr = nvkm_rd32(device, dom->addr + 0x08c); break;
  140. case 1: ctr->ctr = nvkm_rd32(device, dom->addr + 0x088); break;
  141. case 2: ctr->ctr = nvkm_rd32(device, dom->addr + 0x080); break;
  142. case 3: ctr->ctr = nvkm_rd32(device, dom->addr + 0x090); break;
  143. }
  144. dom->clk = nvkm_rd32(device, dom->addr + 0x070);
  145. }
  146. static void
  147. gf100_perfctr_next(struct nvkm_pm *pm, struct nvkm_perfdom *dom)
  148. {
  149. struct nvkm_device *device = pm->engine.subdev.device;
  150. nvkm_wr32(device, dom->addr + 0x06c, dom->signal_nr - 0x40 + 0x27);
  151. nvkm_wr32(device, dom->addr + 0x0ec, 0x00000011);
  152. }
  153. const struct nvkm_funcdom
  154. gf100_perfctr_func = {
  155. .init = gf100_perfctr_init,
  156. .read = gf100_perfctr_read,
  157. .next = gf100_perfctr_next,
  158. };
  159. static void
  160. gf100_pm_fini(struct nvkm_pm *pm)
  161. {
  162. struct nvkm_device *device = pm->engine.subdev.device;
  163. nvkm_mask(device, 0x000200, 0x10000000, 0x00000000);
  164. nvkm_mask(device, 0x000200, 0x10000000, 0x10000000);
  165. }
  166. static const struct nvkm_pm_func
  167. gf100_pm_ = {
  168. .fini = gf100_pm_fini,
  169. };
  170. int
  171. gf100_pm_new_(const struct gf100_pm_func *func, struct nvkm_device *device,
  172. int index, struct nvkm_pm **ppm)
  173. {
  174. struct nvkm_pm *pm;
  175. u32 mask;
  176. int ret;
  177. if (!(pm = *ppm = kzalloc(sizeof(*pm), GFP_KERNEL)))
  178. return -ENOMEM;
  179. ret = nvkm_pm_ctor(&gf100_pm_, device, index, pm);
  180. if (ret)
  181. return ret;
  182. /* HUB */
  183. ret = nvkm_perfdom_new(pm, "hub", 0, 0x1b0000, 0, 0x200,
  184. func->doms_hub);
  185. if (ret)
  186. return ret;
  187. /* GPC */
  188. mask = (1 << nvkm_rd32(device, 0x022430)) - 1;
  189. mask &= ~nvkm_rd32(device, 0x022504);
  190. mask &= ~nvkm_rd32(device, 0x022584);
  191. ret = nvkm_perfdom_new(pm, "gpc", mask, 0x180000,
  192. 0x1000, 0x200, func->doms_gpc);
  193. if (ret)
  194. return ret;
  195. /* PART */
  196. mask = (1 << nvkm_rd32(device, 0x022438)) - 1;
  197. mask &= ~nvkm_rd32(device, 0x022548);
  198. mask &= ~nvkm_rd32(device, 0x0225c8);
  199. ret = nvkm_perfdom_new(pm, "part", mask, 0x1a0000,
  200. 0x1000, 0x200, func->doms_part);
  201. if (ret)
  202. return ret;
  203. return 0;
  204. }
  205. static const struct gf100_pm_func
  206. gf100_pm = {
  207. .doms_gpc = gf100_pm_gpc,
  208. .doms_hub = gf100_pm_hub,
  209. .doms_part = gf100_pm_part,
  210. };
  211. int
  212. gf100_pm_new(struct nvkm_device *device, int index, struct nvkm_pm **ppm)
  213. {
  214. return gf100_pm_new_(&gf100_pm, device, index, ppm);
  215. }