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.
23 * $FreeBSD: src/sys/dev/drm2/drm_sysctl.c,v 1.1 2012/05/22 11:07:44 kib Exp $
26 /** @file drm_sysctl.c
27 * Implementation of various sysctls for controlling DRM behavior and reporting
32 #include <sys/sysctl.h>
33 #include <sys/types.h>
35 #include "dev/drm/drmP.h"
36 #include "dev/drm/drm.h"
38 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS;
39 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS;
40 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS;
41 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS;
42 static int drm_vblank_info DRM_SYSCTL_HANDLER_ARGS;
44 struct drm_sysctl_list {
46 int (*f) DRM_SYSCTL_HANDLER_ARGS;
47 } drm_sysctl_list[] = {
48 {"name", drm_name_info},
50 {"clients", drm_clients_info},
51 {"bufs", drm_bufs_info},
52 {"vblank", drm_vblank_info},
54 #define DRM_SYSCTL_ENTRIES NELEM(drm_sysctl_list)
56 struct drm_sysctl_info {
57 struct sysctl_ctx_list ctx;
61 int drm_sysctl_init(struct drm_device *dev)
63 struct drm_sysctl_info *info;
64 struct sysctl_oid *oid;
65 struct sysctl_oid *top, *drioid;
68 info = kmalloc(sizeof *info, DRM_MEM_DRIVER, M_WAITOK | M_ZERO);
73 /* Add the sysctl node for DRI if it doesn't already exist */
74 drioid = SYSCTL_ADD_NODE(&info->ctx, &sysctl__hw_children, OID_AUTO,
75 "dri", CTLFLAG_RW, NULL, "DRI Graphics");
79 /* Find the next free slot under hw.dri */
81 SLIST_FOREACH(oid, SYSCTL_CHILDREN(drioid), oid_link) {
82 if (i <= oid->oid_arg2)
83 i = oid->oid_arg2 + 1;
88 dev->sysctl_node_idx = i;
89 /* Add the hw.dri.x for our device */
90 info->name[0] = '0' + i;
92 top = SYSCTL_ADD_NODE(&info->ctx, SYSCTL_CHILDREN(drioid),
93 OID_AUTO, info->name, CTLFLAG_RW, NULL, NULL);
97 for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
98 oid = SYSCTL_ADD_OID(&info->ctx,
101 drm_sysctl_list[i].name,
102 CTLTYPE_STRING | CTLFLAG_RD,
105 drm_sysctl_list[i].f,
111 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, "debug",
112 CTLFLAG_RW, &drm_debug_flag, sizeof(drm_debug_flag),
113 "Enable debugging output");
114 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, "notyet",
115 CTLFLAG_RW, &drm_notyet_flag, sizeof(drm_debug_flag),
116 "Enable notyet reminders");
118 if (dev->driver->sysctl_init != NULL)
119 dev->driver->sysctl_init(dev, &info->ctx, top);
121 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO,
122 "vblank_offdelay", CTLFLAG_RW, &drm_vblank_offdelay,
123 sizeof(drm_vblank_offdelay),
125 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO,
126 "timestamp_precision", CTLFLAG_RW, &drm_timestamp_precision,
127 sizeof(drm_timestamp_precision),
133 int drm_sysctl_cleanup(struct drm_device *dev)
137 error = sysctl_ctx_free(&dev->sysctl->ctx);
138 drm_free(dev->sysctl, DRM_MEM_DRIVER);
140 if (dev->driver->sysctl_cleanup != NULL)
141 dev->driver->sysctl_cleanup(dev);
146 #define DRM_SYSCTL_PRINT(fmt, arg...) \
148 ksnprintf(buf, sizeof(buf), fmt, ##arg); \
149 retcode = SYSCTL_OUT(req, buf, strlen(buf)); \
154 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
156 struct drm_device *dev = arg1;
161 DRM_SYSCTL_PRINT("%s 0x%x", dev->driver->name, dev2udev(dev->devnode));
165 ksnprintf(buf, sizeof(buf), " %s", dev->unique);
171 SYSCTL_OUT(req, buf, strlen(buf));
173 SYSCTL_OUT(req, "", 1);
179 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
181 struct drm_device *dev = arg1;
182 drm_local_map_t *map, *tempmaps;
183 const char *types[] = {
184 [_DRM_FRAME_BUFFER] = "FB",
185 [_DRM_REGISTERS] = "REG",
188 [_DRM_SCATTER_GATHER] = "SG",
189 [_DRM_CONSISTENT] = "CONS",
192 const char *type, *yesno;
197 /* We can't hold the lock while doing SYSCTL_OUTs, so allocate a
198 * temporary copy of all the map entries and then SYSCTL_OUT that.
203 TAILQ_FOREACH(map, &dev->maplist, link)
206 tempmaps = kmalloc(sizeof(drm_local_map_t) * mapcount, DRM_MEM_DRIVER,
208 if (tempmaps == NULL) {
214 TAILQ_FOREACH(map, &dev->maplist, link)
215 tempmaps[i++] = *map;
219 DRM_SYSCTL_PRINT("\nslot offset size "
220 "type flags address handle mtrr\n");
222 for (i = 0; i < mapcount; i++) {
229 case _DRM_FRAME_BUFFER:
233 case _DRM_SCATTER_GATHER:
234 case _DRM_CONSISTENT:
236 type = types[map->type];
246 "%4d 0x%016lx 0x%08lx %4.4s 0x%02x 0x%016lx %6d %s\n",
247 i, map->offset, map->size, type, map->flags,
248 (unsigned long)map->virtual,
249 (unsigned int)((unsigned long)map->handle >>
250 DRM_MAP_HANDLE_SHIFT), yesno);
252 SYSCTL_OUT(req, "", 1);
255 drm_free(tempmaps, DRM_MEM_DRIVER);
259 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
261 struct drm_device *dev = arg1;
262 drm_device_dma_t *dma = dev->dma;
263 drm_device_dma_t tempdma;
269 /* We can't hold the locks around DRM_SYSCTL_PRINT, so make a temporary
270 * copy of the whole structure and the relevant data from buflist.
277 spin_lock(&dev->dma_lock);
279 templists = kmalloc(sizeof(int) * dma->buf_count, DRM_MEM_DRIVER,
281 for (i = 0; i < dma->buf_count; i++)
282 templists[i] = dma->buflist[i]->list;
284 spin_unlock(&dev->dma_lock);
287 DRM_SYSCTL_PRINT("\n o size count free segs pages kB\n");
288 for (i = 0; i <= DRM_MAX_ORDER; i++) {
289 if (dma->bufs[i].buf_count)
290 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
292 dma->bufs[i].buf_size,
293 dma->bufs[i].buf_count,
294 atomic_read(&dma->bufs[i]
296 dma->bufs[i].seg_count,
297 dma->bufs[i].seg_count
298 *(1 << dma->bufs[i].page_order),
299 (dma->bufs[i].seg_count
300 * (1 << dma->bufs[i].page_order))
301 * (int)PAGE_SIZE / 1024);
303 DRM_SYSCTL_PRINT("\n");
304 for (i = 0; i < dma->buf_count; i++) {
305 if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
306 DRM_SYSCTL_PRINT(" %d", templists[i]);
308 DRM_SYSCTL_PRINT("\n");
310 SYSCTL_OUT(req, "", 1);
312 drm_free(templists, DRM_MEM_DRIVER);
316 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
318 struct drm_device *dev = arg1;
319 struct drm_file *priv, *tempprivs;
327 TAILQ_FOREACH(priv, &dev->files, link)
330 tempprivs = kmalloc(sizeof(struct drm_file) * privcount, DRM_MEM_DRIVER,
332 if (tempprivs == NULL) {
337 TAILQ_FOREACH(priv, &dev->files, link)
338 tempprivs[i++] = *priv;
343 "\na dev pid uid magic ioctls\n");
344 for (i = 0; i < privcount; i++) {
345 priv = &tempprivs[i];
346 DRM_SYSCTL_PRINT("%c %-12s %5d %5d %10u %10lu\n",
347 priv->authenticated ? 'y' : 'n',
348 devtoname(priv->dev->devnode),
355 SYSCTL_OUT(req, "", 1);
357 drm_free(tempprivs, DRM_MEM_DRIVER);
361 static int drm_vblank_info DRM_SYSCTL_HANDLER_ARGS
363 struct drm_device *dev = arg1;
368 DRM_SYSCTL_PRINT("\ncrtc ref count last enabled inmodeset\n");
370 if (dev->_vblank_count == NULL)
372 for (i = 0 ; i < dev->num_crtcs ; i++) {
373 DRM_SYSCTL_PRINT(" %02d %02d %08d %08d %02d %02d\n",
374 i, dev->vblank_refcount[i],
375 dev->_vblank_count[i],
377 dev->vblank_enabled[i],
378 dev->vblank_inmodeset[i]);
383 SYSCTL_OUT(req, "", -1);