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