nv50_fifo.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. /*
  2. * Copyright (C) 2007 Ben Skeggs.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include "drmP.h"
  27. #include "drm.h"
  28. #include "nouveau_drv.h"
  29. #include "nouveau_ramht.h"
  30. static void
  31. nv50_fifo_playlist_update(struct drm_device *dev)
  32. {
  33. struct drm_nouveau_private *dev_priv = dev->dev_private;
  34. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  35. struct nouveau_gpuobj *cur;
  36. int i, nr;
  37. NV_DEBUG(dev, "\n");
  38. cur = pfifo->playlist[pfifo->cur_playlist];
  39. pfifo->cur_playlist = !pfifo->cur_playlist;
  40. /* We never schedule channel 0 or 127 */
  41. for (i = 1, nr = 0; i < 127; i++) {
  42. if (dev_priv->fifos[i] && dev_priv->fifos[i]->ramfc) {
  43. nv_wo32(cur, (nr * 4), i);
  44. nr++;
  45. }
  46. }
  47. dev_priv->engine.instmem.flush(dev);
  48. nv_wr32(dev, 0x32f4, cur->vinst >> 12);
  49. nv_wr32(dev, 0x32ec, nr);
  50. nv_wr32(dev, 0x2500, 0x101);
  51. }
  52. static void
  53. nv50_fifo_channel_enable(struct drm_device *dev, int channel)
  54. {
  55. struct drm_nouveau_private *dev_priv = dev->dev_private;
  56. struct nouveau_channel *chan = dev_priv->fifos[channel];
  57. uint32_t inst;
  58. NV_DEBUG(dev, "ch%d\n", channel);
  59. if (dev_priv->chipset == 0x50)
  60. inst = chan->ramfc->vinst >> 12;
  61. else
  62. inst = chan->ramfc->vinst >> 8;
  63. nv_wr32(dev, NV50_PFIFO_CTX_TABLE(channel), inst |
  64. NV50_PFIFO_CTX_TABLE_CHANNEL_ENABLED);
  65. }
  66. static void
  67. nv50_fifo_channel_disable(struct drm_device *dev, int channel)
  68. {
  69. struct drm_nouveau_private *dev_priv = dev->dev_private;
  70. uint32_t inst;
  71. NV_DEBUG(dev, "ch%d\n", channel);
  72. if (dev_priv->chipset == 0x50)
  73. inst = NV50_PFIFO_CTX_TABLE_INSTANCE_MASK_G80;
  74. else
  75. inst = NV50_PFIFO_CTX_TABLE_INSTANCE_MASK_G84;
  76. nv_wr32(dev, NV50_PFIFO_CTX_TABLE(channel), inst);
  77. }
  78. static void
  79. nv50_fifo_init_reset(struct drm_device *dev)
  80. {
  81. uint32_t pmc_e = NV_PMC_ENABLE_PFIFO;
  82. NV_DEBUG(dev, "\n");
  83. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) & ~pmc_e);
  84. nv_wr32(dev, NV03_PMC_ENABLE, nv_rd32(dev, NV03_PMC_ENABLE) | pmc_e);
  85. }
  86. static void
  87. nv50_fifo_init_intr(struct drm_device *dev)
  88. {
  89. NV_DEBUG(dev, "\n");
  90. nv_wr32(dev, NV03_PFIFO_INTR_0, 0xFFFFFFFF);
  91. nv_wr32(dev, NV03_PFIFO_INTR_EN_0, 0xFFFFFFFF);
  92. }
  93. static void
  94. nv50_fifo_init_context_table(struct drm_device *dev)
  95. {
  96. struct drm_nouveau_private *dev_priv = dev->dev_private;
  97. int i;
  98. NV_DEBUG(dev, "\n");
  99. for (i = 0; i < NV50_PFIFO_CTX_TABLE__SIZE; i++) {
  100. if (dev_priv->fifos[i])
  101. nv50_fifo_channel_enable(dev, i);
  102. else
  103. nv50_fifo_channel_disable(dev, i);
  104. }
  105. nv50_fifo_playlist_update(dev);
  106. }
  107. static void
  108. nv50_fifo_init_regs__nv(struct drm_device *dev)
  109. {
  110. NV_DEBUG(dev, "\n");
  111. nv_wr32(dev, 0x250c, 0x6f3cfc34);
  112. }
  113. static void
  114. nv50_fifo_init_regs(struct drm_device *dev)
  115. {
  116. NV_DEBUG(dev, "\n");
  117. nv_wr32(dev, 0x2500, 0);
  118. nv_wr32(dev, 0x3250, 0);
  119. nv_wr32(dev, 0x3220, 0);
  120. nv_wr32(dev, 0x3204, 0);
  121. nv_wr32(dev, 0x3210, 0);
  122. nv_wr32(dev, 0x3270, 0);
  123. /* Enable dummy channels setup by nv50_instmem.c */
  124. nv50_fifo_channel_enable(dev, 0);
  125. nv50_fifo_channel_enable(dev, 127);
  126. }
  127. int
  128. nv50_fifo_init(struct drm_device *dev)
  129. {
  130. struct drm_nouveau_private *dev_priv = dev->dev_private;
  131. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  132. int ret;
  133. NV_DEBUG(dev, "\n");
  134. if (pfifo->playlist[0]) {
  135. pfifo->cur_playlist = !pfifo->cur_playlist;
  136. goto just_reset;
  137. }
  138. ret = nouveau_gpuobj_new(dev, NULL, 128*4, 0x1000,
  139. NVOBJ_FLAG_ZERO_ALLOC,
  140. &pfifo->playlist[0]);
  141. if (ret) {
  142. NV_ERROR(dev, "error creating playlist 0: %d\n", ret);
  143. return ret;
  144. }
  145. ret = nouveau_gpuobj_new(dev, NULL, 128*4, 0x1000,
  146. NVOBJ_FLAG_ZERO_ALLOC,
  147. &pfifo->playlist[1]);
  148. if (ret) {
  149. nouveau_gpuobj_ref(NULL, &pfifo->playlist[0]);
  150. NV_ERROR(dev, "error creating playlist 1: %d\n", ret);
  151. return ret;
  152. }
  153. just_reset:
  154. nv50_fifo_init_reset(dev);
  155. nv50_fifo_init_intr(dev);
  156. nv50_fifo_init_context_table(dev);
  157. nv50_fifo_init_regs__nv(dev);
  158. nv50_fifo_init_regs(dev);
  159. dev_priv->engine.fifo.enable(dev);
  160. dev_priv->engine.fifo.reassign(dev, true);
  161. return 0;
  162. }
  163. void
  164. nv50_fifo_takedown(struct drm_device *dev)
  165. {
  166. struct drm_nouveau_private *dev_priv = dev->dev_private;
  167. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  168. NV_DEBUG(dev, "\n");
  169. if (!pfifo->playlist[0])
  170. return;
  171. nouveau_gpuobj_ref(NULL, &pfifo->playlist[0]);
  172. nouveau_gpuobj_ref(NULL, &pfifo->playlist[1]);
  173. }
  174. int
  175. nv50_fifo_channel_id(struct drm_device *dev)
  176. {
  177. return nv_rd32(dev, NV03_PFIFO_CACHE1_PUSH1) &
  178. NV50_PFIFO_CACHE1_PUSH1_CHID_MASK;
  179. }
  180. int
  181. nv50_fifo_create_context(struct nouveau_channel *chan)
  182. {
  183. struct drm_device *dev = chan->dev;
  184. struct drm_nouveau_private *dev_priv = dev->dev_private;
  185. struct nouveau_gpuobj *ramfc = NULL;
  186. unsigned long flags;
  187. int ret;
  188. NV_DEBUG(dev, "ch%d\n", chan->id);
  189. if (dev_priv->chipset == 0x50) {
  190. ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst,
  191. chan->ramin->vinst, 0x100,
  192. NVOBJ_FLAG_ZERO_ALLOC |
  193. NVOBJ_FLAG_ZERO_FREE,
  194. &chan->ramfc);
  195. if (ret)
  196. return ret;
  197. ret = nouveau_gpuobj_new_fake(dev, chan->ramin->pinst + 0x0400,
  198. chan->ramin->vinst + 0x0400,
  199. 4096, 0, &chan->cache);
  200. if (ret)
  201. return ret;
  202. } else {
  203. ret = nouveau_gpuobj_new(dev, chan, 0x100, 256,
  204. NVOBJ_FLAG_ZERO_ALLOC |
  205. NVOBJ_FLAG_ZERO_FREE, &chan->ramfc);
  206. if (ret)
  207. return ret;
  208. ret = nouveau_gpuobj_new(dev, chan, 4096, 1024,
  209. 0, &chan->cache);
  210. if (ret)
  211. return ret;
  212. }
  213. ramfc = chan->ramfc;
  214. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  215. nv_wo32(ramfc, 0x48, chan->pushbuf->cinst >> 4);
  216. nv_wo32(ramfc, 0x80, ((chan->ramht->bits - 9) << 27) |
  217. (4 << 24) /* SEARCH_FULL */ |
  218. (chan->ramht->gpuobj->cinst >> 4));
  219. nv_wo32(ramfc, 0x44, 0x2101ffff);
  220. nv_wo32(ramfc, 0x60, 0x7fffffff);
  221. nv_wo32(ramfc, 0x40, 0x00000000);
  222. nv_wo32(ramfc, 0x7c, 0x30000001);
  223. nv_wo32(ramfc, 0x78, 0x00000000);
  224. nv_wo32(ramfc, 0x3c, 0x403f6078);
  225. nv_wo32(ramfc, 0x50, chan->pushbuf_base + chan->dma.ib_base * 4);
  226. nv_wo32(ramfc, 0x54, drm_order(chan->dma.ib_max + 1) << 16);
  227. if (dev_priv->chipset != 0x50) {
  228. nv_wo32(chan->ramin, 0, chan->id);
  229. nv_wo32(chan->ramin, 4, chan->ramfc->vinst >> 8);
  230. nv_wo32(ramfc, 0x88, chan->cache->vinst >> 10);
  231. nv_wo32(ramfc, 0x98, chan->ramin->vinst >> 12);
  232. }
  233. dev_priv->engine.instmem.flush(dev);
  234. nv50_fifo_channel_enable(dev, chan->id);
  235. nv50_fifo_playlist_update(dev);
  236. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  237. return 0;
  238. }
  239. void
  240. nv50_fifo_destroy_context(struct nouveau_channel *chan)
  241. {
  242. struct drm_device *dev = chan->dev;
  243. struct nouveau_gpuobj *ramfc = NULL;
  244. NV_DEBUG(dev, "ch%d\n", chan->id);
  245. /* This will ensure the channel is seen as disabled. */
  246. nouveau_gpuobj_ref(chan->ramfc, &ramfc);
  247. nouveau_gpuobj_ref(NULL, &chan->ramfc);
  248. nv50_fifo_channel_disable(dev, chan->id);
  249. /* Dummy channel, also used on ch 127 */
  250. if (chan->id == 0)
  251. nv50_fifo_channel_disable(dev, 127);
  252. nv50_fifo_playlist_update(dev);
  253. nouveau_gpuobj_ref(NULL, &ramfc);
  254. nouveau_gpuobj_ref(NULL, &chan->cache);
  255. }
  256. int
  257. nv50_fifo_load_context(struct nouveau_channel *chan)
  258. {
  259. struct drm_device *dev = chan->dev;
  260. struct drm_nouveau_private *dev_priv = dev->dev_private;
  261. struct nouveau_gpuobj *ramfc = chan->ramfc;
  262. struct nouveau_gpuobj *cache = chan->cache;
  263. int ptr, cnt;
  264. NV_DEBUG(dev, "ch%d\n", chan->id);
  265. nv_wr32(dev, 0x3330, nv_ro32(ramfc, 0x00));
  266. nv_wr32(dev, 0x3334, nv_ro32(ramfc, 0x04));
  267. nv_wr32(dev, 0x3240, nv_ro32(ramfc, 0x08));
  268. nv_wr32(dev, 0x3320, nv_ro32(ramfc, 0x0c));
  269. nv_wr32(dev, 0x3244, nv_ro32(ramfc, 0x10));
  270. nv_wr32(dev, 0x3328, nv_ro32(ramfc, 0x14));
  271. nv_wr32(dev, 0x3368, nv_ro32(ramfc, 0x18));
  272. nv_wr32(dev, 0x336c, nv_ro32(ramfc, 0x1c));
  273. nv_wr32(dev, 0x3370, nv_ro32(ramfc, 0x20));
  274. nv_wr32(dev, 0x3374, nv_ro32(ramfc, 0x24));
  275. nv_wr32(dev, 0x3378, nv_ro32(ramfc, 0x28));
  276. nv_wr32(dev, 0x337c, nv_ro32(ramfc, 0x2c));
  277. nv_wr32(dev, 0x3228, nv_ro32(ramfc, 0x30));
  278. nv_wr32(dev, 0x3364, nv_ro32(ramfc, 0x34));
  279. nv_wr32(dev, 0x32a0, nv_ro32(ramfc, 0x38));
  280. nv_wr32(dev, 0x3224, nv_ro32(ramfc, 0x3c));
  281. nv_wr32(dev, 0x324c, nv_ro32(ramfc, 0x40));
  282. nv_wr32(dev, 0x2044, nv_ro32(ramfc, 0x44));
  283. nv_wr32(dev, 0x322c, nv_ro32(ramfc, 0x48));
  284. nv_wr32(dev, 0x3234, nv_ro32(ramfc, 0x4c));
  285. nv_wr32(dev, 0x3340, nv_ro32(ramfc, 0x50));
  286. nv_wr32(dev, 0x3344, nv_ro32(ramfc, 0x54));
  287. nv_wr32(dev, 0x3280, nv_ro32(ramfc, 0x58));
  288. nv_wr32(dev, 0x3254, nv_ro32(ramfc, 0x5c));
  289. nv_wr32(dev, 0x3260, nv_ro32(ramfc, 0x60));
  290. nv_wr32(dev, 0x3264, nv_ro32(ramfc, 0x64));
  291. nv_wr32(dev, 0x3268, nv_ro32(ramfc, 0x68));
  292. nv_wr32(dev, 0x326c, nv_ro32(ramfc, 0x6c));
  293. nv_wr32(dev, 0x32e4, nv_ro32(ramfc, 0x70));
  294. nv_wr32(dev, 0x3248, nv_ro32(ramfc, 0x74));
  295. nv_wr32(dev, 0x2088, nv_ro32(ramfc, 0x78));
  296. nv_wr32(dev, 0x2058, nv_ro32(ramfc, 0x7c));
  297. nv_wr32(dev, 0x2210, nv_ro32(ramfc, 0x80));
  298. cnt = nv_ro32(ramfc, 0x84);
  299. for (ptr = 0; ptr < cnt; ptr++) {
  300. nv_wr32(dev, NV40_PFIFO_CACHE1_METHOD(ptr),
  301. nv_ro32(cache, (ptr * 8) + 0));
  302. nv_wr32(dev, NV40_PFIFO_CACHE1_DATA(ptr),
  303. nv_ro32(cache, (ptr * 8) + 4));
  304. }
  305. nv_wr32(dev, NV03_PFIFO_CACHE1_PUT, cnt << 2);
  306. nv_wr32(dev, NV03_PFIFO_CACHE1_GET, 0);
  307. /* guessing that all the 0x34xx regs aren't on NV50 */
  308. if (dev_priv->chipset != 0x50) {
  309. nv_wr32(dev, 0x340c, nv_ro32(ramfc, 0x88));
  310. nv_wr32(dev, 0x3400, nv_ro32(ramfc, 0x8c));
  311. nv_wr32(dev, 0x3404, nv_ro32(ramfc, 0x90));
  312. nv_wr32(dev, 0x3408, nv_ro32(ramfc, 0x94));
  313. nv_wr32(dev, 0x3410, nv_ro32(ramfc, 0x98));
  314. }
  315. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, chan->id | (1<<16));
  316. return 0;
  317. }
  318. int
  319. nv50_fifo_unload_context(struct drm_device *dev)
  320. {
  321. struct drm_nouveau_private *dev_priv = dev->dev_private;
  322. struct nouveau_fifo_engine *pfifo = &dev_priv->engine.fifo;
  323. struct nouveau_gpuobj *ramfc, *cache;
  324. struct nouveau_channel *chan = NULL;
  325. int chid, get, put, ptr;
  326. NV_DEBUG(dev, "\n");
  327. chid = pfifo->channel_id(dev);
  328. if (chid < 1 || chid >= dev_priv->engine.fifo.channels - 1)
  329. return 0;
  330. chan = dev_priv->fifos[chid];
  331. if (!chan) {
  332. NV_ERROR(dev, "Inactive channel on PFIFO: %d\n", chid);
  333. return -EINVAL;
  334. }
  335. NV_DEBUG(dev, "ch%d\n", chan->id);
  336. ramfc = chan->ramfc;
  337. cache = chan->cache;
  338. nv_wo32(ramfc, 0x00, nv_rd32(dev, 0x3330));
  339. nv_wo32(ramfc, 0x04, nv_rd32(dev, 0x3334));
  340. nv_wo32(ramfc, 0x08, nv_rd32(dev, 0x3240));
  341. nv_wo32(ramfc, 0x0c, nv_rd32(dev, 0x3320));
  342. nv_wo32(ramfc, 0x10, nv_rd32(dev, 0x3244));
  343. nv_wo32(ramfc, 0x14, nv_rd32(dev, 0x3328));
  344. nv_wo32(ramfc, 0x18, nv_rd32(dev, 0x3368));
  345. nv_wo32(ramfc, 0x1c, nv_rd32(dev, 0x336c));
  346. nv_wo32(ramfc, 0x20, nv_rd32(dev, 0x3370));
  347. nv_wo32(ramfc, 0x24, nv_rd32(dev, 0x3374));
  348. nv_wo32(ramfc, 0x28, nv_rd32(dev, 0x3378));
  349. nv_wo32(ramfc, 0x2c, nv_rd32(dev, 0x337c));
  350. nv_wo32(ramfc, 0x30, nv_rd32(dev, 0x3228));
  351. nv_wo32(ramfc, 0x34, nv_rd32(dev, 0x3364));
  352. nv_wo32(ramfc, 0x38, nv_rd32(dev, 0x32a0));
  353. nv_wo32(ramfc, 0x3c, nv_rd32(dev, 0x3224));
  354. nv_wo32(ramfc, 0x40, nv_rd32(dev, 0x324c));
  355. nv_wo32(ramfc, 0x44, nv_rd32(dev, 0x2044));
  356. nv_wo32(ramfc, 0x48, nv_rd32(dev, 0x322c));
  357. nv_wo32(ramfc, 0x4c, nv_rd32(dev, 0x3234));
  358. nv_wo32(ramfc, 0x50, nv_rd32(dev, 0x3340));
  359. nv_wo32(ramfc, 0x54, nv_rd32(dev, 0x3344));
  360. nv_wo32(ramfc, 0x58, nv_rd32(dev, 0x3280));
  361. nv_wo32(ramfc, 0x5c, nv_rd32(dev, 0x3254));
  362. nv_wo32(ramfc, 0x60, nv_rd32(dev, 0x3260));
  363. nv_wo32(ramfc, 0x64, nv_rd32(dev, 0x3264));
  364. nv_wo32(ramfc, 0x68, nv_rd32(dev, 0x3268));
  365. nv_wo32(ramfc, 0x6c, nv_rd32(dev, 0x326c));
  366. nv_wo32(ramfc, 0x70, nv_rd32(dev, 0x32e4));
  367. nv_wo32(ramfc, 0x74, nv_rd32(dev, 0x3248));
  368. nv_wo32(ramfc, 0x78, nv_rd32(dev, 0x2088));
  369. nv_wo32(ramfc, 0x7c, nv_rd32(dev, 0x2058));
  370. nv_wo32(ramfc, 0x80, nv_rd32(dev, 0x2210));
  371. put = (nv_rd32(dev, NV03_PFIFO_CACHE1_PUT) & 0x7ff) >> 2;
  372. get = (nv_rd32(dev, NV03_PFIFO_CACHE1_GET) & 0x7ff) >> 2;
  373. ptr = 0;
  374. while (put != get) {
  375. nv_wo32(cache, ptr + 0,
  376. nv_rd32(dev, NV40_PFIFO_CACHE1_METHOD(get)));
  377. nv_wo32(cache, ptr + 4,
  378. nv_rd32(dev, NV40_PFIFO_CACHE1_DATA(get)));
  379. get = (get + 1) & 0x1ff;
  380. ptr += 8;
  381. }
  382. /* guessing that all the 0x34xx regs aren't on NV50 */
  383. if (dev_priv->chipset != 0x50) {
  384. nv_wo32(ramfc, 0x84, ptr >> 3);
  385. nv_wo32(ramfc, 0x88, nv_rd32(dev, 0x340c));
  386. nv_wo32(ramfc, 0x8c, nv_rd32(dev, 0x3400));
  387. nv_wo32(ramfc, 0x90, nv_rd32(dev, 0x3404));
  388. nv_wo32(ramfc, 0x94, nv_rd32(dev, 0x3408));
  389. nv_wo32(ramfc, 0x98, nv_rd32(dev, 0x3410));
  390. }
  391. dev_priv->engine.instmem.flush(dev);
  392. /*XXX: probably reload ch127 (NULL) state back too */
  393. nv_wr32(dev, NV03_PFIFO_CACHE1_PUSH1, 127);
  394. return 0;
  395. }
  396. void
  397. nv50_fifo_tlb_flush(struct drm_device *dev)
  398. {
  399. nv50_vm_flush(dev, 5);
  400. }