nvc0_graph.c 23 KB

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