niagara2.c revision 102033aa92edf302ad31b3bdd7c6fcd2d6910903
4496171313bed39e96f21bc2f9faf2868e267ae3girish/*
4496171313bed39e96f21bc2f9faf2868e267ae3girish * CDDL HEADER START
4496171313bed39e96f21bc2f9faf2868e267ae3girish *
4496171313bed39e96f21bc2f9faf2868e267ae3girish * The contents of this file are subject to the terms of the
4496171313bed39e96f21bc2f9faf2868e267ae3girish * Common Development and Distribution License (the "License").
4496171313bed39e96f21bc2f9faf2868e267ae3girish * You may not use this file except in compliance with the License.
4496171313bed39e96f21bc2f9faf2868e267ae3girish *
4496171313bed39e96f21bc2f9faf2868e267ae3girish * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4496171313bed39e96f21bc2f9faf2868e267ae3girish * or http://www.opensolaris.org/os/licensing.
4496171313bed39e96f21bc2f9faf2868e267ae3girish * See the License for the specific language governing permissions
4496171313bed39e96f21bc2f9faf2868e267ae3girish * and limitations under the License.
4496171313bed39e96f21bc2f9faf2868e267ae3girish *
4496171313bed39e96f21bc2f9faf2868e267ae3girish * When distributing Covered Code, include this CDDL HEADER in each
4496171313bed39e96f21bc2f9faf2868e267ae3girish * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4496171313bed39e96f21bc2f9faf2868e267ae3girish * If applicable, add the following below this CDDL HEADER, with the
4496171313bed39e96f21bc2f9faf2868e267ae3girish * fields enclosed by brackets "[]" replaced with your own identifying
4496171313bed39e96f21bc2f9faf2868e267ae3girish * information: Portions Copyright [yyyy] [name of copyright owner]
4496171313bed39e96f21bc2f9faf2868e267ae3girish *
4496171313bed39e96f21bc2f9faf2868e267ae3girish * CDDL HEADER END
4496171313bed39e96f21bc2f9faf2868e267ae3girish */
4496171313bed39e96f21bc2f9faf2868e267ae3girish/*
4496171313bed39e96f21bc2f9faf2868e267ae3girish * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
4496171313bed39e96f21bc2f9faf2868e267ae3girish * Use is subject to license terms.
4496171313bed39e96f21bc2f9faf2868e267ae3girish */
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish#pragma ident "%Z%%M% %I% %E% SMI"
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/types.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/systm.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/archsystm.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/machparam.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/machsystm.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/cpu.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/elf_SPARC.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <vm/hat_sfmmu.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <vm/page.h>
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp#include <vm/vm_dep.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/cpuvar.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/async.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/cmn_err.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/debug.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/dditypes.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/sunddi.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/cpu_module.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/prom_debug.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/vmsystm.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/prom_plat.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/sysmacros.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/intreg.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/machtrap.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/ontrap.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/ivintr.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/atomic.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/panic.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/dtrace.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/simulate.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/fault.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/niagara2regs.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/hsvc.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish#include <sys/trapstat.h>
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girishuint_t root_phys_addr_lo_mask = 0xffffffffU;
4496171313bed39e96f21bc2f9faf2868e267ae3girishchar cpu_module_name[] = "SUNW,UltraSPARC-T2";
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish/*
4496171313bed39e96f21bc2f9faf2868e267ae3girish * Hypervisor services information for the NIAGARA2 CPU module
4496171313bed39e96f21bc2f9faf2868e267ae3girish */
4496171313bed39e96f21bc2f9faf2868e267ae3girishstatic boolean_t niagara2_hsvc_available = B_TRUE;
4496171313bed39e96f21bc2f9faf2868e267ae3girishstatic uint64_t niagara2_sup_minor; /* Supported minor number */
4496171313bed39e96f21bc2f9faf2868e267ae3girishstatic hsvc_info_t niagara2_hsvc = {
4496171313bed39e96f21bc2f9faf2868e267ae3girish HSVC_REV_1, NULL, HSVC_GROUP_NIAGARA2_CPU, NIAGARA2_HSVC_MAJOR,
4496171313bed39e96f21bc2f9faf2868e267ae3girish NIAGARA2_HSVC_MINOR, cpu_module_name
4496171313bed39e96f21bc2f9faf2868e267ae3girish};
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girishvoid
4496171313bed39e96f21bc2f9faf2868e267ae3girishcpu_setup(void)
4496171313bed39e96f21bc2f9faf2868e267ae3girish{
4496171313bed39e96f21bc2f9faf2868e267ae3girish extern int mmu_exported_pagesize_mask;
4496171313bed39e96f21bc2f9faf2868e267ae3girish extern int cpc_has_overflow_intr;
4496171313bed39e96f21bc2f9faf2868e267ae3girish int status;
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish /*
4496171313bed39e96f21bc2f9faf2868e267ae3girish * Negotiate the API version for Niagara2 specific hypervisor
4496171313bed39e96f21bc2f9faf2868e267ae3girish * services.
4496171313bed39e96f21bc2f9faf2868e267ae3girish */
4496171313bed39e96f21bc2f9faf2868e267ae3girish status = hsvc_register(&niagara2_hsvc, &niagara2_sup_minor);
4496171313bed39e96f21bc2f9faf2868e267ae3girish if (status != 0) {
4496171313bed39e96f21bc2f9faf2868e267ae3girish cmn_err(CE_WARN, "%s: cannot negotiate hypervisor services "
4496171313bed39e96f21bc2f9faf2868e267ae3girish "group: 0x%lx major: 0x%lx minor: 0x%lx errno: %d",
4496171313bed39e96f21bc2f9faf2868e267ae3girish niagara2_hsvc.hsvc_modname, niagara2_hsvc.hsvc_group,
4496171313bed39e96f21bc2f9faf2868e267ae3girish niagara2_hsvc.hsvc_major, niagara2_hsvc.hsvc_minor, status);
4496171313bed39e96f21bc2f9faf2868e267ae3girish niagara2_hsvc_available = B_FALSE;
4496171313bed39e96f21bc2f9faf2868e267ae3girish }
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish /*
4496171313bed39e96f21bc2f9faf2868e267ae3girish * The setup common to all CPU modules is done in cpu_setup_common
4496171313bed39e96f21bc2f9faf2868e267ae3girish * routine.
4496171313bed39e96f21bc2f9faf2868e267ae3girish */
4496171313bed39e96f21bc2f9faf2868e267ae3girish cpu_setup_common(NULL);
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish cache |= (CACHE_PTAG | CACHE_IOCOHERENT);
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish if ((mmu_exported_pagesize_mask &
4496171313bed39e96f21bc2f9faf2868e267ae3girish DEFAULT_SUN4V_MMU_PAGESIZE_MASK) !=
4496171313bed39e96f21bc2f9faf2868e267ae3girish DEFAULT_SUN4V_MMU_PAGESIZE_MASK)
4496171313bed39e96f21bc2f9faf2868e267ae3girish cmn_err(CE_PANIC, "machine description"
4496171313bed39e96f21bc2f9faf2868e267ae3girish " does not have required sun4v page sizes"
4496171313bed39e96f21bc2f9faf2868e267ae3girish " 8K, 64K and 4M: MD mask is 0x%x",
4496171313bed39e96f21bc2f9faf2868e267ae3girish mmu_exported_pagesize_mask);
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish cpu_hwcap_flags = AV_SPARC_VIS | AV_SPARC_VIS2 | AV_SPARC_ASI_BLK_INIT;
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish /*
4496171313bed39e96f21bc2f9faf2868e267ae3girish * Niagara2 supports a 48-bit subset of the full 64-bit virtual
4496171313bed39e96f21bc2f9faf2868e267ae3girish * address space. Virtual addresses between 0x0000800000000000
4496171313bed39e96f21bc2f9faf2868e267ae3girish * and 0xffff.7fff.ffff.ffff inclusive lie within a "VA Hole"
4496171313bed39e96f21bc2f9faf2868e267ae3girish * and must never be mapped. In addition, software must not use
4496171313bed39e96f21bc2f9faf2868e267ae3girish * pages within 4GB of the VA hole as instruction pages to
4496171313bed39e96f21bc2f9faf2868e267ae3girish * avoid problems with prefetching into the VA hole.
4496171313bed39e96f21bc2f9faf2868e267ae3girish */
4496171313bed39e96f21bc2f9faf2868e267ae3girish hole_start = (caddr_t)((1ull << (va_bits - 1)) - (1ull << 32));
4496171313bed39e96f21bc2f9faf2868e267ae3girish hole_end = (caddr_t)((0ull - (1ull << (va_bits - 1))) + (1ull << 32));
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish /*
4496171313bed39e96f21bc2f9faf2868e267ae3girish * Niagara2 has a performance counter overflow interrupt
4496171313bed39e96f21bc2f9faf2868e267ae3girish */
4496171313bed39e96f21bc2f9faf2868e267ae3girish cpc_has_overflow_intr = 1;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /*
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp * Enable 4M pages for OOB.
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp max_uheap_lpsize = MMU_PAGESIZE4M;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp max_ustack_lpsize = MMU_PAGESIZE4M;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp max_privmap_lpsize = MMU_PAGESIZE4M;
4496171313bed39e96f21bc2f9faf2868e267ae3girish}
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish/*
4496171313bed39e96f21bc2f9faf2868e267ae3girish * Set the magic constants of the implementation.
4496171313bed39e96f21bc2f9faf2868e267ae3girish */
4496171313bed39e96f21bc2f9faf2868e267ae3girishvoid
4496171313bed39e96f21bc2f9faf2868e267ae3girishcpu_fiximp(struct cpu_node *cpunode)
4496171313bed39e96f21bc2f9faf2868e267ae3girish{
4496171313bed39e96f21bc2f9faf2868e267ae3girish /*
4496171313bed39e96f21bc2f9faf2868e267ae3girish * The Cache node is optional in MD. Therefore in case "Cache"
4496171313bed39e96f21bc2f9faf2868e267ae3girish * node does not exists in MD, set the default L2 cache associativity,
4496171313bed39e96f21bc2f9faf2868e267ae3girish * size, linesize.
4496171313bed39e96f21bc2f9faf2868e267ae3girish */
4496171313bed39e96f21bc2f9faf2868e267ae3girish if (cpunode->ecache_size == 0)
4496171313bed39e96f21bc2f9faf2868e267ae3girish cpunode->ecache_size = L2CACHE_SIZE;
4496171313bed39e96f21bc2f9faf2868e267ae3girish if (cpunode->ecache_linesize == 0)
4496171313bed39e96f21bc2f9faf2868e267ae3girish cpunode->ecache_linesize = L2CACHE_LINESIZE;
4496171313bed39e96f21bc2f9faf2868e267ae3girish if (cpunode->ecache_associativity == 0)
4496171313bed39e96f21bc2f9faf2868e267ae3girish cpunode->ecache_associativity = L2CACHE_ASSOCIATIVITY;
4496171313bed39e96f21bc2f9faf2868e267ae3girish}
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girishstatic int niagara2_cpucnt;
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girishvoid
4496171313bed39e96f21bc2f9faf2868e267ae3girishcpu_init_private(struct cpu *cp)
4496171313bed39e96f21bc2f9faf2868e267ae3girish{
4496171313bed39e96f21bc2f9faf2868e267ae3girish extern int niagara_kstat_init(void);
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish /*
4496171313bed39e96f21bc2f9faf2868e267ae3girish * The cpu_ipipe field is initialized based on the execution
4496171313bed39e96f21bc2f9faf2868e267ae3girish * unit sharing information from the MD. It defaults to the
4496171313bed39e96f21bc2f9faf2868e267ae3girish * virtual CPU id in the absence of such information.
4496171313bed39e96f21bc2f9faf2868e267ae3girish */
4496171313bed39e96f21bc2f9faf2868e267ae3girish cp->cpu_m.cpu_ipipe = cpunodes[cp->cpu_id].exec_unit_mapping;
4496171313bed39e96f21bc2f9faf2868e267ae3girish if (cp->cpu_m.cpu_ipipe == NO_EU_MAPPING_FOUND)
4496171313bed39e96f21bc2f9faf2868e267ae3girish cp->cpu_m.cpu_ipipe = (id_t)(cp->cpu_id);
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish ASSERT(MUTEX_HELD(&cpu_lock));
4496171313bed39e96f21bc2f9faf2868e267ae3girish if ((niagara2_cpucnt++ == 0) && (niagara2_hsvc_available == B_TRUE))
4496171313bed39e96f21bc2f9faf2868e267ae3girish (void) niagara_kstat_init();
4496171313bed39e96f21bc2f9faf2868e267ae3girish}
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish/*ARGSUSED*/
4496171313bed39e96f21bc2f9faf2868e267ae3girishvoid
4496171313bed39e96f21bc2f9faf2868e267ae3girishcpu_uninit_private(struct cpu *cp)
4496171313bed39e96f21bc2f9faf2868e267ae3girish{
4496171313bed39e96f21bc2f9faf2868e267ae3girish extern int niagara_kstat_fini(void);
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish ASSERT(MUTEX_HELD(&cpu_lock));
4496171313bed39e96f21bc2f9faf2868e267ae3girish if ((--niagara2_cpucnt == 0) && (niagara2_hsvc_available == B_TRUE))
4496171313bed39e96f21bc2f9faf2868e267ae3girish (void) niagara_kstat_fini();
4496171313bed39e96f21bc2f9faf2868e267ae3girish}
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish/*
4496171313bed39e96f21bc2f9faf2868e267ae3girish * On Niagara2, any flush will cause all preceding stores to be
4496171313bed39e96f21bc2f9faf2868e267ae3girish * synchronized wrt the i$, regardless of address or ASI. In fact,
4496171313bed39e96f21bc2f9faf2868e267ae3girish * the address is ignored, so we always flush address 0.
4496171313bed39e96f21bc2f9faf2868e267ae3girish */
4496171313bed39e96f21bc2f9faf2868e267ae3girish/*ARGSUSED*/
4496171313bed39e96f21bc2f9faf2868e267ae3girishvoid
4496171313bed39e96f21bc2f9faf2868e267ae3girishdtrace_flush_sec(uintptr_t addr)
4496171313bed39e96f21bc2f9faf2868e267ae3girish{
4496171313bed39e96f21bc2f9faf2868e267ae3girish doflush(0);
4496171313bed39e96f21bc2f9faf2868e267ae3girish}
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish/*
4496171313bed39e96f21bc2f9faf2868e267ae3girish * Trapstat support for Niagara2 processor
4496171313bed39e96f21bc2f9faf2868e267ae3girish * The Niagara2 provides HWTW support for TSB lookup and with HWTW
4496171313bed39e96f21bc2f9faf2868e267ae3girish * enabled no TSB hit information will be available. Therefore setting
4496171313bed39e96f21bc2f9faf2868e267ae3girish * the time spent in TLB miss handler for TSB hits to 0.
4496171313bed39e96f21bc2f9faf2868e267ae3girish */
4496171313bed39e96f21bc2f9faf2868e267ae3girishint
4496171313bed39e96f21bc2f9faf2868e267ae3girishcpu_trapstat_conf(int cmd)
4496171313bed39e96f21bc2f9faf2868e267ae3girish{
4496171313bed39e96f21bc2f9faf2868e267ae3girish int status = 0;
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish switch (cmd) {
4496171313bed39e96f21bc2f9faf2868e267ae3girish case CPU_TSTATCONF_INIT:
4496171313bed39e96f21bc2f9faf2868e267ae3girish case CPU_TSTATCONF_FINI:
4496171313bed39e96f21bc2f9faf2868e267ae3girish case CPU_TSTATCONF_ENABLE:
4496171313bed39e96f21bc2f9faf2868e267ae3girish case CPU_TSTATCONF_DISABLE:
4496171313bed39e96f21bc2f9faf2868e267ae3girish break;
4496171313bed39e96f21bc2f9faf2868e267ae3girish default:
4496171313bed39e96f21bc2f9faf2868e267ae3girish status = EINVAL;
4496171313bed39e96f21bc2f9faf2868e267ae3girish break;
4496171313bed39e96f21bc2f9faf2868e267ae3girish }
4496171313bed39e96f21bc2f9faf2868e267ae3girish return (status);
4496171313bed39e96f21bc2f9faf2868e267ae3girish}
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girishvoid
4496171313bed39e96f21bc2f9faf2868e267ae3girishcpu_trapstat_data(void *buf, uint_t tstat_pgszs)
4496171313bed39e96f21bc2f9faf2868e267ae3girish{
4496171313bed39e96f21bc2f9faf2868e267ae3girish tstat_pgszdata_t *tstatp = (tstat_pgszdata_t *)buf;
4496171313bed39e96f21bc2f9faf2868e267ae3girish int i;
4496171313bed39e96f21bc2f9faf2868e267ae3girish
4496171313bed39e96f21bc2f9faf2868e267ae3girish for (i = 0; i < tstat_pgszs; i++, tstatp++) {
4496171313bed39e96f21bc2f9faf2868e267ae3girish tstatp->tpgsz_kernel.tmode_itlb.ttlb_tlb.tmiss_count = 0;
4496171313bed39e96f21bc2f9faf2868e267ae3girish tstatp->tpgsz_kernel.tmode_itlb.ttlb_tlb.tmiss_time = 0;
4496171313bed39e96f21bc2f9faf2868e267ae3girish tstatp->tpgsz_user.tmode_itlb.ttlb_tlb.tmiss_count = 0;
4496171313bed39e96f21bc2f9faf2868e267ae3girish tstatp->tpgsz_user.tmode_itlb.ttlb_tlb.tmiss_time = 0;
4496171313bed39e96f21bc2f9faf2868e267ae3girish tstatp->tpgsz_kernel.tmode_dtlb.ttlb_tlb.tmiss_count = 0;
4496171313bed39e96f21bc2f9faf2868e267ae3girish tstatp->tpgsz_kernel.tmode_dtlb.ttlb_tlb.tmiss_time = 0;
4496171313bed39e96f21bc2f9faf2868e267ae3girish tstatp->tpgsz_user.tmode_dtlb.ttlb_tlb.tmiss_count = 0;
4496171313bed39e96f21bc2f9faf2868e267ae3girish tstatp->tpgsz_user.tmode_dtlb.ttlb_tlb.tmiss_time = 0;
4496171313bed39e96f21bc2f9faf2868e267ae3girish }
4496171313bed39e96f21bc2f9faf2868e267ae3girish}
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp/* NI2 L2$ index is pa[32:28]^pa[17:13].pa[19:18]^pa[12:11].pa[10:6] */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dpuint_t
102033aa92edf302ad31b3bdd7c6fcd2d6910903dppage_pfn_2_color_cpu(pfn_t pfn, uchar_t szc)
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp{
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp uint_t color;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp ASSERT(szc <= TTE256M);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn = PFN_BASE(pfn, szc);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp color = ((pfn >> 15) ^ pfn) & 0x1f;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if (szc >= TTE4M)
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return (color);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp color = (color << 2) | ((pfn >> 5) & 0x3);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return (szc <= TTE64K ? color : (color >> 1));
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp}
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp#if TTE256M != 5
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp#error TTE256M is not 5
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp#endif
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dpuint_t
102033aa92edf302ad31b3bdd7c6fcd2d6910903dppage_get_nsz_color_mask_cpu(uchar_t szc, uint_t mask)
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp{
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp static uint_t ni2_color_masks[5] = {0x63, 0x1e, 0x3e, 0x1f, 0x1f};
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp ASSERT(szc < TTE256M);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp mask &= ni2_color_masks[szc];
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return ((szc == TTE64K || szc == TTE512K) ? (mask >> 1) : mask);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp}
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dpuint_t
102033aa92edf302ad31b3bdd7c6fcd2d6910903dppage_get_nsz_color_cpu(uchar_t szc, uint_t color)
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp{
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp ASSERT(szc < TTE256M);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return ((szc == TTE64K || szc == TTE512K) ? (color >> 1) : color);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp}
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dpuint_t
102033aa92edf302ad31b3bdd7c6fcd2d6910903dppage_get_color_shift_cpu(uchar_t szc, uchar_t nszc)
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp{
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp ASSERT(nszc > szc);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp ASSERT(nszc <= TTE256M);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if (szc <= TTE64K)
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return ((nszc >= TTE4M) ? 2 : ((nszc >= TTE512K) ? 1 : 0));
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if (szc == TTE512K)
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return (1);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return (0);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp}
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp/*ARGSUSED*/
102033aa92edf302ad31b3bdd7c6fcd2d6910903dppfn_t
102033aa92edf302ad31b3bdd7c6fcd2d6910903dppage_next_pfn_for_color_cpu(pfn_t pfn, uchar_t szc, uint_t color,
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp uint_t ceq_mask, uint_t color_mask)
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp{
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn_t pstep = PNUM_SIZE(szc);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn_t npfn, pfn_ceq_mask, pfn_color;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn_t tmpmask, mask = (pfn_t)-1;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp ASSERT((color & ~ceq_mask) == 0);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if (((page_pfn_2_color_cpu(pfn, szc) ^ color) & ceq_mask) == 0) {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /* we start from the page with correct color */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if (szc >= TTE512K) {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if (szc >= TTE4M) {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /* page color is PA[32:28] */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn_ceq_mask = ceq_mask << 15;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp } else {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /* page color is PA[32:28].PA[19:19] */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn_ceq_mask = ((ceq_mask & 1) << 6) |
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp ((ceq_mask >> 1) << 15);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp }
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn = ADD_MASKED(pfn, pstep, pfn_ceq_mask, mask);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return (pfn);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp } else {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /*
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp * We deal 64K or 8K page. Check if we could the
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp * satisfy the request without changing PA[32:28]
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn_ceq_mask = ((ceq_mask & 3) << 5) | (ceq_mask >> 2);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn = ADD_MASKED(pfn, pstep, pfn_ceq_mask, mask);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if ((((npfn ^ pfn) >> 15) & 0x1f) == 0)
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return (npfn);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /*
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp * for next pfn we have to change bits PA[32:28]
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp * set PA[63:28] and PA[19:18] of the next pfn
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn = (pfn >> 15) << 15;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn |= (ceq_mask & color & 3) << 5;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn_ceq_mask = (szc == TTE8K) ? 0 :
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp (ceq_mask & 0x1c) << 13;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn = ADD_MASKED(npfn, (1 << 15), pfn_ceq_mask, mask);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /*
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp * set bits PA[17:13] to match the color
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp ceq_mask >>= 2;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp color = (color >> 2) & ceq_mask;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn |= ((npfn >> 15) ^ color) & ceq_mask;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return (npfn);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp }
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp }
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /*
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp * we start from the page with incorrect color - rare case
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if (szc >= TTE512K) {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if (szc >= TTE4M) {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /* page color is in bits PA[32:28] */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn = ((pfn >> 20) << 20) | (color << 15);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn_ceq_mask = (ceq_mask << 15) | 0x7fff;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp } else {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /* try get the right color by changing bit PA[19:19] */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn = pfn + pstep;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if (((page_pfn_2_color_cpu(npfn, szc) ^ color) &
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp ceq_mask) == 0)
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return (npfn);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /* page color is PA[32:28].PA[19:19] */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn_ceq_mask = ((ceq_mask & 1) << 6) |
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp ((ceq_mask >> 1) << 15) | (0xff << 7);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn_color = ((color & 1) << 6) | ((color >> 1) << 15);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn = ((pfn >> 20) << 20) | pfn_color;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp }
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp while (npfn <= pfn) {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn = ADD_MASKED(npfn, pstep, pfn_ceq_mask, mask);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp }
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return (npfn);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp }
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /*
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp * We deal 64K or 8K page of incorrect color.
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp * Try correcting color without changing PA[32:28]
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn_ceq_mask = ((ceq_mask & 3) << 5) | (ceq_mask >> 2);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp pfn_color = ((color & 3) << 5) | (color >> 2);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn = (pfn & ~(pfn_t)0x7f);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn |= (((pfn >> 15) & 0x1f) ^ pfn_color) & pfn_ceq_mask;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn = (szc == TTE64K) ? (npfn & ~(pfn_t)0x7) : npfn;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if (((page_pfn_2_color_cpu(npfn, szc) ^ color) & ceq_mask) == 0) {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /* the color is fixed - find the next page */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp while (npfn <= pfn) {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn = ADD_MASKED(npfn, pstep, pfn_ceq_mask, mask);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp }
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if ((((npfn ^ pfn) >> 15) & 0x1f) == 0)
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return (npfn);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp }
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /* to fix the color need to touch PA[32:28] */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn = (szc == TTE8K) ? ((pfn >> 15) << 15) :
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp (((pfn >> 18) << 18) | ((color & 0x1c) << 13));
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp tmpmask = (szc == TTE8K) ? 0 : (ceq_mask & 0x1c) << 13;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp while (npfn <= pfn) {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn = ADD_MASKED(npfn, (1 << 15), tmpmask, mask);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp }
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp /* set bits PA[19:13] to match the color */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn |= (((npfn >> 15) & 0x1f) ^ pfn_color) & pfn_ceq_mask;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp npfn = (szc == TTE64K) ? (npfn & ~(pfn_t)0x7) : npfn;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp ASSERT(((page_pfn_2_color_cpu(npfn, szc) ^ color) & ceq_mask) == 0);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp return (npfn);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp}
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp/*
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp * init page coloring
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp */
102033aa92edf302ad31b3bdd7c6fcd2d6910903dpvoid
102033aa92edf302ad31b3bdd7c6fcd2d6910903dppage_coloring_init_cpu()
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp{
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp int i;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp uint_t colors;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp hw_page_array[0].hp_colors = 1 << 7;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp hw_page_array[1].hp_colors = 1 << 7;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp hw_page_array[2].hp_colors = 1 << 6;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp for (i = 3; i < mmu_page_sizes; i++) {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp hw_page_array[i].hp_colors = 1 << 5;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp }
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if (colorequiv > 1) {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp int a = lowbit(colorequiv) - 1;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if (a > 15)
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp a = 15;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp for (i = 0; i < mmu_page_sizes; i++) {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp if ((colors = hw_page_array[i].hp_colors) <= 1) {
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp continue;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp }
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp while ((colors >> a) == 0)
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp a--;
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp colorequivszc[i] = (a << 4);
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp }
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp }
102033aa92edf302ad31b3bdd7c6fcd2d6910903dp}