Linux Audio

Check our new training course

Loading...
v3.1
  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
 33#include "drmP.h"
 
 34#include "nouveau_drv.h"
 35
 36#include <ttm/ttm_page_alloc.h>
 37
 38static int
 39nouveau_debugfs_channel_info(struct seq_file *m, void *data)
 40{
 41	struct drm_info_node *node = (struct drm_info_node *) m->private;
 42	struct nouveau_channel *chan = node->info_ent->data;
 43
 44	seq_printf(m, "channel id    : %d\n", chan->id);
 45
 46	seq_printf(m, "cpu fifo state:\n");
 47	seq_printf(m, "          base: 0x%08x\n", chan->pushbuf_base);
 48	seq_printf(m, "           max: 0x%08x\n", chan->dma.max << 2);
 49	seq_printf(m, "           cur: 0x%08x\n", chan->dma.cur << 2);
 50	seq_printf(m, "           put: 0x%08x\n", chan->dma.put << 2);
 51	seq_printf(m, "          free: 0x%08x\n", chan->dma.free << 2);
 52	if (chan->dma.ib_max) {
 53		seq_printf(m, "        ib max: 0x%08x\n", chan->dma.ib_max);
 54		seq_printf(m, "        ib put: 0x%08x\n", chan->dma.ib_put);
 55		seq_printf(m, "       ib free: 0x%08x\n", chan->dma.ib_free);
 56	}
 57
 58	seq_printf(m, "gpu fifo state:\n");
 59	seq_printf(m, "           get: 0x%08x\n",
 60					nvchan_rd32(chan, chan->user_get));
 61	seq_printf(m, "           put: 0x%08x\n",
 62					nvchan_rd32(chan, chan->user_put));
 63	if (chan->dma.ib_max) {
 64		seq_printf(m, "        ib get: 0x%08x\n",
 65			   nvchan_rd32(chan, 0x88));
 66		seq_printf(m, "        ib put: 0x%08x\n",
 67			   nvchan_rd32(chan, 0x8c));
 68	}
 69
 70	seq_printf(m, "last fence    : %d\n", chan->fence.sequence);
 71	seq_printf(m, "last signalled: %d\n", chan->fence.sequence_ack);
 72	return 0;
 73}
 74
 75int
 76nouveau_debugfs_channel_init(struct nouveau_channel *chan)
 77{
 78	struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
 79	struct drm_minor *minor = chan->dev->primary;
 80	int ret;
 81
 82	if (!dev_priv->debugfs.channel_root) {
 83		dev_priv->debugfs.channel_root =
 84			debugfs_create_dir("channel", minor->debugfs_root);
 85		if (!dev_priv->debugfs.channel_root)
 86			return -ENOENT;
 87	}
 88
 89	snprintf(chan->debugfs.name, 32, "%d", chan->id);
 90	chan->debugfs.info.name = chan->debugfs.name;
 91	chan->debugfs.info.show = nouveau_debugfs_channel_info;
 92	chan->debugfs.info.driver_features = 0;
 93	chan->debugfs.info.data = chan;
 94
 95	ret = drm_debugfs_create_files(&chan->debugfs.info, 1,
 96				       dev_priv->debugfs.channel_root,
 97				       chan->dev->primary);
 98	if (ret == 0)
 99		chan->debugfs.active = true;
100	return ret;
101}
102
103void
104nouveau_debugfs_channel_fini(struct nouveau_channel *chan)
105{
106	struct drm_nouveau_private *dev_priv = chan->dev->dev_private;
 
 
 
 
107
108	if (!chan->debugfs.active)
109		return;
110
111	drm_debugfs_remove_files(&chan->debugfs.info, 1, chan->dev->primary);
112	chan->debugfs.active = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
113
114	if (chan == dev_priv->channel) {
115		debugfs_remove(dev_priv->debugfs.channel_root);
116		dev_priv->debugfs.channel_root = NULL;
117	}
118}
119
120static int
121nouveau_debugfs_chipset_info(struct seq_file *m, void *data)
122{
123	struct drm_info_node *node = (struct drm_info_node *) m->private;
124	struct drm_minor *minor = node->minor;
125	struct drm_device *dev = minor->dev;
126	struct drm_nouveau_private *dev_priv = dev->dev_private;
127	uint32_t ppci_0;
128
129	ppci_0 = nv_rd32(dev, dev_priv->chipset >= 0x40 ? 0x88000 : 0x1800);
130
131	seq_printf(m, "PMC_BOOT_0: 0x%08x\n", nv_rd32(dev, NV03_PMC_BOOT_0));
132	seq_printf(m, "PCI ID    : 0x%04x:0x%04x\n",
133		   ppci_0 & 0xffff, ppci_0 >> 16);
134	return 0;
135}
136
137static int
138nouveau_debugfs_memory_info(struct seq_file *m, void *data)
139{
140	struct drm_info_node *node = (struct drm_info_node *) m->private;
141	struct drm_minor *minor = node->minor;
142	struct drm_nouveau_private *dev_priv = minor->dev->dev_private;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
144	seq_printf(m, "VRAM total: %dKiB\n", (int)(dev_priv->vram_size >> 10));
145	return 0;
146}
 
 
 
 
 
 
 
 
147
148static int
149nouveau_debugfs_vbios_image(struct seq_file *m, void *data)
150{
151	struct drm_info_node *node = (struct drm_info_node *) m->private;
152	struct drm_nouveau_private *dev_priv = node->minor->dev->dev_private;
153	int i;
154
155	for (i = 0; i < dev_priv->vbios.length; i++)
156		seq_printf(m, "%c", dev_priv->vbios.data[i]);
157	return 0;
 
 
 
158}
159
160static int
161nouveau_debugfs_evict_vram(struct seq_file *m, void *data)
162{
163	struct drm_info_node *node = (struct drm_info_node *) m->private;
164	struct drm_nouveau_private *dev_priv = node->minor->dev->dev_private;
165	int ret;
166
167	ret = ttm_bo_evict_mm(&dev_priv->ttm.bdev, TTM_PL_VRAM);
168	if (ret)
169		seq_printf(m, "failed: %d", ret);
170	else
171		seq_printf(m, "succeeded\n");
172	return 0;
173}
174
 
 
 
 
 
 
 
 
175static struct drm_info_list nouveau_debugfs_list[] = {
176	{ "evict_vram", nouveau_debugfs_evict_vram, 0, NULL },
177	{ "chipset", nouveau_debugfs_chipset_info, 0, NULL },
178	{ "memory", nouveau_debugfs_memory_info, 0, NULL },
179	{ "vbios.rom", nouveau_debugfs_vbios_image, 0, NULL },
180	{ "ttm_page_pool", ttm_page_alloc_debugfs, 0, NULL },
181};
182#define NOUVEAU_DEBUGFS_ENTRIES ARRAY_SIZE(nouveau_debugfs_list)
183
184int
185nouveau_debugfs_init(struct drm_minor *minor)
 
 
 
 
 
 
 
