17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5100b72f4Sandrei * Common Development and Distribution License (the "License").
6100b72f4Sandrei * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
21d6694327SYuri Pankov
227c478bd9Sstevel@tonic-gate /*
230db3240dSStephen Hanson * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
249e3e4df2SGarrett D'Amore * Copyright 2012 DEY Storage Systems, Inc. All rights reserved.
25d6694327SYuri Pankov * Copyright 2017 Nexenta Systems, Inc.
26575694f6SJason King * Copyright 2020 Joyent, Inc.
27af868f46SMatthew Ahrens * Copyright (c) 2015 by Delphix. All rights reserved.
28860b5cc8Scneira * Copyright (c) 2020 Carlos Neira <cneirabustos@gmail.com>
29*7c63221aSAndy Fiddaman * Copyright 2025 Oxide Computer Company
307c478bd9Sstevel@tonic-gate */
31a3114836SGerry Liu /*
32a3114836SGerry Liu * Copyright (c) 2010, Intel Corporation.
33a3114836SGerry Liu * All rights reserved.
34a3114836SGerry Liu */
357c478bd9Sstevel@tonic-gate
367c478bd9Sstevel@tonic-gate #include <sys/types.h>
377c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
387c478bd9Sstevel@tonic-gate #include <sys/param.h>
397c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
407c478bd9Sstevel@tonic-gate #include <sys/signal.h>
417c478bd9Sstevel@tonic-gate #include <sys/systm.h>
427c478bd9Sstevel@tonic-gate #include <sys/user.h>
437c478bd9Sstevel@tonic-gate #include <sys/mman.h>
447c478bd9Sstevel@tonic-gate #include <sys/vm.h>
457c478bd9Sstevel@tonic-gate #include <sys/conf.h>
467c478bd9Sstevel@tonic-gate #include <sys/avintr.h>
477c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
487c478bd9Sstevel@tonic-gate #include <sys/disp.h>
497c478bd9Sstevel@tonic-gate #include <sys/class.h>
507c478bd9Sstevel@tonic-gate #include <sys/bitmap.h>
517c478bd9Sstevel@tonic-gate
527c478bd9Sstevel@tonic-gate #include <sys/privregs.h>
537c478bd9Sstevel@tonic-gate
547c478bd9Sstevel@tonic-gate #include <sys/proc.h>
557c478bd9Sstevel@tonic-gate #include <sys/buf.h>
567c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
57ae115bc7Smrj #include <sys/mem.h>
587c478bd9Sstevel@tonic-gate #include <sys/kstat.h>
597c478bd9Sstevel@tonic-gate
607c478bd9Sstevel@tonic-gate #include <sys/reboot.h>
617c478bd9Sstevel@tonic-gate
627c478bd9Sstevel@tonic-gate #include <sys/cred.h>
637c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
647c478bd9Sstevel@tonic-gate #include <sys/file.h>
657c478bd9Sstevel@tonic-gate
667c478bd9Sstevel@tonic-gate #include <sys/procfs.h>
677c478bd9Sstevel@tonic-gate
687c478bd9Sstevel@tonic-gate #include <sys/vfs.h>
697c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
707c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
717c478bd9Sstevel@tonic-gate #include <sys/debug.h>
727c478bd9Sstevel@tonic-gate #include <sys/kdi.h>
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate #include <sys/dumphdr.h>
757c478bd9Sstevel@tonic-gate #include <sys/bootconf.h>
76a3114836SGerry Liu #include <sys/memlist_plat.h>
777c478bd9Sstevel@tonic-gate #include <sys/varargs.h>
787c478bd9Sstevel@tonic-gate #include <sys/promif.h>
79fdcca78fSJoshua M. Clulow #include <sys/prom_debug.h>
80843e1988Sjohnlev #include <sys/modctl.h>
817c478bd9Sstevel@tonic-gate
827c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
837c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
847c478bd9Sstevel@tonic-gate #include <sys/ndi_impldefs.h>
857c478bd9Sstevel@tonic-gate #include <sys/ddidmareq.h>
867c478bd9Sstevel@tonic-gate #include <sys/psw.h>
877c478bd9Sstevel@tonic-gate #include <sys/regset.h>
887c478bd9Sstevel@tonic-gate #include <sys/clock.h>
897c478bd9Sstevel@tonic-gate #include <sys/pte.h>
907c478bd9Sstevel@tonic-gate #include <sys/tss.h>
917c478bd9Sstevel@tonic-gate #include <sys/stack.h>
927c478bd9Sstevel@tonic-gate #include <sys/trap.h>
937c478bd9Sstevel@tonic-gate #include <sys/fp.h>
941d03c31eSjohnlev #include <vm/kboot_mmu.h>
957c478bd9Sstevel@tonic-gate #include <vm/anon.h>
967c478bd9Sstevel@tonic-gate #include <vm/as.h>
977c478bd9Sstevel@tonic-gate #include <vm/page.h>
987c478bd9Sstevel@tonic-gate #include <vm/seg.h>
997c478bd9Sstevel@tonic-gate #include <vm/seg_dev.h>
1007c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h>
1017c478bd9Sstevel@tonic-gate #include <vm/seg_kpm.h>
1027c478bd9Sstevel@tonic-gate #include <vm/seg_map.h>
1037c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h>
1047c478bd9Sstevel@tonic-gate #include <vm/seg_kp.h>
1057c478bd9Sstevel@tonic-gate #include <sys/memnode.h>
1067c478bd9Sstevel@tonic-gate #include <vm/vm_dep.h>
1077c478bd9Sstevel@tonic-gate #include <sys/thread.h>
1087c478bd9Sstevel@tonic-gate #include <sys/sysconf.h>
1097c478bd9Sstevel@tonic-gate #include <sys/vm_machparam.h>
1107c478bd9Sstevel@tonic-gate #include <sys/archsystm.h>
1117c478bd9Sstevel@tonic-gate #include <sys/machsystm.h>
1127c478bd9Sstevel@tonic-gate #include <vm/hat.h>
1137c478bd9Sstevel@tonic-gate #include <vm/hat_i86.h>
1147c478bd9Sstevel@tonic-gate #include <sys/pmem.h>
1157c478bd9Sstevel@tonic-gate #include <sys/smp_impldefs.h>
1167c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h>
117a563a037Sbholler #include <sys/cpuvar.h>
1187c478bd9Sstevel@tonic-gate #include <sys/segments.h>
1197c478bd9Sstevel@tonic-gate #include <sys/clconf.h>
1207c478bd9Sstevel@tonic-gate #include <sys/kobj.h>
1217c478bd9Sstevel@tonic-gate #include <sys/kobj_lex.h>
1227c478bd9Sstevel@tonic-gate #include <sys/cpc_impl.h>
1237aec1d6eScindi #include <sys/cpu_module.h>
12484ab085aSmws #include <sys/smbios.h>
125ae115bc7Smrj #include <sys/debug_info.h>
1261d03c31eSjohnlev #include <sys/bootinfo.h>
127a288e5a9SJoshua M. Clulow #include <sys/ddi_periodic.h>
1285679c89fSjv227347 #include <sys/systeminfo.h>
12919397407SSherry Moore #include <sys/multiboot.h>
1300181461bSKeith M Wesolowski #include <sys/ramdisk.h>
131575694f6SJason King #include <sys/tsc.h>
132575694f6SJason King #include <sys/clock.h>
133ae115bc7Smrj
134843e1988Sjohnlev #ifdef __xpv
1351d03c31eSjohnlev
136843e1988Sjohnlev #include <sys/hypervisor.h>
137843e1988Sjohnlev #include <sys/xen_mmu.h>
138843e1988Sjohnlev #include <sys/evtchn_impl.h>
139843e1988Sjohnlev #include <sys/gnttab.h>
140843e1988Sjohnlev #include <sys/xpv_panic.h>
141843e1988Sjohnlev #include <xen/sys/xenbus_comms.h>
142843e1988Sjohnlev #include <xen/public/physdev.h>
143ae115bc7Smrj
1441d03c31eSjohnlev extern void xen_late_startup(void);
1451d03c31eSjohnlev
1461d03c31eSjohnlev struct xen_evt_data cpu0_evt_data;
1471d03c31eSjohnlev
148a3114836SGerry Liu #else /* __xpv */
149a3114836SGerry Liu #include <sys/memlist_impl.h>
150a3114836SGerry Liu
151a3114836SGerry Liu extern void mem_config_init(void);
1521d03c31eSjohnlev #endif /* __xpv */
1537c478bd9Sstevel@tonic-gate
1547c478bd9Sstevel@tonic-gate extern void progressbar_init(void);
1559acbbeafSnn35248 extern void brand_init(void);
15606fb6a36Sdv142724 extern void pcf_init(void);
1570e751525SEric Saxe extern void pg_init(void);
1586a59053bSAlex Wilson extern void ssp_init(void);
1597c478bd9Sstevel@tonic-gate
160d7d93655Sblakej extern int size_pse_array(pgcnt_t, int);
161d7d93655Sblakej
162ed5289f9SKen Erickson #if defined(_SOFT_HOSTID)
163ed5289f9SKen Erickson
164ed5289f9SKen Erickson static int32_t set_soft_hostid(void);
165ed5289f9SKen Erickson static char hostid_file[] = "/etc/hostid";
166ed5289f9SKen Erickson
167ed5289f9SKen Erickson #endif
168ed5289f9SKen Erickson
16994f1124eSVikram Hegde void *gfx_devinfo_list;
170ed5289f9SKen Erickson
17186ef0a63SRichard Lowe #if !defined(__xpv)
1723a634bfcSVikram Hegde extern void immu_startup(void);
1733a634bfcSVikram Hegde #endif
1743a634bfcSVikram Hegde
1757c478bd9Sstevel@tonic-gate /*
1767c478bd9Sstevel@tonic-gate * XXX make declaration below "static" when drivers no longer use this
1777c478bd9Sstevel@tonic-gate * interface.
1787c478bd9Sstevel@tonic-gate */
1797c478bd9Sstevel@tonic-gate extern caddr_t p0_va; /* Virtual address for accessing physical page 0 */
1807c478bd9Sstevel@tonic-gate
1817c478bd9Sstevel@tonic-gate /*
1827c478bd9Sstevel@tonic-gate * segkp
1837c478bd9Sstevel@tonic-gate */
1847c478bd9Sstevel@tonic-gate extern int segkp_fromheap;
1857c478bd9Sstevel@tonic-gate
1867c478bd9Sstevel@tonic-gate static void kvm_init(void);
1877c478bd9Sstevel@tonic-gate static void startup_init(void);
1887c478bd9Sstevel@tonic-gate static void startup_memlist(void);
189ae115bc7Smrj static void startup_kmem(void);
1907c478bd9Sstevel@tonic-gate static void startup_modules(void);
1917c478bd9Sstevel@tonic-gate static void startup_vm(void);
192575694f6SJason King #ifndef __xpv
193575694f6SJason King static void startup_tsc(void);
194575694f6SJason King #endif
1957c478bd9Sstevel@tonic-gate static void startup_end(void);
19635b1ab99Sjosephb static void layout_kernel_va(void);
1977c478bd9Sstevel@tonic-gate
1987c478bd9Sstevel@tonic-gate /*
1997c478bd9Sstevel@tonic-gate * Declare these as initialized data so we can patch them.
2007c478bd9Sstevel@tonic-gate */
20135b1ab99Sjosephb
20235b1ab99Sjosephb /*
20335b1ab99Sjosephb * For now we can handle memory with physical addresses up to about
20435b1ab99Sjosephb * 64 Terabytes. This keeps the kernel above the VA hole, leaving roughly
20535b1ab99Sjosephb * half the VA space for seg_kpm. When systems get bigger than 64TB this
20635b1ab99Sjosephb * code will need revisiting. There is an implicit assumption that there
20735b1ab99Sjosephb * are no *huge* holes in the physical address space too.
20835b1ab99Sjosephb */
20935b1ab99Sjosephb #define TERABYTE (1ul << 40)
21035b1ab99Sjosephb #define PHYSMEM_MAX64 mmu_btop(64 * TERABYTE)
21135b1ab99Sjosephb #define PHYSMEM PHYSMEM_MAX64
21235b1ab99Sjosephb #define AMD64_VA_HOLE_END 0xFFFF800000000000ul
21335b1ab99Sjosephb
21435b1ab99Sjosephb
21535b1ab99Sjosephb pgcnt_t physmem = PHYSMEM;
2167c478bd9Sstevel@tonic-gate pgcnt_t obp_pages; /* Memory used by PROM for its text and data */
2177c478bd9Sstevel@tonic-gate
2180b35c8bcSToomas Soome extern char *kobj_file_buf;
2190b35c8bcSToomas Soome extern int kobj_file_bufsize; /* set in /etc/system */
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate /* Global variables for MP support. Used in mp_startup */
22219397407SSherry Moore caddr_t rm_platter_va = 0;
2237c478bd9Sstevel@tonic-gate uint32_t rm_platter_pa;
2247c478bd9Sstevel@tonic-gate
22583f9b804Skchow int auto_lpg_disable = 1;
22683f9b804Skchow
2277c478bd9Sstevel@tonic-gate /*
2287c478bd9Sstevel@tonic-gate * Some CPUs have holes in the middle of the 64-bit virtual address range.
2297c478bd9Sstevel@tonic-gate */
2307c478bd9Sstevel@tonic-gate uintptr_t hole_start, hole_end;
2317c478bd9Sstevel@tonic-gate
2327c478bd9Sstevel@tonic-gate /*
2337c478bd9Sstevel@tonic-gate * kpm mapping window
2347c478bd9Sstevel@tonic-gate */
2357c478bd9Sstevel@tonic-gate caddr_t kpm_vbase;
2367c478bd9Sstevel@tonic-gate size_t kpm_size;
23735b1ab99Sjosephb static int kpm_desired;
23835b1ab99Sjosephb static uintptr_t segkpm_base = (uintptr_t)SEGKPM_BASE;
2397c478bd9Sstevel@tonic-gate
2407c478bd9Sstevel@tonic-gate /*
2417c478bd9Sstevel@tonic-gate * Configuration parameters set at boot time.
2427c478bd9Sstevel@tonic-gate */
2437c478bd9Sstevel@tonic-gate
2447c478bd9Sstevel@tonic-gate caddr_t econtig; /* end of first block of contiguous kernel */
2457c478bd9Sstevel@tonic-gate
2467c478bd9Sstevel@tonic-gate struct bootops *bootops = 0; /* passed in from boot */
2477c478bd9Sstevel@tonic-gate struct bootops **bootopsp;
2487c478bd9Sstevel@tonic-gate struct boot_syscalls *sysp; /* passed in from boot */
2497c478bd9Sstevel@tonic-gate
2507c478bd9Sstevel@tonic-gate char bootblock_fstype[16];
2517c478bd9Sstevel@tonic-gate
2527c478bd9Sstevel@tonic-gate char kern_bootargs[OBP_MAXPATHLEN];
25319397407SSherry Moore char kern_bootfile[OBP_MAXPATHLEN];
2547c478bd9Sstevel@tonic-gate
2557c478bd9Sstevel@tonic-gate /*
256ad23a2dbSjohansen * ZFS zio segment. This allows us to exclude large portions of ZFS data that
257ad23a2dbSjohansen * gets cached in kmem caches on the heap. If this is set to zero, we allocate
258ad23a2dbSjohansen * zio buffers from their own segment, otherwise they are allocated from the
259ad23a2dbSjohansen * heap. The optimization of allocating zio buffers from their own segment is
260ad23a2dbSjohansen * only valid on 64-bit kernels.
261ad23a2dbSjohansen */
262ad23a2dbSjohansen int segzio_fromheap = 0;
263ad23a2dbSjohansen
264ad23a2dbSjohansen /*
2653ce2fcdcSRobert Mustacchi * Give folks an escape hatch for disabling SMAP via kmdb. Doesn't work
2663ce2fcdcSRobert Mustacchi * post-boot.
2673ce2fcdcSRobert Mustacchi */
2683ce2fcdcSRobert Mustacchi int disable_smap = 0;
2693ce2fcdcSRobert Mustacchi
2703ce2fcdcSRobert Mustacchi /*
2717c478bd9Sstevel@tonic-gate * new memory fragmentations are possible in startup() due to BOP_ALLOCs. this
2727c478bd9Sstevel@tonic-gate * depends on number of BOP_ALLOC calls made and requested size, memory size
2737c478bd9Sstevel@tonic-gate * combination and whether boot.bin memory needs to be freed.
2747c478bd9Sstevel@tonic-gate */
2757c478bd9Sstevel@tonic-gate #define POSS_NEW_FRAGMENTS 12
2767c478bd9Sstevel@tonic-gate
2777c478bd9Sstevel@tonic-gate /*
2787c478bd9Sstevel@tonic-gate * VM data structures
2797c478bd9Sstevel@tonic-gate */
2807c478bd9Sstevel@tonic-gate long page_hashsz; /* Size of page hash table (power of two) */
281cb15d5d9SPeter Rival unsigned int page_hashsz_shift; /* log2(page_hashsz) */
2827c478bd9Sstevel@tonic-gate struct page *pp_base; /* Base of initial system page struct array */
2837c478bd9Sstevel@tonic-gate struct page **page_hash; /* Page hash table */
284d7d93655Sblakej pad_mutex_t *pse_mutex; /* Locks protecting pp->p_selock */
285d7d93655Sblakej size_t pse_table_size; /* Number of mutexes in pse_mutex[] */
286d7d93655Sblakej int pse_shift; /* log2(pse_table_size) */
2877c478bd9Sstevel@tonic-gate struct seg ktextseg; /* Segment used for kernel executable image */
2887c478bd9Sstevel@tonic-gate struct seg kvalloc; /* Segment used for "valloc" mapping */
2897c478bd9Sstevel@tonic-gate struct seg kpseg; /* Segment used for pageable kernel virt mem */
2907c478bd9Sstevel@tonic-gate struct seg kmapseg; /* Segment used for generic kernel mappings */
2917c478bd9Sstevel@tonic-gate struct seg kdebugseg; /* Segment used for the kernel debugger */
2927c478bd9Sstevel@tonic-gate
2937c478bd9Sstevel@tonic-gate struct seg *segkmap = &kmapseg; /* Kernel generic mapping segment */
294ae115bc7Smrj static struct seg *segmap = &kmapseg; /* easier to use name for in here */
295ae115bc7Smrj
2967c478bd9Sstevel@tonic-gate struct seg *segkp = &kpseg; /* Pageable kernel virtual memory segment */
2977c478bd9Sstevel@tonic-gate
2980b35c8bcSToomas Soome extern struct seg kvseg_core; /* Segment used for the core heap */
2997c478bd9Sstevel@tonic-gate struct seg kpmseg; /* Segment used for physical mapping */
3007c478bd9Sstevel@tonic-gate struct seg *segkpm = &kpmseg; /* 64bit kernel physical mapping segment */
3017c478bd9Sstevel@tonic-gate
3027c478bd9Sstevel@tonic-gate caddr_t segkp_base; /* Base address of segkp */
303ad23a2dbSjohansen caddr_t segzio_base; /* Base address of segzio */
304860b5cc8Scneira pgcnt_t segkpsize; /* size of segkp segment in pages */
30504909c8cSJohn Levon caddr_t segkvmm_base;
30604909c8cSJohn Levon pgcnt_t segkvmmsize;
30704909c8cSJohn Levon pgcnt_t segziosize;
3087c478bd9Sstevel@tonic-gate
309ae115bc7Smrj /*
310a3114836SGerry Liu * A static DR page_t VA map is reserved that can map the page structures
311a3114836SGerry Liu * for a domain's entire RA space. The pages that back this space are
312a3114836SGerry Liu * dynamically allocated and need not be physically contiguous. The DR
313a3114836SGerry Liu * map size is derived from KPM size.
314a3114836SGerry Liu * This mechanism isn't used by x86 yet, so just stubs here.
315a3114836SGerry Liu */
316a3114836SGerry Liu int ppvm_enable = 0; /* Static virtual map for page structs */
317a3114836SGerry Liu page_t *ppvm_base = NULL; /* Base of page struct map */
318a3114836SGerry Liu pgcnt_t ppvm_size = 0; /* Size of page struct map */
319a3114836SGerry Liu
320a3114836SGerry Liu /*
321ae115bc7Smrj * VA range available to the debugger
322ae115bc7Smrj */
323ae115bc7Smrj const caddr_t kdi_segdebugbase = (const caddr_t)SEGDEBUGBASE;
324ae115bc7Smrj const size_t kdi_segdebugsize = SEGDEBUGSIZE;
325ae115bc7Smrj
3267c478bd9Sstevel@tonic-gate struct memseg *memseg_base;
3277c478bd9Sstevel@tonic-gate struct vnode unused_pages_vp;
3287c478bd9Sstevel@tonic-gate
3297c478bd9Sstevel@tonic-gate #define FOURGB 0x100000000LL
3307c478bd9Sstevel@tonic-gate
3317c478bd9Sstevel@tonic-gate struct memlist *memlist;
3327c478bd9Sstevel@tonic-gate
3337c478bd9Sstevel@tonic-gate caddr_t s_text; /* start of kernel text segment */
3347c478bd9Sstevel@tonic-gate caddr_t e_text; /* end of kernel text segment */
3357c478bd9Sstevel@tonic-gate caddr_t s_data; /* start of kernel data segment */
3367c478bd9Sstevel@tonic-gate caddr_t e_data; /* end of kernel data segment */
3377c478bd9Sstevel@tonic-gate caddr_t modtext; /* start of loadable module text reserved */
3387c478bd9Sstevel@tonic-gate caddr_t e_modtext; /* end of loadable module text reserved */
3397c478bd9Sstevel@tonic-gate caddr_t moddata; /* start of loadable module data reserved */
3407c478bd9Sstevel@tonic-gate caddr_t e_moddata; /* end of loadable module data reserved */
3417c478bd9Sstevel@tonic-gate
3427c478bd9Sstevel@tonic-gate struct memlist *phys_install; /* Total installed physical memory */
3437c478bd9Sstevel@tonic-gate struct memlist *phys_avail; /* Total available physical memory */
3441de082f7SVikram Hegde struct memlist *bios_rsvd; /* Bios reserved memory */
3457c478bd9Sstevel@tonic-gate
3467c478bd9Sstevel@tonic-gate /*
3477c478bd9Sstevel@tonic-gate * kphysm_init returns the number of pages that were processed
3487c478bd9Sstevel@tonic-gate */
349ae115bc7Smrj static pgcnt_t kphysm_init(page_t *, pgcnt_t);
3507c478bd9Sstevel@tonic-gate
3517c478bd9Sstevel@tonic-gate #define IO_PROP_SIZE 64 /* device property size */
3527c478bd9Sstevel@tonic-gate
3537c478bd9Sstevel@tonic-gate /*
3547c478bd9Sstevel@tonic-gate * a couple useful roundup macros
3557c478bd9Sstevel@tonic-gate */
3567c478bd9Sstevel@tonic-gate #define ROUND_UP_PAGE(x) \
3577c478bd9Sstevel@tonic-gate ((uintptr_t)P2ROUNDUP((uintptr_t)(x), (uintptr_t)MMU_PAGESIZE))
3587c478bd9Sstevel@tonic-gate #define ROUND_UP_LPAGE(x) \
3597c478bd9Sstevel@tonic-gate ((uintptr_t)P2ROUNDUP((uintptr_t)(x), mmu.level_size[1]))
3607c478bd9Sstevel@tonic-gate #define ROUND_UP_4MEG(x) \
361ae115bc7Smrj ((uintptr_t)P2ROUNDUP((uintptr_t)(x), (uintptr_t)FOUR_MEG))
3627c478bd9Sstevel@tonic-gate #define ROUND_UP_TOPLEVEL(x) \
3637c478bd9Sstevel@tonic-gate ((uintptr_t)P2ROUNDUP((uintptr_t)(x), mmu.level_size[mmu.max_level]))
3647c478bd9Sstevel@tonic-gate
3657c478bd9Sstevel@tonic-gate /*
3667c478bd9Sstevel@tonic-gate * 32-bit Kernel's Virtual memory layout.
3677c478bd9Sstevel@tonic-gate * +-----------------------+
368ae115bc7Smrj * | |
3697c478bd9Sstevel@tonic-gate * 0xFFC00000 -|-----------------------|- ARGSBASE
3707c478bd9Sstevel@tonic-gate * | debugger |
3717c478bd9Sstevel@tonic-gate * 0xFF800000 -|-----------------------|- SEGDEBUGBASE
3727c478bd9Sstevel@tonic-gate * | Kernel Data |
3737c478bd9Sstevel@tonic-gate * 0xFEC00000 -|-----------------------|
3747c478bd9Sstevel@tonic-gate * | Kernel Text |
375843e1988Sjohnlev * 0xFE800000 -|-----------------------|- KERNEL_TEXT (0xFB400000 on Xen)
376ae115bc7Smrj * |--- GDT ---|- GDT page (GDT_VA)
377ae115bc7Smrj * |--- debug info ---|- debug info (DEBUG_INFO_VA)
378ae115bc7Smrj * | |
379ae115bc7Smrj * | page_t structures |
3807c478bd9Sstevel@tonic-gate * | memsegs, memlists, |
3817c478bd9Sstevel@tonic-gate * | page hash, etc. |
382ae115bc7Smrj * --- -|-----------------------|- ekernelheap, valloc_base (floating)
383ae115bc7Smrj * | | (segkp is just an arena in the heap)
3847c478bd9Sstevel@tonic-gate * | |
3857c478bd9Sstevel@tonic-gate * | kvseg |
3867c478bd9Sstevel@tonic-gate * | |
3877c478bd9Sstevel@tonic-gate * | |
3887c478bd9Sstevel@tonic-gate * --- -|-----------------------|- kernelheap (floating)
3897c478bd9Sstevel@tonic-gate * | Segkmap |
390ae115bc7Smrj * 0xC3002000 -|-----------------------|- segmap_start (floating)
3917c478bd9Sstevel@tonic-gate * | Red Zone |
3927c478bd9Sstevel@tonic-gate * 0xC3000000 -|-----------------------|- kernelbase / userlimit (floating)
3937c478bd9Sstevel@tonic-gate * | | ||
3947c478bd9Sstevel@tonic-gate * | Shared objects | \/
3957c478bd9Sstevel@tonic-gate * | |
3967c478bd9Sstevel@tonic-gate * : :
3977c478bd9Sstevel@tonic-gate * | user data |
3987c478bd9Sstevel@tonic-gate * |-----------------------|
3997c478bd9Sstevel@tonic-gate * | user text |
4007c478bd9Sstevel@tonic-gate * 0x08048000 -|-----------------------|
4017c478bd9Sstevel@tonic-gate * | user stack |
4027c478bd9Sstevel@tonic-gate * : :
4037c478bd9Sstevel@tonic-gate * | invalid |
4047c478bd9Sstevel@tonic-gate * 0x00000000 +-----------------------+
4057c478bd9Sstevel@tonic-gate *
4067c478bd9Sstevel@tonic-gate *
4077c478bd9Sstevel@tonic-gate * 64-bit Kernel's Virtual memory layout. (assuming 64 bit app)
4087c478bd9Sstevel@tonic-gate * +-----------------------+
409ae115bc7Smrj * | |
4107c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.FFC00000 |-----------------------|- ARGSBASE
4117c478bd9Sstevel@tonic-gate * | debugger (?) |
4127c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.FF800000 |-----------------------|- SEGDEBUGBASE
4137c478bd9Sstevel@tonic-gate * | unused |
4147c478bd9Sstevel@tonic-gate * +-----------------------+
4157c478bd9Sstevel@tonic-gate * | Kernel Data |
4167c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.FBC00000 |-----------------------|
4177c478bd9Sstevel@tonic-gate * | Kernel Text |
4187c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.FB800000 |-----------------------|- KERNEL_TEXT
419ae115bc7Smrj * |--- debug info ---|- debug info (DEBUG_INFO_VA)
42074ecdb51SJohn Levon * |--- GDT ---|- GDT page (GDT_VA)
42174ecdb51SJohn Levon * |--- IDT ---|- IDT page (IDT_VA)
42274ecdb51SJohn Levon * |--- LDT ---|- LDT pages (LDT_VA)
423ae115bc7Smrj * | |
4247c478bd9Sstevel@tonic-gate * | Core heap | (used for loadable modules)
4257c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.C0000000 |-----------------------|- core_base / ekernelheap
4267c478bd9Sstevel@tonic-gate * | Kernel |
4277c478bd9Sstevel@tonic-gate * | heap |
42804909c8cSJohn Levon * | |
42904909c8cSJohn Levon * | |
4307c478bd9Sstevel@tonic-gate * 0xFFFFFXXX.XXX00000 |-----------------------|- kernelheap (floating)
431ae115bc7Smrj * | segmap |
432ae115bc7Smrj * 0xFFFFFXXX.XXX00000 |-----------------------|- segmap_start (floating)
4337c478bd9Sstevel@tonic-gate * | device mappings |
4347c478bd9Sstevel@tonic-gate * 0xFFFFFXXX.XXX00000 |-----------------------|- toxic_addr (floating)
435ad23a2dbSjohansen * | segzio |
436ad23a2dbSjohansen * 0xFFFFFXXX.XXX00000 |-----------------------|- segzio_base (floating)
43704909c8cSJohn Levon * | segkvmm |
43804909c8cSJohn Levon * | |
43904909c8cSJohn Levon * | |
44004909c8cSJohn Levon * | |
44104909c8cSJohn Levon * 0xFFFFFXXX.XXX00000 |-----------------------|- segkvmm_base (floating)
4427c478bd9Sstevel@tonic-gate * | segkp |
44304909c8cSJohn Levon * |-----------------------|- segkp_base (floating)
444ae115bc7Smrj * | page_t structures | valloc_base + valloc_sz
445ae115bc7Smrj * | memsegs, memlists, |
446ae115bc7Smrj * | page hash, etc. |
44704909c8cSJohn Levon * 0xFFFFFE00.00000000 |-----------------------|- valloc_base (lower if >256GB)
4487c478bd9Sstevel@tonic-gate * | segkpm |
44904909c8cSJohn Levon * | |
45004909c8cSJohn Levon * 0xFFFFFD00.00000000 |-----------------------|- SEGKPM_BASE (lower if >256GB)
4517c478bd9Sstevel@tonic-gate * | Red Zone |
45204909c8cSJohn Levon * 0xFFFFFC80.00000000 |-----------------------|- KERNELBASE (lower if >256GB)
45304909c8cSJohn Levon * 0xFFFFFC7F.FFE00000 |-----------------------|- USERLIMIT (lower if >256GB)
4547c478bd9Sstevel@tonic-gate * | User stack |- User space memory
4557c478bd9Sstevel@tonic-gate * | |
4567c478bd9Sstevel@tonic-gate * | shared objects, etc | (grows downwards)
4577c478bd9Sstevel@tonic-gate * : :
4587c478bd9Sstevel@tonic-gate * | |
4597c478bd9Sstevel@tonic-gate * 0xFFFF8000.00000000 |-----------------------|
4607c478bd9Sstevel@tonic-gate * | |
4617c478bd9Sstevel@tonic-gate * | VA Hole / unused |
4627c478bd9Sstevel@tonic-gate * | |
4637c478bd9Sstevel@tonic-gate * 0x00008000.00000000 |-----------------------|
4647c478bd9Sstevel@tonic-gate * | |
4657c478bd9Sstevel@tonic-gate * | |
4667c478bd9Sstevel@tonic-gate * : :
4677c478bd9Sstevel@tonic-gate * | user heap | (grows upwards)
4687c478bd9Sstevel@tonic-gate * | |
4697c478bd9Sstevel@tonic-gate * | user data |
4707c478bd9Sstevel@tonic-gate * |-----------------------|
4717c478bd9Sstevel@tonic-gate * | user text |
4727c478bd9Sstevel@tonic-gate * 0x00000000.04000000 |-----------------------|
4737c478bd9Sstevel@tonic-gate * | invalid |
4747c478bd9Sstevel@tonic-gate * 0x00000000.00000000 +-----------------------+
4757c478bd9Sstevel@tonic-gate *
4767c478bd9Sstevel@tonic-gate * A 32 bit app on the 64 bit kernel sees the same layout as on the 32 bit
4777c478bd9Sstevel@tonic-gate * kernel, except that userlimit is raised to 0xfe000000
4787c478bd9Sstevel@tonic-gate *
4797c478bd9Sstevel@tonic-gate * Floating values:
4807c478bd9Sstevel@tonic-gate *
4817c478bd9Sstevel@tonic-gate * valloc_base: start of the kernel's memory management/tracking data
482ae115bc7Smrj * structures. This region contains page_t structures for
483ae115bc7Smrj * physical memory, memsegs, memlists, and the page hash.
4847c478bd9Sstevel@tonic-gate *
4857c478bd9Sstevel@tonic-gate * core_base: start of the kernel's "core" heap area on 64-bit systems.
4867c478bd9Sstevel@tonic-gate * This area is intended to be used for global data as well as for module
4877c478bd9Sstevel@tonic-gate * text/data that does not fit into the nucleus pages. The core heap is
4887c478bd9Sstevel@tonic-gate * restricted to a 2GB range, allowing every address within it to be
4897c478bd9Sstevel@tonic-gate * accessed using rip-relative addressing
4907c478bd9Sstevel@tonic-gate *
4917c478bd9Sstevel@tonic-gate * ekernelheap: end of kernelheap and start of segmap.
4927c478bd9Sstevel@tonic-gate *
4937c478bd9Sstevel@tonic-gate * kernelheap: start of kernel heap. On 32-bit systems, this starts right
4947c478bd9Sstevel@tonic-gate * above a red zone that separates the user's address space from the
4957c478bd9Sstevel@tonic-gate * kernel's. On 64-bit systems, it sits above segkp and segkpm.
4967c478bd9Sstevel@tonic-gate *
497ae115bc7Smrj * segmap_start: start of segmap. The length of segmap can be modified
49852eef812SAmrita Sadhukhan * through eeprom. The default length is 16MB on 32-bit systems and 64MB
49952eef812SAmrita Sadhukhan * on 64-bit systems.
5007c478bd9Sstevel@tonic-gate *
5017c478bd9Sstevel@tonic-gate * kernelbase: On a 32-bit kernel the default value of 0xd4000000 will be
5027c478bd9Sstevel@tonic-gate * decreased by 2X the size required for page_t. This allows the kernel
5037c478bd9Sstevel@tonic-gate * heap to grow in size with physical memory. With sizeof(page_t) == 80
5047c478bd9Sstevel@tonic-gate * bytes, the following shows the values of kernelbase and kernel heap
5057c478bd9Sstevel@tonic-gate * sizes for different memory configurations (assuming default segmap and
5067c478bd9Sstevel@tonic-gate * segkp sizes).
5077c478bd9Sstevel@tonic-gate *
5087c478bd9Sstevel@tonic-gate * mem size for kernelbase kernel heap
5097c478bd9Sstevel@tonic-gate * size page_t's size
5107c478bd9Sstevel@tonic-gate * ---- --------- ---------- -----------
5117c478bd9Sstevel@tonic-gate * 1gb 0x01400000 0xd1800000 684MB
5127c478bd9Sstevel@tonic-gate * 2gb 0x02800000 0xcf000000 704MB
5137c478bd9Sstevel@tonic-gate * 4gb 0x05000000 0xca000000 744MB
5147c478bd9Sstevel@tonic-gate * 6gb 0x07800000 0xc5000000 784MB
5157c478bd9Sstevel@tonic-gate * 8gb 0x0a000000 0xc0000000 824MB
5167c478bd9Sstevel@tonic-gate * 16gb 0x14000000 0xac000000 984MB
5177c478bd9Sstevel@tonic-gate * 32gb 0x28000000 0x84000000 1304MB
5187c478bd9Sstevel@tonic-gate * 64gb 0x50000000 0x34000000 1944MB (*)
5197c478bd9Sstevel@tonic-gate *
5207c478bd9Sstevel@tonic-gate * kernelbase is less than the abi minimum of 0xc0000000 for memory
5217c478bd9Sstevel@tonic-gate * configurations above 8gb.
5227c478bd9Sstevel@tonic-gate *
5237c478bd9Sstevel@tonic-gate * (*) support for memory configurations above 32gb will require manual tuning
5247c478bd9Sstevel@tonic-gate * of kernelbase to balance out the need of user applications.
5257c478bd9Sstevel@tonic-gate */
5267c478bd9Sstevel@tonic-gate
5277c478bd9Sstevel@tonic-gate /* real-time-clock initialization parameters */
528ae115bc7Smrj extern time_t process_rtc_config_file(void);
5297c478bd9Sstevel@tonic-gate
5307c478bd9Sstevel@tonic-gate uintptr_t kernelbase;
531ae115bc7Smrj uintptr_t postbootkernelbase; /* not set till boot loader is gone */
5327c478bd9Sstevel@tonic-gate uintptr_t eprom_kernelbase;
5337c478bd9Sstevel@tonic-gate size_t segmapsize;
534ae115bc7Smrj uintptr_t segmap_start;
5357c478bd9Sstevel@tonic-gate int segmapfreelists;
5367c478bd9Sstevel@tonic-gate pgcnt_t npages;
537ae115bc7Smrj pgcnt_t orig_npages;
5387c478bd9Sstevel@tonic-gate size_t core_size; /* size of "core" heap */
5397c478bd9Sstevel@tonic-gate uintptr_t core_base; /* base address of "core" heap */
5407c478bd9Sstevel@tonic-gate
5417c478bd9Sstevel@tonic-gate /*
5427c478bd9Sstevel@tonic-gate * List of bootstrap pages. We mark these as allocated in startup.
5437c478bd9Sstevel@tonic-gate * release_bootstrap() will free them when we're completely done with
5447c478bd9Sstevel@tonic-gate * the bootstrap.
5457c478bd9Sstevel@tonic-gate */
546ae115bc7Smrj static page_t *bootpages;
547ae115bc7Smrj
548ae115bc7Smrj /*
549ae115bc7Smrj * boot time pages that have a vnode from the ramdisk will keep that forever.
550ae115bc7Smrj */
551ae115bc7Smrj static page_t *rd_pages;
5527c478bd9Sstevel@tonic-gate
55319397407SSherry Moore /*
55419397407SSherry Moore * Lower 64K
55519397407SSherry Moore */
55619397407SSherry Moore static page_t *lower_pages = NULL;
55719397407SSherry Moore static int lower_pages_count = 0;
55819397407SSherry Moore
5597c478bd9Sstevel@tonic-gate struct system_hardware system_hardware;
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate /*
5627c478bd9Sstevel@tonic-gate * Enable some debugging messages concerning memory usage...
5637c478bd9Sstevel@tonic-gate */
5647c478bd9Sstevel@tonic-gate static void
print_memlist(char * title,struct memlist * mp)565ae115bc7Smrj print_memlist(char *title, struct memlist *mp)
5667c478bd9Sstevel@tonic-gate {
5677c478bd9Sstevel@tonic-gate prom_printf("MEMLIST: %s:\n", title);
5687c478bd9Sstevel@tonic-gate while (mp != NULL) {
5697c478bd9Sstevel@tonic-gate prom_printf("\tAddress 0x%" PRIx64 ", size 0x%" PRIx64 "\n",
57056f33205SJonathan Adams mp->ml_address, mp->ml_size);
57156f33205SJonathan Adams mp = mp->ml_next;
5727c478bd9Sstevel@tonic-gate }
5737c478bd9Sstevel@tonic-gate }
5747c478bd9Sstevel@tonic-gate
5757c478bd9Sstevel@tonic-gate /*
5767c478bd9Sstevel@tonic-gate * XX64 need a comment here.. are these just default values, surely
5777c478bd9Sstevel@tonic-gate * we read the "cpuid" type information to figure this out.
5787c478bd9Sstevel@tonic-gate */
5797c478bd9Sstevel@tonic-gate int l2cache_sz = 0x80000;
5807c478bd9Sstevel@tonic-gate int l2cache_linesz = 0x40;
5817c478bd9Sstevel@tonic-gate int l2cache_assoc = 1;
5827c478bd9Sstevel@tonic-gate
5832cb27123Saguzovsk static size_t textrepl_min_gb = 10;
5842cb27123Saguzovsk
5857c478bd9Sstevel@tonic-gate /*
5867c478bd9Sstevel@tonic-gate * on 64 bit we use a predifined VA range for mapping devices in the kernel
5877c478bd9Sstevel@tonic-gate * on 32 bit the mappings are intermixed in the heap, so we use a bit map
5887c478bd9Sstevel@tonic-gate */
5897c478bd9Sstevel@tonic-gate
5907c478bd9Sstevel@tonic-gate vmem_t *device_arena;
5917c478bd9Sstevel@tonic-gate uintptr_t toxic_addr = (uintptr_t)NULL;
592ae115bc7Smrj size_t toxic_size = 1024 * 1024 * 1024; /* Sparc uses 1 gig too */
5937c478bd9Sstevel@tonic-gate
5947c478bd9Sstevel@tonic-gate
5957c478bd9Sstevel@tonic-gate int prom_debug;
5967c478bd9Sstevel@tonic-gate
5977c478bd9Sstevel@tonic-gate /*
5987c478bd9Sstevel@tonic-gate * This structure is used to keep track of the intial allocations
5997c478bd9Sstevel@tonic-gate * done in startup_memlist(). The value of NUM_ALLOCATIONS needs to
6007c478bd9Sstevel@tonic-gate * be >= the number of ADD_TO_ALLOCATIONS() executed in the code.
6017c478bd9Sstevel@tonic-gate */
6021de082f7SVikram Hegde #define NUM_ALLOCATIONS 8
6037c478bd9Sstevel@tonic-gate int num_allocations = 0;
6047c478bd9Sstevel@tonic-gate struct {
6057c478bd9Sstevel@tonic-gate void **al_ptr;
6067c478bd9Sstevel@tonic-gate size_t al_size;
6077c478bd9Sstevel@tonic-gate } allocations[NUM_ALLOCATIONS];
6087c478bd9Sstevel@tonic-gate size_t valloc_sz = 0;
6097c478bd9Sstevel@tonic-gate uintptr_t valloc_base;
6107c478bd9Sstevel@tonic-gate
6117c478bd9Sstevel@tonic-gate #define ADD_TO_ALLOCATIONS(ptr, size) { \
6127c478bd9Sstevel@tonic-gate size = ROUND_UP_PAGE(size); \
6137c478bd9Sstevel@tonic-gate if (num_allocations == NUM_ALLOCATIONS) \
6147c478bd9Sstevel@tonic-gate panic("too many ADD_TO_ALLOCATIONS()"); \
6157c478bd9Sstevel@tonic-gate allocations[num_allocations].al_ptr = (void**)&ptr; \
6167c478bd9Sstevel@tonic-gate allocations[num_allocations].al_size = size; \
6177c478bd9Sstevel@tonic-gate valloc_sz += size; \
6187c478bd9Sstevel@tonic-gate ++num_allocations; \
6197c478bd9Sstevel@tonic-gate }
6207c478bd9Sstevel@tonic-gate
621ae115bc7Smrj /*
622ae115bc7Smrj * Allocate all the initial memory needed by the page allocator.
623ae115bc7Smrj */
6247c478bd9Sstevel@tonic-gate static void
perform_allocations(void)6257c478bd9Sstevel@tonic-gate perform_allocations(void)
6267c478bd9Sstevel@tonic-gate {
6277c478bd9Sstevel@tonic-gate caddr_t mem;
6287c478bd9Sstevel@tonic-gate int i;
629ae115bc7Smrj int valloc_align;
6307c478bd9Sstevel@tonic-gate
631ae115bc7Smrj PRM_DEBUG(valloc_base);
632ae115bc7Smrj PRM_DEBUG(valloc_sz);
633ae115bc7Smrj valloc_align = mmu.level_size[mmu.max_page_level > 0];
634ae115bc7Smrj mem = BOP_ALLOC(bootops, (caddr_t)valloc_base, valloc_sz, valloc_align);
6357c478bd9Sstevel@tonic-gate if (mem != (caddr_t)valloc_base)
6367c478bd9Sstevel@tonic-gate panic("BOP_ALLOC() failed");
6377c478bd9Sstevel@tonic-gate bzero(mem, valloc_sz);
6387c478bd9Sstevel@tonic-gate for (i = 0; i < num_allocations; ++i) {
6397c478bd9Sstevel@tonic-gate *allocations[i].al_ptr = (void *)mem;
6407c478bd9Sstevel@tonic-gate mem += allocations[i].al_size;
6417c478bd9Sstevel@tonic-gate }
6427c478bd9Sstevel@tonic-gate }
6437c478bd9Sstevel@tonic-gate
6447c478bd9Sstevel@tonic-gate /*
6453ce2fcdcSRobert Mustacchi * Set up and enable SMAP now before we start other CPUs, but after the kernel's
6463ce2fcdcSRobert Mustacchi * VM has been set up so we can use hot_patch_kernel_text().
6473ce2fcdcSRobert Mustacchi *
6483ce2fcdcSRobert Mustacchi * We can only patch 1, 2, or 4 bytes, but not three bytes. So instead, we
649f0089e39SRichard Lowe * replace the four byte word at the patch point. See uts/intel/ml/copy.s
6503ce2fcdcSRobert Mustacchi * for more information on what's going on here.
6513ce2fcdcSRobert Mustacchi */
6523ce2fcdcSRobert Mustacchi static void
startup_smap(void)6533ce2fcdcSRobert Mustacchi startup_smap(void)
6543ce2fcdcSRobert Mustacchi {
6553ce2fcdcSRobert Mustacchi int i;
6563ce2fcdcSRobert Mustacchi uint32_t inst;
6573ce2fcdcSRobert Mustacchi uint8_t *instp;
6583ce2fcdcSRobert Mustacchi char sym[128];
659425251fdSSam Gwydir struct modctl *modp;
6603ce2fcdcSRobert Mustacchi
6613ce2fcdcSRobert Mustacchi extern int _smap_enable_patch_count;
6623ce2fcdcSRobert Mustacchi extern int _smap_disable_patch_count;
6633ce2fcdcSRobert Mustacchi
6643ce2fcdcSRobert Mustacchi if (disable_smap != 0)
6653ce2fcdcSRobert Mustacchi remove_x86_feature(x86_featureset, X86FSET_SMAP);
6663ce2fcdcSRobert Mustacchi
6673ce2fcdcSRobert Mustacchi if (is_x86_feature(x86_featureset, X86FSET_SMAP) == B_FALSE)
6683ce2fcdcSRobert Mustacchi return;
6693ce2fcdcSRobert Mustacchi
6703ce2fcdcSRobert Mustacchi for (i = 0; i < _smap_enable_patch_count; i++) {
6713ce2fcdcSRobert Mustacchi int sizep;
6723ce2fcdcSRobert Mustacchi
6733ce2fcdcSRobert Mustacchi VERIFY3U(i, <, _smap_enable_patch_count);
6743ce2fcdcSRobert Mustacchi VERIFY(snprintf(sym, sizeof (sym), "_smap_enable_patch_%d", i) <
6753ce2fcdcSRobert Mustacchi sizeof (sym));
6763ce2fcdcSRobert Mustacchi instp = (uint8_t *)(void *)kobj_getelfsym(sym, NULL, &sizep);
6773ce2fcdcSRobert Mustacchi VERIFY(instp != 0);
6783ce2fcdcSRobert Mustacchi inst = (instp[3] << 24) | (SMAP_CLAC_INSTR & 0x00ffffff);
6793ce2fcdcSRobert Mustacchi hot_patch_kernel_text((caddr_t)instp, inst, 4);
6803ce2fcdcSRobert Mustacchi }
6813ce2fcdcSRobert Mustacchi
6823ce2fcdcSRobert Mustacchi for (i = 0; i < _smap_disable_patch_count; i++) {
6833ce2fcdcSRobert Mustacchi int sizep;
6843ce2fcdcSRobert Mustacchi
6853ce2fcdcSRobert Mustacchi VERIFY(snprintf(sym, sizeof (sym), "_smap_disable_patch_%d",
6863ce2fcdcSRobert Mustacchi i) < sizeof (sym));
6873ce2fcdcSRobert Mustacchi instp = (uint8_t *)(void *)kobj_getelfsym(sym, NULL, &sizep);
6883ce2fcdcSRobert Mustacchi VERIFY(instp != 0);
6893ce2fcdcSRobert Mustacchi inst = (instp[3] << 24) | (SMAP_STAC_INSTR & 0x00ffffff);
6903ce2fcdcSRobert Mustacchi hot_patch_kernel_text((caddr_t)instp, inst, 4);
6913ce2fcdcSRobert Mustacchi }
6923ce2fcdcSRobert Mustacchi
693425251fdSSam Gwydir /*
694425251fdSSam Gwydir * Hotinline calls to smap_enable and smap_disable within
695425251fdSSam Gwydir * unix module. Hotinlines in other modules are done on
696425251fdSSam Gwydir * mod_load().
697425251fdSSam Gwydir */
698425251fdSSam Gwydir modp = mod_hold_by_name("unix");
699425251fdSSam Gwydir do_hotinlines(modp->mod_mp);
700425251fdSSam Gwydir mod_release_mod(modp);
701425251fdSSam Gwydir
7023ce2fcdcSRobert Mustacchi setcr4(getcr4() | CR4_SMAP);
7033ce2fcdcSRobert Mustacchi smap_enable();
7043ce2fcdcSRobert Mustacchi }
7053ce2fcdcSRobert Mustacchi
7063ce2fcdcSRobert Mustacchi /*
7077c478bd9Sstevel@tonic-gate * Our world looks like this at startup time.
7087c478bd9Sstevel@tonic-gate *
7097c478bd9Sstevel@tonic-gate * In a 32-bit OS, boot loads the kernel text at 0xfe800000 and kernel data
7107c478bd9Sstevel@tonic-gate * at 0xfec00000. On a 64-bit OS, kernel text and data are loaded at
7117c478bd9Sstevel@tonic-gate * 0xffffffff.fe800000 and 0xffffffff.fec00000 respectively. Those
7127c478bd9Sstevel@tonic-gate * addresses are fixed in the binary at link time.
7137c478bd9Sstevel@tonic-gate *
7147c478bd9Sstevel@tonic-gate * On the text page:
7157c478bd9Sstevel@tonic-gate * unix/genunix/krtld/module text loads.
7167c478bd9Sstevel@tonic-gate *
7177c478bd9Sstevel@tonic-gate * On the data page:
718ae115bc7Smrj * unix/genunix/krtld/module data loads.
719ae115bc7Smrj *
7207c478bd9Sstevel@tonic-gate * Machine-dependent startup code
7217c478bd9Sstevel@tonic-gate */
7227c478bd9Sstevel@tonic-gate void
startup(void)7237c478bd9Sstevel@tonic-gate startup(void)
7247c478bd9Sstevel@tonic-gate {
725843e1988Sjohnlev #if !defined(__xpv)
72675bcd456Sjg extern void startup_pci_bios(void);
727843e1988Sjohnlev #endif
728a563a037Sbholler extern cpuset_t cpu_ready_set;
729a563a037Sbholler
730843e1988Sjohnlev /*
731843e1988Sjohnlev * Make sure that nobody tries to use sekpm until we have
732843e1988Sjohnlev * initialized it properly.
733843e1988Sjohnlev */
73435b1ab99Sjosephb kpm_desired = 1;
7357c478bd9Sstevel@tonic-gate kpm_enable = 0;
736a563a037Sbholler CPUSET_ONLY(cpu_ready_set, 0); /* cpu 0 is boot cpu */
7377c478bd9Sstevel@tonic-gate
738843e1988Sjohnlev #if defined(__xpv) /* XXPV fix me! */
739843e1988Sjohnlev {
740843e1988Sjohnlev extern int segvn_use_regions;
741843e1988Sjohnlev segvn_use_regions = 0;
742843e1988Sjohnlev }
743843e1988Sjohnlev #endif
7446a59053bSAlex Wilson ssp_init();
7457c478bd9Sstevel@tonic-gate progressbar_init();
7467c478bd9Sstevel@tonic-gate startup_init();
747ab4a9bebSjohnlev #if defined(__xpv)
748ab4a9bebSjohnlev startup_xen_version();
749ab4a9bebSjohnlev #endif
7507c478bd9Sstevel@tonic-gate startup_memlist();
751ae115bc7Smrj startup_kmem();
75235b1ab99Sjosephb startup_vm();
753843e1988Sjohnlev #if !defined(__xpv)
7540db3240dSStephen Hanson /*
755575694f6SJason King * Up until this point, we cannot use any time delay functions
756575694f6SJason King * (e.g. tenmicrosec()). Once the TSC is setup, we can. This is
757575694f6SJason King * purposely done after the VM system as been setup to allow
758575694f6SJason King * calibration sources which might require mapping for access
759575694f6SJason King * (e.g. the HPET), but still early enough to allow the rest of
760575694f6SJason King * the startup code to make use of the TSC (via tenmicrosec() or
761575694f6SJason King * the default TSC-based gethrtime()) as required.
762575694f6SJason King */
763575694f6SJason King startup_tsc();
764575694f6SJason King
765575694f6SJason King /*
7660db3240dSStephen Hanson * Note we need to do this even on fast reboot in order to access
7670db3240dSStephen Hanson * the irq routing table (used for pci labels).
7680db3240dSStephen Hanson */
76975bcd456Sjg startup_pci_bios();
7703ce2fcdcSRobert Mustacchi startup_smap();
771843e1988Sjohnlev #endif
772e4b86885SCheng Sean Ye #if defined(__xpv)
773e4b86885SCheng Sean Ye startup_xen_mca();
774e4b86885SCheng Sean Ye #endif
7757c478bd9Sstevel@tonic-gate startup_modules();
7768770118eSlipeng sang - Sun Microsystems - Beijing China
7777c478bd9Sstevel@tonic-gate startup_end();
7787c478bd9Sstevel@tonic-gate }
7797c478bd9Sstevel@tonic-gate
7807c478bd9Sstevel@tonic-gate static void
startup_init()7817c478bd9Sstevel@tonic-gate startup_init()
7827c478bd9Sstevel@tonic-gate {
7837c478bd9Sstevel@tonic-gate PRM_POINT("startup_init() starting...");
7847c478bd9Sstevel@tonic-gate
7857c478bd9Sstevel@tonic-gate /*
7867c478bd9Sstevel@tonic-gate * Complete the extraction of cpuid data
7877c478bd9Sstevel@tonic-gate */
788ab5bb018SKeith M Wesolowski cpuid_execpass(CPU, CPUID_PASS_EXTENDED, NULL);
7897c478bd9Sstevel@tonic-gate
7907c478bd9Sstevel@tonic-gate (void) check_boot_version(BOP_GETVERSION(bootops));
7917c478bd9Sstevel@tonic-gate
7927c478bd9Sstevel@tonic-gate /*
7937c478bd9Sstevel@tonic-gate * Check for prom_debug in boot environment
7947c478bd9Sstevel@tonic-gate */
7957c478bd9Sstevel@tonic-gate if (BOP_GETPROPLEN(bootops, "prom_debug") >= 0) {
7967c478bd9Sstevel@tonic-gate ++prom_debug;
7977c478bd9Sstevel@tonic-gate PRM_POINT("prom_debug found in boot enviroment");
7987c478bd9Sstevel@tonic-gate }
7997c478bd9Sstevel@tonic-gate
8007c478bd9Sstevel@tonic-gate /*
8017c478bd9Sstevel@tonic-gate * Collect node, cpu and memory configuration information.
8027c478bd9Sstevel@tonic-gate */
8037c478bd9Sstevel@tonic-gate get_system_configuration();
8047c478bd9Sstevel@tonic-gate
8057c478bd9Sstevel@tonic-gate /*
8067c478bd9Sstevel@tonic-gate * Halt if this is an unsupported processor.
8077c478bd9Sstevel@tonic-gate */
8087c478bd9Sstevel@tonic-gate if (x86_type == X86_TYPE_486 || x86_type == X86_TYPE_CYRIX_486) {
8097c478bd9Sstevel@tonic-gate printf("\n486 processor (\"%s\") detected.\n",
8107c478bd9Sstevel@tonic-gate CPU->cpu_brandstr);
8117c478bd9Sstevel@tonic-gate halt("This processor is not supported by this release "
8127c478bd9Sstevel@tonic-gate "of Solaris.");
8137c478bd9Sstevel@tonic-gate }
8147c478bd9Sstevel@tonic-gate
8157c478bd9Sstevel@tonic-gate PRM_POINT("startup_init() done");
8167c478bd9Sstevel@tonic-gate }
8177c478bd9Sstevel@tonic-gate
8187c478bd9Sstevel@tonic-gate /*
8197c478bd9Sstevel@tonic-gate * Callback for copy_memlist_filter() to filter nucleus, kadb/kmdb, (ie.
8207c478bd9Sstevel@tonic-gate * everything mapped above KERNEL_TEXT) pages from phys_avail. Note it
8217c478bd9Sstevel@tonic-gate * also filters out physical page zero. There is some reliance on the
8227c478bd9Sstevel@tonic-gate * boot loader allocating only a few contiguous physical memory chunks.
8237c478bd9Sstevel@tonic-gate */
8247c478bd9Sstevel@tonic-gate static void
avail_filter(uint64_t * addr,uint64_t * size)8257c478bd9Sstevel@tonic-gate avail_filter(uint64_t *addr, uint64_t *size)
8267c478bd9Sstevel@tonic-gate {
8277c478bd9Sstevel@tonic-gate uintptr_t va;
8287c478bd9Sstevel@tonic-gate uintptr_t next_va;
8297c478bd9Sstevel@tonic-gate pfn_t pfn;
8307c478bd9Sstevel@tonic-gate uint64_t pfn_addr;
8317c478bd9Sstevel@tonic-gate uint64_t pfn_eaddr;
8327c478bd9Sstevel@tonic-gate uint_t prot;
8337c478bd9Sstevel@tonic-gate size_t len;
8347c478bd9Sstevel@tonic-gate uint_t change;
8357c478bd9Sstevel@tonic-gate
8367c478bd9Sstevel@tonic-gate if (prom_debug)
8377c478bd9Sstevel@tonic-gate prom_printf("\tFilter: in: a=%" PRIx64 ", s=%" PRIx64 "\n",
8387c478bd9Sstevel@tonic-gate *addr, *size);
8397c478bd9Sstevel@tonic-gate
8407c478bd9Sstevel@tonic-gate /*
8417c478bd9Sstevel@tonic-gate * page zero is required for BIOS.. never make it available
8427c478bd9Sstevel@tonic-gate */
8437c478bd9Sstevel@tonic-gate if (*addr == 0) {
8447c478bd9Sstevel@tonic-gate *addr += MMU_PAGESIZE;
8457c478bd9Sstevel@tonic-gate *size -= MMU_PAGESIZE;
8467c478bd9Sstevel@tonic-gate }
8477c478bd9Sstevel@tonic-gate
8487c478bd9Sstevel@tonic-gate /*
849ae115bc7Smrj * First we trim from the front of the range. Since kbm_probe()
8507c478bd9Sstevel@tonic-gate * walks ranges in virtual order, but addr/size are physical, we need
8517c478bd9Sstevel@tonic-gate * to the list until no changes are seen. This deals with the case
8527c478bd9Sstevel@tonic-gate * where page "p" is mapped at v, page "p + PAGESIZE" is mapped at w
8537c478bd9Sstevel@tonic-gate * but w < v.
8547c478bd9Sstevel@tonic-gate */
8557c478bd9Sstevel@tonic-gate do {
8567c478bd9Sstevel@tonic-gate change = 0;
8577c478bd9Sstevel@tonic-gate for (va = KERNEL_TEXT;
858ae115bc7Smrj *size > 0 && kbm_probe(&va, &len, &pfn, &prot) != 0;
8597c478bd9Sstevel@tonic-gate va = next_va) {
8607c478bd9Sstevel@tonic-gate
8617c478bd9Sstevel@tonic-gate next_va = va + len;
862ae115bc7Smrj pfn_addr = pfn_to_pa(pfn);
8637c478bd9Sstevel@tonic-gate pfn_eaddr = pfn_addr + len;
8647c478bd9Sstevel@tonic-gate
8657c478bd9Sstevel@tonic-gate if (pfn_addr <= *addr && pfn_eaddr > *addr) {
8667c478bd9Sstevel@tonic-gate change = 1;
8677c478bd9Sstevel@tonic-gate while (*size > 0 && len > 0) {
8687c478bd9Sstevel@tonic-gate *addr += MMU_PAGESIZE;
8697c478bd9Sstevel@tonic-gate *size -= MMU_PAGESIZE;
8707c478bd9Sstevel@tonic-gate len -= MMU_PAGESIZE;
8717c478bd9Sstevel@tonic-gate }
8727c478bd9Sstevel@tonic-gate }
8737c478bd9Sstevel@tonic-gate }
8747c478bd9Sstevel@tonic-gate if (change && prom_debug)
8757c478bd9Sstevel@tonic-gate prom_printf("\t\ttrim: a=%" PRIx64 ", s=%" PRIx64 "\n",
8767c478bd9Sstevel@tonic-gate *addr, *size);
8777c478bd9Sstevel@tonic-gate } while (change);
8787c478bd9Sstevel@tonic-gate
8797c478bd9Sstevel@tonic-gate /*
8807c478bd9Sstevel@tonic-gate * Trim pages from the end of the range.
8817c478bd9Sstevel@tonic-gate */
8827c478bd9Sstevel@tonic-gate for (va = KERNEL_TEXT;
883ae115bc7Smrj *size > 0 && kbm_probe(&va, &len, &pfn, &prot) != 0;
8847c478bd9Sstevel@tonic-gate va = next_va) {
8857c478bd9Sstevel@tonic-gate
8867c478bd9Sstevel@tonic-gate next_va = va + len;
887ae115bc7Smrj pfn_addr = pfn_to_pa(pfn);
8887c478bd9Sstevel@tonic-gate
8897c478bd9Sstevel@tonic-gate if (pfn_addr >= *addr && pfn_addr < *addr + *size)
8907c478bd9Sstevel@tonic-gate *size = pfn_addr - *addr;
8917c478bd9Sstevel@tonic-gate }
8927c478bd9Sstevel@tonic-gate
8937c478bd9Sstevel@tonic-gate if (prom_debug)
8947c478bd9Sstevel@tonic-gate prom_printf("\tFilter out: a=%" PRIx64 ", s=%" PRIx64 "\n",
8957c478bd9Sstevel@tonic-gate *addr, *size);
8967c478bd9Sstevel@tonic-gate }
8977c478bd9Sstevel@tonic-gate
8987c478bd9Sstevel@tonic-gate static void
kpm_init()8997c478bd9Sstevel@tonic-gate kpm_init()
9007c478bd9Sstevel@tonic-gate {
9017c478bd9Sstevel@tonic-gate struct segkpm_crargs b;
9027c478bd9Sstevel@tonic-gate
9037c478bd9Sstevel@tonic-gate /*
9047c478bd9Sstevel@tonic-gate * These variables were all designed for sfmmu in which segkpm is
9057c478bd9Sstevel@tonic-gate * mapped using a single pagesize - either 8KB or 4MB. On x86, we
9067c478bd9Sstevel@tonic-gate * might use 2+ page sizes on a single machine, so none of these
9077c478bd9Sstevel@tonic-gate * variables have a single correct value. They are set up as if we
9087c478bd9Sstevel@tonic-gate * always use a 4KB pagesize, which should do no harm. In the long
9097c478bd9Sstevel@tonic-gate * run, we should get rid of KPM's assumption that only a single
9107c478bd9Sstevel@tonic-gate * pagesize is used.
9117c478bd9Sstevel@tonic-gate */
9127c478bd9Sstevel@tonic-gate kpm_pgshft = MMU_PAGESHIFT;
9137c478bd9Sstevel@tonic-gate kpm_pgsz = MMU_PAGESIZE;
9147c478bd9Sstevel@tonic-gate kpm_pgoff = MMU_PAGEOFFSET;
9157c478bd9Sstevel@tonic-gate kpmp2pshft = 0;
9167c478bd9Sstevel@tonic-gate kpmpnpgs = 1;
9177c478bd9Sstevel@tonic-gate ASSERT(((uintptr_t)kpm_vbase & (kpm_pgsz - 1)) == 0);
9187c478bd9Sstevel@tonic-gate
9197c478bd9Sstevel@tonic-gate PRM_POINT("about to create segkpm");
9207c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER);
9217c478bd9Sstevel@tonic-gate
9227c478bd9Sstevel@tonic-gate if (seg_attach(&kas, kpm_vbase, kpm_size, segkpm) < 0)
9237c478bd9Sstevel@tonic-gate panic("cannot attach segkpm");
9247c478bd9Sstevel@tonic-gate
9257c478bd9Sstevel@tonic-gate b.prot = PROT_READ | PROT_WRITE;
9267c478bd9Sstevel@tonic-gate b.nvcolors = 1;
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gate if (segkpm_create(segkpm, (caddr_t)&b) != 0)
9297c478bd9Sstevel@tonic-gate panic("segkpm_create segkpm");
9307c478bd9Sstevel@tonic-gate
9317c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock);
93274ecdb51SJohn Levon
93374ecdb51SJohn Levon kpm_enable = 1;
93474ecdb51SJohn Levon
93574ecdb51SJohn Levon /*
93674ecdb51SJohn Levon * As the KPM was disabled while setting up the system, go back and fix
93774ecdb51SJohn Levon * CPU zero's access to its user page table. This is a bit gross, but
93874ecdb51SJohn Levon * we have a chicken and egg problem otherwise.
93974ecdb51SJohn Levon */
94074ecdb51SJohn Levon ASSERT(CPU->cpu_hat_info->hci_user_l3ptes == NULL);
94174ecdb51SJohn Levon CPU->cpu_hat_info->hci_user_l3ptes =
94274ecdb51SJohn Levon (x86pte_t *)hat_kpm_mapin_pfn(CPU->cpu_hat_info->hci_user_l3pfn);
943ae115bc7Smrj }
9447c478bd9Sstevel@tonic-gate
9457c478bd9Sstevel@tonic-gate /*
946ae115bc7Smrj * The debug info page provides enough information to allow external
947ae115bc7Smrj * inspectors (e.g. when running under a hypervisor) to bootstrap
948ae115bc7Smrj * themselves into allowing full-blown kernel debugging.
9497c478bd9Sstevel@tonic-gate */
950ae115bc7Smrj static void
init_debug_info(void)951ae115bc7Smrj init_debug_info(void)
952ae115bc7Smrj {
953ae115bc7Smrj caddr_t mem;
954ae115bc7Smrj debug_info_t *di;
955ae115bc7Smrj
956ae115bc7Smrj #ifndef __lint
957ae115bc7Smrj ASSERT(sizeof (debug_info_t) < MMU_PAGESIZE);
958ae115bc7Smrj #endif
959ae115bc7Smrj
960ae115bc7Smrj mem = BOP_ALLOC(bootops, (caddr_t)DEBUG_INFO_VA, MMU_PAGESIZE,
961ae115bc7Smrj MMU_PAGESIZE);
962ae115bc7Smrj
963ae115bc7Smrj if (mem != (caddr_t)DEBUG_INFO_VA)
964ae115bc7Smrj panic("BOP_ALLOC() failed");
965ae115bc7Smrj bzero(mem, MMU_PAGESIZE);
966ae115bc7Smrj
967ae115bc7Smrj di = (debug_info_t *)mem;
968ae115bc7Smrj
969ae115bc7Smrj di->di_magic = DEBUG_INFO_MAGIC;
970ae115bc7Smrj di->di_version = DEBUG_INFO_VERSION;
971843e1988Sjohnlev di->di_modules = (uintptr_t)&modules;
972843e1988Sjohnlev di->di_s_text = (uintptr_t)s_text;
973843e1988Sjohnlev di->di_e_text = (uintptr_t)e_text;
974843e1988Sjohnlev di->di_s_data = (uintptr_t)s_data;
975843e1988Sjohnlev di->di_e_data = (uintptr_t)e_data;
976843e1988Sjohnlev di->di_hat_htable_off = offsetof(hat_t, hat_htable);
977843e1988Sjohnlev di->di_ht_pfn_off = offsetof(htable_t, ht_pfn);
9787c478bd9Sstevel@tonic-gate }
9797c478bd9Sstevel@tonic-gate
9807c478bd9Sstevel@tonic-gate /*
981ae115bc7Smrj * Build the memlists and other kernel essential memory system data structures.
982ae115bc7Smrj * This is everything at valloc_base.
9837c478bd9Sstevel@tonic-gate */
9847c478bd9Sstevel@tonic-gate static void
startup_memlist(void)9857c478bd9Sstevel@tonic-gate startup_memlist(void)
9867c478bd9Sstevel@tonic-gate {
9877c478bd9Sstevel@tonic-gate size_t memlist_sz;
9887c478bd9Sstevel@tonic-gate size_t memseg_sz;
9897c478bd9Sstevel@tonic-gate size_t pagehash_sz;
9907c478bd9Sstevel@tonic-gate size_t pp_sz;
9917c478bd9Sstevel@tonic-gate uintptr_t va;
9927c478bd9Sstevel@tonic-gate size_t len;
9937c478bd9Sstevel@tonic-gate uint_t prot;
9947c478bd9Sstevel@tonic-gate pfn_t pfn;
9957c478bd9Sstevel@tonic-gate int memblocks;
9961de082f7SVikram Hegde pfn_t rsvd_high_pfn;
9971de082f7SVikram Hegde pgcnt_t rsvd_pgcnt;
9981de082f7SVikram Hegde size_t rsvdmemlist_sz;
9991de082f7SVikram Hegde int rsvdmemblocks;
10007c478bd9Sstevel@tonic-gate caddr_t pagecolor_mem;
10017c478bd9Sstevel@tonic-gate size_t pagecolor_memsz;
10027c478bd9Sstevel@tonic-gate caddr_t page_ctrs_mem;
10037c478bd9Sstevel@tonic-gate size_t page_ctrs_size;
1004d7d93655Sblakej size_t pse_table_alloc_size;
10057c478bd9Sstevel@tonic-gate struct memlist *current;
10067c478bd9Sstevel@tonic-gate extern void startup_build_mem_nodes(struct memlist *);
10077c478bd9Sstevel@tonic-gate
10087c478bd9Sstevel@tonic-gate /* XX64 fix these - they should be in include files */
10097c478bd9Sstevel@tonic-gate extern size_t page_coloring_init(uint_t, int, int);
10107c478bd9Sstevel@tonic-gate extern void page_coloring_setup(caddr_t);
10117c478bd9Sstevel@tonic-gate
10127c478bd9Sstevel@tonic-gate PRM_POINT("startup_memlist() starting...");
10137c478bd9Sstevel@tonic-gate
10147c478bd9Sstevel@tonic-gate /*
10157c478bd9Sstevel@tonic-gate * Use leftover large page nucleus text/data space for loadable modules.
10167c478bd9Sstevel@tonic-gate * Use at most MODTEXT/MODDATA.
10177c478bd9Sstevel@tonic-gate */
1018ae115bc7Smrj len = kbm_nucleus_size;
1019ae115bc7Smrj ASSERT(len > MMU_PAGESIZE);
10207c478bd9Sstevel@tonic-gate
10217c478bd9Sstevel@tonic-gate moddata = (caddr_t)ROUND_UP_PAGE(e_data);
1022ae115bc7Smrj e_moddata = (caddr_t)P2ROUNDUP((uintptr_t)e_data, (uintptr_t)len);
10237c478bd9Sstevel@tonic-gate if (e_moddata - moddata > MODDATA)
10247c478bd9Sstevel@tonic-gate e_moddata = moddata + MODDATA;
10257c478bd9Sstevel@tonic-gate
10267c478bd9Sstevel@tonic-gate modtext = (caddr_t)ROUND_UP_PAGE(e_text);
1027ae115bc7Smrj e_modtext = (caddr_t)P2ROUNDUP((uintptr_t)e_text, (uintptr_t)len);
10287c478bd9Sstevel@tonic-gate if (e_modtext - modtext > MODTEXT)
10297c478bd9Sstevel@tonic-gate e_modtext = modtext + MODTEXT;
10307c478bd9Sstevel@tonic-gate
10317c478bd9Sstevel@tonic-gate econtig = e_moddata;
10327c478bd9Sstevel@tonic-gate
10337c478bd9Sstevel@tonic-gate PRM_DEBUG(modtext);
10347c478bd9Sstevel@tonic-gate PRM_DEBUG(e_modtext);
10357c478bd9Sstevel@tonic-gate PRM_DEBUG(moddata);
10367c478bd9Sstevel@tonic-gate PRM_DEBUG(e_moddata);
10377c478bd9Sstevel@tonic-gate PRM_DEBUG(econtig);
10387c478bd9Sstevel@tonic-gate
10397c478bd9Sstevel@tonic-gate /*
1040ae115bc7Smrj * Examine the boot loader physical memory map to find out:
10417c478bd9Sstevel@tonic-gate * - total memory in system - physinstalled
10427c478bd9Sstevel@tonic-gate * - the max physical address - physmax
1043ae115bc7Smrj * - the number of discontiguous segments of memory.
10447c478bd9Sstevel@tonic-gate */
10457c478bd9Sstevel@tonic-gate if (prom_debug)
1046ae115bc7Smrj print_memlist("boot physinstalled",
10477c478bd9Sstevel@tonic-gate bootops->boot_mem->physinstalled);
1048a3114836SGerry Liu installed_top_size_ex(bootops->boot_mem->physinstalled, &physmax,
10497c478bd9Sstevel@tonic-gate &physinstalled, &memblocks);
10507c478bd9Sstevel@tonic-gate PRM_DEBUG(physmax);
10517c478bd9Sstevel@tonic-gate PRM_DEBUG(physinstalled);
10527c478bd9Sstevel@tonic-gate PRM_DEBUG(memblocks);
10537c478bd9Sstevel@tonic-gate
10547c478bd9Sstevel@tonic-gate /*
105504909c8cSJohn Levon * We no longer support any form of memory DR.
1056a3114836SGerry Liu */
1057a3114836SGerry Liu plat_dr_physmax = 0;
1058a3114836SGerry Liu
1059a3114836SGerry Liu /*
10601de082f7SVikram Hegde * Examine the bios reserved memory to find out:
10611de082f7SVikram Hegde * - the number of discontiguous segments of memory.
10621de082f7SVikram Hegde */
10631de082f7SVikram Hegde if (prom_debug)
10641de082f7SVikram Hegde print_memlist("boot reserved mem",
10651de082f7SVikram Hegde bootops->boot_mem->rsvdmem);
1066a3114836SGerry Liu installed_top_size_ex(bootops->boot_mem->rsvdmem, &rsvd_high_pfn,
10671de082f7SVikram Hegde &rsvd_pgcnt, &rsvdmemblocks);
10681de082f7SVikram Hegde PRM_DEBUG(rsvd_high_pfn);
10691de082f7SVikram Hegde PRM_DEBUG(rsvd_pgcnt);
10701de082f7SVikram Hegde PRM_DEBUG(rsvdmemblocks);
10711de082f7SVikram Hegde
10721de082f7SVikram Hegde /*
10737c478bd9Sstevel@tonic-gate * Initialize hat's mmu parameters.
10747c478bd9Sstevel@tonic-gate * Check for enforce-prot-exec in boot environment. It's used to
10757c478bd9Sstevel@tonic-gate * enable/disable support for the page table entry NX bit.
10767c478bd9Sstevel@tonic-gate * The default is to enforce PROT_EXEC on processors that support NX.
10777c478bd9Sstevel@tonic-gate * Boot seems to round up the "len", but 8 seems to be big enough.
10787c478bd9Sstevel@tonic-gate */
10797c478bd9Sstevel@tonic-gate mmu_init();
10807c478bd9Sstevel@tonic-gate
10817c478bd9Sstevel@tonic-gate
10827c478bd9Sstevel@tonic-gate startup_build_mem_nodes(bootops->boot_mem->physinstalled);
10837c478bd9Sstevel@tonic-gate
10847c478bd9Sstevel@tonic-gate if (BOP_GETPROPLEN(bootops, "enforce-prot-exec") >= 0) {
10857c478bd9Sstevel@tonic-gate int len = BOP_GETPROPLEN(bootops, "enforce-prot-exec");
10867c478bd9Sstevel@tonic-gate char value[8];
10877c478bd9Sstevel@tonic-gate
10887c478bd9Sstevel@tonic-gate if (len < 8)
10897c478bd9Sstevel@tonic-gate (void) BOP_GETPROP(bootops, "enforce-prot-exec", value);
10907c478bd9Sstevel@tonic-gate else
10917c478bd9Sstevel@tonic-gate (void) strcpy(value, "");
10927c478bd9Sstevel@tonic-gate if (strcmp(value, "off") == 0)
10937c478bd9Sstevel@tonic-gate mmu.pt_nx = 0;
10947c478bd9Sstevel@tonic-gate }
10957c478bd9Sstevel@tonic-gate PRM_DEBUG(mmu.pt_nx);
10967c478bd9Sstevel@tonic-gate
10977c478bd9Sstevel@tonic-gate /*
10987c478bd9Sstevel@tonic-gate * We will need page_t's for every page in the system, except for
10997c478bd9Sstevel@tonic-gate * memory mapped at or above above the start of the kernel text segment.
11007c478bd9Sstevel@tonic-gate *
11017c478bd9Sstevel@tonic-gate * pages above e_modtext are attributed to kernel debugger (obp_pages)
11027c478bd9Sstevel@tonic-gate */
11037c478bd9Sstevel@tonic-gate npages = physinstalled - 1; /* avail_filter() skips page 0, so "- 1" */
11047c478bd9Sstevel@tonic-gate obp_pages = 0;
11057c478bd9Sstevel@tonic-gate va = KERNEL_TEXT;
1106ae115bc7Smrj while (kbm_probe(&va, &len, &pfn, &prot) != 0) {
11077c478bd9Sstevel@tonic-gate npages -= len >> MMU_PAGESHIFT;
11087c478bd9Sstevel@tonic-gate if (va >= (uintptr_t)e_moddata)
11097c478bd9Sstevel@tonic-gate obp_pages += len >> MMU_PAGESHIFT;
11107c478bd9Sstevel@tonic-gate va += len;
11117c478bd9Sstevel@tonic-gate }
11127c478bd9Sstevel@tonic-gate PRM_DEBUG(npages);
11137c478bd9Sstevel@tonic-gate PRM_DEBUG(obp_pages);
11147c478bd9Sstevel@tonic-gate
11157c478bd9Sstevel@tonic-gate /*
111635b1ab99Sjosephb * If physmem is patched to be non-zero, use it instead of the computed
111735b1ab99Sjosephb * value unless it is larger than the actual amount of memory on hand.
11187c478bd9Sstevel@tonic-gate */
11194944b02eSkchow if (physmem == 0 || physmem > npages) {
11207c478bd9Sstevel@tonic-gate physmem = npages;
11214944b02eSkchow } else if (physmem < npages) {
1122f53ad214Skchow orig_npages = npages;
11237c478bd9Sstevel@tonic-gate npages = physmem;
11244944b02eSkchow }
11257c478bd9Sstevel@tonic-gate PRM_DEBUG(physmem);
11267c478bd9Sstevel@tonic-gate
11277c478bd9Sstevel@tonic-gate /*
11287c478bd9Sstevel@tonic-gate * We now compute the sizes of all the initial allocations for
11297c478bd9Sstevel@tonic-gate * structures the kernel needs in order do kmem_alloc(). These
11307c478bd9Sstevel@tonic-gate * include:
11317c478bd9Sstevel@tonic-gate * memsegs
11327c478bd9Sstevel@tonic-gate * memlists
11337c478bd9Sstevel@tonic-gate * page hash table
11347c478bd9Sstevel@tonic-gate * page_t's
11357c478bd9Sstevel@tonic-gate * page coloring data structs
11367c478bd9Sstevel@tonic-gate */
11377c478bd9Sstevel@tonic-gate memseg_sz = sizeof (struct memseg) * (memblocks + POSS_NEW_FRAGMENTS);
11387c478bd9Sstevel@tonic-gate ADD_TO_ALLOCATIONS(memseg_base, memseg_sz);
11397c478bd9Sstevel@tonic-gate PRM_DEBUG(memseg_sz);
11407c478bd9Sstevel@tonic-gate
11417c478bd9Sstevel@tonic-gate /*
1142ae115bc7Smrj * Reserve space for memlists. There's no real good way to know exactly
1143ae115bc7Smrj * how much room we'll need, but this should be a good upper bound.
11447c478bd9Sstevel@tonic-gate */
11457c478bd9Sstevel@tonic-gate memlist_sz = ROUND_UP_PAGE(2 * sizeof (struct memlist) *
11467c478bd9Sstevel@tonic-gate (memblocks + POSS_NEW_FRAGMENTS));
11477c478bd9Sstevel@tonic-gate ADD_TO_ALLOCATIONS(memlist, memlist_sz);
11487c478bd9Sstevel@tonic-gate PRM_DEBUG(memlist_sz);
11497c478bd9Sstevel@tonic-gate
11507c478bd9Sstevel@tonic-gate /*
11511de082f7SVikram Hegde * Reserve space for bios reserved memlists.
11521de082f7SVikram Hegde */
11531de082f7SVikram Hegde rsvdmemlist_sz = ROUND_UP_PAGE(2 * sizeof (struct memlist) *
11541de082f7SVikram Hegde (rsvdmemblocks + POSS_NEW_FRAGMENTS));
11551de082f7SVikram Hegde ADD_TO_ALLOCATIONS(bios_rsvd, rsvdmemlist_sz);
11561de082f7SVikram Hegde PRM_DEBUG(rsvdmemlist_sz);
11571de082f7SVikram Hegde
1158cb15d5d9SPeter Rival /* LINTED */
1159cb15d5d9SPeter Rival ASSERT(P2SAMEHIGHBIT((1 << PP_SHIFT), sizeof (struct page)));
11601de082f7SVikram Hegde /*
11617c478bd9Sstevel@tonic-gate * The page structure hash table size is a power of 2
11627c478bd9Sstevel@tonic-gate * such that the average hash chain length is PAGE_HASHAVELEN.
11637c478bd9Sstevel@tonic-gate */
11647c478bd9Sstevel@tonic-gate page_hashsz = npages / PAGE_HASHAVELEN;
1165cb15d5d9SPeter Rival page_hashsz_shift = highbit(page_hashsz);
1166cb15d5d9SPeter Rival page_hashsz = 1 << page_hashsz_shift;
11677c478bd9Sstevel@tonic-gate pagehash_sz = sizeof (struct page *) * page_hashsz;
11687c478bd9Sstevel@tonic-gate ADD_TO_ALLOCATIONS(page_hash, pagehash_sz);
11697c478bd9Sstevel@tonic-gate PRM_DEBUG(pagehash_sz);
11707c478bd9Sstevel@tonic-gate
11717c478bd9Sstevel@tonic-gate /*
1172ae115bc7Smrj * Set aside room for the page structures themselves.
11737c478bd9Sstevel@tonic-gate */
1174ae115bc7Smrj PRM_DEBUG(npages);
1175ae115bc7Smrj pp_sz = sizeof (struct page) * npages;
11767c478bd9Sstevel@tonic-gate ADD_TO_ALLOCATIONS(pp_base, pp_sz);
11777c478bd9Sstevel@tonic-gate PRM_DEBUG(pp_sz);
11787c478bd9Sstevel@tonic-gate
11797c478bd9Sstevel@tonic-gate /*
11807c478bd9Sstevel@tonic-gate * determine l2 cache info and memory size for page coloring
11817c478bd9Sstevel@tonic-gate */
11827c478bd9Sstevel@tonic-gate (void) getl2cacheinfo(CPU,
11837c478bd9Sstevel@tonic-gate &l2cache_sz, &l2cache_linesz, &l2cache_assoc);
11847c478bd9Sstevel@tonic-gate pagecolor_memsz =
11857c478bd9Sstevel@tonic-gate page_coloring_init(l2cache_sz, l2cache_linesz, l2cache_assoc);
11867c478bd9Sstevel@tonic-gate ADD_TO_ALLOCATIONS(pagecolor_mem, pagecolor_memsz);
11877c478bd9Sstevel@tonic-gate PRM_DEBUG(pagecolor_memsz);
11887c478bd9Sstevel@tonic-gate
11897c478bd9Sstevel@tonic-gate page_ctrs_size = page_ctrs_sz();
11907c478bd9Sstevel@tonic-gate ADD_TO_ALLOCATIONS(page_ctrs_mem, page_ctrs_size);
11917c478bd9Sstevel@tonic-gate PRM_DEBUG(page_ctrs_size);
11927c478bd9Sstevel@tonic-gate
1193d7d93655Sblakej /*
1194d7d93655Sblakej * Allocate the array that protects pp->p_selock.
1195d7d93655Sblakej */
1196d7d93655Sblakej pse_shift = size_pse_array(physmem, max_ncpus);
1197d7d93655Sblakej pse_table_size = 1 << pse_shift;
1198d7d93655Sblakej pse_table_alloc_size = pse_table_size * sizeof (pad_mutex_t);
1199d7d93655Sblakej ADD_TO_ALLOCATIONS(pse_mutex, pse_table_alloc_size);
1200d7d93655Sblakej
12017c478bd9Sstevel@tonic-gate valloc_sz = ROUND_UP_LPAGE(valloc_sz);
1202ae115bc7Smrj valloc_base = VALLOC_BASE;
120335b1ab99Sjosephb
120435b1ab99Sjosephb /*
120504909c8cSJohn Levon * The signicant memory-sized regions are roughly sized as follows in
120604909c8cSJohn Levon * the default layout with max physmem:
120704909c8cSJohn Levon * segkpm: 1x physmem allocated (but 1Tb room, below VALLOC_BASE)
120804909c8cSJohn Levon * segzio: 1.5x physmem
120904909c8cSJohn Levon * segkvmm: 4x physmem
121004909c8cSJohn Levon * heap: whatever's left up to COREHEAP_BASE, at least 1.5x physmem
1211af868f46SMatthew Ahrens *
121204909c8cSJohn Levon * The idea is that we leave enough room to avoid fragmentation issues,
121304909c8cSJohn Levon * so we would like the VA arenas to have some extra.
1214af868f46SMatthew Ahrens *
121504909c8cSJohn Levon * Ignoring the loose change of segkp, valloc, and such, this means that
121604909c8cSJohn Levon * as COREHEAP_BASE-VALLOC_BASE=2Tb, we can accommodate a physmem up to
121704909c8cSJohn Levon * about (2Tb / 7.0), rounded down to 256Gb in the check below.
121804909c8cSJohn Levon *
121904909c8cSJohn Levon * Note that KPM lives below VALLOC_BASE, but we want to include it in
122004909c8cSJohn Levon * adjustments, hence the 8 below.
122104909c8cSJohn Levon *
122204909c8cSJohn Levon * Beyond 256Gb, we push segkpm_base (and hence kernelbase and
122304909c8cSJohn Levon * _userlimit) down to accommodate the VA requirements above.
122435b1ab99Sjosephb */
122504909c8cSJohn Levon if (physmax + 1 > mmu_btop(TERABYTE / 4)) {
122604909c8cSJohn Levon uint64_t physmem_bytes = mmu_ptob(physmax + 1);
122704909c8cSJohn Levon uint64_t adjustment = 8 * (physmem_bytes - (TERABYTE / 4));
122835b1ab99Sjosephb
122904909c8cSJohn Levon PRM_DEBUG(adjustment);
1230a3114836SGerry Liu
1231af868f46SMatthew Ahrens /*
123204909c8cSJohn Levon * segkpm_base is always aligned on a L3 PTE boundary.
1233af868f46SMatthew Ahrens */
123404909c8cSJohn Levon segkpm_base -= P2ROUNDUP(adjustment, KERNEL_REDZONE_SIZE);
123535b1ab99Sjosephb
123604909c8cSJohn Levon /*
123704909c8cSJohn Levon * But make sure we leave some space for user apps above hole.
123804909c8cSJohn Levon */
123935b1ab99Sjosephb segkpm_base = MAX(segkpm_base, AMD64_VA_HOLE_END + TERABYTE);
124035b1ab99Sjosephb
124104909c8cSJohn Levon ASSERT(segkpm_base <= SEGKPM_BASE);
124204909c8cSJohn Levon
124304909c8cSJohn Levon valloc_base = segkpm_base + P2ROUNDUP(physmem_bytes, ONE_GIG);
12446c8c89eaSKit Chow if (valloc_base < segkpm_base)
12456c8c89eaSKit Chow panic("not enough kernel VA to support memory size");
124635b1ab99Sjosephb }
124704909c8cSJohn Levon
124804909c8cSJohn Levon PRM_DEBUG(segkpm_base);
12497c478bd9Sstevel@tonic-gate PRM_DEBUG(valloc_base);
1250ae115bc7Smrj
1251ae115bc7Smrj /*
1252ae115bc7Smrj * do all the initial allocations
1253ae115bc7Smrj */
1254ae115bc7Smrj perform_allocations();
1255ae115bc7Smrj
1256ae115bc7Smrj /*
1257ae115bc7Smrj * Build phys_install and phys_avail in kernel memspace.
1258ae115bc7Smrj * - phys_install should be all memory in the system.
1259ae115bc7Smrj * - phys_avail is phys_install minus any memory mapped before this
1260ae115bc7Smrj * point above KERNEL_TEXT.
1261ae115bc7Smrj */
1262ae115bc7Smrj current = phys_install = memlist;
1263ae115bc7Smrj copy_memlist_filter(bootops->boot_mem->physinstalled, ¤t, NULL);
1264ae115bc7Smrj if ((caddr_t)current > (caddr_t)memlist + memlist_sz)
1265ae115bc7Smrj panic("physinstalled was too big!");
1266ae115bc7Smrj if (prom_debug)
1267ae115bc7Smrj print_memlist("phys_install", phys_install);
1268ae115bc7Smrj
1269ae115bc7Smrj phys_avail = current;
1270ae115bc7Smrj PRM_POINT("Building phys_avail:\n");
1271ae115bc7Smrj copy_memlist_filter(bootops->boot_mem->physinstalled, ¤t,
1272ae115bc7Smrj avail_filter);
1273ae115bc7Smrj if ((caddr_t)current > (caddr_t)memlist + memlist_sz)
1274ae115bc7Smrj panic("physavail was too big!");
1275ae115bc7Smrj if (prom_debug)
1276ae115bc7Smrj print_memlist("phys_avail", phys_avail);
1277a3114836SGerry Liu #ifndef __xpv
1278a3114836SGerry Liu /*
1279a3114836SGerry Liu * Free unused memlist items, which may be used by memory DR driver
1280a3114836SGerry Liu * at runtime.
1281a3114836SGerry Liu */
1282a3114836SGerry Liu if ((caddr_t)current < (caddr_t)memlist + memlist_sz) {
1283a3114836SGerry Liu memlist_free_block((caddr_t)current,
1284a3114836SGerry Liu (caddr_t)memlist + memlist_sz - (caddr_t)current);
1285a3114836SGerry Liu }
1286a3114836SGerry Liu #endif
1287ae115bc7Smrj
1288ae115bc7Smrj /*
12891de082f7SVikram Hegde * Build bios reserved memspace
12901de082f7SVikram Hegde */
12911de082f7SVikram Hegde current = bios_rsvd;
12921de082f7SVikram Hegde copy_memlist_filter(bootops->boot_mem->rsvdmem, ¤t, NULL);
12931de082f7SVikram Hegde if ((caddr_t)current > (caddr_t)bios_rsvd + rsvdmemlist_sz)
12941de082f7SVikram Hegde panic("bios_rsvd was too big!");
12951de082f7SVikram Hegde if (prom_debug)
12961de082f7SVikram Hegde print_memlist("bios_rsvd", bios_rsvd);
1297a3114836SGerry Liu #ifndef __xpv
1298a3114836SGerry Liu /*
1299a3114836SGerry Liu * Free unused memlist items, which may be used by memory DR driver
1300a3114836SGerry Liu * at runtime.
1301a3114836SGerry Liu */
1302a3114836SGerry Liu if ((caddr_t)current < (caddr_t)bios_rsvd + rsvdmemlist_sz) {
1303a3114836SGerry Liu memlist_free_block((caddr_t)current,
1304a3114836SGerry Liu (caddr_t)bios_rsvd + rsvdmemlist_sz - (caddr_t)current);
1305a3114836SGerry Liu }
1306a3114836SGerry Liu #endif
13071de082f7SVikram Hegde
13081de082f7SVikram Hegde /*
1309ae115bc7Smrj * setup page coloring
1310ae115bc7Smrj */
1311ae115bc7Smrj page_coloring_setup(pagecolor_mem);
1312ae115bc7Smrj page_lock_init(); /* currently a no-op */
1313ae115bc7Smrj
1314ae115bc7Smrj /*
1315ae115bc7Smrj * free page list counters
1316ae115bc7Smrj */
1317ae115bc7Smrj (void) page_ctrs_alloc(page_ctrs_mem);
1318ae115bc7Smrj
1319ae115bc7Smrj /*
132006fb6a36Sdv142724 * Size the pcf array based on the number of cpus in the box at
132106fb6a36Sdv142724 * boot time.
132206fb6a36Sdv142724 */
132306fb6a36Sdv142724
132406fb6a36Sdv142724 pcf_init();
132506fb6a36Sdv142724
132606fb6a36Sdv142724 /*
1327ae115bc7Smrj * Initialize the page structures from the memory lists.
1328ae115bc7Smrj */
1329ae115bc7Smrj availrmem_initial = availrmem = freemem = 0;
1330ae115bc7Smrj PRM_POINT("Calling kphysm_init()...");
1331ae115bc7Smrj npages = kphysm_init(pp_base, npages);
1332ae115bc7Smrj PRM_POINT("kphysm_init() done");
1333ae115bc7Smrj PRM_DEBUG(npages);
1334ae115bc7Smrj
1335ae115bc7Smrj init_debug_info();
1336ae115bc7Smrj
1337ae115bc7Smrj /*
1338ae115bc7Smrj * Now that page_t's have been initialized, remove all the
1339ae115bc7Smrj * initial allocation pages from the kernel free page lists.
1340ae115bc7Smrj */
1341ae115bc7Smrj boot_mapin((caddr_t)valloc_base, valloc_sz);
13420cfdb603Sjosephb boot_mapin((caddr_t)MISC_VA_BASE, MISC_VA_SIZE);
1343ae115bc7Smrj PRM_POINT("startup_memlist() done");
1344ae115bc7Smrj
1345ae115bc7Smrj PRM_DEBUG(valloc_sz);
13462cb27123Saguzovsk
1347567d55e1Saguzovsk if ((availrmem >> (30 - MMU_PAGESHIFT)) >=
1348567d55e1Saguzovsk textrepl_min_gb && l2cache_sz <= 2 << 20) {
1349567d55e1Saguzovsk extern size_t textrepl_size_thresh;
13502cb27123Saguzovsk textrepl_size_thresh = (16 << 20) - 1;
13512cb27123Saguzovsk }
1352ae115bc7Smrj }
1353ae115bc7Smrj
1354ae115bc7Smrj /*
1355ae115bc7Smrj * Layout the kernel's part of address space and initialize kmem allocator.
1356ae115bc7Smrj */
1357ae115bc7Smrj static void
startup_kmem(void)1358ae115bc7Smrj startup_kmem(void)
1359ae115bc7Smrj {
1360932dc8e5Sdp78419 extern void page_set_colorequiv_arr(void);
136174ecdb51SJohn Levon #if !defined(__xpv)
136274ecdb51SJohn Levon extern uint64_t kpti_kbase;
136374ecdb51SJohn Levon #endif
1364932dc8e5Sdp78419
1365ae115bc7Smrj PRM_POINT("startup_kmem() starting...");
13667c478bd9Sstevel@tonic-gate
13677c478bd9Sstevel@tonic-gate if (eprom_kernelbase && eprom_kernelbase != KERNELBASE)
13687c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!kernelbase cannot be changed on 64-bit "
13697c478bd9Sstevel@tonic-gate "systems.");
137035b1ab99Sjosephb kernelbase = segkpm_base - KERNEL_REDZONE_SIZE;
13717c478bd9Sstevel@tonic-gate core_base = (uintptr_t)COREHEAP_BASE;
1372ae115bc7Smrj core_size = (size_t)MISC_VA_BASE - COREHEAP_BASE;
13737c478bd9Sstevel@tonic-gate
13747c478bd9Sstevel@tonic-gate PRM_DEBUG(core_base);
13757c478bd9Sstevel@tonic-gate PRM_DEBUG(core_size);
1376ae115bc7Smrj PRM_DEBUG(kernelbase);
13777c478bd9Sstevel@tonic-gate
13787c478bd9Sstevel@tonic-gate ekernelheap = (char *)core_base;
1379ae115bc7Smrj PRM_DEBUG(ekernelheap);
13807c478bd9Sstevel@tonic-gate
13817c478bd9Sstevel@tonic-gate /*
13827c478bd9Sstevel@tonic-gate * Now that we know the real value of kernelbase,
13837c478bd9Sstevel@tonic-gate * update variables that were initialized with a value of
13847c478bd9Sstevel@tonic-gate * KERNELBASE (in common/conf/param.c).
13857c478bd9Sstevel@tonic-gate *
13867c478bd9Sstevel@tonic-gate * XXX The problem with this sort of hackery is that the
13877c478bd9Sstevel@tonic-gate * compiler just may feel like putting the const declarations
13887c478bd9Sstevel@tonic-gate * (in param.c) into the .text section. Perhaps they should
13897c478bd9Sstevel@tonic-gate * just be declared as variables there?
13907c478bd9Sstevel@tonic-gate */
13917c478bd9Sstevel@tonic-gate
13927c478bd9Sstevel@tonic-gate *(uintptr_t *)&_kernelbase = kernelbase;
13937c478bd9Sstevel@tonic-gate *(uintptr_t *)&_userlimit = kernelbase;
1394ccbaea4fSjosephb *(uintptr_t *)&_userlimit -= KERNELBASE - USERLIMIT;
139574ecdb51SJohn Levon #if !defined(__xpv)
139674ecdb51SJohn Levon kpti_kbase = kernelbase;
139774ecdb51SJohn Levon #endif
13987c478bd9Sstevel@tonic-gate PRM_DEBUG(_kernelbase);
13997c478bd9Sstevel@tonic-gate PRM_DEBUG(_userlimit);
14007c478bd9Sstevel@tonic-gate PRM_DEBUG(_userlimit32);
14017c478bd9Sstevel@tonic-gate
140274ecdb51SJohn Levon /* We have to re-do this now that we've modified _userlimit. */
140374ecdb51SJohn Levon mmu_calc_user_slots();
140474ecdb51SJohn Levon
140535b1ab99Sjosephb layout_kernel_va();
140635b1ab99Sjosephb
14077c478bd9Sstevel@tonic-gate /*
14087c478bd9Sstevel@tonic-gate * Initialize the kernel heap. Note 3rd argument must be > 1st.
14097c478bd9Sstevel@tonic-gate */
141035b1ab99Sjosephb kernelheap_init(kernelheap, ekernelheap,
141135b1ab99Sjosephb kernelheap + MMU_PAGESIZE,
1412ae115bc7Smrj (void *)core_base, (void *)(core_base + core_size));
14137c478bd9Sstevel@tonic-gate
1414843e1988Sjohnlev #if defined(__xpv)
1415843e1988Sjohnlev /*
1416843e1988Sjohnlev * Link pending events struct into cpu struct
1417843e1988Sjohnlev */
1418843e1988Sjohnlev CPU->cpu_m.mcpu_evt_pend = &cpu0_evt_data;
1419843e1988Sjohnlev #endif
14207c478bd9Sstevel@tonic-gate /*
14217c478bd9Sstevel@tonic-gate * Initialize kernel memory allocator.
14227c478bd9Sstevel@tonic-gate */
14237c478bd9Sstevel@tonic-gate kmem_init();
14247c478bd9Sstevel@tonic-gate
14257c478bd9Sstevel@tonic-gate /*
1426932dc8e5Sdp78419 * Factor in colorequiv to check additional 'equivalent' bins
1427932dc8e5Sdp78419 */
1428932dc8e5Sdp78419 page_set_colorequiv_arr();
1429932dc8e5Sdp78419
1430932dc8e5Sdp78419 /*
14317c478bd9Sstevel@tonic-gate * print this out early so that we know what's going on
14327c478bd9Sstevel@tonic-gate */
14337417cfdeSKuriakose Kuruvilla print_x86_featureset(x86_featureset);
14347c478bd9Sstevel@tonic-gate
14357c478bd9Sstevel@tonic-gate /*
14367c478bd9Sstevel@tonic-gate * Initialize bp_mapin().
14377c478bd9Sstevel@tonic-gate */
14387c478bd9Sstevel@tonic-gate bp_init(MMU_PAGESIZE, HAT_STORECACHING_OK);
14397c478bd9Sstevel@tonic-gate
1440f53ad214Skchow /*
1441f53ad214Skchow * orig_npages is non-zero if physmem has been configured for less
1442f53ad214Skchow * than the available memory.
1443f53ad214Skchow */
1444f53ad214Skchow if (orig_npages) {
144535b1ab99Sjosephb cmn_err(CE_WARN, "!%slimiting physmem to 0x%lx of 0x%lx pages",
144635b1ab99Sjosephb (npages == PHYSMEM ? "Due to virtual address space " : ""),
1447f53ad214Skchow npages, orig_npages);
1448f53ad214Skchow }
14497c478bd9Sstevel@tonic-gate
14507c478bd9Sstevel@tonic-gate #ifdef KERNELBASE_ABI_MIN
14517c478bd9Sstevel@tonic-gate if (kernelbase < (uintptr_t)KERNELBASE_ABI_MIN) {
14527c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!kernelbase set to 0x%lx, system is not "
14537c478bd9Sstevel@tonic-gate "i386 ABI compliant.", (uintptr_t)kernelbase);
14547c478bd9Sstevel@tonic-gate }
14557c478bd9Sstevel@tonic-gate #endif
14567c478bd9Sstevel@tonic-gate
1457a3114836SGerry Liu #ifndef __xpv
1458a3114836SGerry Liu if (plat_dr_support_memory()) {
1459a3114836SGerry Liu mem_config_init();
1460a3114836SGerry Liu }
1461a3114836SGerry Liu #else /* __xpv */
1462843e1988Sjohnlev /*
1463843e1988Sjohnlev * Some of the xen start information has to be relocated up
1464843e1988Sjohnlev * into the kernel's permanent address space.
1465843e1988Sjohnlev */
1466843e1988Sjohnlev PRM_POINT("calling xen_relocate_start_info()");
1467843e1988Sjohnlev xen_relocate_start_info();
1468843e1988Sjohnlev PRM_POINT("xen_relocate_start_info() done");
1469843e1988Sjohnlev
1470843e1988Sjohnlev /*
1471843e1988Sjohnlev * (Update the vcpu pointer in our cpu structure to point into
1472843e1988Sjohnlev * the relocated shared info.)
1473843e1988Sjohnlev */
1474843e1988Sjohnlev CPU->cpu_m.mcpu_vcpu_info =
1475843e1988Sjohnlev &HYPERVISOR_shared_info->vcpu_info[CPU->cpu_id];
1476a3114836SGerry Liu #endif /* __xpv */
1477843e1988Sjohnlev
1478ae115bc7Smrj PRM_POINT("startup_kmem() done");
14797c478bd9Sstevel@tonic-gate }
14807c478bd9Sstevel@tonic-gate
1481551bc2a6Smrj #ifndef __xpv
1482551bc2a6Smrj /*
1483551bc2a6Smrj * If we have detected that we are running in an HVM environment, we need
1484551bc2a6Smrj * to prepend the PV driver directory to the module search path.
1485551bc2a6Smrj */
1486551bc2a6Smrj #define HVM_MOD_DIR "/platform/i86hvm/kernel"
1487551bc2a6Smrj static void
update_default_path()1488551bc2a6Smrj update_default_path()
1489551bc2a6Smrj {
1490551bc2a6Smrj char *current, *newpath;
1491551bc2a6Smrj int newlen;
1492551bc2a6Smrj
1493551bc2a6Smrj /*
1494551bc2a6Smrj * We are about to resync with krtld. krtld will reset its
1495551bc2a6Smrj * internal module search path iff Solaris has set default_path.
1496551bc2a6Smrj * We want to be sure we're prepending this new directory to the
1497551bc2a6Smrj * right search path.
1498551bc2a6Smrj */
1499551bc2a6Smrj current = (default_path == NULL) ? kobj_module_path : default_path;
1500551bc2a6Smrj
1501b6611e3bSStuart Maybee newlen = strlen(HVM_MOD_DIR) + strlen(current) + 2;
1502551bc2a6Smrj newpath = kmem_alloc(newlen, KM_SLEEP);
1503551bc2a6Smrj (void) strcpy(newpath, HVM_MOD_DIR);
1504551bc2a6Smrj (void) strcat(newpath, " ");
1505551bc2a6Smrj (void) strcat(newpath, current);
1506551bc2a6Smrj
1507551bc2a6Smrj default_path = newpath;
1508551bc2a6Smrj }
1509551bc2a6Smrj #endif
1510551bc2a6Smrj
15117c478bd9Sstevel@tonic-gate static void
startup_modules(void)15127c478bd9Sstevel@tonic-gate startup_modules(void)
15137c478bd9Sstevel@tonic-gate {
1514ed5289f9SKen Erickson int cnt;
15157c478bd9Sstevel@tonic-gate extern void prom_setup(void);
1516ed5289f9SKen Erickson int32_t v, h;
1517ed5289f9SKen Erickson char d[11];
1518ed5289f9SKen Erickson char *cp;
1519e4b86885SCheng Sean Ye cmi_hdl_t hdl;
15207c478bd9Sstevel@tonic-gate
15217c478bd9Sstevel@tonic-gate PRM_POINT("startup_modules() starting...");
1522843e1988Sjohnlev
1523843e1988Sjohnlev #ifndef __xpv
152479ec9da8SYuri Pankov if ((get_hwenv() & HW_XEN_HVM) != 0)
1525551bc2a6Smrj update_default_path();
1526843e1988Sjohnlev #endif
15277c478bd9Sstevel@tonic-gate
15287c478bd9Sstevel@tonic-gate /*
15297c478bd9Sstevel@tonic-gate * Read the GMT lag from /etc/rtc_config.
15307c478bd9Sstevel@tonic-gate */
1531ae115bc7Smrj sgmtl(process_rtc_config_file());
15327c478bd9Sstevel@tonic-gate
15337c478bd9Sstevel@tonic-gate /*
15347c478bd9Sstevel@tonic-gate * Calculate default settings of system parameters based upon
15357c478bd9Sstevel@tonic-gate * maxusers, yet allow to be overridden via the /etc/system file.
15367c478bd9Sstevel@tonic-gate */
15377c478bd9Sstevel@tonic-gate param_calc(0);
15387c478bd9Sstevel@tonic-gate
15397c478bd9Sstevel@tonic-gate mod_setup();
15407c478bd9Sstevel@tonic-gate
15417c478bd9Sstevel@tonic-gate /*
15427c478bd9Sstevel@tonic-gate * Initialize system parameters.
15437c478bd9Sstevel@tonic-gate */
15447c478bd9Sstevel@tonic-gate param_init();
15457c478bd9Sstevel@tonic-gate
15467c478bd9Sstevel@tonic-gate /*
15479acbbeafSnn35248 * Initialize the default brands
15489acbbeafSnn35248 */
15499acbbeafSnn35248 brand_init();
15509acbbeafSnn35248
15519acbbeafSnn35248 /*
15527c478bd9Sstevel@tonic-gate * maxmem is the amount of physical memory we're playing with.
15537c478bd9Sstevel@tonic-gate */
15547c478bd9Sstevel@tonic-gate maxmem = physmem;
15557c478bd9Sstevel@tonic-gate
15567c478bd9Sstevel@tonic-gate /*
15577c478bd9Sstevel@tonic-gate * Initialize segment management stuff.
15587c478bd9Sstevel@tonic-gate */
15597c478bd9Sstevel@tonic-gate seg_init();
15607c478bd9Sstevel@tonic-gate
15617c478bd9Sstevel@tonic-gate if (modload("fs", "specfs") == -1)
15627c478bd9Sstevel@tonic-gate halt("Can't load specfs");
15637c478bd9Sstevel@tonic-gate
15647c478bd9Sstevel@tonic-gate if (modload("fs", "devfs") == -1)
15657c478bd9Sstevel@tonic-gate halt("Can't load devfs");
15667c478bd9Sstevel@tonic-gate
1567facf4a8dSllai1 if (modload("fs", "dev") == -1)
1568facf4a8dSllai1 halt("Can't load dev");
1569facf4a8dSllai1
157035a5a358SJonathan Adams if (modload("fs", "procfs") == -1)
157135a5a358SJonathan Adams halt("Can't load procfs");
157235a5a358SJonathan Adams
157345916cd2Sjpk (void) modloadonly("sys", "lbl_edition");
157445916cd2Sjpk
15757c478bd9Sstevel@tonic-gate dispinit();
15767c478bd9Sstevel@tonic-gate
15777c478bd9Sstevel@tonic-gate /* Read cluster configuration data. */
15787c478bd9Sstevel@tonic-gate clconf_init();
15797c478bd9Sstevel@tonic-gate
1580843e1988Sjohnlev #if defined(__xpv)
1581349b53ddSStuart Maybee (void) ec_init();
1582843e1988Sjohnlev gnttab_init();
1583843e1988Sjohnlev (void) xs_early_init();
1584843e1988Sjohnlev #endif /* __xpv */
1585843e1988Sjohnlev
15867c478bd9Sstevel@tonic-gate /*
15877c478bd9Sstevel@tonic-gate * Create a kernel device tree. First, create rootnex and
15887c478bd9Sstevel@tonic-gate * then invoke bus specific code to probe devices.
15897c478bd9Sstevel@tonic-gate */
15907c478bd9Sstevel@tonic-gate setup_ddi();
15917aec1d6eScindi
1592074bb90dSTom Pothier #ifdef __xpv
1593074bb90dSTom Pothier if (DOMAIN_IS_INITDOMAIN(xen_info))
1594074bb90dSTom Pothier #endif
1595074bb90dSTom Pothier {
1596e41d648bSToomas Soome id_t smid;
1597e41d648bSToomas Soome smbios_system_t smsys;
1598e41d648bSToomas Soome smbios_info_t sminfo;
1599e41d648bSToomas Soome char *mfg;
1600074bb90dSTom Pothier /*
1601074bb90dSTom Pothier * Load the System Management BIOS into the global ksmbios
1602074bb90dSTom Pothier * handle, if an SMBIOS is present on this system.
1603e41d648bSToomas Soome * Also set "si-hw-provider" property, if not already set.
1604074bb90dSTom Pothier */
1605074bb90dSTom Pothier ksmbios = smbios_open(NULL, SMB_VERSION, ksmbios_flags, NULL);
1606e41d648bSToomas Soome if (ksmbios != NULL &&
1607e41d648bSToomas Soome ((smid = smbios_info_system(ksmbios, &smsys)) != SMB_ERR) &&
1608e41d648bSToomas Soome (smbios_info_common(ksmbios, smid, &sminfo)) != SMB_ERR) {
1609e41d648bSToomas Soome mfg = (char *)sminfo.smbi_manufacturer;
1610e41d648bSToomas Soome if (BOP_GETPROPLEN(bootops, "si-hw-provider") < 0) {
1611e41d648bSToomas Soome extern char hw_provider[];
1612e41d648bSToomas Soome int i;
1613e41d648bSToomas Soome for (i = 0; i < SYS_NMLN; i++) {
1614e41d648bSToomas Soome if (isprint(mfg[i]))
1615e41d648bSToomas Soome hw_provider[i] = mfg[i];
1616e41d648bSToomas Soome else {
1617e41d648bSToomas Soome hw_provider[i] = '\0';
1618e41d648bSToomas Soome break;
1619e41d648bSToomas Soome }
1620e41d648bSToomas Soome }
1621e41d648bSToomas Soome hw_provider[SYS_NMLN - 1] = '\0';
1622e41d648bSToomas Soome }
1623e41d648bSToomas Soome }
1624074bb90dSTom Pothier }
1625074bb90dSTom Pothier
1626074bb90dSTom Pothier
16277aec1d6eScindi /*
16289e3e4df2SGarrett D'Amore * Originally clconf_init() apparently needed the hostid. But
16299e3e4df2SGarrett D'Amore * this no longer appears to be true - it uses its own nodeid.
16309e3e4df2SGarrett D'Amore * By placing the hostid logic here, we are able to make use of
16319e3e4df2SGarrett D'Amore * the SMBIOS UUID.
16329e3e4df2SGarrett D'Amore */
16339e3e4df2SGarrett D'Amore if ((h = set_soft_hostid()) == HW_INVALID_HOSTID) {
16349e3e4df2SGarrett D'Amore cmn_err(CE_WARN, "Unable to set hostid");
16359e3e4df2SGarrett D'Amore } else {
16369e3e4df2SGarrett D'Amore for (v = h, cnt = 0; cnt < 10; cnt++) {
16379e3e4df2SGarrett D'Amore d[cnt] = (char)(v % 10);
16389e3e4df2SGarrett D'Amore v /= 10;
16399e3e4df2SGarrett D'Amore if (v == 0)
16409e3e4df2SGarrett D'Amore break;
16419e3e4df2SGarrett D'Amore }
16429e3e4df2SGarrett D'Amore for (cp = hw_serial; cnt >= 0; cnt--)
16439e3e4df2SGarrett D'Amore *cp++ = d[cnt] + '0';
16449e3e4df2SGarrett D'Amore *cp = 0;
16459e3e4df2SGarrett D'Amore }
16469e3e4df2SGarrett D'Amore
16479e3e4df2SGarrett D'Amore /*
1648e4b86885SCheng Sean Ye * Set up the CPU module subsystem for the boot cpu in the native
1649e4b86885SCheng Sean Ye * case, and all physical cpu resource in the xpv dom0 case.
1650e4b86885SCheng Sean Ye * Modifies the device tree, so this must be done after
1651e4b86885SCheng Sean Ye * setup_ddi().
16527aec1d6eScindi */
1653e4b86885SCheng Sean Ye #ifdef __xpv
1654e4b86885SCheng Sean Ye /*
1655e4b86885SCheng Sean Ye * If paravirtualized and on dom0 then we initialize all physical
1656e4b86885SCheng Sean Ye * cpu handles now; if paravirtualized on a domU then do not
1657e4b86885SCheng Sean Ye * initialize.
1658e4b86885SCheng Sean Ye */
1659e4b86885SCheng Sean Ye if (DOMAIN_IS_INITDOMAIN(xen_info)) {
1660e4b86885SCheng Sean Ye xen_mc_lcpu_cookie_t cpi;
16617aec1d6eScindi
1662e4b86885SCheng Sean Ye for (cpi = xen_physcpu_next(NULL); cpi != NULL;
1663e4b86885SCheng Sean Ye cpi = xen_physcpu_next(cpi)) {
1664e4b86885SCheng Sean Ye if ((hdl = cmi_init(CMI_HDL_SOLARIS_xVM_MCA,
1665e4b86885SCheng Sean Ye xen_physcpu_chipid(cpi), xen_physcpu_coreid(cpi),
1666e4b86885SCheng Sean Ye xen_physcpu_strandid(cpi))) != NULL &&
16677417cfdeSKuriakose Kuruvilla is_x86_feature(x86_featureset, X86FSET_MCA))
166820c794b3Sgavinm cmi_mca_init(hdl);
166920c794b3Sgavinm }
167020c794b3Sgavinm }
1671e4b86885SCheng Sean Ye #else
1672e4b86885SCheng Sean Ye /*
1673e4b86885SCheng Sean Ye * Initialize a handle for the boot cpu - others will initialize
1674d6694327SYuri Pankov * as they startup.
1675e4b86885SCheng Sean Ye */
1676d6694327SYuri Pankov if ((hdl = cmi_init(CMI_HDL_NATIVE, cmi_ntv_hwchipid(CPU),
1677d6694327SYuri Pankov cmi_ntv_hwcoreid(CPU), cmi_ntv_hwstrandid(CPU))) != NULL) {
1678d6694327SYuri Pankov if (is_x86_feature(x86_featureset, X86FSET_MCA))
1679e4b86885SCheng Sean Ye cmi_mca_init(hdl);
1680a3114836SGerry Liu CPU->cpu_m.mcpu_cmi_hdl = hdl;
1681a3114836SGerry Liu }
168220c794b3Sgavinm #endif /* __xpv */
16837aec1d6eScindi
16847c478bd9Sstevel@tonic-gate /*
16857c478bd9Sstevel@tonic-gate * Fake a prom tree such that /dev/openprom continues to work
16867c478bd9Sstevel@tonic-gate */
1687ae115bc7Smrj PRM_POINT("startup_modules: calling prom_setup...");
16887c478bd9Sstevel@tonic-gate prom_setup();
1689ae115bc7Smrj PRM_POINT("startup_modules: done");
16907c478bd9Sstevel@tonic-gate
16917c478bd9Sstevel@tonic-gate /*
16927c478bd9Sstevel@tonic-gate * Load all platform specific modules
16937c478bd9Sstevel@tonic-gate */
1694ae115bc7Smrj PRM_POINT("startup_modules: calling psm_modload...");
16957c478bd9Sstevel@tonic-gate psm_modload();
16967c478bd9Sstevel@tonic-gate
16977c478bd9Sstevel@tonic-gate PRM_POINT("startup_modules() done");
16987c478bd9Sstevel@tonic-gate }
16997c478bd9Sstevel@tonic-gate
1700ae115bc7Smrj /*
1701ae115bc7Smrj * claim a "setaside" boot page for use in the kernel
1702ae115bc7Smrj */
1703ae115bc7Smrj page_t *
boot_claim_page(pfn_t pfn)1704ae115bc7Smrj boot_claim_page(pfn_t pfn)
17057c478bd9Sstevel@tonic-gate {
1706ae115bc7Smrj page_t *pp;
17077c478bd9Sstevel@tonic-gate
1708ae115bc7Smrj pp = page_numtopp_nolock(pfn);
1709ae115bc7Smrj ASSERT(pp != NULL);
17107c478bd9Sstevel@tonic-gate
1711ae115bc7Smrj if (PP_ISBOOTPAGES(pp)) {
1712ae115bc7Smrj if (pp->p_next != NULL)
1713ae115bc7Smrj pp->p_next->p_prev = pp->p_prev;
1714ae115bc7Smrj if (pp->p_prev == NULL)
1715ae115bc7Smrj bootpages = pp->p_next;
1716ae115bc7Smrj else
1717ae115bc7Smrj pp->p_prev->p_next = pp->p_next;
1718ae115bc7Smrj } else {
17197c478bd9Sstevel@tonic-gate /*
1720ae115bc7Smrj * htable_attach() expects a base pagesize page
17217c478bd9Sstevel@tonic-gate */
1722ae115bc7Smrj if (pp->p_szc != 0)
1723ae115bc7Smrj page_boot_demote(pp);
1724ae115bc7Smrj pp = page_numtopp(pfn, SE_EXCL);
1725ae115bc7Smrj }
1726ae115bc7Smrj return (pp);
17277c478bd9Sstevel@tonic-gate }
17287c478bd9Sstevel@tonic-gate
17297c478bd9Sstevel@tonic-gate /*
17307c478bd9Sstevel@tonic-gate * Walk through the pagetables looking for pages mapped in by boot. If the
17317c478bd9Sstevel@tonic-gate * setaside flag is set the pages are expected to be returned to the
17327c478bd9Sstevel@tonic-gate * kernel later in boot, so we add them to the bootpages list.
17337c478bd9Sstevel@tonic-gate */
17347c478bd9Sstevel@tonic-gate static void
protect_boot_range(uintptr_t low,uintptr_t high,int setaside)17357c478bd9Sstevel@tonic-gate protect_boot_range(uintptr_t low, uintptr_t high, int setaside)
17367c478bd9Sstevel@tonic-gate {
17377c478bd9Sstevel@tonic-gate uintptr_t va = low;
17387c478bd9Sstevel@tonic-gate size_t len;
17397c478bd9Sstevel@tonic-gate uint_t prot;
17407c478bd9Sstevel@tonic-gate pfn_t pfn;
17417c478bd9Sstevel@tonic-gate page_t *pp;
17427c478bd9Sstevel@tonic-gate pgcnt_t boot_protect_cnt = 0;
17437c478bd9Sstevel@tonic-gate
1744ae115bc7Smrj while (kbm_probe(&va, &len, &pfn, &prot) != 0 && va < high) {
17457c478bd9Sstevel@tonic-gate if (va + len >= high)
17467c478bd9Sstevel@tonic-gate panic("0x%lx byte mapping at 0x%p exceeds boot's "
17477c478bd9Sstevel@tonic-gate "legal range.", len, (void *)va);
17487c478bd9Sstevel@tonic-gate
17497c478bd9Sstevel@tonic-gate while (len > 0) {
17507c478bd9Sstevel@tonic-gate pp = page_numtopp_alloc(pfn);
17517c478bd9Sstevel@tonic-gate if (pp != NULL) {
17527c478bd9Sstevel@tonic-gate if (setaside == 0)
17537c478bd9Sstevel@tonic-gate panic("Unexpected mapping by boot. "
17547c478bd9Sstevel@tonic-gate "addr=%p pfn=%lx\n",
17557c478bd9Sstevel@tonic-gate (void *)va, pfn);
17567c478bd9Sstevel@tonic-gate
17577c478bd9Sstevel@tonic-gate pp->p_next = bootpages;
1758ae115bc7Smrj pp->p_prev = NULL;
1759ae115bc7Smrj PP_SETBOOTPAGES(pp);
1760ae115bc7Smrj if (bootpages != NULL) {
1761ae115bc7Smrj bootpages->p_prev = pp;
1762ae115bc7Smrj }
17637c478bd9Sstevel@tonic-gate bootpages = pp;
17647c478bd9Sstevel@tonic-gate ++boot_protect_cnt;
17657c478bd9Sstevel@tonic-gate }
17667c478bd9Sstevel@tonic-gate
17677c478bd9Sstevel@tonic-gate ++pfn;
17687c478bd9Sstevel@tonic-gate len -= MMU_PAGESIZE;
17697c478bd9Sstevel@tonic-gate va += MMU_PAGESIZE;
17707c478bd9Sstevel@tonic-gate }
17717c478bd9Sstevel@tonic-gate }
17727c478bd9Sstevel@tonic-gate PRM_DEBUG(boot_protect_cnt);
17737c478bd9Sstevel@tonic-gate }
17747c478bd9Sstevel@tonic-gate
1775ae115bc7Smrj /*
177604909c8cSJohn Levon * Establish the final size of the kernel's heap, size of segmap, segkp, etc.
1777ae115bc7Smrj */
17787c478bd9Sstevel@tonic-gate static void
layout_kernel_va(void)177935b1ab99Sjosephb layout_kernel_va(void)
17807c478bd9Sstevel@tonic-gate {
178104909c8cSJohn Levon const size_t physmem_size = mmu_ptob(physmem);
178204909c8cSJohn Levon size_t size;
17837c478bd9Sstevel@tonic-gate
178404909c8cSJohn Levon PRM_POINT("layout_kernel_va() starting...");
17857c478bd9Sstevel@tonic-gate
178635b1ab99Sjosephb kpm_vbase = (caddr_t)segkpm_base;
1787ae115bc7Smrj kpm_size = ROUND_UP_LPAGE(mmu_ptob(physmax + 1));
178835b1ab99Sjosephb if ((uintptr_t)kpm_vbase + kpm_size > (uintptr_t)valloc_base)
178935b1ab99Sjosephb panic("not enough room for kpm!");
1790ae115bc7Smrj PRM_DEBUG(kpm_size);
1791ae115bc7Smrj PRM_DEBUG(kpm_vbase);
1792ae115bc7Smrj
1793ae115bc7Smrj segkp_base = (caddr_t)valloc_base + valloc_sz;
17947c478bd9Sstevel@tonic-gate if (!segkp_fromheap) {
179504909c8cSJohn Levon size = mmu_ptob(segkpsize);
17967c478bd9Sstevel@tonic-gate /*
1797860b5cc8Scneira * Determine size of segkp
1798860b5cc8Scneira * Users can change segkpsize through eeprom.
17997c478bd9Sstevel@tonic-gate */
180004909c8cSJohn Levon if (size < SEGKPMINSIZE || size > SEGKPMAXSIZE) {
180104909c8cSJohn Levon size = SEGKPDEFSIZE;
18027c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!Illegal value for segkpsize. "
18037c478bd9Sstevel@tonic-gate "segkpsize has been reset to %ld pages",
180404909c8cSJohn Levon mmu_btop(size));
18057c478bd9Sstevel@tonic-gate }
180604909c8cSJohn Levon size = MIN(size, MAX(SEGKPMINSIZE, physmem_size));
180704909c8cSJohn Levon segkpsize = mmu_btop(ROUND_UP_LPAGE(size));
18087c478bd9Sstevel@tonic-gate }
1809ae115bc7Smrj PRM_DEBUG(segkp_base);
1810ae115bc7Smrj PRM_DEBUG(segkpsize);
18117c478bd9Sstevel@tonic-gate
181235b1ab99Sjosephb /*
181304909c8cSJohn Levon * segkvmm: backing for vmm guest memory. Like segzio, we have a
181404909c8cSJohn Levon * separate segment for two reasons: it makes it easy to skip our pages
181504909c8cSJohn Levon * on kernel crash dumps, and it helps avoid fragmentation. With this
181604909c8cSJohn Levon * segment, we're expecting significantly-sized allocations only; we'll
181704909c8cSJohn Levon * default to 4x the size of physmem.
181835b1ab99Sjosephb */
181904909c8cSJohn Levon segkvmm_base = segkp_base + mmu_ptob(segkpsize);
182004909c8cSJohn Levon size = segkvmmsize != 0 ? mmu_ptob(segkvmmsize) : (physmem_size * 4);
182104909c8cSJohn Levon
182204909c8cSJohn Levon size = MAX(size, SEGVMMMINSIZE);
182304909c8cSJohn Levon segkvmmsize = mmu_btop(ROUND_UP_LPAGE(size));
182404909c8cSJohn Levon
182504909c8cSJohn Levon PRM_DEBUG(segkvmmsize);
182604909c8cSJohn Levon PRM_DEBUG(segkvmm_base);
182704909c8cSJohn Levon
182804909c8cSJohn Levon /*
182904909c8cSJohn Levon * segzio is used for ZFS cached data. For segzio, we use 1.5x physmem.
183004909c8cSJohn Levon */
183104909c8cSJohn Levon segzio_base = segkvmm_base + mmu_ptob(segkvmmsize);
1832ae115bc7Smrj if (segzio_fromheap) {
1833ae115bc7Smrj segziosize = 0;
1834ae115bc7Smrj } else {
183504909c8cSJohn Levon size = (segziosize != 0) ? mmu_ptob(segziosize) :
183604909c8cSJohn Levon (physmem_size * 3) / 2;
1837ad23a2dbSjohansen
183804909c8cSJohn Levon size = MAX(size, SEGZIOMINSIZE);
1839ad23a2dbSjohansen segziosize = mmu_btop(ROUND_UP_LPAGE(size));
1840ae115bc7Smrj }
1841ad23a2dbSjohansen PRM_DEBUG(segziosize);
1842ad23a2dbSjohansen PRM_DEBUG(segzio_base);
1843ad23a2dbSjohansen
18447c478bd9Sstevel@tonic-gate /*
1845ae115bc7Smrj * Put the range of VA for device mappings next, kmdb knows to not
1846ae115bc7Smrj * grep in this range of addresses.
18477c478bd9Sstevel@tonic-gate */
1848ae115bc7Smrj toxic_addr =
1849ae115bc7Smrj ROUND_UP_LPAGE((uintptr_t)segzio_base + mmu_ptob(segziosize));
18507c478bd9Sstevel@tonic-gate PRM_DEBUG(toxic_addr);
1851ae115bc7Smrj segmap_start = ROUND_UP_LPAGE(toxic_addr + toxic_size);
18527c478bd9Sstevel@tonic-gate
18537c478bd9Sstevel@tonic-gate /*
185452eef812SAmrita Sadhukhan * Users can change segmapsize through eeprom. If the variable
185552eef812SAmrita Sadhukhan * is tuned through eeprom, there is no upper bound on the
185652eef812SAmrita Sadhukhan * size of segmap.
18577c478bd9Sstevel@tonic-gate */
18587c478bd9Sstevel@tonic-gate segmapsize = MAX(ROUND_UP_LPAGE(segmapsize), SEGMAPDEFAULT);
18597c478bd9Sstevel@tonic-gate
1860ae115bc7Smrj PRM_DEBUG(segmap_start);
18617c478bd9Sstevel@tonic-gate PRM_DEBUG(segmapsize);
186235b1ab99Sjosephb kernelheap = (caddr_t)ROUND_UP_LPAGE(segmap_start + segmapsize);
186335b1ab99Sjosephb PRM_DEBUG(kernelheap);
186435b1ab99Sjosephb PRM_POINT("layout_kernel_va() done...");
186535b1ab99Sjosephb }
186635b1ab99Sjosephb
186735b1ab99Sjosephb /*
186835b1ab99Sjosephb * Finish initializing the VM system, now that we are no longer
186935b1ab99Sjosephb * relying on the boot time memory allocators.
187035b1ab99Sjosephb */
187135b1ab99Sjosephb static void
startup_vm(void)187235b1ab99Sjosephb startup_vm(void)
187335b1ab99Sjosephb {
187435b1ab99Sjosephb struct segmap_crargs a;
187535b1ab99Sjosephb
187635b1ab99Sjosephb extern int use_brk_lpg, use_stk_lpg;
187735b1ab99Sjosephb
187835b1ab99Sjosephb PRM_POINT("startup_vm() starting...");
187935b1ab99Sjosephb
188035b1ab99Sjosephb /*
188135b1ab99Sjosephb * Initialize the hat layer.
188235b1ab99Sjosephb */
188335b1ab99Sjosephb hat_init();
18847c478bd9Sstevel@tonic-gate
18857c478bd9Sstevel@tonic-gate /*
1886ae115bc7Smrj * Do final allocations of HAT data structures that need to
1887ae115bc7Smrj * be allocated before quiescing the boot loader.
1888ae115bc7Smrj */
1889ae115bc7Smrj PRM_POINT("Calling hat_kern_alloc()...");
1890ae115bc7Smrj hat_kern_alloc((caddr_t)segmap_start, segmapsize, ekernelheap);
1891ae115bc7Smrj PRM_POINT("hat_kern_alloc() done");
1892ae115bc7Smrj
1893843e1988Sjohnlev #ifndef __xpv
1894ae115bc7Smrj /*
18951d03c31eSjohnlev * Setup Page Attribute Table
1896ae115bc7Smrj */
18971d03c31eSjohnlev pat_sync();
1898843e1988Sjohnlev #endif
1899ae115bc7Smrj
1900ae115bc7Smrj /*
1901ae115bc7Smrj * The next two loops are done in distinct steps in order
1902ae115bc7Smrj * to be sure that any page that is doubly mapped (both above
1903ae115bc7Smrj * KERNEL_TEXT and below kernelbase) is dealt with correctly.
1904ae115bc7Smrj * Note this may never happen, but it might someday.
1905ae115bc7Smrj */
1906ae115bc7Smrj bootpages = NULL;
1907ae115bc7Smrj PRM_POINT("Protecting boot pages");
1908ae115bc7Smrj
1909ae115bc7Smrj /*
1910ae115bc7Smrj * Protect any pages mapped above KERNEL_TEXT that somehow have
1911ae115bc7Smrj * page_t's. This can only happen if something weird allocated
1912ae115bc7Smrj * in this range (like kadb/kmdb).
1913ae115bc7Smrj */
1914ae115bc7Smrj protect_boot_range(KERNEL_TEXT, (uintptr_t)-1, 0);
1915ae115bc7Smrj
1916ae115bc7Smrj /*
1917ae115bc7Smrj * Before we can take over memory allocation/mapping from the boot
1918ae115bc7Smrj * loader we must remove from our free page lists any boot allocated
1919ae115bc7Smrj * pages that stay mapped until release_bootstrap().
1920ae115bc7Smrj */
1921ae115bc7Smrj protect_boot_range(0, kernelbase, 1);
1922ae115bc7Smrj
1923843e1988Sjohnlev
1924ae115bc7Smrj /*
1925ae115bc7Smrj * Switch to running on regular HAT (not boot_mmu)
1926ae115bc7Smrj */
1927ae115bc7Smrj PRM_POINT("Calling hat_kern_setup()...");
1928ae115bc7Smrj hat_kern_setup();
1929ae115bc7Smrj
1930ae115bc7Smrj /*
1931ae115bc7Smrj * It is no longer safe to call BOP_ALLOC(), so make sure we don't.
1932ae115bc7Smrj */
1933ae115bc7Smrj bop_no_more_mem();
1934ae115bc7Smrj
1935ae115bc7Smrj PRM_POINT("hat_kern_setup() done");
1936ae115bc7Smrj
1937ae115bc7Smrj hat_cpu_online(CPU);
1938ae115bc7Smrj
1939ae115bc7Smrj /*
19407c478bd9Sstevel@tonic-gate * Initialize VM system
19417c478bd9Sstevel@tonic-gate */
19427c478bd9Sstevel@tonic-gate PRM_POINT("Calling kvm_init()...");
19437c478bd9Sstevel@tonic-gate kvm_init();
19447c478bd9Sstevel@tonic-gate PRM_POINT("kvm_init() done");
19457c478bd9Sstevel@tonic-gate
19467c478bd9Sstevel@tonic-gate /*
19477c478bd9Sstevel@tonic-gate * Tell kmdb that the VM system is now working
19487c478bd9Sstevel@tonic-gate */
19497c478bd9Sstevel@tonic-gate if (boothowto & RB_DEBUG)
19507c478bd9Sstevel@tonic-gate kdi_dvec_vmready();
19517c478bd9Sstevel@tonic-gate
1952843e1988Sjohnlev #if defined(__xpv)
1953843e1988Sjohnlev /*
1954843e1988Sjohnlev * Populate the I/O pool on domain 0
1955843e1988Sjohnlev */
1956843e1988Sjohnlev if (DOMAIN_IS_INITDOMAIN(xen_info)) {
1957843e1988Sjohnlev extern long populate_io_pool(void);
1958843e1988Sjohnlev long init_io_pool_cnt;
1959843e1988Sjohnlev
1960843e1988Sjohnlev PRM_POINT("Populating reserve I/O page pool");
1961843e1988Sjohnlev init_io_pool_cnt = populate_io_pool();
1962843e1988Sjohnlev PRM_DEBUG(init_io_pool_cnt);
1963843e1988Sjohnlev }
1964843e1988Sjohnlev #endif
19657c478bd9Sstevel@tonic-gate /*
19667c478bd9Sstevel@tonic-gate * Mangle the brand string etc.
19677c478bd9Sstevel@tonic-gate */
1968ab5bb018SKeith M Wesolowski cpuid_execpass(CPU, CPUID_PASS_DYNAMIC, NULL);
19697c478bd9Sstevel@tonic-gate
19707c478bd9Sstevel@tonic-gate /*
19717c478bd9Sstevel@tonic-gate * Create the device arena for toxic (to dtrace/kmdb) mappings.
19727c478bd9Sstevel@tonic-gate */
19737c478bd9Sstevel@tonic-gate device_arena = vmem_create("device", (void *)toxic_addr,
19747c478bd9Sstevel@tonic-gate toxic_size, MMU_PAGESIZE, NULL, NULL, NULL, 0, VM_SLEEP);
19757c478bd9Sstevel@tonic-gate
19767c478bd9Sstevel@tonic-gate /*
19777c478bd9Sstevel@tonic-gate * Now that we've got more VA, as well as the ability to allocate from
19787c478bd9Sstevel@tonic-gate * it, tell the debugger.
19797c478bd9Sstevel@tonic-gate */
19807c478bd9Sstevel@tonic-gate if (boothowto & RB_DEBUG)
19817c478bd9Sstevel@tonic-gate kdi_dvec_memavail();
19827c478bd9Sstevel@tonic-gate
1983843e1988Sjohnlev #if !defined(__xpv)
19847c478bd9Sstevel@tonic-gate /*
19857c478bd9Sstevel@tonic-gate * Map page pfn=0 for drivers, such as kd, that need to pick up
19867c478bd9Sstevel@tonic-gate * parameters left there by controllers/BIOS.
19877c478bd9Sstevel@tonic-gate */
19887c478bd9Sstevel@tonic-gate PRM_POINT("setup up p0_va");
19897c478bd9Sstevel@tonic-gate p0_va = i86devmap(0, 1, PROT_READ);
19907c478bd9Sstevel@tonic-gate PRM_DEBUG(p0_va);
1991843e1988Sjohnlev #endif
19927c478bd9Sstevel@tonic-gate
19937c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?mem = %luK (0x%lx)\n",
19947c478bd9Sstevel@tonic-gate physinstalled << (MMU_PAGESHIFT - 10), ptob(physinstalled));
19957c478bd9Sstevel@tonic-gate
199683f9b804Skchow /*
199783f9b804Skchow * disable automatic large pages for small memory systems or
199883f9b804Skchow * when the disable flag is set.
199902bc52beSkchow *
200002bc52beSkchow * Do not yet consider page sizes larger than 2m/4m.
200183f9b804Skchow */
2002ec25b48fSsusans if (!auto_lpg_disable && mmu.max_page_level > 0) {
2003ec25b48fSsusans max_uheap_lpsize = LEVEL_SIZE(1);
2004ec25b48fSsusans max_ustack_lpsize = LEVEL_SIZE(1);
2005ec25b48fSsusans max_privmap_lpsize = LEVEL_SIZE(1);
2006ec25b48fSsusans max_uidata_lpsize = LEVEL_SIZE(1);
2007ec25b48fSsusans max_utext_lpsize = LEVEL_SIZE(1);
2008ec25b48fSsusans max_shm_lpsize = LEVEL_SIZE(1);
2009ec25b48fSsusans }
2010ec25b48fSsusans if (physmem < privm_lpg_min_physmem || mmu.max_page_level == 0 ||
2011ec25b48fSsusans auto_lpg_disable) {
2012beb1bda0Sdavemq use_brk_lpg = 0;
2013beb1bda0Sdavemq use_stk_lpg = 0;
2014ec25b48fSsusans }
201502bc52beSkchow mcntl0_lpsize = LEVEL_SIZE(mmu.umax_page_level);
2016beb1bda0Sdavemq
20177c478bd9Sstevel@tonic-gate PRM_POINT("Calling hat_init_finish()...");
20187c478bd9Sstevel@tonic-gate hat_init_finish();
20197c478bd9Sstevel@tonic-gate PRM_POINT("hat_init_finish() done");
20207c478bd9Sstevel@tonic-gate
20217c478bd9Sstevel@tonic-gate /*
20227c478bd9Sstevel@tonic-gate * Initialize the segkp segment type.
20237c478bd9Sstevel@tonic-gate */
20247c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER);
2025ae115bc7Smrj PRM_POINT("Attaching segkp");
2026ae115bc7Smrj if (segkp_fromheap) {
2027ae115bc7Smrj segkp->s_as = &kas;
2028ae115bc7Smrj } else if (seg_attach(&kas, (caddr_t)segkp_base, mmu_ptob(segkpsize),
20297c478bd9Sstevel@tonic-gate segkp) < 0) {
20307c478bd9Sstevel@tonic-gate panic("startup: cannot attach segkp");
20317c478bd9Sstevel@tonic-gate /*NOTREACHED*/
20327c478bd9Sstevel@tonic-gate }
2033ae115bc7Smrj PRM_POINT("Doing segkp_create()");
20347c478bd9Sstevel@tonic-gate if (segkp_create(segkp) != 0) {
20357c478bd9Sstevel@tonic-gate panic("startup: segkp_create failed");
20367c478bd9Sstevel@tonic-gate /*NOTREACHED*/
20377c478bd9Sstevel@tonic-gate }
20387c478bd9Sstevel@tonic-gate PRM_DEBUG(segkp);
20397c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock);
20407c478bd9Sstevel@tonic-gate
20417c478bd9Sstevel@tonic-gate /*
20427c478bd9Sstevel@tonic-gate * kpm segment
20437c478bd9Sstevel@tonic-gate */
20447c478bd9Sstevel@tonic-gate segmap_kpm = 0;
204574ecdb51SJohn Levon if (kpm_desired)
20467c478bd9Sstevel@tonic-gate kpm_init();
20477c478bd9Sstevel@tonic-gate
20487c478bd9Sstevel@tonic-gate /*
20497c478bd9Sstevel@tonic-gate * Now create segmap segment.
20507c478bd9Sstevel@tonic-gate */
20517c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER);
2052ae115bc7Smrj if (seg_attach(&kas, (caddr_t)segmap_start, segmapsize, segmap) < 0) {
2053ae115bc7Smrj panic("cannot attach segmap");
20547c478bd9Sstevel@tonic-gate /*NOTREACHED*/
20557c478bd9Sstevel@tonic-gate }
2056ae115bc7Smrj PRM_DEBUG(segmap);
20577c478bd9Sstevel@tonic-gate
20587c478bd9Sstevel@tonic-gate a.prot = PROT_READ | PROT_WRITE;
20597c478bd9Sstevel@tonic-gate a.shmsize = 0;
20607c478bd9Sstevel@tonic-gate a.nfreelist = segmapfreelists;
20617c478bd9Sstevel@tonic-gate
2062ae115bc7Smrj if (segmap_create(segmap, (caddr_t)&a) != 0)
2063ae115bc7Smrj panic("segmap_create segmap");
20647c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock);
20657c478bd9Sstevel@tonic-gate
20667c478bd9Sstevel@tonic-gate setup_vaddr_for_ppcopy(CPU);
20677c478bd9Sstevel@tonic-gate
20687c478bd9Sstevel@tonic-gate segdev_init();
2069843e1988Sjohnlev #if defined(__xpv)
2070843e1988Sjohnlev if (DOMAIN_IS_INITDOMAIN(xen_info))
2071843e1988Sjohnlev #endif
20727c478bd9Sstevel@tonic-gate pmem_init();
2073ae115bc7Smrj
20747c478bd9Sstevel@tonic-gate PRM_POINT("startup_vm() done");
20757c478bd9Sstevel@tonic-gate }
20767c478bd9Sstevel@tonic-gate
2077ae115bc7Smrj /*
2078ae115bc7Smrj * Load a tod module for the non-standard tod part found on this system.
2079ae115bc7Smrj */
2080ae115bc7Smrj static void
load_tod_module(char * todmod)2081ae115bc7Smrj load_tod_module(char *todmod)
2082ae115bc7Smrj {
2083ae115bc7Smrj if (modload("tod", todmod) == -1)
2084ae115bc7Smrj halt("Can't load TOD module");
2085ae115bc7Smrj }
2086ae115bc7Smrj
2087575694f6SJason King #ifndef __xpv
2088575694f6SJason King static void
startup_tsc(void)2089575694f6SJason King startup_tsc(void)
2090575694f6SJason King {
2091575694f6SJason King uint64_t tsc_freq;
2092575694f6SJason King
2093575694f6SJason King PRM_POINT("startup_tsc() starting...");
2094575694f6SJason King
2095575694f6SJason King tsc_freq = tsc_calibrate();
2096575694f6SJason King PRM_DEBUG(tsc_freq);
2097575694f6SJason King
2098575694f6SJason King tsc_hrtimeinit(tsc_freq);
2099575694f6SJason King }
2100575694f6SJason King #endif
2101575694f6SJason King
21027c478bd9Sstevel@tonic-gate static void
startup_end(void)21037c478bd9Sstevel@tonic-gate startup_end(void)
21047c478bd9Sstevel@tonic-gate {
2105dd4eeefdSeota int i;
21067c478bd9Sstevel@tonic-gate extern void setx86isalist(void);
2107fb2caebeSRandy Fishel extern void cpu_event_init(void);
21087c478bd9Sstevel@tonic-gate
21097c478bd9Sstevel@tonic-gate PRM_POINT("startup_end() starting...");
21107c478bd9Sstevel@tonic-gate
21117c478bd9Sstevel@tonic-gate /*
21127c478bd9Sstevel@tonic-gate * Perform tasks that get done after most of the VM
21137c478bd9Sstevel@tonic-gate * initialization has been done but before the clock
21147c478bd9Sstevel@tonic-gate * and other devices get started.
21157c478bd9Sstevel@tonic-gate */
21167c478bd9Sstevel@tonic-gate kern_setup1();
21177c478bd9Sstevel@tonic-gate
21187c478bd9Sstevel@tonic-gate /*
21197c478bd9Sstevel@tonic-gate * Perform CPC initialization for this CPU.
21207c478bd9Sstevel@tonic-gate */
21217c478bd9Sstevel@tonic-gate kcpc_hw_init(CPU);
21227c478bd9Sstevel@tonic-gate
2123fb2caebeSRandy Fishel /*
2124fb2caebeSRandy Fishel * Initialize cpu event framework.
2125fb2caebeSRandy Fishel */
2126fb2caebeSRandy Fishel cpu_event_init();
2127fb2caebeSRandy Fishel
2128ee6ee36aSPatrick Mooney #if defined(OPTERON_ERRATUM_147)
2129ee6ee36aSPatrick Mooney if (opteron_erratum_147)
2130ee6ee36aSPatrick Mooney patch_erratum_147();
2131ee88d2b9Skchow #endif
21327c478bd9Sstevel@tonic-gate /*
2133ae115bc7Smrj * If needed, load TOD module now so that ddi_get_time(9F) etc. work
2134ae115bc7Smrj * (For now, "needed" is defined as set tod_module_name in /etc/system)
2135ae115bc7Smrj */
2136ae115bc7Smrj if (tod_module_name != NULL) {
2137ae115bc7Smrj PRM_POINT("load_tod_module()");
2138ae115bc7Smrj load_tod_module(tod_module_name);
2139ae115bc7Smrj }
2140ae115bc7Smrj
2141843e1988Sjohnlev #if defined(__xpv)
2142843e1988Sjohnlev /*
2143843e1988Sjohnlev * Forceload interposing TOD module for the hypervisor.
2144843e1988Sjohnlev */
2145843e1988Sjohnlev PRM_POINT("load_tod_module()");
2146843e1988Sjohnlev load_tod_module("xpvtod");
2147843e1988Sjohnlev #endif
2148843e1988Sjohnlev
2149ae115bc7Smrj /*
21507c478bd9Sstevel@tonic-gate * Configure the system.
21517c478bd9Sstevel@tonic-gate */
21527c478bd9Sstevel@tonic-gate PRM_POINT("Calling configure()...");
21537c478bd9Sstevel@tonic-gate configure(); /* set up devices */
21547c478bd9Sstevel@tonic-gate PRM_POINT("configure() done");
21557c478bd9Sstevel@tonic-gate
21567c478bd9Sstevel@tonic-gate /*
2157*7c63221aSAndy Fiddaman * configure() will have called fpu_probe() so we can now finish off
2158*7c63221aSAndy Fiddaman * the last pieces.
2159*7c63221aSAndy Fiddaman */
2160*7c63221aSAndy Fiddaman
2161*7c63221aSAndy Fiddaman /*
2162*7c63221aSAndy Fiddaman * Set up the FPU save area for LWP0.
2163*7c63221aSAndy Fiddaman */
2164*7c63221aSAndy Fiddaman lwp_fp_init(&lwp0);
2165*7c63221aSAndy Fiddaman
2166*7c63221aSAndy Fiddaman /*
2167*7c63221aSAndy Fiddaman * Set up for XSAVE.
21687af88ac7SKuriakose Kuruvilla */
21697af88ac7SKuriakose Kuruvilla if (fp_save_mech == FP_XSAVE) {
2170fdcca78fSJoshua M. Clulow PRM_POINT("xsave_setup_msr()");
21717af88ac7SKuriakose Kuruvilla xsave_setup_msr(CPU);
21727af88ac7SKuriakose Kuruvilla }
21737af88ac7SKuriakose Kuruvilla
21747af88ac7SKuriakose Kuruvilla /*
21757c478bd9Sstevel@tonic-gate * Set the isa_list string to the defined instruction sets we
21767c478bd9Sstevel@tonic-gate * support.
21777c478bd9Sstevel@tonic-gate */
21787c478bd9Sstevel@tonic-gate setx86isalist();
2179fdcca78fSJoshua M. Clulow PRM_POINT("cpu_intr_alloc()");
2180100b72f4Sandrei cpu_intr_alloc(CPU, NINTR_THREADS);
2181fdcca78fSJoshua M. Clulow PRM_POINT("psm_install()");
21827c478bd9Sstevel@tonic-gate psm_install();
21837c478bd9Sstevel@tonic-gate
21847c478bd9Sstevel@tonic-gate /*
21857c478bd9Sstevel@tonic-gate * We're done with bootops. We don't unmap the bootstrap yet because
21867c478bd9Sstevel@tonic-gate * we're still using bootsvcs.
21877c478bd9Sstevel@tonic-gate */
2188ae115bc7Smrj PRM_POINT("NULLing out bootops");
2189ae115bc7Smrj *bootopsp = (struct bootops *)NULL;
21907c478bd9Sstevel@tonic-gate bootops = (struct bootops *)NULL;
21917c478bd9Sstevel@tonic-gate
2192843e1988Sjohnlev #if defined(__xpv)
2193843e1988Sjohnlev ec_init_debug_irq();
2194843e1988Sjohnlev xs_domu_init();
2195843e1988Sjohnlev #endif
21961de082f7SVikram Hegde
219774ecdb51SJohn Levon #if !defined(__xpv)
21983a634bfcSVikram Hegde /*
21993a634bfcSVikram Hegde * Intel IOMMU has been setup/initialized in ddi_impl.c
22003a634bfcSVikram Hegde * Start it up now.
22013a634bfcSVikram Hegde */
22023a634bfcSVikram Hegde immu_startup();
220374ecdb51SJohn Levon
220474ecdb51SJohn Levon /*
220574ecdb51SJohn Levon * Now that we're no longer going to drop into real mode for a BIOS call
220674ecdb51SJohn Levon * via bootops, we can enable PCID (which requires CR0.PG).
220774ecdb51SJohn Levon */
220874ecdb51SJohn Levon enable_pcid();
22091de082f7SVikram Hegde #endif
22103a634bfcSVikram Hegde
22117c478bd9Sstevel@tonic-gate PRM_POINT("Enabling interrupts");
22127c478bd9Sstevel@tonic-gate (*picinitf)();
22137c478bd9Sstevel@tonic-gate sti();
2214843e1988Sjohnlev #if defined(__xpv)
2215843e1988Sjohnlev ASSERT(CPU->cpu_m.mcpu_vcpu_info->evtchn_upcall_mask == 0);
2216843e1988Sjohnlev xen_late_startup();
2217843e1988Sjohnlev #endif
22187c478bd9Sstevel@tonic-gate
22197c478bd9Sstevel@tonic-gate (void) add_avsoftintr((void *)&softlevel1_hdl, 1, softlevel1,
22207c478bd9Sstevel@tonic-gate "softlevel1", NULL, NULL); /* XXX to be moved later */
22217c478bd9Sstevel@tonic-gate
2222dd4eeefdSeota /*
2223a288e5a9SJoshua M. Clulow * Register software interrupt handlers for ddi_periodic_add(9F).
2224dd4eeefdSeota * Software interrupts up to the level 10 are supported.
2225dd4eeefdSeota */
2226dd4eeefdSeota for (i = DDI_IPL_1; i <= DDI_IPL_10; i++) {
2227dd4eeefdSeota (void) add_avsoftintr((void *)&softlevel_hdl[i-1], i,
2228027bcc9fSToomas Soome (avfunc)(uintptr_t)ddi_periodic_softintr, "ddi_periodic",
2229a288e5a9SJoshua M. Clulow (caddr_t)(uintptr_t)i, NULL);
2230dd4eeefdSeota }
2231dd4eeefdSeota
22327125fcbdSVikram Hegde #if !defined(__xpv)
22337125fcbdSVikram Hegde if (modload("drv", "amd_iommu") < 0) {
22347125fcbdSVikram Hegde PRM_POINT("No AMD IOMMU present\n");
223594f1124eSVikram Hegde } else if (ddi_hold_installed_driver(ddi_name_to_major(
223694f1124eSVikram Hegde "amd_iommu")) == NULL) {
2237e39dbc52SGordon Ross PRM_POINT("AMD IOMMU failed to attach\n");
22387125fcbdSVikram Hegde }
22397125fcbdSVikram Hegde #endif
2240e774b42bSBill Holler post_startup_cpu_fixups();
22417125fcbdSVikram Hegde
22427c478bd9Sstevel@tonic-gate PRM_POINT("startup_end() done");
22437c478bd9Sstevel@tonic-gate }
22447c478bd9Sstevel@tonic-gate
224596d008c2SKen Erickson /*
224696d008c2SKen Erickson * Don't remove the following 2 variables. They are necessary
224796d008c2SKen Erickson * for reading the hostid from the legacy file (/kernel/misc/sysinit).
224896d008c2SKen Erickson */
22497c478bd9Sstevel@tonic-gate char *_hs1107 = hw_serial;
22507c478bd9Sstevel@tonic-gate ulong_t _bdhs34;
22517c478bd9Sstevel@tonic-gate
22527c478bd9Sstevel@tonic-gate void
post_startup(void)22537c478bd9Sstevel@tonic-gate post_startup(void)
22547c478bd9Sstevel@tonic-gate {
22550e751525SEric Saxe extern void cpupm_init(cpu_t *);
2256fb2caebeSRandy Fishel extern void cpu_event_init_cpu(cpu_t *);
22570e751525SEric Saxe
22587c478bd9Sstevel@tonic-gate /*
22597c478bd9Sstevel@tonic-gate * Set the system wide, processor-specific flags to be passed
22607c478bd9Sstevel@tonic-gate * to userland via the aux vector for performance hints and
22617c478bd9Sstevel@tonic-gate * instruction set extensions.
22627c478bd9Sstevel@tonic-gate */
22637c478bd9Sstevel@tonic-gate bind_hwcap();
22647c478bd9Sstevel@tonic-gate
2265843e1988Sjohnlev #ifdef __xpv
2266843e1988Sjohnlev if (DOMAIN_IS_INITDOMAIN(xen_info))
2267843e1988Sjohnlev #endif
2268843e1988Sjohnlev {
2269843e1988Sjohnlev #if defined(__xpv)
2270843e1988Sjohnlev xpv_panic_init();
2271843e1988Sjohnlev #else
227284ab085aSmws /*
2273ae115bc7Smrj * Startup the memory scrubber.
2274843e1988Sjohnlev * XXPV This should be running somewhere ..
22757c478bd9Sstevel@tonic-gate */
227679ec9da8SYuri Pankov if ((get_hwenv() & HW_VIRTUAL) == 0)
227784ab085aSmws memscrub_init();
2278843e1988Sjohnlev #endif
2279843e1988Sjohnlev }
22807c478bd9Sstevel@tonic-gate
22817c478bd9Sstevel@tonic-gate /*
22827aec1d6eScindi * Complete CPU module initialization
22837aec1d6eScindi */
228420c794b3Sgavinm cmi_post_startup();
22857aec1d6eScindi
22867aec1d6eScindi /*
22877c478bd9Sstevel@tonic-gate * Perform forceloading tasks for /etc/system.
22887c478bd9Sstevel@tonic-gate */
22897c478bd9Sstevel@tonic-gate (void) mod_sysctl(SYS_FORCELOAD, NULL);
22907c478bd9Sstevel@tonic-gate
22917c478bd9Sstevel@tonic-gate /*
22927c478bd9Sstevel@tonic-gate * ON4.0: Force /proc module in until clock interrupt handle fixed
22937c478bd9Sstevel@tonic-gate * ON4.0: This must be fixed or restated in /etc/systems.
22947c478bd9Sstevel@tonic-gate */
22957c478bd9Sstevel@tonic-gate (void) modload("fs", "procfs");
22967c478bd9Sstevel@tonic-gate
2297c35aa225Smarx (void) i_ddi_attach_hw_nodes("pit_beep");
2298c35aa225Smarx
22997c478bd9Sstevel@tonic-gate maxmem = freemem;
23007c478bd9Sstevel@tonic-gate
2301fb2caebeSRandy Fishel cpu_event_init_cpu(CPU);
23020e751525SEric Saxe cpupm_init(CPU);
2303fa96bd91SMichael Corcoran (void) mach_cpu_create_device_node(CPU, NULL);
23040e751525SEric Saxe
23050e751525SEric Saxe pg_init();
23067c478bd9Sstevel@tonic-gate }
23077c478bd9Sstevel@tonic-gate
23087c478bd9Sstevel@tonic-gate static int
pp_in_range(page_t * pp,uint64_t low_addr,uint64_t high_addr)230919397407SSherry Moore pp_in_range(page_t *pp, uint64_t low_addr, uint64_t high_addr)
23107c478bd9Sstevel@tonic-gate {
231119397407SSherry Moore return ((pp->p_pagenum >= btop(low_addr)) &&
231219397407SSherry Moore (pp->p_pagenum < btopr(high_addr)));
23137c478bd9Sstevel@tonic-gate }
23147c478bd9Sstevel@tonic-gate
23150181461bSKeith M Wesolowski static int
pp_in_module(page_t * pp,const rd_existing_t * modranges)23160181461bSKeith M Wesolowski pp_in_module(page_t *pp, const rd_existing_t *modranges)
23170181461bSKeith M Wesolowski {
23180181461bSKeith M Wesolowski uint_t i;
23190181461bSKeith M Wesolowski
23200181461bSKeith M Wesolowski for (i = 0; modranges[i].phys != 0; i++) {
23210181461bSKeith M Wesolowski if (pp_in_range(pp, modranges[i].phys,
23220181461bSKeith M Wesolowski modranges[i].phys + modranges[i].size))
23230181461bSKeith M Wesolowski return (1);
23240181461bSKeith M Wesolowski }
23250181461bSKeith M Wesolowski
23260181461bSKeith M Wesolowski return (0);
23270181461bSKeith M Wesolowski }
23280181461bSKeith M Wesolowski
23297c478bd9Sstevel@tonic-gate void
release_bootstrap(void)23307c478bd9Sstevel@tonic-gate release_bootstrap(void)
23317c478bd9Sstevel@tonic-gate {
23327c478bd9Sstevel@tonic-gate int root_is_ramdisk;
23337c478bd9Sstevel@tonic-gate page_t *pp;
23347c478bd9Sstevel@tonic-gate extern void kobj_boot_unmountroot(void);
23357c478bd9Sstevel@tonic-gate extern dev_t rootdev;
23360181461bSKeith M Wesolowski uint_t i;
23370181461bSKeith M Wesolowski char propname[32];
23380181461bSKeith M Wesolowski rd_existing_t *modranges;
233955d507a9SSeth Goldberg #if !defined(__xpv)
234055d507a9SSeth Goldberg pfn_t pfn;
234155d507a9SSeth Goldberg #endif
23427c478bd9Sstevel@tonic-gate
23430181461bSKeith M Wesolowski /*
23440181461bSKeith M Wesolowski * Save the bootfs module ranges so that we can reserve them below
23450181461bSKeith M Wesolowski * for the real bootfs.
23460181461bSKeith M Wesolowski */
23470181461bSKeith M Wesolowski modranges = kmem_alloc(sizeof (rd_existing_t) * MAX_BOOT_MODULES,
23480181461bSKeith M Wesolowski KM_SLEEP);
23490181461bSKeith M Wesolowski for (i = 0; ; i++) {
23500181461bSKeith M Wesolowski uint64_t start, size;
23510181461bSKeith M Wesolowski
23520181461bSKeith M Wesolowski modranges[i].phys = 0;
23530181461bSKeith M Wesolowski
23540181461bSKeith M Wesolowski (void) snprintf(propname, sizeof (propname),
23550181461bSKeith M Wesolowski "module-addr-%u", i);
23560181461bSKeith M Wesolowski if (do_bsys_getproplen(NULL, propname) <= 0)
23570181461bSKeith M Wesolowski break;
23580181461bSKeith M Wesolowski (void) do_bsys_getprop(NULL, propname, &start);
23590181461bSKeith M Wesolowski
23600181461bSKeith M Wesolowski (void) snprintf(propname, sizeof (propname),
23610181461bSKeith M Wesolowski "module-size-%u", i);
23620181461bSKeith M Wesolowski if (do_bsys_getproplen(NULL, propname) <= 0)
23630181461bSKeith M Wesolowski break;
23640181461bSKeith M Wesolowski (void) do_bsys_getprop(NULL, propname, &size);
23650181461bSKeith M Wesolowski
23660181461bSKeith M Wesolowski modranges[i].phys = start;
23670181461bSKeith M Wesolowski modranges[i].size = size;
23680181461bSKeith M Wesolowski }
23690181461bSKeith M Wesolowski
23707c478bd9Sstevel@tonic-gate /* unmount boot ramdisk and release kmem usage */
23717c478bd9Sstevel@tonic-gate kobj_boot_unmountroot();
23727c478bd9Sstevel@tonic-gate
23737c478bd9Sstevel@tonic-gate /*
23747c478bd9Sstevel@tonic-gate * We're finished using the boot loader so free its pages.
23757c478bd9Sstevel@tonic-gate */
23767c478bd9Sstevel@tonic-gate PRM_POINT("Unmapping lower boot pages");
237719397407SSherry Moore
2378ae115bc7Smrj clear_boot_mappings(0, _userlimit);
237919397407SSherry Moore
2380ae115bc7Smrj postbootkernelbase = kernelbase;
23817c478bd9Sstevel@tonic-gate
23827c478bd9Sstevel@tonic-gate /*
23837c478bd9Sstevel@tonic-gate * If root isn't on ramdisk, destroy the hardcoded
23847c478bd9Sstevel@tonic-gate * ramdisk node now and release the memory. Else,
23857c478bd9Sstevel@tonic-gate * ramdisk memory is kept in rd_pages.
23867c478bd9Sstevel@tonic-gate */
23877c478bd9Sstevel@tonic-gate root_is_ramdisk = (getmajor(rootdev) == ddi_name_to_major("ramdisk"));
23887c478bd9Sstevel@tonic-gate if (!root_is_ramdisk) {
23897c478bd9Sstevel@tonic-gate dev_info_t *dip = ddi_find_devinfo("ramdisk", -1, 0);
23907c478bd9Sstevel@tonic-gate ASSERT(dip && ddi_get_parent(dip) == ddi_root_node());
23917c478bd9Sstevel@tonic-gate ndi_rele_devi(dip); /* held from ddi_find_devinfo */
23927c478bd9Sstevel@tonic-gate (void) ddi_remove_child(dip, 0);
23937c478bd9Sstevel@tonic-gate }
23947c478bd9Sstevel@tonic-gate
23957c478bd9Sstevel@tonic-gate PRM_POINT("Releasing boot pages");
23967c478bd9Sstevel@tonic-gate while (bootpages) {
239719397407SSherry Moore extern uint64_t ramdisk_start, ramdisk_end;
23987c478bd9Sstevel@tonic-gate pp = bootpages;
23997c478bd9Sstevel@tonic-gate bootpages = pp->p_next;
240019397407SSherry Moore
240119397407SSherry Moore
240219397407SSherry Moore /* Keep pages for the lower 64K */
240319397407SSherry Moore if (pp_in_range(pp, 0, 0x40000)) {
240419397407SSherry Moore pp->p_next = lower_pages;
240519397407SSherry Moore lower_pages = pp;
240619397407SSherry Moore lower_pages_count++;
240719397407SSherry Moore continue;
240819397407SSherry Moore }
240919397407SSherry Moore
24103df2e8b2SRobert Mustacchi if ((root_is_ramdisk && pp_in_range(pp, ramdisk_start,
24113df2e8b2SRobert Mustacchi ramdisk_end)) || pp_in_module(pp, modranges)) {
24127c478bd9Sstevel@tonic-gate pp->p_next = rd_pages;
24137c478bd9Sstevel@tonic-gate rd_pages = pp;
24147c478bd9Sstevel@tonic-gate continue;
24157c478bd9Sstevel@tonic-gate }
24167c478bd9Sstevel@tonic-gate pp->p_next = (struct page *)0;
2417ae115bc7Smrj pp->p_prev = (struct page *)0;
2418ae115bc7Smrj PP_CLRBOOTPAGES(pp);
24197c478bd9Sstevel@tonic-gate page_free(pp, 1);
24207c478bd9Sstevel@tonic-gate }
2421ae115bc7Smrj PRM_POINT("Boot pages released");
24227c478bd9Sstevel@tonic-gate
24230181461bSKeith M Wesolowski kmem_free(modranges, sizeof (rd_existing_t) * 99);
24240181461bSKeith M Wesolowski
2425843e1988Sjohnlev #if !defined(__xpv)
2426843e1988Sjohnlev /* XXPV -- note this following bunch of code needs to be revisited in Xen 3.0 */
24277c478bd9Sstevel@tonic-gate /*
242855d507a9SSeth Goldberg * Find 1 page below 1 MB so that other processors can boot up or
242955d507a9SSeth Goldberg * so that any processor can resume.
24307c478bd9Sstevel@tonic-gate * Make sure it has a kernel VA as well as a 1:1 mapping.
24317c478bd9Sstevel@tonic-gate * We should have just free'd one up.
24327c478bd9Sstevel@tonic-gate */
243319397407SSherry Moore
243419397407SSherry Moore /*
243519397407SSherry Moore * 0x10 pages is 64K. Leave the bottom 64K alone
243619397407SSherry Moore * for BIOS.
243719397407SSherry Moore */
243819397407SSherry Moore for (pfn = 0x10; pfn < btop(1*1024*1024); pfn++) {
24397c478bd9Sstevel@tonic-gate if (page_numtopp_alloc(pfn) == NULL)
24407c478bd9Sstevel@tonic-gate continue;
24417c478bd9Sstevel@tonic-gate rm_platter_va = i86devmap(pfn, 1,
24427c478bd9Sstevel@tonic-gate PROT_READ | PROT_WRITE | PROT_EXEC);
24437c478bd9Sstevel@tonic-gate rm_platter_pa = ptob(pfn);
24447c478bd9Sstevel@tonic-gate break;
24457c478bd9Sstevel@tonic-gate }
244655d507a9SSeth Goldberg if (pfn == btop(1*1024*1024) && use_mp)
244755d507a9SSeth Goldberg panic("No page below 1M available for starting "
244855d507a9SSeth Goldberg "other processors or for resuming from system-suspend");
2449843e1988Sjohnlev #endif /* !__xpv */
24507c478bd9Sstevel@tonic-gate }
24517c478bd9Sstevel@tonic-gate
24527c478bd9Sstevel@tonic-gate /*
24537c478bd9Sstevel@tonic-gate * Initialize the platform-specific parts of a page_t.
24547c478bd9Sstevel@tonic-gate */
24557c478bd9Sstevel@tonic-gate void
add_physmem_cb(page_t * pp,pfn_t pnum)24567c478bd9Sstevel@tonic-gate add_physmem_cb(page_t *pp, pfn_t pnum)
24577c478bd9Sstevel@tonic-gate {
24587c478bd9Sstevel@tonic-gate pp->p_pagenum = pnum;
24597c478bd9Sstevel@tonic-gate pp->p_mapping = NULL;
24607c478bd9Sstevel@tonic-gate pp->p_embed = 0;
24617c478bd9Sstevel@tonic-gate pp->p_share = 0;
24627c478bd9Sstevel@tonic-gate pp->p_mlentry = 0;
24637c478bd9Sstevel@tonic-gate }
24647c478bd9Sstevel@tonic-gate
24657c478bd9Sstevel@tonic-gate /*
24667c478bd9Sstevel@tonic-gate * kphysm_init() initializes physical memory.
24677c478bd9Sstevel@tonic-gate */
24687c478bd9Sstevel@tonic-gate static pgcnt_t
kphysm_init(page_t * pp,pgcnt_t npages)2469584b574aSToomas Soome kphysm_init(page_t *pp, pgcnt_t npages)
24707c478bd9Sstevel@tonic-gate {
24717c478bd9Sstevel@tonic-gate struct memlist *pmem;
24727c478bd9Sstevel@tonic-gate struct memseg *cur_memseg;
24737c478bd9Sstevel@tonic-gate pfn_t base_pfn;
247418968004SKit Chow pfn_t end_pfn;
24757c478bd9Sstevel@tonic-gate pgcnt_t num;
24767c478bd9Sstevel@tonic-gate pgcnt_t pages_done = 0;
24777c478bd9Sstevel@tonic-gate uint64_t addr;
24787c478bd9Sstevel@tonic-gate uint64_t size;
24797c478bd9Sstevel@tonic-gate extern pfn_t ddiphysmin;
248018968004SKit Chow extern int mnode_xwa;
248118968004SKit Chow int ms = 0, me = 0;
24827c478bd9Sstevel@tonic-gate
24837c478bd9Sstevel@tonic-gate ASSERT(page_hash != NULL && page_hashsz != 0);
24847c478bd9Sstevel@tonic-gate
2485ae115bc7Smrj cur_memseg = memseg_base;
248656f33205SJonathan Adams for (pmem = phys_avail; pmem && npages; pmem = pmem->ml_next) {
24877c478bd9Sstevel@tonic-gate /*
24887c478bd9Sstevel@tonic-gate * In a 32 bit kernel can't use higher memory if we're
24897c478bd9Sstevel@tonic-gate * not booting in PAE mode. This check takes care of that.
24907c478bd9Sstevel@tonic-gate */
249156f33205SJonathan Adams addr = pmem->ml_address;
249256f33205SJonathan Adams size = pmem->ml_size;
24937c478bd9Sstevel@tonic-gate if (btop(addr) > physmax)
24947c478bd9Sstevel@tonic-gate continue;
24957c478bd9Sstevel@tonic-gate
24967c478bd9Sstevel@tonic-gate /*
24977c478bd9Sstevel@tonic-gate * align addr and size - they may not be at page boundaries
24987c478bd9Sstevel@tonic-gate */
24997c478bd9Sstevel@tonic-gate if ((addr & MMU_PAGEOFFSET) != 0) {
25007c478bd9Sstevel@tonic-gate addr += MMU_PAGEOFFSET;
25017c478bd9Sstevel@tonic-gate addr &= ~(uint64_t)MMU_PAGEOFFSET;
250256f33205SJonathan Adams size -= addr - pmem->ml_address;
25037c478bd9Sstevel@tonic-gate }
25047c478bd9Sstevel@tonic-gate
25056bb54764Skchow /* only process pages below or equal to physmax */
25066bb54764Skchow if ((btop(addr + size) - 1) > physmax)
25076bb54764Skchow size = ptob(physmax - btop(addr) + 1);
25087c478bd9Sstevel@tonic-gate
25097c478bd9Sstevel@tonic-gate num = btop(size);
25107c478bd9Sstevel@tonic-gate if (num == 0)
25117c478bd9Sstevel@tonic-gate continue;
25127c478bd9Sstevel@tonic-gate
25137c478bd9Sstevel@tonic-gate if (num > npages)
25147c478bd9Sstevel@tonic-gate num = npages;
25157c478bd9Sstevel@tonic-gate
25167c478bd9Sstevel@tonic-gate npages -= num;
25177c478bd9Sstevel@tonic-gate pages_done += num;
25187c478bd9Sstevel@tonic-gate base_pfn = btop(addr);
25197c478bd9Sstevel@tonic-gate
25207c478bd9Sstevel@tonic-gate if (prom_debug)
25217c478bd9Sstevel@tonic-gate prom_printf("MEMSEG addr=0x%" PRIx64
25227c478bd9Sstevel@tonic-gate " pgs=0x%lx pfn 0x%lx-0x%lx\n",
25237c478bd9Sstevel@tonic-gate addr, num, base_pfn, base_pfn + num);
25247c478bd9Sstevel@tonic-gate
25257c478bd9Sstevel@tonic-gate /*
2526ae115bc7Smrj * Ignore pages below ddiphysmin to simplify ddi memory
25277c478bd9Sstevel@tonic-gate * allocation with non-zero addr_lo requests.
25287c478bd9Sstevel@tonic-gate */
25297c478bd9Sstevel@tonic-gate if (base_pfn < ddiphysmin) {
2530ae115bc7Smrj if (base_pfn + num <= ddiphysmin)
25317c478bd9Sstevel@tonic-gate continue;
25327c478bd9Sstevel@tonic-gate pp += (ddiphysmin - base_pfn);
25337c478bd9Sstevel@tonic-gate num -= (ddiphysmin - base_pfn);
25347c478bd9Sstevel@tonic-gate base_pfn = ddiphysmin;
25357c478bd9Sstevel@tonic-gate }
2536ae115bc7Smrj
25377c478bd9Sstevel@tonic-gate /*
253818968004SKit Chow * mnode_xwa is greater than 1 when large pages regions can
253918968004SKit Chow * cross memory node boundaries. To prevent the formation
254018968004SKit Chow * of these large pages, configure the memsegs based on the
254118968004SKit Chow * memory node ranges which had been made non-contiguous.
254218968004SKit Chow */
254318968004SKit Chow end_pfn = base_pfn + num - 1;
2544584b574aSToomas Soome if (mnode_xwa > 1) {
254518968004SKit Chow ms = PFN_2_MEM_NODE(base_pfn);
254618968004SKit Chow me = PFN_2_MEM_NODE(end_pfn);
254718968004SKit Chow
254818968004SKit Chow if (ms != me) {
254918968004SKit Chow /*
255018968004SKit Chow * current range spans more than 1 memory node.
255118968004SKit Chow * Set num to only the pfn range in the start
255218968004SKit Chow * memory node.
255318968004SKit Chow */
255418968004SKit Chow num = mem_node_config[ms].physmax - base_pfn
255518968004SKit Chow + 1;
255618968004SKit Chow ASSERT(end_pfn > mem_node_config[ms].physmax);
255718968004SKit Chow }
255818968004SKit Chow }
255918968004SKit Chow
256018968004SKit Chow for (;;) {
256118968004SKit Chow /*
25627c478bd9Sstevel@tonic-gate * Build the memsegs entry
25637c478bd9Sstevel@tonic-gate */
25647c478bd9Sstevel@tonic-gate cur_memseg->pages = pp;
25657c478bd9Sstevel@tonic-gate cur_memseg->epages = pp + num;
25667c478bd9Sstevel@tonic-gate cur_memseg->pages_base = base_pfn;
25677c478bd9Sstevel@tonic-gate cur_memseg->pages_end = base_pfn + num;
25687c478bd9Sstevel@tonic-gate
25697c478bd9Sstevel@tonic-gate /*
257018968004SKit Chow * Insert into memseg list in decreasing pfn range
257118968004SKit Chow * order. Low memory is typically more fragmented such
257218968004SKit Chow * that this ordering keeps the larger ranges at the
257318968004SKit Chow * front of the list for code that searches memseg.
257418968004SKit Chow * This ASSERTS that the memsegs coming in from boot
257518968004SKit Chow * are in increasing physical address order and not
257618968004SKit Chow * contiguous.
25777c478bd9Sstevel@tonic-gate */
2578ae115bc7Smrj if (memsegs != NULL) {
257918968004SKit Chow ASSERT(cur_memseg->pages_base >=
258018968004SKit Chow memsegs->pages_end);
2581ae115bc7Smrj cur_memseg->next = memsegs;
2582ae115bc7Smrj }
25837c478bd9Sstevel@tonic-gate memsegs = cur_memseg;
25847c478bd9Sstevel@tonic-gate
25857c478bd9Sstevel@tonic-gate /*
25867c478bd9Sstevel@tonic-gate * add_physmem() initializes the PSM part of the page
25877c478bd9Sstevel@tonic-gate * struct by calling the PSM back with add_physmem_cb().
25887c478bd9Sstevel@tonic-gate * In addition it coalesces pages into larger pages as
25897c478bd9Sstevel@tonic-gate * it initializes them.
25907c478bd9Sstevel@tonic-gate */
25917c478bd9Sstevel@tonic-gate add_physmem(pp, num, base_pfn);
25927c478bd9Sstevel@tonic-gate cur_memseg++;
25937c478bd9Sstevel@tonic-gate availrmem_initial += num;
25947c478bd9Sstevel@tonic-gate availrmem += num;
25957c478bd9Sstevel@tonic-gate
2596ae115bc7Smrj pp += num;
259718968004SKit Chow if (ms >= me)
259818968004SKit Chow break;
259918968004SKit Chow
260018968004SKit Chow /* process next memory node range */
260118968004SKit Chow ms++;
260218968004SKit Chow base_pfn = mem_node_config[ms].physbase;
2603584b574aSToomas Soome
2604584b574aSToomas Soome if (mnode_xwa > 1) {
260518968004SKit Chow num = MIN(mem_node_config[ms].physmax,
260618968004SKit Chow end_pfn) - base_pfn + 1;
2607584b574aSToomas Soome } else {
2608584b574aSToomas Soome num = mem_node_config[ms].physmax -
2609584b574aSToomas Soome base_pfn + 1;
2610584b574aSToomas Soome }
261118968004SKit Chow }
26127c478bd9Sstevel@tonic-gate }
26137c478bd9Sstevel@tonic-gate
26147c478bd9Sstevel@tonic-gate PRM_DEBUG(availrmem_initial);
26157c478bd9Sstevel@tonic-gate PRM_DEBUG(availrmem);
26167c478bd9Sstevel@tonic-gate PRM_DEBUG(freemem);
26177c478bd9Sstevel@tonic-gate build_pfn_hash();
26187c478bd9Sstevel@tonic-gate return (pages_done);
26197c478bd9Sstevel@tonic-gate }
26207c478bd9Sstevel@tonic-gate
26217c478bd9Sstevel@tonic-gate /*
26227c478bd9Sstevel@tonic-gate * Kernel VM initialization.
26237c478bd9Sstevel@tonic-gate */
26247c478bd9Sstevel@tonic-gate static void
kvm_init(void)26257c478bd9Sstevel@tonic-gate kvm_init(void)
26267c478bd9Sstevel@tonic-gate {
26277c478bd9Sstevel@tonic-gate ASSERT((((uintptr_t)s_text) & MMU_PAGEOFFSET) == 0);
26287c478bd9Sstevel@tonic-gate
26297c478bd9Sstevel@tonic-gate /*
26307c478bd9Sstevel@tonic-gate * Put the kernel segments in kernel address space.
26317c478bd9Sstevel@tonic-gate */
26327c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER);
26337c478bd9Sstevel@tonic-gate as_avlinit(&kas);
26347c478bd9Sstevel@tonic-gate
26357c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, s_text, e_moddata - s_text, &ktextseg);
26367c478bd9Sstevel@tonic-gate (void) segkmem_create(&ktextseg);
26377c478bd9Sstevel@tonic-gate
26387c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, (caddr_t)valloc_base, valloc_sz, &kvalloc);
26397c478bd9Sstevel@tonic-gate (void) segkmem_create(&kvalloc);
26407c478bd9Sstevel@tonic-gate
264135b1ab99Sjosephb (void) seg_attach(&kas, kernelheap,
264235b1ab99Sjosephb ekernelheap - kernelheap, &kvseg);
26437c478bd9Sstevel@tonic-gate (void) segkmem_create(&kvseg);
26447c478bd9Sstevel@tonic-gate
2645ae115bc7Smrj if (core_size > 0) {
2646ae115bc7Smrj PRM_POINT("attaching kvseg_core");
2647ae115bc7Smrj (void) seg_attach(&kas, (caddr_t)core_base, core_size,
2648ae115bc7Smrj &kvseg_core);
26497c478bd9Sstevel@tonic-gate (void) segkmem_create(&kvseg_core);
2650ae115bc7Smrj }
2651ad23a2dbSjohansen
265204909c8cSJohn Levon PRM_POINT("attaching segkvmm");
265304909c8cSJohn Levon (void) seg_attach(&kas, segkvmm_base, mmu_ptob(segkvmmsize), &kvmmseg);
265404909c8cSJohn Levon (void) segkmem_create(&kvmmseg);
265504909c8cSJohn Levon segkmem_kvmm_init(segkvmm_base, mmu_ptob(segkvmmsize));
265604909c8cSJohn Levon
2657ae115bc7Smrj if (segziosize > 0) {
2658ae115bc7Smrj PRM_POINT("attaching segzio");
2659ad23a2dbSjohansen (void) seg_attach(&kas, segzio_base, mmu_ptob(segziosize),
2660ad23a2dbSjohansen &kzioseg);
266104909c8cSJohn Levon (void) segkmem_create(&kzioseg);
2662ad23a2dbSjohansen
2663ad23a2dbSjohansen /* create zio area covering new segment */
2664ad23a2dbSjohansen segkmem_zio_init(segzio_base, mmu_ptob(segziosize));
2665ad23a2dbSjohansen }
26667c478bd9Sstevel@tonic-gate
2667ae115bc7Smrj (void) seg_attach(&kas, kdi_segdebugbase, kdi_segdebugsize, &kdebugseg);
26687c478bd9Sstevel@tonic-gate (void) segkmem_create(&kdebugseg);
26697c478bd9Sstevel@tonic-gate
26707c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock);
26717c478bd9Sstevel@tonic-gate
26727c478bd9Sstevel@tonic-gate /*
26737c478bd9Sstevel@tonic-gate * Ensure that the red zone at kernelbase is never accessible.
26747c478bd9Sstevel@tonic-gate */
2675ae115bc7Smrj PRM_POINT("protecting redzone");
26767c478bd9Sstevel@tonic-gate (void) as_setprot(&kas, (caddr_t)kernelbase, KERNEL_REDZONE_SIZE, 0);
26777c478bd9Sstevel@tonic-gate
26787c478bd9Sstevel@tonic-gate /*
26797c478bd9Sstevel@tonic-gate * Make the text writable so that it can be hot patched by DTrace.
26807c478bd9Sstevel@tonic-gate */
26817c478bd9Sstevel@tonic-gate (void) as_setprot(&kas, s_text, e_modtext - s_text,
26827c478bd9Sstevel@tonic-gate PROT_READ | PROT_WRITE | PROT_EXEC);
26837c478bd9Sstevel@tonic-gate
26847c478bd9Sstevel@tonic-gate /*
26857c478bd9Sstevel@tonic-gate * Make data writable until end.
26867c478bd9Sstevel@tonic-gate */
26877c478bd9Sstevel@tonic-gate (void) as_setprot(&kas, s_data, e_moddata - s_data,
26887c478bd9Sstevel@tonic-gate PROT_READ | PROT_WRITE | PROT_EXEC);
26897c478bd9Sstevel@tonic-gate }
26907c478bd9Sstevel@tonic-gate
2691843e1988Sjohnlev #ifndef __xpv
26927c478bd9Sstevel@tonic-gate /*
26931d03c31eSjohnlev * Solaris adds an entry for Write Combining caching to the PAT
26947c478bd9Sstevel@tonic-gate */
26951d03c31eSjohnlev static uint64_t pat_attr_reg = PAT_DEFAULT_ATTRIBUTE;
26967c478bd9Sstevel@tonic-gate
26977c478bd9Sstevel@tonic-gate void
pat_sync(void)26981d03c31eSjohnlev pat_sync(void)
26997c478bd9Sstevel@tonic-gate {
27001d03c31eSjohnlev ulong_t cr0, cr0_orig, cr4;
27017c478bd9Sstevel@tonic-gate
27027417cfdeSKuriakose Kuruvilla if (!is_x86_feature(x86_featureset, X86FSET_PAT))
27037c478bd9Sstevel@tonic-gate return;
27041d03c31eSjohnlev cr0_orig = cr0 = getcr0();
27051d03c31eSjohnlev cr4 = getcr4();
27067c478bd9Sstevel@tonic-gate
27071d03c31eSjohnlev /* disable caching and flush all caches and TLBs */
27081d03c31eSjohnlev cr0 |= CR0_CD;
27091d03c31eSjohnlev cr0 &= ~CR0_NW;
27101d03c31eSjohnlev setcr0(cr0);
27117c478bd9Sstevel@tonic-gate invalidate_cache();
27121d03c31eSjohnlev if (cr4 & CR4_PGE) {
27131d03c31eSjohnlev setcr4(cr4 & ~(ulong_t)CR4_PGE);
27141d03c31eSjohnlev setcr4(cr4);
27151d03c31eSjohnlev } else {
2716ae115bc7Smrj reload_cr3();
27177c478bd9Sstevel@tonic-gate }
2718ae115bc7Smrj
27191d03c31eSjohnlev /* add our entry to the PAT */
27201d03c31eSjohnlev wrmsr(REG_PAT, pat_attr_reg);
27211d03c31eSjohnlev
27221d03c31eSjohnlev /* flush TLBs and cache again, then reenable cr0 caching */
27231d03c31eSjohnlev if (cr4 & CR4_PGE) {
27241d03c31eSjohnlev setcr4(cr4 & ~(ulong_t)CR4_PGE);
27251d03c31eSjohnlev setcr4(cr4);
27261d03c31eSjohnlev } else {
2727ae115bc7Smrj reload_cr3();
27281d03c31eSjohnlev }
27297c478bd9Sstevel@tonic-gate invalidate_cache();
27307c478bd9Sstevel@tonic-gate setcr0(cr0_orig);
27317c478bd9Sstevel@tonic-gate }
27327c478bd9Sstevel@tonic-gate
27331d03c31eSjohnlev #endif /* !__xpv */
27347c478bd9Sstevel@tonic-gate
2735ed5289f9SKen Erickson #if defined(_SOFT_HOSTID)
2736ed5289f9SKen Erickson /*
2737ed5289f9SKen Erickson * On platforms that do not have a hardware serial number, attempt
2738ed5289f9SKen Erickson * to set one based on the contents of /etc/hostid. If this file does
2739ed5289f9SKen Erickson * not exist, assume that we are to generate a new hostid and set
2740ed5289f9SKen Erickson * it in the kernel, for subsequent saving by a userland process
2741ed5289f9SKen Erickson * once the system is up and the root filesystem is mounted r/w.
2742ed5289f9SKen Erickson *
274396d008c2SKen Erickson * In order to gracefully support upgrade on OpenSolaris, if
274496d008c2SKen Erickson * /etc/hostid does not exist, we will attempt to get a serial number
274596d008c2SKen Erickson * using the legacy method (/kernel/misc/sysinit).
274696d008c2SKen Erickson *
27479e3e4df2SGarrett D'Amore * If that isn't present, we attempt to use an SMBIOS UUID, which is
27489e3e4df2SGarrett D'Amore * a hardware serial number. Note that we don't automatically trust
27499e3e4df2SGarrett D'Amore * all SMBIOS UUIDs (some older platforms are defective and ship duplicate
27509e3e4df2SGarrett D'Amore * UUIDs in violation of the standard), we check against a blacklist.
27519e3e4df2SGarrett D'Amore *
2752ed5289f9SKen Erickson * In an attempt to make the hostid less prone to abuse
2753ed5289f9SKen Erickson * (for license circumvention, etc), we store it in /etc/hostid
2754ed5289f9SKen Erickson * in rot47 format.
2755ed5289f9SKen Erickson */
275696d008c2SKen Erickson static int atoi(char *);
2757ed5289f9SKen Erickson
27589e3e4df2SGarrett D'Amore /*
27599e3e4df2SGarrett D'Amore * Set this to non-zero in /etc/system if you think your SMBIOS returns a
27609e3e4df2SGarrett D'Amore * UUID that is not unique. (Also report it so that the smbios_uuid_blacklist
27619e3e4df2SGarrett D'Amore * array can be updated.)
27629e3e4df2SGarrett D'Amore */
27639e3e4df2SGarrett D'Amore int smbios_broken_uuid = 0;
27649e3e4df2SGarrett D'Amore
27659e3e4df2SGarrett D'Amore /*
27669e3e4df2SGarrett D'Amore * List of known bad UUIDs. This is just the lower 32-bit values, since
27679e3e4df2SGarrett D'Amore * that's what we use for the host id. If your hostid falls here, you need
27689e3e4df2SGarrett D'Amore * to contact your hardware OEM for a fix for your BIOS.
27699e3e4df2SGarrett D'Amore */
27709e3e4df2SGarrett D'Amore static unsigned char
27719e3e4df2SGarrett D'Amore smbios_uuid_blacklist[][16] = {
27729e3e4df2SGarrett D'Amore
27739e3e4df2SGarrett D'Amore { /* Reported bad UUID (Google search) */
27749e3e4df2SGarrett D'Amore 0x00, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x05,
27759e3e4df2SGarrett D'Amore 0x00, 0x06, 0x00, 0x07, 0x00, 0x08, 0x00, 0x09,
27769e3e4df2SGarrett D'Amore },
27779e3e4df2SGarrett D'Amore { /* Known bad DELL UUID */
27789e3e4df2SGarrett D'Amore 0x4C, 0x4C, 0x45, 0x44, 0x00, 0x00, 0x20, 0x10,
27799e3e4df2SGarrett D'Amore 0x80, 0x20, 0x80, 0xC0, 0x4F, 0x20, 0x20, 0x20,
27809e3e4df2SGarrett D'Amore },
27819e3e4df2SGarrett D'Amore { /* Uninitialized flash */
27829e3e4df2SGarrett D'Amore 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
27839e3e4df2SGarrett D'Amore 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
27849e3e4df2SGarrett D'Amore },
27859e3e4df2SGarrett D'Amore { /* All zeros */
27869e3e4df2SGarrett D'Amore 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
27879e3e4df2SGarrett D'Amore 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
27889e3e4df2SGarrett D'Amore },
27899e3e4df2SGarrett D'Amore };
27909e3e4df2SGarrett D'Amore
27919e3e4df2SGarrett D'Amore static int32_t
uuid_to_hostid(const uint8_t * uuid)27929e3e4df2SGarrett D'Amore uuid_to_hostid(const uint8_t *uuid)
27939e3e4df2SGarrett D'Amore {
27949e3e4df2SGarrett D'Amore /*
27959e3e4df2SGarrett D'Amore * Although the UUIDs are 128-bits, they may not distribute entropy
27969e3e4df2SGarrett D'Amore * evenly. We would like to use SHA or MD5, but those are located
27979e3e4df2SGarrett D'Amore * in loadable modules and not available this early in boot. As we
27989e3e4df2SGarrett D'Amore * don't need the values to be cryptographically strong, we just
27999e3e4df2SGarrett D'Amore * generate 32-bit vaue by xor'ing the various sequences together,
28002df37efaSGarrett D'Amore * which ensures that the entire UUID contributes to the hostid.
28019e3e4df2SGarrett D'Amore */
28022df37efaSGarrett D'Amore uint32_t id = 0;
28039e3e4df2SGarrett D'Amore
28049e3e4df2SGarrett D'Amore /* first check against the blacklist */
28059e3e4df2SGarrett D'Amore for (int i = 0; i < (sizeof (smbios_uuid_blacklist) / 16); i++) {
28069e3e4df2SGarrett D'Amore if (bcmp(smbios_uuid_blacklist[0], uuid, 16) == 0) {
28079e3e4df2SGarrett D'Amore cmn_err(CE_CONT, "?Broken SMBIOS UUID. "
28089e3e4df2SGarrett D'Amore "Contact BIOS manufacturer for repair.\n");
28099e3e4df2SGarrett D'Amore return ((int32_t)HW_INVALID_HOSTID);
28109e3e4df2SGarrett D'Amore }
28119e3e4df2SGarrett D'Amore }
28129e3e4df2SGarrett D'Amore
28139e3e4df2SGarrett D'Amore for (int i = 0; i < 16; i++)
28149e3e4df2SGarrett D'Amore id ^= ((uuid[i]) << (8 * (i % sizeof (id))));
28159e3e4df2SGarrett D'Amore
28162df37efaSGarrett D'Amore /* Make sure return value is positive */
28172df37efaSGarrett D'Amore return (id & 0x7fffffff);
28189e3e4df2SGarrett D'Amore }
28199e3e4df2SGarrett D'Amore
2820ed5289f9SKen Erickson static int32_t
set_soft_hostid(void)2821ed5289f9SKen Erickson set_soft_hostid(void)
2822ed5289f9SKen Erickson {
2823ed5289f9SKen Erickson struct _buf *file;
2824ed5289f9SKen Erickson char tokbuf[MAXNAMELEN];
2825ed5289f9SKen Erickson token_t token;
2826ed5289f9SKen Erickson int done = 0;
2827ed5289f9SKen Erickson u_longlong_t tmp;
282896d008c2SKen Erickson int i;
28295679c89fSjv227347 int32_t hostid = (int32_t)HW_INVALID_HOSTID;
2830ed5289f9SKen Erickson unsigned char *c;
28319e3e4df2SGarrett D'Amore smbios_system_t smsys;
2832ed5289f9SKen Erickson
2833ed5289f9SKen Erickson /*
2834ed5289f9SKen Erickson * If /etc/hostid file not found, we'd like to get a pseudo
2835ed5289f9SKen Erickson * random number to use at the hostid. A nice way to do this
2836ed5289f9SKen Erickson * is to read the real time clock. To remain xen-compatible,
2837ed5289f9SKen Erickson * we can't poke the real hardware, so we use tsc_read() to
2838575694f6SJason King * read the real time clock.
2839ed5289f9SKen Erickson */
2840ed5289f9SKen Erickson
2841ed5289f9SKen Erickson if ((file = kobj_open_file(hostid_file)) == (struct _buf *)-1) {
284296d008c2SKen Erickson /*
284396d008c2SKen Erickson * hostid file not found - try to load sysinit module
284496d008c2SKen Erickson * and see if it has a nonzero hostid value...use that
284596d008c2SKen Erickson * instead of generating a new hostid here if so.
284696d008c2SKen Erickson */
284796d008c2SKen Erickson if ((i = modload("misc", "sysinit")) != -1) {
284896d008c2SKen Erickson if (strlen(hw_serial) > 0)
284996d008c2SKen Erickson hostid = (int32_t)atoi(hw_serial);
285096d008c2SKen Erickson (void) modunload(i);
285196d008c2SKen Erickson }
28529e3e4df2SGarrett D'Amore
28539e3e4df2SGarrett D'Amore /*
28549e3e4df2SGarrett D'Amore * We try to use the SMBIOS UUID. But not if it is blacklisted
28559e3e4df2SGarrett D'Amore * in /etc/system.
28569e3e4df2SGarrett D'Amore */
28579e3e4df2SGarrett D'Amore if ((hostid == HW_INVALID_HOSTID) &&
28589e3e4df2SGarrett D'Amore (smbios_broken_uuid == 0) &&
28599e3e4df2SGarrett D'Amore (ksmbios != NULL) &&
28609e3e4df2SGarrett D'Amore (smbios_info_system(ksmbios, &smsys) != SMB_ERR) &&
28619e3e4df2SGarrett D'Amore (smsys.smbs_uuidlen >= 16)) {
28629e3e4df2SGarrett D'Amore hostid = uuid_to_hostid(smsys.smbs_uuid);
28639e3e4df2SGarrett D'Amore }
28649e3e4df2SGarrett D'Amore
28659e3e4df2SGarrett D'Amore /*
28669e3e4df2SGarrett D'Amore * Generate a "random" hostid using the clock. These
28679e3e4df2SGarrett D'Amore * hostids will change on each boot if the value is not
28689e3e4df2SGarrett D'Amore * saved to a persistent /etc/hostid file.
28699e3e4df2SGarrett D'Amore */
28705679c89fSjv227347 if (hostid == HW_INVALID_HOSTID) {
2871575694f6SJason King hostid = tsc_read() & 0x0CFFFFF;
287296d008c2SKen Erickson }
2873ed5289f9SKen Erickson } else {
2874ed5289f9SKen Erickson /* hostid file found */
2875ed5289f9SKen Erickson while (!done) {
2876ed5289f9SKen Erickson token = kobj_lex(file, tokbuf, sizeof (tokbuf));
2877ed5289f9SKen Erickson
2878ed5289f9SKen Erickson switch (token) {
2879ed5289f9SKen Erickson case POUND:
2880ed5289f9SKen Erickson /*
2881ed5289f9SKen Erickson * skip comments
2882ed5289f9SKen Erickson */
2883ed5289f9SKen Erickson kobj_find_eol(file);
2884ed5289f9SKen Erickson break;
2885ed5289f9SKen Erickson case STRING:
2886ed5289f9SKen Erickson /*
2887ed5289f9SKen Erickson * un-rot47 - obviously this
2888ed5289f9SKen Erickson * nonsense is ascii-specific
2889ed5289f9SKen Erickson */
2890ed5289f9SKen Erickson for (c = (unsigned char *)tokbuf;
2891ed5289f9SKen Erickson *c != '\0'; c++) {
2892ed5289f9SKen Erickson *c += 47;
2893ed5289f9SKen Erickson if (*c > '~')
2894ed5289f9SKen Erickson *c -= 94;
2895ed5289f9SKen Erickson else if (*c < '!')
2896ed5289f9SKen Erickson *c += 94;
2897ed5289f9SKen Erickson }
2898ed5289f9SKen Erickson /*
2899ed5289f9SKen Erickson * now we should have a real number
2900ed5289f9SKen Erickson */
2901ed5289f9SKen Erickson
2902ed5289f9SKen Erickson if (kobj_getvalue(tokbuf, &tmp) != 0)
2903ed5289f9SKen Erickson kobj_file_err(CE_WARN, file,
2904ed5289f9SKen Erickson "Bad value %s for hostid",
2905ed5289f9SKen Erickson tokbuf);
2906ed5289f9SKen Erickson else
2907ed5289f9SKen Erickson hostid = (int32_t)tmp;
2908ed5289f9SKen Erickson
2909ed5289f9SKen Erickson break;
2910ed5289f9SKen Erickson case EOF:
2911ed5289f9SKen Erickson done = 1;
2912ed5289f9SKen Erickson /* FALLTHROUGH */
2913ed5289f9SKen Erickson case NEWLINE:
2914ed5289f9SKen Erickson kobj_newline(file);
2915ed5289f9SKen Erickson break;
2916ed5289f9SKen Erickson default:
2917ed5289f9SKen Erickson break;
2918ed5289f9SKen Erickson
2919ed5289f9SKen Erickson }
2920ed5289f9SKen Erickson }
29215679c89fSjv227347 if (hostid == HW_INVALID_HOSTID) /* didn't find a hostid */
2922ed5289f9SKen Erickson kobj_file_err(CE_WARN, file,
2923ed5289f9SKen Erickson "hostid missing or corrupt");
2924ed5289f9SKen Erickson
2925ed5289f9SKen Erickson kobj_close_file(file);
2926ed5289f9SKen Erickson }
2927ed5289f9SKen Erickson /*
2928ed5289f9SKen Erickson * hostid is now the value read from /etc/hostid, or the
29295679c89fSjv227347 * new hostid we generated in this routine or HW_INVALID_HOSTID if not
29305679c89fSjv227347 * set.
2931ed5289f9SKen Erickson */
2932ed5289f9SKen Erickson return (hostid);
2933ed5289f9SKen Erickson }
293496d008c2SKen Erickson
293596d008c2SKen Erickson static int
atoi(char * p)293696d008c2SKen Erickson atoi(char *p)
293796d008c2SKen Erickson {
293896d008c2SKen Erickson int i = 0;
293996d008c2SKen Erickson
294096d008c2SKen Erickson while (*p != '\0')
294196d008c2SKen Erickson i = 10 * i + (*p++ - '0');
294296d008c2SKen Erickson
294396d008c2SKen Erickson return (i);
294496d008c2SKen Erickson }
294596d008c2SKen Erickson
2946ed5289f9SKen Erickson #endif /* _SOFT_HOSTID */
2947ed5289f9SKen Erickson
29487c478bd9Sstevel@tonic-gate void
get_system_configuration(void)294945916cd2Sjpk get_system_configuration(void)
29507c478bd9Sstevel@tonic-gate {
29517c478bd9Sstevel@tonic-gate char prop[32];
29527c478bd9Sstevel@tonic-gate u_longlong_t nodes_ll, cpus_pernode_ll, lvalue;
29537c478bd9Sstevel@tonic-gate
295435b1ab99Sjosephb if (BOP_GETPROPLEN(bootops, "nodes") > sizeof (prop) ||
295535b1ab99Sjosephb BOP_GETPROP(bootops, "nodes", prop) < 0 ||
295635b1ab99Sjosephb kobj_getvalue(prop, &nodes_ll) == -1 ||
295735b1ab99Sjosephb nodes_ll > MAXNODES ||
295835b1ab99Sjosephb BOP_GETPROPLEN(bootops, "cpus_pernode") > sizeof (prop) ||
295935b1ab99Sjosephb BOP_GETPROP(bootops, "cpus_pernode", prop) < 0 ||
296035b1ab99Sjosephb kobj_getvalue(prop, &cpus_pernode_ll) == -1) {
29617c478bd9Sstevel@tonic-gate system_hardware.hd_nodes = 1;
29627c478bd9Sstevel@tonic-gate system_hardware.hd_cpus_per_node = 0;
29637c478bd9Sstevel@tonic-gate } else {
29647c478bd9Sstevel@tonic-gate system_hardware.hd_nodes = (int)nodes_ll;
29657c478bd9Sstevel@tonic-gate system_hardware.hd_cpus_per_node = (int)cpus_pernode_ll;
29667c478bd9Sstevel@tonic-gate }
296735b1ab99Sjosephb
296835b1ab99Sjosephb if (BOP_GETPROPLEN(bootops, "kernelbase") > sizeof (prop) ||
296935b1ab99Sjosephb BOP_GETPROP(bootops, "kernelbase", prop) < 0 ||
297035b1ab99Sjosephb kobj_getvalue(prop, &lvalue) == -1)
29714da99751SToomas Soome eprom_kernelbase = 0;
29727c478bd9Sstevel@tonic-gate else
29737c478bd9Sstevel@tonic-gate eprom_kernelbase = (uintptr_t)lvalue;
29747c478bd9Sstevel@tonic-gate
297535b1ab99Sjosephb if (BOP_GETPROPLEN(bootops, "segmapsize") > sizeof (prop) ||
297635b1ab99Sjosephb BOP_GETPROP(bootops, "segmapsize", prop) < 0 ||
297735b1ab99Sjosephb kobj_getvalue(prop, &lvalue) == -1)
29787c478bd9Sstevel@tonic-gate segmapsize = SEGMAPDEFAULT;
297935b1ab99Sjosephb else
29807c478bd9Sstevel@tonic-gate segmapsize = (uintptr_t)lvalue;
29817c478bd9Sstevel@tonic-gate
298235b1ab99Sjosephb if (BOP_GETPROPLEN(bootops, "segmapfreelists") > sizeof (prop) ||
298335b1ab99Sjosephb BOP_GETPROP(bootops, "segmapfreelists", prop) < 0 ||
298435b1ab99Sjosephb kobj_getvalue(prop, &lvalue) == -1)
29857c478bd9Sstevel@tonic-gate segmapfreelists = 0; /* use segmap driver default */
298635b1ab99Sjosephb else
29877c478bd9Sstevel@tonic-gate segmapfreelists = (int)lvalue;
29884944b02eSkchow
2989860b5cc8Scneira if (BOP_GETPROPLEN(bootops, "segkpsize") > sizeof (prop) ||
2990860b5cc8Scneira BOP_GETPROP(bootops, "segkpsize", prop) < 0 ||
2991860b5cc8Scneira kobj_getvalue(prop, &lvalue) == -1)
2992860b5cc8Scneira segkpsize = mmu_btop(SEGKPDEFSIZE);
2993860b5cc8Scneira else
2994860b5cc8Scneira segkpsize = mmu_btop((size_t)lvalue);
2995860b5cc8Scneira
2996aac11643Sjosephb /* physmem used to be here, but moved much earlier to fakebop.c */
29977c478bd9Sstevel@tonic-gate }
29987c478bd9Sstevel@tonic-gate
29997c478bd9Sstevel@tonic-gate /*
30007c478bd9Sstevel@tonic-gate * Add to a memory list.
30017c478bd9Sstevel@tonic-gate * start = start of new memory segment
30027c478bd9Sstevel@tonic-gate * len = length of new memory segment in bytes
30037c478bd9Sstevel@tonic-gate * new = pointer to a new struct memlist
30047c478bd9Sstevel@tonic-gate * memlistp = memory list to which to add segment.
30057c478bd9Sstevel@tonic-gate */
3006ae115bc7Smrj void
memlist_add(uint64_t start,uint64_t len,struct memlist * new,struct memlist ** memlistp)30077c478bd9Sstevel@tonic-gate memlist_add(
30087c478bd9Sstevel@tonic-gate uint64_t start,
30097c478bd9Sstevel@tonic-gate uint64_t len,
30107c478bd9Sstevel@tonic-gate struct memlist *new,
30117c478bd9Sstevel@tonic-gate struct memlist **memlistp)
30127c478bd9Sstevel@tonic-gate {
30137c478bd9Sstevel@tonic-gate struct memlist *cur;
30147c478bd9Sstevel@tonic-gate uint64_t end = start + len;
30157c478bd9Sstevel@tonic-gate
301656f33205SJonathan Adams new->ml_address = start;
301756f33205SJonathan Adams new->ml_size = len;
30187c478bd9Sstevel@tonic-gate
30197c478bd9Sstevel@tonic-gate cur = *memlistp;
30207c478bd9Sstevel@tonic-gate
30217c478bd9Sstevel@tonic-gate while (cur) {
302256f33205SJonathan Adams if (cur->ml_address >= end) {
302356f33205SJonathan Adams new->ml_next = cur;
30247c478bd9Sstevel@tonic-gate *memlistp = new;
302556f33205SJonathan Adams new->ml_prev = cur->ml_prev;
302656f33205SJonathan Adams cur->ml_prev = new;
30277c478bd9Sstevel@tonic-gate return;
30287c478bd9Sstevel@tonic-gate }
302956f33205SJonathan Adams ASSERT(cur->ml_address + cur->ml_size <= start);
303056f33205SJonathan Adams if (cur->ml_next == NULL) {
303156f33205SJonathan Adams cur->ml_next = new;
303256f33205SJonathan Adams new->ml_prev = cur;
303356f33205SJonathan Adams new->ml_next = NULL;
30347c478bd9Sstevel@tonic-gate return;
30357c478bd9Sstevel@tonic-gate }
303656f33205SJonathan Adams memlistp = &cur->ml_next;
303756f33205SJonathan Adams cur = cur->ml_next;
30387c478bd9Sstevel@tonic-gate }
30397c478bd9Sstevel@tonic-gate }
30407c478bd9Sstevel@tonic-gate
30417c478bd9Sstevel@tonic-gate void
kobj_vmem_init(vmem_t ** text_arena,vmem_t ** data_arena)30427c478bd9Sstevel@tonic-gate kobj_vmem_init(vmem_t **text_arena, vmem_t **data_arena)
30437c478bd9Sstevel@tonic-gate {
30447c478bd9Sstevel@tonic-gate size_t tsize = e_modtext - modtext;
30457c478bd9Sstevel@tonic-gate size_t dsize = e_moddata - moddata;
30467c478bd9Sstevel@tonic-gate
30477c478bd9Sstevel@tonic-gate *text_arena = vmem_create("module_text", tsize ? modtext : NULL, tsize,
30487c478bd9Sstevel@tonic-gate 1, segkmem_alloc, segkmem_free, heaptext_arena, 0, VM_SLEEP);
30497c478bd9Sstevel@tonic-gate *data_arena = vmem_create("module_data", dsize ? moddata : NULL, dsize,
30507c478bd9Sstevel@tonic-gate 1, segkmem_alloc, segkmem_free, heap32_arena, 0, VM_SLEEP);
30517c478bd9Sstevel@tonic-gate }
30527c478bd9Sstevel@tonic-gate
30537c478bd9Sstevel@tonic-gate caddr_t
kobj_text_alloc(vmem_t * arena,size_t size)30547c478bd9Sstevel@tonic-gate kobj_text_alloc(vmem_t *arena, size_t size)
30557c478bd9Sstevel@tonic-gate {
30567c478bd9Sstevel@tonic-gate return (vmem_alloc(arena, size, VM_SLEEP | VM_BESTFIT));
30577c478bd9Sstevel@tonic-gate }
30587c478bd9Sstevel@tonic-gate
30597c478bd9Sstevel@tonic-gate /*ARGSUSED*/
30607c478bd9Sstevel@tonic-gate caddr_t
kobj_texthole_alloc(caddr_t addr,size_t size)30617c478bd9Sstevel@tonic-gate kobj_texthole_alloc(caddr_t addr, size_t size)
30627c478bd9Sstevel@tonic-gate {
30637c478bd9Sstevel@tonic-gate panic("unexpected call to kobj_texthole_alloc()");
30647c478bd9Sstevel@tonic-gate /*NOTREACHED*/
30657c478bd9Sstevel@tonic-gate return (0);
30667c478bd9Sstevel@tonic-gate }
30677c478bd9Sstevel@tonic-gate
30687c478bd9Sstevel@tonic-gate /*ARGSUSED*/
30697c478bd9Sstevel@tonic-gate void
kobj_texthole_free(caddr_t addr,size_t size)30707c478bd9Sstevel@tonic-gate kobj_texthole_free(caddr_t addr, size_t size)
30717c478bd9Sstevel@tonic-gate {
30727c478bd9Sstevel@tonic-gate panic("unexpected call to kobj_texthole_free()");
30737c478bd9Sstevel@tonic-gate }
30747c478bd9Sstevel@tonic-gate
30757c478bd9Sstevel@tonic-gate /*
30767c478bd9Sstevel@tonic-gate * This is called just after configure() in startup().
30777c478bd9Sstevel@tonic-gate *
30787c478bd9Sstevel@tonic-gate * The ISALIST concept is a bit hopeless on Intel, because
30797c478bd9Sstevel@tonic-gate * there's no guarantee of an ever-more-capable processor
30807c478bd9Sstevel@tonic-gate * given that various parts of the instruction set may appear
30817c478bd9Sstevel@tonic-gate * and disappear between different implementations.
30827c478bd9Sstevel@tonic-gate *
30837c478bd9Sstevel@tonic-gate * While it would be possible to correct it and even enhance
30847c478bd9Sstevel@tonic-gate * it somewhat, the explicit hardware capability bitmask allows
30857c478bd9Sstevel@tonic-gate * more flexibility.
30867c478bd9Sstevel@tonic-gate *
30877c478bd9Sstevel@tonic-gate * So, we just leave this alone.
30887c478bd9Sstevel@tonic-gate */
30897c478bd9Sstevel@tonic-gate void
setx86isalist(void)30907c478bd9Sstevel@tonic-gate setx86isalist(void)
30917c478bd9Sstevel@tonic-gate {
30927c478bd9Sstevel@tonic-gate char *tp;
30937c478bd9Sstevel@tonic-gate size_t len;
30947c478bd9Sstevel@tonic-gate extern char *isa_list;
30957c478bd9Sstevel@tonic-gate
30967c478bd9Sstevel@tonic-gate #define TBUFSIZE 1024
30977c478bd9Sstevel@tonic-gate
30987c478bd9Sstevel@tonic-gate tp = kmem_alloc(TBUFSIZE, KM_SLEEP);
30997c478bd9Sstevel@tonic-gate *tp = '\0';
31007c478bd9Sstevel@tonic-gate
31017c478bd9Sstevel@tonic-gate (void) strcpy(tp, "amd64 ");
31027c478bd9Sstevel@tonic-gate
31037c478bd9Sstevel@tonic-gate switch (x86_vendor) {
31047c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel:
31057c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD:
31069b0429a1SPu Wen case X86_VENDOR_HYGON:
31077c478bd9Sstevel@tonic-gate case X86_VENDOR_TM:
31087417cfdeSKuriakose Kuruvilla if (is_x86_feature(x86_featureset, X86FSET_CMOV)) {
31097c478bd9Sstevel@tonic-gate /*
31107c478bd9Sstevel@tonic-gate * Pentium Pro or later
31117c478bd9Sstevel@tonic-gate */
31127c478bd9Sstevel@tonic-gate (void) strcat(tp, "pentium_pro");
31137417cfdeSKuriakose Kuruvilla (void) strcat(tp,
31147417cfdeSKuriakose Kuruvilla is_x86_feature(x86_featureset, X86FSET_MMX) ?
31157c478bd9Sstevel@tonic-gate "+mmx pentium_pro " : " ");
31167c478bd9Sstevel@tonic-gate }
31177c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/
31187c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix:
3119ab5bb018SKeith M Wesolowski ASSERT(is_x86_feature(x86_featureset, X86FSET_CPUID));
31207c478bd9Sstevel@tonic-gate (void) strcat(tp, "pentium");
31217417cfdeSKuriakose Kuruvilla (void) strcat(tp,
31227417cfdeSKuriakose Kuruvilla is_x86_feature(x86_featureset, X86FSET_MMX) ?
31237c478bd9Sstevel@tonic-gate "+mmx pentium " : " ");
31247c478bd9Sstevel@tonic-gate break;
31257c478bd9Sstevel@tonic-gate default:
31267c478bd9Sstevel@tonic-gate break;
31277c478bd9Sstevel@tonic-gate }
31287c478bd9Sstevel@tonic-gate (void) strcat(tp, "i486 i386 i86");
31297c478bd9Sstevel@tonic-gate len = strlen(tp) + 1; /* account for NULL at end of string */
31307c478bd9Sstevel@tonic-gate isa_list = strcpy(kmem_alloc(len, KM_SLEEP), tp);
31317c478bd9Sstevel@tonic-gate kmem_free(tp, TBUFSIZE);
31327c478bd9Sstevel@tonic-gate
31337c478bd9Sstevel@tonic-gate #undef TBUFSIZE
31347c478bd9Sstevel@tonic-gate }
31357c478bd9Sstevel@tonic-gate
31367c478bd9Sstevel@tonic-gate void *
device_arena_alloc(size_t size,int vm_flag)31377c478bd9Sstevel@tonic-gate device_arena_alloc(size_t size, int vm_flag)
31387c478bd9Sstevel@tonic-gate {
31397c478bd9Sstevel@tonic-gate return (vmem_alloc(device_arena, size, vm_flag));
31407c478bd9Sstevel@tonic-gate }
31417c478bd9Sstevel@tonic-gate
31427c478bd9Sstevel@tonic-gate void
device_arena_free(void * vaddr,size_t size)31437c478bd9Sstevel@tonic-gate device_arena_free(void *vaddr, size_t size)
31447c478bd9Sstevel@tonic-gate {
31457c478bd9Sstevel@tonic-gate vmem_free(device_arena, vaddr, size);
31467c478bd9Sstevel@tonic-gate }
3147