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 $
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
) {
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
;
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
;
39 info
= DRM(alloc
)(sizeof *info
, DRM_MEM_DRIVER
);
42 bzero(info
, sizeof *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");
50 /* Find the next free slot under hw.dri */
52 SLIST_FOREACH(oid
, SYSCTL_CHILDREN(drioid
), oid_link
) {
53 if (i
<= oid
->oid_arg2
)
54 i
= oid
->oid_arg2
+ 1;
59 /* Add the hw.dri.x for our device */
60 info
->name
[0] = '0' + i
;
62 top
= SYSCTL_ADD_NODE( &info
->ctx
, SYSCTL_CHILDREN(drioid
), OID_AUTO
, info
->name
, CTLFLAG_RW
, NULL
, NULL
);
66 for (i
= 0; i
< DRM_SYSCTL_ENTRIES
; i
++) {
67 oid
= sysctl_add_oid( &info
->ctx
,
70 DRM(sysctl_list
)[i
].name
,
71 CTLTYPE_INT
| CTLFLAG_RD
,
74 DRM(sysctl_list
)[i
].f
,
83 int DRM(sysctl_cleanup
)(drm_device_t
*dev
)
86 error
= sysctl_ctx_free( &dev
->sysctl
->ctx
);
88 DRM(free
)(dev
->sysctl
, sizeof *dev
->sysctl
, DRM_MEM_DRIVER
);
94 static int DRM(name_info
)DRM_SYSCTL_HANDLER_ARGS
96 drm_device_t
*dev
= arg1
;
101 DRM_SYSCTL_PRINT("%s 0x%x %s\n",
102 dev
->name
, dev2udev(dev
->devnode
), dev
->unique
);
104 DRM_SYSCTL_PRINT("%s 0x%x\n", dev
->name
, dev2udev(dev
->devnode
));
107 SYSCTL_OUT(req
, "", 1);
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" };
123 DRM_SYSCTL_PRINT("slot offset size type flags "
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 ",
139 (unsigned long)map
->handle
);
141 DRM_SYSCTL_PRINT("none\n");
143 DRM_SYSCTL_PRINT("%4d\n", map
->mtrr
);
148 SYSCTL_OUT(req
, "", 1);
153 static int DRM(vm_info
)DRM_SYSCTL_HANDLER_ARGS
155 drm_device_t
*dev
= arg1
;
159 ret
= DRM(_vm_info
)(oidp
, arg1
, arg2
, req
);
166 /* drm_bufs_info is called whenever a process reads
169 static int DRM(_bufs_info
) DRM_SYSCTL_HANDLER_ARGS
171 drm_device_t
*dev
= arg1
;
172 drm_device_dma_t
*dma
= dev
->dma
;
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
]
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
))
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);
205 static int DRM(bufs_info
) DRM_SYSCTL_HANDLER_ARGS
207 drm_device_t
*dev
= arg1
;
211 ret
= DRM(_bufs_info
)(oidp
, arg1
, arg2
, req
);
217 static int DRM(_clients_info
) DRM_SYSCTL_HANDLER_ARGS
219 drm_device_t
*dev
= arg1
;
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',
235 SYSCTL_OUT(req
, "", 1);
239 static int DRM(clients_info
)DRM_SYSCTL_HANDLER_ARGS
241 drm_device_t
*dev
= arg1
;
245 ret
= DRM(_clients_info
)(oidp
, arg1
, arg2
, req
);
251 #elif defined(__NetBSD__)
252 /* stub it out for now, sysctl is only for debugging */
253 int DRM(sysctl_init
)(drm_device_t
*dev
)
258 int DRM(sysctl_cleanup
)(drm_device_t
*dev
)