nvc0_graph.c 22 KB

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