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.
27 #include <sys/sysctl.h>
29 static int DRM(name_info)DRM_SYSCTL_HANDLER_ARGS;
30 static int DRM(vm_info)DRM_SYSCTL_HANDLER_ARGS;
31 static int DRM(clients_info)DRM_SYSCTL_HANDLER_ARGS;
32 static int DRM(bufs_info)DRM_SYSCTL_HANDLER_ARGS;
34 struct DRM(sysctl_list) {
36 int (*f) DRM_SYSCTL_HANDLER_ARGS;
37 } DRM(sysctl_list)[] = {
38 { "name", DRM(name_info) },
40 { "mem", DRM(mem_info) },
42 { "vm", DRM(vm_info) },
43 { "clients", DRM(clients_info) },
45 { "bufs", DRM(bufs_info) },
48 #define DRM_SYSCTL_ENTRIES (sizeof(DRM(sysctl_list))/sizeof(DRM(sysctl_list)[0]))
50 struct drm_sysctl_info {
51 struct sysctl_ctx_list ctx;
55 int DRM(sysctl_init)(drm_device_t *dev)
57 struct drm_sysctl_info *info;
58 struct sysctl_oid *oid;
59 struct sysctl_oid *top, *drioid;
62 info = DRM(alloc)(sizeof *info, DRM_MEM_DRIVER);
65 bzero(info, sizeof *info);
68 /* Add the sysctl node for DRI if it doesn't already exist */
69 drioid = SYSCTL_ADD_NODE( &info->ctx, &sysctl__hw_children, OID_AUTO, "dri", CTLFLAG_RW, NULL, "DRI Graphics");
73 /* Find the next free slot under hw.dri */
75 SLIST_FOREACH(oid, SYSCTL_CHILDREN(drioid), oid_link) {
76 if (i <= oid->oid_arg2)
77 i = oid->oid_arg2 + 1;
82 /* Add the hw.dri.x for our device */
83 info->name[0] = '0' + i;
85 top = SYSCTL_ADD_NODE( &info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, info->name, CTLFLAG_RW, NULL, NULL);
89 for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
90 oid = sysctl_add_oid( &info->ctx,
93 DRM(sysctl_list)[i].name,
94 CTLTYPE_INT | CTLFLAG_RD,
97 DRM(sysctl_list)[i].f,
106 int DRM(sysctl_cleanup)(drm_device_t *dev)
109 error = sysctl_ctx_free( &dev->sysctl->ctx );
111 DRM(free)(dev->sysctl, sizeof *dev->sysctl, DRM_MEM_DRIVER);
117 #define DRM_SYSCTL_PRINT(fmt, arg...) \
119 snprintf(buf, sizeof(buf), fmt, ##arg); \
120 retcode = SYSCTL_OUT(req, buf, strlen(buf)); \
125 static int DRM(name_info)DRM_SYSCTL_HANDLER_ARGS
127 drm_device_t *dev = arg1;
132 DRM_SYSCTL_PRINT("%s 0x%x", dev->name, dev2udev(dev->devnode));
136 snprintf(buf, sizeof(buf), " %s", dev->unique);
142 SYSCTL_OUT(req, buf, strlen(buf));
144 SYSCTL_OUT(req, "", 1);
150 static int DRM(vm_info)DRM_SYSCTL_HANDLER_ARGS
152 drm_device_t *dev = arg1;
153 drm_local_map_t *map, *tempmaps;
154 drm_map_list_entry_t *listentry;
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(listentry, dev->maplist, link)
170 tempmaps = DRM(alloc)(sizeof(drm_local_map_t) * mapcount, DRM_MEM_MAPS);
171 if (tempmaps == NULL) {
177 TAILQ_FOREACH(listentry, dev->maplist, link)
178 tempmaps[i++] = *listentry->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 DRM(free)(tempmaps, sizeof(drm_local_map_t) * mapcount, DRM_MEM_MAPS);
211 static int DRM(bufs_info) DRM_SYSCTL_HANDLER_ARGS
213 drm_device_t *dev = arg1;
214 drm_device_dma_t *dma = dev->dma;
215 drm_device_dma_t tempdma;
221 /* We can't hold the locks around DRM_SYSCTL_PRINT, so make a temporary
222 * copy of the whole structure and the relevant data from buflist.
225 DRM_SPINLOCK(&dev->dma_lock);
227 DRM_SPINUNLOCK(&dev->dma_lock);
232 templists = DRM(alloc)(sizeof(int) * dma->buf_count, DRM_MEM_BUFS);
233 for (i = 0; i < dma->buf_count; i++)
234 templists[i] = dma->buflist[i]->list;
236 DRM_SPINUNLOCK(&dev->dma_lock);
239 DRM_SYSCTL_PRINT("\n o size count free segs pages kB\n");
240 for (i = 0; i <= DRM_MAX_ORDER; i++) {
241 if (dma->bufs[i].buf_count)
242 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
244 dma->bufs[i].buf_size,
245 dma->bufs[i].buf_count,
246 atomic_read(&dma->bufs[i]
248 dma->bufs[i].seg_count,
249 dma->bufs[i].seg_count
250 *(1 << dma->bufs[i].page_order),
251 (dma->bufs[i].seg_count
252 * (1 << dma->bufs[i].page_order))
255 DRM_SYSCTL_PRINT("\n");
256 for (i = 0; i < dma->buf_count; i++) {
257 if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
258 DRM_SYSCTL_PRINT(" %d", templists[i]);
260 DRM_SYSCTL_PRINT("\n");
262 SYSCTL_OUT(req, "", 1);
264 DRM(free)(templists, sizeof(int) * dma->buf_count, DRM_MEM_BUFS);
269 static int DRM(clients_info)DRM_SYSCTL_HANDLER_ARGS
271 drm_device_t *dev = arg1;
272 drm_file_t *priv, *tempprivs;
280 TAILQ_FOREACH(priv, &dev->files, link)
283 tempprivs = DRM(alloc)(sizeof(drm_file_t) * privcount, DRM_MEM_FILES);
284 if (tempprivs == NULL) {
289 TAILQ_FOREACH(priv, &dev->files, link)
290 tempprivs[i++] = *priv;
294 DRM_SYSCTL_PRINT("\na dev pid uid magic ioctls\n");
295 for (i = 0; i < privcount; i++) {
296 priv = &tempprivs[i];
297 DRM_SYSCTL_PRINT("%c %3d %5d %5d %10u %10lu\n",
298 priv->authenticated ? 'y' : 'n',
306 SYSCTL_OUT(req, "", 1);
308 DRM(free)(tempprivs, sizeof(drm_file_t) * privcount, DRM_MEM_FILES);
312 #elif defined(__NetBSD__)
313 /* stub it out for now, sysctl is only for debugging */
314 int DRM(sysctl_init)(drm_device_t *dev)
319 int DRM(sysctl_cleanup)(drm_device_t *dev)