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