Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 Red Hat |
| 3 | * Copyright (C) 2014 Intel Corp. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice shall be included in |
| 13 | * all copies or substantial portions of the Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 19 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 20 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 21 | * OTHER DEALINGS IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Rob Clark <robdclark@gmail.com> |
| 25 | * Daniel Vetter <daniel.vetter@ffwll.ch> |
| 26 | */ |
| 27 | |
| 28 | #include <drm/drmP.h> |
| 29 | #include <drm/drm_atomic.h> |
| 30 | #include <drm/drm_plane_helper.h> |
| 31 | #include <drm/drm_crtc_helper.h> |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 32 | #include <drm/drm_atomic_helper.h> |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 33 | #include <linux/dma-fence.h> |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 34 | |
Marek Szyprowski | 44d1240d | 2016-06-13 11:11:26 +0200 | [diff] [blame] | 35 | #include "drm_crtc_internal.h" |
| 36 | |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 37 | /** |
| 38 | * DOC: overview |
| 39 | * |
| 40 | * This helper library provides implementations of check and commit functions on |
| 41 | * top of the CRTC modeset helper callbacks and the plane helper callbacks. It |
| 42 | * also provides convenience implementations for the atomic state handling |
| 43 | * callbacks for drivers which don't need to subclass the drm core structures to |
| 44 | * add their own additional internal state. |
| 45 | * |
| 46 | * This library also provides default implementations for the check callback in |
Daniel Vetter | 26196f7 | 2015-08-25 16:26:03 +0200 | [diff] [blame] | 47 | * drm_atomic_helper_check() and for the commit callback with |
| 48 | * drm_atomic_helper_commit(). But the individual stages and callbacks are |
| 49 | * exposed to allow drivers to mix and match and e.g. use the plane helpers only |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 50 | * together with a driver private modeset implementation. |
| 51 | * |
| 52 | * This library also provides implementations for all the legacy driver |
Daniel Vetter | 26196f7 | 2015-08-25 16:26:03 +0200 | [diff] [blame] | 53 | * interfaces on top of the atomic interface. See drm_atomic_helper_set_config(), |
| 54 | * drm_atomic_helper_disable_plane(), drm_atomic_helper_disable_plane() and the |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 55 | * various functions to implement set_property callbacks. New drivers must not |
| 56 | * implement these functions themselves but must use the provided helpers. |
Daniel Vetter | 092d01d | 2015-12-04 09:45:44 +0100 | [diff] [blame] | 57 | * |
| 58 | * The atomic helper uses the same function table structures as all other |
| 59 | * modesetting helpers. See the documentation for struct &drm_crtc_helper_funcs, |
| 60 | * struct &drm_encoder_helper_funcs and struct &drm_connector_helper_funcs. It |
| 61 | * also shares the struct &drm_plane_helper_funcs function table with the plane |
| 62 | * helpers. |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 63 | */ |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 64 | static void |
| 65 | drm_atomic_helper_plane_changed(struct drm_atomic_state *state, |
| 66 | struct drm_plane_state *plane_state, |
| 67 | struct drm_plane *plane) |
| 68 | { |
| 69 | struct drm_crtc_state *crtc_state; |
| 70 | |
| 71 | if (plane->state->crtc) { |
Andrzej Hajda | 2943ef3 | 2016-03-15 13:46:00 +0100 | [diff] [blame] | 72 | crtc_state = drm_atomic_get_existing_crtc_state(state, |
| 73 | plane->state->crtc); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 74 | |
| 75 | if (WARN_ON(!crtc_state)) |
| 76 | return; |
| 77 | |
| 78 | crtc_state->planes_changed = true; |
| 79 | } |
| 80 | |
| 81 | if (plane_state->crtc) { |
Andrzej Hajda | 2943ef3 | 2016-03-15 13:46:00 +0100 | [diff] [blame] | 82 | crtc_state = drm_atomic_get_existing_crtc_state(state, |
| 83 | plane_state->crtc); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 84 | |
| 85 | if (WARN_ON(!crtc_state)) |
| 86 | return; |
| 87 | |
| 88 | crtc_state->planes_changed = true; |
| 89 | } |
| 90 | } |
| 91 | |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 92 | static int handle_conflicting_encoders(struct drm_atomic_state *state, |
| 93 | bool disable_conflicting_encoders) |
Daniel Vetter | 97ac320 | 2015-12-03 10:49:14 +0100 | [diff] [blame] | 94 | { |
Daniel Vetter | 97ac320 | 2015-12-03 10:49:14 +0100 | [diff] [blame] | 95 | struct drm_connector_state *conn_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 96 | struct drm_connector *connector; |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 97 | struct drm_connector_list_iter conn_iter; |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 98 | struct drm_encoder *encoder; |
| 99 | unsigned encoder_mask = 0; |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 100 | int i, ret = 0; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 101 | |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 102 | /* |
| 103 | * First loop, find all newly assigned encoders from the connectors |
| 104 | * part of the state. If the same encoder is assigned to multiple |
| 105 | * connectors bail out. |
| 106 | */ |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 107 | for_each_connector_in_state(state, connector, conn_state, i) { |
| 108 | const struct drm_connector_helper_funcs *funcs = connector->helper_private; |
| 109 | struct drm_encoder *new_encoder; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 110 | |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 111 | if (!conn_state->crtc) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 112 | continue; |
| 113 | |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 114 | if (funcs->atomic_best_encoder) |
| 115 | new_encoder = funcs->atomic_best_encoder(connector, conn_state); |
Boris Brezillon | a0909cc | 2016-06-01 18:03:37 +0200 | [diff] [blame] | 116 | else if (funcs->best_encoder) |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 117 | new_encoder = funcs->best_encoder(connector); |
Boris Brezillon | a0909cc | 2016-06-01 18:03:37 +0200 | [diff] [blame] | 118 | else |
| 119 | new_encoder = drm_atomic_helper_best_encoder(connector); |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 120 | |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 121 | if (new_encoder) { |
| 122 | if (encoder_mask & (1 << drm_encoder_index(new_encoder))) { |
| 123 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] on [CONNECTOR:%d:%s] already assigned\n", |
| 124 | new_encoder->base.id, new_encoder->name, |
| 125 | connector->base.id, connector->name); |
| 126 | |
| 127 | return -EINVAL; |
| 128 | } |
| 129 | |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 130 | encoder_mask |= 1 << drm_encoder_index(new_encoder); |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 131 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 132 | } |
| 133 | |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 134 | if (!encoder_mask) |
| 135 | return 0; |
| 136 | |
| 137 | /* |
| 138 | * Second loop, iterate over all connectors not part of the state. |
| 139 | * |
| 140 | * If a conflicting encoder is found and disable_conflicting_encoders |
| 141 | * is not set, an error is returned. Userspace can provide a solution |
| 142 | * through the atomic ioctl. |
| 143 | * |
| 144 | * If the flag is set conflicting connectors are removed from the crtc |
| 145 | * and the crtc is disabled if no encoder is left. This preserves |
| 146 | * compatibility with the legacy set_config behavior. |
| 147 | */ |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 148 | drm_connector_list_iter_get(state->dev, &conn_iter); |
| 149 | drm_for_each_connector_iter(connector, &conn_iter) { |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 150 | struct drm_crtc_state *crtc_state; |
| 151 | |
| 152 | if (drm_atomic_get_existing_connector_state(state, connector)) |
| 153 | continue; |
| 154 | |
| 155 | encoder = connector->state->best_encoder; |
| 156 | if (!encoder || !(encoder_mask & (1 << drm_encoder_index(encoder)))) |
| 157 | continue; |
| 158 | |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 159 | if (!disable_conflicting_encoders) { |
| 160 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s] by [CONNECTOR:%d:%s]\n", |
| 161 | encoder->base.id, encoder->name, |
| 162 | connector->state->crtc->base.id, |
| 163 | connector->state->crtc->name, |
| 164 | connector->base.id, connector->name); |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 165 | ret = -EINVAL; |
| 166 | goto out; |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 167 | } |
| 168 | |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 169 | conn_state = drm_atomic_get_connector_state(state, connector); |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 170 | if (IS_ERR(conn_state)) { |
| 171 | ret = PTR_ERR(conn_state); |
| 172 | goto out; |
| 173 | } |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 174 | |
| 175 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s], disabling [CONNECTOR:%d:%s]\n", |
| 176 | encoder->base.id, encoder->name, |
| 177 | conn_state->crtc->base.id, conn_state->crtc->name, |
| 178 | connector->base.id, connector->name); |
| 179 | |
| 180 | crtc_state = drm_atomic_get_existing_crtc_state(state, conn_state->crtc); |
| 181 | |
| 182 | ret = drm_atomic_set_crtc_for_connector(conn_state, NULL); |
| 183 | if (ret) |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 184 | goto out; |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 185 | |
| 186 | if (!crtc_state->connector_mask) { |
| 187 | ret = drm_atomic_set_mode_prop_for_crtc(crtc_state, |
| 188 | NULL); |
| 189 | if (ret < 0) |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 190 | goto out; |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 191 | |
| 192 | crtc_state->active = false; |
| 193 | } |
| 194 | } |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 195 | out: |
| 196 | drm_connector_list_iter_put(&conn_iter); |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 197 | |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 198 | return ret; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 199 | } |
| 200 | |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 201 | static void |
| 202 | set_best_encoder(struct drm_atomic_state *state, |
| 203 | struct drm_connector_state *conn_state, |
| 204 | struct drm_encoder *encoder) |
| 205 | { |
| 206 | struct drm_crtc_state *crtc_state; |
| 207 | struct drm_crtc *crtc; |
| 208 | |
| 209 | if (conn_state->best_encoder) { |
| 210 | /* Unset the encoder_mask in the old crtc state. */ |
| 211 | crtc = conn_state->connector->state->crtc; |
| 212 | |
| 213 | /* A NULL crtc is an error here because we should have |
| 214 | * duplicated a NULL best_encoder when crtc was NULL. |
| 215 | * As an exception restoring duplicated atomic state |
| 216 | * during resume is allowed, so don't warn when |
| 217 | * best_encoder is equal to encoder we intend to set. |
| 218 | */ |
| 219 | WARN_ON(!crtc && encoder != conn_state->best_encoder); |
| 220 | if (crtc) { |
| 221 | crtc_state = drm_atomic_get_existing_crtc_state(state, crtc); |
| 222 | |
| 223 | crtc_state->encoder_mask &= |
| 224 | ~(1 << drm_encoder_index(conn_state->best_encoder)); |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | if (encoder) { |
| 229 | crtc = conn_state->crtc; |
| 230 | WARN_ON(!crtc); |
| 231 | if (crtc) { |
| 232 | crtc_state = drm_atomic_get_existing_crtc_state(state, crtc); |
| 233 | |
| 234 | crtc_state->encoder_mask |= |
| 235 | 1 << drm_encoder_index(encoder); |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | conn_state->best_encoder = encoder; |
| 240 | } |
| 241 | |
Maarten Lankhorst | ec5aaa5 | 2016-03-03 10:17:41 +0100 | [diff] [blame] | 242 | static void |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 243 | steal_encoder(struct drm_atomic_state *state, |
Maarten Lankhorst | ff19b78 | 2016-03-03 10:17:38 +0100 | [diff] [blame] | 244 | struct drm_encoder *encoder) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 245 | { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 246 | struct drm_crtc_state *crtc_state; |
| 247 | struct drm_connector *connector; |
| 248 | struct drm_connector_state *connector_state; |
Maarten Lankhorst | ec5aaa5 | 2016-03-03 10:17:41 +0100 | [diff] [blame] | 249 | int i; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 250 | |
Maarten Lankhorst | ec5aaa5 | 2016-03-03 10:17:41 +0100 | [diff] [blame] | 251 | for_each_connector_in_state(state, connector, connector_state, i) { |
Maarten Lankhorst | ff19b78 | 2016-03-03 10:17:38 +0100 | [diff] [blame] | 252 | struct drm_crtc *encoder_crtc; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 253 | |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 254 | if (connector_state->best_encoder != encoder) |
| 255 | continue; |
| 256 | |
Maarten Lankhorst | ff19b78 | 2016-03-03 10:17:38 +0100 | [diff] [blame] | 257 | encoder_crtc = connector->state->crtc; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 258 | |
Maarten Lankhorst | ff19b78 | 2016-03-03 10:17:38 +0100 | [diff] [blame] | 259 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] in use on [CRTC:%d:%s], stealing it\n", |
| 260 | encoder->base.id, encoder->name, |
| 261 | encoder_crtc->base.id, encoder_crtc->name); |
| 262 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 263 | set_best_encoder(state, connector_state, NULL); |
Maarten Lankhorst | ff19b78 | 2016-03-03 10:17:38 +0100 | [diff] [blame] | 264 | |
| 265 | crtc_state = drm_atomic_get_existing_crtc_state(state, encoder_crtc); |
| 266 | crtc_state->connectors_changed = true; |
| 267 | |
Maarten Lankhorst | ec5aaa5 | 2016-03-03 10:17:41 +0100 | [diff] [blame] | 268 | return; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 269 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | static int |
Maarten Lankhorst | 9459545 | 2016-02-24 09:37:29 +0100 | [diff] [blame] | 273 | update_connector_routing(struct drm_atomic_state *state, |
| 274 | struct drm_connector *connector, |
| 275 | struct drm_connector_state *connector_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 276 | { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 277 | const struct drm_connector_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 278 | struct drm_encoder *new_encoder; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 279 | struct drm_crtc_state *crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 280 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 281 | DRM_DEBUG_ATOMIC("Updating routing for [CONNECTOR:%d:%s]\n", |
| 282 | connector->base.id, |
| 283 | connector->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 284 | |
| 285 | if (connector->state->crtc != connector_state->crtc) { |
| 286 | if (connector->state->crtc) { |
Maarten Lankhorst | 9b8d1e5 | 2016-03-03 10:17:42 +0100 | [diff] [blame] | 287 | crtc_state = drm_atomic_get_existing_crtc_state(state, connector->state->crtc); |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 288 | crtc_state->connectors_changed = true; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | if (connector_state->crtc) { |
Maarten Lankhorst | 9b8d1e5 | 2016-03-03 10:17:42 +0100 | [diff] [blame] | 292 | crtc_state = drm_atomic_get_existing_crtc_state(state, connector_state->crtc); |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 293 | crtc_state->connectors_changed = true; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 294 | } |
| 295 | } |
| 296 | |
| 297 | if (!connector_state->crtc) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 298 | DRM_DEBUG_ATOMIC("Disabling [CONNECTOR:%d:%s]\n", |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 299 | connector->base.id, |
| 300 | connector->name); |
| 301 | |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 302 | set_best_encoder(state, connector_state, NULL); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 303 | |
| 304 | return 0; |
| 305 | } |
| 306 | |
| 307 | funcs = connector->helper_private; |
Daniel Vetter | 3b8a684 | 2015-08-03 17:24:08 +0200 | [diff] [blame] | 308 | |
| 309 | if (funcs->atomic_best_encoder) |
| 310 | new_encoder = funcs->atomic_best_encoder(connector, |
| 311 | connector_state); |
Boris Brezillon | c61b93fe | 2016-06-07 13:47:56 +0200 | [diff] [blame] | 312 | else if (funcs->best_encoder) |
Daniel Vetter | 3b8a684 | 2015-08-03 17:24:08 +0200 | [diff] [blame] | 313 | new_encoder = funcs->best_encoder(connector); |
Boris Brezillon | c61b93fe | 2016-06-07 13:47:56 +0200 | [diff] [blame] | 314 | else |
| 315 | new_encoder = drm_atomic_helper_best_encoder(connector); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 316 | |
| 317 | if (!new_encoder) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 318 | DRM_DEBUG_ATOMIC("No suitable encoder found for [CONNECTOR:%d:%s]\n", |
| 319 | connector->base.id, |
| 320 | connector->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 321 | return -EINVAL; |
| 322 | } |
| 323 | |
Daniel Vetter | 5481c8f | 2015-11-18 18:46:48 +0100 | [diff] [blame] | 324 | if (!drm_encoder_crtc_ok(new_encoder, connector_state->crtc)) { |
| 325 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] incompatible with [CRTC:%d]\n", |
| 326 | new_encoder->base.id, |
| 327 | new_encoder->name, |
| 328 | connector_state->crtc->base.id); |
| 329 | return -EINVAL; |
| 330 | } |
| 331 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 332 | if (new_encoder == connector_state->best_encoder) { |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 333 | set_best_encoder(state, connector_state, new_encoder); |
| 334 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 335 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] keeps [ENCODER:%d:%s], now on [CRTC:%d:%s]\n", |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 336 | connector->base.id, |
| 337 | connector->name, |
| 338 | new_encoder->base.id, |
| 339 | new_encoder->name, |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 340 | connector_state->crtc->base.id, |
| 341 | connector_state->crtc->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 342 | |
| 343 | return 0; |
| 344 | } |
| 345 | |
Maarten Lankhorst | ec5aaa5 | 2016-03-03 10:17:41 +0100 | [diff] [blame] | 346 | steal_encoder(state, new_encoder); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 347 | |
Maarten Lankhorst | e87a52b | 2016-01-28 15:04:58 +0100 | [diff] [blame] | 348 | set_best_encoder(state, connector_state, new_encoder); |
| 349 | |
Maarten Lankhorst | 9b8d1e5 | 2016-03-03 10:17:42 +0100 | [diff] [blame] | 350 | crtc_state = drm_atomic_get_existing_crtc_state(state, connector_state->crtc); |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 351 | crtc_state->connectors_changed = true; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 352 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 353 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] using [ENCODER:%d:%s] on [CRTC:%d:%s]\n", |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 354 | connector->base.id, |
| 355 | connector->name, |
| 356 | new_encoder->base.id, |
| 357 | new_encoder->name, |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 358 | connector_state->crtc->base.id, |
| 359 | connector_state->crtc->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | |
| 364 | static int |
| 365 | mode_fixup(struct drm_atomic_state *state) |
| 366 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 367 | struct drm_crtc *crtc; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 368 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 369 | struct drm_connector *connector; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 370 | struct drm_connector_state *conn_state; |
| 371 | int i; |
| 372 | bool ret; |
| 373 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 374 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 375 | if (!crtc_state->mode_changed && |
| 376 | !crtc_state->connectors_changed) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 377 | continue; |
| 378 | |
| 379 | drm_mode_copy(&crtc_state->adjusted_mode, &crtc_state->mode); |
| 380 | } |
| 381 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 382 | for_each_connector_in_state(state, connector, conn_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 383 | const struct drm_encoder_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 384 | struct drm_encoder *encoder; |
| 385 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 386 | WARN_ON(!!conn_state->best_encoder != !!conn_state->crtc); |
| 387 | |
| 388 | if (!conn_state->crtc || !conn_state->best_encoder) |
| 389 | continue; |
| 390 | |
Andrzej Hajda | 2943ef3 | 2016-03-15 13:46:00 +0100 | [diff] [blame] | 391 | crtc_state = drm_atomic_get_existing_crtc_state(state, |
| 392 | conn_state->crtc); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 393 | |
| 394 | /* |
| 395 | * Each encoder has at most one connector (since we always steal |
| 396 | * it away), so we won't call ->mode_fixup twice. |
| 397 | */ |
| 398 | encoder = conn_state->best_encoder; |
| 399 | funcs = encoder->helper_private; |
| 400 | |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 401 | ret = drm_bridge_mode_fixup(encoder->bridge, &crtc_state->mode, |
| 402 | &crtc_state->adjusted_mode); |
| 403 | if (!ret) { |
| 404 | DRM_DEBUG_ATOMIC("Bridge fixup failed\n"); |
| 405 | return -EINVAL; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 406 | } |
| 407 | |
Noralf Trønnes | 2827635 | 2016-05-11 18:09:20 +0200 | [diff] [blame] | 408 | if (funcs && funcs->atomic_check) { |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 409 | ret = funcs->atomic_check(encoder, crtc_state, |
| 410 | conn_state); |
| 411 | if (ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 412 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] check failed\n", |
| 413 | encoder->base.id, encoder->name); |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 414 | return ret; |
| 415 | } |
Noralf Trønnes | 2827635 | 2016-05-11 18:09:20 +0200 | [diff] [blame] | 416 | } else if (funcs && funcs->mode_fixup) { |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 417 | ret = funcs->mode_fixup(encoder, &crtc_state->mode, |
| 418 | &crtc_state->adjusted_mode); |
| 419 | if (!ret) { |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 420 | DRM_DEBUG_ATOMIC("[ENCODER:%d:%s] fixup failed\n", |
| 421 | encoder->base.id, encoder->name); |
Thierry Reding | 4cd4df8 | 2014-12-03 16:44:34 +0100 | [diff] [blame] | 422 | return -EINVAL; |
| 423 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 424 | } |
| 425 | } |
| 426 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 427 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 428 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 429 | |
Liu Ying | f55f170 | 2016-05-27 17:35:54 +0800 | [diff] [blame] | 430 | if (!crtc_state->enable) |
| 431 | continue; |
| 432 | |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 433 | if (!crtc_state->mode_changed && |
| 434 | !crtc_state->connectors_changed) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 435 | continue; |
| 436 | |
| 437 | funcs = crtc->helper_private; |
Ander Conselvan de Oliveira | 840bfe9 | 2015-04-21 17:13:18 +0300 | [diff] [blame] | 438 | if (!funcs->mode_fixup) |
| 439 | continue; |
| 440 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 441 | ret = funcs->mode_fixup(crtc, &crtc_state->mode, |
| 442 | &crtc_state->adjusted_mode); |
| 443 | if (!ret) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 444 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] fixup failed\n", |
| 445 | crtc->base.id, crtc->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 446 | return -EINVAL; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | return 0; |
| 451 | } |
| 452 | |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 453 | /** |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 454 | * drm_atomic_helper_check_modeset - validate state object for modeset changes |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 455 | * @dev: DRM device |
| 456 | * @state: the driver state object |
| 457 | * |
| 458 | * Check the state object to see if the requested state is physically possible. |
| 459 | * This does all the crtc and connector related computations for an atomic |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 460 | * update and adds any additional connectors needed for full modesets and calls |
| 461 | * down into ->mode_fixup functions of the driver backend. |
| 462 | * |
| 463 | * crtc_state->mode_changed is set when the input mode is changed. |
| 464 | * crtc_state->connectors_changed is set when a connector is added or |
| 465 | * removed from the crtc. |
| 466 | * crtc_state->active_changed is set when crtc_state->active changes, |
| 467 | * which is used for dpms. |
Brian Starkey | d807ed1 | 2016-10-13 10:47:08 +0100 | [diff] [blame] | 468 | * See also: drm_atomic_crtc_needs_modeset() |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 469 | * |
| 470 | * IMPORTANT: |
| 471 | * |
Brian Starkey | d807ed1 | 2016-10-13 10:47:08 +0100 | [diff] [blame] | 472 | * Drivers which set ->mode_changed (e.g. in their ->atomic_check hooks if a |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 473 | * plane update can't be done without a full modeset) _must_ call this function |
| 474 | * afterwards after that change. It is permitted to call this function multiple |
| 475 | * times for the same update, e.g. when the ->atomic_check functions depend upon |
| 476 | * the adjusted dotclock for fifo space allocation and watermark computation. |
| 477 | * |
Daniel Vetter | c39032a | 2016-06-08 14:19:19 +0200 | [diff] [blame] | 478 | * RETURNS: |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 479 | * Zero for success or -errno |
| 480 | */ |
| 481 | int |
Rob Clark | 934ce1c | 2014-11-19 16:41:33 -0500 | [diff] [blame] | 482 | drm_atomic_helper_check_modeset(struct drm_device *dev, |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 483 | struct drm_atomic_state *state) |
| 484 | { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 485 | struct drm_crtc *crtc; |
| 486 | struct drm_crtc_state *crtc_state; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 487 | struct drm_connector *connector; |
| 488 | struct drm_connector_state *connector_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 489 | int i, ret; |
| 490 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 491 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 492 | if (!drm_mode_equal(&crtc->state->mode, &crtc_state->mode)) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 493 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] mode changed\n", |
| 494 | crtc->base.id, crtc->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 495 | crtc_state->mode_changed = true; |
| 496 | } |
| 497 | |
| 498 | if (crtc->state->enable != crtc_state->enable) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 499 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enable changed\n", |
| 500 | crtc->base.id, crtc->name); |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 501 | |
| 502 | /* |
| 503 | * For clarity this assignment is done here, but |
| 504 | * enable == 0 is only true when there are no |
| 505 | * connectors and a NULL mode. |
| 506 | * |
| 507 | * The other way around is true as well. enable != 0 |
| 508 | * iff connectors are attached and a mode is set. |
| 509 | */ |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 510 | crtc_state->mode_changed = true; |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 511 | crtc_state->connectors_changed = true; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
Maarten Lankhorst | 8248b65 | 2016-03-03 10:17:40 +0100 | [diff] [blame] | 515 | ret = handle_conflicting_encoders(state, state->legacy_set_config); |
| 516 | if (ret) |
| 517 | return ret; |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 518 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 519 | for_each_connector_in_state(state, connector, connector_state, i) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 520 | /* |
Brian Starkey | d807ed1 | 2016-10-13 10:47:08 +0100 | [diff] [blame] | 521 | * This only sets crtc->connectors_changed for routing changes, |
| 522 | * drivers must set crtc->connectors_changed themselves when |
| 523 | * connector properties need to be updated. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 524 | */ |
Maarten Lankhorst | 9459545 | 2016-02-24 09:37:29 +0100 | [diff] [blame] | 525 | ret = update_connector_routing(state, connector, |
| 526 | connector_state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 527 | if (ret) |
| 528 | return ret; |
| 529 | } |
| 530 | |
| 531 | /* |
| 532 | * After all the routing has been prepared we need to add in any |
| 533 | * connector which is itself unchanged, but who's crtc changes it's |
| 534 | * configuration. This must be done before calling mode_fixup in case a |
| 535 | * crtc only changed its mode but has the same set of connectors. |
| 536 | */ |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 537 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Maarten Lankhorst | 14de6c4 | 2016-01-04 12:53:20 +0100 | [diff] [blame] | 538 | bool has_connectors = |
| 539 | !!crtc_state->connector_mask; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 540 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 541 | /* |
| 542 | * We must set ->active_changed after walking connectors for |
| 543 | * otherwise an update that only changes active would result in |
| 544 | * a full modeset because update_connector_routing force that. |
| 545 | */ |
| 546 | if (crtc->state->active != crtc_state->active) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 547 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] active changed\n", |
| 548 | crtc->base.id, crtc->name); |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 549 | crtc_state->active_changed = true; |
| 550 | } |
| 551 | |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 552 | if (!drm_atomic_crtc_needs_modeset(crtc_state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 553 | continue; |
| 554 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 555 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] needs all connectors, enable: %c, active: %c\n", |
| 556 | crtc->base.id, crtc->name, |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 557 | crtc_state->enable ? 'y' : 'n', |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 558 | crtc_state->active ? 'y' : 'n'); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 559 | |
| 560 | ret = drm_atomic_add_affected_connectors(state, crtc); |
| 561 | if (ret != 0) |
| 562 | return ret; |
| 563 | |
Maarten Lankhorst | 57744aa | 2015-05-19 16:41:03 +0200 | [diff] [blame] | 564 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 565 | if (ret != 0) |
| 566 | return ret; |
| 567 | |
Maarten Lankhorst | 14de6c4 | 2016-01-04 12:53:20 +0100 | [diff] [blame] | 568 | if (crtc_state->enable != has_connectors) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 569 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] enabled/connectors mismatch\n", |
| 570 | crtc->base.id, crtc->name); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 571 | |
| 572 | return -EINVAL; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | return mode_fixup(state); |
| 577 | } |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 578 | EXPORT_SYMBOL(drm_atomic_helper_check_modeset); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 579 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 580 | /** |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 581 | * drm_atomic_helper_check_planes - validate state object for planes changes |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 582 | * @dev: DRM device |
| 583 | * @state: the driver state object |
| 584 | * |
| 585 | * Check the state object to see if the requested state is physically possible. |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 586 | * This does all the plane update related checks using by calling into the |
| 587 | * ->atomic_check hooks provided by the driver. |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 588 | * |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 589 | * It also sets crtc_state->planes_changed to indicate that a crtc has |
| 590 | * updated planes. |
| 591 | * |
Daniel Vetter | c39032a | 2016-06-08 14:19:19 +0200 | [diff] [blame] | 592 | * RETURNS: |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 593 | * Zero for success or -errno |
| 594 | */ |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 595 | int |
| 596 | drm_atomic_helper_check_planes(struct drm_device *dev, |
| 597 | struct drm_atomic_state *state) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 598 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 599 | struct drm_crtc *crtc; |
| 600 | struct drm_crtc_state *crtc_state; |
| 601 | struct drm_plane *plane; |
| 602 | struct drm_plane_state *plane_state; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 603 | int i, ret = 0; |
| 604 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 605 | for_each_plane_in_state(state, plane, plane_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 606 | const struct drm_plane_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 607 | |
| 608 | funcs = plane->helper_private; |
| 609 | |
| 610 | drm_atomic_helper_plane_changed(state, plane_state, plane); |
| 611 | |
| 612 | if (!funcs || !funcs->atomic_check) |
| 613 | continue; |
| 614 | |
| 615 | ret = funcs->atomic_check(plane, plane_state); |
| 616 | if (ret) { |
Ville Syrjälä | 9f4c97a | 2015-12-08 18:41:54 +0200 | [diff] [blame] | 617 | DRM_DEBUG_ATOMIC("[PLANE:%d:%s] atomic driver check failed\n", |
| 618 | plane->base.id, plane->name); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 619 | return ret; |
| 620 | } |
| 621 | } |
| 622 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 623 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 624 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 625 | |
| 626 | funcs = crtc->helper_private; |
| 627 | |
| 628 | if (!funcs || !funcs->atomic_check) |
| 629 | continue; |
| 630 | |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 631 | ret = funcs->atomic_check(crtc, crtc_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 632 | if (ret) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 633 | DRM_DEBUG_ATOMIC("[CRTC:%d:%s] atomic driver check failed\n", |
| 634 | crtc->base.id, crtc->name); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 635 | return ret; |
| 636 | } |
| 637 | } |
| 638 | |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 639 | return ret; |
| 640 | } |
| 641 | EXPORT_SYMBOL(drm_atomic_helper_check_planes); |
| 642 | |
| 643 | /** |
| 644 | * drm_atomic_helper_check - validate state object |
| 645 | * @dev: DRM device |
| 646 | * @state: the driver state object |
| 647 | * |
| 648 | * Check the state object to see if the requested state is physically possible. |
| 649 | * Only crtcs and planes have check callbacks, so for any additional (global) |
| 650 | * checking that a driver needs it can simply wrap that around this function. |
| 651 | * Drivers without such needs can directly use this as their ->atomic_check() |
| 652 | * callback. |
| 653 | * |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 654 | * This just wraps the two parts of the state checking for planes and modeset |
| 655 | * state in the default order: First it calls drm_atomic_helper_check_modeset() |
| 656 | * and then drm_atomic_helper_check_planes(). The assumption is that the |
| 657 | * ->atomic_check functions depend upon an updated adjusted_mode.clock to |
| 658 | * e.g. properly compute watermarks. |
| 659 | * |
Daniel Vetter | c39032a | 2016-06-08 14:19:19 +0200 | [diff] [blame] | 660 | * RETURNS: |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 661 | * Zero for success or -errno |
| 662 | */ |
| 663 | int drm_atomic_helper_check(struct drm_device *dev, |
| 664 | struct drm_atomic_state *state) |
| 665 | { |
| 666 | int ret; |
| 667 | |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 668 | ret = drm_atomic_helper_check_modeset(dev, state); |
Daniel Vetter | d9b1362 | 2014-11-26 16:57:41 +0100 | [diff] [blame] | 669 | if (ret) |
| 670 | return ret; |
| 671 | |
Daniel Vetter | b4274fb | 2014-11-26 17:02:18 +0100 | [diff] [blame] | 672 | ret = drm_atomic_helper_check_planes(dev, state); |
Rob Clark | 934ce1c | 2014-11-19 16:41:33 -0500 | [diff] [blame] | 673 | if (ret) |
| 674 | return ret; |
| 675 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 676 | return ret; |
| 677 | } |
| 678 | EXPORT_SYMBOL(drm_atomic_helper_check); |
| 679 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 680 | static void |
| 681 | disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state) |
| 682 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 683 | struct drm_connector *connector; |
| 684 | struct drm_connector_state *old_conn_state; |
| 685 | struct drm_crtc *crtc; |
| 686 | struct drm_crtc_state *old_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 687 | int i; |
| 688 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 689 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 690 | const struct drm_encoder_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 691 | struct drm_encoder *encoder; |
| 692 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 693 | /* Shut down everything that's in the changeset and currently |
| 694 | * still on. So need to check the old, saved state. */ |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 695 | if (!old_conn_state->crtc) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 696 | continue; |
| 697 | |
Andrzej Hajda | 2943ef3 | 2016-03-15 13:46:00 +0100 | [diff] [blame] | 698 | old_crtc_state = drm_atomic_get_existing_crtc_state(old_state, |
| 699 | old_conn_state->crtc); |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 700 | |
Daniel Vetter | 4218a32 | 2015-03-26 22:18:40 +0100 | [diff] [blame] | 701 | if (!old_crtc_state->active || |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 702 | !drm_atomic_crtc_needs_modeset(old_conn_state->crtc->state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 703 | continue; |
| 704 | |
Rob Clark | 46df9ad | 2014-11-20 15:40:36 -0500 | [diff] [blame] | 705 | encoder = old_conn_state->best_encoder; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 706 | |
Rob Clark | 46df9ad | 2014-11-20 15:40:36 -0500 | [diff] [blame] | 707 | /* We shouldn't get this far if we didn't previously have |
| 708 | * an encoder.. but WARN_ON() rather than explode. |
| 709 | */ |
| 710 | if (WARN_ON(!encoder)) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 711 | continue; |
| 712 | |
| 713 | funcs = encoder->helper_private; |
| 714 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 715 | DRM_DEBUG_ATOMIC("disabling [ENCODER:%d:%s]\n", |
| 716 | encoder->base.id, encoder->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 717 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 718 | /* |
| 719 | * Each encoder has at most one connector (since we always steal |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 720 | * it away), so we won't call disable hooks twice. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 721 | */ |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 722 | drm_bridge_disable(encoder->bridge); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 723 | |
| 724 | /* Right function depends upon target state. */ |
Noralf Trønnes | 2827635 | 2016-05-11 18:09:20 +0200 | [diff] [blame] | 725 | if (funcs) { |
| 726 | if (connector->state->crtc && funcs->prepare) |
| 727 | funcs->prepare(encoder); |
| 728 | else if (funcs->disable) |
| 729 | funcs->disable(encoder); |
| 730 | else if (funcs->dpms) |
| 731 | funcs->dpms(encoder, DRM_MODE_DPMS_OFF); |
| 732 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 733 | |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 734 | drm_bridge_post_disable(encoder->bridge); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 735 | } |
| 736 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 737 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 738 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 739 | |
| 740 | /* Shut down everything that needs a full modeset. */ |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 741 | if (!drm_atomic_crtc_needs_modeset(crtc->state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 742 | continue; |
| 743 | |
| 744 | if (!old_crtc_state->active) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 745 | continue; |
| 746 | |
| 747 | funcs = crtc->helper_private; |
| 748 | |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 749 | DRM_DEBUG_ATOMIC("disabling [CRTC:%d:%s]\n", |
| 750 | crtc->base.id, crtc->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 751 | |
| 752 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 753 | /* Right function depends upon target state. */ |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 754 | if (crtc->state->enable && funcs->prepare) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 755 | funcs->prepare(crtc); |
Liu Ying | c9ac8b4 | 2016-08-26 15:30:38 +0800 | [diff] [blame] | 756 | else if (funcs->atomic_disable) |
| 757 | funcs->atomic_disable(crtc, old_crtc_state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 758 | else if (funcs->disable) |
| 759 | funcs->disable(crtc); |
| 760 | else |
| 761 | funcs->dpms(crtc, DRM_MODE_DPMS_OFF); |
| 762 | } |
| 763 | } |
| 764 | |
Daniel Vetter | 4c18d30 | 2015-05-12 15:27:37 +0200 | [diff] [blame] | 765 | /** |
| 766 | * drm_atomic_helper_update_legacy_modeset_state - update legacy modeset state |
| 767 | * @dev: DRM device |
| 768 | * @old_state: atomic state object with old state structures |
| 769 | * |
| 770 | * This function updates all the various legacy modeset state pointers in |
| 771 | * connectors, encoders and crtcs. It also updates the timestamping constants |
| 772 | * used for precise vblank timestamps by calling |
| 773 | * drm_calc_timestamping_constants(). |
| 774 | * |
| 775 | * Drivers can use this for building their own atomic commit if they don't have |
| 776 | * a pure helper-based modeset implementation. |
| 777 | */ |
| 778 | void |
| 779 | drm_atomic_helper_update_legacy_modeset_state(struct drm_device *dev, |
| 780 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 781 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 782 | struct drm_connector *connector; |
| 783 | struct drm_connector_state *old_conn_state; |
| 784 | struct drm_crtc *crtc; |
| 785 | struct drm_crtc_state *old_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 786 | int i; |
| 787 | |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 788 | /* clear out existing links and update dpms */ |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 789 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 790 | if (connector->encoder) { |
| 791 | WARN_ON(!connector->encoder->crtc); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 792 | |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 793 | connector->encoder->crtc = NULL; |
| 794 | connector->encoder = NULL; |
| 795 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 796 | |
Maarten Lankhorst | 8c10342 | 2015-07-27 13:24:29 +0200 | [diff] [blame] | 797 | crtc = connector->state->crtc; |
| 798 | if ((!crtc && old_conn_state->crtc) || |
| 799 | (crtc && drm_atomic_crtc_needs_modeset(crtc->state))) { |
| 800 | struct drm_property *dpms_prop = |
| 801 | dev->mode_config.dpms_property; |
| 802 | int mode = DRM_MODE_DPMS_OFF; |
| 803 | |
| 804 | if (crtc && crtc->state->active) |
| 805 | mode = DRM_MODE_DPMS_ON; |
| 806 | |
| 807 | connector->dpms = mode; |
| 808 | drm_object_property_set_value(&connector->base, |
| 809 | dpms_prop, mode); |
| 810 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | /* set new links */ |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 814 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
| 815 | if (!connector->state->crtc) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 816 | continue; |
| 817 | |
| 818 | if (WARN_ON(!connector->state->best_encoder)) |
| 819 | continue; |
| 820 | |
| 821 | connector->encoder = connector->state->best_encoder; |
| 822 | connector->encoder->crtc = connector->state->crtc; |
| 823 | } |
| 824 | |
| 825 | /* set legacy state in the crtc structure */ |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 826 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Maarten Lankhorst | 2660801 | 2015-07-16 15:51:01 +0200 | [diff] [blame] | 827 | struct drm_plane *primary = crtc->primary; |
| 828 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 829 | crtc->mode = crtc->state->mode; |
| 830 | crtc->enabled = crtc->state->enable; |
Maarten Lankhorst | 2660801 | 2015-07-16 15:51:01 +0200 | [diff] [blame] | 831 | |
| 832 | if (drm_atomic_get_existing_plane_state(old_state, primary) && |
| 833 | primary->state->crtc == crtc) { |
| 834 | crtc->x = primary->state->src_x >> 16; |
| 835 | crtc->y = primary->state->src_y >> 16; |
| 836 | } |
Daniel Vetter | 3d51d2d | 2015-05-12 15:21:06 +0200 | [diff] [blame] | 837 | |
| 838 | if (crtc->state->enable) |
| 839 | drm_calc_timestamping_constants(crtc, |
| 840 | &crtc->state->adjusted_mode); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 841 | } |
| 842 | } |
Daniel Vetter | 4c18d30 | 2015-05-12 15:27:37 +0200 | [diff] [blame] | 843 | EXPORT_SYMBOL(drm_atomic_helper_update_legacy_modeset_state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 844 | |
| 845 | static void |
| 846 | crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state) |
| 847 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 848 | struct drm_crtc *crtc; |
| 849 | struct drm_crtc_state *old_crtc_state; |
| 850 | struct drm_connector *connector; |
| 851 | struct drm_connector_state *old_conn_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 852 | int i; |
| 853 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 854 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 855 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 856 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 857 | if (!crtc->state->mode_changed) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 858 | continue; |
| 859 | |
| 860 | funcs = crtc->helper_private; |
| 861 | |
Daniel Vetter | c982bd9 | 2015-02-22 12:24:20 +0100 | [diff] [blame] | 862 | if (crtc->state->enable && funcs->mode_set_nofb) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 863 | DRM_DEBUG_ATOMIC("modeset on [CRTC:%d:%s]\n", |
| 864 | crtc->base.id, crtc->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 865 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 866 | funcs->mode_set_nofb(crtc); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 867 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 868 | } |
| 869 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 870 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 871 | const struct drm_encoder_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 872 | struct drm_crtc_state *new_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 873 | struct drm_encoder *encoder; |
| 874 | struct drm_display_mode *mode, *adjusted_mode; |
| 875 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 876 | if (!connector->state->best_encoder) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 877 | continue; |
| 878 | |
| 879 | encoder = connector->state->best_encoder; |
| 880 | funcs = encoder->helper_private; |
| 881 | new_crtc_state = connector->state->crtc->state; |
| 882 | mode = &new_crtc_state->mode; |
| 883 | adjusted_mode = &new_crtc_state->adjusted_mode; |
| 884 | |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 885 | if (!new_crtc_state->mode_changed) |
| 886 | continue; |
| 887 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 888 | DRM_DEBUG_ATOMIC("modeset on [ENCODER:%d:%s]\n", |
| 889 | encoder->base.id, encoder->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 890 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 891 | /* |
| 892 | * Each encoder has at most one connector (since we always steal |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 893 | * it away), so we won't call mode_set hooks twice. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 894 | */ |
Philipp Zabel | fe4a11c | 2016-07-22 12:20:47 +0200 | [diff] [blame] | 895 | if (funcs && funcs->atomic_mode_set) { |
| 896 | funcs->atomic_mode_set(encoder, new_crtc_state, |
| 897 | connector->state); |
| 898 | } else if (funcs && funcs->mode_set) { |
Daniel Vetter | c982bd9 | 2015-02-22 12:24:20 +0100 | [diff] [blame] | 899 | funcs->mode_set(encoder, mode, adjusted_mode); |
Philipp Zabel | fe4a11c | 2016-07-22 12:20:47 +0200 | [diff] [blame] | 900 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 901 | |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 902 | drm_bridge_mode_set(encoder->bridge, mode, adjusted_mode); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 903 | } |
| 904 | } |
| 905 | |
| 906 | /** |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 907 | * drm_atomic_helper_commit_modeset_disables - modeset commit to disable outputs |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 908 | * @dev: DRM device |
Laurent Pinchart | a072f80 | 2015-02-22 12:24:18 +0100 | [diff] [blame] | 909 | * @old_state: atomic state object with old state structures |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 910 | * |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 911 | * This function shuts down all the outputs that need to be shut down and |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 912 | * prepares them (if required) with the new mode. |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 913 | * |
Laurent Pinchart | 60acc4e | 2015-05-27 15:05:42 +0300 | [diff] [blame] | 914 | * For compatibility with legacy crtc helpers this should be called before |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 915 | * drm_atomic_helper_commit_planes(), which is what the default commit function |
| 916 | * does. But drivers with different needs can group the modeset commits together |
| 917 | * and do the plane commits at the end. This is useful for drivers doing runtime |
| 918 | * PM since planes updates then only happen when the CRTC is actually enabled. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 919 | */ |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 920 | void drm_atomic_helper_commit_modeset_disables(struct drm_device *dev, |
| 921 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 922 | { |
Laurent Pinchart | a072f80 | 2015-02-22 12:24:18 +0100 | [diff] [blame] | 923 | disable_outputs(dev, old_state); |
Daniel Vetter | 4c18d30 | 2015-05-12 15:27:37 +0200 | [diff] [blame] | 924 | |
| 925 | drm_atomic_helper_update_legacy_modeset_state(dev, old_state); |
| 926 | |
Laurent Pinchart | a072f80 | 2015-02-22 12:24:18 +0100 | [diff] [blame] | 927 | crtc_set_mode(dev, old_state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 928 | } |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 929 | EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_disables); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 930 | |
| 931 | /** |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 932 | * drm_atomic_helper_commit_modeset_enables - modeset commit to enable outputs |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 933 | * @dev: DRM device |
| 934 | * @old_state: atomic state object with old state structures |
| 935 | * |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 936 | * This function enables all the outputs with the new configuration which had to |
| 937 | * be turned off for the update. |
| 938 | * |
Laurent Pinchart | 60acc4e | 2015-05-27 15:05:42 +0300 | [diff] [blame] | 939 | * For compatibility with legacy crtc helpers this should be called after |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 940 | * drm_atomic_helper_commit_planes(), which is what the default commit function |
| 941 | * does. But drivers with different needs can group the modeset commits together |
| 942 | * and do the plane commits at the end. This is useful for drivers doing runtime |
| 943 | * PM since planes updates then only happen when the CRTC is actually enabled. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 944 | */ |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 945 | void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, |
| 946 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 947 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 948 | struct drm_crtc *crtc; |
| 949 | struct drm_crtc_state *old_crtc_state; |
| 950 | struct drm_connector *connector; |
| 951 | struct drm_connector_state *old_conn_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 952 | int i; |
| 953 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 954 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 955 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 956 | |
| 957 | /* Need to filter out CRTCs where only planes change. */ |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 958 | if (!drm_atomic_crtc_needs_modeset(crtc->state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 959 | continue; |
| 960 | |
| 961 | if (!crtc->state->active) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 962 | continue; |
| 963 | |
| 964 | funcs = crtc->helper_private; |
| 965 | |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 966 | if (crtc->state->enable) { |
Ville Syrjälä | fa3ab4c | 2015-12-08 18:41:53 +0200 | [diff] [blame] | 967 | DRM_DEBUG_ATOMIC("enabling [CRTC:%d:%s]\n", |
| 968 | crtc->base.id, crtc->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 969 | |
Daniel Vetter | ee0a89c | 2015-01-22 16:36:24 +0100 | [diff] [blame] | 970 | if (funcs->enable) |
| 971 | funcs->enable(crtc); |
| 972 | else |
| 973 | funcs->commit(crtc); |
| 974 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 975 | } |
| 976 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 977 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 978 | const struct drm_encoder_helper_funcs *funcs; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 979 | struct drm_encoder *encoder; |
| 980 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 981 | if (!connector->state->best_encoder) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 982 | continue; |
| 983 | |
Daniel Vetter | 4218a32 | 2015-03-26 22:18:40 +0100 | [diff] [blame] | 984 | if (!connector->state->crtc->state->active || |
Daniel Vetter | 2465ff6 | 2015-06-18 09:58:55 +0200 | [diff] [blame] | 985 | !drm_atomic_crtc_needs_modeset(connector->state->crtc->state)) |
Daniel Vetter | eab3bbe | 2015-01-22 16:36:21 +0100 | [diff] [blame] | 986 | continue; |
| 987 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 988 | encoder = connector->state->best_encoder; |
| 989 | funcs = encoder->helper_private; |
| 990 | |
Daniel Vetter | 17a38d9 | 2015-02-22 12:24:16 +0100 | [diff] [blame] | 991 | DRM_DEBUG_ATOMIC("enabling [ENCODER:%d:%s]\n", |
| 992 | encoder->base.id, encoder->name); |
Daniel Vetter | 95d6eb3 | 2015-01-22 16:36:25 +0100 | [diff] [blame] | 993 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 994 | /* |
| 995 | * Each encoder has at most one connector (since we always steal |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 996 | * it away), so we won't call enable hooks twice. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 997 | */ |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 998 | drm_bridge_pre_enable(encoder->bridge); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 999 | |
Noralf Trønnes | 2827635 | 2016-05-11 18:09:20 +0200 | [diff] [blame] | 1000 | if (funcs) { |
| 1001 | if (funcs->enable) |
| 1002 | funcs->enable(encoder); |
| 1003 | else if (funcs->commit) |
| 1004 | funcs->commit(encoder); |
| 1005 | } |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1006 | |
Archit Taneja | 862e686 | 2015-05-21 11:03:16 +0530 | [diff] [blame] | 1007 | drm_bridge_enable(encoder->bridge); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1008 | } |
| 1009 | } |
Daniel Vetter | 1af434a | 2015-02-22 12:24:19 +0100 | [diff] [blame] | 1010 | EXPORT_SYMBOL(drm_atomic_helper_commit_modeset_enables); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1011 | |
Rob Clark | 4c5b7f3 | 2016-03-18 19:14:55 -0400 | [diff] [blame] | 1012 | /** |
| 1013 | * drm_atomic_helper_wait_for_fences - wait for fences stashed in plane state |
| 1014 | * @dev: DRM device |
| 1015 | * @state: atomic state object with old state structures |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1016 | * @pre_swap: If true, do an interruptible wait, and @state is the new state. |
| 1017 | * Otherwise @state is the old state. |
Rob Clark | 4c5b7f3 | 2016-03-18 19:14:55 -0400 | [diff] [blame] | 1018 | * |
| 1019 | * For implicit sync, driver should fish the exclusive fence out from the |
| 1020 | * incoming fb's and stash it in the drm_plane_state. This is called after |
| 1021 | * drm_atomic_helper_swap_state() so it uses the current plane state (and |
| 1022 | * just uses the atomic state to find the changed planes) |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1023 | * |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1024 | * Note that @pre_swap is needed since the point where we block for fences moves |
| 1025 | * around depending upon whether an atomic commit is blocking or |
| 1026 | * non-blocking. For async commit all waiting needs to happen after |
| 1027 | * drm_atomic_helper_swap_state() is called, but for synchronous commits we want |
| 1028 | * to wait **before** we do anything that can't be easily rolled back. That is |
| 1029 | * before we call drm_atomic_helper_swap_state(). |
| 1030 | * |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 1031 | * Returns zero if success or < 0 if dma_fence_wait() fails. |
Rob Clark | 4c5b7f3 | 2016-03-18 19:14:55 -0400 | [diff] [blame] | 1032 | */ |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1033 | int drm_atomic_helper_wait_for_fences(struct drm_device *dev, |
| 1034 | struct drm_atomic_state *state, |
| 1035 | bool pre_swap) |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1036 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1037 | struct drm_plane *plane; |
| 1038 | struct drm_plane_state *plane_state; |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1039 | int i, ret; |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1040 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1041 | for_each_plane_in_state(state, plane, plane_state, i) { |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1042 | if (!pre_swap) |
| 1043 | plane_state = plane->state; |
| 1044 | |
| 1045 | if (!plane_state->fence) |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1046 | continue; |
| 1047 | |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1048 | WARN_ON(!plane_state->fb); |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1049 | |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1050 | /* |
| 1051 | * If waiting for fences pre-swap (ie: nonblock), userspace can |
| 1052 | * still interrupt the operation. Instead of blocking until the |
| 1053 | * timer expires, make the wait interruptible. |
| 1054 | */ |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 1055 | ret = dma_fence_wait(plane_state->fence, pre_swap); |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1056 | if (ret) |
| 1057 | return ret; |
| 1058 | |
Chris Wilson | f54d186 | 2016-10-25 13:00:45 +0100 | [diff] [blame] | 1059 | dma_fence_put(plane_state->fence); |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1060 | plane_state->fence = NULL; |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1061 | } |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1062 | |
| 1063 | return 0; |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1064 | } |
Rob Clark | 4c5b7f3 | 2016-03-18 19:14:55 -0400 | [diff] [blame] | 1065 | EXPORT_SYMBOL(drm_atomic_helper_wait_for_fences); |
Daniel Vetter | e2330f0 | 2014-10-29 11:34:56 +0100 | [diff] [blame] | 1066 | |
John Keeping | c240906 | 2016-01-19 10:46:58 +0000 | [diff] [blame] | 1067 | /** |
| 1068 | * drm_atomic_helper_framebuffer_changed - check if framebuffer has changed |
| 1069 | * @dev: DRM device |
| 1070 | * @old_state: atomic state object with old state structures |
| 1071 | * @crtc: DRM crtc |
| 1072 | * |
| 1073 | * Checks whether the framebuffer used for this CRTC changes as a result of |
| 1074 | * the atomic update. This is useful for drivers which cannot use |
| 1075 | * drm_atomic_helper_wait_for_vblanks() and need to reimplement its |
| 1076 | * functionality. |
| 1077 | * |
| 1078 | * Returns: |
| 1079 | * true if the framebuffer changed. |
| 1080 | */ |
| 1081 | bool drm_atomic_helper_framebuffer_changed(struct drm_device *dev, |
| 1082 | struct drm_atomic_state *old_state, |
| 1083 | struct drm_crtc *crtc) |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 1084 | { |
| 1085 | struct drm_plane *plane; |
| 1086 | struct drm_plane_state *old_plane_state; |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 1087 | int i; |
| 1088 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1089 | for_each_plane_in_state(old_state, plane, old_plane_state, i) { |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 1090 | if (plane->state->crtc != crtc && |
| 1091 | old_plane_state->crtc != crtc) |
| 1092 | continue; |
| 1093 | |
| 1094 | if (plane->state->fb != old_plane_state->fb) |
| 1095 | return true; |
| 1096 | } |
| 1097 | |
| 1098 | return false; |
| 1099 | } |
John Keeping | c240906 | 2016-01-19 10:46:58 +0000 | [diff] [blame] | 1100 | EXPORT_SYMBOL(drm_atomic_helper_framebuffer_changed); |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 1101 | |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 1102 | /** |
| 1103 | * drm_atomic_helper_wait_for_vblanks - wait for vblank on crtcs |
| 1104 | * @dev: DRM device |
| 1105 | * @old_state: atomic state object with old state structures |
| 1106 | * |
| 1107 | * Helper to, after atomic commit, wait for vblanks on all effected |
| 1108 | * crtcs (ie. before cleaning up old framebuffers using |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 1109 | * drm_atomic_helper_cleanup_planes()). It will only wait on crtcs where the |
| 1110 | * framebuffers have actually changed to optimize for the legacy cursor and |
| 1111 | * plane update use-case. |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 1112 | */ |
| 1113 | void |
| 1114 | drm_atomic_helper_wait_for_vblanks(struct drm_device *dev, |
| 1115 | struct drm_atomic_state *old_state) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1116 | { |
| 1117 | struct drm_crtc *crtc; |
| 1118 | struct drm_crtc_state *old_crtc_state; |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1119 | int i, ret; |
| 1120 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1121 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1122 | /* No one cares about the old state, so abuse it for tracking |
| 1123 | * and store whether we hold a vblank reference (and should do a |
| 1124 | * vblank wait) in the ->enable boolean. */ |
| 1125 | old_crtc_state->enable = false; |
| 1126 | |
Maarten Lankhorst | 7da0e12 | 2016-12-08 14:45:24 +0100 | [diff] [blame] | 1127 | if (!crtc->state->active) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1128 | continue; |
| 1129 | |
Daniel Vetter | f02ad90 | 2015-01-22 16:36:23 +0100 | [diff] [blame] | 1130 | /* Legacy cursor ioctls are completely unsynced, and userspace |
| 1131 | * relies on that (by doing tons of cursor updates). */ |
| 1132 | if (old_state->legacy_cursor_update) |
| 1133 | continue; |
| 1134 | |
John Keeping | c240906 | 2016-01-19 10:46:58 +0000 | [diff] [blame] | 1135 | if (!drm_atomic_helper_framebuffer_changed(dev, |
| 1136 | old_state, crtc)) |
Daniel Vetter | ab58e33 | 2014-11-24 20:42:42 +0100 | [diff] [blame] | 1137 | continue; |
| 1138 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1139 | ret = drm_crtc_vblank_get(crtc); |
| 1140 | if (ret != 0) |
| 1141 | continue; |
| 1142 | |
| 1143 | old_crtc_state->enable = true; |
Thierry Reding | d485363 | 2015-08-12 17:00:35 +0200 | [diff] [blame] | 1144 | old_crtc_state->last_vblank_count = drm_crtc_vblank_count(crtc); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1145 | } |
| 1146 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1147 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
| 1148 | if (!old_crtc_state->enable) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1149 | continue; |
| 1150 | |
| 1151 | ret = wait_event_timeout(dev->vblank[i].queue, |
| 1152 | old_crtc_state->last_vblank_count != |
Thierry Reding | d485363 | 2015-08-12 17:00:35 +0200 | [diff] [blame] | 1153 | drm_crtc_vblank_count(crtc), |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1154 | msecs_to_jiffies(50)); |
| 1155 | |
Ville Syrjälä | 8d4d0d7 | 2016-04-18 14:29:33 +0300 | [diff] [blame] | 1156 | WARN(!ret, "[CRTC:%d] vblank wait timed out\n", crtc->base.id); |
| 1157 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1158 | drm_crtc_vblank_put(crtc); |
| 1159 | } |
| 1160 | } |
Rob Clark | 5ee3229 | 2014-11-11 19:38:59 -0500 | [diff] [blame] | 1161 | EXPORT_SYMBOL(drm_atomic_helper_wait_for_vblanks); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1162 | |
| 1163 | /** |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1164 | * drm_atomic_helper_commit_tail - commit atomic update to hardware |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1165 | * @old_state: atomic state object with old state structures |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1166 | * |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1167 | * This is the default implemenation for the ->atomic_commit_tail() hook of the |
| 1168 | * &drm_mode_config_helper_funcs vtable. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1169 | * |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1170 | * Note that the default ordering of how the various stages are called is to |
| 1171 | * match the legacy modeset helper library closest. One peculiarity of that is |
| 1172 | * that it doesn't mesh well with runtime PM at all. |
Daniel Vetter | 6e48ae3 | 2015-09-08 13:52:45 +0200 | [diff] [blame] | 1173 | * |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1174 | * For drivers supporting runtime PM the recommended sequence is instead :: |
Daniel Vetter | 6e48ae3 | 2015-09-08 13:52:45 +0200 | [diff] [blame] | 1175 | * |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1176 | * drm_atomic_helper_commit_modeset_disables(dev, old_state); |
Daniel Vetter | 6e48ae3 | 2015-09-08 13:52:45 +0200 | [diff] [blame] | 1177 | * |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1178 | * drm_atomic_helper_commit_modeset_enables(dev, old_state); |
Daniel Vetter | 6e48ae3 | 2015-09-08 13:52:45 +0200 | [diff] [blame] | 1179 | * |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1180 | * drm_atomic_helper_commit_planes(dev, old_state, |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 1181 | * DRM_PLANE_COMMIT_ACTIVE_ONLY); |
Daniel Vetter | 6e48ae3 | 2015-09-08 13:52:45 +0200 | [diff] [blame] | 1182 | * |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1183 | * for committing the atomic update to hardware. See the kerneldoc entries for |
| 1184 | * these three functions for more details. |
| 1185 | */ |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1186 | void drm_atomic_helper_commit_tail(struct drm_atomic_state *old_state) |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1187 | { |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1188 | struct drm_device *dev = old_state->dev; |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1189 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1190 | drm_atomic_helper_commit_modeset_disables(dev, old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1191 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1192 | drm_atomic_helper_commit_planes(dev, old_state, 0); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1193 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1194 | drm_atomic_helper_commit_modeset_enables(dev, old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1195 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1196 | drm_atomic_helper_commit_hw_done(old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1197 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1198 | drm_atomic_helper_wait_for_vblanks(dev, old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1199 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1200 | drm_atomic_helper_cleanup_planes(dev, old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1201 | } |
| 1202 | EXPORT_SYMBOL(drm_atomic_helper_commit_tail); |
| 1203 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1204 | static void commit_tail(struct drm_atomic_state *old_state) |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1205 | { |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1206 | struct drm_device *dev = old_state->dev; |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1207 | struct drm_mode_config_helper_funcs *funcs; |
| 1208 | |
| 1209 | funcs = dev->mode_config.helper_private; |
| 1210 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1211 | drm_atomic_helper_wait_for_fences(dev, old_state, false); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1212 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1213 | drm_atomic_helper_wait_for_dependencies(old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1214 | |
| 1215 | if (funcs && funcs->atomic_commit_tail) |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1216 | funcs->atomic_commit_tail(old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1217 | else |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1218 | drm_atomic_helper_commit_tail(old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1219 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1220 | drm_atomic_helper_commit_cleanup_done(old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1221 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1222 | drm_atomic_state_put(old_state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1223 | } |
| 1224 | |
| 1225 | static void commit_work(struct work_struct *work) |
| 1226 | { |
| 1227 | struct drm_atomic_state *state = container_of(work, |
| 1228 | struct drm_atomic_state, |
| 1229 | commit_work); |
| 1230 | commit_tail(state); |
| 1231 | } |
| 1232 | |
| 1233 | /** |
| 1234 | * drm_atomic_helper_commit - commit validated state object |
| 1235 | * @dev: DRM device |
| 1236 | * @state: the driver state object |
| 1237 | * @nonblock: whether nonblocking behavior is requested. |
| 1238 | * |
| 1239 | * This function commits a with drm_atomic_helper_check() pre-validated state |
| 1240 | * object. This can still fail when e.g. the framebuffer reservation fails. This |
| 1241 | * function implements nonblocking commits, using |
| 1242 | * drm_atomic_helper_setup_commit() and related functions. |
| 1243 | * |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1244 | * Committing the actual hardware state is done through the |
| 1245 | * ->atomic_commit_tail() callback of the &drm_mode_config_helper_funcs vtable, |
| 1246 | * or it's default implementation drm_atomic_helper_commit_tail(). |
Daniel Vetter | 6e48ae3 | 2015-09-08 13:52:45 +0200 | [diff] [blame] | 1247 | * |
Daniel Vetter | c39032a | 2016-06-08 14:19:19 +0200 | [diff] [blame] | 1248 | * RETURNS: |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1249 | * Zero for success or -errno. |
| 1250 | */ |
| 1251 | int drm_atomic_helper_commit(struct drm_device *dev, |
| 1252 | struct drm_atomic_state *state, |
Maarten Lankhorst | 286dbb8 | 2016-04-26 16:11:34 +0200 | [diff] [blame] | 1253 | bool nonblock) |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1254 | { |
| 1255 | int ret; |
| 1256 | |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1257 | ret = drm_atomic_helper_setup_commit(state, nonblock); |
| 1258 | if (ret) |
| 1259 | return ret; |
| 1260 | |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1261 | INIT_WORK(&state->commit_work, commit_work); |
| 1262 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1263 | ret = drm_atomic_helper_prepare_planes(dev, state); |
| 1264 | if (ret) |
| 1265 | return ret; |
| 1266 | |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 1267 | if (!nonblock) { |
| 1268 | ret = drm_atomic_helper_wait_for_fences(dev, state, true); |
| 1269 | if (ret) |
| 1270 | return ret; |
| 1271 | } |
| 1272 | |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1273 | /* |
| 1274 | * This is the point of no return - everything below never fails except |
| 1275 | * when the hw goes bonghits. Which means we can commit the new state on |
| 1276 | * the software side now. |
| 1277 | */ |
| 1278 | |
Daniel Vetter | 5e84c26 | 2016-06-10 00:06:32 +0200 | [diff] [blame] | 1279 | drm_atomic_helper_swap_state(state, true); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1280 | |
| 1281 | /* |
| 1282 | * Everything below can be run asynchronously without the need to grab |
John Hunter | f98bd3e | 2015-03-17 15:30:26 +0800 | [diff] [blame] | 1283 | * any modeset locks at all under one condition: It must be guaranteed |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1284 | * that the asynchronous work has either been cancelled (if the driver |
| 1285 | * supports it, which at least requires that the framebuffers get |
| 1286 | * cleaned up with drm_atomic_helper_cleanup_planes()) or completed |
| 1287 | * before the new state gets committed on the software side with |
| 1288 | * drm_atomic_helper_swap_state(). |
| 1289 | * |
| 1290 | * This scheme allows new atomic state updates to be prepared and |
| 1291 | * checked in parallel to the asynchronous completion of the previous |
| 1292 | * update. Which is important since compositors need to figure out the |
| 1293 | * composition of the next frame right after having submitted the |
| 1294 | * current layout. |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1295 | * |
| 1296 | * NOTE: Commit work has multiple phases, first hardware commit, then |
| 1297 | * cleanup. We want them to overlap, hence need system_unbound_wq to |
| 1298 | * make sure work items don't artifically stall on each another. |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1299 | */ |
| 1300 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 1301 | drm_atomic_state_get(state); |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1302 | if (nonblock) |
| 1303 | queue_work(system_unbound_wq, &state->commit_work); |
| 1304 | else |
| 1305 | commit_tail(state); |
Daniel Vetter | 623369e | 2014-09-16 17:50:47 +0200 | [diff] [blame] | 1306 | |
| 1307 | return 0; |
| 1308 | } |
| 1309 | EXPORT_SYMBOL(drm_atomic_helper_commit); |
| 1310 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1311 | /** |
Maarten Lankhorst | 286dbb8 | 2016-04-26 16:11:34 +0200 | [diff] [blame] | 1312 | * DOC: implementing nonblocking commit |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1313 | * |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1314 | * Nonblocking atomic commits have to be implemented in the following sequence: |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1315 | * |
| 1316 | * 1. Run drm_atomic_helper_prepare_planes() first. This is the only function |
| 1317 | * which commit needs to call which can fail, so we want to run it first and |
| 1318 | * synchronously. |
| 1319 | * |
Maarten Lankhorst | 286dbb8 | 2016-04-26 16:11:34 +0200 | [diff] [blame] | 1320 | * 2. Synchronize with any outstanding nonblocking commit worker threads which |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1321 | * might be affected the new state update. This can be done by either cancelling |
| 1322 | * or flushing the work items, depending upon whether the driver can deal with |
| 1323 | * cancelled updates. Note that it is important to ensure that the framebuffer |
| 1324 | * cleanup is still done when cancelling. |
| 1325 | * |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1326 | * Asynchronous workers need to have sufficient parallelism to be able to run |
| 1327 | * different atomic commits on different CRTCs in parallel. The simplest way to |
| 1328 | * achive this is by running them on the &system_unbound_wq work queue. Note |
| 1329 | * that drivers are not required to split up atomic commits and run an |
| 1330 | * individual commit in parallel - userspace is supposed to do that if it cares. |
| 1331 | * But it might be beneficial to do that for modesets, since those necessarily |
| 1332 | * must be done as one global operation, and enabling or disabling a CRTC can |
| 1333 | * take a long time. But even that is not required. |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1334 | * |
| 1335 | * 3. The software state is updated synchronously with |
Daniel Vetter | 26196f7 | 2015-08-25 16:26:03 +0200 | [diff] [blame] | 1336 | * drm_atomic_helper_swap_state(). Doing this under the protection of all modeset |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1337 | * locks means concurrent callers never see inconsistent state. And doing this |
Maarten Lankhorst | 286dbb8 | 2016-04-26 16:11:34 +0200 | [diff] [blame] | 1338 | * while it's guaranteed that no relevant nonblocking worker runs means that |
| 1339 | * nonblocking workers do not need grab any locks. Actually they must not grab |
| 1340 | * locks, for otherwise the work flushing will deadlock. |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1341 | * |
| 1342 | * 4. Schedule a work item to do all subsequent steps, using the split-out |
| 1343 | * commit helpers: a) pre-plane commit b) plane commit c) post-plane commit and |
| 1344 | * then cleaning up the framebuffers after the old framebuffer is no longer |
| 1345 | * being displayed. |
Daniel Vetter | 9f2a795 | 2016-06-08 14:19:02 +0200 | [diff] [blame] | 1346 | * |
| 1347 | * The above scheme is implemented in the atomic helper libraries in |
| 1348 | * drm_atomic_helper_commit() using a bunch of helper functions. See |
| 1349 | * drm_atomic_helper_setup_commit() for a starting point. |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1350 | */ |
| 1351 | |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1352 | static int stall_checks(struct drm_crtc *crtc, bool nonblock) |
| 1353 | { |
| 1354 | struct drm_crtc_commit *commit, *stall_commit = NULL; |
| 1355 | bool completed = true; |
| 1356 | int i; |
| 1357 | long ret = 0; |
| 1358 | |
| 1359 | spin_lock(&crtc->commit_lock); |
| 1360 | i = 0; |
| 1361 | list_for_each_entry(commit, &crtc->commit_list, commit_entry) { |
| 1362 | if (i == 0) { |
| 1363 | completed = try_wait_for_completion(&commit->flip_done); |
| 1364 | /* Userspace is not allowed to get ahead of the previous |
| 1365 | * commit with nonblocking ones. */ |
| 1366 | if (!completed && nonblock) { |
| 1367 | spin_unlock(&crtc->commit_lock); |
| 1368 | return -EBUSY; |
| 1369 | } |
| 1370 | } else if (i == 1) { |
| 1371 | stall_commit = commit; |
| 1372 | drm_crtc_commit_get(stall_commit); |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1373 | break; |
Daniel Vetter | 723c3e5 | 2016-06-14 19:50:58 +0200 | [diff] [blame] | 1374 | } |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1375 | |
| 1376 | i++; |
| 1377 | } |
| 1378 | spin_unlock(&crtc->commit_lock); |
| 1379 | |
| 1380 | if (!stall_commit) |
| 1381 | return 0; |
| 1382 | |
| 1383 | /* We don't want to let commits get ahead of cleanup work too much, |
| 1384 | * stalling on 2nd previous commit means triple-buffer won't ever stall. |
| 1385 | */ |
Daniel Vetter | 723c3e5 | 2016-06-14 19:50:58 +0200 | [diff] [blame] | 1386 | ret = wait_for_completion_interruptible_timeout(&stall_commit->cleanup_done, |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1387 | 10*HZ); |
| 1388 | if (ret == 0) |
| 1389 | DRM_ERROR("[CRTC:%d:%s] cleanup_done timed out\n", |
| 1390 | crtc->base.id, crtc->name); |
| 1391 | |
| 1392 | drm_crtc_commit_put(stall_commit); |
| 1393 | |
| 1394 | return ret < 0 ? ret : 0; |
| 1395 | } |
| 1396 | |
| 1397 | /** |
| 1398 | * drm_atomic_helper_setup_commit - setup possibly nonblocking commit |
| 1399 | * @state: new modeset state to be committed |
| 1400 | * @nonblock: whether nonblocking behavior is requested. |
| 1401 | * |
| 1402 | * This function prepares @state to be used by the atomic helper's support for |
| 1403 | * nonblocking commits. Drivers using the nonblocking commit infrastructure |
| 1404 | * should always call this function from their ->atomic_commit hook. |
| 1405 | * |
| 1406 | * To be able to use this support drivers need to use a few more helper |
| 1407 | * functions. drm_atomic_helper_wait_for_dependencies() must be called before |
| 1408 | * actually committing the hardware state, and for nonblocking commits this call |
| 1409 | * must be placed in the async worker. See also drm_atomic_helper_swap_state() |
| 1410 | * and it's stall parameter, for when a driver's commit hooks look at the |
| 1411 | * ->state pointers of struct &drm_crtc, &drm_plane or &drm_connector directly. |
| 1412 | * |
| 1413 | * Completion of the hardware commit step must be signalled using |
| 1414 | * drm_atomic_helper_commit_hw_done(). After this step the driver is not allowed |
| 1415 | * to read or change any permanent software or hardware modeset state. The only |
| 1416 | * exception is state protected by other means than &drm_modeset_lock locks. |
| 1417 | * Only the free standing @state with pointers to the old state structures can |
| 1418 | * be inspected, e.g. to clean up old buffers using |
| 1419 | * drm_atomic_helper_cleanup_planes(). |
| 1420 | * |
| 1421 | * At the very end, before cleaning up @state drivers must call |
| 1422 | * drm_atomic_helper_commit_cleanup_done(). |
| 1423 | * |
| 1424 | * This is all implemented by in drm_atomic_helper_commit(), giving drivers a |
| 1425 | * complete and esay-to-use default implementation of the atomic_commit() hook. |
| 1426 | * |
| 1427 | * The tracking of asynchronously executed and still pending commits is done |
| 1428 | * using the core structure &drm_crtc_commit. |
| 1429 | * |
| 1430 | * By default there's no need to clean up resources allocated by this function |
| 1431 | * explicitly: drm_atomic_state_default_clear() will take care of that |
| 1432 | * automatically. |
| 1433 | * |
| 1434 | * Returns: |
| 1435 | * |
| 1436 | * 0 on success. -EBUSY when userspace schedules nonblocking commits too fast, |
| 1437 | * -ENOMEM on allocation failures and -EINTR when a signal is pending. |
| 1438 | */ |
| 1439 | int drm_atomic_helper_setup_commit(struct drm_atomic_state *state, |
| 1440 | bool nonblock) |
| 1441 | { |
| 1442 | struct drm_crtc *crtc; |
| 1443 | struct drm_crtc_state *crtc_state; |
| 1444 | struct drm_crtc_commit *commit; |
| 1445 | int i, ret; |
| 1446 | |
| 1447 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 1448 | commit = kzalloc(sizeof(*commit), GFP_KERNEL); |
| 1449 | if (!commit) |
| 1450 | return -ENOMEM; |
| 1451 | |
| 1452 | init_completion(&commit->flip_done); |
| 1453 | init_completion(&commit->hw_done); |
| 1454 | init_completion(&commit->cleanup_done); |
| 1455 | INIT_LIST_HEAD(&commit->commit_entry); |
| 1456 | kref_init(&commit->ref); |
| 1457 | commit->crtc = crtc; |
| 1458 | |
| 1459 | state->crtcs[i].commit = commit; |
| 1460 | |
| 1461 | ret = stall_checks(crtc, nonblock); |
| 1462 | if (ret) |
| 1463 | return ret; |
| 1464 | |
| 1465 | /* Drivers only send out events when at least either current or |
| 1466 | * new CRTC state is active. Complete right away if everything |
| 1467 | * stays off. */ |
| 1468 | if (!crtc->state->active && !crtc_state->active) { |
| 1469 | complete_all(&commit->flip_done); |
| 1470 | continue; |
| 1471 | } |
| 1472 | |
| 1473 | /* Legacy cursor updates are fully unsynced. */ |
| 1474 | if (state->legacy_cursor_update) { |
| 1475 | complete_all(&commit->flip_done); |
| 1476 | continue; |
| 1477 | } |
| 1478 | |
| 1479 | if (!crtc_state->event) { |
| 1480 | commit->event = kzalloc(sizeof(*commit->event), |
| 1481 | GFP_KERNEL); |
| 1482 | if (!commit->event) |
| 1483 | return -ENOMEM; |
| 1484 | |
| 1485 | crtc_state->event = commit->event; |
| 1486 | } |
| 1487 | |
| 1488 | crtc_state->event->base.completion = &commit->flip_done; |
| 1489 | } |
| 1490 | |
| 1491 | return 0; |
| 1492 | } |
| 1493 | EXPORT_SYMBOL(drm_atomic_helper_setup_commit); |
| 1494 | |
| 1495 | |
| 1496 | static struct drm_crtc_commit *preceeding_commit(struct drm_crtc *crtc) |
| 1497 | { |
| 1498 | struct drm_crtc_commit *commit; |
| 1499 | int i = 0; |
| 1500 | |
| 1501 | list_for_each_entry(commit, &crtc->commit_list, commit_entry) { |
| 1502 | /* skip the first entry, that's the current commit */ |
| 1503 | if (i == 1) |
| 1504 | return commit; |
| 1505 | i++; |
| 1506 | } |
| 1507 | |
| 1508 | return NULL; |
| 1509 | } |
| 1510 | |
| 1511 | /** |
| 1512 | * drm_atomic_helper_wait_for_dependencies - wait for required preceeding commits |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1513 | * @old_state: atomic state object with old state structures |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1514 | * |
| 1515 | * This function waits for all preceeding commits that touch the same CRTC as |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1516 | * @old_state to both be committed to the hardware (as signalled by |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1517 | * drm_atomic_helper_commit_hw_done) and executed by the hardware (as signalled |
| 1518 | * by calling drm_crtc_vblank_send_event on the event member of |
| 1519 | * &drm_crtc_state). |
| 1520 | * |
| 1521 | * This is part of the atomic helper support for nonblocking commits, see |
| 1522 | * drm_atomic_helper_setup_commit() for an overview. |
| 1523 | */ |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1524 | void drm_atomic_helper_wait_for_dependencies(struct drm_atomic_state *old_state) |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1525 | { |
| 1526 | struct drm_crtc *crtc; |
| 1527 | struct drm_crtc_state *crtc_state; |
| 1528 | struct drm_crtc_commit *commit; |
| 1529 | int i; |
| 1530 | long ret; |
| 1531 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1532 | for_each_crtc_in_state(old_state, crtc, crtc_state, i) { |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1533 | spin_lock(&crtc->commit_lock); |
| 1534 | commit = preceeding_commit(crtc); |
| 1535 | if (commit) |
| 1536 | drm_crtc_commit_get(commit); |
| 1537 | spin_unlock(&crtc->commit_lock); |
| 1538 | |
| 1539 | if (!commit) |
| 1540 | continue; |
| 1541 | |
| 1542 | ret = wait_for_completion_timeout(&commit->hw_done, |
| 1543 | 10*HZ); |
| 1544 | if (ret == 0) |
| 1545 | DRM_ERROR("[CRTC:%d:%s] hw_done timed out\n", |
| 1546 | crtc->base.id, crtc->name); |
| 1547 | |
| 1548 | /* Currently no support for overwriting flips, hence |
| 1549 | * stall for previous one to execute completely. */ |
| 1550 | ret = wait_for_completion_timeout(&commit->flip_done, |
| 1551 | 10*HZ); |
| 1552 | if (ret == 0) |
| 1553 | DRM_ERROR("[CRTC:%d:%s] flip_done timed out\n", |
| 1554 | crtc->base.id, crtc->name); |
| 1555 | |
| 1556 | drm_crtc_commit_put(commit); |
| 1557 | } |
| 1558 | } |
| 1559 | EXPORT_SYMBOL(drm_atomic_helper_wait_for_dependencies); |
| 1560 | |
| 1561 | /** |
| 1562 | * drm_atomic_helper_commit_hw_done - setup possible nonblocking commit |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1563 | * @old_state: atomic state object with old state structures |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1564 | * |
| 1565 | * This function is used to signal completion of the hardware commit step. After |
| 1566 | * this step the driver is not allowed to read or change any permanent software |
| 1567 | * or hardware modeset state. The only exception is state protected by other |
| 1568 | * means than &drm_modeset_lock locks. |
| 1569 | * |
| 1570 | * Drivers should try to postpone any expensive or delayed cleanup work after |
| 1571 | * this function is called. |
| 1572 | * |
| 1573 | * This is part of the atomic helper support for nonblocking commits, see |
| 1574 | * drm_atomic_helper_setup_commit() for an overview. |
| 1575 | */ |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1576 | void drm_atomic_helper_commit_hw_done(struct drm_atomic_state *old_state) |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1577 | { |
| 1578 | struct drm_crtc *crtc; |
| 1579 | struct drm_crtc_state *crtc_state; |
| 1580 | struct drm_crtc_commit *commit; |
| 1581 | int i; |
| 1582 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1583 | for_each_crtc_in_state(old_state, crtc, crtc_state, i) { |
| 1584 | commit = old_state->crtcs[i].commit; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1585 | if (!commit) |
| 1586 | continue; |
| 1587 | |
| 1588 | /* backend must have consumed any event by now */ |
| 1589 | WARN_ON(crtc->state->event); |
| 1590 | spin_lock(&crtc->commit_lock); |
| 1591 | complete_all(&commit->hw_done); |
| 1592 | spin_unlock(&crtc->commit_lock); |
| 1593 | } |
| 1594 | } |
| 1595 | EXPORT_SYMBOL(drm_atomic_helper_commit_hw_done); |
| 1596 | |
| 1597 | /** |
| 1598 | * drm_atomic_helper_commit_cleanup_done - signal completion of commit |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1599 | * @old_state: atomic state object with old state structures |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1600 | * |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1601 | * This signals completion of the atomic update @old_state, including any |
| 1602 | * cleanup work. If used, it must be called right before calling |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 1603 | * drm_atomic_state_put(). |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1604 | * |
| 1605 | * This is part of the atomic helper support for nonblocking commits, see |
| 1606 | * drm_atomic_helper_setup_commit() for an overview. |
| 1607 | */ |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1608 | void drm_atomic_helper_commit_cleanup_done(struct drm_atomic_state *old_state) |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1609 | { |
| 1610 | struct drm_crtc *crtc; |
| 1611 | struct drm_crtc_state *crtc_state; |
| 1612 | struct drm_crtc_commit *commit; |
| 1613 | int i; |
| 1614 | long ret; |
| 1615 | |
Daniel Vetter | 1ea0c02 | 2016-11-21 18:18:02 +0100 | [diff] [blame] | 1616 | for_each_crtc_in_state(old_state, crtc, crtc_state, i) { |
| 1617 | commit = old_state->crtcs[i].commit; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1618 | if (WARN_ON(!commit)) |
| 1619 | continue; |
| 1620 | |
| 1621 | spin_lock(&crtc->commit_lock); |
| 1622 | complete_all(&commit->cleanup_done); |
| 1623 | WARN_ON(!try_wait_for_completion(&commit->hw_done)); |
| 1624 | |
| 1625 | /* commit_list borrows our reference, need to remove before we |
| 1626 | * clean up our drm_atomic_state. But only after it actually |
| 1627 | * completed, otherwise subsequent commits won't stall properly. */ |
Daniel Vetter | 7deef7f1 | 2016-06-15 12:24:26 +0200 | [diff] [blame] | 1628 | if (try_wait_for_completion(&commit->flip_done)) |
| 1629 | goto del_commit; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1630 | |
| 1631 | spin_unlock(&crtc->commit_lock); |
| 1632 | |
| 1633 | /* We must wait for the vblank event to signal our completion |
| 1634 | * before releasing our reference, since the vblank work does |
| 1635 | * not hold a reference of its own. */ |
| 1636 | ret = wait_for_completion_timeout(&commit->flip_done, |
| 1637 | 10*HZ); |
| 1638 | if (ret == 0) |
| 1639 | DRM_ERROR("[CRTC:%d:%s] flip_done timed out\n", |
| 1640 | crtc->base.id, crtc->name); |
| 1641 | |
| 1642 | spin_lock(&crtc->commit_lock); |
Daniel Vetter | 7deef7f1 | 2016-06-15 12:24:26 +0200 | [diff] [blame] | 1643 | del_commit: |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1644 | list_del(&commit->commit_entry); |
| 1645 | spin_unlock(&crtc->commit_lock); |
| 1646 | } |
| 1647 | } |
| 1648 | EXPORT_SYMBOL(drm_atomic_helper_commit_cleanup_done); |
| 1649 | |
Daniel Vetter | e8c833a | 2014-07-27 18:30:19 +0200 | [diff] [blame] | 1650 | /** |
Daniel Vetter | 2e3afd4 | 2015-02-26 14:17:38 +0100 | [diff] [blame] | 1651 | * drm_atomic_helper_prepare_planes - prepare plane resources before commit |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1652 | * @dev: DRM device |
Daniel Vetter | 2e3afd4 | 2015-02-26 14:17:38 +0100 | [diff] [blame] | 1653 | * @state: atomic state object with new state structures |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1654 | * |
| 1655 | * This function prepares plane state, specifically framebuffers, for the new |
| 1656 | * configuration. If any failure is encountered this function will call |
| 1657 | * ->cleanup_fb on any already successfully prepared framebuffer. |
| 1658 | * |
| 1659 | * Returns: |
| 1660 | * 0 on success, negative error code on failure. |
| 1661 | */ |
| 1662 | int drm_atomic_helper_prepare_planes(struct drm_device *dev, |
| 1663 | struct drm_atomic_state *state) |
| 1664 | { |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 1665 | struct drm_plane *plane; |
| 1666 | struct drm_plane_state *plane_state; |
| 1667 | int ret, i, j; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1668 | |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 1669 | for_each_plane_in_state(state, plane, plane_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1670 | const struct drm_plane_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1671 | |
| 1672 | funcs = plane->helper_private; |
| 1673 | |
Keith Packard | fcc60b4 | 2016-06-04 01:16:22 -0700 | [diff] [blame] | 1674 | if (!drm_atomic_helper_framebuffer_changed(dev, state, plane_state->crtc)) |
| 1675 | continue; |
| 1676 | |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 1677 | if (funcs->prepare_fb) { |
| 1678 | ret = funcs->prepare_fb(plane, plane_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1679 | if (ret) |
| 1680 | goto fail; |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | return 0; |
| 1685 | |
| 1686 | fail: |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 1687 | for_each_plane_in_state(state, plane, plane_state, j) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1688 | const struct drm_plane_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1689 | |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 1690 | if (j >= i) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1691 | continue; |
| 1692 | |
Keith Packard | fcc60b4 | 2016-06-04 01:16:22 -0700 | [diff] [blame] | 1693 | if (!drm_atomic_helper_framebuffer_changed(dev, state, plane_state->crtc)) |
| 1694 | continue; |
| 1695 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1696 | funcs = plane->helper_private; |
| 1697 | |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 1698 | if (funcs->cleanup_fb) |
| 1699 | funcs->cleanup_fb(plane, plane_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1700 | } |
| 1701 | |
| 1702 | return ret; |
| 1703 | } |
| 1704 | EXPORT_SYMBOL(drm_atomic_helper_prepare_planes); |
| 1705 | |
Ville Syrjälä | 7135ac5 | 2016-09-19 16:33:42 +0300 | [diff] [blame] | 1706 | static bool plane_crtc_active(const struct drm_plane_state *state) |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 1707 | { |
| 1708 | return state->crtc && state->crtc->state->active; |
| 1709 | } |
| 1710 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1711 | /** |
| 1712 | * drm_atomic_helper_commit_planes - commit plane state |
| 1713 | * @dev: DRM device |
Daniel Vetter | b0fcfc8 | 2014-11-19 18:38:11 +0100 | [diff] [blame] | 1714 | * @old_state: atomic state object with old state structures |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 1715 | * @flags: flags for committing plane state |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1716 | * |
| 1717 | * This function commits the new plane state using the plane and atomic helper |
| 1718 | * functions for planes and crtcs. It assumes that the atomic state has already |
| 1719 | * been pushed into the relevant object state pointers, since this step can no |
| 1720 | * longer fail. |
| 1721 | * |
Daniel Vetter | b0fcfc8 | 2014-11-19 18:38:11 +0100 | [diff] [blame] | 1722 | * It still requires the global state object @old_state to know which planes and |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1723 | * crtcs need to be updated though. |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 1724 | * |
| 1725 | * Note that this function does all plane updates across all CRTCs in one step. |
| 1726 | * If the hardware can't support this approach look at |
| 1727 | * drm_atomic_helper_commit_planes_on_crtc() instead. |
Daniel Vetter | 6e48ae3 | 2015-09-08 13:52:45 +0200 | [diff] [blame] | 1728 | * |
| 1729 | * Plane parameters can be updated by applications while the associated CRTC is |
| 1730 | * disabled. The DRM/KMS core will store the parameters in the plane state, |
| 1731 | * which will be available to the driver when the CRTC is turned on. As a result |
| 1732 | * most drivers don't need to be immediately notified of plane updates for a |
| 1733 | * disabled CRTC. |
| 1734 | * |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 1735 | * Unless otherwise needed, drivers are advised to set the ACTIVE_ONLY flag in |
| 1736 | * @flags in order not to receive plane update notifications related to a |
| 1737 | * disabled CRTC. This avoids the need to manually ignore plane updates in |
Daniel Vetter | 6e48ae3 | 2015-09-08 13:52:45 +0200 | [diff] [blame] | 1738 | * driver code when the driver and/or hardware can't or just don't need to deal |
| 1739 | * with updates on disabled CRTCs, for example when supporting runtime PM. |
| 1740 | * |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 1741 | * Drivers may set the NO_DISABLE_AFTER_MODESET flag in @flags if the relevant |
| 1742 | * display controllers require to disable a CRTC's planes when the CRTC is |
| 1743 | * disabled. This function would skip the ->atomic_disable call for a plane if |
| 1744 | * the CRTC of the old plane state needs a modesetting operation. Of course, |
| 1745 | * the drivers need to disable the planes in their CRTC disable callbacks |
| 1746 | * since no one else would do that. |
| 1747 | * |
| 1748 | * The drm_atomic_helper_commit() default implementation doesn't set the |
| 1749 | * ACTIVE_ONLY flag to most closely match the behaviour of the legacy helpers. |
| 1750 | * This should not be copied blindly by drivers. |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1751 | */ |
| 1752 | void drm_atomic_helper_commit_planes(struct drm_device *dev, |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 1753 | struct drm_atomic_state *old_state, |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 1754 | uint32_t flags) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1755 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1756 | struct drm_crtc *crtc; |
| 1757 | struct drm_crtc_state *old_crtc_state; |
| 1758 | struct drm_plane *plane; |
| 1759 | struct drm_plane_state *old_plane_state; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1760 | int i; |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 1761 | bool active_only = flags & DRM_PLANE_COMMIT_ACTIVE_ONLY; |
| 1762 | bool no_disable = flags & DRM_PLANE_COMMIT_NO_DISABLE_AFTER_MODESET; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1763 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1764 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1765 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1766 | |
| 1767 | funcs = crtc->helper_private; |
| 1768 | |
| 1769 | if (!funcs || !funcs->atomic_begin) |
| 1770 | continue; |
| 1771 | |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 1772 | if (active_only && !crtc->state->active) |
| 1773 | continue; |
| 1774 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 1775 | funcs->atomic_begin(crtc, old_crtc_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1776 | } |
| 1777 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1778 | for_each_plane_in_state(old_state, plane, old_plane_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1779 | const struct drm_plane_helper_funcs *funcs; |
Laurent Pinchart | 216c59d | 2015-09-11 00:07:19 +0300 | [diff] [blame] | 1780 | bool disabling; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1781 | |
| 1782 | funcs = plane->helper_private; |
| 1783 | |
Thierry Reding | 3cad4b6 | 2014-11-25 13:05:12 +0100 | [diff] [blame] | 1784 | if (!funcs) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1785 | continue; |
| 1786 | |
Laurent Pinchart | 216c59d | 2015-09-11 00:07:19 +0300 | [diff] [blame] | 1787 | disabling = drm_atomic_plane_disabling(plane, old_plane_state); |
| 1788 | |
| 1789 | if (active_only) { |
| 1790 | /* |
| 1791 | * Skip planes related to inactive CRTCs. If the plane |
| 1792 | * is enabled use the state of the current CRTC. If the |
| 1793 | * plane is being disabled use the state of the old |
| 1794 | * CRTC to avoid skipping planes being disabled on an |
| 1795 | * active CRTC. |
| 1796 | */ |
| 1797 | if (!disabling && !plane_crtc_active(plane->state)) |
| 1798 | continue; |
| 1799 | if (disabling && !plane_crtc_active(old_plane_state)) |
| 1800 | continue; |
| 1801 | } |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 1802 | |
Thierry Reding | 407b8bd | 2014-11-20 12:05:50 +0100 | [diff] [blame] | 1803 | /* |
| 1804 | * Special-case disabling the plane if drivers support it. |
| 1805 | */ |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 1806 | if (disabling && funcs->atomic_disable) { |
| 1807 | struct drm_crtc_state *crtc_state; |
| 1808 | |
| 1809 | crtc_state = old_plane_state->crtc->state; |
| 1810 | |
| 1811 | if (drm_atomic_crtc_needs_modeset(crtc_state) && |
| 1812 | no_disable) |
| 1813 | continue; |
| 1814 | |
Thierry Reding | 407b8bd | 2014-11-20 12:05:50 +0100 | [diff] [blame] | 1815 | funcs->atomic_disable(plane, old_plane_state); |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 1816 | } else if (plane->state->crtc || disabling) { |
Thierry Reding | 407b8bd | 2014-11-20 12:05:50 +0100 | [diff] [blame] | 1817 | funcs->atomic_update(plane, old_plane_state); |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 1818 | } |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1819 | } |
| 1820 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1821 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1822 | const struct drm_crtc_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1823 | |
| 1824 | funcs = crtc->helper_private; |
| 1825 | |
| 1826 | if (!funcs || !funcs->atomic_flush) |
| 1827 | continue; |
| 1828 | |
Daniel Vetter | aef9dbb | 2015-09-08 12:02:07 +0200 | [diff] [blame] | 1829 | if (active_only && !crtc->state->active) |
| 1830 | continue; |
| 1831 | |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 1832 | funcs->atomic_flush(crtc, old_crtc_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1833 | } |
| 1834 | } |
| 1835 | EXPORT_SYMBOL(drm_atomic_helper_commit_planes); |
| 1836 | |
| 1837 | /** |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 1838 | * drm_atomic_helper_commit_planes_on_crtc - commit plane state for a crtc |
| 1839 | * @old_crtc_state: atomic state object with the old crtc state |
| 1840 | * |
| 1841 | * This function commits the new plane state using the plane and atomic helper |
| 1842 | * functions for planes on the specific crtc. It assumes that the atomic state |
| 1843 | * has already been pushed into the relevant object state pointers, since this |
| 1844 | * step can no longer fail. |
| 1845 | * |
| 1846 | * This function is useful when plane updates should be done crtc-by-crtc |
| 1847 | * instead of one global step like drm_atomic_helper_commit_planes() does. |
| 1848 | * |
| 1849 | * This function can only be savely used when planes are not allowed to move |
| 1850 | * between different CRTCs because this function doesn't handle inter-CRTC |
| 1851 | * depencies. Callers need to ensure that either no such depencies exist, |
| 1852 | * resolve them through ordering of commit calls or through some other means. |
| 1853 | */ |
| 1854 | void |
| 1855 | drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state) |
| 1856 | { |
| 1857 | const struct drm_crtc_helper_funcs *crtc_funcs; |
| 1858 | struct drm_crtc *crtc = old_crtc_state->crtc; |
| 1859 | struct drm_atomic_state *old_state = old_crtc_state->state; |
| 1860 | struct drm_plane *plane; |
| 1861 | unsigned plane_mask; |
| 1862 | |
| 1863 | plane_mask = old_crtc_state->plane_mask; |
| 1864 | plane_mask |= crtc->state->plane_mask; |
| 1865 | |
| 1866 | crtc_funcs = crtc->helper_private; |
| 1867 | if (crtc_funcs && crtc_funcs->atomic_begin) |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 1868 | crtc_funcs->atomic_begin(crtc, old_crtc_state); |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 1869 | |
| 1870 | drm_for_each_plane_mask(plane, crtc->dev, plane_mask) { |
| 1871 | struct drm_plane_state *old_plane_state = |
| 1872 | drm_atomic_get_existing_plane_state(old_state, plane); |
| 1873 | const struct drm_plane_helper_funcs *plane_funcs; |
| 1874 | |
| 1875 | plane_funcs = plane->helper_private; |
| 1876 | |
| 1877 | if (!old_plane_state || !plane_funcs) |
| 1878 | continue; |
| 1879 | |
| 1880 | WARN_ON(plane->state->crtc && plane->state->crtc != crtc); |
| 1881 | |
| 1882 | if (drm_atomic_plane_disabling(plane, old_plane_state) && |
| 1883 | plane_funcs->atomic_disable) |
| 1884 | plane_funcs->atomic_disable(plane, old_plane_state); |
| 1885 | else if (plane->state->crtc || |
| 1886 | drm_atomic_plane_disabling(plane, old_plane_state)) |
| 1887 | plane_funcs->atomic_update(plane, old_plane_state); |
| 1888 | } |
| 1889 | |
| 1890 | if (crtc_funcs && crtc_funcs->atomic_flush) |
Maarten Lankhorst | 613d2b2 | 2015-07-21 13:28:58 +0200 | [diff] [blame] | 1891 | crtc_funcs->atomic_flush(crtc, old_crtc_state); |
Maarten Lankhorst | de28d02 | 2015-05-19 16:41:01 +0200 | [diff] [blame] | 1892 | } |
| 1893 | EXPORT_SYMBOL(drm_atomic_helper_commit_planes_on_crtc); |
| 1894 | |
| 1895 | /** |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 1896 | * drm_atomic_helper_disable_planes_on_crtc - helper to disable CRTC's planes |
Liu Ying | 2850029 | 2016-08-26 15:30:39 +0800 | [diff] [blame] | 1897 | * @old_crtc_state: atomic state object with the old CRTC state |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 1898 | * @atomic: if set, synchronize with CRTC's atomic_begin/flush hooks |
| 1899 | * |
| 1900 | * Disables all planes associated with the given CRTC. This can be |
Liu Ying | 2850029 | 2016-08-26 15:30:39 +0800 | [diff] [blame] | 1901 | * used for instance in the CRTC helper atomic_disable callback to disable |
| 1902 | * all planes. |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 1903 | * |
| 1904 | * If the atomic-parameter is set the function calls the CRTC's |
| 1905 | * atomic_begin hook before and atomic_flush hook after disabling the |
| 1906 | * planes. |
| 1907 | * |
| 1908 | * It is a bug to call this function without having implemented the |
| 1909 | * ->atomic_disable() plane hook. |
| 1910 | */ |
Liu Ying | 2850029 | 2016-08-26 15:30:39 +0800 | [diff] [blame] | 1911 | void |
| 1912 | drm_atomic_helper_disable_planes_on_crtc(struct drm_crtc_state *old_crtc_state, |
| 1913 | bool atomic) |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 1914 | { |
Liu Ying | 2850029 | 2016-08-26 15:30:39 +0800 | [diff] [blame] | 1915 | struct drm_crtc *crtc = old_crtc_state->crtc; |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 1916 | const struct drm_crtc_helper_funcs *crtc_funcs = |
| 1917 | crtc->helper_private; |
| 1918 | struct drm_plane *plane; |
| 1919 | |
| 1920 | if (atomic && crtc_funcs && crtc_funcs->atomic_begin) |
| 1921 | crtc_funcs->atomic_begin(crtc, NULL); |
| 1922 | |
Liu Ying | 2850029 | 2016-08-26 15:30:39 +0800 | [diff] [blame] | 1923 | drm_atomic_crtc_state_for_each_plane(plane, old_crtc_state) { |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 1924 | const struct drm_plane_helper_funcs *plane_funcs = |
| 1925 | plane->helper_private; |
| 1926 | |
Liu Ying | 2850029 | 2016-08-26 15:30:39 +0800 | [diff] [blame] | 1927 | if (!plane_funcs) |
Jyri Sarha | 6753ba9 | 2015-11-27 16:14:01 +0200 | [diff] [blame] | 1928 | continue; |
| 1929 | |
| 1930 | WARN_ON(!plane_funcs->atomic_disable); |
| 1931 | if (plane_funcs->atomic_disable) |
| 1932 | plane_funcs->atomic_disable(plane, NULL); |
| 1933 | } |
| 1934 | |
| 1935 | if (atomic && crtc_funcs && crtc_funcs->atomic_flush) |
| 1936 | crtc_funcs->atomic_flush(crtc, NULL); |
| 1937 | } |
| 1938 | EXPORT_SYMBOL(drm_atomic_helper_disable_planes_on_crtc); |
| 1939 | |
| 1940 | /** |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1941 | * drm_atomic_helper_cleanup_planes - cleanup plane resources after commit |
| 1942 | * @dev: DRM device |
| 1943 | * @old_state: atomic state object with old state structures |
| 1944 | * |
| 1945 | * This function cleans up plane state, specifically framebuffers, from the old |
| 1946 | * configuration. Hence the old configuration must be perserved in @old_state to |
| 1947 | * be able to call this function. |
| 1948 | * |
| 1949 | * This function must also be called on the new state when the atomic update |
| 1950 | * fails at any point after calling drm_atomic_helper_prepare_planes(). |
| 1951 | */ |
| 1952 | void drm_atomic_helper_cleanup_planes(struct drm_device *dev, |
| 1953 | struct drm_atomic_state *old_state) |
| 1954 | { |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1955 | struct drm_plane *plane; |
| 1956 | struct drm_plane_state *plane_state; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1957 | int i; |
| 1958 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 1959 | for_each_plane_in_state(old_state, plane, plane_state, i) { |
Ville Syrjälä | b5ceff20 | 2015-03-10 14:35:20 +0200 | [diff] [blame] | 1960 | const struct drm_plane_helper_funcs *funcs; |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1961 | |
Keith Packard | fcc60b4 | 2016-06-04 01:16:22 -0700 | [diff] [blame] | 1962 | if (!drm_atomic_helper_framebuffer_changed(dev, old_state, plane_state->crtc)) |
| 1963 | continue; |
| 1964 | |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1965 | funcs = plane->helper_private; |
| 1966 | |
Maarten Lankhorst | 844f911 | 2015-09-02 10:42:40 +0200 | [diff] [blame] | 1967 | if (funcs->cleanup_fb) |
| 1968 | funcs->cleanup_fb(plane, plane_state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1969 | } |
| 1970 | } |
| 1971 | EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes); |
| 1972 | |
| 1973 | /** |
| 1974 | * drm_atomic_helper_swap_state - store atomic state into current sw state |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1975 | * @state: atomic state |
Daniel Vetter | 5e84c26 | 2016-06-10 00:06:32 +0200 | [diff] [blame] | 1976 | * @stall: stall for proceeding commits |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1977 | * |
| 1978 | * This function stores the atomic state into the current state pointers in all |
| 1979 | * driver objects. It should be called after all failing steps have been done |
| 1980 | * and succeeded, but before the actual hardware state is committed. |
| 1981 | * |
| 1982 | * For cleanup and error recovery the current state for all changed objects will |
| 1983 | * be swaped into @state. |
| 1984 | * |
| 1985 | * With that sequence it fits perfectly into the plane prepare/cleanup sequence: |
| 1986 | * |
| 1987 | * 1. Call drm_atomic_helper_prepare_planes() with the staged atomic state. |
| 1988 | * |
| 1989 | * 2. Do any other steps that might fail. |
| 1990 | * |
| 1991 | * 3. Put the staged state into the current state pointers with this function. |
| 1992 | * |
| 1993 | * 4. Actually commit the hardware state. |
| 1994 | * |
Daniel Vetter | 26196f7 | 2015-08-25 16:26:03 +0200 | [diff] [blame] | 1995 | * 5. Call drm_atomic_helper_cleanup_planes() with @state, which since step 3 |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 1996 | * contains the old state. Also do any other cleanup required with that state. |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 1997 | * |
| 1998 | * @stall must be set when nonblocking commits for this driver directly access |
| 1999 | * the ->state pointer of &drm_plane, &drm_crtc or &drm_connector. With the |
| 2000 | * current atomic helpers this is almost always the case, since the helpers |
| 2001 | * don't pass the right state structures to the callbacks. |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2002 | */ |
Daniel Vetter | 5e84c26 | 2016-06-10 00:06:32 +0200 | [diff] [blame] | 2003 | void drm_atomic_helper_swap_state(struct drm_atomic_state *state, |
| 2004 | bool stall) |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2005 | { |
| 2006 | int i; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2007 | long ret; |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 2008 | struct drm_connector *connector; |
| 2009 | struct drm_connector_state *conn_state; |
| 2010 | struct drm_crtc *crtc; |
| 2011 | struct drm_crtc_state *crtc_state; |
| 2012 | struct drm_plane *plane; |
| 2013 | struct drm_plane_state *plane_state; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2014 | struct drm_crtc_commit *commit; |
| 2015 | |
| 2016 | if (stall) { |
| 2017 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 2018 | spin_lock(&crtc->commit_lock); |
| 2019 | commit = list_first_entry_or_null(&crtc->commit_list, |
| 2020 | struct drm_crtc_commit, commit_entry); |
| 2021 | if (commit) |
| 2022 | drm_crtc_commit_get(commit); |
| 2023 | spin_unlock(&crtc->commit_lock); |
| 2024 | |
| 2025 | if (!commit) |
| 2026 | continue; |
| 2027 | |
| 2028 | ret = wait_for_completion_timeout(&commit->hw_done, |
| 2029 | 10*HZ); |
| 2030 | if (ret == 0) |
| 2031 | DRM_ERROR("[CRTC:%d:%s] hw_done timed out\n", |
| 2032 | crtc->base.id, crtc->name); |
| 2033 | drm_crtc_commit_put(commit); |
| 2034 | } |
| 2035 | } |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2036 | |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 2037 | for_each_connector_in_state(state, connector, conn_state, i) { |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2038 | connector->state->state = state; |
Daniel Vetter | 63e83c1 | 2016-06-02 00:06:32 +0200 | [diff] [blame] | 2039 | swap(state->connectors[i].state, connector->state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2040 | connector->state->state = NULL; |
| 2041 | } |
| 2042 | |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 2043 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2044 | crtc->state->state = state; |
Daniel Vetter | 5d943aa6 | 2016-06-02 00:06:34 +0200 | [diff] [blame] | 2045 | swap(state->crtcs[i].state, crtc->state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2046 | crtc->state->state = NULL; |
Daniel Vetter | a095caa | 2016-06-08 17:15:36 +0200 | [diff] [blame] | 2047 | |
| 2048 | if (state->crtcs[i].commit) { |
| 2049 | spin_lock(&crtc->commit_lock); |
| 2050 | list_add(&state->crtcs[i].commit->commit_entry, |
| 2051 | &crtc->commit_list); |
| 2052 | spin_unlock(&crtc->commit_lock); |
| 2053 | |
| 2054 | state->crtcs[i].commit->event = NULL; |
| 2055 | } |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2056 | } |
| 2057 | |
Daniel Vetter | be9174a | 2016-06-02 00:06:24 +0200 | [diff] [blame] | 2058 | for_each_plane_in_state(state, plane, plane_state, i) { |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2059 | plane->state->state = state; |
Daniel Vetter | b8b5342 | 2016-06-02 00:06:33 +0200 | [diff] [blame] | 2060 | swap(state->planes[i].state, plane->state); |
Daniel Vetter | c2fcd27 | 2014-11-05 00:14:14 +0100 | [diff] [blame] | 2061 | plane->state->state = NULL; |
| 2062 | } |
| 2063 | } |
| 2064 | EXPORT_SYMBOL(drm_atomic_helper_swap_state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2065 | |
| 2066 | /** |
| 2067 | * drm_atomic_helper_update_plane - Helper for primary plane update using atomic |
| 2068 | * @plane: plane object to update |
| 2069 | * @crtc: owning CRTC of owning plane |
| 2070 | * @fb: framebuffer to flip onto plane |
| 2071 | * @crtc_x: x offset of primary plane on crtc |
| 2072 | * @crtc_y: y offset of primary plane on crtc |
| 2073 | * @crtc_w: width of primary plane rectangle on crtc |
| 2074 | * @crtc_h: height of primary plane rectangle on crtc |
| 2075 | * @src_x: x offset of @fb for panning |
| 2076 | * @src_y: y offset of @fb for panning |
| 2077 | * @src_w: width of source rectangle in @fb |
| 2078 | * @src_h: height of source rectangle in @fb |
| 2079 | * |
| 2080 | * Provides a default plane update handler using the atomic driver interface. |
| 2081 | * |
| 2082 | * RETURNS: |
| 2083 | * Zero on success, error code on failure |
| 2084 | */ |
| 2085 | int drm_atomic_helper_update_plane(struct drm_plane *plane, |
| 2086 | struct drm_crtc *crtc, |
| 2087 | struct drm_framebuffer *fb, |
| 2088 | int crtc_x, int crtc_y, |
| 2089 | unsigned int crtc_w, unsigned int crtc_h, |
| 2090 | uint32_t src_x, uint32_t src_y, |
| 2091 | uint32_t src_w, uint32_t src_h) |
| 2092 | { |
| 2093 | struct drm_atomic_state *state; |
| 2094 | struct drm_plane_state *plane_state; |
| 2095 | int ret = 0; |
| 2096 | |
| 2097 | state = drm_atomic_state_alloc(plane->dev); |
| 2098 | if (!state) |
| 2099 | return -ENOMEM; |
| 2100 | |
| 2101 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 2102 | retry: |
| 2103 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 2104 | if (IS_ERR(plane_state)) { |
| 2105 | ret = PTR_ERR(plane_state); |
| 2106 | goto fail; |
| 2107 | } |
| 2108 | |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 2109 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2110 | if (ret != 0) |
| 2111 | goto fail; |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 2112 | drm_atomic_set_fb_for_plane(plane_state, fb); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2113 | plane_state->crtc_x = crtc_x; |
| 2114 | plane_state->crtc_y = crtc_y; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2115 | plane_state->crtc_w = crtc_w; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 2116 | plane_state->crtc_h = crtc_h; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2117 | plane_state->src_x = src_x; |
| 2118 | plane_state->src_y = src_y; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2119 | plane_state->src_w = src_w; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 2120 | plane_state->src_h = src_h; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2121 | |
Daniel Vetter | 3671c58 | 2015-05-04 15:40:52 +0200 | [diff] [blame] | 2122 | if (plane == crtc->cursor) |
| 2123 | state->legacy_cursor_update = true; |
| 2124 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2125 | ret = drm_atomic_commit(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2126 | fail: |
| 2127 | if (ret == -EDEADLK) |
| 2128 | goto backoff; |
| 2129 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2130 | drm_atomic_state_put(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2131 | return ret; |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2132 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2133 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2134 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 2135 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2136 | |
| 2137 | /* |
| 2138 | * Someone might have exchanged the framebuffer while we dropped locks |
| 2139 | * in the backoff code. We need to fix up the fb refcount tracking the |
| 2140 | * core does for us. |
| 2141 | */ |
| 2142 | plane->old_fb = plane->fb; |
| 2143 | |
| 2144 | goto retry; |
| 2145 | } |
| 2146 | EXPORT_SYMBOL(drm_atomic_helper_update_plane); |
| 2147 | |
| 2148 | /** |
| 2149 | * drm_atomic_helper_disable_plane - Helper for primary plane disable using * atomic |
| 2150 | * @plane: plane to disable |
| 2151 | * |
| 2152 | * Provides a default plane disable handler using the atomic driver interface. |
| 2153 | * |
| 2154 | * RETURNS: |
| 2155 | * Zero on success, error code on failure |
| 2156 | */ |
| 2157 | int drm_atomic_helper_disable_plane(struct drm_plane *plane) |
| 2158 | { |
| 2159 | struct drm_atomic_state *state; |
| 2160 | struct drm_plane_state *plane_state; |
| 2161 | int ret = 0; |
| 2162 | |
Jasper St. Pierre | aa54e2e | 2014-11-20 19:59:15 -0800 | [diff] [blame] | 2163 | /* |
| 2164 | * FIXME: Without plane->crtc set we can't get at the implicit legacy |
| 2165 | * acquire context. The real fix will be to wire the acquire ctx through |
| 2166 | * everywhere we need it, but meanwhile prevent chaos by just skipping |
| 2167 | * this noop. The critical case is the cursor ioctls which a) only grab |
| 2168 | * crtc/cursor-plane locks (so we need the crtc to get at the right |
| 2169 | * acquire context) and b) can try to disable the plane multiple times. |
| 2170 | */ |
| 2171 | if (!plane->crtc) |
| 2172 | return 0; |
| 2173 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2174 | state = drm_atomic_state_alloc(plane->dev); |
| 2175 | if (!state) |
| 2176 | return -ENOMEM; |
| 2177 | |
| 2178 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(plane->crtc); |
| 2179 | retry: |
| 2180 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 2181 | if (IS_ERR(plane_state)) { |
| 2182 | ret = PTR_ERR(plane_state); |
| 2183 | goto fail; |
| 2184 | } |
| 2185 | |
Maarten Lankhorst | 24e79d0 | 2015-11-11 11:29:07 +0100 | [diff] [blame] | 2186 | if (plane_state->crtc && (plane == plane->crtc->cursor)) |
| 2187 | plane_state->state->legacy_cursor_update = true; |
| 2188 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2189 | ret = __drm_atomic_helper_disable_plane(plane, plane_state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2190 | if (ret != 0) |
| 2191 | goto fail; |
Daniel Vetter | f02ad90 | 2015-01-22 16:36:23 +0100 | [diff] [blame] | 2192 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2193 | ret = drm_atomic_commit(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2194 | fail: |
| 2195 | if (ret == -EDEADLK) |
| 2196 | goto backoff; |
| 2197 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2198 | drm_atomic_state_put(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2199 | return ret; |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2200 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2201 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2202 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 2203 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2204 | |
| 2205 | /* |
| 2206 | * Someone might have exchanged the framebuffer while we dropped locks |
| 2207 | * in the backoff code. We need to fix up the fb refcount tracking the |
| 2208 | * core does for us. |
| 2209 | */ |
| 2210 | plane->old_fb = plane->fb; |
| 2211 | |
| 2212 | goto retry; |
| 2213 | } |
| 2214 | EXPORT_SYMBOL(drm_atomic_helper_disable_plane); |
| 2215 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2216 | /* just used from fb-helper and atomic-helper: */ |
| 2217 | int __drm_atomic_helper_disable_plane(struct drm_plane *plane, |
| 2218 | struct drm_plane_state *plane_state) |
| 2219 | { |
| 2220 | int ret; |
| 2221 | |
| 2222 | ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); |
| 2223 | if (ret != 0) |
| 2224 | return ret; |
| 2225 | |
| 2226 | drm_atomic_set_fb_for_plane(plane_state, NULL); |
| 2227 | plane_state->crtc_x = 0; |
| 2228 | plane_state->crtc_y = 0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2229 | plane_state->crtc_w = 0; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 2230 | plane_state->crtc_h = 0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2231 | plane_state->src_x = 0; |
| 2232 | plane_state->src_y = 0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2233 | plane_state->src_w = 0; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 2234 | plane_state->src_h = 0; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2235 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2236 | return 0; |
| 2237 | } |
| 2238 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2239 | static int update_output_state(struct drm_atomic_state *state, |
| 2240 | struct drm_mode_set *set) |
| 2241 | { |
| 2242 | struct drm_device *dev = set->crtc->dev; |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 2243 | struct drm_crtc *crtc; |
| 2244 | struct drm_crtc_state *crtc_state; |
| 2245 | struct drm_connector *connector; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2246 | struct drm_connector_state *conn_state; |
Maarten Lankhorst | 6ab520a | 2016-02-24 09:37:28 +0100 | [diff] [blame] | 2247 | int ret, i; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2248 | |
| 2249 | ret = drm_modeset_lock(&dev->mode_config.connection_mutex, |
| 2250 | state->acquire_ctx); |
| 2251 | if (ret) |
| 2252 | return ret; |
| 2253 | |
Maarten Lankhorst | 6ab520a | 2016-02-24 09:37:28 +0100 | [diff] [blame] | 2254 | /* First disable all connectors on the target crtc. */ |
| 2255 | ret = drm_atomic_add_affected_connectors(state, set->crtc); |
| 2256 | if (ret) |
| 2257 | return ret; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2258 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 2259 | for_each_connector_in_state(state, connector, conn_state, i) { |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2260 | if (conn_state->crtc == set->crtc) { |
| 2261 | ret = drm_atomic_set_crtc_for_connector(conn_state, |
| 2262 | NULL); |
| 2263 | if (ret) |
| 2264 | return ret; |
| 2265 | } |
Maarten Lankhorst | 6ab520a | 2016-02-24 09:37:28 +0100 | [diff] [blame] | 2266 | } |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2267 | |
Maarten Lankhorst | 6ab520a | 2016-02-24 09:37:28 +0100 | [diff] [blame] | 2268 | /* Then set all connectors from set->connectors on the target crtc */ |
| 2269 | for (i = 0; i < set->num_connectors; i++) { |
| 2270 | conn_state = drm_atomic_get_connector_state(state, |
| 2271 | set->connectors[i]); |
| 2272 | if (IS_ERR(conn_state)) |
| 2273 | return PTR_ERR(conn_state); |
| 2274 | |
| 2275 | ret = drm_atomic_set_crtc_for_connector(conn_state, |
| 2276 | set->crtc); |
| 2277 | if (ret) |
| 2278 | return ret; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2279 | } |
| 2280 | |
Ander Conselvan de Oliveira | df63b99 | 2015-04-10 14:58:39 +0300 | [diff] [blame] | 2281 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2282 | /* Don't update ->enable for the CRTC in the set_config request, |
| 2283 | * since a mismatch would indicate a bug in the upper layers. |
| 2284 | * The actual modeset code later on will catch any |
| 2285 | * inconsistencies here. */ |
| 2286 | if (crtc == set->crtc) |
| 2287 | continue; |
| 2288 | |
Maarten Lankhorst | 14de6c4 | 2016-01-04 12:53:20 +0100 | [diff] [blame] | 2289 | if (!crtc_state->connector_mask) { |
Laurent Pinchart | c30f55a | 2015-06-22 13:37:46 +0300 | [diff] [blame] | 2290 | ret = drm_atomic_set_mode_prop_for_crtc(crtc_state, |
| 2291 | NULL); |
| 2292 | if (ret < 0) |
| 2293 | return ret; |
| 2294 | |
Maarten Lankhorst | 9b5edbf | 2015-06-01 08:59:53 +0200 | [diff] [blame] | 2295 | crtc_state->active = false; |
Laurent Pinchart | c30f55a | 2015-06-22 13:37:46 +0300 | [diff] [blame] | 2296 | } |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2297 | } |
| 2298 | |
| 2299 | return 0; |
| 2300 | } |
| 2301 | |
| 2302 | /** |
| 2303 | * drm_atomic_helper_set_config - set a new config from userspace |
| 2304 | * @set: mode set configuration |
| 2305 | * |
| 2306 | * Provides a default crtc set_config handler using the atomic driver interface. |
| 2307 | * |
| 2308 | * Returns: |
| 2309 | * Returns 0 on success, negative errno numbers on failure. |
| 2310 | */ |
| 2311 | int drm_atomic_helper_set_config(struct drm_mode_set *set) |
| 2312 | { |
| 2313 | struct drm_atomic_state *state; |
| 2314 | struct drm_crtc *crtc = set->crtc; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2315 | int ret = 0; |
| 2316 | |
| 2317 | state = drm_atomic_state_alloc(crtc->dev); |
| 2318 | if (!state) |
| 2319 | return -ENOMEM; |
| 2320 | |
Maarten Lankhorst | 40616a2 | 2016-03-03 10:17:39 +0100 | [diff] [blame] | 2321 | state->legacy_set_config = true; |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2322 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 2323 | retry: |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2324 | ret = __drm_atomic_helper_set_config(set, state); |
Daniel Stone | 819364d | 2015-05-26 14:36:48 +0100 | [diff] [blame] | 2325 | if (ret != 0) |
| 2326 | goto fail; |
| 2327 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2328 | ret = drm_atomic_commit(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2329 | fail: |
| 2330 | if (ret == -EDEADLK) |
| 2331 | goto backoff; |
| 2332 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2333 | drm_atomic_state_put(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2334 | return ret; |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2335 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2336 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2337 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 2338 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2339 | |
| 2340 | /* |
| 2341 | * Someone might have exchanged the framebuffer while we dropped locks |
| 2342 | * in the backoff code. We need to fix up the fb refcount tracking the |
| 2343 | * core does for us. |
| 2344 | */ |
| 2345 | crtc->primary->old_fb = crtc->primary->fb; |
| 2346 | |
| 2347 | goto retry; |
| 2348 | } |
| 2349 | EXPORT_SYMBOL(drm_atomic_helper_set_config); |
| 2350 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2351 | /* just used from fb-helper and atomic-helper: */ |
| 2352 | int __drm_atomic_helper_set_config(struct drm_mode_set *set, |
| 2353 | struct drm_atomic_state *state) |
| 2354 | { |
| 2355 | struct drm_crtc_state *crtc_state; |
| 2356 | struct drm_plane_state *primary_state; |
| 2357 | struct drm_crtc *crtc = set->crtc; |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 2358 | int hdisplay, vdisplay; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2359 | int ret; |
| 2360 | |
| 2361 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 2362 | if (IS_ERR(crtc_state)) |
| 2363 | return PTR_ERR(crtc_state); |
| 2364 | |
| 2365 | primary_state = drm_atomic_get_plane_state(state, crtc->primary); |
| 2366 | if (IS_ERR(primary_state)) |
| 2367 | return PTR_ERR(primary_state); |
| 2368 | |
| 2369 | if (!set->mode) { |
| 2370 | WARN_ON(set->fb); |
| 2371 | WARN_ON(set->num_connectors); |
| 2372 | |
| 2373 | ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL); |
| 2374 | if (ret != 0) |
| 2375 | return ret; |
| 2376 | |
| 2377 | crtc_state->active = false; |
| 2378 | |
| 2379 | ret = drm_atomic_set_crtc_for_plane(primary_state, NULL); |
| 2380 | if (ret != 0) |
| 2381 | return ret; |
| 2382 | |
| 2383 | drm_atomic_set_fb_for_plane(primary_state, NULL); |
| 2384 | |
| 2385 | goto commit; |
| 2386 | } |
| 2387 | |
| 2388 | WARN_ON(!set->fb); |
| 2389 | WARN_ON(!set->num_connectors); |
| 2390 | |
| 2391 | ret = drm_atomic_set_mode_for_crtc(crtc_state, set->mode); |
| 2392 | if (ret != 0) |
| 2393 | return ret; |
| 2394 | |
| 2395 | crtc_state->active = true; |
| 2396 | |
| 2397 | ret = drm_atomic_set_crtc_for_plane(primary_state, crtc); |
| 2398 | if (ret != 0) |
| 2399 | return ret; |
| 2400 | |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 2401 | drm_crtc_get_hv_timing(set->mode, &hdisplay, &vdisplay); |
| 2402 | |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2403 | drm_atomic_set_fb_for_plane(primary_state, set->fb); |
| 2404 | primary_state->crtc_x = 0; |
| 2405 | primary_state->crtc_y = 0; |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 2406 | primary_state->crtc_w = hdisplay; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 2407 | primary_state->crtc_h = vdisplay; |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2408 | primary_state->src_x = set->x << 16; |
| 2409 | primary_state->src_y = set->y << 16; |
Ville Syrjälä | bd2ef25 | 2016-09-26 19:30:46 +0300 | [diff] [blame] | 2410 | if (drm_rotation_90_or_270(primary_state->rotation)) { |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 2411 | primary_state->src_w = vdisplay << 16; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 2412 | primary_state->src_h = hdisplay << 16; |
Ville Syrjälä | 4112124 | 2015-10-15 20:39:59 +0300 | [diff] [blame] | 2413 | } else { |
Ville Syrjälä | 8392611 | 2015-11-16 17:02:34 +0200 | [diff] [blame] | 2414 | primary_state->src_w = hdisplay << 16; |
Ville Syrjälä | 02e6f37 | 2015-11-16 17:02:35 +0200 | [diff] [blame] | 2415 | primary_state->src_h = vdisplay << 16; |
Ville Syrjälä | 4112124 | 2015-10-15 20:39:59 +0300 | [diff] [blame] | 2416 | } |
Rob Clark | bbb1e52 | 2015-08-25 15:35:58 -0400 | [diff] [blame] | 2417 | |
| 2418 | commit: |
| 2419 | ret = update_output_state(state, set); |
| 2420 | if (ret) |
| 2421 | return ret; |
| 2422 | |
| 2423 | return 0; |
| 2424 | } |
| 2425 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2426 | /** |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 2427 | * drm_atomic_helper_disable_all - disable all currently active outputs |
| 2428 | * @dev: DRM device |
| 2429 | * @ctx: lock acquisition context |
| 2430 | * |
| 2431 | * Loops through all connectors, finding those that aren't turned off and then |
| 2432 | * turns them off by setting their DPMS mode to OFF and deactivating the CRTC |
| 2433 | * that they are connected to. |
| 2434 | * |
| 2435 | * This is used for example in suspend/resume to disable all currently active |
| 2436 | * functions when suspending. |
| 2437 | * |
| 2438 | * Note that if callers haven't already acquired all modeset locks this might |
| 2439 | * return -EDEADLK, which must be handled by calling drm_modeset_backoff(). |
| 2440 | * |
| 2441 | * Returns: |
| 2442 | * 0 on success or a negative error code on failure. |
| 2443 | * |
| 2444 | * See also: |
| 2445 | * drm_atomic_helper_suspend(), drm_atomic_helper_resume() |
| 2446 | */ |
| 2447 | int drm_atomic_helper_disable_all(struct drm_device *dev, |
| 2448 | struct drm_modeset_acquire_ctx *ctx) |
| 2449 | { |
| 2450 | struct drm_atomic_state *state; |
| 2451 | struct drm_connector *conn; |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 2452 | struct drm_connector_list_iter conn_iter; |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 2453 | int err; |
| 2454 | |
| 2455 | state = drm_atomic_state_alloc(dev); |
| 2456 | if (!state) |
| 2457 | return -ENOMEM; |
| 2458 | |
| 2459 | state->acquire_ctx = ctx; |
| 2460 | |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 2461 | drm_connector_list_iter_get(dev, &conn_iter); |
| 2462 | drm_for_each_connector_iter(conn, &conn_iter) { |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 2463 | struct drm_crtc *crtc = conn->state->crtc; |
| 2464 | struct drm_crtc_state *crtc_state; |
| 2465 | |
| 2466 | if (!crtc || conn->dpms != DRM_MODE_DPMS_ON) |
| 2467 | continue; |
| 2468 | |
| 2469 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 2470 | if (IS_ERR(crtc_state)) { |
| 2471 | err = PTR_ERR(crtc_state); |
| 2472 | goto free; |
| 2473 | } |
| 2474 | |
| 2475 | crtc_state->active = false; |
| 2476 | } |
| 2477 | |
| 2478 | err = drm_atomic_commit(state); |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 2479 | free: |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 2480 | drm_connector_list_iter_put(&conn_iter); |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2481 | drm_atomic_state_put(state); |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 2482 | return err; |
| 2483 | } |
| 2484 | EXPORT_SYMBOL(drm_atomic_helper_disable_all); |
| 2485 | |
| 2486 | /** |
| 2487 | * drm_atomic_helper_suspend - subsystem-level suspend helper |
| 2488 | * @dev: DRM device |
| 2489 | * |
| 2490 | * Duplicates the current atomic state, disables all active outputs and then |
| 2491 | * returns a pointer to the original atomic state to the caller. Drivers can |
| 2492 | * pass this pointer to the drm_atomic_helper_resume() helper upon resume to |
| 2493 | * restore the output configuration that was active at the time the system |
| 2494 | * entered suspend. |
| 2495 | * |
| 2496 | * Note that it is potentially unsafe to use this. The atomic state object |
| 2497 | * returned by this function is assumed to be persistent. Drivers must ensure |
| 2498 | * that this holds true. Before calling this function, drivers must make sure |
| 2499 | * to suspend fbdev emulation so that nothing can be using the device. |
| 2500 | * |
| 2501 | * Returns: |
| 2502 | * A pointer to a copy of the state before suspend on success or an ERR_PTR()- |
| 2503 | * encoded error code on failure. Drivers should store the returned atomic |
| 2504 | * state object and pass it to the drm_atomic_helper_resume() helper upon |
| 2505 | * resume. |
| 2506 | * |
| 2507 | * See also: |
| 2508 | * drm_atomic_helper_duplicate_state(), drm_atomic_helper_disable_all(), |
| 2509 | * drm_atomic_helper_resume() |
| 2510 | */ |
| 2511 | struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev) |
| 2512 | { |
| 2513 | struct drm_modeset_acquire_ctx ctx; |
| 2514 | struct drm_atomic_state *state; |
| 2515 | int err; |
| 2516 | |
| 2517 | drm_modeset_acquire_init(&ctx, 0); |
| 2518 | |
| 2519 | retry: |
| 2520 | err = drm_modeset_lock_all_ctx(dev, &ctx); |
| 2521 | if (err < 0) { |
| 2522 | state = ERR_PTR(err); |
| 2523 | goto unlock; |
| 2524 | } |
| 2525 | |
| 2526 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
| 2527 | if (IS_ERR(state)) |
| 2528 | goto unlock; |
| 2529 | |
| 2530 | err = drm_atomic_helper_disable_all(dev, &ctx); |
| 2531 | if (err < 0) { |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2532 | drm_atomic_state_put(state); |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 2533 | state = ERR_PTR(err); |
| 2534 | goto unlock; |
| 2535 | } |
| 2536 | |
| 2537 | unlock: |
| 2538 | if (PTR_ERR(state) == -EDEADLK) { |
| 2539 | drm_modeset_backoff(&ctx); |
| 2540 | goto retry; |
| 2541 | } |
| 2542 | |
| 2543 | drm_modeset_drop_locks(&ctx); |
| 2544 | drm_modeset_acquire_fini(&ctx); |
| 2545 | return state; |
| 2546 | } |
| 2547 | EXPORT_SYMBOL(drm_atomic_helper_suspend); |
| 2548 | |
| 2549 | /** |
| 2550 | * drm_atomic_helper_resume - subsystem-level resume helper |
| 2551 | * @dev: DRM device |
| 2552 | * @state: atomic state to resume to |
| 2553 | * |
| 2554 | * Calls drm_mode_config_reset() to synchronize hardware and software states, |
| 2555 | * grabs all modeset locks and commits the atomic state object. This can be |
| 2556 | * used in conjunction with the drm_atomic_helper_suspend() helper to |
| 2557 | * implement suspend/resume for drivers that support atomic mode-setting. |
| 2558 | * |
| 2559 | * Returns: |
| 2560 | * 0 on success or a negative error code on failure. |
| 2561 | * |
| 2562 | * See also: |
| 2563 | * drm_atomic_helper_suspend() |
| 2564 | */ |
| 2565 | int drm_atomic_helper_resume(struct drm_device *dev, |
| 2566 | struct drm_atomic_state *state) |
| 2567 | { |
| 2568 | struct drm_mode_config *config = &dev->mode_config; |
| 2569 | int err; |
| 2570 | |
| 2571 | drm_mode_config_reset(dev); |
| 2572 | drm_modeset_lock_all(dev); |
| 2573 | state->acquire_ctx = config->acquire_ctx; |
| 2574 | err = drm_atomic_commit(state); |
| 2575 | drm_modeset_unlock_all(dev); |
| 2576 | |
| 2577 | return err; |
| 2578 | } |
| 2579 | EXPORT_SYMBOL(drm_atomic_helper_resume); |
| 2580 | |
| 2581 | /** |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 2582 | * drm_atomic_helper_crtc_set_property - helper for crtc properties |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2583 | * @crtc: DRM crtc |
| 2584 | * @property: DRM property |
| 2585 | * @val: value of property |
| 2586 | * |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 2587 | * Provides a default crtc set_property handler using the atomic driver |
| 2588 | * interface. |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2589 | * |
| 2590 | * RETURNS: |
| 2591 | * Zero on success, error code on failure |
| 2592 | */ |
| 2593 | int |
| 2594 | drm_atomic_helper_crtc_set_property(struct drm_crtc *crtc, |
| 2595 | struct drm_property *property, |
| 2596 | uint64_t val) |
| 2597 | { |
| 2598 | struct drm_atomic_state *state; |
| 2599 | struct drm_crtc_state *crtc_state; |
| 2600 | int ret = 0; |
| 2601 | |
| 2602 | state = drm_atomic_state_alloc(crtc->dev); |
| 2603 | if (!state) |
| 2604 | return -ENOMEM; |
| 2605 | |
| 2606 | /* ->set_property is always called with all locks held. */ |
| 2607 | state->acquire_ctx = crtc->dev->mode_config.acquire_ctx; |
| 2608 | retry: |
| 2609 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 2610 | if (IS_ERR(crtc_state)) { |
| 2611 | ret = PTR_ERR(crtc_state); |
| 2612 | goto fail; |
| 2613 | } |
| 2614 | |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 2615 | ret = drm_atomic_crtc_set_property(crtc, crtc_state, |
| 2616 | property, val); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2617 | if (ret) |
| 2618 | goto fail; |
| 2619 | |
| 2620 | ret = drm_atomic_commit(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2621 | fail: |
| 2622 | if (ret == -EDEADLK) |
| 2623 | goto backoff; |
| 2624 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2625 | drm_atomic_state_put(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2626 | return ret; |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2627 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2628 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2629 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 2630 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2631 | |
| 2632 | goto retry; |
| 2633 | } |
| 2634 | EXPORT_SYMBOL(drm_atomic_helper_crtc_set_property); |
| 2635 | |
| 2636 | /** |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 2637 | * drm_atomic_helper_plane_set_property - helper for plane properties |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2638 | * @plane: DRM plane |
| 2639 | * @property: DRM property |
| 2640 | * @val: value of property |
| 2641 | * |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 2642 | * Provides a default plane set_property handler using the atomic driver |
| 2643 | * interface. |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2644 | * |
| 2645 | * RETURNS: |
| 2646 | * Zero on success, error code on failure |
| 2647 | */ |
| 2648 | int |
| 2649 | drm_atomic_helper_plane_set_property(struct drm_plane *plane, |
| 2650 | struct drm_property *property, |
| 2651 | uint64_t val) |
| 2652 | { |
| 2653 | struct drm_atomic_state *state; |
| 2654 | struct drm_plane_state *plane_state; |
| 2655 | int ret = 0; |
| 2656 | |
| 2657 | state = drm_atomic_state_alloc(plane->dev); |
| 2658 | if (!state) |
| 2659 | return -ENOMEM; |
| 2660 | |
| 2661 | /* ->set_property is always called with all locks held. */ |
| 2662 | state->acquire_ctx = plane->dev->mode_config.acquire_ctx; |
| 2663 | retry: |
| 2664 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 2665 | if (IS_ERR(plane_state)) { |
| 2666 | ret = PTR_ERR(plane_state); |
| 2667 | goto fail; |
| 2668 | } |
| 2669 | |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 2670 | ret = drm_atomic_plane_set_property(plane, plane_state, |
| 2671 | property, val); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2672 | if (ret) |
| 2673 | goto fail; |
| 2674 | |
| 2675 | ret = drm_atomic_commit(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2676 | fail: |
| 2677 | if (ret == -EDEADLK) |
| 2678 | goto backoff; |
| 2679 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2680 | drm_atomic_state_put(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2681 | return ret; |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2682 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2683 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2684 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 2685 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2686 | |
| 2687 | goto retry; |
| 2688 | } |
| 2689 | EXPORT_SYMBOL(drm_atomic_helper_plane_set_property); |
| 2690 | |
| 2691 | /** |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 2692 | * drm_atomic_helper_connector_set_property - helper for connector properties |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2693 | * @connector: DRM connector |
| 2694 | * @property: DRM property |
| 2695 | * @val: value of property |
| 2696 | * |
Laurent Pinchart | 7f50002 | 2015-02-23 02:50:23 +0200 | [diff] [blame] | 2697 | * Provides a default connector set_property handler using the atomic driver |
| 2698 | * interface. |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2699 | * |
| 2700 | * RETURNS: |
| 2701 | * Zero on success, error code on failure |
| 2702 | */ |
| 2703 | int |
| 2704 | drm_atomic_helper_connector_set_property(struct drm_connector *connector, |
| 2705 | struct drm_property *property, |
| 2706 | uint64_t val) |
| 2707 | { |
| 2708 | struct drm_atomic_state *state; |
| 2709 | struct drm_connector_state *connector_state; |
| 2710 | int ret = 0; |
| 2711 | |
| 2712 | state = drm_atomic_state_alloc(connector->dev); |
| 2713 | if (!state) |
| 2714 | return -ENOMEM; |
| 2715 | |
| 2716 | /* ->set_property is always called with all locks held. */ |
| 2717 | state->acquire_ctx = connector->dev->mode_config.acquire_ctx; |
| 2718 | retry: |
| 2719 | connector_state = drm_atomic_get_connector_state(state, connector); |
| 2720 | if (IS_ERR(connector_state)) { |
| 2721 | ret = PTR_ERR(connector_state); |
| 2722 | goto fail; |
| 2723 | } |
| 2724 | |
Rob Clark | 40ecc69 | 2014-12-18 16:01:46 -0500 | [diff] [blame] | 2725 | ret = drm_atomic_connector_set_property(connector, connector_state, |
| 2726 | property, val); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2727 | if (ret) |
| 2728 | goto fail; |
| 2729 | |
| 2730 | ret = drm_atomic_commit(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2731 | fail: |
| 2732 | if (ret == -EDEADLK) |
| 2733 | goto backoff; |
| 2734 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2735 | drm_atomic_state_put(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2736 | return ret; |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2737 | |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2738 | backoff: |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2739 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 2740 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 042652e | 2014-07-27 13:46:52 +0200 | [diff] [blame] | 2741 | |
| 2742 | goto retry; |
| 2743 | } |
| 2744 | EXPORT_SYMBOL(drm_atomic_helper_connector_set_property); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2745 | |
| 2746 | /** |
| 2747 | * drm_atomic_helper_page_flip - execute a legacy page flip |
| 2748 | * @crtc: DRM crtc |
| 2749 | * @fb: DRM framebuffer |
| 2750 | * @event: optional DRM event to signal upon completion |
| 2751 | * @flags: flip flags for non-vblank sync'ed updates |
| 2752 | * |
| 2753 | * Provides a default page flip implementation using the atomic driver interface. |
| 2754 | * |
| 2755 | * Note that for now so called async page flips (i.e. updates which are not |
| 2756 | * synchronized to vblank) are not supported, since the atomic interfaces have |
| 2757 | * no provisions for this yet. |
| 2758 | * |
| 2759 | * Returns: |
| 2760 | * Returns 0 on success, negative errno numbers on failure. |
| 2761 | */ |
| 2762 | int drm_atomic_helper_page_flip(struct drm_crtc *crtc, |
| 2763 | struct drm_framebuffer *fb, |
| 2764 | struct drm_pending_vblank_event *event, |
| 2765 | uint32_t flags) |
| 2766 | { |
| 2767 | struct drm_plane *plane = crtc->primary; |
| 2768 | struct drm_atomic_state *state; |
| 2769 | struct drm_plane_state *plane_state; |
| 2770 | struct drm_crtc_state *crtc_state; |
| 2771 | int ret = 0; |
| 2772 | |
| 2773 | if (flags & DRM_MODE_PAGE_FLIP_ASYNC) |
| 2774 | return -EINVAL; |
| 2775 | |
| 2776 | state = drm_atomic_state_alloc(plane->dev); |
| 2777 | if (!state) |
| 2778 | return -ENOMEM; |
| 2779 | |
| 2780 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 2781 | retry: |
| 2782 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 2783 | if (IS_ERR(crtc_state)) { |
| 2784 | ret = PTR_ERR(crtc_state); |
| 2785 | goto fail; |
| 2786 | } |
| 2787 | crtc_state->event = event; |
| 2788 | |
| 2789 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 2790 | if (IS_ERR(plane_state)) { |
| 2791 | ret = PTR_ERR(plane_state); |
| 2792 | goto fail; |
| 2793 | } |
| 2794 | |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 2795 | ret = drm_atomic_set_crtc_for_plane(plane_state, crtc); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2796 | if (ret != 0) |
| 2797 | goto fail; |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 2798 | drm_atomic_set_fb_for_plane(plane_state, fb); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2799 | |
Daniel Vetter | 4cba685 | 2015-12-08 09:49:20 +0100 | [diff] [blame] | 2800 | /* Make sure we don't accidentally do a full modeset. */ |
| 2801 | state->allow_modeset = false; |
| 2802 | if (!crtc_state->active) { |
| 2803 | DRM_DEBUG_ATOMIC("[CRTC:%d] disabled, rejecting legacy flip\n", |
| 2804 | crtc->base.id); |
| 2805 | ret = -EINVAL; |
| 2806 | goto fail; |
| 2807 | } |
| 2808 | |
Maarten Lankhorst | b837ba0 | 2016-04-26 16:11:35 +0200 | [diff] [blame] | 2809 | ret = drm_atomic_nonblocking_commit(state); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2810 | fail: |
| 2811 | if (ret == -EDEADLK) |
| 2812 | goto backoff; |
| 2813 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2814 | drm_atomic_state_put(state); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2815 | return ret; |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2816 | |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2817 | backoff: |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2818 | drm_atomic_state_clear(state); |
Daniel Vetter | 6f75cea | 2014-11-19 18:38:07 +0100 | [diff] [blame] | 2819 | drm_atomic_legacy_backoff(state); |
Daniel Vetter | 8bc0f31 | 2014-07-27 18:42:37 +0200 | [diff] [blame] | 2820 | |
| 2821 | /* |
| 2822 | * Someone might have exchanged the framebuffer while we dropped locks |
| 2823 | * in the backoff code. We need to fix up the fb refcount tracking the |
| 2824 | * core does for us. |
| 2825 | */ |
| 2826 | plane->old_fb = plane->fb; |
| 2827 | |
| 2828 | goto retry; |
| 2829 | } |
| 2830 | EXPORT_SYMBOL(drm_atomic_helper_page_flip); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2831 | |
| 2832 | /** |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2833 | * drm_atomic_helper_connector_dpms() - connector dpms helper implementation |
| 2834 | * @connector: affected connector |
| 2835 | * @mode: DPMS mode |
| 2836 | * |
| 2837 | * This is the main helper function provided by the atomic helper framework for |
| 2838 | * implementing the legacy DPMS connector interface. It computes the new desired |
| 2839 | * ->active state for the corresponding CRTC (if the connector is enabled) and |
Daniel Vetter | 2e7a570 | 2016-06-01 23:40:36 +0200 | [diff] [blame] | 2840 | * updates it. |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2841 | * |
| 2842 | * Returns: |
| 2843 | * Returns 0 on success, negative errno numbers on failure. |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2844 | */ |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2845 | int drm_atomic_helper_connector_dpms(struct drm_connector *connector, |
| 2846 | int mode) |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2847 | { |
| 2848 | struct drm_mode_config *config = &connector->dev->mode_config; |
| 2849 | struct drm_atomic_state *state; |
| 2850 | struct drm_crtc_state *crtc_state; |
| 2851 | struct drm_crtc *crtc; |
| 2852 | struct drm_connector *tmp_connector; |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 2853 | struct drm_connector_list_iter conn_iter; |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2854 | int ret; |
| 2855 | bool active = false; |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2856 | int old_mode = connector->dpms; |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2857 | |
| 2858 | if (mode != DRM_MODE_DPMS_ON) |
| 2859 | mode = DRM_MODE_DPMS_OFF; |
| 2860 | |
| 2861 | connector->dpms = mode; |
| 2862 | crtc = connector->state->crtc; |
| 2863 | |
| 2864 | if (!crtc) |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2865 | return 0; |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2866 | |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2867 | state = drm_atomic_state_alloc(connector->dev); |
| 2868 | if (!state) |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2869 | return -ENOMEM; |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2870 | |
| 2871 | state->acquire_ctx = drm_modeset_legacy_acquire_ctx(crtc); |
| 2872 | retry: |
| 2873 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2874 | if (IS_ERR(crtc_state)) { |
| 2875 | ret = PTR_ERR(crtc_state); |
| 2876 | goto fail; |
| 2877 | } |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2878 | |
| 2879 | WARN_ON(!drm_modeset_is_locked(&config->connection_mutex)); |
| 2880 | |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 2881 | drm_connector_list_iter_get(connector->dev, &conn_iter); |
| 2882 | drm_for_each_connector_iter(tmp_connector, &conn_iter) { |
John Hunter | 0388df0 | 2015-03-17 15:30:28 +0800 | [diff] [blame] | 2883 | if (tmp_connector->state->crtc != crtc) |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2884 | continue; |
| 2885 | |
John Hunter | 0388df0 | 2015-03-17 15:30:28 +0800 | [diff] [blame] | 2886 | if (tmp_connector->dpms == DRM_MODE_DPMS_ON) { |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2887 | active = true; |
| 2888 | break; |
| 2889 | } |
| 2890 | } |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 2891 | drm_connector_list_iter_put(&conn_iter); |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2892 | crtc_state->active = active; |
| 2893 | |
| 2894 | ret = drm_atomic_commit(state); |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2895 | fail: |
| 2896 | if (ret == -EDEADLK) |
| 2897 | goto backoff; |
Marta Lofstedt | 8f5040e | 2016-12-05 14:04:08 +0200 | [diff] [blame] | 2898 | if (ret != 0) |
| 2899 | connector->dpms = old_mode; |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2900 | drm_atomic_state_put(state); |
Maarten Lankhorst | 9a69a9a | 2015-07-21 11:34:55 +0200 | [diff] [blame] | 2901 | return ret; |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 2902 | |
Daniel Vetter | b486e0e | 2015-01-22 18:53:05 +0100 | [diff] [blame] | 2903 | backoff: |
| 2904 | drm_atomic_state_clear(state); |
| 2905 | drm_atomic_legacy_backoff(state); |
| 2906 | |
| 2907 | goto retry; |
| 2908 | } |
| 2909 | EXPORT_SYMBOL(drm_atomic_helper_connector_dpms); |
| 2910 | |
| 2911 | /** |
Noralf Trønnes | 9ecb549 | 2016-05-11 18:09:21 +0200 | [diff] [blame] | 2912 | * drm_atomic_helper_best_encoder - Helper for &drm_connector_helper_funcs |
| 2913 | * ->best_encoder callback |
| 2914 | * @connector: Connector control structure |
| 2915 | * |
| 2916 | * This is a &drm_connector_helper_funcs ->best_encoder callback helper for |
| 2917 | * connectors that support exactly 1 encoder, statically determined at driver |
| 2918 | * init time. |
| 2919 | */ |
| 2920 | struct drm_encoder * |
| 2921 | drm_atomic_helper_best_encoder(struct drm_connector *connector) |
| 2922 | { |
| 2923 | WARN_ON(connector->encoder_ids[1]); |
| 2924 | return drm_encoder_find(connector->dev, connector->encoder_ids[0]); |
| 2925 | } |
| 2926 | EXPORT_SYMBOL(drm_atomic_helper_best_encoder); |
| 2927 | |
| 2928 | /** |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 2929 | * DOC: atomic state reset and initialization |
| 2930 | * |
| 2931 | * Both the drm core and the atomic helpers assume that there is always the full |
| 2932 | * and correct atomic software state for all connectors, CRTCs and planes |
| 2933 | * available. Which is a bit a problem on driver load and also after system |
| 2934 | * suspend. One way to solve this is to have a hardware state read-out |
| 2935 | * infrastructure which reconstructs the full software state (e.g. the i915 |
| 2936 | * driver). |
| 2937 | * |
| 2938 | * The simpler solution is to just reset the software state to everything off, |
| 2939 | * which is easiest to do by calling drm_mode_config_reset(). To facilitate this |
| 2940 | * the atomic helpers provide default reset implementations for all hooks. |
Daniel Vetter | 7f8ee3e | 2015-12-04 09:46:06 +0100 | [diff] [blame] | 2941 | * |
| 2942 | * On the upside the precise state tracking of atomic simplifies system suspend |
| 2943 | * and resume a lot. For drivers using drm_mode_config_reset() a complete recipe |
| 2944 | * is implemented in drm_atomic_helper_suspend() and drm_atomic_helper_resume(). |
| 2945 | * For other drivers the building blocks are split out, see the documentation |
| 2946 | * for these functions. |
Daniel Vetter | 3150c7d | 2014-11-06 20:53:29 +0100 | [diff] [blame] | 2947 | */ |
| 2948 | |
| 2949 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2950 | * drm_atomic_helper_crtc_reset - default ->reset hook for CRTCs |
| 2951 | * @crtc: drm CRTC |
| 2952 | * |
| 2953 | * Resets the atomic state for @crtc by freeing the state pointer (which might |
| 2954 | * be NULL, e.g. at driver load time) and allocating a new empty state object. |
| 2955 | */ |
| 2956 | void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc) |
| 2957 | { |
Daniel Vetter | b0b5511 | 2016-04-22 22:10:29 +0200 | [diff] [blame] | 2958 | if (crtc->state) |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 2959 | __drm_atomic_helper_crtc_destroy_state(crtc->state); |
Daniel Vetter | b0b5511 | 2016-04-22 22:10:29 +0200 | [diff] [blame] | 2960 | |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2961 | kfree(crtc->state); |
| 2962 | crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL); |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 2963 | |
| 2964 | if (crtc->state) |
| 2965 | crtc->state->crtc = crtc; |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 2966 | } |
| 2967 | EXPORT_SYMBOL(drm_atomic_helper_crtc_reset); |
| 2968 | |
| 2969 | /** |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2970 | * __drm_atomic_helper_crtc_duplicate_state - copy atomic CRTC state |
| 2971 | * @crtc: CRTC object |
| 2972 | * @state: atomic CRTC state |
| 2973 | * |
| 2974 | * Copies atomic state from a CRTC's current state and resets inferred values. |
| 2975 | * This is useful for drivers that subclass the CRTC state. |
| 2976 | */ |
| 2977 | void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc, |
| 2978 | struct drm_crtc_state *state) |
| 2979 | { |
| 2980 | memcpy(state, crtc->state, sizeof(*state)); |
| 2981 | |
Daniel Stone | 99cf4a2 | 2015-05-25 19:11:51 +0100 | [diff] [blame] | 2982 | if (state->mode_blob) |
| 2983 | drm_property_reference_blob(state->mode_blob); |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 2984 | if (state->degamma_lut) |
| 2985 | drm_property_reference_blob(state->degamma_lut); |
| 2986 | if (state->ctm) |
| 2987 | drm_property_reference_blob(state->ctm); |
| 2988 | if (state->gamma_lut) |
| 2989 | drm_property_reference_blob(state->gamma_lut); |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2990 | state->mode_changed = false; |
| 2991 | state->active_changed = false; |
| 2992 | state->planes_changed = false; |
Maarten Lankhorst | fc59666 | 2015-07-21 13:28:57 +0200 | [diff] [blame] | 2993 | state->connectors_changed = false; |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 2994 | state->color_mgmt_changed = false; |
Marek Szyprowski | 44d1240d | 2016-06-13 11:11:26 +0200 | [diff] [blame] | 2995 | state->zpos_changed = false; |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 2996 | state->event = NULL; |
| 2997 | } |
| 2998 | EXPORT_SYMBOL(__drm_atomic_helper_crtc_duplicate_state); |
| 2999 | |
| 3000 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3001 | * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook |
| 3002 | * @crtc: drm CRTC |
| 3003 | * |
| 3004 | * Default CRTC state duplicate hook for drivers which don't have their own |
| 3005 | * subclassed CRTC state structure. |
| 3006 | */ |
| 3007 | struct drm_crtc_state * |
| 3008 | drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc) |
| 3009 | { |
| 3010 | struct drm_crtc_state *state; |
| 3011 | |
| 3012 | if (WARN_ON(!crtc->state)) |
| 3013 | return NULL; |
| 3014 | |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3015 | state = kmalloc(sizeof(*state), GFP_KERNEL); |
| 3016 | if (state) |
| 3017 | __drm_atomic_helper_crtc_duplicate_state(crtc, state); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3018 | |
| 3019 | return state; |
| 3020 | } |
| 3021 | EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state); |
| 3022 | |
| 3023 | /** |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3024 | * __drm_atomic_helper_crtc_destroy_state - release CRTC state |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3025 | * @state: CRTC state object to release |
| 3026 | * |
| 3027 | * Releases all resources stored in the CRTC state without actually freeing |
| 3028 | * the memory of the CRTC state. This is useful for drivers that subclass the |
| 3029 | * CRTC state. |
| 3030 | */ |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 3031 | void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state) |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3032 | { |
Markus Elfring | 5f91190 | 2015-11-06 12:03:46 +0100 | [diff] [blame] | 3033 | drm_property_unreference_blob(state->mode_blob); |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 3034 | drm_property_unreference_blob(state->degamma_lut); |
| 3035 | drm_property_unreference_blob(state->ctm); |
| 3036 | drm_property_unreference_blob(state->gamma_lut); |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3037 | } |
| 3038 | EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state); |
| 3039 | |
| 3040 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3041 | * drm_atomic_helper_crtc_destroy_state - default state destroy hook |
| 3042 | * @crtc: drm CRTC |
| 3043 | * @state: CRTC state object to release |
| 3044 | * |
| 3045 | * Default CRTC state destroy hook for drivers which don't have their own |
| 3046 | * subclassed CRTC state structure. |
| 3047 | */ |
| 3048 | void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc, |
| 3049 | struct drm_crtc_state *state) |
| 3050 | { |
Daniel Vetter | ec2dc6a | 2016-05-09 16:34:09 +0200 | [diff] [blame] | 3051 | __drm_atomic_helper_crtc_destroy_state(state); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3052 | kfree(state); |
| 3053 | } |
| 3054 | EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state); |
| 3055 | |
| 3056 | /** |
| 3057 | * drm_atomic_helper_plane_reset - default ->reset hook for planes |
| 3058 | * @plane: drm plane |
| 3059 | * |
| 3060 | * Resets the atomic state for @plane by freeing the state pointer (which might |
| 3061 | * be NULL, e.g. at driver load time) and allocating a new empty state object. |
| 3062 | */ |
| 3063 | void drm_atomic_helper_plane_reset(struct drm_plane *plane) |
| 3064 | { |
Daniel Vetter | b0b5511 | 2016-04-22 22:10:29 +0200 | [diff] [blame] | 3065 | if (plane->state) |
Daniel Vetter | 2f70169 | 2016-05-09 16:34:10 +0200 | [diff] [blame] | 3066 | __drm_atomic_helper_plane_destroy_state(plane->state); |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 3067 | |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3068 | kfree(plane->state); |
| 3069 | plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL); |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 3070 | |
Marek Szyprowski | 25aaa3a | 2016-01-19 09:26:48 +0100 | [diff] [blame] | 3071 | if (plane->state) { |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 3072 | plane->state->plane = plane; |
Joonas Lahtinen | 31ad61e | 2016-07-29 08:50:05 +0300 | [diff] [blame] | 3073 | plane->state->rotation = DRM_ROTATE_0; |
Marek Szyprowski | 25aaa3a | 2016-01-19 09:26:48 +0100 | [diff] [blame] | 3074 | } |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3075 | } |
| 3076 | EXPORT_SYMBOL(drm_atomic_helper_plane_reset); |
| 3077 | |
| 3078 | /** |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3079 | * __drm_atomic_helper_plane_duplicate_state - copy atomic plane state |
| 3080 | * @plane: plane object |
| 3081 | * @state: atomic plane state |
| 3082 | * |
| 3083 | * Copies atomic state from a plane's current state. This is useful for |
| 3084 | * drivers that subclass the plane state. |
| 3085 | */ |
| 3086 | void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane, |
| 3087 | struct drm_plane_state *state) |
| 3088 | { |
| 3089 | memcpy(state, plane->state, sizeof(*state)); |
| 3090 | |
| 3091 | if (state->fb) |
| 3092 | drm_framebuffer_reference(state->fb); |
Gustavo Padovan | 9626014 | 2016-11-15 22:06:39 +0900 | [diff] [blame] | 3093 | |
| 3094 | state->fence = NULL; |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3095 | } |
| 3096 | EXPORT_SYMBOL(__drm_atomic_helper_plane_duplicate_state); |
| 3097 | |
| 3098 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3099 | * drm_atomic_helper_plane_duplicate_state - default state duplicate hook |
| 3100 | * @plane: drm plane |
| 3101 | * |
| 3102 | * Default plane state duplicate hook for drivers which don't have their own |
| 3103 | * subclassed plane state structure. |
| 3104 | */ |
| 3105 | struct drm_plane_state * |
| 3106 | drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane) |
| 3107 | { |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 3108 | struct drm_plane_state *state; |
| 3109 | |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3110 | if (WARN_ON(!plane->state)) |
| 3111 | return NULL; |
| 3112 | |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3113 | state = kmalloc(sizeof(*state), GFP_KERNEL); |
| 3114 | if (state) |
| 3115 | __drm_atomic_helper_plane_duplicate_state(plane, state); |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 3116 | |
| 3117 | return state; |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3118 | } |
| 3119 | EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state); |
| 3120 | |
| 3121 | /** |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3122 | * __drm_atomic_helper_plane_destroy_state - release plane state |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3123 | * @state: plane state object to release |
| 3124 | * |
| 3125 | * Releases all resources stored in the plane state without actually freeing |
| 3126 | * the memory of the plane state. This is useful for drivers that subclass the |
| 3127 | * plane state. |
| 3128 | */ |
Daniel Vetter | 2f70169 | 2016-05-09 16:34:10 +0200 | [diff] [blame] | 3129 | void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state) |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3130 | { |
| 3131 | if (state->fb) |
| 3132 | drm_framebuffer_unreference(state->fb); |
Gustavo Padovan | 9626014 | 2016-11-15 22:06:39 +0900 | [diff] [blame] | 3133 | |
| 3134 | if (state->fence) |
| 3135 | dma_fence_put(state->fence); |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3136 | } |
| 3137 | EXPORT_SYMBOL(__drm_atomic_helper_plane_destroy_state); |
| 3138 | |
| 3139 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3140 | * drm_atomic_helper_plane_destroy_state - default state destroy hook |
| 3141 | * @plane: drm plane |
| 3142 | * @state: plane state object to release |
| 3143 | * |
| 3144 | * Default plane state destroy hook for drivers which don't have their own |
| 3145 | * subclassed plane state structure. |
| 3146 | */ |
| 3147 | void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane, |
Daniel Vetter | 321ebf0 | 2014-11-04 22:57:27 +0100 | [diff] [blame] | 3148 | struct drm_plane_state *state) |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3149 | { |
Daniel Vetter | 2f70169 | 2016-05-09 16:34:10 +0200 | [diff] [blame] | 3150 | __drm_atomic_helper_plane_destroy_state(state); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3151 | kfree(state); |
| 3152 | } |
| 3153 | EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state); |
| 3154 | |
| 3155 | /** |
Maarten Lankhorst | 4cd3991 | 2016-01-04 12:53:16 +0100 | [diff] [blame] | 3156 | * __drm_atomic_helper_connector_reset - reset state on connector |
| 3157 | * @connector: drm connector |
| 3158 | * @conn_state: connector state to assign |
| 3159 | * |
| 3160 | * Initializes the newly allocated @conn_state and assigns it to |
| 3161 | * #connector ->state, usually required when initializing the drivers |
| 3162 | * or when called from the ->reset hook. |
| 3163 | * |
| 3164 | * This is useful for drivers that subclass the connector state. |
| 3165 | */ |
| 3166 | void |
| 3167 | __drm_atomic_helper_connector_reset(struct drm_connector *connector, |
| 3168 | struct drm_connector_state *conn_state) |
| 3169 | { |
| 3170 | if (conn_state) |
| 3171 | conn_state->connector = connector; |
| 3172 | |
| 3173 | connector->state = conn_state; |
| 3174 | } |
| 3175 | EXPORT_SYMBOL(__drm_atomic_helper_connector_reset); |
| 3176 | |
| 3177 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3178 | * drm_atomic_helper_connector_reset - default ->reset hook for connectors |
| 3179 | * @connector: drm connector |
| 3180 | * |
| 3181 | * Resets the atomic state for @connector by freeing the state pointer (which |
| 3182 | * might be NULL, e.g. at driver load time) and allocating a new empty state |
| 3183 | * object. |
| 3184 | */ |
| 3185 | void drm_atomic_helper_connector_reset(struct drm_connector *connector) |
| 3186 | { |
Maarten Lankhorst | 4cd3991 | 2016-01-04 12:53:16 +0100 | [diff] [blame] | 3187 | struct drm_connector_state *conn_state = |
| 3188 | kzalloc(sizeof(*conn_state), GFP_KERNEL); |
Daniel Vetter | 07cc0ef | 2014-11-27 15:49:39 +0100 | [diff] [blame] | 3189 | |
Daniel Vetter | b0b5511 | 2016-04-22 22:10:29 +0200 | [diff] [blame] | 3190 | if (connector->state) |
Daniel Vetter | fabd910 | 2016-05-09 16:34:11 +0200 | [diff] [blame] | 3191 | __drm_atomic_helper_connector_destroy_state(connector->state); |
Daniel Vetter | b0b5511 | 2016-04-22 22:10:29 +0200 | [diff] [blame] | 3192 | |
Maarten Lankhorst | 4cd3991 | 2016-01-04 12:53:16 +0100 | [diff] [blame] | 3193 | kfree(connector->state); |
| 3194 | __drm_atomic_helper_connector_reset(connector, conn_state); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3195 | } |
| 3196 | EXPORT_SYMBOL(drm_atomic_helper_connector_reset); |
| 3197 | |
| 3198 | /** |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3199 | * __drm_atomic_helper_connector_duplicate_state - copy atomic connector state |
| 3200 | * @connector: connector object |
| 3201 | * @state: atomic connector state |
| 3202 | * |
| 3203 | * Copies atomic state from a connector's current state. This is useful for |
| 3204 | * drivers that subclass the connector state. |
| 3205 | */ |
| 3206 | void |
| 3207 | __drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector, |
| 3208 | struct drm_connector_state *state) |
| 3209 | { |
| 3210 | memcpy(state, connector->state, sizeof(*state)); |
Dave Airlie | d2307de | 2016-04-27 11:27:39 +1000 | [diff] [blame] | 3211 | if (state->crtc) |
| 3212 | drm_connector_reference(connector); |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3213 | } |
| 3214 | EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state); |
| 3215 | |
| 3216 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3217 | * drm_atomic_helper_connector_duplicate_state - default state duplicate hook |
| 3218 | * @connector: drm connector |
| 3219 | * |
| 3220 | * Default connector state duplicate hook for drivers which don't have their own |
| 3221 | * subclassed connector state structure. |
| 3222 | */ |
| 3223 | struct drm_connector_state * |
| 3224 | drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector) |
| 3225 | { |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3226 | struct drm_connector_state *state; |
| 3227 | |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3228 | if (WARN_ON(!connector->state)) |
| 3229 | return NULL; |
| 3230 | |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3231 | state = kmalloc(sizeof(*state), GFP_KERNEL); |
| 3232 | if (state) |
| 3233 | __drm_atomic_helper_connector_duplicate_state(connector, state); |
| 3234 | |
| 3235 | return state; |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3236 | } |
| 3237 | EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state); |
| 3238 | |
| 3239 | /** |
Thierry Reding | 397fd77 | 2015-09-08 15:00:45 +0200 | [diff] [blame] | 3240 | * drm_atomic_helper_duplicate_state - duplicate an atomic state object |
| 3241 | * @dev: DRM device |
| 3242 | * @ctx: lock acquisition context |
| 3243 | * |
| 3244 | * Makes a copy of the current atomic state by looping over all objects and |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3245 | * duplicating their respective states. This is used for example by suspend/ |
| 3246 | * resume support code to save the state prior to suspend such that it can |
| 3247 | * be restored upon resume. |
Thierry Reding | 397fd77 | 2015-09-08 15:00:45 +0200 | [diff] [blame] | 3248 | * |
| 3249 | * Note that this treats atomic state as persistent between save and restore. |
| 3250 | * Drivers must make sure that this is possible and won't result in confusion |
| 3251 | * or erroneous behaviour. |
| 3252 | * |
| 3253 | * Note that if callers haven't already acquired all modeset locks this might |
| 3254 | * return -EDEADLK, which must be handled by calling drm_modeset_backoff(). |
| 3255 | * |
| 3256 | * Returns: |
| 3257 | * A pointer to the copy of the atomic state object on success or an |
| 3258 | * ERR_PTR()-encoded error code on failure. |
Thierry Reding | 1494276 | 2015-12-02 17:50:04 +0100 | [diff] [blame] | 3259 | * |
| 3260 | * See also: |
| 3261 | * drm_atomic_helper_suspend(), drm_atomic_helper_resume() |
Thierry Reding | 397fd77 | 2015-09-08 15:00:45 +0200 | [diff] [blame] | 3262 | */ |
| 3263 | struct drm_atomic_state * |
| 3264 | drm_atomic_helper_duplicate_state(struct drm_device *dev, |
| 3265 | struct drm_modeset_acquire_ctx *ctx) |
| 3266 | { |
| 3267 | struct drm_atomic_state *state; |
| 3268 | struct drm_connector *conn; |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 3269 | struct drm_connector_list_iter conn_iter; |
Thierry Reding | 397fd77 | 2015-09-08 15:00:45 +0200 | [diff] [blame] | 3270 | struct drm_plane *plane; |
| 3271 | struct drm_crtc *crtc; |
| 3272 | int err = 0; |
| 3273 | |
| 3274 | state = drm_atomic_state_alloc(dev); |
| 3275 | if (!state) |
| 3276 | return ERR_PTR(-ENOMEM); |
| 3277 | |
| 3278 | state->acquire_ctx = ctx; |
| 3279 | |
| 3280 | drm_for_each_crtc(crtc, dev) { |
| 3281 | struct drm_crtc_state *crtc_state; |
| 3282 | |
| 3283 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 3284 | if (IS_ERR(crtc_state)) { |
| 3285 | err = PTR_ERR(crtc_state); |
| 3286 | goto free; |
| 3287 | } |
| 3288 | } |
| 3289 | |
| 3290 | drm_for_each_plane(plane, dev) { |
| 3291 | struct drm_plane_state *plane_state; |
| 3292 | |
| 3293 | plane_state = drm_atomic_get_plane_state(state, plane); |
| 3294 | if (IS_ERR(plane_state)) { |
| 3295 | err = PTR_ERR(plane_state); |
| 3296 | goto free; |
| 3297 | } |
| 3298 | } |
| 3299 | |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 3300 | drm_connector_list_iter_get(dev, &conn_iter); |
| 3301 | drm_for_each_connector_iter(conn, &conn_iter) { |
Thierry Reding | 397fd77 | 2015-09-08 15:00:45 +0200 | [diff] [blame] | 3302 | struct drm_connector_state *conn_state; |
| 3303 | |
| 3304 | conn_state = drm_atomic_get_connector_state(state, conn); |
| 3305 | if (IS_ERR(conn_state)) { |
| 3306 | err = PTR_ERR(conn_state); |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 3307 | drm_connector_list_iter_put(&conn_iter); |
Thierry Reding | 397fd77 | 2015-09-08 15:00:45 +0200 | [diff] [blame] | 3308 | goto free; |
| 3309 | } |
| 3310 | } |
Daniel Vetter | c36a325 | 2016-12-15 16:58:43 +0100 | [diff] [blame^] | 3311 | drm_connector_list_iter_put(&conn_iter); |
Thierry Reding | 397fd77 | 2015-09-08 15:00:45 +0200 | [diff] [blame] | 3312 | |
| 3313 | /* clear the acquire context so that it isn't accidentally reused */ |
| 3314 | state->acquire_ctx = NULL; |
| 3315 | |
| 3316 | free: |
| 3317 | if (err < 0) { |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 3318 | drm_atomic_state_put(state); |
Thierry Reding | 397fd77 | 2015-09-08 15:00:45 +0200 | [diff] [blame] | 3319 | state = ERR_PTR(err); |
| 3320 | } |
| 3321 | |
| 3322 | return state; |
| 3323 | } |
| 3324 | EXPORT_SYMBOL(drm_atomic_helper_duplicate_state); |
| 3325 | |
| 3326 | /** |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3327 | * __drm_atomic_helper_connector_destroy_state - release connector state |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3328 | * @state: connector state object to release |
| 3329 | * |
| 3330 | * Releases all resources stored in the connector state without actually |
| 3331 | * freeing the memory of the connector state. This is useful for drivers that |
| 3332 | * subclass the connector state. |
| 3333 | */ |
| 3334 | void |
Daniel Vetter | fabd910 | 2016-05-09 16:34:11 +0200 | [diff] [blame] | 3335 | __drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state) |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3336 | { |
| 3337 | /* |
| 3338 | * This is currently a placeholder so that drivers that subclass the |
| 3339 | * state will automatically do the right thing if code is ever added |
| 3340 | * to this function. |
| 3341 | */ |
Dave Airlie | d2307de | 2016-04-27 11:27:39 +1000 | [diff] [blame] | 3342 | if (state->crtc) |
| 3343 | drm_connector_unreference(state->connector); |
Thierry Reding | f5e7840 | 2015-01-28 14:54:32 +0100 | [diff] [blame] | 3344 | } |
| 3345 | EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state); |
| 3346 | |
| 3347 | /** |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3348 | * drm_atomic_helper_connector_destroy_state - default state destroy hook |
| 3349 | * @connector: drm connector |
| 3350 | * @state: connector state object to release |
| 3351 | * |
| 3352 | * Default connector state destroy hook for drivers which don't have their own |
| 3353 | * subclassed connector state structure. |
| 3354 | */ |
| 3355 | void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector, |
| 3356 | struct drm_connector_state *state) |
| 3357 | { |
Daniel Vetter | fabd910 | 2016-05-09 16:34:11 +0200 | [diff] [blame] | 3358 | __drm_atomic_helper_connector_destroy_state(state); |
Daniel Vetter | d461701 | 2014-11-03 15:56:43 +0100 | [diff] [blame] | 3359 | kfree(state); |
| 3360 | } |
| 3361 | EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state); |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 3362 | |
| 3363 | /** |
| 3364 | * drm_atomic_helper_legacy_gamma_set - set the legacy gamma correction table |
| 3365 | * @crtc: CRTC object |
| 3366 | * @red: red correction table |
| 3367 | * @green: green correction table |
| 3368 | * @blue: green correction table |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 3369 | * @size: size of the tables |
| 3370 | * |
| 3371 | * Implements support for legacy gamma correction table for drivers |
| 3372 | * that support color management through the DEGAMMA_LUT/GAMMA_LUT |
| 3373 | * properties. |
| 3374 | */ |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 3375 | int drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc, |
| 3376 | u16 *red, u16 *green, u16 *blue, |
| 3377 | uint32_t size) |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 3378 | { |
| 3379 | struct drm_device *dev = crtc->dev; |
| 3380 | struct drm_mode_config *config = &dev->mode_config; |
| 3381 | struct drm_atomic_state *state; |
| 3382 | struct drm_crtc_state *crtc_state; |
| 3383 | struct drm_property_blob *blob = NULL; |
| 3384 | struct drm_color_lut *blob_data; |
| 3385 | int i, ret = 0; |
| 3386 | |
| 3387 | state = drm_atomic_state_alloc(crtc->dev); |
| 3388 | if (!state) |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 3389 | return -ENOMEM; |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 3390 | |
| 3391 | blob = drm_property_create_blob(dev, |
| 3392 | sizeof(struct drm_color_lut) * size, |
| 3393 | NULL); |
Lionel Landwerlin | 562c5b4 | 2016-03-10 12:04:21 +0000 | [diff] [blame] | 3394 | if (IS_ERR(blob)) { |
| 3395 | ret = PTR_ERR(blob); |
Lionel Landwerlin | c1f415c | 2016-03-11 12:17:26 +0000 | [diff] [blame] | 3396 | blob = NULL; |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 3397 | goto fail; |
| 3398 | } |
| 3399 | |
| 3400 | /* Prepare GAMMA_LUT with the legacy values. */ |
| 3401 | blob_data = (struct drm_color_lut *) blob->data; |
| 3402 | for (i = 0; i < size; i++) { |
| 3403 | blob_data[i].red = red[i]; |
| 3404 | blob_data[i].green = green[i]; |
| 3405 | blob_data[i].blue = blue[i]; |
| 3406 | } |
| 3407 | |
| 3408 | state->acquire_ctx = crtc->dev->mode_config.acquire_ctx; |
| 3409 | retry: |
| 3410 | crtc_state = drm_atomic_get_crtc_state(state, crtc); |
| 3411 | if (IS_ERR(crtc_state)) { |
| 3412 | ret = PTR_ERR(crtc_state); |
| 3413 | goto fail; |
| 3414 | } |
| 3415 | |
| 3416 | /* Reset DEGAMMA_LUT and CTM properties. */ |
| 3417 | ret = drm_atomic_crtc_set_property(crtc, crtc_state, |
| 3418 | config->degamma_lut_property, 0); |
| 3419 | if (ret) |
| 3420 | goto fail; |
| 3421 | |
| 3422 | ret = drm_atomic_crtc_set_property(crtc, crtc_state, |
| 3423 | config->ctm_property, 0); |
| 3424 | if (ret) |
| 3425 | goto fail; |
| 3426 | |
| 3427 | ret = drm_atomic_crtc_set_property(crtc, crtc_state, |
| 3428 | config->gamma_lut_property, blob->base.id); |
| 3429 | if (ret) |
| 3430 | goto fail; |
| 3431 | |
| 3432 | ret = drm_atomic_commit(state); |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 3433 | fail: |
| 3434 | if (ret == -EDEADLK) |
| 3435 | goto backoff; |
| 3436 | |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 3437 | drm_atomic_state_put(state); |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 3438 | drm_property_unreference_blob(blob); |
Maarten Lankhorst | 7ea7728 | 2016-06-07 12:49:30 +0200 | [diff] [blame] | 3439 | return ret; |
Chris Wilson | 0853695 | 2016-10-14 13:18:18 +0100 | [diff] [blame] | 3440 | |
Lionel Landwerlin | 5488dc1 | 2016-02-26 17:05:00 +0000 | [diff] [blame] | 3441 | backoff: |
| 3442 | drm_atomic_state_clear(state); |
| 3443 | drm_atomic_legacy_backoff(state); |
| 3444 | |
| 3445 | goto retry; |
| 3446 | } |
| 3447 | EXPORT_SYMBOL(drm_atomic_helper_legacy_gamma_set); |