g84.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. /*
  2. * Copyright 2012 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 <engine/cipher.h>
  25. #include <engine/fifo.h>
  26. #include <core/client.h>
  27. #include <core/enum.h>
  28. #include <core/gpuobj.h>
  29. #include <nvif/class.h>
  30. static int
  31. g84_cipher_oclass_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
  32. int align, struct nvkm_gpuobj **pgpuobj)
  33. {
  34. int ret = nvkm_gpuobj_new(object->engine->subdev.device, 16,
  35. align, false, parent, pgpuobj);
  36. if (ret == 0) {
  37. nvkm_kmap(*pgpuobj);
  38. nvkm_wo32(*pgpuobj, 0x00, object->oclass);
  39. nvkm_wo32(*pgpuobj, 0x04, 0x00000000);
  40. nvkm_wo32(*pgpuobj, 0x08, 0x00000000);
  41. nvkm_wo32(*pgpuobj, 0x0c, 0x00000000);
  42. nvkm_done(*pgpuobj);
  43. }
  44. return ret;
  45. }
  46. static const struct nvkm_object_func
  47. g84_cipher_oclass_func = {
  48. .bind = g84_cipher_oclass_bind,
  49. };
  50. static int
  51. g84_cipher_cclass_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
  52. int align, struct nvkm_gpuobj **pgpuobj)
  53. {
  54. return nvkm_gpuobj_new(object->engine->subdev.device, 256,
  55. align, true, parent, pgpuobj);
  56. }
  57. static const struct nvkm_object_func
  58. g84_cipher_cclass = {
  59. .bind = g84_cipher_cclass_bind,
  60. };
  61. static const struct nvkm_bitfield
  62. g84_cipher_intr_mask[] = {
  63. { 0x00000001, "INVALID_STATE" },
  64. { 0x00000002, "ILLEGAL_MTHD" },
  65. { 0x00000004, "ILLEGAL_CLASS" },
  66. { 0x00000080, "QUERY" },
  67. { 0x00000100, "FAULT" },
  68. {}
  69. };
  70. static void
  71. g84_cipher_intr(struct nvkm_engine *cipher)
  72. {
  73. struct nvkm_subdev *subdev = &cipher->subdev;
  74. struct nvkm_device *device = subdev->device;
  75. struct nvkm_fifo *fifo = device->fifo;
  76. struct nvkm_fifo_chan *chan;
  77. u32 stat = nvkm_rd32(device, 0x102130);
  78. u32 mthd = nvkm_rd32(device, 0x102190);
  79. u32 data = nvkm_rd32(device, 0x102194);
  80. u32 inst = nvkm_rd32(device, 0x102188) & 0x7fffffff;
  81. unsigned long flags;
  82. char msg[128];
  83. chan = nvkm_fifo_chan_inst(fifo, (u64)inst << 12, &flags);
  84. if (stat) {
  85. nvkm_snprintbf(msg, sizeof(msg), g84_cipher_intr_mask, stat);
  86. nvkm_error(subdev, "%08x [%s] ch %d [%010llx %s] "
  87. "mthd %04x data %08x\n", stat, msg,
  88. chan ? chan->chid : -1, (u64)inst << 12,
  89. chan ? chan->object.client->name : "unknown",
  90. mthd, data);
  91. }
  92. nvkm_fifo_chan_put(fifo, flags, &chan);
  93. nvkm_wr32(device, 0x102130, stat);
  94. nvkm_wr32(device, 0x10200c, 0x10);
  95. }
  96. static int
  97. g84_cipher_init(struct nvkm_engine *cipher)
  98. {
  99. struct nvkm_device *device = cipher->subdev.device;
  100. nvkm_wr32(device, 0x102130, 0xffffffff);
  101. nvkm_wr32(device, 0x102140, 0xffffffbf);
  102. nvkm_wr32(device, 0x10200c, 0x00000010);
  103. return 0;
  104. }
  105. static const struct nvkm_engine_func
  106. g84_cipher = {
  107. .init = g84_cipher_init,
  108. .intr = g84_cipher_intr,
  109. .cclass = &g84_cipher_cclass,
  110. .sclass = {
  111. { -1, -1, NV74_CIPHER, &g84_cipher_oclass_func },
  112. {}
  113. }
  114. };
  115. int
  116. g84_cipher_new(struct nvkm_device *device, int index,
  117. struct nvkm_engine **pengine)
  118. {
  119. return nvkm_engine_new_(&g84_cipher, device, index, true, pengine);
  120. }