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 5*59ac0c16Sdavemq * Common Development and Distribution License (the "License"). 6*59ac0c16Sdavemq * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*59ac0c16Sdavemq * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #ifndef _SYS_TRAPSTAT_H 277c478bd9Sstevel@tonic-gate #define _SYS_TRAPSTAT_H 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifndef _ASM 327c478bd9Sstevel@tonic-gate #include <sys/processor.h> 337c478bd9Sstevel@tonic-gate #endif 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #ifdef __cplusplus 367c478bd9Sstevel@tonic-gate extern "C" { 377c478bd9Sstevel@tonic-gate #endif 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #define TSTATIOC (('t' << 16) | ('s' << 8)) 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate #define TSTATIOC_READ (TSTATIOC | 1) 427c478bd9Sstevel@tonic-gate #define TSTATIOC_GO (TSTATIOC | 2) 437c478bd9Sstevel@tonic-gate #define TSTATIOC_NOGO (TSTATIOC | 3) 447c478bd9Sstevel@tonic-gate #define TSTATIOC_STOP (TSTATIOC | 4) 457c478bd9Sstevel@tonic-gate #define TSTATIOC_CPU (TSTATIOC | 5) 467c478bd9Sstevel@tonic-gate #define TSTATIOC_NOCPU (TSTATIOC | 6) 477c478bd9Sstevel@tonic-gate #define TSTATIOC_ENTRY (TSTATIOC | 7) 487c478bd9Sstevel@tonic-gate #define TSTATIOC_NOENTRY (TSTATIOC | 8) 497c478bd9Sstevel@tonic-gate #define TSTATIOC_TLBDATA (TSTATIOC | 9) 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #define TSTAT_NENT 512 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate #ifndef _ASM 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * tstat_missdata_t must be of size 2^n, for some value of n. This allows 577c478bd9Sstevel@tonic-gate * tstat_tlbdata_t to be of size 2^(n+2), and tstat_pgszdata_t to be of 587c478bd9Sstevel@tonic-gate * size 2^(n+3) -- a constraint which greatly simplifies the TLB return 597c478bd9Sstevel@tonic-gate * entry. 607c478bd9Sstevel@tonic-gate */ 617c478bd9Sstevel@tonic-gate typedef struct tstat_missdata { 627c478bd9Sstevel@tonic-gate uint64_t tmiss_count; 637c478bd9Sstevel@tonic-gate hrtime_t tmiss_time; 647c478bd9Sstevel@tonic-gate } tstat_missdata_t; 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate typedef struct tstat_tlbdata { 677c478bd9Sstevel@tonic-gate tstat_missdata_t ttlb_tlb; 687c478bd9Sstevel@tonic-gate tstat_missdata_t ttlb_tsb; 697c478bd9Sstevel@tonic-gate } tstat_tlbdata_t; 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate typedef struct tstat_modedata { 727c478bd9Sstevel@tonic-gate tstat_tlbdata_t tmode_itlb; 737c478bd9Sstevel@tonic-gate tstat_tlbdata_t tmode_dtlb; 747c478bd9Sstevel@tonic-gate } tstat_modedata_t; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate typedef struct tstat_pgszdata { 777c478bd9Sstevel@tonic-gate tstat_modedata_t tpgsz_user; 787c478bd9Sstevel@tonic-gate tstat_modedata_t tpgsz_kernel; 797c478bd9Sstevel@tonic-gate } tstat_pgszdata_t; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate typedef struct tstat_data { 827c478bd9Sstevel@tonic-gate processorid_t tdata_cpuid; 837c478bd9Sstevel@tonic-gate hrtime_t tdata_snapts; 847c478bd9Sstevel@tonic-gate hrtime_t tdata_snaptick; 857c478bd9Sstevel@tonic-gate hrtime_t tdata_tmptick; 867c478bd9Sstevel@tonic-gate hrtime_t tdata_peffect; 877c478bd9Sstevel@tonic-gate uint64_t tdata_traps[TSTAT_NENT]; 887c478bd9Sstevel@tonic-gate tstat_pgszdata_t tdata_pgsz[1]; 897c478bd9Sstevel@tonic-gate } tstat_data_t; 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate #endif 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate #ifdef _KERNEL 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate #define TSTAT_TLGT0_NENT 256 967c478bd9Sstevel@tonic-gate #define TSTAT_TOTAL_NENT (TSTAT_NENT + TSTAT_TLGT0_NENT) 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate #define TSTAT_ENT_NINSTR 8 /* 8 instructions/entry */ 997c478bd9Sstevel@tonic-gate #define TSTAT_ENT_SHIFT 5 /* 32 bytes/entry */ 1007c478bd9Sstevel@tonic-gate #define TSTAT_ENT_ITLBMISS 0x64 1017c478bd9Sstevel@tonic-gate #define TSTAT_ENT_DTLBMISS 0x68 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate #define TSTAT_TLBRET_NINSTR 32 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate #define TSTAT_PROBE_NPAGES 2048 1067c478bd9Sstevel@tonic-gate #define TSTAT_PROBE_SIZE (TSTAT_PROBE_NPAGES * MMU_PAGESIZE) 1077c478bd9Sstevel@tonic-gate #define TSTAT_PROBE_NLAPS 10 1087c478bd9Sstevel@tonic-gate 109ce0352ebSgirish #ifdef sun4v 110*59ac0c16Sdavemq #define TSTAT_TRAPCNT_NINSTR 8 111*59ac0c16Sdavemq #define TSTAT_TLBENT_NINSTR 64 112ce0352ebSgirish #define TSTAT_ENT_IMMUMISS 0x09 113ce0352ebSgirish #define TSTAT_ENT_DMMUMISS 0x31 114ce0352ebSgirish #endif 115ce0352ebSgirish 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 122ce0352ebSgirish #ifdef sun4v 123ce0352ebSgirish typedef struct tstat_tlbent { 124ce0352ebSgirish uint32_t ttlbent_instr[TSTAT_TLBENT_NINSTR]; 125ce0352ebSgirish } tstat_tlbent_t; 126ce0352ebSgirish #endif /* sun4v */ 127ce0352ebSgirish 128ce0352ebSgirish 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; 140ce0352ebSgirish #ifdef sun4v 141ce0352ebSgirish tstat_tlbent_t tinst_immumiss; 142ce0352ebSgirish tstat_tlbent_t tinst_dmmumiss; 143*59ac0c16Sdavemq uint32_t tinst_trapcnt[TSTAT_TRAPCNT_NINSTR]; 144ce0352ebSgirish #endif 1457c478bd9Sstevel@tonic-gate } tstat_instr_t; 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate typedef struct tstat_tsbmiss_patch_entry { 1487c478bd9Sstevel@tonic-gate uint32_t *tpe_addr; 1497c478bd9Sstevel@tonic-gate uint32_t tpe_instr; 1507c478bd9Sstevel@tonic-gate } tstat_tsbmiss_patch_entry_t; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate #endif 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate #ifdef sun4v 155*59ac0c16Sdavemq 156*59ac0c16Sdavemq #if (NCPU > 508) 157*59ac0c16Sdavemq #error "sun4v trapstat supports up to 508 cpus" 1587c478bd9Sstevel@tonic-gate #endif 159*59ac0c16Sdavemq 1607c478bd9Sstevel@tonic-gate #define TSTAT_TLB_STATS 0x1 /* cpu_tstat_flags */ 161*59ac0c16Sdavemq #define TSTAT_INSTR_SIZE \ 162*59ac0c16Sdavemq ((sizeof (tstat_instr_t) + MMU_PAGESIZE - 1) & ~(MMU_PAGESIZE - 1)) 163*59ac0c16Sdavemq #define TSTAT_DATA_SHIFT 13 164*59ac0c16Sdavemq #define TSTAT_DATA_SIZE (1 << TSTAT_DATA_SHIFT) /* 8K per CPU */ 165*59ac0c16Sdavemq #define TSTAT_TBA_MASK ~((1 << 15) - 1) /* 32K boundary */ 166*59ac0c16Sdavemq 167*59ac0c16Sdavemq #define TSTAT_CPU0_DATA_OFFS(tcpu, mem) \ 168*59ac0c16Sdavemq ((uintptr_t)(tcpu)->tcpu_ibase + TSTAT_INSTR_SIZE + \ 169*59ac0c16Sdavemq offsetof(tstat_data_t, mem)) 170*59ac0c16Sdavemq 1717c478bd9Sstevel@tonic-gate #else /* sun4v */ 172*59ac0c16Sdavemq 1737c478bd9Sstevel@tonic-gate #define TSTAT_INSTR_PAGES ((sizeof (tstat_instr_t) >> MMU_PAGESHIFT) + 1) 1747c478bd9Sstevel@tonic-gate #define TSTAT_INSTR_SIZE (TSTAT_INSTR_PAGES * MMU_PAGESIZE) 1757c478bd9Sstevel@tonic-gate #define TSTAT_TBA_MASK ~((1 << 16) - 1) /* 64K per cpu */ 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate #define TSTAT_DATA_OFFS(tcpu, mem) \ 1787c478bd9Sstevel@tonic-gate ((uintptr_t)(tcpu)->tcpu_dbase + offsetof(tstat_data_t, mem)) 179*59ac0c16Sdavemq 180*59ac0c16Sdavemq #endif /* sun4v */ 181*59ac0c16Sdavemq 1827c478bd9Sstevel@tonic-gate #define TSTAT_INSTR_OFFS(tcpu, mem) \ 1837c478bd9Sstevel@tonic-gate ((uintptr_t)(tcpu)->tcpu_ibase + offsetof(tstat_instr_t, mem)) 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate #define TSTAT_CPU_SELECTED 0x0001 1867c478bd9Sstevel@tonic-gate #define TSTAT_CPU_ALLOCATED 0x0002 1877c478bd9Sstevel@tonic-gate #define TSTAT_CPU_ENABLED 0x0004 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate #define TSTAT_OPT_CPU 0x0001 1907c478bd9Sstevel@tonic-gate #define TSTAT_OPT_NOGO 0x0002 1917c478bd9Sstevel@tonic-gate #define TSTAT_OPT_TLBDATA 0x0004 1927c478bd9Sstevel@tonic-gate #define TSTAT_OPT_ENTRY 0x0008 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate #define TSTAT_TSBMISS_INSTR 0x8e01e000 /* add %g7, 0, %g7 */ 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate #ifndef _ASM 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate typedef struct tstat_percpu { 1997c478bd9Sstevel@tonic-gate uint32_t tcpu_flags; 2007c478bd9Sstevel@tonic-gate caddr_t tcpu_tba; 2017c478bd9Sstevel@tonic-gate caddr_t tcpu_vabase; 2027c478bd9Sstevel@tonic-gate caddr_t tcpu_ibase; 2037c478bd9Sstevel@tonic-gate caddr_t tcpu_dbase; 2047c478bd9Sstevel@tonic-gate pfn_t *tcpu_pfn; 2057c478bd9Sstevel@tonic-gate tstat_instr_t *tcpu_instr; 2067c478bd9Sstevel@tonic-gate tstat_data_t *tcpu_data; 2077c478bd9Sstevel@tonic-gate } tstat_percpu_t; 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate #endif 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate #endif 2127c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2137c478bd9Sstevel@tonic-gate } 2147c478bd9Sstevel@tonic-gate #endif 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate #endif /* _SYS_TRAPSTAT_H */ 217