nvc0_graph.c 23 KB

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