xref: /titanic_53/usr/src/uts/sun4v/cpu/generic.c (revision ce0352eb406e3bc76c5885dfb72e99d53bdb985d)
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
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
247c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate #include <sys/systm.h>
317c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
327c478bd9Sstevel@tonic-gate #include <sys/machparam.h>
337c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
347c478bd9Sstevel@tonic-gate #include <sys/cpu.h>
357c478bd9Sstevel@tonic-gate #include <sys/elf_SPARC.h>
367c478bd9Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
377c478bd9Sstevel@tonic-gate #include <vm/page.h>
387c478bd9Sstevel@tonic-gate #include <sys/cpuvar.h>
397c478bd9Sstevel@tonic-gate #include <sys/async.h>
407c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
417c478bd9Sstevel@tonic-gate #include <sys/debug.h>
427c478bd9Sstevel@tonic-gate #include <sys/dditypes.h>
437c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
447c478bd9Sstevel@tonic-gate #include <sys/cpu_module.h>
457c478bd9Sstevel@tonic-gate #include <sys/prom_debug.h>
467c478bd9Sstevel@tonic-gate #include <sys/vmsystm.h>
477c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h>
487c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
497c478bd9Sstevel@tonic-gate #include <sys/intreg.h>
507c478bd9Sstevel@tonic-gate #include <sys/machtrap.h>
517c478bd9Sstevel@tonic-gate #include <sys/ontrap.h>
527c478bd9Sstevel@tonic-gate #include <sys/ivintr.h>
537c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
547c478bd9Sstevel@tonic-gate #include <sys/panic.h>
557c478bd9Sstevel@tonic-gate #include <sys/dtrace.h>
567c478bd9Sstevel@tonic-gate #include <vm/seg_spt.h>
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate #define	S_VAC_SIZE	MMU_PAGESIZE /* XXXQ? */
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /*
617c478bd9Sstevel@tonic-gate  * Maximum number of contexts
627c478bd9Sstevel@tonic-gate  */
637c478bd9Sstevel@tonic-gate #define	MAX_NCTXS	(1 << 13)
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate uint_t root_phys_addr_lo_mask = 0xffffffffU;
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate void
687c478bd9Sstevel@tonic-gate cpu_setup(void)
697c478bd9Sstevel@tonic-gate {
707c478bd9Sstevel@tonic-gate 	extern int at_flags;
717c478bd9Sstevel@tonic-gate 	extern int disable_delay_tlb_flush, delay_tlb_flush;
727c478bd9Sstevel@tonic-gate 	extern int mmu_exported_pagesize_mask;
737c478bd9Sstevel@tonic-gate 	extern int get_cpu_pagesizes(void);
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate 	cache |= (CACHE_PTAG | CACHE_IOCOHERENT);
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate 	at_flags = EF_SPARC_32PLUS | EF_SPARC_SUN_US1; /* XXXQ */
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	/*
807c478bd9Sstevel@tonic-gate 	 * Use the maximum number of contexts available for Spitfire unless
817c478bd9Sstevel@tonic-gate 	 * it has been tuned for debugging.
827c478bd9Sstevel@tonic-gate 	 * We are checking against 0 here since this value can be patched
837c478bd9Sstevel@tonic-gate 	 * while booting.  It can not be patched via /etc/system since it
847c478bd9Sstevel@tonic-gate 	 * will be patched too late and thus cause the system to panic.
857c478bd9Sstevel@tonic-gate 	 */
867c478bd9Sstevel@tonic-gate 	if (nctxs == 0)
877c478bd9Sstevel@tonic-gate 		nctxs = MAX_NCTXS;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	if (use_page_coloring) {
907c478bd9Sstevel@tonic-gate 		do_pg_coloring = 1;
917c478bd9Sstevel@tonic-gate 		if (use_virtual_coloring)
927c478bd9Sstevel@tonic-gate 			do_virtual_coloring = 1;
937c478bd9Sstevel@tonic-gate 	}
947c478bd9Sstevel@tonic-gate 	/*
957c478bd9Sstevel@tonic-gate 	 * Initalize supported page sizes information before the PD.
967c478bd9Sstevel@tonic-gate 	 * If no information is available, then initialize the
977c478bd9Sstevel@tonic-gate 	 * mmu_exported_pagesize_mask to a reasonable value for that processor.
987c478bd9Sstevel@tonic-gate 	 */
997c478bd9Sstevel@tonic-gate 	mmu_exported_pagesize_mask = get_cpu_pagesizes();
1007c478bd9Sstevel@tonic-gate 	if (mmu_exported_pagesize_mask <= 0) {
1017c478bd9Sstevel@tonic-gate 		mmu_exported_pagesize_mask = (1 << TTE8K) | (1 << TTE64K) |
1027c478bd9Sstevel@tonic-gate 		    (1 << TTE4M);
1037c478bd9Sstevel@tonic-gate 	}
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 	/*
1067c478bd9Sstevel@tonic-gate 	 * Tune pp_slots to use up to 1/8th of the tlb entries.
1077c478bd9Sstevel@tonic-gate 	 */
1087c478bd9Sstevel@tonic-gate 	pp_slots = MIN(8, MAXPP_SLOTS);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	/*
1117c478bd9Sstevel@tonic-gate 	 * Block stores invalidate all pages of the d$ so pagecopy
1127c478bd9Sstevel@tonic-gate 	 * et. al. do not need virtual translations with virtual
1137c478bd9Sstevel@tonic-gate 	 * coloring taken into consideration.
1147c478bd9Sstevel@tonic-gate 	 */
1157c478bd9Sstevel@tonic-gate 	pp_consistent_coloring = 0;
1167c478bd9Sstevel@tonic-gate 	isa_list =
1177c478bd9Sstevel@tonic-gate 	    "sparcv9+vis sparcv9 "
1187c478bd9Sstevel@tonic-gate 	    "sparcv8plus+vis sparcv8plus "
1197c478bd9Sstevel@tonic-gate 	    "sparcv8 sparcv8-fsmuld sparcv7 sparc";
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	/*
1227c478bd9Sstevel@tonic-gate 	 * On Spitfire, there's a hole in the address space
1237c478bd9Sstevel@tonic-gate 	 * that we must never map (the hardware only support 44-bits of
1247c478bd9Sstevel@tonic-gate 	 * virtual address).  Later CPUs are expected to have wider
1257c478bd9Sstevel@tonic-gate 	 * supported address ranges.
1267c478bd9Sstevel@tonic-gate 	 *
1277c478bd9Sstevel@tonic-gate 	 * See address map on p23 of the UltraSPARC 1 user's manual.
1287c478bd9Sstevel@tonic-gate 	 */
1297c478bd9Sstevel@tonic-gate /* XXXQ get from machine description */
1307c478bd9Sstevel@tonic-gate 	hole_start = (caddr_t)0x80000000000ull;
1317c478bd9Sstevel@tonic-gate 	hole_end = (caddr_t)0xfffff80000000000ull;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	/*
1347c478bd9Sstevel@tonic-gate 	 * The kpm mapping window.
1357c478bd9Sstevel@tonic-gate 	 * kpm_size:
1367c478bd9Sstevel@tonic-gate 	 *	The size of a single kpm range.
1377c478bd9Sstevel@tonic-gate 	 *	The overall size will be: kpm_size * vac_colors.
1387c478bd9Sstevel@tonic-gate 	 * kpm_vbase:
1397c478bd9Sstevel@tonic-gate 	 *	The virtual start address of the kpm range within the kernel
1407c478bd9Sstevel@tonic-gate 	 *	virtual address space. kpm_vbase has to be kpm_size aligned.
1417c478bd9Sstevel@tonic-gate 	 */
1427c478bd9Sstevel@tonic-gate 	kpm_size = (size_t)(2ull * 1024 * 1024 * 1024 * 1024); /* 2TB */
1437c478bd9Sstevel@tonic-gate 	kpm_size_shift = 41;
1447c478bd9Sstevel@tonic-gate 	kpm_vbase = (caddr_t)0xfffffa0000000000ull; /* 16EB - 6TB */
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate 	/*
1477c478bd9Sstevel@tonic-gate 	 * The traptrace code uses either %tick or %stick for
1487c478bd9Sstevel@tonic-gate 	 * timestamping.  We have %stick so we can use it.
1497c478bd9Sstevel@tonic-gate 	 */
1507c478bd9Sstevel@tonic-gate 	traptrace_use_stick = 1;
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	/*
1537c478bd9Sstevel@tonic-gate 	 * sun4v provides demap_all
1547c478bd9Sstevel@tonic-gate 	 */
1557c478bd9Sstevel@tonic-gate 	if (!disable_delay_tlb_flush)
1567c478bd9Sstevel@tonic-gate 		delay_tlb_flush = 1;
1577c478bd9Sstevel@tonic-gate }
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate /*
1607c478bd9Sstevel@tonic-gate  * Set the magic constants of the implementation.
1617c478bd9Sstevel@tonic-gate  */
1627c478bd9Sstevel@tonic-gate void
1637c478bd9Sstevel@tonic-gate cpu_fiximp(struct cpu_node *cpunode)
1647c478bd9Sstevel@tonic-gate {
1657c478bd9Sstevel@tonic-gate 	extern int vac_size, vac_shift;
1667c478bd9Sstevel@tonic-gate 	extern uint_t vac_mask;
1677c478bd9Sstevel@tonic-gate 	int i, a;
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 	/*
1707c478bd9Sstevel@tonic-gate 	 * The assumption here is that fillsysinfo will eventually
1717c478bd9Sstevel@tonic-gate 	 * have code to fill this info in from the PD.
1727c478bd9Sstevel@tonic-gate 	 * We hard code this for now.
1737c478bd9Sstevel@tonic-gate 	 * Once the PD access library is done this code
1747c478bd9Sstevel@tonic-gate 	 * might need to be changed to get the info from the PD
1757c478bd9Sstevel@tonic-gate 	 */
1767c478bd9Sstevel@tonic-gate 	/*
1777c478bd9Sstevel@tonic-gate 	 * Page Coloring defaults for sun4v
1787c478bd9Sstevel@tonic-gate 	 */
1797c478bd9Sstevel@tonic-gate 	ecache_setsize = 0x100000;
1807c478bd9Sstevel@tonic-gate 	ecache_alignsize = 64;
1817c478bd9Sstevel@tonic-gate 	cpunode->ecache_setsize =  0x100000;
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	vac_size = S_VAC_SIZE;
1847c478bd9Sstevel@tonic-gate 	vac_mask = MMU_PAGEMASK & (vac_size - 1);
1857c478bd9Sstevel@tonic-gate 	i = 0; a = vac_size;
1867c478bd9Sstevel@tonic-gate 	while (a >>= 1)
1877c478bd9Sstevel@tonic-gate 		++i;
1887c478bd9Sstevel@tonic-gate 	vac_shift = i;
1897c478bd9Sstevel@tonic-gate 	shm_alignment = vac_size;
1907c478bd9Sstevel@tonic-gate 	vac = 0;
1917c478bd9Sstevel@tonic-gate }
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate void
1947c478bd9Sstevel@tonic-gate dtrace_flush_sec(uintptr_t addr)
1957c478bd9Sstevel@tonic-gate {
1967c478bd9Sstevel@tonic-gate 	pfn_t pfn;
1977c478bd9Sstevel@tonic-gate 	proc_t *procp = ttoproc(curthread);
1987c478bd9Sstevel@tonic-gate 	page_t *pp;
1997c478bd9Sstevel@tonic-gate 	caddr_t va;
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	pfn = hat_getpfnum(procp->p_as->a_hat, (void *)addr);
2027c478bd9Sstevel@tonic-gate 	if (pfn != -1) {
2037c478bd9Sstevel@tonic-gate 		ASSERT(pf_is_memory(pfn));
2047c478bd9Sstevel@tonic-gate 		pp = page_numtopp_noreclaim(pfn, SE_SHARED);
2057c478bd9Sstevel@tonic-gate 		if (pp != NULL) {
2067c478bd9Sstevel@tonic-gate 			va = ppmapin(pp, PROT_READ | PROT_WRITE, (void *)addr);
2077c478bd9Sstevel@tonic-gate 			/* sparc needs 8-byte align */
2087c478bd9Sstevel@tonic-gate 			doflush((caddr_t)((uintptr_t)va & -8l));
2097c478bd9Sstevel@tonic-gate 			ppmapout(va);
2107c478bd9Sstevel@tonic-gate 			page_unlock(pp);
2117c478bd9Sstevel@tonic-gate 		}
2127c478bd9Sstevel@tonic-gate 	}
2137c478bd9Sstevel@tonic-gate }
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate void
2167c478bd9Sstevel@tonic-gate cpu_init_private(struct cpu *cp)
2177c478bd9Sstevel@tonic-gate {
21870f54eadSesaxe 	/*
21970f54eadSesaxe 	 * The cpu_ipipe field is initialized based on the execution
22070f54eadSesaxe 	 * unit sharing information from the Machine Description table.
22170f54eadSesaxe 	 * It defaults to the CPU id in the absence of such information.
22270f54eadSesaxe 	 */
22370f54eadSesaxe 	cp->cpu_m.cpu_ipipe = (id_t)(cp->cpu_id);
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate void
2277c478bd9Sstevel@tonic-gate cpu_uninit_private(struct cpu *cp)
2287c478bd9Sstevel@tonic-gate {
2297c478bd9Sstevel@tonic-gate }
2307c478bd9Sstevel@tonic-gate 
2317c478bd9Sstevel@tonic-gate /*
2327c478bd9Sstevel@tonic-gate  * Invalidate a TSB. Since this needs to work on all sun4v
2337c478bd9Sstevel@tonic-gate  * architecture compliant processors, we use the old method of
2347c478bd9Sstevel@tonic-gate  * walking the TSB, setting each tag to TSBTAG_INVALID.
2357c478bd9Sstevel@tonic-gate  */
2367c478bd9Sstevel@tonic-gate void
2377c478bd9Sstevel@tonic-gate cpu_inv_tsb(caddr_t tsb_base, uint_t tsb_bytes)
2387c478bd9Sstevel@tonic-gate {
2397c478bd9Sstevel@tonic-gate 	struct tsbe *tsbaddr;
2407c478bd9Sstevel@tonic-gate 
2417c478bd9Sstevel@tonic-gate 	for (tsbaddr = (struct tsbe *)tsb_base;
2427c478bd9Sstevel@tonic-gate 	    (uintptr_t)tsbaddr < (uintptr_t)(tsb_base + tsb_bytes);
2437c478bd9Sstevel@tonic-gate 	    tsbaddr++) {
2447c478bd9Sstevel@tonic-gate 		tsbaddr->tte_tag.tag_inthi = TSBTAG_INVALID;
2457c478bd9Sstevel@tonic-gate 	}
2467c478bd9Sstevel@tonic-gate }
247*ce0352ebSgirish 
248*ce0352ebSgirish /*
249*ce0352ebSgirish  * Trapstat support for generic sun4v processor
250*ce0352ebSgirish  */
251*ce0352ebSgirish int
252*ce0352ebSgirish cpu_trapstat_conf(int cmd)
253*ce0352ebSgirish {
254*ce0352ebSgirish 	int status;
255*ce0352ebSgirish 
256*ce0352ebSgirish 	switch (cmd) {
257*ce0352ebSgirish 	case CPU_TSTATCONF_INIT:
258*ce0352ebSgirish 	case CPU_TSTATCONF_FINI:
259*ce0352ebSgirish 	case CPU_TSTATCONF_ENABLE:
260*ce0352ebSgirish 	case CPU_TSTATCONF_DISABLE:
261*ce0352ebSgirish 		status = ENOTSUP;
262*ce0352ebSgirish 		break;
263*ce0352ebSgirish 
264*ce0352ebSgirish 	default:
265*ce0352ebSgirish 		status = EINVAL;
266*ce0352ebSgirish 		break;
267*ce0352ebSgirish 	}
268*ce0352ebSgirish 	return (status);
269*ce0352ebSgirish }
270*ce0352ebSgirish 
271*ce0352ebSgirish /*ARGSUSED*/
272*ce0352ebSgirish void
273*ce0352ebSgirish cpu_trapstat_data(void *buf, uint_t tstat_pgszs)
274*ce0352ebSgirish {
275*ce0352ebSgirish }
276