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 #include "dev/drm/drmP.h"
28 #include "dev/drm/drm.h"
30 #include <sys/sysctl.h>
32 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS;
33 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS;
34 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS;
35 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS;
37 struct drm_sysctl_list {
39 int (*f) DRM_SYSCTL_HANDLER_ARGS;
40 } drm_sysctl_list[] = {
41 {"name", drm_name_info},
43 {"clients", drm_clients_info},
44 {"bufs", drm_bufs_info},
46 #define DRM_SYSCTL_ENTRIES (sizeof(drm_sysctl_list)/sizeof(drm_sysctl_list[0]))
48 struct drm_sysctl_info {
49 struct sysctl_ctx_list ctx;
53 int drm_sysctl_init(drm_device_t *dev)
55 struct drm_sysctl_info *info;
56 struct sysctl_oid *oid;
57 struct sysctl_oid *top, *drioid;
60 info = malloc(sizeof *info, M_DRM, M_WAITOK | M_ZERO);
65 /* Add the sysctl node for DRI if it doesn't already exist */
66 drioid = SYSCTL_ADD_NODE( &info->ctx, &sysctl__hw_children, OID_AUTO, "dri", CTLFLAG_RW, NULL, "DRI Graphics");
70 /* Find the next free slot under hw.dri */
72 SLIST_FOREACH(oid, SYSCTL_CHILDREN(drioid), oid_link) {
73 if (i <= oid->oid_arg2)
74 i = oid->oid_arg2 + 1;
79 /* Add the hw.dri.x for our device */
80 info->name[0] = '0' + i;
82 top = SYSCTL_ADD_NODE( &info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, info->name, CTLFLAG_RW, NULL, NULL);
86 for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
87 oid = SYSCTL_ADD_OID(&info->ctx,
90 drm_sysctl_list[i].name,
91 CTLTYPE_INT | CTLFLAG_RD,
100 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(top), OID_AUTO, "debug",
101 CTLFLAG_RW, &drm_debug_flag, sizeof(drm_debug_flag),
102 "Enable debugging output");
107 int drm_sysctl_cleanup(drm_device_t *dev)
110 error = sysctl_ctx_free( &dev->sysctl->ctx );
112 free(dev->sysctl, M_DRM);
118 #define DRM_SYSCTL_PRINT(fmt, arg...) \
120 snprintf(buf, sizeof(buf), fmt, ##arg); \
121 retcode = SYSCTL_OUT(req, buf, strlen(buf)); \
126 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
128 drm_device_t *dev = arg1;
133 DRM_SYSCTL_PRINT("%s 0x%x", dev->driver.name, dev2udev(dev->devnode));
137 snprintf(buf, sizeof(buf), " %s", dev->unique);
143 SYSCTL_OUT(req, buf, strlen(buf));
145 SYSCTL_OUT(req, "", 1);
151 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
153 drm_device_t *dev = arg1;
154 drm_local_map_t *map, *tempmaps;
155 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG" };
156 const char *type, *yesno;
161 /* We can't hold the lock while doing SYSCTL_OUTs, so allocate a
162 * temporary copy of all the map entries and then SYSCTL_OUT that.
167 TAILQ_FOREACH(map, &dev->maplist, link)
170 tempmaps = malloc(sizeof(drm_local_map_t) * mapcount, M_DRM, M_NOWAIT);
171 if (tempmaps == NULL) {
177 TAILQ_FOREACH(map, &dev->maplist, link)
178 tempmaps[i++] = *map;
182 DRM_SYSCTL_PRINT("\nslot offset size type flags "
185 for (i = 0; i < mapcount; i++) {
188 if (map->type < 0 || map->type > 4)
191 type = types[map->type];
199 "%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx %s\n", i,
200 map->offset, map->size, type, map->flags,
201 (unsigned long)map->handle, yesno);
203 SYSCTL_OUT(req, "", 1);
206 free(tempmaps, M_DRM);
210 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
212 drm_device_t *dev = arg1;
213 drm_device_dma_t *dma = dev->dma;
214 drm_device_dma_t tempdma;
220 /* We can't hold the locks around DRM_SYSCTL_PRINT, so make a temporary
221 * copy of the whole structure and the relevant data from buflist.
228 DRM_SPINLOCK(&dev->dma_lock);
230 templists = malloc(sizeof(int) * dma->buf_count, M_DRM, M_NOWAIT);
231 for (i = 0; i < dma->buf_count; i++)
232 templists[i] = dma->buflist[i]->list;
234 DRM_SPINUNLOCK(&dev->dma_lock);
237 DRM_SYSCTL_PRINT("\n o size count free segs pages kB\n");
238 for (i = 0; i <= DRM_MAX_ORDER; i++) {
239 if (dma->bufs[i].buf_count)
240 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
242 dma->bufs[i].buf_size,
243 dma->bufs[i].buf_count,
244 atomic_read(&dma->bufs[i]
246 dma->bufs[i].seg_count,
247 dma->bufs[i].seg_count
248 *(1 << dma->bufs[i].page_order),
249 (dma->bufs[i].seg_count
250 * (1 << dma->bufs[i].page_order))
253 DRM_SYSCTL_PRINT("\n");
254 for (i = 0; i < dma->buf_count; i++) {
255 if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
256 DRM_SYSCTL_PRINT(" %d", templists[i]);
258 DRM_SYSCTL_PRINT("\n");
260 SYSCTL_OUT(req, "", 1);
262 free(templists, M_DRM);
266 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
268 drm_device_t *dev = arg1;
269 drm_file_t *priv, *tempprivs;
277 TAILQ_FOREACH(priv, &dev->files, link)
280 tempprivs = malloc(sizeof(drm_file_t) * privcount, M_DRM, M_NOWAIT);
281 if (tempprivs == NULL) {
286 TAILQ_FOREACH(priv, &dev->files, link)
287 tempprivs[i++] = *priv;
291 DRM_SYSCTL_PRINT("\na dev pid uid magic ioctls\n");
292 for (i = 0; i < privcount; i++) {
293 priv = &tempprivs[i];
294 DRM_SYSCTL_PRINT("%c %3d %5d %5d %10u %10lu\n",
295 priv->authenticated ? 'y' : 'n',
303 SYSCTL_OUT(req, "", 1);
305 free(tempprivs, M_DRM);