18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Copyright (C) 2014 Red Hat 38c2ecf20Sopenharmony_ci * Copyright (C) 2014 Intel Corp. 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 68c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 78c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation 88c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 98c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 108c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 118c2ecf20Sopenharmony_ci * 128c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in 138c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software. 148c2ecf20Sopenharmony_ci * 158c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 168c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 178c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 188c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 198c2ecf20Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 208c2ecf20Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 218c2ecf20Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE. 228c2ecf20Sopenharmony_ci * 238c2ecf20Sopenharmony_ci * Authors: 248c2ecf20Sopenharmony_ci * Rob Clark <robdclark@gmail.com> 258c2ecf20Sopenharmony_ci * Daniel Vetter <daniel.vetter@ffwll.ch> 268c2ecf20Sopenharmony_ci */ 278c2ecf20Sopenharmony_ci 288c2ecf20Sopenharmony_ci#ifndef DRM_ATOMIC_HELPER_H_ 298c2ecf20Sopenharmony_ci#define DRM_ATOMIC_HELPER_H_ 308c2ecf20Sopenharmony_ci 318c2ecf20Sopenharmony_ci#include <drm/drm_crtc.h> 328c2ecf20Sopenharmony_ci#include <drm/drm_modeset_helper_vtables.h> 338c2ecf20Sopenharmony_ci#include <drm/drm_modeset_helper.h> 348c2ecf20Sopenharmony_ci#include <drm/drm_atomic_state_helper.h> 358c2ecf20Sopenharmony_ci#include <drm/drm_util.h> 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistruct drm_atomic_state; 388c2ecf20Sopenharmony_cistruct drm_private_obj; 398c2ecf20Sopenharmony_cistruct drm_private_state; 408c2ecf20Sopenharmony_ci 418c2ecf20Sopenharmony_ciint drm_atomic_helper_check_modeset(struct drm_device *dev, 428c2ecf20Sopenharmony_ci struct drm_atomic_state *state); 438c2ecf20Sopenharmony_ciint drm_atomic_helper_check_plane_state(struct drm_plane_state *plane_state, 448c2ecf20Sopenharmony_ci const struct drm_crtc_state *crtc_state, 458c2ecf20Sopenharmony_ci int min_scale, 468c2ecf20Sopenharmony_ci int max_scale, 478c2ecf20Sopenharmony_ci bool can_position, 488c2ecf20Sopenharmony_ci bool can_update_disabled); 498c2ecf20Sopenharmony_ciint drm_atomic_helper_check_planes(struct drm_device *dev, 508c2ecf20Sopenharmony_ci struct drm_atomic_state *state); 518c2ecf20Sopenharmony_ciint drm_atomic_helper_check(struct drm_device *dev, 528c2ecf20Sopenharmony_ci struct drm_atomic_state *state); 538c2ecf20Sopenharmony_civoid drm_atomic_helper_commit_tail(struct drm_atomic_state *state); 548c2ecf20Sopenharmony_civoid drm_atomic_helper_commit_tail_rpm(struct drm_atomic_state *state); 558c2ecf20Sopenharmony_ciint drm_atomic_helper_commit(struct drm_device *dev, 568c2ecf20Sopenharmony_ci struct drm_atomic_state *state, 578c2ecf20Sopenharmony_ci bool nonblock); 588c2ecf20Sopenharmony_ciint drm_atomic_helper_async_check(struct drm_device *dev, 598c2ecf20Sopenharmony_ci struct drm_atomic_state *state); 608c2ecf20Sopenharmony_civoid drm_atomic_helper_async_commit(struct drm_device *dev, 618c2ecf20Sopenharmony_ci struct drm_atomic_state *state); 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ciint drm_atomic_helper_wait_for_fences(struct drm_device *dev, 648c2ecf20Sopenharmony_ci struct drm_atomic_state *state, 658c2ecf20Sopenharmony_ci bool pre_swap); 668c2ecf20Sopenharmony_ci 678c2ecf20Sopenharmony_civoid drm_atomic_helper_wait_for_vblanks(struct drm_device *dev, 688c2ecf20Sopenharmony_ci struct drm_atomic_state *old_state); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_civoid drm_atomic_helper_wait_for_flip_done(struct drm_device *dev, 718c2ecf20Sopenharmony_ci struct drm_atomic_state *old_state); 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_civoid 748c2ecf20Sopenharmony_cidrm_atomic_helper_update_legacy_modeset_state(struct drm_device *dev, 758c2ecf20Sopenharmony_ci struct drm_atomic_state *old_state); 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_civoid 788c2ecf20Sopenharmony_cidrm_atomic_helper_calc_timestamping_constants(struct drm_atomic_state *state); 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_civoid drm_atomic_helper_commit_modeset_disables(struct drm_device *dev, 818c2ecf20Sopenharmony_ci struct drm_atomic_state *state); 828c2ecf20Sopenharmony_civoid drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, 838c2ecf20Sopenharmony_ci struct drm_atomic_state *old_state); 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ciint drm_atomic_helper_prepare_planes(struct drm_device *dev, 868c2ecf20Sopenharmony_ci struct drm_atomic_state *state); 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci#define DRM_PLANE_COMMIT_ACTIVE_ONLY BIT(0) 898c2ecf20Sopenharmony_ci#define DRM_PLANE_COMMIT_NO_DISABLE_AFTER_MODESET BIT(1) 908c2ecf20Sopenharmony_ci 918c2ecf20Sopenharmony_civoid drm_atomic_helper_commit_planes(struct drm_device *dev, 928c2ecf20Sopenharmony_ci struct drm_atomic_state *state, 938c2ecf20Sopenharmony_ci uint32_t flags); 948c2ecf20Sopenharmony_civoid drm_atomic_helper_cleanup_planes(struct drm_device *dev, 958c2ecf20Sopenharmony_ci struct drm_atomic_state *old_state); 968c2ecf20Sopenharmony_civoid drm_atomic_helper_commit_planes_on_crtc(struct drm_crtc_state *old_crtc_state); 978c2ecf20Sopenharmony_civoid 988c2ecf20Sopenharmony_cidrm_atomic_helper_disable_planes_on_crtc(struct drm_crtc_state *old_crtc_state, 998c2ecf20Sopenharmony_ci bool atomic); 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_ciint __must_check drm_atomic_helper_swap_state(struct drm_atomic_state *state, 1028c2ecf20Sopenharmony_ci bool stall); 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci/* nonblocking commit helpers */ 1058c2ecf20Sopenharmony_ciint drm_atomic_helper_setup_commit(struct drm_atomic_state *state, 1068c2ecf20Sopenharmony_ci bool nonblock); 1078c2ecf20Sopenharmony_civoid drm_atomic_helper_wait_for_dependencies(struct drm_atomic_state *state); 1088c2ecf20Sopenharmony_civoid drm_atomic_helper_fake_vblank(struct drm_atomic_state *state); 1098c2ecf20Sopenharmony_civoid drm_atomic_helper_commit_hw_done(struct drm_atomic_state *state); 1108c2ecf20Sopenharmony_civoid drm_atomic_helper_commit_cleanup_done(struct drm_atomic_state *state); 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci/* implementations for legacy interfaces */ 1138c2ecf20Sopenharmony_ciint drm_atomic_helper_update_plane(struct drm_plane *plane, 1148c2ecf20Sopenharmony_ci struct drm_crtc *crtc, 1158c2ecf20Sopenharmony_ci struct drm_framebuffer *fb, 1168c2ecf20Sopenharmony_ci int crtc_x, int crtc_y, 1178c2ecf20Sopenharmony_ci unsigned int crtc_w, unsigned int crtc_h, 1188c2ecf20Sopenharmony_ci uint32_t src_x, uint32_t src_y, 1198c2ecf20Sopenharmony_ci uint32_t src_w, uint32_t src_h, 1208c2ecf20Sopenharmony_ci struct drm_modeset_acquire_ctx *ctx); 1218c2ecf20Sopenharmony_ciint drm_atomic_helper_disable_plane(struct drm_plane *plane, 1228c2ecf20Sopenharmony_ci struct drm_modeset_acquire_ctx *ctx); 1238c2ecf20Sopenharmony_ciint drm_atomic_helper_set_config(struct drm_mode_set *set, 1248c2ecf20Sopenharmony_ci struct drm_modeset_acquire_ctx *ctx); 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ciint drm_atomic_helper_disable_all(struct drm_device *dev, 1278c2ecf20Sopenharmony_ci struct drm_modeset_acquire_ctx *ctx); 1288c2ecf20Sopenharmony_civoid drm_atomic_helper_shutdown(struct drm_device *dev); 1298c2ecf20Sopenharmony_cistruct drm_atomic_state * 1308c2ecf20Sopenharmony_cidrm_atomic_helper_duplicate_state(struct drm_device *dev, 1318c2ecf20Sopenharmony_ci struct drm_modeset_acquire_ctx *ctx); 1328c2ecf20Sopenharmony_cistruct drm_atomic_state *drm_atomic_helper_suspend(struct drm_device *dev); 1338c2ecf20Sopenharmony_ciint drm_atomic_helper_commit_duplicated_state(struct drm_atomic_state *state, 1348c2ecf20Sopenharmony_ci struct drm_modeset_acquire_ctx *ctx); 1358c2ecf20Sopenharmony_ciint drm_atomic_helper_resume(struct drm_device *dev, 1368c2ecf20Sopenharmony_ci struct drm_atomic_state *state); 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_ciint drm_atomic_helper_page_flip(struct drm_crtc *crtc, 1398c2ecf20Sopenharmony_ci struct drm_framebuffer *fb, 1408c2ecf20Sopenharmony_ci struct drm_pending_vblank_event *event, 1418c2ecf20Sopenharmony_ci uint32_t flags, 1428c2ecf20Sopenharmony_ci struct drm_modeset_acquire_ctx *ctx); 1438c2ecf20Sopenharmony_ciint drm_atomic_helper_page_flip_target( 1448c2ecf20Sopenharmony_ci struct drm_crtc *crtc, 1458c2ecf20Sopenharmony_ci struct drm_framebuffer *fb, 1468c2ecf20Sopenharmony_ci struct drm_pending_vblank_event *event, 1478c2ecf20Sopenharmony_ci uint32_t flags, 1488c2ecf20Sopenharmony_ci uint32_t target, 1498c2ecf20Sopenharmony_ci struct drm_modeset_acquire_ctx *ctx); 1508c2ecf20Sopenharmony_ciint drm_atomic_helper_legacy_gamma_set(struct drm_crtc *crtc, 1518c2ecf20Sopenharmony_ci u16 *red, u16 *green, u16 *blue, 1528c2ecf20Sopenharmony_ci uint32_t size, 1538c2ecf20Sopenharmony_ci struct drm_modeset_acquire_ctx *ctx); 1548c2ecf20Sopenharmony_ci 1558c2ecf20Sopenharmony_ci/** 1568c2ecf20Sopenharmony_ci * drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC 1578c2ecf20Sopenharmony_ci * @plane: the loop cursor 1588c2ecf20Sopenharmony_ci * @crtc: the CRTC whose planes are iterated 1598c2ecf20Sopenharmony_ci * 1608c2ecf20Sopenharmony_ci * This iterates over the current state, useful (for example) when applying 1618c2ecf20Sopenharmony_ci * atomic state after it has been checked and swapped. To iterate over the 1628c2ecf20Sopenharmony_ci * planes which *will* be attached (more useful in code called from 1638c2ecf20Sopenharmony_ci * &drm_mode_config_funcs.atomic_check) see 1648c2ecf20Sopenharmony_ci * drm_atomic_crtc_state_for_each_plane(). 1658c2ecf20Sopenharmony_ci */ 1668c2ecf20Sopenharmony_ci#define drm_atomic_crtc_for_each_plane(plane, crtc) \ 1678c2ecf20Sopenharmony_ci drm_for_each_plane_mask(plane, (crtc)->dev, (crtc)->state->plane_mask) 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_ci/** 1708c2ecf20Sopenharmony_ci * drm_crtc_atomic_state_for_each_plane - iterate over attached planes in new state 1718c2ecf20Sopenharmony_ci * @plane: the loop cursor 1728c2ecf20Sopenharmony_ci * @crtc_state: the incoming CRTC state 1738c2ecf20Sopenharmony_ci * 1748c2ecf20Sopenharmony_ci * Similar to drm_crtc_for_each_plane(), but iterates the planes that will be 1758c2ecf20Sopenharmony_ci * attached if the specified state is applied. Useful during for example 1768c2ecf20Sopenharmony_ci * in code called from &drm_mode_config_funcs.atomic_check operations, to 1778c2ecf20Sopenharmony_ci * validate the incoming state. 1788c2ecf20Sopenharmony_ci */ 1798c2ecf20Sopenharmony_ci#define drm_atomic_crtc_state_for_each_plane(plane, crtc_state) \ 1808c2ecf20Sopenharmony_ci drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask) 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_ci/** 1838c2ecf20Sopenharmony_ci * drm_crtc_atomic_state_for_each_plane_state - iterate over attached planes in new state 1848c2ecf20Sopenharmony_ci * @plane: the loop cursor 1858c2ecf20Sopenharmony_ci * @plane_state: loop cursor for the plane's state, must be const 1868c2ecf20Sopenharmony_ci * @crtc_state: the incoming CRTC state 1878c2ecf20Sopenharmony_ci * 1888c2ecf20Sopenharmony_ci * Similar to drm_crtc_for_each_plane(), but iterates the planes that will be 1898c2ecf20Sopenharmony_ci * attached if the specified state is applied. Useful during for example 1908c2ecf20Sopenharmony_ci * in code called from &drm_mode_config_funcs.atomic_check operations, to 1918c2ecf20Sopenharmony_ci * validate the incoming state. 1928c2ecf20Sopenharmony_ci * 1938c2ecf20Sopenharmony_ci * Compared to just drm_atomic_crtc_state_for_each_plane() this also fills in a 1948c2ecf20Sopenharmony_ci * const plane_state. This is useful when a driver just wants to peek at other 1958c2ecf20Sopenharmony_ci * active planes on this CRTC, but does not need to change it. 1968c2ecf20Sopenharmony_ci */ 1978c2ecf20Sopenharmony_ci#define drm_atomic_crtc_state_for_each_plane_state(plane, plane_state, crtc_state) \ 1988c2ecf20Sopenharmony_ci drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask) \ 1998c2ecf20Sopenharmony_ci for_each_if ((plane_state = \ 2008c2ecf20Sopenharmony_ci __drm_atomic_get_current_plane_state((crtc_state)->state, \ 2018c2ecf20Sopenharmony_ci plane))) 2028c2ecf20Sopenharmony_ci 2038c2ecf20Sopenharmony_ci/** 2048c2ecf20Sopenharmony_ci * drm_atomic_plane_disabling - check whether a plane is being disabled 2058c2ecf20Sopenharmony_ci * @old_plane_state: old atomic plane state 2068c2ecf20Sopenharmony_ci * @new_plane_state: new atomic plane state 2078c2ecf20Sopenharmony_ci * 2088c2ecf20Sopenharmony_ci * Checks the atomic state of a plane to determine whether it's being disabled 2098c2ecf20Sopenharmony_ci * or not. This also WARNs if it detects an invalid state (both CRTC and FB 2108c2ecf20Sopenharmony_ci * need to either both be NULL or both be non-NULL). 2118c2ecf20Sopenharmony_ci * 2128c2ecf20Sopenharmony_ci * RETURNS: 2138c2ecf20Sopenharmony_ci * True if the plane is being disabled, false otherwise. 2148c2ecf20Sopenharmony_ci */ 2158c2ecf20Sopenharmony_cistatic inline bool 2168c2ecf20Sopenharmony_cidrm_atomic_plane_disabling(struct drm_plane_state *old_plane_state, 2178c2ecf20Sopenharmony_ci struct drm_plane_state *new_plane_state) 2188c2ecf20Sopenharmony_ci{ 2198c2ecf20Sopenharmony_ci /* 2208c2ecf20Sopenharmony_ci * When disabling a plane, CRTC and FB should always be NULL together. 2218c2ecf20Sopenharmony_ci * Anything else should be considered a bug in the atomic core, so we 2228c2ecf20Sopenharmony_ci * gently warn about it. 2238c2ecf20Sopenharmony_ci */ 2248c2ecf20Sopenharmony_ci WARN_ON((new_plane_state->crtc == NULL && new_plane_state->fb != NULL) || 2258c2ecf20Sopenharmony_ci (new_plane_state->crtc != NULL && new_plane_state->fb == NULL)); 2268c2ecf20Sopenharmony_ci 2278c2ecf20Sopenharmony_ci return old_plane_state->crtc && !new_plane_state->crtc; 2288c2ecf20Sopenharmony_ci} 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ciu32 * 2318c2ecf20Sopenharmony_cidrm_atomic_helper_bridge_propagate_bus_fmt(struct drm_bridge *bridge, 2328c2ecf20Sopenharmony_ci struct drm_bridge_state *bridge_state, 2338c2ecf20Sopenharmony_ci struct drm_crtc_state *crtc_state, 2348c2ecf20Sopenharmony_ci struct drm_connector_state *conn_state, 2358c2ecf20Sopenharmony_ci u32 output_fmt, 2368c2ecf20Sopenharmony_ci unsigned int *num_input_fmts); 2378c2ecf20Sopenharmony_ci 2388c2ecf20Sopenharmony_ci#endif /* DRM_ATOMIC_HELPER_H_ */ 239