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