niagara2.c revision c6fc6a368e072b6deb37b62fe3f9895efc5316d1
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * CDDL HEADER START
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The contents of this file are subject to the terms of the
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Common Development and Distribution License (the "License").
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * You may not use this file except in compliance with the License.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * or http://www.opensolaris.org/os/licensing.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * See the License for the specific language governing permissions
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * and limitations under the License.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * When distributing Covered Code, include this CDDL HEADER in each
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * If applicable, add the following below this CDDL HEADER, with the
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * fields enclosed by brackets "[]" replaced with your own identifying
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * information: Portions Copyright [yyyy] [name of copyright owner]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster *
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * CDDL HEADER END
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Use is subject to license terms.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/types.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/systm.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/archsystm.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/machparam.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/machsystm.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/cpu.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/elf_SPARC.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <vm/hat_sfmmu.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <vm/page.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <vm/vm_dep.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/cpuvar.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/async.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/cmn_err.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/debug.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/dditypes.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/sunddi.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/cpu_module.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/prom_debug.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/vmsystm.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/prom_plat.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/sysmacros.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/intreg.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/machtrap.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/ontrap.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/ivintr.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/atomic.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/panic.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/dtrace.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/simulate.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/fault.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/niagara2regs.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/hsvc.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/trapstat.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#include <sys/mutex_impl.h>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosteruint_t root_phys_addr_lo_mask = 0xffffffffU;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#if defined(NIAGARA2_IMPL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterchar cpu_module_name[] = "SUNW,UltraSPARC-T2";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#elif defined(VFALLS_IMPL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterchar cpu_module_name[] = "SUNW,UltraSPARC-T2+";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#elif defined(KT_IMPL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterchar cpu_module_name[] = "SUNW,UltraSPARC-T3";
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#endif
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Hypervisor services information for the NIAGARA2 and Victoria Falls
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * CPU module
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic boolean_t cpu_hsvc_available = B_TRUE;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic uint64_t cpu_sup_minor; /* Supported minor number */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#if defined(NIAGARA2_IMPL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic hsvc_info_t cpu_hsvc = {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HSVC_REV_1, NULL, HSVC_GROUP_NIAGARA2_CPU, NIAGARA2_HSVC_MAJOR,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster NIAGARA2_HSVC_MINOR, cpu_module_name
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#elif defined(VFALLS_IMPL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic hsvc_info_t cpu_hsvc = {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HSVC_REV_1, NULL, HSVC_GROUP_VFALLS_CPU, VFALLS_HSVC_MAJOR,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster VFALLS_HSVC_MINOR, cpu_module_name
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#elif defined(KT_IMPL)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic hsvc_info_t cpu_hsvc = {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster HSVC_REV_1, NULL, HSVC_GROUP_KT_CPU, KT_HSVC_MAJOR,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster KT_HSVC_MINOR, cpu_module_name
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#endif
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostercpu_setup(void)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster extern int mmu_exported_pagesize_mask;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster extern int cpc_has_overflow_intr;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster extern size_t contig_mem_prealloc_base_size;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster int status;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Negotiate the API version for Niagara2 specific hypervisor
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * services.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster status = hsvc_register(&cpu_hsvc, &cpu_sup_minor);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (status != 0) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cmn_err(CE_WARN, "%s: cannot negotiate hypervisor services "
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster "group: 0x%lx major: 0x%lx minor: 0x%lx errno: %d",
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cpu_hsvc.hsvc_modname, cpu_hsvc.hsvc_group,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cpu_hsvc.hsvc_major, cpu_hsvc.hsvc_minor, status);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cpu_hsvc_available = B_FALSE;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The setup common to all CPU modules is done in cpu_setup_common
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * routine.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cpu_setup_common(NULL);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Initialize the cpu_hwcap_flags for N2 and VF if it is not already
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * set in cpu_setup_common() by the hwcap MD info. Note that this MD
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * info may not be available for N2/VF.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (cpu_hwcap_flags == 0) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#ifdef KT_IMPL
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * This should not happen since hwcap MD info is always
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * available for KT platforms.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(cpu_hwcap_flags != 0); /* panic in DEBUG mode */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cpu_hwcap_flags |= AV_SPARC_VIS3 | AV_SPARC_HPC | AV_SPARC_FMAF;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#endif /* KT_IMPL */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cpu_hwcap_flags |= AV_SPARC_VIS | AV_SPARC_VIS2 |
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster AV_SPARC_ASI_BLK_INIT | AV_SPARC_POPC;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cache |= (CACHE_PTAG | CACHE_IOCOHERENT);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((mmu_exported_pagesize_mask &
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DEFAULT_SUN4V_MMU_PAGESIZE_MASK) !=
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster DEFAULT_SUN4V_MMU_PAGESIZE_MASK)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cmn_err(CE_PANIC, "machine description"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster " does not have required sun4v page sizes"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster " 8K, 64K and 4M: MD mask is 0x%x",
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mmu_exported_pagesize_mask);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Niagara2 supports a 48-bit subset of the full 64-bit virtual
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * address space. Virtual addresses between 0x0000800000000000
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * and 0xffff.7fff.ffff.ffff inclusive lie within a "VA Hole"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * and must never be mapped. In addition, software must not use
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * pages within 4GB of the VA hole as instruction pages to
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * avoid problems with prefetching into the VA hole.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster hole_start = (caddr_t)((1ull << (va_bits - 1)) - (1ull << 32));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster hole_end = (caddr_t)((0ull - (1ull << (va_bits - 1))) + (1ull << 32));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Niagara2 has a performance counter overflow interrupt
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cpc_has_overflow_intr = 1;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Enable 4M pages for OOB.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster max_uheap_lpsize = MMU_PAGESIZE4M;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster max_ustack_lpsize = MMU_PAGESIZE4M;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster max_privmap_lpsize = MMU_PAGESIZE4M;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#ifdef SUN4V_CONTIG_MEM_PREALLOC_SIZE_MB
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Use CPU Makefile specific compile time define (if exists)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * to add to the contig preallocation size.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster contig_mem_prealloc_base_size = MB(SUN4V_CONTIG_MEM_PREALLOC_SIZE_MB);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#endif
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Set the magic constants of the implementation.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostercpu_fiximp(struct cpu_node *cpunode)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The Cache node is optional in MD. Therefore in case "Cache"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * node does not exists in MD, set the default L2 cache associativity,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * size, linesize.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (cpunode->ecache_size == 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cpunode->ecache_size = L2CACHE_SIZE;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (cpunode->ecache_linesize == 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cpunode->ecache_linesize = L2CACHE_LINESIZE;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (cpunode->ecache_associativity == 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cpunode->ecache_associativity = L2CACHE_ASSOCIATIVITY;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostercpu_map_exec_units(struct cpu *cp)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(MUTEX_HELD(&cpu_lock));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The cpu_ipipe and cpu_fpu fields are initialized based on
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * the execution unit sharing information from the MD. They
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * default to the CPU id in the absence of such information.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cp->cpu_m.cpu_ipipe = cpunodes[cp->cpu_id].exec_unit_mapping;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (cp->cpu_m.cpu_ipipe == NO_EU_MAPPING_FOUND)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cp->cpu_m.cpu_ipipe = (id_t)(cp->cpu_id);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cp->cpu_m.cpu_fpu = cpunodes[cp->cpu_id].fpu_mapping;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (cp->cpu_m.cpu_fpu == NO_EU_MAPPING_FOUND)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cp->cpu_m.cpu_fpu = (id_t)(cp->cpu_id);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Niagara 2 defines the core to be at the FPU level
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cp->cpu_m.cpu_core = cp->cpu_m.cpu_fpu;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The cpu_chip field is initialized based on the information
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * in the MD and assume that all cpus within a chip
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * share the same L2 cache. If no such info is available, we
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * set the cpu to belong to the defacto chip 0.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cp->cpu_m.cpu_mpipe = cpunodes[cp->cpu_id].l2_cache_mapping;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (cp->cpu_m.cpu_mpipe == NO_L2_CACHE_MAPPING_FOUND)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cp->cpu_m.cpu_mpipe = CPU_L2_CACHEID_INVALID;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cp->cpu_m.cpu_chip = cpunodes[cp->cpu_id].l2_cache_mapping;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (cp->cpu_m.cpu_chip == NO_L2_CACHE_MAPPING_FOUND)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cp->cpu_m.cpu_chip = CPU_CHIPID_INVALID;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic int cpucnt;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostercpu_init_private(struct cpu *cp)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster extern void niagara_kstat_init(void);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(MUTEX_HELD(&cpu_lock));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster cpu_map_exec_units(cp);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((cpucnt++ == 0) && (cpu_hsvc_available == B_TRUE))
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (void) niagara_kstat_init();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mutex_delay = rdccr_delay;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*ARGSUSED*/
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostercpu_uninit_private(struct cpu *cp)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster extern void niagara_kstat_fini(void);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(MUTEX_HELD(&cpu_lock));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((--cpucnt == 0) && (cpu_hsvc_available == B_TRUE))
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (void) niagara_kstat_fini();
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * On Niagara2, any flush will cause all preceding stores to be
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * synchronized wrt the i$, regardless of address or ASI. In fact,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * the address is ignored, so we always flush address 0.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*ARGSUSED*/
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterdtrace_flush_sec(uintptr_t addr)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster doflush(0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Trapstat support for Niagara2 processor
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The Niagara2 provides HWTW support for TSB lookup and with HWTW
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * enabled no TSB hit information will be available. Therefore setting
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * the time spent in TLB miss handler for TSB hits to 0.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterint
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostercpu_trapstat_conf(int cmd)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster int status = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster switch (cmd) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case CPU_TSTATCONF_INIT:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case CPU_TSTATCONF_FINI:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case CPU_TSTATCONF_ENABLE:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster case CPU_TSTATCONF_DISABLE:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster default:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster status = EINVAL;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster break;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return (status);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostervoid
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostercpu_trapstat_data(void *buf, uint_t tstat_pgszs)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tstat_pgszdata_t *tstatp = (tstat_pgszdata_t *)buf;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster int i;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster for (i = 0; i < tstat_pgszs; i++, tstatp++) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tstatp->tpgsz_kernel.tmode_itlb.ttlb_tlb.tmiss_count = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tstatp->tpgsz_kernel.tmode_itlb.ttlb_tlb.tmiss_time = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tstatp->tpgsz_user.tmode_itlb.ttlb_tlb.tmiss_count = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tstatp->tpgsz_user.tmode_itlb.ttlb_tlb.tmiss_time = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tstatp->tpgsz_kernel.tmode_dtlb.ttlb_tlb.tmiss_count = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tstatp->tpgsz_kernel.tmode_dtlb.ttlb_tlb.tmiss_time = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tstatp->tpgsz_user.tmode_dtlb.ttlb_tlb.tmiss_count = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster tstatp->tpgsz_user.tmode_dtlb.ttlb_tlb.tmiss_time = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Page coloring support for hashed cache index mode
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Node id bits from machine description (MD). Node id distinguishes
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * local versus remote memory. Because of MPO, page allocation does
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * not cross node boundaries. Therefore, remove the node id bits from
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * the color, since they are fixed. Either bit 30, or 31:30 in
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Victoria Falls processors.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The number of node id bits is always 0 in Niagara2.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostertypedef struct n2color {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster uchar_t nnbits; /* number of node id bits */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster uchar_t nnmask; /* mask for node id bits */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster uchar_t lomask; /* mask for bits below node id */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster uchar_t lobits; /* number of bits below node id */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster} n2color_t;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostern2color_t n2color[MMU_PAGE_SIZES];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic uchar_t nhbits[] = {7, 7, 6, 5, 5, 5};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Remove node id bits from color bits 32:28.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * This will reduce the number of colors.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * No change if number of node bits is zero.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic inline uint_t
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostern2_hash2color(uint_t color, uchar_t szc)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster n2color_t m = n2color[szc];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (m.nnbits > 0) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color = ((color >> m.nnbits) & ~m.lomask) | (color & m.lomask);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT((color & ~(hw_page_array[szc].hp_colors - 1)) == 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return (color);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Restore node id bits into page color.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * This will increase the number of colors to match N2.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * No change if number of node bits is zero.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic inline uint_t
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fostern2_color2hash(uint_t color, uchar_t szc, uint_t node)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster n2color_t m = n2color[szc];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (m.nnbits > 0) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color = ((color & ~m.lomask) << m.nnbits) | (color & m.lomask);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color |= (node & m.nnmask) << m.lobits;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return (color);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/* NI2 L2$ index is pa[32:28]^pa[17:13].pa[19:18]^pa[12:11].pa[10:6] */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * iterator NULL means pfn is VA, do not adjust ra_to_pa
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * iterator (-1) means pfn is RA, need to convert to PA
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * iterator non-null means pfn is RA, use ra_to_pa
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosteruint_t
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterpage_pfn_2_color_cpu(pfn_t pfn, uchar_t szc, void *cookie)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mem_node_iterator_t *it = cookie;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster uint_t color;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(szc <= TTE256M);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (it == ((mem_node_iterator_t *)(-1))) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pfn = plat_rapfn_to_papfn(pfn);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster } else if (it != NULL) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(pfn >= it->mi_mblock_base && pfn <= it->mi_mblock_end);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pfn = pfn + it->mi_ra_to_pa;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pfn = PFN_BASE(pfn, szc);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color = ((pfn >> 15) ^ pfn) & 0x1f;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (szc < TTE4M) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* 19:18 */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color = (color << 2) | ((pfn >> 5) & 0x3);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (szc > TTE64K)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color >>= 1; /* 19 */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return (n2_hash2color(color, szc));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterstatic uint_t
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterpage_papfn_2_color_cpu(pfn_t papfn, uchar_t szc)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster uint_t color;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(szc <= TTE256M);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster papfn = PFN_BASE(papfn, szc);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color = ((papfn >> 15) ^ papfn) & 0x1f;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (szc < TTE4M) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* 19:18 */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color = (color << 2) | ((papfn >> 5) & 0x3);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (szc > TTE64K)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color >>= 1; /* 19 */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return (color);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#if TTE256M != 5
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#error TTE256M is not 5
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#endif
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosteruint_t
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterpage_get_nsz_color_mask_cpu(uchar_t szc, uint_t mask)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster static uint_t ni2_color_masks[5] = {0x63, 0x1e, 0x3e, 0x1f, 0x1f};
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(szc < TTE256M);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mask = n2_color2hash(mask, szc, 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mask &= ni2_color_masks[szc];
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (szc == TTE64K || szc == TTE512K)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mask >>= 1;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return (n2_hash2color(mask, szc + 1));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosteruint_t
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterpage_get_nsz_color_cpu(uchar_t szc, uint_t color)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(szc < TTE256M);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color = n2_color2hash(color, szc, 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (szc == TTE64K || szc == TTE512K)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color >>= 1;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return (n2_hash2color(color, szc + 1));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosteruint_t
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterpage_get_color_shift_cpu(uchar_t szc, uchar_t nszc)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster uint_t s;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(nszc >= szc);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(nszc <= TTE256M);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster s = nhbits[szc] - n2color[szc].nnbits;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster s -= nhbits[nszc] - n2color[nszc].nnbits;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return (s);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosteruint_t
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterpage_convert_color_cpu(uint_t ncolor, uchar_t szc, uchar_t nszc)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster uint_t color;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(nszc > szc);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(nszc <= TTE256M);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ncolor = n2_color2hash(ncolor, nszc, 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color = ncolor << (nhbits[szc] - nhbits[nszc]);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color = n2_hash2color(color, szc);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return (color);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster}
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster#define PAPFN_2_MNODE(pfn) \
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (((pfn) & it->mi_mnode_pfn_mask) >> it->mi_mnode_pfn_shift)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster/*ARGSUSED*/
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterpfn_t
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterpage_next_pfn_for_color_cpu(pfn_t pfn, uchar_t szc, uint_t color,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster uint_t ceq_mask, uint_t color_mask, void *cookie)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster{
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster mem_node_iterator_t *it = cookie;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pfn_t pstep = PNUM_SIZE(szc);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pfn_t npfn, pfn_ceq_mask, pfn_color;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pfn_t tmpmask, mask = (pfn_t)-1;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster uint_t pfnmn;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT((color & ~ceq_mask) == 0);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(pfn >= it->mi_mblock_base && pfn <= it->mi_mblock_end);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* convert RA to PA for accurate color calculation */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (it->mi_init) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* first call after it, so cache these values */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster it->mi_hash_ceq_mask =
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster n2_color2hash(ceq_mask, szc, it->mi_mnode_mask);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster it->mi_hash_color =
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster n2_color2hash(color, szc, it->mi_mnode);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster it->mi_init = 0;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster } else {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(it->mi_hash_ceq_mask ==
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster n2_color2hash(ceq_mask, szc, it->mi_mnode_mask));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ASSERT(it->mi_hash_color ==
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster n2_color2hash(color, szc, it->mi_mnode));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ceq_mask = it->mi_hash_ceq_mask;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster color = it->mi_hash_color;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pfn += it->mi_ra_to_pa;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* restart here when we switch memblocks */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosternext_mem_block:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pfnmn = PAPFN_2_MNODE(pfn);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((((page_papfn_2_color_cpu(pfn, szc) ^ color) & ceq_mask) == 0) &&
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster (pfnmn == it->mi_mnode)) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* we start from the page with correct color and mnode */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (szc >= TTE512K) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (szc >= TTE4M) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* page color is PA[32:28] */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pfn_ceq_mask = ceq_mask << 15;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster } else {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /* page color is PA[32:28].PA[19:19] */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pfn_ceq_mask = ((ceq_mask & 1) << 6) |
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster ((ceq_mask >> 1) << 15);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster }
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Preserve mnode bits in case they are not part of the
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * color mask (eg., 8GB interleave, mnode bits 34:33).
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pfn_ceq_mask |= it->mi_mnode_pfn_mask;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster npfn = ADD_MASKED(pfn, pstep, pfn_ceq_mask, mask);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster goto done;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster } else {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * We deal 64K or 8K page. Check if we could the
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * satisfy the request without changing PA[32:28]
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster */
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pfn_ceq_mask = ((ceq_mask & 3) << 5) | (ceq_mask >> 2);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster pfn_ceq_mask |= it->mi_mnode_pfn_mask;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster npfn = ADD_MASKED(pfn, pstep, pfn_ceq_mask, mask);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((((npfn ^ pfn) >> 15) & 0x1f) == 0)
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster goto done;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster /*
* for next pfn we have to change bits PA[32:28]
* set PA[63:28] and PA[19:18] of the next pfn
*/
npfn = (pfn >> 15) << 15;
npfn |= (ceq_mask & color & 3) << 5;
pfn_ceq_mask = (szc == TTE8K) ? 0 :
(ceq_mask & 0x1c) << 13;
pfn_ceq_mask |= it->mi_mnode_pfn_mask;
npfn = ADD_MASKED(npfn, (1 << 15), pfn_ceq_mask, mask);
/*
* set bits PA[17:13] to match the color
*/
npfn |= ((npfn >> 15) ^ (color >> 2)) & (ceq_mask >> 2);
goto done;
}
}
/*
* we start from the page with incorrect color - rare case
*/
if (szc >= TTE512K) {
if (szc >= TTE4M) {
/* page color is in bits PA[32:28] */
npfn = ((pfn >> 20) << 20) | (color << 15);
pfn_ceq_mask = (ceq_mask << 15) | 0x7fff;
} else {
/* try get the right color by changing bit PA[19:19] */
npfn = pfn + pstep;
pfnmn = PAPFN_2_MNODE(npfn);
if ((((page_papfn_2_color_cpu(npfn, szc) ^ color) &
ceq_mask) == 0) && (pfnmn == it->mi_mnode))
goto done;
/* page color is PA[32:28].PA[19:19] */
pfn_ceq_mask = ((ceq_mask & 1) << 6) |
((ceq_mask >> 1) << 15) | (0xff << 7);
pfn_color = ((color & 1) << 6) | ((color >> 1) << 15);
npfn = ((pfn >> 20) << 20) | pfn_color;
}
/* Fix mnode if necessary */
if ((pfnmn = PAPFN_2_MNODE(npfn)) != it->mi_mnode)
npfn += ((it->mi_mnode - pfnmn) & it->mi_mnode_mask) <<
it->mi_mnode_pfn_shift;
/*
* Preserve mnode bits in case they are not part of the color
* mask eg 8GB interleave, mnode bits 34:33).
*/
pfn_ceq_mask |= it->mi_mnode_pfn_mask;
while (npfn <= pfn) {
npfn = ADD_MASKED(npfn, pstep, pfn_ceq_mask, mask);
}
goto done;
}
/*
* We deal 64K or 8K page of incorrect color.
* Try correcting color without changing PA[32:28]
*/
pfn_ceq_mask = ((ceq_mask & 3) << 5) | (ceq_mask >> 2);
pfn_color = ((color & 3) << 5) | (color >> 2);
if (pfnmn == it->mi_mnode) {
npfn = (pfn & ~(pfn_t)0x7f);
npfn |= (((pfn >> 15) & 0x1f) ^ pfn_color) & pfn_ceq_mask;
npfn = (szc == TTE64K) ? (npfn & ~(pfn_t)0x7) : npfn;
if (((page_papfn_2_color_cpu(npfn, szc) ^ color) &
ceq_mask) == 0) {
/* the color is fixed - find the next page */
pfn_ceq_mask |= it->mi_mnode_pfn_mask;
while (npfn <= pfn) {
npfn = ADD_MASKED(npfn, pstep, pfn_ceq_mask,
mask);
}
if ((((npfn ^ pfn) >> 15) & 0x1f) == 0)
goto done;
}
}
/* to fix the color need to touch PA[32:28] */
npfn = (szc == TTE8K) ? ((pfn >> 15) << 15) :
(((pfn >> 18) << 18) | ((color & 0x1c) << 13));
/* fix mnode if input pfn is in the wrong mnode. */
if ((pfnmn = PAPFN_2_MNODE(npfn)) != it->mi_mnode) {
npfn += ((it->mi_mnode - pfnmn) & it->mi_mnode_mask) <<
it->mi_mnode_pfn_shift;
}
tmpmask = (szc == TTE8K) ? 0 : (ceq_mask & 0x1c) << 13;
tmpmask |= it->mi_mnode_pfn_mask;
while (npfn <= pfn) {
npfn = ADD_MASKED(npfn, (1 << 15), tmpmask, mask);
}
/* set bits PA[19:13] to match the color */
npfn |= (((npfn >> 15) & 0x1f) ^ pfn_color) & pfn_ceq_mask;
npfn = (szc == TTE64K) ? (npfn & ~(pfn_t)0x7) : npfn;
done:
ASSERT(((page_papfn_2_color_cpu(npfn, szc) ^ color) & ceq_mask) == 0);
ASSERT(PAPFN_2_MNODE(npfn) == it->mi_mnode);
/* PA to RA */
npfn -= it->mi_ra_to_pa;
/* check for possible memblock switch */
if (npfn > it->mi_mblock_end) {
pfn = plat_mem_node_iterator_init(npfn, it->mi_mnode, szc, it,
0);
if (pfn == (pfn_t)-1)
return (pfn);
ASSERT(pfn >= it->mi_mblock_base && pfn <= it->mi_mblock_end);
pfn += it->mi_ra_to_pa;
goto next_mem_block;
}
return (npfn);
}
/*
* init page coloring
* VF encodes node_id for an L-group in either bit 30 or 31:30,
* which effectively reduces the number of colors available per mnode.
*/
void
page_coloring_init_cpu()
{
int i;
uchar_t id;
uchar_t lo;
uchar_t hi;
n2color_t m;
mem_node_iterator_t it;
static uchar_t idmask[] = {0, 0x7, 0x1f, 0x1f, 0x1f, 0x1f};
for (i = 0; i < max_mem_nodes; i++) {
memset(&it, 0, sizeof (it));
if (plat_mem_node_iterator_init(0, i, 0, &it, 1) != (pfn_t)-1)
break;
}
ASSERT(i < max_mem_nodes);
for (i = 0; i < mmu_page_sizes; i++) {
(void) memset(&m, 0, sizeof (m));
id = it.mi_mnode_pfn_mask >> 15; /* node id mask */
id &= idmask[i];
lo = lowbit(id);
if (lo > 0) {
hi = highbit(id);
m.nnbits = hi - lo + 1;
m.nnmask = (1 << m.nnbits) - 1;
lo += nhbits[i] - 5;
m.lomask = (1 << (lo - 1)) - 1;
m.lobits = lo - 1;
}
hw_page_array[i].hp_colors = 1 << (nhbits[i] - m.nnbits);
n2color[i] = m;
}
}
/*
* group colorequiv colors on N2 by low order bits of the color first
*/
void
page_set_colorequiv_arr_cpu(void)
{
static uint_t nequiv_shades_log2[MMU_PAGE_SIZES] = {2, 5, 0, 0, 0, 0};
nequiv_shades_log2[1] -= n2color[1].nnbits;
if (colorequiv > 1) {
int i;
uint_t sv_a = lowbit(colorequiv) - 1;
if (sv_a > 15)
sv_a = 15;
for (i = 0; i < MMU_PAGE_SIZES; i++) {
uint_t colors;
uint_t a = sv_a;
if ((colors = hw_page_array[i].hp_colors) <= 1)
continue;
while ((colors >> a) == 0)
a--;
if (a > (colorequivszc[i] & 0xf) +
(colorequivszc[i] >> 4)) {
if (a <= nequiv_shades_log2[i]) {
colorequivszc[i] = (uchar_t)a;
} else {
colorequivszc[i] =
((a - nequiv_shades_log2[i]) << 4) |
nequiv_shades_log2[i];
}
}
}
}
}