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> |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 33 | #include <linux/fence.h> |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 34 | |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 35 | /** |
| 36 | * DOC: overview |
| 37 | * |
| 38 | * This helper library provides implementations of check and commit functions on |
| 39 | * top of the CRTC modeset helper callbacks and the plane helper callbacks. It |
| 40 | * also provides convenience implementations for the atomic state handling |
| 41 | * callbacks for drivers which don't need to subclass the drm core structures to |
| 42 | * add their own additional internal state. |
| 43 | * |
| 44 | * This library also provides default implementations for the check callback in |
Daniel Vetter | 26196f7 | 2015-08-25 16:26:03 +0200 | [diff] [blame] | 45 | * drm_atomic_helper_check() and for the commit callback with |
| 46 | * drm_atomic_helper_commit(). But the individual stages and callbacks are |
| 47 | * 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] | 48 | * together with a driver private modeset implementation. |
| 49 | * |
| 50 | * This library also provides implementations for all the legacy driver |
Daniel Vetter | 26196f7 | 2015-08-25 16:26:03 +0200 | [diff] [blame] | 51 | * interfaces on top of the atomic interface. See drm_atomic_helper_set_config(), |
| 52 | * drm_atomic_helper_disable_plane(), drm_atomic_helper_disable_plane() and the |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 53 | * various functions to implement set_property callbacks. New drivers must not |
| 54 | * implement these functions themselves but must use the provided helpers. |
| 55 | */ |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 56 | static void |
| 57 | drm_atomic_helper_plane_changed(struct drm_atomic_state *state, |
| 58 | struct drm_plane_state *plane_state, |
| 59 | struct drm_plane *plane) |
| 60 | { |
| 61 | struct drm_crtc_state *crtc_state; |
| 62 | |
| 63 | if (plane->state->crtc) { |
Rob Clark | 4b08eae | 2014-12-08 10:45:43 -0500 | [diff] [blame] | 64 | crtc_state = state->crtc_states[drm_crtc_index(plane->state->crtc)]; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 65 | |
| 66 | if (WARN_ON(!crtc_state)) |
| 67 | return; |
| 68 | |
| 69 | crtc_state->planes_changed = true; |
| 70 | } |
| 71 | |
| 72 | if (plane_state->crtc) { |
| 73 | crtc_state = |
| 74 | state->crtc_states[drm_crtc_index(plane_state->crtc)]; |
| 75 | |
| 76 | if (WARN_ON(!crtc_state)) |
| 77 | return; |
| 78 | |
| 79 | crtc_state->planes_changed = true; |
| 80 | } |
| 81 | } |
| 82 | |
Daniel Vetter | 97ac320 | 2015-12-03 10:49:14 +0100 | [diff] [blame] | 83 | static bool |
| 84 | check_pending_encoder_assignment(struct drm_atomic_state *state, |
| 85 | struct drm_encoder *new_encoder, |
| 86 | struct drm_connector *new_connector) |
| 87 | { |
| 88 | struct drm_connector *connector; |
| 89 | struct drm_connector_state *conn_state; |
| 90 | int i; |
| 91 | |
| 92 | for_each_connector_in_state(state, connector, conn_state, i) { |
| 93 | if (conn_state->best_encoder != new_encoder) |
| 94 | continue; |
| 95 | |
| 96 | /* encoder already assigned and we're trying to re-steal it! */ |
| 97 | if (connector->state->best_encoder != conn_state->best_encoder) |
| 98 | return false; |
| 99 | } |
| 100 | |
| 101 | return true; |
| 102 | } |
| 103 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 104 | static struct drm_crtc * |
| 105 | get_current_crtc_for_encoder(struct drm_device *dev, |
| 106 | struct drm_encoder *encoder) |
| 107 | { |
| 108 | struct drm_mode_config *config = &dev->mode_config; |
| 109 | struct drm_connector *connector; |
| 110 | |
| 111 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
| 112 | |
Daniel Vetter | 9a9f5ce | 2015-07-09 23:44:34 +0200 | [diff] [blame] | 113 | drm_for_each_connector(connector, dev) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 114 | if (connector->state->best_encoder != encoder) |
| 115 | continue; |
| 116 | |
| 117 | return connector->state->crtc; |
| 118 | } |
| 119 | |
| 120 | return NULL; |
| 121 | } |
| 122 | |
| 123 | static int |
| 124 | steal_encoder(struct drm_atomic_state *state, |
| 125 | struct drm_encoder *encoder, |
| 126 | struct drm_crtc *encoder_crtc) |
| 127 | { |
| 128 | struct drm_mode_config *config = &state->dev->mode_config; |
| 129 | struct drm_crtc_state *crtc_state; |
| 130 | struct drm_connector *connector; |
| 131 | struct drm_connector_state *connector_state; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 132 | int ret; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 133 | |
| 134 | /* |
| 135 | * We can only steal an encoder coming from a connector, which means we |
| 136 | * must already hold the connection_mutex. |
| 137 | */ |
| 138 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
| 139 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 140 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d], stealing it\n", |
| 141 | encoder->base.id, encoder->name, |
| 142 | encoder_crtc->base.id); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 143 | |
| 144 | crtc_state = drm_atomic_get_crtc_state(state, encoder_crtc); |
| 145 | if (IS_ERR(crtc_state)) |
| 146 | return PTR_ERR(crtc_state); |
| 147 | |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 148 | crtc_state->connectors_changed = true; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 149 | |
| 150 | list_for_each_entry(connector, &config->connector_list, head) { |
| 151 | if (connector->state->best_encoder != encoder) |
| 152 | continue; |
| 153 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 154 | DRM_DEBUG_ATOMIC("Stealing encoder from [CONNECTOR:%d:%s]\n", |
| 155 | connector->base.id, |
| 156 | connector->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 157 | |
| 158 | connector_state = drm_atomic_get_connector_state(state, |
| 159 | connector); |
| 160 | if (IS_ERR(connector_state)) |
| 161 | return PTR_ERR(connector_state); |
| 162 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 163 | ret = drm_atomic_set_crtc_for_connector(connector_state, NULL); |
| 164 | if (ret) |
| 165 | return ret; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 166 | connector_state->best_encoder = NULL; |
| 167 | } |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
| 172 | static int |
| 173 | update_connector_routing(struct drm_atomic_state *state, int conn_idx) |
| 174 | { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 175 | const struct drm_connector_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 176 | struct drm_encoder *new_encoder; |
| 177 | struct drm_crtc *encoder_crtc; |
| 178 | struct drm_connector *connector; |
| 179 | struct drm_connector_state *connector_state; |
| 180 | struct drm_crtc_state *crtc_state; |
| 181 | int idx, ret; |
| 182 | |
| 183 | connector = state->connectors[conn_idx]; |
| 184 | connector_state = state->connector_states[conn_idx]; |
| 185 | |
| 186 | if (!connector) |
| 187 | return 0; |
| 188 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 189 | DRM_DEBUG_ATOMIC("Updating routing for [CONNECTOR:%d:%s]\n", |
| 190 | connector->base.id, |
| 191 | connector->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 192 | |
| 193 | if (connector->state->crtc != connector_state->crtc) { |
| 194 | if (connector->state->crtc) { |
| 195 | idx = drm_crtc_index(connector->state->crtc); |
| 196 | |
| 197 | crtc_state = state->crtc_states[idx]; |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 198 | crtc_state->connectors_changed = true; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | if (connector_state->crtc) { |
| 202 | idx = drm_crtc_index(connector_state->crtc); |
| 203 | |
| 204 | crtc_state = state->crtc_states[idx]; |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 205 | crtc_state->connectors_changed = true; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 206 | } |
| 207 | } |
| 208 | |
| 209 | if (!connector_state->crtc) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 210 | DRM_DEBUG_ATOMIC("Disabling [CONNECTOR:%d:%s]\n", |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 211 | connector->base.id, |
| 212 | connector->name); |
| 213 | |
| 214 | connector_state->best_encoder = NULL; |
| 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | funcs = connector->helper_private; |
Daniel Vetter | 3b8a684 | 2015-08-03 17:24:08 +0200 | [diff] [blame] | 220 | |
| 221 | if (funcs->atomic_best_encoder) |
| 222 | new_encoder = funcs->atomic_best_encoder(connector, |
| 223 | connector_state); |
| 224 | else |
| 225 | new_encoder = funcs->best_encoder(connector); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 226 | |
| 227 | if (!new_encoder) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 228 | DRM_DEBUG_ATOMIC("No suitable encoder found for [CONNECTOR:%d:%s]\n", |
| 229 | connector->base.id, |
| 230 | connector->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 231 | return -EINVAL; |
| 232 | } |
| 233 | |
Daniel Vetter | 5481c8f | 2015-11-18 18:46:48 +0100 | [diff] [blame] | 234 | if (!drm_encoder_crtc_ok(new_encoder, connector_state->crtc)) { |
| 235 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] incompatible with [CRTC:%d]\n", |
| 236 | new_encoder->base.id, |
| 237 | new_encoder->name, |
| 238 | connector_state->crtc->base.id); |
| 239 | return -EINVAL; |
| 240 | } |
| 241 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 242 | if (new_encoder == connector_state->best_encoder) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 243 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] keeps [ENCODER:%d:%s], now on [CRTC:%d]\n", |
| 244 | connector->base.id, |
| 245 | connector->name, |
| 246 | new_encoder->base.id, |
| 247 | new_encoder->name, |
| 248 | connector_state->crtc->base.id); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 249 | |
| 250 | return 0; |
| 251 | } |
| 252 | |
Daniel Vetter | 97ac320 | 2015-12-03 10:49:14 +0100 | [diff] [blame] | 253 | if (!check_pending_encoder_assignment(state, new_encoder, connector)) { |
| 254 | DRM_DEBUG_ATOMIC("Encoder for [CONNECTOR:%d:%s] already assigned\n", |
| 255 | connector->base.id, |
| 256 | connector->name); |
| 257 | return -EINVAL; |
| 258 | } |
| 259 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 260 | encoder_crtc = get_current_crtc_for_encoder(state->dev, |
| 261 | new_encoder); |
| 262 | |
| 263 | if (encoder_crtc) { |
| 264 | ret = steal_encoder(state, new_encoder, encoder_crtc); |
| 265 | if (ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 266 | DRM_DEBUG_ATOMIC("Encoder stealing failed for [CONNECTOR:%d:%s]\n", |
| 267 | connector->base.id, |
| 268 | connector->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 269 | return ret; |
| 270 | } |
| 271 | } |
| 272 | |
Daniel Vetter | 6ea76f3c | 2015-08-03 17:24:11 +0200 | [diff] [blame] | 273 | if (WARN_ON(!connector_state->crtc)) |
| 274 | return -EINVAL; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 275 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 276 | connector_state->best_encoder = new_encoder; |
| 277 | idx = drm_crtc_index(connector_state->crtc); |
| 278 | |
| 279 | crtc_state = state->crtc_states[idx]; |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 280 | crtc_state->connectors_changed = true; |
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("[CONNECTOR:%d:%s] using [ENCODER:%d:%s] on [CRTC:%d]\n", |
| 283 | connector->base.id, |
| 284 | connector->name, |
| 285 | new_encoder->base.id, |
| 286 | new_encoder->name, |
| 287 | connector_state->crtc->base.id); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 288 | |
| 289 | return 0; |
| 290 | } |
| 291 | |
| 292 | static int |
| 293 | mode_fixup(struct drm_atomic_state *state) |
| 294 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 295 | struct drm_crtc *crtc; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 296 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 297 | struct drm_connector *connector; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 298 | struct drm_connector_state *conn_state; |
| 299 | int i; |
| 300 | bool ret; |
| 301 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 302 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 303 | if (!crtc_state->mode_changed && |
| 304 | !crtc_state->connectors_changed) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 305 | continue; |
| 306 | |
| 307 | drm_mode_copy(&crtc_state->adjusted_mode, &crtc_state->mode); |
| 308 | } |
| 309 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 310 | for_each_connector_in_state(state, connector, conn_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 311 | const struct drm_encoder_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 312 | struct drm_encoder *encoder; |
| 313 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 314 | WARN_ON(!!conn_state->best_encoder != !!conn_state->crtc); |
| 315 | |
| 316 | if (!conn_state->crtc || !conn_state->best_encoder) |
| 317 | continue; |
| 318 | |
| 319 | crtc_state = |
| 320 | state->crtc_states[drm_crtc_index(conn_state->crtc)]; |
| 321 | |
| 322 | /* |
| 323 | * Each encoder has at most one connector (since we always steal |
| 324 | * it away), so we won't call ->mode_fixup twice. |
| 325 | */ |
| 326 | encoder = conn_state->best_encoder; |
| 327 | funcs = encoder->helper_private; |
Ander Conselvan de Oliveira | 840bfe9 | 2015-04-21 17:13:18 +0300 | [diff] [blame] | 328 | if (!funcs) |
| 329 | continue; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 330 | |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 331 | ret = drm_bridge_mode_fixup(encoder->bridge, &crtc_state->mode, |
| 332 | &crtc_state->adjusted_mode); |
| 333 | if (!ret) { |
| 334 | DRM_DEBUG_ATOMIC("Bridge fixup failed\n"); |
| 335 | return -EINVAL; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 336 | } |
| 337 | |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 338 | if (funcs->atomic_check) { |
| 339 | ret = funcs->atomic_check(encoder, crtc_state, |
| 340 | conn_state); |
| 341 | if (ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 342 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] check failed\n", |
| 343 | encoder->base.id, encoder->name); |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 344 | return ret; |
| 345 | } |
Inki Dae | 8452491 | 2015-08-11 21:23:49 +0900 | [diff] [blame] | 346 | } else if (funcs->mode_fixup) { |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 347 | ret = funcs->mode_fixup(encoder, &crtc_state->mode, |
| 348 | &crtc_state->adjusted_mode); |
| 349 | if (!ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 350 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] fixup failed\n", |
| 351 | encoder->base.id, encoder->name); |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 352 | return -EINVAL; |
| 353 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 357 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 358 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 359 | |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 360 | if (!crtc_state->mode_changed && |
| 361 | !crtc_state->connectors_changed) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 362 | continue; |
| 363 | |
| 364 | funcs = crtc->helper_private; |
Ander Conselvan de Oliveira | 840bfe9 | 2015-04-21 17:13:18 +0300 | [diff] [blame] | 365 | if (!funcs->mode_fixup) |
| 366 | continue; |
| 367 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 368 | ret = funcs->mode_fixup(crtc, &crtc_state->mode, |
| 369 | &crtc_state->adjusted_mode); |
| 370 | if (!ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 371 | DRM_DEBUG_ATOMIC("[CRTC:%d] fixup failed\n", |
| 372 | crtc->base.id); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 373 | return -EINVAL; |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | return 0; |
| 378 | } |
| 379 | |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 380 | /** |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 381 | * drm_atomic_helper_check_modeset - validate state object for modeset changes |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 382 | * @dev: DRM device |
| 383 | * @state: the driver state object |
| 384 | * |
| 385 | * Check the state object to see if the requested state is physically possible. |
| 386 | * This does all the crtc and connector related computations for an atomic |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 387 | * update and adds any additional connectors needed for full modesets and calls |
| 388 | * down into ->mode_fixup functions of the driver backend. |
| 389 | * |
| 390 | * crtc_state->mode_changed is set when the input mode is changed. |
| 391 | * crtc_state->connectors_changed is set when a connector is added or |
| 392 | * removed from the crtc. |
| 393 | * crtc_state->active_changed is set when crtc_state->active changes, |
| 394 | * which is used for dpms. |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 395 | * |
| 396 | * IMPORTANT: |
| 397 | * |
| 398 | * Drivers which update ->mode_changed (e.g. in their ->atomic_check hooks if a |
| 399 | * plane update can't be done without a full modeset) _must_ call this function |
| 400 | * afterwards after that change. It is permitted to call this function multiple |
| 401 | * times for the same update, e.g. when the ->atomic_check functions depend upon |
| 402 | * the adjusted dotclock for fifo space allocation and watermark computation. |
| 403 | * |
| 404 | * RETURNS |
| 405 | * Zero for success or -errno |
| 406 | */ |
| 407 | int |
Rob Clark | 934ce1c | 2014-11-19 16:41:33 -0500 | [diff] [blame] | 408 | drm_atomic_helper_check_modeset(struct drm_device *dev, |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 409 | struct drm_atomic_state *state) |
| 410 | { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 411 | struct drm_crtc *crtc; |
| 412 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 413 | struct drm_connector *connector; |
| 414 | struct drm_connector_state *connector_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 415 | int i, ret; |
| 416 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 417 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 418 | if (!drm_mode_equal(&crtc->state->mode, &crtc_state->mode)) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 419 | DRM_DEBUG_ATOMIC("[CRTC:%d] mode changed\n", |
| 420 | crtc->base.id); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 421 | crtc_state->mode_changed = true; |
| 422 | } |
| 423 | |
| 424 | if (crtc->state->enable != crtc_state->enable) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 425 | DRM_DEBUG_ATOMIC("[CRTC:%d] enable changed\n", |
| 426 | crtc->base.id); |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 427 | |
| 428 | /* |
| 429 | * For clarity this assignment is done here, but |
| 430 | * enable == 0 is only true when there are no |
| 431 | * connectors and a NULL mode. |
| 432 | * |
| 433 | * The other way around is true as well. enable != 0 |
| 434 | * iff connectors are attached and a mode is set. |
| 435 | */ |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 436 | crtc_state->mode_changed = true; |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 437 | crtc_state->connectors_changed = true; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 438 | } |
| 439 | } |
| 440 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 441 | for_each_connector_in_state(state, connector, connector_state, i) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 442 | /* |
| 443 | * This only sets crtc->mode_changed for routing changes, |
| 444 | * drivers must set crtc->mode_changed themselves when connector |
| 445 | * properties need to be updated. |
| 446 | */ |
| 447 | ret = update_connector_routing(state, i); |
| 448 | if (ret) |
| 449 | return ret; |
| 450 | } |
| 451 | |
| 452 | /* |
| 453 | * After all the routing has been prepared we need to add in any |
| 454 | * connector which is itself unchanged, but who's crtc changes it's |
| 455 | * configuration. This must be done before calling mode_fixup in case a |
| 456 | * crtc only changed its mode but has the same set of connectors. |
| 457 | */ |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 458 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 459 | int num_connectors; |
| 460 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 461 | /* |
| 462 | * We must set ->active_changed after walking connectors for |
| 463 | * otherwise an update that only changes active would result in |
| 464 | * a full modeset because update_connector_routing force that. |
| 465 | */ |
| 466 | if (crtc->state->active != crtc_state->active) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 467 | DRM_DEBUG_ATOMIC("[CRTC:%d] active changed\n", |
| 468 | crtc->base.id); |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 469 | crtc_state->active_changed = true; |
| 470 | } |
| 471 | |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 472 | if (!drm_atomic_crtc_needs_modeset(crtc_state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 473 | continue; |
| 474 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 475 | DRM_DEBUG_ATOMIC("[CRTC:%d] needs all connectors, enable: %c, active: %c\n", |
| 476 | crtc->base.id, |
| 477 | crtc_state->enable ? 'y' : 'n', |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 478 | crtc_state->active ? 'y' : 'n'); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 479 | |
| 480 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 481 | if (ret != 0) |
| 482 | return ret; |
| 483 | |
Maarten Lankhorst | 57744aa | 2015-05-19 16:41:03 +0200 | [diff] [blame] | 484 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 485 | if (ret != 0) |
| 486 | return ret; |
| 487 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 488 | num_connectors = drm_atomic_connectors_for_crtc(state, |
| 489 | crtc); |
| 490 | |
| 491 | if (crtc_state->enable != !!num_connectors) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 492 | DRM_DEBUG_ATOMIC("[CRTC:%d] enabled/connectors mismatch\n", |
| 493 | crtc->base.id); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 494 | |
| 495 | return -EINVAL; |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | return mode_fixup(state); |
| 500 | } |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 501 | EXPORT_SYMBOL(drm_atomic_helper_check_modeset); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 502 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 503 | /** |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 504 | * drm_atomic_helper_check_planes - validate state object for planes changes |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 505 | * @dev: DRM device |
| 506 | * @state: the driver state object |
| 507 | * |
| 508 | * 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] | 509 | * This does all the plane update related checks using by calling into the |
| 510 | * ->atomic_check hooks provided by the driver. |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 511 | * |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 512 | * It also sets crtc_state->planes_changed to indicate that a crtc has |
| 513 | * updated planes. |
| 514 | * |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 515 | * RETURNS |
| 516 | * Zero for success or -errno |
| 517 | */ |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 518 | int |
| 519 | drm_atomic_helper_check_planes(struct drm_device *dev, |
| 520 | struct drm_atomic_state *state) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 521 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 522 | struct drm_crtc *crtc; |
| 523 | struct drm_crtc_state *crtc_state; |
| 524 | struct drm_plane *plane; |
| 525 | struct drm_plane_state *plane_state; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 526 | int i, ret = 0; |
| 527 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 528 | for_each_plane_in_state(state, plane, plane_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 529 | const struct drm_plane_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 530 | |
| 531 | funcs = plane->helper_private; |
| 532 | |
| 533 | drm_atomic_helper_plane_changed(state, plane_state, plane); |
| 534 | |
| 535 | if (!funcs || !funcs->atomic_check) |
| 536 | continue; |
| 537 | |
| 538 | ret = funcs->atomic_check(plane, plane_state); |
| 539 | if (ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 540 | DRM_DEBUG_ATOMIC("[PLANE:%d] atomic driver check failed\n", |
| 541 | plane->base.id); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 542 | return ret; |
| 543 | } |
| 544 | } |
| 545 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 546 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 547 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 548 | |
| 549 | funcs = crtc->helper_private; |
| 550 | |
| 551 | if (!funcs || !funcs->atomic_check) |
| 552 | continue; |
| 553 | |
| 554 | ret = funcs->atomic_check(crtc, state->crtc_states[i]); |
| 555 | if (ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 556 | DRM_DEBUG_ATOMIC("[CRTC:%d] atomic driver check failed\n", |
| 557 | crtc->base.id); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 558 | return ret; |
| 559 | } |
| 560 | } |
| 561 | |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 562 | return ret; |
| 563 | } |
| 564 | EXPORT_SYMBOL(drm_atomic_helper_check_planes); |
| 565 | |
| 566 | /** |
| 567 | * drm_atomic_helper_check - validate state object |
| 568 | * @dev: DRM device |
| 569 | * @state: the driver state object |
| 570 | * |
| 571 | * Check the state object to see if the requested state is physically possible. |
| 572 | * Only crtcs and planes have check callbacks, so for any additional (global) |
| 573 | * checking that a driver needs it can simply wrap that around this function. |
| 574 | * Drivers without such needs can directly use this as their ->atomic_check() |
| 575 | * callback. |
| 576 | * |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 577 | * This just wraps the two parts of the state checking for planes and modeset |
| 578 | * state in the default order: First it calls drm_atomic_helper_check_modeset() |
| 579 | * and then drm_atomic_helper_check_planes(). The assumption is that the |
| 580 | * ->atomic_check functions depend upon an updated adjusted_mode.clock to |
| 581 | * e.g. properly compute watermarks. |
| 582 | * |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 583 | * RETURNS |
| 584 | * Zero for success or -errno |
| 585 | */ |
| 586 | int drm_atomic_helper_check(struct drm_device *dev, |
| 587 | struct drm_atomic_state *state) |
| 588 | { |
| 589 | int ret; |
| 590 | |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 591 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 592 | if (ret) |
| 593 | return ret; |
| 594 | |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 595 | ret = drm_atomic_helper_check_planes(dev, state); |
Rob Clark | 934ce1c | 2014-11-19 16:41:33 -0500 | [diff] [blame] | 596 | if (ret) |
| 597 | return ret; |
| 598 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 599 | return ret; |
| 600 | } |
| 601 | EXPORT_SYMBOL(drm_atomic_helper_check); |
| 602 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 603 | static void |
| 604 | disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state) |
| 605 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 606 | struct drm_connector *connector; |
| 607 | struct drm_connector_state *old_conn_state; |
| 608 | struct drm_crtc *crtc; |
| 609 | struct drm_crtc_state *old_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 610 | int i; |
| 611 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 612 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 613 | const struct drm_encoder_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 614 | struct drm_encoder *encoder; |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 615 | struct drm_crtc_state *old_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 616 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 617 | /* Shut down everything that's in the changeset and currently |
| 618 | * still on. So need to check the old, saved state. */ |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 619 | if (!old_conn_state->crtc) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 620 | continue; |
| 621 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 622 | old_crtc_state = old_state->crtc_states[drm_crtc_index(old_conn_state->crtc)]; |
| 623 | |
Daniel Vetter | 4218a32 | 2015-03-26 22:18:40 +0100 | [diff] [blame] | 624 | if (!old_crtc_state->active || |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 625 | !drm_atomic_crtc_needs_modeset(old_conn_state->crtc->state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 626 | continue; |
| 627 | |
Rob Clark | 46df9ad | 2014-11-20 15:40:36 -0500 | [diff] [blame] | 628 | encoder = old_conn_state->best_encoder; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 629 | |
Rob Clark | 46df9ad | 2014-11-20 15:40:36 -0500 | [diff] [blame] | 630 | /* We shouldn't get this far if we didn't previously have |
| 631 | * an encoder.. but WARN_ON() rather than explode. |
| 632 | */ |
| 633 | if (WARN_ON(!encoder)) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 634 | continue; |
| 635 | |
| 636 | funcs = encoder->helper_private; |
| 637 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 638 | DRM_DEBUG_ATOMIC("disabling [ENCODER:%d:%s]\n", |
| 639 | encoder->base.id, encoder->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 640 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 641 | /* |
| 642 | * Each encoder has at most one connector (since we always steal |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 643 | * it away), so we won't call disable hooks twice. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 644 | */ |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 645 | drm_bridge_disable(encoder->bridge); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 646 | |
| 647 | /* Right function depends upon target state. */ |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 648 | if (connector->state->crtc && funcs->prepare) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 649 | funcs->prepare(encoder); |
| 650 | else if (funcs->disable) |
| 651 | funcs->disable(encoder); |
| 652 | else |
| 653 | funcs->dpms(encoder, DRM_MODE_DPMS_OFF); |
| 654 | |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 655 | drm_bridge_post_disable(encoder->bridge); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 656 | } |
| 657 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 658 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 659 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 660 | |
| 661 | /* Shut down everything that needs a full modeset. */ |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 662 | if (!drm_atomic_crtc_needs_modeset(crtc->state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 663 | continue; |
| 664 | |
| 665 | if (!old_crtc_state->active) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 666 | continue; |
| 667 | |
| 668 | funcs = crtc->helper_private; |
| 669 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 670 | DRM_DEBUG_ATOMIC("disabling [CRTC:%d]\n", |
| 671 | crtc->base.id); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 672 | |
| 673 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 674 | /* Right function depends upon target state. */ |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 675 | if (crtc->state->enable && funcs->prepare) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 676 | funcs->prepare(crtc); |
| 677 | else if (funcs->disable) |
| 678 | funcs->disable(crtc); |
| 679 | else |
| 680 | funcs->dpms(crtc, DRM_MODE_DPMS_OFF); |
| 681 | } |
| 682 | } |
| 683 | |
Daniel Vetter | 4c18d30 | 2015-05-12 15:27:37 +0200 | [diff] [blame] | 684 | /** |
| 685 | * drm_atomic_helper_update_legacy_modeset_state - update legacy modeset state |
| 686 | * @dev: DRM device |
| 687 | * @old_state: atomic state object with old state structures |
| 688 | * |
| 689 | * This function updates all the various legacy modeset state pointers in |
| 690 | * connectors, encoders and crtcs. It also updates the timestamping constants |
| 691 | * used for precise vblank timestamps by calling |
| 692 | * drm_calc_timestamping_constants(). |
| 693 | * |
| 694 | * Drivers can use this for building their own atomic commit if they don't have |
| 695 | * a pure helper-based modeset implementation. |
| 696 | */ |
| 697 | void |
| 698 | drm_atomic_helper_update_legacy_modeset_state(struct drm_device *dev, |
| 699 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 700 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 701 | struct drm_connector *connector; |
| 702 | struct drm_connector_state *old_conn_state; |
| 703 | struct drm_crtc *crtc; |
| 704 | struct drm_crtc_state *old_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 705 | int i; |
| 706 | |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 707 | /* clear out existing links and update dpms */ |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 708 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 709 | if (connector->encoder) { |
| 710 | WARN_ON(!connector->encoder->crtc); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 711 | |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 712 | connector->encoder->crtc = NULL; |
| 713 | connector->encoder = NULL; |
| 714 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 715 | |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 716 | crtc = connector->state->crtc; |
| 717 | if ((!crtc && old_conn_state->crtc) || |
| 718 | (crtc && drm_atomic_crtc_needs_modeset(crtc->state))) { |
| 719 | struct drm_property *dpms_prop = |
| 720 | dev->mode_config.dpms_property; |
| 721 | int mode = DRM_MODE_DPMS_OFF; |
| 722 | |
| 723 | if (crtc && crtc->state->active) |
| 724 | mode = DRM_MODE_DPMS_ON; |
| 725 | |
| 726 | connector->dpms = mode; |
| 727 | drm_object_property_set_value(&connector->base, |
| 728 | dpms_prop, mode); |
| 729 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | /* set new links */ |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 733 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
| 734 | if (!connector->state->crtc) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 735 | continue; |
| 736 | |
| 737 | if (WARN_ON(!connector->state->best_encoder)) |
| 738 | continue; |
| 739 | |
| 740 | connector->encoder = connector->state->best_encoder; |
| 741 | connector->encoder->crtc = connector->state->crtc; |
| 742 | } |
| 743 | |
| 744 | /* set legacy state in the crtc structure */ |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 745 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Maarten Lankhorst | 2660801 | 2015-07-16 15:51:01 +0200 | [diff] [blame] | 746 | struct drm_plane *primary = crtc->primary; |
| 747 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 748 | crtc->mode = crtc->state->mode; |
| 749 | crtc->enabled = crtc->state->enable; |
Maarten Lankhorst | 2660801 | 2015-07-16 15:51:01 +0200 | [diff] [blame] | 750 | |
| 751 | if (drm_atomic_get_existing_plane_state(old_state, primary) && |
| 752 | primary->state->crtc == crtc) { |
| 753 | crtc->x = primary->state->src_x >> 16; |
| 754 | crtc->y = primary->state->src_y >> 16; |
| 755 | } |
Daniel Vetter | 3d51d2d | 2015-05-12 15:21:06 +0200 | [diff] [blame] | 756 | |
| 757 | if (crtc->state->enable) |
| 758 | drm_calc_timestamping_constants(crtc, |
| 759 | &crtc->state->adjusted_mode); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 760 | } |
| 761 | } |
Daniel Vetter | 4c18d30 | 2015-05-12 15:27:37 +0200 | [diff] [blame] | 762 | EXPORT_SYMBOL(drm_atomic_helper_update_legacy_modeset_state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 763 | |
| 764 | static void |
| 765 | crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state) |
| 766 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 767 | struct drm_crtc *crtc; |
| 768 | struct drm_crtc_state *old_crtc_state; |
| 769 | struct drm_connector *connector; |
| 770 | struct drm_connector_state *old_conn_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 771 | int i; |
| 772 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 773 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 774 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 775 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 776 | if (!crtc->state->mode_changed) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 777 | continue; |
| 778 | |
| 779 | funcs = crtc->helper_private; |
| 780 | |
Daniel Vetter | c982bd9 | 2015-02-22 12:24:20 +0100 | [diff] [blame] | 781 | if (crtc->state->enable && funcs->mode_set_nofb) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 782 | DRM_DEBUG_ATOMIC("modeset on [CRTC:%d]\n", |
| 783 | crtc->base.id); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 784 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 785 | funcs->mode_set_nofb(crtc); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 786 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 787 | } |
| 788 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 789 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 790 | const struct drm_encoder_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 791 | struct drm_crtc_state *new_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 792 | struct drm_encoder *encoder; |
| 793 | struct drm_display_mode *mode, *adjusted_mode; |
| 794 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 795 | if (!connector->state->best_encoder) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 796 | continue; |
| 797 | |
| 798 | encoder = connector->state->best_encoder; |
| 799 | funcs = encoder->helper_private; |
| 800 | new_crtc_state = connector->state->crtc->state; |
| 801 | mode = &new_crtc_state->mode; |
| 802 | adjusted_mode = &new_crtc_state->adjusted_mode; |
| 803 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 804 | if (!new_crtc_state->mode_changed) |
| 805 | continue; |
| 806 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 807 | DRM_DEBUG_ATOMIC("modeset on [ENCODER:%d:%s]\n", |
| 808 | encoder->base.id, encoder->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 809 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 810 | /* |
| 811 | * Each encoder has at most one connector (since we always steal |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 812 | * it away), so we won't call mode_set hooks twice. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 813 | */ |
Daniel Vetter | c982bd9 | 2015-02-22 12:24:20 +0100 | [diff] [blame] | 814 | if (funcs->mode_set) |
| 815 | funcs->mode_set(encoder, mode, adjusted_mode); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 816 | |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 817 | drm_bridge_mode_set(encoder->bridge, mode, adjusted_mode); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | |
| 821 | /** |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 822 | * drm_atomic_helper_commit_modeset_disables - modeset commit to disable outputs |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 823 | * @dev: DRM device |
Laurent Pinchart | a072f80 | 2015-02-22 12:24:18 +0100 | [diff] [blame] | 824 | * @old_state: atomic state object with old state structures |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 825 | * |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 826 | * 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] | 827 | * prepares them (if required) with the new mode. |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 828 | * |
Laurent Pinchart | 60acc4e | 2015-05-27 15:05:42 +0300 | [diff] [blame] | 829 | * For compatibility with legacy crtc helpers this should be called before |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 830 | * drm_atomic_helper_commit_planes(), which is what the default commit function |
| 831 | * does. But drivers with different needs can group the modeset commits together |
| 832 | * and do the plane commits at the end. This is useful for drivers doing runtime |
| 833 | * 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] | 834 | */ |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 835 | void drm_atomic_helper_commit_modeset_disables(struct drm_device *dev, |
| 836 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 837 | { |
Laurent Pinchart | a072f80 | 2015-02-22 12:24:18 +0100 | [diff] [blame] | 838 | disable_outputs(dev, old_state); |
Daniel Vetter | 4c18d30 | 2015-05-12 15:27:37 +0200 | [diff] [blame] | 839 | |
| 840 | drm_atomic_helper_update_legacy_modeset_state(dev, old_state); |
| 841 | |
Laurent Pinchart | a072f80 | 2015-02-22 12:24:18 +0100 | [diff] [blame] | 842 | crtc_set_mode(dev, old_state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 843 | } |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 844 | EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_disables); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 845 | |
| 846 | /** |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 847 | * drm_atomic_helper_commit_modeset_enables - modeset commit to enable outputs |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 848 | * @dev: DRM device |
| 849 | * @old_state: atomic state object with old state structures |
| 850 | * |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 851 | * This function enables all the outputs with the new configuration which had to |
| 852 | * be turned off for the update. |
| 853 | * |
Laurent Pinchart | 60acc4e | 2015-05-27 15:05:42 +0300 | [diff] [blame] | 854 | * For compatibility with legacy crtc helpers this should be called after |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 855 | * drm_atomic_helper_commit_planes(), which is what the default commit function |
| 856 | * does. But drivers with different needs can group the modeset commits together |
| 857 | * and do the plane commits at the end. This is useful for drivers doing runtime |
| 858 | * 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] | 859 | */ |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 860 | void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, |
| 861 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 862 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 863 | struct drm_crtc *crtc; |
| 864 | struct drm_crtc_state *old_crtc_state; |
| 865 | struct drm_connector *connector; |
| 866 | struct drm_connector_state *old_conn_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 867 | int i; |
| 868 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 869 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 870 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 871 | |
| 872 | /* Need to filter out CRTCs where only planes change. */ |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 873 | if (!drm_atomic_crtc_needs_modeset(crtc->state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 874 | continue; |
| 875 | |
| 876 | if (!crtc->state->active) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 877 | continue; |
| 878 | |
| 879 | funcs = crtc->helper_private; |
| 880 | |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 881 | if (crtc->state->enable) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 882 | DRM_DEBUG_ATOMIC("enabling [CRTC:%d]\n", |
| 883 | crtc->base.id); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 884 | |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 885 | if (funcs->enable) |
| 886 | funcs->enable(crtc); |
| 887 | else |
| 888 | funcs->commit(crtc); |
| 889 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 890 | } |
| 891 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 892 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 893 | const struct drm_encoder_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 894 | struct drm_encoder *encoder; |
| 895 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 896 | if (!connector->state->best_encoder) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 897 | continue; |
| 898 | |
Daniel Vetter | 4218a32 | 2015-03-26 22:18:40 +0100 | [diff] [blame] | 899 | if (!connector->state->crtc->state->active || |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 900 | !drm_atomic_crtc_needs_modeset(connector->state->crtc->state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 901 | continue; |
| 902 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 903 | encoder = connector->state->best_encoder; |
| 904 | funcs = encoder->helper_private; |
| 905 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 906 | DRM_DEBUG_ATOMIC("enabling [ENCODER:%d:%s]\n", |
| 907 | encoder->base.id, encoder->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 908 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 909 | /* |
| 910 | * Each encoder has at most one connector (since we always steal |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 911 | * it away), so we won't call enable hooks twice. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 912 | */ |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 913 | drm_bridge_pre_enable(encoder->bridge); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 914 | |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 915 | if (funcs->enable) |
| 916 | funcs->enable(encoder); |
| 917 | else |
| 918 | funcs->commit(encoder); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 919 | |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 920 | drm_bridge_enable(encoder->bridge); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 921 | } |
| 922 | } |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 923 | EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_enables); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 924 | |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 925 | static void wait_for_fences(struct drm_device *dev, |
| 926 | struct drm_atomic_state *state) |
| 927 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 928 | struct drm_plane *plane; |
| 929 | struct drm_plane_state *plane_state; |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 930 | int i; |
| 931 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 932 | for_each_plane_in_state(state, plane, plane_state, i) { |
| 933 | if (!plane->state->fence) |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 934 | continue; |
| 935 | |
| 936 | WARN_ON(!plane->state->fb); |
| 937 | |
| 938 | fence_wait(plane->state->fence, false); |
| 939 | fence_put(plane->state->fence); |
| 940 | plane->state->fence = NULL; |
| 941 | } |
| 942 | } |
| 943 | |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 944 | static bool framebuffer_changed(struct drm_device *dev, |
| 945 | struct drm_atomic_state *old_state, |
| 946 | struct drm_crtc *crtc) |
| 947 | { |
| 948 | struct drm_plane *plane; |
| 949 | struct drm_plane_state *old_plane_state; |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 950 | int i; |
| 951 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 952 | for_each_plane_in_state(old_state, plane, old_plane_state, i) { |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 953 | if (plane->state->crtc != crtc && |
| 954 | old_plane_state->crtc != crtc) |
| 955 | continue; |
| 956 | |
| 957 | if (plane->state->fb != old_plane_state->fb) |
| 958 | return true; |
| 959 | } |
| 960 | |
| 961 | return false; |
| 962 | } |
| 963 | |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 964 | /** |
| 965 | * drm_atomic_helper_wait_for_vblanks - wait for vblank on crtcs |
| 966 | * @dev: DRM device |
| 967 | * @old_state: atomic state object with old state structures |
| 968 | * |
| 969 | * Helper to, after atomic commit, wait for vblanks on all effected |
| 970 | * crtcs (ie. before cleaning up old framebuffers using |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 971 | * drm_atomic_helper_cleanup_planes()). It will only wait on crtcs where the |
| 972 | * framebuffers have actually changed to optimize for the legacy cursor and |
| 973 | * plane update use-case. |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 974 | */ |
| 975 | void |
| 976 | drm_atomic_helper_wait_for_vblanks(struct drm_device *dev, |
| 977 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 978 | { |
| 979 | struct drm_crtc *crtc; |
| 980 | struct drm_crtc_state *old_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 981 | int i, ret; |
| 982 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 983 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 984 | /* No one cares about the old state, so abuse it for tracking |
| 985 | * and store whether we hold a vblank reference (and should do a |
| 986 | * vblank wait) in the ->enable boolean. */ |
| 987 | old_crtc_state->enable = false; |
| 988 | |
| 989 | if (!crtc->state->enable) |
| 990 | continue; |
| 991 | |
Daniel Vetter | f02ad90 | 2015-01-22 16:36:23 +0100 | [diff] [blame] | 992 | /* Legacy cursor ioctls are completely unsynced, and userspace |
| 993 | * relies on that (by doing tons of cursor updates). */ |
| 994 | if (old_state->legacy_cursor_update) |
| 995 | continue; |
| 996 | |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 997 | if (!framebuffer_changed(dev, old_state, crtc)) |
| 998 | continue; |
| 999 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1000 | ret = drm_crtc_vblank_get(crtc); |
| 1001 | if (ret != 0) |
| 1002 | continue; |
| 1003 | |
| 1004 | old_crtc_state->enable = true; |
Thierry Reding | d485363 | 2015-08-12 17:00:35 +0200 | [diff] [blame] | 1005 | old_crtc_state->last_vblank_count = drm_crtc_vblank_count(crtc); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1006 | } |
| 1007 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1008 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
| 1009 | if (!old_crtc_state->enable) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1010 | continue; |
| 1011 | |
| 1012 | ret = wait_event_timeout(dev->vblank[i].queue, |
| 1013 | old_crtc_state->last_vblank_count != |
Thierry Reding | d485363 | 2015-08-12 17:00:35 +0200 | [diff] [blame] | 1014 | drm_crtc_vblank_count(crtc), |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1015 | msecs_to_jiffies(50)); |
| 1016 | |
| 1017 | drm_crtc_vblank_put(crtc); |
| 1018 | } |
| 1019 | } |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 1020 | EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1021 | |
| 1022 | /** |
| 1023 | * drm_atomic_helper_commit - commit validated state object |
| 1024 | * @dev: DRM device |
| 1025 | * @state: the driver state object |
| 1026 | * @async: asynchronous commit |
| 1027 | * |
| 1028 | * This function commits a with drm_atomic_helper_check() pre-validated state |
| 1029 | * object. This can still fail when e.g. the framebuffer reservation fails. For |
| 1030 | * now this doesn't implement asynchronous commits. |
| 1031 | * |
Daniel Vetter | 6e48ae3 | 2015-09-08 13:52:45 +0200 | [diff] [blame] | 1032 | * Note that right now this function does not support async commits, and hence |
| 1033 | * driver writers must implement their own version for now. Also note that the |
| 1034 | * default ordering of how the various stages are called is to match the legacy |
| 1035 | * modeset helper library closest. One peculiarity of that is that it doesn't |
| 1036 | * mesh well with runtime PM at all. |
| 1037 | * |
| 1038 | * For drivers supporting runtime PM the recommended sequence is |
| 1039 | * |
| 1040 | * drm_atomic_helper_commit_modeset_disables(dev, state); |
| 1041 | * |
| 1042 | * drm_atomic_helper_commit_modeset_enables(dev, state); |
| 1043 | * |
| 1044 | * drm_atomic_helper_commit_planes(dev, state, true); |
| 1045 | * |
| 1046 | * See the kerneldoc entries for these three functions for more details. |
| 1047 | * |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1048 | * RETURNS |
| 1049 | * Zero for success or -errno. |
| 1050 | */ |
| 1051 | int drm_atomic_helper_commit(struct drm_device *dev, |
| 1052 | struct drm_atomic_state *state, |
| 1053 | bool async) |
| 1054 | { |
| 1055 | int ret; |
| 1056 | |
| 1057 | if (async) |
| 1058 | return -EBUSY; |
| 1059 | |
| 1060 | ret = drm_atomic_helper_prepare_planes(dev, state); |
| 1061 | if (ret) |
| 1062 | return ret; |
| 1063 | |
| 1064 | /* |
| 1065 | * This is the point of no return - everything below never fails except |
| 1066 | * when the hw goes bonghits. Which means we can commit the new state on |
| 1067 | * the software side now. |
| 1068 | */ |
| 1069 | |
| 1070 | drm_atomic_helper_swap_state(dev, state); |
| 1071 | |
| 1072 | /* |
| 1073 | * Everything below can be run asynchronously without the need to grab |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 1074 | * any modeset locks at all under one condition: It must be guaranteed |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1075 | * that the asynchronous work has either been cancelled (if the driver |
| 1076 | * supports it, which at least requires that the framebuffers get |
| 1077 | * cleaned up with drm_atomic_helper_cleanup_planes()) or completed |
| 1078 | * before the new state gets committed on the software side with |
| 1079 | * drm_atomic_helper_swap_state(). |
| 1080 | * |
| 1081 | * This scheme allows new atomic state updates to be prepared and |
| 1082 | * checked in parallel to the asynchronous completion of the previous |
| 1083 | * update. Which is important since compositors need to figure out the |
| 1084 | * composition of the next frame right after having submitted the |
| 1085 | * current layout. |
| 1086 | */ |
| 1087 | |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1088 | wait_for_fences(dev, state); |
| 1089 | |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1090 | drm_atomic_helper_commit_modeset_disables(dev, state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1091 | |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 1092 | drm_atomic_helper_commit_planes(dev, state, false); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1093 | |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1094 | drm_atomic_helper_commit_modeset_enables(dev, state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1095 | |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 1096 | drm_atomic_helper_wait_for_vblanks(dev, state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1097 | |
| 1098 | drm_atomic_helper_cleanup_planes(dev, state); |
| 1099 | |
| 1100 | drm_atomic_state_free(state); |
| 1101 | |
| 1102 | return 0; |
| 1103 | } |
| 1104 | EXPORT_SYMBOL(drm_atomic_helper_commit); |
| 1105 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1106 | /** |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1107 | * DOC: implementing async commit |
| 1108 | * |
| 1109 | * For now the atomic helpers don't support async commit directly. If there is |
| 1110 | * real need it could be added though, using the dma-buf fence infrastructure |
| 1111 | * for generic synchronization with outstanding rendering. |
| 1112 | * |
| 1113 | * For now drivers have to implement async commit themselves, with the following |
| 1114 | * sequence being the recommended one: |
| 1115 | * |
| 1116 | * 1. Run drm_atomic_helper_prepare_planes() first. This is the only function |
| 1117 | * which commit needs to call which can fail, so we want to run it first and |
| 1118 | * synchronously. |
| 1119 | * |
| 1120 | * 2. Synchronize with any outstanding asynchronous commit worker threads which |
| 1121 | * might be affected the new state update. This can be done by either cancelling |
| 1122 | * or flushing the work items, depending upon whether the driver can deal with |
| 1123 | * cancelled updates. Note that it is important to ensure that the framebuffer |
| 1124 | * cleanup is still done when cancelling. |
| 1125 | * |
| 1126 | * For sufficient parallelism it is recommended to have a work item per crtc |
| 1127 | * (for updates which don't touch global state) and a global one. Then we only |
| 1128 | * need to synchronize with the crtc work items for changed crtcs and the global |
| 1129 | * work item, which allows nice concurrent updates on disjoint sets of crtcs. |
| 1130 | * |
| 1131 | * 3. The software state is updated synchronously with |
Daniel Vetter | 26196f7 | 2015-08-25 16:26:03 +0200 | [diff] [blame] | 1132 | * 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] | 1133 | * locks means concurrent callers never see inconsistent state. And doing this |
| 1134 | * while it's guaranteed that no relevant async worker runs means that async |
| 1135 | * workers do not need grab any locks. Actually they must not grab locks, for |
| 1136 | * otherwise the work flushing will deadlock. |
| 1137 | * |
| 1138 | * 4. Schedule a work item to do all subsequent steps, using the split-out |
| 1139 | * commit helpers: a) pre-plane commit b) plane commit c) post-plane commit and |
| 1140 | * then cleaning up the framebuffers after the old framebuffer is no longer |
| 1141 | * being displayed. |
| 1142 | */ |
| 1143 | |
| 1144 | /** |
Daniel Vetter | 2e3afd4 | 2015-02-26 14:17:38 +0100 | [diff] [blame] | 1145 | * drm_atomic_helper_prepare_planes - prepare plane resources before commit |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1146 | * @dev: DRM device |
Daniel Vetter | 2e3afd4 | 2015-02-26 14:17:38 +0100 | [diff] [blame] | 1147 | * @state: atomic state object with new state structures |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1148 | * |
| 1149 | * This function prepares plane state, specifically framebuffers, for the new |
| 1150 | * configuration. If any failure is encountered this function will call |
| 1151 | * ->cleanup_fb on any already successfully prepared framebuffer. |
| 1152 | * |
| 1153 | * Returns: |
| 1154 | * 0 on success, negative error code on failure. |
| 1155 | */ |
| 1156 | int drm_atomic_helper_prepare_planes(struct drm_device *dev, |
| 1157 | struct drm_atomic_state *state) |
| 1158 | { |
| 1159 | int nplanes = dev->mode_config.num_total_plane; |
| 1160 | int ret, i; |
| 1161 | |
| 1162 | for (i = 0; i < nplanes; i++) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1163 | const struct drm_plane_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1164 | struct drm_plane *plane = state->planes[i]; |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 1165 | struct drm_plane_state *plane_state = state->plane_states[i]; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1166 | |
| 1167 | if (!plane) |
| 1168 | continue; |
| 1169 | |
| 1170 | funcs = plane->helper_private; |
| 1171 | |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 1172 | if (funcs->prepare_fb) { |
| 1173 | ret = funcs->prepare_fb(plane, plane_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1174 | if (ret) |
| 1175 | goto fail; |
| 1176 | } |
| 1177 | } |
| 1178 | |
| 1179 | return 0; |
| 1180 | |
| 1181 | fail: |
| 1182 | for (i--; i >= 0; i--) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1183 | const struct drm_plane_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1184 | struct drm_plane *plane = state->planes[i]; |
Tvrtko Ursulin | d136dfe | 2015-03-03 14:22:31 +0000 | [diff] [blame] | 1185 | struct drm_plane_state *plane_state = state->plane_states[i]; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1186 | |
| 1187 | if (!plane) |
| 1188 | continue; |
| 1189 | |
| 1190 | funcs = plane->helper_private; |
| 1191 | |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 1192 | if (funcs->cleanup_fb) |
| 1193 | funcs->cleanup_fb(plane, plane_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1194 | |
| 1195 | } |
| 1196 | |
| 1197 | return ret; |
| 1198 | } |
| 1199 | EXPORT_SYMBOL(drm_atomic_helper_prepare_planes); |
| 1200 | |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 1201 | bool plane_crtc_active(struct drm_plane_state *state) |
| 1202 | { |
| 1203 | return state->crtc && state->crtc->state->active; |
| 1204 | } |
| 1205 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1206 | /** |
| 1207 | * drm_atomic_helper_commit_planes - commit plane state |
| 1208 | * @dev: DRM device |
Daniel Vetter | b0fcfc8 | 2014-11-19 18:38:11 +0100 | [diff] [blame] | 1209 | * @old_state: atomic state object with old state structures |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 1210 | * @active_only: Only commit on active CRTC if set |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1211 | * |
| 1212 | * This function commits the new plane state using the plane and atomic helper |
| 1213 | * functions for planes and crtcs. It assumes that the atomic state has already |
| 1214 | * been pushed into the relevant object state pointers, since this step can no |
| 1215 | * longer fail. |
| 1216 | * |
Daniel Vetter | b0fcfc8 | 2014-11-19 18:38:11 +0100 | [diff] [blame] | 1217 | * 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] | 1218 | * crtcs need to be updated though. |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 1219 | * |
| 1220 | * Note that this function does all plane updates across all CRTCs in one step. |
| 1221 | * If the hardware can't support this approach look at |
| 1222 | * drm_atomic_helper_commit_planes_on_crtc() instead. |
Daniel Vetter | 6e48ae3 | 2015-09-08 13:52:45 +0200 | [diff] [blame] | 1223 | * |
| 1224 | * Plane parameters can be updated by applications while the associated CRTC is |
| 1225 | * disabled. The DRM/KMS core will store the parameters in the plane state, |
| 1226 | * which will be available to the driver when the CRTC is turned on. As a result |
| 1227 | * most drivers don't need to be immediately notified of plane updates for a |
| 1228 | * disabled CRTC. |
| 1229 | * |
| 1230 | * Unless otherwise needed, drivers are advised to set the @active_only |
| 1231 | * parameters to true in order not to receive plane update notifications related |
| 1232 | * to a disabled CRTC. This avoids the need to manually ignore plane updates in |
| 1233 | * driver code when the driver and/or hardware can't or just don't need to deal |
| 1234 | * with updates on disabled CRTCs, for example when supporting runtime PM. |
| 1235 | * |
| 1236 | * The drm_atomic_helper_commit() default implementation only sets @active_only |
| 1237 | * to false to most closely match the behaviour of the legacy helpers. This should |
| 1238 | * not be copied blindly by drivers. |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1239 | */ |
| 1240 | void drm_atomic_helper_commit_planes(struct drm_device *dev, |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 1241 | struct drm_atomic_state *old_state, |
| 1242 | bool active_only) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1243 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1244 | struct drm_crtc *crtc; |
| 1245 | struct drm_crtc_state *old_crtc_state; |
| 1246 | struct drm_plane *plane; |
| 1247 | struct drm_plane_state *old_plane_state; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1248 | int i; |
| 1249 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1250 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1251 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1252 | |
| 1253 | funcs = crtc->helper_private; |
| 1254 | |
| 1255 | if (!funcs || !funcs->atomic_begin) |
| 1256 | continue; |
| 1257 | |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 1258 | if (active_only && !crtc->state->active) |
| 1259 | continue; |
| 1260 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 1261 | funcs->atomic_begin(crtc, old_crtc_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1262 | } |
| 1263 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1264 | for_each_plane_in_state(old_state, plane, old_plane_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1265 | const struct drm_plane_helper_funcs *funcs; |
Laurent Pinchart | 216c59d | 2015-09-11 00:07:19 +0300 | [diff] [blame] | 1266 | bool disabling; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1267 | |
| 1268 | funcs = plane->helper_private; |
| 1269 | |
Thierry Reding | 3cad4b6 | 2014-11-25 13:05:12 +0100 | [diff] [blame] | 1270 | if (!funcs) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1271 | continue; |
| 1272 | |
Laurent Pinchart | 216c59d | 2015-09-11 00:07:19 +0300 | [diff] [blame] | 1273 | disabling = drm_atomic_plane_disabling(plane, old_plane_state); |
| 1274 | |
| 1275 | if (active_only) { |
| 1276 | /* |
| 1277 | * Skip planes related to inactive CRTCs. If the plane |
| 1278 | * is enabled use the state of the current CRTC. If the |
| 1279 | * plane is being disabled use the state of the old |
| 1280 | * CRTC to avoid skipping planes being disabled on an |
| 1281 | * active CRTC. |
| 1282 | */ |
| 1283 | if (!disabling && !plane_crtc_active(plane->state)) |
| 1284 | continue; |
| 1285 | if (disabling && !plane_crtc_active(old_plane_state)) |
| 1286 | continue; |
| 1287 | } |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 1288 | |
Thierry Reding | 407b8bd | 2014-11-20 12:05:50 +0100 | [diff] [blame] | 1289 | /* |
| 1290 | * Special-case disabling the plane if drivers support it. |
| 1291 | */ |
Laurent Pinchart | 216c59d | 2015-09-11 00:07:19 +0300 | [diff] [blame] | 1292 | if (disabling && funcs->atomic_disable) |
Thierry Reding | 407b8bd | 2014-11-20 12:05:50 +0100 | [diff] [blame] | 1293 | funcs->atomic_disable(plane, old_plane_state); |
Laurent Pinchart | 216c59d | 2015-09-11 00:07:19 +0300 | [diff] [blame] | 1294 | else if (plane->state->crtc || disabling) |
Thierry Reding | 407b8bd | 2014-11-20 12:05:50 +0100 | [diff] [blame] | 1295 | funcs->atomic_update(plane, old_plane_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1296 | } |
| 1297 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1298 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1299 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1300 | |
| 1301 | funcs = crtc->helper_private; |
| 1302 | |
| 1303 | if (!funcs || !funcs->atomic_flush) |
| 1304 | continue; |
| 1305 | |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 1306 | if (active_only && !crtc->state->active) |
| 1307 | continue; |
| 1308 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 1309 | funcs->atomic_flush(crtc, old_crtc_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1310 | } |
| 1311 | } |
| 1312 | EXPORT_SYMBOL(drm_atomic_helper_commit_planes); |
| 1313 | |
| 1314 | /** |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 1315 | * drm_atomic_helper_commit_planes_on_crtc - commit plane state for a crtc |
| 1316 | * @old_crtc_state: atomic state object with the old crtc state |
| 1317 | * |
| 1318 | * This function commits the new plane state using the plane and atomic helper |
| 1319 | * functions for planes on the specific crtc. It assumes that the atomic state |
| 1320 | * has already been pushed into the relevant object state pointers, since this |
| 1321 | * step can no longer fail. |
| 1322 | * |
| 1323 | * This function is useful when plane updates should be done crtc-by-crtc |
| 1324 | * instead of one global step like drm_atomic_helper_commit_planes() does. |
| 1325 | * |
| 1326 | * This function can only be savely used when planes are not allowed to move |
| 1327 | * between different CRTCs because this function doesn't handle inter-CRTC |
| 1328 | * depencies. Callers need to ensure that either no such depencies exist, |
| 1329 | * resolve them through ordering of commit calls or through some other means. |
| 1330 | */ |
| 1331 | void |
| 1332 | drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state) |
| 1333 | { |
| 1334 | const struct drm_crtc_helper_funcs *crtc_funcs; |
| 1335 | struct drm_crtc *crtc = old_crtc_state->crtc; |
| 1336 | struct drm_atomic_state *old_state = old_crtc_state->state; |
| 1337 | struct drm_plane *plane; |
| 1338 | unsigned plane_mask; |
| 1339 | |
| 1340 | plane_mask = old_crtc_state->plane_mask; |
| 1341 | plane_mask |= crtc->state->plane_mask; |
| 1342 | |
| 1343 | crtc_funcs = crtc->helper_private; |
| 1344 | if (crtc_funcs && crtc_funcs->atomic_begin) |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 1345 | crtc_funcs->atomic_begin(crtc, old_crtc_state); |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 1346 | |
| 1347 | drm_for_each_plane_mask(plane, crtc->dev, plane_mask) { |
| 1348 | struct drm_plane_state *old_plane_state = |
| 1349 | drm_atomic_get_existing_plane_state(old_state, plane); |
| 1350 | const struct drm_plane_helper_funcs *plane_funcs; |
| 1351 | |
| 1352 | plane_funcs = plane->helper_private; |
| 1353 | |
| 1354 | if (!old_plane_state || !plane_funcs) |
| 1355 | continue; |
| 1356 | |
| 1357 | WARN_ON(plane->state->crtc && plane->state->crtc != crtc); |
| 1358 | |
| 1359 | if (drm_atomic_plane_disabling(plane, old_plane_state) && |
| 1360 | plane_funcs->atomic_disable) |
| 1361 | plane_funcs->atomic_disable(plane, old_plane_state); |
| 1362 | else if (plane->state->crtc || |
| 1363 | drm_atomic_plane_disabling(plane, old_plane_state)) |
| 1364 | plane_funcs->atomic_update(plane, old_plane_state); |
| 1365 | } |
| 1366 | |
| 1367 | if (crtc_funcs && crtc_funcs->atomic_flush) |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 1368 | crtc_funcs->atomic_flush(crtc, old_crtc_state); |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 1369 | } |
| 1370 | EXPORT_SYMBOL(drm_atomic_helper_commit_planes_on_crtc); |
| 1371 | |
| 1372 | /** |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 1373 | * drm_atomic_helper_disable_planes_on_crtc - helper to disable CRTC's planes |
| 1374 | * @crtc: CRTC |
| 1375 | * @atomic: if set, synchronize with CRTC's atomic_begin/flush hooks |
| 1376 | * |
| 1377 | * Disables all planes associated with the given CRTC. This can be |
| 1378 | * used for instance in the CRTC helper disable callback to disable |
| 1379 | * all planes before shutting down the display pipeline. |
| 1380 | * |
| 1381 | * If the atomic-parameter is set the function calls the CRTC's |
| 1382 | * atomic_begin hook before and atomic_flush hook after disabling the |
| 1383 | * planes. |
| 1384 | * |
| 1385 | * It is a bug to call this function without having implemented the |
| 1386 | * ->atomic_disable() plane hook. |
| 1387 | */ |
| 1388 | void drm_atomic_helper_disable_planes_on_crtc(struct drm_crtc *crtc, |
| 1389 | bool atomic) |
| 1390 | { |
| 1391 | const struct drm_crtc_helper_funcs *crtc_funcs = |
| 1392 | crtc->helper_private; |
| 1393 | struct drm_plane *plane; |
| 1394 | |
| 1395 | if (atomic && crtc_funcs && crtc_funcs->atomic_begin) |
| 1396 | crtc_funcs->atomic_begin(crtc, NULL); |
| 1397 | |
| 1398 | drm_for_each_plane(plane, crtc->dev) { |
| 1399 | const struct drm_plane_helper_funcs *plane_funcs = |
| 1400 | plane->helper_private; |
| 1401 | |
| 1402 | if (plane->state->crtc != crtc || !plane_funcs) |
| 1403 | continue; |
| 1404 | |
| 1405 | WARN_ON(!plane_funcs->atomic_disable); |
| 1406 | if (plane_funcs->atomic_disable) |
| 1407 | plane_funcs->atomic_disable(plane, NULL); |
| 1408 | } |
| 1409 | |
| 1410 | if (atomic && crtc_funcs && crtc_funcs->atomic_flush) |
| 1411 | crtc_funcs->atomic_flush(crtc, NULL); |
| 1412 | } |
| 1413 | EXPORT_SYMBOL(drm_atomic_helper_disable_planes_on_crtc); |
| 1414 | |
| 1415 | /** |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1416 | * drm_atomic_helper_cleanup_planes - cleanup plane resources after commit |
| 1417 | * @dev: DRM device |
| 1418 | * @old_state: atomic state object with old state structures |
| 1419 | * |
| 1420 | * This function cleans up plane state, specifically framebuffers, from the old |
| 1421 | * configuration. Hence the old configuration must be perserved in @old_state to |
| 1422 | * be able to call this function. |
| 1423 | * |
| 1424 | * This function must also be called on the new state when the atomic update |
| 1425 | * fails at any point after calling drm_atomic_helper_prepare_planes(). |
| 1426 | */ |
| 1427 | void drm_atomic_helper_cleanup_planes(struct drm_device *dev, |
| 1428 | struct drm_atomic_state *old_state) |
| 1429 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1430 | struct drm_plane *plane; |
| 1431 | struct drm_plane_state *plane_state; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1432 | int i; |
| 1433 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1434 | for_each_plane_in_state(old_state, plane, plane_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1435 | const struct drm_plane_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1436 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1437 | funcs = plane->helper_private; |
| 1438 | |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 1439 | if (funcs->cleanup_fb) |
| 1440 | funcs->cleanup_fb(plane, plane_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1441 | } |
| 1442 | } |
| 1443 | EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes); |
| 1444 | |
| 1445 | /** |
| 1446 | * drm_atomic_helper_swap_state - store atomic state into current sw state |
| 1447 | * @dev: DRM device |
| 1448 | * @state: atomic state |
| 1449 | * |
| 1450 | * This function stores the atomic state into the current state pointers in all |
| 1451 | * driver objects. It should be called after all failing steps have been done |
| 1452 | * and succeeded, but before the actual hardware state is committed. |
| 1453 | * |
| 1454 | * For cleanup and error recovery the current state for all changed objects will |
| 1455 | * be swaped into @state. |
| 1456 | * |
| 1457 | * With that sequence it fits perfectly into the plane prepare/cleanup sequence: |
| 1458 | * |
| 1459 | * 1. Call drm_atomic_helper_prepare_planes() with the staged atomic state. |
| 1460 | * |
| 1461 | * 2. Do any other steps that might fail. |
| 1462 | * |
| 1463 | * 3. Put the staged state into the current state pointers with this function. |
| 1464 | * |
| 1465 | * 4. Actually commit the hardware state. |
| 1466 | * |
Daniel Vetter | 26196f7 | 2015-08-25 16:26:03 +0200 | [diff] [blame] | 1467 | * 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] | 1468 | * contains the old state. Also do any other cleanup required with that state. |
| 1469 | */ |
| 1470 | void drm_atomic_helper_swap_state(struct drm_device *dev, |
| 1471 | struct drm_atomic_state *state) |
| 1472 | { |
| 1473 | int i; |
| 1474 | |
| 1475 | for (i = 0; i < dev->mode_config.num_connector; i++) { |
| 1476 | struct drm_connector *connector = state->connectors[i]; |
| 1477 | |
| 1478 | if (!connector) |
| 1479 | continue; |
| 1480 | |
| 1481 | connector->state->state = state; |
| 1482 | swap(state->connector_states[i], connector->state); |
| 1483 | connector->state->state = NULL; |
| 1484 | } |
| 1485 | |
| 1486 | for (i = 0; i < dev->mode_config.num_crtc; i++) { |
| 1487 | struct drm_crtc *crtc = state->crtcs[i]; |
| 1488 | |
| 1489 | if (!crtc) |
| 1490 | continue; |
| 1491 | |
| 1492 | crtc->state->state = state; |
| 1493 | swap(state->crtc_states[i], crtc->state); |
| 1494 | crtc->state->state = NULL; |
| 1495 | } |
| 1496 | |
| 1497 | for (i = 0; i < dev->mode_config.num_total_plane; i++) { |
| 1498 | struct drm_plane *plane = state->planes[i]; |
| 1499 | |
| 1500 | if (!plane) |
| 1501 | continue; |
| 1502 | |
| 1503 | plane->state->state = state; |
| 1504 | swap(state->plane_states[i], plane->state); |
| 1505 | plane->state->state = NULL; |
| 1506 | } |
| 1507 | } |
| 1508 | EXPORT_SYMBOL(drm_atomic_helper_swap_state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1509 | |
| 1510 | /** |
| 1511 | * drm_atomic_helper_update_plane - Helper for primary plane update using atomic |
| 1512 | * @plane: plane object to update |
| 1513 | * @crtc: owning CRTC of owning plane |
| 1514 | * @fb: framebuffer to flip onto plane |
| 1515 | * @crtc_x: x offset of primary plane on crtc |
| 1516 | * @crtc_y: y offset of primary plane on crtc |
| 1517 | * @crtc_w: width of primary plane rectangle on crtc |
| 1518 | * @crtc_h: height of primary plane rectangle on crtc |
| 1519 | * @src_x: x offset of @fb for panning |
| 1520 | * @src_y: y offset of @fb for panning |
| 1521 | * @src_w: width of source rectangle in @fb |
| 1522 | * @src_h: height of source rectangle in @fb |
| 1523 | * |
| 1524 | * Provides a default plane update handler using the atomic driver interface. |
| 1525 | * |
| 1526 | * RETURNS: |
| 1527 | * Zero on success, error code on failure |
| 1528 | */ |
| 1529 | int drm_atomic_helper_update_plane(struct drm_plane *plane, |
| 1530 | struct drm_crtc *crtc, |
| 1531 | struct drm_framebuffer *fb, |
| 1532 | int crtc_x, int crtc_y, |
| 1533 | unsigned int crtc_w, unsigned int crtc_h, |
| 1534 | uint32_t src_x, uint32_t src_y, |
| 1535 | uint32_t src_w, uint32_t src_h) |
| 1536 | { |
| 1537 | struct drm_atomic_state *state; |
| 1538 | struct drm_plane_state *plane_state; |
| 1539 | int ret = 0; |
| 1540 | |
| 1541 | state = drm_atomic_state_alloc(plane->dev); |
| 1542 | if (!state) |
| 1543 | return -ENOMEM; |
| 1544 | |
| 1545 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 1546 | retry: |
| 1547 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 1548 | if (IS_ERR(plane_state)) { |
| 1549 | ret = PTR_ERR(plane_state); |
| 1550 | goto fail; |
| 1551 | } |
| 1552 | |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 1553 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1554 | if (ret != 0) |
| 1555 | goto fail; |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 1556 | drm_atomic_set_fb_for_plane(plane_state, fb); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1557 | plane_state->crtc_x = crtc_x; |
| 1558 | plane_state->crtc_y = crtc_y; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1559 | plane_state->crtc_w = crtc_w; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 1560 | plane_state->crtc_h = crtc_h; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1561 | plane_state->src_x = src_x; |
| 1562 | plane_state->src_y = src_y; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1563 | plane_state->src_w = src_w; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 1564 | plane_state->src_h = src_h; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1565 | |
Daniel Vetter | 3671c58 | 2015-05-04 15:40:52 +0200 | [diff] [blame] | 1566 | if (plane == crtc->cursor) |
| 1567 | state->legacy_cursor_update = true; |
| 1568 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1569 | ret = drm_atomic_commit(state); |
| 1570 | if (ret != 0) |
| 1571 | goto fail; |
| 1572 | |
| 1573 | /* Driver takes ownership of state on successful commit. */ |
| 1574 | return 0; |
| 1575 | fail: |
| 1576 | if (ret == -EDEADLK) |
| 1577 | goto backoff; |
| 1578 | |
| 1579 | drm_atomic_state_free(state); |
| 1580 | |
| 1581 | return ret; |
| 1582 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1583 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 1584 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1585 | |
| 1586 | /* |
| 1587 | * Someone might have exchanged the framebuffer while we dropped locks |
| 1588 | * in the backoff code. We need to fix up the fb refcount tracking the |
| 1589 | * core does for us. |
| 1590 | */ |
| 1591 | plane->old_fb = plane->fb; |
| 1592 | |
| 1593 | goto retry; |
| 1594 | } |
| 1595 | EXPORT_SYMBOL(drm_atomic_helper_update_plane); |
| 1596 | |
| 1597 | /** |
| 1598 | * drm_atomic_helper_disable_plane - Helper for primary plane disable using * atomic |
| 1599 | * @plane: plane to disable |
| 1600 | * |
| 1601 | * Provides a default plane disable handler using the atomic driver interface. |
| 1602 | * |
| 1603 | * RETURNS: |
| 1604 | * Zero on success, error code on failure |
| 1605 | */ |
| 1606 | int drm_atomic_helper_disable_plane(struct drm_plane *plane) |
| 1607 | { |
| 1608 | struct drm_atomic_state *state; |
| 1609 | struct drm_plane_state *plane_state; |
| 1610 | int ret = 0; |
| 1611 | |
Jasper St. Pierre | aa54e2e | 2014-11-20 19:59:15 -0800 | [diff] [blame] | 1612 | /* |
| 1613 | * FIXME: Without plane->crtc set we can't get at the implicit legacy |
| 1614 | * acquire context. The real fix will be to wire the acquire ctx through |
| 1615 | * everywhere we need it, but meanwhile prevent chaos by just skipping |
| 1616 | * this noop. The critical case is the cursor ioctls which a) only grab |
| 1617 | * crtc/cursor-plane locks (so we need the crtc to get at the right |
| 1618 | * acquire context) and b) can try to disable the plane multiple times. |
| 1619 | */ |
| 1620 | if (!plane->crtc) |
| 1621 | return 0; |
| 1622 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1623 | state = drm_atomic_state_alloc(plane->dev); |
| 1624 | if (!state) |
| 1625 | return -ENOMEM; |
| 1626 | |
| 1627 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(plane->crtc); |
| 1628 | retry: |
| 1629 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 1630 | if (IS_ERR(plane_state)) { |
| 1631 | ret = PTR_ERR(plane_state); |
| 1632 | goto fail; |
| 1633 | } |
| 1634 | |
Maarten Lankhorst | 24e79d0 | 2015-11-11 11:29:07 +0100 | [diff] [blame] | 1635 | if (plane_state->crtc && (plane == plane->crtc->cursor)) |
| 1636 | plane_state->state->legacy_cursor_update = true; |
| 1637 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 1638 | ret = __drm_atomic_helper_disable_plane(plane, plane_state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1639 | if (ret != 0) |
| 1640 | goto fail; |
Daniel Vetter | f02ad90 | 2015-01-22 16:36:23 +0100 | [diff] [blame] | 1641 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1642 | ret = drm_atomic_commit(state); |
| 1643 | if (ret != 0) |
| 1644 | goto fail; |
| 1645 | |
| 1646 | /* Driver takes ownership of state on successful commit. */ |
| 1647 | return 0; |
| 1648 | fail: |
| 1649 | if (ret == -EDEADLK) |
| 1650 | goto backoff; |
| 1651 | |
| 1652 | drm_atomic_state_free(state); |
| 1653 | |
| 1654 | return ret; |
| 1655 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1656 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 1657 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1658 | |
| 1659 | /* |
| 1660 | * Someone might have exchanged the framebuffer while we dropped locks |
| 1661 | * in the backoff code. We need to fix up the fb refcount tracking the |
| 1662 | * core does for us. |
| 1663 | */ |
| 1664 | plane->old_fb = plane->fb; |
| 1665 | |
| 1666 | goto retry; |
| 1667 | } |
| 1668 | EXPORT_SYMBOL(drm_atomic_helper_disable_plane); |
| 1669 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 1670 | /* just used from fb-helper and atomic-helper: */ |
| 1671 | int __drm_atomic_helper_disable_plane(struct drm_plane *plane, |
| 1672 | struct drm_plane_state *plane_state) |
| 1673 | { |
| 1674 | int ret; |
| 1675 | |
| 1676 | ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); |
| 1677 | if (ret != 0) |
| 1678 | return ret; |
| 1679 | |
| 1680 | drm_atomic_set_fb_for_plane(plane_state, NULL); |
| 1681 | plane_state->crtc_x = 0; |
| 1682 | plane_state->crtc_y = 0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 1683 | plane_state->crtc_w = 0; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 1684 | plane_state->crtc_h = 0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 1685 | plane_state->src_x = 0; |
| 1686 | plane_state->src_y = 0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 1687 | plane_state->src_w = 0; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 1688 | plane_state->src_h = 0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 1689 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 1690 | return 0; |
| 1691 | } |
| 1692 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1693 | static int update_output_state(struct drm_atomic_state *state, |
| 1694 | struct drm_mode_set *set) |
| 1695 | { |
| 1696 | struct drm_device *dev = set->crtc->dev; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1697 | struct drm_crtc *crtc; |
| 1698 | struct drm_crtc_state *crtc_state; |
| 1699 | struct drm_connector *connector; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1700 | struct drm_connector_state *conn_state; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1701 | int ret, i, j; |
| 1702 | |
| 1703 | ret = drm_modeset_lock(&dev->mode_config.connection_mutex, |
| 1704 | state->acquire_ctx); |
| 1705 | if (ret) |
| 1706 | return ret; |
| 1707 | |
| 1708 | /* First grab all affected connector/crtc states. */ |
| 1709 | for (i = 0; i < set->num_connectors; i++) { |
| 1710 | conn_state = drm_atomic_get_connector_state(state, |
| 1711 | set->connectors[i]); |
| 1712 | if (IS_ERR(conn_state)) |
| 1713 | return PTR_ERR(conn_state); |
| 1714 | } |
| 1715 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1716 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1717 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 1718 | if (ret) |
| 1719 | return ret; |
| 1720 | } |
| 1721 | |
| 1722 | /* Then recompute connector->crtc links and crtc enabling state. */ |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1723 | for_each_connector_in_state(state, connector, conn_state, i) { |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1724 | if (conn_state->crtc == set->crtc) { |
| 1725 | ret = drm_atomic_set_crtc_for_connector(conn_state, |
| 1726 | NULL); |
| 1727 | if (ret) |
| 1728 | return ret; |
| 1729 | } |
| 1730 | |
| 1731 | for (j = 0; j < set->num_connectors; j++) { |
| 1732 | if (set->connectors[j] == connector) { |
| 1733 | ret = drm_atomic_set_crtc_for_connector(conn_state, |
| 1734 | set->crtc); |
| 1735 | if (ret) |
| 1736 | return ret; |
| 1737 | break; |
| 1738 | } |
| 1739 | } |
| 1740 | } |
| 1741 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1742 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1743 | /* Don't update ->enable for the CRTC in the set_config request, |
| 1744 | * since a mismatch would indicate a bug in the upper layers. |
| 1745 | * The actual modeset code later on will catch any |
| 1746 | * inconsistencies here. */ |
| 1747 | if (crtc == set->crtc) |
| 1748 | continue; |
| 1749 | |
Laurent Pinchart | c30f55a | 2015-06-22 13:37:46 +0300 | [diff] [blame] | 1750 | if (!drm_atomic_connectors_for_crtc(state, crtc)) { |
| 1751 | ret = drm_atomic_set_mode_prop_for_crtc(crtc_state, |
| 1752 | NULL); |
| 1753 | if (ret < 0) |
| 1754 | return ret; |
| 1755 | |
Maarten Lankhorst | 9b5edbf | 2015-06-01 08:59:53 +0200 | [diff] [blame] | 1756 | crtc_state->active = false; |
Laurent Pinchart | c30f55a | 2015-06-22 13:37:46 +0300 | [diff] [blame] | 1757 | } |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1758 | } |
| 1759 | |
| 1760 | return 0; |
| 1761 | } |
| 1762 | |
| 1763 | /** |
| 1764 | * drm_atomic_helper_set_config - set a new config from userspace |
| 1765 | * @set: mode set configuration |
| 1766 | * |
| 1767 | * Provides a default crtc set_config handler using the atomic driver interface. |
| 1768 | * |
| 1769 | * Returns: |
| 1770 | * Returns 0 on success, negative errno numbers on failure. |
| 1771 | */ |
| 1772 | int drm_atomic_helper_set_config(struct drm_mode_set *set) |
| 1773 | { |
| 1774 | struct drm_atomic_state *state; |
| 1775 | struct drm_crtc *crtc = set->crtc; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1776 | int ret = 0; |
| 1777 | |
| 1778 | state = drm_atomic_state_alloc(crtc->dev); |
| 1779 | if (!state) |
| 1780 | return -ENOMEM; |
| 1781 | |
| 1782 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 1783 | retry: |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 1784 | ret = __drm_atomic_helper_set_config(set, state); |
Daniel Stone | 819364d | 2015-05-26 14:36:48 +0100 | [diff] [blame] | 1785 | if (ret != 0) |
| 1786 | goto fail; |
| 1787 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1788 | ret = drm_atomic_commit(state); |
| 1789 | if (ret != 0) |
| 1790 | goto fail; |
| 1791 | |
| 1792 | /* Driver takes ownership of state on successful commit. */ |
| 1793 | return 0; |
| 1794 | fail: |
| 1795 | if (ret == -EDEADLK) |
| 1796 | goto backoff; |
| 1797 | |
| 1798 | drm_atomic_state_free(state); |
| 1799 | |
| 1800 | return ret; |
| 1801 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1802 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 1803 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1804 | |
| 1805 | /* |
| 1806 | * Someone might have exchanged the framebuffer while we dropped locks |
| 1807 | * in the backoff code. We need to fix up the fb refcount tracking the |
| 1808 | * core does for us. |
| 1809 | */ |
| 1810 | crtc->primary->old_fb = crtc->primary->fb; |
| 1811 | |
| 1812 | goto retry; |
| 1813 | } |
| 1814 | EXPORT_SYMBOL(drm_atomic_helper_set_config); |
| 1815 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 1816 | /* just used from fb-helper and atomic-helper: */ |
| 1817 | int __drm_atomic_helper_set_config(struct drm_mode_set *set, |
| 1818 | struct drm_atomic_state *state) |
| 1819 | { |
| 1820 | struct drm_crtc_state *crtc_state; |
| 1821 | struct drm_plane_state *primary_state; |
| 1822 | struct drm_crtc *crtc = set->crtc; |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 1823 | int hdisplay, vdisplay; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 1824 | int ret; |
| 1825 | |
| 1826 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 1827 | if (IS_ERR(crtc_state)) |
| 1828 | return PTR_ERR(crtc_state); |
| 1829 | |
| 1830 | primary_state = drm_atomic_get_plane_state(state, crtc->primary); |
| 1831 | if (IS_ERR(primary_state)) |
| 1832 | return PTR_ERR(primary_state); |
| 1833 | |
| 1834 | if (!set->mode) { |
| 1835 | WARN_ON(set->fb); |
| 1836 | WARN_ON(set->num_connectors); |
| 1837 | |
| 1838 | ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL); |
| 1839 | if (ret != 0) |
| 1840 | return ret; |
| 1841 | |
| 1842 | crtc_state->active = false; |
| 1843 | |
| 1844 | ret = drm_atomic_set_crtc_for_plane(primary_state, NULL); |
| 1845 | if (ret != 0) |
| 1846 | return ret; |
| 1847 | |
| 1848 | drm_atomic_set_fb_for_plane(primary_state, NULL); |
| 1849 | |
| 1850 | goto commit; |
| 1851 | } |
| 1852 | |
| 1853 | WARN_ON(!set->fb); |
| 1854 | WARN_ON(!set->num_connectors); |
| 1855 | |
| 1856 | ret = drm_atomic_set_mode_for_crtc(crtc_state, set->mode); |
| 1857 | if (ret != 0) |
| 1858 | return ret; |
| 1859 | |
| 1860 | crtc_state->active = true; |
| 1861 | |
| 1862 | ret = drm_atomic_set_crtc_for_plane(primary_state, crtc); |
| 1863 | if (ret != 0) |
| 1864 | return ret; |
| 1865 | |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 1866 | drm_crtc_get_hv_timing(set->mode, &hdisplay, &vdisplay); |
| 1867 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 1868 | drm_atomic_set_fb_for_plane(primary_state, set->fb); |
| 1869 | primary_state->crtc_x = 0; |
| 1870 | primary_state->crtc_y = 0; |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 1871 | primary_state->crtc_w = hdisplay; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 1872 | primary_state->crtc_h = vdisplay; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 1873 | primary_state->src_x = set->x << 16; |
| 1874 | primary_state->src_y = set->y << 16; |
Ville Syrjälä | 4112124 | 2015-10-15 20:39:59 +0300 | [diff] [blame] | 1875 | if (primary_state->rotation & (BIT(DRM_ROTATE_90) | BIT(DRM_ROTATE_270))) { |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 1876 | primary_state->src_w = vdisplay << 16; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 1877 | primary_state->src_h = hdisplay << 16; |
Ville Syrjälä | 4112124 | 2015-10-15 20:39:59 +0300 | [diff] [blame] | 1878 | } else { |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 1879 | primary_state->src_w = hdisplay << 16; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 1880 | primary_state->src_h = vdisplay << 16; |
Ville Syrjälä | 4112124 | 2015-10-15 20:39:59 +0300 | [diff] [blame] | 1881 | } |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 1882 | |
| 1883 | commit: |
| 1884 | ret = update_output_state(state, set); |
| 1885 | if (ret) |
| 1886 | return ret; |
| 1887 | |
| 1888 | return 0; |
| 1889 | } |
| 1890 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1891 | /** |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 1892 | * drm_atomic_helper_disable_all - disable all currently active outputs |
| 1893 | * @dev: DRM device |
| 1894 | * @ctx: lock acquisition context |
| 1895 | * |
| 1896 | * Loops through all connectors, finding those that aren't turned off and then |
| 1897 | * turns them off by setting their DPMS mode to OFF and deactivating the CRTC |
| 1898 | * that they are connected to. |
| 1899 | * |
| 1900 | * This is used for example in suspend/resume to disable all currently active |
| 1901 | * functions when suspending. |
| 1902 | * |
| 1903 | * Note that if callers haven't already acquired all modeset locks this might |
| 1904 | * return -EDEADLK, which must be handled by calling drm_modeset_backoff(). |
| 1905 | * |
| 1906 | * Returns: |
| 1907 | * 0 on success or a negative error code on failure. |
| 1908 | * |
| 1909 | * See also: |
| 1910 | * drm_atomic_helper_suspend(), drm_atomic_helper_resume() |
| 1911 | */ |
| 1912 | int drm_atomic_helper_disable_all(struct drm_device *dev, |
| 1913 | struct drm_modeset_acquire_ctx *ctx) |
| 1914 | { |
| 1915 | struct drm_atomic_state *state; |
| 1916 | struct drm_connector *conn; |
| 1917 | int err; |
| 1918 | |
| 1919 | state = drm_atomic_state_alloc(dev); |
| 1920 | if (!state) |
| 1921 | return -ENOMEM; |
| 1922 | |
| 1923 | state->acquire_ctx = ctx; |
| 1924 | |
| 1925 | drm_for_each_connector(conn, dev) { |
| 1926 | struct drm_crtc *crtc = conn->state->crtc; |
| 1927 | struct drm_crtc_state *crtc_state; |
| 1928 | |
| 1929 | if (!crtc || conn->dpms != DRM_MODE_DPMS_ON) |
| 1930 | continue; |
| 1931 | |
| 1932 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 1933 | if (IS_ERR(crtc_state)) { |
| 1934 | err = PTR_ERR(crtc_state); |
| 1935 | goto free; |
| 1936 | } |
| 1937 | |
| 1938 | crtc_state->active = false; |
| 1939 | } |
| 1940 | |
| 1941 | err = drm_atomic_commit(state); |
| 1942 | |
| 1943 | free: |
| 1944 | if (err < 0) |
| 1945 | drm_atomic_state_free(state); |
| 1946 | |
| 1947 | return err; |
| 1948 | } |
| 1949 | EXPORT_SYMBOL(drm_atomic_helper_disable_all); |
| 1950 | |
| 1951 | /** |
| 1952 | * drm_atomic_helper_suspend - subsystem-level suspend helper |
| 1953 | * @dev: DRM device |
| 1954 | * |
| 1955 | * Duplicates the current atomic state, disables all active outputs and then |
| 1956 | * returns a pointer to the original atomic state to the caller. Drivers can |
| 1957 | * pass this pointer to the drm_atomic_helper_resume() helper upon resume to |
| 1958 | * restore the output configuration that was active at the time the system |
| 1959 | * entered suspend. |
| 1960 | * |
| 1961 | * Note that it is potentially unsafe to use this. The atomic state object |
| 1962 | * returned by this function is assumed to be persistent. Drivers must ensure |
| 1963 | * that this holds true. Before calling this function, drivers must make sure |
| 1964 | * to suspend fbdev emulation so that nothing can be using the device. |
| 1965 | * |
| 1966 | * Returns: |
| 1967 | * A pointer to a copy of the state before suspend on success or an ERR_PTR()- |
| 1968 | * encoded error code on failure. Drivers should store the returned atomic |
| 1969 | * state object and pass it to the drm_atomic_helper_resume() helper upon |
| 1970 | * resume. |
| 1971 | * |
| 1972 | * See also: |
| 1973 | * drm_atomic_helper_duplicate_state(), drm_atomic_helper_disable_all(), |
| 1974 | * drm_atomic_helper_resume() |
| 1975 | */ |
| 1976 | struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev) |
| 1977 | { |
| 1978 | struct drm_modeset_acquire_ctx ctx; |
| 1979 | struct drm_atomic_state *state; |
| 1980 | int err; |
| 1981 | |
| 1982 | drm_modeset_acquire_init(&ctx, 0); |
| 1983 | |
| 1984 | retry: |
| 1985 | err = drm_modeset_lock_all_ctx(dev, &ctx); |
| 1986 | if (err < 0) { |
| 1987 | state = ERR_PTR(err); |
| 1988 | goto unlock; |
| 1989 | } |
| 1990 | |
| 1991 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 1992 | if (IS_ERR(state)) |
| 1993 | goto unlock; |
| 1994 | |
| 1995 | err = drm_atomic_helper_disable_all(dev, &ctx); |
| 1996 | if (err < 0) { |
| 1997 | drm_atomic_state_free(state); |
| 1998 | state = ERR_PTR(err); |
| 1999 | goto unlock; |
| 2000 | } |
| 2001 | |
| 2002 | unlock: |
| 2003 | if (PTR_ERR(state) == -EDEADLK) { |
| 2004 | drm_modeset_backoff(&ctx); |
| 2005 | goto retry; |
| 2006 | } |
| 2007 | |
| 2008 | drm_modeset_drop_locks(&ctx); |
| 2009 | drm_modeset_acquire_fini(&ctx); |
| 2010 | return state; |
| 2011 | } |
| 2012 | EXPORT_SYMBOL(drm_atomic_helper_suspend); |
| 2013 | |
| 2014 | /** |
| 2015 | * drm_atomic_helper_resume - subsystem-level resume helper |
| 2016 | * @dev: DRM device |
| 2017 | * @state: atomic state to resume to |
| 2018 | * |
| 2019 | * Calls drm_mode_config_reset() to synchronize hardware and software states, |
| 2020 | * grabs all modeset locks and commits the atomic state object. This can be |
| 2021 | * used in conjunction with the drm_atomic_helper_suspend() helper to |
| 2022 | * implement suspend/resume for drivers that support atomic mode-setting. |
| 2023 | * |
| 2024 | * Returns: |
| 2025 | * 0 on success or a negative error code on failure. |
| 2026 | * |
| 2027 | * See also: |
| 2028 | * drm_atomic_helper_suspend() |
| 2029 | */ |
| 2030 | int drm_atomic_helper_resume(struct drm_device *dev, |
| 2031 | struct drm_atomic_state *state) |
| 2032 | { |
| 2033 | struct drm_mode_config *config = &dev->mode_config; |
| 2034 | int err; |
| 2035 | |
| 2036 | drm_mode_config_reset(dev); |
| 2037 | drm_modeset_lock_all(dev); |
| 2038 | state->acquire_ctx = config->acquire_ctx; |
| 2039 | err = drm_atomic_commit(state); |
| 2040 | drm_modeset_unlock_all(dev); |
| 2041 | |
| 2042 | return err; |
| 2043 | } |
| 2044 | EXPORT_SYMBOL(drm_atomic_helper_resume); |
| 2045 | |
| 2046 | /** |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 2047 | * drm_atomic_helper_crtc_set_property - helper for crtc properties |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2048 | * @crtc: DRM crtc |
| 2049 | * @property: DRM property |
| 2050 | * @val: value of property |
| 2051 | * |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 2052 | * Provides a default crtc set_property handler using the atomic driver |
| 2053 | * interface. |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2054 | * |
| 2055 | * RETURNS: |
| 2056 | * Zero on success, error code on failure |
| 2057 | */ |
| 2058 | int |
| 2059 | drm_atomic_helper_crtc_set_property(struct drm_crtc *crtc, |
| 2060 | struct drm_property *property, |
| 2061 | uint64_t val) |
| 2062 | { |
| 2063 | struct drm_atomic_state *state; |
| 2064 | struct drm_crtc_state *crtc_state; |
| 2065 | int ret = 0; |
| 2066 | |
| 2067 | state = drm_atomic_state_alloc(crtc->dev); |
| 2068 | if (!state) |
| 2069 | return -ENOMEM; |
| 2070 | |
| 2071 | /* ->set_property is always called with all locks held. */ |
| 2072 | state->acquire_ctx = crtc->dev->mode_config.acquire_ctx; |
| 2073 | retry: |
| 2074 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 2075 | if (IS_ERR(crtc_state)) { |
| 2076 | ret = PTR_ERR(crtc_state); |
| 2077 | goto fail; |
| 2078 | } |
| 2079 | |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 2080 | ret = drm_atomic_crtc_set_property(crtc, crtc_state, |
| 2081 | property, val); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2082 | if (ret) |
| 2083 | goto fail; |
| 2084 | |
| 2085 | ret = drm_atomic_commit(state); |
| 2086 | if (ret != 0) |
| 2087 | goto fail; |
| 2088 | |
| 2089 | /* Driver takes ownership of state on successful commit. */ |
| 2090 | return 0; |
| 2091 | fail: |
| 2092 | if (ret == -EDEADLK) |
| 2093 | goto backoff; |
| 2094 | |
| 2095 | drm_atomic_state_free(state); |
| 2096 | |
| 2097 | return ret; |
| 2098 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2099 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 2100 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2101 | |
| 2102 | goto retry; |
| 2103 | } |
| 2104 | EXPORT_SYMBOL(drm_atomic_helper_crtc_set_property); |
| 2105 | |
| 2106 | /** |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 2107 | * drm_atomic_helper_plane_set_property - helper for plane properties |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2108 | * @plane: DRM plane |
| 2109 | * @property: DRM property |
| 2110 | * @val: value of property |
| 2111 | * |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 2112 | * Provides a default plane set_property handler using the atomic driver |
| 2113 | * interface. |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2114 | * |
| 2115 | * RETURNS: |
| 2116 | * Zero on success, error code on failure |
| 2117 | */ |
| 2118 | int |
| 2119 | drm_atomic_helper_plane_set_property(struct drm_plane *plane, |
| 2120 | struct drm_property *property, |
| 2121 | uint64_t val) |
| 2122 | { |
| 2123 | struct drm_atomic_state *state; |
| 2124 | struct drm_plane_state *plane_state; |
| 2125 | int ret = 0; |
| 2126 | |
| 2127 | state = drm_atomic_state_alloc(plane->dev); |
| 2128 | if (!state) |
| 2129 | return -ENOMEM; |
| 2130 | |
| 2131 | /* ->set_property is always called with all locks held. */ |
| 2132 | state->acquire_ctx = plane->dev->mode_config.acquire_ctx; |
| 2133 | retry: |
| 2134 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 2135 | if (IS_ERR(plane_state)) { |
| 2136 | ret = PTR_ERR(plane_state); |
| 2137 | goto fail; |
| 2138 | } |
| 2139 | |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 2140 | ret = drm_atomic_plane_set_property(plane, plane_state, |
| 2141 | property, val); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2142 | if (ret) |
| 2143 | goto fail; |
| 2144 | |
| 2145 | ret = drm_atomic_commit(state); |
| 2146 | if (ret != 0) |
| 2147 | goto fail; |
| 2148 | |
| 2149 | /* Driver takes ownership of state on successful commit. */ |
| 2150 | return 0; |
| 2151 | fail: |
| 2152 | if (ret == -EDEADLK) |
| 2153 | goto backoff; |
| 2154 | |
| 2155 | drm_atomic_state_free(state); |
| 2156 | |
| 2157 | return ret; |
| 2158 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2159 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 2160 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2161 | |
| 2162 | goto retry; |
| 2163 | } |
| 2164 | EXPORT_SYMBOL(drm_atomic_helper_plane_set_property); |
| 2165 | |
| 2166 | /** |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 2167 | * drm_atomic_helper_connector_set_property - helper for connector properties |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2168 | * @connector: DRM connector |
| 2169 | * @property: DRM property |
| 2170 | * @val: value of property |
| 2171 | * |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 2172 | * Provides a default connector set_property handler using the atomic driver |
| 2173 | * interface. |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2174 | * |
| 2175 | * RETURNS: |
| 2176 | * Zero on success, error code on failure |
| 2177 | */ |
| 2178 | int |
| 2179 | drm_atomic_helper_connector_set_property(struct drm_connector *connector, |
| 2180 | struct drm_property *property, |
| 2181 | uint64_t val) |
| 2182 | { |
| 2183 | struct drm_atomic_state *state; |
| 2184 | struct drm_connector_state *connector_state; |
| 2185 | int ret = 0; |
| 2186 | |
| 2187 | state = drm_atomic_state_alloc(connector->dev); |
| 2188 | if (!state) |
| 2189 | return -ENOMEM; |
| 2190 | |
| 2191 | /* ->set_property is always called with all locks held. */ |
| 2192 | state->acquire_ctx = connector->dev->mode_config.acquire_ctx; |
| 2193 | retry: |
| 2194 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 2195 | if (IS_ERR(connector_state)) { |
| 2196 | ret = PTR_ERR(connector_state); |
| 2197 | goto fail; |
| 2198 | } |
| 2199 | |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 2200 | ret = drm_atomic_connector_set_property(connector, connector_state, |
| 2201 | property, val); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2202 | if (ret) |
| 2203 | goto fail; |
| 2204 | |
| 2205 | ret = drm_atomic_commit(state); |
| 2206 | if (ret != 0) |
| 2207 | goto fail; |
| 2208 | |
| 2209 | /* Driver takes ownership of state on successful commit. */ |
| 2210 | return 0; |
| 2211 | fail: |
| 2212 | if (ret == -EDEADLK) |
| 2213 | goto backoff; |
| 2214 | |
| 2215 | drm_atomic_state_free(state); |
| 2216 | |
| 2217 | return ret; |
| 2218 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2219 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 2220 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2221 | |
| 2222 | goto retry; |
| 2223 | } |
| 2224 | EXPORT_SYMBOL(drm_atomic_helper_connector_set_property); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2225 | |
| 2226 | /** |
| 2227 | * drm_atomic_helper_page_flip - execute a legacy page flip |
| 2228 | * @crtc: DRM crtc |
| 2229 | * @fb: DRM framebuffer |
| 2230 | * @event: optional DRM event to signal upon completion |
| 2231 | * @flags: flip flags for non-vblank sync'ed updates |
| 2232 | * |
| 2233 | * Provides a default page flip implementation using the atomic driver interface. |
| 2234 | * |
| 2235 | * Note that for now so called async page flips (i.e. updates which are not |
| 2236 | * synchronized to vblank) are not supported, since the atomic interfaces have |
| 2237 | * no provisions for this yet. |
| 2238 | * |
| 2239 | * Returns: |
| 2240 | * Returns 0 on success, negative errno numbers on failure. |
| 2241 | */ |
| 2242 | int drm_atomic_helper_page_flip(struct drm_crtc *crtc, |
| 2243 | struct drm_framebuffer *fb, |
| 2244 | struct drm_pending_vblank_event *event, |
| 2245 | uint32_t flags) |
| 2246 | { |
| 2247 | struct drm_plane *plane = crtc->primary; |
| 2248 | struct drm_atomic_state *state; |
| 2249 | struct drm_plane_state *plane_state; |
| 2250 | struct drm_crtc_state *crtc_state; |
| 2251 | int ret = 0; |
| 2252 | |
| 2253 | if (flags & DRM_MODE_PAGE_FLIP_ASYNC) |
| 2254 | return -EINVAL; |
| 2255 | |
| 2256 | state = drm_atomic_state_alloc(plane->dev); |
| 2257 | if (!state) |
| 2258 | return -ENOMEM; |
| 2259 | |
| 2260 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 2261 | retry: |
| 2262 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 2263 | if (IS_ERR(crtc_state)) { |
| 2264 | ret = PTR_ERR(crtc_state); |
| 2265 | goto fail; |
| 2266 | } |
| 2267 | crtc_state->event = event; |
| 2268 | |
| 2269 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 2270 | if (IS_ERR(plane_state)) { |
| 2271 | ret = PTR_ERR(plane_state); |
| 2272 | goto fail; |
| 2273 | } |
| 2274 | |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 2275 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2276 | if (ret != 0) |
| 2277 | goto fail; |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 2278 | drm_atomic_set_fb_for_plane(plane_state, fb); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2279 | |
| 2280 | ret = drm_atomic_async_commit(state); |
| 2281 | if (ret != 0) |
| 2282 | goto fail; |
| 2283 | |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2284 | /* Driver takes ownership of state on successful async commit. */ |
| 2285 | return 0; |
| 2286 | fail: |
| 2287 | if (ret == -EDEADLK) |
| 2288 | goto backoff; |
| 2289 | |
| 2290 | drm_atomic_state_free(state); |
| 2291 | |
| 2292 | return ret; |
| 2293 | backoff: |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2294 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 2295 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2296 | |
| 2297 | /* |
| 2298 | * Someone might have exchanged the framebuffer while we dropped locks |
| 2299 | * in the backoff code. We need to fix up the fb refcount tracking the |
| 2300 | * core does for us. |
| 2301 | */ |
| 2302 | plane->old_fb = plane->fb; |
| 2303 | |
| 2304 | goto retry; |
| 2305 | } |
| 2306 | EXPORT_SYMBOL(drm_atomic_helper_page_flip); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2307 | |
| 2308 | /** |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2309 | * drm_atomic_helper_connector_dpms() - connector dpms helper implementation |
| 2310 | * @connector: affected connector |
| 2311 | * @mode: DPMS mode |
| 2312 | * |
| 2313 | * This is the main helper function provided by the atomic helper framework for |
| 2314 | * implementing the legacy DPMS connector interface. It computes the new desired |
| 2315 | * ->active state for the corresponding CRTC (if the connector is enabled) and |
| 2316 | * updates it. |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2317 | * |
| 2318 | * Returns: |
| 2319 | * Returns 0 on success, negative errno numbers on failure. |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2320 | */ |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2321 | int drm_atomic_helper_connector_dpms(struct drm_connector *connector, |
| 2322 | int mode) |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2323 | { |
| 2324 | struct drm_mode_config *config = &connector->dev->mode_config; |
| 2325 | struct drm_atomic_state *state; |
| 2326 | struct drm_crtc_state *crtc_state; |
| 2327 | struct drm_crtc *crtc; |
| 2328 | struct drm_connector *tmp_connector; |
| 2329 | int ret; |
| 2330 | bool active = false; |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2331 | int old_mode = connector->dpms; |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2332 | |
| 2333 | if (mode != DRM_MODE_DPMS_ON) |
| 2334 | mode = DRM_MODE_DPMS_OFF; |
| 2335 | |
| 2336 | connector->dpms = mode; |
| 2337 | crtc = connector->state->crtc; |
| 2338 | |
| 2339 | if (!crtc) |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2340 | return 0; |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2341 | |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2342 | state = drm_atomic_state_alloc(connector->dev); |
| 2343 | if (!state) |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2344 | return -ENOMEM; |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2345 | |
| 2346 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 2347 | retry: |
| 2348 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2349 | if (IS_ERR(crtc_state)) { |
| 2350 | ret = PTR_ERR(crtc_state); |
| 2351 | goto fail; |
| 2352 | } |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2353 | |
| 2354 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
| 2355 | |
Daniel Vetter | 9a9f5ce | 2015-07-09 23:44:34 +0200 | [diff] [blame] | 2356 | drm_for_each_connector(tmp_connector, connector->dev) { |
John Hunter | 0388df0 | 2015-03-17 15:30:28 +0800 | [diff] [blame] | 2357 | if (tmp_connector->state->crtc != crtc) |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2358 | continue; |
| 2359 | |
John Hunter | 0388df0 | 2015-03-17 15:30:28 +0800 | [diff] [blame] | 2360 | if (tmp_connector->dpms == DRM_MODE_DPMS_ON) { |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2361 | active = true; |
| 2362 | break; |
| 2363 | } |
| 2364 | } |
| 2365 | crtc_state->active = active; |
| 2366 | |
| 2367 | ret = drm_atomic_commit(state); |
| 2368 | if (ret != 0) |
| 2369 | goto fail; |
| 2370 | |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2371 | /* Driver takes ownership of state on successful commit. */ |
| 2372 | return 0; |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2373 | fail: |
| 2374 | if (ret == -EDEADLK) |
| 2375 | goto backoff; |
| 2376 | |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2377 | connector->dpms = old_mode; |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2378 | drm_atomic_state_free(state); |
| 2379 | |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2380 | return ret; |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2381 | backoff: |
| 2382 | drm_atomic_state_clear(state); |
| 2383 | drm_atomic_legacy_backoff(state); |
| 2384 | |
| 2385 | goto retry; |
| 2386 | } |
| 2387 | EXPORT_SYMBOL(drm_atomic_helper_connector_dpms); |
| 2388 | |
| 2389 | /** |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 2390 | * DOC: atomic state reset and initialization |
| 2391 | * |
| 2392 | * Both the drm core and the atomic helpers assume that there is always the full |
| 2393 | * and correct atomic software state for all connectors, CRTCs and planes |
| 2394 | * available. Which is a bit a problem on driver load and also after system |
| 2395 | * suspend. One way to solve this is to have a hardware state read-out |
| 2396 | * infrastructure which reconstructs the full software state (e.g. the i915 |
| 2397 | * driver). |
| 2398 | * |
| 2399 | * The simpler solution is to just reset the software state to everything off, |
| 2400 | * which is easiest to do by calling drm_mode_config_reset(). To facilitate this |
| 2401 | * the atomic helpers provide default reset implementations for all hooks. |
| 2402 | */ |
| 2403 | |
| 2404 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2405 | * drm_atomic_helper_crtc_reset - default ->reset hook for CRTCs |
| 2406 | * @crtc: drm CRTC |
| 2407 | * |
| 2408 | * Resets the atomic state for @crtc by freeing the state pointer (which might |
| 2409 | * be NULL, e.g. at driver load time) and allocating a new empty state object. |
| 2410 | */ |
| 2411 | void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc) |
| 2412 | { |
Markus Elfring | 5f91190 | 2015-11-06 12:03:46 +0100 | [diff] [blame] | 2413 | if (crtc->state) |
Daniel Stone | 99cf4a2 | 2015-05-25 19:11:51 +0100 | [diff] [blame] | 2414 | drm_property_unreference_blob(crtc->state->mode_blob); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2415 | kfree(crtc->state); |
| 2416 | crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL); |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 2417 | |
| 2418 | if (crtc->state) |
| 2419 | crtc->state->crtc = crtc; |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2420 | } |
| 2421 | EXPORT_SYMBOL(drm_atomic_helper_crtc_reset); |
| 2422 | |
| 2423 | /** |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2424 | * __drm_atomic_helper_crtc_duplicate_state - copy atomic CRTC state |
| 2425 | * @crtc: CRTC object |
| 2426 | * @state: atomic CRTC state |
| 2427 | * |
| 2428 | * Copies atomic state from a CRTC's current state and resets inferred values. |
| 2429 | * This is useful for drivers that subclass the CRTC state. |
| 2430 | */ |
| 2431 | void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc, |
| 2432 | struct drm_crtc_state *state) |
| 2433 | { |
| 2434 | memcpy(state, crtc->state, sizeof(*state)); |
| 2435 | |
Daniel Stone | 99cf4a2 | 2015-05-25 19:11:51 +0100 | [diff] [blame] | 2436 | if (state->mode_blob) |
| 2437 | drm_property_reference_blob(state->mode_blob); |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2438 | state->mode_changed = false; |
| 2439 | state->active_changed = false; |
| 2440 | state->planes_changed = false; |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 2441 | state->connectors_changed = false; |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2442 | state->event = NULL; |
| 2443 | } |
| 2444 | EXPORT_SYMBOL(__drm_atomic_helper_crtc_duplicate_state); |
| 2445 | |
| 2446 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2447 | * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook |
| 2448 | * @crtc: drm CRTC |
| 2449 | * |
| 2450 | * Default CRTC state duplicate hook for drivers which don't have their own |
| 2451 | * subclassed CRTC state structure. |
| 2452 | */ |
| 2453 | struct drm_crtc_state * |
| 2454 | drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc) |
| 2455 | { |
| 2456 | struct drm_crtc_state *state; |
| 2457 | |
| 2458 | if (WARN_ON(!crtc->state)) |
| 2459 | return NULL; |
| 2460 | |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2461 | state = kmalloc(sizeof(*state), GFP_KERNEL); |
| 2462 | if (state) |
| 2463 | __drm_atomic_helper_crtc_duplicate_state(crtc, state); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2464 | |
| 2465 | return state; |
| 2466 | } |
| 2467 | EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state); |
| 2468 | |
| 2469 | /** |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2470 | * __drm_atomic_helper_crtc_destroy_state - release CRTC state |
| 2471 | * @crtc: CRTC object |
| 2472 | * @state: CRTC state object to release |
| 2473 | * |
| 2474 | * Releases all resources stored in the CRTC state without actually freeing |
| 2475 | * the memory of the CRTC state. This is useful for drivers that subclass the |
| 2476 | * CRTC state. |
| 2477 | */ |
| 2478 | void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc, |
| 2479 | struct drm_crtc_state *state) |
| 2480 | { |
Markus Elfring | 5f91190 | 2015-11-06 12:03:46 +0100 | [diff] [blame] | 2481 | drm_property_unreference_blob(state->mode_blob); |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2482 | } |
| 2483 | EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state); |
| 2484 | |
| 2485 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2486 | * drm_atomic_helper_crtc_destroy_state - default state destroy hook |
| 2487 | * @crtc: drm CRTC |
| 2488 | * @state: CRTC state object to release |
| 2489 | * |
| 2490 | * Default CRTC state destroy hook for drivers which don't have their own |
| 2491 | * subclassed CRTC state structure. |
| 2492 | */ |
| 2493 | void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc, |
| 2494 | struct drm_crtc_state *state) |
| 2495 | { |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2496 | __drm_atomic_helper_crtc_destroy_state(crtc, state); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2497 | kfree(state); |
| 2498 | } |
| 2499 | EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state); |
| 2500 | |
| 2501 | /** |
| 2502 | * drm_atomic_helper_plane_reset - default ->reset hook for planes |
| 2503 | * @plane: drm plane |
| 2504 | * |
| 2505 | * Resets the atomic state for @plane by freeing the state pointer (which might |
| 2506 | * be NULL, e.g. at driver load time) and allocating a new empty state object. |
| 2507 | */ |
| 2508 | void drm_atomic_helper_plane_reset(struct drm_plane *plane) |
| 2509 | { |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 2510 | if (plane->state && plane->state->fb) |
| 2511 | drm_framebuffer_unreference(plane->state->fb); |
| 2512 | |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2513 | kfree(plane->state); |
| 2514 | plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL); |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 2515 | |
| 2516 | if (plane->state) |
| 2517 | plane->state->plane = plane; |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2518 | } |
| 2519 | EXPORT_SYMBOL(drm_atomic_helper_plane_reset); |
| 2520 | |
| 2521 | /** |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2522 | * __drm_atomic_helper_plane_duplicate_state - copy atomic plane state |
| 2523 | * @plane: plane object |
| 2524 | * @state: atomic plane state |
| 2525 | * |
| 2526 | * Copies atomic state from a plane's current state. This is useful for |
| 2527 | * drivers that subclass the plane state. |
| 2528 | */ |
| 2529 | void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane, |
| 2530 | struct drm_plane_state *state) |
| 2531 | { |
| 2532 | memcpy(state, plane->state, sizeof(*state)); |
| 2533 | |
| 2534 | if (state->fb) |
| 2535 | drm_framebuffer_reference(state->fb); |
| 2536 | } |
| 2537 | EXPORT_SYMBOL(__drm_atomic_helper_plane_duplicate_state); |
| 2538 | |
| 2539 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2540 | * drm_atomic_helper_plane_duplicate_state - default state duplicate hook |
| 2541 | * @plane: drm plane |
| 2542 | * |
| 2543 | * Default plane state duplicate hook for drivers which don't have their own |
| 2544 | * subclassed plane state structure. |
| 2545 | */ |
| 2546 | struct drm_plane_state * |
| 2547 | drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane) |
| 2548 | { |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 2549 | struct drm_plane_state *state; |
| 2550 | |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2551 | if (WARN_ON(!plane->state)) |
| 2552 | return NULL; |
| 2553 | |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2554 | state = kmalloc(sizeof(*state), GFP_KERNEL); |
| 2555 | if (state) |
| 2556 | __drm_atomic_helper_plane_duplicate_state(plane, state); |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 2557 | |
| 2558 | return state; |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2559 | } |
| 2560 | EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state); |
| 2561 | |
| 2562 | /** |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2563 | * __drm_atomic_helper_plane_destroy_state - release plane state |
| 2564 | * @plane: plane object |
| 2565 | * @state: plane state object to release |
| 2566 | * |
| 2567 | * Releases all resources stored in the plane state without actually freeing |
| 2568 | * the memory of the plane state. This is useful for drivers that subclass the |
| 2569 | * plane state. |
| 2570 | */ |
| 2571 | void __drm_atomic_helper_plane_destroy_state(struct drm_plane *plane, |
| 2572 | struct drm_plane_state *state) |
| 2573 | { |
| 2574 | if (state->fb) |
| 2575 | drm_framebuffer_unreference(state->fb); |
| 2576 | } |
| 2577 | EXPORT_SYMBOL(__drm_atomic_helper_plane_destroy_state); |
| 2578 | |
| 2579 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2580 | * drm_atomic_helper_plane_destroy_state - default state destroy hook |
| 2581 | * @plane: drm plane |
| 2582 | * @state: plane state object to release |
| 2583 | * |
| 2584 | * Default plane state destroy hook for drivers which don't have their own |
| 2585 | * subclassed plane state structure. |
| 2586 | */ |
| 2587 | void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane, |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 2588 | struct drm_plane_state *state) |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2589 | { |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2590 | __drm_atomic_helper_plane_destroy_state(plane, state); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2591 | kfree(state); |
| 2592 | } |
| 2593 | EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state); |
| 2594 | |
| 2595 | /** |
| 2596 | * drm_atomic_helper_connector_reset - default ->reset hook for connectors |
| 2597 | * @connector: drm connector |
| 2598 | * |
| 2599 | * Resets the atomic state for @connector by freeing the state pointer (which |
| 2600 | * might be NULL, e.g. at driver load time) and allocating a new empty state |
| 2601 | * object. |
| 2602 | */ |
| 2603 | void drm_atomic_helper_connector_reset(struct drm_connector *connector) |
| 2604 | { |
| 2605 | kfree(connector->state); |
| 2606 | connector->state = kzalloc(sizeof(*connector->state), GFP_KERNEL); |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 2607 | |
| 2608 | if (connector->state) |
| 2609 | connector->state->connector = connector; |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2610 | } |
| 2611 | EXPORT_SYMBOL(drm_atomic_helper_connector_reset); |
| 2612 | |
| 2613 | /** |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2614 | * __drm_atomic_helper_connector_duplicate_state - copy atomic connector state |
| 2615 | * @connector: connector object |
| 2616 | * @state: atomic connector state |
| 2617 | * |
| 2618 | * Copies atomic state from a connector's current state. This is useful for |
| 2619 | * drivers that subclass the connector state. |
| 2620 | */ |
| 2621 | void |
| 2622 | __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector, |
| 2623 | struct drm_connector_state *state) |
| 2624 | { |
| 2625 | memcpy(state, connector->state, sizeof(*state)); |
| 2626 | } |
| 2627 | EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state); |
| 2628 | |
| 2629 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2630 | * drm_atomic_helper_connector_duplicate_state - default state duplicate hook |
| 2631 | * @connector: drm connector |
| 2632 | * |
| 2633 | * Default connector state duplicate hook for drivers which don't have their own |
| 2634 | * subclassed connector state structure. |
| 2635 | */ |
| 2636 | struct drm_connector_state * |
| 2637 | drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector) |
| 2638 | { |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2639 | struct drm_connector_state *state; |
| 2640 | |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2641 | if (WARN_ON(!connector->state)) |
| 2642 | return NULL; |
| 2643 | |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2644 | state = kmalloc(sizeof(*state), GFP_KERNEL); |
| 2645 | if (state) |
| 2646 | __drm_atomic_helper_connector_duplicate_state(connector, state); |
| 2647 | |
| 2648 | return state; |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2649 | } |
| 2650 | EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state); |
| 2651 | |
| 2652 | /** |
Thierry Reding | 397fd77 | 2015-09-08 15:00:45 +0200 | [diff] [blame] | 2653 | * drm_atomic_helper_duplicate_state - duplicate an atomic state object |
| 2654 | * @dev: DRM device |
| 2655 | * @ctx: lock acquisition context |
| 2656 | * |
| 2657 | * 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] | 2658 | * duplicating their respective states. This is used for example by suspend/ |
| 2659 | * resume support code to save the state prior to suspend such that it can |
| 2660 | * be restored upon resume. |
Thierry Reding | 397fd77 | 2015-09-08 15:00:45 +0200 | [diff] [blame] | 2661 | * |
| 2662 | * Note that this treats atomic state as persistent between save and restore. |
| 2663 | * Drivers must make sure that this is possible and won't result in confusion |
| 2664 | * or erroneous behaviour. |
| 2665 | * |
| 2666 | * Note that if callers haven't already acquired all modeset locks this might |
| 2667 | * return -EDEADLK, which must be handled by calling drm_modeset_backoff(). |
| 2668 | * |
| 2669 | * Returns: |
| 2670 | * A pointer to the copy of the atomic state object on success or an |
| 2671 | * ERR_PTR()-encoded error code on failure. |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 2672 | * |
| 2673 | * See also: |
| 2674 | * drm_atomic_helper_suspend(), drm_atomic_helper_resume() |
Thierry Reding | 397fd77 | 2015-09-08 15:00:45 +0200 | [diff] [blame] | 2675 | */ |
| 2676 | struct drm_atomic_state * |
| 2677 | drm_atomic_helper_duplicate_state(struct drm_device *dev, |
| 2678 | struct drm_modeset_acquire_ctx *ctx) |
| 2679 | { |
| 2680 | struct drm_atomic_state *state; |
| 2681 | struct drm_connector *conn; |
| 2682 | struct drm_plane *plane; |
| 2683 | struct drm_crtc *crtc; |
| 2684 | int err = 0; |
| 2685 | |
| 2686 | state = drm_atomic_state_alloc(dev); |
| 2687 | if (!state) |
| 2688 | return ERR_PTR(-ENOMEM); |
| 2689 | |
| 2690 | state->acquire_ctx = ctx; |
| 2691 | |
| 2692 | drm_for_each_crtc(crtc, dev) { |
| 2693 | struct drm_crtc_state *crtc_state; |
| 2694 | |
| 2695 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 2696 | if (IS_ERR(crtc_state)) { |
| 2697 | err = PTR_ERR(crtc_state); |
| 2698 | goto free; |
| 2699 | } |
| 2700 | } |
| 2701 | |
| 2702 | drm_for_each_plane(plane, dev) { |
| 2703 | struct drm_plane_state *plane_state; |
| 2704 | |
| 2705 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 2706 | if (IS_ERR(plane_state)) { |
| 2707 | err = PTR_ERR(plane_state); |
| 2708 | goto free; |
| 2709 | } |
| 2710 | } |
| 2711 | |
| 2712 | drm_for_each_connector(conn, dev) { |
| 2713 | struct drm_connector_state *conn_state; |
| 2714 | |
| 2715 | conn_state = drm_atomic_get_connector_state(state, conn); |
| 2716 | if (IS_ERR(conn_state)) { |
| 2717 | err = PTR_ERR(conn_state); |
| 2718 | goto free; |
| 2719 | } |
| 2720 | } |
| 2721 | |
| 2722 | /* clear the acquire context so that it isn't accidentally reused */ |
| 2723 | state->acquire_ctx = NULL; |
| 2724 | |
| 2725 | free: |
| 2726 | if (err < 0) { |
| 2727 | drm_atomic_state_free(state); |
| 2728 | state = ERR_PTR(err); |
| 2729 | } |
| 2730 | |
| 2731 | return state; |
| 2732 | } |
| 2733 | EXPORT_SYMBOL(drm_atomic_helper_duplicate_state); |
| 2734 | |
| 2735 | /** |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2736 | * __drm_atomic_helper_connector_destroy_state - release connector state |
| 2737 | * @connector: connector object |
| 2738 | * @state: connector state object to release |
| 2739 | * |
| 2740 | * Releases all resources stored in the connector state without actually |
| 2741 | * freeing the memory of the connector state. This is useful for drivers that |
| 2742 | * subclass the connector state. |
| 2743 | */ |
| 2744 | void |
| 2745 | __drm_atomic_helper_connector_destroy_state(struct drm_connector *connector, |
| 2746 | struct drm_connector_state *state) |
| 2747 | { |
| 2748 | /* |
| 2749 | * This is currently a placeholder so that drivers that subclass the |
| 2750 | * state will automatically do the right thing if code is ever added |
| 2751 | * to this function. |
| 2752 | */ |
| 2753 | } |
| 2754 | EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state); |
| 2755 | |
| 2756 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2757 | * drm_atomic_helper_connector_destroy_state - default state destroy hook |
| 2758 | * @connector: drm connector |
| 2759 | * @state: connector state object to release |
| 2760 | * |
| 2761 | * Default connector state destroy hook for drivers which don't have their own |
| 2762 | * subclassed connector state structure. |
| 2763 | */ |
| 2764 | void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector, |
| 2765 | struct drm_connector_state *state) |
| 2766 | { |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2767 | __drm_atomic_helper_connector_destroy_state(connector, state); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2768 | kfree(state); |
| 2769 | } |
| 2770 | EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state); |