Linux Audio

Check our new training course

Loading...
v4.6
  1/*
  2 * Copyright (C) 2009 Red Hat <bskeggs@redhat.com>
  3 *
  4 * Permission is hereby granted, free of charge, to any person obtaining
  5 * a copy of this software and associated documentation files (the
  6 * "Software"), to deal in the Software without restriction, including
  7 * without limitation the rights to use, copy, modify, merge, publish,
  8 * distribute, sublicense, and/or sell copies of the Software, and to
  9 * permit persons to whom the Software is furnished to do so, subject to
 10 * the following conditions:
 11 *
 12 * The above copyright notice and this permission notice (including the
 13 * next paragraph) shall be included in all copies or substantial
 14 * portions of the Software.
 15 *
 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 19 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
 20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 23 *
 24 */
 25
 26/*
 27 * Authors:
 28 *  Ben Skeggs <bskeggs@redhat.com>
 29 */
 30
 31#include <linux/debugfs.h>
 32#include <nvif/class.h>
 33#include <nvif/if0001.h>
 34#include "nouveau_debugfs.h"
 35#include "nouveau_drm.h"
 36
 37static int
 38nouveau_debugfs_vbios_image(struct seq_file *m, void *data)
 39{
 40	struct drm_info_node *node = (struct drm_info_node *) m->private;
 41	struct nouveau_drm *drm = nouveau_drm(node->minor->dev);
 42	int i;
 43
 44	for (i = 0; i < drm->vbios.length; i++)
 45		seq_printf(m, "%c", drm->vbios.data[i]);
 46	return 0;
 47}
 48
 49static int
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 50nouveau_debugfs_pstate_get(struct seq_file *m, void *data)
 51{
 52	struct drm_info_node *node = (struct drm_info_node *) m->private;
 53	struct nouveau_debugfs *debugfs = nouveau_debugfs(node->minor->dev);
 54	struct nvif_object *ctrl = &debugfs->ctrl;
 55	struct nvif_control_pstate_info_v0 info = {};
 56	int ret, i;
 57
 58	if (!debugfs)
 59		return -ENODEV;
 60
 61	ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_INFO, &info, sizeof(info));
 62	if (ret)
 63		return ret;
 64
 65	for (i = 0; i < info.count + 1; i++) {
 66		const s32 state = i < info.count ? i :
 67			NVIF_CONTROL_PSTATE_ATTR_V0_STATE_CURRENT;
 68		struct nvif_control_pstate_attr_v0 attr = {
 69			.state = state,
 70			.index = 0,
 71		};
 72
 73		ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_ATTR,
 74				&attr, sizeof(attr));
 75		if (ret)
 76			return ret;
 77
 78		if (i < info.count)
 79			seq_printf(m, "%02x:", attr.state);
 80		else
 81			seq_printf(m, "%s:", info.pwrsrc == 0 ? "DC" :
 82					     info.pwrsrc == 1 ? "AC" : "--");
 83
 84		attr.index = 0;
 85		do {
 86			attr.state = state;
 87			ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_ATTR,
 88					&attr, sizeof(attr));
 89			if (ret)
 90				return ret;
 91
 92			seq_printf(m, " %s %d", attr.name, attr.min);
 93			if (attr.min != attr.max)
 94				seq_printf(m, "-%d", attr.max);
 95			seq_printf(m, " %s", attr.unit);
 96		} while (attr.index);
 97
 98		if (state >= 0) {
 99			if (info.ustate_ac == state)
100				seq_printf(m, " AC");
101			if (info.ustate_dc == state)
102				seq_printf(m, " DC");
103			if (info.pstate == state)
104				seq_printf(m, " *");
105		} else {
106			if (info.ustate_ac < -1)
107				seq_printf(m, " AC");
108			if (info.ustate_dc < -1)
109				seq_printf(m, " DC");
110		}
111
112		seq_printf(m, "\n");
113	}
114
115	return 0;
116}
117
118static ssize_t
119nouveau_debugfs_pstate_set(struct file *file, const char __user *ubuf,
120			   size_t len, loff_t *offp)
121{
122	struct seq_file *m = file->private_data;
123	struct drm_info_node *node = (struct drm_info_node *) m->private;
124	struct nouveau_debugfs *debugfs = nouveau_debugfs(node->minor->dev);
125	struct nvif_object *ctrl = &debugfs->ctrl;
126	struct nvif_control_pstate_user_v0 args = { .pwrsrc = -EINVAL };
127	char buf[32] = {}, *tmp, *cur = buf;
128	long value, ret;
129
130	if (!debugfs)
131		return -ENODEV;
132
133	if (len >= sizeof(buf))
134		return -EINVAL;
135
136	if (copy_from_user(buf, ubuf, len))
137		return -EFAULT;
138
139	if ((tmp = strchr(buf, '\n')))
140		*tmp = '\0';
141
142	if (!strncasecmp(cur, "dc:", 3)) {
143		args.pwrsrc = 0;
144		cur += 3;
145	} else
146	if (!strncasecmp(cur, "ac:", 3)) {
147		args.pwrsrc = 1;
148		cur += 3;
149	}
150
151	if (!strcasecmp(cur, "none"))
152		args.ustate = NVIF_CONTROL_PSTATE_USER_V0_STATE_UNKNOWN;
153	else
154	if (!strcasecmp(cur, "auto"))
155		args.ustate = NVIF_CONTROL_PSTATE_USER_V0_STATE_PERFMON;
156	else {
157		ret = kstrtol(cur, 16, &value);
158		if (ret)
159			return ret;
160		args.ustate = value;
161	}
162
 
 
 
 
 
 
163	ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_USER, &args, sizeof(args));
 
