blob: ffe821b61f7d75a9acbc1623c067ebb3e158a281 [file] [log] [blame]
Dave Airlief64122c2013-02-25 14:47:55 +10001/*
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 * Alon Levy <alevy@redhat.com>
29 */
30
31#include <linux/debugfs.h>
32
33#include "drmP.h"
34#include "qxl_drv.h"
35#include "qxl_object.h"
36
37
David Rientjescaaa0352013-04-28 14:09:25 -070038#if defined(CONFIG_DEBUG_FS)
Dave Airlief64122c2013-02-25 14:47:55 +100039static int
40qxl_debugfs_irq_received(struct seq_file *m, void *data)
41{
42 struct drm_info_node *node = (struct drm_info_node *) m->private;
43 struct qxl_device *qdev = node->minor->dev->dev_private;
44
45 seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
46 seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
47 seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
48 seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
49 seq_printf(m, "%d\n", qdev->irq_received_error);
50 return 0;
51}
52
53static int
54qxl_debugfs_buffers_info(struct seq_file *m, void *data)
55{
56 struct drm_info_node *node = (struct drm_info_node *) m->private;
57 struct qxl_device *qdev = node->minor->dev->dev_private;
58 struct qxl_bo *bo;
59
60 list_for_each_entry(bo, &qdev->gem.objects, list) {
Maarten Lankhorst2f453ed2014-04-02 12:40:05 +020061 struct reservation_object_list *fobj;
62 int rel;
63
64 rcu_read_lock();
65 fobj = rcu_dereference(bo->tbo.resv->fence);
66 rel = fobj ? fobj->shared_count : 0;
67 rcu_read_unlock();
68
Maarten Lankhorstf2c24b82014-04-02 17:14:48 +020069 seq_printf(m, "size %ld, pc %d, num releases %d\n",
70 (unsigned long)bo->gem_base.size,
71 bo->pin_count, rel);
Dave Airlief64122c2013-02-25 14:47:55 +100072 }
73 return 0;
74}
75
76static struct drm_info_list qxl_debugfs_list[] = {
77 { "irq_received", qxl_debugfs_irq_received, 0, NULL },
78 { "qxl_buffers", qxl_debugfs_buffers_info, 0, NULL },
79};
80#define QXL_DEBUGFS_ENTRIES ARRAY_SIZE(qxl_debugfs_list)
David Rientjescaaa0352013-04-28 14:09:25 -070081#endif
Dave Airlief64122c2013-02-25 14:47:55 +100082
83int
84qxl_debugfs_init(struct drm_minor *minor)
85{
David Rientjescaaa0352013-04-28 14:09:25 -070086#if defined(CONFIG_DEBUG_FS)
Gabriel Krisman Bertazi2b65d562017-01-19 11:48:05 -020087 int r;
88 struct qxl_device *dev =
89 (struct qxl_device *) minor->dev->dev_private;
90
Dave Airlief64122c2013-02-25 14:47:55 +100091 drm_debugfs_create_files(qxl_debugfs_list, QXL_DEBUGFS_ENTRIES,
92 minor->debugfs_root, minor);
Gabriel Krisman Bertazi2b65d562017-01-19 11:48:05 -020093
94 r = qxl_ttm_debugfs_init(dev);
95 if (r) {
96 DRM_ERROR("Failed to init TTM debugfs\n");
97 return r;
98 }
David Rientjescaaa0352013-04-28 14:09:25 -070099#endif
Dave Airlief64122c2013-02-25 14:47:55 +1000100 return 0;
101}
102
Dave Airlief64122c2013-02-25 14:47:55 +1000103int qxl_debugfs_add_files(struct qxl_device *qdev,
104 struct drm_info_list *files,
105 unsigned nfiles)
106{
107 unsigned i;
108
109 for (i = 0; i < qdev->debugfs_count; i++) {
110 if (qdev->debugfs[i].files == files) {
111 /* Already registered */
112 return 0;
113 }
114 }
115
116 i = qdev->debugfs_count + 1;
117 if (i > QXL_DEBUGFS_MAX_COMPONENTS) {
118 DRM_ERROR("Reached maximum number of debugfs components.\n");
119 DRM_ERROR("Report so we increase QXL_DEBUGFS_MAX_COMPONENTS.\n");
120 return -EINVAL;
121 }
122 qdev->debugfs[qdev->debugfs_count].files = files;
123 qdev->debugfs[qdev->debugfs_count].num_files = nfiles;
124 qdev->debugfs_count = i;
125#if defined(CONFIG_DEBUG_FS)
126 drm_debugfs_create_files(files, nfiles,
Gabriel Krisman Bertazicbdded72017-01-26 23:05:48 -0200127 qdev->ddev.primary->debugfs_root,
128 qdev->ddev.primary);
Dave Airlief64122c2013-02-25 14:47:55 +1000129#endif
130 return 0;
131}