10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 70Sstevel@tonic-gate * with the License. 80Sstevel@tonic-gate * 90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate * See the License for the specific language governing permissions 120Sstevel@tonic-gate * and limitations under the License. 130Sstevel@tonic-gate * 140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate * 200Sstevel@tonic-gate * CDDL HEADER END 210Sstevel@tonic-gate */ 220Sstevel@tonic-gate /* 230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate * Use is subject to license terms. 250Sstevel@tonic-gate */ 260Sstevel@tonic-gate 270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <sys/types.h> 300Sstevel@tonic-gate #include <sys/systm.h> 310Sstevel@tonic-gate #include <sys/archsystm.h> 320Sstevel@tonic-gate #include <sys/machparam.h> 330Sstevel@tonic-gate #include <sys/machsystm.h> 340Sstevel@tonic-gate #include <sys/cpu.h> 350Sstevel@tonic-gate #include <sys/elf_SPARC.h> 360Sstevel@tonic-gate #include <vm/hat_sfmmu.h> 370Sstevel@tonic-gate #include <vm/page.h> 380Sstevel@tonic-gate #include <sys/cpuvar.h> 390Sstevel@tonic-gate #include <sys/async.h> 400Sstevel@tonic-gate #include <sys/cmn_err.h> 410Sstevel@tonic-gate #include <sys/debug.h> 420Sstevel@tonic-gate #include <sys/dditypes.h> 430Sstevel@tonic-gate #include <sys/sunddi.h> 440Sstevel@tonic-gate #include <sys/cpu_module.h> 450Sstevel@tonic-gate #include <sys/prom_debug.h> 460Sstevel@tonic-gate #include <sys/vmsystm.h> 470Sstevel@tonic-gate #include <sys/prom_plat.h> 480Sstevel@tonic-gate #include <sys/sysmacros.h> 490Sstevel@tonic-gate #include <sys/intreg.h> 500Sstevel@tonic-gate #include <sys/machtrap.h> 510Sstevel@tonic-gate #include <sys/ontrap.h> 520Sstevel@tonic-gate #include <sys/ivintr.h> 530Sstevel@tonic-gate #include <sys/atomic.h> 540Sstevel@tonic-gate #include <sys/panic.h> 550Sstevel@tonic-gate #include <sys/dtrace.h> 560Sstevel@tonic-gate #include <sys/simulate.h> 570Sstevel@tonic-gate #include <sys/fault.h> 580Sstevel@tonic-gate 590Sstevel@tonic-gate #define S_VAC_SIZE MMU_PAGESIZE /* XXXQ? */ 600Sstevel@tonic-gate 610Sstevel@tonic-gate /* 620Sstevel@tonic-gate * Maximum number of contexts 630Sstevel@tonic-gate */ 640Sstevel@tonic-gate #define MAX_NCTXS (1 << 13) 650Sstevel@tonic-gate 660Sstevel@tonic-gate uint_t root_phys_addr_lo_mask = 0xffffffffU; 670Sstevel@tonic-gate 68303Sgirish #ifdef NIAGARA_CHK_VERSION 690Sstevel@tonic-gate static uint64_t cpu_ver; /* Niagara CPU version reg */ 700Sstevel@tonic-gate 710Sstevel@tonic-gate /* Niagara CPU version register */ 720Sstevel@tonic-gate #define VER_MASK_MAJOR_SHIFT 28 730Sstevel@tonic-gate #define VER_MASK_MAJOR_MASK 0xf 740Sstevel@tonic-gate 750Sstevel@tonic-gate extern uint64_t va_to_pa(void *); 760Sstevel@tonic-gate extern uint64_t ni_getver(); /* HV code to get %hver */ 770Sstevel@tonic-gate extern uint64_t niagara_getver(uint64_t ni_getver_ra, uint64_t *cpu_version); 780Sstevel@tonic-gate 79303Sgirish #endif /* NIAGARA_CHK_VERSION */ 800Sstevel@tonic-gate 810Sstevel@tonic-gate void 820Sstevel@tonic-gate cpu_setup(void) 830Sstevel@tonic-gate { 840Sstevel@tonic-gate extern int at_flags; 850Sstevel@tonic-gate extern int disable_delay_tlb_flush, delay_tlb_flush; 860Sstevel@tonic-gate extern int mmu_exported_pagesize_mask; 870Sstevel@tonic-gate extern int get_cpu_pagesizes(void); 880Sstevel@tonic-gate extern int cpc_has_overflow_intr; 890Sstevel@tonic-gate 900Sstevel@tonic-gate cache |= (CACHE_PTAG | CACHE_IOCOHERENT); 910Sstevel@tonic-gate at_flags = EF_SPARC_SUN_US3 | EF_SPARC_32PLUS | EF_SPARC_SUN_US1; 920Sstevel@tonic-gate 930Sstevel@tonic-gate /* 940Sstevel@tonic-gate * Use the maximum number of contexts available for Spitfire unless 950Sstevel@tonic-gate * it has been tuned for debugging. 960Sstevel@tonic-gate * We are checking against 0 here since this value can be patched 970Sstevel@tonic-gate * while booting. It can not be patched via /etc/system since it 980Sstevel@tonic-gate * will be patched too late and thus cause the system to panic. 990Sstevel@tonic-gate */ 1000Sstevel@tonic-gate if (nctxs == 0) 1010Sstevel@tonic-gate nctxs = MAX_NCTXS; 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate if (use_page_coloring) { 1040Sstevel@tonic-gate do_pg_coloring = 1; 1050Sstevel@tonic-gate if (use_virtual_coloring) 1060Sstevel@tonic-gate do_virtual_coloring = 1; 1070Sstevel@tonic-gate } 1080Sstevel@tonic-gate /* 1090Sstevel@tonic-gate * Initalize supported page sizes information before the PD. 1100Sstevel@tonic-gate * If no information is available, then initialize the 1110Sstevel@tonic-gate * mmu_exported_pagesize_mask to a reasonable value for that processor. 1120Sstevel@tonic-gate */ 1130Sstevel@tonic-gate mmu_exported_pagesize_mask = get_cpu_pagesizes(); 1140Sstevel@tonic-gate if (mmu_exported_pagesize_mask <= 0) { 1150Sstevel@tonic-gate mmu_exported_pagesize_mask = (1 << TTE8K) | (1 << TTE64K) | 1160Sstevel@tonic-gate (1 << TTE4M) | (1 << TTE256M); 1170Sstevel@tonic-gate } 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate /* 1200Sstevel@tonic-gate * Tune pp_slots to use up to 1/8th of the tlb entries. 1210Sstevel@tonic-gate */ 1220Sstevel@tonic-gate pp_slots = MIN(8, MAXPP_SLOTS); 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate /* 1250Sstevel@tonic-gate * Block stores invalidate all pages of the d$ so pagecopy 1260Sstevel@tonic-gate * et. al. do not need virtual translations with virtual 1270Sstevel@tonic-gate * coloring taken into consideration. 1280Sstevel@tonic-gate */ 1290Sstevel@tonic-gate pp_consistent_coloring = 0; 1300Sstevel@tonic-gate isa_list = 1310Sstevel@tonic-gate "sparcv9 sparcv8plus sparcv8 sparcv8-fsmuld sparcv7 " 1320Sstevel@tonic-gate "sparc sparcv9+vis sparcv9+vis2 sparcv8plus+vis sparcv8plus+vis2"; 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate cpu_hwcap_flags |= AV_SPARC_ASI_BLK_INIT; 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate /* 137303Sgirish * Niagara supports a 48-bit subset of the full 64-bit virtual 138303Sgirish * address space. Virtual addresses between 0x0000800000000000 139303Sgirish * and 0xffff.7fff.ffff.ffff inclusive lie within a "VA Hole" 140303Sgirish * and must never be mapped. In addition, software must not use 141303Sgirish * pages within 4GB of the VA hole as instruction pages to 142303Sgirish * avoid problems with prefetching into the VA hole. 1430Sstevel@tonic-gate * 144303Sgirish * VA hole information should be obtained from the machine 145303Sgirish * description. 1460Sstevel@tonic-gate */ 147303Sgirish hole_start = (caddr_t)(0x800000000000ul - (1ul << 32)); 148303Sgirish hole_end = (caddr_t)(0xffff800000000000ul + (1ul << 32)); 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate /* 1510Sstevel@tonic-gate * The kpm mapping window. 1520Sstevel@tonic-gate * kpm_size: 1530Sstevel@tonic-gate * The size of a single kpm range. 1540Sstevel@tonic-gate * The overall size will be: kpm_size * vac_colors. 1550Sstevel@tonic-gate * kpm_vbase: 1560Sstevel@tonic-gate * The virtual start address of the kpm range within the kernel 1570Sstevel@tonic-gate * virtual address space. kpm_vbase has to be kpm_size aligned. 1580Sstevel@tonic-gate */ 1590Sstevel@tonic-gate kpm_size = (size_t)(2ull * 1024 * 1024 * 1024 * 1024); /* 2TB */ 1600Sstevel@tonic-gate kpm_size_shift = 41; 1610Sstevel@tonic-gate kpm_vbase = (caddr_t)0xfffffa0000000000ull; /* 16EB - 6TB */ 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* 1640Sstevel@tonic-gate * The traptrace code uses either %tick or %stick for 1650Sstevel@tonic-gate * timestamping. We have %stick so we can use it. 1660Sstevel@tonic-gate */ 1670Sstevel@tonic-gate traptrace_use_stick = 1; 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate /* 1700Sstevel@tonic-gate * sun4v provides demap_all 1710Sstevel@tonic-gate */ 1720Sstevel@tonic-gate if (!disable_delay_tlb_flush) 1730Sstevel@tonic-gate delay_tlb_flush = 1; 1740Sstevel@tonic-gate /* 1750Sstevel@tonic-gate * Niagara has a performance counter overflow interrupt 1760Sstevel@tonic-gate */ 1770Sstevel@tonic-gate cpc_has_overflow_intr = 1; 1780Sstevel@tonic-gate } 1790Sstevel@tonic-gate 1800Sstevel@tonic-gate #define MB * 1024 * 1024 1810Sstevel@tonic-gate /* 1820Sstevel@tonic-gate * Set the magic constants of the implementation. 1830Sstevel@tonic-gate */ 1840Sstevel@tonic-gate void 1850Sstevel@tonic-gate cpu_fiximp(struct cpu_node *cpunode) 1860Sstevel@tonic-gate { 1870Sstevel@tonic-gate extern int vac_size, vac_shift; 1880Sstevel@tonic-gate extern uint_t vac_mask; 1890Sstevel@tonic-gate int i, a; 1900Sstevel@tonic-gate 1910Sstevel@tonic-gate /* 1920Sstevel@tonic-gate * The assumption here is that fillsysinfo will eventually 1930Sstevel@tonic-gate * have code to fill this info in from the PD. 1940Sstevel@tonic-gate * We hard code this for niagara now. 1950Sstevel@tonic-gate * Once the PD access library is done this code 1960Sstevel@tonic-gate * might need to be changed to get the info from the PD 1970Sstevel@tonic-gate */ 1980Sstevel@tonic-gate if (cpunode->ecache_size == 0) 1990Sstevel@tonic-gate cpunode->ecache_size = 3 MB; 2000Sstevel@tonic-gate if (cpunode->ecache_linesize == 0) 2010Sstevel@tonic-gate cpunode->ecache_linesize = 64; 2020Sstevel@tonic-gate if (cpunode->ecache_associativity == 0) 2030Sstevel@tonic-gate cpunode->ecache_associativity = 12; 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate cpunode->ecache_setsize = 2060Sstevel@tonic-gate cpunode->ecache_size / cpunode->ecache_associativity; 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate if (ecache_setsize == 0) 2090Sstevel@tonic-gate ecache_setsize = cpunode->ecache_setsize; 2100Sstevel@tonic-gate if (ecache_alignsize == 0) 2110Sstevel@tonic-gate ecache_alignsize = cpunode->ecache_linesize; 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate vac_size = S_VAC_SIZE; 2140Sstevel@tonic-gate vac_mask = MMU_PAGEMASK & (vac_size - 1); 2150Sstevel@tonic-gate i = 0; a = vac_size; 2160Sstevel@tonic-gate while (a >>= 1) 2170Sstevel@tonic-gate ++i; 2180Sstevel@tonic-gate vac_shift = i; 2190Sstevel@tonic-gate shm_alignment = vac_size; 2200Sstevel@tonic-gate vac = 0; 2210Sstevel@tonic-gate } 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate static int niagara_cpucnt; 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate void 2260Sstevel@tonic-gate cpu_init_private(struct cpu *cp) 2270Sstevel@tonic-gate { 2280Sstevel@tonic-gate extern int niagara_kstat_init(void); 2290Sstevel@tonic-gate 230303Sgirish #ifdef NIAGARA_CHK_VERSION 231303Sgirish /* 232303Sgirish * Prevent booting on a Niagara 1.x processor as it is no longer 233303Sgirish * supported. 234303Sgirish * 235303Sgirish * This is a temporary hack until everyone has switched to the 236303Sgirish * firmware which prevents booting on a Niagara 1.x processor. 237303Sgirish */ 238303Sgirish if (niagara_getver(va_to_pa((void *)ni_getver), &cpu_ver) == H_EOK && 239303Sgirish ((cpu_ver >> VER_MASK_MAJOR_SHIFT) & VER_MASK_MAJOR_MASK) <= 1) 240303Sgirish cmn_err(CE_PANIC, "CPU%d: Niagara 1.x no longer supported.", 241303Sgirish cp->cpu_id); 242303Sgirish #endif /* NIAGARA_CHK_VERSION */ 243303Sgirish 244220Sesaxe /* 245220Sesaxe * This code change assumes that the virtual cpu ids are identical 246220Sesaxe * to the physical cpu ids which is true for ontario but not for 247220Sesaxe * niagara in general. 248220Sesaxe * This is a temporary fix which will later be modified to obtain 249220Sesaxe * the execution unit sharing information from MD table. 250220Sesaxe */ 251220Sesaxe cp->cpu_m.cpu_ipipe = (id_t)(cp->cpu_id / 4); 252220Sesaxe 2530Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 2540Sstevel@tonic-gate if (niagara_cpucnt++ == 0) { 2550Sstevel@tonic-gate (void) niagara_kstat_init(); 2560Sstevel@tonic-gate } 2570Sstevel@tonic-gate } 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate void 2600Sstevel@tonic-gate cpu_uninit_private(struct cpu *cp) 2610Sstevel@tonic-gate { 2620Sstevel@tonic-gate extern int niagara_kstat_fini(void); 2630Sstevel@tonic-gate 2640Sstevel@tonic-gate ASSERT(MUTEX_HELD(&cpu_lock)); 2650Sstevel@tonic-gate if (--niagara_cpucnt == 0) { 2660Sstevel@tonic-gate (void) niagara_kstat_fini(); 2670Sstevel@tonic-gate } 2680Sstevel@tonic-gate } 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate /* 2710Sstevel@tonic-gate * On Niagara, any flush will cause all preceding stores to be 2720Sstevel@tonic-gate * synchronized wrt the i$, regardless of address or ASI. In fact, 2730Sstevel@tonic-gate * the address is ignored, so we always flush address 0. 2740Sstevel@tonic-gate */ 2750Sstevel@tonic-gate void 2760Sstevel@tonic-gate dtrace_flush_sec(uintptr_t addr) 2770Sstevel@tonic-gate { 2780Sstevel@tonic-gate doflush(0); 2790Sstevel@tonic-gate } 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate #define IS_FLOAT(i) (((i) & 0x1000000) != 0) 2820Sstevel@tonic-gate #define IS_IBIT_SET(x) (x & 0x2000) 2830Sstevel@tonic-gate #define IS_VIS1(op, op3)(op == 2 && op3 == 0x36) 2840Sstevel@tonic-gate #define IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(op, op3, asi) \ 2850Sstevel@tonic-gate (op == 3 && (op3 == IOP_V8_LDDFA || \ 2860Sstevel@tonic-gate op3 == IOP_V8_STDFA) && asi > ASI_SNFL) 2870Sstevel@tonic-gate int 2880Sstevel@tonic-gate vis1_partial_support(struct regs *rp, k_siginfo_t *siginfo, uint_t *fault) 2890Sstevel@tonic-gate { 2900Sstevel@tonic-gate char *badaddr; 2910Sstevel@tonic-gate int instr; 2920Sstevel@tonic-gate uint_t optype, op3, asi; 2930Sstevel@tonic-gate uint_t rd, ignor; 2940Sstevel@tonic-gate 295*526Sarao if (!USERMODE(rp->r_tstate)) 296*526Sarao return (-1); 2970Sstevel@tonic-gate 2980Sstevel@tonic-gate instr = fetch_user_instr((caddr_t)rp->r_pc); 2990Sstevel@tonic-gate 3000Sstevel@tonic-gate rd = (instr >> 25) & 0x1f; 3010Sstevel@tonic-gate optype = (instr >> 30) & 0x3; 3020Sstevel@tonic-gate op3 = (instr >> 19) & 0x3f; 3030Sstevel@tonic-gate ignor = (instr >> 5) & 0xff; 3040Sstevel@tonic-gate if (IS_IBIT_SET(instr)) { 3050Sstevel@tonic-gate asi = (uint32_t)((rp->r_tstate >> TSTATE_ASI_SHIFT) & 3060Sstevel@tonic-gate TSTATE_ASI_MASK); 3070Sstevel@tonic-gate } else { 3080Sstevel@tonic-gate asi = ignor; 3090Sstevel@tonic-gate } 3100Sstevel@tonic-gate 3110Sstevel@tonic-gate if (!IS_VIS1(optype, op3) && 3120Sstevel@tonic-gate !IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(optype, op3, asi)) { 3130Sstevel@tonic-gate return (-1); 3140Sstevel@tonic-gate } 3150Sstevel@tonic-gate switch (simulate_unimp(rp, &badaddr)) { 3160Sstevel@tonic-gate case SIMU_RETRY: 3170Sstevel@tonic-gate break; /* regs are already set up */ 3180Sstevel@tonic-gate /*NOTREACHED*/ 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate case SIMU_SUCCESS: 3210Sstevel@tonic-gate /* 3220Sstevel@tonic-gate * skip the successfully 3230Sstevel@tonic-gate * simulated instruction 3240Sstevel@tonic-gate */ 3250Sstevel@tonic-gate rp->r_pc = rp->r_npc; 3260Sstevel@tonic-gate rp->r_npc += 4; 3270Sstevel@tonic-gate break; 3280Sstevel@tonic-gate /*NOTREACHED*/ 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate case SIMU_FAULT: 3310Sstevel@tonic-gate siginfo->si_signo = SIGSEGV; 3320Sstevel@tonic-gate siginfo->si_code = SEGV_MAPERR; 3330Sstevel@tonic-gate siginfo->si_addr = badaddr; 3340Sstevel@tonic-gate *fault = FLTBOUNDS; 3350Sstevel@tonic-gate break; 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate case SIMU_DZERO: 3380Sstevel@tonic-gate siginfo->si_signo = SIGFPE; 3390Sstevel@tonic-gate siginfo->si_code = FPE_INTDIV; 3400Sstevel@tonic-gate siginfo->si_addr = (caddr_t)rp->r_pc; 3410Sstevel@tonic-gate *fault = FLTIZDIV; 3420Sstevel@tonic-gate break; 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate case SIMU_UNALIGN: 3450Sstevel@tonic-gate siginfo->si_signo = SIGBUS; 3460Sstevel@tonic-gate siginfo->si_code = BUS_ADRALN; 3470Sstevel@tonic-gate siginfo->si_addr = badaddr; 3480Sstevel@tonic-gate *fault = FLTACCESS; 3490Sstevel@tonic-gate break; 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate case SIMU_ILLEGAL: 3520Sstevel@tonic-gate default: 3530Sstevel@tonic-gate siginfo->si_signo = SIGILL; 3540Sstevel@tonic-gate op3 = (instr >> 19) & 0x3F; 3550Sstevel@tonic-gate if ((IS_FLOAT(instr) && (op3 == IOP_V8_STQFA) || 3560Sstevel@tonic-gate (op3 == IOP_V8_STDFA))) 3570Sstevel@tonic-gate siginfo->si_code = ILL_ILLADR; 3580Sstevel@tonic-gate else 3590Sstevel@tonic-gate siginfo->si_code = ILL_ILLOPC; 3600Sstevel@tonic-gate siginfo->si_addr = (caddr_t)rp->r_pc; 3610Sstevel@tonic-gate *fault = FLTILL; 3620Sstevel@tonic-gate break; 3630Sstevel@tonic-gate } 3640Sstevel@tonic-gate return (0); 3650Sstevel@tonic-gate } 366