1 // SPDX-License-Identifier: MIT
3 * Copyright © 2023 Intel Corporation
6 #include <drm/drm_managed.h>
8 #include <regs/xe_gt_regs.h>
11 #include "xe_gt_printk.h"
12 #include "xe_gt_sysfs.h"
13 #include "xe_gt_throttle.h"
20 * Provides sysfs entries and other helpers for frequency throttle reasons in GT
22 * device/gt#/freq0/throttle/status - Overall status
23 * device/gt#/freq0/throttle/reason_pl1 - Frequency throttle due to PL1
24 * device/gt#/freq0/throttle/reason_pl2 - Frequency throttle due to PL2
25 * device/gt#/freq0/throttle/reason_pl4 - Frequency throttle due to PL4, Iccmax etc.
26 * device/gt#/freq0/throttle/reason_thermal - Frequency throttle due to thermal
27 * device/gt#/freq0/throttle/reason_prochot - Frequency throttle due to prochot
28 * device/gt#/freq0/throttle/reason_ratl - Frequency throttle due to RATL
29 * device/gt#/freq0/throttle/reason_vr_thermalert - Frequency throttle due to VR THERMALERT
30 * device/gt#/freq0/throttle/reason_vr_tdc - Frequency throttle due to VR TDC
34 dev_to_gt(struct device *dev)
36 return kobj_to_gt(dev->kobj.parent);
39 u32 xe_gt_throttle_get_limit_reasons(struct xe_gt *gt)
43 xe_pm_runtime_get(gt_to_xe(gt));
44 if (xe_gt_is_media_type(gt))
45 reg = xe_mmio_read32(>->mmio, MTL_MEDIA_PERF_LIMIT_REASONS);
47 reg = xe_mmio_read32(>->mmio, GT0_PERF_LIMIT_REASONS);
48 xe_pm_runtime_put(gt_to_xe(gt));
53 static u32 read_status(struct xe_gt *gt)
55 u32 status = xe_gt_throttle_get_limit_reasons(gt) & GT0_PERF_LIMIT_REASONS_MASK;
57 xe_gt_dbg(gt, "throttle reasons: 0x%08x\n", status);
61 static u32 read_reason_pl1(struct xe_gt *gt)
63 u32 pl1 = xe_gt_throttle_get_limit_reasons(gt) & POWER_LIMIT_1_MASK;
68 static u32 read_reason_pl2(struct xe_gt *gt)
70 u32 pl2 = xe_gt_throttle_get_limit_reasons(gt) & POWER_LIMIT_2_MASK;
75 static u32 read_reason_pl4(struct xe_gt *gt)
77 u32 pl4 = xe_gt_throttle_get_limit_reasons(gt) & POWER_LIMIT_4_MASK;
82 static u32 read_reason_thermal(struct xe_gt *gt)
84 u32 thermal = xe_gt_throttle_get_limit_reasons(gt) & THERMAL_LIMIT_MASK;
89 static u32 read_reason_prochot(struct xe_gt *gt)
91 u32 prochot = xe_gt_throttle_get_limit_reasons(gt) & PROCHOT_MASK;
96 static u32 read_reason_ratl(struct xe_gt *gt)
98 u32 ratl = xe_gt_throttle_get_limit_reasons(gt) & RATL_MASK;
103 static u32 read_reason_vr_thermalert(struct xe_gt *gt)
105 u32 thermalert = xe_gt_throttle_get_limit_reasons(gt) & VR_THERMALERT_MASK;
110 static u32 read_reason_vr_tdc(struct xe_gt *gt)
112 u32 tdc = xe_gt_throttle_get_limit_reasons(gt) & VR_TDC_MASK;
117 static ssize_t status_show(struct device *dev,
118 struct device_attribute *attr,
121 struct xe_gt *gt = dev_to_gt(dev);
122 bool status = !!read_status(gt);
124 return sysfs_emit(buff, "%u\n", status);
126 static DEVICE_ATTR_RO(status);
128 static ssize_t reason_pl1_show(struct device *dev,
129 struct device_attribute *attr,
132 struct xe_gt *gt = dev_to_gt(dev);
133 bool pl1 = !!read_reason_pl1(gt);
135 return sysfs_emit(buff, "%u\n", pl1);
137 static DEVICE_ATTR_RO(reason_pl1);
139 static ssize_t reason_pl2_show(struct device *dev,
140 struct device_attribute *attr,
143 struct xe_gt *gt = dev_to_gt(dev);
144 bool pl2 = !!read_reason_pl2(gt);
146 return sysfs_emit(buff, "%u\n", pl2);
148 static DEVICE_ATTR_RO(reason_pl2);
150 static ssize_t reason_pl4_show(struct device *dev,
151 struct device_attribute *attr,
154 struct xe_gt *gt = dev_to_gt(dev);
155 bool pl4 = !!read_reason_pl4(gt);
157 return sysfs_emit(buff, "%u\n", pl4);
159 static DEVICE_ATTR_RO(reason_pl4);
161 static ssize_t reason_thermal_show(struct device *dev,
162 struct device_attribute *attr,
165 struct xe_gt *gt = dev_to_gt(dev);
166 bool thermal = !!read_reason_thermal(gt);
168 return sysfs_emit(buff, "%u\n", thermal);
170 static DEVICE_ATTR_RO(reason_thermal);
172 static ssize_t reason_prochot_show(struct device *dev,
173 struct device_attribute *attr,
176 struct xe_gt *gt = dev_to_gt(dev);
177 bool prochot = !!read_reason_prochot(gt);
179 return sysfs_emit(buff, "%u\n", prochot);
181 static DEVICE_ATTR_RO(reason_prochot);
183 static ssize_t reason_ratl_show(struct device *dev,
184 struct device_attribute *attr,
187 struct xe_gt *gt = dev_to_gt(dev);
188 bool ratl = !!read_reason_ratl(gt);
190 return sysfs_emit(buff, "%u\n", ratl);
192 static DEVICE_ATTR_RO(reason_ratl);
194 static ssize_t reason_vr_thermalert_show(struct device *dev,
195 struct device_attribute *attr,
198 struct xe_gt *gt = dev_to_gt(dev);
199 bool thermalert = !!read_reason_vr_thermalert(gt);
201 return sysfs_emit(buff, "%u\n", thermalert);
203 static DEVICE_ATTR_RO(reason_vr_thermalert);
205 static ssize_t reason_vr_tdc_show(struct device *dev,
206 struct device_attribute *attr,
209 struct xe_gt *gt = dev_to_gt(dev);
210 bool tdc = !!read_reason_vr_tdc(gt);
212 return sysfs_emit(buff, "%u\n", tdc);
214 static DEVICE_ATTR_RO(reason_vr_tdc);
216 static struct attribute *throttle_attrs[] = {
217 &dev_attr_status.attr,
218 &dev_attr_reason_pl1.attr,
219 &dev_attr_reason_pl2.attr,
220 &dev_attr_reason_pl4.attr,
221 &dev_attr_reason_thermal.attr,
222 &dev_attr_reason_prochot.attr,
223 &dev_attr_reason_ratl.attr,
224 &dev_attr_reason_vr_thermalert.attr,
225 &dev_attr_reason_vr_tdc.attr,
229 static const struct attribute_group throttle_group_attrs = {
231 .attrs = throttle_attrs,
234 static void gt_throttle_sysfs_fini(void *arg)
236 struct xe_gt *gt = arg;
238 sysfs_remove_group(gt->freq, &throttle_group_attrs);
241 int xe_gt_throttle_init(struct xe_gt *gt)
243 struct xe_device *xe = gt_to_xe(gt);
246 err = sysfs_create_group(gt->freq, &throttle_group_attrs);
250 return devm_add_action_or_reset(xe->drm.dev, gt_throttle_sysfs_fini, gt);