Lines Matching +full:t +full:- +full:head
1 // SPDX-License-Identifier: MIT
18 #include "head.h"
27 [NV50_CRC_SOURCE_OUTP_ACTIVE] = "outp-active",
28 [NV50_CRC_SOURCE_OUTP_COMPLETE] = "outp-complete",
29 [NV50_CRC_SOURCE_OUTP_INACTIVE] = "outp-inactive",
53 struct nouveau_drm *drm = nouveau_drm(crtc->dev); in nv50_crc_verify_source()
58 return -EINVAL; in nv50_crc_verify_source()
72 nv50_crc_program_ctx(struct nv50_head *head, in nv50_crc_program_ctx() argument
75 struct nv50_disp *disp = nv50_disp(head->base.base.dev); in nv50_crc_program_ctx()
76 struct nv50_core *core = disp->core; in nv50_crc_program_ctx()
79 core->func->crc->set_ctx(head, ctx); in nv50_crc_program_ctx()
80 core->func->update(core, interlock, false); in nv50_crc_program_ctx()
87 struct nv50_head *head = container_of(crc, struct nv50_head, crc); in nv50_crc_ctx_flip_work() local
88 struct drm_crtc *crtc = &head->base.base; in nv50_crc_ctx_flip_work()
89 struct drm_device *dev = crtc->dev; in nv50_crc_ctx_flip_work()
93 u8 new_idx = crc->ctx_idx ^ 1; in nv50_crc_ctx_flip_work()
96 * We don't want to accidentally wait for longer then the vblank, so in nv50_crc_ctx_flip_work()
97 * try again for the next vblank if we don't grab the lock in nv50_crc_ctx_flip_work()
99 if (!mutex_trylock(&disp->mutex)) { in nv50_crc_ctx_flip_work()
100 drm_dbg_kms(dev, "Lock contended, delaying CRC ctx flip for %s\n", crtc->name); in nv50_crc_ctx_flip_work()
105 drm_dbg_kms(dev, "Flipping notifier ctx for %s (%d -> %d)\n", in nv50_crc_ctx_flip_work()
106 crtc->name, crc->ctx_idx, new_idx); in nv50_crc_ctx_flip_work()
108 nv50_crc_program_ctx(head, NULL); in nv50_crc_ctx_flip_work()
109 nv50_crc_program_ctx(head, &crc->ctx[new_idx]); in nv50_crc_ctx_flip_work()
110 mutex_unlock(&disp->mutex); in nv50_crc_ctx_flip_work()
116 crtc->name, end_vbl, start_vbl); in nv50_crc_ctx_flip_work()
118 spin_lock_irq(&crc->lock); in nv50_crc_ctx_flip_work()
119 crc->ctx_changed = true; in nv50_crc_ctx_flip_work()
120 spin_unlock_irq(&crc->lock); in nv50_crc_ctx_flip_work()
125 memset_io(ctx->mem.object.map.ptr, 0, ctx->mem.object.map.size); in nv50_crc_reset_ctx()
129 nv50_crc_get_entries(struct nv50_head *head, in nv50_crc_get_entries() argument
133 struct drm_crtc *crtc = &head->base.base; in nv50_crc_get_entries()
134 struct nv50_crc *crc = &head->crc; in nv50_crc_get_entries()
137 while (crc->entry_idx < func->num_entries) { in nv50_crc_get_entries()
141 * aren't written immediately. in nv50_crc_get_entries()
143 output_crc = func->get_entry(head, &crc->ctx[crc->ctx_idx], in nv50_crc_get_entries()
144 source, crc->entry_idx); in nv50_crc_get_entries()
148 drm_crtc_add_crc_entry(crtc, true, crc->frame, &output_crc); in nv50_crc_get_entries()
149 crc->frame++; in nv50_crc_get_entries()
150 crc->entry_idx++; in nv50_crc_get_entries()
154 void nv50_crc_handle_vblank(struct nv50_head *head) in nv50_crc_handle_vblank() argument
156 struct drm_crtc *crtc = &head->base.base; in nv50_crc_handle_vblank()
157 struct nv50_crc *crc = &head->crc; in nv50_crc_handle_vblank()
159 nv50_disp(head->base.base.dev)->core->func->crc; in nv50_crc_handle_vblank()
167 * We don't lose events if we aren't able to report CRCs until the in nv50_crc_handle_vblank()
168 * next vblank, so only report CRCs if the locks we need aren't in nv50_crc_handle_vblank()
171 if (!spin_trylock(&crc->lock)) in nv50_crc_handle_vblank()
174 if (!crc->src) in nv50_crc_handle_vblank()
177 ctx = &crc->ctx[crc->ctx_idx]; in nv50_crc_handle_vblank()
178 if (crc->ctx_changed && func->ctx_finished(head, ctx)) { in nv50_crc_handle_vblank()
179 nv50_crc_get_entries(head, func, crc->src); in nv50_crc_handle_vblank()
181 crc->ctx_idx ^= 1; in nv50_crc_handle_vblank()
182 crc->entry_idx = 0; in nv50_crc_handle_vblank()
183 crc->ctx_changed = false; in nv50_crc_handle_vblank()
195 * updates back-to-back without waiting, we'll just be in nv50_crc_handle_vblank()
198 drm_dbg_kms(head->base.base.dev, in nv50_crc_handle_vblank()
199 "Notifier ctx flip for head-%d finished, lost CRC for frame %llu\n", in nv50_crc_handle_vblank()
200 head->base.index, crc->frame); in nv50_crc_handle_vblank()
201 crc->frame++; in nv50_crc_handle_vblank()
207 nv50_crc_get_entries(head, func, crc->src); in nv50_crc_handle_vblank()
210 drm_vblank_work_schedule(&crc->flip_work, in nv50_crc_handle_vblank()
212 + crc->flip_threshold in nv50_crc_handle_vblank()
213 - crc->entry_idx, in nv50_crc_handle_vblank()
217 spin_unlock(&crc->lock); in nv50_crc_handle_vblank()
220 static void nv50_crc_wait_ctx_finished(struct nv50_head *head, in nv50_crc_wait_ctx_finished() argument
224 struct drm_device *dev = head->base.base.dev; in nv50_crc_wait_ctx_finished()
228 ret = nvif_msec(&drm->client.device, 50, in nv50_crc_wait_ctx_finished()
229 if (func->ctx_finished(head, ctx)) break;); in nv50_crc_wait_ctx_finished()
230 if (ret == -ETIMEDOUT) in nv50_crc_wait_ctx_finished()
232 "CRC notifier ctx for head %d not finished after 50ms\n", in nv50_crc_wait_ctx_finished()
233 head->base.index); in nv50_crc_wait_ctx_finished()
236 "CRC notifier ctx for head-%d finished after %lldns\n", in nv50_crc_wait_ctx_finished()
237 head->base.index, ret); in nv50_crc_wait_ctx_finished()
247 struct nv50_head *head = nv50_head(crtc); in nv50_crc_atomic_stop_reporting() local
249 struct nv50_crc *crc = &head->crc; in nv50_crc_atomic_stop_reporting()
251 if (!asyh->clr.crc) in nv50_crc_atomic_stop_reporting()
254 spin_lock_irq(&crc->lock); in nv50_crc_atomic_stop_reporting()
255 crc->src = NV50_CRC_SOURCE_NONE; in nv50_crc_atomic_stop_reporting()
256 spin_unlock_irq(&crc->lock); in nv50_crc_atomic_stop_reporting()
259 drm_vblank_work_cancel_sync(&crc->flip_work); in nv50_crc_atomic_stop_reporting()
261 NV_ATOMIC(nouveau_drm(crtc->dev), in nv50_crc_atomic_stop_reporting()
262 "CRC reporting on vblank for head-%d disabled\n", in nv50_crc_atomic_stop_reporting()
263 head->base.index); in nv50_crc_atomic_stop_reporting()
279 struct nv50_head *head = nv50_head(crtc); in nv50_crc_atomic_init_notifier_contexts() local
281 struct nv50_crc *crc = &head->crc; in nv50_crc_atomic_init_notifier_contexts()
284 if (!asyh->set.crc) in nv50_crc_atomic_init_notifier_contexts()
287 crc->entry_idx = 0; in nv50_crc_atomic_init_notifier_contexts()
288 crc->ctx_changed = false; in nv50_crc_atomic_init_notifier_contexts()
289 for (i = 0; i < ARRAY_SIZE(crc->ctx); i++) in nv50_crc_atomic_init_notifier_contexts()
290 nv50_crc_reset_ctx(&crc->ctx[i]); in nv50_crc_atomic_init_notifier_contexts()
297 nv50_disp(state->dev)->core->func->crc; in nv50_crc_atomic_release_notifier_contexts()
303 struct nv50_head *head = nv50_head(crtc); in nv50_crc_atomic_release_notifier_contexts() local
305 struct nv50_crc *crc = &head->crc; in nv50_crc_atomic_release_notifier_contexts()
306 struct nv50_crc_notifier_ctx *ctx = &crc->ctx[crc->ctx_idx]; in nv50_crc_atomic_release_notifier_contexts()
308 if (!asyh->clr.crc) in nv50_crc_atomic_release_notifier_contexts()
311 if (crc->ctx_changed) { in nv50_crc_atomic_release_notifier_contexts()
312 nv50_crc_wait_ctx_finished(head, func, ctx); in nv50_crc_atomic_release_notifier_contexts()
313 ctx = &crc->ctx[crc->ctx_idx ^ 1]; in nv50_crc_atomic_release_notifier_contexts()
315 nv50_crc_wait_ctx_finished(head, func, ctx); in nv50_crc_atomic_release_notifier_contexts()
326 struct nv50_head *head = nv50_head(crtc); in nv50_crc_atomic_start_reporting() local
328 struct nv50_crc *crc = &head->crc; in nv50_crc_atomic_start_reporting()
331 if (!asyh->set.crc) in nv50_crc_atomic_start_reporting()
336 spin_lock_irq(&crc->lock); in nv50_crc_atomic_start_reporting()
338 crc->frame = vbl_count; in nv50_crc_atomic_start_reporting()
339 crc->src = asyh->crc.src; in nv50_crc_atomic_start_reporting()
340 drm_vblank_work_schedule(&crc->flip_work, in nv50_crc_atomic_start_reporting()
341 vbl_count + crc->flip_threshold, in nv50_crc_atomic_start_reporting()
343 spin_unlock_irq(&crc->lock); in nv50_crc_atomic_start_reporting()
345 NV_ATOMIC(nouveau_drm(crtc->dev), in nv50_crc_atomic_start_reporting()
346 "CRC reporting on vblank for head-%d enabled\n", in nv50_crc_atomic_start_reporting()
347 head->base.index); in nv50_crc_atomic_start_reporting()
351 int nv50_crc_atomic_check_head(struct nv50_head *head, in nv50_crc_atomic_check_head() argument
355 struct nv50_atom *atom = nv50_atom(asyh->state.state); in nv50_crc_atomic_check_head()
356 bool changed = armh->crc.src != asyh->crc.src; in nv50_crc_atomic_check_head()
358 if (!armh->crc.src && !asyh->crc.src) { in nv50_crc_atomic_check_head()
359 asyh->set.crc = false; in nv50_crc_atomic_check_head()
360 asyh->clr.crc = false; in nv50_crc_atomic_check_head()
364 if (drm_atomic_crtc_needs_modeset(&asyh->state) || changed) { in nv50_crc_atomic_check_head()
365 asyh->clr.crc = armh->crc.src && armh->state.active; in nv50_crc_atomic_check_head()
366 asyh->set.crc = asyh->crc.src && asyh->state.active; in nv50_crc_atomic_check_head()
368 asyh->set.or |= armh->or.crc_raster != in nv50_crc_atomic_check_head()
369 asyh->or.crc_raster; in nv50_crc_atomic_check_head()
371 if (asyh->clr.crc && asyh->set.crc) in nv50_crc_atomic_check_head()
372 atom->flush_disable = true; in nv50_crc_atomic_check_head()
374 asyh->set.crc = false; in nv50_crc_atomic_check_head()
375 asyh->clr.crc = false; in nv50_crc_atomic_check_head()
387 if (atom->flush_disable) in nv50_crc_atomic_check_outp()
390 for_each_oldnew_crtc_in_state(&atom->state, crtc, old_crtc_state, in nv50_crc_atomic_check_outp()
406 encoder = &outp->base.base; in nv50_crc_atomic_check_outp()
408 if (!asyh->clr.crc) in nv50_crc_atomic_check_outp()
412 * Re-programming ORs can't be done in the same flush as in nv50_crc_atomic_check_outp()
415 list_for_each_entry(outp_atom, &atom->outp, head) { in nv50_crc_atomic_check_outp()
416 if (outp_atom->encoder == encoder) { in nv50_crc_atomic_check_outp()
417 if (outp_atom->set.mask) { in nv50_crc_atomic_check_outp()
418 atom->flush_disable = true; in nv50_crc_atomic_check_outp()
432 struct dcb_output *dcbe = outp->dcb; in nv50_crc_source_type()
440 if (dcbe->location != DCB_LOC_ON_CHIP) in nv50_crc_source_type()
443 switch (dcbe->type) { in nv50_crc_source_type()
450 void nv50_crc_atomic_set(struct nv50_head *head, in nv50_crc_atomic_set() argument
453 struct drm_crtc *crtc = &head->base.base; in nv50_crc_atomic_set()
454 struct drm_device *dev = crtc->dev; in nv50_crc_atomic_set()
455 struct nv50_crc *crc = &head->crc; in nv50_crc_atomic_set()
456 const struct nv50_crc_func *func = nv50_disp(dev)->core->func->crc; in nv50_crc_atomic_set()
468 func->set_src(head, outp->outp.or.id, nv50_crc_source_type(outp, asyh->crc.src), in nv50_crc_atomic_set()
469 &crc->ctx[crc->ctx_idx]); in nv50_crc_atomic_set()
472 void nv50_crc_atomic_clr(struct nv50_head *head) in nv50_crc_atomic_clr() argument
475 nv50_disp(head->base.base.dev)->core->func->crc; in nv50_crc_atomic_clr()
477 func->set_src(head, 0, NV50_CRC_SOURCE_TYPE_NONE, NULL); in nv50_crc_atomic_clr()
502 nv50_crc_ctx_init(struct nv50_head *head, struct nvif_mmu *mmu, in nv50_crc_ctx_init() argument
505 struct nv50_core *core = nv50_disp(head->base.base.dev)->core; in nv50_crc_ctx_init()
508 ret = nvif_mem_ctor_map(mmu, "kmsCrcNtfy", NVIF_MEM_VRAM, len, &ctx->mem); in nv50_crc_ctx_init()
512 ret = nvif_object_ctor(&core->chan.base.user, "kmsCrcNtfyCtxDma", in nv50_crc_ctx_init()
513 NV50_DISP_HANDLE_CRC_CTX(head, idx), in nv50_crc_ctx_init()
518 .start = ctx->mem.addr, in nv50_crc_ctx_init()
519 .limit = ctx->mem.addr in nv50_crc_ctx_init()
520 + ctx->mem.size - 1, in nv50_crc_ctx_init()
522 &ctx->ntfy); in nv50_crc_ctx_init()
529 nvif_mem_dtor(&ctx->mem); in nv50_crc_ctx_init()
536 nvif_object_dtor(&ctx->ntfy); in nv50_crc_ctx_fini()
537 nvif_mem_dtor(&ctx->mem); in nv50_crc_ctx_fini()
542 struct drm_device *dev = crtc->dev; in nv50_crc_set_source()
545 struct nv50_head *head = nv50_head(crtc); in nv50_crc_set_source() local
546 struct nv50_crc *crc = &head->crc; in nv50_crc_set_source()
547 const struct nv50_crc_func *func = nv50_disp(dev)->core->func->crc; in nv50_crc_set_source()
548 struct nvif_mmu *mmu = &nouveau_drm(dev)->client.mmu; in nv50_crc_set_source()
559 * Since we don't want the user to accidentally interrupt us as we're in nv50_crc_set_source()
568 ret = -ENOMEM; in nv50_crc_set_source()
571 state->acquire_ctx = &ctx; in nv50_crc_set_source()
574 for (i = 0; i < ARRAY_SIZE(head->crc.ctx); i++) { in nv50_crc_set_source()
575 ret = nv50_crc_ctx_init(head, mmu, &crc->ctx[i], in nv50_crc_set_source()
576 func->notifier_len, i); in nv50_crc_set_source()
583 crtc_state = drm_atomic_get_crtc_state(state, &head->base.base); in nv50_crc_set_source()
586 if (ret == -EDEADLK) in nv50_crc_set_source()
592 asyh->crc.src = source; in nv50_crc_set_source()
593 asyh->or.crc_raster = nv50_crc_raster_type(source); in nv50_crc_set_source()
596 if (ret == -EDEADLK) in nv50_crc_set_source()
606 crc->flip_threshold = func->flip_threshold; in nv50_crc_set_source()
613 for (i = 0; i < ARRAY_SIZE(crc->ctx); i++) in nv50_crc_set_source()
614 nv50_crc_ctx_fini(&crc->ctx[i]); in nv50_crc_set_source()
630 struct nv50_head *head = m->private; in nv50_crc_debugfs_flip_threshold_get() local
631 struct drm_crtc *crtc = &head->base.base; in nv50_crc_debugfs_flip_threshold_get()
632 struct nv50_crc *crc = &head->crc; in nv50_crc_debugfs_flip_threshold_get()
635 ret = drm_modeset_lock_single_interruptible(&crtc->mutex); in nv50_crc_debugfs_flip_threshold_get()
639 seq_printf(m, "%d\n", crc->flip_threshold); in nv50_crc_debugfs_flip_threshold_get()
641 drm_modeset_unlock(&crtc->mutex); in nv50_crc_debugfs_flip_threshold_get()
649 inode->i_private); in nv50_crc_debugfs_flip_threshold_open()
657 struct seq_file *m = file->private_data; in nv50_crc_debugfs_flip_threshold_set()
658 struct nv50_head *head = m->private; in nv50_crc_debugfs_flip_threshold_set() local
660 struct drm_crtc *crtc = &head->base.base; in nv50_crc_debugfs_flip_threshold_set()
661 struct nouveau_drm *drm = nouveau_drm(crtc->dev); in nv50_crc_debugfs_flip_threshold_set()
662 struct nv50_crc *crc = &head->crc; in nv50_crc_debugfs_flip_threshold_set()
664 nv50_disp(crtc->dev)->core->func->crc; in nv50_crc_debugfs_flip_threshold_set()
671 if (value > func->flip_threshold) in nv50_crc_debugfs_flip_threshold_set()
672 return -EINVAL; in nv50_crc_debugfs_flip_threshold_set()
673 else if (value == -1) in nv50_crc_debugfs_flip_threshold_set()
674 value = func->flip_threshold; in nv50_crc_debugfs_flip_threshold_set()
675 else if (value < -1) in nv50_crc_debugfs_flip_threshold_set()
676 return -EINVAL; in nv50_crc_debugfs_flip_threshold_set()
678 ret = drm_modeset_lock_single_interruptible(&crtc->mutex); in nv50_crc_debugfs_flip_threshold_set()
682 armh = nv50_head_atom(crtc->state); in nv50_crc_debugfs_flip_threshold_set()
683 if (armh->crc.src) { in nv50_crc_debugfs_flip_threshold_set()
684 ret = -EBUSY; in nv50_crc_debugfs_flip_threshold_set()
689 "Changing CRC flip threshold for next capture on head-%d to %d\n", in nv50_crc_debugfs_flip_threshold_set()
690 head->base.index, value); in nv50_crc_debugfs_flip_threshold_set()
691 crc->flip_threshold = value; in nv50_crc_debugfs_flip_threshold_set()
695 drm_modeset_unlock(&crtc->mutex); in nv50_crc_debugfs_flip_threshold_set()
707 int nv50_head_crc_late_register(struct nv50_head *head) in nv50_head_crc_late_register() argument
709 struct drm_crtc *crtc = &head->base.base; in nv50_head_crc_late_register()
711 nv50_disp(crtc->dev)->core->func->crc; in nv50_head_crc_late_register()
714 if (!func || !crtc->debugfs_entry) in nv50_head_crc_late_register()
717 root = debugfs_create_dir("nv_crc", crtc->debugfs_entry); in nv50_head_crc_late_register()
718 debugfs_create_file("flip_threshold", 0644, root, head, in nv50_head_crc_late_register()
726 struct nv50_head *head) in nv50_crc_init_head() argument
728 struct nv50_crc *crc = &head->crc; in nv50_crc_init_head()
730 crc->flip_threshold = func->flip_threshold; in nv50_crc_init_head()
731 spin_lock_init(&crc->lock); in nv50_crc_init_head()
732 drm_vblank_work_init(&crc->flip_work, &head->base.base, in nv50_crc_init_head()
740 const struct nv50_crc_func *func = disp->core->func->crc; in nv50_crc_init()