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/drm/drmP.h"
33 #include "dev/drm/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;
42 struct drm_sysctl_list {
44 int (*f) DRM_SYSCTL_HANDLER_ARGS;
45 } drm_sysctl_list[] = {
46 {"name", drm_name_info},
48 {"clients", drm_clients_info},
49 {"bufs", drm_bufs_info},
51 #define DRM_SYSCTL_ENTRIES (sizeof(drm_sysctl_list)/sizeof(drm_sysctl_list[0]))
53 struct drm_sysctl_info {
54 struct sysctl_ctx_list ctx;
58 int drm_sysctl_init(struct drm_device *dev)
60 struct drm_sysctl_info *info;
61 struct sysctl_oid *oid;
62 struct sysctl_oid *top, *drioid;
65 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__hw_children, OID_AUTO, "dri", CTLFLAG_RW, NULL, "DRI Graphics");
75 /* Find the next free slot under hw.dri */
77 SLIST_FOREACH(oid, SYSCTL_CHILDREN(drioid), oid_link) {
78 if (i <= oid->oid_arg2)
79 i = oid->oid_arg2 + 1;
84 /* Add the hw.dri.x for our device */
85 info->name[0] = '0' + i;
87 top = SYSCTL_ADD_NODE( &info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, info->name, CTLFLAG_RW, NULL, NULL);
91 for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
92 oid = SYSCTL_ADD_OID(&info->ctx,
95 drm_sysctl_list[i].name,
96 CTLTYPE_INT | CTLFLAG_RD,
105 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(top), OID_AUTO, "debug",
106 CTLFLAG_RW, &drm_debug_flag, sizeof(drm_debug_flag),
107 "Enable debugging output");
112 int drm_sysctl_cleanup(struct drm_device *dev)
115 error = sysctl_ctx_free( &dev->sysctl->ctx );
117 free(dev->sysctl, DRM_MEM_DRIVER);
123 #define DRM_SYSCTL_PRINT(fmt, arg...) \
125 snprintf(buf, sizeof(buf), fmt, ##arg); \
126 retcode = SYSCTL_OUT(req, buf, strlen(buf)); \
131 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
133 struct drm_device *dev = arg1;
138 DRM_SYSCTL_PRINT("%s 0x%x", dev->driver->name, dev2udev(dev->devnode));
142 snprintf(buf, sizeof(buf), " %s", dev->unique);
148 SYSCTL_OUT(req, buf, strlen(buf));
150 SYSCTL_OUT(req, "", 1);
156 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
158 struct drm_device *dev = arg1;
159 drm_local_map_t *map, *tempmaps;
160 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG" };
161 const char *type, *yesno;
166 /* We can't hold the lock while doing SYSCTL_OUTs, so allocate a
167 * temporary copy of all the map entries and then SYSCTL_OUT that.
172 TAILQ_FOREACH(map, &dev->maplist, link)
175 tempmaps = malloc(sizeof(drm_local_map_t) * mapcount, DRM_MEM_DRIVER,
177 if (tempmaps == NULL) {
183 TAILQ_FOREACH(map, &dev->maplist, link)
184 tempmaps[i++] = *map;
188 DRM_SYSCTL_PRINT("\nslot offset size "
189 "type flags address mtrr\n");
191 for (i = 0; i < mapcount; i++) {
194 if (map->type < 0 || map->type > 4)
197 type = types[map->type];
205 "%4d 0x%016lx 0x%08lx %4.4s 0x%02x 0x%016lx %s\n", i,
206 map->offset, map->size, type, map->flags,
207 (unsigned long)map->handle, yesno);
209 SYSCTL_OUT(req, "", 1);
212 free(tempmaps, DRM_MEM_DRIVER);
216 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
218 struct drm_device *dev = arg1;
219 drm_device_dma_t *dma = dev->dma;
220 drm_device_dma_t tempdma;
226 /* We can't hold the locks around DRM_SYSCTL_PRINT, so make a temporary
227 * copy of the whole structure and the relevant data from buflist.
234 DRM_SPINLOCK(&dev->dma_lock);
236 templists = malloc(sizeof(int) * dma->buf_count, DRM_MEM_DRIVER,
238 for (i = 0; i < dma->buf_count; i++)
239 templists[i] = dma->buflist[i]->list;
241 DRM_SPINUNLOCK(&dev->dma_lock);
244 DRM_SYSCTL_PRINT("\n o size count free segs pages kB\n");
245 for (i = 0; i <= DRM_MAX_ORDER; i++) {
246 if (dma->bufs[i].buf_count)
247 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
249 dma->bufs[i].buf_size,
250 dma->bufs[i].buf_count,
251 atomic_read(&dma->bufs[i]
253 dma->bufs[i].seg_count,
254 dma->bufs[i].seg_count
255 *(1 << dma->bufs[i].page_order),
256 (dma->bufs[i].seg_count
257 * (1 << dma->bufs[i].page_order))
260 DRM_SYSCTL_PRINT("\n");
261 for (i = 0; i < dma->buf_count; i++) {
262 if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
263 DRM_SYSCTL_PRINT(" %d", templists[i]);
265 DRM_SYSCTL_PRINT("\n");
267 SYSCTL_OUT(req, "", 1);
269 free(templists, DRM_MEM_DRIVER);
273 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
275 struct drm_device *dev = arg1;
276 struct drm_file *priv, *tempprivs;
284 TAILQ_FOREACH(priv, &dev->files, link)
287 tempprivs = malloc(sizeof(struct drm_file) * privcount, DRM_MEM_DRIVER,
289 if (tempprivs == NULL) {
294 TAILQ_FOREACH(priv, &dev->files, link)
295 tempprivs[i++] = *priv;
299 DRM_SYSCTL_PRINT("\na dev pid uid magic ioctls\n");
300 for (i = 0; i < privcount; i++) {
301 priv = &tempprivs[i];
302 DRM_SYSCTL_PRINT("%c %3d %5d %5d %10u %10lu\n",
303 priv->authenticated ? 'y' : 'n',
311 SYSCTL_OUT(req, "", 1);
313 free(tempprivs, DRM_MEM_DRIVER);