xref: /titanic_53/usr/src/uts/sun4/sys/trapstat.h (revision ce0352eb406e3bc76c5885dfb72e99d53bdb985d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #ifndef _SYS_TRAPSTAT_H
287c478bd9Sstevel@tonic-gate #define	_SYS_TRAPSTAT_H
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifndef _ASM
337c478bd9Sstevel@tonic-gate #include <sys/processor.h>
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
377c478bd9Sstevel@tonic-gate extern "C" {
387c478bd9Sstevel@tonic-gate #endif
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #define	TSTATIOC	(('t' << 16) | ('s' << 8))
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #define	TSTATIOC_READ		(TSTATIOC | 1)
437c478bd9Sstevel@tonic-gate #define	TSTATIOC_GO		(TSTATIOC | 2)
447c478bd9Sstevel@tonic-gate #define	TSTATIOC_NOGO		(TSTATIOC | 3)
457c478bd9Sstevel@tonic-gate #define	TSTATIOC_STOP		(TSTATIOC | 4)
467c478bd9Sstevel@tonic-gate #define	TSTATIOC_CPU		(TSTATIOC | 5)
477c478bd9Sstevel@tonic-gate #define	TSTATIOC_NOCPU		(TSTATIOC | 6)
487c478bd9Sstevel@tonic-gate #define	TSTATIOC_ENTRY		(TSTATIOC | 7)
497c478bd9Sstevel@tonic-gate #define	TSTATIOC_NOENTRY	(TSTATIOC | 8)
507c478bd9Sstevel@tonic-gate #define	TSTATIOC_TLBDATA	(TSTATIOC | 9)
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate #define	TSTAT_NENT		512
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #ifndef _ASM
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * tstat_missdata_t must be of size 2^n, for some value of n.  This allows
587c478bd9Sstevel@tonic-gate  * tstat_tlbdata_t to be of size 2^(n+2), and tstat_pgszdata_t to be of
597c478bd9Sstevel@tonic-gate  * size 2^(n+3) -- a constraint which greatly simplifies the TLB return
607c478bd9Sstevel@tonic-gate  * entry.
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate typedef struct tstat_missdata {
637c478bd9Sstevel@tonic-gate 	uint64_t	tmiss_count;
647c478bd9Sstevel@tonic-gate 	hrtime_t	tmiss_time;
657c478bd9Sstevel@tonic-gate } tstat_missdata_t;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate typedef struct tstat_tlbdata {
687c478bd9Sstevel@tonic-gate 	tstat_missdata_t	ttlb_tlb;
697c478bd9Sstevel@tonic-gate 	tstat_missdata_t	ttlb_tsb;
707c478bd9Sstevel@tonic-gate } tstat_tlbdata_t;
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate typedef struct tstat_modedata {
737c478bd9Sstevel@tonic-gate 	tstat_tlbdata_t		tmode_itlb;
747c478bd9Sstevel@tonic-gate 	tstat_tlbdata_t		tmode_dtlb;
757c478bd9Sstevel@tonic-gate } tstat_modedata_t;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate typedef struct tstat_pgszdata {
787c478bd9Sstevel@tonic-gate 	tstat_modedata_t	tpgsz_user;
797c478bd9Sstevel@tonic-gate 	tstat_modedata_t	tpgsz_kernel;
807c478bd9Sstevel@tonic-gate } tstat_pgszdata_t;
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate typedef struct tstat_data {
837c478bd9Sstevel@tonic-gate 	processorid_t	tdata_cpuid;
847c478bd9Sstevel@tonic-gate 	hrtime_t	tdata_snapts;
857c478bd9Sstevel@tonic-gate 	hrtime_t	tdata_snaptick;
867c478bd9Sstevel@tonic-gate 	hrtime_t	tdata_tmptick;
877c478bd9Sstevel@tonic-gate 	hrtime_t	tdata_peffect;
887c478bd9Sstevel@tonic-gate 	uint64_t	tdata_traps[TSTAT_NENT];
897c478bd9Sstevel@tonic-gate 	tstat_pgszdata_t tdata_pgsz[1];
907c478bd9Sstevel@tonic-gate } tstat_data_t;
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate #endif
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate #ifdef _KERNEL
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate #define	TSTAT_TLGT0_NENT	256
977c478bd9Sstevel@tonic-gate #define	TSTAT_TOTAL_NENT	(TSTAT_NENT + TSTAT_TLGT0_NENT)
987c478bd9Sstevel@tonic-gate 
997c478bd9Sstevel@tonic-gate #define	TSTAT_ENT_NINSTR	8		/* 8 instructions/entry */
1007c478bd9Sstevel@tonic-gate #define	TSTAT_ENT_SHIFT		5		/* 32 bytes/entry */
1017c478bd9Sstevel@tonic-gate #define	TSTAT_ENT_ITLBMISS	0x64
1027c478bd9Sstevel@tonic-gate #define	TSTAT_ENT_DTLBMISS	0x68
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate #define	TSTAT_TLBRET_NINSTR	32
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate #define	TSTAT_PROBE_NPAGES	2048
1077c478bd9Sstevel@tonic-gate #define	TSTAT_PROBE_SIZE	(TSTAT_PROBE_NPAGES * MMU_PAGESIZE)
1087c478bd9Sstevel@tonic-gate #define	TSTAT_PROBE_NLAPS	10
1097c478bd9Sstevel@tonic-gate 
110*ce0352ebSgirish #ifdef sun4v
111*ce0352ebSgirish #define	TSTAT_TLBENT_NINSTR	32
112*ce0352ebSgirish #define	TSTAT_ENT_IMMUMISS	0x09
113*ce0352ebSgirish #define	TSTAT_ENT_DMMUMISS	0x31
114*ce0352ebSgirish #endif
115*ce0352ebSgirish 
1167c478bd9Sstevel@tonic-gate #ifndef _ASM
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate typedef struct tstat_tlbretent {
1197c478bd9Sstevel@tonic-gate 	uint32_t	ttlbrent_instr[TSTAT_TLBRET_NINSTR];
1207c478bd9Sstevel@tonic-gate } tstat_tlbretent_t;
1217c478bd9Sstevel@tonic-gate 
122*ce0352ebSgirish #ifdef sun4v
123*ce0352ebSgirish typedef struct tstat_tlbent {
124*ce0352ebSgirish 	uint32_t	ttlbent_instr[TSTAT_TLBENT_NINSTR];
125*ce0352ebSgirish } tstat_tlbent_t;
126*ce0352ebSgirish #endif /* sun4v */
127*ce0352ebSgirish 
128*ce0352ebSgirish 
1297c478bd9Sstevel@tonic-gate typedef struct tstat_tlbret {
1307c478bd9Sstevel@tonic-gate 	tstat_tlbretent_t	ttlbr_ktlb;
1317c478bd9Sstevel@tonic-gate 	tstat_tlbretent_t	ttlbr_ktsb;
1327c478bd9Sstevel@tonic-gate 	tstat_tlbretent_t	ttlbr_utlb;
1337c478bd9Sstevel@tonic-gate 	tstat_tlbretent_t	ttlbr_utsb;
1347c478bd9Sstevel@tonic-gate } tstat_tlbret_t;
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate typedef struct tstat_instr {
1377c478bd9Sstevel@tonic-gate 	uint32_t	tinst_traptab[TSTAT_TOTAL_NENT * TSTAT_ENT_NINSTR];
1387c478bd9Sstevel@tonic-gate 	tstat_tlbret_t	tinst_itlbret;
1397c478bd9Sstevel@tonic-gate 	tstat_tlbret_t	tinst_dtlbret;
140*ce0352ebSgirish #ifdef sun4v
141*ce0352ebSgirish 	tstat_tlbent_t	tinst_immumiss;
142*ce0352ebSgirish 	tstat_tlbent_t	tinst_dmmumiss;
143*ce0352ebSgirish #endif
1447c478bd9Sstevel@tonic-gate } tstat_instr_t;
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate typedef struct tstat_tsbmiss_patch_entry {
1477c478bd9Sstevel@tonic-gate 	uint32_t *tpe_addr;
1487c478bd9Sstevel@tonic-gate 	uint32_t tpe_instr;
1497c478bd9Sstevel@tonic-gate } tstat_tsbmiss_patch_entry_t;
1507c478bd9Sstevel@tonic-gate 
1517c478bd9Sstevel@tonic-gate #endif
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate #ifdef sun4v
1547c478bd9Sstevel@tonic-gate #if (NCPU > 128)
1557c478bd9Sstevel@tonic-gate #error "sun4v trapstat supports upto 128 cpus"
1567c478bd9Sstevel@tonic-gate #endif
1577c478bd9Sstevel@tonic-gate #define	TSTAT_TLB_STATS		0x1		/* cpu_tstat_flags */
1587c478bd9Sstevel@tonic-gate #define	TSTAT_INSTR_SIZE	(sizeof (tstat_instr_t))
1597c478bd9Sstevel@tonic-gate #define	TSTAT_TBA_MASK		~((1 << 15) - 1)	/* 32K per cpu */
1607c478bd9Sstevel@tonic-gate #else /* sun4v */
1617c478bd9Sstevel@tonic-gate #define	TSTAT_INSTR_PAGES	((sizeof (tstat_instr_t) >> MMU_PAGESHIFT) + 1)
1627c478bd9Sstevel@tonic-gate #define	TSTAT_INSTR_SIZE	(TSTAT_INSTR_PAGES * MMU_PAGESIZE)
1637c478bd9Sstevel@tonic-gate #define	TSTAT_TBA_MASK		~((1 << 16) - 1)	/* 64K per cpu */
1647c478bd9Sstevel@tonic-gate #endif /* sun4v */
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate #define	TSTAT_DATA_OFFS(tcpu, mem)	\
1677c478bd9Sstevel@tonic-gate 	((uintptr_t)(tcpu)->tcpu_dbase + offsetof(tstat_data_t, mem))
1687c478bd9Sstevel@tonic-gate #define	TSTAT_INSTR_OFFS(tcpu, mem)	\
1697c478bd9Sstevel@tonic-gate 	((uintptr_t)(tcpu)->tcpu_ibase + offsetof(tstat_instr_t, mem))
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate #define	TSTAT_CPU_SELECTED	0x0001
1727c478bd9Sstevel@tonic-gate #define	TSTAT_CPU_ALLOCATED	0x0002
1737c478bd9Sstevel@tonic-gate #define	TSTAT_CPU_ENABLED	0x0004
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate #define	TSTAT_OPT_CPU		0x0001
1767c478bd9Sstevel@tonic-gate #define	TSTAT_OPT_NOGO		0x0002
1777c478bd9Sstevel@tonic-gate #define	TSTAT_OPT_TLBDATA	0x0004
1787c478bd9Sstevel@tonic-gate #define	TSTAT_OPT_ENTRY		0x0008
1797c478bd9Sstevel@tonic-gate 
1807c478bd9Sstevel@tonic-gate #define	TSTAT_TSBMISS_INSTR	0x8e01e000	/* add %g7, 0, %g7 */
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate #ifndef _ASM
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate typedef struct tstat_percpu {
1857c478bd9Sstevel@tonic-gate 	uint32_t	tcpu_flags;
1867c478bd9Sstevel@tonic-gate 	caddr_t		tcpu_tba;
1877c478bd9Sstevel@tonic-gate 	caddr_t		tcpu_vabase;
1887c478bd9Sstevel@tonic-gate 	caddr_t		tcpu_ibase;
1897c478bd9Sstevel@tonic-gate 	caddr_t		tcpu_dbase;
1907c478bd9Sstevel@tonic-gate 	pfn_t		*tcpu_pfn;
1917c478bd9Sstevel@tonic-gate 	tstat_instr_t	*tcpu_instr;
1927c478bd9Sstevel@tonic-gate 	tstat_data_t	*tcpu_data;
1937c478bd9Sstevel@tonic-gate } tstat_percpu_t;
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate #endif
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate #endif
1987c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1997c478bd9Sstevel@tonic-gate }
2007c478bd9Sstevel@tonic-gate #endif
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate #endif	/* _SYS_TRAPSTAT_H */
203