Commit 58fc5d18 authored by Jessica Zhang's avatar Jessica Zhang Committed by Dmitry Baryshkov
Browse files

drm/msm/dpu: Move LM CRC code into separate method



Move layer mixer-specific section of dpu_crtc_get_crc() into a separate
helper method. This way, we can make it easier to get CRCs from other HW
blocks by adding other get_crc helper methods.

Changes since V1:
- Move common bitmasks to dpu_hw_util.h
- Move common CRC methods to dpu_hw_util.c
- Update copyrights
- Change crcs array to a dynamically allocated array and added it as a
  member of crtc_state

Changes since V2:
- Put changes for hw_util into a separate commit
- Revert crcs array to a static array
- Add else case for set_crc_source to return EINVAL if no valid source
  is selected
- Add DPU_CRTC_MAX_CRC_ENTRIES macro

Changes since V3:
- Move crcs array into dpu_crtc_get_lm_crc
- Remove comment about crcs array in dpu_crtc_state struct
- Revert `lm` rename
- Remove DPU_CRTC_MAX_CRC_ENTRIES macro
- Return EINVAL in dpu_crtc_get_crc if no valid CRC source is set

Signed-off-by: default avatarJessica Zhang <quic_jesszhan@quicinc.com>
Reviewed-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
Patchwork: https://patchwork.freedesktop.org/patch/490735/
Link: https://lore.kernel.org/r/20220622171835.7558-2-quic_jesszhan@quicinc.com


Signed-off-by: default avatarDmitry Baryshkov <dmitry.baryshkov@linaro.org>
parent 4edea8d3
Loading
Loading
Loading
Loading
+41 −24
Original line number Original line Diff line number Diff line
// SPDX-License-Identifier: GPL-2.0-only
// SPDX-License-Identifier: GPL-2.0-only
/*
/*
 * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
 * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
 * Copyright (c) 2014-2021 The Linux Foundation. All rights reserved.
 * Copyright (C) 2013 Red Hat
 * Copyright (C) 2013 Red Hat
 * Author: Rob Clark <robdclark@gmail.com>
 * Author: Rob Clark <robdclark@gmail.com>
@@ -99,17 +100,32 @@ static int dpu_crtc_verify_crc_source(struct drm_crtc *crtc,
	return 0;
	return 0;
}
}


static void dpu_crtc_setup_lm_misr(struct dpu_crtc_state *crtc_state)
{
	struct dpu_crtc_mixer *m;
	int i;

	for (i = 0; i < crtc_state->num_mixers; ++i) {
		m = &crtc_state->mixers[i];

		if (!m->hw_lm || !m->hw_lm->ops.setup_misr)
			continue;

		/* Calculate MISR over 1 frame */
		m->hw_lm->ops.setup_misr(m->hw_lm, true, 1);
	}
}

