dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / uts / intel / io / agpgart / agp_kstat.c
blob2c6cd02d0f357174ebaa3ab1464b11d1a059ea28
1 /*
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
3 * Use is subject to license terms.
4 */
6 #include <sys/kstat.h>
7 #include <sys/ddi.h>
8 #include <sys/sunddi.h>
9 #include <sys/sunldi.h>
10 #include <sys/agpgart.h>
11 #include <sys/agp/agpdefs.h>
12 #include <sys/agp/agpgart_impl.h>
15 * The values of type agp_arc_type_t are used as indices into arc_name
16 * So if agp_arc_type_t's values are changed in the future, the content
17 * of arc_name must be changed accordingly.
19 static const char *arc_name[] = {
20 "IGD_810",
21 "IGD_830",
22 "INTEL_AGP",
23 "AMD64_AGP",
24 "AMD64_NONAGP",
25 "UNKNOWN"
28 static char *agpkstat_name[] = {
29 "&arc_type",
30 "master_dev_id",
31 "master_dev_version",
32 "master_dev_status",
33 "$prealloc_size",
34 "target_dev_id",
35 "target_dev_version",
36 "target_dev_status",
37 "$aper_base",
38 "$aper_size",
39 "&agp_enabled",
40 "agp_mode_set",
41 "$aper_used",
42 NULL
45 static void
46 agp_set_char_kstat(kstat_named_t *knp, const char *s)
48 (void) strlcpy(knp->value.c, s, sizeof (knp->value.c));
51 static int
52 agp_kstat_update(kstat_t *ksp, int flag)
54 agpgart_softstate_t *sc;
55 kstat_named_t *knp;
56 int tmp;
58 if (flag != KSTAT_READ)
59 return (EACCES);
61 sc = ksp->ks_private;
62 knp = ksp->ks_data;
64 agp_set_char_kstat(knp++, arc_name[sc->asoft_devreg.agprd_arctype]);
65 (knp++)->value.ui32 = sc->asoft_info.agpki_mdevid;
66 (knp++)->value.ui32 = (sc->asoft_info.agpki_mver.agpv_major<<16) |
67 sc->asoft_info.agpki_mver.agpv_minor;
68 (knp++)->value.ui32 = sc->asoft_info.agpki_mstatus;
69 (knp++)->value.ui64 = (sc->asoft_info.agpki_presize << 10) & UI32_MASK;
70 (knp++)->value.ui32 = sc->asoft_info.agpki_tdevid;
71 (knp++)->value.ui32 = (sc->asoft_info.agpki_tver.agpv_major<<16) |
72 sc->asoft_info.agpki_tver.agpv_minor;
73 (knp++)->value.ui32 = sc->asoft_info.agpki_tstatus;
74 (knp++)->value.ui64 = sc->asoft_info.agpki_aperbase;
75 (knp++)->value.ui64 =
76 (sc->asoft_info.agpki_apersize << 20) & UI32_MASK;
78 tmp = sc->asoft_agpen;
79 agp_set_char_kstat(knp++, (tmp > 0) ? "yes" : "no");
81 (knp++)->value.ui32 = sc->asoft_mode;
82 (knp++)->value.ui64 = (sc->asoft_pgused << 12) & UI32_MASK;
84 return (0);
87 int
88 agp_init_kstats(agpgart_softstate_t *sc)
90 int instance;
91 kstat_t *ksp;
92 kstat_named_t *knp;
93 char *np;
94 int type;
95 char **aknp;
97 instance = ddi_get_instance(sc->asoft_dip);
98 aknp = agpkstat_name;
99 ksp = kstat_create(AGPGART_DEVNODE, instance, "agpinfo", "agp",
100 KSTAT_TYPE_NAMED, sizeof (agpkstat_name)/sizeof (char *) - 1,
101 KSTAT_FLAG_PERSISTENT);
102 if (ksp == NULL)
103 return (0);
105 ksp->ks_private = sc;
106 ksp->ks_update = agp_kstat_update;
107 for (knp = ksp->ks_data; (np = (*aknp)) != NULL; knp++, aknp++) {
108 switch (*np) {
109 case '$':
110 np += 1;
111 type = KSTAT_DATA_UINT64;
112 break;
113 case '&':
114 np += 1;
115 type = KSTAT_DATA_CHAR;
116 break;
117 default:
118 type = KSTAT_DATA_UINT32;
119 break;
122 kstat_named_init(knp, np, type);
124 kstat_install(ksp);
126 sc->asoft_ksp = ksp;
128 return (0);
131 void
132 agp_fini_kstats(agpgart_softstate_t *sc)
134 ASSERT(sc->asoft_ksp);
135 kstat_delete(sc->asoft_ksp);