nvc0_graph.c 22 KB

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