summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/drm/xe/xe_gt_throttle_sysfs.c
blob: 63d640591a527272e646ca3927b4ee3a6d71f137 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
// SPDX-License-Identifier: MIT
/*
 * Copyright © 2023 Intel Corporation
 */

#include <drm/drm_managed.h>

#include <regs/xe_gt_regs.h>
#include "xe_device.h"
#include "xe_gt.h"
#include "xe_gt_sysfs.h"
#include "xe_gt_throttle_sysfs.h"
#include "xe_mmio.h"

/**
 * DOC: Xe GT Throttle
 *
 * Provides sysfs entries for frequency throttle reasons in GT
 *
 * device/gt#/freq0/throttle/status - Overall status
 * device/gt#/freq0/throttle/reason_pl1 - Frequency throttle due to PL1
 * device/gt#/freq0/throttle/reason_pl2 - Frequency throttle due to PL2
 * device/gt#/freq0/throttle/reason_pl4 - Frequency throttle due to PL4, Iccmax etc.
 * device/gt#/freq0/throttle/reason_thermal - Frequency throttle due to thermal
 * device/gt#/freq0/throttle/reason_prochot - Frequency throttle due to prochot
 * device/gt#/freq0/throttle/reason_ratl - Frequency throttle due to RATL
 * device/gt#/freq0/throttle/reason_vr_thermalert - Frequency throttle due to VR THERMALERT
 * device/gt#/freq0/throttle/reason_vr_tdc -  Frequency throttle due to VR TDC
 */

static struct xe_gt *
dev_to_gt(struct device *dev)
{
	return kobj_to_gt(dev->kobj.parent);
}

static u32 read_perf_limit_reasons(struct xe_gt *gt)
{
	u32 reg;

	if (xe_gt_is_media_type(gt))
		reg = xe_mmio_read32(gt, MTL_MEDIA_PERF_LIMIT_REASONS);
	else
		reg = xe_mmio_read32(gt, GT0_PERF_LIMIT_REASONS);

	return reg;
}

static u32 read_status(struct xe_gt *gt)
{
	u32 status = read_perf_limit_reasons(gt) & GT0_PERF_LIMIT_REASONS_MASK;

	return status;
}

static u32 read_reason_pl1(struct xe_gt *gt)
{
	u32 pl1 = read_perf_limit_reasons(gt) & POWER_LIMIT_1_MASK;

	return pl1;
}

static u32 read_reason_pl2(struct xe_gt *gt)
{
	u32 pl2 = read_perf_limit_reasons(gt) & POWER_LIMIT_2_MASK;

	return pl2;
}

static u32 read_reason_pl4(struct xe_gt *gt)
{
	u32 pl4 = read_perf_limit_reasons(gt) & POWER_LIMIT_4_MASK;

	return pl4;
}

static u32 read_reason_thermal(struct xe_gt *gt)
{
	u32 thermal = read_perf_limit_reasons(gt) & THERMAL_LIMIT_MASK;

	return thermal;
}

static u32 read_reason_prochot(struct xe_gt *gt)
{
	u32 prochot = read_perf_limit_reasons(gt) & PROCHOT_MASK;

	return prochot;
}

static u32 read_reason_ratl(struct xe_gt *gt)
{
	u32 ratl = read_perf_limit_reasons(gt) & RATL_MASK;

	return ratl;
}

static u32 read_reason_vr_thermalert(struct xe_gt *gt)
{
	u32 thermalert = read_perf_limit_reasons(gt) & VR_THERMALERT_MASK;

	return thermalert;
}

static u32 read_reason_vr_tdc(struct xe_gt *gt)
{
	u32 tdc = read_perf_limit_reasons(gt) & VR_TDC_MASK;

	return tdc;
}

static ssize_t status_show(struct device *dev,
			   struct device_attribute *attr,
			   char *buff)
{
	struct xe_gt *gt = dev_to_gt(dev);
	bool status = !!read_status(gt);

	return sysfs_emit(buff, "%u\n", status);
}
static DEVICE_ATTR_RO(status);

