xref: /titanic_41/usr/src/uts/sun4/sys/trapstat.h (revision 70025d765b044c6d8594bb965a2247a61e991a99)
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 #ifndef _ASM
111 
112 typedef struct tstat_tlbretent {
113 	uint32_t	ttlbrent_instr[TSTAT_TLBRET_NINSTR];
114 } tstat_tlbretent_t;
115 
116 typedef struct tstat_tlbret {
117 	tstat_tlbretent_t	ttlbr_ktlb;
118 	tstat_tlbretent_t	ttlbr_ktsb;
119 	tstat_tlbretent_t	ttlbr_utlb;
120 	tstat_tlbretent_t	ttlbr_utsb;
121 } tstat_tlbret_t;
122 
123 typedef struct tstat_instr {
124 	uint32_t	tinst_traptab[TSTAT_TOTAL_NENT * TSTAT_ENT_NINSTR];
125 	tstat_tlbret_t	tinst_itlbret;
126 	tstat_tlbret_t	tinst_dtlbret;
127 } tstat_instr_t;
128 
129 typedef struct tstat_tsbmiss_patch_entry {
130 	uint32_t *tpe_addr;
131 	uint32_t tpe_instr;
132 } tstat_tsbmiss_patch_entry_t;
133 
134 #endif
135 
136 #ifdef sun4v
137 #if (NCPU > 128)
138 #error "sun4v trapstat supports upto 128 cpus"
139 #endif
140 #define	TSTAT_TLB_STATS		0x1		/* cpu_tstat_flags */
141 #define	TSTAT_INSTR_SIZE	(sizeof (tstat_instr_t))
142 #define	TSTAT_TBA_MASK		~((1 << 15) - 1)	/* 32K per cpu */
143 #else /* sun4v */
144 #define	TSTAT_INSTR_PAGES	((sizeof (tstat_instr_t) >> MMU_PAGESHIFT) + 1)
145 #define	TSTAT_INSTR_SIZE	(TSTAT_INSTR_PAGES * MMU_PAGESIZE)
146 #define	TSTAT_TBA_MASK		~((1 << 16) - 1)	/* 64K per cpu */
147 #endif /* sun4v */
148 
149 #define	TSTAT_DATA_OFFS(tcpu, mem)	\
150 	((uintptr_t)(tcpu)->tcpu_dbase + offsetof(tstat_data_t, mem))
151 #define	TSTAT_INSTR_OFFS(tcpu, mem)	\
152 	((uintptr_t)(tcpu)->tcpu_ibase + offsetof(tstat_instr_t, mem))
153 
154 #define	TSTAT_CPU_SELECTED	0x0001
155 #define	TSTAT_CPU_ALLOCATED	0x0002
156 #define	TSTAT_CPU_ENABLED	0x0004
157 
158 #define	TSTAT_OPT_CPU		0x0001
159 #define	TSTAT_OPT_NOGO		0x0002
160 #define	TSTAT_OPT_TLBDATA	0x0004
161 #define	TSTAT_OPT_ENTRY		0x0008
162 
163 #define	TSTAT_TSBMISS_INSTR	0x8e01e000	/* add %g7, 0, %g7 */
164 
165 #ifndef _ASM
166 
167 typedef struct tstat_percpu {
168 	uint32_t	tcpu_flags;
169 	caddr_t		tcpu_tba;
170 	caddr_t		tcpu_vabase;
171 	caddr_t		tcpu_ibase;
172 	caddr_t		tcpu_dbase;
173 	pfn_t		*tcpu_pfn;
174 	tstat_instr_t	*tcpu_instr;
175 	tstat_data_t	*tcpu_data;
176 } tstat_percpu_t;
177 
178 #endif
179 
180 #endif
181 #ifdef	__cplusplus
182 }
183 #endif
184 
185 #endif	/* _SYS_TRAPSTAT_H */
186