nvc0_fifo.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466
  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. return 0;
  207. }
  208. static void
  209. nvc0_fifo_destroy(struct drm_device *dev)
  210. {
  211. struct drm_nouveau_private *dev_priv = dev->dev_private;
  212. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  213. struct nvc0_fifo_priv *priv;
  214. priv = pfifo->priv;
  215. if (!priv)
  216. return;
  217. nouveau_vm_put(&priv->user_vma);
  218. nouveau_gpuobj_ref(NULL, &priv->playlist[1]);
  219. nouveau_gpuobj_ref(NULL, &priv->playlist[0]);
  220. kfree(priv);
  221. }
  222. void
  223. nvc0_fifo_takedown(struct drm_device *dev)
  224. {
  225. nv_wr32(dev, 0x002140, 0x00000000);
  226. nvc0_fifo_destroy(dev);
  227. }
  228. static int
  229. nvc0_fifo_create(struct drm_device *dev)
  230. {
  231. struct drm_nouveau_private *dev_priv = dev->dev_private;
  232. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  233. struct nvc0_fifo_priv *priv;
  234. int ret;
  235. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  236. if (!priv)
  237. return -ENOMEM;
  238. pfifo->priv = priv;
  239. ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 0x1000, 0,
  240. &priv->playlist[0]);
  241. if (ret)
  242. goto error;
  243. ret = nouveau_gpuobj_new(dev, NULL, 0x1000, 0x1000, 0,
  244. &priv->playlist[1]);
  245. if (ret)
  246. goto error;
  247. ret = nouveau_vm_get(dev_priv->bar1_vm, pfifo->channels * 0x1000,
  248. 12, NV_MEM_ACCESS_RW, &priv->user_vma);
  249. if (ret)
  250. goto error;
  251. nouveau_irq_register(dev, 8, nvc0_fifo_isr);
  252. NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */
  253. return 0;
  254. error:
  255. nvc0_fifo_destroy(dev);
  256. return ret;
  257. }
  258. int
  259. nvc0_fifo_init(struct drm_device *dev)
  260. {
  261. struct drm_nouveau_private *dev_priv = dev->dev_private;
  262. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  263. struct nvc0_fifo_priv *priv;
  264. int ret, i;
  265. if (!pfifo->priv) {
  266. ret = nvc0_fifo_create(dev);
  267. if (ret)
  268. return ret;
  269. }
  270. priv = pfifo->priv;
  271. /* reset PFIFO, enable all available PSUBFIFO areas */
  272. nv_mask(dev, 0x000200, 0x00000100, 0x00000000);
  273. nv_mask(dev, 0x000200, 0x00000100, 0x00000100);
  274. nv_wr32(dev, 0x000204, 0xffffffff);
  275. nv_wr32(dev, 0x002204, 0xffffffff);
  276. priv->spoon_nr = hweight32(nv_rd32(dev, 0x002204));
  277. NV_DEBUG(dev, "PFIFO: %d subfifo(s)\n", priv->spoon_nr);
  278. /* assign engines to subfifos */
  279. if (priv->spoon_nr >= 3) {
  280. nv_wr32(dev, 0x002208, ~(1 << 0)); /* PGRAPH */
  281. nv_wr32(dev, 0x00220c, ~(1 << 1)); /* PVP */
  282. nv_wr32(dev, 0x002210, ~(1 << 1)); /* PPP */
  283. nv_wr32(dev, 0x002214, ~(1 << 1)); /* PBSP */
  284. nv_wr32(dev, 0x002218, ~(1 << 2)); /* PCE0 */
  285. nv_wr32(dev, 0x00221c, ~(1 << 1)); /* PCE1 */
  286. }
  287. /* PSUBFIFO[n] */
  288. for (i = 0; i < 3; i++) {
  289. nv_mask(dev, 0x04013c + (i * 0x2000), 0x10000100, 0x00000000);
  290. nv_wr32(dev, 0x040108 + (i * 0x2000), 0xffffffff); /* INTR */
  291. nv_wr32(dev, 0x04010c + (i * 0x2000), 0xfffffeff); /* INTR_EN */
  292. }
  293. nv_mask(dev, 0x002200, 0x00000001, 0x00000001);
  294. nv_wr32(dev, 0x002254, 0x10000000 | priv->user_vma.offset >> 12);
  295. nv_wr32(dev, 0x002a00, 0xffffffff); /* clears PFIFO.INTR bit 30 */
  296. nv_wr32(dev, 0x002100, 0xffffffff);
  297. nv_wr32(dev, 0x002140, 0xbfffffff);
  298. return 0;
  299. }
  300. struct nouveau_enum nvc0_fifo_fault_unit[] = {
  301. { 0, "PGRAPH" },
  302. { 3, "PEEPHOLE" },
  303. { 4, "BAR1" },
  304. { 5, "BAR3" },
  305. { 7, "PFIFO" },
  306. {}
  307. };
  308. struct nouveau_enum nvc0_fifo_fault_reason[] = {
  309. { 0, "PT_NOT_PRESENT" },
  310. { 1, "PT_TOO_SHORT" },
  311. { 2, "PAGE_NOT_PRESENT" },
  312. { 3, "VM_LIMIT_EXCEEDED" },
  313. {}
  314. };
  315. struct nouveau_bitfield nvc0_fifo_subfifo_intr[] = {
  316. /* { 0x00008000, "" } seen with null ib push */
  317. { 0x00200000, "ILLEGAL_MTHD" },
  318. { 0x00800000, "EMPTY_SUBC" },
  319. {}
  320. };
  321. static void
  322. nvc0_fifo_isr_vm_fault(struct drm_device *dev, int unit)
  323. {
  324. u32 inst = nv_rd32(dev, 0x2800 + (unit * 0x10));
  325. u32 valo = nv_rd32(dev, 0x2804 + (unit * 0x10));
  326. u32 vahi = nv_rd32(dev, 0x2808 + (unit * 0x10));
  327. u32 stat = nv_rd32(dev, 0x280c + (unit * 0x10));
  328. NV_INFO(dev, "PFIFO: %s fault at 0x%010llx [",
  329. (stat & 0x00000080) ? "write" : "read", (u64)vahi << 32 | valo);
  330. nouveau_enum_print(nvc0_fifo_fault_reason, stat & 0x0000000f);
  331. printk("] from ");
  332. nouveau_enum_print(nvc0_fifo_fault_unit, unit);
  333. printk(" on channel 0x%010llx\n", (u64)inst << 12);
  334. }
  335. static void
  336. nvc0_fifo_isr_subfifo_intr(struct drm_device *dev, int unit)
  337. {
  338. u32 stat = nv_rd32(dev, 0x040108 + (unit * 0x2000));
  339. u32 addr = nv_rd32(dev, 0x0400c0 + (unit * 0x2000));
  340. u32 data = nv_rd32(dev, 0x0400c4 + (unit * 0x2000));
  341. u32 chid = nv_rd32(dev, 0x040120 + (unit * 0x2000)) & 0x7f;
  342. u32 subc = (addr & 0x00070000);
  343. u32 mthd = (addr & 0x00003ffc);
  344. NV_INFO(dev, "PSUBFIFO %d:", unit);
  345. nouveau_bitfield_print(nvc0_fifo_subfifo_intr, stat);
  346. NV_INFO(dev, "PSUBFIFO %d: ch %d subc %d mthd 0x%04x data 0x%08x\n",
  347. unit, chid, subc, mthd, data);
  348. nv_wr32(dev, 0x0400c0 + (unit * 0x2000), 0x80600008);
  349. nv_wr32(dev, 0x040108 + (unit * 0x2000), stat);
  350. }
  351. static void
  352. nvc0_fifo_isr(struct drm_device *dev)
  353. {
  354. u32 stat = nv_rd32(dev, 0x002100);
  355. if (stat & 0x00000100) {
  356. NV_INFO(dev, "PFIFO: unknown status 0x00000100\n");
  357. nv_wr32(dev, 0x002100, 0x00000100);
  358. stat &= ~0x00000100;
  359. }
  360. if (stat & 0x10000000) {
  361. u32 units = nv_rd32(dev, 0x00259c);
  362. u32 u = units;
  363. while (u) {
  364. int i = ffs(u) - 1;
  365. nvc0_fifo_isr_vm_fault(dev, i);
  366. u &= ~(1 << i);
  367. }
  368. nv_wr32(dev, 0x00259c, units);
  369. stat &= ~0x10000000;
  370. }
  371. if (stat & 0x20000000) {
  372. u32 units = nv_rd32(dev, 0x0025a0);
  373. u32 u = units;
  374. while (u) {
  375. int i = ffs(u) - 1;
  376. nvc0_fifo_isr_subfifo_intr(dev, i);
  377. u &= ~(1 << i);
  378. }
  379. nv_wr32(dev, 0x0025a0, units);
  380. stat &= ~0x20000000;
  381. }
  382. if (stat & 0x40000000) {
  383. NV_INFO(dev, "PFIFO: unknown status 0x40000000\n");
  384. nv_mask(dev, 0x002a00, 0x00000000, 0x00000000);
  385. stat &= ~0x40000000;
  386. }
  387. if (stat) {
  388. NV_INFO(dev, "PFIFO: unhandled status 0x%08x\n", stat);
  389. nv_wr32(dev, 0x002100, stat);
  390. nv_wr32(dev, 0x002140, 0);
  391. }
  392. }