nvc0_graph.c 22 KB

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