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/drm2/drmP.h>
33 #include <dev/drm2/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);
70 /* Add the sysctl node for DRI if it doesn't already exist */
71 drioid = SYSCTL_ADD_NODE(&info->ctx, SYSCTL_CHILDREN(&sysctl___hw), OID_AUTO,
72 "dri", CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, "DRI Graphics");
74 free(dev->sysctl, DRM_MEM_DRIVER);
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;
86 drm_sysctl_cleanup(dev);
90 dev->sysctl_node_idx = i;
91 /* Add the hw.dri.x for our device */
92 info->name[0] = '0' + i;
94 top = SYSCTL_ADD_NODE(&info->ctx, SYSCTL_CHILDREN(drioid),
95 OID_AUTO, info->name, CTLFLAG_RW | CTLFLAG_MPSAFE, NULL, NULL);
97 drm_sysctl_cleanup(dev);
101 for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
102 oid = SYSCTL_ADD_OID(&info->ctx, SYSCTL_CHILDREN(top),
103 OID_AUTO, drm_sysctl_list[i].name,
104 CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_NEEDGIANT,
105 dev, 0, drm_sysctl_list[i].f, "A", NULL);
107 drm_sysctl_cleanup(dev);
111 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, "debug",
112 CTLFLAG_RW, &drm_debug, sizeof(drm_debug),
113 "Enable debugging output");
114 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, "notyet",
115 CTLFLAG_RW, &drm_notyet, sizeof(drm_debug),
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 if (dev->sysctl == NULL)
140 error = sysctl_ctx_free(&dev->sysctl->ctx);
141 free(dev->sysctl, DRM_MEM_DRIVER);
143 if (dev->driver->sysctl_cleanup != NULL)
144 dev->driver->sysctl_cleanup(dev);
149 #define DRM_SYSCTL_PRINT(fmt, arg...) \
151 snprintf(buf, sizeof(buf), fmt, ##arg); \
152 retcode = SYSCTL_OUT(req, buf, strlen(buf)); \
157 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
159 struct drm_device *dev = arg1;
160 struct drm_minor *minor;
161 struct drm_master *master;
166 /* FIXME: This still uses primary minor. */
167 minor = dev->primary;
168 DRM_SYSCTL_PRINT("%s 0x%jx", dev->driver->name,
169 (uintmax_t)dev2udev(minor->device));
172 master = minor->master;
173 if (master != NULL && master->unique) {
174 snprintf(buf, sizeof(buf), " %s", master->unique);
180 SYSCTL_OUT(req, buf, strlen(buf));
182 SYSCTL_OUT(req, "", 1);
188 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
190 struct drm_device *dev = arg1;
191 struct drm_map_list *entry;
192 struct drm_local_map *map, *tempmaps;
193 const char *types[] = {
194 [_DRM_FRAME_BUFFER] = "FB",
195 [_DRM_REGISTERS] = "REG",
198 [_DRM_SCATTER_GATHER] = "SG",
199 [_DRM_CONSISTENT] = "CONS",
202 const char *type, *yesno;
207 /* We can't hold the lock while doing SYSCTL_OUTs, so allocate a
208 * temporary copy of all the map entries and then SYSCTL_OUT that.
213 list_for_each_entry(entry, &dev->maplist, head) {
214 if (entry->map != NULL)
218 tempmaps = malloc(sizeof(*tempmaps) * mapcount, DRM_MEM_DRIVER,
220 if (tempmaps == NULL) {
226 list_for_each_entry(entry, &dev->maplist, head) {
227 if (entry->map != NULL)
228 tempmaps[i++] = *entry->map;
233 DRM_SYSCTL_PRINT("\nslot offset size "
234 "type flags address mtrr\n");
236 for (i = 0; i < mapcount; i++) {
243 case _DRM_FRAME_BUFFER:
247 case _DRM_SCATTER_GATHER:
248 case _DRM_CONSISTENT:
250 type = types[map->type];
260 "%4d 0x%016llx 0x%08lx %4.4s 0x%02x 0x%016lx %s\n",
261 i, (unsigned long long)map->offset, map->size, type,
262 map->flags, (unsigned long)map->handle, yesno);
264 SYSCTL_OUT(req, "", 1);
267 free(tempmaps, DRM_MEM_DRIVER);
271 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
273 struct drm_device *dev = arg1;
274 struct drm_device_dma *dma = dev->dma;
275 struct drm_device_dma tempdma;
281 /* We can't hold the locks around DRM_SYSCTL_PRINT, so make a temporary
282 * copy of the whole structure and the relevant data from buflist.
289 DRM_SPINLOCK(&dev->dma_lock);
291 templists = malloc(sizeof(int) * dma->buf_count, DRM_MEM_DRIVER,
293 for (i = 0; i < dma->buf_count; i++)
294 templists[i] = dma->buflist[i]->list;
296 DRM_SPINUNLOCK(&dev->dma_lock);
299 DRM_SYSCTL_PRINT("\n o size count free segs pages kB\n");
300 for (i = 0; i <= DRM_MAX_ORDER; i++) {
301 if (dma->bufs[i].buf_count)
302 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
304 dma->bufs[i].buf_size,
305 dma->bufs[i].buf_count,
306 atomic_read(&dma->bufs[i]
308 dma->bufs[i].seg_count,
309 dma->bufs[i].seg_count
310 *(1 << dma->bufs[i].page_order),
311 (dma->bufs[i].seg_count
312 * (1 << dma->bufs[i].page_order))
313 * (int)PAGE_SIZE / 1024);
315 DRM_SYSCTL_PRINT("\n");
316 for (i = 0; i < dma->buf_count; i++) {
317 if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
318 DRM_SYSCTL_PRINT(" %d", templists[i]);
320 DRM_SYSCTL_PRINT("\n");
322 SYSCTL_OUT(req, "", 1);
324 free(templists, DRM_MEM_DRIVER);
328 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
330 struct drm_device *dev = arg1;
331 struct drm_file *priv, *tempprivs;
339 list_for_each_entry(priv, &dev->filelist, lhead)
342 tempprivs = malloc(sizeof(struct drm_file) * privcount, DRM_MEM_DRIVER,
344 if (tempprivs == NULL) {
349 list_for_each_entry(priv, &dev->filelist, lhead)
350 tempprivs[i++] = *priv;
355 "\na dev pid uid magic ioctls\n");
356 for (i = 0; i < privcount; i++) {
357 priv = &tempprivs[i];
358 DRM_SYSCTL_PRINT("%c %-12s %5d %5d %10u %10lu\n",
359 priv->authenticated ? 'y' : 'n',
360 devtoname(priv->minor->device),
367 SYSCTL_OUT(req, "", 1);
369 free(tempprivs, DRM_MEM_DRIVER);
373 static int drm_vblank_info DRM_SYSCTL_HANDLER_ARGS
375 struct drm_device *dev = arg1;
380 DRM_SYSCTL_PRINT("\ncrtc ref count last enabled inmodeset\n");
382 if (dev->_vblank_count == NULL)
384 for (i = 0 ; i < dev->num_crtcs ; i++) {
385 DRM_SYSCTL_PRINT(" %02d %02d %08d %08d %02d %02d\n",
386 i, dev->vblank_refcount[i],
387 dev->_vblank_count[i],
389 dev->vblank_enabled[i],
390 dev->vblank_inmodeset[i]);
395 SYSCTL_OUT(req, "", -1);