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 5fea9cb91Slq150181 * 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 */ 21fea9cb91Slq150181 227c478bd9Sstevel@tonic-gate /* 23cb15d5d9SPeter Rival * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 277c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 287c478bd9Sstevel@tonic-gate #include <sys/vm.h> 297c478bd9Sstevel@tonic-gate #include <sys/cpu.h> 307c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 317c478bd9Sstevel@tonic-gate #include <sys/reboot.h> 327c478bd9Sstevel@tonic-gate #include <sys/kdi.h> 337c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 347c478bd9Sstevel@tonic-gate #include <sys/memlist_plat.h> 357c478bd9Sstevel@tonic-gate #include <sys/memlist_impl.h> 367c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h> 377c478bd9Sstevel@tonic-gate #include <sys/prom_isa.h> 387c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 397c478bd9Sstevel@tonic-gate #include <sys/ivintr.h> 407c478bd9Sstevel@tonic-gate #include <sys/fpu/fpusystm.h> 417c478bd9Sstevel@tonic-gate #include <sys/iommutsb.h> 427c478bd9Sstevel@tonic-gate #include <vm/vm_dep.h> 437c478bd9Sstevel@tonic-gate #include <vm/seg_dev.h> 447c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h> 457c478bd9Sstevel@tonic-gate #include <vm/seg_kpm.h> 467c478bd9Sstevel@tonic-gate #include <vm/seg_map.h> 477c478bd9Sstevel@tonic-gate #include <vm/seg_kp.h> 487c478bd9Sstevel@tonic-gate #include <sys/sysconf.h> 497c478bd9Sstevel@tonic-gate #include <vm/hat_sfmmu.h> 507c478bd9Sstevel@tonic-gate #include <sys/kobj.h> 517c478bd9Sstevel@tonic-gate #include <sys/sun4asi.h> 527c478bd9Sstevel@tonic-gate #include <sys/clconf.h> 537c478bd9Sstevel@tonic-gate #include <sys/platform_module.h> 547c478bd9Sstevel@tonic-gate #include <sys/panic.h> 557c478bd9Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h> 567c478bd9Sstevel@tonic-gate #include <sys/clock.h> 577c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 58*9c84d1a2SDave Plauger #include <sys/dumphdr.h> 597c478bd9Sstevel@tonic-gate #include <sys/promif.h> 607c478bd9Sstevel@tonic-gate #include <sys/prom_debug.h> 617c478bd9Sstevel@tonic-gate #include <sys/traptrace.h> 627c478bd9Sstevel@tonic-gate #include <sys/memnode.h> 637c478bd9Sstevel@tonic-gate #include <sys/mem_cage.h> 641e2e7a75Shuah #include <sys/mmu.h> 65cb15d5d9SPeter Rival #include <sys/swap.h> 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate extern void setup_trap_table(void); 68982b9107Sjb145095 extern int cpu_intrq_setup(struct cpu *); 697c478bd9Sstevel@tonic-gate extern void cpu_intrq_register(struct cpu *); 707c478bd9Sstevel@tonic-gate extern void contig_mem_init(void); 71aaa10e67Sha137994 extern caddr_t contig_mem_prealloc(caddr_t, pgcnt_t); 727c478bd9Sstevel@tonic-gate extern void mach_dump_buffer_init(void); 737c478bd9Sstevel@tonic-gate extern void mach_descrip_init(void); 741ae08745Sheppo extern void mach_descrip_startup_fini(void); 757c478bd9Sstevel@tonic-gate extern void mach_memscrub(void); 767c478bd9Sstevel@tonic-gate extern void mach_fpras(void); 777c478bd9Sstevel@tonic-gate extern void mach_cpu_halt_idle(void); 787c478bd9Sstevel@tonic-gate extern void mach_hw_copy_limit(void); 791ae08745Sheppo extern void load_mach_drivers(void); 807c478bd9Sstevel@tonic-gate extern void load_tod_module(void); 817c478bd9Sstevel@tonic-gate #pragma weak load_tod_module 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate extern int ndata_alloc_mmfsa(struct memlist *ndata); 847c478bd9Sstevel@tonic-gate #pragma weak ndata_alloc_mmfsa 857c478bd9Sstevel@tonic-gate 861ae08745Sheppo extern void cif_init(void); 871ae08745Sheppo #pragma weak cif_init 881ae08745Sheppo 897c478bd9Sstevel@tonic-gate extern void parse_idprom(void); 907c478bd9Sstevel@tonic-gate extern void add_vx_handler(char *, int, void (*)(cell_t *)); 917c478bd9Sstevel@tonic-gate extern void mem_config_init(void); 927c478bd9Sstevel@tonic-gate extern void memseg_remap_init(void); 937c478bd9Sstevel@tonic-gate 94fedab560Sae112802 extern void mach_kpm_init(void); 9506fb6a36Sdv142724 extern void pcf_init(); 96d7d93655Sblakej extern int size_pse_array(pgcnt_t, int); 970e751525SEric Saxe extern void pg_init(); 98fedab560Sae112802 997c478bd9Sstevel@tonic-gate /* 1007c478bd9Sstevel@tonic-gate * External Data: 1017c478bd9Sstevel@tonic-gate */ 1027c478bd9Sstevel@tonic-gate extern int vac_size; /* cache size in bytes */ 1037c478bd9Sstevel@tonic-gate extern uint_t vac_mask; /* VAC alignment consistency mask */ 1047c478bd9Sstevel@tonic-gate extern uint_t vac_colors; 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate /* 1077c478bd9Sstevel@tonic-gate * Global Data Definitions: 1087c478bd9Sstevel@tonic-gate */ 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate /* 1117c478bd9Sstevel@tonic-gate * XXX - Don't port this to new architectures 1127c478bd9Sstevel@tonic-gate * A 3rd party volume manager driver (vxdm) depends on the symbol romp. 1137c478bd9Sstevel@tonic-gate * 'romp' has no use with a prom with an IEEE 1275 client interface. 1147c478bd9Sstevel@tonic-gate * The driver doesn't use the value, but it depends on the symbol. 1157c478bd9Sstevel@tonic-gate */ 1167c478bd9Sstevel@tonic-gate void *romp; /* veritas driver won't load without romp 4154976 */ 1177c478bd9Sstevel@tonic-gate /* 1187c478bd9Sstevel@tonic-gate * Declare these as initialized data so we can patch them. 1197c478bd9Sstevel@tonic-gate */ 1207c478bd9Sstevel@tonic-gate pgcnt_t physmem = 0; /* memory size in pages, patch if you want less */ 1217c478bd9Sstevel@tonic-gate pgcnt_t segkpsize = 1227c478bd9Sstevel@tonic-gate btop(SEGKPDEFSIZE); /* size of segkp segment in pages */ 123183971baSPrakash Sangappa uint_t segmap_percent = 6; /* Size of segmap segment */ 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate int use_cache = 1; /* cache not reliable (605 bugs) with MP */ 1267c478bd9Sstevel@tonic-gate int vac_copyback = 1; 1277c478bd9Sstevel@tonic-gate char *cache_mode = NULL; 1287c478bd9Sstevel@tonic-gate int use_mix = 1; 1297c478bd9Sstevel@tonic-gate int prom_debug = 0; 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate caddr_t boot_tba; /* %tba at boot - used by kmdb */ 1327c478bd9Sstevel@tonic-gate uint_t tba_taken_over = 0; 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate caddr_t s_text; /* start of kernel text segment */ 1357c478bd9Sstevel@tonic-gate caddr_t e_text; /* end of kernel text segment */ 1367c478bd9Sstevel@tonic-gate caddr_t s_data; /* start of kernel data segment */ 1377c478bd9Sstevel@tonic-gate caddr_t e_data; /* end of kernel data segment */ 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate caddr_t modtext; /* beginning of module text */ 1407c478bd9Sstevel@tonic-gate size_t modtext_sz; /* size of module text */ 1417c478bd9Sstevel@tonic-gate caddr_t moddata; /* beginning of module data reserve */ 1427c478bd9Sstevel@tonic-gate caddr_t e_moddata; /* end of module data reserve */ 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate /* 1457c478bd9Sstevel@tonic-gate * End of first block of contiguous kernel in 32-bit virtual address space 1467c478bd9Sstevel@tonic-gate */ 1477c478bd9Sstevel@tonic-gate caddr_t econtig32; /* end of first blk of contiguous kernel */ 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate caddr_t ncbase; /* beginning of non-cached segment */ 1507c478bd9Sstevel@tonic-gate caddr_t ncend; /* end of non-cached segment */ 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate size_t ndata_remain_sz; /* bytes from end of data to 4MB boundary */ 1537c478bd9Sstevel@tonic-gate caddr_t nalloc_base; /* beginning of nucleus allocation */ 1547c478bd9Sstevel@tonic-gate caddr_t nalloc_end; /* end of nucleus allocatable memory */ 1557c478bd9Sstevel@tonic-gate caddr_t valloc_base; /* beginning of kvalloc segment */ 1567c478bd9Sstevel@tonic-gate 1577c478bd9Sstevel@tonic-gate caddr_t kmem64_base; /* base of kernel mem segment in 64-bit space */ 1587c478bd9Sstevel@tonic-gate caddr_t kmem64_end; /* end of kernel mem segment in 64-bit space */ 159986fd29aSsetje size_t kmem64_sz; /* bytes in kernel mem segment, 64-bit space */ 160bb121940Sdp78419 caddr_t kmem64_aligned_end; /* end of large page, overmaps 64-bit space */ 161bb121940Sdp78419 int kmem64_szc; /* page size code */ 162bb121940Sdp78419 uint64_t kmem64_pabase = (uint64_t)-1; /* physical address of kmem64_base */ 1637c478bd9Sstevel@tonic-gate 164fedab560Sae112802 uintptr_t shm_alignment; /* VAC address consistency modulus */ 1657c478bd9Sstevel@tonic-gate struct memlist *phys_install; /* Total installed physical memory */ 1667c478bd9Sstevel@tonic-gate struct memlist *phys_avail; /* Available (unreserved) physical memory */ 1677c478bd9Sstevel@tonic-gate struct memlist *virt_avail; /* Available (unmapped?) virtual memory */ 168986fd29aSsetje struct memlist *nopp_list; /* pages with no backing page structs */ 1697c478bd9Sstevel@tonic-gate struct memlist ndata; /* memlist of nucleus allocatable memory */ 1707c478bd9Sstevel@tonic-gate int memexp_flag; /* memory expansion card flag */ 1717c478bd9Sstevel@tonic-gate uint64_t ecache_flushaddr; /* physical address used for flushing E$ */ 1727c478bd9Sstevel@tonic-gate pgcnt_t obp_pages; /* Physical pages used by OBP */ 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate /* 1757c478bd9Sstevel@tonic-gate * VM data structures 1767c478bd9Sstevel@tonic-gate */ 1777c478bd9Sstevel@tonic-gate long page_hashsz; /* Size of page hash table (power of two) */ 178cb15d5d9SPeter Rival unsigned int page_hashsz_shift; /* log2(page_hashsz) */ 1797c478bd9Sstevel@tonic-gate struct page *pp_base; /* Base of system page struct array */ 1807c478bd9Sstevel@tonic-gate size_t pp_sz; /* Size in bytes of page struct array */ 1817c478bd9Sstevel@tonic-gate struct page **page_hash; /* Page hash table */ 182d7d93655Sblakej pad_mutex_t *pse_mutex; /* Locks protecting pp->p_selock */ 183d7d93655Sblakej size_t pse_table_size; /* Number of mutexes in pse_mutex[] */ 184d7d93655Sblakej int pse_shift; /* log2(pse_table_size) */ 1857c478bd9Sstevel@tonic-gate struct seg ktextseg; /* Segment used for kernel executable image */ 1867c478bd9Sstevel@tonic-gate struct seg kvalloc; /* Segment used for "valloc" mapping */ 1877c478bd9Sstevel@tonic-gate struct seg kpseg; /* Segment used for pageable kernel virt mem */ 1887c478bd9Sstevel@tonic-gate struct seg ktexthole; /* Segment used for nucleus text hole */ 1897c478bd9Sstevel@tonic-gate struct seg kmapseg; /* Segment used for generic kernel mappings */ 1907c478bd9Sstevel@tonic-gate struct seg kpmseg; /* Segment used for physical mapping */ 1917c478bd9Sstevel@tonic-gate struct seg kdebugseg; /* Segment used for the kernel debugger */ 1927c478bd9Sstevel@tonic-gate 193986fd29aSsetje void *kpm_pp_base; /* Base of system kpm_page array */ 1947c478bd9Sstevel@tonic-gate size_t kpm_pp_sz; /* Size of system kpm_page array */ 1957c478bd9Sstevel@tonic-gate pgcnt_t kpm_npages; /* How many kpm pages are managed */ 1967c478bd9Sstevel@tonic-gate 1977c478bd9Sstevel@tonic-gate struct seg *segkp = &kpseg; /* Pageable kernel virtual memory segment */ 1987c478bd9Sstevel@tonic-gate struct seg *segkmap = &kmapseg; /* Kernel generic mapping segment */ 1997c478bd9Sstevel@tonic-gate struct seg *segkpm = &kpmseg; /* 64bit kernel physical mapping segment */ 2007c478bd9Sstevel@tonic-gate 201ad23a2dbSjohansen int segzio_fromheap = 0; /* zio allocations occur from heap */ 202ad23a2dbSjohansen caddr_t segzio_base; /* Base address of segzio */ 203ad23a2dbSjohansen pgcnt_t segziosize = 0; /* size of zio segment in pages */ 204ad23a2dbSjohansen 2057c478bd9Sstevel@tonic-gate /* 2069853d9e8SJason Beloro * A static DR page_t VA map is reserved that can map the page structures 2079853d9e8SJason Beloro * for a domain's entire RA space. The pages that backs this space are 2089853d9e8SJason Beloro * dynamically allocated and need not be physically contiguous. The DR 2099853d9e8SJason Beloro * map size is derived from KPM size. 2109853d9e8SJason Beloro */ 2119853d9e8SJason Beloro int ppvm_enable = 0; /* Static virtual map for page structs */ 2129853d9e8SJason Beloro page_t *ppvm_base; /* Base of page struct map */ 2139853d9e8SJason Beloro pgcnt_t ppvm_size = 0; /* Size of page struct map */ 2149853d9e8SJason Beloro 2159853d9e8SJason Beloro /* 2167c478bd9Sstevel@tonic-gate * debugger pages (if allocated) 2177c478bd9Sstevel@tonic-gate */ 2187c478bd9Sstevel@tonic-gate struct vnode kdebugvp; 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate /* 221ae115bc7Smrj * VA range available to the debugger 222ae115bc7Smrj */ 223ae115bc7Smrj const caddr_t kdi_segdebugbase = (const caddr_t)SEGDEBUGBASE; 224ae115bc7Smrj const size_t kdi_segdebugsize = SEGDEBUGSIZE; 225ae115bc7Smrj 226ae115bc7Smrj /* 2277c478bd9Sstevel@tonic-gate * Segment for relocated kernel structures in 64-bit large RAM kernels 2287c478bd9Sstevel@tonic-gate */ 2297c478bd9Sstevel@tonic-gate struct seg kmem64; 2307c478bd9Sstevel@tonic-gate 231986fd29aSsetje struct memseg *memseg_free; 232986fd29aSsetje 2337c478bd9Sstevel@tonic-gate struct vnode unused_pages_vp; 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate /* 2367c478bd9Sstevel@tonic-gate * VM data structures allocated early during boot. 2377c478bd9Sstevel@tonic-gate */ 2387c478bd9Sstevel@tonic-gate size_t pagehash_sz; 2397c478bd9Sstevel@tonic-gate uint64_t memlist_sz; 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate char tbr_wr_addr_inited = 0; 2427c478bd9Sstevel@tonic-gate 243bb57d1f5Sjc25722 caddr_t mpo_heap32_buf = NULL; 244bb57d1f5Sjc25722 size_t mpo_heap32_bufsz = 0; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate /* 2477c478bd9Sstevel@tonic-gate * Static Routines: 2487c478bd9Sstevel@tonic-gate */ 249986fd29aSsetje static int ndata_alloc_memseg(struct memlist *, size_t); 250986fd29aSsetje static void memlist_new(uint64_t, uint64_t, struct memlist **); 251986fd29aSsetje static void memlist_add(uint64_t, uint64_t, 252986fd29aSsetje struct memlist **, struct memlist **); 253986fd29aSsetje static void kphysm_init(void); 2547c478bd9Sstevel@tonic-gate static void kvm_init(void); 255986fd29aSsetje static void install_kmem64_tte(void); 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate static void startup_init(void); 2587c478bd9Sstevel@tonic-gate static void startup_memlist(void); 2597c478bd9Sstevel@tonic-gate static void startup_modules(void); 2607c478bd9Sstevel@tonic-gate static void startup_bop_gone(void); 2617c478bd9Sstevel@tonic-gate static void startup_vm(void); 2627c478bd9Sstevel@tonic-gate static void startup_end(void); 2637c478bd9Sstevel@tonic-gate static void setup_cage_params(void); 264fea9cb91Slq150181 static void startup_create_io_node(void); 2657c478bd9Sstevel@tonic-gate 2667c478bd9Sstevel@tonic-gate static pgcnt_t npages; 2677c478bd9Sstevel@tonic-gate static struct memlist *memlist; 2687c478bd9Sstevel@tonic-gate void *memlist_end; 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate static pgcnt_t bop_alloc_pages; 2717c478bd9Sstevel@tonic-gate static caddr_t hblk_base; 2727c478bd9Sstevel@tonic-gate uint_t hblk_alloc_dynamic = 0; 2737c478bd9Sstevel@tonic-gate uint_t hblk1_min = H1MIN; 2747c478bd9Sstevel@tonic-gate 2757c478bd9Sstevel@tonic-gate 2767c478bd9Sstevel@tonic-gate /* 2777c478bd9Sstevel@tonic-gate * Hooks for unsupported platforms and down-rev firmware 2787c478bd9Sstevel@tonic-gate */ 2797c478bd9Sstevel@tonic-gate int iam_positron(void); 2807c478bd9Sstevel@tonic-gate #pragma weak iam_positron 2817c478bd9Sstevel@tonic-gate static void do_prom_version_check(void); 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate /* 2847c478bd9Sstevel@tonic-gate * After receiving a thermal interrupt, this is the number of seconds 2857c478bd9Sstevel@tonic-gate * to delay before shutting off the system, assuming 2867c478bd9Sstevel@tonic-gate * shutdown fails. Use /etc/system to change the delay if this isn't 2877c478bd9Sstevel@tonic-gate * large enough. 2887c478bd9Sstevel@tonic-gate */ 2897c478bd9Sstevel@tonic-gate int thermal_powerdown_delay = 1200; 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate /* 2927c478bd9Sstevel@tonic-gate * Used to hold off page relocations into the cage until OBP has completed 2937c478bd9Sstevel@tonic-gate * its boot-time handoff of its resources to the kernel. 2947c478bd9Sstevel@tonic-gate */ 2957c478bd9Sstevel@tonic-gate int page_relocate_ready = 0; 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate /* 298ca622e3aSsvemuri * Indicate if kmem64 allocation was done in small chunks 299ca622e3aSsvemuri */ 300ca622e3aSsvemuri int kmem64_smchunks = 0; 301ca622e3aSsvemuri 302ca622e3aSsvemuri /* 3037c478bd9Sstevel@tonic-gate * Enable some debugging messages concerning memory usage... 3047c478bd9Sstevel@tonic-gate */ 3057c478bd9Sstevel@tonic-gate #ifdef DEBUGGING_MEM 3067c478bd9Sstevel@tonic-gate static int debugging_mem; 3077c478bd9Sstevel@tonic-gate static void 3087c478bd9Sstevel@tonic-gate printmemlist(char *title, struct memlist *list) 3097c478bd9Sstevel@tonic-gate { 3107c478bd9Sstevel@tonic-gate if (!debugging_mem) 3117c478bd9Sstevel@tonic-gate return; 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate printf("%s\n", title); 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate while (list) { 3167c478bd9Sstevel@tonic-gate prom_printf("\taddr = 0x%x %8x, size = 0x%x %8x\n", 31756f33205SJonathan Adams (uint32_t)(list->ml_address >> 32), 31856f33205SJonathan Adams (uint32_t)list->ml_address, 31956f33205SJonathan Adams (uint32_t)(list->ml_size >> 32), 32056f33205SJonathan Adams (uint32_t)(list->ml_size)); 32156f33205SJonathan Adams list = list->ml_next; 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate } 3247c478bd9Sstevel@tonic-gate 3257c478bd9Sstevel@tonic-gate void 3267c478bd9Sstevel@tonic-gate printmemseg(struct memseg *memseg) 3277c478bd9Sstevel@tonic-gate { 3287c478bd9Sstevel@tonic-gate if (!debugging_mem) 3297c478bd9Sstevel@tonic-gate return; 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate printf("memseg\n"); 3327c478bd9Sstevel@tonic-gate 3337c478bd9Sstevel@tonic-gate while (memseg) { 3347c478bd9Sstevel@tonic-gate prom_printf("\tpage = 0x%p, epage = 0x%p, " 3357c478bd9Sstevel@tonic-gate "pfn = 0x%x, epfn = 0x%x\n", 3367c478bd9Sstevel@tonic-gate memseg->pages, memseg->epages, 3377c478bd9Sstevel@tonic-gate memseg->pages_base, memseg->pages_end); 3387c478bd9Sstevel@tonic-gate memseg = memseg->next; 3397c478bd9Sstevel@tonic-gate } 3407c478bd9Sstevel@tonic-gate } 3417c478bd9Sstevel@tonic-gate 3427c478bd9Sstevel@tonic-gate #define debug_pause(str) halt((str)) 3437c478bd9Sstevel@tonic-gate #define MPRINTF(str) if (debugging_mem) prom_printf((str)) 3447c478bd9Sstevel@tonic-gate #define MPRINTF1(str, a) if (debugging_mem) prom_printf((str), (a)) 3457c478bd9Sstevel@tonic-gate #define MPRINTF2(str, a, b) if (debugging_mem) prom_printf((str), (a), (b)) 3467c478bd9Sstevel@tonic-gate #define MPRINTF3(str, a, b, c) \ 3477c478bd9Sstevel@tonic-gate if (debugging_mem) prom_printf((str), (a), (b), (c)) 3487c478bd9Sstevel@tonic-gate #else /* DEBUGGING_MEM */ 3497c478bd9Sstevel@tonic-gate #define MPRINTF(str) 3507c478bd9Sstevel@tonic-gate #define MPRINTF1(str, a) 3517c478bd9Sstevel@tonic-gate #define MPRINTF2(str, a, b) 3527c478bd9Sstevel@tonic-gate #define MPRINTF3(str, a, b, c) 3537c478bd9Sstevel@tonic-gate #endif /* DEBUGGING_MEM */ 3547c478bd9Sstevel@tonic-gate 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate /* 3577c478bd9Sstevel@tonic-gate * 3587c478bd9Sstevel@tonic-gate * Kernel's Virtual Memory Layout. 3597c478bd9Sstevel@tonic-gate * /-----------------------\ 3607c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.FFFFFFFF -| |- 3617c478bd9Sstevel@tonic-gate * | OBP's virtual page | 3627c478bd9Sstevel@tonic-gate * | tables | 3637c478bd9Sstevel@tonic-gate * 0xFFFFFFFC.00000000 -|-----------------------|- 3647c478bd9Sstevel@tonic-gate * : : 3657c478bd9Sstevel@tonic-gate * : : 366ad23a2dbSjohansen * -|-----------------------|- 367ad23a2dbSjohansen * | segzio | (base and size vary) 3687c478bd9Sstevel@tonic-gate * 0xFFFFFE00.00000000 -|-----------------------|- 3697c478bd9Sstevel@tonic-gate * | | Ultrasparc I/II support 3707c478bd9Sstevel@tonic-gate * | segkpm segment | up to 2TB of physical 3717c478bd9Sstevel@tonic-gate * | (64-bit kernel ONLY) | memory, VAC has 2 colors 3727c478bd9Sstevel@tonic-gate * | | 3737c478bd9Sstevel@tonic-gate * 0xFFFFFA00.00000000 -|-----------------------|- 2TB segkpm alignment 3747c478bd9Sstevel@tonic-gate * : : 3757c478bd9Sstevel@tonic-gate * : : 3767c478bd9Sstevel@tonic-gate * 0xFFFFF810.00000000 -|-----------------------|- hole_end 3777c478bd9Sstevel@tonic-gate * | | ^ 3787c478bd9Sstevel@tonic-gate * | UltraSPARC I/II call | | 3797c478bd9Sstevel@tonic-gate * | bug requires an extra | | 3807c478bd9Sstevel@tonic-gate * | 4 GB of space between | | 3817c478bd9Sstevel@tonic-gate * | hole and used RAM | | 3827c478bd9Sstevel@tonic-gate * | | | 3837c478bd9Sstevel@tonic-gate * 0xFFFFF800.00000000 -|-----------------------|- | 3847c478bd9Sstevel@tonic-gate * | | | 3857c478bd9Sstevel@tonic-gate * | Virtual Address Hole | UltraSPARC 3867c478bd9Sstevel@tonic-gate * | on UltraSPARC I/II | I/II * ONLY * 3877c478bd9Sstevel@tonic-gate * | | | 3887c478bd9Sstevel@tonic-gate * 0x00000800.00000000 -|-----------------------|- | 3897c478bd9Sstevel@tonic-gate * | | | 3907c478bd9Sstevel@tonic-gate * | UltraSPARC I/II call | | 3917c478bd9Sstevel@tonic-gate * | bug requires an extra | | 3927c478bd9Sstevel@tonic-gate * | 4 GB of space between | | 3937c478bd9Sstevel@tonic-gate * | hole and used RAM | | 3947c478bd9Sstevel@tonic-gate * | | v 3957c478bd9Sstevel@tonic-gate * 0x000007FF.00000000 -|-----------------------|- hole_start ----- 3967c478bd9Sstevel@tonic-gate * : : ^ 3977c478bd9Sstevel@tonic-gate * : : | 398986fd29aSsetje * |-----------------------| | 399986fd29aSsetje * | | | 400986fd29aSsetje * | ecache flush area | | 401986fd29aSsetje * | (twice largest e$) | | 402986fd29aSsetje * | | | 403bb121940Sdp78419 * 0x00000XXX.XXX00000 -|-----------------------|- kmem64_ | 404bb121940Sdp78419 * | overmapped area | alignend_end | 405bb121940Sdp78419 * | (kmem64_alignsize | | 406bb121940Sdp78419 * | boundary) | | 4077c478bd9Sstevel@tonic-gate * 0x00000XXX.XXXXXXXX -|-----------------------|- kmem64_end | 4087c478bd9Sstevel@tonic-gate * | | | 4097c478bd9Sstevel@tonic-gate * | 64-bit kernel ONLY | | 4107c478bd9Sstevel@tonic-gate * | | | 4117c478bd9Sstevel@tonic-gate * | kmem64 segment | | 4127c478bd9Sstevel@tonic-gate * | | | 4137c478bd9Sstevel@tonic-gate * | (Relocated extra HME | Approximately 4147c478bd9Sstevel@tonic-gate * | block allocations, | 1 TB of virtual 4157c478bd9Sstevel@tonic-gate * | memnode freelists, | address space 4167c478bd9Sstevel@tonic-gate * | HME hash buckets, | | 4177c478bd9Sstevel@tonic-gate * | mml_table, kpmp_table,| | 4187c478bd9Sstevel@tonic-gate * | page_t array and | | 4197c478bd9Sstevel@tonic-gate * | hashblock pool to | | 4207c478bd9Sstevel@tonic-gate * | avoid hard-coded | | 4217c478bd9Sstevel@tonic-gate * | 32-bit vaddr | | 4227c478bd9Sstevel@tonic-gate * | limitations) | | 4237c478bd9Sstevel@tonic-gate * | | v 4247c478bd9Sstevel@tonic-gate * 0x00000700.00000000 -|-----------------------|- SYSLIMIT (kmem64_base) 4257c478bd9Sstevel@tonic-gate * | | 4267c478bd9Sstevel@tonic-gate * | segkmem segment | (SYSLIMIT - SYSBASE = 4TB) 4277c478bd9Sstevel@tonic-gate * | | 4287c478bd9Sstevel@tonic-gate * 0x00000300.00000000 -|-----------------------|- SYSBASE 4297c478bd9Sstevel@tonic-gate * : : 4307c478bd9Sstevel@tonic-gate * : : 4317c478bd9Sstevel@tonic-gate * -|-----------------------|- 4327c478bd9Sstevel@tonic-gate * | | 4337c478bd9Sstevel@tonic-gate * | segmap segment | SEGMAPSIZE (1/8th physmem, 4347c478bd9Sstevel@tonic-gate * | | 256G MAX) 4357c478bd9Sstevel@tonic-gate * 0x000002a7.50000000 -|-----------------------|- SEGMAPBASE 4367c478bd9Sstevel@tonic-gate * : : 4377c478bd9Sstevel@tonic-gate * : : 4387c478bd9Sstevel@tonic-gate * -|-----------------------|- 4397c478bd9Sstevel@tonic-gate * | | 4407c478bd9Sstevel@tonic-gate * | segkp | SEGKPSIZE (2GB) 4417c478bd9Sstevel@tonic-gate * | | 4427c478bd9Sstevel@tonic-gate * | | 4437c478bd9Sstevel@tonic-gate * 0x000002a1.00000000 -|-----------------------|- SEGKPBASE 4447c478bd9Sstevel@tonic-gate * | | 4457c478bd9Sstevel@tonic-gate * 0x000002a0.00000000 -|-----------------------|- MEMSCRUBBASE 4467c478bd9Sstevel@tonic-gate * | | (SEGKPBASE - 0x400000) 4477c478bd9Sstevel@tonic-gate * 0x0000029F.FFE00000 -|-----------------------|- ARGSBASE 4487c478bd9Sstevel@tonic-gate * | | (MEMSCRUBBASE - NCARGS) 4497c478bd9Sstevel@tonic-gate * 0x0000029F.FFD80000 -|-----------------------|- PPMAPBASE 4507c478bd9Sstevel@tonic-gate * | | (ARGSBASE - PPMAPSIZE) 4517c478bd9Sstevel@tonic-gate * 0x0000029F.FFD00000 -|-----------------------|- PPMAP_FAST_BASE 4527c478bd9Sstevel@tonic-gate * | | 4537c478bd9Sstevel@tonic-gate * 0x0000029F.FF980000 -|-----------------------|- PIOMAPBASE 4547c478bd9Sstevel@tonic-gate * | | 4557c478bd9Sstevel@tonic-gate * 0x0000029F.FF580000 -|-----------------------|- NARG_BASE 4567c478bd9Sstevel@tonic-gate * : : 4577c478bd9Sstevel@tonic-gate * : : 4587c478bd9Sstevel@tonic-gate * 0x00000000.FFFFFFFF -|-----------------------|- OFW_END_ADDR 4597c478bd9Sstevel@tonic-gate * | | 4607c478bd9Sstevel@tonic-gate * | OBP | 4617c478bd9Sstevel@tonic-gate * | | 4627c478bd9Sstevel@tonic-gate * 0x00000000.F0000000 -|-----------------------|- OFW_START_ADDR 4637c478bd9Sstevel@tonic-gate * | kmdb | 4647c478bd9Sstevel@tonic-gate * 0x00000000.EDD00000 -|-----------------------|- SEGDEBUGBASE 4657c478bd9Sstevel@tonic-gate * : : 4667c478bd9Sstevel@tonic-gate * : : 4677c478bd9Sstevel@tonic-gate * 0x00000000.7c000000 -|-----------------------|- SYSLIMIT32 4687c478bd9Sstevel@tonic-gate * | | 4697c478bd9Sstevel@tonic-gate * | segkmem32 segment | (SYSLIMIT32 - SYSBASE32 = 4707c478bd9Sstevel@tonic-gate * | | ~64MB) 471b48b4544SGangadhar Mylapuram * -|-----------------------| 472b48b4544SGangadhar Mylapuram * | IVSIZE | 473b48b4544SGangadhar Mylapuram * 0x00000000.70004000 -|-----------------------| 474902408c7Sjmcp * | panicbuf | 475b48b4544SGangadhar Mylapuram * 0x00000000.70002000 -|-----------------------| 476b48b4544SGangadhar Mylapuram * | PAGESIZE | 477986fd29aSsetje * 0x00000000.70000000 -|-----------------------|- SYSBASE32 478986fd29aSsetje * | boot-time | 479986fd29aSsetje * | temporary space | 480986fd29aSsetje * 0x00000000.4C000000 -|-----------------------|- BOOTTMPBASE 4817c478bd9Sstevel@tonic-gate * : : 4827c478bd9Sstevel@tonic-gate * : : 4837c478bd9Sstevel@tonic-gate * | | 4847c478bd9Sstevel@tonic-gate * |-----------------------|- econtig32 4857c478bd9Sstevel@tonic-gate * | vm structures | 4867c478bd9Sstevel@tonic-gate * 0x00000000.01C00000 |-----------------------|- nalloc_end 4877c478bd9Sstevel@tonic-gate * | TSBs | 4887c478bd9Sstevel@tonic-gate * |-----------------------|- end/nalloc_base 4897c478bd9Sstevel@tonic-gate * | kernel data & bss | 4907c478bd9Sstevel@tonic-gate * 0x00000000.01800000 -|-----------------------| 4917c478bd9Sstevel@tonic-gate * : nucleus text hole : 4927c478bd9Sstevel@tonic-gate * 0x00000000.01400000 -|-----------------------| 4937c478bd9Sstevel@tonic-gate * : : 4947c478bd9Sstevel@tonic-gate * |-----------------------| 4957c478bd9Sstevel@tonic-gate * | module text | 4967c478bd9Sstevel@tonic-gate * |-----------------------|- e_text/modtext 4977c478bd9Sstevel@tonic-gate * | kernel text | 4987c478bd9Sstevel@tonic-gate * |-----------------------| 4997c478bd9Sstevel@tonic-gate * | trap table (48k) | 5007c478bd9Sstevel@tonic-gate * 0x00000000.01000000 -|-----------------------|- KERNELBASE 5017c478bd9Sstevel@tonic-gate * | reserved for trapstat |} TSTAT_TOTAL_SIZE 5027c478bd9Sstevel@tonic-gate * |-----------------------| 5037c478bd9Sstevel@tonic-gate * | | 5047c478bd9Sstevel@tonic-gate * | invalid | 5057c478bd9Sstevel@tonic-gate * | | 5067c478bd9Sstevel@tonic-gate * 0x00000000.00000000 _|_______________________| 5077c478bd9Sstevel@tonic-gate * 5087c478bd9Sstevel@tonic-gate * 5097c478bd9Sstevel@tonic-gate * 5107c478bd9Sstevel@tonic-gate * 32-bit User Virtual Memory Layout. 5117c478bd9Sstevel@tonic-gate * /-----------------------\ 5127c478bd9Sstevel@tonic-gate * | | 5137c478bd9Sstevel@tonic-gate * | invalid | 5147c478bd9Sstevel@tonic-gate * | | 5157c478bd9Sstevel@tonic-gate * 0xFFC00000 -|-----------------------|- USERLIMIT 5167c478bd9Sstevel@tonic-gate * | user stack | 5177c478bd9Sstevel@tonic-gate * : : 5187c478bd9Sstevel@tonic-gate * : : 5197c478bd9Sstevel@tonic-gate * : : 5207c478bd9Sstevel@tonic-gate * | user data | 5217c478bd9Sstevel@tonic-gate * -|-----------------------|- 5227c478bd9Sstevel@tonic-gate * | user text | 5237c478bd9Sstevel@tonic-gate * 0x00002000 -|-----------------------|- 5247c478bd9Sstevel@tonic-gate * | invalid | 5257c478bd9Sstevel@tonic-gate * 0x00000000 _|_______________________| 5267c478bd9Sstevel@tonic-gate * 5277c478bd9Sstevel@tonic-gate * 5287c478bd9Sstevel@tonic-gate * 5297c478bd9Sstevel@tonic-gate * 64-bit User Virtual Memory Layout. 5307c478bd9Sstevel@tonic-gate * /-----------------------\ 5317c478bd9Sstevel@tonic-gate * | | 5327c478bd9Sstevel@tonic-gate * | invalid | 5337c478bd9Sstevel@tonic-gate * | | 5347c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.80000000 -|-----------------------|- USERLIMIT 5357c478bd9Sstevel@tonic-gate * | user stack | 5367c478bd9Sstevel@tonic-gate * : : 5377c478bd9Sstevel@tonic-gate * : : 5387c478bd9Sstevel@tonic-gate * : : 5397c478bd9Sstevel@tonic-gate * | user data | 5407c478bd9Sstevel@tonic-gate * -|-----------------------|- 5417c478bd9Sstevel@tonic-gate * | user text | 542986fd29aSsetje * 0x00000000.01000000 -|-----------------------|- 5437c478bd9Sstevel@tonic-gate * | invalid | 5447c478bd9Sstevel@tonic-gate * 0x00000000.00000000 _|_______________________| 5457c478bd9Sstevel@tonic-gate */ 5467c478bd9Sstevel@tonic-gate 5477c478bd9Sstevel@tonic-gate extern caddr_t ecache_init_scrub_flush_area(caddr_t alloc_base); 5487c478bd9Sstevel@tonic-gate extern uint64_t ecache_flush_address(void); 5497c478bd9Sstevel@tonic-gate 5507c478bd9Sstevel@tonic-gate #pragma weak load_platform_modules 55125cf1a30Sjl139090 #pragma weak plat_startup_memlist 5527c478bd9Sstevel@tonic-gate #pragma weak ecache_init_scrub_flush_area 5537c478bd9Sstevel@tonic-gate #pragma weak ecache_flush_address 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate /* 5577c478bd9Sstevel@tonic-gate * By default the DR Cage is enabled for maximum OS 5587c478bd9Sstevel@tonic-gate * MPSS performance. Users needing to disable the cage mechanism 5597c478bd9Sstevel@tonic-gate * can set this variable to zero via /etc/system. 5607c478bd9Sstevel@tonic-gate * Disabling the cage on systems supporting Dynamic Reconfiguration (DR) 5617c478bd9Sstevel@tonic-gate * will result in loss of DR functionality. 5627c478bd9Sstevel@tonic-gate * Platforms wishing to disable kernel Cage by default 5637c478bd9Sstevel@tonic-gate * should do so in their set_platform_defaults() routine. 5647c478bd9Sstevel@tonic-gate */ 5657c478bd9Sstevel@tonic-gate int kernel_cage_enable = 1; 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate static void 5687c478bd9Sstevel@tonic-gate setup_cage_params(void) 5697c478bd9Sstevel@tonic-gate { 5707c478bd9Sstevel@tonic-gate void (*func)(void); 5717c478bd9Sstevel@tonic-gate 5727c478bd9Sstevel@tonic-gate func = (void (*)(void))kobj_getsymvalue("set_platform_cage_params", 0); 5737c478bd9Sstevel@tonic-gate if (func != NULL) { 5747c478bd9Sstevel@tonic-gate (*func)(); 5757c478bd9Sstevel@tonic-gate return; 5767c478bd9Sstevel@tonic-gate } 5777c478bd9Sstevel@tonic-gate 5787c478bd9Sstevel@tonic-gate if (kernel_cage_enable == 0) { 5797c478bd9Sstevel@tonic-gate return; 5807c478bd9Sstevel@tonic-gate } 58185f58038Sdp78419 kcage_range_init(phys_avail, KCAGE_DOWN, total_pages / 256); 5827c478bd9Sstevel@tonic-gate 5837c478bd9Sstevel@tonic-gate if (kcage_on) { 5847c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!Kernel Cage is ENABLED"); 5857c478bd9Sstevel@tonic-gate } else { 5867c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!Kernel Cage is DISABLED"); 5877c478bd9Sstevel@tonic-gate } 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate } 5907c478bd9Sstevel@tonic-gate 5917c478bd9Sstevel@tonic-gate /* 5927c478bd9Sstevel@tonic-gate * Machine-dependent startup code 5937c478bd9Sstevel@tonic-gate */ 5947c478bd9Sstevel@tonic-gate void 5957c478bd9Sstevel@tonic-gate startup(void) 5967c478bd9Sstevel@tonic-gate { 5977c478bd9Sstevel@tonic-gate startup_init(); 5987c478bd9Sstevel@tonic-gate if (&startup_platform) 5997c478bd9Sstevel@tonic-gate startup_platform(); 6007c478bd9Sstevel@tonic-gate startup_memlist(); 6017c478bd9Sstevel@tonic-gate startup_modules(); 6027c478bd9Sstevel@tonic-gate setup_cage_params(); 6037c478bd9Sstevel@tonic-gate startup_bop_gone(); 6047c478bd9Sstevel@tonic-gate startup_vm(); 6057c478bd9Sstevel@tonic-gate startup_end(); 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate 6087c478bd9Sstevel@tonic-gate struct regs sync_reg_buf; 6097c478bd9Sstevel@tonic-gate uint64_t sync_tt; 6107c478bd9Sstevel@tonic-gate 6117c478bd9Sstevel@tonic-gate void 6127c478bd9Sstevel@tonic-gate sync_handler(void) 6137c478bd9Sstevel@tonic-gate { 614843e1988Sjohnlev struct panic_trap_info ti; 6157c478bd9Sstevel@tonic-gate int i; 6167c478bd9Sstevel@tonic-gate 6177c478bd9Sstevel@tonic-gate /* 6187c478bd9Sstevel@tonic-gate * Prevent trying to talk to the other CPUs since they are 6197c478bd9Sstevel@tonic-gate * sitting in the prom and won't reply. 6207c478bd9Sstevel@tonic-gate */ 6217c478bd9Sstevel@tonic-gate for (i = 0; i < NCPU; i++) { 6227c478bd9Sstevel@tonic-gate if ((i != CPU->cpu_id) && CPU_XCALL_READY(i)) { 6237c478bd9Sstevel@tonic-gate cpu[i]->cpu_flags &= ~CPU_READY; 6247c478bd9Sstevel@tonic-gate cpu[i]->cpu_flags |= CPU_QUIESCED; 6257c478bd9Sstevel@tonic-gate CPUSET_DEL(cpu_ready_set, cpu[i]->cpu_id); 6267c478bd9Sstevel@tonic-gate } 6277c478bd9Sstevel@tonic-gate } 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate /* 630*9c84d1a2SDave Plauger * Force a serial dump, since there are no CPUs to help. 631*9c84d1a2SDave Plauger */ 632*9c84d1a2SDave Plauger dump_plat_mincpu = 0; 633*9c84d1a2SDave Plauger 634*9c84d1a2SDave Plauger /* 6357c478bd9Sstevel@tonic-gate * We've managed to get here without going through the 6367c478bd9Sstevel@tonic-gate * normal panic code path. Try and save some useful 6377c478bd9Sstevel@tonic-gate * information. 6387c478bd9Sstevel@tonic-gate */ 6397c478bd9Sstevel@tonic-gate if (!panicstr && (curthread->t_panic_trap == NULL)) { 6407c478bd9Sstevel@tonic-gate ti.trap_type = sync_tt; 6417c478bd9Sstevel@tonic-gate ti.trap_regs = &sync_reg_buf; 6427c478bd9Sstevel@tonic-gate ti.trap_addr = NULL; 6437c478bd9Sstevel@tonic-gate ti.trap_mmu_fsr = 0x0; 6447c478bd9Sstevel@tonic-gate 6457c478bd9Sstevel@tonic-gate curthread->t_panic_trap = &ti; 6467c478bd9Sstevel@tonic-gate } 6477c478bd9Sstevel@tonic-gate 6487c478bd9Sstevel@tonic-gate /* 6497c478bd9Sstevel@tonic-gate * If we're re-entering the panic path, update the signature 6507c478bd9Sstevel@tonic-gate * block so that the SC knows we're in the second part of panic. 6517c478bd9Sstevel@tonic-gate */ 6527c478bd9Sstevel@tonic-gate if (panicstr) 6537c478bd9Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_EXIT, SIGSUBST_DUMP, -1); 6547c478bd9Sstevel@tonic-gate 6557c478bd9Sstevel@tonic-gate nopanicdebug = 1; /* do not perform debug_enter() prior to dump */ 6567c478bd9Sstevel@tonic-gate panic("sync initiated"); 6577c478bd9Sstevel@tonic-gate } 6587c478bd9Sstevel@tonic-gate 6597c478bd9Sstevel@tonic-gate 6607c478bd9Sstevel@tonic-gate static void 6617c478bd9Sstevel@tonic-gate startup_init(void) 6627c478bd9Sstevel@tonic-gate { 6637c478bd9Sstevel@tonic-gate /* 6647c478bd9Sstevel@tonic-gate * We want to save the registers while we're still in OBP 6657c478bd9Sstevel@tonic-gate * so that we know they haven't been fiddled with since. 6667c478bd9Sstevel@tonic-gate * (In principle, OBP can't change them just because it 6677c478bd9Sstevel@tonic-gate * makes a callback, but we'd rather not depend on that 6687c478bd9Sstevel@tonic-gate * behavior.) 6697c478bd9Sstevel@tonic-gate */ 6707c478bd9Sstevel@tonic-gate char sync_str[] = 6717c478bd9Sstevel@tonic-gate "warning @ warning off : sync " 6727c478bd9Sstevel@tonic-gate "%%tl-c %%tstate h# %p x! " 6737c478bd9Sstevel@tonic-gate "%%g1 h# %p x! %%g2 h# %p x! %%g3 h# %p x! " 6747c478bd9Sstevel@tonic-gate "%%g4 h# %p x! %%g5 h# %p x! %%g6 h# %p x! " 6757c478bd9Sstevel@tonic-gate "%%g7 h# %p x! %%o0 h# %p x! %%o1 h# %p x! " 6767c478bd9Sstevel@tonic-gate "%%o2 h# %p x! %%o3 h# %p x! %%o4 h# %p x! " 6777c478bd9Sstevel@tonic-gate "%%o5 h# %p x! %%o6 h# %p x! %%o7 h# %p x! " 6787c478bd9Sstevel@tonic-gate "%%tl-c %%tpc h# %p x! %%tl-c %%tnpc h# %p x! " 6797c478bd9Sstevel@tonic-gate "%%y h# %p l! %%tl-c %%tt h# %p x! " 6807c478bd9Sstevel@tonic-gate "sync ; warning !"; 6817c478bd9Sstevel@tonic-gate 6827c478bd9Sstevel@tonic-gate /* 6837c478bd9Sstevel@tonic-gate * 20 == num of %p substrings 6847c478bd9Sstevel@tonic-gate * 16 == max num of chars %p will expand to. 6857c478bd9Sstevel@tonic-gate */ 6867c478bd9Sstevel@tonic-gate char bp[sizeof (sync_str) + 16 * 20]; 6877c478bd9Sstevel@tonic-gate 6887c478bd9Sstevel@tonic-gate /* 6897c478bd9Sstevel@tonic-gate * Initialize ptl1 stack for the 1st CPU. 6907c478bd9Sstevel@tonic-gate */ 6917c478bd9Sstevel@tonic-gate ptl1_init_cpu(&cpu0); 6927c478bd9Sstevel@tonic-gate 6937c478bd9Sstevel@tonic-gate /* 6947c478bd9Sstevel@tonic-gate * Initialize the address map for cache consistent mappings 6957c478bd9Sstevel@tonic-gate * to random pages; must be done after vac_size is set. 6967c478bd9Sstevel@tonic-gate */ 6977c478bd9Sstevel@tonic-gate ppmapinit(); 6987c478bd9Sstevel@tonic-gate 6997c478bd9Sstevel@tonic-gate /* 7007c478bd9Sstevel@tonic-gate * Initialize the PROM callback handler. 7017c478bd9Sstevel@tonic-gate */ 7027c478bd9Sstevel@tonic-gate init_vx_handler(); 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate /* 7057c478bd9Sstevel@tonic-gate * have prom call sync_callback() to handle the sync and 7067c478bd9Sstevel@tonic-gate * save some useful information which will be stored in the 7077c478bd9Sstevel@tonic-gate * core file later. 7087c478bd9Sstevel@tonic-gate */ 7097c478bd9Sstevel@tonic-gate (void) sprintf((char *)bp, sync_str, 7107c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_tstate, (void *)&sync_reg_buf.r_g1, 7117c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_g2, (void *)&sync_reg_buf.r_g3, 7127c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_g4, (void *)&sync_reg_buf.r_g5, 7137c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_g6, (void *)&sync_reg_buf.r_g7, 7147c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_o0, (void *)&sync_reg_buf.r_o1, 7157c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_o2, (void *)&sync_reg_buf.r_o3, 7167c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_o4, (void *)&sync_reg_buf.r_o5, 7177c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_o6, (void *)&sync_reg_buf.r_o7, 7187c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_pc, (void *)&sync_reg_buf.r_npc, 7197c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_y, (void *)&sync_tt); 7207c478bd9Sstevel@tonic-gate prom_interpret(bp, 0, 0, 0, 0, 0); 7217c478bd9Sstevel@tonic-gate add_vx_handler("sync", 1, (void (*)(cell_t *))sync_handler); 7227c478bd9Sstevel@tonic-gate } 7237c478bd9Sstevel@tonic-gate 724986fd29aSsetje 725986fd29aSsetje size_t 726986fd29aSsetje calc_pp_sz(pgcnt_t npages) 727986fd29aSsetje { 728986fd29aSsetje 729986fd29aSsetje return (npages * sizeof (struct page)); 730986fd29aSsetje } 731986fd29aSsetje 732986fd29aSsetje size_t 733986fd29aSsetje calc_kpmpp_sz(pgcnt_t npages) 734986fd29aSsetje { 735986fd29aSsetje 736986fd29aSsetje kpm_pgshft = (kpm_smallpages == 0) ? MMU_PAGESHIFT4M : MMU_PAGESHIFT; 737986fd29aSsetje kpm_pgsz = 1ull << kpm_pgshft; 738986fd29aSsetje kpm_pgoff = kpm_pgsz - 1; 739986fd29aSsetje kpmp2pshft = kpm_pgshft - PAGESHIFT; 740986fd29aSsetje kpmpnpgs = 1 << kpmp2pshft; 741986fd29aSsetje 742986fd29aSsetje if (kpm_smallpages == 0) { 743986fd29aSsetje /* 744986fd29aSsetje * Avoid fragmentation problems in kphysm_init() 745986fd29aSsetje * by allocating for all of physical memory 746986fd29aSsetje */ 747986fd29aSsetje kpm_npages = ptokpmpr(physinstalled); 748986fd29aSsetje return (kpm_npages * sizeof (kpm_page_t)); 749986fd29aSsetje } else { 750986fd29aSsetje kpm_npages = npages; 751986fd29aSsetje return (kpm_npages * sizeof (kpm_spage_t)); 752986fd29aSsetje } 753986fd29aSsetje } 754986fd29aSsetje 755986fd29aSsetje size_t 756986fd29aSsetje calc_pagehash_sz(pgcnt_t npages) 757986fd29aSsetje { 758cb15d5d9SPeter Rival /* LINTED */ 759cb15d5d9SPeter Rival ASSERT(P2SAMEHIGHBIT((1 << PP_SHIFT), (sizeof (struct page)))); 760986fd29aSsetje /* 761986fd29aSsetje * The page structure hash table size is a power of 2 762986fd29aSsetje * such that the average hash chain length is PAGE_HASHAVELEN. 763986fd29aSsetje */ 764986fd29aSsetje page_hashsz = npages / PAGE_HASHAVELEN; 765cb15d5d9SPeter Rival page_hashsz_shift = MAX((AN_VPSHIFT + VNODE_ALIGN_LOG2 + 1), 766cb15d5d9SPeter Rival highbit(page_hashsz)); 767cb15d5d9SPeter Rival page_hashsz = 1 << page_hashsz_shift; 768986fd29aSsetje return (page_hashsz * sizeof (struct page *)); 769986fd29aSsetje } 770986fd29aSsetje 771ca622e3aSsvemuri int testkmem64_smchunks = 0; 772ca622e3aSsvemuri 773ca622e3aSsvemuri int 774986fd29aSsetje alloc_kmem64(caddr_t base, caddr_t end) 775986fd29aSsetje { 776986fd29aSsetje int i; 777986fd29aSsetje caddr_t aligned_end = NULL; 778986fd29aSsetje 779ca622e3aSsvemuri if (testkmem64_smchunks) 780ca622e3aSsvemuri return (1); 781ca622e3aSsvemuri 782986fd29aSsetje /* 783986fd29aSsetje * Make one large memory alloc after figuring out the 64-bit size. This 784986fd29aSsetje * will enable use of the largest page size appropriate for the system 785986fd29aSsetje * architecture. 786986fd29aSsetje */ 787986fd29aSsetje ASSERT(mmu_exported_pagesize_mask & (1 << TTE8K)); 788986fd29aSsetje ASSERT(IS_P2ALIGNED(base, TTEBYTES(max_bootlp_tteszc))); 789986fd29aSsetje for (i = max_bootlp_tteszc; i >= TTE8K; i--) { 790986fd29aSsetje size_t alloc_size, alignsize; 791986fd29aSsetje #if !defined(C_OBP) 792986fd29aSsetje unsigned long long pa; 793986fd29aSsetje #endif /* !C_OBP */ 794986fd29aSsetje 795986fd29aSsetje if ((mmu_exported_pagesize_mask & (1 << i)) == 0) 796986fd29aSsetje continue; 797986fd29aSsetje alignsize = TTEBYTES(i); 798986fd29aSsetje kmem64_szc = i; 799986fd29aSsetje 800986fd29aSsetje /* limit page size for small memory */ 801986fd29aSsetje if (mmu_btop(alignsize) > (npages >> 2)) 802986fd29aSsetje continue; 803986fd29aSsetje 804986fd29aSsetje aligned_end = (caddr_t)roundup((uintptr_t)end, alignsize); 805986fd29aSsetje alloc_size = aligned_end - base; 806986fd29aSsetje #if !defined(C_OBP) 807986fd29aSsetje if (prom_allocate_phys(alloc_size, alignsize, &pa) == 0) { 808986fd29aSsetje if (prom_claim_virt(alloc_size, base) != (caddr_t)-1) { 809986fd29aSsetje kmem64_pabase = pa; 810986fd29aSsetje kmem64_aligned_end = aligned_end; 811986fd29aSsetje install_kmem64_tte(); 812986fd29aSsetje break; 813986fd29aSsetje } else { 814986fd29aSsetje prom_free_phys(alloc_size, pa); 815986fd29aSsetje } 816986fd29aSsetje } 817986fd29aSsetje #else /* !C_OBP */ 818986fd29aSsetje if (prom_alloc(base, alloc_size, alignsize) == base) { 819986fd29aSsetje kmem64_pabase = va_to_pa(kmem64_base); 820986fd29aSsetje kmem64_aligned_end = aligned_end; 821986fd29aSsetje break; 822986fd29aSsetje } 823986fd29aSsetje #endif /* !C_OBP */ 824986fd29aSsetje if (i == TTE8K) { 825ca622e3aSsvemuri #ifdef sun4v 826ca622e3aSsvemuri /* return failure to try small allocations */ 827ca622e3aSsvemuri return (1); 828ca622e3aSsvemuri #else 829986fd29aSsetje prom_panic("kmem64 allocation failure"); 830ca622e3aSsvemuri #endif 831986fd29aSsetje } 832986fd29aSsetje } 833986fd29aSsetje ASSERT(aligned_end != NULL); 834ca622e3aSsvemuri return (0); 835986fd29aSsetje } 836986fd29aSsetje 837986fd29aSsetje static prom_memlist_t *boot_physinstalled, *boot_physavail, *boot_virtavail; 8387c478bd9Sstevel@tonic-gate static size_t boot_physinstalled_len, boot_physavail_len, boot_virtavail_len; 8397c478bd9Sstevel@tonic-gate 840bb121940Sdp78419 #if !defined(C_OBP) 841bb121940Sdp78419 /* 842bb121940Sdp78419 * Install a temporary tte handler in OBP for kmem64 area. 843bb121940Sdp78419 * 844bb121940Sdp78419 * We map kmem64 area with large pages before the trap table is taken 845bb121940Sdp78419 * over. Since OBP makes 8K mappings, it can create 8K tlb entries in 846bb121940Sdp78419 * the same area. Duplicate tlb entries with different page sizes 847bb121940Sdp78419 * cause unpredicatble behavior. To avoid this, we don't create 848bb121940Sdp78419 * kmem64 mappings via BOP_ALLOC (ends up as prom_alloc() call to 849bb121940Sdp78419 * OBP). Instead, we manage translations with a temporary va>tte-data 850bb121940Sdp78419 * handler (kmem64-tte). This handler is replaced by unix-tte when 851bb121940Sdp78419 * the trap table is taken over. 852bb121940Sdp78419 * 853bb121940Sdp78419 * The temporary handler knows the physical address of the kmem64 854bb121940Sdp78419 * area. It uses the prom's pgmap@ Forth word for other addresses. 855bb121940Sdp78419 * 856bb121940Sdp78419 * We have to use BOP_ALLOC() method for C-OBP platforms because 857bb121940Sdp78419 * pgmap@ is not defined in C-OBP. C-OBP is only used on serengeti 858bb121940Sdp78419 * sun4u platforms. On sun4u we flush tlb after trap table is taken 859bb121940Sdp78419 * over if we use large pages for kernel heap and kmem64. Since sun4u 860bb121940Sdp78419 * prom (unlike sun4v) calls va>tte-data first for client address 861bb121940Sdp78419 * translation prom's ttes for kmem64 can't get into TLB even if we 862bb121940Sdp78419 * later switch to prom's trap table again. C-OBP uses 4M pages for 863bb121940Sdp78419 * client mappings when possible so on all platforms we get the 864bb121940Sdp78419 * benefit from large mappings for kmem64 area immediately during 865bb121940Sdp78419 * boot. 866bb121940Sdp78419 * 867bb121940Sdp78419 * pseudo code: 868bb121940Sdp78419 * if (context != 0) { 869bb121940Sdp78419 * return false 870bb121940Sdp78419 * } else if (miss_va in range[kmem64_base, kmem64_end)) { 871bb121940Sdp78419 * tte = tte_template + 872bb121940Sdp78419 * (((miss_va & pagemask) - kmem64_base)); 873bb121940Sdp78419 * return tte, true 874bb121940Sdp78419 * } else { 875bb121940Sdp78419 * return pgmap@ result 876bb121940Sdp78419 * } 877bb121940Sdp78419 */ 878bb121940Sdp78419 char kmem64_obp_str[] = 879986fd29aSsetje "h# %lx constant kmem64-base " 880986fd29aSsetje "h# %lx constant kmem64-end " 881986fd29aSsetje "h# %lx constant kmem64-pagemask " 882986fd29aSsetje "h# %lx constant kmem64-template " 883bb121940Sdp78419 884bb121940Sdp78419 ": kmem64-tte ( addr cnum -- false | tte-data true ) " 885bb121940Sdp78419 " if ( addr ) " 886bb121940Sdp78419 " drop false exit then ( false ) " 887986fd29aSsetje " dup kmem64-base kmem64-end within if ( addr ) " 888986fd29aSsetje " kmem64-pagemask and ( addr' ) " 889986fd29aSsetje " kmem64-base - ( addr' ) " 890986fd29aSsetje " kmem64-template + ( tte ) " 891bb121940Sdp78419 " true ( tte true ) " 892bb121940Sdp78419 " else ( addr ) " 893bb121940Sdp78419 " pgmap@ ( tte ) " 894bb121940Sdp78419 " dup 0< if true else drop false then ( tte true | false ) " 895bb121940Sdp78419 " then ( tte true | false ) " 896bb121940Sdp78419 "; " 897bb121940Sdp78419 898bb121940Sdp78419 "' kmem64-tte is va>tte-data " 899bb121940Sdp78419 ; 900bb121940Sdp78419 901986fd29aSsetje static void 902bb121940Sdp78419 install_kmem64_tte() 903bb121940Sdp78419 { 904bb121940Sdp78419 char b[sizeof (kmem64_obp_str) + (4 * 16)]; 905bb121940Sdp78419 tte_t tte; 906bb121940Sdp78419 907bb121940Sdp78419 PRM_DEBUG(kmem64_pabase); 908bb121940Sdp78419 PRM_DEBUG(kmem64_szc); 909bb121940Sdp78419 sfmmu_memtte(&tte, kmem64_pabase >> MMU_PAGESHIFT, 9109d0d62adSJason Beloro PROC_DATA | HAT_NOSYNC, kmem64_szc); 911bb121940Sdp78419 PRM_DEBUG(tte.ll); 912bb121940Sdp78419 (void) sprintf(b, kmem64_obp_str, 913bb121940Sdp78419 kmem64_base, kmem64_end, TTE_PAGEMASK(kmem64_szc), tte.ll); 914bb121940Sdp78419 ASSERT(strlen(b) < sizeof (b)); 915bb121940Sdp78419 prom_interpret(b, 0, 0, 0, 0, 0); 916bb121940Sdp78419 } 917bb121940Sdp78419 #endif /* !C_OBP */ 918bb121940Sdp78419 9197c478bd9Sstevel@tonic-gate /* 9207c478bd9Sstevel@tonic-gate * As OBP takes up some RAM when the system boots, pages will already be "lost" 9217c478bd9Sstevel@tonic-gate * to the system and reflected in npages by the time we see it. 9227c478bd9Sstevel@tonic-gate * 9237c478bd9Sstevel@tonic-gate * We only want to allocate kernel structures in the 64-bit virtual address 9247c478bd9Sstevel@tonic-gate * space on systems with enough RAM to make the overhead of keeping track of 9257c478bd9Sstevel@tonic-gate * an extra kernel memory segment worthwhile. 9267c478bd9Sstevel@tonic-gate * 9277c478bd9Sstevel@tonic-gate * Since OBP has already performed its memory allocations by this point, if we 9287c478bd9Sstevel@tonic-gate * have more than MINMOVE_RAM_MB MB of RAM left free, go ahead and map 9297c478bd9Sstevel@tonic-gate * memory in the 64-bit virtual address space; otherwise keep allocations 9307c478bd9Sstevel@tonic-gate * contiguous with we've mapped so far in the 32-bit virtual address space. 9317c478bd9Sstevel@tonic-gate */ 9327c478bd9Sstevel@tonic-gate #define MINMOVE_RAM_MB ((size_t)1900) 9337c478bd9Sstevel@tonic-gate #define MB_TO_BYTES(mb) ((mb) * 1048576ul) 9345832075cSsetje #define BYTES_TO_MB(b) ((b) / 1048576ul) 9357c478bd9Sstevel@tonic-gate 9367c478bd9Sstevel@tonic-gate pgcnt_t tune_npages = (pgcnt_t) 9377c478bd9Sstevel@tonic-gate (MB_TO_BYTES(MINMOVE_RAM_MB)/ (size_t)MMU_PAGESIZE); 9387c478bd9Sstevel@tonic-gate 939fe70c9cfSdp78419 #pragma weak page_set_colorequiv_arr_cpu 940fe70c9cfSdp78419 extern void page_set_colorequiv_arr_cpu(void); 941986fd29aSsetje extern void page_set_colorequiv_arr(void); 942986fd29aSsetje 9435832075cSsetje static pgcnt_t ramdisk_npages; 9445832075cSsetje static struct memlist *old_phys_avail; 9455832075cSsetje 9465832075cSsetje kcage_dir_t kcage_startup_dir = KCAGE_DOWN; 947fe70c9cfSdp78419 9487c478bd9Sstevel@tonic-gate static void 9497c478bd9Sstevel@tonic-gate startup_memlist(void) 9507c478bd9Sstevel@tonic-gate { 951986fd29aSsetje size_t hmehash_sz, pagelist_sz, tt_sz; 952986fd29aSsetje size_t psetable_sz; 9537c478bd9Sstevel@tonic-gate caddr_t alloc_base; 9547c478bd9Sstevel@tonic-gate caddr_t memspace; 9557c478bd9Sstevel@tonic-gate struct memlist *cur; 9567c478bd9Sstevel@tonic-gate size_t syslimit = (size_t)SYSLIMIT; 9577c478bd9Sstevel@tonic-gate size_t sysbase = (size_t)SYSBASE; 9587c478bd9Sstevel@tonic-gate 9597c478bd9Sstevel@tonic-gate /* 9607c478bd9Sstevel@tonic-gate * Initialize enough of the system to allow kmem_alloc to work by 9617c478bd9Sstevel@tonic-gate * calling boot to allocate its memory until the time that 9627c478bd9Sstevel@tonic-gate * kvm_init is completed. The page structs are allocated after 9637c478bd9Sstevel@tonic-gate * rounding up end to the nearest page boundary; the memsegs are 9647c478bd9Sstevel@tonic-gate * initialized and the space they use comes from the kernel heap. 9657c478bd9Sstevel@tonic-gate * With appropriate initialization, they can be reallocated later 9667c478bd9Sstevel@tonic-gate * to a size appropriate for the machine's configuration. 9677c478bd9Sstevel@tonic-gate * 9687c478bd9Sstevel@tonic-gate * At this point, memory is allocated for things that will never 9697c478bd9Sstevel@tonic-gate * need to be freed, this used to be "valloced". This allows a 9707c478bd9Sstevel@tonic-gate * savings as the pages don't need page structures to describe 9717c478bd9Sstevel@tonic-gate * them because them will not be managed by the vm system. 9727c478bd9Sstevel@tonic-gate */ 9737c478bd9Sstevel@tonic-gate 9747c478bd9Sstevel@tonic-gate /* 9757c478bd9Sstevel@tonic-gate * We're loaded by boot with the following configuration (as 9767c478bd9Sstevel@tonic-gate * specified in the sun4u/conf/Mapfile): 9777c478bd9Sstevel@tonic-gate * 9787c478bd9Sstevel@tonic-gate * text: 4 MB chunk aligned on a 4MB boundary 9797c478bd9Sstevel@tonic-gate * data & bss: 4 MB chunk aligned on a 4MB boundary 9807c478bd9Sstevel@tonic-gate * 9817c478bd9Sstevel@tonic-gate * These two chunks will eventually be mapped by 2 locked 4MB 9827c478bd9Sstevel@tonic-gate * ttes and will represent the nucleus of the kernel. This gives 9837c478bd9Sstevel@tonic-gate * us some free space that is already allocated, some or all of 9847c478bd9Sstevel@tonic-gate * which is made available to kernel module text. 9857c478bd9Sstevel@tonic-gate * 9867c478bd9Sstevel@tonic-gate * The free space in the data-bss chunk is used for nucleus 9877c478bd9Sstevel@tonic-gate * allocatable data structures and we reserve it using the 9887c478bd9Sstevel@tonic-gate * nalloc_base and nalloc_end variables. This space is currently 9897c478bd9Sstevel@tonic-gate * being used for hat data structures required for tlb miss 9907c478bd9Sstevel@tonic-gate * handling operations. We align nalloc_base to a l2 cache 9917c478bd9Sstevel@tonic-gate * linesize because this is the line size the hardware uses to 9927c478bd9Sstevel@tonic-gate * maintain cache coherency. 993986fd29aSsetje * 512K is carved out for module data. 9947c478bd9Sstevel@tonic-gate */ 9957c478bd9Sstevel@tonic-gate 996986fd29aSsetje moddata = (caddr_t)roundup((uintptr_t)e_data, MMU_PAGESIZE); 997986fd29aSsetje e_moddata = moddata + MODDATA; 9987c478bd9Sstevel@tonic-gate nalloc_base = e_moddata; 9997c478bd9Sstevel@tonic-gate 10007c478bd9Sstevel@tonic-gate nalloc_end = (caddr_t)roundup((uintptr_t)nalloc_base, MMU_PAGESIZE4M); 10017c478bd9Sstevel@tonic-gate valloc_base = nalloc_base; 10027c478bd9Sstevel@tonic-gate 10037c478bd9Sstevel@tonic-gate /* 10047c478bd9Sstevel@tonic-gate * Calculate the start of the data segment. 10057c478bd9Sstevel@tonic-gate */ 1006986fd29aSsetje if (((uintptr_t)e_moddata & MMU_PAGEMASK4M) != (uintptr_t)s_data) 1007986fd29aSsetje prom_panic("nucleus data overflow"); 10087c478bd9Sstevel@tonic-gate 10097c478bd9Sstevel@tonic-gate PRM_DEBUG(moddata); 10107c478bd9Sstevel@tonic-gate PRM_DEBUG(nalloc_base); 10117c478bd9Sstevel@tonic-gate PRM_DEBUG(nalloc_end); 10127c478bd9Sstevel@tonic-gate 10137c478bd9Sstevel@tonic-gate /* 10147c478bd9Sstevel@tonic-gate * Remember any slop after e_text so we can give it to the modules. 10157c478bd9Sstevel@tonic-gate */ 10167c478bd9Sstevel@tonic-gate PRM_DEBUG(e_text); 10177c478bd9Sstevel@tonic-gate modtext = (caddr_t)roundup((uintptr_t)e_text, MMU_PAGESIZE); 101868d3ac02Skchow if (((uintptr_t)e_text & MMU_PAGEMASK4M) != (uintptr_t)s_text) 1019bb121940Sdp78419 prom_panic("nucleus text overflow"); 10207c478bd9Sstevel@tonic-gate modtext_sz = (caddr_t)roundup((uintptr_t)modtext, MMU_PAGESIZE4M) - 10217c478bd9Sstevel@tonic-gate modtext; 10227c478bd9Sstevel@tonic-gate PRM_DEBUG(modtext); 10237c478bd9Sstevel@tonic-gate PRM_DEBUG(modtext_sz); 10247c478bd9Sstevel@tonic-gate 1025986fd29aSsetje init_boot_memlists(); 10267c478bd9Sstevel@tonic-gate copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len, 10277c478bd9Sstevel@tonic-gate &boot_physavail, &boot_physavail_len, 10287c478bd9Sstevel@tonic-gate &boot_virtavail, &boot_virtavail_len); 1029986fd29aSsetje 10307c478bd9Sstevel@tonic-gate /* 10317c478bd9Sstevel@tonic-gate * Remember what the physically available highest page is 10327c478bd9Sstevel@tonic-gate * so that dumpsys works properly, and find out how much 10337c478bd9Sstevel@tonic-gate * memory is installed. 10347c478bd9Sstevel@tonic-gate */ 10357c478bd9Sstevel@tonic-gate installed_top_size_memlist_array(boot_physinstalled, 10367c478bd9Sstevel@tonic-gate boot_physinstalled_len, &physmax, &physinstalled); 10377c478bd9Sstevel@tonic-gate PRM_DEBUG(physinstalled); 10387c478bd9Sstevel@tonic-gate PRM_DEBUG(physmax); 10397c478bd9Sstevel@tonic-gate 10407c478bd9Sstevel@tonic-gate /* Fill out memory nodes config structure */ 10417c478bd9Sstevel@tonic-gate startup_build_mem_nodes(boot_physinstalled, boot_physinstalled_len); 10427c478bd9Sstevel@tonic-gate 10437c478bd9Sstevel@tonic-gate /* 10447c478bd9Sstevel@tonic-gate * npages is the maximum of available physical memory possible. 10457c478bd9Sstevel@tonic-gate * (ie. it will never be more than this) 1046986fd29aSsetje * 1047986fd29aSsetje * When we boot from a ramdisk, the ramdisk memory isn't free, so 1048986fd29aSsetje * using phys_avail will underestimate what will end up being freed. 1049986fd29aSsetje * A better initial guess is just total memory minus the kernel text 10507c478bd9Sstevel@tonic-gate */ 1051986fd29aSsetje npages = physinstalled - btop(MMU_PAGESIZE4M); 10527c478bd9Sstevel@tonic-gate 10537c478bd9Sstevel@tonic-gate /* 1054986fd29aSsetje * First allocate things that can go in the nucleus data page 1055986fd29aSsetje * (fault status, TSBs, dmv, CPUs) 10567c478bd9Sstevel@tonic-gate */ 10577c478bd9Sstevel@tonic-gate ndata_alloc_init(&ndata, (uintptr_t)nalloc_base, (uintptr_t)nalloc_end); 10587c478bd9Sstevel@tonic-gate 10597c478bd9Sstevel@tonic-gate if ((&ndata_alloc_mmfsa != NULL) && (ndata_alloc_mmfsa(&ndata) != 0)) 10607c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "no more nucleus memory after mfsa alloc"); 10617c478bd9Sstevel@tonic-gate 10627c478bd9Sstevel@tonic-gate if (ndata_alloc_tsbs(&ndata, npages) != 0) 10637c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "no more nucleus memory after tsbs alloc"); 10647c478bd9Sstevel@tonic-gate 10657c478bd9Sstevel@tonic-gate if (ndata_alloc_dmv(&ndata) != 0) 10667c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "no more nucleus memory after dmv alloc"); 10677c478bd9Sstevel@tonic-gate 1068986fd29aSsetje if (ndata_alloc_page_mutexs(&ndata) != 0) 10697c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, 10707c478bd9Sstevel@tonic-gate "no more nucleus memory after page free lists alloc"); 10717c478bd9Sstevel@tonic-gate 1072b52a336eSPavel Tatashin if (ndata_alloc_hat(&ndata) != 0) 10737c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "no more nucleus memory after hat alloc"); 10747c478bd9Sstevel@tonic-gate 1075986fd29aSsetje if (ndata_alloc_memseg(&ndata, boot_physavail_len) != 0) 1076986fd29aSsetje cmn_err(CE_PANIC, "no more nucleus memory after memseg alloc"); 10777c478bd9Sstevel@tonic-gate 10787c478bd9Sstevel@tonic-gate /* 10797c478bd9Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING 10807c478bd9Sstevel@tonic-gate * 10817c478bd9Sstevel@tonic-gate * There are comments all over the SFMMU code warning of dire 10827c478bd9Sstevel@tonic-gate * consequences if the TSBs are moved out of 32-bit space. This 10837c478bd9Sstevel@tonic-gate * is largely because the asm code uses "sethi %hi(addr)"-type 10847c478bd9Sstevel@tonic-gate * instructions which will not provide the expected result if the 10857c478bd9Sstevel@tonic-gate * address is a 64-bit one. 10867c478bd9Sstevel@tonic-gate * 10877c478bd9Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING 10887c478bd9Sstevel@tonic-gate */ 10897c478bd9Sstevel@tonic-gate alloc_base = (caddr_t)roundup((uintptr_t)nalloc_end, MMU_PAGESIZE); 1090986fd29aSsetje PRM_DEBUG(alloc_base); 1091986fd29aSsetje 10927c478bd9Sstevel@tonic-gate alloc_base = sfmmu_ktsb_alloc(alloc_base); 10937c478bd9Sstevel@tonic-gate alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 10947c478bd9Sstevel@tonic-gate PRM_DEBUG(alloc_base); 10957c478bd9Sstevel@tonic-gate 10967c478bd9Sstevel@tonic-gate /* 10977c478bd9Sstevel@tonic-gate * Allocate IOMMU TSB array. We do this here so that the physical 10987c478bd9Sstevel@tonic-gate * memory gets deducted from the PROM's physical memory list. 10997c478bd9Sstevel@tonic-gate */ 11007c478bd9Sstevel@tonic-gate alloc_base = iommu_tsb_init(alloc_base); 1101986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 11027c478bd9Sstevel@tonic-gate PRM_DEBUG(alloc_base); 11037c478bd9Sstevel@tonic-gate 11047c478bd9Sstevel@tonic-gate /* 1105986fd29aSsetje * Allow for an early allocation of physically contiguous memory. 1106986fd29aSsetje */ 1107986fd29aSsetje alloc_base = contig_mem_prealloc(alloc_base, npages); 1108986fd29aSsetje 1109986fd29aSsetje /* 111025cf1a30Sjl139090 * Platforms like Starcat and OPL need special structures assigned in 111125cf1a30Sjl139090 * 32-bit virtual address space because their probing routines execute 111225cf1a30Sjl139090 * FCode, and FCode can't handle 64-bit virtual addresses... 11137c478bd9Sstevel@tonic-gate */ 111425cf1a30Sjl139090 if (&plat_startup_memlist) { 111525cf1a30Sjl139090 alloc_base = plat_startup_memlist(alloc_base); 11167c478bd9Sstevel@tonic-gate alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, 11177c478bd9Sstevel@tonic-gate ecache_alignsize); 11187c478bd9Sstevel@tonic-gate PRM_DEBUG(alloc_base); 11197c478bd9Sstevel@tonic-gate } 11207c478bd9Sstevel@tonic-gate 11217c478bd9Sstevel@tonic-gate /* 11227c478bd9Sstevel@tonic-gate * Save off where the contiguous allocations to date have ended 11237c478bd9Sstevel@tonic-gate * in econtig32. 11247c478bd9Sstevel@tonic-gate */ 11257c478bd9Sstevel@tonic-gate econtig32 = alloc_base; 11267c478bd9Sstevel@tonic-gate PRM_DEBUG(econtig32); 11277c478bd9Sstevel@tonic-gate if (econtig32 > (caddr_t)KERNEL_LIMIT32) 11287c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "econtig32 too big"); 11297c478bd9Sstevel@tonic-gate 1130986fd29aSsetje pp_sz = calc_pp_sz(npages); 1131986fd29aSsetje PRM_DEBUG(pp_sz); 1132986fd29aSsetje if (kpm_enable) { 1133986fd29aSsetje kpm_pp_sz = calc_kpmpp_sz(npages); 1134986fd29aSsetje PRM_DEBUG(kpm_pp_sz); 1135986fd29aSsetje } 1136986fd29aSsetje 1137986fd29aSsetje hmehash_sz = calc_hmehash_sz(npages); 1138986fd29aSsetje PRM_DEBUG(hmehash_sz); 1139986fd29aSsetje 1140986fd29aSsetje pagehash_sz = calc_pagehash_sz(npages); 1141986fd29aSsetje PRM_DEBUG(pagehash_sz); 1142986fd29aSsetje 1143986fd29aSsetje pagelist_sz = calc_free_pagelist_sz(); 1144986fd29aSsetje PRM_DEBUG(pagelist_sz); 1145986fd29aSsetje 1146986fd29aSsetje #ifdef TRAPTRACE 1147986fd29aSsetje tt_sz = calc_traptrace_sz(); 1148986fd29aSsetje PRM_DEBUG(tt_sz); 1149986fd29aSsetje #else 1150986fd29aSsetje tt_sz = 0; 1151986fd29aSsetje #endif /* TRAPTRACE */ 11527c478bd9Sstevel@tonic-gate 1153bb121940Sdp78419 /* 1154986fd29aSsetje * Place the array that protects pp->p_selock in the kmem64 wad. 1155986fd29aSsetje */ 115679755401Ssetje pse_shift = size_pse_array(npages, max_ncpus); 1157986fd29aSsetje PRM_DEBUG(pse_shift); 1158986fd29aSsetje pse_table_size = 1 << pse_shift; 1159986fd29aSsetje PRM_DEBUG(pse_table_size); 1160986fd29aSsetje psetable_sz = roundup( 1161986fd29aSsetje pse_table_size * sizeof (pad_mutex_t), ecache_alignsize); 1162986fd29aSsetje PRM_DEBUG(psetable_sz); 1163986fd29aSsetje 1164986fd29aSsetje /* 1165986fd29aSsetje * Now allocate the whole wad 1166986fd29aSsetje */ 1167986fd29aSsetje kmem64_sz = pp_sz + kpm_pp_sz + hmehash_sz + pagehash_sz + 1168986fd29aSsetje pagelist_sz + tt_sz + psetable_sz; 1169986fd29aSsetje kmem64_sz = roundup(kmem64_sz, PAGESIZE); 1170986fd29aSsetje kmem64_base = (caddr_t)syslimit; 1171986fd29aSsetje kmem64_end = kmem64_base + kmem64_sz; 1172ca622e3aSsvemuri if (alloc_kmem64(kmem64_base, kmem64_end)) { 1173ca622e3aSsvemuri /* 1174ca622e3aSsvemuri * Attempt for kmem64 to allocate one big 1175ca622e3aSsvemuri * contiguous chunk of memory failed. 1176ca622e3aSsvemuri * We get here because we are sun4v. 1177ca622e3aSsvemuri * We will proceed by breaking up 1178ca622e3aSsvemuri * the allocation into two attempts. 1179ca622e3aSsvemuri * First, we allocate kpm_pp_sz, hmehash_sz, 1180ca622e3aSsvemuri * pagehash_sz, pagelist_sz, tt_sz & psetable_sz as 1181ca622e3aSsvemuri * one contiguous chunk. This is a much smaller 1182ca622e3aSsvemuri * chunk and we should get it, if not we panic. 1183ca622e3aSsvemuri * Note that hmehash and tt need to be physically 1184ca622e3aSsvemuri * (in the real address sense) contiguous. 1185ca622e3aSsvemuri * Next, we use bop_alloc_chunk() to 1186ca622e3aSsvemuri * to allocate the page_t structures. 1187ca622e3aSsvemuri * This will allow the page_t to be allocated 1188ca622e3aSsvemuri * in multiple smaller chunks. 1189ca622e3aSsvemuri * In doing so, the assumption that page_t is 1190ca622e3aSsvemuri * physically contiguous no longer hold, this is ok 1191ca622e3aSsvemuri * for sun4v but not for sun4u. 1192ca622e3aSsvemuri */ 1193ca622e3aSsvemuri size_t tmp_size; 1194ca622e3aSsvemuri caddr_t tmp_base; 1195ca622e3aSsvemuri 1196ca622e3aSsvemuri pp_sz = roundup(pp_sz, PAGESIZE); 1197ca622e3aSsvemuri 1198ca622e3aSsvemuri /* 1199ca622e3aSsvemuri * Allocate kpm_pp_sz, hmehash_sz, 1200ca622e3aSsvemuri * pagehash_sz, pagelist_sz, tt_sz & psetable_sz 1201ca622e3aSsvemuri */ 1202ca622e3aSsvemuri tmp_base = kmem64_base + pp_sz; 1203ca622e3aSsvemuri tmp_size = roundup(kpm_pp_sz + hmehash_sz + pagehash_sz + 1204ca622e3aSsvemuri pagelist_sz + tt_sz + psetable_sz, PAGESIZE); 1205ca622e3aSsvemuri if (prom_alloc(tmp_base, tmp_size, PAGESIZE) == 0) 1206ca622e3aSsvemuri prom_panic("kmem64 prom_alloc contig failed"); 1207ca622e3aSsvemuri PRM_DEBUG(tmp_base); 1208ca622e3aSsvemuri PRM_DEBUG(tmp_size); 1209ca622e3aSsvemuri 1210ca622e3aSsvemuri /* 1211ca622e3aSsvemuri * Allocate the page_ts 1212ca622e3aSsvemuri */ 1213ca622e3aSsvemuri if (bop_alloc_chunk(kmem64_base, pp_sz, PAGESIZE) == 0) 1214ca622e3aSsvemuri prom_panic("kmem64 bop_alloc_chunk page_t failed"); 1215ca622e3aSsvemuri PRM_DEBUG(kmem64_base); 1216ca622e3aSsvemuri PRM_DEBUG(pp_sz); 1217ca622e3aSsvemuri 1218ca622e3aSsvemuri kmem64_aligned_end = kmem64_base + pp_sz + tmp_size; 1219ca622e3aSsvemuri ASSERT(kmem64_aligned_end >= kmem64_end); 1220ca622e3aSsvemuri 1221ca622e3aSsvemuri kmem64_smchunks = 1; 1222ca622e3aSsvemuri } else { 1223ca622e3aSsvemuri 1224ca622e3aSsvemuri /* 1225ca622e3aSsvemuri * We need to adjust pp_sz for the normal 1226ca622e3aSsvemuri * case where kmem64 can allocate one large chunk 1227ca622e3aSsvemuri */ 1228ca622e3aSsvemuri if (kpm_smallpages == 0) { 1229ca622e3aSsvemuri npages -= kmem64_sz / (PAGESIZE + sizeof (struct page)); 1230ca622e3aSsvemuri } else { 1231ca622e3aSsvemuri npages -= kmem64_sz / (PAGESIZE + sizeof (struct page) + 1232ca622e3aSsvemuri sizeof (kpm_spage_t)); 1233ca622e3aSsvemuri } 1234ca622e3aSsvemuri pp_sz = npages * sizeof (struct page); 1235ca622e3aSsvemuri } 1236ca622e3aSsvemuri 1237986fd29aSsetje if (kmem64_aligned_end > (hole_start ? hole_start : kpm_vbase)) 1238986fd29aSsetje cmn_err(CE_PANIC, "not enough kmem64 space"); 1239986fd29aSsetje PRM_DEBUG(kmem64_base); 1240986fd29aSsetje PRM_DEBUG(kmem64_end); 1241986fd29aSsetje PRM_DEBUG(kmem64_aligned_end); 1242986fd29aSsetje 1243986fd29aSsetje /* 1244986fd29aSsetje * ... and divy it up 1245bb121940Sdp78419 */ 1246bb121940Sdp78419 alloc_base = kmem64_base; 12475832075cSsetje 1248986fd29aSsetje pp_base = (page_t *)alloc_base; 1249986fd29aSsetje alloc_base += pp_sz; 1250986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1251986fd29aSsetje PRM_DEBUG(pp_base); 12527c478bd9Sstevel@tonic-gate PRM_DEBUG(npages); 12537c478bd9Sstevel@tonic-gate 1254986fd29aSsetje if (kpm_enable) { 1255986fd29aSsetje kpm_pp_base = alloc_base; 1256986fd29aSsetje if (kpm_smallpages == 0) { 1257986fd29aSsetje /* kpm_npages based on physinstalled, don't reset */ 1258986fd29aSsetje kpm_pp_sz = kpm_npages * sizeof (kpm_page_t); 1259986fd29aSsetje } else { 1260986fd29aSsetje kpm_npages = ptokpmpr(npages); 1261986fd29aSsetje kpm_pp_sz = kpm_npages * sizeof (kpm_spage_t); 1262986fd29aSsetje } 1263986fd29aSsetje alloc_base += kpm_pp_sz; 1264986fd29aSsetje alloc_base = 1265986fd29aSsetje (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1266986fd29aSsetje PRM_DEBUG(kpm_pp_base); 1267986fd29aSsetje } 12687c478bd9Sstevel@tonic-gate 1269986fd29aSsetje alloc_base = alloc_hmehash(alloc_base); 1270986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1271986fd29aSsetje PRM_DEBUG(alloc_base); 12727c478bd9Sstevel@tonic-gate 1273986fd29aSsetje page_hash = (page_t **)alloc_base; 1274986fd29aSsetje alloc_base += pagehash_sz; 1275986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1276986fd29aSsetje PRM_DEBUG(page_hash); 12777c478bd9Sstevel@tonic-gate 1278986fd29aSsetje alloc_base = alloc_page_freelists(alloc_base); 1279986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1280986fd29aSsetje PRM_DEBUG(alloc_base); 12817c478bd9Sstevel@tonic-gate 1282986fd29aSsetje #ifdef TRAPTRACE 1283986fd29aSsetje ttrace_buf = alloc_base; 1284986fd29aSsetje alloc_base += tt_sz; 1285986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1286986fd29aSsetje PRM_DEBUG(alloc_base); 1287986fd29aSsetje #endif /* TRAPTRACE */ 12887c478bd9Sstevel@tonic-gate 1289986fd29aSsetje pse_mutex = (pad_mutex_t *)alloc_base; 1290986fd29aSsetje alloc_base += psetable_sz; 1291986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1292986fd29aSsetje PRM_DEBUG(alloc_base); 12937c478bd9Sstevel@tonic-gate 1294ca622e3aSsvemuri /* 1295ca622e3aSsvemuri * Note that if we use small chunk allocations for 1296ca622e3aSsvemuri * kmem64, we need to ensure kmem64_end is the same as 1297ca622e3aSsvemuri * kmem64_aligned_end to prevent subsequent logic from 1298ca622e3aSsvemuri * trying to reuse the overmapping. 1299ca622e3aSsvemuri * Otherwise we adjust kmem64_end to what we really allocated. 1300ca622e3aSsvemuri */ 1301ca622e3aSsvemuri if (kmem64_smchunks) { 1302ca622e3aSsvemuri kmem64_end = kmem64_aligned_end; 1303ca622e3aSsvemuri } else { 1304986fd29aSsetje kmem64_end = (caddr_t)roundup((uintptr_t)alloc_base, PAGESIZE); 1305ca622e3aSsvemuri } 1306986fd29aSsetje kmem64_sz = kmem64_end - kmem64_base; 1307986fd29aSsetje 1308986fd29aSsetje if (&ecache_init_scrub_flush_area) { 1309986fd29aSsetje alloc_base = ecache_init_scrub_flush_area(kmem64_aligned_end); 1310986fd29aSsetje ASSERT(alloc_base <= (hole_start ? hole_start : kpm_vbase)); 13117c478bd9Sstevel@tonic-gate } 13127c478bd9Sstevel@tonic-gate 13137c478bd9Sstevel@tonic-gate /* 13147c478bd9Sstevel@tonic-gate * If physmem is patched to be non-zero, use it instead of 13157c478bd9Sstevel@tonic-gate * the monitor value unless physmem is larger than the total 13167c478bd9Sstevel@tonic-gate * amount of memory on hand. 13177c478bd9Sstevel@tonic-gate */ 13187c478bd9Sstevel@tonic-gate if (physmem == 0 || physmem > npages) 13197c478bd9Sstevel@tonic-gate physmem = npages; 13207c478bd9Sstevel@tonic-gate 13217c478bd9Sstevel@tonic-gate /* 1322986fd29aSsetje * root_is_ramdisk is set via /etc/system when the ramdisk miniroot 1323986fd29aSsetje * is mounted as root. This memory is held down by OBP and unlike 1324986fd29aSsetje * the stub boot_archive is never released. 13257c478bd9Sstevel@tonic-gate * 1326986fd29aSsetje * In order to get things sized correctly on lower memory 1327986fd29aSsetje * machines (where the memory used by the ramdisk represents 1328986fd29aSsetje * a significant portion of memory), physmem is adjusted. 1329986fd29aSsetje * 1330986fd29aSsetje * This is done by subtracting the ramdisk_size which is set 1331986fd29aSsetje * to the size of the ramdisk (in Kb) in /etc/system at the 1332986fd29aSsetje * time the miniroot archive is constructed. 13337c478bd9Sstevel@tonic-gate */ 13345832075cSsetje if (root_is_ramdisk == B_TRUE) { 13355832075cSsetje ramdisk_npages = (ramdisk_size * 1024) / PAGESIZE; 13365832075cSsetje physmem -= ramdisk_npages; 13375832075cSsetje } 13387c478bd9Sstevel@tonic-gate 1339986fd29aSsetje if (kpm_enable && (ndata_alloc_kpm(&ndata, kpm_npages) != 0)) 1340986fd29aSsetje cmn_err(CE_PANIC, "no more nucleus memory after kpm alloc"); 13417c478bd9Sstevel@tonic-gate 13427c478bd9Sstevel@tonic-gate /* 1343986fd29aSsetje * Allocate space for the interrupt vector table. 13447c478bd9Sstevel@tonic-gate */ 1345986fd29aSsetje memspace = prom_alloc((caddr_t)intr_vec_table, IVSIZE, MMU_PAGESIZE); 1346b0fc0e77Sgovinda if (memspace != (caddr_t)intr_vec_table) 1347bb121940Sdp78419 prom_panic("interrupt vector table allocation failure"); 13487c478bd9Sstevel@tonic-gate 13497c478bd9Sstevel@tonic-gate /* 13507c478bd9Sstevel@tonic-gate * Between now and when we finish copying in the memory lists, 13517c478bd9Sstevel@tonic-gate * allocations happen so the space gets fragmented and the 1352986fd29aSsetje * lists longer. Leave enough space for lists twice as 1353986fd29aSsetje * long as we have now; then roundup to a pagesize. 13547c478bd9Sstevel@tonic-gate */ 1355986fd29aSsetje memlist_sz = sizeof (struct memlist) * (prom_phys_installed_len() + 1356986fd29aSsetje prom_phys_avail_len() + prom_virt_avail_len()); 1357986fd29aSsetje memlist_sz *= 2; 1358986fd29aSsetje memlist_sz = roundup(memlist_sz, PAGESIZE); 1359986fd29aSsetje memspace = ndata_alloc(&ndata, memlist_sz, ecache_alignsize); 13607c478bd9Sstevel@tonic-gate if (memspace == NULL) 1361986fd29aSsetje cmn_err(CE_PANIC, "no more nucleus memory after memlist alloc"); 13627c478bd9Sstevel@tonic-gate 13637c478bd9Sstevel@tonic-gate memlist = (struct memlist *)memspace; 13647c478bd9Sstevel@tonic-gate memlist_end = (char *)memspace + memlist_sz; 13657c478bd9Sstevel@tonic-gate PRM_DEBUG(memlist); 13667c478bd9Sstevel@tonic-gate PRM_DEBUG(memlist_end); 1367986fd29aSsetje 13687c478bd9Sstevel@tonic-gate PRM_DEBUG(sysbase); 13697c478bd9Sstevel@tonic-gate PRM_DEBUG(syslimit); 13707c478bd9Sstevel@tonic-gate kernelheap_init((void *)sysbase, (void *)syslimit, 13717c478bd9Sstevel@tonic-gate (caddr_t)sysbase + PAGESIZE, NULL, NULL); 13727c478bd9Sstevel@tonic-gate 13737c478bd9Sstevel@tonic-gate /* 13747c478bd9Sstevel@tonic-gate * Take the most current snapshot we can by calling mem-update. 13757c478bd9Sstevel@tonic-gate */ 13767c478bd9Sstevel@tonic-gate copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len, 13777c478bd9Sstevel@tonic-gate &boot_physavail, &boot_physavail_len, 13787c478bd9Sstevel@tonic-gate &boot_virtavail, &boot_virtavail_len); 13797c478bd9Sstevel@tonic-gate 13807c478bd9Sstevel@tonic-gate /* 1381986fd29aSsetje * Remove the space used by prom_alloc from the kernel heap 13827c478bd9Sstevel@tonic-gate * plus the area actually used by the OBP (if any) 13837c478bd9Sstevel@tonic-gate * ignoring virtual addresses in virt_avail, above syslimit. 13847c478bd9Sstevel@tonic-gate */ 13857c478bd9Sstevel@tonic-gate virt_avail = memlist; 13867c478bd9Sstevel@tonic-gate copy_memlist(boot_virtavail, boot_virtavail_len, &memlist); 13877c478bd9Sstevel@tonic-gate 138856f33205SJonathan Adams for (cur = virt_avail; cur->ml_next; cur = cur->ml_next) { 13897c478bd9Sstevel@tonic-gate uint64_t range_base, range_size; 13907c478bd9Sstevel@tonic-gate 139156f33205SJonathan Adams if ((range_base = cur->ml_address + cur->ml_size) < 139256f33205SJonathan Adams (uint64_t)sysbase) 13937c478bd9Sstevel@tonic-gate continue; 13947c478bd9Sstevel@tonic-gate if (range_base >= (uint64_t)syslimit) 13957c478bd9Sstevel@tonic-gate break; 13967c478bd9Sstevel@tonic-gate /* 13977c478bd9Sstevel@tonic-gate * Limit the range to end at syslimit. 13987c478bd9Sstevel@tonic-gate */ 139956f33205SJonathan Adams range_size = MIN(cur->ml_next->ml_address, 14007c478bd9Sstevel@tonic-gate (uint64_t)syslimit) - range_base; 14017c478bd9Sstevel@tonic-gate (void) vmem_xalloc(heap_arena, (size_t)range_size, PAGESIZE, 14027c478bd9Sstevel@tonic-gate 0, 0, (void *)range_base, (void *)(range_base + range_size), 14037c478bd9Sstevel@tonic-gate VM_NOSLEEP | VM_BESTFIT | VM_PANIC); 14047c478bd9Sstevel@tonic-gate } 14057c478bd9Sstevel@tonic-gate 14067c478bd9Sstevel@tonic-gate phys_avail = memlist; 1407986fd29aSsetje copy_memlist(boot_physavail, boot_physavail_len, &memlist); 14087c478bd9Sstevel@tonic-gate 14097c478bd9Sstevel@tonic-gate /* 14101e45ea5aSblakej * Add any extra memory at the end of the ndata region if there's at 14111e45ea5aSblakej * least a page to add. There might be a few more pages available in 14121e45ea5aSblakej * the middle of the ndata region, but for now they are ignored. 14137c478bd9Sstevel@tonic-gate */ 14141e45ea5aSblakej nalloc_base = ndata_extra_base(&ndata, MMU_PAGESIZE, nalloc_end); 14151e45ea5aSblakej if (nalloc_base == NULL) 14167c478bd9Sstevel@tonic-gate nalloc_base = nalloc_end; 14177c478bd9Sstevel@tonic-gate ndata_remain_sz = nalloc_end - nalloc_base; 14187c478bd9Sstevel@tonic-gate 1419986fd29aSsetje /* 1420986fd29aSsetje * Copy physinstalled list into kernel space. 1421986fd29aSsetje */ 1422986fd29aSsetje phys_install = memlist; 1423986fd29aSsetje copy_memlist(boot_physinstalled, boot_physinstalled_len, &memlist); 14247c478bd9Sstevel@tonic-gate 1425986fd29aSsetje /* 1426986fd29aSsetje * Create list of physical addrs we don't need pp's for: 1427986fd29aSsetje * kernel text 4M page 1428986fd29aSsetje * kernel data 4M page - ndata_remain_sz 1429986fd29aSsetje * kmem64 pages 1430986fd29aSsetje * 1431986fd29aSsetje * NB if adding any pages here, make sure no kpm page 1432986fd29aSsetje * overlaps can occur (see ASSERTs in kphysm_memsegs) 1433986fd29aSsetje */ 1434986fd29aSsetje nopp_list = memlist; 1435986fd29aSsetje memlist_new(va_to_pa(s_text), MMU_PAGESIZE4M, &memlist); 1436986fd29aSsetje memlist_add(va_to_pa(s_data), MMU_PAGESIZE4M - ndata_remain_sz, 1437986fd29aSsetje &memlist, &nopp_list); 1438ca622e3aSsvemuri 1439ca622e3aSsvemuri /* Don't add to nopp_list if kmem64 was allocated in smchunks */ 1440ca622e3aSsvemuri if (!kmem64_smchunks) 1441986fd29aSsetje memlist_add(kmem64_pabase, kmem64_sz, &memlist, &nopp_list); 14427c478bd9Sstevel@tonic-gate 14437c478bd9Sstevel@tonic-gate if ((caddr_t)memlist > (memspace + memlist_sz)) 1444bb121940Sdp78419 prom_panic("memlist overflow"); 14457c478bd9Sstevel@tonic-gate 14467c478bd9Sstevel@tonic-gate /* 144706fb6a36Sdv142724 * Size the pcf array based on the number of cpus in the box at 144806fb6a36Sdv142724 * boot time. 144906fb6a36Sdv142724 */ 145006fb6a36Sdv142724 pcf_init(); 145106fb6a36Sdv142724 145206fb6a36Sdv142724 /* 14537c478bd9Sstevel@tonic-gate * Initialize the page structures from the memory lists. 14547c478bd9Sstevel@tonic-gate */ 1455986fd29aSsetje kphysm_init(); 14567c478bd9Sstevel@tonic-gate 14577c478bd9Sstevel@tonic-gate availrmem_initial = availrmem = freemem; 14587c478bd9Sstevel@tonic-gate PRM_DEBUG(availrmem); 14597c478bd9Sstevel@tonic-gate 14607c478bd9Sstevel@tonic-gate /* 14617c478bd9Sstevel@tonic-gate * Some of the locks depend on page_hashsz being set! 14627c478bd9Sstevel@tonic-gate * kmem_init() depends on this; so, keep it here. 14637c478bd9Sstevel@tonic-gate */ 14647c478bd9Sstevel@tonic-gate page_lock_init(); 14657c478bd9Sstevel@tonic-gate 14667c478bd9Sstevel@tonic-gate /* 14677c478bd9Sstevel@tonic-gate * Initialize kernel memory allocator. 14687c478bd9Sstevel@tonic-gate */ 14697c478bd9Sstevel@tonic-gate kmem_init(); 14707c478bd9Sstevel@tonic-gate 14717c478bd9Sstevel@tonic-gate /* 1472932dc8e5Sdp78419 * Factor in colorequiv to check additional 'equivalent' bins 1473932dc8e5Sdp78419 */ 1474fe70c9cfSdp78419 if (&page_set_colorequiv_arr_cpu != NULL) 1475fe70c9cfSdp78419 page_set_colorequiv_arr_cpu(); 1476fe70c9cfSdp78419 else 1477932dc8e5Sdp78419 page_set_colorequiv_arr(); 1478932dc8e5Sdp78419 1479932dc8e5Sdp78419 /* 14807c478bd9Sstevel@tonic-gate * Initialize bp_mapin(). 14817c478bd9Sstevel@tonic-gate */ 14827c478bd9Sstevel@tonic-gate bp_init(shm_alignment, HAT_STRICTORDER); 14837c478bd9Sstevel@tonic-gate 14847c478bd9Sstevel@tonic-gate /* 1485b48b4544SGangadhar Mylapuram * Reserve space for MPO mblock structs from the 32-bit heap. 14867c478bd9Sstevel@tonic-gate */ 14877c478bd9Sstevel@tonic-gate 1488bb57d1f5Sjc25722 if (mpo_heap32_bufsz > (size_t)0) { 1489bb57d1f5Sjc25722 (void) vmem_xalloc(heap32_arena, mpo_heap32_bufsz, 1490bb57d1f5Sjc25722 PAGESIZE, 0, 0, mpo_heap32_buf, 1491bb57d1f5Sjc25722 mpo_heap32_buf + mpo_heap32_bufsz, 1492bb57d1f5Sjc25722 VM_NOSLEEP | VM_BESTFIT | VM_PANIC); 1493bb57d1f5Sjc25722 } 14947c478bd9Sstevel@tonic-gate mem_config_init(); 14957c478bd9Sstevel@tonic-gate } 14967c478bd9Sstevel@tonic-gate 14977c478bd9Sstevel@tonic-gate static void 14987c478bd9Sstevel@tonic-gate startup_modules(void) 14997c478bd9Sstevel@tonic-gate { 1500986fd29aSsetje int nhblk1, nhblk8; 15017c478bd9Sstevel@tonic-gate size_t nhblksz; 1502bb121940Sdp78419 pgcnt_t pages_per_hblk; 15037c478bd9Sstevel@tonic-gate size_t hme8blk_sz, hme1blk_sz; 15047c478bd9Sstevel@tonic-gate 15057c478bd9Sstevel@tonic-gate /* 15064cca9c84SDave Plauger * The system file /etc/system was read already under startup_memlist. 15077c478bd9Sstevel@tonic-gate */ 15087c478bd9Sstevel@tonic-gate if (&set_platform_defaults) 15097c478bd9Sstevel@tonic-gate set_platform_defaults(); 15107c478bd9Sstevel@tonic-gate 15117c478bd9Sstevel@tonic-gate /* 15127c478bd9Sstevel@tonic-gate * Calculate default settings of system parameters based upon 15137c478bd9Sstevel@tonic-gate * maxusers, yet allow to be overridden via the /etc/system file. 15147c478bd9Sstevel@tonic-gate */ 15157c478bd9Sstevel@tonic-gate param_calc(0); 15167c478bd9Sstevel@tonic-gate 15177c478bd9Sstevel@tonic-gate mod_setup(); 15187c478bd9Sstevel@tonic-gate 15197c478bd9Sstevel@tonic-gate /* 15207c478bd9Sstevel@tonic-gate * If this is a positron, complain and halt. 15217c478bd9Sstevel@tonic-gate */ 15227c478bd9Sstevel@tonic-gate if (&iam_positron && iam_positron()) { 15237c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "This hardware platform is not supported" 15247c478bd9Sstevel@tonic-gate " by this release of Solaris.\n"); 15257c478bd9Sstevel@tonic-gate #ifdef DEBUG 15267c478bd9Sstevel@tonic-gate prom_enter_mon(); /* Type 'go' to resume */ 15277c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Booting an unsupported platform.\n"); 15287c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Booting with down-rev firmware.\n"); 15297c478bd9Sstevel@tonic-gate 15307c478bd9Sstevel@tonic-gate #else /* DEBUG */ 15317c478bd9Sstevel@tonic-gate halt(0); 15327c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 15337c478bd9Sstevel@tonic-gate } 15347c478bd9Sstevel@tonic-gate 15357c478bd9Sstevel@tonic-gate /* 15367c478bd9Sstevel@tonic-gate * If we are running firmware that isn't 64-bit ready 15377c478bd9Sstevel@tonic-gate * then complain and halt. 15387c478bd9Sstevel@tonic-gate */ 15397c478bd9Sstevel@tonic-gate do_prom_version_check(); 15407c478bd9Sstevel@tonic-gate 15417c478bd9Sstevel@tonic-gate /* 15427c478bd9Sstevel@tonic-gate * Initialize system parameters 15437c478bd9Sstevel@tonic-gate */ 15447c478bd9Sstevel@tonic-gate param_init(); 15457c478bd9Sstevel@tonic-gate 15467c478bd9Sstevel@tonic-gate /* 15477c478bd9Sstevel@tonic-gate * maxmem is the amount of physical memory we're playing with. 15487c478bd9Sstevel@tonic-gate */ 15497c478bd9Sstevel@tonic-gate maxmem = physmem; 15507c478bd9Sstevel@tonic-gate 15517c478bd9Sstevel@tonic-gate /* Set segkp limits. */ 1552ae115bc7Smrj ncbase = kdi_segdebugbase; 1553ae115bc7Smrj ncend = kdi_segdebugbase; 15547c478bd9Sstevel@tonic-gate 15557c478bd9Sstevel@tonic-gate /* 15567c478bd9Sstevel@tonic-gate * Initialize the hat layer. 15577c478bd9Sstevel@tonic-gate */ 15587c478bd9Sstevel@tonic-gate hat_init(); 15597c478bd9Sstevel@tonic-gate 15607c478bd9Sstevel@tonic-gate /* 15617c478bd9Sstevel@tonic-gate * Initialize segment management stuff. 15627c478bd9Sstevel@tonic-gate */ 15637c478bd9Sstevel@tonic-gate seg_init(); 15647c478bd9Sstevel@tonic-gate 15657c478bd9Sstevel@tonic-gate /* 15667c478bd9Sstevel@tonic-gate * Create the va>tte handler, so the prom can understand 15677c478bd9Sstevel@tonic-gate * kernel translations. The handler is installed later, just 15687c478bd9Sstevel@tonic-gate * as we are about to take over the trap table from the prom. 15697c478bd9Sstevel@tonic-gate */ 15707c478bd9Sstevel@tonic-gate create_va_to_tte(); 15717c478bd9Sstevel@tonic-gate 15727c478bd9Sstevel@tonic-gate /* 15737c478bd9Sstevel@tonic-gate * Load the forthdebugger (optional) 15747c478bd9Sstevel@tonic-gate */ 15757c478bd9Sstevel@tonic-gate forthdebug_init(); 15767c478bd9Sstevel@tonic-gate 15777c478bd9Sstevel@tonic-gate /* 15787c478bd9Sstevel@tonic-gate * Create OBP node for console input callbacks 15797c478bd9Sstevel@tonic-gate * if it is needed. 15807c478bd9Sstevel@tonic-gate */ 1581fea9cb91Slq150181 startup_create_io_node(); 15827c478bd9Sstevel@tonic-gate 15837c478bd9Sstevel@tonic-gate if (modloadonly("fs", "specfs") == -1) 15847c478bd9Sstevel@tonic-gate halt("Can't load specfs"); 15857c478bd9Sstevel@tonic-gate 15867c478bd9Sstevel@tonic-gate if (modloadonly("fs", "devfs") == -1) 15877c478bd9Sstevel@tonic-gate halt("Can't load devfs"); 15887c478bd9Sstevel@tonic-gate 158935a5a358SJonathan Adams if (modloadonly("fs", "procfs") == -1) 159035a5a358SJonathan Adams halt("Can't load procfs"); 159135a5a358SJonathan Adams 15927c478bd9Sstevel@tonic-gate if (modloadonly("misc", "swapgeneric") == -1) 15937c478bd9Sstevel@tonic-gate halt("Can't load swapgeneric"); 15947c478bd9Sstevel@tonic-gate 159545916cd2Sjpk (void) modloadonly("sys", "lbl_edition"); 159645916cd2Sjpk 15977c478bd9Sstevel@tonic-gate dispinit(); 15987c478bd9Sstevel@tonic-gate 15997c478bd9Sstevel@tonic-gate /* 16007c478bd9Sstevel@tonic-gate * Infer meanings to the members of the idprom buffer. 16017c478bd9Sstevel@tonic-gate */ 16027c478bd9Sstevel@tonic-gate parse_idprom(); 16037c478bd9Sstevel@tonic-gate 16047c478bd9Sstevel@tonic-gate /* Read cluster configuration data. */ 16057c478bd9Sstevel@tonic-gate clconf_init(); 16067c478bd9Sstevel@tonic-gate 16077c478bd9Sstevel@tonic-gate setup_ddi(); 16087c478bd9Sstevel@tonic-gate 16097c478bd9Sstevel@tonic-gate /* 16107c478bd9Sstevel@tonic-gate * Lets take this opportunity to load the root device. 16117c478bd9Sstevel@tonic-gate */ 16127c478bd9Sstevel@tonic-gate if (loadrootmodules() != 0) 16137c478bd9Sstevel@tonic-gate debug_enter("Can't load the root filesystem"); 16147c478bd9Sstevel@tonic-gate 16157c478bd9Sstevel@tonic-gate /* 16167c478bd9Sstevel@tonic-gate * Load tod driver module for the tod part found on this system. 16177c478bd9Sstevel@tonic-gate * Recompute the cpu frequency/delays based on tod as tod part 16187c478bd9Sstevel@tonic-gate * tends to keep time more accurately. 16197c478bd9Sstevel@tonic-gate */ 16207c478bd9Sstevel@tonic-gate if (&load_tod_module) 16217c478bd9Sstevel@tonic-gate load_tod_module(); 16227c478bd9Sstevel@tonic-gate 16237c478bd9Sstevel@tonic-gate /* 16247c478bd9Sstevel@tonic-gate * Allow platforms to load modules which might 16257c478bd9Sstevel@tonic-gate * be needed after bootops are gone. 16267c478bd9Sstevel@tonic-gate */ 16277c478bd9Sstevel@tonic-gate if (&load_platform_modules) 16287c478bd9Sstevel@tonic-gate load_platform_modules(); 16297c478bd9Sstevel@tonic-gate 16307c478bd9Sstevel@tonic-gate setcpudelay(); 16317c478bd9Sstevel@tonic-gate 16327c478bd9Sstevel@tonic-gate copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len, 16337c478bd9Sstevel@tonic-gate &boot_physavail, &boot_physavail_len, 16347c478bd9Sstevel@tonic-gate &boot_virtavail, &boot_virtavail_len); 16357c478bd9Sstevel@tonic-gate 16367c478bd9Sstevel@tonic-gate /* 16377c478bd9Sstevel@tonic-gate * Calculation and allocation of hmeblks needed to remap 1638bb121940Sdp78419 * the memory allocated by PROM till now. 1639bb121940Sdp78419 * Overestimate the number of hblk1 elements by assuming 1640bb121940Sdp78419 * worst case of TTE64K mappings. 1641bb121940Sdp78419 * sfmmu_hblk_alloc will panic if this calculation is wrong. 16427c478bd9Sstevel@tonic-gate */ 1643bb121940Sdp78419 bop_alloc_pages = btopr(kmem64_end - kmem64_base); 1644bb121940Sdp78419 pages_per_hblk = btop(HMEBLK_SPAN(TTE64K)); 1645bb121940Sdp78419 bop_alloc_pages = roundup(bop_alloc_pages, pages_per_hblk); 1646bb121940Sdp78419 nhblk1 = bop_alloc_pages / pages_per_hblk + hblk1_min; 16477c478bd9Sstevel@tonic-gate 1648bb121940Sdp78419 bop_alloc_pages = size_virtalloc(boot_virtavail, boot_virtavail_len); 1649bb121940Sdp78419 1650bb121940Sdp78419 /* sfmmu_init_nucleus_hblks expects properly aligned data structures */ 16517c478bd9Sstevel@tonic-gate hme8blk_sz = roundup(HME8BLK_SZ, sizeof (int64_t)); 16527c478bd9Sstevel@tonic-gate hme1blk_sz = roundup(HME1BLK_SZ, sizeof (int64_t)); 16537c478bd9Sstevel@tonic-gate 1654bb121940Sdp78419 bop_alloc_pages += btopr(nhblk1 * hme1blk_sz); 1655bb121940Sdp78419 16567c478bd9Sstevel@tonic-gate pages_per_hblk = btop(HMEBLK_SPAN(TTE8K)); 1657bb121940Sdp78419 nhblk8 = 0; 1658bb121940Sdp78419 while (bop_alloc_pages > 1) { 16597c478bd9Sstevel@tonic-gate bop_alloc_pages = roundup(bop_alloc_pages, pages_per_hblk); 1660bb121940Sdp78419 nhblk8 += bop_alloc_pages /= pages_per_hblk; 1661bb121940Sdp78419 bop_alloc_pages *= hme8blk_sz; 1662bb121940Sdp78419 bop_alloc_pages = btopr(bop_alloc_pages); 1663bb121940Sdp78419 } 1664bb121940Sdp78419 nhblk8 += 2; 16657c478bd9Sstevel@tonic-gate 16667c478bd9Sstevel@tonic-gate /* 16677c478bd9Sstevel@tonic-gate * Since hblk8's can hold up to 64k of mappings aligned on a 64k 16687c478bd9Sstevel@tonic-gate * boundary, the number of hblk8's needed to map the entries in the 16697c478bd9Sstevel@tonic-gate * boot_virtavail list needs to be adjusted to take this into 16707c478bd9Sstevel@tonic-gate * consideration. Thus, we need to add additional hblk8's since it 16717c478bd9Sstevel@tonic-gate * is possible that an hblk8 will not have all 8 slots used due to 16727c478bd9Sstevel@tonic-gate * alignment constraints. Since there were boot_virtavail_len entries 16737c478bd9Sstevel@tonic-gate * in that list, we need to add that many hblk8's to the number 16747c478bd9Sstevel@tonic-gate * already calculated to make sure we don't underestimate. 16757c478bd9Sstevel@tonic-gate */ 16767c478bd9Sstevel@tonic-gate nhblk8 += boot_virtavail_len; 16777c478bd9Sstevel@tonic-gate nhblksz = nhblk8 * hme8blk_sz + nhblk1 * hme1blk_sz; 16787c478bd9Sstevel@tonic-gate 16797c478bd9Sstevel@tonic-gate /* Allocate in pagesize chunks */ 16807c478bd9Sstevel@tonic-gate nhblksz = roundup(nhblksz, MMU_PAGESIZE); 16817c478bd9Sstevel@tonic-gate hblk_base = kmem_zalloc(nhblksz, KM_SLEEP); 16827c478bd9Sstevel@tonic-gate sfmmu_init_nucleus_hblks(hblk_base, nhblksz, nhblk8, nhblk1); 16837c478bd9Sstevel@tonic-gate } 16847c478bd9Sstevel@tonic-gate 16857c478bd9Sstevel@tonic-gate static void 16867c478bd9Sstevel@tonic-gate startup_bop_gone(void) 16877c478bd9Sstevel@tonic-gate { 16887c478bd9Sstevel@tonic-gate 16897c478bd9Sstevel@tonic-gate /* 16901ae08745Sheppo * Destroy the MD initialized at startup 16911ae08745Sheppo * The startup initializes the MD framework 16921ae08745Sheppo * using prom and BOP alloc free it now. 16931ae08745Sheppo */ 16941ae08745Sheppo mach_descrip_startup_fini(); 16951ae08745Sheppo 16961ae08745Sheppo /* 1697986fd29aSsetje * We're done with prom allocations. 16987c478bd9Sstevel@tonic-gate */ 1699986fd29aSsetje bop_fini(); 17007c478bd9Sstevel@tonic-gate 17017c478bd9Sstevel@tonic-gate copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len, 17027c478bd9Sstevel@tonic-gate &boot_physavail, &boot_physavail_len, 17037c478bd9Sstevel@tonic-gate &boot_virtavail, &boot_virtavail_len); 17047c478bd9Sstevel@tonic-gate 17057c478bd9Sstevel@tonic-gate /* 17067c478bd9Sstevel@tonic-gate * setup physically contiguous area twice as large as the ecache. 17077c478bd9Sstevel@tonic-gate * this is used while doing displacement flush of ecaches 17087c478bd9Sstevel@tonic-gate */ 17097c478bd9Sstevel@tonic-gate if (&ecache_flush_address) { 17107c478bd9Sstevel@tonic-gate ecache_flushaddr = ecache_flush_address(); 17117c478bd9Sstevel@tonic-gate if (ecache_flushaddr == (uint64_t)-1) { 17127c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, 17137c478bd9Sstevel@tonic-gate "startup: no memory to set ecache_flushaddr"); 17147c478bd9Sstevel@tonic-gate } 17157c478bd9Sstevel@tonic-gate } 17167c478bd9Sstevel@tonic-gate 17177c478bd9Sstevel@tonic-gate /* 17187c478bd9Sstevel@tonic-gate * Virtual available next. 17197c478bd9Sstevel@tonic-gate */ 17207c478bd9Sstevel@tonic-gate ASSERT(virt_avail != NULL); 17217c478bd9Sstevel@tonic-gate memlist_free_list(virt_avail); 17227c478bd9Sstevel@tonic-gate virt_avail = memlist; 17237c478bd9Sstevel@tonic-gate copy_memlist(boot_virtavail, boot_virtavail_len, &memlist); 17247c478bd9Sstevel@tonic-gate 17257c478bd9Sstevel@tonic-gate } 17267c478bd9Sstevel@tonic-gate 17277c478bd9Sstevel@tonic-gate 17287c478bd9Sstevel@tonic-gate /* 17297c478bd9Sstevel@tonic-gate * startup_fixup_physavail - called from mach_sfmmu.c after the final 17307c478bd9Sstevel@tonic-gate * allocations have been performed. We can't call it in startup_bop_gone 17317c478bd9Sstevel@tonic-gate * since later operations can cause obp to allocate more memory. 17327c478bd9Sstevel@tonic-gate */ 17337c478bd9Sstevel@tonic-gate void 17347c478bd9Sstevel@tonic-gate startup_fixup_physavail(void) 17357c478bd9Sstevel@tonic-gate { 17367c478bd9Sstevel@tonic-gate struct memlist *cur; 1737bb121940Sdp78419 size_t kmem64_overmap_size = kmem64_aligned_end - kmem64_end; 1738bb121940Sdp78419 1739bb121940Sdp78419 PRM_DEBUG(kmem64_overmap_size); 17407c478bd9Sstevel@tonic-gate 17417c478bd9Sstevel@tonic-gate /* 17427c478bd9Sstevel@tonic-gate * take the most current snapshot we can by calling mem-update 17437c478bd9Sstevel@tonic-gate */ 17447c478bd9Sstevel@tonic-gate copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len, 17457c478bd9Sstevel@tonic-gate &boot_physavail, &boot_physavail_len, 17467c478bd9Sstevel@tonic-gate &boot_virtavail, &boot_virtavail_len); 17477c478bd9Sstevel@tonic-gate 17487c478bd9Sstevel@tonic-gate /* 17497c478bd9Sstevel@tonic-gate * Copy phys_avail list, again. 17507c478bd9Sstevel@tonic-gate * Both the kernel/boot and the prom have been allocating 17517c478bd9Sstevel@tonic-gate * from the original list we copied earlier. 17527c478bd9Sstevel@tonic-gate */ 17537c478bd9Sstevel@tonic-gate cur = memlist; 1754986fd29aSsetje copy_memlist(boot_physavail, boot_physavail_len, &memlist); 17557c478bd9Sstevel@tonic-gate 17567c478bd9Sstevel@tonic-gate /* 1757bb121940Sdp78419 * Add any unused kmem64 memory from overmapped page 1758bb121940Sdp78419 * (Note: va_to_pa does not work for kmem64_end) 1759bb121940Sdp78419 */ 1760bb121940Sdp78419 if (kmem64_overmap_size) { 1761bb121940Sdp78419 memlist_add(kmem64_pabase + (kmem64_end - kmem64_base), 1762986fd29aSsetje kmem64_overmap_size, &memlist, &cur); 1763bb121940Sdp78419 } 1764bb121940Sdp78419 1765bb121940Sdp78419 /* 1766986fd29aSsetje * Add any extra memory after e_data we added to the phys_avail list 17677c478bd9Sstevel@tonic-gate * back to the old list. 17687c478bd9Sstevel@tonic-gate */ 17697c478bd9Sstevel@tonic-gate if (ndata_remain_sz >= MMU_PAGESIZE) 17707c478bd9Sstevel@tonic-gate memlist_add(va_to_pa(nalloc_base), 17717c478bd9Sstevel@tonic-gate (uint64_t)ndata_remain_sz, &memlist, &cur); 17727c478bd9Sstevel@tonic-gate 17737c478bd9Sstevel@tonic-gate /* 17747c478bd9Sstevel@tonic-gate * There isn't any bounds checking on the memlist area 17757c478bd9Sstevel@tonic-gate * so ensure it hasn't overgrown. 17767c478bd9Sstevel@tonic-gate */ 17777c478bd9Sstevel@tonic-gate if ((caddr_t)memlist > (caddr_t)memlist_end) 17787c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "startup: memlist size exceeded"); 17797c478bd9Sstevel@tonic-gate 17807c478bd9Sstevel@tonic-gate /* 17817c478bd9Sstevel@tonic-gate * The kernel removes the pages that were allocated for it from 17827c478bd9Sstevel@tonic-gate * the freelist, but we now have to find any -extra- pages that 17837c478bd9Sstevel@tonic-gate * the prom has allocated for it's own book-keeping, and remove 17847c478bd9Sstevel@tonic-gate * them from the freelist too. sigh. 17857c478bd9Sstevel@tonic-gate */ 1786986fd29aSsetje sync_memlists(phys_avail, cur); 17877c478bd9Sstevel@tonic-gate 17887c478bd9Sstevel@tonic-gate ASSERT(phys_avail != NULL); 17897c478bd9Sstevel@tonic-gate 17905832075cSsetje old_phys_avail = phys_avail; 17915832075cSsetje phys_avail = cur; 17925832075cSsetje } 17935832075cSsetje 17945832075cSsetje void 17955832075cSsetje update_kcage_ranges(uint64_t addr, uint64_t len) 17965832075cSsetje { 17975832075cSsetje pfn_t base = btop(addr); 17985832075cSsetje pgcnt_t num = btop(len); 17995832075cSsetje int rv; 18005832075cSsetje 18015832075cSsetje rv = kcage_range_add(base, num, kcage_startup_dir); 18025832075cSsetje 18035832075cSsetje if (rv == ENOMEM) { 18045832075cSsetje cmn_err(CE_WARN, "%ld megabytes not available to kernel cage", 18055832075cSsetje (len == 0 ? 0 : BYTES_TO_MB(len))); 18065832075cSsetje } else if (rv != 0) { 18075832075cSsetje /* catch this in debug kernels */ 18085832075cSsetje ASSERT(0); 18095832075cSsetje 18105832075cSsetje cmn_err(CE_WARN, "unexpected kcage_range_add" 18115832075cSsetje " return value %d", rv); 18125832075cSsetje } 18137c478bd9Sstevel@tonic-gate } 18147c478bd9Sstevel@tonic-gate 18157c478bd9Sstevel@tonic-gate static void 18167c478bd9Sstevel@tonic-gate startup_vm(void) 18177c478bd9Sstevel@tonic-gate { 18187c478bd9Sstevel@tonic-gate size_t i; 18197c478bd9Sstevel@tonic-gate struct segmap_crargs a; 18207c478bd9Sstevel@tonic-gate struct segkpm_crargs b; 18217c478bd9Sstevel@tonic-gate 18227c478bd9Sstevel@tonic-gate uint64_t avmem; 18237c478bd9Sstevel@tonic-gate caddr_t va; 18247c478bd9Sstevel@tonic-gate pgcnt_t max_phys_segkp; 18257c478bd9Sstevel@tonic-gate int mnode; 18267c478bd9Sstevel@tonic-gate 1827ec25b48fSsusans extern int use_brk_lpg, use_stk_lpg; 1828beb1bda0Sdavemq 18297c478bd9Sstevel@tonic-gate /* 18307c478bd9Sstevel@tonic-gate * get prom's mappings, create hments for them and switch 18317c478bd9Sstevel@tonic-gate * to the kernel context. 18327c478bd9Sstevel@tonic-gate */ 18337c478bd9Sstevel@tonic-gate hat_kern_setup(); 18347c478bd9Sstevel@tonic-gate 18357c478bd9Sstevel@tonic-gate /* 18367c478bd9Sstevel@tonic-gate * Take over trap table 18377c478bd9Sstevel@tonic-gate */ 18387c478bd9Sstevel@tonic-gate setup_trap_table(); 18397c478bd9Sstevel@tonic-gate 18407c478bd9Sstevel@tonic-gate /* 18417c478bd9Sstevel@tonic-gate * Install the va>tte handler, so that the prom can handle 18427c478bd9Sstevel@tonic-gate * misses and understand the kernel table layout in case 18437c478bd9Sstevel@tonic-gate * we need call into the prom. 18447c478bd9Sstevel@tonic-gate */ 18457c478bd9Sstevel@tonic-gate install_va_to_tte(); 18467c478bd9Sstevel@tonic-gate 18477c478bd9Sstevel@tonic-gate /* 18487c478bd9Sstevel@tonic-gate * Set a flag to indicate that the tba has been taken over. 18497c478bd9Sstevel@tonic-gate */ 18507c478bd9Sstevel@tonic-gate tba_taken_over = 1; 18517c478bd9Sstevel@tonic-gate 18527c478bd9Sstevel@tonic-gate /* initialize MMU primary context register */ 18537c478bd9Sstevel@tonic-gate mmu_init_kcontext(); 18547c478bd9Sstevel@tonic-gate 18557c478bd9Sstevel@tonic-gate /* 18567c478bd9Sstevel@tonic-gate * The boot cpu can now take interrupts, x-calls, x-traps 18577c478bd9Sstevel@tonic-gate */ 18587c478bd9Sstevel@tonic-gate CPUSET_ADD(cpu_ready_set, CPU->cpu_id); 18597c478bd9Sstevel@tonic-gate CPU->cpu_flags |= (CPU_READY | CPU_ENABLE | CPU_EXISTS); 18607c478bd9Sstevel@tonic-gate 18617c478bd9Sstevel@tonic-gate /* 18627c478bd9Sstevel@tonic-gate * Set a flag to tell write_scb_int() that it can access V_TBR_WR_ADDR. 18637c478bd9Sstevel@tonic-gate */ 18647c478bd9Sstevel@tonic-gate tbr_wr_addr_inited = 1; 18657c478bd9Sstevel@tonic-gate 18667c478bd9Sstevel@tonic-gate /* 18677c478bd9Sstevel@tonic-gate * Initialize VM system, and map kernel address space. 18687c478bd9Sstevel@tonic-gate */ 18697c478bd9Sstevel@tonic-gate kvm_init(); 18707c478bd9Sstevel@tonic-gate 18715832075cSsetje ASSERT(old_phys_avail != NULL && phys_avail != NULL); 18725832075cSsetje if (kernel_cage_enable) { 18735832075cSsetje diff_memlists(phys_avail, old_phys_avail, update_kcage_ranges); 18745832075cSsetje } 18755832075cSsetje memlist_free_list(old_phys_avail); 18765832075cSsetje 18777c478bd9Sstevel@tonic-gate /* 18787c478bd9Sstevel@tonic-gate * If the following is true, someone has patched 18797c478bd9Sstevel@tonic-gate * phsymem to be less than the number of pages that 18807c478bd9Sstevel@tonic-gate * the system actually has. Remove pages until system 18817c478bd9Sstevel@tonic-gate * memory is limited to the requested amount. Since we 18827c478bd9Sstevel@tonic-gate * have allocated page structures for all pages, we 18837c478bd9Sstevel@tonic-gate * correct the amount of memory we want to remove 18847c478bd9Sstevel@tonic-gate * by the size of the memory used to hold page structures 18857c478bd9Sstevel@tonic-gate * for the non-used pages. 18867c478bd9Sstevel@tonic-gate */ 18875832075cSsetje if (physmem + ramdisk_npages < npages) { 18887c478bd9Sstevel@tonic-gate pgcnt_t diff, off; 18897c478bd9Sstevel@tonic-gate struct page *pp; 18907c478bd9Sstevel@tonic-gate struct seg kseg; 18917c478bd9Sstevel@tonic-gate 18927c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "limiting physmem to %ld pages", physmem); 18937c478bd9Sstevel@tonic-gate 18947c478bd9Sstevel@tonic-gate off = 0; 18955832075cSsetje diff = npages - (physmem + ramdisk_npages); 18967c478bd9Sstevel@tonic-gate diff -= mmu_btopr(diff * sizeof (struct page)); 18977c478bd9Sstevel@tonic-gate kseg.s_as = &kas; 18987c478bd9Sstevel@tonic-gate while (diff--) { 18997c478bd9Sstevel@tonic-gate pp = page_create_va(&unused_pages_vp, (offset_t)off, 19007c478bd9Sstevel@tonic-gate MMU_PAGESIZE, PG_WAIT | PG_EXCL, 19017c478bd9Sstevel@tonic-gate &kseg, (caddr_t)off); 19027c478bd9Sstevel@tonic-gate if (pp == NULL) 19037c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "limited physmem too much!"); 19047c478bd9Sstevel@tonic-gate page_io_unlock(pp); 19057c478bd9Sstevel@tonic-gate page_downgrade(pp); 19067c478bd9Sstevel@tonic-gate availrmem--; 19077c478bd9Sstevel@tonic-gate off += MMU_PAGESIZE; 19087c478bd9Sstevel@tonic-gate } 19097c478bd9Sstevel@tonic-gate } 19107c478bd9Sstevel@tonic-gate 19117c478bd9Sstevel@tonic-gate /* 19127c478bd9Sstevel@tonic-gate * When printing memory, show the total as physmem less 19137c478bd9Sstevel@tonic-gate * that stolen by a debugger. 19147c478bd9Sstevel@tonic-gate */ 19157c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?mem = %ldK (0x%lx000)\n", 19167c478bd9Sstevel@tonic-gate (ulong_t)(physinstalled) << (PAGESHIFT - 10), 19177c478bd9Sstevel@tonic-gate (ulong_t)(physinstalled) << (PAGESHIFT - 12)); 19187c478bd9Sstevel@tonic-gate 19197c478bd9Sstevel@tonic-gate avmem = (uint64_t)freemem << PAGESHIFT; 19207c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?avail mem = %lld\n", (unsigned long long)avmem); 19217c478bd9Sstevel@tonic-gate 1922ec25b48fSsusans /* 1923ec25b48fSsusans * For small memory systems disable automatic large pages. 1924ec25b48fSsusans */ 1925ec25b48fSsusans if (physmem < privm_lpg_min_physmem) { 1926beb1bda0Sdavemq use_brk_lpg = 0; 1927beb1bda0Sdavemq use_stk_lpg = 0; 1928beb1bda0Sdavemq } 1929beb1bda0Sdavemq 19307c478bd9Sstevel@tonic-gate /* 19317c478bd9Sstevel@tonic-gate * Perform platform specific freelist processing 19327c478bd9Sstevel@tonic-gate */ 19337c478bd9Sstevel@tonic-gate if (&plat_freelist_process) { 19347c478bd9Sstevel@tonic-gate for (mnode = 0; mnode < max_mem_nodes; mnode++) 19357c478bd9Sstevel@tonic-gate if (mem_node_config[mnode].exists) 19367c478bd9Sstevel@tonic-gate plat_freelist_process(mnode); 19377c478bd9Sstevel@tonic-gate } 19387c478bd9Sstevel@tonic-gate 19397c478bd9Sstevel@tonic-gate /* 19407c478bd9Sstevel@tonic-gate * Initialize the segkp segment type. We position it 19417c478bd9Sstevel@tonic-gate * after the configured tables and buffers (whose end 19427c478bd9Sstevel@tonic-gate * is given by econtig) and before V_WKBASE_ADDR. 19437c478bd9Sstevel@tonic-gate * Also in this area is segkmap (size SEGMAPSIZE). 19447c478bd9Sstevel@tonic-gate */ 19457c478bd9Sstevel@tonic-gate 19467c478bd9Sstevel@tonic-gate /* XXX - cache alignment? */ 19477c478bd9Sstevel@tonic-gate va = (caddr_t)SEGKPBASE; 19487c478bd9Sstevel@tonic-gate ASSERT(((uintptr_t)va & PAGEOFFSET) == 0); 19497c478bd9Sstevel@tonic-gate 19507c478bd9Sstevel@tonic-gate max_phys_segkp = (physmem * 2); 19517c478bd9Sstevel@tonic-gate 19527c478bd9Sstevel@tonic-gate if (segkpsize < btop(SEGKPMINSIZE) || segkpsize > btop(SEGKPMAXSIZE)) { 19537c478bd9Sstevel@tonic-gate segkpsize = btop(SEGKPDEFSIZE); 19547c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Illegal value for segkpsize. " 19557c478bd9Sstevel@tonic-gate "segkpsize has been reset to %ld pages", segkpsize); 19567c478bd9Sstevel@tonic-gate } 19577c478bd9Sstevel@tonic-gate 19587c478bd9Sstevel@tonic-gate i = ptob(MIN(segkpsize, max_phys_segkp)); 19597c478bd9Sstevel@tonic-gate 19607c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER); 19617c478bd9Sstevel@tonic-gate if (seg_attach(&kas, va, i, segkp) < 0) 19627c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "startup: cannot attach segkp"); 19637c478bd9Sstevel@tonic-gate if (segkp_create(segkp) != 0) 19647c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "startup: segkp_create failed"); 19657c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock); 19667c478bd9Sstevel@tonic-gate 19677c478bd9Sstevel@tonic-gate /* 19687c478bd9Sstevel@tonic-gate * kpm segment 19697c478bd9Sstevel@tonic-gate */ 19707c478bd9Sstevel@tonic-gate segmap_kpm = kpm_enable && 19717c478bd9Sstevel@tonic-gate segmap_kpm && PAGESIZE == MAXBSIZE; 19727c478bd9Sstevel@tonic-gate 19737c478bd9Sstevel@tonic-gate if (kpm_enable) { 19747c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER); 19757c478bd9Sstevel@tonic-gate 19767c478bd9Sstevel@tonic-gate /* 19777c478bd9Sstevel@tonic-gate * The segkpm virtual range range is larger than the 19787c478bd9Sstevel@tonic-gate * actual physical memory size and also covers gaps in 19797c478bd9Sstevel@tonic-gate * the physical address range for the following reasons: 19807c478bd9Sstevel@tonic-gate * . keep conversion between segkpm and physical addresses 19817c478bd9Sstevel@tonic-gate * simple, cheap and unambiguous. 19827c478bd9Sstevel@tonic-gate * . avoid extension/shrink of the the segkpm in case of DR. 19837c478bd9Sstevel@tonic-gate * . avoid complexity for handling of virtual addressed 19847c478bd9Sstevel@tonic-gate * caches, segkpm and the regular mapping scheme must be 19857c478bd9Sstevel@tonic-gate * kept in sync wrt. the virtual color of mapped pages. 19867c478bd9Sstevel@tonic-gate * Any accesses to virtual segkpm ranges not backed by 19877c478bd9Sstevel@tonic-gate * physical memory will fall through the memseg pfn hash 19887c478bd9Sstevel@tonic-gate * and will be handled in segkpm_fault. 19897c478bd9Sstevel@tonic-gate * Additional kpm_size spaces needed for vac alias prevention. 19907c478bd9Sstevel@tonic-gate */ 19917c478bd9Sstevel@tonic-gate if (seg_attach(&kas, kpm_vbase, kpm_size * vac_colors, 19927c478bd9Sstevel@tonic-gate segkpm) < 0) 19937c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "cannot attach segkpm"); 19947c478bd9Sstevel@tonic-gate 19957c478bd9Sstevel@tonic-gate b.prot = PROT_READ | PROT_WRITE; 19967c478bd9Sstevel@tonic-gate b.nvcolors = shm_alignment >> MMU_PAGESHIFT; 19977c478bd9Sstevel@tonic-gate 19987c478bd9Sstevel@tonic-gate if (segkpm_create(segkpm, (caddr_t)&b) != 0) 19997c478bd9Sstevel@tonic-gate panic("segkpm_create segkpm"); 20007c478bd9Sstevel@tonic-gate 20017c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock); 2002fedab560Sae112802 2003fedab560Sae112802 mach_kpm_init(); 20047c478bd9Sstevel@tonic-gate } 20057c478bd9Sstevel@tonic-gate 20069853d9e8SJason Beloro va = kpm_vbase + (kpm_size * vac_colors); 20079853d9e8SJason Beloro 2008ad23a2dbSjohansen if (!segzio_fromheap) { 2009ad23a2dbSjohansen size_t size; 2010a778305aSjohansen size_t physmem_b = mmu_ptob(physmem); 2011ad23a2dbSjohansen 2012ad23a2dbSjohansen /* size is in bytes, segziosize is in pages */ 2013ad23a2dbSjohansen if (segziosize == 0) { 2014a778305aSjohansen size = physmem_b; 2015ad23a2dbSjohansen } else { 2016ad23a2dbSjohansen size = mmu_ptob(segziosize); 2017ad23a2dbSjohansen } 2018ad23a2dbSjohansen 2019ad23a2dbSjohansen if (size < SEGZIOMINSIZE) { 2020ad23a2dbSjohansen size = SEGZIOMINSIZE; 2021a778305aSjohansen } else if (size > SEGZIOMAXSIZE) { 2022a778305aSjohansen size = SEGZIOMAXSIZE; 2023a778305aSjohansen /* 2024a778305aSjohansen * On 64-bit x86, we only have 2TB of KVA. This exists 2025a778305aSjohansen * for parity with x86. 2026a778305aSjohansen * 2027a778305aSjohansen * SEGZIOMAXSIZE is capped at 512gb so that segzio 2028a778305aSjohansen * doesn't consume all of KVA. However, if we have a 2029a778305aSjohansen * system that has more thant 512gb of physical memory, 2030a778305aSjohansen * we can actually consume about half of the difference 2031a778305aSjohansen * between 512gb and the rest of the available physical 2032a778305aSjohansen * memory. 2033a778305aSjohansen */ 2034a778305aSjohansen if (physmem_b > SEGZIOMAXSIZE) { 2035a778305aSjohansen size += (physmem_b - SEGZIOMAXSIZE) / 2; 2036a778305aSjohansen } 2037ad23a2dbSjohansen } 2038ad23a2dbSjohansen segziosize = mmu_btop(roundup(size, MMU_PAGESIZE)); 2039ad23a2dbSjohansen /* put the base of the ZIO segment after the kpm segment */ 20409853d9e8SJason Beloro segzio_base = va; 20419853d9e8SJason Beloro va += mmu_ptob(segziosize); 2042ad23a2dbSjohansen PRM_DEBUG(segziosize); 2043ad23a2dbSjohansen PRM_DEBUG(segzio_base); 2044ad23a2dbSjohansen 2045ad23a2dbSjohansen /* 2046ad23a2dbSjohansen * On some platforms, kvm_init is called after the kpm 2047ad23a2dbSjohansen * sizes have been determined. On SPARC, kvm_init is called 2048ad23a2dbSjohansen * before, so we have to attach the kzioseg after kvm is 2049ad23a2dbSjohansen * initialized, otherwise we'll try to allocate from the boot 2050ad23a2dbSjohansen * area since the kernel heap hasn't yet been configured. 2051ad23a2dbSjohansen */ 2052ad23a2dbSjohansen rw_enter(&kas.a_lock, RW_WRITER); 2053ad23a2dbSjohansen 2054ad23a2dbSjohansen (void) seg_attach(&kas, segzio_base, mmu_ptob(segziosize), 2055ad23a2dbSjohansen &kzioseg); 2056ad23a2dbSjohansen (void) segkmem_zio_create(&kzioseg); 2057ad23a2dbSjohansen 2058ad23a2dbSjohansen /* create zio area covering new segment */ 2059ad23a2dbSjohansen segkmem_zio_init(segzio_base, mmu_ptob(segziosize)); 2060ad23a2dbSjohansen 2061ad23a2dbSjohansen rw_exit(&kas.a_lock); 2062ad23a2dbSjohansen } 2063ad23a2dbSjohansen 20649853d9e8SJason Beloro if (ppvm_enable) { 20659853d9e8SJason Beloro caddr_t ppvm_max; 20669853d9e8SJason Beloro 20679853d9e8SJason Beloro /* 20689853d9e8SJason Beloro * ppvm refers to the static VA space used to map 20699853d9e8SJason Beloro * the page_t's for dynamically added memory. 20709853d9e8SJason Beloro * 20719853d9e8SJason Beloro * ppvm_base should not cross a potential VA hole. 20729853d9e8SJason Beloro * 20739853d9e8SJason Beloro * ppvm_size should be large enough to map the 20749853d9e8SJason Beloro * page_t's needed to manage all of KPM range. 20759853d9e8SJason Beloro */ 20769853d9e8SJason Beloro ppvm_size = 20779853d9e8SJason Beloro roundup(mmu_btop(kpm_size * vac_colors) * sizeof (page_t), 20789853d9e8SJason Beloro MMU_PAGESIZE); 20799853d9e8SJason Beloro ppvm_max = (caddr_t)(0ull - ppvm_size); 20809853d9e8SJason Beloro ppvm_base = (page_t *)va; 20819853d9e8SJason Beloro 20829853d9e8SJason Beloro if ((caddr_t)ppvm_base <= hole_end) { 20839853d9e8SJason Beloro cmn_err(CE_WARN, 20849853d9e8SJason Beloro "Memory DR disabled: invalid DR map base: 0x%p\n", 20859853d9e8SJason Beloro (void *)ppvm_base); 20869853d9e8SJason Beloro ppvm_enable = 0; 20879853d9e8SJason Beloro } else if ((caddr_t)ppvm_base > ppvm_max) { 20889853d9e8SJason Beloro uint64_t diff = (caddr_t)ppvm_base - ppvm_max; 20899853d9e8SJason Beloro 20909853d9e8SJason Beloro cmn_err(CE_WARN, 20919853d9e8SJason Beloro "Memory DR disabled: insufficient DR map size:" 20929853d9e8SJason Beloro " 0x%lx (needed 0x%lx)\n", 20939853d9e8SJason Beloro ppvm_size - diff, ppvm_size); 20949853d9e8SJason Beloro ppvm_enable = 0; 20959853d9e8SJason Beloro } 20969853d9e8SJason Beloro PRM_DEBUG(ppvm_size); 20979853d9e8SJason Beloro PRM_DEBUG(ppvm_base); 20989853d9e8SJason Beloro } 2099ad23a2dbSjohansen 21007c478bd9Sstevel@tonic-gate /* 21017c478bd9Sstevel@tonic-gate * Now create generic mapping segment. This mapping 21027c478bd9Sstevel@tonic-gate * goes SEGMAPSIZE beyond SEGMAPBASE. But if the total 21037c478bd9Sstevel@tonic-gate * virtual address is greater than the amount of free 21047c478bd9Sstevel@tonic-gate * memory that is available, then we trim back the 21057c478bd9Sstevel@tonic-gate * segment size to that amount 21067c478bd9Sstevel@tonic-gate */ 21077c478bd9Sstevel@tonic-gate va = (caddr_t)SEGMAPBASE; 21087c478bd9Sstevel@tonic-gate 21097c478bd9Sstevel@tonic-gate /* 21107c478bd9Sstevel@tonic-gate * 1201049: segkmap base address must be MAXBSIZE aligned 21117c478bd9Sstevel@tonic-gate */ 21127c478bd9Sstevel@tonic-gate ASSERT(((uintptr_t)va & MAXBOFFSET) == 0); 21137c478bd9Sstevel@tonic-gate 21147c478bd9Sstevel@tonic-gate /* 21157c478bd9Sstevel@tonic-gate * Set size of segmap to percentage of freemem at boot, 21167c478bd9Sstevel@tonic-gate * but stay within the allowable range 21177c478bd9Sstevel@tonic-gate * Note we take percentage before converting from pages 21187c478bd9Sstevel@tonic-gate * to bytes to avoid an overflow on 32-bit kernels. 21197c478bd9Sstevel@tonic-gate */ 21207c478bd9Sstevel@tonic-gate i = mmu_ptob((freemem * segmap_percent) / 100); 21217c478bd9Sstevel@tonic-gate 21227c478bd9Sstevel@tonic-gate if (i < MINMAPSIZE) 21237c478bd9Sstevel@tonic-gate i = MINMAPSIZE; 21247c478bd9Sstevel@tonic-gate 21257c478bd9Sstevel@tonic-gate if (i > MIN(SEGMAPSIZE, mmu_ptob(freemem))) 21267c478bd9Sstevel@tonic-gate i = MIN(SEGMAPSIZE, mmu_ptob(freemem)); 21277c478bd9Sstevel@tonic-gate 21287c478bd9Sstevel@tonic-gate i &= MAXBMASK; /* 1201049: segkmap size must be MAXBSIZE aligned */ 21297c478bd9Sstevel@tonic-gate 21307c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER); 21317c478bd9Sstevel@tonic-gate if (seg_attach(&kas, va, i, segkmap) < 0) 21327c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "cannot attach segkmap"); 21337c478bd9Sstevel@tonic-gate 21347c478bd9Sstevel@tonic-gate a.prot = PROT_READ | PROT_WRITE; 21357c478bd9Sstevel@tonic-gate a.shmsize = shm_alignment; 21367c478bd9Sstevel@tonic-gate a.nfreelist = 0; /* use segmap driver defaults */ 21377c478bd9Sstevel@tonic-gate 21387c478bd9Sstevel@tonic-gate if (segmap_create(segkmap, (caddr_t)&a) != 0) 21397c478bd9Sstevel@tonic-gate panic("segmap_create segkmap"); 21407c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock); 21417c478bd9Sstevel@tonic-gate 21427c478bd9Sstevel@tonic-gate segdev_init(); 21437c478bd9Sstevel@tonic-gate } 21447c478bd9Sstevel@tonic-gate 21457c478bd9Sstevel@tonic-gate static void 21467c478bd9Sstevel@tonic-gate startup_end(void) 21477c478bd9Sstevel@tonic-gate { 21487c478bd9Sstevel@tonic-gate if ((caddr_t)memlist > (caddr_t)memlist_end) 21497c478bd9Sstevel@tonic-gate panic("memlist overflow 2"); 21507c478bd9Sstevel@tonic-gate memlist_free_block((caddr_t)memlist, 21517c478bd9Sstevel@tonic-gate ((caddr_t)memlist_end - (caddr_t)memlist)); 21527c478bd9Sstevel@tonic-gate memlist = NULL; 21537c478bd9Sstevel@tonic-gate 21547c478bd9Sstevel@tonic-gate /* enable page_relocation since OBP is now done */ 21557c478bd9Sstevel@tonic-gate page_relocate_ready = 1; 21567c478bd9Sstevel@tonic-gate 21577c478bd9Sstevel@tonic-gate /* 21587c478bd9Sstevel@tonic-gate * Perform tasks that get done after most of the VM 21597c478bd9Sstevel@tonic-gate * initialization has been done but before the clock 21607c478bd9Sstevel@tonic-gate * and other devices get started. 21617c478bd9Sstevel@tonic-gate */ 21627c478bd9Sstevel@tonic-gate kern_setup1(); 21637c478bd9Sstevel@tonic-gate 21647c478bd9Sstevel@tonic-gate /* 2165b9e93c10SJonathan Haslam * Perform CPC initialization for this CPU. 2166b9e93c10SJonathan Haslam */ 2167b9e93c10SJonathan Haslam kcpc_hw_init(); 2168b9e93c10SJonathan Haslam 2169b9e93c10SJonathan Haslam /* 21707c478bd9Sstevel@tonic-gate * Intialize the VM arenas for allocating physically 21717c478bd9Sstevel@tonic-gate * contiguus memory chunk for interrupt queues snd 21727c478bd9Sstevel@tonic-gate * allocate/register boot cpu's queues, if any and 21737c478bd9Sstevel@tonic-gate * allocate dump buffer for sun4v systems to store 21747c478bd9Sstevel@tonic-gate * extra crash information during crash dump 21757c478bd9Sstevel@tonic-gate */ 21767c478bd9Sstevel@tonic-gate contig_mem_init(); 21777c478bd9Sstevel@tonic-gate mach_descrip_init(); 2178982b9107Sjb145095 2179982b9107Sjb145095 if (cpu_intrq_setup(CPU)) { 2180982b9107Sjb145095 cmn_err(CE_PANIC, "cpu%d: setup failed", CPU->cpu_id); 2181982b9107Sjb145095 } 21827c478bd9Sstevel@tonic-gate cpu_intrq_register(CPU); 2183db6d2ee3Ssvemuri mach_htraptrace_setup(CPU->cpu_id); 2184db6d2ee3Ssvemuri mach_htraptrace_configure(CPU->cpu_id); 21857c478bd9Sstevel@tonic-gate mach_dump_buffer_init(); 21867c478bd9Sstevel@tonic-gate 21877c478bd9Sstevel@tonic-gate /* 21887c478bd9Sstevel@tonic-gate * Initialize interrupt related stuff 21897c478bd9Sstevel@tonic-gate */ 2190100b72f4Sandrei cpu_intr_alloc(CPU, NINTR_THREADS); 21917c478bd9Sstevel@tonic-gate 21927c478bd9Sstevel@tonic-gate (void) splzs(); /* allow hi clock ints but not zs */ 21937c478bd9Sstevel@tonic-gate 21947c478bd9Sstevel@tonic-gate /* 21957c478bd9Sstevel@tonic-gate * Initialize errors. 21967c478bd9Sstevel@tonic-gate */ 21977c478bd9Sstevel@tonic-gate error_init(); 21987c478bd9Sstevel@tonic-gate 21997c478bd9Sstevel@tonic-gate /* 22007c478bd9Sstevel@tonic-gate * Note that we may have already used kernel bcopy before this 22017c478bd9Sstevel@tonic-gate * point - but if you really care about this, adb the use_hw_* 22027c478bd9Sstevel@tonic-gate * variables to 0 before rebooting. 22037c478bd9Sstevel@tonic-gate */ 22047c478bd9Sstevel@tonic-gate mach_hw_copy_limit(); 22057c478bd9Sstevel@tonic-gate 22067c478bd9Sstevel@tonic-gate /* 22077c478bd9Sstevel@tonic-gate * Install the "real" preemption guards before DDI services 22087c478bd9Sstevel@tonic-gate * are available. 22097c478bd9Sstevel@tonic-gate */ 22107c478bd9Sstevel@tonic-gate (void) prom_set_preprom(kern_preprom); 22117c478bd9Sstevel@tonic-gate (void) prom_set_postprom(kern_postprom); 22127c478bd9Sstevel@tonic-gate CPU->cpu_m.mutex_ready = 1; 22137c478bd9Sstevel@tonic-gate 22147c478bd9Sstevel@tonic-gate /* 22157c478bd9Sstevel@tonic-gate * Initialize segnf (kernel support for non-faulting loads). 22167c478bd9Sstevel@tonic-gate */ 22177c478bd9Sstevel@tonic-gate segnf_init(); 22187c478bd9Sstevel@tonic-gate 22197c478bd9Sstevel@tonic-gate /* 22207c478bd9Sstevel@tonic-gate * Configure the root devinfo node. 22217c478bd9Sstevel@tonic-gate */ 22227c478bd9Sstevel@tonic-gate configure(); /* set up devices */ 22237c478bd9Sstevel@tonic-gate mach_cpu_halt_idle(); 22247c478bd9Sstevel@tonic-gate } 22257c478bd9Sstevel@tonic-gate 22267c478bd9Sstevel@tonic-gate 22277c478bd9Sstevel@tonic-gate void 22287c478bd9Sstevel@tonic-gate post_startup(void) 22297c478bd9Sstevel@tonic-gate { 22307c478bd9Sstevel@tonic-gate #ifdef PTL1_PANIC_DEBUG 22317c478bd9Sstevel@tonic-gate extern void init_ptl1_thread(void); 22327c478bd9Sstevel@tonic-gate #endif /* PTL1_PANIC_DEBUG */ 22337c478bd9Sstevel@tonic-gate extern void abort_sequence_init(void); 22347c478bd9Sstevel@tonic-gate 22357c478bd9Sstevel@tonic-gate /* 22367c478bd9Sstevel@tonic-gate * Set the system wide, processor-specific flags to be passed 22377c478bd9Sstevel@tonic-gate * to userland via the aux vector for performance hints and 22387c478bd9Sstevel@tonic-gate * instruction set extensions. 22397c478bd9Sstevel@tonic-gate */ 22407c478bd9Sstevel@tonic-gate bind_hwcap(); 22417c478bd9Sstevel@tonic-gate 22427c478bd9Sstevel@tonic-gate /* 22437c478bd9Sstevel@tonic-gate * Startup memory scrubber (if any) 22447c478bd9Sstevel@tonic-gate */ 22457c478bd9Sstevel@tonic-gate mach_memscrub(); 22467c478bd9Sstevel@tonic-gate 22477c478bd9Sstevel@tonic-gate /* 22487c478bd9Sstevel@tonic-gate * Allocate soft interrupt to handle abort sequence. 22497c478bd9Sstevel@tonic-gate */ 22507c478bd9Sstevel@tonic-gate abort_sequence_init(); 22517c478bd9Sstevel@tonic-gate 22527c478bd9Sstevel@tonic-gate /* 22537c478bd9Sstevel@tonic-gate * Configure the rest of the system. 22547c478bd9Sstevel@tonic-gate * Perform forceloading tasks for /etc/system. 22557c478bd9Sstevel@tonic-gate */ 22567c478bd9Sstevel@tonic-gate (void) mod_sysctl(SYS_FORCELOAD, NULL); 22577c478bd9Sstevel@tonic-gate /* 22587c478bd9Sstevel@tonic-gate * ON4.0: Force /proc module in until clock interrupt handle fixed 22597c478bd9Sstevel@tonic-gate * ON4.0: This must be fixed or restated in /etc/systems. 22607c478bd9Sstevel@tonic-gate */ 22617c478bd9Sstevel@tonic-gate (void) modload("fs", "procfs"); 22627c478bd9Sstevel@tonic-gate 22631ae08745Sheppo /* load machine class specific drivers */ 22641ae08745Sheppo load_mach_drivers(); 22651ae08745Sheppo 22661ae08745Sheppo /* load platform specific drivers */ 22677c478bd9Sstevel@tonic-gate if (&load_platform_drivers) 22687c478bd9Sstevel@tonic-gate load_platform_drivers(); 22697c478bd9Sstevel@tonic-gate 22707c478bd9Sstevel@tonic-gate /* load vis simulation module, if we are running w/fpu off */ 22717c478bd9Sstevel@tonic-gate if (!fpu_exists) { 22727c478bd9Sstevel@tonic-gate if (modload("misc", "vis") == -1) 22737c478bd9Sstevel@tonic-gate halt("Can't load vis"); 22747c478bd9Sstevel@tonic-gate } 22757c478bd9Sstevel@tonic-gate 22767c478bd9Sstevel@tonic-gate mach_fpras(); 22777c478bd9Sstevel@tonic-gate 22787c478bd9Sstevel@tonic-gate maxmem = freemem; 22797c478bd9Sstevel@tonic-gate 22800e751525SEric Saxe pg_init(); 22810e751525SEric Saxe 22827c478bd9Sstevel@tonic-gate #ifdef PTL1_PANIC_DEBUG 22837c478bd9Sstevel@tonic-gate init_ptl1_thread(); 22847c478bd9Sstevel@tonic-gate #endif /* PTL1_PANIC_DEBUG */ 22857c478bd9Sstevel@tonic-gate } 22867c478bd9Sstevel@tonic-gate 22877c478bd9Sstevel@tonic-gate #ifdef PTL1_PANIC_DEBUG 22887c478bd9Sstevel@tonic-gate int ptl1_panic_test = 0; 22897c478bd9Sstevel@tonic-gate int ptl1_panic_xc_one_test = 0; 22907c478bd9Sstevel@tonic-gate int ptl1_panic_xc_all_test = 0; 22917c478bd9Sstevel@tonic-gate int ptl1_panic_xt_one_test = 0; 22927c478bd9Sstevel@tonic-gate int ptl1_panic_xt_all_test = 0; 22937c478bd9Sstevel@tonic-gate kthread_id_t ptl1_thread_p = NULL; 22947c478bd9Sstevel@tonic-gate kcondvar_t ptl1_cv; 22957c478bd9Sstevel@tonic-gate kmutex_t ptl1_mutex; 22967c478bd9Sstevel@tonic-gate int ptl1_recurse_count_threshold = 0x40; 22977c478bd9Sstevel@tonic-gate int ptl1_recurse_trap_threshold = 0x3d; 22987c478bd9Sstevel@tonic-gate extern void ptl1_recurse(int, int); 22997c478bd9Sstevel@tonic-gate extern void ptl1_panic_xt(int, int); 23007c478bd9Sstevel@tonic-gate 23017c478bd9Sstevel@tonic-gate /* 23027c478bd9Sstevel@tonic-gate * Called once per second by timeout() to wake up 23037c478bd9Sstevel@tonic-gate * the ptl1_panic thread to see if it should cause 23047c478bd9Sstevel@tonic-gate * a trap to the ptl1_panic() code. 23057c478bd9Sstevel@tonic-gate */ 23067c478bd9Sstevel@tonic-gate /* ARGSUSED */ 23077c478bd9Sstevel@tonic-gate static void 23087c478bd9Sstevel@tonic-gate ptl1_wakeup(void *arg) 23097c478bd9Sstevel@tonic-gate { 23107c478bd9Sstevel@tonic-gate mutex_enter(&ptl1_mutex); 23117c478bd9Sstevel@tonic-gate cv_signal(&ptl1_cv); 23127c478bd9Sstevel@tonic-gate mutex_exit(&ptl1_mutex); 23137c478bd9Sstevel@tonic-gate } 23147c478bd9Sstevel@tonic-gate 23157c478bd9Sstevel@tonic-gate /* 23167c478bd9Sstevel@tonic-gate * ptl1_panic cross call function: 23177c478bd9Sstevel@tonic-gate * Needed because xc_one() and xc_some() can pass 23187c478bd9Sstevel@tonic-gate * 64 bit args but ptl1_recurse() expects ints. 23197c478bd9Sstevel@tonic-gate */ 23207c478bd9Sstevel@tonic-gate static void 23217c478bd9Sstevel@tonic-gate ptl1_panic_xc(void) 23227c478bd9Sstevel@tonic-gate { 23237c478bd9Sstevel@tonic-gate ptl1_recurse(ptl1_recurse_count_threshold, 23247c478bd9Sstevel@tonic-gate ptl1_recurse_trap_threshold); 23257c478bd9Sstevel@tonic-gate } 23267c478bd9Sstevel@tonic-gate 23277c478bd9Sstevel@tonic-gate /* 23287c478bd9Sstevel@tonic-gate * The ptl1 thread waits for a global flag to be set 23297c478bd9Sstevel@tonic-gate * and uses the recurse thresholds to set the stack depth 23307c478bd9Sstevel@tonic-gate * to cause a ptl1_panic() directly via a call to ptl1_recurse 23317c478bd9Sstevel@tonic-gate * or indirectly via the cross call and cross trap functions. 23327c478bd9Sstevel@tonic-gate * 23337c478bd9Sstevel@tonic-gate * This is useful testing stack overflows and normal 23347c478bd9Sstevel@tonic-gate * ptl1_panic() states with a know stack frame. 23357c478bd9Sstevel@tonic-gate * 23367c478bd9Sstevel@tonic-gate * ptl1_recurse() is an asm function in ptl1_panic.s that 23377c478bd9Sstevel@tonic-gate * sets the {In, Local, Out, and Global} registers to a 23387c478bd9Sstevel@tonic-gate * know state on the stack and just prior to causing a 23397c478bd9Sstevel@tonic-gate * test ptl1_panic trap. 23407c478bd9Sstevel@tonic-gate */ 23417c478bd9Sstevel@tonic-gate static void 23427c478bd9Sstevel@tonic-gate ptl1_thread(void) 23437c478bd9Sstevel@tonic-gate { 23447c478bd9Sstevel@tonic-gate mutex_enter(&ptl1_mutex); 23457c478bd9Sstevel@tonic-gate while (ptl1_thread_p) { 23467c478bd9Sstevel@tonic-gate cpuset_t other_cpus; 23477c478bd9Sstevel@tonic-gate int cpu_id; 23487c478bd9Sstevel@tonic-gate int my_cpu_id; 23497c478bd9Sstevel@tonic-gate int target_cpu_id; 23507c478bd9Sstevel@tonic-gate int target_found; 23517c478bd9Sstevel@tonic-gate 23527c478bd9Sstevel@tonic-gate if (ptl1_panic_test) { 23537c478bd9Sstevel@tonic-gate ptl1_recurse(ptl1_recurse_count_threshold, 23547c478bd9Sstevel@tonic-gate ptl1_recurse_trap_threshold); 23557c478bd9Sstevel@tonic-gate } 23567c478bd9Sstevel@tonic-gate 23577c478bd9Sstevel@tonic-gate /* 23587c478bd9Sstevel@tonic-gate * Find potential targets for x-call and x-trap, 23597c478bd9Sstevel@tonic-gate * if any exist while preempt is disabled we 23607c478bd9Sstevel@tonic-gate * start a ptl1_panic if requested via a 23617c478bd9Sstevel@tonic-gate * globals. 23627c478bd9Sstevel@tonic-gate */ 23637c478bd9Sstevel@tonic-gate kpreempt_disable(); 23647c478bd9Sstevel@tonic-gate my_cpu_id = CPU->cpu_id; 23657c478bd9Sstevel@tonic-gate other_cpus = cpu_ready_set; 23667c478bd9Sstevel@tonic-gate CPUSET_DEL(other_cpus, CPU->cpu_id); 23677c478bd9Sstevel@tonic-gate target_found = 0; 23687c478bd9Sstevel@tonic-gate if (!CPUSET_ISNULL(other_cpus)) { 23697c478bd9Sstevel@tonic-gate /* 23707c478bd9Sstevel@tonic-gate * Pick the first one 23717c478bd9Sstevel@tonic-gate */ 23727c478bd9Sstevel@tonic-gate for (cpu_id = 0; cpu_id < NCPU; cpu_id++) { 23737c478bd9Sstevel@tonic-gate if (cpu_id == my_cpu_id) 23747c478bd9Sstevel@tonic-gate continue; 23757c478bd9Sstevel@tonic-gate 23767c478bd9Sstevel@tonic-gate if (CPU_XCALL_READY(cpu_id)) { 23777c478bd9Sstevel@tonic-gate target_cpu_id = cpu_id; 23787c478bd9Sstevel@tonic-gate target_found = 1; 23797c478bd9Sstevel@tonic-gate break; 23807c478bd9Sstevel@tonic-gate } 23817c478bd9Sstevel@tonic-gate } 23827c478bd9Sstevel@tonic-gate ASSERT(target_found); 23837c478bd9Sstevel@tonic-gate 23847c478bd9Sstevel@tonic-gate if (ptl1_panic_xc_one_test) { 23857c478bd9Sstevel@tonic-gate xc_one(target_cpu_id, 23867c478bd9Sstevel@tonic-gate (xcfunc_t *)ptl1_panic_xc, 0, 0); 23877c478bd9Sstevel@tonic-gate } 23887c478bd9Sstevel@tonic-gate if (ptl1_panic_xc_all_test) { 23897c478bd9Sstevel@tonic-gate xc_some(other_cpus, 23907c478bd9Sstevel@tonic-gate (xcfunc_t *)ptl1_panic_xc, 0, 0); 23917c478bd9Sstevel@tonic-gate } 23927c478bd9Sstevel@tonic-gate if (ptl1_panic_xt_one_test) { 23937c478bd9Sstevel@tonic-gate xt_one(target_cpu_id, 23947c478bd9Sstevel@tonic-gate (xcfunc_t *)ptl1_panic_xt, 0, 0); 23957c478bd9Sstevel@tonic-gate } 23967c478bd9Sstevel@tonic-gate if (ptl1_panic_xt_all_test) { 23977c478bd9Sstevel@tonic-gate xt_some(other_cpus, 23987c478bd9Sstevel@tonic-gate (xcfunc_t *)ptl1_panic_xt, 0, 0); 23997c478bd9Sstevel@tonic-gate } 24007c478bd9Sstevel@tonic-gate } 24017c478bd9Sstevel@tonic-gate kpreempt_enable(); 24027c478bd9Sstevel@tonic-gate (void) timeout(ptl1_wakeup, NULL, hz); 24037c478bd9Sstevel@tonic-gate (void) cv_wait(&ptl1_cv, &ptl1_mutex); 24047c478bd9Sstevel@tonic-gate } 24057c478bd9Sstevel@tonic-gate mutex_exit(&ptl1_mutex); 24067c478bd9Sstevel@tonic-gate } 24077c478bd9Sstevel@tonic-gate 24087c478bd9Sstevel@tonic-gate /* 24097c478bd9Sstevel@tonic-gate * Called during early startup to create the ptl1_thread 24107c478bd9Sstevel@tonic-gate */ 24117c478bd9Sstevel@tonic-gate void 24127c478bd9Sstevel@tonic-gate init_ptl1_thread(void) 24137c478bd9Sstevel@tonic-gate { 24147c478bd9Sstevel@tonic-gate ptl1_thread_p = thread_create(NULL, 0, ptl1_thread, NULL, 0, 24157c478bd9Sstevel@tonic-gate &p0, TS_RUN, 0); 24167c478bd9Sstevel@tonic-gate } 24177c478bd9Sstevel@tonic-gate #endif /* PTL1_PANIC_DEBUG */ 24187c478bd9Sstevel@tonic-gate 24197c478bd9Sstevel@tonic-gate 2420986fd29aSsetje static void 2421986fd29aSsetje memlist_new(uint64_t start, uint64_t len, struct memlist **memlistp) 2422986fd29aSsetje { 2423986fd29aSsetje struct memlist *new; 2424986fd29aSsetje 2425986fd29aSsetje new = *memlistp; 242656f33205SJonathan Adams new->ml_address = start; 242756f33205SJonathan Adams new->ml_size = len; 2428986fd29aSsetje *memlistp = new + 1; 2429986fd29aSsetje } 2430986fd29aSsetje 24317c478bd9Sstevel@tonic-gate /* 24327c478bd9Sstevel@tonic-gate * Add to a memory list. 24337c478bd9Sstevel@tonic-gate * start = start of new memory segment 24347c478bd9Sstevel@tonic-gate * len = length of new memory segment in bytes 24357c478bd9Sstevel@tonic-gate * memlistp = pointer to array of available memory segment structures 24367c478bd9Sstevel@tonic-gate * curmemlistp = memory list to which to add segment. 24377c478bd9Sstevel@tonic-gate */ 24387c478bd9Sstevel@tonic-gate static void 24397c478bd9Sstevel@tonic-gate memlist_add(uint64_t start, uint64_t len, struct memlist **memlistp, 24407c478bd9Sstevel@tonic-gate struct memlist **curmemlistp) 24417c478bd9Sstevel@tonic-gate { 2442986fd29aSsetje struct memlist *new = *memlistp; 24437c478bd9Sstevel@tonic-gate 2444986fd29aSsetje memlist_new(start, len, memlistp); 24457c478bd9Sstevel@tonic-gate memlist_insert(new, curmemlistp); 24467c478bd9Sstevel@tonic-gate } 24477c478bd9Sstevel@tonic-gate 2448986fd29aSsetje static int 2449986fd29aSsetje ndata_alloc_memseg(struct memlist *ndata, size_t avail) 2450986fd29aSsetje { 2451986fd29aSsetje int nseg; 2452986fd29aSsetje size_t memseg_sz; 2453986fd29aSsetje struct memseg *msp; 2454986fd29aSsetje 2455986fd29aSsetje /* 2456986fd29aSsetje * The memseg list is for the chunks of physical memory that 2457986fd29aSsetje * will be managed by the vm system. The number calculated is 2458986fd29aSsetje * a guess as boot may fragment it more when memory allocations 2459986fd29aSsetje * are made before kphysm_init(). 2460986fd29aSsetje */ 2461986fd29aSsetje memseg_sz = (avail + 10) * sizeof (struct memseg); 2462986fd29aSsetje memseg_sz = roundup(memseg_sz, PAGESIZE); 2463986fd29aSsetje nseg = memseg_sz / sizeof (struct memseg); 2464986fd29aSsetje msp = ndata_alloc(ndata, memseg_sz, ecache_alignsize); 2465986fd29aSsetje if (msp == NULL) 2466986fd29aSsetje return (1); 2467986fd29aSsetje PRM_DEBUG(memseg_free); 2468986fd29aSsetje 2469986fd29aSsetje while (nseg--) { 2470986fd29aSsetje msp->next = memseg_free; 2471986fd29aSsetje memseg_free = msp; 2472986fd29aSsetje msp++; 2473986fd29aSsetje } 2474986fd29aSsetje return (0); 2475986fd29aSsetje } 2476986fd29aSsetje 24777c478bd9Sstevel@tonic-gate /* 24787c478bd9Sstevel@tonic-gate * In the case of architectures that support dynamic addition of 24797c478bd9Sstevel@tonic-gate * memory at run-time there are two cases where memsegs need to 24807c478bd9Sstevel@tonic-gate * be initialized and added to the memseg list. 24817c478bd9Sstevel@tonic-gate * 1) memsegs that are constructed at startup. 24827c478bd9Sstevel@tonic-gate * 2) memsegs that are constructed at run-time on 24837c478bd9Sstevel@tonic-gate * hot-plug capable architectures. 24847c478bd9Sstevel@tonic-gate * This code was originally part of the function kphysm_init(). 24857c478bd9Sstevel@tonic-gate */ 24867c478bd9Sstevel@tonic-gate 24877c478bd9Sstevel@tonic-gate static void 24887c478bd9Sstevel@tonic-gate memseg_list_add(struct memseg *memsegp) 24897c478bd9Sstevel@tonic-gate { 24907c478bd9Sstevel@tonic-gate struct memseg **prev_memsegp; 24917c478bd9Sstevel@tonic-gate pgcnt_t num; 24927c478bd9Sstevel@tonic-gate 24937c478bd9Sstevel@tonic-gate /* insert in memseg list, decreasing number of pages order */ 24947c478bd9Sstevel@tonic-gate 24957c478bd9Sstevel@tonic-gate num = MSEG_NPAGES(memsegp); 24967c478bd9Sstevel@tonic-gate 24977c478bd9Sstevel@tonic-gate for (prev_memsegp = &memsegs; *prev_memsegp; 24987c478bd9Sstevel@tonic-gate prev_memsegp = &((*prev_memsegp)->next)) { 24997c478bd9Sstevel@tonic-gate if (num > MSEG_NPAGES(*prev_memsegp)) 25007c478bd9Sstevel@tonic-gate break; 25017c478bd9Sstevel@tonic-gate } 25027c478bd9Sstevel@tonic-gate 25037c478bd9Sstevel@tonic-gate memsegp->next = *prev_memsegp; 25047c478bd9Sstevel@tonic-gate *prev_memsegp = memsegp; 25057c478bd9Sstevel@tonic-gate 25067c478bd9Sstevel@tonic-gate if (kpm_enable) { 25077c478bd9Sstevel@tonic-gate memsegp->nextpa = (memsegp->next) ? 25087c478bd9Sstevel@tonic-gate va_to_pa(memsegp->next) : MSEG_NULLPTR_PA; 25097c478bd9Sstevel@tonic-gate 25107c478bd9Sstevel@tonic-gate if (prev_memsegp != &memsegs) { 25117c478bd9Sstevel@tonic-gate struct memseg *msp; 25127c478bd9Sstevel@tonic-gate msp = (struct memseg *)((caddr_t)prev_memsegp - 25137c478bd9Sstevel@tonic-gate offsetof(struct memseg, next)); 25147c478bd9Sstevel@tonic-gate msp->nextpa = va_to_pa(memsegp); 25157c478bd9Sstevel@tonic-gate } else { 25167c478bd9Sstevel@tonic-gate memsegspa = va_to_pa(memsegs); 25177c478bd9Sstevel@tonic-gate } 25187c478bd9Sstevel@tonic-gate } 25197c478bd9Sstevel@tonic-gate } 25207c478bd9Sstevel@tonic-gate 25217c478bd9Sstevel@tonic-gate /* 25227c478bd9Sstevel@tonic-gate * PSM add_physmem_cb(). US-II and newer processors have some 25237c478bd9Sstevel@tonic-gate * flavor of the prefetch capability implemented. We exploit 25247c478bd9Sstevel@tonic-gate * this capability for optimum performance. 25257c478bd9Sstevel@tonic-gate */ 25267c478bd9Sstevel@tonic-gate #define PREFETCH_BYTES 64 25277c478bd9Sstevel@tonic-gate 25287c478bd9Sstevel@tonic-gate void 25297c478bd9Sstevel@tonic-gate add_physmem_cb(page_t *pp, pfn_t pnum) 25307c478bd9Sstevel@tonic-gate { 25317c478bd9Sstevel@tonic-gate extern void prefetch_page_w(void *); 25327c478bd9Sstevel@tonic-gate 25337c478bd9Sstevel@tonic-gate pp->p_pagenum = pnum; 25347c478bd9Sstevel@tonic-gate 25357c478bd9Sstevel@tonic-gate /* 25367c478bd9Sstevel@tonic-gate * Prefetch one more page_t into E$. To prevent future 25377c478bd9Sstevel@tonic-gate * mishaps with the sizeof(page_t) changing on us, we 25387c478bd9Sstevel@tonic-gate * catch this on debug kernels if we can't bring in the 25397c478bd9Sstevel@tonic-gate * entire hpage with 2 PREFETCH_BYTES reads. See 25407c478bd9Sstevel@tonic-gate * also, sun4u/cpu/cpu_module.c 25417c478bd9Sstevel@tonic-gate */ 25427c478bd9Sstevel@tonic-gate /*LINTED*/ 25437c478bd9Sstevel@tonic-gate ASSERT(sizeof (page_t) <= 2*PREFETCH_BYTES); 25447c478bd9Sstevel@tonic-gate prefetch_page_w((char *)pp); 25457c478bd9Sstevel@tonic-gate } 25467c478bd9Sstevel@tonic-gate 25477c478bd9Sstevel@tonic-gate /* 2548986fd29aSsetje * Find memseg with given pfn 2549986fd29aSsetje */ 2550986fd29aSsetje static struct memseg * 2551986fd29aSsetje memseg_find(pfn_t base, pfn_t *next) 2552986fd29aSsetje { 2553986fd29aSsetje struct memseg *seg; 2554986fd29aSsetje 2555986fd29aSsetje if (next != NULL) 2556986fd29aSsetje *next = LONG_MAX; 2557986fd29aSsetje for (seg = memsegs; seg != NULL; seg = seg->next) { 2558986fd29aSsetje if (base >= seg->pages_base && base < seg->pages_end) 2559986fd29aSsetje return (seg); 2560986fd29aSsetje if (next != NULL && seg->pages_base > base && 2561986fd29aSsetje seg->pages_base < *next) 2562986fd29aSsetje *next = seg->pages_base; 2563986fd29aSsetje } 2564986fd29aSsetje return (NULL); 2565986fd29aSsetje } 2566986fd29aSsetje 2567986fd29aSsetje /* 2568986fd29aSsetje * Put page allocated by OBP on prom_ppages 25697c478bd9Sstevel@tonic-gate */ 25707c478bd9Sstevel@tonic-gate static void 2571986fd29aSsetje kphysm_erase(uint64_t addr, uint64_t len) 25727c478bd9Sstevel@tonic-gate { 2573986fd29aSsetje struct page *pp; 2574986fd29aSsetje struct memseg *seg; 2575986fd29aSsetje pfn_t base = btop(addr), next; 2576986fd29aSsetje pgcnt_t num = btop(len); 25777c478bd9Sstevel@tonic-gate 2578986fd29aSsetje while (num != 0) { 2579986fd29aSsetje pgcnt_t off, left; 25807c478bd9Sstevel@tonic-gate 2581986fd29aSsetje seg = memseg_find(base, &next); 2582986fd29aSsetje if (seg == NULL) { 2583986fd29aSsetje if (next == LONG_MAX) 2584986fd29aSsetje break; 2585986fd29aSsetje left = MIN(next - base, num); 2586986fd29aSsetje base += left, num -= left; 2587986fd29aSsetje continue; 2588986fd29aSsetje } 2589986fd29aSsetje off = base - seg->pages_base; 2590986fd29aSsetje pp = seg->pages + off; 2591986fd29aSsetje left = num - MIN(num, (seg->pages_end - seg->pages_base) - off); 2592986fd29aSsetje while (num != left) { 2593986fd29aSsetje /* 2594986fd29aSsetje * init it, lock it, and hashin on prom_pages vp. 2595986fd29aSsetje * 25969853d9e8SJason Beloro * Mark it as NONRELOC to let DR know the page 25979853d9e8SJason Beloro * is locked long term, otherwise DR hangs when 25989853d9e8SJason Beloro * trying to remove those pages. 25999853d9e8SJason Beloro * 2600986fd29aSsetje * XXX vnode offsets on the prom_ppages vnode 2601986fd29aSsetje * are page numbers (gack) for >32 bit 2602986fd29aSsetje * physical memory machines. 2603986fd29aSsetje */ 26049853d9e8SJason Beloro PP_SETNORELOC(pp); 2605986fd29aSsetje add_physmem_cb(pp, base); 2606986fd29aSsetje if (page_trylock(pp, SE_EXCL) == 0) 2607986fd29aSsetje cmn_err(CE_PANIC, "prom page locked"); 2608af4c679fSSean McEnroe (void) page_hashin(pp, &promvp, 2609986fd29aSsetje (offset_t)base, NULL); 2610986fd29aSsetje (void) page_pp_lock(pp, 0, 1); 2611986fd29aSsetje pp++, base++, num--; 2612986fd29aSsetje } 2613986fd29aSsetje } 2614986fd29aSsetje } 2615986fd29aSsetje 2616986fd29aSsetje static page_t *ppnext; 2617986fd29aSsetje static pgcnt_t ppleft; 2618986fd29aSsetje 2619986fd29aSsetje static void *kpm_ppnext; 2620986fd29aSsetje static pgcnt_t kpm_ppleft; 26217c478bd9Sstevel@tonic-gate 26227c478bd9Sstevel@tonic-gate /* 2623986fd29aSsetje * Create a memseg 26247c478bd9Sstevel@tonic-gate */ 2625986fd29aSsetje static void 2626986fd29aSsetje kphysm_memseg(uint64_t addr, uint64_t len) 2627986fd29aSsetje { 2628986fd29aSsetje pfn_t base = btop(addr); 2629986fd29aSsetje pgcnt_t num = btop(len); 2630986fd29aSsetje struct memseg *seg; 26317c478bd9Sstevel@tonic-gate 2632986fd29aSsetje seg = memseg_free; 2633986fd29aSsetje memseg_free = seg->next; 2634986fd29aSsetje ASSERT(seg != NULL); 2635986fd29aSsetje 2636986fd29aSsetje seg->pages = ppnext; 2637986fd29aSsetje seg->epages = ppnext + num; 2638986fd29aSsetje seg->pages_base = base; 2639986fd29aSsetje seg->pages_end = base + num; 2640986fd29aSsetje ppnext += num; 2641986fd29aSsetje ppleft -= num; 26427c478bd9Sstevel@tonic-gate 26437c478bd9Sstevel@tonic-gate if (kpm_enable) { 2644986fd29aSsetje pgcnt_t kpnum = ptokpmpr(num); 26457c478bd9Sstevel@tonic-gate 2646986fd29aSsetje if (kpnum > kpm_ppleft) 2647986fd29aSsetje panic("kphysm_memseg: kpm_pp overflow"); 2648986fd29aSsetje seg->pagespa = va_to_pa(seg->pages); 2649986fd29aSsetje seg->epagespa = va_to_pa(seg->epages); 2650986fd29aSsetje seg->kpm_pbase = kpmptop(ptokpmp(base)); 2651986fd29aSsetje seg->kpm_nkpmpgs = kpnum; 26527c478bd9Sstevel@tonic-gate /* 2653986fd29aSsetje * In the kpm_smallpage case, the kpm array 2654986fd29aSsetje * is 1-1 wrt the page array 26557c478bd9Sstevel@tonic-gate */ 2656986fd29aSsetje if (kpm_smallpages) { 2657986fd29aSsetje kpm_spage_t *kpm_pp = kpm_ppnext; 26587c478bd9Sstevel@tonic-gate 2659986fd29aSsetje kpm_ppnext = kpm_pp + kpnum; 2660986fd29aSsetje seg->kpm_spages = kpm_pp; 2661986fd29aSsetje seg->kpm_pagespa = va_to_pa(seg->kpm_spages); 2662986fd29aSsetje } else { 2663986fd29aSsetje kpm_page_t *kpm_pp = kpm_ppnext; 2664986fd29aSsetje 2665986fd29aSsetje kpm_ppnext = kpm_pp + kpnum; 2666986fd29aSsetje seg->kpm_pages = kpm_pp; 2667986fd29aSsetje seg->kpm_pagespa = va_to_pa(seg->kpm_pages); 2668986fd29aSsetje /* ASSERT no kpm overlaps */ 2669986fd29aSsetje ASSERT( 2670986fd29aSsetje memseg_find(base - pmodkpmp(base), NULL) == NULL); 2671986fd29aSsetje ASSERT(memseg_find( 2672986fd29aSsetje roundup(base + num, kpmpnpgs) - 1, NULL) == NULL); 2673986fd29aSsetje } 26749853d9e8SJason Beloro kpm_ppleft -= kpnum; 2675986fd29aSsetje } 2676986fd29aSsetje 2677986fd29aSsetje memseg_list_add(seg); 2678986fd29aSsetje } 2679986fd29aSsetje 26807c478bd9Sstevel@tonic-gate /* 2681986fd29aSsetje * Add range to free list 26827c478bd9Sstevel@tonic-gate */ 2683986fd29aSsetje void 2684986fd29aSsetje kphysm_add(uint64_t addr, uint64_t len, int reclaim) 2685986fd29aSsetje { 2686986fd29aSsetje struct page *pp; 2687986fd29aSsetje struct memseg *seg; 2688986fd29aSsetje pfn_t base = btop(addr); 2689986fd29aSsetje pgcnt_t num = btop(len); 26907c478bd9Sstevel@tonic-gate 2691986fd29aSsetje seg = memseg_find(base, NULL); 2692986fd29aSsetje ASSERT(seg != NULL); 2693986fd29aSsetje pp = seg->pages + (base - seg->pages_base); 26947c478bd9Sstevel@tonic-gate 2695986fd29aSsetje if (reclaim) { 2696986fd29aSsetje struct page *rpp = pp; 2697986fd29aSsetje struct page *lpp = pp + num; 26987c478bd9Sstevel@tonic-gate 2699986fd29aSsetje /* 2700986fd29aSsetje * page should be locked on prom_ppages 2701986fd29aSsetje * unhash and unlock it 2702986fd29aSsetje */ 2703986fd29aSsetje while (rpp < lpp) { 2704af4c679fSSean McEnroe ASSERT(PAGE_EXCL(rpp) && rpp->p_vnode == &promvp); 27059853d9e8SJason Beloro ASSERT(PP_ISNORELOC(rpp)); 27069853d9e8SJason Beloro PP_CLRNORELOC(rpp); 2707986fd29aSsetje page_pp_unlock(rpp, 0, 1); 2708986fd29aSsetje page_hashout(rpp, NULL); 2709986fd29aSsetje page_unlock(rpp); 2710986fd29aSsetje rpp++; 27117c478bd9Sstevel@tonic-gate } 2712986fd29aSsetje } 27137c478bd9Sstevel@tonic-gate 27147c478bd9Sstevel@tonic-gate /* 27157c478bd9Sstevel@tonic-gate * add_physmem() initializes the PSM part of the page 27167c478bd9Sstevel@tonic-gate * struct by calling the PSM back with add_physmem_cb(). 27177c478bd9Sstevel@tonic-gate * In addition it coalesces pages into larger pages as 27187c478bd9Sstevel@tonic-gate * it initializes them. 27197c478bd9Sstevel@tonic-gate */ 27207c478bd9Sstevel@tonic-gate add_physmem(pp, num, base); 27217c478bd9Sstevel@tonic-gate } 27227c478bd9Sstevel@tonic-gate 2723986fd29aSsetje /* 2724986fd29aSsetje * kphysm_init() tackles the problem of initializing physical memory. 2725986fd29aSsetje */ 2726986fd29aSsetje static void 2727986fd29aSsetje kphysm_init(void) 2728986fd29aSsetje { 2729986fd29aSsetje struct memlist *pmem; 2730986fd29aSsetje 2731986fd29aSsetje ASSERT(page_hash != NULL && page_hashsz != 0); 2732986fd29aSsetje 2733986fd29aSsetje ppnext = pp_base; 2734986fd29aSsetje ppleft = npages; 2735986fd29aSsetje kpm_ppnext = kpm_pp_base; 2736986fd29aSsetje kpm_ppleft = kpm_npages; 2737986fd29aSsetje 2738986fd29aSsetje /* 2739986fd29aSsetje * installed pages not on nopp_memlist go in memseg list 2740986fd29aSsetje */ 2741986fd29aSsetje diff_memlists(phys_install, nopp_list, kphysm_memseg); 2742986fd29aSsetje 2743986fd29aSsetje /* 2744986fd29aSsetje * Free the avail list 2745986fd29aSsetje */ 274656f33205SJonathan Adams for (pmem = phys_avail; pmem != NULL; pmem = pmem->ml_next) 274756f33205SJonathan Adams kphysm_add(pmem->ml_address, pmem->ml_size, 0); 2748986fd29aSsetje 2749986fd29aSsetje /* 2750986fd29aSsetje * Erase pages that aren't available 2751986fd29aSsetje */ 2752986fd29aSsetje diff_memlists(phys_install, phys_avail, kphysm_erase); 2753986fd29aSsetje 27547c478bd9Sstevel@tonic-gate build_pfn_hash(); 27557c478bd9Sstevel@tonic-gate } 27567c478bd9Sstevel@tonic-gate 27577c478bd9Sstevel@tonic-gate /* 27587c478bd9Sstevel@tonic-gate * Kernel VM initialization. 27597c478bd9Sstevel@tonic-gate * Assumptions about kernel address space ordering: 27607c478bd9Sstevel@tonic-gate * (1) gap (user space) 27617c478bd9Sstevel@tonic-gate * (2) kernel text 27627c478bd9Sstevel@tonic-gate * (3) kernel data/bss 27637c478bd9Sstevel@tonic-gate * (4) gap 27647c478bd9Sstevel@tonic-gate * (5) kernel data structures 27657c478bd9Sstevel@tonic-gate * (6) gap 27667c478bd9Sstevel@tonic-gate * (7) debugger (optional) 27677c478bd9Sstevel@tonic-gate * (8) monitor 27687c478bd9Sstevel@tonic-gate * (9) gap (possibly null) 27697c478bd9Sstevel@tonic-gate * (10) dvma 27707c478bd9Sstevel@tonic-gate * (11) devices 27717c478bd9Sstevel@tonic-gate */ 27727c478bd9Sstevel@tonic-gate static void 27737c478bd9Sstevel@tonic-gate kvm_init(void) 27747c478bd9Sstevel@tonic-gate { 27757c478bd9Sstevel@tonic-gate /* 27767c478bd9Sstevel@tonic-gate * Put the kernel segments in kernel address space. 27777c478bd9Sstevel@tonic-gate */ 27787c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER); 27797c478bd9Sstevel@tonic-gate as_avlinit(&kas); 27807c478bd9Sstevel@tonic-gate 27817c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, (caddr_t)KERNELBASE, 27827c478bd9Sstevel@tonic-gate (size_t)(e_moddata - KERNELBASE), &ktextseg); 27837c478bd9Sstevel@tonic-gate (void) segkmem_create(&ktextseg); 27847c478bd9Sstevel@tonic-gate 27857c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, (caddr_t)(KERNELBASE + MMU_PAGESIZE4M), 27867c478bd9Sstevel@tonic-gate (size_t)(MMU_PAGESIZE4M), &ktexthole); 27877c478bd9Sstevel@tonic-gate (void) segkmem_create(&ktexthole); 27887c478bd9Sstevel@tonic-gate 27897c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, (caddr_t)valloc_base, 27907c478bd9Sstevel@tonic-gate (size_t)(econtig32 - valloc_base), &kvalloc); 27917c478bd9Sstevel@tonic-gate (void) segkmem_create(&kvalloc); 27927c478bd9Sstevel@tonic-gate 27937c478bd9Sstevel@tonic-gate if (kmem64_base) { 27947c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, (caddr_t)kmem64_base, 27957c478bd9Sstevel@tonic-gate (size_t)(kmem64_end - kmem64_base), &kmem64); 27967c478bd9Sstevel@tonic-gate (void) segkmem_create(&kmem64); 27977c478bd9Sstevel@tonic-gate } 27987c478bd9Sstevel@tonic-gate 27997c478bd9Sstevel@tonic-gate /* 28007c478bd9Sstevel@tonic-gate * We're about to map out /boot. This is the beginning of the 28017c478bd9Sstevel@tonic-gate * system resource management transition. We can no longer 28027c478bd9Sstevel@tonic-gate * call into /boot for I/O or memory allocations. 28037c478bd9Sstevel@tonic-gate */ 28047c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, kernelheap, ekernelheap - kernelheap, &kvseg); 28057c478bd9Sstevel@tonic-gate (void) segkmem_create(&kvseg); 28067c478bd9Sstevel@tonic-gate hblk_alloc_dynamic = 1; 28077c478bd9Sstevel@tonic-gate 28087c478bd9Sstevel@tonic-gate /* 28097c478bd9Sstevel@tonic-gate * we need to preallocate pages for DR operations before enabling large 28107c478bd9Sstevel@tonic-gate * page kernel heap because of memseg_remap_init() hat_unload() hack. 28117c478bd9Sstevel@tonic-gate */ 28127c478bd9Sstevel@tonic-gate memseg_remap_init(); 28137c478bd9Sstevel@tonic-gate 28147c478bd9Sstevel@tonic-gate /* at this point we are ready to use large page heap */ 28157c478bd9Sstevel@tonic-gate segkmem_heap_lp_init(); 28167c478bd9Sstevel@tonic-gate 28177c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, (caddr_t)SYSBASE32, SYSLIMIT32 - SYSBASE32, 28187c478bd9Sstevel@tonic-gate &kvseg32); 28197c478bd9Sstevel@tonic-gate (void) segkmem_create(&kvseg32); 28207c478bd9Sstevel@tonic-gate 28217c478bd9Sstevel@tonic-gate /* 28227c478bd9Sstevel@tonic-gate * Create a segment for the debugger. 28237c478bd9Sstevel@tonic-gate */ 2824ae115bc7Smrj (void) seg_attach(&kas, kdi_segdebugbase, kdi_segdebugsize, &kdebugseg); 28257c478bd9Sstevel@tonic-gate (void) segkmem_create(&kdebugseg); 28267c478bd9Sstevel@tonic-gate 28277c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock); 28287c478bd9Sstevel@tonic-gate } 28297c478bd9Sstevel@tonic-gate 28307c478bd9Sstevel@tonic-gate char obp_tte_str[] = 28317c478bd9Sstevel@tonic-gate "h# %x constant MMU_PAGESHIFT " 28327c478bd9Sstevel@tonic-gate "h# %x constant TTE8K " 28337c478bd9Sstevel@tonic-gate "h# %x constant SFHME_SIZE " 28347c478bd9Sstevel@tonic-gate "h# %x constant SFHME_TTE " 28357c478bd9Sstevel@tonic-gate "h# %x constant HMEBLK_TAG " 28367c478bd9Sstevel@tonic-gate "h# %x constant HMEBLK_NEXT " 28377c478bd9Sstevel@tonic-gate "h# %x constant HMEBLK_MISC " 28387c478bd9Sstevel@tonic-gate "h# %x constant HMEBLK_HME1 " 28397c478bd9Sstevel@tonic-gate "h# %x constant NHMENTS " 28407c478bd9Sstevel@tonic-gate "h# %x constant HBLK_SZMASK " 28417c478bd9Sstevel@tonic-gate "h# %x constant HBLK_RANGE_SHIFT " 28427c478bd9Sstevel@tonic-gate "h# %x constant HMEBP_HBLK " 28430a90a7fdSAmritpal Sandhu "h# %x constant HMEBLK_ENDPA " 28447c478bd9Sstevel@tonic-gate "h# %x constant HMEBUCKET_SIZE " 28457c478bd9Sstevel@tonic-gate "h# %x constant HTAG_SFMMUPSZ " 284605d3dc4bSpaulsan "h# %x constant HTAG_BSPAGE_SHIFT " 284705d3dc4bSpaulsan "h# %x constant HTAG_REHASH_SHIFT " 284805d3dc4bSpaulsan "h# %x constant SFMMU_INVALID_SHMERID " 28497c478bd9Sstevel@tonic-gate "h# %x constant mmu_hashcnt " 28507c478bd9Sstevel@tonic-gate "h# %p constant uhme_hash " 28517c478bd9Sstevel@tonic-gate "h# %p constant khme_hash " 28527c478bd9Sstevel@tonic-gate "h# %x constant UHMEHASH_SZ " 28537c478bd9Sstevel@tonic-gate "h# %x constant KHMEHASH_SZ " 28541e2e7a75Shuah "h# %p constant KCONTEXT " 28557c478bd9Sstevel@tonic-gate "h# %p constant KHATID " 28567c478bd9Sstevel@tonic-gate "h# %x constant ASI_MEM " 28577c478bd9Sstevel@tonic-gate 28587c478bd9Sstevel@tonic-gate ": PHYS-X@ ( phys -- data ) " 28597c478bd9Sstevel@tonic-gate " ASI_MEM spacex@ " 28607c478bd9Sstevel@tonic-gate "; " 28617c478bd9Sstevel@tonic-gate 28627c478bd9Sstevel@tonic-gate ": PHYS-W@ ( phys -- data ) " 28637c478bd9Sstevel@tonic-gate " ASI_MEM spacew@ " 28647c478bd9Sstevel@tonic-gate "; " 28657c478bd9Sstevel@tonic-gate 28667c478bd9Sstevel@tonic-gate ": PHYS-L@ ( phys -- data ) " 28677c478bd9Sstevel@tonic-gate " ASI_MEM spaceL@ " 28687c478bd9Sstevel@tonic-gate "; " 28697c478bd9Sstevel@tonic-gate 28707c478bd9Sstevel@tonic-gate ": TTE_PAGE_SHIFT ( ttesz -- hmeshift ) " 28717c478bd9Sstevel@tonic-gate " 3 * MMU_PAGESHIFT + " 28727c478bd9Sstevel@tonic-gate "; " 28737c478bd9Sstevel@tonic-gate 28747c478bd9Sstevel@tonic-gate ": TTE_IS_VALID ( ttep -- flag ) " 28757c478bd9Sstevel@tonic-gate " PHYS-X@ 0< " 28767c478bd9Sstevel@tonic-gate "; " 28777c478bd9Sstevel@tonic-gate 28787c478bd9Sstevel@tonic-gate ": HME_HASH_SHIFT ( ttesz -- hmeshift ) " 28797c478bd9Sstevel@tonic-gate " dup TTE8K = if " 28807c478bd9Sstevel@tonic-gate " drop HBLK_RANGE_SHIFT " 28817c478bd9Sstevel@tonic-gate " else " 28827c478bd9Sstevel@tonic-gate " TTE_PAGE_SHIFT " 28837c478bd9Sstevel@tonic-gate " then " 28847c478bd9Sstevel@tonic-gate "; " 28857c478bd9Sstevel@tonic-gate 28867c478bd9Sstevel@tonic-gate ": HME_HASH_BSPAGE ( addr hmeshift -- bspage ) " 28877c478bd9Sstevel@tonic-gate " tuck >> swap MMU_PAGESHIFT - << " 28887c478bd9Sstevel@tonic-gate "; " 28897c478bd9Sstevel@tonic-gate 28907c478bd9Sstevel@tonic-gate ": HME_HASH_FUNCTION ( sfmmup addr hmeshift -- hmebp ) " 28917c478bd9Sstevel@tonic-gate " >> over xor swap ( hash sfmmup ) " 28927c478bd9Sstevel@tonic-gate " KHATID <> if ( hash ) " 28937c478bd9Sstevel@tonic-gate " UHMEHASH_SZ and ( bucket ) " 28947c478bd9Sstevel@tonic-gate " HMEBUCKET_SIZE * uhme_hash + ( hmebp ) " 28957c478bd9Sstevel@tonic-gate " else ( hash ) " 28967c478bd9Sstevel@tonic-gate " KHMEHASH_SZ and ( bucket ) " 28977c478bd9Sstevel@tonic-gate " HMEBUCKET_SIZE * khme_hash + ( hmebp ) " 28987c478bd9Sstevel@tonic-gate " then ( hmebp ) " 28997c478bd9Sstevel@tonic-gate "; " 29007c478bd9Sstevel@tonic-gate 29017c478bd9Sstevel@tonic-gate ": HME_HASH_TABLE_SEARCH " 29027c478bd9Sstevel@tonic-gate " ( sfmmup hmebp hblktag -- sfmmup null | sfmmup hmeblkp ) " 29037c478bd9Sstevel@tonic-gate " >r hmebp_hblk + phys-x@ begin ( sfmmup hmeblkp ) ( r: hblktag ) " 29040a90a7fdSAmritpal Sandhu " dup HMEBLK_ENDPA <> if ( sfmmup hmeblkp ) ( r: hblktag ) " 29057c478bd9Sstevel@tonic-gate " dup hmeblk_tag + phys-x@ r@ = if ( sfmmup hmeblkp ) " 29067c478bd9Sstevel@tonic-gate " dup hmeblk_tag + 8 + phys-x@ 2 pick = if " 29077c478bd9Sstevel@tonic-gate " true ( sfmmup hmeblkp true ) ( r: hblktag ) " 29087c478bd9Sstevel@tonic-gate " else " 29097c478bd9Sstevel@tonic-gate " hmeblk_next + phys-x@ false " 29107c478bd9Sstevel@tonic-gate " ( sfmmup hmeblkp false ) ( r: hblktag ) " 29117c478bd9Sstevel@tonic-gate " then " 29127c478bd9Sstevel@tonic-gate " else " 29137c478bd9Sstevel@tonic-gate " hmeblk_next + phys-x@ false " 29147c478bd9Sstevel@tonic-gate " ( sfmmup hmeblkp false ) ( r: hblktag ) " 29157c478bd9Sstevel@tonic-gate " then " 29167c478bd9Sstevel@tonic-gate " else " 29170a90a7fdSAmritpal Sandhu " drop 0 true " 29187c478bd9Sstevel@tonic-gate " then " 29197c478bd9Sstevel@tonic-gate " until r> drop " 29207c478bd9Sstevel@tonic-gate "; " 29217c478bd9Sstevel@tonic-gate 29227c478bd9Sstevel@tonic-gate ": HME_HASH_TAG ( sfmmup rehash addr -- hblktag ) " 29237c478bd9Sstevel@tonic-gate " over HME_HASH_SHIFT HME_HASH_BSPAGE ( sfmmup rehash bspage ) " 292405d3dc4bSpaulsan " HTAG_BSPAGE_SHIFT << ( sfmmup rehash htag-bspage )" 292505d3dc4bSpaulsan " swap HTAG_REHASH_SHIFT << or ( sfmmup htag-bspage-rehash )" 292605d3dc4bSpaulsan " SFMMU_INVALID_SHMERID or nip ( hblktag ) " 29277c478bd9Sstevel@tonic-gate "; " 29287c478bd9Sstevel@tonic-gate 29297c478bd9Sstevel@tonic-gate ": HBLK_TO_TTEP ( hmeblkp addr -- ttep ) " 29307c478bd9Sstevel@tonic-gate " over HMEBLK_MISC + PHYS-L@ HBLK_SZMASK and ( hmeblkp addr ttesz ) " 29317c478bd9Sstevel@tonic-gate " TTE8K = if ( hmeblkp addr ) " 29327c478bd9Sstevel@tonic-gate " MMU_PAGESHIFT >> NHMENTS 1- and ( hmeblkp hme-index ) " 29337c478bd9Sstevel@tonic-gate " else ( hmeblkp addr ) " 29347c478bd9Sstevel@tonic-gate " drop 0 ( hmeblkp 0 ) " 29357c478bd9Sstevel@tonic-gate " then ( hmeblkp hme-index ) " 29367c478bd9Sstevel@tonic-gate " SFHME_SIZE * + HMEBLK_HME1 + ( hmep ) " 29377c478bd9Sstevel@tonic-gate " SFHME_TTE + ( ttep ) " 29387c478bd9Sstevel@tonic-gate "; " 29397c478bd9Sstevel@tonic-gate 29407c478bd9Sstevel@tonic-gate ": unix-tte ( addr cnum -- false | tte-data true ) " 29411e2e7a75Shuah " KCONTEXT = if ( addr ) " 29421e2e7a75Shuah " KHATID ( addr khatid ) " 29431e2e7a75Shuah " else ( addr ) " 29441e2e7a75Shuah " drop false exit ( false ) " 29451e2e7a75Shuah " then " 29461e2e7a75Shuah " ( addr khatid ) " 29477c478bd9Sstevel@tonic-gate " mmu_hashcnt 1+ 1 do ( addr sfmmup ) " 29487c478bd9Sstevel@tonic-gate " 2dup swap i HME_HASH_SHIFT " 29497c478bd9Sstevel@tonic-gate "( addr sfmmup sfmmup addr hmeshift ) " 29507c478bd9Sstevel@tonic-gate " HME_HASH_FUNCTION ( addr sfmmup hmebp ) " 29517c478bd9Sstevel@tonic-gate " over i 4 pick " 29527c478bd9Sstevel@tonic-gate "( addr sfmmup hmebp sfmmup rehash addr ) " 29537c478bd9Sstevel@tonic-gate " HME_HASH_TAG ( addr sfmmup hmebp hblktag ) " 29547c478bd9Sstevel@tonic-gate " HME_HASH_TABLE_SEARCH " 29557c478bd9Sstevel@tonic-gate "( addr sfmmup { null | hmeblkp } ) " 29567c478bd9Sstevel@tonic-gate " ?dup if ( addr sfmmup hmeblkp ) " 29577c478bd9Sstevel@tonic-gate " nip swap HBLK_TO_TTEP ( ttep ) " 29587c478bd9Sstevel@tonic-gate " dup TTE_IS_VALID if ( valid-ttep ) " 29599d0d62adSJason Beloro " PHYS-X@ true ( tte-data true ) " 29607c478bd9Sstevel@tonic-gate " else ( invalid-tte ) " 29617c478bd9Sstevel@tonic-gate " drop false ( false ) " 29627c478bd9Sstevel@tonic-gate " then ( false | tte-data true ) " 29637c478bd9Sstevel@tonic-gate " unloop exit ( false | tte-data true ) " 29647c478bd9Sstevel@tonic-gate " then ( addr sfmmup ) " 29657c478bd9Sstevel@tonic-gate " loop ( addr sfmmup ) " 29667c478bd9Sstevel@tonic-gate " 2drop false ( false ) " 29677c478bd9Sstevel@tonic-gate "; " 29687c478bd9Sstevel@tonic-gate ; 29697c478bd9Sstevel@tonic-gate 29707c478bd9Sstevel@tonic-gate void 29717c478bd9Sstevel@tonic-gate create_va_to_tte(void) 29727c478bd9Sstevel@tonic-gate { 29737c478bd9Sstevel@tonic-gate char *bp; 29747c478bd9Sstevel@tonic-gate extern int khmehash_num, uhmehash_num; 29757c478bd9Sstevel@tonic-gate extern struct hmehash_bucket *khme_hash, *uhme_hash; 29767c478bd9Sstevel@tonic-gate 29777c478bd9Sstevel@tonic-gate #define OFFSET(type, field) ((uintptr_t)(&((type *)0)->field)) 29787c478bd9Sstevel@tonic-gate 29797c478bd9Sstevel@tonic-gate bp = (char *)kobj_zalloc(MMU_PAGESIZE, KM_SLEEP); 29807c478bd9Sstevel@tonic-gate 29817c478bd9Sstevel@tonic-gate /* 29827c478bd9Sstevel@tonic-gate * Teach obp how to parse our sw ttes. 29837c478bd9Sstevel@tonic-gate */ 29847c478bd9Sstevel@tonic-gate (void) sprintf(bp, obp_tte_str, 29857c478bd9Sstevel@tonic-gate MMU_PAGESHIFT, 29867c478bd9Sstevel@tonic-gate TTE8K, 29877c478bd9Sstevel@tonic-gate sizeof (struct sf_hment), 29887c478bd9Sstevel@tonic-gate OFFSET(struct sf_hment, hme_tte), 29897c478bd9Sstevel@tonic-gate OFFSET(struct hme_blk, hblk_tag), 29907c478bd9Sstevel@tonic-gate OFFSET(struct hme_blk, hblk_nextpa), 29917c478bd9Sstevel@tonic-gate OFFSET(struct hme_blk, hblk_misc), 29927c478bd9Sstevel@tonic-gate OFFSET(struct hme_blk, hblk_hme), 29937c478bd9Sstevel@tonic-gate NHMENTS, 29947c478bd9Sstevel@tonic-gate HBLK_SZMASK, 29957c478bd9Sstevel@tonic-gate HBLK_RANGE_SHIFT, 29967c478bd9Sstevel@tonic-gate OFFSET(struct hmehash_bucket, hmeh_nextpa), 29970a90a7fdSAmritpal Sandhu HMEBLK_ENDPA, 29987c478bd9Sstevel@tonic-gate sizeof (struct hmehash_bucket), 29997c478bd9Sstevel@tonic-gate HTAG_SFMMUPSZ, 300005d3dc4bSpaulsan HTAG_BSPAGE_SHIFT, 300105d3dc4bSpaulsan HTAG_REHASH_SHIFT, 300205d3dc4bSpaulsan SFMMU_INVALID_SHMERID, 30037c478bd9Sstevel@tonic-gate mmu_hashcnt, 30047c478bd9Sstevel@tonic-gate (caddr_t)va_to_pa((caddr_t)uhme_hash), 30057c478bd9Sstevel@tonic-gate (caddr_t)va_to_pa((caddr_t)khme_hash), 30067c478bd9Sstevel@tonic-gate UHMEHASH_SZ, 30077c478bd9Sstevel@tonic-gate KHMEHASH_SZ, 30081e2e7a75Shuah KCONTEXT, 30097c478bd9Sstevel@tonic-gate KHATID, 30109d0d62adSJason Beloro ASI_MEM); 30117c478bd9Sstevel@tonic-gate prom_interpret(bp, 0, 0, 0, 0, 0); 30127c478bd9Sstevel@tonic-gate 30137c478bd9Sstevel@tonic-gate kobj_free(bp, MMU_PAGESIZE); 30147c478bd9Sstevel@tonic-gate } 30157c478bd9Sstevel@tonic-gate 30167c478bd9Sstevel@tonic-gate void 30177c478bd9Sstevel@tonic-gate install_va_to_tte(void) 30187c478bd9Sstevel@tonic-gate { 30197c478bd9Sstevel@tonic-gate /* 30207c478bd9Sstevel@tonic-gate * advise prom that he can use unix-tte 30217c478bd9Sstevel@tonic-gate */ 30227c478bd9Sstevel@tonic-gate prom_interpret("' unix-tte is va>tte-data", 0, 0, 0, 0, 0); 30237c478bd9Sstevel@tonic-gate } 30247c478bd9Sstevel@tonic-gate 3025fea9cb91Slq150181 /* 30262d7b546fSlq150181 * Here we add "device-type=console" for /os-io node, for currently 30272d7b546fSlq150181 * our kernel console output only supports displaying text and 30282d7b546fSlq150181 * performing cursor-positioning operations (through kernel framebuffer 30292d7b546fSlq150181 * driver) and it doesn't support other functionalities required for a 30302d7b546fSlq150181 * standard "display" device as specified in 1275 spec. The main missing 30312d7b546fSlq150181 * interface defined by the 1275 spec is "draw-logo". 30322d7b546fSlq150181 * also see the comments above prom_stdout_is_framebuffer(). 3033fea9cb91Slq150181 */ 30347c478bd9Sstevel@tonic-gate static char *create_node = 303512ef07e9Slq150181 "\" /\" find-device " 30367c478bd9Sstevel@tonic-gate "new-device " 30377c478bd9Sstevel@tonic-gate "\" os-io\" device-name " 30382d7b546fSlq150181 "\" "OBP_DISPLAY_CONSOLE"\" device-type " 30397c478bd9Sstevel@tonic-gate ": cb-r/w ( adr,len method$ -- #read/#written ) " 30407c478bd9Sstevel@tonic-gate " 2>r swap 2 2r> ['] $callback catch if " 30417c478bd9Sstevel@tonic-gate " 2drop 3drop 0 " 30427c478bd9Sstevel@tonic-gate " then " 30437c478bd9Sstevel@tonic-gate "; " 30447c478bd9Sstevel@tonic-gate ": read ( adr,len -- #read ) " 30457c478bd9Sstevel@tonic-gate " \" read\" ['] cb-r/w catch if 2drop 2drop -2 exit then " 30467c478bd9Sstevel@tonic-gate " ( retN ... ret1 N ) " 30477c478bd9Sstevel@tonic-gate " ?dup if " 30487c478bd9Sstevel@tonic-gate " swap >r 1- 0 ?do drop loop r> " 30497c478bd9Sstevel@tonic-gate " else " 30507c478bd9Sstevel@tonic-gate " -2 " 305112ef07e9Slq150181 " then " 30527c478bd9Sstevel@tonic-gate "; " 30537c478bd9Sstevel@tonic-gate ": write ( adr,len -- #written ) " 30547c478bd9Sstevel@tonic-gate " \" write\" ['] cb-r/w catch if 2drop 2drop 0 exit then " 30557c478bd9Sstevel@tonic-gate " ( retN ... ret1 N ) " 30567c478bd9Sstevel@tonic-gate " ?dup if " 30577c478bd9Sstevel@tonic-gate " swap >r 1- 0 ?do drop loop r> " 30587c478bd9Sstevel@tonic-gate " else " 30597c478bd9Sstevel@tonic-gate " 0 " 30607c478bd9Sstevel@tonic-gate " then " 30617c478bd9Sstevel@tonic-gate "; " 30627c478bd9Sstevel@tonic-gate ": poll-tty ( -- ) ; " 30637c478bd9Sstevel@tonic-gate ": install-abort ( -- ) ['] poll-tty d# 10 alarm ; " 30647c478bd9Sstevel@tonic-gate ": remove-abort ( -- ) ['] poll-tty 0 alarm ; " 30657c478bd9Sstevel@tonic-gate ": cb-give/take ( $method -- ) " 30667c478bd9Sstevel@tonic-gate " 0 -rot ['] $callback catch ?dup if " 30677c478bd9Sstevel@tonic-gate " >r 2drop 2drop r> throw " 30687c478bd9Sstevel@tonic-gate " else " 30697c478bd9Sstevel@tonic-gate " 0 ?do drop loop " 30707c478bd9Sstevel@tonic-gate " then " 30717c478bd9Sstevel@tonic-gate "; " 30727c478bd9Sstevel@tonic-gate ": give ( -- ) \" exit-input\" cb-give/take ; " 30737c478bd9Sstevel@tonic-gate ": take ( -- ) \" enter-input\" cb-give/take ; " 30747c478bd9Sstevel@tonic-gate ": open ( -- ok? ) true ; " 30757c478bd9Sstevel@tonic-gate ": close ( -- ) ; " 30767c478bd9Sstevel@tonic-gate "finish-device " 30777c478bd9Sstevel@tonic-gate "device-end "; 30787c478bd9Sstevel@tonic-gate 30797c478bd9Sstevel@tonic-gate /* 3080fea9cb91Slq150181 * Create the OBP input/output node (FCode serial driver). 3081fea9cb91Slq150181 * It is needed for both USB console keyboard and for 3082fea9cb91Slq150181 * the kernel terminal emulator. It is too early to check for a 3083fea9cb91Slq150181 * kernel console compatible framebuffer now, so we create this 3084fea9cb91Slq150181 * so that we're ready if we need to enable kernel terminal emulation. 30857c478bd9Sstevel@tonic-gate * 3086fea9cb91Slq150181 * When the USB software takes over the input device at the time 3087fea9cb91Slq150181 * consconfig runs, OBP's stdin is redirected to this node. 3088fea9cb91Slq150181 * Whenever the FORTH user interface is used after this switch, 3089fea9cb91Slq150181 * the node will call back into the kernel for console input. 3090fea9cb91Slq150181 * If a serial device such as ttya or a UART with a Type 5 keyboard 3091fea9cb91Slq150181 * attached is used, OBP takes over the serial device when the system 3092fea9cb91Slq150181 * goes to the debugger after the system is booted. This sharing 3093fea9cb91Slq150181 * of the relatively simple serial device is difficult but possible. 3094fea9cb91Slq150181 * Sharing the USB host controller is impossible due its complexity. 3095fea9cb91Slq150181 * 3096fea9cb91Slq150181 * Similarly to USB keyboard input redirection, after consconfig_dacf 3097fea9cb91Slq150181 * configures a kernel console framebuffer as the standard output 3098fea9cb91Slq150181 * device, OBP's stdout is switched to to vector through the 3099fea9cb91Slq150181 * /os-io node into the kernel terminal emulator. 31007c478bd9Sstevel@tonic-gate */ 31017c478bd9Sstevel@tonic-gate static void 3102fea9cb91Slq150181 startup_create_io_node(void) 31037c478bd9Sstevel@tonic-gate { 31047c478bd9Sstevel@tonic-gate prom_interpret(create_node, 0, 0, 0, 0, 0); 31057c478bd9Sstevel@tonic-gate } 31067c478bd9Sstevel@tonic-gate 31077c478bd9Sstevel@tonic-gate 31087c478bd9Sstevel@tonic-gate static void 31097c478bd9Sstevel@tonic-gate do_prom_version_check(void) 31107c478bd9Sstevel@tonic-gate { 31117c478bd9Sstevel@tonic-gate int i; 3112fa9e4066Sahrens pnode_t node; 31137c478bd9Sstevel@tonic-gate char buf[64]; 31147c478bd9Sstevel@tonic-gate static char drev[] = "Down-rev firmware detected%s\n" 31157c478bd9Sstevel@tonic-gate "\tPlease upgrade to the following minimum version:\n" 31167c478bd9Sstevel@tonic-gate "\t\t%s\n"; 31177c478bd9Sstevel@tonic-gate 31187c478bd9Sstevel@tonic-gate i = prom_version_check(buf, sizeof (buf), &node); 31197c478bd9Sstevel@tonic-gate 31207c478bd9Sstevel@tonic-gate if (i == PROM_VER64_OK) 31217c478bd9Sstevel@tonic-gate return; 31227c478bd9Sstevel@tonic-gate 31237c478bd9Sstevel@tonic-gate if (i == PROM_VER64_UPGRADE) { 31247c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, drev, "", buf); 31257c478bd9Sstevel@tonic-gate 31267c478bd9Sstevel@tonic-gate #ifdef DEBUG 31277c478bd9Sstevel@tonic-gate prom_enter_mon(); /* Type 'go' to continue */ 31287c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Booting with down-rev firmware\n"); 31297c478bd9Sstevel@tonic-gate return; 31307c478bd9Sstevel@tonic-gate #else 31317c478bd9Sstevel@tonic-gate halt(0); 31327c478bd9Sstevel@tonic-gate #endif 31337c478bd9Sstevel@tonic-gate } 31347c478bd9Sstevel@tonic-gate 31357c478bd9Sstevel@tonic-gate /* 31367c478bd9Sstevel@tonic-gate * The other possibility is that this is a server running 31377c478bd9Sstevel@tonic-gate * good firmware, but down-rev firmware was detected on at 31387c478bd9Sstevel@tonic-gate * least one other cpu board. We just complain if we see 31397c478bd9Sstevel@tonic-gate * that. 31407c478bd9Sstevel@tonic-gate */ 31417c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, drev, " on one or more CPU boards", buf); 31427c478bd9Sstevel@tonic-gate } 31437c478bd9Sstevel@tonic-gate 31447c478bd9Sstevel@tonic-gate 31457c478bd9Sstevel@tonic-gate /* 31467c478bd9Sstevel@tonic-gate * Must be defined in platform dependent code. 31477c478bd9Sstevel@tonic-gate */ 31487c478bd9Sstevel@tonic-gate extern caddr_t modtext; 31497c478bd9Sstevel@tonic-gate extern size_t modtext_sz; 31507c478bd9Sstevel@tonic-gate extern caddr_t moddata; 31517c478bd9Sstevel@tonic-gate 31527c478bd9Sstevel@tonic-gate #define HEAPTEXT_ARENA(addr) \ 31537c478bd9Sstevel@tonic-gate ((uintptr_t)(addr) < KERNELBASE + 2 * MMU_PAGESIZE4M ? 0 : \ 31547c478bd9Sstevel@tonic-gate (((uintptr_t)(addr) - HEAPTEXT_BASE) / \ 31557c478bd9Sstevel@tonic-gate (HEAPTEXT_MAPPED + HEAPTEXT_UNMAPPED) + 1)) 31567c478bd9Sstevel@tonic-gate 31577c478bd9Sstevel@tonic-gate #define HEAPTEXT_OVERSIZED(addr) \ 31587c478bd9Sstevel@tonic-gate ((uintptr_t)(addr) >= HEAPTEXT_BASE + HEAPTEXT_SIZE - HEAPTEXT_OVERSIZE) 31597c478bd9Sstevel@tonic-gate 3160e5c2c6e7SJonathan Haslam #define HEAPTEXT_IN_NUCLEUSDATA(addr) \ 3161e5c2c6e7SJonathan Haslam (((uintptr_t)(addr) >= KERNELBASE + 2 * MMU_PAGESIZE4M) && \ 3162e5c2c6e7SJonathan Haslam ((uintptr_t)(addr) < KERNELBASE + 3 * MMU_PAGESIZE4M)) 3163e5c2c6e7SJonathan Haslam 31647c478bd9Sstevel@tonic-gate vmem_t *texthole_source[HEAPTEXT_NARENAS]; 31657c478bd9Sstevel@tonic-gate vmem_t *texthole_arena[HEAPTEXT_NARENAS]; 31667c478bd9Sstevel@tonic-gate kmutex_t texthole_lock; 31677c478bd9Sstevel@tonic-gate 31687c478bd9Sstevel@tonic-gate char kern_bootargs[OBP_MAXPATHLEN]; 316919397407SSherry Moore char kern_bootfile[OBP_MAXPATHLEN]; 31707c478bd9Sstevel@tonic-gate 31717c478bd9Sstevel@tonic-gate void 31727c478bd9Sstevel@tonic-gate kobj_vmem_init(vmem_t **text_arena, vmem_t **data_arena) 31737c478bd9Sstevel@tonic-gate { 31747c478bd9Sstevel@tonic-gate uintptr_t addr, limit; 31757c478bd9Sstevel@tonic-gate 31767c478bd9Sstevel@tonic-gate addr = HEAPTEXT_BASE; 31777c478bd9Sstevel@tonic-gate limit = addr + HEAPTEXT_SIZE - HEAPTEXT_OVERSIZE; 31787c478bd9Sstevel@tonic-gate 31797c478bd9Sstevel@tonic-gate /* 31807c478bd9Sstevel@tonic-gate * Before we initialize the text_arena, we want to punch holes in the 31817c478bd9Sstevel@tonic-gate * underlying heaptext_arena. This guarantees that for any text 31827c478bd9Sstevel@tonic-gate * address we can find a text hole less than HEAPTEXT_MAPPED away. 31837c478bd9Sstevel@tonic-gate */ 31847c478bd9Sstevel@tonic-gate for (; addr + HEAPTEXT_UNMAPPED <= limit; 31857c478bd9Sstevel@tonic-gate addr += HEAPTEXT_MAPPED + HEAPTEXT_UNMAPPED) { 31867c478bd9Sstevel@tonic-gate (void) vmem_xalloc(heaptext_arena, HEAPTEXT_UNMAPPED, PAGESIZE, 31877c478bd9Sstevel@tonic-gate 0, 0, (void *)addr, (void *)(addr + HEAPTEXT_UNMAPPED), 31887c478bd9Sstevel@tonic-gate VM_NOSLEEP | VM_BESTFIT | VM_PANIC); 31897c478bd9Sstevel@tonic-gate } 31907c478bd9Sstevel@tonic-gate 31917c478bd9Sstevel@tonic-gate /* 31927c478bd9Sstevel@tonic-gate * Allocate one page at the oversize to break up the text region 31937c478bd9Sstevel@tonic-gate * from the oversized region. 31947c478bd9Sstevel@tonic-gate */ 31957c478bd9Sstevel@tonic-gate (void) vmem_xalloc(heaptext_arena, PAGESIZE, PAGESIZE, 0, 0, 31967c478bd9Sstevel@tonic-gate (void *)limit, (void *)(limit + PAGESIZE), 31977c478bd9Sstevel@tonic-gate VM_NOSLEEP | VM_BESTFIT | VM_PANIC); 31987c478bd9Sstevel@tonic-gate 319968d3ac02Skchow *text_arena = vmem_create("module_text", modtext_sz ? modtext : NULL, 320068d3ac02Skchow modtext_sz, sizeof (uintptr_t), segkmem_alloc, segkmem_free, 32017c478bd9Sstevel@tonic-gate heaptext_arena, 0, VM_SLEEP); 32027c478bd9Sstevel@tonic-gate *data_arena = vmem_create("module_data", moddata, MODDATA, 1, 32037c478bd9Sstevel@tonic-gate segkmem_alloc, segkmem_free, heap32_arena, 0, VM_SLEEP); 32047c478bd9Sstevel@tonic-gate } 32057c478bd9Sstevel@tonic-gate 32067c478bd9Sstevel@tonic-gate caddr_t 32077c478bd9Sstevel@tonic-gate kobj_text_alloc(vmem_t *arena, size_t size) 32087c478bd9Sstevel@tonic-gate { 32097c478bd9Sstevel@tonic-gate caddr_t rval, better; 32107c478bd9Sstevel@tonic-gate 32117c478bd9Sstevel@tonic-gate /* 32127c478bd9Sstevel@tonic-gate * First, try a sleeping allocation. 32137c478bd9Sstevel@tonic-gate */ 32147c478bd9Sstevel@tonic-gate rval = vmem_alloc(arena, size, VM_SLEEP | VM_BESTFIT); 32157c478bd9Sstevel@tonic-gate 32167c478bd9Sstevel@tonic-gate if (size >= HEAPTEXT_MAPPED || !HEAPTEXT_OVERSIZED(rval)) 32177c478bd9Sstevel@tonic-gate return (rval); 32187c478bd9Sstevel@tonic-gate 32197c478bd9Sstevel@tonic-gate /* 32207c478bd9Sstevel@tonic-gate * We didn't get the area that we wanted. We're going to try to do an 32217c478bd9Sstevel@tonic-gate * allocation with explicit constraints. 32227c478bd9Sstevel@tonic-gate */ 32237c478bd9Sstevel@tonic-gate better = vmem_xalloc(arena, size, sizeof (uintptr_t), 0, 0, NULL, 32247c478bd9Sstevel@tonic-gate (void *)(HEAPTEXT_BASE + HEAPTEXT_SIZE - HEAPTEXT_OVERSIZE), 32257c478bd9Sstevel@tonic-gate VM_NOSLEEP | VM_BESTFIT); 32267c478bd9Sstevel@tonic-gate 32277c478bd9Sstevel@tonic-gate if (better != NULL) { 32287c478bd9Sstevel@tonic-gate /* 32297c478bd9Sstevel@tonic-gate * That worked. Free our first attempt and return. 32307c478bd9Sstevel@tonic-gate */ 32317c478bd9Sstevel@tonic-gate vmem_free(arena, rval, size); 32327c478bd9Sstevel@tonic-gate return (better); 32337c478bd9Sstevel@tonic-gate } 32347c478bd9Sstevel@tonic-gate 32357c478bd9Sstevel@tonic-gate /* 32367c478bd9Sstevel@tonic-gate * That didn't work; we'll have to return our first attempt. 32377c478bd9Sstevel@tonic-gate */ 32387c478bd9Sstevel@tonic-gate return (rval); 32397c478bd9Sstevel@tonic-gate } 32407c478bd9Sstevel@tonic-gate 32417c478bd9Sstevel@tonic-gate caddr_t 32427c478bd9Sstevel@tonic-gate kobj_texthole_alloc(caddr_t addr, size_t size) 32437c478bd9Sstevel@tonic-gate { 32447c478bd9Sstevel@tonic-gate int arena = HEAPTEXT_ARENA(addr); 32457c478bd9Sstevel@tonic-gate char c[30]; 32467c478bd9Sstevel@tonic-gate uintptr_t base; 32477c478bd9Sstevel@tonic-gate 3248e5c2c6e7SJonathan Haslam if (HEAPTEXT_OVERSIZED(addr) || HEAPTEXT_IN_NUCLEUSDATA(addr)) { 32497c478bd9Sstevel@tonic-gate /* 3250e5c2c6e7SJonathan Haslam * If this is an oversized allocation or it is allocated in 3251e5c2c6e7SJonathan Haslam * the nucleus data page, there is no text hole available for 3252e5c2c6e7SJonathan Haslam * it; return NULL. 32537c478bd9Sstevel@tonic-gate */ 32547c478bd9Sstevel@tonic-gate return (NULL); 32557c478bd9Sstevel@tonic-gate } 32567c478bd9Sstevel@tonic-gate 32577c478bd9Sstevel@tonic-gate mutex_enter(&texthole_lock); 32587c478bd9Sstevel@tonic-gate 32597c478bd9Sstevel@tonic-gate if (texthole_arena[arena] == NULL) { 32607c478bd9Sstevel@tonic-gate ASSERT(texthole_source[arena] == NULL); 32617c478bd9Sstevel@tonic-gate 32627c478bd9Sstevel@tonic-gate if (arena == 0) { 32637c478bd9Sstevel@tonic-gate texthole_source[0] = vmem_create("module_text_holesrc", 32647c478bd9Sstevel@tonic-gate (void *)(KERNELBASE + MMU_PAGESIZE4M), 32657c478bd9Sstevel@tonic-gate MMU_PAGESIZE4M, PAGESIZE, NULL, NULL, NULL, 32667c478bd9Sstevel@tonic-gate 0, VM_SLEEP); 32677c478bd9Sstevel@tonic-gate } else { 32687c478bd9Sstevel@tonic-gate base = HEAPTEXT_BASE + 32697c478bd9Sstevel@tonic-gate (arena - 1) * (HEAPTEXT_MAPPED + HEAPTEXT_UNMAPPED); 32707c478bd9Sstevel@tonic-gate 32717c478bd9Sstevel@tonic-gate (void) snprintf(c, sizeof (c), 32727c478bd9Sstevel@tonic-gate "heaptext_holesrc_%d", arena); 32737c478bd9Sstevel@tonic-gate 32747c478bd9Sstevel@tonic-gate texthole_source[arena] = vmem_create(c, (void *)base, 32757c478bd9Sstevel@tonic-gate HEAPTEXT_UNMAPPED, PAGESIZE, NULL, NULL, NULL, 32767c478bd9Sstevel@tonic-gate 0, VM_SLEEP); 32777c478bd9Sstevel@tonic-gate } 32787c478bd9Sstevel@tonic-gate 32797c478bd9Sstevel@tonic-gate (void) snprintf(c, sizeof (c), "heaptext_hole_%d", arena); 32807c478bd9Sstevel@tonic-gate 32817c478bd9Sstevel@tonic-gate texthole_arena[arena] = vmem_create(c, NULL, 0, 32827c478bd9Sstevel@tonic-gate sizeof (uint32_t), segkmem_alloc_permanent, segkmem_free, 32837c478bd9Sstevel@tonic-gate texthole_source[arena], 0, VM_SLEEP); 32847c478bd9Sstevel@tonic-gate } 32857c478bd9Sstevel@tonic-gate 32867c478bd9Sstevel@tonic-gate mutex_exit(&texthole_lock); 32877c478bd9Sstevel@tonic-gate 32887c478bd9Sstevel@tonic-gate ASSERT(texthole_arena[arena] != NULL); 32897c478bd9Sstevel@tonic-gate ASSERT(arena >= 0 && arena < HEAPTEXT_NARENAS); 32907c478bd9Sstevel@tonic-gate return (vmem_alloc(texthole_arena[arena], size, 32917c478bd9Sstevel@tonic-gate VM_BESTFIT | VM_NOSLEEP)); 32927c478bd9Sstevel@tonic-gate } 32937c478bd9Sstevel@tonic-gate 32947c478bd9Sstevel@tonic-gate void 32957c478bd9Sstevel@tonic-gate kobj_texthole_free(caddr_t addr, size_t size) 32967c478bd9Sstevel@tonic-gate { 32977c478bd9Sstevel@tonic-gate int arena = HEAPTEXT_ARENA(addr); 32987c478bd9Sstevel@tonic-gate 32997c478bd9Sstevel@tonic-gate ASSERT(arena >= 0 && arena < HEAPTEXT_NARENAS); 33007c478bd9Sstevel@tonic-gate ASSERT(texthole_arena[arena] != NULL); 33017c478bd9Sstevel@tonic-gate vmem_free(texthole_arena[arena], addr, size); 33027c478bd9Sstevel@tonic-gate } 33031b83305cSjm22469 33041b83305cSjm22469 void 33051b83305cSjm22469 release_bootstrap(void) 33061b83305cSjm22469 { 33071b83305cSjm22469 if (&cif_init) 33081b83305cSjm22469 cif_init(); 33091b83305cSjm22469 } 3310