186{
187	drm_debugfs_create_files(nouveau_debugfs_list, NOUVEAU_DEBUGFS_ENTRIES,
 
 
 
 
 
 
 
 
 
 
 
 
188				 minor->debugfs_root, minor);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189	return 0;
190}
191
192void
193nouveau_debugfs_takedown(struct drm_minor *minor)
194{
195	drm_debugfs_remove_files(nouveau_debugfs_list, NOUVEAU_DEBUGFS_ENTRIES,
196				 minor);
 
 
 
197}
v5.14.15
  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	int ret;
259
260	drm->debugfs = kzalloc(sizeof(*drm->debugfs), GFP_KERNEL);
261	if (!drm->debugfs)
262		return -ENOMEM;
263
264	ret = nvif_object_ctor(&drm->client.device.object, "debugfsCtrl", 0,
265			       NVIF_CLASS_CONTROL, NULL, 0,
266			       &drm->debugfs->ctrl);
267	if (ret)
268		return ret;
269
270	return 0;
271}
272
273void
274nouveau_debugfs_fini(struct nouveau_drm *drm)
275{
276	if (drm->debugfs && drm->debugfs->ctrl.priv)
277		nvif_object_dtor(&drm->debugfs->ctrl);
278
279	kfree(drm->debugfs);
280	drm->debugfs = NULL;
281}