Nuke device_ptr_t, USBBASEDEVICE, USBDEVNAME(), USBDEVUNIT(), USBGETSOFTC(),
[dragonfly/vkernel-mp.git] / sys / dev / drm / drm_sysctl.h
blob69555d6bedddcbed7413eb65dbacf7fa2e33c6bf
1 /*
2 * $FreeBSD: src/sys/dev/drm/drm_sysctl.h,v 1.3.2.1 2003/04/26 07:05:29 anholt Exp $
3 * $DragonFly: src/sys/dev/drm/drm_sysctl.h,v 1.3 2004/02/13 02:23:57 joerg Exp $
4 */
6 #if defined(__DragonFly__) || defined(__FreeBSD__)
8 #include <sys/sysctl.h>
10 static int DRM(name_info)DRM_SYSCTL_HANDLER_ARGS;
11 static int DRM(vm_info)DRM_SYSCTL_HANDLER_ARGS;
12 static int DRM(clients_info)DRM_SYSCTL_HANDLER_ARGS;
13 static int DRM(bufs_info)DRM_SYSCTL_HANDLER_ARGS;
15 struct DRM(sysctl_list) {
16 const char *name;
17 int (*f) DRM_SYSCTL_HANDLER_ARGS;
18 } DRM(sysctl_list)[] = {
19 { "name", DRM(name_info) },
20 { "mem", DRM(mem_info) },
21 { "vm", DRM(vm_info) },
22 { "clients", DRM(clients_info) },
23 { "bufs", DRM(bufs_info) },
25 #define DRM_SYSCTL_ENTRIES (sizeof(DRM(sysctl_list))/sizeof(DRM(sysctl_list)[0]))
27 struct drm_sysctl_info {
28 struct sysctl_ctx_list ctx;
29 char name[2];
32 int DRM(sysctl_init)(drm_device_t *dev)
34 struct drm_sysctl_info *info;
35 struct sysctl_oid *oid;
36 struct sysctl_oid *top, *drioid;
37 int i;
39 info = DRM(alloc)(sizeof *info, DRM_MEM_DRIVER);
40 if ( !info )
41 return 1;
42 bzero(info, sizeof *info);
43 dev->sysctl = info;
45 /* Add the sysctl node for DRI if it doesn't already exist */
46 drioid = SYSCTL_ADD_NODE( &info->ctx, &sysctl__hw_children, OID_AUTO, "dri", CTLFLAG_RW, NULL, "DRI Graphics");
47 if (!drioid)
48 return 1;
50 /* Find the next free slot under hw.dri */
51 i = 0;
52 SLIST_FOREACH(oid, SYSCTL_CHILDREN(drioid), oid_link) {
53 if (i <= oid->oid_arg2)
54 i = oid->oid_arg2 + 1;
56 if (i>9)
57 return 1;
59 /* Add the hw.dri.x for our device */
60 info->name[0] = '0' + i;
61 info->name[1] = 0;
62 top = SYSCTL_ADD_NODE( &info->ctx, SYSCTL_CHILDREN(drioid), OID_AUTO, info->name, CTLFLAG_RW, NULL, NULL);
63 if (!top)
64 return 1;
66 for (i = 0; i < DRM_SYSCTL_ENTRIES; i++) {
67 oid = sysctl_add_oid( &info->ctx,
68 SYSCTL_CHILDREN(top),
69 OID_AUTO,
70 DRM(sysctl_list)[i].name,
71 CTLTYPE_INT | CTLFLAG_RD,
72 dev,
73 0,
74 DRM(sysctl_list)[i].f,
75 "A",
76 NULL);
77 if (!oid)
78 return 1;
80 return 0;
83 int DRM(sysctl_cleanup)(drm_device_t *dev)
85 int error;
86 error = sysctl_ctx_free( &dev->sysctl->ctx );
88 DRM(free)(dev->sysctl, sizeof *dev->sysctl, DRM_MEM_DRIVER);
89 dev->sysctl = NULL;
91 return error;
94 static int DRM(name_info)DRM_SYSCTL_HANDLER_ARGS
96 drm_device_t *dev = arg1;
97 char buf[128];
98 int error;
100 if (dev->unique) {
101 DRM_SYSCTL_PRINT("%s 0x%x %s\n",
102 dev->name, dev2udev(dev->devnode), dev->unique);
103 } else {
104 DRM_SYSCTL_PRINT("%s 0x%x\n", dev->name, dev2udev(dev->devnode));
107 SYSCTL_OUT(req, "", 1);
109 return 0;
112 static int DRM(_vm_info)DRM_SYSCTL_HANDLER_ARGS
114 drm_device_t *dev = arg1;
115 drm_local_map_t *map;
116 drm_map_list_entry_t *listentry;
117 const char *types[] = { "FB", "REG", "SHM" };
118 const char *type;
119 int i=0;
120 char buf[128];
121 int error;
123 DRM_SYSCTL_PRINT("slot offset size type flags "
124 "address mtrr\n\n");
125 error = SYSCTL_OUT(req, buf, strlen(buf));
126 if (error) return error;
128 if (dev->maplist != NULL) {
129 TAILQ_FOREACH(listentry, dev->maplist, link) {
130 map = listentry->map;
131 if (map->type < 0 || map->type > 2) type = "??";
132 else type = types[map->type];
133 DRM_SYSCTL_PRINT("%4d 0x%08lx 0x%08lx %4.4s 0x%02x 0x%08lx ",
135 map->offset,
136 map->size,
137 type,
138 map->flags,
139 (unsigned long)map->handle);
140 if (map->mtrr < 0) {
141 DRM_SYSCTL_PRINT("none\n");
142 } else {
143 DRM_SYSCTL_PRINT("%4d\n", map->mtrr);
145 i++;
148 SYSCTL_OUT(req, "", 1);
150 return 0;
153 static int DRM(vm_info)DRM_SYSCTL_HANDLER_ARGS
155 drm_device_t *dev = arg1;
156 int ret;
158 DRM_LOCK;
159 ret = DRM(_vm_info)(oidp, arg1, arg2, req);
160 DRM_UNLOCK;
162 return ret;
166 /* drm_bufs_info is called whenever a process reads
167 hw.dri.0.bufs. */
169 static int DRM(_bufs_info) DRM_SYSCTL_HANDLER_ARGS
171 drm_device_t *dev = arg1;
172 drm_device_dma_t *dma = dev->dma;
173 int i;
174 char buf[128];
175 int error;
177 if (!dma) return 0;
178 DRM_SYSCTL_PRINT(" o size count free segs pages kB\n\n");
179 for (i = 0; i <= DRM_MAX_ORDER; i++) {
180 if (dma->bufs[i].buf_count)
181 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
183 dma->bufs[i].buf_size,
184 dma->bufs[i].buf_count,
185 atomic_read(&dma->bufs[i]
186 .freelist.count),
187 dma->bufs[i].seg_count,
188 dma->bufs[i].seg_count
189 *(1 << dma->bufs[i].page_order),
190 (dma->bufs[i].seg_count
191 * (1 << dma->bufs[i].page_order))
192 * PAGE_SIZE / 1024);
194 DRM_SYSCTL_PRINT("\n");
195 for (i = 0; i < dma->buf_count; i++) {
196 if (i && !(i%32)) DRM_SYSCTL_PRINT("\n");
197 DRM_SYSCTL_PRINT(" %d", dma->buflist[i]->list);
199 DRM_SYSCTL_PRINT("\n");
201 SYSCTL_OUT(req, "", 1);
202 return 0;
205 static int DRM(bufs_info) DRM_SYSCTL_HANDLER_ARGS
207 drm_device_t *dev = arg1;
208 int ret;
210 DRM_LOCK;
211 ret = DRM(_bufs_info)(oidp, arg1, arg2, req);
212 DRM_UNLOCK;
213 return ret;
217 static int DRM(_clients_info) DRM_SYSCTL_HANDLER_ARGS
219 drm_device_t *dev = arg1;
220 drm_file_t *priv;
221 char buf[128];
222 int error;
224 DRM_SYSCTL_PRINT("a dev pid uid magic ioctls\n\n");
225 TAILQ_FOREACH(priv, &dev->files, link) {
226 DRM_SYSCTL_PRINT("%c %3d %5d %5d %10u %10lu\n",
227 priv->authenticated ? 'y' : 'n',
228 priv->minor,
229 priv->pid,
230 priv->uid,
231 priv->magic,
232 priv->ioctl_count);
235 SYSCTL_OUT(req, "", 1);
236 return 0;
239 static int DRM(clients_info)DRM_SYSCTL_HANDLER_ARGS
241 drm_device_t *dev = arg1;
242 int ret;
244 DRM_LOCK;
245 ret = DRM(_clients_info)(oidp, arg1, arg2, req);
246 DRM_UNLOCK;
247 return ret;
251 #elif defined(__NetBSD__)
252 /* stub it out for now, sysctl is only for debugging */
253 int DRM(sysctl_init)(drm_device_t *dev)
255 return 0;
258 int DRM(sysctl_cleanup)(drm_device_t *dev)
260 return 0;
262 #endif