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 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 * DEALINGS IN THE SOFTWARE.
28 #include <sys/sysctl.h>
30 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS;
31 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS;
32 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS;
33 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS;
35 struct drm_sysctl_list {
37 int (*f) DRM_SYSCTL_HANDLER_ARGS;
38 } drm_sysctl_list[] = {
39 {"name", drm_name_info},
41 {"clients", drm_clients_info},
42 {"bufs", drm_bufs_info},
44 #define DRM_SYSCTL_ENTRIES (sizeof(drm_sysctl_list)/sizeof(drm_sysctl_list[0]))
46 struct drm_sysctl_info {
47 struct sysctl_ctx_list ctx;
51 int drm_sysctl_init(drm_device_t *dev)
53 struct drm_sysctl_info *info;
54 struct sysctl_oid *oid;
55 struct sysctl_oid *top, *drioid;
58 info = malloc(sizeof *info, M_DRM, M_WAITOK | M_ZERO);
63 /* Add the sysctl node for DRI if it doesn't already exist */
64 drioid = SYSCTL_ADD_NODE( &info->ctx, &sysctl__hw_children, OID_AUTO, "dri", CTLFLAG_RW, NULL, "DRI Graphics");
68 /* Find the next free slot under hw.dri */
70 SLIST_FOREACH(oid, SYSCTL_CHILDREN(drioid), oid_link) {
71 if (i <= oid->oid_arg2)
72 i = oid->oid_arg2 + 1;
77 /* Add the hw.dri.x for our device */
78 info->name[0] = '0' + i;
80 top = SYSCTL_ADD_NODE( &info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, info->name, CTLFLAG_RW, NULL, NULL);
84 for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
85 oid = SYSCTL_ADD_OID(&info->ctx,
88 drm_sysctl_list[i].name,
89 CTLTYPE_INT | CTLFLAG_RD,
98 SYSCTL_ADD_INT(&info->ctx, SYSCTL_CHILDREN(top), OID_AUTO, "debug",
99 CTLFLAG_RW, &drm_debug_flag, sizeof(drm_debug_flag),
100 "Enable debugging output");
105 int drm_sysctl_cleanup(drm_device_t *dev)
108 error = sysctl_ctx_free( &dev->sysctl->ctx );
110 free(dev->sysctl, M_DRM);
116 #define DRM_SYSCTL_PRINT(fmt, arg...) \
118 snprintf(buf, sizeof(buf), fmt, ##arg); \
119 retcode = SYSCTL_OUT(req, buf, strlen(buf)); \
124 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
126 drm_device_t *dev = arg1;
131 DRM_SYSCTL_PRINT("%s 0x%x", dev->driver_name, dev2udev(dev->devnode));
135 snprintf(buf, sizeof(buf), " %s", dev->unique);
141 SYSCTL_OUT(req, buf, strlen(buf));
143 SYSCTL_OUT(req, "", 1);
149 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
151 drm_device_t *dev = arg1;
152 drm_local_map_t *map, *tempmaps;
153 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG" };
154 const char *type, *yesno;
159 /* We can't hold the lock while doing SYSCTL_OUTs, so allocate a
160 * temporary copy of all the map entries and then SYSCTL_OUT that.
165 TAILQ_FOREACH(map, &dev->maplist, link)
168 tempmaps = malloc(sizeof(drm_local_map_t) * mapcount, M_DRM, M_NOWAIT);
169 if (tempmaps == NULL) {
175 TAILQ_FOREACH(map, &dev->maplist, link)
176 tempmaps[i++] = *map;
180 DRM_SYSCTL_PRINT("\nslot offset size type flags "
183 for (i = 0; i < mapcount; i++) {
186 if (map->type < 0 || map->type > 4)
189 type = types[map->type];
197 "%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx %s\n", i,
198 map->offset, map->size, type, map->flags,
199 (unsigned long)map->handle, yesno);
201 SYSCTL_OUT(req, "", 1);
204 free(tempmaps, M_DRM);
208 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
210 drm_device_t *dev = arg1;
211 drm_device_dma_t *dma = dev->dma;
212 drm_device_dma_t tempdma;
218 /* We can't hold the locks around DRM_SYSCTL_PRINT, so make a temporary
219 * copy of the whole structure and the relevant data from buflist.
226 DRM_SPINLOCK(&dev->dma_lock);
228 templists = malloc(sizeof(int) * dma->buf_count, M_DRM, M_NOWAIT);
229 for (i = 0; i < dma->buf_count; i++)
230 templists[i] = dma->buflist[i]->list;
232 DRM_SPINUNLOCK(&dev->dma_lock);
235 DRM_SYSCTL_PRINT("\n o size count free segs pages kB\n");
236 for (i = 0; i <= DRM_MAX_ORDER; i++) {
237 if (dma->bufs[i].buf_count)
238 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
240 dma->bufs[i].buf_size,
241 dma->bufs[i].buf_count,
242 atomic_read(&dma->bufs[i]
244 dma->bufs[i].seg_count,
245 dma->bufs[i].seg_count
246 *(1 << dma->bufs[i].page_order),
247 (dma->bufs[i].seg_count
248 * (1 << dma->bufs[i].page_order))
251 DRM_SYSCTL_PRINT("\n");
252 for (i = 0; i < dma->buf_count; i++) {
253 if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
254 DRM_SYSCTL_PRINT(" %d", templists[i]);
256 DRM_SYSCTL_PRINT("\n");
258 SYSCTL_OUT(req, "", 1);
260 free(templists, M_DRM);
264 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
266 drm_device_t *dev = arg1;
267 drm_file_t *priv, *tempprivs;
275 TAILQ_FOREACH(priv, &dev->files, link)
278 tempprivs = malloc(sizeof(drm_file_t) * privcount, M_DRM, M_NOWAIT);
279 if (tempprivs == NULL) {
284 TAILQ_FOREACH(priv, &dev->files, link)
285 tempprivs[i++] = *priv;
289 DRM_SYSCTL_PRINT("\na dev pid uid magic ioctls\n");
290 for (i = 0; i < privcount; i++) {
291 priv = &tempprivs[i];
292 DRM_SYSCTL_PRINT("%c %3d %5d %5d %10u %10lu\n",
293 priv->authenticated ? 'y' : 'n',
301 SYSCTL_OUT(req, "", 1);
303 free(tempprivs, M_DRM);