nvc0_fifo.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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_gpuobj *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 = chan->pushbuf_base + chan->dma.ib_base * 4;
  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_gpuobj_new(dev, NULL, 0x1000, 0x1000,
  102. NVOBJ_FLAG_ZERO_ALLOC, &fifoch->user);
  103. if (ret)
  104. goto error;
  105. nouveau_vm_map_at(&priv->user_vma, chan->id * 0x1000,
  106. *(struct nouveau_mem **)fifoch->user->node);
  107. chan->user = ioremap_wc(pci_resource_start(dev->pdev, 1) +
  108. priv->user_vma.offset + (chan->id * 0x1000),
  109. PAGE_SIZE);
  110. if (!chan->user) {
  111. ret = -ENOMEM;
  112. goto error;
  113. }
  114. /* ramfc */
  115. ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst,
  116. chan->ramin->vinst, 0x100,
  117. NVOBJ_FLAG_ZERO_ALLOC, &fifoch->ramfc);
  118. if (ret)
  119. goto error;
  120. nv_wo32(fifoch->ramfc, 0x08, lower_32_bits(fifoch->user->vinst));
  121. nv_wo32(fifoch->ramfc, 0x0c, upper_32_bits(fifoch->user->vinst));
  122. nv_wo32(fifoch->ramfc, 0x10, 0x0000face);
  123. nv_wo32(fifoch->ramfc, 0x30, 0xfffff902);
  124. nv_wo32(fifoch->ramfc, 0x48, lower_32_bits(ib_virt));
  125. nv_wo32(fifoch->ramfc, 0x4c, drm_order(chan->dma.ib_max + 1) << 16 |
  126. upper_32_bits(ib_virt));
  127. nv_wo32(fifoch->ramfc, 0x54, 0x00000002);
  128. nv_wo32(fifoch->ramfc, 0x84, 0x20400000);
  129. nv_wo32(fifoch->ramfc, 0x94, 0x30000001);
  130. nv_wo32(fifoch->ramfc, 0x9c, 0x00000100);
  131. nv_wo32(fifoch->ramfc, 0xa4, 0x1f1f1f1f);
  132. nv_wo32(fifoch->ramfc, 0xa8, 0x1f1f1f1f);
  133. nv_wo32(fifoch->ramfc, 0xac, 0x0000001f);
  134. nv_wo32(fifoch->ramfc, 0xb8, 0xf8000000);
  135. nv_wo32(fifoch->ramfc, 0xf8, 0x10003080); /* 0x002310 */
  136. nv_wo32(fifoch->ramfc, 0xfc, 0x10000010); /* 0x002350 */
  137. pinstmem->flush(dev);
  138. nv_wr32(dev, 0x003000 + (chan->id * 8), 0xc0000000 |
  139. (chan->ramin->vinst >> 12));
  140. nv_wr32(dev, 0x003004 + (chan->id * 8), 0x001f0001);
  141. nvc0_fifo_playlist_update(dev);
  142. return 0;
  143. error:
  144. pfifo->destroy_context(chan);
  145. return ret;
  146. }
  147. void
  148. nvc0_fifo_destroy_context(struct nouveau_channel *chan)
  149. {
  150. struct drm_device *dev = chan->dev;
  151. struct nvc0_fifo_chan *fifoch;
  152. nv_mask(dev, 0x003004 + (chan->id * 8), 0x00000001, 0x00000000);
  153. nv_wr32(dev, 0x002634, chan->id);
  154. if (!nv_wait(dev, 0x0002634, 0xffffffff, chan->id))
  155. NV_WARN(dev, "0x2634 != chid: 0x%08x\n", nv_rd32(dev, 0x2634));
  156. nvc0_fifo_playlist_update(dev);
  157. nv_wr32(dev, 0x003000 + (chan->id * 8), 0x00000000);
  158. if (chan->user) {
  159. iounmap(chan->user);
  160. chan->user = NULL;
  161. }
  162. fifoch = chan->fifo_priv;
  163. chan->fifo_priv = NULL;
  164. if (!fifoch)
  165. return;
  166. nouveau_gpuobj_ref(NULL, &fifoch->ramfc);
  167. nouveau_gpuobj_ref(NULL, &fifoch->user);
  168. kfree(fifoch);
  169. }
  170. int
  171. nvc0_fifo_load_context(struct nouveau_channel *chan)
  172. {
  173. return 0;
  174. }
  175. int
  176. nvc0_fifo_unload_context(struct drm_device *dev)
  177. {
  178. int i;
  179. for (i = 0; i < 128; i++) {
  180. if (!(nv_rd32(dev, 0x003004 + (i * 8)) & 1))
  181. continue;
  182. nv_mask(dev, 0x003004 + (i * 8), 0x00000001, 0x00000000);
  183. nv_wr32(dev, 0x002634, i);
  184. if (!nv_wait(dev, 0x002634, 0xffffffff, i)) {
  185. NV_INFO(dev, "PFIFO: kick ch %d failed: 0x%08x\n",
  186. i, nv_rd32(dev, 0x002634));
  187. return -EBUSY;
  188. }
  189. }
  190. return 0;
  191. }
  192. static void
  193. nvc0_fifo_destroy(struct drm_device *dev)
  194. {
  195. struct drm_nouveau_private *dev_priv = dev->dev_private;
  196. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  197. struct nvc0_fifo_priv *priv;
  198. priv = pfifo->priv;
  199. if (!priv)
  200. return;
  201. nouveau_vm_put(&priv->user_vma);
  202. nouveau_gpuobj_ref(NULL, &priv->playlist[1]);
  203. nouveau_gpuobj_ref(NULL, &priv->playlist[0]);
  204. kfree(priv);
  205. }
  206. void
  207. nvc0_fifo_takedown(struct drm_device *dev)
  208. {
  209. nv_wr32(dev, 0x002140, 0x00000000);
  210. nvc0_fifo_destroy(dev);
  211. }
  212. static int
  213. nvc0_fifo_create(struct drm_device *dev)
  214. {
  215. struct drm_nouveau_private *dev_priv = dev->dev_private;
  216. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  217. struct nvc0_fifo_priv *priv;
  218. int ret;
  219. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  220. if (!priv)
  221. return -ENOMEM;
  222. pfifo->priv = priv;
  223. ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 0x1000, 0,
  224. &priv->playlist[0]);
  225. if (ret)
  226. goto error;
  227. ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 0x1000, 0,
  228. &priv->playlist[1]);
  229. if (ret)
  230. goto error;
  231. ret = nouveau_vm_get(dev_priv->bar1_vm, pfifo->channels * 0x1000,
  232. 12, NV_MEM_ACCESS_RW, &priv->user_vma);
  233. if (ret)
  234. goto error;
  235. nouveau_irq_register(dev, 8, nvc0_fifo_isr);
  236. return 0;
  237. error:
  238. nvc0_fifo_destroy(dev);
  239. return ret;
  240. }
  241. int
  242. nvc0_fifo_init(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 nouveau_channel *chan;
  247. struct nvc0_fifo_priv *priv;
  248. int ret, i;
  249. if (!pfifo->priv) {
  250. ret = nvc0_fifo_create(dev);
  251. if (ret)
  252. return ret;
  253. }
  254. priv = pfifo->priv;
  255. /* reset PFIFO, enable all available PSUBFIFO areas */
  256. nv_mask(dev, 0x000200, 0x00000100, 0x00000000);
  257. nv_mask(dev, 0x000200, 0x00000100, 0x00000100);
  258. nv_wr32(dev, 0x000204, 0xffffffff);
  259. nv_wr32(dev, 0x002204, 0xffffffff);
  260. priv->spoon_nr = hweight32(nv_rd32(dev, 0x002204));
  261. NV_DEBUG(dev, "PFIFO: %d subfifo(s)\n", priv->spoon_nr);
  262. /* assign engines to subfifos */
  263. if (priv->spoon_nr >= 3) {
  264. nv_wr32(dev, 0x002208, ~(1 << 0)); /* PGRAPH */
  265. nv_wr32(dev, 0x00220c, ~(1 << 1)); /* PVP */
  266. nv_wr32(dev, 0x002210, ~(1 << 1)); /* PPP */
  267. nv_wr32(dev, 0x002214, ~(1 << 1)); /* PBSP */
  268. nv_wr32(dev, 0x002218, ~(1 << 2)); /* PCE0 */
  269. nv_wr32(dev, 0x00221c, ~(1 << 1)); /* PCE1 */
  270. }
  271. /* PSUBFIFO[n] */
  272. for (i = 0; i < priv->spoon_nr; i++) {
  273. nv_mask(dev, 0x04013c + (i * 0x2000), 0x10000100, 0x00000000);
  274. nv_wr32(dev, 0x040108 + (i * 0x2000), 0xffffffff); /* INTR */
  275. nv_wr32(dev, 0x04010c + (i * 0x2000), 0xfffffeff); /* INTR_EN */
  276. }
  277. nv_mask(dev, 0x002200, 0x00000001, 0x00000001);
  278. nv_wr32(dev, 0x002254, 0x10000000 | priv->user_vma.offset >> 12);
  279. nv_wr32(dev, 0x002a00, 0xffffffff); /* clears PFIFO.INTR bit 30 */
  280. nv_wr32(dev, 0x002100, 0xffffffff);
  281. nv_wr32(dev, 0x002140, 0xbfffffff);
  282. /* restore PFIFO context table */
  283. for (i = 0; i < 128; i++) {
  284. chan = dev_priv->channels.ptr[i];
  285. if (!chan || !chan->fifo_priv)
  286. continue;
  287. nv_wr32(dev, 0x003000 + (i * 8), 0xc0000000 |
  288. (chan->ramin->vinst >> 12));
  289. nv_wr32(dev, 0x003004 + (i * 8), 0x001f0001);
  290. }
  291. nvc0_fifo_playlist_update(dev);
  292. return 0;
  293. }
  294. struct nouveau_enum nvc0_fifo_fault_unit[] = {
  295. { 0x00, "PGRAPH" },
  296. { 0x03, "PEEPHOLE" },
  297. { 0x04, "BAR1" },
  298. { 0x05, "BAR3" },
  299. { 0x07, "PFIFO" },
  300. { 0x10, "PBSP" },
  301. { 0x11, "PPPP" },
  302. { 0x13, "PCOUNTER" },
  303. { 0x14, "PVP" },
  304. { 0x15, "PCOPY0" },
  305. { 0x16, "PCOPY1" },
  306. { 0x17, "PDAEMON" },
  307. {}
  308. };
  309. struct nouveau_enum nvc0_fifo_fault_reason[] = {
  310. { 0x00, "PT_NOT_PRESENT" },
  311. { 0x01, "PT_TOO_SHORT" },
  312. { 0x02, "PAGE_NOT_PRESENT" },
  313. { 0x03, "VM_LIMIT_EXCEEDED" },
  314. { 0x04, "NO_CHANNEL" },
  315. { 0x05, "PAGE_SYSTEM_ONLY" },
  316. { 0x06, "PAGE_READ_ONLY" },
  317. { 0x0a, "COMPRESSED_SYSRAM" },
  318. { 0x0c, "INVALID_STORAGE_TYPE" },
  319. {}
  320. };
  321. struct nouveau_enum nvc0_fifo_fault_hubclient[] = {
  322. { 0x01, "PCOPY0" },
  323. { 0x02, "PCOPY1" },
  324. { 0x04, "DISPATCH" },
  325. { 0x05, "CTXCTL" },
  326. { 0x06, "PFIFO" },
  327. { 0x07, "BAR_READ" },
  328. { 0x08, "BAR_WRITE" },
  329. { 0x0b, "PVP" },
  330. { 0x0c, "PPPP" },
  331. { 0x0d, "PBSP" },
  332. { 0x11, "PCOUNTER" },
  333. { 0x12, "PDAEMON" },
  334. { 0x14, "CCACHE" },
  335. { 0x15, "CCACHE_POST" },
  336. {}
  337. };
  338. struct nouveau_enum nvc0_fifo_fault_gpcclient[] = {
  339. { 0x01, "TEX" },
  340. { 0x0c, "ESETUP" },
  341. { 0x0e, "CTXCTL" },
  342. { 0x0f, "PROP" },
  343. {}
  344. };
  345. struct nouveau_bitfield nvc0_fifo_subfifo_intr[] = {
  346. /* { 0x00008000, "" } seen with null ib push */
  347. { 0x00200000, "ILLEGAL_MTHD" },
  348. { 0x00800000, "EMPTY_SUBC" },
  349. {}
  350. };
  351. static void
  352. nvc0_fifo_isr_vm_fault(struct drm_device *dev, int unit)
  353. {
  354. u32 inst = nv_rd32(dev, 0x2800 + (unit * 0x10));
  355. u32 valo = nv_rd32(dev, 0x2804 + (unit * 0x10));
  356. u32 vahi = nv_rd32(dev, 0x2808 + (unit * 0x10));
  357. u32 stat = nv_rd32(dev, 0x280c + (unit * 0x10));
  358. u32 client = (stat & 0x00001f00) >> 8;
  359. NV_INFO(dev, "PFIFO: %s fault at 0x%010llx [",
  360. (stat & 0x00000080) ? "write" : "read", (u64)vahi << 32 | valo);
  361. nouveau_enum_print(nvc0_fifo_fault_reason, stat & 0x0000000f);
  362. printk("] from ");
  363. nouveau_enum_print(nvc0_fifo_fault_unit, unit);
  364. if (stat & 0x00000040) {
  365. printk("/");
  366. nouveau_enum_print(nvc0_fifo_fault_hubclient, client);
  367. } else {
  368. printk("/GPC%d/", (stat & 0x1f000000) >> 24);
  369. nouveau_enum_print(nvc0_fifo_fault_gpcclient, client);
  370. }
  371. printk(" on channel 0x%010llx\n", (u64)inst << 12);
  372. }
  373. static int
  374. nvc0_fifo_page_flip(struct drm_device *dev, u32 chid)
  375. {
  376. struct drm_nouveau_private *dev_priv = dev->dev_private;
  377. struct nouveau_channel *chan = NULL;
  378. unsigned long flags;
  379. int ret = -EINVAL;
  380. spin_lock_irqsave(&dev_priv->channels.lock, flags);
  381. if (likely(chid >= 0 && chid < dev_priv->engine.fifo.channels)) {
  382. chan = dev_priv->channels.ptr[chid];
  383. if (likely(chan))
  384. ret = nouveau_finish_page_flip(chan, NULL);
  385. }
  386. spin_unlock_irqrestore(&dev_priv->channels.lock, flags);
  387. return ret;
  388. }
  389. static void
  390. nvc0_fifo_isr_subfifo_intr(struct drm_device *dev, int unit)
  391. {
  392. u32 stat = nv_rd32(dev, 0x040108 + (unit * 0x2000));
  393. u32 addr = nv_rd32(dev, 0x0400c0 + (unit * 0x2000));
  394. u32 data = nv_rd32(dev, 0x0400c4 + (unit * 0x2000));
  395. u32 chid = nv_rd32(dev, 0x040120 + (unit * 0x2000)) & 0x7f;
  396. u32 subc = (addr & 0x00070000);
  397. u32 mthd = (addr & 0x00003ffc);
  398. u32 show = stat;
  399. if (stat & 0x00200000) {
  400. if (mthd == 0x0054) {
  401. if (!nvc0_fifo_page_flip(dev, chid))
  402. show &= ~0x00200000;
  403. }
  404. }
  405. if (show) {
  406. NV_INFO(dev, "PFIFO%d:", unit);
  407. nouveau_bitfield_print(nvc0_fifo_subfifo_intr, show);
  408. NV_INFO(dev, "PFIFO%d: ch %d subc %d mthd 0x%04x data 0x%08x\n",
  409. unit, chid, subc, mthd, data);
  410. }
  411. nv_wr32(dev, 0x0400c0 + (unit * 0x2000), 0x80600008);
  412. nv_wr32(dev, 0x040108 + (unit * 0x2000), stat);
  413. }
  414. static void
  415. nvc0_fifo_isr(struct drm_device *dev)
  416. {
  417. u32 stat = nv_rd32(dev, 0x002100);
  418. if (stat & 0x00000100) {
  419. NV_INFO(dev, "PFIFO: unknown status 0x00000100\n");
  420. nv_wr32(dev, 0x002100, 0x00000100);
  421. stat &= ~0x00000100;
  422. }
  423. if (stat & 0x10000000) {
  424. u32 units = nv_rd32(dev, 0x00259c);
  425. u32 u = units;
  426. while (u) {
  427. int i = ffs(u) - 1;
  428. nvc0_fifo_isr_vm_fault(dev, i);
  429. u &= ~(1 << i);
  430. }
  431. nv_wr32(dev, 0x00259c, units);
  432. stat &= ~0x10000000;
  433. }
  434. if (stat & 0x20000000) {
  435. u32 units = nv_rd32(dev, 0x0025a0);
  436. u32 u = units;
  437. while (u) {
  438. int i = ffs(u) - 1;
  439. nvc0_fifo_isr_subfifo_intr(dev, i);
  440. u &= ~(1 << i);
  441. }
  442. nv_wr32(dev, 0x0025a0, units);
  443. stat &= ~0x20000000;
  444. }
  445. if (stat & 0x40000000) {
  446. NV_INFO(dev, "PFIFO: unknown status 0x40000000\n");
  447. nv_mask(dev, 0x002a00, 0x00000000, 0x00000000);
  448. stat &= ~0x40000000;
  449. }
  450. if (stat) {
  451. NV_INFO(dev, "PFIFO: unhandled status 0x%08x\n", stat);
  452. nv_wr32(dev, 0x002100, stat);
  453. nv_wr32(dev, 0x002140, 0);
  454. }
  455. }