static ssize_t reason_pl1_show(struct device *dev,
			       struct device_attribute *attr,
			       char *buff)
{
	struct xe_gt *gt = dev_to_gt(dev);
	bool pl1 = !!read_reason_pl1(gt);

	return sysfs_emit(buff, "%u\n", pl1);
}
static DEVICE_ATTR_RO(reason_pl1);

static ssize_t reason_pl2_show(struct device *dev,
			       struct device_attribute *attr,
			       char *buff)
{
	struct xe_gt *gt = dev_to_gt(dev);
	bool pl2 = !!read_reason_pl2(gt);

	return sysfs_emit(buff, "%u\n", pl2);
}
static DEVICE_ATTR_RO(reason_pl2);

static ssize_t reason_pl4_show(struct device *dev,
			       struct device_attribute *attr,
			       char *buff)
{
	struct xe_gt *gt = dev_to_gt(dev);
	bool pl4 = !!read_reason_pl4(gt);

	return sysfs_emit(buff, "%u\n", pl4);
}
static DEVICE_ATTR_RO(reason_pl4);

static ssize_t reason_thermal_show(struct device *dev,
				   struct device_attribute *attr,
				   char *buff)
{
	struct xe_gt *gt = dev_to_gt(dev);
	bool thermal = !!read_reason_thermal(gt);

	return sysfs_emit(buff, "%u\n", thermal);
}
static DEVICE_ATTR_RO(reason_thermal);

static ssize_t reason_prochot_show(struct device *dev,
				   struct device_attribute *attr,
				   char *buff)
{
	struct xe_gt *gt = dev_to_gt(dev);
	bool prochot = !!read_reason_prochot(gt);

	return sysfs_emit(buff, "%u\n", prochot);
}
static DEVICE_ATTR_RO(reason_prochot);

static ssize_t reason_ratl_show(struct device *dev,
				struct device_attribute *attr,
				char *buff)
{
	struct xe_gt *gt = dev_to_gt(dev);
	bool ratl = !!read_reason_ratl(gt);

	return sysfs_emit(buff, "%u\n", ratl);
}
static DEVICE_ATTR_RO(reason_ratl);

static ssize_t reason_vr_thermalert_show(struct device *dev,
					 struct device_attribute *attr,
					 char *buff)
{
	struct xe_gt *gt = dev_to_gt(dev);
	bool thermalert = !!read_reason_vr_thermalert(gt);

	return sysfs_emit(buff, "%u\n", thermalert);
}
static DEVICE_ATTR_RO(reason_vr_thermalert);

static ssize_t reason_vr_tdc_show(struct device *dev,
				  struct device_attribute *attr,
				  char *buff)
{
	struct xe_gt *gt = dev_to_gt(dev);
	bool tdc = !!read_reason_vr_tdc(gt);

	return sysfs_emit(buff, "%u\n", tdc);
}
static DEVICE_ATTR_RO(reason_vr_tdc);

static struct attribute *throttle_attrs[] = {
	&dev_attr_status.attr,
	&dev_attr_reason_pl1.attr,
	&dev_attr_reason_pl2.attr,
	&dev_attr_reason_pl4.attr,
	&dev_attr_reason_thermal.attr,
	&dev_attr_reason_prochot.attr,
	&dev_attr_reason_ratl.attr,
	&dev_attr_reason_vr_thermalert.attr,
	&dev_attr_reason_vr_tdc.attr,
	NULL
};

static const struct attribute_group throttle_group_attrs = {
	.name = "throttle",
	.attrs = throttle_attrs,
};

static void gt_throttle_sysfs_fini(struct drm_device *drm, void *arg)
{
	struct xe_gt *gt = arg;

	sysfs_remove_group(gt->freq, &throttle_group_attrs);
}

void xe_gt_throttle_sysfs_init(struct xe_gt *gt)
{
	struct xe_device *xe = gt_to_xe(gt);
	int err;

	err = sysfs_create_group(gt->freq, &throttle_group_attrs);
	if (err) {
		drm_warn(&xe->drm, "failed to register throttle sysfs, err: %d\n", err);
		return;
	}

	err = drmm_add_action_or_reset(&xe->drm, gt_throttle_sysfs_fini, gt);
	if (err)
		drm_warn(&xe->drm, "%s: drmm_add_action_or_reset failed, err: %d\n",
			 __func__, err);
}