hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/drivers/gpu/drm/drm_atomic_helper.c
....@@ -25,13 +25,21 @@
2525 * Daniel Vetter <daniel.vetter@ffwll.ch>
2626 */
2727
28
-#include <drm/drmP.h>
29
-#include <drm/drm_atomic.h>
30
-#include <drm/drm_plane_helper.h>
31
-#include <drm/drm_crtc_helper.h>
32
-#include <drm/drm_atomic_helper.h>
33
-#include <drm/drm_writeback.h>
3428 #include <linux/dma-fence.h>
29
+#include <linux/ktime.h>
30
+
31
+#include <drm/drm_atomic.h>
32
+#include <drm/drm_atomic_helper.h>
33
+#include <drm/drm_atomic_uapi.h>
34
+#include <drm/drm_bridge.h>
35
+#include <drm/drm_damage_helper.h>
36
+#include <drm/drm_device.h>
37
+#include <drm/drm_drv.h>
38
+#include <drm/drm_plane_helper.h>
39
+#include <drm/drm_print.h>
40
+#include <drm/drm_self_refresh_helper.h>
41
+#include <drm/drm_vblank.h>
42
+#include <drm/drm_writeback.h>
3543
3644 #include "drm_crtc_helper_internal.h"
3745 #include "drm_crtc_internal.h"
....@@ -118,7 +126,7 @@
118126 else if (funcs->best_encoder)
119127 new_encoder = funcs->best_encoder(connector);
120128 else
121
- new_encoder = drm_atomic_helper_best_encoder(connector);
129
+ new_encoder = drm_connector_get_single_encoder(connector);
122130
123131 if (new_encoder) {
124132 if (encoder_mask & drm_encoder_mask(new_encoder)) {
....@@ -143,8 +151,8 @@
143151 * is not set, an error is returned. Userspace can provide a solution
144152 * through the atomic ioctl.
145153 *
146
- * If the flag is set conflicting connectors are removed from the crtc
147
- * and the crtc is disabled if no encoder is left. This preserves
154
+ * If the flag is set conflicting connectors are removed from the CRTC
155
+ * and the CRTC is disabled if no encoder is left. This preserves
148156 * compatibility with the legacy set_config behavior.
149157 */
150158 drm_connector_list_iter_begin(state->dev, &conn_iter);
....@@ -213,7 +221,7 @@
213221 crtc = conn_state->connector->state->crtc;
214222
215223 /* A NULL crtc is an error here because we should have
216
- * duplicated a NULL best_encoder when crtc was NULL.
224
+ * duplicated a NULL best_encoder when crtc was NULL.
217225 * As an exception restoring duplicated atomic state
218226 * during resume is allowed, so don't warn when
219227 * best_encoder is equal to encoder we intend to set.
....@@ -288,14 +296,12 @@
288296 if (old_connector_state->crtc != new_connector_state->crtc) {
289297 if (old_connector_state->crtc) {
290298 crtc_state = drm_atomic_get_new_crtc_state(state, old_connector_state->crtc);
291
- if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
292
- crtc_state->connectors_changed = true;
299
+ crtc_state->connectors_changed = true;
293300 }
294301
295302 if (new_connector_state->crtc) {
296303 crtc_state = drm_atomic_get_new_crtc_state(state, new_connector_state->crtc);
297
- if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
298
- crtc_state->connectors_changed = true;
304
+ crtc_state->connectors_changed = true;
299305 }
300306 }
301307
....@@ -320,10 +326,17 @@
320326 * Since the connector can be unregistered at any point during an
321327 * atomic check or commit, this is racy. But that's OK: all we care
322328 * about is ensuring that userspace can't do anything but shut off the
323
- * display on a connector that was destroyed after its been notified,
329
+ * display on a connector that was destroyed after it's been notified,
324330 * not before.
331
+ *
332
+ * Additionally, we also want to ignore connector registration when
333
+ * we're trying to restore an atomic state during system resume since
334
+ * there's a chance the connector may have been destroyed during the
335
+ * process, but it's better to ignore that then cause
336
+ * drm_atomic_helper_resume() to fail.
325337 */
326
- if (drm_connector_is_unregistered(connector) && crtc_state->active) {
338
+ if (!state->duplicated && drm_connector_is_unregistered(connector) &&
339
+ crtc_state->active) {
327340 DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] is not registered\n",
328341 connector->base.id, connector->name);
329342 return -EINVAL;
....@@ -337,7 +350,7 @@
337350 else if (funcs->best_encoder)
338351 new_encoder = funcs->best_encoder(connector);
339352 else
340
- new_encoder = drm_atomic_helper_best_encoder(connector);
353
+ new_encoder = drm_connector_get_single_encoder(connector);
341354
342355 if (!new_encoder) {
343356 DRM_DEBUG_ATOMIC("No suitable encoder found for [CONNECTOR:%d:%s]\n",
....@@ -373,8 +386,7 @@
373386
374387 set_best_encoder(state, new_connector_state, new_encoder);
375388
376
- if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK)
377
- crtc_state->connectors_changed = true;
389
+ crtc_state->connectors_changed = true;
378390
379391 DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] using [ENCODER:%d:%s] on [CRTC:%d:%s]\n",
380392 connector->base.id,
....@@ -408,6 +420,7 @@
408420 for_each_new_connector_in_state(state, connector, new_conn_state, i) {
409421 const struct drm_encoder_helper_funcs *funcs;
410422 struct drm_encoder *encoder;
423
+ struct drm_bridge *bridge;
411424
412425 WARN_ON(!!new_conn_state->best_encoder != !!new_conn_state->crtc);
413426
....@@ -424,11 +437,13 @@
424437 encoder = new_conn_state->best_encoder;
425438 funcs = encoder->helper_private;
426439
427
- ret = drm_bridge_mode_fixup(encoder->bridge, &new_crtc_state->mode,
428
- &new_crtc_state->adjusted_mode);
429
- if (!ret) {
430
- DRM_DEBUG_ATOMIC("Bridge fixup failed\n");
431
- return -EINVAL;
440
+ bridge = drm_bridge_chain_get_first_bridge(encoder);
441
+ ret = drm_atomic_bridge_chain_check(bridge,
442
+ new_crtc_state,
443
+ new_conn_state);
444
+ if (ret) {
445
+ DRM_DEBUG_ATOMIC("Bridge atomic check failed\n");
446
+ return ret;
432447 }
433448
434449 if (funcs && funcs->atomic_check) {
....@@ -461,7 +476,7 @@
461476 continue;
462477
463478 funcs = crtc->helper_private;
464
- if (!funcs->mode_fixup)
479
+ if (!funcs || !funcs->mode_fixup)
465480 continue;
466481
467482 ret = funcs->mode_fixup(crtc, &new_crtc_state->mode,
....@@ -479,8 +494,9 @@
479494 static enum drm_mode_status mode_valid_path(struct drm_connector *connector,
480495 struct drm_encoder *encoder,
481496 struct drm_crtc *crtc,
482
- struct drm_display_mode *mode)
497
+ const struct drm_display_mode *mode)
483498 {
499
+ struct drm_bridge *bridge;
484500 enum drm_mode_status ret;
485501
486502 ret = drm_encoder_mode_valid(encoder, mode);
....@@ -490,7 +506,9 @@
490506 return ret;
491507 }
492508
493
- ret = drm_bridge_mode_valid(encoder->bridge, mode);
509
+ bridge = drm_bridge_chain_get_first_bridge(encoder);
510
+ ret = drm_bridge_chain_mode_valid(bridge, &connector->display_info,
511
+ mode);
494512 if (ret != MODE_OK) {
495513 DRM_DEBUG_ATOMIC("[BRIDGE] mode_valid() failed\n");
496514 return ret;
....@@ -518,7 +536,7 @@
518536 struct drm_crtc *crtc = conn_state->crtc;
519537 struct drm_crtc_state *crtc_state;
520538 enum drm_mode_status mode_status;
521
- struct drm_display_mode *mode;
539
+ const struct drm_display_mode *mode;
522540
523541 if (!crtc || !encoder)
524542 continue;
....@@ -545,28 +563,29 @@
545563 * @state: the driver state object
546564 *
547565 * Check the state object to see if the requested state is physically possible.
548
- * This does all the crtc and connector related computations for an atomic
566
+ * This does all the CRTC and connector related computations for an atomic
549567 * update and adds any additional connectors needed for full modesets. It calls
550568 * the various per-object callbacks in the follow order:
551569 *
552570 * 1. &drm_connector_helper_funcs.atomic_best_encoder for determining the new encoder.
553571 * 2. &drm_connector_helper_funcs.atomic_check to validate the connector state.
554
- * 3. If it's determined a modeset is needed then all connectors on the affected crtc
555
- * crtc are added and &drm_connector_helper_funcs.atomic_check is run on them.
572
+ * 3. If it's determined a modeset is needed then all connectors on the affected
573
+ * CRTC are added and &drm_connector_helper_funcs.atomic_check is run on them.
556574 * 4. &drm_encoder_helper_funcs.mode_valid, &drm_bridge_funcs.mode_valid and
557575 * &drm_crtc_helper_funcs.mode_valid are called on the affected components.
558576 * 5. &drm_bridge_funcs.mode_fixup is called on all encoder bridges.
559577 * 6. &drm_encoder_helper_funcs.atomic_check is called to validate any encoder state.
560
- * This function is only called when the encoder will be part of a configured crtc,
578
+ * This function is only called when the encoder will be part of a configured CRTC,
561579 * it must not be used for implementing connector property validation.
562580 * If this function is NULL, &drm_atomic_encoder_helper_funcs.mode_fixup is called
563581 * instead.
564
- * 7. &drm_crtc_helper_funcs.mode_fixup is called last, to fix up the mode with crtc constraints.
582
+ * 7. &drm_crtc_helper_funcs.mode_fixup is called last, to fix up the mode with CRTC constraints.
565583 *
566584 * &drm_crtc_state.mode_changed is set when the input mode is changed.
567585 * &drm_crtc_state.connectors_changed is set when a connector is added or
568
- * removed from the crtc. &drm_crtc_state.active_changed is set when
586
+ * removed from the CRTC. &drm_crtc_state.active_changed is set when
569587 * &drm_crtc_state.active changes, which is used for DPMS.
588
+ * &drm_crtc_state.no_vblank is set from the result of drm_dev_has_vblank().
570589 * See also: drm_atomic_crtc_needs_modeset()
571590 *
572591 * IMPORTANT:
....@@ -633,6 +652,11 @@
633652
634653 return -EINVAL;
635654 }
655
+
656
+ if (drm_dev_has_vblank(dev))
657
+ new_crtc_state->no_vblank = false;
658
+ else
659
+ new_crtc_state->no_vblank = true;
636660 }
637661
638662 ret = handle_conflicting_encoders(state, false);
....@@ -660,6 +684,10 @@
660684 if (old_connector_state->link_status !=
661685 new_connector_state->link_status)
662686 new_crtc_state->connectors_changed = true;
687
+
688
+ if (old_connector_state->max_requested_bpc !=
689
+ new_connector_state->max_requested_bpc)
690
+ new_crtc_state->connectors_changed = true;
663691 }
664692
665693 if (funcs->atomic_check)
....@@ -672,7 +700,7 @@
672700
673701 /*
674702 * After all the routing has been prepared we need to add in any
675
- * connector which is itself unchanged, but who's crtc changes it's
703
+ * connector which is itself unchanged, but whose CRTC changes its
676704 * configuration. This must be done before calling mode_fixup in case a
677705 * crtc only changed its mode but has the same set of connectors.
678706 */
....@@ -710,6 +738,26 @@
710738 return ret;
711739 }
712740
741
+ /*
742
+ * Iterate over all connectors again, and add all affected bridges to
743
+ * the state.
744
+ */
745
+ for_each_oldnew_connector_in_state(state, connector,
746
+ old_connector_state,
747
+ new_connector_state, i) {
748
+ struct drm_encoder *encoder;
749
+
750
+ encoder = old_connector_state->best_encoder;
751
+ ret = drm_atomic_add_encoder_bridges(state, encoder);
752
+ if (ret)
753
+ return ret;
754
+
755
+ encoder = new_connector_state->best_encoder;
756
+ ret = drm_atomic_add_encoder_bridges(state, encoder);
757
+ if (ret)
758
+ return ret;
759
+ }
760
+
713761 ret = mode_valid(state);
714762 if (ret)
715763 return ret;
....@@ -721,13 +769,13 @@
721769 /**
722770 * drm_atomic_helper_check_plane_state() - Check plane state for validity
723771 * @plane_state: plane state to check
724
- * @crtc_state: crtc state to check
772
+ * @crtc_state: CRTC state to check
725773 * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point
726774 * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point
727775 * @can_position: is it legal to position the plane such that it
728
- * doesn't cover the entire crtc? This will generally
776
+ * doesn't cover the entire CRTC? This will generally
729777 * only be false for primary planes.
730
- * @can_update_disabled: can the plane be updated while the crtc
778
+ * @can_update_disabled: can the plane be updated while the CRTC
731779 * is disabled?
732780 *
733781 * Checks that a desired plane update is valid, and updates various
....@@ -824,7 +872,7 @@
824872 * &drm_crtc_helper_funcs.atomic_check and &drm_plane_helper_funcs.atomic_check
825873 * hooks provided by the driver.
826874 *
827
- * It also sets &drm_crtc_state.planes_changed to indicate that a crtc has
875
+ * It also sets &drm_crtc_state.planes_changed to indicate that a CRTC has
828876 * updated planes.
829877 *
830878 * RETURNS:
....@@ -848,6 +896,8 @@
848896 funcs = plane->helper_private;
849897
850898 drm_atomic_helper_plane_changed(state, old_plane_state, new_plane_state, plane);
899
+
900
+ drm_atomic_helper_check_plane_damage(state, new_plane_state);
851901
852902 if (!funcs || !funcs->atomic_check)
853903 continue;
....@@ -886,7 +936,7 @@
886936 * @state: the driver state object
887937 *
888938 * Check the state object to see if the requested state is physically possible.
889
- * Only crtcs and planes have check callbacks, so for any additional (global)
939
+ * Only CRTCs and planes have check callbacks, so for any additional (global)
890940 * checking that a driver needs it can simply wrap that around this function.
891941 * Drivers without such needs can directly use this as their
892942 * &drm_mode_config_funcs.atomic_check callback.
....@@ -928,9 +978,42 @@
928978 if (state->legacy_cursor_update)
929979 state->async_update = !drm_atomic_helper_async_check(dev, state);
930980
981
+ drm_self_refresh_helper_alter_state(state);
982
+
931983 return ret;
932984 }
933985 EXPORT_SYMBOL(drm_atomic_helper_check);
986
+
987
+static bool
988
+crtc_needs_disable(struct drm_crtc_state *old_state,
989
+ struct drm_crtc_state *new_state)
990
+{
991
+ /*
992
+ * No new_state means the CRTC is off, so the only criteria is whether
993
+ * it's currently active or in self refresh mode.
994
+ */
995
+ if (!new_state)
996
+ return drm_atomic_crtc_effectively_active(old_state);
997
+
998
+ /*
999
+ * We need to disable bridge(s) and CRTC if we're transitioning out of
1000
+ * self-refresh and changing CRTCs at the same time, because the
1001
+ * bridge tracks self-refresh status via CRTC state.
1002
+ */
1003
+ if (old_state->self_refresh_active &&
1004
+ old_state->crtc != new_state->crtc)
1005
+ return true;
1006
+
1007
+ /*
1008
+ * We also need to run through the crtc_funcs->disable() function if
1009
+ * the CRTC is currently on, if it's transitioning to self refresh
1010
+ * mode, or if it's in self refresh mode and needs to be fully
1011
+ * disabled.
1012
+ */
1013
+ return old_state->active ||
1014
+ (old_state->self_refresh_active && !new_state->enable) ||
1015
+ new_state->self_refresh_active;
1016
+}
9341017
9351018 static void
9361019 disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)
....@@ -943,8 +1026,8 @@
9431026
9441027 for_each_oldnew_connector_in_state(old_state, connector, old_conn_state, new_conn_state, i) {
9451028 const struct drm_encoder_helper_funcs *funcs;
946
- const struct drm_connector_helper_funcs *conn_funcs;
9471029 struct drm_encoder *encoder;
1030
+ struct drm_bridge *bridge;
9481031
9491032 /* Shut down everything that's in the changeset and currently
9501033 * still on. So need to check the old, saved state. */
....@@ -953,7 +1036,14 @@
9531036
9541037 old_crtc_state = drm_atomic_get_old_crtc_state(old_state, old_conn_state->crtc);
9551038
956
- if (!old_crtc_state->active ||
1039
+ if (new_conn_state->crtc)
1040
+ new_crtc_state = drm_atomic_get_new_crtc_state(
1041
+ old_state,
1042
+ new_conn_state->crtc);
1043
+ else
1044
+ new_crtc_state = NULL;
1045
+
1046
+ if (!crtc_needs_disable(old_crtc_state, new_crtc_state) ||
9571047 !drm_atomic_crtc_needs_modeset(old_conn_state->crtc->state))
9581048 continue;
9591049
....@@ -970,35 +1060,18 @@
9701060 DRM_DEBUG_ATOMIC("disabling [ENCODER:%d:%s]\n",
9711061 encoder->base.id, encoder->name);
9721062
973
- conn_funcs = connector->helper_private;
974
- if (connector->loader_protect) {
975
- drm_bridge_pre_enable(encoder->bridge);
976
-
977
- if (funcs->enable)
978
- funcs->enable(encoder);
979
- else
980
- funcs->commit(encoder);
981
-
982
- drm_bridge_enable(encoder->bridge);
983
-
984
- if (conn_funcs->loader_protect)
985
- conn_funcs->loader_protect(connector, false);
986
- connector->loader_protect = false;
987
- }
9881063 /*
9891064 * Each encoder has at most one connector (since we always steal
9901065 * it away), so we won't call disable hooks twice.
9911066 */
992
- drm_bridge_disable(encoder->bridge);
1067
+ bridge = drm_bridge_chain_get_first_bridge(encoder);
1068
+ drm_atomic_bridge_chain_disable(bridge, old_state);
9931069
994
- if (encoder->loader_protect) {
995
- if (funcs->loader_protect)
996
- funcs->loader_protect(encoder, false);
997
- encoder->loader_protect = false;
998
- }
9991070 /* Right function depends upon target state. */
10001071 if (funcs) {
1001
- if (new_conn_state->crtc && funcs->prepare)
1072
+ if (funcs->atomic_disable)
1073
+ funcs->atomic_disable(encoder, old_state);
1074
+ else if (new_conn_state->crtc && funcs->prepare)
10021075 funcs->prepare(encoder);
10031076 else if (funcs->disable)
10041077 funcs->disable(encoder);
....@@ -1006,7 +1079,7 @@
10061079 funcs->dpms(encoder, DRM_MODE_DPMS_OFF);
10071080 }
10081081
1009
- drm_bridge_post_disable(encoder->bridge);
1082
+ drm_atomic_bridge_chain_post_disable(bridge, old_state);
10101083 }
10111084
10121085 for_each_oldnew_crtc_in_state(old_state, crtc, old_crtc_state, new_crtc_state, i) {
....@@ -1017,7 +1090,7 @@
10171090 if (!drm_atomic_crtc_needs_modeset(new_crtc_state))
10181091 continue;
10191092
1020
- if (!old_crtc_state->active)
1093
+ if (!crtc_needs_disable(old_crtc_state, new_crtc_state))
10211094 continue;
10221095
10231096 funcs = crtc->helper_private;
....@@ -1033,14 +1106,23 @@
10331106 funcs->atomic_disable(crtc, old_crtc_state);
10341107 else if (funcs->disable)
10351108 funcs->disable(crtc);
1036
- else
1109
+ else if (funcs->dpms)
10371110 funcs->dpms(crtc, DRM_MODE_DPMS_OFF);
10381111
1039
- if (!(dev->irq_enabled && dev->num_crtcs))
1112
+ if (!drm_dev_has_vblank(dev))
10401113 continue;
10411114
10421115 ret = drm_crtc_vblank_get(crtc);
1043
- WARN_ONCE(ret != -EINVAL, "driver forgot to call drm_crtc_vblank_off()\n");
1116
+ /*
1117
+ * Self-refresh is not a true "disable"; ensure vblank remains
1118
+ * enabled.
1119
+ */
1120
+ if (new_crtc_state->self_refresh_active)
1121
+ WARN_ONCE(ret != 0,
1122
+ "driver disabled vblank in self-refresh\n");
1123
+ else
1124
+ WARN_ONCE(ret != -EINVAL,
1125
+ "driver forgot to call drm_crtc_vblank_off()\n");
10441126 if (ret == 0)
10451127 drm_crtc_vblank_put(crtc);
10461128 }
....@@ -1052,9 +1134,7 @@
10521134 * @old_state: atomic state object with old state structures
10531135 *
10541136 * This function updates all the various legacy modeset state pointers in
1055
- * connectors, encoders and crtcs. It also updates the timestamping constants
1056
- * used for precise vblank timestamps by calling
1057
- * drm_calc_timestamping_constants().
1137
+ * connectors, encoders and CRTCs.
10581138 *
10591139 * Drivers can use this for building their own atomic commit if they don't have
10601140 * a pure helper-based modeset implementation.
....@@ -1123,13 +1203,30 @@
11231203 crtc->x = new_plane_state->src_x >> 16;
11241204 crtc->y = new_plane_state->src_y >> 16;
11251205 }
1206
+ }
1207
+}
1208
+EXPORT_SYMBOL(drm_atomic_helper_update_legacy_modeset_state);
11261209
1210
+/**
1211
+ * drm_atomic_helper_calc_timestamping_constants - update vblank timestamping constants
1212
+ * @state: atomic state object
1213
+ *
1214
+ * Updates the timestamping constants used for precise vblank timestamps
1215
+ * by calling drm_calc_timestamping_constants() for all enabled crtcs in @state.
1216
+ */
1217
+void drm_atomic_helper_calc_timestamping_constants(struct drm_atomic_state *state)
1218
+{
1219
+ struct drm_crtc_state *new_crtc_state;
1220
+ struct drm_crtc *crtc;
1221
+ int i;
1222
+
1223
+ for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
11271224 if (new_crtc_state->enable)
11281225 drm_calc_timestamping_constants(crtc,
11291226 &new_crtc_state->adjusted_mode);
11301227 }
11311228 }
1132
-EXPORT_SYMBOL(drm_atomic_helper_update_legacy_modeset_state);
1229
+EXPORT_SYMBOL(drm_atomic_helper_calc_timestamping_constants);
11331230
11341231 static void
11351232 crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state)
....@@ -1160,6 +1257,7 @@
11601257 const struct drm_encoder_helper_funcs *funcs;
11611258 struct drm_encoder *encoder;
11621259 struct drm_display_mode *mode, *adjusted_mode;
1260
+ struct drm_bridge *bridge;
11631261
11641262 if (!new_conn_state->best_encoder)
11651263 continue;
....@@ -1187,7 +1285,8 @@
11871285 funcs->mode_set(encoder, mode, adjusted_mode);
11881286 }
11891287
1190
- drm_bridge_mode_set(encoder->bridge, mode, adjusted_mode);
1288
+ bridge = drm_bridge_chain_get_first_bridge(encoder);
1289
+ drm_bridge_chain_mode_set(bridge, mode, adjusted_mode);
11911290 }
11921291 }
11931292
....@@ -1199,7 +1298,7 @@
11991298 * This function shuts down all the outputs that need to be shut down and
12001299 * prepares them (if required) with the new mode.
12011300 *
1202
- * For compatibility with legacy crtc helpers this should be called before
1301
+ * For compatibility with legacy CRTC helpers this should be called before
12031302 * drm_atomic_helper_commit_planes(), which is what the default commit function
12041303 * does. But drivers with different needs can group the modeset commits together
12051304 * and do the plane commits at the end. This is useful for drivers doing runtime
....@@ -1211,6 +1310,7 @@
12111310 disable_outputs(dev, old_state);
12121311
12131312 drm_atomic_helper_update_legacy_modeset_state(dev, old_state);
1313
+ drm_atomic_helper_calc_timestamping_constants(old_state);
12141314
12151315 crtc_set_mode(dev, old_state);
12161316 }
....@@ -1245,7 +1345,7 @@
12451345 * This function enables all the outputs with the new configuration which had to
12461346 * be turned off for the update.
12471347 *
1248
- * For compatibility with legacy crtc helpers this should be called after
1348
+ * For compatibility with legacy CRTC helpers this should be called after
12491349 * drm_atomic_helper_commit_planes(), which is what the default commit function
12501350 * does. But drivers with different needs can group the modeset commits together
12511351 * and do the plane commits at the end. This is useful for drivers doing runtime
....@@ -1276,10 +1376,9 @@
12761376 if (new_crtc_state->enable) {
12771377 DRM_DEBUG_ATOMIC("enabling [CRTC:%d:%s]\n",
12781378 crtc->base.id, crtc->name);
1279
-
12801379 if (funcs->atomic_enable)
12811380 funcs->atomic_enable(crtc, old_crtc_state);
1282
- else
1381
+ else if (funcs->commit)
12831382 funcs->commit(crtc);
12841383 }
12851384 }
....@@ -1287,6 +1386,7 @@
12871386 for_each_new_connector_in_state(old_state, connector, new_conn_state, i) {
12881387 const struct drm_encoder_helper_funcs *funcs;
12891388 struct drm_encoder *encoder;
1389
+ struct drm_bridge *bridge;
12901390
12911391 if (!new_conn_state->best_encoder)
12921392 continue;
....@@ -1305,16 +1405,19 @@
13051405 * Each encoder has at most one connector (since we always steal
13061406 * it away), so we won't call enable hooks twice.
13071407 */
1308
- drm_bridge_pre_enable(encoder->bridge);
1408
+ bridge = drm_bridge_chain_get_first_bridge(encoder);
1409
+ drm_atomic_bridge_chain_pre_enable(bridge, old_state);
13091410
13101411 if (funcs) {
1311
- if (funcs->enable)
1412
+ if (funcs->atomic_enable)
1413
+ funcs->atomic_enable(encoder, old_state);
1414
+ else if (funcs->enable)
13121415 funcs->enable(encoder);
13131416 else if (funcs->commit)
13141417 funcs->commit(encoder);
13151418 }
13161419
1317
- drm_bridge_enable(encoder->bridge);
1420
+ drm_atomic_bridge_chain_enable(bridge, old_state);
13181421 }
13191422
13201423 drm_atomic_helper_commit_writebacks(dev, old_state);
....@@ -1374,12 +1477,12 @@
13741477 EXPORT_SYMBOL(drm_atomic_helper_wait_for_fences);
13751478
13761479 /**
1377
- * drm_atomic_helper_wait_for_vblanks - wait for vblank on crtcs
1480
+ * drm_atomic_helper_wait_for_vblanks - wait for vblank on CRTCs
13781481 * @dev: DRM device
13791482 * @old_state: atomic state object with old state structures
13801483 *
1381
- * Helper to, after atomic commit, wait for vblanks on all effected
1382
- * crtcs (ie. before cleaning up old framebuffers using
1484
+ * Helper to, after atomic commit, wait for vblanks on all affected
1485
+ * CRTCs (ie. before cleaning up old framebuffers using
13831486 * drm_atomic_helper_cleanup_planes()). It will only wait on CRTCs where the
13841487 * framebuffers have actually changed to optimize for the legacy cursor and
13851488 * plane update use-case.
....@@ -1423,7 +1526,7 @@
14231526 ret = wait_event_timeout(dev->vblank[i].queue,
14241527 old_state->crtcs[i].last_vblank_count !=
14251528 drm_crtc_vblank_count(crtc),
1426
- msecs_to_jiffies(50));
1529
+ msecs_to_jiffies(100));
14271530
14281531 WARN(!ret, "[CRTC:%d:%s] vblank wait timed out\n",
14291532 crtc->base.id, crtc->name);
....@@ -1438,10 +1541,10 @@
14381541 * @dev: DRM device
14391542 * @old_state: atomic state object with old state structures
14401543 *
1441
- * Helper to, after atomic commit, wait for page flips on all effected
1544
+ * Helper to, after atomic commit, wait for page flips on all affected
14421545 * crtcs (ie. before cleaning up old framebuffers using
14431546 * drm_atomic_helper_cleanup_planes()). Compared to
1444
- * drm_atomic_helper_wait_for_vblanks() this waits for the completion of on all
1547
+ * drm_atomic_helper_wait_for_vblanks() this waits for the completion on all
14451548 * CRTCs, assuming that cursors-only updates are signalling their completion
14461549 * immediately (or using a different path).
14471550 *
....@@ -1542,17 +1645,49 @@
15421645 {
15431646 struct drm_device *dev = old_state->dev;
15441647 const struct drm_mode_config_helper_funcs *funcs;
1648
+ struct drm_crtc_state *new_crtc_state;
1649
+ struct drm_crtc *crtc;
1650
+ ktime_t start;
1651
+ s64 commit_time_ms;
1652
+ unsigned int i, new_self_refresh_mask = 0;
15451653
15461654 funcs = dev->mode_config.helper_private;
1655
+
1656
+ /*
1657
+ * We're measuring the _entire_ commit, so the time will vary depending
1658
+ * on how many fences and objects are involved. For the purposes of self
1659
+ * refresh, this is desirable since it'll give us an idea of how
1660
+ * congested things are. This will inform our decision on how often we
1661
+ * should enter self refresh after idle.
1662
+ *
1663
+ * These times will be averaged out in the self refresh helpers to avoid
1664
+ * overreacting over one outlier frame
1665
+ */
1666
+ start = ktime_get();
15471667
15481668 drm_atomic_helper_wait_for_fences(dev, old_state, false);
15491669
15501670 drm_atomic_helper_wait_for_dependencies(old_state);
15511671
1672
+ /*
1673
+ * We cannot safely access new_crtc_state after
1674
+ * drm_atomic_helper_commit_hw_done() so figure out which crtc's have
1675
+ * self-refresh active beforehand:
1676
+ */
1677
+ for_each_new_crtc_in_state(old_state, crtc, new_crtc_state, i)
1678
+ if (new_crtc_state->self_refresh_active)
1679
+ new_self_refresh_mask |= BIT(i);
1680
+
15521681 if (funcs && funcs->atomic_commit_tail)
15531682 funcs->atomic_commit_tail(old_state);
15541683 else
15551684 drm_atomic_helper_commit_tail(old_state);
1685
+
1686
+ commit_time_ms = ktime_ms_delta(ktime_get(), start);
1687
+ if (commit_time_ms > 0)
1688
+ drm_self_refresh_helper_update_avg_times(old_state,
1689
+ (unsigned long)commit_time_ms,
1690
+ new_self_refresh_mask);
15561691
15571692 drm_atomic_helper_commit_cleanup_done(old_state);
15581693
....@@ -1605,15 +1740,6 @@
16051740
16061741 if (!new_plane_state->crtc ||
16071742 old_plane_state->crtc != new_plane_state->crtc)
1608
- return -EINVAL;
1609
-
1610
- /*
1611
- * FIXME: Since prepare_fb and cleanup_fb are always called on
1612
- * the new_plane_state for async updates we need to block framebuffer
1613
- * changes. This prevents use of a fb that's been cleaned up and
1614
- * double cleanups from occuring.
1615
- */
1616
- if (old_plane_state->fb != new_plane_state->fb)
16171743 return -EINVAL;
16181744
16191745 funcs = plane->helper_private;
....@@ -1696,7 +1822,7 @@
16961822 * drm_atomic_helper_setup_commit() and related functions.
16971823 *
16981824 * Committing the actual hardware state is done through the
1699
- * &drm_mode_config_helper_funcs.atomic_commit_tail callback, or it's default
1825
+ * &drm_mode_config_helper_funcs.atomic_commit_tail callback, or its default
17001826 * implementation drm_atomic_helper_commit_tail().
17011827 *
17021828 * RETURNS:
....@@ -1762,7 +1888,7 @@
17621888 *
17631889 * NOTE: Commit work has multiple phases, first hardware commit, then
17641890 * cleanup. We want them to overlap, hence need system_unbound_wq to
1765
- * make sure work items don't artifically stall on each another.
1891
+ * make sure work items don't artificially stall on each another.
17661892 */
17671893
17681894 drm_atomic_state_get(state);
....@@ -1782,42 +1908,54 @@
17821908 /**
17831909 * DOC: implementing nonblocking commit
17841910 *
1785
- * Nonblocking atomic commits have to be implemented in the following sequence:
1911
+ * Nonblocking atomic commits should use struct &drm_crtc_commit to sequence
1912
+ * different operations against each another. Locks, especially struct
1913
+ * &drm_modeset_lock, should not be held in worker threads or any other
1914
+ * asynchronous context used to commit the hardware state.
17861915 *
1787
- * 1. Run drm_atomic_helper_prepare_planes() first. This is the only function
1788
- * which commit needs to call which can fail, so we want to run it first and
1916
+ * drm_atomic_helper_commit() implements the recommended sequence for
1917
+ * nonblocking commits, using drm_atomic_helper_setup_commit() internally:
1918
+ *
1919
+ * 1. Run drm_atomic_helper_prepare_planes(). Since this can fail and we
1920
+ * need to propagate out of memory/VRAM errors to userspace, it must be called
17891921 * synchronously.
17901922 *
17911923 * 2. Synchronize with any outstanding nonblocking commit worker threads which
1792
- * might be affected the new state update. This can be done by either cancelling
1793
- * or flushing the work items, depending upon whether the driver can deal with
1794
- * cancelled updates. Note that it is important to ensure that the framebuffer
1795
- * cleanup is still done when cancelling.
1924
+ * might be affected by the new state update. This is handled by
1925
+ * drm_atomic_helper_setup_commit().
17961926 *
17971927 * Asynchronous workers need to have sufficient parallelism to be able to run
17981928 * different atomic commits on different CRTCs in parallel. The simplest way to
1799
- * achive this is by running them on the &system_unbound_wq work queue. Note
1929
+ * achieve this is by running them on the &system_unbound_wq work queue. Note
18001930 * that drivers are not required to split up atomic commits and run an
18011931 * individual commit in parallel - userspace is supposed to do that if it cares.
18021932 * But it might be beneficial to do that for modesets, since those necessarily
18031933 * must be done as one global operation, and enabling or disabling a CRTC can
18041934 * take a long time. But even that is not required.
18051935 *
1936
+ * IMPORTANT: A &drm_atomic_state update for multiple CRTCs is sequenced
1937
+ * against all CRTCs therein. Therefore for atomic state updates which only flip
1938
+ * planes the driver must not get the struct &drm_crtc_state of unrelated CRTCs
1939
+ * in its atomic check code: This would prevent committing of atomic updates to
1940
+ * multiple CRTCs in parallel. In general, adding additional state structures
1941
+ * should be avoided as much as possible, because this reduces parallelism in
1942
+ * (nonblocking) commits, both due to locking and due to commit sequencing
1943
+ * requirements.
1944
+ *
18061945 * 3. The software state is updated synchronously with
18071946 * drm_atomic_helper_swap_state(). Doing this under the protection of all modeset
1808
- * locks means concurrent callers never see inconsistent state. And doing this
1809
- * while it's guaranteed that no relevant nonblocking worker runs means that
1810
- * nonblocking workers do not need grab any locks. Actually they must not grab
1811
- * locks, for otherwise the work flushing will deadlock.
1947
+ * locks means concurrent callers never see inconsistent state. Note that commit
1948
+ * workers do not hold any locks; their access is only coordinated through
1949
+ * ordering. If workers would access state only through the pointers in the
1950
+ * free-standing state objects (currently not the case for any driver) then even
1951
+ * multiple pending commits could be in-flight at the same time.
18121952 *
18131953 * 4. Schedule a work item to do all subsequent steps, using the split-out
18141954 * commit helpers: a) pre-plane commit b) plane commit c) post-plane commit and
18151955 * then cleaning up the framebuffers after the old framebuffer is no longer
1816
- * being displayed.
1817
- *
1818
- * The above scheme is implemented in the atomic helper libraries in
1819
- * drm_atomic_helper_commit() using a bunch of helper functions. See
1820
- * drm_atomic_helper_setup_commit() for a starting point.
1956
+ * being displayed. The scheduled work should synchronize against other workers
1957
+ * using the &drm_crtc_commit infrastructure as needed. See
1958
+ * drm_atomic_helper_setup_commit() for more details.
18211959 */
18221960
18231961 static int stall_checks(struct drm_crtc *crtc, bool nonblock)
....@@ -1919,7 +2057,7 @@
19192057 * functions. drm_atomic_helper_wait_for_dependencies() must be called before
19202058 * actually committing the hardware state, and for nonblocking commits this call
19212059 * must be placed in the async worker. See also drm_atomic_helper_swap_state()
1922
- * and it's stall parameter, for when a driver's commit hooks look at the
2060
+ * and its stall parameter, for when a driver's commit hooks look at the
19232061 * &drm_crtc.state, &drm_plane.state or &drm_connector.state pointer directly.
19242062 *
19252063 * Completion of the hardware commit step must be signalled using
....@@ -2046,7 +2184,7 @@
20462184 *
20472185 * This function waits for all preceeding commits that touch the same CRTC as
20482186 * @old_state to both be committed to the hardware (as signalled by
2049
- * drm_atomic_helper_commit_hw_done) and executed by the hardware (as signalled
2187
+ * drm_atomic_helper_commit_hw_done()) and executed by the hardware (as signalled
20502188 * by calling drm_crtc_send_vblank_event() on the &drm_crtc_state.event).
20512189 *
20522190 * This is part of the atomic helper support for nonblocking commits, see
....@@ -2133,14 +2271,16 @@
21332271 * drm_atomic_helper_fake_vblank - fake VBLANK events if needed
21342272 * @old_state: atomic state object with old state structures
21352273 *
2136
- * This function walks all CRTCs and fake VBLANK events on those with
2274
+ * This function walks all CRTCs and fakes VBLANK events on those with
21372275 * &drm_crtc_state.no_vblank set to true and &drm_crtc_state.event != NULL.
21382276 * The primary use of this function is writeback connectors working in oneshot
21392277 * mode and faking VBLANK events. In this case they only fake the VBLANK event
21402278 * when a job is queued, and any change to the pipeline that does not touch the
21412279 * connector is leading to timeouts when calling
21422280 * drm_atomic_helper_wait_for_vblanks() or
2143
- * drm_atomic_helper_wait_for_flip_done().
2281
+ * drm_atomic_helper_wait_for_flip_done(). In addition to writeback
2282
+ * connectors, this function can also fake VBLANK events for CRTCs without
2283
+ * VBLANK interrupt.
21442284 *
21452285 * This is part of the atomic helper support for nonblocking commits, see
21462286 * drm_atomic_helper_setup_commit() for an overview.
....@@ -2248,8 +2388,10 @@
22482388 spin_unlock(&crtc->commit_lock);
22492389 }
22502390
2251
- if (old_state->fake_commit)
2391
+ if (old_state->fake_commit) {
22522392 complete_all(&old_state->fake_commit->cleanup_done);
2393
+ WARN_ON(!try_wait_for_completion(&old_state->fake_commit->hw_done));
2394
+ }
22532395 }
22542396 EXPORT_SYMBOL(drm_atomic_helper_commit_cleanup_done);
22552397
....@@ -2269,9 +2411,20 @@
22692411 int drm_atomic_helper_prepare_planes(struct drm_device *dev,
22702412 struct drm_atomic_state *state)
22712413 {
2414
+ struct drm_connector *connector;
2415
+ struct drm_connector_state *new_conn_state;
22722416 struct drm_plane *plane;
22732417 struct drm_plane_state *new_plane_state;
22742418 int ret, i, j;
2419
+
2420
+ for_each_new_connector_in_state(state, connector, new_conn_state, i) {
2421
+ if (!new_conn_state->writeback_job)
2422
+ continue;
2423
+
2424
+ ret = drm_writeback_prepare_job(new_conn_state->writeback_job);
2425
+ if (ret < 0)
2426
+ return ret;
2427
+ }
22752428
22762429 for_each_new_plane_in_state(state, plane, new_plane_state, i) {
22772430 const struct drm_plane_helper_funcs *funcs;
....@@ -2316,7 +2469,7 @@
23162469 * @flags: flags for committing plane state
23172470 *
23182471 * This function commits the new plane state using the plane and atomic helper
2319
- * functions for planes and crtcs. It assumes that the atomic state has already
2472
+ * functions for planes and CRTCs. It assumes that the atomic state has already
23202473 * been pushed into the relevant object state pointers, since this step can no
23212474 * longer fail.
23222475 *
....@@ -2437,15 +2590,15 @@
24372590 EXPORT_SYMBOL(drm_atomic_helper_commit_planes);
24382591
24392592 /**
2440
- * drm_atomic_helper_commit_planes_on_crtc - commit plane state for a crtc
2441
- * @old_crtc_state: atomic state object with the old crtc state
2593
+ * drm_atomic_helper_commit_planes_on_crtc - commit plane state for a CRTC
2594
+ * @old_crtc_state: atomic state object with the old CRTC state
24422595 *
24432596 * This function commits the new plane state using the plane and atomic helper
2444
- * functions for planes on the specific crtc. It assumes that the atomic state
2597
+ * functions for planes on the specific CRTC. It assumes that the atomic state
24452598 * has already been pushed into the relevant object state pointers, since this
24462599 * step can no longer fail.
24472600 *
2448
- * This function is useful when plane updates should be done crtc-by-crtc
2601
+ * This function is useful when plane updates should be done CRTC-by-CRTC
24492602 * instead of one global step like drm_atomic_helper_commit_planes() does.
24502603 *
24512604 * This function can only be savely used when planes are not allowed to move
....@@ -2735,10 +2888,10 @@
27352888 * @plane: plane object to update
27362889 * @crtc: owning CRTC of owning plane
27372890 * @fb: framebuffer to flip onto plane
2738
- * @crtc_x: x offset of primary plane on crtc
2739
- * @crtc_y: y offset of primary plane on crtc
2740
- * @crtc_w: width of primary plane rectangle on crtc
2741
- * @crtc_h: height of primary plane rectangle on crtc
2891
+ * @crtc_x: x offset of primary plane on @crtc
2892
+ * @crtc_y: y offset of primary plane on @crtc
2893
+ * @crtc_w: width of primary plane rectangle on @crtc
2894
+ * @crtc_h: height of primary plane rectangle on @crtc
27422895 * @src_x: x offset of @fb for panning
27432896 * @src_y: y offset of @fb for panning
27442897 * @src_w: width of source rectangle in @fb
....@@ -2839,102 +2992,12 @@
28392992 }
28402993 EXPORT_SYMBOL(drm_atomic_helper_disable_plane);
28412994
2842
-/* just used from fb-helper and atomic-helper: */
2843
-int __drm_atomic_helper_disable_plane(struct drm_plane *plane,
2844
- struct drm_plane_state *plane_state)
2845
-{
2846
- int ret;
2847
-
2848
- ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
2849
- if (ret != 0)
2850
- return ret;
2851
-
2852
- drm_atomic_set_fb_for_plane(plane_state, NULL);
2853
- plane_state->crtc_x = 0;
2854
- plane_state->crtc_y = 0;
2855
- plane_state->crtc_w = 0;
2856
- plane_state->crtc_h = 0;
2857
- plane_state->src_x = 0;
2858
- plane_state->src_y = 0;
2859
- plane_state->src_w = 0;
2860
- plane_state->src_h = 0;
2861
-
2862
- return 0;
2863
-}
2864
-EXPORT_SYMBOL_GPL(__drm_atomic_helper_disable_plane);
2865
-
2866
-static int update_output_state(struct drm_atomic_state *state,
2867
- struct drm_mode_set *set)
2868
-{
2869
- struct drm_device *dev = set->crtc->dev;
2870
- struct drm_crtc *crtc;
2871
- struct drm_crtc_state *new_crtc_state;
2872
- struct drm_connector *connector;
2873
- struct drm_connector_state *new_conn_state;
2874
- int ret, i;
2875
-
2876
- ret = drm_modeset_lock(&dev->mode_config.connection_mutex,
2877
- state->acquire_ctx);
2878
- if (ret)
2879
- return ret;
2880
-
2881
- /* First disable all connectors on the target crtc. */
2882
- ret = drm_atomic_add_affected_connectors(state, set->crtc);
2883
- if (ret)
2884
- return ret;
2885
-
2886
- for_each_new_connector_in_state(state, connector, new_conn_state, i) {
2887
- if (new_conn_state->crtc == set->crtc) {
2888
- ret = drm_atomic_set_crtc_for_connector(new_conn_state,
2889
- NULL);
2890
- if (ret)
2891
- return ret;
2892
-
2893
- /* Make sure legacy setCrtc always re-trains */
2894
- new_conn_state->link_status = DRM_LINK_STATUS_GOOD;
2895
- }
2896
- }
2897
-
2898
- /* Then set all connectors from set->connectors on the target crtc */
2899
- for (i = 0; i < set->num_connectors; i++) {
2900
- new_conn_state = drm_atomic_get_connector_state(state,
2901
- set->connectors[i]);
2902
- if (IS_ERR(new_conn_state))
2903
- return PTR_ERR(new_conn_state);
2904
-
2905
- ret = drm_atomic_set_crtc_for_connector(new_conn_state,
2906
- set->crtc);
2907
- if (ret)
2908
- return ret;
2909
- }
2910
-
2911
- for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) {
2912
- /* Don't update ->enable for the CRTC in the set_config request,
2913
- * since a mismatch would indicate a bug in the upper layers.
2914
- * The actual modeset code later on will catch any
2915
- * inconsistencies here. */
2916
- if (crtc == set->crtc)
2917
- continue;
2918
-
2919
- if (!new_crtc_state->connector_mask) {
2920
- ret = drm_atomic_set_mode_prop_for_crtc(new_crtc_state,
2921
- NULL);
2922
- if (ret < 0)
2923
- return ret;
2924
-
2925
- new_crtc_state->active = false;
2926
- }
2927
- }
2928
-
2929
- return 0;
2930
-}
2931
-
29322995 /**
29332996 * drm_atomic_helper_set_config - set a new config from userspace
29342997 * @set: mode set configuration
29352998 * @ctx: lock acquisition context
29362999 *
2937
- * Provides a default crtc set_config handler using the atomic driver interface.
3000
+ * Provides a default CRTC set_config handler using the atomic driver interface.
29383001 *
29393002 * NOTE: For backwards compatibility with old userspace this automatically
29403003 * resets the "link-status" property to GOOD, to force any link
....@@ -2973,85 +3036,31 @@
29733036 }
29743037 EXPORT_SYMBOL(drm_atomic_helper_set_config);
29753038
2976
-/* just used from fb-helper and atomic-helper: */
2977
-int __drm_atomic_helper_set_config(struct drm_mode_set *set,
2978
- struct drm_atomic_state *state)
2979
-{
2980
- struct drm_crtc_state *crtc_state;
2981
- struct drm_plane_state *primary_state;
2982
- struct drm_crtc *crtc = set->crtc;
2983
- int hdisplay, vdisplay;
2984
- int ret;
2985
-
2986
- crtc_state = drm_atomic_get_crtc_state(state, crtc);
2987
- if (IS_ERR(crtc_state))
2988
- return PTR_ERR(crtc_state);
2989
-
2990
- primary_state = drm_atomic_get_plane_state(state, crtc->primary);
2991
- if (IS_ERR(primary_state))
2992
- return PTR_ERR(primary_state);
2993
-
2994
- if (!set->mode) {
2995
- WARN_ON(set->fb);
2996
- WARN_ON(set->num_connectors);
2997
-
2998
- ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL);
2999
- if (ret != 0)
3000
- return ret;
3001
-
3002
- crtc_state->active = false;
3003
-
3004
- ret = drm_atomic_set_crtc_for_plane(primary_state, NULL);
3005
- if (ret != 0)
3006
- return ret;
3007
-
3008
- drm_atomic_set_fb_for_plane(primary_state, NULL);
3009
-
3010
- goto commit;
3011
- }
3012
-
3013
- WARN_ON(!set->fb);
3014
- WARN_ON(!set->num_connectors);
3015
-
3016
- ret = drm_atomic_set_mode_for_crtc(crtc_state, set->mode);
3017
- if (ret != 0)
3018
- return ret;
3019
-
3020
- crtc_state->active = true;
3021
-
3022
- ret = drm_atomic_set_crtc_for_plane(primary_state, crtc);
3023
- if (ret != 0)
3024
- return ret;
3025
-
3026
- drm_mode_get_hv_timing(set->mode, &hdisplay, &vdisplay);
3027
-
3028
- drm_atomic_set_fb_for_plane(primary_state, set->fb);
3029
- primary_state->crtc_x = 0;
3030
- primary_state->crtc_y = 0;
3031
- primary_state->crtc_w = hdisplay;
3032
- primary_state->crtc_h = vdisplay;
3033
- primary_state->src_x = set->x << 16;
3034
- primary_state->src_y = set->y << 16;
3035
- if (drm_rotation_90_or_270(primary_state->rotation)) {
3036
- primary_state->src_w = vdisplay << 16;
3037
- primary_state->src_h = hdisplay << 16;
3038
- } else {
3039
- primary_state->src_w = hdisplay << 16;
3040
- primary_state->src_h = vdisplay << 16;
3041
- }
3042
-
3043
-commit:
3044
- ret = update_output_state(state, set);
3045
- if (ret)
3046
- return ret;
3047
-
3048
- return 0;
3049
-}
3050
-EXPORT_SYMBOL_GPL(__drm_atomic_helper_set_config);
3051
-
3052
-static int __drm_atomic_helper_disable_all(struct drm_device *dev,
3053
- struct drm_modeset_acquire_ctx *ctx,
3054
- bool clean_old_fbs)
3039
+/**
3040
+ * drm_atomic_helper_disable_all - disable all currently active outputs
3041
+ * @dev: DRM device
3042
+ * @ctx: lock acquisition context
3043
+ *
3044
+ * Loops through all connectors, finding those that aren't turned off and then
3045
+ * turns them off by setting their DPMS mode to OFF and deactivating the CRTC
3046
+ * that they are connected to.
3047
+ *
3048
+ * This is used for example in suspend/resume to disable all currently active
3049
+ * functions when suspending. If you just want to shut down everything at e.g.
3050
+ * driver unload, look at drm_atomic_helper_shutdown().
3051
+ *
3052
+ * Note that if callers haven't already acquired all modeset locks this might
3053
+ * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
3054
+ *
3055
+ * Returns:
3056
+ * 0 on success or a negative error code on failure.
3057
+ *
3058
+ * See also:
3059
+ * drm_atomic_helper_suspend(), drm_atomic_helper_resume() and
3060
+ * drm_atomic_helper_shutdown().
3061
+ */
3062
+int drm_atomic_helper_disable_all(struct drm_device *dev,
3063
+ struct drm_modeset_acquire_ctx *ctx)
30553064 {
30563065 struct drm_atomic_state *state;
30573066 struct drm_connector_state *conn_state;
....@@ -3109,35 +3118,6 @@
31093118 drm_atomic_state_put(state);
31103119 return ret;
31113120 }
3112
-
3113
-/**
3114
- * drm_atomic_helper_disable_all - disable all currently active outputs
3115
- * @dev: DRM device
3116
- * @ctx: lock acquisition context
3117
- *
3118
- * Loops through all connectors, finding those that aren't turned off and then
3119
- * turns them off by setting their DPMS mode to OFF and deactivating the CRTC
3120
- * that they are connected to.
3121
- *
3122
- * This is used for example in suspend/resume to disable all currently active
3123
- * functions when suspending. If you just want to shut down everything at e.g.
3124
- * driver unload, look at drm_atomic_helper_shutdown().
3125
- *
3126
- * Note that if callers haven't already acquired all modeset locks this might
3127
- * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
3128
- *
3129
- * Returns:
3130
- * 0 on success or a negative error code on failure.
3131
- *
3132
- * See also:
3133
- * drm_atomic_helper_suspend(), drm_atomic_helper_resume() and
3134
- * drm_atomic_helper_shutdown().
3135
- */
3136
-int drm_atomic_helper_disable_all(struct drm_device *dev,
3137
- struct drm_modeset_acquire_ctx *ctx)
3138
-{
3139
- return __drm_atomic_helper_disable_all(dev, ctx, false);
3140
-}
31413121 EXPORT_SYMBOL(drm_atomic_helper_disable_all);
31423122
31433123 /**
....@@ -3156,25 +3136,103 @@
31563136 struct drm_modeset_acquire_ctx ctx;
31573137 int ret;
31583138
3159
- drm_modeset_acquire_init(&ctx, 0);
3160
- while (1) {
3161
- ret = drm_modeset_lock_all_ctx(dev, &ctx);
3162
- if (!ret)
3163
- ret = __drm_atomic_helper_disable_all(dev, &ctx, true);
3139
+ DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret);
31643140
3165
- if (ret != -EDEADLK)
3166
- break;
3167
-
3168
- drm_modeset_backoff(&ctx);
3169
- }
3170
-
3141
+ ret = drm_atomic_helper_disable_all(dev, &ctx);
31713142 if (ret)
31723143 DRM_ERROR("Disabling all crtc's during unload failed with %i\n", ret);
31733144
3174
- drm_modeset_drop_locks(&ctx);
3175
- drm_modeset_acquire_fini(&ctx);
3145
+ DRM_MODESET_LOCK_ALL_END(dev, ctx, ret);
31763146 }
31773147 EXPORT_SYMBOL(drm_atomic_helper_shutdown);
3148
+
3149
+/**
3150
+ * drm_atomic_helper_duplicate_state - duplicate an atomic state object
3151
+ * @dev: DRM device
3152
+ * @ctx: lock acquisition context
3153
+ *
3154
+ * Makes a copy of the current atomic state by looping over all objects and
3155
+ * duplicating their respective states. This is used for example by suspend/
3156
+ * resume support code to save the state prior to suspend such that it can
3157
+ * be restored upon resume.
3158
+ *
3159
+ * Note that this treats atomic state as persistent between save and restore.
3160
+ * Drivers must make sure that this is possible and won't result in confusion
3161
+ * or erroneous behaviour.
3162
+ *
3163
+ * Note that if callers haven't already acquired all modeset locks this might
3164
+ * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
3165
+ *
3166
+ * Returns:
3167
+ * A pointer to the copy of the atomic state object on success or an
3168
+ * ERR_PTR()-encoded error code on failure.
3169
+ *
3170
+ * See also:
3171
+ * drm_atomic_helper_suspend(), drm_atomic_helper_resume()
3172
+ */
3173
+struct drm_atomic_state *
3174
+drm_atomic_helper_duplicate_state(struct drm_device *dev,
3175
+ struct drm_modeset_acquire_ctx *ctx)
3176
+{
3177
+ struct drm_atomic_state *state;
3178
+ struct drm_connector *conn;
3179
+ struct drm_connector_list_iter conn_iter;
3180
+ struct drm_plane *plane;
3181
+ struct drm_crtc *crtc;
3182
+ int err = 0;
3183
+
3184
+ state = drm_atomic_state_alloc(dev);
3185
+ if (!state)
3186
+ return ERR_PTR(-ENOMEM);
3187
+
3188
+ state->acquire_ctx = ctx;
3189
+ state->duplicated = true;
3190
+
3191
+ drm_for_each_crtc(crtc, dev) {
3192
+ struct drm_crtc_state *crtc_state;
3193
+
3194
+ crtc_state = drm_atomic_get_crtc_state(state, crtc);
3195
+ if (IS_ERR(crtc_state)) {
3196
+ err = PTR_ERR(crtc_state);
3197
+ goto free;
3198
+ }
3199
+ }
3200
+
3201
+ drm_for_each_plane(plane, dev) {
3202
+ struct drm_plane_state *plane_state;
3203
+
3204
+ plane_state = drm_atomic_get_plane_state(state, plane);
3205
+ if (IS_ERR(plane_state)) {
3206
+ err = PTR_ERR(plane_state);
3207
+ goto free;
3208
+ }
3209
+ }
3210
+
3211
+ drm_connector_list_iter_begin(dev, &conn_iter);
3212
+ drm_for_each_connector_iter(conn, &conn_iter) {
3213
+ struct drm_connector_state *conn_state;
3214
+
3215
+ conn_state = drm_atomic_get_connector_state(state, conn);
3216
+ if (IS_ERR(conn_state)) {
3217
+ err = PTR_ERR(conn_state);
3218
+ drm_connector_list_iter_end(&conn_iter);
3219
+ goto free;
3220
+ }
3221
+ }
3222
+ drm_connector_list_iter_end(&conn_iter);
3223
+
3224
+ /* clear the acquire context so that it isn't accidentally reused */
3225
+ state->acquire_ctx = NULL;
3226
+
3227
+free:
3228
+ if (err < 0) {
3229
+ drm_atomic_state_put(state);
3230
+ state = ERR_PTR(err);
3231
+ }
3232
+
3233
+ return state;
3234
+}
3235
+EXPORT_SYMBOL(drm_atomic_helper_duplicate_state);
31783236
31793237 /**
31803238 * drm_atomic_helper_suspend - subsystem-level suspend helper
....@@ -3207,14 +3265,10 @@
32073265 struct drm_atomic_state *state;
32083266 int err;
32093267
3210
- drm_modeset_acquire_init(&ctx, 0);
3268
+ /* This can never be returned, but it makes the compiler happy */
3269
+ state = ERR_PTR(-EINVAL);
32113270
3212
-retry:
3213
- err = drm_modeset_lock_all_ctx(dev, &ctx);
3214
- if (err < 0) {
3215
- state = ERR_PTR(err);
3216
- goto unlock;
3217
- }
3271
+ DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, err);
32183272
32193273 state = drm_atomic_helper_duplicate_state(dev, &ctx);
32203274 if (IS_ERR(state))
....@@ -3228,13 +3282,10 @@
32283282 }
32293283
32303284 unlock:
3231
- if (PTR_ERR(state) == -EDEADLK) {
3232
- drm_modeset_backoff(&ctx);
3233
- goto retry;
3234
- }
3285
+ DRM_MODESET_LOCK_ALL_END(dev, ctx, err);
3286
+ if (err)
3287
+ return ERR_PTR(err);
32353288
3236
- drm_modeset_drop_locks(&ctx);
3237
- drm_modeset_acquire_fini(&ctx);
32383289 return state;
32393290 }
32403291 EXPORT_SYMBOL(drm_atomic_helper_suspend);
....@@ -3308,23 +3359,12 @@
33083359
33093360 drm_mode_config_reset(dev);
33103361
3311
- drm_modeset_acquire_init(&ctx, 0);
3312
- while (1) {
3313
- err = drm_modeset_lock_all_ctx(dev, &ctx);
3314
- if (err)
3315
- goto out;
3362
+ DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, err);
33163363
3317
- err = drm_atomic_helper_commit_duplicated_state(state, &ctx);
3318
-out:
3319
- if (err != -EDEADLK)
3320
- break;
3364
+ err = drm_atomic_helper_commit_duplicated_state(state, &ctx);
33213365
3322
- drm_modeset_backoff(&ctx);
3323
- }
3324
-
3366
+ DRM_MODESET_LOCK_ALL_END(dev, ctx, err);
33253367 drm_atomic_state_put(state);
3326
- drm_modeset_drop_locks(&ctx);
3327
- drm_modeset_acquire_fini(&ctx);
33283368
33293369 return err;
33303370 }
....@@ -3346,7 +3386,7 @@
33463386 return PTR_ERR(crtc_state);
33473387
33483388 crtc_state->event = event;
3349
- crtc_state->pageflip_flags = flags;
3389
+ crtc_state->async_flip = flags & DRM_MODE_PAGE_FLIP_ASYNC;
33503390
33513391 plane_state = drm_atomic_get_plane_state(state, plane);
33523392 if (IS_ERR(plane_state))
....@@ -3370,7 +3410,7 @@
33703410
33713411 /**
33723412 * drm_atomic_helper_page_flip - execute a legacy page flip
3373
- * @crtc: DRM crtc
3413
+ * @crtc: DRM CRTC
33743414 * @fb: DRM framebuffer
33753415 * @event: optional DRM event to signal upon completion
33763416 * @flags: flip flags for non-vblank sync'ed updates
....@@ -3414,7 +3454,7 @@
34143454
34153455 /**
34163456 * drm_atomic_helper_page_flip_target - do page flip on target vblank period.
3417
- * @crtc: DRM crtc
3457
+ * @crtc: DRM CRTC
34183458 * @fb: DRM framebuffer
34193459 * @event: optional DRM event to signal upon completion
34203460 * @flags: flip flags for non-vblank sync'ed updates
....@@ -3463,498 +3503,6 @@
34633503 return ret;
34643504 }
34653505 EXPORT_SYMBOL(drm_atomic_helper_page_flip_target);
3466
-
3467
-/**
3468
- * drm_atomic_helper_best_encoder - Helper for
3469
- * &drm_connector_helper_funcs.best_encoder callback
3470
- * @connector: Connector control structure
3471
- *
3472
- * This is a &drm_connector_helper_funcs.best_encoder callback helper for
3473
- * connectors that support exactly 1 encoder, statically determined at driver
3474
- * init time.
3475
- */
3476
-struct drm_encoder *
3477
-drm_atomic_helper_best_encoder(struct drm_connector *connector)
3478
-{
3479
- WARN_ON(connector->encoder_ids[1]);
3480
- return drm_encoder_find(connector->dev, NULL, connector->encoder_ids[0]);
3481
-}
3482
-EXPORT_SYMBOL(drm_atomic_helper_best_encoder);
3483
-
3484
-/**
3485
- * DOC: atomic state reset and initialization
3486
- *
3487
- * Both the drm core and the atomic helpers assume that there is always the full
3488
- * and correct atomic software state for all connectors, CRTCs and planes
3489
- * available. Which is a bit a problem on driver load and also after system
3490
- * suspend. One way to solve this is to have a hardware state read-out
3491
- * infrastructure which reconstructs the full software state (e.g. the i915
3492
- * driver).
3493
- *
3494
- * The simpler solution is to just reset the software state to everything off,
3495
- * which is easiest to do by calling drm_mode_config_reset(). To facilitate this
3496
- * the atomic helpers provide default reset implementations for all hooks.
3497
- *
3498
- * On the upside the precise state tracking of atomic simplifies system suspend
3499
- * and resume a lot. For drivers using drm_mode_config_reset() a complete recipe
3500
- * is implemented in drm_atomic_helper_suspend() and drm_atomic_helper_resume().
3501
- * For other drivers the building blocks are split out, see the documentation
3502
- * for these functions.
3503
- */
3504
-
3505
-/**
3506
- * drm_atomic_helper_crtc_reset - default &drm_crtc_funcs.reset hook for CRTCs
3507
- * @crtc: drm CRTC
3508
- *
3509
- * Resets the atomic state for @crtc by freeing the state pointer (which might
3510
- * be NULL, e.g. at driver load time) and allocating a new empty state object.
3511
- */
3512
-void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc)
3513
-{
3514
- if (crtc->state)
3515
- __drm_atomic_helper_crtc_destroy_state(crtc->state);
3516
-
3517
- kfree(crtc->state);
3518
- crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL);
3519
-
3520
- if (crtc->state)
3521
- crtc->state->crtc = crtc;
3522
-}
3523
-EXPORT_SYMBOL(drm_atomic_helper_crtc_reset);
3524
-
3525
-/**
3526
- * __drm_atomic_helper_crtc_duplicate_state - copy atomic CRTC state
3527
- * @crtc: CRTC object
3528
- * @state: atomic CRTC state
3529
- *
3530
- * Copies atomic state from a CRTC's current state and resets inferred values.
3531
- * This is useful for drivers that subclass the CRTC state.
3532
- */
3533
-void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc,
3534
- struct drm_crtc_state *state)
3535
-{
3536
- memcpy(state, crtc->state, sizeof(*state));
3537
-
3538
- if (state->mode_blob)
3539
- drm_property_blob_get(state->mode_blob);
3540
- if (state->degamma_lut)
3541
- drm_property_blob_get(state->degamma_lut);
3542
- if (state->ctm)
3543
- drm_property_blob_get(state->ctm);
3544
- if (state->gamma_lut)
3545
- drm_property_blob_get(state->gamma_lut);
3546
- if (state->cubic_lut)
3547
- drm_property_blob_get(state->cubic_lut);
3548
- state->mode_changed = false;
3549
- state->active_changed = false;
3550
- state->planes_changed = false;
3551
- state->connectors_changed = false;
3552
- state->color_mgmt_changed = false;
3553
- state->zpos_changed = false;
3554
- state->commit = NULL;
3555
- state->event = NULL;
3556
- state->pageflip_flags = 0;
3557
-}
3558
-EXPORT_SYMBOL(__drm_atomic_helper_crtc_duplicate_state);
3559
-
3560
-/**
3561
- * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook
3562
- * @crtc: drm CRTC
3563
- *
3564
- * Default CRTC state duplicate hook for drivers which don't have their own
3565
- * subclassed CRTC state structure.
3566
- */
3567
-struct drm_crtc_state *
3568
-drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc)
3569
-{
3570
- struct drm_crtc_state *state;
3571
-
3572
- if (WARN_ON(!crtc->state))
3573
- return NULL;
3574
-
3575
- state = kmalloc(sizeof(*state), GFP_KERNEL);
3576
- if (state)
3577
- __drm_atomic_helper_crtc_duplicate_state(crtc, state);
3578
-
3579
- return state;
3580
-}
3581
-EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state);
3582
-
3583
-/**
3584
- * __drm_atomic_helper_crtc_destroy_state - release CRTC state
3585
- * @state: CRTC state object to release
3586
- *
3587
- * Releases all resources stored in the CRTC state without actually freeing
3588
- * the memory of the CRTC state. This is useful for drivers that subclass the
3589
- * CRTC state.
3590
- */
3591
-void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state)
3592
-{
3593
- if (state->commit) {
3594
- /*
3595
- * In the event that a non-blocking commit returns
3596
- * -ERESTARTSYS before the commit_tail work is queued, we will
3597
- * have an extra reference to the commit object. Release it, if
3598
- * the event has not been consumed by the worker.
3599
- *
3600
- * state->event may be freed, so we can't directly look at
3601
- * state->event->base.completion.
3602
- */
3603
- if (state->event && state->commit->abort_completion)
3604
- drm_crtc_commit_put(state->commit);
3605
-
3606
- kfree(state->commit->event);
3607
- state->commit->event = NULL;
3608
-
3609
- drm_crtc_commit_put(state->commit);
3610
- }
3611
-
3612
- drm_property_blob_put(state->mode_blob);
3613
- drm_property_blob_put(state->degamma_lut);
3614
- drm_property_blob_put(state->ctm);
3615
- drm_property_blob_put(state->gamma_lut);
3616
- drm_property_blob_put(state->cubic_lut);
3617
-}
3618
-EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state);
3619
-
3620
-/**
3621
- * drm_atomic_helper_crtc_destroy_state - default state destroy hook
3622
- * @crtc: drm CRTC
3623
- * @state: CRTC state object to release
3624
- *
3625
- * Default CRTC state destroy hook for drivers which don't have their own
3626
- * subclassed CRTC state structure.
3627
- */
3628
-void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
3629
- struct drm_crtc_state *state)
3630
-{
3631
- __drm_atomic_helper_crtc_destroy_state(state);
3632
- kfree(state);
3633
-}
3634
-EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state);
3635
-
3636
-/**
3637
- * drm_atomic_helper_plane_reset - default &drm_plane_funcs.reset hook for planes
3638
- * @plane: drm plane
3639
- *
3640
- * Resets the atomic state for @plane by freeing the state pointer (which might
3641
- * be NULL, e.g. at driver load time) and allocating a new empty state object.
3642
- */
3643
-void drm_atomic_helper_plane_reset(struct drm_plane *plane)
3644
-{
3645
- if (plane->state)
3646
- __drm_atomic_helper_plane_destroy_state(plane->state);
3647
-
3648
- kfree(plane->state);
3649
- plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL);
3650
-
3651
- if (plane->state) {
3652
- plane->state->plane = plane;
3653
- plane->state->rotation = DRM_MODE_ROTATE_0;
3654
-
3655
- /* Reset the alpha value to fully opaque if it matters */
3656
- if (plane->alpha_property)
3657
- plane->state->alpha = plane->alpha_property->values[1];
3658
- }
3659
-}
3660
-EXPORT_SYMBOL(drm_atomic_helper_plane_reset);
3661
-
3662
-/**
3663
- * __drm_atomic_helper_plane_duplicate_state - copy atomic plane state
3664
- * @plane: plane object
3665
- * @state: atomic plane state
3666
- *
3667
- * Copies atomic state from a plane's current state. This is useful for
3668
- * drivers that subclass the plane state.
3669
- */
3670
-void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane,
3671
- struct drm_plane_state *state)
3672
-{
3673
- memcpy(state, plane->state, sizeof(*state));
3674
-
3675
- if (state->fb)
3676
- drm_framebuffer_get(state->fb);
3677
-
3678
- state->fence = NULL;
3679
- state->commit = NULL;
3680
-}
3681
-EXPORT_SYMBOL(__drm_atomic_helper_plane_duplicate_state);
3682
-
3683
-/**
3684
- * drm_atomic_helper_plane_duplicate_state - default state duplicate hook
3685
- * @plane: drm plane
3686
- *
3687
- * Default plane state duplicate hook for drivers which don't have their own
3688
- * subclassed plane state structure.
3689
- */
3690
-struct drm_plane_state *
3691
-drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane)
3692
-{
3693
- struct drm_plane_state *state;
3694
-
3695
- if (WARN_ON(!plane->state))
3696
- return NULL;
3697
-
3698
- state = kmalloc(sizeof(*state), GFP_KERNEL);
3699
- if (state)
3700
- __drm_atomic_helper_plane_duplicate_state(plane, state);
3701
-
3702
- return state;
3703
-}
3704
-EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state);
3705
-
3706
-/**
3707
- * __drm_atomic_helper_plane_destroy_state - release plane state
3708
- * @state: plane state object to release
3709
- *
3710
- * Releases all resources stored in the plane state without actually freeing
3711
- * the memory of the plane state. This is useful for drivers that subclass the
3712
- * plane state.
3713
- */
3714
-void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state)
3715
-{
3716
- if (state->fb)
3717
- drm_framebuffer_put(state->fb);
3718
-
3719
- if (state->fence)
3720
- dma_fence_put(state->fence);
3721
-
3722
- if (state->commit)
3723
- drm_crtc_commit_put(state->commit);
3724
-}
3725
-EXPORT_SYMBOL(__drm_atomic_helper_plane_destroy_state);
3726
-
3727
-/**
3728
- * drm_atomic_helper_plane_destroy_state - default state destroy hook
3729
- * @plane: drm plane
3730
- * @state: plane state object to release
3731
- *
3732
- * Default plane state destroy hook for drivers which don't have their own
3733
- * subclassed plane state structure.
3734
- */
3735
-void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
3736
- struct drm_plane_state *state)
3737
-{
3738
- __drm_atomic_helper_plane_destroy_state(state);
3739
- kfree(state);
3740
-}
3741
-EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state);
3742
-
3743
-/**
3744
- * __drm_atomic_helper_connector_reset - reset state on connector
3745
- * @connector: drm connector
3746
- * @conn_state: connector state to assign
3747
- *
3748
- * Initializes the newly allocated @conn_state and assigns it to
3749
- * the &drm_conector->state pointer of @connector, usually required when
3750
- * initializing the drivers or when called from the &drm_connector_funcs.reset
3751
- * hook.
3752
- *
3753
- * This is useful for drivers that subclass the connector state.
3754
- */
3755
-void
3756
-__drm_atomic_helper_connector_reset(struct drm_connector *connector,
3757
- struct drm_connector_state *conn_state)
3758
-{
3759
- if (conn_state)
3760
- conn_state->connector = connector;
3761
-
3762
- connector->state = conn_state;
3763
-}
3764
-EXPORT_SYMBOL(__drm_atomic_helper_connector_reset);
3765
-
3766
-/**
3767
- * drm_atomic_helper_connector_reset - default &drm_connector_funcs.reset hook for connectors
3768
- * @connector: drm connector
3769
- *
3770
- * Resets the atomic state for @connector by freeing the state pointer (which
3771
- * might be NULL, e.g. at driver load time) and allocating a new empty state
3772
- * object.
3773
- */
3774
-void drm_atomic_helper_connector_reset(struct drm_connector *connector)
3775
-{
3776
- struct drm_connector_state *conn_state =
3777
- kzalloc(sizeof(*conn_state), GFP_KERNEL);
3778
-
3779
- if (connector->state)
3780
- __drm_atomic_helper_connector_destroy_state(connector->state);
3781
-
3782
- kfree(connector->state);
3783
- __drm_atomic_helper_connector_reset(connector, conn_state);
3784
-}
3785
-EXPORT_SYMBOL(drm_atomic_helper_connector_reset);
3786
-
3787
-/**
3788
- * __drm_atomic_helper_connector_duplicate_state - copy atomic connector state
3789
- * @connector: connector object
3790
- * @state: atomic connector state
3791
- *
3792
- * Copies atomic state from a connector's current state. This is useful for
3793
- * drivers that subclass the connector state.
3794
- */
3795
-void
3796
-__drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector,
3797
- struct drm_connector_state *state)
3798
-{
3799
- memcpy(state, connector->state, sizeof(*state));
3800
- if (state->crtc)
3801
- drm_connector_get(connector);
3802
- state->commit = NULL;
3803
-
3804
- if (state->hdr_output_metadata)
3805
- drm_property_blob_get(state->hdr_output_metadata);
3806
-
3807
- /* Don't copy over a writeback job, they are used only once */
3808
- state->writeback_job = NULL;
3809
-}
3810
-EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state);
3811
-
3812
-/**
3813
- * drm_atomic_helper_connector_duplicate_state - default state duplicate hook
3814
- * @connector: drm connector
3815
- *
3816
- * Default connector state duplicate hook for drivers which don't have their own
3817
- * subclassed connector state structure.
3818
- */
3819
-struct drm_connector_state *
3820
-drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector)
3821
-{
3822
- struct drm_connector_state *state;
3823
-
3824
- if (WARN_ON(!connector->state))
3825
- return NULL;
3826
-
3827
- state = kmalloc(sizeof(*state), GFP_KERNEL);
3828
- if (state)
3829
- __drm_atomic_helper_connector_duplicate_state(connector, state);
3830
-
3831
- return state;
3832
-}
3833
-EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state);
3834
-
3835
-/**
3836
- * drm_atomic_helper_duplicate_state - duplicate an atomic state object
3837
- * @dev: DRM device
3838
- * @ctx: lock acquisition context
3839
- *
3840
- * Makes a copy of the current atomic state by looping over all objects and
3841
- * duplicating their respective states. This is used for example by suspend/
3842
- * resume support code to save the state prior to suspend such that it can
3843
- * be restored upon resume.
3844
- *
3845
- * Note that this treats atomic state as persistent between save and restore.
3846
- * Drivers must make sure that this is possible and won't result in confusion
3847
- * or erroneous behaviour.
3848
- *
3849
- * Note that if callers haven't already acquired all modeset locks this might
3850
- * return -EDEADLK, which must be handled by calling drm_modeset_backoff().
3851
- *
3852
- * Returns:
3853
- * A pointer to the copy of the atomic state object on success or an
3854
- * ERR_PTR()-encoded error code on failure.
3855
- *
3856
- * See also:
3857
- * drm_atomic_helper_suspend(), drm_atomic_helper_resume()
3858
- */
3859
-struct drm_atomic_state *
3860
-drm_atomic_helper_duplicate_state(struct drm_device *dev,
3861
- struct drm_modeset_acquire_ctx *ctx)
3862
-{
3863
- struct drm_atomic_state *state;
3864
- struct drm_connector *conn;
3865
- struct drm_connector_list_iter conn_iter;
3866
- struct drm_plane *plane;
3867
- struct drm_crtc *crtc;
3868
- int err = 0;
3869
-
3870
- state = drm_atomic_state_alloc(dev);
3871
- if (!state)
3872
- return ERR_PTR(-ENOMEM);
3873
-
3874
- state->acquire_ctx = ctx;
3875
-
3876
- drm_for_each_crtc(crtc, dev) {
3877
- struct drm_crtc_state *crtc_state;
3878
-
3879
- crtc_state = drm_atomic_get_crtc_state(state, crtc);
3880
- if (IS_ERR(crtc_state)) {
3881
- err = PTR_ERR(crtc_state);
3882
- goto free;
3883
- }
3884
- }
3885
-
3886
- drm_for_each_plane(plane, dev) {
3887
- struct drm_plane_state *plane_state;
3888
-
3889
- plane_state = drm_atomic_get_plane_state(state, plane);
3890
- if (IS_ERR(plane_state)) {
3891
- err = PTR_ERR(plane_state);
3892
- goto free;
3893
- }
3894
- }
3895
-
3896
- drm_connector_list_iter_begin(dev, &conn_iter);
3897
- drm_for_each_connector_iter(conn, &conn_iter) {
3898
- struct drm_connector_state *conn_state;
3899
-
3900
- conn_state = drm_atomic_get_connector_state(state, conn);
3901
- if (IS_ERR(conn_state)) {
3902
- err = PTR_ERR(conn_state);
3903
- drm_connector_list_iter_end(&conn_iter);
3904
- goto free;
3905
- }
3906
- }
3907
- drm_connector_list_iter_end(&conn_iter);
3908
-
3909
- /* clear the acquire context so that it isn't accidentally reused */
3910
- state->acquire_ctx = NULL;
3911
-
3912
-free:
3913
- if (err < 0) {
3914
- drm_atomic_state_put(state);
3915
- state = ERR_PTR(err);
3916
- }
3917
-
3918
- return state;
3919
-}
3920
-EXPORT_SYMBOL(drm_atomic_helper_duplicate_state);
3921
-
3922
-/**
3923
- * __drm_atomic_helper_connector_destroy_state - release connector state
3924
- * @state: connector state object to release
3925
- *
3926
- * Releases all resources stored in the connector state without actually
3927
- * freeing the memory of the connector state. This is useful for drivers that
3928
- * subclass the connector state.
3929
- */
3930
-void
3931
-__drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state)
3932
-{
3933
- if (state->crtc)
3934
- drm_connector_put(state->connector);
3935
-
3936
- if (state->commit)
3937
- drm_crtc_commit_put(state->commit);
3938
-
3939
- drm_property_blob_put(state->hdr_output_metadata);
3940
-}
3941
-EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state);
3942
-
3943
-/**
3944
- * drm_atomic_helper_connector_destroy_state - default state destroy hook
3945
- * @connector: drm connector
3946
- * @state: connector state object to release
3947
- *
3948
- * Default connector state destroy hook for drivers which don't have their own
3949
- * subclassed connector state structure.
3950
- */
3951
-void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
3952
- struct drm_connector_state *state)
3953
-{
3954
- __drm_atomic_helper_connector_destroy_state(state);
3955
- kfree(state);
3956
-}
3957
-EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state);
39583506
39593507 /**
39603508 * drm_atomic_helper_legacy_gamma_set - set the legacy gamma correction table
....@@ -4015,7 +3563,6 @@
40153563 replaced = drm_property_replace_blob(&crtc_state->degamma_lut, NULL);
40163564 replaced |= drm_property_replace_blob(&crtc_state->ctm, NULL);
40173565 replaced |= drm_property_replace_blob(&crtc_state->gamma_lut, blob);
4018
- replaced |= drm_property_replace_blob(&crtc_state->cubic_lut, NULL);
40193566 crtc_state->color_mgmt_changed |= replaced;
40203567
40213568 ret = drm_atomic_commit(state);
....@@ -4028,16 +3575,42 @@
40283575 EXPORT_SYMBOL(drm_atomic_helper_legacy_gamma_set);
40293576
40303577 /**
4031
- * __drm_atomic_helper_private_duplicate_state - copy atomic private state
4032
- * @obj: CRTC object
4033
- * @state: new private object state
3578
+ * drm_atomic_helper_bridge_propagate_bus_fmt() - Propagate output format to
3579
+ * the input end of a bridge
3580
+ * @bridge: bridge control structure
3581
+ * @bridge_state: new bridge state
3582
+ * @crtc_state: new CRTC state
3583
+ * @conn_state: new connector state
3584
+ * @output_fmt: tested output bus format
3585
+ * @num_input_fmts: will contain the size of the returned array
40343586 *
4035
- * Copies atomic state from a private objects's current state and resets inferred values.
4036
- * This is useful for drivers that subclass the private state.
3587
+ * This helper is a pluggable implementation of the
3588
+ * &drm_bridge_funcs.atomic_get_input_bus_fmts operation for bridges that don't
3589
+ * modify the bus configuration between their input and their output. It
3590
+ * returns an array of input formats with a single element set to @output_fmt.
3591
+ *
3592
+ * RETURNS:
3593
+ * a valid format array of size @num_input_fmts, or NULL if the allocation
3594
+ * failed
40373595 */
4038
-void __drm_atomic_helper_private_obj_duplicate_state(struct drm_private_obj *obj,
4039
- struct drm_private_state *state)
3596
+u32 *
3597
+drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
3598
+ struct drm_bridge_state *bridge_state,
3599
+ struct drm_crtc_state *crtc_state,
3600
+ struct drm_connector_state *conn_state,
3601
+ u32 output_fmt,
3602
+ unsigned int *num_input_fmts)
40403603 {
4041
- memcpy(state, obj->state, sizeof(*state));
3604
+ u32 *input_fmts;
3605
+
3606
+ input_fmts = kzalloc(sizeof(*input_fmts), GFP_KERNEL);
3607
+ if (!input_fmts) {
3608
+ *num_input_fmts = 0;
3609
+ return NULL;
3610
+ }
3611
+
3612
+ *num_input_fmts = 1;
3613
+ input_fmts[0] = output_fmt;
3614
+ return input_fmts;
40423615 }
4043
-EXPORT_SYMBOL(__drm_atomic_helper_private_obj_duplicate_state);
3616
+EXPORT_SYMBOL(drm_atomic_helper_bridge_propagate_bus_fmt);