2 * Copyright 2003 Eric Anholt
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * ERIC ANHOLT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 #include <sys/cdefs.h>
25 __FBSDID("$FreeBSD$");
27 /** @file drm_sysctl.c
28 * Implementation of various sysctls for controlling DRM behavior and reporting
32 #include "dev/drm/drmP.h"
33 #include "dev/drm/drm.h"
35 #include <sys/sysctl.h>
37 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS;
38 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS;
39 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS;
40 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS;
41 static int drm_vblank_info DRM_SYSCTL_HANDLER_ARGS;
43 struct drm_sysctl_list {
45 int (*f) DRM_SYSCTL_HANDLER_ARGS;
46 } drm_sysctl_list[] = {
47 {"name", drm_name_info},
49 {"clients", drm_clients_info},
50 {"bufs", drm_bufs_info},
51 {"vblank", drm_vblank_info},
53 #define DRM_SYSCTL_ENTRIES (sizeof(drm_sysctl_list)/sizeof(drm_sysctl_list[0]))
55 struct drm_sysctl_info {
56 struct sysctl_ctx_list ctx;
60 int drm_sysctl_init(struct drm_device *dev)
62 struct drm_sysctl_info *info;
63 struct sysctl_oid *oid;
64 struct sysctl_oid *top, *drioid;
67 info = malloc(sizeof *info, DRM_MEM_DRIVER, M_WAITOK | M_ZERO);
72 /* Add the sysctl node for DRI if it doesn't already exist */
73 drioid = SYSCTL_ADD_NODE( &info->ctx, &sysctl__hw_children, OID_AUTO, "dri", CTLFLAG_RW, NULL, "DRI Graphics");
77 /* Find the next free slot under hw.dri */
79 SLIST_FOREACH(oid, SYSCTL_CHILDREN(drioid), oid_link) {
80 if (i <= oid->oid_arg2)
81 i = oid->oid_arg2 + 1;
86 /* Add the hw.dri.x for our device */
87 info->name[0] = '0' + i;
89 top = SYSCTL_ADD_NODE( &info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, info->name, CTLFLAG_RW, NULL, NULL);
93 for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
94 oid = SYSCTL_ADD_OID(&info->ctx,
97 drm_sysctl_list[i].name,
98 CTLTYPE_STRING | CTLFLAG_RD,
101 drm_sysctl_list[i].f,
107 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(top), OID_AUTO, "debug",
108 CTLFLAG_RW, &drm_debug_flag, sizeof(drm_debug_flag),
109 "Enable debugging output");
114 int drm_sysctl_cleanup(struct drm_device *dev)
117 error = sysctl_ctx_free( &dev->sysctl->ctx );
119 free(dev->sysctl, DRM_MEM_DRIVER);
125 #define DRM_SYSCTL_PRINT(fmt, arg...) \
127 snprintf(buf, sizeof(buf), fmt, ##arg); \
128 retcode = SYSCTL_OUT(req, buf, strlen(buf)); \
133 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
135 struct drm_device *dev = arg1;
140 DRM_SYSCTL_PRINT("%s 0x%x", dev->driver->name, dev2udev(dev->devnode));
144 snprintf(buf, sizeof(buf), " %s", dev->unique);
150 SYSCTL_OUT(req, buf, strlen(buf));
152 SYSCTL_OUT(req, "", 1);
158 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
160 struct drm_device *dev = arg1;
161 drm_local_map_t *map, *tempmaps;
162 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG" };
163 const char *type, *yesno;
168 /* We can't hold the lock while doing SYSCTL_OUTs, so allocate a
169 * temporary copy of all the map entries and then SYSCTL_OUT that.
174 TAILQ_FOREACH(map, &dev->maplist, link)
177 tempmaps = malloc(sizeof(drm_local_map_t) * mapcount, DRM_MEM_DRIVER,
179 if (tempmaps == NULL) {
185 TAILQ_FOREACH(map, &dev->maplist, link)
186 tempmaps[i++] = *map;
190 DRM_SYSCTL_PRINT("\nslot offset size "
191 "type flags address handle mtrr\n");
193 for (i = 0; i < mapcount; i++) {
196 if (map->type < 0 || map->type > 4)
199 type = types[map->type];
207 "%4d 0x%016lx 0x%08lx %4.4s 0x%02x 0x%016lx %6d %s\n",
208 i, map->offset, map->size, type, map->flags,
209 (unsigned long)map->virtual,
210 (unsigned int)((unsigned long)map->handle >>
211 DRM_MAP_HANDLE_SHIFT), yesno);
213 SYSCTL_OUT(req, "", 1);
216 free(tempmaps, DRM_MEM_DRIVER);
220 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
222 struct drm_device *dev = arg1;
223 drm_device_dma_t *dma = dev->dma;
224 drm_device_dma_t tempdma;
230 /* We can't hold the locks around DRM_SYSCTL_PRINT, so make a temporary
231 * copy of the whole structure and the relevant data from buflist.
238 DRM_SPINLOCK(&dev->dma_lock);
240 templists = malloc(sizeof(int) * dma->buf_count, DRM_MEM_DRIVER,
242 for (i = 0; i < dma->buf_count; i++)
243 templists[i] = dma->buflist[i]->list;
245 DRM_SPINUNLOCK(&dev->dma_lock);
248 DRM_SYSCTL_PRINT("\n o size count free segs pages kB\n");
249 for (i = 0; i <= DRM_MAX_ORDER; i++) {
250 if (dma->bufs[i].buf_count)
251 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
253 dma->bufs[i].buf_size,
254 dma->bufs[i].buf_count,
255 atomic_read(&dma->bufs[i]
257 dma->bufs[i].seg_count,
258 dma->bufs[i].seg_count
259 *(1 << dma->bufs[i].page_order),
260 (dma->bufs[i].seg_count
261 * (1 << dma->bufs[i].page_order))
262 * (int)PAGE_SIZE / 1024);
264 DRM_SYSCTL_PRINT("\n");
265 for (i = 0; i < dma->buf_count; i++) {
266 if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
267 DRM_SYSCTL_PRINT(" %d", templists[i]);
269 DRM_SYSCTL_PRINT("\n");
271 SYSCTL_OUT(req, "", 1);
273 free(templists, DRM_MEM_DRIVER);
277 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
279 struct drm_device *dev = arg1;
280 struct drm_file *priv, *tempprivs;
288 TAILQ_FOREACH(priv, &dev->files, link)
291 tempprivs = malloc(sizeof(struct drm_file) * privcount, DRM_MEM_DRIVER,
293 if (tempprivs == NULL) {
298 TAILQ_FOREACH(priv, &dev->files, link)
299 tempprivs[i++] = *priv;
304 "\na dev pid uid magic ioctls\n");
305 for (i = 0; i < privcount; i++) {
306 priv = &tempprivs[i];
307 DRM_SYSCTL_PRINT("%c %-12s %5d %5d %10u %10lu\n",
308 priv->authenticated ? 'y' : 'n',
309 devtoname(priv->dev->devnode),
316 SYSCTL_OUT(req, "", 1);
318 free(tempprivs, DRM_MEM_DRIVER);
322 static int drm_vblank_info DRM_SYSCTL_HANDLER_ARGS
324 struct drm_device *dev = arg1;
329 DRM_SYSCTL_PRINT("\ncrtc ref count last enabled inmodeset\n");
330 for(i = 0 ; i < dev->num_crtcs ; i++) {
331 DRM_SYSCTL_PRINT(" %02d %02d %08d %08d %02d %02d\n",
332 i, atomic_load_acq_32(&dev->vblank[i].refcount),
333 atomic_load_acq_32(&dev->vblank[i].count),
334 atomic_load_acq_32(&dev->vblank[i].last),
335 atomic_load_acq_int(&dev->vblank[i].enabled),
336 atomic_load_acq_int(&dev->vblank[i].inmodeset));
339 SYSCTL_OUT(req, "", -1);