drm/i915: Consolidate gem object list dumping
[linux-2.6] / drivers / gpu / drm / i915 / i915_gem_debugfs.c
1 /*
2  * Copyright © 2008 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  * Authors:
24  *    Eric Anholt <eric@anholt.net>
25  *    Keith Packard <keithp@keithp.com>
26  *
27  */
28
29 #include <linux/seq_file.h>
30 #include "drmP.h"
31 #include "drm.h"
32 #include "i915_drm.h"
33 #include "i915_drv.h"
34
35 #define DRM_I915_RING_DEBUG 1
36
37
38 #if defined(CONFIG_DEBUG_FS)
39
40 #define ACTIVE_LIST     1
41 #define FLUSHING_LIST   2
42 #define INACTIVE_LIST   3
43
44 static int i915_gem_object_list_info(struct seq_file *m, void *data)
45 {
46         struct drm_info_node *node = (struct drm_info_node *) m->private;
47         uintptr_t list = (uintptr_t) node->info_ent->data;
48         struct list_head *head;
49         struct drm_device *dev = node->minor->dev;
50         drm_i915_private_t *dev_priv = dev->dev_private;
51         struct drm_i915_gem_object *obj_priv;
52
53         switch (list) {
54         case ACTIVE_LIST:
55                 seq_printf(m, "Active:\n");
56                 head = &dev_priv->mm.active_list;
57                 break;
58         case INACTIVE_LIST:
59                 seq_printf(m, "Inctive:\n");
60                 head = &dev_priv->mm.inactive_list;
61                 break;
62         case FLUSHING_LIST:
63                 seq_printf(m, "Flushing:\n");
64                 head = &dev_priv->mm.flushing_list;
65                 break;
66         default:
67                 DRM_INFO("Ooops, unexpected list\n");
68                 return 0;
69         }
70
71         list_for_each_entry(obj_priv, head, list)
72         {
73                 struct drm_gem_object *obj = obj_priv->obj;
74                 if (obj->name) {
75                         seq_printf(m, "    %p(%d): %08x %08x %d\n",
76                                         obj, obj->name,
77                                         obj->read_domains, obj->write_domain,
78                                         obj_priv->last_rendering_seqno);
79                 } else {
80                         seq_printf(m, "       %p: %08x %08x %d\n",
81                                         obj,
82                                         obj->read_domains, obj->write_domain,
83                                         obj_priv->last_rendering_seqno);
84                 }
85         }
86         return 0;
87 }
88
89 static int i915_gem_request_info(struct seq_file *m, void *data)
90 {
91         struct drm_info_node *node = (struct drm_info_node *) m->private;
92         struct drm_device *dev = node->minor->dev;
93         drm_i915_private_t *dev_priv = dev->dev_private;
94         struct drm_i915_gem_request *gem_request;
95
96         seq_printf(m, "Request:\n");
97         list_for_each_entry(gem_request, &dev_priv->mm.request_list, list) {
98                 seq_printf(m, "    %d @ %d\n",
99                            gem_request->seqno,
100                            (int) (jiffies - gem_request->emitted_jiffies));
101         }
102         return 0;
103 }
104
105 static int i915_gem_seqno_info(struct seq_file *m, void *data)
106 {
107         struct drm_info_node *node = (struct drm_info_node *) m->private;
108         struct drm_device *dev = node->minor->dev;
109         drm_i915_private_t *dev_priv = dev->dev_private;
110
111         if (dev_priv->hw_status_page != NULL) {
112                 seq_printf(m, "Current sequence: %d\n",
113                            i915_get_gem_seqno(dev));
114         } else {
115                 seq_printf(m, "Current sequence: hws uninitialized\n");
116         }
117         seq_printf(m, "Waiter sequence:  %d\n",
118                         dev_priv->mm.waiting_gem_seqno);
119         seq_printf(m, "IRQ sequence:     %d\n", dev_priv->mm.irq_gem_seqno);
120         return 0;
121 }
122
123
124 static int i915_interrupt_info(struct seq_file *m, void *data)
125 {
126         struct drm_info_node *node = (struct drm_info_node *) m->private;
127         struct drm_device *dev = node->minor->dev;
128         drm_i915_private_t *dev_priv = dev->dev_private;
129
130         seq_printf(m, "Interrupt enable:    %08x\n",
131                    I915_READ(IER));
132         seq_printf(m, "Interrupt identity:  %08x\n",
133                    I915_READ(IIR));
134         seq_printf(m, "Interrupt mask:      %08x\n",
135                    I915_READ(IMR));
136         seq_printf(m, "Pipe A stat:         %08x\n",
137                    I915_READ(PIPEASTAT));
138         seq_printf(m, "Pipe B stat:         %08x\n",
139                    I915_READ(PIPEBSTAT));
140         seq_printf(m, "Interrupts received: %d\n",
141                    atomic_read(&dev_priv->irq_received));
142         if (dev_priv->hw_status_page != NULL) {
143                 seq_printf(m, "Current sequence:    %d\n",
144                            i915_get_gem_seqno(dev));
145         } else {
146                 seq_printf(m, "Current sequence:    hws uninitialized\n");
147         }
148         seq_printf(m, "Waiter sequence:     %d\n",
149                    dev_priv->mm.waiting_gem_seqno);
150         seq_printf(m, "IRQ sequence:        %d\n",
151                    dev_priv->mm.irq_gem_seqno);
152         return 0;
153 }
154
155 static int i915_hws_info(struct seq_file *m, void *data)
156 {
157         struct drm_info_node *node = (struct drm_info_node *) m->private;
158         struct drm_device *dev = node->minor->dev;
159         drm_i915_private_t *dev_priv = dev->dev_private;
160         int i;
161         volatile u32 *hws;
162
163         hws = (volatile u32 *)dev_priv->hw_status_page;
164         if (hws == NULL)
165                 return 0;
166
167         for (i = 0; i < 4096 / sizeof(u32) / 4; i += 4) {
168                 seq_printf(m, "0x%08x: 0x%08x 0x%08x 0x%08x 0x%08x\n",
169                            i * 4,
170                            hws[i], hws[i + 1], hws[i + 2], hws[i + 3]);
171         }
172         return 0;
173 }
174
175 static struct drm_info_list i915_gem_debugfs_list[] = {
176         {"i915_gem_active", i915_gem_object_list_info, 0, (void *) ACTIVE_LIST},
177         {"i915_gem_flushing", i915_gem_object_list_info, 0, (void *) FLUSHING_LIST},
178         {"i915_gem_inactive", i915_gem_object_list_info, 0, (void *) INACTIVE_LIST},
179         {"i915_gem_request", i915_gem_request_info, 0},
180         {"i915_gem_seqno", i915_gem_seqno_info, 0},
181         {"i915_gem_interrupt", i915_interrupt_info, 0},
182         {"i915_gem_hws", i915_hws_info, 0},
183 };
184 #define I915_GEM_DEBUGFS_ENTRIES ARRAY_SIZE(i915_gem_debugfs_list)
185
186 int i915_gem_debugfs_init(struct drm_minor *minor)
187 {
188         return drm_debugfs_create_files(i915_gem_debugfs_list,
189                                         I915_GEM_DEBUGFS_ENTRIES,
190                                         minor->debugfs_root, minor);
191 }
192
193 void i915_gem_debugfs_cleanup(struct drm_minor *minor)
194 {
195         drm_debugfs_remove_files(i915_gem_debugfs_list,
196                                  I915_GEM_DEBUGFS_ENTRIES, minor);
197 }
198
199 #endif /* CONFIG_DEBUG_FS */
200