]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe/gt_throttle: Always read and mask
authorLucas De Marchi <lucas.demarchi@intel.com>
Wed, 29 Oct 2025 23:45:05 +0000 (16:45 -0700)
committerLucas De Marchi <lucas.demarchi@intel.com>
Fri, 31 Oct 2025 06:20:25 +0000 (23:20 -0700)
Use a single function to read and mask the value the callers will be
interested in. This reduces the risk of a caller using a plain call to
xe_gt_throttle_get_limit_reasons() without applying any mask, which can
return unexpected bits for future platforms.

Select which reg and mask it's going to be used according to the
platform and gt type and always use that one function.

There was an odd xe_gt_dbg() when reading the status, which is not done
for any other throttle/* sysfs file, so just make the status be as
special as everybody else.

Reviewed-by: Raag Jadav <raag.jadav@intel.com>
Link: https://patch.msgid.link/20251029-gt-throttle-cri-v3-3-d1f5abbb8114@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
drivers/gpu/drm/xe/xe_gt_throttle.c

index c69710f2dbeb525be11dbd30f8c87464e5bfe88f..f743444f641a88b98e99d8d65d77e8fc28c137b1 100644 (file)
@@ -8,7 +8,6 @@
 #include <regs/xe_gt_regs.h>
 #include "xe_device.h"
 #include "xe_gt.h"
-#include "xe_gt_printk.h"
 #include "xe_gt_sysfs.h"
 #include "xe_gt_throttle.h"
 #include "xe_mmio.h"
@@ -57,32 +56,25 @@ dev_to_gt(struct device *dev)
 
 u32 xe_gt_throttle_get_limit_reasons(struct xe_gt *gt)
 {
-       u32 reg;
+       struct xe_device *xe = gt_to_xe(gt);
+       struct xe_reg reg;
+       u32 val, mask;
 
-       xe_pm_runtime_get(gt_to_xe(gt));
        if (xe_gt_is_media_type(gt))
-               reg = xe_mmio_read32(&gt->mmio, MTL_MEDIA_PERF_LIMIT_REASONS);
+               reg = MTL_MEDIA_PERF_LIMIT_REASONS;
        else
-               reg = xe_mmio_read32(&gt->mmio, GT0_PERF_LIMIT_REASONS);
-       xe_pm_runtime_put(gt_to_xe(gt));
-
-       return reg;
-}
-
-static u32 read_status(struct xe_gt *gt)
-{
-       struct xe_device *xe = gt_to_xe(gt);
-       u32 status, mask;
+               reg = GT0_PERF_LIMIT_REASONS;
 
        if (xe->info.platform == XE_CRESCENTISLAND)
                mask = CRI_PERF_LIMIT_REASONS_MASK;
        else
                mask = GT0_PERF_LIMIT_REASONS_MASK;
 
-       status = xe_gt_throttle_get_limit_reasons(gt) & mask;
-       xe_gt_dbg(gt, "throttle reasons: 0x%08x\n", status);
+       xe_pm_runtime_get(xe);
+       val = xe_mmio_read32(&gt->mmio, reg) & mask;
+       xe_pm_runtime_put(xe);
 
-       return status;
+       return val;
 }
 
 static bool is_throttled_by(struct xe_gt *gt, u32 mask)
@@ -96,7 +88,7 @@ static ssize_t status_show(struct kobject *kobj,
        struct device *dev = kobj_to_dev(kobj);
        struct xe_gt *gt = dev_to_gt(dev);
 
-       return sysfs_emit(buff, "%u\n", !!read_status(gt));
+       return sysfs_emit(buff, "%u\n", is_throttled_by(gt, U32_MAX));
 }
 static struct kobj_attribute attr_status = __ATTR_RO(status);