xref: /titanic_41/usr/src/uts/sun4v/io/iospc/iospc.h (revision abc79d9dd51e98eafb6fc25b4a0b4f66bef40b00)
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 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_IOSPC_H
28 #define	_IOSPC_H
29 
30 /*
31  * Definitions which deal with things other than registers.
32  */
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #include <sys/sunddi.h>
39 
40 #define	SUCCESS	0
41 #define	FAILURE	-1
42 
43 #define	NAMEINST(dip)	ddi_driver_name(dip), ddi_get_instance(dip)
44 
45 /* Used for data structure retrieval during kstat update. */
46 typedef struct iospc_ksinfo {
47 	kstat_t		*cntr_ksp;
48 	struct iospc	*iospc_p;
49 	struct iospc_grp *grp_p;
50 	void		*arg;
51 } iospc_ksinfo_t;
52 
53 #define	IOSPC_MAX_NUM_GRPS	10
54 
55 /* State structure. */
56 typedef struct iospc {
57 	dev_info_t	*iospc_dip;
58 	iospc_ksinfo_t	*iospc_ksinfo_p[IOSPC_MAX_NUM_GRPS];
59 } iospc_t;
60 
61 /*
62  * Description of a counter's events.  Each counter will have an array of these,
63  * to define the events it can be programmed to report.  Nonprogrammable
64  * counters still need an array of these, to contain the name busstat will
65  * display for it, and a CLEAR_PIC entry.
66  */
67 typedef struct iospc_event {
68 	char *name;
69 	uint64_t value;
70 } iospc_event_t;
71 
72 #define	NUM_EVTS(x)	(sizeof (x) / sizeof (iospc_event_t))
73 
74 /*
75  * Counter description, including its access logistics and how to zero it.
76  */
77 typedef struct iospc_cntr {
78 	off_t regoff;		/* Register offset or address. */
79 	uint64_t fld_mask;	/* Width of the active part of the register */
80 	off_t zero_regoff;	/* Offset of register used to zero counter. */
81 	uint64_t zero_value;	/* Value to write to zero_regoff, to clr cntr */
82 } iospc_cntr_t;
83 
84 #define	FULL64BIT	-1ULL   /* Can use this for fld_mask. */
85 
86 #define	NUM_CTRS(x)	(sizeof (x) / sizeof (iospc_cntr_t))
87 
88 /*
89  * Description of a counter's event selection.  There will be one entry for
90  * each counter in the group.
91  */
92 typedef struct iospc_regsel_fld {
93 	iospc_event_t *events_p;
94 	int num_events;		/* Size of events array. */
95 	uint64_t event_mask;	/* Width of the event field. */
96 	int event_offset;	/* Offset of the event field. */
97 } iospc_regsel_fld_t;
98 
99 /*
100  * Description of a group's select register.
101  */
102 typedef struct iospc_regsel {
103 	off_t regoff;			/* Register offset or address. */
104 	iospc_regsel_fld_t *fields_p;	/* select reg subfield descriptions.  */
105 	int num_fields;			/* Size of the fields array. */
106 } iospc_regsel_t;
107 
108 #define	NUM_FLDS(x)	(sizeof (x) / sizeof (iospc_regsel_fld_t))
109 
110 #define	IOSPC_REG_READ	0
111 #define	IOSPC_REG_WRITE	1
112 
113 /* Standin symbol for when there is no register. */
114 #define	NO_REGISTER	(off_t)-1ULL
115 
116 /*
117  * Group description.
118  */
119 typedef struct iospc_grp {
120 	char *grp_name;		 /* Name, shows up as busstat "module" name. */
121 	iospc_regsel_t *regsel_p; /* Select register. */
122 	iospc_cntr_t *counters_p; /* Counter definitions. */
123 	int num_counters;	 /* Size of the counters array. */
124 	int (*access_init)(iospc_t *iospc_p, iospc_ksinfo_t *ksinfo_p);
125 	int (*access)(iospc_t *iospc_p, void *, int op, int regid,
126 	    uint64_t *data);
127 	int (*access_fini)(iospc_t *iospc_p, iospc_ksinfo_t *ksinfo_p);
128 	kstat_t **name_kstats_pp; /* Named kstats.  One for all instances. */
129 } iospc_grp_t;
130 
131 /* Debugging facility. */
132 #ifdef DEBUG
133 extern int iospc_debug;
134 #define	IOSPC_DBG1 if (iospc_debug >= 1) printf
135 #define	IOSPC_DBG2 if (iospc_debug >= 2) printf
136 #else
137 #define	IOSPC_DBG1 0 &&
138 #define	IOSPC_DBG2 0 &&
139 #endif	/* DEBUG */
140 
141 /* Function definitions exported among different modules. */
142 extern int iospc_kstat_init(void);
143 extern void iospc_kstat_fini(void);
144 extern int iospc_kstat_attach(iospc_t *iospc_p);
145 extern void iospc_kstat_detach(iospc_t *iospc_p);
146 extern iospc_grp_t **rfios_bind_group(void);
147 extern void rfios_unbind_group(void);
148 
149 #ifdef	__cplusplus
150 }
151 #endif
152 
153 #endif	/* _IOSPC_H */
154