nve0_graph.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  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 <linux/module.h>
  26. #include "drmP.h"
  27. #include "nouveau_drv.h"
  28. #include "nouveau_mm.h"
  29. #include "nouveau_fifo.h"
  30. #include "nve0_graph.h"
  31. static void
  32. nve0_graph_ctxctl_debug_unit(struct drm_device *dev, u32 base)
  33. {
  34. NV_INFO(dev, "PGRAPH: %06x - done 0x%08x\n", base,
  35. nv_rd32(dev, base + 0x400));
  36. NV_INFO(dev, "PGRAPH: %06x - stat 0x%08x 0x%08x 0x%08x 0x%08x\n", base,
  37. nv_rd32(dev, base + 0x800), nv_rd32(dev, base + 0x804),
  38. nv_rd32(dev, base + 0x808), nv_rd32(dev, base + 0x80c));
  39. NV_INFO(dev, "PGRAPH: %06x - stat 0x%08x 0x%08x 0x%08x 0x%08x\n", base,
  40. nv_rd32(dev, base + 0x810), nv_rd32(dev, base + 0x814),
  41. nv_rd32(dev, base + 0x818), nv_rd32(dev, base + 0x81c));
  42. }
  43. static void
  44. nve0_graph_ctxctl_debug(struct drm_device *dev)
  45. {
  46. u32 gpcnr = nv_rd32(dev, 0x409604) & 0xffff;
  47. u32 gpc;
  48. nve0_graph_ctxctl_debug_unit(dev, 0x409000);
  49. for (gpc = 0; gpc < gpcnr; gpc++)
  50. nve0_graph_ctxctl_debug_unit(dev, 0x502000 + (gpc * 0x8000));
  51. }
  52. static int
  53. nve0_graph_load_context(struct nouveau_channel *chan)
  54. {
  55. struct drm_device *dev = chan->dev;
  56. nv_wr32(dev, 0x409840, 0x00000030);
  57. nv_wr32(dev, 0x409500, 0x80000000 | chan->ramin->vinst >> 12);
  58. nv_wr32(dev, 0x409504, 0x00000003);
  59. if (!nv_wait(dev, 0x409800, 0x00000010, 0x00000010))
  60. NV_ERROR(dev, "PGRAPH: load_ctx timeout\n");
  61. return 0;
  62. }
  63. static int
  64. nve0_graph_unload_context_to(struct drm_device *dev, u64 chan)
  65. {
  66. nv_wr32(dev, 0x409840, 0x00000003);
  67. nv_wr32(dev, 0x409500, 0x80000000 | chan >> 12);
  68. nv_wr32(dev, 0x409504, 0x00000009);
  69. if (!nv_wait(dev, 0x409800, 0x00000001, 0x00000000)) {
  70. NV_ERROR(dev, "PGRAPH: unload_ctx timeout\n");
  71. return -EBUSY;
  72. }
  73. return 0;
  74. }
  75. static int
  76. nve0_graph_construct_context(struct nouveau_channel *chan)
  77. {
  78. struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
  79. struct nve0_graph_priv *priv = nv_engine(chan->dev, NVOBJ_ENGINE_GR);
  80. struct nve0_graph_chan *grch = chan->engctx[NVOBJ_ENGINE_GR];
  81. struct drm_device *dev = chan->dev;
  82. int ret, i;
  83. u32 *ctx;
  84. ctx = kmalloc(priv->grctx_size, GFP_KERNEL);
  85. if (!ctx)
  86. return -ENOMEM;
  87. nve0_graph_load_context(chan);
  88. nv_wo32(grch->grctx, 0x1c, 1);
  89. nv_wo32(grch->grctx, 0x20, 0);
  90. nv_wo32(grch->grctx, 0x28, 0);
  91. nv_wo32(grch->grctx, 0x2c, 0);
  92. dev_priv->engine.instmem.flush(dev);
  93. ret = nve0_grctx_generate(chan);
  94. if (ret)
  95. goto err;
  96. ret = nve0_graph_unload_context_to(dev, chan->ramin->vinst);
  97. if (ret)
  98. goto err;
  99. for (i = 0; i < priv->grctx_size; i += 4)
  100. ctx[i / 4] = nv_ro32(grch->grctx, i);
  101. priv->grctx_vals = ctx;
  102. return 0;
  103. err:
  104. kfree(ctx);
  105. return ret;
  106. }
  107. static int
  108. nve0_graph_create_context_mmio_list(struct nouveau_channel *chan)
  109. {
  110. struct nve0_graph_priv *priv = nv_engine(chan->dev, NVOBJ_ENGINE_GR);
  111. struct nve0_graph_chan *grch = chan->engctx[NVOBJ_ENGINE_GR];
  112. struct drm_device *dev = chan->dev;
  113. u32 magic[GPC_MAX][2];
  114. u16 offset = 0x0000;
  115. int gpc;
  116. int ret;
  117. ret = nouveau_gpuobj_new(dev, chan, 0x3000, 256, NVOBJ_FLAG_VM,
  118. &grch->unk408004);
  119. if (ret)
  120. return ret;
  121. ret = nouveau_gpuobj_new(dev, chan, 0x8000, 256, NVOBJ_FLAG_VM,
  122. &grch->unk40800c);
  123. if (ret)
  124. return ret;
  125. ret = nouveau_gpuobj_new(dev, chan, 384 * 1024, 4096,
  126. NVOBJ_FLAG_VM | NVOBJ_FLAG_VM_USER,
  127. &grch->unk418810);
  128. if (ret)
  129. return ret;
  130. ret = nouveau_gpuobj_new(dev, chan, 0x1000, 0, NVOBJ_FLAG_VM,
  131. &grch->mmio);
  132. if (ret)
  133. return ret;
  134. #define mmio(r,v) do { \
  135. nv_wo32(grch->mmio, (grch->mmio_nr * 8) + 0, (r)); \
  136. nv_wo32(grch->mmio, (grch->mmio_nr * 8) + 4, (v)); \
  137. grch->mmio_nr++; \
  138. } while (0)
  139. mmio(0x40800c, grch->unk40800c->linst >> 8);
  140. mmio(0x408010, 0x80000000);
  141. mmio(0x419004, grch->unk40800c->linst >> 8);
  142. mmio(0x419008, 0x00000000);
  143. mmio(0x4064cc, 0x80000000);
  144. mmio(0x408004, grch->unk408004->linst >> 8);
  145. mmio(0x408008, 0x80000030);
  146. mmio(0x418808, grch->unk408004->linst >> 8);
  147. mmio(0x41880c, 0x80000030);
  148. mmio(0x4064c8, 0x01800600);
  149. mmio(0x418810, 0x80000000 | grch->unk418810->linst >> 12);
  150. mmio(0x419848, 0x10000000 | grch->unk418810->linst >> 12);
  151. mmio(0x405830, 0x02180648);
  152. mmio(0x4064c4, 0x0192ffff);
  153. for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
  154. u16 magic0 = 0x0218 * priv->tpc_nr[gpc];
  155. u16 magic1 = 0x0648 * priv->tpc_nr[gpc];
  156. magic[gpc][0] = 0x10000000 | (magic0 << 16) | offset;
  157. magic[gpc][1] = 0x00000000 | (magic1 << 16);
  158. offset += 0x0324 * priv->tpc_nr[gpc];
  159. }
  160. for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
  161. mmio(GPC_UNIT(gpc, 0x30c0), magic[gpc][0]);
  162. mmio(GPC_UNIT(gpc, 0x30e4), magic[gpc][1] | offset);
  163. offset += 0x07ff * priv->tpc_nr[gpc];
  164. }
  165. mmio(0x17e91c, 0x06060609);
  166. mmio(0x17e920, 0x00090a05);
  167. #undef mmio
  168. return 0;
  169. }
  170. static int
  171. nve0_graph_context_new(struct nouveau_channel *chan, int engine)
  172. {
  173. struct drm_device *dev = chan->dev;
  174. struct drm_nouveau_private *dev_priv = dev->dev_private;
  175. struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
  176. struct nve0_graph_priv *priv = nv_engine(dev, engine);
  177. struct nve0_graph_chan *grch;
  178. struct nouveau_gpuobj *grctx;
  179. int ret, i;
  180. grch = kzalloc(sizeof(*grch), GFP_KERNEL);
  181. if (!grch)
  182. return -ENOMEM;
  183. chan->engctx[NVOBJ_ENGINE_GR] = grch;
  184. ret = nouveau_gpuobj_new(dev, chan, priv->grctx_size, 256,
  185. NVOBJ_FLAG_VM | NVOBJ_FLAG_ZERO_ALLOC,
  186. &grch->grctx);
  187. if (ret)
  188. goto error;
  189. grctx = grch->grctx;
  190. ret = nve0_graph_create_context_mmio_list(chan);
  191. if (ret)
  192. goto error;
  193. nv_wo32(chan->ramin, 0x0210, lower_32_bits(grctx->linst) | 4);
  194. nv_wo32(chan->ramin, 0x0214, upper_32_bits(grctx->linst));
  195. pinstmem->flush(dev);
  196. if (!priv->grctx_vals) {
  197. ret = nve0_graph_construct_context(chan);
  198. if (ret)
  199. goto error;
  200. }
  201. for (i = 0; i < priv->grctx_size; i += 4)
  202. nv_wo32(grctx, i, priv->grctx_vals[i / 4]);
  203. nv_wo32(grctx, 0xf4, 0);
  204. nv_wo32(grctx, 0xf8, 0);
  205. nv_wo32(grctx, 0x10, grch->mmio_nr);
  206. nv_wo32(grctx, 0x14, lower_32_bits(grch->mmio->linst));
  207. nv_wo32(grctx, 0x18, upper_32_bits(grch->mmio->linst));
  208. nv_wo32(grctx, 0x1c, 1);
  209. nv_wo32(grctx, 0x20, 0);
  210. nv_wo32(grctx, 0x28, 0);
  211. nv_wo32(grctx, 0x2c, 0);
  212. pinstmem->flush(dev);
  213. return 0;
  214. error:
  215. priv->base.context_del(chan, engine);
  216. return ret;
  217. }
  218. static void
  219. nve0_graph_context_del(struct nouveau_channel *chan, int engine)
  220. {
  221. struct nve0_graph_chan *grch = chan->engctx[engine];
  222. nouveau_gpuobj_ref(NULL, &grch->mmio);
  223. nouveau_gpuobj_ref(NULL, &grch->unk418810);
  224. nouveau_gpuobj_ref(NULL, &grch->unk40800c);
  225. nouveau_gpuobj_ref(NULL, &grch->unk408004);
  226. nouveau_gpuobj_ref(NULL, &grch->grctx);
  227. chan->engctx[engine] = NULL;
  228. }
  229. static int
  230. nve0_graph_object_new(struct nouveau_channel *chan, int engine,
  231. u32 handle, u16 class)
  232. {
  233. return 0;
  234. }
  235. static int
  236. nve0_graph_fini(struct drm_device *dev, int engine, bool suspend)
  237. {
  238. return 0;
  239. }
  240. static void
  241. nve0_graph_init_obj418880(struct drm_device *dev)
  242. {
  243. struct nve0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
  244. int i;
  245. nv_wr32(dev, GPC_BCAST(0x0880), 0x00000000);
  246. nv_wr32(dev, GPC_BCAST(0x08a4), 0x00000000);
  247. for (i = 0; i < 4; i++)
  248. nv_wr32(dev, GPC_BCAST(0x0888) + (i * 4), 0x00000000);
  249. nv_wr32(dev, GPC_BCAST(0x08b4), priv->unk4188b4->vinst >> 8);
  250. nv_wr32(dev, GPC_BCAST(0x08b8), priv->unk4188b8->vinst >> 8);
  251. }
  252. static void
  253. nve0_graph_init_regs(struct drm_device *dev)
  254. {
  255. nv_wr32(dev, 0x400080, 0x003083c2);
  256. nv_wr32(dev, 0x400088, 0x0001ffe7);
  257. nv_wr32(dev, 0x40008c, 0x00000000);
  258. nv_wr32(dev, 0x400090, 0x00000030);
  259. nv_wr32(dev, 0x40013c, 0x003901f7);
  260. nv_wr32(dev, 0x400140, 0x00000100);
  261. nv_wr32(dev, 0x400144, 0x00000000);
  262. nv_wr32(dev, 0x400148, 0x00000110);
  263. nv_wr32(dev, 0x400138, 0x00000000);
  264. nv_wr32(dev, 0x400130, 0x00000000);
  265. nv_wr32(dev, 0x400134, 0x00000000);
  266. nv_wr32(dev, 0x400124, 0x00000002);
  267. }
  268. static void
  269. nve0_graph_init_units(struct drm_device *dev)
  270. {
  271. nv_wr32(dev, 0x409ffc, 0x00000000);
  272. nv_wr32(dev, 0x409c14, 0x00003e3e);
  273. nv_wr32(dev, 0x409c24, 0x000f0000);
  274. nv_wr32(dev, 0x404000, 0xc0000000);
  275. nv_wr32(dev, 0x404600, 0xc0000000);
  276. nv_wr32(dev, 0x408030, 0xc0000000);
  277. nv_wr32(dev, 0x404490, 0xc0000000);
  278. nv_wr32(dev, 0x406018, 0xc0000000);
  279. nv_wr32(dev, 0x407020, 0xc0000000);
  280. nv_wr32(dev, 0x405840, 0xc0000000);
  281. nv_wr32(dev, 0x405844, 0x00ffffff);
  282. nv_mask(dev, 0x419cc0, 0x00000008, 0x00000008);
  283. nv_mask(dev, 0x419eb4, 0x00001000, 0x00001000);
  284. }
  285. static void
  286. nve0_graph_init_gpc_0(struct drm_device *dev)
  287. {
  288. struct nve0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
  289. const u32 magicgpc918 = DIV_ROUND_UP(0x00800000, priv->tpc_total);
  290. u32 data[TPC_MAX / 8];
  291. u8 tpcnr[GPC_MAX];
  292. int i, gpc, tpc;
  293. nv_wr32(dev, GPC_UNIT(0, 0x3018), 0x00000001);
  294. memset(data, 0x00, sizeof(data));
  295. memcpy(tpcnr, priv->tpc_nr, sizeof(priv->tpc_nr));
  296. for (i = 0, gpc = -1; i < priv->tpc_total; i++) {
  297. do {
  298. gpc = (gpc + 1) % priv->gpc_nr;
  299. } while (!tpcnr[gpc]);
  300. tpc = priv->tpc_nr[gpc] - tpcnr[gpc]--;
  301. data[i / 8] |= tpc << ((i % 8) * 4);
  302. }
  303. nv_wr32(dev, GPC_BCAST(0x0980), data[0]);
  304. nv_wr32(dev, GPC_BCAST(0x0984), data[1]);
  305. nv_wr32(dev, GPC_BCAST(0x0988), data[2]);
  306. nv_wr32(dev, GPC_BCAST(0x098c), data[3]);
  307. for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
  308. nv_wr32(dev, GPC_UNIT(gpc, 0x0914), priv->magic_not_rop_nr << 8 |
  309. priv->tpc_nr[gpc]);
  310. nv_wr32(dev, GPC_UNIT(gpc, 0x0910), 0x00040000 | priv->tpc_total);
  311. nv_wr32(dev, GPC_UNIT(gpc, 0x0918), magicgpc918);
  312. }
  313. nv_wr32(dev, GPC_BCAST(0x1bd4), magicgpc918);
  314. nv_wr32(dev, GPC_BCAST(0x08ac), nv_rd32(dev, 0x100800));
  315. }
  316. static void
  317. nve0_graph_init_gpc_1(struct drm_device *dev)
  318. {
  319. struct nve0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
  320. int gpc, tpc;
  321. for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
  322. nv_wr32(dev, GPC_UNIT(gpc, 0x3038), 0xc0000000);
  323. nv_wr32(dev, GPC_UNIT(gpc, 0x0420), 0xc0000000);
  324. nv_wr32(dev, GPC_UNIT(gpc, 0x0900), 0xc0000000);
  325. nv_wr32(dev, GPC_UNIT(gpc, 0x1028), 0xc0000000);
  326. nv_wr32(dev, GPC_UNIT(gpc, 0x0824), 0xc0000000);
  327. for (tpc = 0; tpc < priv->tpc_nr[gpc]; tpc++) {
  328. nv_wr32(dev, TPC_UNIT(gpc, tpc, 0x508), 0xffffffff);
  329. nv_wr32(dev, TPC_UNIT(gpc, tpc, 0x50c), 0xffffffff);
  330. nv_wr32(dev, TPC_UNIT(gpc, tpc, 0x224), 0xc0000000);
  331. nv_wr32(dev, TPC_UNIT(gpc, tpc, 0x48c), 0xc0000000);
  332. nv_wr32(dev, TPC_UNIT(gpc, tpc, 0x084), 0xc0000000);
  333. nv_wr32(dev, TPC_UNIT(gpc, tpc, 0x644), 0x001ffffe);
  334. nv_wr32(dev, TPC_UNIT(gpc, tpc, 0x64c), 0x0000000f);
  335. }
  336. nv_wr32(dev, GPC_UNIT(gpc, 0x2c90), 0xffffffff);
  337. nv_wr32(dev, GPC_UNIT(gpc, 0x2c94), 0xffffffff);
  338. }
  339. }
  340. static void
  341. nve0_graph_init_rop(struct drm_device *dev)
  342. {
  343. struct nve0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
  344. int rop;
  345. for (rop = 0; rop < priv->rop_nr; rop++) {
  346. nv_wr32(dev, ROP_UNIT(rop, 0x144), 0xc0000000);
  347. nv_wr32(dev, ROP_UNIT(rop, 0x070), 0xc0000000);
  348. nv_wr32(dev, ROP_UNIT(rop, 0x204), 0xffffffff);
  349. nv_wr32(dev, ROP_UNIT(rop, 0x208), 0xffffffff);
  350. }
  351. }
  352. static void
  353. nve0_graph_init_fuc(struct drm_device *dev, u32 fuc_base,
  354. struct nve0_graph_fuc *code, struct nve0_graph_fuc *data)
  355. {
  356. int i;
  357. nv_wr32(dev, fuc_base + 0x01c0, 0x01000000);
  358. for (i = 0; i < data->size / 4; i++)
  359. nv_wr32(dev, fuc_base + 0x01c4, data->data[i]);
  360. nv_wr32(dev, fuc_base + 0x0180, 0x01000000);
  361. for (i = 0; i < code->size / 4; i++) {
  362. if ((i & 0x3f) == 0)
  363. nv_wr32(dev, fuc_base + 0x0188, i >> 6);
  364. nv_wr32(dev, fuc_base + 0x0184, code->data[i]);
  365. }
  366. }
  367. static int
  368. nve0_graph_init_ctxctl(struct drm_device *dev)
  369. {
  370. struct nve0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
  371. u32 r000260;
  372. /* load fuc microcode */
  373. r000260 = nv_mask(dev, 0x000260, 0x00000001, 0x00000000);
  374. nve0_graph_init_fuc(dev, 0x409000, &priv->fuc409c, &priv->fuc409d);
  375. nve0_graph_init_fuc(dev, 0x41a000, &priv->fuc41ac, &priv->fuc41ad);
  376. nv_wr32(dev, 0x000260, r000260);
  377. /* start both of them running */
  378. nv_wr32(dev, 0x409840, 0xffffffff);
  379. nv_wr32(dev, 0x41a10c, 0x00000000);
  380. nv_wr32(dev, 0x40910c, 0x00000000);
  381. nv_wr32(dev, 0x41a100, 0x00000002);
  382. nv_wr32(dev, 0x409100, 0x00000002);
  383. if (!nv_wait(dev, 0x409800, 0x00000001, 0x00000001))
  384. NV_INFO(dev, "0x409800 wait failed\n");
  385. nv_wr32(dev, 0x409840, 0xffffffff);
  386. nv_wr32(dev, 0x409500, 0x7fffffff);
  387. nv_wr32(dev, 0x409504, 0x00000021);
  388. nv_wr32(dev, 0x409840, 0xffffffff);
  389. nv_wr32(dev, 0x409500, 0x00000000);
  390. nv_wr32(dev, 0x409504, 0x00000010);
  391. if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
  392. NV_ERROR(dev, "fuc09 req 0x10 timeout\n");
  393. return -EBUSY;
  394. }
  395. priv->grctx_size = nv_rd32(dev, 0x409800);
  396. nv_wr32(dev, 0x409840, 0xffffffff);
  397. nv_wr32(dev, 0x409500, 0x00000000);
  398. nv_wr32(dev, 0x409504, 0x00000016);
  399. if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
  400. NV_ERROR(dev, "fuc09 req 0x16 timeout\n");
  401. return -EBUSY;
  402. }
  403. nv_wr32(dev, 0x409840, 0xffffffff);
  404. nv_wr32(dev, 0x409500, 0x00000000);
  405. nv_wr32(dev, 0x409504, 0x00000025);
  406. if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
  407. NV_ERROR(dev, "fuc09 req 0x25 timeout\n");
  408. return -EBUSY;
  409. }
  410. nv_wr32(dev, 0x409800, 0x00000000);
  411. nv_wr32(dev, 0x409500, 0x00000001);
  412. nv_wr32(dev, 0x409504, 0x00000030);
  413. if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
  414. NV_ERROR(dev, "fuc09 req 0x30 timeout\n");
  415. return -EBUSY;
  416. }
  417. nv_wr32(dev, 0x409810, 0xb00095c8);
  418. nv_wr32(dev, 0x409800, 0x00000000);
  419. nv_wr32(dev, 0x409500, 0x00000001);
  420. nv_wr32(dev, 0x409504, 0x00000031);
  421. if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
  422. NV_ERROR(dev, "fuc09 req 0x31 timeout\n");
  423. return -EBUSY;
  424. }
  425. nv_wr32(dev, 0x409810, 0x00080420);
  426. nv_wr32(dev, 0x409800, 0x00000000);
  427. nv_wr32(dev, 0x409500, 0x00000001);
  428. nv_wr32(dev, 0x409504, 0x00000032);
  429. if (!nv_wait_ne(dev, 0x409800, 0xffffffff, 0x00000000)) {
  430. NV_ERROR(dev, "fuc09 req 0x32 timeout\n");
  431. return -EBUSY;
  432. }
  433. nv_wr32(dev, 0x409614, 0x00000070);
  434. nv_wr32(dev, 0x409614, 0x00000770);
  435. nv_wr32(dev, 0x40802c, 0x00000001);
  436. return 0;
  437. }
  438. static int
  439. nve0_graph_init(struct drm_device *dev, int engine)
  440. {
  441. int ret;
  442. nv_mask(dev, 0x000200, 0x18001000, 0x00000000);
  443. nv_mask(dev, 0x000200, 0x18001000, 0x18001000);
  444. nve0_graph_init_obj418880(dev);
  445. nve0_graph_init_regs(dev);
  446. nve0_graph_init_gpc_0(dev);
  447. nv_wr32(dev, 0x400500, 0x00010001);
  448. nv_wr32(dev, 0x400100, 0xffffffff);
  449. nv_wr32(dev, 0x40013c, 0xffffffff);
  450. nve0_graph_init_units(dev);
  451. nve0_graph_init_gpc_1(dev);
  452. nve0_graph_init_rop(dev);
  453. nv_wr32(dev, 0x400108, 0xffffffff);
  454. nv_wr32(dev, 0x400138, 0xffffffff);
  455. nv_wr32(dev, 0x400118, 0xffffffff);
  456. nv_wr32(dev, 0x400130, 0xffffffff);
  457. nv_wr32(dev, 0x40011c, 0xffffffff);
  458. nv_wr32(dev, 0x400134, 0xffffffff);
  459. nv_wr32(dev, 0x400054, 0x34ce3464);
  460. ret = nve0_graph_init_ctxctl(dev);
  461. if (ret)
  462. return ret;
  463. return 0;
  464. }
  465. int
  466. nve0_graph_isr_chid(struct drm_device *dev, u64 inst)
  467. {
  468. struct nouveau_fifo_priv *pfifo = nv_engine(dev, NVOBJ_ENGINE_FIFO);
  469. struct drm_nouveau_private *dev_priv = dev->dev_private;
  470. struct nouveau_channel *chan;
  471. unsigned long flags;
  472. int i;
  473. spin_lock_irqsave(&dev_priv->channels.lock, flags);
  474. for (i = 0; i < pfifo->channels; i++) {
  475. chan = dev_priv->channels.ptr[i];
  476. if (!chan || !chan->ramin)
  477. continue;
  478. if (inst == chan->ramin->vinst)
  479. break;
  480. }
  481. spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
  482. return i;
  483. }
  484. static void
  485. nve0_graph_ctxctl_isr(struct drm_device *dev)
  486. {
  487. u32 ustat = nv_rd32(dev, 0x409c18);
  488. if (ustat & 0x00000001)
  489. NV_INFO(dev, "PGRAPH: CTXCTRL ucode error\n");
  490. if (ustat & 0x00080000)
  491. NV_INFO(dev, "PGRAPH: CTXCTRL watchdog timeout\n");
  492. if (ustat & ~0x00080001)
  493. NV_INFO(dev, "PGRAPH: CTXCTRL 0x%08x\n", ustat);
  494. nve0_graph_ctxctl_debug(dev);
  495. nv_wr32(dev, 0x409c20, ustat);
  496. }
  497. static void
  498. nve0_graph_trap_isr(struct drm_device *dev, int chid)
  499. {
  500. struct nve0_graph_priv *priv = nv_engine(dev, NVOBJ_ENGINE_GR);
  501. u32 trap = nv_rd32(dev, 0x400108);
  502. int rop;
  503. if (trap & 0x00000001) {
  504. u32 stat = nv_rd32(dev, 0x404000);
  505. NV_INFO(dev, "PGRAPH: DISPATCH ch %d 0x%08x\n", chid, stat);
  506. nv_wr32(dev, 0x404000, 0xc0000000);
  507. nv_wr32(dev, 0x400108, 0x00000001);
  508. trap &= ~0x00000001;
  509. }
  510. if (trap & 0x00000010) {
  511. u32 stat = nv_rd32(dev, 0x405840);
  512. NV_INFO(dev, "PGRAPH: SHADER ch %d 0x%08x\n", chid, stat);
  513. nv_wr32(dev, 0x405840, 0xc0000000);
  514. nv_wr32(dev, 0x400108, 0x00000010);
  515. trap &= ~0x00000010;
  516. }
  517. if (trap & 0x02000000) {
  518. for (rop = 0; rop < priv->rop_nr; rop++) {
  519. u32 statz = nv_rd32(dev, ROP_UNIT(rop, 0x070));
  520. u32 statc = nv_rd32(dev, ROP_UNIT(rop, 0x144));
  521. NV_INFO(dev, "PGRAPH: ROP%d ch %d 0x%08x 0x%08x\n",
  522. rop, chid, statz, statc);
  523. nv_wr32(dev, ROP_UNIT(rop, 0x070), 0xc0000000);
  524. nv_wr32(dev, ROP_UNIT(rop, 0x144), 0xc0000000);
  525. }
  526. nv_wr32(dev, 0x400108, 0x02000000);
  527. trap &= ~0x02000000;
  528. }
  529. if (trap) {
  530. NV_INFO(dev, "PGRAPH: TRAP ch %d 0x%08x\n", chid, trap);
  531. nv_wr32(dev, 0x400108, trap);
  532. }
  533. }
  534. static void
  535. nve0_graph_isr(struct drm_device *dev)
  536. {
  537. u64 inst = (u64)(nv_rd32(dev, 0x409b00) & 0x0fffffff) << 12;
  538. u32 chid = nve0_graph_isr_chid(dev, inst);
  539. u32 stat = nv_rd32(dev, 0x400100);
  540. u32 addr = nv_rd32(dev, 0x400704);
  541. u32 mthd = (addr & 0x00003ffc);
  542. u32 subc = (addr & 0x00070000) >> 16;
  543. u32 data = nv_rd32(dev, 0x400708);
  544. u32 code = nv_rd32(dev, 0x400110);
  545. u32 class = nv_rd32(dev, 0x404200 + (subc * 4));
  546. if (stat & 0x00000010) {
  547. if (nouveau_gpuobj_mthd_call2(dev, chid, class, mthd, data)) {
  548. NV_INFO(dev, "PGRAPH: ILLEGAL_MTHD ch %d [0x%010llx] "
  549. "subc %d class 0x%04x mthd 0x%04x "
  550. "data 0x%08x\n",
  551. chid, inst, subc, class, mthd, data);
  552. }
  553. nv_wr32(dev, 0x400100, 0x00000010);
  554. stat &= ~0x00000010;
  555. }
  556. if (stat & 0x00000020) {
  557. NV_INFO(dev, "PGRAPH: ILLEGAL_CLASS ch %d [0x%010llx] subc %d "
  558. "class 0x%04x mthd 0x%04x data 0x%08x\n",
  559. chid, inst, subc, class, mthd, data);
  560. nv_wr32(dev, 0x400100, 0x00000020);
  561. stat &= ~0x00000020;
  562. }
  563. if (stat & 0x00100000) {
  564. NV_INFO(dev, "PGRAPH: DATA_ERROR [");
  565. nouveau_enum_print(nv50_data_error_names, code);
  566. printk("] ch %d [0x%010llx] subc %d class 0x%04x "
  567. "mthd 0x%04x data 0x%08x\n",
  568. chid, inst, subc, class, mthd, data);
  569. nv_wr32(dev, 0x400100, 0x00100000);
  570. stat &= ~0x00100000;
  571. }
  572. if (stat & 0x00200000) {
  573. nve0_graph_trap_isr(dev, chid);
  574. nv_wr32(dev, 0x400100, 0x00200000);
  575. stat &= ~0x00200000;
  576. }
  577. if (stat & 0x00080000) {
  578. nve0_graph_ctxctl_isr(dev);
  579. nv_wr32(dev, 0x400100, 0x00080000);
  580. stat &= ~0x00080000;
  581. }
  582. if (stat) {
  583. NV_INFO(dev, "PGRAPH: unknown stat 0x%08x\n", stat);
  584. nv_wr32(dev, 0x400100, stat);
  585. }
  586. nv_wr32(dev, 0x400500, 0x00010001);
  587. }
  588. static int
  589. nve0_graph_create_fw(struct drm_device *dev, const char *fwname,
  590. struct nve0_graph_fuc *fuc)
  591. {
  592. struct drm_nouveau_private *dev_priv = dev->dev_private;
  593. const struct firmware *fw;
  594. char f[32];
  595. int ret;
  596. snprintf(f, sizeof(f), "nouveau/nv%02x_%s", dev_priv->chipset, fwname);
  597. ret = request_firmware(&fw, f, &dev->pdev->dev);
  598. if (ret)
  599. return ret;
  600. fuc->size = fw->size;
  601. fuc->data = kmemdup(fw->data, fuc->size, GFP_KERNEL);
  602. release_firmware(fw);
  603. return (fuc->data != NULL) ? 0 : -ENOMEM;
  604. }
  605. static void
  606. nve0_graph_destroy_fw(struct nve0_graph_fuc *fuc)
  607. {
  608. if (fuc->data) {
  609. kfree(fuc->data);
  610. fuc->data = NULL;
  611. }
  612. }
  613. static void
  614. nve0_graph_destroy(struct drm_device *dev, int engine)
  615. {
  616. struct nve0_graph_priv *priv = nv_engine(dev, engine);
  617. nve0_graph_destroy_fw(&priv->fuc409c);
  618. nve0_graph_destroy_fw(&priv->fuc409d);
  619. nve0_graph_destroy_fw(&priv->fuc41ac);
  620. nve0_graph_destroy_fw(&priv->fuc41ad);
  621. nouveau_irq_unregister(dev, 12);
  622. nouveau_gpuobj_ref(NULL, &priv->unk4188b8);
  623. nouveau_gpuobj_ref(NULL, &priv->unk4188b4);
  624. if (priv->grctx_vals)
  625. kfree(priv->grctx_vals);
  626. NVOBJ_ENGINE_DEL(dev, GR);
  627. kfree(priv);
  628. }
  629. int
  630. nve0_graph_create(struct drm_device *dev)
  631. {
  632. struct drm_nouveau_private *dev_priv = dev->dev_private;
  633. struct nve0_graph_priv *priv;
  634. int ret, gpc, i;
  635. u32 kepler;
  636. kepler = nve0_graph_class(dev);
  637. if (!kepler) {
  638. NV_ERROR(dev, "PGRAPH: unsupported chipset, please report!\n");
  639. return 0;
  640. }
  641. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  642. if (!priv)
  643. return -ENOMEM;
  644. priv->base.destroy = nve0_graph_destroy;
  645. priv->base.init = nve0_graph_init;
  646. priv->base.fini = nve0_graph_fini;
  647. priv->base.context_new = nve0_graph_context_new;
  648. priv->base.context_del = nve0_graph_context_del;
  649. priv->base.object_new = nve0_graph_object_new;
  650. NVOBJ_ENGINE_ADD(dev, GR, &priv->base);
  651. nouveau_irq_register(dev, 12, nve0_graph_isr);
  652. NV_INFO(dev, "PGRAPH: using external firmware\n");
  653. if (nve0_graph_create_fw(dev, "fuc409c", &priv->fuc409c) ||
  654. nve0_graph_create_fw(dev, "fuc409d", &priv->fuc409d) ||
  655. nve0_graph_create_fw(dev, "fuc41ac", &priv->fuc41ac) ||
  656. nve0_graph_create_fw(dev, "fuc41ad", &priv->fuc41ad)) {
  657. ret = 0;
  658. goto error;
  659. }
  660. ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 256, 0, &priv->unk4188b4);
  661. if (ret)
  662. goto error;
  663. ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 256, 0, &priv->unk4188b8);
  664. if (ret)
  665. goto error;
  666. for (i = 0; i < 0x1000; i += 4) {
  667. nv_wo32(priv->unk4188b4, i, 0x00000010);
  668. nv_wo32(priv->unk4188b8, i, 0x00000010);
  669. }
  670. priv->gpc_nr = nv_rd32(dev, 0x409604) & 0x0000001f;
  671. priv->rop_nr = (nv_rd32(dev, 0x409604) & 0x001f0000) >> 16;
  672. for (gpc = 0; gpc < priv->gpc_nr; gpc++) {
  673. priv->tpc_nr[gpc] = nv_rd32(dev, GPC_UNIT(gpc, 0x2608));
  674. priv->tpc_total += priv->tpc_nr[gpc];
  675. }
  676. switch (dev_priv->chipset) {
  677. case 0xe4:
  678. if (priv->tpc_total == 8)
  679. priv->magic_not_rop_nr = 3;
  680. else
  681. if (priv->tpc_total == 7)
  682. priv->magic_not_rop_nr = 1;
  683. break;
  684. case 0xe7:
  685. priv->magic_not_rop_nr = 1;
  686. break;
  687. default:
  688. break;
  689. }
  690. if (!priv->magic_not_rop_nr) {
  691. NV_ERROR(dev, "PGRAPH: unknown config: %d/%d/%d/%d, %d\n",
  692. priv->tpc_nr[0], priv->tpc_nr[1], priv->tpc_nr[2],
  693. priv->tpc_nr[3], priv->rop_nr);
  694. priv->magic_not_rop_nr = 0x00;
  695. }
  696. NVOBJ_CLASS(dev, 0xa097, GR); /* subc 0: 3D */
  697. NVOBJ_CLASS(dev, 0xa0c0, GR); /* subc 1: COMPUTE */
  698. NVOBJ_CLASS(dev, 0xa040, GR); /* subc 2: P2MF */
  699. NVOBJ_CLASS(dev, 0x902d, GR); /* subc 3: 2D */
  700. NVOBJ_CLASS(dev, 0xa0b5, GR); /* subc 4: COPY */
  701. return 0;
  702. error:
  703. nve0_graph_destroy(dev, NVOBJ_ENGINE_GR);
  704. return ret;
  705. }