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");
76 /* Find the next free slot under hw.dri */
78 SLIST_FOREACH(oid, SYSCTL_CHILDREN(drioid), oid_link) {
79 if (i <= oid->oid_arg2)
80 i = oid->oid_arg2 + 1;
85 dev->sysctl_node_idx = i;
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),
90 OID_AUTO, info->name, CTLFLAG_RW, NULL, NULL);
94 for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
95 oid = SYSCTL_ADD_OID(&info->ctx,
98 drm_sysctl_list[i].name,
99 CTLTYPE_STRING | CTLFLAG_RD,
102 drm_sysctl_list[i].f,
108 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, "debug",
109 CTLFLAG_RW, &drm_debug_flag, sizeof(drm_debug_flag),
110 "Enable debugging output");
111 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, "notyet",
112 CTLFLAG_RW, &drm_notyet_flag, sizeof(drm_debug_flag),
113 "Enable notyet reminders");
115 if (dev->driver->sysctl_init != NULL)
116 dev->driver->sysctl_init(dev, &info->ctx, top);
118 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO,
119 "vblank_offdelay", CTLFLAG_RW, &drm_vblank_offdelay,
120 sizeof(drm_vblank_offdelay),
122 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO,
123 "timestamp_precision", CTLFLAG_RW, &drm_timestamp_precision,
124 sizeof(drm_timestamp_precision),
130 int drm_sysctl_cleanup(struct drm_device *dev)
134 error = sysctl_ctx_free(&dev->sysctl->ctx);
135 free(dev->sysctl, DRM_MEM_DRIVER);
137 if (dev->driver->sysctl_cleanup != NULL)
138 dev->driver->sysctl_cleanup(dev);
143 #define DRM_SYSCTL_PRINT(fmt, arg...) \
145 snprintf(buf, sizeof(buf), fmt, ##arg); \
146 retcode = SYSCTL_OUT(req, buf, strlen(buf)); \
151 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
153 struct drm_device *dev = arg1;
158 DRM_SYSCTL_PRINT("%s 0x%x", dev->driver->name, dev2udev(dev->devnode));
162 snprintf(buf, sizeof(buf), " %s", dev->unique);
168 SYSCTL_OUT(req, buf, strlen(buf));
170 SYSCTL_OUT(req, "", 1);
176 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
178 struct drm_device *dev = arg1;
179 drm_local_map_t *map, *tempmaps;
180 const char *types[] = {
181 [_DRM_FRAME_BUFFER] = "FB",
182 [_DRM_REGISTERS] = "REG",
185 [_DRM_SCATTER_GATHER] = "SG",
186 [_DRM_CONSISTENT] = "CONS",
189 const char *type, *yesno;
194 /* We can't hold the lock while doing SYSCTL_OUTs, so allocate a
195 * temporary copy of all the map entries and then SYSCTL_OUT that.
200 TAILQ_FOREACH(map, &dev->maplist, link)
203 tempmaps = malloc(sizeof(drm_local_map_t) * mapcount, DRM_MEM_DRIVER,
205 if (tempmaps == NULL) {
211 TAILQ_FOREACH(map, &dev->maplist, link)
212 tempmaps[i++] = *map;
216 DRM_SYSCTL_PRINT("\nslot offset size "
217 "type flags address handle mtrr\n");
219 for (i = 0; i < mapcount; i++) {
226 case _DRM_FRAME_BUFFER:
230 case _DRM_SCATTER_GATHER:
231 case _DRM_CONSISTENT:
233 type = types[map->type];
243 "%4d 0x%016lx 0x%08lx %4.4s 0x%02x 0x%016lx %6d %s\n",
244 i, map->offset, map->size, type, map->flags,
245 (unsigned long)map->virtual,
246 (unsigned int)((unsigned long)map->handle >>
247 DRM_MAP_HANDLE_SHIFT), yesno);
249 SYSCTL_OUT(req, "", 1);
252 free(tempmaps, DRM_MEM_DRIVER);
256 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
258 struct drm_device *dev = arg1;
259 drm_device_dma_t *dma = dev->dma;
260 drm_device_dma_t tempdma;
266 /* We can't hold the locks around DRM_SYSCTL_PRINT, so make a temporary
267 * copy of the whole structure and the relevant data from buflist.
274 DRM_SPINLOCK(&dev->dma_lock);
276 templists = malloc(sizeof(int) * dma->buf_count, DRM_MEM_DRIVER,
278 for (i = 0; i < dma->buf_count; i++)
279 templists[i] = dma->buflist[i]->list;
281 DRM_SPINUNLOCK(&dev->dma_lock);
284 DRM_SYSCTL_PRINT("\n o size count free segs pages kB\n");
285 for (i = 0; i <= DRM_MAX_ORDER; i++) {
286 if (dma->bufs[i].buf_count)
287 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
289 dma->bufs[i].buf_size,
290 dma->bufs[i].buf_count,
291 atomic_read(&dma->bufs[i]
293 dma->bufs[i].seg_count,
294 dma->bufs[i].seg_count
295 *(1 << dma->bufs[i].page_order),
296 (dma->bufs[i].seg_count
297 * (1 << dma->bufs[i].page_order))
298 * (int)PAGE_SIZE / 1024);
300 DRM_SYSCTL_PRINT("\n");
301 for (i = 0; i < dma->buf_count; i++) {
302 if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
303 DRM_SYSCTL_PRINT(" %d", templists[i]);
305 DRM_SYSCTL_PRINT("\n");
307 SYSCTL_OUT(req, "", 1);
309 free(templists, DRM_MEM_DRIVER);
313 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
315 struct drm_device *dev = arg1;
316 struct drm_file *priv, *tempprivs;
324 TAILQ_FOREACH(priv, &dev->files, link)
327 tempprivs = malloc(sizeof(struct drm_file) * privcount, DRM_MEM_DRIVER,
329 if (tempprivs == NULL) {
334 TAILQ_FOREACH(priv, &dev->files, link)
335 tempprivs[i++] = *priv;
340 "\na dev pid uid magic ioctls\n");
341 for (i = 0; i < privcount; i++) {
342 priv = &tempprivs[i];
343 DRM_SYSCTL_PRINT("%c %-12s %5d %5d %10u %10lu\n",
344 priv->authenticated ? 'y' : 'n',
345 devtoname(priv->dev->devnode),
352 SYSCTL_OUT(req, "", 1);
354 free(tempprivs, DRM_MEM_DRIVER);
358 static int drm_vblank_info DRM_SYSCTL_HANDLER_ARGS
360 struct drm_device *dev = arg1;
365 DRM_SYSCTL_PRINT("\ncrtc ref count last enabled inmodeset\n");
367 if (dev->_vblank_count == NULL)
369 for (i = 0 ; i < dev->num_crtcs ; i++) {
370 DRM_SYSCTL_PRINT(" %02d %02d %08d %08d %02d %02d\n",
371 i, dev->vblank_refcount[i],
372 dev->_vblank_count[i],
374 dev->vblank_enabled[i],
375 dev->vblank_inmodeset[i]);
380 SYSCTL_OUT(req, "", -1);