crc907d.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // SPDX-License-Identifier: MIT
  2. #include <drm/drm_crtc.h>
  3. #include "crc.h"
  4. #include "core.h"
  5. #include "disp.h"
  6. #include "head.h"
  7. #include <nvif/push507c.h>
  8. #include <nvhw/class/cl907d.h>
  9. #define CRC907D_MAX_ENTRIES 255
  10. struct crc907d_notifier {
  11. u32 status;
  12. u32 :32; /* reserved */
  13. struct crc907d_entry {
  14. u32 status;
  15. u32 compositor_crc;
  16. u32 output_crc[2];
  17. } entries[CRC907D_MAX_ENTRIES];
  18. } __packed;
  19. static int
  20. crc907d_set_src(struct nv50_head *head, int or, enum nv50_crc_source_type source,
  21. struct nv50_crc_notifier_ctx *ctx)
  22. {
  23. struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
  24. const int i = head->base.index;
  25. u32 crc_args = NVDEF(NV907D, HEAD_SET_CRC_CONTROL, CONTROLLING_CHANNEL, CORE) |
  26. NVDEF(NV907D, HEAD_SET_CRC_CONTROL, EXPECT_BUFFER_COLLAPSE, FALSE) |
  27. NVDEF(NV907D, HEAD_SET_CRC_CONTROL, TIMESTAMP_MODE, FALSE) |
  28. NVDEF(NV907D, HEAD_SET_CRC_CONTROL, SECONDARY_OUTPUT, NONE) |
  29. NVDEF(NV907D, HEAD_SET_CRC_CONTROL, CRC_DURING_SNOOZE, DISABLE) |
  30. NVDEF(NV907D, HEAD_SET_CRC_CONTROL, WIDE_PIPE_CRC, ENABLE);
  31. int ret;
  32. switch (source) {
  33. case NV50_CRC_SOURCE_TYPE_SOR:
  34. crc_args |= NVDEF(NV907D, HEAD_SET_CRC_CONTROL, PRIMARY_OUTPUT, SOR(or));
  35. break;
  36. case NV50_CRC_SOURCE_TYPE_PIOR:
  37. crc_args |= NVDEF(NV907D, HEAD_SET_CRC_CONTROL, PRIMARY_OUTPUT, PIOR(or));
  38. break;
  39. case NV50_CRC_SOURCE_TYPE_DAC:
  40. crc_args |= NVDEF(NV907D, HEAD_SET_CRC_CONTROL, PRIMARY_OUTPUT, DAC(or));
  41. break;
  42. case NV50_CRC_SOURCE_TYPE_RG:
  43. crc_args |= NVDEF(NV907D, HEAD_SET_CRC_CONTROL, PRIMARY_OUTPUT, RG(i));
  44. break;
  45. case NV50_CRC_SOURCE_TYPE_SF:
  46. crc_args |= NVDEF(NV907D, HEAD_SET_CRC_CONTROL, PRIMARY_OUTPUT, SF(i));
  47. break;
  48. case NV50_CRC_SOURCE_NONE:
  49. crc_args |= NVDEF(NV907D, HEAD_SET_CRC_CONTROL, PRIMARY_OUTPUT, NONE);
  50. break;
  51. }
  52. if ((ret = PUSH_WAIT(push, 4)))
  53. return ret;
  54. if (source) {
  55. PUSH_MTHD(push, NV907D, HEAD_SET_CONTEXT_DMA_CRC(i), ctx->ntfy.handle);
  56. PUSH_MTHD(push, NV907D, HEAD_SET_CRC_CONTROL(i), crc_args);
  57. } else {
  58. PUSH_MTHD(push, NV907D, HEAD_SET_CRC_CONTROL(i), crc_args);
  59. PUSH_MTHD(push, NV907D, HEAD_SET_CONTEXT_DMA_CRC(i), 0);
  60. }
  61. return 0;
  62. }
  63. static int
  64. crc907d_set_ctx(struct nv50_head *head, struct nv50_crc_notifier_ctx *ctx)
  65. {
  66. struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
  67. const int i = head->base.index;
  68. int ret;
  69. if ((ret = PUSH_WAIT(push, 2)))
  70. return ret;
  71. PUSH_MTHD(push, NV907D, HEAD_SET_CONTEXT_DMA_CRC(i), ctx ? ctx->ntfy.handle : 0);
  72. return 0;
  73. }
  74. static u32 crc907d_get_entry(struct nv50_head *head,
  75. struct nv50_crc_notifier_ctx *ctx,
  76. enum nv50_crc_source source, int idx)
  77. {
  78. struct crc907d_notifier __iomem *notifier = ctx->mem.object.map.ptr;
  79. return ioread32_native(&notifier->entries[idx].output_crc[0]);
  80. }
  81. static bool crc907d_ctx_finished(struct nv50_head *head,
  82. struct nv50_crc_notifier_ctx *ctx)
  83. {
  84. struct nouveau_drm *drm = nouveau_drm(head->base.base.dev);
  85. struct crc907d_notifier __iomem *notifier = ctx->mem.object.map.ptr;
  86. const u32 status = ioread32_native(&notifier->status);
  87. const u32 overflow = status & 0x0000003e;
  88. if (!(status & 0x00000001))
  89. return false;
  90. if (overflow) {
  91. const char *engine = NULL;
  92. switch (overflow) {
  93. case 0x00000004: engine = "DSI"; break;
  94. case 0x00000008: engine = "Compositor"; break;
  95. case 0x00000010: engine = "CRC output 1"; break;
  96. case 0x00000020: engine = "CRC output 2"; break;
  97. }
  98. if (engine)
  99. NV_ERROR(drm,
  100. "CRC notifier context for head %d overflowed on %s: %x\n",
  101. head->base.index, engine, status);
  102. else
  103. NV_ERROR(drm,
  104. "CRC notifier context for head %d overflowed: %x\n",
  105. head->base.index, status);
  106. }
  107. NV_DEBUG(drm, "Head %d CRC context status: %x\n",
  108. head->base.index, status);
  109. return true;
  110. }
  111. const struct nv50_crc_func crc907d = {
  112. .set_src = crc907d_set_src,
  113. .set_ctx = crc907d_set_ctx,
  114. .get_entry = crc907d_get_entry,
  115. .ctx_finished = crc907d_ctx_finished,
  116. .flip_threshold = CRC907D_MAX_ENTRIES - 10,
  117. .num_entries = CRC907D_MAX_ENTRIES,
  118. .notifier_len = sizeof(struct crc907d_notifier),
  119. };