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> |
Daniel Vetter | 72fdb40c | 2018-09-05 15:57:11 +0200 | [diff] [blame] | 31 | #include <drm/drm_atomic_uapi.h> |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 32 | #include <drm/drm_mode.h> |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 33 | #include <drm/drm_print.h> |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 34 | #include <drm/drm_writeback.h> |
Gustavo Padovan | 9626014 | 2016-11-15 22:06:39 +0900 | [diff] [blame] | 35 | #include <linux/sync_file.h> |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 36 | |
Thierry Reding | be35f94 | 2016-04-28 15:19:56 +0200 | [diff] [blame] | 37 | #include "drm_crtc_internal.h" |
Noralf Trønnes | f02b604 | 2017-11-07 20:13:41 +0100 | [diff] [blame] | 38 | #include "drm_internal.h" |
Thierry Reding | be35f94 | 2016-04-28 15:19:56 +0200 | [diff] [blame] | 39 | |
Daniel Vetter | b3ba3f6 | 2016-12-21 14:03:35 +0100 | [diff] [blame] | 40 | void __drm_crtc_commit_free(struct kref *kref) |
Daniel Vetter | 3b24f7d | 2016-06-08 14:19:00 +0200 | [diff] [blame] | 41 | { |
| 42 | struct drm_crtc_commit *commit = |
| 43 | container_of(kref, struct drm_crtc_commit, ref); |
| 44 | |
| 45 | kfree(commit); |
| 46 | } |
Daniel Vetter | b3ba3f6 | 2016-12-21 14:03:35 +0100 | [diff] [blame] | 47 | EXPORT_SYMBOL(__drm_crtc_commit_free); |
Daniel Vetter | 3b24f7d | 2016-06-08 14:19:00 +0200 | [diff] [blame] | 48 | |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 49 | /** |
| 50 | * drm_atomic_state_default_release - |
| 51 | * release memory initialized by drm_atomic_state_init |
| 52 | * @state: atomic state |
| 53 | * |
| 54 | * Free all the memory allocated by drm_atomic_state_init. |
Daniel Vetter | da6c059 | 2017-12-14 21:30:53 +0100 | [diff] [blame] | 55 | * This should only be used by drivers which are still subclassing |
| 56 | * &drm_atomic_state and haven't switched to &drm_private_state yet. |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 57 | */ |
| 58 | void drm_atomic_state_default_release(struct drm_atomic_state *state) |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 59 | { |
| 60 | kfree(state->connectors); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 61 | kfree(state->crtcs); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 62 | kfree(state->planes); |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 63 | kfree(state->private_objs); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 64 | } |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 65 | EXPORT_SYMBOL(drm_atomic_state_default_release); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 66 | |
| 67 | /** |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 68 | * drm_atomic_state_init - init new atomic state |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 69 | * @dev: DRM device |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 70 | * @state: atomic state |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 71 | * |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 72 | * Default implementation for filling in a new atomic state. |
Daniel Vetter | da6c059 | 2017-12-14 21:30:53 +0100 | [diff] [blame] | 73 | * This should only be used by drivers which are still subclassing |
| 74 | * &drm_atomic_state and haven't switched to &drm_private_state yet. |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 75 | */ |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 76 | int |
| 77 | 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] | 78 | { |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 79 | kref_init(&state->ref); |
| 80 | |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 81 | /* TODO legacy paths should maybe do a better job about |
| 82 | * setting this appropriately? |
| 83 | */ |
| 84 | state->allow_modeset = true; |
| 85 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 86 | state->crtcs = kcalloc(dev->mode_config.num_crtc, |
| 87 | sizeof(*state->crtcs), GFP_KERNEL); |
| 88 | if (!state->crtcs) |
| 89 | goto fail; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 90 | state->planes = kcalloc(dev->mode_config.num_total_plane, |
| 91 | sizeof(*state->planes), GFP_KERNEL); |
| 92 | if (!state->planes) |
| 93 | goto fail; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 94 | |
| 95 | state->dev = dev; |
| 96 | |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 97 | DRM_DEBUG_ATOMIC("Allocated atomic state %p\n", state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 98 | |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 99 | return 0; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 100 | fail: |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 101 | drm_atomic_state_default_release(state); |
| 102 | return -ENOMEM; |
| 103 | } |
| 104 | EXPORT_SYMBOL(drm_atomic_state_init); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 105 | |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 106 | /** |
| 107 | * drm_atomic_state_alloc - allocate atomic state |
| 108 | * @dev: DRM device |
| 109 | * |
| 110 | * This allocates an empty atomic state to track updates. |
| 111 | */ |
| 112 | struct drm_atomic_state * |
| 113 | drm_atomic_state_alloc(struct drm_device *dev) |
| 114 | { |
| 115 | struct drm_mode_config *config = &dev->mode_config; |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 116 | |
| 117 | if (!config->funcs->atomic_state_alloc) { |
Dawid Kurek | ac7c748 | 2017-06-15 19:45:56 +0200 | [diff] [blame] | 118 | struct drm_atomic_state *state; |
| 119 | |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 120 | state = kzalloc(sizeof(*state), GFP_KERNEL); |
| 121 | if (!state) |
| 122 | return NULL; |
| 123 | if (drm_atomic_state_init(dev, state) < 0) { |
| 124 | kfree(state); |
| 125 | return NULL; |
| 126 | } |
| 127 | return state; |
| 128 | } |
| 129 | |
| 130 | return config->funcs->atomic_state_alloc(dev); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 131 | } |
| 132 | EXPORT_SYMBOL(drm_atomic_state_alloc); |
| 133 | |
| 134 | /** |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 135 | * drm_atomic_state_default_clear - clear base atomic state |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 136 | * @state: atomic state |
| 137 | * |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 138 | * Default implementation for clearing atomic state. |
Daniel Vetter | da6c059 | 2017-12-14 21:30:53 +0100 | [diff] [blame] | 139 | * This should only be used by drivers which are still subclassing |
| 140 | * &drm_atomic_state and haven't switched to &drm_private_state yet. |
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 | 63e83c1 | 2016-06-02 00:06:32 +0200 | [diff] [blame] | 151 | struct drm_connector *connector = state->connectors[i].ptr; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 152 | |
| 153 | if (!connector) |
| 154 | continue; |
| 155 | |
Dave Airlie | d2307de | 2016-04-27 11:27:39 +1000 | [diff] [blame] | 156 | connector->funcs->atomic_destroy_state(connector, |
Daniel Vetter | 63e83c1 | 2016-06-02 00:06:32 +0200 | [diff] [blame] | 157 | state->connectors[i].state); |
| 158 | state->connectors[i].ptr = NULL; |
| 159 | state->connectors[i].state = NULL; |
Ville Syrjälä | f0b408e | 2018-05-02 21:32:47 +0300 | [diff] [blame] | 160 | state->connectors[i].old_state = NULL; |
| 161 | state->connectors[i].new_state = NULL; |
Thierry Reding | ad09360 | 2017-02-28 15:46:39 +0100 | [diff] [blame] | 162 | drm_connector_put(connector); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 163 | } |
| 164 | |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 165 | for (i = 0; i < config->num_crtc; i++) { |
Daniel Vetter | 5d943aa6 | 2016-06-02 00:06:34 +0200 | [diff] [blame] | 166 | struct drm_crtc *crtc = state->crtcs[i].ptr; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 167 | |
| 168 | if (!crtc) |
| 169 | continue; |
| 170 | |
| 171 | crtc->funcs->atomic_destroy_state(crtc, |
Daniel Vetter | 5d943aa6 | 2016-06-02 00:06:34 +0200 | [diff] [blame] | 172 | state->crtcs[i].state); |
Daniel Vetter | 3b24f7d | 2016-06-08 14:19:00 +0200 | [diff] [blame] | 173 | |
Daniel Vetter | 5d943aa6 | 2016-06-02 00:06:34 +0200 | [diff] [blame] | 174 | state->crtcs[i].ptr = NULL; |
| 175 | state->crtcs[i].state = NULL; |
Ville Syrjälä | f0b408e | 2018-05-02 21:32:47 +0300 | [diff] [blame] | 176 | state->crtcs[i].old_state = NULL; |
| 177 | state->crtcs[i].new_state = NULL; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 178 | } |
| 179 | |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 180 | for (i = 0; i < config->num_total_plane; i++) { |
Daniel Vetter | b8b5342 | 2016-06-02 00:06:33 +0200 | [diff] [blame] | 181 | struct drm_plane *plane = state->planes[i].ptr; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 182 | |
| 183 | if (!plane) |
| 184 | continue; |
| 185 | |
| 186 | plane->funcs->atomic_destroy_state(plane, |
Daniel Vetter | b8b5342 | 2016-06-02 00:06:33 +0200 | [diff] [blame] | 187 | state->planes[i].state); |
| 188 | state->planes[i].ptr = NULL; |
| 189 | state->planes[i].state = NULL; |
Ville Syrjälä | f0b408e | 2018-05-02 21:32:47 +0300 | [diff] [blame] | 190 | state->planes[i].old_state = NULL; |
| 191 | state->planes[i].new_state = NULL; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 192 | } |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 193 | |
| 194 | for (i = 0; i < state->num_private_objs; i++) { |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 195 | struct drm_private_obj *obj = state->private_objs[i].ptr; |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 196 | |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 197 | obj->funcs->atomic_destroy_state(obj, |
| 198 | state->private_objs[i].state); |
| 199 | state->private_objs[i].ptr = NULL; |
| 200 | state->private_objs[i].state = NULL; |
Ville Syrjälä | b5cb2e5 | 2018-05-02 21:32:47 +0300 | [diff] [blame] | 201 | state->private_objs[i].old_state = NULL; |
| 202 | state->private_objs[i].new_state = NULL; |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 203 | } |
| 204 | state->num_private_objs = 0; |
| 205 | |
Maarten Lankhorst | 21a01ab | 2017-09-04 12:48:37 +0200 | [diff] [blame] | 206 | if (state->fake_commit) { |
| 207 | drm_crtc_commit_put(state->fake_commit); |
| 208 | state->fake_commit = NULL; |
| 209 | } |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 210 | } |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 211 | EXPORT_SYMBOL(drm_atomic_state_default_clear); |
| 212 | |
| 213 | /** |
| 214 | * drm_atomic_state_clear - clear state object |
| 215 | * @state: atomic state |
| 216 | * |
| 217 | * When the w/w mutex algorithm detects a deadlock we need to back off and drop |
| 218 | * all locks. So someone else could sneak in and change the current modeset |
| 219 | * configuration. Which means that all the state assembled in @state is no |
| 220 | * longer an atomic update to the current state, but to some arbitrary earlier |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 221 | * state. Which could break assumptions the driver's |
| 222 | * &drm_mode_config_funcs.atomic_check likely relies on. |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 223 | * |
| 224 | * Hence we must clear all cached state and completely start over, using this |
| 225 | * function. |
| 226 | */ |
| 227 | void drm_atomic_state_clear(struct drm_atomic_state *state) |
| 228 | { |
| 229 | struct drm_device *dev = state->dev; |
| 230 | struct drm_mode_config *config = &dev->mode_config; |
| 231 | |
| 232 | if (config->funcs->atomic_state_clear) |
| 233 | config->funcs->atomic_state_clear(state); |
| 234 | else |
| 235 | drm_atomic_state_default_clear(state); |
| 236 | } |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 237 | EXPORT_SYMBOL(drm_atomic_state_clear); |
| 238 | |
| 239 | /** |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 240 | * __drm_atomic_state_free - free all memory for an atomic state |
| 241 | * @ref: This atomic state to deallocate |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 242 | * |
| 243 | * This frees all memory associated with an atomic state, including all the |
| 244 | * per-object state for planes, crtcs and connectors. |
| 245 | */ |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 246 | void __drm_atomic_state_free(struct kref *ref) |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 247 | { |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 248 | struct drm_atomic_state *state = container_of(ref, typeof(*state), ref); |
| 249 | struct drm_mode_config *config = &state->dev->mode_config; |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 250 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 251 | drm_atomic_state_clear(state); |
| 252 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 253 | DRM_DEBUG_ATOMIC("Freeing atomic state %p\n", state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 254 | |
Maarten Lankhorst | 036ef57 | 2015-05-18 10:06:40 +0200 | [diff] [blame] | 255 | if (config->funcs->atomic_state_free) { |
| 256 | config->funcs->atomic_state_free(state); |
| 257 | } else { |
| 258 | drm_atomic_state_default_release(state); |
| 259 | kfree(state); |
| 260 | } |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 261 | } |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 262 | EXPORT_SYMBOL(__drm_atomic_state_free); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 263 | |
| 264 | /** |
| 265 | * drm_atomic_get_crtc_state - get crtc state |
| 266 | * @state: global atomic state object |
| 267 | * @crtc: crtc to get state object for |
| 268 | * |
| 269 | * This function returns the crtc state for the given crtc, allocating it if |
| 270 | * needed. It will also grab the relevant crtc lock to make sure that the state |
| 271 | * is consistent. |
| 272 | * |
| 273 | * Returns: |
| 274 | * |
| 275 | * Either the allocated state or the error code encoded into the pointer. When |
| 276 | * the error is EDEADLK then the w/w mutex code has detected a deadlock and the |
| 277 | * entire atomic sequence must be restarted. All other errors are fatal. |
| 278 | */ |
| 279 | struct drm_crtc_state * |
| 280 | drm_atomic_get_crtc_state(struct drm_atomic_state *state, |
| 281 | struct drm_crtc *crtc) |
| 282 | { |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 283 | int ret, index = drm_crtc_index(crtc); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 284 | struct drm_crtc_state *crtc_state; |
| 285 | |
Maarten Lankhorst | 7f4eaa89 | 2016-05-03 11:12:31 +0200 | [diff] [blame] | 286 | WARN_ON(!state->acquire_ctx); |
| 287 | |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 288 | crtc_state = drm_atomic_get_existing_crtc_state(state, crtc); |
| 289 | if (crtc_state) |
| 290 | return crtc_state; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 291 | |
| 292 | ret = drm_modeset_lock(&crtc->mutex, state->acquire_ctx); |
| 293 | if (ret) |
| 294 | return ERR_PTR(ret); |
| 295 | |
| 296 | crtc_state = crtc->funcs->atomic_duplicate_state(crtc); |
| 297 | if (!crtc_state) |
| 298 | return ERR_PTR(-ENOMEM); |
| 299 | |
Daniel Vetter | 5d943aa6 | 2016-06-02 00:06:34 +0200 | [diff] [blame] | 300 | state->crtcs[index].state = crtc_state; |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 301 | state->crtcs[index].old_state = crtc->state; |
| 302 | state->crtcs[index].new_state = crtc_state; |
Daniel Vetter | 5d943aa6 | 2016-06-02 00:06:34 +0200 | [diff] [blame] | 303 | state->crtcs[index].ptr = crtc; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 304 | crtc_state->state = state; |
| 305 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 306 | DRM_DEBUG_ATOMIC("Added [CRTC:%d:%s] %p state to %p\n", |
| 307 | crtc->base.id, crtc->name, crtc_state, state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 308 | |
| 309 | return crtc_state; |
| 310 | } |
| 311 | EXPORT_SYMBOL(drm_atomic_get_crtc_state); |
| 312 | |
Ville Syrjälä | b2432ad | 2018-11-01 20:46:45 +0200 | [diff] [blame^] | 313 | static int drm_atomic_crtc_check(const struct drm_crtc_state *old_crtc_state, |
| 314 | const struct drm_crtc_state *new_crtc_state) |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 315 | { |
Ville Syrjälä | b2432ad | 2018-11-01 20:46:45 +0200 | [diff] [blame^] | 316 | struct drm_crtc *crtc = new_crtc_state->crtc; |
| 317 | |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 318 | /* NOTE: we explicitly don't enforce constraints such as primary |
| 319 | * layer covering entire screen, since that is something we want |
| 320 | * to allow (on hw that supports it). For hw that does not, it |
| 321 | * should be checked in driver's crtc->atomic_check() vfunc. |
| 322 | * |
| 323 | * TODO: Add generic modeset state checks once we support those. |
| 324 | */ |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 325 | |
Ville Syrjälä | b2432ad | 2018-11-01 20:46:45 +0200 | [diff] [blame^] | 326 | if (new_crtc_state->active && !new_crtc_state->enable) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 327 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] active without enabled\n", |
| 328 | crtc->base.id, crtc->name); |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 329 | return -EINVAL; |
| 330 | } |
| 331 | |
Daniel Stone | 99cf4a2 | 2015-05-25 19:11:51 +0100 | [diff] [blame] | 332 | /* The state->enable vs. state->mode_blob checks can be WARN_ON, |
| 333 | * as this is a kernel-internal detail that userspace should never |
| 334 | * be able to trigger. */ |
| 335 | if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) && |
Ville Syrjälä | b2432ad | 2018-11-01 20:46:45 +0200 | [diff] [blame^] | 336 | WARN_ON(new_crtc_state->enable && !new_crtc_state->mode_blob)) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 337 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enabled without mode blob\n", |
| 338 | crtc->base.id, crtc->name); |
Daniel Stone | 99cf4a2 | 2015-05-25 19:11:51 +0100 | [diff] [blame] | 339 | return -EINVAL; |
| 340 | } |
| 341 | |
| 342 | if (drm_core_check_feature(crtc->dev, DRIVER_ATOMIC) && |
Ville Syrjälä | b2432ad | 2018-11-01 20:46:45 +0200 | [diff] [blame^] | 343 | WARN_ON(!new_crtc_state->enable && new_crtc_state->mode_blob)) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 344 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] disabled with mode blob\n", |
| 345 | crtc->base.id, crtc->name); |
Daniel Stone | 99cf4a2 | 2015-05-25 19:11:51 +0100 | [diff] [blame] | 346 | return -EINVAL; |
| 347 | } |
| 348 | |
Daniel Vetter | 4cba685 | 2015-12-08 09:49:20 +0100 | [diff] [blame] | 349 | /* |
| 350 | * Reject event generation for when a CRTC is off and stays off. |
| 351 | * It wouldn't be hard to implement this, but userspace has a track |
| 352 | * record of happily burning through 100% cpu (or worse, crash) when the |
| 353 | * display pipe is suspended. To avoid all that fun just reject updates |
| 354 | * that ask for events since likely that indicates a bug in the |
| 355 | * compositor's drawing loop. This is consistent with the vblank IOCTL |
| 356 | * and legacy page_flip IOCTL which also reject service on a disabled |
| 357 | * pipe. |
| 358 | */ |
Ville Syrjälä | b2432ad | 2018-11-01 20:46:45 +0200 | [diff] [blame^] | 359 | if (new_crtc_state->event && |
| 360 | !new_crtc_state->active && !old_crtc_state->active) { |
Russell King | 6ac7c54 | 2017-02-13 12:27:03 +0000 | [diff] [blame] | 361 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] requesting event but off\n", |
| 362 | crtc->base.id, crtc->name); |
Daniel Vetter | 4cba685 | 2015-12-08 09:49:20 +0100 | [diff] [blame] | 363 | return -EINVAL; |
| 364 | } |
| 365 | |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 366 | return 0; |
| 367 | } |
| 368 | |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 369 | static void drm_atomic_crtc_print_state(struct drm_printer *p, |
| 370 | const struct drm_crtc_state *state) |
| 371 | { |
| 372 | struct drm_crtc *crtc = state->crtc; |
| 373 | |
| 374 | drm_printf(p, "crtc[%u]: %s\n", crtc->base.id, crtc->name); |
| 375 | drm_printf(p, "\tenable=%d\n", state->enable); |
| 376 | drm_printf(p, "\tactive=%d\n", state->active); |
| 377 | drm_printf(p, "\tplanes_changed=%d\n", state->planes_changed); |
| 378 | drm_printf(p, "\tmode_changed=%d\n", state->mode_changed); |
| 379 | drm_printf(p, "\tactive_changed=%d\n", state->active_changed); |
| 380 | drm_printf(p, "\tconnectors_changed=%d\n", state->connectors_changed); |
| 381 | drm_printf(p, "\tcolor_mgmt_changed=%d\n", state->color_mgmt_changed); |
| 382 | drm_printf(p, "\tplane_mask=%x\n", state->plane_mask); |
| 383 | drm_printf(p, "\tconnector_mask=%x\n", state->connector_mask); |
| 384 | drm_printf(p, "\tencoder_mask=%x\n", state->encoder_mask); |
| 385 | drm_printf(p, "\tmode: " DRM_MODE_FMT "\n", DRM_MODE_ARG(&state->mode)); |
| 386 | |
| 387 | if (crtc->funcs->atomic_print_state) |
| 388 | crtc->funcs->atomic_print_state(p, state); |
| 389 | } |
| 390 | |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 391 | static int drm_atomic_connector_check(struct drm_connector *connector, |
| 392 | struct drm_connector_state *state) |
| 393 | { |
| 394 | struct drm_crtc_state *crtc_state; |
| 395 | struct drm_writeback_job *writeback_job = state->writeback_job; |
| 396 | |
| 397 | if ((connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) || !writeback_job) |
| 398 | return 0; |
| 399 | |
| 400 | if (writeback_job->fb && !state->crtc) { |
| 401 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] framebuffer without CRTC\n", |
| 402 | connector->base.id, connector->name); |
| 403 | return -EINVAL; |
| 404 | } |
| 405 | |
| 406 | if (state->crtc) |
| 407 | crtc_state = drm_atomic_get_existing_crtc_state(state->state, |
| 408 | state->crtc); |
| 409 | |
| 410 | if (writeback_job->fb && !crtc_state->active) { |
| 411 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] has framebuffer, but [CRTC:%d] is off\n", |
| 412 | connector->base.id, connector->name, |
| 413 | state->crtc->base.id); |
| 414 | return -EINVAL; |
| 415 | } |
| 416 | |
Brian Starkey | b13cc8d | 2017-03-29 17:42:33 +0100 | [diff] [blame] | 417 | if (writeback_job->out_fence && !writeback_job->fb) { |
| 418 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] requesting out-fence without framebuffer\n", |
| 419 | connector->base.id, connector->name); |
| 420 | return -EINVAL; |
| 421 | } |
| 422 | |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | /** |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 427 | * drm_atomic_get_plane_state - get plane state |
| 428 | * @state: global atomic state object |
| 429 | * @plane: plane to get state object for |
| 430 | * |
| 431 | * This function returns the plane state for the given plane, allocating it if |
| 432 | * needed. It will also grab the relevant plane lock to make sure that the state |
| 433 | * is consistent. |
| 434 | * |
| 435 | * Returns: |
| 436 | * |
| 437 | * Either the allocated state or the error code encoded into the pointer. When |
| 438 | * the error is EDEADLK then the w/w mutex code has detected a deadlock and the |
| 439 | * entire atomic sequence must be restarted. All other errors are fatal. |
| 440 | */ |
| 441 | struct drm_plane_state * |
| 442 | drm_atomic_get_plane_state(struct drm_atomic_state *state, |
| 443 | struct drm_plane *plane) |
| 444 | { |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 445 | int ret, index = drm_plane_index(plane); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 446 | struct drm_plane_state *plane_state; |
| 447 | |
Maarten Lankhorst | 7f4eaa89 | 2016-05-03 11:12:31 +0200 | [diff] [blame] | 448 | WARN_ON(!state->acquire_ctx); |
| 449 | |
Ville Syrjälä | e00fb85 | 2018-05-25 21:50:45 +0300 | [diff] [blame] | 450 | /* the legacy pointers should never be set */ |
| 451 | WARN_ON(plane->fb); |
| 452 | WARN_ON(plane->old_fb); |
| 453 | WARN_ON(plane->crtc); |
| 454 | |
Maarten Lankhorst | 1b26a5e | 2015-05-13 10:37:25 +0200 | [diff] [blame] | 455 | plane_state = drm_atomic_get_existing_plane_state(state, plane); |
| 456 | if (plane_state) |
| 457 | return plane_state; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 458 | |
Daniel Vetter | 4d02e2d | 2014-11-11 10:12:00 +0100 | [diff] [blame] | 459 | ret = drm_modeset_lock(&plane->mutex, state->acquire_ctx); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 460 | if (ret) |
| 461 | return ERR_PTR(ret); |
| 462 | |
| 463 | plane_state = plane->funcs->atomic_duplicate_state(plane); |
| 464 | if (!plane_state) |
| 465 | return ERR_PTR(-ENOMEM); |
| 466 | |
Daniel Vetter | b8b5342 | 2016-06-02 00:06:33 +0200 | [diff] [blame] | 467 | state->planes[index].state = plane_state; |
| 468 | state->planes[index].ptr = plane; |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 469 | state->planes[index].old_state = plane->state; |
| 470 | state->planes[index].new_state = plane_state; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 471 | plane_state->state = state; |
| 472 | |
Ville Syrjälä | 9f4c97a | 2015-12-08 18:41:54 +0200 | [diff] [blame] | 473 | DRM_DEBUG_ATOMIC("Added [PLANE:%d:%s] %p state to %p\n", |
| 474 | plane->base.id, plane->name, plane_state, state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 475 | |
| 476 | if (plane_state->crtc) { |
| 477 | struct drm_crtc_state *crtc_state; |
| 478 | |
| 479 | crtc_state = drm_atomic_get_crtc_state(state, |
| 480 | plane_state->crtc); |
| 481 | if (IS_ERR(crtc_state)) |
| 482 | return ERR_CAST(crtc_state); |
| 483 | } |
| 484 | |
| 485 | return plane_state; |
| 486 | } |
| 487 | EXPORT_SYMBOL(drm_atomic_get_plane_state); |
| 488 | |
Daniel Vetter | f8aeb41 | 2015-08-26 21:49:42 +0200 | [diff] [blame] | 489 | static bool |
| 490 | plane_switching_crtc(struct drm_atomic_state *state, |
| 491 | struct drm_plane *plane, |
| 492 | struct drm_plane_state *plane_state) |
| 493 | { |
| 494 | if (!plane->state->crtc || !plane_state->crtc) |
| 495 | return false; |
| 496 | |
| 497 | if (plane->state->crtc == plane_state->crtc) |
| 498 | return false; |
| 499 | |
| 500 | /* This could be refined, but currently there's no helper or driver code |
| 501 | * to implement direct switching of active planes nor userspace to take |
| 502 | * advantage of more direct plane switching without the intermediate |
| 503 | * full OFF state. |
| 504 | */ |
| 505 | return true; |
| 506 | } |
| 507 | |
Rob Clark | ac9c925 | 2014-12-18 16:01:47 -0500 | [diff] [blame] | 508 | /** |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 509 | * drm_atomic_plane_check - check plane state |
| 510 | * @plane: plane to check |
| 511 | * @state: plane state to check |
| 512 | * |
| 513 | * Provides core sanity checks for plane state. |
| 514 | * |
| 515 | * RETURNS: |
| 516 | * Zero on success, error code on failure |
| 517 | */ |
| 518 | static int drm_atomic_plane_check(struct drm_plane *plane, |
| 519 | struct drm_plane_state *state) |
| 520 | { |
| 521 | unsigned int fb_width, fb_height; |
Laurent Pinchart | ead8610 | 2015-03-05 02:25:43 +0200 | [diff] [blame] | 522 | int ret; |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 523 | |
| 524 | /* either *both* CRTC and FB must be set, or neither */ |
Maarten Lankhorst | fa5aaee | 2018-01-30 11:27:04 +0100 | [diff] [blame] | 525 | if (state->crtc && !state->fb) { |
Ville Syrjälä | b6f690a | 2018-06-11 22:34:01 +0300 | [diff] [blame] | 526 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] CRTC set but no FB\n", |
| 527 | plane->base.id, plane->name); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 528 | return -EINVAL; |
Maarten Lankhorst | fa5aaee | 2018-01-30 11:27:04 +0100 | [diff] [blame] | 529 | } else if (state->fb && !state->crtc) { |
Ville Syrjälä | b6f690a | 2018-06-11 22:34:01 +0300 | [diff] [blame] | 530 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] FB set but no CRTC\n", |
| 531 | plane->base.id, plane->name); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 532 | return -EINVAL; |
| 533 | } |
| 534 | |
| 535 | /* if disabled, we don't care about the rest of the state: */ |
| 536 | if (!state->crtc) |
| 537 | return 0; |
| 538 | |
| 539 | /* Check whether this plane is usable on this CRTC */ |
| 540 | if (!(plane->possible_crtcs & drm_crtc_mask(state->crtc))) { |
Ville Syrjälä | b6f690a | 2018-06-11 22:34:01 +0300 | [diff] [blame] | 541 | DRM_DEBUG_ATOMIC("Invalid [CRTC:%d:%s] for [PLANE:%d:%s]\n", |
| 542 | state->crtc->base.id, state->crtc->name, |
| 543 | plane->base.id, plane->name); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 544 | return -EINVAL; |
| 545 | } |
| 546 | |
| 547 | /* Check whether this plane supports the fb pixel format. */ |
Ville Syrjälä | 23163a7 | 2017-12-22 21:22:30 +0200 | [diff] [blame] | 548 | ret = drm_plane_check_pixel_format(plane, state->fb->format->format, |
| 549 | state->fb->modifier); |
Laurent Pinchart | ead8610 | 2015-03-05 02:25:43 +0200 | [diff] [blame] | 550 | if (ret) { |
Eric Engestrom | b3c11ac | 2016-11-12 01:12:56 +0000 | [diff] [blame] | 551 | struct drm_format_name_buf format_name; |
Ville Syrjälä | b6f690a | 2018-06-11 22:34:01 +0300 | [diff] [blame] | 552 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] invalid pixel format %s, modifier 0x%llx\n", |
| 553 | plane->base.id, plane->name, |
Ville Syrjälä | 23163a7 | 2017-12-22 21:22:30 +0200 | [diff] [blame] | 554 | drm_get_format_name(state->fb->format->format, |
| 555 | &format_name), |
| 556 | state->fb->modifier); |
Laurent Pinchart | ead8610 | 2015-03-05 02:25:43 +0200 | [diff] [blame] | 557 | return ret; |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | /* Give drivers some help against integer overflows */ |
| 561 | if (state->crtc_w > INT_MAX || |
| 562 | state->crtc_x > INT_MAX - (int32_t) state->crtc_w || |
| 563 | state->crtc_h > INT_MAX || |
| 564 | state->crtc_y > INT_MAX - (int32_t) state->crtc_h) { |
Ville Syrjälä | b6f690a | 2018-06-11 22:34:01 +0300 | [diff] [blame] | 565 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] invalid CRTC coordinates %ux%u+%d+%d\n", |
| 566 | plane->base.id, plane->name, |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 567 | state->crtc_w, state->crtc_h, |
| 568 | state->crtc_x, state->crtc_y); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 569 | return -ERANGE; |
| 570 | } |
| 571 | |
| 572 | fb_width = state->fb->width << 16; |
| 573 | fb_height = state->fb->height << 16; |
| 574 | |
| 575 | /* Make sure source coordinates are inside the fb. */ |
| 576 | if (state->src_w > fb_width || |
| 577 | state->src_x > fb_width - state->src_w || |
| 578 | state->src_h > fb_height || |
| 579 | state->src_y > fb_height - state->src_h) { |
Ville Syrjälä | b6f690a | 2018-06-11 22:34:01 +0300 | [diff] [blame] | 580 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] invalid source coordinates " |
Ville Syrjälä | 0338f0d | 2017-11-01 20:35:33 +0200 | [diff] [blame] | 581 | "%u.%06ux%u.%06u+%u.%06u+%u.%06u (fb %ux%u)\n", |
Ville Syrjälä | b6f690a | 2018-06-11 22:34:01 +0300 | [diff] [blame] | 582 | plane->base.id, plane->name, |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 583 | state->src_w >> 16, ((state->src_w & 0xffff) * 15625) >> 10, |
| 584 | state->src_h >> 16, ((state->src_h & 0xffff) * 15625) >> 10, |
| 585 | state->src_x >> 16, ((state->src_x & 0xffff) * 15625) >> 10, |
Ville Syrjälä | 0338f0d | 2017-11-01 20:35:33 +0200 | [diff] [blame] | 586 | state->src_y >> 16, ((state->src_y & 0xffff) * 15625) >> 10, |
| 587 | state->fb->width, state->fb->height); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 588 | return -ENOSPC; |
| 589 | } |
| 590 | |
Daniel Vetter | f8aeb41 | 2015-08-26 21:49:42 +0200 | [diff] [blame] | 591 | if (plane_switching_crtc(state->state, plane, state)) { |
Ville Syrjälä | 9f4c97a | 2015-12-08 18:41:54 +0200 | [diff] [blame] | 592 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] switching CRTC directly\n", |
| 593 | plane->base.id, plane->name); |
Daniel Vetter | f8aeb41 | 2015-08-26 21:49:42 +0200 | [diff] [blame] | 594 | return -EINVAL; |
| 595 | } |
| 596 | |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 597 | return 0; |
| 598 | } |
| 599 | |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 600 | static void drm_atomic_plane_print_state(struct drm_printer *p, |
| 601 | const struct drm_plane_state *state) |
| 602 | { |
| 603 | struct drm_plane *plane = state->plane; |
| 604 | struct drm_rect src = drm_plane_state_src(state); |
| 605 | struct drm_rect dest = drm_plane_state_dest(state); |
| 606 | |
| 607 | drm_printf(p, "plane[%u]: %s\n", plane->base.id, plane->name); |
| 608 | drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)"); |
| 609 | drm_printf(p, "\tfb=%u\n", state->fb ? state->fb->base.id : 0); |
Noralf Trønnes | f02b604 | 2017-11-07 20:13:41 +0100 | [diff] [blame] | 610 | if (state->fb) |
| 611 | drm_framebuffer_print_info(p, 2, state->fb); |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 612 | drm_printf(p, "\tcrtc-pos=" DRM_RECT_FMT "\n", DRM_RECT_ARG(&dest)); |
| 613 | drm_printf(p, "\tsrc-pos=" DRM_RECT_FP_FMT "\n", DRM_RECT_FP_ARG(&src)); |
| 614 | drm_printf(p, "\trotation=%x\n", state->rotation); |
Benjamin Gaignard | f8878bb | 2018-06-05 15:54:01 +0200 | [diff] [blame] | 615 | drm_printf(p, "\tnormalized-zpos=%x\n", state->normalized_zpos); |
Ville Syrjälä | 56dbbaf | 2018-02-19 22:28:46 +0200 | [diff] [blame] | 616 | drm_printf(p, "\tcolor-encoding=%s\n", |
| 617 | drm_get_color_encoding_name(state->color_encoding)); |
| 618 | drm_printf(p, "\tcolor-range=%s\n", |
| 619 | drm_get_color_range_name(state->color_range)); |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 620 | |
| 621 | if (plane->funcs->atomic_print_state) |
| 622 | plane->funcs->atomic_print_state(p, state); |
| 623 | } |
| 624 | |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 625 | /** |
Daniel Vetter | da6c059 | 2017-12-14 21:30:53 +0100 | [diff] [blame] | 626 | * DOC: handling driver private state |
| 627 | * |
| 628 | * Very often the DRM objects exposed to userspace in the atomic modeset api |
| 629 | * (&drm_connector, &drm_crtc and &drm_plane) do not map neatly to the |
| 630 | * underlying hardware. Especially for any kind of shared resources (e.g. shared |
| 631 | * clocks, scaler units, bandwidth and fifo limits shared among a group of |
| 632 | * planes or CRTCs, and so on) it makes sense to model these as independent |
| 633 | * objects. Drivers then need to do similar state tracking and commit ordering for |
| 634 | * such private (since not exposed to userpace) objects as the atomic core and |
| 635 | * helpers already provide for connectors, planes and CRTCs. |
| 636 | * |
| 637 | * To make this easier on drivers the atomic core provides some support to track |
| 638 | * driver private state objects using struct &drm_private_obj, with the |
| 639 | * associated state struct &drm_private_state. |
| 640 | * |
| 641 | * Similar to userspace-exposed objects, private state structures can be |
| 642 | * acquired by calling drm_atomic_get_private_obj_state(). Since this function |
| 643 | * does not take care of locking, drivers should wrap it for each type of |
| 644 | * private state object they have with the required call to drm_modeset_lock() |
| 645 | * for the corresponding &drm_modeset_lock. |
| 646 | * |
| 647 | * All private state structures contained in a &drm_atomic_state update can be |
| 648 | * iterated using for_each_oldnew_private_obj_in_state(), |
| 649 | * for_each_new_private_obj_in_state() and for_each_old_private_obj_in_state(). |
| 650 | * Drivers are recommended to wrap these for each type of driver private state |
| 651 | * object they have, filtering on &drm_private_obj.funcs using for_each_if(), at |
| 652 | * least if they want to iterate over all objects of a given type. |
| 653 | * |
| 654 | * An earlier way to handle driver private state was by subclassing struct |
| 655 | * &drm_atomic_state. But since that encourages non-standard ways to implement |
| 656 | * the check/commit split atomic requires (by using e.g. "check and rollback or |
| 657 | * commit instead" of "duplicate state, check, then either commit or release |
| 658 | * duplicated state) it is deprecated in favour of using &drm_private_state. |
| 659 | */ |
| 660 | |
| 661 | /** |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 662 | * drm_atomic_private_obj_init - initialize private object |
| 663 | * @obj: private object |
| 664 | * @state: initial private object state |
| 665 | * @funcs: pointer to the struct of function pointers that identify the object |
| 666 | * type |
| 667 | * |
| 668 | * Initialize the private object, which can be embedded into any |
| 669 | * driver private object that needs its own atomic state. |
| 670 | */ |
| 671 | void |
| 672 | drm_atomic_private_obj_init(struct drm_private_obj *obj, |
| 673 | struct drm_private_state *state, |
| 674 | const struct drm_private_state_funcs *funcs) |
| 675 | { |
| 676 | memset(obj, 0, sizeof(*obj)); |
| 677 | |
| 678 | obj->state = state; |
| 679 | obj->funcs = funcs; |
| 680 | } |
| 681 | EXPORT_SYMBOL(drm_atomic_private_obj_init); |
| 682 | |
| 683 | /** |
| 684 | * drm_atomic_private_obj_fini - finalize private object |
| 685 | * @obj: private object |
| 686 | * |
| 687 | * Finalize the private object. |
| 688 | */ |
| 689 | void |
| 690 | drm_atomic_private_obj_fini(struct drm_private_obj *obj) |
| 691 | { |
| 692 | obj->funcs->atomic_destroy_state(obj, obj->state); |
| 693 | } |
| 694 | EXPORT_SYMBOL(drm_atomic_private_obj_fini); |
| 695 | |
| 696 | /** |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 697 | * drm_atomic_get_private_obj_state - get private object state |
| 698 | * @state: global atomic state |
| 699 | * @obj: private object to get the state for |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 700 | * |
| 701 | * This function returns the private object state for the given private object, |
| 702 | * allocating the state if needed. It does not grab any locks as the caller is |
| 703 | * expected to care of any required locking. |
| 704 | * |
| 705 | * RETURNS: |
| 706 | * |
| 707 | * Either the allocated state or the error code encoded into a pointer. |
| 708 | */ |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 709 | struct drm_private_state * |
| 710 | drm_atomic_get_private_obj_state(struct drm_atomic_state *state, |
| 711 | struct drm_private_obj *obj) |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 712 | { |
| 713 | int index, num_objs, i; |
| 714 | size_t size; |
| 715 | struct __drm_private_objs_state *arr; |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 716 | struct drm_private_state *obj_state; |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 717 | |
| 718 | for (i = 0; i < state->num_private_objs; i++) |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 719 | if (obj == state->private_objs[i].ptr) |
| 720 | return state->private_objs[i].state; |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 721 | |
| 722 | num_objs = state->num_private_objs + 1; |
| 723 | size = sizeof(*state->private_objs) * num_objs; |
| 724 | arr = krealloc(state->private_objs, size, GFP_KERNEL); |
| 725 | if (!arr) |
| 726 | return ERR_PTR(-ENOMEM); |
| 727 | |
| 728 | state->private_objs = arr; |
| 729 | index = state->num_private_objs; |
| 730 | memset(&state->private_objs[index], 0, sizeof(*state->private_objs)); |
| 731 | |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 732 | obj_state = obj->funcs->atomic_duplicate_state(obj); |
| 733 | if (!obj_state) |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 734 | return ERR_PTR(-ENOMEM); |
| 735 | |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 736 | state->private_objs[index].state = obj_state; |
| 737 | state->private_objs[index].old_state = obj->state; |
| 738 | state->private_objs[index].new_state = obj_state; |
| 739 | state->private_objs[index].ptr = obj; |
Alexandru Gheorghe | e89ea35 | 2018-05-30 18:30:52 +0100 | [diff] [blame] | 740 | obj_state->state = state; |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 741 | |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 742 | state->num_private_objs = num_objs; |
| 743 | |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 744 | DRM_DEBUG_ATOMIC("Added new private object %p state %p to %p\n", |
| 745 | obj, obj_state, state); |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 746 | |
Ville Syrjälä | a4370c7 | 2017-07-12 18:51:02 +0300 | [diff] [blame] | 747 | return obj_state; |
Pandiyan, Dhinakaran | b430c27 | 2017-04-20 22:51:30 -0700 | [diff] [blame] | 748 | } |
| 749 | EXPORT_SYMBOL(drm_atomic_get_private_obj_state); |
| 750 | |
| 751 | /** |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 752 | * drm_atomic_get_connector_state - get connector state |
| 753 | * @state: global atomic state object |
| 754 | * @connector: connector to get state object for |
| 755 | * |
| 756 | * This function returns the connector state for the given connector, |
| 757 | * allocating it if needed. It will also grab the relevant connector lock to |
| 758 | * make sure that the state is consistent. |
| 759 | * |
| 760 | * Returns: |
| 761 | * |
| 762 | * Either the allocated state or the error code encoded into the pointer. When |
| 763 | * the error is EDEADLK then the w/w mutex code has detected a deadlock and the |
| 764 | * entire atomic sequence must be restarted. All other errors are fatal. |
| 765 | */ |
| 766 | struct drm_connector_state * |
| 767 | drm_atomic_get_connector_state(struct drm_atomic_state *state, |
| 768 | struct drm_connector *connector) |
| 769 | { |
| 770 | int ret, index; |
| 771 | struct drm_mode_config *config = &connector->dev->mode_config; |
| 772 | struct drm_connector_state *connector_state; |
| 773 | |
Maarten Lankhorst | 7f4eaa89 | 2016-05-03 11:12:31 +0200 | [diff] [blame] | 774 | WARN_ON(!state->acquire_ctx); |
| 775 | |
Daniel Vetter | c7eb76f | 2014-11-19 18:38:06 +0100 | [diff] [blame] | 776 | ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx); |
| 777 | if (ret) |
| 778 | return ERR_PTR(ret); |
| 779 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 780 | index = drm_connector_index(connector); |
| 781 | |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 782 | if (index >= state->num_connector) { |
Daniel Vetter | 63e83c1 | 2016-06-02 00:06:32 +0200 | [diff] [blame] | 783 | struct __drm_connnectors_state *c; |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 784 | int alloc = max(index + 1, config->num_connector); |
| 785 | |
| 786 | c = krealloc(state->connectors, alloc * sizeof(*state->connectors), GFP_KERNEL); |
| 787 | if (!c) |
| 788 | return ERR_PTR(-ENOMEM); |
| 789 | |
| 790 | state->connectors = c; |
| 791 | memset(&state->connectors[state->num_connector], 0, |
| 792 | sizeof(*state->connectors) * (alloc - state->num_connector)); |
| 793 | |
Maarten Lankhorst | 5fff80b | 2016-02-17 08:32:05 +0100 | [diff] [blame] | 794 | state->num_connector = alloc; |
Daniel Vetter | f52b69f1 | 2014-11-19 18:38:08 +0100 | [diff] [blame] | 795 | } |
| 796 | |
Daniel Vetter | 63e83c1 | 2016-06-02 00:06:32 +0200 | [diff] [blame] | 797 | if (state->connectors[index].state) |
| 798 | return state->connectors[index].state; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 799 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 800 | connector_state = connector->funcs->atomic_duplicate_state(connector); |
| 801 | if (!connector_state) |
| 802 | return ERR_PTR(-ENOMEM); |
| 803 | |
Thierry Reding | ad09360 | 2017-02-28 15:46:39 +0100 | [diff] [blame] | 804 | drm_connector_get(connector); |
Daniel Vetter | 63e83c1 | 2016-06-02 00:06:32 +0200 | [diff] [blame] | 805 | state->connectors[index].state = connector_state; |
Maarten Lankhorst | 581e49f | 2017-01-16 10:37:38 +0100 | [diff] [blame] | 806 | state->connectors[index].old_state = connector->state; |
| 807 | state->connectors[index].new_state = connector_state; |
Daniel Vetter | 63e83c1 | 2016-06-02 00:06:32 +0200 | [diff] [blame] | 808 | state->connectors[index].ptr = connector; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 809 | connector_state->state = state; |
| 810 | |
Russell King | 6ac7c54 | 2017-02-13 12:27:03 +0000 | [diff] [blame] | 811 | DRM_DEBUG_ATOMIC("Added [CONNECTOR:%d:%s] %p state to %p\n", |
| 812 | connector->base.id, connector->name, |
| 813 | connector_state, state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 814 | |
| 815 | if (connector_state->crtc) { |
| 816 | struct drm_crtc_state *crtc_state; |
| 817 | |
| 818 | crtc_state = drm_atomic_get_crtc_state(state, |
| 819 | connector_state->crtc); |
| 820 | if (IS_ERR(crtc_state)) |
| 821 | return ERR_CAST(crtc_state); |
| 822 | } |
| 823 | |
| 824 | return connector_state; |
| 825 | } |
| 826 | EXPORT_SYMBOL(drm_atomic_get_connector_state); |
| 827 | |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 828 | static void drm_atomic_connector_print_state(struct drm_printer *p, |
| 829 | const struct drm_connector_state *state) |
| 830 | { |
| 831 | struct drm_connector *connector = state->connector; |
| 832 | |
| 833 | drm_printf(p, "connector[%u]: %s\n", connector->base.id, connector->name); |
| 834 | drm_printf(p, "\tcrtc=%s\n", state->crtc ? state->crtc->name : "(null)"); |
| 835 | |
Brian Starkey | 8cbc5ca | 2017-11-02 16:49:51 +0000 | [diff] [blame] | 836 | if (connector->connector_type == DRM_MODE_CONNECTOR_WRITEBACK) |
| 837 | if (state->writeback_job && state->writeback_job->fb) |
| 838 | drm_printf(p, "\tfb=%d\n", state->writeback_job->fb->base.id); |
| 839 | |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 840 | if (connector->funcs->atomic_print_state) |
| 841 | connector->funcs->atomic_print_state(p, state); |
| 842 | } |
| 843 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 844 | /** |
| 845 | * drm_atomic_add_affected_connectors - add connectors for crtc |
| 846 | * @state: atomic state |
| 847 | * @crtc: DRM crtc |
| 848 | * |
| 849 | * This function walks the current configuration and adds all connectors |
| 850 | * currently using @crtc to the atomic configuration @state. Note that this |
| 851 | * function must acquire the connection mutex. This can potentially cause |
| 852 | * unneeded seralization if the update is just for the planes on one crtc. Hence |
| 853 | * drivers and helpers should only call this when really needed (e.g. when a |
| 854 | * full modeset needs to happen due to some change). |
| 855 | * |
| 856 | * Returns: |
| 857 | * 0 on success or can fail with -EDEADLK or -ENOMEM. When the error is EDEADLK |
| 858 | * then the w/w mutex code has detected a deadlock and the entire atomic |
| 859 | * sequence must be restarted. All other errors are fatal. |
| 860 | */ |
| 861 | int |
| 862 | drm_atomic_add_affected_connectors(struct drm_atomic_state *state, |
| 863 | struct drm_crtc *crtc) |
| 864 | { |
| 865 | struct drm_mode_config *config = &state->dev->mode_config; |
| 866 | struct drm_connector *connector; |
| 867 | struct drm_connector_state *conn_state; |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 868 | struct drm_connector_list_iter conn_iter; |
Maarten Lankhorst | 5351bbd | 2017-01-16 10:37:39 +0100 | [diff] [blame] | 869 | struct drm_crtc_state *crtc_state; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 870 | int ret; |
| 871 | |
Maarten Lankhorst | 5351bbd | 2017-01-16 10:37:39 +0100 | [diff] [blame] | 872 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 873 | if (IS_ERR(crtc_state)) |
| 874 | return PTR_ERR(crtc_state); |
| 875 | |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 876 | ret = drm_modeset_lock(&config->connection_mutex, state->acquire_ctx); |
| 877 | if (ret) |
| 878 | return ret; |
| 879 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 880 | DRM_DEBUG_ATOMIC("Adding all current connectors for [CRTC:%d:%s] to %p\n", |
| 881 | crtc->base.id, crtc->name, state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 882 | |
| 883 | /* |
Maarten Lankhorst | 5351bbd | 2017-01-16 10:37:39 +0100 | [diff] [blame] | 884 | * Changed connectors are already in @state, so only need to look |
| 885 | * at the connector_mask in crtc_state. |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 886 | */ |
Thierry Reding | b982dab | 2017-02-28 15:46:43 +0100 | [diff] [blame] | 887 | drm_connector_list_iter_begin(state->dev, &conn_iter); |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 888 | drm_for_each_connector_iter(connector, &conn_iter) { |
Ville Syrjälä | 7370573 | 2018-06-26 22:47:10 +0300 | [diff] [blame] | 889 | if (!(crtc_state->connector_mask & drm_connector_mask(connector))) |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 890 | continue; |
| 891 | |
| 892 | conn_state = drm_atomic_get_connector_state(state, connector); |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 893 | if (IS_ERR(conn_state)) { |
Thierry Reding | b982dab | 2017-02-28 15:46:43 +0100 | [diff] [blame] | 894 | drm_connector_list_iter_end(&conn_iter); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 895 | return PTR_ERR(conn_state); |
Daniel Vetter | 613051d | 2016-12-14 00:08:06 +0100 | [diff] [blame] | 896 | } |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 897 | } |
Thierry Reding | b982dab | 2017-02-28 15:46:43 +0100 | [diff] [blame] | 898 | drm_connector_list_iter_end(&conn_iter); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | EXPORT_SYMBOL(drm_atomic_add_affected_connectors); |
| 903 | |
| 904 | /** |
Maarten Lankhorst | e01e9f7 | 2015-05-19 16:41:02 +0200 | [diff] [blame] | 905 | * drm_atomic_add_affected_planes - add planes for crtc |
| 906 | * @state: atomic state |
| 907 | * @crtc: DRM crtc |
| 908 | * |
| 909 | * This function walks the current configuration and adds all planes |
| 910 | * currently used by @crtc to the atomic configuration @state. This is useful |
| 911 | * when an atomic commit also needs to check all currently enabled plane on |
| 912 | * @crtc, e.g. when changing the mode. It's also useful when re-enabling a CRTC |
| 913 | * to avoid special code to force-enable all planes. |
| 914 | * |
| 915 | * Since acquiring a plane state will always also acquire the w/w mutex of the |
| 916 | * current CRTC for that plane (if there is any) adding all the plane states for |
| 917 | * a CRTC will not reduce parallism of atomic updates. |
| 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 |
| 925 | drm_atomic_add_affected_planes(struct drm_atomic_state *state, |
| 926 | struct drm_crtc *crtc) |
| 927 | { |
Ville Syrjälä | 534903d | 2018-11-01 20:46:44 +0200 | [diff] [blame] | 928 | const struct drm_crtc_state *old_crtc_state = |
| 929 | drm_atomic_get_old_crtc_state(state, crtc); |
Maarten Lankhorst | e01e9f7 | 2015-05-19 16:41:02 +0200 | [diff] [blame] | 930 | struct drm_plane *plane; |
| 931 | |
Maarten Lankhorst | b4d9367 | 2017-03-01 10:22:10 +0100 | [diff] [blame] | 932 | WARN_ON(!drm_atomic_get_new_crtc_state(state, crtc)); |
Maarten Lankhorst | e01e9f7 | 2015-05-19 16:41:02 +0200 | [diff] [blame] | 933 | |
Ville Syrjälä | b6f690a | 2018-06-11 22:34:01 +0300 | [diff] [blame] | 934 | DRM_DEBUG_ATOMIC("Adding all current planes for [CRTC:%d:%s] to %p\n", |
| 935 | crtc->base.id, crtc->name, state); |
| 936 | |
Ville Syrjälä | 534903d | 2018-11-01 20:46:44 +0200 | [diff] [blame] | 937 | drm_for_each_plane_mask(plane, state->dev, old_crtc_state->plane_mask) { |
Maarten Lankhorst | e01e9f7 | 2015-05-19 16:41:02 +0200 | [diff] [blame] | 938 | struct drm_plane_state *plane_state = |
| 939 | drm_atomic_get_plane_state(state, plane); |
| 940 | |
| 941 | if (IS_ERR(plane_state)) |
| 942 | return PTR_ERR(plane_state); |
| 943 | } |
| 944 | return 0; |
| 945 | } |
| 946 | EXPORT_SYMBOL(drm_atomic_add_affected_planes); |
| 947 | |
| 948 | /** |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 949 | * drm_atomic_check_only - check whether a given config would work |
| 950 | * @state: atomic configuration to check |
| 951 | * |
| 952 | * Note that this function can return -EDEADLK if the driver needed to acquire |
| 953 | * more locks but encountered a deadlock. The caller must then do the usual w/w |
| 954 | * backoff dance and restart. All other errors are fatal. |
| 955 | * |
| 956 | * Returns: |
| 957 | * 0 on success, negative error code on failure. |
| 958 | */ |
| 959 | int drm_atomic_check_only(struct drm_atomic_state *state) |
| 960 | { |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 961 | struct drm_device *dev = state->dev; |
| 962 | struct drm_mode_config *config = &dev->mode_config; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 963 | struct drm_plane *plane; |
| 964 | struct drm_plane_state *plane_state; |
| 965 | struct drm_crtc *crtc; |
Ville Syrjälä | b2432ad | 2018-11-01 20:46:45 +0200 | [diff] [blame^] | 966 | struct drm_crtc_state *old_crtc_state; |
| 967 | struct drm_crtc_state *new_crtc_state; |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 968 | struct drm_connector *conn; |
| 969 | struct drm_connector_state *conn_state; |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 970 | int i, ret = 0; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 971 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 972 | DRM_DEBUG_ATOMIC("checking %p\n", state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 973 | |
Maarten Lankhorst | 5721a38 | 2017-01-16 10:37:40 +0100 | [diff] [blame] | 974 | for_each_new_plane_in_state(state, plane, plane_state, i) { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 975 | ret = drm_atomic_plane_check(plane, plane_state); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 976 | if (ret) { |
Ville Syrjälä | 9f4c97a | 2015-12-08 18:41:54 +0200 | [diff] [blame] | 977 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] atomic core check failed\n", |
| 978 | plane->base.id, plane->name); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 979 | return ret; |
| 980 | } |
| 981 | } |
| 982 | |
Ville Syrjälä | b2432ad | 2018-11-01 20:46:45 +0200 | [diff] [blame^] | 983 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
| 984 | ret = drm_atomic_crtc_check(old_crtc_state, new_crtc_state); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 985 | if (ret) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 986 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic core check failed\n", |
| 987 | crtc->base.id, crtc->name); |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 988 | return ret; |
| 989 | } |
| 990 | } |
| 991 | |
Brian Starkey | 935774c | 2017-03-29 17:42:32 +0100 | [diff] [blame] | 992 | for_each_new_connector_in_state(state, conn, conn_state, i) { |
| 993 | ret = drm_atomic_connector_check(conn, conn_state); |
| 994 | if (ret) { |
| 995 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] atomic core check failed\n", |
| 996 | conn->base.id, conn->name); |
| 997 | return ret; |
| 998 | } |
| 999 | } |
| 1000 | |
Lyude Paul | 14d4e52 | 2018-04-11 19:42:40 -0400 | [diff] [blame] | 1001 | if (config->funcs->atomic_check) { |
Rob Clark | 5e74373 | 2014-12-18 16:01:51 -0500 | [diff] [blame] | 1002 | ret = config->funcs->atomic_check(state->dev, state); |
| 1003 | |
Lyude Paul | 14d4e52 | 2018-04-11 19:42:40 -0400 | [diff] [blame] | 1004 | if (ret) { |
| 1005 | DRM_DEBUG_ATOMIC("atomic driver check for %p failed: %d\n", |
| 1006 | state, ret); |
| 1007 | return ret; |
| 1008 | } |
| 1009 | } |
Maarten Lankhorst | a0ffc51 | 2017-08-15 11:57:06 +0200 | [diff] [blame] | 1010 | |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 1011 | if (!state->allow_modeset) { |
Ville Syrjälä | b2432ad | 2018-11-01 20:46:45 +0200 | [diff] [blame^] | 1012 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 1013 | if (drm_atomic_crtc_needs_modeset(new_crtc_state)) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 1014 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] requires full modeset\n", |
| 1015 | crtc->base.id, crtc->name); |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 1016 | return -EINVAL; |
| 1017 | } |
| 1018 | } |
| 1019 | } |
| 1020 | |
Maarten Lankhorst | a0ffc51 | 2017-08-15 11:57:06 +0200 | [diff] [blame] | 1021 | return 0; |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1022 | } |
| 1023 | EXPORT_SYMBOL(drm_atomic_check_only); |
| 1024 | |
| 1025 | /** |
| 1026 | * drm_atomic_commit - commit configuration atomically |
| 1027 | * @state: atomic configuration to check |
| 1028 | * |
| 1029 | * Note that this function can return -EDEADLK if the driver needed to acquire |
| 1030 | * more locks but encountered a deadlock. The caller must then do the usual w/w |
| 1031 | * backoff dance and restart. All other errors are fatal. |
| 1032 | * |
Maarten Lankhorst | 76fede2 | 2017-01-04 12:34:00 +0100 | [diff] [blame] | 1033 | * This function will take its own reference on @state. |
| 1034 | * Callers should always release their reference with drm_atomic_state_put(). |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1035 | * |
| 1036 | * Returns: |
| 1037 | * 0 on success, negative error code on failure. |
| 1038 | */ |
| 1039 | int drm_atomic_commit(struct drm_atomic_state *state) |
| 1040 | { |
| 1041 | struct drm_mode_config *config = &state->dev->mode_config; |
| 1042 | int ret; |
| 1043 | |
| 1044 | ret = drm_atomic_check_only(state); |
| 1045 | if (ret) |
| 1046 | return ret; |
| 1047 | |
Colin Ian King | a0752d4 | 2017-04-12 17:27:22 +0100 | [diff] [blame] | 1048 | DRM_DEBUG_ATOMIC("committing %p\n", state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1049 | |
| 1050 | return config->funcs->atomic_commit(state->dev, state, false); |
| 1051 | } |
| 1052 | EXPORT_SYMBOL(drm_atomic_commit); |
| 1053 | |
| 1054 | /** |
Daniel Vetter | d574528 | 2017-01-25 07:26:45 +0100 | [diff] [blame] | 1055 | * drm_atomic_nonblocking_commit - atomic nonblocking commit |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1056 | * @state: atomic configuration to check |
| 1057 | * |
| 1058 | * Note that this function can return -EDEADLK if the driver needed to acquire |
| 1059 | * more locks but encountered a deadlock. The caller must then do the usual w/w |
| 1060 | * backoff dance and restart. All other errors are fatal. |
| 1061 | * |
Maarten Lankhorst | 76fede2 | 2017-01-04 12:34:00 +0100 | [diff] [blame] | 1062 | * This function will take its own reference on @state. |
| 1063 | * Callers should always release their reference with drm_atomic_state_put(). |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1064 | * |
| 1065 | * Returns: |
| 1066 | * 0 on success, negative error code on failure. |
| 1067 | */ |
Maarten Lankhorst | b837ba0 | 2016-04-26 16:11:35 +0200 | [diff] [blame] | 1068 | int drm_atomic_nonblocking_commit(struct drm_atomic_state *state) |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1069 | { |
| 1070 | struct drm_mode_config *config = &state->dev->mode_config; |
| 1071 | int ret; |
| 1072 | |
| 1073 | ret = drm_atomic_check_only(state); |
| 1074 | if (ret) |
| 1075 | return ret; |
| 1076 | |
Colin Ian King | a0752d4 | 2017-04-12 17:27:22 +0100 | [diff] [blame] | 1077 | DRM_DEBUG_ATOMIC("committing %p nonblocking\n", state); |
Daniel Vetter | cc4ceb4 | 2014-07-25 21:30:38 +0200 | [diff] [blame] | 1078 | |
| 1079 | return config->funcs->atomic_commit(state->dev, state, true); |
| 1080 | } |
Maarten Lankhorst | b837ba0 | 2016-04-26 16:11:35 +0200 | [diff] [blame] | 1081 | EXPORT_SYMBOL(drm_atomic_nonblocking_commit); |
Rob Clark | d34f20d | 2014-12-18 16:01:56 -0500 | [diff] [blame] | 1082 | |
Daniel Vetter | 72fdb40c | 2018-09-05 15:57:11 +0200 | [diff] [blame] | 1083 | void drm_atomic_print_state(const struct drm_atomic_state *state) |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 1084 | { |
| 1085 | struct drm_printer p = drm_info_printer(state->dev->dev); |
| 1086 | struct drm_plane *plane; |
| 1087 | struct drm_plane_state *plane_state; |
| 1088 | struct drm_crtc *crtc; |
| 1089 | struct drm_crtc_state *crtc_state; |
| 1090 | struct drm_connector *connector; |
| 1091 | struct drm_connector_state *connector_state; |
| 1092 | int i; |
| 1093 | |
| 1094 | DRM_DEBUG_ATOMIC("checking %p\n", state); |
| 1095 | |
Maarten Lankhorst | 5721a38 | 2017-01-16 10:37:40 +0100 | [diff] [blame] | 1096 | for_each_new_plane_in_state(state, plane, plane_state, i) |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 1097 | drm_atomic_plane_print_state(&p, plane_state); |
| 1098 | |
Maarten Lankhorst | 5721a38 | 2017-01-16 10:37:40 +0100 | [diff] [blame] | 1099 | for_each_new_crtc_in_state(state, crtc, crtc_state, i) |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 1100 | drm_atomic_crtc_print_state(&p, crtc_state); |
| 1101 | |
Maarten Lankhorst | 5721a38 | 2017-01-16 10:37:40 +0100 | [diff] [blame] | 1102 | for_each_new_connector_in_state(state, connector, connector_state, i) |
Rob Clark | fceffb32 | 2016-11-05 11:08:09 -0400 | [diff] [blame] | 1103 | drm_atomic_connector_print_state(&p, connector_state); |
| 1104 | } |
| 1105 | |
Daniel Vetter | c2d8556 | 2017-04-03 10:32:54 +0200 | [diff] [blame] | 1106 | static void __drm_state_dump(struct drm_device *dev, struct drm_printer *p, |
| 1107 | bool take_locks) |
| 1108 | { |
| 1109 | struct drm_mode_config *config = &dev->mode_config; |
| 1110 | struct drm_plane *plane; |
| 1111 | struct drm_crtc *crtc; |
| 1112 | struct drm_connector *connector; |
| 1113 | struct drm_connector_list_iter conn_iter; |
| 1114 | |
Lyude Paul | 3c499ea | 2018-09-17 13:37:33 -0400 | [diff] [blame] | 1115 | if (!drm_drv_uses_atomic_modeset(dev)) |
Daniel Vetter | c2d8556 | 2017-04-03 10:32:54 +0200 | [diff] [blame] | 1116 | return; |
| 1117 | |
| 1118 | list_for_each_entry(plane, &config->plane_list, head) { |
| 1119 | if (take_locks) |
| 1120 | drm_modeset_lock(&plane->mutex, NULL); |
| 1121 | drm_atomic_plane_print_state(p, plane->state); |
| 1122 | if (take_locks) |
| 1123 | drm_modeset_unlock(&plane->mutex); |
| 1124 | } |
| 1125 | |
| 1126 | list_for_each_entry(crtc, &config->crtc_list, head) { |
| 1127 | if (take_locks) |
| 1128 | drm_modeset_lock(&crtc->mutex, NULL); |
| 1129 | drm_atomic_crtc_print_state(p, crtc->state); |
| 1130 | if (take_locks) |
| 1131 | drm_modeset_unlock(&crtc->mutex); |
| 1132 | } |
| 1133 | |
| 1134 | drm_connector_list_iter_begin(dev, &conn_iter); |
| 1135 | if (take_locks) |
| 1136 | drm_modeset_lock(&dev->mode_config.connection_mutex, NULL); |
| 1137 | drm_for_each_connector_iter(connector, &conn_iter) |
| 1138 | drm_atomic_connector_print_state(p, connector->state); |
| 1139 | if (take_locks) |
| 1140 | drm_modeset_unlock(&dev->mode_config.connection_mutex); |
| 1141 | drm_connector_list_iter_end(&conn_iter); |
| 1142 | } |
| 1143 | |
Rob Clark | 6559c90 | 2016-11-05 11:08:10 -0400 | [diff] [blame] | 1144 | /** |
| 1145 | * drm_state_dump - dump entire device atomic state |
| 1146 | * @dev: the drm device |
| 1147 | * @p: where to print the state to |
| 1148 | * |
| 1149 | * Just for debugging. Drivers might want an option to dump state |
| 1150 | * to dmesg in case of error irq's. (Hint, you probably want to |
| 1151 | * ratelimit this!) |
| 1152 | * |
| 1153 | * The caller must drm_modeset_lock_all(), or if this is called |
| 1154 | * from error irq handler, it should not be enabled by default. |
| 1155 | * (Ie. if you are debugging errors you might not care that this |
| 1156 | * is racey. But calling this without all modeset locks held is |
| 1157 | * not inherently safe.) |
| 1158 | */ |
| 1159 | void drm_state_dump(struct drm_device *dev, struct drm_printer *p) |
| 1160 | { |
Daniel Vetter | c2d8556 | 2017-04-03 10:32:54 +0200 | [diff] [blame] | 1161 | __drm_state_dump(dev, p, false); |
Rob Clark | 6559c90 | 2016-11-05 11:08:10 -0400 | [diff] [blame] | 1162 | } |
| 1163 | EXPORT_SYMBOL(drm_state_dump); |
| 1164 | |
| 1165 | #ifdef CONFIG_DEBUG_FS |
| 1166 | static int drm_state_info(struct seq_file *m, void *data) |
| 1167 | { |
| 1168 | struct drm_info_node *node = (struct drm_info_node *) m->private; |
| 1169 | struct drm_device *dev = node->minor->dev; |
| 1170 | struct drm_printer p = drm_seq_file_printer(m); |
| 1171 | |
Daniel Vetter | c2d8556 | 2017-04-03 10:32:54 +0200 | [diff] [blame] | 1172 | __drm_state_dump(dev, &p, true); |
Rob Clark | 6559c90 | 2016-11-05 11:08:10 -0400 | [diff] [blame] | 1173 | |
| 1174 | return 0; |
| 1175 | } |
| 1176 | |
| 1177 | /* any use in debugfs files to dump individual planes/crtc/etc? */ |
| 1178 | static const struct drm_info_list drm_atomic_debugfs_list[] = { |
| 1179 | {"state", drm_state_info, 0}, |
| 1180 | }; |
| 1181 | |
| 1182 | int drm_atomic_debugfs_init(struct drm_minor *minor) |
| 1183 | { |
| 1184 | return drm_debugfs_create_files(drm_atomic_debugfs_list, |
| 1185 | ARRAY_SIZE(drm_atomic_debugfs_list), |
| 1186 | minor->debugfs_root, minor); |
| 1187 | } |
| 1188 | #endif |
| 1189 | |