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