nvc0_fifo.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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. NVOBJ_CLASS(dev, 0x506e, SW); /* nvsw */
  237. return 0;
  238. error:
  239. nvc0_fifo_destroy(dev);
  240. return ret;
  241. }
  242. int
  243. nvc0_fifo_init(struct drm_device *dev)
  244. {
  245. struct drm_nouveau_private *dev_priv = dev->dev_private;
  246. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  247. struct nouveau_channel *chan;
  248. struct nvc0_fifo_priv *priv;
  249. int ret, i;
  250. if (!pfifo->priv) {
  251. ret = nvc0_fifo_create(dev);
  252. if (ret)
  253. return ret;
  254. }
  255. priv = pfifo->priv;
  256. /* reset PFIFO, enable all available PSUBFIFO areas */
  257. nv_mask(dev, 0x000200, 0x00000100, 0x00000000);
  258. nv_mask(dev, 0x000200, 0x00000100, 0x00000100);
  259. nv_wr32(dev, 0x000204, 0xffffffff);
  260. nv_wr32(dev, 0x002204, 0xffffffff);
  261. priv->spoon_nr = hweight32(nv_rd32(dev, 0x002204));
  262. NV_DEBUG(dev, "PFIFO: %d subfifo(s)\n", priv->spoon_nr);
  263. /* assign engines to subfifos */
  264. if (priv->spoon_nr >= 3) {
  265. nv_wr32(dev, 0x002208, ~(1 << 0)); /* PGRAPH */
  266. nv_wr32(dev, 0x00220c, ~(1 << 1)); /* PVP */
  267. nv_wr32(dev, 0x002210, ~(1 << 1)); /* PPP */
  268. nv_wr32(dev, 0x002214, ~(1 << 1)); /* PBSP */
  269. nv_wr32(dev, 0x002218, ~(1 << 2)); /* PCE0 */
  270. nv_wr32(dev, 0x00221c, ~(1 << 1)); /* PCE1 */
  271. }
  272. /* PSUBFIFO[n] */
  273. for (i = 0; i < 3; i++) {
  274. nv_mask(dev, 0x04013c + (i * 0x2000), 0x10000100, 0x00000000);
  275. nv_wr32(dev, 0x040108 + (i * 0x2000), 0xffffffff); /* INTR */
  276. nv_wr32(dev, 0x04010c + (i * 0x2000), 0xfffffeff); /* INTR_EN */
  277. }
  278. nv_mask(dev, 0x002200, 0x00000001, 0x00000001);
  279. nv_wr32(dev, 0x002254, 0x10000000 | priv->user_vma.offset >> 12);
  280. nv_wr32(dev, 0x002a00, 0xffffffff); /* clears PFIFO.INTR bit 30 */
  281. nv_wr32(dev, 0x002100, 0xffffffff);
  282. nv_wr32(dev, 0x002140, 0xbfffffff);
  283. /* restore PFIFO context table */
  284. for (i = 0; i < 128; i++) {
  285. chan = dev_priv->channels.ptr[i];
  286. if (!chan || !chan->fifo_priv)
  287. continue;
  288. nv_wr32(dev, 0x003000 + (i * 8), 0xc0000000 |
  289. (chan->ramin->vinst >> 12));
  290. nv_wr32(dev, 0x003004 + (i * 8), 0x001f0001);
  291. }
  292. nvc0_fifo_playlist_update(dev);
  293. return 0;
  294. }
  295. struct nouveau_enum nvc0_fifo_fault_unit[] = {
  296. { 0x00, "PGRAPH" },
  297. { 0x03, "PEEPHOLE" },
  298. { 0x04, "BAR1" },
  299. { 0x05, "BAR3" },
  300. { 0x07, "PFIFO" },
  301. { 0x10, "PBSP" },
  302. { 0x11, "PPPP" },
  303. { 0x13, "PCOUNTER" },
  304. { 0x14, "PVP" },
  305. { 0x15, "PCOPY0" },
  306. { 0x16, "PCOPY1" },
  307. { 0x17, "PDAEMON" },
  308. {}
  309. };
  310. struct nouveau_enum nvc0_fifo_fault_reason[] = {
  311. { 0x00, "PT_NOT_PRESENT" },
  312. { 0x01, "PT_TOO_SHORT" },
  313. { 0x02, "PAGE_NOT_PRESENT" },
  314. { 0x03, "VM_LIMIT_EXCEEDED" },
  315. { 0x04, "NO_CHANNEL" },
  316. { 0x05, "PAGE_SYSTEM_ONLY" },
  317. { 0x06, "PAGE_READ_ONLY" },
  318. { 0x0a, "COMPRESSED_SYSRAM" },
  319. { 0x0c, "INVALID_STORAGE_TYPE" },
  320. {}
  321. };
  322. struct nouveau_enum nvc0_fifo_fault_hubclient[] = {
  323. { 0x01, "PCOPY0" },
  324. { 0x02, "PCOPY1" },
  325. { 0x04, "DISPATCH" },
  326. { 0x05, "CTXCTL" },
  327. { 0x06, "PFIFO" },
  328. { 0x07, "BAR_READ" },
  329. { 0x08, "BAR_WRITE" },
  330. { 0x0b, "PVP" },
  331. { 0x0c, "PPPP" },
  332. { 0x0d, "PBSP" },
  333. { 0x11, "PCOUNTER" },
  334. { 0x12, "PDAEMON" },
  335. { 0x14, "CCACHE" },
  336. { 0x15, "CCACHE_POST" },
  337. {}
  338. };
  339. struct nouveau_enum nvc0_fifo_fault_gpcclient[] = {
  340. { 0x01, "TEX" },
  341. { 0x0c, "ESETUP" },
  342. { 0x0e, "CTXCTL" },
  343. { 0x0f, "PROP" },
  344. {}
  345. };
  346. struct nouveau_bitfield nvc0_fifo_subfifo_intr[] = {
  347. /* { 0x00008000, "" } seen with null ib push */
  348. { 0x00200000, "ILLEGAL_MTHD" },
  349. { 0x00800000, "EMPTY_SUBC" },
  350. {}
  351. };
  352. static void
  353. nvc0_fifo_isr_vm_fault(struct drm_device *dev, int unit)
  354. {
  355. u32 inst = nv_rd32(dev, 0x2800 + (unit * 0x10));
  356. u32 valo = nv_rd32(dev, 0x2804 + (unit * 0x10));
  357. u32 vahi = nv_rd32(dev, 0x2808 + (unit * 0x10));
  358. u32 stat = nv_rd32(dev, 0x280c + (unit * 0x10));
  359. u32 client = (stat & 0x00001f00) >> 8;
  360. NV_INFO(dev, "PFIFO: %s fault at 0x%010llx [",
  361. (stat & 0x00000080) ? "write" : "read", (u64)vahi << 32 | valo);
  362. nouveau_enum_print(nvc0_fifo_fault_reason, stat & 0x0000000f);
  363. printk("] from ");
  364. nouveau_enum_print(nvc0_fifo_fault_unit, unit);
  365. if (stat & 0x00000040) {
  366. printk("/");
  367. nouveau_enum_print(nvc0_fifo_fault_hubclient, client);
  368. } else {
  369. printk("/GPC%d/", (stat & 0x1f000000) >> 24);
  370. nouveau_enum_print(nvc0_fifo_fault_gpcclient, client);
  371. }
  372. printk(" on channel 0x%010llx\n", (u64)inst << 12);
  373. }
  374. static void
  375. nvc0_fifo_isr_subfifo_intr(struct drm_device *dev, int unit)
  376. {
  377. u32 stat = nv_rd32(dev, 0x040108 + (unit * 0x2000));
  378. u32 addr = nv_rd32(dev, 0x0400c0 + (unit * 0x2000));
  379. u32 data = nv_rd32(dev, 0x0400c4 + (unit * 0x2000));
  380. u32 chid = nv_rd32(dev, 0x040120 + (unit * 0x2000)) & 0x7f;
  381. u32 subc = (addr & 0x00070000);
  382. u32 mthd = (addr & 0x00003ffc);
  383. NV_INFO(dev, "PSUBFIFO %d:", unit);
  384. nouveau_bitfield_print(nvc0_fifo_subfifo_intr, stat);
  385. NV_INFO(dev, "PSUBFIFO %d: ch %d subc %d mthd 0x%04x data 0x%08x\n",
  386. unit, chid, subc, mthd, data);
  387. nv_wr32(dev, 0x0400c0 + (unit * 0x2000), 0x80600008);
  388. nv_wr32(dev, 0x040108 + (unit * 0x2000), stat);
  389. }
  390. static void
  391. nvc0_fifo_isr(struct drm_device *dev)
  392. {
  393. u32 stat = nv_rd32(dev, 0x002100);
  394. if (stat & 0x00000100) {
  395. NV_INFO(dev, "PFIFO: unknown status 0x00000100\n");
  396. nv_wr32(dev, 0x002100, 0x00000100);
  397. stat &= ~0x00000100;
  398. }
  399. if (stat & 0x10000000) {
  400. u32 units = nv_rd32(dev, 0x00259c);
  401. u32 u = units;
  402. while (u) {
  403. int i = ffs(u) - 1;
  404. nvc0_fifo_isr_vm_fault(dev, i);
  405. u &= ~(1 << i);
  406. }
  407. nv_wr32(dev, 0x00259c, units);
  408. stat &= ~0x10000000;
  409. }
  410. if (stat & 0x20000000) {
  411. u32 units = nv_rd32(dev, 0x0025a0);
  412. u32 u = units;
  413. while (u) {
  414. int i = ffs(u) - 1;
  415. nvc0_fifo_isr_subfifo_intr(dev, i);
  416. u &= ~(1 << i);
  417. }
  418. nv_wr32(dev, 0x0025a0, units);
  419. stat &= ~0x20000000;
  420. }
  421. if (stat & 0x40000000) {
  422. NV_INFO(dev, "PFIFO: unknown status 0x40000000\n");
  423. nv_mask(dev, 0x002a00, 0x00000000, 0x00000000);
  424. stat &= ~0x40000000;
  425. }
  426. if (stat) {
  427. NV_INFO(dev, "PFIFO: unhandled status 0x%08x\n", stat);
  428. nv_wr32(dev, 0x002100, stat);
  429. nv_wr32(dev, 0x002140, 0);
  430. }
  431. }