Commit | Line | Data |
---|---|---|
955b12de BG |
1 | /** |
2 | * \file drm_info.c | |
3 | * DRM info file implementations | |
4 | * | |
5 | * \author Ben Gamari <bgamari@gmail.com> | |
6 | */ | |
7 | ||
8 | /* | |
9 | * Created: Sun Dec 21 13:09:50 2008 by bgamari@gmail.com | |
10 | * | |
11 | * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. | |
12 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. | |
13 | * Copyright 2008 Ben Gamari <bgamari@gmail.com> | |
14 | * All Rights Reserved. | |
15 | * | |
16 | * Permission is hereby granted, free of charge, to any person obtaining a | |
17 | * copy of this software and associated documentation files (the "Software"), | |
18 | * to deal in the Software without restriction, including without limitation | |
19 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, | |
20 | * and/or sell copies of the Software, and to permit persons to whom the | |
21 | * Software is furnished to do so, subject to the following conditions: | |
22 | * | |
23 | * The above copyright notice and this permission notice (including the next | |
24 | * paragraph) shall be included in all copies or substantial portions of the | |
25 | * Software. | |
26 | * | |
27 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
28 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
29 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL | |
30 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR | |
31 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
32 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
33 | * OTHER DEALINGS IN THE SOFTWARE. | |
34 | */ | |
35 | ||
36 | #include <linux/seq_file.h> | |
760285e7 | 37 | #include <drm/drmP.h> |
955b12de BG |
38 | |
39 | /** | |
40 | * Called when "/proc/dri/.../name" is read. | |
41 | * | |
42 | * Prints the device name together with the bus id if available. | |
43 | */ | |
44 | int drm_name_info(struct seq_file *m, void *data) | |
45 | { | |
46 | struct drm_info_node *node = (struct drm_info_node *) m->private; | |
47 | struct drm_minor *minor = node->minor; | |
48 | struct drm_device *dev = minor->dev; | |
49 | struct drm_master *master = minor->master; | |
8410ea3b | 50 | const char *bus_name; |
955b12de BG |
51 | if (!master) |
52 | return 0; | |
53 | ||
8410ea3b DA |
54 | bus_name = dev->driver->bus->get_name(dev); |
55 | if (master->unique) { | |
56 | seq_printf(m, "%s %s %s\n", | |
57 | bus_name, | |
58 | dev_name(dev->dev), master->unique); | |
955b12de | 59 | } else { |
8410ea3b DA |
60 | seq_printf(m, "%s %s\n", |
61 | bus_name, dev_name(dev->dev)); | |
955b12de | 62 | } |
955b12de BG |
63 | return 0; |
64 | } | |
65 | ||
66 | /** | |
67 | * Called when "/proc/dri/.../vm" is read. | |
68 | * | |
69 | * Prints information about all mappings in drm_device::maplist. | |
70 | */ | |
71 | int drm_vm_info(struct seq_file *m, void *data) | |
72 | { | |
73 | struct drm_info_node *node = (struct drm_info_node *) m->private; | |
74 | struct drm_device *dev = node->minor->dev; | |
1847a549 | 75 | struct drm_local_map *map; |
955b12de BG |
76 | struct drm_map_list *r_list; |
77 | ||
78 | /* Hardcoded from _DRM_FRAME_BUFFER, | |
79 | _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and | |
80 | _DRM_SCATTER_GATHER and _DRM_CONSISTENT */ | |
81 | const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" }; | |
82 | const char *type; | |
83 | int i; | |
84 | ||
85 | mutex_lock(&dev->struct_mutex); | |
86 | seq_printf(m, "slot offset size type flags address mtrr\n\n"); | |
87 | i = 0; | |
88 | list_for_each_entry(r_list, &dev->maplist, head) { | |
89 | map = r_list->map; | |
90 | if (!map) | |
91 | continue; | |
92 | if (map->type < 0 || map->type > 5) | |
93 | type = "??"; | |
94 | else | |
95 | type = types[map->type]; | |
96 | ||
1847a549 | 97 | seq_printf(m, "%4d 0x%016llx 0x%08lx %4.4s 0x%02x 0x%08lx ", |
955b12de | 98 | i, |
1847a549 | 99 | (unsigned long long)map->offset, |
955b12de BG |
100 | map->size, type, map->flags, |
101 | (unsigned long) r_list->user_token); | |
102 | if (map->mtrr < 0) | |
103 | seq_printf(m, "none\n"); | |
104 | else | |
105 | seq_printf(m, "%4d\n", map->mtrr); | |
106 | i++; | |
107 | } | |
108 | mutex_unlock(&dev->struct_mutex); | |
109 | return 0; | |
110 | } | |
111 | ||
955b12de BG |
112 | /** |
113 | * Called when "/proc/dri/.../bufs" is read. | |
114 | */ | |
115 | int drm_bufs_info(struct seq_file *m, void *data) | |
116 | { | |
117 | struct drm_info_node *node = (struct drm_info_node *) m->private; | |
118 | struct drm_device *dev = node->minor->dev; | |
119 | struct drm_device_dma *dma; | |
120 | int i, seg_pages; | |
121 | ||
122 | mutex_lock(&dev->struct_mutex); | |
123 | dma = dev->dma; | |
124 | if (!dma) { | |
125 | mutex_unlock(&dev->struct_mutex); | |
126 | return 0; | |
127 | } | |
128 | ||
129 | seq_printf(m, " o size count free segs pages kB\n\n"); | |
130 | for (i = 0; i <= DRM_MAX_ORDER; i++) { | |
131 | if (dma->bufs[i].buf_count) { | |
132 | seg_pages = dma->bufs[i].seg_count * (1 << dma->bufs[i].page_order); | |
133 | seq_printf(m, "%2d %8d %5d %5d %5d %5d %5ld\n", | |
134 | i, | |
135 | dma->bufs[i].buf_size, | |
136 | dma->bufs[i].buf_count, | |
137 | atomic_read(&dma->bufs[i].freelist.count), | |
138 | dma->bufs[i].seg_count, | |
139 | seg_pages, | |
140 | seg_pages * PAGE_SIZE / 1024); | |
141 | } | |
142 | } | |
143 | seq_printf(m, "\n"); | |
144 | for (i = 0; i < dma->buf_count; i++) { | |
145 | if (i && !(i % 32)) | |
146 | seq_printf(m, "\n"); | |
147 | seq_printf(m, " %d", dma->buflist[i]->list); | |
148 | } | |
149 | seq_printf(m, "\n"); | |
150 | mutex_unlock(&dev->struct_mutex); | |
151 | return 0; | |
152 | } | |
153 | ||
154 | /** | |
155 | * Called when "/proc/dri/.../vblank" is read. | |
156 | */ | |
157 | int drm_vblank_info(struct seq_file *m, void *data) | |
158 | { | |
159 | struct drm_info_node *node = (struct drm_info_node *) m->private; | |
160 | struct drm_device *dev = node->minor->dev; | |
161 | int crtc; | |
162 | ||
163 | mutex_lock(&dev->struct_mutex); | |
164 | for (crtc = 0; crtc < dev->num_crtcs; crtc++) { | |
165 | seq_printf(m, "CRTC %d enable: %d\n", | |
5380e929 | 166 | crtc, atomic_read(&dev->vblank[crtc].refcount)); |
955b12de BG |
167 | seq_printf(m, "CRTC %d counter: %d\n", |
168 | crtc, drm_vblank_count(dev, crtc)); | |
169 | seq_printf(m, "CRTC %d last wait: %d\n", | |
5380e929 | 170 | crtc, dev->vblank[crtc].last_wait); |
955b12de | 171 | seq_printf(m, "CRTC %d in modeset: %d\n", |
5380e929 | 172 | crtc, dev->vblank[crtc].inmodeset); |
955b12de BG |
173 | } |
174 | mutex_unlock(&dev->struct_mutex); | |
175 | return 0; | |
176 | } | |
177 | ||
178 | /** | |
179 | * Called when "/proc/dri/.../clients" is read. | |
180 | * | |
181 | */ | |
182 | int drm_clients_info(struct seq_file *m, void *data) | |
183 | { | |
184 | struct drm_info_node *node = (struct drm_info_node *) m->private; | |
185 | struct drm_device *dev = node->minor->dev; | |
186 | struct drm_file *priv; | |
187 | ||
188 | mutex_lock(&dev->struct_mutex); | |
5952fba5 | 189 | seq_printf(m, "a dev pid uid magic\n\n"); |
955b12de | 190 | list_for_each_entry(priv, &dev->filelist, lhead) { |
5952fba5 | 191 | seq_printf(m, "%c %3d %5d %5d %10u\n", |
955b12de BG |
192 | priv->authenticated ? 'y' : 'n', |
193 | priv->minor->index, | |
5fce5e0b EB |
194 | pid_vnr(priv->pid), |
195 | from_kuid_munged(seq_user_ns(m), priv->uid), | |
5952fba5 | 196 | priv->magic); |
955b12de BG |
197 | } |
198 | mutex_unlock(&dev->struct_mutex); | |
199 | return 0; | |
200 | } | |
201 | ||
202 | ||
b375de0b | 203 | static int drm_gem_one_name_info(int id, void *ptr, void *data) |
955b12de BG |
204 | { |
205 | struct drm_gem_object *obj = ptr; | |
206 | struct seq_file *m = data; | |
207 | ||
955b12de BG |
208 | seq_printf(m, "%6d %8zd %7d %8d\n", |
209 | obj->name, obj->size, | |
a8e11d1c | 210 | obj->handle_count, |
955b12de BG |
211 | atomic_read(&obj->refcount.refcount)); |
212 | return 0; | |
213 | } | |
214 | ||
215 | int drm_gem_name_info(struct seq_file *m, void *data) | |
216 | { | |
217 | struct drm_info_node *node = (struct drm_info_node *) m->private; | |
218 | struct drm_device *dev = node->minor->dev; | |
219 | ||
220 | seq_printf(m, " name size handles refcount\n"); | |
90254ac0 | 221 | |
cd4f013f | 222 | mutex_lock(&dev->object_name_lock); |
955b12de | 223 | idr_for_each(&dev->object_name_idr, drm_gem_one_name_info, m); |
cd4f013f | 224 | mutex_unlock(&dev->object_name_lock); |
90254ac0 | 225 | |
955b12de BG |
226 | return 0; |
227 | } | |
228 | ||
955b12de BG |
229 | #if DRM_DEBUG_CODE |
230 | ||
231 | int drm_vma_info(struct seq_file *m, void *data) | |
232 | { | |
233 | struct drm_info_node *node = (struct drm_info_node *) m->private; | |
234 | struct drm_device *dev = node->minor->dev; | |
235 | struct drm_vma_entry *pt; | |
236 | struct vm_area_struct *vma; | |
99c09e74 | 237 | unsigned long vma_count = 0; |
955b12de BG |
238 | #if defined(__i386__) |
239 | unsigned int pgprot; | |
240 | #endif | |
241 | ||
242 | mutex_lock(&dev->struct_mutex); | |
99c09e74 DV |
243 | list_for_each_entry(pt, &dev->vmalist, head) |
244 | vma_count++; | |
245 | ||
246 | seq_printf(m, "vma use count: %lu, high_memory = %pK, 0x%pK\n", | |
247 | vma_count, high_memory, | |
248 | (void *)(unsigned long)virt_to_phys(high_memory)); | |
955b12de BG |
249 | |
250 | list_for_each_entry(pt, &dev->vmalist, head) { | |
251 | vma = pt->vma; | |
252 | if (!vma) | |
253 | continue; | |
254 | seq_printf(m, | |
01e2f533 KC |
255 | "\n%5d 0x%pK-0x%pK %c%c%c%c%c%c 0x%08lx000", |
256 | pt->pid, | |
257 | (void *)vma->vm_start, (void *)vma->vm_end, | |
955b12de BG |
258 | vma->vm_flags & VM_READ ? 'r' : '-', |
259 | vma->vm_flags & VM_WRITE ? 'w' : '-', | |
260 | vma->vm_flags & VM_EXEC ? 'x' : '-', | |
261 | vma->vm_flags & VM_MAYSHARE ? 's' : 'p', | |
262 | vma->vm_flags & VM_LOCKED ? 'l' : '-', | |
263 | vma->vm_flags & VM_IO ? 'i' : '-', | |
264 | vma->vm_pgoff); | |
265 | ||
266 | #if defined(__i386__) | |
267 | pgprot = pgprot_val(vma->vm_page_prot); | |
268 | seq_printf(m, " %c%c%c%c%c%c%c%c%c", | |
269 | pgprot & _PAGE_PRESENT ? 'p' : '-', | |
270 | pgprot & _PAGE_RW ? 'w' : 'r', | |
271 | pgprot & _PAGE_USER ? 'u' : 's', | |
272 | pgprot & _PAGE_PWT ? 't' : 'b', | |
273 | pgprot & _PAGE_PCD ? 'u' : 'c', | |
274 | pgprot & _PAGE_ACCESSED ? 'a' : '-', | |
275 | pgprot & _PAGE_DIRTY ? 'd' : '-', | |
276 | pgprot & _PAGE_PSE ? 'm' : 'k', | |
277 | pgprot & _PAGE_GLOBAL ? 'g' : 'l'); | |
278 | #endif | |
279 | seq_printf(m, "\n"); | |
280 | } | |
281 | mutex_unlock(&dev->struct_mutex); | |
282 | return 0; | |
283 | } | |
284 | ||
285 | #endif | |
286 |