Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright (C) 2014 Red Hat
0003  * Copyright (C) 2014 Intel Corp.
0004  *
0005  * Permission is hereby granted, free of charge, to any person obtaining a
0006  * copy of this software and associated documentation files (the "Software"),
0007  * to deal in the Software without restriction, including without limitation
0008  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0009  * and/or sell copies of the Software, and to permit persons to whom the
0010  * Software is furnished to do so, subject to the following conditions:
0011  *
0012  * The above copyright notice and this permission notice shall be included in
0013  * all copies or substantial portions of the Software.
0014  *
0015  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0016  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0017  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0018  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0019  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0020  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0021  * OTHER DEALINGS IN THE SOFTWARE.
0022  *
0023  * Authors:
0024  * Rob Clark <robdclark@gmail.com>
0025  * Daniel Vetter <daniel.vetter@ffwll.ch>
0026  */
0027 
0028 #ifndef DRM_ATOMIC_HELPER_H_
0029 #define DRM_ATOMIC_HELPER_H_
0030 
0031 #include <drm/drm_crtc.h>
0032 #include <drm/drm_modeset_helper_vtables.h>
0033 #include <drm/drm_modeset_helper.h>
0034 #include <drm/drm_atomic_state_helper.h>
0035 #include <drm/drm_util.h>
0036 
0037 struct drm_atomic_state;
0038 struct drm_private_obj;
0039 struct drm_private_state;
0040 
0041 int drm_atomic_helper_check_modeset(struct drm_device *dev,
0042                 struct drm_atomic_state *state);
0043 int drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state,
0044                     const struct drm_crtc_state *crtc_state,
0045                     int min_scale,
0046                     int max_scale,
0047                     bool can_position,
0048                     bool can_update_disabled);
0049 int drm_atomic_helper_check_crtc_state(struct drm_crtc_state *crtc_state,
0050                        bool can_disable_primary_plane);
0051 int drm_atomic_helper_check_planes(struct drm_device *dev,
0052                    struct drm_atomic_state *state);
0053 int drm_atomic_helper_check(struct drm_device *dev,
0054                 struct drm_atomic_state *state);
0055 void drm_atomic_helper_commit_tail(struct drm_atomic_state *state);
0056 void drm_atomic_helper_commit_tail_rpm(struct drm_atomic_state *state);
0057 int drm_atomic_helper_commit(struct drm_device *dev,
0058                  struct drm_atomic_state *state,
0059                  bool nonblock);
0060 int drm_atomic_helper_async_check(struct drm_device *dev,
0061                   struct drm_atomic_state *state);
0062 void drm_atomic_helper_async_commit(struct drm_device *dev,
0063                     struct drm_atomic_state *state);
0064 
0065 int drm_atomic_helper_wait_for_fences(struct drm_device *dev,
0066                     struct drm_atomic_state *state,
0067                     bool pre_swap);
0068 
0069 void drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
0070                     struct drm_atomic_state *old_state);
0071 
0072 void drm_atomic_helper_wait_for_flip_done(struct drm_device *dev,
0073                       struct drm_atomic_state *old_state);
0074 
0075 void
0076 drm_atomic_helper_update_legacy_modeset_state(struct drm_device *dev,
0077                           struct drm_atomic_state *old_state);
0078 
0079 void
0080 drm_atomic_helper_calc_timestamping_constants(struct drm_atomic_state *state);
0081 
0082 void drm_atomic_helper_commit_modeset_disables(struct drm_device *dev,
0083                            struct drm_atomic_state *state);
0084 void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,
0085                       struct drm_atomic_state *old_state);
0086 
0087 int drm_atomic_helper_prepare_planes(struct drm_device *dev,
0088                      struct drm_atomic_state *state);
0089 
0090 #define DRM_PLANE_COMMIT_ACTIVE_ONLY            BIT(0)
0091 #define DRM_PLANE_COMMIT_NO_DISABLE_AFTER_MODESET   BIT(1)
0092 
0093 void drm_atomic_helper_commit_planes(struct drm_device *dev,
0094                      struct drm_atomic_state *state,
0095                      uint32_t flags);
0096 void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
0097                       struct drm_atomic_state *old_state);
0098 void drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state);
0099 void
0100 drm_atomic_helper_disable_planes_on_crtc(struct drm_crtc_state *old_crtc_state,
0101                      bool atomic);
0102 
0103 int __must_check drm_atomic_helper_swap_state(struct drm_atomic_state *state,
0104                           bool stall);
0105 
0106 /* nonblocking commit helpers */
0107 int drm_atomic_helper_setup_commit(struct drm_atomic_state *state,
0108                    bool nonblock);
0109 void drm_atomic_helper_wait_for_dependencies(struct drm_atomic_state *state);
0110 void drm_atomic_helper_fake_vblank(struct drm_atomic_state *state);
0111 void drm_atomic_helper_commit_hw_done(struct drm_atomic_state *state);
0112 void drm_atomic_helper_commit_cleanup_done(struct drm_atomic_state *state);
0113 
0114 /* implementations for legacy interfaces */
0115 int drm_atomic_helper_update_plane(struct drm_plane *plane,
0116                    struct drm_crtc *crtc,
0117                    struct drm_framebuffer *fb,
0118                    int crtc_x, int crtc_y,
0119                    unsigned int crtc_w, unsigned int crtc_h,
0120                    uint32_t src_x, uint32_t src_y,
0121                    uint32_t src_w, uint32_t src_h,
0122                    struct drm_modeset_acquire_ctx *ctx);
0123 int drm_atomic_helper_disable_plane(struct drm_plane *plane,
0124                     struct drm_modeset_acquire_ctx *ctx);
0125 int drm_atomic_helper_set_config(struct drm_mode_set *set,
0126                  struct drm_modeset_acquire_ctx *ctx);
0127 
0128 int drm_atomic_helper_disable_all(struct drm_device *dev,
0129                   struct drm_modeset_acquire_ctx *ctx);
0130 void drm_atomic_helper_shutdown(struct drm_device *dev);
0131 struct drm_atomic_state *
0132 drm_atomic_helper_duplicate_state(struct drm_device *dev,
0133                   struct drm_modeset_acquire_ctx *ctx);
0134 struct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev);
0135 int drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state,
0136                           struct drm_modeset_acquire_ctx *ctx);
0137 int drm_atomic_helper_resume(struct drm_device *dev,
0138                  struct drm_atomic_state *state);
0139 
0140 int drm_atomic_helper_page_flip(struct drm_crtc *crtc,
0141                 struct drm_framebuffer *fb,
0142                 struct drm_pending_vblank_event *event,
0143                 uint32_t flags,
0144                 struct drm_modeset_acquire_ctx *ctx);
0145 int drm_atomic_helper_page_flip_target(
0146                 struct drm_crtc *crtc,
0147                 struct drm_framebuffer *fb,
0148                 struct drm_pending_vblank_event *event,
0149                 uint32_t flags,
0150                 uint32_t target,
0151                 struct drm_modeset_acquire_ctx *ctx);
0152 
0153 /**
0154  * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC
0155  * @plane: the loop cursor
0156  * @crtc:  the CRTC whose planes are iterated
0157  *
0158  * This iterates over the current state, useful (for example) when applying
0159  * atomic state after it has been checked and swapped.  To iterate over the
0160  * planes which *will* be attached (more useful in code called from
0161  * &drm_mode_config_funcs.atomic_check) see
0162  * drm_atomic_crtc_state_for_each_plane().
0163  */
0164 #define drm_atomic_crtc_for_each_plane(plane, crtc) \
0165     drm_for_each_plane_mask(plane, (crtc)->dev, (crtc)->state->plane_mask)
0166 
0167 /**
0168  * drm_atomic_crtc_state_for_each_plane - iterate over attached planes in new state
0169  * @plane: the loop cursor
0170  * @crtc_state: the incoming CRTC state
0171  *
0172  * Similar to drm_crtc_for_each_plane(), but iterates the planes that will be
0173  * attached if the specified state is applied.  Useful during for example
0174  * in code called from &drm_mode_config_funcs.atomic_check operations, to
0175  * validate the incoming state.
0176  */
0177 #define drm_atomic_crtc_state_for_each_plane(plane, crtc_state) \
0178     drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask)
0179 
0180 /**
0181  * drm_atomic_crtc_state_for_each_plane_state - iterate over attached planes in new state
0182  * @plane: the loop cursor
0183  * @plane_state: loop cursor for the plane's state, must be const
0184  * @crtc_state: the incoming CRTC state
0185  *
0186  * Similar to drm_crtc_for_each_plane(), but iterates the planes that will be
0187  * attached if the specified state is applied.  Useful during for example
0188  * in code called from &drm_mode_config_funcs.atomic_check operations, to
0189  * validate the incoming state.
0190  *
0191  * Compared to just drm_atomic_crtc_state_for_each_plane() this also fills in a
0192  * const plane_state. This is useful when a driver just wants to peek at other
0193  * active planes on this CRTC, but does not need to change it.
0194  */
0195 #define drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) \
0196     drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask) \
0197         for_each_if ((plane_state = \
0198                   __drm_atomic_get_current_plane_state((crtc_state)->state, \
0199                                    plane)))
0200 
0201 /**
0202  * drm_atomic_plane_disabling - check whether a plane is being disabled
0203  * @old_plane_state: old atomic plane state
0204  * @new_plane_state: new atomic plane state
0205  *
0206  * Checks the atomic state of a plane to determine whether it's being disabled
0207  * or not. This also WARNs if it detects an invalid state (both CRTC and FB
0208  * need to either both be NULL or both be non-NULL).
0209  *
0210  * RETURNS:
0211  * True if the plane is being disabled, false otherwise.
0212  */
0213 static inline bool
0214 drm_atomic_plane_disabling(struct drm_plane_state *old_plane_state,
0215                struct drm_plane_state *new_plane_state)
0216 {
0217     /*
0218      * When disabling a plane, CRTC and FB should always be NULL together.
0219      * Anything else should be considered a bug in the atomic core, so we
0220      * gently warn about it.
0221      */
0222     WARN_ON((new_plane_state->crtc == NULL && new_plane_state->fb != NULL) ||
0223         (new_plane_state->crtc != NULL && new_plane_state->fb == NULL));
0224 
0225     return old_plane_state->crtc && !new_plane_state->crtc;
0226 }
0227 
0228 u32 *
0229 drm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge,
0230                     struct drm_bridge_state *bridge_state,
0231                     struct drm_crtc_state *crtc_state,
0232                     struct drm_connector_state *conn_state,
0233                     u32 output_fmt,
0234                     unsigned int *num_input_fmts);
0235 
0236 #endif /* DRM_ATOMIC_HELPER_H_ */