17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5100b72f4Sandrei * Common Development and Distribution License (the "License"). 6100b72f4Sandrei * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 2256f33205SJonathan Adams * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <sys/types.h> 277c478bd9Sstevel@tonic-gate #include <sys/t_lock.h> 287c478bd9Sstevel@tonic-gate #include <sys/param.h> 297c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 307c478bd9Sstevel@tonic-gate #include <sys/signal.h> 317c478bd9Sstevel@tonic-gate #include <sys/systm.h> 327c478bd9Sstevel@tonic-gate #include <sys/user.h> 337c478bd9Sstevel@tonic-gate #include <sys/mman.h> 347c478bd9Sstevel@tonic-gate #include <sys/vm.h> 357c478bd9Sstevel@tonic-gate #include <sys/conf.h> 367c478bd9Sstevel@tonic-gate #include <sys/avintr.h> 377c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 387c478bd9Sstevel@tonic-gate #include <sys/disp.h> 397c478bd9Sstevel@tonic-gate #include <sys/class.h> 407c478bd9Sstevel@tonic-gate #include <sys/bitmap.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #include <sys/privregs.h> 437c478bd9Sstevel@tonic-gate 447c478bd9Sstevel@tonic-gate #include <sys/proc.h> 457c478bd9Sstevel@tonic-gate #include <sys/buf.h> 467c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 47ae115bc7Smrj #include <sys/mem.h> 487c478bd9Sstevel@tonic-gate #include <sys/kstat.h> 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate #include <sys/reboot.h> 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate #include <sys/cred.h> 537c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 547c478bd9Sstevel@tonic-gate #include <sys/file.h> 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #include <sys/procfs.h> 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate #include <sys/vfs.h> 597c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 607c478bd9Sstevel@tonic-gate #include <sys/utsname.h> 617c478bd9Sstevel@tonic-gate #include <sys/debug.h> 627c478bd9Sstevel@tonic-gate #include <sys/kdi.h> 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate #include <sys/dumphdr.h> 657c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 667c478bd9Sstevel@tonic-gate #include <sys/varargs.h> 677c478bd9Sstevel@tonic-gate #include <sys/promif.h> 68843e1988Sjohnlev #include <sys/modctl.h> 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 717c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 727c478bd9Sstevel@tonic-gate #include <sys/ndi_impldefs.h> 737c478bd9Sstevel@tonic-gate #include <sys/ddidmareq.h> 747c478bd9Sstevel@tonic-gate #include <sys/psw.h> 757c478bd9Sstevel@tonic-gate #include <sys/regset.h> 767c478bd9Sstevel@tonic-gate #include <sys/clock.h> 777c478bd9Sstevel@tonic-gate #include <sys/pte.h> 787c478bd9Sstevel@tonic-gate #include <sys/tss.h> 797c478bd9Sstevel@tonic-gate #include <sys/stack.h> 807c478bd9Sstevel@tonic-gate #include <sys/trap.h> 817c478bd9Sstevel@tonic-gate #include <sys/fp.h> 821d03c31eSjohnlev #include <vm/kboot_mmu.h> 837c478bd9Sstevel@tonic-gate #include <vm/anon.h> 847c478bd9Sstevel@tonic-gate #include <vm/as.h> 857c478bd9Sstevel@tonic-gate #include <vm/page.h> 867c478bd9Sstevel@tonic-gate #include <vm/seg.h> 877c478bd9Sstevel@tonic-gate #include <vm/seg_dev.h> 887c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h> 897c478bd9Sstevel@tonic-gate #include <vm/seg_kpm.h> 907c478bd9Sstevel@tonic-gate #include <vm/seg_map.h> 917c478bd9Sstevel@tonic-gate #include <vm/seg_vn.h> 927c478bd9Sstevel@tonic-gate #include <vm/seg_kp.h> 937c478bd9Sstevel@tonic-gate #include <sys/memnode.h> 947c478bd9Sstevel@tonic-gate #include <vm/vm_dep.h> 957c478bd9Sstevel@tonic-gate #include <sys/thread.h> 967c478bd9Sstevel@tonic-gate #include <sys/sysconf.h> 977c478bd9Sstevel@tonic-gate #include <sys/vm_machparam.h> 987c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 997c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 1007c478bd9Sstevel@tonic-gate #include <vm/hat.h> 1017c478bd9Sstevel@tonic-gate #include <vm/hat_i86.h> 1027c478bd9Sstevel@tonic-gate #include <sys/pmem.h> 1037c478bd9Sstevel@tonic-gate #include <sys/smp_impldefs.h> 1047c478bd9Sstevel@tonic-gate #include <sys/x86_archext.h> 105a563a037Sbholler #include <sys/cpuvar.h> 1067c478bd9Sstevel@tonic-gate #include <sys/segments.h> 1077c478bd9Sstevel@tonic-gate #include <sys/clconf.h> 1087c478bd9Sstevel@tonic-gate #include <sys/kobj.h> 1097c478bd9Sstevel@tonic-gate #include <sys/kobj_lex.h> 1107c478bd9Sstevel@tonic-gate #include <sys/cpc_impl.h> 1117aec1d6eScindi #include <sys/cpu_module.h> 11284ab085aSmws #include <sys/smbios.h> 113ae115bc7Smrj #include <sys/debug_info.h> 1141d03c31eSjohnlev #include <sys/bootinfo.h> 115dd4eeefdSeota #include <sys/ddi_timer.h> 1165679c89fSjv227347 #include <sys/systeminfo.h> 11719397407SSherry Moore #include <sys/multiboot.h> 118ae115bc7Smrj 119843e1988Sjohnlev #ifdef __xpv 1201d03c31eSjohnlev 121843e1988Sjohnlev #include <sys/hypervisor.h> 122843e1988Sjohnlev #include <sys/xen_mmu.h> 123843e1988Sjohnlev #include <sys/evtchn_impl.h> 124843e1988Sjohnlev #include <sys/gnttab.h> 125843e1988Sjohnlev #include <sys/xpv_panic.h> 126843e1988Sjohnlev #include <xen/sys/xenbus_comms.h> 127843e1988Sjohnlev #include <xen/public/physdev.h> 128ae115bc7Smrj 1291d03c31eSjohnlev extern void xen_late_startup(void); 1301d03c31eSjohnlev 1311d03c31eSjohnlev struct xen_evt_data cpu0_evt_data; 1321d03c31eSjohnlev 1331d03c31eSjohnlev #endif /* __xpv */ 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate extern void progressbar_init(void); 1369acbbeafSnn35248 extern void brand_init(void); 13706fb6a36Sdv142724 extern void pcf_init(void); 1380e751525SEric Saxe extern void pg_init(void); 1397c478bd9Sstevel@tonic-gate 140d7d93655Sblakej extern int size_pse_array(pgcnt_t, int); 141d7d93655Sblakej 142ed5289f9SKen Erickson #if defined(_SOFT_HOSTID) 143ed5289f9SKen Erickson 144ed5289f9SKen Erickson #include <sys/rtc.h> 145ed5289f9SKen Erickson 146ed5289f9SKen Erickson static int32_t set_soft_hostid(void); 147ed5289f9SKen Erickson static char hostid_file[] = "/etc/hostid"; 148ed5289f9SKen Erickson 149ed5289f9SKen Erickson #endif 150ed5289f9SKen Erickson 15194f1124eSVikram Hegde void *gfx_devinfo_list; 152ed5289f9SKen Erickson 1533a634bfcSVikram Hegde #if defined(__amd64) && !defined(__xpv) 1543a634bfcSVikram Hegde extern void immu_startup(void); 1553a634bfcSVikram Hegde #endif 1563a634bfcSVikram Hegde 1577c478bd9Sstevel@tonic-gate /* 1587c478bd9Sstevel@tonic-gate * XXX make declaration below "static" when drivers no longer use this 1597c478bd9Sstevel@tonic-gate * interface. 1607c478bd9Sstevel@tonic-gate */ 1617c478bd9Sstevel@tonic-gate extern caddr_t p0_va; /* Virtual address for accessing physical page 0 */ 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate /* 1647c478bd9Sstevel@tonic-gate * segkp 1657c478bd9Sstevel@tonic-gate */ 1667c478bd9Sstevel@tonic-gate extern int segkp_fromheap; 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate static void kvm_init(void); 1697c478bd9Sstevel@tonic-gate static void startup_init(void); 1707c478bd9Sstevel@tonic-gate static void startup_memlist(void); 171ae115bc7Smrj static void startup_kmem(void); 1727c478bd9Sstevel@tonic-gate static void startup_modules(void); 1737c478bd9Sstevel@tonic-gate static void startup_vm(void); 1747c478bd9Sstevel@tonic-gate static void startup_end(void); 17535b1ab99Sjosephb static void layout_kernel_va(void); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate /* 1787c478bd9Sstevel@tonic-gate * Declare these as initialized data so we can patch them. 1797c478bd9Sstevel@tonic-gate */ 180f53ad214Skchow #ifdef __i386 18135b1ab99Sjosephb 182f53ad214Skchow /* 183f53ad214Skchow * Due to virtual address space limitations running in 32 bit mode, restrict 18435b1ab99Sjosephb * the amount of physical memory configured to a max of PHYSMEM pages (16g). 185f53ad214Skchow * 186f53ad214Skchow * If the physical max memory size of 64g were allowed to be configured, the 187f53ad214Skchow * size of user virtual address space will be less than 1g. A limited user 188f53ad214Skchow * address space greatly reduces the range of applications that can run. 189f53ad214Skchow * 19035b1ab99Sjosephb * If more physical memory than PHYSMEM is required, users should preferably 19135b1ab99Sjosephb * run in 64 bit mode which has far looser virtual address space limitations. 192f53ad214Skchow * 193f53ad214Skchow * If 64 bit mode is not available (as in IA32) and/or more physical memory 19435b1ab99Sjosephb * than PHYSMEM is required in 32 bit mode, physmem can be set to the desired 195f53ad214Skchow * value or to 0 (to configure all available memory) via eeprom(1M). kernelbase 196f53ad214Skchow * should also be carefully tuned to balance out the need of the user 197f53ad214Skchow * application while minimizing the risk of kernel heap exhaustion due to 198f53ad214Skchow * kernelbase being set too high. 199f53ad214Skchow */ 20035b1ab99Sjosephb #define PHYSMEM 0x400000 201f53ad214Skchow 20235b1ab99Sjosephb #else /* __amd64 */ 20335b1ab99Sjosephb 20435b1ab99Sjosephb /* 20535b1ab99Sjosephb * For now we can handle memory with physical addresses up to about 20635b1ab99Sjosephb * 64 Terabytes. This keeps the kernel above the VA hole, leaving roughly 20735b1ab99Sjosephb * half the VA space for seg_kpm. When systems get bigger than 64TB this 20835b1ab99Sjosephb * code will need revisiting. There is an implicit assumption that there 20935b1ab99Sjosephb * are no *huge* holes in the physical address space too. 21035b1ab99Sjosephb */ 21135b1ab99Sjosephb #define TERABYTE (1ul << 40) 21235b1ab99Sjosephb #define PHYSMEM_MAX64 mmu_btop(64 * TERABYTE) 21335b1ab99Sjosephb #define PHYSMEM PHYSMEM_MAX64 21435b1ab99Sjosephb #define AMD64_VA_HOLE_END 0xFFFF800000000000ul 21535b1ab99Sjosephb 21635b1ab99Sjosephb #endif /* __amd64 */ 21735b1ab99Sjosephb 21835b1ab99Sjosephb pgcnt_t physmem = PHYSMEM; 2197c478bd9Sstevel@tonic-gate pgcnt_t obp_pages; /* Memory used by PROM for its text and data */ 2207c478bd9Sstevel@tonic-gate 2217c478bd9Sstevel@tonic-gate char *kobj_file_buf; 2227c478bd9Sstevel@tonic-gate int kobj_file_bufsize; /* set in /etc/system */ 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* Global variables for MP support. Used in mp_startup */ 22519397407SSherry Moore caddr_t rm_platter_va = 0; 2267c478bd9Sstevel@tonic-gate uint32_t rm_platter_pa; 2277c478bd9Sstevel@tonic-gate 22883f9b804Skchow int auto_lpg_disable = 1; 22983f9b804Skchow 2307c478bd9Sstevel@tonic-gate /* 2317c478bd9Sstevel@tonic-gate * Some CPUs have holes in the middle of the 64-bit virtual address range. 2327c478bd9Sstevel@tonic-gate */ 2337c478bd9Sstevel@tonic-gate uintptr_t hole_start, hole_end; 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate /* 2367c478bd9Sstevel@tonic-gate * kpm mapping window 2377c478bd9Sstevel@tonic-gate */ 2387c478bd9Sstevel@tonic-gate caddr_t kpm_vbase; 2397c478bd9Sstevel@tonic-gate size_t kpm_size; 24035b1ab99Sjosephb static int kpm_desired; 24135b1ab99Sjosephb #ifdef __amd64 24235b1ab99Sjosephb static uintptr_t segkpm_base = (uintptr_t)SEGKPM_BASE; 24335b1ab99Sjosephb #endif 2447c478bd9Sstevel@tonic-gate 2457c478bd9Sstevel@tonic-gate /* 2467c478bd9Sstevel@tonic-gate * Configuration parameters set at boot time. 2477c478bd9Sstevel@tonic-gate */ 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate caddr_t econtig; /* end of first block of contiguous kernel */ 2507c478bd9Sstevel@tonic-gate 2517c478bd9Sstevel@tonic-gate struct bootops *bootops = 0; /* passed in from boot */ 2527c478bd9Sstevel@tonic-gate struct bootops **bootopsp; 2537c478bd9Sstevel@tonic-gate struct boot_syscalls *sysp; /* passed in from boot */ 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate char bootblock_fstype[16]; 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate char kern_bootargs[OBP_MAXPATHLEN]; 25819397407SSherry Moore char kern_bootfile[OBP_MAXPATHLEN]; 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate /* 261ad23a2dbSjohansen * ZFS zio segment. This allows us to exclude large portions of ZFS data that 262ad23a2dbSjohansen * gets cached in kmem caches on the heap. If this is set to zero, we allocate 263ad23a2dbSjohansen * zio buffers from their own segment, otherwise they are allocated from the 264ad23a2dbSjohansen * heap. The optimization of allocating zio buffers from their own segment is 265ad23a2dbSjohansen * only valid on 64-bit kernels. 266ad23a2dbSjohansen */ 267ad23a2dbSjohansen #if defined(__amd64) 268ad23a2dbSjohansen int segzio_fromheap = 0; 269ad23a2dbSjohansen #else 270ad23a2dbSjohansen int segzio_fromheap = 1; 271ad23a2dbSjohansen #endif 272ad23a2dbSjohansen 273ad23a2dbSjohansen /* 2747c478bd9Sstevel@tonic-gate * new memory fragmentations are possible in startup() due to BOP_ALLOCs. this 2757c478bd9Sstevel@tonic-gate * depends on number of BOP_ALLOC calls made and requested size, memory size 2767c478bd9Sstevel@tonic-gate * combination and whether boot.bin memory needs to be freed. 2777c478bd9Sstevel@tonic-gate */ 2787c478bd9Sstevel@tonic-gate #define POSS_NEW_FRAGMENTS 12 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate /* 2817c478bd9Sstevel@tonic-gate * VM data structures 2827c478bd9Sstevel@tonic-gate */ 2837c478bd9Sstevel@tonic-gate long page_hashsz; /* Size of page hash table (power of two) */ 2847c478bd9Sstevel@tonic-gate struct page *pp_base; /* Base of initial system page struct array */ 2857c478bd9Sstevel@tonic-gate struct page **page_hash; /* Page hash table */ 286d7d93655Sblakej pad_mutex_t *pse_mutex; /* Locks protecting pp->p_selock */ 287d7d93655Sblakej size_t pse_table_size; /* Number of mutexes in pse_mutex[] */ 288d7d93655Sblakej int pse_shift; /* log2(pse_table_size) */ 2897c478bd9Sstevel@tonic-gate struct seg ktextseg; /* Segment used for kernel executable image */ 2907c478bd9Sstevel@tonic-gate struct seg kvalloc; /* Segment used for "valloc" mapping */ 2917c478bd9Sstevel@tonic-gate struct seg kpseg; /* Segment used for pageable kernel virt mem */ 2927c478bd9Sstevel@tonic-gate struct seg kmapseg; /* Segment used for generic kernel mappings */ 2937c478bd9Sstevel@tonic-gate struct seg kdebugseg; /* Segment used for the kernel debugger */ 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate struct seg *segkmap = &kmapseg; /* Kernel generic mapping segment */ 296ae115bc7Smrj static struct seg *segmap = &kmapseg; /* easier to use name for in here */ 297ae115bc7Smrj 2987c478bd9Sstevel@tonic-gate struct seg *segkp = &kpseg; /* Pageable kernel virtual memory segment */ 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate #if defined(__amd64) 3017c478bd9Sstevel@tonic-gate struct seg kvseg_core; /* Segment used for the core heap */ 3027c478bd9Sstevel@tonic-gate struct seg kpmseg; /* Segment used for physical mapping */ 3037c478bd9Sstevel@tonic-gate struct seg *segkpm = &kpmseg; /* 64bit kernel physical mapping segment */ 3047c478bd9Sstevel@tonic-gate #else 3057c478bd9Sstevel@tonic-gate struct seg *segkpm = NULL; /* Unused on IA32 */ 3067c478bd9Sstevel@tonic-gate #endif 3077c478bd9Sstevel@tonic-gate 3087c478bd9Sstevel@tonic-gate caddr_t segkp_base; /* Base address of segkp */ 309ad23a2dbSjohansen caddr_t segzio_base; /* Base address of segzio */ 3107c478bd9Sstevel@tonic-gate #if defined(__amd64) 3117c478bd9Sstevel@tonic-gate pgcnt_t segkpsize = btop(SEGKPDEFSIZE); /* size of segkp segment in pages */ 3127c478bd9Sstevel@tonic-gate #else 3137c478bd9Sstevel@tonic-gate pgcnt_t segkpsize = 0; 3147c478bd9Sstevel@tonic-gate #endif 315ad23a2dbSjohansen pgcnt_t segziosize = 0; /* size of zio segment in pages */ 3167c478bd9Sstevel@tonic-gate 317ae115bc7Smrj /* 318ae115bc7Smrj * VA range available to the debugger 319ae115bc7Smrj */ 320ae115bc7Smrj const caddr_t kdi_segdebugbase = (const caddr_t)SEGDEBUGBASE; 321ae115bc7Smrj const size_t kdi_segdebugsize = SEGDEBUGSIZE; 322ae115bc7Smrj 3237c478bd9Sstevel@tonic-gate struct memseg *memseg_base; 3247c478bd9Sstevel@tonic-gate struct vnode unused_pages_vp; 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate #define FOURGB 0x100000000LL 3277c478bd9Sstevel@tonic-gate 3287c478bd9Sstevel@tonic-gate struct memlist *memlist; 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate caddr_t s_text; /* start of kernel text segment */ 3317c478bd9Sstevel@tonic-gate caddr_t e_text; /* end of kernel text segment */ 3327c478bd9Sstevel@tonic-gate caddr_t s_data; /* start of kernel data segment */ 3337c478bd9Sstevel@tonic-gate caddr_t e_data; /* end of kernel data segment */ 3347c478bd9Sstevel@tonic-gate caddr_t modtext; /* start of loadable module text reserved */ 3357c478bd9Sstevel@tonic-gate caddr_t e_modtext; /* end of loadable module text reserved */ 3367c478bd9Sstevel@tonic-gate caddr_t moddata; /* start of loadable module data reserved */ 3377c478bd9Sstevel@tonic-gate caddr_t e_moddata; /* end of loadable module data reserved */ 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate struct memlist *phys_install; /* Total installed physical memory */ 3407c478bd9Sstevel@tonic-gate struct memlist *phys_avail; /* Total available physical memory */ 3411de082f7SVikram Hegde struct memlist *bios_rsvd; /* Bios reserved memory */ 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate /* 3447c478bd9Sstevel@tonic-gate * kphysm_init returns the number of pages that were processed 3457c478bd9Sstevel@tonic-gate */ 346ae115bc7Smrj static pgcnt_t kphysm_init(page_t *, pgcnt_t); 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate #define IO_PROP_SIZE 64 /* device property size */ 3497c478bd9Sstevel@tonic-gate 3507c478bd9Sstevel@tonic-gate /* 3517c478bd9Sstevel@tonic-gate * a couple useful roundup macros 3527c478bd9Sstevel@tonic-gate */ 3537c478bd9Sstevel@tonic-gate #define ROUND_UP_PAGE(x) \ 3547c478bd9Sstevel@tonic-gate ((uintptr_t)P2ROUNDUP((uintptr_t)(x), (uintptr_t)MMU_PAGESIZE)) 3557c478bd9Sstevel@tonic-gate #define ROUND_UP_LPAGE(x) \ 3567c478bd9Sstevel@tonic-gate ((uintptr_t)P2ROUNDUP((uintptr_t)(x), mmu.level_size[1])) 3577c478bd9Sstevel@tonic-gate #define ROUND_UP_4MEG(x) \ 358ae115bc7Smrj ((uintptr_t)P2ROUNDUP((uintptr_t)(x), (uintptr_t)FOUR_MEG)) 3597c478bd9Sstevel@tonic-gate #define ROUND_UP_TOPLEVEL(x) \ 3607c478bd9Sstevel@tonic-gate ((uintptr_t)P2ROUNDUP((uintptr_t)(x), mmu.level_size[mmu.max_level])) 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate /* 3637c478bd9Sstevel@tonic-gate * 32-bit Kernel's Virtual memory layout. 3647c478bd9Sstevel@tonic-gate * +-----------------------+ 365ae115bc7Smrj * | | 3667c478bd9Sstevel@tonic-gate * 0xFFC00000 -|-----------------------|- ARGSBASE 3677c478bd9Sstevel@tonic-gate * | debugger | 3687c478bd9Sstevel@tonic-gate * 0xFF800000 -|-----------------------|- SEGDEBUGBASE 3697c478bd9Sstevel@tonic-gate * | Kernel Data | 3707c478bd9Sstevel@tonic-gate * 0xFEC00000 -|-----------------------| 3717c478bd9Sstevel@tonic-gate * | Kernel Text | 372843e1988Sjohnlev * 0xFE800000 -|-----------------------|- KERNEL_TEXT (0xFB400000 on Xen) 373ae115bc7Smrj * |--- GDT ---|- GDT page (GDT_VA) 374ae115bc7Smrj * |--- debug info ---|- debug info (DEBUG_INFO_VA) 375ae115bc7Smrj * | | 376ae115bc7Smrj * | page_t structures | 3777c478bd9Sstevel@tonic-gate * | memsegs, memlists, | 3787c478bd9Sstevel@tonic-gate * | page hash, etc. | 379ae115bc7Smrj * --- -|-----------------------|- ekernelheap, valloc_base (floating) 380ae115bc7Smrj * | | (segkp is just an arena in the heap) 3817c478bd9Sstevel@tonic-gate * | | 3827c478bd9Sstevel@tonic-gate * | kvseg | 3837c478bd9Sstevel@tonic-gate * | | 3847c478bd9Sstevel@tonic-gate * | | 3857c478bd9Sstevel@tonic-gate * --- -|-----------------------|- kernelheap (floating) 3867c478bd9Sstevel@tonic-gate * | Segkmap | 387ae115bc7Smrj * 0xC3002000 -|-----------------------|- segmap_start (floating) 3887c478bd9Sstevel@tonic-gate * | Red Zone | 3897c478bd9Sstevel@tonic-gate * 0xC3000000 -|-----------------------|- kernelbase / userlimit (floating) 3907c478bd9Sstevel@tonic-gate * | | || 3917c478bd9Sstevel@tonic-gate * | Shared objects | \/ 3927c478bd9Sstevel@tonic-gate * | | 3937c478bd9Sstevel@tonic-gate * : : 3947c478bd9Sstevel@tonic-gate * | user data | 3957c478bd9Sstevel@tonic-gate * |-----------------------| 3967c478bd9Sstevel@tonic-gate * | user text | 3977c478bd9Sstevel@tonic-gate * 0x08048000 -|-----------------------| 3987c478bd9Sstevel@tonic-gate * | user stack | 3997c478bd9Sstevel@tonic-gate * : : 4007c478bd9Sstevel@tonic-gate * | invalid | 4017c478bd9Sstevel@tonic-gate * 0x00000000 +-----------------------+ 4027c478bd9Sstevel@tonic-gate * 4037c478bd9Sstevel@tonic-gate * 4047c478bd9Sstevel@tonic-gate * 64-bit Kernel's Virtual memory layout. (assuming 64 bit app) 4057c478bd9Sstevel@tonic-gate * +-----------------------+ 406ae115bc7Smrj * | | 4077c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.FFC00000 |-----------------------|- ARGSBASE 4087c478bd9Sstevel@tonic-gate * | debugger (?) | 4097c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.FF800000 |-----------------------|- SEGDEBUGBASE 4107c478bd9Sstevel@tonic-gate * | unused | 4117c478bd9Sstevel@tonic-gate * +-----------------------+ 4127c478bd9Sstevel@tonic-gate * | Kernel Data | 4137c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.FBC00000 |-----------------------| 4147c478bd9Sstevel@tonic-gate * | Kernel Text | 4157c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.FB800000 |-----------------------|- KERNEL_TEXT 416ae115bc7Smrj * |--- GDT ---|- GDT page (GDT_VA) 417ae115bc7Smrj * |--- debug info ---|- debug info (DEBUG_INFO_VA) 418ae115bc7Smrj * | | 4197c478bd9Sstevel@tonic-gate * | Core heap | (used for loadable modules) 4207c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.C0000000 |-----------------------|- core_base / ekernelheap 4217c478bd9Sstevel@tonic-gate * | Kernel | 4227c478bd9Sstevel@tonic-gate * | heap | 4237c478bd9Sstevel@tonic-gate * 0xFFFFFXXX.XXX00000 |-----------------------|- kernelheap (floating) 424ae115bc7Smrj * | segmap | 425ae115bc7Smrj * 0xFFFFFXXX.XXX00000 |-----------------------|- segmap_start (floating) 4267c478bd9Sstevel@tonic-gate * | device mappings | 4277c478bd9Sstevel@tonic-gate * 0xFFFFFXXX.XXX00000 |-----------------------|- toxic_addr (floating) 428ad23a2dbSjohansen * | segzio | 429ad23a2dbSjohansen * 0xFFFFFXXX.XXX00000 |-----------------------|- segzio_base (floating) 4307c478bd9Sstevel@tonic-gate * | segkp | 431ae115bc7Smrj * --- |-----------------------|- segkp_base (floating) 432ae115bc7Smrj * | page_t structures | valloc_base + valloc_sz 433ae115bc7Smrj * | memsegs, memlists, | 434ae115bc7Smrj * | page hash, etc. | 43535b1ab99Sjosephb * 0xFFFFFF00.00000000 |-----------------------|- valloc_base (lower if > 1TB) 4367c478bd9Sstevel@tonic-gate * | segkpm | 4377c478bd9Sstevel@tonic-gate * 0xFFFFFE00.00000000 |-----------------------| 4387c478bd9Sstevel@tonic-gate * | Red Zone | 43935b1ab99Sjosephb * 0xFFFFFD80.00000000 |-----------------------|- KERNELBASE (lower if > 1TB) 4407c478bd9Sstevel@tonic-gate * | User stack |- User space memory 4417c478bd9Sstevel@tonic-gate * | | 4427c478bd9Sstevel@tonic-gate * | shared objects, etc | (grows downwards) 4437c478bd9Sstevel@tonic-gate * : : 4447c478bd9Sstevel@tonic-gate * | | 4457c478bd9Sstevel@tonic-gate * 0xFFFF8000.00000000 |-----------------------| 4467c478bd9Sstevel@tonic-gate * | | 4477c478bd9Sstevel@tonic-gate * | VA Hole / unused | 4487c478bd9Sstevel@tonic-gate * | | 4497c478bd9Sstevel@tonic-gate * 0x00008000.00000000 |-----------------------| 4507c478bd9Sstevel@tonic-gate * | | 4517c478bd9Sstevel@tonic-gate * | | 4527c478bd9Sstevel@tonic-gate * : : 4537c478bd9Sstevel@tonic-gate * | user heap | (grows upwards) 4547c478bd9Sstevel@tonic-gate * | | 4557c478bd9Sstevel@tonic-gate * | user data | 4567c478bd9Sstevel@tonic-gate * |-----------------------| 4577c478bd9Sstevel@tonic-gate * | user text | 4587c478bd9Sstevel@tonic-gate * 0x00000000.04000000 |-----------------------| 4597c478bd9Sstevel@tonic-gate * | invalid | 4607c478bd9Sstevel@tonic-gate * 0x00000000.00000000 +-----------------------+ 4617c478bd9Sstevel@tonic-gate * 4627c478bd9Sstevel@tonic-gate * A 32 bit app on the 64 bit kernel sees the same layout as on the 32 bit 4637c478bd9Sstevel@tonic-gate * kernel, except that userlimit is raised to 0xfe000000 4647c478bd9Sstevel@tonic-gate * 4657c478bd9Sstevel@tonic-gate * Floating values: 4667c478bd9Sstevel@tonic-gate * 4677c478bd9Sstevel@tonic-gate * valloc_base: start of the kernel's memory management/tracking data 468ae115bc7Smrj * structures. This region contains page_t structures for 469ae115bc7Smrj * physical memory, memsegs, memlists, and the page hash. 4707c478bd9Sstevel@tonic-gate * 4717c478bd9Sstevel@tonic-gate * core_base: start of the kernel's "core" heap area on 64-bit systems. 4727c478bd9Sstevel@tonic-gate * This area is intended to be used for global data as well as for module 4737c478bd9Sstevel@tonic-gate * text/data that does not fit into the nucleus pages. The core heap is 4747c478bd9Sstevel@tonic-gate * restricted to a 2GB range, allowing every address within it to be 4757c478bd9Sstevel@tonic-gate * accessed using rip-relative addressing 4767c478bd9Sstevel@tonic-gate * 4777c478bd9Sstevel@tonic-gate * ekernelheap: end of kernelheap and start of segmap. 4787c478bd9Sstevel@tonic-gate * 4797c478bd9Sstevel@tonic-gate * kernelheap: start of kernel heap. On 32-bit systems, this starts right 4807c478bd9Sstevel@tonic-gate * above a red zone that separates the user's address space from the 4817c478bd9Sstevel@tonic-gate * kernel's. On 64-bit systems, it sits above segkp and segkpm. 4827c478bd9Sstevel@tonic-gate * 483ae115bc7Smrj * segmap_start: start of segmap. The length of segmap can be modified 48452eef812SAmrita Sadhukhan * through eeprom. The default length is 16MB on 32-bit systems and 64MB 48552eef812SAmrita Sadhukhan * on 64-bit systems. 4867c478bd9Sstevel@tonic-gate * 4877c478bd9Sstevel@tonic-gate * kernelbase: On a 32-bit kernel the default value of 0xd4000000 will be 4887c478bd9Sstevel@tonic-gate * decreased by 2X the size required for page_t. This allows the kernel 4897c478bd9Sstevel@tonic-gate * heap to grow in size with physical memory. With sizeof(page_t) == 80 4907c478bd9Sstevel@tonic-gate * bytes, the following shows the values of kernelbase and kernel heap 4917c478bd9Sstevel@tonic-gate * sizes for different memory configurations (assuming default segmap and 4927c478bd9Sstevel@tonic-gate * segkp sizes). 4937c478bd9Sstevel@tonic-gate * 4947c478bd9Sstevel@tonic-gate * mem size for kernelbase kernel heap 4957c478bd9Sstevel@tonic-gate * size page_t's size 4967c478bd9Sstevel@tonic-gate * ---- --------- ---------- ----------- 4977c478bd9Sstevel@tonic-gate * 1gb 0x01400000 0xd1800000 684MB 4987c478bd9Sstevel@tonic-gate * 2gb 0x02800000 0xcf000000 704MB 4997c478bd9Sstevel@tonic-gate * 4gb 0x05000000 0xca000000 744MB 5007c478bd9Sstevel@tonic-gate * 6gb 0x07800000 0xc5000000 784MB 5017c478bd9Sstevel@tonic-gate * 8gb 0x0a000000 0xc0000000 824MB 5027c478bd9Sstevel@tonic-gate * 16gb 0x14000000 0xac000000 984MB 5037c478bd9Sstevel@tonic-gate * 32gb 0x28000000 0x84000000 1304MB 5047c478bd9Sstevel@tonic-gate * 64gb 0x50000000 0x34000000 1944MB (*) 5057c478bd9Sstevel@tonic-gate * 5067c478bd9Sstevel@tonic-gate * kernelbase is less than the abi minimum of 0xc0000000 for memory 5077c478bd9Sstevel@tonic-gate * configurations above 8gb. 5087c478bd9Sstevel@tonic-gate * 5097c478bd9Sstevel@tonic-gate * (*) support for memory configurations above 32gb will require manual tuning 5107c478bd9Sstevel@tonic-gate * of kernelbase to balance out the need of user applications. 5117c478bd9Sstevel@tonic-gate */ 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate /* real-time-clock initialization parameters */ 514ae115bc7Smrj extern time_t process_rtc_config_file(void); 5157c478bd9Sstevel@tonic-gate 5167c478bd9Sstevel@tonic-gate uintptr_t kernelbase; 517ae115bc7Smrj uintptr_t postbootkernelbase; /* not set till boot loader is gone */ 5187c478bd9Sstevel@tonic-gate uintptr_t eprom_kernelbase; 5197c478bd9Sstevel@tonic-gate size_t segmapsize; 520ae115bc7Smrj uintptr_t segmap_start; 5217c478bd9Sstevel@tonic-gate int segmapfreelists; 5227c478bd9Sstevel@tonic-gate pgcnt_t npages; 523ae115bc7Smrj pgcnt_t orig_npages; 5247c478bd9Sstevel@tonic-gate size_t core_size; /* size of "core" heap */ 5257c478bd9Sstevel@tonic-gate uintptr_t core_base; /* base address of "core" heap */ 5267c478bd9Sstevel@tonic-gate 5277c478bd9Sstevel@tonic-gate /* 5287c478bd9Sstevel@tonic-gate * List of bootstrap pages. We mark these as allocated in startup. 5297c478bd9Sstevel@tonic-gate * release_bootstrap() will free them when we're completely done with 5307c478bd9Sstevel@tonic-gate * the bootstrap. 5317c478bd9Sstevel@tonic-gate */ 532ae115bc7Smrj static page_t *bootpages; 533ae115bc7Smrj 534ae115bc7Smrj /* 535ae115bc7Smrj * boot time pages that have a vnode from the ramdisk will keep that forever. 536ae115bc7Smrj */ 537ae115bc7Smrj static page_t *rd_pages; 5387c478bd9Sstevel@tonic-gate 53919397407SSherry Moore /* 54019397407SSherry Moore * Lower 64K 54119397407SSherry Moore */ 54219397407SSherry Moore static page_t *lower_pages = NULL; 54319397407SSherry Moore static int lower_pages_count = 0; 54419397407SSherry Moore 5457c478bd9Sstevel@tonic-gate struct system_hardware system_hardware; 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate /* 5487c478bd9Sstevel@tonic-gate * Enable some debugging messages concerning memory usage... 5497c478bd9Sstevel@tonic-gate */ 5507c478bd9Sstevel@tonic-gate static void 551ae115bc7Smrj print_memlist(char *title, struct memlist *mp) 5527c478bd9Sstevel@tonic-gate { 5537c478bd9Sstevel@tonic-gate prom_printf("MEMLIST: %s:\n", title); 5547c478bd9Sstevel@tonic-gate while (mp != NULL) { 5557c478bd9Sstevel@tonic-gate prom_printf("\tAddress 0x%" PRIx64 ", size 0x%" PRIx64 "\n", 55656f33205SJonathan Adams mp->ml_address, mp->ml_size); 55756f33205SJonathan Adams mp = mp->ml_next; 5587c478bd9Sstevel@tonic-gate } 5597c478bd9Sstevel@tonic-gate } 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate /* 5627c478bd9Sstevel@tonic-gate * XX64 need a comment here.. are these just default values, surely 5637c478bd9Sstevel@tonic-gate * we read the "cpuid" type information to figure this out. 5647c478bd9Sstevel@tonic-gate */ 5657c478bd9Sstevel@tonic-gate int l2cache_sz = 0x80000; 5667c478bd9Sstevel@tonic-gate int l2cache_linesz = 0x40; 5677c478bd9Sstevel@tonic-gate int l2cache_assoc = 1; 5687c478bd9Sstevel@tonic-gate 5692cb27123Saguzovsk static size_t textrepl_min_gb = 10; 5702cb27123Saguzovsk 5717c478bd9Sstevel@tonic-gate /* 5727c478bd9Sstevel@tonic-gate * on 64 bit we use a predifined VA range for mapping devices in the kernel 5737c478bd9Sstevel@tonic-gate * on 32 bit the mappings are intermixed in the heap, so we use a bit map 5747c478bd9Sstevel@tonic-gate */ 5757c478bd9Sstevel@tonic-gate #ifdef __amd64 5767c478bd9Sstevel@tonic-gate 5777c478bd9Sstevel@tonic-gate vmem_t *device_arena; 5787c478bd9Sstevel@tonic-gate uintptr_t toxic_addr = (uintptr_t)NULL; 579ae115bc7Smrj size_t toxic_size = 1024 * 1024 * 1024; /* Sparc uses 1 gig too */ 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate #else /* __i386 */ 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate ulong_t *toxic_bit_map; /* one bit for each 4k of VA in heap_arena */ 5847c478bd9Sstevel@tonic-gate size_t toxic_bit_map_len = 0; /* in bits */ 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gate #endif /* __i386 */ 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate /* 5897c478bd9Sstevel@tonic-gate * Simple boot time debug facilities 5907c478bd9Sstevel@tonic-gate */ 5917c478bd9Sstevel@tonic-gate static char *prm_dbg_str[] = { 5927c478bd9Sstevel@tonic-gate "%s:%d: '%s' is 0x%x\n", 5937c478bd9Sstevel@tonic-gate "%s:%d: '%s' is 0x%llx\n" 5947c478bd9Sstevel@tonic-gate }; 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate int prom_debug; 5977c478bd9Sstevel@tonic-gate 5987c478bd9Sstevel@tonic-gate #define PRM_DEBUG(q) if (prom_debug) \ 5997c478bd9Sstevel@tonic-gate prom_printf(prm_dbg_str[sizeof (q) >> 3], "startup.c", __LINE__, #q, q); 6007c478bd9Sstevel@tonic-gate #define PRM_POINT(q) if (prom_debug) \ 6017c478bd9Sstevel@tonic-gate prom_printf("%s:%d: %s\n", "startup.c", __LINE__, q); 6027c478bd9Sstevel@tonic-gate 6037c478bd9Sstevel@tonic-gate /* 6047c478bd9Sstevel@tonic-gate * This structure is used to keep track of the intial allocations 6057c478bd9Sstevel@tonic-gate * done in startup_memlist(). The value of NUM_ALLOCATIONS needs to 6067c478bd9Sstevel@tonic-gate * be >= the number of ADD_TO_ALLOCATIONS() executed in the code. 6077c478bd9Sstevel@tonic-gate */ 6081de082f7SVikram Hegde #define NUM_ALLOCATIONS 8 6097c478bd9Sstevel@tonic-gate int num_allocations = 0; 6107c478bd9Sstevel@tonic-gate struct { 6117c478bd9Sstevel@tonic-gate void **al_ptr; 6127c478bd9Sstevel@tonic-gate size_t al_size; 6137c478bd9Sstevel@tonic-gate } allocations[NUM_ALLOCATIONS]; 6147c478bd9Sstevel@tonic-gate size_t valloc_sz = 0; 6157c478bd9Sstevel@tonic-gate uintptr_t valloc_base; 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate #define ADD_TO_ALLOCATIONS(ptr, size) { \ 6187c478bd9Sstevel@tonic-gate size = ROUND_UP_PAGE(size); \ 6197c478bd9Sstevel@tonic-gate if (num_allocations == NUM_ALLOCATIONS) \ 6207c478bd9Sstevel@tonic-gate panic("too many ADD_TO_ALLOCATIONS()"); \ 6217c478bd9Sstevel@tonic-gate allocations[num_allocations].al_ptr = (void**)&ptr; \ 6227c478bd9Sstevel@tonic-gate allocations[num_allocations].al_size = size; \ 6237c478bd9Sstevel@tonic-gate valloc_sz += size; \ 6247c478bd9Sstevel@tonic-gate ++num_allocations; \ 6257c478bd9Sstevel@tonic-gate } 6267c478bd9Sstevel@tonic-gate 627ae115bc7Smrj /* 628ae115bc7Smrj * Allocate all the initial memory needed by the page allocator. 629ae115bc7Smrj */ 6307c478bd9Sstevel@tonic-gate static void 6317c478bd9Sstevel@tonic-gate perform_allocations(void) 6327c478bd9Sstevel@tonic-gate { 6337c478bd9Sstevel@tonic-gate caddr_t mem; 6347c478bd9Sstevel@tonic-gate int i; 635ae115bc7Smrj int valloc_align; 6367c478bd9Sstevel@tonic-gate 637ae115bc7Smrj PRM_DEBUG(valloc_base); 638ae115bc7Smrj PRM_DEBUG(valloc_sz); 639ae115bc7Smrj valloc_align = mmu.level_size[mmu.max_page_level > 0]; 640ae115bc7Smrj mem = BOP_ALLOC(bootops, (caddr_t)valloc_base, valloc_sz, valloc_align); 6417c478bd9Sstevel@tonic-gate if (mem != (caddr_t)valloc_base) 6427c478bd9Sstevel@tonic-gate panic("BOP_ALLOC() failed"); 6437c478bd9Sstevel@tonic-gate bzero(mem, valloc_sz); 6447c478bd9Sstevel@tonic-gate for (i = 0; i < num_allocations; ++i) { 6457c478bd9Sstevel@tonic-gate *allocations[i].al_ptr = (void *)mem; 6467c478bd9Sstevel@tonic-gate mem += allocations[i].al_size; 6477c478bd9Sstevel@tonic-gate } 6487c478bd9Sstevel@tonic-gate } 6497c478bd9Sstevel@tonic-gate 6507c478bd9Sstevel@tonic-gate /* 6517c478bd9Sstevel@tonic-gate * Our world looks like this at startup time. 6527c478bd9Sstevel@tonic-gate * 6537c478bd9Sstevel@tonic-gate * In a 32-bit OS, boot loads the kernel text at 0xfe800000 and kernel data 6547c478bd9Sstevel@tonic-gate * at 0xfec00000. On a 64-bit OS, kernel text and data are loaded at 6557c478bd9Sstevel@tonic-gate * 0xffffffff.fe800000 and 0xffffffff.fec00000 respectively. Those 6567c478bd9Sstevel@tonic-gate * addresses are fixed in the binary at link time. 6577c478bd9Sstevel@tonic-gate * 6587c478bd9Sstevel@tonic-gate * On the text page: 6597c478bd9Sstevel@tonic-gate * unix/genunix/krtld/module text loads. 6607c478bd9Sstevel@tonic-gate * 6617c478bd9Sstevel@tonic-gate * On the data page: 662ae115bc7Smrj * unix/genunix/krtld/module data loads. 663ae115bc7Smrj * 6647c478bd9Sstevel@tonic-gate * Machine-dependent startup code 6657c478bd9Sstevel@tonic-gate */ 6667c478bd9Sstevel@tonic-gate void 6677c478bd9Sstevel@tonic-gate startup(void) 6687c478bd9Sstevel@tonic-gate { 669843e1988Sjohnlev #if !defined(__xpv) 67075bcd456Sjg extern void startup_pci_bios(void); 67119397407SSherry Moore extern int post_fastreboot; 672843e1988Sjohnlev #endif 673a563a037Sbholler extern cpuset_t cpu_ready_set; 674a563a037Sbholler 675843e1988Sjohnlev /* 676843e1988Sjohnlev * Make sure that nobody tries to use sekpm until we have 677843e1988Sjohnlev * initialized it properly. 678843e1988Sjohnlev */ 6797c478bd9Sstevel@tonic-gate #if defined(__amd64) 68035b1ab99Sjosephb kpm_desired = 1; 6817c478bd9Sstevel@tonic-gate #endif 6827c478bd9Sstevel@tonic-gate kpm_enable = 0; 683a563a037Sbholler CPUSET_ONLY(cpu_ready_set, 0); /* cpu 0 is boot cpu */ 6847c478bd9Sstevel@tonic-gate 685843e1988Sjohnlev #if defined(__xpv) /* XXPV fix me! */ 686843e1988Sjohnlev { 687843e1988Sjohnlev extern int segvn_use_regions; 688843e1988Sjohnlev segvn_use_regions = 0; 689843e1988Sjohnlev } 690843e1988Sjohnlev #endif 6917c478bd9Sstevel@tonic-gate progressbar_init(); 6927c478bd9Sstevel@tonic-gate startup_init(); 693ab4a9bebSjohnlev #if defined(__xpv) 694ab4a9bebSjohnlev startup_xen_version(); 695ab4a9bebSjohnlev #endif 6967c478bd9Sstevel@tonic-gate startup_memlist(); 697ae115bc7Smrj startup_kmem(); 69835b1ab99Sjosephb startup_vm(); 699843e1988Sjohnlev #if !defined(__xpv) 70019397407SSherry Moore if (!post_fastreboot) 70175bcd456Sjg startup_pci_bios(); 702843e1988Sjohnlev #endif 703e4b86885SCheng Sean Ye #if defined(__xpv) 704e4b86885SCheng Sean Ye startup_xen_mca(); 705e4b86885SCheng Sean Ye #endif 7067c478bd9Sstevel@tonic-gate startup_modules(); 7078770118eSlipeng sang - Sun Microsystems - Beijing China 7087c478bd9Sstevel@tonic-gate startup_end(); 7097c478bd9Sstevel@tonic-gate } 7107c478bd9Sstevel@tonic-gate 7117c478bd9Sstevel@tonic-gate static void 7127c478bd9Sstevel@tonic-gate startup_init() 7137c478bd9Sstevel@tonic-gate { 7147c478bd9Sstevel@tonic-gate PRM_POINT("startup_init() starting..."); 7157c478bd9Sstevel@tonic-gate 7167c478bd9Sstevel@tonic-gate /* 7177c478bd9Sstevel@tonic-gate * Complete the extraction of cpuid data 7187c478bd9Sstevel@tonic-gate */ 7197c478bd9Sstevel@tonic-gate cpuid_pass2(CPU); 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate (void) check_boot_version(BOP_GETVERSION(bootops)); 7227c478bd9Sstevel@tonic-gate 7237c478bd9Sstevel@tonic-gate /* 7247c478bd9Sstevel@tonic-gate * Check for prom_debug in boot environment 7257c478bd9Sstevel@tonic-gate */ 7267c478bd9Sstevel@tonic-gate if (BOP_GETPROPLEN(bootops, "prom_debug") >= 0) { 7277c478bd9Sstevel@tonic-gate ++prom_debug; 7287c478bd9Sstevel@tonic-gate PRM_POINT("prom_debug found in boot enviroment"); 7297c478bd9Sstevel@tonic-gate } 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate /* 7327c478bd9Sstevel@tonic-gate * Collect node, cpu and memory configuration information. 7337c478bd9Sstevel@tonic-gate */ 7347c478bd9Sstevel@tonic-gate get_system_configuration(); 7357c478bd9Sstevel@tonic-gate 7367c478bd9Sstevel@tonic-gate /* 7377c478bd9Sstevel@tonic-gate * Halt if this is an unsupported processor. 7387c478bd9Sstevel@tonic-gate */ 7397c478bd9Sstevel@tonic-gate if (x86_type == X86_TYPE_486 || x86_type == X86_TYPE_CYRIX_486) { 7407c478bd9Sstevel@tonic-gate printf("\n486 processor (\"%s\") detected.\n", 7417c478bd9Sstevel@tonic-gate CPU->cpu_brandstr); 7427c478bd9Sstevel@tonic-gate halt("This processor is not supported by this release " 7437c478bd9Sstevel@tonic-gate "of Solaris."); 7447c478bd9Sstevel@tonic-gate } 7457c478bd9Sstevel@tonic-gate 7467c478bd9Sstevel@tonic-gate PRM_POINT("startup_init() done"); 7477c478bd9Sstevel@tonic-gate } 7487c478bd9Sstevel@tonic-gate 7497c478bd9Sstevel@tonic-gate /* 7507c478bd9Sstevel@tonic-gate * Callback for copy_memlist_filter() to filter nucleus, kadb/kmdb, (ie. 7517c478bd9Sstevel@tonic-gate * everything mapped above KERNEL_TEXT) pages from phys_avail. Note it 7527c478bd9Sstevel@tonic-gate * also filters out physical page zero. There is some reliance on the 7537c478bd9Sstevel@tonic-gate * boot loader allocating only a few contiguous physical memory chunks. 7547c478bd9Sstevel@tonic-gate */ 7557c478bd9Sstevel@tonic-gate static void 7567c478bd9Sstevel@tonic-gate avail_filter(uint64_t *addr, uint64_t *size) 7577c478bd9Sstevel@tonic-gate { 7587c478bd9Sstevel@tonic-gate uintptr_t va; 7597c478bd9Sstevel@tonic-gate uintptr_t next_va; 7607c478bd9Sstevel@tonic-gate pfn_t pfn; 7617c478bd9Sstevel@tonic-gate uint64_t pfn_addr; 7627c478bd9Sstevel@tonic-gate uint64_t pfn_eaddr; 7637c478bd9Sstevel@tonic-gate uint_t prot; 7647c478bd9Sstevel@tonic-gate size_t len; 7657c478bd9Sstevel@tonic-gate uint_t change; 7667c478bd9Sstevel@tonic-gate 7677c478bd9Sstevel@tonic-gate if (prom_debug) 7687c478bd9Sstevel@tonic-gate prom_printf("\tFilter: in: a=%" PRIx64 ", s=%" PRIx64 "\n", 7697c478bd9Sstevel@tonic-gate *addr, *size); 7707c478bd9Sstevel@tonic-gate 7717c478bd9Sstevel@tonic-gate /* 7727c478bd9Sstevel@tonic-gate * page zero is required for BIOS.. never make it available 7737c478bd9Sstevel@tonic-gate */ 7747c478bd9Sstevel@tonic-gate if (*addr == 0) { 7757c478bd9Sstevel@tonic-gate *addr += MMU_PAGESIZE; 7767c478bd9Sstevel@tonic-gate *size -= MMU_PAGESIZE; 7777c478bd9Sstevel@tonic-gate } 7787c478bd9Sstevel@tonic-gate 7797c478bd9Sstevel@tonic-gate /* 780ae115bc7Smrj * First we trim from the front of the range. Since kbm_probe() 7817c478bd9Sstevel@tonic-gate * walks ranges in virtual order, but addr/size are physical, we need 7827c478bd9Sstevel@tonic-gate * to the list until no changes are seen. This deals with the case 7837c478bd9Sstevel@tonic-gate * where page "p" is mapped at v, page "p + PAGESIZE" is mapped at w 7847c478bd9Sstevel@tonic-gate * but w < v. 7857c478bd9Sstevel@tonic-gate */ 7867c478bd9Sstevel@tonic-gate do { 7877c478bd9Sstevel@tonic-gate change = 0; 7887c478bd9Sstevel@tonic-gate for (va = KERNEL_TEXT; 789ae115bc7Smrj *size > 0 && kbm_probe(&va, &len, &pfn, &prot) != 0; 7907c478bd9Sstevel@tonic-gate va = next_va) { 7917c478bd9Sstevel@tonic-gate 7927c478bd9Sstevel@tonic-gate next_va = va + len; 793ae115bc7Smrj pfn_addr = pfn_to_pa(pfn); 7947c478bd9Sstevel@tonic-gate pfn_eaddr = pfn_addr + len; 7957c478bd9Sstevel@tonic-gate 7967c478bd9Sstevel@tonic-gate if (pfn_addr <= *addr && pfn_eaddr > *addr) { 7977c478bd9Sstevel@tonic-gate change = 1; 7987c478bd9Sstevel@tonic-gate while (*size > 0 && len > 0) { 7997c478bd9Sstevel@tonic-gate *addr += MMU_PAGESIZE; 8007c478bd9Sstevel@tonic-gate *size -= MMU_PAGESIZE; 8017c478bd9Sstevel@tonic-gate len -= MMU_PAGESIZE; 8027c478bd9Sstevel@tonic-gate } 8037c478bd9Sstevel@tonic-gate } 8047c478bd9Sstevel@tonic-gate } 8057c478bd9Sstevel@tonic-gate if (change && prom_debug) 8067c478bd9Sstevel@tonic-gate prom_printf("\t\ttrim: a=%" PRIx64 ", s=%" PRIx64 "\n", 8077c478bd9Sstevel@tonic-gate *addr, *size); 8087c478bd9Sstevel@tonic-gate } while (change); 8097c478bd9Sstevel@tonic-gate 8107c478bd9Sstevel@tonic-gate /* 8117c478bd9Sstevel@tonic-gate * Trim pages from the end of the range. 8127c478bd9Sstevel@tonic-gate */ 8137c478bd9Sstevel@tonic-gate for (va = KERNEL_TEXT; 814ae115bc7Smrj *size > 0 && kbm_probe(&va, &len, &pfn, &prot) != 0; 8157c478bd9Sstevel@tonic-gate va = next_va) { 8167c478bd9Sstevel@tonic-gate 8177c478bd9Sstevel@tonic-gate next_va = va + len; 818ae115bc7Smrj pfn_addr = pfn_to_pa(pfn); 8197c478bd9Sstevel@tonic-gate 8207c478bd9Sstevel@tonic-gate if (pfn_addr >= *addr && pfn_addr < *addr + *size) 8217c478bd9Sstevel@tonic-gate *size = pfn_addr - *addr; 8227c478bd9Sstevel@tonic-gate } 8237c478bd9Sstevel@tonic-gate 8247c478bd9Sstevel@tonic-gate if (prom_debug) 8257c478bd9Sstevel@tonic-gate prom_printf("\tFilter out: a=%" PRIx64 ", s=%" PRIx64 "\n", 8267c478bd9Sstevel@tonic-gate *addr, *size); 8277c478bd9Sstevel@tonic-gate } 8287c478bd9Sstevel@tonic-gate 8297c478bd9Sstevel@tonic-gate static void 8307c478bd9Sstevel@tonic-gate kpm_init() 8317c478bd9Sstevel@tonic-gate { 8327c478bd9Sstevel@tonic-gate struct segkpm_crargs b; 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate /* 8357c478bd9Sstevel@tonic-gate * These variables were all designed for sfmmu in which segkpm is 8367c478bd9Sstevel@tonic-gate * mapped using a single pagesize - either 8KB or 4MB. On x86, we 8377c478bd9Sstevel@tonic-gate * might use 2+ page sizes on a single machine, so none of these 8387c478bd9Sstevel@tonic-gate * variables have a single correct value. They are set up as if we 8397c478bd9Sstevel@tonic-gate * always use a 4KB pagesize, which should do no harm. In the long 8407c478bd9Sstevel@tonic-gate * run, we should get rid of KPM's assumption that only a single 8417c478bd9Sstevel@tonic-gate * pagesize is used. 8427c478bd9Sstevel@tonic-gate */ 8437c478bd9Sstevel@tonic-gate kpm_pgshft = MMU_PAGESHIFT; 8447c478bd9Sstevel@tonic-gate kpm_pgsz = MMU_PAGESIZE; 8457c478bd9Sstevel@tonic-gate kpm_pgoff = MMU_PAGEOFFSET; 8467c478bd9Sstevel@tonic-gate kpmp2pshft = 0; 8477c478bd9Sstevel@tonic-gate kpmpnpgs = 1; 8487c478bd9Sstevel@tonic-gate ASSERT(((uintptr_t)kpm_vbase & (kpm_pgsz - 1)) == 0); 8497c478bd9Sstevel@tonic-gate 8507c478bd9Sstevel@tonic-gate PRM_POINT("about to create segkpm"); 8517c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER); 8527c478bd9Sstevel@tonic-gate 8537c478bd9Sstevel@tonic-gate if (seg_attach(&kas, kpm_vbase, kpm_size, segkpm) < 0) 8547c478bd9Sstevel@tonic-gate panic("cannot attach segkpm"); 8557c478bd9Sstevel@tonic-gate 8567c478bd9Sstevel@tonic-gate b.prot = PROT_READ | PROT_WRITE; 8577c478bd9Sstevel@tonic-gate b.nvcolors = 1; 8587c478bd9Sstevel@tonic-gate 8597c478bd9Sstevel@tonic-gate if (segkpm_create(segkpm, (caddr_t)&b) != 0) 8607c478bd9Sstevel@tonic-gate panic("segkpm_create segkpm"); 8617c478bd9Sstevel@tonic-gate 8627c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock); 863ae115bc7Smrj } 8647c478bd9Sstevel@tonic-gate 8657c478bd9Sstevel@tonic-gate /* 866ae115bc7Smrj * The debug info page provides enough information to allow external 867ae115bc7Smrj * inspectors (e.g. when running under a hypervisor) to bootstrap 868ae115bc7Smrj * themselves into allowing full-blown kernel debugging. 8697c478bd9Sstevel@tonic-gate */ 870ae115bc7Smrj static void 871ae115bc7Smrj init_debug_info(void) 872ae115bc7Smrj { 873ae115bc7Smrj caddr_t mem; 874ae115bc7Smrj debug_info_t *di; 875ae115bc7Smrj 876ae115bc7Smrj #ifndef __lint 877ae115bc7Smrj ASSERT(sizeof (debug_info_t) < MMU_PAGESIZE); 878ae115bc7Smrj #endif 879ae115bc7Smrj 880ae115bc7Smrj mem = BOP_ALLOC(bootops, (caddr_t)DEBUG_INFO_VA, MMU_PAGESIZE, 881ae115bc7Smrj MMU_PAGESIZE); 882ae115bc7Smrj 883ae115bc7Smrj if (mem != (caddr_t)DEBUG_INFO_VA) 884ae115bc7Smrj panic("BOP_ALLOC() failed"); 885ae115bc7Smrj bzero(mem, MMU_PAGESIZE); 886ae115bc7Smrj 887ae115bc7Smrj di = (debug_info_t *)mem; 888ae115bc7Smrj 889ae115bc7Smrj di->di_magic = DEBUG_INFO_MAGIC; 890ae115bc7Smrj di->di_version = DEBUG_INFO_VERSION; 891843e1988Sjohnlev di->di_modules = (uintptr_t)&modules; 892843e1988Sjohnlev di->di_s_text = (uintptr_t)s_text; 893843e1988Sjohnlev di->di_e_text = (uintptr_t)e_text; 894843e1988Sjohnlev di->di_s_data = (uintptr_t)s_data; 895843e1988Sjohnlev di->di_e_data = (uintptr_t)e_data; 896843e1988Sjohnlev di->di_hat_htable_off = offsetof(hat_t, hat_htable); 897843e1988Sjohnlev di->di_ht_pfn_off = offsetof(htable_t, ht_pfn); 8987c478bd9Sstevel@tonic-gate } 8997c478bd9Sstevel@tonic-gate 9007c478bd9Sstevel@tonic-gate /* 901ae115bc7Smrj * Build the memlists and other kernel essential memory system data structures. 902ae115bc7Smrj * This is everything at valloc_base. 9037c478bd9Sstevel@tonic-gate */ 9047c478bd9Sstevel@tonic-gate static void 9057c478bd9Sstevel@tonic-gate startup_memlist(void) 9067c478bd9Sstevel@tonic-gate { 9077c478bd9Sstevel@tonic-gate size_t memlist_sz; 9087c478bd9Sstevel@tonic-gate size_t memseg_sz; 9097c478bd9Sstevel@tonic-gate size_t pagehash_sz; 9107c478bd9Sstevel@tonic-gate size_t pp_sz; 9117c478bd9Sstevel@tonic-gate uintptr_t va; 9127c478bd9Sstevel@tonic-gate size_t len; 9137c478bd9Sstevel@tonic-gate uint_t prot; 9147c478bd9Sstevel@tonic-gate pfn_t pfn; 9157c478bd9Sstevel@tonic-gate int memblocks; 9161de082f7SVikram Hegde pfn_t rsvd_high_pfn; 9171de082f7SVikram Hegde pgcnt_t rsvd_pgcnt; 9181de082f7SVikram Hegde size_t rsvdmemlist_sz; 9191de082f7SVikram Hegde int rsvdmemblocks; 9207c478bd9Sstevel@tonic-gate caddr_t pagecolor_mem; 9217c478bd9Sstevel@tonic-gate size_t pagecolor_memsz; 9227c478bd9Sstevel@tonic-gate caddr_t page_ctrs_mem; 9237c478bd9Sstevel@tonic-gate size_t page_ctrs_size; 924d7d93655Sblakej size_t pse_table_alloc_size; 9257c478bd9Sstevel@tonic-gate struct memlist *current; 9267c478bd9Sstevel@tonic-gate extern void startup_build_mem_nodes(struct memlist *); 9277c478bd9Sstevel@tonic-gate 9287c478bd9Sstevel@tonic-gate /* XX64 fix these - they should be in include files */ 9297c478bd9Sstevel@tonic-gate extern size_t page_coloring_init(uint_t, int, int); 9307c478bd9Sstevel@tonic-gate extern void page_coloring_setup(caddr_t); 9317c478bd9Sstevel@tonic-gate 9327c478bd9Sstevel@tonic-gate PRM_POINT("startup_memlist() starting..."); 9337c478bd9Sstevel@tonic-gate 9347c478bd9Sstevel@tonic-gate /* 9357c478bd9Sstevel@tonic-gate * Use leftover large page nucleus text/data space for loadable modules. 9367c478bd9Sstevel@tonic-gate * Use at most MODTEXT/MODDATA. 9377c478bd9Sstevel@tonic-gate */ 938ae115bc7Smrj len = kbm_nucleus_size; 939ae115bc7Smrj ASSERT(len > MMU_PAGESIZE); 9407c478bd9Sstevel@tonic-gate 9417c478bd9Sstevel@tonic-gate moddata = (caddr_t)ROUND_UP_PAGE(e_data); 942ae115bc7Smrj e_moddata = (caddr_t)P2ROUNDUP((uintptr_t)e_data, (uintptr_t)len); 9437c478bd9Sstevel@tonic-gate if (e_moddata - moddata > MODDATA) 9447c478bd9Sstevel@tonic-gate e_moddata = moddata + MODDATA; 9457c478bd9Sstevel@tonic-gate 9467c478bd9Sstevel@tonic-gate modtext = (caddr_t)ROUND_UP_PAGE(e_text); 947ae115bc7Smrj e_modtext = (caddr_t)P2ROUNDUP((uintptr_t)e_text, (uintptr_t)len); 9487c478bd9Sstevel@tonic-gate if (e_modtext - modtext > MODTEXT) 9497c478bd9Sstevel@tonic-gate e_modtext = modtext + MODTEXT; 9507c478bd9Sstevel@tonic-gate 9517c478bd9Sstevel@tonic-gate econtig = e_moddata; 9527c478bd9Sstevel@tonic-gate 9537c478bd9Sstevel@tonic-gate PRM_DEBUG(modtext); 9547c478bd9Sstevel@tonic-gate PRM_DEBUG(e_modtext); 9557c478bd9Sstevel@tonic-gate PRM_DEBUG(moddata); 9567c478bd9Sstevel@tonic-gate PRM_DEBUG(e_moddata); 9577c478bd9Sstevel@tonic-gate PRM_DEBUG(econtig); 9587c478bd9Sstevel@tonic-gate 9597c478bd9Sstevel@tonic-gate /* 960ae115bc7Smrj * Examine the boot loader physical memory map to find out: 9617c478bd9Sstevel@tonic-gate * - total memory in system - physinstalled 9627c478bd9Sstevel@tonic-gate * - the max physical address - physmax 963ae115bc7Smrj * - the number of discontiguous segments of memory. 9647c478bd9Sstevel@tonic-gate */ 9657c478bd9Sstevel@tonic-gate if (prom_debug) 966ae115bc7Smrj print_memlist("boot physinstalled", 9677c478bd9Sstevel@tonic-gate bootops->boot_mem->physinstalled); 9687c478bd9Sstevel@tonic-gate installed_top_size(bootops->boot_mem->physinstalled, &physmax, 9697c478bd9Sstevel@tonic-gate &physinstalled, &memblocks); 9707c478bd9Sstevel@tonic-gate PRM_DEBUG(physmax); 9717c478bd9Sstevel@tonic-gate PRM_DEBUG(physinstalled); 9727c478bd9Sstevel@tonic-gate PRM_DEBUG(memblocks); 9737c478bd9Sstevel@tonic-gate 9747c478bd9Sstevel@tonic-gate /* 9751de082f7SVikram Hegde * Examine the bios reserved memory to find out: 9761de082f7SVikram Hegde * - the number of discontiguous segments of memory. 9771de082f7SVikram Hegde */ 9781de082f7SVikram Hegde if (prom_debug) 9791de082f7SVikram Hegde print_memlist("boot reserved mem", 9801de082f7SVikram Hegde bootops->boot_mem->rsvdmem); 9811de082f7SVikram Hegde installed_top_size(bootops->boot_mem->rsvdmem, &rsvd_high_pfn, 9821de082f7SVikram Hegde &rsvd_pgcnt, &rsvdmemblocks); 9831de082f7SVikram Hegde PRM_DEBUG(rsvd_high_pfn); 9841de082f7SVikram Hegde PRM_DEBUG(rsvd_pgcnt); 9851de082f7SVikram Hegde PRM_DEBUG(rsvdmemblocks); 9861de082f7SVikram Hegde 9871de082f7SVikram Hegde /* 9887c478bd9Sstevel@tonic-gate * Initialize hat's mmu parameters. 9897c478bd9Sstevel@tonic-gate * Check for enforce-prot-exec in boot environment. It's used to 9907c478bd9Sstevel@tonic-gate * enable/disable support for the page table entry NX bit. 9917c478bd9Sstevel@tonic-gate * The default is to enforce PROT_EXEC on processors that support NX. 9927c478bd9Sstevel@tonic-gate * Boot seems to round up the "len", but 8 seems to be big enough. 9937c478bd9Sstevel@tonic-gate */ 9947c478bd9Sstevel@tonic-gate mmu_init(); 9957c478bd9Sstevel@tonic-gate 9967c478bd9Sstevel@tonic-gate #ifdef __i386 9977c478bd9Sstevel@tonic-gate /* 9987c478bd9Sstevel@tonic-gate * physmax is lowered if there is more memory than can be 9997c478bd9Sstevel@tonic-gate * physically addressed in 32 bit (PAE/non-PAE) modes. 10007c478bd9Sstevel@tonic-gate */ 10017c478bd9Sstevel@tonic-gate if (mmu.pae_hat) { 10027c478bd9Sstevel@tonic-gate if (PFN_ABOVE64G(physmax)) { 10037c478bd9Sstevel@tonic-gate physinstalled -= (physmax - (PFN_64G - 1)); 10047c478bd9Sstevel@tonic-gate physmax = PFN_64G - 1; 10057c478bd9Sstevel@tonic-gate } 10067c478bd9Sstevel@tonic-gate } else { 10077c478bd9Sstevel@tonic-gate if (PFN_ABOVE4G(physmax)) { 10087c478bd9Sstevel@tonic-gate physinstalled -= (physmax - (PFN_4G - 1)); 10097c478bd9Sstevel@tonic-gate physmax = PFN_4G - 1; 10107c478bd9Sstevel@tonic-gate } 10117c478bd9Sstevel@tonic-gate } 10127c478bd9Sstevel@tonic-gate #endif 10137c478bd9Sstevel@tonic-gate 10147c478bd9Sstevel@tonic-gate startup_build_mem_nodes(bootops->boot_mem->physinstalled); 10157c478bd9Sstevel@tonic-gate 10167c478bd9Sstevel@tonic-gate if (BOP_GETPROPLEN(bootops, "enforce-prot-exec") >= 0) { 10177c478bd9Sstevel@tonic-gate int len = BOP_GETPROPLEN(bootops, "enforce-prot-exec"); 10187c478bd9Sstevel@tonic-gate char value[8]; 10197c478bd9Sstevel@tonic-gate 10207c478bd9Sstevel@tonic-gate if (len < 8) 10217c478bd9Sstevel@tonic-gate (void) BOP_GETPROP(bootops, "enforce-prot-exec", value); 10227c478bd9Sstevel@tonic-gate else 10237c478bd9Sstevel@tonic-gate (void) strcpy(value, ""); 10247c478bd9Sstevel@tonic-gate if (strcmp(value, "off") == 0) 10257c478bd9Sstevel@tonic-gate mmu.pt_nx = 0; 10267c478bd9Sstevel@tonic-gate } 10277c478bd9Sstevel@tonic-gate PRM_DEBUG(mmu.pt_nx); 10287c478bd9Sstevel@tonic-gate 10297c478bd9Sstevel@tonic-gate /* 10307c478bd9Sstevel@tonic-gate * We will need page_t's for every page in the system, except for 10317c478bd9Sstevel@tonic-gate * memory mapped at or above above the start of the kernel text segment. 10327c478bd9Sstevel@tonic-gate * 10337c478bd9Sstevel@tonic-gate * pages above e_modtext are attributed to kernel debugger (obp_pages) 10347c478bd9Sstevel@tonic-gate */ 10357c478bd9Sstevel@tonic-gate npages = physinstalled - 1; /* avail_filter() skips page 0, so "- 1" */ 10367c478bd9Sstevel@tonic-gate obp_pages = 0; 10377c478bd9Sstevel@tonic-gate va = KERNEL_TEXT; 1038ae115bc7Smrj while (kbm_probe(&va, &len, &pfn, &prot) != 0) { 10397c478bd9Sstevel@tonic-gate npages -= len >> MMU_PAGESHIFT; 10407c478bd9Sstevel@tonic-gate if (va >= (uintptr_t)e_moddata) 10417c478bd9Sstevel@tonic-gate obp_pages += len >> MMU_PAGESHIFT; 10427c478bd9Sstevel@tonic-gate va += len; 10437c478bd9Sstevel@tonic-gate } 10447c478bd9Sstevel@tonic-gate PRM_DEBUG(npages); 10457c478bd9Sstevel@tonic-gate PRM_DEBUG(obp_pages); 10467c478bd9Sstevel@tonic-gate 10477c478bd9Sstevel@tonic-gate /* 104835b1ab99Sjosephb * If physmem is patched to be non-zero, use it instead of the computed 104935b1ab99Sjosephb * value unless it is larger than the actual amount of memory on hand. 10507c478bd9Sstevel@tonic-gate */ 10514944b02eSkchow if (physmem == 0 || physmem > npages) { 10527c478bd9Sstevel@tonic-gate physmem = npages; 10534944b02eSkchow } else if (physmem < npages) { 1054f53ad214Skchow orig_npages = npages; 10557c478bd9Sstevel@tonic-gate npages = physmem; 10564944b02eSkchow } 10577c478bd9Sstevel@tonic-gate PRM_DEBUG(physmem); 10587c478bd9Sstevel@tonic-gate 10597c478bd9Sstevel@tonic-gate /* 10607c478bd9Sstevel@tonic-gate * We now compute the sizes of all the initial allocations for 10617c478bd9Sstevel@tonic-gate * structures the kernel needs in order do kmem_alloc(). These 10627c478bd9Sstevel@tonic-gate * include: 10637c478bd9Sstevel@tonic-gate * memsegs 10647c478bd9Sstevel@tonic-gate * memlists 10657c478bd9Sstevel@tonic-gate * page hash table 10667c478bd9Sstevel@tonic-gate * page_t's 10677c478bd9Sstevel@tonic-gate * page coloring data structs 10687c478bd9Sstevel@tonic-gate */ 10697c478bd9Sstevel@tonic-gate memseg_sz = sizeof (struct memseg) * (memblocks + POSS_NEW_FRAGMENTS); 10707c478bd9Sstevel@tonic-gate ADD_TO_ALLOCATIONS(memseg_base, memseg_sz); 10717c478bd9Sstevel@tonic-gate PRM_DEBUG(memseg_sz); 10727c478bd9Sstevel@tonic-gate 10737c478bd9Sstevel@tonic-gate /* 1074ae115bc7Smrj * Reserve space for memlists. There's no real good way to know exactly 1075ae115bc7Smrj * how much room we'll need, but this should be a good upper bound. 10767c478bd9Sstevel@tonic-gate */ 10777c478bd9Sstevel@tonic-gate memlist_sz = ROUND_UP_PAGE(2 * sizeof (struct memlist) * 10787c478bd9Sstevel@tonic-gate (memblocks + POSS_NEW_FRAGMENTS)); 10797c478bd9Sstevel@tonic-gate ADD_TO_ALLOCATIONS(memlist, memlist_sz); 10807c478bd9Sstevel@tonic-gate PRM_DEBUG(memlist_sz); 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate /* 10831de082f7SVikram Hegde * Reserve space for bios reserved memlists. 10841de082f7SVikram Hegde */ 10851de082f7SVikram Hegde rsvdmemlist_sz = ROUND_UP_PAGE(2 * sizeof (struct memlist) * 10861de082f7SVikram Hegde (rsvdmemblocks + POSS_NEW_FRAGMENTS)); 10871de082f7SVikram Hegde ADD_TO_ALLOCATIONS(bios_rsvd, rsvdmemlist_sz); 10881de082f7SVikram Hegde PRM_DEBUG(rsvdmemlist_sz); 10891de082f7SVikram Hegde 10901de082f7SVikram Hegde /* 10917c478bd9Sstevel@tonic-gate * The page structure hash table size is a power of 2 10927c478bd9Sstevel@tonic-gate * such that the average hash chain length is PAGE_HASHAVELEN. 10937c478bd9Sstevel@tonic-gate */ 10947c478bd9Sstevel@tonic-gate page_hashsz = npages / PAGE_HASHAVELEN; 10957c478bd9Sstevel@tonic-gate page_hashsz = 1 << highbit(page_hashsz); 10967c478bd9Sstevel@tonic-gate pagehash_sz = sizeof (struct page *) * page_hashsz; 10977c478bd9Sstevel@tonic-gate ADD_TO_ALLOCATIONS(page_hash, pagehash_sz); 10987c478bd9Sstevel@tonic-gate PRM_DEBUG(pagehash_sz); 10997c478bd9Sstevel@tonic-gate 11007c478bd9Sstevel@tonic-gate /* 1101ae115bc7Smrj * Set aside room for the page structures themselves. 11027c478bd9Sstevel@tonic-gate */ 1103ae115bc7Smrj PRM_DEBUG(npages); 1104ae115bc7Smrj pp_sz = sizeof (struct page) * npages; 11057c478bd9Sstevel@tonic-gate ADD_TO_ALLOCATIONS(pp_base, pp_sz); 11067c478bd9Sstevel@tonic-gate PRM_DEBUG(pp_sz); 11077c478bd9Sstevel@tonic-gate 11087c478bd9Sstevel@tonic-gate /* 11097c478bd9Sstevel@tonic-gate * determine l2 cache info and memory size for page coloring 11107c478bd9Sstevel@tonic-gate */ 11117c478bd9Sstevel@tonic-gate (void) getl2cacheinfo(CPU, 11127c478bd9Sstevel@tonic-gate &l2cache_sz, &l2cache_linesz, &l2cache_assoc); 11137c478bd9Sstevel@tonic-gate pagecolor_memsz = 11147c478bd9Sstevel@tonic-gate page_coloring_init(l2cache_sz, l2cache_linesz, l2cache_assoc); 11157c478bd9Sstevel@tonic-gate ADD_TO_ALLOCATIONS(pagecolor_mem, pagecolor_memsz); 11167c478bd9Sstevel@tonic-gate PRM_DEBUG(pagecolor_memsz); 11177c478bd9Sstevel@tonic-gate 11187c478bd9Sstevel@tonic-gate page_ctrs_size = page_ctrs_sz(); 11197c478bd9Sstevel@tonic-gate ADD_TO_ALLOCATIONS(page_ctrs_mem, page_ctrs_size); 11207c478bd9Sstevel@tonic-gate PRM_DEBUG(page_ctrs_size); 11217c478bd9Sstevel@tonic-gate 1122d7d93655Sblakej /* 1123d7d93655Sblakej * Allocate the array that protects pp->p_selock. 1124d7d93655Sblakej */ 1125d7d93655Sblakej pse_shift = size_pse_array(physmem, max_ncpus); 1126d7d93655Sblakej pse_table_size = 1 << pse_shift; 1127d7d93655Sblakej pse_table_alloc_size = pse_table_size * sizeof (pad_mutex_t); 1128d7d93655Sblakej ADD_TO_ALLOCATIONS(pse_mutex, pse_table_alloc_size); 1129d7d93655Sblakej 1130ae115bc7Smrj #if defined(__amd64) 11317c478bd9Sstevel@tonic-gate valloc_sz = ROUND_UP_LPAGE(valloc_sz); 1132ae115bc7Smrj valloc_base = VALLOC_BASE; 113335b1ab99Sjosephb 113435b1ab99Sjosephb /* 113535b1ab99Sjosephb * The default values of VALLOC_BASE and SEGKPM_BASE should work 113635b1ab99Sjosephb * for values of physmax up to 1 Terabyte. They need adjusting when 11376c8c89eaSKit Chow * memory is at addresses above 1 TB. When adjusted, segkpm_base must 11386c8c89eaSKit Chow * be aligned on KERNEL_REDZONE_SIZE boundary (span of top level pte). 113935b1ab99Sjosephb */ 114035b1ab99Sjosephb if (physmax + 1 > mmu_btop(TERABYTE)) { 114135b1ab99Sjosephb uint64_t kpm_resv_amount = mmu_ptob(physmax + 1); 114235b1ab99Sjosephb 11436c8c89eaSKit Chow segkpm_base = -(P2ROUNDUP((2 * kpm_resv_amount), 11446c8c89eaSKit Chow KERNEL_REDZONE_SIZE)); /* down from top VA */ 114535b1ab99Sjosephb 114635b1ab99Sjosephb /* make sure we leave some space for user apps above hole */ 114735b1ab99Sjosephb segkpm_base = MAX(segkpm_base, AMD64_VA_HOLE_END + TERABYTE); 114835b1ab99Sjosephb if (segkpm_base > SEGKPM_BASE) 114935b1ab99Sjosephb segkpm_base = SEGKPM_BASE; 115035b1ab99Sjosephb PRM_DEBUG(segkpm_base); 115135b1ab99Sjosephb 11526c8c89eaSKit Chow valloc_base = segkpm_base + P2ROUNDUP(kpm_resv_amount, ONE_GIG); 11536c8c89eaSKit Chow if (valloc_base < segkpm_base) 11546c8c89eaSKit Chow panic("not enough kernel VA to support memory size"); 115535b1ab99Sjosephb PRM_DEBUG(valloc_base); 115635b1ab99Sjosephb } 1157ae115bc7Smrj #else /* __i386 */ 1158ae115bc7Smrj valloc_base = (uintptr_t)(MISC_VA_BASE - valloc_sz); 1159ae115bc7Smrj valloc_base = P2ALIGN(valloc_base, mmu.level_size[1]); 11607c478bd9Sstevel@tonic-gate PRM_DEBUG(valloc_base); 116135b1ab99Sjosephb #endif /* __i386 */ 1162ae115bc7Smrj 1163ae115bc7Smrj /* 1164ae115bc7Smrj * do all the initial allocations 1165ae115bc7Smrj */ 1166ae115bc7Smrj perform_allocations(); 1167ae115bc7Smrj 1168ae115bc7Smrj /* 1169ae115bc7Smrj * Build phys_install and phys_avail in kernel memspace. 1170ae115bc7Smrj * - phys_install should be all memory in the system. 1171ae115bc7Smrj * - phys_avail is phys_install minus any memory mapped before this 1172ae115bc7Smrj * point above KERNEL_TEXT. 1173ae115bc7Smrj */ 1174ae115bc7Smrj current = phys_install = memlist; 1175ae115bc7Smrj copy_memlist_filter(bootops->boot_mem->physinstalled, ¤t, NULL); 1176ae115bc7Smrj if ((caddr_t)current > (caddr_t)memlist + memlist_sz) 1177ae115bc7Smrj panic("physinstalled was too big!"); 1178ae115bc7Smrj if (prom_debug) 1179ae115bc7Smrj print_memlist("phys_install", phys_install); 1180ae115bc7Smrj 1181ae115bc7Smrj phys_avail = current; 1182ae115bc7Smrj PRM_POINT("Building phys_avail:\n"); 1183ae115bc7Smrj copy_memlist_filter(bootops->boot_mem->physinstalled, ¤t, 1184ae115bc7Smrj avail_filter); 1185ae115bc7Smrj if ((caddr_t)current > (caddr_t)memlist + memlist_sz) 1186ae115bc7Smrj panic("physavail was too big!"); 1187ae115bc7Smrj if (prom_debug) 1188ae115bc7Smrj print_memlist("phys_avail", phys_avail); 1189ae115bc7Smrj 1190ae115bc7Smrj /* 11911de082f7SVikram Hegde * Build bios reserved memspace 11921de082f7SVikram Hegde */ 11931de082f7SVikram Hegde current = bios_rsvd; 11941de082f7SVikram Hegde copy_memlist_filter(bootops->boot_mem->rsvdmem, ¤t, NULL); 11951de082f7SVikram Hegde if ((caddr_t)current > (caddr_t)bios_rsvd + rsvdmemlist_sz) 11961de082f7SVikram Hegde panic("bios_rsvd was too big!"); 11971de082f7SVikram Hegde if (prom_debug) 11981de082f7SVikram Hegde print_memlist("bios_rsvd", bios_rsvd); 11991de082f7SVikram Hegde 12001de082f7SVikram Hegde /* 1201ae115bc7Smrj * setup page coloring 1202ae115bc7Smrj */ 1203ae115bc7Smrj page_coloring_setup(pagecolor_mem); 1204ae115bc7Smrj page_lock_init(); /* currently a no-op */ 1205ae115bc7Smrj 1206ae115bc7Smrj /* 1207ae115bc7Smrj * free page list counters 1208ae115bc7Smrj */ 1209ae115bc7Smrj (void) page_ctrs_alloc(page_ctrs_mem); 1210ae115bc7Smrj 1211ae115bc7Smrj /* 121206fb6a36Sdv142724 * Size the pcf array based on the number of cpus in the box at 121306fb6a36Sdv142724 * boot time. 121406fb6a36Sdv142724 */ 121506fb6a36Sdv142724 121606fb6a36Sdv142724 pcf_init(); 121706fb6a36Sdv142724 121806fb6a36Sdv142724 /* 1219ae115bc7Smrj * Initialize the page structures from the memory lists. 1220ae115bc7Smrj */ 1221ae115bc7Smrj availrmem_initial = availrmem = freemem = 0; 1222ae115bc7Smrj PRM_POINT("Calling kphysm_init()..."); 1223ae115bc7Smrj npages = kphysm_init(pp_base, npages); 1224ae115bc7Smrj PRM_POINT("kphysm_init() done"); 1225ae115bc7Smrj PRM_DEBUG(npages); 1226ae115bc7Smrj 1227ae115bc7Smrj init_debug_info(); 1228ae115bc7Smrj 1229ae115bc7Smrj /* 1230ae115bc7Smrj * Now that page_t's have been initialized, remove all the 1231ae115bc7Smrj * initial allocation pages from the kernel free page lists. 1232ae115bc7Smrj */ 1233ae115bc7Smrj boot_mapin((caddr_t)valloc_base, valloc_sz); 12340cfdb603Sjosephb boot_mapin((caddr_t)MISC_VA_BASE, MISC_VA_SIZE); 1235ae115bc7Smrj PRM_POINT("startup_memlist() done"); 1236ae115bc7Smrj 1237ae115bc7Smrj PRM_DEBUG(valloc_sz); 12382cb27123Saguzovsk 1239567d55e1Saguzovsk #if defined(__amd64) 1240567d55e1Saguzovsk if ((availrmem >> (30 - MMU_PAGESHIFT)) >= 1241567d55e1Saguzovsk textrepl_min_gb && l2cache_sz <= 2 << 20) { 1242567d55e1Saguzovsk extern size_t textrepl_size_thresh; 12432cb27123Saguzovsk textrepl_size_thresh = (16 << 20) - 1; 12442cb27123Saguzovsk } 1245567d55e1Saguzovsk #endif 1246ae115bc7Smrj } 1247ae115bc7Smrj 1248ae115bc7Smrj /* 1249ae115bc7Smrj * Layout the kernel's part of address space and initialize kmem allocator. 1250ae115bc7Smrj */ 1251ae115bc7Smrj static void 1252ae115bc7Smrj startup_kmem(void) 1253ae115bc7Smrj { 1254932dc8e5Sdp78419 extern void page_set_colorequiv_arr(void); 1255a50a8b93SKuriakose Kuruvilla const char *fmt = "?features: %b\n"; 1256932dc8e5Sdp78419 1257ae115bc7Smrj PRM_POINT("startup_kmem() starting..."); 12587c478bd9Sstevel@tonic-gate 12597c478bd9Sstevel@tonic-gate #if defined(__amd64) 12607c478bd9Sstevel@tonic-gate if (eprom_kernelbase && eprom_kernelbase != KERNELBASE) 12617c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!kernelbase cannot be changed on 64-bit " 12627c478bd9Sstevel@tonic-gate "systems."); 126335b1ab99Sjosephb kernelbase = segkpm_base - KERNEL_REDZONE_SIZE; 12647c478bd9Sstevel@tonic-gate core_base = (uintptr_t)COREHEAP_BASE; 1265ae115bc7Smrj core_size = (size_t)MISC_VA_BASE - COREHEAP_BASE; 12667c478bd9Sstevel@tonic-gate #else /* __i386 */ 12677c478bd9Sstevel@tonic-gate /* 12687c478bd9Sstevel@tonic-gate * We configure kernelbase based on: 12697c478bd9Sstevel@tonic-gate * 12707c478bd9Sstevel@tonic-gate * 1. user specified kernelbase via eeprom command. Value cannot exceed 12717c478bd9Sstevel@tonic-gate * KERNELBASE_MAX. we large page align eprom_kernelbase 12727c478bd9Sstevel@tonic-gate * 12737c478bd9Sstevel@tonic-gate * 2. Default to KERNELBASE and adjust to 2X less the size for page_t. 12747c478bd9Sstevel@tonic-gate * On large memory systems we must lower kernelbase to allow 12757c478bd9Sstevel@tonic-gate * enough room for page_t's for all of memory. 12767c478bd9Sstevel@tonic-gate * 12777c478bd9Sstevel@tonic-gate * The value set here, might be changed a little later. 12787c478bd9Sstevel@tonic-gate */ 12797c478bd9Sstevel@tonic-gate if (eprom_kernelbase) { 12807c478bd9Sstevel@tonic-gate kernelbase = eprom_kernelbase & mmu.level_mask[1]; 12817c478bd9Sstevel@tonic-gate if (kernelbase > KERNELBASE_MAX) 12827c478bd9Sstevel@tonic-gate kernelbase = KERNELBASE_MAX; 12837c478bd9Sstevel@tonic-gate } else { 12847c478bd9Sstevel@tonic-gate kernelbase = (uintptr_t)KERNELBASE; 12857c478bd9Sstevel@tonic-gate kernelbase -= ROUND_UP_4MEG(2 * valloc_sz); 12867c478bd9Sstevel@tonic-gate } 12877c478bd9Sstevel@tonic-gate ASSERT((kernelbase & mmu.level_offset[1]) == 0); 1288ae115bc7Smrj core_base = valloc_base; 12897c478bd9Sstevel@tonic-gate core_size = 0; 1290ae115bc7Smrj #endif /* __i386 */ 12917c478bd9Sstevel@tonic-gate 12927c478bd9Sstevel@tonic-gate PRM_DEBUG(core_base); 12937c478bd9Sstevel@tonic-gate PRM_DEBUG(core_size); 1294ae115bc7Smrj PRM_DEBUG(kernelbase); 12957c478bd9Sstevel@tonic-gate 129635b1ab99Sjosephb #if defined(__i386) 12977c478bd9Sstevel@tonic-gate segkp_fromheap = 1; 1298ae115bc7Smrj #endif /* __i386 */ 129935b1ab99Sjosephb 13007c478bd9Sstevel@tonic-gate ekernelheap = (char *)core_base; 1301ae115bc7Smrj PRM_DEBUG(ekernelheap); 13027c478bd9Sstevel@tonic-gate 13037c478bd9Sstevel@tonic-gate /* 13047c478bd9Sstevel@tonic-gate * Now that we know the real value of kernelbase, 13057c478bd9Sstevel@tonic-gate * update variables that were initialized with a value of 13067c478bd9Sstevel@tonic-gate * KERNELBASE (in common/conf/param.c). 13077c478bd9Sstevel@tonic-gate * 13087c478bd9Sstevel@tonic-gate * XXX The problem with this sort of hackery is that the 13097c478bd9Sstevel@tonic-gate * compiler just may feel like putting the const declarations 13107c478bd9Sstevel@tonic-gate * (in param.c) into the .text section. Perhaps they should 13117c478bd9Sstevel@tonic-gate * just be declared as variables there? 13127c478bd9Sstevel@tonic-gate */ 13137c478bd9Sstevel@tonic-gate 13147c478bd9Sstevel@tonic-gate *(uintptr_t *)&_kernelbase = kernelbase; 13157c478bd9Sstevel@tonic-gate *(uintptr_t *)&_userlimit = kernelbase; 1316ccbaea4fSjosephb #if defined(__amd64) 1317ccbaea4fSjosephb *(uintptr_t *)&_userlimit -= KERNELBASE - USERLIMIT; 1318ccbaea4fSjosephb #else 13197c478bd9Sstevel@tonic-gate *(uintptr_t *)&_userlimit32 = _userlimit; 13207c478bd9Sstevel@tonic-gate #endif 13217c478bd9Sstevel@tonic-gate PRM_DEBUG(_kernelbase); 13227c478bd9Sstevel@tonic-gate PRM_DEBUG(_userlimit); 13237c478bd9Sstevel@tonic-gate PRM_DEBUG(_userlimit32); 13247c478bd9Sstevel@tonic-gate 132535b1ab99Sjosephb layout_kernel_va(); 132635b1ab99Sjosephb 132735b1ab99Sjosephb #if defined(__i386) 132835b1ab99Sjosephb /* 132935b1ab99Sjosephb * If segmap is too large we can push the bottom of the kernel heap 133035b1ab99Sjosephb * higher than the base. Or worse, it could exceed the top of the 133135b1ab99Sjosephb * VA space entirely, causing it to wrap around. 133235b1ab99Sjosephb */ 133335b1ab99Sjosephb if (kernelheap >= ekernelheap || (uintptr_t)kernelheap < kernelbase) 133435b1ab99Sjosephb panic("too little address space available for kernelheap," 133535b1ab99Sjosephb " use eeprom for lower kernelbase or smaller segmapsize"); 133635b1ab99Sjosephb #endif /* __i386 */ 133735b1ab99Sjosephb 13387c478bd9Sstevel@tonic-gate /* 13397c478bd9Sstevel@tonic-gate * Initialize the kernel heap. Note 3rd argument must be > 1st. 13407c478bd9Sstevel@tonic-gate */ 134135b1ab99Sjosephb kernelheap_init(kernelheap, ekernelheap, 134235b1ab99Sjosephb kernelheap + MMU_PAGESIZE, 1343ae115bc7Smrj (void *)core_base, (void *)(core_base + core_size)); 13447c478bd9Sstevel@tonic-gate 1345843e1988Sjohnlev #if defined(__xpv) 1346843e1988Sjohnlev /* 1347843e1988Sjohnlev * Link pending events struct into cpu struct 1348843e1988Sjohnlev */ 1349843e1988Sjohnlev CPU->cpu_m.mcpu_evt_pend = &cpu0_evt_data; 1350843e1988Sjohnlev #endif 13517c478bd9Sstevel@tonic-gate /* 13527c478bd9Sstevel@tonic-gate * Initialize kernel memory allocator. 13537c478bd9Sstevel@tonic-gate */ 13547c478bd9Sstevel@tonic-gate kmem_init(); 13557c478bd9Sstevel@tonic-gate 13567c478bd9Sstevel@tonic-gate /* 1357932dc8e5Sdp78419 * Factor in colorequiv to check additional 'equivalent' bins 1358932dc8e5Sdp78419 */ 1359932dc8e5Sdp78419 page_set_colorequiv_arr(); 1360932dc8e5Sdp78419 1361932dc8e5Sdp78419 /* 13627c478bd9Sstevel@tonic-gate * print this out early so that we know what's going on 13637c478bd9Sstevel@tonic-gate */ 1364a50a8b93SKuriakose Kuruvilla cmn_err(CE_CONT, fmt, x86_feature, FMT_X86_FEATURE); 13657c478bd9Sstevel@tonic-gate 13667c478bd9Sstevel@tonic-gate /* 13677c478bd9Sstevel@tonic-gate * Initialize bp_mapin(). 13687c478bd9Sstevel@tonic-gate */ 13697c478bd9Sstevel@tonic-gate bp_init(MMU_PAGESIZE, HAT_STORECACHING_OK); 13707c478bd9Sstevel@tonic-gate 1371f53ad214Skchow /* 1372f53ad214Skchow * orig_npages is non-zero if physmem has been configured for less 1373f53ad214Skchow * than the available memory. 1374f53ad214Skchow */ 1375f53ad214Skchow if (orig_npages) { 137635b1ab99Sjosephb cmn_err(CE_WARN, "!%slimiting physmem to 0x%lx of 0x%lx pages", 137735b1ab99Sjosephb (npages == PHYSMEM ? "Due to virtual address space " : ""), 1378f53ad214Skchow npages, orig_npages); 1379f53ad214Skchow } 13807c478bd9Sstevel@tonic-gate #if defined(__i386) 13817c478bd9Sstevel@tonic-gate if (eprom_kernelbase && (eprom_kernelbase != kernelbase)) 13827c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "kernelbase value, User specified 0x%lx, " 13837c478bd9Sstevel@tonic-gate "System using 0x%lx", 13847c478bd9Sstevel@tonic-gate (uintptr_t)eprom_kernelbase, (uintptr_t)kernelbase); 13857c478bd9Sstevel@tonic-gate #endif 13867c478bd9Sstevel@tonic-gate 13877c478bd9Sstevel@tonic-gate #ifdef KERNELBASE_ABI_MIN 13887c478bd9Sstevel@tonic-gate if (kernelbase < (uintptr_t)KERNELBASE_ABI_MIN) { 13897c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!kernelbase set to 0x%lx, system is not " 13907c478bd9Sstevel@tonic-gate "i386 ABI compliant.", (uintptr_t)kernelbase); 13917c478bd9Sstevel@tonic-gate } 13927c478bd9Sstevel@tonic-gate #endif 13937c478bd9Sstevel@tonic-gate 1394843e1988Sjohnlev #ifdef __xpv 1395843e1988Sjohnlev /* 1396843e1988Sjohnlev * Some of the xen start information has to be relocated up 1397843e1988Sjohnlev * into the kernel's permanent address space. 1398843e1988Sjohnlev */ 1399843e1988Sjohnlev PRM_POINT("calling xen_relocate_start_info()"); 1400843e1988Sjohnlev xen_relocate_start_info(); 1401843e1988Sjohnlev PRM_POINT("xen_relocate_start_info() done"); 1402843e1988Sjohnlev 1403843e1988Sjohnlev /* 1404843e1988Sjohnlev * (Update the vcpu pointer in our cpu structure to point into 1405843e1988Sjohnlev * the relocated shared info.) 1406843e1988Sjohnlev */ 1407843e1988Sjohnlev CPU->cpu_m.mcpu_vcpu_info = 1408843e1988Sjohnlev &HYPERVISOR_shared_info->vcpu_info[CPU->cpu_id]; 1409843e1988Sjohnlev #endif 1410843e1988Sjohnlev 1411ae115bc7Smrj PRM_POINT("startup_kmem() done"); 14127c478bd9Sstevel@tonic-gate } 14137c478bd9Sstevel@tonic-gate 1414551bc2a6Smrj #ifndef __xpv 1415551bc2a6Smrj /* 1416551bc2a6Smrj * If we have detected that we are running in an HVM environment, we need 1417551bc2a6Smrj * to prepend the PV driver directory to the module search path. 1418551bc2a6Smrj */ 1419551bc2a6Smrj #define HVM_MOD_DIR "/platform/i86hvm/kernel" 1420551bc2a6Smrj static void 1421551bc2a6Smrj update_default_path() 1422551bc2a6Smrj { 1423551bc2a6Smrj char *current, *newpath; 1424551bc2a6Smrj int newlen; 1425551bc2a6Smrj 1426551bc2a6Smrj /* 1427551bc2a6Smrj * We are about to resync with krtld. krtld will reset its 1428551bc2a6Smrj * internal module search path iff Solaris has set default_path. 1429551bc2a6Smrj * We want to be sure we're prepending this new directory to the 1430551bc2a6Smrj * right search path. 1431551bc2a6Smrj */ 1432551bc2a6Smrj current = (default_path == NULL) ? kobj_module_path : default_path; 1433551bc2a6Smrj 1434*b6611e3bSStuart Maybee newlen = strlen(HVM_MOD_DIR) + strlen(current) + 2; 1435551bc2a6Smrj newpath = kmem_alloc(newlen, KM_SLEEP); 1436551bc2a6Smrj (void) strcpy(newpath, HVM_MOD_DIR); 1437551bc2a6Smrj (void) strcat(newpath, " "); 1438551bc2a6Smrj (void) strcat(newpath, current); 1439551bc2a6Smrj 1440551bc2a6Smrj default_path = newpath; 1441551bc2a6Smrj } 1442551bc2a6Smrj #endif 1443551bc2a6Smrj 14447c478bd9Sstevel@tonic-gate static void 14457c478bd9Sstevel@tonic-gate startup_modules(void) 14467c478bd9Sstevel@tonic-gate { 1447ed5289f9SKen Erickson int cnt; 14487c478bd9Sstevel@tonic-gate extern void prom_setup(void); 1449ed5289f9SKen Erickson int32_t v, h; 1450ed5289f9SKen Erickson char d[11]; 1451ed5289f9SKen Erickson char *cp; 1452e4b86885SCheng Sean Ye cmi_hdl_t hdl; 14537c478bd9Sstevel@tonic-gate 14547c478bd9Sstevel@tonic-gate PRM_POINT("startup_modules() starting..."); 1455843e1988Sjohnlev 1456843e1988Sjohnlev #ifndef __xpv 14577c478bd9Sstevel@tonic-gate /* 14587c478bd9Sstevel@tonic-gate * Initialize ten-micro second timer so that drivers will 14597c478bd9Sstevel@tonic-gate * not get short changed in their init phase. This was 14607c478bd9Sstevel@tonic-gate * not getting called until clkinit which, on fast cpu's 14617c478bd9Sstevel@tonic-gate * caused the drv_usecwait to be way too short. 14627c478bd9Sstevel@tonic-gate */ 14637c478bd9Sstevel@tonic-gate microfind(); 1464551bc2a6Smrj 1465b9bfdccdSStuart Maybee if (get_hwenv() == HW_XEN_HVM) 1466551bc2a6Smrj update_default_path(); 1467843e1988Sjohnlev #endif 14687c478bd9Sstevel@tonic-gate 14697c478bd9Sstevel@tonic-gate /* 14707c478bd9Sstevel@tonic-gate * Read the GMT lag from /etc/rtc_config. 14717c478bd9Sstevel@tonic-gate */ 1472ae115bc7Smrj sgmtl(process_rtc_config_file()); 14737c478bd9Sstevel@tonic-gate 14747c478bd9Sstevel@tonic-gate /* 14757c478bd9Sstevel@tonic-gate * Calculate default settings of system parameters based upon 14767c478bd9Sstevel@tonic-gate * maxusers, yet allow to be overridden via the /etc/system file. 14777c478bd9Sstevel@tonic-gate */ 14787c478bd9Sstevel@tonic-gate param_calc(0); 14797c478bd9Sstevel@tonic-gate 14807c478bd9Sstevel@tonic-gate mod_setup(); 14817c478bd9Sstevel@tonic-gate 14827c478bd9Sstevel@tonic-gate /* 14837c478bd9Sstevel@tonic-gate * Initialize system parameters. 14847c478bd9Sstevel@tonic-gate */ 14857c478bd9Sstevel@tonic-gate param_init(); 14867c478bd9Sstevel@tonic-gate 14877c478bd9Sstevel@tonic-gate /* 14889acbbeafSnn35248 * Initialize the default brands 14899acbbeafSnn35248 */ 14909acbbeafSnn35248 brand_init(); 14919acbbeafSnn35248 14929acbbeafSnn35248 /* 14937c478bd9Sstevel@tonic-gate * maxmem is the amount of physical memory we're playing with. 14947c478bd9Sstevel@tonic-gate */ 14957c478bd9Sstevel@tonic-gate maxmem = physmem; 14967c478bd9Sstevel@tonic-gate 14977c478bd9Sstevel@tonic-gate /* 14987c478bd9Sstevel@tonic-gate * Initialize segment management stuff. 14997c478bd9Sstevel@tonic-gate */ 15007c478bd9Sstevel@tonic-gate seg_init(); 15017c478bd9Sstevel@tonic-gate 15027c478bd9Sstevel@tonic-gate if (modload("fs", "specfs") == -1) 15037c478bd9Sstevel@tonic-gate halt("Can't load specfs"); 15047c478bd9Sstevel@tonic-gate 15057c478bd9Sstevel@tonic-gate if (modload("fs", "devfs") == -1) 15067c478bd9Sstevel@tonic-gate halt("Can't load devfs"); 15077c478bd9Sstevel@tonic-gate 1508facf4a8dSllai1 if (modload("fs", "dev") == -1) 1509facf4a8dSllai1 halt("Can't load dev"); 1510facf4a8dSllai1 151135a5a358SJonathan Adams if (modload("fs", "procfs") == -1) 151235a5a358SJonathan Adams halt("Can't load procfs"); 151335a5a358SJonathan Adams 151445916cd2Sjpk (void) modloadonly("sys", "lbl_edition"); 151545916cd2Sjpk 15167c478bd9Sstevel@tonic-gate dispinit(); 15177c478bd9Sstevel@tonic-gate 15187c478bd9Sstevel@tonic-gate /* 15197c478bd9Sstevel@tonic-gate * This is needed here to initialize hw_serial[] for cluster booting. 15207c478bd9Sstevel@tonic-gate */ 15215679c89fSjv227347 if ((h = set_soft_hostid()) == HW_INVALID_HOSTID) { 1522ed5289f9SKen Erickson cmn_err(CE_WARN, "Unable to set hostid"); 15235679c89fSjv227347 } else { 1524ed5289f9SKen Erickson for (v = h, cnt = 0; cnt < 10; cnt++) { 15255679c89fSjv227347 d[cnt] = (char)(v % 10); 1526ed5289f9SKen Erickson v /= 10; 1527ed5289f9SKen Erickson if (v == 0) 1528ed5289f9SKen Erickson break; 1529ed5289f9SKen Erickson } 1530ed5289f9SKen Erickson for (cp = hw_serial; cnt >= 0; cnt--) 1531ed5289f9SKen Erickson *cp++ = d[cnt] + '0'; 1532ed5289f9SKen Erickson *cp = 0; 1533ed5289f9SKen Erickson } 15347c478bd9Sstevel@tonic-gate 15357c478bd9Sstevel@tonic-gate /* Read cluster configuration data. */ 15367c478bd9Sstevel@tonic-gate clconf_init(); 15377c478bd9Sstevel@tonic-gate 1538843e1988Sjohnlev #if defined(__xpv) 1539349b53ddSStuart Maybee (void) ec_init(); 1540843e1988Sjohnlev gnttab_init(); 1541843e1988Sjohnlev (void) xs_early_init(); 1542843e1988Sjohnlev #endif /* __xpv */ 1543843e1988Sjohnlev 15447c478bd9Sstevel@tonic-gate /* 15457c478bd9Sstevel@tonic-gate * Create a kernel device tree. First, create rootnex and 15467c478bd9Sstevel@tonic-gate * then invoke bus specific code to probe devices. 15477c478bd9Sstevel@tonic-gate */ 15487c478bd9Sstevel@tonic-gate setup_ddi(); 15497aec1d6eScindi 1550074bb90dSTom Pothier #ifdef __xpv 1551074bb90dSTom Pothier if (DOMAIN_IS_INITDOMAIN(xen_info)) 1552074bb90dSTom Pothier #endif 1553074bb90dSTom Pothier { 1554074bb90dSTom Pothier /* 1555074bb90dSTom Pothier * Load the System Management BIOS into the global ksmbios 1556074bb90dSTom Pothier * handle, if an SMBIOS is present on this system. 1557074bb90dSTom Pothier */ 1558074bb90dSTom Pothier ksmbios = smbios_open(NULL, SMB_VERSION, ksmbios_flags, NULL); 1559074bb90dSTom Pothier } 1560074bb90dSTom Pothier 1561074bb90dSTom Pothier 15627aec1d6eScindi /* 1563e4b86885SCheng Sean Ye * Set up the CPU module subsystem for the boot cpu in the native 1564e4b86885SCheng Sean Ye * case, and all physical cpu resource in the xpv dom0 case. 1565e4b86885SCheng Sean Ye * Modifies the device tree, so this must be done after 1566e4b86885SCheng Sean Ye * setup_ddi(). 15677aec1d6eScindi */ 1568e4b86885SCheng Sean Ye #ifdef __xpv 1569e4b86885SCheng Sean Ye /* 1570e4b86885SCheng Sean Ye * If paravirtualized and on dom0 then we initialize all physical 1571e4b86885SCheng Sean Ye * cpu handles now; if paravirtualized on a domU then do not 1572e4b86885SCheng Sean Ye * initialize. 1573e4b86885SCheng Sean Ye */ 1574e4b86885SCheng Sean Ye if (DOMAIN_IS_INITDOMAIN(xen_info)) { 1575e4b86885SCheng Sean Ye xen_mc_lcpu_cookie_t cpi; 15767aec1d6eScindi 1577e4b86885SCheng Sean Ye for (cpi = xen_physcpu_next(NULL); cpi != NULL; 1578e4b86885SCheng Sean Ye cpi = xen_physcpu_next(cpi)) { 1579e4b86885SCheng Sean Ye if ((hdl = cmi_init(CMI_HDL_SOLARIS_xVM_MCA, 1580e4b86885SCheng Sean Ye xen_physcpu_chipid(cpi), xen_physcpu_coreid(cpi), 1581e4b86885SCheng Sean Ye xen_physcpu_strandid(cpi))) != NULL && 1582e4b86885SCheng Sean Ye (x86_feature & X86_MCA)) 158320c794b3Sgavinm cmi_mca_init(hdl); 158420c794b3Sgavinm } 158520c794b3Sgavinm } 1586e4b86885SCheng Sean Ye #else 1587e4b86885SCheng Sean Ye /* 1588e4b86885SCheng Sean Ye * Initialize a handle for the boot cpu - others will initialize 1589e4b86885SCheng Sean Ye * as they startup. Do not do this if we know we are in an HVM domU. 1590e4b86885SCheng Sean Ye */ 1591b9bfdccdSStuart Maybee if ((get_hwenv() != HW_XEN_HVM) && 1592e4b86885SCheng Sean Ye (hdl = cmi_init(CMI_HDL_NATIVE, cmi_ntv_hwchipid(CPU), 1593e4b86885SCheng Sean Ye cmi_ntv_hwcoreid(CPU), cmi_ntv_hwstrandid(CPU))) != NULL && 1594e4b86885SCheng Sean Ye (x86_feature & X86_MCA)) 1595e4b86885SCheng Sean Ye cmi_mca_init(hdl); 159620c794b3Sgavinm #endif /* __xpv */ 15977aec1d6eScindi 15987c478bd9Sstevel@tonic-gate /* 15997c478bd9Sstevel@tonic-gate * Fake a prom tree such that /dev/openprom continues to work 16007c478bd9Sstevel@tonic-gate */ 1601ae115bc7Smrj PRM_POINT("startup_modules: calling prom_setup..."); 16027c478bd9Sstevel@tonic-gate prom_setup(); 1603ae115bc7Smrj PRM_POINT("startup_modules: done"); 16047c478bd9Sstevel@tonic-gate 16057c478bd9Sstevel@tonic-gate /* 16067c478bd9Sstevel@tonic-gate * Load all platform specific modules 16077c478bd9Sstevel@tonic-gate */ 1608ae115bc7Smrj PRM_POINT("startup_modules: calling psm_modload..."); 16097c478bd9Sstevel@tonic-gate psm_modload(); 16107c478bd9Sstevel@tonic-gate 16117c478bd9Sstevel@tonic-gate PRM_POINT("startup_modules() done"); 16127c478bd9Sstevel@tonic-gate } 16137c478bd9Sstevel@tonic-gate 1614ae115bc7Smrj /* 1615ae115bc7Smrj * claim a "setaside" boot page for use in the kernel 1616ae115bc7Smrj */ 1617ae115bc7Smrj page_t * 1618ae115bc7Smrj boot_claim_page(pfn_t pfn) 16197c478bd9Sstevel@tonic-gate { 1620ae115bc7Smrj page_t *pp; 16217c478bd9Sstevel@tonic-gate 1622ae115bc7Smrj pp = page_numtopp_nolock(pfn); 1623ae115bc7Smrj ASSERT(pp != NULL); 16247c478bd9Sstevel@tonic-gate 1625ae115bc7Smrj if (PP_ISBOOTPAGES(pp)) { 1626ae115bc7Smrj if (pp->p_next != NULL) 1627ae115bc7Smrj pp->p_next->p_prev = pp->p_prev; 1628ae115bc7Smrj if (pp->p_prev == NULL) 1629ae115bc7Smrj bootpages = pp->p_next; 1630ae115bc7Smrj else 1631ae115bc7Smrj pp->p_prev->p_next = pp->p_next; 1632ae115bc7Smrj } else { 16337c478bd9Sstevel@tonic-gate /* 1634ae115bc7Smrj * htable_attach() expects a base pagesize page 16357c478bd9Sstevel@tonic-gate */ 1636ae115bc7Smrj if (pp->p_szc != 0) 1637ae115bc7Smrj page_boot_demote(pp); 1638ae115bc7Smrj pp = page_numtopp(pfn, SE_EXCL); 1639ae115bc7Smrj } 1640ae115bc7Smrj return (pp); 16417c478bd9Sstevel@tonic-gate } 16427c478bd9Sstevel@tonic-gate 16437c478bd9Sstevel@tonic-gate /* 16447c478bd9Sstevel@tonic-gate * Walk through the pagetables looking for pages mapped in by boot. If the 16457c478bd9Sstevel@tonic-gate * setaside flag is set the pages are expected to be returned to the 16467c478bd9Sstevel@tonic-gate * kernel later in boot, so we add them to the bootpages list. 16477c478bd9Sstevel@tonic-gate */ 16487c478bd9Sstevel@tonic-gate static void 16497c478bd9Sstevel@tonic-gate protect_boot_range(uintptr_t low, uintptr_t high, int setaside) 16507c478bd9Sstevel@tonic-gate { 16517c478bd9Sstevel@tonic-gate uintptr_t va = low; 16527c478bd9Sstevel@tonic-gate size_t len; 16537c478bd9Sstevel@tonic-gate uint_t prot; 16547c478bd9Sstevel@tonic-gate pfn_t pfn; 16557c478bd9Sstevel@tonic-gate page_t *pp; 16567c478bd9Sstevel@tonic-gate pgcnt_t boot_protect_cnt = 0; 16577c478bd9Sstevel@tonic-gate 1658ae115bc7Smrj while (kbm_probe(&va, &len, &pfn, &prot) != 0 && va < high) { 16597c478bd9Sstevel@tonic-gate if (va + len >= high) 16607c478bd9Sstevel@tonic-gate panic("0x%lx byte mapping at 0x%p exceeds boot's " 16617c478bd9Sstevel@tonic-gate "legal range.", len, (void *)va); 16627c478bd9Sstevel@tonic-gate 16637c478bd9Sstevel@tonic-gate while (len > 0) { 16647c478bd9Sstevel@tonic-gate pp = page_numtopp_alloc(pfn); 16657c478bd9Sstevel@tonic-gate if (pp != NULL) { 16667c478bd9Sstevel@tonic-gate if (setaside == 0) 16677c478bd9Sstevel@tonic-gate panic("Unexpected mapping by boot. " 16687c478bd9Sstevel@tonic-gate "addr=%p pfn=%lx\n", 16697c478bd9Sstevel@tonic-gate (void *)va, pfn); 16707c478bd9Sstevel@tonic-gate 16717c478bd9Sstevel@tonic-gate pp->p_next = bootpages; 1672ae115bc7Smrj pp->p_prev = NULL; 1673ae115bc7Smrj PP_SETBOOTPAGES(pp); 1674ae115bc7Smrj if (bootpages != NULL) { 1675ae115bc7Smrj bootpages->p_prev = pp; 1676ae115bc7Smrj } 16777c478bd9Sstevel@tonic-gate bootpages = pp; 16787c478bd9Sstevel@tonic-gate ++boot_protect_cnt; 16797c478bd9Sstevel@tonic-gate } 16807c478bd9Sstevel@tonic-gate 16817c478bd9Sstevel@tonic-gate ++pfn; 16827c478bd9Sstevel@tonic-gate len -= MMU_PAGESIZE; 16837c478bd9Sstevel@tonic-gate va += MMU_PAGESIZE; 16847c478bd9Sstevel@tonic-gate } 16857c478bd9Sstevel@tonic-gate } 16867c478bd9Sstevel@tonic-gate PRM_DEBUG(boot_protect_cnt); 16877c478bd9Sstevel@tonic-gate } 16887c478bd9Sstevel@tonic-gate 1689ae115bc7Smrj /* 169035b1ab99Sjosephb * 1691ae115bc7Smrj */ 16927c478bd9Sstevel@tonic-gate static void 169335b1ab99Sjosephb layout_kernel_va(void) 16947c478bd9Sstevel@tonic-gate { 169535b1ab99Sjosephb PRM_POINT("layout_kernel_va() starting..."); 16967c478bd9Sstevel@tonic-gate /* 1697ae115bc7Smrj * Establish the final size of the kernel's heap, size of segmap, 1698ae115bc7Smrj * segkp, etc. 16997c478bd9Sstevel@tonic-gate */ 17007c478bd9Sstevel@tonic-gate 17017c478bd9Sstevel@tonic-gate #if defined(__amd64) 17027c478bd9Sstevel@tonic-gate 170335b1ab99Sjosephb kpm_vbase = (caddr_t)segkpm_base; 1704ae115bc7Smrj kpm_size = ROUND_UP_LPAGE(mmu_ptob(physmax + 1)); 170535b1ab99Sjosephb if ((uintptr_t)kpm_vbase + kpm_size > (uintptr_t)valloc_base) 170635b1ab99Sjosephb panic("not enough room for kpm!"); 1707ae115bc7Smrj PRM_DEBUG(kpm_size); 1708ae115bc7Smrj PRM_DEBUG(kpm_vbase); 1709ae115bc7Smrj 1710ae115bc7Smrj /* 1711ae115bc7Smrj * By default we create a seg_kp in 64 bit kernels, it's a little 1712ae115bc7Smrj * faster to access than embedding it in the heap. 1713ae115bc7Smrj */ 1714ae115bc7Smrj segkp_base = (caddr_t)valloc_base + valloc_sz; 17157c478bd9Sstevel@tonic-gate if (!segkp_fromheap) { 17167c478bd9Sstevel@tonic-gate size_t sz = mmu_ptob(segkpsize); 17177c478bd9Sstevel@tonic-gate 17187c478bd9Sstevel@tonic-gate /* 1719ae115bc7Smrj * determine size of segkp 17207c478bd9Sstevel@tonic-gate */ 17217c478bd9Sstevel@tonic-gate if (sz < SEGKPMINSIZE || sz > SEGKPMAXSIZE) { 17227c478bd9Sstevel@tonic-gate sz = SEGKPDEFSIZE; 17237c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "!Illegal value for segkpsize. " 17247c478bd9Sstevel@tonic-gate "segkpsize has been reset to %ld pages", 17257c478bd9Sstevel@tonic-gate mmu_btop(sz)); 17267c478bd9Sstevel@tonic-gate } 17277c478bd9Sstevel@tonic-gate sz = MIN(sz, MAX(SEGKPMINSIZE, mmu_ptob(physmem))); 17287c478bd9Sstevel@tonic-gate 17297c478bd9Sstevel@tonic-gate segkpsize = mmu_btop(ROUND_UP_LPAGE(sz)); 17307c478bd9Sstevel@tonic-gate } 1731ae115bc7Smrj PRM_DEBUG(segkp_base); 1732ae115bc7Smrj PRM_DEBUG(segkpsize); 17337c478bd9Sstevel@tonic-gate 173435b1ab99Sjosephb /* 173535b1ab99Sjosephb * segzio is used for ZFS cached data. It uses a distinct VA 173635b1ab99Sjosephb * segment (from kernel heap) so that we can easily tell not to 173735b1ab99Sjosephb * include it in kernel crash dumps on 64 bit kernels. The trick is 173835b1ab99Sjosephb * to give it lots of VA, but not constrain the kernel heap. 173935b1ab99Sjosephb * We scale the size of segzio linearly with physmem up to 174035b1ab99Sjosephb * SEGZIOMAXSIZE. Above that amount it scales at 50% of physmem. 174135b1ab99Sjosephb */ 1742ae115bc7Smrj segzio_base = segkp_base + mmu_ptob(segkpsize); 1743ae115bc7Smrj if (segzio_fromheap) { 1744ae115bc7Smrj segziosize = 0; 1745ae115bc7Smrj } else { 174635b1ab99Sjosephb size_t physmem_size = mmu_ptob(physmem); 174735b1ab99Sjosephb size_t size = (segziosize == 0) ? 174835b1ab99Sjosephb physmem_size : mmu_ptob(segziosize); 1749ad23a2dbSjohansen 175035b1ab99Sjosephb if (size < SEGZIOMINSIZE) 1751ad23a2dbSjohansen size = SEGZIOMINSIZE; 175235b1ab99Sjosephb if (size > SEGZIOMAXSIZE) { 1753a778305aSjohansen size = SEGZIOMAXSIZE; 175435b1ab99Sjosephb if (physmem_size > size) 175535b1ab99Sjosephb size += (physmem_size - size) / 2; 1756ad23a2dbSjohansen } 1757ad23a2dbSjohansen segziosize = mmu_btop(ROUND_UP_LPAGE(size)); 1758ae115bc7Smrj } 1759ad23a2dbSjohansen PRM_DEBUG(segziosize); 1760ad23a2dbSjohansen PRM_DEBUG(segzio_base); 1761ad23a2dbSjohansen 17627c478bd9Sstevel@tonic-gate /* 1763ae115bc7Smrj * Put the range of VA for device mappings next, kmdb knows to not 1764ae115bc7Smrj * grep in this range of addresses. 17657c478bd9Sstevel@tonic-gate */ 1766ae115bc7Smrj toxic_addr = 1767ae115bc7Smrj ROUND_UP_LPAGE((uintptr_t)segzio_base + mmu_ptob(segziosize)); 17687c478bd9Sstevel@tonic-gate PRM_DEBUG(toxic_addr); 1769ae115bc7Smrj segmap_start = ROUND_UP_LPAGE(toxic_addr + toxic_size); 1770ae115bc7Smrj #else /* __i386 */ 1771ae115bc7Smrj segmap_start = ROUND_UP_LPAGE(kernelbase); 1772ae115bc7Smrj #endif /* __i386 */ 1773ae115bc7Smrj PRM_DEBUG(segmap_start); 17747c478bd9Sstevel@tonic-gate 17757c478bd9Sstevel@tonic-gate /* 177652eef812SAmrita Sadhukhan * Users can change segmapsize through eeprom. If the variable 177752eef812SAmrita Sadhukhan * is tuned through eeprom, there is no upper bound on the 177852eef812SAmrita Sadhukhan * size of segmap. 17797c478bd9Sstevel@tonic-gate */ 17807c478bd9Sstevel@tonic-gate segmapsize = MAX(ROUND_UP_LPAGE(segmapsize), SEGMAPDEFAULT); 17817c478bd9Sstevel@tonic-gate 17827c478bd9Sstevel@tonic-gate #if defined(__i386) 17837c478bd9Sstevel@tonic-gate /* 17847c478bd9Sstevel@tonic-gate * 32-bit systems don't have segkpm or segkp, so segmap appears at 17857c478bd9Sstevel@tonic-gate * the bottom of the kernel's address range. Set aside space for a 1786ae115bc7Smrj * small red zone just below the start of segmap. 17877c478bd9Sstevel@tonic-gate */ 1788ae115bc7Smrj segmap_start += KERNEL_REDZONE_SIZE; 17897c478bd9Sstevel@tonic-gate segmapsize -= KERNEL_REDZONE_SIZE; 17907c478bd9Sstevel@tonic-gate #endif 17917c478bd9Sstevel@tonic-gate 1792ae115bc7Smrj PRM_DEBUG(segmap_start); 17937c478bd9Sstevel@tonic-gate PRM_DEBUG(segmapsize); 179435b1ab99Sjosephb kernelheap = (caddr_t)ROUND_UP_LPAGE(segmap_start + segmapsize); 179535b1ab99Sjosephb PRM_DEBUG(kernelheap); 179635b1ab99Sjosephb PRM_POINT("layout_kernel_va() done..."); 179735b1ab99Sjosephb } 179835b1ab99Sjosephb 179935b1ab99Sjosephb /* 180035b1ab99Sjosephb * Finish initializing the VM system, now that we are no longer 180135b1ab99Sjosephb * relying on the boot time memory allocators. 180235b1ab99Sjosephb */ 180335b1ab99Sjosephb static void 180435b1ab99Sjosephb startup_vm(void) 180535b1ab99Sjosephb { 180635b1ab99Sjosephb struct segmap_crargs a; 180735b1ab99Sjosephb 180835b1ab99Sjosephb extern int use_brk_lpg, use_stk_lpg; 180935b1ab99Sjosephb 181035b1ab99Sjosephb PRM_POINT("startup_vm() starting..."); 181135b1ab99Sjosephb 181235b1ab99Sjosephb /* 181335b1ab99Sjosephb * Initialize the hat layer. 181435b1ab99Sjosephb */ 181535b1ab99Sjosephb hat_init(); 18167c478bd9Sstevel@tonic-gate 18177c478bd9Sstevel@tonic-gate /* 1818ae115bc7Smrj * Do final allocations of HAT data structures that need to 1819ae115bc7Smrj * be allocated before quiescing the boot loader. 1820ae115bc7Smrj */ 1821ae115bc7Smrj PRM_POINT("Calling hat_kern_alloc()..."); 1822ae115bc7Smrj hat_kern_alloc((caddr_t)segmap_start, segmapsize, ekernelheap); 1823ae115bc7Smrj PRM_POINT("hat_kern_alloc() done"); 1824ae115bc7Smrj 1825843e1988Sjohnlev #ifndef __xpv 1826ae115bc7Smrj /* 18271d03c31eSjohnlev * Setup Page Attribute Table 1828ae115bc7Smrj */ 18291d03c31eSjohnlev pat_sync(); 1830843e1988Sjohnlev #endif 1831ae115bc7Smrj 1832ae115bc7Smrj /* 1833ae115bc7Smrj * The next two loops are done in distinct steps in order 1834ae115bc7Smrj * to be sure that any page that is doubly mapped (both above 1835ae115bc7Smrj * KERNEL_TEXT and below kernelbase) is dealt with correctly. 1836ae115bc7Smrj * Note this may never happen, but it might someday. 1837ae115bc7Smrj */ 1838ae115bc7Smrj bootpages = NULL; 1839ae115bc7Smrj PRM_POINT("Protecting boot pages"); 1840ae115bc7Smrj 1841ae115bc7Smrj /* 1842ae115bc7Smrj * Protect any pages mapped above KERNEL_TEXT that somehow have 1843ae115bc7Smrj * page_t's. This can only happen if something weird allocated 1844ae115bc7Smrj * in this range (like kadb/kmdb). 1845ae115bc7Smrj */ 1846ae115bc7Smrj protect_boot_range(KERNEL_TEXT, (uintptr_t)-1, 0); 1847ae115bc7Smrj 1848ae115bc7Smrj /* 1849ae115bc7Smrj * Before we can take over memory allocation/mapping from the boot 1850ae115bc7Smrj * loader we must remove from our free page lists any boot allocated 1851ae115bc7Smrj * pages that stay mapped until release_bootstrap(). 1852ae115bc7Smrj */ 1853ae115bc7Smrj protect_boot_range(0, kernelbase, 1); 1854ae115bc7Smrj 1855843e1988Sjohnlev 1856ae115bc7Smrj /* 1857ae115bc7Smrj * Switch to running on regular HAT (not boot_mmu) 1858ae115bc7Smrj */ 1859ae115bc7Smrj PRM_POINT("Calling hat_kern_setup()..."); 1860ae115bc7Smrj hat_kern_setup(); 1861ae115bc7Smrj 1862ae115bc7Smrj /* 1863ae115bc7Smrj * It is no longer safe to call BOP_ALLOC(), so make sure we don't. 1864ae115bc7Smrj */ 1865ae115bc7Smrj bop_no_more_mem(); 1866ae115bc7Smrj 1867ae115bc7Smrj PRM_POINT("hat_kern_setup() done"); 1868ae115bc7Smrj 1869ae115bc7Smrj hat_cpu_online(CPU); 1870ae115bc7Smrj 1871ae115bc7Smrj /* 18727c478bd9Sstevel@tonic-gate * Initialize VM system 18737c478bd9Sstevel@tonic-gate */ 18747c478bd9Sstevel@tonic-gate PRM_POINT("Calling kvm_init()..."); 18757c478bd9Sstevel@tonic-gate kvm_init(); 18767c478bd9Sstevel@tonic-gate PRM_POINT("kvm_init() done"); 18777c478bd9Sstevel@tonic-gate 18787c478bd9Sstevel@tonic-gate /* 18797c478bd9Sstevel@tonic-gate * Tell kmdb that the VM system is now working 18807c478bd9Sstevel@tonic-gate */ 18817c478bd9Sstevel@tonic-gate if (boothowto & RB_DEBUG) 18827c478bd9Sstevel@tonic-gate kdi_dvec_vmready(); 18837c478bd9Sstevel@tonic-gate 1884843e1988Sjohnlev #if defined(__xpv) 1885843e1988Sjohnlev /* 1886843e1988Sjohnlev * Populate the I/O pool on domain 0 1887843e1988Sjohnlev */ 1888843e1988Sjohnlev if (DOMAIN_IS_INITDOMAIN(xen_info)) { 1889843e1988Sjohnlev extern long populate_io_pool(void); 1890843e1988Sjohnlev long init_io_pool_cnt; 1891843e1988Sjohnlev 1892843e1988Sjohnlev PRM_POINT("Populating reserve I/O page pool"); 1893843e1988Sjohnlev init_io_pool_cnt = populate_io_pool(); 1894843e1988Sjohnlev PRM_DEBUG(init_io_pool_cnt); 1895843e1988Sjohnlev } 1896843e1988Sjohnlev #endif 18977c478bd9Sstevel@tonic-gate /* 18987c478bd9Sstevel@tonic-gate * Mangle the brand string etc. 18997c478bd9Sstevel@tonic-gate */ 19007c478bd9Sstevel@tonic-gate cpuid_pass3(CPU); 19017c478bd9Sstevel@tonic-gate 19027c478bd9Sstevel@tonic-gate #if defined(__amd64) 19037c478bd9Sstevel@tonic-gate 19047c478bd9Sstevel@tonic-gate /* 19057c478bd9Sstevel@tonic-gate * Create the device arena for toxic (to dtrace/kmdb) mappings. 19067c478bd9Sstevel@tonic-gate */ 19077c478bd9Sstevel@tonic-gate device_arena = vmem_create("device", (void *)toxic_addr, 19087c478bd9Sstevel@tonic-gate toxic_size, MMU_PAGESIZE, NULL, NULL, NULL, 0, VM_SLEEP); 19097c478bd9Sstevel@tonic-gate 19107c478bd9Sstevel@tonic-gate #else /* __i386 */ 19117c478bd9Sstevel@tonic-gate 19127c478bd9Sstevel@tonic-gate /* 19137c478bd9Sstevel@tonic-gate * allocate the bit map that tracks toxic pages 19147c478bd9Sstevel@tonic-gate */ 1915ae115bc7Smrj toxic_bit_map_len = btop((ulong_t)(valloc_base - kernelbase)); 19167c478bd9Sstevel@tonic-gate PRM_DEBUG(toxic_bit_map_len); 19177c478bd9Sstevel@tonic-gate toxic_bit_map = 19187c478bd9Sstevel@tonic-gate kmem_zalloc(BT_SIZEOFMAP(toxic_bit_map_len), KM_NOSLEEP); 19197c478bd9Sstevel@tonic-gate ASSERT(toxic_bit_map != NULL); 19207c478bd9Sstevel@tonic-gate PRM_DEBUG(toxic_bit_map); 19217c478bd9Sstevel@tonic-gate 19227c478bd9Sstevel@tonic-gate #endif /* __i386 */ 19237c478bd9Sstevel@tonic-gate 19247c478bd9Sstevel@tonic-gate 19257c478bd9Sstevel@tonic-gate /* 19267c478bd9Sstevel@tonic-gate * Now that we've got more VA, as well as the ability to allocate from 19277c478bd9Sstevel@tonic-gate * it, tell the debugger. 19287c478bd9Sstevel@tonic-gate */ 19297c478bd9Sstevel@tonic-gate if (boothowto & RB_DEBUG) 19307c478bd9Sstevel@tonic-gate kdi_dvec_memavail(); 19317c478bd9Sstevel@tonic-gate 19327c478bd9Sstevel@tonic-gate /* 19337c478bd9Sstevel@tonic-gate * The following code installs a special page fault handler (#pf) 19347c478bd9Sstevel@tonic-gate * to work around a pentium bug. 19357c478bd9Sstevel@tonic-gate */ 1936843e1988Sjohnlev #if !defined(__amd64) && !defined(__xpv) 19377c478bd9Sstevel@tonic-gate if (x86_type == X86_TYPE_P5) { 1938ae115bc7Smrj desctbr_t idtr; 19397c478bd9Sstevel@tonic-gate gate_desc_t *newidt; 19407c478bd9Sstevel@tonic-gate 19417c478bd9Sstevel@tonic-gate if ((newidt = kmem_zalloc(MMU_PAGESIZE, KM_NOSLEEP)) == NULL) 19427c478bd9Sstevel@tonic-gate panic("failed to install pentium_pftrap"); 19437c478bd9Sstevel@tonic-gate 19440cfdb603Sjosephb bcopy(idt0, newidt, NIDT * sizeof (*idt0)); 19457c478bd9Sstevel@tonic-gate set_gatesegd(&newidt[T_PGFLT], &pentium_pftrap, 19469844da31SSeth Goldberg KCS_SEL, SDT_SYSIGT, TRP_KPL, 0); 19477c478bd9Sstevel@tonic-gate 19487c478bd9Sstevel@tonic-gate (void) as_setprot(&kas, (caddr_t)newidt, MMU_PAGESIZE, 19497c478bd9Sstevel@tonic-gate PROT_READ | PROT_EXEC); 19507c478bd9Sstevel@tonic-gate 19510cfdb603Sjosephb CPU->cpu_idt = newidt; 19520cfdb603Sjosephb idtr.dtr_base = (uintptr_t)CPU->cpu_idt; 19530cfdb603Sjosephb idtr.dtr_limit = (NIDT * sizeof (*idt0)) - 1; 1954ae115bc7Smrj wr_idtr(&idtr); 19557c478bd9Sstevel@tonic-gate } 19567c478bd9Sstevel@tonic-gate #endif /* !__amd64 */ 19577c478bd9Sstevel@tonic-gate 1958843e1988Sjohnlev #if !defined(__xpv) 19597c478bd9Sstevel@tonic-gate /* 19607c478bd9Sstevel@tonic-gate * Map page pfn=0 for drivers, such as kd, that need to pick up 19617c478bd9Sstevel@tonic-gate * parameters left there by controllers/BIOS. 19627c478bd9Sstevel@tonic-gate */ 19637c478bd9Sstevel@tonic-gate PRM_POINT("setup up p0_va"); 19647c478bd9Sstevel@tonic-gate p0_va = i86devmap(0, 1, PROT_READ); 19657c478bd9Sstevel@tonic-gate PRM_DEBUG(p0_va); 1966843e1988Sjohnlev #endif 19677c478bd9Sstevel@tonic-gate 19687c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?mem = %luK (0x%lx)\n", 19697c478bd9Sstevel@tonic-gate physinstalled << (MMU_PAGESHIFT - 10), ptob(physinstalled)); 19707c478bd9Sstevel@tonic-gate 197183f9b804Skchow /* 197283f9b804Skchow * disable automatic large pages for small memory systems or 197383f9b804Skchow * when the disable flag is set. 197402bc52beSkchow * 197502bc52beSkchow * Do not yet consider page sizes larger than 2m/4m. 197683f9b804Skchow */ 1977ec25b48fSsusans if (!auto_lpg_disable && mmu.max_page_level > 0) { 1978ec25b48fSsusans max_uheap_lpsize = LEVEL_SIZE(1); 1979ec25b48fSsusans max_ustack_lpsize = LEVEL_SIZE(1); 1980ec25b48fSsusans max_privmap_lpsize = LEVEL_SIZE(1); 1981ec25b48fSsusans max_uidata_lpsize = LEVEL_SIZE(1); 1982ec25b48fSsusans max_utext_lpsize = LEVEL_SIZE(1); 1983ec25b48fSsusans max_shm_lpsize = LEVEL_SIZE(1); 1984ec25b48fSsusans } 1985ec25b48fSsusans if (physmem < privm_lpg_min_physmem || mmu.max_page_level == 0 || 1986ec25b48fSsusans auto_lpg_disable) { 1987beb1bda0Sdavemq use_brk_lpg = 0; 1988beb1bda0Sdavemq use_stk_lpg = 0; 1989ec25b48fSsusans } 199002bc52beSkchow mcntl0_lpsize = LEVEL_SIZE(mmu.umax_page_level); 1991beb1bda0Sdavemq 19927c478bd9Sstevel@tonic-gate PRM_POINT("Calling hat_init_finish()..."); 19937c478bd9Sstevel@tonic-gate hat_init_finish(); 19947c478bd9Sstevel@tonic-gate PRM_POINT("hat_init_finish() done"); 19957c478bd9Sstevel@tonic-gate 19967c478bd9Sstevel@tonic-gate /* 19977c478bd9Sstevel@tonic-gate * Initialize the segkp segment type. 19987c478bd9Sstevel@tonic-gate */ 19997c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER); 2000ae115bc7Smrj PRM_POINT("Attaching segkp"); 2001ae115bc7Smrj if (segkp_fromheap) { 2002ae115bc7Smrj segkp->s_as = &kas; 2003ae115bc7Smrj } else if (seg_attach(&kas, (caddr_t)segkp_base, mmu_ptob(segkpsize), 20047c478bd9Sstevel@tonic-gate segkp) < 0) { 20057c478bd9Sstevel@tonic-gate panic("startup: cannot attach segkp"); 20067c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 20077c478bd9Sstevel@tonic-gate } 2008ae115bc7Smrj PRM_POINT("Doing segkp_create()"); 20097c478bd9Sstevel@tonic-gate if (segkp_create(segkp) != 0) { 20107c478bd9Sstevel@tonic-gate panic("startup: segkp_create failed"); 20117c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 20127c478bd9Sstevel@tonic-gate } 20137c478bd9Sstevel@tonic-gate PRM_DEBUG(segkp); 20147c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock); 20157c478bd9Sstevel@tonic-gate 20167c478bd9Sstevel@tonic-gate /* 20177c478bd9Sstevel@tonic-gate * kpm segment 20187c478bd9Sstevel@tonic-gate */ 20197c478bd9Sstevel@tonic-gate segmap_kpm = 0; 20207c478bd9Sstevel@tonic-gate if (kpm_desired) { 20217c478bd9Sstevel@tonic-gate kpm_init(); 20227c478bd9Sstevel@tonic-gate kpm_enable = 1; 20237c478bd9Sstevel@tonic-gate } 20247c478bd9Sstevel@tonic-gate 20257c478bd9Sstevel@tonic-gate /* 20267c478bd9Sstevel@tonic-gate * Now create segmap segment. 20277c478bd9Sstevel@tonic-gate */ 20287c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER); 2029ae115bc7Smrj if (seg_attach(&kas, (caddr_t)segmap_start, segmapsize, segmap) < 0) { 2030ae115bc7Smrj panic("cannot attach segmap"); 20317c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 20327c478bd9Sstevel@tonic-gate } 2033ae115bc7Smrj PRM_DEBUG(segmap); 20347c478bd9Sstevel@tonic-gate 20357c478bd9Sstevel@tonic-gate a.prot = PROT_READ | PROT_WRITE; 20367c478bd9Sstevel@tonic-gate a.shmsize = 0; 20377c478bd9Sstevel@tonic-gate a.nfreelist = segmapfreelists; 20387c478bd9Sstevel@tonic-gate 2039ae115bc7Smrj if (segmap_create(segmap, (caddr_t)&a) != 0) 2040ae115bc7Smrj panic("segmap_create segmap"); 20417c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock); 20427c478bd9Sstevel@tonic-gate 20437c478bd9Sstevel@tonic-gate setup_vaddr_for_ppcopy(CPU); 20447c478bd9Sstevel@tonic-gate 20457c478bd9Sstevel@tonic-gate segdev_init(); 2046843e1988Sjohnlev #if defined(__xpv) 2047843e1988Sjohnlev if (DOMAIN_IS_INITDOMAIN(xen_info)) 2048843e1988Sjohnlev #endif 20497c478bd9Sstevel@tonic-gate pmem_init(); 2050ae115bc7Smrj 20517c478bd9Sstevel@tonic-gate PRM_POINT("startup_vm() done"); 20527c478bd9Sstevel@tonic-gate } 20537c478bd9Sstevel@tonic-gate 2054ae115bc7Smrj /* 2055ae115bc7Smrj * Load a tod module for the non-standard tod part found on this system. 2056ae115bc7Smrj */ 2057ae115bc7Smrj static void 2058ae115bc7Smrj load_tod_module(char *todmod) 2059ae115bc7Smrj { 2060ae115bc7Smrj if (modload("tod", todmod) == -1) 2061ae115bc7Smrj halt("Can't load TOD module"); 2062ae115bc7Smrj } 2063ae115bc7Smrj 20647c478bd9Sstevel@tonic-gate static void 20657c478bd9Sstevel@tonic-gate startup_end(void) 20667c478bd9Sstevel@tonic-gate { 2067dd4eeefdSeota int i; 20687c478bd9Sstevel@tonic-gate extern void setx86isalist(void); 2069fb2caebeSRandy Fishel extern void cpu_event_init(void); 20707c478bd9Sstevel@tonic-gate 20717c478bd9Sstevel@tonic-gate PRM_POINT("startup_end() starting..."); 20727c478bd9Sstevel@tonic-gate 20737c478bd9Sstevel@tonic-gate /* 20747c478bd9Sstevel@tonic-gate * Perform tasks that get done after most of the VM 20757c478bd9Sstevel@tonic-gate * initialization has been done but before the clock 20767c478bd9Sstevel@tonic-gate * and other devices get started. 20777c478bd9Sstevel@tonic-gate */ 20787c478bd9Sstevel@tonic-gate kern_setup1(); 20797c478bd9Sstevel@tonic-gate 20807c478bd9Sstevel@tonic-gate /* 20817c478bd9Sstevel@tonic-gate * Perform CPC initialization for this CPU. 20827c478bd9Sstevel@tonic-gate */ 20837c478bd9Sstevel@tonic-gate kcpc_hw_init(CPU); 20847c478bd9Sstevel@tonic-gate 2085fb2caebeSRandy Fishel /* 2086fb2caebeSRandy Fishel * Initialize cpu event framework. 2087fb2caebeSRandy Fishel */ 2088fb2caebeSRandy Fishel cpu_event_init(); 2089fb2caebeSRandy Fishel 2090ee88d2b9Skchow #if defined(OPTERON_WORKAROUND_6323525) 2091ee88d2b9Skchow if (opteron_workaround_6323525) 2092ee88d2b9Skchow patch_workaround_6323525(); 2093ee88d2b9Skchow #endif 20947c478bd9Sstevel@tonic-gate /* 2095ae115bc7Smrj * If needed, load TOD module now so that ddi_get_time(9F) etc. work 2096ae115bc7Smrj * (For now, "needed" is defined as set tod_module_name in /etc/system) 2097ae115bc7Smrj */ 2098ae115bc7Smrj if (tod_module_name != NULL) { 2099ae115bc7Smrj PRM_POINT("load_tod_module()"); 2100ae115bc7Smrj load_tod_module(tod_module_name); 2101ae115bc7Smrj } 2102ae115bc7Smrj 2103843e1988Sjohnlev #if defined(__xpv) 2104843e1988Sjohnlev /* 2105843e1988Sjohnlev * Forceload interposing TOD module for the hypervisor. 2106843e1988Sjohnlev */ 2107843e1988Sjohnlev PRM_POINT("load_tod_module()"); 2108843e1988Sjohnlev load_tod_module("xpvtod"); 2109843e1988Sjohnlev #endif 2110843e1988Sjohnlev 2111ae115bc7Smrj /* 21127c478bd9Sstevel@tonic-gate * Configure the system. 21137c478bd9Sstevel@tonic-gate */ 21147c478bd9Sstevel@tonic-gate PRM_POINT("Calling configure()..."); 21157c478bd9Sstevel@tonic-gate configure(); /* set up devices */ 21167c478bd9Sstevel@tonic-gate PRM_POINT("configure() done"); 21177c478bd9Sstevel@tonic-gate 21187c478bd9Sstevel@tonic-gate /* 21197c478bd9Sstevel@tonic-gate * Set the isa_list string to the defined instruction sets we 21207c478bd9Sstevel@tonic-gate * support. 21217c478bd9Sstevel@tonic-gate */ 21227c478bd9Sstevel@tonic-gate setx86isalist(); 2123100b72f4Sandrei cpu_intr_alloc(CPU, NINTR_THREADS); 21247c478bd9Sstevel@tonic-gate psm_install(); 21257c478bd9Sstevel@tonic-gate 21267c478bd9Sstevel@tonic-gate /* 21277c478bd9Sstevel@tonic-gate * We're done with bootops. We don't unmap the bootstrap yet because 21287c478bd9Sstevel@tonic-gate * we're still using bootsvcs. 21297c478bd9Sstevel@tonic-gate */ 2130ae115bc7Smrj PRM_POINT("NULLing out bootops"); 2131ae115bc7Smrj *bootopsp = (struct bootops *)NULL; 21327c478bd9Sstevel@tonic-gate bootops = (struct bootops *)NULL; 21337c478bd9Sstevel@tonic-gate 2134843e1988Sjohnlev #if defined(__xpv) 2135843e1988Sjohnlev ec_init_debug_irq(); 2136843e1988Sjohnlev xs_domu_init(); 2137843e1988Sjohnlev #endif 21381de082f7SVikram Hegde 21393a634bfcSVikram Hegde #if defined(__amd64) && !defined(__xpv) 21403a634bfcSVikram Hegde /* 21413a634bfcSVikram Hegde * Intel IOMMU has been setup/initialized in ddi_impl.c 21423a634bfcSVikram Hegde * Start it up now. 21433a634bfcSVikram Hegde */ 21443a634bfcSVikram Hegde immu_startup(); 21451de082f7SVikram Hegde #endif 21463a634bfcSVikram Hegde 21477c478bd9Sstevel@tonic-gate PRM_POINT("Enabling interrupts"); 21487c478bd9Sstevel@tonic-gate (*picinitf)(); 21497c478bd9Sstevel@tonic-gate sti(); 2150843e1988Sjohnlev #if defined(__xpv) 2151843e1988Sjohnlev ASSERT(CPU->cpu_m.mcpu_vcpu_info->evtchn_upcall_mask == 0); 2152843e1988Sjohnlev xen_late_startup(); 2153843e1988Sjohnlev #endif 21547c478bd9Sstevel@tonic-gate 21557c478bd9Sstevel@tonic-gate (void) add_avsoftintr((void *)&softlevel1_hdl, 1, softlevel1, 21567c478bd9Sstevel@tonic-gate "softlevel1", NULL, NULL); /* XXX to be moved later */ 21577c478bd9Sstevel@tonic-gate 2158dd4eeefdSeota /* 2159dd4eeefdSeota * Register these software interrupts for ddi timer. 2160dd4eeefdSeota * Software interrupts up to the level 10 are supported. 2161dd4eeefdSeota */ 2162dd4eeefdSeota for (i = DDI_IPL_1; i <= DDI_IPL_10; i++) { 2163dd4eeefdSeota char name[sizeof ("timer_softintr") + 2]; 2164dd4eeefdSeota (void) sprintf(name, "timer_softintr%02d", i); 2165dd4eeefdSeota (void) add_avsoftintr((void *)&softlevel_hdl[i-1], i, 2166dd4eeefdSeota (avfunc)timer_softintr, name, (caddr_t)(uintptr_t)i, NULL); 2167dd4eeefdSeota } 2168dd4eeefdSeota 21697125fcbdSVikram Hegde #if !defined(__xpv) 21707125fcbdSVikram Hegde if (modload("drv", "amd_iommu") < 0) { 21717125fcbdSVikram Hegde PRM_POINT("No AMD IOMMU present\n"); 217294f1124eSVikram Hegde } else if (ddi_hold_installed_driver(ddi_name_to_major( 217394f1124eSVikram Hegde "amd_iommu")) == NULL) { 21747125fcbdSVikram Hegde prom_printf("ERROR: failed to attach AMD IOMMU\n"); 21757125fcbdSVikram Hegde } 21767125fcbdSVikram Hegde #endif 2177e774b42bSBill Holler post_startup_cpu_fixups(); 21787125fcbdSVikram Hegde 21797c478bd9Sstevel@tonic-gate PRM_POINT("startup_end() done"); 21807c478bd9Sstevel@tonic-gate } 21817c478bd9Sstevel@tonic-gate 218296d008c2SKen Erickson /* 218396d008c2SKen Erickson * Don't remove the following 2 variables. They are necessary 218496d008c2SKen Erickson * for reading the hostid from the legacy file (/kernel/misc/sysinit). 218596d008c2SKen Erickson */ 21867c478bd9Sstevel@tonic-gate char *_hs1107 = hw_serial; 21877c478bd9Sstevel@tonic-gate ulong_t _bdhs34; 21887c478bd9Sstevel@tonic-gate 21897c478bd9Sstevel@tonic-gate void 21907c478bd9Sstevel@tonic-gate post_startup(void) 21917c478bd9Sstevel@tonic-gate { 21920e751525SEric Saxe extern void cpupm_init(cpu_t *); 2193fb2caebeSRandy Fishel extern void cpu_event_init_cpu(cpu_t *); 21940e751525SEric Saxe 21957c478bd9Sstevel@tonic-gate /* 21967c478bd9Sstevel@tonic-gate * Set the system wide, processor-specific flags to be passed 21977c478bd9Sstevel@tonic-gate * to userland via the aux vector for performance hints and 21987c478bd9Sstevel@tonic-gate * instruction set extensions. 21997c478bd9Sstevel@tonic-gate */ 22007c478bd9Sstevel@tonic-gate bind_hwcap(); 22017c478bd9Sstevel@tonic-gate 2202843e1988Sjohnlev #ifdef __xpv 2203843e1988Sjohnlev if (DOMAIN_IS_INITDOMAIN(xen_info)) 2204843e1988Sjohnlev #endif 2205843e1988Sjohnlev { 2206843e1988Sjohnlev #if defined(__xpv) 2207843e1988Sjohnlev xpv_panic_init(); 2208843e1988Sjohnlev #else 220984ab085aSmws /* 2210ae115bc7Smrj * Startup the memory scrubber. 2211843e1988Sjohnlev * XXPV This should be running somewhere .. 22127c478bd9Sstevel@tonic-gate */ 2213b9bfdccdSStuart Maybee if (get_hwenv() != HW_XEN_HVM) 221484ab085aSmws memscrub_init(); 2215843e1988Sjohnlev #endif 2216843e1988Sjohnlev } 22177c478bd9Sstevel@tonic-gate 22187c478bd9Sstevel@tonic-gate /* 22197aec1d6eScindi * Complete CPU module initialization 22207aec1d6eScindi */ 222120c794b3Sgavinm cmi_post_startup(); 22227aec1d6eScindi 22237aec1d6eScindi /* 22247c478bd9Sstevel@tonic-gate * Perform forceloading tasks for /etc/system. 22257c478bd9Sstevel@tonic-gate */ 22267c478bd9Sstevel@tonic-gate (void) mod_sysctl(SYS_FORCELOAD, NULL); 22277c478bd9Sstevel@tonic-gate 22287c478bd9Sstevel@tonic-gate /* 22297c478bd9Sstevel@tonic-gate * ON4.0: Force /proc module in until clock interrupt handle fixed 22307c478bd9Sstevel@tonic-gate * ON4.0: This must be fixed or restated in /etc/systems. 22317c478bd9Sstevel@tonic-gate */ 22327c478bd9Sstevel@tonic-gate (void) modload("fs", "procfs"); 22337c478bd9Sstevel@tonic-gate 2234c35aa225Smarx (void) i_ddi_attach_hw_nodes("pit_beep"); 2235c35aa225Smarx 22367c478bd9Sstevel@tonic-gate #if defined(__i386) 22377c478bd9Sstevel@tonic-gate /* 22387c478bd9Sstevel@tonic-gate * Check for required functional Floating Point hardware, 22397c478bd9Sstevel@tonic-gate * unless FP hardware explicitly disabled. 22407c478bd9Sstevel@tonic-gate */ 22417c478bd9Sstevel@tonic-gate if (fpu_exists && (fpu_pentium_fdivbug || fp_kind == FP_NO)) 22427c478bd9Sstevel@tonic-gate halt("No working FP hardware found"); 22437c478bd9Sstevel@tonic-gate #endif 22447c478bd9Sstevel@tonic-gate 22457c478bd9Sstevel@tonic-gate maxmem = freemem; 22467c478bd9Sstevel@tonic-gate 2247fb2caebeSRandy Fishel cpu_event_init_cpu(CPU); 22480e751525SEric Saxe cpupm_init(CPU); 2249fa96bd91SMichael Corcoran (void) mach_cpu_create_device_node(CPU, NULL); 22500e751525SEric Saxe 22510e751525SEric Saxe pg_init(); 22527c478bd9Sstevel@tonic-gate } 22537c478bd9Sstevel@tonic-gate 22547c478bd9Sstevel@tonic-gate static int 225519397407SSherry Moore pp_in_range(page_t *pp, uint64_t low_addr, uint64_t high_addr) 22567c478bd9Sstevel@tonic-gate { 225719397407SSherry Moore return ((pp->p_pagenum >= btop(low_addr)) && 225819397407SSherry Moore (pp->p_pagenum < btopr(high_addr))); 22597c478bd9Sstevel@tonic-gate } 22607c478bd9Sstevel@tonic-gate 22617c478bd9Sstevel@tonic-gate void 22627c478bd9Sstevel@tonic-gate release_bootstrap(void) 22637c478bd9Sstevel@tonic-gate { 22647c478bd9Sstevel@tonic-gate int root_is_ramdisk; 22657c478bd9Sstevel@tonic-gate page_t *pp; 22667c478bd9Sstevel@tonic-gate extern void kobj_boot_unmountroot(void); 22677c478bd9Sstevel@tonic-gate extern dev_t rootdev; 226855d507a9SSeth Goldberg #if !defined(__xpv) 226955d507a9SSeth Goldberg pfn_t pfn; 227055d507a9SSeth Goldberg #endif 22717c478bd9Sstevel@tonic-gate 22727c478bd9Sstevel@tonic-gate /* unmount boot ramdisk and release kmem usage */ 22737c478bd9Sstevel@tonic-gate kobj_boot_unmountroot(); 22747c478bd9Sstevel@tonic-gate 22757c478bd9Sstevel@tonic-gate /* 22767c478bd9Sstevel@tonic-gate * We're finished using the boot loader so free its pages. 22777c478bd9Sstevel@tonic-gate */ 22787c478bd9Sstevel@tonic-gate PRM_POINT("Unmapping lower boot pages"); 227919397407SSherry Moore 2280ae115bc7Smrj clear_boot_mappings(0, _userlimit); 228119397407SSherry Moore 2282ae115bc7Smrj postbootkernelbase = kernelbase; 22837c478bd9Sstevel@tonic-gate 22847c478bd9Sstevel@tonic-gate /* 22857c478bd9Sstevel@tonic-gate * If root isn't on ramdisk, destroy the hardcoded 22867c478bd9Sstevel@tonic-gate * ramdisk node now and release the memory. Else, 22877c478bd9Sstevel@tonic-gate * ramdisk memory is kept in rd_pages. 22887c478bd9Sstevel@tonic-gate */ 22897c478bd9Sstevel@tonic-gate root_is_ramdisk = (getmajor(rootdev) == ddi_name_to_major("ramdisk")); 22907c478bd9Sstevel@tonic-gate if (!root_is_ramdisk) { 22917c478bd9Sstevel@tonic-gate dev_info_t *dip = ddi_find_devinfo("ramdisk", -1, 0); 22927c478bd9Sstevel@tonic-gate ASSERT(dip && ddi_get_parent(dip) == ddi_root_node()); 22937c478bd9Sstevel@tonic-gate ndi_rele_devi(dip); /* held from ddi_find_devinfo */ 22947c478bd9Sstevel@tonic-gate (void) ddi_remove_child(dip, 0); 22957c478bd9Sstevel@tonic-gate } 22967c478bd9Sstevel@tonic-gate 22977c478bd9Sstevel@tonic-gate PRM_POINT("Releasing boot pages"); 22987c478bd9Sstevel@tonic-gate while (bootpages) { 229919397407SSherry Moore extern uint64_t ramdisk_start, ramdisk_end; 23007c478bd9Sstevel@tonic-gate pp = bootpages; 23017c478bd9Sstevel@tonic-gate bootpages = pp->p_next; 230219397407SSherry Moore 230319397407SSherry Moore 230419397407SSherry Moore /* Keep pages for the lower 64K */ 230519397407SSherry Moore if (pp_in_range(pp, 0, 0x40000)) { 230619397407SSherry Moore pp->p_next = lower_pages; 230719397407SSherry Moore lower_pages = pp; 230819397407SSherry Moore lower_pages_count++; 230919397407SSherry Moore continue; 231019397407SSherry Moore } 231119397407SSherry Moore 231219397407SSherry Moore 231319397407SSherry Moore if (root_is_ramdisk && pp_in_range(pp, ramdisk_start, 231419397407SSherry Moore ramdisk_end)) { 23157c478bd9Sstevel@tonic-gate pp->p_next = rd_pages; 23167c478bd9Sstevel@tonic-gate rd_pages = pp; 23177c478bd9Sstevel@tonic-gate continue; 23187c478bd9Sstevel@tonic-gate } 23197c478bd9Sstevel@tonic-gate pp->p_next = (struct page *)0; 2320ae115bc7Smrj pp->p_prev = (struct page *)0; 2321ae115bc7Smrj PP_CLRBOOTPAGES(pp); 23227c478bd9Sstevel@tonic-gate page_free(pp, 1); 23237c478bd9Sstevel@tonic-gate } 2324ae115bc7Smrj PRM_POINT("Boot pages released"); 23257c478bd9Sstevel@tonic-gate 2326843e1988Sjohnlev #if !defined(__xpv) 2327843e1988Sjohnlev /* XXPV -- note this following bunch of code needs to be revisited in Xen 3.0 */ 23287c478bd9Sstevel@tonic-gate /* 232955d507a9SSeth Goldberg * Find 1 page below 1 MB so that other processors can boot up or 233055d507a9SSeth Goldberg * so that any processor can resume. 23317c478bd9Sstevel@tonic-gate * Make sure it has a kernel VA as well as a 1:1 mapping. 23327c478bd9Sstevel@tonic-gate * We should have just free'd one up. 23337c478bd9Sstevel@tonic-gate */ 233419397407SSherry Moore 233519397407SSherry Moore /* 233619397407SSherry Moore * 0x10 pages is 64K. Leave the bottom 64K alone 233719397407SSherry Moore * for BIOS. 233819397407SSherry Moore */ 233919397407SSherry Moore for (pfn = 0x10; pfn < btop(1*1024*1024); pfn++) { 23407c478bd9Sstevel@tonic-gate if (page_numtopp_alloc(pfn) == NULL) 23417c478bd9Sstevel@tonic-gate continue; 23427c478bd9Sstevel@tonic-gate rm_platter_va = i86devmap(pfn, 1, 23437c478bd9Sstevel@tonic-gate PROT_READ | PROT_WRITE | PROT_EXEC); 23447c478bd9Sstevel@tonic-gate rm_platter_pa = ptob(pfn); 23457c478bd9Sstevel@tonic-gate hat_devload(kas.a_hat, 23467c478bd9Sstevel@tonic-gate (caddr_t)(uintptr_t)rm_platter_pa, MMU_PAGESIZE, 23477c478bd9Sstevel@tonic-gate pfn, PROT_READ | PROT_WRITE | PROT_EXEC, 23487c478bd9Sstevel@tonic-gate HAT_LOAD_NOCONSIST); 23497c478bd9Sstevel@tonic-gate break; 23507c478bd9Sstevel@tonic-gate } 235155d507a9SSeth Goldberg if (pfn == btop(1*1024*1024) && use_mp) 235255d507a9SSeth Goldberg panic("No page below 1M available for starting " 235355d507a9SSeth Goldberg "other processors or for resuming from system-suspend"); 2354843e1988Sjohnlev #endif /* !__xpv */ 23557c478bd9Sstevel@tonic-gate } 23567c478bd9Sstevel@tonic-gate 23577c478bd9Sstevel@tonic-gate /* 23587c478bd9Sstevel@tonic-gate * Initialize the platform-specific parts of a page_t. 23597c478bd9Sstevel@tonic-gate */ 23607c478bd9Sstevel@tonic-gate void 23617c478bd9Sstevel@tonic-gate add_physmem_cb(page_t *pp, pfn_t pnum) 23627c478bd9Sstevel@tonic-gate { 23637c478bd9Sstevel@tonic-gate pp->p_pagenum = pnum; 23647c478bd9Sstevel@tonic-gate pp->p_mapping = NULL; 23657c478bd9Sstevel@tonic-gate pp->p_embed = 0; 23667c478bd9Sstevel@tonic-gate pp->p_share = 0; 23677c478bd9Sstevel@tonic-gate pp->p_mlentry = 0; 23687c478bd9Sstevel@tonic-gate } 23697c478bd9Sstevel@tonic-gate 23707c478bd9Sstevel@tonic-gate /* 23717c478bd9Sstevel@tonic-gate * kphysm_init() initializes physical memory. 23727c478bd9Sstevel@tonic-gate */ 23737c478bd9Sstevel@tonic-gate static pgcnt_t 23747c478bd9Sstevel@tonic-gate kphysm_init( 2375ae115bc7Smrj page_t *pp, 23767c478bd9Sstevel@tonic-gate pgcnt_t npages) 23777c478bd9Sstevel@tonic-gate { 23787c478bd9Sstevel@tonic-gate struct memlist *pmem; 23797c478bd9Sstevel@tonic-gate struct memseg *cur_memseg; 23807c478bd9Sstevel@tonic-gate pfn_t base_pfn; 238118968004SKit Chow pfn_t end_pfn; 23827c478bd9Sstevel@tonic-gate pgcnt_t num; 23837c478bd9Sstevel@tonic-gate pgcnt_t pages_done = 0; 23847c478bd9Sstevel@tonic-gate uint64_t addr; 23857c478bd9Sstevel@tonic-gate uint64_t size; 23867c478bd9Sstevel@tonic-gate extern pfn_t ddiphysmin; 238718968004SKit Chow extern int mnode_xwa; 238818968004SKit Chow int ms = 0, me = 0; 23897c478bd9Sstevel@tonic-gate 23907c478bd9Sstevel@tonic-gate ASSERT(page_hash != NULL && page_hashsz != 0); 23917c478bd9Sstevel@tonic-gate 2392ae115bc7Smrj cur_memseg = memseg_base; 239356f33205SJonathan Adams for (pmem = phys_avail; pmem && npages; pmem = pmem->ml_next) { 23947c478bd9Sstevel@tonic-gate /* 23957c478bd9Sstevel@tonic-gate * In a 32 bit kernel can't use higher memory if we're 23967c478bd9Sstevel@tonic-gate * not booting in PAE mode. This check takes care of that. 23977c478bd9Sstevel@tonic-gate */ 239856f33205SJonathan Adams addr = pmem->ml_address; 239956f33205SJonathan Adams size = pmem->ml_size; 24007c478bd9Sstevel@tonic-gate if (btop(addr) > physmax) 24017c478bd9Sstevel@tonic-gate continue; 24027c478bd9Sstevel@tonic-gate 24037c478bd9Sstevel@tonic-gate /* 24047c478bd9Sstevel@tonic-gate * align addr and size - they may not be at page boundaries 24057c478bd9Sstevel@tonic-gate */ 24067c478bd9Sstevel@tonic-gate if ((addr & MMU_PAGEOFFSET) != 0) { 24077c478bd9Sstevel@tonic-gate addr += MMU_PAGEOFFSET; 24087c478bd9Sstevel@tonic-gate addr &= ~(uint64_t)MMU_PAGEOFFSET; 240956f33205SJonathan Adams size -= addr - pmem->ml_address; 24107c478bd9Sstevel@tonic-gate } 24117c478bd9Sstevel@tonic-gate 24126bb54764Skchow /* only process pages below or equal to physmax */ 24136bb54764Skchow if ((btop(addr + size) - 1) > physmax) 24146bb54764Skchow size = ptob(physmax - btop(addr) + 1); 24157c478bd9Sstevel@tonic-gate 24167c478bd9Sstevel@tonic-gate num = btop(size); 24177c478bd9Sstevel@tonic-gate if (num == 0) 24187c478bd9Sstevel@tonic-gate continue; 24197c478bd9Sstevel@tonic-gate 24207c478bd9Sstevel@tonic-gate if (num > npages) 24217c478bd9Sstevel@tonic-gate num = npages; 24227c478bd9Sstevel@tonic-gate 24237c478bd9Sstevel@tonic-gate npages -= num; 24247c478bd9Sstevel@tonic-gate pages_done += num; 24257c478bd9Sstevel@tonic-gate base_pfn = btop(addr); 24267c478bd9Sstevel@tonic-gate 24277c478bd9Sstevel@tonic-gate if (prom_debug) 24287c478bd9Sstevel@tonic-gate prom_printf("MEMSEG addr=0x%" PRIx64 24297c478bd9Sstevel@tonic-gate " pgs=0x%lx pfn 0x%lx-0x%lx\n", 24307c478bd9Sstevel@tonic-gate addr, num, base_pfn, base_pfn + num); 24317c478bd9Sstevel@tonic-gate 24327c478bd9Sstevel@tonic-gate /* 2433ae115bc7Smrj * Ignore pages below ddiphysmin to simplify ddi memory 24347c478bd9Sstevel@tonic-gate * allocation with non-zero addr_lo requests. 24357c478bd9Sstevel@tonic-gate */ 24367c478bd9Sstevel@tonic-gate if (base_pfn < ddiphysmin) { 2437ae115bc7Smrj if (base_pfn + num <= ddiphysmin) 24387c478bd9Sstevel@tonic-gate continue; 24397c478bd9Sstevel@tonic-gate pp += (ddiphysmin - base_pfn); 24407c478bd9Sstevel@tonic-gate num -= (ddiphysmin - base_pfn); 24417c478bd9Sstevel@tonic-gate base_pfn = ddiphysmin; 24427c478bd9Sstevel@tonic-gate } 2443ae115bc7Smrj 24447c478bd9Sstevel@tonic-gate /* 244518968004SKit Chow * mnode_xwa is greater than 1 when large pages regions can 244618968004SKit Chow * cross memory node boundaries. To prevent the formation 244718968004SKit Chow * of these large pages, configure the memsegs based on the 244818968004SKit Chow * memory node ranges which had been made non-contiguous. 244918968004SKit Chow */ 245018968004SKit Chow if (mnode_xwa > 1) { 245118968004SKit Chow 245218968004SKit Chow end_pfn = base_pfn + num - 1; 245318968004SKit Chow ms = PFN_2_MEM_NODE(base_pfn); 245418968004SKit Chow me = PFN_2_MEM_NODE(end_pfn); 245518968004SKit Chow 245618968004SKit Chow if (ms != me) { 245718968004SKit Chow /* 245818968004SKit Chow * current range spans more than 1 memory node. 245918968004SKit Chow * Set num to only the pfn range in the start 246018968004SKit Chow * memory node. 246118968004SKit Chow */ 246218968004SKit Chow num = mem_node_config[ms].physmax - base_pfn 246318968004SKit Chow + 1; 246418968004SKit Chow ASSERT(end_pfn > mem_node_config[ms].physmax); 246518968004SKit Chow } 246618968004SKit Chow } 246718968004SKit Chow 246818968004SKit Chow for (;;) { 246918968004SKit Chow /* 24707c478bd9Sstevel@tonic-gate * Build the memsegs entry 24717c478bd9Sstevel@tonic-gate */ 24727c478bd9Sstevel@tonic-gate cur_memseg->pages = pp; 24737c478bd9Sstevel@tonic-gate cur_memseg->epages = pp + num; 24747c478bd9Sstevel@tonic-gate cur_memseg->pages_base = base_pfn; 24757c478bd9Sstevel@tonic-gate cur_memseg->pages_end = base_pfn + num; 24767c478bd9Sstevel@tonic-gate 24777c478bd9Sstevel@tonic-gate /* 247818968004SKit Chow * Insert into memseg list in decreasing pfn range 247918968004SKit Chow * order. Low memory is typically more fragmented such 248018968004SKit Chow * that this ordering keeps the larger ranges at the 248118968004SKit Chow * front of the list for code that searches memseg. 248218968004SKit Chow * This ASSERTS that the memsegs coming in from boot 248318968004SKit Chow * are in increasing physical address order and not 248418968004SKit Chow * contiguous. 24857c478bd9Sstevel@tonic-gate */ 2486ae115bc7Smrj if (memsegs != NULL) { 248718968004SKit Chow ASSERT(cur_memseg->pages_base >= 248818968004SKit Chow memsegs->pages_end); 2489ae115bc7Smrj cur_memseg->next = memsegs; 2490ae115bc7Smrj } 24917c478bd9Sstevel@tonic-gate memsegs = cur_memseg; 24927c478bd9Sstevel@tonic-gate 24937c478bd9Sstevel@tonic-gate /* 24947c478bd9Sstevel@tonic-gate * add_physmem() initializes the PSM part of the page 24957c478bd9Sstevel@tonic-gate * struct by calling the PSM back with add_physmem_cb(). 24967c478bd9Sstevel@tonic-gate * In addition it coalesces pages into larger pages as 24977c478bd9Sstevel@tonic-gate * it initializes them. 24987c478bd9Sstevel@tonic-gate */ 24997c478bd9Sstevel@tonic-gate add_physmem(pp, num, base_pfn); 25007c478bd9Sstevel@tonic-gate cur_memseg++; 25017c478bd9Sstevel@tonic-gate availrmem_initial += num; 25027c478bd9Sstevel@tonic-gate availrmem += num; 25037c478bd9Sstevel@tonic-gate 2504ae115bc7Smrj pp += num; 250518968004SKit Chow if (ms >= me) 250618968004SKit Chow break; 250718968004SKit Chow 250818968004SKit Chow /* process next memory node range */ 250918968004SKit Chow ms++; 251018968004SKit Chow base_pfn = mem_node_config[ms].physbase; 251118968004SKit Chow num = MIN(mem_node_config[ms].physmax, 251218968004SKit Chow end_pfn) - base_pfn + 1; 251318968004SKit Chow } 25147c478bd9Sstevel@tonic-gate } 25157c478bd9Sstevel@tonic-gate 25167c478bd9Sstevel@tonic-gate PRM_DEBUG(availrmem_initial); 25177c478bd9Sstevel@tonic-gate PRM_DEBUG(availrmem); 25187c478bd9Sstevel@tonic-gate PRM_DEBUG(freemem); 25197c478bd9Sstevel@tonic-gate build_pfn_hash(); 25207c478bd9Sstevel@tonic-gate return (pages_done); 25217c478bd9Sstevel@tonic-gate } 25227c478bd9Sstevel@tonic-gate 25237c478bd9Sstevel@tonic-gate /* 25247c478bd9Sstevel@tonic-gate * Kernel VM initialization. 25257c478bd9Sstevel@tonic-gate */ 25267c478bd9Sstevel@tonic-gate static void 25277c478bd9Sstevel@tonic-gate kvm_init(void) 25287c478bd9Sstevel@tonic-gate { 25297c478bd9Sstevel@tonic-gate ASSERT((((uintptr_t)s_text) & MMU_PAGEOFFSET) == 0); 25307c478bd9Sstevel@tonic-gate 25317c478bd9Sstevel@tonic-gate /* 25327c478bd9Sstevel@tonic-gate * Put the kernel segments in kernel address space. 25337c478bd9Sstevel@tonic-gate */ 25347c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER); 25357c478bd9Sstevel@tonic-gate as_avlinit(&kas); 25367c478bd9Sstevel@tonic-gate 25377c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, s_text, e_moddata - s_text, &ktextseg); 25387c478bd9Sstevel@tonic-gate (void) segkmem_create(&ktextseg); 25397c478bd9Sstevel@tonic-gate 25407c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, (caddr_t)valloc_base, valloc_sz, &kvalloc); 25417c478bd9Sstevel@tonic-gate (void) segkmem_create(&kvalloc); 25427c478bd9Sstevel@tonic-gate 254335b1ab99Sjosephb (void) seg_attach(&kas, kernelheap, 254435b1ab99Sjosephb ekernelheap - kernelheap, &kvseg); 25457c478bd9Sstevel@tonic-gate (void) segkmem_create(&kvseg); 25467c478bd9Sstevel@tonic-gate 2547ae115bc7Smrj if (core_size > 0) { 2548ae115bc7Smrj PRM_POINT("attaching kvseg_core"); 2549ae115bc7Smrj (void) seg_attach(&kas, (caddr_t)core_base, core_size, 2550ae115bc7Smrj &kvseg_core); 25517c478bd9Sstevel@tonic-gate (void) segkmem_create(&kvseg_core); 2552ae115bc7Smrj } 2553ad23a2dbSjohansen 2554ae115bc7Smrj if (segziosize > 0) { 2555ae115bc7Smrj PRM_POINT("attaching segzio"); 2556ad23a2dbSjohansen (void) seg_attach(&kas, segzio_base, mmu_ptob(segziosize), 2557ad23a2dbSjohansen &kzioseg); 2558ad23a2dbSjohansen (void) segkmem_zio_create(&kzioseg); 2559ad23a2dbSjohansen 2560ad23a2dbSjohansen /* create zio area covering new segment */ 2561ad23a2dbSjohansen segkmem_zio_init(segzio_base, mmu_ptob(segziosize)); 2562ad23a2dbSjohansen } 25637c478bd9Sstevel@tonic-gate 2564ae115bc7Smrj (void) seg_attach(&kas, kdi_segdebugbase, kdi_segdebugsize, &kdebugseg); 25657c478bd9Sstevel@tonic-gate (void) segkmem_create(&kdebugseg); 25667c478bd9Sstevel@tonic-gate 25677c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock); 25687c478bd9Sstevel@tonic-gate 25697c478bd9Sstevel@tonic-gate /* 25707c478bd9Sstevel@tonic-gate * Ensure that the red zone at kernelbase is never accessible. 25717c478bd9Sstevel@tonic-gate */ 2572ae115bc7Smrj PRM_POINT("protecting redzone"); 25737c478bd9Sstevel@tonic-gate (void) as_setprot(&kas, (caddr_t)kernelbase, KERNEL_REDZONE_SIZE, 0); 25747c478bd9Sstevel@tonic-gate 25757c478bd9Sstevel@tonic-gate /* 25767c478bd9Sstevel@tonic-gate * Make the text writable so that it can be hot patched by DTrace. 25777c478bd9Sstevel@tonic-gate */ 25787c478bd9Sstevel@tonic-gate (void) as_setprot(&kas, s_text, e_modtext - s_text, 25797c478bd9Sstevel@tonic-gate PROT_READ | PROT_WRITE | PROT_EXEC); 25807c478bd9Sstevel@tonic-gate 25817c478bd9Sstevel@tonic-gate /* 25827c478bd9Sstevel@tonic-gate * Make data writable until end. 25837c478bd9Sstevel@tonic-gate */ 25847c478bd9Sstevel@tonic-gate (void) as_setprot(&kas, s_data, e_moddata - s_data, 25857c478bd9Sstevel@tonic-gate PROT_READ | PROT_WRITE | PROT_EXEC); 25867c478bd9Sstevel@tonic-gate } 25877c478bd9Sstevel@tonic-gate 2588843e1988Sjohnlev #ifndef __xpv 25897c478bd9Sstevel@tonic-gate /* 25901d03c31eSjohnlev * Solaris adds an entry for Write Combining caching to the PAT 25917c478bd9Sstevel@tonic-gate */ 25921d03c31eSjohnlev static uint64_t pat_attr_reg = PAT_DEFAULT_ATTRIBUTE; 25937c478bd9Sstevel@tonic-gate 25947c478bd9Sstevel@tonic-gate void 25951d03c31eSjohnlev pat_sync(void) 25967c478bd9Sstevel@tonic-gate { 25971d03c31eSjohnlev ulong_t cr0, cr0_orig, cr4; 25987c478bd9Sstevel@tonic-gate 25991d03c31eSjohnlev if (!(x86_feature & X86_PAT)) 26007c478bd9Sstevel@tonic-gate return; 26011d03c31eSjohnlev cr0_orig = cr0 = getcr0(); 26021d03c31eSjohnlev cr4 = getcr4(); 26037c478bd9Sstevel@tonic-gate 26041d03c31eSjohnlev /* disable caching and flush all caches and TLBs */ 26051d03c31eSjohnlev cr0 |= CR0_CD; 26061d03c31eSjohnlev cr0 &= ~CR0_NW; 26071d03c31eSjohnlev setcr0(cr0); 26087c478bd9Sstevel@tonic-gate invalidate_cache(); 26091d03c31eSjohnlev if (cr4 & CR4_PGE) { 26101d03c31eSjohnlev setcr4(cr4 & ~(ulong_t)CR4_PGE); 26111d03c31eSjohnlev setcr4(cr4); 26121d03c31eSjohnlev } else { 2613ae115bc7Smrj reload_cr3(); 26147c478bd9Sstevel@tonic-gate } 2615ae115bc7Smrj 26161d03c31eSjohnlev /* add our entry to the PAT */ 26171d03c31eSjohnlev wrmsr(REG_PAT, pat_attr_reg); 26181d03c31eSjohnlev 26191d03c31eSjohnlev /* flush TLBs and cache again, then reenable cr0 caching */ 26201d03c31eSjohnlev if (cr4 & CR4_PGE) { 26211d03c31eSjohnlev setcr4(cr4 & ~(ulong_t)CR4_PGE); 26221d03c31eSjohnlev setcr4(cr4); 26231d03c31eSjohnlev } else { 2624ae115bc7Smrj reload_cr3(); 26251d03c31eSjohnlev } 26267c478bd9Sstevel@tonic-gate invalidate_cache(); 26277c478bd9Sstevel@tonic-gate setcr0(cr0_orig); 26287c478bd9Sstevel@tonic-gate } 26297c478bd9Sstevel@tonic-gate 26301d03c31eSjohnlev #endif /* !__xpv */ 26317c478bd9Sstevel@tonic-gate 2632ed5289f9SKen Erickson #if defined(_SOFT_HOSTID) 2633ed5289f9SKen Erickson /* 2634ed5289f9SKen Erickson * On platforms that do not have a hardware serial number, attempt 2635ed5289f9SKen Erickson * to set one based on the contents of /etc/hostid. If this file does 2636ed5289f9SKen Erickson * not exist, assume that we are to generate a new hostid and set 2637ed5289f9SKen Erickson * it in the kernel, for subsequent saving by a userland process 2638ed5289f9SKen Erickson * once the system is up and the root filesystem is mounted r/w. 2639ed5289f9SKen Erickson * 264096d008c2SKen Erickson * In order to gracefully support upgrade on OpenSolaris, if 264196d008c2SKen Erickson * /etc/hostid does not exist, we will attempt to get a serial number 264296d008c2SKen Erickson * using the legacy method (/kernel/misc/sysinit). 264396d008c2SKen Erickson * 2644ed5289f9SKen Erickson * In an attempt to make the hostid less prone to abuse 2645ed5289f9SKen Erickson * (for license circumvention, etc), we store it in /etc/hostid 2646ed5289f9SKen Erickson * in rot47 format. 2647ed5289f9SKen Erickson */ 2648ed5289f9SKen Erickson extern volatile unsigned long tenmicrodata; 264996d008c2SKen Erickson static int atoi(char *); 2650ed5289f9SKen Erickson 2651ed5289f9SKen Erickson static int32_t 2652ed5289f9SKen Erickson set_soft_hostid(void) 2653ed5289f9SKen Erickson { 2654ed5289f9SKen Erickson struct _buf *file; 2655ed5289f9SKen Erickson char tokbuf[MAXNAMELEN]; 2656ed5289f9SKen Erickson token_t token; 2657ed5289f9SKen Erickson int done = 0; 2658ed5289f9SKen Erickson u_longlong_t tmp; 265996d008c2SKen Erickson int i; 26605679c89fSjv227347 int32_t hostid = (int32_t)HW_INVALID_HOSTID; 2661ed5289f9SKen Erickson unsigned char *c; 2662ed5289f9SKen Erickson hrtime_t tsc; 2663ed5289f9SKen Erickson 2664ed5289f9SKen Erickson /* 2665ed5289f9SKen Erickson * If /etc/hostid file not found, we'd like to get a pseudo 2666ed5289f9SKen Erickson * random number to use at the hostid. A nice way to do this 2667ed5289f9SKen Erickson * is to read the real time clock. To remain xen-compatible, 2668ed5289f9SKen Erickson * we can't poke the real hardware, so we use tsc_read() to 2669ed5289f9SKen Erickson * read the real time clock. However, there is an ominous 2670ed5289f9SKen Erickson * warning in tsc_read that says it can return zero, so we 2671ed5289f9SKen Erickson * deal with that possibility by falling back to using the 2672ed5289f9SKen Erickson * (hopefully random enough) value in tenmicrodata. 2673ed5289f9SKen Erickson */ 2674ed5289f9SKen Erickson 2675ed5289f9SKen Erickson if ((file = kobj_open_file(hostid_file)) == (struct _buf *)-1) { 267696d008c2SKen Erickson /* 267796d008c2SKen Erickson * hostid file not found - try to load sysinit module 267896d008c2SKen Erickson * and see if it has a nonzero hostid value...use that 267996d008c2SKen Erickson * instead of generating a new hostid here if so. 268096d008c2SKen Erickson */ 268196d008c2SKen Erickson if ((i = modload("misc", "sysinit")) != -1) { 268296d008c2SKen Erickson if (strlen(hw_serial) > 0) 268396d008c2SKen Erickson hostid = (int32_t)atoi(hw_serial); 268496d008c2SKen Erickson (void) modunload(i); 268596d008c2SKen Erickson } 26865679c89fSjv227347 if (hostid == HW_INVALID_HOSTID) { 2687ed5289f9SKen Erickson tsc = tsc_read(); 2688ed5289f9SKen Erickson if (tsc == 0) /* tsc_read can return zero sometimes */ 2689ed5289f9SKen Erickson hostid = (int32_t)tenmicrodata & 0x0CFFFFF; 2690ed5289f9SKen Erickson else 2691ed5289f9SKen Erickson hostid = (int32_t)tsc & 0x0CFFFFF; 269296d008c2SKen Erickson } 2693ed5289f9SKen Erickson } else { 2694ed5289f9SKen Erickson /* hostid file found */ 2695ed5289f9SKen Erickson while (!done) { 2696ed5289f9SKen Erickson token = kobj_lex(file, tokbuf, sizeof (tokbuf)); 2697ed5289f9SKen Erickson 2698ed5289f9SKen Erickson switch (token) { 2699ed5289f9SKen Erickson case POUND: 2700ed5289f9SKen Erickson /* 2701ed5289f9SKen Erickson * skip comments 2702ed5289f9SKen Erickson */ 2703ed5289f9SKen Erickson kobj_find_eol(file); 2704ed5289f9SKen Erickson break; 2705ed5289f9SKen Erickson case STRING: 2706ed5289f9SKen Erickson /* 2707ed5289f9SKen Erickson * un-rot47 - obviously this 2708ed5289f9SKen Erickson * nonsense is ascii-specific 2709ed5289f9SKen Erickson */ 2710ed5289f9SKen Erickson for (c = (unsigned char *)tokbuf; 2711ed5289f9SKen Erickson *c != '\0'; c++) { 2712ed5289f9SKen Erickson *c += 47; 2713ed5289f9SKen Erickson if (*c > '~') 2714ed5289f9SKen Erickson *c -= 94; 2715ed5289f9SKen Erickson else if (*c < '!') 2716ed5289f9SKen Erickson *c += 94; 2717ed5289f9SKen Erickson } 2718ed5289f9SKen Erickson /* 2719ed5289f9SKen Erickson * now we should have a real number 2720ed5289f9SKen Erickson */ 2721ed5289f9SKen Erickson 2722ed5289f9SKen Erickson if (kobj_getvalue(tokbuf, &tmp) != 0) 2723ed5289f9SKen Erickson kobj_file_err(CE_WARN, file, 2724ed5289f9SKen Erickson "Bad value %s for hostid", 2725ed5289f9SKen Erickson tokbuf); 2726ed5289f9SKen Erickson else 2727ed5289f9SKen Erickson hostid = (int32_t)tmp; 2728ed5289f9SKen Erickson 2729ed5289f9SKen Erickson break; 2730ed5289f9SKen Erickson case EOF: 2731ed5289f9SKen Erickson done = 1; 2732ed5289f9SKen Erickson /* FALLTHROUGH */ 2733ed5289f9SKen Erickson case NEWLINE: 2734ed5289f9SKen Erickson kobj_newline(file); 2735ed5289f9SKen Erickson break; 2736ed5289f9SKen Erickson default: 2737ed5289f9SKen Erickson break; 2738ed5289f9SKen Erickson 2739ed5289f9SKen Erickson } 2740ed5289f9SKen Erickson } 27415679c89fSjv227347 if (hostid == HW_INVALID_HOSTID) /* didn't find a hostid */ 2742ed5289f9SKen Erickson kobj_file_err(CE_WARN, file, 2743ed5289f9SKen Erickson "hostid missing or corrupt"); 2744ed5289f9SKen Erickson 2745ed5289f9SKen Erickson kobj_close_file(file); 2746ed5289f9SKen Erickson } 2747ed5289f9SKen Erickson /* 2748ed5289f9SKen Erickson * hostid is now the value read from /etc/hostid, or the 27495679c89fSjv227347 * new hostid we generated in this routine or HW_INVALID_HOSTID if not 27505679c89fSjv227347 * set. 2751ed5289f9SKen Erickson */ 2752ed5289f9SKen Erickson return (hostid); 2753ed5289f9SKen Erickson } 275496d008c2SKen Erickson 275596d008c2SKen Erickson static int 275696d008c2SKen Erickson atoi(char *p) 275796d008c2SKen Erickson { 275896d008c2SKen Erickson int i = 0; 275996d008c2SKen Erickson 276096d008c2SKen Erickson while (*p != '\0') 276196d008c2SKen Erickson i = 10 * i + (*p++ - '0'); 276296d008c2SKen Erickson 276396d008c2SKen Erickson return (i); 276496d008c2SKen Erickson } 276596d008c2SKen Erickson 2766ed5289f9SKen Erickson #endif /* _SOFT_HOSTID */ 2767ed5289f9SKen Erickson 27687c478bd9Sstevel@tonic-gate void 276945916cd2Sjpk get_system_configuration(void) 27707c478bd9Sstevel@tonic-gate { 27717c478bd9Sstevel@tonic-gate char prop[32]; 27727c478bd9Sstevel@tonic-gate u_longlong_t nodes_ll, cpus_pernode_ll, lvalue; 27737c478bd9Sstevel@tonic-gate 277435b1ab99Sjosephb if (BOP_GETPROPLEN(bootops, "nodes") > sizeof (prop) || 277535b1ab99Sjosephb BOP_GETPROP(bootops, "nodes", prop) < 0 || 277635b1ab99Sjosephb kobj_getvalue(prop, &nodes_ll) == -1 || 277735b1ab99Sjosephb nodes_ll > MAXNODES || 277835b1ab99Sjosephb BOP_GETPROPLEN(bootops, "cpus_pernode") > sizeof (prop) || 277935b1ab99Sjosephb BOP_GETPROP(bootops, "cpus_pernode", prop) < 0 || 278035b1ab99Sjosephb kobj_getvalue(prop, &cpus_pernode_ll) == -1) { 27817c478bd9Sstevel@tonic-gate system_hardware.hd_nodes = 1; 27827c478bd9Sstevel@tonic-gate system_hardware.hd_cpus_per_node = 0; 27837c478bd9Sstevel@tonic-gate } else { 27847c478bd9Sstevel@tonic-gate system_hardware.hd_nodes = (int)nodes_ll; 27857c478bd9Sstevel@tonic-gate system_hardware.hd_cpus_per_node = (int)cpus_pernode_ll; 27867c478bd9Sstevel@tonic-gate } 278735b1ab99Sjosephb 278835b1ab99Sjosephb if (BOP_GETPROPLEN(bootops, "kernelbase") > sizeof (prop) || 278935b1ab99Sjosephb BOP_GETPROP(bootops, "kernelbase", prop) < 0 || 279035b1ab99Sjosephb kobj_getvalue(prop, &lvalue) == -1) 27917c478bd9Sstevel@tonic-gate eprom_kernelbase = NULL; 27927c478bd9Sstevel@tonic-gate else 27937c478bd9Sstevel@tonic-gate eprom_kernelbase = (uintptr_t)lvalue; 27947c478bd9Sstevel@tonic-gate 279535b1ab99Sjosephb if (BOP_GETPROPLEN(bootops, "segmapsize") > sizeof (prop) || 279635b1ab99Sjosephb BOP_GETPROP(bootops, "segmapsize", prop) < 0 || 279735b1ab99Sjosephb kobj_getvalue(prop, &lvalue) == -1) 27987c478bd9Sstevel@tonic-gate segmapsize = SEGMAPDEFAULT; 279935b1ab99Sjosephb else 28007c478bd9Sstevel@tonic-gate segmapsize = (uintptr_t)lvalue; 28017c478bd9Sstevel@tonic-gate 280235b1ab99Sjosephb if (BOP_GETPROPLEN(bootops, "segmapfreelists") > sizeof (prop) || 280335b1ab99Sjosephb BOP_GETPROP(bootops, "segmapfreelists", prop) < 0 || 280435b1ab99Sjosephb kobj_getvalue(prop, &lvalue) == -1) 28057c478bd9Sstevel@tonic-gate segmapfreelists = 0; /* use segmap driver default */ 280635b1ab99Sjosephb else 28077c478bd9Sstevel@tonic-gate segmapfreelists = (int)lvalue; 28084944b02eSkchow 2809aac11643Sjosephb /* physmem used to be here, but moved much earlier to fakebop.c */ 28107c478bd9Sstevel@tonic-gate } 28117c478bd9Sstevel@tonic-gate 28127c478bd9Sstevel@tonic-gate /* 28137c478bd9Sstevel@tonic-gate * Add to a memory list. 28147c478bd9Sstevel@tonic-gate * start = start of new memory segment 28157c478bd9Sstevel@tonic-gate * len = length of new memory segment in bytes 28167c478bd9Sstevel@tonic-gate * new = pointer to a new struct memlist 28177c478bd9Sstevel@tonic-gate * memlistp = memory list to which to add segment. 28187c478bd9Sstevel@tonic-gate */ 2819ae115bc7Smrj void 28207c478bd9Sstevel@tonic-gate memlist_add( 28217c478bd9Sstevel@tonic-gate uint64_t start, 28227c478bd9Sstevel@tonic-gate uint64_t len, 28237c478bd9Sstevel@tonic-gate struct memlist *new, 28247c478bd9Sstevel@tonic-gate struct memlist **memlistp) 28257c478bd9Sstevel@tonic-gate { 28267c478bd9Sstevel@tonic-gate struct memlist *cur; 28277c478bd9Sstevel@tonic-gate uint64_t end = start + len; 28287c478bd9Sstevel@tonic-gate 282956f33205SJonathan Adams new->ml_address = start; 283056f33205SJonathan Adams new->ml_size = len; 28317c478bd9Sstevel@tonic-gate 28327c478bd9Sstevel@tonic-gate cur = *memlistp; 28337c478bd9Sstevel@tonic-gate 28347c478bd9Sstevel@tonic-gate while (cur) { 283556f33205SJonathan Adams if (cur->ml_address >= end) { 283656f33205SJonathan Adams new->ml_next = cur; 28377c478bd9Sstevel@tonic-gate *memlistp = new; 283856f33205SJonathan Adams new->ml_prev = cur->ml_prev; 283956f33205SJonathan Adams cur->ml_prev = new; 28407c478bd9Sstevel@tonic-gate return; 28417c478bd9Sstevel@tonic-gate } 284256f33205SJonathan Adams ASSERT(cur->ml_address + cur->ml_size <= start); 284356f33205SJonathan Adams if (cur->ml_next == NULL) { 284456f33205SJonathan Adams cur->ml_next = new; 284556f33205SJonathan Adams new->ml_prev = cur; 284656f33205SJonathan Adams new->ml_next = NULL; 28477c478bd9Sstevel@tonic-gate return; 28487c478bd9Sstevel@tonic-gate } 284956f33205SJonathan Adams memlistp = &cur->ml_next; 285056f33205SJonathan Adams cur = cur->ml_next; 28517c478bd9Sstevel@tonic-gate } 28527c478bd9Sstevel@tonic-gate } 28537c478bd9Sstevel@tonic-gate 28547c478bd9Sstevel@tonic-gate void 28557c478bd9Sstevel@tonic-gate kobj_vmem_init(vmem_t **text_arena, vmem_t **data_arena) 28567c478bd9Sstevel@tonic-gate { 28577c478bd9Sstevel@tonic-gate size_t tsize = e_modtext - modtext; 28587c478bd9Sstevel@tonic-gate size_t dsize = e_moddata - moddata; 28597c478bd9Sstevel@tonic-gate 28607c478bd9Sstevel@tonic-gate *text_arena = vmem_create("module_text", tsize ? modtext : NULL, tsize, 28617c478bd9Sstevel@tonic-gate 1, segkmem_alloc, segkmem_free, heaptext_arena, 0, VM_SLEEP); 28627c478bd9Sstevel@tonic-gate *data_arena = vmem_create("module_data", dsize ? moddata : NULL, dsize, 28637c478bd9Sstevel@tonic-gate 1, segkmem_alloc, segkmem_free, heap32_arena, 0, VM_SLEEP); 28647c478bd9Sstevel@tonic-gate } 28657c478bd9Sstevel@tonic-gate 28667c478bd9Sstevel@tonic-gate caddr_t 28677c478bd9Sstevel@tonic-gate kobj_text_alloc(vmem_t *arena, size_t size) 28687c478bd9Sstevel@tonic-gate { 28697c478bd9Sstevel@tonic-gate return (vmem_alloc(arena, size, VM_SLEEP | VM_BESTFIT)); 28707c478bd9Sstevel@tonic-gate } 28717c478bd9Sstevel@tonic-gate 28727c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 28737c478bd9Sstevel@tonic-gate caddr_t 28747c478bd9Sstevel@tonic-gate kobj_texthole_alloc(caddr_t addr, size_t size) 28757c478bd9Sstevel@tonic-gate { 28767c478bd9Sstevel@tonic-gate panic("unexpected call to kobj_texthole_alloc()"); 28777c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 28787c478bd9Sstevel@tonic-gate return (0); 28797c478bd9Sstevel@tonic-gate } 28807c478bd9Sstevel@tonic-gate 28817c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 28827c478bd9Sstevel@tonic-gate void 28837c478bd9Sstevel@tonic-gate kobj_texthole_free(caddr_t addr, size_t size) 28847c478bd9Sstevel@tonic-gate { 28857c478bd9Sstevel@tonic-gate panic("unexpected call to kobj_texthole_free()"); 28867c478bd9Sstevel@tonic-gate } 28877c478bd9Sstevel@tonic-gate 28887c478bd9Sstevel@tonic-gate /* 28897c478bd9Sstevel@tonic-gate * This is called just after configure() in startup(). 28907c478bd9Sstevel@tonic-gate * 28917c478bd9Sstevel@tonic-gate * The ISALIST concept is a bit hopeless on Intel, because 28927c478bd9Sstevel@tonic-gate * there's no guarantee of an ever-more-capable processor 28937c478bd9Sstevel@tonic-gate * given that various parts of the instruction set may appear 28947c478bd9Sstevel@tonic-gate * and disappear between different implementations. 28957c478bd9Sstevel@tonic-gate * 28967c478bd9Sstevel@tonic-gate * While it would be possible to correct it and even enhance 28977c478bd9Sstevel@tonic-gate * it somewhat, the explicit hardware capability bitmask allows 28987c478bd9Sstevel@tonic-gate * more flexibility. 28997c478bd9Sstevel@tonic-gate * 29007c478bd9Sstevel@tonic-gate * So, we just leave this alone. 29017c478bd9Sstevel@tonic-gate */ 29027c478bd9Sstevel@tonic-gate void 29037c478bd9Sstevel@tonic-gate setx86isalist(void) 29047c478bd9Sstevel@tonic-gate { 29057c478bd9Sstevel@tonic-gate char *tp; 29067c478bd9Sstevel@tonic-gate size_t len; 29077c478bd9Sstevel@tonic-gate extern char *isa_list; 29087c478bd9Sstevel@tonic-gate 29097c478bd9Sstevel@tonic-gate #define TBUFSIZE 1024 29107c478bd9Sstevel@tonic-gate 29117c478bd9Sstevel@tonic-gate tp = kmem_alloc(TBUFSIZE, KM_SLEEP); 29127c478bd9Sstevel@tonic-gate *tp = '\0'; 29137c478bd9Sstevel@tonic-gate 29147c478bd9Sstevel@tonic-gate #if defined(__amd64) 29157c478bd9Sstevel@tonic-gate (void) strcpy(tp, "amd64 "); 29167c478bd9Sstevel@tonic-gate #endif 29177c478bd9Sstevel@tonic-gate 29187c478bd9Sstevel@tonic-gate switch (x86_vendor) { 29197c478bd9Sstevel@tonic-gate case X86_VENDOR_Intel: 29207c478bd9Sstevel@tonic-gate case X86_VENDOR_AMD: 29217c478bd9Sstevel@tonic-gate case X86_VENDOR_TM: 29227c478bd9Sstevel@tonic-gate if (x86_feature & X86_CMOV) { 29237c478bd9Sstevel@tonic-gate /* 29247c478bd9Sstevel@tonic-gate * Pentium Pro or later 29257c478bd9Sstevel@tonic-gate */ 29267c478bd9Sstevel@tonic-gate (void) strcat(tp, "pentium_pro"); 29277c478bd9Sstevel@tonic-gate (void) strcat(tp, x86_feature & X86_MMX ? 29287c478bd9Sstevel@tonic-gate "+mmx pentium_pro " : " "); 29297c478bd9Sstevel@tonic-gate } 29307c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 29317c478bd9Sstevel@tonic-gate case X86_VENDOR_Cyrix: 29327c478bd9Sstevel@tonic-gate /* 29337c478bd9Sstevel@tonic-gate * The Cyrix 6x86 does not have any Pentium features 29347c478bd9Sstevel@tonic-gate * accessible while not at privilege level 0. 29357c478bd9Sstevel@tonic-gate */ 29367c478bd9Sstevel@tonic-gate if (x86_feature & X86_CPUID) { 29377c478bd9Sstevel@tonic-gate (void) strcat(tp, "pentium"); 29387c478bd9Sstevel@tonic-gate (void) strcat(tp, x86_feature & X86_MMX ? 29397c478bd9Sstevel@tonic-gate "+mmx pentium " : " "); 29407c478bd9Sstevel@tonic-gate } 29417c478bd9Sstevel@tonic-gate break; 29427c478bd9Sstevel@tonic-gate default: 29437c478bd9Sstevel@tonic-gate break; 29447c478bd9Sstevel@tonic-gate } 29457c478bd9Sstevel@tonic-gate (void) strcat(tp, "i486 i386 i86"); 29467c478bd9Sstevel@tonic-gate len = strlen(tp) + 1; /* account for NULL at end of string */ 29477c478bd9Sstevel@tonic-gate isa_list = strcpy(kmem_alloc(len, KM_SLEEP), tp); 29487c478bd9Sstevel@tonic-gate kmem_free(tp, TBUFSIZE); 29497c478bd9Sstevel@tonic-gate 29507c478bd9Sstevel@tonic-gate #undef TBUFSIZE 29517c478bd9Sstevel@tonic-gate } 29527c478bd9Sstevel@tonic-gate 29537c478bd9Sstevel@tonic-gate 29547c478bd9Sstevel@tonic-gate #ifdef __amd64 29557c478bd9Sstevel@tonic-gate 29567c478bd9Sstevel@tonic-gate void * 29577c478bd9Sstevel@tonic-gate device_arena_alloc(size_t size, int vm_flag) 29587c478bd9Sstevel@tonic-gate { 29597c478bd9Sstevel@tonic-gate return (vmem_alloc(device_arena, size, vm_flag)); 29607c478bd9Sstevel@tonic-gate } 29617c478bd9Sstevel@tonic-gate 29627c478bd9Sstevel@tonic-gate void 29637c478bd9Sstevel@tonic-gate device_arena_free(void *vaddr, size_t size) 29647c478bd9Sstevel@tonic-gate { 29657c478bd9Sstevel@tonic-gate vmem_free(device_arena, vaddr, size); 29667c478bd9Sstevel@tonic-gate } 29677c478bd9Sstevel@tonic-gate 2968ae115bc7Smrj #else /* __i386 */ 29697c478bd9Sstevel@tonic-gate 29707c478bd9Sstevel@tonic-gate void * 29717c478bd9Sstevel@tonic-gate device_arena_alloc(size_t size, int vm_flag) 29727c478bd9Sstevel@tonic-gate { 29737c478bd9Sstevel@tonic-gate caddr_t vaddr; 29747c478bd9Sstevel@tonic-gate uintptr_t v; 29757c478bd9Sstevel@tonic-gate size_t start; 29767c478bd9Sstevel@tonic-gate size_t end; 29777c478bd9Sstevel@tonic-gate 29787c478bd9Sstevel@tonic-gate vaddr = vmem_alloc(heap_arena, size, vm_flag); 29797c478bd9Sstevel@tonic-gate if (vaddr == NULL) 29807c478bd9Sstevel@tonic-gate return (NULL); 29817c478bd9Sstevel@tonic-gate 29827c478bd9Sstevel@tonic-gate v = (uintptr_t)vaddr; 29837c478bd9Sstevel@tonic-gate ASSERT(v >= kernelbase); 2984ae115bc7Smrj ASSERT(v + size <= valloc_base); 29857c478bd9Sstevel@tonic-gate 29867c478bd9Sstevel@tonic-gate start = btop(v - kernelbase); 29877c478bd9Sstevel@tonic-gate end = btop(v + size - 1 - kernelbase); 29887c478bd9Sstevel@tonic-gate ASSERT(start < toxic_bit_map_len); 29897c478bd9Sstevel@tonic-gate ASSERT(end < toxic_bit_map_len); 29907c478bd9Sstevel@tonic-gate 29917c478bd9Sstevel@tonic-gate while (start <= end) { 29927c478bd9Sstevel@tonic-gate BT_ATOMIC_SET(toxic_bit_map, start); 29937c478bd9Sstevel@tonic-gate ++start; 29947c478bd9Sstevel@tonic-gate } 29957c478bd9Sstevel@tonic-gate return (vaddr); 29967c478bd9Sstevel@tonic-gate } 29977c478bd9Sstevel@tonic-gate 29987c478bd9Sstevel@tonic-gate void 29997c478bd9Sstevel@tonic-gate device_arena_free(void *vaddr, size_t size) 30007c478bd9Sstevel@tonic-gate { 30017c478bd9Sstevel@tonic-gate uintptr_t v = (uintptr_t)vaddr; 30027c478bd9Sstevel@tonic-gate size_t start; 30037c478bd9Sstevel@tonic-gate size_t end; 30047c478bd9Sstevel@tonic-gate 30057c478bd9Sstevel@tonic-gate ASSERT(v >= kernelbase); 3006ae115bc7Smrj ASSERT(v + size <= valloc_base); 30077c478bd9Sstevel@tonic-gate 30087c478bd9Sstevel@tonic-gate start = btop(v - kernelbase); 30097c478bd9Sstevel@tonic-gate end = btop(v + size - 1 - kernelbase); 30107c478bd9Sstevel@tonic-gate ASSERT(start < toxic_bit_map_len); 30117c478bd9Sstevel@tonic-gate ASSERT(end < toxic_bit_map_len); 30127c478bd9Sstevel@tonic-gate 30137c478bd9Sstevel@tonic-gate while (start <= end) { 30147c478bd9Sstevel@tonic-gate ASSERT(BT_TEST(toxic_bit_map, start) != 0); 30157c478bd9Sstevel@tonic-gate BT_ATOMIC_CLEAR(toxic_bit_map, start); 30167c478bd9Sstevel@tonic-gate ++start; 30177c478bd9Sstevel@tonic-gate } 30187c478bd9Sstevel@tonic-gate vmem_free(heap_arena, vaddr, size); 30197c478bd9Sstevel@tonic-gate } 30207c478bd9Sstevel@tonic-gate 30217c478bd9Sstevel@tonic-gate /* 30227c478bd9Sstevel@tonic-gate * returns 1st address in range that is in device arena, or NULL 30237c478bd9Sstevel@tonic-gate * if len is not NULL it returns the length of the toxic range 30247c478bd9Sstevel@tonic-gate */ 30257c478bd9Sstevel@tonic-gate void * 30267c478bd9Sstevel@tonic-gate device_arena_contains(void *vaddr, size_t size, size_t *len) 30277c478bd9Sstevel@tonic-gate { 30287c478bd9Sstevel@tonic-gate uintptr_t v = (uintptr_t)vaddr; 30297c478bd9Sstevel@tonic-gate uintptr_t eaddr = v + size; 30307c478bd9Sstevel@tonic-gate size_t start; 30317c478bd9Sstevel@tonic-gate size_t end; 30327c478bd9Sstevel@tonic-gate 30337c478bd9Sstevel@tonic-gate /* 30347c478bd9Sstevel@tonic-gate * if called very early by kmdb, just return NULL 30357c478bd9Sstevel@tonic-gate */ 30367c478bd9Sstevel@tonic-gate if (toxic_bit_map == NULL) 30377c478bd9Sstevel@tonic-gate return (NULL); 30387c478bd9Sstevel@tonic-gate 30397c478bd9Sstevel@tonic-gate /* 30407c478bd9Sstevel@tonic-gate * First check if we're completely outside the bitmap range. 30417c478bd9Sstevel@tonic-gate */ 3042ae115bc7Smrj if (v >= valloc_base || eaddr < kernelbase) 30437c478bd9Sstevel@tonic-gate return (NULL); 30447c478bd9Sstevel@tonic-gate 30457c478bd9Sstevel@tonic-gate /* 30467c478bd9Sstevel@tonic-gate * Trim ends of search to look at only what the bitmap covers. 30477c478bd9Sstevel@tonic-gate */ 30487c478bd9Sstevel@tonic-gate if (v < kernelbase) 30497c478bd9Sstevel@tonic-gate v = kernelbase; 30507c478bd9Sstevel@tonic-gate start = btop(v - kernelbase); 30517c478bd9Sstevel@tonic-gate end = btop(eaddr - kernelbase); 30527c478bd9Sstevel@tonic-gate if (end >= toxic_bit_map_len) 30537c478bd9Sstevel@tonic-gate end = toxic_bit_map_len; 30547c478bd9Sstevel@tonic-gate 30557c478bd9Sstevel@tonic-gate if (bt_range(toxic_bit_map, &start, &end, end) == 0) 30567c478bd9Sstevel@tonic-gate return (NULL); 30577c478bd9Sstevel@tonic-gate 30587c478bd9Sstevel@tonic-gate v = kernelbase + ptob(start); 30597c478bd9Sstevel@tonic-gate if (len != NULL) 30607c478bd9Sstevel@tonic-gate *len = ptob(end - start); 30617c478bd9Sstevel@tonic-gate return ((void *)v); 30627c478bd9Sstevel@tonic-gate } 30637c478bd9Sstevel@tonic-gate 3064ae115bc7Smrj #endif /* __i386 */ 3065