nv50_evo.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  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_dma.h"
  27. #include "nouveau_ramht.h"
  28. static void
  29. nv50_evo_channel_del(struct nouveau_channel **pevo)
  30. {
  31. struct drm_nouveau_private *dev_priv;
  32. struct nouveau_channel *evo = *pevo;
  33. if (!evo)
  34. return;
  35. *pevo = NULL;
  36. dev_priv = evo->dev->dev_private;
  37. dev_priv->evo_alloc &= ~(1 << evo->id);
  38. nouveau_gpuobj_channel_takedown(evo);
  39. nouveau_bo_unmap(evo->pushbuf_bo);
  40. nouveau_bo_ref(NULL, &evo->pushbuf_bo);
  41. if (evo->user)
  42. iounmap(evo->user);
  43. kfree(evo);
  44. }
  45. int
  46. nv50_evo_dmaobj_new(struct nouveau_channel *evo, u32 class, u32 name,
  47. u32 tile_flags, u32 magic_flags, u32 offset, u32 limit)
  48. {
  49. struct drm_nouveau_private *dev_priv = evo->dev->dev_private;
  50. struct drm_device *dev = evo->dev;
  51. struct nouveau_gpuobj *obj = NULL;
  52. int ret;
  53. ret = nouveau_gpuobj_new(dev, dev_priv->evo, 6*4, 32, 0, &obj);
  54. if (ret)
  55. return ret;
  56. obj->engine = NVOBJ_ENGINE_DISPLAY;
  57. nv_wo32(obj, 0, (tile_flags << 22) | (magic_flags << 16) | class);
  58. nv_wo32(obj, 4, limit);
  59. nv_wo32(obj, 8, offset);
  60. nv_wo32(obj, 12, 0x00000000);
  61. nv_wo32(obj, 16, 0x00000000);
  62. if (dev_priv->card_type < NV_C0)
  63. nv_wo32(obj, 20, 0x00010000);
  64. else
  65. nv_wo32(obj, 20, 0x00020000);
  66. dev_priv->engine.instmem.flush(dev);
  67. ret = nouveau_ramht_insert(evo, name, obj);
  68. nouveau_gpuobj_ref(NULL, &obj);
  69. if (ret) {
  70. return ret;
  71. }
  72. return 0;
  73. }
  74. static int
  75. nv50_evo_channel_new(struct drm_device *dev, struct nouveau_channel **pevo)
  76. {
  77. struct drm_nouveau_private *dev_priv = dev->dev_private;
  78. struct nouveau_channel *evo;
  79. int ret;
  80. evo = kzalloc(sizeof(struct nouveau_channel), GFP_KERNEL);
  81. if (!evo)
  82. return -ENOMEM;
  83. *pevo = evo;
  84. for (evo->id = 0; evo->id < 5; evo->id++) {
  85. if (dev_priv->evo_alloc & (1 << evo->id))
  86. continue;
  87. dev_priv->evo_alloc |= (1 << evo->id);
  88. break;
  89. }
  90. if (evo->id == 5) {
  91. kfree(evo);
  92. return -ENODEV;
  93. }
  94. evo->dev = dev;
  95. evo->user_get = 4;
  96. evo->user_put = 0;
  97. ret = nouveau_bo_new(dev, NULL, 4096, 0, TTM_PL_FLAG_VRAM, 0, 0,
  98. false, true, &evo->pushbuf_bo);
  99. if (ret == 0)
  100. ret = nouveau_bo_pin(evo->pushbuf_bo, TTM_PL_FLAG_VRAM);
  101. if (ret) {
  102. NV_ERROR(dev, "Error creating EVO DMA push buffer: %d\n", ret);
  103. nv50_evo_channel_del(pevo);
  104. return ret;
  105. }
  106. ret = nouveau_bo_map(evo->pushbuf_bo);
  107. if (ret) {
  108. NV_ERROR(dev, "Error mapping EVO DMA push buffer: %d\n", ret);
  109. nv50_evo_channel_del(pevo);
  110. return ret;
  111. }
  112. evo->user = ioremap(pci_resource_start(dev->pdev, 0) +
  113. NV50_PDISPLAY_USER(evo->id), PAGE_SIZE);
  114. if (!evo->user) {
  115. NV_ERROR(dev, "Error mapping EVO control regs.\n");
  116. nv50_evo_channel_del(pevo);
  117. return -ENOMEM;
  118. }
  119. /* bind primary evo channel's ramht to the channel */
  120. if (dev_priv->evo && evo != dev_priv->evo)
  121. nouveau_ramht_ref(dev_priv->evo->ramht, &evo->ramht, NULL);
  122. return 0;
  123. }
  124. static int
  125. nv50_evo_channel_init(struct nouveau_channel *evo)
  126. {
  127. struct drm_nouveau_private *dev_priv = evo->dev->dev_private;
  128. struct nouveau_timer_engine *ptimer = &dev_priv->engine.timer;
  129. struct drm_device *dev = evo->dev;
  130. int id = evo->id, ret, i;
  131. u64 start;
  132. u32 tmp;
  133. /* taken from nv bug #12637, attempts to un-wedge the hw if it's
  134. * stuck in some unspecified state
  135. */
  136. start = ptimer->read(dev);
  137. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x2b00);
  138. while ((tmp = nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id))) & 0x1e0000) {
  139. if ((tmp & 0x9f0000) == 0x20000)
  140. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x800000);
  141. if ((tmp & 0x3f0000) == 0x30000)
  142. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), tmp | 0x200000);
  143. if (ptimer->read(dev) - start > 1000000000ULL) {
  144. NV_ERROR(dev, "timeout: (0x610200 & 0x1e0000) != 0\n");
  145. NV_ERROR(dev, "0x610200 = 0x%08x\n", tmp);
  146. return -EBUSY;
  147. }
  148. }
  149. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x1000b03);
  150. if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(id),
  151. 0x40000000, 0x40000000)) {
  152. NV_ERROR(dev, "timeout: (0x610200 & 0x40000000) == 0x40000000\n");
  153. NV_ERROR(dev, "0x610200 = 0x%08x\n",
  154. nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id)));
  155. return -EBUSY;
  156. }
  157. /* initialise fifo */
  158. nv_wr32(dev, NV50_PDISPLAY_EVO_DMA_CB(id),
  159. ((evo->pushbuf_bo->bo.mem.start << PAGE_SHIFT) >> 8) |
  160. NV50_PDISPLAY_EVO_DMA_CB_LOCATION_VRAM |
  161. NV50_PDISPLAY_EVO_DMA_CB_VALID);
  162. nv_wr32(dev, NV50_PDISPLAY_EVO_UNK2(id), 0x00010000);
  163. nv_wr32(dev, NV50_PDISPLAY_EVO_HASH_TAG(id), id);
  164. if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x80000000, 0x00000000)) {
  165. NV_ERROR(dev, "timeout: (0x610200 & 0x80000000) == 0\n");
  166. NV_ERROR(dev, "0x610200 = 0x%08x\n",
  167. nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id)));
  168. return -EBUSY;
  169. }
  170. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id),
  171. (nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(id)) & ~0x00000003) |
  172. NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
  173. nv_wr32(dev, NV50_PDISPLAY_USER_PUT(id), 0);
  174. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(id), 0x01000003 |
  175. NV50_PDISPLAY_EVO_CTRL_DMA_ENABLED);
  176. /* enable error reporting on the channel */
  177. nv_mask(dev, 0x610028, 0x00000000, 0x00010001 << id);
  178. evo->dma.max = (4096/4) - 2;
  179. evo->dma.put = 0;
  180. evo->dma.cur = evo->dma.put;
  181. evo->dma.free = evo->dma.max - evo->dma.cur;
  182. ret = RING_SPACE(evo, NOUVEAU_DMA_SKIPS);
  183. if (ret)
  184. return ret;
  185. for (i = 0; i < NOUVEAU_DMA_SKIPS; i++)
  186. OUT_RING(evo, 0);
  187. return 0;
  188. }
  189. static void
  190. nv50_evo_channel_fini(struct nouveau_channel *evo)
  191. {
  192. struct drm_device *dev = evo->dev;
  193. nv_wr32(dev, NV50_PDISPLAY_EVO_CTRL(evo->id), 0);
  194. if (!nv_wait(dev, NV50_PDISPLAY_EVO_CTRL(evo->id), 0x1e0000, 0)) {
  195. NV_ERROR(dev, "timeout: (0x610200 & 0x1e0000) == 0\n");
  196. NV_ERROR(dev, "0x610200 = 0x%08x\n",
  197. nv_rd32(dev, NV50_PDISPLAY_EVO_CTRL(evo->id)));
  198. }
  199. }
  200. static int
  201. nv50_evo_create(struct drm_device *dev)
  202. {
  203. struct drm_nouveau_private *dev_priv = dev->dev_private;
  204. struct nouveau_gpuobj *ramht = NULL;
  205. struct nouveau_channel *evo;
  206. int ret;
  207. /* create primary evo channel, the one we use for modesetting
  208. * purporses
  209. */
  210. ret = nv50_evo_channel_new(dev, &dev_priv->evo);
  211. if (ret)
  212. return ret;
  213. evo = dev_priv->evo;
  214. /* setup object management on it, any other evo channel will
  215. * use this also as there's no per-channel support on the
  216. * hardware
  217. */
  218. ret = nouveau_gpuobj_new(dev, NULL, 32768, 0x1000,
  219. NVOBJ_FLAG_ZERO_ALLOC, &evo->ramin);
  220. if (ret) {
  221. NV_ERROR(dev, "Error allocating EVO channel memory: %d\n", ret);
  222. nv50_evo_channel_del(&dev_priv->evo);
  223. return ret;
  224. }
  225. ret = drm_mm_init(&evo->ramin_heap, 0, 32768);
  226. if (ret) {
  227. NV_ERROR(dev, "Error initialising EVO PRAMIN heap: %d\n", ret);
  228. nv50_evo_channel_del(&dev_priv->evo);
  229. return ret;
  230. }
  231. ret = nouveau_gpuobj_new(dev, evo, 4096, 16, 0, &ramht);
  232. if (ret) {
  233. NV_ERROR(dev, "Unable to allocate EVO RAMHT: %d\n", ret);
  234. nv50_evo_channel_del(&dev_priv->evo);
  235. return ret;
  236. }
  237. ret = nouveau_ramht_new(dev, ramht, &evo->ramht);
  238. nouveau_gpuobj_ref(NULL, &ramht);
  239. if (ret) {
  240. nv50_evo_channel_del(&dev_priv->evo);
  241. return ret;
  242. }
  243. /* create some default objects for the scanout memtypes we support */
  244. if (dev_priv->chipset != 0x50) {
  245. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB16, 0x70, 0x19,
  246. 0, 0xffffffff);
  247. if (ret) {
  248. nv50_evo_channel_del(&dev_priv->evo);
  249. return ret;
  250. }
  251. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoFB32, 0x7a, 0x19,
  252. 0, 0xffffffff);
  253. if (ret) {
  254. nv50_evo_channel_del(&dev_priv->evo);
  255. return ret;
  256. }
  257. }
  258. ret = nv50_evo_dmaobj_new(evo, 0x3d, NvEvoVRAM, 0, 0x19,
  259. 0, dev_priv->vram_size);
  260. if (ret) {
  261. nv50_evo_channel_del(&dev_priv->evo);
  262. return ret;
  263. }
  264. return 0;
  265. }
  266. int
  267. nv50_evo_init(struct drm_device *dev)
  268. {
  269. struct drm_nouveau_private *dev_priv = dev->dev_private;
  270. int ret;
  271. if (!dev_priv->evo) {
  272. ret = nv50_evo_create(dev);
  273. if (ret)
  274. return ret;
  275. }
  276. return nv50_evo_channel_init(dev_priv->evo);
  277. }
  278. void
  279. nv50_evo_fini(struct drm_device *dev)
  280. {
  281. struct drm_nouveau_private *dev_priv = dev->dev_private;
  282. if (dev_priv->evo) {
  283. nv50_evo_channel_fini(dev_priv->evo);
  284. nv50_evo_channel_del(&dev_priv->evo);
  285. }
  286. }