2014-04-02 06:22:35 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2014 Intel Corporation
|
|
|
|
*
|
|
|
|
* DRM universal plane helper functions
|
|
|
|
*
|
|
|
|
* 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 (including the next
|
|
|
|
* paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/list.h>
|
|
|
|
#include <drm/drmP.h>
|
2014-05-29 23:06:52 +08:00
|
|
|
#include <drm/drm_plane_helper.h>
|
2014-04-02 06:22:35 +08:00
|
|
|
#include <drm/drm_rect.h>
|
2014-11-05 05:57:27 +08:00
|
|
|
#include <drm/drm_atomic.h>
|
2014-07-29 21:33:05 +08:00
|
|
|
#include <drm/drm_crtc_helper.h>
|
2014-11-05 05:57:27 +08:00
|
|
|
#include <drm/drm_atomic_helper.h>
|
2014-04-02 06:22:35 +08:00
|
|
|
|
|
|
|
#define SUBPIXEL_MASK 0xffff
|
|
|
|
|
2014-11-07 03:53:29 +08:00
|
|
|
/**
|
|
|
|
* DOC: overview
|
|
|
|
*
|
|
|
|
* This helper library has two parts. The first part has support to implement
|
|
|
|
* primary plane support on top of the normal CRTC configuration interface.
|
|
|
|
* Since the legacy ->set_config interface ties the primary plane together with
|
|
|
|
* the CRTC state this does not allow userspace to disable the primary plane
|
|
|
|
* itself. To avoid too much duplicated code use
|
|
|
|
* drm_plane_helper_check_update() which can be used to enforce the same
|
|
|
|
* restrictions as primary planes had thus. The default primary plane only
|
|
|
|
* expose XRBG8888 and ARGB8888 as valid pixel formats for the attached
|
|
|
|
* framebuffer.
|
|
|
|
*
|
|
|
|
* Drivers are highly recommended to implement proper support for primary
|
|
|
|
* planes, and newly merged drivers must not rely upon these transitional
|
|
|
|
* helpers.
|
|
|
|
*
|
|
|
|
* The second part also implements transitional helpers which allow drivers to
|
|
|
|
* gradually switch to the atomic helper infrastructure for plane updates. Once
|
|
|
|
* that switch is complete drivers shouldn't use these any longer, instead using
|
|
|
|
* the proper legacy implementations for update and disable plane hooks provided
|
|
|
|
* by the atomic helpers.
|
|
|
|
*
|
|
|
|
* Again drivers are strongly urged to switch to the new interfaces.
|
|
|
|
*/
|
|
|
|
|
2014-04-02 06:22:35 +08:00
|
|
|
/*
|
|
|
|
* This is the minimal list of formats that seem to be safe for modeset use
|
|
|
|
* with all current DRM drivers. Most hardware can actually support more
|
|
|
|
* formats than this and drivers may specify a more accurate list when
|
|
|
|
* creating the primary plane. However drivers that still call
|
|
|
|
* drm_plane_init() will use this minimal format list as the default.
|
|
|
|
*/
|
2014-05-13 22:58:35 +08:00
|
|
|
static const uint32_t safe_modeset_formats[] = {
|
|
|
|
DRM_FORMAT_XRGB8888,
|
|
|
|
DRM_FORMAT_ARGB8888,
|
2014-04-02 06:22:35 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns the connectors currently associated with a CRTC. This function
|
|
|
|
* should be called twice: once with a NULL connector list to retrieve
|
|
|
|
* the list size, and once with the properly allocated list to be filled in.
|
|
|
|
*/
|
|
|
|
static int get_connectors_for_crtc(struct drm_crtc *crtc,
|
|
|
|
struct drm_connector **connector_list,
|
|
|
|
int num_connectors)
|
|
|
|
{
|
|
|
|
struct drm_device *dev = crtc->dev;
|
|
|
|
struct drm_connector *connector;
|
|
|
|
int count = 0;
|
|
|
|
|
drm: Split connection_mutex out of mode_config.mutex (v3)
After the split-out of crtc locks from the big mode_config.mutex
there's still two major areas it protects:
- Various connector probe states, like connector->status, EDID
properties, probed mode lists and similar information.
- The links from connector->encoder and encoder->crtc and other
modeset-relevant connector state (e.g. properties which control the
panel fitter).
The later is used by modeset operations. But they don't really care
about the former since it's allowed to e.g. enable a disconnected VGA
output or with a mode not in the probed list.
Thus far this hasn't been a problem, but for the atomic modeset
conversion Rob Clark needs to convert all modeset relevant locks into
w/w locks. This is required because the order of acquisition is
determined by how userspace supplies the atomic modeset data. This has
run into troubles in the detect path since the i915 load detect code
needs _both_ protections offered by the mode_config.mutex: It updates
probe state and it needs to change the modeset configuration to enable
the temporary load detect pipe.
The big deal here is that for the probe/detect users of this lock a
plain mutex fits best, but for atomic modesets we really want a w/w
mutex. To fix this lets split out a new connection_mutex lock for the
modeset relevant parts.
For simplicity I've decided to only add one additional lock for all
connector/encoder links and modeset configuration states. We have
piles of different modeset objects in addition to those (like bridges
or panels), so adding per-object locks would be much more effort.
Also, we're guaranteed (at least for now) to do a full modeset if we
need to acquire this lock. Which means that fine-grained locking is
fairly irrelevant compared to the amount of time the full modeset will
take.
I've done a full audit, and there's just a few things that justify
special focus:
- Locking in drm_sysfs.c is almost completely absent. We should
sprinkle mode_config.connection_mutex over this file a bit, but
since it already lacks mode_config.mutex this patch wont make the
situation any worse. This is material for a follow-up patch.
- omap has a omap_framebuffer_flush function which walks the
connector->encoder->crtc links and is called from many contexts.
Some look like they don't acquire mode_config.mutex, so this is
already racy. Again fixing this is material for a separate patch.
- The radeon hot_plug function to retrain DP links looks at
connector->dpms. Currently this happens without any locking, so is
already racy. I think radeon_hotplug_work_func should gain
mutex_lock/unlock calls for the mode_config.connection_mutex.
- Same applies to i915's intel_dp_hot_plug. But again, this is already
racy.
- i915 load_detect code needs to acquire this lock. Which means the
w/w dance due to Rob's work will be nicely contained to _just_ this
function.
I've added fixme comments everywhere where it looks suspicious but in
the sysfs code. After a quick irc discussion with Dave Airlie it
sounds like the lack of locking in there is due to sysfs cleanup fun
at module unload.
v1: original (only compile tested)
v2: missing mutex_init(), etc (from Rob Clark)
v3: i915 needs more care in the conversion:
- Protect the edp pp logic with the connection_mutex.
- Use connection_mutex in the backlight code due to
get_pipe_from_connector.
- Use drm_modeset_lock_all in suspend/resume paths.
- Update lock checks in the overlay code.
Cc: Alex Deucher <alexdeucher@gmail.com>
Cc: Rob Clark <robdclark@gmail.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Rob Clark <robdclark@gmail.com>
2014-05-30 05:54:47 +08:00
|
|
|
/*
|
|
|
|
* Note: Once we change the plane hooks to more fine-grained locking we
|
|
|
|
* need to grab the connection_mutex here to be able to make these
|
|
|
|
* checks.
|
|
|
|
*/
|
2013-11-20 01:10:12 +08:00
|
|
|
WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
|
drm: Split connection_mutex out of mode_config.mutex (v3)
After the split-out of crtc locks from the big mode_config.mutex
there's still two major areas it protects:
- Various connector probe states, like connector->status, EDID
properties, probed mode lists and similar information.
- The links from connector->encoder and encoder->crtc and other
modeset-relevant connector state (e.g. properties which control the
panel fitter).
The later is used by modeset operations. But they don't really care
about the former since it's allowed to e.g. enable a disconnected VGA
output or with a mode not in the probed list.
Thus far this hasn't been a problem, but for the atomic modeset
conversion Rob Clark needs to convert all modeset relevant locks into
w/w locks. This is required because the order of acquisition is
determined by how userspace supplies the atomic modeset data. This has
run into troubles in the detect path since the i915 load detect code
needs _both_ protections offered by the mode_config.mutex: It updates
probe state and it needs to change the modeset configuration to enable
the temporary load detect pipe.
The big deal here is that for the probe/detect users of this lock a
plain mutex fits best, but for atomic modesets we really want a w/w
mutex. To fix this lets split out a new connection_mutex lock for the
modeset relevant parts.
For simplicity I've decided to only add one additional lock for all
connector/encoder links and modeset configuration states. We have
piles of different modeset objects in addition to those (like bridges
or panels), so adding per-object locks would be much more effort.
Also, we're guaranteed (at least for now) to do a full modeset if we
need to acquire this lock. Which means that fine-grained locking is
fairly irrelevant compared to the amount of time the full modeset will
take.
I've done a full audit, and there's just a few things that justify
special focus:
- Locking in drm_sysfs.c is almost completely absent. We should
sprinkle mode_config.connection_mutex over this file a bit, but
since it already lacks mode_config.mutex this patch wont make the
situation any worse. This is material for a follow-up patch.
- omap has a omap_framebuffer_flush function which walks the
connector->encoder->crtc links and is called from many contexts.
Some look like they don't acquire mode_config.mutex, so this is
already racy. Again fixing this is material for a separate patch.
- The radeon hot_plug function to retrain DP links looks at
connector->dpms. Currently this happens without any locking, so is
already racy. I think radeon_hotplug_work_func should gain
mutex_lock/unlock calls for the mode_config.connection_mutex.
- Same applies to i915's intel_dp_hot_plug. But again, this is already
racy.
- i915 load_detect code needs to acquire this lock. Which means the
w/w dance due to Rob's work will be nicely contained to _just_ this
function.
I've added fixme comments everywhere where it looks suspicious but in
the sysfs code. After a quick irc discussion with Dave Airlie it
sounds like the lack of locking in there is due to sysfs cleanup fun
at module unload.
v1: original (only compile tested)
v2: missing mutex_init(), etc (from Rob Clark)
v3: i915 needs more care in the conversion:
- Protect the edp pp logic with the connection_mutex.
- Use connection_mutex in the backlight code due to
get_pipe_from_connector.
- Use drm_modeset_lock_all in suspend/resume paths.
- Update lock checks in the overlay code.
Cc: Alex Deucher <alexdeucher@gmail.com>
Cc: Rob Clark <robdclark@gmail.com>
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Reviewed-by: Rob Clark <robdclark@gmail.com>
2014-05-30 05:54:47 +08:00
|
|
|
|
2015-07-10 05:44:34 +08:00
|
|
|
drm_for_each_connector(connector, dev) {
|
2014-04-02 06:22:35 +08:00
|
|
|
if (connector->encoder && connector->encoder->crtc == crtc) {
|
|
|
|
if (connector_list != NULL && count < num_connectors)
|
|
|
|
*(connector_list++) = connector;
|
|
|
|
|
|
|
|
count++;
|
|
|
|
}
|
2015-07-10 05:44:34 +08:00
|
|
|
}
|
2014-04-02 06:22:35 +08:00
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2014-05-29 23:06:52 +08:00
|
|
|
/**
|
|
|
|
* drm_plane_helper_check_update() - Check plane update for validity
|
|
|
|
* @plane: plane object to update
|
|
|
|
* @crtc: owning CRTC of owning plane
|
|
|
|
* @fb: framebuffer to flip onto plane
|
|
|
|
* @src: source coordinates in 16.16 fixed point
|
|
|
|
* @dest: integer destination coordinates
|
|
|
|
* @clip: integer clipping coordinates
|
|
|
|
* @min_scale: minimum @src:@dest scaling factor in 16.16 fixed point
|
|
|
|
* @max_scale: maximum @src:@dest scaling factor in 16.16 fixed point
|
|
|
|
* @can_position: is it legal to position the plane such that it
|
|
|
|
* doesn't cover the entire crtc? This will generally
|
|
|
|
* only be false for primary planes.
|
|
|
|
* @can_update_disabled: can the plane be updated while the crtc
|
|
|
|
* is disabled?
|
|
|
|
* @visible: output parameter indicating whether plane is still visible after
|
|
|
|
* clipping
|
|
|
|
*
|
|
|
|
* Checks that a desired plane update is valid. Drivers that provide
|
|
|
|
* their own plane handling rather than helper-provided implementations may
|
|
|
|
* still wish to call this function to avoid duplication of error checking
|
|
|
|
* code.
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero if update appears valid, error code on failure
|
|
|
|
*/
|
|
|
|
int drm_plane_helper_check_update(struct drm_plane *plane,
|
|
|
|
struct drm_crtc *crtc,
|
|
|
|
struct drm_framebuffer *fb,
|
|
|
|
struct drm_rect *src,
|
|
|
|
struct drm_rect *dest,
|
|
|
|
const struct drm_rect *clip,
|
|
|
|
int min_scale,
|
|
|
|
int max_scale,
|
|
|
|
bool can_position,
|
|
|
|
bool can_update_disabled,
|
|
|
|
bool *visible)
|
|
|
|
{
|
|
|
|
int hscale, vscale;
|
|
|
|
|
2014-12-11 23:20:57 +08:00
|
|
|
if (!fb) {
|
|
|
|
*visible = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* crtc should only be NULL when disabling (i.e., !fb) */
|
|
|
|
if (WARN_ON(!crtc)) {
|
|
|
|
*visible = false;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-29 23:06:52 +08:00
|
|
|
if (!crtc->enabled && !can_update_disabled) {
|
|
|
|
DRM_DEBUG_KMS("Cannot update plane of a disabled CRTC.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check scaling */
|
|
|
|
hscale = drm_rect_calc_hscale(src, dest, min_scale, max_scale);
|
|
|
|
vscale = drm_rect_calc_vscale(src, dest, min_scale, max_scale);
|
|
|
|
if (hscale < 0 || vscale < 0) {
|
|
|
|
DRM_DEBUG_KMS("Invalid scaling of plane\n");
|
|
|
|
return -ERANGE;
|
|
|
|
}
|
|
|
|
|
|
|
|
*visible = drm_rect_clip_scaled(src, dest, clip, hscale, vscale);
|
|
|
|
if (!*visible)
|
|
|
|
/*
|
|
|
|
* Plane isn't visible; some drivers can handle this
|
|
|
|
* so we just return success here. Drivers that can't
|
|
|
|
* (including those that use the primary plane helper's
|
|
|
|
* update function) will return an error from their
|
|
|
|
* update_plane handler.
|
|
|
|
*/
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!can_position && !drm_rect_equals(dest, clip)) {
|
|
|
|
DRM_DEBUG_KMS("Plane must cover entire CRTC\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_plane_helper_check_update);
|
|
|
|
|
2014-04-02 06:22:35 +08:00
|
|
|
/**
|
|
|
|
* drm_primary_helper_update() - Helper for primary plane update
|
|
|
|
* @plane: plane object to update
|
|
|
|
* @crtc: owning CRTC of owning plane
|
|
|
|
* @fb: framebuffer to flip onto plane
|
|
|
|
* @crtc_x: x offset of primary plane on crtc
|
|
|
|
* @crtc_y: y offset of primary plane on crtc
|
|
|
|
* @crtc_w: width of primary plane rectangle on crtc
|
|
|
|
* @crtc_h: height of primary plane rectangle on crtc
|
|
|
|
* @src_x: x offset of @fb for panning
|
|
|
|
* @src_y: y offset of @fb for panning
|
|
|
|
* @src_w: width of source rectangle in @fb
|
|
|
|
* @src_h: height of source rectangle in @fb
|
|
|
|
*
|
|
|
|
* Provides a default plane update handler for primary planes. This is handler
|
|
|
|
* is called in response to a userspace SetPlane operation on the plane with a
|
|
|
|
* non-NULL framebuffer. We call the driver's modeset handler to update the
|
|
|
|
* framebuffer.
|
|
|
|
*
|
|
|
|
* SetPlane() on a primary plane of a disabled CRTC is not supported, and will
|
|
|
|
* return an error.
|
|
|
|
*
|
|
|
|
* Note that we make some assumptions about hardware limitations that may not be
|
|
|
|
* true for all hardware --
|
|
|
|
* 1) Primary plane cannot be repositioned.
|
|
|
|
* 2) Primary plane cannot be scaled.
|
|
|
|
* 3) Primary plane must cover the entire CRTC.
|
|
|
|
* 4) Subpixel positioning is not supported.
|
|
|
|
* Drivers for hardware that don't have these restrictions can provide their
|
|
|
|
* own implementation rather than using this helper.
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure
|
|
|
|
*/
|
|
|
|
int drm_primary_helper_update(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)
|
|
|
|
{
|
|
|
|
struct drm_mode_set set = {
|
|
|
|
.crtc = crtc,
|
|
|
|
.fb = fb,
|
|
|
|
.mode = &crtc->mode,
|
|
|
|
.x = src_x >> 16,
|
|
|
|
.y = src_y >> 16,
|
|
|
|
};
|
2014-05-29 23:06:52 +08:00
|
|
|
struct drm_rect src = {
|
|
|
|
.x1 = src_x,
|
|
|
|
.y1 = src_y,
|
|
|
|
.x2 = src_x + src_w,
|
|
|
|
.y2 = src_y + src_h,
|
|
|
|
};
|
2014-04-02 06:22:35 +08:00
|
|
|
struct drm_rect dest = {
|
|
|
|
.x1 = crtc_x,
|
|
|
|
.y1 = crtc_y,
|
|
|
|
.x2 = crtc_x + crtc_w,
|
|
|
|
.y2 = crtc_y + crtc_h,
|
|
|
|
};
|
2014-05-29 23:06:52 +08:00
|
|
|
const struct drm_rect clip = {
|
2014-04-02 06:22:35 +08:00
|
|
|
.x2 = crtc->mode.hdisplay,
|
|
|
|
.y2 = crtc->mode.vdisplay,
|
|
|
|
};
|
|
|
|
struct drm_connector **connector_list;
|
|
|
|
int num_connectors, ret;
|
2014-05-29 23:06:52 +08:00
|
|
|
bool visible;
|
2014-04-02 06:22:35 +08:00
|
|
|
|
2014-05-29 23:06:52 +08:00
|
|
|
ret = drm_plane_helper_check_update(plane, crtc, fb,
|
|
|
|
&src, &dest, &clip,
|
|
|
|
DRM_PLANE_HELPER_NO_SCALING,
|
|
|
|
DRM_PLANE_HELPER_NO_SCALING,
|
|
|
|
false, false, &visible);
|
2014-04-02 06:22:35 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2014-05-29 23:06:52 +08:00
|
|
|
if (!visible)
|
|
|
|
/*
|
|
|
|
* Primary plane isn't visible. Note that unless a driver
|
|
|
|
* provides their own disable function, this will just
|
|
|
|
* wind up returning -EINVAL to userspace.
|
|
|
|
*/
|
|
|
|
return plane->funcs->disable_plane(plane);
|
|
|
|
|
2014-04-02 06:22:35 +08:00
|
|
|
/* Find current connectors for CRTC */
|
|
|
|
num_connectors = get_connectors_for_crtc(crtc, NULL, 0);
|
|
|
|
BUG_ON(num_connectors == 0);
|
|
|
|
connector_list = kzalloc(num_connectors * sizeof(*connector_list),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!connector_list)
|
|
|
|
return -ENOMEM;
|
|
|
|
get_connectors_for_crtc(crtc, connector_list, num_connectors);
|
|
|
|
|
|
|
|
set.connectors = connector_list;
|
|
|
|
set.num_connectors = num_connectors;
|
|
|
|
|
|
|
|
/*
|
2014-04-23 23:34:06 +08:00
|
|
|
* We call set_config() directly here rather than using
|
2014-04-02 06:22:35 +08:00
|
|
|
* drm_mode_set_config_internal. We're reprogramming the same
|
|
|
|
* connectors that were already in use, so we shouldn't need the extra
|
|
|
|
* cross-CRTC fb refcounting to accomodate stealing connectors.
|
|
|
|
* drm_mode_setplane() already handles the basic refcounting for the
|
|
|
|
* framebuffers involved in this operation.
|
|
|
|
*/
|
|
|
|
ret = crtc->funcs->set_config(&set);
|
|
|
|
|
|
|
|
kfree(connector_list);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_primary_helper_update);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_primary_helper_disable() - Helper for primary plane disable
|
|
|
|
* @plane: plane to disable
|
|
|
|
*
|
|
|
|
* Provides a default plane disable handler for primary planes. This is handler
|
|
|
|
* is called in response to a userspace SetPlane operation on the plane with a
|
2014-04-15 16:02:43 +08:00
|
|
|
* NULL framebuffer parameter. It unconditionally fails the disable call with
|
|
|
|
* -EINVAL the only way to disable the primary plane without driver support is
|
|
|
|
* to disable the entier CRTC. Which does not match the plane ->disable hook.
|
2014-04-02 06:22:35 +08:00
|
|
|
*
|
|
|
|
* Note that some hardware may be able to disable the primary plane without
|
|
|
|
* disabling the whole CRTC. Drivers for such hardware should provide their
|
|
|
|
* own disable handler that disables just the primary plane (and they'll likely
|
|
|
|
* need to provide their own update handler as well to properly re-enable a
|
|
|
|
* disabled primary plane).
|
|
|
|
*
|
|
|
|
* RETURNS:
|
2014-04-15 16:02:43 +08:00
|
|
|
* Unconditionally returns -EINVAL.
|
2014-04-02 06:22:35 +08:00
|
|
|
*/
|
|
|
|
int drm_primary_helper_disable(struct drm_plane *plane)
|
|
|
|
{
|
2014-04-15 16:02:43 +08:00
|
|
|
return -EINVAL;
|
2014-04-02 06:22:35 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_primary_helper_disable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* drm_primary_helper_destroy() - Helper for primary plane destruction
|
|
|
|
* @plane: plane to destroy
|
|
|
|
*
|
|
|
|
* Provides a default plane destroy handler for primary planes. This handler
|
|
|
|
* is called during CRTC destruction. We disable the primary plane, remove
|
|
|
|
* it from the DRM plane list, and deallocate the plane structure.
|
|
|
|
*/
|
|
|
|
void drm_primary_helper_destroy(struct drm_plane *plane)
|
|
|
|
{
|
|
|
|
drm_plane_cleanup(plane);
|
|
|
|
kfree(plane);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_primary_helper_destroy);
|
|
|
|
|
|
|
|
const struct drm_plane_funcs drm_primary_helper_funcs = {
|
|
|
|
.update_plane = drm_primary_helper_update,
|
|
|
|
.disable_plane = drm_primary_helper_disable,
|
|
|
|
.destroy = drm_primary_helper_destroy,
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL(drm_primary_helper_funcs);
|
|
|
|
|
2015-03-05 17:32:44 +08:00
|
|
|
static struct drm_plane *create_primary_plane(struct drm_device *dev)
|
2014-04-02 06:22:35 +08:00
|
|
|
{
|
|
|
|
struct drm_plane *primary;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
primary = kzalloc(sizeof(*primary), GFP_KERNEL);
|
|
|
|
if (primary == NULL) {
|
|
|
|
DRM_DEBUG_KMS("Failed to allocate primary plane\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-03-11 15:35:47 +08:00
|
|
|
/*
|
|
|
|
* Remove the format_default field from drm_plane when dropping
|
|
|
|
* this helper.
|
|
|
|
*/
|
|
|
|
primary->format_default = true;
|
|
|
|
|
2014-04-02 06:22:35 +08:00
|
|
|
/* possible_crtc's will be filled in later by crtc_init */
|
2014-07-01 06:37:51 +08:00
|
|
|
ret = drm_universal_plane_init(dev, primary, 0,
|
|
|
|
&drm_primary_helper_funcs,
|
2015-03-05 17:32:44 +08:00
|
|
|
safe_modeset_formats,
|
|
|
|
ARRAY_SIZE(safe_modeset_formats),
|
2014-07-01 06:37:51 +08:00
|
|
|
DRM_PLANE_TYPE_PRIMARY);
|
2014-04-02 06:22:35 +08:00
|
|
|
if (ret) {
|
|
|
|
kfree(primary);
|
|
|
|
primary = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return primary;
|
|
|
|
}
|
|
|
|
|
2014-04-02 06:22:38 +08:00
|
|
|
/**
|
|
|
|
* drm_crtc_init - Legacy CRTC initialization function
|
|
|
|
* @dev: DRM device
|
|
|
|
* @crtc: CRTC object to init
|
|
|
|
* @funcs: callbacks for the new CRTC
|
|
|
|
*
|
|
|
|
* Initialize a CRTC object with a default helper-provided primary plane and no
|
|
|
|
* cursor plane.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Zero on success, error code on failure.
|
|
|
|
*/
|
|
|
|
int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
|
|
|
|
const struct drm_crtc_funcs *funcs)
|
|
|
|
{
|
|
|
|
struct drm_plane *primary;
|
|
|
|
|
2015-03-05 17:32:44 +08:00
|
|
|
primary = create_primary_plane(dev);
|
2014-04-02 06:22:38 +08:00
|
|
|
return drm_crtc_init_with_planes(dev, crtc, primary, NULL, funcs);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_crtc_init);
|
2014-07-29 21:33:05 +08:00
|
|
|
|
2014-10-29 18:13:47 +08:00
|
|
|
int drm_plane_helper_commit(struct drm_plane *plane,
|
|
|
|
struct drm_plane_state *plane_state,
|
|
|
|
struct drm_framebuffer *old_fb)
|
2014-07-29 21:33:05 +08:00
|
|
|
{
|
2015-03-11 17:51:06 +08:00
|
|
|
const struct drm_plane_helper_funcs *plane_funcs;
|
2014-07-29 21:33:05 +08:00
|
|
|
struct drm_crtc *crtc[2];
|
2015-03-11 17:51:06 +08:00
|
|
|
const struct drm_crtc_helper_funcs *crtc_funcs[2];
|
2014-07-29 21:33:05 +08:00
|
|
|
int i, ret = 0;
|
|
|
|
|
|
|
|
plane_funcs = plane->helper_private;
|
|
|
|
|
|
|
|
/* Since this is a transitional helper we can't assume that plane->state
|
|
|
|
* is always valid. Hence we need to use plane->crtc instead of
|
|
|
|
* plane->state->crtc as the old crtc. */
|
|
|
|
crtc[0] = plane->crtc;
|
|
|
|
crtc[1] = crtc[0] != plane_state->crtc ? plane_state->crtc : NULL;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
crtc_funcs[i] = crtc[i] ? crtc[i]->helper_private : NULL;
|
|
|
|
|
|
|
|
if (plane_funcs->atomic_check) {
|
|
|
|
ret = plane_funcs->atomic_check(plane, plane_state);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-01-20 00:31:49 +08:00
|
|
|
if (plane_funcs->prepare_fb && plane_state->fb &&
|
|
|
|
plane_state->fb != old_fb) {
|
2015-09-02 16:42:40 +08:00
|
|
|
ret = plane_funcs->prepare_fb(plane,
|
2015-03-03 22:22:31 +08:00
|
|
|
plane_state);
|
2014-07-29 21:33:05 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Point of no return, commit sw state. */
|
|
|
|
swap(plane->state, plane_state);
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (crtc_funcs[i] && crtc_funcs[i]->atomic_begin)
|
2015-07-21 19:28:58 +08:00
|
|
|
crtc_funcs[i]->atomic_begin(crtc[i], crtc[i]->state);
|
2014-07-29 21:33:05 +08:00
|
|
|
}
|
|
|
|
|
drm/plane: Add optional ->atomic_disable() callback
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>
2014-11-20 19:05:50 +08:00
|
|
|
/*
|
|
|
|
* Drivers may optionally implement the ->atomic_disable callback, so
|
|
|
|
* special-case that here.
|
|
|
|
*/
|
|
|
|
if (drm_atomic_plane_disabling(plane, plane_state) &&
|
|
|
|
plane_funcs->atomic_disable)
|
|
|
|
plane_funcs->atomic_disable(plane, plane_state);
|
|
|
|
else
|
|
|
|
plane_funcs->atomic_update(plane, plane_state);
|
2014-07-29 21:33:05 +08:00
|
|
|
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (crtc_funcs[i] && crtc_funcs[i]->atomic_flush)
|
2015-07-21 19:28:58 +08:00
|
|
|
crtc_funcs[i]->atomic_flush(crtc[i], crtc[i]->state);
|
2014-07-29 21:33:05 +08:00
|
|
|
}
|
|
|
|
|
2015-01-20 00:31:49 +08:00
|
|
|
/*
|
|
|
|
* If we only moved the plane and didn't change fb's, there's no need to
|
|
|
|
* wait for vblank.
|
|
|
|
*/
|
|
|
|
if (plane->state->fb == old_fb)
|
|
|
|
goto out;
|
|
|
|
|
2014-07-29 21:33:05 +08:00
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (!crtc[i])
|
|
|
|
continue;
|
|
|
|
|
2015-05-20 16:36:32 +08:00
|
|
|
if (crtc[i]->cursor == plane)
|
|
|
|
continue;
|
|
|
|
|
2014-07-29 21:33:05 +08:00
|
|
|
/* There's no other way to figure out whether the crtc is running. */
|
|
|
|
ret = drm_crtc_vblank_get(crtc[i]);
|
|
|
|
if (ret == 0) {
|
|
|
|
drm_crtc_wait_one_vblank(crtc[i]);
|
|
|
|
drm_crtc_vblank_put(crtc[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
|
2015-09-02 16:42:40 +08:00
|
|
|
if (plane_funcs->cleanup_fb)
|
|
|
|
plane_funcs->cleanup_fb(plane, plane_state);
|
2014-07-29 21:33:05 +08:00
|
|
|
out:
|
|
|
|
if (plane_state) {
|
|
|
|
if (plane->funcs->atomic_destroy_state)
|
|
|
|
plane->funcs->atomic_destroy_state(plane, plane_state);
|
|
|
|
else
|
2014-11-05 05:57:27 +08:00
|
|
|
drm_atomic_helper_plane_destroy_state(plane, plane_state);
|
2014-07-29 21:33:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-01-16 10:34:22 +08:00
|
|
|
* drm_plane_helper_update() - Transitional helper for plane update
|
2014-07-29 21:33:05 +08:00
|
|
|
* @plane: plane object to update
|
|
|
|
* @crtc: owning CRTC of owning plane
|
|
|
|
* @fb: framebuffer to flip onto plane
|
|
|
|
* @crtc_x: x offset of primary plane on crtc
|
|
|
|
* @crtc_y: y offset of primary plane on crtc
|
|
|
|
* @crtc_w: width of primary plane rectangle on crtc
|
|
|
|
* @crtc_h: height of primary plane rectangle on crtc
|
|
|
|
* @src_x: x offset of @fb for panning
|
|
|
|
* @src_y: y offset of @fb for panning
|
|
|
|
* @src_w: width of source rectangle in @fb
|
|
|
|
* @src_h: height of source rectangle in @fb
|
|
|
|
*
|
|
|
|
* Provides a default plane update handler using the atomic plane update
|
|
|
|
* functions. It is fully left to the driver to check plane constraints and
|
|
|
|
* handle corner-cases like a fully occluded or otherwise invisible plane.
|
|
|
|
*
|
|
|
|
* This is useful for piecewise transitioning of a driver to the atomic helpers.
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure
|
|
|
|
*/
|
|
|
|
int drm_plane_helper_update(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)
|
|
|
|
{
|
|
|
|
struct drm_plane_state *plane_state;
|
|
|
|
|
|
|
|
if (plane->funcs->atomic_duplicate_state)
|
|
|
|
plane_state = plane->funcs->atomic_duplicate_state(plane);
|
2015-07-02 22:33:53 +08:00
|
|
|
else {
|
|
|
|
if (!plane->state)
|
|
|
|
drm_atomic_helper_plane_reset(plane);
|
|
|
|
|
2014-11-05 05:57:27 +08:00
|
|
|
plane_state = drm_atomic_helper_plane_duplicate_state(plane);
|
2015-07-02 22:33:53 +08:00
|
|
|
}
|
2014-07-29 21:33:05 +08:00
|
|
|
if (!plane_state)
|
|
|
|
return -ENOMEM;
|
2014-11-27 22:49:39 +08:00
|
|
|
plane_state->plane = plane;
|
2014-07-29 21:33:05 +08:00
|
|
|
|
|
|
|
plane_state->crtc = crtc;
|
2014-11-05 05:57:27 +08:00
|
|
|
drm_atomic_set_fb_for_plane(plane_state, fb);
|
2014-07-29 21:33:05 +08:00
|
|
|
plane_state->crtc_x = crtc_x;
|
|
|
|
plane_state->crtc_y = crtc_y;
|
|
|
|
plane_state->crtc_h = crtc_h;
|
|
|
|
plane_state->crtc_w = crtc_w;
|
|
|
|
plane_state->src_x = src_x;
|
|
|
|
plane_state->src_y = src_y;
|
|
|
|
plane_state->src_h = src_h;
|
|
|
|
plane_state->src_w = src_w;
|
|
|
|
|
2014-10-29 18:13:47 +08:00
|
|
|
return drm_plane_helper_commit(plane, plane_state, plane->fb);
|
2014-07-29 21:33:05 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_plane_helper_update);
|
|
|
|
|
|
|
|
/**
|
2015-01-16 10:34:22 +08:00
|
|
|
* drm_plane_helper_disable() - Transitional helper for plane disable
|
2014-07-29 21:33:05 +08:00
|
|
|
* @plane: plane to disable
|
|
|
|
*
|
|
|
|
* Provides a default plane disable handler using the atomic plane update
|
|
|
|
* functions. It is fully left to the driver to check plane constraints and
|
|
|
|
* handle corner-cases like a fully occluded or otherwise invisible plane.
|
|
|
|
*
|
|
|
|
* This is useful for piecewise transitioning of a driver to the atomic helpers.
|
|
|
|
*
|
|
|
|
* RETURNS:
|
|
|
|
* Zero on success, error code on failure
|
|
|
|
*/
|
|
|
|
int drm_plane_helper_disable(struct drm_plane *plane)
|
|
|
|
{
|
|
|
|
struct drm_plane_state *plane_state;
|
|
|
|
|
|
|
|
/* crtc helpers love to call disable functions for already disabled hw
|
|
|
|
* functions. So cope with that. */
|
|
|
|
if (!plane->crtc)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (plane->funcs->atomic_duplicate_state)
|
|
|
|
plane_state = plane->funcs->atomic_duplicate_state(plane);
|
2015-07-02 22:33:53 +08:00
|
|
|
else {
|
|
|
|
if (!plane->state)
|
|
|
|
drm_atomic_helper_plane_reset(plane);
|
|
|
|
|
2014-11-05 05:57:27 +08:00
|
|
|
plane_state = drm_atomic_helper_plane_duplicate_state(plane);
|
2015-07-02 22:33:53 +08:00
|
|
|
}
|
2014-07-29 21:33:05 +08:00
|
|
|
if (!plane_state)
|
|
|
|
return -ENOMEM;
|
2014-11-27 22:49:39 +08:00
|
|
|
plane_state->plane = plane;
|
2014-07-29 21:33:05 +08:00
|
|
|
|
|
|
|
plane_state->crtc = NULL;
|
2014-11-05 05:57:27 +08:00
|
|
|
drm_atomic_set_fb_for_plane(plane_state, NULL);
|
2014-07-29 21:33:05 +08:00
|
|
|
|
2014-10-29 18:13:47 +08:00
|
|
|
return drm_plane_helper_commit(plane, plane_state, plane->fb);
|
2014-07-29 21:33:05 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(drm_plane_helper_disable);
|