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 |
| 45 | * drm_atomic_helper_check and for the commit callback with |
| 46 | * drm_atomic_helper_commit. But the individual stages and callbacks are expose |
| 47 | * to allow drivers to mix and match and e.g. use the plane helpers only |
| 48 | * together with a driver private modeset implementation. |
| 49 | * |
| 50 | * This library also provides implementations for all the legacy driver |
| 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 |
| 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 | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 83 | static struct drm_crtc * |
| 84 | get_current_crtc_for_encoder(struct drm_device *dev, |
| 85 | struct drm_encoder *encoder) |
| 86 | { |
| 87 | struct drm_mode_config *config = &dev->mode_config; |
| 88 | struct drm_connector *connector; |
| 89 | |
| 90 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
| 91 | |
| 92 | list_for_each_entry(connector, &config->connector_list, head) { |
| 93 | if (connector->state->best_encoder != encoder) |
| 94 | continue; |
| 95 | |
| 96 | return connector->state->crtc; |
| 97 | } |
| 98 | |
| 99 | return NULL; |
| 100 | } |
| 101 | |
| 102 | static int |
| 103 | steal_encoder(struct drm_atomic_state *state, |
| 104 | struct drm_encoder *encoder, |
| 105 | struct drm_crtc *encoder_crtc) |
| 106 | { |
| 107 | struct drm_mode_config *config = &state->dev->mode_config; |
| 108 | struct drm_crtc_state *crtc_state; |
| 109 | struct drm_connector *connector; |
| 110 | struct drm_connector_state *connector_state; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 111 | int ret; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * We can only steal an encoder coming from a connector, which means we |
| 115 | * must already hold the connection_mutex. |
| 116 | */ |
| 117 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
| 118 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 119 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d], stealing it\n", |
| 120 | encoder->base.id, encoder->name, |
| 121 | encoder_crtc->base.id); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 122 | |
| 123 | crtc_state = drm_atomic_get_crtc_state(state, encoder_crtc); |
| 124 | if (IS_ERR(crtc_state)) |
| 125 | return PTR_ERR(crtc_state); |
| 126 | |
| 127 | crtc_state->mode_changed = true; |
| 128 | |
| 129 | list_for_each_entry(connector, &config->connector_list, head) { |
| 130 | if (connector->state->best_encoder != encoder) |
| 131 | continue; |
| 132 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 133 | DRM_DEBUG_ATOMIC("Stealing encoder from [CONNECTOR:%d:%s]\n", |
| 134 | connector->base.id, |
| 135 | connector->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 136 | |
| 137 | connector_state = drm_atomic_get_connector_state(state, |
| 138 | connector); |
| 139 | if (IS_ERR(connector_state)) |
| 140 | return PTR_ERR(connector_state); |
| 141 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 142 | ret = drm_atomic_set_crtc_for_connector(connector_state, NULL); |
| 143 | if (ret) |
| 144 | return ret; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 145 | connector_state->best_encoder = NULL; |
| 146 | } |
| 147 | |
| 148 | return 0; |
| 149 | } |
| 150 | |
| 151 | static int |
| 152 | update_connector_routing(struct drm_atomic_state *state, int conn_idx) |
| 153 | { |
| 154 | struct drm_connector_helper_funcs *funcs; |
| 155 | struct drm_encoder *new_encoder; |
| 156 | struct drm_crtc *encoder_crtc; |
| 157 | struct drm_connector *connector; |
| 158 | struct drm_connector_state *connector_state; |
| 159 | struct drm_crtc_state *crtc_state; |
| 160 | int idx, ret; |
| 161 | |
| 162 | connector = state->connectors[conn_idx]; |
| 163 | connector_state = state->connector_states[conn_idx]; |
| 164 | |
| 165 | if (!connector) |
| 166 | return 0; |
| 167 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 168 | DRM_DEBUG_ATOMIC("Updating routing for [CONNECTOR:%d:%s]\n", |
| 169 | connector->base.id, |
| 170 | connector->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 171 | |
| 172 | if (connector->state->crtc != connector_state->crtc) { |
| 173 | if (connector->state->crtc) { |
| 174 | idx = drm_crtc_index(connector->state->crtc); |
| 175 | |
| 176 | crtc_state = state->crtc_states[idx]; |
| 177 | crtc_state->mode_changed = true; |
| 178 | } |
| 179 | |
| 180 | if (connector_state->crtc) { |
| 181 | idx = drm_crtc_index(connector_state->crtc); |
| 182 | |
| 183 | crtc_state = state->crtc_states[idx]; |
| 184 | crtc_state->mode_changed = true; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | if (!connector_state->crtc) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 189 | DRM_DEBUG_ATOMIC("Disabling [CONNECTOR:%d:%s]\n", |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 190 | connector->base.id, |
| 191 | connector->name); |
| 192 | |
| 193 | connector_state->best_encoder = NULL; |
| 194 | |
| 195 | return 0; |
| 196 | } |
| 197 | |
| 198 | funcs = connector->helper_private; |
| 199 | new_encoder = funcs->best_encoder(connector); |
| 200 | |
| 201 | if (!new_encoder) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 202 | DRM_DEBUG_ATOMIC("No suitable encoder found for [CONNECTOR:%d:%s]\n", |
| 203 | connector->base.id, |
| 204 | connector->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 205 | return -EINVAL; |
| 206 | } |
| 207 | |
| 208 | if (new_encoder == connector_state->best_encoder) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 209 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] keeps [ENCODER:%d:%s], now on [CRTC:%d]\n", |
| 210 | connector->base.id, |
| 211 | connector->name, |
| 212 | new_encoder->base.id, |
| 213 | new_encoder->name, |
| 214 | connector_state->crtc->base.id); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 215 | |
| 216 | return 0; |
| 217 | } |
| 218 | |
| 219 | encoder_crtc = get_current_crtc_for_encoder(state->dev, |
| 220 | new_encoder); |
| 221 | |
| 222 | if (encoder_crtc) { |
| 223 | ret = steal_encoder(state, new_encoder, encoder_crtc); |
| 224 | if (ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 225 | DRM_DEBUG_ATOMIC("Encoder stealing failed for [CONNECTOR:%d:%s]\n", |
| 226 | connector->base.id, |
| 227 | connector->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 228 | return ret; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | connector_state->best_encoder = new_encoder; |
| 233 | idx = drm_crtc_index(connector_state->crtc); |
| 234 | |
| 235 | crtc_state = state->crtc_states[idx]; |
| 236 | crtc_state->mode_changed = true; |
| 237 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 238 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] using [ENCODER:%d:%s] on [CRTC:%d]\n", |
| 239 | connector->base.id, |
| 240 | connector->name, |
| 241 | new_encoder->base.id, |
| 242 | new_encoder->name, |
| 243 | connector_state->crtc->base.id); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 244 | |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | static int |
| 249 | mode_fixup(struct drm_atomic_state *state) |
| 250 | { |
| 251 | int ncrtcs = state->dev->mode_config.num_crtc; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 252 | struct drm_crtc_state *crtc_state; |
| 253 | struct drm_connector_state *conn_state; |
| 254 | int i; |
| 255 | bool ret; |
| 256 | |
| 257 | for (i = 0; i < ncrtcs; i++) { |
| 258 | crtc_state = state->crtc_states[i]; |
| 259 | |
| 260 | if (!crtc_state || !crtc_state->mode_changed) |
| 261 | continue; |
| 262 | |
| 263 | drm_mode_copy(&crtc_state->adjusted_mode, &crtc_state->mode); |
| 264 | } |
| 265 | |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 266 | for (i = 0; i < state->num_connector; i++) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 267 | struct drm_encoder_helper_funcs *funcs; |
| 268 | struct drm_encoder *encoder; |
| 269 | |
| 270 | conn_state = state->connector_states[i]; |
| 271 | |
| 272 | if (!conn_state) |
| 273 | continue; |
| 274 | |
| 275 | WARN_ON(!!conn_state->best_encoder != !!conn_state->crtc); |
| 276 | |
| 277 | if (!conn_state->crtc || !conn_state->best_encoder) |
| 278 | continue; |
| 279 | |
| 280 | crtc_state = |
| 281 | state->crtc_states[drm_crtc_index(conn_state->crtc)]; |
| 282 | |
| 283 | /* |
| 284 | * Each encoder has at most one connector (since we always steal |
| 285 | * it away), so we won't call ->mode_fixup twice. |
| 286 | */ |
| 287 | encoder = conn_state->best_encoder; |
| 288 | funcs = encoder->helper_private; |
| 289 | |
| 290 | if (encoder->bridge && encoder->bridge->funcs->mode_fixup) { |
| 291 | ret = encoder->bridge->funcs->mode_fixup( |
| 292 | encoder->bridge, &crtc_state->mode, |
| 293 | &crtc_state->adjusted_mode); |
| 294 | if (!ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 295 | DRM_DEBUG_ATOMIC("Bridge fixup failed\n"); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 296 | return -EINVAL; |
| 297 | } |
| 298 | } |
| 299 | |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 300 | if (funcs->atomic_check) { |
| 301 | ret = funcs->atomic_check(encoder, crtc_state, |
| 302 | conn_state); |
| 303 | if (ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 304 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] check failed\n", |
| 305 | encoder->base.id, encoder->name); |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 306 | return ret; |
| 307 | } |
| 308 | } else { |
| 309 | ret = funcs->mode_fixup(encoder, &crtc_state->mode, |
| 310 | &crtc_state->adjusted_mode); |
| 311 | if (!ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 312 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] fixup failed\n", |
| 313 | encoder->base.id, encoder->name); |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 314 | return -EINVAL; |
| 315 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 316 | } |
| 317 | } |
| 318 | |
| 319 | for (i = 0; i < ncrtcs; i++) { |
| 320 | struct drm_crtc_helper_funcs *funcs; |
| 321 | struct drm_crtc *crtc; |
| 322 | |
| 323 | crtc_state = state->crtc_states[i]; |
| 324 | crtc = state->crtcs[i]; |
| 325 | |
| 326 | if (!crtc_state || !crtc_state->mode_changed) |
| 327 | continue; |
| 328 | |
| 329 | funcs = crtc->helper_private; |
| 330 | ret = funcs->mode_fixup(crtc, &crtc_state->mode, |
| 331 | &crtc_state->adjusted_mode); |
| 332 | if (!ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 333 | DRM_DEBUG_ATOMIC("[CRTC:%d] fixup failed\n", |
| 334 | crtc->base.id); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 335 | return -EINVAL; |
| 336 | } |
| 337 | } |
| 338 | |
| 339 | return 0; |
| 340 | } |
| 341 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 342 | static bool |
| 343 | needs_modeset(struct drm_crtc_state *state) |
| 344 | { |
| 345 | return state->mode_changed || state->active_changed; |
| 346 | } |
| 347 | |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 348 | /** |
| 349 | * drm_atomic_helper_check - validate state object for modeset changes |
| 350 | * @dev: DRM device |
| 351 | * @state: the driver state object |
| 352 | * |
| 353 | * Check the state object to see if the requested state is physically possible. |
| 354 | * This does all the crtc and connector related computations for an atomic |
| 355 | * update. It computes and updates crtc_state->mode_changed, adds any additional |
| 356 | * connectors needed for full modesets and calls down into ->mode_fixup |
| 357 | * functions of the driver backend. |
| 358 | * |
| 359 | * IMPORTANT: |
| 360 | * |
| 361 | * Drivers which update ->mode_changed (e.g. in their ->atomic_check hooks if a |
| 362 | * plane update can't be done without a full modeset) _must_ call this function |
| 363 | * afterwards after that change. It is permitted to call this function multiple |
| 364 | * times for the same update, e.g. when the ->atomic_check functions depend upon |
| 365 | * the adjusted dotclock for fifo space allocation and watermark computation. |
| 366 | * |
| 367 | * RETURNS |
| 368 | * Zero for success or -errno |
| 369 | */ |
| 370 | int |
Rob Clark | 934ce1c | 2014-11-19 16:41:33 -0500 | [diff] [blame] | 371 | drm_atomic_helper_check_modeset(struct drm_device *dev, |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 372 | struct drm_atomic_state *state) |
| 373 | { |
| 374 | int ncrtcs = dev->mode_config.num_crtc; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 375 | struct drm_crtc *crtc; |
| 376 | struct drm_crtc_state *crtc_state; |
| 377 | int i, ret; |
| 378 | |
| 379 | for (i = 0; i < ncrtcs; i++) { |
| 380 | crtc = state->crtcs[i]; |
| 381 | crtc_state = state->crtc_states[i]; |
| 382 | |
| 383 | if (!crtc) |
| 384 | continue; |
| 385 | |
| 386 | if (!drm_mode_equal(&crtc->state->mode, &crtc_state->mode)) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 387 | DRM_DEBUG_ATOMIC("[CRTC:%d] mode changed\n", |
| 388 | crtc->base.id); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 389 | crtc_state->mode_changed = true; |
| 390 | } |
| 391 | |
| 392 | if (crtc->state->enable != crtc_state->enable) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 393 | DRM_DEBUG_ATOMIC("[CRTC:%d] enable changed\n", |
| 394 | crtc->base.id); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 395 | crtc_state->mode_changed = true; |
| 396 | } |
| 397 | } |
| 398 | |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 399 | for (i = 0; i < state->num_connector; i++) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 400 | /* |
| 401 | * This only sets crtc->mode_changed for routing changes, |
| 402 | * drivers must set crtc->mode_changed themselves when connector |
| 403 | * properties need to be updated. |
| 404 | */ |
| 405 | ret = update_connector_routing(state, i); |
| 406 | if (ret) |
| 407 | return ret; |
| 408 | } |
| 409 | |
| 410 | /* |
| 411 | * After all the routing has been prepared we need to add in any |
| 412 | * connector which is itself unchanged, but who's crtc changes it's |
| 413 | * configuration. This must be done before calling mode_fixup in case a |
| 414 | * crtc only changed its mode but has the same set of connectors. |
| 415 | */ |
| 416 | for (i = 0; i < ncrtcs; i++) { |
| 417 | int num_connectors; |
| 418 | |
| 419 | crtc = state->crtcs[i]; |
| 420 | crtc_state = state->crtc_states[i]; |
| 421 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 422 | if (!crtc) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 423 | continue; |
| 424 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 425 | /* |
| 426 | * We must set ->active_changed after walking connectors for |
| 427 | * otherwise an update that only changes active would result in |
| 428 | * a full modeset because update_connector_routing force that. |
| 429 | */ |
| 430 | if (crtc->state->active != crtc_state->active) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 431 | DRM_DEBUG_ATOMIC("[CRTC:%d] active changed\n", |
| 432 | crtc->base.id); |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 433 | crtc_state->active_changed = true; |
| 434 | } |
| 435 | |
| 436 | if (!needs_modeset(crtc_state)) |
| 437 | continue; |
| 438 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 439 | DRM_DEBUG_ATOMIC("[CRTC:%d] needs all connectors, enable: %c, active: %c\n", |
| 440 | crtc->base.id, |
| 441 | crtc_state->enable ? 'y' : 'n', |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 442 | crtc_state->active ? 'y' : 'n'); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 443 | |
| 444 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 445 | if (ret != 0) |
| 446 | return ret; |
| 447 | |
| 448 | num_connectors = drm_atomic_connectors_for_crtc(state, |
| 449 | crtc); |
| 450 | |
| 451 | if (crtc_state->enable != !!num_connectors) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 452 | DRM_DEBUG_ATOMIC("[CRTC:%d] enabled/connectors mismatch\n", |
| 453 | crtc->base.id); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 454 | |
| 455 | return -EINVAL; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | return mode_fixup(state); |
| 460 | } |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 461 | EXPORT_SYMBOL(drm_atomic_helper_check_modeset); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 462 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 463 | /** |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 464 | * drm_atomic_helper_check - validate state object for modeset changes |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 465 | * @dev: DRM device |
| 466 | * @state: the driver state object |
| 467 | * |
| 468 | * 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] | 469 | * This does all the plane update related checks using by calling into the |
| 470 | * ->atomic_check hooks provided by the driver. |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 471 | * |
| 472 | * RETURNS |
| 473 | * Zero for success or -errno |
| 474 | */ |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 475 | int |
| 476 | drm_atomic_helper_check_planes(struct drm_device *dev, |
| 477 | struct drm_atomic_state *state) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 478 | { |
| 479 | int nplanes = dev->mode_config.num_total_plane; |
| 480 | int ncrtcs = dev->mode_config.num_crtc; |
| 481 | int i, ret = 0; |
| 482 | |
| 483 | for (i = 0; i < nplanes; i++) { |
| 484 | struct drm_plane_helper_funcs *funcs; |
| 485 | struct drm_plane *plane = state->planes[i]; |
| 486 | struct drm_plane_state *plane_state = state->plane_states[i]; |
| 487 | |
| 488 | if (!plane) |
| 489 | continue; |
| 490 | |
| 491 | funcs = plane->helper_private; |
| 492 | |
| 493 | drm_atomic_helper_plane_changed(state, plane_state, plane); |
| 494 | |
| 495 | if (!funcs || !funcs->atomic_check) |
| 496 | continue; |
| 497 | |
| 498 | ret = funcs->atomic_check(plane, plane_state); |
| 499 | if (ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 500 | DRM_DEBUG_ATOMIC("[PLANE:%d] atomic driver check failed\n", |
| 501 | plane->base.id); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 502 | return ret; |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | for (i = 0; i < ncrtcs; i++) { |
| 507 | struct drm_crtc_helper_funcs *funcs; |
| 508 | struct drm_crtc *crtc = state->crtcs[i]; |
| 509 | |
| 510 | if (!crtc) |
| 511 | continue; |
| 512 | |
| 513 | funcs = crtc->helper_private; |
| 514 | |
| 515 | if (!funcs || !funcs->atomic_check) |
| 516 | continue; |
| 517 | |
| 518 | ret = funcs->atomic_check(crtc, state->crtc_states[i]); |
| 519 | if (ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 520 | DRM_DEBUG_ATOMIC("[CRTC:%d] atomic driver check failed\n", |
| 521 | crtc->base.id); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 522 | return ret; |
| 523 | } |
| 524 | } |
| 525 | |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 526 | return ret; |
| 527 | } |
| 528 | EXPORT_SYMBOL(drm_atomic_helper_check_planes); |
| 529 | |
| 530 | /** |
| 531 | * drm_atomic_helper_check - validate state object |
| 532 | * @dev: DRM device |
| 533 | * @state: the driver state object |
| 534 | * |
| 535 | * Check the state object to see if the requested state is physically possible. |
| 536 | * Only crtcs and planes have check callbacks, so for any additional (global) |
| 537 | * checking that a driver needs it can simply wrap that around this function. |
| 538 | * Drivers without such needs can directly use this as their ->atomic_check() |
| 539 | * callback. |
| 540 | * |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 541 | * This just wraps the two parts of the state checking for planes and modeset |
| 542 | * state in the default order: First it calls drm_atomic_helper_check_modeset() |
| 543 | * and then drm_atomic_helper_check_planes(). The assumption is that the |
| 544 | * ->atomic_check functions depend upon an updated adjusted_mode.clock to |
| 545 | * e.g. properly compute watermarks. |
| 546 | * |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 547 | * RETURNS |
| 548 | * Zero for success or -errno |
| 549 | */ |
| 550 | int drm_atomic_helper_check(struct drm_device *dev, |
| 551 | struct drm_atomic_state *state) |
| 552 | { |
| 553 | int ret; |
| 554 | |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 555 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 556 | if (ret) |
| 557 | return ret; |
| 558 | |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 559 | ret = drm_atomic_helper_check_planes(dev, state); |
Rob Clark | 934ce1c | 2014-11-19 16:41:33 -0500 | [diff] [blame] | 560 | if (ret) |
| 561 | return ret; |
| 562 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 563 | return ret; |
| 564 | } |
| 565 | EXPORT_SYMBOL(drm_atomic_helper_check); |
| 566 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 567 | static void |
| 568 | disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state) |
| 569 | { |
| 570 | int ncrtcs = old_state->dev->mode_config.num_crtc; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 571 | int i; |
| 572 | |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 573 | for (i = 0; i < old_state->num_connector; i++) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 574 | struct drm_connector_state *old_conn_state; |
| 575 | struct drm_connector *connector; |
| 576 | struct drm_encoder_helper_funcs *funcs; |
| 577 | struct drm_encoder *encoder; |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 578 | struct drm_crtc_state *old_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 579 | |
| 580 | old_conn_state = old_state->connector_states[i]; |
| 581 | connector = old_state->connectors[i]; |
| 582 | |
| 583 | /* Shut down everything that's in the changeset and currently |
| 584 | * still on. So need to check the old, saved state. */ |
| 585 | if (!old_conn_state || !old_conn_state->crtc) |
| 586 | continue; |
| 587 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 588 | old_crtc_state = old_state->crtc_states[drm_crtc_index(old_conn_state->crtc)]; |
| 589 | |
| 590 | if (!old_crtc_state->active) |
| 591 | continue; |
| 592 | |
Rob Clark | 46df9ad | 2014-11-20 15:40:36 -0500 | [diff] [blame] | 593 | encoder = old_conn_state->best_encoder; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 594 | |
Rob Clark | 46df9ad | 2014-11-20 15:40:36 -0500 | [diff] [blame] | 595 | /* We shouldn't get this far if we didn't previously have |
| 596 | * an encoder.. but WARN_ON() rather than explode. |
| 597 | */ |
| 598 | if (WARN_ON(!encoder)) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 599 | continue; |
| 600 | |
| 601 | funcs = encoder->helper_private; |
| 602 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 603 | DRM_DEBUG_ATOMIC("disabling [ENCODER:%d:%s]\n", |
| 604 | encoder->base.id, encoder->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 605 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 606 | /* |
| 607 | * Each encoder has at most one connector (since we always steal |
| 608 | * it away), so we won't call call disable hooks twice. |
| 609 | */ |
| 610 | if (encoder->bridge) |
| 611 | encoder->bridge->funcs->disable(encoder->bridge); |
| 612 | |
| 613 | /* Right function depends upon target state. */ |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 614 | if (connector->state->crtc && funcs->prepare) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 615 | funcs->prepare(encoder); |
| 616 | else if (funcs->disable) |
| 617 | funcs->disable(encoder); |
| 618 | else |
| 619 | funcs->dpms(encoder, DRM_MODE_DPMS_OFF); |
| 620 | |
| 621 | if (encoder->bridge) |
| 622 | encoder->bridge->funcs->post_disable(encoder->bridge); |
| 623 | } |
| 624 | |
| 625 | for (i = 0; i < ncrtcs; i++) { |
| 626 | struct drm_crtc_helper_funcs *funcs; |
| 627 | struct drm_crtc *crtc; |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 628 | struct drm_crtc_state *old_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 629 | |
| 630 | crtc = old_state->crtcs[i]; |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 631 | old_crtc_state = old_state->crtc_states[i]; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 632 | |
| 633 | /* Shut down everything that needs a full modeset. */ |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 634 | if (!crtc || !needs_modeset(crtc->state)) |
| 635 | continue; |
| 636 | |
| 637 | if (!old_crtc_state->active) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 638 | continue; |
| 639 | |
| 640 | funcs = crtc->helper_private; |
| 641 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 642 | DRM_DEBUG_ATOMIC("disabling [CRTC:%d]\n", |
| 643 | crtc->base.id); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 644 | |
| 645 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 646 | /* Right function depends upon target state. */ |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 647 | if (crtc->state->enable && funcs->prepare) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 648 | funcs->prepare(crtc); |
| 649 | else if (funcs->disable) |
| 650 | funcs->disable(crtc); |
| 651 | else |
| 652 | funcs->dpms(crtc, DRM_MODE_DPMS_OFF); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | static void |
| 657 | set_routing_links(struct drm_device *dev, struct drm_atomic_state *old_state) |
| 658 | { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 659 | int ncrtcs = old_state->dev->mode_config.num_crtc; |
| 660 | int i; |
| 661 | |
| 662 | /* clear out existing links */ |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 663 | for (i = 0; i < old_state->num_connector; i++) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 664 | struct drm_connector *connector; |
| 665 | |
| 666 | connector = old_state->connectors[i]; |
| 667 | |
| 668 | if (!connector || !connector->encoder) |
| 669 | continue; |
| 670 | |
| 671 | WARN_ON(!connector->encoder->crtc); |
| 672 | |
| 673 | connector->encoder->crtc = NULL; |
| 674 | connector->encoder = NULL; |
| 675 | } |
| 676 | |
| 677 | /* set new links */ |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 678 | for (i = 0; i < old_state->num_connector; i++) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 679 | struct drm_connector *connector; |
| 680 | |
| 681 | connector = old_state->connectors[i]; |
| 682 | |
| 683 | if (!connector || !connector->state->crtc) |
| 684 | continue; |
| 685 | |
| 686 | if (WARN_ON(!connector->state->best_encoder)) |
| 687 | continue; |
| 688 | |
| 689 | connector->encoder = connector->state->best_encoder; |
| 690 | connector->encoder->crtc = connector->state->crtc; |
| 691 | } |
| 692 | |
| 693 | /* set legacy state in the crtc structure */ |
| 694 | for (i = 0; i < ncrtcs; i++) { |
| 695 | struct drm_crtc *crtc; |
| 696 | |
| 697 | crtc = old_state->crtcs[i]; |
| 698 | |
| 699 | if (!crtc) |
| 700 | continue; |
| 701 | |
| 702 | crtc->mode = crtc->state->mode; |
| 703 | crtc->enabled = crtc->state->enable; |
| 704 | crtc->x = crtc->primary->state->src_x >> 16; |
| 705 | crtc->y = crtc->primary->state->src_y >> 16; |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | static void |
| 710 | crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state) |
| 711 | { |
| 712 | int ncrtcs = old_state->dev->mode_config.num_crtc; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 713 | int i; |
| 714 | |
| 715 | for (i = 0; i < ncrtcs; i++) { |
| 716 | struct drm_crtc_helper_funcs *funcs; |
| 717 | struct drm_crtc *crtc; |
| 718 | |
| 719 | crtc = old_state->crtcs[i]; |
| 720 | |
| 721 | if (!crtc || !crtc->state->mode_changed) |
| 722 | continue; |
| 723 | |
| 724 | funcs = crtc->helper_private; |
| 725 | |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 726 | if (crtc->state->enable) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 727 | DRM_DEBUG_ATOMIC("modeset on [CRTC:%d]\n", |
| 728 | crtc->base.id); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 729 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 730 | funcs->mode_set_nofb(crtc); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 731 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 732 | } |
| 733 | |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 734 | for (i = 0; i < old_state->num_connector; i++) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 735 | struct drm_connector *connector; |
| 736 | struct drm_crtc_state *new_crtc_state; |
| 737 | struct drm_encoder_helper_funcs *funcs; |
| 738 | struct drm_encoder *encoder; |
| 739 | struct drm_display_mode *mode, *adjusted_mode; |
| 740 | |
| 741 | connector = old_state->connectors[i]; |
| 742 | |
| 743 | if (!connector || !connector->state->best_encoder) |
| 744 | continue; |
| 745 | |
| 746 | encoder = connector->state->best_encoder; |
| 747 | funcs = encoder->helper_private; |
| 748 | new_crtc_state = connector->state->crtc->state; |
| 749 | mode = &new_crtc_state->mode; |
| 750 | adjusted_mode = &new_crtc_state->adjusted_mode; |
| 751 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 752 | if (!new_crtc_state->mode_changed) |
| 753 | continue; |
| 754 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 755 | DRM_DEBUG_ATOMIC("modeset on [ENCODER:%d:%s]\n", |
| 756 | encoder->base.id, encoder->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 757 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 758 | /* |
| 759 | * Each encoder has at most one connector (since we always steal |
| 760 | * it away), so we won't call call mode_set hooks twice. |
| 761 | */ |
| 762 | funcs->mode_set(encoder, mode, adjusted_mode); |
| 763 | |
| 764 | if (encoder->bridge && encoder->bridge->funcs->mode_set) |
| 765 | encoder->bridge->funcs->mode_set(encoder->bridge, |
| 766 | mode, adjusted_mode); |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | /** |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame^] | 771 | * drm_atomic_helper_commit_modeset_disables - modeset commit to disable outputs |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 772 | * @dev: DRM device |
Laurent Pinchart | a072f80 | 2015-02-22 12:24:18 +0100 | [diff] [blame] | 773 | * @old_state: atomic state object with old state structures |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 774 | * |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame^] | 775 | * 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] | 776 | * prepares them (if required) with the new mode. |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame^] | 777 | * |
| 778 | * For compatability with legacy crtc helpers this should be called before |
| 779 | * drm_atomic_helper_commit_planes(), which is what the default commit function |
| 780 | * does. But drivers with different needs can group the modeset commits together |
| 781 | * and do the plane commits at the end. This is useful for drivers doing runtime |
| 782 | * 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] | 783 | */ |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame^] | 784 | void drm_atomic_helper_commit_modeset_disables(struct drm_device *dev, |
| 785 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 786 | { |
Laurent Pinchart | a072f80 | 2015-02-22 12:24:18 +0100 | [diff] [blame] | 787 | disable_outputs(dev, old_state); |
| 788 | set_routing_links(dev, old_state); |
| 789 | crtc_set_mode(dev, old_state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 790 | } |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame^] | 791 | EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_disables); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 792 | |
| 793 | /** |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame^] | 794 | * drm_atomic_helper_commit_modeset_enables - modeset commit to enable outputs |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 795 | * @dev: DRM device |
| 796 | * @old_state: atomic state object with old state structures |
| 797 | * |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame^] | 798 | * This function enables all the outputs with the new configuration which had to |
| 799 | * be turned off for the update. |
| 800 | * |
| 801 | * For compatability with legacy crtc helpers this should be called after |
| 802 | * drm_atomic_helper_commit_planes(), which is what the default commit function |
| 803 | * does. But drivers with different needs can group the modeset commits together |
| 804 | * and do the plane commits at the end. This is useful for drivers doing runtime |
| 805 | * 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] | 806 | */ |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame^] | 807 | void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, |
| 808 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 809 | { |
| 810 | int ncrtcs = old_state->dev->mode_config.num_crtc; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 811 | int i; |
| 812 | |
| 813 | for (i = 0; i < ncrtcs; i++) { |
| 814 | struct drm_crtc_helper_funcs *funcs; |
| 815 | struct drm_crtc *crtc; |
| 816 | |
| 817 | crtc = old_state->crtcs[i]; |
| 818 | |
| 819 | /* Need to filter out CRTCs where only planes change. */ |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 820 | if (!crtc || !needs_modeset(crtc->state)) |
| 821 | continue; |
| 822 | |
| 823 | if (!crtc->state->active) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 824 | continue; |
| 825 | |
| 826 | funcs = crtc->helper_private; |
| 827 | |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 828 | if (crtc->state->enable) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 829 | DRM_DEBUG_ATOMIC("enabling [CRTC:%d]\n", |
| 830 | crtc->base.id); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 831 | |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 832 | if (funcs->enable) |
| 833 | funcs->enable(crtc); |
| 834 | else |
| 835 | funcs->commit(crtc); |
| 836 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 837 | } |
| 838 | |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 839 | for (i = 0; i < old_state->num_connector; i++) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 840 | struct drm_connector *connector; |
| 841 | struct drm_encoder_helper_funcs *funcs; |
| 842 | struct drm_encoder *encoder; |
| 843 | |
| 844 | connector = old_state->connectors[i]; |
| 845 | |
| 846 | if (!connector || !connector->state->best_encoder) |
| 847 | continue; |
| 848 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 849 | if (!connector->state->crtc->state->active) |
| 850 | continue; |
| 851 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 852 | encoder = connector->state->best_encoder; |
| 853 | funcs = encoder->helper_private; |
| 854 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 855 | DRM_DEBUG_ATOMIC("enabling [ENCODER:%d:%s]\n", |
| 856 | encoder->base.id, encoder->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 857 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 858 | /* |
| 859 | * Each encoder has at most one connector (since we always steal |
| 860 | * it away), so we won't call call enable hooks twice. |
| 861 | */ |
| 862 | if (encoder->bridge) |
| 863 | encoder->bridge->funcs->pre_enable(encoder->bridge); |
| 864 | |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 865 | if (funcs->enable) |
| 866 | funcs->enable(encoder); |
| 867 | else |
| 868 | funcs->commit(encoder); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 869 | |
| 870 | if (encoder->bridge) |
| 871 | encoder->bridge->funcs->enable(encoder->bridge); |
| 872 | } |
| 873 | } |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame^] | 874 | EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_enables); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 875 | |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 876 | static void wait_for_fences(struct drm_device *dev, |
| 877 | struct drm_atomic_state *state) |
| 878 | { |
| 879 | int nplanes = dev->mode_config.num_total_plane; |
| 880 | int i; |
| 881 | |
| 882 | for (i = 0; i < nplanes; i++) { |
| 883 | struct drm_plane *plane = state->planes[i]; |
| 884 | |
| 885 | if (!plane || !plane->state->fence) |
| 886 | continue; |
| 887 | |
| 888 | WARN_ON(!plane->state->fb); |
| 889 | |
| 890 | fence_wait(plane->state->fence, false); |
| 891 | fence_put(plane->state->fence); |
| 892 | plane->state->fence = NULL; |
| 893 | } |
| 894 | } |
| 895 | |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 896 | static bool framebuffer_changed(struct drm_device *dev, |
| 897 | struct drm_atomic_state *old_state, |
| 898 | struct drm_crtc *crtc) |
| 899 | { |
| 900 | struct drm_plane *plane; |
| 901 | struct drm_plane_state *old_plane_state; |
| 902 | int nplanes = old_state->dev->mode_config.num_total_plane; |
| 903 | int i; |
| 904 | |
| 905 | for (i = 0; i < nplanes; i++) { |
| 906 | plane = old_state->planes[i]; |
| 907 | old_plane_state = old_state->plane_states[i]; |
| 908 | |
| 909 | if (!plane) |
| 910 | continue; |
| 911 | |
| 912 | if (plane->state->crtc != crtc && |
| 913 | old_plane_state->crtc != crtc) |
| 914 | continue; |
| 915 | |
| 916 | if (plane->state->fb != old_plane_state->fb) |
| 917 | return true; |
| 918 | } |
| 919 | |
| 920 | return false; |
| 921 | } |
| 922 | |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 923 | /** |
| 924 | * drm_atomic_helper_wait_for_vblanks - wait for vblank on crtcs |
| 925 | * @dev: DRM device |
| 926 | * @old_state: atomic state object with old state structures |
| 927 | * |
| 928 | * Helper to, after atomic commit, wait for vblanks on all effected |
| 929 | * crtcs (ie. before cleaning up old framebuffers using |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 930 | * drm_atomic_helper_cleanup_planes()). It will only wait on crtcs where the |
| 931 | * framebuffers have actually changed to optimize for the legacy cursor and |
| 932 | * plane update use-case. |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 933 | */ |
| 934 | void |
| 935 | drm_atomic_helper_wait_for_vblanks(struct drm_device *dev, |
| 936 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 937 | { |
| 938 | struct drm_crtc *crtc; |
| 939 | struct drm_crtc_state *old_crtc_state; |
| 940 | int ncrtcs = old_state->dev->mode_config.num_crtc; |
| 941 | int i, ret; |
| 942 | |
| 943 | for (i = 0; i < ncrtcs; i++) { |
| 944 | crtc = old_state->crtcs[i]; |
| 945 | old_crtc_state = old_state->crtc_states[i]; |
| 946 | |
| 947 | if (!crtc) |
| 948 | continue; |
| 949 | |
| 950 | /* No one cares about the old state, so abuse it for tracking |
| 951 | * and store whether we hold a vblank reference (and should do a |
| 952 | * vblank wait) in the ->enable boolean. */ |
| 953 | old_crtc_state->enable = false; |
| 954 | |
| 955 | if (!crtc->state->enable) |
| 956 | continue; |
| 957 | |
Daniel Vetter | f02ad90 | 2015-01-22 16:36:23 +0100 | [diff] [blame] | 958 | /* Legacy cursor ioctls are completely unsynced, and userspace |
| 959 | * relies on that (by doing tons of cursor updates). */ |
| 960 | if (old_state->legacy_cursor_update) |
| 961 | continue; |
| 962 | |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 963 | if (!framebuffer_changed(dev, old_state, crtc)) |
| 964 | continue; |
| 965 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 966 | ret = drm_crtc_vblank_get(crtc); |
| 967 | if (ret != 0) |
| 968 | continue; |
| 969 | |
| 970 | old_crtc_state->enable = true; |
| 971 | old_crtc_state->last_vblank_count = drm_vblank_count(dev, i); |
| 972 | } |
| 973 | |
| 974 | for (i = 0; i < ncrtcs; i++) { |
| 975 | crtc = old_state->crtcs[i]; |
| 976 | old_crtc_state = old_state->crtc_states[i]; |
| 977 | |
| 978 | if (!crtc || !old_crtc_state->enable) |
| 979 | continue; |
| 980 | |
| 981 | ret = wait_event_timeout(dev->vblank[i].queue, |
| 982 | old_crtc_state->last_vblank_count != |
| 983 | drm_vblank_count(dev, i), |
| 984 | msecs_to_jiffies(50)); |
| 985 | |
| 986 | drm_crtc_vblank_put(crtc); |
| 987 | } |
| 988 | } |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 989 | EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 990 | |
| 991 | /** |
| 992 | * drm_atomic_helper_commit - commit validated state object |
| 993 | * @dev: DRM device |
| 994 | * @state: the driver state object |
| 995 | * @async: asynchronous commit |
| 996 | * |
| 997 | * This function commits a with drm_atomic_helper_check() pre-validated state |
| 998 | * object. This can still fail when e.g. the framebuffer reservation fails. For |
| 999 | * now this doesn't implement asynchronous commits. |
| 1000 | * |
| 1001 | * RETURNS |
| 1002 | * Zero for success or -errno. |
| 1003 | */ |
| 1004 | int drm_atomic_helper_commit(struct drm_device *dev, |
| 1005 | struct drm_atomic_state *state, |
| 1006 | bool async) |
| 1007 | { |
| 1008 | int ret; |
| 1009 | |
| 1010 | if (async) |
| 1011 | return -EBUSY; |
| 1012 | |
| 1013 | ret = drm_atomic_helper_prepare_planes(dev, state); |
| 1014 | if (ret) |
| 1015 | return ret; |
| 1016 | |
| 1017 | /* |
| 1018 | * This is the point of no return - everything below never fails except |
| 1019 | * when the hw goes bonghits. Which means we can commit the new state on |
| 1020 | * the software side now. |
| 1021 | */ |
| 1022 | |
| 1023 | drm_atomic_helper_swap_state(dev, state); |
| 1024 | |
| 1025 | /* |
| 1026 | * Everything below can be run asynchronously without the need to grab |
| 1027 | * any modeset locks at all under one conditions: It must be guaranteed |
| 1028 | * that the asynchronous work has either been cancelled (if the driver |
| 1029 | * supports it, which at least requires that the framebuffers get |
| 1030 | * cleaned up with drm_atomic_helper_cleanup_planes()) or completed |
| 1031 | * before the new state gets committed on the software side with |
| 1032 | * drm_atomic_helper_swap_state(). |
| 1033 | * |
| 1034 | * This scheme allows new atomic state updates to be prepared and |
| 1035 | * checked in parallel to the asynchronous completion of the previous |
| 1036 | * update. Which is important since compositors need to figure out the |
| 1037 | * composition of the next frame right after having submitted the |
| 1038 | * current layout. |
| 1039 | */ |
| 1040 | |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1041 | wait_for_fences(dev, state); |
| 1042 | |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame^] | 1043 | drm_atomic_helper_commit_modeset_disables(dev, state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1044 | |
| 1045 | drm_atomic_helper_commit_planes(dev, state); |
| 1046 | |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame^] | 1047 | drm_atomic_helper_commit_modeset_enables(dev, state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1048 | |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 1049 | drm_atomic_helper_wait_for_vblanks(dev, state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1050 | |
| 1051 | drm_atomic_helper_cleanup_planes(dev, state); |
| 1052 | |
| 1053 | drm_atomic_state_free(state); |
| 1054 | |
| 1055 | return 0; |
| 1056 | } |
| 1057 | EXPORT_SYMBOL(drm_atomic_helper_commit); |
| 1058 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1059 | /** |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1060 | * DOC: implementing async commit |
| 1061 | * |
| 1062 | * For now the atomic helpers don't support async commit directly. If there is |
| 1063 | * real need it could be added though, using the dma-buf fence infrastructure |
| 1064 | * for generic synchronization with outstanding rendering. |
| 1065 | * |
| 1066 | * For now drivers have to implement async commit themselves, with the following |
| 1067 | * sequence being the recommended one: |
| 1068 | * |
| 1069 | * 1. Run drm_atomic_helper_prepare_planes() first. This is the only function |
| 1070 | * which commit needs to call which can fail, so we want to run it first and |
| 1071 | * synchronously. |
| 1072 | * |
| 1073 | * 2. Synchronize with any outstanding asynchronous commit worker threads which |
| 1074 | * might be affected the new state update. This can be done by either cancelling |
| 1075 | * or flushing the work items, depending upon whether the driver can deal with |
| 1076 | * cancelled updates. Note that it is important to ensure that the framebuffer |
| 1077 | * cleanup is still done when cancelling. |
| 1078 | * |
| 1079 | * For sufficient parallelism it is recommended to have a work item per crtc |
| 1080 | * (for updates which don't touch global state) and a global one. Then we only |
| 1081 | * need to synchronize with the crtc work items for changed crtcs and the global |
| 1082 | * work item, which allows nice concurrent updates on disjoint sets of crtcs. |
| 1083 | * |
| 1084 | * 3. The software state is updated synchronously with |
| 1085 | * drm_atomic_helper_swap_state. Doing this under the protection of all modeset |
| 1086 | * locks means concurrent callers never see inconsistent state. And doing this |
| 1087 | * while it's guaranteed that no relevant async worker runs means that async |
| 1088 | * workers do not need grab any locks. Actually they must not grab locks, for |
| 1089 | * otherwise the work flushing will deadlock. |
| 1090 | * |
| 1091 | * 4. Schedule a work item to do all subsequent steps, using the split-out |
| 1092 | * commit helpers: a) pre-plane commit b) plane commit c) post-plane commit and |
| 1093 | * then cleaning up the framebuffers after the old framebuffer is no longer |
| 1094 | * being displayed. |
| 1095 | */ |
| 1096 | |
| 1097 | /** |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1098 | * drm_atomic_helper_prepare_planes - prepare plane resources after commit |
| 1099 | * @dev: DRM device |
| 1100 | * @state: atomic state object with old state structures |
| 1101 | * |
| 1102 | * This function prepares plane state, specifically framebuffers, for the new |
| 1103 | * configuration. If any failure is encountered this function will call |
| 1104 | * ->cleanup_fb on any already successfully prepared framebuffer. |
| 1105 | * |
| 1106 | * Returns: |
| 1107 | * 0 on success, negative error code on failure. |
| 1108 | */ |
| 1109 | int drm_atomic_helper_prepare_planes(struct drm_device *dev, |
| 1110 | struct drm_atomic_state *state) |
| 1111 | { |
| 1112 | int nplanes = dev->mode_config.num_total_plane; |
| 1113 | int ret, i; |
| 1114 | |
| 1115 | for (i = 0; i < nplanes; i++) { |
| 1116 | struct drm_plane_helper_funcs *funcs; |
| 1117 | struct drm_plane *plane = state->planes[i]; |
| 1118 | struct drm_framebuffer *fb; |
| 1119 | |
| 1120 | if (!plane) |
| 1121 | continue; |
| 1122 | |
| 1123 | funcs = plane->helper_private; |
| 1124 | |
| 1125 | fb = state->plane_states[i]->fb; |
| 1126 | |
| 1127 | if (fb && funcs->prepare_fb) { |
| 1128 | ret = funcs->prepare_fb(plane, fb); |
| 1129 | if (ret) |
| 1130 | goto fail; |
| 1131 | } |
| 1132 | } |
| 1133 | |
| 1134 | return 0; |
| 1135 | |
| 1136 | fail: |
| 1137 | for (i--; i >= 0; i--) { |
| 1138 | struct drm_plane_helper_funcs *funcs; |
| 1139 | struct drm_plane *plane = state->planes[i]; |
| 1140 | struct drm_framebuffer *fb; |
| 1141 | |
| 1142 | if (!plane) |
| 1143 | continue; |
| 1144 | |
| 1145 | funcs = plane->helper_private; |
| 1146 | |
| 1147 | fb = state->plane_states[i]->fb; |
| 1148 | |
| 1149 | if (fb && funcs->cleanup_fb) |
| 1150 | funcs->cleanup_fb(plane, fb); |
| 1151 | |
| 1152 | } |
| 1153 | |
| 1154 | return ret; |
| 1155 | } |
| 1156 | EXPORT_SYMBOL(drm_atomic_helper_prepare_planes); |
| 1157 | |
| 1158 | /** |
| 1159 | * drm_atomic_helper_commit_planes - commit plane state |
| 1160 | * @dev: DRM device |
Daniel Vetter | b0fcfc8 | 2014-11-19 18:38:11 +0100 | [diff] [blame] | 1161 | * @old_state: atomic state object with old state structures |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1162 | * |
| 1163 | * This function commits the new plane state using the plane and atomic helper |
| 1164 | * functions for planes and crtcs. It assumes that the atomic state has already |
| 1165 | * been pushed into the relevant object state pointers, since this step can no |
| 1166 | * longer fail. |
| 1167 | * |
Daniel Vetter | b0fcfc8 | 2014-11-19 18:38:11 +0100 | [diff] [blame] | 1168 | * 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] | 1169 | * crtcs need to be updated though. |
| 1170 | */ |
| 1171 | void drm_atomic_helper_commit_planes(struct drm_device *dev, |
Daniel Vetter | b0fcfc8 | 2014-11-19 18:38:11 +0100 | [diff] [blame] | 1172 | struct drm_atomic_state *old_state) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1173 | { |
| 1174 | int nplanes = dev->mode_config.num_total_plane; |
| 1175 | int ncrtcs = dev->mode_config.num_crtc; |
| 1176 | int i; |
| 1177 | |
| 1178 | for (i = 0; i < ncrtcs; i++) { |
| 1179 | struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | b0fcfc8 | 2014-11-19 18:38:11 +0100 | [diff] [blame] | 1180 | struct drm_crtc *crtc = old_state->crtcs[i]; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1181 | |
| 1182 | if (!crtc) |
| 1183 | continue; |
| 1184 | |
| 1185 | funcs = crtc->helper_private; |
| 1186 | |
| 1187 | if (!funcs || !funcs->atomic_begin) |
| 1188 | continue; |
| 1189 | |
| 1190 | funcs->atomic_begin(crtc); |
| 1191 | } |
| 1192 | |
| 1193 | for (i = 0; i < nplanes; i++) { |
| 1194 | struct drm_plane_helper_funcs *funcs; |
Daniel Vetter | b0fcfc8 | 2014-11-19 18:38:11 +0100 | [diff] [blame] | 1195 | struct drm_plane *plane = old_state->planes[i]; |
Thierry Reding | f1c37e1 | 2014-11-25 12:09:44 +0100 | [diff] [blame] | 1196 | struct drm_plane_state *old_plane_state; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1197 | |
| 1198 | if (!plane) |
| 1199 | continue; |
| 1200 | |
| 1201 | funcs = plane->helper_private; |
| 1202 | |
Thierry Reding | 3cad4b6 | 2014-11-25 13:05:12 +0100 | [diff] [blame] | 1203 | if (!funcs) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1204 | continue; |
| 1205 | |
Thierry Reding | f1c37e1 | 2014-11-25 12:09:44 +0100 | [diff] [blame] | 1206 | old_plane_state = old_state->plane_states[i]; |
| 1207 | |
Thierry Reding | 407b8bd | 2014-11-20 12:05:50 +0100 | [diff] [blame] | 1208 | /* |
| 1209 | * Special-case disabling the plane if drivers support it. |
| 1210 | */ |
| 1211 | if (drm_atomic_plane_disabling(plane, old_plane_state) && |
| 1212 | funcs->atomic_disable) |
| 1213 | funcs->atomic_disable(plane, old_plane_state); |
| 1214 | else |
| 1215 | funcs->atomic_update(plane, old_plane_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1216 | } |
| 1217 | |
| 1218 | for (i = 0; i < ncrtcs; i++) { |
| 1219 | struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | b0fcfc8 | 2014-11-19 18:38:11 +0100 | [diff] [blame] | 1220 | struct drm_crtc *crtc = old_state->crtcs[i]; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1221 | |
| 1222 | if (!crtc) |
| 1223 | continue; |
| 1224 | |
| 1225 | funcs = crtc->helper_private; |
| 1226 | |
| 1227 | if (!funcs || !funcs->atomic_flush) |
| 1228 | continue; |
| 1229 | |
| 1230 | funcs->atomic_flush(crtc); |
| 1231 | } |
| 1232 | } |
| 1233 | EXPORT_SYMBOL(drm_atomic_helper_commit_planes); |
| 1234 | |
| 1235 | /** |
| 1236 | * drm_atomic_helper_cleanup_planes - cleanup plane resources after commit |
| 1237 | * @dev: DRM device |
| 1238 | * @old_state: atomic state object with old state structures |
| 1239 | * |
| 1240 | * This function cleans up plane state, specifically framebuffers, from the old |
| 1241 | * configuration. Hence the old configuration must be perserved in @old_state to |
| 1242 | * be able to call this function. |
| 1243 | * |
| 1244 | * This function must also be called on the new state when the atomic update |
| 1245 | * fails at any point after calling drm_atomic_helper_prepare_planes(). |
| 1246 | */ |
| 1247 | void drm_atomic_helper_cleanup_planes(struct drm_device *dev, |
| 1248 | struct drm_atomic_state *old_state) |
| 1249 | { |
| 1250 | int nplanes = dev->mode_config.num_total_plane; |
| 1251 | int i; |
| 1252 | |
| 1253 | for (i = 0; i < nplanes; i++) { |
| 1254 | struct drm_plane_helper_funcs *funcs; |
| 1255 | struct drm_plane *plane = old_state->planes[i]; |
| 1256 | struct drm_framebuffer *old_fb; |
| 1257 | |
| 1258 | if (!plane) |
| 1259 | continue; |
| 1260 | |
| 1261 | funcs = plane->helper_private; |
| 1262 | |
| 1263 | old_fb = old_state->plane_states[i]->fb; |
| 1264 | |
| 1265 | if (old_fb && funcs->cleanup_fb) |
| 1266 | funcs->cleanup_fb(plane, old_fb); |
| 1267 | } |
| 1268 | } |
| 1269 | EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes); |
| 1270 | |
| 1271 | /** |
| 1272 | * drm_atomic_helper_swap_state - store atomic state into current sw state |
| 1273 | * @dev: DRM device |
| 1274 | * @state: atomic state |
| 1275 | * |
| 1276 | * This function stores the atomic state into the current state pointers in all |
| 1277 | * driver objects. It should be called after all failing steps have been done |
| 1278 | * and succeeded, but before the actual hardware state is committed. |
| 1279 | * |
| 1280 | * For cleanup and error recovery the current state for all changed objects will |
| 1281 | * be swaped into @state. |
| 1282 | * |
| 1283 | * With that sequence it fits perfectly into the plane prepare/cleanup sequence: |
| 1284 | * |
| 1285 | * 1. Call drm_atomic_helper_prepare_planes() with the staged atomic state. |
| 1286 | * |
| 1287 | * 2. Do any other steps that might fail. |
| 1288 | * |
| 1289 | * 3. Put the staged state into the current state pointers with this function. |
| 1290 | * |
| 1291 | * 4. Actually commit the hardware state. |
| 1292 | * |
| 1293 | * 5. Call drm_atomic_helper_cleanup_planes with @state, which since step 3 |
| 1294 | * contains the old state. Also do any other cleanup required with that state. |
| 1295 | */ |
| 1296 | void drm_atomic_helper_swap_state(struct drm_device *dev, |
| 1297 | struct drm_atomic_state *state) |
| 1298 | { |
| 1299 | int i; |
| 1300 | |
| 1301 | for (i = 0; i < dev->mode_config.num_connector; i++) { |
| 1302 | struct drm_connector *connector = state->connectors[i]; |
| 1303 | |
| 1304 | if (!connector) |
| 1305 | continue; |
| 1306 | |
| 1307 | connector->state->state = state; |
| 1308 | swap(state->connector_states[i], connector->state); |
| 1309 | connector->state->state = NULL; |
| 1310 | } |
| 1311 | |
| 1312 | for (i = 0; i < dev->mode_config.num_crtc; i++) { |
| 1313 | struct drm_crtc *crtc = state->crtcs[i]; |
| 1314 | |
| 1315 | if (!crtc) |
| 1316 | continue; |
| 1317 | |
| 1318 | crtc->state->state = state; |
| 1319 | swap(state->crtc_states[i], crtc->state); |
| 1320 | crtc->state->state = NULL; |
| 1321 | } |
| 1322 | |
| 1323 | for (i = 0; i < dev->mode_config.num_total_plane; i++) { |
| 1324 | struct drm_plane *plane = state->planes[i]; |
| 1325 | |
| 1326 | if (!plane) |
| 1327 | continue; |
| 1328 | |
| 1329 | plane->state->state = state; |
| 1330 | swap(state->plane_states[i], plane->state); |
| 1331 | plane->state->state = NULL; |
| 1332 | } |
| 1333 | } |
| 1334 | EXPORT_SYMBOL(drm_atomic_helper_swap_state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1335 | |
| 1336 | /** |
| 1337 | * drm_atomic_helper_update_plane - Helper for primary plane update using atomic |
| 1338 | * @plane: plane object to update |
| 1339 | * @crtc: owning CRTC of owning plane |
| 1340 | * @fb: framebuffer to flip onto plane |
| 1341 | * @crtc_x: x offset of primary plane on crtc |
| 1342 | * @crtc_y: y offset of primary plane on crtc |
| 1343 | * @crtc_w: width of primary plane rectangle on crtc |
| 1344 | * @crtc_h: height of primary plane rectangle on crtc |
| 1345 | * @src_x: x offset of @fb for panning |
| 1346 | * @src_y: y offset of @fb for panning |
| 1347 | * @src_w: width of source rectangle in @fb |
| 1348 | * @src_h: height of source rectangle in @fb |
| 1349 | * |
| 1350 | * Provides a default plane update handler using the atomic driver interface. |
| 1351 | * |
| 1352 | * RETURNS: |
| 1353 | * Zero on success, error code on failure |
| 1354 | */ |
| 1355 | int drm_atomic_helper_update_plane(struct drm_plane *plane, |
| 1356 | struct drm_crtc *crtc, |
| 1357 | struct drm_framebuffer *fb, |
| 1358 | int crtc_x, int crtc_y, |
| 1359 | unsigned int crtc_w, unsigned int crtc_h, |
| 1360 | uint32_t src_x, uint32_t src_y, |
| 1361 | uint32_t src_w, uint32_t src_h) |
| 1362 | { |
| 1363 | struct drm_atomic_state *state; |
| 1364 | struct drm_plane_state *plane_state; |
| 1365 | int ret = 0; |
| 1366 | |
| 1367 | state = drm_atomic_state_alloc(plane->dev); |
| 1368 | if (!state) |
| 1369 | return -ENOMEM; |
| 1370 | |
| 1371 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 1372 | retry: |
| 1373 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 1374 | if (IS_ERR(plane_state)) { |
| 1375 | ret = PTR_ERR(plane_state); |
| 1376 | goto fail; |
| 1377 | } |
| 1378 | |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 1379 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1380 | if (ret != 0) |
| 1381 | goto fail; |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 1382 | drm_atomic_set_fb_for_plane(plane_state, fb); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1383 | plane_state->crtc_x = crtc_x; |
| 1384 | plane_state->crtc_y = crtc_y; |
| 1385 | plane_state->crtc_h = crtc_h; |
| 1386 | plane_state->crtc_w = crtc_w; |
| 1387 | plane_state->src_x = src_x; |
| 1388 | plane_state->src_y = src_y; |
| 1389 | plane_state->src_h = src_h; |
| 1390 | plane_state->src_w = src_w; |
| 1391 | |
| 1392 | ret = drm_atomic_commit(state); |
| 1393 | if (ret != 0) |
| 1394 | goto fail; |
| 1395 | |
Daniel Vetter | f02ad90 | 2015-01-22 16:36:23 +0100 | [diff] [blame] | 1396 | if (plane == crtc->cursor) |
| 1397 | state->legacy_cursor_update = true; |
| 1398 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1399 | /* Driver takes ownership of state on successful commit. */ |
| 1400 | return 0; |
| 1401 | fail: |
| 1402 | if (ret == -EDEADLK) |
| 1403 | goto backoff; |
| 1404 | |
| 1405 | drm_atomic_state_free(state); |
| 1406 | |
| 1407 | return ret; |
| 1408 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1409 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 1410 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1411 | |
| 1412 | /* |
| 1413 | * Someone might have exchanged the framebuffer while we dropped locks |
| 1414 | * in the backoff code. We need to fix up the fb refcount tracking the |
| 1415 | * core does for us. |
| 1416 | */ |
| 1417 | plane->old_fb = plane->fb; |
| 1418 | |
| 1419 | goto retry; |
| 1420 | } |
| 1421 | EXPORT_SYMBOL(drm_atomic_helper_update_plane); |
| 1422 | |
| 1423 | /** |
| 1424 | * drm_atomic_helper_disable_plane - Helper for primary plane disable using * atomic |
| 1425 | * @plane: plane to disable |
| 1426 | * |
| 1427 | * Provides a default plane disable handler using the atomic driver interface. |
| 1428 | * |
| 1429 | * RETURNS: |
| 1430 | * Zero on success, error code on failure |
| 1431 | */ |
| 1432 | int drm_atomic_helper_disable_plane(struct drm_plane *plane) |
| 1433 | { |
| 1434 | struct drm_atomic_state *state; |
| 1435 | struct drm_plane_state *plane_state; |
| 1436 | int ret = 0; |
| 1437 | |
Jasper St. Pierre | aa54e2e | 2014-11-20 19:59:15 -0800 | [diff] [blame] | 1438 | /* |
| 1439 | * FIXME: Without plane->crtc set we can't get at the implicit legacy |
| 1440 | * acquire context. The real fix will be to wire the acquire ctx through |
| 1441 | * everywhere we need it, but meanwhile prevent chaos by just skipping |
| 1442 | * this noop. The critical case is the cursor ioctls which a) only grab |
| 1443 | * crtc/cursor-plane locks (so we need the crtc to get at the right |
| 1444 | * acquire context) and b) can try to disable the plane multiple times. |
| 1445 | */ |
| 1446 | if (!plane->crtc) |
| 1447 | return 0; |
| 1448 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1449 | state = drm_atomic_state_alloc(plane->dev); |
| 1450 | if (!state) |
| 1451 | return -ENOMEM; |
| 1452 | |
| 1453 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(plane->crtc); |
| 1454 | retry: |
| 1455 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 1456 | if (IS_ERR(plane_state)) { |
| 1457 | ret = PTR_ERR(plane_state); |
| 1458 | goto fail; |
| 1459 | } |
| 1460 | |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 1461 | ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1462 | if (ret != 0) |
| 1463 | goto fail; |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 1464 | drm_atomic_set_fb_for_plane(plane_state, NULL); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1465 | plane_state->crtc_x = 0; |
| 1466 | plane_state->crtc_y = 0; |
| 1467 | plane_state->crtc_h = 0; |
| 1468 | plane_state->crtc_w = 0; |
| 1469 | plane_state->src_x = 0; |
| 1470 | plane_state->src_y = 0; |
| 1471 | plane_state->src_h = 0; |
| 1472 | plane_state->src_w = 0; |
| 1473 | |
Daniel Vetter | f02ad90 | 2015-01-22 16:36:23 +0100 | [diff] [blame] | 1474 | if (plane == plane->crtc->cursor) |
| 1475 | state->legacy_cursor_update = true; |
| 1476 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1477 | ret = drm_atomic_commit(state); |
| 1478 | if (ret != 0) |
| 1479 | goto fail; |
| 1480 | |
| 1481 | /* Driver takes ownership of state on successful commit. */ |
| 1482 | return 0; |
| 1483 | fail: |
| 1484 | if (ret == -EDEADLK) |
| 1485 | goto backoff; |
| 1486 | |
| 1487 | drm_atomic_state_free(state); |
| 1488 | |
| 1489 | return ret; |
| 1490 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1491 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 1492 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1493 | |
| 1494 | /* |
| 1495 | * Someone might have exchanged the framebuffer while we dropped locks |
| 1496 | * in the backoff code. We need to fix up the fb refcount tracking the |
| 1497 | * core does for us. |
| 1498 | */ |
| 1499 | plane->old_fb = plane->fb; |
| 1500 | |
| 1501 | goto retry; |
| 1502 | } |
| 1503 | EXPORT_SYMBOL(drm_atomic_helper_disable_plane); |
| 1504 | |
| 1505 | static int update_output_state(struct drm_atomic_state *state, |
| 1506 | struct drm_mode_set *set) |
| 1507 | { |
| 1508 | struct drm_device *dev = set->crtc->dev; |
| 1509 | struct drm_connector_state *conn_state; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1510 | int ncrtcs = state->dev->mode_config.num_crtc; |
| 1511 | int ret, i, j; |
| 1512 | |
| 1513 | ret = drm_modeset_lock(&dev->mode_config.connection_mutex, |
| 1514 | state->acquire_ctx); |
| 1515 | if (ret) |
| 1516 | return ret; |
| 1517 | |
| 1518 | /* First grab all affected connector/crtc states. */ |
| 1519 | for (i = 0; i < set->num_connectors; i++) { |
| 1520 | conn_state = drm_atomic_get_connector_state(state, |
| 1521 | set->connectors[i]); |
| 1522 | if (IS_ERR(conn_state)) |
| 1523 | return PTR_ERR(conn_state); |
| 1524 | } |
| 1525 | |
| 1526 | for (i = 0; i < ncrtcs; i++) { |
| 1527 | struct drm_crtc *crtc = state->crtcs[i]; |
| 1528 | |
| 1529 | if (!crtc) |
| 1530 | continue; |
| 1531 | |
| 1532 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 1533 | if (ret) |
| 1534 | return ret; |
| 1535 | } |
| 1536 | |
| 1537 | /* Then recompute connector->crtc links and crtc enabling state. */ |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 1538 | for (i = 0; i < state->num_connector; i++) { |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1539 | struct drm_connector *connector; |
| 1540 | |
| 1541 | connector = state->connectors[i]; |
| 1542 | conn_state = state->connector_states[i]; |
| 1543 | |
| 1544 | if (!connector) |
| 1545 | continue; |
| 1546 | |
| 1547 | if (conn_state->crtc == set->crtc) { |
| 1548 | ret = drm_atomic_set_crtc_for_connector(conn_state, |
| 1549 | NULL); |
| 1550 | if (ret) |
| 1551 | return ret; |
| 1552 | } |
| 1553 | |
| 1554 | for (j = 0; j < set->num_connectors; j++) { |
| 1555 | if (set->connectors[j] == connector) { |
| 1556 | ret = drm_atomic_set_crtc_for_connector(conn_state, |
| 1557 | set->crtc); |
| 1558 | if (ret) |
| 1559 | return ret; |
| 1560 | break; |
| 1561 | } |
| 1562 | } |
| 1563 | } |
| 1564 | |
| 1565 | for (i = 0; i < ncrtcs; i++) { |
| 1566 | struct drm_crtc *crtc = state->crtcs[i]; |
| 1567 | struct drm_crtc_state *crtc_state = state->crtc_states[i]; |
| 1568 | |
| 1569 | if (!crtc) |
| 1570 | continue; |
| 1571 | |
| 1572 | /* Don't update ->enable for the CRTC in the set_config request, |
| 1573 | * since a mismatch would indicate a bug in the upper layers. |
| 1574 | * The actual modeset code later on will catch any |
| 1575 | * inconsistencies here. */ |
| 1576 | if (crtc == set->crtc) |
| 1577 | continue; |
| 1578 | |
| 1579 | crtc_state->enable = |
| 1580 | drm_atomic_connectors_for_crtc(state, crtc); |
| 1581 | } |
| 1582 | |
| 1583 | return 0; |
| 1584 | } |
| 1585 | |
| 1586 | /** |
| 1587 | * drm_atomic_helper_set_config - set a new config from userspace |
| 1588 | * @set: mode set configuration |
| 1589 | * |
| 1590 | * Provides a default crtc set_config handler using the atomic driver interface. |
| 1591 | * |
| 1592 | * Returns: |
| 1593 | * Returns 0 on success, negative errno numbers on failure. |
| 1594 | */ |
| 1595 | int drm_atomic_helper_set_config(struct drm_mode_set *set) |
| 1596 | { |
| 1597 | struct drm_atomic_state *state; |
| 1598 | struct drm_crtc *crtc = set->crtc; |
| 1599 | struct drm_crtc_state *crtc_state; |
| 1600 | struct drm_plane_state *primary_state; |
| 1601 | int ret = 0; |
| 1602 | |
| 1603 | state = drm_atomic_state_alloc(crtc->dev); |
| 1604 | if (!state) |
| 1605 | return -ENOMEM; |
| 1606 | |
| 1607 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 1608 | retry: |
| 1609 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 1610 | if (IS_ERR(crtc_state)) { |
| 1611 | ret = PTR_ERR(crtc_state); |
| 1612 | goto fail; |
| 1613 | } |
| 1614 | |
Rob Clark | e5b5341 | 2014-11-26 18:58:04 -0500 | [diff] [blame] | 1615 | primary_state = drm_atomic_get_plane_state(state, crtc->primary); |
| 1616 | if (IS_ERR(primary_state)) { |
| 1617 | ret = PTR_ERR(primary_state); |
| 1618 | goto fail; |
| 1619 | } |
| 1620 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1621 | if (!set->mode) { |
| 1622 | WARN_ON(set->fb); |
| 1623 | WARN_ON(set->num_connectors); |
| 1624 | |
| 1625 | crtc_state->enable = false; |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 1626 | crtc_state->active = false; |
Rob Clark | e5b5341 | 2014-11-26 18:58:04 -0500 | [diff] [blame] | 1627 | |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 1628 | ret = drm_atomic_set_crtc_for_plane(primary_state, NULL); |
Rob Clark | e5b5341 | 2014-11-26 18:58:04 -0500 | [diff] [blame] | 1629 | if (ret != 0) |
| 1630 | goto fail; |
| 1631 | |
| 1632 | drm_atomic_set_fb_for_plane(primary_state, NULL); |
| 1633 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1634 | goto commit; |
| 1635 | } |
| 1636 | |
| 1637 | WARN_ON(!set->fb); |
| 1638 | WARN_ON(!set->num_connectors); |
| 1639 | |
| 1640 | crtc_state->enable = true; |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 1641 | crtc_state->active = true; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1642 | drm_mode_copy(&crtc_state->mode, set->mode); |
| 1643 | |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 1644 | ret = drm_atomic_set_crtc_for_plane(primary_state, crtc); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1645 | if (ret != 0) |
| 1646 | goto fail; |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 1647 | drm_atomic_set_fb_for_plane(primary_state, set->fb); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1648 | primary_state->crtc_x = 0; |
| 1649 | primary_state->crtc_y = 0; |
| 1650 | primary_state->crtc_h = set->mode->vdisplay; |
| 1651 | primary_state->crtc_w = set->mode->hdisplay; |
| 1652 | primary_state->src_x = set->x << 16; |
| 1653 | primary_state->src_y = set->y << 16; |
| 1654 | primary_state->src_h = set->mode->vdisplay << 16; |
| 1655 | primary_state->src_w = set->mode->hdisplay << 16; |
| 1656 | |
| 1657 | commit: |
| 1658 | ret = update_output_state(state, set); |
| 1659 | if (ret) |
| 1660 | goto fail; |
| 1661 | |
| 1662 | ret = drm_atomic_commit(state); |
| 1663 | if (ret != 0) |
| 1664 | goto fail; |
| 1665 | |
| 1666 | /* Driver takes ownership of state on successful commit. */ |
| 1667 | return 0; |
| 1668 | fail: |
| 1669 | if (ret == -EDEADLK) |
| 1670 | goto backoff; |
| 1671 | |
| 1672 | drm_atomic_state_free(state); |
| 1673 | |
| 1674 | return ret; |
| 1675 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1676 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 1677 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1678 | |
| 1679 | /* |
| 1680 | * Someone might have exchanged the framebuffer while we dropped locks |
| 1681 | * in the backoff code. We need to fix up the fb refcount tracking the |
| 1682 | * core does for us. |
| 1683 | */ |
| 1684 | crtc->primary->old_fb = crtc->primary->fb; |
| 1685 | |
| 1686 | goto retry; |
| 1687 | } |
| 1688 | EXPORT_SYMBOL(drm_atomic_helper_set_config); |
| 1689 | |
| 1690 | /** |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 1691 | * drm_atomic_helper_crtc_set_property - helper for crtc properties |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1692 | * @crtc: DRM crtc |
| 1693 | * @property: DRM property |
| 1694 | * @val: value of property |
| 1695 | * |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 1696 | * Provides a default crtc set_property handler using the atomic driver |
| 1697 | * interface. |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1698 | * |
| 1699 | * RETURNS: |
| 1700 | * Zero on success, error code on failure |
| 1701 | */ |
| 1702 | int |
| 1703 | drm_atomic_helper_crtc_set_property(struct drm_crtc *crtc, |
| 1704 | struct drm_property *property, |
| 1705 | uint64_t val) |
| 1706 | { |
| 1707 | struct drm_atomic_state *state; |
| 1708 | struct drm_crtc_state *crtc_state; |
| 1709 | int ret = 0; |
| 1710 | |
| 1711 | state = drm_atomic_state_alloc(crtc->dev); |
| 1712 | if (!state) |
| 1713 | return -ENOMEM; |
| 1714 | |
| 1715 | /* ->set_property is always called with all locks held. */ |
| 1716 | state->acquire_ctx = crtc->dev->mode_config.acquire_ctx; |
| 1717 | retry: |
| 1718 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 1719 | if (IS_ERR(crtc_state)) { |
| 1720 | ret = PTR_ERR(crtc_state); |
| 1721 | goto fail; |
| 1722 | } |
| 1723 | |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 1724 | ret = drm_atomic_crtc_set_property(crtc, crtc_state, |
| 1725 | property, val); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1726 | if (ret) |
| 1727 | goto fail; |
| 1728 | |
| 1729 | ret = drm_atomic_commit(state); |
| 1730 | if (ret != 0) |
| 1731 | goto fail; |
| 1732 | |
| 1733 | /* Driver takes ownership of state on successful commit. */ |
| 1734 | return 0; |
| 1735 | fail: |
| 1736 | if (ret == -EDEADLK) |
| 1737 | goto backoff; |
| 1738 | |
| 1739 | drm_atomic_state_free(state); |
| 1740 | |
| 1741 | return ret; |
| 1742 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1743 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 1744 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1745 | |
| 1746 | goto retry; |
| 1747 | } |
| 1748 | EXPORT_SYMBOL(drm_atomic_helper_crtc_set_property); |
| 1749 | |
| 1750 | /** |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 1751 | * drm_atomic_helper_plane_set_property - helper for plane properties |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1752 | * @plane: DRM plane |
| 1753 | * @property: DRM property |
| 1754 | * @val: value of property |
| 1755 | * |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 1756 | * Provides a default plane set_property handler using the atomic driver |
| 1757 | * interface. |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1758 | * |
| 1759 | * RETURNS: |
| 1760 | * Zero on success, error code on failure |
| 1761 | */ |
| 1762 | int |
| 1763 | drm_atomic_helper_plane_set_property(struct drm_plane *plane, |
| 1764 | struct drm_property *property, |
| 1765 | uint64_t val) |
| 1766 | { |
| 1767 | struct drm_atomic_state *state; |
| 1768 | struct drm_plane_state *plane_state; |
| 1769 | int ret = 0; |
| 1770 | |
| 1771 | state = drm_atomic_state_alloc(plane->dev); |
| 1772 | if (!state) |
| 1773 | return -ENOMEM; |
| 1774 | |
| 1775 | /* ->set_property is always called with all locks held. */ |
| 1776 | state->acquire_ctx = plane->dev->mode_config.acquire_ctx; |
| 1777 | retry: |
| 1778 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 1779 | if (IS_ERR(plane_state)) { |
| 1780 | ret = PTR_ERR(plane_state); |
| 1781 | goto fail; |
| 1782 | } |
| 1783 | |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 1784 | ret = drm_atomic_plane_set_property(plane, plane_state, |
| 1785 | property, val); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1786 | if (ret) |
| 1787 | goto fail; |
| 1788 | |
| 1789 | ret = drm_atomic_commit(state); |
| 1790 | if (ret != 0) |
| 1791 | goto fail; |
| 1792 | |
| 1793 | /* Driver takes ownership of state on successful commit. */ |
| 1794 | return 0; |
| 1795 | fail: |
| 1796 | if (ret == -EDEADLK) |
| 1797 | goto backoff; |
| 1798 | |
| 1799 | drm_atomic_state_free(state); |
| 1800 | |
| 1801 | return ret; |
| 1802 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1803 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 1804 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1805 | |
| 1806 | goto retry; |
| 1807 | } |
| 1808 | EXPORT_SYMBOL(drm_atomic_helper_plane_set_property); |
| 1809 | |
| 1810 | /** |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 1811 | * drm_atomic_helper_connector_set_property - helper for connector properties |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1812 | * @connector: DRM connector |
| 1813 | * @property: DRM property |
| 1814 | * @val: value of property |
| 1815 | * |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 1816 | * Provides a default connector set_property handler using the atomic driver |
| 1817 | * interface. |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1818 | * |
| 1819 | * RETURNS: |
| 1820 | * Zero on success, error code on failure |
| 1821 | */ |
| 1822 | int |
| 1823 | drm_atomic_helper_connector_set_property(struct drm_connector *connector, |
| 1824 | struct drm_property *property, |
| 1825 | uint64_t val) |
| 1826 | { |
| 1827 | struct drm_atomic_state *state; |
| 1828 | struct drm_connector_state *connector_state; |
| 1829 | int ret = 0; |
| 1830 | |
| 1831 | state = drm_atomic_state_alloc(connector->dev); |
| 1832 | if (!state) |
| 1833 | return -ENOMEM; |
| 1834 | |
| 1835 | /* ->set_property is always called with all locks held. */ |
| 1836 | state->acquire_ctx = connector->dev->mode_config.acquire_ctx; |
| 1837 | retry: |
| 1838 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 1839 | if (IS_ERR(connector_state)) { |
| 1840 | ret = PTR_ERR(connector_state); |
| 1841 | goto fail; |
| 1842 | } |
| 1843 | |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 1844 | ret = drm_atomic_connector_set_property(connector, connector_state, |
| 1845 | property, val); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1846 | if (ret) |
| 1847 | goto fail; |
| 1848 | |
| 1849 | ret = drm_atomic_commit(state); |
| 1850 | if (ret != 0) |
| 1851 | goto fail; |
| 1852 | |
| 1853 | /* Driver takes ownership of state on successful commit. */ |
| 1854 | return 0; |
| 1855 | fail: |
| 1856 | if (ret == -EDEADLK) |
| 1857 | goto backoff; |
| 1858 | |
| 1859 | drm_atomic_state_free(state); |
| 1860 | |
| 1861 | return ret; |
| 1862 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1863 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 1864 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 1865 | |
| 1866 | goto retry; |
| 1867 | } |
| 1868 | EXPORT_SYMBOL(drm_atomic_helper_connector_set_property); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 1869 | |
| 1870 | /** |
| 1871 | * drm_atomic_helper_page_flip - execute a legacy page flip |
| 1872 | * @crtc: DRM crtc |
| 1873 | * @fb: DRM framebuffer |
| 1874 | * @event: optional DRM event to signal upon completion |
| 1875 | * @flags: flip flags for non-vblank sync'ed updates |
| 1876 | * |
| 1877 | * Provides a default page flip implementation using the atomic driver interface. |
| 1878 | * |
| 1879 | * Note that for now so called async page flips (i.e. updates which are not |
| 1880 | * synchronized to vblank) are not supported, since the atomic interfaces have |
| 1881 | * no provisions for this yet. |
| 1882 | * |
| 1883 | * Returns: |
| 1884 | * Returns 0 on success, negative errno numbers on failure. |
| 1885 | */ |
| 1886 | int drm_atomic_helper_page_flip(struct drm_crtc *crtc, |
| 1887 | struct drm_framebuffer *fb, |
| 1888 | struct drm_pending_vblank_event *event, |
| 1889 | uint32_t flags) |
| 1890 | { |
| 1891 | struct drm_plane *plane = crtc->primary; |
| 1892 | struct drm_atomic_state *state; |
| 1893 | struct drm_plane_state *plane_state; |
| 1894 | struct drm_crtc_state *crtc_state; |
| 1895 | int ret = 0; |
| 1896 | |
| 1897 | if (flags & DRM_MODE_PAGE_FLIP_ASYNC) |
| 1898 | return -EINVAL; |
| 1899 | |
| 1900 | state = drm_atomic_state_alloc(plane->dev); |
| 1901 | if (!state) |
| 1902 | return -ENOMEM; |
| 1903 | |
| 1904 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 1905 | retry: |
| 1906 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 1907 | if (IS_ERR(crtc_state)) { |
| 1908 | ret = PTR_ERR(crtc_state); |
| 1909 | goto fail; |
| 1910 | } |
| 1911 | crtc_state->event = event; |
| 1912 | |
| 1913 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 1914 | if (IS_ERR(plane_state)) { |
| 1915 | ret = PTR_ERR(plane_state); |
| 1916 | goto fail; |
| 1917 | } |
| 1918 | |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 1919 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 1920 | if (ret != 0) |
| 1921 | goto fail; |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 1922 | drm_atomic_set_fb_for_plane(plane_state, fb); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 1923 | |
| 1924 | ret = drm_atomic_async_commit(state); |
| 1925 | if (ret != 0) |
| 1926 | goto fail; |
| 1927 | |
| 1928 | /* TODO: ->page_flip is the only driver callback where the core |
| 1929 | * doesn't update plane->fb. For now patch it up here. */ |
| 1930 | plane->fb = plane->state->fb; |
| 1931 | |
| 1932 | /* Driver takes ownership of state on successful async commit. */ |
| 1933 | return 0; |
| 1934 | fail: |
| 1935 | if (ret == -EDEADLK) |
| 1936 | goto backoff; |
| 1937 | |
| 1938 | drm_atomic_state_free(state); |
| 1939 | |
| 1940 | return ret; |
| 1941 | backoff: |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 1942 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 1943 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 1944 | |
| 1945 | /* |
| 1946 | * Someone might have exchanged the framebuffer while we dropped locks |
| 1947 | * in the backoff code. We need to fix up the fb refcount tracking the |
| 1948 | * core does for us. |
| 1949 | */ |
| 1950 | plane->old_fb = plane->fb; |
| 1951 | |
| 1952 | goto retry; |
| 1953 | } |
| 1954 | EXPORT_SYMBOL(drm_atomic_helper_page_flip); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 1955 | |
| 1956 | /** |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 1957 | * drm_atomic_helper_connector_dpms() - connector dpms helper implementation |
| 1958 | * @connector: affected connector |
| 1959 | * @mode: DPMS mode |
| 1960 | * |
| 1961 | * This is the main helper function provided by the atomic helper framework for |
| 1962 | * implementing the legacy DPMS connector interface. It computes the new desired |
| 1963 | * ->active state for the corresponding CRTC (if the connector is enabled) and |
| 1964 | * updates it. |
| 1965 | */ |
| 1966 | void drm_atomic_helper_connector_dpms(struct drm_connector *connector, |
| 1967 | int mode) |
| 1968 | { |
| 1969 | struct drm_mode_config *config = &connector->dev->mode_config; |
| 1970 | struct drm_atomic_state *state; |
| 1971 | struct drm_crtc_state *crtc_state; |
| 1972 | struct drm_crtc *crtc; |
| 1973 | struct drm_connector *tmp_connector; |
| 1974 | int ret; |
| 1975 | bool active = false; |
| 1976 | |
| 1977 | if (mode != DRM_MODE_DPMS_ON) |
| 1978 | mode = DRM_MODE_DPMS_OFF; |
| 1979 | |
| 1980 | connector->dpms = mode; |
| 1981 | crtc = connector->state->crtc; |
| 1982 | |
| 1983 | if (!crtc) |
| 1984 | return; |
| 1985 | |
| 1986 | /* FIXME: ->dpms has no return value so can't forward the -ENOMEM. */ |
| 1987 | state = drm_atomic_state_alloc(connector->dev); |
| 1988 | if (!state) |
| 1989 | return; |
| 1990 | |
| 1991 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 1992 | retry: |
| 1993 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 1994 | if (IS_ERR(crtc_state)) |
| 1995 | return; |
| 1996 | |
| 1997 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
| 1998 | |
| 1999 | list_for_each_entry(tmp_connector, &config->connector_list, head) { |
| 2000 | if (connector->state->crtc != crtc) |
| 2001 | continue; |
| 2002 | |
| 2003 | if (connector->dpms == DRM_MODE_DPMS_ON) { |
| 2004 | active = true; |
| 2005 | break; |
| 2006 | } |
| 2007 | } |
| 2008 | crtc_state->active = active; |
| 2009 | |
| 2010 | ret = drm_atomic_commit(state); |
| 2011 | if (ret != 0) |
| 2012 | goto fail; |
| 2013 | |
| 2014 | /* Driver takes ownership of state on successful async commit. */ |
| 2015 | return; |
| 2016 | fail: |
| 2017 | if (ret == -EDEADLK) |
| 2018 | goto backoff; |
| 2019 | |
| 2020 | drm_atomic_state_free(state); |
| 2021 | |
| 2022 | WARN(1, "Driver bug: Changing ->active failed with ret=%i\n", ret); |
| 2023 | |
| 2024 | return; |
| 2025 | backoff: |
| 2026 | drm_atomic_state_clear(state); |
| 2027 | drm_atomic_legacy_backoff(state); |
| 2028 | |
| 2029 | goto retry; |
| 2030 | } |
| 2031 | EXPORT_SYMBOL(drm_atomic_helper_connector_dpms); |
| 2032 | |
| 2033 | /** |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 2034 | * DOC: atomic state reset and initialization |
| 2035 | * |
| 2036 | * Both the drm core and the atomic helpers assume that there is always the full |
| 2037 | * and correct atomic software state for all connectors, CRTCs and planes |
| 2038 | * available. Which is a bit a problem on driver load and also after system |
| 2039 | * suspend. One way to solve this is to have a hardware state read-out |
| 2040 | * infrastructure which reconstructs the full software state (e.g. the i915 |
| 2041 | * driver). |
| 2042 | * |
| 2043 | * The simpler solution is to just reset the software state to everything off, |
| 2044 | * which is easiest to do by calling drm_mode_config_reset(). To facilitate this |
| 2045 | * the atomic helpers provide default reset implementations for all hooks. |
| 2046 | */ |
| 2047 | |
| 2048 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2049 | * drm_atomic_helper_crtc_reset - default ->reset hook for CRTCs |
| 2050 | * @crtc: drm CRTC |
| 2051 | * |
| 2052 | * Resets the atomic state for @crtc by freeing the state pointer (which might |
| 2053 | * be NULL, e.g. at driver load time) and allocating a new empty state object. |
| 2054 | */ |
| 2055 | void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc) |
| 2056 | { |
| 2057 | kfree(crtc->state); |
| 2058 | crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL); |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 2059 | |
| 2060 | if (crtc->state) |
| 2061 | crtc->state->crtc = crtc; |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2062 | } |
| 2063 | EXPORT_SYMBOL(drm_atomic_helper_crtc_reset); |
| 2064 | |
| 2065 | /** |
| 2066 | * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook |
| 2067 | * @crtc: drm CRTC |
| 2068 | * |
| 2069 | * Default CRTC state duplicate hook for drivers which don't have their own |
| 2070 | * subclassed CRTC state structure. |
| 2071 | */ |
| 2072 | struct drm_crtc_state * |
| 2073 | drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc) |
| 2074 | { |
| 2075 | struct drm_crtc_state *state; |
| 2076 | |
| 2077 | if (WARN_ON(!crtc->state)) |
| 2078 | return NULL; |
| 2079 | |
| 2080 | state = kmemdup(crtc->state, sizeof(*crtc->state), GFP_KERNEL); |
| 2081 | |
| 2082 | if (state) { |
| 2083 | state->mode_changed = false; |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 2084 | state->active_changed = false; |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2085 | state->planes_changed = false; |
| 2086 | state->event = NULL; |
| 2087 | } |
| 2088 | |
| 2089 | return state; |
| 2090 | } |
| 2091 | EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state); |
| 2092 | |
| 2093 | /** |
| 2094 | * drm_atomic_helper_crtc_destroy_state - default state destroy hook |
| 2095 | * @crtc: drm CRTC |
| 2096 | * @state: CRTC state object to release |
| 2097 | * |
| 2098 | * Default CRTC state destroy hook for drivers which don't have their own |
| 2099 | * subclassed CRTC state structure. |
| 2100 | */ |
| 2101 | void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc, |
| 2102 | struct drm_crtc_state *state) |
| 2103 | { |
| 2104 | kfree(state); |
| 2105 | } |
| 2106 | EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state); |
| 2107 | |
| 2108 | /** |
| 2109 | * drm_atomic_helper_plane_reset - default ->reset hook for planes |
| 2110 | * @plane: drm plane |
| 2111 | * |
| 2112 | * Resets the atomic state for @plane by freeing the state pointer (which might |
| 2113 | * be NULL, e.g. at driver load time) and allocating a new empty state object. |
| 2114 | */ |
| 2115 | void drm_atomic_helper_plane_reset(struct drm_plane *plane) |
| 2116 | { |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 2117 | if (plane->state && plane->state->fb) |
| 2118 | drm_framebuffer_unreference(plane->state->fb); |
| 2119 | |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2120 | kfree(plane->state); |
| 2121 | plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL); |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 2122 | |
| 2123 | if (plane->state) |
| 2124 | plane->state->plane = plane; |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2125 | } |
| 2126 | EXPORT_SYMBOL(drm_atomic_helper_plane_reset); |
| 2127 | |
| 2128 | /** |
| 2129 | * drm_atomic_helper_plane_duplicate_state - default state duplicate hook |
| 2130 | * @plane: drm plane |
| 2131 | * |
| 2132 | * Default plane state duplicate hook for drivers which don't have their own |
| 2133 | * subclassed plane state structure. |
| 2134 | */ |
| 2135 | struct drm_plane_state * |
| 2136 | drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane) |
| 2137 | { |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 2138 | struct drm_plane_state *state; |
| 2139 | |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2140 | if (WARN_ON(!plane->state)) |
| 2141 | return NULL; |
| 2142 | |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 2143 | state = kmemdup(plane->state, sizeof(*plane->state), GFP_KERNEL); |
| 2144 | |
| 2145 | if (state && state->fb) |
| 2146 | drm_framebuffer_reference(state->fb); |
| 2147 | |
| 2148 | return state; |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2149 | } |
| 2150 | EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state); |
| 2151 | |
| 2152 | /** |
| 2153 | * drm_atomic_helper_plane_destroy_state - default state destroy hook |
| 2154 | * @plane: drm plane |
| 2155 | * @state: plane state object to release |
| 2156 | * |
| 2157 | * Default plane state destroy hook for drivers which don't have their own |
| 2158 | * subclassed plane state structure. |
| 2159 | */ |
| 2160 | void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane, |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 2161 | struct drm_plane_state *state) |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2162 | { |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 2163 | if (state->fb) |
| 2164 | drm_framebuffer_unreference(state->fb); |
| 2165 | |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2166 | kfree(state); |
| 2167 | } |
| 2168 | EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state); |
| 2169 | |
| 2170 | /** |
| 2171 | * drm_atomic_helper_connector_reset - default ->reset hook for connectors |
| 2172 | * @connector: drm connector |
| 2173 | * |
| 2174 | * Resets the atomic state for @connector by freeing the state pointer (which |
| 2175 | * might be NULL, e.g. at driver load time) and allocating a new empty state |
| 2176 | * object. |
| 2177 | */ |
| 2178 | void drm_atomic_helper_connector_reset(struct drm_connector *connector) |
| 2179 | { |
| 2180 | kfree(connector->state); |
| 2181 | connector->state = kzalloc(sizeof(*connector->state), GFP_KERNEL); |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 2182 | |
| 2183 | if (connector->state) |
| 2184 | connector->state->connector = connector; |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2185 | } |
| 2186 | EXPORT_SYMBOL(drm_atomic_helper_connector_reset); |
| 2187 | |
| 2188 | /** |
| 2189 | * drm_atomic_helper_connector_duplicate_state - default state duplicate hook |
| 2190 | * @connector: drm connector |
| 2191 | * |
| 2192 | * Default connector state duplicate hook for drivers which don't have their own |
| 2193 | * subclassed connector state structure. |
| 2194 | */ |
| 2195 | struct drm_connector_state * |
| 2196 | drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector) |
| 2197 | { |
| 2198 | if (WARN_ON(!connector->state)) |
| 2199 | return NULL; |
| 2200 | |
| 2201 | return kmemdup(connector->state, sizeof(*connector->state), GFP_KERNEL); |
| 2202 | } |
| 2203 | EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state); |
| 2204 | |
| 2205 | /** |
| 2206 | * drm_atomic_helper_connector_destroy_state - default state destroy hook |
| 2207 | * @connector: drm connector |
| 2208 | * @state: connector state object to release |
| 2209 | * |
| 2210 | * Default connector state destroy hook for drivers which don't have their own |
| 2211 | * subclassed connector state structure. |
| 2212 | */ |
| 2213 | void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector, |
| 2214 | struct drm_connector_state *state) |
| 2215 | { |
| 2216 | kfree(state); |
| 2217 | } |
| 2218 | EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state); |