xref: /titanic_44/usr/src/uts/sun4/os/mlsetup.c (revision c56c1e58d46678af913f4c68f2ef9dcacb5f282f)
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
5*c56c1e58Sgirish  * Common Development and Distribution License (the "License").
6*c56c1e58Sgirish  * 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 /*
22*c56c1e58Sgirish  * 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);
73*c56c1e58Sgirish extern void hsvc_setup(void);
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate int	dcache_size;
767c478bd9Sstevel@tonic-gate int	dcache_linesize;
777c478bd9Sstevel@tonic-gate int	icache_size;
787c478bd9Sstevel@tonic-gate int	icache_linesize;
797c478bd9Sstevel@tonic-gate int	ecache_size;
807c478bd9Sstevel@tonic-gate int	ecache_alignsize;
817c478bd9Sstevel@tonic-gate int	ecache_associativity;
827c478bd9Sstevel@tonic-gate int	ecache_setsize;			/* max possible e$ setsize */
837c478bd9Sstevel@tonic-gate int	cpu_setsize;			/* max e$ setsize of configured cpus */
847c478bd9Sstevel@tonic-gate int	dcache_line_mask;		/* spitfire only */
857c478bd9Sstevel@tonic-gate int	vac_size;			/* cache size in bytes */
867c478bd9Sstevel@tonic-gate uint_t	vac_mask;			/* VAC alignment consistency mask */
877c478bd9Sstevel@tonic-gate int	vac_shift;			/* log2(vac_size) for ppmapout() */
887c478bd9Sstevel@tonic-gate int	vac = 0;	/* virtual address cache type (none == 0) */
897c478bd9Sstevel@tonic-gate 
907c478bd9Sstevel@tonic-gate /*
917c478bd9Sstevel@tonic-gate  * fpRAS.  An individual sun4* machine class (or perhaps subclass,
927c478bd9Sstevel@tonic-gate  * eg sun4u/cheetah) must set fpras_implemented to indicate that it implements
937c478bd9Sstevel@tonic-gate  * the fpRAS feature.  The feature can be suppressed by setting fpras_disable
947c478bd9Sstevel@tonic-gate  * or the mechanism can be disabled for individual copy operations with
957c478bd9Sstevel@tonic-gate  * fpras_disableids.  All these are checked in post_startup() code so
967c478bd9Sstevel@tonic-gate  * fpras_disable and fpras_disableids can be set in /etc/system.
977c478bd9Sstevel@tonic-gate  * If/when fpRAS is implemented on non-sun4 architectures these
987c478bd9Sstevel@tonic-gate  * definitions will need to move up to the common level.
997c478bd9Sstevel@tonic-gate  */
1007c478bd9Sstevel@tonic-gate int	fpras_implemented;
1017c478bd9Sstevel@tonic-gate int	fpras_disable;
1027c478bd9Sstevel@tonic-gate int	fpras_disableids;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /*
1057c478bd9Sstevel@tonic-gate  * Static Routines:
1067c478bd9Sstevel@tonic-gate  */
1077c478bd9Sstevel@tonic-gate static void kern_splr_preprom(void);
1087c478bd9Sstevel@tonic-gate static void kern_splx_postprom(void);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate /*
1117c478bd9Sstevel@tonic-gate  * Setup routine called right before main(). Interposing this function
1127c478bd9Sstevel@tonic-gate  * before main() allows us to call it in a machine-independent fashion.
1137c478bd9Sstevel@tonic-gate  */
1147c478bd9Sstevel@tonic-gate 
1157c478bd9Sstevel@tonic-gate void
1167c478bd9Sstevel@tonic-gate mlsetup(struct regs *rp, void *cif, kfpu_t *fp)
1177c478bd9Sstevel@tonic-gate {
1187c478bd9Sstevel@tonic-gate 	struct machpcb *mpcb;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	extern char t0stack[];
1217c478bd9Sstevel@tonic-gate 	extern struct classfuncs sys_classfuncs;
1227c478bd9Sstevel@tonic-gate 	extern disp_t cpu0_disp;
1237c478bd9Sstevel@tonic-gate 	unsigned long long pa;
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
1267c478bd9Sstevel@tonic-gate 	TRAP_TRACE_CTL *ctlp;
1277c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate 	/*
1307c478bd9Sstevel@tonic-gate 	 * initialize cpu_self
1317c478bd9Sstevel@tonic-gate 	 */
1327c478bd9Sstevel@tonic-gate 	cpu0.cpu_self = &cpu0;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	/*
1357c478bd9Sstevel@tonic-gate 	 * initialize t0
1367c478bd9Sstevel@tonic-gate 	 */
1377c478bd9Sstevel@tonic-gate 	t0.t_stk = (caddr_t)rp - REGOFF;
1387c478bd9Sstevel@tonic-gate 	/* Can't use va_to_pa here - wait until prom_ initialized */
1397c478bd9Sstevel@tonic-gate 	t0.t_stkbase = t0stack;
1407c478bd9Sstevel@tonic-gate 	t0.t_pri = maxclsyspri - 3;
1417c478bd9Sstevel@tonic-gate 	t0.t_schedflag = TS_LOAD | TS_DONT_SWAP;
1427c478bd9Sstevel@tonic-gate 	t0.t_procp = &p0;
1437c478bd9Sstevel@tonic-gate 	t0.t_plockp = &p0lock.pl_lock;
1447c478bd9Sstevel@tonic-gate 	t0.t_lwp = &lwp0;
1457c478bd9Sstevel@tonic-gate 	t0.t_forw = &t0;
1467c478bd9Sstevel@tonic-gate 	t0.t_back = &t0;
1477c478bd9Sstevel@tonic-gate 	t0.t_next = &t0;
1487c478bd9Sstevel@tonic-gate 	t0.t_prev = &t0;
1497c478bd9Sstevel@tonic-gate 	t0.t_cpu = &cpu0;			/* loaded by _start */
1507c478bd9Sstevel@tonic-gate 	t0.t_disp_queue = &cpu0_disp;
1517c478bd9Sstevel@tonic-gate 	t0.t_bind_cpu = PBIND_NONE;
1527c478bd9Sstevel@tonic-gate 	t0.t_bind_pset = PS_NONE;
1537c478bd9Sstevel@tonic-gate 	t0.t_cpupart = &cp_default;
1547c478bd9Sstevel@tonic-gate 	t0.t_clfuncs = &sys_classfuncs.thread;
1557c478bd9Sstevel@tonic-gate 	t0.t_copyops = NULL;
1567c478bd9Sstevel@tonic-gate 	THREAD_ONPROC(&t0, CPU);
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate 	lwp0.lwp_thread = &t0;
1597c478bd9Sstevel@tonic-gate 	lwp0.lwp_procp = &p0;
1607c478bd9Sstevel@tonic-gate 	lwp0.lwp_regs = (void *)rp;
1617c478bd9Sstevel@tonic-gate 	t0.t_tid = p0.p_lwpcnt = p0.p_lwprcnt = p0.p_lwpid = 1;
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 	mpcb = lwptompcb(&lwp0);
1647c478bd9Sstevel@tonic-gate 	mpcb->mpcb_fpu = fp;
1657c478bd9Sstevel@tonic-gate 	mpcb->mpcb_fpu->fpu_q = mpcb->mpcb_fpu_q;
1667c478bd9Sstevel@tonic-gate 	mpcb->mpcb_thread = &t0;
1677c478bd9Sstevel@tonic-gate 	lwp0.lwp_fpu = (void *)mpcb->mpcb_fpu;
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 	p0.p_exec = NULL;
1707c478bd9Sstevel@tonic-gate 	p0.p_stat = SRUN;
1717c478bd9Sstevel@tonic-gate 	p0.p_flag = SSYS;
1727c478bd9Sstevel@tonic-gate 	p0.p_tlist = &t0;
1737c478bd9Sstevel@tonic-gate 	p0.p_stksize = 2*PAGESIZE;
1747c478bd9Sstevel@tonic-gate 	p0.p_stkpageszc = 0;
1757c478bd9Sstevel@tonic-gate 	p0.p_as = &kas;
1767c478bd9Sstevel@tonic-gate 	p0.p_lockp = &p0lock;
1777c478bd9Sstevel@tonic-gate 	p0.p_utraps = NULL;
1787c478bd9Sstevel@tonic-gate 	p0.p_brkpageszc = 0;
1797c478bd9Sstevel@tonic-gate 	sigorset(&p0.p_ignore, &ignoredefault);
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	CPU->cpu_thread = &t0;
1827c478bd9Sstevel@tonic-gate 	CPU->cpu_dispthread = &t0;
1837c478bd9Sstevel@tonic-gate 	bzero(&cpu0_disp, sizeof (disp_t));
1847c478bd9Sstevel@tonic-gate 	CPU->cpu_disp = &cpu0_disp;
1857c478bd9Sstevel@tonic-gate 	CPU->cpu_disp->disp_cpu = CPU;
1867c478bd9Sstevel@tonic-gate 	CPU->cpu_idle_thread = &t0;
1877c478bd9Sstevel@tonic-gate 	CPU->cpu_flags = CPU_RUNNING;
1887c478bd9Sstevel@tonic-gate 	CPU->cpu_id = getprocessorid();
1897c478bd9Sstevel@tonic-gate 	CPU->cpu_dispatch_pri = t0.t_pri;
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	/*
1927c478bd9Sstevel@tonic-gate 	 * Initialize thread/cpu microstate accounting here
1937c478bd9Sstevel@tonic-gate 	 */
1947c478bd9Sstevel@tonic-gate 	init_mstate(&t0, LMS_SYSTEM);
1957c478bd9Sstevel@tonic-gate 	init_cpu_mstate(CPU, CMS_SYSTEM);
1967c478bd9Sstevel@tonic-gate 
1977c478bd9Sstevel@tonic-gate 	/*
1987c478bd9Sstevel@tonic-gate 	 * Initialize lists of available and active CPUs.
1997c478bd9Sstevel@tonic-gate 	 */
2007c478bd9Sstevel@tonic-gate 	cpu_list_init(CPU);
2017c478bd9Sstevel@tonic-gate 
202affbd3ccSkchow 	cpu_vm_data_init(CPU);
203affbd3ccSkchow 
2047c478bd9Sstevel@tonic-gate 	prom_init("kernel", cif);
2057c478bd9Sstevel@tonic-gate 	(void) prom_set_preprom(kern_splr_preprom);
2067c478bd9Sstevel@tonic-gate 	(void) prom_set_postprom(kern_splx_postprom);
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate 	PRM_INFO("mlsetup: now ok to call prom_printf");
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	mpcb->mpcb_pa = va_to_pa(t0.t_stk);
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	/*
2137c478bd9Sstevel@tonic-gate 	 * Claim the physical and virtual resources used by panicbuf,
2147c478bd9Sstevel@tonic-gate 	 * then map panicbuf.  This operation removes the phys and
2157c478bd9Sstevel@tonic-gate 	 * virtual addresses from the free lists.
2167c478bd9Sstevel@tonic-gate 	 */
2177c478bd9Sstevel@tonic-gate 	if (prom_claim_virt(PANICBUFSIZE, panicbuf) != panicbuf)
2187c478bd9Sstevel@tonic-gate 		prom_panic("Can't claim panicbuf virtual address");
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	if (prom_retain("panicbuf", PANICBUFSIZE, MMU_PAGESIZE, &pa) != 0)
2217c478bd9Sstevel@tonic-gate 		prom_panic("Can't allocate retained panicbuf physical address");
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 	if (prom_map_phys(-1, PANICBUFSIZE, panicbuf, pa) != 0)
2247c478bd9Sstevel@tonic-gate 		prom_panic("Can't map panicbuf");
2257c478bd9Sstevel@tonic-gate 
2267c478bd9Sstevel@tonic-gate 	PRM_DEBUG(panicbuf);
2277c478bd9Sstevel@tonic-gate 	PRM_DEBUG(pa);
2287c478bd9Sstevel@tonic-gate 
229*c56c1e58Sgirish 	/*
230*c56c1e58Sgirish 	 * Negotiate hypervisor services, if any
231*c56c1e58Sgirish 	 */
232*c56c1e58Sgirish 	hsvc_setup();
233*c56c1e58Sgirish 
2347c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
2357c478bd9Sstevel@tonic-gate 	/*
2367c478bd9Sstevel@tonic-gate 	 * initialize the trap trace buffer for the boot cpu
2377c478bd9Sstevel@tonic-gate 	 * XXX todo, dynamically allocate this buffer too
2387c478bd9Sstevel@tonic-gate 	 */
2397c478bd9Sstevel@tonic-gate 	ctlp = &trap_trace_ctl[CPU->cpu_id];
2407c478bd9Sstevel@tonic-gate 	ctlp->d.vaddr_base = trap_tr0;
2417c478bd9Sstevel@tonic-gate 	ctlp->d.offset = ctlp->d.last_offset = 0;
2427c478bd9Sstevel@tonic-gate 	ctlp->d.limit = TRAP_TSIZE;		/* XXX dynamic someday */
2437c478bd9Sstevel@tonic-gate 	ctlp->d.paddr_base = va_to_pa(trap_tr0);
244db6d2ee3Ssvemuri #endif /* TRAPTRACE */
2457c478bd9Sstevel@tonic-gate 	/*
2467c478bd9Sstevel@tonic-gate 	 * initialize HV trap trace buffer for the boot cpu
2477c478bd9Sstevel@tonic-gate 	 */
248db6d2ee3Ssvemuri 	mach_htraptrace_setup(CPU->cpu_id);
249db6d2ee3Ssvemuri 	mach_htraptrace_configure(CPU->cpu_id);
2507c478bd9Sstevel@tonic-gate 
2517c478bd9Sstevel@tonic-gate 	/*
2527c478bd9Sstevel@tonic-gate 	 * lgroup framework initialization. This must be done prior
2537c478bd9Sstevel@tonic-gate 	 * to devices being mapped.
2547c478bd9Sstevel@tonic-gate 	 */
2557c478bd9Sstevel@tonic-gate 	lgrp_init();
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	cpu_setup();
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	if (boothowto & RB_HALT) {
2607c478bd9Sstevel@tonic-gate 		prom_printf("unix: kernel halted by -h flag\n");
2617c478bd9Sstevel@tonic-gate 		prom_enter_mon();
2627c478bd9Sstevel@tonic-gate 	}
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate 	setcputype();
2657c478bd9Sstevel@tonic-gate 	map_wellknown_devices();
2667c478bd9Sstevel@tonic-gate 	setcpudelay();
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 	/*
2697c478bd9Sstevel@tonic-gate 	 * Associate the boot cpu with a physical processor.
2707c478bd9Sstevel@tonic-gate 	 * This needs to be done after devices are mapped, since
2717c478bd9Sstevel@tonic-gate 	 * we need to know what type of physical processor this is.
2727c478bd9Sstevel@tonic-gate 	 * (CMP for example)
2737c478bd9Sstevel@tonic-gate 	 */
2747c478bd9Sstevel@tonic-gate 	chip_cpu_init(CPU);
2757c478bd9Sstevel@tonic-gate 	chip_cpu_assign(CPU);
2767c478bd9Sstevel@tonic-gate }
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate /*
2797c478bd9Sstevel@tonic-gate  * These routines are called immediately before and
2807c478bd9Sstevel@tonic-gate  * immediately after calling into the firmware.  The
2817c478bd9Sstevel@tonic-gate  * firmware is significantly confused by preemption -
2827c478bd9Sstevel@tonic-gate  * particularly on MP machines - but also on UP's too.
2837c478bd9Sstevel@tonic-gate  */
2847c478bd9Sstevel@tonic-gate 
2857c478bd9Sstevel@tonic-gate static int saved_spl;
2867c478bd9Sstevel@tonic-gate 
2877c478bd9Sstevel@tonic-gate static void
2887c478bd9Sstevel@tonic-gate kern_splr_preprom(void)
2897c478bd9Sstevel@tonic-gate {
2907c478bd9Sstevel@tonic-gate 	saved_spl = spl7();
2917c478bd9Sstevel@tonic-gate }
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate static void
2947c478bd9Sstevel@tonic-gate kern_splx_postprom(void)
2957c478bd9Sstevel@tonic-gate {
2967c478bd9Sstevel@tonic-gate 	splx(saved_spl);
2977c478bd9Sstevel@tonic-gate }
298