160405de4Skz151634 /*
260405de4Skz151634 * CDDL HEADER START
360405de4Skz151634 *
460405de4Skz151634 * The contents of this file are subject to the terms of the
560405de4Skz151634 * Common Development and Distribution License (the "License").
660405de4Skz151634 * You may not use this file except in compliance with the License.
760405de4Skz151634 *
860405de4Skz151634 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
960405de4Skz151634 * or http://www.opensolaris.org/os/licensing.
1060405de4Skz151634 * See the License for the specific language governing permissions
1160405de4Skz151634 * and limitations under the License.
1260405de4Skz151634 *
1360405de4Skz151634 * When distributing Covered Code, include this CDDL HEADER in each
1460405de4Skz151634 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1560405de4Skz151634 * If applicable, add the following below this CDDL HEADER, with the
1660405de4Skz151634 * fields enclosed by brackets "[]" replaced with your own identifying
1760405de4Skz151634 * information: Portions Copyright [yyyy] [name of copyright owner]
1860405de4Skz151634 *
1960405de4Skz151634 * CDDL HEADER END
2060405de4Skz151634 */
2160405de4Skz151634 /*
22*d0538f66Scg149915 * Copyright 2008 Sun Microsystems, Inc.
2360405de4Skz151634 * All rights reserved. Use is subject to license terms.
2460405de4Skz151634 */
2560405de4Skz151634
2660405de4Skz151634 #pragma ident "%Z%%M% %I% %E% SMI"
2760405de4Skz151634
2860405de4Skz151634 #include "drmP.h"
2960405de4Skz151634 #include <sys/kstat.h>
3060405de4Skz151634 #include <sys/ddi.h>
3160405de4Skz151634 #include <sys/sunddi.h>
3260405de4Skz151634 #include <sys/sunldi.h>
3360405de4Skz151634
3460405de4Skz151634 static char *drmkstat_name[] = {
3560405de4Skz151634 "opens",
3660405de4Skz151634 "closes",
3760405de4Skz151634 "IOCTLs",
3860405de4Skz151634 "locks",
3960405de4Skz151634 "unlocks",
4060405de4Skz151634 NULL
4160405de4Skz151634 };
4260405de4Skz151634
4360405de4Skz151634 static int
drm_kstat_update(kstat_t * ksp,int flag)4460405de4Skz151634 drm_kstat_update(kstat_t *ksp, int flag)
4560405de4Skz151634 {
46*d0538f66Scg149915 drm_device_t *sc;
4760405de4Skz151634 kstat_named_t *knp;
4860405de4Skz151634 int tmp;
4960405de4Skz151634
5060405de4Skz151634 if (flag != KSTAT_READ)
5160405de4Skz151634 return (EACCES);
5260405de4Skz151634
5360405de4Skz151634 sc = ksp->ks_private;
5460405de4Skz151634 knp = ksp->ks_data;
5560405de4Skz151634
5660405de4Skz151634 for (tmp = 1; tmp < 6; tmp++) {
5760405de4Skz151634 (knp++)->value.ui32 = sc->counts[tmp];
5860405de4Skz151634 }
5960405de4Skz151634
6060405de4Skz151634 return (0);
6160405de4Skz151634 }
6260405de4Skz151634
6360405de4Skz151634 int
drm_init_kstats(drm_device_t * sc)64*d0538f66Scg149915 drm_init_kstats(drm_device_t *sc)
6560405de4Skz151634 {
6660405de4Skz151634 int instance;
6760405de4Skz151634 kstat_t *ksp;
6860405de4Skz151634 kstat_named_t *knp;
6960405de4Skz151634 char *np;
7060405de4Skz151634 char **aknp;
7160405de4Skz151634
7260405de4Skz151634 instance = ddi_get_instance(sc->dip);
7360405de4Skz151634 aknp = drmkstat_name;
7460405de4Skz151634 ksp = kstat_create("drm", instance, "drminfo", "drm",
7560405de4Skz151634 KSTAT_TYPE_NAMED, sizeof (drmkstat_name)/sizeof (char *) - 1,
7660405de4Skz151634 KSTAT_FLAG_PERSISTENT);
7760405de4Skz151634 if (ksp == NULL)
7860405de4Skz151634 return (NULL);
7960405de4Skz151634
8060405de4Skz151634 ksp->ks_private = sc;
8160405de4Skz151634 ksp->ks_update = drm_kstat_update;
8260405de4Skz151634 for (knp = ksp->ks_data; (np = (*aknp)) != NULL; knp++, aknp++) {
8360405de4Skz151634 kstat_named_init(knp, np, KSTAT_DATA_UINT32);
8460405de4Skz151634 }
8560405de4Skz151634 kstat_install(ksp);
8660405de4Skz151634
8760405de4Skz151634 sc->asoft_ksp = ksp;
8860405de4Skz151634
8960405de4Skz151634 return (0);
9060405de4Skz151634 }
9160405de4Skz151634
9260405de4Skz151634 void
drm_fini_kstats(drm_device_t * sc)93*d0538f66Scg149915 drm_fini_kstats(drm_device_t *sc)
9460405de4Skz151634 {
95*d0538f66Scg149915 if (sc->asoft_ksp)
9660405de4Skz151634 kstat_delete(sc->asoft_ksp);
97*d0538f66Scg149915 else
98*d0538f66Scg149915 cmn_err(CE_WARN, "attempt to delete null kstat");
9960405de4Skz151634 }
100