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