nvc0_fifo.c 11 KB

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