Commit c52c35e5 authored by Jacek Lawrynowicz's avatar Jacek Lawrynowicz
Browse files

accel/ivpu: Return max freq for DRM_IVPU_PARAM_CORE_CLOCK_RATE



DRM_IVPU_PARAM_CORE_CLOCK_RATE returns current NPU frequency which
could be 0 if device was sleeping. This value isn't really useful to
the user space, so return max freq instead which can be used to estimate
NPU performance.

Fixes: c39dc151 ("accel/ivpu: Read clock rate only if device is up")
Cc: <stable@vger.kernel.org> # v6.7
Signed-off-by: default avatarJacek Lawrynowicz <jacek.lawrynowicz@linux.intel.com>
Reviewed-by: default avatarJeffrey Hugo <quic_jhugo@quicinc.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240402104929.941186-7-jacek.lawrynowicz@linux.intel.com
parent 3556f922
Loading
Loading
Loading
Loading
+1 −17
Original line number Diff line number Diff line
@@ -131,22 +131,6 @@ static int ivpu_get_capabilities(struct ivpu_device *vdev, struct drm_ivpu_param
	return 0;
}

static int ivpu_get_core_clock_rate(struct ivpu_device *vdev, u64 *clk_rate)
{
	int ret;

	ret = ivpu_rpm_get_if_active(vdev);
	if (ret < 0)
		return ret;

	*clk_rate = ret ? ivpu_hw_reg_pll_freq_get(vdev) : 0;

	if (ret)
		ivpu_rpm_put(vdev);

	return 0;
}

static int ivpu_get_param_ioctl(struct drm_device *dev, void *data, struct drm_file *file)
{
	struct ivpu_file_priv *file_priv = file->driver_priv;
@@ -170,7 +154,7 @@ static int ivpu_get_param_ioctl(struct drm_device *dev, void *data, struct drm_f
		args->value = vdev->platform;
		break;
	case DRM_IVPU_PARAM_CORE_CLOCK_RATE:
		ret = ivpu_get_core_clock_rate(vdev, &args->value);
		args->value = ivpu_hw_ratio_to_freq(vdev, vdev->hw->pll.max_ratio);
		break;
	case DRM_IVPU_PARAM_NUM_CONTEXTS:
		args->value = ivpu_get_context_count(vdev);
+6 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ struct ivpu_hw_ops {
	u32 (*profiling_freq_get)(struct ivpu_device *vdev);
	void (*profiling_freq_drive)(struct ivpu_device *vdev, bool enable);
	u32 (*reg_pll_freq_get)(struct ivpu_device *vdev);
	u32 (*ratio_to_freq)(struct ivpu_device *vdev, u32 ratio);
	u32 (*reg_telemetry_offset_get)(struct ivpu_device *vdev);
	u32 (*reg_telemetry_size_get)(struct ivpu_device *vdev);
	u32 (*reg_telemetry_enable_get)(struct ivpu_device *vdev);
@@ -130,6 +131,11 @@ static inline u32 ivpu_hw_reg_pll_freq_get(struct ivpu_device *vdev)
	return vdev->hw->ops->reg_pll_freq_get(vdev);
};

static inline u32 ivpu_hw_ratio_to_freq(struct ivpu_device *vdev, u32 ratio)
{
	return vdev->hw->ops->ratio_to_freq(vdev, ratio);
}

static inline u32 ivpu_hw_reg_telemetry_offset_get(struct ivpu_device *vdev)
{
	return vdev->hw->ops->reg_telemetry_offset_get(vdev);
+4 −3
Original line number Diff line number Diff line
@@ -803,12 +803,12 @@ static void ivpu_hw_37xx_profiling_freq_drive(struct ivpu_device *vdev, bool ena
	/* Profiling freq - is a debug feature. Unavailable on VPU 37XX. */
}

static u32 ivpu_hw_37xx_pll_to_freq(u32 ratio, u32 config)
static u32 ivpu_hw_37xx_ratio_to_freq(struct ivpu_device *vdev, u32 ratio)
{
	u32 pll_clock = PLL_REF_CLK_FREQ * ratio;
	u32 cpu_clock;

	if ((config & 0xff) == PLL_RATIO_4_3)
	if ((vdev->hw->config & 0xff) == PLL_RATIO_4_3)
		cpu_clock = pll_clock * 2 / 4;
	else
		cpu_clock = pll_clock * 2 / 5;
@@ -827,7 +827,7 @@ static u32 ivpu_hw_37xx_reg_pll_freq_get(struct ivpu_device *vdev)
	if (!ivpu_is_silicon(vdev))
		return PLL_SIMULATION_FREQ;

	return ivpu_hw_37xx_pll_to_freq(pll_curr_ratio, vdev->hw->config);
	return ivpu_hw_37xx_ratio_to_freq(vdev, pll_curr_ratio);
}

static u32 ivpu_hw_37xx_reg_telemetry_offset_get(struct ivpu_device *vdev)
@@ -1050,6 +1050,7 @@ const struct ivpu_hw_ops ivpu_hw_37xx_ops = {
	.profiling_freq_get = ivpu_hw_37xx_profiling_freq_get,
	.profiling_freq_drive = ivpu_hw_37xx_profiling_freq_drive,
	.reg_pll_freq_get = ivpu_hw_37xx_reg_pll_freq_get,
	.ratio_to_freq = ivpu_hw_37xx_ratio_to_freq,
	.reg_telemetry_offset_get = ivpu_hw_37xx_reg_telemetry_offset_get,
	.reg_telemetry_size_get = ivpu_hw_37xx_reg_telemetry_size_get,
	.reg_telemetry_enable_get = ivpu_hw_37xx_reg_telemetry_enable_get,
+6 −0
Original line number Diff line number Diff line
@@ -980,6 +980,11 @@ static u32 ivpu_hw_40xx_reg_pll_freq_get(struct ivpu_device *vdev)
	return PLL_RATIO_TO_FREQ(pll_curr_ratio);
}

static u32 ivpu_hw_40xx_ratio_to_freq(struct ivpu_device *vdev, u32 ratio)
{
	return PLL_RATIO_TO_FREQ(ratio);
}

static u32 ivpu_hw_40xx_reg_telemetry_offset_get(struct ivpu_device *vdev)
{
	return REGB_RD32(VPU_40XX_BUTTRESS_VPU_TELEMETRY_OFFSET);
@@ -1230,6 +1235,7 @@ const struct ivpu_hw_ops ivpu_hw_40xx_ops = {
	.profiling_freq_get = ivpu_hw_40xx_profiling_freq_get,
	.profiling_freq_drive = ivpu_hw_40xx_profiling_freq_drive,
	.reg_pll_freq_get = ivpu_hw_40xx_reg_pll_freq_get,
	.ratio_to_freq = ivpu_hw_40xx_ratio_to_freq,
	.reg_telemetry_offset_get = ivpu_hw_40xx_reg_telemetry_offset_get,
	.reg_telemetry_size_get = ivpu_hw_40xx_reg_telemetry_size_get,
	.reg_telemetry_enable_get = ivpu_hw_40xx_reg_telemetry_enable_get,