Lines Matching +full:- +full:- +full:commits
28 #include <linux/dma-fence.h>
85 if (old_plane_state->crtc) { in drm_atomic_helper_plane_changed()
87 old_plane_state->crtc); in drm_atomic_helper_plane_changed()
92 crtc_state->planes_changed = true; in drm_atomic_helper_plane_changed()
95 if (plane_state->crtc) { in drm_atomic_helper_plane_changed()
96 crtc_state = drm_atomic_get_new_crtc_state(state, plane_state->crtc); in drm_atomic_helper_plane_changed()
101 crtc_state->planes_changed = true; in drm_atomic_helper_plane_changed()
121 const struct drm_connector_helper_funcs *funcs = connector->helper_private; in handle_conflicting_encoders()
124 if (!new_conn_state->crtc) in handle_conflicting_encoders()
127 if (funcs->atomic_best_encoder) in handle_conflicting_encoders()
128 new_encoder = funcs->atomic_best_encoder(connector, in handle_conflicting_encoders()
130 else if (funcs->best_encoder) in handle_conflicting_encoders()
131 new_encoder = funcs->best_encoder(connector); in handle_conflicting_encoders()
137 drm_dbg_atomic(connector->dev, in handle_conflicting_encoders()
139 new_encoder->base.id, new_encoder->name, in handle_conflicting_encoders()
140 connector->base.id, connector->name); in handle_conflicting_encoders()
142 return -EINVAL; in handle_conflicting_encoders()
163 drm_connector_list_iter_begin(state->dev, &conn_iter); in handle_conflicting_encoders()
170 encoder = connector->state->best_encoder; in handle_conflicting_encoders()
175 drm_dbg_atomic(connector->dev, in handle_conflicting_encoders()
177 encoder->base.id, encoder->name, in handle_conflicting_encoders()
178 connector->state->crtc->base.id, in handle_conflicting_encoders()
179 connector->state->crtc->name, in handle_conflicting_encoders()
180 connector->base.id, connector->name); in handle_conflicting_encoders()
181 ret = -EINVAL; in handle_conflicting_encoders()
191 drm_dbg_atomic(connector->dev, in handle_conflicting_encoders()
193 encoder->base.id, encoder->name, in handle_conflicting_encoders()
194 new_conn_state->crtc->base.id, new_conn_state->crtc->name, in handle_conflicting_encoders()
195 connector->base.id, connector->name); in handle_conflicting_encoders()
197 crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); in handle_conflicting_encoders()
203 if (!crtc_state->connector_mask) { in handle_conflicting_encoders()
209 crtc_state->active = false; in handle_conflicting_encoders()
226 if (conn_state->best_encoder) { in set_best_encoder()
228 crtc = conn_state->connector->state->crtc; in set_best_encoder()
236 WARN_ON(!crtc && encoder != conn_state->best_encoder); in set_best_encoder()
240 crtc_state->encoder_mask &= in set_best_encoder()
241 ~drm_encoder_mask(conn_state->best_encoder); in set_best_encoder()
246 crtc = conn_state->crtc; in set_best_encoder()
251 crtc_state->encoder_mask |= in set_best_encoder()
256 conn_state->best_encoder = encoder; in set_best_encoder()
271 if (new_connector_state->best_encoder != encoder) in steal_encoder()
274 encoder_crtc = old_connector_state->crtc; in steal_encoder()
276 drm_dbg_atomic(encoder->dev, in steal_encoder()
278 encoder->base.id, encoder->name, in steal_encoder()
279 encoder_crtc->base.id, encoder_crtc->name); in steal_encoder()
284 crtc_state->connectors_changed = true; in steal_encoder()
301 drm_dbg_atomic(connector->dev, "Updating routing for [CONNECTOR:%d:%s]\n", in update_connector_routing()
302 connector->base.id, connector->name); in update_connector_routing()
304 if (old_connector_state->crtc != new_connector_state->crtc) { in update_connector_routing()
305 if (old_connector_state->crtc) { in update_connector_routing()
306 crtc_state = drm_atomic_get_new_crtc_state(state, old_connector_state->crtc); in update_connector_routing()
307 crtc_state->connectors_changed = true; in update_connector_routing()
310 if (new_connector_state->crtc) { in update_connector_routing()
311 crtc_state = drm_atomic_get_new_crtc_state(state, new_connector_state->crtc); in update_connector_routing()
312 crtc_state->connectors_changed = true; in update_connector_routing()
316 if (!new_connector_state->crtc) { in update_connector_routing()
317 drm_dbg_atomic(connector->dev, "Disabling [CONNECTOR:%d:%s]\n", in update_connector_routing()
318 connector->base.id, connector->name); in update_connector_routing()
326 new_connector_state->crtc); in update_connector_routing()
329 * we allow DPMS On->Off modesets on unregistered connectors. Modesets in update_connector_routing()
346 * was not pulled in the atomic state by user-space (ie, was pulled in update_connector_routing()
347 * in by the driver, e.g. when updating a DP-MST stream). in update_connector_routing()
349 if (!state->duplicated && drm_connector_is_unregistered(connector) && in update_connector_routing()
350 added_by_user && crtc_state->active) { in update_connector_routing()
351 drm_dbg_atomic(connector->dev, in update_connector_routing()
353 connector->base.id, connector->name); in update_connector_routing()
354 return -EINVAL; in update_connector_routing()
357 funcs = connector->helper_private; in update_connector_routing()
359 if (funcs->atomic_best_encoder) in update_connector_routing()
360 new_encoder = funcs->atomic_best_encoder(connector, state); in update_connector_routing()
361 else if (funcs->best_encoder) in update_connector_routing()
362 new_encoder = funcs->best_encoder(connector); in update_connector_routing()
367 drm_dbg_atomic(connector->dev, in update_connector_routing()
369 connector->base.id, connector->name); in update_connector_routing()
370 return -EINVAL; in update_connector_routing()
373 if (!drm_encoder_crtc_ok(new_encoder, new_connector_state->crtc)) { in update_connector_routing()
374 drm_dbg_atomic(connector->dev, in update_connector_routing()
376 new_encoder->base.id, in update_connector_routing()
377 new_encoder->name, in update_connector_routing()
378 new_connector_state->crtc->base.id, in update_connector_routing()
379 new_connector_state->crtc->name); in update_connector_routing()
380 return -EINVAL; in update_connector_routing()
383 if (new_encoder == new_connector_state->best_encoder) { in update_connector_routing()
386 drm_dbg_atomic(connector->dev, in update_connector_routing()
388 connector->base.id, in update_connector_routing()
389 connector->name, in update_connector_routing()
390 new_encoder->base.id, in update_connector_routing()
391 new_encoder->name, in update_connector_routing()
392 new_connector_state->crtc->base.id, in update_connector_routing()
393 new_connector_state->crtc->name); in update_connector_routing()
402 crtc_state->connectors_changed = true; in update_connector_routing()
404 drm_dbg_atomic(connector->dev, in update_connector_routing()
406 connector->base.id, in update_connector_routing()
407 connector->name, in update_connector_routing()
408 new_encoder->base.id, in update_connector_routing()
409 new_encoder->name, in update_connector_routing()
410 new_connector_state->crtc->base.id, in update_connector_routing()
411 new_connector_state->crtc->name); in update_connector_routing()
427 if (!new_crtc_state->mode_changed && in mode_fixup()
428 !new_crtc_state->connectors_changed) in mode_fixup()
431 drm_mode_copy(&new_crtc_state->adjusted_mode, &new_crtc_state->mode); in mode_fixup()
439 WARN_ON(!!new_conn_state->best_encoder != !!new_conn_state->crtc); in mode_fixup()
441 if (!new_conn_state->crtc || !new_conn_state->best_encoder) in mode_fixup()
445 drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); in mode_fixup()
449 * it away), so we won't call ->mode_fixup twice. in mode_fixup()
451 encoder = new_conn_state->best_encoder; in mode_fixup()
452 funcs = encoder->helper_private; in mode_fixup()
459 drm_dbg_atomic(encoder->dev, "Bridge atomic check failed\n"); in mode_fixup()
463 if (funcs && funcs->atomic_check) { in mode_fixup()
464 ret = funcs->atomic_check(encoder, new_crtc_state, in mode_fixup()
467 drm_dbg_atomic(encoder->dev, in mode_fixup()
469 encoder->base.id, encoder->name); in mode_fixup()
472 } else if (funcs && funcs->mode_fixup) { in mode_fixup()
473 ret = funcs->mode_fixup(encoder, &new_crtc_state->mode, in mode_fixup()
474 &new_crtc_state->adjusted_mode); in mode_fixup()
476 drm_dbg_atomic(encoder->dev, in mode_fixup()
478 encoder->base.id, encoder->name); in mode_fixup()
479 return -EINVAL; in mode_fixup()
487 if (!new_crtc_state->enable) in mode_fixup()
490 if (!new_crtc_state->mode_changed && in mode_fixup()
491 !new_crtc_state->connectors_changed) in mode_fixup()
494 funcs = crtc->helper_private; in mode_fixup()
495 if (!funcs || !funcs->mode_fixup) in mode_fixup()
498 ret = funcs->mode_fixup(crtc, &new_crtc_state->mode, in mode_fixup()
499 &new_crtc_state->adjusted_mode); in mode_fixup()
501 drm_dbg_atomic(crtc->dev, "[CRTC:%d:%s] fixup failed\n", in mode_fixup()
502 crtc->base.id, crtc->name); in mode_fixup()
503 return -EINVAL; in mode_fixup()
520 drm_dbg_atomic(encoder->dev, in mode_valid_path()
522 encoder->base.id, encoder->name); in mode_valid_path()
527 ret = drm_bridge_chain_mode_valid(bridge, &connector->display_info, in mode_valid_path()
530 drm_dbg_atomic(encoder->dev, "[BRIDGE] mode_valid() failed\n"); in mode_valid_path()
536 drm_dbg_atomic(encoder->dev, "[CRTC:%d:%s] mode_valid() failed\n", in mode_valid_path()
537 crtc->base.id, crtc->name); in mode_valid_path()
552 struct drm_encoder *encoder = conn_state->best_encoder; in mode_valid()
553 struct drm_crtc *crtc = conn_state->crtc; in mode_valid()
564 if (!crtc_state->mode_changed && !crtc_state->connectors_changed) in mode_valid()
567 mode = &crtc_state->mode; in mode_valid()
571 return -EINVAL; in mode_valid()
584 drm_for_each_encoder_mask(drm_enc, crtc->dev, crtc_state->encoder_mask) { in drm_atomic_check_valid_clones()
585 if (!drm_enc->possible_clones) { in drm_atomic_check_valid_clones()
586 DRM_DEBUG("enc%d possible_clones is 0\n", drm_enc->base.id); in drm_atomic_check_valid_clones()
590 if ((crtc_state->encoder_mask & drm_enc->possible_clones) != in drm_atomic_check_valid_clones()
591 crtc_state->encoder_mask) { in drm_atomic_check_valid_clones()
593 crtc->base.id, crtc_state->encoder_mask); in drm_atomic_check_valid_clones()
594 return -EINVAL; in drm_atomic_check_valid_clones()
602 * drm_atomic_helper_check_modeset - validate state object for modeset changes
609 * the various per-object callbacks in the follow order:
642 * Zero for success or -errno
660 !!new_crtc_state->connector_mask; in drm_atomic_helper_check_modeset()
662 WARN_ON(!drm_modeset_is_locked(&crtc->mutex)); in drm_atomic_helper_check_modeset()
664 if (!drm_mode_equal(&old_crtc_state->mode, &new_crtc_state->mode)) { in drm_atomic_helper_check_modeset()
666 crtc->base.id, crtc->name); in drm_atomic_helper_check_modeset()
667 new_crtc_state->mode_changed = true; in drm_atomic_helper_check_modeset()
670 if (old_crtc_state->enable != new_crtc_state->enable) { in drm_atomic_helper_check_modeset()
672 crtc->base.id, crtc->name); in drm_atomic_helper_check_modeset()
682 new_crtc_state->mode_changed = true; in drm_atomic_helper_check_modeset()
683 new_crtc_state->connectors_changed = true; in drm_atomic_helper_check_modeset()
686 if (old_crtc_state->active != new_crtc_state->active) { in drm_atomic_helper_check_modeset()
688 crtc->base.id, crtc->name); in drm_atomic_helper_check_modeset()
689 new_crtc_state->active_changed = true; in drm_atomic_helper_check_modeset()
692 if (new_crtc_state->enable != has_connectors) { in drm_atomic_helper_check_modeset()
694 crtc->base.id, crtc->name, in drm_atomic_helper_check_modeset()
695 new_crtc_state->enable, has_connectors); in drm_atomic_helper_check_modeset()
697 return -EINVAL; in drm_atomic_helper_check_modeset()
701 new_crtc_state->no_vblank = false; in drm_atomic_helper_check_modeset()
703 new_crtc_state->no_vblank = true; in drm_atomic_helper_check_modeset()
711 const struct drm_connector_helper_funcs *funcs = connector->helper_private; in drm_atomic_helper_check_modeset()
713 WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); in drm_atomic_helper_check_modeset()
716 * This only sets crtc->connectors_changed for routing changes, in drm_atomic_helper_check_modeset()
717 * drivers must set crtc->connectors_changed themselves when in drm_atomic_helper_check_modeset()
726 if (old_connector_state->crtc) { in drm_atomic_helper_check_modeset()
728 old_connector_state->crtc); in drm_atomic_helper_check_modeset()
729 if (old_connector_state->link_status != in drm_atomic_helper_check_modeset()
730 new_connector_state->link_status) in drm_atomic_helper_check_modeset()
731 new_crtc_state->connectors_changed = true; in drm_atomic_helper_check_modeset()
733 if (old_connector_state->max_requested_bpc != in drm_atomic_helper_check_modeset()
734 new_connector_state->max_requested_bpc) in drm_atomic_helper_check_modeset()
735 new_crtc_state->connectors_changed = true; in drm_atomic_helper_check_modeset()
738 if (funcs->atomic_check) in drm_atomic_helper_check_modeset()
739 ret = funcs->atomic_check(connector, state); in drm_atomic_helper_check_modeset()
743 connector->base.id, connector->name); in drm_atomic_helper_check_modeset()
762 crtc->base.id, crtc->name, in drm_atomic_helper_check_modeset()
763 new_crtc_state->enable ? 'y' : 'n', in drm_atomic_helper_check_modeset()
764 new_crtc_state->active ? 'y' : 'n'); in drm_atomic_helper_check_modeset()
784 const struct drm_connector_helper_funcs *funcs = connector->helper_private; in drm_atomic_helper_check_modeset()
789 if (funcs->atomic_check) in drm_atomic_helper_check_modeset()
790 ret = funcs->atomic_check(connector, state); in drm_atomic_helper_check_modeset()
794 connector->base.id, connector->name); in drm_atomic_helper_check_modeset()
808 encoder = old_connector_state->best_encoder; in drm_atomic_helper_check_modeset()
813 encoder = new_connector_state->best_encoder; in drm_atomic_helper_check_modeset()
828 * drm_atomic_helper_check_wb_connector_state() - Check writeback connector state
836 * Zero for success or -errno
844 struct drm_writeback_job *wb_job = conn_state->writeback_job; in drm_atomic_helper_check_wb_connector_state()
850 if (!wb_job || !wb_job->fb) in drm_atomic_helper_check_wb_connector_state()
853 pixel_format_blob = wb_job->connector->pixel_formats_blob_ptr; in drm_atomic_helper_check_wb_connector_state()
854 nformats = pixel_format_blob->length / sizeof(u32); in drm_atomic_helper_check_wb_connector_state()
855 formats = pixel_format_blob->data; in drm_atomic_helper_check_wb_connector_state()
856 fb = wb_job->fb; in drm_atomic_helper_check_wb_connector_state()
859 if (fb->format->format == formats[i]) in drm_atomic_helper_check_wb_connector_state()
862 drm_dbg_kms(connector->dev, "Invalid pixel format %p4cc\n", &fb->format->format); in drm_atomic_helper_check_wb_connector_state()
864 return -EINVAL; in drm_atomic_helper_check_wb_connector_state()
869 * drm_atomic_helper_check_plane_state() - Check plane state for validity
882 * their own plane handling rather than helper-provided implementations may
896 struct drm_framebuffer *fb = plane_state->fb; in drm_atomic_helper_check_plane_state()
897 struct drm_rect *src = &plane_state->src; in drm_atomic_helper_check_plane_state()
898 struct drm_rect *dst = &plane_state->dst; in drm_atomic_helper_check_plane_state()
899 unsigned int rotation = plane_state->rotation; in drm_atomic_helper_check_plane_state()
903 WARN_ON(plane_state->crtc && plane_state->crtc != crtc_state->crtc); in drm_atomic_helper_check_plane_state()
909 plane_state->visible = false; in drm_atomic_helper_check_plane_state()
914 if (WARN_ON(!plane_state->crtc)) { in drm_atomic_helper_check_plane_state()
915 plane_state->visible = false; in drm_atomic_helper_check_plane_state()
919 if (!crtc_state->enable && !can_update_disabled) { in drm_atomic_helper_check_plane_state()
920 drm_dbg_kms(plane_state->plane->dev, in drm_atomic_helper_check_plane_state()
922 return -EINVAL; in drm_atomic_helper_check_plane_state()
925 drm_rect_rotate(src, fb->width << 16, fb->height << 16, rotation); in drm_atomic_helper_check_plane_state()
931 drm_dbg_kms(plane_state->plane->dev, in drm_atomic_helper_check_plane_state()
933 drm_rect_debug_print("src: ", &plane_state->src, true); in drm_atomic_helper_check_plane_state()
934 drm_rect_debug_print("dst: ", &plane_state->dst, false); in drm_atomic_helper_check_plane_state()
935 return -ERANGE; in drm_atomic_helper_check_plane_state()
938 if (crtc_state->enable) in drm_atomic_helper_check_plane_state()
939 drm_mode_get_hv_timing(&crtc_state->mode, &clip.x2, &clip.y2); in drm_atomic_helper_check_plane_state()
941 plane_state->visible = drm_rect_clip_scaled(src, dst, &clip); in drm_atomic_helper_check_plane_state()
943 drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, rotation); in drm_atomic_helper_check_plane_state()
945 if (!plane_state->visible) in drm_atomic_helper_check_plane_state()
956 drm_dbg_kms(plane_state->plane->dev, in drm_atomic_helper_check_plane_state()
960 return -EINVAL; in drm_atomic_helper_check_plane_state()
968 * drm_atomic_helper_check_crtc_primary_plane() - Check CRTC state for primary plane
982 struct drm_crtc *crtc = crtc_state->crtc; in drm_atomic_helper_check_crtc_primary_plane()
983 struct drm_device *dev = crtc->dev; in drm_atomic_helper_check_crtc_primary_plane()
987 drm_for_each_plane_mask(plane, dev, crtc_state->plane_mask) { in drm_atomic_helper_check_crtc_primary_plane()
988 if (plane->type == DRM_PLANE_TYPE_PRIMARY) in drm_atomic_helper_check_crtc_primary_plane()
992 drm_dbg_atomic(dev, "[CRTC:%d:%s] primary plane missing\n", crtc->base.id, crtc->name); in drm_atomic_helper_check_crtc_primary_plane()
994 return -EINVAL; in drm_atomic_helper_check_crtc_primary_plane()
999 * drm_atomic_helper_check_planes - validate state object for planes changes
1012 * Zero for success or -errno
1027 WARN_ON(!drm_modeset_is_locked(&plane->mutex)); in drm_atomic_helper_check_planes()
1029 funcs = plane->helper_private; in drm_atomic_helper_check_planes()
1035 if (!funcs || !funcs->atomic_check) in drm_atomic_helper_check_planes()
1038 ret = funcs->atomic_check(plane, state); in drm_atomic_helper_check_planes()
1040 drm_dbg_atomic(plane->dev, in drm_atomic_helper_check_planes()
1042 plane->base.id, plane->name); in drm_atomic_helper_check_planes()
1050 funcs = crtc->helper_private; in drm_atomic_helper_check_planes()
1052 if (!funcs || !funcs->atomic_check) in drm_atomic_helper_check_planes()
1055 ret = funcs->atomic_check(crtc, state); in drm_atomic_helper_check_planes()
1057 drm_dbg_atomic(crtc->dev, in drm_atomic_helper_check_planes()
1059 crtc->base.id, crtc->name); in drm_atomic_helper_check_planes()
1069 * drm_atomic_helper_check - validate state object
1101 * Zero for success or -errno
1112 if (dev->mode_config.normalize_zpos) { in drm_atomic_helper_check()
1122 if (state->legacy_cursor_update) in drm_atomic_helper_check()
1123 state->async_update = !drm_atomic_helper_async_check(dev, state); in drm_atomic_helper_check()
1144 * self-refresh and changing CRTCs at the same time, because the in crtc_needs_disable()
1145 * bridge tracks self-refresh status via CRTC state. in crtc_needs_disable()
1147 if (old_state->self_refresh_active && in crtc_needs_disable()
1148 old_state->crtc != new_state->crtc) in crtc_needs_disable()
1152 * We also need to run through the crtc_funcs->disable() function if in crtc_needs_disable()
1157 return old_state->active || in crtc_needs_disable()
1158 (old_state->self_refresh_active && !new_state->active) || in crtc_needs_disable()
1159 new_state->self_refresh_active; in crtc_needs_disable()
1180 if (!old_conn_state->crtc) in disable_outputs()
1183 old_crtc_state = drm_atomic_get_old_crtc_state(state, old_conn_state->crtc); in disable_outputs()
1185 if (new_conn_state->crtc) in disable_outputs()
1188 new_conn_state->crtc); in disable_outputs()
1193 !drm_atomic_crtc_needs_modeset(old_conn_state->crtc->state)) in disable_outputs()
1196 encoder = old_conn_state->best_encoder; in disable_outputs()
1204 funcs = encoder->helper_private; in disable_outputs()
1207 encoder->base.id, encoder->name); in disable_outputs()
1218 if (funcs->atomic_disable) in disable_outputs()
1219 funcs->atomic_disable(encoder, state); in disable_outputs()
1220 else if (new_conn_state->crtc && funcs->prepare) in disable_outputs()
1221 funcs->prepare(encoder); in disable_outputs()
1222 else if (funcs->disable) in disable_outputs()
1223 funcs->disable(encoder); in disable_outputs()
1224 else if (funcs->dpms) in disable_outputs()
1225 funcs->dpms(encoder, DRM_MODE_DPMS_OFF); in disable_outputs()
1242 funcs = crtc->helper_private; in disable_outputs()
1245 crtc->base.id, crtc->name); in disable_outputs()
1249 if (new_crtc_state->enable && funcs->prepare) in disable_outputs()
1250 funcs->prepare(crtc); in disable_outputs()
1251 else if (funcs->atomic_disable) in disable_outputs()
1252 funcs->atomic_disable(crtc, state); in disable_outputs()
1253 else if (funcs->disable) in disable_outputs()
1254 funcs->disable(crtc); in disable_outputs()
1255 else if (funcs->dpms) in disable_outputs()
1256 funcs->dpms(crtc, DRM_MODE_DPMS_OFF); in disable_outputs()
1263 * Self-refresh is not a true "disable"; ensure vblank remains in disable_outputs()
1266 if (new_crtc_state->self_refresh_active) in disable_outputs()
1268 "driver disabled vblank in self-refresh\n"); in disable_outputs()
1270 WARN_ONCE(ret != -EINVAL, in disable_outputs()
1278 * drm_atomic_helper_update_legacy_modeset_state - update legacy modeset state
1286 * a pure helper-based modeset implementation.
1306 if (connector->encoder) { in drm_atomic_helper_update_legacy_modeset_state()
1307 WARN_ON(!connector->encoder->crtc); in drm_atomic_helper_update_legacy_modeset_state()
1309 connector->encoder->crtc = NULL; in drm_atomic_helper_update_legacy_modeset_state()
1310 connector->encoder = NULL; in drm_atomic_helper_update_legacy_modeset_state()
1313 crtc = new_conn_state->crtc; in drm_atomic_helper_update_legacy_modeset_state()
1314 if ((!crtc && old_conn_state->crtc) || in drm_atomic_helper_update_legacy_modeset_state()
1315 (crtc && drm_atomic_crtc_needs_modeset(crtc->state))) { in drm_atomic_helper_update_legacy_modeset_state()
1318 if (crtc && crtc->state->active) in drm_atomic_helper_update_legacy_modeset_state()
1321 connector->dpms = mode; in drm_atomic_helper_update_legacy_modeset_state()
1327 if (!new_conn_state->crtc) in drm_atomic_helper_update_legacy_modeset_state()
1330 if (WARN_ON(!new_conn_state->best_encoder)) in drm_atomic_helper_update_legacy_modeset_state()
1333 connector->encoder = new_conn_state->best_encoder; in drm_atomic_helper_update_legacy_modeset_state()
1334 connector->encoder->crtc = new_conn_state->crtc; in drm_atomic_helper_update_legacy_modeset_state()
1339 struct drm_plane *primary = crtc->primary; in drm_atomic_helper_update_legacy_modeset_state()
1342 crtc->mode = new_crtc_state->mode; in drm_atomic_helper_update_legacy_modeset_state()
1343 crtc->enabled = new_crtc_state->enable; in drm_atomic_helper_update_legacy_modeset_state()
1348 if (new_plane_state && new_plane_state->crtc == crtc) { in drm_atomic_helper_update_legacy_modeset_state()
1349 crtc->x = new_plane_state->src_x >> 16; in drm_atomic_helper_update_legacy_modeset_state()
1350 crtc->y = new_plane_state->src_y >> 16; in drm_atomic_helper_update_legacy_modeset_state()
1357 * drm_atomic_helper_calc_timestamping_constants - update vblank timestamping constants
1370 if (new_crtc_state->enable) in drm_atomic_helper_calc_timestamping_constants()
1372 &new_crtc_state->adjusted_mode); in drm_atomic_helper_calc_timestamping_constants()
1389 if (!new_crtc_state->mode_changed) in crtc_set_mode()
1392 funcs = crtc->helper_private; in crtc_set_mode()
1394 if (new_crtc_state->enable && funcs->mode_set_nofb) { in crtc_set_mode()
1396 crtc->base.id, crtc->name); in crtc_set_mode()
1398 funcs->mode_set_nofb(crtc); in crtc_set_mode()
1408 if (!new_conn_state->best_encoder) in crtc_set_mode()
1411 encoder = new_conn_state->best_encoder; in crtc_set_mode()
1412 funcs = encoder->helper_private; in crtc_set_mode()
1413 new_crtc_state = new_conn_state->crtc->state; in crtc_set_mode()
1414 mode = &new_crtc_state->mode; in crtc_set_mode()
1415 adjusted_mode = &new_crtc_state->adjusted_mode; in crtc_set_mode()
1417 if (!new_crtc_state->mode_changed && !new_crtc_state->connectors_changed) in crtc_set_mode()
1421 encoder->base.id, encoder->name); in crtc_set_mode()
1427 if (funcs && funcs->atomic_mode_set) { in crtc_set_mode()
1428 funcs->atomic_mode_set(encoder, new_crtc_state, in crtc_set_mode()
1430 } else if (funcs && funcs->mode_set) { in crtc_set_mode()
1431 funcs->mode_set(encoder, mode, adjusted_mode); in crtc_set_mode()
1440 * drm_atomic_helper_commit_modeset_disables - modeset commit to disable outputs
1449 * does. But drivers with different needs can group the modeset commits together
1450 * and do the plane commits at the end. This is useful for drivers doing runtime
1475 funcs = connector->helper_private; in drm_atomic_helper_commit_writebacks()
1476 if (!funcs->atomic_commit) in drm_atomic_helper_commit_writebacks()
1479 if (new_conn_state->writeback_job && new_conn_state->writeback_job->fb) { in drm_atomic_helper_commit_writebacks()
1480 WARN_ON(connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK); in drm_atomic_helper_commit_writebacks()
1481 funcs->atomic_commit(connector, state); in drm_atomic_helper_commit_writebacks()
1487 * drm_atomic_helper_commit_modeset_enables - modeset commit to enable outputs
1496 * does. But drivers with different needs can group the modeset commits together
1497 * and do the plane commits at the end. This is useful for drivers doing runtime
1517 if (!new_crtc_state->active) in drm_atomic_helper_commit_modeset_enables()
1520 funcs = crtc->helper_private; in drm_atomic_helper_commit_modeset_enables()
1522 if (new_crtc_state->enable) { in drm_atomic_helper_commit_modeset_enables()
1524 crtc->base.id, crtc->name); in drm_atomic_helper_commit_modeset_enables()
1525 if (funcs->atomic_enable) in drm_atomic_helper_commit_modeset_enables()
1526 funcs->atomic_enable(crtc, state); in drm_atomic_helper_commit_modeset_enables()
1527 else if (funcs->commit) in drm_atomic_helper_commit_modeset_enables()
1528 funcs->commit(crtc); in drm_atomic_helper_commit_modeset_enables()
1537 if (!new_conn_state->best_encoder) in drm_atomic_helper_commit_modeset_enables()
1540 if (!new_conn_state->crtc->state->active || in drm_atomic_helper_commit_modeset_enables()
1541 !drm_atomic_crtc_needs_modeset(new_conn_state->crtc->state)) in drm_atomic_helper_commit_modeset_enables()
1544 encoder = new_conn_state->best_encoder; in drm_atomic_helper_commit_modeset_enables()
1545 funcs = encoder->helper_private; in drm_atomic_helper_commit_modeset_enables()
1548 encoder->base.id, encoder->name); in drm_atomic_helper_commit_modeset_enables()
1558 if (funcs->atomic_enable) in drm_atomic_helper_commit_modeset_enables()
1559 funcs->atomic_enable(encoder, state); in drm_atomic_helper_commit_modeset_enables()
1560 else if (funcs->enable) in drm_atomic_helper_commit_modeset_enables()
1561 funcs->enable(encoder); in drm_atomic_helper_commit_modeset_enables()
1562 else if (funcs->commit) in drm_atomic_helper_commit_modeset_enables()
1563 funcs->commit(encoder); in drm_atomic_helper_commit_modeset_enables()
1593 if (!new_crtc_state->active) in set_fence_deadline()
1608 if (!new_plane_state->fence) in set_fence_deadline()
1610 dma_fence_set_deadline(new_plane_state->fence, vbltime); in set_fence_deadline()
1615 * drm_atomic_helper_wait_for_fences - wait for fences stashed in plane state
1628 * non-blocking. For non-blocking commit all waiting needs to happen after
1629 * drm_atomic_helper_swap_state() is called, but for blocking commits we want
1646 if (!new_plane_state->fence) in drm_atomic_helper_wait_for_fences()
1649 WARN_ON(!new_plane_state->fb); in drm_atomic_helper_wait_for_fences()
1652 * If waiting for fences pre-swap (ie: nonblock), userspace can in drm_atomic_helper_wait_for_fences()
1656 ret = dma_fence_wait(new_plane_state->fence, pre_swap); in drm_atomic_helper_wait_for_fences()
1660 dma_fence_put(new_plane_state->fence); in drm_atomic_helper_wait_for_fences()
1661 new_plane_state->fence = NULL; in drm_atomic_helper_wait_for_fences()
1669 * drm_atomic_helper_wait_for_vblanks - wait for vblank on CRTCs
1677 * plane update use-case.
1696 if (state->legacy_cursor_update) in drm_atomic_helper_wait_for_vblanks()
1700 if (!new_crtc_state->active) in drm_atomic_helper_wait_for_vblanks()
1708 state->crtcs[i].last_vblank_count = drm_crtc_vblank_count(crtc); in drm_atomic_helper_wait_for_vblanks()
1715 ret = wait_event_timeout(dev->vblank[i].queue, in drm_atomic_helper_wait_for_vblanks()
1716 state->crtcs[i].last_vblank_count != in drm_atomic_helper_wait_for_vblanks()
1721 crtc->base.id, crtc->name); in drm_atomic_helper_wait_for_vblanks()
1729 * drm_atomic_helper_wait_for_flip_done - wait for all page flips to be done
1737 * CRTCs, assuming that cursors-only updates are signalling their completion
1749 for (i = 0; i < dev->mode_config.num_crtc; i++) { in drm_atomic_helper_wait_for_flip_done()
1750 struct drm_crtc_commit *commit = state->crtcs[i].commit; in drm_atomic_helper_wait_for_flip_done()
1753 crtc = state->crtcs[i].ptr; in drm_atomic_helper_wait_for_flip_done()
1758 ret = wait_for_completion_timeout(&commit->flip_done, 10 * HZ); in drm_atomic_helper_wait_for_flip_done()
1761 crtc->base.id, crtc->name); in drm_atomic_helper_wait_for_flip_done()
1764 if (state->fake_commit) in drm_atomic_helper_wait_for_flip_done()
1765 complete_all(&state->fake_commit->flip_done); in drm_atomic_helper_wait_for_flip_done()
1770 * drm_atomic_helper_commit_tail - commit atomic update to hardware
1784 struct drm_device *dev = state->dev; in drm_atomic_helper_commit_tail()
1803 * drm_atomic_helper_commit_tail_rpm - commit atomic update to hardware
1814 struct drm_device *dev = state->dev; in drm_atomic_helper_commit_tail_rpm()
1835 struct drm_device *dev = state->dev; in commit_tail()
1843 funcs = dev->mode_config.helper_private; in commit_tail()
1864 * self-refresh active beforehand: in commit_tail()
1867 if (new_crtc_state->self_refresh_active) in commit_tail()
1870 if (funcs && funcs->atomic_commit_tail) in commit_tail()
1871 funcs->atomic_commit_tail(state); in commit_tail()
1895 * drm_atomic_helper_async_check - check if state can be committed asynchronously
1900 * Async commits are not supposed to swap the states like normal sync commits
1901 * but just do in-place changes on the current state.
1920 return -EINVAL; in drm_atomic_helper_async_check()
1930 return -EINVAL; in drm_atomic_helper_async_check()
1933 if (!new_plane_state->crtc || in drm_atomic_helper_async_check()
1934 old_plane_state->crtc != new_plane_state->crtc) { in drm_atomic_helper_async_check()
1937 plane->base.id, plane->name); in drm_atomic_helper_async_check()
1938 return -EINVAL; in drm_atomic_helper_async_check()
1941 funcs = plane->helper_private; in drm_atomic_helper_async_check()
1942 if (!funcs->atomic_async_update) { in drm_atomic_helper_async_check()
1945 plane->base.id, plane->name); in drm_atomic_helper_async_check()
1946 return -EINVAL; in drm_atomic_helper_async_check()
1949 if (new_plane_state->fence) { in drm_atomic_helper_async_check()
1952 plane->base.id, plane->name); in drm_atomic_helper_async_check()
1953 return -EINVAL; in drm_atomic_helper_async_check()
1961 if (old_plane_state->commit && in drm_atomic_helper_async_check()
1962 !try_wait_for_completion(&old_plane_state->commit->hw_done)) { in drm_atomic_helper_async_check()
1965 plane->base.id, plane->name); in drm_atomic_helper_async_check()
1966 return -EBUSY; in drm_atomic_helper_async_check()
1969 ret = funcs->atomic_async_check(plane, state, false); in drm_atomic_helper_async_check()
1973 plane->base.id, plane->name); in drm_atomic_helper_async_check()
1979 * drm_atomic_helper_async_commit - commit state asynchronously
1983 * This function commits a state asynchronously, i.e., not vblank
1985 * drm_atomic_async_check() succeeds. Async commits are not supposed to swap
1986 * the states like normal sync commits, but just do in-place changes on the
1989 * TODO: Implement full swap instead of doing in-place changes.
2000 struct drm_framebuffer *new_fb = plane_state->fb; in drm_atomic_helper_async_commit()
2001 struct drm_framebuffer *old_fb = plane->state->fb; in drm_atomic_helper_async_commit()
2003 funcs = plane->helper_private; in drm_atomic_helper_async_commit()
2004 funcs->atomic_async_update(plane, state); in drm_atomic_helper_async_commit()
2007 * ->atomic_async_update() is supposed to update the in drm_atomic_helper_async_commit()
2008 * plane->state in-place, make sure at least common in drm_atomic_helper_async_commit()
2011 WARN_ON_ONCE(plane->state->fb != new_fb); in drm_atomic_helper_async_commit()
2012 WARN_ON_ONCE(plane->state->crtc_x != plane_state->crtc_x); in drm_atomic_helper_async_commit()
2013 WARN_ON_ONCE(plane->state->crtc_y != plane_state->crtc_y); in drm_atomic_helper_async_commit()
2014 WARN_ON_ONCE(plane->state->src_x != plane_state->src_x); in drm_atomic_helper_async_commit()
2015 WARN_ON_ONCE(plane->state->src_y != plane_state->src_y); in drm_atomic_helper_async_commit()
2021 WARN_ON_ONCE(plane_state->fb != old_fb); in drm_atomic_helper_async_commit()
2027 * drm_atomic_helper_commit - commit validated state object
2032 * This function commits a with drm_atomic_helper_check() pre-validated state
2034 * function implements nonblocking commits, using
2042 * Zero for success or -errno.
2050 if (state->async_update) { in drm_atomic_helper_commit()
2065 INIT_WORK(&state->commit_work, commit_work); in drm_atomic_helper_commit()
2078 * This is the point of no return - everything below never fails except in drm_atomic_helper_commit()
2109 queue_work(system_unbound_wq, &state->commit_work); in drm_atomic_helper_commit()
2124 * Nonblocking atomic commits should use struct &drm_crtc_commit to sequence
2130 * nonblocking commits, using drm_atomic_helper_setup_commit() internally:
2141 * different atomic commits on different CRTCs in parallel. The simplest way to
2143 * that drivers are not required to split up atomic commits and run an
2144 * individual commit in parallel - userspace is supposed to do that if it cares.
2155 * (nonblocking) commits, both due to locking and due to commit sequencing
2163 * free-standing state objects (currently not the case for any driver) then even
2164 * multiple pending commits could be in-flight at the same time.
2166 * 4. Schedule a work item to do all subsequent steps, using the split-out
2167 * commit helpers: a) pre-plane commit b) plane commit c) post-plane commit and
2181 spin_lock(&crtc->commit_lock); in stall_checks()
2183 list_for_each_entry(commit, &crtc->commit_list, commit_entry) { in stall_checks()
2185 completed = try_wait_for_completion(&commit->flip_done); in stall_checks()
2191 spin_unlock(&crtc->commit_lock); in stall_checks()
2192 drm_dbg_atomic(crtc->dev, in stall_checks()
2194 crtc->base.id, crtc->name); in stall_checks()
2196 return -EBUSY; in stall_checks()
2205 spin_unlock(&crtc->commit_lock); in stall_checks()
2210 /* We don't want to let commits get ahead of cleanup work too much, in stall_checks()
2211 * stalling on 2nd previous commit means triple-buffer won't ever stall. in stall_checks()
2213 ret = wait_for_completion_interruptible_timeout(&stall_commit->cleanup_done, in stall_checks()
2216 drm_err(crtc->dev, "[CRTC:%d:%s] cleanup_done timed out\n", in stall_checks()
2217 crtc->base.id, crtc->name); in stall_checks()
2235 init_completion(&commit->flip_done); in init_commit()
2236 init_completion(&commit->hw_done); in init_commit()
2237 init_completion(&commit->cleanup_done); in init_commit()
2238 INIT_LIST_HEAD(&commit->commit_entry); in init_commit()
2239 kref_init(&commit->ref); in init_commit()
2240 commit->crtc = crtc; in init_commit()
2251 return new_crtc_state->commit; in crtc_or_fake_commit()
2254 if (!state->fake_commit) { in crtc_or_fake_commit()
2255 state->fake_commit = kzalloc(sizeof(*state->fake_commit), GFP_KERNEL); in crtc_or_fake_commit()
2256 if (!state->fake_commit) in crtc_or_fake_commit()
2259 init_commit(state->fake_commit, NULL); in crtc_or_fake_commit()
2262 return state->fake_commit; in crtc_or_fake_commit()
2266 * drm_atomic_helper_setup_commit - setup possibly nonblocking commit
2271 * nonblocking commits. Drivers using the nonblocking commit infrastructure
2280 * actually committing the hardware state, and for nonblocking commits this call
2297 * complete and easy-to-use default implementation of the atomic_commit() hook.
2299 * The tracking of asynchronously executed and still pending commits is done
2307 * 0 on success. -EBUSY when userspace schedules nonblocking commits too fast,
2308 * -ENOMEM on allocation failures and -EINTR when a signal is pending.
2323 funcs = state->dev->mode_config.helper_private; in drm_atomic_helper_setup_commit()
2328 return -ENOMEM; in drm_atomic_helper_setup_commit()
2332 new_crtc_state->commit = commit; in drm_atomic_helper_setup_commit()
2343 if (!old_crtc_state->active && !new_crtc_state->active) { in drm_atomic_helper_setup_commit()
2344 complete_all(&commit->flip_done); in drm_atomic_helper_setup_commit()
2349 if (state->legacy_cursor_update) { in drm_atomic_helper_setup_commit()
2350 complete_all(&commit->flip_done); in drm_atomic_helper_setup_commit()
2354 if (!new_crtc_state->event) { in drm_atomic_helper_setup_commit()
2355 commit->event = kzalloc(sizeof(*commit->event), in drm_atomic_helper_setup_commit()
2357 if (!commit->event) in drm_atomic_helper_setup_commit()
2358 return -ENOMEM; in drm_atomic_helper_setup_commit()
2360 new_crtc_state->event = commit->event; in drm_atomic_helper_setup_commit()
2363 new_crtc_state->event->base.completion = &commit->flip_done; in drm_atomic_helper_setup_commit()
2364 new_crtc_state->event->base.completion_release = release_crtc_commit; in drm_atomic_helper_setup_commit()
2367 commit->abort_completion = true; in drm_atomic_helper_setup_commit()
2369 state->crtcs[i].commit = commit; in drm_atomic_helper_setup_commit()
2378 if (nonblock && old_conn_state->commit && in drm_atomic_helper_setup_commit()
2379 !try_wait_for_completion(&old_conn_state->commit->flip_done)) { in drm_atomic_helper_setup_commit()
2380 drm_dbg_atomic(conn->dev, in drm_atomic_helper_setup_commit()
2382 conn->base.id, conn->name); in drm_atomic_helper_setup_commit()
2384 return -EBUSY; in drm_atomic_helper_setup_commit()
2388 commit = crtc_or_fake_commit(state, new_conn_state->crtc ?: old_conn_state->crtc); in drm_atomic_helper_setup_commit()
2390 return -ENOMEM; in drm_atomic_helper_setup_commit()
2392 new_conn_state->commit = drm_crtc_commit_get(commit); in drm_atomic_helper_setup_commit()
2400 if (nonblock && old_plane_state->commit && in drm_atomic_helper_setup_commit()
2401 !try_wait_for_completion(&old_plane_state->commit->flip_done)) { in drm_atomic_helper_setup_commit()
2402 drm_dbg_atomic(plane->dev, in drm_atomic_helper_setup_commit()
2404 plane->base.id, plane->name); in drm_atomic_helper_setup_commit()
2406 return -EBUSY; in drm_atomic_helper_setup_commit()
2410 commit = crtc_or_fake_commit(state, new_plane_state->crtc ?: old_plane_state->crtc); in drm_atomic_helper_setup_commit()
2412 return -ENOMEM; in drm_atomic_helper_setup_commit()
2414 new_plane_state->commit = drm_crtc_commit_get(commit); in drm_atomic_helper_setup_commit()
2417 if (funcs && funcs->atomic_commit_setup) in drm_atomic_helper_setup_commit()
2418 return funcs->atomic_commit_setup(state); in drm_atomic_helper_setup_commit()
2425 * drm_atomic_helper_wait_for_dependencies - wait for required preceding commits
2428 * This function waits for all preceding commits that touch the same CRTC as
2433 * This is part of the atomic helper support for nonblocking commits, see
2448 ret = drm_crtc_commit_wait(old_crtc_state->commit); in drm_atomic_helper_wait_for_dependencies()
2450 drm_err(crtc->dev, in drm_atomic_helper_wait_for_dependencies()
2452 crtc->base.id, crtc->name); in drm_atomic_helper_wait_for_dependencies()
2456 ret = drm_crtc_commit_wait(old_conn_state->commit); in drm_atomic_helper_wait_for_dependencies()
2458 drm_err(conn->dev, in drm_atomic_helper_wait_for_dependencies()
2460 conn->base.id, conn->name); in drm_atomic_helper_wait_for_dependencies()
2464 ret = drm_crtc_commit_wait(old_plane_state->commit); in drm_atomic_helper_wait_for_dependencies()
2466 drm_err(plane->dev, in drm_atomic_helper_wait_for_dependencies()
2468 plane->base.id, plane->name); in drm_atomic_helper_wait_for_dependencies()
2474 * drm_atomic_helper_fake_vblank - fake VBLANK events if needed
2488 * This is part of the atomic helper support for nonblocking commits, see
2500 if (!new_crtc_state->no_vblank) in drm_atomic_helper_fake_vblank()
2503 spin_lock_irqsave(&state->dev->event_lock, flags); in drm_atomic_helper_fake_vblank()
2504 if (new_crtc_state->event) { in drm_atomic_helper_fake_vblank()
2506 new_crtc_state->event); in drm_atomic_helper_fake_vblank()
2507 new_crtc_state->event = NULL; in drm_atomic_helper_fake_vblank()
2509 spin_unlock_irqrestore(&state->dev->event_lock, flags); in drm_atomic_helper_fake_vblank()
2515 * drm_atomic_helper_commit_hw_done - setup possible nonblocking commit
2526 * This is part of the atomic helper support for nonblocking commits, see
2537 commit = new_crtc_state->commit; in drm_atomic_helper_commit_hw_done()
2542 * copy new_crtc_state->commit to old_crtc_state->commit, in drm_atomic_helper_commit_hw_done()
2546 if (old_crtc_state->commit) in drm_atomic_helper_commit_hw_done()
2547 drm_crtc_commit_put(old_crtc_state->commit); in drm_atomic_helper_commit_hw_done()
2549 old_crtc_state->commit = drm_crtc_commit_get(commit); in drm_atomic_helper_commit_hw_done()
2552 WARN_ON(new_crtc_state->event); in drm_atomic_helper_commit_hw_done()
2553 complete_all(&commit->hw_done); in drm_atomic_helper_commit_hw_done()
2556 if (state->fake_commit) { in drm_atomic_helper_commit_hw_done()
2557 complete_all(&state->fake_commit->hw_done); in drm_atomic_helper_commit_hw_done()
2558 complete_all(&state->fake_commit->flip_done); in drm_atomic_helper_commit_hw_done()
2564 * drm_atomic_helper_commit_cleanup_done - signal completion of commit
2571 * This is part of the atomic helper support for nonblocking commits, see
2582 commit = old_crtc_state->commit; in drm_atomic_helper_commit_cleanup_done()
2586 complete_all(&commit->cleanup_done); in drm_atomic_helper_commit_cleanup_done()
2587 WARN_ON(!try_wait_for_completion(&commit->hw_done)); in drm_atomic_helper_commit_cleanup_done()
2589 spin_lock(&crtc->commit_lock); in drm_atomic_helper_commit_cleanup_done()
2590 list_del(&commit->commit_entry); in drm_atomic_helper_commit_cleanup_done()
2591 spin_unlock(&crtc->commit_lock); in drm_atomic_helper_commit_cleanup_done()
2594 if (state->fake_commit) { in drm_atomic_helper_commit_cleanup_done()
2595 complete_all(&state->fake_commit->cleanup_done); in drm_atomic_helper_commit_cleanup_done()
2596 WARN_ON(!try_wait_for_completion(&state->fake_commit->hw_done)); in drm_atomic_helper_commit_cleanup_done()
2602 * drm_atomic_helper_prepare_planes - prepare plane resources before commit
2624 if (!new_conn_state->writeback_job) in drm_atomic_helper_prepare_planes()
2627 ret = drm_writeback_prepare_job(new_conn_state->writeback_job); in drm_atomic_helper_prepare_planes()
2635 funcs = plane->helper_private; in drm_atomic_helper_prepare_planes()
2637 if (funcs->prepare_fb) { in drm_atomic_helper_prepare_planes()
2638 ret = funcs->prepare_fb(plane, new_plane_state); in drm_atomic_helper_prepare_planes()
2642 WARN_ON_ONCE(funcs->cleanup_fb); in drm_atomic_helper_prepare_planes()
2654 const struct drm_plane_helper_funcs *funcs = plane->helper_private; in drm_atomic_helper_prepare_planes()
2656 if (funcs->begin_fb_access) { in drm_atomic_helper_prepare_planes()
2657 ret = funcs->begin_fb_access(plane, new_plane_state); in drm_atomic_helper_prepare_planes()
2667 const struct drm_plane_helper_funcs *funcs = plane->helper_private; in drm_atomic_helper_prepare_planes()
2672 if (funcs->end_fb_access) in drm_atomic_helper_prepare_planes()
2673 funcs->end_fb_access(plane, new_plane_state); in drm_atomic_helper_prepare_planes()
2683 funcs = plane->helper_private; in drm_atomic_helper_prepare_planes()
2685 if (funcs->cleanup_fb) in drm_atomic_helper_prepare_planes()
2686 funcs->cleanup_fb(plane, new_plane_state); in drm_atomic_helper_prepare_planes()
2694 * drm_atomic_helper_unprepare_planes - release plane resources on aborts
2711 const struct drm_plane_helper_funcs *funcs = plane->helper_private; in drm_atomic_helper_unprepare_planes()
2713 if (funcs->end_fb_access) in drm_atomic_helper_unprepare_planes()
2714 funcs->end_fb_access(plane, new_plane_state); in drm_atomic_helper_unprepare_planes()
2718 const struct drm_plane_helper_funcs *funcs = plane->helper_private; in drm_atomic_helper_unprepare_planes()
2720 if (funcs->cleanup_fb) in drm_atomic_helper_unprepare_planes()
2721 funcs->cleanup_fb(plane, new_plane_state); in drm_atomic_helper_unprepare_planes()
2728 return state->crtc && state->crtc->state->active; in plane_crtc_active()
2732 * drm_atomic_helper_commit_planes - commit plane state
2737 * This function commits the new plane state using the plane and atomic helper
2787 funcs = crtc->helper_private; in drm_atomic_helper_commit_planes()
2789 if (!funcs || !funcs->atomic_begin) in drm_atomic_helper_commit_planes()
2792 if (active_only && !new_crtc_state->active) in drm_atomic_helper_commit_planes()
2795 funcs->atomic_begin(crtc, state); in drm_atomic_helper_commit_planes()
2802 funcs = plane->helper_private; in drm_atomic_helper_commit_planes()
2825 * Special-case disabling the plane if drivers support it. in drm_atomic_helper_commit_planes()
2827 if (disabling && funcs->atomic_disable) { in drm_atomic_helper_commit_planes()
2830 crtc_state = old_plane_state->crtc->state; in drm_atomic_helper_commit_planes()
2836 funcs->atomic_disable(plane, state); in drm_atomic_helper_commit_planes()
2837 } else if (new_plane_state->crtc || disabling) { in drm_atomic_helper_commit_planes()
2838 funcs->atomic_update(plane, state); in drm_atomic_helper_commit_planes()
2840 if (!disabling && funcs->atomic_enable) { in drm_atomic_helper_commit_planes()
2842 funcs->atomic_enable(plane, state); in drm_atomic_helper_commit_planes()
2850 funcs = crtc->helper_private; in drm_atomic_helper_commit_planes()
2852 if (!funcs || !funcs->atomic_flush) in drm_atomic_helper_commit_planes()
2855 if (active_only && !new_crtc_state->active) in drm_atomic_helper_commit_planes()
2858 funcs->atomic_flush(crtc, state); in drm_atomic_helper_commit_planes()
2866 const struct drm_plane_helper_funcs *funcs = plane->helper_private; in drm_atomic_helper_commit_planes()
2868 if (funcs->end_fb_access) in drm_atomic_helper_commit_planes()
2869 funcs->end_fb_access(plane, old_plane_state); in drm_atomic_helper_commit_planes()
2875 * drm_atomic_helper_commit_planes_on_crtc - commit plane state for a CRTC
2878 * This function commits the new plane state using the plane and atomic helper
2883 * This function is useful when plane updates should be done CRTC-by-CRTC
2887 * between different CRTCs because this function doesn't handle inter-CRTC
2895 struct drm_crtc *crtc = old_crtc_state->crtc; in drm_atomic_helper_commit_planes_on_crtc()
2896 struct drm_atomic_state *old_state = old_crtc_state->state; in drm_atomic_helper_commit_planes_on_crtc()
2902 plane_mask = old_crtc_state->plane_mask; in drm_atomic_helper_commit_planes_on_crtc()
2903 plane_mask |= new_crtc_state->plane_mask; in drm_atomic_helper_commit_planes_on_crtc()
2905 crtc_funcs = crtc->helper_private; in drm_atomic_helper_commit_planes_on_crtc()
2906 if (crtc_funcs && crtc_funcs->atomic_begin) in drm_atomic_helper_commit_planes_on_crtc()
2907 crtc_funcs->atomic_begin(crtc, old_state); in drm_atomic_helper_commit_planes_on_crtc()
2909 drm_for_each_plane_mask(plane, crtc->dev, plane_mask) { in drm_atomic_helper_commit_planes_on_crtc()
2917 plane_funcs = plane->helper_private; in drm_atomic_helper_commit_planes_on_crtc()
2922 WARN_ON(new_plane_state->crtc && in drm_atomic_helper_commit_planes_on_crtc()
2923 new_plane_state->crtc != crtc); in drm_atomic_helper_commit_planes_on_crtc()
2927 if (disabling && plane_funcs->atomic_disable) { in drm_atomic_helper_commit_planes_on_crtc()
2928 plane_funcs->atomic_disable(plane, old_state); in drm_atomic_helper_commit_planes_on_crtc()
2929 } else if (new_plane_state->crtc || disabling) { in drm_atomic_helper_commit_planes_on_crtc()
2930 plane_funcs->atomic_update(plane, old_state); in drm_atomic_helper_commit_planes_on_crtc()
2932 if (!disabling && plane_funcs->atomic_enable) { in drm_atomic_helper_commit_planes_on_crtc()
2934 plane_funcs->atomic_enable(plane, old_state); in drm_atomic_helper_commit_planes_on_crtc()
2939 if (crtc_funcs && crtc_funcs->atomic_flush) in drm_atomic_helper_commit_planes_on_crtc()
2940 crtc_funcs->atomic_flush(crtc, old_state); in drm_atomic_helper_commit_planes_on_crtc()
2945 * drm_atomic_helper_disable_planes_on_crtc - helper to disable CRTC's planes
2953 * If the atomic-parameter is set the function calls the CRTC's
2964 struct drm_crtc *crtc = old_crtc_state->crtc; in drm_atomic_helper_disable_planes_on_crtc()
2966 crtc->helper_private; in drm_atomic_helper_disable_planes_on_crtc()
2969 if (atomic && crtc_funcs && crtc_funcs->atomic_begin) in drm_atomic_helper_disable_planes_on_crtc()
2970 crtc_funcs->atomic_begin(crtc, NULL); in drm_atomic_helper_disable_planes_on_crtc()
2974 plane->helper_private; in drm_atomic_helper_disable_planes_on_crtc()
2979 WARN_ON(!plane_funcs->atomic_disable); in drm_atomic_helper_disable_planes_on_crtc()
2980 if (plane_funcs->atomic_disable) in drm_atomic_helper_disable_planes_on_crtc()
2981 plane_funcs->atomic_disable(plane, NULL); in drm_atomic_helper_disable_planes_on_crtc()
2984 if (atomic && crtc_funcs && crtc_funcs->atomic_flush) in drm_atomic_helper_disable_planes_on_crtc()
2985 crtc_funcs->atomic_flush(crtc, NULL); in drm_atomic_helper_disable_planes_on_crtc()
2990 * drm_atomic_helper_cleanup_planes - cleanup plane resources after commit
3010 const struct drm_plane_helper_funcs *funcs = plane->helper_private; in drm_atomic_helper_cleanup_planes()
3012 if (funcs->cleanup_fb) in drm_atomic_helper_cleanup_planes()
3013 funcs->cleanup_fb(plane, old_plane_state); in drm_atomic_helper_cleanup_planes()
3019 * drm_atomic_helper_swap_state - store atomic state into current sw state
3021 * @stall: stall for preceding commits
3043 * @stall must be set when nonblocking commits for this driver directly access
3049 * Returns 0 on success. Can return -ERESTARTSYS when @stall is true and the
3050 * waiting for the previous commits has been interrupted.
3072 * obj->state is directly dereferenced anywhere in the drivers in drm_atomic_helper_swap_state()
3078 commit = old_crtc_state->commit; in drm_atomic_helper_swap_state()
3083 ret = wait_for_completion_interruptible(&commit->hw_done); in drm_atomic_helper_swap_state()
3089 commit = old_conn_state->commit; in drm_atomic_helper_swap_state()
3094 ret = wait_for_completion_interruptible(&commit->hw_done); in drm_atomic_helper_swap_state()
3100 commit = old_plane_state->commit; in drm_atomic_helper_swap_state()
3105 ret = wait_for_completion_interruptible(&commit->hw_done); in drm_atomic_helper_swap_state()
3112 WARN_ON(connector->state != old_conn_state); in drm_atomic_helper_swap_state()
3114 old_conn_state->state = state; in drm_atomic_helper_swap_state()
3115 new_conn_state->state = NULL; in drm_atomic_helper_swap_state()
3117 state->connectors[i].state = old_conn_state; in drm_atomic_helper_swap_state()
3118 connector->state = new_conn_state; in drm_atomic_helper_swap_state()
3122 WARN_ON(crtc->state != old_crtc_state); in drm_atomic_helper_swap_state()
3124 old_crtc_state->state = state; in drm_atomic_helper_swap_state()
3125 new_crtc_state->state = NULL; in drm_atomic_helper_swap_state()
3127 state->crtcs[i].state = old_crtc_state; in drm_atomic_helper_swap_state()
3128 crtc->state = new_crtc_state; in drm_atomic_helper_swap_state()
3130 if (new_crtc_state->commit) { in drm_atomic_helper_swap_state()
3131 spin_lock(&crtc->commit_lock); in drm_atomic_helper_swap_state()
3132 list_add(&new_crtc_state->commit->commit_entry, in drm_atomic_helper_swap_state()
3133 &crtc->commit_list); in drm_atomic_helper_swap_state()
3134 spin_unlock(&crtc->commit_lock); in drm_atomic_helper_swap_state()
3136 new_crtc_state->commit->event = NULL; in drm_atomic_helper_swap_state()
3140 drm_panic_lock(state->dev, flags); in drm_atomic_helper_swap_state()
3142 WARN_ON(plane->state != old_plane_state); in drm_atomic_helper_swap_state()
3144 old_plane_state->state = state; in drm_atomic_helper_swap_state()
3145 new_plane_state->state = NULL; in drm_atomic_helper_swap_state()
3147 state->planes[i].state = old_plane_state; in drm_atomic_helper_swap_state()
3148 plane->state = new_plane_state; in drm_atomic_helper_swap_state()
3150 drm_panic_unlock(state->dev, flags); in drm_atomic_helper_swap_state()
3153 WARN_ON(obj->state != old_obj_state); in drm_atomic_helper_swap_state()
3155 old_obj_state->state = state; in drm_atomic_helper_swap_state()
3156 new_obj_state->state = NULL; in drm_atomic_helper_swap_state()
3158 state->private_objs[i].state = old_obj_state; in drm_atomic_helper_swap_state()
3159 obj->state = new_obj_state; in drm_atomic_helper_swap_state()
3167 * drm_atomic_helper_update_plane - Helper for primary plane update using atomic
3199 state = drm_atomic_state_alloc(plane->dev); in drm_atomic_helper_update_plane()
3201 return -ENOMEM; in drm_atomic_helper_update_plane()
3203 state->acquire_ctx = ctx; in drm_atomic_helper_update_plane()
3214 plane_state->crtc_x = crtc_x; in drm_atomic_helper_update_plane()
3215 plane_state->crtc_y = crtc_y; in drm_atomic_helper_update_plane()
3216 plane_state->crtc_w = crtc_w; in drm_atomic_helper_update_plane()
3217 plane_state->crtc_h = crtc_h; in drm_atomic_helper_update_plane()
3218 plane_state->src_x = src_x; in drm_atomic_helper_update_plane()
3219 plane_state->src_y = src_y; in drm_atomic_helper_update_plane()
3220 plane_state->src_w = src_w; in drm_atomic_helper_update_plane()
3221 plane_state->src_h = src_h; in drm_atomic_helper_update_plane()
3223 if (plane == crtc->cursor) in drm_atomic_helper_update_plane()
3224 state->legacy_cursor_update = true; in drm_atomic_helper_update_plane()
3234 * drm_atomic_helper_disable_plane - Helper for primary plane disable using atomic
3250 state = drm_atomic_state_alloc(plane->dev); in drm_atomic_helper_disable_plane()
3252 return -ENOMEM; in drm_atomic_helper_disable_plane()
3254 state->acquire_ctx = ctx; in drm_atomic_helper_disable_plane()
3261 if (plane_state->crtc && plane_state->crtc->cursor == plane) in drm_atomic_helper_disable_plane()
3262 plane_state->state->legacy_cursor_update = true; in drm_atomic_helper_disable_plane()
3276 * drm_atomic_helper_set_config - set a new config from userspace
3283 * resets the "link-status" property to GOOD, to force any link
3284 * re-training. The SETCRTC ioctl does not define whether an update does
3295 struct drm_crtc *crtc = set->crtc; in drm_atomic_helper_set_config()
3298 state = drm_atomic_state_alloc(crtc->dev); in drm_atomic_helper_set_config()
3300 return -ENOMEM; in drm_atomic_helper_set_config()
3302 state->acquire_ctx = ctx; in drm_atomic_helper_set_config()
3320 * drm_atomic_helper_disable_all - disable all currently active outputs
3333 * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
3356 return -ENOMEM; in drm_atomic_helper_disable_all()
3358 state->acquire_ctx = ctx; in drm_atomic_helper_disable_all()
3367 crtc_state->active = false; in drm_atomic_helper_disable_all()
3404 * drm_atomic_helper_reset_crtc - reset the active outputs of a CRTC
3414 * a no-op commit, achieving nothing.
3426 state = drm_atomic_state_alloc(crtc->dev); in drm_atomic_helper_reset_crtc()
3428 return -ENOMEM; in drm_atomic_helper_reset_crtc()
3430 state->acquire_ctx = ctx; in drm_atomic_helper_reset_crtc()
3438 crtc_state->connectors_changed = true; in drm_atomic_helper_reset_crtc()
3449 * drm_atomic_helper_shutdown - shutdown all CRTC
3480 * drm_atomic_helper_duplicate_state - duplicate an atomic state object
3494 * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
3498 * ERR_PTR()-encoded error code on failure.
3516 return ERR_PTR(-ENOMEM); in drm_atomic_helper_duplicate_state()
3518 state->acquire_ctx = ctx; in drm_atomic_helper_duplicate_state()
3519 state->duplicated = true; in drm_atomic_helper_duplicate_state()
3555 state->acquire_ctx = NULL; in drm_atomic_helper_duplicate_state()
3568 * drm_atomic_helper_suspend - subsystem-level suspend helper
3583 * A pointer to a copy of the state before suspend on success or an ERR_PTR()-
3599 state = ERR_PTR(-EINVAL); in drm_atomic_helper_suspend()
3624 * drm_atomic_helper_commit_duplicated_state - commit duplicated state
3649 state->acquire_ctx = ctx; in drm_atomic_helper_commit_duplicated_state()
3652 state->planes[i].old_state = plane->state; in drm_atomic_helper_commit_duplicated_state()
3655 state->crtcs[i].old_state = crtc->state; in drm_atomic_helper_commit_duplicated_state()
3658 state->connectors[i].old_state = connector->state; in drm_atomic_helper_commit_duplicated_state()
3662 state->acquire_ctx = NULL; in drm_atomic_helper_commit_duplicated_state()
3669 * drm_atomic_helper_resume - subsystem-level resume helper
3674 * grabs all modeset locks and commits the atomic state object. This can be
3676 * implement suspend/resume for drivers that support atomic mode-setting.
3709 struct drm_plane *plane = crtc->primary; in page_flip_common()
3718 crtc_state->event = event; in page_flip_common()
3719 crtc_state->async_flip = flags & DRM_MODE_PAGE_FLIP_ASYNC; in page_flip_common()
3731 state->allow_modeset = false; in page_flip_common()
3732 if (!crtc_state->active) { in page_flip_common()
3733 drm_dbg_atomic(crtc->dev, in page_flip_common()
3735 crtc->base.id, crtc->name); in page_flip_common()
3736 return -EINVAL; in page_flip_common()
3743 * drm_atomic_helper_page_flip - execute a legacy page flip
3747 * @flags: flip flags for non-vblank sync'ed updates
3765 struct drm_plane *plane = crtc->primary; in drm_atomic_helper_page_flip()
3769 state = drm_atomic_state_alloc(plane->dev); in drm_atomic_helper_page_flip()
3771 return -ENOMEM; in drm_atomic_helper_page_flip()
3773 state->acquire_ctx = ctx; in drm_atomic_helper_page_flip()
3787 * drm_atomic_helper_page_flip_target - do page flip on target vblank period.
3791 * @flags: flip flags for non-vblank sync'ed updates
3809 struct drm_plane *plane = crtc->primary; in drm_atomic_helper_page_flip_target()
3814 state = drm_atomic_state_alloc(plane->dev); in drm_atomic_helper_page_flip_target()
3816 return -ENOMEM; in drm_atomic_helper_page_flip_target()
3818 state->acquire_ctx = ctx; in drm_atomic_helper_page_flip_target()
3826 ret = -EINVAL; in drm_atomic_helper_page_flip_target()
3829 crtc_state->target_vblank = target; in drm_atomic_helper_page_flip_target()
3839 * drm_atomic_helper_bridge_propagate_bus_fmt() - Propagate output format to