xref: /onnv-gate/usr/src/uts/sun4v/cpu/niagara2.c (revision 3177:6d48ee59c4fc)
13156Sgirish /*
23156Sgirish  * CDDL HEADER START
33156Sgirish  *
43156Sgirish  * The contents of this file are subject to the terms of the
53156Sgirish  * Common Development and Distribution License (the "License").
63156Sgirish  * You may not use this file except in compliance with the License.
73156Sgirish  *
83156Sgirish  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
93156Sgirish  * or http://www.opensolaris.org/os/licensing.
103156Sgirish  * See the License for the specific language governing permissions
113156Sgirish  * and limitations under the License.
123156Sgirish  *
133156Sgirish  * When distributing Covered Code, include this CDDL HEADER in each
143156Sgirish  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
153156Sgirish  * If applicable, add the following below this CDDL HEADER, with the
163156Sgirish  * fields enclosed by brackets "[]" replaced with your own identifying
173156Sgirish  * information: Portions Copyright [yyyy] [name of copyright owner]
183156Sgirish  *
193156Sgirish  * CDDL HEADER END
203156Sgirish  */
213156Sgirish /*
223156Sgirish  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
233156Sgirish  * Use is subject to license terms.
243156Sgirish  */
253156Sgirish 
263156Sgirish #pragma ident	"%Z%%M%	%I%	%E% SMI"
273156Sgirish 
283156Sgirish #include <sys/types.h>
293156Sgirish #include <sys/systm.h>
303156Sgirish #include <sys/archsystm.h>
313156Sgirish #include <sys/machparam.h>
323156Sgirish #include <sys/machsystm.h>
333156Sgirish #include <sys/cpu.h>
343156Sgirish #include <sys/elf_SPARC.h>
353156Sgirish #include <vm/hat_sfmmu.h>
363156Sgirish #include <vm/page.h>
37*3177Sdp78419 #include <vm/vm_dep.h>
383156Sgirish #include <sys/cpuvar.h>
393156Sgirish #include <sys/async.h>
403156Sgirish #include <sys/cmn_err.h>
413156Sgirish #include <sys/debug.h>
423156Sgirish #include <sys/dditypes.h>
433156Sgirish #include <sys/sunddi.h>
443156Sgirish #include <sys/cpu_module.h>
453156Sgirish #include <sys/prom_debug.h>
463156Sgirish #include <sys/vmsystm.h>
473156Sgirish #include <sys/prom_plat.h>
483156Sgirish #include <sys/sysmacros.h>
493156Sgirish #include <sys/intreg.h>
503156Sgirish #include <sys/machtrap.h>
513156Sgirish #include <sys/ontrap.h>
523156Sgirish #include <sys/ivintr.h>
533156Sgirish #include <sys/atomic.h>
543156Sgirish #include <sys/panic.h>
553156Sgirish #include <sys/dtrace.h>
563156Sgirish #include <sys/simulate.h>
573156Sgirish #include <sys/fault.h>
583156Sgirish #include <sys/niagara2regs.h>
593156Sgirish #include <sys/hsvc.h>
603156Sgirish #include <sys/trapstat.h>
613156Sgirish 
623156Sgirish uint_t root_phys_addr_lo_mask = 0xffffffffU;
633156Sgirish char cpu_module_name[] = "SUNW,UltraSPARC-T2";
643156Sgirish 
653156Sgirish /*
663156Sgirish  * Hypervisor services information for the NIAGARA2 CPU module
673156Sgirish  */
683156Sgirish static boolean_t niagara2_hsvc_available = B_TRUE;
693156Sgirish static uint64_t niagara2_sup_minor;		/* Supported minor number */
703156Sgirish static hsvc_info_t niagara2_hsvc = {
713156Sgirish 	HSVC_REV_1, NULL, HSVC_GROUP_NIAGARA2_CPU, NIAGARA2_HSVC_MAJOR,
723156Sgirish 	NIAGARA2_HSVC_MINOR, cpu_module_name
733156Sgirish };
743156Sgirish 
753156Sgirish void
763156Sgirish cpu_setup(void)
773156Sgirish {
783156Sgirish 	extern int mmu_exported_pagesize_mask;
793156Sgirish 	extern int cpc_has_overflow_intr;
803156Sgirish 	int status;
813156Sgirish 
823156Sgirish 	/*
833156Sgirish 	 * Negotiate the API version for Niagara2 specific hypervisor
843156Sgirish 	 * services.
853156Sgirish 	 */
863156Sgirish 	status = hsvc_register(&niagara2_hsvc, &niagara2_sup_minor);
873156Sgirish 	if (status != 0) {
883156Sgirish 		cmn_err(CE_WARN, "%s: cannot negotiate hypervisor services "
893156Sgirish 		    "group: 0x%lx major: 0x%lx minor: 0x%lx errno: %d",
903156Sgirish 		    niagara2_hsvc.hsvc_modname, niagara2_hsvc.hsvc_group,
913156Sgirish 		    niagara2_hsvc.hsvc_major, niagara2_hsvc.hsvc_minor, status);
923156Sgirish 		niagara2_hsvc_available = B_FALSE;
933156Sgirish 	}
943156Sgirish 
953156Sgirish 	/*
963156Sgirish 	 * The setup common to all CPU modules is done in cpu_setup_common
973156Sgirish 	 * routine.
983156Sgirish 	 */
993156Sgirish 	cpu_setup_common(NULL);
1003156Sgirish 
1013156Sgirish 	cache |= (CACHE_PTAG | CACHE_IOCOHERENT);
1023156Sgirish 
1033156Sgirish 	if ((mmu_exported_pagesize_mask &
1043156Sgirish 	    DEFAULT_SUN4V_MMU_PAGESIZE_MASK) !=
1053156Sgirish 	    DEFAULT_SUN4V_MMU_PAGESIZE_MASK)
1063156Sgirish 		cmn_err(CE_PANIC, "machine description"
1073156Sgirish 		    " does not have required sun4v page sizes"
1083156Sgirish 		    " 8K, 64K and 4M: MD mask is 0x%x",
1093156Sgirish 		    mmu_exported_pagesize_mask);
1103156Sgirish 
1113156Sgirish 	cpu_hwcap_flags = AV_SPARC_VIS | AV_SPARC_VIS2 | AV_SPARC_ASI_BLK_INIT;
1123156Sgirish 
1133156Sgirish 	/*
1143156Sgirish 	 * Niagara2 supports a 48-bit subset of the full 64-bit virtual
1153156Sgirish 	 * address space. Virtual addresses between 0x0000800000000000
1163156Sgirish 	 * and 0xffff.7fff.ffff.ffff inclusive lie within a "VA Hole"
1173156Sgirish 	 * and must never be mapped. In addition, software must not use
1183156Sgirish 	 * pages within 4GB of the VA hole as instruction pages to
1193156Sgirish 	 * avoid problems with prefetching into the VA hole.
1203156Sgirish 	 */
1213156Sgirish 	hole_start = (caddr_t)((1ull << (va_bits - 1)) - (1ull << 32));
1223156Sgirish 	hole_end = (caddr_t)((0ull - (1ull << (va_bits - 1))) + (1ull << 32));
1233156Sgirish 
1243156Sgirish 	/*
1253156Sgirish 	 * Niagara2 has a performance counter overflow interrupt
1263156Sgirish 	 */
1273156Sgirish 	cpc_has_overflow_intr = 1;
128*3177Sdp78419 
129*3177Sdp78419 	/*
130*3177Sdp78419 	 * Enable 4M pages for OOB.
131*3177Sdp78419 	 */
132*3177Sdp78419 	max_uheap_lpsize = MMU_PAGESIZE4M;
133*3177Sdp78419 	max_ustack_lpsize = MMU_PAGESIZE4M;
134*3177Sdp78419 	max_privmap_lpsize = MMU_PAGESIZE4M;
1353156Sgirish }
1363156Sgirish 
1373156Sgirish /*
1383156Sgirish  * Set the magic constants of the implementation.
1393156Sgirish  */
1403156Sgirish void
1413156Sgirish cpu_fiximp(struct cpu_node *cpunode)
1423156Sgirish {
1433156Sgirish 	/*
1443156Sgirish 	 * The Cache node is optional in MD. Therefore in case "Cache"
1453156Sgirish 	 * node does not exists in MD, set the default L2 cache associativity,
1463156Sgirish 	 * size, linesize.
1473156Sgirish 	 */
1483156Sgirish 	if (cpunode->ecache_size == 0)
1493156Sgirish 		cpunode->ecache_size = L2CACHE_SIZE;
1503156Sgirish 	if (cpunode->ecache_linesize == 0)
1513156Sgirish 		cpunode->ecache_linesize = L2CACHE_LINESIZE;
1523156Sgirish 	if (cpunode->ecache_associativity == 0)
1533156Sgirish 		cpunode->ecache_associativity = L2CACHE_ASSOCIATIVITY;
1543156Sgirish }
1553156Sgirish 
1563156Sgirish static int niagara2_cpucnt;
1573156Sgirish 
1583156Sgirish void
1593156Sgirish cpu_init_private(struct cpu *cp)
1603156Sgirish {
1613156Sgirish 	extern int niagara_kstat_init(void);
1623156Sgirish 
1633156Sgirish 	/*
1643156Sgirish 	 * The cpu_ipipe field is initialized based on the execution
1653156Sgirish 	 * unit sharing information from the MD. It defaults to the
1663156Sgirish 	 * virtual CPU id in the absence of such information.
1673156Sgirish 	 */
1683156Sgirish 	cp->cpu_m.cpu_ipipe = cpunodes[cp->cpu_id].exec_unit_mapping;
1693156Sgirish 	if (cp->cpu_m.cpu_ipipe == NO_EU_MAPPING_FOUND)
1703156Sgirish 		cp->cpu_m.cpu_ipipe = (id_t)(cp->cpu_id);
1713156Sgirish 
1723156Sgirish 	ASSERT(MUTEX_HELD(&cpu_lock));
1733156Sgirish 	if ((niagara2_cpucnt++ == 0) && (niagara2_hsvc_available == B_TRUE))
1743156Sgirish 		(void) niagara_kstat_init();
1753156Sgirish }
1763156Sgirish 
1773156Sgirish /*ARGSUSED*/
1783156Sgirish void
1793156Sgirish cpu_uninit_private(struct cpu *cp)
1803156Sgirish {
1813156Sgirish 	extern int niagara_kstat_fini(void);
1823156Sgirish 
1833156Sgirish 	ASSERT(MUTEX_HELD(&cpu_lock));
1843156Sgirish 	if ((--niagara2_cpucnt == 0) && (niagara2_hsvc_available == B_TRUE))
1853156Sgirish 		(void) niagara_kstat_fini();
1863156Sgirish }
1873156Sgirish 
1883156Sgirish /*
1893156Sgirish  * On Niagara2, any flush will cause all preceding stores to be
1903156Sgirish  * synchronized wrt the i$, regardless of address or ASI.  In fact,
1913156Sgirish  * the address is ignored, so we always flush address 0.
1923156Sgirish  */
1933156Sgirish /*ARGSUSED*/
1943156Sgirish void
1953156Sgirish dtrace_flush_sec(uintptr_t addr)
1963156Sgirish {
1973156Sgirish 	doflush(0);
1983156Sgirish }
1993156Sgirish 
2003156Sgirish /*
2013156Sgirish  * Trapstat support for Niagara2 processor
2023156Sgirish  * The Niagara2 provides HWTW support for TSB lookup and with HWTW
2033156Sgirish  * enabled no TSB hit information will be available. Therefore setting
2043156Sgirish  * the time spent in TLB miss handler for TSB hits to 0.
2053156Sgirish  */
2063156Sgirish int
2073156Sgirish cpu_trapstat_conf(int cmd)
2083156Sgirish {
2093156Sgirish 	int status = 0;
2103156Sgirish 
2113156Sgirish 	switch (cmd) {
2123156Sgirish 	case CPU_TSTATCONF_INIT:
2133156Sgirish 	case CPU_TSTATCONF_FINI:
2143156Sgirish 	case CPU_TSTATCONF_ENABLE:
2153156Sgirish 	case CPU_TSTATCONF_DISABLE:
2163156Sgirish 		break;
2173156Sgirish 	default:
2183156Sgirish 		status = EINVAL;
2193156Sgirish 		break;
2203156Sgirish 	}
2213156Sgirish 	return (status);
2223156Sgirish }
2233156Sgirish 
2243156Sgirish void
2253156Sgirish cpu_trapstat_data(void *buf, uint_t tstat_pgszs)
2263156Sgirish {
2273156Sgirish 	tstat_pgszdata_t	*tstatp = (tstat_pgszdata_t *)buf;
2283156Sgirish 	int	i;
2293156Sgirish 
2303156Sgirish 	for (i = 0; i < tstat_pgszs; i++, tstatp++) {
2313156Sgirish 		tstatp->tpgsz_kernel.tmode_itlb.ttlb_tlb.tmiss_count = 0;
2323156Sgirish 		tstatp->tpgsz_kernel.tmode_itlb.ttlb_tlb.tmiss_time = 0;
2333156Sgirish 		tstatp->tpgsz_user.tmode_itlb.ttlb_tlb.tmiss_count = 0;
2343156Sgirish 		tstatp->tpgsz_user.tmode_itlb.ttlb_tlb.tmiss_time = 0;
2353156Sgirish 		tstatp->tpgsz_kernel.tmode_dtlb.ttlb_tlb.tmiss_count = 0;
2363156Sgirish 		tstatp->tpgsz_kernel.tmode_dtlb.ttlb_tlb.tmiss_time = 0;
2373156Sgirish 		tstatp->tpgsz_user.tmode_dtlb.ttlb_tlb.tmiss_count = 0;
2383156Sgirish 		tstatp->tpgsz_user.tmode_dtlb.ttlb_tlb.tmiss_time = 0;
2393156Sgirish 	}
2403156Sgirish }
241*3177Sdp78419 
242*3177Sdp78419 /* NI2 L2$ index is pa[32:28]^pa[17:13].pa[19:18]^pa[12:11].pa[10:6] */
243*3177Sdp78419 uint_t
244*3177Sdp78419 page_pfn_2_color_cpu(pfn_t pfn, uchar_t szc)
245*3177Sdp78419 {
246*3177Sdp78419 	uint_t color;
247*3177Sdp78419 
248*3177Sdp78419 	ASSERT(szc <= TTE256M);
249*3177Sdp78419 
250*3177Sdp78419 	pfn = PFN_BASE(pfn, szc);
251*3177Sdp78419 	color = ((pfn >> 15) ^ pfn) & 0x1f;
252*3177Sdp78419 	if (szc >= TTE4M)
253*3177Sdp78419 		return (color);
254*3177Sdp78419 
255*3177Sdp78419 	color = (color << 2) | ((pfn >> 5) & 0x3);
256*3177Sdp78419 
257*3177Sdp78419 	return (szc <= TTE64K ? color : (color >> 1));
258*3177Sdp78419 }
259*3177Sdp78419 
260*3177Sdp78419 #if TTE256M != 5
261*3177Sdp78419 #error TTE256M is not 5
262*3177Sdp78419 #endif
263*3177Sdp78419 
264*3177Sdp78419 uint_t
265*3177Sdp78419 page_get_nsz_color_mask_cpu(uchar_t szc, uint_t mask)
266*3177Sdp78419 {
267*3177Sdp78419 	static uint_t ni2_color_masks[5] = {0x63, 0x1e, 0x3e, 0x1f, 0x1f};
268*3177Sdp78419 	ASSERT(szc < TTE256M);
269*3177Sdp78419 
270*3177Sdp78419 	mask &= ni2_color_masks[szc];
271*3177Sdp78419 	return ((szc == TTE64K || szc == TTE512K) ? (mask >> 1) : mask);
272*3177Sdp78419 }
273*3177Sdp78419 
274*3177Sdp78419 uint_t
275*3177Sdp78419 page_get_nsz_color_cpu(uchar_t szc, uint_t color)
276*3177Sdp78419 {
277*3177Sdp78419 	ASSERT(szc < TTE256M);
278*3177Sdp78419 	return ((szc == TTE64K || szc == TTE512K) ? (color >> 1) : color);
279*3177Sdp78419 }
280*3177Sdp78419 
281*3177Sdp78419 uint_t
282*3177Sdp78419 page_get_color_shift_cpu(uchar_t szc, uchar_t nszc)
283*3177Sdp78419 {
284*3177Sdp78419 	ASSERT(nszc > szc);
285*3177Sdp78419 	ASSERT(nszc <= TTE256M);
286*3177Sdp78419 
287*3177Sdp78419 	if (szc <= TTE64K)
288*3177Sdp78419 		return ((nszc >= TTE4M) ? 2 : ((nszc >= TTE512K) ? 1 : 0));
289*3177Sdp78419 	if (szc == TTE512K)
290*3177Sdp78419 		return (1);
291*3177Sdp78419 
292*3177Sdp78419 	return (0);
293*3177Sdp78419 }
294*3177Sdp78419 
295*3177Sdp78419 /*ARGSUSED*/
296*3177Sdp78419 pfn_t
297*3177Sdp78419 page_next_pfn_for_color_cpu(pfn_t pfn, uchar_t szc, uint_t color,
298*3177Sdp78419     uint_t ceq_mask, uint_t color_mask)
299*3177Sdp78419 {
300*3177Sdp78419 	pfn_t pstep = PNUM_SIZE(szc);
301*3177Sdp78419 	pfn_t npfn, pfn_ceq_mask, pfn_color;
302*3177Sdp78419 	pfn_t tmpmask, mask = (pfn_t)-1;
303*3177Sdp78419 
304*3177Sdp78419 	ASSERT((color & ~ceq_mask) == 0);
305*3177Sdp78419 
306*3177Sdp78419 	if (((page_pfn_2_color_cpu(pfn, szc) ^ color) & ceq_mask) == 0) {
307*3177Sdp78419 
308*3177Sdp78419 		/* we start from the page with correct color */
309*3177Sdp78419 		if (szc >= TTE512K) {
310*3177Sdp78419 			if (szc >= TTE4M) {
311*3177Sdp78419 				/* page color is PA[32:28] */
312*3177Sdp78419 				pfn_ceq_mask = ceq_mask << 15;
313*3177Sdp78419 			} else {
314*3177Sdp78419 				/* page color is PA[32:28].PA[19:19] */
315*3177Sdp78419 				pfn_ceq_mask = ((ceq_mask & 1) << 6) |
316*3177Sdp78419 				    ((ceq_mask >> 1) << 15);
317*3177Sdp78419 			}
318*3177Sdp78419 			pfn = ADD_MASKED(pfn, pstep, pfn_ceq_mask, mask);
319*3177Sdp78419 			return (pfn);
320*3177Sdp78419 		} else {
321*3177Sdp78419 			/*
322*3177Sdp78419 			 * We deal 64K or 8K page. Check if we could the
323*3177Sdp78419 			 * satisfy the request without changing PA[32:28]
324*3177Sdp78419 			 */
325*3177Sdp78419 			pfn_ceq_mask = ((ceq_mask & 3) << 5) | (ceq_mask >> 2);
326*3177Sdp78419 			npfn = ADD_MASKED(pfn, pstep, pfn_ceq_mask, mask);
327*3177Sdp78419 
328*3177Sdp78419 			if ((((npfn ^ pfn) >> 15) & 0x1f) == 0)
329*3177Sdp78419 				return (npfn);
330*3177Sdp78419 
331*3177Sdp78419 			/*
332*3177Sdp78419 			 * for next pfn we have to change bits PA[32:28]
333*3177Sdp78419 			 * set PA[63:28] and PA[19:18] of the next pfn
334*3177Sdp78419 			 */
335*3177Sdp78419 			npfn = (pfn >> 15) << 15;
336*3177Sdp78419 			npfn |= (ceq_mask & color & 3) << 5;
337*3177Sdp78419 			pfn_ceq_mask = (szc == TTE8K) ? 0 :
338*3177Sdp78419 			    (ceq_mask & 0x1c) << 13;
339*3177Sdp78419 			npfn = ADD_MASKED(npfn, (1 << 15), pfn_ceq_mask, mask);
340*3177Sdp78419 
341*3177Sdp78419 			/*
342*3177Sdp78419 			 * set bits PA[17:13] to match the color
343*3177Sdp78419 			 */
344*3177Sdp78419 			ceq_mask >>= 2;
345*3177Sdp78419 			color = (color >> 2) & ceq_mask;
346*3177Sdp78419 			npfn |= ((npfn >> 15) ^ color) & ceq_mask;
347*3177Sdp78419 			return (npfn);
348*3177Sdp78419 		}
349*3177Sdp78419 	}
350*3177Sdp78419 
351*3177Sdp78419 	/*
352*3177Sdp78419 	 * we start from the page with incorrect color - rare case
353*3177Sdp78419 	 */
354*3177Sdp78419 	if (szc >= TTE512K) {
355*3177Sdp78419 		if (szc >= TTE4M) {
356*3177Sdp78419 			/* page color is in bits PA[32:28] */
357*3177Sdp78419 			npfn = ((pfn >> 20) << 20) | (color << 15);
358*3177Sdp78419 			pfn_ceq_mask = (ceq_mask << 15) | 0x7fff;
359*3177Sdp78419 		} else {
360*3177Sdp78419 			/* try get the right color by changing bit PA[19:19] */
361*3177Sdp78419 			npfn = pfn + pstep;
362*3177Sdp78419 			if (((page_pfn_2_color_cpu(npfn, szc) ^ color) &
363*3177Sdp78419 			    ceq_mask) == 0)
364*3177Sdp78419 				return (npfn);
365*3177Sdp78419 
366*3177Sdp78419 			/* page color is PA[32:28].PA[19:19] */
367*3177Sdp78419 			pfn_ceq_mask = ((ceq_mask & 1) << 6) |
368*3177Sdp78419 			    ((ceq_mask >> 1) << 15) | (0xff << 7);
369*3177Sdp78419 			pfn_color = ((color & 1) << 6) | ((color >> 1) << 15);
370*3177Sdp78419 			npfn = ((pfn >> 20) << 20) | pfn_color;
371*3177Sdp78419 		}
372*3177Sdp78419 
373*3177Sdp78419 		while (npfn <= pfn) {
374*3177Sdp78419 			npfn = ADD_MASKED(npfn, pstep, pfn_ceq_mask, mask);
375*3177Sdp78419 		}
376*3177Sdp78419 		return (npfn);
377*3177Sdp78419 	}
378*3177Sdp78419 
379*3177Sdp78419 	/*
380*3177Sdp78419 	 * We deal 64K or 8K page of incorrect color.
381*3177Sdp78419 	 * Try correcting color without changing PA[32:28]
382*3177Sdp78419 	 */
383*3177Sdp78419 
384*3177Sdp78419 	pfn_ceq_mask = ((ceq_mask & 3) << 5) | (ceq_mask >> 2);
385*3177Sdp78419 	pfn_color = ((color & 3) << 5) | (color >> 2);
386*3177Sdp78419 	npfn = (pfn & ~(pfn_t)0x7f);
387*3177Sdp78419 	npfn |= (((pfn >> 15) & 0x1f) ^ pfn_color) & pfn_ceq_mask;
388*3177Sdp78419 	npfn = (szc == TTE64K) ? (npfn & ~(pfn_t)0x7) : npfn;
389*3177Sdp78419 
390*3177Sdp78419 	if (((page_pfn_2_color_cpu(npfn, szc) ^ color) & ceq_mask) == 0) {
391*3177Sdp78419 
392*3177Sdp78419 		/* the color is fixed - find the next page */
393*3177Sdp78419 		while (npfn <= pfn) {
394*3177Sdp78419 			npfn = ADD_MASKED(npfn, pstep, pfn_ceq_mask, mask);
395*3177Sdp78419 		}
396*3177Sdp78419 		if ((((npfn ^ pfn) >> 15) & 0x1f) == 0)
397*3177Sdp78419 			return (npfn);
398*3177Sdp78419 	}
399*3177Sdp78419 
400*3177Sdp78419 	/* to fix the color need to touch PA[32:28] */
401*3177Sdp78419 	npfn = (szc == TTE8K) ? ((pfn >> 15) << 15) :
402*3177Sdp78419 	    (((pfn >> 18) << 18) | ((color & 0x1c) << 13));
403*3177Sdp78419 	tmpmask = (szc == TTE8K) ? 0 : (ceq_mask & 0x1c) << 13;
404*3177Sdp78419 
405*3177Sdp78419 	while (npfn <= pfn) {
406*3177Sdp78419 		npfn = ADD_MASKED(npfn, (1 << 15), tmpmask, mask);
407*3177Sdp78419 	}
408*3177Sdp78419 
409*3177Sdp78419 	/* set bits PA[19:13] to match the color */
410*3177Sdp78419 	npfn |= (((npfn >> 15) & 0x1f) ^ pfn_color) & pfn_ceq_mask;
411*3177Sdp78419 	npfn = (szc == TTE64K) ? (npfn & ~(pfn_t)0x7) : npfn;
412*3177Sdp78419 
413*3177Sdp78419 	ASSERT(((page_pfn_2_color_cpu(npfn, szc) ^ color) & ceq_mask) == 0);
414*3177Sdp78419 
415*3177Sdp78419 	return (npfn);
416*3177Sdp78419 }
417*3177Sdp78419 
418*3177Sdp78419 /*
419*3177Sdp78419  * init page coloring
420*3177Sdp78419  */
421*3177Sdp78419 void
422*3177Sdp78419 page_coloring_init_cpu()
423*3177Sdp78419 {
424*3177Sdp78419 	int i;
425*3177Sdp78419 	uint_t colors;
426*3177Sdp78419 
427*3177Sdp78419 	hw_page_array[0].hp_colors = 1 << 7;
428*3177Sdp78419 	hw_page_array[1].hp_colors = 1 << 7;
429*3177Sdp78419 	hw_page_array[2].hp_colors = 1 << 6;
430*3177Sdp78419 
431*3177Sdp78419 	for (i = 3; i < mmu_page_sizes; i++) {
432*3177Sdp78419 		hw_page_array[i].hp_colors = 1 << 5;
433*3177Sdp78419 	}
434*3177Sdp78419 
435*3177Sdp78419 	if (colorequiv > 1) {
436*3177Sdp78419 		int a = lowbit(colorequiv) - 1;
437*3177Sdp78419 
438*3177Sdp78419 		if (a > 15)
439*3177Sdp78419 			a = 15;
440*3177Sdp78419 
441*3177Sdp78419 		for (i = 0; i < mmu_page_sizes; i++) {
442*3177Sdp78419 			if ((colors = hw_page_array[i].hp_colors) <= 1) {
443*3177Sdp78419 				continue;
444*3177Sdp78419 			}
445*3177Sdp78419 			while ((colors >> a) == 0)
446*3177Sdp78419 				a--;
447*3177Sdp78419 			colorequivszc[i] = (a << 4);
448*3177Sdp78419 		}
449*3177Sdp78419 	}
450*3177Sdp78419 }
451