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 * ERIC ANHOLT BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
20 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 /** @file drm_sysctl.c
25 * Implementation of various sysctls for controlling DRM behavior and reporting
29 #include "dev/drm/drmP.h"
30 #include "dev/drm/drm.h"
32 #include <sys/sysctl.h>
34 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
;
35 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
;
36 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
;
37 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
;
38 static int drm_vblank_info DRM_SYSCTL_HANDLER_ARGS
;
40 struct drm_sysctl_list
{
42 int (*f
) DRM_SYSCTL_HANDLER_ARGS
;
43 } drm_sysctl_list
[] = {
44 {"name", drm_name_info
},
46 {"clients", drm_clients_info
},
47 {"bufs", drm_bufs_info
},
48 {"vblank", drm_vblank_info
},
50 #define DRM_SYSCTL_ENTRIES (sizeof(drm_sysctl_list)/sizeof(drm_sysctl_list[0]))
52 struct drm_sysctl_info
{
53 struct sysctl_ctx_list ctx
;
57 int drm_sysctl_init(struct drm_device
*dev
)
59 struct drm_sysctl_info
*info
;
60 struct sysctl_oid
*oid
;
61 struct sysctl_oid
*top
, *drioid
;
64 info
= malloc(sizeof *info
, DRM_MEM_DRIVER
, M_WAITOK
| M_ZERO
);
69 /* Add the sysctl node for DRI if it doesn't already exist */
70 drioid
= SYSCTL_ADD_NODE( &info
->ctx
, &sysctl__hw_children
, OID_AUTO
, "dri", CTLFLAG_RW
, NULL
, "DRI Graphics");
74 /* Find the next free slot under hw.dri */
76 SLIST_FOREACH(oid
, SYSCTL_CHILDREN(drioid
), oid_link
) {
77 if (i
<= oid
->oid_arg2
)
78 i
= oid
->oid_arg2
+ 1;
83 /* Add the hw.dri.x for our device */
84 info
->name
[0] = '0' + i
;
86 top
= SYSCTL_ADD_NODE( &info
->ctx
, SYSCTL_CHILDREN(drioid
), OID_AUTO
, info
->name
, CTLFLAG_RW
, NULL
, NULL
);
90 for (i
= 0; i
< DRM_SYSCTL_ENTRIES
; i
++) {
91 oid
= SYSCTL_ADD_OID(&info
->ctx
,
94 drm_sysctl_list
[i
].name
,
95 CTLTYPE_INT
| CTLFLAG_RD
,
104 SYSCTL_ADD_INT(&info
->ctx
, SYSCTL_CHILDREN(top
), OID_AUTO
, "debug",
105 CTLFLAG_RW
, &drm_debug_flag
, sizeof(drm_debug_flag
),
106 "Enable debugging output");
111 int drm_sysctl_cleanup(struct drm_device
*dev
)
114 error
= sysctl_ctx_free( &dev
->sysctl
->ctx
);
116 free(dev
->sysctl
, DRM_MEM_DRIVER
);
122 #define DRM_SYSCTL_PRINT(fmt, arg...) \
124 snprintf(buf, sizeof(buf), fmt, ##arg); \
125 retcode = SYSCTL_OUT(req, buf, strlen(buf)); \
130 static int drm_name_info DRM_SYSCTL_HANDLER_ARGS
132 struct drm_device
*dev
= arg1
;
137 DRM_SYSCTL_PRINT("%s 0x%x", dev
->driver
->name
, dev2udev(dev
->devnode
));
141 snprintf(buf
, sizeof(buf
), " %s", dev
->unique
);
147 SYSCTL_OUT(req
, buf
, strlen(buf
));
149 SYSCTL_OUT(req
, "", 1);
155 static int drm_vm_info DRM_SYSCTL_HANDLER_ARGS
157 struct drm_device
*dev
= arg1
;
158 drm_local_map_t
*map
, *tempmaps
;
159 const char *types
[] = { "FB", "REG", "SHM", "AGP", "SG" };
160 const char *type
, *yesno
;
165 /* We can't hold the lock while doing SYSCTL_OUTs, so allocate a
166 * temporary copy of all the map entries and then SYSCTL_OUT that.
171 TAILQ_FOREACH(map
, &dev
->maplist
, link
)
174 tempmaps
= malloc(sizeof(drm_local_map_t
) * mapcount
, DRM_MEM_DRIVER
,
176 if (tempmaps
== NULL
) {
182 TAILQ_FOREACH(map
, &dev
->maplist
, link
)
183 tempmaps
[i
++] = *map
;
187 DRM_SYSCTL_PRINT("\nslot offset size "
188 "type flags address mtrr\n");
190 for (i
= 0; i
< mapcount
; i
++) {
193 if (map
->type
< 0 || map
->type
> 4)
196 type
= types
[map
->type
];
204 "%4d 0x%016lx 0x%08lx %4.4s 0x%02x 0x%016lx %s\n", i
,
205 map
->offset
, map
->size
, type
, map
->flags
,
206 (unsigned long)map
->handle
, yesno
);
208 SYSCTL_OUT(req
, "", 1);
211 free(tempmaps
, DRM_MEM_DRIVER
);
215 static int drm_bufs_info DRM_SYSCTL_HANDLER_ARGS
217 struct drm_device
*dev
= arg1
;
218 drm_device_dma_t
*dma
= dev
->dma
;
219 drm_device_dma_t tempdma
;
225 /* We can't hold the locks around DRM_SYSCTL_PRINT, so make a temporary
226 * copy of the whole structure and the relevant data from buflist.
233 DRM_SPINLOCK(&dev
->dma_lock
);
235 templists
= malloc(sizeof(int) * dma
->buf_count
, DRM_MEM_DRIVER
,
237 for (i
= 0; i
< dma
->buf_count
; i
++)
238 templists
[i
] = dma
->buflist
[i
]->list
;
240 DRM_SPINUNLOCK(&dev
->dma_lock
);
243 DRM_SYSCTL_PRINT("\n o size count free segs pages kB\n");
244 for (i
= 0; i
<= DRM_MAX_ORDER
; i
++) {
245 if (dma
->bufs
[i
].buf_count
)
246 DRM_SYSCTL_PRINT("%2d %8d %5d %5d %5d %5d %5d\n",
248 dma
->bufs
[i
].buf_size
,
249 dma
->bufs
[i
].buf_count
,
250 atomic_read(&dma
->bufs
[i
]
252 dma
->bufs
[i
].seg_count
,
253 dma
->bufs
[i
].seg_count
254 *(1 << dma
->bufs
[i
].page_order
),
255 (dma
->bufs
[i
].seg_count
256 * (1 << dma
->bufs
[i
].page_order
))
259 DRM_SYSCTL_PRINT("\n");
260 for (i
= 0; i
< dma
->buf_count
; i
++) {
261 if (i
&& !(i
%32)) DRM_SYSCTL_PRINT("\n");
262 DRM_SYSCTL_PRINT(" %d", templists
[i
]);
264 DRM_SYSCTL_PRINT("\n");
266 SYSCTL_OUT(req
, "", 1);
268 free(templists
, DRM_MEM_DRIVER
);
272 static int drm_clients_info DRM_SYSCTL_HANDLER_ARGS
274 struct drm_device
*dev
= arg1
;
275 struct drm_file
*priv
, *tempprivs
;
283 TAILQ_FOREACH(priv
, &dev
->files
, link
)
286 tempprivs
= malloc(sizeof(struct drm_file
) * privcount
, DRM_MEM_DRIVER
,
288 if (tempprivs
== NULL
) {
293 TAILQ_FOREACH(priv
, &dev
->files
, link
)
294 tempprivs
[i
++] = *priv
;
298 DRM_SYSCTL_PRINT("\na dev pid uid magic ioctls\n");
299 for (i
= 0; i
< privcount
; i
++) {
300 priv
= &tempprivs
[i
];
301 DRM_SYSCTL_PRINT("%c %3d %5d %5d %10u %10lu\n",
302 priv
->authenticated
? 'y' : 'n',
310 SYSCTL_OUT(req
, "", 1);
312 free(tempprivs
, DRM_MEM_DRIVER
);
316 static int drm_vblank_info DRM_SYSCTL_HANDLER_ARGS
318 struct drm_device
*dev
= arg1
;
323 DRM_SYSCTL_PRINT("\ncrtc ref count last enabled inmodeset\n");
324 for(i
= 0 ; i
< dev
->num_crtcs
; i
++) {
325 DRM_SYSCTL_PRINT(" %02d %02d %08d %08d %02d %02d\n",
326 i
, atomic_load_acq_32(&dev
->vblank
[i
].refcount
),
327 atomic_load_acq_32(&dev
->vblank
[i
].count
),
328 atomic_load_acq_32(&dev
->vblank
[i
].last
),
329 atomic_load_acq_int(&dev
->vblank
[i
].enabled
),
330 atomic_load_acq_int(&dev
->vblank
[i
].inmodeset
));
333 SYSCTL_OUT(req
, "", -1);