nvc0_graph.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778
  1. /*
  2. * Copyright 2010 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 <linux/firmware.h>
  25. #include "drmP.h"
  26. #include "nouveau_drv.h"
  27. #include "nouveau_mm.h"
  28. #include "nvc0_graph.h"
  29. static void nvc0_graph_isr(struct drm_device *);
  30. static int nvc0_graph_unload_context_to(struct drm_device *dev, u64 chan);
  31. void
  32. nvc0_graph_fifo_access(struct drm_device *dev, bool enabled)
  33. {
  34. }
  35. struct nouveau_channel *
  36. nvc0_graph_channel(struct drm_device *dev)
  37. {
  38. return NULL;
  39. }
  40. static int
  41. nvc0_graph_construct_context(struct nouveau_channel *chan)
  42. {
  43. struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
  44. struct nvc0_graph_priv *priv = dev_priv->engine.graph.priv;
  45. struct nvc0_graph_chan *grch = chan->pgraph_ctx;
  46. struct drm_device *dev = chan->dev;
  47. int ret, i;
  48. u32 *ctx;
  49. ctx = kmalloc(priv->grctx_size, GFP_KERNEL);
  50. if (!ctx)
  51. return -ENOMEM;
  52. nvc0_graph_load_context(chan);
  53. nv_wo32(grch->grctx, 0x1c, 1);
  54. nv_wo32(grch->grctx, 0x20, 0);
  55. nv_wo32(grch->grctx, 0x28, 0);
  56. nv_wo32(grch->grctx, 0x2c, 0);
  57. dev_priv->engine.instmem.flush(dev);
  58. ret = nvc0_grctx_generate(chan);
  59. if (ret) {
  60. kfree(ctx);
  61. return ret;
  62. }
  63. ret = nvc0_graph_unload_context_to(dev, chan->ramin->vinst);
  64. if (ret) {
  65. kfree(ctx);
  66. return ret;
  67. }
  68. for (i = 0; i < priv->grctx_size; i += 4)
  69. ctx[i / 4] = nv_ro32(grch->grctx, i);
  70. priv->grctx_vals = ctx;
  71. return 0;
  72. }
  73. static int
  74. nvc0_graph_create_context_mmio_list(struct nouveau_channel *chan)
  75. {
  76. struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
  77. struct nvc0_graph_priv *priv = dev_priv->engine.graph.priv;
  78. struct nvc0_graph_chan *grch = chan->pgraph_ctx;
  79. struct drm_device *dev = chan->dev;
  80. int i = 0, gpc, tp, ret;
  81. u32 magic;
  82. ret = nouveau_gpuobj_new(dev, NULL, 0x2000, 256, NVOBJ_FLAG_VM,
  83. &grch->unk408004);
  84. if (ret)
  85. return ret;
  86. ret = nouveau_gpuobj_new(dev, NULL, 0x8000, 256, NVOBJ_FLAG_VM,
  87. &grch->unk40800c);
  88. if (ret)
  89. return ret;
  90. ret = nouveau_gpuobj_new(dev, NULL, 384 * 1024, 4096, NVOBJ_FLAG_VM,
  91. &grch->unk418810);
  92. if (ret)
  93. return ret;
  94. ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 0, NVOBJ_FLAG_VM,
  95. &grch->mmio);
  96. if (ret)
  97. return ret;
  98. nv_wo32(grch->mmio, i++ * 4, 0x00408004);
  99. nv_wo32(grch->mmio, i++ * 4, grch->unk408004->vinst >> 8);
  100. nv_wo32(grch->mmio, i++ * 4, 0x00408008);
  101. nv_wo32(grch->mmio, i++ * 4, 0x80000018);
  102. nv_wo32(grch->mmio, i++ * 4, 0x0040800c);
  103. nv_wo32(grch->mmio, i++ * 4, grch->unk40800c->vinst >> 8);
  104. nv_wo32(grch->mmio, i++ * 4, 0x00408010);
  105. nv_wo32(grch->mmio, i++ * 4, 0x80000000);
  106. nv_wo32(grch->mmio, i++ * 4, 0x00418810);
  107. nv_wo32(grch->mmio, i++ * 4, 0x80000000 | grch->unk418810->vinst >> 12);
  108. nv_wo32(grch->mmio, i++ * 4, 0x00419848);
  109. nv_wo32(grch->mmio, i++ * 4, 0x10000000 | grch->unk418810->vinst >> 12);
  110. nv_wo32(grch->mmio, i++ * 4, 0x00419004);
  111. nv_wo32(grch->mmio, i++ * 4, grch->unk40800c->vinst >> 8);
  112. nv_wo32(grch->mmio, i++ * 4, 0x00419008);
  113. nv_wo32(grch->mmio, i++ * 4, 0x00000000);
  114. nv_wo32(grch->mmio, i++ * 4, 0x00418808);
  115. nv_wo32(grch->mmio, i++ * 4, grch->unk408004->vinst >> 8);
  116. nv_wo32(grch->mmio, i++ * 4, 0x0041880c);
  117. nv_wo32(grch->mmio, i++ * 4, 0x80000018);
  118. magic = 0x02180000;
  119. nv_wo32(grch->mmio, i++ * 4, 0x00405830);
  120. nv_wo32(grch->mmio, i++ * 4, magic);
  121. for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
  122. for (tp = 0; tp < priv->tp_nr[gpc]; tp++, magic += 0x02fc) {
  123. u32 reg = 0x504520 + (gpc * 0x8000) + (tp * 0x0800);
  124. nv_wo32(grch->mmio, i++ * 4, reg);
  125. nv_wo32(grch->mmio, i++ * 4, magic);
  126. }
  127. }
  128. grch->mmio_nr = i / 2;
  129. return 0;
  130. }
  131. int
  132. nvc0_graph_create_context(struct nouveau_channel *chan)
  133. {
  134. struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
  135. struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
  136. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  137. struct nvc0_graph_priv *priv = pgraph->priv;
  138. struct nvc0_graph_chan *grch;
  139. struct drm_device *dev = chan->dev;
  140. struct nouveau_gpuobj *grctx;
  141. int ret, i;
  142. chan->pgraph_ctx = kzalloc(sizeof(*grch), GFP_KERNEL);
  143. if (!chan->pgraph_ctx)
  144. return -ENOMEM;
  145. grch = chan->pgraph_ctx;
  146. ret = nouveau_gpuobj_new(dev, NULL, priv->grctx_size, 256,
  147. NVOBJ_FLAG_VM | NVOBJ_FLAG_ZERO_ALLOC,
  148. &grch->grctx);
  149. if (ret)
  150. goto error;
  151. chan->ramin_grctx = grch->grctx;
  152. grctx = grch->grctx;
  153. ret = nvc0_graph_create_context_mmio_list(chan);
  154. if (ret)
  155. goto error;
  156. nv_wo32(chan->ramin, 0x0210, lower_32_bits(grctx->vinst) | 4);
  157. nv_wo32(chan->ramin, 0x0214, upper_32_bits(grctx->vinst));
  158. pinstmem->flush(dev);
  159. if (!priv->grctx_vals) {
  160. ret = nvc0_graph_construct_context(chan);
  161. if (ret)
  162. goto error;
  163. }
  164. for (i = 0; i < priv->grctx_size; i += 4)
  165. nv_wo32(grctx, i, priv->grctx_vals[i / 4]);
  166. nv_wo32(grctx, 0xf4, 0);
  167. nv_wo32(grctx, 0xf8, 0);
  168. nv_wo32(grctx, 0x10, grch->mmio_nr);
  169. nv_wo32(grctx, 0x14, lower_32_bits(grch->mmio->vinst));
  170. nv_wo32(grctx, 0x18, upper_32_bits(grch->mmio->vinst));
  171. nv_wo32(grctx, 0x1c, 1);
  172. nv_wo32(grctx, 0x20, 0);
  173. nv_wo32(grctx, 0x28, 0);
  174. nv_wo32(grctx, 0x2c, 0);
  175. pinstmem->flush(dev);
  176. return 0;
  177. error:
  178. pgraph->destroy_context(chan);
  179. return ret;
  180. }
  181. void
  182. nvc0_graph_destroy_context(struct nouveau_channel *chan)
  183. {
  184. struct nvc0_graph_chan *grch;
  185. grch = chan->pgraph_ctx;
  186. chan->pgraph_ctx = NULL;
  187. if (!grch)
  188. return;
  189. nouveau_gpuobj_ref(NULL, &grch->mmio);
  190. nouveau_gpuobj_ref(NULL, &grch->unk418810);
  191. nouveau_gpuobj_ref(NULL, &grch->unk40800c);
  192. nouveau_gpuobj_ref(NULL, &grch->unk408004);
  193. nouveau_gpuobj_ref(NULL, &grch->grctx);
  194. chan->ramin_grctx = NULL;
  195. }
  196. int
  197. nvc0_graph_load_context(struct nouveau_channel *chan)
  198. {
  199. struct drm_device *dev = chan->dev;
  200. nv_wr32(dev, 0x409840, 0x00000030);
  201. nv_wr32(dev, 0x409500, 0x80000000 | chan->ramin->vinst >> 12);
  202. nv_wr32(dev, 0x409504, 0x00000003);
  203. if (!nv_wait(dev, 0x409800, 0x00000010, 0x00000010))
  204. NV_ERROR(dev, "PGRAPH: load_ctx timeout\n");
  205. return 0;
  206. }
  207. static int
  208. nvc0_graph_unload_context_to(struct drm_device *dev, u64 chan)
  209. {
  210. nv_wr32(dev, 0x409840, 0x00000003);
  211. nv_wr32(dev, 0x409500, 0x80000000 | chan >> 12);
  212. nv_wr32(dev, 0x409504, 0x00000009);
  213. if (!nv_wait(dev, 0x409800, 0x00000001, 0x00000000)) {
  214. NV_ERROR(dev, "PGRAPH: unload_ctx timeout\n");
  215. return -EBUSY;
  216. }
  217. return 0;
  218. }
  219. int
  220. nvc0_graph_unload_context(struct drm_device *dev)
  221. {
  222. u64 inst = (u64)(nv_rd32(dev, 0x409b00) & 0x0fffffff) << 12;
  223. return nvc0_graph_unload_context_to(dev, inst);
  224. }
  225. static void
  226. nvc0_graph_destroy(struct drm_device *dev)
  227. {
  228. struct drm_nouveau_private *dev_priv = dev->dev_private;
  229. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  230. struct nvc0_graph_priv *priv;
  231. priv = pgraph->priv;
  232. if (!priv)
  233. return;
  234. nouveau_irq_unregister(dev, 12);
  235. nouveau_gpuobj_ref(NULL, &priv->unk4188b8);
  236. nouveau_gpuobj_ref(NULL, &priv->unk4188b4);
  237. if (priv->grctx_vals)
  238. kfree(priv->grctx_vals);
  239. kfree(priv);
  240. }
  241. void
  242. nvc0_graph_takedown(struct drm_device *dev)
  243. {
  244. nvc0_graph_destroy(dev);
  245. }
  246. static int
  247. nvc0_graph_create(struct drm_device *dev)
  248. {
  249. struct drm_nouveau_private *dev_priv = dev->dev_private;
  250. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  251. struct nvc0_graph_priv *priv;
  252. int ret, gpc, i;
  253. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  254. if (!priv)
  255. return -ENOMEM;
  256. pgraph->priv = priv;
  257. ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 256, 0, &priv->unk4188b4);
  258. if (ret)
  259. goto error;
  260. ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 256, 0, &priv->unk4188b8);
  261. if (ret)
  262. goto error;
  263. for (i = 0; i < 0x1000; i += 4) {
  264. nv_wo32(priv->unk4188b4, i, 0x00000010);
  265. nv_wo32(priv->unk4188b8, i, 0x00000010);
  266. }
  267. priv->gpc_nr = nv_rd32(dev, 0x409604) & 0x0000001f;
  268. priv->rop_nr = (nv_rd32(dev, 0x409604) & 0x001f0000) >> 16;
  269. for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
  270. priv->tp_nr[gpc] = nv_rd32(dev, GPC_UNIT(gpc, 0x2608));
  271. priv->tp_total += priv->tp_nr[gpc];
  272. }
  273. /*XXX: these need figuring out... */
  274. switch (dev_priv->chipset) {
  275. case 0xc0:
  276. if (priv->tp_total == 11) { /* 465, 3/4/4/0, 4 */
  277. priv->magic_not_rop_nr = 0x07;
  278. /* filled values up to tp_total, the rest 0 */
  279. priv->magicgpc980[0] = 0x22111000;
  280. priv->magicgpc980[1] = 0x00000233;
  281. priv->magicgpc980[2] = 0x00000000;
  282. priv->magicgpc980[3] = 0x00000000;
  283. priv->magicgpc918 = 0x000ba2e9;
  284. } else
  285. if (priv->tp_total == 14) { /* 470, 3/3/4/4, 5 */
  286. priv->magic_not_rop_nr = 0x05;
  287. priv->magicgpc980[0] = 0x11110000;
  288. priv->magicgpc980[1] = 0x00233222;
  289. priv->magicgpc980[2] = 0x00000000;
  290. priv->magicgpc980[3] = 0x00000000;
  291. priv->magicgpc918 = 0x00092493;
  292. } else
  293. if (priv->tp_total == 15) { /* 480, 3/4/4/4, 6 */
  294. priv->magic_not_rop_nr = 0x06;
  295. priv->magicgpc980[0] = 0x11110000;
  296. priv->magicgpc980[1] = 0x03332222;
  297. priv->magicgpc980[2] = 0x00000000;
  298. priv->magicgpc980[3] = 0x00000000;
  299. priv->magicgpc918 = 0x00088889;
  300. }
  301. break;
  302. case 0xc3: /* 450, 4/0/0/0, 2 */
  303. priv->magic_not_rop_nr = 0x03;
  304. priv->magicgpc980[0] = 0x00003210;
  305. priv->magicgpc980[1] = 0x00000000;
  306. priv->magicgpc980[2] = 0x00000000;
  307. priv->magicgpc980[3] = 0x00000000;
  308. priv->magicgpc918 = 0x00200000;
  309. break;
  310. case 0xc4: /* 460, 3/4/0/0, 4 */
  311. priv->magic_not_rop_nr = 0x01;
  312. priv->magicgpc980[0] = 0x02321100;
  313. priv->magicgpc980[1] = 0x00000000;
  314. priv->magicgpc980[2] = 0x00000000;
  315. priv->magicgpc980[3] = 0x00000000;
  316. priv->magicgpc918 = 0x00124925;
  317. break;
  318. }
  319. if (!priv->magic_not_rop_nr) {
  320. NV_ERROR(dev, "PGRAPH: unknown config: %d/%d/%d/%d, %d\n",
  321. priv->tp_nr[0], priv->tp_nr[1], priv->tp_nr[2],
  322. priv->tp_nr[3], priv->rop_nr);
  323. /* use 0xc3's values... */
  324. priv->magic_not_rop_nr = 0x03;
  325. priv->magicgpc980[0] = 0x00003210;
  326. priv->magicgpc980[1] = 0x00000000;
  327. priv->magicgpc980[2] = 0x00000000;
  328. priv->magicgpc980[3] = 0x00000000;
  329. priv->magicgpc918 = 0x00200000;
  330. }
  331. nouveau_irq_register(dev, 12, nvc0_graph_isr);
  332. NVOBJ_CLASS(dev, 0x902d, GR); /* 2D */
  333. NVOBJ_CLASS(dev, 0x9039, GR); /* M2MF */
  334. NVOBJ_CLASS(dev, 0x9097, GR); /* 3D */
  335. NVOBJ_CLASS(dev, 0x90c0, GR); /* COMPUTE */
  336. return 0;
  337. error:
  338. nvc0_graph_destroy(dev);
  339. return ret;
  340. }
  341. static void
  342. nvc0_graph_init_obj418880(struct drm_device *dev)
  343. {
  344. struct drm_nouveau_private *dev_priv = dev->dev_private;
  345. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  346. struct nvc0_graph_priv *priv = pgraph->priv;
  347. int i;
  348. nv_wr32(dev, GPC_BCAST(0x0880), 0x00000000);
  349. nv_wr32(dev, GPC_BCAST(0x08a4), 0x00000000);
  350. for (i = 0; i < 4; i++)
  351. nv_wr32(dev, GPC_BCAST(0x0888) + (i * 4), 0x00000000);
  352. nv_wr32(dev, GPC_BCAST(0x08b4), priv->unk4188b4->vinst >> 8);
  353. nv_wr32(dev, GPC_BCAST(0x08b8), priv->unk4188b8->vinst >> 8);
  354. }
  355. static void
  356. nvc0_graph_init_regs(struct drm_device *dev)
  357. {
  358. nv_wr32(dev, 0x400080, 0x003083c2);
  359. nv_wr32(dev, 0x400088, 0x00006fe7);
  360. nv_wr32(dev, 0x40008c, 0x00000000);
  361. nv_wr32(dev, 0x400090, 0x00000030);
  362. nv_wr32(dev, 0x40013c, 0x013901f7);
  363. nv_wr32(dev, 0x400140, 0x00000100);
  364. nv_wr32(dev, 0x400144, 0x00000000);
  365. nv_wr32(dev, 0x400148, 0x00000110);
  366. nv_wr32(dev, 0x400138, 0x00000000);
  367. nv_wr32(dev, 0x400130, 0x00000000);
  368. nv_wr32(dev, 0x400134, 0x00000000);
  369. nv_wr32(dev, 0x400124, 0x00000002);
  370. }
  371. static void
  372. nvc0_graph_init_gpc_0(struct drm_device *dev)
  373. {
  374. struct drm_nouveau_private *dev_priv = dev->dev_private;
  375. struct nvc0_graph_priv *priv = dev_priv->engine.graph.priv;
  376. int gpc;
  377. // TP ROP UNKVAL(magic_not_rop_nr)
  378. // 450: 4/0/0/0 2 3
  379. // 460: 3/4/0/0 4 1
  380. // 465: 3/4/4/0 4 7
  381. // 470: 3/3/4/4 5 5
  382. // 480: 3/4/4/4 6 6
  383. // magicgpc918
  384. // 450: 00200000 00000000001000000000000000000000
  385. // 460: 00124925 00000000000100100100100100100101
  386. // 465: 000ba2e9 00000000000010111010001011101001
  387. // 470: 00092493 00000000000010010010010010010011
  388. // 480: 00088889 00000000000010001000100010001001
  389. /* filled values up to tp_total, remainder 0 */
  390. // 450: 00003210 00000000 00000000 00000000
  391. // 460: 02321100 00000000 00000000 00000000
  392. // 465: 22111000 00000233 00000000 00000000
  393. // 470: 11110000 00233222 00000000 00000000
  394. // 480: 11110000 03332222 00000000 00000000
  395. nv_wr32(dev, GPC_BCAST(0x0980), priv->magicgpc980[0]);
  396. nv_wr32(dev, GPC_BCAST(0x0984), priv->magicgpc980[1]);
  397. nv_wr32(dev, GPC_BCAST(0x0988), priv->magicgpc980[2]);
  398. nv_wr32(dev, GPC_BCAST(0x098c), priv->magicgpc980[3]);
  399. for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
  400. nv_wr32(dev, GPC_UNIT(gpc, 0x0914), priv->magic_not_rop_nr << 8 |
  401. priv->tp_nr[gpc]);
  402. nv_wr32(dev, GPC_UNIT(gpc, 0x0910), 0x00040000 | priv->tp_total);
  403. nv_wr32(dev, GPC_UNIT(gpc, 0x0918), priv->magicgpc918);
  404. }
  405. nv_wr32(dev, GPC_BCAST(0x1bd4), priv->magicgpc918);
  406. nv_wr32(dev, GPC_BCAST(0x08ac), priv->rop_nr);
  407. }
  408. static void
  409. nvc0_graph_init_units(struct drm_device *dev)
  410. {
  411. nv_wr32(dev, 0x409c24, 0x000f0000);
  412. nv_wr32(dev, 0x404000, 0xc0000000); /* DISPATCH */
  413. nv_wr32(dev, 0x404600, 0xc0000000); /* M2MF */
  414. nv_wr32(dev, 0x408030, 0xc0000000);
  415. nv_wr32(dev, 0x40601c, 0xc0000000);
  416. nv_wr32(dev, 0x404490, 0xc0000000); /* MACRO */
  417. nv_wr32(dev, 0x406018, 0xc0000000);
  418. nv_wr32(dev, 0x405840, 0xc0000000);
  419. nv_wr32(dev, 0x405844, 0x00ffffff);
  420. nv_mask(dev, 0x419cc0, 0x00000008, 0x00000008);
  421. nv_mask(dev, 0x419eb4, 0x00001000, 0x00001000);
  422. }
  423. static void
  424. nvc0_graph_init_gpc_1(struct drm_device *dev)
  425. {
  426. struct drm_nouveau_private *dev_priv = dev->dev_private;
  427. struct nvc0_graph_priv *priv = dev_priv->engine.graph.priv;
  428. int gpc, tp;
  429. for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
  430. nv_wr32(dev, GPC_UNIT(gpc, 0x0420), 0xc0000000);
  431. nv_wr32(dev, GPC_UNIT(gpc, 0x0900), 0xc0000000);
  432. nv_wr32(dev, GPC_UNIT(gpc, 0x1028), 0xc0000000);
  433. nv_wr32(dev, GPC_UNIT(gpc, 0x0824), 0xc0000000);
  434. for (tp = 0; tp < priv->tp_nr[gpc]; tp++) {
  435. nv_wr32(dev, TP_UNIT(gpc, tp, 0x508), 0xffffffff);
  436. nv_wr32(dev, TP_UNIT(gpc, tp, 0x50c), 0xffffffff);
  437. nv_wr32(dev, TP_UNIT(gpc, tp, 0x224), 0xc0000000);
  438. nv_wr32(dev, TP_UNIT(gpc, tp, 0x48c), 0xc0000000);
  439. nv_wr32(dev, TP_UNIT(gpc, tp, 0x084), 0xc0000000);
  440. nv_wr32(dev, TP_UNIT(gpc, tp, 0xe44), 0x001ffffe);
  441. nv_wr32(dev, TP_UNIT(gpc, tp, 0xe4c), 0x0000000f);
  442. }
  443. nv_wr32(dev, GPC_UNIT(gpc, 0x2c90), 0xffffffff);
  444. nv_wr32(dev, GPC_UNIT(gpc, 0x2c94), 0xffffffff);
  445. }
  446. }
  447. static void
  448. nvc0_graph_init_rop(struct drm_device *dev)
  449. {
  450. struct drm_nouveau_private *dev_priv = dev->dev_private;
  451. struct nvc0_graph_priv *priv = dev_priv->engine.graph.priv;
  452. int rop;
  453. for (rop = 0; rop < priv->rop_nr; rop++) {
  454. nv_wr32(dev, ROP_UNIT(rop, 0x144), 0xc0000000);
  455. nv_wr32(dev, ROP_UNIT(rop, 0x070), 0xc0000000);
  456. nv_wr32(dev, ROP_UNIT(rop, 0x204), 0xffffffff);
  457. nv_wr32(dev, ROP_UNIT(rop, 0x208), 0xffffffff);
  458. }
  459. }
  460. static int
  461. nvc0_fuc_load_fw(struct drm_device *dev, u32 fuc_base,
  462. const char *code_fw, const char *data_fw)
  463. {
  464. const struct firmware *fw;
  465. char name[32];
  466. int ret, i;
  467. snprintf(name, sizeof(name), "nouveau/%s", data_fw);
  468. ret = request_firmware(&fw, name, &dev->pdev->dev);
  469. if (ret) {
  470. NV_ERROR(dev, "failed to load %s\n", data_fw);
  471. return ret;
  472. }
  473. nv_wr32(dev, fuc_base + 0x01c0, 0x01000000);
  474. for (i = 0; i < fw->size / 4; i++)
  475. nv_wr32(dev, fuc_base + 0x01c4, ((u32 *)fw->data)[i]);
  476. release_firmware(fw);
  477. snprintf(name, sizeof(name), "nouveau/%s", code_fw);
  478. ret = request_firmware(&fw, name, &dev->pdev->dev);
  479. if (ret) {
  480. NV_ERROR(dev, "failed to load %s\n", code_fw);
  481. return ret;
  482. }
  483. nv_wr32(dev, fuc_base + 0x0180, 0x01000000);
  484. for (i = 0; i < fw->size / 4; i++) {
  485. if ((i & 0x3f) == 0)
  486. nv_wr32(dev, fuc_base + 0x0188, i >> 6);
  487. nv_wr32(dev, fuc_base + 0x0184, ((u32 *)fw->data)[i]);
  488. }
  489. release_firmware(fw);
  490. return 0;
  491. }
  492. static int
  493. nvc0_graph_init_ctxctl(struct drm_device *dev)
  494. {
  495. struct drm_nouveau_private *dev_priv = dev->dev_private;
  496. struct nvc0_graph_priv *priv = dev_priv->engine.graph.priv;
  497. u32 r000260;
  498. int ret;
  499. /* load fuc microcode */
  500. r000260 = nv_mask(dev, 0x000260, 0x00000001, 0x00000000);
  501. ret = nvc0_fuc_load_fw(dev, 0x409000, "fuc409c", "fuc409d");
  502. if (ret == 0)
  503. ret = nvc0_fuc_load_fw(dev, 0x41a000, "fuc41ac", "fuc41ad");
  504. nv_wr32(dev, 0x000260, r000260);
  505. if (ret)
  506. return ret;
  507. /* start both of them running */
  508. nv_wr32(dev, 0x409840, 0xffffffff);
  509. nv_wr32(dev, 0x41a10c, 0x00000000);
  510. nv_wr32(dev, 0x40910c, 0x00000000);
  511. nv_wr32(dev, 0x41a100, 0x00000002);
  512. nv_wr32(dev, 0x409100, 0x00000002);
  513. if (!nv_wait(dev, 0x409800, 0x00000001, 0x00000001))
  514. NV_INFO(dev, "0x409800 wait failed\n");
  515. nv_wr32(dev, 0x409840, 0xffffffff);
  516. nv_wr32(dev, 0x409500, 0x7fffffff);
  517. nv_wr32(dev, 0x409504, 0x00000021);
  518. nv_wr32(dev, 0x409840, 0xffffffff);
  519. nv_wr32(dev, 0x409500, 0x00000000);
  520. nv_wr32(dev, 0x409504, 0x00000010);
  521. if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
  522. NV_ERROR(dev, "fuc09 req 0x10 timeout\n");
  523. return -EBUSY;
  524. }
  525. priv->grctx_size = nv_rd32(dev, 0x409800);
  526. nv_wr32(dev, 0x409840, 0xffffffff);
  527. nv_wr32(dev, 0x409500, 0x00000000);
  528. nv_wr32(dev, 0x409504, 0x00000016);
  529. if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
  530. NV_ERROR(dev, "fuc09 req 0x16 timeout\n");
  531. return -EBUSY;
  532. }
  533. nv_wr32(dev, 0x409840, 0xffffffff);
  534. nv_wr32(dev, 0x409500, 0x00000000);
  535. nv_wr32(dev, 0x409504, 0x00000025);
  536. if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
  537. NV_ERROR(dev, "fuc09 req 0x25 timeout\n");
  538. return -EBUSY;
  539. }
  540. return 0;
  541. }
  542. int
  543. nvc0_graph_init(struct drm_device *dev)
  544. {
  545. struct drm_nouveau_private *dev_priv = dev->dev_private;
  546. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  547. struct nvc0_graph_priv *priv;
  548. int ret;
  549. dev_priv->engine.graph.accel_blocked = true;
  550. switch (dev_priv->chipset) {
  551. case 0xc0:
  552. case 0xc3:
  553. case 0xc4:
  554. break;
  555. default:
  556. NV_ERROR(dev, "PGRAPH: unsupported chipset, please report!\n");
  557. if (nouveau_noaccel != 0)
  558. return 0;
  559. break;
  560. }
  561. nv_mask(dev, 0x000200, 0x18001000, 0x00000000);
  562. nv_mask(dev, 0x000200, 0x18001000, 0x18001000);
  563. if (!pgraph->priv) {
  564. ret = nvc0_graph_create(dev);
  565. if (ret)
  566. return ret;
  567. }
  568. priv = pgraph->priv;
  569. nvc0_graph_init_obj418880(dev);
  570. nvc0_graph_init_regs(dev);
  571. //nvc0_graph_init_unitplemented_magics(dev);
  572. nvc0_graph_init_gpc_0(dev);
  573. //nvc0_graph_init_unitplemented_c242(dev);
  574. nv_wr32(dev, 0x400500, 0x00010001);
  575. nv_wr32(dev, 0x400100, 0xffffffff);
  576. nv_wr32(dev, 0x40013c, 0xffffffff);
  577. nvc0_graph_init_units(dev);
  578. nvc0_graph_init_gpc_1(dev);
  579. nvc0_graph_init_rop(dev);
  580. nv_wr32(dev, 0x400108, 0xffffffff);
  581. nv_wr32(dev, 0x400138, 0xffffffff);
  582. nv_wr32(dev, 0x400118, 0xffffffff);
  583. nv_wr32(dev, 0x400130, 0xffffffff);
  584. nv_wr32(dev, 0x40011c, 0xffffffff);
  585. nv_wr32(dev, 0x400134, 0xffffffff);
  586. nv_wr32(dev, 0x400054, 0x34ce3464);
  587. ret = nvc0_graph_init_ctxctl(dev);
  588. if (ret == 0)
  589. dev_priv->engine.graph.accel_blocked = false;
  590. return 0;
  591. }
  592. static int
  593. nvc0_graph_isr_chid(struct drm_device *dev, u64 inst)
  594. {
  595. struct drm_nouveau_private *dev_priv = dev->dev_private;
  596. struct nouveau_channel *chan;
  597. unsigned long flags;
  598. int i;
  599. spin_lock_irqsave(&dev_priv->channels.lock, flags);
  600. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  601. chan = dev_priv->channels.ptr[i];
  602. if (!chan || !chan->ramin)
  603. continue;
  604. if (inst == chan->ramin->vinst)
  605. break;
  606. }
  607. spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
  608. return i;
  609. }
  610. static void
  611. nvc0_graph_isr(struct drm_device *dev)
  612. {
  613. u64 inst = (u64)(nv_rd32(dev, 0x409b00) & 0x0fffffff) << 12;
  614. u32 chid = nvc0_graph_isr_chid(dev, inst);
  615. u32 stat = nv_rd32(dev, 0x400100);
  616. u32 addr = nv_rd32(dev, 0x400704);
  617. u32 mthd = (addr & 0x00003ffc);
  618. u32 subc = (addr & 0x00070000) >> 16;
  619. u32 data = nv_rd32(dev, 0x400708);
  620. u32 code = nv_rd32(dev, 0x400110);
  621. u32 class = nv_rd32(dev, 0x404200 + (subc * 4));
  622. if (stat & 0x00000010) {
  623. NV_INFO(dev, "PGRAPH: ILLEGAL_MTHD ch %d [0x%010llx] subc %d "
  624. "class 0x%04x mthd 0x%04x data 0x%08x\n",
  625. chid, inst, subc, class, mthd, data);
  626. nv_wr32(dev, 0x400100, 0x00000010);
  627. stat &= ~0x00000010;
  628. }
  629. if (stat & 0x00000020) {
  630. NV_INFO(dev, "PGRAPH: ILLEGAL_CLASS ch %d [0x%010llx] subc %d "
  631. "class 0x%04x mthd 0x%04x data 0x%08x\n",
  632. chid, inst, subc, class, mthd, data);
  633. nv_wr32(dev, 0x400100, 0x00000020);
  634. stat &= ~0x00000020;
  635. }
  636. if (stat & 0x00100000) {
  637. NV_INFO(dev, "PGRAPH: DATA_ERROR [");
  638. nouveau_enum_print(nv50_data_error_names, code);
  639. printk("] ch %d [0x%010llx] subc %d class 0x%04x "
  640. "mthd 0x%04x data 0x%08x\n",
  641. chid, inst, subc, class, mthd, data);
  642. nv_wr32(dev, 0x400100, 0x00100000);
  643. stat &= ~0x00100000;
  644. }
  645. if (stat & 0x00200000) {
  646. u32 trap = nv_rd32(dev, 0x400108);
  647. NV_INFO(dev, "PGRAPH: TRAP ch %d status 0x%08x\n", chid, trap);
  648. nv_wr32(dev, 0x400108, trap);
  649. nv_wr32(dev, 0x400100, 0x00200000);
  650. stat &= ~0x00200000;
  651. }
  652. if (stat & 0x00080000) {
  653. u32 ustat = nv_rd32(dev, 0x409c18);
  654. NV_INFO(dev, "PGRAPH: CTXCTRL ustat 0x%08x\n", ustat);
  655. nv_wr32(dev, 0x409c20, ustat);
  656. nv_wr32(dev, 0x400100, 0x00080000);
  657. stat &= ~0x00080000;
  658. }
  659. if (stat) {
  660. NV_INFO(dev, "PGRAPH: unknown stat 0x%08x\n", stat);
  661. nv_wr32(dev, 0x400100, stat);
  662. }
  663. nv_wr32(dev, 0x400500, 0x00010001);
  664. }