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 51991Sheppo * Common Development and Distribution License (the "License"). 61991Sheppo * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 214203Srsmaeda 220Sstevel@tonic-gate /* 233434Sesaxe * Copyright 2007 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> 38*4769Sdp78419 #include <vm/vm_dep.h> 390Sstevel@tonic-gate #include <sys/cpuvar.h> 400Sstevel@tonic-gate #include <sys/async.h> 410Sstevel@tonic-gate #include <sys/cmn_err.h> 420Sstevel@tonic-gate #include <sys/debug.h> 430Sstevel@tonic-gate #include <sys/dditypes.h> 440Sstevel@tonic-gate #include <sys/sunddi.h> 450Sstevel@tonic-gate #include <sys/cpu_module.h> 460Sstevel@tonic-gate #include <sys/prom_debug.h> 470Sstevel@tonic-gate #include <sys/vmsystm.h> 480Sstevel@tonic-gate #include <sys/prom_plat.h> 490Sstevel@tonic-gate #include <sys/sysmacros.h> 500Sstevel@tonic-gate #include <sys/intreg.h> 510Sstevel@tonic-gate #include <sys/machtrap.h> 520Sstevel@tonic-gate #include <sys/ontrap.h> 530Sstevel@tonic-gate #include <sys/ivintr.h> 540Sstevel@tonic-gate #include <sys/atomic.h> 550Sstevel@tonic-gate #include <sys/panic.h> 560Sstevel@tonic-gate #include <sys/dtrace.h> 570Sstevel@tonic-gate #include <vm/seg_spt.h> 581991Sheppo #include <sys/simulate.h> 591991Sheppo #include <sys/fault.h> 600Sstevel@tonic-gate 610Sstevel@tonic-gate 620Sstevel@tonic-gate uint_t root_phys_addr_lo_mask = 0xffffffffU; 630Sstevel@tonic-gate 640Sstevel@tonic-gate void 650Sstevel@tonic-gate cpu_setup(void) 660Sstevel@tonic-gate { 670Sstevel@tonic-gate extern int mmu_exported_pagesize_mask; 681991Sheppo char *generic_isa_set[] = { 691991Sheppo "sparcv9+vis", 701991Sheppo "sparcv8plus+vis", 711991Sheppo NULL 721991Sheppo }; 731991Sheppo 741991Sheppo /* 751991Sheppo * The setup common to all CPU modules is done in cpu_setup_common 761991Sheppo * routine. 771991Sheppo */ 781991Sheppo cpu_setup_common(generic_isa_set); 790Sstevel@tonic-gate 800Sstevel@tonic-gate cache |= (CACHE_PTAG | CACHE_IOCOHERENT); 810Sstevel@tonic-gate 821991Sheppo if (broken_md_flag) { 831991Sheppo /* 841991Sheppo * Turn on the missing bits supported by sun4v architecture in 851991Sheppo * MMU pagesize mask returned by MD. 861991Sheppo */ 871991Sheppo mmu_exported_pagesize_mask |= DEFAULT_SUN4V_MMU_PAGESIZE_MASK; 881991Sheppo } else { 891991Sheppo /* 901991Sheppo * According to sun4v architecture each processor must 911991Sheppo * support 8K, 64K and 4M page sizes. If any of the page 921991Sheppo * size is missing from page size mask, then panic. 931991Sheppo */ 941991Sheppo if ((mmu_exported_pagesize_mask & 951991Sheppo DEFAULT_SUN4V_MMU_PAGESIZE_MASK) != 961991Sheppo DEFAULT_SUN4V_MMU_PAGESIZE_MASK) 971991Sheppo cmn_err(CE_PANIC, "machine description" 981991Sheppo " does not have required sun4v page sizes" 991991Sheppo " 8K, 64K and 4M: MD mask is 0x%x", 1001991Sheppo mmu_exported_pagesize_mask); 1010Sstevel@tonic-gate } 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate /* 1041991Sheppo * If processor supports the subset of full 64-bit virtual 1051991Sheppo * address space, then set VA hole accordingly. 1060Sstevel@tonic-gate */ 1071991Sheppo if (va_bits < VA_ADDRESS_SPACE_BITS) { 1081991Sheppo hole_start = (caddr_t)(1ull << (va_bits - 1)); 1091991Sheppo hole_end = (caddr_t)(0ull - (1ull << (va_bits - 1))); 1101991Sheppo } else { 1111991Sheppo hole_start = hole_end = 0; 1121991Sheppo } 1130Sstevel@tonic-gate } 1140Sstevel@tonic-gate 1150Sstevel@tonic-gate void 1160Sstevel@tonic-gate cpu_fiximp(struct cpu_node *cpunode) 1170Sstevel@tonic-gate { 1180Sstevel@tonic-gate /* 1191991Sheppo * The Cache node is optional in MD. Therefore in case "Cache" 1201991Sheppo * does not exists in MD, set the default L2 cache associativity, 1211991Sheppo * size, linesize for generic CPU module. 1220Sstevel@tonic-gate */ 1231991Sheppo if (cpunode->ecache_size == 0) 1241991Sheppo cpunode->ecache_size = 0x100000; 1251991Sheppo if (cpunode->ecache_linesize == 0) 1261991Sheppo cpunode->ecache_linesize = 64; 1271991Sheppo if (cpunode->ecache_associativity == 0) 1281991Sheppo cpunode->ecache_associativity = 1; 1290Sstevel@tonic-gate } 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate void 1320Sstevel@tonic-gate dtrace_flush_sec(uintptr_t addr) 1330Sstevel@tonic-gate { 1340Sstevel@tonic-gate pfn_t pfn; 1350Sstevel@tonic-gate proc_t *procp = ttoproc(curthread); 1360Sstevel@tonic-gate page_t *pp; 1370Sstevel@tonic-gate caddr_t va; 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate pfn = hat_getpfnum(procp->p_as->a_hat, (void *)addr); 1400Sstevel@tonic-gate if (pfn != -1) { 1410Sstevel@tonic-gate ASSERT(pf_is_memory(pfn)); 1420Sstevel@tonic-gate pp = page_numtopp_noreclaim(pfn, SE_SHARED); 1430Sstevel@tonic-gate if (pp != NULL) { 1440Sstevel@tonic-gate va = ppmapin(pp, PROT_READ | PROT_WRITE, (void *)addr); 1450Sstevel@tonic-gate /* sparc needs 8-byte align */ 1460Sstevel@tonic-gate doflush((caddr_t)((uintptr_t)va & -8l)); 1470Sstevel@tonic-gate ppmapout(va); 1480Sstevel@tonic-gate page_unlock(pp); 1490Sstevel@tonic-gate } 1500Sstevel@tonic-gate } 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate void 1544203Srsmaeda cpu_map_exec_units(struct cpu *cp) 1550Sstevel@tonic-gate { 1564203Srsmaeda ASSERT(MUTEX_HELD(&cpu_lock)); 1574203Srsmaeda 158220Sesaxe /* 1593434Sesaxe * The cpu_ipipe and cpu_fpu fields are initialized based on 1604203Srsmaeda * the execution unit sharing information from the MD. They 1614203Srsmaeda * default to the CPU id in the absence of such information. 162220Sesaxe */ 1631991Sheppo cp->cpu_m.cpu_ipipe = cpunodes[cp->cpu_id].exec_unit_mapping; 1641991Sheppo if (cp->cpu_m.cpu_ipipe == NO_EU_MAPPING_FOUND) 1651991Sheppo cp->cpu_m.cpu_ipipe = (id_t)(cp->cpu_id); 1663434Sesaxe 1673434Sesaxe cp->cpu_m.cpu_fpu = cpunodes[cp->cpu_id].fpu_mapping; 1683434Sesaxe if (cp->cpu_m.cpu_fpu == NO_EU_MAPPING_FOUND) 1693434Sesaxe cp->cpu_m.cpu_fpu = (id_t)(cp->cpu_id); 1703434Sesaxe 171*4769Sdp78419 cp->cpu_m.cpu_mpipe = cpunodes[cp->cpu_id].l2_cache_mapping; 172*4769Sdp78419 if (cp->cpu_m.cpu_mpipe == NO_L2_CACHE_MAPPING_FOUND) 173*4769Sdp78419 cp->cpu_m.cpu_mpipe = CPU_L2_CACHEID_INVALID; 174*4769Sdp78419 1753434Sesaxe cp->cpu_m.cpu_core = (id_t)(cp->cpu_id); 1764732Sdavemq 1774732Sdavemq /* 1784732Sdavemq * The cpu_chip field is set to invalid(unknown) for generic cpu. 1794732Sdavemq */ 1804732Sdavemq cp->cpu_m.cpu_chip = CPU_CHIPID_INVALID; 1810Sstevel@tonic-gate } 1820Sstevel@tonic-gate 1830Sstevel@tonic-gate void 1844203Srsmaeda cpu_init_private(struct cpu *cp) 1850Sstevel@tonic-gate { 1864203Srsmaeda cpu_map_exec_units(cp); 1870Sstevel@tonic-gate } 1880Sstevel@tonic-gate 1894203Srsmaeda /*ARGSUSED*/ 1904203Srsmaeda void 1914203Srsmaeda cpu_uninit_private(struct cpu *cp) 1924203Srsmaeda {} 1934203Srsmaeda 1940Sstevel@tonic-gate /* 1950Sstevel@tonic-gate * Invalidate a TSB. Since this needs to work on all sun4v 1960Sstevel@tonic-gate * architecture compliant processors, we use the old method of 1970Sstevel@tonic-gate * walking the TSB, setting each tag to TSBTAG_INVALID. 1980Sstevel@tonic-gate */ 1990Sstevel@tonic-gate void 2000Sstevel@tonic-gate cpu_inv_tsb(caddr_t tsb_base, uint_t tsb_bytes) 2010Sstevel@tonic-gate { 2020Sstevel@tonic-gate struct tsbe *tsbaddr; 2030Sstevel@tonic-gate 2040Sstevel@tonic-gate for (tsbaddr = (struct tsbe *)tsb_base; 2050Sstevel@tonic-gate (uintptr_t)tsbaddr < (uintptr_t)(tsb_base + tsb_bytes); 2060Sstevel@tonic-gate tsbaddr++) { 2070Sstevel@tonic-gate tsbaddr->tte_tag.tag_inthi = TSBTAG_INVALID; 2080Sstevel@tonic-gate } 2090Sstevel@tonic-gate } 2101050Sgirish 2111050Sgirish /* 2121991Sheppo * Sun4v kernel must emulate code a generic sun4v processor may not support 2131991Sheppo * i.e. VIS1 and VIS2. 2141991Sheppo */ 2151991Sheppo #define IS_FLOAT(i) (((i) & 0x1000000) != 0) 2161991Sheppo #define IS_IBIT_SET(x) (x & 0x2000) 2171991Sheppo #define IS_VIS1(op, op3)(op == 2 && op3 == 0x36) 2181991Sheppo #define IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(op, op3, asi) \ 2191991Sheppo (op == 3 && (op3 == IOP_V8_LDDFA || \ 2201991Sheppo op3 == IOP_V8_STDFA) && asi > ASI_SNFL) 2211991Sheppo int 2221991Sheppo vis1_partial_support(struct regs *rp, k_siginfo_t *siginfo, uint_t *fault) 2231991Sheppo { 2241991Sheppo char *badaddr; 2251991Sheppo int instr; 2261991Sheppo uint_t optype, op3, asi; 2271991Sheppo uint_t rd, ignor; 2281991Sheppo 2291991Sheppo if (!USERMODE(rp->r_tstate)) 2301991Sheppo return (-1); 2311991Sheppo 2321991Sheppo instr = fetch_user_instr((caddr_t)rp->r_pc); 2331991Sheppo 2341991Sheppo rd = (instr >> 25) & 0x1f; 2351991Sheppo optype = (instr >> 30) & 0x3; 2361991Sheppo op3 = (instr >> 19) & 0x3f; 2371991Sheppo ignor = (instr >> 5) & 0xff; 2381991Sheppo if (IS_IBIT_SET(instr)) { 2391991Sheppo asi = (uint32_t)((rp->r_tstate >> TSTATE_ASI_SHIFT) & 2401991Sheppo TSTATE_ASI_MASK); 2411991Sheppo } else { 2421991Sheppo asi = ignor; 2431991Sheppo } 2441991Sheppo 2451991Sheppo if (!IS_VIS1(optype, op3) && 2461991Sheppo !IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(optype, op3, asi)) { 2471991Sheppo return (-1); 2481991Sheppo } 2491991Sheppo switch (simulate_unimp(rp, &badaddr)) { 2501991Sheppo case SIMU_RETRY: 2511991Sheppo break; /* regs are already set up */ 2521991Sheppo /*NOTREACHED*/ 2531991Sheppo 2541991Sheppo case SIMU_SUCCESS: 2551991Sheppo /* 2561991Sheppo * skip the successfully 2571991Sheppo * simulated instruction 2581991Sheppo */ 2591991Sheppo rp->r_pc = rp->r_npc; 2601991Sheppo rp->r_npc += 4; 2611991Sheppo break; 2621991Sheppo /*NOTREACHED*/ 2631991Sheppo 2641991Sheppo case SIMU_FAULT: 2651991Sheppo siginfo->si_signo = SIGSEGV; 2661991Sheppo siginfo->si_code = SEGV_MAPERR; 2671991Sheppo siginfo->si_addr = badaddr; 2681991Sheppo *fault = FLTBOUNDS; 2691991Sheppo break; 2701991Sheppo 2711991Sheppo case SIMU_DZERO: 2721991Sheppo siginfo->si_signo = SIGFPE; 2731991Sheppo siginfo->si_code = FPE_INTDIV; 2741991Sheppo siginfo->si_addr = (caddr_t)rp->r_pc; 2751991Sheppo *fault = FLTIZDIV; 2761991Sheppo break; 2771991Sheppo 2781991Sheppo case SIMU_UNALIGN: 2791991Sheppo siginfo->si_signo = SIGBUS; 2801991Sheppo siginfo->si_code = BUS_ADRALN; 2811991Sheppo siginfo->si_addr = badaddr; 2821991Sheppo *fault = FLTACCESS; 2831991Sheppo break; 2841991Sheppo 2851991Sheppo case SIMU_ILLEGAL: 2861991Sheppo default: 2871991Sheppo siginfo->si_signo = SIGILL; 2881991Sheppo op3 = (instr >> 19) & 0x3F; 2891991Sheppo if ((IS_FLOAT(instr) && (op3 == IOP_V8_STQFA) || 2901991Sheppo (op3 == IOP_V8_STDFA))) 2911991Sheppo siginfo->si_code = ILL_ILLADR; 2921991Sheppo else 2931991Sheppo siginfo->si_code = ILL_ILLOPC; 2941991Sheppo siginfo->si_addr = (caddr_t)rp->r_pc; 2951991Sheppo *fault = FLTILL; 2961991Sheppo break; 2971991Sheppo } 2981991Sheppo return (0); 2991991Sheppo } 3001991Sheppo 3011991Sheppo /* 3021050Sgirish * Trapstat support for generic sun4v processor 3031050Sgirish */ 3041050Sgirish int 3051050Sgirish cpu_trapstat_conf(int cmd) 3061050Sgirish { 3071050Sgirish int status; 3081050Sgirish 3091050Sgirish switch (cmd) { 3101050Sgirish case CPU_TSTATCONF_INIT: 3111050Sgirish case CPU_TSTATCONF_FINI: 3121050Sgirish case CPU_TSTATCONF_ENABLE: 3131050Sgirish case CPU_TSTATCONF_DISABLE: 3141050Sgirish status = ENOTSUP; 3151050Sgirish break; 3161050Sgirish 3171050Sgirish default: 3181050Sgirish status = EINVAL; 3191050Sgirish break; 3201050Sgirish } 3211050Sgirish return (status); 3221050Sgirish } 3231050Sgirish 3241050Sgirish /*ARGSUSED*/ 3251050Sgirish void 3261050Sgirish cpu_trapstat_data(void *buf, uint_t tstat_pgszs) 3271050Sgirish { 3281050Sgirish } 329