Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [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 | |
| 29 | #include <drm/drmP.h> |
| 30 | #include <drm/drm_atomic.h> |
| 31 | #include <drm/drm_plane_helper.h> |
| 32 | |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 33 | /** |
| 34 | * drm_atomic_state_default_release - |
| 35 | * release memory initialized by drm_atomic_state_init |
| 36 | * @state: atomic state |
| 37 | * |
| 38 | * Free all the memory allocated by drm_atomic_state_init. |
| 39 | * This is useful for drivers that subclass the atomic state. |
| 40 | */ |
| 41 | void drm_atomic_state_default_release(struct drm_atomic_state *state) |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 42 | { |
| 43 | kfree(state->connectors); |
| 44 | kfree(state->connector_states); |
| 45 | kfree(state->crtcs); |
| 46 | kfree(state->crtc_states); |
| 47 | kfree(state->planes); |
| 48 | kfree(state->plane_states); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 49 | } |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 50 | EXPORT_SYMBOL(drm_atomic_state_default_release); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 51 | |
| 52 | /** |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 53 | * drm_atomic_state_init - init new atomic state |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 54 | * @dev: DRM device |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 55 | * @state: atomic state |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 56 | * |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 57 | * Default implementation for filling in a new atomic state. |
| 58 | * This is useful for drivers that subclass the atomic state. |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 59 | */ |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 60 | int |
| 61 | drm_atomic_state_init(struct drm_device *dev, struct drm_atomic_state *state) |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 62 | { |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 63 | /* TODO legacy paths should maybe do a better job about |
| 64 | * setting this appropriately? |
| 65 | */ |
| 66 | state->allow_modeset = true; |
| 67 | |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 68 | state->num_connector = ACCESS_ONCE(dev->mode_config.num_connector); |
| 69 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 70 | state->crtcs = kcalloc(dev->mode_config.num_crtc, |
| 71 | sizeof(*state->crtcs), GFP_KERNEL); |
| 72 | if (!state->crtcs) |
| 73 | goto fail; |
| 74 | state->crtc_states = kcalloc(dev->mode_config.num_crtc, |
| 75 | sizeof(*state->crtc_states), GFP_KERNEL); |
| 76 | if (!state->crtc_states) |
| 77 | goto fail; |
| 78 | state->planes = kcalloc(dev->mode_config.num_total_plane, |
| 79 | sizeof(*state->planes), GFP_KERNEL); |
| 80 | if (!state->planes) |
| 81 | goto fail; |
| 82 | state->plane_states = kcalloc(dev->mode_config.num_total_plane, |
| 83 | sizeof(*state->plane_states), GFP_KERNEL); |
| 84 | if (!state->plane_states) |
| 85 | goto fail; |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 86 | state->connectors = kcalloc(state->num_connector, |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 87 | sizeof(*state->connectors), |
| 88 | GFP_KERNEL); |
| 89 | if (!state->connectors) |
| 90 | goto fail; |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 91 | state->connector_states = kcalloc(state->num_connector, |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 92 | sizeof(*state->connector_states), |
| 93 | GFP_KERNEL); |
| 94 | if (!state->connector_states) |
| 95 | goto fail; |
| 96 | |
| 97 | state->dev = dev; |
| 98 | |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 99 | DRM_DEBUG_ATOMIC("Allocated atomic state %p\n", state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 100 | |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 101 | return 0; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 102 | fail: |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 103 | drm_atomic_state_default_release(state); |
| 104 | return -ENOMEM; |
| 105 | } |
| 106 | EXPORT_SYMBOL(drm_atomic_state_init); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 107 | |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 108 | /** |
| 109 | * drm_atomic_state_alloc - allocate atomic state |
| 110 | * @dev: DRM device |
| 111 | * |
| 112 | * This allocates an empty atomic state to track updates. |
| 113 | */ |
| 114 | struct drm_atomic_state * |
| 115 | drm_atomic_state_alloc(struct drm_device *dev) |
| 116 | { |
| 117 | struct drm_mode_config *config = &dev->mode_config; |
| 118 | struct drm_atomic_state *state; |
| 119 | |
| 120 | if (!config->funcs->atomic_state_alloc) { |
| 121 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
| 122 | if (!state) |
| 123 | return NULL; |
| 124 | if (drm_atomic_state_init(dev, state) < 0) { |
| 125 | kfree(state); |
| 126 | return NULL; |
| 127 | } |
| 128 | return state; |
| 129 | } |
| 130 | |
| 131 | return config->funcs->atomic_state_alloc(dev); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 132 | } |
| 133 | EXPORT_SYMBOL(drm_atomic_state_alloc); |
| 134 | |
| 135 | /** |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 136 | * drm_atomic_state_default_clear - clear base atomic state |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 137 | * @state: atomic state |
| 138 | * |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 139 | * Default implementation for clearing atomic state. |
| 140 | * This is useful for drivers that subclass the atomic state. |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 141 | */ |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 142 | void drm_atomic_state_default_clear(struct drm_atomic_state *state) |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 143 | { |
| 144 | struct drm_device *dev = state->dev; |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 145 | struct drm_mode_config *config = &dev->mode_config; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 146 | int i; |
| 147 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 148 | DRM_DEBUG_ATOMIC("Clearing atomic state %p\n", state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 149 | |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 150 | for (i = 0; i < state->num_connector; i++) { |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 151 | struct drm_connector *connector = state->connectors[i]; |
| 152 | |
| 153 | if (!connector) |
| 154 | continue; |
| 155 | |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 156 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
| 157 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 158 | connector->funcs->atomic_destroy_state(connector, |
| 159 | state->connector_states[i]); |
Ander Conselvan de Oliveira | 8a5c0bd | 2015-03-30 10:41:19 +0300 | [diff] [blame] | 160 | state->connectors[i] = NULL; |
Ander Conselvan de Oliveira | 9469244 | 2015-01-23 09:27:59 +0200 | [diff] [blame] | 161 | state->connector_states[i] = NULL; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 162 | } |
| 163 | |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 164 | for (i = 0; i < config->num_crtc; i++) { |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 165 | struct drm_crtc *crtc = state->crtcs[i]; |
| 166 | |
| 167 | if (!crtc) |
| 168 | continue; |
| 169 | |
| 170 | crtc->funcs->atomic_destroy_state(crtc, |
| 171 | state->crtc_states[i]); |
Ander Conselvan de Oliveira | 8a5c0bd | 2015-03-30 10:41:19 +0300 | [diff] [blame] | 172 | state->crtcs[i] = NULL; |
Ander Conselvan de Oliveira | 9469244 | 2015-01-23 09:27:59 +0200 | [diff] [blame] | 173 | state->crtc_states[i] = NULL; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 176 | for (i = 0; i < config->num_total_plane; i++) { |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 177 | struct drm_plane *plane = state->planes[i]; |
| 178 | |
| 179 | if (!plane) |
| 180 | continue; |
| 181 | |
| 182 | plane->funcs->atomic_destroy_state(plane, |
| 183 | state->plane_states[i]); |
Ander Conselvan de Oliveira | 8a5c0bd | 2015-03-30 10:41:19 +0300 | [diff] [blame] | 184 | state->planes[i] = NULL; |
Ander Conselvan de Oliveira | 9469244 | 2015-01-23 09:27:59 +0200 | [diff] [blame] | 185 | state->plane_states[i] = NULL; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 186 | } |
| 187 | } |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 188 | EXPORT_SYMBOL(drm_atomic_state_default_clear); |
| 189 | |
| 190 | /** |
| 191 | * drm_atomic_state_clear - clear state object |
| 192 | * @state: atomic state |
| 193 | * |
| 194 | * When the w/w mutex algorithm detects a deadlock we need to back off and drop |
| 195 | * all locks. So someone else could sneak in and change the current modeset |
| 196 | * configuration. Which means that all the state assembled in @state is no |
| 197 | * longer an atomic update to the current state, but to some arbitrary earlier |
| 198 | * state. Which could break assumptions the driver's ->atomic_check likely |
| 199 | * relies on. |
| 200 | * |
| 201 | * Hence we must clear all cached state and completely start over, using this |
| 202 | * function. |
| 203 | */ |
| 204 | void drm_atomic_state_clear(struct drm_atomic_state *state) |
| 205 | { |
| 206 | struct drm_device *dev = state->dev; |
| 207 | struct drm_mode_config *config = &dev->mode_config; |
| 208 | |
| 209 | if (config->funcs->atomic_state_clear) |
| 210 | config->funcs->atomic_state_clear(state); |
| 211 | else |
| 212 | drm_atomic_state_default_clear(state); |
| 213 | } |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 214 | EXPORT_SYMBOL(drm_atomic_state_clear); |
| 215 | |
| 216 | /** |
| 217 | * drm_atomic_state_free - free all memory for an atomic state |
| 218 | * @state: atomic state to deallocate |
| 219 | * |
| 220 | * This frees all memory associated with an atomic state, including all the |
| 221 | * per-object state for planes, crtcs and connectors. |
| 222 | */ |
| 223 | void drm_atomic_state_free(struct drm_atomic_state *state) |
| 224 | { |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 225 | struct drm_device *dev; |
| 226 | struct drm_mode_config *config; |
| 227 | |
Ander Conselvan de Oliveira | a0211bb | 2015-03-30 14:05:43 +0300 | [diff] [blame] | 228 | if (!state) |
| 229 | return; |
| 230 | |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 231 | dev = state->dev; |
| 232 | config = &dev->mode_config; |
| 233 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 234 | drm_atomic_state_clear(state); |
| 235 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 236 | DRM_DEBUG_ATOMIC("Freeing atomic state %p\n", state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 237 | |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 238 | if (config->funcs->atomic_state_free) { |
| 239 | config->funcs->atomic_state_free(state); |
| 240 | } else { |
| 241 | drm_atomic_state_default_release(state); |
| 242 | kfree(state); |
| 243 | } |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 244 | } |
| 245 | EXPORT_SYMBOL(drm_atomic_state_free); |
| 246 | |
| 247 | /** |
| 248 | * drm_atomic_get_crtc_state - get crtc state |
| 249 | * @state: global atomic state object |
| 250 | * @crtc: crtc to get state object for |
| 251 | * |
| 252 | * This function returns the crtc state for the given crtc, allocating it if |
| 253 | * needed. It will also grab the relevant crtc lock to make sure that the state |
| 254 | * is consistent. |
| 255 | * |
| 256 | * Returns: |
| 257 | * |
| 258 | * Either the allocated state or the error code encoded into the pointer. When |
| 259 | * the error is EDEADLK then the w/w mutex code has detected a deadlock and the |
| 260 | * entire atomic sequence must be restarted. All other errors are fatal. |
| 261 | */ |
| 262 | struct drm_crtc_state * |
| 263 | drm_atomic_get_crtc_state(struct drm_atomic_state *state, |
| 264 | struct drm_crtc *crtc) |
| 265 | { |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 266 | int ret, index = drm_crtc_index(crtc); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 267 | struct drm_crtc_state *crtc_state; |
| 268 | |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 269 | crtc_state = drm_atomic_get_existing_crtc_state(state, crtc); |
| 270 | if (crtc_state) |
| 271 | return crtc_state; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 272 | |
| 273 | ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx); |
| 274 | if (ret) |
| 275 | return ERR_PTR(ret); |
| 276 | |
| 277 | crtc_state = crtc->funcs->atomic_duplicate_state(crtc); |
| 278 | if (!crtc_state) |
| 279 | return ERR_PTR(-ENOMEM); |
| 280 | |
| 281 | state->crtc_states[index] = crtc_state; |
| 282 | state->crtcs[index] = crtc; |
| 283 | crtc_state->state = state; |
| 284 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 285 | DRM_DEBUG_ATOMIC("Added [CRTC:%d] %p state to %p\n", |
| 286 | crtc->base.id, crtc_state, state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 287 | |
| 288 | return crtc_state; |
| 289 | } |
| 290 | EXPORT_SYMBOL(drm_atomic_get_crtc_state); |
| 291 | |
| 292 | /** |
Daniel Stone | 819364d | 2015-05-26 14:36:48 +0100 | [diff] [blame] | 293 | * drm_atomic_set_mode_for_crtc - set mode for CRTC |
| 294 | * @state: the CRTC whose incoming state to update |
| 295 | * @mode: kernel-internal mode to use for the CRTC, or NULL to disable |
| 296 | * |
| 297 | * Set a mode (originating from the kernel) on the desired CRTC state. Does |
| 298 | * not change any other state properties, including enable, active, or |
| 299 | * mode_changed. |
| 300 | * |
| 301 | * RETURNS: |
| 302 | * Zero on success, error code on failure. Cannot return -EDEADLK. |
| 303 | */ |
| 304 | int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state, |
| 305 | struct drm_display_mode *mode) |
| 306 | { |
Daniel Stone | 99cf4a2 | 2015-05-25 19:11:51 +0100 | [diff] [blame] | 307 | struct drm_mode_modeinfo umode; |
| 308 | |
Daniel Stone | 819364d | 2015-05-26 14:36:48 +0100 | [diff] [blame] | 309 | /* Early return for no change. */ |
| 310 | if (mode && memcmp(&state->mode, mode, sizeof(*mode)) == 0) |
| 311 | return 0; |
| 312 | |
Daniel Stone | 99cf4a2 | 2015-05-25 19:11:51 +0100 | [diff] [blame] | 313 | if (state->mode_blob) |
| 314 | drm_property_unreference_blob(state->mode_blob); |
| 315 | state->mode_blob = NULL; |
| 316 | |
Daniel Stone | 819364d | 2015-05-26 14:36:48 +0100 | [diff] [blame] | 317 | if (mode) { |
Daniel Stone | 99cf4a2 | 2015-05-25 19:11:51 +0100 | [diff] [blame] | 318 | drm_mode_convert_to_umode(&umode, mode); |
| 319 | state->mode_blob = |
| 320 | drm_property_create_blob(state->crtc->dev, |
| 321 | sizeof(umode), |
| 322 | &umode); |
| 323 | if (IS_ERR(state->mode_blob)) |
| 324 | return PTR_ERR(state->mode_blob); |
| 325 | |
Daniel Stone | 819364d | 2015-05-26 14:36:48 +0100 | [diff] [blame] | 326 | drm_mode_copy(&state->mode, mode); |
| 327 | state->enable = true; |
| 328 | DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n", |
| 329 | mode->name, state); |
| 330 | } else { |
| 331 | memset(&state->mode, 0, sizeof(state->mode)); |
| 332 | state->enable = false; |
| 333 | DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n", |
| 334 | state); |
| 335 | } |
| 336 | |
| 337 | return 0; |
| 338 | } |
| 339 | EXPORT_SYMBOL(drm_atomic_set_mode_for_crtc); |
| 340 | |
Daniel Stone | 819364d | 2015-05-26 14:36:48 +0100 | [diff] [blame] | 341 | /** |
Daniel Stone | 955f3c3 | 2015-05-25 19:11:52 +0100 | [diff] [blame] | 342 | * drm_atomic_set_mode_prop_for_crtc - set mode for CRTC |
| 343 | * @state: the CRTC whose incoming state to update |
| 344 | * @blob: pointer to blob property to use for mode |
| 345 | * |
| 346 | * Set a mode (originating from a blob property) on the desired CRTC state. |
| 347 | * This function will take a reference on the blob property for the CRTC state, |
| 348 | * and release the reference held on the state's existing mode property, if any |
| 349 | * was set. |
| 350 | * |
| 351 | * RETURNS: |
| 352 | * Zero on success, error code on failure. Cannot return -EDEADLK. |
| 353 | */ |
| 354 | int drm_atomic_set_mode_prop_for_crtc(struct drm_crtc_state *state, |
| 355 | struct drm_property_blob *blob) |
| 356 | { |
| 357 | if (blob == state->mode_blob) |
| 358 | return 0; |
| 359 | |
| 360 | if (state->mode_blob) |
| 361 | drm_property_unreference_blob(state->mode_blob); |
| 362 | state->mode_blob = NULL; |
| 363 | |
| 364 | if (blob) { |
| 365 | if (blob->length != sizeof(struct drm_mode_modeinfo) || |
| 366 | drm_mode_convert_umode(&state->mode, |
| 367 | (const struct drm_mode_modeinfo *) |
| 368 | blob->data)) |
| 369 | return -EINVAL; |
| 370 | |
| 371 | state->mode_blob = drm_property_reference_blob(blob); |
| 372 | state->enable = true; |
| 373 | DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n", |
| 374 | state->mode.name, state); |
| 375 | } else { |
| 376 | memset(&state->mode, 0, sizeof(state->mode)); |
| 377 | state->enable = false; |
| 378 | DRM_DEBUG_ATOMIC("Set [NOMODE] for CRTC state %p\n", |
| 379 | state); |
| 380 | } |
| 381 | |
| 382 | return 0; |
| 383 | } |
| 384 | EXPORT_SYMBOL(drm_atomic_set_mode_prop_for_crtc); |
| 385 | |
| 386 | /** |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 387 | * drm_atomic_crtc_set_property - set property on CRTC |
| 388 | * @crtc: the drm CRTC to set a property on |
| 389 | * @state: the state object to update with the new property value |
| 390 | * @property: the property to set |
| 391 | * @val: the new property value |
| 392 | * |
| 393 | * Use this instead of calling crtc->atomic_set_property directly. |
| 394 | * This function handles generic/core properties and calls out to |
| 395 | * driver's ->atomic_set_property() for driver properties. To ensure |
| 396 | * consistent behavior you must call this function rather than the |
| 397 | * driver hook directly. |
| 398 | * |
| 399 | * RETURNS: |
| 400 | * Zero on success, error code on failure |
| 401 | */ |
| 402 | int drm_atomic_crtc_set_property(struct drm_crtc *crtc, |
| 403 | struct drm_crtc_state *state, struct drm_property *property, |
| 404 | uint64_t val) |
| 405 | { |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 406 | struct drm_device *dev = crtc->dev; |
| 407 | struct drm_mode_config *config = &dev->mode_config; |
Daniel Stone | 955f3c3 | 2015-05-25 19:11:52 +0100 | [diff] [blame] | 408 | int ret; |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 409 | |
Daniel Stone | 2779836 | 2015-03-19 04:33:26 +0000 | [diff] [blame] | 410 | if (property == config->prop_active) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 411 | state->active = val; |
Daniel Stone | 955f3c3 | 2015-05-25 19:11:52 +0100 | [diff] [blame] | 412 | else if (property == config->prop_mode_id) { |
| 413 | struct drm_property_blob *mode = |
| 414 | drm_property_lookup_blob(dev, val); |
| 415 | ret = drm_atomic_set_mode_prop_for_crtc(state, mode); |
| 416 | if (mode) |
| 417 | drm_property_unreference_blob(mode); |
| 418 | return ret; |
| 419 | } |
Daniel Stone | 2779836 | 2015-03-19 04:33:26 +0000 | [diff] [blame] | 420 | else if (crtc->funcs->atomic_set_property) |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 421 | return crtc->funcs->atomic_set_property(crtc, state, property, val); |
Daniel Stone | 2779836 | 2015-03-19 04:33:26 +0000 | [diff] [blame] | 422 | else |
| 423 | return -EINVAL; |
| 424 | |
| 425 | return 0; |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 426 | } |
| 427 | EXPORT_SYMBOL(drm_atomic_crtc_set_property); |
| 428 | |
Daniel Vetter | a97df1c | 2014-12-18 22:49:02 +0100 | [diff] [blame] | 429 | /* |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 430 | * This function handles generic/core properties and calls out to |
| 431 | * driver's ->atomic_get_property() for driver properties. To ensure |
| 432 | * consistent behavior you must call this function rather than the |
| 433 | * driver hook directly. |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 434 | */ |
| 435 | int drm_atomic_crtc_get_property(struct drm_crtc *crtc, |
| 436 | const struct drm_crtc_state *state, |
| 437 | struct drm_property *property, uint64_t *val) |
| 438 | { |
Daniel Stone | 8f164ce | 2015-03-19 04:33:25 +0000 | [diff] [blame] | 439 | struct drm_device *dev = crtc->dev; |
| 440 | struct drm_mode_config *config = &dev->mode_config; |
| 441 | |
| 442 | if (property == config->prop_active) |
| 443 | *val = state->active; |
Daniel Stone | 955f3c3 | 2015-05-25 19:11:52 +0100 | [diff] [blame] | 444 | else if (property == config->prop_mode_id) |
| 445 | *val = (state->mode_blob) ? state->mode_blob->base.id : 0; |
Daniel Stone | 8f164ce | 2015-03-19 04:33:25 +0000 | [diff] [blame] | 446 | else if (crtc->funcs->atomic_get_property) |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 447 | return crtc->funcs->atomic_get_property(crtc, state, property, val); |
Daniel Stone | 8f164ce | 2015-03-19 04:33:25 +0000 | [diff] [blame] | 448 | else |
| 449 | return -EINVAL; |
| 450 | |
| 451 | return 0; |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 452 | } |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 453 | |
| 454 | /** |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 455 | * drm_atomic_crtc_check - check crtc state |
| 456 | * @crtc: crtc to check |
| 457 | * @state: crtc state to check |
| 458 | * |
| 459 | * Provides core sanity checks for crtc state. |
| 460 | * |
| 461 | * RETURNS: |
| 462 | * Zero on success, error code on failure |
| 463 | */ |
| 464 | static int drm_atomic_crtc_check(struct drm_crtc *crtc, |
| 465 | struct drm_crtc_state *state) |
| 466 | { |
| 467 | /* NOTE: we explicitly don't enforce constraints such as primary |
| 468 | * layer covering entire screen, since that is something we want |
| 469 | * to allow (on hw that supports it). For hw that does not, it |
| 470 | * should be checked in driver's crtc->atomic_check() vfunc. |
| 471 | * |
| 472 | * TODO: Add generic modeset state checks once we support those. |
| 473 | */ |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 474 | |
| 475 | if (state->active && !state->enable) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 476 | DRM_DEBUG_ATOMIC("[CRTC:%d] active without enabled\n", |
| 477 | crtc->base.id); |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 478 | return -EINVAL; |
| 479 | } |
| 480 | |
Daniel Stone | 99cf4a2 | 2015-05-25 19:11:51 +0100 | [diff] [blame] | 481 | /* The state->enable vs. state->mode_blob checks can be WARN_ON, |
| 482 | * as this is a kernel-internal detail that userspace should never |
| 483 | * be able to trigger. */ |
| 484 | if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) && |
| 485 | WARN_ON(state->enable && !state->mode_blob)) { |
| 486 | DRM_DEBUG_ATOMIC("[CRTC:%d] enabled without mode blob\n", |
| 487 | crtc->base.id); |
| 488 | return -EINVAL; |
| 489 | } |
| 490 | |
| 491 | if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) && |
| 492 | WARN_ON(!state->enable && state->mode_blob)) { |
| 493 | DRM_DEBUG_ATOMIC("[CRTC:%d] disabled with mode blob\n", |
| 494 | crtc->base.id); |
| 495 | return -EINVAL; |
| 496 | } |
| 497 | |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 498 | return 0; |
| 499 | } |
| 500 | |
| 501 | /** |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 502 | * drm_atomic_get_plane_state - get plane state |
| 503 | * @state: global atomic state object |
| 504 | * @plane: plane to get state object for |
| 505 | * |
| 506 | * This function returns the plane state for the given plane, allocating it if |
| 507 | * needed. It will also grab the relevant plane lock to make sure that the state |
| 508 | * is consistent. |
| 509 | * |
| 510 | * Returns: |
| 511 | * |
| 512 | * Either the allocated state or the error code encoded into the pointer. When |
| 513 | * the error is EDEADLK then the w/w mutex code has detected a deadlock and the |
| 514 | * entire atomic sequence must be restarted. All other errors are fatal. |
| 515 | */ |
| 516 | struct drm_plane_state * |
| 517 | drm_atomic_get_plane_state(struct drm_atomic_state *state, |
| 518 | struct drm_plane *plane) |
| 519 | { |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 520 | int ret, index = drm_plane_index(plane); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 521 | struct drm_plane_state *plane_state; |
| 522 | |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 523 | plane_state = drm_atomic_get_existing_plane_state(state, plane); |
| 524 | if (plane_state) |
| 525 | return plane_state; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 526 | |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 527 | ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 528 | if (ret) |
| 529 | return ERR_PTR(ret); |
| 530 | |
| 531 | plane_state = plane->funcs->atomic_duplicate_state(plane); |
| 532 | if (!plane_state) |
| 533 | return ERR_PTR(-ENOMEM); |
| 534 | |
| 535 | state->plane_states[index] = plane_state; |
| 536 | state->planes[index] = plane; |
| 537 | plane_state->state = state; |
| 538 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 539 | DRM_DEBUG_ATOMIC("Added [PLANE:%d] %p state to %p\n", |
| 540 | plane->base.id, plane_state, state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 541 | |
| 542 | if (plane_state->crtc) { |
| 543 | struct drm_crtc_state *crtc_state; |
| 544 | |
| 545 | crtc_state = drm_atomic_get_crtc_state(state, |
| 546 | plane_state->crtc); |
| 547 | if (IS_ERR(crtc_state)) |
| 548 | return ERR_CAST(crtc_state); |
| 549 | } |
| 550 | |
| 551 | return plane_state; |
| 552 | } |
| 553 | EXPORT_SYMBOL(drm_atomic_get_plane_state); |
| 554 | |
| 555 | /** |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 556 | * drm_atomic_plane_set_property - set property on plane |
| 557 | * @plane: the drm plane to set a property on |
| 558 | * @state: the state object to update with the new property value |
| 559 | * @property: the property to set |
| 560 | * @val: the new property value |
| 561 | * |
| 562 | * Use this instead of calling plane->atomic_set_property directly. |
| 563 | * This function handles generic/core properties and calls out to |
| 564 | * driver's ->atomic_set_property() for driver properties. To ensure |
| 565 | * consistent behavior you must call this function rather than the |
| 566 | * driver hook directly. |
| 567 | * |
| 568 | * RETURNS: |
| 569 | * Zero on success, error code on failure |
| 570 | */ |
| 571 | int drm_atomic_plane_set_property(struct drm_plane *plane, |
| 572 | struct drm_plane_state *state, struct drm_property *property, |
| 573 | uint64_t val) |
| 574 | { |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 575 | struct drm_device *dev = plane->dev; |
| 576 | struct drm_mode_config *config = &dev->mode_config; |
| 577 | |
| 578 | if (property == config->prop_fb_id) { |
| 579 | struct drm_framebuffer *fb = drm_framebuffer_lookup(dev, val); |
| 580 | drm_atomic_set_fb_for_plane(state, fb); |
| 581 | if (fb) |
| 582 | drm_framebuffer_unreference(fb); |
| 583 | } else if (property == config->prop_crtc_id) { |
| 584 | struct drm_crtc *crtc = drm_crtc_find(dev, val); |
| 585 | return drm_atomic_set_crtc_for_plane(state, crtc); |
| 586 | } else if (property == config->prop_crtc_x) { |
| 587 | state->crtc_x = U642I64(val); |
| 588 | } else if (property == config->prop_crtc_y) { |
| 589 | state->crtc_y = U642I64(val); |
| 590 | } else if (property == config->prop_crtc_w) { |
| 591 | state->crtc_w = val; |
| 592 | } else if (property == config->prop_crtc_h) { |
| 593 | state->crtc_h = val; |
| 594 | } else if (property == config->prop_src_x) { |
| 595 | state->src_x = val; |
| 596 | } else if (property == config->prop_src_y) { |
| 597 | state->src_y = val; |
| 598 | } else if (property == config->prop_src_w) { |
| 599 | state->src_w = val; |
| 600 | } else if (property == config->prop_src_h) { |
| 601 | state->src_h = val; |
Matt Roper | 1da3062 | 2015-01-21 16:35:40 -0800 | [diff] [blame] | 602 | } else if (property == config->rotation_property) { |
| 603 | state->rotation = val; |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 604 | } else if (plane->funcs->atomic_set_property) { |
| 605 | return plane->funcs->atomic_set_property(plane, state, |
| 606 | property, val); |
| 607 | } else { |
| 608 | return -EINVAL; |
| 609 | } |
| 610 | |
| 611 | return 0; |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 612 | } |
| 613 | EXPORT_SYMBOL(drm_atomic_plane_set_property); |
| 614 | |
Daniel Vetter | a97df1c | 2014-12-18 22:49:02 +0100 | [diff] [blame] | 615 | /* |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 616 | * This function handles generic/core properties and calls out to |
| 617 | * driver's ->atomic_get_property() for driver properties. To ensure |
| 618 | * consistent behavior you must call this function rather than the |
| 619 | * driver hook directly. |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 620 | */ |
Daniel Vetter | a97df1c | 2014-12-18 22:49:02 +0100 | [diff] [blame] | 621 | static int |
| 622 | drm_atomic_plane_get_property(struct drm_plane *plane, |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 623 | const struct drm_plane_state *state, |
| 624 | struct drm_property *property, uint64_t *val) |
| 625 | { |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 626 | struct drm_device *dev = plane->dev; |
| 627 | struct drm_mode_config *config = &dev->mode_config; |
| 628 | |
| 629 | if (property == config->prop_fb_id) { |
| 630 | *val = (state->fb) ? state->fb->base.id : 0; |
| 631 | } else if (property == config->prop_crtc_id) { |
| 632 | *val = (state->crtc) ? state->crtc->base.id : 0; |
| 633 | } else if (property == config->prop_crtc_x) { |
| 634 | *val = I642U64(state->crtc_x); |
| 635 | } else if (property == config->prop_crtc_y) { |
| 636 | *val = I642U64(state->crtc_y); |
| 637 | } else if (property == config->prop_crtc_w) { |
| 638 | *val = state->crtc_w; |
| 639 | } else if (property == config->prop_crtc_h) { |
| 640 | *val = state->crtc_h; |
| 641 | } else if (property == config->prop_src_x) { |
| 642 | *val = state->src_x; |
| 643 | } else if (property == config->prop_src_y) { |
| 644 | *val = state->src_y; |
| 645 | } else if (property == config->prop_src_w) { |
| 646 | *val = state->src_w; |
| 647 | } else if (property == config->prop_src_h) { |
| 648 | *val = state->src_h; |
Tvrtko Ursulin | 4cda09c | 2015-02-26 13:49:17 +0000 | [diff] [blame] | 649 | } else if (property == config->rotation_property) { |
| 650 | *val = state->rotation; |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 651 | } else if (plane->funcs->atomic_get_property) { |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 652 | return plane->funcs->atomic_get_property(plane, state, property, val); |
Rob Clark | 6b4959f | 2014-12-18 16:01:53 -0500 | [diff] [blame] | 653 | } else { |
| 654 | return -EINVAL; |
| 655 | } |
| 656 | |
| 657 | return 0; |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 658 | } |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 659 | |
| 660 | /** |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 661 | * drm_atomic_plane_check - check plane state |
| 662 | * @plane: plane to check |
| 663 | * @state: plane state to check |
| 664 | * |
| 665 | * Provides core sanity checks for plane state. |
| 666 | * |
| 667 | * RETURNS: |
| 668 | * Zero on success, error code on failure |
| 669 | */ |
| 670 | static int drm_atomic_plane_check(struct drm_plane *plane, |
| 671 | struct drm_plane_state *state) |
| 672 | { |
| 673 | unsigned int fb_width, fb_height; |
Laurent Pinchart | ead8610 | 2015-03-05 02:25:43 +0200 | [diff] [blame] | 674 | int ret; |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 675 | |
| 676 | /* either *both* CRTC and FB must be set, or neither */ |
| 677 | if (WARN_ON(state->crtc && !state->fb)) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 678 | DRM_DEBUG_ATOMIC("CRTC set but no FB\n"); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 679 | return -EINVAL; |
| 680 | } else if (WARN_ON(state->fb && !state->crtc)) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 681 | DRM_DEBUG_ATOMIC("FB set but no CRTC\n"); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 682 | return -EINVAL; |
| 683 | } |
| 684 | |
| 685 | /* if disabled, we don't care about the rest of the state: */ |
| 686 | if (!state->crtc) |
| 687 | return 0; |
| 688 | |
| 689 | /* Check whether this plane is usable on this CRTC */ |
| 690 | if (!(plane->possible_crtcs & drm_crtc_mask(state->crtc))) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 691 | DRM_DEBUG_ATOMIC("Invalid crtc for plane\n"); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 692 | return -EINVAL; |
| 693 | } |
| 694 | |
| 695 | /* Check whether this plane supports the fb pixel format. */ |
Laurent Pinchart | ead8610 | 2015-03-05 02:25:43 +0200 | [diff] [blame] | 696 | ret = drm_plane_check_pixel_format(plane, state->fb->pixel_format); |
| 697 | if (ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 698 | DRM_DEBUG_ATOMIC("Invalid pixel format %s\n", |
| 699 | drm_get_format_name(state->fb->pixel_format)); |
Laurent Pinchart | ead8610 | 2015-03-05 02:25:43 +0200 | [diff] [blame] | 700 | return ret; |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | /* Give drivers some help against integer overflows */ |
| 704 | if (state->crtc_w > INT_MAX || |
| 705 | state->crtc_x > INT_MAX - (int32_t) state->crtc_w || |
| 706 | state->crtc_h > INT_MAX || |
| 707 | state->crtc_y > INT_MAX - (int32_t) state->crtc_h) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 708 | DRM_DEBUG_ATOMIC("Invalid CRTC coordinates %ux%u+%d+%d\n", |
| 709 | state->crtc_w, state->crtc_h, |
| 710 | state->crtc_x, state->crtc_y); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 711 | return -ERANGE; |
| 712 | } |
| 713 | |
| 714 | fb_width = state->fb->width << 16; |
| 715 | fb_height = state->fb->height << 16; |
| 716 | |
| 717 | /* Make sure source coordinates are inside the fb. */ |
| 718 | if (state->src_w > fb_width || |
| 719 | state->src_x > fb_width - state->src_w || |
| 720 | state->src_h > fb_height || |
| 721 | state->src_y > fb_height - state->src_h) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 722 | DRM_DEBUG_ATOMIC("Invalid source coordinates " |
| 723 | "%u.%06ux%u.%06u+%u.%06u+%u.%06u\n", |
| 724 | state->src_w >> 16, ((state->src_w & 0xffff) * 15625) >> 10, |
| 725 | state->src_h >> 16, ((state->src_h & 0xffff) * 15625) >> 10, |
| 726 | state->src_x >> 16, ((state->src_x & 0xffff) * 15625) >> 10, |
| 727 | state->src_y >> 16, ((state->src_y & 0xffff) * 15625) >> 10); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 728 | return -ENOSPC; |
| 729 | } |
| 730 | |
| 731 | return 0; |
| 732 | } |
| 733 | |
| 734 | /** |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 735 | * drm_atomic_get_connector_state - get connector state |
| 736 | * @state: global atomic state object |
| 737 | * @connector: connector to get state object for |
| 738 | * |
| 739 | * This function returns the connector state for the given connector, |
| 740 | * allocating it if needed. It will also grab the relevant connector lock to |
| 741 | * make sure that the state is consistent. |
| 742 | * |
| 743 | * Returns: |
| 744 | * |
| 745 | * Either the allocated state or the error code encoded into the pointer. When |
| 746 | * the error is EDEADLK then the w/w mutex code has detected a deadlock and the |
| 747 | * entire atomic sequence must be restarted. All other errors are fatal. |
| 748 | */ |
| 749 | struct drm_connector_state * |
| 750 | drm_atomic_get_connector_state(struct drm_atomic_state *state, |
| 751 | struct drm_connector *connector) |
| 752 | { |
| 753 | int ret, index; |
| 754 | struct drm_mode_config *config = &connector->dev->mode_config; |
| 755 | struct drm_connector_state *connector_state; |
| 756 | |
Daniel Vetter | c7eb76f | 2014-11-19 18:38:06 +0100 | [diff] [blame] | 757 | ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx); |
| 758 | if (ret) |
| 759 | return ERR_PTR(ret); |
| 760 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 761 | index = drm_connector_index(connector); |
| 762 | |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 763 | /* |
| 764 | * Construction of atomic state updates can race with a connector |
| 765 | * hot-add which might overflow. In this case flip the table and just |
| 766 | * restart the entire ioctl - no one is fast enough to livelock a cpu |
| 767 | * with physical hotplug events anyway. |
| 768 | * |
| 769 | * Note that we only grab the indexes once we have the right lock to |
| 770 | * prevent hotplug/unplugging of connectors. So removal is no problem, |
| 771 | * at most the array is a bit too large. |
| 772 | */ |
| 773 | if (index >= state->num_connector) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 774 | DRM_DEBUG_ATOMIC("Hot-added connector would overflow state array, restarting\n"); |
Daniel Vetter | fc2d2bc | 2014-11-20 09:53:35 +0100 | [diff] [blame] | 775 | return ERR_PTR(-EAGAIN); |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 776 | } |
| 777 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 778 | if (state->connector_states[index]) |
| 779 | return state->connector_states[index]; |
| 780 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 781 | connector_state = connector->funcs->atomic_duplicate_state(connector); |
| 782 | if (!connector_state) |
| 783 | return ERR_PTR(-ENOMEM); |
| 784 | |
| 785 | state->connector_states[index] = connector_state; |
| 786 | state->connectors[index] = connector; |
| 787 | connector_state->state = state; |
| 788 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 789 | DRM_DEBUG_ATOMIC("Added [CONNECTOR:%d] %p state to %p\n", |
| 790 | connector->base.id, connector_state, state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 791 | |
| 792 | if (connector_state->crtc) { |
| 793 | struct drm_crtc_state *crtc_state; |
| 794 | |
| 795 | crtc_state = drm_atomic_get_crtc_state(state, |
| 796 | connector_state->crtc); |
| 797 | if (IS_ERR(crtc_state)) |
| 798 | return ERR_CAST(crtc_state); |
| 799 | } |
| 800 | |
| 801 | return connector_state; |
| 802 | } |
| 803 | EXPORT_SYMBOL(drm_atomic_get_connector_state); |
| 804 | |
| 805 | /** |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 806 | * drm_atomic_connector_set_property - set property on connector. |
| 807 | * @connector: the drm connector to set a property on |
| 808 | * @state: the state object to update with the new property value |
| 809 | * @property: the property to set |
| 810 | * @val: the new property value |
| 811 | * |
| 812 | * Use this instead of calling connector->atomic_set_property directly. |
| 813 | * This function handles generic/core properties and calls out to |
| 814 | * driver's ->atomic_set_property() for driver properties. To ensure |
| 815 | * consistent behavior you must call this function rather than the |
| 816 | * driver hook directly. |
| 817 | * |
| 818 | * RETURNS: |
| 819 | * Zero on success, error code on failure |
| 820 | */ |
| 821 | int drm_atomic_connector_set_property(struct drm_connector *connector, |
| 822 | struct drm_connector_state *state, struct drm_property *property, |
| 823 | uint64_t val) |
| 824 | { |
| 825 | struct drm_device *dev = connector->dev; |
| 826 | struct drm_mode_config *config = &dev->mode_config; |
| 827 | |
Rob Clark | ae16c59 | 2014-12-18 16:01:54 -0500 | [diff] [blame] | 828 | if (property == config->prop_crtc_id) { |
| 829 | struct drm_crtc *crtc = drm_crtc_find(dev, val); |
| 830 | return drm_atomic_set_crtc_for_connector(state, crtc); |
| 831 | } else if (property == config->dpms_property) { |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 832 | /* setting DPMS property requires special handling, which |
| 833 | * is done in legacy setprop path for us. Disallow (for |
| 834 | * now?) atomic writes to DPMS property: |
| 835 | */ |
| 836 | return -EINVAL; |
| 837 | } else if (connector->funcs->atomic_set_property) { |
| 838 | return connector->funcs->atomic_set_property(connector, |
| 839 | state, property, val); |
| 840 | } else { |
| 841 | return -EINVAL; |
| 842 | } |
| 843 | } |
| 844 | EXPORT_SYMBOL(drm_atomic_connector_set_property); |
| 845 | |
Daniel Vetter | a97df1c | 2014-12-18 22:49:02 +0100 | [diff] [blame] | 846 | /* |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 847 | * This function handles generic/core properties and calls out to |
| 848 | * driver's ->atomic_get_property() for driver properties. To ensure |
| 849 | * consistent behavior you must call this function rather than the |
| 850 | * driver hook directly. |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 851 | */ |
Daniel Vetter | a97df1c | 2014-12-18 22:49:02 +0100 | [diff] [blame] | 852 | static int |
| 853 | drm_atomic_connector_get_property(struct drm_connector *connector, |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 854 | const struct drm_connector_state *state, |
| 855 | struct drm_property *property, uint64_t *val) |
| 856 | { |
| 857 | struct drm_device *dev = connector->dev; |
| 858 | struct drm_mode_config *config = &dev->mode_config; |
| 859 | |
Rob Clark | ae16c59 | 2014-12-18 16:01:54 -0500 | [diff] [blame] | 860 | if (property == config->prop_crtc_id) { |
| 861 | *val = (state->crtc) ? state->crtc->base.id : 0; |
| 862 | } else if (property == config->dpms_property) { |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 863 | *val = connector->dpms; |
| 864 | } else if (connector->funcs->atomic_get_property) { |
| 865 | return connector->funcs->atomic_get_property(connector, |
| 866 | state, property, val); |
| 867 | } else { |
| 868 | return -EINVAL; |
| 869 | } |
| 870 | |
| 871 | return 0; |
| 872 | } |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 873 | |
Rob Clark | 88a48e2 | 2014-12-18 16:01:50 -0500 | [diff] [blame] | 874 | int drm_atomic_get_property(struct drm_mode_object *obj, |
| 875 | struct drm_property *property, uint64_t *val) |
| 876 | { |
| 877 | struct drm_device *dev = property->dev; |
| 878 | int ret; |
| 879 | |
| 880 | switch (obj->type) { |
| 881 | case DRM_MODE_OBJECT_CONNECTOR: { |
| 882 | struct drm_connector *connector = obj_to_connector(obj); |
| 883 | WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex)); |
| 884 | ret = drm_atomic_connector_get_property(connector, |
| 885 | connector->state, property, val); |
| 886 | break; |
| 887 | } |
| 888 | case DRM_MODE_OBJECT_CRTC: { |
| 889 | struct drm_crtc *crtc = obj_to_crtc(obj); |
| 890 | WARN_ON(!drm_modeset_is_locked(&crtc->mutex)); |
| 891 | ret = drm_atomic_crtc_get_property(crtc, |
| 892 | crtc->state, property, val); |
| 893 | break; |
| 894 | } |
| 895 | case DRM_MODE_OBJECT_PLANE: { |
| 896 | struct drm_plane *plane = obj_to_plane(obj); |
| 897 | WARN_ON(!drm_modeset_is_locked(&plane->mutex)); |
| 898 | ret = drm_atomic_plane_get_property(plane, |
| 899 | plane->state, property, val); |
| 900 | break; |
| 901 | } |
| 902 | default: |
| 903 | ret = -EINVAL; |
| 904 | break; |
| 905 | } |
| 906 | |
| 907 | return ret; |
| 908 | } |
| 909 | |
| 910 | /** |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 911 | * drm_atomic_set_crtc_for_plane - set crtc for plane |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 912 | * @plane_state: the plane whose incoming state to update |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 913 | * @crtc: crtc to use for the plane |
| 914 | * |
| 915 | * Changing the assigned crtc for a plane requires us to grab the lock and state |
| 916 | * for the new crtc, as needed. This function takes care of all these details |
| 917 | * besides updating the pointer in the state object itself. |
| 918 | * |
| 919 | * Returns: |
| 920 | * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK |
| 921 | * then the w/w mutex code has detected a deadlock and the entire atomic |
| 922 | * sequence must be restarted. All other errors are fatal. |
| 923 | */ |
| 924 | int |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 925 | drm_atomic_set_crtc_for_plane(struct drm_plane_state *plane_state, |
| 926 | struct drm_crtc *crtc) |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 927 | { |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 928 | struct drm_plane *plane = plane_state->plane; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 929 | struct drm_crtc_state *crtc_state; |
| 930 | |
Rob Clark | 6ddd388 | 2014-11-21 15:28:31 -0500 | [diff] [blame] | 931 | if (plane_state->crtc) { |
| 932 | crtc_state = drm_atomic_get_crtc_state(plane_state->state, |
| 933 | plane_state->crtc); |
| 934 | if (WARN_ON(IS_ERR(crtc_state))) |
| 935 | return PTR_ERR(crtc_state); |
| 936 | |
| 937 | crtc_state->plane_mask &= ~(1 << drm_plane_index(plane)); |
| 938 | } |
| 939 | |
| 940 | plane_state->crtc = crtc; |
| 941 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 942 | if (crtc) { |
| 943 | crtc_state = drm_atomic_get_crtc_state(plane_state->state, |
| 944 | crtc); |
| 945 | if (IS_ERR(crtc_state)) |
| 946 | return PTR_ERR(crtc_state); |
Rob Clark | 6ddd388 | 2014-11-21 15:28:31 -0500 | [diff] [blame] | 947 | crtc_state->plane_mask |= (1 << drm_plane_index(plane)); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 948 | } |
| 949 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 950 | if (crtc) |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 951 | DRM_DEBUG_ATOMIC("Link plane state %p to [CRTC:%d]\n", |
| 952 | plane_state, crtc->base.id); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 953 | else |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 954 | DRM_DEBUG_ATOMIC("Link plane state %p to [NOCRTC]\n", |
| 955 | plane_state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 956 | |
| 957 | return 0; |
| 958 | } |
| 959 | EXPORT_SYMBOL(drm_atomic_set_crtc_for_plane); |
| 960 | |
| 961 | /** |
John Hunter | 16d78bc2e | 2015-04-07 19:38:50 +0800 | [diff] [blame] | 962 | * drm_atomic_set_fb_for_plane - set framebuffer for plane |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 963 | * @plane_state: atomic state object for the plane |
| 964 | * @fb: fb to use for the plane |
| 965 | * |
| 966 | * Changing the assigned framebuffer for a plane requires us to grab a reference |
| 967 | * to the new fb and drop the reference to the old fb, if there is one. This |
| 968 | * function takes care of all these details besides updating the pointer in the |
| 969 | * state object itself. |
| 970 | */ |
| 971 | void |
| 972 | drm_atomic_set_fb_for_plane(struct drm_plane_state *plane_state, |
| 973 | struct drm_framebuffer *fb) |
| 974 | { |
| 975 | if (plane_state->fb) |
| 976 | drm_framebuffer_unreference(plane_state->fb); |
| 977 | if (fb) |
| 978 | drm_framebuffer_reference(fb); |
| 979 | plane_state->fb = fb; |
| 980 | |
| 981 | if (fb) |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 982 | DRM_DEBUG_ATOMIC("Set [FB:%d] for plane state %p\n", |
| 983 | fb->base.id, plane_state); |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 984 | else |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 985 | DRM_DEBUG_ATOMIC("Set [NOFB] for plane state %p\n", |
| 986 | plane_state); |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 987 | } |
| 988 | EXPORT_SYMBOL(drm_atomic_set_fb_for_plane); |
| 989 | |
| 990 | /** |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 991 | * drm_atomic_set_crtc_for_connector - set crtc for connector |
| 992 | * @conn_state: atomic state object for the connector |
| 993 | * @crtc: crtc to use for the connector |
| 994 | * |
| 995 | * Changing the assigned crtc for a connector requires us to grab the lock and |
| 996 | * state for the new crtc, as needed. This function takes care of all these |
| 997 | * details besides updating the pointer in the state object itself. |
| 998 | * |
| 999 | * Returns: |
| 1000 | * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK |
| 1001 | * then the w/w mutex code has detected a deadlock and the entire atomic |
| 1002 | * sequence must be restarted. All other errors are fatal. |
| 1003 | */ |
| 1004 | int |
| 1005 | drm_atomic_set_crtc_for_connector(struct drm_connector_state *conn_state, |
| 1006 | struct drm_crtc *crtc) |
| 1007 | { |
| 1008 | struct drm_crtc_state *crtc_state; |
| 1009 | |
| 1010 | if (crtc) { |
| 1011 | crtc_state = drm_atomic_get_crtc_state(conn_state->state, crtc); |
| 1012 | if (IS_ERR(crtc_state)) |
| 1013 | return PTR_ERR(crtc_state); |
| 1014 | } |
| 1015 | |
| 1016 | conn_state->crtc = crtc; |
| 1017 | |
| 1018 | if (crtc) |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 1019 | DRM_DEBUG_ATOMIC("Link connector state %p to [CRTC:%d]\n", |
| 1020 | conn_state, crtc->base.id); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1021 | else |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 1022 | DRM_DEBUG_ATOMIC("Link connector state %p to [NOCRTC]\n", |
| 1023 | conn_state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1024 | |
| 1025 | return 0; |
| 1026 | } |
| 1027 | EXPORT_SYMBOL(drm_atomic_set_crtc_for_connector); |
| 1028 | |
| 1029 | /** |
| 1030 | * drm_atomic_add_affected_connectors - add connectors for crtc |
| 1031 | * @state: atomic state |
| 1032 | * @crtc: DRM crtc |
| 1033 | * |
| 1034 | * This function walks the current configuration and adds all connectors |
| 1035 | * currently using @crtc to the atomic configuration @state. Note that this |
| 1036 | * function must acquire the connection mutex. This can potentially cause |
| 1037 | * unneeded seralization if the update is just for the planes on one crtc. Hence |
| 1038 | * drivers and helpers should only call this when really needed (e.g. when a |
| 1039 | * full modeset needs to happen due to some change). |
| 1040 | * |
| 1041 | * Returns: |
| 1042 | * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK |
| 1043 | * then the w/w mutex code has detected a deadlock and the entire atomic |
| 1044 | * sequence must be restarted. All other errors are fatal. |
| 1045 | */ |
| 1046 | int |
| 1047 | drm_atomic_add_affected_connectors(struct drm_atomic_state *state, |
| 1048 | struct drm_crtc *crtc) |
| 1049 | { |
| 1050 | struct drm_mode_config *config = &state->dev->mode_config; |
| 1051 | struct drm_connector *connector; |
| 1052 | struct drm_connector_state *conn_state; |
| 1053 | int ret; |
| 1054 | |
| 1055 | ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx); |
| 1056 | if (ret) |
| 1057 | return ret; |
| 1058 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 1059 | DRM_DEBUG_ATOMIC("Adding all current connectors for [CRTC:%d] to %p\n", |
| 1060 | crtc->base.id, state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1061 | |
| 1062 | /* |
| 1063 | * Changed connectors are already in @state, so only need to look at the |
| 1064 | * current configuration. |
| 1065 | */ |
Daniel Vetter | 9a9f5ce | 2015-07-09 23:44:34 +0200 | [diff] [blame^] | 1066 | drm_for_each_connector(connector, state->dev) { |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1067 | if (connector->state->crtc != crtc) |
| 1068 | continue; |
| 1069 | |
| 1070 | conn_state = drm_atomic_get_connector_state(state, connector); |
| 1071 | if (IS_ERR(conn_state)) |
| 1072 | return PTR_ERR(conn_state); |
| 1073 | } |
| 1074 | |
| 1075 | return 0; |
| 1076 | } |
| 1077 | EXPORT_SYMBOL(drm_atomic_add_affected_connectors); |
| 1078 | |
| 1079 | /** |
Maarten Lankhorst | e01e9f7 | 2015-05-19 16:41:02 +0200 | [diff] [blame] | 1080 | * drm_atomic_add_affected_planes - add planes for crtc |
| 1081 | * @state: atomic state |
| 1082 | * @crtc: DRM crtc |
| 1083 | * |
| 1084 | * This function walks the current configuration and adds all planes |
| 1085 | * currently used by @crtc to the atomic configuration @state. This is useful |
| 1086 | * when an atomic commit also needs to check all currently enabled plane on |
| 1087 | * @crtc, e.g. when changing the mode. It's also useful when re-enabling a CRTC |
| 1088 | * to avoid special code to force-enable all planes. |
| 1089 | * |
| 1090 | * Since acquiring a plane state will always also acquire the w/w mutex of the |
| 1091 | * current CRTC for that plane (if there is any) adding all the plane states for |
| 1092 | * a CRTC will not reduce parallism of atomic updates. |
| 1093 | * |
| 1094 | * Returns: |
| 1095 | * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK |
| 1096 | * then the w/w mutex code has detected a deadlock and the entire atomic |
| 1097 | * sequence must be restarted. All other errors are fatal. |
| 1098 | */ |
| 1099 | int |
| 1100 | drm_atomic_add_affected_planes(struct drm_atomic_state *state, |
| 1101 | struct drm_crtc *crtc) |
| 1102 | { |
| 1103 | struct drm_plane *plane; |
| 1104 | |
| 1105 | WARN_ON(!drm_atomic_get_existing_crtc_state(state, crtc)); |
| 1106 | |
| 1107 | drm_for_each_plane_mask(plane, state->dev, crtc->state->plane_mask) { |
| 1108 | struct drm_plane_state *plane_state = |
| 1109 | drm_atomic_get_plane_state(state, plane); |
| 1110 | |
| 1111 | if (IS_ERR(plane_state)) |
| 1112 | return PTR_ERR(plane_state); |
| 1113 | } |
| 1114 | return 0; |
| 1115 | } |
| 1116 | EXPORT_SYMBOL(drm_atomic_add_affected_planes); |
| 1117 | |
| 1118 | /** |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1119 | * drm_atomic_connectors_for_crtc - count number of connected outputs |
| 1120 | * @state: atomic state |
| 1121 | * @crtc: DRM crtc |
| 1122 | * |
| 1123 | * This function counts all connectors which will be connected to @crtc |
| 1124 | * according to @state. Useful to recompute the enable state for @crtc. |
| 1125 | */ |
| 1126 | int |
| 1127 | drm_atomic_connectors_for_crtc(struct drm_atomic_state *state, |
| 1128 | struct drm_crtc *crtc) |
| 1129 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1130 | struct drm_connector *connector; |
| 1131 | struct drm_connector_state *conn_state; |
| 1132 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1133 | int i, num_connected_connectors = 0; |
| 1134 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1135 | for_each_connector_in_state(state, connector, conn_state, i) { |
| 1136 | if (conn_state->crtc == crtc) |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1137 | num_connected_connectors++; |
| 1138 | } |
| 1139 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 1140 | DRM_DEBUG_ATOMIC("State %p has %i connectors for [CRTC:%d]\n", |
| 1141 | state, num_connected_connectors, crtc->base.id); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1142 | |
| 1143 | return num_connected_connectors; |
| 1144 | } |
| 1145 | EXPORT_SYMBOL(drm_atomic_connectors_for_crtc); |
| 1146 | |
| 1147 | /** |
| 1148 | * drm_atomic_legacy_backoff - locking backoff for legacy ioctls |
| 1149 | * @state: atomic state |
| 1150 | * |
| 1151 | * This function should be used by legacy entry points which don't understand |
| 1152 | * -EDEADLK semantics. For simplicity this one will grab all modeset locks after |
John Hunter | 16d78bc2e | 2015-04-07 19:38:50 +0800 | [diff] [blame] | 1153 | * the slowpath completed. |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1154 | */ |
| 1155 | void drm_atomic_legacy_backoff(struct drm_atomic_state *state) |
| 1156 | { |
| 1157 | int ret; |
| 1158 | |
| 1159 | retry: |
| 1160 | drm_modeset_backoff(state->acquire_ctx); |
| 1161 | |
| 1162 | ret = drm_modeset_lock(&state->dev->mode_config.connection_mutex, |
| 1163 | state->acquire_ctx); |
| 1164 | if (ret) |
| 1165 | goto retry; |
| 1166 | ret = drm_modeset_lock_all_crtcs(state->dev, |
| 1167 | state->acquire_ctx); |
| 1168 | if (ret) |
| 1169 | goto retry; |
| 1170 | } |
| 1171 | EXPORT_SYMBOL(drm_atomic_legacy_backoff); |
| 1172 | |
| 1173 | /** |
| 1174 | * drm_atomic_check_only - check whether a given config would work |
| 1175 | * @state: atomic configuration to check |
| 1176 | * |
| 1177 | * Note that this function can return -EDEADLK if the driver needed to acquire |
| 1178 | * more locks but encountered a deadlock. The caller must then do the usual w/w |
| 1179 | * backoff dance and restart. All other errors are fatal. |
| 1180 | * |
| 1181 | * Returns: |
| 1182 | * 0 on success, negative error code on failure. |
| 1183 | */ |
| 1184 | int drm_atomic_check_only(struct drm_atomic_state *state) |
| 1185 | { |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 1186 | struct drm_device *dev = state->dev; |
| 1187 | struct drm_mode_config *config = &dev->mode_config; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1188 | struct drm_plane *plane; |
| 1189 | struct drm_plane_state *plane_state; |
| 1190 | struct drm_crtc *crtc; |
| 1191 | struct drm_crtc_state *crtc_state; |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 1192 | int i, ret = 0; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1193 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 1194 | DRM_DEBUG_ATOMIC("checking %p\n", state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1195 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1196 | for_each_plane_in_state(state, plane, plane_state, i) { |
| 1197 | ret = drm_atomic_plane_check(plane, plane_state); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 1198 | if (ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 1199 | DRM_DEBUG_ATOMIC("[PLANE:%d] atomic core check failed\n", |
| 1200 | plane->base.id); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 1201 | return ret; |
| 1202 | } |
| 1203 | } |
| 1204 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1205 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 1206 | ret = drm_atomic_crtc_check(crtc, crtc_state); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 1207 | if (ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 1208 | DRM_DEBUG_ATOMIC("[CRTC:%d] atomic core check failed\n", |
| 1209 | crtc->base.id); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 1210 | return ret; |
| 1211 | } |
| 1212 | } |
| 1213 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1214 | if (config->funcs->atomic_check) |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 1215 | ret = config->funcs->atomic_check(state->dev, state); |
| 1216 | |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 1217 | if (!state->allow_modeset) { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1218 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 1219 | if (drm_atomic_crtc_needs_modeset(crtc_state)) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 1220 | DRM_DEBUG_ATOMIC("[CRTC:%d] requires full modeset\n", |
| 1221 | crtc->base.id); |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 1222 | return -EINVAL; |
| 1223 | } |
| 1224 | } |
| 1225 | } |
| 1226 | |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 1227 | return ret; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1228 | } |
| 1229 | EXPORT_SYMBOL(drm_atomic_check_only); |
| 1230 | |
| 1231 | /** |
| 1232 | * drm_atomic_commit - commit configuration atomically |
| 1233 | * @state: atomic configuration to check |
| 1234 | * |
| 1235 | * Note that this function can return -EDEADLK if the driver needed to acquire |
| 1236 | * more locks but encountered a deadlock. The caller must then do the usual w/w |
| 1237 | * backoff dance and restart. All other errors are fatal. |
| 1238 | * |
| 1239 | * Also note that on successful execution ownership of @state is transferred |
| 1240 | * from the caller of this function to the function itself. The caller must not |
| 1241 | * free or in any other way access @state. If the function fails then the caller |
| 1242 | * must clean up @state itself. |
| 1243 | * |
| 1244 | * Returns: |
| 1245 | * 0 on success, negative error code on failure. |
| 1246 | */ |
| 1247 | int drm_atomic_commit(struct drm_atomic_state *state) |
| 1248 | { |
| 1249 | struct drm_mode_config *config = &state->dev->mode_config; |
| 1250 | int ret; |
| 1251 | |
| 1252 | ret = drm_atomic_check_only(state); |
| 1253 | if (ret) |
| 1254 | return ret; |
| 1255 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 1256 | DRM_DEBUG_ATOMIC("commiting %p\n", state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1257 | |
| 1258 | return config->funcs->atomic_commit(state->dev, state, false); |
| 1259 | } |
| 1260 | EXPORT_SYMBOL(drm_atomic_commit); |
| 1261 | |
| 1262 | /** |
| 1263 | * drm_atomic_async_commit - atomic&async configuration commit |
| 1264 | * @state: atomic configuration to check |
| 1265 | * |
| 1266 | * Note that this function can return -EDEADLK if the driver needed to acquire |
| 1267 | * more locks but encountered a deadlock. The caller must then do the usual w/w |
| 1268 | * backoff dance and restart. All other errors are fatal. |
| 1269 | * |
| 1270 | * Also note that on successful execution ownership of @state is transferred |
| 1271 | * from the caller of this function to the function itself. The caller must not |
| 1272 | * free or in any other way access @state. If the function fails then the caller |
| 1273 | * must clean up @state itself. |
| 1274 | * |
| 1275 | * Returns: |
| 1276 | * 0 on success, negative error code on failure. |
| 1277 | */ |
| 1278 | int drm_atomic_async_commit(struct drm_atomic_state *state) |
| 1279 | { |
| 1280 | struct drm_mode_config *config = &state->dev->mode_config; |
| 1281 | int ret; |
| 1282 | |
| 1283 | ret = drm_atomic_check_only(state); |
| 1284 | if (ret) |
| 1285 | return ret; |
| 1286 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 1287 | DRM_DEBUG_ATOMIC("commiting %p asynchronously\n", state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1288 | |
| 1289 | return config->funcs->atomic_commit(state->dev, state, true); |
| 1290 | } |
| 1291 | EXPORT_SYMBOL(drm_atomic_async_commit); |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 1292 | |
| 1293 | /* |
| 1294 | * The big monstor ioctl |
| 1295 | */ |
| 1296 | |
| 1297 | static struct drm_pending_vblank_event *create_vblank_event( |
| 1298 | struct drm_device *dev, struct drm_file *file_priv, uint64_t user_data) |
| 1299 | { |
| 1300 | struct drm_pending_vblank_event *e = NULL; |
| 1301 | unsigned long flags; |
| 1302 | |
| 1303 | spin_lock_irqsave(&dev->event_lock, flags); |
| 1304 | if (file_priv->event_space < sizeof e->event) { |
| 1305 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 1306 | goto out; |
| 1307 | } |
| 1308 | file_priv->event_space -= sizeof e->event; |
| 1309 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 1310 | |
| 1311 | e = kzalloc(sizeof *e, GFP_KERNEL); |
| 1312 | if (e == NULL) { |
| 1313 | spin_lock_irqsave(&dev->event_lock, flags); |
| 1314 | file_priv->event_space += sizeof e->event; |
| 1315 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 1316 | goto out; |
| 1317 | } |
| 1318 | |
| 1319 | e->event.base.type = DRM_EVENT_FLIP_COMPLETE; |
| 1320 | e->event.base.length = sizeof e->event; |
| 1321 | e->event.user_data = user_data; |
| 1322 | e->base.event = &e->event.base; |
| 1323 | e->base.file_priv = file_priv; |
| 1324 | e->base.destroy = (void (*) (struct drm_pending_event *)) kfree; |
| 1325 | |
| 1326 | out: |
| 1327 | return e; |
| 1328 | } |
| 1329 | |
| 1330 | static void destroy_vblank_event(struct drm_device *dev, |
| 1331 | struct drm_file *file_priv, struct drm_pending_vblank_event *e) |
| 1332 | { |
| 1333 | unsigned long flags; |
| 1334 | |
| 1335 | spin_lock_irqsave(&dev->event_lock, flags); |
| 1336 | file_priv->event_space += sizeof e->event; |
| 1337 | spin_unlock_irqrestore(&dev->event_lock, flags); |
| 1338 | kfree(e); |
| 1339 | } |
| 1340 | |
| 1341 | static int atomic_set_prop(struct drm_atomic_state *state, |
| 1342 | struct drm_mode_object *obj, struct drm_property *prop, |
| 1343 | uint64_t prop_value) |
| 1344 | { |
| 1345 | struct drm_mode_object *ref; |
| 1346 | int ret; |
| 1347 | |
| 1348 | if (!drm_property_change_valid_get(prop, prop_value, &ref)) |
| 1349 | return -EINVAL; |
| 1350 | |
| 1351 | switch (obj->type) { |
| 1352 | case DRM_MODE_OBJECT_CONNECTOR: { |
| 1353 | struct drm_connector *connector = obj_to_connector(obj); |
| 1354 | struct drm_connector_state *connector_state; |
| 1355 | |
| 1356 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 1357 | if (IS_ERR(connector_state)) { |
| 1358 | ret = PTR_ERR(connector_state); |
| 1359 | break; |
| 1360 | } |
| 1361 | |
| 1362 | ret = drm_atomic_connector_set_property(connector, |
| 1363 | connector_state, prop, prop_value); |
| 1364 | break; |
| 1365 | } |
| 1366 | case DRM_MODE_OBJECT_CRTC: { |
| 1367 | struct drm_crtc *crtc = obj_to_crtc(obj); |
| 1368 | struct drm_crtc_state *crtc_state; |
| 1369 | |
| 1370 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 1371 | if (IS_ERR(crtc_state)) { |
| 1372 | ret = PTR_ERR(crtc_state); |
| 1373 | break; |
| 1374 | } |
| 1375 | |
| 1376 | ret = drm_atomic_crtc_set_property(crtc, |
| 1377 | crtc_state, prop, prop_value); |
| 1378 | break; |
| 1379 | } |
| 1380 | case DRM_MODE_OBJECT_PLANE: { |
| 1381 | struct drm_plane *plane = obj_to_plane(obj); |
| 1382 | struct drm_plane_state *plane_state; |
| 1383 | |
| 1384 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 1385 | if (IS_ERR(plane_state)) { |
| 1386 | ret = PTR_ERR(plane_state); |
| 1387 | break; |
| 1388 | } |
| 1389 | |
| 1390 | ret = drm_atomic_plane_set_property(plane, |
| 1391 | plane_state, prop, prop_value); |
| 1392 | break; |
| 1393 | } |
| 1394 | default: |
| 1395 | ret = -EINVAL; |
| 1396 | break; |
| 1397 | } |
| 1398 | |
| 1399 | drm_property_change_valid_put(prop, ref); |
| 1400 | return ret; |
| 1401 | } |
| 1402 | |
| 1403 | int drm_mode_atomic_ioctl(struct drm_device *dev, |
| 1404 | void *data, struct drm_file *file_priv) |
| 1405 | { |
| 1406 | struct drm_mode_atomic *arg = data; |
| 1407 | uint32_t __user *objs_ptr = (uint32_t __user *)(unsigned long)(arg->objs_ptr); |
| 1408 | uint32_t __user *count_props_ptr = (uint32_t __user *)(unsigned long)(arg->count_props_ptr); |
| 1409 | uint32_t __user *props_ptr = (uint32_t __user *)(unsigned long)(arg->props_ptr); |
| 1410 | uint64_t __user *prop_values_ptr = (uint64_t __user *)(unsigned long)(arg->prop_values_ptr); |
| 1411 | unsigned int copied_objs, copied_props; |
| 1412 | struct drm_atomic_state *state; |
| 1413 | struct drm_modeset_acquire_ctx ctx; |
| 1414 | struct drm_plane *plane; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1415 | struct drm_crtc *crtc; |
| 1416 | struct drm_crtc_state *crtc_state; |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 1417 | unsigned plane_mask = 0; |
| 1418 | int ret = 0; |
| 1419 | unsigned int i, j; |
| 1420 | |
| 1421 | /* disallow for drivers not supporting atomic: */ |
| 1422 | if (!drm_core_check_feature(dev, DRIVER_ATOMIC)) |
| 1423 | return -EINVAL; |
| 1424 | |
| 1425 | /* disallow for userspace that has not enabled atomic cap (even |
| 1426 | * though this may be a bit overkill, since legacy userspace |
| 1427 | * wouldn't know how to call this ioctl) |
| 1428 | */ |
| 1429 | if (!file_priv->atomic) |
| 1430 | return -EINVAL; |
| 1431 | |
| 1432 | if (arg->flags & ~DRM_MODE_ATOMIC_FLAGS) |
| 1433 | return -EINVAL; |
| 1434 | |
| 1435 | if (arg->reserved) |
| 1436 | return -EINVAL; |
| 1437 | |
| 1438 | if ((arg->flags & DRM_MODE_PAGE_FLIP_ASYNC) && |
| 1439 | !dev->mode_config.async_page_flip) |
| 1440 | return -EINVAL; |
| 1441 | |
| 1442 | /* can't test and expect an event at the same time. */ |
| 1443 | if ((arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) && |
| 1444 | (arg->flags & DRM_MODE_PAGE_FLIP_EVENT)) |
| 1445 | return -EINVAL; |
| 1446 | |
| 1447 | drm_modeset_acquire_init(&ctx, 0); |
| 1448 | |
| 1449 | state = drm_atomic_state_alloc(dev); |
| 1450 | if (!state) |
| 1451 | return -ENOMEM; |
| 1452 | |
| 1453 | state->acquire_ctx = &ctx; |
| 1454 | state->allow_modeset = !!(arg->flags & DRM_MODE_ATOMIC_ALLOW_MODESET); |
| 1455 | |
| 1456 | retry: |
| 1457 | copied_objs = 0; |
| 1458 | copied_props = 0; |
| 1459 | |
| 1460 | for (i = 0; i < arg->count_objs; i++) { |
| 1461 | uint32_t obj_id, count_props; |
| 1462 | struct drm_mode_object *obj; |
| 1463 | |
| 1464 | if (get_user(obj_id, objs_ptr + copied_objs)) { |
| 1465 | ret = -EFAULT; |
| 1466 | goto fail; |
| 1467 | } |
| 1468 | |
| 1469 | obj = drm_mode_object_find(dev, obj_id, DRM_MODE_OBJECT_ANY); |
| 1470 | if (!obj || !obj->properties) { |
| 1471 | ret = -ENOENT; |
| 1472 | goto fail; |
| 1473 | } |
| 1474 | |
| 1475 | if (obj->type == DRM_MODE_OBJECT_PLANE) { |
| 1476 | plane = obj_to_plane(obj); |
| 1477 | plane_mask |= (1 << drm_plane_index(plane)); |
| 1478 | plane->old_fb = plane->fb; |
| 1479 | } |
| 1480 | |
| 1481 | if (get_user(count_props, count_props_ptr + copied_objs)) { |
| 1482 | ret = -EFAULT; |
| 1483 | goto fail; |
| 1484 | } |
| 1485 | |
| 1486 | copied_objs++; |
| 1487 | |
| 1488 | for (j = 0; j < count_props; j++) { |
| 1489 | uint32_t prop_id; |
| 1490 | uint64_t prop_value; |
| 1491 | struct drm_property *prop; |
| 1492 | |
| 1493 | if (get_user(prop_id, props_ptr + copied_props)) { |
| 1494 | ret = -EFAULT; |
| 1495 | goto fail; |
| 1496 | } |
| 1497 | |
| 1498 | prop = drm_property_find(dev, prop_id); |
| 1499 | if (!prop) { |
| 1500 | ret = -ENOENT; |
| 1501 | goto fail; |
| 1502 | } |
| 1503 | |
Guenter Roeck | 42c5814 | 2015-01-12 21:12:17 -0800 | [diff] [blame] | 1504 | if (copy_from_user(&prop_value, |
| 1505 | prop_values_ptr + copied_props, |
| 1506 | sizeof(prop_value))) { |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 1507 | ret = -EFAULT; |
| 1508 | goto fail; |
| 1509 | } |
| 1510 | |
| 1511 | ret = atomic_set_prop(state, obj, prop, prop_value); |
| 1512 | if (ret) |
| 1513 | goto fail; |
| 1514 | |
| 1515 | copied_props++; |
| 1516 | } |
| 1517 | } |
| 1518 | |
| 1519 | if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT) { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1520 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 1521 | struct drm_pending_vblank_event *e; |
| 1522 | |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 1523 | e = create_vblank_event(dev, file_priv, arg->user_data); |
| 1524 | if (!e) { |
| 1525 | ret = -ENOMEM; |
| 1526 | goto fail; |
| 1527 | } |
| 1528 | |
| 1529 | crtc_state->event = e; |
| 1530 | } |
| 1531 | } |
| 1532 | |
| 1533 | if (arg->flags & DRM_MODE_ATOMIC_TEST_ONLY) { |
| 1534 | ret = drm_atomic_check_only(state); |
| 1535 | /* _check_only() does not free state, unlike _commit() */ |
| 1536 | drm_atomic_state_free(state); |
| 1537 | } else if (arg->flags & DRM_MODE_ATOMIC_NONBLOCK) { |
| 1538 | ret = drm_atomic_async_commit(state); |
| 1539 | } else { |
| 1540 | ret = drm_atomic_commit(state); |
| 1541 | } |
| 1542 | |
| 1543 | /* if succeeded, fixup legacy plane crtc/fb ptrs before dropping |
| 1544 | * locks (ie. while it is still safe to deref plane->state). We |
| 1545 | * need to do this here because the driver entry points cannot |
| 1546 | * distinguish between legacy and atomic ioctls. |
| 1547 | */ |
| 1548 | drm_for_each_plane_mask(plane, dev, plane_mask) { |
| 1549 | if (ret == 0) { |
| 1550 | struct drm_framebuffer *new_fb = plane->state->fb; |
| 1551 | if (new_fb) |
| 1552 | drm_framebuffer_reference(new_fb); |
| 1553 | plane->fb = new_fb; |
| 1554 | plane->crtc = plane->state->crtc; |
| 1555 | } else { |
| 1556 | plane->old_fb = NULL; |
| 1557 | } |
| 1558 | if (plane->old_fb) { |
| 1559 | drm_framebuffer_unreference(plane->old_fb); |
| 1560 | plane->old_fb = NULL; |
| 1561 | } |
| 1562 | } |
| 1563 | |
| 1564 | drm_modeset_drop_locks(&ctx); |
| 1565 | drm_modeset_acquire_fini(&ctx); |
| 1566 | |
| 1567 | return ret; |
| 1568 | |
| 1569 | fail: |
| 1570 | if (ret == -EDEADLK) |
| 1571 | goto backoff; |
| 1572 | |
| 1573 | if (arg->flags & DRM_MODE_PAGE_FLIP_EVENT) { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1574 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 1575 | destroy_vblank_event(dev, file_priv, crtc_state->event); |
| 1576 | crtc_state->event = NULL; |
| 1577 | } |
| 1578 | } |
| 1579 | |
| 1580 | drm_atomic_state_free(state); |
| 1581 | |
| 1582 | drm_modeset_drop_locks(&ctx); |
| 1583 | drm_modeset_acquire_fini(&ctx); |
| 1584 | |
| 1585 | return ret; |
| 1586 | |
| 1587 | backoff: |
| 1588 | drm_atomic_state_clear(state); |
| 1589 | drm_modeset_backoff(&ctx); |
| 1590 | |
| 1591 | goto retry; |
| 1592 | } |