Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 Red Hat |
| 3 | * Copyright (C) 2014 Intel Corp. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included in |
| 13 | * all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 19 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 21 | * OTHER DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Rob Clark <robdclark@gmail.com> |
| 25 | * Daniel Vetter <daniel.vetter@ffwll.ch> |
| 26 | */ |
| 27 | |
| 28 | #include <drm/drmP.h> |
| 29 | #include <drm/drm_atomic.h> |
Daniel Vetter | 72fdb40c | 2018-09-05 15:57:11 +0200 | [diff] [blame] | 30 | #include <drm/drm_atomic_uapi.h> |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 31 | #include <drm/drm_plane_helper.h> |
| 32 | #include <drm/drm_crtc_helper.h> |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 33 | #include <drm/drm_atomic_helper.h> |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 34 | #include <drm/drm_writeback.h> |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 35 | #include <linux/dma-fence.h> |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 36 | |
Jose Abreu | faf94a0 | 2017-05-25 15:19:16 +0100 | [diff] [blame] | 37 | #include "drm_crtc_helper_internal.h" |
Marek Szyprowski | 44d1240d | 2016-06-13 11:11:26 +0200 | [diff] [blame] | 38 | #include "drm_crtc_internal.h" |
| 39 | |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 40 | /** |
| 41 | * DOC: overview |
| 42 | * |
| 43 | * This helper library provides implementations of check and commit functions on |
| 44 | * top of the CRTC modeset helper callbacks and the plane helper callbacks. It |
| 45 | * also provides convenience implementations for the atomic state handling |
| 46 | * callbacks for drivers which don't need to subclass the drm core structures to |
| 47 | * add their own additional internal state. |
| 48 | * |
| 49 | * This library also provides default implementations for the check callback in |
Daniel Vetter | 26196f7 | 2015-08-25 16:26:03 +0200 | [diff] [blame] | 50 | * drm_atomic_helper_check() and for the commit callback with |
| 51 | * drm_atomic_helper_commit(). But the individual stages and callbacks are |
| 52 | * exposed to allow drivers to mix and match and e.g. use the plane helpers only |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 53 | * together with a driver private modeset implementation. |
| 54 | * |
| 55 | * This library also provides implementations for all the legacy driver |
Daniel Vetter | 26196f7 | 2015-08-25 16:26:03 +0200 | [diff] [blame] | 56 | * interfaces on top of the atomic interface. See drm_atomic_helper_set_config(), |
| 57 | * drm_atomic_helper_disable_plane(), drm_atomic_helper_disable_plane() and the |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 58 | * various functions to implement set_property callbacks. New drivers must not |
| 59 | * implement these functions themselves but must use the provided helpers. |
Daniel Vetter | 092d01d | 2015-12-04 09:45:44 +0100 | [diff] [blame] | 60 | * |
| 61 | * The atomic helper uses the same function table structures as all other |
Daniel Vetter | ea0dd85 | 2016-12-29 21:48:26 +0100 | [diff] [blame] | 62 | * modesetting helpers. See the documentation for &struct drm_crtc_helper_funcs, |
| 63 | * struct &drm_encoder_helper_funcs and &struct drm_connector_helper_funcs. It |
| 64 | * also shares the &struct drm_plane_helper_funcs function table with the plane |
Daniel Vetter | 092d01d | 2015-12-04 09:45:44 +0100 | [diff] [blame] | 65 | * helpers. |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 66 | */ |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 67 | static void |
| 68 | drm_atomic_helper_plane_changed(struct drm_atomic_state *state, |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 69 | struct drm_plane_state *old_plane_state, |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 70 | struct drm_plane_state *plane_state, |
| 71 | struct drm_plane *plane) |
| 72 | { |
| 73 | struct drm_crtc_state *crtc_state; |
| 74 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 75 | if (old_plane_state->crtc) { |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 76 | crtc_state = drm_atomic_get_new_crtc_state(state, |
| 77 | old_plane_state->crtc); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 78 | |
| 79 | if (WARN_ON(!crtc_state)) |
| 80 | return; |
| 81 | |
| 82 | crtc_state->planes_changed = true; |
| 83 | } |
| 84 | |
| 85 | if (plane_state->crtc) { |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 86 | crtc_state = drm_atomic_get_new_crtc_state(state, plane_state->crtc); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 87 | |
| 88 | if (WARN_ON(!crtc_state)) |
| 89 | return; |
| 90 | |
| 91 | crtc_state->planes_changed = true; |
| 92 | } |
| 93 | } |
| 94 | |
Daniel Vetter | 297e30b | 2018-10-04 22:24:27 +0200 | [diff] [blame] | 95 | /* |
| 96 | * For connectors that support multiple encoders, either the |
| 97 | * .atomic_best_encoder() or .best_encoder() operation must be implemented. |
| 98 | */ |
| 99 | static struct drm_encoder * |
| 100 | pick_single_encoder_for_connector(struct drm_connector *connector) |
| 101 | { |
| 102 | WARN_ON(connector->encoder_ids[1]); |
| 103 | return drm_encoder_find(connector->dev, NULL, connector->encoder_ids[0]); |
| 104 | } |
| 105 | |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 106 | static int handle_conflicting_encoders(struct drm_atomic_state *state, |
| 107 | bool disable_conflicting_encoders) |
Daniel Vetter | 97ac320 | 2015-12-03 10:49:14 +0100 | [diff] [blame] | 108 | { |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 109 | struct drm_connector_state *new_conn_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 110 | struct drm_connector *connector; |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame] | 111 | struct drm_connector_list_iter conn_iter; |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 112 | struct drm_encoder *encoder; |
| 113 | unsigned encoder_mask = 0; |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame] | 114 | int i, ret = 0; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 115 | |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 116 | /* |
| 117 | * First loop, find all newly assigned encoders from the connectors |
| 118 | * part of the state. If the same encoder is assigned to multiple |
| 119 | * connectors bail out. |
| 120 | */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 121 | for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 122 | const struct drm_connector_helper_funcs *funcs = connector->helper_private; |
| 123 | struct drm_encoder *new_encoder; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 124 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 125 | if (!new_conn_state->crtc) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 126 | continue; |
| 127 | |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 128 | if (funcs->atomic_best_encoder) |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 129 | new_encoder = funcs->atomic_best_encoder(connector, new_conn_state); |
Boris Brezillon | a0909cc | 2016-06-01 18:03:37 +0200 | [diff] [blame] | 130 | else if (funcs->best_encoder) |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 131 | new_encoder = funcs->best_encoder(connector); |
Boris Brezillon | a0909cc | 2016-06-01 18:03:37 +0200 | [diff] [blame] | 132 | else |
Daniel Vetter | 297e30b | 2018-10-04 22:24:27 +0200 | [diff] [blame] | 133 | new_encoder = pick_single_encoder_for_connector(connector); |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 134 | |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 135 | if (new_encoder) { |
Ville Syrjälä | 6f3be03 | 2018-06-26 22:47:09 +0300 | [diff] [blame] | 136 | if (encoder_mask & drm_encoder_mask(new_encoder)) { |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 137 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] on [CONNECTOR:%d:%s] already assigned\n", |
| 138 | new_encoder->base.id, new_encoder->name, |
| 139 | connector->base.id, connector->name); |
| 140 | |
| 141 | return -EINVAL; |
| 142 | } |
| 143 | |
Ville Syrjälä | 6f3be03 | 2018-06-26 22:47:09 +0300 | [diff] [blame] | 144 | encoder_mask |= drm_encoder_mask(new_encoder); |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 145 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 146 | } |
| 147 | |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 148 | if (!encoder_mask) |
| 149 | return 0; |
| 150 | |
| 151 | /* |
| 152 | * Second loop, iterate over all connectors not part of the state. |
| 153 | * |
| 154 | * If a conflicting encoder is found and disable_conflicting_encoders |
| 155 | * is not set, an error is returned. Userspace can provide a solution |
| 156 | * through the atomic ioctl. |
| 157 | * |
| 158 | * If the flag is set conflicting connectors are removed from the crtc |
| 159 | * and the crtc is disabled if no encoder is left. This preserves |
| 160 | * compatibility with the legacy set_config behavior. |
| 161 | */ |
Thierry Reding | b982dab | 2017-02-28 15:46:43 +0100 | [diff] [blame] | 162 | drm_connector_list_iter_begin(state->dev, &conn_iter); |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame] | 163 | drm_for_each_connector_iter(connector, &conn_iter) { |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 164 | struct drm_crtc_state *crtc_state; |
| 165 | |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 166 | if (drm_atomic_get_new_connector_state(state, connector)) |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 167 | continue; |
| 168 | |
| 169 | encoder = connector->state->best_encoder; |
Ville Syrjälä | 6f3be03 | 2018-06-26 22:47:09 +0300 | [diff] [blame] | 170 | if (!encoder || !(encoder_mask & drm_encoder_mask(encoder))) |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 171 | continue; |
| 172 | |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 173 | if (!disable_conflicting_encoders) { |
| 174 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s] by [CONNECTOR:%d:%s]\n", |
| 175 | encoder->base.id, encoder->name, |
| 176 | connector->state->crtc->base.id, |
| 177 | connector->state->crtc->name, |
| 178 | connector->base.id, connector->name); |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame] | 179 | ret = -EINVAL; |
| 180 | goto out; |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 181 | } |
| 182 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 183 | new_conn_state = drm_atomic_get_connector_state(state, connector); |
| 184 | if (IS_ERR(new_conn_state)) { |
| 185 | ret = PTR_ERR(new_conn_state); |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame] | 186 | goto out; |
| 187 | } |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 188 | |
| 189 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s], disabling [CONNECTOR:%d:%s]\n", |
| 190 | encoder->base.id, encoder->name, |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 191 | new_conn_state->crtc->base.id, new_conn_state->crtc->name, |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 192 | connector->base.id, connector->name); |
| 193 | |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 194 | crtc_state = drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 195 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 196 | ret = drm_atomic_set_crtc_for_connector(new_conn_state, NULL); |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 197 | if (ret) |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame] | 198 | goto out; |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 199 | |
| 200 | if (!crtc_state->connector_mask) { |
| 201 | ret = drm_atomic_set_mode_prop_for_crtc(crtc_state, |
| 202 | NULL); |
| 203 | if (ret < 0) |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame] | 204 | goto out; |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 205 | |
| 206 | crtc_state->active = false; |
| 207 | } |
| 208 | } |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame] | 209 | out: |
Thierry Reding | b982dab | 2017-02-28 15:46:43 +0100 | [diff] [blame] | 210 | drm_connector_list_iter_end(&conn_iter); |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 211 | |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame] | 212 | return ret; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 213 | } |
| 214 | |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 215 | static void |
| 216 | set_best_encoder(struct drm_atomic_state *state, |
| 217 | struct drm_connector_state *conn_state, |
| 218 | struct drm_encoder *encoder) |
| 219 | { |
| 220 | struct drm_crtc_state *crtc_state; |
| 221 | struct drm_crtc *crtc; |
| 222 | |
| 223 | if (conn_state->best_encoder) { |
| 224 | /* Unset the encoder_mask in the old crtc state. */ |
| 225 | crtc = conn_state->connector->state->crtc; |
| 226 | |
| 227 | /* A NULL crtc is an error here because we should have |
| 228 | * duplicated a NULL best_encoder when crtc was NULL. |
| 229 | * As an exception restoring duplicated atomic state |
| 230 | * during resume is allowed, so don't warn when |
| 231 | * best_encoder is equal to encoder we intend to set. |
| 232 | */ |
| 233 | WARN_ON(!crtc && encoder != conn_state->best_encoder); |
| 234 | if (crtc) { |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 235 | crtc_state = drm_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 236 | |
| 237 | crtc_state->encoder_mask &= |
Ville Syrjälä | 6f3be03 | 2018-06-26 22:47:09 +0300 | [diff] [blame] | 238 | ~drm_encoder_mask(conn_state->best_encoder); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 239 | } |
| 240 | } |
| 241 | |
| 242 | if (encoder) { |
| 243 | crtc = conn_state->crtc; |
| 244 | WARN_ON(!crtc); |
| 245 | if (crtc) { |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 246 | crtc_state = drm_atomic_get_new_crtc_state(state, crtc); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 247 | |
| 248 | crtc_state->encoder_mask |= |
Ville Syrjälä | 6f3be03 | 2018-06-26 22:47:09 +0300 | [diff] [blame] | 249 | drm_encoder_mask(encoder); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 250 | } |
| 251 | } |
| 252 | |
| 253 | conn_state->best_encoder = encoder; |
| 254 | } |
| 255 | |
Maarten Lankhorst | ec5aaa5 | 2016-03-03 10:17:41 +0100 | [diff] [blame] | 256 | static void |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 257 | steal_encoder(struct drm_atomic_state *state, |
Maarten Lankhorst | ff19b78 | 2016-03-03 10:17:38 +0100 | [diff] [blame] | 258 | struct drm_encoder *encoder) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 259 | { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 260 | struct drm_crtc_state *crtc_state; |
| 261 | struct drm_connector *connector; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 262 | struct drm_connector_state *old_connector_state, *new_connector_state; |
Maarten Lankhorst | ec5aaa5 | 2016-03-03 10:17:41 +0100 | [diff] [blame] | 263 | int i; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 264 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 265 | for_each_oldnew_connector_in_state(state, connector, old_connector_state, new_connector_state, i) { |
Maarten Lankhorst | ff19b78 | 2016-03-03 10:17:38 +0100 | [diff] [blame] | 266 | struct drm_crtc *encoder_crtc; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 267 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 268 | if (new_connector_state->best_encoder != encoder) |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 269 | continue; |
| 270 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 271 | encoder_crtc = old_connector_state->crtc; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 272 | |
Maarten Lankhorst | ff19b78 | 2016-03-03 10:17:38 +0100 | [diff] [blame] | 273 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s], stealing it\n", |
| 274 | encoder->base.id, encoder->name, |
| 275 | encoder_crtc->base.id, encoder_crtc->name); |
| 276 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 277 | set_best_encoder(state, new_connector_state, NULL); |
Maarten Lankhorst | ff19b78 | 2016-03-03 10:17:38 +0100 | [diff] [blame] | 278 | |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 279 | crtc_state = drm_atomic_get_new_crtc_state(state, encoder_crtc); |
Maarten Lankhorst | ff19b78 | 2016-03-03 10:17:38 +0100 | [diff] [blame] | 280 | crtc_state->connectors_changed = true; |
| 281 | |
Maarten Lankhorst | ec5aaa5 | 2016-03-03 10:17:41 +0100 | [diff] [blame] | 282 | return; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 283 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | static int |
Maarten Lankhorst | 9459545 | 2016-02-24 09:37:29 +0100 | [diff] [blame] | 287 | update_connector_routing(struct drm_atomic_state *state, |
| 288 | struct drm_connector *connector, |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 289 | struct drm_connector_state *old_connector_state, |
| 290 | struct drm_connector_state *new_connector_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 291 | { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 292 | const struct drm_connector_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 293 | struct drm_encoder *new_encoder; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 294 | struct drm_crtc_state *crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 295 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 296 | DRM_DEBUG_ATOMIC("Updating routing for [CONNECTOR:%d:%s]\n", |
| 297 | connector->base.id, |
| 298 | connector->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 299 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 300 | if (old_connector_state->crtc != new_connector_state->crtc) { |
| 301 | if (old_connector_state->crtc) { |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 302 | crtc_state = drm_atomic_get_new_crtc_state(state, old_connector_state->crtc); |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 303 | crtc_state->connectors_changed = true; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 304 | } |
| 305 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 306 | if (new_connector_state->crtc) { |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 307 | crtc_state = drm_atomic_get_new_crtc_state(state, new_connector_state->crtc); |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 308 | crtc_state->connectors_changed = true; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 309 | } |
| 310 | } |
| 311 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 312 | if (!new_connector_state->crtc) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 313 | DRM_DEBUG_ATOMIC("Disabling [CONNECTOR:%d:%s]\n", |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 314 | connector->base.id, |
| 315 | connector->name); |
| 316 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 317 | set_best_encoder(state, new_connector_state, NULL); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 318 | |
| 319 | return 0; |
| 320 | } |
| 321 | |
Lyude Paul | de9f8ee | 2018-10-16 16:39:46 -0400 | [diff] [blame] | 322 | crtc_state = drm_atomic_get_new_crtc_state(state, |
| 323 | new_connector_state->crtc); |
| 324 | /* |
| 325 | * For compatibility with legacy users, we want to make sure that |
| 326 | * we allow DPMS On->Off modesets on unregistered connectors. Modesets |
| 327 | * which would result in anything else must be considered invalid, to |
| 328 | * avoid turning on new displays on dead connectors. |
| 329 | * |
| 330 | * Since the connector can be unregistered at any point during an |
| 331 | * atomic check or commit, this is racy. But that's OK: all we care |
| 332 | * about is ensuring that userspace can't do anything but shut off the |
| 333 | * display on a connector that was destroyed after its been notified, |
| 334 | * not before. |
| 335 | */ |
| 336 | if (drm_connector_is_unregistered(connector) && crtc_state->active) { |
| 337 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] is not registered\n", |
| 338 | connector->base.id, connector->name); |
| 339 | return -EINVAL; |
| 340 | } |
| 341 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 342 | funcs = connector->helper_private; |
Daniel Vetter | 3b8a684 | 2015-08-03 17:24:08 +0200 | [diff] [blame] | 343 | |
| 344 | if (funcs->atomic_best_encoder) |
| 345 | new_encoder = funcs->atomic_best_encoder(connector, |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 346 | new_connector_state); |
Boris Brezillon | c61b93f | 2016-06-07 13:47:56 +0200 | [diff] [blame] | 347 | else if (funcs->best_encoder) |
Daniel Vetter | 3b8a684 | 2015-08-03 17:24:08 +0200 | [diff] [blame] | 348 | new_encoder = funcs->best_encoder(connector); |
Boris Brezillon | c61b93f | 2016-06-07 13:47:56 +0200 | [diff] [blame] | 349 | else |
Daniel Vetter | 297e30b | 2018-10-04 22:24:27 +0200 | [diff] [blame] | 350 | new_encoder = pick_single_encoder_for_connector(connector); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 351 | |
| 352 | if (!new_encoder) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 353 | DRM_DEBUG_ATOMIC("No suitable encoder found for [CONNECTOR:%d:%s]\n", |
| 354 | connector->base.id, |
| 355 | connector->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 356 | return -EINVAL; |
| 357 | } |
| 358 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 359 | if (!drm_encoder_crtc_ok(new_encoder, new_connector_state->crtc)) { |
Russell King | 6ac7c54 | 2017-02-13 12:27:03 +0000 | [diff] [blame] | 360 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] incompatible with [CRTC:%d:%s]\n", |
Daniel Vetter | 5481c8f | 2015-11-18 18:46:48 +0100 | [diff] [blame] | 361 | new_encoder->base.id, |
| 362 | new_encoder->name, |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 363 | new_connector_state->crtc->base.id, |
| 364 | new_connector_state->crtc->name); |
Daniel Vetter | 5481c8f | 2015-11-18 18:46:48 +0100 | [diff] [blame] | 365 | return -EINVAL; |
| 366 | } |
| 367 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 368 | if (new_encoder == new_connector_state->best_encoder) { |
| 369 | set_best_encoder(state, new_connector_state, new_encoder); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 370 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 371 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] keeps [ENCODER:%d:%s], now on [CRTC:%d:%s]\n", |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 372 | connector->base.id, |
| 373 | connector->name, |
| 374 | new_encoder->base.id, |
| 375 | new_encoder->name, |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 376 | new_connector_state->crtc->base.id, |
| 377 | new_connector_state->crtc->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 378 | |
| 379 | return 0; |
| 380 | } |
| 381 | |
Maarten Lankhorst | ec5aaa5 | 2016-03-03 10:17:41 +0100 | [diff] [blame] | 382 | steal_encoder(state, new_encoder); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 383 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 384 | set_best_encoder(state, new_connector_state, new_encoder); |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 385 | |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 386 | crtc_state->connectors_changed = true; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 387 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 388 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] using [ENCODER:%d:%s] on [CRTC:%d:%s]\n", |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 389 | connector->base.id, |
| 390 | connector->name, |
| 391 | new_encoder->base.id, |
| 392 | new_encoder->name, |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 393 | new_connector_state->crtc->base.id, |
| 394 | new_connector_state->crtc->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 395 | |
| 396 | return 0; |
| 397 | } |
| 398 | |
| 399 | static int |
| 400 | mode_fixup(struct drm_atomic_state *state) |
| 401 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 402 | struct drm_crtc *crtc; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 403 | struct drm_crtc_state *new_crtc_state; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 404 | struct drm_connector *connector; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 405 | struct drm_connector_state *new_conn_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 406 | int i; |
Dan Carpenter | f9ad86e | 2017-02-08 02:46:01 +0300 | [diff] [blame] | 407 | int ret; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 408 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 409 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 410 | if (!new_crtc_state->mode_changed && |
| 411 | !new_crtc_state->connectors_changed) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 412 | continue; |
| 413 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 414 | drm_mode_copy(&new_crtc_state->adjusted_mode, &new_crtc_state->mode); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 415 | } |
| 416 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 417 | for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 418 | const struct drm_encoder_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 419 | struct drm_encoder *encoder; |
| 420 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 421 | WARN_ON(!!new_conn_state->best_encoder != !!new_conn_state->crtc); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 422 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 423 | if (!new_conn_state->crtc || !new_conn_state->best_encoder) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 424 | continue; |
| 425 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 426 | new_crtc_state = |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 427 | drm_atomic_get_new_crtc_state(state, new_conn_state->crtc); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 428 | |
| 429 | /* |
| 430 | * Each encoder has at most one connector (since we always steal |
| 431 | * it away), so we won't call ->mode_fixup twice. |
| 432 | */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 433 | encoder = new_conn_state->best_encoder; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 434 | funcs = encoder->helper_private; |
| 435 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 436 | ret = drm_bridge_mode_fixup(encoder->bridge, &new_crtc_state->mode, |
| 437 | &new_crtc_state->adjusted_mode); |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 438 | if (!ret) { |
| 439 | DRM_DEBUG_ATOMIC("Bridge fixup failed\n"); |
| 440 | return -EINVAL; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 441 | } |
| 442 | |
Noralf Trønnes | 2827635 | 2016-05-11 18:09:20 +0200 | [diff] [blame] | 443 | if (funcs && funcs->atomic_check) { |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 444 | ret = funcs->atomic_check(encoder, new_crtc_state, |
| 445 | new_conn_state); |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 446 | if (ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 447 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] check failed\n", |
| 448 | encoder->base.id, encoder->name); |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 449 | return ret; |
| 450 | } |
Noralf Trønnes | 2827635 | 2016-05-11 18:09:20 +0200 | [diff] [blame] | 451 | } else if (funcs && funcs->mode_fixup) { |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 452 | ret = funcs->mode_fixup(encoder, &new_crtc_state->mode, |
| 453 | &new_crtc_state->adjusted_mode); |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 454 | if (!ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 455 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] fixup failed\n", |
| 456 | encoder->base.id, encoder->name); |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 457 | return -EINVAL; |
| 458 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 462 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 463 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 464 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 465 | if (!new_crtc_state->enable) |
Liu Ying | f55f170 | 2016-05-27 17:35:54 +0800 | [diff] [blame] | 466 | continue; |
| 467 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 468 | if (!new_crtc_state->mode_changed && |
| 469 | !new_crtc_state->connectors_changed) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 470 | continue; |
| 471 | |
| 472 | funcs = crtc->helper_private; |
Ander Conselvan de Oliveira | 840bfe9 | 2015-04-21 17:13:18 +0300 | [diff] [blame] | 473 | if (!funcs->mode_fixup) |
| 474 | continue; |
| 475 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 476 | ret = funcs->mode_fixup(crtc, &new_crtc_state->mode, |
| 477 | &new_crtc_state->adjusted_mode); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 478 | if (!ret) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 479 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] fixup failed\n", |
| 480 | crtc->base.id, crtc->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 481 | return -EINVAL; |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | return 0; |
| 486 | } |
| 487 | |
Jose Abreu | faf94a0 | 2017-05-25 15:19:16 +0100 | [diff] [blame] | 488 | static enum drm_mode_status mode_valid_path(struct drm_connector *connector, |
| 489 | struct drm_encoder *encoder, |
| 490 | struct drm_crtc *crtc, |
| 491 | struct drm_display_mode *mode) |
| 492 | { |
| 493 | enum drm_mode_status ret; |
| 494 | |
| 495 | ret = drm_encoder_mode_valid(encoder, mode); |
| 496 | if (ret != MODE_OK) { |
| 497 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] mode_valid() failed\n", |
| 498 | encoder->base.id, encoder->name); |
| 499 | return ret; |
| 500 | } |
| 501 | |
| 502 | ret = drm_bridge_mode_valid(encoder->bridge, mode); |
| 503 | if (ret != MODE_OK) { |
| 504 | DRM_DEBUG_ATOMIC("[BRIDGE] mode_valid() failed\n"); |
| 505 | return ret; |
| 506 | } |
| 507 | |
| 508 | ret = drm_crtc_mode_valid(crtc, mode); |
| 509 | if (ret != MODE_OK) { |
| 510 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] mode_valid() failed\n", |
| 511 | crtc->base.id, crtc->name); |
| 512 | return ret; |
| 513 | } |
| 514 | |
| 515 | return ret; |
| 516 | } |
| 517 | |
| 518 | static int |
| 519 | mode_valid(struct drm_atomic_state *state) |
| 520 | { |
| 521 | struct drm_connector_state *conn_state; |
| 522 | struct drm_connector *connector; |
| 523 | int i; |
| 524 | |
| 525 | for_each_new_connector_in_state(state, connector, conn_state, i) { |
| 526 | struct drm_encoder *encoder = conn_state->best_encoder; |
| 527 | struct drm_crtc *crtc = conn_state->crtc; |
| 528 | struct drm_crtc_state *crtc_state; |
| 529 | enum drm_mode_status mode_status; |
| 530 | struct drm_display_mode *mode; |
| 531 | |
| 532 | if (!crtc || !encoder) |
| 533 | continue; |
| 534 | |
| 535 | crtc_state = drm_atomic_get_new_crtc_state(state, crtc); |
| 536 | if (!crtc_state) |
| 537 | continue; |
| 538 | if (!crtc_state->mode_changed && !crtc_state->connectors_changed) |
| 539 | continue; |
| 540 | |
| 541 | mode = &crtc_state->mode; |
| 542 | |
| 543 | mode_status = mode_valid_path(connector, encoder, crtc, mode); |
| 544 | if (mode_status != MODE_OK) |
| 545 | return -EINVAL; |
| 546 | } |
| 547 | |
| 548 | return 0; |
| 549 | } |
| 550 | |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 551 | /** |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 552 | * drm_atomic_helper_check_modeset - validate state object for modeset changes |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 553 | * @dev: DRM device |
| 554 | * @state: the driver state object |
| 555 | * |
| 556 | * Check the state object to see if the requested state is physically possible. |
| 557 | * This does all the crtc and connector related computations for an atomic |
Maarten Lankhorst | ce09d76 | 2017-04-06 13:19:03 +0200 | [diff] [blame] | 558 | * update and adds any additional connectors needed for full modesets. It calls |
| 559 | * the various per-object callbacks in the follow order: |
| 560 | * |
| 561 | * 1. &drm_connector_helper_funcs.atomic_best_encoder for determining the new encoder. |
| 562 | * 2. &drm_connector_helper_funcs.atomic_check to validate the connector state. |
| 563 | * 3. If it's determined a modeset is needed then all connectors on the affected crtc |
| 564 | * crtc are added and &drm_connector_helper_funcs.atomic_check is run on them. |
Jose Abreu | faf94a0 | 2017-05-25 15:19:16 +0100 | [diff] [blame] | 565 | * 4. &drm_encoder_helper_funcs.mode_valid, &drm_bridge_funcs.mode_valid and |
| 566 | * &drm_crtc_helper_funcs.mode_valid are called on the affected components. |
| 567 | * 5. &drm_bridge_funcs.mode_fixup is called on all encoder bridges. |
| 568 | * 6. &drm_encoder_helper_funcs.atomic_check is called to validate any encoder state. |
Maarten Lankhorst | ce09d76 | 2017-04-06 13:19:03 +0200 | [diff] [blame] | 569 | * This function is only called when the encoder will be part of a configured crtc, |
| 570 | * it must not be used for implementing connector property validation. |
| 571 | * If this function is NULL, &drm_atomic_encoder_helper_funcs.mode_fixup is called |
| 572 | * instead. |
Jose Abreu | faf94a0 | 2017-05-25 15:19:16 +0100 | [diff] [blame] | 573 | * 7. &drm_crtc_helper_funcs.mode_fixup is called last, to fix up the mode with crtc constraints. |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 574 | * |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 575 | * &drm_crtc_state.mode_changed is set when the input mode is changed. |
| 576 | * &drm_crtc_state.connectors_changed is set when a connector is added or |
| 577 | * removed from the crtc. &drm_crtc_state.active_changed is set when |
| 578 | * &drm_crtc_state.active changes, which is used for DPMS. |
Brian Starkey | d807ed1 | 2016-10-13 10:47:08 +0100 | [diff] [blame] | 579 | * See also: drm_atomic_crtc_needs_modeset() |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 580 | * |
| 581 | * IMPORTANT: |
| 582 | * |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 583 | * Drivers which set &drm_crtc_state.mode_changed (e.g. in their |
| 584 | * &drm_plane_helper_funcs.atomic_check hooks if a plane update can't be done |
| 585 | * without a full modeset) _must_ call this function afterwards after that |
| 586 | * change. It is permitted to call this function multiple times for the same |
| 587 | * update, e.g. when the &drm_crtc_helper_funcs.atomic_check functions depend |
| 588 | * upon the adjusted dotclock for fifo space allocation and watermark |
| 589 | * computation. |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 590 | * |
Daniel Vetter | c39032a | 2016-06-08 14:19:19 +0200 | [diff] [blame] | 591 | * RETURNS: |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 592 | * Zero for success or -errno |
| 593 | */ |
| 594 | int |
Rob Clark | 934ce1c | 2014-11-19 16:41:33 -0500 | [diff] [blame] | 595 | drm_atomic_helper_check_modeset(struct drm_device *dev, |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 596 | struct drm_atomic_state *state) |
| 597 | { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 598 | struct drm_crtc *crtc; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 599 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 600 | struct drm_connector *connector; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 601 | struct drm_connector_state *old_connector_state, *new_connector_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 602 | int i, ret; |
Maarten Lankhorst | ce09d76 | 2017-04-06 13:19:03 +0200 | [diff] [blame] | 603 | unsigned connectors_mask = 0; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 604 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 605 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | 970ece8 | 2017-04-06 13:19:02 +0200 | [diff] [blame] | 606 | bool has_connectors = |
| 607 | !!new_crtc_state->connector_mask; |
| 608 | |
Daniel Vetter | 869e188 | 2017-05-31 10:38:13 +0200 | [diff] [blame] | 609 | WARN_ON(!drm_modeset_is_locked(&crtc->mutex)); |
| 610 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 611 | if (!drm_mode_equal(&old_crtc_state->mode, &new_crtc_state->mode)) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 612 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] mode changed\n", |
| 613 | crtc->base.id, crtc->name); |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 614 | new_crtc_state->mode_changed = true; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 615 | } |
| 616 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 617 | if (old_crtc_state->enable != new_crtc_state->enable) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 618 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enable changed\n", |
| 619 | crtc->base.id, crtc->name); |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 620 | |
| 621 | /* |
| 622 | * For clarity this assignment is done here, but |
| 623 | * enable == 0 is only true when there are no |
| 624 | * connectors and a NULL mode. |
| 625 | * |
| 626 | * The other way around is true as well. enable != 0 |
| 627 | * iff connectors are attached and a mode is set. |
| 628 | */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 629 | new_crtc_state->mode_changed = true; |
| 630 | new_crtc_state->connectors_changed = true; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 631 | } |
Maarten Lankhorst | 24d6652 | 2017-04-06 13:19:01 +0200 | [diff] [blame] | 632 | |
| 633 | if (old_crtc_state->active != new_crtc_state->active) { |
| 634 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] active changed\n", |
| 635 | crtc->base.id, crtc->name); |
| 636 | new_crtc_state->active_changed = true; |
| 637 | } |
Maarten Lankhorst | 970ece8 | 2017-04-06 13:19:02 +0200 | [diff] [blame] | 638 | |
| 639 | if (new_crtc_state->enable != has_connectors) { |
| 640 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enabled/connectors mismatch\n", |
| 641 | crtc->base.id, crtc->name); |
| 642 | |
| 643 | return -EINVAL; |
| 644 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 645 | } |
| 646 | |
Maarten Lankhorst | 44596b8 | 2017-04-06 13:19:00 +0200 | [diff] [blame] | 647 | ret = handle_conflicting_encoders(state, false); |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 648 | if (ret) |
| 649 | return ret; |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 650 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 651 | for_each_oldnew_connector_in_state(state, connector, old_connector_state, new_connector_state, i) { |
Maarten Lankhorst | ce09d76 | 2017-04-06 13:19:03 +0200 | [diff] [blame] | 652 | const struct drm_connector_helper_funcs *funcs = connector->helper_private; |
| 653 | |
Daniel Vetter | 869e188 | 2017-05-31 10:38:13 +0200 | [diff] [blame] | 654 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
| 655 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 656 | /* |
Brian Starkey | d807ed1 | 2016-10-13 10:47:08 +0100 | [diff] [blame] | 657 | * This only sets crtc->connectors_changed for routing changes, |
| 658 | * drivers must set crtc->connectors_changed themselves when |
| 659 | * connector properties need to be updated. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 660 | */ |
Maarten Lankhorst | 9459545 | 2016-02-24 09:37:29 +0100 | [diff] [blame] | 661 | ret = update_connector_routing(state, connector, |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 662 | old_connector_state, |
| 663 | new_connector_state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 664 | if (ret) |
| 665 | return ret; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 666 | if (old_connector_state->crtc) { |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 667 | new_crtc_state = drm_atomic_get_new_crtc_state(state, |
| 668 | old_connector_state->crtc); |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 669 | if (old_connector_state->link_status != |
| 670 | new_connector_state->link_status) |
| 671 | new_crtc_state->connectors_changed = true; |
Radhakrishna Sripada | 47e22ff | 2018-10-12 11:42:32 -0700 | [diff] [blame] | 672 | |
| 673 | if (old_connector_state->max_requested_bpc != |
| 674 | new_connector_state->max_requested_bpc) |
| 675 | new_crtc_state->connectors_changed = true; |
Manasi Navare | 40ee6fb | 2016-12-16 12:29:06 +0200 | [diff] [blame] | 676 | } |
Maarten Lankhorst | ce09d76 | 2017-04-06 13:19:03 +0200 | [diff] [blame] | 677 | |
| 678 | if (funcs->atomic_check) |
| 679 | ret = funcs->atomic_check(connector, new_connector_state); |
| 680 | if (ret) |
| 681 | return ret; |
| 682 | |
Ville Syrjälä | ca52bea | 2018-06-15 20:07:34 +0300 | [diff] [blame] | 683 | connectors_mask |= BIT(i); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | /* |
| 687 | * After all the routing has been prepared we need to add in any |
| 688 | * connector which is itself unchanged, but who's crtc changes it's |
| 689 | * configuration. This must be done before calling mode_fixup in case a |
| 690 | * crtc only changed its mode but has the same set of connectors. |
| 691 | */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 692 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 693 | if (!drm_atomic_crtc_needs_modeset(new_crtc_state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 694 | continue; |
| 695 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 696 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] needs all connectors, enable: %c, active: %c\n", |
| 697 | crtc->base.id, crtc->name, |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 698 | new_crtc_state->enable ? 'y' : 'n', |
| 699 | new_crtc_state->active ? 'y' : 'n'); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 700 | |
| 701 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 702 | if (ret != 0) |
| 703 | return ret; |
| 704 | |
Maarten Lankhorst | 57744aa | 2015-05-19 16:41:03 +0200 | [diff] [blame] | 705 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 706 | if (ret != 0) |
| 707 | return ret; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 708 | } |
| 709 | |
Maarten Lankhorst | ce09d76 | 2017-04-06 13:19:03 +0200 | [diff] [blame] | 710 | /* |
| 711 | * Iterate over all connectors again, to make sure atomic_check() |
| 712 | * has been called on them when a modeset is forced. |
| 713 | */ |
| 714 | for_each_oldnew_connector_in_state(state, connector, old_connector_state, new_connector_state, i) { |
| 715 | const struct drm_connector_helper_funcs *funcs = connector->helper_private; |
| 716 | |
| 717 | if (connectors_mask & BIT(i)) |
| 718 | continue; |
| 719 | |
| 720 | if (funcs->atomic_check) |
| 721 | ret = funcs->atomic_check(connector, new_connector_state); |
| 722 | if (ret) |
| 723 | return ret; |
| 724 | } |
| 725 | |
Jose Abreu | faf94a0 | 2017-05-25 15:19:16 +0100 | [diff] [blame] | 726 | ret = mode_valid(state); |
| 727 | if (ret) |
| 728 | return ret; |
| 729 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 730 | return mode_fixup(state); |
| 731 | } |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 732 | EXPORT_SYMBOL(drm_atomic_helper_check_modeset); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 733 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 734 | /** |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 735 | * drm_atomic_helper_check_plane_state() - Check plane state for validity |
| 736 | * @plane_state: plane state to check |
| 737 | * @crtc_state: crtc state to check |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 738 | * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point |
| 739 | * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point |
| 740 | * @can_position: is it legal to position the plane such that it |
| 741 | * doesn't cover the entire crtc? This will generally |
| 742 | * only be false for primary planes. |
| 743 | * @can_update_disabled: can the plane be updated while the crtc |
| 744 | * is disabled? |
| 745 | * |
| 746 | * Checks that a desired plane update is valid, and updates various |
| 747 | * bits of derived state (clipped coordinates etc.). Drivers that provide |
| 748 | * their own plane handling rather than helper-provided implementations may |
| 749 | * still wish to call this function to avoid duplication of error checking |
| 750 | * code. |
| 751 | * |
| 752 | * RETURNS: |
| 753 | * Zero if update appears valid, error code on failure |
| 754 | */ |
| 755 | int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state, |
| 756 | const struct drm_crtc_state *crtc_state, |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 757 | int min_scale, |
| 758 | int max_scale, |
| 759 | bool can_position, |
| 760 | bool can_update_disabled) |
| 761 | { |
| 762 | struct drm_framebuffer *fb = plane_state->fb; |
| 763 | struct drm_rect *src = &plane_state->src; |
| 764 | struct drm_rect *dst = &plane_state->dst; |
| 765 | unsigned int rotation = plane_state->rotation; |
Ville Syrjälä | 81af63a | 2018-01-23 19:08:57 +0200 | [diff] [blame] | 766 | struct drm_rect clip = {}; |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 767 | int hscale, vscale; |
| 768 | |
| 769 | WARN_ON(plane_state->crtc && plane_state->crtc != crtc_state->crtc); |
| 770 | |
| 771 | *src = drm_plane_state_src(plane_state); |
| 772 | *dst = drm_plane_state_dest(plane_state); |
| 773 | |
| 774 | if (!fb) { |
| 775 | plane_state->visible = false; |
| 776 | return 0; |
| 777 | } |
| 778 | |
| 779 | /* crtc should only be NULL when disabling (i.e., !fb) */ |
| 780 | if (WARN_ON(!plane_state->crtc)) { |
| 781 | plane_state->visible = false; |
| 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | if (!crtc_state->enable && !can_update_disabled) { |
| 786 | DRM_DEBUG_KMS("Cannot update plane of a disabled CRTC.\n"); |
| 787 | return -EINVAL; |
| 788 | } |
| 789 | |
| 790 | drm_rect_rotate(src, fb->width << 16, fb->height << 16, rotation); |
| 791 | |
| 792 | /* Check scaling */ |
| 793 | hscale = drm_rect_calc_hscale(src, dst, min_scale, max_scale); |
| 794 | vscale = drm_rect_calc_vscale(src, dst, min_scale, max_scale); |
| 795 | if (hscale < 0 || vscale < 0) { |
| 796 | DRM_DEBUG_KMS("Invalid scaling of plane\n"); |
| 797 | drm_rect_debug_print("src: ", &plane_state->src, true); |
| 798 | drm_rect_debug_print("dst: ", &plane_state->dst, false); |
| 799 | return -ERANGE; |
| 800 | } |
| 801 | |
Ville Syrjälä | 81af63a | 2018-01-23 19:08:57 +0200 | [diff] [blame] | 802 | if (crtc_state->enable) |
| 803 | drm_mode_get_hv_timing(&crtc_state->mode, &clip.x2, &clip.y2); |
| 804 | |
Maarten Lankhorst | f96bdf5 | 2018-05-03 13:22:14 +0200 | [diff] [blame] | 805 | plane_state->visible = drm_rect_clip_scaled(src, dst, &clip); |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 806 | |
| 807 | drm_rect_rotate_inv(src, fb->width << 16, fb->height << 16, rotation); |
| 808 | |
| 809 | if (!plane_state->visible) |
| 810 | /* |
| 811 | * Plane isn't visible; some drivers can handle this |
| 812 | * so we just return success here. Drivers that can't |
| 813 | * (including those that use the primary plane helper's |
| 814 | * update function) will return an error from their |
| 815 | * update_plane handler. |
| 816 | */ |
| 817 | return 0; |
| 818 | |
Ville Syrjälä | 81af63a | 2018-01-23 19:08:57 +0200 | [diff] [blame] | 819 | if (!can_position && !drm_rect_equals(dst, &clip)) { |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 820 | DRM_DEBUG_KMS("Plane must cover entire CRTC\n"); |
| 821 | drm_rect_debug_print("dst: ", dst, false); |
Ville Syrjälä | 81af63a | 2018-01-23 19:08:57 +0200 | [diff] [blame] | 822 | drm_rect_debug_print("clip: ", &clip, false); |
Ville Syrjälä | a01cb8b | 2017-11-01 22:16:19 +0200 | [diff] [blame] | 823 | return -EINVAL; |
| 824 | } |
| 825 | |
| 826 | return 0; |
| 827 | } |
| 828 | EXPORT_SYMBOL(drm_atomic_helper_check_plane_state); |
| 829 | |
| 830 | /** |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 831 | * drm_atomic_helper_check_planes - validate state object for planes changes |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 832 | * @dev: DRM device |
| 833 | * @state: the driver state object |
| 834 | * |
| 835 | * Check the state object to see if the requested state is physically possible. |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 836 | * This does all the plane update related checks using by calling into the |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 837 | * &drm_crtc_helper_funcs.atomic_check and &drm_plane_helper_funcs.atomic_check |
| 838 | * hooks provided by the driver. |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 839 | * |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 840 | * It also sets &drm_crtc_state.planes_changed to indicate that a crtc has |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 841 | * updated planes. |
| 842 | * |
Daniel Vetter | c39032a | 2016-06-08 14:19:19 +0200 | [diff] [blame] | 843 | * RETURNS: |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 844 | * Zero for success or -errno |
| 845 | */ |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 846 | int |
| 847 | drm_atomic_helper_check_planes(struct drm_device *dev, |
| 848 | struct drm_atomic_state *state) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 849 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 850 | struct drm_crtc *crtc; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 851 | struct drm_crtc_state *new_crtc_state; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 852 | struct drm_plane *plane; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 853 | struct drm_plane_state *new_plane_state, *old_plane_state; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 854 | int i, ret = 0; |
| 855 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 856 | for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 857 | const struct drm_plane_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 858 | |
Daniel Vetter | 869e188 | 2017-05-31 10:38:13 +0200 | [diff] [blame] | 859 | WARN_ON(!drm_modeset_is_locked(&plane->mutex)); |
| 860 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 861 | funcs = plane->helper_private; |
| 862 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 863 | drm_atomic_helper_plane_changed(state, old_plane_state, new_plane_state, plane); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 864 | |
| 865 | if (!funcs || !funcs->atomic_check) |
| 866 | continue; |
| 867 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 868 | ret = funcs->atomic_check(plane, new_plane_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 869 | if (ret) { |
Ville Syrjälä | 9f4c97a | 2015-12-08 18:41:54 +0200 | [diff] [blame] | 870 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] atomic driver check failed\n", |
| 871 | plane->base.id, plane->name); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 872 | return ret; |
| 873 | } |
| 874 | } |
| 875 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 876 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 877 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 878 | |
| 879 | funcs = crtc->helper_private; |
| 880 | |
| 881 | if (!funcs || !funcs->atomic_check) |
| 882 | continue; |
| 883 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 884 | ret = funcs->atomic_check(crtc, new_crtc_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 885 | if (ret) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 886 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic driver check failed\n", |
| 887 | crtc->base.id, crtc->name); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 888 | return ret; |
| 889 | } |
| 890 | } |
| 891 | |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 892 | return ret; |
| 893 | } |
| 894 | EXPORT_SYMBOL(drm_atomic_helper_check_planes); |
| 895 | |
| 896 | /** |
| 897 | * drm_atomic_helper_check - validate state object |
| 898 | * @dev: DRM device |
| 899 | * @state: the driver state object |
| 900 | * |
| 901 | * Check the state object to see if the requested state is physically possible. |
| 902 | * Only crtcs and planes have check callbacks, so for any additional (global) |
| 903 | * checking that a driver needs it can simply wrap that around this function. |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 904 | * Drivers without such needs can directly use this as their |
| 905 | * &drm_mode_config_funcs.atomic_check callback. |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 906 | * |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 907 | * This just wraps the two parts of the state checking for planes and modeset |
| 908 | * state in the default order: First it calls drm_atomic_helper_check_modeset() |
| 909 | * and then drm_atomic_helper_check_planes(). The assumption is that the |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 910 | * @drm_plane_helper_funcs.atomic_check and @drm_crtc_helper_funcs.atomic_check |
| 911 | * functions depend upon an updated adjusted_mode.clock to e.g. properly compute |
| 912 | * watermarks. |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 913 | * |
Peter Ujfalusi | 49efffc | 2018-03-21 12:20:24 +0200 | [diff] [blame] | 914 | * Note that zpos normalization will add all enable planes to the state which |
| 915 | * might not desired for some drivers. |
| 916 | * For example enable/disable of a cursor plane which have fixed zpos value |
| 917 | * would trigger all other enabled planes to be forced to the state change. |
| 918 | * |
Daniel Vetter | c39032a | 2016-06-08 14:19:19 +0200 | [diff] [blame] | 919 | * RETURNS: |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 920 | * Zero for success or -errno |
| 921 | */ |
| 922 | int drm_atomic_helper_check(struct drm_device *dev, |
| 923 | struct drm_atomic_state *state) |
| 924 | { |
| 925 | int ret; |
| 926 | |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 927 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 928 | if (ret) |
| 929 | return ret; |
| 930 | |
Peter Ujfalusi | 49efffc | 2018-03-21 12:20:24 +0200 | [diff] [blame] | 931 | if (dev->mode_config.normalize_zpos) { |
| 932 | ret = drm_atomic_normalize_zpos(dev, state); |
| 933 | if (ret) |
| 934 | return ret; |
| 935 | } |
| 936 | |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 937 | ret = drm_atomic_helper_check_planes(dev, state); |
Rob Clark | 934ce1c | 2014-11-19 16:41:33 -0500 | [diff] [blame] | 938 | if (ret) |
| 939 | return ret; |
| 940 | |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 941 | if (state->legacy_cursor_update) |
| 942 | state->async_update = !drm_atomic_helper_async_check(dev, state); |
| 943 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 944 | return ret; |
| 945 | } |
| 946 | EXPORT_SYMBOL(drm_atomic_helper_check); |
| 947 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 948 | static void |
| 949 | disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state) |
| 950 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 951 | struct drm_connector *connector; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 952 | struct drm_connector_state *old_conn_state, *new_conn_state; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 953 | struct drm_crtc *crtc; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 954 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 955 | int i; |
| 956 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 957 | for_each_oldnew_connector_in_state(old_state, connector, old_conn_state, new_conn_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 958 | const struct drm_encoder_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 959 | struct drm_encoder *encoder; |
| 960 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 961 | /* Shut down everything that's in the changeset and currently |
| 962 | * still on. So need to check the old, saved state. */ |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 963 | if (!old_conn_state->crtc) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 964 | continue; |
| 965 | |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 966 | old_crtc_state = drm_atomic_get_old_crtc_state(old_state, old_conn_state->crtc); |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 967 | |
Daniel Vetter | 4218a32 | 2015-03-26 22:18:40 +0100 | [diff] [blame] | 968 | if (!old_crtc_state->active || |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 969 | !drm_atomic_crtc_needs_modeset(old_conn_state->crtc->state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 970 | continue; |
| 971 | |
Rob Clark | 46df9ad | 2014-11-20 15:40:36 -0500 | [diff] [blame] | 972 | encoder = old_conn_state->best_encoder; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 973 | |
Rob Clark | 46df9ad | 2014-11-20 15:40:36 -0500 | [diff] [blame] | 974 | /* We shouldn't get this far if we didn't previously have |
| 975 | * an encoder.. but WARN_ON() rather than explode. |
| 976 | */ |
| 977 | if (WARN_ON(!encoder)) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 978 | continue; |
| 979 | |
| 980 | funcs = encoder->helper_private; |
| 981 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 982 | DRM_DEBUG_ATOMIC("disabling [ENCODER:%d:%s]\n", |
| 983 | encoder->base.id, encoder->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 984 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 985 | /* |
| 986 | * Each encoder has at most one connector (since we always steal |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 987 | * it away), so we won't call disable hooks twice. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 988 | */ |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 989 | drm_bridge_disable(encoder->bridge); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 990 | |
| 991 | /* Right function depends upon target state. */ |
Noralf Trønnes | 2827635 | 2016-05-11 18:09:20 +0200 | [diff] [blame] | 992 | if (funcs) { |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 993 | if (new_conn_state->crtc && funcs->prepare) |
Noralf Trønnes | 2827635 | 2016-05-11 18:09:20 +0200 | [diff] [blame] | 994 | funcs->prepare(encoder); |
| 995 | else if (funcs->disable) |
| 996 | funcs->disable(encoder); |
| 997 | else if (funcs->dpms) |
| 998 | funcs->dpms(encoder, DRM_MODE_DPMS_OFF); |
| 999 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1000 | |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 1001 | drm_bridge_post_disable(encoder->bridge); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1002 | } |
| 1003 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1004 | for_each_oldnew_crtc_in_state(old_state, crtc, old_crtc_state, new_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1005 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | 84014b0 | 2017-10-17 17:27:14 +0200 | [diff] [blame] | 1006 | int ret; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1007 | |
| 1008 | /* Shut down everything that needs a full modeset. */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1009 | if (!drm_atomic_crtc_needs_modeset(new_crtc_state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 1010 | continue; |
| 1011 | |
| 1012 | if (!old_crtc_state->active) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1013 | continue; |
| 1014 | |
| 1015 | funcs = crtc->helper_private; |
| 1016 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 1017 | DRM_DEBUG_ATOMIC("disabling [CRTC:%d:%s]\n", |
| 1018 | crtc->base.id, crtc->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 1019 | |
| 1020 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1021 | /* Right function depends upon target state. */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1022 | if (new_crtc_state->enable && funcs->prepare) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1023 | funcs->prepare(crtc); |
Liu Ying | c9ac8b4 | 2016-08-26 15:30:38 +0800 | [diff] [blame] | 1024 | else if (funcs->atomic_disable) |
| 1025 | funcs->atomic_disable(crtc, old_crtc_state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1026 | else if (funcs->disable) |
| 1027 | funcs->disable(crtc); |
| 1028 | else |
| 1029 | funcs->dpms(crtc, DRM_MODE_DPMS_OFF); |
Daniel Vetter | 84014b0 | 2017-10-17 17:27:14 +0200 | [diff] [blame] | 1030 | |
| 1031 | if (!(dev->irq_enabled && dev->num_crtcs)) |
| 1032 | continue; |
| 1033 | |
| 1034 | ret = drm_crtc_vblank_get(crtc); |
| 1035 | WARN_ONCE(ret != -EINVAL, "driver forgot to call drm_crtc_vblank_off()\n"); |
| 1036 | if (ret == 0) |
| 1037 | drm_crtc_vblank_put(crtc); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1038 | } |
| 1039 | } |
| 1040 | |
Daniel Vetter | 4c18d30 | 2015-05-12 15:27:37 +0200 | [diff] [blame] | 1041 | /** |
| 1042 | * drm_atomic_helper_update_legacy_modeset_state - update legacy modeset state |
| 1043 | * @dev: DRM device |
| 1044 | * @old_state: atomic state object with old state structures |
| 1045 | * |
| 1046 | * This function updates all the various legacy modeset state pointers in |
| 1047 | * connectors, encoders and crtcs. It also updates the timestamping constants |
| 1048 | * used for precise vblank timestamps by calling |
| 1049 | * drm_calc_timestamping_constants(). |
| 1050 | * |
| 1051 | * Drivers can use this for building their own atomic commit if they don't have |
| 1052 | * a pure helper-based modeset implementation. |
Daniel Vetter | 2e2b96e | 2017-11-08 21:30:07 +0100 | [diff] [blame] | 1053 | * |
| 1054 | * Since these updates are not synchronized with lockings, only code paths |
| 1055 | * called from &drm_mode_config_helper_funcs.atomic_commit_tail can look at the |
| 1056 | * legacy state filled out by this helper. Defacto this means this helper and |
| 1057 | * the legacy state pointers are only really useful for transitioning an |
| 1058 | * existing driver to the atomic world. |
Daniel Vetter | 4c18d30 | 2015-05-12 15:27:37 +0200 | [diff] [blame] | 1059 | */ |
| 1060 | void |
| 1061 | drm_atomic_helper_update_legacy_modeset_state(struct drm_device *dev, |
| 1062 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1063 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1064 | struct drm_connector *connector; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1065 | struct drm_connector_state *old_conn_state, *new_conn_state; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1066 | struct drm_crtc *crtc; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1067 | struct drm_crtc_state *new_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1068 | int i; |
| 1069 | |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 1070 | /* clear out existing links and update dpms */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1071 | for_each_oldnew_connector_in_state(old_state, connector, old_conn_state, new_conn_state, i) { |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 1072 | if (connector->encoder) { |
| 1073 | WARN_ON(!connector->encoder->crtc); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1074 | |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 1075 | connector->encoder->crtc = NULL; |
| 1076 | connector->encoder = NULL; |
| 1077 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1078 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1079 | crtc = new_conn_state->crtc; |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 1080 | if ((!crtc && old_conn_state->crtc) || |
| 1081 | (crtc && drm_atomic_crtc_needs_modeset(crtc->state))) { |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 1082 | int mode = DRM_MODE_DPMS_OFF; |
| 1083 | |
| 1084 | if (crtc && crtc->state->active) |
| 1085 | mode = DRM_MODE_DPMS_ON; |
| 1086 | |
| 1087 | connector->dpms = mode; |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 1088 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | /* set new links */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1092 | for_each_new_connector_in_state(old_state, connector, new_conn_state, i) { |
| 1093 | if (!new_conn_state->crtc) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1094 | continue; |
| 1095 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1096 | if (WARN_ON(!new_conn_state->best_encoder)) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1097 | continue; |
| 1098 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1099 | connector->encoder = new_conn_state->best_encoder; |
| 1100 | connector->encoder->crtc = new_conn_state->crtc; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | /* set legacy state in the crtc structure */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1104 | for_each_new_crtc_in_state(old_state, crtc, new_crtc_state, i) { |
Maarten Lankhorst | 2660801 | 2015-07-16 15:51:01 +0200 | [diff] [blame] | 1105 | struct drm_plane *primary = crtc->primary; |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 1106 | struct drm_plane_state *new_plane_state; |
Maarten Lankhorst | 2660801 | 2015-07-16 15:51:01 +0200 | [diff] [blame] | 1107 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1108 | crtc->mode = new_crtc_state->mode; |
| 1109 | crtc->enabled = new_crtc_state->enable; |
Maarten Lankhorst | 2660801 | 2015-07-16 15:51:01 +0200 | [diff] [blame] | 1110 | |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 1111 | new_plane_state = |
| 1112 | drm_atomic_get_new_plane_state(old_state, primary); |
| 1113 | |
| 1114 | if (new_plane_state && new_plane_state->crtc == crtc) { |
| 1115 | crtc->x = new_plane_state->src_x >> 16; |
| 1116 | crtc->y = new_plane_state->src_y >> 16; |
Maarten Lankhorst | 2660801 | 2015-07-16 15:51:01 +0200 | [diff] [blame] | 1117 | } |
Daniel Vetter | 3d51d2d | 2015-05-12 15:21:06 +0200 | [diff] [blame] | 1118 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1119 | if (new_crtc_state->enable) |
Daniel Vetter | 3d51d2d | 2015-05-12 15:21:06 +0200 | [diff] [blame] | 1120 | drm_calc_timestamping_constants(crtc, |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1121 | &new_crtc_state->adjusted_mode); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1122 | } |
| 1123 | } |
Daniel Vetter | 4c18d30 | 2015-05-12 15:27:37 +0200 | [diff] [blame] | 1124 | EXPORT_SYMBOL(drm_atomic_helper_update_legacy_modeset_state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1125 | |
| 1126 | static void |
| 1127 | crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state) |
| 1128 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1129 | struct drm_crtc *crtc; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1130 | struct drm_crtc_state *new_crtc_state; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1131 | struct drm_connector *connector; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1132 | struct drm_connector_state *new_conn_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1133 | int i; |
| 1134 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1135 | for_each_new_crtc_in_state(old_state, crtc, new_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1136 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1137 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1138 | if (!new_crtc_state->mode_changed) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1139 | continue; |
| 1140 | |
| 1141 | funcs = crtc->helper_private; |
| 1142 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1143 | if (new_crtc_state->enable && funcs->mode_set_nofb) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 1144 | DRM_DEBUG_ATOMIC("modeset on [CRTC:%d:%s]\n", |
| 1145 | crtc->base.id, crtc->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 1146 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1147 | funcs->mode_set_nofb(crtc); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 1148 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1149 | } |
| 1150 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1151 | for_each_new_connector_in_state(old_state, connector, new_conn_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1152 | const struct drm_encoder_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1153 | struct drm_encoder *encoder; |
| 1154 | struct drm_display_mode *mode, *adjusted_mode; |
| 1155 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1156 | if (!new_conn_state->best_encoder) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1157 | continue; |
| 1158 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1159 | encoder = new_conn_state->best_encoder; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1160 | funcs = encoder->helper_private; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1161 | new_crtc_state = new_conn_state->crtc->state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1162 | mode = &new_crtc_state->mode; |
| 1163 | adjusted_mode = &new_crtc_state->adjusted_mode; |
| 1164 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 1165 | if (!new_crtc_state->mode_changed) |
| 1166 | continue; |
| 1167 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 1168 | DRM_DEBUG_ATOMIC("modeset on [ENCODER:%d:%s]\n", |
| 1169 | encoder->base.id, encoder->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 1170 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1171 | /* |
| 1172 | * Each encoder has at most one connector (since we always steal |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 1173 | * it away), so we won't call mode_set hooks twice. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1174 | */ |
Philipp Zabel | fe4a11c | 2016-07-22 12:20:47 +0200 | [diff] [blame] | 1175 | if (funcs && funcs->atomic_mode_set) { |
| 1176 | funcs->atomic_mode_set(encoder, new_crtc_state, |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1177 | new_conn_state); |
Philipp Zabel | fe4a11c | 2016-07-22 12:20:47 +0200 | [diff] [blame] | 1178 | } else if (funcs && funcs->mode_set) { |
Daniel Vetter | c982bd9 | 2015-02-22 12:24:20 +0100 | [diff] [blame] | 1179 | funcs->mode_set(encoder, mode, adjusted_mode); |
Philipp Zabel | fe4a11c | 2016-07-22 12:20:47 +0200 | [diff] [blame] | 1180 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1181 | |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 1182 | drm_bridge_mode_set(encoder->bridge, mode, adjusted_mode); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1183 | } |
| 1184 | } |
| 1185 | |
| 1186 | /** |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1187 | * drm_atomic_helper_commit_modeset_disables - modeset commit to disable outputs |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1188 | * @dev: DRM device |
Laurent Pinchart | a072f80 | 2015-02-22 12:24:18 +0100 | [diff] [blame] | 1189 | * @old_state: atomic state object with old state structures |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1190 | * |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1191 | * This function shuts down all the outputs that need to be shut down and |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1192 | * prepares them (if required) with the new mode. |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1193 | * |
Laurent Pinchart | 60acc4e | 2015-05-27 15:05:42 +0300 | [diff] [blame] | 1194 | * For compatibility with legacy crtc helpers this should be called before |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1195 | * drm_atomic_helper_commit_planes(), which is what the default commit function |
| 1196 | * does. But drivers with different needs can group the modeset commits together |
| 1197 | * and do the plane commits at the end. This is useful for drivers doing runtime |
| 1198 | * PM since planes updates then only happen when the CRTC is actually enabled. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1199 | */ |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1200 | void drm_atomic_helper_commit_modeset_disables(struct drm_device *dev, |
| 1201 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1202 | { |
Laurent Pinchart | a072f80 | 2015-02-22 12:24:18 +0100 | [diff] [blame] | 1203 | disable_outputs(dev, old_state); |
Daniel Vetter | 4c18d30 | 2015-05-12 15:27:37 +0200 | [diff] [blame] | 1204 | |
| 1205 | drm_atomic_helper_update_legacy_modeset_state(dev, old_state); |
| 1206 | |
Laurent Pinchart | a072f80 | 2015-02-22 12:24:18 +0100 | [diff] [blame] | 1207 | crtc_set_mode(dev, old_state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1208 | } |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1209 | EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_disables); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1210 | |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 1211 | static void drm_atomic_helper_commit_writebacks(struct drm_device *dev, |
| 1212 | struct drm_atomic_state *old_state) |
| 1213 | { |
| 1214 | struct drm_connector *connector; |
| 1215 | struct drm_connector_state *new_conn_state; |
| 1216 | int i; |
| 1217 | |
| 1218 | for_each_new_connector_in_state(old_state, connector, new_conn_state, i) { |
| 1219 | const struct drm_connector_helper_funcs *funcs; |
| 1220 | |
| 1221 | funcs = connector->helper_private; |
Boris Brezillon | 814bde9 | 2018-07-03 09:50:17 +0200 | [diff] [blame] | 1222 | if (!funcs->atomic_commit) |
| 1223 | continue; |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 1224 | |
| 1225 | if (new_conn_state->writeback_job && new_conn_state->writeback_job->fb) { |
| 1226 | WARN_ON(connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK); |
Boris Brezillon | 425132f | 2018-07-03 09:50:16 +0200 | [diff] [blame] | 1227 | funcs->atomic_commit(connector, new_conn_state); |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 1228 | } |
| 1229 | } |
| 1230 | } |
| 1231 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1232 | /** |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1233 | * drm_atomic_helper_commit_modeset_enables - modeset commit to enable outputs |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1234 | * @dev: DRM device |
| 1235 | * @old_state: atomic state object with old state structures |
| 1236 | * |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1237 | * This function enables all the outputs with the new configuration which had to |
| 1238 | * be turned off for the update. |
| 1239 | * |
Laurent Pinchart | 60acc4e | 2015-05-27 15:05:42 +0300 | [diff] [blame] | 1240 | * For compatibility with legacy crtc helpers this should be called after |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1241 | * drm_atomic_helper_commit_planes(), which is what the default commit function |
| 1242 | * does. But drivers with different needs can group the modeset commits together |
| 1243 | * and do the plane commits at the end. This is useful for drivers doing runtime |
| 1244 | * PM since planes updates then only happen when the CRTC is actually enabled. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1245 | */ |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1246 | void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, |
| 1247 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1248 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1249 | struct drm_crtc *crtc; |
Laurent Pinchart | 0b20a0f | 2017-06-30 12:36:44 +0300 | [diff] [blame] | 1250 | struct drm_crtc_state *old_crtc_state; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1251 | struct drm_crtc_state *new_crtc_state; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1252 | struct drm_connector *connector; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1253 | struct drm_connector_state *new_conn_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1254 | int i; |
| 1255 | |
Laurent Pinchart | 0b20a0f | 2017-06-30 12:36:44 +0300 | [diff] [blame] | 1256 | for_each_oldnew_crtc_in_state(old_state, crtc, old_crtc_state, new_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1257 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1258 | |
| 1259 | /* Need to filter out CRTCs where only planes change. */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1260 | if (!drm_atomic_crtc_needs_modeset(new_crtc_state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 1261 | continue; |
| 1262 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1263 | if (!new_crtc_state->active) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1264 | continue; |
| 1265 | |
| 1266 | funcs = crtc->helper_private; |
| 1267 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1268 | if (new_crtc_state->enable) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 1269 | DRM_DEBUG_ATOMIC("enabling [CRTC:%d:%s]\n", |
| 1270 | crtc->base.id, crtc->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 1271 | |
Laurent Pinchart | 0b20a0f | 2017-06-30 12:36:44 +0300 | [diff] [blame] | 1272 | if (funcs->atomic_enable) |
| 1273 | funcs->atomic_enable(crtc, old_crtc_state); |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 1274 | else |
| 1275 | funcs->commit(crtc); |
| 1276 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1277 | } |
| 1278 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1279 | for_each_new_connector_in_state(old_state, connector, new_conn_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1280 | const struct drm_encoder_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1281 | struct drm_encoder *encoder; |
| 1282 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1283 | if (!new_conn_state->best_encoder) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1284 | continue; |
| 1285 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1286 | if (!new_conn_state->crtc->state->active || |
| 1287 | !drm_atomic_crtc_needs_modeset(new_conn_state->crtc->state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 1288 | continue; |
| 1289 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1290 | encoder = new_conn_state->best_encoder; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1291 | funcs = encoder->helper_private; |
| 1292 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 1293 | DRM_DEBUG_ATOMIC("enabling [ENCODER:%d:%s]\n", |
| 1294 | encoder->base.id, encoder->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 1295 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1296 | /* |
| 1297 | * Each encoder has at most one connector (since we always steal |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 1298 | * it away), so we won't call enable hooks twice. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1299 | */ |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 1300 | drm_bridge_pre_enable(encoder->bridge); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1301 | |
Noralf Trønnes | 2827635 | 2016-05-11 18:09:20 +0200 | [diff] [blame] | 1302 | if (funcs) { |
| 1303 | if (funcs->enable) |
| 1304 | funcs->enable(encoder); |
| 1305 | else if (funcs->commit) |
| 1306 | funcs->commit(encoder); |
| 1307 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1308 | |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 1309 | drm_bridge_enable(encoder->bridge); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1310 | } |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 1311 | |
| 1312 | drm_atomic_helper_commit_writebacks(dev, old_state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1313 | } |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1314 | EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_enables); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1315 | |
Rob Clark | 4c5b7f3 | 2016-03-18 19:14:55 -0400 | [diff] [blame] | 1316 | /** |
| 1317 | * drm_atomic_helper_wait_for_fences - wait for fences stashed in plane state |
| 1318 | * @dev: DRM device |
| 1319 | * @state: atomic state object with old state structures |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1320 | * @pre_swap: If true, do an interruptible wait, and @state is the new state. |
| 1321 | * Otherwise @state is the old state. |
Rob Clark | 4c5b7f3 | 2016-03-18 19:14:55 -0400 | [diff] [blame] | 1322 | * |
| 1323 | * For implicit sync, driver should fish the exclusive fence out from the |
| 1324 | * incoming fb's and stash it in the drm_plane_state. This is called after |
| 1325 | * drm_atomic_helper_swap_state() so it uses the current plane state (and |
| 1326 | * just uses the atomic state to find the changed planes) |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1327 | * |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1328 | * Note that @pre_swap is needed since the point where we block for fences moves |
| 1329 | * around depending upon whether an atomic commit is blocking or |
Gustavo Padovan | 4259037 | 2017-04-27 11:35:06 -0300 | [diff] [blame] | 1330 | * non-blocking. For non-blocking commit all waiting needs to happen after |
| 1331 | * drm_atomic_helper_swap_state() is called, but for blocking commits we want |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1332 | * to wait **before** we do anything that can't be easily rolled back. That is |
| 1333 | * before we call drm_atomic_helper_swap_state(). |
| 1334 | * |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 1335 | * Returns zero if success or < 0 if dma_fence_wait() fails. |
Rob Clark | 4c5b7f3 | 2016-03-18 19:14:55 -0400 | [diff] [blame] | 1336 | */ |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1337 | int drm_atomic_helper_wait_for_fences(struct drm_device *dev, |
| 1338 | struct drm_atomic_state *state, |
| 1339 | bool pre_swap) |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1340 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1341 | struct drm_plane *plane; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1342 | struct drm_plane_state *new_plane_state; |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1343 | int i, ret; |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1344 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1345 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 1346 | if (!new_plane_state->fence) |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1347 | continue; |
| 1348 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1349 | WARN_ON(!new_plane_state->fb); |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1350 | |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1351 | /* |
| 1352 | * If waiting for fences pre-swap (ie: nonblock), userspace can |
| 1353 | * still interrupt the operation. Instead of blocking until the |
| 1354 | * timer expires, make the wait interruptible. |
| 1355 | */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1356 | ret = dma_fence_wait(new_plane_state->fence, pre_swap); |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1357 | if (ret) |
| 1358 | return ret; |
| 1359 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1360 | dma_fence_put(new_plane_state->fence); |
| 1361 | new_plane_state->fence = NULL; |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1362 | } |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1363 | |
| 1364 | return 0; |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1365 | } |
Rob Clark | 4c5b7f3 | 2016-03-18 19:14:55 -0400 | [diff] [blame] | 1366 | EXPORT_SYMBOL(drm_atomic_helper_wait_for_fences); |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1367 | |
John Keeping | c240906 | 2016-01-19 10:46:58 +0000 | [diff] [blame] | 1368 | /** |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 1369 | * drm_atomic_helper_wait_for_vblanks - wait for vblank on crtcs |
| 1370 | * @dev: DRM device |
| 1371 | * @old_state: atomic state object with old state structures |
| 1372 | * |
| 1373 | * Helper to, after atomic commit, wait for vblanks on all effected |
| 1374 | * crtcs (ie. before cleaning up old framebuffers using |
Boris Brezillon | 0108648 | 2017-06-02 10:32:06 +0200 | [diff] [blame] | 1375 | * drm_atomic_helper_cleanup_planes()). It will only wait on CRTCs where the |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 1376 | * framebuffers have actually changed to optimize for the legacy cursor and |
| 1377 | * plane update use-case. |
Boris Brezillon | 0108648 | 2017-06-02 10:32:06 +0200 | [diff] [blame] | 1378 | * |
| 1379 | * Drivers using the nonblocking commit tracking support initialized by calling |
| 1380 | * drm_atomic_helper_setup_commit() should look at |
| 1381 | * drm_atomic_helper_wait_for_flip_done() as an alternative. |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 1382 | */ |
| 1383 | void |
| 1384 | drm_atomic_helper_wait_for_vblanks(struct drm_device *dev, |
| 1385 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1386 | { |
| 1387 | struct drm_crtc *crtc; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1388 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1389 | int i, ret; |
Maarten Lankhorst | bdc5714 | 2016-12-15 12:51:42 +0100 | [diff] [blame] | 1390 | unsigned crtc_mask = 0; |
| 1391 | |
| 1392 | /* |
| 1393 | * Legacy cursor ioctls are completely unsynced, and userspace |
| 1394 | * relies on that (by doing tons of cursor updates). |
| 1395 | */ |
| 1396 | if (old_state->legacy_cursor_update) |
| 1397 | return; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1398 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1399 | for_each_oldnew_crtc_in_state(old_state, crtc, old_crtc_state, new_crtc_state, i) { |
Lucas Stach | a76dfe3 | 2017-11-29 12:04:31 +0100 | [diff] [blame] | 1400 | if (!new_crtc_state->active) |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 1401 | continue; |
| 1402 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1403 | ret = drm_crtc_vblank_get(crtc); |
| 1404 | if (ret != 0) |
| 1405 | continue; |
| 1406 | |
Maarten Lankhorst | bdc5714 | 2016-12-15 12:51:42 +0100 | [diff] [blame] | 1407 | crtc_mask |= drm_crtc_mask(crtc); |
| 1408 | old_state->crtcs[i].last_vblank_count = drm_crtc_vblank_count(crtc); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1409 | } |
| 1410 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1411 | for_each_old_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Maarten Lankhorst | bdc5714 | 2016-12-15 12:51:42 +0100 | [diff] [blame] | 1412 | if (!(crtc_mask & drm_crtc_mask(crtc))) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1413 | continue; |
| 1414 | |
| 1415 | ret = wait_event_timeout(dev->vblank[i].queue, |
Maarten Lankhorst | bdc5714 | 2016-12-15 12:51:42 +0100 | [diff] [blame] | 1416 | old_state->crtcs[i].last_vblank_count != |
Thierry Reding | d485363 | 2015-08-12 17:00:35 +0200 | [diff] [blame] | 1417 | drm_crtc_vblank_count(crtc), |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1418 | msecs_to_jiffies(50)); |
| 1419 | |
Russell King | 6ac7c54 | 2017-02-13 12:27:03 +0000 | [diff] [blame] | 1420 | WARN(!ret, "[CRTC:%d:%s] vblank wait timed out\n", |
| 1421 | crtc->base.id, crtc->name); |
Ville Syrjälä | 8d4d0d7 | 2016-04-18 14:29:33 +0300 | [diff] [blame] | 1422 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1423 | drm_crtc_vblank_put(crtc); |
| 1424 | } |
| 1425 | } |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 1426 | EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1427 | |
| 1428 | /** |
Boris Brezillon | 0108648 | 2017-06-02 10:32:06 +0200 | [diff] [blame] | 1429 | * drm_atomic_helper_wait_for_flip_done - wait for all page flips to be done |
| 1430 | * @dev: DRM device |
| 1431 | * @old_state: atomic state object with old state structures |
| 1432 | * |
| 1433 | * Helper to, after atomic commit, wait for page flips on all effected |
| 1434 | * crtcs (ie. before cleaning up old framebuffers using |
| 1435 | * drm_atomic_helper_cleanup_planes()). Compared to |
| 1436 | * drm_atomic_helper_wait_for_vblanks() this waits for the completion of on all |
| 1437 | * CRTCs, assuming that cursors-only updates are signalling their completion |
| 1438 | * immediately (or using a different path). |
| 1439 | * |
| 1440 | * This requires that drivers use the nonblocking commit tracking support |
| 1441 | * initialized using drm_atomic_helper_setup_commit(). |
| 1442 | */ |
| 1443 | void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev, |
| 1444 | struct drm_atomic_state *old_state) |
| 1445 | { |
Boris Brezillon | 0108648 | 2017-06-02 10:32:06 +0200 | [diff] [blame] | 1446 | struct drm_crtc *crtc; |
| 1447 | int i; |
| 1448 | |
Leo Li | 4364bcb | 2018-10-15 09:46:40 -0400 | [diff] [blame] | 1449 | for (i = 0; i < dev->mode_config.num_crtc; i++) { |
| 1450 | struct drm_crtc_commit *commit = old_state->crtcs[i].commit; |
Boris Brezillon | 0108648 | 2017-06-02 10:32:06 +0200 | [diff] [blame] | 1451 | int ret; |
| 1452 | |
Leo Li | 4364bcb | 2018-10-15 09:46:40 -0400 | [diff] [blame] | 1453 | crtc = old_state->crtcs[i].ptr; |
| 1454 | |
| 1455 | if (!crtc || !commit) |
Boris Brezillon | 0108648 | 2017-06-02 10:32:06 +0200 | [diff] [blame] | 1456 | continue; |
| 1457 | |
| 1458 | ret = wait_for_completion_timeout(&commit->flip_done, 10 * HZ); |
| 1459 | if (ret == 0) |
| 1460 | DRM_ERROR("[CRTC:%d:%s] flip_done timed out\n", |
| 1461 | crtc->base.id, crtc->name); |
| 1462 | } |
Ville Syrjälä | 2de42f7 | 2018-11-22 16:34:11 +0200 | [diff] [blame] | 1463 | |
| 1464 | if (old_state->fake_commit) |
| 1465 | complete_all(&old_state->fake_commit->flip_done); |
Boris Brezillon | 0108648 | 2017-06-02 10:32:06 +0200 | [diff] [blame] | 1466 | } |
| 1467 | EXPORT_SYMBOL(drm_atomic_helper_wait_for_flip_done); |
| 1468 | |
| 1469 | /** |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1470 | * drm_atomic_helper_commit_tail - commit atomic update to hardware |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1471 | * @old_state: atomic state object with old state structures |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1472 | * |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 1473 | * This is the default implementation for the |
Maxime Ripard | 81a099a | 2017-07-20 15:01:16 +0200 | [diff] [blame] | 1474 | * &drm_mode_config_helper_funcs.atomic_commit_tail hook, for drivers |
| 1475 | * that do not support runtime_pm or do not need the CRTC to be |
| 1476 | * enabled to perform a commit. Otherwise, see |
| 1477 | * drm_atomic_helper_commit_tail_rpm(). |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1478 | * |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1479 | * Note that the default ordering of how the various stages are called is to |
Maxime Ripard | 81a099a | 2017-07-20 15:01:16 +0200 | [diff] [blame] | 1480 | * match the legacy modeset helper library closest. |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1481 | */ |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1482 | void drm_atomic_helper_commit_tail(struct drm_atomic_state *old_state) |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1483 | { |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1484 | struct drm_device *dev = old_state->dev; |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1485 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1486 | drm_atomic_helper_commit_modeset_disables(dev, old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1487 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1488 | drm_atomic_helper_commit_planes(dev, old_state, 0); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1489 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1490 | drm_atomic_helper_commit_modeset_enables(dev, old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1491 | |
Boris Brezillon | 6fb42b6 | 2018-07-03 09:50:20 +0200 | [diff] [blame] | 1492 | drm_atomic_helper_fake_vblank(old_state); |
| 1493 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1494 | drm_atomic_helper_commit_hw_done(old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1495 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1496 | drm_atomic_helper_wait_for_vblanks(dev, old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1497 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1498 | drm_atomic_helper_cleanup_planes(dev, old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1499 | } |
| 1500 | EXPORT_SYMBOL(drm_atomic_helper_commit_tail); |
| 1501 | |
Maxime Ripard | 81a099a | 2017-07-20 15:01:16 +0200 | [diff] [blame] | 1502 | /** |
| 1503 | * drm_atomic_helper_commit_tail_rpm - commit atomic update to hardware |
| 1504 | * @old_state: new modeset state to be committed |
| 1505 | * |
| 1506 | * This is an alternative implementation for the |
| 1507 | * &drm_mode_config_helper_funcs.atomic_commit_tail hook, for drivers |
| 1508 | * that support runtime_pm or need the CRTC to be enabled to perform a |
| 1509 | * commit. Otherwise, one should use the default implementation |
| 1510 | * drm_atomic_helper_commit_tail(). |
| 1511 | */ |
| 1512 | void drm_atomic_helper_commit_tail_rpm(struct drm_atomic_state *old_state) |
| 1513 | { |
| 1514 | struct drm_device *dev = old_state->dev; |
| 1515 | |
| 1516 | drm_atomic_helper_commit_modeset_disables(dev, old_state); |
| 1517 | |
| 1518 | drm_atomic_helper_commit_modeset_enables(dev, old_state); |
| 1519 | |
| 1520 | drm_atomic_helper_commit_planes(dev, old_state, |
| 1521 | DRM_PLANE_COMMIT_ACTIVE_ONLY); |
| 1522 | |
Boris Brezillon | 6fb42b6 | 2018-07-03 09:50:20 +0200 | [diff] [blame] | 1523 | drm_atomic_helper_fake_vblank(old_state); |
| 1524 | |
Maxime Ripard | 81a099a | 2017-07-20 15:01:16 +0200 | [diff] [blame] | 1525 | drm_atomic_helper_commit_hw_done(old_state); |
| 1526 | |
| 1527 | drm_atomic_helper_wait_for_vblanks(dev, old_state); |
| 1528 | |
| 1529 | drm_atomic_helper_cleanup_planes(dev, old_state); |
| 1530 | } |
| 1531 | EXPORT_SYMBOL(drm_atomic_helper_commit_tail_rpm); |
| 1532 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1533 | static void commit_tail(struct drm_atomic_state *old_state) |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1534 | { |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1535 | struct drm_device *dev = old_state->dev; |
Laurent Pinchart | a4b10cc | 2017-01-02 11:16:13 +0200 | [diff] [blame] | 1536 | const struct drm_mode_config_helper_funcs *funcs; |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1537 | |
| 1538 | funcs = dev->mode_config.helper_private; |
| 1539 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1540 | drm_atomic_helper_wait_for_fences(dev, old_state, false); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1541 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1542 | drm_atomic_helper_wait_for_dependencies(old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1543 | |
| 1544 | if (funcs && funcs->atomic_commit_tail) |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1545 | funcs->atomic_commit_tail(old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1546 | else |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1547 | drm_atomic_helper_commit_tail(old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1548 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1549 | drm_atomic_helper_commit_cleanup_done(old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1550 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1551 | drm_atomic_state_put(old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1552 | } |
| 1553 | |
| 1554 | static void commit_work(struct work_struct *work) |
| 1555 | { |
| 1556 | struct drm_atomic_state *state = container_of(work, |
| 1557 | struct drm_atomic_state, |
| 1558 | commit_work); |
| 1559 | commit_tail(state); |
| 1560 | } |
| 1561 | |
| 1562 | /** |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 1563 | * drm_atomic_helper_async_check - check if state can be commited asynchronously |
| 1564 | * @dev: DRM device |
| 1565 | * @state: the driver state object |
| 1566 | * |
| 1567 | * This helper will check if it is possible to commit the state asynchronously. |
| 1568 | * Async commits are not supposed to swap the states like normal sync commits |
| 1569 | * but just do in-place changes on the current state. |
| 1570 | * |
| 1571 | * It will return 0 if the commit can happen in an asynchronous fashion or error |
| 1572 | * if not. Note that error just mean it can't be commited asynchronously, if it |
| 1573 | * fails the commit should be treated like a normal synchronous commit. |
| 1574 | */ |
| 1575 | int drm_atomic_helper_async_check(struct drm_device *dev, |
| 1576 | struct drm_atomic_state *state) |
| 1577 | { |
| 1578 | struct drm_crtc *crtc; |
| 1579 | struct drm_crtc_state *crtc_state; |
Boris Brezillon | de2d8db | 2018-07-24 15:33:00 +0200 | [diff] [blame] | 1580 | struct drm_plane *plane = NULL; |
| 1581 | struct drm_plane_state *old_plane_state = NULL; |
| 1582 | struct drm_plane_state *new_plane_state = NULL; |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 1583 | const struct drm_plane_helper_funcs *funcs; |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 1584 | int i, n_planes = 0; |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 1585 | |
| 1586 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) { |
| 1587 | if (drm_atomic_crtc_needs_modeset(crtc_state)) |
| 1588 | return -EINVAL; |
| 1589 | } |
| 1590 | |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 1591 | for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 1592 | n_planes++; |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 1593 | |
| 1594 | /* FIXME: we support only single plane updates for now */ |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 1595 | if (n_planes != 1) |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 1596 | return -EINVAL; |
| 1597 | |
Boris Brezillon | 603ba2d | 2018-07-24 15:32:15 +0200 | [diff] [blame] | 1598 | if (!new_plane_state->crtc || |
| 1599 | old_plane_state->crtc != new_plane_state->crtc) |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 1600 | return -EINVAL; |
| 1601 | |
| 1602 | funcs = plane->helper_private; |
| 1603 | if (!funcs->atomic_async_update) |
| 1604 | return -EINVAL; |
| 1605 | |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 1606 | if (new_plane_state->fence) |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 1607 | return -EINVAL; |
| 1608 | |
| 1609 | /* |
| 1610 | * Don't do an async update if there is an outstanding commit modifying |
| 1611 | * the plane. This prevents our async update's changes from getting |
| 1612 | * overridden by a previous synchronous update's state. |
| 1613 | */ |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 1614 | if (old_plane_state->commit && |
| 1615 | !try_wait_for_completion(&old_plane_state->commit->hw_done)) |
| 1616 | return -EBUSY; |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 1617 | |
Maarten Lankhorst | 669c921 | 2017-09-04 12:48:38 +0200 | [diff] [blame] | 1618 | return funcs->atomic_async_check(plane, new_plane_state); |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 1619 | } |
| 1620 | EXPORT_SYMBOL(drm_atomic_helper_async_check); |
| 1621 | |
| 1622 | /** |
| 1623 | * drm_atomic_helper_async_commit - commit state asynchronously |
| 1624 | * @dev: DRM device |
| 1625 | * @state: the driver state object |
| 1626 | * |
| 1627 | * This function commits a state asynchronously, i.e., not vblank |
| 1628 | * synchronized. It should be used on a state only when |
| 1629 | * drm_atomic_async_check() succeeds. Async commits are not supposed to swap |
| 1630 | * the states like normal sync commits, but just do in-place changes on the |
| 1631 | * current state. |
| 1632 | */ |
| 1633 | void drm_atomic_helper_async_commit(struct drm_device *dev, |
| 1634 | struct drm_atomic_state *state) |
| 1635 | { |
| 1636 | struct drm_plane *plane; |
| 1637 | struct drm_plane_state *plane_state; |
| 1638 | const struct drm_plane_helper_funcs *funcs; |
| 1639 | int i; |
| 1640 | |
| 1641 | for_each_new_plane_in_state(state, plane, plane_state, i) { |
| 1642 | funcs = plane->helper_private; |
| 1643 | funcs->atomic_async_update(plane, plane_state); |
Boris Brezillon | 02edfd9 | 2018-03-30 16:55:18 +0200 | [diff] [blame] | 1644 | |
| 1645 | /* |
| 1646 | * ->atomic_async_update() is supposed to update the |
| 1647 | * plane->state in-place, make sure at least common |
| 1648 | * properties have been properly updated. |
| 1649 | */ |
| 1650 | WARN_ON_ONCE(plane->state->fb != plane_state->fb); |
| 1651 | WARN_ON_ONCE(plane->state->crtc_x != plane_state->crtc_x); |
| 1652 | WARN_ON_ONCE(plane->state->crtc_y != plane_state->crtc_y); |
| 1653 | WARN_ON_ONCE(plane->state->src_x != plane_state->src_x); |
| 1654 | WARN_ON_ONCE(plane->state->src_y != plane_state->src_y); |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 1655 | } |
| 1656 | } |
| 1657 | EXPORT_SYMBOL(drm_atomic_helper_async_commit); |
| 1658 | |
| 1659 | /** |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1660 | * drm_atomic_helper_commit - commit validated state object |
| 1661 | * @dev: DRM device |
| 1662 | * @state: the driver state object |
| 1663 | * @nonblock: whether nonblocking behavior is requested. |
| 1664 | * |
| 1665 | * This function commits a with drm_atomic_helper_check() pre-validated state |
| 1666 | * object. This can still fail when e.g. the framebuffer reservation fails. This |
| 1667 | * function implements nonblocking commits, using |
| 1668 | * drm_atomic_helper_setup_commit() and related functions. |
| 1669 | * |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1670 | * Committing the actual hardware state is done through the |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 1671 | * &drm_mode_config_helper_funcs.atomic_commit_tail callback, or it's default |
| 1672 | * implementation drm_atomic_helper_commit_tail(). |
Daniel Vetter | 6e48ae3 | 2015-09-08 13:52:45 +0200 | [diff] [blame] | 1673 | * |
Daniel Vetter | c39032a | 2016-06-08 14:19:19 +0200 | [diff] [blame] | 1674 | * RETURNS: |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1675 | * Zero for success or -errno. |
| 1676 | */ |
| 1677 | int drm_atomic_helper_commit(struct drm_device *dev, |
| 1678 | struct drm_atomic_state *state, |
Maarten Lankhorst | 286dbb8 | 2016-04-26 16:11:34 +0200 | [diff] [blame] | 1679 | bool nonblock) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1680 | { |
| 1681 | int ret; |
| 1682 | |
Gustavo Padovan | fef9df8 | 2017-06-30 15:03:17 -0300 | [diff] [blame] | 1683 | if (state->async_update) { |
| 1684 | ret = drm_atomic_helper_prepare_planes(dev, state); |
| 1685 | if (ret) |
| 1686 | return ret; |
| 1687 | |
| 1688 | drm_atomic_helper_async_commit(dev, state); |
| 1689 | drm_atomic_helper_cleanup_planes(dev, state); |
| 1690 | |
| 1691 | return 0; |
| 1692 | } |
| 1693 | |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1694 | ret = drm_atomic_helper_setup_commit(state, nonblock); |
| 1695 | if (ret) |
| 1696 | return ret; |
| 1697 | |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1698 | INIT_WORK(&state->commit_work, commit_work); |
| 1699 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1700 | ret = drm_atomic_helper_prepare_planes(dev, state); |
| 1701 | if (ret) |
| 1702 | return ret; |
| 1703 | |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1704 | if (!nonblock) { |
| 1705 | ret = drm_atomic_helper_wait_for_fences(dev, state, true); |
Maarten Lankhorst | c066d23 | 2017-07-11 16:33:04 +0200 | [diff] [blame] | 1706 | if (ret) |
| 1707 | goto err; |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1708 | } |
| 1709 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1710 | /* |
| 1711 | * This is the point of no return - everything below never fails except |
| 1712 | * when the hw goes bonghits. Which means we can commit the new state on |
| 1713 | * the software side now. |
| 1714 | */ |
| 1715 | |
Maarten Lankhorst | c066d23 | 2017-07-11 16:33:04 +0200 | [diff] [blame] | 1716 | ret = drm_atomic_helper_swap_state(state, true); |
| 1717 | if (ret) |
| 1718 | goto err; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1719 | |
| 1720 | /* |
| 1721 | * Everything below can be run asynchronously without the need to grab |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 1722 | * any modeset locks at all under one condition: It must be guaranteed |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1723 | * that the asynchronous work has either been cancelled (if the driver |
| 1724 | * supports it, which at least requires that the framebuffers get |
| 1725 | * cleaned up with drm_atomic_helper_cleanup_planes()) or completed |
| 1726 | * before the new state gets committed on the software side with |
| 1727 | * drm_atomic_helper_swap_state(). |
| 1728 | * |
| 1729 | * This scheme allows new atomic state updates to be prepared and |
| 1730 | * checked in parallel to the asynchronous completion of the previous |
| 1731 | * update. Which is important since compositors need to figure out the |
| 1732 | * composition of the next frame right after having submitted the |
| 1733 | * current layout. |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1734 | * |
| 1735 | * NOTE: Commit work has multiple phases, first hardware commit, then |
| 1736 | * cleanup. We want them to overlap, hence need system_unbound_wq to |
| 1737 | * make sure work items don't artifically stall on each another. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1738 | */ |
| 1739 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 1740 | drm_atomic_state_get(state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1741 | if (nonblock) |
| 1742 | queue_work(system_unbound_wq, &state->commit_work); |
| 1743 | else |
| 1744 | commit_tail(state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1745 | |
| 1746 | return 0; |
Maarten Lankhorst | c066d23 | 2017-07-11 16:33:04 +0200 | [diff] [blame] | 1747 | |
| 1748 | err: |
| 1749 | drm_atomic_helper_cleanup_planes(dev, state); |
| 1750 | return ret; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1751 | } |
| 1752 | EXPORT_SYMBOL(drm_atomic_helper_commit); |
| 1753 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1754 | /** |
Maarten Lankhorst | 286dbb8 | 2016-04-26 16:11:34 +0200 | [diff] [blame] | 1755 | * DOC: implementing nonblocking commit |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1756 | * |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1757 | * Nonblocking atomic commits have to be implemented in the following sequence: |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1758 | * |
| 1759 | * 1. Run drm_atomic_helper_prepare_planes() first. This is the only function |
| 1760 | * which commit needs to call which can fail, so we want to run it first and |
| 1761 | * synchronously. |
| 1762 | * |
Maarten Lankhorst | 286dbb8 | 2016-04-26 16:11:34 +0200 | [diff] [blame] | 1763 | * 2. Synchronize with any outstanding nonblocking commit worker threads which |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1764 | * might be affected the new state update. This can be done by either cancelling |
| 1765 | * or flushing the work items, depending upon whether the driver can deal with |
| 1766 | * cancelled updates. Note that it is important to ensure that the framebuffer |
| 1767 | * cleanup is still done when cancelling. |
| 1768 | * |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1769 | * Asynchronous workers need to have sufficient parallelism to be able to run |
| 1770 | * different atomic commits on different CRTCs in parallel. The simplest way to |
| 1771 | * achive this is by running them on the &system_unbound_wq work queue. Note |
| 1772 | * that drivers are not required to split up atomic commits and run an |
| 1773 | * individual commit in parallel - userspace is supposed to do that if it cares. |
| 1774 | * But it might be beneficial to do that for modesets, since those necessarily |
| 1775 | * must be done as one global operation, and enabling or disabling a CRTC can |
| 1776 | * take a long time. But even that is not required. |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1777 | * |
| 1778 | * 3. The software state is updated synchronously with |
Daniel Vetter | 26196f7 | 2015-08-25 16:26:03 +0200 | [diff] [blame] | 1779 | * drm_atomic_helper_swap_state(). Doing this under the protection of all modeset |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1780 | * locks means concurrent callers never see inconsistent state. And doing this |
Maarten Lankhorst | 286dbb8 | 2016-04-26 16:11:34 +0200 | [diff] [blame] | 1781 | * while it's guaranteed that no relevant nonblocking worker runs means that |
| 1782 | * nonblocking workers do not need grab any locks. Actually they must not grab |
| 1783 | * locks, for otherwise the work flushing will deadlock. |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1784 | * |
| 1785 | * 4. Schedule a work item to do all subsequent steps, using the split-out |
| 1786 | * commit helpers: a) pre-plane commit b) plane commit c) post-plane commit and |
| 1787 | * then cleaning up the framebuffers after the old framebuffer is no longer |
| 1788 | * being displayed. |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1789 | * |
| 1790 | * The above scheme is implemented in the atomic helper libraries in |
| 1791 | * drm_atomic_helper_commit() using a bunch of helper functions. See |
| 1792 | * drm_atomic_helper_setup_commit() for a starting point. |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1793 | */ |
| 1794 | |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1795 | static int stall_checks(struct drm_crtc *crtc, bool nonblock) |
| 1796 | { |
| 1797 | struct drm_crtc_commit *commit, *stall_commit = NULL; |
| 1798 | bool completed = true; |
| 1799 | int i; |
| 1800 | long ret = 0; |
| 1801 | |
| 1802 | spin_lock(&crtc->commit_lock); |
| 1803 | i = 0; |
| 1804 | list_for_each_entry(commit, &crtc->commit_list, commit_entry) { |
| 1805 | if (i == 0) { |
| 1806 | completed = try_wait_for_completion(&commit->flip_done); |
| 1807 | /* Userspace is not allowed to get ahead of the previous |
| 1808 | * commit with nonblocking ones. */ |
| 1809 | if (!completed && nonblock) { |
| 1810 | spin_unlock(&crtc->commit_lock); |
| 1811 | return -EBUSY; |
| 1812 | } |
| 1813 | } else if (i == 1) { |
Maarten Lankhorst | f46640b | 2017-09-04 12:48:36 +0200 | [diff] [blame] | 1814 | stall_commit = drm_crtc_commit_get(commit); |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1815 | break; |
Daniel Vetter | 723c3e5 | 2016-06-14 19:50:58 +0200 | [diff] [blame] | 1816 | } |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1817 | |
| 1818 | i++; |
| 1819 | } |
| 1820 | spin_unlock(&crtc->commit_lock); |
| 1821 | |
| 1822 | if (!stall_commit) |
| 1823 | return 0; |
| 1824 | |
| 1825 | /* We don't want to let commits get ahead of cleanup work too much, |
| 1826 | * stalling on 2nd previous commit means triple-buffer won't ever stall. |
| 1827 | */ |
Daniel Vetter | 723c3e5 | 2016-06-14 19:50:58 +0200 | [diff] [blame] | 1828 | ret = wait_for_completion_interruptible_timeout(&stall_commit->cleanup_done, |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1829 | 10*HZ); |
| 1830 | if (ret == 0) |
| 1831 | DRM_ERROR("[CRTC:%d:%s] cleanup_done timed out\n", |
| 1832 | crtc->base.id, crtc->name); |
| 1833 | |
| 1834 | drm_crtc_commit_put(stall_commit); |
| 1835 | |
| 1836 | return ret < 0 ? ret : 0; |
| 1837 | } |
| 1838 | |
Wei Yongjun | 899cc5f | 2017-01-12 14:21:57 +0000 | [diff] [blame] | 1839 | static void release_crtc_commit(struct completion *completion) |
Daniel Vetter | 24835e4 | 2016-12-21 11:23:30 +0100 | [diff] [blame] | 1840 | { |
| 1841 | struct drm_crtc_commit *commit = container_of(completion, |
| 1842 | typeof(*commit), |
| 1843 | flip_done); |
| 1844 | |
| 1845 | drm_crtc_commit_put(commit); |
| 1846 | } |
| 1847 | |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 1848 | static void init_commit(struct drm_crtc_commit *commit, struct drm_crtc *crtc) |
| 1849 | { |
| 1850 | init_completion(&commit->flip_done); |
| 1851 | init_completion(&commit->hw_done); |
| 1852 | init_completion(&commit->cleanup_done); |
| 1853 | INIT_LIST_HEAD(&commit->commit_entry); |
| 1854 | kref_init(&commit->ref); |
| 1855 | commit->crtc = crtc; |
| 1856 | } |
| 1857 | |
| 1858 | static struct drm_crtc_commit * |
| 1859 | crtc_or_fake_commit(struct drm_atomic_state *state, struct drm_crtc *crtc) |
| 1860 | { |
| 1861 | if (crtc) { |
| 1862 | struct drm_crtc_state *new_crtc_state; |
| 1863 | |
| 1864 | new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc); |
| 1865 | |
| 1866 | return new_crtc_state->commit; |
| 1867 | } |
| 1868 | |
| 1869 | if (!state->fake_commit) { |
| 1870 | state->fake_commit = kzalloc(sizeof(*state->fake_commit), GFP_KERNEL); |
| 1871 | if (!state->fake_commit) |
| 1872 | return NULL; |
| 1873 | |
| 1874 | init_commit(state->fake_commit, NULL); |
| 1875 | } |
| 1876 | |
| 1877 | return state->fake_commit; |
| 1878 | } |
| 1879 | |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1880 | /** |
| 1881 | * drm_atomic_helper_setup_commit - setup possibly nonblocking commit |
| 1882 | * @state: new modeset state to be committed |
| 1883 | * @nonblock: whether nonblocking behavior is requested. |
| 1884 | * |
| 1885 | * This function prepares @state to be used by the atomic helper's support for |
| 1886 | * nonblocking commits. Drivers using the nonblocking commit infrastructure |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 1887 | * should always call this function from their |
| 1888 | * &drm_mode_config_funcs.atomic_commit hook. |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1889 | * |
| 1890 | * To be able to use this support drivers need to use a few more helper |
| 1891 | * functions. drm_atomic_helper_wait_for_dependencies() must be called before |
| 1892 | * actually committing the hardware state, and for nonblocking commits this call |
| 1893 | * must be placed in the async worker. See also drm_atomic_helper_swap_state() |
| 1894 | * and it's stall parameter, for when a driver's commit hooks look at the |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 1895 | * &drm_crtc.state, &drm_plane.state or &drm_connector.state pointer directly. |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1896 | * |
| 1897 | * Completion of the hardware commit step must be signalled using |
| 1898 | * drm_atomic_helper_commit_hw_done(). After this step the driver is not allowed |
| 1899 | * to read or change any permanent software or hardware modeset state. The only |
| 1900 | * exception is state protected by other means than &drm_modeset_lock locks. |
| 1901 | * Only the free standing @state with pointers to the old state structures can |
| 1902 | * be inspected, e.g. to clean up old buffers using |
| 1903 | * drm_atomic_helper_cleanup_planes(). |
| 1904 | * |
| 1905 | * At the very end, before cleaning up @state drivers must call |
| 1906 | * drm_atomic_helper_commit_cleanup_done(). |
| 1907 | * |
| 1908 | * This is all implemented by in drm_atomic_helper_commit(), giving drivers a |
Thierry Reding | 9ac0781 | 2017-10-12 16:06:16 +0200 | [diff] [blame] | 1909 | * complete and easy-to-use default implementation of the atomic_commit() hook. |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1910 | * |
| 1911 | * The tracking of asynchronously executed and still pending commits is done |
| 1912 | * using the core structure &drm_crtc_commit. |
| 1913 | * |
| 1914 | * By default there's no need to clean up resources allocated by this function |
| 1915 | * explicitly: drm_atomic_state_default_clear() will take care of that |
| 1916 | * automatically. |
| 1917 | * |
| 1918 | * Returns: |
| 1919 | * |
| 1920 | * 0 on success. -EBUSY when userspace schedules nonblocking commits too fast, |
| 1921 | * -ENOMEM on allocation failures and -EINTR when a signal is pending. |
| 1922 | */ |
| 1923 | int drm_atomic_helper_setup_commit(struct drm_atomic_state *state, |
| 1924 | bool nonblock) |
| 1925 | { |
| 1926 | struct drm_crtc *crtc; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1927 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 1928 | struct drm_connector *conn; |
| 1929 | struct drm_connector_state *old_conn_state, *new_conn_state; |
| 1930 | struct drm_plane *plane; |
| 1931 | struct drm_plane_state *old_plane_state, *new_plane_state; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1932 | struct drm_crtc_commit *commit; |
| 1933 | int i, ret; |
| 1934 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1935 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1936 | commit = kzalloc(sizeof(*commit), GFP_KERNEL); |
| 1937 | if (!commit) |
| 1938 | return -ENOMEM; |
| 1939 | |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 1940 | init_commit(commit, crtc); |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1941 | |
Maarten Lankhorst | 163bcc2 | 2017-09-04 17:04:56 +0200 | [diff] [blame] | 1942 | new_crtc_state->commit = commit; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1943 | |
| 1944 | ret = stall_checks(crtc, nonblock); |
| 1945 | if (ret) |
| 1946 | return ret; |
| 1947 | |
| 1948 | /* Drivers only send out events when at least either current or |
| 1949 | * new CRTC state is active. Complete right away if everything |
| 1950 | * stays off. */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1951 | if (!old_crtc_state->active && !new_crtc_state->active) { |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1952 | complete_all(&commit->flip_done); |
| 1953 | continue; |
| 1954 | } |
| 1955 | |
| 1956 | /* Legacy cursor updates are fully unsynced. */ |
| 1957 | if (state->legacy_cursor_update) { |
| 1958 | complete_all(&commit->flip_done); |
| 1959 | continue; |
| 1960 | } |
| 1961 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1962 | if (!new_crtc_state->event) { |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1963 | commit->event = kzalloc(sizeof(*commit->event), |
| 1964 | GFP_KERNEL); |
| 1965 | if (!commit->event) |
| 1966 | return -ENOMEM; |
| 1967 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1968 | new_crtc_state->event = commit->event; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1969 | } |
| 1970 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 1971 | new_crtc_state->event->base.completion = &commit->flip_done; |
| 1972 | new_crtc_state->event->base.completion_release = release_crtc_commit; |
Daniel Vetter | 24835e4 | 2016-12-21 11:23:30 +0100 | [diff] [blame] | 1973 | drm_crtc_commit_get(commit); |
Leo (Sunpeng) Li | 1c6ceee | 2018-01-17 12:51:08 +0100 | [diff] [blame] | 1974 | |
| 1975 | commit->abort_completion = true; |
Leo Li | 4364bcb | 2018-10-15 09:46:40 -0400 | [diff] [blame] | 1976 | |
| 1977 | state->crtcs[i].commit = commit; |
| 1978 | drm_crtc_commit_get(commit); |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1979 | } |
| 1980 | |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 1981 | for_each_oldnew_connector_in_state(state, conn, old_conn_state, new_conn_state, i) { |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 1982 | /* Userspace is not allowed to get ahead of the previous |
| 1983 | * commit with nonblocking ones. */ |
| 1984 | if (nonblock && old_conn_state->commit && |
| 1985 | !try_wait_for_completion(&old_conn_state->commit->flip_done)) |
| 1986 | return -EBUSY; |
| 1987 | |
Daniel Vetter | 1f2d9bd | 2017-11-10 11:53:12 +0100 | [diff] [blame] | 1988 | /* Always track connectors explicitly for e.g. link retraining. */ |
| 1989 | commit = crtc_or_fake_commit(state, new_conn_state->crtc ?: old_conn_state->crtc); |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 1990 | if (!commit) |
| 1991 | return -ENOMEM; |
| 1992 | |
| 1993 | new_conn_state->commit = drm_crtc_commit_get(commit); |
| 1994 | } |
| 1995 | |
| 1996 | for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) { |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 1997 | /* Userspace is not allowed to get ahead of the previous |
| 1998 | * commit with nonblocking ones. */ |
| 1999 | if (nonblock && old_plane_state->commit && |
| 2000 | !try_wait_for_completion(&old_plane_state->commit->flip_done)) |
| 2001 | return -EBUSY; |
| 2002 | |
Daniel Vetter | 1f2d9bd | 2017-11-10 11:53:12 +0100 | [diff] [blame] | 2003 | /* Always track planes explicitly for async pageflip support. */ |
Maarten Lankhorst | 4edd608 | 2017-10-17 07:20:47 +0200 | [diff] [blame] | 2004 | commit = crtc_or_fake_commit(state, new_plane_state->crtc ?: old_plane_state->crtc); |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 2005 | if (!commit) |
| 2006 | return -ENOMEM; |
| 2007 | |
| 2008 | new_plane_state->commit = drm_crtc_commit_get(commit); |
| 2009 | } |
| 2010 | |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2011 | return 0; |
| 2012 | } |
| 2013 | EXPORT_SYMBOL(drm_atomic_helper_setup_commit); |
| 2014 | |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2015 | /** |
| 2016 | * drm_atomic_helper_wait_for_dependencies - wait for required preceeding commits |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 2017 | * @old_state: atomic state object with old state structures |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2018 | * |
| 2019 | * This function waits for all preceeding commits that touch the same CRTC as |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 2020 | * @old_state to both be committed to the hardware (as signalled by |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2021 | * drm_atomic_helper_commit_hw_done) and executed by the hardware (as signalled |
Thierry Reding | 277b09c | 2017-10-12 16:08:57 +0200 | [diff] [blame] | 2022 | * by calling drm_crtc_send_vblank_event() on the &drm_crtc_state.event). |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2023 | * |
| 2024 | * This is part of the atomic helper support for nonblocking commits, see |
| 2025 | * drm_atomic_helper_setup_commit() for an overview. |
| 2026 | */ |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 2027 | void drm_atomic_helper_wait_for_dependencies(struct drm_atomic_state *old_state) |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2028 | { |
| 2029 | struct drm_crtc *crtc; |
Maarten Lankhorst | 163bcc2 | 2017-09-04 17:04:56 +0200 | [diff] [blame] | 2030 | struct drm_crtc_state *old_crtc_state; |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 2031 | struct drm_plane *plane; |
| 2032 | struct drm_plane_state *old_plane_state; |
| 2033 | struct drm_connector *conn; |
| 2034 | struct drm_connector_state *old_conn_state; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2035 | struct drm_crtc_commit *commit; |
| 2036 | int i; |
| 2037 | long ret; |
| 2038 | |
Maarten Lankhorst | 163bcc2 | 2017-09-04 17:04:56 +0200 | [diff] [blame] | 2039 | for_each_old_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
| 2040 | commit = old_crtc_state->commit; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2041 | |
| 2042 | if (!commit) |
| 2043 | continue; |
| 2044 | |
| 2045 | ret = wait_for_completion_timeout(&commit->hw_done, |
| 2046 | 10*HZ); |
| 2047 | if (ret == 0) |
| 2048 | DRM_ERROR("[CRTC:%d:%s] hw_done timed out\n", |
| 2049 | crtc->base.id, crtc->name); |
| 2050 | |
| 2051 | /* Currently no support for overwriting flips, hence |
| 2052 | * stall for previous one to execute completely. */ |
| 2053 | ret = wait_for_completion_timeout(&commit->flip_done, |
| 2054 | 10*HZ); |
| 2055 | if (ret == 0) |
| 2056 | DRM_ERROR("[CRTC:%d:%s] flip_done timed out\n", |
| 2057 | crtc->base.id, crtc->name); |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2058 | } |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2059 | |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 2060 | for_each_old_connector_in_state(old_state, conn, old_conn_state, i) { |
| 2061 | commit = old_conn_state->commit; |
| 2062 | |
| 2063 | if (!commit) |
| 2064 | continue; |
| 2065 | |
| 2066 | ret = wait_for_completion_timeout(&commit->hw_done, |
| 2067 | 10*HZ); |
| 2068 | if (ret == 0) |
| 2069 | DRM_ERROR("[CONNECTOR:%d:%s] hw_done timed out\n", |
| 2070 | conn->base.id, conn->name); |
| 2071 | |
| 2072 | /* Currently no support for overwriting flips, hence |
| 2073 | * stall for previous one to execute completely. */ |
| 2074 | ret = wait_for_completion_timeout(&commit->flip_done, |
| 2075 | 10*HZ); |
| 2076 | if (ret == 0) |
| 2077 | DRM_ERROR("[CONNECTOR:%d:%s] flip_done timed out\n", |
| 2078 | conn->base.id, conn->name); |
| 2079 | } |
| 2080 | |
| 2081 | for_each_old_plane_in_state(old_state, plane, old_plane_state, i) { |
| 2082 | commit = old_plane_state->commit; |
| 2083 | |
| 2084 | if (!commit) |
| 2085 | continue; |
| 2086 | |
| 2087 | ret = wait_for_completion_timeout(&commit->hw_done, |
| 2088 | 10*HZ); |
| 2089 | if (ret == 0) |
| 2090 | DRM_ERROR("[PLANE:%d:%s] hw_done timed out\n", |
| 2091 | plane->base.id, plane->name); |
| 2092 | |
| 2093 | /* Currently no support for overwriting flips, hence |
| 2094 | * stall for previous one to execute completely. */ |
| 2095 | ret = wait_for_completion_timeout(&commit->flip_done, |
| 2096 | 10*HZ); |
| 2097 | if (ret == 0) |
| 2098 | DRM_ERROR("[PLANE:%d:%s] flip_done timed out\n", |
| 2099 | plane->base.id, plane->name); |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2100 | } |
| 2101 | } |
| 2102 | EXPORT_SYMBOL(drm_atomic_helper_wait_for_dependencies); |
| 2103 | |
| 2104 | /** |
Boris Brezillon | b25c60a | 2018-07-03 09:50:19 +0200 | [diff] [blame] | 2105 | * drm_atomic_helper_fake_vblank - fake VBLANK events if needed |
| 2106 | * @old_state: atomic state object with old state structures |
| 2107 | * |
| 2108 | * This function walks all CRTCs and fake VBLANK events on those with |
| 2109 | * &drm_crtc_state.no_vblank set to true and &drm_crtc_state.event != NULL. |
| 2110 | * The primary use of this function is writeback connectors working in oneshot |
| 2111 | * mode and faking VBLANK events. In this case they only fake the VBLANK event |
| 2112 | * when a job is queued, and any change to the pipeline that does not touch the |
| 2113 | * connector is leading to timeouts when calling |
| 2114 | * drm_atomic_helper_wait_for_vblanks() or |
| 2115 | * drm_atomic_helper_wait_for_flip_done(). |
| 2116 | * |
| 2117 | * This is part of the atomic helper support for nonblocking commits, see |
| 2118 | * drm_atomic_helper_setup_commit() for an overview. |
| 2119 | */ |
| 2120 | void drm_atomic_helper_fake_vblank(struct drm_atomic_state *old_state) |
| 2121 | { |
| 2122 | struct drm_crtc_state *new_crtc_state; |
| 2123 | struct drm_crtc *crtc; |
| 2124 | int i; |
| 2125 | |
| 2126 | for_each_new_crtc_in_state(old_state, crtc, new_crtc_state, i) { |
| 2127 | unsigned long flags; |
| 2128 | |
| 2129 | if (!new_crtc_state->no_vblank) |
| 2130 | continue; |
| 2131 | |
| 2132 | spin_lock_irqsave(&old_state->dev->event_lock, flags); |
| 2133 | if (new_crtc_state->event) { |
| 2134 | drm_crtc_send_vblank_event(crtc, |
| 2135 | new_crtc_state->event); |
| 2136 | new_crtc_state->event = NULL; |
| 2137 | } |
| 2138 | spin_unlock_irqrestore(&old_state->dev->event_lock, flags); |
| 2139 | } |
| 2140 | } |
| 2141 | EXPORT_SYMBOL(drm_atomic_helper_fake_vblank); |
| 2142 | |
| 2143 | /** |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2144 | * drm_atomic_helper_commit_hw_done - setup possible nonblocking commit |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 2145 | * @old_state: atomic state object with old state structures |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2146 | * |
| 2147 | * This function is used to signal completion of the hardware commit step. After |
| 2148 | * this step the driver is not allowed to read or change any permanent software |
| 2149 | * or hardware modeset state. The only exception is state protected by other |
| 2150 | * means than &drm_modeset_lock locks. |
| 2151 | * |
| 2152 | * Drivers should try to postpone any expensive or delayed cleanup work after |
| 2153 | * this function is called. |
| 2154 | * |
| 2155 | * This is part of the atomic helper support for nonblocking commits, see |
| 2156 | * drm_atomic_helper_setup_commit() for an overview. |
| 2157 | */ |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 2158 | void drm_atomic_helper_commit_hw_done(struct drm_atomic_state *old_state) |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2159 | { |
| 2160 | struct drm_crtc *crtc; |
Maarten Lankhorst | 163bcc2 | 2017-09-04 17:04:56 +0200 | [diff] [blame] | 2161 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2162 | struct drm_crtc_commit *commit; |
| 2163 | int i; |
| 2164 | |
Maarten Lankhorst | 163bcc2 | 2017-09-04 17:04:56 +0200 | [diff] [blame] | 2165 | for_each_oldnew_crtc_in_state(old_state, crtc, old_crtc_state, new_crtc_state, i) { |
| 2166 | commit = new_crtc_state->commit; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2167 | if (!commit) |
| 2168 | continue; |
| 2169 | |
Maarten Lankhorst | 163bcc2 | 2017-09-04 17:04:56 +0200 | [diff] [blame] | 2170 | /* |
| 2171 | * copy new_crtc_state->commit to old_crtc_state->commit, |
| 2172 | * it's unsafe to touch new_crtc_state after hw_done, |
| 2173 | * but we still need to do so in cleanup_done(). |
| 2174 | */ |
| 2175 | if (old_crtc_state->commit) |
| 2176 | drm_crtc_commit_put(old_crtc_state->commit); |
| 2177 | |
| 2178 | old_crtc_state->commit = drm_crtc_commit_get(commit); |
| 2179 | |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2180 | /* backend must have consumed any event by now */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2181 | WARN_ON(new_crtc_state->event); |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2182 | complete_all(&commit->hw_done); |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2183 | } |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 2184 | |
| 2185 | if (old_state->fake_commit) { |
| 2186 | complete_all(&old_state->fake_commit->hw_done); |
| 2187 | complete_all(&old_state->fake_commit->flip_done); |
| 2188 | } |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2189 | } |
| 2190 | EXPORT_SYMBOL(drm_atomic_helper_commit_hw_done); |
| 2191 | |
| 2192 | /** |
| 2193 | * drm_atomic_helper_commit_cleanup_done - signal completion of commit |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 2194 | * @old_state: atomic state object with old state structures |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2195 | * |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 2196 | * This signals completion of the atomic update @old_state, including any |
| 2197 | * cleanup work. If used, it must be called right before calling |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2198 | * drm_atomic_state_put(). |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2199 | * |
| 2200 | * This is part of the atomic helper support for nonblocking commits, see |
| 2201 | * drm_atomic_helper_setup_commit() for an overview. |
| 2202 | */ |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 2203 | void drm_atomic_helper_commit_cleanup_done(struct drm_atomic_state *old_state) |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2204 | { |
| 2205 | struct drm_crtc *crtc; |
Maarten Lankhorst | 163bcc2 | 2017-09-04 17:04:56 +0200 | [diff] [blame] | 2206 | struct drm_crtc_state *old_crtc_state; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2207 | struct drm_crtc_commit *commit; |
| 2208 | int i; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2209 | |
Maarten Lankhorst | 163bcc2 | 2017-09-04 17:04:56 +0200 | [diff] [blame] | 2210 | for_each_old_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
| 2211 | commit = old_crtc_state->commit; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2212 | if (WARN_ON(!commit)) |
| 2213 | continue; |
| 2214 | |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2215 | complete_all(&commit->cleanup_done); |
| 2216 | WARN_ON(!try_wait_for_completion(&commit->hw_done)); |
| 2217 | |
Daniel Vetter | 7141fd3 | 2017-06-21 11:16:27 +0200 | [diff] [blame] | 2218 | spin_lock(&crtc->commit_lock); |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2219 | list_del(&commit->commit_entry); |
| 2220 | spin_unlock(&crtc->commit_lock); |
| 2221 | } |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 2222 | |
Ville Syrjälä | 10a599f | 2018-11-22 16:34:12 +0200 | [diff] [blame] | 2223 | if (old_state->fake_commit) { |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 2224 | complete_all(&old_state->fake_commit->cleanup_done); |
Ville Syrjälä | 10a599f | 2018-11-22 16:34:12 +0200 | [diff] [blame] | 2225 | WARN_ON(!try_wait_for_completion(&old_state->fake_commit->hw_done)); |
| 2226 | } |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2227 | } |
| 2228 | EXPORT_SYMBOL(drm_atomic_helper_commit_cleanup_done); |
| 2229 | |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 2230 | /** |
Daniel Vetter | 2e3afd4 | 2015-02-26 14:17:38 +0100 | [diff] [blame] | 2231 | * drm_atomic_helper_prepare_planes - prepare plane resources before commit |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2232 | * @dev: DRM device |
Daniel Vetter | 2e3afd4 | 2015-02-26 14:17:38 +0100 | [diff] [blame] | 2233 | * @state: atomic state object with new state structures |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2234 | * |
| 2235 | * This function prepares plane state, specifically framebuffers, for the new |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 2236 | * configuration, by calling &drm_plane_helper_funcs.prepare_fb. If any failure |
| 2237 | * is encountered this function will call &drm_plane_helper_funcs.cleanup_fb on |
| 2238 | * any already successfully prepared framebuffer. |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2239 | * |
| 2240 | * Returns: |
| 2241 | * 0 on success, negative error code on failure. |
| 2242 | */ |
| 2243 | int drm_atomic_helper_prepare_planes(struct drm_device *dev, |
| 2244 | struct drm_atomic_state *state) |
| 2245 | { |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 2246 | struct drm_plane *plane; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2247 | struct drm_plane_state *new_plane_state; |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 2248 | int ret, i, j; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2249 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2250 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 2251 | const struct drm_plane_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2252 | |
| 2253 | funcs = plane->helper_private; |
| 2254 | |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 2255 | if (funcs->prepare_fb) { |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2256 | ret = funcs->prepare_fb(plane, new_plane_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2257 | if (ret) |
| 2258 | goto fail; |
| 2259 | } |
| 2260 | } |
| 2261 | |
| 2262 | return 0; |
| 2263 | |
| 2264 | fail: |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2265 | for_each_new_plane_in_state(state, plane, new_plane_state, j) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 2266 | const struct drm_plane_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2267 | |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 2268 | if (j >= i) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2269 | continue; |
| 2270 | |
| 2271 | funcs = plane->helper_private; |
| 2272 | |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 2273 | if (funcs->cleanup_fb) |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2274 | funcs->cleanup_fb(plane, new_plane_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | return ret; |
| 2278 | } |
| 2279 | EXPORT_SYMBOL(drm_atomic_helper_prepare_planes); |
| 2280 | |
Ville Syrjälä | 7135ac5 | 2016-09-19 16:33:42 +0300 | [diff] [blame] | 2281 | static bool plane_crtc_active(const struct drm_plane_state *state) |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 2282 | { |
| 2283 | return state->crtc && state->crtc->state->active; |
| 2284 | } |
| 2285 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2286 | /** |
| 2287 | * drm_atomic_helper_commit_planes - commit plane state |
| 2288 | * @dev: DRM device |
Daniel Vetter | b0fcfc8 | 2014-11-19 18:38:11 +0100 | [diff] [blame] | 2289 | * @old_state: atomic state object with old state structures |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 2290 | * @flags: flags for committing plane state |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2291 | * |
| 2292 | * This function commits the new plane state using the plane and atomic helper |
| 2293 | * functions for planes and crtcs. It assumes that the atomic state has already |
| 2294 | * been pushed into the relevant object state pointers, since this step can no |
| 2295 | * longer fail. |
| 2296 | * |
Daniel Vetter | b0fcfc8 | 2014-11-19 18:38:11 +0100 | [diff] [blame] | 2297 | * It still requires the global state object @old_state to know which planes and |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2298 | * crtcs need to be updated though. |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 2299 | * |
| 2300 | * Note that this function does all plane updates across all CRTCs in one step. |
| 2301 | * If the hardware can't support this approach look at |
| 2302 | * drm_atomic_helper_commit_planes_on_crtc() instead. |
Daniel Vetter | 6e48ae3 | 2015-09-08 13:52:45 +0200 | [diff] [blame] | 2303 | * |
| 2304 | * Plane parameters can be updated by applications while the associated CRTC is |
| 2305 | * disabled. The DRM/KMS core will store the parameters in the plane state, |
| 2306 | * which will be available to the driver when the CRTC is turned on. As a result |
| 2307 | * most drivers don't need to be immediately notified of plane updates for a |
| 2308 | * disabled CRTC. |
| 2309 | * |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 2310 | * Unless otherwise needed, drivers are advised to set the ACTIVE_ONLY flag in |
| 2311 | * @flags in order not to receive plane update notifications related to a |
| 2312 | * disabled CRTC. This avoids the need to manually ignore plane updates in |
Daniel Vetter | 6e48ae3 | 2015-09-08 13:52:45 +0200 | [diff] [blame] | 2313 | * driver code when the driver and/or hardware can't or just don't need to deal |
| 2314 | * with updates on disabled CRTCs, for example when supporting runtime PM. |
| 2315 | * |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 2316 | * Drivers may set the NO_DISABLE_AFTER_MODESET flag in @flags if the relevant |
| 2317 | * display controllers require to disable a CRTC's planes when the CRTC is |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 2318 | * disabled. This function would skip the &drm_plane_helper_funcs.atomic_disable |
| 2319 | * call for a plane if the CRTC of the old plane state needs a modesetting |
| 2320 | * operation. Of course, the drivers need to disable the planes in their CRTC |
| 2321 | * disable callbacks since no one else would do that. |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 2322 | * |
| 2323 | * The drm_atomic_helper_commit() default implementation doesn't set the |
| 2324 | * ACTIVE_ONLY flag to most closely match the behaviour of the legacy helpers. |
| 2325 | * This should not be copied blindly by drivers. |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2326 | */ |
| 2327 | void drm_atomic_helper_commit_planes(struct drm_device *dev, |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 2328 | struct drm_atomic_state *old_state, |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 2329 | uint32_t flags) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2330 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 2331 | struct drm_crtc *crtc; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2332 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 2333 | struct drm_plane *plane; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2334 | struct drm_plane_state *old_plane_state, *new_plane_state; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2335 | int i; |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 2336 | bool active_only = flags & DRM_PLANE_COMMIT_ACTIVE_ONLY; |
| 2337 | bool no_disable = flags & DRM_PLANE_COMMIT_NO_DISABLE_AFTER_MODESET; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2338 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2339 | for_each_oldnew_crtc_in_state(old_state, crtc, old_crtc_state, new_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 2340 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2341 | |
| 2342 | funcs = crtc->helper_private; |
| 2343 | |
| 2344 | if (!funcs || !funcs->atomic_begin) |
| 2345 | continue; |
| 2346 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2347 | if (active_only && !new_crtc_state->active) |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 2348 | continue; |
| 2349 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 2350 | funcs->atomic_begin(crtc, old_crtc_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2351 | } |
| 2352 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2353 | for_each_oldnew_plane_in_state(old_state, plane, old_plane_state, new_plane_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 2354 | const struct drm_plane_helper_funcs *funcs; |
Laurent Pinchart | 216c59d | 2015-09-11 00:07:19 +0300 | [diff] [blame] | 2355 | bool disabling; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2356 | |
| 2357 | funcs = plane->helper_private; |
| 2358 | |
Thierry Reding | 3cad4b6 | 2014-11-25 13:05:12 +0100 | [diff] [blame] | 2359 | if (!funcs) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2360 | continue; |
| 2361 | |
Maarten Lankhorst | 51ffa12 | 2017-02-16 15:47:07 +0100 | [diff] [blame] | 2362 | disabling = drm_atomic_plane_disabling(old_plane_state, |
| 2363 | new_plane_state); |
Laurent Pinchart | 216c59d | 2015-09-11 00:07:19 +0300 | [diff] [blame] | 2364 | |
| 2365 | if (active_only) { |
| 2366 | /* |
| 2367 | * Skip planes related to inactive CRTCs. If the plane |
| 2368 | * is enabled use the state of the current CRTC. If the |
| 2369 | * plane is being disabled use the state of the old |
| 2370 | * CRTC to avoid skipping planes being disabled on an |
| 2371 | * active CRTC. |
| 2372 | */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2373 | if (!disabling && !plane_crtc_active(new_plane_state)) |
Laurent Pinchart | 216c59d | 2015-09-11 00:07:19 +0300 | [diff] [blame] | 2374 | continue; |
| 2375 | if (disabling && !plane_crtc_active(old_plane_state)) |
| 2376 | continue; |
| 2377 | } |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 2378 | |
Thierry Reding | 407b8bd | 2014-11-20 12:05:50 +0100 | [diff] [blame] | 2379 | /* |
| 2380 | * Special-case disabling the plane if drivers support it. |
| 2381 | */ |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 2382 | if (disabling && funcs->atomic_disable) { |
| 2383 | struct drm_crtc_state *crtc_state; |
| 2384 | |
| 2385 | crtc_state = old_plane_state->crtc->state; |
| 2386 | |
| 2387 | if (drm_atomic_crtc_needs_modeset(crtc_state) && |
| 2388 | no_disable) |
| 2389 | continue; |
| 2390 | |
Thierry Reding | 407b8bd | 2014-11-20 12:05:50 +0100 | [diff] [blame] | 2391 | funcs->atomic_disable(plane, old_plane_state); |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2392 | } else if (new_plane_state->crtc || disabling) { |
Thierry Reding | 407b8bd | 2014-11-20 12:05:50 +0100 | [diff] [blame] | 2393 | funcs->atomic_update(plane, old_plane_state); |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 2394 | } |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2395 | } |
| 2396 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2397 | for_each_oldnew_crtc_in_state(old_state, crtc, old_crtc_state, new_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 2398 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2399 | |
| 2400 | funcs = crtc->helper_private; |
| 2401 | |
| 2402 | if (!funcs || !funcs->atomic_flush) |
| 2403 | continue; |
| 2404 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2405 | if (active_only && !new_crtc_state->active) |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 2406 | continue; |
| 2407 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 2408 | funcs->atomic_flush(crtc, old_crtc_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2409 | } |
| 2410 | } |
| 2411 | EXPORT_SYMBOL(drm_atomic_helper_commit_planes); |
| 2412 | |
| 2413 | /** |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 2414 | * drm_atomic_helper_commit_planes_on_crtc - commit plane state for a crtc |
| 2415 | * @old_crtc_state: atomic state object with the old crtc state |
| 2416 | * |
| 2417 | * This function commits the new plane state using the plane and atomic helper |
| 2418 | * functions for planes on the specific crtc. It assumes that the atomic state |
| 2419 | * has already been pushed into the relevant object state pointers, since this |
| 2420 | * step can no longer fail. |
| 2421 | * |
| 2422 | * This function is useful when plane updates should be done crtc-by-crtc |
| 2423 | * instead of one global step like drm_atomic_helper_commit_planes() does. |
| 2424 | * |
| 2425 | * This function can only be savely used when planes are not allowed to move |
| 2426 | * between different CRTCs because this function doesn't handle inter-CRTC |
| 2427 | * depencies. Callers need to ensure that either no such depencies exist, |
| 2428 | * resolve them through ordering of commit calls or through some other means. |
| 2429 | */ |
| 2430 | void |
| 2431 | drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state) |
| 2432 | { |
| 2433 | const struct drm_crtc_helper_funcs *crtc_funcs; |
| 2434 | struct drm_crtc *crtc = old_crtc_state->crtc; |
| 2435 | struct drm_atomic_state *old_state = old_crtc_state->state; |
Ville Syrjälä | e35a2f9 | 2018-06-26 23:41:44 +0300 | [diff] [blame] | 2436 | struct drm_crtc_state *new_crtc_state = |
| 2437 | drm_atomic_get_new_crtc_state(old_state, crtc); |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 2438 | struct drm_plane *plane; |
| 2439 | unsigned plane_mask; |
| 2440 | |
| 2441 | plane_mask = old_crtc_state->plane_mask; |
Ville Syrjälä | e35a2f9 | 2018-06-26 23:41:44 +0300 | [diff] [blame] | 2442 | plane_mask |= new_crtc_state->plane_mask; |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 2443 | |
| 2444 | crtc_funcs = crtc->helper_private; |
| 2445 | if (crtc_funcs && crtc_funcs->atomic_begin) |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 2446 | crtc_funcs->atomic_begin(crtc, old_crtc_state); |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 2447 | |
| 2448 | drm_for_each_plane_mask(plane, crtc->dev, plane_mask) { |
| 2449 | struct drm_plane_state *old_plane_state = |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 2450 | drm_atomic_get_old_plane_state(old_state, plane); |
Ville Syrjälä | e35a2f9 | 2018-06-26 23:41:44 +0300 | [diff] [blame] | 2451 | struct drm_plane_state *new_plane_state = |
| 2452 | drm_atomic_get_new_plane_state(old_state, plane); |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 2453 | const struct drm_plane_helper_funcs *plane_funcs; |
| 2454 | |
| 2455 | plane_funcs = plane->helper_private; |
| 2456 | |
| 2457 | if (!old_plane_state || !plane_funcs) |
| 2458 | continue; |
| 2459 | |
Ville Syrjälä | e35a2f9 | 2018-06-26 23:41:44 +0300 | [diff] [blame] | 2460 | WARN_ON(new_plane_state->crtc && |
| 2461 | new_plane_state->crtc != crtc); |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 2462 | |
Ville Syrjälä | e35a2f9 | 2018-06-26 23:41:44 +0300 | [diff] [blame] | 2463 | if (drm_atomic_plane_disabling(old_plane_state, new_plane_state) && |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 2464 | plane_funcs->atomic_disable) |
| 2465 | plane_funcs->atomic_disable(plane, old_plane_state); |
Ville Syrjälä | e35a2f9 | 2018-06-26 23:41:44 +0300 | [diff] [blame] | 2466 | else if (new_plane_state->crtc || |
| 2467 | drm_atomic_plane_disabling(old_plane_state, new_plane_state)) |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 2468 | plane_funcs->atomic_update(plane, old_plane_state); |
| 2469 | } |
| 2470 | |
| 2471 | if (crtc_funcs && crtc_funcs->atomic_flush) |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 2472 | crtc_funcs->atomic_flush(crtc, old_crtc_state); |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 2473 | } |
| 2474 | EXPORT_SYMBOL(drm_atomic_helper_commit_planes_on_crtc); |
| 2475 | |
| 2476 | /** |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 2477 | * drm_atomic_helper_disable_planes_on_crtc - helper to disable CRTC's planes |
Liu Ying | 2850029 | 2016-08-26 15:30:39 +0800 | [diff] [blame] | 2478 | * @old_crtc_state: atomic state object with the old CRTC state |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 2479 | * @atomic: if set, synchronize with CRTC's atomic_begin/flush hooks |
| 2480 | * |
| 2481 | * Disables all planes associated with the given CRTC. This can be |
Liu Ying | 2850029 | 2016-08-26 15:30:39 +0800 | [diff] [blame] | 2482 | * used for instance in the CRTC helper atomic_disable callback to disable |
| 2483 | * all planes. |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 2484 | * |
| 2485 | * If the atomic-parameter is set the function calls the CRTC's |
| 2486 | * atomic_begin hook before and atomic_flush hook after disabling the |
| 2487 | * planes. |
| 2488 | * |
| 2489 | * It is a bug to call this function without having implemented the |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 2490 | * &drm_plane_helper_funcs.atomic_disable plane hook. |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 2491 | */ |
Liu Ying | 2850029 | 2016-08-26 15:30:39 +0800 | [diff] [blame] | 2492 | void |
| 2493 | drm_atomic_helper_disable_planes_on_crtc(struct drm_crtc_state *old_crtc_state, |
| 2494 | bool atomic) |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 2495 | { |
Liu Ying | 2850029 | 2016-08-26 15:30:39 +0800 | [diff] [blame] | 2496 | struct drm_crtc *crtc = old_crtc_state->crtc; |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 2497 | const struct drm_crtc_helper_funcs *crtc_funcs = |
| 2498 | crtc->helper_private; |
| 2499 | struct drm_plane *plane; |
| 2500 | |
| 2501 | if (atomic && crtc_funcs && crtc_funcs->atomic_begin) |
| 2502 | crtc_funcs->atomic_begin(crtc, NULL); |
| 2503 | |
Liu Ying | 2850029 | 2016-08-26 15:30:39 +0800 | [diff] [blame] | 2504 | drm_atomic_crtc_state_for_each_plane(plane, old_crtc_state) { |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 2505 | const struct drm_plane_helper_funcs *plane_funcs = |
| 2506 | plane->helper_private; |
| 2507 | |
Liu Ying | 2850029 | 2016-08-26 15:30:39 +0800 | [diff] [blame] | 2508 | if (!plane_funcs) |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 2509 | continue; |
| 2510 | |
| 2511 | WARN_ON(!plane_funcs->atomic_disable); |
| 2512 | if (plane_funcs->atomic_disable) |
| 2513 | plane_funcs->atomic_disable(plane, NULL); |
| 2514 | } |
| 2515 | |
| 2516 | if (atomic && crtc_funcs && crtc_funcs->atomic_flush) |
| 2517 | crtc_funcs->atomic_flush(crtc, NULL); |
| 2518 | } |
| 2519 | EXPORT_SYMBOL(drm_atomic_helper_disable_planes_on_crtc); |
| 2520 | |
| 2521 | /** |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2522 | * drm_atomic_helper_cleanup_planes - cleanup plane resources after commit |
| 2523 | * @dev: DRM device |
| 2524 | * @old_state: atomic state object with old state structures |
| 2525 | * |
| 2526 | * This function cleans up plane state, specifically framebuffers, from the old |
| 2527 | * configuration. Hence the old configuration must be perserved in @old_state to |
| 2528 | * be able to call this function. |
| 2529 | * |
| 2530 | * This function must also be called on the new state when the atomic update |
| 2531 | * fails at any point after calling drm_atomic_helper_prepare_planes(). |
| 2532 | */ |
| 2533 | void drm_atomic_helper_cleanup_planes(struct drm_device *dev, |
| 2534 | struct drm_atomic_state *old_state) |
| 2535 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 2536 | struct drm_plane *plane; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2537 | struct drm_plane_state *old_plane_state, *new_plane_state; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2538 | int i; |
| 2539 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2540 | for_each_oldnew_plane_in_state(old_state, plane, old_plane_state, new_plane_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 2541 | const struct drm_plane_helper_funcs *funcs; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2542 | struct drm_plane_state *plane_state; |
| 2543 | |
| 2544 | /* |
| 2545 | * This might be called before swapping when commit is aborted, |
| 2546 | * in which case we have to cleanup the new state. |
| 2547 | */ |
| 2548 | if (old_plane_state == plane->state) |
| 2549 | plane_state = new_plane_state; |
| 2550 | else |
| 2551 | plane_state = old_plane_state; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2552 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2553 | funcs = plane->helper_private; |
| 2554 | |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 2555 | if (funcs->cleanup_fb) |
| 2556 | funcs->cleanup_fb(plane, plane_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2557 | } |
| 2558 | } |
| 2559 | EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes); |
| 2560 | |
| 2561 | /** |
| 2562 | * drm_atomic_helper_swap_state - store atomic state into current sw state |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2563 | * @state: atomic state |
Maarten Lankhorst | c066d23 | 2017-07-11 16:33:04 +0200 | [diff] [blame] | 2564 | * @stall: stall for preceeding commits |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2565 | * |
| 2566 | * This function stores the atomic state into the current state pointers in all |
| 2567 | * driver objects. It should be called after all failing steps have been done |
| 2568 | * and succeeded, but before the actual hardware state is committed. |
| 2569 | * |
| 2570 | * For cleanup and error recovery the current state for all changed objects will |
Maarten Lankhorst | c066d23 | 2017-07-11 16:33:04 +0200 | [diff] [blame] | 2571 | * be swapped into @state. |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2572 | * |
| 2573 | * With that sequence it fits perfectly into the plane prepare/cleanup sequence: |
| 2574 | * |
| 2575 | * 1. Call drm_atomic_helper_prepare_planes() with the staged atomic state. |
| 2576 | * |
| 2577 | * 2. Do any other steps that might fail. |
| 2578 | * |
| 2579 | * 3. Put the staged state into the current state pointers with this function. |
| 2580 | * |
| 2581 | * 4. Actually commit the hardware state. |
| 2582 | * |
Daniel Vetter | 26196f7 | 2015-08-25 16:26:03 +0200 | [diff] [blame] | 2583 | * 5. Call drm_atomic_helper_cleanup_planes() with @state, which since step 3 |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2584 | * contains the old state. Also do any other cleanup required with that state. |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2585 | * |
| 2586 | * @stall must be set when nonblocking commits for this driver directly access |
Daniel Vetter | 6806cdf | 2017-01-25 07:26:43 +0100 | [diff] [blame] | 2587 | * the &drm_plane.state, &drm_crtc.state or &drm_connector.state pointer. With |
| 2588 | * the current atomic helpers this is almost always the case, since the helpers |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2589 | * don't pass the right state structures to the callbacks. |
Maarten Lankhorst | c066d23 | 2017-07-11 16:33:04 +0200 | [diff] [blame] | 2590 | * |
| 2591 | * Returns: |
| 2592 | * |
Maarten Lankhorst | c4bbb73 | 2017-07-11 16:33:14 +0200 | [diff] [blame] | 2593 | * Returns 0 on success. Can return -ERESTARTSYS when @stall is true and the |
| 2594 | * waiting for the previous commits has been interrupted. |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2595 | */ |
Maarten Lankhorst | c066d23 | 2017-07-11 16:33:04 +0200 | [diff] [blame] | 2596 | int drm_atomic_helper_swap_state(struct drm_atomic_state *state, |
Daniel Vetter | 5e84c26 | 2016-06-10 00:06:32 +0200 | [diff] [blame] | 2597 | bool stall) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2598 | { |
Maarten Lankhorst | c4bbb73 | 2017-07-11 16:33:14 +0200 | [diff] [blame] | 2599 | int i, ret; |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 2600 | struct drm_connector *connector; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2601 | struct drm_connector_state *old_conn_state, *new_conn_state; |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 2602 | struct drm_crtc *crtc; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2603 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 2604 | struct drm_plane *plane; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2605 | struct drm_plane_state *old_plane_state, *new_plane_state; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2606 | struct drm_crtc_commit *commit; |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 2607 | struct drm_private_obj *obj; |
| 2608 | struct drm_private_state *old_obj_state, *new_obj_state; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2609 | |
| 2610 | if (stall) { |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 2611 | /* |
| 2612 | * We have to stall for hw_done here before |
| 2613 | * drm_atomic_helper_wait_for_dependencies() because flip |
| 2614 | * depth > 1 is not yet supported by all drivers. As long as |
| 2615 | * obj->state is directly dereferenced anywhere in the drivers |
| 2616 | * atomic_commit_tail function, then it's unsafe to swap state |
| 2617 | * before drm_atomic_helper_commit_hw_done() is called. |
| 2618 | */ |
| 2619 | |
Maarten Lankhorst | 163bcc2 | 2017-09-04 17:04:56 +0200 | [diff] [blame] | 2620 | for_each_old_crtc_in_state(state, crtc, old_crtc_state, i) { |
| 2621 | commit = old_crtc_state->commit; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2622 | |
| 2623 | if (!commit) |
| 2624 | continue; |
| 2625 | |
Maarten Lankhorst | c4bbb73 | 2017-07-11 16:33:14 +0200 | [diff] [blame] | 2626 | ret = wait_for_completion_interruptible(&commit->hw_done); |
Maarten Lankhorst | c4bbb73 | 2017-07-11 16:33:14 +0200 | [diff] [blame] | 2627 | if (ret) |
| 2628 | return ret; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2629 | } |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2630 | |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 2631 | for_each_old_connector_in_state(state, connector, old_conn_state, i) { |
| 2632 | commit = old_conn_state->commit; |
| 2633 | |
| 2634 | if (!commit) |
| 2635 | continue; |
| 2636 | |
| 2637 | ret = wait_for_completion_interruptible(&commit->hw_done); |
| 2638 | if (ret) |
| 2639 | return ret; |
| 2640 | } |
| 2641 | |
| 2642 | for_each_old_plane_in_state(state, plane, old_plane_state, i) { |
| 2643 | commit = old_plane_state->commit; |
| 2644 | |
| 2645 | if (!commit) |
| 2646 | continue; |
| 2647 | |
| 2648 | ret = wait_for_completion_interruptible(&commit->hw_done); |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2649 | if (ret) |
| 2650 | return ret; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2651 | } |
| 2652 | } |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2653 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2654 | for_each_oldnew_connector_in_state(state, connector, old_conn_state, new_conn_state, i) { |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 2655 | WARN_ON(connector->state != old_conn_state); |
| 2656 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2657 | old_conn_state->state = state; |
| 2658 | new_conn_state->state = NULL; |
| 2659 | |
| 2660 | state->connectors[i].state = old_conn_state; |
| 2661 | connector->state = new_conn_state; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2662 | } |
| 2663 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2664 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 2665 | WARN_ON(crtc->state != old_crtc_state); |
| 2666 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2667 | old_crtc_state->state = state; |
| 2668 | new_crtc_state->state = NULL; |
| 2669 | |
| 2670 | state->crtcs[i].state = old_crtc_state; |
| 2671 | crtc->state = new_crtc_state; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2672 | |
Maarten Lankhorst | 163bcc2 | 2017-09-04 17:04:56 +0200 | [diff] [blame] | 2673 | if (new_crtc_state->commit) { |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2674 | spin_lock(&crtc->commit_lock); |
Maarten Lankhorst | 163bcc2 | 2017-09-04 17:04:56 +0200 | [diff] [blame] | 2675 | list_add(&new_crtc_state->commit->commit_entry, |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2676 | &crtc->commit_list); |
| 2677 | spin_unlock(&crtc->commit_lock); |
| 2678 | |
Maarten Lankhorst | 163bcc2 | 2017-09-04 17:04:56 +0200 | [diff] [blame] | 2679 | new_crtc_state->commit->event = NULL; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2680 | } |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2681 | } |
| 2682 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2683 | for_each_oldnew_plane_in_state(state, plane, old_plane_state, new_plane_state, i) { |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 2684 | WARN_ON(plane->state != old_plane_state); |
| 2685 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2686 | old_plane_state->state = state; |
| 2687 | new_plane_state->state = NULL; |
| 2688 | |
| 2689 | state->planes[i].state = old_plane_state; |
| 2690 | plane->state = new_plane_state; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2691 | } |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 2692 | |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 2693 | for_each_oldnew_private_obj_in_state(state, obj, old_obj_state, new_obj_state, i) { |
| 2694 | WARN_ON(obj->state != old_obj_state); |
| 2695 | |
| 2696 | old_obj_state->state = state; |
| 2697 | new_obj_state->state = NULL; |
| 2698 | |
| 2699 | state->private_objs[i].state = old_obj_state; |
| 2700 | obj->state = new_obj_state; |
| 2701 | } |
Maarten Lankhorst | c066d23 | 2017-07-11 16:33:04 +0200 | [diff] [blame] | 2702 | |
| 2703 | return 0; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2704 | } |
| 2705 | EXPORT_SYMBOL(drm_atomic_helper_swap_state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2706 | |
| 2707 | /** |
| 2708 | * drm_atomic_helper_update_plane - Helper for primary plane update using atomic |
| 2709 | * @plane: plane object to update |
| 2710 | * @crtc: owning CRTC of owning plane |
| 2711 | * @fb: framebuffer to flip onto plane |
| 2712 | * @crtc_x: x offset of primary plane on crtc |
| 2713 | * @crtc_y: y offset of primary plane on crtc |
| 2714 | * @crtc_w: width of primary plane rectangle on crtc |
| 2715 | * @crtc_h: height of primary plane rectangle on crtc |
| 2716 | * @src_x: x offset of @fb for panning |
| 2717 | * @src_y: y offset of @fb for panning |
| 2718 | * @src_w: width of source rectangle in @fb |
| 2719 | * @src_h: height of source rectangle in @fb |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 2720 | * @ctx: lock acquire context |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2721 | * |
| 2722 | * Provides a default plane update handler using the atomic driver interface. |
| 2723 | * |
| 2724 | * RETURNS: |
| 2725 | * Zero on success, error code on failure |
| 2726 | */ |
| 2727 | int drm_atomic_helper_update_plane(struct drm_plane *plane, |
| 2728 | struct drm_crtc *crtc, |
| 2729 | struct drm_framebuffer *fb, |
| 2730 | int crtc_x, int crtc_y, |
| 2731 | unsigned int crtc_w, unsigned int crtc_h, |
| 2732 | uint32_t src_x, uint32_t src_y, |
Daniel Vetter | 34a2ab5 | 2017-03-22 22:50:41 +0100 | [diff] [blame] | 2733 | uint32_t src_w, uint32_t src_h, |
| 2734 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2735 | { |
| 2736 | struct drm_atomic_state *state; |
| 2737 | struct drm_plane_state *plane_state; |
| 2738 | int ret = 0; |
| 2739 | |
| 2740 | state = drm_atomic_state_alloc(plane->dev); |
| 2741 | if (!state) |
| 2742 | return -ENOMEM; |
| 2743 | |
Daniel Vetter | d26f96c | 2017-03-22 22:50:44 +0100 | [diff] [blame] | 2744 | state->acquire_ctx = ctx; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2745 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 2746 | if (IS_ERR(plane_state)) { |
| 2747 | ret = PTR_ERR(plane_state); |
| 2748 | goto fail; |
| 2749 | } |
| 2750 | |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 2751 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2752 | if (ret != 0) |
| 2753 | goto fail; |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 2754 | drm_atomic_set_fb_for_plane(plane_state, fb); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2755 | plane_state->crtc_x = crtc_x; |
| 2756 | plane_state->crtc_y = crtc_y; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2757 | plane_state->crtc_w = crtc_w; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 2758 | plane_state->crtc_h = crtc_h; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2759 | plane_state->src_x = src_x; |
| 2760 | plane_state->src_y = src_y; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2761 | plane_state->src_w = src_w; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 2762 | plane_state->src_h = src_h; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2763 | |
Daniel Vetter | 3671c58 | 2015-05-04 15:40:52 +0200 | [diff] [blame] | 2764 | if (plane == crtc->cursor) |
| 2765 | state->legacy_cursor_update = true; |
| 2766 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2767 | ret = drm_atomic_commit(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2768 | fail: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2769 | drm_atomic_state_put(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2770 | return ret; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2771 | } |
| 2772 | EXPORT_SYMBOL(drm_atomic_helper_update_plane); |
| 2773 | |
| 2774 | /** |
| 2775 | * drm_atomic_helper_disable_plane - Helper for primary plane disable using * atomic |
| 2776 | * @plane: plane to disable |
Daniel Vetter | 1931529 | 2017-03-22 22:50:43 +0100 | [diff] [blame] | 2777 | * @ctx: lock acquire context |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2778 | * |
| 2779 | * Provides a default plane disable handler using the atomic driver interface. |
| 2780 | * |
| 2781 | * RETURNS: |
| 2782 | * Zero on success, error code on failure |
| 2783 | */ |
Daniel Vetter | 1931529 | 2017-03-22 22:50:43 +0100 | [diff] [blame] | 2784 | int drm_atomic_helper_disable_plane(struct drm_plane *plane, |
| 2785 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2786 | { |
| 2787 | struct drm_atomic_state *state; |
| 2788 | struct drm_plane_state *plane_state; |
| 2789 | int ret = 0; |
| 2790 | |
| 2791 | state = drm_atomic_state_alloc(plane->dev); |
| 2792 | if (!state) |
| 2793 | return -ENOMEM; |
| 2794 | |
Daniel Vetter | d26f96c | 2017-03-22 22:50:44 +0100 | [diff] [blame] | 2795 | state->acquire_ctx = ctx; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2796 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 2797 | if (IS_ERR(plane_state)) { |
| 2798 | ret = PTR_ERR(plane_state); |
| 2799 | goto fail; |
| 2800 | } |
| 2801 | |
Ville Syrjälä | a36c027 | 2018-03-22 17:22:58 +0200 | [diff] [blame] | 2802 | if (plane_state->crtc && plane_state->crtc->cursor == plane) |
Maarten Lankhorst | 24e79d0 | 2015-11-11 11:29:07 +0100 | [diff] [blame] | 2803 | plane_state->state->legacy_cursor_update = true; |
| 2804 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2805 | ret = __drm_atomic_helper_disable_plane(plane, plane_state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2806 | if (ret != 0) |
| 2807 | goto fail; |
Daniel Vetter | f02ad90 | 2015-01-22 16:36:23 +0100 | [diff] [blame] | 2808 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2809 | ret = drm_atomic_commit(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2810 | fail: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2811 | drm_atomic_state_put(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2812 | return ret; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2813 | } |
| 2814 | EXPORT_SYMBOL(drm_atomic_helper_disable_plane); |
| 2815 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2816 | /* just used from fb-helper and atomic-helper: */ |
| 2817 | int __drm_atomic_helper_disable_plane(struct drm_plane *plane, |
| 2818 | struct drm_plane_state *plane_state) |
| 2819 | { |
| 2820 | int ret; |
| 2821 | |
| 2822 | ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); |
| 2823 | if (ret != 0) |
| 2824 | return ret; |
| 2825 | |
| 2826 | drm_atomic_set_fb_for_plane(plane_state, NULL); |
| 2827 | plane_state->crtc_x = 0; |
| 2828 | plane_state->crtc_y = 0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2829 | plane_state->crtc_w = 0; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 2830 | plane_state->crtc_h = 0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2831 | plane_state->src_x = 0; |
| 2832 | plane_state->src_y = 0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2833 | plane_state->src_w = 0; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 2834 | plane_state->src_h = 0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2835 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2836 | return 0; |
| 2837 | } |
| 2838 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2839 | static int update_output_state(struct drm_atomic_state *state, |
| 2840 | struct drm_mode_set *set) |
| 2841 | { |
| 2842 | struct drm_device *dev = set->crtc->dev; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 2843 | struct drm_crtc *crtc; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2844 | struct drm_crtc_state *new_crtc_state; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 2845 | struct drm_connector *connector; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2846 | struct drm_connector_state *new_conn_state; |
Maarten Lankhorst | 6ab520a | 2016-02-24 09:37:28 +0100 | [diff] [blame] | 2847 | int ret, i; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2848 | |
| 2849 | ret = drm_modeset_lock(&dev->mode_config.connection_mutex, |
| 2850 | state->acquire_ctx); |
| 2851 | if (ret) |
| 2852 | return ret; |
| 2853 | |
Maarten Lankhorst | 6ab520a | 2016-02-24 09:37:28 +0100 | [diff] [blame] | 2854 | /* First disable all connectors on the target crtc. */ |
| 2855 | ret = drm_atomic_add_affected_connectors(state, set->crtc); |
| 2856 | if (ret) |
| 2857 | return ret; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2858 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2859 | for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
| 2860 | if (new_conn_state->crtc == set->crtc) { |
| 2861 | ret = drm_atomic_set_crtc_for_connector(new_conn_state, |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2862 | NULL); |
| 2863 | if (ret) |
| 2864 | return ret; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2865 | |
Manasi Navare | 40ee6fb | 2016-12-16 12:29:06 +0200 | [diff] [blame] | 2866 | /* Make sure legacy setCrtc always re-trains */ |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2867 | new_conn_state->link_status = DRM_LINK_STATUS_GOOD; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2868 | } |
Maarten Lankhorst | 6ab520a | 2016-02-24 09:37:28 +0100 | [diff] [blame] | 2869 | } |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2870 | |
Maarten Lankhorst | 6ab520a | 2016-02-24 09:37:28 +0100 | [diff] [blame] | 2871 | /* Then set all connectors from set->connectors on the target crtc */ |
| 2872 | for (i = 0; i < set->num_connectors; i++) { |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2873 | new_conn_state = drm_atomic_get_connector_state(state, |
Maarten Lankhorst | 6ab520a | 2016-02-24 09:37:28 +0100 | [diff] [blame] | 2874 | set->connectors[i]); |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2875 | if (IS_ERR(new_conn_state)) |
| 2876 | return PTR_ERR(new_conn_state); |
Maarten Lankhorst | 6ab520a | 2016-02-24 09:37:28 +0100 | [diff] [blame] | 2877 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2878 | ret = drm_atomic_set_crtc_for_connector(new_conn_state, |
Maarten Lankhorst | 6ab520a | 2016-02-24 09:37:28 +0100 | [diff] [blame] | 2879 | set->crtc); |
| 2880 | if (ret) |
| 2881 | return ret; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2882 | } |
| 2883 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2884 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2885 | /* Don't update ->enable for the CRTC in the set_config request, |
| 2886 | * since a mismatch would indicate a bug in the upper layers. |
| 2887 | * The actual modeset code later on will catch any |
| 2888 | * inconsistencies here. */ |
| 2889 | if (crtc == set->crtc) |
| 2890 | continue; |
| 2891 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2892 | if (!new_crtc_state->connector_mask) { |
| 2893 | ret = drm_atomic_set_mode_prop_for_crtc(new_crtc_state, |
Laurent Pinchart | c30f55a | 2015-06-22 13:37:46 +0300 | [diff] [blame] | 2894 | NULL); |
| 2895 | if (ret < 0) |
| 2896 | return ret; |
| 2897 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 2898 | new_crtc_state->active = false; |
Laurent Pinchart | c30f55a | 2015-06-22 13:37:46 +0300 | [diff] [blame] | 2899 | } |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | return 0; |
| 2903 | } |
| 2904 | |
| 2905 | /** |
| 2906 | * drm_atomic_helper_set_config - set a new config from userspace |
| 2907 | * @set: mode set configuration |
Daniel Vetter | a4eff9a | 2017-03-22 22:50:57 +0100 | [diff] [blame] | 2908 | * @ctx: lock acquisition context |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2909 | * |
| 2910 | * Provides a default crtc set_config handler using the atomic driver interface. |
| 2911 | * |
Manasi Navare | 40ee6fb | 2016-12-16 12:29:06 +0200 | [diff] [blame] | 2912 | * NOTE: For backwards compatibility with old userspace this automatically |
| 2913 | * resets the "link-status" property to GOOD, to force any link |
| 2914 | * re-training. The SETCRTC ioctl does not define whether an update does |
| 2915 | * need a full modeset or just a plane update, hence we're allowed to do |
Daniel Vetter | 97e14fb | 2018-07-09 10:40:08 +0200 | [diff] [blame] | 2916 | * that. See also drm_connector_set_link_status_property(). |
Manasi Navare | 40ee6fb | 2016-12-16 12:29:06 +0200 | [diff] [blame] | 2917 | * |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2918 | * Returns: |
| 2919 | * Returns 0 on success, negative errno numbers on failure. |
| 2920 | */ |
Daniel Vetter | a4eff9a | 2017-03-22 22:50:57 +0100 | [diff] [blame] | 2921 | int drm_atomic_helper_set_config(struct drm_mode_set *set, |
| 2922 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2923 | { |
| 2924 | struct drm_atomic_state *state; |
| 2925 | struct drm_crtc *crtc = set->crtc; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2926 | int ret = 0; |
| 2927 | |
| 2928 | state = drm_atomic_state_alloc(crtc->dev); |
| 2929 | if (!state) |
| 2930 | return -ENOMEM; |
| 2931 | |
Daniel Vetter | 38b6441 | 2017-03-22 22:50:58 +0100 | [diff] [blame] | 2932 | state->acquire_ctx = ctx; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2933 | ret = __drm_atomic_helper_set_config(set, state); |
Daniel Stone | 819364d | 2015-05-26 14:36:48 +0100 | [diff] [blame] | 2934 | if (ret != 0) |
Daniel Vetter | 1fa4da0 | 2017-03-29 19:41:36 +0200 | [diff] [blame] | 2935 | goto fail; |
Daniel Stone | 819364d | 2015-05-26 14:36:48 +0100 | [diff] [blame] | 2936 | |
Maarten Lankhorst | 44596b8 | 2017-04-06 13:19:00 +0200 | [diff] [blame] | 2937 | ret = handle_conflicting_encoders(state, true); |
| 2938 | if (ret) |
| 2939 | return ret; |
| 2940 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2941 | ret = drm_atomic_commit(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2942 | |
Daniel Vetter | 1fa4da0 | 2017-03-29 19:41:36 +0200 | [diff] [blame] | 2943 | fail: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2944 | drm_atomic_state_put(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2945 | return ret; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2946 | } |
| 2947 | EXPORT_SYMBOL(drm_atomic_helper_set_config); |
| 2948 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2949 | /* just used from fb-helper and atomic-helper: */ |
| 2950 | int __drm_atomic_helper_set_config(struct drm_mode_set *set, |
| 2951 | struct drm_atomic_state *state) |
| 2952 | { |
| 2953 | struct drm_crtc_state *crtc_state; |
| 2954 | struct drm_plane_state *primary_state; |
| 2955 | struct drm_crtc *crtc = set->crtc; |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 2956 | int hdisplay, vdisplay; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2957 | int ret; |
| 2958 | |
| 2959 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 2960 | if (IS_ERR(crtc_state)) |
| 2961 | return PTR_ERR(crtc_state); |
| 2962 | |
| 2963 | primary_state = drm_atomic_get_plane_state(state, crtc->primary); |
| 2964 | if (IS_ERR(primary_state)) |
| 2965 | return PTR_ERR(primary_state); |
| 2966 | |
| 2967 | if (!set->mode) { |
| 2968 | WARN_ON(set->fb); |
| 2969 | WARN_ON(set->num_connectors); |
| 2970 | |
| 2971 | ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL); |
| 2972 | if (ret != 0) |
| 2973 | return ret; |
| 2974 | |
| 2975 | crtc_state->active = false; |
| 2976 | |
| 2977 | ret = drm_atomic_set_crtc_for_plane(primary_state, NULL); |
| 2978 | if (ret != 0) |
| 2979 | return ret; |
| 2980 | |
| 2981 | drm_atomic_set_fb_for_plane(primary_state, NULL); |
| 2982 | |
| 2983 | goto commit; |
| 2984 | } |
| 2985 | |
| 2986 | WARN_ON(!set->fb); |
| 2987 | WARN_ON(!set->num_connectors); |
| 2988 | |
| 2989 | ret = drm_atomic_set_mode_for_crtc(crtc_state, set->mode); |
| 2990 | if (ret != 0) |
| 2991 | return ret; |
| 2992 | |
| 2993 | crtc_state->active = true; |
| 2994 | |
| 2995 | ret = drm_atomic_set_crtc_for_plane(primary_state, crtc); |
| 2996 | if (ret != 0) |
| 2997 | return ret; |
| 2998 | |
Daniel Vetter | 196cd5d | 2017-01-25 07:26:56 +0100 | [diff] [blame] | 2999 | drm_mode_get_hv_timing(set->mode, &hdisplay, &vdisplay); |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 3000 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 3001 | drm_atomic_set_fb_for_plane(primary_state, set->fb); |
| 3002 | primary_state->crtc_x = 0; |
| 3003 | primary_state->crtc_y = 0; |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 3004 | primary_state->crtc_w = hdisplay; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 3005 | primary_state->crtc_h = vdisplay; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 3006 | primary_state->src_x = set->x << 16; |
| 3007 | primary_state->src_y = set->y << 16; |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 3008 | if (drm_rotation_90_or_270(primary_state->rotation)) { |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 3009 | primary_state->src_w = vdisplay << 16; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 3010 | primary_state->src_h = hdisplay << 16; |
Ville Syrjälä | 4112124 | 2015-10-15 20:39:59 +0300 | [diff] [blame] | 3011 | } else { |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 3012 | primary_state->src_w = hdisplay << 16; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 3013 | primary_state->src_h = vdisplay << 16; |
Ville Syrjälä | 4112124 | 2015-10-15 20:39:59 +0300 | [diff] [blame] | 3014 | } |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 3015 | |
| 3016 | commit: |
| 3017 | ret = update_output_state(state, set); |
| 3018 | if (ret) |
| 3019 | return ret; |
| 3020 | |
| 3021 | return 0; |
| 3022 | } |
| 3023 | |
Ville Syrjälä | 5e9cfeb | 2018-03-22 17:22:51 +0200 | [diff] [blame] | 3024 | static int __drm_atomic_helper_disable_all(struct drm_device *dev, |
| 3025 | struct drm_modeset_acquire_ctx *ctx, |
| 3026 | bool clean_old_fbs) |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3027 | { |
| 3028 | struct drm_atomic_state *state; |
Maarten Lankhorst | 9b2104f | 2017-02-21 14:51:40 +0100 | [diff] [blame] | 3029 | struct drm_connector_state *conn_state; |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3030 | struct drm_connector *conn; |
Maarten Lankhorst | 9b2104f | 2017-02-21 14:51:40 +0100 | [diff] [blame] | 3031 | struct drm_plane_state *plane_state; |
| 3032 | struct drm_plane *plane; |
| 3033 | struct drm_crtc_state *crtc_state; |
| 3034 | struct drm_crtc *crtc; |
| 3035 | int ret, i; |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3036 | |
| 3037 | state = drm_atomic_state_alloc(dev); |
| 3038 | if (!state) |
| 3039 | return -ENOMEM; |
| 3040 | |
| 3041 | state->acquire_ctx = ctx; |
| 3042 | |
Maarten Lankhorst | 9b2104f | 2017-02-21 14:51:40 +0100 | [diff] [blame] | 3043 | drm_for_each_crtc(crtc, dev) { |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3044 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 3045 | if (IS_ERR(crtc_state)) { |
Maarten Lankhorst | 9b2104f | 2017-02-21 14:51:40 +0100 | [diff] [blame] | 3046 | ret = PTR_ERR(crtc_state); |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3047 | goto free; |
| 3048 | } |
| 3049 | |
| 3050 | crtc_state->active = false; |
Maarten Lankhorst | 9b2104f | 2017-02-21 14:51:40 +0100 | [diff] [blame] | 3051 | |
| 3052 | ret = drm_atomic_set_mode_prop_for_crtc(crtc_state, NULL); |
| 3053 | if (ret < 0) |
| 3054 | goto free; |
| 3055 | |
| 3056 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 3057 | if (ret < 0) |
| 3058 | goto free; |
| 3059 | |
| 3060 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 3061 | if (ret < 0) |
| 3062 | goto free; |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3063 | } |
| 3064 | |
Maarten Lankhorst | dfb8bb3 | 2017-07-12 10:13:31 +0200 | [diff] [blame] | 3065 | for_each_new_connector_in_state(state, conn, conn_state, i) { |
Maarten Lankhorst | 9b2104f | 2017-02-21 14:51:40 +0100 | [diff] [blame] | 3066 | ret = drm_atomic_set_crtc_for_connector(conn_state, NULL); |
| 3067 | if (ret < 0) |
| 3068 | goto free; |
| 3069 | } |
| 3070 | |
Maarten Lankhorst | dfb8bb3 | 2017-07-12 10:13:31 +0200 | [diff] [blame] | 3071 | for_each_new_plane_in_state(state, plane, plane_state, i) { |
Maarten Lankhorst | 9b2104f | 2017-02-21 14:51:40 +0100 | [diff] [blame] | 3072 | ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); |
| 3073 | if (ret < 0) |
| 3074 | goto free; |
| 3075 | |
| 3076 | drm_atomic_set_fb_for_plane(plane_state, NULL); |
| 3077 | } |
| 3078 | |
| 3079 | ret = drm_atomic_commit(state); |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3080 | free: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 3081 | drm_atomic_state_put(state); |
Maarten Lankhorst | 9b2104f | 2017-02-21 14:51:40 +0100 | [diff] [blame] | 3082 | return ret; |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3083 | } |
Maarten Lankhorst | 9b2104f | 2017-02-21 14:51:40 +0100 | [diff] [blame] | 3084 | |
Ville Syrjälä | 5e9cfeb | 2018-03-22 17:22:51 +0200 | [diff] [blame] | 3085 | /** |
| 3086 | * drm_atomic_helper_disable_all - disable all currently active outputs |
| 3087 | * @dev: DRM device |
| 3088 | * @ctx: lock acquisition context |
| 3089 | * |
| 3090 | * Loops through all connectors, finding those that aren't turned off and then |
| 3091 | * turns them off by setting their DPMS mode to OFF and deactivating the CRTC |
| 3092 | * that they are connected to. |
| 3093 | * |
| 3094 | * This is used for example in suspend/resume to disable all currently active |
| 3095 | * functions when suspending. If you just want to shut down everything at e.g. |
| 3096 | * driver unload, look at drm_atomic_helper_shutdown(). |
| 3097 | * |
| 3098 | * Note that if callers haven't already acquired all modeset locks this might |
| 3099 | * return -EDEADLK, which must be handled by calling drm_modeset_backoff(). |
| 3100 | * |
| 3101 | * Returns: |
| 3102 | * 0 on success or a negative error code on failure. |
| 3103 | * |
| 3104 | * See also: |
| 3105 | * drm_atomic_helper_suspend(), drm_atomic_helper_resume() and |
| 3106 | * drm_atomic_helper_shutdown(). |
| 3107 | */ |
| 3108 | int drm_atomic_helper_disable_all(struct drm_device *dev, |
| 3109 | struct drm_modeset_acquire_ctx *ctx) |
| 3110 | { |
| 3111 | return __drm_atomic_helper_disable_all(dev, ctx, false); |
| 3112 | } |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3113 | EXPORT_SYMBOL(drm_atomic_helper_disable_all); |
| 3114 | |
| 3115 | /** |
Daniel Vetter | 18dddad | 2017-03-21 17:41:49 +0100 | [diff] [blame] | 3116 | * drm_atomic_helper_shutdown - shutdown all CRTC |
| 3117 | * @dev: DRM device |
| 3118 | * |
| 3119 | * This shuts down all CRTC, which is useful for driver unloading. Shutdown on |
| 3120 | * suspend should instead be handled with drm_atomic_helper_suspend(), since |
| 3121 | * that also takes a snapshot of the modeset state to be restored on resume. |
| 3122 | * |
| 3123 | * This is just a convenience wrapper around drm_atomic_helper_disable_all(), |
| 3124 | * and it is the atomic version of drm_crtc_force_disable_all(). |
| 3125 | */ |
| 3126 | void drm_atomic_helper_shutdown(struct drm_device *dev) |
| 3127 | { |
| 3128 | struct drm_modeset_acquire_ctx ctx; |
| 3129 | int ret; |
| 3130 | |
Sean Paul | b7ea04d | 2018-11-29 10:04:17 -0500 | [diff] [blame] | 3131 | DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret); |
Daniel Vetter | 18dddad | 2017-03-21 17:41:49 +0100 | [diff] [blame] | 3132 | |
Sean Paul | b7ea04d | 2018-11-29 10:04:17 -0500 | [diff] [blame] | 3133 | ret = __drm_atomic_helper_disable_all(dev, &ctx, true); |
Daniel Vetter | 18dddad | 2017-03-21 17:41:49 +0100 | [diff] [blame] | 3134 | if (ret) |
| 3135 | DRM_ERROR("Disabling all crtc's during unload failed with %i\n", ret); |
| 3136 | |
Sean Paul | b7ea04d | 2018-11-29 10:04:17 -0500 | [diff] [blame] | 3137 | DRM_MODESET_LOCK_ALL_END(ctx, ret); |
Daniel Vetter | 18dddad | 2017-03-21 17:41:49 +0100 | [diff] [blame] | 3138 | } |
| 3139 | EXPORT_SYMBOL(drm_atomic_helper_shutdown); |
| 3140 | |
| 3141 | /** |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3142 | * drm_atomic_helper_suspend - subsystem-level suspend helper |
| 3143 | * @dev: DRM device |
| 3144 | * |
| 3145 | * Duplicates the current atomic state, disables all active outputs and then |
| 3146 | * returns a pointer to the original atomic state to the caller. Drivers can |
| 3147 | * pass this pointer to the drm_atomic_helper_resume() helper upon resume to |
| 3148 | * restore the output configuration that was active at the time the system |
| 3149 | * entered suspend. |
| 3150 | * |
| 3151 | * Note that it is potentially unsafe to use this. The atomic state object |
| 3152 | * returned by this function is assumed to be persistent. Drivers must ensure |
| 3153 | * that this holds true. Before calling this function, drivers must make sure |
| 3154 | * to suspend fbdev emulation so that nothing can be using the device. |
| 3155 | * |
| 3156 | * Returns: |
| 3157 | * A pointer to a copy of the state before suspend on success or an ERR_PTR()- |
| 3158 | * encoded error code on failure. Drivers should store the returned atomic |
| 3159 | * state object and pass it to the drm_atomic_helper_resume() helper upon |
| 3160 | * resume. |
| 3161 | * |
| 3162 | * See also: |
| 3163 | * drm_atomic_helper_duplicate_state(), drm_atomic_helper_disable_all(), |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3164 | * drm_atomic_helper_resume(), drm_atomic_helper_commit_duplicated_state() |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3165 | */ |
| 3166 | struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev) |
| 3167 | { |
| 3168 | struct drm_modeset_acquire_ctx ctx; |
| 3169 | struct drm_atomic_state *state; |
| 3170 | int err; |
| 3171 | |
Sean Paul | 615aa3d | 2018-11-29 15:36:48 -0500 | [diff] [blame^] | 3172 | /* This can never be returned, but it makes the compiler happy */ |
| 3173 | state = ERR_PTR(-EINVAL); |
| 3174 | |
Sean Paul | b7ea04d | 2018-11-29 10:04:17 -0500 | [diff] [blame] | 3175 | DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, err); |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3176 | |
| 3177 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 3178 | if (IS_ERR(state)) |
| 3179 | goto unlock; |
| 3180 | |
| 3181 | err = drm_atomic_helper_disable_all(dev, &ctx); |
| 3182 | if (err < 0) { |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 3183 | drm_atomic_state_put(state); |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3184 | state = ERR_PTR(err); |
| 3185 | goto unlock; |
| 3186 | } |
| 3187 | |
| 3188 | unlock: |
Sean Paul | b7ea04d | 2018-11-29 10:04:17 -0500 | [diff] [blame] | 3189 | DRM_MODESET_LOCK_ALL_END(ctx, err); |
| 3190 | if (err) |
| 3191 | return ERR_PTR(err); |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3192 | |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3193 | return state; |
| 3194 | } |
| 3195 | EXPORT_SYMBOL(drm_atomic_helper_suspend); |
| 3196 | |
| 3197 | /** |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3198 | * drm_atomic_helper_commit_duplicated_state - commit duplicated state |
| 3199 | * @state: duplicated atomic state to commit |
| 3200 | * @ctx: pointer to acquire_ctx to use for commit. |
| 3201 | * |
| 3202 | * The state returned by drm_atomic_helper_duplicate_state() and |
| 3203 | * drm_atomic_helper_suspend() is partially invalid, and needs to |
| 3204 | * be fixed up before commit. |
| 3205 | * |
| 3206 | * Returns: |
| 3207 | * 0 on success or a negative error code on failure. |
| 3208 | * |
| 3209 | * See also: |
| 3210 | * drm_atomic_helper_suspend() |
| 3211 | */ |
| 3212 | int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state, |
| 3213 | struct drm_modeset_acquire_ctx *ctx) |
| 3214 | { |
Sean Paul | aa394b0 | 2018-11-29 10:04:14 -0500 | [diff] [blame] | 3215 | int i, ret; |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3216 | struct drm_plane *plane; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 3217 | struct drm_plane_state *new_plane_state; |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3218 | struct drm_connector *connector; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 3219 | struct drm_connector_state *new_conn_state; |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3220 | struct drm_crtc *crtc; |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 3221 | struct drm_crtc_state *new_crtc_state; |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3222 | |
| 3223 | state->acquire_ctx = ctx; |
| 3224 | |
Ville Syrjälä | e00fb85 | 2018-05-25 21:50:45 +0300 | [diff] [blame] | 3225 | for_each_new_plane_in_state(state, plane, new_plane_state, i) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3226 | state->planes[i].old_state = plane->state; |
| 3227 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 3228 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3229 | state->crtcs[i].old_state = crtc->state; |
| 3230 | |
Maarten Lankhorst | 415c3ac | 2017-03-01 10:21:26 +0100 | [diff] [blame] | 3231 | for_each_new_connector_in_state(state, connector, new_conn_state, i) |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3232 | state->connectors[i].old_state = connector->state; |
| 3233 | |
Sean Paul | aa394b0 | 2018-11-29 10:04:14 -0500 | [diff] [blame] | 3234 | ret = drm_atomic_commit(state); |
| 3235 | |
| 3236 | state->acquire_ctx = NULL; |
| 3237 | |
| 3238 | return ret; |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3239 | } |
| 3240 | EXPORT_SYMBOL(drm_atomic_helper_commit_duplicated_state); |
| 3241 | |
| 3242 | /** |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3243 | * drm_atomic_helper_resume - subsystem-level resume helper |
| 3244 | * @dev: DRM device |
| 3245 | * @state: atomic state to resume to |
| 3246 | * |
| 3247 | * Calls drm_mode_config_reset() to synchronize hardware and software states, |
| 3248 | * grabs all modeset locks and commits the atomic state object. This can be |
| 3249 | * used in conjunction with the drm_atomic_helper_suspend() helper to |
| 3250 | * implement suspend/resume for drivers that support atomic mode-setting. |
| 3251 | * |
| 3252 | * Returns: |
| 3253 | * 0 on success or a negative error code on failure. |
| 3254 | * |
| 3255 | * See also: |
| 3256 | * drm_atomic_helper_suspend() |
| 3257 | */ |
| 3258 | int drm_atomic_helper_resume(struct drm_device *dev, |
| 3259 | struct drm_atomic_state *state) |
| 3260 | { |
Daniel Vetter | a5b8444 | 2017-04-03 10:32:53 +0200 | [diff] [blame] | 3261 | struct drm_modeset_acquire_ctx ctx; |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3262 | int err; |
| 3263 | |
| 3264 | drm_mode_config_reset(dev); |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 3265 | |
Sean Paul | b7ea04d | 2018-11-29 10:04:17 -0500 | [diff] [blame] | 3266 | DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, err); |
Daniel Vetter | 869e188 | 2017-05-31 10:38:13 +0200 | [diff] [blame] | 3267 | |
Sean Paul | b7ea04d | 2018-11-29 10:04:17 -0500 | [diff] [blame] | 3268 | err = drm_atomic_helper_commit_duplicated_state(state, &ctx); |
Daniel Vetter | a5b8444 | 2017-04-03 10:32:53 +0200 | [diff] [blame] | 3269 | |
Sean Paul | b7ea04d | 2018-11-29 10:04:17 -0500 | [diff] [blame] | 3270 | DRM_MODESET_LOCK_ALL_END(ctx, err); |
Sean Paul | 2aa3eef | 2018-11-29 10:04:16 -0500 | [diff] [blame] | 3271 | drm_atomic_state_put(state); |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3272 | |
| 3273 | return err; |
| 3274 | } |
| 3275 | EXPORT_SYMBOL(drm_atomic_helper_resume); |
| 3276 | |
Daniel Vetter | 8c3a818 | 2017-06-27 16:59:36 +0200 | [diff] [blame] | 3277 | static int page_flip_common(struct drm_atomic_state *state, |
| 3278 | struct drm_crtc *crtc, |
| 3279 | struct drm_framebuffer *fb, |
| 3280 | struct drm_pending_vblank_event *event, |
| 3281 | uint32_t flags) |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3282 | { |
| 3283 | struct drm_plane *plane = crtc->primary; |
| 3284 | struct drm_plane_state *plane_state; |
| 3285 | struct drm_crtc_state *crtc_state; |
| 3286 | int ret = 0; |
| 3287 | |
| 3288 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 3289 | if (IS_ERR(crtc_state)) |
| 3290 | return PTR_ERR(crtc_state); |
| 3291 | |
| 3292 | crtc_state->event = event; |
Andrey Grodzovsky | 6cbe5c4 | 2017-02-02 16:56:29 -0500 | [diff] [blame] | 3293 | crtc_state->pageflip_flags = flags; |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3294 | |
| 3295 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 3296 | if (IS_ERR(plane_state)) |
| 3297 | return PTR_ERR(plane_state); |
| 3298 | |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3299 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); |
| 3300 | if (ret != 0) |
| 3301 | return ret; |
| 3302 | drm_atomic_set_fb_for_plane(plane_state, fb); |
| 3303 | |
| 3304 | /* Make sure we don't accidentally do a full modeset. */ |
| 3305 | state->allow_modeset = false; |
| 3306 | if (!crtc_state->active) { |
Russell King | 6ac7c54 | 2017-02-13 12:27:03 +0000 | [diff] [blame] | 3307 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] disabled, rejecting legacy flip\n", |
| 3308 | crtc->base.id, crtc->name); |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3309 | return -EINVAL; |
| 3310 | } |
| 3311 | |
| 3312 | return ret; |
| 3313 | } |
| 3314 | |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 3315 | /** |
| 3316 | * drm_atomic_helper_page_flip - execute a legacy page flip |
| 3317 | * @crtc: DRM crtc |
| 3318 | * @fb: DRM framebuffer |
| 3319 | * @event: optional DRM event to signal upon completion |
| 3320 | * @flags: flip flags for non-vblank sync'ed updates |
Daniel Vetter | 41292b1f | 2017-03-22 22:50:50 +0100 | [diff] [blame] | 3321 | * @ctx: lock acquisition context |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 3322 | * |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3323 | * Provides a default &drm_crtc_funcs.page_flip implementation |
| 3324 | * using the atomic driver interface. |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 3325 | * |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 3326 | * Returns: |
| 3327 | * Returns 0 on success, negative errno numbers on failure. |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3328 | * |
| 3329 | * See also: |
| 3330 | * drm_atomic_helper_page_flip_target() |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 3331 | */ |
| 3332 | int drm_atomic_helper_page_flip(struct drm_crtc *crtc, |
| 3333 | struct drm_framebuffer *fb, |
| 3334 | struct drm_pending_vblank_event *event, |
Daniel Vetter | 41292b1f | 2017-03-22 22:50:50 +0100 | [diff] [blame] | 3335 | uint32_t flags, |
| 3336 | struct drm_modeset_acquire_ctx *ctx) |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 3337 | { |
| 3338 | struct drm_plane *plane = crtc->primary; |
| 3339 | struct drm_atomic_state *state; |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 3340 | int ret = 0; |
| 3341 | |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 3342 | state = drm_atomic_state_alloc(plane->dev); |
| 3343 | if (!state) |
| 3344 | return -ENOMEM; |
| 3345 | |
Daniel Vetter | 043e7fb | 2017-03-22 22:50:51 +0100 | [diff] [blame] | 3346 | state->acquire_ctx = ctx; |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3347 | |
Andrey Grodzovsky | 6cbe5c4 | 2017-02-02 16:56:29 -0500 | [diff] [blame] | 3348 | ret = page_flip_common(state, crtc, fb, event, flags); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 3349 | if (ret != 0) |
| 3350 | goto fail; |
Daniel Vetter | 4cba685 | 2015-12-08 09:49:20 +0100 | [diff] [blame] | 3351 | |
Maarten Lankhorst | b837ba0 | 2016-04-26 16:11:35 +0200 | [diff] [blame] | 3352 | ret = drm_atomic_nonblocking_commit(state); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 3353 | fail: |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 3354 | drm_atomic_state_put(state); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 3355 | return ret; |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 3356 | } |
| 3357 | EXPORT_SYMBOL(drm_atomic_helper_page_flip); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3358 | |
| 3359 | /** |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3360 | * drm_atomic_helper_page_flip_target - do page flip on target vblank period. |
| 3361 | * @crtc: DRM crtc |
| 3362 | * @fb: DRM framebuffer |
| 3363 | * @event: optional DRM event to signal upon completion |
| 3364 | * @flags: flip flags for non-vblank sync'ed updates |
| 3365 | * @target: specifying the target vblank period when the flip to take effect |
Daniel Vetter | 41292b1f | 2017-03-22 22:50:50 +0100 | [diff] [blame] | 3366 | * @ctx: lock acquisition context |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3367 | * |
| 3368 | * Provides a default &drm_crtc_funcs.page_flip_target implementation. |
| 3369 | * Similar to drm_atomic_helper_page_flip() with extra parameter to specify |
| 3370 | * target vblank period to flip. |
| 3371 | * |
| 3372 | * Returns: |
| 3373 | * Returns 0 on success, negative errno numbers on failure. |
| 3374 | */ |
Daniel Vetter | 8c3a818 | 2017-06-27 16:59:36 +0200 | [diff] [blame] | 3375 | int drm_atomic_helper_page_flip_target(struct drm_crtc *crtc, |
| 3376 | struct drm_framebuffer *fb, |
| 3377 | struct drm_pending_vblank_event *event, |
| 3378 | uint32_t flags, |
| 3379 | uint32_t target, |
| 3380 | struct drm_modeset_acquire_ctx *ctx) |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3381 | { |
| 3382 | struct drm_plane *plane = crtc->primary; |
| 3383 | struct drm_atomic_state *state; |
| 3384 | struct drm_crtc_state *crtc_state; |
| 3385 | int ret = 0; |
| 3386 | |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3387 | state = drm_atomic_state_alloc(plane->dev); |
| 3388 | if (!state) |
| 3389 | return -ENOMEM; |
| 3390 | |
Daniel Vetter | 043e7fb | 2017-03-22 22:50:51 +0100 | [diff] [blame] | 3391 | state->acquire_ctx = ctx; |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3392 | |
Andrey Grodzovsky | 6cbe5c4 | 2017-02-02 16:56:29 -0500 | [diff] [blame] | 3393 | ret = page_flip_common(state, crtc, fb, event, flags); |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3394 | if (ret != 0) |
| 3395 | goto fail; |
| 3396 | |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 3397 | crtc_state = drm_atomic_get_new_crtc_state(state, crtc); |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3398 | if (WARN_ON(!crtc_state)) { |
| 3399 | ret = -EINVAL; |
| 3400 | goto fail; |
| 3401 | } |
| 3402 | crtc_state->target_vblank = target; |
| 3403 | |
| 3404 | ret = drm_atomic_nonblocking_commit(state); |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3405 | fail: |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3406 | drm_atomic_state_put(state); |
| 3407 | return ret; |
Andrey Grodzovsky | f869a6e | 2017-01-06 15:39:40 -0500 | [diff] [blame] | 3408 | } |
| 3409 | EXPORT_SYMBOL(drm_atomic_helper_page_flip_target); |