linux/drivers/gpu/drm/v3d/v3d_power.c
Maíra Canal 07e769ba3d
drm/v3d: Idle AXI transactions before disabling the clock on suspend
Currently, v3d_power_suspend() removes the GPU clock without first
quiescing the GPU's memory interface (AXI). If the clock is cut while the
core still has outstanding AXI transactions in flight, the hardware is
frozen mid-transaction. That corrupted state survives the power cycle, and
the first job submitted after the next resume will cause a GPU hang
accompanied by an L2T "pte invalid" MMU fault.

The hardware already provides a safe-powerdown sequence for this: request
the GMP to stop and wait for outstanding reads/writes to drain
(v3d_idle_axi()), plus the GCA safe shutdown on pre-4.1 HW
(v3d_idle_gca()). The driver implements both, but the runtime PM support
added later never invoked them when powering the GPU down.

Perform the safe-powerdown sequence in v3d_power_suspend() before
disabling the clock, while the core is still powered.

Link: https://github.com/raspberrypi/linux/issues/7443
Link: https://github.com/raspberrypi/linux/issues/7488
Fixes: 458f2a712a ("drm/v3d: Introduce Runtime Power Management")
Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
Link: https://patch.msgid.link/20260718-v3d-pm-axi-transactions-v1-2-4ecd7729ed70@igalia.com
Signed-off-by: Maíra Canal <mcanal@igalia.com>
2026-07-22 10:36:43 -03:00

97 lines
1.8 KiB
C

// SPDX-License-Identifier: GPL-2.0+
/* Copyright (C) 2026 Raspberry Pi */
#include <linux/clk.h>
#include <drm/drm_print.h>
#include "v3d_drv.h"
#include "v3d_regs.h"
static int
v3d_resume_sms(struct v3d_dev *v3d)
{
if (v3d->ver < V3D_GEN_71)
return 0;
V3D_SMS_WRITE(V3D_SMS_TEE_CS, V3D_SMS_CLEAR_POWER_OFF);
if (wait_for((V3D_GET_FIELD(V3D_SMS_READ(V3D_SMS_TEE_CS),
V3D_SMS_STATE) == V3D_SMS_IDLE), 100)) {
drm_err(&v3d->drm, "Failed to power up SMS\n");
return -ETIMEDOUT;
}
v3d_reset_sms(v3d);
return 0;
}
static int
v3d_suspend_sms(struct v3d_dev *v3d)
{
if (v3d->ver < V3D_GEN_71)
return 0;
V3D_SMS_WRITE(V3D_SMS_TEE_CS, V3D_SMS_POWER_OFF);
if (wait_for((V3D_GET_FIELD(V3D_SMS_READ(V3D_SMS_TEE_CS),
V3D_SMS_STATE) == V3D_SMS_POWER_OFF_STATE), 100)) {
drm_err(&v3d->drm, "Failed to power off SMS\n");
return -ETIMEDOUT;
}
return 0;
}
int v3d_power_suspend(struct device *dev)
{
struct drm_device *drm = dev_get_drvdata(dev);
struct v3d_dev *v3d = to_v3d_dev(drm);
int ret;
v3d_irq_disable(v3d);
v3d_clean_caches(v3d);
/* Wait until V3D has no active or pending AXI transactions. */
v3d_idle_axi(v3d, 0);
v3d_idle_gca(v3d);
ret = v3d_suspend_sms(v3d);
if (ret) {
/* Staying active: undo the GMP STOP_REQ from v3d_idle_axi(). */
V3D_WRITE(V3D_GMP_CFG(v3d->ver),
V3D_READ(V3D_GMP_CFG(v3d->ver)) & ~V3D_GMP_CFG_STOP_REQ);
v3d_irq_enable(v3d);
return ret;
}
clk_disable_unprepare(v3d->clk);
return 0;
}
int v3d_power_resume(struct device *dev)
{
struct drm_device *drm = dev_get_drvdata(dev);
struct v3d_dev *v3d = to_v3d_dev(drm);
int ret;
ret = clk_prepare_enable(v3d->clk);
if (ret)
return ret;
ret = v3d_resume_sms(v3d);
if (ret) {
clk_disable_unprepare(v3d->clk);
return ret;
}
v3d_init_hw_state(v3d);
v3d_mmu_set_page_table(v3d);
v3d_irq_enable(v3d);
return 0;
}