Commit 61e983e7 authored by Lucas De Marchi's avatar Lucas De Marchi
Browse files

drm/xe/gt_throttle: Always read and mask



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: default avatarRaag Jadav <raag.jadav@intel.com>
Link: https://patch.msgid.link/20251029-gt-throttle-cri-v3-3-d1f5abbb8114@intel.com


Signed-off-by: default avatarLucas De Marchi <lucas.demarchi@intel.com>
parent f90556a4
Loading
Loading
Loading
Loading
+10 −18
Original line number Diff line number Diff line
@@ -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);