10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51455Sandrei * Common Development and Distribution License (the "License").
61455Sandrei * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
2212054SStephen.Hanson@Sun.COM * Copyright (c) 1993, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate */
2412004Sjiang.liu@intel.com /*
2512004Sjiang.liu@intel.com * Copyright (c) 2010, Intel Corporation.
2612004Sjiang.liu@intel.com * All rights reserved.
2712004Sjiang.liu@intel.com */
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <sys/t_lock.h>
310Sstevel@tonic-gate #include <sys/param.h>
320Sstevel@tonic-gate #include <sys/sysmacros.h>
330Sstevel@tonic-gate #include <sys/signal.h>
340Sstevel@tonic-gate #include <sys/systm.h>
350Sstevel@tonic-gate #include <sys/user.h>
360Sstevel@tonic-gate #include <sys/mman.h>
370Sstevel@tonic-gate #include <sys/vm.h>
380Sstevel@tonic-gate #include <sys/conf.h>
390Sstevel@tonic-gate #include <sys/avintr.h>
400Sstevel@tonic-gate #include <sys/autoconf.h>
410Sstevel@tonic-gate #include <sys/disp.h>
420Sstevel@tonic-gate #include <sys/class.h>
430Sstevel@tonic-gate #include <sys/bitmap.h>
440Sstevel@tonic-gate
450Sstevel@tonic-gate #include <sys/privregs.h>
460Sstevel@tonic-gate
470Sstevel@tonic-gate #include <sys/proc.h>
480Sstevel@tonic-gate #include <sys/buf.h>
490Sstevel@tonic-gate #include <sys/kmem.h>
503446Smrj #include <sys/mem.h>
510Sstevel@tonic-gate #include <sys/kstat.h>
520Sstevel@tonic-gate
530Sstevel@tonic-gate #include <sys/reboot.h>
540Sstevel@tonic-gate
550Sstevel@tonic-gate #include <sys/cred.h>
560Sstevel@tonic-gate #include <sys/vnode.h>
570Sstevel@tonic-gate #include <sys/file.h>
580Sstevel@tonic-gate
590Sstevel@tonic-gate #include <sys/procfs.h>
600Sstevel@tonic-gate
610Sstevel@tonic-gate #include <sys/vfs.h>
620Sstevel@tonic-gate #include <sys/cmn_err.h>
630Sstevel@tonic-gate #include <sys/utsname.h>
640Sstevel@tonic-gate #include <sys/debug.h>
650Sstevel@tonic-gate #include <sys/kdi.h>
660Sstevel@tonic-gate
670Sstevel@tonic-gate #include <sys/dumphdr.h>
680Sstevel@tonic-gate #include <sys/bootconf.h>
6912004Sjiang.liu@intel.com #include <sys/memlist_plat.h>
700Sstevel@tonic-gate #include <sys/varargs.h>
710Sstevel@tonic-gate #include <sys/promif.h>
725084Sjohnlev #include <sys/modctl.h>
730Sstevel@tonic-gate
740Sstevel@tonic-gate #include <sys/sunddi.h>
750Sstevel@tonic-gate #include <sys/sunndi.h>
760Sstevel@tonic-gate #include <sys/ndi_impldefs.h>
770Sstevel@tonic-gate #include <sys/ddidmareq.h>
780Sstevel@tonic-gate #include <sys/psw.h>
790Sstevel@tonic-gate #include <sys/regset.h>
800Sstevel@tonic-gate #include <sys/clock.h>
810Sstevel@tonic-gate #include <sys/pte.h>
820Sstevel@tonic-gate #include <sys/tss.h>
830Sstevel@tonic-gate #include <sys/stack.h>
840Sstevel@tonic-gate #include <sys/trap.h>
850Sstevel@tonic-gate #include <sys/fp.h>
865159Sjohnlev #include <vm/kboot_mmu.h>
870Sstevel@tonic-gate #include <vm/anon.h>
880Sstevel@tonic-gate #include <vm/as.h>
890Sstevel@tonic-gate #include <vm/page.h>
900Sstevel@tonic-gate #include <vm/seg.h>
910Sstevel@tonic-gate #include <vm/seg_dev.h>
920Sstevel@tonic-gate #include <vm/seg_kmem.h>
930Sstevel@tonic-gate #include <vm/seg_kpm.h>
940Sstevel@tonic-gate #include <vm/seg_map.h>
950Sstevel@tonic-gate #include <vm/seg_vn.h>
960Sstevel@tonic-gate #include <vm/seg_kp.h>
970Sstevel@tonic-gate #include <sys/memnode.h>
980Sstevel@tonic-gate #include <vm/vm_dep.h>
990Sstevel@tonic-gate #include <sys/thread.h>
1000Sstevel@tonic-gate #include <sys/sysconf.h>
1010Sstevel@tonic-gate #include <sys/vm_machparam.h>
1020Sstevel@tonic-gate #include <sys/archsystm.h>
1030Sstevel@tonic-gate #include <sys/machsystm.h>
1040Sstevel@tonic-gate #include <vm/hat.h>
1050Sstevel@tonic-gate #include <vm/hat_i86.h>
1060Sstevel@tonic-gate #include <sys/pmem.h>
1070Sstevel@tonic-gate #include <sys/smp_impldefs.h>
1080Sstevel@tonic-gate #include <sys/x86_archext.h>
1096336Sbholler #include <sys/cpuvar.h>
1100Sstevel@tonic-gate #include <sys/segments.h>
1110Sstevel@tonic-gate #include <sys/clconf.h>
1120Sstevel@tonic-gate #include <sys/kobj.h>
1130Sstevel@tonic-gate #include <sys/kobj_lex.h>
1140Sstevel@tonic-gate #include <sys/cpc_impl.h>
1151414Scindi #include <sys/cpu_module.h>
116437Smws #include <sys/smbios.h>
1173446Smrj #include <sys/debug_info.h>
1185159Sjohnlev #include <sys/bootinfo.h>
1195107Seota #include <sys/ddi_timer.h>
1208662SJordan.Vaughan@Sun.com #include <sys/systeminfo.h>
1217656SSherry.Moore@Sun.COM #include <sys/multiboot.h>
1223446Smrj
12312004Sjiang.liu@intel.com #ifdef __xpv
1245159Sjohnlev
1255084Sjohnlev #include <sys/hypervisor.h>
1265084Sjohnlev #include <sys/xen_mmu.h>
1275084Sjohnlev #include <sys/evtchn_impl.h>
1285084Sjohnlev #include <sys/gnttab.h>
1295084Sjohnlev #include <sys/xpv_panic.h>
1305084Sjohnlev #include <xen/sys/xenbus_comms.h>
1315084Sjohnlev #include <xen/public/physdev.h>
1325159Sjohnlev
1335084Sjohnlev extern void xen_late_startup(void);
1343446Smrj
1355159Sjohnlev struct xen_evt_data cpu0_evt_data;
1365159Sjohnlev
13712004Sjiang.liu@intel.com #else /* __xpv */
13812004Sjiang.liu@intel.com #include <sys/memlist_impl.h>
13912004Sjiang.liu@intel.com
14012004Sjiang.liu@intel.com extern void mem_config_init(void);
1415159Sjohnlev #endif /* __xpv */
1420Sstevel@tonic-gate
1430Sstevel@tonic-gate extern void progressbar_init(void);
1442712Snn35248 extern void brand_init(void);
1456880Sdv142724 extern void pcf_init(void);
1468906SEric.Saxe@Sun.COM extern void pg_init(void);
1470Sstevel@tonic-gate
1484878Sblakej extern int size_pse_array(pgcnt_t, int);
1494878Sblakej
1507720SKen.Erickson@Sun.COM #if defined(_SOFT_HOSTID)
1517720SKen.Erickson@Sun.COM
1527720SKen.Erickson@Sun.COM #include <sys/rtc.h>
1537720SKen.Erickson@Sun.COM
1547720SKen.Erickson@Sun.COM static int32_t set_soft_hostid(void);
1557720SKen.Erickson@Sun.COM static char hostid_file[] = "/etc/hostid";
1567720SKen.Erickson@Sun.COM
1577720SKen.Erickson@Sun.COM #endif
1587720SKen.Erickson@Sun.COM
1598215SVikram.Hegde@Sun.COM void *gfx_devinfo_list;
1607720SKen.Erickson@Sun.COM
16111600SVikram.Hegde@Sun.COM #if defined(__amd64) && !defined(__xpv)
16211600SVikram.Hegde@Sun.COM extern void immu_startup(void);
16311600SVikram.Hegde@Sun.COM #endif
16411600SVikram.Hegde@Sun.COM
1650Sstevel@tonic-gate /*
1660Sstevel@tonic-gate * XXX make declaration below "static" when drivers no longer use this
1670Sstevel@tonic-gate * interface.
1680Sstevel@tonic-gate */
1690Sstevel@tonic-gate extern caddr_t p0_va; /* Virtual address for accessing physical page 0 */
1700Sstevel@tonic-gate
1710Sstevel@tonic-gate /*
1720Sstevel@tonic-gate * segkp
1730Sstevel@tonic-gate */
1740Sstevel@tonic-gate extern int segkp_fromheap;
1750Sstevel@tonic-gate
1760Sstevel@tonic-gate static void kvm_init(void);
1770Sstevel@tonic-gate static void startup_init(void);
1780Sstevel@tonic-gate static void startup_memlist(void);
1793446Smrj static void startup_kmem(void);
1800Sstevel@tonic-gate static void startup_modules(void);
1810Sstevel@tonic-gate static void startup_vm(void);
1820Sstevel@tonic-gate static void startup_end(void);
1834828Sjosephb static void layout_kernel_va(void);
1840Sstevel@tonic-gate
1850Sstevel@tonic-gate /*
1860Sstevel@tonic-gate * Declare these as initialized data so we can patch them.
1870Sstevel@tonic-gate */
1881479Skchow #ifdef __i386
1894828Sjosephb
1901479Skchow /*
1911479Skchow * Due to virtual address space limitations running in 32 bit mode, restrict
1924828Sjosephb * the amount of physical memory configured to a max of PHYSMEM pages (16g).
1931479Skchow *
1941479Skchow * If the physical max memory size of 64g were allowed to be configured, the
1951479Skchow * size of user virtual address space will be less than 1g. A limited user
1961479Skchow * address space greatly reduces the range of applications that can run.
1971479Skchow *
1984828Sjosephb * If more physical memory than PHYSMEM is required, users should preferably
1994828Sjosephb * run in 64 bit mode which has far looser virtual address space limitations.
2001479Skchow *
2011479Skchow * If 64 bit mode is not available (as in IA32) and/or more physical memory
2024828Sjosephb * than PHYSMEM is required in 32 bit mode, physmem can be set to the desired
2031479Skchow * value or to 0 (to configure all available memory) via eeprom(1M). kernelbase
2041479Skchow * should also be carefully tuned to balance out the need of the user
2051479Skchow * application while minimizing the risk of kernel heap exhaustion due to
2061479Skchow * kernelbase being set too high.
2071479Skchow */
2084828Sjosephb #define PHYSMEM 0x400000
2094828Sjosephb
2104828Sjosephb #else /* __amd64 */
2111479Skchow
2124828Sjosephb /*
2134828Sjosephb * For now we can handle memory with physical addresses up to about
2144828Sjosephb * 64 Terabytes. This keeps the kernel above the VA hole, leaving roughly
2154828Sjosephb * half the VA space for seg_kpm. When systems get bigger than 64TB this
2164828Sjosephb * code will need revisiting. There is an implicit assumption that there
2174828Sjosephb * are no *huge* holes in the physical address space too.
2184828Sjosephb */
2194828Sjosephb #define TERABYTE (1ul << 40)
2204828Sjosephb #define PHYSMEM_MAX64 mmu_btop(64 * TERABYTE)
2214828Sjosephb #define PHYSMEM PHYSMEM_MAX64
2224828Sjosephb #define AMD64_VA_HOLE_END 0xFFFF800000000000ul
2234828Sjosephb
2244828Sjosephb #endif /* __amd64 */
2254828Sjosephb
2264828Sjosephb pgcnt_t physmem = PHYSMEM;
2270Sstevel@tonic-gate pgcnt_t obp_pages; /* Memory used by PROM for its text and data */
2280Sstevel@tonic-gate
2290Sstevel@tonic-gate char *kobj_file_buf;
2300Sstevel@tonic-gate int kobj_file_bufsize; /* set in /etc/system */
2310Sstevel@tonic-gate
2320Sstevel@tonic-gate /* Global variables for MP support. Used in mp_startup */
2337656SSherry.Moore@Sun.COM caddr_t rm_platter_va = 0;
2340Sstevel@tonic-gate uint32_t rm_platter_pa;
2350Sstevel@tonic-gate
236841Skchow int auto_lpg_disable = 1;
237841Skchow
2380Sstevel@tonic-gate /*
2390Sstevel@tonic-gate * Some CPUs have holes in the middle of the 64-bit virtual address range.
2400Sstevel@tonic-gate */
2410Sstevel@tonic-gate uintptr_t hole_start, hole_end;
2420Sstevel@tonic-gate
2430Sstevel@tonic-gate /*
2440Sstevel@tonic-gate * kpm mapping window
2450Sstevel@tonic-gate */
2460Sstevel@tonic-gate caddr_t kpm_vbase;
2470Sstevel@tonic-gate size_t kpm_size;
2484828Sjosephb static int kpm_desired;
2494828Sjosephb #ifdef __amd64
2504828Sjosephb static uintptr_t segkpm_base = (uintptr_t)SEGKPM_BASE;
2514828Sjosephb #endif
2520Sstevel@tonic-gate
2530Sstevel@tonic-gate /*
2540Sstevel@tonic-gate * Configuration parameters set at boot time.
2550Sstevel@tonic-gate */
2560Sstevel@tonic-gate
2570Sstevel@tonic-gate caddr_t econtig; /* end of first block of contiguous kernel */
2580Sstevel@tonic-gate
2590Sstevel@tonic-gate struct bootops *bootops = 0; /* passed in from boot */
2600Sstevel@tonic-gate struct bootops **bootopsp;
2610Sstevel@tonic-gate struct boot_syscalls *sysp; /* passed in from boot */
2620Sstevel@tonic-gate
2630Sstevel@tonic-gate char bootblock_fstype[16];
2640Sstevel@tonic-gate
2650Sstevel@tonic-gate char kern_bootargs[OBP_MAXPATHLEN];
2667656SSherry.Moore@Sun.COM char kern_bootfile[OBP_MAXPATHLEN];
2670Sstevel@tonic-gate
2680Sstevel@tonic-gate /*
2693290Sjohansen * ZFS zio segment. This allows us to exclude large portions of ZFS data that
2703290Sjohansen * gets cached in kmem caches on the heap. If this is set to zero, we allocate
2713290Sjohansen * zio buffers from their own segment, otherwise they are allocated from the
2723290Sjohansen * heap. The optimization of allocating zio buffers from their own segment is
2733290Sjohansen * only valid on 64-bit kernels.
2743290Sjohansen */
2753290Sjohansen #if defined(__amd64)
2763290Sjohansen int segzio_fromheap = 0;
2773290Sjohansen #else
2783290Sjohansen int segzio_fromheap = 1;
2793290Sjohansen #endif
2803290Sjohansen
2813290Sjohansen /*
2820Sstevel@tonic-gate * new memory fragmentations are possible in startup() due to BOP_ALLOCs. this
2830Sstevel@tonic-gate * depends on number of BOP_ALLOC calls made and requested size, memory size
2840Sstevel@tonic-gate * combination and whether boot.bin memory needs to be freed.
2850Sstevel@tonic-gate */
2860Sstevel@tonic-gate #define POSS_NEW_FRAGMENTS 12
2870Sstevel@tonic-gate
2880Sstevel@tonic-gate /*
2890Sstevel@tonic-gate * VM data structures
2900Sstevel@tonic-gate */
2910Sstevel@tonic-gate long page_hashsz; /* Size of page hash table (power of two) */
29212230SFrank.Rival@oracle.com unsigned int page_hashsz_shift; /* log2(page_hashsz) */
2930Sstevel@tonic-gate struct page *pp_base; /* Base of initial system page struct array */
2940Sstevel@tonic-gate struct page **page_hash; /* Page hash table */
2954878Sblakej pad_mutex_t *pse_mutex; /* Locks protecting pp->p_selock */
2964878Sblakej size_t pse_table_size; /* Number of mutexes in pse_mutex[] */
2974878Sblakej int pse_shift; /* log2(pse_table_size) */
2980Sstevel@tonic-gate struct seg ktextseg; /* Segment used for kernel executable image */
2990Sstevel@tonic-gate struct seg kvalloc; /* Segment used for "valloc" mapping */
3000Sstevel@tonic-gate struct seg kpseg; /* Segment used for pageable kernel virt mem */
3010Sstevel@tonic-gate struct seg kmapseg; /* Segment used for generic kernel mappings */
3020Sstevel@tonic-gate struct seg kdebugseg; /* Segment used for the kernel debugger */
3030Sstevel@tonic-gate
3040Sstevel@tonic-gate struct seg *segkmap = &kmapseg; /* Kernel generic mapping segment */
3053446Smrj static struct seg *segmap = &kmapseg; /* easier to use name for in here */
3063446Smrj
3070Sstevel@tonic-gate struct seg *segkp = &kpseg; /* Pageable kernel virtual memory segment */
3080Sstevel@tonic-gate
3090Sstevel@tonic-gate #if defined(__amd64)
3100Sstevel@tonic-gate struct seg kvseg_core; /* Segment used for the core heap */
3110Sstevel@tonic-gate struct seg kpmseg; /* Segment used for physical mapping */
3120Sstevel@tonic-gate struct seg *segkpm = &kpmseg; /* 64bit kernel physical mapping segment */
3130Sstevel@tonic-gate #else
3140Sstevel@tonic-gate struct seg *segkpm = NULL; /* Unused on IA32 */
3150Sstevel@tonic-gate #endif
3160Sstevel@tonic-gate
3170Sstevel@tonic-gate caddr_t segkp_base; /* Base address of segkp */
3183290Sjohansen caddr_t segzio_base; /* Base address of segzio */
3190Sstevel@tonic-gate #if defined(__amd64)
3200Sstevel@tonic-gate pgcnt_t segkpsize = btop(SEGKPDEFSIZE); /* size of segkp segment in pages */
3210Sstevel@tonic-gate #else
3220Sstevel@tonic-gate pgcnt_t segkpsize = 0;
3230Sstevel@tonic-gate #endif
3243290Sjohansen pgcnt_t segziosize = 0; /* size of zio segment in pages */
3250Sstevel@tonic-gate
3263446Smrj /*
32712004Sjiang.liu@intel.com * A static DR page_t VA map is reserved that can map the page structures
32812004Sjiang.liu@intel.com * for a domain's entire RA space. The pages that back this space are
32912004Sjiang.liu@intel.com * dynamically allocated and need not be physically contiguous. The DR
33012004Sjiang.liu@intel.com * map size is derived from KPM size.
33112004Sjiang.liu@intel.com * This mechanism isn't used by x86 yet, so just stubs here.
33212004Sjiang.liu@intel.com */
33312004Sjiang.liu@intel.com int ppvm_enable = 0; /* Static virtual map for page structs */
33412004Sjiang.liu@intel.com page_t *ppvm_base = NULL; /* Base of page struct map */
33512004Sjiang.liu@intel.com pgcnt_t ppvm_size = 0; /* Size of page struct map */
33612004Sjiang.liu@intel.com
33712004Sjiang.liu@intel.com /*
3383446Smrj * VA range available to the debugger
3393446Smrj */
3403446Smrj const caddr_t kdi_segdebugbase = (const caddr_t)SEGDEBUGBASE;
3413446Smrj const size_t kdi_segdebugsize = SEGDEBUGSIZE;
3423446Smrj
3430Sstevel@tonic-gate struct memseg *memseg_base;
3440Sstevel@tonic-gate struct vnode unused_pages_vp;
3450Sstevel@tonic-gate
3460Sstevel@tonic-gate #define FOURGB 0x100000000LL
3470Sstevel@tonic-gate
3480Sstevel@tonic-gate struct memlist *memlist;
3490Sstevel@tonic-gate
3500Sstevel@tonic-gate caddr_t s_text; /* start of kernel text segment */
3510Sstevel@tonic-gate caddr_t e_text; /* end of kernel text segment */
3520Sstevel@tonic-gate caddr_t s_data; /* start of kernel data segment */
3530Sstevel@tonic-gate caddr_t e_data; /* end of kernel data segment */
3540Sstevel@tonic-gate caddr_t modtext; /* start of loadable module text reserved */
3550Sstevel@tonic-gate caddr_t e_modtext; /* end of loadable module text reserved */
3560Sstevel@tonic-gate caddr_t moddata; /* start of loadable module data reserved */
3570Sstevel@tonic-gate caddr_t e_moddata; /* end of loadable module data reserved */
3580Sstevel@tonic-gate
3590Sstevel@tonic-gate struct memlist *phys_install; /* Total installed physical memory */
3600Sstevel@tonic-gate struct memlist *phys_avail; /* Total available physical memory */
3619940SVikram.Hegde@Sun.COM struct memlist *bios_rsvd; /* Bios reserved memory */
3620Sstevel@tonic-gate
3630Sstevel@tonic-gate /*
3640Sstevel@tonic-gate * kphysm_init returns the number of pages that were processed
3650Sstevel@tonic-gate */
3663446Smrj static pgcnt_t kphysm_init(page_t *, pgcnt_t);
3670Sstevel@tonic-gate
3680Sstevel@tonic-gate #define IO_PROP_SIZE 64 /* device property size */
3690Sstevel@tonic-gate
3700Sstevel@tonic-gate /*
3710Sstevel@tonic-gate * a couple useful roundup macros
3720Sstevel@tonic-gate */
3730Sstevel@tonic-gate #define ROUND_UP_PAGE(x) \
3740Sstevel@tonic-gate ((uintptr_t)P2ROUNDUP((uintptr_t)(x), (uintptr_t)MMU_PAGESIZE))
3750Sstevel@tonic-gate #define ROUND_UP_LPAGE(x) \
3760Sstevel@tonic-gate ((uintptr_t)P2ROUNDUP((uintptr_t)(x), mmu.level_size[1]))
3770Sstevel@tonic-gate #define ROUND_UP_4MEG(x) \
3783446Smrj ((uintptr_t)P2ROUNDUP((uintptr_t)(x), (uintptr_t)FOUR_MEG))
3790Sstevel@tonic-gate #define ROUND_UP_TOPLEVEL(x) \
3800Sstevel@tonic-gate ((uintptr_t)P2ROUNDUP((uintptr_t)(x), mmu.level_size[mmu.max_level]))
3810Sstevel@tonic-gate
3820Sstevel@tonic-gate /*
3830Sstevel@tonic-gate * 32-bit Kernel's Virtual memory layout.
3840Sstevel@tonic-gate * +-----------------------+
3853446Smrj * | |
3860Sstevel@tonic-gate * 0xFFC00000 -|-----------------------|- ARGSBASE
3870Sstevel@tonic-gate * | debugger |
3880Sstevel@tonic-gate * 0xFF800000 -|-----------------------|- SEGDEBUGBASE
3890Sstevel@tonic-gate * | Kernel Data |
3900Sstevel@tonic-gate * 0xFEC00000 -|-----------------------|
3910Sstevel@tonic-gate * | Kernel Text |
3925084Sjohnlev * 0xFE800000 -|-----------------------|- KERNEL_TEXT (0xFB400000 on Xen)
3933446Smrj * |--- GDT ---|- GDT page (GDT_VA)
3943446Smrj * |--- debug info ---|- debug info (DEBUG_INFO_VA)
3953446Smrj * | |
3963446Smrj * | page_t structures |
3970Sstevel@tonic-gate * | memsegs, memlists, |
3980Sstevel@tonic-gate * | page hash, etc. |
3993446Smrj * --- -|-----------------------|- ekernelheap, valloc_base (floating)
4003446Smrj * | | (segkp is just an arena in the heap)
4010Sstevel@tonic-gate * | |
4020Sstevel@tonic-gate * | kvseg |
4030Sstevel@tonic-gate * | |
4040Sstevel@tonic-gate * | |
4050Sstevel@tonic-gate * --- -|-----------------------|- kernelheap (floating)
4060Sstevel@tonic-gate * | Segkmap |
4073446Smrj * 0xC3002000 -|-----------------------|- segmap_start (floating)
4080Sstevel@tonic-gate * | Red Zone |
4090Sstevel@tonic-gate * 0xC3000000 -|-----------------------|- kernelbase / userlimit (floating)
4100Sstevel@tonic-gate * | | ||
4110Sstevel@tonic-gate * | Shared objects | \/
4120Sstevel@tonic-gate * | |
4130Sstevel@tonic-gate * : :
4140Sstevel@tonic-gate * | user data |
4150Sstevel@tonic-gate * |-----------------------|
4160Sstevel@tonic-gate * | user text |
4170Sstevel@tonic-gate * 0x08048000 -|-----------------------|
4180Sstevel@tonic-gate * | user stack |
4190Sstevel@tonic-gate * : :
4200Sstevel@tonic-gate * | invalid |
4210Sstevel@tonic-gate * 0x00000000 +-----------------------+
4220Sstevel@tonic-gate *
4230Sstevel@tonic-gate *
4240Sstevel@tonic-gate * 64-bit Kernel's Virtual memory layout. (assuming 64 bit app)
4250Sstevel@tonic-gate * +-----------------------+
4263446Smrj * | |
4270Sstevel@tonic-gate * 0xFFFFFFFF.FFC00000 |-----------------------|- ARGSBASE
4280Sstevel@tonic-gate * | debugger (?) |
4290Sstevel@tonic-gate * 0xFFFFFFFF.FF800000 |-----------------------|- SEGDEBUGBASE
4300Sstevel@tonic-gate * | unused |
4310Sstevel@tonic-gate * +-----------------------+
4320Sstevel@tonic-gate * | Kernel Data |
4330Sstevel@tonic-gate * 0xFFFFFFFF.FBC00000 |-----------------------|
4340Sstevel@tonic-gate * | Kernel Text |
4350Sstevel@tonic-gate * 0xFFFFFFFF.FB800000 |-----------------------|- KERNEL_TEXT
4363446Smrj * |--- GDT ---|- GDT page (GDT_VA)
4373446Smrj * |--- debug info ---|- debug info (DEBUG_INFO_VA)
4383446Smrj * | |
4390Sstevel@tonic-gate * | Core heap | (used for loadable modules)
4400Sstevel@tonic-gate * 0xFFFFFFFF.C0000000 |-----------------------|- core_base / ekernelheap
4410Sstevel@tonic-gate * | Kernel |
4420Sstevel@tonic-gate * | heap |
4430Sstevel@tonic-gate * 0xFFFFFXXX.XXX00000 |-----------------------|- kernelheap (floating)
4443446Smrj * | segmap |
4453446Smrj * 0xFFFFFXXX.XXX00000 |-----------------------|- segmap_start (floating)
4460Sstevel@tonic-gate * | device mappings |
4470Sstevel@tonic-gate * 0xFFFFFXXX.XXX00000 |-----------------------|- toxic_addr (floating)
4483290Sjohansen * | segzio |
4493290Sjohansen * 0xFFFFFXXX.XXX00000 |-----------------------|- segzio_base (floating)
4500Sstevel@tonic-gate * | segkp |
4513446Smrj * --- |-----------------------|- segkp_base (floating)
4523446Smrj * | page_t structures | valloc_base + valloc_sz
4533446Smrj * | memsegs, memlists, |
4543446Smrj * | page hash, etc. |
4554828Sjosephb * 0xFFFFFF00.00000000 |-----------------------|- valloc_base (lower if > 1TB)
4560Sstevel@tonic-gate * | segkpm |
4570Sstevel@tonic-gate * 0xFFFFFE00.00000000 |-----------------------|
4580Sstevel@tonic-gate * | Red Zone |
4594828Sjosephb * 0xFFFFFD80.00000000 |-----------------------|- KERNELBASE (lower if > 1TB)
4600Sstevel@tonic-gate * | User stack |- User space memory
4610Sstevel@tonic-gate * | |
4620Sstevel@tonic-gate * | shared objects, etc | (grows downwards)
4630Sstevel@tonic-gate * : :
4640Sstevel@tonic-gate * | |
4650Sstevel@tonic-gate * 0xFFFF8000.00000000 |-----------------------|
4660Sstevel@tonic-gate * | |
4670Sstevel@tonic-gate * | VA Hole / unused |
4680Sstevel@tonic-gate * | |
4690Sstevel@tonic-gate * 0x00008000.00000000 |-----------------------|
4700Sstevel@tonic-gate * | |
4710Sstevel@tonic-gate * | |
4720Sstevel@tonic-gate * : :
4730Sstevel@tonic-gate * | user heap | (grows upwards)
4740Sstevel@tonic-gate * | |
4750Sstevel@tonic-gate * | user data |
4760Sstevel@tonic-gate * |-----------------------|
4770Sstevel@tonic-gate * | user text |
4780Sstevel@tonic-gate * 0x00000000.04000000 |-----------------------|
4790Sstevel@tonic-gate * | invalid |
4800Sstevel@tonic-gate * 0x00000000.00000000 +-----------------------+
4810Sstevel@tonic-gate *
4820Sstevel@tonic-gate * A 32 bit app on the 64 bit kernel sees the same layout as on the 32 bit
4830Sstevel@tonic-gate * kernel, except that userlimit is raised to 0xfe000000
4840Sstevel@tonic-gate *
4850Sstevel@tonic-gate * Floating values:
4860Sstevel@tonic-gate *
4870Sstevel@tonic-gate * valloc_base: start of the kernel's memory management/tracking data
4883446Smrj * structures. This region contains page_t structures for
4893446Smrj * physical memory, memsegs, memlists, and the page hash.
4900Sstevel@tonic-gate *
4910Sstevel@tonic-gate * core_base: start of the kernel's "core" heap area on 64-bit systems.
4920Sstevel@tonic-gate * This area is intended to be used for global data as well as for module
4930Sstevel@tonic-gate * text/data that does not fit into the nucleus pages. The core heap is
4940Sstevel@tonic-gate * restricted to a 2GB range, allowing every address within it to be
4950Sstevel@tonic-gate * accessed using rip-relative addressing
4960Sstevel@tonic-gate *
4970Sstevel@tonic-gate * ekernelheap: end of kernelheap and start of segmap.
4980Sstevel@tonic-gate *
4990Sstevel@tonic-gate * kernelheap: start of kernel heap. On 32-bit systems, this starts right
5000Sstevel@tonic-gate * above a red zone that separates the user's address space from the
5010Sstevel@tonic-gate * kernel's. On 64-bit systems, it sits above segkp and segkpm.
5020Sstevel@tonic-gate *
5033446Smrj * segmap_start: start of segmap. The length of segmap can be modified
5047692SAmrita.Sadhukhan@Sun.COM * through eeprom. The default length is 16MB on 32-bit systems and 64MB
5057692SAmrita.Sadhukhan@Sun.COM * on 64-bit systems.
5060Sstevel@tonic-gate *
5070Sstevel@tonic-gate * kernelbase: On a 32-bit kernel the default value of 0xd4000000 will be
5080Sstevel@tonic-gate * decreased by 2X the size required for page_t. This allows the kernel
5090Sstevel@tonic-gate * heap to grow in size with physical memory. With sizeof(page_t) == 80
5100Sstevel@tonic-gate * bytes, the following shows the values of kernelbase and kernel heap
5110Sstevel@tonic-gate * sizes for different memory configurations (assuming default segmap and
5120Sstevel@tonic-gate * segkp sizes).
5130Sstevel@tonic-gate *
5140Sstevel@tonic-gate * mem size for kernelbase kernel heap
5150Sstevel@tonic-gate * size page_t's size
5160Sstevel@tonic-gate * ---- --------- ---------- -----------
5170Sstevel@tonic-gate * 1gb 0x01400000 0xd1800000 684MB
5180Sstevel@tonic-gate * 2gb 0x02800000 0xcf000000 704MB
5190Sstevel@tonic-gate * 4gb 0x05000000 0xca000000 744MB
5200Sstevel@tonic-gate * 6gb 0x07800000 0xc5000000 784MB
5210Sstevel@tonic-gate * 8gb 0x0a000000 0xc0000000 824MB
5220Sstevel@tonic-gate * 16gb 0x14000000 0xac000000 984MB
5230Sstevel@tonic-gate * 32gb 0x28000000 0x84000000 1304MB
5240Sstevel@tonic-gate * 64gb 0x50000000 0x34000000 1944MB (*)
5250Sstevel@tonic-gate *
5260Sstevel@tonic-gate * kernelbase is less than the abi minimum of 0xc0000000 for memory
5270Sstevel@tonic-gate * configurations above 8gb.
5280Sstevel@tonic-gate *
5290Sstevel@tonic-gate * (*) support for memory configurations above 32gb will require manual tuning
5300Sstevel@tonic-gate * of kernelbase to balance out the need of user applications.
5310Sstevel@tonic-gate */
5320Sstevel@tonic-gate
5330Sstevel@tonic-gate /* real-time-clock initialization parameters */
5343446Smrj extern time_t process_rtc_config_file(void);
5350Sstevel@tonic-gate
5360Sstevel@tonic-gate uintptr_t kernelbase;
5373446Smrj uintptr_t postbootkernelbase; /* not set till boot loader is gone */
5380Sstevel@tonic-gate uintptr_t eprom_kernelbase;
5390Sstevel@tonic-gate size_t segmapsize;
5403446Smrj uintptr_t segmap_start;
5410Sstevel@tonic-gate int segmapfreelists;
5420Sstevel@tonic-gate pgcnt_t npages;
5433446Smrj pgcnt_t orig_npages;
5440Sstevel@tonic-gate size_t core_size; /* size of "core" heap */
5450Sstevel@tonic-gate uintptr_t core_base; /* base address of "core" heap */
5460Sstevel@tonic-gate
5470Sstevel@tonic-gate /*
5480Sstevel@tonic-gate * List of bootstrap pages. We mark these as allocated in startup.
5490Sstevel@tonic-gate * release_bootstrap() will free them when we're completely done with
5500Sstevel@tonic-gate * the bootstrap.
5510Sstevel@tonic-gate */
5523446Smrj static page_t *bootpages;
5533446Smrj
5543446Smrj /*
5553446Smrj * boot time pages that have a vnode from the ramdisk will keep that forever.
5563446Smrj */
5573446Smrj static page_t *rd_pages;
5580Sstevel@tonic-gate
5597656SSherry.Moore@Sun.COM /*
5607656SSherry.Moore@Sun.COM * Lower 64K
5617656SSherry.Moore@Sun.COM */
5627656SSherry.Moore@Sun.COM static page_t *lower_pages = NULL;
5637656SSherry.Moore@Sun.COM static int lower_pages_count = 0;
5647656SSherry.Moore@Sun.COM
5650Sstevel@tonic-gate struct system_hardware system_hardware;
5660Sstevel@tonic-gate
5670Sstevel@tonic-gate /*
5680Sstevel@tonic-gate * Enable some debugging messages concerning memory usage...
5690Sstevel@tonic-gate */
5700Sstevel@tonic-gate static void
print_memlist(char * title,struct memlist * mp)5713446Smrj print_memlist(char *title, struct memlist *mp)
5720Sstevel@tonic-gate {
5730Sstevel@tonic-gate prom_printf("MEMLIST: %s:\n", title);
5740Sstevel@tonic-gate while (mp != NULL) {
5750Sstevel@tonic-gate prom_printf("\tAddress 0x%" PRIx64 ", size 0x%" PRIx64 "\n",
57611474SJonathan.Adams@Sun.COM mp->ml_address, mp->ml_size);
57711474SJonathan.Adams@Sun.COM mp = mp->ml_next;
5780Sstevel@tonic-gate }
5790Sstevel@tonic-gate }
5800Sstevel@tonic-gate
5810Sstevel@tonic-gate /*
5820Sstevel@tonic-gate * XX64 need a comment here.. are these just default values, surely
5830Sstevel@tonic-gate * we read the "cpuid" type information to figure this out.
5840Sstevel@tonic-gate */
5850Sstevel@tonic-gate int l2cache_sz = 0x80000;
5860Sstevel@tonic-gate int l2cache_linesz = 0x40;
5870Sstevel@tonic-gate int l2cache_assoc = 1;
5880Sstevel@tonic-gate
5894426Saguzovsk static size_t textrepl_min_gb = 10;
5904426Saguzovsk
5910Sstevel@tonic-gate /*
5920Sstevel@tonic-gate * on 64 bit we use a predifined VA range for mapping devices in the kernel
5930Sstevel@tonic-gate * on 32 bit the mappings are intermixed in the heap, so we use a bit map
5940Sstevel@tonic-gate */
5950Sstevel@tonic-gate #ifdef __amd64
5960Sstevel@tonic-gate
5970Sstevel@tonic-gate vmem_t *device_arena;
5980Sstevel@tonic-gate uintptr_t toxic_addr = (uintptr_t)NULL;
5993446Smrj size_t toxic_size = 1024 * 1024 * 1024; /* Sparc uses 1 gig too */
6000Sstevel@tonic-gate
6010Sstevel@tonic-gate #else /* __i386 */
6020Sstevel@tonic-gate
6030Sstevel@tonic-gate ulong_t *toxic_bit_map; /* one bit for each 4k of VA in heap_arena */
6040Sstevel@tonic-gate size_t toxic_bit_map_len = 0; /* in bits */
6050Sstevel@tonic-gate
6060Sstevel@tonic-gate #endif /* __i386 */
6070Sstevel@tonic-gate
6080Sstevel@tonic-gate /*
6090Sstevel@tonic-gate * Simple boot time debug facilities
6100Sstevel@tonic-gate */
6110Sstevel@tonic-gate static char *prm_dbg_str[] = {
6120Sstevel@tonic-gate "%s:%d: '%s' is 0x%x\n",
6130Sstevel@tonic-gate "%s:%d: '%s' is 0x%llx\n"
6140Sstevel@tonic-gate };
6150Sstevel@tonic-gate
6160Sstevel@tonic-gate int prom_debug;
6170Sstevel@tonic-gate
6180Sstevel@tonic-gate #define PRM_DEBUG(q) if (prom_debug) \
6190Sstevel@tonic-gate prom_printf(prm_dbg_str[sizeof (q) >> 3], "startup.c", __LINE__, #q, q);
6200Sstevel@tonic-gate #define PRM_POINT(q) if (prom_debug) \
6210Sstevel@tonic-gate prom_printf("%s:%d: %s\n", "startup.c", __LINE__, q);
6220Sstevel@tonic-gate
6230Sstevel@tonic-gate /*
6240Sstevel@tonic-gate * This structure is used to keep track of the intial allocations
6250Sstevel@tonic-gate * done in startup_memlist(). The value of NUM_ALLOCATIONS needs to
6260Sstevel@tonic-gate * be >= the number of ADD_TO_ALLOCATIONS() executed in the code.
6270Sstevel@tonic-gate */
6289940SVikram.Hegde@Sun.COM #define NUM_ALLOCATIONS 8
6290Sstevel@tonic-gate int num_allocations = 0;
6300Sstevel@tonic-gate struct {
6310Sstevel@tonic-gate void **al_ptr;
6320Sstevel@tonic-gate size_t al_size;
6330Sstevel@tonic-gate } allocations[NUM_ALLOCATIONS];
6340Sstevel@tonic-gate size_t valloc_sz = 0;
6350Sstevel@tonic-gate uintptr_t valloc_base;
6360Sstevel@tonic-gate
6370Sstevel@tonic-gate #define ADD_TO_ALLOCATIONS(ptr, size) { \
6380Sstevel@tonic-gate size = ROUND_UP_PAGE(size); \
6390Sstevel@tonic-gate if (num_allocations == NUM_ALLOCATIONS) \
6400Sstevel@tonic-gate panic("too many ADD_TO_ALLOCATIONS()"); \
6410Sstevel@tonic-gate allocations[num_allocations].al_ptr = (void**)&ptr; \
6420Sstevel@tonic-gate allocations[num_allocations].al_size = size; \
6430Sstevel@tonic-gate valloc_sz += size; \
6440Sstevel@tonic-gate ++num_allocations; \
6450Sstevel@tonic-gate }
6460Sstevel@tonic-gate
6473446Smrj /*
6483446Smrj * Allocate all the initial memory needed by the page allocator.
6493446Smrj */
6500Sstevel@tonic-gate static void
perform_allocations(void)6510Sstevel@tonic-gate perform_allocations(void)
6520Sstevel@tonic-gate {
6530Sstevel@tonic-gate caddr_t mem;
6540Sstevel@tonic-gate int i;
6553446Smrj int valloc_align;
6560Sstevel@tonic-gate
6573446Smrj PRM_DEBUG(valloc_base);
6583446Smrj PRM_DEBUG(valloc_sz);
6593446Smrj valloc_align = mmu.level_size[mmu.max_page_level > 0];
6603446Smrj mem = BOP_ALLOC(bootops, (caddr_t)valloc_base, valloc_sz, valloc_align);
6610Sstevel@tonic-gate if (mem != (caddr_t)valloc_base)
6620Sstevel@tonic-gate panic("BOP_ALLOC() failed");
6630Sstevel@tonic-gate bzero(mem, valloc_sz);
6640Sstevel@tonic-gate for (i = 0; i < num_allocations; ++i) {
6650Sstevel@tonic-gate *allocations[i].al_ptr = (void *)mem;
6660Sstevel@tonic-gate mem += allocations[i].al_size;
6670Sstevel@tonic-gate }
6680Sstevel@tonic-gate }
6690Sstevel@tonic-gate
6700Sstevel@tonic-gate /*
6710Sstevel@tonic-gate * Our world looks like this at startup time.
6720Sstevel@tonic-gate *
6730Sstevel@tonic-gate * In a 32-bit OS, boot loads the kernel text at 0xfe800000 and kernel data
6740Sstevel@tonic-gate * at 0xfec00000. On a 64-bit OS, kernel text and data are loaded at
6750Sstevel@tonic-gate * 0xffffffff.fe800000 and 0xffffffff.fec00000 respectively. Those
6760Sstevel@tonic-gate * addresses are fixed in the binary at link time.
6770Sstevel@tonic-gate *
6780Sstevel@tonic-gate * On the text page:
6790Sstevel@tonic-gate * unix/genunix/krtld/module text loads.
6800Sstevel@tonic-gate *
6810Sstevel@tonic-gate * On the data page:
6823446Smrj * unix/genunix/krtld/module data loads.
6833446Smrj *
6840Sstevel@tonic-gate * Machine-dependent startup code
6850Sstevel@tonic-gate */
6860Sstevel@tonic-gate void
startup(void)6870Sstevel@tonic-gate startup(void)
6880Sstevel@tonic-gate {
6895084Sjohnlev #if !defined(__xpv)
6901494Sjg extern void startup_pci_bios(void);
6915084Sjohnlev #endif
6926336Sbholler extern cpuset_t cpu_ready_set;
6936336Sbholler
6945084Sjohnlev /*
6955084Sjohnlev * Make sure that nobody tries to use sekpm until we have
6965084Sjohnlev * initialized it properly.
6975084Sjohnlev */
6980Sstevel@tonic-gate #if defined(__amd64)
6994828Sjosephb kpm_desired = 1;
7000Sstevel@tonic-gate #endif
7010Sstevel@tonic-gate kpm_enable = 0;
7026336Sbholler CPUSET_ONLY(cpu_ready_set, 0); /* cpu 0 is boot cpu */
7030Sstevel@tonic-gate
7045084Sjohnlev #if defined(__xpv) /* XXPV fix me! */
7055084Sjohnlev {
7065084Sjohnlev extern int segvn_use_regions;
7075084Sjohnlev segvn_use_regions = 0;
7085084Sjohnlev }
7095084Sjohnlev #endif
7100Sstevel@tonic-gate progressbar_init();
7110Sstevel@tonic-gate startup_init();
7125316Sjohnlev #if defined(__xpv)
7135316Sjohnlev startup_xen_version();
7145316Sjohnlev #endif
7150Sstevel@tonic-gate startup_memlist();
7163446Smrj startup_kmem();
7174828Sjosephb startup_vm();
7185084Sjohnlev #if !defined(__xpv)
71912054SStephen.Hanson@Sun.COM /*
72012054SStephen.Hanson@Sun.COM * Note we need to do this even on fast reboot in order to access
72112054SStephen.Hanson@Sun.COM * the irq routing table (used for pci labels).
72212054SStephen.Hanson@Sun.COM */
72312054SStephen.Hanson@Sun.COM startup_pci_bios();
7245084Sjohnlev #endif
7257532SSean.Ye@Sun.COM #if defined(__xpv)
7267532SSean.Ye@Sun.COM startup_xen_mca();
7277532SSean.Ye@Sun.COM #endif
7280Sstevel@tonic-gate startup_modules();
72910321SLipeng.Sang@Sun.COM
7300Sstevel@tonic-gate startup_end();
7310Sstevel@tonic-gate }
7320Sstevel@tonic-gate
7330Sstevel@tonic-gate static void
startup_init()7340Sstevel@tonic-gate startup_init()
7350Sstevel@tonic-gate {
7360Sstevel@tonic-gate PRM_POINT("startup_init() starting...");
7370Sstevel@tonic-gate
7380Sstevel@tonic-gate /*
7390Sstevel@tonic-gate * Complete the extraction of cpuid data
7400Sstevel@tonic-gate */
7410Sstevel@tonic-gate cpuid_pass2(CPU);
7420Sstevel@tonic-gate
7430Sstevel@tonic-gate (void) check_boot_version(BOP_GETVERSION(bootops));
7440Sstevel@tonic-gate
7450Sstevel@tonic-gate /*
7460Sstevel@tonic-gate * Check for prom_debug in boot environment
7470Sstevel@tonic-gate */
7480Sstevel@tonic-gate if (BOP_GETPROPLEN(bootops, "prom_debug") >= 0) {
7490Sstevel@tonic-gate ++prom_debug;
7500Sstevel@tonic-gate PRM_POINT("prom_debug found in boot enviroment");
7510Sstevel@tonic-gate }
7520Sstevel@tonic-gate
7530Sstevel@tonic-gate /*
7540Sstevel@tonic-gate * Collect node, cpu and memory configuration information.
7550Sstevel@tonic-gate */
7560Sstevel@tonic-gate get_system_configuration();
7570Sstevel@tonic-gate
7580Sstevel@tonic-gate /*
7590Sstevel@tonic-gate * Halt if this is an unsupported processor.
7600Sstevel@tonic-gate */
7610Sstevel@tonic-gate if (x86_type == X86_TYPE_486 || x86_type == X86_TYPE_CYRIX_486) {
7620Sstevel@tonic-gate printf("\n486 processor (\"%s\") detected.\n",
7630Sstevel@tonic-gate CPU->cpu_brandstr);
7640Sstevel@tonic-gate halt("This processor is not supported by this release "
7650Sstevel@tonic-gate "of Solaris.");
7660Sstevel@tonic-gate }
7670Sstevel@tonic-gate
7680Sstevel@tonic-gate PRM_POINT("startup_init() done");
7690Sstevel@tonic-gate }
7700Sstevel@tonic-gate
7710Sstevel@tonic-gate /*
7720Sstevel@tonic-gate * Callback for copy_memlist_filter() to filter nucleus, kadb/kmdb, (ie.
7730Sstevel@tonic-gate * everything mapped above KERNEL_TEXT) pages from phys_avail. Note it
7740Sstevel@tonic-gate * also filters out physical page zero. There is some reliance on the
7750Sstevel@tonic-gate * boot loader allocating only a few contiguous physical memory chunks.
7760Sstevel@tonic-gate */
7770Sstevel@tonic-gate static void
avail_filter(uint64_t * addr,uint64_t * size)7780Sstevel@tonic-gate avail_filter(uint64_t *addr, uint64_t *size)
7790Sstevel@tonic-gate {
7800Sstevel@tonic-gate uintptr_t va;
7810Sstevel@tonic-gate uintptr_t next_va;
7820Sstevel@tonic-gate pfn_t pfn;
7830Sstevel@tonic-gate uint64_t pfn_addr;
7840Sstevel@tonic-gate uint64_t pfn_eaddr;
7850Sstevel@tonic-gate uint_t prot;
7860Sstevel@tonic-gate size_t len;
7870Sstevel@tonic-gate uint_t change;
7880Sstevel@tonic-gate
7890Sstevel@tonic-gate if (prom_debug)
7900Sstevel@tonic-gate prom_printf("\tFilter: in: a=%" PRIx64 ", s=%" PRIx64 "\n",
7910Sstevel@tonic-gate *addr, *size);
7920Sstevel@tonic-gate
7930Sstevel@tonic-gate /*
7940Sstevel@tonic-gate * page zero is required for BIOS.. never make it available
7950Sstevel@tonic-gate */
7960Sstevel@tonic-gate if (*addr == 0) {
7970Sstevel@tonic-gate *addr += MMU_PAGESIZE;
7980Sstevel@tonic-gate *size -= MMU_PAGESIZE;
7990Sstevel@tonic-gate }
8000Sstevel@tonic-gate
8010Sstevel@tonic-gate /*
8023446Smrj * First we trim from the front of the range. Since kbm_probe()
8030Sstevel@tonic-gate * walks ranges in virtual order, but addr/size are physical, we need
8040Sstevel@tonic-gate * to the list until no changes are seen. This deals with the case
8050Sstevel@tonic-gate * where page "p" is mapped at v, page "p + PAGESIZE" is mapped at w
8060Sstevel@tonic-gate * but w < v.
8070Sstevel@tonic-gate */
8080Sstevel@tonic-gate do {
8090Sstevel@tonic-gate change = 0;
8100Sstevel@tonic-gate for (va = KERNEL_TEXT;
8113446Smrj *size > 0 && kbm_probe(&va, &len, &pfn, &prot) != 0;
8120Sstevel@tonic-gate va = next_va) {
8130Sstevel@tonic-gate
8140Sstevel@tonic-gate next_va = va + len;
8153446Smrj pfn_addr = pfn_to_pa(pfn);
8160Sstevel@tonic-gate pfn_eaddr = pfn_addr + len;
8170Sstevel@tonic-gate
8180Sstevel@tonic-gate if (pfn_addr <= *addr && pfn_eaddr > *addr) {
8190Sstevel@tonic-gate change = 1;
8200Sstevel@tonic-gate while (*size > 0 && len > 0) {
8210Sstevel@tonic-gate *addr += MMU_PAGESIZE;
8220Sstevel@tonic-gate *size -= MMU_PAGESIZE;
8230Sstevel@tonic-gate len -= MMU_PAGESIZE;
8240Sstevel@tonic-gate }
8250Sstevel@tonic-gate }
8260Sstevel@tonic-gate }
8270Sstevel@tonic-gate if (change && prom_debug)
8280Sstevel@tonic-gate prom_printf("\t\ttrim: a=%" PRIx64 ", s=%" PRIx64 "\n",
8290Sstevel@tonic-gate *addr, *size);
8300Sstevel@tonic-gate } while (change);
8310Sstevel@tonic-gate
8320Sstevel@tonic-gate /*
8330Sstevel@tonic-gate * Trim pages from the end of the range.
8340Sstevel@tonic-gate */
8350Sstevel@tonic-gate for (va = KERNEL_TEXT;
8363446Smrj *size > 0 && kbm_probe(&va, &len, &pfn, &prot) != 0;
8370Sstevel@tonic-gate va = next_va) {
8380Sstevel@tonic-gate
8390Sstevel@tonic-gate next_va = va + len;
8403446Smrj pfn_addr = pfn_to_pa(pfn);
8410Sstevel@tonic-gate
8420Sstevel@tonic-gate if (pfn_addr >= *addr && pfn_addr < *addr + *size)
8430Sstevel@tonic-gate *size = pfn_addr - *addr;
8440Sstevel@tonic-gate }
8450Sstevel@tonic-gate
8460Sstevel@tonic-gate if (prom_debug)
8470Sstevel@tonic-gate prom_printf("\tFilter out: a=%" PRIx64 ", s=%" PRIx64 "\n",
8480Sstevel@tonic-gate *addr, *size);
8490Sstevel@tonic-gate }
8500Sstevel@tonic-gate
8510Sstevel@tonic-gate static void
kpm_init()8520Sstevel@tonic-gate kpm_init()
8530Sstevel@tonic-gate {
8540Sstevel@tonic-gate struct segkpm_crargs b;
8550Sstevel@tonic-gate
8560Sstevel@tonic-gate /*
8570Sstevel@tonic-gate * These variables were all designed for sfmmu in which segkpm is
8580Sstevel@tonic-gate * mapped using a single pagesize - either 8KB or 4MB. On x86, we
8590Sstevel@tonic-gate * might use 2+ page sizes on a single machine, so none of these
8600Sstevel@tonic-gate * variables have a single correct value. They are set up as if we
8610Sstevel@tonic-gate * always use a 4KB pagesize, which should do no harm. In the long
8620Sstevel@tonic-gate * run, we should get rid of KPM's assumption that only a single
8630Sstevel@tonic-gate * pagesize is used.
8640Sstevel@tonic-gate */
8650Sstevel@tonic-gate kpm_pgshft = MMU_PAGESHIFT;
8660Sstevel@tonic-gate kpm_pgsz = MMU_PAGESIZE;
8670Sstevel@tonic-gate kpm_pgoff = MMU_PAGEOFFSET;
8680Sstevel@tonic-gate kpmp2pshft = 0;
8690Sstevel@tonic-gate kpmpnpgs = 1;
8700Sstevel@tonic-gate ASSERT(((uintptr_t)kpm_vbase & (kpm_pgsz - 1)) == 0);
8710Sstevel@tonic-gate
8720Sstevel@tonic-gate PRM_POINT("about to create segkpm");
8730Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER);
8740Sstevel@tonic-gate
8750Sstevel@tonic-gate if (seg_attach(&kas, kpm_vbase, kpm_size, segkpm) < 0)
8760Sstevel@tonic-gate panic("cannot attach segkpm");
8770Sstevel@tonic-gate
8780Sstevel@tonic-gate b.prot = PROT_READ | PROT_WRITE;
8790Sstevel@tonic-gate b.nvcolors = 1;
8800Sstevel@tonic-gate
8810Sstevel@tonic-gate if (segkpm_create(segkpm, (caddr_t)&b) != 0)
8820Sstevel@tonic-gate panic("segkpm_create segkpm");
8830Sstevel@tonic-gate
8840Sstevel@tonic-gate rw_exit(&kas.a_lock);
8850Sstevel@tonic-gate }
8860Sstevel@tonic-gate
8870Sstevel@tonic-gate /*
8883446Smrj * The debug info page provides enough information to allow external
8893446Smrj * inspectors (e.g. when running under a hypervisor) to bootstrap
8903446Smrj * themselves into allowing full-blown kernel debugging.
8913446Smrj */
8923446Smrj static void
init_debug_info(void)8933446Smrj init_debug_info(void)
8943446Smrj {
8953446Smrj caddr_t mem;
8963446Smrj debug_info_t *di;
8973446Smrj
8983446Smrj #ifndef __lint
8993446Smrj ASSERT(sizeof (debug_info_t) < MMU_PAGESIZE);
9003446Smrj #endif
9013446Smrj
9023446Smrj mem = BOP_ALLOC(bootops, (caddr_t)DEBUG_INFO_VA, MMU_PAGESIZE,
9033446Smrj MMU_PAGESIZE);
9043446Smrj
9053446Smrj if (mem != (caddr_t)DEBUG_INFO_VA)
9063446Smrj panic("BOP_ALLOC() failed");
9073446Smrj bzero(mem, MMU_PAGESIZE);
9083446Smrj
9093446Smrj di = (debug_info_t *)mem;
9103446Smrj
9113446Smrj di->di_magic = DEBUG_INFO_MAGIC;
9123446Smrj di->di_version = DEBUG_INFO_VERSION;
9135084Sjohnlev di->di_modules = (uintptr_t)&modules;
9145084Sjohnlev di->di_s_text = (uintptr_t)s_text;
9155084Sjohnlev di->di_e_text = (uintptr_t)e_text;
9165084Sjohnlev di->di_s_data = (uintptr_t)s_data;
9175084Sjohnlev di->di_e_data = (uintptr_t)e_data;
9185084Sjohnlev di->di_hat_htable_off = offsetof(hat_t, hat_htable);
9195084Sjohnlev di->di_ht_pfn_off = offsetof(htable_t, ht_pfn);
9203446Smrj }
9213446Smrj
9223446Smrj /*
9233446Smrj * Build the memlists and other kernel essential memory system data structures.
9243446Smrj * This is everything at valloc_base.
9250Sstevel@tonic-gate */
9260Sstevel@tonic-gate static void
startup_memlist(void)9270Sstevel@tonic-gate startup_memlist(void)
9280Sstevel@tonic-gate {
9290Sstevel@tonic-gate size_t memlist_sz;
9300Sstevel@tonic-gate size_t memseg_sz;
9310Sstevel@tonic-gate size_t pagehash_sz;
9320Sstevel@tonic-gate size_t pp_sz;
9330Sstevel@tonic-gate uintptr_t va;
9340Sstevel@tonic-gate size_t len;
9350Sstevel@tonic-gate uint_t prot;
9360Sstevel@tonic-gate pfn_t pfn;
9370Sstevel@tonic-gate int memblocks;
9389940SVikram.Hegde@Sun.COM pfn_t rsvd_high_pfn;
9399940SVikram.Hegde@Sun.COM pgcnt_t rsvd_pgcnt;
9409940SVikram.Hegde@Sun.COM size_t rsvdmemlist_sz;
9419940SVikram.Hegde@Sun.COM int rsvdmemblocks;
9420Sstevel@tonic-gate caddr_t pagecolor_mem;
9430Sstevel@tonic-gate size_t pagecolor_memsz;
9440Sstevel@tonic-gate caddr_t page_ctrs_mem;
9450Sstevel@tonic-gate size_t page_ctrs_size;
9464878Sblakej size_t pse_table_alloc_size;
9470Sstevel@tonic-gate struct memlist *current;
9480Sstevel@tonic-gate extern void startup_build_mem_nodes(struct memlist *);
9490Sstevel@tonic-gate
9500Sstevel@tonic-gate /* XX64 fix these - they should be in include files */
9510Sstevel@tonic-gate extern size_t page_coloring_init(uint_t, int, int);
9520Sstevel@tonic-gate extern void page_coloring_setup(caddr_t);
9530Sstevel@tonic-gate
9540Sstevel@tonic-gate PRM_POINT("startup_memlist() starting...");
9550Sstevel@tonic-gate
9560Sstevel@tonic-gate /*
9570Sstevel@tonic-gate * Use leftover large page nucleus text/data space for loadable modules.
9580Sstevel@tonic-gate * Use at most MODTEXT/MODDATA.
9590Sstevel@tonic-gate */
9603446Smrj len = kbm_nucleus_size;
9613446Smrj ASSERT(len > MMU_PAGESIZE);
9620Sstevel@tonic-gate
9633446Smrj moddata = (caddr_t)ROUND_UP_PAGE(e_data);
9643446Smrj e_moddata = (caddr_t)P2ROUNDUP((uintptr_t)e_data, (uintptr_t)len);
9653446Smrj if (e_moddata - moddata > MODDATA)
9663446Smrj e_moddata = moddata + MODDATA;
9670Sstevel@tonic-gate
9683446Smrj modtext = (caddr_t)ROUND_UP_PAGE(e_text);
9693446Smrj e_modtext = (caddr_t)P2ROUNDUP((uintptr_t)e_text, (uintptr_t)len);
9703446Smrj if (e_modtext - modtext > MODTEXT)
9713446Smrj e_modtext = modtext + MODTEXT;
9720Sstevel@tonic-gate
9730Sstevel@tonic-gate econtig = e_moddata;
9740Sstevel@tonic-gate
9750Sstevel@tonic-gate PRM_DEBUG(modtext);
9760Sstevel@tonic-gate PRM_DEBUG(e_modtext);
9770Sstevel@tonic-gate PRM_DEBUG(moddata);
9780Sstevel@tonic-gate PRM_DEBUG(e_moddata);
9790Sstevel@tonic-gate PRM_DEBUG(econtig);
9800Sstevel@tonic-gate
9810Sstevel@tonic-gate /*
9823446Smrj * Examine the boot loader physical memory map to find out:
9830Sstevel@tonic-gate * - total memory in system - physinstalled
9840Sstevel@tonic-gate * - the max physical address - physmax
9853446Smrj * - the number of discontiguous segments of memory.
9860Sstevel@tonic-gate */
9870Sstevel@tonic-gate if (prom_debug)
9883446Smrj print_memlist("boot physinstalled",
9890Sstevel@tonic-gate bootops->boot_mem->physinstalled);
99012004Sjiang.liu@intel.com installed_top_size_ex(bootops->boot_mem->physinstalled, &physmax,
9910Sstevel@tonic-gate &physinstalled, &memblocks);
9920Sstevel@tonic-gate PRM_DEBUG(physmax);
9930Sstevel@tonic-gate PRM_DEBUG(physinstalled);
9940Sstevel@tonic-gate PRM_DEBUG(memblocks);
9950Sstevel@tonic-gate
9960Sstevel@tonic-gate /*
99712004Sjiang.liu@intel.com * Compute maximum physical address for memory DR operations.
99812004Sjiang.liu@intel.com * Memory DR operations are unsupported on xpv or 32bit OSes.
99912004Sjiang.liu@intel.com */
100012004Sjiang.liu@intel.com #ifdef __amd64
100112004Sjiang.liu@intel.com if (plat_dr_support_memory()) {
100212004Sjiang.liu@intel.com if (plat_dr_physmax == 0) {
100312004Sjiang.liu@intel.com uint_t pabits = UINT_MAX;
100412004Sjiang.liu@intel.com
100512004Sjiang.liu@intel.com cpuid_get_addrsize(CPU, &pabits, NULL);
100612004Sjiang.liu@intel.com plat_dr_physmax = btop(1ULL << pabits);
100712004Sjiang.liu@intel.com }
100812004Sjiang.liu@intel.com if (plat_dr_physmax > PHYSMEM_MAX64)
100912004Sjiang.liu@intel.com plat_dr_physmax = PHYSMEM_MAX64;
101012004Sjiang.liu@intel.com } else
101112004Sjiang.liu@intel.com #endif
101212004Sjiang.liu@intel.com plat_dr_physmax = 0;
101312004Sjiang.liu@intel.com
101412004Sjiang.liu@intel.com /*
10159940SVikram.Hegde@Sun.COM * Examine the bios reserved memory to find out:
10169940SVikram.Hegde@Sun.COM * - the number of discontiguous segments of memory.
10179940SVikram.Hegde@Sun.COM */
10189940SVikram.Hegde@Sun.COM if (prom_debug)
10199940SVikram.Hegde@Sun.COM print_memlist("boot reserved mem",
10209940SVikram.Hegde@Sun.COM bootops->boot_mem->rsvdmem);
102112004Sjiang.liu@intel.com installed_top_size_ex(bootops->boot_mem->rsvdmem, &rsvd_high_pfn,
10229940SVikram.Hegde@Sun.COM &rsvd_pgcnt, &rsvdmemblocks);
10239940SVikram.Hegde@Sun.COM PRM_DEBUG(rsvd_high_pfn);
10249940SVikram.Hegde@Sun.COM PRM_DEBUG(rsvd_pgcnt);
10259940SVikram.Hegde@Sun.COM PRM_DEBUG(rsvdmemblocks);
10269940SVikram.Hegde@Sun.COM
10279940SVikram.Hegde@Sun.COM /*
10280Sstevel@tonic-gate * Initialize hat's mmu parameters.
10290Sstevel@tonic-gate * Check for enforce-prot-exec in boot environment. It's used to
10300Sstevel@tonic-gate * enable/disable support for the page table entry NX bit.
10310Sstevel@tonic-gate * The default is to enforce PROT_EXEC on processors that support NX.
10320Sstevel@tonic-gate * Boot seems to round up the "len", but 8 seems to be big enough.
10330Sstevel@tonic-gate */
10340Sstevel@tonic-gate mmu_init();
10350Sstevel@tonic-gate
10360Sstevel@tonic-gate #ifdef __i386
10370Sstevel@tonic-gate /*
10380Sstevel@tonic-gate * physmax is lowered if there is more memory than can be
10390Sstevel@tonic-gate * physically addressed in 32 bit (PAE/non-PAE) modes.
10400Sstevel@tonic-gate */
10410Sstevel@tonic-gate if (mmu.pae_hat) {
10420Sstevel@tonic-gate if (PFN_ABOVE64G(physmax)) {
10430Sstevel@tonic-gate physinstalled -= (physmax - (PFN_64G - 1));
10440Sstevel@tonic-gate physmax = PFN_64G - 1;
10450Sstevel@tonic-gate }
10460Sstevel@tonic-gate } else {
10470Sstevel@tonic-gate if (PFN_ABOVE4G(physmax)) {
10480Sstevel@tonic-gate physinstalled -= (physmax - (PFN_4G - 1));
10490Sstevel@tonic-gate physmax = PFN_4G - 1;
10500Sstevel@tonic-gate }
10510Sstevel@tonic-gate }
10520Sstevel@tonic-gate #endif
10530Sstevel@tonic-gate
10540Sstevel@tonic-gate startup_build_mem_nodes(bootops->boot_mem->physinstalled);
10550Sstevel@tonic-gate
10560Sstevel@tonic-gate if (BOP_GETPROPLEN(bootops, "enforce-prot-exec") >= 0) {
10570Sstevel@tonic-gate int len = BOP_GETPROPLEN(bootops, "enforce-prot-exec");
10580Sstevel@tonic-gate char value[8];
10590Sstevel@tonic-gate
10600Sstevel@tonic-gate if (len < 8)
10610Sstevel@tonic-gate (void) BOP_GETPROP(bootops, "enforce-prot-exec", value);
10620Sstevel@tonic-gate else
10630Sstevel@tonic-gate (void) strcpy(value, "");
10640Sstevel@tonic-gate if (strcmp(value, "off") == 0)
10650Sstevel@tonic-gate mmu.pt_nx = 0;
10660Sstevel@tonic-gate }
10670Sstevel@tonic-gate PRM_DEBUG(mmu.pt_nx);
10680Sstevel@tonic-gate
10690Sstevel@tonic-gate /*
10700Sstevel@tonic-gate * We will need page_t's for every page in the system, except for
10710Sstevel@tonic-gate * memory mapped at or above above the start of the kernel text segment.
10720Sstevel@tonic-gate *
10730Sstevel@tonic-gate * pages above e_modtext are attributed to kernel debugger (obp_pages)
10740Sstevel@tonic-gate */
10750Sstevel@tonic-gate npages = physinstalled - 1; /* avail_filter() skips page 0, so "- 1" */
10760Sstevel@tonic-gate obp_pages = 0;
10770Sstevel@tonic-gate va = KERNEL_TEXT;
10783446Smrj while (kbm_probe(&va, &len, &pfn, &prot) != 0) {
10790Sstevel@tonic-gate npages -= len >> MMU_PAGESHIFT;
10800Sstevel@tonic-gate if (va >= (uintptr_t)e_moddata)
10810Sstevel@tonic-gate obp_pages += len >> MMU_PAGESHIFT;
10820Sstevel@tonic-gate va += len;
10830Sstevel@tonic-gate }
10840Sstevel@tonic-gate PRM_DEBUG(npages);
10850Sstevel@tonic-gate PRM_DEBUG(obp_pages);
10860Sstevel@tonic-gate
10870Sstevel@tonic-gate /*
10884828Sjosephb * If physmem is patched to be non-zero, use it instead of the computed
10894828Sjosephb * value unless it is larger than the actual amount of memory on hand.
10900Sstevel@tonic-gate */
10911417Skchow if (physmem == 0 || physmem > npages) {
10920Sstevel@tonic-gate physmem = npages;
10931417Skchow } else if (physmem < npages) {
10941479Skchow orig_npages = npages;
10950Sstevel@tonic-gate npages = physmem;
10961417Skchow }
10970Sstevel@tonic-gate PRM_DEBUG(physmem);
10980Sstevel@tonic-gate
10990Sstevel@tonic-gate /*
11000Sstevel@tonic-gate * We now compute the sizes of all the initial allocations for
11010Sstevel@tonic-gate * structures the kernel needs in order do kmem_alloc(). These
11020Sstevel@tonic-gate * include:
11030Sstevel@tonic-gate * memsegs
11040Sstevel@tonic-gate * memlists
11050Sstevel@tonic-gate * page hash table
11060Sstevel@tonic-gate * page_t's
11070Sstevel@tonic-gate * page coloring data structs
11080Sstevel@tonic-gate */
11090Sstevel@tonic-gate memseg_sz = sizeof (struct memseg) * (memblocks + POSS_NEW_FRAGMENTS);
11100Sstevel@tonic-gate ADD_TO_ALLOCATIONS(memseg_base, memseg_sz);
11110Sstevel@tonic-gate PRM_DEBUG(memseg_sz);
11120Sstevel@tonic-gate
11130Sstevel@tonic-gate /*
11143446Smrj * Reserve space for memlists. There's no real good way to know exactly
11153446Smrj * how much room we'll need, but this should be a good upper bound.
11160Sstevel@tonic-gate */
11170Sstevel@tonic-gate memlist_sz = ROUND_UP_PAGE(2 * sizeof (struct memlist) *
11180Sstevel@tonic-gate (memblocks + POSS_NEW_FRAGMENTS));
11190Sstevel@tonic-gate ADD_TO_ALLOCATIONS(memlist, memlist_sz);
11200Sstevel@tonic-gate PRM_DEBUG(memlist_sz);
11210Sstevel@tonic-gate
11220Sstevel@tonic-gate /*
11239940SVikram.Hegde@Sun.COM * Reserve space for bios reserved memlists.
11249940SVikram.Hegde@Sun.COM */
11259940SVikram.Hegde@Sun.COM rsvdmemlist_sz = ROUND_UP_PAGE(2 * sizeof (struct memlist) *
11269940SVikram.Hegde@Sun.COM (rsvdmemblocks + POSS_NEW_FRAGMENTS));
11279940SVikram.Hegde@Sun.COM ADD_TO_ALLOCATIONS(bios_rsvd, rsvdmemlist_sz);
11289940SVikram.Hegde@Sun.COM PRM_DEBUG(rsvdmemlist_sz);
11299940SVikram.Hegde@Sun.COM
113012230SFrank.Rival@oracle.com /* LINTED */
113112230SFrank.Rival@oracle.com ASSERT(P2SAMEHIGHBIT((1 << PP_SHIFT), sizeof (struct page)));
11329940SVikram.Hegde@Sun.COM /*
11330Sstevel@tonic-gate * The page structure hash table size is a power of 2
11340Sstevel@tonic-gate * such that the average hash chain length is PAGE_HASHAVELEN.
11350Sstevel@tonic-gate */
11360Sstevel@tonic-gate page_hashsz = npages / PAGE_HASHAVELEN;
113712230SFrank.Rival@oracle.com page_hashsz_shift = highbit(page_hashsz);
113812230SFrank.Rival@oracle.com page_hashsz = 1 << page_hashsz_shift;
11390Sstevel@tonic-gate pagehash_sz = sizeof (struct page *) * page_hashsz;
11400Sstevel@tonic-gate ADD_TO_ALLOCATIONS(page_hash, pagehash_sz);
11410Sstevel@tonic-gate PRM_DEBUG(pagehash_sz);
11420Sstevel@tonic-gate
11430Sstevel@tonic-gate /*
11443446Smrj * Set aside room for the page structures themselves.
11450Sstevel@tonic-gate */
11463446Smrj PRM_DEBUG(npages);
11473446Smrj pp_sz = sizeof (struct page) * npages;
11480Sstevel@tonic-gate ADD_TO_ALLOCATIONS(pp_base, pp_sz);
11490Sstevel@tonic-gate PRM_DEBUG(pp_sz);
11500Sstevel@tonic-gate
11510Sstevel@tonic-gate /*
11520Sstevel@tonic-gate * determine l2 cache info and memory size for page coloring
11530Sstevel@tonic-gate */
11540Sstevel@tonic-gate (void) getl2cacheinfo(CPU,
11550Sstevel@tonic-gate &l2cache_sz, &l2cache_linesz, &l2cache_assoc);
11560Sstevel@tonic-gate pagecolor_memsz =
11570Sstevel@tonic-gate page_coloring_init(l2cache_sz, l2cache_linesz, l2cache_assoc);
11580Sstevel@tonic-gate ADD_TO_ALLOCATIONS(pagecolor_mem, pagecolor_memsz);
11590Sstevel@tonic-gate PRM_DEBUG(pagecolor_memsz);
11600Sstevel@tonic-gate
11610Sstevel@tonic-gate page_ctrs_size = page_ctrs_sz();
11620Sstevel@tonic-gate ADD_TO_ALLOCATIONS(page_ctrs_mem, page_ctrs_size);
11630Sstevel@tonic-gate PRM_DEBUG(page_ctrs_size);
11640Sstevel@tonic-gate
11654878Sblakej /*
11664878Sblakej * Allocate the array that protects pp->p_selock.
11674878Sblakej */
11684878Sblakej pse_shift = size_pse_array(physmem, max_ncpus);
11694878Sblakej pse_table_size = 1 << pse_shift;
11704878Sblakej pse_table_alloc_size = pse_table_size * sizeof (pad_mutex_t);
11714878Sblakej ADD_TO_ALLOCATIONS(pse_mutex, pse_table_alloc_size);
11724878Sblakej
11733446Smrj #if defined(__amd64)
11743446Smrj valloc_sz = ROUND_UP_LPAGE(valloc_sz);
11753446Smrj valloc_base = VALLOC_BASE;
11764828Sjosephb
11774828Sjosephb /*
11784828Sjosephb * The default values of VALLOC_BASE and SEGKPM_BASE should work
11794828Sjosephb * for values of physmax up to 1 Terabyte. They need adjusting when
118011721SKit.Chow@Sun.COM * memory is at addresses above 1 TB. When adjusted, segkpm_base must
118111721SKit.Chow@Sun.COM * be aligned on KERNEL_REDZONE_SIZE boundary (span of top level pte).
11824828Sjosephb */
118312004Sjiang.liu@intel.com if (physmax + 1 > mmu_btop(TERABYTE) ||
118412004Sjiang.liu@intel.com plat_dr_physmax > mmu_btop(TERABYTE)) {
11854828Sjosephb uint64_t kpm_resv_amount = mmu_ptob(physmax + 1);
11864828Sjosephb
118712004Sjiang.liu@intel.com if (kpm_resv_amount < mmu_ptob(plat_dr_physmax)) {
118812004Sjiang.liu@intel.com kpm_resv_amount = mmu_ptob(plat_dr_physmax);
118912004Sjiang.liu@intel.com }
119012004Sjiang.liu@intel.com
119111721SKit.Chow@Sun.COM segkpm_base = -(P2ROUNDUP((2 * kpm_resv_amount),
119211721SKit.Chow@Sun.COM KERNEL_REDZONE_SIZE)); /* down from top VA */
11934828Sjosephb
11944828Sjosephb /* make sure we leave some space for user apps above hole */
11954828Sjosephb segkpm_base = MAX(segkpm_base, AMD64_VA_HOLE_END + TERABYTE);
11964828Sjosephb if (segkpm_base > SEGKPM_BASE)
11974828Sjosephb segkpm_base = SEGKPM_BASE;
11984828Sjosephb PRM_DEBUG(segkpm_base);
11994828Sjosephb
120011721SKit.Chow@Sun.COM valloc_base = segkpm_base + P2ROUNDUP(kpm_resv_amount, ONE_GIG);
120111721SKit.Chow@Sun.COM if (valloc_base < segkpm_base)
120211721SKit.Chow@Sun.COM panic("not enough kernel VA to support memory size");
12034828Sjosephb PRM_DEBUG(valloc_base);
12044828Sjosephb }
12053446Smrj #else /* __i386 */
12063446Smrj valloc_base = (uintptr_t)(MISC_VA_BASE - valloc_sz);
12073446Smrj valloc_base = P2ALIGN(valloc_base, mmu.level_size[1]);
12084828Sjosephb PRM_DEBUG(valloc_base);
12093446Smrj #endif /* __i386 */
12103446Smrj
12110Sstevel@tonic-gate /*
12123446Smrj * do all the initial allocations
12133446Smrj */
12143446Smrj perform_allocations();
12153446Smrj
12163446Smrj /*
12173446Smrj * Build phys_install and phys_avail in kernel memspace.
12183446Smrj * - phys_install should be all memory in the system.
12193446Smrj * - phys_avail is phys_install minus any memory mapped before this
12203446Smrj * point above KERNEL_TEXT.
12213446Smrj */
12223446Smrj current = phys_install = memlist;
12233446Smrj copy_memlist_filter(bootops->boot_mem->physinstalled, ¤t, NULL);
12243446Smrj if ((caddr_t)current > (caddr_t)memlist + memlist_sz)
12253446Smrj panic("physinstalled was too big!");
12263446Smrj if (prom_debug)
12273446Smrj print_memlist("phys_install", phys_install);
12283446Smrj
12293446Smrj phys_avail = current;
12303446Smrj PRM_POINT("Building phys_avail:\n");
12313446Smrj copy_memlist_filter(bootops->boot_mem->physinstalled, ¤t,
12323446Smrj avail_filter);
12333446Smrj if ((caddr_t)current > (caddr_t)memlist + memlist_sz)
12343446Smrj panic("physavail was too big!");
12353446Smrj if (prom_debug)
12363446Smrj print_memlist("phys_avail", phys_avail);
123712004Sjiang.liu@intel.com #ifndef __xpv
123812004Sjiang.liu@intel.com /*
123912004Sjiang.liu@intel.com * Free unused memlist items, which may be used by memory DR driver
124012004Sjiang.liu@intel.com * at runtime.
124112004Sjiang.liu@intel.com */
124212004Sjiang.liu@intel.com if ((caddr_t)current < (caddr_t)memlist + memlist_sz) {
124312004Sjiang.liu@intel.com memlist_free_block((caddr_t)current,
124412004Sjiang.liu@intel.com (caddr_t)memlist + memlist_sz - (caddr_t)current);
124512004Sjiang.liu@intel.com }
124612004Sjiang.liu@intel.com #endif
12473446Smrj
12483446Smrj /*
12499940SVikram.Hegde@Sun.COM * Build bios reserved memspace
12509940SVikram.Hegde@Sun.COM */
12519940SVikram.Hegde@Sun.COM current = bios_rsvd;
12529940SVikram.Hegde@Sun.COM copy_memlist_filter(bootops->boot_mem->rsvdmem, ¤t, NULL);
12539940SVikram.Hegde@Sun.COM if ((caddr_t)current > (caddr_t)bios_rsvd + rsvdmemlist_sz)
12549940SVikram.Hegde@Sun.COM panic("bios_rsvd was too big!");
12559940SVikram.Hegde@Sun.COM if (prom_debug)
12569940SVikram.Hegde@Sun.COM print_memlist("bios_rsvd", bios_rsvd);
125712004Sjiang.liu@intel.com #ifndef __xpv
125812004Sjiang.liu@intel.com /*
125912004Sjiang.liu@intel.com * Free unused memlist items, which may be used by memory DR driver
126012004Sjiang.liu@intel.com * at runtime.
126112004Sjiang.liu@intel.com */
126212004Sjiang.liu@intel.com if ((caddr_t)current < (caddr_t)bios_rsvd + rsvdmemlist_sz) {
126312004Sjiang.liu@intel.com memlist_free_block((caddr_t)current,
126412004Sjiang.liu@intel.com (caddr_t)bios_rsvd + rsvdmemlist_sz - (caddr_t)current);
126512004Sjiang.liu@intel.com }
126612004Sjiang.liu@intel.com #endif
12679940SVikram.Hegde@Sun.COM
12689940SVikram.Hegde@Sun.COM /*
12693446Smrj * setup page coloring
12700Sstevel@tonic-gate */
12713446Smrj page_coloring_setup(pagecolor_mem);
12723446Smrj page_lock_init(); /* currently a no-op */
12733446Smrj
12743446Smrj /*
12753446Smrj * free page list counters
12763446Smrj */
12773446Smrj (void) page_ctrs_alloc(page_ctrs_mem);
12783446Smrj
12793446Smrj /*
12806880Sdv142724 * Size the pcf array based on the number of cpus in the box at
12816880Sdv142724 * boot time.
12826880Sdv142724 */
12836880Sdv142724
12846880Sdv142724 pcf_init();
12856880Sdv142724
12866880Sdv142724 /*
12873446Smrj * Initialize the page structures from the memory lists.
12883446Smrj */
12893446Smrj availrmem_initial = availrmem = freemem = 0;
12903446Smrj PRM_POINT("Calling kphysm_init()...");
12913446Smrj npages = kphysm_init(pp_base, npages);
12923446Smrj PRM_POINT("kphysm_init() done");
12933446Smrj PRM_DEBUG(npages);
12943446Smrj
12953446Smrj init_debug_info();
12963446Smrj
12973446Smrj /*
12983446Smrj * Now that page_t's have been initialized, remove all the
12993446Smrj * initial allocation pages from the kernel free page lists.
13003446Smrj */
13013446Smrj boot_mapin((caddr_t)valloc_base, valloc_sz);
13025460Sjosephb boot_mapin((caddr_t)MISC_VA_BASE, MISC_VA_SIZE);
13033446Smrj PRM_POINT("startup_memlist() done");
13043446Smrj
13053446Smrj PRM_DEBUG(valloc_sz);
13064426Saguzovsk
13074748Saguzovsk #if defined(__amd64)
13084748Saguzovsk if ((availrmem >> (30 - MMU_PAGESHIFT)) >=
13094748Saguzovsk textrepl_min_gb && l2cache_sz <= 2 << 20) {
13104748Saguzovsk extern size_t textrepl_size_thresh;
13114426Saguzovsk textrepl_size_thresh = (16 << 20) - 1;
13124426Saguzovsk }
13134748Saguzovsk #endif
13143446Smrj }
13153446Smrj
13163446Smrj /*
13173446Smrj * Layout the kernel's part of address space and initialize kmem allocator.
13183446Smrj */
13193446Smrj static void
startup_kmem(void)13203446Smrj startup_kmem(void)
13213446Smrj {
13223717Sdp78419 extern void page_set_colorequiv_arr(void);
13233717Sdp78419
13243446Smrj PRM_POINT("startup_kmem() starting...");
13250Sstevel@tonic-gate
13260Sstevel@tonic-gate #if defined(__amd64)
13270Sstevel@tonic-gate if (eprom_kernelbase && eprom_kernelbase != KERNELBASE)
13280Sstevel@tonic-gate cmn_err(CE_NOTE, "!kernelbase cannot be changed on 64-bit "
13290Sstevel@tonic-gate "systems.");
13304828Sjosephb kernelbase = segkpm_base - KERNEL_REDZONE_SIZE;
13310Sstevel@tonic-gate core_base = (uintptr_t)COREHEAP_BASE;
13323446Smrj core_size = (size_t)MISC_VA_BASE - COREHEAP_BASE;
13330Sstevel@tonic-gate #else /* __i386 */
13340Sstevel@tonic-gate /*
13350Sstevel@tonic-gate * We configure kernelbase based on:
13360Sstevel@tonic-gate *
13370Sstevel@tonic-gate * 1. user specified kernelbase via eeprom command. Value cannot exceed
13380Sstevel@tonic-gate * KERNELBASE_MAX. we large page align eprom_kernelbase
13390Sstevel@tonic-gate *
13400Sstevel@tonic-gate * 2. Default to KERNELBASE and adjust to 2X less the size for page_t.
13410Sstevel@tonic-gate * On large memory systems we must lower kernelbase to allow
13420Sstevel@tonic-gate * enough room for page_t's for all of memory.
13430Sstevel@tonic-gate *
13440Sstevel@tonic-gate * The value set here, might be changed a little later.
13450Sstevel@tonic-gate */
13460Sstevel@tonic-gate if (eprom_kernelbase) {
13470Sstevel@tonic-gate kernelbase = eprom_kernelbase & mmu.level_mask[1];
13480Sstevel@tonic-gate if (kernelbase > KERNELBASE_MAX)
13490Sstevel@tonic-gate kernelbase = KERNELBASE_MAX;
13500Sstevel@tonic-gate } else {
13510Sstevel@tonic-gate kernelbase = (uintptr_t)KERNELBASE;
13520Sstevel@tonic-gate kernelbase -= ROUND_UP_4MEG(2 * valloc_sz);
13530Sstevel@tonic-gate }
13540Sstevel@tonic-gate ASSERT((kernelbase & mmu.level_offset[1]) == 0);
13553446Smrj core_base = valloc_base;
13560Sstevel@tonic-gate core_size = 0;
13573446Smrj #endif /* __i386 */
13580Sstevel@tonic-gate
13590Sstevel@tonic-gate PRM_DEBUG(core_base);
13600Sstevel@tonic-gate PRM_DEBUG(core_size);
13613446Smrj PRM_DEBUG(kernelbase);
13620Sstevel@tonic-gate
13634828Sjosephb #if defined(__i386)
13644828Sjosephb segkp_fromheap = 1;
13654828Sjosephb #endif /* __i386 */
13663446Smrj
13673446Smrj ekernelheap = (char *)core_base;
13683446Smrj PRM_DEBUG(ekernelheap);
13690Sstevel@tonic-gate
13700Sstevel@tonic-gate /*
13710Sstevel@tonic-gate * Now that we know the real value of kernelbase,
13720Sstevel@tonic-gate * update variables that were initialized with a value of
13730Sstevel@tonic-gate * KERNELBASE (in common/conf/param.c).
13740Sstevel@tonic-gate *
13750Sstevel@tonic-gate * XXX The problem with this sort of hackery is that the
13760Sstevel@tonic-gate * compiler just may feel like putting the const declarations
13770Sstevel@tonic-gate * (in param.c) into the .text section. Perhaps they should
13780Sstevel@tonic-gate * just be declared as variables there?
13790Sstevel@tonic-gate */
13800Sstevel@tonic-gate
13810Sstevel@tonic-gate *(uintptr_t *)&_kernelbase = kernelbase;
13820Sstevel@tonic-gate *(uintptr_t *)&_userlimit = kernelbase;
13834875Sjosephb #if defined(__amd64)
13844875Sjosephb *(uintptr_t *)&_userlimit -= KERNELBASE - USERLIMIT;
13854875Sjosephb #else
13860Sstevel@tonic-gate *(uintptr_t *)&_userlimit32 = _userlimit;
13870Sstevel@tonic-gate #endif
13880Sstevel@tonic-gate PRM_DEBUG(_kernelbase);
13890Sstevel@tonic-gate PRM_DEBUG(_userlimit);
13900Sstevel@tonic-gate PRM_DEBUG(_userlimit32);
13910Sstevel@tonic-gate
13924828Sjosephb layout_kernel_va();
13934828Sjosephb
13944828Sjosephb #if defined(__i386)
13954828Sjosephb /*
13964828Sjosephb * If segmap is too large we can push the bottom of the kernel heap
13974828Sjosephb * higher than the base. Or worse, it could exceed the top of the
13984828Sjosephb * VA space entirely, causing it to wrap around.
13994828Sjosephb */
14004828Sjosephb if (kernelheap >= ekernelheap || (uintptr_t)kernelheap < kernelbase)
14014828Sjosephb panic("too little address space available for kernelheap,"
14024828Sjosephb " use eeprom for lower kernelbase or smaller segmapsize");
14034828Sjosephb #endif /* __i386 */
14044828Sjosephb
14050Sstevel@tonic-gate /*
14060Sstevel@tonic-gate * Initialize the kernel heap. Note 3rd argument must be > 1st.
14070Sstevel@tonic-gate */
14084828Sjosephb kernelheap_init(kernelheap, ekernelheap,
14094828Sjosephb kernelheap + MMU_PAGESIZE,
14103446Smrj (void *)core_base, (void *)(core_base + core_size));
14110Sstevel@tonic-gate
14125084Sjohnlev #if defined(__xpv)
14135084Sjohnlev /*
14145084Sjohnlev * Link pending events struct into cpu struct
14155084Sjohnlev */
14165084Sjohnlev CPU->cpu_m.mcpu_evt_pend = &cpu0_evt_data;
14175084Sjohnlev #endif
14180Sstevel@tonic-gate /*
14190Sstevel@tonic-gate * Initialize kernel memory allocator.
14200Sstevel@tonic-gate */
14210Sstevel@tonic-gate kmem_init();
14220Sstevel@tonic-gate
14230Sstevel@tonic-gate /*
14243717Sdp78419 * Factor in colorequiv to check additional 'equivalent' bins
14253717Sdp78419 */
14263717Sdp78419 page_set_colorequiv_arr();
14273717Sdp78419
14283717Sdp78419 /*
14290Sstevel@tonic-gate * print this out early so that we know what's going on
14300Sstevel@tonic-gate */
143112826Skuriakose.kuruvilla@oracle.com print_x86_featureset(x86_featureset);
14320Sstevel@tonic-gate
14330Sstevel@tonic-gate /*
14340Sstevel@tonic-gate * Initialize bp_mapin().
14350Sstevel@tonic-gate */
14360Sstevel@tonic-gate bp_init(MMU_PAGESIZE, HAT_STORECACHING_OK);
14370Sstevel@tonic-gate
14381479Skchow /*
14391479Skchow * orig_npages is non-zero if physmem has been configured for less
14401479Skchow * than the available memory.
14411479Skchow */
14421479Skchow if (orig_npages) {
14434828Sjosephb cmn_err(CE_WARN, "!%slimiting physmem to 0x%lx of 0x%lx pages",
14444828Sjosephb (npages == PHYSMEM ? "Due to virtual address space " : ""),
14454828Sjosephb npages, orig_npages);
14461479Skchow }
14470Sstevel@tonic-gate #if defined(__i386)
14480Sstevel@tonic-gate if (eprom_kernelbase && (eprom_kernelbase != kernelbase))
14490Sstevel@tonic-gate cmn_err(CE_WARN, "kernelbase value, User specified 0x%lx, "
14500Sstevel@tonic-gate "System using 0x%lx",
14510Sstevel@tonic-gate (uintptr_t)eprom_kernelbase, (uintptr_t)kernelbase);
14520Sstevel@tonic-gate #endif
14530Sstevel@tonic-gate
14540Sstevel@tonic-gate #ifdef KERNELBASE_ABI_MIN
14550Sstevel@tonic-gate if (kernelbase < (uintptr_t)KERNELBASE_ABI_MIN) {
14560Sstevel@tonic-gate cmn_err(CE_NOTE, "!kernelbase set to 0x%lx, system is not "
14570Sstevel@tonic-gate "i386 ABI compliant.", (uintptr_t)kernelbase);
14580Sstevel@tonic-gate }
14590Sstevel@tonic-gate #endif
14600Sstevel@tonic-gate
146112004Sjiang.liu@intel.com #ifndef __xpv
146212004Sjiang.liu@intel.com if (plat_dr_support_memory()) {
146312004Sjiang.liu@intel.com mem_config_init();
146412004Sjiang.liu@intel.com }
146512004Sjiang.liu@intel.com #else /* __xpv */
14665084Sjohnlev /*
14675084Sjohnlev * Some of the xen start information has to be relocated up
14685084Sjohnlev * into the kernel's permanent address space.
14695084Sjohnlev */
14705084Sjohnlev PRM_POINT("calling xen_relocate_start_info()");
14715084Sjohnlev xen_relocate_start_info();
14725084Sjohnlev PRM_POINT("xen_relocate_start_info() done");
14735084Sjohnlev
14745084Sjohnlev /*
14755084Sjohnlev * (Update the vcpu pointer in our cpu structure to point into
14765084Sjohnlev * the relocated shared info.)
14775084Sjohnlev */
14785084Sjohnlev CPU->cpu_m.mcpu_vcpu_info =
14795084Sjohnlev &HYPERVISOR_shared_info->vcpu_info[CPU->cpu_id];
148012004Sjiang.liu@intel.com #endif /* __xpv */
14815084Sjohnlev
14823446Smrj PRM_POINT("startup_kmem() done");
14830Sstevel@tonic-gate }
14840Sstevel@tonic-gate
14855741Smrj #ifndef __xpv
14865741Smrj /*
14875741Smrj * If we have detected that we are running in an HVM environment, we need
14885741Smrj * to prepend the PV driver directory to the module search path.
14895741Smrj */
14905741Smrj #define HVM_MOD_DIR "/platform/i86hvm/kernel"
14915741Smrj static void
update_default_path()14925741Smrj update_default_path()
14935741Smrj {
14945741Smrj char *current, *newpath;
14955741Smrj int newlen;
14965741Smrj
14975741Smrj /*
14985741Smrj * We are about to resync with krtld. krtld will reset its
14995741Smrj * internal module search path iff Solaris has set default_path.
15005741Smrj * We want to be sure we're prepending this new directory to the
15015741Smrj * right search path.
15025741Smrj */
15035741Smrj current = (default_path == NULL) ? kobj_module_path : default_path;
15045741Smrj
150511971SStuart.Maybee@Sun.COM newlen = strlen(HVM_MOD_DIR) + strlen(current) + 2;
15065741Smrj newpath = kmem_alloc(newlen, KM_SLEEP);
15075741Smrj (void) strcpy(newpath, HVM_MOD_DIR);
15085741Smrj (void) strcat(newpath, " ");
15095741Smrj (void) strcat(newpath, current);
15105741Smrj
15115741Smrj default_path = newpath;
15125741Smrj }
15135741Smrj #endif
15145741Smrj
15150Sstevel@tonic-gate static void
startup_modules(void)15160Sstevel@tonic-gate startup_modules(void)
15170Sstevel@tonic-gate {
15187720SKen.Erickson@Sun.COM int cnt;
15190Sstevel@tonic-gate extern void prom_setup(void);
15207720SKen.Erickson@Sun.COM int32_t v, h;
15217720SKen.Erickson@Sun.COM char d[11];
15227720SKen.Erickson@Sun.COM char *cp;
15237532SSean.Ye@Sun.COM cmi_hdl_t hdl;
15240Sstevel@tonic-gate
15250Sstevel@tonic-gate PRM_POINT("startup_modules() starting...");
15265084Sjohnlev
15275084Sjohnlev #ifndef __xpv
15280Sstevel@tonic-gate /*
15290Sstevel@tonic-gate * Initialize ten-micro second timer so that drivers will
15300Sstevel@tonic-gate * not get short changed in their init phase. This was
15310Sstevel@tonic-gate * not getting called until clkinit which, on fast cpu's
15320Sstevel@tonic-gate * caused the drv_usecwait to be way too short.
15330Sstevel@tonic-gate */
15340Sstevel@tonic-gate microfind();
15355741Smrj
15369000SStuart.Maybee@Sun.COM if (get_hwenv() == HW_XEN_HVM)
15375741Smrj update_default_path();
15385084Sjohnlev #endif
15390Sstevel@tonic-gate
15400Sstevel@tonic-gate /*
15410Sstevel@tonic-gate * Read the GMT lag from /etc/rtc_config.
15420Sstevel@tonic-gate */
15433446Smrj sgmtl(process_rtc_config_file());
15440Sstevel@tonic-gate
15450Sstevel@tonic-gate /*
15460Sstevel@tonic-gate * Calculate default settings of system parameters based upon
15470Sstevel@tonic-gate * maxusers, yet allow to be overridden via the /etc/system file.
15480Sstevel@tonic-gate */
15490Sstevel@tonic-gate param_calc(0);
15500Sstevel@tonic-gate
15510Sstevel@tonic-gate mod_setup();
15520Sstevel@tonic-gate
15530Sstevel@tonic-gate /*
15540Sstevel@tonic-gate * Initialize system parameters.
15550Sstevel@tonic-gate */
15560Sstevel@tonic-gate param_init();
15570Sstevel@tonic-gate
15580Sstevel@tonic-gate /*
15592712Snn35248 * Initialize the default brands
15602712Snn35248 */
15612712Snn35248 brand_init();
15622712Snn35248
15632712Snn35248 /*
15640Sstevel@tonic-gate * maxmem is the amount of physical memory we're playing with.
15650Sstevel@tonic-gate */
15660Sstevel@tonic-gate maxmem = physmem;
15670Sstevel@tonic-gate
15680Sstevel@tonic-gate /*
15690Sstevel@tonic-gate * Initialize segment management stuff.
15700Sstevel@tonic-gate */
15710Sstevel@tonic-gate seg_init();
15720Sstevel@tonic-gate
15730Sstevel@tonic-gate if (modload("fs", "specfs") == -1)
15740Sstevel@tonic-gate halt("Can't load specfs");
15750Sstevel@tonic-gate
15760Sstevel@tonic-gate if (modload("fs", "devfs") == -1)
15770Sstevel@tonic-gate halt("Can't load devfs");
15780Sstevel@tonic-gate
15792621Sllai1 if (modload("fs", "dev") == -1)
15802621Sllai1 halt("Can't load dev");
15812621Sllai1
158211173SJonathan.Adams@Sun.COM if (modload("fs", "procfs") == -1)
158311173SJonathan.Adams@Sun.COM halt("Can't load procfs");
158411173SJonathan.Adams@Sun.COM
15851676Sjpk (void) modloadonly("sys", "lbl_edition");
15861676Sjpk
15870Sstevel@tonic-gate dispinit();
15880Sstevel@tonic-gate
15890Sstevel@tonic-gate /*
15900Sstevel@tonic-gate * This is needed here to initialize hw_serial[] for cluster booting.
15910Sstevel@tonic-gate */
15928662SJordan.Vaughan@Sun.com if ((h = set_soft_hostid()) == HW_INVALID_HOSTID) {
15937720SKen.Erickson@Sun.COM cmn_err(CE_WARN, "Unable to set hostid");
15948662SJordan.Vaughan@Sun.com } else {
15957720SKen.Erickson@Sun.COM for (v = h, cnt = 0; cnt < 10; cnt++) {
15968662SJordan.Vaughan@Sun.com d[cnt] = (char)(v % 10);
15977720SKen.Erickson@Sun.COM v /= 10;
15987720SKen.Erickson@Sun.COM if (v == 0)
15997720SKen.Erickson@Sun.COM break;
16007720SKen.Erickson@Sun.COM }
16017720SKen.Erickson@Sun.COM for (cp = hw_serial; cnt >= 0; cnt--)
16027720SKen.Erickson@Sun.COM *cp++ = d[cnt] + '0';
16037720SKen.Erickson@Sun.COM *cp = 0;
16047720SKen.Erickson@Sun.COM }
16050Sstevel@tonic-gate
16060Sstevel@tonic-gate /* Read cluster configuration data. */
16070Sstevel@tonic-gate clconf_init();
16080Sstevel@tonic-gate
16095084Sjohnlev #if defined(__xpv)
161010175SStuart.Maybee@Sun.COM (void) ec_init();
16115084Sjohnlev gnttab_init();
16125084Sjohnlev (void) xs_early_init();
16135084Sjohnlev #endif /* __xpv */
16145084Sjohnlev
16150Sstevel@tonic-gate /*
16160Sstevel@tonic-gate * Create a kernel device tree. First, create rootnex and
16170Sstevel@tonic-gate * then invoke bus specific code to probe devices.
16180Sstevel@tonic-gate */
16190Sstevel@tonic-gate setup_ddi();
16201414Scindi
162110942STom.Pothier@Sun.COM #ifdef __xpv
162210942STom.Pothier@Sun.COM if (DOMAIN_IS_INITDOMAIN(xen_info))
162310942STom.Pothier@Sun.COM #endif
162410942STom.Pothier@Sun.COM {
162510942STom.Pothier@Sun.COM /*
162610942STom.Pothier@Sun.COM * Load the System Management BIOS into the global ksmbios
162710942STom.Pothier@Sun.COM * handle, if an SMBIOS is present on this system.
162810942STom.Pothier@Sun.COM */
162910942STom.Pothier@Sun.COM ksmbios = smbios_open(NULL, SMB_VERSION, ksmbios_flags, NULL);
163010942STom.Pothier@Sun.COM }
163110942STom.Pothier@Sun.COM
163210942STom.Pothier@Sun.COM
16337532SSean.Ye@Sun.COM /*
16347532SSean.Ye@Sun.COM * Set up the CPU module subsystem for the boot cpu in the native
16357532SSean.Ye@Sun.COM * case, and all physical cpu resource in the xpv dom0 case.
16367532SSean.Ye@Sun.COM * Modifies the device tree, so this must be done after
16377532SSean.Ye@Sun.COM * setup_ddi().
16387532SSean.Ye@Sun.COM */
16397532SSean.Ye@Sun.COM #ifdef __xpv
16407532SSean.Ye@Sun.COM /*
16417532SSean.Ye@Sun.COM * If paravirtualized and on dom0 then we initialize all physical
16427532SSean.Ye@Sun.COM * cpu handles now; if paravirtualized on a domU then do not
16437532SSean.Ye@Sun.COM * initialize.
16447532SSean.Ye@Sun.COM */
16457532SSean.Ye@Sun.COM if (DOMAIN_IS_INITDOMAIN(xen_info)) {
16467532SSean.Ye@Sun.COM xen_mc_lcpu_cookie_t cpi;
16477532SSean.Ye@Sun.COM
16487532SSean.Ye@Sun.COM for (cpi = xen_physcpu_next(NULL); cpi != NULL;
16497532SSean.Ye@Sun.COM cpi = xen_physcpu_next(cpi)) {
16507532SSean.Ye@Sun.COM if ((hdl = cmi_init(CMI_HDL_SOLARIS_xVM_MCA,
16517532SSean.Ye@Sun.COM xen_physcpu_chipid(cpi), xen_physcpu_coreid(cpi),
16527532SSean.Ye@Sun.COM xen_physcpu_strandid(cpi))) != NULL &&
165312826Skuriakose.kuruvilla@oracle.com is_x86_feature(x86_featureset, X86FSET_MCA))
16545254Sgavinm cmi_mca_init(hdl);
16555254Sgavinm }
16565254Sgavinm }
16577532SSean.Ye@Sun.COM #else
16587532SSean.Ye@Sun.COM /*
16597532SSean.Ye@Sun.COM * Initialize a handle for the boot cpu - others will initialize
16607532SSean.Ye@Sun.COM * as they startup. Do not do this if we know we are in an HVM domU.
16617532SSean.Ye@Sun.COM */
16629000SStuart.Maybee@Sun.COM if ((get_hwenv() != HW_XEN_HVM) &&
16637532SSean.Ye@Sun.COM (hdl = cmi_init(CMI_HDL_NATIVE, cmi_ntv_hwchipid(CPU),
16647532SSean.Ye@Sun.COM cmi_ntv_hwcoreid(CPU), cmi_ntv_hwstrandid(CPU))) != NULL &&
166512826Skuriakose.kuruvilla@oracle.com is_x86_feature(x86_featureset, X86FSET_MCA)) {
16667532SSean.Ye@Sun.COM cmi_mca_init(hdl);
166712004Sjiang.liu@intel.com CPU->cpu_m.mcpu_cmi_hdl = hdl;
166812004Sjiang.liu@intel.com }
16695254Sgavinm #endif /* __xpv */
16701414Scindi
16710Sstevel@tonic-gate /*
16720Sstevel@tonic-gate * Fake a prom tree such that /dev/openprom continues to work
16730Sstevel@tonic-gate */
16743446Smrj PRM_POINT("startup_modules: calling prom_setup...");
16750Sstevel@tonic-gate prom_setup();
16763446Smrj PRM_POINT("startup_modules: done");
16770Sstevel@tonic-gate
16780Sstevel@tonic-gate /*
16790Sstevel@tonic-gate * Load all platform specific modules
16800Sstevel@tonic-gate */
16813446Smrj PRM_POINT("startup_modules: calling psm_modload...");
16820Sstevel@tonic-gate psm_modload();
16830Sstevel@tonic-gate
16840Sstevel@tonic-gate PRM_POINT("startup_modules() done");
16850Sstevel@tonic-gate }
16860Sstevel@tonic-gate
16873446Smrj /*
16883446Smrj * claim a "setaside" boot page for use in the kernel
16893446Smrj */
16903446Smrj page_t *
boot_claim_page(pfn_t pfn)16913446Smrj boot_claim_page(pfn_t pfn)
16920Sstevel@tonic-gate {
16933446Smrj page_t *pp;
16943446Smrj
16953446Smrj pp = page_numtopp_nolock(pfn);
16963446Smrj ASSERT(pp != NULL);
16970Sstevel@tonic-gate
16983446Smrj if (PP_ISBOOTPAGES(pp)) {
16993446Smrj if (pp->p_next != NULL)
17003446Smrj pp->p_next->p_prev = pp->p_prev;
17013446Smrj if (pp->p_prev == NULL)
17023446Smrj bootpages = pp->p_next;
17033446Smrj else
17043446Smrj pp->p_prev->p_next = pp->p_next;
17053446Smrj } else {
17063446Smrj /*
17073446Smrj * htable_attach() expects a base pagesize page
17083446Smrj */
17093446Smrj if (pp->p_szc != 0)
17103446Smrj page_boot_demote(pp);
17113446Smrj pp = page_numtopp(pfn, SE_EXCL);
17123446Smrj }
17133446Smrj return (pp);
17140Sstevel@tonic-gate }
17150Sstevel@tonic-gate
17160Sstevel@tonic-gate /*
17170Sstevel@tonic-gate * Walk through the pagetables looking for pages mapped in by boot. If the
17180Sstevel@tonic-gate * setaside flag is set the pages are expected to be returned to the
17190Sstevel@tonic-gate * kernel later in boot, so we add them to the bootpages list.
17200Sstevel@tonic-gate */
17210Sstevel@tonic-gate static void
protect_boot_range(uintptr_t low,uintptr_t high,int setaside)17220Sstevel@tonic-gate protect_boot_range(uintptr_t low, uintptr_t high, int setaside)
17230Sstevel@tonic-gate {
17240Sstevel@tonic-gate uintptr_t va = low;
17250Sstevel@tonic-gate size_t len;
17260Sstevel@tonic-gate uint_t prot;
17270Sstevel@tonic-gate pfn_t pfn;
17280Sstevel@tonic-gate page_t *pp;
17290Sstevel@tonic-gate pgcnt_t boot_protect_cnt = 0;
17300Sstevel@tonic-gate
17313446Smrj while (kbm_probe(&va, &len, &pfn, &prot) != 0 && va < high) {
17320Sstevel@tonic-gate if (va + len >= high)
17330Sstevel@tonic-gate panic("0x%lx byte mapping at 0x%p exceeds boot's "
17340Sstevel@tonic-gate "legal range.", len, (void *)va);
17350Sstevel@tonic-gate
17360Sstevel@tonic-gate while (len > 0) {
17370Sstevel@tonic-gate pp = page_numtopp_alloc(pfn);
17380Sstevel@tonic-gate if (pp != NULL) {
17390Sstevel@tonic-gate if (setaside == 0)
17400Sstevel@tonic-gate panic("Unexpected mapping by boot. "
17410Sstevel@tonic-gate "addr=%p pfn=%lx\n",
17420Sstevel@tonic-gate (void *)va, pfn);
17430Sstevel@tonic-gate
17440Sstevel@tonic-gate pp->p_next = bootpages;
17453446Smrj pp->p_prev = NULL;
17463446Smrj PP_SETBOOTPAGES(pp);
17473446Smrj if (bootpages != NULL) {
17483446Smrj bootpages->p_prev = pp;
17493446Smrj }
17500Sstevel@tonic-gate bootpages = pp;
17510Sstevel@tonic-gate ++boot_protect_cnt;
17520Sstevel@tonic-gate }
17530Sstevel@tonic-gate
17540Sstevel@tonic-gate ++pfn;
17550Sstevel@tonic-gate len -= MMU_PAGESIZE;
17560Sstevel@tonic-gate va += MMU_PAGESIZE;
17570Sstevel@tonic-gate }
17580Sstevel@tonic-gate }
17590Sstevel@tonic-gate PRM_DEBUG(boot_protect_cnt);
17600Sstevel@tonic-gate }
17610Sstevel@tonic-gate
17623446Smrj /*
17634828Sjosephb *
17643446Smrj */
17650Sstevel@tonic-gate static void
layout_kernel_va(void)17664828Sjosephb layout_kernel_va(void)
17670Sstevel@tonic-gate {
17684828Sjosephb PRM_POINT("layout_kernel_va() starting...");
17690Sstevel@tonic-gate /*
17703446Smrj * Establish the final size of the kernel's heap, size of segmap,
17713446Smrj * segkp, etc.
17720Sstevel@tonic-gate */
17730Sstevel@tonic-gate
17740Sstevel@tonic-gate #if defined(__amd64)
17750Sstevel@tonic-gate
17764828Sjosephb kpm_vbase = (caddr_t)segkpm_base;
177712004Sjiang.liu@intel.com if (physmax + 1 < plat_dr_physmax) {
177812004Sjiang.liu@intel.com kpm_size = ROUND_UP_LPAGE(mmu_ptob(plat_dr_physmax));
177912004Sjiang.liu@intel.com } else {
178012004Sjiang.liu@intel.com kpm_size = ROUND_UP_LPAGE(mmu_ptob(physmax + 1));
178112004Sjiang.liu@intel.com }
17824828Sjosephb if ((uintptr_t)kpm_vbase + kpm_size > (uintptr_t)valloc_base)
17834828Sjosephb panic("not enough room for kpm!");
17843446Smrj PRM_DEBUG(kpm_size);
17853446Smrj PRM_DEBUG(kpm_vbase);
17860Sstevel@tonic-gate
17870Sstevel@tonic-gate /*
17883446Smrj * By default we create a seg_kp in 64 bit kernels, it's a little
17893446Smrj * faster to access than embedding it in the heap.
17900Sstevel@tonic-gate */
17913446Smrj segkp_base = (caddr_t)valloc_base + valloc_sz;
17920Sstevel@tonic-gate if (!segkp_fromheap) {
17930Sstevel@tonic-gate size_t sz = mmu_ptob(segkpsize);
17940Sstevel@tonic-gate
17950Sstevel@tonic-gate /*
17963446Smrj * determine size of segkp
17970Sstevel@tonic-gate */
17980Sstevel@tonic-gate if (sz < SEGKPMINSIZE || sz > SEGKPMAXSIZE) {
17990Sstevel@tonic-gate sz = SEGKPDEFSIZE;
18000Sstevel@tonic-gate cmn_err(CE_WARN, "!Illegal value for segkpsize. "
18010Sstevel@tonic-gate "segkpsize has been reset to %ld pages",
18020Sstevel@tonic-gate mmu_btop(sz));
18030Sstevel@tonic-gate }
18040Sstevel@tonic-gate sz = MIN(sz, MAX(SEGKPMINSIZE, mmu_ptob(physmem)));
18050Sstevel@tonic-gate
18060Sstevel@tonic-gate segkpsize = mmu_btop(ROUND_UP_LPAGE(sz));
18070Sstevel@tonic-gate }
18083446Smrj PRM_DEBUG(segkp_base);
18093446Smrj PRM_DEBUG(segkpsize);
18100Sstevel@tonic-gate
18114828Sjosephb /*
18124828Sjosephb * segzio is used for ZFS cached data. It uses a distinct VA
18134828Sjosephb * segment (from kernel heap) so that we can easily tell not to
18144828Sjosephb * include it in kernel crash dumps on 64 bit kernels. The trick is
18154828Sjosephb * to give it lots of VA, but not constrain the kernel heap.
18164828Sjosephb * We scale the size of segzio linearly with physmem up to
18174828Sjosephb * SEGZIOMAXSIZE. Above that amount it scales at 50% of physmem.
18184828Sjosephb */
18193446Smrj segzio_base = segkp_base + mmu_ptob(segkpsize);
18203446Smrj if (segzio_fromheap) {
18213446Smrj segziosize = 0;
18223446Smrj } else {
18234828Sjosephb size_t physmem_size = mmu_ptob(physmem);
18244828Sjosephb size_t size = (segziosize == 0) ?
18254828Sjosephb physmem_size : mmu_ptob(segziosize);
18263290Sjohansen
18274828Sjosephb if (size < SEGZIOMINSIZE)
18283290Sjohansen size = SEGZIOMINSIZE;
18294828Sjosephb if (size > SEGZIOMAXSIZE) {
18303552Sjohansen size = SEGZIOMAXSIZE;
18314828Sjosephb if (physmem_size > size)
18324828Sjosephb size += (physmem_size - size) / 2;
18333290Sjohansen }
18343290Sjohansen segziosize = mmu_btop(ROUND_UP_LPAGE(size));
18353290Sjohansen }
18363446Smrj PRM_DEBUG(segziosize);
18373446Smrj PRM_DEBUG(segzio_base);
18383290Sjohansen
18390Sstevel@tonic-gate /*
18403446Smrj * Put the range of VA for device mappings next, kmdb knows to not
18413446Smrj * grep in this range of addresses.
18420Sstevel@tonic-gate */
18433446Smrj toxic_addr =
18443446Smrj ROUND_UP_LPAGE((uintptr_t)segzio_base + mmu_ptob(segziosize));
18450Sstevel@tonic-gate PRM_DEBUG(toxic_addr);
18463446Smrj segmap_start = ROUND_UP_LPAGE(toxic_addr + toxic_size);
18473446Smrj #else /* __i386 */
18483446Smrj segmap_start = ROUND_UP_LPAGE(kernelbase);
18493446Smrj #endif /* __i386 */
18503446Smrj PRM_DEBUG(segmap_start);
18510Sstevel@tonic-gate
18520Sstevel@tonic-gate /*
18537692SAmrita.Sadhukhan@Sun.COM * Users can change segmapsize through eeprom. If the variable
18547692SAmrita.Sadhukhan@Sun.COM * is tuned through eeprom, there is no upper bound on the
18557720SKen.Erickson@Sun.COM * size of segmap.
18560Sstevel@tonic-gate */
18570Sstevel@tonic-gate segmapsize = MAX(ROUND_UP_LPAGE(segmapsize), SEGMAPDEFAULT);
18580Sstevel@tonic-gate
18590Sstevel@tonic-gate #if defined(__i386)
18600Sstevel@tonic-gate /*
18610Sstevel@tonic-gate * 32-bit systems don't have segkpm or segkp, so segmap appears at
18620Sstevel@tonic-gate * the bottom of the kernel's address range. Set aside space for a
18633446Smrj * small red zone just below the start of segmap.
18640Sstevel@tonic-gate */
18653446Smrj segmap_start += KERNEL_REDZONE_SIZE;
18660Sstevel@tonic-gate segmapsize -= KERNEL_REDZONE_SIZE;
18670Sstevel@tonic-gate #endif
18683446Smrj
18693446Smrj PRM_DEBUG(segmap_start);
18703446Smrj PRM_DEBUG(segmapsize);
18714828Sjosephb kernelheap = (caddr_t)ROUND_UP_LPAGE(segmap_start + segmapsize);
18724828Sjosephb PRM_DEBUG(kernelheap);
18734828Sjosephb PRM_POINT("layout_kernel_va() done...");
18744828Sjosephb }
18754828Sjosephb
18764828Sjosephb /*
18774828Sjosephb * Finish initializing the VM system, now that we are no longer
18784828Sjosephb * relying on the boot time memory allocators.
18794828Sjosephb */
18804828Sjosephb static void
startup_vm(void)18814828Sjosephb startup_vm(void)
18824828Sjosephb {
18834828Sjosephb struct segmap_crargs a;
18844828Sjosephb
18854828Sjosephb extern int use_brk_lpg, use_stk_lpg;
18864828Sjosephb
18874828Sjosephb PRM_POINT("startup_vm() starting...");
18884828Sjosephb
18894828Sjosephb /*
18904828Sjosephb * Initialize the hat layer.
18914828Sjosephb */
18924828Sjosephb hat_init();
18933446Smrj
18943446Smrj /*
18953446Smrj * Do final allocations of HAT data structures that need to
18963446Smrj * be allocated before quiescing the boot loader.
18973446Smrj */
18983446Smrj PRM_POINT("Calling hat_kern_alloc()...");
18993446Smrj hat_kern_alloc((caddr_t)segmap_start, segmapsize, ekernelheap);
19003446Smrj PRM_POINT("hat_kern_alloc() done");
19013446Smrj
19025084Sjohnlev #ifndef __xpv
19033446Smrj /*
19045159Sjohnlev * Setup Page Attribute Table
19053446Smrj */
19065159Sjohnlev pat_sync();
19075084Sjohnlev #endif
19083446Smrj
19093446Smrj /*
19103446Smrj * The next two loops are done in distinct steps in order
19113446Smrj * to be sure that any page that is doubly mapped (both above
19123446Smrj * KERNEL_TEXT and below kernelbase) is dealt with correctly.
19133446Smrj * Note this may never happen, but it might someday.
19143446Smrj */
19153446Smrj bootpages = NULL;
19163446Smrj PRM_POINT("Protecting boot pages");
19170Sstevel@tonic-gate
19183446Smrj /*
19193446Smrj * Protect any pages mapped above KERNEL_TEXT that somehow have
19203446Smrj * page_t's. This can only happen if something weird allocated
19213446Smrj * in this range (like kadb/kmdb).
19223446Smrj */
19233446Smrj protect_boot_range(KERNEL_TEXT, (uintptr_t)-1, 0);
19243446Smrj
19253446Smrj /*
19263446Smrj * Before we can take over memory allocation/mapping from the boot
19273446Smrj * loader we must remove from our free page lists any boot allocated
19283446Smrj * pages that stay mapped until release_bootstrap().
19293446Smrj */
19303446Smrj protect_boot_range(0, kernelbase, 1);
19313446Smrj
19325084Sjohnlev
19333446Smrj /*
19343446Smrj * Switch to running on regular HAT (not boot_mmu)
19353446Smrj */
19363446Smrj PRM_POINT("Calling hat_kern_setup()...");
19373446Smrj hat_kern_setup();
19383446Smrj
19393446Smrj /*
19403446Smrj * It is no longer safe to call BOP_ALLOC(), so make sure we don't.
19413446Smrj */
19423446Smrj bop_no_more_mem();
19433446Smrj
19443446Smrj PRM_POINT("hat_kern_setup() done");
19453446Smrj
19463446Smrj hat_cpu_online(CPU);
19470Sstevel@tonic-gate
19480Sstevel@tonic-gate /*
19490Sstevel@tonic-gate * Initialize VM system
19500Sstevel@tonic-gate */
19510Sstevel@tonic-gate PRM_POINT("Calling kvm_init()...");
19520Sstevel@tonic-gate kvm_init();
19530Sstevel@tonic-gate PRM_POINT("kvm_init() done");
19540Sstevel@tonic-gate
19550Sstevel@tonic-gate /*
19560Sstevel@tonic-gate * Tell kmdb that the VM system is now working
19570Sstevel@tonic-gate */
19580Sstevel@tonic-gate if (boothowto & RB_DEBUG)
19590Sstevel@tonic-gate kdi_dvec_vmready();
19600Sstevel@tonic-gate
19615084Sjohnlev #if defined(__xpv)
19625084Sjohnlev /*
19635084Sjohnlev * Populate the I/O pool on domain 0
19645084Sjohnlev */
19655084Sjohnlev if (DOMAIN_IS_INITDOMAIN(xen_info)) {
19665084Sjohnlev extern long populate_io_pool(void);
19675084Sjohnlev long init_io_pool_cnt;
19685084Sjohnlev
19695084Sjohnlev PRM_POINT("Populating reserve I/O page pool");
19705084Sjohnlev init_io_pool_cnt = populate_io_pool();
19715084Sjohnlev PRM_DEBUG(init_io_pool_cnt);
19725084Sjohnlev }
19735084Sjohnlev #endif
19740Sstevel@tonic-gate /*
19750Sstevel@tonic-gate * Mangle the brand string etc.
19760Sstevel@tonic-gate */
19770Sstevel@tonic-gate cpuid_pass3(CPU);
19780Sstevel@tonic-gate
19790Sstevel@tonic-gate #if defined(__amd64)
19800Sstevel@tonic-gate
19810Sstevel@tonic-gate /*
19820Sstevel@tonic-gate * Create the device arena for toxic (to dtrace/kmdb) mappings.
19830Sstevel@tonic-gate */
19840Sstevel@tonic-gate device_arena = vmem_create("device", (void *)toxic_addr,
19850Sstevel@tonic-gate toxic_size, MMU_PAGESIZE, NULL, NULL, NULL, 0, VM_SLEEP);
19860Sstevel@tonic-gate
19870Sstevel@tonic-gate #else /* __i386 */
19880Sstevel@tonic-gate
19890Sstevel@tonic-gate /*
19900Sstevel@tonic-gate * allocate the bit map that tracks toxic pages
19910Sstevel@tonic-gate */
19923446Smrj toxic_bit_map_len = btop((ulong_t)(valloc_base - kernelbase));
19930Sstevel@tonic-gate PRM_DEBUG(toxic_bit_map_len);
19940Sstevel@tonic-gate toxic_bit_map =
19950Sstevel@tonic-gate kmem_zalloc(BT_SIZEOFMAP(toxic_bit_map_len), KM_NOSLEEP);
19960Sstevel@tonic-gate ASSERT(toxic_bit_map != NULL);
19970Sstevel@tonic-gate PRM_DEBUG(toxic_bit_map);
19980Sstevel@tonic-gate
19990Sstevel@tonic-gate #endif /* __i386 */
20000Sstevel@tonic-gate
20010Sstevel@tonic-gate
20020Sstevel@tonic-gate /*
20030Sstevel@tonic-gate * Now that we've got more VA, as well as the ability to allocate from
20040Sstevel@tonic-gate * it, tell the debugger.
20050Sstevel@tonic-gate */
20060Sstevel@tonic-gate if (boothowto & RB_DEBUG)
20070Sstevel@tonic-gate kdi_dvec_memavail();
20080Sstevel@tonic-gate
20090Sstevel@tonic-gate /*
20100Sstevel@tonic-gate * The following code installs a special page fault handler (#pf)
20110Sstevel@tonic-gate * to work around a pentium bug.
20120Sstevel@tonic-gate */
20135084Sjohnlev #if !defined(__amd64) && !defined(__xpv)
20140Sstevel@tonic-gate if (x86_type == X86_TYPE_P5) {
20153446Smrj desctbr_t idtr;
20160Sstevel@tonic-gate gate_desc_t *newidt;
20170Sstevel@tonic-gate
20180Sstevel@tonic-gate if ((newidt = kmem_zalloc(MMU_PAGESIZE, KM_NOSLEEP)) == NULL)
20190Sstevel@tonic-gate panic("failed to install pentium_pftrap");
20200Sstevel@tonic-gate
20215460Sjosephb bcopy(idt0, newidt, NIDT * sizeof (*idt0));
20220Sstevel@tonic-gate set_gatesegd(&newidt[T_PGFLT], &pentium_pftrap,
20238679SSeth.Goldberg@Sun.COM KCS_SEL, SDT_SYSIGT, TRP_KPL, 0);
20240Sstevel@tonic-gate
20250Sstevel@tonic-gate (void) as_setprot(&kas, (caddr_t)newidt, MMU_PAGESIZE,
20265460Sjosephb PROT_READ | PROT_EXEC);
20270Sstevel@tonic-gate
20285460Sjosephb CPU->cpu_idt = newidt;
20295460Sjosephb idtr.dtr_base = (uintptr_t)CPU->cpu_idt;
20305460Sjosephb idtr.dtr_limit = (NIDT * sizeof (*idt0)) - 1;
20313446Smrj wr_idtr(&idtr);
20320Sstevel@tonic-gate }
20330Sstevel@tonic-gate #endif /* !__amd64 */
20340Sstevel@tonic-gate
20355084Sjohnlev #if !defined(__xpv)
20360Sstevel@tonic-gate /*
20370Sstevel@tonic-gate * Map page pfn=0 for drivers, such as kd, that need to pick up
20380Sstevel@tonic-gate * parameters left there by controllers/BIOS.
20390Sstevel@tonic-gate */
20400Sstevel@tonic-gate PRM_POINT("setup up p0_va");
20410Sstevel@tonic-gate p0_va = i86devmap(0, 1, PROT_READ);
20420Sstevel@tonic-gate PRM_DEBUG(p0_va);
20435084Sjohnlev #endif
20440Sstevel@tonic-gate
20450Sstevel@tonic-gate cmn_err(CE_CONT, "?mem = %luK (0x%lx)\n",
20460Sstevel@tonic-gate physinstalled << (MMU_PAGESHIFT - 10), ptob(physinstalled));
20470Sstevel@tonic-gate
2048841Skchow /*
2049841Skchow * disable automatic large pages for small memory systems or
2050841Skchow * when the disable flag is set.
20515349Skchow *
20525349Skchow * Do not yet consider page sizes larger than 2m/4m.
2053841Skchow */
20542991Ssusans if (!auto_lpg_disable && mmu.max_page_level > 0) {
20552991Ssusans max_uheap_lpsize = LEVEL_SIZE(1);
20562991Ssusans max_ustack_lpsize = LEVEL_SIZE(1);
20572991Ssusans max_privmap_lpsize = LEVEL_SIZE(1);
20582991Ssusans max_uidata_lpsize = LEVEL_SIZE(1);
20592991Ssusans max_utext_lpsize = LEVEL_SIZE(1);
20602991Ssusans max_shm_lpsize = LEVEL_SIZE(1);
20612991Ssusans }
20622991Ssusans if (physmem < privm_lpg_min_physmem || mmu.max_page_level == 0 ||
20632991Ssusans auto_lpg_disable) {
2064423Sdavemq use_brk_lpg = 0;
2065423Sdavemq use_stk_lpg = 0;
20662991Ssusans }
20675349Skchow mcntl0_lpsize = LEVEL_SIZE(mmu.umax_page_level);
2068423Sdavemq
20690Sstevel@tonic-gate PRM_POINT("Calling hat_init_finish()...");
20700Sstevel@tonic-gate hat_init_finish();
20710Sstevel@tonic-gate PRM_POINT("hat_init_finish() done");
20720Sstevel@tonic-gate
20730Sstevel@tonic-gate /*
20740Sstevel@tonic-gate * Initialize the segkp segment type.
20750Sstevel@tonic-gate */
20760Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER);
20773446Smrj PRM_POINT("Attaching segkp");
20783446Smrj if (segkp_fromheap) {
20790Sstevel@tonic-gate segkp->s_as = &kas;
20803446Smrj } else if (seg_attach(&kas, (caddr_t)segkp_base, mmu_ptob(segkpsize),
20813446Smrj segkp) < 0) {
20823446Smrj panic("startup: cannot attach segkp");
20833446Smrj /*NOTREACHED*/
20840Sstevel@tonic-gate }
20853446Smrj PRM_POINT("Doing segkp_create()");
20860Sstevel@tonic-gate if (segkp_create(segkp) != 0) {
20870Sstevel@tonic-gate panic("startup: segkp_create failed");
20880Sstevel@tonic-gate /*NOTREACHED*/
20890Sstevel@tonic-gate }
20900Sstevel@tonic-gate PRM_DEBUG(segkp);
20910Sstevel@tonic-gate rw_exit(&kas.a_lock);
20920Sstevel@tonic-gate
20930Sstevel@tonic-gate /*
20940Sstevel@tonic-gate * kpm segment
20950Sstevel@tonic-gate */
20960Sstevel@tonic-gate segmap_kpm = 0;
20970Sstevel@tonic-gate if (kpm_desired) {
20980Sstevel@tonic-gate kpm_init();
20990Sstevel@tonic-gate kpm_enable = 1;
21000Sstevel@tonic-gate }
21010Sstevel@tonic-gate
21020Sstevel@tonic-gate /*
21030Sstevel@tonic-gate * Now create segmap segment.
21040Sstevel@tonic-gate */
21050Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER);
21063446Smrj if (seg_attach(&kas, (caddr_t)segmap_start, segmapsize, segmap) < 0) {
21073446Smrj panic("cannot attach segmap");
21080Sstevel@tonic-gate /*NOTREACHED*/
21090Sstevel@tonic-gate }
21103446Smrj PRM_DEBUG(segmap);
21110Sstevel@tonic-gate
21120Sstevel@tonic-gate a.prot = PROT_READ | PROT_WRITE;
21130Sstevel@tonic-gate a.shmsize = 0;
21140Sstevel@tonic-gate a.nfreelist = segmapfreelists;
21150Sstevel@tonic-gate
21163446Smrj if (segmap_create(segmap, (caddr_t)&a) != 0)
21173446Smrj panic("segmap_create segmap");
21180Sstevel@tonic-gate rw_exit(&kas.a_lock);
21190Sstevel@tonic-gate
21200Sstevel@tonic-gate setup_vaddr_for_ppcopy(CPU);
21210Sstevel@tonic-gate
21220Sstevel@tonic-gate segdev_init();
21235084Sjohnlev #if defined(__xpv)
21245084Sjohnlev if (DOMAIN_IS_INITDOMAIN(xen_info))
21255084Sjohnlev #endif
21265084Sjohnlev pmem_init();
21273446Smrj
21280Sstevel@tonic-gate PRM_POINT("startup_vm() done");
21290Sstevel@tonic-gate }
21300Sstevel@tonic-gate
21313446Smrj /*
21323446Smrj * Load a tod module for the non-standard tod part found on this system.
21333446Smrj */
21343446Smrj static void
load_tod_module(char * todmod)21353446Smrj load_tod_module(char *todmod)
21363446Smrj {
21373446Smrj if (modload("tod", todmod) == -1)
21383446Smrj halt("Can't load TOD module");
21393446Smrj }
21403446Smrj
21410Sstevel@tonic-gate static void
startup_end(void)21420Sstevel@tonic-gate startup_end(void)
21430Sstevel@tonic-gate {
21445107Seota int i;
21450Sstevel@tonic-gate extern void setx86isalist(void);
21469637SRandy.Fishel@Sun.COM extern void cpu_event_init(void);
21470Sstevel@tonic-gate
21480Sstevel@tonic-gate PRM_POINT("startup_end() starting...");
21490Sstevel@tonic-gate
21500Sstevel@tonic-gate /*
21510Sstevel@tonic-gate * Perform tasks that get done after most of the VM
21520Sstevel@tonic-gate * initialization has been done but before the clock
21530Sstevel@tonic-gate * and other devices get started.
21540Sstevel@tonic-gate */
21550Sstevel@tonic-gate kern_setup1();
21560Sstevel@tonic-gate
21570Sstevel@tonic-gate /*
21580Sstevel@tonic-gate * Perform CPC initialization for this CPU.
21590Sstevel@tonic-gate */
21600Sstevel@tonic-gate kcpc_hw_init(CPU);
21610Sstevel@tonic-gate
21629637SRandy.Fishel@Sun.COM /*
21639637SRandy.Fishel@Sun.COM * Initialize cpu event framework.
21649637SRandy.Fishel@Sun.COM */
21659637SRandy.Fishel@Sun.COM cpu_event_init();
21669637SRandy.Fishel@Sun.COM
21671582Skchow #if defined(OPTERON_WORKAROUND_6323525)
21681582Skchow if (opteron_workaround_6323525)
21691582Skchow patch_workaround_6323525();
21701582Skchow #endif
21710Sstevel@tonic-gate /*
21723446Smrj * If needed, load TOD module now so that ddi_get_time(9F) etc. work
21733446Smrj * (For now, "needed" is defined as set tod_module_name in /etc/system)
21743446Smrj */
21753446Smrj if (tod_module_name != NULL) {
21763446Smrj PRM_POINT("load_tod_module()");
21773446Smrj load_tod_module(tod_module_name);
21783446Smrj }
21793446Smrj
21805084Sjohnlev #if defined(__xpv)
21815084Sjohnlev /*
21825084Sjohnlev * Forceload interposing TOD module for the hypervisor.
21835084Sjohnlev */
21845084Sjohnlev PRM_POINT("load_tod_module()");
21855084Sjohnlev load_tod_module("xpvtod");
21865084Sjohnlev #endif
21875084Sjohnlev
21883446Smrj /*
21890Sstevel@tonic-gate * Configure the system.
21900Sstevel@tonic-gate */
21910Sstevel@tonic-gate PRM_POINT("Calling configure()...");
21920Sstevel@tonic-gate configure(); /* set up devices */
21930Sstevel@tonic-gate PRM_POINT("configure() done");
21940Sstevel@tonic-gate
21950Sstevel@tonic-gate /*
2196*13134Skuriakose.kuruvilla@oracle.com * We can now setup for XSAVE because fpu_probe is done in configure().
2197*13134Skuriakose.kuruvilla@oracle.com */
2198*13134Skuriakose.kuruvilla@oracle.com if (fp_save_mech == FP_XSAVE) {
2199*13134Skuriakose.kuruvilla@oracle.com xsave_setup_msr(CPU);
2200*13134Skuriakose.kuruvilla@oracle.com }
2201*13134Skuriakose.kuruvilla@oracle.com
2202*13134Skuriakose.kuruvilla@oracle.com /*
22030Sstevel@tonic-gate * Set the isa_list string to the defined instruction sets we
22040Sstevel@tonic-gate * support.
22050Sstevel@tonic-gate */
22060Sstevel@tonic-gate setx86isalist();
22071455Sandrei cpu_intr_alloc(CPU, NINTR_THREADS);
22080Sstevel@tonic-gate psm_install();
22090Sstevel@tonic-gate
22100Sstevel@tonic-gate /*
22110Sstevel@tonic-gate * We're done with bootops. We don't unmap the bootstrap yet because
22120Sstevel@tonic-gate * we're still using bootsvcs.
22130Sstevel@tonic-gate */
22143446Smrj PRM_POINT("NULLing out bootops");
22153446Smrj *bootopsp = (struct bootops *)NULL;
22160Sstevel@tonic-gate bootops = (struct bootops *)NULL;
22170Sstevel@tonic-gate
22185084Sjohnlev #if defined(__xpv)
22195084Sjohnlev ec_init_debug_irq();
22205084Sjohnlev xs_domu_init();
22215084Sjohnlev #endif
22229940SVikram.Hegde@Sun.COM
222311600SVikram.Hegde@Sun.COM #if defined(__amd64) && !defined(__xpv)
222411600SVikram.Hegde@Sun.COM /*
222511600SVikram.Hegde@Sun.COM * Intel IOMMU has been setup/initialized in ddi_impl.c
222611600SVikram.Hegde@Sun.COM * Start it up now.
222711600SVikram.Hegde@Sun.COM */
222811600SVikram.Hegde@Sun.COM immu_startup();
22299940SVikram.Hegde@Sun.COM #endif
223011600SVikram.Hegde@Sun.COM
22310Sstevel@tonic-gate PRM_POINT("Enabling interrupts");
22320Sstevel@tonic-gate (*picinitf)();
22330Sstevel@tonic-gate sti();
22345084Sjohnlev #if defined(__xpv)
22355084Sjohnlev ASSERT(CPU->cpu_m.mcpu_vcpu_info->evtchn_upcall_mask == 0);
22365084Sjohnlev xen_late_startup();
22375084Sjohnlev #endif
22380Sstevel@tonic-gate
22390Sstevel@tonic-gate (void) add_avsoftintr((void *)&softlevel1_hdl, 1, softlevel1,
22404828Sjosephb "softlevel1", NULL, NULL); /* XXX to be moved later */
22410Sstevel@tonic-gate
22425107Seota /*
22435107Seota * Register these software interrupts for ddi timer.
22445107Seota * Software interrupts up to the level 10 are supported.
22455107Seota */
22465107Seota for (i = DDI_IPL_1; i <= DDI_IPL_10; i++) {
22475107Seota char name[sizeof ("timer_softintr") + 2];
22485107Seota (void) sprintf(name, "timer_softintr%02d", i);
22495107Seota (void) add_avsoftintr((void *)&softlevel_hdl[i-1], i,
22505107Seota (avfunc)timer_softintr, name, (caddr_t)(uintptr_t)i, NULL);
22515107Seota }
22525107Seota
22537730SVikram.Hegde@Sun.COM #if !defined(__xpv)
22547730SVikram.Hegde@Sun.COM if (modload("drv", "amd_iommu") < 0) {
22557730SVikram.Hegde@Sun.COM PRM_POINT("No AMD IOMMU present\n");
22568215SVikram.Hegde@Sun.COM } else if (ddi_hold_installed_driver(ddi_name_to_major(
22578215SVikram.Hegde@Sun.COM "amd_iommu")) == NULL) {
22587730SVikram.Hegde@Sun.COM prom_printf("ERROR: failed to attach AMD IOMMU\n");
22597730SVikram.Hegde@Sun.COM }
22607730SVikram.Hegde@Sun.COM #endif
22618930SBill.Holler@Sun.COM post_startup_cpu_fixups();
22627730SVikram.Hegde@Sun.COM
22630Sstevel@tonic-gate PRM_POINT("startup_end() done");
22640Sstevel@tonic-gate }
22650Sstevel@tonic-gate
22667942SKen.Erickson@Sun.COM /*
22677942SKen.Erickson@Sun.COM * Don't remove the following 2 variables. They are necessary
22687942SKen.Erickson@Sun.COM * for reading the hostid from the legacy file (/kernel/misc/sysinit).
22697942SKen.Erickson@Sun.COM */
22700Sstevel@tonic-gate char *_hs1107 = hw_serial;
22710Sstevel@tonic-gate ulong_t _bdhs34;
22720Sstevel@tonic-gate
22730Sstevel@tonic-gate void
post_startup(void)22740Sstevel@tonic-gate post_startup(void)
22750Sstevel@tonic-gate {
22768906SEric.Saxe@Sun.COM extern void cpupm_init(cpu_t *);
22779637SRandy.Fishel@Sun.COM extern void cpu_event_init_cpu(cpu_t *);
22788906SEric.Saxe@Sun.COM
22790Sstevel@tonic-gate /*
22800Sstevel@tonic-gate * Set the system wide, processor-specific flags to be passed
22810Sstevel@tonic-gate * to userland via the aux vector for performance hints and
22820Sstevel@tonic-gate * instruction set extensions.
22830Sstevel@tonic-gate */
22840Sstevel@tonic-gate bind_hwcap();
22850Sstevel@tonic-gate
22865084Sjohnlev #ifdef __xpv
22875084Sjohnlev if (DOMAIN_IS_INITDOMAIN(xen_info))
22885084Sjohnlev #endif
22895084Sjohnlev {
22905084Sjohnlev #if defined(__xpv)
22915084Sjohnlev xpv_panic_init();
22925084Sjohnlev #else
22935084Sjohnlev /*
22945084Sjohnlev * Startup the memory scrubber.
22955084Sjohnlev * XXPV This should be running somewhere ..
22965084Sjohnlev */
22979000SStuart.Maybee@Sun.COM if (get_hwenv() != HW_XEN_HVM)
22987532SSean.Ye@Sun.COM memscrub_init();
22995084Sjohnlev #endif
23005084Sjohnlev }
23010Sstevel@tonic-gate
23020Sstevel@tonic-gate /*
23031414Scindi * Complete CPU module initialization
23041414Scindi */
23055254Sgavinm cmi_post_startup();
23061414Scindi
23071414Scindi /*
23080Sstevel@tonic-gate * Perform forceloading tasks for /etc/system.
23090Sstevel@tonic-gate */
23100Sstevel@tonic-gate (void) mod_sysctl(SYS_FORCELOAD, NULL);
23110Sstevel@tonic-gate
23120Sstevel@tonic-gate /*
23130Sstevel@tonic-gate * ON4.0: Force /proc module in until clock interrupt handle fixed
23140Sstevel@tonic-gate * ON4.0: This must be fixed or restated in /etc/systems.
23150Sstevel@tonic-gate */
23160Sstevel@tonic-gate (void) modload("fs", "procfs");
23170Sstevel@tonic-gate
23185129Smarx (void) i_ddi_attach_hw_nodes("pit_beep");
23195129Smarx
23200Sstevel@tonic-gate #if defined(__i386)
23210Sstevel@tonic-gate /*
23220Sstevel@tonic-gate * Check for required functional Floating Point hardware,
23230Sstevel@tonic-gate * unless FP hardware explicitly disabled.
23240Sstevel@tonic-gate */
23250Sstevel@tonic-gate if (fpu_exists && (fpu_pentium_fdivbug || fp_kind == FP_NO))
23260Sstevel@tonic-gate halt("No working FP hardware found");
23270Sstevel@tonic-gate #endif
23280Sstevel@tonic-gate
23290Sstevel@tonic-gate maxmem = freemem;
23300Sstevel@tonic-gate
23319637SRandy.Fishel@Sun.COM cpu_event_init_cpu(CPU);
23328906SEric.Saxe@Sun.COM cpupm_init(CPU);
23339652SMichael.Corcoran@Sun.COM (void) mach_cpu_create_device_node(CPU, NULL);
23348906SEric.Saxe@Sun.COM
23358906SEric.Saxe@Sun.COM pg_init();
23360Sstevel@tonic-gate }
23370Sstevel@tonic-gate
23380Sstevel@tonic-gate static int
pp_in_range(page_t * pp,uint64_t low_addr,uint64_t high_addr)23397656SSherry.Moore@Sun.COM pp_in_range(page_t *pp, uint64_t low_addr, uint64_t high_addr)
23400Sstevel@tonic-gate {
23417656SSherry.Moore@Sun.COM return ((pp->p_pagenum >= btop(low_addr)) &&
23427656SSherry.Moore@Sun.COM (pp->p_pagenum < btopr(high_addr)));
23430Sstevel@tonic-gate }
23440Sstevel@tonic-gate
23450Sstevel@tonic-gate void
release_bootstrap(void)23460Sstevel@tonic-gate release_bootstrap(void)
23470Sstevel@tonic-gate {
23480Sstevel@tonic-gate int root_is_ramdisk;
23490Sstevel@tonic-gate page_t *pp;
23500Sstevel@tonic-gate extern void kobj_boot_unmountroot(void);
23510Sstevel@tonic-gate extern dev_t rootdev;
23527515SSeth.Goldberg@Sun.COM #if !defined(__xpv)
23537515SSeth.Goldberg@Sun.COM pfn_t pfn;
23547515SSeth.Goldberg@Sun.COM #endif
23550Sstevel@tonic-gate
23560Sstevel@tonic-gate /* unmount boot ramdisk and release kmem usage */
23570Sstevel@tonic-gate kobj_boot_unmountroot();
23580Sstevel@tonic-gate
23590Sstevel@tonic-gate /*
23600Sstevel@tonic-gate * We're finished using the boot loader so free its pages.
23610Sstevel@tonic-gate */
23620Sstevel@tonic-gate PRM_POINT("Unmapping lower boot pages");
23637656SSherry.Moore@Sun.COM
23643446Smrj clear_boot_mappings(0, _userlimit);
23657656SSherry.Moore@Sun.COM
23663446Smrj postbootkernelbase = kernelbase;
23670Sstevel@tonic-gate
23680Sstevel@tonic-gate /*
23690Sstevel@tonic-gate * If root isn't on ramdisk, destroy the hardcoded
23700Sstevel@tonic-gate * ramdisk node now and release the memory. Else,
23710Sstevel@tonic-gate * ramdisk memory is kept in rd_pages.
23720Sstevel@tonic-gate */
23730Sstevel@tonic-gate root_is_ramdisk = (getmajor(rootdev) == ddi_name_to_major("ramdisk"));
23740Sstevel@tonic-gate if (!root_is_ramdisk) {
23750Sstevel@tonic-gate dev_info_t *dip = ddi_find_devinfo("ramdisk", -1, 0);
23760Sstevel@tonic-gate ASSERT(dip && ddi_get_parent(dip) == ddi_root_node());
23770Sstevel@tonic-gate ndi_rele_devi(dip); /* held from ddi_find_devinfo */
23780Sstevel@tonic-gate (void) ddi_remove_child(dip, 0);
23790Sstevel@tonic-gate }
23800Sstevel@tonic-gate
23810Sstevel@tonic-gate PRM_POINT("Releasing boot pages");
23820Sstevel@tonic-gate while (bootpages) {
23837656SSherry.Moore@Sun.COM extern uint64_t ramdisk_start, ramdisk_end;
23840Sstevel@tonic-gate pp = bootpages;
23850Sstevel@tonic-gate bootpages = pp->p_next;
23867656SSherry.Moore@Sun.COM
23877656SSherry.Moore@Sun.COM
23887656SSherry.Moore@Sun.COM /* Keep pages for the lower 64K */
23897656SSherry.Moore@Sun.COM if (pp_in_range(pp, 0, 0x40000)) {
23907656SSherry.Moore@Sun.COM pp->p_next = lower_pages;
23917656SSherry.Moore@Sun.COM lower_pages = pp;
23927656SSherry.Moore@Sun.COM lower_pages_count++;
23937656SSherry.Moore@Sun.COM continue;
23947656SSherry.Moore@Sun.COM }
23957656SSherry.Moore@Sun.COM
23967656SSherry.Moore@Sun.COM
23977656SSherry.Moore@Sun.COM if (root_is_ramdisk && pp_in_range(pp, ramdisk_start,
23987656SSherry.Moore@Sun.COM ramdisk_end)) {
23990Sstevel@tonic-gate pp->p_next = rd_pages;
24000Sstevel@tonic-gate rd_pages = pp;
24010Sstevel@tonic-gate continue;
24020Sstevel@tonic-gate }
24030Sstevel@tonic-gate pp->p_next = (struct page *)0;
24043446Smrj pp->p_prev = (struct page *)0;
24053446Smrj PP_CLRBOOTPAGES(pp);
24060Sstevel@tonic-gate page_free(pp, 1);
24070Sstevel@tonic-gate }
24083446Smrj PRM_POINT("Boot pages released");
24090Sstevel@tonic-gate
24105084Sjohnlev #if !defined(__xpv)
24115084Sjohnlev /* XXPV -- note this following bunch of code needs to be revisited in Xen 3.0 */
24120Sstevel@tonic-gate /*
24137515SSeth.Goldberg@Sun.COM * Find 1 page below 1 MB so that other processors can boot up or
24147515SSeth.Goldberg@Sun.COM * so that any processor can resume.
24150Sstevel@tonic-gate * Make sure it has a kernel VA as well as a 1:1 mapping.
24160Sstevel@tonic-gate * We should have just free'd one up.
24170Sstevel@tonic-gate */
24187656SSherry.Moore@Sun.COM
24197656SSherry.Moore@Sun.COM /*
24207656SSherry.Moore@Sun.COM * 0x10 pages is 64K. Leave the bottom 64K alone
24217656SSherry.Moore@Sun.COM * for BIOS.
24227656SSherry.Moore@Sun.COM */
24237656SSherry.Moore@Sun.COM for (pfn = 0x10; pfn < btop(1*1024*1024); pfn++) {
24247515SSeth.Goldberg@Sun.COM if (page_numtopp_alloc(pfn) == NULL)
24257515SSeth.Goldberg@Sun.COM continue;
24267515SSeth.Goldberg@Sun.COM rm_platter_va = i86devmap(pfn, 1,
24277515SSeth.Goldberg@Sun.COM PROT_READ | PROT_WRITE | PROT_EXEC);
24287515SSeth.Goldberg@Sun.COM rm_platter_pa = ptob(pfn);
24297515SSeth.Goldberg@Sun.COM break;
24300Sstevel@tonic-gate }
24317515SSeth.Goldberg@Sun.COM if (pfn == btop(1*1024*1024) && use_mp)
24327515SSeth.Goldberg@Sun.COM panic("No page below 1M available for starting "
24337515SSeth.Goldberg@Sun.COM "other processors or for resuming from system-suspend");
24345084Sjohnlev #endif /* !__xpv */
24350Sstevel@tonic-gate }
24360Sstevel@tonic-gate
24370Sstevel@tonic-gate /*
24380Sstevel@tonic-gate * Initialize the platform-specific parts of a page_t.
24390Sstevel@tonic-gate */
24400Sstevel@tonic-gate void
add_physmem_cb(page_t * pp,pfn_t pnum)24410Sstevel@tonic-gate add_physmem_cb(page_t *pp, pfn_t pnum)
24420Sstevel@tonic-gate {
24430Sstevel@tonic-gate pp->p_pagenum = pnum;
24440Sstevel@tonic-gate pp->p_mapping = NULL;
24450Sstevel@tonic-gate pp->p_embed = 0;
24460Sstevel@tonic-gate pp->p_share = 0;
24470Sstevel@tonic-gate pp->p_mlentry = 0;
24480Sstevel@tonic-gate }
24490Sstevel@tonic-gate
24500Sstevel@tonic-gate /*
24510Sstevel@tonic-gate * kphysm_init() initializes physical memory.
24520Sstevel@tonic-gate */
24530Sstevel@tonic-gate static pgcnt_t
kphysm_init(page_t * pp,pgcnt_t npages)24540Sstevel@tonic-gate kphysm_init(
24553446Smrj page_t *pp,
24560Sstevel@tonic-gate pgcnt_t npages)
24570Sstevel@tonic-gate {
24580Sstevel@tonic-gate struct memlist *pmem;
24590Sstevel@tonic-gate struct memseg *cur_memseg;
24600Sstevel@tonic-gate pfn_t base_pfn;
24619732SKit.Chow@Sun.COM pfn_t end_pfn;
24620Sstevel@tonic-gate pgcnt_t num;
24630Sstevel@tonic-gate pgcnt_t pages_done = 0;
24640Sstevel@tonic-gate uint64_t addr;
24650Sstevel@tonic-gate uint64_t size;
24660Sstevel@tonic-gate extern pfn_t ddiphysmin;
24679732SKit.Chow@Sun.COM extern int mnode_xwa;
24689732SKit.Chow@Sun.COM int ms = 0, me = 0;
24690Sstevel@tonic-gate
24700Sstevel@tonic-gate ASSERT(page_hash != NULL && page_hashsz != 0);
24710Sstevel@tonic-gate
24723446Smrj cur_memseg = memseg_base;
247311474SJonathan.Adams@Sun.COM for (pmem = phys_avail; pmem && npages; pmem = pmem->ml_next) {
24740Sstevel@tonic-gate /*
24750Sstevel@tonic-gate * In a 32 bit kernel can't use higher memory if we're
24760Sstevel@tonic-gate * not booting in PAE mode. This check takes care of that.
24770Sstevel@tonic-gate */
247811474SJonathan.Adams@Sun.COM addr = pmem->ml_address;
247911474SJonathan.Adams@Sun.COM size = pmem->ml_size;
24800Sstevel@tonic-gate if (btop(addr) > physmax)
24810Sstevel@tonic-gate continue;
24820Sstevel@tonic-gate
24830Sstevel@tonic-gate /*
24840Sstevel@tonic-gate * align addr and size - they may not be at page boundaries
24850Sstevel@tonic-gate */
24860Sstevel@tonic-gate if ((addr & MMU_PAGEOFFSET) != 0) {
24870Sstevel@tonic-gate addr += MMU_PAGEOFFSET;
24880Sstevel@tonic-gate addr &= ~(uint64_t)MMU_PAGEOFFSET;
248911474SJonathan.Adams@Sun.COM size -= addr - pmem->ml_address;
24900Sstevel@tonic-gate }
24910Sstevel@tonic-gate
2492810Skchow /* only process pages below or equal to physmax */
2493810Skchow if ((btop(addr + size) - 1) > physmax)
2494810Skchow size = ptob(physmax - btop(addr) + 1);
24950Sstevel@tonic-gate
24960Sstevel@tonic-gate num = btop(size);
24970Sstevel@tonic-gate if (num == 0)
24980Sstevel@tonic-gate continue;
24990Sstevel@tonic-gate
25000Sstevel@tonic-gate if (num > npages)
25010Sstevel@tonic-gate num = npages;
25020Sstevel@tonic-gate
25030Sstevel@tonic-gate npages -= num;
25040Sstevel@tonic-gate pages_done += num;
25050Sstevel@tonic-gate base_pfn = btop(addr);
25060Sstevel@tonic-gate
25070Sstevel@tonic-gate if (prom_debug)
25080Sstevel@tonic-gate prom_printf("MEMSEG addr=0x%" PRIx64
25090Sstevel@tonic-gate " pgs=0x%lx pfn 0x%lx-0x%lx\n",
25100Sstevel@tonic-gate addr, num, base_pfn, base_pfn + num);
25110Sstevel@tonic-gate
25120Sstevel@tonic-gate /*
25133446Smrj * Ignore pages below ddiphysmin to simplify ddi memory
25140Sstevel@tonic-gate * allocation with non-zero addr_lo requests.
25150Sstevel@tonic-gate */
25160Sstevel@tonic-gate if (base_pfn < ddiphysmin) {
25173446Smrj if (base_pfn + num <= ddiphysmin)
25180Sstevel@tonic-gate continue;
25190Sstevel@tonic-gate pp += (ddiphysmin - base_pfn);
25200Sstevel@tonic-gate num -= (ddiphysmin - base_pfn);
25210Sstevel@tonic-gate base_pfn = ddiphysmin;
25220Sstevel@tonic-gate }
25233446Smrj
25240Sstevel@tonic-gate /*
25259732SKit.Chow@Sun.COM * mnode_xwa is greater than 1 when large pages regions can
25269732SKit.Chow@Sun.COM * cross memory node boundaries. To prevent the formation
25279732SKit.Chow@Sun.COM * of these large pages, configure the memsegs based on the
25289732SKit.Chow@Sun.COM * memory node ranges which had been made non-contiguous.
25290Sstevel@tonic-gate */
25309732SKit.Chow@Sun.COM if (mnode_xwa > 1) {
25319732SKit.Chow@Sun.COM
25329732SKit.Chow@Sun.COM end_pfn = base_pfn + num - 1;
25339732SKit.Chow@Sun.COM ms = PFN_2_MEM_NODE(base_pfn);
25349732SKit.Chow@Sun.COM me = PFN_2_MEM_NODE(end_pfn);
25359732SKit.Chow@Sun.COM
25369732SKit.Chow@Sun.COM if (ms != me) {
25379732SKit.Chow@Sun.COM /*
25389732SKit.Chow@Sun.COM * current range spans more than 1 memory node.
25399732SKit.Chow@Sun.COM * Set num to only the pfn range in the start
25409732SKit.Chow@Sun.COM * memory node.
25419732SKit.Chow@Sun.COM */
25429732SKit.Chow@Sun.COM num = mem_node_config[ms].physmax - base_pfn
25439732SKit.Chow@Sun.COM + 1;
25449732SKit.Chow@Sun.COM ASSERT(end_pfn > mem_node_config[ms].physmax);
25459732SKit.Chow@Sun.COM }
25460Sstevel@tonic-gate }
25479732SKit.Chow@Sun.COM
25489732SKit.Chow@Sun.COM for (;;) {
25499732SKit.Chow@Sun.COM /*
25509732SKit.Chow@Sun.COM * Build the memsegs entry
25519732SKit.Chow@Sun.COM */
25529732SKit.Chow@Sun.COM cur_memseg->pages = pp;
25539732SKit.Chow@Sun.COM cur_memseg->epages = pp + num;
25549732SKit.Chow@Sun.COM cur_memseg->pages_base = base_pfn;
25559732SKit.Chow@Sun.COM cur_memseg->pages_end = base_pfn + num;
25569732SKit.Chow@Sun.COM
25579732SKit.Chow@Sun.COM /*
25589732SKit.Chow@Sun.COM * Insert into memseg list in decreasing pfn range
25599732SKit.Chow@Sun.COM * order. Low memory is typically more fragmented such
25609732SKit.Chow@Sun.COM * that this ordering keeps the larger ranges at the
25619732SKit.Chow@Sun.COM * front of the list for code that searches memseg.
25629732SKit.Chow@Sun.COM * This ASSERTS that the memsegs coming in from boot
25639732SKit.Chow@Sun.COM * are in increasing physical address order and not
25649732SKit.Chow@Sun.COM * contiguous.
25659732SKit.Chow@Sun.COM */
25669732SKit.Chow@Sun.COM if (memsegs != NULL) {
25679732SKit.Chow@Sun.COM ASSERT(cur_memseg->pages_base >=
25689732SKit.Chow@Sun.COM memsegs->pages_end);
25699732SKit.Chow@Sun.COM cur_memseg->next = memsegs;
25709732SKit.Chow@Sun.COM }
25719732SKit.Chow@Sun.COM memsegs = cur_memseg;
25729732SKit.Chow@Sun.COM
25739732SKit.Chow@Sun.COM /*
25749732SKit.Chow@Sun.COM * add_physmem() initializes the PSM part of the page
25759732SKit.Chow@Sun.COM * struct by calling the PSM back with add_physmem_cb().
25769732SKit.Chow@Sun.COM * In addition it coalesces pages into larger pages as
25779732SKit.Chow@Sun.COM * it initializes them.
25789732SKit.Chow@Sun.COM */
25799732SKit.Chow@Sun.COM add_physmem(pp, num, base_pfn);
25809732SKit.Chow@Sun.COM cur_memseg++;
25819732SKit.Chow@Sun.COM availrmem_initial += num;
25829732SKit.Chow@Sun.COM availrmem += num;
25839732SKit.Chow@Sun.COM
25849732SKit.Chow@Sun.COM pp += num;
25859732SKit.Chow@Sun.COM if (ms >= me)
25869732SKit.Chow@Sun.COM break;
25879732SKit.Chow@Sun.COM
25889732SKit.Chow@Sun.COM /* process next memory node range */
25899732SKit.Chow@Sun.COM ms++;
25909732SKit.Chow@Sun.COM base_pfn = mem_node_config[ms].physbase;
25919732SKit.Chow@Sun.COM num = MIN(mem_node_config[ms].physmax,
25929732SKit.Chow@Sun.COM end_pfn) - base_pfn + 1;
25939732SKit.Chow@Sun.COM }
25940Sstevel@tonic-gate }
25950Sstevel@tonic-gate
25960Sstevel@tonic-gate PRM_DEBUG(availrmem_initial);
25970Sstevel@tonic-gate PRM_DEBUG(availrmem);
25980Sstevel@tonic-gate PRM_DEBUG(freemem);
25990Sstevel@tonic-gate build_pfn_hash();
26000Sstevel@tonic-gate return (pages_done);
26010Sstevel@tonic-gate }
26020Sstevel@tonic-gate
26030Sstevel@tonic-gate /*
26040Sstevel@tonic-gate * Kernel VM initialization.
26050Sstevel@tonic-gate */
26060Sstevel@tonic-gate static void
kvm_init(void)26070Sstevel@tonic-gate kvm_init(void)
26080Sstevel@tonic-gate {
26090Sstevel@tonic-gate ASSERT((((uintptr_t)s_text) & MMU_PAGEOFFSET) == 0);
26100Sstevel@tonic-gate
26110Sstevel@tonic-gate /*
26120Sstevel@tonic-gate * Put the kernel segments in kernel address space.
26130Sstevel@tonic-gate */
26140Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER);
26150Sstevel@tonic-gate as_avlinit(&kas);
26160Sstevel@tonic-gate
26170Sstevel@tonic-gate (void) seg_attach(&kas, s_text, e_moddata - s_text, &ktextseg);
26180Sstevel@tonic-gate (void) segkmem_create(&ktextseg);
26190Sstevel@tonic-gate
26200Sstevel@tonic-gate (void) seg_attach(&kas, (caddr_t)valloc_base, valloc_sz, &kvalloc);
26210Sstevel@tonic-gate (void) segkmem_create(&kvalloc);
26220Sstevel@tonic-gate
26234828Sjosephb (void) seg_attach(&kas, kernelheap,
26244828Sjosephb ekernelheap - kernelheap, &kvseg);
26250Sstevel@tonic-gate (void) segkmem_create(&kvseg);
26260Sstevel@tonic-gate
26273446Smrj if (core_size > 0) {
26283446Smrj PRM_POINT("attaching kvseg_core");
26293446Smrj (void) seg_attach(&kas, (caddr_t)core_base, core_size,
26303446Smrj &kvseg_core);
26313446Smrj (void) segkmem_create(&kvseg_core);
26323446Smrj }
26333290Sjohansen
26343446Smrj if (segziosize > 0) {
26353446Smrj PRM_POINT("attaching segzio");
26363290Sjohansen (void) seg_attach(&kas, segzio_base, mmu_ptob(segziosize),
26373290Sjohansen &kzioseg);
26383290Sjohansen (void) segkmem_zio_create(&kzioseg);
26393290Sjohansen
26403290Sjohansen /* create zio area covering new segment */
26413290Sjohansen segkmem_zio_init(segzio_base, mmu_ptob(segziosize));
26423290Sjohansen }
26430Sstevel@tonic-gate
26443446Smrj (void) seg_attach(&kas, kdi_segdebugbase, kdi_segdebugsize, &kdebugseg);
26450Sstevel@tonic-gate (void) segkmem_create(&kdebugseg);
26460Sstevel@tonic-gate
26470Sstevel@tonic-gate rw_exit(&kas.a_lock);
26480Sstevel@tonic-gate
26490Sstevel@tonic-gate /*
26500Sstevel@tonic-gate * Ensure that the red zone at kernelbase is never accessible.
26510Sstevel@tonic-gate */
26523446Smrj PRM_POINT("protecting redzone");
26530Sstevel@tonic-gate (void) as_setprot(&kas, (caddr_t)kernelbase, KERNEL_REDZONE_SIZE, 0);
26540Sstevel@tonic-gate
26550Sstevel@tonic-gate /*
26560Sstevel@tonic-gate * Make the text writable so that it can be hot patched by DTrace.
26570Sstevel@tonic-gate */
26580Sstevel@tonic-gate (void) as_setprot(&kas, s_text, e_modtext - s_text,
26590Sstevel@tonic-gate PROT_READ | PROT_WRITE | PROT_EXEC);
26600Sstevel@tonic-gate
26610Sstevel@tonic-gate /*
26620Sstevel@tonic-gate * Make data writable until end.
26630Sstevel@tonic-gate */
26640Sstevel@tonic-gate (void) as_setprot(&kas, s_data, e_moddata - s_data,
26650Sstevel@tonic-gate PROT_READ | PROT_WRITE | PROT_EXEC);
26660Sstevel@tonic-gate }
26670Sstevel@tonic-gate
26685084Sjohnlev #ifndef __xpv
26690Sstevel@tonic-gate /*
26705159Sjohnlev * Solaris adds an entry for Write Combining caching to the PAT
26710Sstevel@tonic-gate */
26725159Sjohnlev static uint64_t pat_attr_reg = PAT_DEFAULT_ATTRIBUTE;
26730Sstevel@tonic-gate
26740Sstevel@tonic-gate void
pat_sync(void)26755159Sjohnlev pat_sync(void)
26760Sstevel@tonic-gate {
26775159Sjohnlev ulong_t cr0, cr0_orig, cr4;
26780Sstevel@tonic-gate
267912826Skuriakose.kuruvilla@oracle.com if (!is_x86_feature(x86_featureset, X86FSET_PAT))
26800Sstevel@tonic-gate return;
26815159Sjohnlev cr0_orig = cr0 = getcr0();
26825159Sjohnlev cr4 = getcr4();
26830Sstevel@tonic-gate
26845159Sjohnlev /* disable caching and flush all caches and TLBs */
26855159Sjohnlev cr0 |= CR0_CD;
26865159Sjohnlev cr0 &= ~CR0_NW;
26875159Sjohnlev setcr0(cr0);
26885159Sjohnlev invalidate_cache();
26895159Sjohnlev if (cr4 & CR4_PGE) {
26905159Sjohnlev setcr4(cr4 & ~(ulong_t)CR4_PGE);
26915159Sjohnlev setcr4(cr4);
26925159Sjohnlev } else {
26935159Sjohnlev reload_cr3();
26940Sstevel@tonic-gate }
26950Sstevel@tonic-gate
26965159Sjohnlev /* add our entry to the PAT */
26975159Sjohnlev wrmsr(REG_PAT, pat_attr_reg);
2698770Skucharsk
26995159Sjohnlev /* flush TLBs and cache again, then reenable cr0 caching */
27005159Sjohnlev if (cr4 & CR4_PGE) {
27015159Sjohnlev setcr4(cr4 & ~(ulong_t)CR4_PGE);
27025159Sjohnlev setcr4(cr4);
27035159Sjohnlev } else {
27045159Sjohnlev reload_cr3();
27050Sstevel@tonic-gate }
27060Sstevel@tonic-gate invalidate_cache();
27070Sstevel@tonic-gate setcr0(cr0_orig);
27080Sstevel@tonic-gate }
27090Sstevel@tonic-gate
27105159Sjohnlev #endif /* !__xpv */
27110Sstevel@tonic-gate
27127720SKen.Erickson@Sun.COM #if defined(_SOFT_HOSTID)
27137720SKen.Erickson@Sun.COM /*
27147720SKen.Erickson@Sun.COM * On platforms that do not have a hardware serial number, attempt
27157720SKen.Erickson@Sun.COM * to set one based on the contents of /etc/hostid. If this file does
27167720SKen.Erickson@Sun.COM * not exist, assume that we are to generate a new hostid and set
27177720SKen.Erickson@Sun.COM * it in the kernel, for subsequent saving by a userland process
27187720SKen.Erickson@Sun.COM * once the system is up and the root filesystem is mounted r/w.
27197720SKen.Erickson@Sun.COM *
27207942SKen.Erickson@Sun.COM * In order to gracefully support upgrade on OpenSolaris, if
27217942SKen.Erickson@Sun.COM * /etc/hostid does not exist, we will attempt to get a serial number
27227942SKen.Erickson@Sun.COM * using the legacy method (/kernel/misc/sysinit).
27237942SKen.Erickson@Sun.COM *
27247720SKen.Erickson@Sun.COM * In an attempt to make the hostid less prone to abuse
27257720SKen.Erickson@Sun.COM * (for license circumvention, etc), we store it in /etc/hostid
27267720SKen.Erickson@Sun.COM * in rot47 format.
27277720SKen.Erickson@Sun.COM */
27287720SKen.Erickson@Sun.COM extern volatile unsigned long tenmicrodata;
27297942SKen.Erickson@Sun.COM static int atoi(char *);
27307720SKen.Erickson@Sun.COM
27317720SKen.Erickson@Sun.COM static int32_t
set_soft_hostid(void)27327720SKen.Erickson@Sun.COM set_soft_hostid(void)
27337720SKen.Erickson@Sun.COM {
27347720SKen.Erickson@Sun.COM struct _buf *file;
27357720SKen.Erickson@Sun.COM char tokbuf[MAXNAMELEN];
27367720SKen.Erickson@Sun.COM token_t token;
27377720SKen.Erickson@Sun.COM int done = 0;
27387720SKen.Erickson@Sun.COM u_longlong_t tmp;
27397942SKen.Erickson@Sun.COM int i;
27408662SJordan.Vaughan@Sun.com int32_t hostid = (int32_t)HW_INVALID_HOSTID;
27417720SKen.Erickson@Sun.COM unsigned char *c;
27427720SKen.Erickson@Sun.COM hrtime_t tsc;
27437720SKen.Erickson@Sun.COM
27447720SKen.Erickson@Sun.COM /*
27457720SKen.Erickson@Sun.COM * If /etc/hostid file not found, we'd like to get a pseudo
27467720SKen.Erickson@Sun.COM * random number to use at the hostid. A nice way to do this
27477720SKen.Erickson@Sun.COM * is to read the real time clock. To remain xen-compatible,
27487720SKen.Erickson@Sun.COM * we can't poke the real hardware, so we use tsc_read() to
27497720SKen.Erickson@Sun.COM * read the real time clock. However, there is an ominous
27507720SKen.Erickson@Sun.COM * warning in tsc_read that says it can return zero, so we
27517720SKen.Erickson@Sun.COM * deal with that possibility by falling back to using the
27527720SKen.Erickson@Sun.COM * (hopefully random enough) value in tenmicrodata.
27537720SKen.Erickson@Sun.COM */
27547720SKen.Erickson@Sun.COM
27557720SKen.Erickson@Sun.COM if ((file = kobj_open_file(hostid_file)) == (struct _buf *)-1) {
27567942SKen.Erickson@Sun.COM /*
27577942SKen.Erickson@Sun.COM * hostid file not found - try to load sysinit module
27587942SKen.Erickson@Sun.COM * and see if it has a nonzero hostid value...use that
27597942SKen.Erickson@Sun.COM * instead of generating a new hostid here if so.
27607942SKen.Erickson@Sun.COM */
27617942SKen.Erickson@Sun.COM if ((i = modload("misc", "sysinit")) != -1) {
27627942SKen.Erickson@Sun.COM if (strlen(hw_serial) > 0)
27637942SKen.Erickson@Sun.COM hostid = (int32_t)atoi(hw_serial);
27647942SKen.Erickson@Sun.COM (void) modunload(i);
27657942SKen.Erickson@Sun.COM }
27668662SJordan.Vaughan@Sun.com if (hostid == HW_INVALID_HOSTID) {
27677942SKen.Erickson@Sun.COM tsc = tsc_read();
27687942SKen.Erickson@Sun.COM if (tsc == 0) /* tsc_read can return zero sometimes */
27697942SKen.Erickson@Sun.COM hostid = (int32_t)tenmicrodata & 0x0CFFFFF;
27707942SKen.Erickson@Sun.COM else
27717942SKen.Erickson@Sun.COM hostid = (int32_t)tsc & 0x0CFFFFF;
27727942SKen.Erickson@Sun.COM }
27737720SKen.Erickson@Sun.COM } else {
27747720SKen.Erickson@Sun.COM /* hostid file found */
27757720SKen.Erickson@Sun.COM while (!done) {
27767720SKen.Erickson@Sun.COM token = kobj_lex(file, tokbuf, sizeof (tokbuf));
27777720SKen.Erickson@Sun.COM
27787720SKen.Erickson@Sun.COM switch (token) {
27797720SKen.Erickson@Sun.COM case POUND:
27807720SKen.Erickson@Sun.COM /*
27817720SKen.Erickson@Sun.COM * skip comments
27827720SKen.Erickson@Sun.COM */
27837720SKen.Erickson@Sun.COM kobj_find_eol(file);
27847720SKen.Erickson@Sun.COM break;
27857720SKen.Erickson@Sun.COM case STRING:
27867720SKen.Erickson@Sun.COM /*
27877720SKen.Erickson@Sun.COM * un-rot47 - obviously this
27887720SKen.Erickson@Sun.COM * nonsense is ascii-specific
27897720SKen.Erickson@Sun.COM */
27907720SKen.Erickson@Sun.COM for (c = (unsigned char *)tokbuf;
27917720SKen.Erickson@Sun.COM *c != '\0'; c++) {
27927720SKen.Erickson@Sun.COM *c += 47;
27937720SKen.Erickson@Sun.COM if (*c > '~')
27947720SKen.Erickson@Sun.COM *c -= 94;
27957720SKen.Erickson@Sun.COM else if (*c < '!')
27967720SKen.Erickson@Sun.COM *c += 94;
27977720SKen.Erickson@Sun.COM }
27987720SKen.Erickson@Sun.COM /*
27997720SKen.Erickson@Sun.COM * now we should have a real number
28007720SKen.Erickson@Sun.COM */
28017720SKen.Erickson@Sun.COM
28027720SKen.Erickson@Sun.COM if (kobj_getvalue(tokbuf, &tmp) != 0)
28037720SKen.Erickson@Sun.COM kobj_file_err(CE_WARN, file,
28047720SKen.Erickson@Sun.COM "Bad value %s for hostid",
28057720SKen.Erickson@Sun.COM tokbuf);
28067720SKen.Erickson@Sun.COM else
28077720SKen.Erickson@Sun.COM hostid = (int32_t)tmp;
28087720SKen.Erickson@Sun.COM
28097720SKen.Erickson@Sun.COM break;
28107720SKen.Erickson@Sun.COM case EOF:
28117720SKen.Erickson@Sun.COM done = 1;
28127720SKen.Erickson@Sun.COM /* FALLTHROUGH */
28137720SKen.Erickson@Sun.COM case NEWLINE:
28147720SKen.Erickson@Sun.COM kobj_newline(file);
28157720SKen.Erickson@Sun.COM break;
28167720SKen.Erickson@Sun.COM default:
28177720SKen.Erickson@Sun.COM break;
28187720SKen.Erickson@Sun.COM
28197720SKen.Erickson@Sun.COM }
28207720SKen.Erickson@Sun.COM }
28218662SJordan.Vaughan@Sun.com if (hostid == HW_INVALID_HOSTID) /* didn't find a hostid */
28227720SKen.Erickson@Sun.COM kobj_file_err(CE_WARN, file,
28237720SKen.Erickson@Sun.COM "hostid missing or corrupt");
28247720SKen.Erickson@Sun.COM
28257720SKen.Erickson@Sun.COM kobj_close_file(file);
28267720SKen.Erickson@Sun.COM }
28277720SKen.Erickson@Sun.COM /*
28287720SKen.Erickson@Sun.COM * hostid is now the value read from /etc/hostid, or the
28298662SJordan.Vaughan@Sun.com * new hostid we generated in this routine or HW_INVALID_HOSTID if not
28308662SJordan.Vaughan@Sun.com * set.
28317720SKen.Erickson@Sun.COM */
28327720SKen.Erickson@Sun.COM return (hostid);
28337720SKen.Erickson@Sun.COM }
28347942SKen.Erickson@Sun.COM
28357942SKen.Erickson@Sun.COM static int
atoi(char * p)28367942SKen.Erickson@Sun.COM atoi(char *p)
28377942SKen.Erickson@Sun.COM {
28387942SKen.Erickson@Sun.COM int i = 0;
28397942SKen.Erickson@Sun.COM
28407942SKen.Erickson@Sun.COM while (*p != '\0')
28417942SKen.Erickson@Sun.COM i = 10 * i + (*p++ - '0');
28427942SKen.Erickson@Sun.COM
28437942SKen.Erickson@Sun.COM return (i);
28447942SKen.Erickson@Sun.COM }
28457942SKen.Erickson@Sun.COM
28467720SKen.Erickson@Sun.COM #endif /* _SOFT_HOSTID */
28477720SKen.Erickson@Sun.COM
28480Sstevel@tonic-gate void
get_system_configuration(void)28491676Sjpk get_system_configuration(void)
28500Sstevel@tonic-gate {
28510Sstevel@tonic-gate char prop[32];
28520Sstevel@tonic-gate u_longlong_t nodes_ll, cpus_pernode_ll, lvalue;
28530Sstevel@tonic-gate
28544828Sjosephb if (BOP_GETPROPLEN(bootops, "nodes") > sizeof (prop) ||
28554828Sjosephb BOP_GETPROP(bootops, "nodes", prop) < 0 ||
28564828Sjosephb kobj_getvalue(prop, &nodes_ll) == -1 ||
28574828Sjosephb nodes_ll > MAXNODES ||
28584828Sjosephb BOP_GETPROPLEN(bootops, "cpus_pernode") > sizeof (prop) ||
28594828Sjosephb BOP_GETPROP(bootops, "cpus_pernode", prop) < 0 ||
28604828Sjosephb kobj_getvalue(prop, &cpus_pernode_ll) == -1) {
28610Sstevel@tonic-gate system_hardware.hd_nodes = 1;
28620Sstevel@tonic-gate system_hardware.hd_cpus_per_node = 0;
28630Sstevel@tonic-gate } else {
28640Sstevel@tonic-gate system_hardware.hd_nodes = (int)nodes_ll;
28650Sstevel@tonic-gate system_hardware.hd_cpus_per_node = (int)cpus_pernode_ll;
28660Sstevel@tonic-gate }
28674828Sjosephb
28684828Sjosephb if (BOP_GETPROPLEN(bootops, "kernelbase") > sizeof (prop) ||
28694828Sjosephb BOP_GETPROP(bootops, "kernelbase", prop) < 0 ||
28704828Sjosephb kobj_getvalue(prop, &lvalue) == -1)
28714828Sjosephb eprom_kernelbase = NULL;
28720Sstevel@tonic-gate else
28734828Sjosephb eprom_kernelbase = (uintptr_t)lvalue;
28740Sstevel@tonic-gate
28754828Sjosephb if (BOP_GETPROPLEN(bootops, "segmapsize") > sizeof (prop) ||
28764828Sjosephb BOP_GETPROP(bootops, "segmapsize", prop) < 0 ||
28774828Sjosephb kobj_getvalue(prop, &lvalue) == -1)
28780Sstevel@tonic-gate segmapsize = SEGMAPDEFAULT;
28794828Sjosephb else
28800Sstevel@tonic-gate segmapsize = (uintptr_t)lvalue;
28810Sstevel@tonic-gate
28824828Sjosephb if (BOP_GETPROPLEN(bootops, "segmapfreelists") > sizeof (prop) ||
28834828Sjosephb BOP_GETPROP(bootops, "segmapfreelists", prop) < 0 ||
28844828Sjosephb kobj_getvalue(prop, &lvalue) == -1)
28850Sstevel@tonic-gate segmapfreelists = 0; /* use segmap driver default */
28864828Sjosephb else
28870Sstevel@tonic-gate segmapfreelists = (int)lvalue;
28881417Skchow
28894004Sjosephb /* physmem used to be here, but moved much earlier to fakebop.c */
28900Sstevel@tonic-gate }
28910Sstevel@tonic-gate
28920Sstevel@tonic-gate /*
28930Sstevel@tonic-gate * Add to a memory list.
28940Sstevel@tonic-gate * start = start of new memory segment
28950Sstevel@tonic-gate * len = length of new memory segment in bytes
28960Sstevel@tonic-gate * new = pointer to a new struct memlist
28970Sstevel@tonic-gate * memlistp = memory list to which to add segment.
28980Sstevel@tonic-gate */
28993446Smrj void
memlist_add(uint64_t start,uint64_t len,struct memlist * new,struct memlist ** memlistp)29000Sstevel@tonic-gate memlist_add(
29010Sstevel@tonic-gate uint64_t start,
29020Sstevel@tonic-gate uint64_t len,
29030Sstevel@tonic-gate struct memlist *new,
29040Sstevel@tonic-gate struct memlist **memlistp)
29050Sstevel@tonic-gate {
29060Sstevel@tonic-gate struct memlist *cur;
29070Sstevel@tonic-gate uint64_t end = start + len;
29080Sstevel@tonic-gate
290911474SJonathan.Adams@Sun.COM new->ml_address = start;
291011474SJonathan.Adams@Sun.COM new->ml_size = len;
29110Sstevel@tonic-gate
29120Sstevel@tonic-gate cur = *memlistp;
29130Sstevel@tonic-gate
29140Sstevel@tonic-gate while (cur) {
291511474SJonathan.Adams@Sun.COM if (cur->ml_address >= end) {
291611474SJonathan.Adams@Sun.COM new->ml_next = cur;
29170Sstevel@tonic-gate *memlistp = new;
291811474SJonathan.Adams@Sun.COM new->ml_prev = cur->ml_prev;
291911474SJonathan.Adams@Sun.COM cur->ml_prev = new;
29200Sstevel@tonic-gate return;
29210Sstevel@tonic-gate }
292211474SJonathan.Adams@Sun.COM ASSERT(cur->ml_address + cur->ml_size <= start);
292311474SJonathan.Adams@Sun.COM if (cur->ml_next == NULL) {
292411474SJonathan.Adams@Sun.COM cur->ml_next = new;
292511474SJonathan.Adams@Sun.COM new->ml_prev = cur;
292611474SJonathan.Adams@Sun.COM new->ml_next = NULL;
29270Sstevel@tonic-gate return;
29280Sstevel@tonic-gate }
292911474SJonathan.Adams@Sun.COM memlistp = &cur->ml_next;
293011474SJonathan.Adams@Sun.COM cur = cur->ml_next;
29310Sstevel@tonic-gate }
29320Sstevel@tonic-gate }
29330Sstevel@tonic-gate
29340Sstevel@tonic-gate void
kobj_vmem_init(vmem_t ** text_arena,vmem_t ** data_arena)29350Sstevel@tonic-gate kobj_vmem_init(vmem_t **text_arena, vmem_t **data_arena)
29360Sstevel@tonic-gate {
29370Sstevel@tonic-gate size_t tsize = e_modtext - modtext;
29380Sstevel@tonic-gate size_t dsize = e_moddata - moddata;
29390Sstevel@tonic-gate
29400Sstevel@tonic-gate *text_arena = vmem_create("module_text", tsize ? modtext : NULL, tsize,
29410Sstevel@tonic-gate 1, segkmem_alloc, segkmem_free, heaptext_arena, 0, VM_SLEEP);
29420Sstevel@tonic-gate *data_arena = vmem_create("module_data", dsize ? moddata : NULL, dsize,
29430Sstevel@tonic-gate 1, segkmem_alloc, segkmem_free, heap32_arena, 0, VM_SLEEP);
29440Sstevel@tonic-gate }
29450Sstevel@tonic-gate
29460Sstevel@tonic-gate caddr_t
kobj_text_alloc(vmem_t * arena,size_t size)29470Sstevel@tonic-gate kobj_text_alloc(vmem_t *arena, size_t size)
29480Sstevel@tonic-gate {
29490Sstevel@tonic-gate return (vmem_alloc(arena, size, VM_SLEEP | VM_BESTFIT));
29500Sstevel@tonic-gate }
29510Sstevel@tonic-gate
29520Sstevel@tonic-gate /*ARGSUSED*/
29530Sstevel@tonic-gate caddr_t
kobj_texthole_alloc(caddr_t addr,size_t size)29540Sstevel@tonic-gate kobj_texthole_alloc(caddr_t addr, size_t size)
29550Sstevel@tonic-gate {
29560Sstevel@tonic-gate panic("unexpected call to kobj_texthole_alloc()");
29570Sstevel@tonic-gate /*NOTREACHED*/
29580Sstevel@tonic-gate return (0);
29590Sstevel@tonic-gate }
29600Sstevel@tonic-gate
29610Sstevel@tonic-gate /*ARGSUSED*/
29620Sstevel@tonic-gate void
kobj_texthole_free(caddr_t addr,size_t size)29630Sstevel@tonic-gate kobj_texthole_free(caddr_t addr, size_t size)
29640Sstevel@tonic-gate {
29650Sstevel@tonic-gate panic("unexpected call to kobj_texthole_free()");
29660Sstevel@tonic-gate }
29670Sstevel@tonic-gate
29680Sstevel@tonic-gate /*
29690Sstevel@tonic-gate * This is called just after configure() in startup().
29700Sstevel@tonic-gate *
29710Sstevel@tonic-gate * The ISALIST concept is a bit hopeless on Intel, because
29720Sstevel@tonic-gate * there's no guarantee of an ever-more-capable processor
29730Sstevel@tonic-gate * given that various parts of the instruction set may appear
29740Sstevel@tonic-gate * and disappear between different implementations.
29750Sstevel@tonic-gate *
29760Sstevel@tonic-gate * While it would be possible to correct it and even enhance
29770Sstevel@tonic-gate * it somewhat, the explicit hardware capability bitmask allows
29780Sstevel@tonic-gate * more flexibility.
29790Sstevel@tonic-gate *
29800Sstevel@tonic-gate * So, we just leave this alone.
29810Sstevel@tonic-gate */
29820Sstevel@tonic-gate void
setx86isalist(void)29830Sstevel@tonic-gate setx86isalist(void)
29840Sstevel@tonic-gate {
29850Sstevel@tonic-gate char *tp;
29860Sstevel@tonic-gate size_t len;
29870Sstevel@tonic-gate extern char *isa_list;
29880Sstevel@tonic-gate
29890Sstevel@tonic-gate #define TBUFSIZE 1024
29900Sstevel@tonic-gate
29910Sstevel@tonic-gate tp = kmem_alloc(TBUFSIZE, KM_SLEEP);
29920Sstevel@tonic-gate *tp = '\0';
29930Sstevel@tonic-gate
29940Sstevel@tonic-gate #if defined(__amd64)
29950Sstevel@tonic-gate (void) strcpy(tp, "amd64 ");
29960Sstevel@tonic-gate #endif
29970Sstevel@tonic-gate
29980Sstevel@tonic-gate switch (x86_vendor) {
29990Sstevel@tonic-gate case X86_VENDOR_Intel:
30000Sstevel@tonic-gate case X86_VENDOR_AMD:
30010Sstevel@tonic-gate case X86_VENDOR_TM:
300212826Skuriakose.kuruvilla@oracle.com if (is_x86_feature(x86_featureset, X86FSET_CMOV)) {
30030Sstevel@tonic-gate /*
30040Sstevel@tonic-gate * Pentium Pro or later
30050Sstevel@tonic-gate */
30060Sstevel@tonic-gate (void) strcat(tp, "pentium_pro");
300712826Skuriakose.kuruvilla@oracle.com (void) strcat(tp,
300812826Skuriakose.kuruvilla@oracle.com is_x86_feature(x86_featureset, X86FSET_MMX) ?
30090Sstevel@tonic-gate "+mmx pentium_pro " : " ");
30100Sstevel@tonic-gate }
30110Sstevel@tonic-gate /*FALLTHROUGH*/
30120Sstevel@tonic-gate case X86_VENDOR_Cyrix:
30130Sstevel@tonic-gate /*
30140Sstevel@tonic-gate * The Cyrix 6x86 does not have any Pentium features
30150Sstevel@tonic-gate * accessible while not at privilege level 0.
30160Sstevel@tonic-gate */
301712826Skuriakose.kuruvilla@oracle.com if (is_x86_feature(x86_featureset, X86FSET_CPUID)) {
30180Sstevel@tonic-gate (void) strcat(tp, "pentium");
301912826Skuriakose.kuruvilla@oracle.com (void) strcat(tp,
302012826Skuriakose.kuruvilla@oracle.com is_x86_feature(x86_featureset, X86FSET_MMX) ?
30210Sstevel@tonic-gate "+mmx pentium " : " ");
30220Sstevel@tonic-gate }
30230Sstevel@tonic-gate break;
30240Sstevel@tonic-gate default:
30250Sstevel@tonic-gate break;
30260Sstevel@tonic-gate }
30270Sstevel@tonic-gate (void) strcat(tp, "i486 i386 i86");
30280Sstevel@tonic-gate len = strlen(tp) + 1; /* account for NULL at end of string */
30290Sstevel@tonic-gate isa_list = strcpy(kmem_alloc(len, KM_SLEEP), tp);
30300Sstevel@tonic-gate kmem_free(tp, TBUFSIZE);
30310Sstevel@tonic-gate
30320Sstevel@tonic-gate #undef TBUFSIZE
30330Sstevel@tonic-gate }
30340Sstevel@tonic-gate
30350Sstevel@tonic-gate
30360Sstevel@tonic-gate #ifdef __amd64
30370Sstevel@tonic-gate
30380Sstevel@tonic-gate void *
device_arena_alloc(size_t size,int vm_flag)30390Sstevel@tonic-gate device_arena_alloc(size_t size, int vm_flag)
30400Sstevel@tonic-gate {
30410Sstevel@tonic-gate return (vmem_alloc(device_arena, size, vm_flag));
30420Sstevel@tonic-gate }
30430Sstevel@tonic-gate
30440Sstevel@tonic-gate void
device_arena_free(void * vaddr,size_t size)30450Sstevel@tonic-gate device_arena_free(void *vaddr, size_t size)
30460Sstevel@tonic-gate {
30470Sstevel@tonic-gate vmem_free(device_arena, vaddr, size);
30480Sstevel@tonic-gate }
30490Sstevel@tonic-gate
30503446Smrj #else /* __i386 */
30510Sstevel@tonic-gate
30520Sstevel@tonic-gate void *
device_arena_alloc(size_t size,int vm_flag)30530Sstevel@tonic-gate device_arena_alloc(size_t size, int vm_flag)
30540Sstevel@tonic-gate {
30550Sstevel@tonic-gate caddr_t vaddr;
30560Sstevel@tonic-gate uintptr_t v;
30570Sstevel@tonic-gate size_t start;
30580Sstevel@tonic-gate size_t end;
30590Sstevel@tonic-gate
30600Sstevel@tonic-gate vaddr = vmem_alloc(heap_arena, size, vm_flag);
30610Sstevel@tonic-gate if (vaddr == NULL)
30620Sstevel@tonic-gate return (NULL);
30630Sstevel@tonic-gate
30640Sstevel@tonic-gate v = (uintptr_t)vaddr;
30650Sstevel@tonic-gate ASSERT(v >= kernelbase);
30663446Smrj ASSERT(v + size <= valloc_base);
30670Sstevel@tonic-gate
30680Sstevel@tonic-gate start = btop(v - kernelbase);
30690Sstevel@tonic-gate end = btop(v + size - 1 - kernelbase);
30700Sstevel@tonic-gate ASSERT(start < toxic_bit_map_len);
30710Sstevel@tonic-gate ASSERT(end < toxic_bit_map_len);
30720Sstevel@tonic-gate
30730Sstevel@tonic-gate while (start <= end) {
30740Sstevel@tonic-gate BT_ATOMIC_SET(toxic_bit_map, start);
30750Sstevel@tonic-gate ++start;
30760Sstevel@tonic-gate }
30770Sstevel@tonic-gate return (vaddr);
30780Sstevel@tonic-gate }
30790Sstevel@tonic-gate
30800Sstevel@tonic-gate void
device_arena_free(void * vaddr,size_t size)30810Sstevel@tonic-gate device_arena_free(void *vaddr, size_t size)
30820Sstevel@tonic-gate {
30830Sstevel@tonic-gate uintptr_t v = (uintptr_t)vaddr;
30840Sstevel@tonic-gate size_t start;
30850Sstevel@tonic-gate size_t end;
30860Sstevel@tonic-gate
30870Sstevel@tonic-gate ASSERT(v >= kernelbase);
30883446Smrj ASSERT(v + size <= valloc_base);
30890Sstevel@tonic-gate
30900Sstevel@tonic-gate start = btop(v - kernelbase);
30910Sstevel@tonic-gate end = btop(v + size - 1 - kernelbase);
30920Sstevel@tonic-gate ASSERT(start < toxic_bit_map_len);
30930Sstevel@tonic-gate ASSERT(end < toxic_bit_map_len);
30940Sstevel@tonic-gate
30950Sstevel@tonic-gate while (start <= end) {
30960Sstevel@tonic-gate ASSERT(BT_TEST(toxic_bit_map, start) != 0);
30970Sstevel@tonic-gate BT_ATOMIC_CLEAR(toxic_bit_map, start);
30980Sstevel@tonic-gate ++start;
30990Sstevel@tonic-gate }
31000Sstevel@tonic-gate vmem_free(heap_arena, vaddr, size);
31010Sstevel@tonic-gate }
31020Sstevel@tonic-gate
31030Sstevel@tonic-gate /*
31040Sstevel@tonic-gate * returns 1st address in range that is in device arena, or NULL
31050Sstevel@tonic-gate * if len is not NULL it returns the length of the toxic range
31060Sstevel@tonic-gate */
31070Sstevel@tonic-gate void *
device_arena_contains(void * vaddr,size_t size,size_t * len)31080Sstevel@tonic-gate device_arena_contains(void *vaddr, size_t size, size_t *len)
31090Sstevel@tonic-gate {
31100Sstevel@tonic-gate uintptr_t v = (uintptr_t)vaddr;
31110Sstevel@tonic-gate uintptr_t eaddr = v + size;
31120Sstevel@tonic-gate size_t start;
31130Sstevel@tonic-gate size_t end;
31140Sstevel@tonic-gate
31150Sstevel@tonic-gate /*
31160Sstevel@tonic-gate * if called very early by kmdb, just return NULL
31170Sstevel@tonic-gate */
31180Sstevel@tonic-gate if (toxic_bit_map == NULL)
31190Sstevel@tonic-gate return (NULL);
31200Sstevel@tonic-gate
31210Sstevel@tonic-gate /*
31220Sstevel@tonic-gate * First check if we're completely outside the bitmap range.
31230Sstevel@tonic-gate */
31243446Smrj if (v >= valloc_base || eaddr < kernelbase)
31250Sstevel@tonic-gate return (NULL);
31260Sstevel@tonic-gate
31270Sstevel@tonic-gate /*
31280Sstevel@tonic-gate * Trim ends of search to look at only what the bitmap covers.
31290Sstevel@tonic-gate */
31300Sstevel@tonic-gate if (v < kernelbase)
31310Sstevel@tonic-gate v = kernelbase;
31320Sstevel@tonic-gate start = btop(v - kernelbase);
31330Sstevel@tonic-gate end = btop(eaddr - kernelbase);
31340Sstevel@tonic-gate if (end >= toxic_bit_map_len)
31350Sstevel@tonic-gate end = toxic_bit_map_len;
31360Sstevel@tonic-gate
31370Sstevel@tonic-gate if (bt_range(toxic_bit_map, &start, &end, end) == 0)
31380Sstevel@tonic-gate return (NULL);
31390Sstevel@tonic-gate
31400Sstevel@tonic-gate v = kernelbase + ptob(start);
31410Sstevel@tonic-gate if (len != NULL)
31420Sstevel@tonic-gate *len = ptob(end - start);
31430Sstevel@tonic-gate return ((void *)v);
31440Sstevel@tonic-gate }
31450Sstevel@tonic-gate
31463446Smrj #endif /* __i386 */
3147