1 // SPDX-License-Identifier: MIT
2 #include <drm/drm_crtc.h>
10 #include <nvif/pushc37b.h>
12 #include <nvhw/class/clc37d.h>
15 crcc37d_set_src(struct nv50_head *head, int or, enum nv50_crc_source_type source,
16 struct nv50_crc_notifier_ctx *ctx)
18 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
19 const int i = head->base.index;
20 u32 crc_args = NVVAL(NVC37D, HEAD_SET_CRC_CONTROL, CONTROLLING_CHANNEL, i * 4) |
21 NVDEF(NVC37D, HEAD_SET_CRC_CONTROL, EXPECT_BUFFER_COLLAPSE, FALSE) |
22 NVDEF(NVC37D, HEAD_SET_CRC_CONTROL, SECONDARY_CRC, NONE) |
23 NVDEF(NVC37D, HEAD_SET_CRC_CONTROL, CRC_DURING_SNOOZE, DISABLE);
27 case NV50_CRC_SOURCE_TYPE_SOR:
28 crc_args |= NVDEF(NVC37D, HEAD_SET_CRC_CONTROL, PRIMARY_CRC, SOR(or));
30 case NV50_CRC_SOURCE_TYPE_PIOR:
31 crc_args |= NVDEF(NVC37D, HEAD_SET_CRC_CONTROL, PRIMARY_CRC, PIOR(or));
33 case NV50_CRC_SOURCE_TYPE_SF:
34 crc_args |= NVDEF(NVC37D, HEAD_SET_CRC_CONTROL, PRIMARY_CRC, SF);
40 if ((ret = PUSH_WAIT(push, 4)))
44 PUSH_MTHD(push, NVC37D, HEAD_SET_CONTEXT_DMA_CRC(i), ctx->ntfy.handle);
45 PUSH_MTHD(push, NVC37D, HEAD_SET_CRC_CONTROL(i), crc_args);
47 PUSH_MTHD(push, NVC37D, HEAD_SET_CRC_CONTROL(i), 0);
48 PUSH_MTHD(push, NVC37D, HEAD_SET_CONTEXT_DMA_CRC(i), 0);
54 int crcc37d_set_ctx(struct nv50_head *head, struct nv50_crc_notifier_ctx *ctx)
56 struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
57 const int i = head->base.index;
60 if ((ret = PUSH_WAIT(push, 2)))
63 PUSH_MTHD(push, NVC37D, HEAD_SET_CONTEXT_DMA_CRC(i), ctx ? ctx->ntfy.handle : 0);
67 u32 crcc37d_get_entry(struct nv50_head *head, struct nv50_crc_notifier_ctx *ctx,
68 enum nv50_crc_source source, int idx)
70 struct crcc37d_notifier __iomem *notifier = ctx->mem.object.map.ptr;
71 struct crcc37d_entry __iomem *entry = ¬ifier->entries[idx];
72 u32 __iomem *crc_addr;
74 if (source == NV50_CRC_SOURCE_RG)
75 crc_addr = &entry->rg_crc;
77 crc_addr = &entry->output_crc[0];
79 return ioread32_native(crc_addr);
82 bool crcc37d_ctx_finished(struct nv50_head *head, struct nv50_crc_notifier_ctx *ctx)
84 struct nouveau_drm *drm = nouveau_drm(head->base.base.dev);
85 struct crcc37d_notifier __iomem *notifier = ctx->mem.object.map.ptr;
86 const u32 status = ioread32_native(¬ifier->status);
87 const u32 overflow = status & 0x0000007e;
89 if (!(status & 0x00000001))
93 const char *engine = NULL;
96 case 0x00000004: engine = "Front End"; break;
97 case 0x00000008: engine = "Compositor"; break;
98 case 0x00000010: engine = "RG"; break;
99 case 0x00000020: engine = "CRC output 1"; break;
100 case 0x00000040: engine = "CRC output 2"; break;
105 "CRC notifier context for head %d overflowed on %s: %x\n",
106 head->base.index, engine, status);
109 "CRC notifier context for head %d overflowed: %x\n",
110 head->base.index, status);
113 NV_DEBUG(drm, "Head %d CRC context status: %x\n",
114 head->base.index, status);
119 const struct nv50_crc_func crcc37d = {
120 .set_src = crcc37d_set_src,
121 .set_ctx = crcc37d_set_ctx,
122 .get_entry = crcc37d_get_entry,
123 .ctx_finished = crcc37d_ctx_finished,
124 .flip_threshold = CRCC37D_FLIP_THRESHOLD,
125 .num_entries = CRCC37D_MAX_ENTRIES,
126 .notifier_len = sizeof(struct crcc37d_notifier),