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) },
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 = DRM(alloc)(sizeof *info, DRM_MEM_DRIVER);
63 bzero(info, sizeof *info);
66 /* Add the sysctl node for DRI if it doesn't already exist */
67 drioid = SYSCTL_ADD_NODE( &info->ctx, &sysctl__hw_children, OID_AUTO, "dri", CTLFLAG_RW, NULL, "DRI Graphics");
71 /* Find the next free slot under hw.dri */
73 SLIST_FOREACH(oid, SYSCTL_CHILDREN(drioid), oid_link) {
74 if (i <= oid->oid_arg2)
75 i = oid->oid_arg2 + 1;
80 /* Add the hw.dri.x for our device */
81 info->name[0] = '0' + i;
83 top = SYSCTL_ADD_NODE( &info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, info->name, CTLFLAG_RW, NULL, NULL);
87 for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
88 oid = sysctl_add_oid( &info->ctx,
91 DRM(sysctl_list)[i].name,
92 CTLTYPE_INT | CTLFLAG_RD,
95 DRM(sysctl_list)[i].f,
104 int DRM(sysctl_cleanup)(drm_device_t *dev)
107 error = sysctl_ctx_free( &dev->sysctl->ctx );
109 DRM(free)(dev->sysctl, sizeof *dev->sysctl, DRM_MEM_DRIVER);
115 static int DRM(name_info)DRM_SYSCTL_HANDLER_ARGS
117 drm_device_t *dev = arg1;
122 DRM_SYSCTL_PRINT("%s 0x%x %s",
123 dev->name, dev2udev(dev->devnode), dev->unique);
125 DRM_SYSCTL_PRINT("%s 0x%x", dev->name, dev2udev(dev->devnode));
128 SYSCTL_OUT(req, "", 1);
133 static int DRM(_vm_info)DRM_SYSCTL_HANDLER_ARGS
135 drm_device_t *dev = arg1;
136 drm_local_map_t *map;
137 drm_map_list_entry_t *listentry;
138 const char *types[] = { "FB", "REG", "SHM", "AGP", "SG" };
144 DRM_SYSCTL_PRINT("\nslot offset size type flags "
147 if (dev->maplist != NULL) {
148 TAILQ_FOREACH(listentry, dev->maplist, link) {
149 map = listentry->map;
150 if (map->type < 0 || map->type > 4)
153 type = types[map->type];
154 DRM_SYSCTL_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx ",
160 (unsigned long)map->handle);
162 DRM_SYSCTL_PRINT("no\n");
164 DRM_SYSCTL_PRINT("yes\n");
169 SYSCTL_OUT(req, "", 1);
174 static int DRM(vm_info)DRM_SYSCTL_HANDLER_ARGS
176 drm_device_t *dev = arg1;
180 ret = DRM(_vm_info)(oidp, arg1, arg2, req);
187 /* drm_bufs_info is called whenever a process reads
190 static int DRM(_bufs_info) DRM_SYSCTL_HANDLER_ARGS
192 drm_device_t *dev = arg1;
193 drm_device_dma_t *dma = dev->dma;
199 DRM_SYSCTL_PRINT("\n o size count free segs pages kB\n");
200 for (i = 0; i <= DRM_MAX_ORDER; i++) {
201 if (dma->bufs[i].buf_count)
202 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
204 dma->bufs[i].buf_size,
205 dma->bufs[i].buf_count,
206 atomic_read(&dma->bufs[i]
208 dma->bufs[i].seg_count,
209 dma->bufs[i].seg_count
210 *(1 << dma->bufs[i].page_order),
211 (dma->bufs[i].seg_count
212 * (1 << dma->bufs[i].page_order))
215 DRM_SYSCTL_PRINT("\n");
216 for (i = 0; i < dma->buf_count; i++) {
217 if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
218 DRM_SYSCTL_PRINT(" %d", dma->buflist[i]->list);
220 DRM_SYSCTL_PRINT("\n");
222 SYSCTL_OUT(req, "", 1);
226 static int DRM(bufs_info) DRM_SYSCTL_HANDLER_ARGS
228 drm_device_t *dev = arg1;
232 ret = DRM(_bufs_info)(oidp, arg1, arg2, req);
238 static int DRM(_clients_info) DRM_SYSCTL_HANDLER_ARGS
240 drm_device_t *dev = arg1;
245 DRM_SYSCTL_PRINT("\na dev pid uid magic ioctls\n");
246 TAILQ_FOREACH(priv, &dev->files, link) {
247 DRM_SYSCTL_PRINT("%c %3d %5d %5d %10u %10lu\n",
248 priv->authenticated ? 'y' : 'n',
256 SYSCTL_OUT(req, "", 1);
260 static int DRM(clients_info)DRM_SYSCTL_HANDLER_ARGS
262 drm_device_t *dev = arg1;
266 ret = DRM(_clients_info)(oidp, arg1, arg2, req);
272 #elif defined(__NetBSD__)
273 /* stub it out for now, sysctl is only for debugging */
274 int DRM(sysctl_init)(drm_device_t *dev)
279 int DRM(sysctl_cleanup)(drm_device_t *dev)