1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 30*7c478bd9Sstevel@tonic-gate #include <sys/systm.h> 31*7c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 32*7c478bd9Sstevel@tonic-gate #include <sys/machparam.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/cpu.h> 35*7c478bd9Sstevel@tonic-gate #include <sys/elf_SPARC.h> 36*7c478bd9Sstevel@tonic-gate #include <vm/hat_sfmmu.h> 37*7c478bd9Sstevel@tonic-gate #include <vm/page.h> 38*7c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h> 39*7c478bd9Sstevel@tonic-gate #include <sys/async.h> 40*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 41*7c478bd9Sstevel@tonic-gate #include <sys/debug.h> 42*7c478bd9Sstevel@tonic-gate #include <sys/dditypes.h> 43*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 44*7c478bd9Sstevel@tonic-gate #include <sys/cpu_module.h> 45*7c478bd9Sstevel@tonic-gate #include <sys/prom_debug.h> 46*7c478bd9Sstevel@tonic-gate #include <sys/vmsystm.h> 47*7c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h> 48*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 49*7c478bd9Sstevel@tonic-gate #include <sys/intreg.h> 50*7c478bd9Sstevel@tonic-gate #include <sys/machtrap.h> 51*7c478bd9Sstevel@tonic-gate #include <sys/ontrap.h> 52*7c478bd9Sstevel@tonic-gate #include <sys/ivintr.h> 53*7c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 54*7c478bd9Sstevel@tonic-gate #include <sys/panic.h> 55*7c478bd9Sstevel@tonic-gate #include <sys/dtrace.h> 56*7c478bd9Sstevel@tonic-gate #include <vm/seg_spt.h> 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate #define S_VAC_SIZE MMU_PAGESIZE /* XXXQ? */ 59*7c478bd9Sstevel@tonic-gate 60*7c478bd9Sstevel@tonic-gate /* 61*7c478bd9Sstevel@tonic-gate * Maximum number of contexts 62*7c478bd9Sstevel@tonic-gate */ 63*7c478bd9Sstevel@tonic-gate #define MAX_NCTXS (1 << 13) 64*7c478bd9Sstevel@tonic-gate 65*7c478bd9Sstevel@tonic-gate uint_t root_phys_addr_lo_mask = 0xffffffffU; 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate void 68*7c478bd9Sstevel@tonic-gate cpu_setup(void) 69*7c478bd9Sstevel@tonic-gate { 70*7c478bd9Sstevel@tonic-gate extern int at_flags; 71*7c478bd9Sstevel@tonic-gate extern int disable_delay_tlb_flush, delay_tlb_flush; 72*7c478bd9Sstevel@tonic-gate extern int mmu_exported_pagesize_mask; 73*7c478bd9Sstevel@tonic-gate extern int get_cpu_pagesizes(void); 74*7c478bd9Sstevel@tonic-gate 75*7c478bd9Sstevel@tonic-gate cache |= (CACHE_PTAG | CACHE_IOCOHERENT); 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate at_flags = EF_SPARC_32PLUS | EF_SPARC_SUN_US1; /* XXXQ */ 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gate /* 80*7c478bd9Sstevel@tonic-gate * Use the maximum number of contexts available for Spitfire unless 81*7c478bd9Sstevel@tonic-gate * it has been tuned for debugging. 82*7c478bd9Sstevel@tonic-gate * We are checking against 0 here since this value can be patched 83*7c478bd9Sstevel@tonic-gate * while booting. It can not be patched via /etc/system since it 84*7c478bd9Sstevel@tonic-gate * will be patched too late and thus cause the system to panic. 85*7c478bd9Sstevel@tonic-gate */ 86*7c478bd9Sstevel@tonic-gate if (nctxs == 0) 87*7c478bd9Sstevel@tonic-gate nctxs = MAX_NCTXS; 88*7c478bd9Sstevel@tonic-gate 89*7c478bd9Sstevel@tonic-gate if (use_page_coloring) { 90*7c478bd9Sstevel@tonic-gate do_pg_coloring = 1; 91*7c478bd9Sstevel@tonic-gate if (use_virtual_coloring) 92*7c478bd9Sstevel@tonic-gate do_virtual_coloring = 1; 93*7c478bd9Sstevel@tonic-gate } 94*7c478bd9Sstevel@tonic-gate /* 95*7c478bd9Sstevel@tonic-gate * Initalize supported page sizes information before the PD. 96*7c478bd9Sstevel@tonic-gate * If no information is available, then initialize the 97*7c478bd9Sstevel@tonic-gate * mmu_exported_pagesize_mask to a reasonable value for that processor. 98*7c478bd9Sstevel@tonic-gate */ 99*7c478bd9Sstevel@tonic-gate mmu_exported_pagesize_mask = get_cpu_pagesizes(); 100*7c478bd9Sstevel@tonic-gate if (mmu_exported_pagesize_mask <= 0) { 101*7c478bd9Sstevel@tonic-gate mmu_exported_pagesize_mask = (1 << TTE8K) | (1 << TTE64K) | 102*7c478bd9Sstevel@tonic-gate (1 << TTE4M); 103*7c478bd9Sstevel@tonic-gate } 104*7c478bd9Sstevel@tonic-gate 105*7c478bd9Sstevel@tonic-gate /* 106*7c478bd9Sstevel@tonic-gate * Tune pp_slots to use up to 1/8th of the tlb entries. 107*7c478bd9Sstevel@tonic-gate */ 108*7c478bd9Sstevel@tonic-gate pp_slots = MIN(8, MAXPP_SLOTS); 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate /* 111*7c478bd9Sstevel@tonic-gate * Block stores invalidate all pages of the d$ so pagecopy 112*7c478bd9Sstevel@tonic-gate * et. al. do not need virtual translations with virtual 113*7c478bd9Sstevel@tonic-gate * coloring taken into consideration. 114*7c478bd9Sstevel@tonic-gate */ 115*7c478bd9Sstevel@tonic-gate pp_consistent_coloring = 0; 116*7c478bd9Sstevel@tonic-gate isa_list = 117*7c478bd9Sstevel@tonic-gate "sparcv9+vis sparcv9 " 118*7c478bd9Sstevel@tonic-gate "sparcv8plus+vis sparcv8plus " 119*7c478bd9Sstevel@tonic-gate "sparcv8 sparcv8-fsmuld sparcv7 sparc"; 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate /* 122*7c478bd9Sstevel@tonic-gate * On Spitfire, there's a hole in the address space 123*7c478bd9Sstevel@tonic-gate * that we must never map (the hardware only support 44-bits of 124*7c478bd9Sstevel@tonic-gate * virtual address). Later CPUs are expected to have wider 125*7c478bd9Sstevel@tonic-gate * supported address ranges. 126*7c478bd9Sstevel@tonic-gate * 127*7c478bd9Sstevel@tonic-gate * See address map on p23 of the UltraSPARC 1 user's manual. 128*7c478bd9Sstevel@tonic-gate */ 129*7c478bd9Sstevel@tonic-gate /* XXXQ get from machine description */ 130*7c478bd9Sstevel@tonic-gate hole_start = (caddr_t)0x80000000000ull; 131*7c478bd9Sstevel@tonic-gate hole_end = (caddr_t)0xfffff80000000000ull; 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate /* 134*7c478bd9Sstevel@tonic-gate * The kpm mapping window. 135*7c478bd9Sstevel@tonic-gate * kpm_size: 136*7c478bd9Sstevel@tonic-gate * The size of a single kpm range. 137*7c478bd9Sstevel@tonic-gate * The overall size will be: kpm_size * vac_colors. 138*7c478bd9Sstevel@tonic-gate * kpm_vbase: 139*7c478bd9Sstevel@tonic-gate * The virtual start address of the kpm range within the kernel 140*7c478bd9Sstevel@tonic-gate * virtual address space. kpm_vbase has to be kpm_size aligned. 141*7c478bd9Sstevel@tonic-gate */ 142*7c478bd9Sstevel@tonic-gate kpm_size = (size_t)(2ull * 1024 * 1024 * 1024 * 1024); /* 2TB */ 143*7c478bd9Sstevel@tonic-gate kpm_size_shift = 41; 144*7c478bd9Sstevel@tonic-gate kpm_vbase = (caddr_t)0xfffffa0000000000ull; /* 16EB - 6TB */ 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate /* 147*7c478bd9Sstevel@tonic-gate * The traptrace code uses either %tick or %stick for 148*7c478bd9Sstevel@tonic-gate * timestamping. We have %stick so we can use it. 149*7c478bd9Sstevel@tonic-gate */ 150*7c478bd9Sstevel@tonic-gate traptrace_use_stick = 1; 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate /* 153*7c478bd9Sstevel@tonic-gate * sun4v provides demap_all 154*7c478bd9Sstevel@tonic-gate */ 155*7c478bd9Sstevel@tonic-gate if (!disable_delay_tlb_flush) 156*7c478bd9Sstevel@tonic-gate delay_tlb_flush = 1; 157*7c478bd9Sstevel@tonic-gate } 158*7c478bd9Sstevel@tonic-gate 159*7c478bd9Sstevel@tonic-gate /* 160*7c478bd9Sstevel@tonic-gate * Set the magic constants of the implementation. 161*7c478bd9Sstevel@tonic-gate */ 162*7c478bd9Sstevel@tonic-gate void 163*7c478bd9Sstevel@tonic-gate cpu_fiximp(struct cpu_node *cpunode) 164*7c478bd9Sstevel@tonic-gate { 165*7c478bd9Sstevel@tonic-gate extern int vac_size, vac_shift; 166*7c478bd9Sstevel@tonic-gate extern uint_t vac_mask; 167*7c478bd9Sstevel@tonic-gate int i, a; 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate /* 170*7c478bd9Sstevel@tonic-gate * The assumption here is that fillsysinfo will eventually 171*7c478bd9Sstevel@tonic-gate * have code to fill this info in from the PD. 172*7c478bd9Sstevel@tonic-gate * We hard code this for now. 173*7c478bd9Sstevel@tonic-gate * Once the PD access library is done this code 174*7c478bd9Sstevel@tonic-gate * might need to be changed to get the info from the PD 175*7c478bd9Sstevel@tonic-gate */ 176*7c478bd9Sstevel@tonic-gate /* 177*7c478bd9Sstevel@tonic-gate * Page Coloring defaults for sun4v 178*7c478bd9Sstevel@tonic-gate */ 179*7c478bd9Sstevel@tonic-gate ecache_setsize = 0x100000; 180*7c478bd9Sstevel@tonic-gate ecache_alignsize = 64; 181*7c478bd9Sstevel@tonic-gate cpunode->ecache_setsize = 0x100000; 182*7c478bd9Sstevel@tonic-gate 183*7c478bd9Sstevel@tonic-gate vac_size = S_VAC_SIZE; 184*7c478bd9Sstevel@tonic-gate vac_mask = MMU_PAGEMASK & (vac_size - 1); 185*7c478bd9Sstevel@tonic-gate i = 0; a = vac_size; 186*7c478bd9Sstevel@tonic-gate while (a >>= 1) 187*7c478bd9Sstevel@tonic-gate ++i; 188*7c478bd9Sstevel@tonic-gate vac_shift = i; 189*7c478bd9Sstevel@tonic-gate shm_alignment = vac_size; 190*7c478bd9Sstevel@tonic-gate vac = 0; 191*7c478bd9Sstevel@tonic-gate } 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate void 194*7c478bd9Sstevel@tonic-gate dtrace_flush_sec(uintptr_t addr) 195*7c478bd9Sstevel@tonic-gate { 196*7c478bd9Sstevel@tonic-gate pfn_t pfn; 197*7c478bd9Sstevel@tonic-gate proc_t *procp = ttoproc(curthread); 198*7c478bd9Sstevel@tonic-gate page_t *pp; 199*7c478bd9Sstevel@tonic-gate caddr_t va; 200*7c478bd9Sstevel@tonic-gate 201*7c478bd9Sstevel@tonic-gate pfn = hat_getpfnum(procp->p_as->a_hat, (void *)addr); 202*7c478bd9Sstevel@tonic-gate if (pfn != -1) { 203*7c478bd9Sstevel@tonic-gate ASSERT(pf_is_memory(pfn)); 204*7c478bd9Sstevel@tonic-gate pp = page_numtopp_noreclaim(pfn, SE_SHARED); 205*7c478bd9Sstevel@tonic-gate if (pp != NULL) { 206*7c478bd9Sstevel@tonic-gate va = ppmapin(pp, PROT_READ | PROT_WRITE, (void *)addr); 207*7c478bd9Sstevel@tonic-gate /* sparc needs 8-byte align */ 208*7c478bd9Sstevel@tonic-gate doflush((caddr_t)((uintptr_t)va & -8l)); 209*7c478bd9Sstevel@tonic-gate ppmapout(va); 210*7c478bd9Sstevel@tonic-gate page_unlock(pp); 211*7c478bd9Sstevel@tonic-gate } 212*7c478bd9Sstevel@tonic-gate } 213*7c478bd9Sstevel@tonic-gate } 214*7c478bd9Sstevel@tonic-gate 215*7c478bd9Sstevel@tonic-gate void 216*7c478bd9Sstevel@tonic-gate cpu_init_private(struct cpu *cp) 217*7c478bd9Sstevel@tonic-gate { 218*7c478bd9Sstevel@tonic-gate } 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate void 221*7c478bd9Sstevel@tonic-gate cpu_uninit_private(struct cpu *cp) 222*7c478bd9Sstevel@tonic-gate { 223*7c478bd9Sstevel@tonic-gate } 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate /* 226*7c478bd9Sstevel@tonic-gate * Invalidate a TSB. Since this needs to work on all sun4v 227*7c478bd9Sstevel@tonic-gate * architecture compliant processors, we use the old method of 228*7c478bd9Sstevel@tonic-gate * walking the TSB, setting each tag to TSBTAG_INVALID. 229*7c478bd9Sstevel@tonic-gate */ 230*7c478bd9Sstevel@tonic-gate void 231*7c478bd9Sstevel@tonic-gate cpu_inv_tsb(caddr_t tsb_base, uint_t tsb_bytes) 232*7c478bd9Sstevel@tonic-gate { 233*7c478bd9Sstevel@tonic-gate struct tsbe *tsbaddr; 234*7c478bd9Sstevel@tonic-gate 235*7c478bd9Sstevel@tonic-gate for (tsbaddr = (struct tsbe *)tsb_base; 236*7c478bd9Sstevel@tonic-gate (uintptr_t)tsbaddr < (uintptr_t)(tsb_base + tsb_bytes); 237*7c478bd9Sstevel@tonic-gate tsbaddr++) { 238*7c478bd9Sstevel@tonic-gate tsbaddr->tte_tag.tag_inthi = TSBTAG_INVALID; 239*7c478bd9Sstevel@tonic-gate } 240*7c478bd9Sstevel@tonic-gate } 241