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