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*1ae08745Sheppo * Common Development and Distribution License (the "License"). 6*1ae08745Sheppo * 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*1ae08745Sheppo * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <sys/types.h> 297c478bd9Sstevel@tonic-gate #include <sys/systm.h> 307c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 317c478bd9Sstevel@tonic-gate #include <sys/machparam.h> 327c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 337c478bd9Sstevel@tonic-gate #include <sys/cpu.h> 347c478bd9Sstevel@tonic-gate #include <sys/elf_SPARC.h> 357c478bd9Sstevel@tonic-gate #include <vm/hat_sfmmu.h> 367c478bd9Sstevel@tonic-gate #include <vm/page.h> 377c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 387c478bd9Sstevel@tonic-gate #include <sys/async.h> 397c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 407c478bd9Sstevel@tonic-gate #include <sys/debug.h> 417c478bd9Sstevel@tonic-gate #include <sys/dditypes.h> 427c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 437c478bd9Sstevel@tonic-gate #include <sys/cpu_module.h> 447c478bd9Sstevel@tonic-gate #include <sys/prom_debug.h> 457c478bd9Sstevel@tonic-gate #include <sys/vmsystm.h> 467c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h> 477c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 487c478bd9Sstevel@tonic-gate #include <sys/intreg.h> 497c478bd9Sstevel@tonic-gate #include <sys/machtrap.h> 507c478bd9Sstevel@tonic-gate #include <sys/ontrap.h> 517c478bd9Sstevel@tonic-gate #include <sys/ivintr.h> 527c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 537c478bd9Sstevel@tonic-gate #include <sys/panic.h> 547c478bd9Sstevel@tonic-gate #include <sys/dtrace.h> 557c478bd9Sstevel@tonic-gate #include <vm/seg_spt.h> 56*1ae08745Sheppo #include <sys/simulate.h> 57*1ae08745Sheppo #include <sys/fault.h> 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate uint_t root_phys_addr_lo_mask = 0xffffffffU; 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate void 637c478bd9Sstevel@tonic-gate cpu_setup(void) 647c478bd9Sstevel@tonic-gate { 657c478bd9Sstevel@tonic-gate extern int mmu_exported_pagesize_mask; 66*1ae08745Sheppo char *generic_isa_set[] = { 67*1ae08745Sheppo "sparcv9+vis", 68*1ae08745Sheppo "sparcv8plus+vis", 69*1ae08745Sheppo NULL 70*1ae08745Sheppo }; 71*1ae08745Sheppo 72*1ae08745Sheppo /* 73*1ae08745Sheppo * The setup common to all CPU modules is done in cpu_setup_common 74*1ae08745Sheppo * routine. 75*1ae08745Sheppo */ 76*1ae08745Sheppo cpu_setup_common(generic_isa_set); 777c478bd9Sstevel@tonic-gate 787c478bd9Sstevel@tonic-gate cache |= (CACHE_PTAG | CACHE_IOCOHERENT); 797c478bd9Sstevel@tonic-gate 80*1ae08745Sheppo if (broken_md_flag) { 817c478bd9Sstevel@tonic-gate /* 82*1ae08745Sheppo * Turn on the missing bits supported by sun4v architecture in 83*1ae08745Sheppo * MMU pagesize mask returned by MD. 847c478bd9Sstevel@tonic-gate */ 85*1ae08745Sheppo mmu_exported_pagesize_mask |= DEFAULT_SUN4V_MMU_PAGESIZE_MASK; 86*1ae08745Sheppo } else { 877c478bd9Sstevel@tonic-gate /* 88*1ae08745Sheppo * According to sun4v architecture each processor must 89*1ae08745Sheppo * support 8K, 64K and 4M page sizes. If any of the page 90*1ae08745Sheppo * size is missing from page size mask, then panic. 917c478bd9Sstevel@tonic-gate */ 92*1ae08745Sheppo if ((mmu_exported_pagesize_mask & 93*1ae08745Sheppo DEFAULT_SUN4V_MMU_PAGESIZE_MASK) != 94*1ae08745Sheppo DEFAULT_SUN4V_MMU_PAGESIZE_MASK) 95*1ae08745Sheppo cmn_err(CE_PANIC, "machine description" 96*1ae08745Sheppo " does not have required sun4v page sizes" 97*1ae08745Sheppo " 8K, 64K and 4M: MD mask is 0x%x", 98*1ae08745Sheppo mmu_exported_pagesize_mask); 997c478bd9Sstevel@tonic-gate } 1007c478bd9Sstevel@tonic-gate 1017c478bd9Sstevel@tonic-gate /* 102*1ae08745Sheppo * If processor supports the subset of full 64-bit virtual 103*1ae08745Sheppo * address space, then set VA hole accordingly. 1047c478bd9Sstevel@tonic-gate */ 105*1ae08745Sheppo if (va_bits < VA_ADDRESS_SPACE_BITS) { 106*1ae08745Sheppo hole_start = (caddr_t)(1ull << (va_bits - 1)); 107*1ae08745Sheppo hole_end = (caddr_t)(0ull - (1ull << (va_bits - 1))); 108*1ae08745Sheppo } else { 109*1ae08745Sheppo hole_start = hole_end = 0; 110*1ae08745Sheppo } 1117c478bd9Sstevel@tonic-gate } 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate void 1147c478bd9Sstevel@tonic-gate cpu_fiximp(struct cpu_node *cpunode) 1157c478bd9Sstevel@tonic-gate { 1167c478bd9Sstevel@tonic-gate /* 117*1ae08745Sheppo * The Cache node is optional in MD. Therefore in case "Cache" 118*1ae08745Sheppo * does not exists in MD, set the default L2 cache associativity, 119*1ae08745Sheppo * size, linesize for generic CPU module. 1207c478bd9Sstevel@tonic-gate */ 121*1ae08745Sheppo if (cpunode->ecache_size == 0) 122*1ae08745Sheppo cpunode->ecache_size = 0x100000; 123*1ae08745Sheppo if (cpunode->ecache_linesize == 0) 124*1ae08745Sheppo cpunode->ecache_linesize = 64; 125*1ae08745Sheppo if (cpunode->ecache_associativity == 0) 126*1ae08745Sheppo cpunode->ecache_associativity = 1; 1277c478bd9Sstevel@tonic-gate } 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate void 1307c478bd9Sstevel@tonic-gate dtrace_flush_sec(uintptr_t addr) 1317c478bd9Sstevel@tonic-gate { 1327c478bd9Sstevel@tonic-gate pfn_t pfn; 1337c478bd9Sstevel@tonic-gate proc_t *procp = ttoproc(curthread); 1347c478bd9Sstevel@tonic-gate page_t *pp; 1357c478bd9Sstevel@tonic-gate caddr_t va; 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate pfn = hat_getpfnum(procp->p_as->a_hat, (void *)addr); 1387c478bd9Sstevel@tonic-gate if (pfn != -1) { 1397c478bd9Sstevel@tonic-gate ASSERT(pf_is_memory(pfn)); 1407c478bd9Sstevel@tonic-gate pp = page_numtopp_noreclaim(pfn, SE_SHARED); 1417c478bd9Sstevel@tonic-gate if (pp != NULL) { 1427c478bd9Sstevel@tonic-gate va = ppmapin(pp, PROT_READ | PROT_WRITE, (void *)addr); 1437c478bd9Sstevel@tonic-gate /* sparc needs 8-byte align */ 1447c478bd9Sstevel@tonic-gate doflush((caddr_t)((uintptr_t)va & -8l)); 1457c478bd9Sstevel@tonic-gate ppmapout(va); 1467c478bd9Sstevel@tonic-gate page_unlock(pp); 1477c478bd9Sstevel@tonic-gate } 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate } 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate void 1527c478bd9Sstevel@tonic-gate cpu_init_private(struct cpu *cp) 1537c478bd9Sstevel@tonic-gate { 15470f54eadSesaxe /* 15570f54eadSesaxe * The cpu_ipipe field is initialized based on the execution 15670f54eadSesaxe * unit sharing information from the Machine Description table. 15770f54eadSesaxe * It defaults to the CPU id in the absence of such information. 15870f54eadSesaxe */ 159*1ae08745Sheppo cp->cpu_m.cpu_ipipe = cpunodes[cp->cpu_id].exec_unit_mapping; 160*1ae08745Sheppo if (cp->cpu_m.cpu_ipipe == NO_EU_MAPPING_FOUND) 16170f54eadSesaxe cp->cpu_m.cpu_ipipe = (id_t)(cp->cpu_id); 1627c478bd9Sstevel@tonic-gate } 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate void 1657c478bd9Sstevel@tonic-gate cpu_uninit_private(struct cpu *cp) 1667c478bd9Sstevel@tonic-gate { 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate /* 1707c478bd9Sstevel@tonic-gate * Invalidate a TSB. Since this needs to work on all sun4v 1717c478bd9Sstevel@tonic-gate * architecture compliant processors, we use the old method of 1727c478bd9Sstevel@tonic-gate * walking the TSB, setting each tag to TSBTAG_INVALID. 1737c478bd9Sstevel@tonic-gate */ 1747c478bd9Sstevel@tonic-gate void 1757c478bd9Sstevel@tonic-gate cpu_inv_tsb(caddr_t tsb_base, uint_t tsb_bytes) 1767c478bd9Sstevel@tonic-gate { 1777c478bd9Sstevel@tonic-gate struct tsbe *tsbaddr; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate for (tsbaddr = (struct tsbe *)tsb_base; 1807c478bd9Sstevel@tonic-gate (uintptr_t)tsbaddr < (uintptr_t)(tsb_base + tsb_bytes); 1817c478bd9Sstevel@tonic-gate tsbaddr++) { 1827c478bd9Sstevel@tonic-gate tsbaddr->tte_tag.tag_inthi = TSBTAG_INVALID; 1837c478bd9Sstevel@tonic-gate } 1847c478bd9Sstevel@tonic-gate } 185ce0352ebSgirish 186ce0352ebSgirish /* 187*1ae08745Sheppo * Sun4v kernel must emulate code a generic sun4v processor may not support 188*1ae08745Sheppo * i.e. VIS1 and VIS2. 189*1ae08745Sheppo */ 190*1ae08745Sheppo #define IS_FLOAT(i) (((i) & 0x1000000) != 0) 191*1ae08745Sheppo #define IS_IBIT_SET(x) (x & 0x2000) 192*1ae08745Sheppo #define IS_VIS1(op, op3)(op == 2 && op3 == 0x36) 193*1ae08745Sheppo #define IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(op, op3, asi) \ 194*1ae08745Sheppo (op == 3 && (op3 == IOP_V8_LDDFA || \ 195*1ae08745Sheppo op3 == IOP_V8_STDFA) && asi > ASI_SNFL) 196*1ae08745Sheppo int 197*1ae08745Sheppo vis1_partial_support(struct regs *rp, k_siginfo_t *siginfo, uint_t *fault) 198*1ae08745Sheppo { 199*1ae08745Sheppo char *badaddr; 200*1ae08745Sheppo int instr; 201*1ae08745Sheppo uint_t optype, op3, asi; 202*1ae08745Sheppo uint_t rd, ignor; 203*1ae08745Sheppo 204*1ae08745Sheppo if (!USERMODE(rp->r_tstate)) 205*1ae08745Sheppo return (-1); 206*1ae08745Sheppo 207*1ae08745Sheppo instr = fetch_user_instr((caddr_t)rp->r_pc); 208*1ae08745Sheppo 209*1ae08745Sheppo rd = (instr >> 25) & 0x1f; 210*1ae08745Sheppo optype = (instr >> 30) & 0x3; 211*1ae08745Sheppo op3 = (instr >> 19) & 0x3f; 212*1ae08745Sheppo ignor = (instr >> 5) & 0xff; 213*1ae08745Sheppo if (IS_IBIT_SET(instr)) { 214*1ae08745Sheppo asi = (uint32_t)((rp->r_tstate >> TSTATE_ASI_SHIFT) & 215*1ae08745Sheppo TSTATE_ASI_MASK); 216*1ae08745Sheppo } else { 217*1ae08745Sheppo asi = ignor; 218*1ae08745Sheppo } 219*1ae08745Sheppo 220*1ae08745Sheppo if (!IS_VIS1(optype, op3) && 221*1ae08745Sheppo !IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(optype, op3, asi)) { 222*1ae08745Sheppo return (-1); 223*1ae08745Sheppo } 224*1ae08745Sheppo switch (simulate_unimp(rp, &badaddr)) { 225*1ae08745Sheppo case SIMU_RETRY: 226*1ae08745Sheppo break; /* regs are already set up */ 227*1ae08745Sheppo /*NOTREACHED*/ 228*1ae08745Sheppo 229*1ae08745Sheppo case SIMU_SUCCESS: 230*1ae08745Sheppo /* 231*1ae08745Sheppo * skip the successfully 232*1ae08745Sheppo * simulated instruction 233*1ae08745Sheppo */ 234*1ae08745Sheppo rp->r_pc = rp->r_npc; 235*1ae08745Sheppo rp->r_npc += 4; 236*1ae08745Sheppo break; 237*1ae08745Sheppo /*NOTREACHED*/ 238*1ae08745Sheppo 239*1ae08745Sheppo case SIMU_FAULT: 240*1ae08745Sheppo siginfo->si_signo = SIGSEGV; 241*1ae08745Sheppo siginfo->si_code = SEGV_MAPERR; 242*1ae08745Sheppo siginfo->si_addr = badaddr; 243*1ae08745Sheppo *fault = FLTBOUNDS; 244*1ae08745Sheppo break; 245*1ae08745Sheppo 246*1ae08745Sheppo case SIMU_DZERO: 247*1ae08745Sheppo siginfo->si_signo = SIGFPE; 248*1ae08745Sheppo siginfo->si_code = FPE_INTDIV; 249*1ae08745Sheppo siginfo->si_addr = (caddr_t)rp->r_pc; 250*1ae08745Sheppo *fault = FLTIZDIV; 251*1ae08745Sheppo break; 252*1ae08745Sheppo 253*1ae08745Sheppo case SIMU_UNALIGN: 254*1ae08745Sheppo siginfo->si_signo = SIGBUS; 255*1ae08745Sheppo siginfo->si_code = BUS_ADRALN; 256*1ae08745Sheppo siginfo->si_addr = badaddr; 257*1ae08745Sheppo *fault = FLTACCESS; 258*1ae08745Sheppo break; 259*1ae08745Sheppo 260*1ae08745Sheppo case SIMU_ILLEGAL: 261*1ae08745Sheppo default: 262*1ae08745Sheppo siginfo->si_signo = SIGILL; 263*1ae08745Sheppo op3 = (instr >> 19) & 0x3F; 264*1ae08745Sheppo if ((IS_FLOAT(instr) && (op3 == IOP_V8_STQFA) || 265*1ae08745Sheppo (op3 == IOP_V8_STDFA))) 266*1ae08745Sheppo siginfo->si_code = ILL_ILLADR; 267*1ae08745Sheppo else 268*1ae08745Sheppo siginfo->si_code = ILL_ILLOPC; 269*1ae08745Sheppo siginfo->si_addr = (caddr_t)rp->r_pc; 270*1ae08745Sheppo *fault = FLTILL; 271*1ae08745Sheppo break; 272*1ae08745Sheppo } 273*1ae08745Sheppo return (0); 274*1ae08745Sheppo } 275*1ae08745Sheppo 276*1ae08745Sheppo /* 277ce0352ebSgirish * Trapstat support for generic sun4v processor 278ce0352ebSgirish */ 279ce0352ebSgirish int 280ce0352ebSgirish cpu_trapstat_conf(int cmd) 281ce0352ebSgirish { 282ce0352ebSgirish int status; 283ce0352ebSgirish 284ce0352ebSgirish switch (cmd) { 285ce0352ebSgirish case CPU_TSTATCONF_INIT: 286ce0352ebSgirish case CPU_TSTATCONF_FINI: 287ce0352ebSgirish case CPU_TSTATCONF_ENABLE: 288ce0352ebSgirish case CPU_TSTATCONF_DISABLE: 289ce0352ebSgirish status = ENOTSUP; 290ce0352ebSgirish break; 291ce0352ebSgirish 292ce0352ebSgirish default: 293ce0352ebSgirish status = EINVAL; 294ce0352ebSgirish break; 295ce0352ebSgirish } 296ce0352ebSgirish return (status); 297ce0352ebSgirish } 298ce0352ebSgirish 299ce0352ebSgirish /*ARGSUSED*/ 300ce0352ebSgirish void 301ce0352ebSgirish cpu_trapstat_data(void *buf, uint_t tstat_pgszs) 302ce0352ebSgirish { 303ce0352ebSgirish } 304