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
31 #include <dev/drm2/drmP.h>
32 #include <dev/drm2/drm.h>
34 #include <sys/sysctl.h>
35 #include <sys/types.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 (sizeof(drm_sysctl_list)/sizeof(drm_sysctl_list[0]))
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);
71 /* Add the sysctl node for DRI if it doesn't already exist */
72 drioid = SYSCTL_ADD_NODE(&info->ctx, &sysctl__hw_children, OID_AUTO,
73 "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 dev->sysctl_node_idx = i;
87 /* Add the hw.dri.x for our device */
88 info->name[0] = '0' + i;
90 top = SYSCTL_ADD_NODE(&info->ctx, SYSCTL_CHILDREN(drioid),
91 OID_AUTO, info->name, CTLFLAG_RW, NULL, NULL);
95 for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
96 oid = SYSCTL_ADD_OID(&info->ctx,
99 drm_sysctl_list[i].name,
100 CTLTYPE_STRING | CTLFLAG_RD,
103 drm_sysctl_list[i].f,
109 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, "debug",
110 CTLFLAG_RW, &drm_debug_flag, sizeof(drm_debug_flag),
111 "Enable debugging output");
112 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, "notyet",
113 CTLFLAG_RW, &drm_notyet_flag, sizeof(drm_debug_flag),
114 "Enable notyet reminders");
116 if (dev->driver->sysctl_init != NULL)
117 dev->driver->sysctl_init(dev, &info->ctx, top);
119 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO,
120 "vblank_offdelay", CTLFLAG_RW, &drm_vblank_offdelay,
121 sizeof(drm_vblank_offdelay),
123 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO,
124 "timestamp_precision", CTLFLAG_RW, &drm_timestamp_precision,
125 sizeof(drm_timestamp_precision),
131 int drm_sysctl_cleanup(struct drm_device *dev)
135 error = sysctl_ctx_free(&dev->sysctl->ctx);
136 drm_free(dev->sysctl, DRM_MEM_DRIVER);
138 if (dev->driver->sysctl_cleanup != NULL)
139 dev->driver->sysctl_cleanup(dev);
144 #define DRM_SYSCTL_PRINT(fmt, arg...) \
146 ksnprintf(buf, sizeof(buf), fmt, ##arg); \
147 retcode = SYSCTL_OUT(req, buf, strlen(buf)); \
152 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
154 struct drm_device *dev = arg1;
159 DRM_SYSCTL_PRINT("%s 0x%x", dev->driver->name, dev2udev(dev->devnode));
163 ksnprintf(buf, sizeof(buf), " %s", dev->unique);
169 SYSCTL_OUT(req, buf, strlen(buf));
171 SYSCTL_OUT(req, "", 1);
177 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
179 struct drm_device *dev = arg1;
180 drm_local_map_t *map, *tempmaps;
181 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG" };
182 const char *type, *yesno;
187 /* We can't hold the lock while doing SYSCTL_OUTs, so allocate a
188 * temporary copy of all the map entries and then SYSCTL_OUT that.
193 TAILQ_FOREACH(map, &dev->maplist, link)
196 tempmaps = kmalloc(sizeof(drm_local_map_t) * mapcount, DRM_MEM_DRIVER,
198 if (tempmaps == NULL) {
204 TAILQ_FOREACH(map, &dev->maplist, link)
205 tempmaps[i++] = *map;
209 DRM_SYSCTL_PRINT("\nslot offset size "
210 "type flags address handle mtrr\n");
212 for (i = 0; i < mapcount; i++) {
215 if (map->type < 0 || map->type > 4)
218 type = types[map->type];
226 "%4d 0x%016lx 0x%08lx %4.4s 0x%02x 0x%016lx %6d %s\n",
227 i, map->offset, map->size, type, map->flags,
228 (unsigned long)map->virtual,
229 (unsigned int)((unsigned long)map->handle >>
230 DRM_MAP_HANDLE_SHIFT), yesno);
232 SYSCTL_OUT(req, "", 1);
235 drm_free(tempmaps, DRM_MEM_DRIVER);
239 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
241 struct drm_device *dev = arg1;
242 drm_device_dma_t *dma = dev->dma;
243 drm_device_dma_t tempdma;
249 /* We can't hold the locks around DRM_SYSCTL_PRINT, so make a temporary
250 * copy of the whole structure and the relevant data from buflist.
257 spin_lock(&dev->dma_lock);
259 templists = kmalloc(sizeof(int) * dma->buf_count, DRM_MEM_DRIVER,
261 for (i = 0; i < dma->buf_count; i++)
262 templists[i] = dma->buflist[i]->list;
264 spin_unlock(&dev->dma_lock);
267 DRM_SYSCTL_PRINT("\n o size count free segs pages kB\n");
268 for (i = 0; i <= DRM_MAX_ORDER; i++) {
269 if (dma->bufs[i].buf_count)
270 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
272 dma->bufs[i].buf_size,
273 dma->bufs[i].buf_count,
274 atomic_read(&dma->bufs[i]
276 dma->bufs[i].seg_count,
277 dma->bufs[i].seg_count
278 *(1 << dma->bufs[i].page_order),
279 (dma->bufs[i].seg_count
280 * (1 << dma->bufs[i].page_order))
281 * (int)PAGE_SIZE / 1024);
283 DRM_SYSCTL_PRINT("\n");
284 for (i = 0; i < dma->buf_count; i++) {
285 if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
286 DRM_SYSCTL_PRINT(" %d", templists[i]);
288 DRM_SYSCTL_PRINT("\n");
290 SYSCTL_OUT(req, "", 1);
292 drm_free(templists, DRM_MEM_DRIVER);
296 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
298 struct drm_device *dev = arg1;
299 struct drm_file *priv, *tempprivs;
307 TAILQ_FOREACH(priv, &dev->files, link)
310 tempprivs = kmalloc(sizeof(struct drm_file) * privcount, DRM_MEM_DRIVER,
312 if (tempprivs == NULL) {
317 TAILQ_FOREACH(priv, &dev->files, link)
318 tempprivs[i++] = *priv;
323 "\na dev pid uid magic ioctls\n");
324 for (i = 0; i < privcount; i++) {
325 priv = &tempprivs[i];
326 DRM_SYSCTL_PRINT("%c %-12s %5d %5d %10u %10lu\n",
327 priv->authenticated ? 'y' : 'n',
328 devtoname(priv->dev->devnode),
335 SYSCTL_OUT(req, "", 1);
337 drm_free(tempprivs, DRM_MEM_DRIVER);
341 static int drm_vblank_info DRM_SYSCTL_HANDLER_ARGS
343 struct drm_device *dev = arg1;
348 DRM_SYSCTL_PRINT("\ncrtc ref count last enabled inmodeset\n");
350 if (dev->_vblank_count == NULL)
352 for (i = 0 ; i < dev->num_crtcs ; i++) {
353 DRM_SYSCTL_PRINT(" %02d %02d %08d %08d %02d %02d\n",
354 i, dev->vblank_refcount[i],
355 dev->_vblank_count[i],
357 dev->vblank_enabled[i],
358 dev->vblank_inmodeset[i]);
363 SYSCTL_OUT(req, "", -1);