forked from Minki/linux
407b8bd9f5
In order to prevent drivers from having to perform the same checks over and over again, add an optional ->atomic_disable callback which the core calls under the right circumstances. v2: pass old state and detect edges to avoid calling ->atomic_disable on already disabled planes, remove redundant comment (Daniel Vetter) v3: rename helper to drm_atomic_plane_disabling() to clarify that it is checking for transitions, move helper to drm_atomic_helper.h, clarify check for !old_state and its relation to transitional helpers Here's an extract from some discussion rationalizing the behaviour (for a full version, see the reference below): > > Hm, thinking about this some more this will result in a slight difference > > in behaviour, at least when drivers just use the helper ->reset functions > > but don't disable everything: > > - With transitional helpers we assume we know nothing and call > > ->atomic_disable. > > - With atomic old_state->crtc == NULL in the same situation right after > > boot-up, but we asssume the plane is really off and _dont_ call > > ->atomic_disable. > > > > Should we instead check for (old_state && old_state->crtc) and state that > > drivers need to make sure they don't have stuff hanging around? > > I don't think we can check for old_state because otherwise this will > always return false, whereas we really want it to force-disable planes > that could be on (lacking any more accurate information). For > transitional helpers anyway. > > For the atomic helpers, old_state will never be NULL, but I'd assume > that the driver would reconstruct the current state in ->reset(). By the way, the reason for why old_state can be NULL with transitional helpers is the ordering of the steps in the atomic transition. Currently the Tegra patches do this (based on your blog post and the Exynos proto- type): 1) atomic conversion, phase 1: - implement ->atomic_{check,update,disable}() - use drm_plane_helper_{update,disable}() 2) atomic conversion, phase 2: - call drm_mode_config_reset() from ->load() - implement ->reset() That's only a partial list of what's done in these steps, but that's the only relevant pieces for why old_state is NULL. What happens is that without ->reset() implemented there won't be any initial state, hence plane->state (the old_state here) will be NULL the first time atomic state is applied. We could of course reorder the sequence such that drivers are required to hook up ->reset() before they can (or at the same as they) hook up the transitional helpers. We could add an appropriate WARN_ON to this helper to make that more obvious. However, that will not solve the problem because it only gets rid of the special case. We still don't know whether old_state->crtc == NULL is the current state or just the initial default. So no matter which way we do this, I don't see a way to get away without requiring specific semantics from drivers. They would be that: - drivers recreate the correct state in ->reset() so that old_state->crtc != NULL if the plane is really enabled or - drivers have to ensure that the real state in fact mirrors the initial default as encoded in the state (plane disabled) References: http://lists.freedesktop.org/archives/dri-devel/2015-January/075578.html Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Reviewed-by: Gustavo Padovan <gustavo.padovan@collabora.co.uk> Signed-off-by: Thierry Reding <treding@nvidia.com>
168 lines
6.6 KiB
C
168 lines
6.6 KiB
C
/*
|
|
* Copyright (C) 2014 Red Hat
|
|
* Copyright (C) 2014 Intel Corp.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice shall be included in
|
|
* all copies or substantial portions of the Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
*
|
|
* Authors:
|
|
* Rob Clark <robdclark@gmail.com>
|
|
* Daniel Vetter <daniel.vetter@ffwll.ch>
|
|
*/
|
|
|
|
#ifndef DRM_ATOMIC_HELPER_H_
|
|
#define DRM_ATOMIC_HELPER_H_
|
|
|
|
#include <drm/drm_crtc.h>
|
|
|
|
int drm_atomic_helper_check_modeset(struct drm_device *dev,
|
|
struct drm_atomic_state *state);
|
|
int drm_atomic_helper_check_planes(struct drm_device *dev,
|
|
struct drm_atomic_state *state);
|
|
int drm_atomic_helper_check(struct drm_device *dev,
|
|
struct drm_atomic_state *state);
|
|
int drm_atomic_helper_commit(struct drm_device *dev,
|
|
struct drm_atomic_state *state,
|
|
bool async);
|
|
|
|
void drm_atomic_helper_wait_for_vblanks(struct drm_device *dev,
|
|
struct drm_atomic_state *old_state);
|
|
|
|
void drm_atomic_helper_commit_pre_planes(struct drm_device *dev,
|
|
struct drm_atomic_state *state);
|
|
void drm_atomic_helper_commit_post_planes(struct drm_device *dev,
|
|
struct drm_atomic_state *old_state);
|
|
|
|
int drm_atomic_helper_prepare_planes(struct drm_device *dev,
|
|
struct drm_atomic_state *state);
|
|
void drm_atomic_helper_commit_planes(struct drm_device *dev,
|
|
struct drm_atomic_state *state);
|
|
void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
|
|
struct drm_atomic_state *old_state);
|
|
|
|
void drm_atomic_helper_swap_state(struct drm_device *dev,
|
|
struct drm_atomic_state *state);
|
|
|
|
/* implementations for legacy interfaces */
|
|
int drm_atomic_helper_update_plane(struct drm_plane *plane,
|
|
struct drm_crtc *crtc,
|
|
struct drm_framebuffer *fb,
|
|
int crtc_x, int crtc_y,
|
|
unsigned int crtc_w, unsigned int crtc_h,
|
|
uint32_t src_x, uint32_t src_y,
|
|
uint32_t src_w, uint32_t src_h);
|
|
int drm_atomic_helper_disable_plane(struct drm_plane *plane);
|
|
int drm_atomic_helper_set_config(struct drm_mode_set *set);
|
|
|
|
int drm_atomic_helper_crtc_set_property(struct drm_crtc *crtc,
|
|
struct drm_property *property,
|
|
uint64_t val);
|
|
int drm_atomic_helper_plane_set_property(struct drm_plane *plane,
|
|
struct drm_property *property,
|
|
uint64_t val);
|
|
int drm_atomic_helper_connector_set_property(struct drm_connector *connector,
|
|
struct drm_property *property,
|
|
uint64_t val);
|
|
int drm_atomic_helper_page_flip(struct drm_crtc *crtc,
|
|
struct drm_framebuffer *fb,
|
|
struct drm_pending_vblank_event *event,
|
|
uint32_t flags);
|
|
|
|
/* default implementations for state handling */
|
|
void drm_atomic_helper_crtc_reset(struct drm_crtc *crtc);
|
|
struct drm_crtc_state *
|
|
drm_atomic_helper_crtc_duplicate_state(struct drm_crtc *crtc);
|
|
void drm_atomic_helper_crtc_destroy_state(struct drm_crtc *crtc,
|
|
struct drm_crtc_state *state);
|
|
|
|
void drm_atomic_helper_plane_reset(struct drm_plane *plane);
|
|
struct drm_plane_state *
|
|
drm_atomic_helper_plane_duplicate_state(struct drm_plane *plane);
|
|
void drm_atomic_helper_plane_destroy_state(struct drm_plane *plane,
|
|
struct drm_plane_state *state);
|
|
|
|
void drm_atomic_helper_connector_reset(struct drm_connector *connector);
|
|
struct drm_connector_state *
|
|
drm_atomic_helper_connector_duplicate_state(struct drm_connector *connector);
|
|
void drm_atomic_helper_connector_destroy_state(struct drm_connector *connector,
|
|
struct drm_connector_state *state);
|
|
|
|
/**
|
|
* drm_atomic_crtc_for_each_plane - iterate over planes currently attached to CRTC
|
|
* @plane: the loop cursor
|
|
* @crtc: the crtc whose planes are iterated
|
|
*
|
|
* This iterates over the current state, useful (for example) when applying
|
|
* atomic state after it has been checked and swapped. To iterate over the
|
|
* planes which *will* be attached (for ->atomic_check()) see
|
|
* drm_crtc_for_each_pending_plane()
|
|
*/
|
|
#define drm_atomic_crtc_for_each_plane(plane, crtc) \
|
|
drm_for_each_plane_mask(plane, (crtc)->dev, (crtc)->state->plane_mask)
|
|
|
|
/**
|
|
* drm_crtc_atomic_state_for_each_plane - iterate over attached planes in new state
|
|
* @plane: the loop cursor
|
|
* @crtc_state: the incoming crtc-state
|
|
*
|
|
* Similar to drm_crtc_for_each_plane(), but iterates the planes that will be
|
|
* attached if the specified state is applied. Useful during (for example)
|
|
* ->atomic_check() operations, to validate the incoming state
|
|
*/
|
|
#define drm_atomic_crtc_state_for_each_plane(plane, crtc_state) \
|
|
drm_for_each_plane_mask(plane, (crtc_state)->state->dev, (crtc_state)->plane_mask)
|
|
|
|
/*
|
|
* drm_atomic_plane_disabling - check whether a plane is being disabled
|
|
* @plane: plane object
|
|
* @old_state: previous atomic state
|
|
*
|
|
* Checks the atomic state of a plane to determine whether it's being disabled
|
|
* or not. This also WARNs if it detects an invalid state (both CRTC and FB
|
|
* need to either both be NULL or both be non-NULL).
|
|
*
|
|
* RETURNS:
|
|
* True if the plane is being disabled, false otherwise.
|
|
*/
|
|
static inline bool
|
|
drm_atomic_plane_disabling(struct drm_plane *plane,
|
|
struct drm_plane_state *old_state)
|
|
{
|
|
/*
|
|
* When disabling a plane, CRTC and FB should always be NULL together.
|
|
* Anything else should be considered a bug in the atomic core, so we
|
|
* gently warn about it.
|
|
*/
|
|
WARN_ON((plane->state->crtc == NULL && plane->state->fb != NULL) ||
|
|
(plane->state->crtc != NULL && plane->state->fb == NULL));
|
|
|
|
/*
|
|
* When using the transitional helpers, old_state may be NULL. If so,
|
|
* we know nothing about the current state and have to assume that it
|
|
* might be enabled.
|
|
*
|
|
* When using the atomic helpers, old_state won't be NULL. Therefore
|
|
* this check assumes that either the driver will have reconstructed
|
|
* the correct state in ->reset() or that the driver will have taken
|
|
* appropriate measures to disable all planes.
|
|
*/
|
|
return (!old_state || old_state->crtc) && !plane->state->crtc;
|
|
}
|
|
|
|
#endif /* DRM_ATOMIC_HELPER_H_ */
|