nv50_mpeg.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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 nouveau_gpuobj *ctx = chan->engctx[engine];
  69. struct drm_device *dev = chan->dev;
  70. int i;
  71. for (i = 0x00; i <= 0x14; i += 4)
  72. nv_wo32(chan->ramin, CTX_PTR(dev, i), 0x00000000);
  73. nouveau_gpuobj_ref(NULL, &ctx);
  74. chan->engctx[engine] = NULL;
  75. }
  76. static int
  77. nv50_mpeg_object_new(struct nouveau_channel *chan, int engine,
  78. u32 handle, u16 class)
  79. {
  80. struct drm_device *dev = chan->dev;
  81. struct drm_nouveau_private *dev_priv = dev->dev_private;
  82. struct nouveau_gpuobj *obj = NULL;
  83. int ret;
  84. ret = nouveau_gpuobj_new(dev, chan, 16, 16, NVOBJ_FLAG_ZERO_FREE, &obj);
  85. if (ret)
  86. return ret;
  87. obj->engine = 2;
  88. obj->class = class;
  89. nv_wo32(obj, 0x00, class);
  90. nv_wo32(obj, 0x04, 0x00000000);
  91. nv_wo32(obj, 0x08, 0x00000000);
  92. nv_wo32(obj, 0x0c, 0x00000000);
  93. dev_priv->engine.instmem.flush(dev);
  94. ret = nouveau_ramht_insert(chan, handle, obj);
  95. nouveau_gpuobj_ref(NULL, &obj);
  96. return ret;
  97. }
  98. static void
  99. nv50_mpeg_tlb_flush(struct drm_device *dev, int engine)
  100. {
  101. nv50_vm_flush_engine(dev, 0x08);
  102. }
  103. static int
  104. nv50_mpeg_init(struct drm_device *dev, int engine)
  105. {
  106. nv_wr32(dev, 0x00b32c, 0x00000000);
  107. nv_wr32(dev, 0x00b314, 0x00000100);
  108. nv_wr32(dev, 0x00b0e0, 0x0000001a);
  109. nv_wr32(dev, 0x00b220, 0x00000044);
  110. nv_wr32(dev, 0x00b300, 0x00801ec1);
  111. nv_wr32(dev, 0x00b390, 0x00000000);
  112. nv_wr32(dev, 0x00b394, 0x00000000);
  113. nv_wr32(dev, 0x00b398, 0x00000000);
  114. nv_mask(dev, 0x00b32c, 0x00000001, 0x00000001);
  115. nv_wr32(dev, 0x00b100, 0xffffffff);
  116. nv_wr32(dev, 0x00b140, 0xffffffff);
  117. if (!nv_wait(dev, 0x00b200, 0x00000001, 0x00000000)) {
  118. NV_ERROR(dev, "PMPEG init: 0x%08x\n", nv_rd32(dev, 0x00b200));
  119. return -EBUSY;
  120. }
  121. return 0;
  122. }
  123. static int
  124. nv50_mpeg_fini(struct drm_device *dev, int engine, bool suspend)
  125. {
  126. nv_mask(dev, 0x00b32c, 0x00000001, 0x00000000);
  127. nv_wr32(dev, 0x00b140, 0x00000000);
  128. return 0;
  129. }
  130. static void
  131. nv50_mpeg_isr(struct drm_device *dev)
  132. {
  133. u32 stat = nv_rd32(dev, 0x00b100);
  134. u32 type = nv_rd32(dev, 0x00b230);
  135. u32 mthd = nv_rd32(dev, 0x00b234);
  136. u32 data = nv_rd32(dev, 0x00b238);
  137. u32 show = stat;
  138. if (stat & 0x01000000) {
  139. /* happens on initial binding of the object */
  140. if (type == 0x00000020 && mthd == 0x0000) {
  141. nv_wr32(dev, 0x00b308, 0x00000100);
  142. show &= ~0x01000000;
  143. }
  144. }
  145. if (show && nouveau_ratelimit()) {
  146. NV_INFO(dev, "PMPEG - 0x%08x 0x%08x 0x%08x 0x%08x\n",
  147. stat, type, mthd, data);
  148. }
  149. nv_wr32(dev, 0x00b100, stat);
  150. nv_wr32(dev, 0x00b230, 0x00000001);
  151. nv50_fb_vm_trap(dev, 1);
  152. }
  153. static void
  154. nv50_vpe_isr(struct drm_device *dev)
  155. {
  156. if (nv_rd32(dev, 0x00b100))
  157. nv50_mpeg_isr(dev);
  158. if (nv_rd32(dev, 0x00b800)) {
  159. u32 stat = nv_rd32(dev, 0x00b800);
  160. NV_INFO(dev, "PMSRCH: 0x%08x\n", stat);
  161. nv_wr32(dev, 0xb800, stat);
  162. }
  163. }
  164. static void
  165. nv50_mpeg_destroy(struct drm_device *dev, int engine)
  166. {
  167. struct nv50_mpeg_engine *pmpeg = nv_engine(dev, engine);
  168. nouveau_irq_unregister(dev, 0);
  169. NVOBJ_ENGINE_DEL(dev, MPEG);
  170. kfree(pmpeg);
  171. }
  172. int
  173. nv50_mpeg_create(struct drm_device *dev)
  174. {
  175. struct drm_nouveau_private *dev_priv = dev->dev_private;
  176. struct nv50_mpeg_engine *pmpeg;
  177. pmpeg = kzalloc(sizeof(*pmpeg), GFP_KERNEL);
  178. if (!pmpeg)
  179. return -ENOMEM;
  180. pmpeg->base.destroy = nv50_mpeg_destroy;
  181. pmpeg->base.init = nv50_mpeg_init;
  182. pmpeg->base.fini = nv50_mpeg_fini;
  183. pmpeg->base.context_new = nv50_mpeg_context_new;
  184. pmpeg->base.context_del = nv50_mpeg_context_del;
  185. pmpeg->base.object_new = nv50_mpeg_object_new;
  186. pmpeg->base.tlb_flush = nv50_mpeg_tlb_flush;
  187. if (dev_priv->chipset == 0x50) {
  188. nouveau_irq_register(dev, 0, nv50_vpe_isr);
  189. NVOBJ_ENGINE_ADD(dev, MPEG, &pmpeg->base);
  190. NVOBJ_CLASS(dev, 0x3174, MPEG);
  191. #if 0
  192. NVOBJ_ENGINE_ADD(dev, ME, &pme->base);
  193. NVOBJ_CLASS(dev, 0x4075, ME);
  194. #endif
  195. } else {
  196. nouveau_irq_register(dev, 0, nv50_mpeg_isr);
  197. NVOBJ_ENGINE_ADD(dev, MPEG, &pmpeg->base);
  198. NVOBJ_CLASS(dev, 0x8274, MPEG);
  199. }
  200. return 0;
  201. }