nvc0_graph.c 22 KB

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