mirror of
https://github.com/torvalds/linux.git
synced 2026-06-07 14:04:54 +02:00
UPSTREAM: drm/crc: Cleanup crtc_crc_open function
This patch make changes to allocate crc-entries buffer before
enabling CRC generation.
It moves all the failure check early in the function before setting
the source or memory allocation.
Now set_crc_source takes only two variable inputs, values_cnt we
already gets as part of verify_crc_source.
Changes since V1:
- refactor code to use single spin lock
Changes since V2:
- rebase
Changes since V3:
- rebase on top of VKMS driver
Change-Id: Ice00c20dd988bd850b1d4b3f47d4d1f1f7ef83f6
Signed-off-by: Mahesh Kumar <mahesh1.kumar@intel.com>
Cc: dri-devel@lists.freedesktop.org
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Cc: Haneen Mohammed <hamohammed.sa@gmail.com>
Reviewed-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Acked-by: Leo Li <sunpeng.li@amd.com> (V2)
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> (V3)
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Sandy Huang <hjc@rock-chips.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180821083858.26275-3-mahesh1.kumar@intel.com
(cherry picked from commit c0811a7d5b)
This commit is contained in:
parent
93d8cf1baa
commit
d327288a19
|
|
@ -257,8 +257,7 @@ amdgpu_dm_remove_sink_from_freesync_module(struct drm_connector *connector);
|
|||
|
||||
/* amdgpu_dm_crc.c */
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
int amdgpu_dm_crtc_set_crc_source(struct drm_crtc *crtc, const char *src_name,
|
||||
size_t *values_cnt);
|
||||
int amdgpu_dm_crtc_set_crc_source(struct drm_crtc *crtc, const char *src_name);
|
||||
void amdgpu_dm_crtc_handle_crc_irq(struct drm_crtc *crtc);
|
||||
#else
|
||||
#define amdgpu_dm_crtc_set_crc_source NULL
|
||||
|
|
|
|||
|
|
@ -46,8 +46,7 @@ static enum amdgpu_dm_pipe_crc_source dm_parse_crc_source(const char *source)
|
|||
return AMDGPU_DM_PIPE_CRC_SOURCE_INVALID;
|
||||
}
|
||||
|
||||
int amdgpu_dm_crtc_set_crc_source(struct drm_crtc *crtc, const char *src_name,
|
||||
size_t *values_cnt)
|
||||
int amdgpu_dm_crtc_set_crc_source(struct drm_crtc *crtc, const char *src_name)
|
||||
{
|
||||
struct dm_crtc_state *crtc_state = to_dm_crtc_state(crtc->state);
|
||||
struct dc_stream_state *stream_state = crtc_state->stream;
|
||||
|
|
@ -88,7 +87,6 @@ int amdgpu_dm_crtc_set_crc_source(struct drm_crtc *crtc, const char *src_name,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
*values_cnt = 3;
|
||||
/* Reset crc_skipped on dm state */
|
||||
crtc_state->crc_skip_count = 0;
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -127,11 +127,9 @@ static ssize_t crc_control_write(struct file *file, const char __user *ubuf,
|
|||
if (source[len] == '\n')
|
||||
source[len] = '\0';
|
||||
|
||||
if (crtc->funcs->verify_crc_source) {
|
||||
ret = crtc->funcs->verify_crc_source(crtc, source, &values_cnt);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
ret = crtc->funcs->verify_crc_source(crtc, source, &values_cnt);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
spin_lock_irq(&crc->lock);
|
||||
|
||||
|
|
@ -197,40 +195,40 @@ static int crtc_crc_open(struct inode *inode, struct file *filep)
|
|||
return ret;
|
||||
}
|
||||
|
||||
spin_lock_irq(&crc->lock);
|
||||
if (!crc->opened)
|
||||
crc->opened = true;
|
||||
else
|
||||
ret = -EBUSY;
|
||||
spin_unlock_irq(&crc->lock);
|
||||
|
||||
ret = crtc->funcs->verify_crc_source(crtc, crc->source, &values_cnt);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = crtc->funcs->set_crc_source(crtc, crc->source, &values_cnt);
|
||||
if (WARN_ON(values_cnt > DRM_MAX_CRC_NR))
|
||||
return -EINVAL;
|
||||
|
||||
if (WARN_ON(values_cnt == 0))
|
||||
return -EINVAL;
|
||||
|
||||
entries = kcalloc(DRM_CRC_ENTRIES_NR, sizeof(*entries), GFP_KERNEL);
|
||||
if (!entries)
|
||||
return -ENOMEM;
|
||||
|
||||
spin_lock_irq(&crc->lock);
|
||||
if (!crc->opened) {
|
||||
crc->opened = true;
|
||||
crc->entries = entries;
|
||||
crc->values_cnt = values_cnt;
|
||||
} else {
|
||||
ret = -EBUSY;
|
||||
}
|
||||
spin_unlock_irq(&crc->lock);
|
||||
|
||||
if (ret) {
|
||||
kfree(entries);
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = crtc->funcs->set_crc_source(crtc, crc->source);
|
||||
if (ret)
|
||||
goto err;
|
||||
|
||||
if (WARN_ON(values_cnt > DRM_MAX_CRC_NR)) {
|
||||
ret = -EINVAL;
|
||||
goto err_disable;
|
||||
}
|
||||
|
||||
if (WARN_ON(values_cnt == 0)) {
|
||||
ret = -EINVAL;
|
||||
goto err_disable;
|
||||
}
|
||||
|
||||
entries = kcalloc(DRM_CRC_ENTRIES_NR, sizeof(*entries), GFP_KERNEL);
|
||||
if (!entries) {
|
||||
ret = -ENOMEM;
|
||||
goto err_disable;
|
||||
}
|
||||
|
||||
spin_lock_irq(&crc->lock);
|
||||
crc->entries = entries;
|
||||
crc->values_cnt = values_cnt;
|
||||
|
||||
/*
|
||||
* Only return once we got a first frame, so userspace doesn't have to
|
||||
* guess when this particular piece of HW will be ready to start
|
||||
|
|
@ -247,7 +245,7 @@ static int crtc_crc_open(struct inode *inode, struct file *filep)
|
|||
return 0;
|
||||
|
||||
err_disable:
|
||||
crtc->funcs->set_crc_source(crtc, NULL, &values_cnt);
|
||||
crtc->funcs->set_crc_source(crtc, NULL);
|
||||
err:
|
||||
spin_lock_irq(&crc->lock);
|
||||
crtc_crc_cleanup(crc);
|
||||
|
|
@ -259,9 +257,8 @@ static int crtc_crc_release(struct inode *inode, struct file *filep)
|
|||
{
|
||||
struct drm_crtc *crtc = filep->f_inode->i_private;
|
||||
struct drm_crtc_crc *crc = &crtc->crc;
|
||||
size_t values_cnt;
|
||||
|
||||
crtc->funcs->set_crc_source(crtc, NULL, &values_cnt);
|
||||
crtc->funcs->set_crc_source(crtc, NULL);
|
||||
|
||||
spin_lock_irq(&crc->lock);
|
||||
crtc_crc_cleanup(crc);
|
||||
|
|
@ -367,7 +364,7 @@ int drm_debugfs_crtc_crc_add(struct drm_crtc *crtc)
|
|||
{
|
||||
struct dentry *crc_ent, *ent;
|
||||
|
||||
if (!crtc->funcs->set_crc_source)
|
||||
if (!crtc->funcs->set_crc_source || !crtc->funcs->verify_crc_source)
|
||||
return 0;
|
||||
|
||||
crc_ent = debugfs_create_dir("crc", crtc->debugfs_entry);
|
||||
|
|
|
|||
|
|
@ -2172,8 +2172,7 @@ void lspcon_wait_pcon_mode(struct intel_lspcon *lspcon);
|
|||
|
||||
/* intel_pipe_crc.c */
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
int intel_crtc_set_crc_source(struct drm_crtc *crtc, const char *source_name,
|
||||
size_t *values_cnt);
|
||||
int intel_crtc_set_crc_source(struct drm_crtc *crtc, const char *source_name);
|
||||
void intel_crtc_disable_pipe_crc(struct intel_crtc *crtc);
|
||||
void intel_crtc_enable_pipe_crc(struct intel_crtc *crtc);
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -468,8 +468,7 @@ void intel_display_crc_init(struct drm_i915_private *dev_priv)
|
|||
}
|
||||
}
|
||||
|
||||
int intel_crtc_set_crc_source(struct drm_crtc *crtc, const char *source_name,
|
||||
size_t *values_cnt)
|
||||
int intel_crtc_set_crc_source(struct drm_crtc *crtc, const char *source_name)
|
||||
{
|
||||
struct drm_i915_private *dev_priv = to_i915(crtc->dev);
|
||||
struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[crtc->index];
|
||||
|
|
@ -508,7 +507,6 @@ int intel_crtc_set_crc_source(struct drm_crtc *crtc, const char *source_name,
|
|||
}
|
||||
|
||||
pipe_crc->skipped = 0;
|
||||
*values_cnt = 5;
|
||||
|
||||
out:
|
||||
intel_display_power_put(dev_priv, power_domain);
|
||||
|
|
|
|||
|
|
@ -757,8 +757,7 @@ static void rcar_du_crtc_disable_vblank(struct drm_crtc *crtc)
|
|||
}
|
||||
|
||||
static int rcar_du_crtc_set_crc_source(struct drm_crtc *crtc,
|
||||
const char *source_name,
|
||||
size_t *values_cnt)
|
||||
const char *source_name)
|
||||
{
|
||||
struct rcar_du_crtc *rcrtc = to_rcar_crtc(crtc);
|
||||
struct drm_modeset_acquire_ctx ctx;
|
||||
|
|
@ -798,8 +797,6 @@ static int rcar_du_crtc_set_crc_source(struct drm_crtc *crtc,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
*values_cnt = 1;
|
||||
|
||||
/* Perform an atomic commit to set the CRC source. */
|
||||
drm_modeset_acquire_init(&ctx, 0);
|
||||
|
||||
|
|
|
|||
|
|
@ -1111,7 +1111,7 @@ static struct drm_connector *vop_get_edp_connector(struct vop *vop)
|
|||
}
|
||||
|
||||
static int vop_crtc_set_crc_source(struct drm_crtc *crtc,
|
||||
const char *source_name, size_t *values_cnt)
|
||||
const char *source_name)
|
||||
{
|
||||
struct vop *vop = to_vop(crtc);
|
||||
struct drm_connector *connector;
|
||||
|
|
@ -1121,8 +1121,6 @@ static int vop_crtc_set_crc_source(struct drm_crtc *crtc,
|
|||
if (!connector)
|
||||
return -EINVAL;
|
||||
|
||||
*values_cnt = 3;
|
||||
|
||||
if (source_name && strcmp(source_name, "auto") == 0)
|
||||
ret = analogix_dp_start_crc(connector);
|
||||
else if (!source_name)
|
||||
|
|
@ -1146,7 +1144,7 @@ vop_crtc_verify_crc_source(struct drm_crtc *crtc, const char *source_name,
|
|||
|
||||
#else
|
||||
static int vop_crtc_set_crc_source(struct drm_crtc *crtc,
|
||||
const char *source_name, size_t *values_cnt)
|
||||
const char *source_name)
|
||||
{
|
||||
return -ENODEV;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -744,8 +744,7 @@ struct drm_crtc_funcs {
|
|||
*
|
||||
* 0 on success or a negative error code on failure.
|
||||
*/
|
||||
int (*set_crc_source)(struct drm_crtc *crtc, const char *source,
|
||||
size_t *values_cnt);
|
||||
int (*set_crc_source)(struct drm_crtc *crtc, const char *source);
|
||||
/**
|
||||
* @verify_crc_source:
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user