Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / uts / common / io / drm / drm_kstat.c
blobbc704a29561595ad63b4d1f2ba632553ed3a8a5f
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
22 * Copyright 2008 Sun Microsystems, Inc.
23 * All rights reserved. Use is subject to license terms.
26 #include "drmP.h"
27 #include <sys/kstat.h>
28 #include <sys/ddi.h>
29 #include <sys/sunddi.h>
30 #include <sys/sunldi.h>
32 static char *drmkstat_name[] = {
33 "opens",
34 "closes",
35 "IOCTLs",
36 "locks",
37 "unlocks",
38 NULL
41 static int
42 drm_kstat_update(kstat_t *ksp, int flag)
44 drm_device_t *sc;
45 kstat_named_t *knp;
46 int tmp;
48 if (flag != KSTAT_READ)
49 return (EACCES);
51 sc = ksp->ks_private;
52 knp = ksp->ks_data;
54 for (tmp = 1; tmp < 6; tmp++) {
55 (knp++)->value.ui32 = sc->counts[tmp];
58 return (0);
61 int
62 drm_init_kstats(drm_device_t *sc)
64 int instance;
65 kstat_t *ksp;
66 kstat_named_t *knp;
67 char *np;
68 char **aknp;
70 instance = ddi_get_instance(sc->dip);
71 aknp = drmkstat_name;
72 ksp = kstat_create("drm", instance, "drminfo", "drm",
73 KSTAT_TYPE_NAMED, sizeof (drmkstat_name)/sizeof (char *) - 1,
74 KSTAT_FLAG_PERSISTENT);
75 if (ksp == NULL)
76 return (0);
78 ksp->ks_private = sc;
79 ksp->ks_update = drm_kstat_update;
80 for (knp = ksp->ks_data; (np = (*aknp)) != NULL; knp++, aknp++) {
81 kstat_named_init(knp, np, KSTAT_DATA_UINT32);
83 kstat_install(ksp);
85 sc->asoft_ksp = ksp;
87 return (0);
90 void
91 drm_fini_kstats(drm_device_t *sc)
93 if (sc->asoft_ksp)
94 kstat_delete(sc->asoft_ksp);
95 else
96 cmn_err(CE_WARN, "attempt to delete null kstat");