Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 1 | /* |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016-2017, The Linux Foundation. All rights reserved. |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 3 | * Copyright (C) 2014 Red Hat |
| 4 | * Author: Rob Clark <robdclark@gmail.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify it |
| 7 | * under the terms of the GNU General Public License version 2 as published by |
| 8 | * the Free Software Foundation. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | * more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License along with |
| 16 | * this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | #include "msm_drv.h" |
| 20 | #include "msm_kms.h" |
| 21 | #include "msm_gem.h" |
Rob Clark | fde5de6 | 2016-03-15 15:35:08 -0400 | [diff] [blame] | 22 | #include "msm_fence.h" |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 23 | #include "sde_trace.h" |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 24 | |
| 25 | struct msm_commit { |
Rob Clark | 0b776d4 | 2015-01-30 17:04:45 -0500 | [diff] [blame] | 26 | struct drm_device *dev; |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 27 | struct drm_atomic_state *state; |
Rob Clark | f86afec | 2014-11-25 12:41:18 -0500 | [diff] [blame] | 28 | uint32_t crtc_mask; |
Sandeep Panda | f48c46a | 2016-10-24 09:48:50 +0530 | [diff] [blame] | 29 | struct kthread_work commit_work; |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 30 | }; |
| 31 | |
Rob Clark | f86afec | 2014-11-25 12:41:18 -0500 | [diff] [blame] | 32 | /* block until specified crtcs are no longer pending update, and |
| 33 | * atomically mark them as pending update |
| 34 | */ |
| 35 | static int start_atomic(struct msm_drm_private *priv, uint32_t crtc_mask) |
| 36 | { |
| 37 | int ret; |
| 38 | |
| 39 | spin_lock(&priv->pending_crtcs_event.lock); |
| 40 | ret = wait_event_interruptible_locked(priv->pending_crtcs_event, |
| 41 | !(priv->pending_crtcs & crtc_mask)); |
| 42 | if (ret == 0) { |
| 43 | DBG("start: %08x", crtc_mask); |
| 44 | priv->pending_crtcs |= crtc_mask; |
| 45 | } |
| 46 | spin_unlock(&priv->pending_crtcs_event.lock); |
| 47 | |
| 48 | return ret; |
| 49 | } |
| 50 | |
| 51 | /* clear specified crtcs (no longer pending update) |
| 52 | */ |
| 53 | static void end_atomic(struct msm_drm_private *priv, uint32_t crtc_mask) |
| 54 | { |
| 55 | spin_lock(&priv->pending_crtcs_event.lock); |
| 56 | DBG("end: %08x", crtc_mask); |
| 57 | priv->pending_crtcs &= ~crtc_mask; |
| 58 | wake_up_all_locked(&priv->pending_crtcs_event); |
| 59 | spin_unlock(&priv->pending_crtcs_event.lock); |
| 60 | } |
| 61 | |
Rob Clark | 0b776d4 | 2015-01-30 17:04:45 -0500 | [diff] [blame] | 62 | static void commit_destroy(struct msm_commit *c) |
| 63 | { |
| 64 | end_atomic(c->dev->dev_private, c->crtc_mask); |
| 65 | kfree(c); |
| 66 | } |
| 67 | |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 68 | static void msm_atomic_wait_for_commit_done( |
| 69 | struct drm_device *dev, |
Lloyd Atkinson | 940340d | 2016-12-09 14:49:37 -0500 | [diff] [blame] | 70 | struct drm_atomic_state *old_state) |
Hai Li | 0a5c9aa | 2015-04-28 19:35:37 -0400 | [diff] [blame] | 71 | { |
| 72 | struct drm_crtc *crtc; |
Daniel Vetter | 8d76b79 | 2016-06-02 15:41:53 +0200 | [diff] [blame] | 73 | struct drm_crtc_state *crtc_state; |
Hai Li | 0a5c9aa | 2015-04-28 19:35:37 -0400 | [diff] [blame] | 74 | struct msm_drm_private *priv = old_state->dev->dev_private; |
| 75 | struct msm_kms *kms = priv->kms; |
Hai Li | 0a5c9aa | 2015-04-28 19:35:37 -0400 | [diff] [blame] | 76 | int i; |
| 77 | |
Daniel Vetter | 8d76b79 | 2016-06-02 15:41:53 +0200 | [diff] [blame] | 78 | for_each_crtc_in_state(old_state, crtc, crtc_state, i) { |
Hai Li | 0a5c9aa | 2015-04-28 19:35:37 -0400 | [diff] [blame] | 79 | if (!crtc->state->enable) |
| 80 | continue; |
| 81 | |
| 82 | /* Legacy cursor ioctls are completely unsynced, and userspace |
| 83 | * relies on that (by doing tons of cursor updates). */ |
| 84 | if (old_state->legacy_cursor_update) |
| 85 | continue; |
| 86 | |
| 87 | kms->funcs->wait_for_crtc_commit_done(kms, crtc); |
| 88 | } |
| 89 | } |
| 90 | |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 91 | static void |
| 92 | msm_disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state) |
| 93 | { |
| 94 | struct drm_connector *connector; |
| 95 | struct drm_connector_state *old_conn_state; |
| 96 | struct drm_crtc *crtc; |
| 97 | struct drm_crtc_state *old_crtc_state; |
| 98 | int i; |
| 99 | |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 100 | SDE_ATRACE_BEGIN("msm_disable"); |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 101 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
| 102 | const struct drm_encoder_helper_funcs *funcs; |
| 103 | struct drm_encoder *encoder; |
| 104 | struct drm_crtc_state *old_crtc_state; |
| 105 | unsigned int crtc_idx; |
| 106 | |
| 107 | /* |
| 108 | * Shut down everything that's in the changeset and currently |
| 109 | * still on. So need to check the old, saved state. |
| 110 | */ |
| 111 | if (!old_conn_state->crtc) |
| 112 | continue; |
| 113 | |
| 114 | crtc_idx = drm_crtc_index(old_conn_state->crtc); |
Dhaval Patel | 04c7e8e | 2016-09-26 20:14:31 -0700 | [diff] [blame] | 115 | old_crtc_state = drm_atomic_get_existing_crtc_state(old_state, |
| 116 | old_conn_state->crtc); |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 117 | |
| 118 | if (!old_crtc_state->active || |
| 119 | !drm_atomic_crtc_needs_modeset(old_conn_state->crtc->state)) |
| 120 | continue; |
| 121 | |
| 122 | encoder = old_conn_state->best_encoder; |
| 123 | |
| 124 | /* We shouldn't get this far if we didn't previously have |
| 125 | * an encoder.. but WARN_ON() rather than explode. |
| 126 | */ |
| 127 | if (WARN_ON(!encoder)) |
| 128 | continue; |
| 129 | |
| 130 | if (msm_is_mode_seamless( |
| 131 | &connector->encoder->crtc->state->mode)) |
| 132 | continue; |
| 133 | |
Jeykumar Sankaran | 6993462 | 2017-05-31 18:16:25 -0700 | [diff] [blame] | 134 | if (msm_is_mode_seamless_dms( |
| 135 | &connector->encoder->crtc->state->adjusted_mode)) |
| 136 | continue; |
| 137 | |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 138 | funcs = encoder->helper_private; |
| 139 | |
| 140 | DRM_DEBUG_ATOMIC("disabling [ENCODER:%d:%s]\n", |
| 141 | encoder->base.id, encoder->name); |
| 142 | |
| 143 | /* |
| 144 | * Each encoder has at most one connector (since we always steal |
| 145 | * it away), so we won't call disable hooks twice. |
| 146 | */ |
| 147 | drm_bridge_disable(encoder->bridge); |
| 148 | |
| 149 | /* Right function depends upon target state. */ |
| 150 | if (connector->state->crtc && funcs->prepare) |
| 151 | funcs->prepare(encoder); |
| 152 | else if (funcs->disable) |
| 153 | funcs->disable(encoder); |
| 154 | else |
| 155 | funcs->dpms(encoder, DRM_MODE_DPMS_OFF); |
| 156 | |
| 157 | drm_bridge_post_disable(encoder->bridge); |
| 158 | } |
| 159 | |
| 160 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
| 161 | const struct drm_crtc_helper_funcs *funcs; |
| 162 | |
| 163 | /* Shut down everything that needs a full modeset. */ |
| 164 | if (!drm_atomic_crtc_needs_modeset(crtc->state)) |
| 165 | continue; |
| 166 | |
| 167 | if (!old_crtc_state->active) |
| 168 | continue; |
| 169 | |
| 170 | if (msm_is_mode_seamless(&crtc->state->mode)) |
| 171 | continue; |
| 172 | |
Jeykumar Sankaran | 6993462 | 2017-05-31 18:16:25 -0700 | [diff] [blame] | 173 | if (msm_is_mode_seamless_dms(&crtc->state->adjusted_mode)) |
| 174 | continue; |
| 175 | |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 176 | funcs = crtc->helper_private; |
| 177 | |
| 178 | DRM_DEBUG_ATOMIC("disabling [CRTC:%d]\n", |
| 179 | crtc->base.id); |
| 180 | |
| 181 | /* Right function depends upon target state. */ |
| 182 | if (crtc->state->enable && funcs->prepare) |
| 183 | funcs->prepare(crtc); |
| 184 | else if (funcs->disable) |
| 185 | funcs->disable(crtc); |
| 186 | else |
| 187 | funcs->dpms(crtc, DRM_MODE_DPMS_OFF); |
| 188 | } |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 189 | SDE_ATRACE_END("msm_disable"); |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | static void |
| 193 | msm_crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state) |
| 194 | { |
| 195 | struct drm_crtc *crtc; |
| 196 | struct drm_crtc_state *old_crtc_state; |
| 197 | struct drm_connector *connector; |
| 198 | struct drm_connector_state *old_conn_state; |
| 199 | int i; |
| 200 | |
| 201 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
| 202 | const struct drm_crtc_helper_funcs *funcs; |
| 203 | |
| 204 | if (!crtc->state->mode_changed) |
| 205 | continue; |
| 206 | |
| 207 | funcs = crtc->helper_private; |
| 208 | |
| 209 | if (crtc->state->enable && funcs->mode_set_nofb) { |
| 210 | DRM_DEBUG_ATOMIC("modeset on [CRTC:%d]\n", |
| 211 | crtc->base.id); |
| 212 | |
| 213 | funcs->mode_set_nofb(crtc); |
| 214 | } |
| 215 | } |
| 216 | |
| 217 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
| 218 | const struct drm_encoder_helper_funcs *funcs; |
| 219 | struct drm_crtc_state *new_crtc_state; |
| 220 | struct drm_encoder *encoder; |
| 221 | struct drm_display_mode *mode, *adjusted_mode; |
| 222 | |
| 223 | if (!connector->state->best_encoder) |
| 224 | continue; |
| 225 | |
| 226 | encoder = connector->state->best_encoder; |
| 227 | funcs = encoder->helper_private; |
| 228 | new_crtc_state = connector->state->crtc->state; |
| 229 | mode = &new_crtc_state->mode; |
| 230 | adjusted_mode = &new_crtc_state->adjusted_mode; |
| 231 | |
| 232 | if (!new_crtc_state->mode_changed) |
| 233 | continue; |
| 234 | |
| 235 | DRM_DEBUG_ATOMIC("modeset on [ENCODER:%d:%s]\n", |
| 236 | encoder->base.id, encoder->name); |
| 237 | |
| 238 | /* |
| 239 | * Each encoder has at most one connector (since we always steal |
| 240 | * it away), so we won't call mode_set hooks twice. |
| 241 | */ |
| 242 | if (funcs->mode_set) |
| 243 | funcs->mode_set(encoder, mode, adjusted_mode); |
| 244 | |
| 245 | drm_bridge_mode_set(encoder->bridge, mode, adjusted_mode); |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * msm_atomic_helper_commit_modeset_disables - modeset commit to disable outputs |
| 251 | * @dev: DRM device |
| 252 | * @old_state: atomic state object with old state structures |
| 253 | * |
| 254 | * This function shuts down all the outputs that need to be shut down and |
| 255 | * prepares them (if required) with the new mode. |
| 256 | * |
| 257 | * For compatibility with legacy crtc helpers this should be called before |
| 258 | * drm_atomic_helper_commit_planes(), which is what the default commit function |
| 259 | * does. But drivers with different needs can group the modeset commits together |
| 260 | * and do the plane commits at the end. This is useful for drivers doing runtime |
| 261 | * PM since planes updates then only happen when the CRTC is actually enabled. |
| 262 | */ |
| 263 | void msm_atomic_helper_commit_modeset_disables(struct drm_device *dev, |
| 264 | struct drm_atomic_state *old_state) |
| 265 | { |
| 266 | msm_disable_outputs(dev, old_state); |
| 267 | |
| 268 | drm_atomic_helper_update_legacy_modeset_state(dev, old_state); |
| 269 | |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 270 | msm_crtc_set_mode(dev, old_state); |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | /** |
| 274 | * msm_atomic_helper_commit_modeset_enables - modeset commit to enable outputs |
| 275 | * @dev: DRM device |
| 276 | * @old_state: atomic state object with old state structures |
| 277 | * |
| 278 | * This function enables all the outputs with the new configuration which had to |
| 279 | * be turned off for the update. |
| 280 | * |
| 281 | * For compatibility with legacy crtc helpers this should be called after |
| 282 | * drm_atomic_helper_commit_planes(), which is what the default commit function |
| 283 | * does. But drivers with different needs can group the modeset commits together |
| 284 | * and do the plane commits at the end. This is useful for drivers doing runtime |
| 285 | * PM since planes updates then only happen when the CRTC is actually enabled. |
| 286 | */ |
Lloyd Atkinson | 0b7ff59 | 2016-05-30 14:01:10 -0400 | [diff] [blame] | 287 | static void msm_atomic_helper_commit_modeset_enables(struct drm_device *dev, |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 288 | struct drm_atomic_state *old_state) |
| 289 | { |
| 290 | struct drm_crtc *crtc; |
| 291 | struct drm_crtc_state *old_crtc_state; |
| 292 | struct drm_connector *connector; |
| 293 | struct drm_connector_state *old_conn_state; |
Lloyd Atkinson | 0b7ff59 | 2016-05-30 14:01:10 -0400 | [diff] [blame] | 294 | struct msm_drm_private *priv = dev->dev_private; |
| 295 | struct msm_kms *kms = priv->kms; |
| 296 | int bridge_enable_count = 0; |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 297 | int i; |
| 298 | |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 299 | SDE_ATRACE_BEGIN("msm_enable"); |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 300 | for_each_crtc_in_state(old_state, crtc, old_crtc_state, i) { |
| 301 | const struct drm_crtc_helper_funcs *funcs; |
| 302 | |
| 303 | /* Need to filter out CRTCs where only planes change. */ |
| 304 | if (!drm_atomic_crtc_needs_modeset(crtc->state)) |
| 305 | continue; |
| 306 | |
| 307 | if (!crtc->state->active) |
| 308 | continue; |
| 309 | |
| 310 | if (msm_is_mode_seamless(&crtc->state->mode)) |
| 311 | continue; |
| 312 | |
Jeykumar Sankaran | 6993462 | 2017-05-31 18:16:25 -0700 | [diff] [blame] | 313 | /** |
| 314 | * On DMS switch, wait for ping pong done to ensure the current |
| 315 | * frame transfer is complete. |
| 316 | */ |
| 317 | if (msm_is_mode_seamless_dms(&crtc->state->adjusted_mode)) |
| 318 | kms->funcs->wait_for_tx_complete(kms, crtc); |
| 319 | |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 320 | funcs = crtc->helper_private; |
| 321 | |
| 322 | if (crtc->state->enable) { |
| 323 | DRM_DEBUG_ATOMIC("enabling [CRTC:%d]\n", |
| 324 | crtc->base.id); |
| 325 | |
| 326 | if (funcs->enable) |
| 327 | funcs->enable(crtc); |
| 328 | else |
| 329 | funcs->commit(crtc); |
| 330 | } |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 331 | |
Lloyd Atkinson | 940340d | 2016-12-09 14:49:37 -0500 | [diff] [blame] | 332 | if (msm_needs_vblank_pre_modeset(&crtc->state->adjusted_mode)) |
| 333 | drm_crtc_wait_one_vblank(crtc); |
| 334 | } |
Clarence Ip | f99ccea | 2016-07-05 11:41:07 -0400 | [diff] [blame] | 335 | |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 336 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
| 337 | const struct drm_encoder_helper_funcs *funcs; |
| 338 | struct drm_encoder *encoder; |
| 339 | |
| 340 | if (!connector->state->best_encoder) |
| 341 | continue; |
| 342 | |
| 343 | if (!connector->state->crtc->state->active || |
| 344 | !drm_atomic_crtc_needs_modeset( |
| 345 | connector->state->crtc->state)) |
| 346 | continue; |
| 347 | |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 348 | encoder = connector->state->best_encoder; |
| 349 | funcs = encoder->helper_private; |
| 350 | |
| 351 | DRM_DEBUG_ATOMIC("enabling [ENCODER:%d:%s]\n", |
| 352 | encoder->base.id, encoder->name); |
| 353 | |
| 354 | /* |
| 355 | * Each encoder has at most one connector (since we always steal |
| 356 | * it away), so we won't call enable hooks twice. |
| 357 | */ |
| 358 | drm_bridge_pre_enable(encoder->bridge); |
Lloyd Atkinson | 0b7ff59 | 2016-05-30 14:01:10 -0400 | [diff] [blame] | 359 | ++bridge_enable_count; |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 360 | |
| 361 | if (funcs->enable) |
| 362 | funcs->enable(encoder); |
| 363 | else |
| 364 | funcs->commit(encoder); |
Lloyd Atkinson | 0b7ff59 | 2016-05-30 14:01:10 -0400 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | if (kms->funcs->commit) { |
| 368 | DRM_DEBUG_ATOMIC("triggering commit\n"); |
| 369 | kms->funcs->commit(kms, old_state); |
| 370 | } |
| 371 | |
| 372 | /* If no bridges were pre_enabled, skip iterating over them again */ |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 373 | if (bridge_enable_count == 0) { |
| 374 | SDE_ATRACE_END("msm_enable"); |
Lloyd Atkinson | 0b7ff59 | 2016-05-30 14:01:10 -0400 | [diff] [blame] | 375 | return; |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 376 | } |
Lloyd Atkinson | 0b7ff59 | 2016-05-30 14:01:10 -0400 | [diff] [blame] | 377 | |
| 378 | for_each_connector_in_state(old_state, connector, old_conn_state, i) { |
| 379 | struct drm_encoder *encoder; |
| 380 | |
| 381 | if (!connector->state->best_encoder) |
| 382 | continue; |
| 383 | |
| 384 | if (!connector->state->crtc->state->active || |
| 385 | !drm_atomic_crtc_needs_modeset( |
| 386 | connector->state->crtc->state)) |
| 387 | continue; |
| 388 | |
| 389 | encoder = connector->state->best_encoder; |
| 390 | |
| 391 | DRM_DEBUG_ATOMIC("bridge enable enabling [ENCODER:%d:%s]\n", |
| 392 | encoder->base.id, encoder->name); |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 393 | |
| 394 | drm_bridge_enable(encoder->bridge); |
| 395 | } |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 396 | SDE_ATRACE_END("msm_enable"); |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 397 | } |
| 398 | |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 399 | /* The (potentially) asynchronous part of the commit. At this point |
| 400 | * nothing can fail short of armageddon. |
| 401 | */ |
Sandeep Panda | f48c46a | 2016-10-24 09:48:50 +0530 | [diff] [blame] | 402 | static void complete_commit(struct msm_commit *c) |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 403 | { |
| 404 | struct drm_atomic_state *state = c->state; |
| 405 | struct drm_device *dev = state->dev; |
Rob Clark | 0b776d4 | 2015-01-30 17:04:45 -0500 | [diff] [blame] | 406 | struct msm_drm_private *priv = dev->dev_private; |
| 407 | struct msm_kms *kms = priv->kms; |
| 408 | |
Gustavo Padovan | f6ce410 | 2016-09-12 16:08:11 -0300 | [diff] [blame] | 409 | drm_atomic_helper_wait_for_fences(dev, state, false); |
Rob Clark | ba00c3f | 2016-03-16 18:18:17 -0400 | [diff] [blame] | 410 | |
Rob Clark | 0b776d4 | 2015-01-30 17:04:45 -0500 | [diff] [blame] | 411 | kms->funcs->prepare_commit(kms, state); |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 412 | |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 413 | msm_atomic_helper_commit_modeset_disables(dev, state); |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 414 | |
Liu Ying | 2b58e98 | 2016-08-29 17:12:03 +0800 | [diff] [blame] | 415 | drm_atomic_helper_commit_planes(dev, state, 0); |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 416 | |
Lloyd Atkinson | af7952d | 2016-06-26 22:41:26 -0400 | [diff] [blame] | 417 | msm_atomic_helper_commit_modeset_enables(dev, state); |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 418 | |
Rob Clark | f86afec | 2014-11-25 12:41:18 -0500 | [diff] [blame] | 419 | /* NOTE: _wait_for_vblanks() only waits for vblank on |
| 420 | * enabled CRTCs. So we end up faulting when disabling |
| 421 | * due to (potentially) unref'ing the outgoing fb's |
| 422 | * before the vblank when the disable has latched. |
| 423 | * |
| 424 | * But if it did wait on disabled (or newly disabled) |
| 425 | * CRTCs, that would be racy (ie. we could have missed |
| 426 | * the irq. We need some way to poll for pipe shut |
| 427 | * down. Or just live with occasionally hitting the |
| 428 | * timeout in the CRTC disable path (which really should |
| 429 | * not be critical path) |
| 430 | */ |
| 431 | |
Lloyd Atkinson | 940340d | 2016-12-09 14:49:37 -0500 | [diff] [blame] | 432 | msm_atomic_wait_for_commit_done(dev, state); |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 433 | |
| 434 | drm_atomic_helper_cleanup_planes(dev, state); |
| 435 | |
Rob Clark | 0b776d4 | 2015-01-30 17:04:45 -0500 | [diff] [blame] | 436 | kms->funcs->complete_commit(kms, state); |
| 437 | |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 438 | drm_atomic_state_free(state); |
| 439 | |
Rob Clark | 0b776d4 | 2015-01-30 17:04:45 -0500 | [diff] [blame] | 440 | commit_destroy(c); |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 441 | } |
| 442 | |
Sandeep Panda | f48c46a | 2016-10-24 09:48:50 +0530 | [diff] [blame] | 443 | static void _msm_drm_commit_work_cb(struct kthread_work *work) |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 444 | { |
Sandeep Panda | f48c46a | 2016-10-24 09:48:50 +0530 | [diff] [blame] | 445 | struct msm_commit *commit = NULL; |
| 446 | |
| 447 | if (!work) { |
| 448 | DRM_ERROR("%s: Invalid commit work data!\n", __func__); |
| 449 | return; |
| 450 | } |
| 451 | |
| 452 | commit = container_of(work, struct msm_commit, commit_work); |
| 453 | |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 454 | SDE_ATRACE_BEGIN("complete_commit"); |
Sandeep Panda | f48c46a | 2016-10-24 09:48:50 +0530 | [diff] [blame] | 455 | complete_commit(commit); |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 456 | SDE_ATRACE_END("complete_commit"); |
Sandeep Panda | f48c46a | 2016-10-24 09:48:50 +0530 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static struct msm_commit *commit_init(struct drm_atomic_state *state) |
| 460 | { |
| 461 | struct msm_commit *c = kzalloc(sizeof(*c), GFP_KERNEL); |
| 462 | |
| 463 | if (!c) |
| 464 | return NULL; |
| 465 | |
| 466 | c->dev = state->dev; |
| 467 | c->state = state; |
| 468 | |
| 469 | kthread_init_work(&c->commit_work, _msm_drm_commit_work_cb); |
| 470 | |
| 471 | return c; |
| 472 | } |
| 473 | |
| 474 | /* Start display thread function */ |
| 475 | static int msm_atomic_commit_dispatch(struct drm_device *dev, |
| 476 | struct drm_atomic_state *state, struct msm_commit *commit) |
| 477 | { |
| 478 | struct msm_drm_private *priv = dev->dev_private; |
| 479 | struct drm_crtc *crtc = NULL; |
| 480 | struct drm_crtc_state *crtc_state = NULL; |
| 481 | int ret = -EINVAL, i = 0, j = 0; |
| 482 | |
| 483 | for_each_crtc_in_state(state, crtc, crtc_state, i) { |
| 484 | for (j = 0; j < priv->num_crtcs; j++) { |
| 485 | if (priv->disp_thread[j].crtc_id == |
| 486 | crtc->base.id) { |
| 487 | if (priv->disp_thread[j].thread) { |
| 488 | kthread_queue_work( |
| 489 | &priv->disp_thread[j].worker, |
| 490 | &commit->commit_work); |
| 491 | /* only return zero if work is |
| 492 | * queued successfully. |
| 493 | */ |
| 494 | ret = 0; |
| 495 | } else { |
| 496 | DRM_ERROR(" Error for crtc_id: %d\n", |
| 497 | priv->disp_thread[j].crtc_id); |
| 498 | } |
| 499 | break; |
| 500 | } |
| 501 | } |
| 502 | /* |
| 503 | * TODO: handle cases where there will be more than |
| 504 | * one crtc per commit cycle. Remove this check then. |
| 505 | * Current assumption is there will be only one crtc |
| 506 | * per commit cycle. |
| 507 | */ |
| 508 | if (j < priv->num_crtcs) |
| 509 | break; |
| 510 | } |
| 511 | |
| 512 | return ret; |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 513 | } |
| 514 | |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 515 | /** |
| 516 | * drm_atomic_helper_commit - commit validated state object |
| 517 | * @dev: DRM device |
| 518 | * @state: the driver state object |
Maarten Lankhorst | a3ccfb9 | 2016-04-26 16:11:38 +0200 | [diff] [blame] | 519 | * @nonblock: nonblocking commit |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 520 | * |
| 521 | * This function commits a with drm_atomic_helper_check() pre-validated state |
Maarten Lankhorst | a3ccfb9 | 2016-04-26 16:11:38 +0200 | [diff] [blame] | 522 | * object. This can still fail when e.g. the framebuffer reservation fails. |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 523 | * |
| 524 | * RETURNS |
| 525 | * Zero for success or -errno. |
| 526 | */ |
| 527 | int msm_atomic_commit(struct drm_device *dev, |
Maarten Lankhorst | a3ccfb9 | 2016-04-26 16:11:38 +0200 | [diff] [blame] | 528 | struct drm_atomic_state *state, bool nonblock) |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 529 | { |
Rob Clark | ca762a8 | 2016-03-15 17:22:13 -0400 | [diff] [blame] | 530 | struct msm_drm_private *priv = dev->dev_private; |
Rob Clark | f86afec | 2014-11-25 12:41:18 -0500 | [diff] [blame] | 531 | struct msm_commit *c; |
Daniel Vetter | 8d76b79 | 2016-06-02 15:41:53 +0200 | [diff] [blame] | 532 | struct drm_crtc *crtc; |
| 533 | struct drm_crtc_state *crtc_state; |
| 534 | struct drm_plane *plane; |
| 535 | struct drm_plane_state *plane_state; |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 536 | int i, ret; |
| 537 | |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 538 | SDE_ATRACE_BEGIN("atomic_commit"); |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 539 | ret = drm_atomic_helper_prepare_planes(dev, state); |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 540 | if (ret) { |
| 541 | SDE_ATRACE_END("atomic_commit"); |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 542 | return ret; |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 543 | } |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 544 | |
Rob Clark | 0b776d4 | 2015-01-30 17:04:45 -0500 | [diff] [blame] | 545 | c = commit_init(state); |
Laurent Pinchart | f65c18c | 2015-05-27 14:39:46 +0300 | [diff] [blame] | 546 | if (!c) { |
| 547 | ret = -ENOMEM; |
| 548 | goto error; |
| 549 | } |
Rob Clark | f86afec | 2014-11-25 12:41:18 -0500 | [diff] [blame] | 550 | |
| 551 | /* |
| 552 | * Figure out what crtcs we have: |
| 553 | */ |
Daniel Vetter | 8d76b79 | 2016-06-02 15:41:53 +0200 | [diff] [blame] | 554 | for_each_crtc_in_state(state, crtc, crtc_state, i) |
| 555 | c->crtc_mask |= drm_crtc_mask(crtc); |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 556 | |
| 557 | /* |
Rob Clark | b6295f9 | 2016-03-15 18:26:28 -0400 | [diff] [blame] | 558 | * Figure out what fence to wait for: |
| 559 | */ |
Daniel Vetter | 8d76b79 | 2016-06-02 15:41:53 +0200 | [diff] [blame] | 560 | for_each_plane_in_state(state, plane, plane_state, i) { |
| 561 | if ((plane->state->fb != plane_state->fb) && plane_state->fb) { |
| 562 | struct drm_gem_object *obj = msm_framebuffer_bo(plane_state->fb, 0); |
Rob Clark | b6295f9 | 2016-03-15 18:26:28 -0400 | [diff] [blame] | 563 | struct msm_gem_object *msm_obj = to_msm_bo(obj); |
| 564 | |
Daniel Vetter | 8d76b79 | 2016-06-02 15:41:53 +0200 | [diff] [blame] | 565 | plane_state->fence = reservation_object_get_excl_rcu(msm_obj->resv); |
Rob Clark | b6295f9 | 2016-03-15 18:26:28 -0400 | [diff] [blame] | 566 | } |
| 567 | } |
| 568 | |
| 569 | /* |
Rob Clark | f86afec | 2014-11-25 12:41:18 -0500 | [diff] [blame] | 570 | * Wait for pending updates on any of the same crtc's and then |
| 571 | * mark our set of crtc's as busy: |
| 572 | */ |
| 573 | ret = start_atomic(dev->dev_private, c->crtc_mask); |
Laurent Pinchart | 5b2e2b6 | 2015-02-23 00:58:03 +0200 | [diff] [blame] | 574 | if (ret) { |
| 575 | kfree(c); |
Laurent Pinchart | f65c18c | 2015-05-27 14:39:46 +0300 | [diff] [blame] | 576 | goto error; |
Laurent Pinchart | 5b2e2b6 | 2015-02-23 00:58:03 +0200 | [diff] [blame] | 577 | } |
Rob Clark | f86afec | 2014-11-25 12:41:18 -0500 | [diff] [blame] | 578 | |
| 579 | /* |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 580 | * This is the point of no return - everything below never fails except |
| 581 | * when the hw goes bonghits. Which means we can commit the new state on |
| 582 | * the software side now. |
| 583 | */ |
| 584 | |
Daniel Vetter | 5e84c26 | 2016-06-10 00:06:32 +0200 | [diff] [blame] | 585 | drm_atomic_helper_swap_state(state, true); |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 586 | |
| 587 | /* |
Clarence Ip | 24f8066 | 2016-06-13 19:05:32 -0400 | [diff] [blame] | 588 | * Provide the driver a chance to prepare for output fences. This is |
| 589 | * done after the point of no return, but before asynchronous commits |
| 590 | * are dispatched to work queues, so that the fence preparation is |
| 591 | * finished before the .atomic_commit returns. |
| 592 | */ |
| 593 | if (priv && priv->kms && priv->kms->funcs && |
| 594 | priv->kms->funcs->prepare_fence) |
| 595 | priv->kms->funcs->prepare_fence(priv->kms, state); |
| 596 | |
| 597 | /* |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 598 | * Everything below can be run asynchronously without the need to grab |
| 599 | * any modeset locks at all under one conditions: It must be guaranteed |
| 600 | * that the asynchronous work has either been cancelled (if the driver |
| 601 | * supports it, which at least requires that the framebuffers get |
| 602 | * cleaned up with drm_atomic_helper_cleanup_planes()) or completed |
| 603 | * before the new state gets committed on the software side with |
| 604 | * drm_atomic_helper_swap_state(). |
| 605 | * |
| 606 | * This scheme allows new atomic state updates to be prepared and |
| 607 | * checked in parallel to the asynchronous completion of the previous |
| 608 | * update. Which is important since compositors need to figure out the |
| 609 | * composition of the next frame right after having submitted the |
| 610 | * current layout. |
| 611 | */ |
| 612 | |
Rob Clark | ba00c3f | 2016-03-16 18:18:17 -0400 | [diff] [blame] | 613 | if (nonblock) { |
Sandeep Panda | f48c46a | 2016-10-24 09:48:50 +0530 | [diff] [blame] | 614 | ret = msm_atomic_commit_dispatch(dev, state, c); |
| 615 | if (ret) { |
| 616 | DRM_ERROR("%s: atomic commit failed\n", __func__); |
| 617 | drm_atomic_state_free(state); |
| 618 | commit_destroy(c); |
| 619 | goto error; |
| 620 | } |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 621 | SDE_ATRACE_END("atomic_commit"); |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 622 | return 0; |
| 623 | } |
| 624 | |
Sandeep Panda | f48c46a | 2016-10-24 09:48:50 +0530 | [diff] [blame] | 625 | complete_commit(c); |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 626 | |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 627 | SDE_ATRACE_END("atomic_commit"); |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 628 | return 0; |
Laurent Pinchart | f65c18c | 2015-05-27 14:39:46 +0300 | [diff] [blame] | 629 | |
| 630 | error: |
| 631 | drm_atomic_helper_cleanup_planes(dev, state); |
Narendra Muppalla | 77b3293 | 2017-05-10 13:53:11 -0700 | [diff] [blame] | 632 | SDE_ATRACE_END("atomic_commit"); |
Laurent Pinchart | f65c18c | 2015-05-27 14:39:46 +0300 | [diff] [blame] | 633 | return ret; |
Rob Clark | cf3a7e4 | 2014-11-08 13:21:06 -0500 | [diff] [blame] | 634 | } |