.. | .. |
---|
25 | 25 | * Daniel Vetter <daniel.vetter@ffwll.ch> |
---|
26 | 26 | */ |
---|
27 | 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> |
---|
32 | | -#include <drm/drm_atomic_helper.h> |
---|
33 | | -#include <drm/drm_writeback.h> |
---|
34 | 28 | #include <linux/dma-fence.h> |
---|
| 29 | +#include <linux/ktime.h> |
---|
| 30 | + |
---|
| 31 | +#include <drm/drm_atomic.h> |
---|
| 32 | +#include <drm/drm_atomic_helper.h> |
---|
| 33 | +#include <drm/drm_atomic_uapi.h> |
---|
| 34 | +#include <drm/drm_bridge.h> |
---|
| 35 | +#include <drm/drm_damage_helper.h> |
---|
| 36 | +#include <drm/drm_device.h> |
---|
| 37 | +#include <drm/drm_drv.h> |
---|
| 38 | +#include <drm/drm_plane_helper.h> |
---|
| 39 | +#include <drm/drm_print.h> |
---|
| 40 | +#include <drm/drm_self_refresh_helper.h> |
---|
| 41 | +#include <drm/drm_vblank.h> |
---|
| 42 | +#include <drm/drm_writeback.h> |
---|
35 | 43 | |
---|
36 | 44 | #include "drm_crtc_helper_internal.h" |
---|
37 | 45 | #include "drm_crtc_internal.h" |
---|
.. | .. |
---|
118 | 126 | else if (funcs->best_encoder) |
---|
119 | 127 | new_encoder = funcs->best_encoder(connector); |
---|
120 | 128 | else |
---|
121 | | - new_encoder = drm_atomic_helper_best_encoder(connector); |
---|
| 129 | + new_encoder = drm_connector_get_single_encoder(connector); |
---|
122 | 130 | |
---|
123 | 131 | if (new_encoder) { |
---|
124 | 132 | if (encoder_mask & drm_encoder_mask(new_encoder)) { |
---|
.. | .. |
---|
143 | 151 | * is not set, an error is returned. Userspace can provide a solution |
---|
144 | 152 | * through the atomic ioctl. |
---|
145 | 153 | * |
---|
146 | | - * If the flag is set conflicting connectors are removed from the crtc |
---|
147 | | - * and the crtc is disabled if no encoder is left. This preserves |
---|
| 154 | + * If the flag is set conflicting connectors are removed from the CRTC |
---|
| 155 | + * and the CRTC is disabled if no encoder is left. This preserves |
---|
148 | 156 | * compatibility with the legacy set_config behavior. |
---|
149 | 157 | */ |
---|
150 | 158 | drm_connector_list_iter_begin(state->dev, &conn_iter); |
---|
.. | .. |
---|
213 | 221 | crtc = conn_state->connector->state->crtc; |
---|
214 | 222 | |
---|
215 | 223 | /* A NULL crtc is an error here because we should have |
---|
216 | | - * duplicated a NULL best_encoder when crtc was NULL. |
---|
| 224 | + * duplicated a NULL best_encoder when crtc was NULL. |
---|
217 | 225 | * As an exception restoring duplicated atomic state |
---|
218 | 226 | * during resume is allowed, so don't warn when |
---|
219 | 227 | * best_encoder is equal to encoder we intend to set. |
---|
.. | .. |
---|
288 | 296 | if (old_connector_state->crtc != new_connector_state->crtc) { |
---|
289 | 297 | if (old_connector_state->crtc) { |
---|
290 | 298 | crtc_state = drm_atomic_get_new_crtc_state(state, old_connector_state->crtc); |
---|
291 | | - if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) |
---|
292 | | - crtc_state->connectors_changed = true; |
---|
| 299 | + crtc_state->connectors_changed = true; |
---|
293 | 300 | } |
---|
294 | 301 | |
---|
295 | 302 | if (new_connector_state->crtc) { |
---|
296 | 303 | crtc_state = drm_atomic_get_new_crtc_state(state, new_connector_state->crtc); |
---|
297 | | - if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) |
---|
298 | | - crtc_state->connectors_changed = true; |
---|
| 304 | + crtc_state->connectors_changed = true; |
---|
299 | 305 | } |
---|
300 | 306 | } |
---|
301 | 307 | |
---|
.. | .. |
---|
320 | 326 | * Since the connector can be unregistered at any point during an |
---|
321 | 327 | * atomic check or commit, this is racy. But that's OK: all we care |
---|
322 | 328 | * about is ensuring that userspace can't do anything but shut off the |
---|
323 | | - * display on a connector that was destroyed after its been notified, |
---|
| 329 | + * display on a connector that was destroyed after it's been notified, |
---|
324 | 330 | * not before. |
---|
| 331 | + * |
---|
| 332 | + * Additionally, we also want to ignore connector registration when |
---|
| 333 | + * we're trying to restore an atomic state during system resume since |
---|
| 334 | + * there's a chance the connector may have been destroyed during the |
---|
| 335 | + * process, but it's better to ignore that then cause |
---|
| 336 | + * drm_atomic_helper_resume() to fail. |
---|
325 | 337 | */ |
---|
326 | | - if (drm_connector_is_unregistered(connector) && crtc_state->active) { |
---|
| 338 | + if (!state->duplicated && drm_connector_is_unregistered(connector) && |
---|
| 339 | + crtc_state->active) { |
---|
327 | 340 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] is not registered\n", |
---|
328 | 341 | connector->base.id, connector->name); |
---|
329 | 342 | return -EINVAL; |
---|
.. | .. |
---|
337 | 350 | else if (funcs->best_encoder) |
---|
338 | 351 | new_encoder = funcs->best_encoder(connector); |
---|
339 | 352 | else |
---|
340 | | - new_encoder = drm_atomic_helper_best_encoder(connector); |
---|
| 353 | + new_encoder = drm_connector_get_single_encoder(connector); |
---|
341 | 354 | |
---|
342 | 355 | if (!new_encoder) { |
---|
343 | 356 | DRM_DEBUG_ATOMIC("No suitable encoder found for [CONNECTOR:%d:%s]\n", |
---|
.. | .. |
---|
373 | 386 | |
---|
374 | 387 | set_best_encoder(state, new_connector_state, new_encoder); |
---|
375 | 388 | |
---|
376 | | - if (connector->connector_type != DRM_MODE_CONNECTOR_WRITEBACK) |
---|
377 | | - crtc_state->connectors_changed = true; |
---|
| 389 | + crtc_state->connectors_changed = true; |
---|
378 | 390 | |
---|
379 | 391 | DRM_DEBUG_ATOMIC("[CONNECTOR:%d:%s] using [ENCODER:%d:%s] on [CRTC:%d:%s]\n", |
---|
380 | 392 | connector->base.id, |
---|
.. | .. |
---|
408 | 420 | for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
---|
409 | 421 | const struct drm_encoder_helper_funcs *funcs; |
---|
410 | 422 | struct drm_encoder *encoder; |
---|
| 423 | + struct drm_bridge *bridge; |
---|
411 | 424 | |
---|
412 | 425 | WARN_ON(!!new_conn_state->best_encoder != !!new_conn_state->crtc); |
---|
413 | 426 | |
---|
.. | .. |
---|
424 | 437 | encoder = new_conn_state->best_encoder; |
---|
425 | 438 | funcs = encoder->helper_private; |
---|
426 | 439 | |
---|
427 | | - ret = drm_bridge_mode_fixup(encoder->bridge, &new_crtc_state->mode, |
---|
428 | | - &new_crtc_state->adjusted_mode); |
---|
429 | | - if (!ret) { |
---|
430 | | - DRM_DEBUG_ATOMIC("Bridge fixup failed\n"); |
---|
431 | | - return -EINVAL; |
---|
| 440 | + bridge = drm_bridge_chain_get_first_bridge(encoder); |
---|
| 441 | + ret = drm_atomic_bridge_chain_check(bridge, |
---|
| 442 | + new_crtc_state, |
---|
| 443 | + new_conn_state); |
---|
| 444 | + if (ret) { |
---|
| 445 | + DRM_DEBUG_ATOMIC("Bridge atomic check failed\n"); |
---|
| 446 | + return ret; |
---|
432 | 447 | } |
---|
433 | 448 | |
---|
434 | 449 | if (funcs && funcs->atomic_check) { |
---|
.. | .. |
---|
461 | 476 | continue; |
---|
462 | 477 | |
---|
463 | 478 | funcs = crtc->helper_private; |
---|
464 | | - if (!funcs->mode_fixup) |
---|
| 479 | + if (!funcs || !funcs->mode_fixup) |
---|
465 | 480 | continue; |
---|
466 | 481 | |
---|
467 | 482 | ret = funcs->mode_fixup(crtc, &new_crtc_state->mode, |
---|
.. | .. |
---|
479 | 494 | static enum drm_mode_status mode_valid_path(struct drm_connector *connector, |
---|
480 | 495 | struct drm_encoder *encoder, |
---|
481 | 496 | struct drm_crtc *crtc, |
---|
482 | | - struct drm_display_mode *mode) |
---|
| 497 | + const struct drm_display_mode *mode) |
---|
483 | 498 | { |
---|
| 499 | + struct drm_bridge *bridge; |
---|
484 | 500 | enum drm_mode_status ret; |
---|
485 | 501 | |
---|
486 | 502 | ret = drm_encoder_mode_valid(encoder, mode); |
---|
.. | .. |
---|
490 | 506 | return ret; |
---|
491 | 507 | } |
---|
492 | 508 | |
---|
493 | | - ret = drm_bridge_mode_valid(encoder->bridge, mode); |
---|
| 509 | + bridge = drm_bridge_chain_get_first_bridge(encoder); |
---|
| 510 | + ret = drm_bridge_chain_mode_valid(bridge, &connector->display_info, |
---|
| 511 | + mode); |
---|
494 | 512 | if (ret != MODE_OK) { |
---|
495 | 513 | DRM_DEBUG_ATOMIC("[BRIDGE] mode_valid() failed\n"); |
---|
496 | 514 | return ret; |
---|
.. | .. |
---|
518 | 536 | struct drm_crtc *crtc = conn_state->crtc; |
---|
519 | 537 | struct drm_crtc_state *crtc_state; |
---|
520 | 538 | enum drm_mode_status mode_status; |
---|
521 | | - struct drm_display_mode *mode; |
---|
| 539 | + const struct drm_display_mode *mode; |
---|
522 | 540 | |
---|
523 | 541 | if (!crtc || !encoder) |
---|
524 | 542 | continue; |
---|
.. | .. |
---|
545 | 563 | * @state: the driver state object |
---|
546 | 564 | * |
---|
547 | 565 | * Check the state object to see if the requested state is physically possible. |
---|
548 | | - * This does all the crtc and connector related computations for an atomic |
---|
| 566 | + * This does all the CRTC and connector related computations for an atomic |
---|
549 | 567 | * update and adds any additional connectors needed for full modesets. It calls |
---|
550 | 568 | * the various per-object callbacks in the follow order: |
---|
551 | 569 | * |
---|
552 | 570 | * 1. &drm_connector_helper_funcs.atomic_best_encoder for determining the new encoder. |
---|
553 | 571 | * 2. &drm_connector_helper_funcs.atomic_check to validate the connector state. |
---|
554 | | - * 3. If it's determined a modeset is needed then all connectors on the affected crtc |
---|
555 | | - * crtc are added and &drm_connector_helper_funcs.atomic_check is run on them. |
---|
| 572 | + * 3. If it's determined a modeset is needed then all connectors on the affected |
---|
| 573 | + * CRTC are added and &drm_connector_helper_funcs.atomic_check is run on them. |
---|
556 | 574 | * 4. &drm_encoder_helper_funcs.mode_valid, &drm_bridge_funcs.mode_valid and |
---|
557 | 575 | * &drm_crtc_helper_funcs.mode_valid are called on the affected components. |
---|
558 | 576 | * 5. &drm_bridge_funcs.mode_fixup is called on all encoder bridges. |
---|
559 | 577 | * 6. &drm_encoder_helper_funcs.atomic_check is called to validate any encoder state. |
---|
560 | | - * This function is only called when the encoder will be part of a configured crtc, |
---|
| 578 | + * This function is only called when the encoder will be part of a configured CRTC, |
---|
561 | 579 | * it must not be used for implementing connector property validation. |
---|
562 | 580 | * If this function is NULL, &drm_atomic_encoder_helper_funcs.mode_fixup is called |
---|
563 | 581 | * instead. |
---|
564 | | - * 7. &drm_crtc_helper_funcs.mode_fixup is called last, to fix up the mode with crtc constraints. |
---|
| 582 | + * 7. &drm_crtc_helper_funcs.mode_fixup is called last, to fix up the mode with CRTC constraints. |
---|
565 | 583 | * |
---|
566 | 584 | * &drm_crtc_state.mode_changed is set when the input mode is changed. |
---|
567 | 585 | * &drm_crtc_state.connectors_changed is set when a connector is added or |
---|
568 | | - * removed from the crtc. &drm_crtc_state.active_changed is set when |
---|
| 586 | + * removed from the CRTC. &drm_crtc_state.active_changed is set when |
---|
569 | 587 | * &drm_crtc_state.active changes, which is used for DPMS. |
---|
| 588 | + * &drm_crtc_state.no_vblank is set from the result of drm_dev_has_vblank(). |
---|
570 | 589 | * See also: drm_atomic_crtc_needs_modeset() |
---|
571 | 590 | * |
---|
572 | 591 | * IMPORTANT: |
---|
.. | .. |
---|
633 | 652 | |
---|
634 | 653 | return -EINVAL; |
---|
635 | 654 | } |
---|
| 655 | + |
---|
| 656 | + if (drm_dev_has_vblank(dev)) |
---|
| 657 | + new_crtc_state->no_vblank = false; |
---|
| 658 | + else |
---|
| 659 | + new_crtc_state->no_vblank = true; |
---|
636 | 660 | } |
---|
637 | 661 | |
---|
638 | 662 | ret = handle_conflicting_encoders(state, false); |
---|
.. | .. |
---|
660 | 684 | if (old_connector_state->link_status != |
---|
661 | 685 | new_connector_state->link_status) |
---|
662 | 686 | new_crtc_state->connectors_changed = true; |
---|
| 687 | + |
---|
| 688 | + if (old_connector_state->max_requested_bpc != |
---|
| 689 | + new_connector_state->max_requested_bpc) |
---|
| 690 | + new_crtc_state->connectors_changed = true; |
---|
663 | 691 | } |
---|
664 | 692 | |
---|
665 | 693 | if (funcs->atomic_check) |
---|
.. | .. |
---|
672 | 700 | |
---|
673 | 701 | /* |
---|
674 | 702 | * After all the routing has been prepared we need to add in any |
---|
675 | | - * connector which is itself unchanged, but who's crtc changes it's |
---|
| 703 | + * connector which is itself unchanged, but whose CRTC changes its |
---|
676 | 704 | * configuration. This must be done before calling mode_fixup in case a |
---|
677 | 705 | * crtc only changed its mode but has the same set of connectors. |
---|
678 | 706 | */ |
---|
.. | .. |
---|
710 | 738 | return ret; |
---|
711 | 739 | } |
---|
712 | 740 | |
---|
| 741 | + /* |
---|
| 742 | + * Iterate over all connectors again, and add all affected bridges to |
---|
| 743 | + * the state. |
---|
| 744 | + */ |
---|
| 745 | + for_each_oldnew_connector_in_state(state, connector, |
---|
| 746 | + old_connector_state, |
---|
| 747 | + new_connector_state, i) { |
---|
| 748 | + struct drm_encoder *encoder; |
---|
| 749 | + |
---|
| 750 | + encoder = old_connector_state->best_encoder; |
---|
| 751 | + ret = drm_atomic_add_encoder_bridges(state, encoder); |
---|
| 752 | + if (ret) |
---|
| 753 | + return ret; |
---|
| 754 | + |
---|
| 755 | + encoder = new_connector_state->best_encoder; |
---|
| 756 | + ret = drm_atomic_add_encoder_bridges(state, encoder); |
---|
| 757 | + if (ret) |
---|
| 758 | + return ret; |
---|
| 759 | + } |
---|
| 760 | + |
---|
713 | 761 | ret = mode_valid(state); |
---|
714 | 762 | if (ret) |
---|
715 | 763 | return ret; |
---|
.. | .. |
---|
721 | 769 | /** |
---|
722 | 770 | * drm_atomic_helper_check_plane_state() - Check plane state for validity |
---|
723 | 771 | * @plane_state: plane state to check |
---|
724 | | - * @crtc_state: crtc state to check |
---|
| 772 | + * @crtc_state: CRTC state to check |
---|
725 | 773 | * @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point |
---|
726 | 774 | * @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point |
---|
727 | 775 | * @can_position: is it legal to position the plane such that it |
---|
728 | | - * doesn't cover the entire crtc? This will generally |
---|
| 776 | + * doesn't cover the entire CRTC? This will generally |
---|
729 | 777 | * only be false for primary planes. |
---|
730 | | - * @can_update_disabled: can the plane be updated while the crtc |
---|
| 778 | + * @can_update_disabled: can the plane be updated while the CRTC |
---|
731 | 779 | * is disabled? |
---|
732 | 780 | * |
---|
733 | 781 | * Checks that a desired plane update is valid, and updates various |
---|
.. | .. |
---|
824 | 872 | * &drm_crtc_helper_funcs.atomic_check and &drm_plane_helper_funcs.atomic_check |
---|
825 | 873 | * hooks provided by the driver. |
---|
826 | 874 | * |
---|
827 | | - * It also sets &drm_crtc_state.planes_changed to indicate that a crtc has |
---|
| 875 | + * It also sets &drm_crtc_state.planes_changed to indicate that a CRTC has |
---|
828 | 876 | * updated planes. |
---|
829 | 877 | * |
---|
830 | 878 | * RETURNS: |
---|
.. | .. |
---|
848 | 896 | funcs = plane->helper_private; |
---|
849 | 897 | |
---|
850 | 898 | drm_atomic_helper_plane_changed(state, old_plane_state, new_plane_state, plane); |
---|
| 899 | + |
---|
| 900 | + drm_atomic_helper_check_plane_damage(state, new_plane_state); |
---|
851 | 901 | |
---|
852 | 902 | if (!funcs || !funcs->atomic_check) |
---|
853 | 903 | continue; |
---|
.. | .. |
---|
886 | 936 | * @state: the driver state object |
---|
887 | 937 | * |
---|
888 | 938 | * Check the state object to see if the requested state is physically possible. |
---|
889 | | - * Only crtcs and planes have check callbacks, so for any additional (global) |
---|
| 939 | + * Only CRTCs and planes have check callbacks, so for any additional (global) |
---|
890 | 940 | * checking that a driver needs it can simply wrap that around this function. |
---|
891 | 941 | * Drivers without such needs can directly use this as their |
---|
892 | 942 | * &drm_mode_config_funcs.atomic_check callback. |
---|
.. | .. |
---|
928 | 978 | if (state->legacy_cursor_update) |
---|
929 | 979 | state->async_update = !drm_atomic_helper_async_check(dev, state); |
---|
930 | 980 | |
---|
| 981 | + drm_self_refresh_helper_alter_state(state); |
---|
| 982 | + |
---|
931 | 983 | return ret; |
---|
932 | 984 | } |
---|
933 | 985 | EXPORT_SYMBOL(drm_atomic_helper_check); |
---|
| 986 | + |
---|
| 987 | +static bool |
---|
| 988 | +crtc_needs_disable(struct drm_crtc_state *old_state, |
---|
| 989 | + struct drm_crtc_state *new_state) |
---|
| 990 | +{ |
---|
| 991 | + /* |
---|
| 992 | + * No new_state means the CRTC is off, so the only criteria is whether |
---|
| 993 | + * it's currently active or in self refresh mode. |
---|
| 994 | + */ |
---|
| 995 | + if (!new_state) |
---|
| 996 | + return drm_atomic_crtc_effectively_active(old_state); |
---|
| 997 | + |
---|
| 998 | + /* |
---|
| 999 | + * We need to disable bridge(s) and CRTC if we're transitioning out of |
---|
| 1000 | + * self-refresh and changing CRTCs at the same time, because the |
---|
| 1001 | + * bridge tracks self-refresh status via CRTC state. |
---|
| 1002 | + */ |
---|
| 1003 | + if (old_state->self_refresh_active && |
---|
| 1004 | + old_state->crtc != new_state->crtc) |
---|
| 1005 | + return true; |
---|
| 1006 | + |
---|
| 1007 | + /* |
---|
| 1008 | + * We also need to run through the crtc_funcs->disable() function if |
---|
| 1009 | + * the CRTC is currently on, if it's transitioning to self refresh |
---|
| 1010 | + * mode, or if it's in self refresh mode and needs to be fully |
---|
| 1011 | + * disabled. |
---|
| 1012 | + */ |
---|
| 1013 | + return old_state->active || |
---|
| 1014 | + (old_state->self_refresh_active && !new_state->enable) || |
---|
| 1015 | + new_state->self_refresh_active; |
---|
| 1016 | +} |
---|
934 | 1017 | |
---|
935 | 1018 | static void |
---|
936 | 1019 | disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state) |
---|
.. | .. |
---|
943 | 1026 | |
---|
944 | 1027 | for_each_oldnew_connector_in_state(old_state, connector, old_conn_state, new_conn_state, i) { |
---|
945 | 1028 | const struct drm_encoder_helper_funcs *funcs; |
---|
946 | | - const struct drm_connector_helper_funcs *conn_funcs; |
---|
947 | 1029 | struct drm_encoder *encoder; |
---|
| 1030 | + struct drm_bridge *bridge; |
---|
948 | 1031 | |
---|
949 | 1032 | /* Shut down everything that's in the changeset and currently |
---|
950 | 1033 | * still on. So need to check the old, saved state. */ |
---|
.. | .. |
---|
953 | 1036 | |
---|
954 | 1037 | old_crtc_state = drm_atomic_get_old_crtc_state(old_state, old_conn_state->crtc); |
---|
955 | 1038 | |
---|
956 | | - if (!old_crtc_state->active || |
---|
| 1039 | + if (new_conn_state->crtc) |
---|
| 1040 | + new_crtc_state = drm_atomic_get_new_crtc_state( |
---|
| 1041 | + old_state, |
---|
| 1042 | + new_conn_state->crtc); |
---|
| 1043 | + else |
---|
| 1044 | + new_crtc_state = NULL; |
---|
| 1045 | + |
---|
| 1046 | + if (!crtc_needs_disable(old_crtc_state, new_crtc_state) || |
---|
957 | 1047 | !drm_atomic_crtc_needs_modeset(old_conn_state->crtc->state)) |
---|
958 | 1048 | continue; |
---|
959 | 1049 | |
---|
.. | .. |
---|
970 | 1060 | DRM_DEBUG_ATOMIC("disabling [ENCODER:%d:%s]\n", |
---|
971 | 1061 | encoder->base.id, encoder->name); |
---|
972 | 1062 | |
---|
973 | | - conn_funcs = connector->helper_private; |
---|
974 | | - if (connector->loader_protect) { |
---|
975 | | - drm_bridge_pre_enable(encoder->bridge); |
---|
976 | | - |
---|
977 | | - if (funcs->enable) |
---|
978 | | - funcs->enable(encoder); |
---|
979 | | - else |
---|
980 | | - funcs->commit(encoder); |
---|
981 | | - |
---|
982 | | - drm_bridge_enable(encoder->bridge); |
---|
983 | | - |
---|
984 | | - if (conn_funcs->loader_protect) |
---|
985 | | - conn_funcs->loader_protect(connector, false); |
---|
986 | | - connector->loader_protect = false; |
---|
987 | | - } |
---|
988 | 1063 | /* |
---|
989 | 1064 | * Each encoder has at most one connector (since we always steal |
---|
990 | 1065 | * it away), so we won't call disable hooks twice. |
---|
991 | 1066 | */ |
---|
992 | | - drm_bridge_disable(encoder->bridge); |
---|
| 1067 | + bridge = drm_bridge_chain_get_first_bridge(encoder); |
---|
| 1068 | + drm_atomic_bridge_chain_disable(bridge, old_state); |
---|
993 | 1069 | |
---|
994 | | - if (encoder->loader_protect) { |
---|
995 | | - if (funcs->loader_protect) |
---|
996 | | - funcs->loader_protect(encoder, false); |
---|
997 | | - encoder->loader_protect = false; |
---|
998 | | - } |
---|
999 | 1070 | /* Right function depends upon target state. */ |
---|
1000 | 1071 | if (funcs) { |
---|
1001 | | - if (new_conn_state->crtc && funcs->prepare) |
---|
| 1072 | + if (funcs->atomic_disable) |
---|
| 1073 | + funcs->atomic_disable(encoder, old_state); |
---|
| 1074 | + else if (new_conn_state->crtc && funcs->prepare) |
---|
1002 | 1075 | funcs->prepare(encoder); |
---|
1003 | 1076 | else if (funcs->disable) |
---|
1004 | 1077 | funcs->disable(encoder); |
---|
.. | .. |
---|
1006 | 1079 | funcs->dpms(encoder, DRM_MODE_DPMS_OFF); |
---|
1007 | 1080 | } |
---|
1008 | 1081 | |
---|
1009 | | - drm_bridge_post_disable(encoder->bridge); |
---|
| 1082 | + drm_atomic_bridge_chain_post_disable(bridge, old_state); |
---|
1010 | 1083 | } |
---|
1011 | 1084 | |
---|
1012 | 1085 | for_each_oldnew_crtc_in_state(old_state, crtc, old_crtc_state, new_crtc_state, i) { |
---|
.. | .. |
---|
1017 | 1090 | if (!drm_atomic_crtc_needs_modeset(new_crtc_state)) |
---|
1018 | 1091 | continue; |
---|
1019 | 1092 | |
---|
1020 | | - if (!old_crtc_state->active) |
---|
| 1093 | + if (!crtc_needs_disable(old_crtc_state, new_crtc_state)) |
---|
1021 | 1094 | continue; |
---|
1022 | 1095 | |
---|
1023 | 1096 | funcs = crtc->helper_private; |
---|
.. | .. |
---|
1033 | 1106 | funcs->atomic_disable(crtc, old_crtc_state); |
---|
1034 | 1107 | else if (funcs->disable) |
---|
1035 | 1108 | funcs->disable(crtc); |
---|
1036 | | - else |
---|
| 1109 | + else if (funcs->dpms) |
---|
1037 | 1110 | funcs->dpms(crtc, DRM_MODE_DPMS_OFF); |
---|
1038 | 1111 | |
---|
1039 | | - if (!(dev->irq_enabled && dev->num_crtcs)) |
---|
| 1112 | + if (!drm_dev_has_vblank(dev)) |
---|
1040 | 1113 | continue; |
---|
1041 | 1114 | |
---|
1042 | 1115 | ret = drm_crtc_vblank_get(crtc); |
---|
1043 | | - WARN_ONCE(ret != -EINVAL, "driver forgot to call drm_crtc_vblank_off()\n"); |
---|
| 1116 | + /* |
---|
| 1117 | + * Self-refresh is not a true "disable"; ensure vblank remains |
---|
| 1118 | + * enabled. |
---|
| 1119 | + */ |
---|
| 1120 | + if (new_crtc_state->self_refresh_active) |
---|
| 1121 | + WARN_ONCE(ret != 0, |
---|
| 1122 | + "driver disabled vblank in self-refresh\n"); |
---|
| 1123 | + else |
---|
| 1124 | + WARN_ONCE(ret != -EINVAL, |
---|
| 1125 | + "driver forgot to call drm_crtc_vblank_off()\n"); |
---|
1044 | 1126 | if (ret == 0) |
---|
1045 | 1127 | drm_crtc_vblank_put(crtc); |
---|
1046 | 1128 | } |
---|
.. | .. |
---|
1052 | 1134 | * @old_state: atomic state object with old state structures |
---|
1053 | 1135 | * |
---|
1054 | 1136 | * This function updates all the various legacy modeset state pointers in |
---|
1055 | | - * connectors, encoders and crtcs. It also updates the timestamping constants |
---|
1056 | | - * used for precise vblank timestamps by calling |
---|
1057 | | - * drm_calc_timestamping_constants(). |
---|
| 1137 | + * connectors, encoders and CRTCs. |
---|
1058 | 1138 | * |
---|
1059 | 1139 | * Drivers can use this for building their own atomic commit if they don't have |
---|
1060 | 1140 | * a pure helper-based modeset implementation. |
---|
.. | .. |
---|
1123 | 1203 | crtc->x = new_plane_state->src_x >> 16; |
---|
1124 | 1204 | crtc->y = new_plane_state->src_y >> 16; |
---|
1125 | 1205 | } |
---|
| 1206 | + } |
---|
| 1207 | +} |
---|
| 1208 | +EXPORT_SYMBOL(drm_atomic_helper_update_legacy_modeset_state); |
---|
1126 | 1209 | |
---|
| 1210 | +/** |
---|
| 1211 | + * drm_atomic_helper_calc_timestamping_constants - update vblank timestamping constants |
---|
| 1212 | + * @state: atomic state object |
---|
| 1213 | + * |
---|
| 1214 | + * Updates the timestamping constants used for precise vblank timestamps |
---|
| 1215 | + * by calling drm_calc_timestamping_constants() for all enabled crtcs in @state. |
---|
| 1216 | + */ |
---|
| 1217 | +void drm_atomic_helper_calc_timestamping_constants(struct drm_atomic_state *state) |
---|
| 1218 | +{ |
---|
| 1219 | + struct drm_crtc_state *new_crtc_state; |
---|
| 1220 | + struct drm_crtc *crtc; |
---|
| 1221 | + int i; |
---|
| 1222 | + |
---|
| 1223 | + for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
---|
1127 | 1224 | if (new_crtc_state->enable) |
---|
1128 | 1225 | drm_calc_timestamping_constants(crtc, |
---|
1129 | 1226 | &new_crtc_state->adjusted_mode); |
---|
1130 | 1227 | } |
---|
1131 | 1228 | } |
---|
1132 | | -EXPORT_SYMBOL(drm_atomic_helper_update_legacy_modeset_state); |
---|
| 1229 | +EXPORT_SYMBOL(drm_atomic_helper_calc_timestamping_constants); |
---|
1133 | 1230 | |
---|
1134 | 1231 | static void |
---|
1135 | 1232 | crtc_set_mode(struct drm_device *dev, struct drm_atomic_state *old_state) |
---|
.. | .. |
---|
1160 | 1257 | const struct drm_encoder_helper_funcs *funcs; |
---|
1161 | 1258 | struct drm_encoder *encoder; |
---|
1162 | 1259 | struct drm_display_mode *mode, *adjusted_mode; |
---|
| 1260 | + struct drm_bridge *bridge; |
---|
1163 | 1261 | |
---|
1164 | 1262 | if (!new_conn_state->best_encoder) |
---|
1165 | 1263 | continue; |
---|
.. | .. |
---|
1187 | 1285 | funcs->mode_set(encoder, mode, adjusted_mode); |
---|
1188 | 1286 | } |
---|
1189 | 1287 | |
---|
1190 | | - drm_bridge_mode_set(encoder->bridge, mode, adjusted_mode); |
---|
| 1288 | + bridge = drm_bridge_chain_get_first_bridge(encoder); |
---|
| 1289 | + drm_bridge_chain_mode_set(bridge, mode, adjusted_mode); |
---|
1191 | 1290 | } |
---|
1192 | 1291 | } |
---|
1193 | 1292 | |
---|
.. | .. |
---|
1199 | 1298 | * This function shuts down all the outputs that need to be shut down and |
---|
1200 | 1299 | * prepares them (if required) with the new mode. |
---|
1201 | 1300 | * |
---|
1202 | | - * For compatibility with legacy crtc helpers this should be called before |
---|
| 1301 | + * For compatibility with legacy CRTC helpers this should be called before |
---|
1203 | 1302 | * drm_atomic_helper_commit_planes(), which is what the default commit function |
---|
1204 | 1303 | * does. But drivers with different needs can group the modeset commits together |
---|
1205 | 1304 | * and do the plane commits at the end. This is useful for drivers doing runtime |
---|
.. | .. |
---|
1211 | 1310 | disable_outputs(dev, old_state); |
---|
1212 | 1311 | |
---|
1213 | 1312 | drm_atomic_helper_update_legacy_modeset_state(dev, old_state); |
---|
| 1313 | + drm_atomic_helper_calc_timestamping_constants(old_state); |
---|
1214 | 1314 | |
---|
1215 | 1315 | crtc_set_mode(dev, old_state); |
---|
1216 | 1316 | } |
---|
.. | .. |
---|
1245 | 1345 | * This function enables all the outputs with the new configuration which had to |
---|
1246 | 1346 | * be turned off for the update. |
---|
1247 | 1347 | * |
---|
1248 | | - * For compatibility with legacy crtc helpers this should be called after |
---|
| 1348 | + * For compatibility with legacy CRTC helpers this should be called after |
---|
1249 | 1349 | * drm_atomic_helper_commit_planes(), which is what the default commit function |
---|
1250 | 1350 | * does. But drivers with different needs can group the modeset commits together |
---|
1251 | 1351 | * and do the plane commits at the end. This is useful for drivers doing runtime |
---|
.. | .. |
---|
1276 | 1376 | if (new_crtc_state->enable) { |
---|
1277 | 1377 | DRM_DEBUG_ATOMIC("enabling [CRTC:%d:%s]\n", |
---|
1278 | 1378 | crtc->base.id, crtc->name); |
---|
1279 | | - |
---|
1280 | 1379 | if (funcs->atomic_enable) |
---|
1281 | 1380 | funcs->atomic_enable(crtc, old_crtc_state); |
---|
1282 | | - else |
---|
| 1381 | + else if (funcs->commit) |
---|
1283 | 1382 | funcs->commit(crtc); |
---|
1284 | 1383 | } |
---|
1285 | 1384 | } |
---|
.. | .. |
---|
1287 | 1386 | for_each_new_connector_in_state(old_state, connector, new_conn_state, i) { |
---|
1288 | 1387 | const struct drm_encoder_helper_funcs *funcs; |
---|
1289 | 1388 | struct drm_encoder *encoder; |
---|
| 1389 | + struct drm_bridge *bridge; |
---|
1290 | 1390 | |
---|
1291 | 1391 | if (!new_conn_state->best_encoder) |
---|
1292 | 1392 | continue; |
---|
.. | .. |
---|
1305 | 1405 | * Each encoder has at most one connector (since we always steal |
---|
1306 | 1406 | * it away), so we won't call enable hooks twice. |
---|
1307 | 1407 | */ |
---|
1308 | | - drm_bridge_pre_enable(encoder->bridge); |
---|
| 1408 | + bridge = drm_bridge_chain_get_first_bridge(encoder); |
---|
| 1409 | + drm_atomic_bridge_chain_pre_enable(bridge, old_state); |
---|
1309 | 1410 | |
---|
1310 | 1411 | if (funcs) { |
---|
1311 | | - if (funcs->enable) |
---|
| 1412 | + if (funcs->atomic_enable) |
---|
| 1413 | + funcs->atomic_enable(encoder, old_state); |
---|
| 1414 | + else if (funcs->enable) |
---|
1312 | 1415 | funcs->enable(encoder); |
---|
1313 | 1416 | else if (funcs->commit) |
---|
1314 | 1417 | funcs->commit(encoder); |
---|
1315 | 1418 | } |
---|
1316 | 1419 | |
---|
1317 | | - drm_bridge_enable(encoder->bridge); |
---|
| 1420 | + drm_atomic_bridge_chain_enable(bridge, old_state); |
---|
1318 | 1421 | } |
---|
1319 | 1422 | |
---|
1320 | 1423 | drm_atomic_helper_commit_writebacks(dev, old_state); |
---|
.. | .. |
---|
1374 | 1477 | EXPORT_SYMBOL(drm_atomic_helper_wait_for_fences); |
---|
1375 | 1478 | |
---|
1376 | 1479 | /** |
---|
1377 | | - * drm_atomic_helper_wait_for_vblanks - wait for vblank on crtcs |
---|
| 1480 | + * drm_atomic_helper_wait_for_vblanks - wait for vblank on CRTCs |
---|
1378 | 1481 | * @dev: DRM device |
---|
1379 | 1482 | * @old_state: atomic state object with old state structures |
---|
1380 | 1483 | * |
---|
1381 | | - * Helper to, after atomic commit, wait for vblanks on all effected |
---|
1382 | | - * crtcs (ie. before cleaning up old framebuffers using |
---|
| 1484 | + * Helper to, after atomic commit, wait for vblanks on all affected |
---|
| 1485 | + * CRTCs (ie. before cleaning up old framebuffers using |
---|
1383 | 1486 | * drm_atomic_helper_cleanup_planes()). It will only wait on CRTCs where the |
---|
1384 | 1487 | * framebuffers have actually changed to optimize for the legacy cursor and |
---|
1385 | 1488 | * plane update use-case. |
---|
.. | .. |
---|
1423 | 1526 | ret = wait_event_timeout(dev->vblank[i].queue, |
---|
1424 | 1527 | old_state->crtcs[i].last_vblank_count != |
---|
1425 | 1528 | drm_crtc_vblank_count(crtc), |
---|
1426 | | - msecs_to_jiffies(50)); |
---|
| 1529 | + msecs_to_jiffies(100)); |
---|
1427 | 1530 | |
---|
1428 | 1531 | WARN(!ret, "[CRTC:%d:%s] vblank wait timed out\n", |
---|
1429 | 1532 | crtc->base.id, crtc->name); |
---|
.. | .. |
---|
1438 | 1541 | * @dev: DRM device |
---|
1439 | 1542 | * @old_state: atomic state object with old state structures |
---|
1440 | 1543 | * |
---|
1441 | | - * Helper to, after atomic commit, wait for page flips on all effected |
---|
| 1544 | + * Helper to, after atomic commit, wait for page flips on all affected |
---|
1442 | 1545 | * crtcs (ie. before cleaning up old framebuffers using |
---|
1443 | 1546 | * drm_atomic_helper_cleanup_planes()). Compared to |
---|
1444 | | - * drm_atomic_helper_wait_for_vblanks() this waits for the completion of on all |
---|
| 1547 | + * drm_atomic_helper_wait_for_vblanks() this waits for the completion on all |
---|
1445 | 1548 | * CRTCs, assuming that cursors-only updates are signalling their completion |
---|
1446 | 1549 | * immediately (or using a different path). |
---|
1447 | 1550 | * |
---|
.. | .. |
---|
1542 | 1645 | { |
---|
1543 | 1646 | struct drm_device *dev = old_state->dev; |
---|
1544 | 1647 | const struct drm_mode_config_helper_funcs *funcs; |
---|
| 1648 | + struct drm_crtc_state *new_crtc_state; |
---|
| 1649 | + struct drm_crtc *crtc; |
---|
| 1650 | + ktime_t start; |
---|
| 1651 | + s64 commit_time_ms; |
---|
| 1652 | + unsigned int i, new_self_refresh_mask = 0; |
---|
1545 | 1653 | |
---|
1546 | 1654 | funcs = dev->mode_config.helper_private; |
---|
| 1655 | + |
---|
| 1656 | + /* |
---|
| 1657 | + * We're measuring the _entire_ commit, so the time will vary depending |
---|
| 1658 | + * on how many fences and objects are involved. For the purposes of self |
---|
| 1659 | + * refresh, this is desirable since it'll give us an idea of how |
---|
| 1660 | + * congested things are. This will inform our decision on how often we |
---|
| 1661 | + * should enter self refresh after idle. |
---|
| 1662 | + * |
---|
| 1663 | + * These times will be averaged out in the self refresh helpers to avoid |
---|
| 1664 | + * overreacting over one outlier frame |
---|
| 1665 | + */ |
---|
| 1666 | + start = ktime_get(); |
---|
1547 | 1667 | |
---|
1548 | 1668 | drm_atomic_helper_wait_for_fences(dev, old_state, false); |
---|
1549 | 1669 | |
---|
1550 | 1670 | drm_atomic_helper_wait_for_dependencies(old_state); |
---|
1551 | 1671 | |
---|
| 1672 | + /* |
---|
| 1673 | + * We cannot safely access new_crtc_state after |
---|
| 1674 | + * drm_atomic_helper_commit_hw_done() so figure out which crtc's have |
---|
| 1675 | + * self-refresh active beforehand: |
---|
| 1676 | + */ |
---|
| 1677 | + for_each_new_crtc_in_state(old_state, crtc, new_crtc_state, i) |
---|
| 1678 | + if (new_crtc_state->self_refresh_active) |
---|
| 1679 | + new_self_refresh_mask |= BIT(i); |
---|
| 1680 | + |
---|
1552 | 1681 | if (funcs && funcs->atomic_commit_tail) |
---|
1553 | 1682 | funcs->atomic_commit_tail(old_state); |
---|
1554 | 1683 | else |
---|
1555 | 1684 | drm_atomic_helper_commit_tail(old_state); |
---|
| 1685 | + |
---|
| 1686 | + commit_time_ms = ktime_ms_delta(ktime_get(), start); |
---|
| 1687 | + if (commit_time_ms > 0) |
---|
| 1688 | + drm_self_refresh_helper_update_avg_times(old_state, |
---|
| 1689 | + (unsigned long)commit_time_ms, |
---|
| 1690 | + new_self_refresh_mask); |
---|
1556 | 1691 | |
---|
1557 | 1692 | drm_atomic_helper_commit_cleanup_done(old_state); |
---|
1558 | 1693 | |
---|
.. | .. |
---|
1605 | 1740 | |
---|
1606 | 1741 | if (!new_plane_state->crtc || |
---|
1607 | 1742 | old_plane_state->crtc != new_plane_state->crtc) |
---|
1608 | | - return -EINVAL; |
---|
1609 | | - |
---|
1610 | | - /* |
---|
1611 | | - * FIXME: Since prepare_fb and cleanup_fb are always called on |
---|
1612 | | - * the new_plane_state for async updates we need to block framebuffer |
---|
1613 | | - * changes. This prevents use of a fb that's been cleaned up and |
---|
1614 | | - * double cleanups from occuring. |
---|
1615 | | - */ |
---|
1616 | | - if (old_plane_state->fb != new_plane_state->fb) |
---|
1617 | 1743 | return -EINVAL; |
---|
1618 | 1744 | |
---|
1619 | 1745 | funcs = plane->helper_private; |
---|
.. | .. |
---|
1696 | 1822 | * drm_atomic_helper_setup_commit() and related functions. |
---|
1697 | 1823 | * |
---|
1698 | 1824 | * Committing the actual hardware state is done through the |
---|
1699 | | - * &drm_mode_config_helper_funcs.atomic_commit_tail callback, or it's default |
---|
| 1825 | + * &drm_mode_config_helper_funcs.atomic_commit_tail callback, or its default |
---|
1700 | 1826 | * implementation drm_atomic_helper_commit_tail(). |
---|
1701 | 1827 | * |
---|
1702 | 1828 | * RETURNS: |
---|
.. | .. |
---|
1762 | 1888 | * |
---|
1763 | 1889 | * NOTE: Commit work has multiple phases, first hardware commit, then |
---|
1764 | 1890 | * cleanup. We want them to overlap, hence need system_unbound_wq to |
---|
1765 | | - * make sure work items don't artifically stall on each another. |
---|
| 1891 | + * make sure work items don't artificially stall on each another. |
---|
1766 | 1892 | */ |
---|
1767 | 1893 | |
---|
1768 | 1894 | drm_atomic_state_get(state); |
---|
.. | .. |
---|
1782 | 1908 | /** |
---|
1783 | 1909 | * DOC: implementing nonblocking commit |
---|
1784 | 1910 | * |
---|
1785 | | - * Nonblocking atomic commits have to be implemented in the following sequence: |
---|
| 1911 | + * Nonblocking atomic commits should use struct &drm_crtc_commit to sequence |
---|
| 1912 | + * different operations against each another. Locks, especially struct |
---|
| 1913 | + * &drm_modeset_lock, should not be held in worker threads or any other |
---|
| 1914 | + * asynchronous context used to commit the hardware state. |
---|
1786 | 1915 | * |
---|
1787 | | - * 1. Run drm_atomic_helper_prepare_planes() first. This is the only function |
---|
1788 | | - * which commit needs to call which can fail, so we want to run it first and |
---|
| 1916 | + * drm_atomic_helper_commit() implements the recommended sequence for |
---|
| 1917 | + * nonblocking commits, using drm_atomic_helper_setup_commit() internally: |
---|
| 1918 | + * |
---|
| 1919 | + * 1. Run drm_atomic_helper_prepare_planes(). Since this can fail and we |
---|
| 1920 | + * need to propagate out of memory/VRAM errors to userspace, it must be called |
---|
1789 | 1921 | * synchronously. |
---|
1790 | 1922 | * |
---|
1791 | 1923 | * 2. Synchronize with any outstanding nonblocking commit worker threads which |
---|
1792 | | - * might be affected the new state update. This can be done by either cancelling |
---|
1793 | | - * or flushing the work items, depending upon whether the driver can deal with |
---|
1794 | | - * cancelled updates. Note that it is important to ensure that the framebuffer |
---|
1795 | | - * cleanup is still done when cancelling. |
---|
| 1924 | + * might be affected by the new state update. This is handled by |
---|
| 1925 | + * drm_atomic_helper_setup_commit(). |
---|
1796 | 1926 | * |
---|
1797 | 1927 | * Asynchronous workers need to have sufficient parallelism to be able to run |
---|
1798 | 1928 | * different atomic commits on different CRTCs in parallel. The simplest way to |
---|
1799 | | - * achive this is by running them on the &system_unbound_wq work queue. Note |
---|
| 1929 | + * achieve this is by running them on the &system_unbound_wq work queue. Note |
---|
1800 | 1930 | * that drivers are not required to split up atomic commits and run an |
---|
1801 | 1931 | * individual commit in parallel - userspace is supposed to do that if it cares. |
---|
1802 | 1932 | * But it might be beneficial to do that for modesets, since those necessarily |
---|
1803 | 1933 | * must be done as one global operation, and enabling or disabling a CRTC can |
---|
1804 | 1934 | * take a long time. But even that is not required. |
---|
1805 | 1935 | * |
---|
| 1936 | + * IMPORTANT: A &drm_atomic_state update for multiple CRTCs is sequenced |
---|
| 1937 | + * against all CRTCs therein. Therefore for atomic state updates which only flip |
---|
| 1938 | + * planes the driver must not get the struct &drm_crtc_state of unrelated CRTCs |
---|
| 1939 | + * in its atomic check code: This would prevent committing of atomic updates to |
---|
| 1940 | + * multiple CRTCs in parallel. In general, adding additional state structures |
---|
| 1941 | + * should be avoided as much as possible, because this reduces parallelism in |
---|
| 1942 | + * (nonblocking) commits, both due to locking and due to commit sequencing |
---|
| 1943 | + * requirements. |
---|
| 1944 | + * |
---|
1806 | 1945 | * 3. The software state is updated synchronously with |
---|
1807 | 1946 | * drm_atomic_helper_swap_state(). Doing this under the protection of all modeset |
---|
1808 | | - * locks means concurrent callers never see inconsistent state. And doing this |
---|
1809 | | - * while it's guaranteed that no relevant nonblocking worker runs means that |
---|
1810 | | - * nonblocking workers do not need grab any locks. Actually they must not grab |
---|
1811 | | - * locks, for otherwise the work flushing will deadlock. |
---|
| 1947 | + * locks means concurrent callers never see inconsistent state. Note that commit |
---|
| 1948 | + * workers do not hold any locks; their access is only coordinated through |
---|
| 1949 | + * ordering. If workers would access state only through the pointers in the |
---|
| 1950 | + * free-standing state objects (currently not the case for any driver) then even |
---|
| 1951 | + * multiple pending commits could be in-flight at the same time. |
---|
1812 | 1952 | * |
---|
1813 | 1953 | * 4. Schedule a work item to do all subsequent steps, using the split-out |
---|
1814 | 1954 | * commit helpers: a) pre-plane commit b) plane commit c) post-plane commit and |
---|
1815 | 1955 | * then cleaning up the framebuffers after the old framebuffer is no longer |
---|
1816 | | - * being displayed. |
---|
1817 | | - * |
---|
1818 | | - * The above scheme is implemented in the atomic helper libraries in |
---|
1819 | | - * drm_atomic_helper_commit() using a bunch of helper functions. See |
---|
1820 | | - * drm_atomic_helper_setup_commit() for a starting point. |
---|
| 1956 | + * being displayed. The scheduled work should synchronize against other workers |
---|
| 1957 | + * using the &drm_crtc_commit infrastructure as needed. See |
---|
| 1958 | + * drm_atomic_helper_setup_commit() for more details. |
---|
1821 | 1959 | */ |
---|
1822 | 1960 | |
---|
1823 | 1961 | static int stall_checks(struct drm_crtc *crtc, bool nonblock) |
---|
.. | .. |
---|
1919 | 2057 | * functions. drm_atomic_helper_wait_for_dependencies() must be called before |
---|
1920 | 2058 | * actually committing the hardware state, and for nonblocking commits this call |
---|
1921 | 2059 | * must be placed in the async worker. See also drm_atomic_helper_swap_state() |
---|
1922 | | - * and it's stall parameter, for when a driver's commit hooks look at the |
---|
| 2060 | + * and its stall parameter, for when a driver's commit hooks look at the |
---|
1923 | 2061 | * &drm_crtc.state, &drm_plane.state or &drm_connector.state pointer directly. |
---|
1924 | 2062 | * |
---|
1925 | 2063 | * Completion of the hardware commit step must be signalled using |
---|
.. | .. |
---|
2046 | 2184 | * |
---|
2047 | 2185 | * This function waits for all preceeding commits that touch the same CRTC as |
---|
2048 | 2186 | * @old_state to both be committed to the hardware (as signalled by |
---|
2049 | | - * drm_atomic_helper_commit_hw_done) and executed by the hardware (as signalled |
---|
| 2187 | + * drm_atomic_helper_commit_hw_done()) and executed by the hardware (as signalled |
---|
2050 | 2188 | * by calling drm_crtc_send_vblank_event() on the &drm_crtc_state.event). |
---|
2051 | 2189 | * |
---|
2052 | 2190 | * This is part of the atomic helper support for nonblocking commits, see |
---|
.. | .. |
---|
2133 | 2271 | * drm_atomic_helper_fake_vblank - fake VBLANK events if needed |
---|
2134 | 2272 | * @old_state: atomic state object with old state structures |
---|
2135 | 2273 | * |
---|
2136 | | - * This function walks all CRTCs and fake VBLANK events on those with |
---|
| 2274 | + * This function walks all CRTCs and fakes VBLANK events on those with |
---|
2137 | 2275 | * &drm_crtc_state.no_vblank set to true and &drm_crtc_state.event != NULL. |
---|
2138 | 2276 | * The primary use of this function is writeback connectors working in oneshot |
---|
2139 | 2277 | * mode and faking VBLANK events. In this case they only fake the VBLANK event |
---|
2140 | 2278 | * when a job is queued, and any change to the pipeline that does not touch the |
---|
2141 | 2279 | * connector is leading to timeouts when calling |
---|
2142 | 2280 | * drm_atomic_helper_wait_for_vblanks() or |
---|
2143 | | - * drm_atomic_helper_wait_for_flip_done(). |
---|
| 2281 | + * drm_atomic_helper_wait_for_flip_done(). In addition to writeback |
---|
| 2282 | + * connectors, this function can also fake VBLANK events for CRTCs without |
---|
| 2283 | + * VBLANK interrupt. |
---|
2144 | 2284 | * |
---|
2145 | 2285 | * This is part of the atomic helper support for nonblocking commits, see |
---|
2146 | 2286 | * drm_atomic_helper_setup_commit() for an overview. |
---|
.. | .. |
---|
2248 | 2388 | spin_unlock(&crtc->commit_lock); |
---|
2249 | 2389 | } |
---|
2250 | 2390 | |
---|
2251 | | - if (old_state->fake_commit) |
---|
| 2391 | + if (old_state->fake_commit) { |
---|
2252 | 2392 | complete_all(&old_state->fake_commit->cleanup_done); |
---|
| 2393 | + WARN_ON(!try_wait_for_completion(&old_state->fake_commit->hw_done)); |
---|
| 2394 | + } |
---|
2253 | 2395 | } |
---|
2254 | 2396 | EXPORT_SYMBOL(drm_atomic_helper_commit_cleanup_done); |
---|
2255 | 2397 | |
---|
.. | .. |
---|
2269 | 2411 | int drm_atomic_helper_prepare_planes(struct drm_device *dev, |
---|
2270 | 2412 | struct drm_atomic_state *state) |
---|
2271 | 2413 | { |
---|
| 2414 | + struct drm_connector *connector; |
---|
| 2415 | + struct drm_connector_state *new_conn_state; |
---|
2272 | 2416 | struct drm_plane *plane; |
---|
2273 | 2417 | struct drm_plane_state *new_plane_state; |
---|
2274 | 2418 | int ret, i, j; |
---|
| 2419 | + |
---|
| 2420 | + for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
---|
| 2421 | + if (!new_conn_state->writeback_job) |
---|
| 2422 | + continue; |
---|
| 2423 | + |
---|
| 2424 | + ret = drm_writeback_prepare_job(new_conn_state->writeback_job); |
---|
| 2425 | + if (ret < 0) |
---|
| 2426 | + return ret; |
---|
| 2427 | + } |
---|
2275 | 2428 | |
---|
2276 | 2429 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
---|
2277 | 2430 | const struct drm_plane_helper_funcs *funcs; |
---|
.. | .. |
---|
2316 | 2469 | * @flags: flags for committing plane state |
---|
2317 | 2470 | * |
---|
2318 | 2471 | * This function commits the new plane state using the plane and atomic helper |
---|
2319 | | - * functions for planes and crtcs. It assumes that the atomic state has already |
---|
| 2472 | + * functions for planes and CRTCs. It assumes that the atomic state has already |
---|
2320 | 2473 | * been pushed into the relevant object state pointers, since this step can no |
---|
2321 | 2474 | * longer fail. |
---|
2322 | 2475 | * |
---|
.. | .. |
---|
2437 | 2590 | EXPORT_SYMBOL(drm_atomic_helper_commit_planes); |
---|
2438 | 2591 | |
---|
2439 | 2592 | /** |
---|
2440 | | - * drm_atomic_helper_commit_planes_on_crtc - commit plane state for a crtc |
---|
2441 | | - * @old_crtc_state: atomic state object with the old crtc state |
---|
| 2593 | + * drm_atomic_helper_commit_planes_on_crtc - commit plane state for a CRTC |
---|
| 2594 | + * @old_crtc_state: atomic state object with the old CRTC state |
---|
2442 | 2595 | * |
---|
2443 | 2596 | * This function commits the new plane state using the plane and atomic helper |
---|
2444 | | - * functions for planes on the specific crtc. It assumes that the atomic state |
---|
| 2597 | + * functions for planes on the specific CRTC. It assumes that the atomic state |
---|
2445 | 2598 | * has already been pushed into the relevant object state pointers, since this |
---|
2446 | 2599 | * step can no longer fail. |
---|
2447 | 2600 | * |
---|
2448 | | - * This function is useful when plane updates should be done crtc-by-crtc |
---|
| 2601 | + * This function is useful when plane updates should be done CRTC-by-CRTC |
---|
2449 | 2602 | * instead of one global step like drm_atomic_helper_commit_planes() does. |
---|
2450 | 2603 | * |
---|
2451 | 2604 | * This function can only be savely used when planes are not allowed to move |
---|
.. | .. |
---|
2735 | 2888 | * @plane: plane object to update |
---|
2736 | 2889 | * @crtc: owning CRTC of owning plane |
---|
2737 | 2890 | * @fb: framebuffer to flip onto plane |
---|
2738 | | - * @crtc_x: x offset of primary plane on crtc |
---|
2739 | | - * @crtc_y: y offset of primary plane on crtc |
---|
2740 | | - * @crtc_w: width of primary plane rectangle on crtc |
---|
2741 | | - * @crtc_h: height of primary plane rectangle on crtc |
---|
| 2891 | + * @crtc_x: x offset of primary plane on @crtc |
---|
| 2892 | + * @crtc_y: y offset of primary plane on @crtc |
---|
| 2893 | + * @crtc_w: width of primary plane rectangle on @crtc |
---|
| 2894 | + * @crtc_h: height of primary plane rectangle on @crtc |
---|
2742 | 2895 | * @src_x: x offset of @fb for panning |
---|
2743 | 2896 | * @src_y: y offset of @fb for panning |
---|
2744 | 2897 | * @src_w: width of source rectangle in @fb |
---|
.. | .. |
---|
2839 | 2992 | } |
---|
2840 | 2993 | EXPORT_SYMBOL(drm_atomic_helper_disable_plane); |
---|
2841 | 2994 | |
---|
2842 | | -/* just used from fb-helper and atomic-helper: */ |
---|
2843 | | -int __drm_atomic_helper_disable_plane(struct drm_plane *plane, |
---|
2844 | | - struct drm_plane_state *plane_state) |
---|
2845 | | -{ |
---|
2846 | | - int ret; |
---|
2847 | | - |
---|
2848 | | - ret = drm_atomic_set_crtc_for_plane(plane_state, NULL); |
---|
2849 | | - if (ret != 0) |
---|
2850 | | - return ret; |
---|
2851 | | - |
---|
2852 | | - drm_atomic_set_fb_for_plane(plane_state, NULL); |
---|
2853 | | - plane_state->crtc_x = 0; |
---|
2854 | | - plane_state->crtc_y = 0; |
---|
2855 | | - plane_state->crtc_w = 0; |
---|
2856 | | - plane_state->crtc_h = 0; |
---|
2857 | | - plane_state->src_x = 0; |
---|
2858 | | - plane_state->src_y = 0; |
---|
2859 | | - plane_state->src_w = 0; |
---|
2860 | | - plane_state->src_h = 0; |
---|
2861 | | - |
---|
2862 | | - return 0; |
---|
2863 | | -} |
---|
2864 | | -EXPORT_SYMBOL_GPL(__drm_atomic_helper_disable_plane); |
---|
2865 | | - |
---|
2866 | | -static int update_output_state(struct drm_atomic_state *state, |
---|
2867 | | - struct drm_mode_set *set) |
---|
2868 | | -{ |
---|
2869 | | - struct drm_device *dev = set->crtc->dev; |
---|
2870 | | - struct drm_crtc *crtc; |
---|
2871 | | - struct drm_crtc_state *new_crtc_state; |
---|
2872 | | - struct drm_connector *connector; |
---|
2873 | | - struct drm_connector_state *new_conn_state; |
---|
2874 | | - int ret, i; |
---|
2875 | | - |
---|
2876 | | - ret = drm_modeset_lock(&dev->mode_config.connection_mutex, |
---|
2877 | | - state->acquire_ctx); |
---|
2878 | | - if (ret) |
---|
2879 | | - return ret; |
---|
2880 | | - |
---|
2881 | | - /* First disable all connectors on the target crtc. */ |
---|
2882 | | - ret = drm_atomic_add_affected_connectors(state, set->crtc); |
---|
2883 | | - if (ret) |
---|
2884 | | - return ret; |
---|
2885 | | - |
---|
2886 | | - for_each_new_connector_in_state(state, connector, new_conn_state, i) { |
---|
2887 | | - if (new_conn_state->crtc == set->crtc) { |
---|
2888 | | - ret = drm_atomic_set_crtc_for_connector(new_conn_state, |
---|
2889 | | - NULL); |
---|
2890 | | - if (ret) |
---|
2891 | | - return ret; |
---|
2892 | | - |
---|
2893 | | - /* Make sure legacy setCrtc always re-trains */ |
---|
2894 | | - new_conn_state->link_status = DRM_LINK_STATUS_GOOD; |
---|
2895 | | - } |
---|
2896 | | - } |
---|
2897 | | - |
---|
2898 | | - /* Then set all connectors from set->connectors on the target crtc */ |
---|
2899 | | - for (i = 0; i < set->num_connectors; i++) { |
---|
2900 | | - new_conn_state = drm_atomic_get_connector_state(state, |
---|
2901 | | - set->connectors[i]); |
---|
2902 | | - if (IS_ERR(new_conn_state)) |
---|
2903 | | - return PTR_ERR(new_conn_state); |
---|
2904 | | - |
---|
2905 | | - ret = drm_atomic_set_crtc_for_connector(new_conn_state, |
---|
2906 | | - set->crtc); |
---|
2907 | | - if (ret) |
---|
2908 | | - return ret; |
---|
2909 | | - } |
---|
2910 | | - |
---|
2911 | | - for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
---|
2912 | | - /* Don't update ->enable for the CRTC in the set_config request, |
---|
2913 | | - * since a mismatch would indicate a bug in the upper layers. |
---|
2914 | | - * The actual modeset code later on will catch any |
---|
2915 | | - * inconsistencies here. */ |
---|
2916 | | - if (crtc == set->crtc) |
---|
2917 | | - continue; |
---|
2918 | | - |
---|
2919 | | - if (!new_crtc_state->connector_mask) { |
---|
2920 | | - ret = drm_atomic_set_mode_prop_for_crtc(new_crtc_state, |
---|
2921 | | - NULL); |
---|
2922 | | - if (ret < 0) |
---|
2923 | | - return ret; |
---|
2924 | | - |
---|
2925 | | - new_crtc_state->active = false; |
---|
2926 | | - } |
---|
2927 | | - } |
---|
2928 | | - |
---|
2929 | | - return 0; |
---|
2930 | | -} |
---|
2931 | | - |
---|
2932 | 2995 | /** |
---|
2933 | 2996 | * drm_atomic_helper_set_config - set a new config from userspace |
---|
2934 | 2997 | * @set: mode set configuration |
---|
2935 | 2998 | * @ctx: lock acquisition context |
---|
2936 | 2999 | * |
---|
2937 | | - * Provides a default crtc set_config handler using the atomic driver interface. |
---|
| 3000 | + * Provides a default CRTC set_config handler using the atomic driver interface. |
---|
2938 | 3001 | * |
---|
2939 | 3002 | * NOTE: For backwards compatibility with old userspace this automatically |
---|
2940 | 3003 | * resets the "link-status" property to GOOD, to force any link |
---|
.. | .. |
---|
2973 | 3036 | } |
---|
2974 | 3037 | EXPORT_SYMBOL(drm_atomic_helper_set_config); |
---|
2975 | 3038 | |
---|
2976 | | -/* just used from fb-helper and atomic-helper: */ |
---|
2977 | | -int __drm_atomic_helper_set_config(struct drm_mode_set *set, |
---|
2978 | | - struct drm_atomic_state *state) |
---|
2979 | | -{ |
---|
2980 | | - struct drm_crtc_state *crtc_state; |
---|
2981 | | - struct drm_plane_state *primary_state; |
---|
2982 | | - struct drm_crtc *crtc = set->crtc; |
---|
2983 | | - int hdisplay, vdisplay; |
---|
2984 | | - int ret; |
---|
2985 | | - |
---|
2986 | | - crtc_state = drm_atomic_get_crtc_state(state, crtc); |
---|
2987 | | - if (IS_ERR(crtc_state)) |
---|
2988 | | - return PTR_ERR(crtc_state); |
---|
2989 | | - |
---|
2990 | | - primary_state = drm_atomic_get_plane_state(state, crtc->primary); |
---|
2991 | | - if (IS_ERR(primary_state)) |
---|
2992 | | - return PTR_ERR(primary_state); |
---|
2993 | | - |
---|
2994 | | - if (!set->mode) { |
---|
2995 | | - WARN_ON(set->fb); |
---|
2996 | | - WARN_ON(set->num_connectors); |
---|
2997 | | - |
---|
2998 | | - ret = drm_atomic_set_mode_for_crtc(crtc_state, NULL); |
---|
2999 | | - if (ret != 0) |
---|
3000 | | - return ret; |
---|
3001 | | - |
---|
3002 | | - crtc_state->active = false; |
---|
3003 | | - |
---|
3004 | | - ret = drm_atomic_set_crtc_for_plane(primary_state, NULL); |
---|
3005 | | - if (ret != 0) |
---|
3006 | | - return ret; |
---|
3007 | | - |
---|
3008 | | - drm_atomic_set_fb_for_plane(primary_state, NULL); |
---|
3009 | | - |
---|
3010 | | - goto commit; |
---|
3011 | | - } |
---|
3012 | | - |
---|
3013 | | - WARN_ON(!set->fb); |
---|
3014 | | - WARN_ON(!set->num_connectors); |
---|
3015 | | - |
---|
3016 | | - ret = drm_atomic_set_mode_for_crtc(crtc_state, set->mode); |
---|
3017 | | - if (ret != 0) |
---|
3018 | | - return ret; |
---|
3019 | | - |
---|
3020 | | - crtc_state->active = true; |
---|
3021 | | - |
---|
3022 | | - ret = drm_atomic_set_crtc_for_plane(primary_state, crtc); |
---|
3023 | | - if (ret != 0) |
---|
3024 | | - return ret; |
---|
3025 | | - |
---|
3026 | | - drm_mode_get_hv_timing(set->mode, &hdisplay, &vdisplay); |
---|
3027 | | - |
---|
3028 | | - drm_atomic_set_fb_for_plane(primary_state, set->fb); |
---|
3029 | | - primary_state->crtc_x = 0; |
---|
3030 | | - primary_state->crtc_y = 0; |
---|
3031 | | - primary_state->crtc_w = hdisplay; |
---|
3032 | | - primary_state->crtc_h = vdisplay; |
---|
3033 | | - primary_state->src_x = set->x << 16; |
---|
3034 | | - primary_state->src_y = set->y << 16; |
---|
3035 | | - if (drm_rotation_90_or_270(primary_state->rotation)) { |
---|
3036 | | - primary_state->src_w = vdisplay << 16; |
---|
3037 | | - primary_state->src_h = hdisplay << 16; |
---|
3038 | | - } else { |
---|
3039 | | - primary_state->src_w = hdisplay << 16; |
---|
3040 | | - primary_state->src_h = vdisplay << 16; |
---|
3041 | | - } |
---|
3042 | | - |
---|
3043 | | -commit: |
---|
3044 | | - ret = update_output_state(state, set); |
---|
3045 | | - if (ret) |
---|
3046 | | - return ret; |
---|
3047 | | - |
---|
3048 | | - return 0; |
---|
3049 | | -} |
---|
3050 | | -EXPORT_SYMBOL_GPL(__drm_atomic_helper_set_config); |
---|
3051 | | - |
---|
3052 | | -static int __drm_atomic_helper_disable_all(struct drm_device *dev, |
---|
3053 | | - struct drm_modeset_acquire_ctx *ctx, |
---|
3054 | | - bool clean_old_fbs) |
---|
| 3039 | +/** |
---|
| 3040 | + * drm_atomic_helper_disable_all - disable all currently active outputs |
---|
| 3041 | + * @dev: DRM device |
---|
| 3042 | + * @ctx: lock acquisition context |
---|
| 3043 | + * |
---|
| 3044 | + * Loops through all connectors, finding those that aren't turned off and then |
---|
| 3045 | + * turns them off by setting their DPMS mode to OFF and deactivating the CRTC |
---|
| 3046 | + * that they are connected to. |
---|
| 3047 | + * |
---|
| 3048 | + * This is used for example in suspend/resume to disable all currently active |
---|
| 3049 | + * functions when suspending. If you just want to shut down everything at e.g. |
---|
| 3050 | + * driver unload, look at drm_atomic_helper_shutdown(). |
---|
| 3051 | + * |
---|
| 3052 | + * Note that if callers haven't already acquired all modeset locks this might |
---|
| 3053 | + * return -EDEADLK, which must be handled by calling drm_modeset_backoff(). |
---|
| 3054 | + * |
---|
| 3055 | + * Returns: |
---|
| 3056 | + * 0 on success or a negative error code on failure. |
---|
| 3057 | + * |
---|
| 3058 | + * See also: |
---|
| 3059 | + * drm_atomic_helper_suspend(), drm_atomic_helper_resume() and |
---|
| 3060 | + * drm_atomic_helper_shutdown(). |
---|
| 3061 | + */ |
---|
| 3062 | +int drm_atomic_helper_disable_all(struct drm_device *dev, |
---|
| 3063 | + struct drm_modeset_acquire_ctx *ctx) |
---|
3055 | 3064 | { |
---|
3056 | 3065 | struct drm_atomic_state *state; |
---|
3057 | 3066 | struct drm_connector_state *conn_state; |
---|
.. | .. |
---|
3109 | 3118 | drm_atomic_state_put(state); |
---|
3110 | 3119 | return ret; |
---|
3111 | 3120 | } |
---|
3112 | | - |
---|
3113 | | -/** |
---|
3114 | | - * drm_atomic_helper_disable_all - disable all currently active outputs |
---|
3115 | | - * @dev: DRM device |
---|
3116 | | - * @ctx: lock acquisition context |
---|
3117 | | - * |
---|
3118 | | - * Loops through all connectors, finding those that aren't turned off and then |
---|
3119 | | - * turns them off by setting their DPMS mode to OFF and deactivating the CRTC |
---|
3120 | | - * that they are connected to. |
---|
3121 | | - * |
---|
3122 | | - * This is used for example in suspend/resume to disable all currently active |
---|
3123 | | - * functions when suspending. If you just want to shut down everything at e.g. |
---|
3124 | | - * driver unload, look at drm_atomic_helper_shutdown(). |
---|
3125 | | - * |
---|
3126 | | - * Note that if callers haven't already acquired all modeset locks this might |
---|
3127 | | - * return -EDEADLK, which must be handled by calling drm_modeset_backoff(). |
---|
3128 | | - * |
---|
3129 | | - * Returns: |
---|
3130 | | - * 0 on success or a negative error code on failure. |
---|
3131 | | - * |
---|
3132 | | - * See also: |
---|
3133 | | - * drm_atomic_helper_suspend(), drm_atomic_helper_resume() and |
---|
3134 | | - * drm_atomic_helper_shutdown(). |
---|
3135 | | - */ |
---|
3136 | | -int drm_atomic_helper_disable_all(struct drm_device *dev, |
---|
3137 | | - struct drm_modeset_acquire_ctx *ctx) |
---|
3138 | | -{ |
---|
3139 | | - return __drm_atomic_helper_disable_all(dev, ctx, false); |
---|
3140 | | -} |
---|
3141 | 3121 | EXPORT_SYMBOL(drm_atomic_helper_disable_all); |
---|
3142 | 3122 | |
---|
3143 | 3123 | /** |
---|
.. | .. |
---|
3156 | 3136 | struct drm_modeset_acquire_ctx ctx; |
---|
3157 | 3137 | int ret; |
---|
3158 | 3138 | |
---|
3159 | | - drm_modeset_acquire_init(&ctx, 0); |
---|
3160 | | - while (1) { |
---|
3161 | | - ret = drm_modeset_lock_all_ctx(dev, &ctx); |
---|
3162 | | - if (!ret) |
---|
3163 | | - ret = __drm_atomic_helper_disable_all(dev, &ctx, true); |
---|
| 3139 | + DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, ret); |
---|
3164 | 3140 | |
---|
3165 | | - if (ret != -EDEADLK) |
---|
3166 | | - break; |
---|
3167 | | - |
---|
3168 | | - drm_modeset_backoff(&ctx); |
---|
3169 | | - } |
---|
3170 | | - |
---|
| 3141 | + ret = drm_atomic_helper_disable_all(dev, &ctx); |
---|
3171 | 3142 | if (ret) |
---|
3172 | 3143 | DRM_ERROR("Disabling all crtc's during unload failed with %i\n", ret); |
---|
3173 | 3144 | |
---|
3174 | | - drm_modeset_drop_locks(&ctx); |
---|
3175 | | - drm_modeset_acquire_fini(&ctx); |
---|
| 3145 | + DRM_MODESET_LOCK_ALL_END(dev, ctx, ret); |
---|
3176 | 3146 | } |
---|
3177 | 3147 | EXPORT_SYMBOL(drm_atomic_helper_shutdown); |
---|
| 3148 | + |
---|
| 3149 | +/** |
---|
| 3150 | + * drm_atomic_helper_duplicate_state - duplicate an atomic state object |
---|
| 3151 | + * @dev: DRM device |
---|
| 3152 | + * @ctx: lock acquisition context |
---|
| 3153 | + * |
---|
| 3154 | + * Makes a copy of the current atomic state by looping over all objects and |
---|
| 3155 | + * duplicating their respective states. This is used for example by suspend/ |
---|
| 3156 | + * resume support code to save the state prior to suspend such that it can |
---|
| 3157 | + * be restored upon resume. |
---|
| 3158 | + * |
---|
| 3159 | + * Note that this treats atomic state as persistent between save and restore. |
---|
| 3160 | + * Drivers must make sure that this is possible and won't result in confusion |
---|
| 3161 | + * or erroneous behaviour. |
---|
| 3162 | + * |
---|
| 3163 | + * Note that if callers haven't already acquired all modeset locks this might |
---|
| 3164 | + * return -EDEADLK, which must be handled by calling drm_modeset_backoff(). |
---|
| 3165 | + * |
---|
| 3166 | + * Returns: |
---|
| 3167 | + * A pointer to the copy of the atomic state object on success or an |
---|
| 3168 | + * ERR_PTR()-encoded error code on failure. |
---|
| 3169 | + * |
---|
| 3170 | + * See also: |
---|
| 3171 | + * drm_atomic_helper_suspend(), drm_atomic_helper_resume() |
---|
| 3172 | + */ |
---|
| 3173 | +struct drm_atomic_state * |
---|
| 3174 | +drm_atomic_helper_duplicate_state(struct drm_device *dev, |
---|
| 3175 | + struct drm_modeset_acquire_ctx *ctx) |
---|
| 3176 | +{ |
---|
| 3177 | + struct drm_atomic_state *state; |
---|
| 3178 | + struct drm_connector *conn; |
---|
| 3179 | + struct drm_connector_list_iter conn_iter; |
---|
| 3180 | + struct drm_plane *plane; |
---|
| 3181 | + struct drm_crtc *crtc; |
---|
| 3182 | + int err = 0; |
---|
| 3183 | + |
---|
| 3184 | + state = drm_atomic_state_alloc(dev); |
---|
| 3185 | + if (!state) |
---|
| 3186 | + return ERR_PTR(-ENOMEM); |
---|
| 3187 | + |
---|
| 3188 | + state->acquire_ctx = ctx; |
---|
| 3189 | + state->duplicated = true; |
---|
| 3190 | + |
---|
| 3191 | + drm_for_each_crtc(crtc, dev) { |
---|
| 3192 | + struct drm_crtc_state *crtc_state; |
---|
| 3193 | + |
---|
| 3194 | + crtc_state = drm_atomic_get_crtc_state(state, crtc); |
---|
| 3195 | + if (IS_ERR(crtc_state)) { |
---|
| 3196 | + err = PTR_ERR(crtc_state); |
---|
| 3197 | + goto free; |
---|
| 3198 | + } |
---|
| 3199 | + } |
---|
| 3200 | + |
---|
| 3201 | + drm_for_each_plane(plane, dev) { |
---|
| 3202 | + struct drm_plane_state *plane_state; |
---|
| 3203 | + |
---|
| 3204 | + plane_state = drm_atomic_get_plane_state(state, plane); |
---|
| 3205 | + if (IS_ERR(plane_state)) { |
---|
| 3206 | + err = PTR_ERR(plane_state); |
---|
| 3207 | + goto free; |
---|
| 3208 | + } |
---|
| 3209 | + } |
---|
| 3210 | + |
---|
| 3211 | + drm_connector_list_iter_begin(dev, &conn_iter); |
---|
| 3212 | + drm_for_each_connector_iter(conn, &conn_iter) { |
---|
| 3213 | + struct drm_connector_state *conn_state; |
---|
| 3214 | + |
---|
| 3215 | + conn_state = drm_atomic_get_connector_state(state, conn); |
---|
| 3216 | + if (IS_ERR(conn_state)) { |
---|
| 3217 | + err = PTR_ERR(conn_state); |
---|
| 3218 | + drm_connector_list_iter_end(&conn_iter); |
---|
| 3219 | + goto free; |
---|
| 3220 | + } |
---|
| 3221 | + } |
---|
| 3222 | + drm_connector_list_iter_end(&conn_iter); |
---|
| 3223 | + |
---|
| 3224 | + /* clear the acquire context so that it isn't accidentally reused */ |
---|
| 3225 | + state->acquire_ctx = NULL; |
---|
| 3226 | + |
---|
| 3227 | +free: |
---|
| 3228 | + if (err < 0) { |
---|
| 3229 | + drm_atomic_state_put(state); |
---|
| 3230 | + state = ERR_PTR(err); |
---|
| 3231 | + } |
---|
| 3232 | + |
---|
| 3233 | + return state; |
---|
| 3234 | +} |
---|
| 3235 | +EXPORT_SYMBOL(drm_atomic_helper_duplicate_state); |
---|
3178 | 3236 | |
---|
3179 | 3237 | /** |
---|
3180 | 3238 | * drm_atomic_helper_suspend - subsystem-level suspend helper |
---|
.. | .. |
---|
3207 | 3265 | struct drm_atomic_state *state; |
---|
3208 | 3266 | int err; |
---|
3209 | 3267 | |
---|
3210 | | - drm_modeset_acquire_init(&ctx, 0); |
---|
| 3268 | + /* This can never be returned, but it makes the compiler happy */ |
---|
| 3269 | + state = ERR_PTR(-EINVAL); |
---|
3211 | 3270 | |
---|
3212 | | -retry: |
---|
3213 | | - err = drm_modeset_lock_all_ctx(dev, &ctx); |
---|
3214 | | - if (err < 0) { |
---|
3215 | | - state = ERR_PTR(err); |
---|
3216 | | - goto unlock; |
---|
3217 | | - } |
---|
| 3271 | + DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, err); |
---|
3218 | 3272 | |
---|
3219 | 3273 | state = drm_atomic_helper_duplicate_state(dev, &ctx); |
---|
3220 | 3274 | if (IS_ERR(state)) |
---|
.. | .. |
---|
3228 | 3282 | } |
---|
3229 | 3283 | |
---|
3230 | 3284 | unlock: |
---|
3231 | | - if (PTR_ERR(state) == -EDEADLK) { |
---|
3232 | | - drm_modeset_backoff(&ctx); |
---|
3233 | | - goto retry; |
---|
3234 | | - } |
---|
| 3285 | + DRM_MODESET_LOCK_ALL_END(dev, ctx, err); |
---|
| 3286 | + if (err) |
---|
| 3287 | + return ERR_PTR(err); |
---|
3235 | 3288 | |
---|
3236 | | - drm_modeset_drop_locks(&ctx); |
---|
3237 | | - drm_modeset_acquire_fini(&ctx); |
---|
3238 | 3289 | return state; |
---|
3239 | 3290 | } |
---|
3240 | 3291 | EXPORT_SYMBOL(drm_atomic_helper_suspend); |
---|
.. | .. |
---|
3308 | 3359 | |
---|
3309 | 3360 | drm_mode_config_reset(dev); |
---|
3310 | 3361 | |
---|
3311 | | - drm_modeset_acquire_init(&ctx, 0); |
---|
3312 | | - while (1) { |
---|
3313 | | - err = drm_modeset_lock_all_ctx(dev, &ctx); |
---|
3314 | | - if (err) |
---|
3315 | | - goto out; |
---|
| 3362 | + DRM_MODESET_LOCK_ALL_BEGIN(dev, ctx, 0, err); |
---|
3316 | 3363 | |
---|
3317 | | - err = drm_atomic_helper_commit_duplicated_state(state, &ctx); |
---|
3318 | | -out: |
---|
3319 | | - if (err != -EDEADLK) |
---|
3320 | | - break; |
---|
| 3364 | + err = drm_atomic_helper_commit_duplicated_state(state, &ctx); |
---|
3321 | 3365 | |
---|
3322 | | - drm_modeset_backoff(&ctx); |
---|
3323 | | - } |
---|
3324 | | - |
---|
| 3366 | + DRM_MODESET_LOCK_ALL_END(dev, ctx, err); |
---|
3325 | 3367 | drm_atomic_state_put(state); |
---|
3326 | | - drm_modeset_drop_locks(&ctx); |
---|
3327 | | - drm_modeset_acquire_fini(&ctx); |
---|
3328 | 3368 | |
---|
3329 | 3369 | return err; |
---|
3330 | 3370 | } |
---|
.. | .. |
---|
3346 | 3386 | return PTR_ERR(crtc_state); |
---|
3347 | 3387 | |
---|
3348 | 3388 | crtc_state->event = event; |
---|
3349 | | - crtc_state->pageflip_flags = flags; |
---|
| 3389 | + crtc_state->async_flip = flags & DRM_MODE_PAGE_FLIP_ASYNC; |
---|
3350 | 3390 | |
---|
3351 | 3391 | plane_state = drm_atomic_get_plane_state(state, plane); |
---|
3352 | 3392 | if (IS_ERR(plane_state)) |
---|
.. | .. |
---|
3370 | 3410 | |
---|
3371 | 3411 | /** |
---|
3372 | 3412 | * drm_atomic_helper_page_flip - execute a legacy page flip |
---|
3373 | | - * @crtc: DRM crtc |
---|
| 3413 | + * @crtc: DRM CRTC |
---|
3374 | 3414 | * @fb: DRM framebuffer |
---|
3375 | 3415 | * @event: optional DRM event to signal upon completion |
---|
3376 | 3416 | * @flags: flip flags for non-vblank sync'ed updates |
---|
.. | .. |
---|
3414 | 3454 | |
---|
3415 | 3455 | /** |
---|
3416 | 3456 | * drm_atomic_helper_page_flip_target - do page flip on target vblank period. |
---|
3417 | | - * @crtc: DRM crtc |
---|
| 3457 | + * @crtc: DRM CRTC |
---|
3418 | 3458 | * @fb: DRM framebuffer |
---|
3419 | 3459 | * @event: optional DRM event to signal upon completion |
---|
3420 | 3460 | * @flags: flip flags for non-vblank sync'ed updates |
---|
.. | .. |
---|
3463 | 3503 | return ret; |
---|
3464 | 3504 | } |
---|
3465 | 3505 | EXPORT_SYMBOL(drm_atomic_helper_page_flip_target); |
---|
3466 | | - |
---|
3467 | | -/** |
---|
3468 | | - * drm_atomic_helper_best_encoder - Helper for |
---|
3469 | | - * &drm_connector_helper_funcs.best_encoder callback |
---|
3470 | | - * @connector: Connector control structure |
---|
3471 | | - * |
---|
3472 | | - * This is a &drm_connector_helper_funcs.best_encoder callback helper for |
---|
3473 | | - * connectors that support exactly 1 encoder, statically determined at driver |
---|
3474 | | - * init time. |
---|
3475 | | - */ |
---|
3476 | | -struct drm_encoder * |
---|
3477 | | -drm_atomic_helper_best_encoder(struct drm_connector *connector) |
---|
3478 | | -{ |
---|
3479 | | - WARN_ON(connector->encoder_ids[1]); |
---|
3480 | | - return drm_encoder_find(connector->dev, NULL, connector->encoder_ids[0]); |
---|
3481 | | -} |
---|
3482 | | -EXPORT_SYMBOL(drm_atomic_helper_best_encoder); |
---|
3483 | | - |
---|
3484 | | -/** |
---|
3485 | | - * DOC: atomic state reset and initialization |
---|
3486 | | - * |
---|
3487 | | - * Both the drm core and the atomic helpers assume that there is always the full |
---|
3488 | | - * and correct atomic software state for all connectors, CRTCs and planes |
---|
3489 | | - * available. Which is a bit a problem on driver load and also after system |
---|
3490 | | - * suspend. One way to solve this is to have a hardware state read-out |
---|
3491 | | - * infrastructure which reconstructs the full software state (e.g. the i915 |
---|
3492 | | - * driver). |
---|
3493 | | - * |
---|
3494 | | - * The simpler solution is to just reset the software state to everything off, |
---|
3495 | | - * which is easiest to do by calling drm_mode_config_reset(). To facilitate this |
---|
3496 | | - * the atomic helpers provide default reset implementations for all hooks. |
---|
3497 | | - * |
---|
3498 | | - * On the upside the precise state tracking of atomic simplifies system suspend |
---|
3499 | | - * and resume a lot. For drivers using drm_mode_config_reset() a complete recipe |
---|
3500 | | - * is implemented in drm_atomic_helper_suspend() and drm_atomic_helper_resume(). |
---|
3501 | | - * For other drivers the building blocks are split out, see the documentation |
---|
3502 | | - * for these functions. |
---|
3503 | | - */ |
---|
3504 | | - |
---|
3505 | | -/** |
---|
3506 | | - * drm_atomic_helper_crtc_reset - default &drm_crtc_funcs.reset hook for CRTCs |
---|
3507 | | - * @crtc: drm CRTC |
---|
3508 | | - * |
---|
3509 | | - * Resets the atomic state for @crtc by freeing the state pointer (which might |
---|
3510 | | - * be NULL, e.g. at driver load time) and allocating a new empty state object. |
---|
3511 | | - */ |
---|
3512 | | -void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc) |
---|
3513 | | -{ |
---|
3514 | | - if (crtc->state) |
---|
3515 | | - __drm_atomic_helper_crtc_destroy_state(crtc->state); |
---|
3516 | | - |
---|
3517 | | - kfree(crtc->state); |
---|
3518 | | - crtc->state = kzalloc(sizeof(*crtc->state), GFP_KERNEL); |
---|
3519 | | - |
---|
3520 | | - if (crtc->state) |
---|
3521 | | - crtc->state->crtc = crtc; |
---|
3522 | | -} |
---|
3523 | | -EXPORT_SYMBOL(drm_atomic_helper_crtc_reset); |
---|
3524 | | - |
---|
3525 | | -/** |
---|
3526 | | - * __drm_atomic_helper_crtc_duplicate_state - copy atomic CRTC state |
---|
3527 | | - * @crtc: CRTC object |
---|
3528 | | - * @state: atomic CRTC state |
---|
3529 | | - * |
---|
3530 | | - * Copies atomic state from a CRTC's current state and resets inferred values. |
---|
3531 | | - * This is useful for drivers that subclass the CRTC state. |
---|
3532 | | - */ |
---|
3533 | | -void __drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc, |
---|
3534 | | - struct drm_crtc_state *state) |
---|
3535 | | -{ |
---|
3536 | | - memcpy(state, crtc->state, sizeof(*state)); |
---|
3537 | | - |
---|
3538 | | - if (state->mode_blob) |
---|
3539 | | - drm_property_blob_get(state->mode_blob); |
---|
3540 | | - if (state->degamma_lut) |
---|
3541 | | - drm_property_blob_get(state->degamma_lut); |
---|
3542 | | - if (state->ctm) |
---|
3543 | | - drm_property_blob_get(state->ctm); |
---|
3544 | | - if (state->gamma_lut) |
---|
3545 | | - drm_property_blob_get(state->gamma_lut); |
---|
3546 | | - if (state->cubic_lut) |
---|
3547 | | - drm_property_blob_get(state->cubic_lut); |
---|
3548 | | - state->mode_changed = false; |
---|
3549 | | - state->active_changed = false; |
---|
3550 | | - state->planes_changed = false; |
---|
3551 | | - state->connectors_changed = false; |
---|
3552 | | - state->color_mgmt_changed = false; |
---|
3553 | | - state->zpos_changed = false; |
---|
3554 | | - state->commit = NULL; |
---|
3555 | | - state->event = NULL; |
---|
3556 | | - state->pageflip_flags = 0; |
---|
3557 | | -} |
---|
3558 | | -EXPORT_SYMBOL(__drm_atomic_helper_crtc_duplicate_state); |
---|
3559 | | - |
---|
3560 | | -/** |
---|
3561 | | - * drm_atomic_helper_crtc_duplicate_state - default state duplicate hook |
---|
3562 | | - * @crtc: drm CRTC |
---|
3563 | | - * |
---|
3564 | | - * Default CRTC state duplicate hook for drivers which don't have their own |
---|
3565 | | - * subclassed CRTC state structure. |
---|
3566 | | - */ |
---|
3567 | | -struct drm_crtc_state * |
---|
3568 | | -drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc) |
---|
3569 | | -{ |
---|
3570 | | - struct drm_crtc_state *state; |
---|
3571 | | - |
---|
3572 | | - if (WARN_ON(!crtc->state)) |
---|
3573 | | - return NULL; |
---|
3574 | | - |
---|
3575 | | - state = kmalloc(sizeof(*state), GFP_KERNEL); |
---|
3576 | | - if (state) |
---|
3577 | | - __drm_atomic_helper_crtc_duplicate_state(crtc, state); |
---|
3578 | | - |
---|
3579 | | - return state; |
---|
3580 | | -} |
---|
3581 | | -EXPORT_SYMBOL(drm_atomic_helper_crtc_duplicate_state); |
---|
3582 | | - |
---|
3583 | | -/** |
---|
3584 | | - * __drm_atomic_helper_crtc_destroy_state - release CRTC state |
---|
3585 | | - * @state: CRTC state object to release |
---|
3586 | | - * |
---|
3587 | | - * Releases all resources stored in the CRTC state without actually freeing |
---|
3588 | | - * the memory of the CRTC state. This is useful for drivers that subclass the |
---|
3589 | | - * CRTC state. |
---|
3590 | | - */ |
---|
3591 | | -void __drm_atomic_helper_crtc_destroy_state(struct drm_crtc_state *state) |
---|
3592 | | -{ |
---|
3593 | | - if (state->commit) { |
---|
3594 | | - /* |
---|
3595 | | - * In the event that a non-blocking commit returns |
---|
3596 | | - * -ERESTARTSYS before the commit_tail work is queued, we will |
---|
3597 | | - * have an extra reference to the commit object. Release it, if |
---|
3598 | | - * the event has not been consumed by the worker. |
---|
3599 | | - * |
---|
3600 | | - * state->event may be freed, so we can't directly look at |
---|
3601 | | - * state->event->base.completion. |
---|
3602 | | - */ |
---|
3603 | | - if (state->event && state->commit->abort_completion) |
---|
3604 | | - drm_crtc_commit_put(state->commit); |
---|
3605 | | - |
---|
3606 | | - kfree(state->commit->event); |
---|
3607 | | - state->commit->event = NULL; |
---|
3608 | | - |
---|
3609 | | - drm_crtc_commit_put(state->commit); |
---|
3610 | | - } |
---|
3611 | | - |
---|
3612 | | - drm_property_blob_put(state->mode_blob); |
---|
3613 | | - drm_property_blob_put(state->degamma_lut); |
---|
3614 | | - drm_property_blob_put(state->ctm); |
---|
3615 | | - drm_property_blob_put(state->gamma_lut); |
---|
3616 | | - drm_property_blob_put(state->cubic_lut); |
---|
3617 | | -} |
---|
3618 | | -EXPORT_SYMBOL(__drm_atomic_helper_crtc_destroy_state); |
---|
3619 | | - |
---|
3620 | | -/** |
---|
3621 | | - * drm_atomic_helper_crtc_destroy_state - default state destroy hook |
---|
3622 | | - * @crtc: drm CRTC |
---|
3623 | | - * @state: CRTC state object to release |
---|
3624 | | - * |
---|
3625 | | - * Default CRTC state destroy hook for drivers which don't have their own |
---|
3626 | | - * subclassed CRTC state structure. |
---|
3627 | | - */ |
---|
3628 | | -void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc, |
---|
3629 | | - struct drm_crtc_state *state) |
---|
3630 | | -{ |
---|
3631 | | - __drm_atomic_helper_crtc_destroy_state(state); |
---|
3632 | | - kfree(state); |
---|
3633 | | -} |
---|
3634 | | -EXPORT_SYMBOL(drm_atomic_helper_crtc_destroy_state); |
---|
3635 | | - |
---|
3636 | | -/** |
---|
3637 | | - * drm_atomic_helper_plane_reset - default &drm_plane_funcs.reset hook for planes |
---|
3638 | | - * @plane: drm plane |
---|
3639 | | - * |
---|
3640 | | - * Resets the atomic state for @plane by freeing the state pointer (which might |
---|
3641 | | - * be NULL, e.g. at driver load time) and allocating a new empty state object. |
---|
3642 | | - */ |
---|
3643 | | -void drm_atomic_helper_plane_reset(struct drm_plane *plane) |
---|
3644 | | -{ |
---|
3645 | | - if (plane->state) |
---|
3646 | | - __drm_atomic_helper_plane_destroy_state(plane->state); |
---|
3647 | | - |
---|
3648 | | - kfree(plane->state); |
---|
3649 | | - plane->state = kzalloc(sizeof(*plane->state), GFP_KERNEL); |
---|
3650 | | - |
---|
3651 | | - if (plane->state) { |
---|
3652 | | - plane->state->plane = plane; |
---|
3653 | | - plane->state->rotation = DRM_MODE_ROTATE_0; |
---|
3654 | | - |
---|
3655 | | - /* Reset the alpha value to fully opaque if it matters */ |
---|
3656 | | - if (plane->alpha_property) |
---|
3657 | | - plane->state->alpha = plane->alpha_property->values[1]; |
---|
3658 | | - } |
---|
3659 | | -} |
---|
3660 | | -EXPORT_SYMBOL(drm_atomic_helper_plane_reset); |
---|
3661 | | - |
---|
3662 | | -/** |
---|
3663 | | - * __drm_atomic_helper_plane_duplicate_state - copy atomic plane state |
---|
3664 | | - * @plane: plane object |
---|
3665 | | - * @state: atomic plane state |
---|
3666 | | - * |
---|
3667 | | - * Copies atomic state from a plane's current state. This is useful for |
---|
3668 | | - * drivers that subclass the plane state. |
---|
3669 | | - */ |
---|
3670 | | -void __drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane, |
---|
3671 | | - struct drm_plane_state *state) |
---|
3672 | | -{ |
---|
3673 | | - memcpy(state, plane->state, sizeof(*state)); |
---|
3674 | | - |
---|
3675 | | - if (state->fb) |
---|
3676 | | - drm_framebuffer_get(state->fb); |
---|
3677 | | - |
---|
3678 | | - state->fence = NULL; |
---|
3679 | | - state->commit = NULL; |
---|
3680 | | -} |
---|
3681 | | -EXPORT_SYMBOL(__drm_atomic_helper_plane_duplicate_state); |
---|
3682 | | - |
---|
3683 | | -/** |
---|
3684 | | - * drm_atomic_helper_plane_duplicate_state - default state duplicate hook |
---|
3685 | | - * @plane: drm plane |
---|
3686 | | - * |
---|
3687 | | - * Default plane state duplicate hook for drivers which don't have their own |
---|
3688 | | - * subclassed plane state structure. |
---|
3689 | | - */ |
---|
3690 | | -struct drm_plane_state * |
---|
3691 | | -drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane) |
---|
3692 | | -{ |
---|
3693 | | - struct drm_plane_state *state; |
---|
3694 | | - |
---|
3695 | | - if (WARN_ON(!plane->state)) |
---|
3696 | | - return NULL; |
---|
3697 | | - |
---|
3698 | | - state = kmalloc(sizeof(*state), GFP_KERNEL); |
---|
3699 | | - if (state) |
---|
3700 | | - __drm_atomic_helper_plane_duplicate_state(plane, state); |
---|
3701 | | - |
---|
3702 | | - return state; |
---|
3703 | | -} |
---|
3704 | | -EXPORT_SYMBOL(drm_atomic_helper_plane_duplicate_state); |
---|
3705 | | - |
---|
3706 | | -/** |
---|
3707 | | - * __drm_atomic_helper_plane_destroy_state - release plane state |
---|
3708 | | - * @state: plane state object to release |
---|
3709 | | - * |
---|
3710 | | - * Releases all resources stored in the plane state without actually freeing |
---|
3711 | | - * the memory of the plane state. This is useful for drivers that subclass the |
---|
3712 | | - * plane state. |
---|
3713 | | - */ |
---|
3714 | | -void __drm_atomic_helper_plane_destroy_state(struct drm_plane_state *state) |
---|
3715 | | -{ |
---|
3716 | | - if (state->fb) |
---|
3717 | | - drm_framebuffer_put(state->fb); |
---|
3718 | | - |
---|
3719 | | - if (state->fence) |
---|
3720 | | - dma_fence_put(state->fence); |
---|
3721 | | - |
---|
3722 | | - if (state->commit) |
---|
3723 | | - drm_crtc_commit_put(state->commit); |
---|
3724 | | -} |
---|
3725 | | -EXPORT_SYMBOL(__drm_atomic_helper_plane_destroy_state); |
---|
3726 | | - |
---|
3727 | | -/** |
---|
3728 | | - * drm_atomic_helper_plane_destroy_state - default state destroy hook |
---|
3729 | | - * @plane: drm plane |
---|
3730 | | - * @state: plane state object to release |
---|
3731 | | - * |
---|
3732 | | - * Default plane state destroy hook for drivers which don't have their own |
---|
3733 | | - * subclassed plane state structure. |
---|
3734 | | - */ |
---|
3735 | | -void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane, |
---|
3736 | | - struct drm_plane_state *state) |
---|
3737 | | -{ |
---|
3738 | | - __drm_atomic_helper_plane_destroy_state(state); |
---|
3739 | | - kfree(state); |
---|
3740 | | -} |
---|
3741 | | -EXPORT_SYMBOL(drm_atomic_helper_plane_destroy_state); |
---|
3742 | | - |
---|
3743 | | -/** |
---|
3744 | | - * __drm_atomic_helper_connector_reset - reset state on connector |
---|
3745 | | - * @connector: drm connector |
---|
3746 | | - * @conn_state: connector state to assign |
---|
3747 | | - * |
---|
3748 | | - * Initializes the newly allocated @conn_state and assigns it to |
---|
3749 | | - * the &drm_conector->state pointer of @connector, usually required when |
---|
3750 | | - * initializing the drivers or when called from the &drm_connector_funcs.reset |
---|
3751 | | - * hook. |
---|
3752 | | - * |
---|
3753 | | - * This is useful for drivers that subclass the connector state. |
---|
3754 | | - */ |
---|
3755 | | -void |
---|
3756 | | -__drm_atomic_helper_connector_reset(struct drm_connector *connector, |
---|
3757 | | - struct drm_connector_state *conn_state) |
---|
3758 | | -{ |
---|
3759 | | - if (conn_state) |
---|
3760 | | - conn_state->connector = connector; |
---|
3761 | | - |
---|
3762 | | - connector->state = conn_state; |
---|
3763 | | -} |
---|
3764 | | -EXPORT_SYMBOL(__drm_atomic_helper_connector_reset); |
---|
3765 | | - |
---|
3766 | | -/** |
---|
3767 | | - * drm_atomic_helper_connector_reset - default &drm_connector_funcs.reset hook for connectors |
---|
3768 | | - * @connector: drm connector |
---|
3769 | | - * |
---|
3770 | | - * Resets the atomic state for @connector by freeing the state pointer (which |
---|
3771 | | - * might be NULL, e.g. at driver load time) and allocating a new empty state |
---|
3772 | | - * object. |
---|
3773 | | - */ |
---|
3774 | | -void drm_atomic_helper_connector_reset(struct drm_connector *connector) |
---|
3775 | | -{ |
---|
3776 | | - struct drm_connector_state *conn_state = |
---|
3777 | | - kzalloc(sizeof(*conn_state), GFP_KERNEL); |
---|
3778 | | - |
---|
3779 | | - if (connector->state) |
---|
3780 | | - __drm_atomic_helper_connector_destroy_state(connector->state); |
---|
3781 | | - |
---|
3782 | | - kfree(connector->state); |
---|
3783 | | - __drm_atomic_helper_connector_reset(connector, conn_state); |
---|
3784 | | -} |
---|
3785 | | -EXPORT_SYMBOL(drm_atomic_helper_connector_reset); |
---|
3786 | | - |
---|
3787 | | -/** |
---|
3788 | | - * __drm_atomic_helper_connector_duplicate_state - copy atomic connector state |
---|
3789 | | - * @connector: connector object |
---|
3790 | | - * @state: atomic connector state |
---|
3791 | | - * |
---|
3792 | | - * Copies atomic state from a connector's current state. This is useful for |
---|
3793 | | - * drivers that subclass the connector state. |
---|
3794 | | - */ |
---|
3795 | | -void |
---|
3796 | | -__drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector, |
---|
3797 | | - struct drm_connector_state *state) |
---|
3798 | | -{ |
---|
3799 | | - memcpy(state, connector->state, sizeof(*state)); |
---|
3800 | | - if (state->crtc) |
---|
3801 | | - drm_connector_get(connector); |
---|
3802 | | - state->commit = NULL; |
---|
3803 | | - |
---|
3804 | | - if (state->hdr_output_metadata) |
---|
3805 | | - drm_property_blob_get(state->hdr_output_metadata); |
---|
3806 | | - |
---|
3807 | | - /* Don't copy over a writeback job, they are used only once */ |
---|
3808 | | - state->writeback_job = NULL; |
---|
3809 | | -} |
---|
3810 | | -EXPORT_SYMBOL(__drm_atomic_helper_connector_duplicate_state); |
---|
3811 | | - |
---|
3812 | | -/** |
---|
3813 | | - * drm_atomic_helper_connector_duplicate_state - default state duplicate hook |
---|
3814 | | - * @connector: drm connector |
---|
3815 | | - * |
---|
3816 | | - * Default connector state duplicate hook for drivers which don't have their own |
---|
3817 | | - * subclassed connector state structure. |
---|
3818 | | - */ |
---|
3819 | | -struct drm_connector_state * |
---|
3820 | | -drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector) |
---|
3821 | | -{ |
---|
3822 | | - struct drm_connector_state *state; |
---|
3823 | | - |
---|
3824 | | - if (WARN_ON(!connector->state)) |
---|
3825 | | - return NULL; |
---|
3826 | | - |
---|
3827 | | - state = kmalloc(sizeof(*state), GFP_KERNEL); |
---|
3828 | | - if (state) |
---|
3829 | | - __drm_atomic_helper_connector_duplicate_state(connector, state); |
---|
3830 | | - |
---|
3831 | | - return state; |
---|
3832 | | -} |
---|
3833 | | -EXPORT_SYMBOL(drm_atomic_helper_connector_duplicate_state); |
---|
3834 | | - |
---|
3835 | | -/** |
---|
3836 | | - * drm_atomic_helper_duplicate_state - duplicate an atomic state object |
---|
3837 | | - * @dev: DRM device |
---|
3838 | | - * @ctx: lock acquisition context |
---|
3839 | | - * |
---|
3840 | | - * Makes a copy of the current atomic state by looping over all objects and |
---|
3841 | | - * duplicating their respective states. This is used for example by suspend/ |
---|
3842 | | - * resume support code to save the state prior to suspend such that it can |
---|
3843 | | - * be restored upon resume. |
---|
3844 | | - * |
---|
3845 | | - * Note that this treats atomic state as persistent between save and restore. |
---|
3846 | | - * Drivers must make sure that this is possible and won't result in confusion |
---|
3847 | | - * or erroneous behaviour. |
---|
3848 | | - * |
---|
3849 | | - * Note that if callers haven't already acquired all modeset locks this might |
---|
3850 | | - * return -EDEADLK, which must be handled by calling drm_modeset_backoff(). |
---|
3851 | | - * |
---|
3852 | | - * Returns: |
---|
3853 | | - * A pointer to the copy of the atomic state object on success or an |
---|
3854 | | - * ERR_PTR()-encoded error code on failure. |
---|
3855 | | - * |
---|
3856 | | - * See also: |
---|
3857 | | - * drm_atomic_helper_suspend(), drm_atomic_helper_resume() |
---|
3858 | | - */ |
---|
3859 | | -struct drm_atomic_state * |
---|
3860 | | -drm_atomic_helper_duplicate_state(struct drm_device *dev, |
---|
3861 | | - struct drm_modeset_acquire_ctx *ctx) |
---|
3862 | | -{ |
---|
3863 | | - struct drm_atomic_state *state; |
---|
3864 | | - struct drm_connector *conn; |
---|
3865 | | - struct drm_connector_list_iter conn_iter; |
---|
3866 | | - struct drm_plane *plane; |
---|
3867 | | - struct drm_crtc *crtc; |
---|
3868 | | - int err = 0; |
---|
3869 | | - |
---|
3870 | | - state = drm_atomic_state_alloc(dev); |
---|
3871 | | - if (!state) |
---|
3872 | | - return ERR_PTR(-ENOMEM); |
---|
3873 | | - |
---|
3874 | | - state->acquire_ctx = ctx; |
---|
3875 | | - |
---|
3876 | | - drm_for_each_crtc(crtc, dev) { |
---|
3877 | | - struct drm_crtc_state *crtc_state; |
---|
3878 | | - |
---|
3879 | | - crtc_state = drm_atomic_get_crtc_state(state, crtc); |
---|
3880 | | - if (IS_ERR(crtc_state)) { |
---|
3881 | | - err = PTR_ERR(crtc_state); |
---|
3882 | | - goto free; |
---|
3883 | | - } |
---|
3884 | | - } |
---|
3885 | | - |
---|
3886 | | - drm_for_each_plane(plane, dev) { |
---|
3887 | | - struct drm_plane_state *plane_state; |
---|
3888 | | - |
---|
3889 | | - plane_state = drm_atomic_get_plane_state(state, plane); |
---|
3890 | | - if (IS_ERR(plane_state)) { |
---|
3891 | | - err = PTR_ERR(plane_state); |
---|
3892 | | - goto free; |
---|
3893 | | - } |
---|
3894 | | - } |
---|
3895 | | - |
---|
3896 | | - drm_connector_list_iter_begin(dev, &conn_iter); |
---|
3897 | | - drm_for_each_connector_iter(conn, &conn_iter) { |
---|
3898 | | - struct drm_connector_state *conn_state; |
---|
3899 | | - |
---|
3900 | | - conn_state = drm_atomic_get_connector_state(state, conn); |
---|
3901 | | - if (IS_ERR(conn_state)) { |
---|
3902 | | - err = PTR_ERR(conn_state); |
---|
3903 | | - drm_connector_list_iter_end(&conn_iter); |
---|
3904 | | - goto free; |
---|
3905 | | - } |
---|
3906 | | - } |
---|
3907 | | - drm_connector_list_iter_end(&conn_iter); |
---|
3908 | | - |
---|
3909 | | - /* clear the acquire context so that it isn't accidentally reused */ |
---|
3910 | | - state->acquire_ctx = NULL; |
---|
3911 | | - |
---|
3912 | | -free: |
---|
3913 | | - if (err < 0) { |
---|
3914 | | - drm_atomic_state_put(state); |
---|
3915 | | - state = ERR_PTR(err); |
---|
3916 | | - } |
---|
3917 | | - |
---|
3918 | | - return state; |
---|
3919 | | -} |
---|
3920 | | -EXPORT_SYMBOL(drm_atomic_helper_duplicate_state); |
---|
3921 | | - |
---|
3922 | | -/** |
---|
3923 | | - * __drm_atomic_helper_connector_destroy_state - release connector state |
---|
3924 | | - * @state: connector state object to release |
---|
3925 | | - * |
---|
3926 | | - * Releases all resources stored in the connector state without actually |
---|
3927 | | - * freeing the memory of the connector state. This is useful for drivers that |
---|
3928 | | - * subclass the connector state. |
---|
3929 | | - */ |
---|
3930 | | -void |
---|
3931 | | -__drm_atomic_helper_connector_destroy_state(struct drm_connector_state *state) |
---|
3932 | | -{ |
---|
3933 | | - if (state->crtc) |
---|
3934 | | - drm_connector_put(state->connector); |
---|
3935 | | - |
---|
3936 | | - if (state->commit) |
---|
3937 | | - drm_crtc_commit_put(state->commit); |
---|
3938 | | - |
---|
3939 | | - drm_property_blob_put(state->hdr_output_metadata); |
---|
3940 | | -} |
---|
3941 | | -EXPORT_SYMBOL(__drm_atomic_helper_connector_destroy_state); |
---|
3942 | | - |
---|
3943 | | -/** |
---|
3944 | | - * drm_atomic_helper_connector_destroy_state - default state destroy hook |
---|
3945 | | - * @connector: drm connector |
---|
3946 | | - * @state: connector state object to release |
---|
3947 | | - * |
---|
3948 | | - * Default connector state destroy hook for drivers which don't have their own |
---|
3949 | | - * subclassed connector state structure. |
---|
3950 | | - */ |
---|
3951 | | -void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector, |
---|
3952 | | - struct drm_connector_state *state) |
---|
3953 | | -{ |
---|
3954 | | - __drm_atomic_helper_connector_destroy_state(state); |
---|
3955 | | - kfree(state); |
---|
3956 | | -} |
---|
3957 | | -EXPORT_SYMBOL(drm_atomic_helper_connector_destroy_state); |
---|
3958 | 3506 | |
---|
3959 | 3507 | /** |
---|
3960 | 3508 | * drm_atomic_helper_legacy_gamma_set - set the legacy gamma correction table |
---|
.. | .. |
---|
4015 | 3563 | replaced = drm_property_replace_blob(&crtc_state->degamma_lut, NULL); |
---|
4016 | 3564 | replaced |= drm_property_replace_blob(&crtc_state->ctm, NULL); |
---|
4017 | 3565 | replaced |= drm_property_replace_blob(&crtc_state->gamma_lut, blob); |
---|
4018 | | - replaced |= drm_property_replace_blob(&crtc_state->cubic_lut, NULL); |
---|
4019 | 3566 | crtc_state->color_mgmt_changed |= replaced; |
---|
4020 | 3567 | |
---|
4021 | 3568 | ret = drm_atomic_commit(state); |
---|
.. | .. |
---|
4028 | 3575 | EXPORT_SYMBOL(drm_atomic_helper_legacy_gamma_set); |
---|
4029 | 3576 | |
---|
4030 | 3577 | /** |
---|
4031 | | - * __drm_atomic_helper_private_duplicate_state - copy atomic private state |
---|
4032 | | - * @obj: CRTC object |
---|
4033 | | - * @state: new private object state |
---|
| 3578 | + * drm_atomic_helper_bridge_propagate_bus_fmt() - Propagate output format to |
---|
| 3579 | + * the input end of a bridge |
---|
| 3580 | + * @bridge: bridge control structure |
---|
| 3581 | + * @bridge_state: new bridge state |
---|
| 3582 | + * @crtc_state: new CRTC state |
---|
| 3583 | + * @conn_state: new connector state |
---|
| 3584 | + * @output_fmt: tested output bus format |
---|
| 3585 | + * @num_input_fmts: will contain the size of the returned array |
---|
4034 | 3586 | * |
---|
4035 | | - * Copies atomic state from a private objects's current state and resets inferred values. |
---|
4036 | | - * This is useful for drivers that subclass the private state. |
---|
| 3587 | + * This helper is a pluggable implementation of the |
---|
| 3588 | + * &drm_bridge_funcs.atomic_get_input_bus_fmts operation for bridges that don't |
---|
| 3589 | + * modify the bus configuration between their input and their output. It |
---|
| 3590 | + * returns an array of input formats with a single element set to @output_fmt. |
---|
| 3591 | + * |
---|
| 3592 | + * RETURNS: |
---|
| 3593 | + * a valid format array of size @num_input_fmts, or NULL if the allocation |
---|
| 3594 | + * failed |
---|
4037 | 3595 | */ |
---|
4038 | | -void __drm_atomic_helper_private_obj_duplicate_state(struct drm_private_obj *obj, |
---|
4039 | | - struct drm_private_state *state) |
---|
| 3596 | +u32 * |
---|
| 3597 | +drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge, |
---|
| 3598 | + struct drm_bridge_state *bridge_state, |
---|
| 3599 | + struct drm_crtc_state *crtc_state, |
---|
| 3600 | + struct drm_connector_state *conn_state, |
---|
| 3601 | + u32 output_fmt, |
---|
| 3602 | + unsigned int *num_input_fmts) |
---|
4040 | 3603 | { |
---|
4041 | | - memcpy(state, obj->state, sizeof(*state)); |
---|
| 3604 | + u32 *input_fmts; |
---|
| 3605 | + |
---|
| 3606 | + input_fmts = kzalloc(sizeof(*input_fmts), GFP_KERNEL); |
---|
| 3607 | + if (!input_fmts) { |
---|
| 3608 | + *num_input_fmts = 0; |
---|
| 3609 | + return NULL; |
---|
| 3610 | + } |
---|
| 3611 | + |
---|
| 3612 | + *num_input_fmts = 1; |
---|
| 3613 | + input_fmts[0] = output_fmt; |
---|
| 3614 | + return input_fmts; |
---|
4042 | 3615 | } |
---|
4043 | | -EXPORT_SYMBOL(__drm_atomic_helper_private_obj_duplicate_state); |
---|
| 3616 | +EXPORT_SYMBOL(drm_atomic_helper_bridge_propagate_bus_fmt); |
---|