nv50_evo.c 9.0 KB

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