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 5c56c1e58Sgirish * Common Development and Distribution License (the "License"). 6c56c1e58Sgirish * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22c56c1e58Sgirish * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <sys/types.h> 297c478bd9Sstevel@tonic-gate #include <sys/systm.h> 307c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 317c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 327c478bd9Sstevel@tonic-gate #include <sys/disp.h> 337c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 347c478bd9Sstevel@tonic-gate #include <sys/promif.h> 357c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h> 367c478bd9Sstevel@tonic-gate #include <sys/clock.h> 377c478bd9Sstevel@tonic-gate #include <sys/pte.h> 387c478bd9Sstevel@tonic-gate #include <sys/scb.h> 397c478bd9Sstevel@tonic-gate #include <sys/cpu.h> 407c478bd9Sstevel@tonic-gate #include <sys/stack.h> 417c478bd9Sstevel@tonic-gate #include <sys/intreg.h> 427c478bd9Sstevel@tonic-gate #include <sys/ivintr.h> 437c478bd9Sstevel@tonic-gate #include <vm/as.h> 447c478bd9Sstevel@tonic-gate #include <vm/hat_sfmmu.h> 457c478bd9Sstevel@tonic-gate #include <sys/reboot.h> 467c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 477c478bd9Sstevel@tonic-gate #include <sys/vtrace.h> 487c478bd9Sstevel@tonic-gate #include <sys/trap.h> 497c478bd9Sstevel@tonic-gate #include <sys/machtrap.h> 507c478bd9Sstevel@tonic-gate #include <sys/privregs.h> 517c478bd9Sstevel@tonic-gate #include <sys/machpcb.h> 527c478bd9Sstevel@tonic-gate #include <sys/proc.h> 537c478bd9Sstevel@tonic-gate #include <sys/cpupart.h> 547c478bd9Sstevel@tonic-gate #include <sys/pset.h> 557c478bd9Sstevel@tonic-gate #include <sys/cpu_module.h> 567c478bd9Sstevel@tonic-gate #include <sys/copyops.h> 577c478bd9Sstevel@tonic-gate #include <sys/panic.h> 587c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> /* for bootops */ 597c478bd9Sstevel@tonic-gate #include <sys/chip.h> 607c478bd9Sstevel@tonic-gate #include <sys/kdi.h> 617c478bd9Sstevel@tonic-gate #include <sys/fpras.h> 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate #include <sys/prom_debug.h> 647c478bd9Sstevel@tonic-gate #include <sys/debug.h> 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 677c478bd9Sstevel@tonic-gate #include <sys/lgrp.h> 687c478bd9Sstevel@tonic-gate #include <sys/traptrace.h> 697c478bd9Sstevel@tonic-gate /* 707c478bd9Sstevel@tonic-gate * External Routines: 717c478bd9Sstevel@tonic-gate */ 727c478bd9Sstevel@tonic-gate extern void map_wellknown_devices(void); 73c56c1e58Sgirish extern void hsvc_setup(void); 741ae08745Sheppo extern void mach_descrip_startup_init(void); 75*3b890a5bSjb145095 extern void mach_soft_state_init(void); 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate int dcache_size; 787c478bd9Sstevel@tonic-gate int dcache_linesize; 797c478bd9Sstevel@tonic-gate int icache_size; 807c478bd9Sstevel@tonic-gate int icache_linesize; 817c478bd9Sstevel@tonic-gate int ecache_size; 827c478bd9Sstevel@tonic-gate int ecache_alignsize; 837c478bd9Sstevel@tonic-gate int ecache_associativity; 847c478bd9Sstevel@tonic-gate int ecache_setsize; /* max possible e$ setsize */ 857c478bd9Sstevel@tonic-gate int cpu_setsize; /* max e$ setsize of configured cpus */ 867c478bd9Sstevel@tonic-gate int dcache_line_mask; /* spitfire only */ 877c478bd9Sstevel@tonic-gate int vac_size; /* cache size in bytes */ 887c478bd9Sstevel@tonic-gate uint_t vac_mask; /* VAC alignment consistency mask */ 897c478bd9Sstevel@tonic-gate int vac_shift; /* log2(vac_size) for ppmapout() */ 907c478bd9Sstevel@tonic-gate int vac = 0; /* virtual address cache type (none == 0) */ 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate /* 937c478bd9Sstevel@tonic-gate * fpRAS. An individual sun4* machine class (or perhaps subclass, 947c478bd9Sstevel@tonic-gate * eg sun4u/cheetah) must set fpras_implemented to indicate that it implements 957c478bd9Sstevel@tonic-gate * the fpRAS feature. The feature can be suppressed by setting fpras_disable 967c478bd9Sstevel@tonic-gate * or the mechanism can be disabled for individual copy operations with 977c478bd9Sstevel@tonic-gate * fpras_disableids. All these are checked in post_startup() code so 987c478bd9Sstevel@tonic-gate * fpras_disable and fpras_disableids can be set in /etc/system. 997c478bd9Sstevel@tonic-gate * If/when fpRAS is implemented on non-sun4 architectures these 1007c478bd9Sstevel@tonic-gate * definitions will need to move up to the common level. 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate int fpras_implemented; 1037c478bd9Sstevel@tonic-gate int fpras_disable; 1047c478bd9Sstevel@tonic-gate int fpras_disableids; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * Static Routines: 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate static void kern_splr_preprom(void); 1107c478bd9Sstevel@tonic-gate static void kern_splx_postprom(void); 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * Setup routine called right before main(). Interposing this function 1147c478bd9Sstevel@tonic-gate * before main() allows us to call it in a machine-independent fashion. 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate void 1187c478bd9Sstevel@tonic-gate mlsetup(struct regs *rp, void *cif, kfpu_t *fp) 1197c478bd9Sstevel@tonic-gate { 1207c478bd9Sstevel@tonic-gate struct machpcb *mpcb; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate extern char t0stack[]; 1237c478bd9Sstevel@tonic-gate extern struct classfuncs sys_classfuncs; 1247c478bd9Sstevel@tonic-gate extern disp_t cpu0_disp; 1257c478bd9Sstevel@tonic-gate unsigned long long pa; 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE 1287c478bd9Sstevel@tonic-gate TRAP_TRACE_CTL *ctlp; 1297c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */ 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate /* 1327c478bd9Sstevel@tonic-gate * initialize cpu_self 1337c478bd9Sstevel@tonic-gate */ 1347c478bd9Sstevel@tonic-gate cpu0.cpu_self = &cpu0; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate /* 1377c478bd9Sstevel@tonic-gate * initialize t0 1387c478bd9Sstevel@tonic-gate */ 1397c478bd9Sstevel@tonic-gate t0.t_stk = (caddr_t)rp - REGOFF; 1407c478bd9Sstevel@tonic-gate /* Can't use va_to_pa here - wait until prom_ initialized */ 1417c478bd9Sstevel@tonic-gate t0.t_stkbase = t0stack; 1427c478bd9Sstevel@tonic-gate t0.t_pri = maxclsyspri - 3; 1437c478bd9Sstevel@tonic-gate t0.t_schedflag = TS_LOAD | TS_DONT_SWAP; 1447c478bd9Sstevel@tonic-gate t0.t_procp = &p0; 1457c478bd9Sstevel@tonic-gate t0.t_plockp = &p0lock.pl_lock; 1467c478bd9Sstevel@tonic-gate t0.t_lwp = &lwp0; 1477c478bd9Sstevel@tonic-gate t0.t_forw = &t0; 1487c478bd9Sstevel@tonic-gate t0.t_back = &t0; 1497c478bd9Sstevel@tonic-gate t0.t_next = &t0; 1507c478bd9Sstevel@tonic-gate t0.t_prev = &t0; 1517c478bd9Sstevel@tonic-gate t0.t_cpu = &cpu0; /* loaded by _start */ 1527c478bd9Sstevel@tonic-gate t0.t_disp_queue = &cpu0_disp; 1537c478bd9Sstevel@tonic-gate t0.t_bind_cpu = PBIND_NONE; 1547c478bd9Sstevel@tonic-gate t0.t_bind_pset = PS_NONE; 1557c478bd9Sstevel@tonic-gate t0.t_cpupart = &cp_default; 1567c478bd9Sstevel@tonic-gate t0.t_clfuncs = &sys_classfuncs.thread; 1577c478bd9Sstevel@tonic-gate t0.t_copyops = NULL; 1587c478bd9Sstevel@tonic-gate THREAD_ONPROC(&t0, CPU); 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate lwp0.lwp_thread = &t0; 1617c478bd9Sstevel@tonic-gate lwp0.lwp_procp = &p0; 1627c478bd9Sstevel@tonic-gate lwp0.lwp_regs = (void *)rp; 1637c478bd9Sstevel@tonic-gate t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1; 1647c478bd9Sstevel@tonic-gate 1657c478bd9Sstevel@tonic-gate mpcb = lwptompcb(&lwp0); 1667c478bd9Sstevel@tonic-gate mpcb->mpcb_fpu = fp; 1677c478bd9Sstevel@tonic-gate mpcb->mpcb_fpu->fpu_q = mpcb->mpcb_fpu_q; 1687c478bd9Sstevel@tonic-gate mpcb->mpcb_thread = &t0; 1697c478bd9Sstevel@tonic-gate lwp0.lwp_fpu = (void *)mpcb->mpcb_fpu; 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate p0.p_exec = NULL; 1727c478bd9Sstevel@tonic-gate p0.p_stat = SRUN; 1737c478bd9Sstevel@tonic-gate p0.p_flag = SSYS; 1747c478bd9Sstevel@tonic-gate p0.p_tlist = &t0; 1757c478bd9Sstevel@tonic-gate p0.p_stksize = 2*PAGESIZE; 1767c478bd9Sstevel@tonic-gate p0.p_stkpageszc = 0; 1777c478bd9Sstevel@tonic-gate p0.p_as = &kas; 1787c478bd9Sstevel@tonic-gate p0.p_lockp = &p0lock; 1797c478bd9Sstevel@tonic-gate p0.p_utraps = NULL; 1807c478bd9Sstevel@tonic-gate p0.p_brkpageszc = 0; 1817c478bd9Sstevel@tonic-gate sigorset(&p0.p_ignore, &ignoredefault); 1827c478bd9Sstevel@tonic-gate 1837c478bd9Sstevel@tonic-gate CPU->cpu_thread = &t0; 1847c478bd9Sstevel@tonic-gate CPU->cpu_dispthread = &t0; 1857c478bd9Sstevel@tonic-gate bzero(&cpu0_disp, sizeof (disp_t)); 1867c478bd9Sstevel@tonic-gate CPU->cpu_disp = &cpu0_disp; 1877c478bd9Sstevel@tonic-gate CPU->cpu_disp->disp_cpu = CPU; 1887c478bd9Sstevel@tonic-gate CPU->cpu_idle_thread = &t0; 1897c478bd9Sstevel@tonic-gate CPU->cpu_flags = CPU_RUNNING; 1907c478bd9Sstevel@tonic-gate CPU->cpu_id = getprocessorid(); 1917c478bd9Sstevel@tonic-gate CPU->cpu_dispatch_pri = t0.t_pri; 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate /* 1947c478bd9Sstevel@tonic-gate * Initialize thread/cpu microstate accounting here 1957c478bd9Sstevel@tonic-gate */ 1967c478bd9Sstevel@tonic-gate init_mstate(&t0, LMS_SYSTEM); 1977c478bd9Sstevel@tonic-gate init_cpu_mstate(CPU, CMS_SYSTEM); 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate /* 2007c478bd9Sstevel@tonic-gate * Initialize lists of available and active CPUs. 2017c478bd9Sstevel@tonic-gate */ 2027c478bd9Sstevel@tonic-gate cpu_list_init(CPU); 2037c478bd9Sstevel@tonic-gate 204affbd3ccSkchow cpu_vm_data_init(CPU); 205affbd3ccSkchow 2067c478bd9Sstevel@tonic-gate prom_init("kernel", cif); 2077c478bd9Sstevel@tonic-gate (void) prom_set_preprom(kern_splr_preprom); 2087c478bd9Sstevel@tonic-gate (void) prom_set_postprom(kern_splx_postprom); 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate PRM_INFO("mlsetup: now ok to call prom_printf"); 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate mpcb->mpcb_pa = va_to_pa(t0.t_stk); 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate /* 2157c478bd9Sstevel@tonic-gate * Claim the physical and virtual resources used by panicbuf, 2167c478bd9Sstevel@tonic-gate * then map panicbuf. This operation removes the phys and 2177c478bd9Sstevel@tonic-gate * virtual addresses from the free lists. 2187c478bd9Sstevel@tonic-gate */ 2197c478bd9Sstevel@tonic-gate if (prom_claim_virt(PANICBUFSIZE, panicbuf) != panicbuf) 2207c478bd9Sstevel@tonic-gate prom_panic("Can't claim panicbuf virtual address"); 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate if (prom_retain("panicbuf", PANICBUFSIZE, MMU_PAGESIZE, &pa) != 0) 2237c478bd9Sstevel@tonic-gate prom_panic("Can't allocate retained panicbuf physical address"); 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate if (prom_map_phys(-1, PANICBUFSIZE, panicbuf, pa) != 0) 2267c478bd9Sstevel@tonic-gate prom_panic("Can't map panicbuf"); 2277c478bd9Sstevel@tonic-gate 2287c478bd9Sstevel@tonic-gate PRM_DEBUG(panicbuf); 2297c478bd9Sstevel@tonic-gate PRM_DEBUG(pa); 2307c478bd9Sstevel@tonic-gate 231c56c1e58Sgirish /* 232c56c1e58Sgirish * Negotiate hypervisor services, if any 233c56c1e58Sgirish */ 234c56c1e58Sgirish hsvc_setup(); 235*3b890a5bSjb145095 mach_soft_state_init(); 236c56c1e58Sgirish 2377c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE 2387c478bd9Sstevel@tonic-gate /* 2397c478bd9Sstevel@tonic-gate * initialize the trap trace buffer for the boot cpu 2407c478bd9Sstevel@tonic-gate * XXX todo, dynamically allocate this buffer too 2417c478bd9Sstevel@tonic-gate */ 2427c478bd9Sstevel@tonic-gate ctlp = &trap_trace_ctl[CPU->cpu_id]; 2437c478bd9Sstevel@tonic-gate ctlp->d.vaddr_base = trap_tr0; 2447c478bd9Sstevel@tonic-gate ctlp->d.offset = ctlp->d.last_offset = 0; 2457c478bd9Sstevel@tonic-gate ctlp->d.limit = TRAP_TSIZE; /* XXX dynamic someday */ 2467c478bd9Sstevel@tonic-gate ctlp->d.paddr_base = va_to_pa(trap_tr0); 247db6d2ee3Ssvemuri #endif /* TRAPTRACE */ 2481ae08745Sheppo 2491ae08745Sheppo /* 2501ae08745Sheppo * Initialize the Machine Description kernel framework 2511ae08745Sheppo */ 2521ae08745Sheppo 2531ae08745Sheppo mach_descrip_startup_init(); 2541ae08745Sheppo 2557c478bd9Sstevel@tonic-gate /* 2567c478bd9Sstevel@tonic-gate * initialize HV trap trace buffer for the boot cpu 2577c478bd9Sstevel@tonic-gate */ 258db6d2ee3Ssvemuri mach_htraptrace_setup(CPU->cpu_id); 259db6d2ee3Ssvemuri mach_htraptrace_configure(CPU->cpu_id); 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate /* 2627c478bd9Sstevel@tonic-gate * lgroup framework initialization. This must be done prior 2637c478bd9Sstevel@tonic-gate * to devices being mapped. 2647c478bd9Sstevel@tonic-gate */ 2657c478bd9Sstevel@tonic-gate lgrp_init(); 2667c478bd9Sstevel@tonic-gate 2677c478bd9Sstevel@tonic-gate cpu_setup(); 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate if (boothowto & RB_HALT) { 2707c478bd9Sstevel@tonic-gate prom_printf("unix: kernel halted by -h flag\n"); 2717c478bd9Sstevel@tonic-gate prom_enter_mon(); 2727c478bd9Sstevel@tonic-gate } 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate setcputype(); 2757c478bd9Sstevel@tonic-gate map_wellknown_devices(); 2767c478bd9Sstevel@tonic-gate setcpudelay(); 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate /* 2797c478bd9Sstevel@tonic-gate * Associate the boot cpu with a physical processor. 2807c478bd9Sstevel@tonic-gate * This needs to be done after devices are mapped, since 2817c478bd9Sstevel@tonic-gate * we need to know what type of physical processor this is. 2827c478bd9Sstevel@tonic-gate * (CMP for example) 2837c478bd9Sstevel@tonic-gate */ 2847c478bd9Sstevel@tonic-gate chip_cpu_init(CPU); 2857c478bd9Sstevel@tonic-gate chip_cpu_assign(CPU); 2867c478bd9Sstevel@tonic-gate } 2877c478bd9Sstevel@tonic-gate 2887c478bd9Sstevel@tonic-gate /* 2897c478bd9Sstevel@tonic-gate * These routines are called immediately before and 2907c478bd9Sstevel@tonic-gate * immediately after calling into the firmware. The 2917c478bd9Sstevel@tonic-gate * firmware is significantly confused by preemption - 2927c478bd9Sstevel@tonic-gate * particularly on MP machines - but also on UP's too. 2937c478bd9Sstevel@tonic-gate */ 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate static int saved_spl; 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate static void 2987c478bd9Sstevel@tonic-gate kern_splr_preprom(void) 2997c478bd9Sstevel@tonic-gate { 3007c478bd9Sstevel@tonic-gate saved_spl = spl7(); 3017c478bd9Sstevel@tonic-gate } 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate static void 3047c478bd9Sstevel@tonic-gate kern_splx_postprom(void) 3057c478bd9Sstevel@tonic-gate { 3067c478bd9Sstevel@tonic-gate splx(saved_spl); 3077c478bd9Sstevel@tonic-gate } 308