nvc0_graph.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  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. printk(KERN_ERR "load_ctx 0x%08x\n", nv_rd32(dev, 0x409b00));
  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. priv->magic419bd0 = 0x0a360000;
  280. priv->magic419be4 = 0x04c33a54;
  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->magic419bd0 = 0x043c0000;
  291. priv->magic419be4 = 0x09041208;
  292. priv->magicgpc980[0] = 0x11110000;
  293. priv->magicgpc980[1] = 0x00233222;
  294. priv->magicgpc980[2] = 0x00000000;
  295. priv->magicgpc980[3] = 0x00000000;
  296. priv->magicgpc918 = 0x00092493;
  297. } else
  298. if (priv->tp_total == 15) { /* 480, 3/4/4/4, 6 */
  299. priv->magic_not_rop_nr = 0x06;
  300. priv->magic419bd0 = 0x023e0000;
  301. priv->magic419be4 = 0x10414104;
  302. priv->magicgpc980[0] = 0x11110000;
  303. priv->magicgpc980[1] = 0x03332222;
  304. priv->magicgpc980[2] = 0x00000000;
  305. priv->magicgpc980[3] = 0x00000000;
  306. priv->magicgpc918 = 0x00088889;
  307. }
  308. break;
  309. case 0xc3: /* 450, 4/0/0/0, 2 */
  310. priv->magic_not_rop_nr = 0x03;
  311. priv->magic419bd0 = 0x00500000;
  312. priv->magic419be4 = 0x00000000;
  313. priv->magicgpc980[0] = 0x00003210;
  314. priv->magicgpc980[1] = 0x00000000;
  315. priv->magicgpc980[2] = 0x00000000;
  316. priv->magicgpc980[3] = 0x00000000;
  317. priv->magicgpc918 = 0x00200000;
  318. break;
  319. case 0xc4: /* 460, 3/4/0/0, 4 */
  320. priv->magic_not_rop_nr = 0x01;
  321. priv->magic419bd0 = 0x045c0000;
  322. priv->magic419be4 = 0x09041208;
  323. priv->magicgpc980[0] = 0x02321100;
  324. priv->magicgpc980[1] = 0x00000000;
  325. priv->magicgpc980[2] = 0x00000000;
  326. priv->magicgpc980[3] = 0x00000000;
  327. priv->magicgpc918 = 0x00124925;
  328. break;
  329. }
  330. if (!priv->magic419bd0) {
  331. NV_ERROR(dev, "PGRAPH: unknown config: %d/%d/%d/%d, %d\n",
  332. priv->tp_nr[0], priv->tp_nr[1], priv->tp_nr[2],
  333. priv->tp_nr[3], priv->rop_nr);
  334. /* use 0xc3's values... */
  335. priv->magic_not_rop_nr = 0x03;
  336. priv->magic419bd0 = 0x00500000;
  337. priv->magic419be4 = 0x00000000;
  338. priv->magicgpc980[0] = 0x00003210;
  339. priv->magicgpc980[1] = 0x00000000;
  340. priv->magicgpc980[2] = 0x00000000;
  341. priv->magicgpc980[3] = 0x00000000;
  342. priv->magicgpc918 = 0x00200000;
  343. }
  344. nouveau_irq_register(dev, 12, nvc0_graph_isr);
  345. NVOBJ_CLASS(dev, 0x902d, GR); /* 2D */
  346. NVOBJ_CLASS(dev, 0x9039, GR); /* M2MF */
  347. NVOBJ_CLASS(dev, 0x9097, GR); /* 3D */
  348. NVOBJ_CLASS(dev, 0x90c0, GR); /* COMPUTE */
  349. return 0;
  350. error:
  351. nvc0_graph_destroy(dev);
  352. return ret;
  353. }
  354. static void
  355. nvc0_graph_init_obj418880(struct drm_device *dev)
  356. {
  357. struct drm_nouveau_private *dev_priv = dev->dev_private;
  358. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  359. struct nvc0_graph_priv *priv = pgraph->priv;
  360. int i;
  361. nv_wr32(dev, GPC_BCAST(0x0880), 0x00000000);
  362. nv_wr32(dev, GPC_BCAST(0x08a4), 0x00000000);
  363. for (i = 0; i < 4; i++)
  364. nv_wr32(dev, GPC_BCAST(0x0888) + (i * 4), 0x00000000);
  365. nv_wr32(dev, GPC_BCAST(0x08b4), priv->unk4188b4->vinst >> 8);
  366. nv_wr32(dev, GPC_BCAST(0x08b8), priv->unk4188b8->vinst >> 8);
  367. }
  368. static void
  369. nvc0_graph_init_regs(struct drm_device *dev)
  370. {
  371. nv_wr32(dev, 0x400080, 0x003083c2);
  372. nv_wr32(dev, 0x400088, 0x00006fe7);
  373. nv_wr32(dev, 0x40008c, 0x00000000);
  374. nv_wr32(dev, 0x400090, 0x00000030);
  375. nv_wr32(dev, 0x40013c, 0x013901f7);
  376. nv_wr32(dev, 0x400140, 0x00000100);
  377. nv_wr32(dev, 0x400144, 0x00000000);
  378. nv_wr32(dev, 0x400148, 0x00000110);
  379. nv_wr32(dev, 0x400138, 0x00000000);
  380. nv_wr32(dev, 0x400130, 0x00000000);
  381. nv_wr32(dev, 0x400134, 0x00000000);
  382. nv_wr32(dev, 0x400124, 0x00000002);
  383. }
  384. static void
  385. nvc0_graph_init_gpc_0(struct drm_device *dev)
  386. {
  387. struct drm_nouveau_private *dev_priv = dev->dev_private;
  388. struct nvc0_graph_priv *priv = dev_priv->engine.graph.priv;
  389. int gpc;
  390. // TP ROP UNKVAL(magic_not_rop_nr)
  391. // 450: 4/0/0/0 2 3
  392. // 460: 3/4/0/0 4 1
  393. // 465: 3/4/4/0 4 7
  394. // 470: 3/3/4/4 5 5
  395. // 480: 3/4/4/4 6 6
  396. // magicgpc918
  397. // 450: 00200000 00000000001000000000000000000000
  398. // 460: 00124925 00000000000100100100100100100101
  399. // 465: 000ba2e9 00000000000010111010001011101001
  400. // 470: 00092493 00000000000010010010010010010011
  401. // 480: 00088889 00000000000010001000100010001001
  402. /* filled values up to tp_total, remainder 0 */
  403. // 450: 00003210 00000000 00000000 00000000
  404. // 460: 02321100 00000000 00000000 00000000
  405. // 465: 22111000 00000233 00000000 00000000
  406. // 470: 11110000 00233222 00000000 00000000
  407. // 480: 11110000 03332222 00000000 00000000
  408. nv_wr32(dev, GPC_BCAST(0x0980), priv->magicgpc980[0]);
  409. nv_wr32(dev, GPC_BCAST(0x0984), priv->magicgpc980[1]);
  410. nv_wr32(dev, GPC_BCAST(0x0988), priv->magicgpc980[2]);
  411. nv_wr32(dev, GPC_BCAST(0x098c), priv->magicgpc980[3]);
  412. for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
  413. nv_wr32(dev, GPC_UNIT(gpc, 0x0914), priv->magic_not_rop_nr << 8 |
  414. priv->tp_nr[gpc]);
  415. nv_wr32(dev, GPC_UNIT(gpc, 0x0910), 0x00040000 | priv->tp_total);
  416. nv_wr32(dev, GPC_UNIT(gpc, 0x0918), priv->magicgpc918);
  417. }
  418. nv_wr32(dev, GPC_BCAST(0x1bd4), priv->magicgpc918);
  419. nv_wr32(dev, GPC_BCAST(0x08ac), priv->rop_nr);
  420. }
  421. static void
  422. nvc0_graph_init_units(struct drm_device *dev)
  423. {
  424. nv_wr32(dev, 0x409c24, 0x000f0000);
  425. nv_wr32(dev, 0x404000, 0xc0000000); /* DISPATCH */
  426. nv_wr32(dev, 0x404600, 0xc0000000); /* M2MF */
  427. nv_wr32(dev, 0x408030, 0xc0000000);
  428. nv_wr32(dev, 0x40601c, 0xc0000000);
  429. nv_wr32(dev, 0x404490, 0xc0000000); /* MACRO */
  430. nv_wr32(dev, 0x406018, 0xc0000000);
  431. nv_wr32(dev, 0x405840, 0xc0000000);
  432. nv_wr32(dev, 0x405844, 0x00ffffff);
  433. nv_mask(dev, 0x419cc0, 0x00000008, 0x00000008);
  434. nv_mask(dev, 0x419eb4, 0x00001000, 0x00001000);
  435. }
  436. static void
  437. nvc0_graph_init_gpc_1(struct drm_device *dev)
  438. {
  439. struct drm_nouveau_private *dev_priv = dev->dev_private;
  440. struct nvc0_graph_priv *priv = dev_priv->engine.graph.priv;
  441. int gpc, tp;
  442. for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
  443. nv_wr32(dev, GPC_UNIT(gpc, 0x0420), 0xc0000000);
  444. nv_wr32(dev, GPC_UNIT(gpc, 0x0900), 0xc0000000);
  445. nv_wr32(dev, GPC_UNIT(gpc, 0x1028), 0xc0000000);
  446. nv_wr32(dev, GPC_UNIT(gpc, 0x0824), 0xc0000000);
  447. for (tp = 0; tp < priv->tp_nr[gpc]; tp++) {
  448. nv_wr32(dev, TP_UNIT(gpc, tp, 0x508), 0xffffffff);
  449. nv_wr32(dev, TP_UNIT(gpc, tp, 0x50c), 0xffffffff);
  450. nv_wr32(dev, TP_UNIT(gpc, tp, 0x224), 0xc0000000);
  451. nv_wr32(dev, TP_UNIT(gpc, tp, 0x48c), 0xc0000000);
  452. nv_wr32(dev, TP_UNIT(gpc, tp, 0x084), 0xc0000000);
  453. nv_wr32(dev, TP_UNIT(gpc, tp, 0xe44), 0x001ffffe);
  454. nv_wr32(dev, TP_UNIT(gpc, tp, 0xe4c), 0x0000000f);
  455. }
  456. nv_wr32(dev, GPC_UNIT(gpc, 0x2c90), 0xffffffff);
  457. nv_wr32(dev, GPC_UNIT(gpc, 0x2c94), 0xffffffff);
  458. }
  459. }
  460. static void
  461. nvc0_graph_init_rop(struct drm_device *dev)
  462. {
  463. struct drm_nouveau_private *dev_priv = dev->dev_private;
  464. struct nvc0_graph_priv *priv = dev_priv->engine.graph.priv;
  465. int rop;
  466. for (rop = 0; rop < priv->rop_nr; rop++) {
  467. nv_wr32(dev, ROP_UNIT(rop, 0x144), 0xc0000000);
  468. nv_wr32(dev, ROP_UNIT(rop, 0x070), 0xc0000000);
  469. nv_wr32(dev, ROP_UNIT(rop, 0x204), 0xffffffff);
  470. nv_wr32(dev, ROP_UNIT(rop, 0x208), 0xffffffff);
  471. }
  472. }
  473. static int
  474. nvc0_fuc_load_fw(struct drm_device *dev, u32 fuc_base,
  475. const char *code_fw, const char *data_fw)
  476. {
  477. const struct firmware *fw;
  478. char name[32];
  479. int ret, i;
  480. snprintf(name, sizeof(name), "nouveau/%s", data_fw);
  481. ret = request_firmware(&fw, name, &dev->pdev->dev);
  482. if (ret) {
  483. NV_ERROR(dev, "failed to load %s\n", data_fw);
  484. return ret;
  485. }
  486. nv_wr32(dev, fuc_base + 0x01c0, 0x01000000);
  487. for (i = 0; i < fw->size / 4; i++)
  488. nv_wr32(dev, fuc_base + 0x01c4, ((u32 *)fw->data)[i]);
  489. release_firmware(fw);
  490. snprintf(name, sizeof(name), "nouveau/%s", code_fw);
  491. ret = request_firmware(&fw, name, &dev->pdev->dev);
  492. if (ret) {
  493. NV_ERROR(dev, "failed to load %s\n", code_fw);
  494. return ret;
  495. }
  496. nv_wr32(dev, fuc_base + 0x0180, 0x01000000);
  497. for (i = 0; i < fw->size / 4; i++) {
  498. if ((i & 0x3f) == 0)
  499. nv_wr32(dev, fuc_base + 0x0188, i >> 6);
  500. nv_wr32(dev, fuc_base + 0x0184, ((u32 *)fw->data)[i]);
  501. }
  502. release_firmware(fw);
  503. return 0;
  504. }
  505. static int
  506. nvc0_graph_init_ctxctl(struct drm_device *dev)
  507. {
  508. struct drm_nouveau_private *dev_priv = dev->dev_private;
  509. struct nvc0_graph_priv *priv = dev_priv->engine.graph.priv;
  510. u32 r000260;
  511. int ret;
  512. /* load fuc microcode */
  513. r000260 = nv_mask(dev, 0x000260, 0x00000001, 0x00000000);
  514. ret = nvc0_fuc_load_fw(dev, 0x409000, "fuc409c", "fuc409d");
  515. if (ret == 0)
  516. nvc0_fuc_load_fw(dev, 0x41a000, "fuc41ac", "fuc41ad");
  517. nv_wr32(dev, 0x000260, r000260);
  518. if (ret)
  519. return ret;
  520. /* start both of them running */
  521. nv_wr32(dev, 0x409840, 0xffffffff);
  522. nv_wr32(dev, 0x41a10c, 0x00000000);
  523. nv_wr32(dev, 0x40910c, 0x00000000);
  524. nv_wr32(dev, 0x41a100, 0x00000002);
  525. nv_wr32(dev, 0x409100, 0x00000002);
  526. if (!nv_wait(dev, 0x409800, 0x00000001, 0x00000001))
  527. NV_INFO(dev, "0x409800 wait failed\n");
  528. nv_wr32(dev, 0x409840, 0xffffffff);
  529. nv_wr32(dev, 0x409500, 0x7fffffff);
  530. nv_wr32(dev, 0x409504, 0x00000021);
  531. nv_wr32(dev, 0x409840, 0xffffffff);
  532. nv_wr32(dev, 0x409500, 0x00000000);
  533. nv_wr32(dev, 0x409504, 0x00000010);
  534. if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
  535. NV_ERROR(dev, "fuc09 req 0x10 timeout\n");
  536. return -EBUSY;
  537. }
  538. priv->grctx_size = nv_rd32(dev, 0x409800);
  539. nv_wr32(dev, 0x409840, 0xffffffff);
  540. nv_wr32(dev, 0x409500, 0x00000000);
  541. nv_wr32(dev, 0x409504, 0x00000016);
  542. if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
  543. NV_ERROR(dev, "fuc09 req 0x16 timeout\n");
  544. return -EBUSY;
  545. }
  546. nv_wr32(dev, 0x409840, 0xffffffff);
  547. nv_wr32(dev, 0x409500, 0x00000000);
  548. nv_wr32(dev, 0x409504, 0x00000025);
  549. if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
  550. NV_ERROR(dev, "fuc09 req 0x25 timeout\n");
  551. return -EBUSY;
  552. }
  553. return 0;
  554. }
  555. int
  556. nvc0_graph_init(struct drm_device *dev)
  557. {
  558. struct drm_nouveau_private *dev_priv = dev->dev_private;
  559. struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph;
  560. struct nvc0_graph_priv *priv;
  561. int ret;
  562. dev_priv->engine.graph.accel_blocked = true;
  563. switch (dev_priv->chipset) {
  564. case 0xc0:
  565. case 0xc3:
  566. case 0xc4:
  567. break;
  568. default:
  569. NV_ERROR(dev, "PGRAPH: unsupported chipset, please report!\n");
  570. if (nouveau_noaccel != 0)
  571. return 0;
  572. break;
  573. }
  574. nv_mask(dev, 0x000200, 0x18001000, 0x00000000);
  575. nv_mask(dev, 0x000200, 0x18001000, 0x18001000);
  576. if (!pgraph->priv) {
  577. ret = nvc0_graph_create(dev);
  578. if (ret)
  579. return ret;
  580. }
  581. priv = pgraph->priv;
  582. nvc0_graph_init_obj418880(dev);
  583. nvc0_graph_init_regs(dev);
  584. //nvc0_graph_init_unitplemented_magics(dev);
  585. nvc0_graph_init_gpc_0(dev);
  586. //nvc0_graph_init_unitplemented_c242(dev);
  587. nv_wr32(dev, 0x400500, 0x00010001);
  588. nv_wr32(dev, 0x400100, 0xffffffff);
  589. nv_wr32(dev, 0x40013c, 0xffffffff);
  590. nvc0_graph_init_units(dev);
  591. nvc0_graph_init_gpc_1(dev);
  592. nvc0_graph_init_rop(dev);
  593. nv_wr32(dev, 0x400108, 0xffffffff);
  594. nv_wr32(dev, 0x400138, 0xffffffff);
  595. nv_wr32(dev, 0x400118, 0xffffffff);
  596. nv_wr32(dev, 0x400130, 0xffffffff);
  597. nv_wr32(dev, 0x40011c, 0xffffffff);
  598. nv_wr32(dev, 0x400134, 0xffffffff);
  599. nv_wr32(dev, 0x400054, 0x34ce3464);
  600. ret = nvc0_graph_init_ctxctl(dev);
  601. if (ret)
  602. return ret;
  603. dev_priv->engine.graph.accel_blocked = false;
  604. return 0;
  605. }
  606. static struct nouveau_enum nvc0_graph_data_error[] = {
  607. { 5, "INVALID_ENUM" },
  608. {}
  609. };
  610. static int
  611. nvc0_graph_isr_chid(struct drm_device *dev, u64 inst)
  612. {
  613. struct drm_nouveau_private *dev_priv = dev->dev_private;
  614. struct nouveau_channel *chan;
  615. unsigned long flags;
  616. int i;
  617. spin_lock_irqsave(&dev_priv->channels.lock, flags);
  618. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  619. chan = dev_priv->channels.ptr[i];
  620. if (!chan || !chan->ramin)
  621. continue;
  622. if (inst == chan->ramin->vinst)
  623. break;
  624. }
  625. spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
  626. return i;
  627. }
  628. static void
  629. nvc0_graph_isr(struct drm_device *dev)
  630. {
  631. u64 inst = (u64)(nv_rd32(dev, 0x409b00) & 0x0fffffff) << 12;
  632. u32 chid = nvc0_graph_isr_chid(dev, inst);
  633. u32 stat = nv_rd32(dev, 0x400100);
  634. u32 addr = nv_rd32(dev, 0x400704);
  635. u32 mthd = (addr & 0x00003ffc);
  636. u32 subc = (addr & 0x00070000) >> 16;
  637. u32 data = nv_rd32(dev, 0x400708);
  638. u32 code = nv_rd32(dev, 0x400110);
  639. u32 class = nv_rd32(dev, 0x404200 + (subc * 4));
  640. if (stat & 0x00000010) {
  641. NV_INFO(dev, "PGRAPH: ILLEGAL_MTHD ch %d [0x%010llx] subc %d "
  642. "class 0x%04x mthd 0x%04x data 0x%08x\n",
  643. chid, inst, subc, class, mthd, data);
  644. nv_wr32(dev, 0x400100, 0x00000010);
  645. stat &= ~0x00000010;
  646. }
  647. if (stat & 0x00100000) {
  648. NV_INFO(dev, "PGRAPH: DATA_ERROR [");
  649. nouveau_enum_print(nvc0_graph_data_error, code);
  650. printk("] ch %d [0x%010llx] subc %d class 0x%04x "
  651. "mthd 0x%04x data 0x%08x\n",
  652. chid, inst, subc, class, mthd, data);
  653. nv_wr32(dev, 0x400100, 0x00100000);
  654. stat &= ~0x00100000;
  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. }