[Intel-gfx] [RFC 21/22] drm/i915/slpc: Add enable/disable debugfs for slpc

tom.orourke at intel.com tom.orourke at intel.com
Wed Jan 20 18:26:23 PST 2016


From: Tom O'Rourke <Tom.O'Rourke at intel.com>

Adds debugfs hooks for each slpc task.

The enable/disable debugfs files are
i915_slpc_dfps, i915_slpc_turbo, and i915_slpc_dcc.

Each of these can take the values:
"default", "enabled", or "disabled"

Signed-off-by: Tom O'Rourke <Tom.O'Rourke at intel.com>
---
 drivers/gpu/drm/i915/i915_debugfs.c | 251 ++++++++++++++++++++++++++++++++++++
 1 file changed, 251 insertions(+)

diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
index c26260e..a6171bf 100644
--- a/drivers/gpu/drm/i915/i915_debugfs.c
+++ b/drivers/gpu/drm/i915/i915_debugfs.c
@@ -1293,6 +1293,254 @@ static int i915_slpc_info(struct seq_file *m, void *unused)
 	return ret;
 }
 
+static int slpc_enable_disable_get(struct drm_device *dev, u64 *val,
+			       enum slpc_param_id enable_id,
+			       enum slpc_param_id disable_id)
+{
+	int ret1, ret2;
+	int override_enable, override_disable;
+	u32 value_enable, value_disable;
+
+	if (!HAS_SLPC(dev)) {
+		ret1 = -ENODEV;
+	} else if (val) {
+		ret1 = intel_slpc_get_param(dev, enable_id, &override_enable,
+					    &value_enable);
+		ret2 = intel_slpc_get_param(dev, disable_id, &override_disable,
+					    &value_disable);
+
+		/* set the output value:
+		* 0: default
+		* 1: enabled
+		* 2: disabled
+		* 3: unknown (should not happen)
+		*/
+		if (override_disable && (1 == value_disable))
+			*val = 2;
+		else if (override_enable && (1 == value_enable))
+			*val = 1;
+		else if (!override_enable && !override_disable)
+			*val = 0;
+		else
+			*val = 3;
+
+	} else {
+		ret1 = -EINVAL;
+	}
+
+	return ret1 ? ret1 : ret2;
+}
+
+static int slpc_enable_disable_set(struct drm_device *dev, u64 val,
+			       enum slpc_param_id enable_id,
+			       enum slpc_param_id disable_id)
+{
+	int ret1, ret2;
+
+	if (!HAS_SLPC(dev)) {
+		ret1 = -ENODEV;
+	} else if (0 == val) {
+		/* set default */
+		ret1 = intel_slpc_unset_param(dev, enable_id);
+		ret2 = intel_slpc_unset_param(dev, disable_id);
+	} else if (1 == val) {
+		/* set enable */
+		ret1 = intel_slpc_set_param(dev, enable_id, 1);
+		ret2 = intel_slpc_unset_param(dev, disable_id);
+	} else if (2 == val) {
+		/* set disable */
+		ret2 = intel_slpc_set_param(dev, disable_id, 1);
+		ret1 = intel_slpc_unset_param(dev, enable_id);
+	} else {
+		ret1 = -EINVAL;
+	}
+
+	return ret1 ? ret1 : ret2;
+}
+
+
+static void slpc_param_show(struct seq_file *m, enum slpc_param_id enable_id,
+			    enum slpc_param_id disable_id)
+{
+	struct drm_device *dev = m->private;
+	const char *status;
+	u64 val;
+	int ret;
+
+	ret = slpc_enable_disable_get(dev, &val, enable_id, disable_id);
+
+	if (ret) {
+		seq_printf(m, "error %d\n", ret);
+	} else {
+		switch (val) {
+		case 0:
+			status = "default\n";
+			break;
+
+		case 1:
+			status = "enabled\n";
+			break;
+
+		case 2:
+			status = "disabled\n";
+			break;
+
+		default:
+			status = "unknown\n";
+			break;
+		}
+
+		seq_puts(m, status);
+	}
+}
+
+static int slpc_param_write(struct seq_file *m, const char __user *ubuf,
+			    size_t len, enum slpc_param_id enable_id,
+                            enum slpc_param_id disable_id)
+{
+	struct drm_device *dev = m->private;
+	u64 val;
+	int ret = 0;
+	char buf[10];
+
+	if (len >= sizeof(buf))
+		ret = -EINVAL;
+	else if (copy_from_user(buf, ubuf, len))
+		ret = -EFAULT;
+	else
+		buf[len] = '\0';
+
+	if (!ret) {
+		if (!strncmp(buf, "default", 7))
+			val = 0;
+		else if (!strncmp(buf, "enabled", 7))
+			val = 1;
+		else if (!strncmp(buf, "disabled", 8))
+			val = 2;
+		else
+			ret = -EINVAL;
+	}
+
+	if (!ret)
+		ret = slpc_enable_disable_set(dev, val, enable_id, disable_id);
+
+	return ret;
+}
+
+static int slpc_dfps_show(struct seq_file *m, void *data)
+{
+	slpc_param_show(m, SLPC_PARAM_TASK_ENABLE_DFPS,
+			SLPC_PARAM_TASK_DISABLE_DFPS);
+
+	return 0;
+}
+
+static int slpc_dfps_open(struct inode *inode, struct file *file)
+{
+	struct drm_connector *dev = inode->i_private;
+
+	return single_open(file, slpc_dfps_show, dev);
+}
+
+static ssize_t slpc_dfps_write(struct file *file, const char __user *ubuf,
+			      size_t len, loff_t *offp)
+{
+	struct seq_file *m = file->private_data;
+	int ret = 0;
+
+	ret = slpc_param_write(m, ubuf, len, SLPC_PARAM_TASK_ENABLE_DFPS,
+			       SLPC_PARAM_TASK_DISABLE_DFPS);
+	if (ret)
+		return (size_t) ret;
+
+	return len;
+}
+
+static const struct file_operations i915_slpc_dfps_fops = {
+	.owner	 = THIS_MODULE,
+	.open	 = slpc_dfps_open,
+	.release = single_release,
+	.read	 = seq_read,
+	.write	 = slpc_dfps_write,
+	.llseek	 = seq_lseek
+};
+
+static int slpc_turbo_show(struct seq_file *m, void *data)
+{
+	slpc_param_show(m, SLPC_PARAM_TASK_ENABLE_TURBO,
+			SLPC_PARAM_TASK_DISABLE_TURBO);
+
+	return 0;
+}
+
+static int slpc_turbo_open(struct inode *inode, struct file *file)
+{
+	struct drm_connector *dev = inode->i_private;
+
+	return single_open(file, slpc_turbo_show, dev);
+}
+
+static ssize_t slpc_turbo_write(struct file *file, const char __user *ubuf,
+			      size_t len, loff_t *offp)
+{
+	struct seq_file *m = file->private_data;
+	int ret = 0;
+
+	ret = slpc_param_write(m, ubuf, len, SLPC_PARAM_TASK_ENABLE_TURBO,
+			       SLPC_PARAM_TASK_DISABLE_TURBO);
+	if (ret)
+		return (size_t) ret;
+
+	return len;
+}
+
+static const struct file_operations i915_slpc_turbo_fops = {
+	.owner	 = THIS_MODULE,
+	.open	 = slpc_turbo_open,
+	.release = single_release,
+	.read	 = seq_read,
+	.write	 = slpc_turbo_write,
+	.llseek	 = seq_lseek
+};
+
+static int slpc_dcc_show(struct seq_file *m, void *data)
+{
+	slpc_param_show(m, SLPC_PARAM_TASK_ENABLE_DCC,
+			SLPC_PARAM_TASK_DISABLE_DCC);
+
+	return 0;
+}
+
+static int slpc_dcc_open(struct inode *inode, struct file *file)
+{
+	struct drm_connector *dev = inode->i_private;
+
+	return single_open(file, slpc_dcc_show, dev);
+}
+
+static ssize_t slpc_dcc_write(struct file *file, const char __user *ubuf,
+			      size_t len, loff_t *offp)
+{
+	struct seq_file *m = file->private_data;
+	int ret = 0;
+
+	ret = slpc_param_write(m, ubuf, len, SLPC_PARAM_TASK_ENABLE_DCC,
+			       SLPC_PARAM_TASK_DISABLE_DCC);
+	if (ret)
+		return (size_t) ret;
+
+	return len;
+}
+
+static const struct file_operations i915_slpc_dcc_fops = {
+	.owner	 = THIS_MODULE,
+	.open	 = slpc_dcc_open,
+	.release = single_release,
+	.read	 = seq_read,
+	.write	 = slpc_dcc_write,
+	.llseek	 = seq_lseek
+};
+
 static int i915_frequency_info(struct seq_file *m, void *unused)
 {
 	struct drm_info_node *node = m->private;
@@ -5570,6 +5818,9 @@ static const struct i915_debugfs_files {
 	const struct file_operations *fops;
 } i915_debugfs_files[] = {
 	{"i915_wedged", &i915_wedged_fops},
+	{"i915_slpc_dfps", &i915_slpc_dfps_fops},
+	{"i915_slpc_turbo", &i915_slpc_turbo_fops},
+	{"i915_slpc_dcc", &i915_slpc_dcc_fops},
 	{"i915_max_freq", &i915_max_freq_fops},
 	{"i915_min_freq", &i915_min_freq_fops},
 	{"i915_cache_sharing", &i915_cache_sharing_fops},
-- 
1.9.1



More information about the Intel-gfx mailing list