xref: /titanic_50/usr/src/uts/common/io/drm/drm_kstat.c (revision c0889d7a91fa87e1cb7ef4457629b0cb51d47b50)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.
23  * All rights reserved.  Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include "drmP.h"
29 #include <sys/kstat.h>
30 #include <sys/ddi.h>
31 #include <sys/sunddi.h>
32 #include <sys/sunldi.h>
33 
34 static char *drmkstat_name[] = {
35 	"opens",
36 	"closes",
37 	"IOCTLs",
38 	"locks",
39 	"unlocks",
40 	NULL
41 };
42 
43 static int
44 drm_kstat_update(kstat_t *ksp, int flag)
45 {
46 	drm_device_t *sc;
47 	kstat_named_t *knp;
48 	int tmp;
49 
50 	if (flag != KSTAT_READ)
51 		return (EACCES);
52 
53 	sc = ksp->ks_private;
54 	knp = ksp->ks_data;
55 
56 	for (tmp = 1; tmp < 6; tmp++) {
57 		(knp++)->value.ui32 = sc->counts[tmp];
58 	}
59 
60 	return (0);
61 }
62 
63 int
64 drm_init_kstats(drm_device_t *sc)
65 {
66 	int instance;
67 	kstat_t *ksp;
68 	kstat_named_t *knp;
69 	char *np;
70 	char **aknp;
71 
72 	instance = ddi_get_instance(sc->dip);
73 	aknp = drmkstat_name;
74 	ksp = kstat_create("drm", instance, "drminfo", "drm",
75 	    KSTAT_TYPE_NAMED, sizeof (drmkstat_name)/sizeof (char *) - 1,
76 	    KSTAT_FLAG_PERSISTENT);
77 	if (ksp == NULL)
78 		return (NULL);
79 
80 	ksp->ks_private = sc;
81 	ksp->ks_update = drm_kstat_update;
82 	for (knp = ksp->ks_data; (np = (*aknp)) != NULL; knp++, aknp++) {
83 		kstat_named_init(knp, np, KSTAT_DATA_UINT32);
84 	}
85 	kstat_install(ksp);
86 
87 	sc->asoft_ksp = ksp;
88 
89 	return (0);
90 }
91 
92 void
93 drm_fini_kstats(drm_device_t *sc)
94 {
95 	if (sc->asoft_ksp)
96 		kstat_delete(sc->asoft_ksp);
97 	else
98 		cmn_err(CE_WARN, "attempt to delete null kstat");
99 }
100