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:
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.
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.
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"
38 nouveau_debugfs_vbios_image(struct seq_file *m, void *data)
40 struct drm_info_node *node = (struct drm_info_node *) m->private;
41 struct nouveau_drm *drm = nouveau_drm(node->minor->dev);
44 for (i = 0; i < drm->vbios.length; i++)
45 seq_printf(m, "%c", drm->vbios.data[i]);
50 nouveau_debugfs_strap_peek(struct seq_file *m, void *data)
52 struct drm_info_node *node = m->private;
53 struct nouveau_drm *drm = nouveau_drm(node->minor->dev);
56 ret = pm_runtime_get_sync(drm->dev->dev);
57 if (ret < 0 && ret != -EACCES) {
58 pm_runtime_put_autosuspend(drm->dev->dev);
62 seq_printf(m, "0x%08x\n",
63 nvif_rd32(&drm->client.device.object, 0x101000));
65 pm_runtime_mark_last_busy(drm->dev->dev);
66 pm_runtime_put_autosuspend(drm->dev->dev);
72 nouveau_debugfs_pstate_get(struct seq_file *m, void *data)
74 struct drm_device *drm = m->private;
75 struct nouveau_debugfs *debugfs = nouveau_debugfs(drm);
76 struct nvif_object *ctrl;
77 struct nvif_control_pstate_info_v0 info = {};
83 ctrl = &debugfs->ctrl;
84 ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_INFO, &info, sizeof(info));
88 for (i = 0; i < info.count + 1; i++) {
89 const s32 state = i < info.count ? i :
90 NVIF_CONTROL_PSTATE_ATTR_V0_STATE_CURRENT;
91 struct nvif_control_pstate_attr_v0 attr = {
96 ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_ATTR,
102 seq_printf(m, "%02x:", attr.state);
104 seq_printf(m, "%s:", info.pwrsrc == 0 ? "DC" :
105 info.pwrsrc == 1 ? "AC" : "--");
110 ret = nvif_mthd(ctrl, NVIF_CONTROL_PSTATE_ATTR,
111 &attr, sizeof(attr));
115 seq_printf(m, " %s %d", attr.name, attr.min);
116 if (attr.min != attr.max)
117 seq_printf(m, "-%d", attr.max);
118 seq_printf(m, " %s", attr.unit);
119 } while (attr.index);
122 if (info.ustate_ac == state)
124 if (info.ustate_dc == state)
126 if (info.pstate == state)
129 if (info.ustate_ac < -1)
131 if (info.ustate_dc < -1)
142 nouveau_debugfs_pstate_set(struct file *file, const char __user *ubuf,
143 size_t len, loff_t *offp)
145 struct seq_file *m = file->private_data;
146 struct drm_device *drm = m->private;
147 struct nouveau_debugfs *debugfs = nouveau_debugfs(drm);
148 struct nvif_control_pstate_user_v0 args = { .pwrsrc = -EINVAL };
149 char buf[32] = {}, *tmp, *cur = buf;
155 if (len >= sizeof(buf))
158 if (copy_from_user(buf, ubuf, len))
161 if ((tmp = strchr(buf, '\n')))
164 if (!strncasecmp(cur, "dc:", 3)) {
168 if (!strncasecmp(cur, "ac:", 3)) {
173 if (!strcasecmp(cur, "none"))
174 args.ustate = NVIF_CONTROL_PSTATE_USER_V0_STATE_UNKNOWN;
176 if (!strcasecmp(cur, "auto"))
177 args.ustate = NVIF_CONTROL_PSTATE_USER_V0_STATE_PERFMON;
179 ret = kstrtol(cur, 16, &value);
185 ret = pm_runtime_get_sync(drm->dev);
186 if (ret < 0 && ret != -EACCES) {
187 pm_runtime_put_autosuspend(drm->dev);
191 ret = nvif_mthd(&debugfs->ctrl, NVIF_CONTROL_PSTATE_USER,
192 &args, sizeof(args));
193 pm_runtime_put_autosuspend(drm->dev);
201 nouveau_debugfs_pstate_open(struct inode *inode, struct file *file)
203 return single_open(file, nouveau_debugfs_pstate_get, inode->i_private);
207 nouveau_debugfs_gpuva_regions(struct seq_file *m, struct nouveau_uvmm *uvmm)
209 MA_STATE(mas, &uvmm->region_mt, 0, 0);
210 struct nouveau_uvma_region *reg;
212 seq_puts (m, " VA regions | start | range | end \n");
213 seq_puts (m, "----------------------------------------------------------------------------\n");
214 mas_for_each(&mas, reg, ULONG_MAX)
215 seq_printf(m, " | 0x%016llx | 0x%016llx | 0x%016llx\n",
216 reg->va.addr, reg->va.range, reg->va.addr + reg->va.range);
220 nouveau_debugfs_gpuva(struct seq_file *m, void *data)
222 struct drm_info_node *node = (struct drm_info_node *) m->private;
223 struct nouveau_drm *drm = nouveau_drm(node->minor->dev);
224 struct nouveau_cli *cli;
226 mutex_lock(&drm->clients_lock);
227 list_for_each_entry(cli, &drm->clients, head) {
228 struct nouveau_uvmm *uvmm = nouveau_cli_uvmm(cli);
233 nouveau_uvmm_lock(uvmm);
234 drm_debugfs_gpuva_info(m, &uvmm->base);
236 nouveau_debugfs_gpuva_regions(m, uvmm);
237 nouveau_uvmm_unlock(uvmm);
239 mutex_unlock(&drm->clients_lock);
244 static const struct file_operations nouveau_pstate_fops = {
245 .owner = THIS_MODULE,
246 .open = nouveau_debugfs_pstate_open,
248 .write = nouveau_debugfs_pstate_set,
249 .release = single_release,
252 static struct drm_info_list nouveau_debugfs_list[] = {
253 { "vbios.rom", nouveau_debugfs_vbios_image, 0, NULL },
254 { "strap_peek", nouveau_debugfs_strap_peek, 0, NULL },
255 DRM_DEBUGFS_GPUVA_INFO(nouveau_debugfs_gpuva, NULL),
257 #define NOUVEAU_DEBUGFS_ENTRIES ARRAY_SIZE(nouveau_debugfs_list)
259 static const struct nouveau_debugfs_files {
261 const struct file_operations *fops;
262 } nouveau_debugfs_files[] = {
263 {"pstate", &nouveau_pstate_fops},
267 nouveau_drm_debugfs_init(struct drm_minor *minor)
269 struct nouveau_drm *drm = nouveau_drm(minor->dev);
270 struct dentry *dentry;
273 for (i = 0; i < ARRAY_SIZE(nouveau_debugfs_files); i++) {
274 debugfs_create_file(nouveau_debugfs_files[i].name,
276 minor->debugfs_root, minor->dev,
277 nouveau_debugfs_files[i].fops);
280 drm_debugfs_create_files(nouveau_debugfs_list,
281 NOUVEAU_DEBUGFS_ENTRIES,
282 minor->debugfs_root, minor);
284 /* Set the size of the vbios since we know it, and it's confusing to
285 * userspace if it wants to seek() but the file has a length of 0
287 dentry = debugfs_lookup("vbios.rom", minor->debugfs_root);
291 d_inode(dentry)->i_size = drm->vbios.length;
296 nouveau_debugfs_init(struct nouveau_drm *drm)
298 drm->debugfs = kzalloc(sizeof(*drm->debugfs), GFP_KERNEL);
302 return nvif_object_ctor(&drm->client.device.object, "debugfsCtrl", 0,
303 NVIF_CLASS_CONTROL, NULL, 0,
304 &drm->debugfs->ctrl);
308 nouveau_debugfs_fini(struct nouveau_drm *drm)
310 if (drm->debugfs && drm->debugfs->ctrl.priv)
311 nvif_object_dtor(&drm->debugfs->ctrl);
318 nouveau_module_debugfs_init(void)
320 nouveau_debugfs_root = debugfs_create_dir("nouveau", NULL);
321 if (IS_ERR(nouveau_debugfs_root))
322 return PTR_ERR(nouveau_debugfs_root);
328 nouveau_module_debugfs_fini(void)
330 debugfs_remove(nouveau_debugfs_root);