gk104.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  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 <bskeggs@redhat.com>
  23. */
  24. #include "gf100.h"
  25. #include "ctxgf100.h"
  26. #include <nvif/class.h>
  27. /*******************************************************************************
  28. * PGRAPH register lists
  29. ******************************************************************************/
  30. const struct gf100_gr_init
  31. gk104_gr_init_main_0[] = {
  32. { 0x400080, 1, 0x04, 0x003083c2 },
  33. { 0x400088, 1, 0x04, 0x0001ffe7 },
  34. { 0x40008c, 1, 0x04, 0x00000000 },
  35. { 0x400090, 1, 0x04, 0x00000030 },
  36. { 0x40013c, 1, 0x04, 0x003901f7 },
  37. { 0x400140, 1, 0x04, 0x00000100 },
  38. { 0x400144, 1, 0x04, 0x00000000 },
  39. { 0x400148, 1, 0x04, 0x00000110 },
  40. { 0x400138, 1, 0x04, 0x00000000 },
  41. { 0x400130, 2, 0x04, 0x00000000 },
  42. { 0x400124, 1, 0x04, 0x00000002 },
  43. {}
  44. };
  45. static const struct gf100_gr_init
  46. gk104_gr_init_ds_0[] = {
  47. { 0x405844, 1, 0x04, 0x00ffffff },
  48. { 0x405850, 1, 0x04, 0x00000000 },
  49. { 0x405900, 1, 0x04, 0x0000ff34 },
  50. { 0x405908, 1, 0x04, 0x00000000 },
  51. { 0x405928, 2, 0x04, 0x00000000 },
  52. {}
  53. };
  54. static const struct gf100_gr_init
  55. gk104_gr_init_sked_0[] = {
  56. { 0x407010, 1, 0x04, 0x00000000 },
  57. {}
  58. };
  59. static const struct gf100_gr_init
  60. gk104_gr_init_cwd_0[] = {
  61. { 0x405b50, 1, 0x04, 0x00000000 },
  62. {}
  63. };
  64. static const struct gf100_gr_init
  65. gk104_gr_init_gpc_unk_1[] = {
  66. { 0x418d00, 1, 0x04, 0x00000000 },
  67. { 0x418d28, 2, 0x04, 0x00000000 },
  68. { 0x418f00, 1, 0x04, 0x00000000 },
  69. { 0x418f08, 1, 0x04, 0x00000000 },
  70. { 0x418f20, 2, 0x04, 0x00000000 },
  71. { 0x418e00, 1, 0x04, 0x00000060 },
  72. { 0x418e08, 1, 0x04, 0x00000000 },
  73. { 0x418e1c, 2, 0x04, 0x00000000 },
  74. {}
  75. };
  76. const struct gf100_gr_init
  77. gk104_gr_init_tpccs_0[] = {
  78. { 0x419d0c, 1, 0x04, 0x00000000 },
  79. { 0x419d10, 1, 0x04, 0x00000014 },
  80. {}
  81. };
  82. const struct gf100_gr_init
  83. gk104_gr_init_pe_0[] = {
  84. { 0x41980c, 1, 0x04, 0x00000010 },
  85. { 0x419844, 1, 0x04, 0x00000000 },
  86. { 0x419850, 1, 0x04, 0x00000004 },
  87. { 0x419854, 2, 0x04, 0x00000000 },
  88. {}
  89. };
  90. static const struct gf100_gr_init
  91. gk104_gr_init_l1c_0[] = {
  92. { 0x419c98, 1, 0x04, 0x00000000 },
  93. { 0x419ca8, 1, 0x04, 0x00000000 },
  94. { 0x419cb0, 1, 0x04, 0x01000000 },
  95. { 0x419cb4, 1, 0x04, 0x00000000 },
  96. { 0x419cb8, 1, 0x04, 0x00b08bea },
  97. { 0x419c84, 1, 0x04, 0x00010384 },
  98. { 0x419cbc, 1, 0x04, 0x28137646 },
  99. { 0x419cc0, 2, 0x04, 0x00000000 },
  100. { 0x419c80, 1, 0x04, 0x00020232 },
  101. {}
  102. };
  103. static const struct gf100_gr_init
  104. gk104_gr_init_sm_0[] = {
  105. { 0x419e00, 1, 0x04, 0x00000000 },
  106. { 0x419ea0, 1, 0x04, 0x00000000 },
  107. { 0x419ee4, 1, 0x04, 0x00000000 },
  108. { 0x419ea4, 1, 0x04, 0x00000100 },
  109. { 0x419ea8, 1, 0x04, 0x00000000 },
  110. { 0x419eb4, 4, 0x04, 0x00000000 },
  111. { 0x419edc, 1, 0x04, 0x00000000 },
  112. { 0x419f00, 1, 0x04, 0x00000000 },
  113. { 0x419f74, 1, 0x04, 0x00000555 },
  114. {}
  115. };
  116. const struct gf100_gr_init
  117. gk104_gr_init_be_0[] = {
  118. { 0x40880c, 1, 0x04, 0x00000000 },
  119. { 0x408850, 1, 0x04, 0x00000004 },
  120. { 0x408910, 9, 0x04, 0x00000000 },
  121. { 0x408950, 1, 0x04, 0x00000000 },
  122. { 0x408954, 1, 0x04, 0x0000ffff },
  123. { 0x408958, 1, 0x04, 0x00000034 },
  124. { 0x408984, 1, 0x04, 0x00000000 },
  125. { 0x408988, 1, 0x04, 0x08040201 },
  126. { 0x40898c, 1, 0x04, 0x80402010 },
  127. {}
  128. };
  129. const struct gf100_gr_pack
  130. gk104_gr_pack_mmio[] = {
  131. { gk104_gr_init_main_0 },
  132. { gf100_gr_init_fe_0 },
  133. { gf100_gr_init_pri_0 },
  134. { gf100_gr_init_rstr2d_0 },
  135. { gf119_gr_init_pd_0 },
  136. { gk104_gr_init_ds_0 },
  137. { gf100_gr_init_scc_0 },
  138. { gk104_gr_init_sked_0 },
  139. { gk104_gr_init_cwd_0 },
  140. { gf119_gr_init_prop_0 },
  141. { gf108_gr_init_gpc_unk_0 },
  142. { gf100_gr_init_setup_0 },
  143. { gf100_gr_init_crstr_0 },
  144. { gf108_gr_init_setup_1 },
  145. { gf100_gr_init_zcull_0 },
  146. { gf119_gr_init_gpm_0 },
  147. { gk104_gr_init_gpc_unk_1 },
  148. { gf100_gr_init_gcc_0 },
  149. { gk104_gr_init_tpccs_0 },
  150. { gf119_gr_init_tex_0 },
  151. { gk104_gr_init_pe_0 },
  152. { gk104_gr_init_l1c_0 },
  153. { gf100_gr_init_mpc_0 },
  154. { gk104_gr_init_sm_0 },
  155. { gf117_gr_init_pes_0 },
  156. { gf117_gr_init_wwdx_0 },
  157. { gf117_gr_init_cbm_0 },
  158. { gk104_gr_init_be_0 },
  159. { gf100_gr_init_fe_1 },
  160. {}
  161. };
  162. /*******************************************************************************
  163. * PGRAPH engine/subdev functions
  164. ******************************************************************************/
  165. int
  166. gk104_gr_init(struct gf100_gr *gr)
  167. {
  168. struct nvkm_device *device = gr->base.engine.subdev.device;
  169. const u32 magicgpc918 = DIV_ROUND_UP(0x00800000, gr->tpc_total);
  170. u32 data[TPC_MAX / 8] = {};
  171. u8 tpcnr[GPC_MAX];
  172. int gpc, tpc, rop;
  173. int i;
  174. nvkm_wr32(device, GPC_BCAST(0x0880), 0x00000000);
  175. nvkm_wr32(device, GPC_BCAST(0x08a4), 0x00000000);
  176. nvkm_wr32(device, GPC_BCAST(0x0888), 0x00000000);
  177. nvkm_wr32(device, GPC_BCAST(0x088c), 0x00000000);
  178. nvkm_wr32(device, GPC_BCAST(0x0890), 0x00000000);
  179. nvkm_wr32(device, GPC_BCAST(0x0894), 0x00000000);
  180. nvkm_wr32(device, GPC_BCAST(0x08b4), nvkm_memory_addr(gr->unk4188b4) >> 8);
  181. nvkm_wr32(device, GPC_BCAST(0x08b8), nvkm_memory_addr(gr->unk4188b8) >> 8);
  182. gf100_gr_mmio(gr, gr->func->mmio);
  183. nvkm_wr32(device, GPC_UNIT(0, 0x3018), 0x00000001);
  184. memset(data, 0x00, sizeof(data));
  185. memcpy(tpcnr, gr->tpc_nr, sizeof(gr->tpc_nr));
  186. for (i = 0, gpc = -1; i < gr->tpc_total; i++) {
  187. do {
  188. gpc = (gpc + 1) % gr->gpc_nr;
  189. } while (!tpcnr[gpc]);
  190. tpc = gr->tpc_nr[gpc] - tpcnr[gpc]--;
  191. data[i / 8] |= tpc << ((i % 8) * 4);
  192. }
  193. nvkm_wr32(device, GPC_BCAST(0x0980), data[0]);
  194. nvkm_wr32(device, GPC_BCAST(0x0984), data[1]);
  195. nvkm_wr32(device, GPC_BCAST(0x0988), data[2]);
  196. nvkm_wr32(device, GPC_BCAST(0x098c), data[3]);
  197. for (gpc = 0; gpc < gr->gpc_nr; gpc++) {
  198. nvkm_wr32(device, GPC_UNIT(gpc, 0x0914),
  199. gr->magic_not_rop_nr << 8 | gr->tpc_nr[gpc]);
  200. nvkm_wr32(device, GPC_UNIT(gpc, 0x0910), 0x00040000 |
  201. gr->tpc_total);
  202. nvkm_wr32(device, GPC_UNIT(gpc, 0x0918), magicgpc918);
  203. }
  204. nvkm_wr32(device, GPC_BCAST(0x3fd4), magicgpc918);
  205. nvkm_wr32(device, GPC_BCAST(0x08ac), nvkm_rd32(device, 0x100800));
  206. nvkm_wr32(device, 0x400500, 0x00010001);
  207. nvkm_wr32(device, 0x400100, 0xffffffff);
  208. nvkm_wr32(device, 0x40013c, 0xffffffff);
  209. nvkm_wr32(device, 0x409ffc, 0x00000000);
  210. nvkm_wr32(device, 0x409c14, 0x00003e3e);
  211. nvkm_wr32(device, 0x409c24, 0x000f0001);
  212. nvkm_wr32(device, 0x404000, 0xc0000000);
  213. nvkm_wr32(device, 0x404600, 0xc0000000);
  214. nvkm_wr32(device, 0x408030, 0xc0000000);
  215. nvkm_wr32(device, 0x404490, 0xc0000000);
  216. nvkm_wr32(device, 0x406018, 0xc0000000);
  217. nvkm_wr32(device, 0x407020, 0x40000000);
  218. nvkm_wr32(device, 0x405840, 0xc0000000);
  219. nvkm_wr32(device, 0x405844, 0x00ffffff);
  220. nvkm_mask(device, 0x419cc0, 0x00000008, 0x00000008);
  221. nvkm_mask(device, 0x419eb4, 0x00001000, 0x00001000);
  222. for (gpc = 0; gpc < gr->gpc_nr; gpc++) {
  223. nvkm_wr32(device, GPC_UNIT(gpc, 0x3038), 0xc0000000);
  224. nvkm_wr32(device, GPC_UNIT(gpc, 0x0420), 0xc0000000);
  225. nvkm_wr32(device, GPC_UNIT(gpc, 0x0900), 0xc0000000);
  226. nvkm_wr32(device, GPC_UNIT(gpc, 0x1028), 0xc0000000);
  227. nvkm_wr32(device, GPC_UNIT(gpc, 0x0824), 0xc0000000);
  228. for (tpc = 0; tpc < gr->tpc_nr[gpc]; tpc++) {
  229. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x508), 0xffffffff);
  230. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x50c), 0xffffffff);
  231. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x224), 0xc0000000);
  232. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x48c), 0xc0000000);
  233. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x084), 0xc0000000);
  234. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x644), 0x001ffffe);
  235. nvkm_wr32(device, TPC_UNIT(gpc, tpc, 0x64c), 0x0000000f);
  236. }
  237. nvkm_wr32(device, GPC_UNIT(gpc, 0x2c90), 0xffffffff);
  238. nvkm_wr32(device, GPC_UNIT(gpc, 0x2c94), 0xffffffff);
  239. }
  240. for (rop = 0; rop < gr->rop_nr; rop++) {
  241. nvkm_wr32(device, ROP_UNIT(rop, 0x144), 0xc0000000);
  242. nvkm_wr32(device, ROP_UNIT(rop, 0x070), 0xc0000000);
  243. nvkm_wr32(device, ROP_UNIT(rop, 0x204), 0xffffffff);
  244. nvkm_wr32(device, ROP_UNIT(rop, 0x208), 0xffffffff);
  245. }
  246. nvkm_wr32(device, 0x400108, 0xffffffff);
  247. nvkm_wr32(device, 0x400138, 0xffffffff);
  248. nvkm_wr32(device, 0x400118, 0xffffffff);
  249. nvkm_wr32(device, 0x400130, 0xffffffff);
  250. nvkm_wr32(device, 0x40011c, 0xffffffff);
  251. nvkm_wr32(device, 0x400134, 0xffffffff);
  252. nvkm_wr32(device, 0x400054, 0x34ce3464);
  253. gf100_gr_zbc_init(gr);
  254. return gf100_gr_init_ctxctl(gr);
  255. }
  256. #include "fuc/hubgk104.fuc3.h"
  257. static struct gf100_gr_ucode
  258. gk104_gr_fecs_ucode = {
  259. .code.data = gk104_grhub_code,
  260. .code.size = sizeof(gk104_grhub_code),
  261. .data.data = gk104_grhub_data,
  262. .data.size = sizeof(gk104_grhub_data),
  263. };
  264. #include "fuc/gpcgk104.fuc3.h"
  265. static struct gf100_gr_ucode
  266. gk104_gr_gpccs_ucode = {
  267. .code.data = gk104_grgpc_code,
  268. .code.size = sizeof(gk104_grgpc_code),
  269. .data.data = gk104_grgpc_data,
  270. .data.size = sizeof(gk104_grgpc_data),
  271. };
  272. static const struct gf100_gr_func
  273. gk104_gr = {
  274. .init = gk104_gr_init,
  275. .mmio = gk104_gr_pack_mmio,
  276. .fecs.ucode = &gk104_gr_fecs_ucode,
  277. .gpccs.ucode = &gk104_gr_gpccs_ucode,
  278. .ppc_nr = 1,
  279. .grctx = &gk104_grctx,
  280. .sclass = {
  281. { -1, -1, FERMI_TWOD_A },
  282. { -1, -1, KEPLER_INLINE_TO_MEMORY_A },
  283. { -1, -1, KEPLER_A, &gf100_fermi },
  284. { -1, -1, KEPLER_COMPUTE_A },
  285. {}
  286. }
  287. };
  288. int
  289. gk104_gr_new(struct nvkm_device *device, int index, struct nvkm_gr **pgr)
  290. {
  291. return gf100_gr_new_(&gk104_gr, device, index, pgr);
  292. }