xref: /onnv-gate/usr/src/uts/sun4/os/mlsetup.c (revision 3434)
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 /*
22*3434Sesaxe  * Copyright 2007 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 */
59*3434Sesaxe #include <sys/pg.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);
741991Sheppo extern void mach_descrip_startup_init(void);
753266Sjb145095 extern void mach_soft_state_init(void);
760Sstevel@tonic-gate 
770Sstevel@tonic-gate int	dcache_size;
780Sstevel@tonic-gate int	dcache_linesize;
790Sstevel@tonic-gate int	icache_size;
800Sstevel@tonic-gate int	icache_linesize;
810Sstevel@tonic-gate int	ecache_size;
820Sstevel@tonic-gate int	ecache_alignsize;
830Sstevel@tonic-gate int	ecache_associativity;
840Sstevel@tonic-gate int	ecache_setsize;			/* max possible e$ setsize */
850Sstevel@tonic-gate int	cpu_setsize;			/* max e$ setsize of configured cpus */
860Sstevel@tonic-gate int	dcache_line_mask;		/* spitfire only */
870Sstevel@tonic-gate int	vac_size;			/* cache size in bytes */
880Sstevel@tonic-gate uint_t	vac_mask;			/* VAC alignment consistency mask */
890Sstevel@tonic-gate int	vac_shift;			/* log2(vac_size) for ppmapout() */
900Sstevel@tonic-gate int	vac = 0;	/* virtual address cache type (none == 0) */
910Sstevel@tonic-gate 
920Sstevel@tonic-gate /*
930Sstevel@tonic-gate  * fpRAS.  An individual sun4* machine class (or perhaps subclass,
940Sstevel@tonic-gate  * eg sun4u/cheetah) must set fpras_implemented to indicate that it implements
950Sstevel@tonic-gate  * the fpRAS feature.  The feature can be suppressed by setting fpras_disable
960Sstevel@tonic-gate  * or the mechanism can be disabled for individual copy operations with
970Sstevel@tonic-gate  * fpras_disableids.  All these are checked in post_startup() code so
980Sstevel@tonic-gate  * fpras_disable and fpras_disableids can be set in /etc/system.
990Sstevel@tonic-gate  * If/when fpRAS is implemented on non-sun4 architectures these
1000Sstevel@tonic-gate  * definitions will need to move up to the common level.
1010Sstevel@tonic-gate  */
1020Sstevel@tonic-gate int	fpras_implemented;
1030Sstevel@tonic-gate int	fpras_disable;
1040Sstevel@tonic-gate int	fpras_disableids;
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate /*
1070Sstevel@tonic-gate  * Static Routines:
1080Sstevel@tonic-gate  */
1090Sstevel@tonic-gate static void kern_splr_preprom(void);
1100Sstevel@tonic-gate static void kern_splx_postprom(void);
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate /*
1130Sstevel@tonic-gate  * Setup routine called right before main(). Interposing this function
1140Sstevel@tonic-gate  * before main() allows us to call it in a machine-independent fashion.
1150Sstevel@tonic-gate  */
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate void
1180Sstevel@tonic-gate mlsetup(struct regs *rp, void *cif, kfpu_t *fp)
1190Sstevel@tonic-gate {
1200Sstevel@tonic-gate 	struct machpcb *mpcb;
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate 	extern char t0stack[];
1230Sstevel@tonic-gate 	extern struct classfuncs sys_classfuncs;
1240Sstevel@tonic-gate 	extern disp_t cpu0_disp;
1250Sstevel@tonic-gate 	unsigned long long pa;
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate #ifdef TRAPTRACE
1280Sstevel@tonic-gate 	TRAP_TRACE_CTL *ctlp;
1290Sstevel@tonic-gate #endif /* TRAPTRACE */
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 	/*
1320Sstevel@tonic-gate 	 * initialize cpu_self
1330Sstevel@tonic-gate 	 */
1340Sstevel@tonic-gate 	cpu0.cpu_self = &cpu0;
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 	/*
1370Sstevel@tonic-gate 	 * initialize t0
1380Sstevel@tonic-gate 	 */
1390Sstevel@tonic-gate 	t0.t_stk = (caddr_t)rp - REGOFF;
1400Sstevel@tonic-gate 	/* Can't use va_to_pa here - wait until prom_ initialized */
1410Sstevel@tonic-gate 	t0.t_stkbase = t0stack;
1420Sstevel@tonic-gate 	t0.t_pri = maxclsyspri - 3;
1430Sstevel@tonic-gate 	t0.t_schedflag = TS_LOAD | TS_DONT_SWAP;
1440Sstevel@tonic-gate 	t0.t_procp = &p0;
1450Sstevel@tonic-gate 	t0.t_plockp = &p0lock.pl_lock;
1460Sstevel@tonic-gate 	t0.t_lwp = &lwp0;
1470Sstevel@tonic-gate 	t0.t_forw = &t0;
1480Sstevel@tonic-gate 	t0.t_back = &t0;
1490Sstevel@tonic-gate 	t0.t_next = &t0;
1500Sstevel@tonic-gate 	t0.t_prev = &t0;
1510Sstevel@tonic-gate 	t0.t_cpu = &cpu0;			/* loaded by _start */
1520Sstevel@tonic-gate 	t0.t_disp_queue = &cpu0_disp;
1530Sstevel@tonic-gate 	t0.t_bind_cpu = PBIND_NONE;
1540Sstevel@tonic-gate 	t0.t_bind_pset = PS_NONE;
1550Sstevel@tonic-gate 	t0.t_cpupart = &cp_default;
1560Sstevel@tonic-gate 	t0.t_clfuncs = &sys_classfuncs.thread;
1570Sstevel@tonic-gate 	t0.t_copyops = NULL;
1580Sstevel@tonic-gate 	THREAD_ONPROC(&t0, CPU);
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate 	lwp0.lwp_thread = &t0;
1610Sstevel@tonic-gate 	lwp0.lwp_procp = &p0;
1620Sstevel@tonic-gate 	lwp0.lwp_regs = (void *)rp;
1630Sstevel@tonic-gate 	t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1;
1640Sstevel@tonic-gate 
1650Sstevel@tonic-gate 	mpcb = lwptompcb(&lwp0);
1660Sstevel@tonic-gate 	mpcb->mpcb_fpu = fp;
1670Sstevel@tonic-gate 	mpcb->mpcb_fpu->fpu_q = mpcb->mpcb_fpu_q;
1680Sstevel@tonic-gate 	mpcb->mpcb_thread = &t0;
1690Sstevel@tonic-gate 	lwp0.lwp_fpu = (void *)mpcb->mpcb_fpu;
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 	p0.p_exec = NULL;
1720Sstevel@tonic-gate 	p0.p_stat = SRUN;
1730Sstevel@tonic-gate 	p0.p_flag = SSYS;
1740Sstevel@tonic-gate 	p0.p_tlist = &t0;
1750Sstevel@tonic-gate 	p0.p_stksize = 2*PAGESIZE;
1760Sstevel@tonic-gate 	p0.p_stkpageszc = 0;
1770Sstevel@tonic-gate 	p0.p_as = &kas;
1780Sstevel@tonic-gate 	p0.p_lockp = &p0lock;
1790Sstevel@tonic-gate 	p0.p_utraps = NULL;
1800Sstevel@tonic-gate 	p0.p_brkpageszc = 0;
1810Sstevel@tonic-gate 	sigorset(&p0.p_ignore, &ignoredefault);
1820Sstevel@tonic-gate 
1830Sstevel@tonic-gate 	CPU->cpu_thread = &t0;
1840Sstevel@tonic-gate 	CPU->cpu_dispthread = &t0;
1850Sstevel@tonic-gate 	bzero(&cpu0_disp, sizeof (disp_t));
1860Sstevel@tonic-gate 	CPU->cpu_disp = &cpu0_disp;
1870Sstevel@tonic-gate 	CPU->cpu_disp->disp_cpu = CPU;
1880Sstevel@tonic-gate 	CPU->cpu_idle_thread = &t0;
1890Sstevel@tonic-gate 	CPU->cpu_flags = CPU_RUNNING;
1900Sstevel@tonic-gate 	CPU->cpu_id = getprocessorid();
1910Sstevel@tonic-gate 	CPU->cpu_dispatch_pri = t0.t_pri;
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate 	/*
1940Sstevel@tonic-gate 	 * Initialize thread/cpu microstate accounting here
1950Sstevel@tonic-gate 	 */
1960Sstevel@tonic-gate 	init_mstate(&t0, LMS_SYSTEM);
1970Sstevel@tonic-gate 	init_cpu_mstate(CPU, CMS_SYSTEM);
1980Sstevel@tonic-gate 
1990Sstevel@tonic-gate 	/*
2000Sstevel@tonic-gate 	 * Initialize lists of available and active CPUs.
2010Sstevel@tonic-gate 	 */
2020Sstevel@tonic-gate 	cpu_list_init(CPU);
2030Sstevel@tonic-gate 
204414Skchow 	cpu_vm_data_init(CPU);
205414Skchow 
2060Sstevel@tonic-gate 	prom_init("kernel", cif);
2070Sstevel@tonic-gate 	(void) prom_set_preprom(kern_splr_preprom);
2080Sstevel@tonic-gate 	(void) prom_set_postprom(kern_splx_postprom);
2090Sstevel@tonic-gate 
2100Sstevel@tonic-gate 	PRM_INFO("mlsetup: now ok to call prom_printf");
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate 	mpcb->mpcb_pa = va_to_pa(t0.t_stk);
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate 	/*
2150Sstevel@tonic-gate 	 * Claim the physical and virtual resources used by panicbuf,
2160Sstevel@tonic-gate 	 * then map panicbuf.  This operation removes the phys and
2170Sstevel@tonic-gate 	 * virtual addresses from the free lists.
2180Sstevel@tonic-gate 	 */
2190Sstevel@tonic-gate 	if (prom_claim_virt(PANICBUFSIZE, panicbuf) != panicbuf)
2200Sstevel@tonic-gate 		prom_panic("Can't claim panicbuf virtual address");
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 	if (prom_retain("panicbuf", PANICBUFSIZE, MMU_PAGESIZE, &pa) != 0)
2230Sstevel@tonic-gate 		prom_panic("Can't allocate retained panicbuf physical address");
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate 	if (prom_map_phys(-1, PANICBUFSIZE, panicbuf, pa) != 0)
2260Sstevel@tonic-gate 		prom_panic("Can't map panicbuf");
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 	PRM_DEBUG(panicbuf);
2290Sstevel@tonic-gate 	PRM_DEBUG(pa);
2300Sstevel@tonic-gate 
2311592Sgirish 	/*
2321592Sgirish 	 * Negotiate hypervisor services, if any
2331592Sgirish 	 */
2341592Sgirish 	hsvc_setup();
2353266Sjb145095 	mach_soft_state_init();
2361592Sgirish 
2370Sstevel@tonic-gate #ifdef TRAPTRACE
2380Sstevel@tonic-gate 	/*
2390Sstevel@tonic-gate 	 * initialize the trap trace buffer for the boot cpu
2400Sstevel@tonic-gate 	 * XXX todo, dynamically allocate this buffer too
2410Sstevel@tonic-gate 	 */
2420Sstevel@tonic-gate 	ctlp = &trap_trace_ctl[CPU->cpu_id];
2430Sstevel@tonic-gate 	ctlp->d.vaddr_base = trap_tr0;
2440Sstevel@tonic-gate 	ctlp->d.offset = ctlp->d.last_offset = 0;
2450Sstevel@tonic-gate 	ctlp->d.limit = TRAP_TSIZE;		/* XXX dynamic someday */
2460Sstevel@tonic-gate 	ctlp->d.paddr_base = va_to_pa(trap_tr0);
2471077Ssvemuri #endif /* TRAPTRACE */
2481991Sheppo 
2491991Sheppo 	/*
2501991Sheppo 	 * Initialize the Machine Description kernel framework
2511991Sheppo 	 */
2521991Sheppo 
2531991Sheppo 	mach_descrip_startup_init();
2541991Sheppo 
2550Sstevel@tonic-gate 	/*
2560Sstevel@tonic-gate 	 * initialize HV trap trace buffer for the boot cpu
2570Sstevel@tonic-gate 	 */
2581077Ssvemuri 	mach_htraptrace_setup(CPU->cpu_id);
2591077Ssvemuri 	mach_htraptrace_configure(CPU->cpu_id);
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate 	/*
2620Sstevel@tonic-gate 	 * lgroup framework initialization. This must be done prior
2630Sstevel@tonic-gate 	 * to devices being mapped.
2640Sstevel@tonic-gate 	 */
2650Sstevel@tonic-gate 	lgrp_init();
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 	cpu_setup();
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate 	if (boothowto & RB_HALT) {
2700Sstevel@tonic-gate 		prom_printf("unix: kernel halted by -h flag\n");
2710Sstevel@tonic-gate 		prom_enter_mon();
2720Sstevel@tonic-gate 	}
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate 	setcputype();
2750Sstevel@tonic-gate 	map_wellknown_devices();
2760Sstevel@tonic-gate 	setcpudelay();
2770Sstevel@tonic-gate }
2780Sstevel@tonic-gate 
2790Sstevel@tonic-gate /*
2800Sstevel@tonic-gate  * These routines are called immediately before and
2810Sstevel@tonic-gate  * immediately after calling into the firmware.  The
2820Sstevel@tonic-gate  * firmware is significantly confused by preemption -
2830Sstevel@tonic-gate  * particularly on MP machines - but also on UP's too.
2840Sstevel@tonic-gate  */
2850Sstevel@tonic-gate 
2860Sstevel@tonic-gate static int saved_spl;
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate static void
2890Sstevel@tonic-gate kern_splr_preprom(void)
2900Sstevel@tonic-gate {
2910Sstevel@tonic-gate 	saved_spl = spl7();
2920Sstevel@tonic-gate }
2930Sstevel@tonic-gate 
2940Sstevel@tonic-gate static void
2950Sstevel@tonic-gate kern_splx_postprom(void)
2960Sstevel@tonic-gate {
2970Sstevel@tonic-gate 	splx(saved_spl);
2980Sstevel@tonic-gate }
299