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>
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 NELEM(drm_sysctl_list)
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 = kmalloc(sizeof *info, DRM_MEM_DRIVER, M_WAITOK | M_ZERO);
72 /* Add the sysctl node for DRI if it doesn't already exist */
73 drioid = SYSCTL_ADD_NODE(&info->ctx, &sysctl__hw_children, OID_AUTO,
74 "dri", CTLFLAG_RW, NULL, "DRI Graphics");
78 /* Find the next free slot under hw.dri */
80 SLIST_FOREACH(oid, SYSCTL_CHILDREN(drioid), oid_link) {
81 if (i <= oid->oid_arg2)
82 i = oid->oid_arg2 + 1;
87 dev->sysctl_node_idx = i;
88 /* Add the hw.dri.x for our device */
89 info->name[0] = '0' + i;
91 top = SYSCTL_ADD_NODE(&info->ctx, SYSCTL_CHILDREN(drioid),
92 OID_AUTO, info->name, CTLFLAG_RW, NULL, NULL);
96 for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
97 oid = SYSCTL_ADD_OID(&info->ctx,
100 drm_sysctl_list[i].name,
101 CTLTYPE_STRING | CTLFLAG_RD,
104 drm_sysctl_list[i].f,
110 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, "debug",
111 CTLFLAG_RW, &drm_debug, sizeof(drm_debug),
112 "Enable debugging output");
113 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, "notyet",
114 CTLFLAG_RW, &drm_notyet_flag, sizeof(drm_debug),
115 "Enable notyet reminders");
117 if (dev->driver->sysctl_init != NULL)
118 dev->driver->sysctl_init(dev, &info->ctx, top);
120 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO,
121 "vblank_offdelay", CTLFLAG_RW, &drm_vblank_offdelay,
122 sizeof(drm_vblank_offdelay),
124 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO,
125 "timestamp_precision", CTLFLAG_RW, &drm_timestamp_precision,
126 sizeof(drm_timestamp_precision),
132 int drm_sysctl_cleanup(struct drm_device *dev)
136 error = sysctl_ctx_free(&dev->sysctl->ctx);
137 drm_free(dev->sysctl, DRM_MEM_DRIVER);
139 if (dev->driver->sysctl_cleanup != NULL)
140 dev->driver->sysctl_cleanup(dev);
145 #define DRM_SYSCTL_PRINT(fmt, arg...) \
147 ksnprintf(buf, sizeof(buf), fmt, ##arg); \
148 retcode = SYSCTL_OUT(req, buf, strlen(buf)); \
153 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
155 struct drm_device *dev = arg1;
160 DRM_SYSCTL_PRINT("%s 0x%x", dev->driver->name, dev2udev(dev->devnode));
164 ksnprintf(buf, sizeof(buf), " %s", dev->unique);
170 SYSCTL_OUT(req, buf, strlen(buf));
172 SYSCTL_OUT(req, "", 1);
179 * Called when "/proc/dri/.../vm" is read.
181 * Prints information about all mappings in drm_device::maplist.
183 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
187 struct drm_device *dev = arg1;
188 struct drm_local_map *map;
189 struct drm_map_list *r_list;
191 /* Hardcoded from _DRM_FRAME_BUFFER,
192 _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
193 _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
194 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
199 DRM_SYSCTL_PRINT("\nslot offset size "
200 "type flags address handle mtrr\n");
202 list_for_each_entry(r_list, &dev->maplist, head) {
206 if (map->type < 0 || map->type > 5)
209 type = types[map->type];
211 DRM_SYSCTL_PRINT("%4d 0x%016llx 0x%08lx %4.4s 0x%02x 0x%08lx ",
213 (unsigned long long)map->offset,
214 map->size, type, map->flags,
215 (unsigned long) r_list->user_token);
217 DRM_SYSCTL_PRINT("none\n");
219 DRM_SYSCTL_PRINT("%4d\n", map->mtrr);
223 SYSCTL_OUT(req, "", 1);
230 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
232 struct drm_device *dev = arg1;
233 drm_device_dma_t *dma = dev->dma;
234 drm_device_dma_t tempdma;
240 /* We can't hold the locks around DRM_SYSCTL_PRINT, so make a temporary
241 * copy of the whole structure and the relevant data from buflist.
248 spin_lock(&dev->dma_lock);
250 templists = kmalloc(sizeof(int) * dma->buf_count, DRM_MEM_DRIVER,
252 for (i = 0; i < dma->buf_count; i++)
253 templists[i] = dma->buflist[i]->list;
255 spin_unlock(&dev->dma_lock);
258 DRM_SYSCTL_PRINT("\n o size count free segs pages kB\n");
259 for (i = 0; i <= DRM_MAX_ORDER; i++) {
260 if (dma->bufs[i].buf_count)
261 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
263 dma->bufs[i].buf_size,
264 dma->bufs[i].buf_count,
265 atomic_read(&dma->bufs[i]
267 dma->bufs[i].seg_count,
268 dma->bufs[i].seg_count
269 *(1 << dma->bufs[i].page_order),
270 (dma->bufs[i].seg_count
271 * (1 << dma->bufs[i].page_order))
272 * (int)PAGE_SIZE / 1024);
274 DRM_SYSCTL_PRINT("\n");
275 for (i = 0; i < dma->buf_count; i++) {
276 if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
277 DRM_SYSCTL_PRINT(" %d", templists[i]);
279 DRM_SYSCTL_PRINT("\n");
281 SYSCTL_OUT(req, "", 1);
283 drm_free(templists, DRM_MEM_DRIVER);
287 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
289 struct drm_device *dev = arg1;
290 struct drm_file *priv, *tempprivs;
298 list_for_each_entry(priv, &dev->filelist, lhead)
301 tempprivs = kmalloc(sizeof(struct drm_file) * privcount, DRM_MEM_DRIVER,
303 if (tempprivs == NULL) {
308 list_for_each_entry(priv, &dev->filelist, lhead)
309 tempprivs[i++] = *priv;
314 "\na dev pid uid magic ioctls\n");
315 for (i = 0; i < privcount; i++) {
316 priv = &tempprivs[i];
317 DRM_SYSCTL_PRINT("%c %-12s %5d %5d %10u %10lu\n",
318 priv->authenticated ? 'y' : 'n',
319 devtoname(priv->dev->devnode),
326 SYSCTL_OUT(req, "", 1);
328 drm_free(tempprivs, DRM_MEM_DRIVER);
332 static int drm_vblank_info DRM_SYSCTL_HANDLER_ARGS
334 struct drm_device *dev = arg1;
339 DRM_SYSCTL_PRINT("\ncrtc ref count last enabled inmodeset\n");
341 if (dev->_vblank_count == NULL)
343 for (i = 0 ; i < dev->num_crtcs ; i++) {
344 DRM_SYSCTL_PRINT(" %02d %02d %08d %08d %02d %02d\n",
345 i, dev->vblank_refcount[i].counter,
346 dev->_vblank_count[i].counter,
348 dev->vblank_enabled[i],
349 dev->vblank_inmodeset[i]);
354 SYSCTL_OUT(req, "", -1);