nv98_crypt.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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_util.h"
  27. #include "nouveau_vm.h"
  28. #include "nouveau_ramht.h"
  29. #include "nv98_crypt.fuc.h"
  30. struct nv98_crypt_priv {
  31. struct nouveau_exec_engine base;
  32. };
  33. struct nv98_crypt_chan {
  34. struct nouveau_gpuobj *mem;
  35. };
  36. static int
  37. nv98_crypt_context_new(struct nouveau_channel *chan, int engine)
  38. {
  39. struct drm_device *dev = chan->dev;
  40. struct drm_nouveau_private *dev_priv = dev->dev_private;
  41. struct nv98_crypt_priv *priv = nv_engine(dev, engine);
  42. struct nv98_crypt_chan *cctx;
  43. int ret;
  44. cctx = chan->engctx[engine] = kzalloc(sizeof(*cctx), GFP_KERNEL);
  45. if (!cctx)
  46. return -ENOMEM;
  47. atomic_inc(&chan->vm->engref[engine]);
  48. ret = nouveau_gpuobj_new(dev, chan, 256, 0, NVOBJ_FLAG_ZERO_ALLOC |
  49. NVOBJ_FLAG_ZERO_FREE, &cctx->mem);
  50. if (ret)
  51. goto error;
  52. nv_wo32(chan->ramin, 0xa0, 0x00190000);
  53. nv_wo32(chan->ramin, 0xa4, cctx->mem->vinst + cctx->mem->size - 1);
  54. nv_wo32(chan->ramin, 0xa8, cctx->mem->vinst);
  55. nv_wo32(chan->ramin, 0xac, 0x00000000);
  56. nv_wo32(chan->ramin, 0xb0, 0x00000000);
  57. nv_wo32(chan->ramin, 0xb4, 0x00000000);
  58. dev_priv->engine.instmem.flush(dev);
  59. error:
  60. if (ret)
  61. priv->base.context_del(chan, engine);
  62. return ret;
  63. }
  64. static void
  65. nv98_crypt_context_del(struct nouveau_channel *chan, int engine)
  66. {
  67. struct nv98_crypt_chan *cctx = chan->engctx[engine];
  68. int i;
  69. for (i = 0xa0; i < 0xb4; i += 4)
  70. nv_wo32(chan->ramin, i, 0x00000000);
  71. nouveau_gpuobj_ref(NULL, &cctx->mem);
  72. atomic_dec(&chan->vm->engref[engine]);
  73. chan->engctx[engine] = NULL;
  74. kfree(cctx);
  75. }
  76. static int
  77. nv98_crypt_object_new(struct nouveau_channel *chan, int engine,
  78. u32 handle, u16 class)
  79. {
  80. struct nv98_crypt_chan *cctx = chan->engctx[engine];
  81. /* fuc engine doesn't need an object, our ramht code does.. */
  82. cctx->mem->engine = 5;
  83. cctx->mem->class = class;
  84. return nouveau_ramht_insert(chan, handle, cctx->mem);
  85. }
  86. static void
  87. nv98_crypt_tlb_flush(struct drm_device *dev, int engine)
  88. {
  89. nv50_vm_flush_engine(dev, 0x0a);
  90. }
  91. static int
  92. nv98_crypt_fini(struct drm_device *dev, int engine, bool suspend)
  93. {
  94. nv_mask(dev, 0x000200, 0x00004000, 0x00000000);
  95. return 0;
  96. }
  97. static int
  98. nv98_crypt_init(struct drm_device *dev, int engine)
  99. {
  100. int i;
  101. /* reset! */
  102. nv_mask(dev, 0x000200, 0x00004000, 0x00000000);
  103. nv_mask(dev, 0x000200, 0x00004000, 0x00004000);
  104. /* wait for exit interrupt to signal */
  105. nv_wait(dev, 0x087008, 0x00000010, 0x00000010);
  106. nv_wr32(dev, 0x087004, 0x00000010);
  107. /* upload microcode code and data segments */
  108. nv_wr32(dev, 0x087ff8, 0x00100000);
  109. for (i = 0; i < ARRAY_SIZE(nv98_pcrypt_code); i++)
  110. nv_wr32(dev, 0x087ff4, nv98_pcrypt_code[i]);
  111. nv_wr32(dev, 0x087ff8, 0x00000000);
  112. for (i = 0; i < ARRAY_SIZE(nv98_pcrypt_data); i++)
  113. nv_wr32(dev, 0x087ff4, nv98_pcrypt_data[i]);
  114. /* start it running */
  115. nv_wr32(dev, 0x08710c, 0x00000000);
  116. nv_wr32(dev, 0x087104, 0x00000000); /* ENTRY */
  117. nv_wr32(dev, 0x087100, 0x00000002); /* TRIGGER */
  118. return 0;
  119. }
  120. static struct nouveau_enum nv98_crypt_isr_error_name[] = {
  121. { 0x0000, "ILLEGAL_MTHD" },
  122. { 0x0001, "INVALID_BITFIELD" },
  123. { 0x0002, "INVALID_ENUM" },
  124. { 0x0003, "QUERY" },
  125. {}
  126. };
  127. static void
  128. nv98_crypt_isr(struct drm_device *dev)
  129. {
  130. u32 disp = nv_rd32(dev, 0x08701c);
  131. u32 stat = nv_rd32(dev, 0x087008) & disp & ~(disp >> 16);
  132. u32 inst = nv_rd32(dev, 0x087050) & 0x3fffffff;
  133. u32 ssta = nv_rd32(dev, 0x087040) & 0x0000ffff;
  134. u32 addr = nv_rd32(dev, 0x087040) >> 16;
  135. u32 mthd = (addr & 0x07ff) << 2;
  136. u32 subc = (addr & 0x3800) >> 11;
  137. u32 data = nv_rd32(dev, 0x087044);
  138. int chid = nv50_graph_isr_chid(dev, inst);
  139. if (stat & 0x00000040) {
  140. NV_INFO(dev, "PCRYPT: DISPATCH_ERROR [");
  141. nouveau_enum_print(nv98_crypt_isr_error_name, ssta);
  142. printk("] ch %d [0x%08x] subc %d mthd 0x%04x data 0x%08x\n",
  143. chid, inst, subc, mthd, data);
  144. nv_wr32(dev, 0x087004, 0x00000040);
  145. stat &= ~0x00000040;
  146. }
  147. if (stat) {
  148. NV_INFO(dev, "PCRYPT: unhandled intr 0x%08x\n", stat);
  149. nv_wr32(dev, 0x087004, stat);
  150. }
  151. nv50_fb_vm_trap(dev, 1);
  152. }
  153. static void
  154. nv98_crypt_destroy(struct drm_device *dev, int engine)
  155. {
  156. struct nv98_crypt_priv *priv = nv_engine(dev, engine);
  157. nouveau_irq_unregister(dev, 14);
  158. NVOBJ_ENGINE_DEL(dev, CRYPT);
  159. kfree(priv);
  160. }
  161. int
  162. nv98_crypt_create(struct drm_device *dev)
  163. {
  164. struct nv98_crypt_priv *priv;
  165. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  166. if (!priv)
  167. return -ENOMEM;
  168. priv->base.destroy = nv98_crypt_destroy;
  169. priv->base.init = nv98_crypt_init;
  170. priv->base.fini = nv98_crypt_fini;
  171. priv->base.context_new = nv98_crypt_context_new;
  172. priv->base.context_del = nv98_crypt_context_del;
  173. priv->base.object_new = nv98_crypt_object_new;
  174. priv->base.tlb_flush = nv98_crypt_tlb_flush;
  175. nouveau_irq_register(dev, 14, nv98_crypt_isr);
  176. NVOBJ_ENGINE_ADD(dev, CRYPT, &priv->base);
  177. NVOBJ_CLASS(dev, 0x88b4, CRYPT);
  178. return 0;
  179. }