nv50_graph.c 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987
  1. /*
  2. * Copyright (C) 2007 Ben Skeggs.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include "drmP.h"
  27. #include "drm.h"
  28. #include "nouveau_drv.h"
  29. #include "nouveau_ramht.h"
  30. #include "nouveau_dma.h"
  31. #include "nouveau_vm.h"
  32. #include "nv50_evo.h"
  33. struct nv50_graph_engine {
  34. struct nouveau_exec_engine base;
  35. u32 ctxprog[512];
  36. u32 ctxprog_size;
  37. u32 grctx_size;
  38. };
  39. static void
  40. nv50_graph_fifo_access(struct drm_device *dev, bool enabled)
  41. {
  42. const uint32_t mask = 0x00010001;
  43. if (enabled)
  44. nv_wr32(dev, 0x400500, nv_rd32(dev, 0x400500) | mask);
  45. else
  46. nv_wr32(dev, 0x400500, nv_rd32(dev, 0x400500) & ~mask);
  47. }
  48. static struct nouveau_channel *
  49. nv50_graph_channel(struct drm_device *dev)
  50. {
  51. struct drm_nouveau_private *dev_priv = dev->dev_private;
  52. uint32_t inst;
  53. int i;
  54. /* Be sure we're not in the middle of a context switch or bad things
  55. * will happen, such as unloading the wrong pgraph context.
  56. */
  57. if (!nv_wait(dev, 0x400300, 0x00000001, 0x00000000))
  58. NV_ERROR(dev, "Ctxprog is still running\n");
  59. inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR);
  60. if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED))
  61. return NULL;
  62. inst = (inst & NV50_PGRAPH_CTXCTL_CUR_INSTANCE) << 12;
  63. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  64. struct nouveau_channel *chan = dev_priv->channels.ptr[i];
  65. if (chan && chan->ramin && chan->ramin->vinst == inst)
  66. return chan;
  67. }
  68. return NULL;
  69. }
  70. static int
  71. nv50_graph_do_load_context(struct drm_device *dev, uint32_t inst)
  72. {
  73. uint32_t fifo = nv_rd32(dev, 0x400500);
  74. nv_wr32(dev, 0x400500, fifo & ~1);
  75. nv_wr32(dev, 0x400784, inst);
  76. nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x40);
  77. nv_wr32(dev, 0x400320, nv_rd32(dev, 0x400320) | 0x11);
  78. nv_wr32(dev, 0x400040, 0xffffffff);
  79. (void)nv_rd32(dev, 0x400040);
  80. nv_wr32(dev, 0x400040, 0x00000000);
  81. nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 1);
  82. if (nouveau_wait_for_idle(dev))
  83. nv_wr32(dev, 0x40032c, inst | (1<<31));
  84. nv_wr32(dev, 0x400500, fifo);
  85. return 0;
  86. }
  87. static int
  88. nv50_graph_unload_context(struct drm_device *dev)
  89. {
  90. uint32_t inst;
  91. inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_CUR);
  92. if (!(inst & NV50_PGRAPH_CTXCTL_CUR_LOADED))
  93. return 0;
  94. inst &= NV50_PGRAPH_CTXCTL_CUR_INSTANCE;
  95. nouveau_wait_for_idle(dev);
  96. nv_wr32(dev, 0x400784, inst);
  97. nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) | 0x20);
  98. nv_wr32(dev, 0x400304, nv_rd32(dev, 0x400304) | 0x01);
  99. nouveau_wait_for_idle(dev);
  100. nv_wr32(dev, NV50_PGRAPH_CTXCTL_CUR, inst);
  101. return 0;
  102. }
  103. static int
  104. nv50_graph_init(struct drm_device *dev, int engine)
  105. {
  106. struct drm_nouveau_private *dev_priv = dev->dev_private;
  107. struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
  108. u32 units = nv_rd32(dev, 0x001540);
  109. int i;
  110. NV_DEBUG(dev, "\n");
  111. /* master reset */
  112. nv_mask(dev, 0x000200, 0x00201000, 0x00000000);
  113. nv_mask(dev, 0x000200, 0x00201000, 0x00201000);
  114. nv_wr32(dev, 0x40008c, 0x00000004); /* HW_CTX_SWITCH_ENABLED */
  115. /* reset/enable traps and interrupts */
  116. nv_wr32(dev, 0x400804, 0xc0000000);
  117. nv_wr32(dev, 0x406800, 0xc0000000);
  118. nv_wr32(dev, 0x400c04, 0xc0000000);
  119. nv_wr32(dev, 0x401800, 0xc0000000);
  120. nv_wr32(dev, 0x405018, 0xc0000000);
  121. nv_wr32(dev, 0x402000, 0xc0000000);
  122. for (i = 0; i < 16; i++) {
  123. if (!(units & (1 << i)))
  124. continue;
  125. if (dev_priv->chipset < 0xa0) {
  126. nv_wr32(dev, 0x408900 + (i << 12), 0xc0000000);
  127. nv_wr32(dev, 0x408e08 + (i << 12), 0xc0000000);
  128. nv_wr32(dev, 0x408314 + (i << 12), 0xc0000000);
  129. } else {
  130. nv_wr32(dev, 0x408600 + (i << 11), 0xc0000000);
  131. nv_wr32(dev, 0x408708 + (i << 11), 0xc0000000);
  132. nv_wr32(dev, 0x40831c + (i << 11), 0xc0000000);
  133. }
  134. }
  135. nv_wr32(dev, 0x400108, 0xffffffff);
  136. nv_wr32(dev, 0x400138, 0xffffffff);
  137. nv_wr32(dev, 0x400100, 0xffffffff);
  138. nv_wr32(dev, 0x40013c, 0xffffffff);
  139. nv_wr32(dev, 0x400500, 0x00010001);
  140. /* upload context program, initialise ctxctl defaults */
  141. nv_wr32(dev, 0x400324, 0x00000000);
  142. for (i = 0; i < pgraph->ctxprog_size; i++)
  143. nv_wr32(dev, 0x400328, pgraph->ctxprog[i]);
  144. nv_wr32(dev, 0x400824, 0x00000000);
  145. nv_wr32(dev, 0x400828, 0x00000000);
  146. nv_wr32(dev, 0x40082c, 0x00000000);
  147. nv_wr32(dev, 0x400830, 0x00000000);
  148. nv_wr32(dev, 0x400724, 0x00000000);
  149. nv_wr32(dev, 0x40032c, 0x00000000);
  150. nv_wr32(dev, 0x400320, 4); /* CTXCTL_CMD = NEWCTXDMA */
  151. /* some unknown zcull magic */
  152. switch (dev_priv->chipset & 0xf0) {
  153. case 0x50:
  154. case 0x80:
  155. case 0x90:
  156. nv_wr32(dev, 0x402ca8, 0x00000800);
  157. break;
  158. case 0xa0:
  159. default:
  160. nv_wr32(dev, 0x402cc0, 0x00000000);
  161. if (dev_priv->chipset == 0xa0 ||
  162. dev_priv->chipset == 0xaa ||
  163. dev_priv->chipset == 0xac) {
  164. nv_wr32(dev, 0x402ca8, 0x00000802);
  165. } else {
  166. nv_wr32(dev, 0x402cc0, 0x00000000);
  167. nv_wr32(dev, 0x402ca8, 0x00000002);
  168. }
  169. break;
  170. }
  171. /* zero out zcull regions */
  172. for (i = 0; i < 8; i++) {
  173. nv_wr32(dev, 0x402c20 + (i * 8), 0x00000000);
  174. nv_wr32(dev, 0x402c24 + (i * 8), 0x00000000);
  175. nv_wr32(dev, 0x402c28 + (i * 8), 0x00000000);
  176. nv_wr32(dev, 0x402c2c + (i * 8), 0x00000000);
  177. }
  178. return 0;
  179. }
  180. static int
  181. nv50_graph_fini(struct drm_device *dev, int engine, bool suspend)
  182. {
  183. nv_wr32(dev, 0x40013c, 0x00000000);
  184. return 0;
  185. }
  186. static int
  187. nv50_graph_context_new(struct nouveau_channel *chan, int engine)
  188. {
  189. struct drm_device *dev = chan->dev;
  190. struct drm_nouveau_private *dev_priv = dev->dev_private;
  191. struct nouveau_gpuobj *ramin = chan->ramin;
  192. struct nouveau_gpuobj *grctx = NULL;
  193. struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
  194. int hdr, ret;
  195. NV_DEBUG(dev, "ch%d\n", chan->id);
  196. ret = nouveau_gpuobj_new(dev, NULL, pgraph->grctx_size, 0,
  197. NVOBJ_FLAG_ZERO_ALLOC |
  198. NVOBJ_FLAG_ZERO_FREE, &grctx);
  199. if (ret)
  200. return ret;
  201. hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
  202. nv_wo32(ramin, hdr + 0x00, 0x00190002);
  203. nv_wo32(ramin, hdr + 0x04, grctx->vinst + grctx->size - 1);
  204. nv_wo32(ramin, hdr + 0x08, grctx->vinst);
  205. nv_wo32(ramin, hdr + 0x0c, 0);
  206. nv_wo32(ramin, hdr + 0x10, 0);
  207. nv_wo32(ramin, hdr + 0x14, 0x00010000);
  208. nv50_grctx_fill(dev, grctx);
  209. nv_wo32(grctx, 0x00000, chan->ramin->vinst >> 12);
  210. dev_priv->engine.instmem.flush(dev);
  211. atomic_inc(&chan->vm->engref[NVOBJ_ENGINE_GR]);
  212. chan->engctx[NVOBJ_ENGINE_GR] = grctx;
  213. return 0;
  214. }
  215. static void
  216. nv50_graph_context_del(struct nouveau_channel *chan, int engine)
  217. {
  218. struct nouveau_gpuobj *grctx = chan->engctx[engine];
  219. struct drm_device *dev = chan->dev;
  220. struct drm_nouveau_private *dev_priv = dev->dev_private;
  221. int i, hdr = (dev_priv->chipset == 0x50) ? 0x200 : 0x20;
  222. unsigned long flags;
  223. NV_DEBUG(dev, "ch%d\n", chan->id);
  224. if (!chan->ramin)
  225. return;
  226. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  227. nv_wr32(dev, NV03_PFIFO_CACHES, 0);
  228. nv50_graph_fifo_access(dev, false);
  229. if (nv50_graph_channel(dev) == chan)
  230. nv50_graph_unload_context(dev);
  231. for (i = hdr; i < hdr + 24; i += 4)
  232. nv_wo32(chan->ramin, i, 0);
  233. dev_priv->engine.instmem.flush(dev);
  234. nv50_graph_fifo_access(dev, true);
  235. nv_wr32(dev, NV03_PFIFO_CACHES, 1);
  236. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  237. nouveau_gpuobj_ref(NULL, &grctx);
  238. atomic_dec(&chan->vm->engref[engine]);
  239. chan->engctx[engine] = NULL;
  240. }
  241. static int
  242. nv50_graph_object_new(struct nouveau_channel *chan, int engine,
  243. u32 handle, u16 class)
  244. {
  245. struct drm_device *dev = chan->dev;
  246. struct drm_nouveau_private *dev_priv = dev->dev_private;
  247. struct nouveau_gpuobj *obj = NULL;
  248. int ret;
  249. ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
  250. if (ret)
  251. return ret;
  252. obj->engine = 1;
  253. obj->class = class;
  254. nv_wo32(obj, 0x00, class);
  255. nv_wo32(obj, 0x04, 0x00000000);
  256. nv_wo32(obj, 0x08, 0x00000000);
  257. nv_wo32(obj, 0x0c, 0x00000000);
  258. dev_priv->engine.instmem.flush(dev);
  259. ret = nouveau_ramht_insert(chan, handle, obj);
  260. nouveau_gpuobj_ref(NULL, &obj);
  261. return ret;
  262. }
  263. static void
  264. nv50_graph_context_switch(struct drm_device *dev)
  265. {
  266. uint32_t inst;
  267. nv50_graph_unload_context(dev);
  268. inst = nv_rd32(dev, NV50_PGRAPH_CTXCTL_NEXT);
  269. inst &= NV50_PGRAPH_CTXCTL_NEXT_INSTANCE;
  270. nv50_graph_do_load_context(dev, inst);
  271. nv_wr32(dev, NV40_PGRAPH_INTR_EN, nv_rd32(dev,
  272. NV40_PGRAPH_INTR_EN) | NV_PGRAPH_INTR_CONTEXT_SWITCH);
  273. }
  274. static void
  275. nv50_graph_tlb_flush(struct drm_device *dev, int engine)
  276. {
  277. nv50_vm_flush_engine(dev, 0);
  278. }
  279. static void
  280. nv84_graph_tlb_flush(struct drm_device *dev, int engine)
  281. {
  282. struct drm_nouveau_private *dev_priv = dev->dev_private;
  283. struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
  284. bool idle, timeout = false;
  285. unsigned long flags;
  286. u64 start;
  287. u32 tmp;
  288. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  289. nv_mask(dev, 0x400500, 0x00000001, 0x00000000);
  290. start = ptimer->read(dev);
  291. do {
  292. idle = true;
  293. for (tmp = nv_rd32(dev, 0x400380); tmp && idle; tmp >>= 3) {
  294. if ((tmp & 7) == 1)
  295. idle = false;
  296. }
  297. for (tmp = nv_rd32(dev, 0x400384); tmp && idle; tmp >>= 3) {
  298. if ((tmp & 7) == 1)
  299. idle = false;
  300. }
  301. for (tmp = nv_rd32(dev, 0x400388); tmp && idle; tmp >>= 3) {
  302. if ((tmp & 7) == 1)
  303. idle = false;
  304. }
  305. } while (!idle && !(timeout = ptimer->read(dev) - start > 2000000000));
  306. if (timeout) {
  307. NV_ERROR(dev, "PGRAPH TLB flush idle timeout fail: "
  308. "0x%08x 0x%08x 0x%08x 0x%08x\n",
  309. nv_rd32(dev, 0x400700), nv_rd32(dev, 0x400380),
  310. nv_rd32(dev, 0x400384), nv_rd32(dev, 0x400388));
  311. }
  312. nv50_vm_flush_engine(dev, 0);
  313. nv_mask(dev, 0x400500, 0x00000001, 0x00000001);
  314. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  315. }
  316. static struct nouveau_enum nv50_mp_exec_error_names[] = {
  317. { 3, "STACK_UNDERFLOW", NULL },
  318. { 4, "QUADON_ACTIVE", NULL },
  319. { 8, "TIMEOUT", NULL },
  320. { 0x10, "INVALID_OPCODE", NULL },
  321. { 0x40, "BREAKPOINT", NULL },
  322. {}
  323. };
  324. static struct nouveau_bitfield nv50_graph_trap_m2mf[] = {
  325. { 0x00000001, "NOTIFY" },
  326. { 0x00000002, "IN" },
  327. { 0x00000004, "OUT" },
  328. {}
  329. };
  330. static struct nouveau_bitfield nv50_graph_trap_vfetch[] = {
  331. { 0x00000001, "FAULT" },
  332. {}
  333. };
  334. static struct nouveau_bitfield nv50_graph_trap_strmout[] = {
  335. { 0x00000001, "FAULT" },
  336. {}
  337. };
  338. static struct nouveau_bitfield nv50_graph_trap_ccache[] = {
  339. { 0x00000001, "FAULT" },
  340. {}
  341. };
  342. /* There must be a *lot* of these. Will take some time to gather them up. */
  343. struct nouveau_enum nv50_data_error_names[] = {
  344. { 0x00000003, "INVALID_QUERY_OR_TEXTURE", NULL },
  345. { 0x00000004, "INVALID_VALUE", NULL },
  346. { 0x00000005, "INVALID_ENUM", NULL },
  347. { 0x00000008, "INVALID_OBJECT", NULL },
  348. { 0x00000009, "READ_ONLY_OBJECT", NULL },
  349. { 0x0000000a, "SUPERVISOR_OBJECT", NULL },
  350. { 0x0000000b, "INVALID_ADDRESS_ALIGNMENT", NULL },
  351. { 0x0000000c, "INVALID_BITFIELD", NULL },
  352. { 0x0000000d, "BEGIN_END_ACTIVE", NULL },
  353. { 0x0000000e, "SEMANTIC_COLOR_BACK_OVER_LIMIT", NULL },
  354. { 0x0000000f, "VIEWPORT_ID_NEEDS_GP", NULL },
  355. { 0x00000010, "RT_DOUBLE_BIND", NULL },
  356. { 0x00000011, "RT_TYPES_MISMATCH", NULL },
  357. { 0x00000012, "RT_LINEAR_WITH_ZETA", NULL },
  358. { 0x00000015, "FP_TOO_FEW_REGS", NULL },
  359. { 0x00000016, "ZETA_FORMAT_CSAA_MISMATCH", NULL },
  360. { 0x00000017, "RT_LINEAR_WITH_MSAA", NULL },
  361. { 0x00000018, "FP_INTERPOLANT_START_OVER_LIMIT", NULL },
  362. { 0x00000019, "SEMANTIC_LAYER_OVER_LIMIT", NULL },
  363. { 0x0000001a, "RT_INVALID_ALIGNMENT", NULL },
  364. { 0x0000001b, "SAMPLER_OVER_LIMIT", NULL },
  365. { 0x0000001c, "TEXTURE_OVER_LIMIT", NULL },
  366. { 0x0000001e, "GP_TOO_MANY_OUTPUTS", NULL },
  367. { 0x0000001f, "RT_BPP128_WITH_MS8", NULL },
  368. { 0x00000021, "Z_OUT_OF_BOUNDS", NULL },
  369. { 0x00000023, "XY_OUT_OF_BOUNDS", NULL },
  370. { 0x00000027, "CP_MORE_PARAMS_THAN_SHARED", NULL },
  371. { 0x00000028, "CP_NO_REG_SPACE_STRIPED", NULL },
  372. { 0x00000029, "CP_NO_REG_SPACE_PACKED", NULL },
  373. { 0x0000002a, "CP_NOT_ENOUGH_WARPS", NULL },
  374. { 0x0000002b, "CP_BLOCK_SIZE_MISMATCH", NULL },
  375. { 0x0000002c, "CP_NOT_ENOUGH_LOCAL_WARPS", NULL },
  376. { 0x0000002d, "CP_NOT_ENOUGH_STACK_WARPS", NULL },
  377. { 0x0000002e, "CP_NO_BLOCKDIM_LATCH", NULL },
  378. { 0x00000031, "ENG2D_FORMAT_MISMATCH", NULL },
  379. { 0x0000003f, "PRIMITIVE_ID_NEEDS_GP", NULL },
  380. { 0x00000044, "SEMANTIC_VIEWPORT_OVER_LIMIT", NULL },
  381. { 0x00000045, "SEMANTIC_COLOR_FRONT_OVER_LIMIT", NULL },
  382. { 0x00000046, "LAYER_ID_NEEDS_GP", NULL },
  383. { 0x00000047, "SEMANTIC_CLIP_OVER_LIMIT", NULL },
  384. { 0x00000048, "SEMANTIC_PTSZ_OVER_LIMIT", NULL },
  385. {}
  386. };
  387. static struct nouveau_bitfield nv50_graph_intr[] = {
  388. { 0x00000001, "NOTIFY" },
  389. { 0x00000002, "COMPUTE_QUERY" },
  390. { 0x00000010, "ILLEGAL_MTHD" },
  391. { 0x00000020, "ILLEGAL_CLASS" },
  392. { 0x00000040, "DOUBLE_NOTIFY" },
  393. { 0x00001000, "CONTEXT_SWITCH" },
  394. { 0x00010000, "BUFFER_NOTIFY" },
  395. { 0x00100000, "DATA_ERROR" },
  396. { 0x00200000, "TRAP" },
  397. { 0x01000000, "SINGLE_STEP" },
  398. {}
  399. };
  400. static void
  401. nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display)
  402. {
  403. struct drm_nouveau_private *dev_priv = dev->dev_private;
  404. uint32_t units = nv_rd32(dev, 0x1540);
  405. uint32_t addr, mp10, status, pc, oplow, ophigh;
  406. int i;
  407. int mps = 0;
  408. for (i = 0; i < 4; i++) {
  409. if (!(units & 1 << (i+24)))
  410. continue;
  411. if (dev_priv->chipset < 0xa0)
  412. addr = 0x408200 + (tpid << 12) + (i << 7);
  413. else
  414. addr = 0x408100 + (tpid << 11) + (i << 7);
  415. mp10 = nv_rd32(dev, addr + 0x10);
  416. status = nv_rd32(dev, addr + 0x14);
  417. if (!status)
  418. continue;
  419. if (display) {
  420. nv_rd32(dev, addr + 0x20);
  421. pc = nv_rd32(dev, addr + 0x24);
  422. oplow = nv_rd32(dev, addr + 0x70);
  423. ophigh = nv_rd32(dev, addr + 0x74);
  424. NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - "
  425. "TP %d MP %d: ", tpid, i);
  426. nouveau_enum_print(nv50_mp_exec_error_names, status);
  427. printk(" at %06x warp %d, opcode %08x %08x\n",
  428. pc&0xffffff, pc >> 24,
  429. oplow, ophigh);
  430. }
  431. nv_wr32(dev, addr + 0x10, mp10);
  432. nv_wr32(dev, addr + 0x14, 0);
  433. mps++;
  434. }
  435. if (!mps && display)
  436. NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: "
  437. "No MPs claiming errors?\n", tpid);
  438. }
  439. static void
  440. nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old,
  441. uint32_t ustatus_new, int display, const char *name)
  442. {
  443. struct drm_nouveau_private *dev_priv = dev->dev_private;
  444. int tps = 0;
  445. uint32_t units = nv_rd32(dev, 0x1540);
  446. int i, r;
  447. uint32_t ustatus_addr, ustatus;
  448. for (i = 0; i < 16; i++) {
  449. if (!(units & (1 << i)))
  450. continue;
  451. if (dev_priv->chipset < 0xa0)
  452. ustatus_addr = ustatus_old + (i << 12);
  453. else
  454. ustatus_addr = ustatus_new + (i << 11);
  455. ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff;
  456. if (!ustatus)
  457. continue;
  458. tps++;
  459. switch (type) {
  460. case 6: /* texture error... unknown for now */
  461. if (display) {
  462. NV_ERROR(dev, "magic set %d:\n", i);
  463. for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4)
  464. NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r,
  465. nv_rd32(dev, r));
  466. }
  467. break;
  468. case 7: /* MP error */
  469. if (ustatus & 0x04030000) {
  470. nv50_pgraph_mp_trap(dev, i, display);
  471. ustatus &= ~0x04030000;
  472. }
  473. break;
  474. case 8: /* TPDMA error */
  475. {
  476. uint32_t e0c = nv_rd32(dev, ustatus_addr + 4);
  477. uint32_t e10 = nv_rd32(dev, ustatus_addr + 8);
  478. uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc);
  479. uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10);
  480. uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14);
  481. uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18);
  482. uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c);
  483. /* 2d engine destination */
  484. if (ustatus & 0x00000010) {
  485. if (display) {
  486. NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n",
  487. i, e14, e10);
  488. NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
  489. i, e0c, e18, e1c, e20, e24);
  490. }
  491. ustatus &= ~0x00000010;
  492. }
  493. /* Render target */
  494. if (ustatus & 0x00000040) {
  495. if (display) {
  496. NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n",
  497. i, e14, e10);
  498. NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
  499. i, e0c, e18, e1c, e20, e24);
  500. }
  501. ustatus &= ~0x00000040;
  502. }
  503. /* CUDA memory: l[], g[] or stack. */
  504. if (ustatus & 0x00000080) {
  505. if (display) {
  506. if (e18 & 0x80000000) {
  507. /* g[] read fault? */
  508. NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n",
  509. i, e14, e10 | ((e18 >> 24) & 0x1f));
  510. e18 &= ~0x1f000000;
  511. } else if (e18 & 0xc) {
  512. /* g[] write fault? */
  513. NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n",
  514. i, e14, e10 | ((e18 >> 7) & 0x1f));
  515. e18 &= ~0x00000f80;
  516. } else {
  517. NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n",
  518. i, e14, e10);
  519. }
  520. NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n",
  521. i, e0c, e18, e1c, e20, e24);
  522. }
  523. ustatus &= ~0x00000080;
  524. }
  525. }
  526. break;
  527. }
  528. if (ustatus) {
  529. if (display)
  530. NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus);
  531. }
  532. nv_wr32(dev, ustatus_addr, 0xc0000000);
  533. }
  534. if (!tps && display)
  535. NV_INFO(dev, "%s - No TPs claiming errors?\n", name);
  536. }
  537. static int
  538. nv50_pgraph_trap_handler(struct drm_device *dev, u32 display, u64 inst, u32 chid)
  539. {
  540. u32 status = nv_rd32(dev, 0x400108);
  541. u32 ustatus;
  542. if (!status && display) {
  543. NV_INFO(dev, "PGRAPH - TRAP: no units reporting traps?\n");
  544. return 1;
  545. }
  546. /* DISPATCH: Relays commands to other units and handles NOTIFY,
  547. * COND, QUERY. If you get a trap from it, the command is still stuck
  548. * in DISPATCH and you need to do something about it. */
  549. if (status & 0x001) {
  550. ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff;
  551. if (!ustatus && display) {
  552. NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n");
  553. }
  554. nv_wr32(dev, 0x400500, 0x00000000);
  555. /* Known to be triggered by screwed up NOTIFY and COND... */
  556. if (ustatus & 0x00000001) {
  557. u32 addr = nv_rd32(dev, 0x400808);
  558. u32 subc = (addr & 0x00070000) >> 16;
  559. u32 mthd = (addr & 0x00001ffc);
  560. u32 datal = nv_rd32(dev, 0x40080c);
  561. u32 datah = nv_rd32(dev, 0x400810);
  562. u32 class = nv_rd32(dev, 0x400814);
  563. u32 r848 = nv_rd32(dev, 0x400848);
  564. NV_INFO(dev, "PGRAPH - TRAP DISPATCH_FAULT\n");
  565. if (display && (addr & 0x80000000)) {
  566. NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
  567. "subc %d class 0x%04x mthd 0x%04x "
  568. "data 0x%08x%08x "
  569. "400808 0x%08x 400848 0x%08x\n",
  570. chid, inst, subc, class, mthd, datah,
  571. datal, addr, r848);
  572. } else
  573. if (display) {
  574. NV_INFO(dev, "PGRAPH - no stuck command?\n");
  575. }
  576. nv_wr32(dev, 0x400808, 0);
  577. nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3);
  578. nv_wr32(dev, 0x400848, 0);
  579. ustatus &= ~0x00000001;
  580. }
  581. if (ustatus & 0x00000002) {
  582. u32 addr = nv_rd32(dev, 0x40084c);
  583. u32 subc = (addr & 0x00070000) >> 16;
  584. u32 mthd = (addr & 0x00001ffc);
  585. u32 data = nv_rd32(dev, 0x40085c);
  586. u32 class = nv_rd32(dev, 0x400814);
  587. NV_INFO(dev, "PGRAPH - TRAP DISPATCH_QUERY\n");
  588. if (display && (addr & 0x80000000)) {
  589. NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) "
  590. "subc %d class 0x%04x mthd 0x%04x "
  591. "data 0x%08x 40084c 0x%08x\n",
  592. chid, inst, subc, class, mthd,
  593. data, addr);
  594. } else
  595. if (display) {
  596. NV_INFO(dev, "PGRAPH - no stuck command?\n");
  597. }
  598. nv_wr32(dev, 0x40084c, 0);
  599. ustatus &= ~0x00000002;
  600. }
  601. if (ustatus && display) {
  602. NV_INFO(dev, "PGRAPH - TRAP_DISPATCH (unknown "
  603. "0x%08x)\n", ustatus);
  604. }
  605. nv_wr32(dev, 0x400804, 0xc0000000);
  606. nv_wr32(dev, 0x400108, 0x001);
  607. status &= ~0x001;
  608. if (!status)
  609. return 0;
  610. }
  611. /* M2MF: Memory to memory copy engine. */
  612. if (status & 0x002) {
  613. u32 ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff;
  614. if (display) {
  615. NV_INFO(dev, "PGRAPH - TRAP_M2MF");
  616. nouveau_bitfield_print(nv50_graph_trap_m2mf, ustatus);
  617. printk("\n");
  618. NV_INFO(dev, "PGRAPH - TRAP_M2MF %08x %08x %08x %08x\n",
  619. nv_rd32(dev, 0x406804), nv_rd32(dev, 0x406808),
  620. nv_rd32(dev, 0x40680c), nv_rd32(dev, 0x406810));
  621. }
  622. /* No sane way found yet -- just reset the bugger. */
  623. nv_wr32(dev, 0x400040, 2);
  624. nv_wr32(dev, 0x400040, 0);
  625. nv_wr32(dev, 0x406800, 0xc0000000);
  626. nv_wr32(dev, 0x400108, 0x002);
  627. status &= ~0x002;
  628. }
  629. /* VFETCH: Fetches data from vertex buffers. */
  630. if (status & 0x004) {
  631. u32 ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff;
  632. if (display) {
  633. NV_INFO(dev, "PGRAPH - TRAP_VFETCH");
  634. nouveau_bitfield_print(nv50_graph_trap_vfetch, ustatus);
  635. printk("\n");
  636. NV_INFO(dev, "PGRAPH - TRAP_VFETCH %08x %08x %08x %08x\n",
  637. nv_rd32(dev, 0x400c00), nv_rd32(dev, 0x400c08),
  638. nv_rd32(dev, 0x400c0c), nv_rd32(dev, 0x400c10));
  639. }
  640. nv_wr32(dev, 0x400c04, 0xc0000000);
  641. nv_wr32(dev, 0x400108, 0x004);
  642. status &= ~0x004;
  643. }
  644. /* STRMOUT: DirectX streamout / OpenGL transform feedback. */
  645. if (status & 0x008) {
  646. ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff;
  647. if (display) {
  648. NV_INFO(dev, "PGRAPH - TRAP_STRMOUT");
  649. nouveau_bitfield_print(nv50_graph_trap_strmout, ustatus);
  650. printk("\n");
  651. NV_INFO(dev, "PGRAPH - TRAP_STRMOUT %08x %08x %08x %08x\n",
  652. nv_rd32(dev, 0x401804), nv_rd32(dev, 0x401808),
  653. nv_rd32(dev, 0x40180c), nv_rd32(dev, 0x401810));
  654. }
  655. /* No sane way found yet -- just reset the bugger. */
  656. nv_wr32(dev, 0x400040, 0x80);
  657. nv_wr32(dev, 0x400040, 0);
  658. nv_wr32(dev, 0x401800, 0xc0000000);
  659. nv_wr32(dev, 0x400108, 0x008);
  660. status &= ~0x008;
  661. }
  662. /* CCACHE: Handles code and c[] caches and fills them. */
  663. if (status & 0x010) {
  664. ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff;
  665. if (display) {
  666. NV_INFO(dev, "PGRAPH - TRAP_CCACHE");
  667. nouveau_bitfield_print(nv50_graph_trap_ccache, ustatus);
  668. printk("\n");
  669. NV_INFO(dev, "PGRAPH - TRAP_CCACHE %08x %08x %08x %08x"
  670. " %08x %08x %08x\n",
  671. nv_rd32(dev, 0x405000), nv_rd32(dev, 0x405004),
  672. nv_rd32(dev, 0x405008), nv_rd32(dev, 0x40500c),
  673. nv_rd32(dev, 0x405010), nv_rd32(dev, 0x405014),
  674. nv_rd32(dev, 0x40501c));
  675. }
  676. nv_wr32(dev, 0x405018, 0xc0000000);
  677. nv_wr32(dev, 0x400108, 0x010);
  678. status &= ~0x010;
  679. }
  680. /* Unknown, not seen yet... 0x402000 is the only trap status reg
  681. * remaining, so try to handle it anyway. Perhaps related to that
  682. * unknown DMA slot on tesla? */
  683. if (status & 0x20) {
  684. ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff;
  685. if (display)
  686. NV_INFO(dev, "PGRAPH - TRAP_UNKC04 0x%08x\n", ustatus);
  687. nv_wr32(dev, 0x402000, 0xc0000000);
  688. /* no status modifiction on purpose */
  689. }
  690. /* TEXTURE: CUDA texturing units */
  691. if (status & 0x040) {
  692. nv50_pgraph_tp_trap(dev, 6, 0x408900, 0x408600, display,
  693. "PGRAPH - TRAP_TEXTURE");
  694. nv_wr32(dev, 0x400108, 0x040);
  695. status &= ~0x040;
  696. }
  697. /* MP: CUDA execution engines. */
  698. if (status & 0x080) {
  699. nv50_pgraph_tp_trap(dev, 7, 0x408314, 0x40831c, display,
  700. "PGRAPH - TRAP_MP");
  701. nv_wr32(dev, 0x400108, 0x080);
  702. status &= ~0x080;
  703. }
  704. /* TPDMA: Handles TP-initiated uncached memory accesses:
  705. * l[], g[], stack, 2d surfaces, render targets. */
  706. if (status & 0x100) {
  707. nv50_pgraph_tp_trap(dev, 8, 0x408e08, 0x408708, display,
  708. "PGRAPH - TRAP_TPDMA");
  709. nv_wr32(dev, 0x400108, 0x100);
  710. status &= ~0x100;
  711. }
  712. if (status) {
  713. if (display)
  714. NV_INFO(dev, "PGRAPH - TRAP: unknown 0x%08x\n", status);
  715. nv_wr32(dev, 0x400108, status);
  716. }
  717. return 1;
  718. }
  719. int
  720. nv50_graph_isr_chid(struct drm_device *dev, u64 inst)
  721. {
  722. struct drm_nouveau_private *dev_priv = dev->dev_private;
  723. struct nouveau_channel *chan;
  724. unsigned long flags;
  725. int i;
  726. spin_lock_irqsave(&dev_priv->channels.lock, flags);
  727. for (i = 0; i < dev_priv->engine.fifo.channels; i++) {
  728. chan = dev_priv->channels.ptr[i];
  729. if (!chan || !chan->ramin)
  730. continue;
  731. if (inst == chan->ramin->vinst)
  732. break;
  733. }
  734. spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
  735. return i;
  736. }
  737. static void
  738. nv50_graph_isr(struct drm_device *dev)
  739. {
  740. u32 stat;
  741. while ((stat = nv_rd32(dev, 0x400100))) {
  742. u64 inst = (u64)(nv_rd32(dev, 0x40032c) & 0x0fffffff) << 12;
  743. u32 chid = nv50_graph_isr_chid(dev, inst);
  744. u32 addr = nv_rd32(dev, NV04_PGRAPH_TRAPPED_ADDR);
  745. u32 subc = (addr & 0x00070000) >> 16;
  746. u32 mthd = (addr & 0x00001ffc);
  747. u32 data = nv_rd32(dev, NV04_PGRAPH_TRAPPED_DATA);
  748. u32 class = nv_rd32(dev, 0x400814);
  749. u32 show = stat;
  750. if (stat & 0x00000010) {
  751. if (!nouveau_gpuobj_mthd_call2(dev, chid, class,
  752. mthd, data))
  753. show &= ~0x00000010;
  754. }
  755. if (stat & 0x00001000) {
  756. nv_wr32(dev, 0x400500, 0x00000000);
  757. nv_wr32(dev, 0x400100, 0x00001000);
  758. nv_mask(dev, 0x40013c, 0x00001000, 0x00000000);
  759. nv50_graph_context_switch(dev);
  760. stat &= ~0x00001000;
  761. show &= ~0x00001000;
  762. }
  763. show = (show && nouveau_ratelimit()) ? show : 0;
  764. if (show & 0x00100000) {
  765. u32 ecode = nv_rd32(dev, 0x400110);
  766. NV_INFO(dev, "PGRAPH - DATA_ERROR ");
  767. nouveau_enum_print(nv50_data_error_names, ecode);
  768. printk("\n");
  769. }
  770. if (stat & 0x00200000) {
  771. if (!nv50_pgraph_trap_handler(dev, show, inst, chid))
  772. show &= ~0x00200000;
  773. }
  774. nv_wr32(dev, 0x400100, stat);
  775. nv_wr32(dev, 0x400500, 0x00010001);
  776. if (show) {
  777. NV_INFO(dev, "PGRAPH -");
  778. nouveau_bitfield_print(nv50_graph_intr, show);
  779. printk("\n");
  780. NV_INFO(dev, "PGRAPH - ch %d (0x%010llx) subc %d "
  781. "class 0x%04x mthd 0x%04x data 0x%08x\n",
  782. chid, inst, subc, class, mthd, data);
  783. nv50_fb_vm_trap(dev, 1);
  784. }
  785. }
  786. if (nv_rd32(dev, 0x400824) & (1 << 31))
  787. nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31));
  788. }
  789. static void
  790. nv50_graph_destroy(struct drm_device *dev, int engine)
  791. {
  792. struct nv50_graph_engine *pgraph = nv_engine(dev, engine);
  793. NVOBJ_ENGINE_DEL(dev, GR);
  794. nouveau_irq_unregister(dev, 12);
  795. kfree(pgraph);
  796. }
  797. int
  798. nv50_graph_create(struct drm_device *dev)
  799. {
  800. struct drm_nouveau_private *dev_priv = dev->dev_private;
  801. struct nv50_graph_engine *pgraph;
  802. int ret;
  803. pgraph = kzalloc(sizeof(*pgraph),GFP_KERNEL);
  804. if (!pgraph)
  805. return -ENOMEM;
  806. ret = nv50_grctx_init(dev, pgraph->ctxprog, ARRAY_SIZE(pgraph->ctxprog),
  807. &pgraph->ctxprog_size,
  808. &pgraph->grctx_size);
  809. if (ret) {
  810. NV_ERROR(dev, "PGRAPH: ctxprog build failed\n");
  811. kfree(pgraph);
  812. return 0;
  813. }
  814. pgraph->base.destroy = nv50_graph_destroy;
  815. pgraph->base.init = nv50_graph_init;
  816. pgraph->base.fini = nv50_graph_fini;
  817. pgraph->base.context_new = nv50_graph_context_new;
  818. pgraph->base.context_del = nv50_graph_context_del;
  819. pgraph->base.object_new = nv50_graph_object_new;
  820. if (dev_priv->chipset == 0x50 || dev_priv->chipset == 0xac)
  821. pgraph->base.tlb_flush = nv50_graph_tlb_flush;
  822. else
  823. pgraph->base.tlb_flush = nv84_graph_tlb_flush;
  824. nouveau_irq_register(dev, 12, nv50_graph_isr);
  825. NVOBJ_ENGINE_ADD(dev, GR, &pgraph->base);
  826. NVOBJ_CLASS(dev, 0x0030, GR); /* null */
  827. NVOBJ_CLASS(dev, 0x5039, GR); /* m2mf */
  828. NVOBJ_CLASS(dev, 0x502d, GR); /* 2d */
  829. /* tesla */
  830. if (dev_priv->chipset == 0x50)
  831. NVOBJ_CLASS(dev, 0x5097, GR); /* tesla (nv50) */
  832. else
  833. if (dev_priv->chipset < 0xa0)
  834. NVOBJ_CLASS(dev, 0x8297, GR); /* tesla (nv8x/nv9x) */
  835. else {
  836. switch (dev_priv->chipset) {
  837. case 0xa0:
  838. case 0xaa:
  839. case 0xac:
  840. NVOBJ_CLASS(dev, 0x8397, GR);
  841. break;
  842. case 0xa3:
  843. case 0xa5:
  844. case 0xa8:
  845. NVOBJ_CLASS(dev, 0x8597, GR);
  846. break;
  847. case 0xaf:
  848. NVOBJ_CLASS(dev, 0x8697, GR);
  849. break;
  850. }
  851. }
  852. /* compute */
  853. NVOBJ_CLASS(dev, 0x50c0, GR);
  854. if (dev_priv->chipset > 0xa0 &&
  855. dev_priv->chipset != 0xaa &&
  856. dev_priv->chipset != 0xac)
  857. NVOBJ_CLASS(dev, 0x85c0, GR);
  858. return 0;
  859. }