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, 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, NULL, NULL);
97 drm_sysctl_cleanup(dev);
101 for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
102 oid = SYSCTL_ADD_OID(&info->ctx,
103 SYSCTL_CHILDREN(top),
105 drm_sysctl_list[i].name,
106 CTLTYPE_STRING | CTLFLAG_RD,
109 drm_sysctl_list[i].f,
113 drm_sysctl_cleanup(dev);
117 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, "debug",
118 CTLFLAG_RW, &drm_debug, sizeof(drm_debug),
119 "Enable debugging output");
120 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, "notyet",
121 CTLFLAG_RW, &drm_notyet, sizeof(drm_debug),
122 "Enable notyet reminders");
124 if (dev->driver->sysctl_init != NULL)
125 dev->driver->sysctl_init(dev, &info->ctx, top);
127 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO,
128 "vblank_offdelay", CTLFLAG_RW, &drm_vblank_offdelay,
129 sizeof(drm_vblank_offdelay),
131 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO,
132 "timestamp_precision", CTLFLAG_RW, &drm_timestamp_precision,
133 sizeof(drm_timestamp_precision),
139 int drm_sysctl_cleanup(struct drm_device *dev)
143 if (dev->sysctl == NULL)
146 error = sysctl_ctx_free(&dev->sysctl->ctx);
147 free(dev->sysctl, DRM_MEM_DRIVER);
149 if (dev->driver->sysctl_cleanup != NULL)
150 dev->driver->sysctl_cleanup(dev);
155 #define DRM_SYSCTL_PRINT(fmt, arg...) \
157 snprintf(buf, sizeof(buf), fmt, ##arg); \
158 retcode = SYSCTL_OUT(req, buf, strlen(buf)); \
163 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
165 struct drm_device *dev = arg1;
166 struct drm_minor *minor;
167 struct drm_master *master;
172 /* FIXME: This still uses primary minor. */
173 minor = dev->primary;
174 DRM_SYSCTL_PRINT("%s 0x%jx", dev->driver->name,
175 (uintmax_t)dev2udev(minor->device));
178 master = minor->master;
179 if (master != NULL && master->unique) {
180 snprintf(buf, sizeof(buf), " %s", master->unique);
186 SYSCTL_OUT(req, buf, strlen(buf));
188 SYSCTL_OUT(req, "", 1);
194 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
196 struct drm_device *dev = arg1;
197 struct drm_map_list *entry;
198 struct drm_local_map *map, *tempmaps;
199 const char *types[] = {
200 [_DRM_FRAME_BUFFER] = "FB",
201 [_DRM_REGISTERS] = "REG",
204 [_DRM_SCATTER_GATHER] = "SG",
205 [_DRM_CONSISTENT] = "CONS",
208 const char *type, *yesno;
213 /* We can't hold the lock while doing SYSCTL_OUTs, so allocate a
214 * temporary copy of all the map entries and then SYSCTL_OUT that.
219 list_for_each_entry(entry, &dev->maplist, head) {
220 if (entry->map != NULL)
224 tempmaps = malloc(sizeof(*tempmaps) * mapcount, DRM_MEM_DRIVER,
226 if (tempmaps == NULL) {
232 list_for_each_entry(entry, &dev->maplist, head) {
233 if (entry->map != NULL)
234 tempmaps[i++] = *entry->map;
239 DRM_SYSCTL_PRINT("\nslot offset size "
240 "type flags address mtrr\n");
242 for (i = 0; i < mapcount; i++) {
249 case _DRM_FRAME_BUFFER:
253 case _DRM_SCATTER_GATHER:
254 case _DRM_CONSISTENT:
256 type = types[map->type];
266 "%4d 0x%016llx 0x%08lx %4.4s 0x%02x 0x%016lx %s\n",
267 i, (unsigned long long)map->offset, map->size, type,
268 map->flags, (unsigned long)map->handle, yesno);
270 SYSCTL_OUT(req, "", 1);
273 free(tempmaps, DRM_MEM_DRIVER);
277 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
279 struct drm_device *dev = arg1;
280 struct drm_device_dma *dma = dev->dma;
281 struct drm_device_dma tempdma;
287 /* We can't hold the locks around DRM_SYSCTL_PRINT, so make a temporary
288 * copy of the whole structure and the relevant data from buflist.
295 DRM_SPINLOCK(&dev->dma_lock);
297 templists = malloc(sizeof(int) * dma->buf_count, DRM_MEM_DRIVER,
299 for (i = 0; i < dma->buf_count; i++)
300 templists[i] = dma->buflist[i]->list;
302 DRM_SPINUNLOCK(&dev->dma_lock);
305 DRM_SYSCTL_PRINT("\n o size count free segs pages kB\n");
306 for (i = 0; i <= DRM_MAX_ORDER; i++) {
307 if (dma->bufs[i].buf_count)
308 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
310 dma->bufs[i].buf_size,
311 dma->bufs[i].buf_count,
312 atomic_read(&dma->bufs[i]
314 dma->bufs[i].seg_count,
315 dma->bufs[i].seg_count
316 *(1 << dma->bufs[i].page_order),
317 (dma->bufs[i].seg_count
318 * (1 << dma->bufs[i].page_order))
319 * (int)PAGE_SIZE / 1024);
321 DRM_SYSCTL_PRINT("\n");
322 for (i = 0; i < dma->buf_count; i++) {
323 if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
324 DRM_SYSCTL_PRINT(" %d", templists[i]);
326 DRM_SYSCTL_PRINT("\n");
328 SYSCTL_OUT(req, "", 1);
330 free(templists, DRM_MEM_DRIVER);
334 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
336 struct drm_device *dev = arg1;
337 struct drm_file *priv, *tempprivs;
345 list_for_each_entry(priv, &dev->filelist, lhead)
348 tempprivs = malloc(sizeof(struct drm_file) * privcount, DRM_MEM_DRIVER,
350 if (tempprivs == NULL) {
355 list_for_each_entry(priv, &dev->filelist, lhead)
356 tempprivs[i++] = *priv;
361 "\na dev pid uid magic ioctls\n");
362 for (i = 0; i < privcount; i++) {
363 priv = &tempprivs[i];
364 DRM_SYSCTL_PRINT("%c %-12s %5d %5d %10u %10lu\n",
365 priv->authenticated ? 'y' : 'n',
366 devtoname(priv->minor->device),
373 SYSCTL_OUT(req, "", 1);
375 free(tempprivs, DRM_MEM_DRIVER);
379 static int drm_vblank_info DRM_SYSCTL_HANDLER_ARGS
381 struct drm_device *dev = arg1;
386 DRM_SYSCTL_PRINT("\ncrtc ref count last enabled inmodeset\n");
388 if (dev->_vblank_count == NULL)
390 for (i = 0 ; i < dev->num_crtcs ; i++) {
391 DRM_SYSCTL_PRINT(" %02d %02d %08d %08d %02d %02d\n",
392 i, dev->vblank_refcount[i],
393 dev->_vblank_count[i],
395 dev->vblank_enabled[i],
396 dev->vblank_inmodeset[i]);
401 SYSCTL_OUT(req, "", -1);