static int dpu_crtc_set_crc_source(struct drm_crtc *crtc, const char *src_name)
static int dpu_crtc_set_crc_source(struct drm_crtc *crtc, const char *src_name)
{
{
	enum dpu_crtc_crc_source source = dpu_crtc_parse_crc_source(src_name);
	enum dpu_crtc_crc_source source = dpu_crtc_parse_crc_source(src_name);
	enum dpu_crtc_crc_source current_source;
	enum dpu_crtc_crc_source current_source;
	struct dpu_crtc_state *crtc_state;
	struct dpu_crtc_state *crtc_state;
	struct drm_device *drm_dev = crtc->dev;
	struct drm_device *drm_dev = crtc->dev;
	struct dpu_crtc_mixer *m;


	bool was_enabled;
	bool was_enabled;
	bool enable = false;
	bool enable = false;
	int i, ret = 0;
	int ret = 0;


	if (source < 0) {
	if (source < 0) {
		DRM_DEBUG_DRIVER("Invalid CRC source %s for CRTC%d\n", src_name, crtc->index);
		DRM_DEBUG_DRIVER("Invalid CRC source %s for CRTC%d\n", src_name, crtc->index);
@@ -146,16 +162,10 @@ static int dpu_crtc_set_crc_source(struct drm_crtc *crtc, const char *src_name)


	crtc_state->crc_frame_skip_count = 0;
	crtc_state->crc_frame_skip_count = 0;


	for (i = 0; i < crtc_state->num_mixers; ++i) {
	if (source == DPU_CRTC_CRC_SOURCE_LAYER_MIXER)
		m = &crtc_state->mixers[i];
		dpu_crtc_setup_lm_misr(crtc_state);

	else
		if (!m->hw_lm || !m->hw_lm->ops.setup_misr)
		ret = -EINVAL;
			continue;

		/* Calculate MISR over 1 frame */
		m->hw_lm->ops.setup_misr(m->hw_lm, true, 1);
	}



cleanup:
cleanup:
	drm_modeset_unlock(&crtc->mutex);
	drm_modeset_unlock(&crtc->mutex);
@@ -174,26 +184,17 @@ static u32 dpu_crtc_get_vblank_counter(struct drm_crtc *crtc)
	return dpu_encoder_get_vsync_count(encoder);
	return dpu_encoder_get_vsync_count(encoder);
}
}



static int dpu_crtc_get_lm_crc(struct drm_crtc *crtc,
static int dpu_crtc_get_crc(struct drm_crtc *crtc)
		struct dpu_crtc_state *crtc_state)
{
{
	struct dpu_crtc_state *crtc_state;
	struct dpu_crtc_mixer *m;
	struct dpu_crtc_mixer *m;
	u32 crcs[CRTC_DUAL_MIXERS];
	u32 crcs[CRTC_DUAL_MIXERS];


	int i = 0;
	int rc = 0;
	int rc = 0;

	int i;
	crtc_state = to_dpu_crtc_state(crtc->state);


	BUILD_BUG_ON(ARRAY_SIZE(crcs) != ARRAY_SIZE(crtc_state->mixers));
	BUILD_BUG_ON(ARRAY_SIZE(crcs) != ARRAY_SIZE(crtc_state->mixers));


	/* Skip first 2 frames in case of "uncooked" CRCs */
	if (crtc_state->crc_frame_skip_count < 2) {
		crtc_state->crc_frame_skip_count++;
		return 0;
	}

	for (i = 0; i < crtc_state->num_mixers; ++i) {
	for (i = 0; i < crtc_state->num_mixers; ++i) {


		m = &crtc_state->mixers[i];
		m = &crtc_state->mixers[i];
@@ -214,6 +215,22 @@ static int dpu_crtc_get_crc(struct drm_crtc *crtc)
			drm_crtc_accurate_vblank_count(crtc), crcs);
			drm_crtc_accurate_vblank_count(crtc), crcs);
}
}


static int dpu_crtc_get_crc(struct drm_crtc *crtc)
{
	struct dpu_crtc_state *crtc_state = to_dpu_crtc_state(crtc->state);

	/* Skip first 2 frames in case of "uncooked" CRCs */
	if (crtc_state->crc_frame_skip_count < 2) {
		crtc_state->crc_frame_skip_count++;
		return 0;
	}

	if (crtc_state->crc_source == DPU_CRTC_CRC_SOURCE_LAYER_MIXER)
		return dpu_crtc_get_lm_crc(crtc, crtc_state);

	return -EINVAL;
}

static bool dpu_crtc_get_scanout_position(struct drm_crtc *crtc,
static bool dpu_crtc_get_scanout_position(struct drm_crtc *crtc,
					   bool in_vblank_irq,
					   bool in_vblank_irq,
					   int *vpos, int *hpos,
					   int *vpos, int *hpos,
+2 −0
Original line number Original line Diff line number Diff line
@@ -201,6 +201,8 @@ struct dpu_crtc {
 * @mixers        : List of active mixers
 * @mixers        : List of active mixers
 * @num_ctls      : Number of ctl paths in use
 * @num_ctls      : Number of ctl paths in use
 * @hw_ctls       : List of active ctl paths
 * @hw_ctls       : List of active ctl paths
 * @crc_source    : CRC source
 * @crc_frame_skip_count: Number of frames skipped before getting CRC
 */
 */
struct dpu_crtc_state {
struct dpu_crtc_state {
	struct drm_crtc_state base;
	struct drm_crtc_state base;