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>
384769Sdp78419 #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
cpu_setup(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
cpu_fiximp(struct cpu_node * cpunode)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
dtrace_flush_sec(uintptr_t addr)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
cpu_map_exec_units(struct cpu * cp)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
1715079Sjc25722 /*
1725079Sjc25722 * The cpu_chip field is initialized based on the information
1735079Sjc25722 * in the MD and assume that all cpus within a chip
1745079Sjc25722 * share the same L2 cache. If no such info is available, we
1755079Sjc25722 * set the cpu to belong to the defacto chip 0.
1765079Sjc25722 */
1774769Sdp78419 cp->cpu_m.cpu_mpipe = cpunodes[cp->cpu_id].l2_cache_mapping;
1784769Sdp78419 if (cp->cpu_m.cpu_mpipe == NO_L2_CACHE_MAPPING_FOUND)
1794769Sdp78419 cp->cpu_m.cpu_mpipe = CPU_L2_CACHEID_INVALID;
1804769Sdp78419
1813434Sesaxe cp->cpu_m.cpu_core = (id_t)(cp->cpu_id);
1824732Sdavemq
1834732Sdavemq /*
1844732Sdavemq * The cpu_chip field is set to invalid(unknown) for generic cpu.
1854732Sdavemq */
1864732Sdavemq cp->cpu_m.cpu_chip = CPU_CHIPID_INVALID;
1870Sstevel@tonic-gate }
1880Sstevel@tonic-gate
1890Sstevel@tonic-gate void
cpu_init_private(struct cpu * cp)1904203Srsmaeda cpu_init_private(struct cpu *cp)
1910Sstevel@tonic-gate {
1924203Srsmaeda cpu_map_exec_units(cp);
1930Sstevel@tonic-gate }
1940Sstevel@tonic-gate
1954203Srsmaeda /*ARGSUSED*/
1964203Srsmaeda void
cpu_uninit_private(struct cpu * cp)1974203Srsmaeda cpu_uninit_private(struct cpu *cp)
1984203Srsmaeda {}
1994203Srsmaeda
2000Sstevel@tonic-gate /*
2010Sstevel@tonic-gate * Invalidate a TSB. Since this needs to work on all sun4v
2020Sstevel@tonic-gate * architecture compliant processors, we use the old method of
2030Sstevel@tonic-gate * walking the TSB, setting each tag to TSBTAG_INVALID.
2040Sstevel@tonic-gate */
2050Sstevel@tonic-gate void
cpu_inv_tsb(caddr_t tsb_base,uint_t tsb_bytes)2060Sstevel@tonic-gate cpu_inv_tsb(caddr_t tsb_base, uint_t tsb_bytes)
2070Sstevel@tonic-gate {
2080Sstevel@tonic-gate struct tsbe *tsbaddr;
2090Sstevel@tonic-gate
210*5352Ssvemuri for (tsbaddr = (struct tsbe *)(uintptr_t)tsb_base;
2110Sstevel@tonic-gate (uintptr_t)tsbaddr < (uintptr_t)(tsb_base + tsb_bytes);
2120Sstevel@tonic-gate tsbaddr++) {
2130Sstevel@tonic-gate tsbaddr->tte_tag.tag_inthi = TSBTAG_INVALID;
2140Sstevel@tonic-gate }
2150Sstevel@tonic-gate }
2161050Sgirish
2171050Sgirish /*
2181991Sheppo * Sun4v kernel must emulate code a generic sun4v processor may not support
2191991Sheppo * i.e. VIS1 and VIS2.
2201991Sheppo */
2211991Sheppo #define IS_FLOAT(i) (((i) & 0x1000000) != 0)
2221991Sheppo #define IS_IBIT_SET(x) (x & 0x2000)
2231991Sheppo #define IS_VIS1(op, op3)(op == 2 && op3 == 0x36)
2241991Sheppo #define IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(op, op3, asi) \
2251991Sheppo (op == 3 && (op3 == IOP_V8_LDDFA || \
2261991Sheppo op3 == IOP_V8_STDFA) && asi > ASI_SNFL)
2271991Sheppo int
vis1_partial_support(struct regs * rp,k_siginfo_t * siginfo,uint_t * fault)2281991Sheppo vis1_partial_support(struct regs *rp, k_siginfo_t *siginfo, uint_t *fault)
2291991Sheppo {
2301991Sheppo char *badaddr;
2311991Sheppo int instr;
2321991Sheppo uint_t optype, op3, asi;
233*5352Ssvemuri uint_t ignor;
2341991Sheppo
2351991Sheppo if (!USERMODE(rp->r_tstate))
2361991Sheppo return (-1);
2371991Sheppo
2381991Sheppo instr = fetch_user_instr((caddr_t)rp->r_pc);
2391991Sheppo
2401991Sheppo optype = (instr >> 30) & 0x3;
2411991Sheppo op3 = (instr >> 19) & 0x3f;
2421991Sheppo ignor = (instr >> 5) & 0xff;
2431991Sheppo if (IS_IBIT_SET(instr)) {
2441991Sheppo asi = (uint32_t)((rp->r_tstate >> TSTATE_ASI_SHIFT) &
2451991Sheppo TSTATE_ASI_MASK);
2461991Sheppo } else {
2471991Sheppo asi = ignor;
2481991Sheppo }
2491991Sheppo
2501991Sheppo if (!IS_VIS1(optype, op3) &&
2511991Sheppo !IS_PARTIAL_OR_SHORT_FLOAT_LD_ST(optype, op3, asi)) {
2521991Sheppo return (-1);
2531991Sheppo }
2541991Sheppo switch (simulate_unimp(rp, &badaddr)) {
2551991Sheppo case SIMU_RETRY:
2561991Sheppo break; /* regs are already set up */
2571991Sheppo /*NOTREACHED*/
2581991Sheppo
2591991Sheppo case SIMU_SUCCESS:
2601991Sheppo /*
2611991Sheppo * skip the successfully
2621991Sheppo * simulated instruction
2631991Sheppo */
2641991Sheppo rp->r_pc = rp->r_npc;
2651991Sheppo rp->r_npc += 4;
2661991Sheppo break;
2671991Sheppo /*NOTREACHED*/
2681991Sheppo
2691991Sheppo case SIMU_FAULT:
2701991Sheppo siginfo->si_signo = SIGSEGV;
2711991Sheppo siginfo->si_code = SEGV_MAPERR;
2721991Sheppo siginfo->si_addr = badaddr;
2731991Sheppo *fault = FLTBOUNDS;
2741991Sheppo break;
2751991Sheppo
2761991Sheppo case SIMU_DZERO:
2771991Sheppo siginfo->si_signo = SIGFPE;
2781991Sheppo siginfo->si_code = FPE_INTDIV;
2791991Sheppo siginfo->si_addr = (caddr_t)rp->r_pc;
2801991Sheppo *fault = FLTIZDIV;
2811991Sheppo break;
2821991Sheppo
2831991Sheppo case SIMU_UNALIGN:
2841991Sheppo siginfo->si_signo = SIGBUS;
2851991Sheppo siginfo->si_code = BUS_ADRALN;
2861991Sheppo siginfo->si_addr = badaddr;
2871991Sheppo *fault = FLTACCESS;
2881991Sheppo break;
2891991Sheppo
2901991Sheppo case SIMU_ILLEGAL:
2911991Sheppo default:
2921991Sheppo siginfo->si_signo = SIGILL;
2931991Sheppo op3 = (instr >> 19) & 0x3F;
2941991Sheppo if ((IS_FLOAT(instr) && (op3 == IOP_V8_STQFA) ||
2951991Sheppo (op3 == IOP_V8_STDFA)))
2961991Sheppo siginfo->si_code = ILL_ILLADR;
2971991Sheppo else
2981991Sheppo siginfo->si_code = ILL_ILLOPC;
2991991Sheppo siginfo->si_addr = (caddr_t)rp->r_pc;
3001991Sheppo *fault = FLTILL;
3011991Sheppo break;
3021991Sheppo }
3031991Sheppo return (0);
3041991Sheppo }
3051991Sheppo
3061991Sheppo /*
3071050Sgirish * Trapstat support for generic sun4v processor
3081050Sgirish */
3091050Sgirish int
cpu_trapstat_conf(int cmd)3101050Sgirish cpu_trapstat_conf(int cmd)
3111050Sgirish {
3121050Sgirish int status;
3131050Sgirish
3141050Sgirish switch (cmd) {
3151050Sgirish case CPU_TSTATCONF_INIT:
3161050Sgirish case CPU_TSTATCONF_FINI:
3171050Sgirish case CPU_TSTATCONF_ENABLE:
3181050Sgirish case CPU_TSTATCONF_DISABLE:
3191050Sgirish status = ENOTSUP;
3201050Sgirish break;
3211050Sgirish
3221050Sgirish default:
3231050Sgirish status = EINVAL;
3241050Sgirish break;
3251050Sgirish }
3261050Sgirish return (status);
3271050Sgirish }
3281050Sgirish
3291050Sgirish /*ARGSUSED*/
3301050Sgirish void
cpu_trapstat_data(void * buf,uint_t tstat_pgszs)3311050Sgirish cpu_trapstat_data(void *buf, uint_t tstat_pgszs)
3321050Sgirish {
3331050Sgirish }
334