nva3_copy.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. struct drm_device *dev = chan->dev;
  73. u32 inst;
  74. inst = (chan->ramin->vinst >> 12);
  75. inst |= 0x40000000;
  76. /* disable fifo access */
  77. nv_wr32(dev, 0x104048, 0x00000000);
  78. /* mark channel as unloaded if it's currently active */
  79. if (nv_rd32(dev, 0x104050) == inst)
  80. nv_mask(dev, 0x104050, 0x40000000, 0x00000000);
  81. /* mark next channel as invalid if it's about to be loaded */
  82. if (nv_rd32(dev, 0x104054) == inst)
  83. nv_mask(dev, 0x104054, 0x40000000, 0x00000000);
  84. /* restore fifo access */
  85. nv_wr32(dev, 0x104048, 0x00000003);
  86. for (inst = 0xc0; inst <= 0xd4; inst += 4)
  87. nv_wo32(chan->ramin, inst, 0x00000000);
  88. nouveau_gpuobj_ref(NULL, &ctx);
  89. atomic_dec(&chan->vm->engref[engine]);
  90. chan->engctx[engine] = ctx;
  91. }
  92. static void
  93. nva3_copy_tlb_flush(struct drm_device *dev, int engine)
  94. {
  95. nv50_vm_flush_engine(dev, 0x0d);
  96. }
  97. static int
  98. nva3_copy_init(struct drm_device *dev, int engine)
  99. {
  100. int i;
  101. nv_mask(dev, 0x000200, 0x00002000, 0x00000000);
  102. nv_mask(dev, 0x000200, 0x00002000, 0x00002000);
  103. nv_wr32(dev, 0x104014, 0xffffffff); /* disable all interrupts */
  104. /* upload ucode */
  105. nv_wr32(dev, 0x1041c0, 0x01000000);
  106. for (i = 0; i < sizeof(nva3_pcopy_data) / 4; i++)
  107. nv_wr32(dev, 0x1041c4, nva3_pcopy_data[i]);
  108. nv_wr32(dev, 0x104180, 0x01000000);
  109. for (i = 0; i < sizeof(nva3_pcopy_code) / 4; i++) {
  110. if ((i & 0x3f) == 0)
  111. nv_wr32(dev, 0x104188, i >> 6);
  112. nv_wr32(dev, 0x104184, nva3_pcopy_code[i]);
  113. }
  114. /* start it running */
  115. nv_wr32(dev, 0x10410c, 0x00000000);
  116. nv_wr32(dev, 0x104104, 0x00000000); /* ENTRY */
  117. nv_wr32(dev, 0x104100, 0x00000002); /* TRIGGER */
  118. return 0;
  119. }
  120. static int
  121. nva3_copy_fini(struct drm_device *dev, int engine, bool suspend)
  122. {
  123. nv_mask(dev, 0x104048, 0x00000003, 0x00000000);
  124. /* trigger fuc context unload */
  125. nv_wait(dev, 0x104008, 0x0000000c, 0x00000000);
  126. nv_mask(dev, 0x104054, 0x40000000, 0x00000000);
  127. nv_wr32(dev, 0x104000, 0x00000008);
  128. nv_wait(dev, 0x104008, 0x00000008, 0x00000000);
  129. nv_wr32(dev, 0x104014, 0xffffffff);
  130. return 0;
  131. }
  132. static struct nouveau_enum nva3_copy_isr_error_name[] = {
  133. { 0x0001, "ILLEGAL_MTHD" },
  134. { 0x0002, "INVALID_ENUM" },
  135. { 0x0003, "INVALID_BITFIELD" },
  136. {}
  137. };
  138. static void
  139. nva3_copy_isr(struct drm_device *dev)
  140. {
  141. u32 dispatch = nv_rd32(dev, 0x10401c);
  142. u32 stat = nv_rd32(dev, 0x104008) & dispatch & ~(dispatch >> 16);
  143. u32 inst = nv_rd32(dev, 0x104050) & 0x3fffffff;
  144. u32 ssta = nv_rd32(dev, 0x104040) & 0x0000ffff;
  145. u32 addr = nv_rd32(dev, 0x104040) >> 16;
  146. u32 mthd = (addr & 0x07ff) << 2;
  147. u32 subc = (addr & 0x3800) >> 11;
  148. u32 data = nv_rd32(dev, 0x104044);
  149. int chid = nv50_graph_isr_chid(dev, inst);
  150. if (stat & 0x00000040) {
  151. NV_INFO(dev, "PCOPY: DISPATCH_ERROR [");
  152. nouveau_enum_print(nva3_copy_isr_error_name, ssta);
  153. printk("] ch %d [0x%08x] subc %d mthd 0x%04x data 0x%08x\n",
  154. chid, inst, subc, mthd, data);
  155. nv_wr32(dev, 0x104004, 0x00000040);
  156. stat &= ~0x00000040;
  157. }
  158. if (stat) {
  159. NV_INFO(dev, "PCOPY: unhandled intr 0x%08x\n", stat);
  160. nv_wr32(dev, 0x104004, stat);
  161. }
  162. nv50_fb_vm_trap(dev, 1);
  163. }
  164. static void
  165. nva3_copy_destroy(struct drm_device *dev, int engine)
  166. {
  167. struct nva3_copy_engine *pcopy = nv_engine(dev, engine);
  168. nouveau_irq_unregister(dev, 22);
  169. NVOBJ_ENGINE_DEL(dev, COPY0);
  170. kfree(pcopy);
  171. }
  172. int
  173. nva3_copy_create(struct drm_device *dev)
  174. {
  175. struct nva3_copy_engine *pcopy;
  176. pcopy = kzalloc(sizeof(*pcopy), GFP_KERNEL);
  177. if (!pcopy)
  178. return -ENOMEM;
  179. pcopy->base.destroy = nva3_copy_destroy;
  180. pcopy->base.init = nva3_copy_init;
  181. pcopy->base.fini = nva3_copy_fini;
  182. pcopy->base.context_new = nva3_copy_context_new;
  183. pcopy->base.context_del = nva3_copy_context_del;
  184. pcopy->base.object_new = nva3_copy_object_new;
  185. pcopy->base.tlb_flush = nva3_copy_tlb_flush;
  186. nouveau_irq_register(dev, 22, nva3_copy_isr);
  187. NVOBJ_ENGINE_ADD(dev, COPY0, &pcopy->base);
  188. NVOBJ_CLASS(dev, 0x85b5, COPY0);
  189. return 0;
  190. }