xref: /titanic_50/usr/src/uts/sun4/sys/trapstat.h (revision 672986541be54a7a471bb088e60780c37e371d7e)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_TRAPSTAT_H
28 #define	_SYS_TRAPSTAT_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifndef _ASM
33 #include <sys/processor.h>
34 #endif
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #define	TSTATIOC	(('t' << 16) | ('s' << 8))
41 
42 #define	TSTATIOC_READ		(TSTATIOC | 1)
43 #define	TSTATIOC_GO		(TSTATIOC | 2)
44 #define	TSTATIOC_NOGO		(TSTATIOC | 3)
45 #define	TSTATIOC_STOP		(TSTATIOC | 4)
46 #define	TSTATIOC_CPU		(TSTATIOC | 5)
47 #define	TSTATIOC_NOCPU		(TSTATIOC | 6)
48 #define	TSTATIOC_ENTRY		(TSTATIOC | 7)
49 #define	TSTATIOC_NOENTRY	(TSTATIOC | 8)
50 #define	TSTATIOC_TLBDATA	(TSTATIOC | 9)
51 
52 #define	TSTAT_NENT		512
53 
54 #ifndef _ASM
55 
56 /*
57  * tstat_missdata_t must be of size 2^n, for some value of n.  This allows
58  * tstat_tlbdata_t to be of size 2^(n+2), and tstat_pgszdata_t to be of
59  * size 2^(n+3) -- a constraint which greatly simplifies the TLB return
60  * entry.
61  */
62 typedef struct tstat_missdata {
63 	uint64_t	tmiss_count;
64 	hrtime_t	tmiss_time;
65 } tstat_missdata_t;
66 
67 typedef struct tstat_tlbdata {
68 	tstat_missdata_t	ttlb_tlb;
69 	tstat_missdata_t	ttlb_tsb;
70 } tstat_tlbdata_t;
71 
72 typedef struct tstat_modedata {
73 	tstat_tlbdata_t		tmode_itlb;
74 	tstat_tlbdata_t		tmode_dtlb;
75 } tstat_modedata_t;
76 
77 typedef struct tstat_pgszdata {
78 	tstat_modedata_t	tpgsz_user;
79 	tstat_modedata_t	tpgsz_kernel;
80 } tstat_pgszdata_t;
81 
82 typedef struct tstat_data {
83 	processorid_t	tdata_cpuid;
84 	hrtime_t	tdata_snapts;
85 	hrtime_t	tdata_snaptick;
86 	hrtime_t	tdata_tmptick;
87 	hrtime_t	tdata_peffect;
88 	uint64_t	tdata_traps[TSTAT_NENT];
89 	tstat_pgszdata_t tdata_pgsz[1];
90 } tstat_data_t;
91 
92 #endif
93 
94 #ifdef _KERNEL
95 
96 #define	TSTAT_TLGT0_NENT	256
97 #define	TSTAT_TOTAL_NENT	(TSTAT_NENT + TSTAT_TLGT0_NENT)
98 
99 #define	TSTAT_ENT_NINSTR	8		/* 8 instructions/entry */
100 #define	TSTAT_ENT_SHIFT		5		/* 32 bytes/entry */
101 #define	TSTAT_ENT_ITLBMISS	0x64
102 #define	TSTAT_ENT_DTLBMISS	0x68
103 
104 #define	TSTAT_TLBRET_NINSTR	32
105 
106 #define	TSTAT_PROBE_NPAGES	2048
107 #define	TSTAT_PROBE_SIZE	(TSTAT_PROBE_NPAGES * MMU_PAGESIZE)
108 #define	TSTAT_PROBE_NLAPS	10
109 
110 #ifdef sun4v
111 #define	TSTAT_TLBENT_NINSTR	32
112 #define	TSTAT_ENT_IMMUMISS	0x09
113 #define	TSTAT_ENT_DMMUMISS	0x31
114 #endif
115 
116 #ifndef _ASM
117 
118 typedef struct tstat_tlbretent {
119 	uint32_t	ttlbrent_instr[TSTAT_TLBRET_NINSTR];
120 } tstat_tlbretent_t;
121 
122 #ifdef sun4v
123 typedef struct tstat_tlbent {
124 	uint32_t	ttlbent_instr[TSTAT_TLBENT_NINSTR];
125 } tstat_tlbent_t;
126 #endif /* sun4v */
127 
128 
129 typedef struct tstat_tlbret {
130 	tstat_tlbretent_t	ttlbr_ktlb;
131 	tstat_tlbretent_t	ttlbr_ktsb;
132 	tstat_tlbretent_t	ttlbr_utlb;
133 	tstat_tlbretent_t	ttlbr_utsb;
134 } tstat_tlbret_t;
135 
136 typedef struct tstat_instr {
137 	uint32_t	tinst_traptab[TSTAT_TOTAL_NENT * TSTAT_ENT_NINSTR];
138 	tstat_tlbret_t	tinst_itlbret;
139 	tstat_tlbret_t	tinst_dtlbret;
140 #ifdef sun4v
141 	tstat_tlbent_t	tinst_immumiss;
142 	tstat_tlbent_t	tinst_dmmumiss;
143 #endif
144 } tstat_instr_t;
145 
146 typedef struct tstat_tsbmiss_patch_entry {
147 	uint32_t *tpe_addr;
148 	uint32_t tpe_instr;
149 } tstat_tsbmiss_patch_entry_t;
150 
151 #endif
152 
153 #ifdef sun4v
154 #if (NCPU > 128)
155 #error "sun4v trapstat supports upto 128 cpus"
156 #endif
157 #define	TSTAT_TLB_STATS		0x1		/* cpu_tstat_flags */
158 #define	TSTAT_INSTR_SIZE	(sizeof (tstat_instr_t))
159 #define	TSTAT_TBA_MASK		~((1 << 15) - 1)	/* 32K per cpu */
160 #else /* sun4v */
161 #define	TSTAT_INSTR_PAGES	((sizeof (tstat_instr_t) >> MMU_PAGESHIFT) + 1)
162 #define	TSTAT_INSTR_SIZE	(TSTAT_INSTR_PAGES * MMU_PAGESIZE)
163 #define	TSTAT_TBA_MASK		~((1 << 16) - 1)	/* 64K per cpu */
164 #endif /* sun4v */
165 
166 #define	TSTAT_DATA_OFFS(tcpu, mem)	\
167 	((uintptr_t)(tcpu)->tcpu_dbase + offsetof(tstat_data_t, mem))
168 #define	TSTAT_INSTR_OFFS(tcpu, mem)	\
169 	((uintptr_t)(tcpu)->tcpu_ibase + offsetof(tstat_instr_t, mem))
170 
171 #define	TSTAT_CPU_SELECTED	0x0001
172 #define	TSTAT_CPU_ALLOCATED	0x0002
173 #define	TSTAT_CPU_ENABLED	0x0004
174 
175 #define	TSTAT_OPT_CPU		0x0001
176 #define	TSTAT_OPT_NOGO		0x0002
177 #define	TSTAT_OPT_TLBDATA	0x0004
178 #define	TSTAT_OPT_ENTRY		0x0008
179 
180 #define	TSTAT_TSBMISS_INSTR	0x8e01e000	/* add %g7, 0, %g7 */
181 
182 #ifndef _ASM
183 
184 typedef struct tstat_percpu {
185 	uint32_t	tcpu_flags;
186 	caddr_t		tcpu_tba;
187 	caddr_t		tcpu_vabase;
188 	caddr_t		tcpu_ibase;
189 	caddr_t		tcpu_dbase;
190 	pfn_t		*tcpu_pfn;
191 	tstat_instr_t	*tcpu_instr;
192 	tstat_data_t	*tcpu_data;
193 } tstat_percpu_t;
194 
195 #endif
196 
197 #endif
198 #ifdef	__cplusplus
199 }
200 #endif
201 
202 #endif	/* _SYS_TRAPSTAT_H */
203