gk104.c 11 KB

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