aie2_pm_set_mode() refuses to enter POWER_MODE_TURBO while a hardware
context is live, and reports it as -EINVAL. The mode argument is valid;
it is the device state that forbids the transition, which is what -EBUSY
says. Documentation/gpu/drm-uapi.rst describes -EINVAL as the catch-all
for "an invalid argument combination which cannot work", and lists
-EBUSY among the codes whose common meaning applies.

-EINVAL is returned for three distinct conditions on this path: an out
of range mode value and a non-zero reserved field, both in
aie2_set_power_mode(), plus this device-busy case. Userspace cannot tell
them apart, and the natural reading of -EINVAL sends the caller to audit
its arguments rather than to quiesce the device. The driver logs the
real reason, but that reaches the kernel log rather than the caller. The
practical cost is that the refusal reads as "turbo is unsupported on this
part" and the caller settles for POWER_MODE_HIGH, which pins the same
DPM level but leaves clock gating enabled.

-EBUSY is what the driver already returns elsewhere when a valid request
meets a conflicting device state, in aie2_ctx.c for a BO that is already
assigned to a context and in amdxdna_cbuf.c for carveout memory that is
already set up.

The guard covers the transition into turbo, not the state: a request
made while the device is already in turbo returns success before the
check is reached, so a context that starts afterwards does not change the
reported mode.

Signed-off-by: Taimuraz Kaitmazov <[email protected]>
---
Confirmed on npu4 that this guard is what refuses the transition: with a
hardware context live, xrt-smi configure --pmode turbo failed, and with
the device quiesced the same command succeeded. That ran against an
unpatched driver, so it establishes which branch is taken rather than the
errno a caller now sees.

Compile-tested on drm-misc-next (dc2f9f7fe), clang,
CONFIG_DRM_ACCEL_AMDXDNA=m.

 drivers/accel/amdxdna/aie2_pm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/accel/amdxdna/aie2_pm.c b/drivers/accel/amdxdna/aie2_pm.c
index 4fe6030d2..e4f2e9cc7 100644
--- a/drivers/accel/amdxdna/aie2_pm.c
+++ b/drivers/accel/amdxdna/aie2_pm.c
@@ -94,7 +94,7 @@ int aie2_pm_set_mode(struct amdxdna_dev_hdl *ndev, enum 
amdxdna_power_mode_type
        case POWER_MODE_TURBO:
                if (ndev->hwctx_num) {
                        XDNA_ERR(xdna, "Can not set turbo when there is active 
hwctx");
-                       return -EINVAL;
+                       return -EBUSY;
                }
 
                clk_gating = AIE2_CLK_GATING_DISABLE;
-- 
2.55.0

Reply via email to