nv84_crypt.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*
  2. * Copyright 2010 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. static void nv84_crypt_isr(struct drm_device *);
  29. int
  30. nv84_crypt_create_context(struct nouveau_channel *chan)
  31. {
  32. struct drm_device *dev = chan->dev;
  33. struct drm_nouveau_private *dev_priv = dev->dev_private;
  34. struct nouveau_gpuobj *ramin = chan->ramin;
  35. int ret;
  36. NV_DEBUG(dev, "ch%d\n", chan->id);
  37. ret = nouveau_gpuobj_new(dev, chan, 256, 0,
  38. NVOBJ_FLAG_ZERO_ALLOC | NVOBJ_FLAG_ZERO_FREE,
  39. &chan->crypt_ctx);
  40. if (ret)
  41. return ret;
  42. nv_wo32(ramin, 0xa0, 0x00190000);
  43. nv_wo32(ramin, 0xa4, chan->crypt_ctx->vinst + 0xff);
  44. nv_wo32(ramin, 0xa8, chan->crypt_ctx->vinst);
  45. nv_wo32(ramin, 0xac, 0);
  46. nv_wo32(ramin, 0xb0, 0);
  47. nv_wo32(ramin, 0xb4, 0);
  48. dev_priv->engine.instmem.flush(dev);
  49. atomic_inc(&chan->vm->pcrypt_refs);
  50. return 0;
  51. }
  52. void
  53. nv84_crypt_destroy_context(struct nouveau_channel *chan)
  54. {
  55. struct drm_device *dev = chan->dev;
  56. u32 inst;
  57. if (!chan->crypt_ctx)
  58. return;
  59. inst = (chan->ramin->vinst >> 12);
  60. inst |= 0x80000000;
  61. /* mark context as invalid if still on the hardware, not
  62. * doing this causes issues the next time PCRYPT is used,
  63. * unsurprisingly :)
  64. */
  65. nv_wr32(dev, 0x10200c, 0x00000000);
  66. if (nv_rd32(dev, 0x102188) == inst)
  67. nv_mask(dev, 0x102188, 0x80000000, 0x00000000);
  68. if (nv_rd32(dev, 0x10218c) == inst)
  69. nv_mask(dev, 0x10218c, 0x80000000, 0x00000000);
  70. nv_wr32(dev, 0x10200c, 0x00000010);
  71. nouveau_gpuobj_ref(NULL, &chan->crypt_ctx);
  72. atomic_dec(&chan->vm->pcrypt_refs);
  73. }
  74. void
  75. nv84_crypt_tlb_flush(struct drm_device *dev)
  76. {
  77. nv50_vm_flush_engine(dev, 0x0a);
  78. }
  79. int
  80. nv84_crypt_init(struct drm_device *dev)
  81. {
  82. struct drm_nouveau_private *dev_priv = dev->dev_private;
  83. struct nouveau_crypt_engine *pcrypt = &dev_priv->engine.crypt;
  84. if (!pcrypt->registered) {
  85. NVOBJ_CLASS(dev, 0x74c1, CRYPT);
  86. pcrypt->registered = true;
  87. }
  88. nv_mask(dev, 0x000200, 0x00004000, 0x00000000);
  89. nv_mask(dev, 0x000200, 0x00004000, 0x00004000);
  90. nouveau_irq_register(dev, 14, nv84_crypt_isr);
  91. nv_wr32(dev, 0x102130, 0xffffffff);
  92. nv_wr32(dev, 0x102140, 0xffffffbf);
  93. nv_wr32(dev, 0x10200c, 0x00000010);
  94. return 0;
  95. }
  96. void
  97. nv84_crypt_fini(struct drm_device *dev)
  98. {
  99. nv_wr32(dev, 0x102140, 0x00000000);
  100. nouveau_irq_unregister(dev, 14);
  101. }
  102. static void
  103. nv84_crypt_isr(struct drm_device *dev)
  104. {
  105. u32 stat = nv_rd32(dev, 0x102130);
  106. u32 mthd = nv_rd32(dev, 0x102190);
  107. u32 data = nv_rd32(dev, 0x102194);
  108. u32 inst = nv_rd32(dev, 0x102188) & 0x7fffffff;
  109. int show = nouveau_ratelimit();
  110. if (show) {
  111. NV_INFO(dev, "PCRYPT_INTR: 0x%08x 0x%08x 0x%08x 0x%08x\n",
  112. stat, mthd, data, inst);
  113. }
  114. nv_wr32(dev, 0x102130, stat);
  115. nv_wr32(dev, 0x10200c, 0x10);
  116. nv50_fb_vm_trap(dev, show, "PCRYPT");
  117. }