nva3_copy.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 <linux/firmware.h>
  25. #include "drmP.h"
  26. #include "nouveau_drv.h"
  27. #include "nouveau_util.h"
  28. #include "nouveau_vm.h"
  29. #include "nouveau_ramht.h"
  30. #include "nva3_copy.fuc.h"
  31. struct nva3_copy_engine {
  32. struct nouveau_exec_engine base;
  33. };
  34. static int
  35. nva3_copy_context_new(struct nouveau_channel *chan, int engine)
  36. {
  37. struct drm_device *dev = chan->dev;
  38. struct drm_nouveau_private *dev_priv = dev->dev_private;
  39. struct nouveau_gpuobj *ramin = chan->ramin;
  40. struct nouveau_gpuobj *ctx = NULL;
  41. int ret;
  42. NV_DEBUG(dev, "ch%d\n", chan->id);
  43. ret = nouveau_gpuobj_new(dev, chan, 256, 0, NVOBJ_FLAG_ZERO_ALLOC |
  44. NVOBJ_FLAG_ZERO_FREE, &ctx);
  45. if (ret)
  46. return ret;
  47. nv_wo32(ramin, 0xc0, 0x00190000);
  48. nv_wo32(ramin, 0xc4, ctx->vinst + ctx->size - 1);
  49. nv_wo32(ramin, 0xc8, ctx->vinst);
  50. nv_wo32(ramin, 0xcc, 0x00000000);
  51. nv_wo32(ramin, 0xd0, 0x00000000);
  52. nv_wo32(ramin, 0xd4, 0x00000000);
  53. dev_priv->engine.instmem.flush(dev);
  54. atomic_inc(&chan->vm->engref[engine]);
  55. chan->engctx[engine] = ctx;
  56. return 0;
  57. }
  58. static int
  59. nva3_copy_object_new(struct nouveau_channel *chan, int engine,
  60. u32 handle, u16 class)
  61. {
  62. struct nouveau_gpuobj *ctx = chan->engctx[engine];
  63. /* fuc engine doesn't need an object, our ramht code does.. */
  64. ctx->engine = 3;
  65. ctx->class = class;
  66. return nouveau_ramht_insert(chan, handle, ctx);
  67. }
  68. static void
  69. nva3_copy_context_del(struct nouveau_channel *chan, int engine)
  70. {
  71. struct nouveau_gpuobj *ctx = chan->engctx[engine];
  72. int i;
  73. for (i = 0xc0; i <= 0xd4; i += 4)
  74. nv_wo32(chan->ramin, i, 0x00000000);
  75. atomic_dec(&chan->vm->engref[engine]);
  76. nouveau_gpuobj_ref(NULL, &ctx);
  77. chan->engctx[engine] = ctx;
  78. }
  79. static void
  80. nva3_copy_tlb_flush(struct drm_device *dev, int engine)
  81. {
  82. nv50_vm_flush_engine(dev, 0x0d);
  83. }
  84. static int
  85. nva3_copy_init(struct drm_device *dev, int engine)
  86. {
  87. int i;
  88. nv_mask(dev, 0x000200, 0x00002000, 0x00000000);
  89. nv_mask(dev, 0x000200, 0x00002000, 0x00002000);
  90. nv_wr32(dev, 0x104014, 0xffffffff); /* disable all interrupts */
  91. /* upload ucode */
  92. nv_wr32(dev, 0x1041c0, 0x01000000);
  93. for (i = 0; i < sizeof(nva3_pcopy_data) / 4; i++)
  94. nv_wr32(dev, 0x1041c4, nva3_pcopy_data[i]);
  95. nv_wr32(dev, 0x104180, 0x01000000);
  96. for (i = 0; i < sizeof(nva3_pcopy_code) / 4; i++) {
  97. if ((i & 0x3f) == 0)
  98. nv_wr32(dev, 0x104188, i >> 6);
  99. nv_wr32(dev, 0x104184, nva3_pcopy_code[i]);
  100. }
  101. /* start it running */
  102. nv_wr32(dev, 0x10410c, 0x00000000);
  103. nv_wr32(dev, 0x104104, 0x00000000); /* ENTRY */
  104. nv_wr32(dev, 0x104100, 0x00000002); /* TRIGGER */
  105. return 0;
  106. }
  107. static int
  108. nva3_copy_fini(struct drm_device *dev, int engine, bool suspend)
  109. {
  110. nv_mask(dev, 0x104048, 0x00000003, 0x00000000);
  111. nv_wr32(dev, 0x104014, 0xffffffff);
  112. return 0;
  113. }
  114. static struct nouveau_enum nva3_copy_isr_error_name[] = {
  115. { 0x0001, "ILLEGAL_MTHD" },
  116. { 0x0002, "INVALID_ENUM" },
  117. { 0x0003, "INVALID_BITFIELD" },
  118. {}
  119. };
  120. static void
  121. nva3_copy_isr(struct drm_device *dev)
  122. {
  123. u32 dispatch = nv_rd32(dev, 0x10401c);
  124. u32 stat = nv_rd32(dev, 0x104008) & dispatch & ~(dispatch >> 16);
  125. u32 inst = nv_rd32(dev, 0x104050) & 0x3fffffff;
  126. u32 ssta = nv_rd32(dev, 0x104040) & 0x0000ffff;
  127. u32 addr = nv_rd32(dev, 0x104040) >> 16;
  128. u32 mthd = (addr & 0x07ff) << 2;
  129. u32 subc = (addr & 0x3800) >> 11;
  130. u32 data = nv_rd32(dev, 0x104044);
  131. int chid = nv50_graph_isr_chid(dev, inst);
  132. if (stat & 0x00000040) {
  133. NV_INFO(dev, "PCOPY: DISPATCH_ERROR [");
  134. nouveau_enum_print(nva3_copy_isr_error_name, ssta);
  135. printk("] ch %d [0x%08x] subc %d mthd 0x%04x data 0x%08x\n",
  136. chid, inst, subc, mthd, data);
  137. nv_wr32(dev, 0x104004, 0x00000040);
  138. stat &= ~0x00000040;
  139. }
  140. if (stat) {
  141. NV_INFO(dev, "PCOPY: unhandled intr 0x%08x\n", stat);
  142. nv_wr32(dev, 0x104004, stat);
  143. }
  144. nv50_fb_vm_trap(dev, 1);
  145. }
  146. static void
  147. nva3_copy_destroy(struct drm_device *dev, int engine)
  148. {
  149. struct nva3_copy_engine *pcopy = nv_engine(dev, engine);
  150. nouveau_irq_unregister(dev, 22);
  151. NVOBJ_ENGINE_DEL(dev, COPY0);
  152. kfree(pcopy);
  153. }
  154. int
  155. nva3_copy_create(struct drm_device *dev)
  156. {
  157. struct nva3_copy_engine *pcopy;
  158. pcopy = kzalloc(sizeof(*pcopy), GFP_KERNEL);
  159. if (!pcopy)
  160. return -ENOMEM;
  161. pcopy->base.destroy = nva3_copy_destroy;
  162. pcopy->base.init = nva3_copy_init;
  163. pcopy->base.fini = nva3_copy_fini;
  164. pcopy->base.context_new = nva3_copy_context_new;
  165. pcopy->base.context_del = nva3_copy_context_del;
  166. pcopy->base.object_new = nva3_copy_object_new;
  167. pcopy->base.tlb_flush = nva3_copy_tlb_flush;
  168. nouveau_irq_register(dev, 22, nva3_copy_isr);
  169. NVOBJ_ENGINE_ADD(dev, COPY0, &pcopy->base);
  170. NVOBJ_CLASS(dev, 0x85b5, COPY0);
  171. return 0;
  172. }