xref: /titanic_51/usr/src/uts/sun4/os/startup.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate  * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate  *
4*7c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate  * with the License.
8*7c478bd9Sstevel@tonic-gate  *
9*7c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate  * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate  *
14*7c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate  *
20*7c478bd9Sstevel@tonic-gate  * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate  */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24*7c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate  */
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
28*7c478bd9Sstevel@tonic-gate 
29*7c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/vm.h>
32*7c478bd9Sstevel@tonic-gate #include <sys/cpu.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/atomic.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/reboot.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/kdi.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/memlist_plat.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/memlist_impl.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h>
40*7c478bd9Sstevel@tonic-gate #include <sys/prom_isa.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/intreg.h>
43*7c478bd9Sstevel@tonic-gate #include <sys/ivintr.h>
44*7c478bd9Sstevel@tonic-gate #include <sys/fpu/fpusystm.h>
45*7c478bd9Sstevel@tonic-gate #include <sys/iommutsb.h>
46*7c478bd9Sstevel@tonic-gate #include <vm/vm_dep.h>
47*7c478bd9Sstevel@tonic-gate #include <vm/seg_dev.h>
48*7c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h>
49*7c478bd9Sstevel@tonic-gate #include <vm/seg_kpm.h>
50*7c478bd9Sstevel@tonic-gate #include <vm/seg_map.h>
51*7c478bd9Sstevel@tonic-gate #include <vm/seg_kp.h>
52*7c478bd9Sstevel@tonic-gate #include <sys/sysconf.h>
53*7c478bd9Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
54*7c478bd9Sstevel@tonic-gate #include <sys/kobj.h>
55*7c478bd9Sstevel@tonic-gate #include <sys/sun4asi.h>
56*7c478bd9Sstevel@tonic-gate #include <sys/clconf.h>
57*7c478bd9Sstevel@tonic-gate #include <sys/platform_module.h>
58*7c478bd9Sstevel@tonic-gate #include <sys/panic.h>
59*7c478bd9Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h>
60*7c478bd9Sstevel@tonic-gate #include <sys/clock.h>
61*7c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
62*7c478bd9Sstevel@tonic-gate #include <sys/promif.h>
63*7c478bd9Sstevel@tonic-gate #include <sys/prom_debug.h>
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate #ifdef TRAPTRACE
66*7c478bd9Sstevel@tonic-gate #include <sys/traptrace.h>
67*7c478bd9Sstevel@tonic-gate #endif /* TRAPTRACE */
68*7c478bd9Sstevel@tonic-gate 
69*7c478bd9Sstevel@tonic-gate #include <sys/memnode.h>
70*7c478bd9Sstevel@tonic-gate #include <sys/mem_cage.h>
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate extern void setup_trap_table(void);
74*7c478bd9Sstevel@tonic-gate extern void cpu_intrq_setup(struct cpu *);
75*7c478bd9Sstevel@tonic-gate extern void cpu_intrq_register(struct cpu *);
76*7c478bd9Sstevel@tonic-gate extern void contig_mem_init(void);
77*7c478bd9Sstevel@tonic-gate extern void mach_dump_buffer_init(void);
78*7c478bd9Sstevel@tonic-gate extern void mach_descrip_init(void);
79*7c478bd9Sstevel@tonic-gate extern void mach_memscrub(void);
80*7c478bd9Sstevel@tonic-gate extern void mach_fpras(void);
81*7c478bd9Sstevel@tonic-gate extern void mach_cpu_halt_idle(void);
82*7c478bd9Sstevel@tonic-gate extern void mach_hw_copy_limit(void);
83*7c478bd9Sstevel@tonic-gate extern void load_tod_module(void);
84*7c478bd9Sstevel@tonic-gate #pragma weak load_tod_module
85*7c478bd9Sstevel@tonic-gate 
86*7c478bd9Sstevel@tonic-gate extern int ndata_alloc_mmfsa(struct memlist *ndata);
87*7c478bd9Sstevel@tonic-gate #pragma weak ndata_alloc_mmfsa
88*7c478bd9Sstevel@tonic-gate 
89*7c478bd9Sstevel@tonic-gate extern void parse_idprom(void);
90*7c478bd9Sstevel@tonic-gate extern void add_vx_handler(char *, int, void (*)(cell_t *));
91*7c478bd9Sstevel@tonic-gate extern void mem_config_init(void);
92*7c478bd9Sstevel@tonic-gate extern void memseg_remap_init(void);
93*7c478bd9Sstevel@tonic-gate 
94*7c478bd9Sstevel@tonic-gate /*
95*7c478bd9Sstevel@tonic-gate  * External Data:
96*7c478bd9Sstevel@tonic-gate  */
97*7c478bd9Sstevel@tonic-gate extern int vac_size;	/* cache size in bytes */
98*7c478bd9Sstevel@tonic-gate extern uint_t vac_mask;	/* VAC alignment consistency mask */
99*7c478bd9Sstevel@tonic-gate extern uint_t vac_colors;
100*7c478bd9Sstevel@tonic-gate 
101*7c478bd9Sstevel@tonic-gate /*
102*7c478bd9Sstevel@tonic-gate  * Global Data Definitions:
103*7c478bd9Sstevel@tonic-gate  */
104*7c478bd9Sstevel@tonic-gate 
105*7c478bd9Sstevel@tonic-gate /*
106*7c478bd9Sstevel@tonic-gate  * XXX - Don't port this to new architectures
107*7c478bd9Sstevel@tonic-gate  * A 3rd party volume manager driver (vxdm) depends on the symbol romp.
108*7c478bd9Sstevel@tonic-gate  * 'romp' has no use with a prom with an IEEE 1275 client interface.
109*7c478bd9Sstevel@tonic-gate  * The driver doesn't use the value, but it depends on the symbol.
110*7c478bd9Sstevel@tonic-gate  */
111*7c478bd9Sstevel@tonic-gate void *romp;		/* veritas driver won't load without romp 4154976 */
112*7c478bd9Sstevel@tonic-gate /*
113*7c478bd9Sstevel@tonic-gate  * Declare these as initialized data so we can patch them.
114*7c478bd9Sstevel@tonic-gate  */
115*7c478bd9Sstevel@tonic-gate pgcnt_t physmem = 0;	/* memory size in pages, patch if you want less */
116*7c478bd9Sstevel@tonic-gate pgcnt_t segkpsize =
117*7c478bd9Sstevel@tonic-gate     btop(SEGKPDEFSIZE);	/* size of segkp segment in pages */
118*7c478bd9Sstevel@tonic-gate uint_t segmap_percent = 12; /* Size of segmap segment */
119*7c478bd9Sstevel@tonic-gate 
120*7c478bd9Sstevel@tonic-gate int use_cache = 1;		/* cache not reliable (605 bugs) with MP */
121*7c478bd9Sstevel@tonic-gate int vac_copyback = 1;
122*7c478bd9Sstevel@tonic-gate char *cache_mode = NULL;
123*7c478bd9Sstevel@tonic-gate int use_mix = 1;
124*7c478bd9Sstevel@tonic-gate int prom_debug = 0;
125*7c478bd9Sstevel@tonic-gate int usb_node_debug = 0;
126*7c478bd9Sstevel@tonic-gate 
127*7c478bd9Sstevel@tonic-gate struct bootops *bootops = 0;	/* passed in from boot in %o2 */
128*7c478bd9Sstevel@tonic-gate caddr_t boot_tba;		/* %tba at boot - used by kmdb */
129*7c478bd9Sstevel@tonic-gate uint_t	tba_taken_over = 0;
130*7c478bd9Sstevel@tonic-gate 
131*7c478bd9Sstevel@tonic-gate caddr_t s_text;			/* start of kernel text segment */
132*7c478bd9Sstevel@tonic-gate caddr_t e_text;			/* end of kernel text segment */
133*7c478bd9Sstevel@tonic-gate caddr_t s_data;			/* start of kernel data segment */
134*7c478bd9Sstevel@tonic-gate caddr_t e_data;			/* end of kernel data segment */
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate caddr_t modtext;		/* beginning of module text */
137*7c478bd9Sstevel@tonic-gate size_t	modtext_sz;		/* size of module text */
138*7c478bd9Sstevel@tonic-gate caddr_t moddata;		/* beginning of module data reserve */
139*7c478bd9Sstevel@tonic-gate caddr_t e_moddata;		/* end of module data reserve */
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate /*
142*7c478bd9Sstevel@tonic-gate  * End of first block of contiguous kernel in 32-bit virtual address space
143*7c478bd9Sstevel@tonic-gate  */
144*7c478bd9Sstevel@tonic-gate caddr_t		econtig32;	/* end of first blk of contiguous kernel */
145*7c478bd9Sstevel@tonic-gate 
146*7c478bd9Sstevel@tonic-gate caddr_t		ncbase;		/* beginning of non-cached segment */
147*7c478bd9Sstevel@tonic-gate caddr_t		ncend;		/* end of non-cached segment */
148*7c478bd9Sstevel@tonic-gate caddr_t		sdata;		/* beginning of data segment */
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate caddr_t		extra_etva;	/* beginning of unused nucleus text */
151*7c478bd9Sstevel@tonic-gate pgcnt_t		extra_etpg;	/* number of pages of unused nucleus text */
152*7c478bd9Sstevel@tonic-gate 
153*7c478bd9Sstevel@tonic-gate size_t	ndata_remain_sz;	/* bytes from end of data to 4MB boundary */
154*7c478bd9Sstevel@tonic-gate caddr_t	nalloc_base;		/* beginning of nucleus allocation */
155*7c478bd9Sstevel@tonic-gate caddr_t nalloc_end;		/* end of nucleus allocatable memory */
156*7c478bd9Sstevel@tonic-gate caddr_t valloc_base;		/* beginning of kvalloc segment	*/
157*7c478bd9Sstevel@tonic-gate 
158*7c478bd9Sstevel@tonic-gate caddr_t kmem64_base;		/* base of kernel mem segment in 64-bit space */
159*7c478bd9Sstevel@tonic-gate caddr_t kmem64_end;		/* end of kernel mem segment in 64-bit space */
160*7c478bd9Sstevel@tonic-gate 
161*7c478bd9Sstevel@tonic-gate uintptr_t shm_alignment = 0;	/* VAC address consistency modulus */
162*7c478bd9Sstevel@tonic-gate struct memlist *phys_install;	/* Total installed physical memory */
163*7c478bd9Sstevel@tonic-gate struct memlist *phys_avail;	/* Available (unreserved) physical memory */
164*7c478bd9Sstevel@tonic-gate struct memlist *virt_avail;	/* Available (unmapped?) virtual memory */
165*7c478bd9Sstevel@tonic-gate struct memlist ndata;		/* memlist of nucleus allocatable memory */
166*7c478bd9Sstevel@tonic-gate int memexp_flag;		/* memory expansion card flag */
167*7c478bd9Sstevel@tonic-gate uint64_t ecache_flushaddr;	/* physical address used for flushing E$ */
168*7c478bd9Sstevel@tonic-gate pgcnt_t obp_pages;		/* Physical pages used by OBP */
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate /*
171*7c478bd9Sstevel@tonic-gate  * VM data structures
172*7c478bd9Sstevel@tonic-gate  */
173*7c478bd9Sstevel@tonic-gate long page_hashsz;		/* Size of page hash table (power of two) */
174*7c478bd9Sstevel@tonic-gate struct page *pp_base;		/* Base of system page struct array */
175*7c478bd9Sstevel@tonic-gate size_t pp_sz;			/* Size in bytes of page struct array */
176*7c478bd9Sstevel@tonic-gate struct page **page_hash;	/* Page hash table */
177*7c478bd9Sstevel@tonic-gate struct seg ktextseg;		/* Segment used for kernel executable image */
178*7c478bd9Sstevel@tonic-gate struct seg kvalloc;		/* Segment used for "valloc" mapping */
179*7c478bd9Sstevel@tonic-gate struct seg kpseg;		/* Segment used for pageable kernel virt mem */
180*7c478bd9Sstevel@tonic-gate struct seg ktexthole;		/* Segment used for nucleus text hole */
181*7c478bd9Sstevel@tonic-gate struct seg kmapseg;		/* Segment used for generic kernel mappings */
182*7c478bd9Sstevel@tonic-gate struct seg kpmseg;		/* Segment used for physical mapping */
183*7c478bd9Sstevel@tonic-gate struct seg kdebugseg;		/* Segment used for the kernel debugger */
184*7c478bd9Sstevel@tonic-gate 
185*7c478bd9Sstevel@tonic-gate uintptr_t kpm_pp_base;		/* Base of system kpm_page array */
186*7c478bd9Sstevel@tonic-gate size_t	kpm_pp_sz;		/* Size of system kpm_page array */
187*7c478bd9Sstevel@tonic-gate pgcnt_t	kpm_npages;		/* How many kpm pages are managed */
188*7c478bd9Sstevel@tonic-gate 
189*7c478bd9Sstevel@tonic-gate struct seg *segkp = &kpseg;	/* Pageable kernel virtual memory segment */
190*7c478bd9Sstevel@tonic-gate struct seg *segkmap = &kmapseg;	/* Kernel generic mapping segment */
191*7c478bd9Sstevel@tonic-gate struct seg *segkpm = &kpmseg;	/* 64bit kernel physical mapping segment */
192*7c478bd9Sstevel@tonic-gate 
193*7c478bd9Sstevel@tonic-gate /*
194*7c478bd9Sstevel@tonic-gate  * debugger pages (if allocated)
195*7c478bd9Sstevel@tonic-gate  */
196*7c478bd9Sstevel@tonic-gate struct vnode kdebugvp;
197*7c478bd9Sstevel@tonic-gate 
198*7c478bd9Sstevel@tonic-gate /*
199*7c478bd9Sstevel@tonic-gate  * Segment for relocated kernel structures in 64-bit large RAM kernels
200*7c478bd9Sstevel@tonic-gate  */
201*7c478bd9Sstevel@tonic-gate struct seg kmem64;
202*7c478bd9Sstevel@tonic-gate 
203*7c478bd9Sstevel@tonic-gate struct memseg *memseg_base;
204*7c478bd9Sstevel@tonic-gate size_t memseg_sz;		/* Used to translate a va to page */
205*7c478bd9Sstevel@tonic-gate struct vnode unused_pages_vp;
206*7c478bd9Sstevel@tonic-gate 
207*7c478bd9Sstevel@tonic-gate /*
208*7c478bd9Sstevel@tonic-gate  * VM data structures allocated early during boot.
209*7c478bd9Sstevel@tonic-gate  */
210*7c478bd9Sstevel@tonic-gate size_t pagehash_sz;
211*7c478bd9Sstevel@tonic-gate uint64_t memlist_sz;
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate char tbr_wr_addr_inited = 0;
214*7c478bd9Sstevel@tonic-gate 
215*7c478bd9Sstevel@tonic-gate 
216*7c478bd9Sstevel@tonic-gate /*
217*7c478bd9Sstevel@tonic-gate  * Static Routines:
218*7c478bd9Sstevel@tonic-gate  */
219*7c478bd9Sstevel@tonic-gate static void memlist_add(uint64_t, uint64_t, struct memlist **,
220*7c478bd9Sstevel@tonic-gate 	struct memlist **);
221*7c478bd9Sstevel@tonic-gate static void kphysm_init(page_t *, struct memseg *, pgcnt_t, uintptr_t,
222*7c478bd9Sstevel@tonic-gate 	pgcnt_t);
223*7c478bd9Sstevel@tonic-gate static void kvm_init(void);
224*7c478bd9Sstevel@tonic-gate 
225*7c478bd9Sstevel@tonic-gate static void startup_init(void);
226*7c478bd9Sstevel@tonic-gate static void startup_memlist(void);
227*7c478bd9Sstevel@tonic-gate static void startup_modules(void);
228*7c478bd9Sstevel@tonic-gate static void startup_bop_gone(void);
229*7c478bd9Sstevel@tonic-gate static void startup_vm(void);
230*7c478bd9Sstevel@tonic-gate static void startup_end(void);
231*7c478bd9Sstevel@tonic-gate static void setup_cage_params(void);
232*7c478bd9Sstevel@tonic-gate static void startup_create_input_node(void);
233*7c478bd9Sstevel@tonic-gate 
234*7c478bd9Sstevel@tonic-gate static pgcnt_t npages;
235*7c478bd9Sstevel@tonic-gate static struct memlist *memlist;
236*7c478bd9Sstevel@tonic-gate void *memlist_end;
237*7c478bd9Sstevel@tonic-gate 
238*7c478bd9Sstevel@tonic-gate static pgcnt_t bop_alloc_pages;
239*7c478bd9Sstevel@tonic-gate static caddr_t hblk_base;
240*7c478bd9Sstevel@tonic-gate uint_t hblk_alloc_dynamic = 0;
241*7c478bd9Sstevel@tonic-gate uint_t hblk1_min = H1MIN;
242*7c478bd9Sstevel@tonic-gate uint_t hblk8_min;
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate 
245*7c478bd9Sstevel@tonic-gate /*
246*7c478bd9Sstevel@tonic-gate  * Hooks for unsupported platforms and down-rev firmware
247*7c478bd9Sstevel@tonic-gate  */
248*7c478bd9Sstevel@tonic-gate int iam_positron(void);
249*7c478bd9Sstevel@tonic-gate #pragma weak iam_positron
250*7c478bd9Sstevel@tonic-gate static void do_prom_version_check(void);
251*7c478bd9Sstevel@tonic-gate static void kpm_init(void);
252*7c478bd9Sstevel@tonic-gate static void kpm_npages_setup(int);
253*7c478bd9Sstevel@tonic-gate static void kpm_memseg_init(void);
254*7c478bd9Sstevel@tonic-gate 
255*7c478bd9Sstevel@tonic-gate /*
256*7c478bd9Sstevel@tonic-gate  * After receiving a thermal interrupt, this is the number of seconds
257*7c478bd9Sstevel@tonic-gate  * to delay before shutting off the system, assuming
258*7c478bd9Sstevel@tonic-gate  * shutdown fails.  Use /etc/system to change the delay if this isn't
259*7c478bd9Sstevel@tonic-gate  * large enough.
260*7c478bd9Sstevel@tonic-gate  */
261*7c478bd9Sstevel@tonic-gate int thermal_powerdown_delay = 1200;
262*7c478bd9Sstevel@tonic-gate 
263*7c478bd9Sstevel@tonic-gate /*
264*7c478bd9Sstevel@tonic-gate  * Used to hold off page relocations into the cage until OBP has completed
265*7c478bd9Sstevel@tonic-gate  * its boot-time handoff of its resources to the kernel.
266*7c478bd9Sstevel@tonic-gate  */
267*7c478bd9Sstevel@tonic-gate int page_relocate_ready = 0;
268*7c478bd9Sstevel@tonic-gate 
269*7c478bd9Sstevel@tonic-gate /*
270*7c478bd9Sstevel@tonic-gate  * Enable some debugging messages concerning memory usage...
271*7c478bd9Sstevel@tonic-gate  */
272*7c478bd9Sstevel@tonic-gate #ifdef  DEBUGGING_MEM
273*7c478bd9Sstevel@tonic-gate static int debugging_mem;
274*7c478bd9Sstevel@tonic-gate static void
275*7c478bd9Sstevel@tonic-gate printmemlist(char *title, struct memlist *list)
276*7c478bd9Sstevel@tonic-gate {
277*7c478bd9Sstevel@tonic-gate 	if (!debugging_mem)
278*7c478bd9Sstevel@tonic-gate 		return;
279*7c478bd9Sstevel@tonic-gate 
280*7c478bd9Sstevel@tonic-gate 	printf("%s\n", title);
281*7c478bd9Sstevel@tonic-gate 
282*7c478bd9Sstevel@tonic-gate 	while (list) {
283*7c478bd9Sstevel@tonic-gate 		prom_printf("\taddr = 0x%x %8x, size = 0x%x %8x\n",
284*7c478bd9Sstevel@tonic-gate 		    (uint32_t)(list->address >> 32), (uint32_t)list->address,
285*7c478bd9Sstevel@tonic-gate 		    (uint32_t)(list->size >> 32), (uint32_t)(list->size));
286*7c478bd9Sstevel@tonic-gate 		list = list->next;
287*7c478bd9Sstevel@tonic-gate 	}
288*7c478bd9Sstevel@tonic-gate }
289*7c478bd9Sstevel@tonic-gate 
290*7c478bd9Sstevel@tonic-gate void
291*7c478bd9Sstevel@tonic-gate printmemseg(struct memseg *memseg)
292*7c478bd9Sstevel@tonic-gate {
293*7c478bd9Sstevel@tonic-gate 	if (!debugging_mem)
294*7c478bd9Sstevel@tonic-gate 		return;
295*7c478bd9Sstevel@tonic-gate 
296*7c478bd9Sstevel@tonic-gate 	printf("memseg\n");
297*7c478bd9Sstevel@tonic-gate 
298*7c478bd9Sstevel@tonic-gate 	while (memseg) {
299*7c478bd9Sstevel@tonic-gate 		prom_printf("\tpage = 0x%p, epage = 0x%p, "
300*7c478bd9Sstevel@tonic-gate 		    "pfn = 0x%x, epfn = 0x%x\n",
301*7c478bd9Sstevel@tonic-gate 		    memseg->pages, memseg->epages,
302*7c478bd9Sstevel@tonic-gate 		    memseg->pages_base, memseg->pages_end);
303*7c478bd9Sstevel@tonic-gate 		memseg = memseg->next;
304*7c478bd9Sstevel@tonic-gate 	}
305*7c478bd9Sstevel@tonic-gate }
306*7c478bd9Sstevel@tonic-gate 
307*7c478bd9Sstevel@tonic-gate #define	debug_pause(str)	halt((str))
308*7c478bd9Sstevel@tonic-gate #define	MPRINTF(str)		if (debugging_mem) prom_printf((str))
309*7c478bd9Sstevel@tonic-gate #define	MPRINTF1(str, a)	if (debugging_mem) prom_printf((str), (a))
310*7c478bd9Sstevel@tonic-gate #define	MPRINTF2(str, a, b)	if (debugging_mem) prom_printf((str), (a), (b))
311*7c478bd9Sstevel@tonic-gate #define	MPRINTF3(str, a, b, c) \
312*7c478bd9Sstevel@tonic-gate 	if (debugging_mem) prom_printf((str), (a), (b), (c))
313*7c478bd9Sstevel@tonic-gate #else	/* DEBUGGING_MEM */
314*7c478bd9Sstevel@tonic-gate #define	MPRINTF(str)
315*7c478bd9Sstevel@tonic-gate #define	MPRINTF1(str, a)
316*7c478bd9Sstevel@tonic-gate #define	MPRINTF2(str, a, b)
317*7c478bd9Sstevel@tonic-gate #define	MPRINTF3(str, a, b, c)
318*7c478bd9Sstevel@tonic-gate #endif	/* DEBUGGING_MEM */
319*7c478bd9Sstevel@tonic-gate 
320*7c478bd9Sstevel@tonic-gate /* Simple message to indicate that the bootops pointer has been zeroed */
321*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
322*7c478bd9Sstevel@tonic-gate static int bootops_gone_on = 0;
323*7c478bd9Sstevel@tonic-gate #define	BOOTOPS_GONE() \
324*7c478bd9Sstevel@tonic-gate 	if (bootops_gone_on) \
325*7c478bd9Sstevel@tonic-gate 		prom_printf("The bootops vec is zeroed now!\n");
326*7c478bd9Sstevel@tonic-gate #else
327*7c478bd9Sstevel@tonic-gate #define	BOOTOPS_GONE()
328*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
329*7c478bd9Sstevel@tonic-gate 
330*7c478bd9Sstevel@tonic-gate /*
331*7c478bd9Sstevel@tonic-gate  * Monitor pages may not be where this says they are.
332*7c478bd9Sstevel@tonic-gate  * and the debugger may not be there either.
333*7c478bd9Sstevel@tonic-gate  *
334*7c478bd9Sstevel@tonic-gate  * Note that 'pages' here are *physical* pages, which are 8k on sun4u.
335*7c478bd9Sstevel@tonic-gate  *
336*7c478bd9Sstevel@tonic-gate  *                        Physical memory layout
337*7c478bd9Sstevel@tonic-gate  *                     (not necessarily contiguous)
338*7c478bd9Sstevel@tonic-gate  *                       (THIS IS SOMEWHAT WRONG)
339*7c478bd9Sstevel@tonic-gate  *                       /-----------------------\
340*7c478bd9Sstevel@tonic-gate  *                       |       monitor pages   |
341*7c478bd9Sstevel@tonic-gate  *             availmem -|-----------------------|
342*7c478bd9Sstevel@tonic-gate  *                       |                       |
343*7c478bd9Sstevel@tonic-gate  *                       |       page pool       |
344*7c478bd9Sstevel@tonic-gate  *                       |                       |
345*7c478bd9Sstevel@tonic-gate  *                       |-----------------------|
346*7c478bd9Sstevel@tonic-gate  *                       |   configured tables   |
347*7c478bd9Sstevel@tonic-gate  *                       |       buffers         |
348*7c478bd9Sstevel@tonic-gate  *            firstaddr -|-----------------------|
349*7c478bd9Sstevel@tonic-gate  *                       |   hat data structures |
350*7c478bd9Sstevel@tonic-gate  *                       |-----------------------|
351*7c478bd9Sstevel@tonic-gate  *                       |    kernel data, bss   |
352*7c478bd9Sstevel@tonic-gate  *                       |-----------------------|
353*7c478bd9Sstevel@tonic-gate  *                       |    interrupt stack    |
354*7c478bd9Sstevel@tonic-gate  *                       |-----------------------|
355*7c478bd9Sstevel@tonic-gate  *                       |    kernel text (RO)   |
356*7c478bd9Sstevel@tonic-gate  *                       |-----------------------|
357*7c478bd9Sstevel@tonic-gate  *                       |    trap table (4k)    |
358*7c478bd9Sstevel@tonic-gate  *                       |-----------------------|
359*7c478bd9Sstevel@tonic-gate  *               page 1  |      panicbuf         |
360*7c478bd9Sstevel@tonic-gate  *                       |-----------------------|
361*7c478bd9Sstevel@tonic-gate  *               page 0  |       reclaimed       |
362*7c478bd9Sstevel@tonic-gate  *                       |_______________________|
363*7c478bd9Sstevel@tonic-gate  *
364*7c478bd9Sstevel@tonic-gate  *
365*7c478bd9Sstevel@tonic-gate  *
366*7c478bd9Sstevel@tonic-gate  *                    Kernel's Virtual Memory Layout.
367*7c478bd9Sstevel@tonic-gate  *                       /-----------------------\
368*7c478bd9Sstevel@tonic-gate  * 0xFFFFFFFF.FFFFFFFF  -|                       |-
369*7c478bd9Sstevel@tonic-gate  *                       |   OBP's virtual page  |
370*7c478bd9Sstevel@tonic-gate  *                       |        tables         |
371*7c478bd9Sstevel@tonic-gate  * 0xFFFFFFFC.00000000  -|-----------------------|-
372*7c478bd9Sstevel@tonic-gate  *                       :                       :
373*7c478bd9Sstevel@tonic-gate  *                       :                       :
374*7c478bd9Sstevel@tonic-gate  * 0xFFFFFE00.00000000  -|-----------------------|-
375*7c478bd9Sstevel@tonic-gate  *                       |                       |  Ultrasparc I/II support
376*7c478bd9Sstevel@tonic-gate  *                       |    segkpm segment     |  up to 2TB of physical
377*7c478bd9Sstevel@tonic-gate  *                       | (64-bit kernel ONLY)  |  memory, VAC has 2 colors
378*7c478bd9Sstevel@tonic-gate  *                       |                       |
379*7c478bd9Sstevel@tonic-gate  * 0xFFFFFA00.00000000  -|-----------------------|- 2TB segkpm alignment
380*7c478bd9Sstevel@tonic-gate  *                       :                       :
381*7c478bd9Sstevel@tonic-gate  *                       :                       :
382*7c478bd9Sstevel@tonic-gate  * 0xFFFFF810.00000000  -|-----------------------|- hole_end
383*7c478bd9Sstevel@tonic-gate  *                       |                       |      ^
384*7c478bd9Sstevel@tonic-gate  *                       |  UltraSPARC I/II call |      |
385*7c478bd9Sstevel@tonic-gate  *                       | bug requires an extra |      |
386*7c478bd9Sstevel@tonic-gate  *                       | 4 GB of space between |      |
387*7c478bd9Sstevel@tonic-gate  *                       |   hole and used RAM   |	|
388*7c478bd9Sstevel@tonic-gate  *                       |                       |      |
389*7c478bd9Sstevel@tonic-gate  * 0xFFFFF800.00000000  -|-----------------------|-     |
390*7c478bd9Sstevel@tonic-gate  *                       |                       |      |
391*7c478bd9Sstevel@tonic-gate  *                       | Virtual Address Hole  |   UltraSPARC
392*7c478bd9Sstevel@tonic-gate  *                       |  on UltraSPARC I/II   |  I/II * ONLY *
393*7c478bd9Sstevel@tonic-gate  *                       |                       |      |
394*7c478bd9Sstevel@tonic-gate  * 0x00000800.00000000  -|-----------------------|-     |
395*7c478bd9Sstevel@tonic-gate  *                       |                       |      |
396*7c478bd9Sstevel@tonic-gate  *                       |  UltraSPARC I/II call |      |
397*7c478bd9Sstevel@tonic-gate  *                       | bug requires an extra |      |
398*7c478bd9Sstevel@tonic-gate  *                       | 4 GB of space between |      |
399*7c478bd9Sstevel@tonic-gate  *                       |   hole and used RAM   |      |
400*7c478bd9Sstevel@tonic-gate  *                       |                       |      v
401*7c478bd9Sstevel@tonic-gate  * 0x000007FF.00000000  -|-----------------------|- hole_start -----
402*7c478bd9Sstevel@tonic-gate  *                       :                       :		   ^
403*7c478bd9Sstevel@tonic-gate  *                       :                       :		   |
404*7c478bd9Sstevel@tonic-gate  * 0x00000XXX.XXXXXXXX  -|-----------------------|- kmem64_end	   |
405*7c478bd9Sstevel@tonic-gate  *                       |                       |		   |
406*7c478bd9Sstevel@tonic-gate  *                       |   64-bit kernel ONLY  |		   |
407*7c478bd9Sstevel@tonic-gate  *                       |                       |		   |
408*7c478bd9Sstevel@tonic-gate  *                       |    kmem64 segment     |		   |
409*7c478bd9Sstevel@tonic-gate  *                       |                       |		   |
410*7c478bd9Sstevel@tonic-gate  *                       | (Relocated extra HME  |	     Approximately
411*7c478bd9Sstevel@tonic-gate  *                       |   block allocations,  |	    1 TB of virtual
412*7c478bd9Sstevel@tonic-gate  *                       |   memnode freelists,  |	     address space
413*7c478bd9Sstevel@tonic-gate  *                       |    HME hash buckets,  |		   |
414*7c478bd9Sstevel@tonic-gate  *                       | mml_table, kpmp_table,|		   |
415*7c478bd9Sstevel@tonic-gate  *                       |  page_t array and     |		   |
416*7c478bd9Sstevel@tonic-gate  *                       |  hashblock pool to    |		   |
417*7c478bd9Sstevel@tonic-gate  *                       |   avoid hard-coded    |		   |
418*7c478bd9Sstevel@tonic-gate  *                       |     32-bit vaddr      |		   |
419*7c478bd9Sstevel@tonic-gate  *                       |     limitations)      |		   |
420*7c478bd9Sstevel@tonic-gate  *                       |                       |		   v
421*7c478bd9Sstevel@tonic-gate  * 0x00000700.00000000  -|-----------------------|- SYSLIMIT (kmem64_base)
422*7c478bd9Sstevel@tonic-gate  *                       |                       |
423*7c478bd9Sstevel@tonic-gate  *                       |  segkmem segment      | (SYSLIMIT - SYSBASE = 4TB)
424*7c478bd9Sstevel@tonic-gate  *                       |                       |
425*7c478bd9Sstevel@tonic-gate  * 0x00000300.00000000  -|-----------------------|- SYSBASE
426*7c478bd9Sstevel@tonic-gate  *                       :                       :
427*7c478bd9Sstevel@tonic-gate  *                       :                       :
428*7c478bd9Sstevel@tonic-gate  *                      -|-----------------------|-
429*7c478bd9Sstevel@tonic-gate  *                       |                       |
430*7c478bd9Sstevel@tonic-gate  *                       |  segmap segment       |   SEGMAPSIZE (1/8th physmem,
431*7c478bd9Sstevel@tonic-gate  *                       |                       |               256G MAX)
432*7c478bd9Sstevel@tonic-gate  * 0x000002a7.50000000  -|-----------------------|- SEGMAPBASE
433*7c478bd9Sstevel@tonic-gate  *                       :                       :
434*7c478bd9Sstevel@tonic-gate  *                       :                       :
435*7c478bd9Sstevel@tonic-gate  *                      -|-----------------------|-
436*7c478bd9Sstevel@tonic-gate  *                       |                       |
437*7c478bd9Sstevel@tonic-gate  *                       |       segkp           |    SEGKPSIZE (2GB)
438*7c478bd9Sstevel@tonic-gate  *                       |                       |
439*7c478bd9Sstevel@tonic-gate  *                       |                       |
440*7c478bd9Sstevel@tonic-gate  * 0x000002a1.00000000  -|-----------------------|- SEGKPBASE
441*7c478bd9Sstevel@tonic-gate  *                       |                       |
442*7c478bd9Sstevel@tonic-gate  * 0x000002a0.00000000  -|-----------------------|- MEMSCRUBBASE
443*7c478bd9Sstevel@tonic-gate  *                       |                       |       (SEGKPBASE - 0x400000)
444*7c478bd9Sstevel@tonic-gate  * 0x0000029F.FFE00000  -|-----------------------|- ARGSBASE
445*7c478bd9Sstevel@tonic-gate  *                       |                       |       (MEMSCRUBBASE - NCARGS)
446*7c478bd9Sstevel@tonic-gate  * 0x0000029F.FFD80000  -|-----------------------|- PPMAPBASE
447*7c478bd9Sstevel@tonic-gate  *                       |                       |       (ARGSBASE - PPMAPSIZE)
448*7c478bd9Sstevel@tonic-gate  * 0x0000029F.FFD00000  -|-----------------------|- PPMAP_FAST_BASE
449*7c478bd9Sstevel@tonic-gate  *                       |                       |
450*7c478bd9Sstevel@tonic-gate  * 0x0000029F.FF980000  -|-----------------------|- PIOMAPBASE
451*7c478bd9Sstevel@tonic-gate  *                       |                       |
452*7c478bd9Sstevel@tonic-gate  * 0x0000029F.FF580000  -|-----------------------|- NARG_BASE
453*7c478bd9Sstevel@tonic-gate  *                       :                       :
454*7c478bd9Sstevel@tonic-gate  *                       :                       :
455*7c478bd9Sstevel@tonic-gate  * 0x00000000.FFFFFFFF  -|-----------------------|- OFW_END_ADDR
456*7c478bd9Sstevel@tonic-gate  *                       |                       |
457*7c478bd9Sstevel@tonic-gate  *                       |         OBP           |
458*7c478bd9Sstevel@tonic-gate  *                       |                       |
459*7c478bd9Sstevel@tonic-gate  * 0x00000000.F0000000  -|-----------------------|- OFW_START_ADDR
460*7c478bd9Sstevel@tonic-gate  *                       |         kmdb          |
461*7c478bd9Sstevel@tonic-gate  * 0x00000000.EDD00000  -|-----------------------|- SEGDEBUGBASE
462*7c478bd9Sstevel@tonic-gate  *                       :                       :
463*7c478bd9Sstevel@tonic-gate  *                       :                       :
464*7c478bd9Sstevel@tonic-gate  * 0x00000000.7c000000  -|-----------------------|- SYSLIMIT32
465*7c478bd9Sstevel@tonic-gate  *                       |                       |
466*7c478bd9Sstevel@tonic-gate  *                       |  segkmem32 segment    | (SYSLIMIT32 - SYSBASE32 =
467*7c478bd9Sstevel@tonic-gate  *                       |                       |    ~64MB)
468*7c478bd9Sstevel@tonic-gate  * 0x00000000.78002000  -|-----------------------|
469*7c478bd9Sstevel@tonic-gate  *                       |     panicbuf          |
470*7c478bd9Sstevel@tonic-gate  * 0x00000000.78000000  -|-----------------------|- SYSBASE32
471*7c478bd9Sstevel@tonic-gate  *                       :                       :
472*7c478bd9Sstevel@tonic-gate  *                       :                       :
473*7c478bd9Sstevel@tonic-gate  *                       |                       |
474*7c478bd9Sstevel@tonic-gate  *                       |-----------------------|- econtig32
475*7c478bd9Sstevel@tonic-gate  *                       |    vm structures      |
476*7c478bd9Sstevel@tonic-gate  * 0x00000000.01C00000   |-----------------------|- nalloc_end
477*7c478bd9Sstevel@tonic-gate  *                       |         TSBs          |
478*7c478bd9Sstevel@tonic-gate  *                       |-----------------------|- end/nalloc_base
479*7c478bd9Sstevel@tonic-gate  *                       |   kernel data & bss   |
480*7c478bd9Sstevel@tonic-gate  * 0x00000000.01800000  -|-----------------------|
481*7c478bd9Sstevel@tonic-gate  *                       :   nucleus text hole   :
482*7c478bd9Sstevel@tonic-gate  * 0x00000000.01400000  -|-----------------------|
483*7c478bd9Sstevel@tonic-gate  *                       :                       :
484*7c478bd9Sstevel@tonic-gate  *                       |-----------------------|
485*7c478bd9Sstevel@tonic-gate  *                       |      module text      |
486*7c478bd9Sstevel@tonic-gate  *                       |-----------------------|- e_text/modtext
487*7c478bd9Sstevel@tonic-gate  *                       |      kernel text      |
488*7c478bd9Sstevel@tonic-gate  *                       |-----------------------|
489*7c478bd9Sstevel@tonic-gate  *                       |    trap table (48k)   |
490*7c478bd9Sstevel@tonic-gate  * 0x00000000.01000000  -|-----------------------|- KERNELBASE
491*7c478bd9Sstevel@tonic-gate  *                       | reserved for trapstat |} TSTAT_TOTAL_SIZE
492*7c478bd9Sstevel@tonic-gate  *                       |-----------------------|
493*7c478bd9Sstevel@tonic-gate  *                       |                       |
494*7c478bd9Sstevel@tonic-gate  *                       |        invalid        |
495*7c478bd9Sstevel@tonic-gate  *                       |                       |
496*7c478bd9Sstevel@tonic-gate  * 0x00000000.00000000  _|_______________________|
497*7c478bd9Sstevel@tonic-gate  *
498*7c478bd9Sstevel@tonic-gate  *
499*7c478bd9Sstevel@tonic-gate  *
500*7c478bd9Sstevel@tonic-gate  *                   32-bit User Virtual Memory Layout.
501*7c478bd9Sstevel@tonic-gate  *                       /-----------------------\
502*7c478bd9Sstevel@tonic-gate  *                       |                       |
503*7c478bd9Sstevel@tonic-gate  *                       |        invalid        |
504*7c478bd9Sstevel@tonic-gate  *                       |                       |
505*7c478bd9Sstevel@tonic-gate  *          0xFFC00000  -|-----------------------|- USERLIMIT
506*7c478bd9Sstevel@tonic-gate  *                       |       user stack      |
507*7c478bd9Sstevel@tonic-gate  *                       :                       :
508*7c478bd9Sstevel@tonic-gate  *                       :                       :
509*7c478bd9Sstevel@tonic-gate  *                       :                       :
510*7c478bd9Sstevel@tonic-gate  *                       |       user data       |
511*7c478bd9Sstevel@tonic-gate  *                      -|-----------------------|-
512*7c478bd9Sstevel@tonic-gate  *                       |       user text       |
513*7c478bd9Sstevel@tonic-gate  *          0x00002000  -|-----------------------|-
514*7c478bd9Sstevel@tonic-gate  *                       |       invalid         |
515*7c478bd9Sstevel@tonic-gate  *          0x00000000  _|_______________________|
516*7c478bd9Sstevel@tonic-gate  *
517*7c478bd9Sstevel@tonic-gate  *
518*7c478bd9Sstevel@tonic-gate  *
519*7c478bd9Sstevel@tonic-gate  *                   64-bit User Virtual Memory Layout.
520*7c478bd9Sstevel@tonic-gate  *                       /-----------------------\
521*7c478bd9Sstevel@tonic-gate  *                       |                       |
522*7c478bd9Sstevel@tonic-gate  *                       |        invalid        |
523*7c478bd9Sstevel@tonic-gate  *                       |                       |
524*7c478bd9Sstevel@tonic-gate  *  0xFFFFFFFF.80000000 -|-----------------------|- USERLIMIT
525*7c478bd9Sstevel@tonic-gate  *                       |       user stack      |
526*7c478bd9Sstevel@tonic-gate  *                       :                       :
527*7c478bd9Sstevel@tonic-gate  *                       :                       :
528*7c478bd9Sstevel@tonic-gate  *                       :                       :
529*7c478bd9Sstevel@tonic-gate  *                       |       user data       |
530*7c478bd9Sstevel@tonic-gate  *                      -|-----------------------|-
531*7c478bd9Sstevel@tonic-gate  *                       |       user text       |
532*7c478bd9Sstevel@tonic-gate  *  0x00000000.00100000 -|-----------------------|-
533*7c478bd9Sstevel@tonic-gate  *                       |       invalid         |
534*7c478bd9Sstevel@tonic-gate  *  0x00000000.00000000 _|_______________________|
535*7c478bd9Sstevel@tonic-gate  */
536*7c478bd9Sstevel@tonic-gate 
537*7c478bd9Sstevel@tonic-gate extern caddr_t ecache_init_scrub_flush_area(caddr_t alloc_base);
538*7c478bd9Sstevel@tonic-gate extern uint64_t ecache_flush_address(void);
539*7c478bd9Sstevel@tonic-gate 
540*7c478bd9Sstevel@tonic-gate #pragma weak load_platform_modules
541*7c478bd9Sstevel@tonic-gate #pragma weak starcat_startup_memlist
542*7c478bd9Sstevel@tonic-gate #pragma weak ecache_init_scrub_flush_area
543*7c478bd9Sstevel@tonic-gate #pragma weak ecache_flush_address
544*7c478bd9Sstevel@tonic-gate 
545*7c478bd9Sstevel@tonic-gate 
546*7c478bd9Sstevel@tonic-gate /*
547*7c478bd9Sstevel@tonic-gate  * By default the DR Cage is enabled for maximum OS
548*7c478bd9Sstevel@tonic-gate  * MPSS performance.  Users needing to disable the cage mechanism
549*7c478bd9Sstevel@tonic-gate  * can set this variable to zero via /etc/system.
550*7c478bd9Sstevel@tonic-gate  * Disabling the cage on systems supporting Dynamic Reconfiguration (DR)
551*7c478bd9Sstevel@tonic-gate  * will result in loss of DR functionality.
552*7c478bd9Sstevel@tonic-gate  * Platforms wishing to disable kernel Cage by default
553*7c478bd9Sstevel@tonic-gate  * should do so in their set_platform_defaults() routine.
554*7c478bd9Sstevel@tonic-gate  */
555*7c478bd9Sstevel@tonic-gate int	kernel_cage_enable = 1;
556*7c478bd9Sstevel@tonic-gate 
557*7c478bd9Sstevel@tonic-gate static void
558*7c478bd9Sstevel@tonic-gate setup_cage_params(void)
559*7c478bd9Sstevel@tonic-gate {
560*7c478bd9Sstevel@tonic-gate 	void (*func)(void);
561*7c478bd9Sstevel@tonic-gate 
562*7c478bd9Sstevel@tonic-gate 	func = (void (*)(void))kobj_getsymvalue("set_platform_cage_params", 0);
563*7c478bd9Sstevel@tonic-gate 	if (func != NULL) {
564*7c478bd9Sstevel@tonic-gate 		(*func)();
565*7c478bd9Sstevel@tonic-gate 		return;
566*7c478bd9Sstevel@tonic-gate 	}
567*7c478bd9Sstevel@tonic-gate 
568*7c478bd9Sstevel@tonic-gate 	if (kernel_cage_enable == 0) {
569*7c478bd9Sstevel@tonic-gate 		return;
570*7c478bd9Sstevel@tonic-gate 	}
571*7c478bd9Sstevel@tonic-gate 	kcage_range_lock();
572*7c478bd9Sstevel@tonic-gate 	if (kcage_range_init(phys_avail, 1) == 0) {
573*7c478bd9Sstevel@tonic-gate 		kcage_init(total_pages / 256);
574*7c478bd9Sstevel@tonic-gate 	}
575*7c478bd9Sstevel@tonic-gate 	kcage_range_unlock();
576*7c478bd9Sstevel@tonic-gate 
577*7c478bd9Sstevel@tonic-gate 	if (kcage_on) {
578*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!Kernel Cage is ENABLED");
579*7c478bd9Sstevel@tonic-gate 	} else {
580*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_NOTE, "!Kernel Cage is DISABLED");
581*7c478bd9Sstevel@tonic-gate 	}
582*7c478bd9Sstevel@tonic-gate 
583*7c478bd9Sstevel@tonic-gate }
584*7c478bd9Sstevel@tonic-gate 
585*7c478bd9Sstevel@tonic-gate /*
586*7c478bd9Sstevel@tonic-gate  * Machine-dependent startup code
587*7c478bd9Sstevel@tonic-gate  */
588*7c478bd9Sstevel@tonic-gate void
589*7c478bd9Sstevel@tonic-gate startup(void)
590*7c478bd9Sstevel@tonic-gate {
591*7c478bd9Sstevel@tonic-gate 	startup_init();
592*7c478bd9Sstevel@tonic-gate 	if (&startup_platform)
593*7c478bd9Sstevel@tonic-gate 		startup_platform();
594*7c478bd9Sstevel@tonic-gate 	startup_memlist();
595*7c478bd9Sstevel@tonic-gate 	startup_modules();
596*7c478bd9Sstevel@tonic-gate 	setup_cage_params();
597*7c478bd9Sstevel@tonic-gate 	startup_bop_gone();
598*7c478bd9Sstevel@tonic-gate 	startup_vm();
599*7c478bd9Sstevel@tonic-gate 	startup_end();
600*7c478bd9Sstevel@tonic-gate }
601*7c478bd9Sstevel@tonic-gate 
602*7c478bd9Sstevel@tonic-gate struct regs sync_reg_buf;
603*7c478bd9Sstevel@tonic-gate uint64_t sync_tt;
604*7c478bd9Sstevel@tonic-gate 
605*7c478bd9Sstevel@tonic-gate void
606*7c478bd9Sstevel@tonic-gate sync_handler(void)
607*7c478bd9Sstevel@tonic-gate {
608*7c478bd9Sstevel@tonic-gate 	struct  trap_info 	ti;
609*7c478bd9Sstevel@tonic-gate 	int i;
610*7c478bd9Sstevel@tonic-gate 
611*7c478bd9Sstevel@tonic-gate 	/*
612*7c478bd9Sstevel@tonic-gate 	 * Prevent trying to talk to the other CPUs since they are
613*7c478bd9Sstevel@tonic-gate 	 * sitting in the prom and won't reply.
614*7c478bd9Sstevel@tonic-gate 	 */
615*7c478bd9Sstevel@tonic-gate 	for (i = 0; i < NCPU; i++) {
616*7c478bd9Sstevel@tonic-gate 		if ((i != CPU->cpu_id) && CPU_XCALL_READY(i)) {
617*7c478bd9Sstevel@tonic-gate 			cpu[i]->cpu_flags &= ~CPU_READY;
618*7c478bd9Sstevel@tonic-gate 			cpu[i]->cpu_flags |= CPU_QUIESCED;
619*7c478bd9Sstevel@tonic-gate 			CPUSET_DEL(cpu_ready_set, cpu[i]->cpu_id);
620*7c478bd9Sstevel@tonic-gate 		}
621*7c478bd9Sstevel@tonic-gate 	}
622*7c478bd9Sstevel@tonic-gate 
623*7c478bd9Sstevel@tonic-gate 	/*
624*7c478bd9Sstevel@tonic-gate 	 * We've managed to get here without going through the
625*7c478bd9Sstevel@tonic-gate 	 * normal panic code path. Try and save some useful
626*7c478bd9Sstevel@tonic-gate 	 * information.
627*7c478bd9Sstevel@tonic-gate 	 */
628*7c478bd9Sstevel@tonic-gate 	if (!panicstr && (curthread->t_panic_trap == NULL)) {
629*7c478bd9Sstevel@tonic-gate 		ti.trap_type = sync_tt;
630*7c478bd9Sstevel@tonic-gate 		ti.trap_regs = &sync_reg_buf;
631*7c478bd9Sstevel@tonic-gate 		ti.trap_addr = NULL;
632*7c478bd9Sstevel@tonic-gate 		ti.trap_mmu_fsr = 0x0;
633*7c478bd9Sstevel@tonic-gate 
634*7c478bd9Sstevel@tonic-gate 		curthread->t_panic_trap = &ti;
635*7c478bd9Sstevel@tonic-gate 	}
636*7c478bd9Sstevel@tonic-gate 
637*7c478bd9Sstevel@tonic-gate 	/*
638*7c478bd9Sstevel@tonic-gate 	 * If we're re-entering the panic path, update the signature
639*7c478bd9Sstevel@tonic-gate 	 * block so that the SC knows we're in the second part of panic.
640*7c478bd9Sstevel@tonic-gate 	 */
641*7c478bd9Sstevel@tonic-gate 	if (panicstr)
642*7c478bd9Sstevel@tonic-gate 		CPU_SIGNATURE(OS_SIG, SIGST_EXIT, SIGSUBST_DUMP, -1);
643*7c478bd9Sstevel@tonic-gate 
644*7c478bd9Sstevel@tonic-gate 	nopanicdebug = 1; /* do not perform debug_enter() prior to dump */
645*7c478bd9Sstevel@tonic-gate 	panic("sync initiated");
646*7c478bd9Sstevel@tonic-gate }
647*7c478bd9Sstevel@tonic-gate 
648*7c478bd9Sstevel@tonic-gate 
649*7c478bd9Sstevel@tonic-gate static void
650*7c478bd9Sstevel@tonic-gate startup_init(void)
651*7c478bd9Sstevel@tonic-gate {
652*7c478bd9Sstevel@tonic-gate 	/*
653*7c478bd9Sstevel@tonic-gate 	 * We want to save the registers while we're still in OBP
654*7c478bd9Sstevel@tonic-gate 	 * so that we know they haven't been fiddled with since.
655*7c478bd9Sstevel@tonic-gate 	 * (In principle, OBP can't change them just because it
656*7c478bd9Sstevel@tonic-gate 	 * makes a callback, but we'd rather not depend on that
657*7c478bd9Sstevel@tonic-gate 	 * behavior.)
658*7c478bd9Sstevel@tonic-gate 	 */
659*7c478bd9Sstevel@tonic-gate 	char		sync_str[] =
660*7c478bd9Sstevel@tonic-gate 		"warning @ warning off : sync "
661*7c478bd9Sstevel@tonic-gate 		"%%tl-c %%tstate h# %p x! "
662*7c478bd9Sstevel@tonic-gate 		"%%g1 h# %p x! %%g2 h# %p x! %%g3 h# %p x! "
663*7c478bd9Sstevel@tonic-gate 		"%%g4 h# %p x! %%g5 h# %p x! %%g6 h# %p x! "
664*7c478bd9Sstevel@tonic-gate 		"%%g7 h# %p x! %%o0 h# %p x! %%o1 h# %p x! "
665*7c478bd9Sstevel@tonic-gate 		"%%o2 h# %p x! %%o3 h# %p x! %%o4 h# %p x! "
666*7c478bd9Sstevel@tonic-gate 		"%%o5 h# %p x! %%o6 h# %p x! %%o7 h# %p x! "
667*7c478bd9Sstevel@tonic-gate 		"%%tl-c %%tpc h# %p x! %%tl-c %%tnpc h# %p x! "
668*7c478bd9Sstevel@tonic-gate 		"%%y h# %p l! %%tl-c %%tt h# %p x! "
669*7c478bd9Sstevel@tonic-gate 		"sync ; warning !";
670*7c478bd9Sstevel@tonic-gate 
671*7c478bd9Sstevel@tonic-gate 	/*
672*7c478bd9Sstevel@tonic-gate 	 * 20 == num of %p substrings
673*7c478bd9Sstevel@tonic-gate 	 * 16 == max num of chars %p will expand to.
674*7c478bd9Sstevel@tonic-gate 	 */
675*7c478bd9Sstevel@tonic-gate 	char 		bp[sizeof (sync_str) + 16 * 20];
676*7c478bd9Sstevel@tonic-gate 
677*7c478bd9Sstevel@tonic-gate 	(void) check_boot_version(BOP_GETVERSION(bootops));
678*7c478bd9Sstevel@tonic-gate 
679*7c478bd9Sstevel@tonic-gate 	/*
680*7c478bd9Sstevel@tonic-gate 	 * Initialize ptl1 stack for the 1st CPU.
681*7c478bd9Sstevel@tonic-gate 	 */
682*7c478bd9Sstevel@tonic-gate 	ptl1_init_cpu(&cpu0);
683*7c478bd9Sstevel@tonic-gate 
684*7c478bd9Sstevel@tonic-gate 	/*
685*7c478bd9Sstevel@tonic-gate 	 * Initialize the address map for cache consistent mappings
686*7c478bd9Sstevel@tonic-gate 	 * to random pages; must be done after vac_size is set.
687*7c478bd9Sstevel@tonic-gate 	 */
688*7c478bd9Sstevel@tonic-gate 	ppmapinit();
689*7c478bd9Sstevel@tonic-gate 
690*7c478bd9Sstevel@tonic-gate 	/*
691*7c478bd9Sstevel@tonic-gate 	 * Initialize the PROM callback handler.
692*7c478bd9Sstevel@tonic-gate 	 */
693*7c478bd9Sstevel@tonic-gate 	init_vx_handler();
694*7c478bd9Sstevel@tonic-gate 
695*7c478bd9Sstevel@tonic-gate 	/*
696*7c478bd9Sstevel@tonic-gate 	 * have prom call sync_callback() to handle the sync and
697*7c478bd9Sstevel@tonic-gate 	 * save some useful information which will be stored in the
698*7c478bd9Sstevel@tonic-gate 	 * core file later.
699*7c478bd9Sstevel@tonic-gate 	 */
700*7c478bd9Sstevel@tonic-gate 	(void) sprintf((char *)bp, sync_str,
701*7c478bd9Sstevel@tonic-gate 		(void *)&sync_reg_buf.r_tstate, (void *)&sync_reg_buf.r_g1,
702*7c478bd9Sstevel@tonic-gate 		(void *)&sync_reg_buf.r_g2, (void *)&sync_reg_buf.r_g3,
703*7c478bd9Sstevel@tonic-gate 		(void *)&sync_reg_buf.r_g4, (void *)&sync_reg_buf.r_g5,
704*7c478bd9Sstevel@tonic-gate 		(void *)&sync_reg_buf.r_g6, (void *)&sync_reg_buf.r_g7,
705*7c478bd9Sstevel@tonic-gate 		(void *)&sync_reg_buf.r_o0, (void *)&sync_reg_buf.r_o1,
706*7c478bd9Sstevel@tonic-gate 		(void *)&sync_reg_buf.r_o2, (void *)&sync_reg_buf.r_o3,
707*7c478bd9Sstevel@tonic-gate 		(void *)&sync_reg_buf.r_o4, (void *)&sync_reg_buf.r_o5,
708*7c478bd9Sstevel@tonic-gate 		(void *)&sync_reg_buf.r_o6, (void *)&sync_reg_buf.r_o7,
709*7c478bd9Sstevel@tonic-gate 		(void *)&sync_reg_buf.r_pc, (void *)&sync_reg_buf.r_npc,
710*7c478bd9Sstevel@tonic-gate 		(void *)&sync_reg_buf.r_y, (void *)&sync_tt);
711*7c478bd9Sstevel@tonic-gate 	prom_interpret(bp, 0, 0, 0, 0, 0);
712*7c478bd9Sstevel@tonic-gate 	add_vx_handler("sync", 1, (void (*)(cell_t *))sync_handler);
713*7c478bd9Sstevel@tonic-gate }
714*7c478bd9Sstevel@tonic-gate 
715*7c478bd9Sstevel@tonic-gate static u_longlong_t *boot_physinstalled, *boot_physavail, *boot_virtavail;
716*7c478bd9Sstevel@tonic-gate static size_t boot_physinstalled_len, boot_physavail_len, boot_virtavail_len;
717*7c478bd9Sstevel@tonic-gate 
718*7c478bd9Sstevel@tonic-gate #define	IVSIZE	((MAXIVNUM + 1) * sizeof (struct intr_vector))
719*7c478bd9Sstevel@tonic-gate 
720*7c478bd9Sstevel@tonic-gate /*
721*7c478bd9Sstevel@tonic-gate  * As OBP takes up some RAM when the system boots, pages will already be "lost"
722*7c478bd9Sstevel@tonic-gate  * to the system and reflected in npages by the time we see it.
723*7c478bd9Sstevel@tonic-gate  *
724*7c478bd9Sstevel@tonic-gate  * We only want to allocate kernel structures in the 64-bit virtual address
725*7c478bd9Sstevel@tonic-gate  * space on systems with enough RAM to make the overhead of keeping track of
726*7c478bd9Sstevel@tonic-gate  * an extra kernel memory segment worthwhile.
727*7c478bd9Sstevel@tonic-gate  *
728*7c478bd9Sstevel@tonic-gate  * Since OBP has already performed its memory allocations by this point, if we
729*7c478bd9Sstevel@tonic-gate  * have more than MINMOVE_RAM_MB MB of RAM left free, go ahead and map
730*7c478bd9Sstevel@tonic-gate  * memory in the 64-bit virtual address space; otherwise keep allocations
731*7c478bd9Sstevel@tonic-gate  * contiguous with we've mapped so far in the 32-bit virtual address space.
732*7c478bd9Sstevel@tonic-gate  */
733*7c478bd9Sstevel@tonic-gate #define	MINMOVE_RAM_MB	((size_t)1900)
734*7c478bd9Sstevel@tonic-gate #define	MB_TO_BYTES(mb)	((mb) * 1048576ul)
735*7c478bd9Sstevel@tonic-gate 
736*7c478bd9Sstevel@tonic-gate pgcnt_t	tune_npages = (pgcnt_t)
737*7c478bd9Sstevel@tonic-gate 	(MB_TO_BYTES(MINMOVE_RAM_MB)/ (size_t)MMU_PAGESIZE);
738*7c478bd9Sstevel@tonic-gate 
739*7c478bd9Sstevel@tonic-gate static void
740*7c478bd9Sstevel@tonic-gate startup_memlist(void)
741*7c478bd9Sstevel@tonic-gate {
742*7c478bd9Sstevel@tonic-gate 	size_t alloc_sz;
743*7c478bd9Sstevel@tonic-gate 	size_t ctrs_sz;
744*7c478bd9Sstevel@tonic-gate 	caddr_t alloc_base;
745*7c478bd9Sstevel@tonic-gate 	caddr_t ctrs_base, ctrs_end;
746*7c478bd9Sstevel@tonic-gate 	caddr_t memspace;
747*7c478bd9Sstevel@tonic-gate 	caddr_t va;
748*7c478bd9Sstevel@tonic-gate 	int memblocks = 0;
749*7c478bd9Sstevel@tonic-gate 	struct memlist *cur;
750*7c478bd9Sstevel@tonic-gate 	size_t syslimit = (size_t)SYSLIMIT;
751*7c478bd9Sstevel@tonic-gate 	size_t sysbase = (size_t)SYSBASE;
752*7c478bd9Sstevel@tonic-gate 	int alloc_alignsize = MMU_PAGESIZE;
753*7c478bd9Sstevel@tonic-gate 	extern void page_coloring_init(void);
754*7c478bd9Sstevel@tonic-gate 
755*7c478bd9Sstevel@tonic-gate 	/*
756*7c478bd9Sstevel@tonic-gate 	 * Initialize enough of the system to allow kmem_alloc to work by
757*7c478bd9Sstevel@tonic-gate 	 * calling boot to allocate its memory until the time that
758*7c478bd9Sstevel@tonic-gate 	 * kvm_init is completed.  The page structs are allocated after
759*7c478bd9Sstevel@tonic-gate 	 * rounding up end to the nearest page boundary; the memsegs are
760*7c478bd9Sstevel@tonic-gate 	 * initialized and the space they use comes from the kernel heap.
761*7c478bd9Sstevel@tonic-gate 	 * With appropriate initialization, they can be reallocated later
762*7c478bd9Sstevel@tonic-gate 	 * to a size appropriate for the machine's configuration.
763*7c478bd9Sstevel@tonic-gate 	 *
764*7c478bd9Sstevel@tonic-gate 	 * At this point, memory is allocated for things that will never
765*7c478bd9Sstevel@tonic-gate 	 * need to be freed, this used to be "valloced".  This allows a
766*7c478bd9Sstevel@tonic-gate 	 * savings as the pages don't need page structures to describe
767*7c478bd9Sstevel@tonic-gate 	 * them because them will not be managed by the vm system.
768*7c478bd9Sstevel@tonic-gate 	 */
769*7c478bd9Sstevel@tonic-gate 
770*7c478bd9Sstevel@tonic-gate 	/*
771*7c478bd9Sstevel@tonic-gate 	 * We're loaded by boot with the following configuration (as
772*7c478bd9Sstevel@tonic-gate 	 * specified in the sun4u/conf/Mapfile):
773*7c478bd9Sstevel@tonic-gate 	 *
774*7c478bd9Sstevel@tonic-gate 	 * 	text:		4 MB chunk aligned on a 4MB boundary
775*7c478bd9Sstevel@tonic-gate 	 * 	data & bss:	4 MB chunk aligned on a 4MB boundary
776*7c478bd9Sstevel@tonic-gate 	 *
777*7c478bd9Sstevel@tonic-gate 	 * These two chunks will eventually be mapped by 2 locked 4MB
778*7c478bd9Sstevel@tonic-gate 	 * ttes and will represent the nucleus of the kernel.  This gives
779*7c478bd9Sstevel@tonic-gate 	 * us some free space that is already allocated, some or all of
780*7c478bd9Sstevel@tonic-gate 	 * which is made available to kernel module text.
781*7c478bd9Sstevel@tonic-gate 	 *
782*7c478bd9Sstevel@tonic-gate 	 * The free space in the data-bss chunk is used for nucleus
783*7c478bd9Sstevel@tonic-gate 	 * allocatable data structures and we reserve it using the
784*7c478bd9Sstevel@tonic-gate 	 * nalloc_base and nalloc_end variables.  This space is currently
785*7c478bd9Sstevel@tonic-gate 	 * being used for hat data structures required for tlb miss
786*7c478bd9Sstevel@tonic-gate 	 * handling operations.  We align nalloc_base to a l2 cache
787*7c478bd9Sstevel@tonic-gate 	 * linesize because this is the line size the hardware uses to
788*7c478bd9Sstevel@tonic-gate 	 * maintain cache coherency.
789*7c478bd9Sstevel@tonic-gate 	 * 256K is carved out for module data.
790*7c478bd9Sstevel@tonic-gate 	 */
791*7c478bd9Sstevel@tonic-gate 
792*7c478bd9Sstevel@tonic-gate 	nalloc_base = (caddr_t)roundup((uintptr_t)e_data, MMU_PAGESIZE);
793*7c478bd9Sstevel@tonic-gate 	moddata = nalloc_base;
794*7c478bd9Sstevel@tonic-gate 	e_moddata = nalloc_base + MODDATA;
795*7c478bd9Sstevel@tonic-gate 	nalloc_base = e_moddata;
796*7c478bd9Sstevel@tonic-gate 
797*7c478bd9Sstevel@tonic-gate 	nalloc_end = (caddr_t)roundup((uintptr_t)nalloc_base, MMU_PAGESIZE4M);
798*7c478bd9Sstevel@tonic-gate 	valloc_base = nalloc_base;
799*7c478bd9Sstevel@tonic-gate 
800*7c478bd9Sstevel@tonic-gate 	/*
801*7c478bd9Sstevel@tonic-gate 	 * Calculate the start of the data segment.
802*7c478bd9Sstevel@tonic-gate 	 */
803*7c478bd9Sstevel@tonic-gate 	sdata = (caddr_t)((uintptr_t)e_data & MMU_PAGEMASK4M);
804*7c478bd9Sstevel@tonic-gate 
805*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(moddata);
806*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(nalloc_base);
807*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(nalloc_end);
808*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(sdata);
809*7c478bd9Sstevel@tonic-gate 
810*7c478bd9Sstevel@tonic-gate 	/*
811*7c478bd9Sstevel@tonic-gate 	 * Remember any slop after e_text so we can give it to the modules.
812*7c478bd9Sstevel@tonic-gate 	 */
813*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(e_text);
814*7c478bd9Sstevel@tonic-gate 	modtext = (caddr_t)roundup((uintptr_t)e_text, MMU_PAGESIZE);
815*7c478bd9Sstevel@tonic-gate 	if (((uintptr_t)modtext & MMU_PAGEMASK4M) != (uintptr_t)s_text)
816*7c478bd9Sstevel@tonic-gate 		panic("nucleus text overflow");
817*7c478bd9Sstevel@tonic-gate 	modtext_sz = (caddr_t)roundup((uintptr_t)modtext, MMU_PAGESIZE4M) -
818*7c478bd9Sstevel@tonic-gate 	    modtext;
819*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(modtext);
820*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(modtext_sz);
821*7c478bd9Sstevel@tonic-gate 
822*7c478bd9Sstevel@tonic-gate 	copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len,
823*7c478bd9Sstevel@tonic-gate 	    &boot_physavail, &boot_physavail_len,
824*7c478bd9Sstevel@tonic-gate 	    &boot_virtavail, &boot_virtavail_len);
825*7c478bd9Sstevel@tonic-gate 	/*
826*7c478bd9Sstevel@tonic-gate 	 * Remember what the physically available highest page is
827*7c478bd9Sstevel@tonic-gate 	 * so that dumpsys works properly, and find out how much
828*7c478bd9Sstevel@tonic-gate 	 * memory is installed.
829*7c478bd9Sstevel@tonic-gate 	 */
830*7c478bd9Sstevel@tonic-gate 	installed_top_size_memlist_array(boot_physinstalled,
831*7c478bd9Sstevel@tonic-gate 	    boot_physinstalled_len, &physmax, &physinstalled);
832*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(physinstalled);
833*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(physmax);
834*7c478bd9Sstevel@tonic-gate 
835*7c478bd9Sstevel@tonic-gate 	/* Fill out memory nodes config structure */
836*7c478bd9Sstevel@tonic-gate 	startup_build_mem_nodes(boot_physinstalled, boot_physinstalled_len);
837*7c478bd9Sstevel@tonic-gate 
838*7c478bd9Sstevel@tonic-gate 	/*
839*7c478bd9Sstevel@tonic-gate 	 * Get the list of physically available memory to size
840*7c478bd9Sstevel@tonic-gate 	 * the number of page structures needed.
841*7c478bd9Sstevel@tonic-gate 	 */
842*7c478bd9Sstevel@tonic-gate 	size_physavail(boot_physavail, boot_physavail_len, &npages, &memblocks);
843*7c478bd9Sstevel@tonic-gate 	/*
844*7c478bd9Sstevel@tonic-gate 	 * This first snap shot of npages can represent the pages used
845*7c478bd9Sstevel@tonic-gate 	 * by OBP's text and data approximately. This is used in the
846*7c478bd9Sstevel@tonic-gate 	 * the calculation of the kernel size
847*7c478bd9Sstevel@tonic-gate 	 */
848*7c478bd9Sstevel@tonic-gate 	obp_pages = physinstalled - npages;
849*7c478bd9Sstevel@tonic-gate 
850*7c478bd9Sstevel@tonic-gate 
851*7c478bd9Sstevel@tonic-gate 	/*
852*7c478bd9Sstevel@tonic-gate 	 * On small-memory systems (<MODTEXT_SM_SIZE MB, currently 256MB), the
853*7c478bd9Sstevel@tonic-gate 	 * in-nucleus module text is capped to MODTEXT_SM_CAP bytes (currently
854*7c478bd9Sstevel@tonic-gate 	 * 2MB) and any excess pages are put on physavail.  The assumption is
855*7c478bd9Sstevel@tonic-gate 	 * that small-memory systems will need more pages more than they'll
856*7c478bd9Sstevel@tonic-gate 	 * need efficiently-mapped module texts.
857*7c478bd9Sstevel@tonic-gate 	 */
858*7c478bd9Sstevel@tonic-gate 	if ((physinstalled < mmu_btop(MODTEXT_SM_SIZE << 20)) &&
859*7c478bd9Sstevel@tonic-gate 	    modtext_sz > MODTEXT_SM_CAP) {
860*7c478bd9Sstevel@tonic-gate 		extra_etpg = mmu_btop(modtext_sz - MODTEXT_SM_CAP);
861*7c478bd9Sstevel@tonic-gate 		modtext_sz = MODTEXT_SM_CAP;
862*7c478bd9Sstevel@tonic-gate 	} else
863*7c478bd9Sstevel@tonic-gate 		extra_etpg = 0;
864*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(extra_etpg);
865*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(modtext_sz);
866*7c478bd9Sstevel@tonic-gate 	extra_etva = modtext + modtext_sz;
867*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(extra_etva);
868*7c478bd9Sstevel@tonic-gate 
869*7c478bd9Sstevel@tonic-gate 	/*
870*7c478bd9Sstevel@tonic-gate 	 * Account for any pages after e_text and e_data.
871*7c478bd9Sstevel@tonic-gate 	 */
872*7c478bd9Sstevel@tonic-gate 	npages += extra_etpg;
873*7c478bd9Sstevel@tonic-gate 	npages += mmu_btopr(nalloc_end - nalloc_base);
874*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(npages);
875*7c478bd9Sstevel@tonic-gate 
876*7c478bd9Sstevel@tonic-gate 	/*
877*7c478bd9Sstevel@tonic-gate 	 * npages is the maximum of available physical memory possible.
878*7c478bd9Sstevel@tonic-gate 	 * (ie. it will never be more than this)
879*7c478bd9Sstevel@tonic-gate 	 */
880*7c478bd9Sstevel@tonic-gate 
881*7c478bd9Sstevel@tonic-gate 	/*
882*7c478bd9Sstevel@tonic-gate 	 * initialize the nucleus memory allocator.
883*7c478bd9Sstevel@tonic-gate 	 */
884*7c478bd9Sstevel@tonic-gate 	ndata_alloc_init(&ndata, (uintptr_t)nalloc_base, (uintptr_t)nalloc_end);
885*7c478bd9Sstevel@tonic-gate 
886*7c478bd9Sstevel@tonic-gate 	/*
887*7c478bd9Sstevel@tonic-gate 	 * Allocate mmu fault status area from the nucleus data area.
888*7c478bd9Sstevel@tonic-gate 	 */
889*7c478bd9Sstevel@tonic-gate 	if ((&ndata_alloc_mmfsa != NULL) && (ndata_alloc_mmfsa(&ndata) != 0))
890*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "no more nucleus memory after mfsa alloc");
891*7c478bd9Sstevel@tonic-gate 
892*7c478bd9Sstevel@tonic-gate 	/*
893*7c478bd9Sstevel@tonic-gate 	 * Allocate kernel TSBs from the nucleus data area.
894*7c478bd9Sstevel@tonic-gate 	 */
895*7c478bd9Sstevel@tonic-gate 	if (ndata_alloc_tsbs(&ndata, npages) != 0)
896*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "no more nucleus memory after tsbs alloc");
897*7c478bd9Sstevel@tonic-gate 
898*7c478bd9Sstevel@tonic-gate 	/*
899*7c478bd9Sstevel@tonic-gate 	 * Allocate cpus structs from the nucleus data area.
900*7c478bd9Sstevel@tonic-gate 	 */
901*7c478bd9Sstevel@tonic-gate 	if (ndata_alloc_cpus(&ndata) != 0)
902*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "no more nucleus memory after cpu alloc");
903*7c478bd9Sstevel@tonic-gate 
904*7c478bd9Sstevel@tonic-gate 	/*
905*7c478bd9Sstevel@tonic-gate 	 * Allocate dmv dispatch table from the nucleus data area.
906*7c478bd9Sstevel@tonic-gate 	 */
907*7c478bd9Sstevel@tonic-gate 	if (ndata_alloc_dmv(&ndata) != 0)
908*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "no more nucleus memory after dmv alloc");
909*7c478bd9Sstevel@tonic-gate 
910*7c478bd9Sstevel@tonic-gate 
911*7c478bd9Sstevel@tonic-gate 	page_coloring_init();
912*7c478bd9Sstevel@tonic-gate 
913*7c478bd9Sstevel@tonic-gate 	/*
914*7c478bd9Sstevel@tonic-gate 	 * Allocate page_freelists bin headers for memnode 0 from the
915*7c478bd9Sstevel@tonic-gate 	 * nucleus data area.
916*7c478bd9Sstevel@tonic-gate 	 */
917*7c478bd9Sstevel@tonic-gate 	if (ndata_alloc_page_freelists(&ndata, 0) != 0)
918*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC,
919*7c478bd9Sstevel@tonic-gate 		    "no more nucleus memory after page free lists alloc");
920*7c478bd9Sstevel@tonic-gate 
921*7c478bd9Sstevel@tonic-gate 	if (kpm_enable) {
922*7c478bd9Sstevel@tonic-gate 		kpm_init();
923*7c478bd9Sstevel@tonic-gate 		/*
924*7c478bd9Sstevel@tonic-gate 		 * kpm page space -- Update kpm_npages and make the
925*7c478bd9Sstevel@tonic-gate 		 * same assumption about fragmenting as it is done
926*7c478bd9Sstevel@tonic-gate 		 * for memseg_sz.
927*7c478bd9Sstevel@tonic-gate 		 */
928*7c478bd9Sstevel@tonic-gate 		kpm_npages_setup(memblocks + 4);
929*7c478bd9Sstevel@tonic-gate 	}
930*7c478bd9Sstevel@tonic-gate 
931*7c478bd9Sstevel@tonic-gate 	/*
932*7c478bd9Sstevel@tonic-gate 	 * Allocate hat related structs from the nucleus data area.
933*7c478bd9Sstevel@tonic-gate 	 */
934*7c478bd9Sstevel@tonic-gate 	if (ndata_alloc_hat(&ndata, npages, kpm_npages) != 0)
935*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "no more nucleus memory after hat alloc");
936*7c478bd9Sstevel@tonic-gate 
937*7c478bd9Sstevel@tonic-gate 	/*
938*7c478bd9Sstevel@tonic-gate 	 * We want to do the BOP_ALLOCs before the real allocation of page
939*7c478bd9Sstevel@tonic-gate 	 * structs in order to not have to allocate page structs for this
940*7c478bd9Sstevel@tonic-gate 	 * memory.  We need to calculate a virtual address because we want
941*7c478bd9Sstevel@tonic-gate 	 * the page structs to come before other allocations in virtual address
942*7c478bd9Sstevel@tonic-gate 	 * space.  This is so some (if not all) of page structs can actually
943*7c478bd9Sstevel@tonic-gate 	 * live in the nucleus.
944*7c478bd9Sstevel@tonic-gate 	 */
945*7c478bd9Sstevel@tonic-gate 
946*7c478bd9Sstevel@tonic-gate 	/*
947*7c478bd9Sstevel@tonic-gate 	 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING
948*7c478bd9Sstevel@tonic-gate 	 *
949*7c478bd9Sstevel@tonic-gate 	 * There are comments all over the SFMMU code warning of dire
950*7c478bd9Sstevel@tonic-gate 	 * consequences if the TSBs are moved out of 32-bit space.  This
951*7c478bd9Sstevel@tonic-gate 	 * is largely because the asm code uses "sethi %hi(addr)"-type
952*7c478bd9Sstevel@tonic-gate 	 * instructions which will not provide the expected result if the
953*7c478bd9Sstevel@tonic-gate 	 * address is a 64-bit one.
954*7c478bd9Sstevel@tonic-gate 	 *
955*7c478bd9Sstevel@tonic-gate 	 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING
956*7c478bd9Sstevel@tonic-gate 	 */
957*7c478bd9Sstevel@tonic-gate 	alloc_base = (caddr_t)roundup((uintptr_t)nalloc_end, MMU_PAGESIZE);
958*7c478bd9Sstevel@tonic-gate 	alloc_base = sfmmu_ktsb_alloc(alloc_base);
959*7c478bd9Sstevel@tonic-gate 	alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize);
960*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(alloc_base);
961*7c478bd9Sstevel@tonic-gate 
962*7c478bd9Sstevel@tonic-gate 	/*
963*7c478bd9Sstevel@tonic-gate 	 * Allocate IOMMU TSB array.  We do this here so that the physical
964*7c478bd9Sstevel@tonic-gate 	 * memory gets deducted from the PROM's physical memory list.
965*7c478bd9Sstevel@tonic-gate 	 */
966*7c478bd9Sstevel@tonic-gate 	alloc_base = iommu_tsb_init(alloc_base);
967*7c478bd9Sstevel@tonic-gate 	alloc_base = (caddr_t)roundup((uintptr_t)alloc_base,
968*7c478bd9Sstevel@tonic-gate 	    ecache_alignsize);
969*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(alloc_base);
970*7c478bd9Sstevel@tonic-gate 
971*7c478bd9Sstevel@tonic-gate 	/*
972*7c478bd9Sstevel@tonic-gate 	 * Starcat needs its special structures assigned in 32-bit virtual
973*7c478bd9Sstevel@tonic-gate 	 * address space because its probing routines execute FCode, and FCode
974*7c478bd9Sstevel@tonic-gate 	 * can't handle 64-bit virtual addresses...
975*7c478bd9Sstevel@tonic-gate 	 */
976*7c478bd9Sstevel@tonic-gate 	if (&starcat_startup_memlist) {
977*7c478bd9Sstevel@tonic-gate 		alloc_base = starcat_startup_memlist(alloc_base);
978*7c478bd9Sstevel@tonic-gate 		alloc_base = (caddr_t)roundup((uintptr_t)alloc_base,
979*7c478bd9Sstevel@tonic-gate 		    ecache_alignsize);
980*7c478bd9Sstevel@tonic-gate 		PRM_DEBUG(alloc_base);
981*7c478bd9Sstevel@tonic-gate 	}
982*7c478bd9Sstevel@tonic-gate 
983*7c478bd9Sstevel@tonic-gate 	/*
984*7c478bd9Sstevel@tonic-gate 	 * If we have enough memory, use 4M pages for alignment because it
985*7c478bd9Sstevel@tonic-gate 	 * greatly reduces the number of TLB misses we take albeit at the cost
986*7c478bd9Sstevel@tonic-gate 	 * of possible RAM wastage (degenerate case of 4 MB - MMU_PAGESIZE per
987*7c478bd9Sstevel@tonic-gate 	 * allocation.) Still, the speedup on large memory systems (e.g. > 64
988*7c478bd9Sstevel@tonic-gate 	 * GB) is quite noticeable, so it is worth the effort to do if we can.
989*7c478bd9Sstevel@tonic-gate 	 *
990*7c478bd9Sstevel@tonic-gate 	 * Note, however, that this speedup will only occur if the boot PROM
991*7c478bd9Sstevel@tonic-gate 	 * uses the largest possible MMU page size possible to map memory
992*7c478bd9Sstevel@tonic-gate 	 * requests that are properly aligned and sized (for example, a request
993*7c478bd9Sstevel@tonic-gate 	 * for a multiple of 4MB of memory aligned to a 4MB boundary will
994*7c478bd9Sstevel@tonic-gate 	 * result in a mapping using a 4MB MMU page.)
995*7c478bd9Sstevel@tonic-gate 	 *
996*7c478bd9Sstevel@tonic-gate 	 * Even then, the large page mappings will only speed things up until
997*7c478bd9Sstevel@tonic-gate 	 * the startup process proceeds a bit further, as when
998*7c478bd9Sstevel@tonic-gate 	 * sfmmu_map_prom_mappings() copies page mappings from the PROM to the
999*7c478bd9Sstevel@tonic-gate 	 * kernel it remaps everything but the TSBs using 8K pages anyway...
1000*7c478bd9Sstevel@tonic-gate 	 *
1001*7c478bd9Sstevel@tonic-gate 	 * At some point in the future, sfmmu_map_prom_mappings() will be
1002*7c478bd9Sstevel@tonic-gate 	 * rewritten to copy memory mappings to the kernel using the same MMU
1003*7c478bd9Sstevel@tonic-gate 	 * page sizes the PROM used.  When that occurs, if the PROM did use
1004*7c478bd9Sstevel@tonic-gate 	 * large MMU pages to map memory, the alignment/sizing work we're
1005*7c478bd9Sstevel@tonic-gate 	 * doing now should give us a nice extra performance boost, albeit at
1006*7c478bd9Sstevel@tonic-gate 	 * the cost of greater RAM usage...
1007*7c478bd9Sstevel@tonic-gate 	 */
1008*7c478bd9Sstevel@tonic-gate 	alloc_alignsize = ((npages >= tune_npages) ? MMU_PAGESIZE4M :
1009*7c478bd9Sstevel@tonic-gate 	    MMU_PAGESIZE);
1010*7c478bd9Sstevel@tonic-gate 
1011*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(tune_npages);
1012*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(alloc_alignsize);
1013*7c478bd9Sstevel@tonic-gate 
1014*7c478bd9Sstevel@tonic-gate 	/*
1015*7c478bd9Sstevel@tonic-gate 	 * Save off where the contiguous allocations to date have ended
1016*7c478bd9Sstevel@tonic-gate 	 * in econtig32.
1017*7c478bd9Sstevel@tonic-gate 	 */
1018*7c478bd9Sstevel@tonic-gate 	econtig32 = alloc_base;
1019*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(econtig32);
1020*7c478bd9Sstevel@tonic-gate 
1021*7c478bd9Sstevel@tonic-gate 	if (econtig32 > (caddr_t)KERNEL_LIMIT32)
1022*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "econtig32 too big");
1023*7c478bd9Sstevel@tonic-gate 
1024*7c478bd9Sstevel@tonic-gate 	/*
1025*7c478bd9Sstevel@tonic-gate 	 * To avoid memory allocation collisions in the 32-bit virtual address
1026*7c478bd9Sstevel@tonic-gate 	 * space, make allocations from this point forward in 64-bit virtual
1027*7c478bd9Sstevel@tonic-gate 	 * address space starting at syslimit and working up.  Also use the
1028*7c478bd9Sstevel@tonic-gate 	 * alignment specified by alloc_alignsize, as we may be able to save
1029*7c478bd9Sstevel@tonic-gate 	 * ourselves TLB misses by using larger page sizes if they're
1030*7c478bd9Sstevel@tonic-gate 	 * available.
1031*7c478bd9Sstevel@tonic-gate 	 *
1032*7c478bd9Sstevel@tonic-gate 	 * All this is needed because on large memory systems, the default
1033*7c478bd9Sstevel@tonic-gate 	 * Solaris allocations will collide with SYSBASE32, which is hard
1034*7c478bd9Sstevel@tonic-gate 	 * coded to be at the virtual address 0x78000000.  Therefore, on 64-bit
1035*7c478bd9Sstevel@tonic-gate 	 * kernels, move the allocations to a location in the 64-bit virtual
1036*7c478bd9Sstevel@tonic-gate 	 * address space space, allowing those structures to grow without
1037*7c478bd9Sstevel@tonic-gate 	 * worry.
1038*7c478bd9Sstevel@tonic-gate 	 *
1039*7c478bd9Sstevel@tonic-gate 	 * On current CPUs we'll run out of physical memory address bits before
1040*7c478bd9Sstevel@tonic-gate 	 * we need to worry about the allocations running into anything else in
1041*7c478bd9Sstevel@tonic-gate 	 * VM or the virtual address holes on US-I and II, as there's currently
1042*7c478bd9Sstevel@tonic-gate 	 * about 1 TB of addressable space before the US-I/II VA hole.
1043*7c478bd9Sstevel@tonic-gate 	 */
1044*7c478bd9Sstevel@tonic-gate 	kmem64_base = (caddr_t)syslimit;
1045*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(kmem64_base);
1046*7c478bd9Sstevel@tonic-gate 
1047*7c478bd9Sstevel@tonic-gate 	alloc_base = (caddr_t)roundup((uintptr_t)kmem64_base, alloc_alignsize);
1048*7c478bd9Sstevel@tonic-gate 
1049*7c478bd9Sstevel@tonic-gate 	/*
1050*7c478bd9Sstevel@tonic-gate 	 * If KHME and/or UHME hash buckets won't fit in the nucleus, allocate
1051*7c478bd9Sstevel@tonic-gate 	 * them here.
1052*7c478bd9Sstevel@tonic-gate 	 */
1053*7c478bd9Sstevel@tonic-gate 	if (khme_hash == NULL || uhme_hash == NULL) {
1054*7c478bd9Sstevel@tonic-gate 		/*
1055*7c478bd9Sstevel@tonic-gate 		 * alloc_hme_buckets() will align alloc_base properly before
1056*7c478bd9Sstevel@tonic-gate 		 * assigning the hash buckets, so we don't need to do it
1057*7c478bd9Sstevel@tonic-gate 		 * before the call...
1058*7c478bd9Sstevel@tonic-gate 		 */
1059*7c478bd9Sstevel@tonic-gate 		alloc_base = alloc_hme_buckets(alloc_base, alloc_alignsize);
1060*7c478bd9Sstevel@tonic-gate 
1061*7c478bd9Sstevel@tonic-gate 		PRM_DEBUG(alloc_base);
1062*7c478bd9Sstevel@tonic-gate 		PRM_DEBUG(khme_hash);
1063*7c478bd9Sstevel@tonic-gate 		PRM_DEBUG(uhme_hash);
1064*7c478bd9Sstevel@tonic-gate 	}
1065*7c478bd9Sstevel@tonic-gate 
1066*7c478bd9Sstevel@tonic-gate 	/*
1067*7c478bd9Sstevel@tonic-gate 	 * Allocate the remaining page freelists.  NUMA systems can
1068*7c478bd9Sstevel@tonic-gate 	 * have lots of page freelists, one per node, which quickly
1069*7c478bd9Sstevel@tonic-gate 	 * outgrow the amount of nucleus memory available.
1070*7c478bd9Sstevel@tonic-gate 	 */
1071*7c478bd9Sstevel@tonic-gate 	if (max_mem_nodes > 1) {
1072*7c478bd9Sstevel@tonic-gate 		int mnode;
1073*7c478bd9Sstevel@tonic-gate 		caddr_t alloc_start = alloc_base;
1074*7c478bd9Sstevel@tonic-gate 
1075*7c478bd9Sstevel@tonic-gate 		for (mnode = 1; mnode < max_mem_nodes; mnode++) {
1076*7c478bd9Sstevel@tonic-gate 			alloc_base = alloc_page_freelists(mnode, alloc_base,
1077*7c478bd9Sstevel@tonic-gate 				ecache_alignsize);
1078*7c478bd9Sstevel@tonic-gate 		}
1079*7c478bd9Sstevel@tonic-gate 
1080*7c478bd9Sstevel@tonic-gate 		if (alloc_base > alloc_start) {
1081*7c478bd9Sstevel@tonic-gate 			alloc_base = (caddr_t)roundup((uintptr_t)alloc_base,
1082*7c478bd9Sstevel@tonic-gate 				alloc_alignsize);
1083*7c478bd9Sstevel@tonic-gate 			if ((caddr_t)BOP_ALLOC(bootops, alloc_start,
1084*7c478bd9Sstevel@tonic-gate 				alloc_base - alloc_start,
1085*7c478bd9Sstevel@tonic-gate 				alloc_alignsize) != alloc_start)
1086*7c478bd9Sstevel@tonic-gate 				cmn_err(CE_PANIC,
1087*7c478bd9Sstevel@tonic-gate 					"Unable to alloc page freelists\n");
1088*7c478bd9Sstevel@tonic-gate 		}
1089*7c478bd9Sstevel@tonic-gate 
1090*7c478bd9Sstevel@tonic-gate 		PRM_DEBUG(alloc_base);
1091*7c478bd9Sstevel@tonic-gate 	}
1092*7c478bd9Sstevel@tonic-gate 
1093*7c478bd9Sstevel@tonic-gate 	if (!mml_table) {
1094*7c478bd9Sstevel@tonic-gate 		size_t mmltable_sz;
1095*7c478bd9Sstevel@tonic-gate 
1096*7c478bd9Sstevel@tonic-gate 		/*
1097*7c478bd9Sstevel@tonic-gate 		 * We need to allocate the mml_table here because there
1098*7c478bd9Sstevel@tonic-gate 		 * was not enough space within the nucleus.
1099*7c478bd9Sstevel@tonic-gate 		 */
1100*7c478bd9Sstevel@tonic-gate 		mmltable_sz = sizeof (kmutex_t) * mml_table_sz;
1101*7c478bd9Sstevel@tonic-gate 		alloc_sz = roundup(mmltable_sz, alloc_alignsize);
1102*7c478bd9Sstevel@tonic-gate 		alloc_base = (caddr_t)roundup((uintptr_t)alloc_base,
1103*7c478bd9Sstevel@tonic-gate 		    alloc_alignsize);
1104*7c478bd9Sstevel@tonic-gate 
1105*7c478bd9Sstevel@tonic-gate 		if ((mml_table = (kmutex_t *)BOP_ALLOC(bootops, alloc_base,
1106*7c478bd9Sstevel@tonic-gate 		    alloc_sz, alloc_alignsize)) != (kmutex_t *)alloc_base)
1107*7c478bd9Sstevel@tonic-gate 			panic("mml_table alloc failure");
1108*7c478bd9Sstevel@tonic-gate 
1109*7c478bd9Sstevel@tonic-gate 		alloc_base += alloc_sz;
1110*7c478bd9Sstevel@tonic-gate 		PRM_DEBUG(mml_table);
1111*7c478bd9Sstevel@tonic-gate 		PRM_DEBUG(alloc_base);
1112*7c478bd9Sstevel@tonic-gate 	}
1113*7c478bd9Sstevel@tonic-gate 
1114*7c478bd9Sstevel@tonic-gate 	if (kpm_enable && !(kpmp_table || kpmp_stable)) {
1115*7c478bd9Sstevel@tonic-gate 		size_t kpmptable_sz;
1116*7c478bd9Sstevel@tonic-gate 		caddr_t table;
1117*7c478bd9Sstevel@tonic-gate 
1118*7c478bd9Sstevel@tonic-gate 		/*
1119*7c478bd9Sstevel@tonic-gate 		 * We need to allocate either kpmp_table or kpmp_stable here
1120*7c478bd9Sstevel@tonic-gate 		 * because there was not enough space within the nucleus.
1121*7c478bd9Sstevel@tonic-gate 		 */
1122*7c478bd9Sstevel@tonic-gate 		kpmptable_sz = (kpm_smallpages == 0) ?
1123*7c478bd9Sstevel@tonic-gate 				sizeof (kpm_hlk_t) * kpmp_table_sz :
1124*7c478bd9Sstevel@tonic-gate 				sizeof (kpm_shlk_t) * kpmp_stable_sz;
1125*7c478bd9Sstevel@tonic-gate 
1126*7c478bd9Sstevel@tonic-gate 		alloc_sz = roundup(kpmptable_sz, alloc_alignsize);
1127*7c478bd9Sstevel@tonic-gate 		alloc_base = (caddr_t)roundup((uintptr_t)alloc_base,
1128*7c478bd9Sstevel@tonic-gate 		    alloc_alignsize);
1129*7c478bd9Sstevel@tonic-gate 
1130*7c478bd9Sstevel@tonic-gate 		table = BOP_ALLOC(bootops, alloc_base, alloc_sz,
1131*7c478bd9Sstevel@tonic-gate 				alloc_alignsize);
1132*7c478bd9Sstevel@tonic-gate 
1133*7c478bd9Sstevel@tonic-gate 		if (table != alloc_base)
1134*7c478bd9Sstevel@tonic-gate 			panic("kpmp_table or kpmp_stable alloc failure");
1135*7c478bd9Sstevel@tonic-gate 
1136*7c478bd9Sstevel@tonic-gate 		if (kpm_smallpages == 0) {
1137*7c478bd9Sstevel@tonic-gate 			kpmp_table = (kpm_hlk_t *)table;
1138*7c478bd9Sstevel@tonic-gate 			PRM_DEBUG(kpmp_table);
1139*7c478bd9Sstevel@tonic-gate 		} else {
1140*7c478bd9Sstevel@tonic-gate 			kpmp_stable = (kpm_shlk_t *)table;
1141*7c478bd9Sstevel@tonic-gate 			PRM_DEBUG(kpmp_stable);
1142*7c478bd9Sstevel@tonic-gate 		}
1143*7c478bd9Sstevel@tonic-gate 
1144*7c478bd9Sstevel@tonic-gate 		alloc_base += alloc_sz;
1145*7c478bd9Sstevel@tonic-gate 		PRM_DEBUG(alloc_base);
1146*7c478bd9Sstevel@tonic-gate 	}
1147*7c478bd9Sstevel@tonic-gate 
1148*7c478bd9Sstevel@tonic-gate 	if (&ecache_init_scrub_flush_area) {
1149*7c478bd9Sstevel@tonic-gate 		/*
1150*7c478bd9Sstevel@tonic-gate 		 * Pass alloc_base directly, as the routine itself is
1151*7c478bd9Sstevel@tonic-gate 		 * responsible for any special alignment requirements...
1152*7c478bd9Sstevel@tonic-gate 		 */
1153*7c478bd9Sstevel@tonic-gate 		alloc_base = ecache_init_scrub_flush_area(alloc_base);
1154*7c478bd9Sstevel@tonic-gate 		PRM_DEBUG(alloc_base);
1155*7c478bd9Sstevel@tonic-gate 	}
1156*7c478bd9Sstevel@tonic-gate 
1157*7c478bd9Sstevel@tonic-gate 	/*
1158*7c478bd9Sstevel@tonic-gate 	 * Take the most current snapshot we can by calling mem-update.
1159*7c478bd9Sstevel@tonic-gate 	 */
1160*7c478bd9Sstevel@tonic-gate 	copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len,
1161*7c478bd9Sstevel@tonic-gate 	    &boot_physavail, &boot_physavail_len,
1162*7c478bd9Sstevel@tonic-gate 	    &boot_virtavail, &boot_virtavail_len);
1163*7c478bd9Sstevel@tonic-gate 
1164*7c478bd9Sstevel@tonic-gate 	/*
1165*7c478bd9Sstevel@tonic-gate 	 * Reset npages and memblocks based on boot_physavail list.
1166*7c478bd9Sstevel@tonic-gate 	 */
1167*7c478bd9Sstevel@tonic-gate 	size_physavail(boot_physavail, boot_physavail_len, &npages, &memblocks);
1168*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(npages);
1169*7c478bd9Sstevel@tonic-gate 
1170*7c478bd9Sstevel@tonic-gate 	/*
1171*7c478bd9Sstevel@tonic-gate 	 * Account for extra memory after e_text.
1172*7c478bd9Sstevel@tonic-gate 	 */
1173*7c478bd9Sstevel@tonic-gate 	npages += extra_etpg;
1174*7c478bd9Sstevel@tonic-gate 
1175*7c478bd9Sstevel@tonic-gate 	/*
1176*7c478bd9Sstevel@tonic-gate 	 * Calculate the largest free memory chunk in the nucleus data area.
1177*7c478bd9Sstevel@tonic-gate 	 * We need to figure out if page structs can fit in there or not.
1178*7c478bd9Sstevel@tonic-gate 	 * We also make sure enough page structs get created for any physical
1179*7c478bd9Sstevel@tonic-gate 	 * memory we might be returning to the system.
1180*7c478bd9Sstevel@tonic-gate 	 */
1181*7c478bd9Sstevel@tonic-gate 	ndata_remain_sz = ndata_maxsize(&ndata);
1182*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(ndata_remain_sz);
1183*7c478bd9Sstevel@tonic-gate 
1184*7c478bd9Sstevel@tonic-gate 	pp_sz = sizeof (struct page) * npages;
1185*7c478bd9Sstevel@tonic-gate 
1186*7c478bd9Sstevel@tonic-gate 	/*
1187*7c478bd9Sstevel@tonic-gate 	 * Here's a nice bit of code based on somewhat recursive logic:
1188*7c478bd9Sstevel@tonic-gate 	 *
1189*7c478bd9Sstevel@tonic-gate 	 * If the page array would fit within the nucleus, we want to
1190*7c478bd9Sstevel@tonic-gate 	 * add npages to cover any extra memory we may be returning back
1191*7c478bd9Sstevel@tonic-gate 	 * to the system.
1192*7c478bd9Sstevel@tonic-gate 	 *
1193*7c478bd9Sstevel@tonic-gate 	 * HOWEVER, the page array is sized by calculating the size of
1194*7c478bd9Sstevel@tonic-gate 	 * (struct page * npages), as are the pagehash table, ctrs and
1195*7c478bd9Sstevel@tonic-gate 	 * memseg_list, so the very act of performing the calculation below may
1196*7c478bd9Sstevel@tonic-gate 	 * in fact make the array large enough that it no longer fits in the
1197*7c478bd9Sstevel@tonic-gate 	 * nucleus, meaning there would now be a much larger area of the
1198*7c478bd9Sstevel@tonic-gate 	 * nucleus free that should really be added to npages, which would
1199*7c478bd9Sstevel@tonic-gate 	 * make the page array that much larger, and so on.
1200*7c478bd9Sstevel@tonic-gate 	 *
1201*7c478bd9Sstevel@tonic-gate 	 * This also ignores the memory possibly used in the nucleus for the
1202*7c478bd9Sstevel@tonic-gate 	 * the page hash, ctrs and memseg list and the fact that whether they
1203*7c478bd9Sstevel@tonic-gate 	 * fit there or not varies with the npages calculation below, but we
1204*7c478bd9Sstevel@tonic-gate 	 * don't even factor them into the equation at this point; perhaps we
1205*7c478bd9Sstevel@tonic-gate 	 * should or perhaps we should just take the approach that the few
1206*7c478bd9Sstevel@tonic-gate 	 * extra pages we could add via this calculation REALLY aren't worth
1207*7c478bd9Sstevel@tonic-gate 	 * the hassle...
1208*7c478bd9Sstevel@tonic-gate 	 */
1209*7c478bd9Sstevel@tonic-gate 	if (ndata_remain_sz > pp_sz) {
1210*7c478bd9Sstevel@tonic-gate 		size_t spare = ndata_spare(&ndata, pp_sz, ecache_alignsize);
1211*7c478bd9Sstevel@tonic-gate 
1212*7c478bd9Sstevel@tonic-gate 		npages += mmu_btop(spare);
1213*7c478bd9Sstevel@tonic-gate 
1214*7c478bd9Sstevel@tonic-gate 		pp_sz = npages * sizeof (struct page);
1215*7c478bd9Sstevel@tonic-gate 
1216*7c478bd9Sstevel@tonic-gate 		pp_base = ndata_alloc(&ndata, pp_sz, ecache_alignsize);
1217*7c478bd9Sstevel@tonic-gate 	}
1218*7c478bd9Sstevel@tonic-gate 
1219*7c478bd9Sstevel@tonic-gate 	/*
1220*7c478bd9Sstevel@tonic-gate 	 * If physmem is patched to be non-zero, use it instead of
1221*7c478bd9Sstevel@tonic-gate 	 * the monitor value unless physmem is larger than the total
1222*7c478bd9Sstevel@tonic-gate 	 * amount of memory on hand.
1223*7c478bd9Sstevel@tonic-gate 	 */
1224*7c478bd9Sstevel@tonic-gate 	if (physmem == 0 || physmem > npages)
1225*7c478bd9Sstevel@tonic-gate 		physmem = npages;
1226*7c478bd9Sstevel@tonic-gate 
1227*7c478bd9Sstevel@tonic-gate 	/*
1228*7c478bd9Sstevel@tonic-gate 	 * If pp_base is NULL that means the routines above have determined
1229*7c478bd9Sstevel@tonic-gate 	 * the page array will not fit in the nucleus; we'll have to
1230*7c478bd9Sstevel@tonic-gate 	 * BOP_ALLOC() ourselves some space for them.
1231*7c478bd9Sstevel@tonic-gate 	 */
1232*7c478bd9Sstevel@tonic-gate 	if (pp_base == NULL) {
1233*7c478bd9Sstevel@tonic-gate 		alloc_base = (caddr_t)roundup((uintptr_t)alloc_base,
1234*7c478bd9Sstevel@tonic-gate 		    alloc_alignsize);
1235*7c478bd9Sstevel@tonic-gate 
1236*7c478bd9Sstevel@tonic-gate 		alloc_sz = roundup(pp_sz, alloc_alignsize);
1237*7c478bd9Sstevel@tonic-gate 
1238*7c478bd9Sstevel@tonic-gate 		if ((pp_base = (struct page *)BOP_ALLOC(bootops,
1239*7c478bd9Sstevel@tonic-gate 		    alloc_base, alloc_sz, alloc_alignsize)) !=
1240*7c478bd9Sstevel@tonic-gate 		    (struct page *)alloc_base)
1241*7c478bd9Sstevel@tonic-gate 			panic("page alloc failure");
1242*7c478bd9Sstevel@tonic-gate 
1243*7c478bd9Sstevel@tonic-gate 		alloc_base += alloc_sz;
1244*7c478bd9Sstevel@tonic-gate 	}
1245*7c478bd9Sstevel@tonic-gate 
1246*7c478bd9Sstevel@tonic-gate 	/*
1247*7c478bd9Sstevel@tonic-gate 	 * The page structure hash table size is a power of 2
1248*7c478bd9Sstevel@tonic-gate 	 * such that the average hash chain length is PAGE_HASHAVELEN.
1249*7c478bd9Sstevel@tonic-gate 	 */
1250*7c478bd9Sstevel@tonic-gate 	page_hashsz = npages / PAGE_HASHAVELEN;
1251*7c478bd9Sstevel@tonic-gate 	page_hashsz = 1 << highbit((ulong_t)page_hashsz);
1252*7c478bd9Sstevel@tonic-gate 	pagehash_sz = sizeof (struct page *) * page_hashsz;
1253*7c478bd9Sstevel@tonic-gate 
1254*7c478bd9Sstevel@tonic-gate 	/*
1255*7c478bd9Sstevel@tonic-gate 	 * We want to TRY to fit the page structure hash table,
1256*7c478bd9Sstevel@tonic-gate 	 * the page size free list counters, the memseg list and
1257*7c478bd9Sstevel@tonic-gate 	 * and the kpm page space in the nucleus if possible.
1258*7c478bd9Sstevel@tonic-gate 	 *
1259*7c478bd9Sstevel@tonic-gate 	 * alloc_sz counts how much memory needs to be allocated by
1260*7c478bd9Sstevel@tonic-gate 	 * BOP_ALLOC().
1261*7c478bd9Sstevel@tonic-gate 	 */
1262*7c478bd9Sstevel@tonic-gate 	page_hash = ndata_alloc(&ndata, pagehash_sz, ecache_alignsize);
1263*7c478bd9Sstevel@tonic-gate 
1264*7c478bd9Sstevel@tonic-gate 	alloc_sz = (page_hash == NULL ? pagehash_sz : 0);
1265*7c478bd9Sstevel@tonic-gate 
1266*7c478bd9Sstevel@tonic-gate 	/*
1267*7c478bd9Sstevel@tonic-gate 	 * Size up per page size free list counters.
1268*7c478bd9Sstevel@tonic-gate 	 */
1269*7c478bd9Sstevel@tonic-gate 	ctrs_sz = page_ctrs_sz();
1270*7c478bd9Sstevel@tonic-gate 	ctrs_base = ndata_alloc(&ndata, ctrs_sz, ecache_alignsize);
1271*7c478bd9Sstevel@tonic-gate 
1272*7c478bd9Sstevel@tonic-gate 	if (ctrs_base == NULL)
1273*7c478bd9Sstevel@tonic-gate 		alloc_sz = roundup(alloc_sz, ecache_alignsize) + ctrs_sz;
1274*7c478bd9Sstevel@tonic-gate 
1275*7c478bd9Sstevel@tonic-gate 	/*
1276*7c478bd9Sstevel@tonic-gate 	 * The memseg list is for the chunks of physical memory that
1277*7c478bd9Sstevel@tonic-gate 	 * will be managed by the vm system.  The number calculated is
1278*7c478bd9Sstevel@tonic-gate 	 * a guess as boot may fragment it more when memory allocations
1279*7c478bd9Sstevel@tonic-gate 	 * are made before kphysm_init().  Currently, there are two
1280*7c478bd9Sstevel@tonic-gate 	 * allocations before then, so we assume each causes fragmen-
1281*7c478bd9Sstevel@tonic-gate 	 * tation, and add a couple more for good measure.
1282*7c478bd9Sstevel@tonic-gate 	 */
1283*7c478bd9Sstevel@tonic-gate 	memseg_sz = sizeof (struct memseg) * (memblocks + 4);
1284*7c478bd9Sstevel@tonic-gate 	memseg_base = ndata_alloc(&ndata, memseg_sz, ecache_alignsize);
1285*7c478bd9Sstevel@tonic-gate 
1286*7c478bd9Sstevel@tonic-gate 	if (memseg_base == NULL)
1287*7c478bd9Sstevel@tonic-gate 		alloc_sz = roundup(alloc_sz, ecache_alignsize) + memseg_sz;
1288*7c478bd9Sstevel@tonic-gate 
1289*7c478bd9Sstevel@tonic-gate 
1290*7c478bd9Sstevel@tonic-gate 	if (kpm_enable) {
1291*7c478bd9Sstevel@tonic-gate 		/*
1292*7c478bd9Sstevel@tonic-gate 		 * kpm page space -- Update kpm_npages and make the
1293*7c478bd9Sstevel@tonic-gate 		 * same assumption about fragmenting as it is done
1294*7c478bd9Sstevel@tonic-gate 		 * for memseg_sz above.
1295*7c478bd9Sstevel@tonic-gate 		 */
1296*7c478bd9Sstevel@tonic-gate 		kpm_npages_setup(memblocks + 4);
1297*7c478bd9Sstevel@tonic-gate 		kpm_pp_sz = (kpm_smallpages == 0) ?
1298*7c478bd9Sstevel@tonic-gate 				kpm_npages * sizeof (kpm_page_t):
1299*7c478bd9Sstevel@tonic-gate 				kpm_npages * sizeof (kpm_spage_t);
1300*7c478bd9Sstevel@tonic-gate 
1301*7c478bd9Sstevel@tonic-gate 		kpm_pp_base = (uintptr_t)ndata_alloc(&ndata, kpm_pp_sz,
1302*7c478bd9Sstevel@tonic-gate 		    ecache_alignsize);
1303*7c478bd9Sstevel@tonic-gate 
1304*7c478bd9Sstevel@tonic-gate 		if (kpm_pp_base == NULL)
1305*7c478bd9Sstevel@tonic-gate 			alloc_sz = roundup(alloc_sz, ecache_alignsize) +
1306*7c478bd9Sstevel@tonic-gate 			    kpm_pp_sz;
1307*7c478bd9Sstevel@tonic-gate 	}
1308*7c478bd9Sstevel@tonic-gate 
1309*7c478bd9Sstevel@tonic-gate 	if (alloc_sz > 0) {
1310*7c478bd9Sstevel@tonic-gate 		uintptr_t bop_base;
1311*7c478bd9Sstevel@tonic-gate 
1312*7c478bd9Sstevel@tonic-gate 		/*
1313*7c478bd9Sstevel@tonic-gate 		 * We need extra memory allocated through BOP_ALLOC.
1314*7c478bd9Sstevel@tonic-gate 		 */
1315*7c478bd9Sstevel@tonic-gate 		alloc_base = (caddr_t)roundup((uintptr_t)alloc_base,
1316*7c478bd9Sstevel@tonic-gate 		    alloc_alignsize);
1317*7c478bd9Sstevel@tonic-gate 
1318*7c478bd9Sstevel@tonic-gate 		alloc_sz = roundup(alloc_sz, alloc_alignsize);
1319*7c478bd9Sstevel@tonic-gate 
1320*7c478bd9Sstevel@tonic-gate 		if ((bop_base = (uintptr_t)BOP_ALLOC(bootops, alloc_base,
1321*7c478bd9Sstevel@tonic-gate 		    alloc_sz, alloc_alignsize)) != (uintptr_t)alloc_base)
1322*7c478bd9Sstevel@tonic-gate 			panic("system page struct alloc failure");
1323*7c478bd9Sstevel@tonic-gate 
1324*7c478bd9Sstevel@tonic-gate 		alloc_base += alloc_sz;
1325*7c478bd9Sstevel@tonic-gate 
1326*7c478bd9Sstevel@tonic-gate 		if (page_hash == NULL) {
1327*7c478bd9Sstevel@tonic-gate 			page_hash = (struct page **)bop_base;
1328*7c478bd9Sstevel@tonic-gate 			bop_base = roundup(bop_base + pagehash_sz,
1329*7c478bd9Sstevel@tonic-gate 			    ecache_alignsize);
1330*7c478bd9Sstevel@tonic-gate 		}
1331*7c478bd9Sstevel@tonic-gate 
1332*7c478bd9Sstevel@tonic-gate 		if (ctrs_base == NULL) {
1333*7c478bd9Sstevel@tonic-gate 			ctrs_base = (caddr_t)bop_base;
1334*7c478bd9Sstevel@tonic-gate 			bop_base = roundup(bop_base + ctrs_sz,
1335*7c478bd9Sstevel@tonic-gate 			    ecache_alignsize);
1336*7c478bd9Sstevel@tonic-gate 		}
1337*7c478bd9Sstevel@tonic-gate 
1338*7c478bd9Sstevel@tonic-gate 		if (memseg_base == NULL) {
1339*7c478bd9Sstevel@tonic-gate 			memseg_base = (struct memseg *)bop_base;
1340*7c478bd9Sstevel@tonic-gate 			bop_base = roundup(bop_base + memseg_sz,
1341*7c478bd9Sstevel@tonic-gate 			    ecache_alignsize);
1342*7c478bd9Sstevel@tonic-gate 		}
1343*7c478bd9Sstevel@tonic-gate 
1344*7c478bd9Sstevel@tonic-gate 		if (kpm_enable && kpm_pp_base == NULL) {
1345*7c478bd9Sstevel@tonic-gate 			kpm_pp_base = (uintptr_t)bop_base;
1346*7c478bd9Sstevel@tonic-gate 			bop_base = roundup(bop_base + kpm_pp_sz,
1347*7c478bd9Sstevel@tonic-gate 			    ecache_alignsize);
1348*7c478bd9Sstevel@tonic-gate 		}
1349*7c478bd9Sstevel@tonic-gate 
1350*7c478bd9Sstevel@tonic-gate 		ASSERT(bop_base <= (uintptr_t)alloc_base);
1351*7c478bd9Sstevel@tonic-gate 	}
1352*7c478bd9Sstevel@tonic-gate 
1353*7c478bd9Sstevel@tonic-gate 	/*
1354*7c478bd9Sstevel@tonic-gate 	 * Initialize per page size free list counters.
1355*7c478bd9Sstevel@tonic-gate 	 */
1356*7c478bd9Sstevel@tonic-gate 	ctrs_end = page_ctrs_alloc(ctrs_base);
1357*7c478bd9Sstevel@tonic-gate 	ASSERT(ctrs_base + ctrs_sz >= ctrs_end);
1358*7c478bd9Sstevel@tonic-gate 
1359*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(page_hash);
1360*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(memseg_base);
1361*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(kpm_pp_base);
1362*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(kpm_pp_sz);
1363*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(pp_base);
1364*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(pp_sz);
1365*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(alloc_base);
1366*7c478bd9Sstevel@tonic-gate 
1367*7c478bd9Sstevel@tonic-gate #ifdef	TRAPTRACE
1368*7c478bd9Sstevel@tonic-gate 	/*
1369*7c478bd9Sstevel@tonic-gate 	 * Allocate trap trace buffer last so as not to affect
1370*7c478bd9Sstevel@tonic-gate 	 * the 4M alignments of the allocations above on V9 SPARCs...
1371*7c478bd9Sstevel@tonic-gate 	 */
1372*7c478bd9Sstevel@tonic-gate 	alloc_base = trap_trace_alloc(alloc_base);
1373*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(alloc_base);
1374*7c478bd9Sstevel@tonic-gate #endif	/* TRAPTRACE */
1375*7c478bd9Sstevel@tonic-gate 
1376*7c478bd9Sstevel@tonic-gate 	if (kmem64_base) {
1377*7c478bd9Sstevel@tonic-gate 		/*
1378*7c478bd9Sstevel@tonic-gate 		 * Set the end of the kmem64 segment for V9 SPARCs, if
1379*7c478bd9Sstevel@tonic-gate 		 * appropriate...
1380*7c478bd9Sstevel@tonic-gate 		 */
1381*7c478bd9Sstevel@tonic-gate 		kmem64_end = (caddr_t)roundup((uintptr_t)alloc_base,
1382*7c478bd9Sstevel@tonic-gate 		    alloc_alignsize);
1383*7c478bd9Sstevel@tonic-gate 
1384*7c478bd9Sstevel@tonic-gate 		PRM_DEBUG(kmem64_base);
1385*7c478bd9Sstevel@tonic-gate 		PRM_DEBUG(kmem64_end);
1386*7c478bd9Sstevel@tonic-gate 	}
1387*7c478bd9Sstevel@tonic-gate 
1388*7c478bd9Sstevel@tonic-gate 	/*
1389*7c478bd9Sstevel@tonic-gate 	 * Allocate space for the interrupt vector table.
1390*7c478bd9Sstevel@tonic-gate 	 */
1391*7c478bd9Sstevel@tonic-gate 	memspace = (caddr_t)BOP_ALLOC(bootops, (caddr_t)intr_vector,
1392*7c478bd9Sstevel@tonic-gate 	    IVSIZE, MMU_PAGESIZE);
1393*7c478bd9Sstevel@tonic-gate 	if (memspace != (caddr_t)intr_vector)
1394*7c478bd9Sstevel@tonic-gate 		panic("interrupt table allocation failure");
1395*7c478bd9Sstevel@tonic-gate 
1396*7c478bd9Sstevel@tonic-gate 	/*
1397*7c478bd9Sstevel@tonic-gate 	 * The memory lists from boot are allocated from the heap arena
1398*7c478bd9Sstevel@tonic-gate 	 * so that later they can be freed and/or reallocated.
1399*7c478bd9Sstevel@tonic-gate 	 */
1400*7c478bd9Sstevel@tonic-gate 	if (BOP_GETPROP(bootops, "extent", &memlist_sz) == -1)
1401*7c478bd9Sstevel@tonic-gate 		panic("could not retrieve property \"extent\"");
1402*7c478bd9Sstevel@tonic-gate 
1403*7c478bd9Sstevel@tonic-gate 	/*
1404*7c478bd9Sstevel@tonic-gate 	 * Between now and when we finish copying in the memory lists,
1405*7c478bd9Sstevel@tonic-gate 	 * allocations happen so the space gets fragmented and the
1406*7c478bd9Sstevel@tonic-gate 	 * lists longer.  Leave enough space for lists twice as long
1407*7c478bd9Sstevel@tonic-gate 	 * as what boot says it has now; roundup to a pagesize.
1408*7c478bd9Sstevel@tonic-gate 	 * Also add space for the final phys-avail copy in the fixup
1409*7c478bd9Sstevel@tonic-gate 	 * routine.
1410*7c478bd9Sstevel@tonic-gate 	 */
1411*7c478bd9Sstevel@tonic-gate 	va = (caddr_t)(sysbase + PAGESIZE + PANICBUFSIZE +
1412*7c478bd9Sstevel@tonic-gate 	    roundup(IVSIZE, MMU_PAGESIZE));
1413*7c478bd9Sstevel@tonic-gate 	memlist_sz *= 4;
1414*7c478bd9Sstevel@tonic-gate 	memlist_sz = roundup(memlist_sz, MMU_PAGESIZE);
1415*7c478bd9Sstevel@tonic-gate 	memspace = (caddr_t)BOP_ALLOC(bootops, va, memlist_sz, BO_NO_ALIGN);
1416*7c478bd9Sstevel@tonic-gate 	if (memspace == NULL)
1417*7c478bd9Sstevel@tonic-gate 		halt("Boot allocation failed.");
1418*7c478bd9Sstevel@tonic-gate 
1419*7c478bd9Sstevel@tonic-gate 	memlist = (struct memlist *)memspace;
1420*7c478bd9Sstevel@tonic-gate 	memlist_end = (char *)memspace + memlist_sz;
1421*7c478bd9Sstevel@tonic-gate 
1422*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(memlist);
1423*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(memlist_end);
1424*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(sysbase);
1425*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(syslimit);
1426*7c478bd9Sstevel@tonic-gate 
1427*7c478bd9Sstevel@tonic-gate 	kernelheap_init((void *)sysbase, (void *)syslimit,
1428*7c478bd9Sstevel@tonic-gate 	    (caddr_t)sysbase + PAGESIZE, NULL, NULL);
1429*7c478bd9Sstevel@tonic-gate 
1430*7c478bd9Sstevel@tonic-gate 	/*
1431*7c478bd9Sstevel@tonic-gate 	 * Take the most current snapshot we can by calling mem-update.
1432*7c478bd9Sstevel@tonic-gate 	 */
1433*7c478bd9Sstevel@tonic-gate 	copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len,
1434*7c478bd9Sstevel@tonic-gate 	    &boot_physavail, &boot_physavail_len,
1435*7c478bd9Sstevel@tonic-gate 	    &boot_virtavail, &boot_virtavail_len);
1436*7c478bd9Sstevel@tonic-gate 
1437*7c478bd9Sstevel@tonic-gate 	/*
1438*7c478bd9Sstevel@tonic-gate 	 * Remove the space used by BOP_ALLOC from the kernel heap
1439*7c478bd9Sstevel@tonic-gate 	 * plus the area actually used by the OBP (if any)
1440*7c478bd9Sstevel@tonic-gate 	 * ignoring virtual addresses in virt_avail, above syslimit.
1441*7c478bd9Sstevel@tonic-gate 	 */
1442*7c478bd9Sstevel@tonic-gate 	virt_avail = memlist;
1443*7c478bd9Sstevel@tonic-gate 	copy_memlist(boot_virtavail, boot_virtavail_len, &memlist);
1444*7c478bd9Sstevel@tonic-gate 
1445*7c478bd9Sstevel@tonic-gate 	for (cur = virt_avail; cur->next; cur = cur->next) {
1446*7c478bd9Sstevel@tonic-gate 		uint64_t range_base, range_size;
1447*7c478bd9Sstevel@tonic-gate 
1448*7c478bd9Sstevel@tonic-gate 		if ((range_base = cur->address + cur->size) < (uint64_t)sysbase)
1449*7c478bd9Sstevel@tonic-gate 			continue;
1450*7c478bd9Sstevel@tonic-gate 		if (range_base >= (uint64_t)syslimit)
1451*7c478bd9Sstevel@tonic-gate 			break;
1452*7c478bd9Sstevel@tonic-gate 		/*
1453*7c478bd9Sstevel@tonic-gate 		 * Limit the range to end at syslimit.
1454*7c478bd9Sstevel@tonic-gate 		 */
1455*7c478bd9Sstevel@tonic-gate 		range_size = MIN(cur->next->address,
1456*7c478bd9Sstevel@tonic-gate 		    (uint64_t)syslimit) - range_base;
1457*7c478bd9Sstevel@tonic-gate 		(void) vmem_xalloc(heap_arena, (size_t)range_size, PAGESIZE,
1458*7c478bd9Sstevel@tonic-gate 		    0, 0, (void *)range_base, (void *)(range_base + range_size),
1459*7c478bd9Sstevel@tonic-gate 		    VM_NOSLEEP | VM_BESTFIT | VM_PANIC);
1460*7c478bd9Sstevel@tonic-gate 	}
1461*7c478bd9Sstevel@tonic-gate 
1462*7c478bd9Sstevel@tonic-gate 	phys_avail = memlist;
1463*7c478bd9Sstevel@tonic-gate 	(void) copy_physavail(boot_physavail, boot_physavail_len,
1464*7c478bd9Sstevel@tonic-gate 	    &memlist, 0, 0);
1465*7c478bd9Sstevel@tonic-gate 
1466*7c478bd9Sstevel@tonic-gate 	/*
1467*7c478bd9Sstevel@tonic-gate 	 * Add any extra memory after e_text to the phys_avail list, as long
1468*7c478bd9Sstevel@tonic-gate 	 * as there's at least a page to add.
1469*7c478bd9Sstevel@tonic-gate 	 */
1470*7c478bd9Sstevel@tonic-gate 	if (extra_etpg)
1471*7c478bd9Sstevel@tonic-gate 		memlist_add(va_to_pa(extra_etva), mmu_ptob(extra_etpg),
1472*7c478bd9Sstevel@tonic-gate 		    &memlist, &phys_avail);
1473*7c478bd9Sstevel@tonic-gate 
1474*7c478bd9Sstevel@tonic-gate 	/*
1475*7c478bd9Sstevel@tonic-gate 	 * Add any extra memory after e_data to the phys_avail list as long
1476*7c478bd9Sstevel@tonic-gate 	 * as there's at least a page to add.  Usually, there isn't any,
1477*7c478bd9Sstevel@tonic-gate 	 * since extra HME blocks typically get allocated there first before
1478*7c478bd9Sstevel@tonic-gate 	 * using RAM elsewhere.
1479*7c478bd9Sstevel@tonic-gate 	 */
1480*7c478bd9Sstevel@tonic-gate 	if ((nalloc_base = ndata_extra_base(&ndata, MMU_PAGESIZE)) == NULL)
1481*7c478bd9Sstevel@tonic-gate 		nalloc_base = nalloc_end;
1482*7c478bd9Sstevel@tonic-gate 	ndata_remain_sz = nalloc_end - nalloc_base;
1483*7c478bd9Sstevel@tonic-gate 
1484*7c478bd9Sstevel@tonic-gate 	if (ndata_remain_sz >= MMU_PAGESIZE)
1485*7c478bd9Sstevel@tonic-gate 		memlist_add(va_to_pa(nalloc_base),
1486*7c478bd9Sstevel@tonic-gate 		    (uint64_t)ndata_remain_sz, &memlist, &phys_avail);
1487*7c478bd9Sstevel@tonic-gate 
1488*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(memlist);
1489*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(memlist_sz);
1490*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(memspace);
1491*7c478bd9Sstevel@tonic-gate 
1492*7c478bd9Sstevel@tonic-gate 	if ((caddr_t)memlist > (memspace + memlist_sz))
1493*7c478bd9Sstevel@tonic-gate 		panic("memlist overflow");
1494*7c478bd9Sstevel@tonic-gate 
1495*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(pp_base);
1496*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(memseg_base);
1497*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(npages);
1498*7c478bd9Sstevel@tonic-gate 
1499*7c478bd9Sstevel@tonic-gate 	/*
1500*7c478bd9Sstevel@tonic-gate 	 * Initialize the page structures from the memory lists.
1501*7c478bd9Sstevel@tonic-gate 	 */
1502*7c478bd9Sstevel@tonic-gate 	kphysm_init(pp_base, memseg_base, npages, kpm_pp_base, kpm_npages);
1503*7c478bd9Sstevel@tonic-gate 
1504*7c478bd9Sstevel@tonic-gate 	availrmem_initial = availrmem = freemem;
1505*7c478bd9Sstevel@tonic-gate 	PRM_DEBUG(availrmem);
1506*7c478bd9Sstevel@tonic-gate 
1507*7c478bd9Sstevel@tonic-gate 	/*
1508*7c478bd9Sstevel@tonic-gate 	 * Some of the locks depend on page_hashsz being set!
1509*7c478bd9Sstevel@tonic-gate 	 * kmem_init() depends on this; so, keep it here.
1510*7c478bd9Sstevel@tonic-gate 	 */
1511*7c478bd9Sstevel@tonic-gate 	page_lock_init();
1512*7c478bd9Sstevel@tonic-gate 
1513*7c478bd9Sstevel@tonic-gate 	/*
1514*7c478bd9Sstevel@tonic-gate 	 * Initialize kernel memory allocator.
1515*7c478bd9Sstevel@tonic-gate 	 */
1516*7c478bd9Sstevel@tonic-gate 	kmem_init();
1517*7c478bd9Sstevel@tonic-gate 
1518*7c478bd9Sstevel@tonic-gate 	/*
1519*7c478bd9Sstevel@tonic-gate 	 * Initialize bp_mapin().
1520*7c478bd9Sstevel@tonic-gate 	 */
1521*7c478bd9Sstevel@tonic-gate 	bp_init(shm_alignment, HAT_STRICTORDER);
1522*7c478bd9Sstevel@tonic-gate 
1523*7c478bd9Sstevel@tonic-gate 	/*
1524*7c478bd9Sstevel@tonic-gate 	 * Reserve space for panicbuf and intr_vector from the 32-bit heap
1525*7c478bd9Sstevel@tonic-gate 	 */
1526*7c478bd9Sstevel@tonic-gate 	(void) vmem_xalloc(heap32_arena, PANICBUFSIZE, PAGESIZE, 0, 0,
1527*7c478bd9Sstevel@tonic-gate 	    panicbuf, panicbuf + PANICBUFSIZE,
1528*7c478bd9Sstevel@tonic-gate 	    VM_NOSLEEP | VM_BESTFIT | VM_PANIC);
1529*7c478bd9Sstevel@tonic-gate 
1530*7c478bd9Sstevel@tonic-gate 	(void) vmem_xalloc(heap32_arena, IVSIZE, PAGESIZE, 0, 0,
1531*7c478bd9Sstevel@tonic-gate 	    intr_vector, (caddr_t)intr_vector + IVSIZE,
1532*7c478bd9Sstevel@tonic-gate 	    VM_NOSLEEP | VM_BESTFIT | VM_PANIC);
1533*7c478bd9Sstevel@tonic-gate 
1534*7c478bd9Sstevel@tonic-gate 	mem_config_init();
1535*7c478bd9Sstevel@tonic-gate }
1536*7c478bd9Sstevel@tonic-gate 
1537*7c478bd9Sstevel@tonic-gate static void
1538*7c478bd9Sstevel@tonic-gate startup_modules(void)
1539*7c478bd9Sstevel@tonic-gate {
1540*7c478bd9Sstevel@tonic-gate 	int proplen, nhblk1, nhblk8;
1541*7c478bd9Sstevel@tonic-gate 	size_t  nhblksz;
1542*7c478bd9Sstevel@tonic-gate 	pgcnt_t hblk_pages, pages_per_hblk;
1543*7c478bd9Sstevel@tonic-gate 	size_t hme8blk_sz, hme1blk_sz;
1544*7c478bd9Sstevel@tonic-gate 
1545*7c478bd9Sstevel@tonic-gate 	/*
1546*7c478bd9Sstevel@tonic-gate 	 * Log any optional messages from the boot program
1547*7c478bd9Sstevel@tonic-gate 	 */
1548*7c478bd9Sstevel@tonic-gate 	proplen = (size_t)BOP_GETPROPLEN(bootops, "boot-message");
1549*7c478bd9Sstevel@tonic-gate 	if (proplen > 0) {
1550*7c478bd9Sstevel@tonic-gate 		char *msg;
1551*7c478bd9Sstevel@tonic-gate 		size_t len = (size_t)proplen;
1552*7c478bd9Sstevel@tonic-gate 
1553*7c478bd9Sstevel@tonic-gate 		msg = kmem_zalloc(len, KM_SLEEP);
1554*7c478bd9Sstevel@tonic-gate 		(void) BOP_GETPROP(bootops, "boot-message", msg);
1555*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_CONT, "?%s\n", msg);
1556*7c478bd9Sstevel@tonic-gate 		kmem_free(msg, len);
1557*7c478bd9Sstevel@tonic-gate 	}
1558*7c478bd9Sstevel@tonic-gate 
1559*7c478bd9Sstevel@tonic-gate 	/*
1560*7c478bd9Sstevel@tonic-gate 	 * Let the platforms have a chance to change default
1561*7c478bd9Sstevel@tonic-gate 	 * values before reading system file.
1562*7c478bd9Sstevel@tonic-gate 	 */
1563*7c478bd9Sstevel@tonic-gate 	if (&set_platform_defaults)
1564*7c478bd9Sstevel@tonic-gate 		set_platform_defaults();
1565*7c478bd9Sstevel@tonic-gate 
1566*7c478bd9Sstevel@tonic-gate 	/*
1567*7c478bd9Sstevel@tonic-gate 	 * Calculate default settings of system parameters based upon
1568*7c478bd9Sstevel@tonic-gate 	 * maxusers, yet allow to be overridden via the /etc/system file.
1569*7c478bd9Sstevel@tonic-gate 	 */
1570*7c478bd9Sstevel@tonic-gate 	param_calc(0);
1571*7c478bd9Sstevel@tonic-gate 
1572*7c478bd9Sstevel@tonic-gate 	mod_setup();
1573*7c478bd9Sstevel@tonic-gate 
1574*7c478bd9Sstevel@tonic-gate 	/*
1575*7c478bd9Sstevel@tonic-gate 	 * If this is a positron, complain and halt.
1576*7c478bd9Sstevel@tonic-gate 	 */
1577*7c478bd9Sstevel@tonic-gate 	if (&iam_positron && iam_positron()) {
1578*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "This hardware platform is not supported"
1579*7c478bd9Sstevel@tonic-gate 		    " by this release of Solaris.\n");
1580*7c478bd9Sstevel@tonic-gate #ifdef DEBUG
1581*7c478bd9Sstevel@tonic-gate 		prom_enter_mon();	/* Type 'go' to resume */
1582*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "Booting an unsupported platform.\n");
1583*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "Booting with down-rev firmware.\n");
1584*7c478bd9Sstevel@tonic-gate 
1585*7c478bd9Sstevel@tonic-gate #else /* DEBUG */
1586*7c478bd9Sstevel@tonic-gate 		halt(0);
1587*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
1588*7c478bd9Sstevel@tonic-gate 	}
1589*7c478bd9Sstevel@tonic-gate 
1590*7c478bd9Sstevel@tonic-gate 	/*
1591*7c478bd9Sstevel@tonic-gate 	 * If we are running firmware that isn't 64-bit ready
1592*7c478bd9Sstevel@tonic-gate 	 * then complain and halt.
1593*7c478bd9Sstevel@tonic-gate 	 */
1594*7c478bd9Sstevel@tonic-gate 	do_prom_version_check();
1595*7c478bd9Sstevel@tonic-gate 
1596*7c478bd9Sstevel@tonic-gate 	/*
1597*7c478bd9Sstevel@tonic-gate 	 * Initialize system parameters
1598*7c478bd9Sstevel@tonic-gate 	 */
1599*7c478bd9Sstevel@tonic-gate 	param_init();
1600*7c478bd9Sstevel@tonic-gate 
1601*7c478bd9Sstevel@tonic-gate 	/*
1602*7c478bd9Sstevel@tonic-gate 	 * maxmem is the amount of physical memory we're playing with.
1603*7c478bd9Sstevel@tonic-gate 	 */
1604*7c478bd9Sstevel@tonic-gate 	maxmem = physmem;
1605*7c478bd9Sstevel@tonic-gate 
1606*7c478bd9Sstevel@tonic-gate 	/* Set segkp limits. */
1607*7c478bd9Sstevel@tonic-gate 	ncbase = (caddr_t)SEGDEBUGBASE;
1608*7c478bd9Sstevel@tonic-gate 	ncend = (caddr_t)SEGDEBUGBASE;
1609*7c478bd9Sstevel@tonic-gate 
1610*7c478bd9Sstevel@tonic-gate 	/*
1611*7c478bd9Sstevel@tonic-gate 	 * Initialize the hat layer.
1612*7c478bd9Sstevel@tonic-gate 	 */
1613*7c478bd9Sstevel@tonic-gate 	hat_init();
1614*7c478bd9Sstevel@tonic-gate 
1615*7c478bd9Sstevel@tonic-gate 	/*
1616*7c478bd9Sstevel@tonic-gate 	 * Initialize segment management stuff.
1617*7c478bd9Sstevel@tonic-gate 	 */
1618*7c478bd9Sstevel@tonic-gate 	seg_init();
1619*7c478bd9Sstevel@tonic-gate 
1620*7c478bd9Sstevel@tonic-gate 	/*
1621*7c478bd9Sstevel@tonic-gate 	 * Create the va>tte handler, so the prom can understand
1622*7c478bd9Sstevel@tonic-gate 	 * kernel translations.  The handler is installed later, just
1623*7c478bd9Sstevel@tonic-gate 	 * as we are about to take over the trap table from the prom.
1624*7c478bd9Sstevel@tonic-gate 	 */
1625*7c478bd9Sstevel@tonic-gate 	create_va_to_tte();
1626*7c478bd9Sstevel@tonic-gate 
1627*7c478bd9Sstevel@tonic-gate 	/*
1628*7c478bd9Sstevel@tonic-gate 	 * Load the forthdebugger (optional)
1629*7c478bd9Sstevel@tonic-gate 	 */
1630*7c478bd9Sstevel@tonic-gate 	forthdebug_init();
1631*7c478bd9Sstevel@tonic-gate 
1632*7c478bd9Sstevel@tonic-gate 	/*
1633*7c478bd9Sstevel@tonic-gate 	 * Create OBP node for console input callbacks
1634*7c478bd9Sstevel@tonic-gate 	 * if it is needed.
1635*7c478bd9Sstevel@tonic-gate 	 */
1636*7c478bd9Sstevel@tonic-gate 	startup_create_input_node();
1637*7c478bd9Sstevel@tonic-gate 
1638*7c478bd9Sstevel@tonic-gate 	if (modloadonly("fs", "specfs") == -1)
1639*7c478bd9Sstevel@tonic-gate 		halt("Can't load specfs");
1640*7c478bd9Sstevel@tonic-gate 
1641*7c478bd9Sstevel@tonic-gate 	if (modloadonly("fs", "devfs") == -1)
1642*7c478bd9Sstevel@tonic-gate 		halt("Can't load devfs");
1643*7c478bd9Sstevel@tonic-gate 
1644*7c478bd9Sstevel@tonic-gate 	if (modloadonly("misc", "swapgeneric") == -1)
1645*7c478bd9Sstevel@tonic-gate 		halt("Can't load swapgeneric");
1646*7c478bd9Sstevel@tonic-gate 
1647*7c478bd9Sstevel@tonic-gate 	dispinit();
1648*7c478bd9Sstevel@tonic-gate 
1649*7c478bd9Sstevel@tonic-gate 	/*
1650*7c478bd9Sstevel@tonic-gate 	 * Infer meanings to the members of the idprom buffer.
1651*7c478bd9Sstevel@tonic-gate 	 */
1652*7c478bd9Sstevel@tonic-gate 	parse_idprom();
1653*7c478bd9Sstevel@tonic-gate 
1654*7c478bd9Sstevel@tonic-gate 	/* Read cluster configuration data. */
1655*7c478bd9Sstevel@tonic-gate 	clconf_init();
1656*7c478bd9Sstevel@tonic-gate 
1657*7c478bd9Sstevel@tonic-gate 	setup_ddi();
1658*7c478bd9Sstevel@tonic-gate 
1659*7c478bd9Sstevel@tonic-gate 	/*
1660*7c478bd9Sstevel@tonic-gate 	 * Lets take this opportunity to load the root device.
1661*7c478bd9Sstevel@tonic-gate 	 */
1662*7c478bd9Sstevel@tonic-gate 	if (loadrootmodules() != 0)
1663*7c478bd9Sstevel@tonic-gate 		debug_enter("Can't load the root filesystem");
1664*7c478bd9Sstevel@tonic-gate 
1665*7c478bd9Sstevel@tonic-gate 	/*
1666*7c478bd9Sstevel@tonic-gate 	 * Load tod driver module for the tod part found on this system.
1667*7c478bd9Sstevel@tonic-gate 	 * Recompute the cpu frequency/delays based on tod as tod part
1668*7c478bd9Sstevel@tonic-gate 	 * tends to keep time more accurately.
1669*7c478bd9Sstevel@tonic-gate 	 */
1670*7c478bd9Sstevel@tonic-gate 	if (&load_tod_module)
1671*7c478bd9Sstevel@tonic-gate 		load_tod_module();
1672*7c478bd9Sstevel@tonic-gate 
1673*7c478bd9Sstevel@tonic-gate 	/*
1674*7c478bd9Sstevel@tonic-gate 	 * Allow platforms to load modules which might
1675*7c478bd9Sstevel@tonic-gate 	 * be needed after bootops are gone.
1676*7c478bd9Sstevel@tonic-gate 	 */
1677*7c478bd9Sstevel@tonic-gate 	if (&load_platform_modules)
1678*7c478bd9Sstevel@tonic-gate 		load_platform_modules();
1679*7c478bd9Sstevel@tonic-gate 
1680*7c478bd9Sstevel@tonic-gate 	setcpudelay();
1681*7c478bd9Sstevel@tonic-gate 
1682*7c478bd9Sstevel@tonic-gate 	copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len,
1683*7c478bd9Sstevel@tonic-gate 	    &boot_physavail, &boot_physavail_len,
1684*7c478bd9Sstevel@tonic-gate 	    &boot_virtavail, &boot_virtavail_len);
1685*7c478bd9Sstevel@tonic-gate 
1686*7c478bd9Sstevel@tonic-gate 	bop_alloc_pages = size_virtalloc(boot_virtavail, boot_virtavail_len);
1687*7c478bd9Sstevel@tonic-gate 
1688*7c478bd9Sstevel@tonic-gate 	/*
1689*7c478bd9Sstevel@tonic-gate 	 * Calculation and allocation of hmeblks needed to remap
1690*7c478bd9Sstevel@tonic-gate 	 * the memory allocated by PROM till now:
1691*7c478bd9Sstevel@tonic-gate 	 *
1692*7c478bd9Sstevel@tonic-gate 	 * (1)  calculate how much virtual memory has been bop_alloc'ed.
1693*7c478bd9Sstevel@tonic-gate 	 * (2)  roundup this memory to span of hme8blk, i.e. 64KB
1694*7c478bd9Sstevel@tonic-gate 	 * (3)  calculate number of hme8blk's needed to remap this memory
1695*7c478bd9Sstevel@tonic-gate 	 * (4)  calculate amount of memory that's consumed by these hme8blk's
1696*7c478bd9Sstevel@tonic-gate 	 * (5)  add memory calculated in steps (2) and (4) above.
1697*7c478bd9Sstevel@tonic-gate 	 * (6)  roundup this memory to span of hme8blk, i.e. 64KB
1698*7c478bd9Sstevel@tonic-gate 	 * (7)  calculate number of hme8blk's needed to remap this memory
1699*7c478bd9Sstevel@tonic-gate 	 * (8)  calculate amount of memory that's consumed by these hme8blk's
1700*7c478bd9Sstevel@tonic-gate 	 * (9)  allocate additional hme1blk's to hold large mappings.
1701*7c478bd9Sstevel@tonic-gate 	 *	H8TOH1 determines this.  The current SWAG gives enough hblk1's
1702*7c478bd9Sstevel@tonic-gate 	 *	to remap everything with 4M mappings.
1703*7c478bd9Sstevel@tonic-gate 	 * (10) account for partially used hblk8's due to non-64K aligned
1704*7c478bd9Sstevel@tonic-gate 	 *	PROM mapping entries.
1705*7c478bd9Sstevel@tonic-gate 	 * (11) add memory calculated in steps (8), (9), and (10) above.
1706*7c478bd9Sstevel@tonic-gate 	 * (12) kmem_zalloc the memory calculated in (11); since segkmem
1707*7c478bd9Sstevel@tonic-gate 	 *	is not ready yet, this gets bop_alloc'ed.
1708*7c478bd9Sstevel@tonic-gate 	 * (13) there will be very few bop_alloc's after this point before
1709*7c478bd9Sstevel@tonic-gate 	 *	trap table takes over
1710*7c478bd9Sstevel@tonic-gate 	 */
1711*7c478bd9Sstevel@tonic-gate 
1712*7c478bd9Sstevel@tonic-gate 	/* sfmmu_init_nucleus_hblks expects properly aligned data structures. */
1713*7c478bd9Sstevel@tonic-gate 	hme8blk_sz = roundup(HME8BLK_SZ, sizeof (int64_t));
1714*7c478bd9Sstevel@tonic-gate 	hme1blk_sz = roundup(HME1BLK_SZ, sizeof (int64_t));
1715*7c478bd9Sstevel@tonic-gate 
1716*7c478bd9Sstevel@tonic-gate 	pages_per_hblk = btop(HMEBLK_SPAN(TTE8K));
1717*7c478bd9Sstevel@tonic-gate 	bop_alloc_pages = roundup(bop_alloc_pages, pages_per_hblk);
1718*7c478bd9Sstevel@tonic-gate 	nhblk8 = bop_alloc_pages / pages_per_hblk;
1719*7c478bd9Sstevel@tonic-gate 	nhblk1 = roundup(nhblk8, H8TOH1) / H8TOH1;
1720*7c478bd9Sstevel@tonic-gate 	hblk_pages = btopr(nhblk8 * hme8blk_sz + nhblk1 * hme1blk_sz);
1721*7c478bd9Sstevel@tonic-gate 	bop_alloc_pages += hblk_pages;
1722*7c478bd9Sstevel@tonic-gate 	bop_alloc_pages = roundup(bop_alloc_pages, pages_per_hblk);
1723*7c478bd9Sstevel@tonic-gate 	nhblk8 = bop_alloc_pages / pages_per_hblk;
1724*7c478bd9Sstevel@tonic-gate 	nhblk1 = roundup(nhblk8, H8TOH1) / H8TOH1;
1725*7c478bd9Sstevel@tonic-gate 	if (nhblk1 < hblk1_min)
1726*7c478bd9Sstevel@tonic-gate 		nhblk1 = hblk1_min;
1727*7c478bd9Sstevel@tonic-gate 	if (nhblk8 < hblk8_min)
1728*7c478bd9Sstevel@tonic-gate 		nhblk8 = hblk8_min;
1729*7c478bd9Sstevel@tonic-gate 
1730*7c478bd9Sstevel@tonic-gate 	/*
1731*7c478bd9Sstevel@tonic-gate 	 * Since hblk8's can hold up to 64k of mappings aligned on a 64k
1732*7c478bd9Sstevel@tonic-gate 	 * boundary, the number of hblk8's needed to map the entries in the
1733*7c478bd9Sstevel@tonic-gate 	 * boot_virtavail list needs to be adjusted to take this into
1734*7c478bd9Sstevel@tonic-gate 	 * consideration.  Thus, we need to add additional hblk8's since it
1735*7c478bd9Sstevel@tonic-gate 	 * is possible that an hblk8 will not have all 8 slots used due to
1736*7c478bd9Sstevel@tonic-gate 	 * alignment constraints.  Since there were boot_virtavail_len entries
1737*7c478bd9Sstevel@tonic-gate 	 * in that list, we need to add that many hblk8's to the number
1738*7c478bd9Sstevel@tonic-gate 	 * already calculated to make sure we don't underestimate.
1739*7c478bd9Sstevel@tonic-gate 	 */
1740*7c478bd9Sstevel@tonic-gate 	nhblk8 += boot_virtavail_len;
1741*7c478bd9Sstevel@tonic-gate 	nhblksz = nhblk8 * hme8blk_sz + nhblk1 * hme1blk_sz;
1742*7c478bd9Sstevel@tonic-gate 
1743*7c478bd9Sstevel@tonic-gate 	/* Allocate in pagesize chunks */
1744*7c478bd9Sstevel@tonic-gate 	nhblksz = roundup(nhblksz, MMU_PAGESIZE);
1745*7c478bd9Sstevel@tonic-gate 	hblk_base = kmem_zalloc(nhblksz, KM_SLEEP);
1746*7c478bd9Sstevel@tonic-gate 	sfmmu_init_nucleus_hblks(hblk_base, nhblksz, nhblk8, nhblk1);
1747*7c478bd9Sstevel@tonic-gate }
1748*7c478bd9Sstevel@tonic-gate 
1749*7c478bd9Sstevel@tonic-gate static void
1750*7c478bd9Sstevel@tonic-gate startup_bop_gone(void)
1751*7c478bd9Sstevel@tonic-gate {
1752*7c478bd9Sstevel@tonic-gate 	extern int bop_io_quiesced;
1753*7c478bd9Sstevel@tonic-gate 
1754*7c478bd9Sstevel@tonic-gate 	/*
1755*7c478bd9Sstevel@tonic-gate 	 * Call back into boot and release boots resources.
1756*7c478bd9Sstevel@tonic-gate 	 */
1757*7c478bd9Sstevel@tonic-gate 	BOP_QUIESCE_IO(bootops);
1758*7c478bd9Sstevel@tonic-gate 	bop_io_quiesced = 1;
1759*7c478bd9Sstevel@tonic-gate 
1760*7c478bd9Sstevel@tonic-gate 	copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len,
1761*7c478bd9Sstevel@tonic-gate 	    &boot_physavail, &boot_physavail_len,
1762*7c478bd9Sstevel@tonic-gate 	    &boot_virtavail, &boot_virtavail_len);
1763*7c478bd9Sstevel@tonic-gate 	/*
1764*7c478bd9Sstevel@tonic-gate 	 * Copy physinstalled list into kernel space.
1765*7c478bd9Sstevel@tonic-gate 	 */
1766*7c478bd9Sstevel@tonic-gate 	phys_install = memlist;
1767*7c478bd9Sstevel@tonic-gate 	copy_memlist(boot_physinstalled, boot_physinstalled_len, &memlist);
1768*7c478bd9Sstevel@tonic-gate 
1769*7c478bd9Sstevel@tonic-gate 	/*
1770*7c478bd9Sstevel@tonic-gate 	 * setup physically contiguous area twice as large as the ecache.
1771*7c478bd9Sstevel@tonic-gate 	 * this is used while doing displacement flush of ecaches
1772*7c478bd9Sstevel@tonic-gate 	 */
1773*7c478bd9Sstevel@tonic-gate 	if (&ecache_flush_address) {
1774*7c478bd9Sstevel@tonic-gate 		ecache_flushaddr = ecache_flush_address();
1775*7c478bd9Sstevel@tonic-gate 		if (ecache_flushaddr == (uint64_t)-1) {
1776*7c478bd9Sstevel@tonic-gate 			cmn_err(CE_PANIC,
1777*7c478bd9Sstevel@tonic-gate 			    "startup: no memory to set ecache_flushaddr");
1778*7c478bd9Sstevel@tonic-gate 		}
1779*7c478bd9Sstevel@tonic-gate 	}
1780*7c478bd9Sstevel@tonic-gate 
1781*7c478bd9Sstevel@tonic-gate 	/*
1782*7c478bd9Sstevel@tonic-gate 	 * Virtual available next.
1783*7c478bd9Sstevel@tonic-gate 	 */
1784*7c478bd9Sstevel@tonic-gate 	ASSERT(virt_avail != NULL);
1785*7c478bd9Sstevel@tonic-gate 	memlist_free_list(virt_avail);
1786*7c478bd9Sstevel@tonic-gate 	virt_avail = memlist;
1787*7c478bd9Sstevel@tonic-gate 	copy_memlist(boot_virtavail, boot_virtavail_len, &memlist);
1788*7c478bd9Sstevel@tonic-gate 
1789*7c478bd9Sstevel@tonic-gate 	/*
1790*7c478bd9Sstevel@tonic-gate 	 * Last chance to ask our booter questions ..
1791*7c478bd9Sstevel@tonic-gate 	 */
1792*7c478bd9Sstevel@tonic-gate }
1793*7c478bd9Sstevel@tonic-gate 
1794*7c478bd9Sstevel@tonic-gate 
1795*7c478bd9Sstevel@tonic-gate /*
1796*7c478bd9Sstevel@tonic-gate  * startup_fixup_physavail - called from mach_sfmmu.c after the final
1797*7c478bd9Sstevel@tonic-gate  * allocations have been performed.  We can't call it in startup_bop_gone
1798*7c478bd9Sstevel@tonic-gate  * since later operations can cause obp to allocate more memory.
1799*7c478bd9Sstevel@tonic-gate  */
1800*7c478bd9Sstevel@tonic-gate void
1801*7c478bd9Sstevel@tonic-gate startup_fixup_physavail(void)
1802*7c478bd9Sstevel@tonic-gate {
1803*7c478bd9Sstevel@tonic-gate 	struct memlist *cur;
1804*7c478bd9Sstevel@tonic-gate 
1805*7c478bd9Sstevel@tonic-gate 	/*
1806*7c478bd9Sstevel@tonic-gate 	 * take the most current snapshot we can by calling mem-update
1807*7c478bd9Sstevel@tonic-gate 	 */
1808*7c478bd9Sstevel@tonic-gate 	copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len,
1809*7c478bd9Sstevel@tonic-gate 	    &boot_physavail, &boot_physavail_len,
1810*7c478bd9Sstevel@tonic-gate 	    &boot_virtavail, &boot_virtavail_len);
1811*7c478bd9Sstevel@tonic-gate 
1812*7c478bd9Sstevel@tonic-gate 	/*
1813*7c478bd9Sstevel@tonic-gate 	 * Copy phys_avail list, again.
1814*7c478bd9Sstevel@tonic-gate 	 * Both the kernel/boot and the prom have been allocating
1815*7c478bd9Sstevel@tonic-gate 	 * from the original list we copied earlier.
1816*7c478bd9Sstevel@tonic-gate 	 */
1817*7c478bd9Sstevel@tonic-gate 	cur = memlist;
1818*7c478bd9Sstevel@tonic-gate 	(void) copy_physavail(boot_physavail, boot_physavail_len,
1819*7c478bd9Sstevel@tonic-gate 	    &memlist, 0, 0);
1820*7c478bd9Sstevel@tonic-gate 
1821*7c478bd9Sstevel@tonic-gate 	/*
1822*7c478bd9Sstevel@tonic-gate 	 * Add any extra memory after e_text we added to the phys_avail list
1823*7c478bd9Sstevel@tonic-gate 	 * back to the old list.
1824*7c478bd9Sstevel@tonic-gate 	 */
1825*7c478bd9Sstevel@tonic-gate 	if (extra_etpg)
1826*7c478bd9Sstevel@tonic-gate 		memlist_add(va_to_pa(extra_etva), mmu_ptob(extra_etpg),
1827*7c478bd9Sstevel@tonic-gate 		    &memlist, &cur);
1828*7c478bd9Sstevel@tonic-gate 	if (ndata_remain_sz >= MMU_PAGESIZE)
1829*7c478bd9Sstevel@tonic-gate 		memlist_add(va_to_pa(nalloc_base),
1830*7c478bd9Sstevel@tonic-gate 		    (uint64_t)ndata_remain_sz, &memlist, &cur);
1831*7c478bd9Sstevel@tonic-gate 
1832*7c478bd9Sstevel@tonic-gate 	/*
1833*7c478bd9Sstevel@tonic-gate 	 * There isn't any bounds checking on the memlist area
1834*7c478bd9Sstevel@tonic-gate 	 * so ensure it hasn't overgrown.
1835*7c478bd9Sstevel@tonic-gate 	 */
1836*7c478bd9Sstevel@tonic-gate 	if ((caddr_t)memlist > (caddr_t)memlist_end)
1837*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "startup: memlist size exceeded");
1838*7c478bd9Sstevel@tonic-gate 
1839*7c478bd9Sstevel@tonic-gate 	/*
1840*7c478bd9Sstevel@tonic-gate 	 * The kernel removes the pages that were allocated for it from
1841*7c478bd9Sstevel@tonic-gate 	 * the freelist, but we now have to find any -extra- pages that
1842*7c478bd9Sstevel@tonic-gate 	 * the prom has allocated for it's own book-keeping, and remove
1843*7c478bd9Sstevel@tonic-gate 	 * them from the freelist too. sigh.
1844*7c478bd9Sstevel@tonic-gate 	 */
1845*7c478bd9Sstevel@tonic-gate 	fix_prom_pages(phys_avail, cur);
1846*7c478bd9Sstevel@tonic-gate 
1847*7c478bd9Sstevel@tonic-gate 	ASSERT(phys_avail != NULL);
1848*7c478bd9Sstevel@tonic-gate 	memlist_free_list(phys_avail);
1849*7c478bd9Sstevel@tonic-gate 	phys_avail = cur;
1850*7c478bd9Sstevel@tonic-gate 
1851*7c478bd9Sstevel@tonic-gate 	/*
1852*7c478bd9Sstevel@tonic-gate 	 * We're done with boot.  Just after this point in time, boot
1853*7c478bd9Sstevel@tonic-gate 	 * gets unmapped, so we can no longer rely on its services.
1854*7c478bd9Sstevel@tonic-gate 	 * Zero the bootops to indicate this fact.
1855*7c478bd9Sstevel@tonic-gate 	 */
1856*7c478bd9Sstevel@tonic-gate 	bootops = (struct bootops *)NULL;
1857*7c478bd9Sstevel@tonic-gate 	BOOTOPS_GONE();
1858*7c478bd9Sstevel@tonic-gate }
1859*7c478bd9Sstevel@tonic-gate 
1860*7c478bd9Sstevel@tonic-gate static void
1861*7c478bd9Sstevel@tonic-gate startup_vm(void)
1862*7c478bd9Sstevel@tonic-gate {
1863*7c478bd9Sstevel@tonic-gate 	size_t	i;
1864*7c478bd9Sstevel@tonic-gate 	struct segmap_crargs a;
1865*7c478bd9Sstevel@tonic-gate 	struct segkpm_crargs b;
1866*7c478bd9Sstevel@tonic-gate 
1867*7c478bd9Sstevel@tonic-gate 	uint64_t avmem;
1868*7c478bd9Sstevel@tonic-gate 	caddr_t va;
1869*7c478bd9Sstevel@tonic-gate 	pgcnt_t	max_phys_segkp;
1870*7c478bd9Sstevel@tonic-gate 	int	mnode;
1871*7c478bd9Sstevel@tonic-gate 
1872*7c478bd9Sstevel@tonic-gate 	/*
1873*7c478bd9Sstevel@tonic-gate 	 * get prom's mappings, create hments for them and switch
1874*7c478bd9Sstevel@tonic-gate 	 * to the kernel context.
1875*7c478bd9Sstevel@tonic-gate 	 */
1876*7c478bd9Sstevel@tonic-gate 	hat_kern_setup();
1877*7c478bd9Sstevel@tonic-gate 
1878*7c478bd9Sstevel@tonic-gate 	/*
1879*7c478bd9Sstevel@tonic-gate 	 * Take over trap table
1880*7c478bd9Sstevel@tonic-gate 	 */
1881*7c478bd9Sstevel@tonic-gate 	setup_trap_table();
1882*7c478bd9Sstevel@tonic-gate 
1883*7c478bd9Sstevel@tonic-gate 	/*
1884*7c478bd9Sstevel@tonic-gate 	 * Install the va>tte handler, so that the prom can handle
1885*7c478bd9Sstevel@tonic-gate 	 * misses and understand the kernel table layout in case
1886*7c478bd9Sstevel@tonic-gate 	 * we need call into the prom.
1887*7c478bd9Sstevel@tonic-gate 	 */
1888*7c478bd9Sstevel@tonic-gate 	install_va_to_tte();
1889*7c478bd9Sstevel@tonic-gate 
1890*7c478bd9Sstevel@tonic-gate 	/*
1891*7c478bd9Sstevel@tonic-gate 	 * Set a flag to indicate that the tba has been taken over.
1892*7c478bd9Sstevel@tonic-gate 	 */
1893*7c478bd9Sstevel@tonic-gate 	tba_taken_over = 1;
1894*7c478bd9Sstevel@tonic-gate 
1895*7c478bd9Sstevel@tonic-gate 	/* initialize MMU primary context register */
1896*7c478bd9Sstevel@tonic-gate 	mmu_init_kcontext();
1897*7c478bd9Sstevel@tonic-gate 
1898*7c478bd9Sstevel@tonic-gate 	/*
1899*7c478bd9Sstevel@tonic-gate 	 * The boot cpu can now take interrupts, x-calls, x-traps
1900*7c478bd9Sstevel@tonic-gate 	 */
1901*7c478bd9Sstevel@tonic-gate 	CPUSET_ADD(cpu_ready_set, CPU->cpu_id);
1902*7c478bd9Sstevel@tonic-gate 	CPU->cpu_flags |= (CPU_READY | CPU_ENABLE | CPU_EXISTS);
1903*7c478bd9Sstevel@tonic-gate 
1904*7c478bd9Sstevel@tonic-gate 	/*
1905*7c478bd9Sstevel@tonic-gate 	 * Set a flag to tell write_scb_int() that it can access V_TBR_WR_ADDR.
1906*7c478bd9Sstevel@tonic-gate 	 */
1907*7c478bd9Sstevel@tonic-gate 	tbr_wr_addr_inited = 1;
1908*7c478bd9Sstevel@tonic-gate 
1909*7c478bd9Sstevel@tonic-gate 	/*
1910*7c478bd9Sstevel@tonic-gate 	 * Initialize VM system, and map kernel address space.
1911*7c478bd9Sstevel@tonic-gate 	 */
1912*7c478bd9Sstevel@tonic-gate 	kvm_init();
1913*7c478bd9Sstevel@tonic-gate 
1914*7c478bd9Sstevel@tonic-gate 	/*
1915*7c478bd9Sstevel@tonic-gate 	 * XXX4U: previously, we initialized and turned on
1916*7c478bd9Sstevel@tonic-gate 	 * the caches at this point. But of course we have
1917*7c478bd9Sstevel@tonic-gate 	 * nothing to do, as the prom has already done this
1918*7c478bd9Sstevel@tonic-gate 	 * for us -- main memory must be E$able at all times.
1919*7c478bd9Sstevel@tonic-gate 	 */
1920*7c478bd9Sstevel@tonic-gate 
1921*7c478bd9Sstevel@tonic-gate 	/*
1922*7c478bd9Sstevel@tonic-gate 	 * If the following is true, someone has patched
1923*7c478bd9Sstevel@tonic-gate 	 * phsymem to be less than the number of pages that
1924*7c478bd9Sstevel@tonic-gate 	 * the system actually has.  Remove pages until system
1925*7c478bd9Sstevel@tonic-gate 	 * memory is limited to the requested amount.  Since we
1926*7c478bd9Sstevel@tonic-gate 	 * have allocated page structures for all pages, we
1927*7c478bd9Sstevel@tonic-gate 	 * correct the amount of memory we want to remove
1928*7c478bd9Sstevel@tonic-gate 	 * by the size of the memory used to hold page structures
1929*7c478bd9Sstevel@tonic-gate 	 * for the non-used pages.
1930*7c478bd9Sstevel@tonic-gate 	 */
1931*7c478bd9Sstevel@tonic-gate 	if (physmem < npages) {
1932*7c478bd9Sstevel@tonic-gate 		pgcnt_t diff, off;
1933*7c478bd9Sstevel@tonic-gate 		struct page *pp;
1934*7c478bd9Sstevel@tonic-gate 		struct seg kseg;
1935*7c478bd9Sstevel@tonic-gate 
1936*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "limiting physmem to %ld pages", physmem);
1937*7c478bd9Sstevel@tonic-gate 
1938*7c478bd9Sstevel@tonic-gate 		off = 0;
1939*7c478bd9Sstevel@tonic-gate 		diff = npages - physmem;
1940*7c478bd9Sstevel@tonic-gate 		diff -= mmu_btopr(diff * sizeof (struct page));
1941*7c478bd9Sstevel@tonic-gate 		kseg.s_as = &kas;
1942*7c478bd9Sstevel@tonic-gate 		while (diff--) {
1943*7c478bd9Sstevel@tonic-gate 			pp = page_create_va(&unused_pages_vp, (offset_t)off,
1944*7c478bd9Sstevel@tonic-gate 			    MMU_PAGESIZE, PG_WAIT | PG_EXCL,
1945*7c478bd9Sstevel@tonic-gate 			    &kseg, (caddr_t)off);
1946*7c478bd9Sstevel@tonic-gate 			if (pp == NULL)
1947*7c478bd9Sstevel@tonic-gate 				cmn_err(CE_PANIC, "limited physmem too much!");
1948*7c478bd9Sstevel@tonic-gate 			page_io_unlock(pp);
1949*7c478bd9Sstevel@tonic-gate 			page_downgrade(pp);
1950*7c478bd9Sstevel@tonic-gate 			availrmem--;
1951*7c478bd9Sstevel@tonic-gate 			off += MMU_PAGESIZE;
1952*7c478bd9Sstevel@tonic-gate 		}
1953*7c478bd9Sstevel@tonic-gate 	}
1954*7c478bd9Sstevel@tonic-gate 
1955*7c478bd9Sstevel@tonic-gate 	/*
1956*7c478bd9Sstevel@tonic-gate 	 * When printing memory, show the total as physmem less
1957*7c478bd9Sstevel@tonic-gate 	 * that stolen by a debugger.
1958*7c478bd9Sstevel@tonic-gate 	 */
1959*7c478bd9Sstevel@tonic-gate 	cmn_err(CE_CONT, "?mem = %ldK (0x%lx000)\n",
1960*7c478bd9Sstevel@tonic-gate 	    (ulong_t)(physinstalled) << (PAGESHIFT - 10),
1961*7c478bd9Sstevel@tonic-gate 	    (ulong_t)(physinstalled) << (PAGESHIFT - 12));
1962*7c478bd9Sstevel@tonic-gate 
1963*7c478bd9Sstevel@tonic-gate 	avmem = (uint64_t)freemem << PAGESHIFT;
1964*7c478bd9Sstevel@tonic-gate 	cmn_err(CE_CONT, "?avail mem = %lld\n", (unsigned long long)avmem);
1965*7c478bd9Sstevel@tonic-gate 
1966*7c478bd9Sstevel@tonic-gate 	/*
1967*7c478bd9Sstevel@tonic-gate 	 * Perform platform specific freelist processing
1968*7c478bd9Sstevel@tonic-gate 	 */
1969*7c478bd9Sstevel@tonic-gate 	if (&plat_freelist_process) {
1970*7c478bd9Sstevel@tonic-gate 		for (mnode = 0; mnode < max_mem_nodes; mnode++)
1971*7c478bd9Sstevel@tonic-gate 			if (mem_node_config[mnode].exists)
1972*7c478bd9Sstevel@tonic-gate 				plat_freelist_process(mnode);
1973*7c478bd9Sstevel@tonic-gate 	}
1974*7c478bd9Sstevel@tonic-gate 
1975*7c478bd9Sstevel@tonic-gate 	/*
1976*7c478bd9Sstevel@tonic-gate 	 * Initialize the segkp segment type.  We position it
1977*7c478bd9Sstevel@tonic-gate 	 * after the configured tables and buffers (whose end
1978*7c478bd9Sstevel@tonic-gate 	 * is given by econtig) and before V_WKBASE_ADDR.
1979*7c478bd9Sstevel@tonic-gate 	 * Also in this area is segkmap (size SEGMAPSIZE).
1980*7c478bd9Sstevel@tonic-gate 	 */
1981*7c478bd9Sstevel@tonic-gate 
1982*7c478bd9Sstevel@tonic-gate 	/* XXX - cache alignment? */
1983*7c478bd9Sstevel@tonic-gate 	va = (caddr_t)SEGKPBASE;
1984*7c478bd9Sstevel@tonic-gate 	ASSERT(((uintptr_t)va & PAGEOFFSET) == 0);
1985*7c478bd9Sstevel@tonic-gate 
1986*7c478bd9Sstevel@tonic-gate 	max_phys_segkp = (physmem * 2);
1987*7c478bd9Sstevel@tonic-gate 
1988*7c478bd9Sstevel@tonic-gate 	if (segkpsize < btop(SEGKPMINSIZE) || segkpsize > btop(SEGKPMAXSIZE)) {
1989*7c478bd9Sstevel@tonic-gate 		segkpsize = btop(SEGKPDEFSIZE);
1990*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "Illegal value for segkpsize. "
1991*7c478bd9Sstevel@tonic-gate 		    "segkpsize has been reset to %ld pages", segkpsize);
1992*7c478bd9Sstevel@tonic-gate 	}
1993*7c478bd9Sstevel@tonic-gate 
1994*7c478bd9Sstevel@tonic-gate 	i = ptob(MIN(segkpsize, max_phys_segkp));
1995*7c478bd9Sstevel@tonic-gate 
1996*7c478bd9Sstevel@tonic-gate 	rw_enter(&kas.a_lock, RW_WRITER);
1997*7c478bd9Sstevel@tonic-gate 	if (seg_attach(&kas, va, i, segkp) < 0)
1998*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "startup: cannot attach segkp");
1999*7c478bd9Sstevel@tonic-gate 	if (segkp_create(segkp) != 0)
2000*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "startup: segkp_create failed");
2001*7c478bd9Sstevel@tonic-gate 	rw_exit(&kas.a_lock);
2002*7c478bd9Sstevel@tonic-gate 
2003*7c478bd9Sstevel@tonic-gate 	/*
2004*7c478bd9Sstevel@tonic-gate 	 * kpm segment
2005*7c478bd9Sstevel@tonic-gate 	 */
2006*7c478bd9Sstevel@tonic-gate 	segmap_kpm = kpm_enable &&
2007*7c478bd9Sstevel@tonic-gate 		segmap_kpm && PAGESIZE == MAXBSIZE;
2008*7c478bd9Sstevel@tonic-gate 
2009*7c478bd9Sstevel@tonic-gate 	if (kpm_enable) {
2010*7c478bd9Sstevel@tonic-gate 		rw_enter(&kas.a_lock, RW_WRITER);
2011*7c478bd9Sstevel@tonic-gate 
2012*7c478bd9Sstevel@tonic-gate 		/*
2013*7c478bd9Sstevel@tonic-gate 		 * The segkpm virtual range range is larger than the
2014*7c478bd9Sstevel@tonic-gate 		 * actual physical memory size and also covers gaps in
2015*7c478bd9Sstevel@tonic-gate 		 * the physical address range for the following reasons:
2016*7c478bd9Sstevel@tonic-gate 		 * . keep conversion between segkpm and physical addresses
2017*7c478bd9Sstevel@tonic-gate 		 *   simple, cheap and unambiguous.
2018*7c478bd9Sstevel@tonic-gate 		 * . avoid extension/shrink of the the segkpm in case of DR.
2019*7c478bd9Sstevel@tonic-gate 		 * . avoid complexity for handling of virtual addressed
2020*7c478bd9Sstevel@tonic-gate 		 *   caches, segkpm and the regular mapping scheme must be
2021*7c478bd9Sstevel@tonic-gate 		 *   kept in sync wrt. the virtual color of mapped pages.
2022*7c478bd9Sstevel@tonic-gate 		 * Any accesses to virtual segkpm ranges not backed by
2023*7c478bd9Sstevel@tonic-gate 		 * physical memory will fall through the memseg pfn hash
2024*7c478bd9Sstevel@tonic-gate 		 * and will be handled in segkpm_fault.
2025*7c478bd9Sstevel@tonic-gate 		 * Additional kpm_size spaces needed for vac alias prevention.
2026*7c478bd9Sstevel@tonic-gate 		 */
2027*7c478bd9Sstevel@tonic-gate 		if (seg_attach(&kas, kpm_vbase, kpm_size * vac_colors,
2028*7c478bd9Sstevel@tonic-gate 		    segkpm) < 0)
2029*7c478bd9Sstevel@tonic-gate 			cmn_err(CE_PANIC, "cannot attach segkpm");
2030*7c478bd9Sstevel@tonic-gate 
2031*7c478bd9Sstevel@tonic-gate 		b.prot = PROT_READ | PROT_WRITE;
2032*7c478bd9Sstevel@tonic-gate 		b.nvcolors = shm_alignment >> MMU_PAGESHIFT;
2033*7c478bd9Sstevel@tonic-gate 
2034*7c478bd9Sstevel@tonic-gate 		if (segkpm_create(segkpm, (caddr_t)&b) != 0)
2035*7c478bd9Sstevel@tonic-gate 			panic("segkpm_create segkpm");
2036*7c478bd9Sstevel@tonic-gate 
2037*7c478bd9Sstevel@tonic-gate 		rw_exit(&kas.a_lock);
2038*7c478bd9Sstevel@tonic-gate 	}
2039*7c478bd9Sstevel@tonic-gate 
2040*7c478bd9Sstevel@tonic-gate 	/*
2041*7c478bd9Sstevel@tonic-gate 	 * Now create generic mapping segment.  This mapping
2042*7c478bd9Sstevel@tonic-gate 	 * goes SEGMAPSIZE beyond SEGMAPBASE.  But if the total
2043*7c478bd9Sstevel@tonic-gate 	 * virtual address is greater than the amount of free
2044*7c478bd9Sstevel@tonic-gate 	 * memory that is available, then we trim back the
2045*7c478bd9Sstevel@tonic-gate 	 * segment size to that amount
2046*7c478bd9Sstevel@tonic-gate 	 */
2047*7c478bd9Sstevel@tonic-gate 	va = (caddr_t)SEGMAPBASE;
2048*7c478bd9Sstevel@tonic-gate 
2049*7c478bd9Sstevel@tonic-gate 	/*
2050*7c478bd9Sstevel@tonic-gate 	 * 1201049: segkmap base address must be MAXBSIZE aligned
2051*7c478bd9Sstevel@tonic-gate 	 */
2052*7c478bd9Sstevel@tonic-gate 	ASSERT(((uintptr_t)va & MAXBOFFSET) == 0);
2053*7c478bd9Sstevel@tonic-gate 
2054*7c478bd9Sstevel@tonic-gate 	/*
2055*7c478bd9Sstevel@tonic-gate 	 * Set size of segmap to percentage of freemem at boot,
2056*7c478bd9Sstevel@tonic-gate 	 * but stay within the allowable range
2057*7c478bd9Sstevel@tonic-gate 	 * Note we take percentage  before converting from pages
2058*7c478bd9Sstevel@tonic-gate 	 * to bytes to avoid an overflow on 32-bit kernels.
2059*7c478bd9Sstevel@tonic-gate 	 */
2060*7c478bd9Sstevel@tonic-gate 	i = mmu_ptob((freemem * segmap_percent) / 100);
2061*7c478bd9Sstevel@tonic-gate 
2062*7c478bd9Sstevel@tonic-gate 	if (i < MINMAPSIZE)
2063*7c478bd9Sstevel@tonic-gate 		i = MINMAPSIZE;
2064*7c478bd9Sstevel@tonic-gate 
2065*7c478bd9Sstevel@tonic-gate 	if (i > MIN(SEGMAPSIZE, mmu_ptob(freemem)))
2066*7c478bd9Sstevel@tonic-gate 		i = MIN(SEGMAPSIZE, mmu_ptob(freemem));
2067*7c478bd9Sstevel@tonic-gate 
2068*7c478bd9Sstevel@tonic-gate 	i &= MAXBMASK;	/* 1201049: segkmap size must be MAXBSIZE aligned */
2069*7c478bd9Sstevel@tonic-gate 
2070*7c478bd9Sstevel@tonic-gate 	rw_enter(&kas.a_lock, RW_WRITER);
2071*7c478bd9Sstevel@tonic-gate 	if (seg_attach(&kas, va, i, segkmap) < 0)
2072*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_PANIC, "cannot attach segkmap");
2073*7c478bd9Sstevel@tonic-gate 
2074*7c478bd9Sstevel@tonic-gate 	a.prot = PROT_READ | PROT_WRITE;
2075*7c478bd9Sstevel@tonic-gate 	a.shmsize = shm_alignment;
2076*7c478bd9Sstevel@tonic-gate 	a.nfreelist = 0;	/* use segmap driver defaults */
2077*7c478bd9Sstevel@tonic-gate 
2078*7c478bd9Sstevel@tonic-gate 	if (segmap_create(segkmap, (caddr_t)&a) != 0)
2079*7c478bd9Sstevel@tonic-gate 		panic("segmap_create segkmap");
2080*7c478bd9Sstevel@tonic-gate 	rw_exit(&kas.a_lock);
2081*7c478bd9Sstevel@tonic-gate 
2082*7c478bd9Sstevel@tonic-gate 	segdev_init();
2083*7c478bd9Sstevel@tonic-gate }
2084*7c478bd9Sstevel@tonic-gate 
2085*7c478bd9Sstevel@tonic-gate static void
2086*7c478bd9Sstevel@tonic-gate startup_end(void)
2087*7c478bd9Sstevel@tonic-gate {
2088*7c478bd9Sstevel@tonic-gate 	if ((caddr_t)memlist > (caddr_t)memlist_end)
2089*7c478bd9Sstevel@tonic-gate 		panic("memlist overflow 2");
2090*7c478bd9Sstevel@tonic-gate 	memlist_free_block((caddr_t)memlist,
2091*7c478bd9Sstevel@tonic-gate 	    ((caddr_t)memlist_end - (caddr_t)memlist));
2092*7c478bd9Sstevel@tonic-gate 	memlist = NULL;
2093*7c478bd9Sstevel@tonic-gate 
2094*7c478bd9Sstevel@tonic-gate 	/* enable page_relocation since OBP is now done */
2095*7c478bd9Sstevel@tonic-gate 	page_relocate_ready = 1;
2096*7c478bd9Sstevel@tonic-gate 
2097*7c478bd9Sstevel@tonic-gate 	/*
2098*7c478bd9Sstevel@tonic-gate 	 * Perform tasks that get done after most of the VM
2099*7c478bd9Sstevel@tonic-gate 	 * initialization has been done but before the clock
2100*7c478bd9Sstevel@tonic-gate 	 * and other devices get started.
2101*7c478bd9Sstevel@tonic-gate 	 */
2102*7c478bd9Sstevel@tonic-gate 	kern_setup1();
2103*7c478bd9Sstevel@tonic-gate 
2104*7c478bd9Sstevel@tonic-gate 	/*
2105*7c478bd9Sstevel@tonic-gate 	 * Intialize the VM arenas for allocating physically
2106*7c478bd9Sstevel@tonic-gate 	 * contiguus memory chunk for interrupt queues snd
2107*7c478bd9Sstevel@tonic-gate 	 * allocate/register boot cpu's queues, if any and
2108*7c478bd9Sstevel@tonic-gate 	 * allocate dump buffer for sun4v systems to store
2109*7c478bd9Sstevel@tonic-gate 	 * extra crash information during crash dump
2110*7c478bd9Sstevel@tonic-gate 	 */
2111*7c478bd9Sstevel@tonic-gate 	contig_mem_init();
2112*7c478bd9Sstevel@tonic-gate 	mach_descrip_init();
2113*7c478bd9Sstevel@tonic-gate 	cpu_intrq_setup(CPU);
2114*7c478bd9Sstevel@tonic-gate 	cpu_intrq_register(CPU);
2115*7c478bd9Sstevel@tonic-gate 	mach_dump_buffer_init();
2116*7c478bd9Sstevel@tonic-gate 
2117*7c478bd9Sstevel@tonic-gate 	/*
2118*7c478bd9Sstevel@tonic-gate 	 * Initialize interrupt related stuff
2119*7c478bd9Sstevel@tonic-gate 	 */
2120*7c478bd9Sstevel@tonic-gate 	init_intr_threads(CPU);
2121*7c478bd9Sstevel@tonic-gate 
2122*7c478bd9Sstevel@tonic-gate 	(void) splzs();			/* allow hi clock ints but not zs */
2123*7c478bd9Sstevel@tonic-gate 
2124*7c478bd9Sstevel@tonic-gate 	/*
2125*7c478bd9Sstevel@tonic-gate 	 * Initialize errors.
2126*7c478bd9Sstevel@tonic-gate 	 */
2127*7c478bd9Sstevel@tonic-gate 	error_init();
2128*7c478bd9Sstevel@tonic-gate 
2129*7c478bd9Sstevel@tonic-gate 	/*
2130*7c478bd9Sstevel@tonic-gate 	 * Note that we may have already used kernel bcopy before this
2131*7c478bd9Sstevel@tonic-gate 	 * point - but if you really care about this, adb the use_hw_*
2132*7c478bd9Sstevel@tonic-gate 	 * variables to 0 before rebooting.
2133*7c478bd9Sstevel@tonic-gate 	 */
2134*7c478bd9Sstevel@tonic-gate 	mach_hw_copy_limit();
2135*7c478bd9Sstevel@tonic-gate 
2136*7c478bd9Sstevel@tonic-gate 	/*
2137*7c478bd9Sstevel@tonic-gate 	 * Install the "real" preemption guards before DDI services
2138*7c478bd9Sstevel@tonic-gate 	 * are available.
2139*7c478bd9Sstevel@tonic-gate 	 */
2140*7c478bd9Sstevel@tonic-gate 	(void) prom_set_preprom(kern_preprom);
2141*7c478bd9Sstevel@tonic-gate 	(void) prom_set_postprom(kern_postprom);
2142*7c478bd9Sstevel@tonic-gate 	CPU->cpu_m.mutex_ready = 1;
2143*7c478bd9Sstevel@tonic-gate 
2144*7c478bd9Sstevel@tonic-gate 	/*
2145*7c478bd9Sstevel@tonic-gate 	 * Initialize segnf (kernel support for non-faulting loads).
2146*7c478bd9Sstevel@tonic-gate 	 */
2147*7c478bd9Sstevel@tonic-gate 	segnf_init();
2148*7c478bd9Sstevel@tonic-gate 
2149*7c478bd9Sstevel@tonic-gate 	/*
2150*7c478bd9Sstevel@tonic-gate 	 * Configure the root devinfo node.
2151*7c478bd9Sstevel@tonic-gate 	 */
2152*7c478bd9Sstevel@tonic-gate 	configure();		/* set up devices */
2153*7c478bd9Sstevel@tonic-gate 	mach_cpu_halt_idle();
2154*7c478bd9Sstevel@tonic-gate }
2155*7c478bd9Sstevel@tonic-gate 
2156*7c478bd9Sstevel@tonic-gate 
2157*7c478bd9Sstevel@tonic-gate void
2158*7c478bd9Sstevel@tonic-gate post_startup(void)
2159*7c478bd9Sstevel@tonic-gate {
2160*7c478bd9Sstevel@tonic-gate #ifdef	PTL1_PANIC_DEBUG
2161*7c478bd9Sstevel@tonic-gate 	extern void init_ptl1_thread(void);
2162*7c478bd9Sstevel@tonic-gate #endif	/* PTL1_PANIC_DEBUG */
2163*7c478bd9Sstevel@tonic-gate 	extern void abort_sequence_init(void);
2164*7c478bd9Sstevel@tonic-gate 
2165*7c478bd9Sstevel@tonic-gate 	/*
2166*7c478bd9Sstevel@tonic-gate 	 * Set the system wide, processor-specific flags to be passed
2167*7c478bd9Sstevel@tonic-gate 	 * to userland via the aux vector for performance hints and
2168*7c478bd9Sstevel@tonic-gate 	 * instruction set extensions.
2169*7c478bd9Sstevel@tonic-gate 	 */
2170*7c478bd9Sstevel@tonic-gate 	bind_hwcap();
2171*7c478bd9Sstevel@tonic-gate 
2172*7c478bd9Sstevel@tonic-gate 	/*
2173*7c478bd9Sstevel@tonic-gate 	 * Startup memory scrubber (if any)
2174*7c478bd9Sstevel@tonic-gate 	 */
2175*7c478bd9Sstevel@tonic-gate 	mach_memscrub();
2176*7c478bd9Sstevel@tonic-gate 
2177*7c478bd9Sstevel@tonic-gate 	/*
2178*7c478bd9Sstevel@tonic-gate 	 * Allocate soft interrupt to handle abort sequence.
2179*7c478bd9Sstevel@tonic-gate 	 */
2180*7c478bd9Sstevel@tonic-gate 	abort_sequence_init();
2181*7c478bd9Sstevel@tonic-gate 
2182*7c478bd9Sstevel@tonic-gate 	/*
2183*7c478bd9Sstevel@tonic-gate 	 * Configure the rest of the system.
2184*7c478bd9Sstevel@tonic-gate 	 * Perform forceloading tasks for /etc/system.
2185*7c478bd9Sstevel@tonic-gate 	 */
2186*7c478bd9Sstevel@tonic-gate 	(void) mod_sysctl(SYS_FORCELOAD, NULL);
2187*7c478bd9Sstevel@tonic-gate 	/*
2188*7c478bd9Sstevel@tonic-gate 	 * ON4.0: Force /proc module in until clock interrupt handle fixed
2189*7c478bd9Sstevel@tonic-gate 	 * ON4.0: This must be fixed or restated in /etc/systems.
2190*7c478bd9Sstevel@tonic-gate 	 */
2191*7c478bd9Sstevel@tonic-gate 	(void) modload("fs", "procfs");
2192*7c478bd9Sstevel@tonic-gate 
2193*7c478bd9Sstevel@tonic-gate 	if (&load_platform_drivers)
2194*7c478bd9Sstevel@tonic-gate 		load_platform_drivers();
2195*7c478bd9Sstevel@tonic-gate 
2196*7c478bd9Sstevel@tonic-gate 	/* load vis simulation module, if we are running w/fpu off */
2197*7c478bd9Sstevel@tonic-gate 	if (!fpu_exists) {
2198*7c478bd9Sstevel@tonic-gate 		if (modload("misc", "vis") == -1)
2199*7c478bd9Sstevel@tonic-gate 			halt("Can't load vis");
2200*7c478bd9Sstevel@tonic-gate 	}
2201*7c478bd9Sstevel@tonic-gate 
2202*7c478bd9Sstevel@tonic-gate 	mach_fpras();
2203*7c478bd9Sstevel@tonic-gate 
2204*7c478bd9Sstevel@tonic-gate 	maxmem = freemem;
2205*7c478bd9Sstevel@tonic-gate 
2206*7c478bd9Sstevel@tonic-gate #ifdef	PTL1_PANIC_DEBUG
2207*7c478bd9Sstevel@tonic-gate 	init_ptl1_thread();
2208*7c478bd9Sstevel@tonic-gate #endif	/* PTL1_PANIC_DEBUG */
2209*7c478bd9Sstevel@tonic-gate }
2210*7c478bd9Sstevel@tonic-gate 
2211*7c478bd9Sstevel@tonic-gate #ifdef	PTL1_PANIC_DEBUG
2212*7c478bd9Sstevel@tonic-gate int		ptl1_panic_test = 0;
2213*7c478bd9Sstevel@tonic-gate int		ptl1_panic_xc_one_test = 0;
2214*7c478bd9Sstevel@tonic-gate int		ptl1_panic_xc_all_test = 0;
2215*7c478bd9Sstevel@tonic-gate int		ptl1_panic_xt_one_test = 0;
2216*7c478bd9Sstevel@tonic-gate int		ptl1_panic_xt_all_test = 0;
2217*7c478bd9Sstevel@tonic-gate kthread_id_t	ptl1_thread_p = NULL;
2218*7c478bd9Sstevel@tonic-gate kcondvar_t	ptl1_cv;
2219*7c478bd9Sstevel@tonic-gate kmutex_t	ptl1_mutex;
2220*7c478bd9Sstevel@tonic-gate int		ptl1_recurse_count_threshold = 0x40;
2221*7c478bd9Sstevel@tonic-gate int		ptl1_recurse_trap_threshold = 0x3d;
2222*7c478bd9Sstevel@tonic-gate extern void	ptl1_recurse(int, int);
2223*7c478bd9Sstevel@tonic-gate extern void	ptl1_panic_xt(int, int);
2224*7c478bd9Sstevel@tonic-gate 
2225*7c478bd9Sstevel@tonic-gate /*
2226*7c478bd9Sstevel@tonic-gate  * Called once per second by timeout() to wake up
2227*7c478bd9Sstevel@tonic-gate  * the ptl1_panic thread to see if it should cause
2228*7c478bd9Sstevel@tonic-gate  * a trap to the ptl1_panic() code.
2229*7c478bd9Sstevel@tonic-gate  */
2230*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
2231*7c478bd9Sstevel@tonic-gate static void
2232*7c478bd9Sstevel@tonic-gate ptl1_wakeup(void *arg)
2233*7c478bd9Sstevel@tonic-gate {
2234*7c478bd9Sstevel@tonic-gate 	mutex_enter(&ptl1_mutex);
2235*7c478bd9Sstevel@tonic-gate 	cv_signal(&ptl1_cv);
2236*7c478bd9Sstevel@tonic-gate 	mutex_exit(&ptl1_mutex);
2237*7c478bd9Sstevel@tonic-gate }
2238*7c478bd9Sstevel@tonic-gate 
2239*7c478bd9Sstevel@tonic-gate /*
2240*7c478bd9Sstevel@tonic-gate  * ptl1_panic cross call function:
2241*7c478bd9Sstevel@tonic-gate  *     Needed because xc_one() and xc_some() can pass
2242*7c478bd9Sstevel@tonic-gate  *	64 bit args but ptl1_recurse() expects ints.
2243*7c478bd9Sstevel@tonic-gate  */
2244*7c478bd9Sstevel@tonic-gate static void
2245*7c478bd9Sstevel@tonic-gate ptl1_panic_xc(void)
2246*7c478bd9Sstevel@tonic-gate {
2247*7c478bd9Sstevel@tonic-gate 	ptl1_recurse(ptl1_recurse_count_threshold,
2248*7c478bd9Sstevel@tonic-gate 	    ptl1_recurse_trap_threshold);
2249*7c478bd9Sstevel@tonic-gate }
2250*7c478bd9Sstevel@tonic-gate 
2251*7c478bd9Sstevel@tonic-gate /*
2252*7c478bd9Sstevel@tonic-gate  * The ptl1 thread waits for a global flag to be set
2253*7c478bd9Sstevel@tonic-gate  * and uses the recurse thresholds to set the stack depth
2254*7c478bd9Sstevel@tonic-gate  * to cause a ptl1_panic() directly via a call to ptl1_recurse
2255*7c478bd9Sstevel@tonic-gate  * or indirectly via the cross call and cross trap functions.
2256*7c478bd9Sstevel@tonic-gate  *
2257*7c478bd9Sstevel@tonic-gate  * This is useful testing stack overflows and normal
2258*7c478bd9Sstevel@tonic-gate  * ptl1_panic() states with a know stack frame.
2259*7c478bd9Sstevel@tonic-gate  *
2260*7c478bd9Sstevel@tonic-gate  * ptl1_recurse() is an asm function in ptl1_panic.s that
2261*7c478bd9Sstevel@tonic-gate  * sets the {In, Local, Out, and Global} registers to a
2262*7c478bd9Sstevel@tonic-gate  * know state on the stack and just prior to causing a
2263*7c478bd9Sstevel@tonic-gate  * test ptl1_panic trap.
2264*7c478bd9Sstevel@tonic-gate  */
2265*7c478bd9Sstevel@tonic-gate static void
2266*7c478bd9Sstevel@tonic-gate ptl1_thread(void)
2267*7c478bd9Sstevel@tonic-gate {
2268*7c478bd9Sstevel@tonic-gate 	mutex_enter(&ptl1_mutex);
2269*7c478bd9Sstevel@tonic-gate 	while (ptl1_thread_p) {
2270*7c478bd9Sstevel@tonic-gate 		cpuset_t	other_cpus;
2271*7c478bd9Sstevel@tonic-gate 		int		cpu_id;
2272*7c478bd9Sstevel@tonic-gate 		int		my_cpu_id;
2273*7c478bd9Sstevel@tonic-gate 		int		target_cpu_id;
2274*7c478bd9Sstevel@tonic-gate 		int		target_found;
2275*7c478bd9Sstevel@tonic-gate 
2276*7c478bd9Sstevel@tonic-gate 		if (ptl1_panic_test) {
2277*7c478bd9Sstevel@tonic-gate 			ptl1_recurse(ptl1_recurse_count_threshold,
2278*7c478bd9Sstevel@tonic-gate 			    ptl1_recurse_trap_threshold);
2279*7c478bd9Sstevel@tonic-gate 		}
2280*7c478bd9Sstevel@tonic-gate 
2281*7c478bd9Sstevel@tonic-gate 		/*
2282*7c478bd9Sstevel@tonic-gate 		 * Find potential targets for x-call and x-trap,
2283*7c478bd9Sstevel@tonic-gate 		 * if any exist while preempt is disabled we
2284*7c478bd9Sstevel@tonic-gate 		 * start a ptl1_panic if requested via a
2285*7c478bd9Sstevel@tonic-gate 		 * globals.
2286*7c478bd9Sstevel@tonic-gate 		 */
2287*7c478bd9Sstevel@tonic-gate 		kpreempt_disable();
2288*7c478bd9Sstevel@tonic-gate 		my_cpu_id = CPU->cpu_id;
2289*7c478bd9Sstevel@tonic-gate 		other_cpus = cpu_ready_set;
2290*7c478bd9Sstevel@tonic-gate 		CPUSET_DEL(other_cpus, CPU->cpu_id);
2291*7c478bd9Sstevel@tonic-gate 		target_found = 0;
2292*7c478bd9Sstevel@tonic-gate 		if (!CPUSET_ISNULL(other_cpus)) {
2293*7c478bd9Sstevel@tonic-gate 			/*
2294*7c478bd9Sstevel@tonic-gate 			 * Pick the first one
2295*7c478bd9Sstevel@tonic-gate 			 */
2296*7c478bd9Sstevel@tonic-gate 			for (cpu_id = 0; cpu_id < NCPU; cpu_id++) {
2297*7c478bd9Sstevel@tonic-gate 				if (cpu_id == my_cpu_id)
2298*7c478bd9Sstevel@tonic-gate 					continue;
2299*7c478bd9Sstevel@tonic-gate 
2300*7c478bd9Sstevel@tonic-gate 				if (CPU_XCALL_READY(cpu_id)) {
2301*7c478bd9Sstevel@tonic-gate 					target_cpu_id = cpu_id;
2302*7c478bd9Sstevel@tonic-gate 					target_found = 1;
2303*7c478bd9Sstevel@tonic-gate 					break;
2304*7c478bd9Sstevel@tonic-gate 				}
2305*7c478bd9Sstevel@tonic-gate 			}
2306*7c478bd9Sstevel@tonic-gate 			ASSERT(target_found);
2307*7c478bd9Sstevel@tonic-gate 
2308*7c478bd9Sstevel@tonic-gate 			if (ptl1_panic_xc_one_test) {
2309*7c478bd9Sstevel@tonic-gate 				xc_one(target_cpu_id,
2310*7c478bd9Sstevel@tonic-gate 				    (xcfunc_t *)ptl1_panic_xc, 0, 0);
2311*7c478bd9Sstevel@tonic-gate 			}
2312*7c478bd9Sstevel@tonic-gate 			if (ptl1_panic_xc_all_test) {
2313*7c478bd9Sstevel@tonic-gate 				xc_some(other_cpus,
2314*7c478bd9Sstevel@tonic-gate 				    (xcfunc_t *)ptl1_panic_xc, 0, 0);
2315*7c478bd9Sstevel@tonic-gate 			}
2316*7c478bd9Sstevel@tonic-gate 			if (ptl1_panic_xt_one_test) {
2317*7c478bd9Sstevel@tonic-gate 				xt_one(target_cpu_id,
2318*7c478bd9Sstevel@tonic-gate 				    (xcfunc_t *)ptl1_panic_xt, 0, 0);
2319*7c478bd9Sstevel@tonic-gate 			}
2320*7c478bd9Sstevel@tonic-gate 			if (ptl1_panic_xt_all_test) {
2321*7c478bd9Sstevel@tonic-gate 				xt_some(other_cpus,
2322*7c478bd9Sstevel@tonic-gate 				    (xcfunc_t *)ptl1_panic_xt, 0, 0);
2323*7c478bd9Sstevel@tonic-gate 			}
2324*7c478bd9Sstevel@tonic-gate 		}
2325*7c478bd9Sstevel@tonic-gate 		kpreempt_enable();
2326*7c478bd9Sstevel@tonic-gate 		(void) timeout(ptl1_wakeup, NULL, hz);
2327*7c478bd9Sstevel@tonic-gate 		(void) cv_wait(&ptl1_cv, &ptl1_mutex);
2328*7c478bd9Sstevel@tonic-gate 	}
2329*7c478bd9Sstevel@tonic-gate 	mutex_exit(&ptl1_mutex);
2330*7c478bd9Sstevel@tonic-gate }
2331*7c478bd9Sstevel@tonic-gate 
2332*7c478bd9Sstevel@tonic-gate /*
2333*7c478bd9Sstevel@tonic-gate  * Called during early startup to create the ptl1_thread
2334*7c478bd9Sstevel@tonic-gate  */
2335*7c478bd9Sstevel@tonic-gate void
2336*7c478bd9Sstevel@tonic-gate init_ptl1_thread(void)
2337*7c478bd9Sstevel@tonic-gate {
2338*7c478bd9Sstevel@tonic-gate 	ptl1_thread_p = thread_create(NULL, 0, ptl1_thread, NULL, 0,
2339*7c478bd9Sstevel@tonic-gate 	    &p0, TS_RUN, 0);
2340*7c478bd9Sstevel@tonic-gate }
2341*7c478bd9Sstevel@tonic-gate #endif	/* PTL1_PANIC_DEBUG */
2342*7c478bd9Sstevel@tonic-gate 
2343*7c478bd9Sstevel@tonic-gate 
2344*7c478bd9Sstevel@tonic-gate /*
2345*7c478bd9Sstevel@tonic-gate  * Add to a memory list.
2346*7c478bd9Sstevel@tonic-gate  * start = start of new memory segment
2347*7c478bd9Sstevel@tonic-gate  * len = length of new memory segment in bytes
2348*7c478bd9Sstevel@tonic-gate  * memlistp = pointer to array of available memory segment structures
2349*7c478bd9Sstevel@tonic-gate  * curmemlistp = memory list to which to add segment.
2350*7c478bd9Sstevel@tonic-gate  */
2351*7c478bd9Sstevel@tonic-gate static void
2352*7c478bd9Sstevel@tonic-gate memlist_add(uint64_t start, uint64_t len, struct memlist **memlistp,
2353*7c478bd9Sstevel@tonic-gate 	struct memlist **curmemlistp)
2354*7c478bd9Sstevel@tonic-gate {
2355*7c478bd9Sstevel@tonic-gate 	struct memlist *new;
2356*7c478bd9Sstevel@tonic-gate 
2357*7c478bd9Sstevel@tonic-gate 	new = *memlistp;
2358*7c478bd9Sstevel@tonic-gate 	new->address = start;
2359*7c478bd9Sstevel@tonic-gate 	new->size = len;
2360*7c478bd9Sstevel@tonic-gate 	*memlistp = new + 1;
2361*7c478bd9Sstevel@tonic-gate 
2362*7c478bd9Sstevel@tonic-gate 	memlist_insert(new, curmemlistp);
2363*7c478bd9Sstevel@tonic-gate }
2364*7c478bd9Sstevel@tonic-gate 
2365*7c478bd9Sstevel@tonic-gate /*
2366*7c478bd9Sstevel@tonic-gate  * In the case of architectures that support dynamic addition of
2367*7c478bd9Sstevel@tonic-gate  * memory at run-time there are two cases where memsegs need to
2368*7c478bd9Sstevel@tonic-gate  * be initialized and added to the memseg list.
2369*7c478bd9Sstevel@tonic-gate  * 1) memsegs that are constructed at startup.
2370*7c478bd9Sstevel@tonic-gate  * 2) memsegs that are constructed at run-time on
2371*7c478bd9Sstevel@tonic-gate  *    hot-plug capable architectures.
2372*7c478bd9Sstevel@tonic-gate  * This code was originally part of the function kphysm_init().
2373*7c478bd9Sstevel@tonic-gate  */
2374*7c478bd9Sstevel@tonic-gate 
2375*7c478bd9Sstevel@tonic-gate static void
2376*7c478bd9Sstevel@tonic-gate memseg_list_add(struct memseg *memsegp)
2377*7c478bd9Sstevel@tonic-gate {
2378*7c478bd9Sstevel@tonic-gate 	struct memseg **prev_memsegp;
2379*7c478bd9Sstevel@tonic-gate 	pgcnt_t num;
2380*7c478bd9Sstevel@tonic-gate 
2381*7c478bd9Sstevel@tonic-gate 	/* insert in memseg list, decreasing number of pages order */
2382*7c478bd9Sstevel@tonic-gate 
2383*7c478bd9Sstevel@tonic-gate 	num = MSEG_NPAGES(memsegp);
2384*7c478bd9Sstevel@tonic-gate 
2385*7c478bd9Sstevel@tonic-gate 	for (prev_memsegp = &memsegs; *prev_memsegp;
2386*7c478bd9Sstevel@tonic-gate 	    prev_memsegp = &((*prev_memsegp)->next)) {
2387*7c478bd9Sstevel@tonic-gate 		if (num > MSEG_NPAGES(*prev_memsegp))
2388*7c478bd9Sstevel@tonic-gate 			break;
2389*7c478bd9Sstevel@tonic-gate 	}
2390*7c478bd9Sstevel@tonic-gate 
2391*7c478bd9Sstevel@tonic-gate 	memsegp->next = *prev_memsegp;
2392*7c478bd9Sstevel@tonic-gate 	*prev_memsegp = memsegp;
2393*7c478bd9Sstevel@tonic-gate 
2394*7c478bd9Sstevel@tonic-gate 	if (kpm_enable) {
2395*7c478bd9Sstevel@tonic-gate 		memsegp->nextpa = (memsegp->next) ?
2396*7c478bd9Sstevel@tonic-gate 			va_to_pa(memsegp->next) : MSEG_NULLPTR_PA;
2397*7c478bd9Sstevel@tonic-gate 
2398*7c478bd9Sstevel@tonic-gate 		if (prev_memsegp != &memsegs) {
2399*7c478bd9Sstevel@tonic-gate 			struct memseg *msp;
2400*7c478bd9Sstevel@tonic-gate 			msp = (struct memseg *)((caddr_t)prev_memsegp -
2401*7c478bd9Sstevel@tonic-gate 				offsetof(struct memseg, next));
2402*7c478bd9Sstevel@tonic-gate 			msp->nextpa = va_to_pa(memsegp);
2403*7c478bd9Sstevel@tonic-gate 		} else {
2404*7c478bd9Sstevel@tonic-gate 			memsegspa = va_to_pa(memsegs);
2405*7c478bd9Sstevel@tonic-gate 		}
2406*7c478bd9Sstevel@tonic-gate 	}
2407*7c478bd9Sstevel@tonic-gate }
2408*7c478bd9Sstevel@tonic-gate 
2409*7c478bd9Sstevel@tonic-gate /*
2410*7c478bd9Sstevel@tonic-gate  * PSM add_physmem_cb(). US-II and newer processors have some
2411*7c478bd9Sstevel@tonic-gate  * flavor of the prefetch capability implemented. We exploit
2412*7c478bd9Sstevel@tonic-gate  * this capability for optimum performance.
2413*7c478bd9Sstevel@tonic-gate  */
2414*7c478bd9Sstevel@tonic-gate #define	PREFETCH_BYTES	64
2415*7c478bd9Sstevel@tonic-gate 
2416*7c478bd9Sstevel@tonic-gate void
2417*7c478bd9Sstevel@tonic-gate add_physmem_cb(page_t *pp, pfn_t pnum)
2418*7c478bd9Sstevel@tonic-gate {
2419*7c478bd9Sstevel@tonic-gate 	extern void	 prefetch_page_w(void *);
2420*7c478bd9Sstevel@tonic-gate 
2421*7c478bd9Sstevel@tonic-gate 	pp->p_pagenum = pnum;
2422*7c478bd9Sstevel@tonic-gate 
2423*7c478bd9Sstevel@tonic-gate 	/*
2424*7c478bd9Sstevel@tonic-gate 	 * Prefetch one more page_t into E$. To prevent future
2425*7c478bd9Sstevel@tonic-gate 	 * mishaps with the sizeof(page_t) changing on us, we
2426*7c478bd9Sstevel@tonic-gate 	 * catch this on debug kernels if we can't bring in the
2427*7c478bd9Sstevel@tonic-gate 	 * entire hpage with 2 PREFETCH_BYTES reads. See
2428*7c478bd9Sstevel@tonic-gate 	 * also, sun4u/cpu/cpu_module.c
2429*7c478bd9Sstevel@tonic-gate 	 */
2430*7c478bd9Sstevel@tonic-gate 	/*LINTED*/
2431*7c478bd9Sstevel@tonic-gate 	ASSERT(sizeof (page_t) <= 2*PREFETCH_BYTES);
2432*7c478bd9Sstevel@tonic-gate 	prefetch_page_w((char *)pp);
2433*7c478bd9Sstevel@tonic-gate }
2434*7c478bd9Sstevel@tonic-gate 
2435*7c478bd9Sstevel@tonic-gate /*
2436*7c478bd9Sstevel@tonic-gate  * kphysm_init() tackles the problem of initializing physical memory.
2437*7c478bd9Sstevel@tonic-gate  * The old startup made some assumptions about the kernel living in
2438*7c478bd9Sstevel@tonic-gate  * physically contiguous space which is no longer valid.
2439*7c478bd9Sstevel@tonic-gate  */
2440*7c478bd9Sstevel@tonic-gate static void
2441*7c478bd9Sstevel@tonic-gate kphysm_init(page_t *pp, struct memseg *memsegp, pgcnt_t npages,
2442*7c478bd9Sstevel@tonic-gate 	uintptr_t kpm_pp, pgcnt_t kpm_npages)
2443*7c478bd9Sstevel@tonic-gate {
2444*7c478bd9Sstevel@tonic-gate 	struct memlist	*pmem;
2445*7c478bd9Sstevel@tonic-gate 	struct memseg	*msp;
2446*7c478bd9Sstevel@tonic-gate 	pfn_t		 base;
2447*7c478bd9Sstevel@tonic-gate 	pgcnt_t		 num;
2448*7c478bd9Sstevel@tonic-gate 	pfn_t		 lastseg_pages_end = 0;
2449*7c478bd9Sstevel@tonic-gate 	pgcnt_t		 nelem_used = 0;
2450*7c478bd9Sstevel@tonic-gate 
2451*7c478bd9Sstevel@tonic-gate 	ASSERT(page_hash != NULL && page_hashsz != 0);
2452*7c478bd9Sstevel@tonic-gate 
2453*7c478bd9Sstevel@tonic-gate 	msp = memsegp;
2454*7c478bd9Sstevel@tonic-gate 	for (pmem = phys_avail; pmem && npages; pmem = pmem->next) {
2455*7c478bd9Sstevel@tonic-gate 
2456*7c478bd9Sstevel@tonic-gate 		/*
2457*7c478bd9Sstevel@tonic-gate 		 * Build the memsegs entry
2458*7c478bd9Sstevel@tonic-gate 		 */
2459*7c478bd9Sstevel@tonic-gate 		num = btop(pmem->size);
2460*7c478bd9Sstevel@tonic-gate 		if (num > npages)
2461*7c478bd9Sstevel@tonic-gate 			num = npages;
2462*7c478bd9Sstevel@tonic-gate 		npages -= num;
2463*7c478bd9Sstevel@tonic-gate 		base = btop(pmem->address);
2464*7c478bd9Sstevel@tonic-gate 
2465*7c478bd9Sstevel@tonic-gate 		msp->pages = pp;
2466*7c478bd9Sstevel@tonic-gate 		msp->epages = pp + num;
2467*7c478bd9Sstevel@tonic-gate 		msp->pages_base = base;
2468*7c478bd9Sstevel@tonic-gate 		msp->pages_end = base + num;
2469*7c478bd9Sstevel@tonic-gate 
2470*7c478bd9Sstevel@tonic-gate 		if (kpm_enable) {
2471*7c478bd9Sstevel@tonic-gate 			pfn_t pbase_a;
2472*7c478bd9Sstevel@tonic-gate 			pfn_t pend_a;
2473*7c478bd9Sstevel@tonic-gate 			pfn_t prev_pend_a;
2474*7c478bd9Sstevel@tonic-gate 			pgcnt_t	nelem;
2475*7c478bd9Sstevel@tonic-gate 
2476*7c478bd9Sstevel@tonic-gate 			msp->pagespa = va_to_pa(pp);
2477*7c478bd9Sstevel@tonic-gate 			msp->epagespa = va_to_pa(pp + num);
2478*7c478bd9Sstevel@tonic-gate 			pbase_a = kpmptop(ptokpmp(base));
2479*7c478bd9Sstevel@tonic-gate 			pend_a = kpmptop(ptokpmp(base + num - 1)) + kpmpnpgs;
2480*7c478bd9Sstevel@tonic-gate 			nelem = ptokpmp(pend_a - pbase_a);
2481*7c478bd9Sstevel@tonic-gate 			msp->kpm_nkpmpgs = nelem;
2482*7c478bd9Sstevel@tonic-gate 			msp->kpm_pbase = pbase_a;
2483*7c478bd9Sstevel@tonic-gate 			if (lastseg_pages_end) {
2484*7c478bd9Sstevel@tonic-gate 				/*
2485*7c478bd9Sstevel@tonic-gate 				 * Assume phys_avail is in ascending order
2486*7c478bd9Sstevel@tonic-gate 				 * of physical addresses.
2487*7c478bd9Sstevel@tonic-gate 				 */
2488*7c478bd9Sstevel@tonic-gate 				ASSERT(base + num > lastseg_pages_end);
2489*7c478bd9Sstevel@tonic-gate 				prev_pend_a = kpmptop(
2490*7c478bd9Sstevel@tonic-gate 				    ptokpmp(lastseg_pages_end - 1)) + kpmpnpgs;
2491*7c478bd9Sstevel@tonic-gate 
2492*7c478bd9Sstevel@tonic-gate 				if (prev_pend_a > pbase_a) {
2493*7c478bd9Sstevel@tonic-gate 					/*
2494*7c478bd9Sstevel@tonic-gate 					 * Overlap, more than one memseg may
2495*7c478bd9Sstevel@tonic-gate 					 * point to the same kpm_page range.
2496*7c478bd9Sstevel@tonic-gate 					 */
2497*7c478bd9Sstevel@tonic-gate 					if (kpm_smallpages == 0) {
2498*7c478bd9Sstevel@tonic-gate 						msp->kpm_pages =
2499*7c478bd9Sstevel@tonic-gate 						    (kpm_page_t *)kpm_pp - 1;
2500*7c478bd9Sstevel@tonic-gate 						kpm_pp = (uintptr_t)
2501*7c478bd9Sstevel@tonic-gate 							((kpm_page_t *)kpm_pp
2502*7c478bd9Sstevel@tonic-gate 							+ nelem - 1);
2503*7c478bd9Sstevel@tonic-gate 					} else {
2504*7c478bd9Sstevel@tonic-gate 						msp->kpm_spages =
2505*7c478bd9Sstevel@tonic-gate 						    (kpm_spage_t *)kpm_pp - 1;
2506*7c478bd9Sstevel@tonic-gate 						kpm_pp = (uintptr_t)
2507*7c478bd9Sstevel@tonic-gate 							((kpm_spage_t *)kpm_pp
2508*7c478bd9Sstevel@tonic-gate 							+ nelem - 1);
2509*7c478bd9Sstevel@tonic-gate 					}
2510*7c478bd9Sstevel@tonic-gate 					nelem_used += nelem - 1;
2511*7c478bd9Sstevel@tonic-gate 
2512*7c478bd9Sstevel@tonic-gate 				} else {
2513*7c478bd9Sstevel@tonic-gate 					if (kpm_smallpages == 0) {
2514*7c478bd9Sstevel@tonic-gate 						msp->kpm_pages =
2515*7c478bd9Sstevel@tonic-gate 						    (kpm_page_t *)kpm_pp;
2516*7c478bd9Sstevel@tonic-gate 						kpm_pp = (uintptr_t)
2517*7c478bd9Sstevel@tonic-gate 							((kpm_page_t *)kpm_pp
2518*7c478bd9Sstevel@tonic-gate 							+ nelem);
2519*7c478bd9Sstevel@tonic-gate 					} else {
2520*7c478bd9Sstevel@tonic-gate 						msp->kpm_spages =
2521*7c478bd9Sstevel@tonic-gate 						    (kpm_spage_t *)kpm_pp;
2522*7c478bd9Sstevel@tonic-gate 						kpm_pp = (uintptr_t)
2523*7c478bd9Sstevel@tonic-gate 							((kpm_spage_t *)
2524*7c478bd9Sstevel@tonic-gate 							kpm_pp + nelem);
2525*7c478bd9Sstevel@tonic-gate 					}
2526*7c478bd9Sstevel@tonic-gate 					nelem_used += nelem;
2527*7c478bd9Sstevel@tonic-gate 				}
2528*7c478bd9Sstevel@tonic-gate 
2529*7c478bd9Sstevel@tonic-gate 			} else {
2530*7c478bd9Sstevel@tonic-gate 				if (kpm_smallpages == 0) {
2531*7c478bd9Sstevel@tonic-gate 					msp->kpm_pages = (kpm_page_t *)kpm_pp;
2532*7c478bd9Sstevel@tonic-gate 					kpm_pp = (uintptr_t)
2533*7c478bd9Sstevel@tonic-gate 						((kpm_page_t *)kpm_pp + nelem);
2534*7c478bd9Sstevel@tonic-gate 				} else {
2535*7c478bd9Sstevel@tonic-gate 					msp->kpm_spages = (kpm_spage_t *)kpm_pp;
2536*7c478bd9Sstevel@tonic-gate 					kpm_pp = (uintptr_t)
2537*7c478bd9Sstevel@tonic-gate 						((kpm_spage_t *)kpm_pp + nelem);
2538*7c478bd9Sstevel@tonic-gate 				}
2539*7c478bd9Sstevel@tonic-gate 				nelem_used = nelem;
2540*7c478bd9Sstevel@tonic-gate 			}
2541*7c478bd9Sstevel@tonic-gate 
2542*7c478bd9Sstevel@tonic-gate 			if (nelem_used > kpm_npages)
2543*7c478bd9Sstevel@tonic-gate 				panic("kphysm_init: kpm_pp overflow\n");
2544*7c478bd9Sstevel@tonic-gate 
2545*7c478bd9Sstevel@tonic-gate 			msp->kpm_pagespa = va_to_pa(msp->kpm_pages);
2546*7c478bd9Sstevel@tonic-gate 			lastseg_pages_end = msp->pages_end;
2547*7c478bd9Sstevel@tonic-gate 		}
2548*7c478bd9Sstevel@tonic-gate 
2549*7c478bd9Sstevel@tonic-gate 		memseg_list_add(msp);
2550*7c478bd9Sstevel@tonic-gate 
2551*7c478bd9Sstevel@tonic-gate 		/*
2552*7c478bd9Sstevel@tonic-gate 		 * add_physmem() initializes the PSM part of the page
2553*7c478bd9Sstevel@tonic-gate 		 * struct by calling the PSM back with add_physmem_cb().
2554*7c478bd9Sstevel@tonic-gate 		 * In addition it coalesces pages into larger pages as
2555*7c478bd9Sstevel@tonic-gate 		 * it initializes them.
2556*7c478bd9Sstevel@tonic-gate 		 */
2557*7c478bd9Sstevel@tonic-gate 		add_physmem(pp, num, base);
2558*7c478bd9Sstevel@tonic-gate 		pp += num;
2559*7c478bd9Sstevel@tonic-gate 		msp++;
2560*7c478bd9Sstevel@tonic-gate 	}
2561*7c478bd9Sstevel@tonic-gate 
2562*7c478bd9Sstevel@tonic-gate 	build_pfn_hash();
2563*7c478bd9Sstevel@tonic-gate }
2564*7c478bd9Sstevel@tonic-gate 
2565*7c478bd9Sstevel@tonic-gate /*
2566*7c478bd9Sstevel@tonic-gate  * Kernel VM initialization.
2567*7c478bd9Sstevel@tonic-gate  * Assumptions about kernel address space ordering:
2568*7c478bd9Sstevel@tonic-gate  *	(1) gap (user space)
2569*7c478bd9Sstevel@tonic-gate  *	(2) kernel text
2570*7c478bd9Sstevel@tonic-gate  *	(3) kernel data/bss
2571*7c478bd9Sstevel@tonic-gate  *	(4) gap
2572*7c478bd9Sstevel@tonic-gate  *	(5) kernel data structures
2573*7c478bd9Sstevel@tonic-gate  *	(6) gap
2574*7c478bd9Sstevel@tonic-gate  *	(7) debugger (optional)
2575*7c478bd9Sstevel@tonic-gate  *	(8) monitor
2576*7c478bd9Sstevel@tonic-gate  *	(9) gap (possibly null)
2577*7c478bd9Sstevel@tonic-gate  *	(10) dvma
2578*7c478bd9Sstevel@tonic-gate  *	(11) devices
2579*7c478bd9Sstevel@tonic-gate  */
2580*7c478bd9Sstevel@tonic-gate static void
2581*7c478bd9Sstevel@tonic-gate kvm_init(void)
2582*7c478bd9Sstevel@tonic-gate {
2583*7c478bd9Sstevel@tonic-gate 	/*
2584*7c478bd9Sstevel@tonic-gate 	 * Put the kernel segments in kernel address space.
2585*7c478bd9Sstevel@tonic-gate 	 */
2586*7c478bd9Sstevel@tonic-gate 	rw_enter(&kas.a_lock, RW_WRITER);
2587*7c478bd9Sstevel@tonic-gate 	as_avlinit(&kas);
2588*7c478bd9Sstevel@tonic-gate 
2589*7c478bd9Sstevel@tonic-gate 	(void) seg_attach(&kas, (caddr_t)KERNELBASE,
2590*7c478bd9Sstevel@tonic-gate 	    (size_t)(e_moddata - KERNELBASE), &ktextseg);
2591*7c478bd9Sstevel@tonic-gate 	(void) segkmem_create(&ktextseg);
2592*7c478bd9Sstevel@tonic-gate 
2593*7c478bd9Sstevel@tonic-gate 	(void) seg_attach(&kas, (caddr_t)(KERNELBASE + MMU_PAGESIZE4M),
2594*7c478bd9Sstevel@tonic-gate 	    (size_t)(MMU_PAGESIZE4M), &ktexthole);
2595*7c478bd9Sstevel@tonic-gate 	(void) segkmem_create(&ktexthole);
2596*7c478bd9Sstevel@tonic-gate 
2597*7c478bd9Sstevel@tonic-gate 	(void) seg_attach(&kas, (caddr_t)valloc_base,
2598*7c478bd9Sstevel@tonic-gate 	    (size_t)(econtig32 - valloc_base), &kvalloc);
2599*7c478bd9Sstevel@tonic-gate 	(void) segkmem_create(&kvalloc);
2600*7c478bd9Sstevel@tonic-gate 
2601*7c478bd9Sstevel@tonic-gate 	if (kmem64_base) {
2602*7c478bd9Sstevel@tonic-gate 	    (void) seg_attach(&kas, (caddr_t)kmem64_base,
2603*7c478bd9Sstevel@tonic-gate 		(size_t)(kmem64_end - kmem64_base), &kmem64);
2604*7c478bd9Sstevel@tonic-gate 	    (void) segkmem_create(&kmem64);
2605*7c478bd9Sstevel@tonic-gate 	}
2606*7c478bd9Sstevel@tonic-gate 
2607*7c478bd9Sstevel@tonic-gate 	/*
2608*7c478bd9Sstevel@tonic-gate 	 * We're about to map out /boot.  This is the beginning of the
2609*7c478bd9Sstevel@tonic-gate 	 * system resource management transition. We can no longer
2610*7c478bd9Sstevel@tonic-gate 	 * call into /boot for I/O or memory allocations.
2611*7c478bd9Sstevel@tonic-gate 	 */
2612*7c478bd9Sstevel@tonic-gate 	(void) seg_attach(&kas, kernelheap, ekernelheap - kernelheap, &kvseg);
2613*7c478bd9Sstevel@tonic-gate 	(void) segkmem_create(&kvseg);
2614*7c478bd9Sstevel@tonic-gate 	hblk_alloc_dynamic = 1;
2615*7c478bd9Sstevel@tonic-gate 
2616*7c478bd9Sstevel@tonic-gate 	/*
2617*7c478bd9Sstevel@tonic-gate 	 * we need to preallocate pages for DR operations before enabling large
2618*7c478bd9Sstevel@tonic-gate 	 * page kernel heap because of memseg_remap_init() hat_unload() hack.
2619*7c478bd9Sstevel@tonic-gate 	 */
2620*7c478bd9Sstevel@tonic-gate 	memseg_remap_init();
2621*7c478bd9Sstevel@tonic-gate 
2622*7c478bd9Sstevel@tonic-gate 	/* at this point we are ready to use large page heap */
2623*7c478bd9Sstevel@tonic-gate 	segkmem_heap_lp_init();
2624*7c478bd9Sstevel@tonic-gate 
2625*7c478bd9Sstevel@tonic-gate 	(void) seg_attach(&kas, (caddr_t)SYSBASE32, SYSLIMIT32 - SYSBASE32,
2626*7c478bd9Sstevel@tonic-gate 	    &kvseg32);
2627*7c478bd9Sstevel@tonic-gate 	(void) segkmem_create(&kvseg32);
2628*7c478bd9Sstevel@tonic-gate 
2629*7c478bd9Sstevel@tonic-gate 	/*
2630*7c478bd9Sstevel@tonic-gate 	 * Create a segment for the debugger.
2631*7c478bd9Sstevel@tonic-gate 	 */
2632*7c478bd9Sstevel@tonic-gate 	(void) seg_attach(&kas, (caddr_t)SEGDEBUGBASE, (size_t)SEGDEBUGSIZE,
2633*7c478bd9Sstevel@tonic-gate 	    &kdebugseg);
2634*7c478bd9Sstevel@tonic-gate 	(void) segkmem_create(&kdebugseg);
2635*7c478bd9Sstevel@tonic-gate 
2636*7c478bd9Sstevel@tonic-gate 	rw_exit(&kas.a_lock);
2637*7c478bd9Sstevel@tonic-gate }
2638*7c478bd9Sstevel@tonic-gate 
2639*7c478bd9Sstevel@tonic-gate char obp_tte_str[] =
2640*7c478bd9Sstevel@tonic-gate 	"h# %x constant MMU_PAGESHIFT "
2641*7c478bd9Sstevel@tonic-gate 	"h# %x constant TTE8K "
2642*7c478bd9Sstevel@tonic-gate 	"h# %x constant SFHME_SIZE "
2643*7c478bd9Sstevel@tonic-gate 	"h# %x constant SFHME_TTE "
2644*7c478bd9Sstevel@tonic-gate 	"h# %x constant HMEBLK_TAG "
2645*7c478bd9Sstevel@tonic-gate 	"h# %x constant HMEBLK_NEXT "
2646*7c478bd9Sstevel@tonic-gate 	"h# %x constant HMEBLK_MISC "
2647*7c478bd9Sstevel@tonic-gate 	"h# %x constant HMEBLK_HME1 "
2648*7c478bd9Sstevel@tonic-gate 	"h# %x constant NHMENTS "
2649*7c478bd9Sstevel@tonic-gate 	"h# %x constant HBLK_SZMASK "
2650*7c478bd9Sstevel@tonic-gate 	"h# %x constant HBLK_RANGE_SHIFT "
2651*7c478bd9Sstevel@tonic-gate 	"h# %x constant HMEBP_HBLK "
2652*7c478bd9Sstevel@tonic-gate 	"h# %x constant HMEBUCKET_SIZE "
2653*7c478bd9Sstevel@tonic-gate 	"h# %x constant HTAG_SFMMUPSZ "
2654*7c478bd9Sstevel@tonic-gate 	"h# %x constant HTAG_REHASHSZ "
2655*7c478bd9Sstevel@tonic-gate 	"h# %x constant mmu_hashcnt "
2656*7c478bd9Sstevel@tonic-gate 	"h# %p constant uhme_hash "
2657*7c478bd9Sstevel@tonic-gate 	"h# %p constant khme_hash "
2658*7c478bd9Sstevel@tonic-gate 	"h# %x constant UHMEHASH_SZ "
2659*7c478bd9Sstevel@tonic-gate 	"h# %x constant KHMEHASH_SZ "
2660*7c478bd9Sstevel@tonic-gate 	"h# %p constant KHATID "
2661*7c478bd9Sstevel@tonic-gate 	"h# %x constant CTX_SIZE "
2662*7c478bd9Sstevel@tonic-gate 	"h# %x constant CTX_SFMMU "
2663*7c478bd9Sstevel@tonic-gate 	"h# %p constant ctxs "
2664*7c478bd9Sstevel@tonic-gate 	"h# %x constant ASI_MEM "
2665*7c478bd9Sstevel@tonic-gate 
2666*7c478bd9Sstevel@tonic-gate 	": PHYS-X@ ( phys -- data ) "
2667*7c478bd9Sstevel@tonic-gate 	"   ASI_MEM spacex@ "
2668*7c478bd9Sstevel@tonic-gate 	"; "
2669*7c478bd9Sstevel@tonic-gate 
2670*7c478bd9Sstevel@tonic-gate 	": PHYS-W@ ( phys -- data ) "
2671*7c478bd9Sstevel@tonic-gate 	"   ASI_MEM spacew@ "
2672*7c478bd9Sstevel@tonic-gate 	"; "
2673*7c478bd9Sstevel@tonic-gate 
2674*7c478bd9Sstevel@tonic-gate 	": PHYS-L@ ( phys -- data ) "
2675*7c478bd9Sstevel@tonic-gate 	"   ASI_MEM spaceL@ "
2676*7c478bd9Sstevel@tonic-gate 	"; "
2677*7c478bd9Sstevel@tonic-gate 
2678*7c478bd9Sstevel@tonic-gate 	": TTE_PAGE_SHIFT ( ttesz -- hmeshift ) "
2679*7c478bd9Sstevel@tonic-gate 	"   3 * MMU_PAGESHIFT + "
2680*7c478bd9Sstevel@tonic-gate 	"; "
2681*7c478bd9Sstevel@tonic-gate 
2682*7c478bd9Sstevel@tonic-gate 	": TTE_IS_VALID ( ttep -- flag ) "
2683*7c478bd9Sstevel@tonic-gate 	"   PHYS-X@ 0< "
2684*7c478bd9Sstevel@tonic-gate 	"; "
2685*7c478bd9Sstevel@tonic-gate 
2686*7c478bd9Sstevel@tonic-gate 	": HME_HASH_SHIFT ( ttesz -- hmeshift ) "
2687*7c478bd9Sstevel@tonic-gate 	"   dup TTE8K =  if "
2688*7c478bd9Sstevel@tonic-gate 	"      drop HBLK_RANGE_SHIFT "
2689*7c478bd9Sstevel@tonic-gate 	"   else "
2690*7c478bd9Sstevel@tonic-gate 	"      TTE_PAGE_SHIFT "
2691*7c478bd9Sstevel@tonic-gate 	"   then "
2692*7c478bd9Sstevel@tonic-gate 	"; "
2693*7c478bd9Sstevel@tonic-gate 
2694*7c478bd9Sstevel@tonic-gate 	": HME_HASH_BSPAGE ( addr hmeshift -- bspage ) "
2695*7c478bd9Sstevel@tonic-gate 	"   tuck >> swap MMU_PAGESHIFT - << "
2696*7c478bd9Sstevel@tonic-gate 	"; "
2697*7c478bd9Sstevel@tonic-gate 
2698*7c478bd9Sstevel@tonic-gate 	": HME_HASH_FUNCTION ( sfmmup addr hmeshift -- hmebp ) "
2699*7c478bd9Sstevel@tonic-gate 	"   >> over xor swap                    ( hash sfmmup ) "
2700*7c478bd9Sstevel@tonic-gate 	"   KHATID <>  if                       ( hash ) "
2701*7c478bd9Sstevel@tonic-gate 	"      UHMEHASH_SZ and                  ( bucket ) "
2702*7c478bd9Sstevel@tonic-gate 	"      HMEBUCKET_SIZE * uhme_hash +     ( hmebp ) "
2703*7c478bd9Sstevel@tonic-gate 	"   else                                ( hash ) "
2704*7c478bd9Sstevel@tonic-gate 	"      KHMEHASH_SZ and                  ( bucket ) "
2705*7c478bd9Sstevel@tonic-gate 	"      HMEBUCKET_SIZE * khme_hash +     ( hmebp ) "
2706*7c478bd9Sstevel@tonic-gate 	"   then                                ( hmebp ) "
2707*7c478bd9Sstevel@tonic-gate 	"; "
2708*7c478bd9Sstevel@tonic-gate 
2709*7c478bd9Sstevel@tonic-gate 	": HME_HASH_TABLE_SEARCH "
2710*7c478bd9Sstevel@tonic-gate 	"       ( sfmmup hmebp hblktag --  sfmmup null | sfmmup hmeblkp ) "
2711*7c478bd9Sstevel@tonic-gate 	"   >r hmebp_hblk + phys-x@ begin ( sfmmup hmeblkp ) ( r: hblktag ) "
2712*7c478bd9Sstevel@tonic-gate 	"      dup if   		( sfmmup hmeblkp ) ( r: hblktag ) "
2713*7c478bd9Sstevel@tonic-gate 	"         dup hmeblk_tag + phys-x@ r@ = if ( sfmmup hmeblkp )	  "
2714*7c478bd9Sstevel@tonic-gate 	"	     dup hmeblk_tag + 8 + phys-x@ 2 pick = if		  "
2715*7c478bd9Sstevel@tonic-gate 	"		  true 	( sfmmup hmeblkp true ) ( r: hblktag )	  "
2716*7c478bd9Sstevel@tonic-gate 	"	     else						  "
2717*7c478bd9Sstevel@tonic-gate 	"	     	  hmeblk_next + phys-x@ false 			  "
2718*7c478bd9Sstevel@tonic-gate 	"			( sfmmup hmeblkp false ) ( r: hblktag )   "
2719*7c478bd9Sstevel@tonic-gate 	"	     then  						  "
2720*7c478bd9Sstevel@tonic-gate 	"	  else							  "
2721*7c478bd9Sstevel@tonic-gate 	"	     hmeblk_next + phys-x@ false 			  "
2722*7c478bd9Sstevel@tonic-gate 	"			( sfmmup hmeblkp false ) ( r: hblktag )   "
2723*7c478bd9Sstevel@tonic-gate 	"	  then 							  "
2724*7c478bd9Sstevel@tonic-gate 	"      else							  "
2725*7c478bd9Sstevel@tonic-gate 	"         true 							  "
2726*7c478bd9Sstevel@tonic-gate 	"      then  							  "
2727*7c478bd9Sstevel@tonic-gate 	"   until r> drop 						  "
2728*7c478bd9Sstevel@tonic-gate 	"; "
2729*7c478bd9Sstevel@tonic-gate 
2730*7c478bd9Sstevel@tonic-gate 	": CNUM_TO_SFMMUP ( cnum -- sfmmup ) "
2731*7c478bd9Sstevel@tonic-gate 	"   CTX_SIZE * ctxs + CTX_SFMMU + "
2732*7c478bd9Sstevel@tonic-gate 	"x@ "
2733*7c478bd9Sstevel@tonic-gate 	"; "
2734*7c478bd9Sstevel@tonic-gate 
2735*7c478bd9Sstevel@tonic-gate 	": HME_HASH_TAG ( sfmmup rehash addr -- hblktag ) "
2736*7c478bd9Sstevel@tonic-gate 	"   over HME_HASH_SHIFT HME_HASH_BSPAGE      ( sfmmup rehash bspage ) "
2737*7c478bd9Sstevel@tonic-gate 	"   HTAG_REHASHSZ << or nip		     ( hblktag ) "
2738*7c478bd9Sstevel@tonic-gate 	"; "
2739*7c478bd9Sstevel@tonic-gate 
2740*7c478bd9Sstevel@tonic-gate 	": HBLK_TO_TTEP ( hmeblkp addr -- ttep ) "
2741*7c478bd9Sstevel@tonic-gate 	"   over HMEBLK_MISC + PHYS-L@ HBLK_SZMASK and  ( hmeblkp addr ttesz ) "
2742*7c478bd9Sstevel@tonic-gate 	"   TTE8K =  if                            ( hmeblkp addr ) "
2743*7c478bd9Sstevel@tonic-gate 	"      MMU_PAGESHIFT >> NHMENTS 1- and     ( hmeblkp hme-index ) "
2744*7c478bd9Sstevel@tonic-gate 	"   else                                   ( hmeblkp addr ) "
2745*7c478bd9Sstevel@tonic-gate 	"      drop 0                              ( hmeblkp 0 ) "
2746*7c478bd9Sstevel@tonic-gate 	"   then                                   ( hmeblkp hme-index ) "
2747*7c478bd9Sstevel@tonic-gate 	"   SFHME_SIZE * + HMEBLK_HME1 +           ( hmep ) "
2748*7c478bd9Sstevel@tonic-gate 	"   SFHME_TTE +                            ( ttep ) "
2749*7c478bd9Sstevel@tonic-gate 	"; "
2750*7c478bd9Sstevel@tonic-gate 
2751*7c478bd9Sstevel@tonic-gate 	": unix-tte ( addr cnum -- false | tte-data true ) "
2752*7c478bd9Sstevel@tonic-gate 	"      CNUM_TO_SFMMUP                 ( addr sfmmup ) "
2753*7c478bd9Sstevel@tonic-gate 	"      mmu_hashcnt 1+ 1  do           ( addr sfmmup ) "
2754*7c478bd9Sstevel@tonic-gate 	"         2dup swap i HME_HASH_SHIFT  "
2755*7c478bd9Sstevel@tonic-gate 					"( addr sfmmup sfmmup addr hmeshift ) "
2756*7c478bd9Sstevel@tonic-gate 	"         HME_HASH_FUNCTION           ( addr sfmmup hmebp ) "
2757*7c478bd9Sstevel@tonic-gate 	"         over i 4 pick               "
2758*7c478bd9Sstevel@tonic-gate 				"( addr sfmmup hmebp sfmmup rehash addr ) "
2759*7c478bd9Sstevel@tonic-gate 	"         HME_HASH_TAG                ( addr sfmmup hmebp hblktag ) "
2760*7c478bd9Sstevel@tonic-gate 	"         HME_HASH_TABLE_SEARCH       "
2761*7c478bd9Sstevel@tonic-gate 					"( addr sfmmup { null | hmeblkp } ) "
2762*7c478bd9Sstevel@tonic-gate 	"         ?dup  if                    ( addr sfmmup hmeblkp ) "
2763*7c478bd9Sstevel@tonic-gate 	"            nip swap HBLK_TO_TTEP    ( ttep ) "
2764*7c478bd9Sstevel@tonic-gate 	"            dup TTE_IS_VALID  if     ( valid-ttep ) "
2765*7c478bd9Sstevel@tonic-gate 	"               PHYS-X@ true          ( tte-data true ) "
2766*7c478bd9Sstevel@tonic-gate 	"            else                     ( invalid-tte ) "
2767*7c478bd9Sstevel@tonic-gate 	"               drop false            ( false ) "
2768*7c478bd9Sstevel@tonic-gate 	"            then                     ( false | tte-data true ) "
2769*7c478bd9Sstevel@tonic-gate 	"            unloop exit              ( false | tte-data true ) "
2770*7c478bd9Sstevel@tonic-gate 	"         then                        ( addr sfmmup ) "
2771*7c478bd9Sstevel@tonic-gate 	"      loop                           ( addr sfmmup ) "
2772*7c478bd9Sstevel@tonic-gate 	"      2drop false                    ( false ) "
2773*7c478bd9Sstevel@tonic-gate 	"; "
2774*7c478bd9Sstevel@tonic-gate ;
2775*7c478bd9Sstevel@tonic-gate 
2776*7c478bd9Sstevel@tonic-gate void
2777*7c478bd9Sstevel@tonic-gate create_va_to_tte(void)
2778*7c478bd9Sstevel@tonic-gate {
2779*7c478bd9Sstevel@tonic-gate 	char *bp;
2780*7c478bd9Sstevel@tonic-gate 	extern int khmehash_num, uhmehash_num;
2781*7c478bd9Sstevel@tonic-gate 	extern struct hmehash_bucket *khme_hash, *uhme_hash;
2782*7c478bd9Sstevel@tonic-gate 
2783*7c478bd9Sstevel@tonic-gate #define	OFFSET(type, field)	((uintptr_t)(&((type *)0)->field))
2784*7c478bd9Sstevel@tonic-gate 
2785*7c478bd9Sstevel@tonic-gate 	bp = (char *)kobj_zalloc(MMU_PAGESIZE, KM_SLEEP);
2786*7c478bd9Sstevel@tonic-gate 
2787*7c478bd9Sstevel@tonic-gate 	/*
2788*7c478bd9Sstevel@tonic-gate 	 * Teach obp how to parse our sw ttes.
2789*7c478bd9Sstevel@tonic-gate 	 */
2790*7c478bd9Sstevel@tonic-gate 	(void) sprintf(bp, obp_tte_str,
2791*7c478bd9Sstevel@tonic-gate 	    MMU_PAGESHIFT,
2792*7c478bd9Sstevel@tonic-gate 	    TTE8K,
2793*7c478bd9Sstevel@tonic-gate 	    sizeof (struct sf_hment),
2794*7c478bd9Sstevel@tonic-gate 	    OFFSET(struct sf_hment, hme_tte),
2795*7c478bd9Sstevel@tonic-gate 	    OFFSET(struct hme_blk, hblk_tag),
2796*7c478bd9Sstevel@tonic-gate 	    OFFSET(struct hme_blk, hblk_nextpa),
2797*7c478bd9Sstevel@tonic-gate 	    OFFSET(struct hme_blk, hblk_misc),
2798*7c478bd9Sstevel@tonic-gate 	    OFFSET(struct hme_blk, hblk_hme),
2799*7c478bd9Sstevel@tonic-gate 	    NHMENTS,
2800*7c478bd9Sstevel@tonic-gate 	    HBLK_SZMASK,
2801*7c478bd9Sstevel@tonic-gate 	    HBLK_RANGE_SHIFT,
2802*7c478bd9Sstevel@tonic-gate 	    OFFSET(struct hmehash_bucket, hmeh_nextpa),
2803*7c478bd9Sstevel@tonic-gate 	    sizeof (struct hmehash_bucket),
2804*7c478bd9Sstevel@tonic-gate 	    HTAG_SFMMUPSZ,
2805*7c478bd9Sstevel@tonic-gate 	    HTAG_REHASHSZ,
2806*7c478bd9Sstevel@tonic-gate 	    mmu_hashcnt,
2807*7c478bd9Sstevel@tonic-gate 	    (caddr_t)va_to_pa((caddr_t)uhme_hash),
2808*7c478bd9Sstevel@tonic-gate 	    (caddr_t)va_to_pa((caddr_t)khme_hash),
2809*7c478bd9Sstevel@tonic-gate 	    UHMEHASH_SZ,
2810*7c478bd9Sstevel@tonic-gate 	    KHMEHASH_SZ,
2811*7c478bd9Sstevel@tonic-gate 	    KHATID,
2812*7c478bd9Sstevel@tonic-gate 	    sizeof (struct ctx),
2813*7c478bd9Sstevel@tonic-gate 	    OFFSET(struct ctx, ctx_sfmmu),
2814*7c478bd9Sstevel@tonic-gate 	    ctxs,
2815*7c478bd9Sstevel@tonic-gate 	    ASI_MEM);
2816*7c478bd9Sstevel@tonic-gate 	prom_interpret(bp, 0, 0, 0, 0, 0);
2817*7c478bd9Sstevel@tonic-gate 
2818*7c478bd9Sstevel@tonic-gate 	kobj_free(bp, MMU_PAGESIZE);
2819*7c478bd9Sstevel@tonic-gate }
2820*7c478bd9Sstevel@tonic-gate 
2821*7c478bd9Sstevel@tonic-gate void
2822*7c478bd9Sstevel@tonic-gate install_va_to_tte(void)
2823*7c478bd9Sstevel@tonic-gate {
2824*7c478bd9Sstevel@tonic-gate 	/*
2825*7c478bd9Sstevel@tonic-gate 	 * advise prom that he can use unix-tte
2826*7c478bd9Sstevel@tonic-gate 	 */
2827*7c478bd9Sstevel@tonic-gate 	prom_interpret("' unix-tte is va>tte-data", 0, 0, 0, 0, 0);
2828*7c478bd9Sstevel@tonic-gate }
2829*7c478bd9Sstevel@tonic-gate 
2830*7c478bd9Sstevel@tonic-gate 
2831*7c478bd9Sstevel@tonic-gate static char *create_node =
2832*7c478bd9Sstevel@tonic-gate 	"root-device "
2833*7c478bd9Sstevel@tonic-gate 	"new-device "
2834*7c478bd9Sstevel@tonic-gate 	"\" os-io\" device-name "
2835*7c478bd9Sstevel@tonic-gate 	": cb-r/w  ( adr,len method$ -- #read/#written ) "
2836*7c478bd9Sstevel@tonic-gate 	"   2>r swap 2 2r> ['] $callback  catch  if "
2837*7c478bd9Sstevel@tonic-gate 	"      2drop 3drop 0 "
2838*7c478bd9Sstevel@tonic-gate 	"   then "
2839*7c478bd9Sstevel@tonic-gate 	"; "
2840*7c478bd9Sstevel@tonic-gate 	": read ( adr,len -- #read ) "
2841*7c478bd9Sstevel@tonic-gate 	"       \" read\" ['] cb-r/w catch  if  2drop 2drop -2 exit then "
2842*7c478bd9Sstevel@tonic-gate 	"       ( retN ... ret1 N ) "
2843*7c478bd9Sstevel@tonic-gate 	"       ?dup  if "
2844*7c478bd9Sstevel@tonic-gate 	"               swap >r 1-  0  ?do  drop  loop  r> "
2845*7c478bd9Sstevel@tonic-gate 	"       else "
2846*7c478bd9Sstevel@tonic-gate 	"               -2 "
2847*7c478bd9Sstevel@tonic-gate 	"       then l->n "
2848*7c478bd9Sstevel@tonic-gate 	";    "
2849*7c478bd9Sstevel@tonic-gate 	": write ( adr,len -- #written ) "
2850*7c478bd9Sstevel@tonic-gate 	"       \" write\" ['] cb-r/w catch  if  2drop 2drop 0 exit  then "
2851*7c478bd9Sstevel@tonic-gate 	"       ( retN ... ret1 N ) "
2852*7c478bd9Sstevel@tonic-gate 	"       ?dup  if "
2853*7c478bd9Sstevel@tonic-gate 	"               swap >r 1-  0  ?do  drop  loop  r> "
2854*7c478bd9Sstevel@tonic-gate 	"        else "
2855*7c478bd9Sstevel@tonic-gate 	"               0 "
2856*7c478bd9Sstevel@tonic-gate 	"       then "
2857*7c478bd9Sstevel@tonic-gate 	"; "
2858*7c478bd9Sstevel@tonic-gate 	": poll-tty ( -- ) ; "
2859*7c478bd9Sstevel@tonic-gate 	": install-abort  ( -- )  ['] poll-tty d# 10 alarm ; "
2860*7c478bd9Sstevel@tonic-gate 	": remove-abort ( -- )  ['] poll-tty 0 alarm ; "
2861*7c478bd9Sstevel@tonic-gate 	": cb-give/take ( $method -- ) "
2862*7c478bd9Sstevel@tonic-gate 	"       0 -rot ['] $callback catch  ?dup  if "
2863*7c478bd9Sstevel@tonic-gate 	"               >r 2drop 2drop r> throw "
2864*7c478bd9Sstevel@tonic-gate 	"       else "
2865*7c478bd9Sstevel@tonic-gate 	"               0  ?do  drop  loop "
2866*7c478bd9Sstevel@tonic-gate 	"       then "
2867*7c478bd9Sstevel@tonic-gate 	"; "
2868*7c478bd9Sstevel@tonic-gate 	": give ( -- )  \" exit-input\" cb-give/take ; "
2869*7c478bd9Sstevel@tonic-gate 	": take ( -- )  \" enter-input\" cb-give/take ; "
2870*7c478bd9Sstevel@tonic-gate 	": open ( -- ok? )  true ; "
2871*7c478bd9Sstevel@tonic-gate 	": close ( -- ) ; "
2872*7c478bd9Sstevel@tonic-gate 	"finish-device "
2873*7c478bd9Sstevel@tonic-gate 	"device-end ";
2874*7c478bd9Sstevel@tonic-gate 
2875*7c478bd9Sstevel@tonic-gate /*
2876*7c478bd9Sstevel@tonic-gate  * Create the obp input/output node only if the USB keyboard is the
2877*7c478bd9Sstevel@tonic-gate  * standard input device.  When the USB software takes over the
2878*7c478bd9Sstevel@tonic-gate  * input device at the time consconfig runs, it will switch OBP's
2879*7c478bd9Sstevel@tonic-gate  * notion of the input device to this node.  Whenever the
2880*7c478bd9Sstevel@tonic-gate  * forth user interface is used after this switch, the node will
2881*7c478bd9Sstevel@tonic-gate  * call back into the kernel for console input.
2882*7c478bd9Sstevel@tonic-gate  *
2883*7c478bd9Sstevel@tonic-gate  * This callback mechanism is currently only used when the USB keyboard
2884*7c478bd9Sstevel@tonic-gate  * is the input device.  If a serial device such as ttya or
2885*7c478bd9Sstevel@tonic-gate  * a UART with a Type 5 keyboard attached is used, obp takes over the
2886*7c478bd9Sstevel@tonic-gate  * serial device when the system goes to the debugger after the system is
2887*7c478bd9Sstevel@tonic-gate  * booted.  This sharing of the relatively simple serial device is difficult
2888*7c478bd9Sstevel@tonic-gate  * but possible.  Sharing the USB host controller is impossible due
2889*7c478bd9Sstevel@tonic-gate  * its complexity
2890*7c478bd9Sstevel@tonic-gate  */
2891*7c478bd9Sstevel@tonic-gate static void
2892*7c478bd9Sstevel@tonic-gate startup_create_input_node(void)
2893*7c478bd9Sstevel@tonic-gate {
2894*7c478bd9Sstevel@tonic-gate 	char *stdin_path;
2895*7c478bd9Sstevel@tonic-gate 
2896*7c478bd9Sstevel@tonic-gate 	/*
2897*7c478bd9Sstevel@tonic-gate 	 * If usb_node_debug is set in /etc/system
2898*7c478bd9Sstevel@tonic-gate 	 * then the user would like to test the callbacks
2899*7c478bd9Sstevel@tonic-gate 	 * from the input node regardless of whether or
2900*7c478bd9Sstevel@tonic-gate 	 * not the USB keyboard is the console input.
2901*7c478bd9Sstevel@tonic-gate 	 * This variable is useful for debugging.
2902*7c478bd9Sstevel@tonic-gate 	 */
2903*7c478bd9Sstevel@tonic-gate 	if (usb_node_debug) {
2904*7c478bd9Sstevel@tonic-gate 
2905*7c478bd9Sstevel@tonic-gate 		prom_interpret(create_node, 0, 0, 0, 0, 0);
2906*7c478bd9Sstevel@tonic-gate 
2907*7c478bd9Sstevel@tonic-gate 		return;
2908*7c478bd9Sstevel@tonic-gate 	}
2909*7c478bd9Sstevel@tonic-gate 
2910*7c478bd9Sstevel@tonic-gate 	/* Obtain the console input device */
2911*7c478bd9Sstevel@tonic-gate 	stdin_path = prom_stdinpath();
2912*7c478bd9Sstevel@tonic-gate 
2913*7c478bd9Sstevel@tonic-gate 	/*
2914*7c478bd9Sstevel@tonic-gate 	 * If the string "usb" and "keyboard" are in the path
2915*7c478bd9Sstevel@tonic-gate 	 * then a USB keyboard is the console input device,
2916*7c478bd9Sstevel@tonic-gate 	 * create the node.
2917*7c478bd9Sstevel@tonic-gate 	 */
2918*7c478bd9Sstevel@tonic-gate 	if ((strstr(stdin_path, "usb") != 0) &&
2919*7c478bd9Sstevel@tonic-gate 	    (strstr(stdin_path, "keyboard") != 0)) {
2920*7c478bd9Sstevel@tonic-gate 
2921*7c478bd9Sstevel@tonic-gate 		prom_interpret(create_node, 0, 0, 0, 0, 0);
2922*7c478bd9Sstevel@tonic-gate 	}
2923*7c478bd9Sstevel@tonic-gate }
2924*7c478bd9Sstevel@tonic-gate 
2925*7c478bd9Sstevel@tonic-gate 
2926*7c478bd9Sstevel@tonic-gate static void
2927*7c478bd9Sstevel@tonic-gate do_prom_version_check(void)
2928*7c478bd9Sstevel@tonic-gate {
2929*7c478bd9Sstevel@tonic-gate 	int i;
2930*7c478bd9Sstevel@tonic-gate 	dnode_t node;
2931*7c478bd9Sstevel@tonic-gate 	char buf[64];
2932*7c478bd9Sstevel@tonic-gate 	static char drev[] = "Down-rev firmware detected%s\n"
2933*7c478bd9Sstevel@tonic-gate 		"\tPlease upgrade to the following minimum version:\n"
2934*7c478bd9Sstevel@tonic-gate 		"\t\t%s\n";
2935*7c478bd9Sstevel@tonic-gate 
2936*7c478bd9Sstevel@tonic-gate 	i = prom_version_check(buf, sizeof (buf), &node);
2937*7c478bd9Sstevel@tonic-gate 
2938*7c478bd9Sstevel@tonic-gate 	if (i == PROM_VER64_OK)
2939*7c478bd9Sstevel@tonic-gate 		return;
2940*7c478bd9Sstevel@tonic-gate 
2941*7c478bd9Sstevel@tonic-gate 	if (i == PROM_VER64_UPGRADE) {
2942*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, drev, "", buf);
2943*7c478bd9Sstevel@tonic-gate 
2944*7c478bd9Sstevel@tonic-gate #ifdef	DEBUG
2945*7c478bd9Sstevel@tonic-gate 		prom_enter_mon();	/* Type 'go' to continue */
2946*7c478bd9Sstevel@tonic-gate 		cmn_err(CE_WARN, "Booting with down-rev firmware\n");
2947*7c478bd9Sstevel@tonic-gate 		return;
2948*7c478bd9Sstevel@tonic-gate #else
2949*7c478bd9Sstevel@tonic-gate 		halt(0);
2950*7c478bd9Sstevel@tonic-gate #endif
2951*7c478bd9Sstevel@tonic-gate 	}
2952*7c478bd9Sstevel@tonic-gate 
2953*7c478bd9Sstevel@tonic-gate 	/*
2954*7c478bd9Sstevel@tonic-gate 	 * The other possibility is that this is a server running
2955*7c478bd9Sstevel@tonic-gate 	 * good firmware, but down-rev firmware was detected on at
2956*7c478bd9Sstevel@tonic-gate 	 * least one other cpu board. We just complain if we see
2957*7c478bd9Sstevel@tonic-gate 	 * that.
2958*7c478bd9Sstevel@tonic-gate 	 */
2959*7c478bd9Sstevel@tonic-gate 	cmn_err(CE_WARN, drev, " on one or more CPU boards", buf);
2960*7c478bd9Sstevel@tonic-gate }
2961*7c478bd9Sstevel@tonic-gate 
2962*7c478bd9Sstevel@tonic-gate static void
2963*7c478bd9Sstevel@tonic-gate kpm_init()
2964*7c478bd9Sstevel@tonic-gate {
2965*7c478bd9Sstevel@tonic-gate 	kpm_pgshft = (kpm_smallpages == 0) ? MMU_PAGESHIFT4M : MMU_PAGESHIFT;
2966*7c478bd9Sstevel@tonic-gate 	kpm_pgsz = 1ull << kpm_pgshft;
2967*7c478bd9Sstevel@tonic-gate 	kpm_pgoff = kpm_pgsz - 1;
2968*7c478bd9Sstevel@tonic-gate 	kpmp2pshft = kpm_pgshft - PAGESHIFT;
2969*7c478bd9Sstevel@tonic-gate 	kpmpnpgs = 1 << kpmp2pshft;
2970*7c478bd9Sstevel@tonic-gate 	ASSERT(((uintptr_t)kpm_vbase & (kpm_pgsz - 1)) == 0);
2971*7c478bd9Sstevel@tonic-gate }
2972*7c478bd9Sstevel@tonic-gate 
2973*7c478bd9Sstevel@tonic-gate void
2974*7c478bd9Sstevel@tonic-gate kpm_npages_setup(int memblocks)
2975*7c478bd9Sstevel@tonic-gate {
2976*7c478bd9Sstevel@tonic-gate 	/*
2977*7c478bd9Sstevel@tonic-gate 	 * npages can be scattered in a maximum of 'memblocks'
2978*7c478bd9Sstevel@tonic-gate 	 */
2979*7c478bd9Sstevel@tonic-gate 	kpm_npages = ptokpmpr(npages) + memblocks;
2980*7c478bd9Sstevel@tonic-gate }
2981*7c478bd9Sstevel@tonic-gate 
2982*7c478bd9Sstevel@tonic-gate /*
2983*7c478bd9Sstevel@tonic-gate  * Must be defined in platform dependent code.
2984*7c478bd9Sstevel@tonic-gate  */
2985*7c478bd9Sstevel@tonic-gate extern caddr_t modtext;
2986*7c478bd9Sstevel@tonic-gate extern size_t modtext_sz;
2987*7c478bd9Sstevel@tonic-gate extern caddr_t moddata;
2988*7c478bd9Sstevel@tonic-gate 
2989*7c478bd9Sstevel@tonic-gate #define	HEAPTEXT_ARENA(addr)	\
2990*7c478bd9Sstevel@tonic-gate 	((uintptr_t)(addr) < KERNELBASE + 2 * MMU_PAGESIZE4M ? 0 : \
2991*7c478bd9Sstevel@tonic-gate 	(((uintptr_t)(addr) - HEAPTEXT_BASE) / \
2992*7c478bd9Sstevel@tonic-gate 	(HEAPTEXT_MAPPED + HEAPTEXT_UNMAPPED) + 1))
2993*7c478bd9Sstevel@tonic-gate 
2994*7c478bd9Sstevel@tonic-gate #define	HEAPTEXT_OVERSIZED(addr)	\
2995*7c478bd9Sstevel@tonic-gate 	((uintptr_t)(addr) >= HEAPTEXT_BASE + HEAPTEXT_SIZE - HEAPTEXT_OVERSIZE)
2996*7c478bd9Sstevel@tonic-gate 
2997*7c478bd9Sstevel@tonic-gate vmem_t *texthole_source[HEAPTEXT_NARENAS];
2998*7c478bd9Sstevel@tonic-gate vmem_t *texthole_arena[HEAPTEXT_NARENAS];
2999*7c478bd9Sstevel@tonic-gate kmutex_t texthole_lock;
3000*7c478bd9Sstevel@tonic-gate 
3001*7c478bd9Sstevel@tonic-gate char kern_bootargs[OBP_MAXPATHLEN];
3002*7c478bd9Sstevel@tonic-gate 
3003*7c478bd9Sstevel@tonic-gate void
3004*7c478bd9Sstevel@tonic-gate kobj_vmem_init(vmem_t **text_arena, vmem_t **data_arena)
3005*7c478bd9Sstevel@tonic-gate {
3006*7c478bd9Sstevel@tonic-gate 	uintptr_t addr, limit;
3007*7c478bd9Sstevel@tonic-gate 
3008*7c478bd9Sstevel@tonic-gate 	addr = HEAPTEXT_BASE;
3009*7c478bd9Sstevel@tonic-gate 	limit = addr + HEAPTEXT_SIZE - HEAPTEXT_OVERSIZE;
3010*7c478bd9Sstevel@tonic-gate 
3011*7c478bd9Sstevel@tonic-gate 	/*
3012*7c478bd9Sstevel@tonic-gate 	 * Before we initialize the text_arena, we want to punch holes in the
3013*7c478bd9Sstevel@tonic-gate 	 * underlying heaptext_arena.  This guarantees that for any text
3014*7c478bd9Sstevel@tonic-gate 	 * address we can find a text hole less than HEAPTEXT_MAPPED away.
3015*7c478bd9Sstevel@tonic-gate 	 */
3016*7c478bd9Sstevel@tonic-gate 	for (; addr + HEAPTEXT_UNMAPPED <= limit;
3017*7c478bd9Sstevel@tonic-gate 	    addr += HEAPTEXT_MAPPED + HEAPTEXT_UNMAPPED) {
3018*7c478bd9Sstevel@tonic-gate 		(void) vmem_xalloc(heaptext_arena, HEAPTEXT_UNMAPPED, PAGESIZE,
3019*7c478bd9Sstevel@tonic-gate 		    0, 0, (void *)addr, (void *)(addr + HEAPTEXT_UNMAPPED),
3020*7c478bd9Sstevel@tonic-gate 		    VM_NOSLEEP | VM_BESTFIT | VM_PANIC);
3021*7c478bd9Sstevel@tonic-gate 	}
3022*7c478bd9Sstevel@tonic-gate 
3023*7c478bd9Sstevel@tonic-gate 	/*
3024*7c478bd9Sstevel@tonic-gate 	 * Allocate one page at the oversize to break up the text region
3025*7c478bd9Sstevel@tonic-gate 	 * from the oversized region.
3026*7c478bd9Sstevel@tonic-gate 	 */
3027*7c478bd9Sstevel@tonic-gate 	(void) vmem_xalloc(heaptext_arena, PAGESIZE, PAGESIZE, 0, 0,
3028*7c478bd9Sstevel@tonic-gate 	    (void *)limit, (void *)(limit + PAGESIZE),
3029*7c478bd9Sstevel@tonic-gate 	    VM_NOSLEEP | VM_BESTFIT | VM_PANIC);
3030*7c478bd9Sstevel@tonic-gate 
3031*7c478bd9Sstevel@tonic-gate 	*text_arena = vmem_create("module_text", modtext, modtext_sz,
3032*7c478bd9Sstevel@tonic-gate 	    sizeof (uintptr_t), segkmem_alloc, segkmem_free,
3033*7c478bd9Sstevel@tonic-gate 	    heaptext_arena, 0, VM_SLEEP);
3034*7c478bd9Sstevel@tonic-gate 	*data_arena = vmem_create("module_data", moddata, MODDATA, 1,
3035*7c478bd9Sstevel@tonic-gate 	    segkmem_alloc, segkmem_free, heap32_arena, 0, VM_SLEEP);
3036*7c478bd9Sstevel@tonic-gate }
3037*7c478bd9Sstevel@tonic-gate 
3038*7c478bd9Sstevel@tonic-gate caddr_t
3039*7c478bd9Sstevel@tonic-gate kobj_text_alloc(vmem_t *arena, size_t size)
3040*7c478bd9Sstevel@tonic-gate {
3041*7c478bd9Sstevel@tonic-gate 	caddr_t rval, better;
3042*7c478bd9Sstevel@tonic-gate 
3043*7c478bd9Sstevel@tonic-gate 	/*
3044*7c478bd9Sstevel@tonic-gate 	 * First, try a sleeping allocation.
3045*7c478bd9Sstevel@tonic-gate 	 */
3046*7c478bd9Sstevel@tonic-gate 	rval = vmem_alloc(arena, size, VM_SLEEP | VM_BESTFIT);
3047*7c478bd9Sstevel@tonic-gate 
3048*7c478bd9Sstevel@tonic-gate 	if (size >= HEAPTEXT_MAPPED || !HEAPTEXT_OVERSIZED(rval))
3049*7c478bd9Sstevel@tonic-gate 		return (rval);
3050*7c478bd9Sstevel@tonic-gate 
3051*7c478bd9Sstevel@tonic-gate 	/*
3052*7c478bd9Sstevel@tonic-gate 	 * We didn't get the area that we wanted.  We're going to try to do an
3053*7c478bd9Sstevel@tonic-gate 	 * allocation with explicit constraints.
3054*7c478bd9Sstevel@tonic-gate 	 */
3055*7c478bd9Sstevel@tonic-gate 	better = vmem_xalloc(arena, size, sizeof (uintptr_t), 0, 0, NULL,
3056*7c478bd9Sstevel@tonic-gate 	    (void *)(HEAPTEXT_BASE + HEAPTEXT_SIZE - HEAPTEXT_OVERSIZE),
3057*7c478bd9Sstevel@tonic-gate 	    VM_NOSLEEP | VM_BESTFIT);
3058*7c478bd9Sstevel@tonic-gate 
3059*7c478bd9Sstevel@tonic-gate 	if (better != NULL) {
3060*7c478bd9Sstevel@tonic-gate 		/*
3061*7c478bd9Sstevel@tonic-gate 		 * That worked.  Free our first attempt and return.
3062*7c478bd9Sstevel@tonic-gate 		 */
3063*7c478bd9Sstevel@tonic-gate 		vmem_free(arena, rval, size);
3064*7c478bd9Sstevel@tonic-gate 		return (better);
3065*7c478bd9Sstevel@tonic-gate 	}
3066*7c478bd9Sstevel@tonic-gate 
3067*7c478bd9Sstevel@tonic-gate 	/*
3068*7c478bd9Sstevel@tonic-gate 	 * That didn't work; we'll have to return our first attempt.
3069*7c478bd9Sstevel@tonic-gate 	 */
3070*7c478bd9Sstevel@tonic-gate 	return (rval);
3071*7c478bd9Sstevel@tonic-gate }
3072*7c478bd9Sstevel@tonic-gate 
3073*7c478bd9Sstevel@tonic-gate caddr_t
3074*7c478bd9Sstevel@tonic-gate kobj_texthole_alloc(caddr_t addr, size_t size)
3075*7c478bd9Sstevel@tonic-gate {
3076*7c478bd9Sstevel@tonic-gate 	int arena = HEAPTEXT_ARENA(addr);
3077*7c478bd9Sstevel@tonic-gate 	char c[30];
3078*7c478bd9Sstevel@tonic-gate 	uintptr_t base;
3079*7c478bd9Sstevel@tonic-gate 
3080*7c478bd9Sstevel@tonic-gate 	if (HEAPTEXT_OVERSIZED(addr)) {
3081*7c478bd9Sstevel@tonic-gate 		/*
3082*7c478bd9Sstevel@tonic-gate 		 * If this is an oversized allocation, there is no text hole
3083*7c478bd9Sstevel@tonic-gate 		 * available for it; return NULL.
3084*7c478bd9Sstevel@tonic-gate 		 */
3085*7c478bd9Sstevel@tonic-gate 		return (NULL);
3086*7c478bd9Sstevel@tonic-gate 	}
3087*7c478bd9Sstevel@tonic-gate 
3088*7c478bd9Sstevel@tonic-gate 	mutex_enter(&texthole_lock);
3089*7c478bd9Sstevel@tonic-gate 
3090*7c478bd9Sstevel@tonic-gate 	if (texthole_arena[arena] == NULL) {
3091*7c478bd9Sstevel@tonic-gate 		ASSERT(texthole_source[arena] == NULL);
3092*7c478bd9Sstevel@tonic-gate 
3093*7c478bd9Sstevel@tonic-gate 		if (arena == 0) {
3094*7c478bd9Sstevel@tonic-gate 			texthole_source[0] = vmem_create("module_text_holesrc",
3095*7c478bd9Sstevel@tonic-gate 			    (void *)(KERNELBASE + MMU_PAGESIZE4M),
3096*7c478bd9Sstevel@tonic-gate 			    MMU_PAGESIZE4M, PAGESIZE, NULL, NULL, NULL,
3097*7c478bd9Sstevel@tonic-gate 			    0, VM_SLEEP);
3098*7c478bd9Sstevel@tonic-gate 		} else {
3099*7c478bd9Sstevel@tonic-gate 			base = HEAPTEXT_BASE +
3100*7c478bd9Sstevel@tonic-gate 			    (arena - 1) * (HEAPTEXT_MAPPED + HEAPTEXT_UNMAPPED);
3101*7c478bd9Sstevel@tonic-gate 
3102*7c478bd9Sstevel@tonic-gate 			(void) snprintf(c, sizeof (c),
3103*7c478bd9Sstevel@tonic-gate 			    "heaptext_holesrc_%d", arena);
3104*7c478bd9Sstevel@tonic-gate 
3105*7c478bd9Sstevel@tonic-gate 			texthole_source[arena] = vmem_create(c, (void *)base,
3106*7c478bd9Sstevel@tonic-gate 			    HEAPTEXT_UNMAPPED, PAGESIZE, NULL, NULL, NULL,
3107*7c478bd9Sstevel@tonic-gate 			    0, VM_SLEEP);
3108*7c478bd9Sstevel@tonic-gate 		}
3109*7c478bd9Sstevel@tonic-gate 
3110*7c478bd9Sstevel@tonic-gate 		(void) snprintf(c, sizeof (c), "heaptext_hole_%d", arena);
3111*7c478bd9Sstevel@tonic-gate 
3112*7c478bd9Sstevel@tonic-gate 		texthole_arena[arena] = vmem_create(c, NULL, 0,
3113*7c478bd9Sstevel@tonic-gate 		    sizeof (uint32_t), segkmem_alloc_permanent, segkmem_free,
3114*7c478bd9Sstevel@tonic-gate 		    texthole_source[arena], 0, VM_SLEEP);
3115*7c478bd9Sstevel@tonic-gate 	}
3116*7c478bd9Sstevel@tonic-gate 
3117*7c478bd9Sstevel@tonic-gate 	mutex_exit(&texthole_lock);
3118*7c478bd9Sstevel@tonic-gate 
3119*7c478bd9Sstevel@tonic-gate 	ASSERT(texthole_arena[arena] != NULL);
3120*7c478bd9Sstevel@tonic-gate 	ASSERT(arena >= 0 && arena < HEAPTEXT_NARENAS);
3121*7c478bd9Sstevel@tonic-gate 	return (vmem_alloc(texthole_arena[arena], size,
3122*7c478bd9Sstevel@tonic-gate 	    VM_BESTFIT | VM_NOSLEEP));
3123*7c478bd9Sstevel@tonic-gate }
3124*7c478bd9Sstevel@tonic-gate 
3125*7c478bd9Sstevel@tonic-gate void
3126*7c478bd9Sstevel@tonic-gate kobj_texthole_free(caddr_t addr, size_t size)
3127*7c478bd9Sstevel@tonic-gate {
3128*7c478bd9Sstevel@tonic-gate 	int arena = HEAPTEXT_ARENA(addr);
3129*7c478bd9Sstevel@tonic-gate 
3130*7c478bd9Sstevel@tonic-gate 	ASSERT(arena >= 0 && arena < HEAPTEXT_NARENAS);
3131*7c478bd9Sstevel@tonic-gate 	ASSERT(texthole_arena[arena] != NULL);
3132*7c478bd9Sstevel@tonic-gate 	vmem_free(texthole_arena[arena], addr, size);
3133*7c478bd9Sstevel@tonic-gate }
3134