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