gk20a.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. /*
  2. * Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
  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 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  19. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  20. * DEALINGS IN THE SOFTWARE.
  21. */
  22. #include "gf100.h"
  23. #include "ctxgf100.h"
  24. #include <subdev/timer.h>
  25. #include <nvif/class.h>
  26. struct gk20a_fw_av
  27. {
  28. u32 addr;
  29. u32 data;
  30. };
  31. int
  32. gk20a_gr_av_to_init(struct gf100_gr *gr, const char *fw_name,
  33. struct gf100_gr_pack **ppack)
  34. {
  35. struct gf100_gr_fuc fuc;
  36. struct gf100_gr_init *init;
  37. struct gf100_gr_pack *pack;
  38. int nent;
  39. int ret;
  40. int i;
  41. ret = gf100_gr_ctor_fw(gr, fw_name, &fuc);
  42. if (ret)
  43. return ret;
  44. nent = (fuc.size / sizeof(struct gk20a_fw_av));
  45. pack = vzalloc((sizeof(*pack) * 2) + (sizeof(*init) * (nent + 1)));
  46. if (!pack) {
  47. ret = -ENOMEM;
  48. goto end;
  49. }
  50. init = (void *)(pack + 2);
  51. pack[0].init = init;
  52. for (i = 0; i < nent; i++) {
  53. struct gf100_gr_init *ent = &init[i];
  54. struct gk20a_fw_av *av = &((struct gk20a_fw_av *)fuc.data)[i];
  55. ent->addr = av->addr;
  56. ent->data = av->data;
  57. ent->count = 1;
  58. ent->pitch = 1;
  59. }
  60. *ppack = pack;
  61. end:
  62. gf100_gr_dtor_fw(&fuc);
  63. return ret;
  64. }
  65. struct gk20a_fw_aiv
  66. {
  67. u32 addr;
  68. u32 index;
  69. u32 data;
  70. };
  71. int
  72. gk20a_gr_aiv_to_init(struct gf100_gr *gr, const char *fw_name,
  73. struct gf100_gr_pack **ppack)
  74. {
  75. struct gf100_gr_fuc fuc;
  76. struct gf100_gr_init *init;
  77. struct gf100_gr_pack *pack;
  78. int nent;
  79. int ret;
  80. int i;
  81. ret = gf100_gr_ctor_fw(gr, fw_name, &fuc);
  82. if (ret)
  83. return ret;
  84. nent = (fuc.size / sizeof(struct gk20a_fw_aiv));
  85. pack = vzalloc((sizeof(*pack) * 2) + (sizeof(*init) * (nent + 1)));
  86. if (!pack) {
  87. ret = -ENOMEM;
  88. goto end;
  89. }
  90. init = (void *)(pack + 2);
  91. pack[0].init = init;
  92. for (i = 0; i < nent; i++) {
  93. struct gf100_gr_init *ent = &init[i];
  94. struct gk20a_fw_aiv *av = &((struct gk20a_fw_aiv *)fuc.data)[i];
  95. ent->addr = av->addr;
  96. ent->data = av->data;
  97. ent->count = 1;
  98. ent->pitch = 1;
  99. }
  100. *ppack = pack;
  101. end:
  102. gf100_gr_dtor_fw(&fuc);
  103. return ret;
  104. }
  105. int
  106. gk20a_gr_av_to_method(struct gf100_gr *gr, const char *fw_name,
  107. struct gf100_gr_pack **ppack)
  108. {
  109. struct gf100_gr_fuc fuc;
  110. struct gf100_gr_init *init;
  111. struct gf100_gr_pack *pack;
  112. /* We don't suppose we will initialize more than 16 classes here... */
  113. static const unsigned int max_classes = 16;
  114. u32 classidx = 0, prevclass = 0;
  115. int nent;
  116. int ret;
  117. int i;
  118. ret = gf100_gr_ctor_fw(gr, fw_name, &fuc);
  119. if (ret)
  120. return ret;
  121. nent = (fuc.size / sizeof(struct gk20a_fw_av));
  122. pack = vzalloc((sizeof(*pack) * max_classes) +
  123. (sizeof(*init) * (nent + 1)));
  124. if (!pack) {
  125. ret = -ENOMEM;
  126. goto end;
  127. }
  128. init = (void *)(pack + max_classes);
  129. for (i = 0; i < nent; i++) {
  130. struct gf100_gr_init *ent = &init[i];
  131. struct gk20a_fw_av *av = &((struct gk20a_fw_av *)fuc.data)[i];
  132. u32 class = av->addr & 0xffff;
  133. u32 addr = (av->addr & 0xffff0000) >> 14;
  134. if (prevclass != class) {
  135. pack[classidx].init = ent;
  136. pack[classidx].type = class;
  137. prevclass = class;
  138. if (++classidx >= max_classes) {
  139. vfree(pack);
  140. ret = -ENOSPC;
  141. goto end;
  142. }
  143. }
  144. ent->addr = addr;
  145. ent->data = av->data;
  146. ent->count = 1;
  147. ent->pitch = 1;
  148. }
  149. *ppack = pack;
  150. end:
  151. gf100_gr_dtor_fw(&fuc);
  152. return ret;
  153. }
  154. static int
  155. gk20a_gr_wait_mem_scrubbing(struct gf100_gr *gr)
  156. {
  157. struct nvkm_subdev *subdev = &gr->base.engine.subdev;
  158. struct nvkm_device *device = subdev->device;
  159. if (nvkm_msec(device, 2000,
  160. if (!(nvkm_rd32(device, 0x40910c) & 0x00000006))
  161. break;
  162. ) < 0) {
  163. nvkm_error(subdev, "FECS mem scrubbing timeout\n");
  164. return -ETIMEDOUT;
  165. }
  166. if (nvkm_msec(device, 2000,
  167. if (!(nvkm_rd32(device, 0x41a10c) & 0x00000006))
  168. break;
  169. ) < 0) {
  170. nvkm_error(subdev, "GPCCS mem scrubbing timeout\n");
  171. return -ETIMEDOUT;
  172. }
  173. return 0;
  174. }
  175. static void
  176. gk20a_gr_set_hww_esr_report_mask(struct gf100_gr *gr)
  177. {
  178. struct nvkm_device *device = gr->base.engine.subdev.device;
  179. nvkm_wr32(device, 0x419e44, 0x1ffffe);
  180. nvkm_wr32(device, 0x419e4c, 0x7f);
  181. }
  182. int
  183. gk20a_gr_init(struct gf100_gr *gr)
  184. {
  185. struct nvkm_device *device = gr->base.engine.subdev.device;
  186. const u32 magicgpc918 = DIV_ROUND_UP(0x00800000, gr->tpc_total);
  187. u32 data[TPC_MAX / 8] = {};
  188. u8 tpcnr[GPC_MAX];
  189. int gpc, tpc;
  190. int ret, i;
  191. /* Clear SCC RAM */
  192. nvkm_wr32(device, 0x40802c, 0x1);
  193. gf100_gr_mmio(gr, gr->fuc_sw_nonctx);
  194. ret = gk20a_gr_wait_mem_scrubbing(gr);
  195. if (ret)
  196. return ret;
  197. ret = gf100_gr_wait_idle(gr);
  198. if (ret)
  199. return ret;
  200. /* MMU debug buffer */
  201. if (gr->func->init_gpc_mmu)
  202. gr->func->init_gpc_mmu(gr);
  203. /* Set the PE as stream master */
  204. nvkm_mask(device, 0x503018, 0x1, 0x1);
  205. /* Zcull init */
  206. memset(data, 0x00, sizeof(data));
  207. memcpy(tpcnr, gr->tpc_nr, sizeof(gr->tpc_nr));
  208. for (i = 0, gpc = -1; i < gr->tpc_total; i++) {
  209. do {
  210. gpc = (gpc + 1) % gr->gpc_nr;
  211. } while (!tpcnr[gpc]);
  212. tpc = gr->tpc_nr[gpc] - tpcnr[gpc]--;
  213. data[i / 8] |= tpc << ((i % 8) * 4);
  214. }
  215. nvkm_wr32(device, GPC_BCAST(0x0980), data[0]);
  216. nvkm_wr32(device, GPC_BCAST(0x0984), data[1]);
  217. nvkm_wr32(device, GPC_BCAST(0x0988), data[2]);
  218. nvkm_wr32(device, GPC_BCAST(0x098c), data[3]);
  219. for (gpc = 0; gpc < gr->gpc_nr; gpc++) {
  220. nvkm_wr32(device, GPC_UNIT(gpc, 0x0914),
  221. gr->screen_tile_row_offset << 8 | gr->tpc_nr[gpc]);
  222. nvkm_wr32(device, GPC_UNIT(gpc, 0x0910), 0x00040000 |
  223. gr->tpc_total);
  224. nvkm_wr32(device, GPC_UNIT(gpc, 0x0918), magicgpc918);
  225. }
  226. nvkm_wr32(device, GPC_BCAST(0x3fd4), magicgpc918);
  227. gr->func->init_rop_active_fbps(gr);
  228. /* Enable FIFO access */
  229. nvkm_wr32(device, 0x400500, 0x00010001);
  230. /* Enable interrupts */
  231. nvkm_wr32(device, 0x400100, 0xffffffff);
  232. nvkm_wr32(device, 0x40013c, 0xffffffff);
  233. /* Enable FECS error interrupts */
  234. nvkm_wr32(device, 0x409c24, 0x000f0000);
  235. /* Enable hardware warning exceptions */
  236. nvkm_wr32(device, 0x404000, 0xc0000000);
  237. nvkm_wr32(device, 0x404600, 0xc0000000);
  238. if (gr->func->set_hww_esr_report_mask)
  239. gr->func->set_hww_esr_report_mask(gr);
  240. /* Enable TPC exceptions per GPC */
  241. nvkm_wr32(device, 0x419d0c, 0x2);
  242. nvkm_wr32(device, 0x41ac94, (((1 << gr->tpc_total) - 1) & 0xff) << 16);
  243. /* Reset and enable all exceptions */
  244. nvkm_wr32(device, 0x400108, 0xffffffff);
  245. nvkm_wr32(device, 0x400138, 0xffffffff);
  246. nvkm_wr32(device, 0x400118, 0xffffffff);
  247. nvkm_wr32(device, 0x400130, 0xffffffff);
  248. nvkm_wr32(device, 0x40011c, 0xffffffff);
  249. nvkm_wr32(device, 0x400134, 0xffffffff);
  250. gf100_gr_zbc_init(gr);
  251. return gf100_gr_init_ctxctl(gr);
  252. }
  253. static const struct gf100_gr_func
  254. gk20a_gr = {
  255. .init = gk20a_gr_init,
  256. .init_rop_active_fbps = gk104_gr_init_rop_active_fbps,
  257. .set_hww_esr_report_mask = gk20a_gr_set_hww_esr_report_mask,
  258. .rops = gf100_gr_rops,
  259. .ppc_nr = 1,
  260. .grctx = &gk20a_grctx,
  261. .sclass = {
  262. { -1, -1, FERMI_TWOD_A },
  263. { -1, -1, KEPLER_INLINE_TO_MEMORY_A },
  264. { -1, -1, KEPLER_C, &gf100_fermi },
  265. { -1, -1, KEPLER_COMPUTE_A },
  266. {}
  267. }
  268. };
  269. int
  270. gk20a_gr_new(struct nvkm_device *device, int index, struct nvkm_gr **pgr)
  271. {
  272. struct gf100_gr *gr;
  273. int ret;
  274. if (!(gr = kzalloc(sizeof(*gr), GFP_KERNEL)))
  275. return -ENOMEM;
  276. *pgr = &gr->base;
  277. ret = gf100_gr_ctor(&gk20a_gr, device, index, gr);
  278. if (ret)
  279. return ret;
  280. if (gf100_gr_ctor_fw(gr, "fecs_inst", &gr->fuc409c) ||
  281. gf100_gr_ctor_fw(gr, "fecs_data", &gr->fuc409d) ||
  282. gf100_gr_ctor_fw(gr, "gpccs_inst", &gr->fuc41ac) ||
  283. gf100_gr_ctor_fw(gr, "gpccs_data", &gr->fuc41ad))
  284. return -ENODEV;
  285. ret = gk20a_gr_av_to_init(gr, "sw_nonctx", &gr->fuc_sw_nonctx);
  286. if (ret)
  287. return ret;
  288. ret = gk20a_gr_aiv_to_init(gr, "sw_ctx", &gr->fuc_sw_ctx);
  289. if (ret)
  290. return ret;
  291. ret = gk20a_gr_av_to_init(gr, "sw_bundle_init", &gr->fuc_bundle);
  292. if (ret)
  293. return ret;
  294. ret = gk20a_gr_av_to_method(gr, "sw_method_init", &gr->fuc_method);
  295. if (ret)
  296. return ret;
  297. return 0;
  298. }