10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51592Sgirish * Common Development and Distribution License (the "License"). 61592Sgirish * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 221592Sgirish * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <sys/types.h> 290Sstevel@tonic-gate #include <sys/systm.h> 300Sstevel@tonic-gate #include <sys/archsystm.h> 310Sstevel@tonic-gate #include <sys/machsystm.h> 320Sstevel@tonic-gate #include <sys/disp.h> 330Sstevel@tonic-gate #include <sys/autoconf.h> 340Sstevel@tonic-gate #include <sys/promif.h> 350Sstevel@tonic-gate #include <sys/prom_plat.h> 360Sstevel@tonic-gate #include <sys/clock.h> 370Sstevel@tonic-gate #include <sys/pte.h> 380Sstevel@tonic-gate #include <sys/scb.h> 390Sstevel@tonic-gate #include <sys/cpu.h> 400Sstevel@tonic-gate #include <sys/stack.h> 410Sstevel@tonic-gate #include <sys/intreg.h> 420Sstevel@tonic-gate #include <sys/ivintr.h> 430Sstevel@tonic-gate #include <vm/as.h> 440Sstevel@tonic-gate #include <vm/hat_sfmmu.h> 450Sstevel@tonic-gate #include <sys/reboot.h> 460Sstevel@tonic-gate #include <sys/sysmacros.h> 470Sstevel@tonic-gate #include <sys/vtrace.h> 480Sstevel@tonic-gate #include <sys/trap.h> 490Sstevel@tonic-gate #include <sys/machtrap.h> 500Sstevel@tonic-gate #include <sys/privregs.h> 510Sstevel@tonic-gate #include <sys/machpcb.h> 520Sstevel@tonic-gate #include <sys/proc.h> 530Sstevel@tonic-gate #include <sys/cpupart.h> 540Sstevel@tonic-gate #include <sys/pset.h> 550Sstevel@tonic-gate #include <sys/cpu_module.h> 560Sstevel@tonic-gate #include <sys/copyops.h> 570Sstevel@tonic-gate #include <sys/panic.h> 580Sstevel@tonic-gate #include <sys/bootconf.h> /* for bootops */ 590Sstevel@tonic-gate #include <sys/chip.h> 600Sstevel@tonic-gate #include <sys/kdi.h> 610Sstevel@tonic-gate #include <sys/fpras.h> 620Sstevel@tonic-gate 630Sstevel@tonic-gate #include <sys/prom_debug.h> 640Sstevel@tonic-gate #include <sys/debug.h> 650Sstevel@tonic-gate 660Sstevel@tonic-gate #include <sys/sunddi.h> 670Sstevel@tonic-gate #include <sys/lgrp.h> 680Sstevel@tonic-gate #include <sys/traptrace.h> 690Sstevel@tonic-gate /* 700Sstevel@tonic-gate * External Routines: 710Sstevel@tonic-gate */ 720Sstevel@tonic-gate extern void map_wellknown_devices(void); 731592Sgirish extern void hsvc_setup(void); 74*1991Sheppo extern void mach_descrip_startup_init(void); 750Sstevel@tonic-gate 760Sstevel@tonic-gate int dcache_size; 770Sstevel@tonic-gate int dcache_linesize; 780Sstevel@tonic-gate int icache_size; 790Sstevel@tonic-gate int icache_linesize; 800Sstevel@tonic-gate int ecache_size; 810Sstevel@tonic-gate int ecache_alignsize; 820Sstevel@tonic-gate int ecache_associativity; 830Sstevel@tonic-gate int ecache_setsize; /* max possible e$ setsize */ 840Sstevel@tonic-gate int cpu_setsize; /* max e$ setsize of configured cpus */ 850Sstevel@tonic-gate int dcache_line_mask; /* spitfire only */ 860Sstevel@tonic-gate int vac_size; /* cache size in bytes */ 870Sstevel@tonic-gate uint_t vac_mask; /* VAC alignment consistency mask */ 880Sstevel@tonic-gate int vac_shift; /* log2(vac_size) for ppmapout() */ 890Sstevel@tonic-gate int vac = 0; /* virtual address cache type (none == 0) */ 900Sstevel@tonic-gate 910Sstevel@tonic-gate /* 920Sstevel@tonic-gate * fpRAS. An individual sun4* machine class (or perhaps subclass, 930Sstevel@tonic-gate * eg sun4u/cheetah) must set fpras_implemented to indicate that it implements 940Sstevel@tonic-gate * the fpRAS feature. The feature can be suppressed by setting fpras_disable 950Sstevel@tonic-gate * or the mechanism can be disabled for individual copy operations with 960Sstevel@tonic-gate * fpras_disableids. All these are checked in post_startup() code so 970Sstevel@tonic-gate * fpras_disable and fpras_disableids can be set in /etc/system. 980Sstevel@tonic-gate * If/when fpRAS is implemented on non-sun4 architectures these 990Sstevel@tonic-gate * definitions will need to move up to the common level. 1000Sstevel@tonic-gate */ 1010Sstevel@tonic-gate int fpras_implemented; 1020Sstevel@tonic-gate int fpras_disable; 1030Sstevel@tonic-gate int fpras_disableids; 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate /* 1060Sstevel@tonic-gate * Static Routines: 1070Sstevel@tonic-gate */ 1080Sstevel@tonic-gate static void kern_splr_preprom(void); 1090Sstevel@tonic-gate static void kern_splx_postprom(void); 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate /* 1120Sstevel@tonic-gate * Setup routine called right before main(). Interposing this function 1130Sstevel@tonic-gate * before main() allows us to call it in a machine-independent fashion. 1140Sstevel@tonic-gate */ 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate void 1170Sstevel@tonic-gate mlsetup(struct regs *rp, void *cif, kfpu_t *fp) 1180Sstevel@tonic-gate { 1190Sstevel@tonic-gate struct machpcb *mpcb; 1200Sstevel@tonic-gate 1210Sstevel@tonic-gate extern char t0stack[]; 1220Sstevel@tonic-gate extern struct classfuncs sys_classfuncs; 1230Sstevel@tonic-gate extern disp_t cpu0_disp; 1240Sstevel@tonic-gate unsigned long long pa; 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate #ifdef TRAPTRACE 1270Sstevel@tonic-gate TRAP_TRACE_CTL *ctlp; 1280Sstevel@tonic-gate #endif /* TRAPTRACE */ 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate /* 1310Sstevel@tonic-gate * initialize cpu_self 1320Sstevel@tonic-gate */ 1330Sstevel@tonic-gate cpu0.cpu_self = &cpu0; 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate /* 1360Sstevel@tonic-gate * initialize t0 1370Sstevel@tonic-gate */ 1380Sstevel@tonic-gate t0.t_stk = (caddr_t)rp - REGOFF; 1390Sstevel@tonic-gate /* Can't use va_to_pa here - wait until prom_ initialized */ 1400Sstevel@tonic-gate t0.t_stkbase = t0stack; 1410Sstevel@tonic-gate t0.t_pri = maxclsyspri - 3; 1420Sstevel@tonic-gate t0.t_schedflag = TS_LOAD | TS_DONT_SWAP; 1430Sstevel@tonic-gate t0.t_procp = &p0; 1440Sstevel@tonic-gate t0.t_plockp = &p0lock.pl_lock; 1450Sstevel@tonic-gate t0.t_lwp = &lwp0; 1460Sstevel@tonic-gate t0.t_forw = &t0; 1470Sstevel@tonic-gate t0.t_back = &t0; 1480Sstevel@tonic-gate t0.t_next = &t0; 1490Sstevel@tonic-gate t0.t_prev = &t0; 1500Sstevel@tonic-gate t0.t_cpu = &cpu0; /* loaded by _start */ 1510Sstevel@tonic-gate t0.t_disp_queue = &cpu0_disp; 1520Sstevel@tonic-gate t0.t_bind_cpu = PBIND_NONE; 1530Sstevel@tonic-gate t0.t_bind_pset = PS_NONE; 1540Sstevel@tonic-gate t0.t_cpupart = &cp_default; 1550Sstevel@tonic-gate t0.t_clfuncs = &sys_classfuncs.thread; 1560Sstevel@tonic-gate t0.t_copyops = NULL; 1570Sstevel@tonic-gate THREAD_ONPROC(&t0, CPU); 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate lwp0.lwp_thread = &t0; 1600Sstevel@tonic-gate lwp0.lwp_procp = &p0; 1610Sstevel@tonic-gate lwp0.lwp_regs = (void *)rp; 1620Sstevel@tonic-gate t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate mpcb = lwptompcb(&lwp0); 1650Sstevel@tonic-gate mpcb->mpcb_fpu = fp; 1660Sstevel@tonic-gate mpcb->mpcb_fpu->fpu_q = mpcb->mpcb_fpu_q; 1670Sstevel@tonic-gate mpcb->mpcb_thread = &t0; 1680Sstevel@tonic-gate lwp0.lwp_fpu = (void *)mpcb->mpcb_fpu; 1690Sstevel@tonic-gate 1700Sstevel@tonic-gate p0.p_exec = NULL; 1710Sstevel@tonic-gate p0.p_stat = SRUN; 1720Sstevel@tonic-gate p0.p_flag = SSYS; 1730Sstevel@tonic-gate p0.p_tlist = &t0; 1740Sstevel@tonic-gate p0.p_stksize = 2*PAGESIZE; 1750Sstevel@tonic-gate p0.p_stkpageszc = 0; 1760Sstevel@tonic-gate p0.p_as = &kas; 1770Sstevel@tonic-gate p0.p_lockp = &p0lock; 1780Sstevel@tonic-gate p0.p_utraps = NULL; 1790Sstevel@tonic-gate p0.p_brkpageszc = 0; 1800Sstevel@tonic-gate sigorset(&p0.p_ignore, &ignoredefault); 1810Sstevel@tonic-gate 1820Sstevel@tonic-gate CPU->cpu_thread = &t0; 1830Sstevel@tonic-gate CPU->cpu_dispthread = &t0; 1840Sstevel@tonic-gate bzero(&cpu0_disp, sizeof (disp_t)); 1850Sstevel@tonic-gate CPU->cpu_disp = &cpu0_disp; 1860Sstevel@tonic-gate CPU->cpu_disp->disp_cpu = CPU; 1870Sstevel@tonic-gate CPU->cpu_idle_thread = &t0; 1880Sstevel@tonic-gate CPU->cpu_flags = CPU_RUNNING; 1890Sstevel@tonic-gate CPU->cpu_id = getprocessorid(); 1900Sstevel@tonic-gate CPU->cpu_dispatch_pri = t0.t_pri; 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate /* 1930Sstevel@tonic-gate * Initialize thread/cpu microstate accounting here 1940Sstevel@tonic-gate */ 1950Sstevel@tonic-gate init_mstate(&t0, LMS_SYSTEM); 1960Sstevel@tonic-gate init_cpu_mstate(CPU, CMS_SYSTEM); 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate /* 1990Sstevel@tonic-gate * Initialize lists of available and active CPUs. 2000Sstevel@tonic-gate */ 2010Sstevel@tonic-gate cpu_list_init(CPU); 2020Sstevel@tonic-gate 203414Skchow cpu_vm_data_init(CPU); 204414Skchow 2050Sstevel@tonic-gate prom_init("kernel", cif); 2060Sstevel@tonic-gate (void) prom_set_preprom(kern_splr_preprom); 2070Sstevel@tonic-gate (void) prom_set_postprom(kern_splx_postprom); 2080Sstevel@tonic-gate 2090Sstevel@tonic-gate PRM_INFO("mlsetup: now ok to call prom_printf"); 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate mpcb->mpcb_pa = va_to_pa(t0.t_stk); 2120Sstevel@tonic-gate 2130Sstevel@tonic-gate /* 2140Sstevel@tonic-gate * Claim the physical and virtual resources used by panicbuf, 2150Sstevel@tonic-gate * then map panicbuf. This operation removes the phys and 2160Sstevel@tonic-gate * virtual addresses from the free lists. 2170Sstevel@tonic-gate */ 2180Sstevel@tonic-gate if (prom_claim_virt(PANICBUFSIZE, panicbuf) != panicbuf) 2190Sstevel@tonic-gate prom_panic("Can't claim panicbuf virtual address"); 2200Sstevel@tonic-gate 2210Sstevel@tonic-gate if (prom_retain("panicbuf", PANICBUFSIZE, MMU_PAGESIZE, &pa) != 0) 2220Sstevel@tonic-gate prom_panic("Can't allocate retained panicbuf physical address"); 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate if (prom_map_phys(-1, PANICBUFSIZE, panicbuf, pa) != 0) 2250Sstevel@tonic-gate prom_panic("Can't map panicbuf"); 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate PRM_DEBUG(panicbuf); 2280Sstevel@tonic-gate PRM_DEBUG(pa); 2290Sstevel@tonic-gate 2301592Sgirish /* 2311592Sgirish * Negotiate hypervisor services, if any 2321592Sgirish */ 2331592Sgirish hsvc_setup(); 2341592Sgirish 2350Sstevel@tonic-gate #ifdef TRAPTRACE 2360Sstevel@tonic-gate /* 2370Sstevel@tonic-gate * initialize the trap trace buffer for the boot cpu 2380Sstevel@tonic-gate * XXX todo, dynamically allocate this buffer too 2390Sstevel@tonic-gate */ 2400Sstevel@tonic-gate ctlp = &trap_trace_ctl[CPU->cpu_id]; 2410Sstevel@tonic-gate ctlp->d.vaddr_base = trap_tr0; 2420Sstevel@tonic-gate ctlp->d.offset = ctlp->d.last_offset = 0; 2430Sstevel@tonic-gate ctlp->d.limit = TRAP_TSIZE; /* XXX dynamic someday */ 2440Sstevel@tonic-gate ctlp->d.paddr_base = va_to_pa(trap_tr0); 2451077Ssvemuri #endif /* TRAPTRACE */ 246*1991Sheppo 247*1991Sheppo /* 248*1991Sheppo * Initialize the Machine Description kernel framework 249*1991Sheppo */ 250*1991Sheppo 251*1991Sheppo mach_descrip_startup_init(); 252*1991Sheppo 2530Sstevel@tonic-gate /* 2540Sstevel@tonic-gate * initialize HV trap trace buffer for the boot cpu 2550Sstevel@tonic-gate */ 2561077Ssvemuri mach_htraptrace_setup(CPU->cpu_id); 2571077Ssvemuri mach_htraptrace_configure(CPU->cpu_id); 2580Sstevel@tonic-gate 2590Sstevel@tonic-gate /* 2600Sstevel@tonic-gate * lgroup framework initialization. This must be done prior 2610Sstevel@tonic-gate * to devices being mapped. 2620Sstevel@tonic-gate */ 2630Sstevel@tonic-gate lgrp_init(); 2640Sstevel@tonic-gate 2650Sstevel@tonic-gate cpu_setup(); 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate if (boothowto & RB_HALT) { 2680Sstevel@tonic-gate prom_printf("unix: kernel halted by -h flag\n"); 2690Sstevel@tonic-gate prom_enter_mon(); 2700Sstevel@tonic-gate } 2710Sstevel@tonic-gate 2720Sstevel@tonic-gate setcputype(); 2730Sstevel@tonic-gate map_wellknown_devices(); 2740Sstevel@tonic-gate setcpudelay(); 2750Sstevel@tonic-gate 2760Sstevel@tonic-gate /* 2770Sstevel@tonic-gate * Associate the boot cpu with a physical processor. 2780Sstevel@tonic-gate * This needs to be done after devices are mapped, since 2790Sstevel@tonic-gate * we need to know what type of physical processor this is. 2800Sstevel@tonic-gate * (CMP for example) 2810Sstevel@tonic-gate */ 2820Sstevel@tonic-gate chip_cpu_init(CPU); 2830Sstevel@tonic-gate chip_cpu_assign(CPU); 2840Sstevel@tonic-gate } 2850Sstevel@tonic-gate 2860Sstevel@tonic-gate /* 2870Sstevel@tonic-gate * These routines are called immediately before and 2880Sstevel@tonic-gate * immediately after calling into the firmware. The 2890Sstevel@tonic-gate * firmware is significantly confused by preemption - 2900Sstevel@tonic-gate * particularly on MP machines - but also on UP's too. 2910Sstevel@tonic-gate */ 2920Sstevel@tonic-gate 2930Sstevel@tonic-gate static int saved_spl; 2940Sstevel@tonic-gate 2950Sstevel@tonic-gate static void 2960Sstevel@tonic-gate kern_splr_preprom(void) 2970Sstevel@tonic-gate { 2980Sstevel@tonic-gate saved_spl = spl7(); 2990Sstevel@tonic-gate } 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate static void 3020Sstevel@tonic-gate kern_splx_postprom(void) 3030Sstevel@tonic-gate { 3040Sstevel@tonic-gate splx(saved_spl); 3050Sstevel@tonic-gate } 306