nv84_crypt.c 3.7 KB

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