164	if (ret < 0)
165		return ret;
166
167	return len;
168}
169
170static int
171nouveau_debugfs_pstate_open(struct inode *inode, struct file *file)
172{
173	return single_open(file, nouveau_debugfs_pstate_get, inode->i_private);
174}
175
176static const struct file_operations nouveau_pstate_fops = {
177	.owner = THIS_MODULE,
178	.open = nouveau_debugfs_pstate_open,
179	.read = seq_read,
180	.write = nouveau_debugfs_pstate_set,
 
181};
182
183static struct drm_info_list nouveau_debugfs_list[] = {
184	{ "vbios.rom", nouveau_debugfs_vbios_image, 0, NULL },
 
185};
186#define NOUVEAU_DEBUGFS_ENTRIES ARRAY_SIZE(nouveau_debugfs_list)
187
188static const struct nouveau_debugfs_files {
189	const char *name;
190	const struct file_operations *fops;
191} nouveau_debugfs_files[] = {
192	{"pstate", &nouveau_pstate_fops},
193};
194
195static int
196nouveau_debugfs_create_file(struct drm_minor *minor,
197		const struct nouveau_debugfs_files *ndf)
198{
199	struct drm_info_node *node;
200
201	node = kmalloc(sizeof(*node), GFP_KERNEL);
202	if (node == NULL)
203		return -ENOMEM;
204
205	node->minor = minor;
206	node->info_ent = (const void *)ndf->fops;
207	node->dent = debugfs_create_file(ndf->name, S_IRUGO | S_IWUSR,
208					 minor->debugfs_root, node, ndf->fops);
209	if (!node->dent) {
210		kfree(node);
211		return -ENOMEM;
212	}
213
214	mutex_lock(&minor->debugfs_lock);
215	list_add(&node->list, &minor->debugfs_list);
216	mutex_unlock(&minor->debugfs_lock);
217	return 0;
218}
219
220int
221nouveau_drm_debugfs_init(struct drm_minor *minor)
222{
223	int i, ret;
224
225	for (i = 0; i < ARRAY_SIZE(nouveau_debugfs_files); i++) {
226		ret = nouveau_debugfs_create_file(minor,
227						  &nouveau_debugfs_files[i]);
228
229		if (ret)
230			return ret;
231	}
232
233	return drm_debugfs_create_files(nouveau_debugfs_list,
234					NOUVEAU_DEBUGFS_ENTRIES,
235					minor->debugfs_root, minor);
236}
237
238void
239nouveau_drm_debugfs_cleanup(struct drm_minor *minor)
240{
 
 
241	int i;
242
243	drm_debugfs_remove_files(nouveau_debugfs_list, NOUVEAU_DEBUGFS_ENTRIES,
244				 minor);
245
246	for (i = 0; i < ARRAY_SIZE(nouveau_debugfs_files); i++) {
247		drm_debugfs_remove_files((struct drm_info_list *)
248					 nouveau_debugfs_files[i].fops,
249					 1, minor);
250	}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
251}
252
253int
254nouveau_debugfs_init(struct nouveau_drm *drm)
255{
256	int ret;
257
258	drm->debugfs = kzalloc(sizeof(*drm->debugfs), GFP_KERNEL);
259	if (!drm->debugfs)
260		return -ENOMEM;
261
262	ret = nvif_object_init(&drm->device.object, 0, NVIF_CLASS_CONTROL,
263			       NULL, 0, &drm->debugfs->ctrl);
264	if (ret)
265		return ret;
266
267	return 0;
268}
269
270void
271nouveau_debugfs_fini(struct nouveau_drm *drm)
272{
273	if (drm->debugfs && drm->debugfs->ctrl.priv)
274		nvif_object_fini(&drm->debugfs->ctrl);
275
276	kfree(drm->debugfs);
277	drm->debugfs = NULL;
278}
v6.2
  1/*
  2 * Copyright (C) 2009 Red Hat <bskeggs@redhat.com>
  3 *
  4 * Permission is hereby granted, free of charge, to any person obtaining
  5 * a copy of this software and associated documentation files (the
  6 * "Software"), to deal in the Software without restriction, including
  7 * without limitation the rights to use, copy, modify, merge, publish,
  8 * distribute, sublicense, and/or sell copies of the Software, and to
  9 * permit persons to whom the Software is furnished to do so, subject to
 10 * the following conditions:
 11 *
 12 * The above copyright notice and this permission notice (including the
 13 * next paragraph) shall be included in all copies or substantial
 14 * portions of the Software.
 15 *
 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 19 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
 20 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 21 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 22 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 23 *
 24 */
 25
 26/*
 27 * Authors:
 28 *  Ben Skeggs <bskeggs@redhat.com>
 29 */
 30
 31#include <linux/debugfs.h>
 32#include <nvif/class.h>
 33#include <nvif/if0001.h>
 34#include "nouveau_debugfs.h"
 35#include "nouveau_drv.h"
 36
 37static int
 38nouveau_debugfs_vbios_image(struct seq_file *m, void *data)
 39{
 40	struct drm_info_node *node = (struct drm_info_node *) m->private;
 41	struct nouveau_drm *drm = nouveau_drm(node->minor->dev);
 42	int i;
 43
 44	for (i = 0; i < drm->vbios.length; i++)
 45		seq_printf(m, "%c", drm->vbios.data[i]);
 46	return 0;
 47}
 48
 49static int
 50nouveau_debugfs_strap_peek(struct seq_file *m, void *data)
 51{
 52	struct drm_info_node *node = m->private;
 53	struct nouveau_drm *drm = nouveau_drm(node->minor->dev);
 54	int ret;
 55
 56	ret = pm_runtime_get_sync(drm->dev->dev);
 57	if (ret < 0 && ret != -EACCES) {
 58		pm_runtime_put_autosuspend(drm->dev->dev);
 59		return ret;
 60	}
 61
 62	seq_printf(m, "0x%08x\n",
 63		   nvif_rd32(&drm->client.device.object, 0x101000));
 64
 65	pm_runtime_mark_last_busy(drm->dev->dev);
 66	pm_runtime_put_autosuspend(drm->dev->dev);
 67
 68	return 0;
 69}
 70
 71static int
 72nouveau_debugfs_pstate_get(struct seq_file *m, void *data)
 73{
 74	struct drm_device *drm = m->private;
 75	struct nouveau_debugfs *debugfs = nouveau_debugfs(drm);
 76	struct nvif_object *ctrl = &debugfs->ctrl;
 77	struct nvif_control_pstate_info_v0 info = {};
 78	int ret, i;
 79
 80	if (!debugfs)
 81		return -ENODEV;
 82
 83	ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_INFO, &info, sizeof(info));
 84	if (ret)
 85		return ret;
 86
 87	for (i = 0; i < info.count + 1; i++) {
 88		const s32 state = i < info.count ? i :
 89			NVIF_CONTROL_PSTATE_ATTR_V0_STATE_CURRENT;
 90		struct nvif_control_pstate_attr_v0 attr = {
 91			.state = state,
 92			.index = 0,
 93		};
 94
 95		ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_ATTR,
 96				&attr, sizeof(attr));
 97		if (ret)
 98			return ret;
 99
