gk104.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright 2016 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 <bskeggs@redhat.com>
  23. */
  24. #include "priv.h"
  25. static int
  26. gk104_top_oneinit(struct nvkm_top *top)
  27. {
  28. struct nvkm_subdev *subdev = &top->subdev;
  29. struct nvkm_device *device = subdev->device;
  30. struct nvkm_top_device *info = NULL;
  31. u32 data, type, inst;
  32. int i;
  33. for (i = 0; i < 64; i++) {
  34. if (!info) {
  35. if (!(info = nvkm_top_device_new(top)))
  36. return -ENOMEM;
  37. type = ~0;
  38. inst = 0;
  39. }
  40. data = nvkm_rd32(device, 0x022700 + (i * 0x04));
  41. nvkm_trace(subdev, "%02x: %08x\n", i, data);
  42. switch (data & 0x00000003) {
  43. case 0x00000000: /* NOT_VALID */
  44. continue;
  45. case 0x00000001: /* DATA */
  46. inst = (data & 0x3c000000) >> 26;
  47. info->addr = (data & 0x00fff000);
  48. info->fault = (data & 0x000000f8) >> 3;
  49. break;
  50. case 0x00000002: /* ENUM */
  51. if (data & 0x00000020)
  52. info->engine = (data & 0x3c000000) >> 26;
  53. if (data & 0x00000010)
  54. info->runlist = (data & 0x01e00000) >> 21;
  55. if (data & 0x00000008)
  56. info->intr = (data & 0x000f8000) >> 15;
  57. if (data & 0x00000004)
  58. info->reset = (data & 0x00003e00) >> 9;
  59. break;
  60. case 0x00000003: /* ENGINE_TYPE */
  61. type = (data & 0x7ffffffc) >> 2;
  62. break;
  63. }
  64. if (data & 0x80000000)
  65. continue;
  66. /* Translate engine type to NVKM engine identifier. */
  67. #define A_(A) if (inst == 0) info->index = NVKM_ENGINE_##A
  68. #define B_(A) if (inst + NVKM_ENGINE_##A##0 < NVKM_ENGINE_##A##_LAST + 1) \
  69. info->index = NVKM_ENGINE_##A##0 + inst
  70. switch (type) {
  71. case 0x00000000: A_(GR ); break;
  72. case 0x00000001: A_(CE0 ); break;
  73. case 0x00000002: A_(CE1 ); break;
  74. case 0x00000003: A_(CE2 ); break;
  75. case 0x00000008: A_(MSPDEC); break;
  76. case 0x00000009: A_(MSPPP ); break;
  77. case 0x0000000a: A_(MSVLD ); break;
  78. case 0x0000000b: A_(MSENC ); break;
  79. case 0x0000000c: A_(VIC ); break;
  80. case 0x0000000d: A_(SEC ); break;
  81. case 0x0000000e: B_(NVENC ); break;
  82. case 0x0000000f: A_(NVENC1); break;
  83. case 0x00000010: A_(NVDEC ); break;
  84. case 0x00000013: B_(CE ); break;
  85. break;
  86. default:
  87. break;
  88. }
  89. nvkm_debug(subdev, "%02x.%d (%8s): addr %06x fault %2d "
  90. "engine %2d runlist %2d intr %2d "
  91. "reset %2d\n", type, inst,
  92. info->index == NVKM_SUBDEV_NR ? NULL :
  93. nvkm_subdev_name[info->index],
  94. info->addr, info->fault, info->engine, info->runlist,
  95. info->intr, info->reset);
  96. info = NULL;
  97. }
  98. return 0;
  99. }
  100. static const struct nvkm_top_func
  101. gk104_top = {
  102. .oneinit = gk104_top_oneinit,
  103. };
  104. int
  105. gk104_top_new(struct nvkm_device *device, int index, struct nvkm_top **ptop)
  106. {
  107. return nvkm_top_new_(&gk104_top, device, index, ptop);
  108. }