17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 307c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 317c478bd9Sstevel@tonic-gate #include <sys/vm.h> 327c478bd9Sstevel@tonic-gate #include <sys/cpu.h> 337c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 347c478bd9Sstevel@tonic-gate #include <sys/reboot.h> 357c478bd9Sstevel@tonic-gate #include <sys/kdi.h> 367c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 377c478bd9Sstevel@tonic-gate #include <sys/memlist_plat.h> 387c478bd9Sstevel@tonic-gate #include <sys/memlist_impl.h> 397c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h> 407c478bd9Sstevel@tonic-gate #include <sys/prom_isa.h> 417c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 427c478bd9Sstevel@tonic-gate #include <sys/intreg.h> 437c478bd9Sstevel@tonic-gate #include <sys/ivintr.h> 447c478bd9Sstevel@tonic-gate #include <sys/fpu/fpusystm.h> 457c478bd9Sstevel@tonic-gate #include <sys/iommutsb.h> 467c478bd9Sstevel@tonic-gate #include <vm/vm_dep.h> 477c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h> 487c478bd9Sstevel@tonic-gate #include <vm/seg_kpm.h> 497c478bd9Sstevel@tonic-gate #include <vm/seg_map.h> 507c478bd9Sstevel@tonic-gate #include <vm/seg_kp.h> 517c478bd9Sstevel@tonic-gate #include <sys/sysconf.h> 527c478bd9Sstevel@tonic-gate #include <vm/hat_sfmmu.h> 537c478bd9Sstevel@tonic-gate #include <sys/kobj.h> 547c478bd9Sstevel@tonic-gate #include <sys/sun4asi.h> 557c478bd9Sstevel@tonic-gate #include <sys/clconf.h> 567c478bd9Sstevel@tonic-gate #include <sys/platform_module.h> 577c478bd9Sstevel@tonic-gate #include <sys/panic.h> 587c478bd9Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h> 597c478bd9Sstevel@tonic-gate #include <sys/clock.h> 607c478bd9Sstevel@tonic-gate #include <sys/fpras_impl.h> 617c478bd9Sstevel@tonic-gate #include <sys/prom_debug.h> 627c478bd9Sstevel@tonic-gate #include <sys/traptrace.h> 637c478bd9Sstevel@tonic-gate #include <sys/memnode.h> 647c478bd9Sstevel@tonic-gate #include <sys/mem_cage.h> 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate /* 677c478bd9Sstevel@tonic-gate * fpRAS implementation structures. 687c478bd9Sstevel@tonic-gate */ 697c478bd9Sstevel@tonic-gate struct fpras_chkfn *fpras_chkfnaddrs[FPRAS_NCOPYOPS]; 707c478bd9Sstevel@tonic-gate struct fpras_chkfngrp *fpras_chkfngrps; 717c478bd9Sstevel@tonic-gate struct fpras_chkfngrp *fpras_chkfngrps_base; 727c478bd9Sstevel@tonic-gate int fpras_frequency = -1; 737c478bd9Sstevel@tonic-gate int64_t fpras_interval = -1; 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate void 767c478bd9Sstevel@tonic-gate setup_trap_table(void) 777c478bd9Sstevel@tonic-gate { 787c478bd9Sstevel@tonic-gate intr_init(CPU); /* init interrupt request free list */ 797c478bd9Sstevel@tonic-gate setwstate(WSTATE_KERN); 807c478bd9Sstevel@tonic-gate prom_set_traptable(&trap_table); 817c478bd9Sstevel@tonic-gate } 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate void 847c478bd9Sstevel@tonic-gate mach_fpras() 857c478bd9Sstevel@tonic-gate { 867c478bd9Sstevel@tonic-gate if (fpras_implemented && !fpras_disable) { 877c478bd9Sstevel@tonic-gate int i; 887c478bd9Sstevel@tonic-gate struct fpras_chkfngrp *fcgp; 897c478bd9Sstevel@tonic-gate size_t chkfngrpsallocsz; 907c478bd9Sstevel@tonic-gate 917c478bd9Sstevel@tonic-gate /* 927c478bd9Sstevel@tonic-gate * Note that we size off of NCPU and setup for 937c478bd9Sstevel@tonic-gate * all those possibilities regardless of whether 947c478bd9Sstevel@tonic-gate * the cpu id is present or not. We do this so that 957c478bd9Sstevel@tonic-gate * we don't have any construction or destruction 967c478bd9Sstevel@tonic-gate * activity to perform at DR time, and it's not 977c478bd9Sstevel@tonic-gate * costly in memory. We require block alignment. 987c478bd9Sstevel@tonic-gate */ 997c478bd9Sstevel@tonic-gate chkfngrpsallocsz = NCPU * sizeof (struct fpras_chkfngrp); 1007c478bd9Sstevel@tonic-gate fpras_chkfngrps_base = kmem_alloc(chkfngrpsallocsz, KM_SLEEP); 1017c478bd9Sstevel@tonic-gate if (IS_P2ALIGNED((uintptr_t)fpras_chkfngrps_base, 64)) { 1027c478bd9Sstevel@tonic-gate fpras_chkfngrps = fpras_chkfngrps_base; 1037c478bd9Sstevel@tonic-gate } else { 1047c478bd9Sstevel@tonic-gate kmem_free(fpras_chkfngrps_base, chkfngrpsallocsz); 1057c478bd9Sstevel@tonic-gate chkfngrpsallocsz += 64; 1067c478bd9Sstevel@tonic-gate fpras_chkfngrps_base = kmem_alloc(chkfngrpsallocsz, 1077c478bd9Sstevel@tonic-gate KM_SLEEP); 1087c478bd9Sstevel@tonic-gate fpras_chkfngrps = (struct fpras_chkfngrp *) 1097c478bd9Sstevel@tonic-gate P2ROUNDUP((uintptr_t)fpras_chkfngrps_base, 64); 1107c478bd9Sstevel@tonic-gate } 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * Copy our check function into place for each copy operation 1147c478bd9Sstevel@tonic-gate * and each cpu id. 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate fcgp = &fpras_chkfngrps[0]; 1177c478bd9Sstevel@tonic-gate for (i = 0; i < FPRAS_NCOPYOPS; ++i) 1187c478bd9Sstevel@tonic-gate bcopy((void *)fpras_chkfn_type1, &fcgp->fpras_fn[i], 1197c478bd9Sstevel@tonic-gate sizeof (struct fpras_chkfn)); 1207c478bd9Sstevel@tonic-gate for (i = 1; i < NCPU; ++i) 1217c478bd9Sstevel@tonic-gate *(&fpras_chkfngrps[i]) = *fcgp; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* 1247c478bd9Sstevel@tonic-gate * At definition fpras_frequency is set to -1, and it will 1257c478bd9Sstevel@tonic-gate * still have that value unless changed in /etc/system (not 1267c478bd9Sstevel@tonic-gate * strictly supported, but not preventable). The following 1277c478bd9Sstevel@tonic-gate * both sets the default and sanity checks anything from 1287c478bd9Sstevel@tonic-gate * /etc/system. 1297c478bd9Sstevel@tonic-gate */ 1307c478bd9Sstevel@tonic-gate if (fpras_frequency < 0) 1317c478bd9Sstevel@tonic-gate fpras_frequency = FPRAS_DEFAULT_FREQUENCY; 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate /* 1347c478bd9Sstevel@tonic-gate * Now calculate fpras_interval. When fpras_interval 1357c478bd9Sstevel@tonic-gate * becomes non-negative fpras checks will commence 1367c478bd9Sstevel@tonic-gate * (copies before this point in boot will bypass fpras). 1377c478bd9Sstevel@tonic-gate * Our stores of instructions must be visible; no need 1387c478bd9Sstevel@tonic-gate * to flush as they're never been executed before. 1397c478bd9Sstevel@tonic-gate */ 1407c478bd9Sstevel@tonic-gate membar_producer(); 1417c478bd9Sstevel@tonic-gate fpras_interval = (fpras_frequency == 0) ? 1427c478bd9Sstevel@tonic-gate 0 : sys_tick_freq / fpras_frequency; 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate } 1457c478bd9Sstevel@tonic-gate 1467c478bd9Sstevel@tonic-gate void 1477c478bd9Sstevel@tonic-gate mach_hw_copy_limit(void) 1487c478bd9Sstevel@tonic-gate { 1497c478bd9Sstevel@tonic-gate if (!fpu_exists) { 1507c478bd9Sstevel@tonic-gate use_hw_bcopy = 0; 1517c478bd9Sstevel@tonic-gate hw_copy_limit_1 = 0; 1527c478bd9Sstevel@tonic-gate hw_copy_limit_2 = 0; 1537c478bd9Sstevel@tonic-gate hw_copy_limit_4 = 0; 1547c478bd9Sstevel@tonic-gate hw_copy_limit_8 = 0; 1557c478bd9Sstevel@tonic-gate use_hw_bzero = 0; 1567c478bd9Sstevel@tonic-gate } 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate void 1607c478bd9Sstevel@tonic-gate load_tod_module() 1617c478bd9Sstevel@tonic-gate { 1627c478bd9Sstevel@tonic-gate /* 1637c478bd9Sstevel@tonic-gate * Load tod driver module for the tod part found on this system. 1647c478bd9Sstevel@tonic-gate * Recompute the cpu frequency/delays based on tod as tod part 1657c478bd9Sstevel@tonic-gate * tends to keep time more accurately. 1667c478bd9Sstevel@tonic-gate */ 1677c478bd9Sstevel@tonic-gate if (tod_module_name == NULL || modload("tod", tod_module_name) == -1) 1687c478bd9Sstevel@tonic-gate halt("Can't load tod module"); 1697c478bd9Sstevel@tonic-gate } 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate void 1727c478bd9Sstevel@tonic-gate mach_memscrub(void) 1737c478bd9Sstevel@tonic-gate { 1747c478bd9Sstevel@tonic-gate /* 1757c478bd9Sstevel@tonic-gate * Startup memory scrubber, if not running fpu emulation code. 1767c478bd9Sstevel@tonic-gate */ 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate if (fpu_exists) { 1797c478bd9Sstevel@tonic-gate if (memscrub_init()) { 1807c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, 1817c478bd9Sstevel@tonic-gate "Memory scrubber failed to initialize"); 1827c478bd9Sstevel@tonic-gate } 1837c478bd9Sstevel@tonic-gate } 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate void 1877c478bd9Sstevel@tonic-gate mach_cpu_halt_idle() 1887c478bd9Sstevel@tonic-gate { 1897c478bd9Sstevel@tonic-gate /* no suport for halting idle CPU */ 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1937c478bd9Sstevel@tonic-gate void 1947c478bd9Sstevel@tonic-gate cpu_intrq_setup(struct cpu *cp) 1957c478bd9Sstevel@tonic-gate { 1967c478bd9Sstevel@tonic-gate /* Interrupt mondo queues not applicable to sun4u */ 1977c478bd9Sstevel@tonic-gate } 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2007c478bd9Sstevel@tonic-gate void 2017c478bd9Sstevel@tonic-gate cpu_intrq_register(struct cpu *cp) 2027c478bd9Sstevel@tonic-gate { 2037c478bd9Sstevel@tonic-gate /* Interrupt/error queues not applicable to sun4u */ 2047c478bd9Sstevel@tonic-gate } 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2077c478bd9Sstevel@tonic-gate void 208*db6d2ee3Ssvemuri mach_htraptrace_setup(int cpuid) 2097c478bd9Sstevel@tonic-gate { 2107c478bd9Sstevel@tonic-gate /* Setup hypervisor traptrace buffer, not applicable to sun4u */ 2117c478bd9Sstevel@tonic-gate } 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2147c478bd9Sstevel@tonic-gate void 215*db6d2ee3Ssvemuri mach_htraptrace_configure(int cpuid) 2167c478bd9Sstevel@tonic-gate { 217*db6d2ee3Ssvemuri /* enable/ disable hypervisor traptracing, not applicable to sun4u */ 218*db6d2ee3Ssvemuri } 219*db6d2ee3Ssvemuri 220*db6d2ee3Ssvemuri /*ARGSUSED*/ 221*db6d2ee3Ssvemuri void 222*db6d2ee3Ssvemuri mach_htraptrace_init(void) 223*db6d2ee3Ssvemuri { 224*db6d2ee3Ssvemuri /* allocate hypervisor traptrace buffer, not applicable to sun4u */ 225*db6d2ee3Ssvemuri } 226*db6d2ee3Ssvemuri 227*db6d2ee3Ssvemuri /*ARGSUSED*/ 228*db6d2ee3Ssvemuri void 229*db6d2ee3Ssvemuri mach_htraptrace_cleanup(int cpuid) 230*db6d2ee3Ssvemuri { 231*db6d2ee3Ssvemuri /* cleanup hypervisor traptrace buffer, not applicable to sun4u */ 2327c478bd9Sstevel@tonic-gate } 2337c478bd9Sstevel@tonic-gate 2347c478bd9Sstevel@tonic-gate void 2357c478bd9Sstevel@tonic-gate mach_descrip_init(void) 2367c478bd9Sstevel@tonic-gate { 2377c478bd9Sstevel@tonic-gate /* Obtain Machine description - only for sun4v */ 2387c478bd9Sstevel@tonic-gate } 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate /* 2417c478bd9Sstevel@tonic-gate * Return true if the machine we're running on is a Positron. 2427c478bd9Sstevel@tonic-gate * (Positron is an unsupported developers platform.) 2437c478bd9Sstevel@tonic-gate */ 2447c478bd9Sstevel@tonic-gate int 2457c478bd9Sstevel@tonic-gate iam_positron(void) 2467c478bd9Sstevel@tonic-gate { 2477c478bd9Sstevel@tonic-gate char model[32]; 2487c478bd9Sstevel@tonic-gate const char proto_model[] = "SUNW,501-2732"; 249fa9e4066Sahrens pnode_t root = prom_rootnode(); 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate if (prom_getproplen(root, "model") != sizeof (proto_model)) 2527c478bd9Sstevel@tonic-gate return (0); 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate (void) prom_getprop(root, "model", model); 2557c478bd9Sstevel@tonic-gate if (strcmp(model, proto_model) == 0) 2567c478bd9Sstevel@tonic-gate return (1); 2577c478bd9Sstevel@tonic-gate return (0); 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate /* 2617c478bd9Sstevel@tonic-gate * Find a physically contiguous area of twice the largest ecache size 2627c478bd9Sstevel@tonic-gate * to be used while doing displacement flush of ecaches. 2637c478bd9Sstevel@tonic-gate */ 2647c478bd9Sstevel@tonic-gate uint64_t 2657c478bd9Sstevel@tonic-gate ecache_flush_address(void) 2667c478bd9Sstevel@tonic-gate { 2677c478bd9Sstevel@tonic-gate struct memlist *pmem; 2687c478bd9Sstevel@tonic-gate uint64_t flush_size; 2697c478bd9Sstevel@tonic-gate uint64_t ret_val; 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate flush_size = ecache_size * 2; 2727c478bd9Sstevel@tonic-gate for (pmem = phys_install; pmem; pmem = pmem->next) { 2737c478bd9Sstevel@tonic-gate ret_val = P2ROUNDUP(pmem->address, ecache_size); 2747c478bd9Sstevel@tonic-gate if (ret_val + flush_size <= pmem->address + pmem->size) 2757c478bd9Sstevel@tonic-gate return (ret_val); 2767c478bd9Sstevel@tonic-gate } 2777c478bd9Sstevel@tonic-gate return ((uint64_t)-1); 2787c478bd9Sstevel@tonic-gate } 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate /* 2817c478bd9Sstevel@tonic-gate * Called with the memlist lock held to say that phys_install has 2827c478bd9Sstevel@tonic-gate * changed. 2837c478bd9Sstevel@tonic-gate */ 2847c478bd9Sstevel@tonic-gate void 2857c478bd9Sstevel@tonic-gate phys_install_has_changed(void) 2867c478bd9Sstevel@tonic-gate { 2877c478bd9Sstevel@tonic-gate /* 2887c478bd9Sstevel@tonic-gate * Get the new address into a temporary just in case panicking 2897c478bd9Sstevel@tonic-gate * involves use of ecache_flushaddr. 2907c478bd9Sstevel@tonic-gate */ 2917c478bd9Sstevel@tonic-gate uint64_t new_addr; 2927c478bd9Sstevel@tonic-gate 2937c478bd9Sstevel@tonic-gate new_addr = ecache_flush_address(); 2947c478bd9Sstevel@tonic-gate if (new_addr == (uint64_t)-1) { 2957c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, 2967c478bd9Sstevel@tonic-gate "ecache_flush_address(): failed, ecache_size=%x", 2977c478bd9Sstevel@tonic-gate ecache_size); 2987c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 2997c478bd9Sstevel@tonic-gate } 3007c478bd9Sstevel@tonic-gate ecache_flushaddr = new_addr; 3017c478bd9Sstevel@tonic-gate membar_producer(); 3027c478bd9Sstevel@tonic-gate } 303