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