nv50_mpeg.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /*
  2. * Copyright 2011 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_ramht.h"
  27. struct nv50_mpeg_engine {
  28. struct nouveau_exec_engine base;
  29. };
  30. static inline u32
  31. CTX_PTR(struct drm_device *dev, u32 offset)
  32. {
  33. struct drm_nouveau_private *dev_priv = dev->dev_private;
  34. if (dev_priv->chipset == 0x50)
  35. offset += 0x0260;
  36. else
  37. offset += 0x0060;
  38. return offset;
  39. }
  40. static int
  41. nv50_mpeg_context_new(struct nouveau_channel *chan, int engine)
  42. {
  43. struct drm_device *dev = chan->dev;
  44. struct drm_nouveau_private *dev_priv = dev->dev_private;
  45. struct nouveau_gpuobj *ramin = chan->ramin;
  46. struct nouveau_gpuobj *ctx = NULL;
  47. int ret;
  48. NV_DEBUG(dev, "ch%d\n", chan->id);
  49. ret = nouveau_gpuobj_new(dev, chan, 128 * 4, 0, NVOBJ_FLAG_ZERO_ALLOC |
  50. NVOBJ_FLAG_ZERO_FREE, &ctx);
  51. if (ret)
  52. return ret;
  53. nv_wo32(ramin, CTX_PTR(dev, 0x00), 0x80190002);
  54. nv_wo32(ramin, CTX_PTR(dev, 0x04), ctx->vinst + ctx->size - 1);
  55. nv_wo32(ramin, CTX_PTR(dev, 0x08), ctx->vinst);
  56. nv_wo32(ramin, CTX_PTR(dev, 0x0c), 0);
  57. nv_wo32(ramin, CTX_PTR(dev, 0x10), 0);
  58. nv_wo32(ramin, CTX_PTR(dev, 0x14), 0x00010000);
  59. nv_wo32(ctx, 0x70, 0x00801ec1);
  60. nv_wo32(ctx, 0x7c, 0x0000037c);
  61. dev_priv->engine.instmem.flush(dev);
  62. chan->engctx[engine] = ctx;
  63. return 0;
  64. }
  65. static void
  66. nv50_mpeg_context_del(struct nouveau_channel *chan, int engine)
  67. {
  68. struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
  69. struct nouveau_gpuobj *ctx = chan->engctx[engine];
  70. struct drm_device *dev = chan->dev;
  71. unsigned long flags;
  72. u32 inst, i;
  73. if (!chan->ramin)
  74. return;
  75. inst = chan->ramin->vinst >> 12;
  76. inst |= 0x80000000;
  77. spin_lock_irqsave(&dev_priv->context_switch_lock, flags);
  78. nv_mask(dev, 0x00b32c, 0x00000001, 0x00000000);
  79. if (nv_rd32(dev, 0x00b318) == inst)
  80. nv_mask(dev, 0x00b318, 0x80000000, 0x00000000);
  81. nv_mask(dev, 0x00b32c, 0x00000001, 0x00000001);
  82. spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags);
  83. for (i = 0x00; i <= 0x14; i += 4)
  84. nv_wo32(chan->ramin, CTX_PTR(dev, i), 0x00000000);
  85. nouveau_gpuobj_ref(NULL, &ctx);
  86. chan->engctx[engine] = NULL;
  87. }
  88. static int
  89. nv50_mpeg_object_new(struct nouveau_channel *chan, int engine,
  90. u32 handle, u16 class)
  91. {
  92. struct drm_device *dev = chan->dev;
  93. struct drm_nouveau_private *dev_priv = dev->dev_private;
  94. struct nouveau_gpuobj *obj = NULL;
  95. int ret;
  96. ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
  97. if (ret)
  98. return ret;
  99. obj->engine = 2;
  100. obj->class = class;
  101. nv_wo32(obj, 0x00, class);
  102. nv_wo32(obj, 0x04, 0x00000000);
  103. nv_wo32(obj, 0x08, 0x00000000);
  104. nv_wo32(obj, 0x0c, 0x00000000);
  105. dev_priv->engine.instmem.flush(dev);
  106. ret = nouveau_ramht_insert(chan, handle, obj);
  107. nouveau_gpuobj_ref(NULL, &obj);
  108. return ret;
  109. }
  110. static void
  111. nv50_mpeg_tlb_flush(struct drm_device *dev, int engine)
  112. {
  113. nv50_vm_flush_engine(dev, 0x08);
  114. }
  115. static int
  116. nv50_mpeg_init(struct drm_device *dev, int engine)
  117. {
  118. nv_wr32(dev, 0x00b32c, 0x00000000);
  119. nv_wr32(dev, 0x00b314, 0x00000100);
  120. nv_wr32(dev, 0x00b0e0, 0x0000001a);
  121. nv_wr32(dev, 0x00b220, 0x00000044);
  122. nv_wr32(dev, 0x00b300, 0x00801ec1);
  123. nv_wr32(dev, 0x00b390, 0x00000000);
  124. nv_wr32(dev, 0x00b394, 0x00000000);
  125. nv_wr32(dev, 0x00b398, 0x00000000);
  126. nv_mask(dev, 0x00b32c, 0x00000001, 0x00000001);
  127. nv_wr32(dev, 0x00b100, 0xffffffff);
  128. nv_wr32(dev, 0x00b140, 0xffffffff);
  129. if (!nv_wait(dev, 0x00b200, 0x00000001, 0x00000000)) {
  130. NV_ERROR(dev, "PMPEG init: 0x%08x\n", nv_rd32(dev, 0x00b200));
  131. return -EBUSY;
  132. }
  133. return 0;
  134. }
  135. static int
  136. nv50_mpeg_fini(struct drm_device *dev, int engine, bool suspend)
  137. {
  138. /*XXX: context save for s/r */
  139. nv_mask(dev, 0x00b32c, 0x00000001, 0x00000000);
  140. nv_wr32(dev, 0x00b140, 0x00000000);
  141. return 0;
  142. }
  143. static void
  144. nv50_mpeg_isr(struct drm_device *dev)
  145. {
  146. u32 stat = nv_rd32(dev, 0x00b100);
  147. u32 type = nv_rd32(dev, 0x00b230);
  148. u32 mthd = nv_rd32(dev, 0x00b234);
  149. u32 data = nv_rd32(dev, 0x00b238);
  150. u32 show = stat;
  151. if (stat & 0x01000000) {
  152. /* happens on initial binding of the object */
  153. if (type == 0x00000020 && mthd == 0x0000) {
  154. nv_wr32(dev, 0x00b308, 0x00000100);
  155. show &= ~0x01000000;
  156. }
  157. }
  158. if (show && nouveau_ratelimit()) {
  159. NV_INFO(dev, "PMPEG - 0x%08x 0x%08x 0x%08x 0x%08x\n",
  160. stat, type, mthd, data);
  161. }
  162. nv_wr32(dev, 0x00b100, stat);
  163. nv_wr32(dev, 0x00b230, 0x00000001);
  164. nv50_fb_vm_trap(dev, 1);
  165. }
  166. static void
  167. nv50_vpe_isr(struct drm_device *dev)
  168. {
  169. if (nv_rd32(dev, 0x00b100))
  170. nv50_mpeg_isr(dev);
  171. if (nv_rd32(dev, 0x00b800)) {
  172. u32 stat = nv_rd32(dev, 0x00b800);
  173. NV_INFO(dev, "PMSRCH: 0x%08x\n", stat);
  174. nv_wr32(dev, 0xb800, stat);
  175. }
  176. }
  177. static void
  178. nv50_mpeg_destroy(struct drm_device *dev, int engine)
  179. {
  180. struct nv50_mpeg_engine *pmpeg = nv_engine(dev, engine);
  181. nouveau_irq_unregister(dev, 0);
  182. NVOBJ_ENGINE_DEL(dev, MPEG);
  183. kfree(pmpeg);
  184. }
  185. int
  186. nv50_mpeg_create(struct drm_device *dev)
  187. {
  188. struct drm_nouveau_private *dev_priv = dev->dev_private;
  189. struct nv50_mpeg_engine *pmpeg;
  190. pmpeg = kzalloc(sizeof(*pmpeg), GFP_KERNEL);
  191. if (!pmpeg)
  192. return -ENOMEM;
  193. pmpeg->base.destroy = nv50_mpeg_destroy;
  194. pmpeg->base.init = nv50_mpeg_init;
  195. pmpeg->base.fini = nv50_mpeg_fini;
  196. pmpeg->base.context_new = nv50_mpeg_context_new;
  197. pmpeg->base.context_del = nv50_mpeg_context_del;
  198. pmpeg->base.object_new = nv50_mpeg_object_new;
  199. pmpeg->base.tlb_flush = nv50_mpeg_tlb_flush;
  200. if (dev_priv->chipset == 0x50) {
  201. nouveau_irq_register(dev, 0, nv50_vpe_isr);
  202. NVOBJ_ENGINE_ADD(dev, MPEG, &pmpeg->base);
  203. NVOBJ_CLASS(dev, 0x3174, MPEG);
  204. #if 0
  205. NVOBJ_ENGINE_ADD(dev, ME, &pme->base);
  206. NVOBJ_CLASS(dev, 0x4075, ME);
  207. #endif
  208. } else {
  209. nouveau_irq_register(dev, 0, nv50_mpeg_isr);
  210. NVOBJ_ENGINE_ADD(dev, MPEG, &pmpeg->base);
  211. NVOBJ_CLASS(dev, 0x8274, MPEG);
  212. }
  213. return 0;
  214. }