100		if (i < info.count)
101			seq_printf(m, "%02x:", attr.state);
102		else
103			seq_printf(m, "%s:", info.pwrsrc == 0 ? "DC" :
104					     info.pwrsrc == 1 ? "AC" : "--");
105
106		attr.index = 0;
107		do {
108			attr.state = state;
109			ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_ATTR,
110					&attr, sizeof(attr));
111			if (ret)
112				return ret;
113
114			seq_printf(m, " %s %d", attr.name, attr.min);
115			if (attr.min != attr.max)
116				seq_printf(m, "-%d", attr.max);
117			seq_printf(m, " %s", attr.unit);
118		} while (attr.index);
119
120		if (state >= 0) {
121			if (info.ustate_ac == state)
122				seq_printf(m, " AC");
123			if (info.ustate_dc == state)
124				seq_printf(m, " DC");
125			if (info.pstate == state)
126				seq_printf(m, " *");
127		} else {
128			if (info.ustate_ac < -1)
129				seq_printf(m, " AC");
130			if (info.ustate_dc < -1)
131				seq_printf(m, " DC");
132		}
133
134		seq_printf(m, "\n");
135	}
136
137	return 0;
138}
139
140static ssize_t
141nouveau_debugfs_pstate_set(struct file *file, const char __user *ubuf,
142			   size_t len, loff_t *offp)
143{
144	struct seq_file *m = file->private_data;
145	struct drm_device *drm = m->private;
146	struct nouveau_debugfs *debugfs = nouveau_debugfs(drm);
147	struct nvif_object *ctrl = &debugfs->ctrl;
148	struct nvif_control_pstate_user_v0 args = { .pwrsrc = -EINVAL };
149	char buf[32] = {}, *tmp, *cur = buf;
150	long value, ret;
151
152	if (!debugfs)
153		return -ENODEV;
154
155	if (len >= sizeof(buf))
156		return -EINVAL;
157
158	if (copy_from_user(buf, ubuf, len))
159		return -EFAULT;
160
161	if ((tmp = strchr(buf, '\n')))
162		*tmp = '\0';
163
164	if (!strncasecmp(cur, "dc:", 3)) {
165		args.pwrsrc = 0;
166		cur += 3;
167	} else
168	if (!strncasecmp(cur, "ac:", 3)) {
169		args.pwrsrc = 1;
170		cur += 3;
171	}
172
173	if (!strcasecmp(cur, "none"))
174		args.ustate = NVIF_CONTROL_PSTATE_USER_V0_STATE_UNKNOWN;
175	else
176	if (!strcasecmp(cur, "auto"))
177		args.ustate = NVIF_CONTROL_PSTATE_USER_V0_STATE_PERFMON;
178	else {
179		ret = kstrtol(cur, 16, &value);
180		if (ret)
181			return ret;
182		args.ustate = value;
183	}
184
185	ret = pm_runtime_get_sync(drm->dev);
186	if (ret < 0 && ret != -EACCES) {
187		pm_runtime_put_autosuspend(drm->dev);
188		return ret;
189	}
190
191	ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_USER, &args, sizeof(args));
192	pm_runtime_put_autosuspend(drm->dev);
193	if (ret < 0)
194		return ret;
195
196	return len;
197}
198
199static int
200nouveau_debugfs_pstate_open(struct inode *inode, struct file *file)
201{
202	return single_open(file, nouveau_debugfs_pstate_get, inode->i_private);
203}
204
205static const struct file_operations nouveau_pstate_fops = {
206	.owner = THIS_MODULE,
207	.open = nouveau_debugfs_pstate_open,
208	.read = seq_read,
209	.write = nouveau_debugfs_pstate_set,
210	.release = single_release,
211};
212
213static struct drm_info_list nouveau_debugfs_list[] = {
214	{ "vbios.rom",  nouveau_debugfs_vbios_image, 0, NULL },
215	{ "strap_peek", nouveau_debugfs_strap_peek, 0, NULL },
216};
217#define NOUVEAU_DEBUGFS_ENTRIES ARRAY_SIZE(nouveau_debugfs_list)
218
219static const struct nouveau_debugfs_files {
220	const char *name;
221	const struct file_operations *fops;
222} nouveau_debugfs_files[] = {
223	{"pstate", &nouveau_pstate_fops},
224};
225
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226void
227nouveau_drm_debugfs_init(struct drm_minor *minor)
228{
229	struct nouveau_drm *drm = nouveau_drm(minor->dev);
230	struct dentry *dentry;
231	int i;
232
 
 
 
233	for (i = 0; i < ARRAY_SIZE(nouveau_debugfs_files); i++) {
234		debugfs_create_file(nouveau_debugfs_files[i].name,
235				    S_IRUGO | S_IWUSR,
236				    minor->debugfs_root, minor->dev,
237				    nouveau_debugfs_files[i].fops);
238	}
239
240	drm_debugfs_create_files(nouveau_debugfs_list,
241				 NOUVEAU_DEBUGFS_ENTRIES,
242				 minor->debugfs_root, minor);
243
244	/* Set the size of the vbios since we know it, and it's confusing to
245	 * userspace if it wants to seek() but the file has a length of 0
246	 */
247	dentry = debugfs_lookup("vbios.rom", minor->debugfs_root);
248	if (!dentry)
249		return;
250
251	d_inode(dentry)->i_size = drm->vbios.length;
252	dput(dentry);
253}
254
255int
256nouveau_debugfs_init(struct nouveau_drm *drm)
257{
 
 
258	drm->debugfs = kzalloc(sizeof(*drm->debugfs), GFP_KERNEL);
259	if (!drm->debugfs)
260		return -ENOMEM;
261
262	return nvif_object_ctor(&drm->client.device.object, "debugfsCtrl", 0,
263				NVIF_CLASS_CONTROL, NULL, 0,
264				&drm->debugfs->ctrl);
 
 
 
265}
266
267void
268nouveau_debugfs_fini(struct nouveau_drm *drm)
269{
270	if (drm->debugfs && drm->debugfs->ctrl.priv)
271		nvif_object_dtor(&drm->debugfs->ctrl);
272
273	kfree(drm->debugfs);
274	drm->debugfs = NULL;
275}