nvc0_fifo.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  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 "drmP.h"
  25. #include "nouveau_drv.h"
  26. #include "nouveau_mm.h"
  27. static void nvc0_fifo_isr(struct drm_device *);
  28. struct nvc0_fifo_priv {
  29. struct nouveau_gpuobj *playlist[2];
  30. int cur_playlist;
  31. struct nouveau_vma user_vma;
  32. int spoon_nr;
  33. };
  34. struct nvc0_fifo_chan {
  35. struct nouveau_bo *user;
  36. struct nouveau_gpuobj *ramfc;
  37. };
  38. static void
  39. nvc0_fifo_playlist_update(struct drm_device *dev)
  40. {
  41. struct drm_nouveau_private *dev_priv = dev->dev_private;
  42. struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
  43. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  44. struct nvc0_fifo_priv *priv = pfifo->priv;
  45. struct nouveau_gpuobj *cur;
  46. int i, p;
  47. cur = priv->playlist[priv->cur_playlist];
  48. priv->cur_playlist = !priv->cur_playlist;
  49. for (i = 0, p = 0; i < 128; i++) {
  50. if (!(nv_rd32(dev, 0x3004 + (i * 8)) & 1))
  51. continue;
  52. nv_wo32(cur, p + 0, i);
  53. nv_wo32(cur, p + 4, 0x00000004);
  54. p += 8;
  55. }
  56. pinstmem->flush(dev);
  57. nv_wr32(dev, 0x002270, cur->vinst >> 12);
  58. nv_wr32(dev, 0x002274, 0x01f00000 | (p >> 3));
  59. if (!nv_wait(dev, 0x00227c, 0x00100000, 0x00000000))
  60. NV_ERROR(dev, "PFIFO - playlist update failed\n");
  61. }
  62. void
  63. nvc0_fifo_disable(struct drm_device *dev)
  64. {
  65. }
  66. void
  67. nvc0_fifo_enable(struct drm_device *dev)
  68. {
  69. }
  70. bool
  71. nvc0_fifo_reassign(struct drm_device *dev, bool enable)
  72. {
  73. return false;
  74. }
  75. bool
  76. nvc0_fifo_cache_pull(struct drm_device *dev, bool enable)
  77. {
  78. return false;
  79. }
  80. int
  81. nvc0_fifo_channel_id(struct drm_device *dev)
  82. {
  83. return 127;
  84. }
  85. int
  86. nvc0_fifo_create_context(struct nouveau_channel *chan)
  87. {
  88. struct drm_device *dev = chan->dev;
  89. struct drm_nouveau_private *dev_priv = dev->dev_private;
  90. struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
  91. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  92. struct nvc0_fifo_priv *priv = pfifo->priv;
  93. struct nvc0_fifo_chan *fifoch;
  94. u64 ib_virt, user_vinst;
  95. int ret;
  96. chan->fifo_priv = kzalloc(sizeof(*fifoch), GFP_KERNEL);
  97. if (!chan->fifo_priv)
  98. return -ENOMEM;
  99. fifoch = chan->fifo_priv;
  100. /* allocate vram for control regs, map into polling area */
  101. ret = nouveau_bo_new(dev, NULL, 0x1000, 0, TTM_PL_FLAG_VRAM,
  102. 0, 0, &fifoch->user);
  103. if (ret)
  104. goto error;
  105. ret = nouveau_bo_pin(fifoch->user, TTM_PL_FLAG_VRAM);
  106. if (ret) {
  107. nouveau_bo_ref(NULL, &fifoch->user);
  108. goto error;
  109. }
  110. user_vinst = fifoch->user->bo.mem.start << PAGE_SHIFT;
  111. ret = nouveau_bo_map(fifoch->user);
  112. if (ret) {
  113. nouveau_bo_unpin(fifoch->user);
  114. nouveau_bo_ref(NULL, &fifoch->user);
  115. goto error;
  116. }
  117. nouveau_vm_map_at(&priv->user_vma, chan->id * 0x1000,
  118. fifoch->user->bo.mem.mm_node);
  119. chan->user = ioremap_wc(pci_resource_start(dev->pdev, 1) +
  120. priv->user_vma.offset + (chan->id * 0x1000),
  121. PAGE_SIZE);
  122. if (!chan->user) {
  123. ret = -ENOMEM;
  124. goto error;
  125. }
  126. ib_virt = chan->pushbuf_base + chan->dma.ib_base * 4;
  127. /* zero channel regs */
  128. nouveau_bo_wr32(fifoch->user, 0x0040/4, 0);
  129. nouveau_bo_wr32(fifoch->user, 0x0044/4, 0);
  130. nouveau_bo_wr32(fifoch->user, 0x0048/4, 0);
  131. nouveau_bo_wr32(fifoch->user, 0x004c/4, 0);
  132. nouveau_bo_wr32(fifoch->user, 0x0050/4, 0);
  133. nouveau_bo_wr32(fifoch->user, 0x0058/4, 0);
  134. nouveau_bo_wr32(fifoch->user, 0x005c/4, 0);
  135. nouveau_bo_wr32(fifoch->user, 0x0060/4, 0);
  136. nouveau_bo_wr32(fifoch->user, 0x0088/4, 0);
  137. nouveau_bo_wr32(fifoch->user, 0x008c/4, 0);
  138. /* ramfc */
  139. ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst,
  140. chan->ramin->vinst, 0x100,
  141. NVOBJ_FLAG_ZERO_ALLOC, &fifoch->ramfc);
  142. if (ret)
  143. goto error;
  144. nv_wo32(fifoch->ramfc, 0x08, lower_32_bits(user_vinst));
  145. nv_wo32(fifoch->ramfc, 0x0c, upper_32_bits(user_vinst));
  146. nv_wo32(fifoch->ramfc, 0x10, 0x0000face);
  147. nv_wo32(fifoch->ramfc, 0x30, 0xfffff902);
  148. nv_wo32(fifoch->ramfc, 0x48, lower_32_bits(ib_virt));
  149. nv_wo32(fifoch->ramfc, 0x4c, drm_order(chan->dma.ib_max + 1) << 16 |
  150. upper_32_bits(ib_virt));
  151. nv_wo32(fifoch->ramfc, 0x54, 0x00000002);
  152. nv_wo32(fifoch->ramfc, 0x84, 0x20400000);
  153. nv_wo32(fifoch->ramfc, 0x94, 0x30000001);
  154. nv_wo32(fifoch->ramfc, 0x9c, 0x00000100);
  155. nv_wo32(fifoch->ramfc, 0xa4, 0x1f1f1f1f);
  156. nv_wo32(fifoch->ramfc, 0xa8, 0x1f1f1f1f);
  157. nv_wo32(fifoch->ramfc, 0xac, 0x0000001f);
  158. nv_wo32(fifoch->ramfc, 0xb8, 0xf8000000);
  159. nv_wo32(fifoch->ramfc, 0xf8, 0x10003080); /* 0x002310 */
  160. nv_wo32(fifoch->ramfc, 0xfc, 0x10000010); /* 0x002350 */
  161. pinstmem->flush(dev);
  162. nv_wr32(dev, 0x003000 + (chan->id * 8), 0xc0000000 |
  163. (chan->ramin->vinst >> 12));
  164. nv_wr32(dev, 0x003004 + (chan->id * 8), 0x001f0001);
  165. nvc0_fifo_playlist_update(dev);
  166. return 0;
  167. error:
  168. pfifo->destroy_context(chan);
  169. return ret;
  170. }
  171. void
  172. nvc0_fifo_destroy_context(struct nouveau_channel *chan)
  173. {
  174. struct drm_device *dev = chan->dev;
  175. struct nvc0_fifo_chan *fifoch;
  176. nv_mask(dev, 0x003004 + (chan->id * 8), 0x00000001, 0x00000000);
  177. nv_wr32(dev, 0x002634, chan->id);
  178. if (!nv_wait(dev, 0x0002634, 0xffffffff, chan->id))
  179. NV_WARN(dev, "0x2634 != chid: 0x%08x\n", nv_rd32(dev, 0x2634));
  180. nvc0_fifo_playlist_update(dev);
  181. nv_wr32(dev, 0x003000 + (chan->id * 8), 0x00000000);
  182. if (chan->user) {
  183. iounmap(chan->user);
  184. chan->user = NULL;
  185. }
  186. fifoch = chan->fifo_priv;
  187. chan->fifo_priv = NULL;
  188. if (!fifoch)
  189. return;
  190. nouveau_gpuobj_ref(NULL, &fifoch->ramfc);
  191. if (fifoch->user) {
  192. nouveau_bo_unmap(fifoch->user);
  193. nouveau_bo_unpin(fifoch->user);
  194. nouveau_bo_ref(NULL, &fifoch->user);
  195. }
  196. kfree(fifoch);
  197. }
  198. int
  199. nvc0_fifo_load_context(struct nouveau_channel *chan)
  200. {
  201. return 0;
  202. }
  203. int
  204. nvc0_fifo_unload_context(struct drm_device *dev)
  205. {
  206. struct drm_nouveau_private *dev_priv = dev->dev_private;
  207. int i;
  208. for (i = 0; i < 128; i++) {
  209. if (!(nv_rd32(dev, 0x003004 + (i * 4)) & 1))
  210. continue;
  211. nv_mask(dev, 0x003004 + (i * 4), 0x00000001, 0x00000000);
  212. nv_wr32(dev, 0x002634, i);
  213. if (!nv_wait(dev, 0x002634, 0xffffffff, i)) {
  214. NV_INFO(dev, "PFIFO: kick ch %d failed: 0x%08x\n",
  215. i, nv_rd32(dev, 0x002634));
  216. return -EBUSY;
  217. }
  218. }
  219. return 0;
  220. }
  221. static void
  222. nvc0_fifo_destroy(struct drm_device *dev)
  223. {
  224. struct drm_nouveau_private *dev_priv = dev->dev_private;
  225. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  226. struct nvc0_fifo_priv *priv;
  227. priv = pfifo->priv;
  228. if (!priv)
  229. return;
  230. nouveau_vm_put(&priv->user_vma);
  231. nouveau_gpuobj_ref(NULL, &priv->playlist[1]);
  232. nouveau_gpuobj_ref(NULL, &priv->playlist[0]);
  233. kfree(priv);
  234. }
  235. void
  236. nvc0_fifo_takedown(struct drm_device *dev)
  237. {
  238. nv_wr32(dev, 0x002140, 0x00000000);
  239. nvc0_fifo_destroy(dev);
  240. }
  241. static int
  242. nvc0_fifo_create(struct drm_device *dev)
  243. {
  244. struct drm_nouveau_private *dev_priv = dev->dev_private;
  245. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  246. struct nvc0_fifo_priv *priv;
  247. int ret;
  248. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  249. if (!priv)
  250. return -ENOMEM;
  251. pfifo->priv = priv;
  252. ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 0x1000, 0,
  253. &priv->playlist[0]);
  254. if (ret)
  255. goto error;
  256. ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 0x1000, 0,
  257. &priv->playlist[1]);
  258. if (ret)
  259. goto error;
  260. ret = nouveau_vm_get(dev_priv->bar1_vm, pfifo->channels * 0x1000,
  261. 12, NV_MEM_ACCESS_RW, &priv->user_vma);
  262. if (ret)
  263. goto error;
  264. nouveau_irq_register(dev, 8, nvc0_fifo_isr);
  265. NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */
  266. return 0;
  267. error:
  268. nvc0_fifo_destroy(dev);
  269. return ret;
  270. }
  271. int
  272. nvc0_fifo_init(struct drm_device *dev)
  273. {
  274. struct drm_nouveau_private *dev_priv = dev->dev_private;
  275. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  276. struct nvc0_fifo_priv *priv;
  277. int ret, i;
  278. if (!pfifo->priv) {
  279. ret = nvc0_fifo_create(dev);
  280. if (ret)
  281. return ret;
  282. }
  283. priv = pfifo->priv;
  284. /* reset PFIFO, enable all available PSUBFIFO areas */
  285. nv_mask(dev, 0x000200, 0x00000100, 0x00000000);
  286. nv_mask(dev, 0x000200, 0x00000100, 0x00000100);
  287. nv_wr32(dev, 0x000204, 0xffffffff);
  288. nv_wr32(dev, 0x002204, 0xffffffff);
  289. priv->spoon_nr = hweight32(nv_rd32(dev, 0x002204));
  290. NV_DEBUG(dev, "PFIFO: %d subfifo(s)\n", priv->spoon_nr);
  291. /* assign engines to subfifos */
  292. if (priv->spoon_nr >= 3) {
  293. nv_wr32(dev, 0x002208, ~(1 << 0)); /* PGRAPH */
  294. nv_wr32(dev, 0x00220c, ~(1 << 1)); /* PVP */
  295. nv_wr32(dev, 0x002210, ~(1 << 1)); /* PPP */
  296. nv_wr32(dev, 0x002214, ~(1 << 1)); /* PBSP */
  297. nv_wr32(dev, 0x002218, ~(1 << 2)); /* PCE0 */
  298. nv_wr32(dev, 0x00221c, ~(1 << 1)); /* PCE1 */
  299. }
  300. /* PSUBFIFO[n] */
  301. for (i = 0; i < 3; i++) {
  302. nv_mask(dev, 0x04013c + (i * 0x2000), 0x10000100, 0x00000000);
  303. nv_wr32(dev, 0x040108 + (i * 0x2000), 0xffffffff); /* INTR */
  304. nv_wr32(dev, 0x04010c + (i * 0x2000), 0xfffffeff); /* INTR_EN */
  305. }
  306. nv_mask(dev, 0x002200, 0x00000001, 0x00000001);
  307. nv_wr32(dev, 0x002254, 0x10000000 | priv->user_vma.offset >> 12);
  308. nv_wr32(dev, 0x002a00, 0xffffffff); /* clears PFIFO.INTR bit 30 */
  309. nv_wr32(dev, 0x002100, 0xffffffff);
  310. nv_wr32(dev, 0x002140, 0xbfffffff);
  311. return 0;
  312. }
  313. struct nouveau_enum nvc0_fifo_fault_unit[] = {
  314. { 0x00, "PGRAPH" },
  315. { 0x03, "PEEPHOLE" },
  316. { 0x04, "BAR1" },
  317. { 0x05, "BAR3" },
  318. { 0x07, "PFIFO" },
  319. { 0x10, "PBSP" },
  320. { 0x11, "PPPP" },
  321. { 0x13, "PCOUNTER" },
  322. { 0x14, "PVP" },
  323. { 0x15, "PCOPY0" },
  324. { 0x16, "PCOPY1" },
  325. { 0x17, "PDAEMON" },
  326. {}
  327. };
  328. struct nouveau_enum nvc0_fifo_fault_reason[] = {
  329. { 0x00, "PT_NOT_PRESENT" },
  330. { 0x01, "PT_TOO_SHORT" },
  331. { 0x02, "PAGE_NOT_PRESENT" },
  332. { 0x03, "VM_LIMIT_EXCEEDED" },
  333. { 0x04, "NO_CHANNEL" },
  334. { 0x05, "PAGE_SYSTEM_ONLY" },
  335. { 0x06, "PAGE_READ_ONLY" },
  336. { 0x0a, "COMPRESSED_SYSRAM" },
  337. { 0x0c, "INVALID_STORAGE_TYPE" },
  338. {}
  339. };
  340. struct nouveau_enum nvc0_fifo_fault_hubclient[] = {
  341. { 0x01, "PCOPY0" },
  342. { 0x02, "PCOPY1" },
  343. { 0x04, "DISPATCH" },
  344. { 0x05, "CTXCTL" },
  345. { 0x06, "PFIFO" },
  346. { 0x07, "BAR_READ" },
  347. { 0x08, "BAR_WRITE" },
  348. { 0x0b, "PVP" },
  349. { 0x0c, "PPPP" },
  350. { 0x0d, "PBSP" },
  351. { 0x11, "PCOUNTER" },
  352. { 0x12, "PDAEMON" },
  353. { 0x14, "CCACHE" },
  354. { 0x15, "CCACHE_POST" },
  355. {}
  356. };
  357. struct nouveau_enum nvc0_fifo_fault_gpcclient[] = {
  358. { 0x01, "TEX" },
  359. { 0x0c, "ESETUP" },
  360. { 0x0e, "CTXCTL" },
  361. { 0x0f, "PROP" },
  362. {}
  363. };
  364. struct nouveau_bitfield nvc0_fifo_subfifo_intr[] = {
  365. /* { 0x00008000, "" } seen with null ib push */
  366. { 0x00200000, "ILLEGAL_MTHD" },
  367. { 0x00800000, "EMPTY_SUBC" },
  368. {}
  369. };
  370. static void
  371. nvc0_fifo_isr_vm_fault(struct drm_device *dev, int unit)
  372. {
  373. u32 inst = nv_rd32(dev, 0x2800 + (unit * 0x10));
  374. u32 valo = nv_rd32(dev, 0x2804 + (unit * 0x10));
  375. u32 vahi = nv_rd32(dev, 0x2808 + (unit * 0x10));
  376. u32 stat = nv_rd32(dev, 0x280c + (unit * 0x10));
  377. u32 client = (stat & 0x00001f00) >> 8;
  378. NV_INFO(dev, "PFIFO: %s fault at 0x%010llx [",
  379. (stat & 0x00000080) ? "write" : "read", (u64)vahi << 32 | valo);
  380. nouveau_enum_print(nvc0_fifo_fault_reason, stat & 0x0000000f);
  381. printk("] from ");
  382. nouveau_enum_print(nvc0_fifo_fault_unit, unit);
  383. if (stat & 0x00000040) {
  384. printk("/");
  385. nouveau_enum_print(nvc0_fifo_fault_hubclient, client);
  386. } else {
  387. printk("/GPC%d/", (stat & 0x1f000000) >> 24);
  388. nouveau_enum_print(nvc0_fifo_fault_gpcclient, client);
  389. }
  390. printk(" on channel 0x%010llx\n", (u64)inst << 12);
  391. }
  392. static void
  393. nvc0_fifo_isr_subfifo_intr(struct drm_device *dev, int unit)
  394. {
  395. u32 stat = nv_rd32(dev, 0x040108 + (unit * 0x2000));
  396. u32 addr = nv_rd32(dev, 0x0400c0 + (unit * 0x2000));
  397. u32 data = nv_rd32(dev, 0x0400c4 + (unit * 0x2000));
  398. u32 chid = nv_rd32(dev, 0x040120 + (unit * 0x2000)) & 0x7f;
  399. u32 subc = (addr & 0x00070000);
  400. u32 mthd = (addr & 0x00003ffc);
  401. NV_INFO(dev, "PSUBFIFO %d:", unit);
  402. nouveau_bitfield_print(nvc0_fifo_subfifo_intr, stat);
  403. NV_INFO(dev, "PSUBFIFO %d: ch %d subc %d mthd 0x%04x data 0x%08x\n",
  404. unit, chid, subc, mthd, data);
  405. nv_wr32(dev, 0x0400c0 + (unit * 0x2000), 0x80600008);
  406. nv_wr32(dev, 0x040108 + (unit * 0x2000), stat);
  407. }
  408. static void
  409. nvc0_fifo_isr(struct drm_device *dev)
  410. {
  411. u32 stat = nv_rd32(dev, 0x002100);
  412. if (stat & 0x00000100) {
  413. NV_INFO(dev, "PFIFO: unknown status 0x00000100\n");
  414. nv_wr32(dev, 0x002100, 0x00000100);
  415. stat &= ~0x00000100;
  416. }
  417. if (stat & 0x10000000) {
  418. u32 units = nv_rd32(dev, 0x00259c);
  419. u32 u = units;
  420. while (u) {
  421. int i = ffs(u) - 1;
  422. nvc0_fifo_isr_vm_fault(dev, i);
  423. u &= ~(1 << i);
  424. }
  425. nv_wr32(dev, 0x00259c, units);
  426. stat &= ~0x10000000;
  427. }
  428. if (stat & 0x20000000) {
  429. u32 units = nv_rd32(dev, 0x0025a0);
  430. u32 u = units;
  431. while (u) {
  432. int i = ffs(u) - 1;
  433. nvc0_fifo_isr_subfifo_intr(dev, i);
  434. u &= ~(1 << i);
  435. }
  436. nv_wr32(dev, 0x0025a0, units);
  437. stat &= ~0x20000000;
  438. }
  439. if (stat & 0x40000000) {
  440. NV_INFO(dev, "PFIFO: unknown status 0x40000000\n");
  441. nv_mask(dev, 0x002a00, 0x00000000, 0x00000000);
  442. stat &= ~0x40000000;
  443. }
  444. if (stat) {
  445. NV_INFO(dev, "PFIFO: unhandled status 0x%08x\n", stat);
  446. nv_wr32(dev, 0x002100, stat);
  447. nv_wr32(dev, 0x002140, 0);
  448. }
  449. }