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 /* 23ae115bc7Smrj * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/machsystm.h> 307c478bd9Sstevel@tonic-gate #include <sys/archsystm.h> 317c478bd9Sstevel@tonic-gate #include <sys/vm.h> 327c478bd9Sstevel@tonic-gate #include <sys/cpu.h> 337c478bd9Sstevel@tonic-gate #include <sys/atomic.h> 347c478bd9Sstevel@tonic-gate #include <sys/reboot.h> 357c478bd9Sstevel@tonic-gate #include <sys/kdi.h> 367c478bd9Sstevel@tonic-gate #include <sys/bootconf.h> 377c478bd9Sstevel@tonic-gate #include <sys/memlist_plat.h> 387c478bd9Sstevel@tonic-gate #include <sys/memlist_impl.h> 397c478bd9Sstevel@tonic-gate #include <sys/prom_plat.h> 407c478bd9Sstevel@tonic-gate #include <sys/prom_isa.h> 417c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 427c478bd9Sstevel@tonic-gate #include <sys/intreg.h> 437c478bd9Sstevel@tonic-gate #include <sys/ivintr.h> 447c478bd9Sstevel@tonic-gate #include <sys/fpu/fpusystm.h> 457c478bd9Sstevel@tonic-gate #include <sys/iommutsb.h> 467c478bd9Sstevel@tonic-gate #include <vm/vm_dep.h> 477c478bd9Sstevel@tonic-gate #include <vm/seg_dev.h> 487c478bd9Sstevel@tonic-gate #include <vm/seg_kmem.h> 497c478bd9Sstevel@tonic-gate #include <vm/seg_kpm.h> 507c478bd9Sstevel@tonic-gate #include <vm/seg_map.h> 517c478bd9Sstevel@tonic-gate #include <vm/seg_kp.h> 527c478bd9Sstevel@tonic-gate #include <sys/sysconf.h> 537c478bd9Sstevel@tonic-gate #include <vm/hat_sfmmu.h> 547c478bd9Sstevel@tonic-gate #include <sys/kobj.h> 557c478bd9Sstevel@tonic-gate #include <sys/sun4asi.h> 567c478bd9Sstevel@tonic-gate #include <sys/clconf.h> 577c478bd9Sstevel@tonic-gate #include <sys/platform_module.h> 587c478bd9Sstevel@tonic-gate #include <sys/panic.h> 597c478bd9Sstevel@tonic-gate #include <sys/cpu_sgnblk_defs.h> 607c478bd9Sstevel@tonic-gate #include <sys/clock.h> 617c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 627c478bd9Sstevel@tonic-gate #include <sys/promif.h> 637c478bd9Sstevel@tonic-gate #include <sys/prom_debug.h> 647c478bd9Sstevel@tonic-gate #include <sys/traptrace.h> 657c478bd9Sstevel@tonic-gate #include <sys/memnode.h> 667c478bd9Sstevel@tonic-gate #include <sys/mem_cage.h> 671e2e7a75Shuah #include <sys/mmu.h> 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate extern void setup_trap_table(void); 70982b9107Sjb145095 extern int cpu_intrq_setup(struct cpu *); 717c478bd9Sstevel@tonic-gate extern void cpu_intrq_register(struct cpu *); 727c478bd9Sstevel@tonic-gate extern void contig_mem_init(void); 73aaa10e67Sha137994 extern caddr_t contig_mem_prealloc(caddr_t, pgcnt_t); 747c478bd9Sstevel@tonic-gate extern void mach_dump_buffer_init(void); 757c478bd9Sstevel@tonic-gate extern void mach_descrip_init(void); 761ae08745Sheppo extern void mach_descrip_startup_fini(void); 777c478bd9Sstevel@tonic-gate extern void mach_memscrub(void); 787c478bd9Sstevel@tonic-gate extern void mach_fpras(void); 797c478bd9Sstevel@tonic-gate extern void mach_cpu_halt_idle(void); 807c478bd9Sstevel@tonic-gate extern void mach_hw_copy_limit(void); 811ae08745Sheppo extern void load_mach_drivers(void); 827c478bd9Sstevel@tonic-gate extern void load_tod_module(void); 837c478bd9Sstevel@tonic-gate #pragma weak load_tod_module 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate extern int ndata_alloc_mmfsa(struct memlist *ndata); 867c478bd9Sstevel@tonic-gate #pragma weak ndata_alloc_mmfsa 877c478bd9Sstevel@tonic-gate 881ae08745Sheppo extern void cif_init(void); 891ae08745Sheppo #pragma weak cif_init 901ae08745Sheppo 917c478bd9Sstevel@tonic-gate extern void parse_idprom(void); 927c478bd9Sstevel@tonic-gate extern void add_vx_handler(char *, int, void (*)(cell_t *)); 937c478bd9Sstevel@tonic-gate extern void mem_config_init(void); 947c478bd9Sstevel@tonic-gate extern void memseg_remap_init(void); 957c478bd9Sstevel@tonic-gate 96fedab560Sae112802 extern void mach_kpm_init(void); 97d7d93655Sblakej extern int size_pse_array(pgcnt_t, int); 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 */ 1237c478bd9Sstevel@tonic-gate uint_t segmap_percent = 12; /* 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 */ 159*986fd29aSsetje 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 */ 168*986fd29aSsetje 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) */ 1787c478bd9Sstevel@tonic-gate struct page *pp_base; /* Base of system page struct array */ 1797c478bd9Sstevel@tonic-gate size_t pp_sz; /* Size in bytes of page struct array */ 1807c478bd9Sstevel@tonic-gate struct page **page_hash; /* Page hash table */ 181d7d93655Sblakej pad_mutex_t *pse_mutex; /* Locks protecting pp->p_selock */ 182d7d93655Sblakej size_t pse_table_size; /* Number of mutexes in pse_mutex[] */ 183d7d93655Sblakej int pse_shift; /* log2(pse_table_size) */ 1847c478bd9Sstevel@tonic-gate struct seg ktextseg; /* Segment used for kernel executable image */ 1857c478bd9Sstevel@tonic-gate struct seg kvalloc; /* Segment used for "valloc" mapping */ 1867c478bd9Sstevel@tonic-gate struct seg kpseg; /* Segment used for pageable kernel virt mem */ 1877c478bd9Sstevel@tonic-gate struct seg ktexthole; /* Segment used for nucleus text hole */ 1887c478bd9Sstevel@tonic-gate struct seg kmapseg; /* Segment used for generic kernel mappings */ 1897c478bd9Sstevel@tonic-gate struct seg kpmseg; /* Segment used for physical mapping */ 1907c478bd9Sstevel@tonic-gate struct seg kdebugseg; /* Segment used for the kernel debugger */ 1917c478bd9Sstevel@tonic-gate 192*986fd29aSsetje void *kpm_pp_base; /* Base of system kpm_page array */ 1937c478bd9Sstevel@tonic-gate size_t kpm_pp_sz; /* Size of system kpm_page array */ 1947c478bd9Sstevel@tonic-gate pgcnt_t kpm_npages; /* How many kpm pages are managed */ 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate struct seg *segkp = &kpseg; /* Pageable kernel virtual memory segment */ 1977c478bd9Sstevel@tonic-gate struct seg *segkmap = &kmapseg; /* Kernel generic mapping segment */ 1987c478bd9Sstevel@tonic-gate struct seg *segkpm = &kpmseg; /* 64bit kernel physical mapping segment */ 1997c478bd9Sstevel@tonic-gate 200ad23a2dbSjohansen int segzio_fromheap = 0; /* zio allocations occur from heap */ 201ad23a2dbSjohansen caddr_t segzio_base; /* Base address of segzio */ 202ad23a2dbSjohansen pgcnt_t segziosize = 0; /* size of zio segment in pages */ 203ad23a2dbSjohansen 2047c478bd9Sstevel@tonic-gate /* 2057c478bd9Sstevel@tonic-gate * debugger pages (if allocated) 2067c478bd9Sstevel@tonic-gate */ 2077c478bd9Sstevel@tonic-gate struct vnode kdebugvp; 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate /* 210ae115bc7Smrj * VA range available to the debugger 211ae115bc7Smrj */ 212ae115bc7Smrj const caddr_t kdi_segdebugbase = (const caddr_t)SEGDEBUGBASE; 213ae115bc7Smrj const size_t kdi_segdebugsize = SEGDEBUGSIZE; 214ae115bc7Smrj 215ae115bc7Smrj /* 2167c478bd9Sstevel@tonic-gate * Segment for relocated kernel structures in 64-bit large RAM kernels 2177c478bd9Sstevel@tonic-gate */ 2187c478bd9Sstevel@tonic-gate struct seg kmem64; 2197c478bd9Sstevel@tonic-gate 220*986fd29aSsetje struct memseg *memseg_free; 221*986fd29aSsetje 2227c478bd9Sstevel@tonic-gate struct vnode unused_pages_vp; 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* 2257c478bd9Sstevel@tonic-gate * VM data structures allocated early during boot. 2267c478bd9Sstevel@tonic-gate */ 2277c478bd9Sstevel@tonic-gate size_t pagehash_sz; 2287c478bd9Sstevel@tonic-gate uint64_t memlist_sz; 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate char tbr_wr_addr_inited = 0; 2317c478bd9Sstevel@tonic-gate 232bb57d1f5Sjc25722 caddr_t mpo_heap32_buf = NULL; 233bb57d1f5Sjc25722 size_t mpo_heap32_bufsz = 0; 2347c478bd9Sstevel@tonic-gate 2357c478bd9Sstevel@tonic-gate /* 2367c478bd9Sstevel@tonic-gate * Static Routines: 2377c478bd9Sstevel@tonic-gate */ 238*986fd29aSsetje static int ndata_alloc_memseg(struct memlist *, size_t); 239*986fd29aSsetje static void memlist_new(uint64_t, uint64_t, struct memlist **); 240*986fd29aSsetje static void memlist_add(uint64_t, uint64_t, 241*986fd29aSsetje struct memlist **, struct memlist **); 242*986fd29aSsetje static void kphysm_init(void); 2437c478bd9Sstevel@tonic-gate static void kvm_init(void); 244*986fd29aSsetje static void install_kmem64_tte(void); 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate static void startup_init(void); 2477c478bd9Sstevel@tonic-gate static void startup_memlist(void); 2487c478bd9Sstevel@tonic-gate static void startup_modules(void); 2497c478bd9Sstevel@tonic-gate static void startup_bop_gone(void); 2507c478bd9Sstevel@tonic-gate static void startup_vm(void); 2517c478bd9Sstevel@tonic-gate static void startup_end(void); 2527c478bd9Sstevel@tonic-gate static void setup_cage_params(void); 253fea9cb91Slq150181 static void startup_create_io_node(void); 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate static pgcnt_t npages; 2567c478bd9Sstevel@tonic-gate static struct memlist *memlist; 2577c478bd9Sstevel@tonic-gate void *memlist_end; 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate static pgcnt_t bop_alloc_pages; 2607c478bd9Sstevel@tonic-gate static caddr_t hblk_base; 2617c478bd9Sstevel@tonic-gate uint_t hblk_alloc_dynamic = 0; 2627c478bd9Sstevel@tonic-gate uint_t hblk1_min = H1MIN; 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate /* 2667c478bd9Sstevel@tonic-gate * Hooks for unsupported platforms and down-rev firmware 2677c478bd9Sstevel@tonic-gate */ 2687c478bd9Sstevel@tonic-gate int iam_positron(void); 2697c478bd9Sstevel@tonic-gate #pragma weak iam_positron 2707c478bd9Sstevel@tonic-gate static void do_prom_version_check(void); 2717c478bd9Sstevel@tonic-gate 2727c478bd9Sstevel@tonic-gate /* 2737c478bd9Sstevel@tonic-gate * After receiving a thermal interrupt, this is the number of seconds 2747c478bd9Sstevel@tonic-gate * to delay before shutting off the system, assuming 2757c478bd9Sstevel@tonic-gate * shutdown fails. Use /etc/system to change the delay if this isn't 2767c478bd9Sstevel@tonic-gate * large enough. 2777c478bd9Sstevel@tonic-gate */ 2787c478bd9Sstevel@tonic-gate int thermal_powerdown_delay = 1200; 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate /* 2817c478bd9Sstevel@tonic-gate * Used to hold off page relocations into the cage until OBP has completed 2827c478bd9Sstevel@tonic-gate * its boot-time handoff of its resources to the kernel. 2837c478bd9Sstevel@tonic-gate */ 2847c478bd9Sstevel@tonic-gate int page_relocate_ready = 0; 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate /* 2877c478bd9Sstevel@tonic-gate * Enable some debugging messages concerning memory usage... 2887c478bd9Sstevel@tonic-gate */ 2897c478bd9Sstevel@tonic-gate #ifdef DEBUGGING_MEM 2907c478bd9Sstevel@tonic-gate static int debugging_mem; 2917c478bd9Sstevel@tonic-gate static void 2927c478bd9Sstevel@tonic-gate printmemlist(char *title, struct memlist *list) 2937c478bd9Sstevel@tonic-gate { 2947c478bd9Sstevel@tonic-gate if (!debugging_mem) 2957c478bd9Sstevel@tonic-gate return; 2967c478bd9Sstevel@tonic-gate 2977c478bd9Sstevel@tonic-gate printf("%s\n", title); 2987c478bd9Sstevel@tonic-gate 2997c478bd9Sstevel@tonic-gate while (list) { 3007c478bd9Sstevel@tonic-gate prom_printf("\taddr = 0x%x %8x, size = 0x%x %8x\n", 3017c478bd9Sstevel@tonic-gate (uint32_t)(list->address >> 32), (uint32_t)list->address, 3027c478bd9Sstevel@tonic-gate (uint32_t)(list->size >> 32), (uint32_t)(list->size)); 3037c478bd9Sstevel@tonic-gate list = list->next; 3047c478bd9Sstevel@tonic-gate } 3057c478bd9Sstevel@tonic-gate } 3067c478bd9Sstevel@tonic-gate 3077c478bd9Sstevel@tonic-gate void 3087c478bd9Sstevel@tonic-gate printmemseg(struct memseg *memseg) 3097c478bd9Sstevel@tonic-gate { 3107c478bd9Sstevel@tonic-gate if (!debugging_mem) 3117c478bd9Sstevel@tonic-gate return; 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate printf("memseg\n"); 3147c478bd9Sstevel@tonic-gate 3157c478bd9Sstevel@tonic-gate while (memseg) { 3167c478bd9Sstevel@tonic-gate prom_printf("\tpage = 0x%p, epage = 0x%p, " 3177c478bd9Sstevel@tonic-gate "pfn = 0x%x, epfn = 0x%x\n", 3187c478bd9Sstevel@tonic-gate memseg->pages, memseg->epages, 3197c478bd9Sstevel@tonic-gate memseg->pages_base, memseg->pages_end); 3207c478bd9Sstevel@tonic-gate memseg = memseg->next; 3217c478bd9Sstevel@tonic-gate } 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate #define debug_pause(str) halt((str)) 3257c478bd9Sstevel@tonic-gate #define MPRINTF(str) if (debugging_mem) prom_printf((str)) 3267c478bd9Sstevel@tonic-gate #define MPRINTF1(str, a) if (debugging_mem) prom_printf((str), (a)) 3277c478bd9Sstevel@tonic-gate #define MPRINTF2(str, a, b) if (debugging_mem) prom_printf((str), (a), (b)) 3287c478bd9Sstevel@tonic-gate #define MPRINTF3(str, a, b, c) \ 3297c478bd9Sstevel@tonic-gate if (debugging_mem) prom_printf((str), (a), (b), (c)) 3307c478bd9Sstevel@tonic-gate #else /* DEBUGGING_MEM */ 3317c478bd9Sstevel@tonic-gate #define MPRINTF(str) 3327c478bd9Sstevel@tonic-gate #define MPRINTF1(str, a) 3337c478bd9Sstevel@tonic-gate #define MPRINTF2(str, a, b) 3347c478bd9Sstevel@tonic-gate #define MPRINTF3(str, a, b, c) 3357c478bd9Sstevel@tonic-gate #endif /* DEBUGGING_MEM */ 3367c478bd9Sstevel@tonic-gate 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate /* 3397c478bd9Sstevel@tonic-gate * 3407c478bd9Sstevel@tonic-gate * Kernel's Virtual Memory Layout. 3417c478bd9Sstevel@tonic-gate * /-----------------------\ 3427c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.FFFFFFFF -| |- 3437c478bd9Sstevel@tonic-gate * | OBP's virtual page | 3447c478bd9Sstevel@tonic-gate * | tables | 3457c478bd9Sstevel@tonic-gate * 0xFFFFFFFC.00000000 -|-----------------------|- 3467c478bd9Sstevel@tonic-gate * : : 3477c478bd9Sstevel@tonic-gate * : : 348ad23a2dbSjohansen * -|-----------------------|- 349ad23a2dbSjohansen * | segzio | (base and size vary) 3507c478bd9Sstevel@tonic-gate * 0xFFFFFE00.00000000 -|-----------------------|- 3517c478bd9Sstevel@tonic-gate * | | Ultrasparc I/II support 3527c478bd9Sstevel@tonic-gate * | segkpm segment | up to 2TB of physical 3537c478bd9Sstevel@tonic-gate * | (64-bit kernel ONLY) | memory, VAC has 2 colors 3547c478bd9Sstevel@tonic-gate * | | 3557c478bd9Sstevel@tonic-gate * 0xFFFFFA00.00000000 -|-----------------------|- 2TB segkpm alignment 3567c478bd9Sstevel@tonic-gate * : : 3577c478bd9Sstevel@tonic-gate * : : 3587c478bd9Sstevel@tonic-gate * 0xFFFFF810.00000000 -|-----------------------|- hole_end 3597c478bd9Sstevel@tonic-gate * | | ^ 3607c478bd9Sstevel@tonic-gate * | UltraSPARC I/II call | | 3617c478bd9Sstevel@tonic-gate * | bug requires an extra | | 3627c478bd9Sstevel@tonic-gate * | 4 GB of space between | | 3637c478bd9Sstevel@tonic-gate * | hole and used RAM | | 3647c478bd9Sstevel@tonic-gate * | | | 3657c478bd9Sstevel@tonic-gate * 0xFFFFF800.00000000 -|-----------------------|- | 3667c478bd9Sstevel@tonic-gate * | | | 3677c478bd9Sstevel@tonic-gate * | Virtual Address Hole | UltraSPARC 3687c478bd9Sstevel@tonic-gate * | on UltraSPARC I/II | I/II * ONLY * 3697c478bd9Sstevel@tonic-gate * | | | 3707c478bd9Sstevel@tonic-gate * 0x00000800.00000000 -|-----------------------|- | 3717c478bd9Sstevel@tonic-gate * | | | 3727c478bd9Sstevel@tonic-gate * | UltraSPARC I/II call | | 3737c478bd9Sstevel@tonic-gate * | bug requires an extra | | 3747c478bd9Sstevel@tonic-gate * | 4 GB of space between | | 3757c478bd9Sstevel@tonic-gate * | hole and used RAM | | 3767c478bd9Sstevel@tonic-gate * | | v 3777c478bd9Sstevel@tonic-gate * 0x000007FF.00000000 -|-----------------------|- hole_start ----- 3787c478bd9Sstevel@tonic-gate * : : ^ 3797c478bd9Sstevel@tonic-gate * : : | 380*986fd29aSsetje * |-----------------------| | 381*986fd29aSsetje * | | | 382*986fd29aSsetje * | ecache flush area | | 383*986fd29aSsetje * | (twice largest e$) | | 384*986fd29aSsetje * | | | 385bb121940Sdp78419 * 0x00000XXX.XXX00000 -|-----------------------|- kmem64_ | 386bb121940Sdp78419 * | overmapped area | alignend_end | 387bb121940Sdp78419 * | (kmem64_alignsize | | 388bb121940Sdp78419 * | boundary) | | 3897c478bd9Sstevel@tonic-gate * 0x00000XXX.XXXXXXXX -|-----------------------|- kmem64_end | 3907c478bd9Sstevel@tonic-gate * | | | 3917c478bd9Sstevel@tonic-gate * | 64-bit kernel ONLY | | 3927c478bd9Sstevel@tonic-gate * | | | 3937c478bd9Sstevel@tonic-gate * | kmem64 segment | | 3947c478bd9Sstevel@tonic-gate * | | | 3957c478bd9Sstevel@tonic-gate * | (Relocated extra HME | Approximately 3967c478bd9Sstevel@tonic-gate * | block allocations, | 1 TB of virtual 3977c478bd9Sstevel@tonic-gate * | memnode freelists, | address space 3987c478bd9Sstevel@tonic-gate * | HME hash buckets, | | 3997c478bd9Sstevel@tonic-gate * | mml_table, kpmp_table,| | 4007c478bd9Sstevel@tonic-gate * | page_t array and | | 4017c478bd9Sstevel@tonic-gate * | hashblock pool to | | 4027c478bd9Sstevel@tonic-gate * | avoid hard-coded | | 4037c478bd9Sstevel@tonic-gate * | 32-bit vaddr | | 4047c478bd9Sstevel@tonic-gate * | limitations) | | 4057c478bd9Sstevel@tonic-gate * | | v 4067c478bd9Sstevel@tonic-gate * 0x00000700.00000000 -|-----------------------|- SYSLIMIT (kmem64_base) 4077c478bd9Sstevel@tonic-gate * | | 4087c478bd9Sstevel@tonic-gate * | segkmem segment | (SYSLIMIT - SYSBASE = 4TB) 4097c478bd9Sstevel@tonic-gate * | | 4107c478bd9Sstevel@tonic-gate * 0x00000300.00000000 -|-----------------------|- SYSBASE 4117c478bd9Sstevel@tonic-gate * : : 4127c478bd9Sstevel@tonic-gate * : : 4137c478bd9Sstevel@tonic-gate * -|-----------------------|- 4147c478bd9Sstevel@tonic-gate * | | 4157c478bd9Sstevel@tonic-gate * | segmap segment | SEGMAPSIZE (1/8th physmem, 4167c478bd9Sstevel@tonic-gate * | | 256G MAX) 4177c478bd9Sstevel@tonic-gate * 0x000002a7.50000000 -|-----------------------|- SEGMAPBASE 4187c478bd9Sstevel@tonic-gate * : : 4197c478bd9Sstevel@tonic-gate * : : 4207c478bd9Sstevel@tonic-gate * -|-----------------------|- 4217c478bd9Sstevel@tonic-gate * | | 4227c478bd9Sstevel@tonic-gate * | segkp | SEGKPSIZE (2GB) 4237c478bd9Sstevel@tonic-gate * | | 4247c478bd9Sstevel@tonic-gate * | | 4257c478bd9Sstevel@tonic-gate * 0x000002a1.00000000 -|-----------------------|- SEGKPBASE 4267c478bd9Sstevel@tonic-gate * | | 4277c478bd9Sstevel@tonic-gate * 0x000002a0.00000000 -|-----------------------|- MEMSCRUBBASE 4287c478bd9Sstevel@tonic-gate * | | (SEGKPBASE - 0x400000) 4297c478bd9Sstevel@tonic-gate * 0x0000029F.FFE00000 -|-----------------------|- ARGSBASE 4307c478bd9Sstevel@tonic-gate * | | (MEMSCRUBBASE - NCARGS) 4317c478bd9Sstevel@tonic-gate * 0x0000029F.FFD80000 -|-----------------------|- PPMAPBASE 4327c478bd9Sstevel@tonic-gate * | | (ARGSBASE - PPMAPSIZE) 4337c478bd9Sstevel@tonic-gate * 0x0000029F.FFD00000 -|-----------------------|- PPMAP_FAST_BASE 4347c478bd9Sstevel@tonic-gate * | | 4357c478bd9Sstevel@tonic-gate * 0x0000029F.FF980000 -|-----------------------|- PIOMAPBASE 4367c478bd9Sstevel@tonic-gate * | | 4377c478bd9Sstevel@tonic-gate * 0x0000029F.FF580000 -|-----------------------|- NARG_BASE 4387c478bd9Sstevel@tonic-gate * : : 4397c478bd9Sstevel@tonic-gate * : : 4407c478bd9Sstevel@tonic-gate * 0x00000000.FFFFFFFF -|-----------------------|- OFW_END_ADDR 4417c478bd9Sstevel@tonic-gate * | | 4427c478bd9Sstevel@tonic-gate * | OBP | 4437c478bd9Sstevel@tonic-gate * | | 4447c478bd9Sstevel@tonic-gate * 0x00000000.F0000000 -|-----------------------|- OFW_START_ADDR 4457c478bd9Sstevel@tonic-gate * | kmdb | 4467c478bd9Sstevel@tonic-gate * 0x00000000.EDD00000 -|-----------------------|- SEGDEBUGBASE 4477c478bd9Sstevel@tonic-gate * : : 4487c478bd9Sstevel@tonic-gate * : : 4497c478bd9Sstevel@tonic-gate * 0x00000000.7c000000 -|-----------------------|- SYSLIMIT32 4507c478bd9Sstevel@tonic-gate * | | 4517c478bd9Sstevel@tonic-gate * | segkmem32 segment | (SYSLIMIT32 - SYSBASE32 = 4527c478bd9Sstevel@tonic-gate * | | ~64MB) 453*986fd29aSsetje * 0x00000000.70002000 -|-----------------------| 4547c478bd9Sstevel@tonic-gate * | panicbuf | 455*986fd29aSsetje * 0x00000000.70000000 -|-----------------------|- SYSBASE32 456*986fd29aSsetje * | boot-time | 457*986fd29aSsetje * | temporary space | 458*986fd29aSsetje * 0x00000000.4C000000 -|-----------------------|- BOOTTMPBASE 4597c478bd9Sstevel@tonic-gate * : : 4607c478bd9Sstevel@tonic-gate * : : 4617c478bd9Sstevel@tonic-gate * | | 4627c478bd9Sstevel@tonic-gate * |-----------------------|- econtig32 4637c478bd9Sstevel@tonic-gate * | vm structures | 4647c478bd9Sstevel@tonic-gate * 0x00000000.01C00000 |-----------------------|- nalloc_end 4657c478bd9Sstevel@tonic-gate * | TSBs | 4667c478bd9Sstevel@tonic-gate * |-----------------------|- end/nalloc_base 4677c478bd9Sstevel@tonic-gate * | kernel data & bss | 4687c478bd9Sstevel@tonic-gate * 0x00000000.01800000 -|-----------------------| 4697c478bd9Sstevel@tonic-gate * : nucleus text hole : 4707c478bd9Sstevel@tonic-gate * 0x00000000.01400000 -|-----------------------| 4717c478bd9Sstevel@tonic-gate * : : 4727c478bd9Sstevel@tonic-gate * |-----------------------| 4737c478bd9Sstevel@tonic-gate * | module text | 4747c478bd9Sstevel@tonic-gate * |-----------------------|- e_text/modtext 4757c478bd9Sstevel@tonic-gate * | kernel text | 4767c478bd9Sstevel@tonic-gate * |-----------------------| 4777c478bd9Sstevel@tonic-gate * | trap table (48k) | 4787c478bd9Sstevel@tonic-gate * 0x00000000.01000000 -|-----------------------|- KERNELBASE 4797c478bd9Sstevel@tonic-gate * | reserved for trapstat |} TSTAT_TOTAL_SIZE 4807c478bd9Sstevel@tonic-gate * |-----------------------| 4817c478bd9Sstevel@tonic-gate * | | 4827c478bd9Sstevel@tonic-gate * | invalid | 4837c478bd9Sstevel@tonic-gate * | | 4847c478bd9Sstevel@tonic-gate * 0x00000000.00000000 _|_______________________| 4857c478bd9Sstevel@tonic-gate * 4867c478bd9Sstevel@tonic-gate * 4877c478bd9Sstevel@tonic-gate * 4887c478bd9Sstevel@tonic-gate * 32-bit User Virtual Memory Layout. 4897c478bd9Sstevel@tonic-gate * /-----------------------\ 4907c478bd9Sstevel@tonic-gate * | | 4917c478bd9Sstevel@tonic-gate * | invalid | 4927c478bd9Sstevel@tonic-gate * | | 4937c478bd9Sstevel@tonic-gate * 0xFFC00000 -|-----------------------|- USERLIMIT 4947c478bd9Sstevel@tonic-gate * | user stack | 4957c478bd9Sstevel@tonic-gate * : : 4967c478bd9Sstevel@tonic-gate * : : 4977c478bd9Sstevel@tonic-gate * : : 4987c478bd9Sstevel@tonic-gate * | user data | 4997c478bd9Sstevel@tonic-gate * -|-----------------------|- 5007c478bd9Sstevel@tonic-gate * | user text | 5017c478bd9Sstevel@tonic-gate * 0x00002000 -|-----------------------|- 5027c478bd9Sstevel@tonic-gate * | invalid | 5037c478bd9Sstevel@tonic-gate * 0x00000000 _|_______________________| 5047c478bd9Sstevel@tonic-gate * 5057c478bd9Sstevel@tonic-gate * 5067c478bd9Sstevel@tonic-gate * 5077c478bd9Sstevel@tonic-gate * 64-bit User Virtual Memory Layout. 5087c478bd9Sstevel@tonic-gate * /-----------------------\ 5097c478bd9Sstevel@tonic-gate * | | 5107c478bd9Sstevel@tonic-gate * | invalid | 5117c478bd9Sstevel@tonic-gate * | | 5127c478bd9Sstevel@tonic-gate * 0xFFFFFFFF.80000000 -|-----------------------|- USERLIMIT 5137c478bd9Sstevel@tonic-gate * | user stack | 5147c478bd9Sstevel@tonic-gate * : : 5157c478bd9Sstevel@tonic-gate * : : 5167c478bd9Sstevel@tonic-gate * : : 5177c478bd9Sstevel@tonic-gate * | user data | 5187c478bd9Sstevel@tonic-gate * -|-----------------------|- 5197c478bd9Sstevel@tonic-gate * | user text | 520*986fd29aSsetje * 0x00000000.01000000 -|-----------------------|- 5217c478bd9Sstevel@tonic-gate * | invalid | 5227c478bd9Sstevel@tonic-gate * 0x00000000.00000000 _|_______________________| 5237c478bd9Sstevel@tonic-gate */ 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate extern caddr_t ecache_init_scrub_flush_area(caddr_t alloc_base); 5267c478bd9Sstevel@tonic-gate extern uint64_t ecache_flush_address(void); 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate #pragma weak load_platform_modules 52925cf1a30Sjl139090 #pragma weak plat_startup_memlist 5307c478bd9Sstevel@tonic-gate #pragma weak ecache_init_scrub_flush_area 5317c478bd9Sstevel@tonic-gate #pragma weak ecache_flush_address 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate /* 5357c478bd9Sstevel@tonic-gate * By default the DR Cage is enabled for maximum OS 5367c478bd9Sstevel@tonic-gate * MPSS performance. Users needing to disable the cage mechanism 5377c478bd9Sstevel@tonic-gate * can set this variable to zero via /etc/system. 5387c478bd9Sstevel@tonic-gate * Disabling the cage on systems supporting Dynamic Reconfiguration (DR) 5397c478bd9Sstevel@tonic-gate * will result in loss of DR functionality. 5407c478bd9Sstevel@tonic-gate * Platforms wishing to disable kernel Cage by default 5417c478bd9Sstevel@tonic-gate * should do so in their set_platform_defaults() routine. 5427c478bd9Sstevel@tonic-gate */ 5437c478bd9Sstevel@tonic-gate int kernel_cage_enable = 1; 5447c478bd9Sstevel@tonic-gate 5457c478bd9Sstevel@tonic-gate static void 5467c478bd9Sstevel@tonic-gate setup_cage_params(void) 5477c478bd9Sstevel@tonic-gate { 5487c478bd9Sstevel@tonic-gate void (*func)(void); 5497c478bd9Sstevel@tonic-gate 5507c478bd9Sstevel@tonic-gate func = (void (*)(void))kobj_getsymvalue("set_platform_cage_params", 0); 5517c478bd9Sstevel@tonic-gate if (func != NULL) { 5527c478bd9Sstevel@tonic-gate (*func)(); 5537c478bd9Sstevel@tonic-gate return; 5547c478bd9Sstevel@tonic-gate } 5557c478bd9Sstevel@tonic-gate 5567c478bd9Sstevel@tonic-gate if (kernel_cage_enable == 0) { 5577c478bd9Sstevel@tonic-gate return; 5587c478bd9Sstevel@tonic-gate } 55985f58038Sdp78419 kcage_range_init(phys_avail, KCAGE_DOWN, total_pages / 256); 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate if (kcage_on) { 5627c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!Kernel Cage is ENABLED"); 5637c478bd9Sstevel@tonic-gate } else { 5647c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!Kernel Cage is DISABLED"); 5657c478bd9Sstevel@tonic-gate } 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate } 5687c478bd9Sstevel@tonic-gate 5697c478bd9Sstevel@tonic-gate /* 5707c478bd9Sstevel@tonic-gate * Machine-dependent startup code 5717c478bd9Sstevel@tonic-gate */ 5727c478bd9Sstevel@tonic-gate void 5737c478bd9Sstevel@tonic-gate startup(void) 5747c478bd9Sstevel@tonic-gate { 5757c478bd9Sstevel@tonic-gate startup_init(); 5767c478bd9Sstevel@tonic-gate if (&startup_platform) 5777c478bd9Sstevel@tonic-gate startup_platform(); 5787c478bd9Sstevel@tonic-gate startup_memlist(); 5797c478bd9Sstevel@tonic-gate startup_modules(); 5807c478bd9Sstevel@tonic-gate setup_cage_params(); 5817c478bd9Sstevel@tonic-gate startup_bop_gone(); 5827c478bd9Sstevel@tonic-gate startup_vm(); 5837c478bd9Sstevel@tonic-gate startup_end(); 5847c478bd9Sstevel@tonic-gate } 5857c478bd9Sstevel@tonic-gate 5867c478bd9Sstevel@tonic-gate struct regs sync_reg_buf; 5877c478bd9Sstevel@tonic-gate uint64_t sync_tt; 5887c478bd9Sstevel@tonic-gate 5897c478bd9Sstevel@tonic-gate void 5907c478bd9Sstevel@tonic-gate sync_handler(void) 5917c478bd9Sstevel@tonic-gate { 592843e1988Sjohnlev struct panic_trap_info ti; 5937c478bd9Sstevel@tonic-gate int i; 5947c478bd9Sstevel@tonic-gate 5957c478bd9Sstevel@tonic-gate /* 5967c478bd9Sstevel@tonic-gate * Prevent trying to talk to the other CPUs since they are 5977c478bd9Sstevel@tonic-gate * sitting in the prom and won't reply. 5987c478bd9Sstevel@tonic-gate */ 5997c478bd9Sstevel@tonic-gate for (i = 0; i < NCPU; i++) { 6007c478bd9Sstevel@tonic-gate if ((i != CPU->cpu_id) && CPU_XCALL_READY(i)) { 6017c478bd9Sstevel@tonic-gate cpu[i]->cpu_flags &= ~CPU_READY; 6027c478bd9Sstevel@tonic-gate cpu[i]->cpu_flags |= CPU_QUIESCED; 6037c478bd9Sstevel@tonic-gate CPUSET_DEL(cpu_ready_set, cpu[i]->cpu_id); 6047c478bd9Sstevel@tonic-gate } 6057c478bd9Sstevel@tonic-gate } 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate /* 6087c478bd9Sstevel@tonic-gate * We've managed to get here without going through the 6097c478bd9Sstevel@tonic-gate * normal panic code path. Try and save some useful 6107c478bd9Sstevel@tonic-gate * information. 6117c478bd9Sstevel@tonic-gate */ 6127c478bd9Sstevel@tonic-gate if (!panicstr && (curthread->t_panic_trap == NULL)) { 6137c478bd9Sstevel@tonic-gate ti.trap_type = sync_tt; 6147c478bd9Sstevel@tonic-gate ti.trap_regs = &sync_reg_buf; 6157c478bd9Sstevel@tonic-gate ti.trap_addr = NULL; 6167c478bd9Sstevel@tonic-gate ti.trap_mmu_fsr = 0x0; 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate curthread->t_panic_trap = &ti; 6197c478bd9Sstevel@tonic-gate } 6207c478bd9Sstevel@tonic-gate 6217c478bd9Sstevel@tonic-gate /* 6227c478bd9Sstevel@tonic-gate * If we're re-entering the panic path, update the signature 6237c478bd9Sstevel@tonic-gate * block so that the SC knows we're in the second part of panic. 6247c478bd9Sstevel@tonic-gate */ 6257c478bd9Sstevel@tonic-gate if (panicstr) 6267c478bd9Sstevel@tonic-gate CPU_SIGNATURE(OS_SIG, SIGST_EXIT, SIGSUBST_DUMP, -1); 6277c478bd9Sstevel@tonic-gate 6287c478bd9Sstevel@tonic-gate nopanicdebug = 1; /* do not perform debug_enter() prior to dump */ 6297c478bd9Sstevel@tonic-gate panic("sync initiated"); 6307c478bd9Sstevel@tonic-gate } 6317c478bd9Sstevel@tonic-gate 6327c478bd9Sstevel@tonic-gate 6337c478bd9Sstevel@tonic-gate static void 6347c478bd9Sstevel@tonic-gate startup_init(void) 6357c478bd9Sstevel@tonic-gate { 6367c478bd9Sstevel@tonic-gate /* 6377c478bd9Sstevel@tonic-gate * We want to save the registers while we're still in OBP 6387c478bd9Sstevel@tonic-gate * so that we know they haven't been fiddled with since. 6397c478bd9Sstevel@tonic-gate * (In principle, OBP can't change them just because it 6407c478bd9Sstevel@tonic-gate * makes a callback, but we'd rather not depend on that 6417c478bd9Sstevel@tonic-gate * behavior.) 6427c478bd9Sstevel@tonic-gate */ 6437c478bd9Sstevel@tonic-gate char sync_str[] = 6447c478bd9Sstevel@tonic-gate "warning @ warning off : sync " 6457c478bd9Sstevel@tonic-gate "%%tl-c %%tstate h# %p x! " 6467c478bd9Sstevel@tonic-gate "%%g1 h# %p x! %%g2 h# %p x! %%g3 h# %p x! " 6477c478bd9Sstevel@tonic-gate "%%g4 h# %p x! %%g5 h# %p x! %%g6 h# %p x! " 6487c478bd9Sstevel@tonic-gate "%%g7 h# %p x! %%o0 h# %p x! %%o1 h# %p x! " 6497c478bd9Sstevel@tonic-gate "%%o2 h# %p x! %%o3 h# %p x! %%o4 h# %p x! " 6507c478bd9Sstevel@tonic-gate "%%o5 h# %p x! %%o6 h# %p x! %%o7 h# %p x! " 6517c478bd9Sstevel@tonic-gate "%%tl-c %%tpc h# %p x! %%tl-c %%tnpc h# %p x! " 6527c478bd9Sstevel@tonic-gate "%%y h# %p l! %%tl-c %%tt h# %p x! " 6537c478bd9Sstevel@tonic-gate "sync ; warning !"; 6547c478bd9Sstevel@tonic-gate 6557c478bd9Sstevel@tonic-gate /* 6567c478bd9Sstevel@tonic-gate * 20 == num of %p substrings 6577c478bd9Sstevel@tonic-gate * 16 == max num of chars %p will expand to. 6587c478bd9Sstevel@tonic-gate */ 6597c478bd9Sstevel@tonic-gate char bp[sizeof (sync_str) + 16 * 20]; 6607c478bd9Sstevel@tonic-gate 6617c478bd9Sstevel@tonic-gate /* 6627c478bd9Sstevel@tonic-gate * Initialize ptl1 stack for the 1st CPU. 6637c478bd9Sstevel@tonic-gate */ 6647c478bd9Sstevel@tonic-gate ptl1_init_cpu(&cpu0); 6657c478bd9Sstevel@tonic-gate 6667c478bd9Sstevel@tonic-gate /* 6677c478bd9Sstevel@tonic-gate * Initialize the address map for cache consistent mappings 6687c478bd9Sstevel@tonic-gate * to random pages; must be done after vac_size is set. 6697c478bd9Sstevel@tonic-gate */ 6707c478bd9Sstevel@tonic-gate ppmapinit(); 6717c478bd9Sstevel@tonic-gate 6727c478bd9Sstevel@tonic-gate /* 6737c478bd9Sstevel@tonic-gate * Initialize the PROM callback handler. 6747c478bd9Sstevel@tonic-gate */ 6757c478bd9Sstevel@tonic-gate init_vx_handler(); 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate /* 6787c478bd9Sstevel@tonic-gate * have prom call sync_callback() to handle the sync and 6797c478bd9Sstevel@tonic-gate * save some useful information which will be stored in the 6807c478bd9Sstevel@tonic-gate * core file later. 6817c478bd9Sstevel@tonic-gate */ 6827c478bd9Sstevel@tonic-gate (void) sprintf((char *)bp, sync_str, 6837c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_tstate, (void *)&sync_reg_buf.r_g1, 6847c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_g2, (void *)&sync_reg_buf.r_g3, 6857c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_g4, (void *)&sync_reg_buf.r_g5, 6867c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_g6, (void *)&sync_reg_buf.r_g7, 6877c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_o0, (void *)&sync_reg_buf.r_o1, 6887c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_o2, (void *)&sync_reg_buf.r_o3, 6897c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_o4, (void *)&sync_reg_buf.r_o5, 6907c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_o6, (void *)&sync_reg_buf.r_o7, 6917c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_pc, (void *)&sync_reg_buf.r_npc, 6927c478bd9Sstevel@tonic-gate (void *)&sync_reg_buf.r_y, (void *)&sync_tt); 6937c478bd9Sstevel@tonic-gate prom_interpret(bp, 0, 0, 0, 0, 0); 6947c478bd9Sstevel@tonic-gate add_vx_handler("sync", 1, (void (*)(cell_t *))sync_handler); 6957c478bd9Sstevel@tonic-gate } 6967c478bd9Sstevel@tonic-gate 697*986fd29aSsetje 698*986fd29aSsetje size_t 699*986fd29aSsetje calc_pp_sz(pgcnt_t npages) 700*986fd29aSsetje { 701*986fd29aSsetje 702*986fd29aSsetje return (npages * sizeof (struct page)); 703*986fd29aSsetje } 704*986fd29aSsetje 705*986fd29aSsetje size_t 706*986fd29aSsetje calc_kpmpp_sz(pgcnt_t npages) 707*986fd29aSsetje { 708*986fd29aSsetje 709*986fd29aSsetje kpm_pgshft = (kpm_smallpages == 0) ? MMU_PAGESHIFT4M : MMU_PAGESHIFT; 710*986fd29aSsetje kpm_pgsz = 1ull << kpm_pgshft; 711*986fd29aSsetje kpm_pgoff = kpm_pgsz - 1; 712*986fd29aSsetje kpmp2pshft = kpm_pgshft - PAGESHIFT; 713*986fd29aSsetje kpmpnpgs = 1 << kpmp2pshft; 714*986fd29aSsetje 715*986fd29aSsetje if (kpm_smallpages == 0) { 716*986fd29aSsetje /* 717*986fd29aSsetje * Avoid fragmentation problems in kphysm_init() 718*986fd29aSsetje * by allocating for all of physical memory 719*986fd29aSsetje */ 720*986fd29aSsetje kpm_npages = ptokpmpr(physinstalled); 721*986fd29aSsetje return (kpm_npages * sizeof (kpm_page_t)); 722*986fd29aSsetje } else { 723*986fd29aSsetje kpm_npages = npages; 724*986fd29aSsetje return (kpm_npages * sizeof (kpm_spage_t)); 725*986fd29aSsetje } 726*986fd29aSsetje } 727*986fd29aSsetje 728*986fd29aSsetje size_t 729*986fd29aSsetje calc_pagehash_sz(pgcnt_t npages) 730*986fd29aSsetje { 731*986fd29aSsetje 732*986fd29aSsetje /* 733*986fd29aSsetje * The page structure hash table size is a power of 2 734*986fd29aSsetje * such that the average hash chain length is PAGE_HASHAVELEN. 735*986fd29aSsetje */ 736*986fd29aSsetje page_hashsz = npages / PAGE_HASHAVELEN; 737*986fd29aSsetje page_hashsz = 1 << highbit(page_hashsz); 738*986fd29aSsetje return (page_hashsz * sizeof (struct page *)); 739*986fd29aSsetje } 740*986fd29aSsetje 741*986fd29aSsetje void 742*986fd29aSsetje alloc_kmem64(caddr_t base, caddr_t end) 743*986fd29aSsetje { 744*986fd29aSsetje int i; 745*986fd29aSsetje caddr_t aligned_end = NULL; 746*986fd29aSsetje 747*986fd29aSsetje /* 748*986fd29aSsetje * Make one large memory alloc after figuring out the 64-bit size. This 749*986fd29aSsetje * will enable use of the largest page size appropriate for the system 750*986fd29aSsetje * architecture. 751*986fd29aSsetje */ 752*986fd29aSsetje ASSERT(mmu_exported_pagesize_mask & (1 << TTE8K)); 753*986fd29aSsetje ASSERT(IS_P2ALIGNED(base, TTEBYTES(max_bootlp_tteszc))); 754*986fd29aSsetje for (i = max_bootlp_tteszc; i >= TTE8K; i--) { 755*986fd29aSsetje size_t alloc_size, alignsize; 756*986fd29aSsetje #if !defined(C_OBP) 757*986fd29aSsetje unsigned long long pa; 758*986fd29aSsetje #endif /* !C_OBP */ 759*986fd29aSsetje 760*986fd29aSsetje if ((mmu_exported_pagesize_mask & (1 << i)) == 0) 761*986fd29aSsetje continue; 762*986fd29aSsetje alignsize = TTEBYTES(i); 763*986fd29aSsetje kmem64_szc = i; 764*986fd29aSsetje 765*986fd29aSsetje /* limit page size for small memory */ 766*986fd29aSsetje if (mmu_btop(alignsize) > (npages >> 2)) 767*986fd29aSsetje continue; 768*986fd29aSsetje 769*986fd29aSsetje aligned_end = (caddr_t)roundup((uintptr_t)end, alignsize); 770*986fd29aSsetje alloc_size = aligned_end - base; 771*986fd29aSsetje #if !defined(C_OBP) 772*986fd29aSsetje if (prom_allocate_phys(alloc_size, alignsize, &pa) == 0) { 773*986fd29aSsetje if (prom_claim_virt(alloc_size, base) != (caddr_t)-1) { 774*986fd29aSsetje kmem64_pabase = pa; 775*986fd29aSsetje kmem64_aligned_end = aligned_end; 776*986fd29aSsetje install_kmem64_tte(); 777*986fd29aSsetje break; 778*986fd29aSsetje } else { 779*986fd29aSsetje prom_free_phys(alloc_size, pa); 780*986fd29aSsetje } 781*986fd29aSsetje } 782*986fd29aSsetje #else /* !C_OBP */ 783*986fd29aSsetje if (prom_alloc(base, alloc_size, alignsize) == base) { 784*986fd29aSsetje kmem64_pabase = va_to_pa(kmem64_base); 785*986fd29aSsetje kmem64_aligned_end = aligned_end; 786*986fd29aSsetje break; 787*986fd29aSsetje } 788*986fd29aSsetje #endif /* !C_OBP */ 789*986fd29aSsetje if (i == TTE8K) { 790*986fd29aSsetje prom_panic("kmem64 allocation failure"); 791*986fd29aSsetje } 792*986fd29aSsetje } 793*986fd29aSsetje ASSERT(aligned_end != NULL); 794*986fd29aSsetje } 795*986fd29aSsetje 796*986fd29aSsetje static prom_memlist_t *boot_physinstalled, *boot_physavail, *boot_virtavail; 7977c478bd9Sstevel@tonic-gate static size_t boot_physinstalled_len, boot_physavail_len, boot_virtavail_len; 7987c478bd9Sstevel@tonic-gate 799*986fd29aSsetje #define IVSIZE roundup(((MAXIVNUM * sizeof (intr_vec_t *)) + \ 800b0fc0e77Sgovinda (MAX_RSVD_IV * sizeof (intr_vec_t)) + \ 801*986fd29aSsetje (MAX_RSVD_IVX * sizeof (intr_vecx_t))), PAGESIZE) 8027c478bd9Sstevel@tonic-gate 803bb121940Sdp78419 #if !defined(C_OBP) 804bb121940Sdp78419 /* 805bb121940Sdp78419 * Install a temporary tte handler in OBP for kmem64 area. 806bb121940Sdp78419 * 807bb121940Sdp78419 * We map kmem64 area with large pages before the trap table is taken 808bb121940Sdp78419 * over. Since OBP makes 8K mappings, it can create 8K tlb entries in 809bb121940Sdp78419 * the same area. Duplicate tlb entries with different page sizes 810bb121940Sdp78419 * cause unpredicatble behavior. To avoid this, we don't create 811bb121940Sdp78419 * kmem64 mappings via BOP_ALLOC (ends up as prom_alloc() call to 812bb121940Sdp78419 * OBP). Instead, we manage translations with a temporary va>tte-data 813bb121940Sdp78419 * handler (kmem64-tte). This handler is replaced by unix-tte when 814bb121940Sdp78419 * the trap table is taken over. 815bb121940Sdp78419 * 816bb121940Sdp78419 * The temporary handler knows the physical address of the kmem64 817bb121940Sdp78419 * area. It uses the prom's pgmap@ Forth word for other addresses. 818bb121940Sdp78419 * 819bb121940Sdp78419 * We have to use BOP_ALLOC() method for C-OBP platforms because 820bb121940Sdp78419 * pgmap@ is not defined in C-OBP. C-OBP is only used on serengeti 821bb121940Sdp78419 * sun4u platforms. On sun4u we flush tlb after trap table is taken 822bb121940Sdp78419 * over if we use large pages for kernel heap and kmem64. Since sun4u 823bb121940Sdp78419 * prom (unlike sun4v) calls va>tte-data first for client address 824bb121940Sdp78419 * translation prom's ttes for kmem64 can't get into TLB even if we 825bb121940Sdp78419 * later switch to prom's trap table again. C-OBP uses 4M pages for 826bb121940Sdp78419 * client mappings when possible so on all platforms we get the 827bb121940Sdp78419 * benefit from large mappings for kmem64 area immediately during 828bb121940Sdp78419 * boot. 829bb121940Sdp78419 * 830bb121940Sdp78419 * pseudo code: 831bb121940Sdp78419 * if (context != 0) { 832bb121940Sdp78419 * return false 833bb121940Sdp78419 * } else if (miss_va in range[kmem64_base, kmem64_end)) { 834bb121940Sdp78419 * tte = tte_template + 835bb121940Sdp78419 * (((miss_va & pagemask) - kmem64_base)); 836bb121940Sdp78419 * return tte, true 837bb121940Sdp78419 * } else { 838bb121940Sdp78419 * return pgmap@ result 839bb121940Sdp78419 * } 840bb121940Sdp78419 */ 841bb121940Sdp78419 char kmem64_obp_str[] = 842*986fd29aSsetje "h# %lx constant kmem64-base " 843*986fd29aSsetje "h# %lx constant kmem64-end " 844*986fd29aSsetje "h# %lx constant kmem64-pagemask " 845*986fd29aSsetje "h# %lx constant kmem64-template " 846bb121940Sdp78419 847bb121940Sdp78419 ": kmem64-tte ( addr cnum -- false | tte-data true ) " 848bb121940Sdp78419 " if ( addr ) " 849bb121940Sdp78419 " drop false exit then ( false ) " 850*986fd29aSsetje " dup kmem64-base kmem64-end within if ( addr ) " 851*986fd29aSsetje " kmem64-pagemask and ( addr' ) " 852*986fd29aSsetje " kmem64-base - ( addr' ) " 853*986fd29aSsetje " kmem64-template + ( tte ) " 854bb121940Sdp78419 " true ( tte true ) " 855bb121940Sdp78419 " else ( addr ) " 856bb121940Sdp78419 " pgmap@ ( tte ) " 857bb121940Sdp78419 " dup 0< if true else drop false then ( tte true | false ) " 858bb121940Sdp78419 " then ( tte true | false ) " 859bb121940Sdp78419 "; " 860bb121940Sdp78419 861bb121940Sdp78419 "' kmem64-tte is va>tte-data " 862bb121940Sdp78419 ; 863bb121940Sdp78419 864*986fd29aSsetje static void 865bb121940Sdp78419 install_kmem64_tte() 866bb121940Sdp78419 { 867bb121940Sdp78419 char b[sizeof (kmem64_obp_str) + (4 * 16)]; 868bb121940Sdp78419 tte_t tte; 869bb121940Sdp78419 870bb121940Sdp78419 PRM_DEBUG(kmem64_pabase); 871bb121940Sdp78419 PRM_DEBUG(kmem64_szc); 872bb121940Sdp78419 sfmmu_memtte(&tte, kmem64_pabase >> MMU_PAGESHIFT, 873bb121940Sdp78419 PROC_DATA | HAT_NOSYNC, kmem64_szc); 874bb121940Sdp78419 PRM_DEBUG(tte.ll); 875bb121940Sdp78419 (void) sprintf(b, kmem64_obp_str, 876bb121940Sdp78419 kmem64_base, kmem64_end, TTE_PAGEMASK(kmem64_szc), tte.ll); 877bb121940Sdp78419 ASSERT(strlen(b) < sizeof (b)); 878bb121940Sdp78419 prom_interpret(b, 0, 0, 0, 0, 0); 879bb121940Sdp78419 } 880bb121940Sdp78419 #endif /* !C_OBP */ 881bb121940Sdp78419 8827c478bd9Sstevel@tonic-gate /* 8837c478bd9Sstevel@tonic-gate * As OBP takes up some RAM when the system boots, pages will already be "lost" 8847c478bd9Sstevel@tonic-gate * to the system and reflected in npages by the time we see it. 8857c478bd9Sstevel@tonic-gate * 8867c478bd9Sstevel@tonic-gate * We only want to allocate kernel structures in the 64-bit virtual address 8877c478bd9Sstevel@tonic-gate * space on systems with enough RAM to make the overhead of keeping track of 8887c478bd9Sstevel@tonic-gate * an extra kernel memory segment worthwhile. 8897c478bd9Sstevel@tonic-gate * 8907c478bd9Sstevel@tonic-gate * Since OBP has already performed its memory allocations by this point, if we 8917c478bd9Sstevel@tonic-gate * have more than MINMOVE_RAM_MB MB of RAM left free, go ahead and map 8927c478bd9Sstevel@tonic-gate * memory in the 64-bit virtual address space; otherwise keep allocations 8937c478bd9Sstevel@tonic-gate * contiguous with we've mapped so far in the 32-bit virtual address space. 8947c478bd9Sstevel@tonic-gate */ 8957c478bd9Sstevel@tonic-gate #define MINMOVE_RAM_MB ((size_t)1900) 8967c478bd9Sstevel@tonic-gate #define MB_TO_BYTES(mb) ((mb) * 1048576ul) 8977c478bd9Sstevel@tonic-gate 8987c478bd9Sstevel@tonic-gate pgcnt_t tune_npages = (pgcnt_t) 8997c478bd9Sstevel@tonic-gate (MB_TO_BYTES(MINMOVE_RAM_MB)/ (size_t)MMU_PAGESIZE); 9007c478bd9Sstevel@tonic-gate 901fe70c9cfSdp78419 #pragma weak page_set_colorequiv_arr_cpu 902fe70c9cfSdp78419 extern void page_set_colorequiv_arr_cpu(void); 903*986fd29aSsetje extern void page_set_colorequiv_arr(void); 904*986fd29aSsetje 905fe70c9cfSdp78419 9067c478bd9Sstevel@tonic-gate static void 9077c478bd9Sstevel@tonic-gate startup_memlist(void) 9087c478bd9Sstevel@tonic-gate { 909*986fd29aSsetje size_t hmehash_sz, pagelist_sz, tt_sz; 910*986fd29aSsetje size_t psetable_sz; 9117c478bd9Sstevel@tonic-gate caddr_t alloc_base; 9127c478bd9Sstevel@tonic-gate caddr_t memspace; 9137c478bd9Sstevel@tonic-gate struct memlist *cur; 9147c478bd9Sstevel@tonic-gate size_t syslimit = (size_t)SYSLIMIT; 9157c478bd9Sstevel@tonic-gate size_t sysbase = (size_t)SYSBASE; 9167c478bd9Sstevel@tonic-gate 9177c478bd9Sstevel@tonic-gate /* 9187c478bd9Sstevel@tonic-gate * Initialize enough of the system to allow kmem_alloc to work by 9197c478bd9Sstevel@tonic-gate * calling boot to allocate its memory until the time that 9207c478bd9Sstevel@tonic-gate * kvm_init is completed. The page structs are allocated after 9217c478bd9Sstevel@tonic-gate * rounding up end to the nearest page boundary; the memsegs are 9227c478bd9Sstevel@tonic-gate * initialized and the space they use comes from the kernel heap. 9237c478bd9Sstevel@tonic-gate * With appropriate initialization, they can be reallocated later 9247c478bd9Sstevel@tonic-gate * to a size appropriate for the machine's configuration. 9257c478bd9Sstevel@tonic-gate * 9267c478bd9Sstevel@tonic-gate * At this point, memory is allocated for things that will never 9277c478bd9Sstevel@tonic-gate * need to be freed, this used to be "valloced". This allows a 9287c478bd9Sstevel@tonic-gate * savings as the pages don't need page structures to describe 9297c478bd9Sstevel@tonic-gate * them because them will not be managed by the vm system. 9307c478bd9Sstevel@tonic-gate */ 9317c478bd9Sstevel@tonic-gate 9327c478bd9Sstevel@tonic-gate /* 9337c478bd9Sstevel@tonic-gate * We're loaded by boot with the following configuration (as 9347c478bd9Sstevel@tonic-gate * specified in the sun4u/conf/Mapfile): 9357c478bd9Sstevel@tonic-gate * 9367c478bd9Sstevel@tonic-gate * text: 4 MB chunk aligned on a 4MB boundary 9377c478bd9Sstevel@tonic-gate * data & bss: 4 MB chunk aligned on a 4MB boundary 9387c478bd9Sstevel@tonic-gate * 9397c478bd9Sstevel@tonic-gate * These two chunks will eventually be mapped by 2 locked 4MB 9407c478bd9Sstevel@tonic-gate * ttes and will represent the nucleus of the kernel. This gives 9417c478bd9Sstevel@tonic-gate * us some free space that is already allocated, some or all of 9427c478bd9Sstevel@tonic-gate * which is made available to kernel module text. 9437c478bd9Sstevel@tonic-gate * 9447c478bd9Sstevel@tonic-gate * The free space in the data-bss chunk is used for nucleus 9457c478bd9Sstevel@tonic-gate * allocatable data structures and we reserve it using the 9467c478bd9Sstevel@tonic-gate * nalloc_base and nalloc_end variables. This space is currently 9477c478bd9Sstevel@tonic-gate * being used for hat data structures required for tlb miss 9487c478bd9Sstevel@tonic-gate * handling operations. We align nalloc_base to a l2 cache 9497c478bd9Sstevel@tonic-gate * linesize because this is the line size the hardware uses to 9507c478bd9Sstevel@tonic-gate * maintain cache coherency. 951*986fd29aSsetje * 512K is carved out for module data. 9527c478bd9Sstevel@tonic-gate */ 9537c478bd9Sstevel@tonic-gate 954*986fd29aSsetje moddata = (caddr_t)roundup((uintptr_t)e_data, MMU_PAGESIZE); 955*986fd29aSsetje e_moddata = moddata + MODDATA; 9567c478bd9Sstevel@tonic-gate nalloc_base = e_moddata; 9577c478bd9Sstevel@tonic-gate 9587c478bd9Sstevel@tonic-gate nalloc_end = (caddr_t)roundup((uintptr_t)nalloc_base, MMU_PAGESIZE4M); 9597c478bd9Sstevel@tonic-gate valloc_base = nalloc_base; 9607c478bd9Sstevel@tonic-gate 9617c478bd9Sstevel@tonic-gate /* 9627c478bd9Sstevel@tonic-gate * Calculate the start of the data segment. 9637c478bd9Sstevel@tonic-gate */ 964*986fd29aSsetje if (((uintptr_t)e_moddata & MMU_PAGEMASK4M) != (uintptr_t)s_data) 965*986fd29aSsetje prom_panic("nucleus data overflow"); 9667c478bd9Sstevel@tonic-gate 9677c478bd9Sstevel@tonic-gate PRM_DEBUG(moddata); 9687c478bd9Sstevel@tonic-gate PRM_DEBUG(nalloc_base); 9697c478bd9Sstevel@tonic-gate PRM_DEBUG(nalloc_end); 9707c478bd9Sstevel@tonic-gate 9717c478bd9Sstevel@tonic-gate /* 9727c478bd9Sstevel@tonic-gate * Remember any slop after e_text so we can give it to the modules. 9737c478bd9Sstevel@tonic-gate */ 9747c478bd9Sstevel@tonic-gate PRM_DEBUG(e_text); 9757c478bd9Sstevel@tonic-gate modtext = (caddr_t)roundup((uintptr_t)e_text, MMU_PAGESIZE); 97668d3ac02Skchow if (((uintptr_t)e_text & MMU_PAGEMASK4M) != (uintptr_t)s_text) 977bb121940Sdp78419 prom_panic("nucleus text overflow"); 9787c478bd9Sstevel@tonic-gate modtext_sz = (caddr_t)roundup((uintptr_t)modtext, MMU_PAGESIZE4M) - 9797c478bd9Sstevel@tonic-gate modtext; 9807c478bd9Sstevel@tonic-gate PRM_DEBUG(modtext); 9817c478bd9Sstevel@tonic-gate PRM_DEBUG(modtext_sz); 9827c478bd9Sstevel@tonic-gate 983*986fd29aSsetje init_boot_memlists(); 9847c478bd9Sstevel@tonic-gate copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len, 9857c478bd9Sstevel@tonic-gate &boot_physavail, &boot_physavail_len, 9867c478bd9Sstevel@tonic-gate &boot_virtavail, &boot_virtavail_len); 987*986fd29aSsetje 9887c478bd9Sstevel@tonic-gate /* 9897c478bd9Sstevel@tonic-gate * Remember what the physically available highest page is 9907c478bd9Sstevel@tonic-gate * so that dumpsys works properly, and find out how much 9917c478bd9Sstevel@tonic-gate * memory is installed. 9927c478bd9Sstevel@tonic-gate */ 9937c478bd9Sstevel@tonic-gate installed_top_size_memlist_array(boot_physinstalled, 9947c478bd9Sstevel@tonic-gate boot_physinstalled_len, &physmax, &physinstalled); 9957c478bd9Sstevel@tonic-gate PRM_DEBUG(physinstalled); 9967c478bd9Sstevel@tonic-gate PRM_DEBUG(physmax); 9977c478bd9Sstevel@tonic-gate 9987c478bd9Sstevel@tonic-gate /* Fill out memory nodes config structure */ 9997c478bd9Sstevel@tonic-gate startup_build_mem_nodes(boot_physinstalled, boot_physinstalled_len); 10007c478bd9Sstevel@tonic-gate 10017c478bd9Sstevel@tonic-gate /* 10027c478bd9Sstevel@tonic-gate * npages is the maximum of available physical memory possible. 10037c478bd9Sstevel@tonic-gate * (ie. it will never be more than this) 1004*986fd29aSsetje * 1005*986fd29aSsetje * When we boot from a ramdisk, the ramdisk memory isn't free, so 1006*986fd29aSsetje * using phys_avail will underestimate what will end up being freed. 1007*986fd29aSsetje * A better initial guess is just total memory minus the kernel text 10087c478bd9Sstevel@tonic-gate */ 1009*986fd29aSsetje npages = physinstalled - btop(MMU_PAGESIZE4M); 10107c478bd9Sstevel@tonic-gate 10117c478bd9Sstevel@tonic-gate /* 1012*986fd29aSsetje * First allocate things that can go in the nucleus data page 1013*986fd29aSsetje * (fault status, TSBs, dmv, CPUs) 10147c478bd9Sstevel@tonic-gate */ 10157c478bd9Sstevel@tonic-gate ndata_alloc_init(&ndata, (uintptr_t)nalloc_base, (uintptr_t)nalloc_end); 10167c478bd9Sstevel@tonic-gate 10177c478bd9Sstevel@tonic-gate if ((&ndata_alloc_mmfsa != NULL) && (ndata_alloc_mmfsa(&ndata) != 0)) 10187c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "no more nucleus memory after mfsa alloc"); 10197c478bd9Sstevel@tonic-gate 10207c478bd9Sstevel@tonic-gate if (ndata_alloc_tsbs(&ndata, npages) != 0) 10217c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "no more nucleus memory after tsbs alloc"); 10227c478bd9Sstevel@tonic-gate 10237c478bd9Sstevel@tonic-gate if (ndata_alloc_dmv(&ndata) != 0) 10247c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "no more nucleus memory after dmv alloc"); 10257c478bd9Sstevel@tonic-gate 1026*986fd29aSsetje if (ndata_alloc_page_mutexs(&ndata) != 0) 10277c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, 10287c478bd9Sstevel@tonic-gate "no more nucleus memory after page free lists alloc"); 10297c478bd9Sstevel@tonic-gate 1030*986fd29aSsetje if (ndata_alloc_hat(&ndata, npages) != 0) 10317c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "no more nucleus memory after hat alloc"); 10327c478bd9Sstevel@tonic-gate 1033*986fd29aSsetje if (ndata_alloc_memseg(&ndata, boot_physavail_len) != 0) 1034*986fd29aSsetje cmn_err(CE_PANIC, "no more nucleus memory after memseg alloc"); 10357c478bd9Sstevel@tonic-gate 10367c478bd9Sstevel@tonic-gate /* 10377c478bd9Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING 10387c478bd9Sstevel@tonic-gate * 10397c478bd9Sstevel@tonic-gate * There are comments all over the SFMMU code warning of dire 10407c478bd9Sstevel@tonic-gate * consequences if the TSBs are moved out of 32-bit space. This 10417c478bd9Sstevel@tonic-gate * is largely because the asm code uses "sethi %hi(addr)"-type 10427c478bd9Sstevel@tonic-gate * instructions which will not provide the expected result if the 10437c478bd9Sstevel@tonic-gate * address is a 64-bit one. 10447c478bd9Sstevel@tonic-gate * 10457c478bd9Sstevel@tonic-gate * WARNING WARNING WARNING WARNING WARNING WARNING WARNING 10467c478bd9Sstevel@tonic-gate */ 10477c478bd9Sstevel@tonic-gate alloc_base = (caddr_t)roundup((uintptr_t)nalloc_end, MMU_PAGESIZE); 1048*986fd29aSsetje PRM_DEBUG(alloc_base); 1049*986fd29aSsetje 10507c478bd9Sstevel@tonic-gate alloc_base = sfmmu_ktsb_alloc(alloc_base); 10517c478bd9Sstevel@tonic-gate alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 10527c478bd9Sstevel@tonic-gate PRM_DEBUG(alloc_base); 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate /* 10557c478bd9Sstevel@tonic-gate * Allocate IOMMU TSB array. We do this here so that the physical 10567c478bd9Sstevel@tonic-gate * memory gets deducted from the PROM's physical memory list. 10577c478bd9Sstevel@tonic-gate */ 10587c478bd9Sstevel@tonic-gate alloc_base = iommu_tsb_init(alloc_base); 1059*986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 10607c478bd9Sstevel@tonic-gate PRM_DEBUG(alloc_base); 10617c478bd9Sstevel@tonic-gate 10627c478bd9Sstevel@tonic-gate /* 1063*986fd29aSsetje * Allow for an early allocation of physically contiguous memory. 1064*986fd29aSsetje */ 1065*986fd29aSsetje alloc_base = contig_mem_prealloc(alloc_base, npages); 1066*986fd29aSsetje 1067*986fd29aSsetje /* 106825cf1a30Sjl139090 * Platforms like Starcat and OPL need special structures assigned in 106925cf1a30Sjl139090 * 32-bit virtual address space because their probing routines execute 107025cf1a30Sjl139090 * FCode, and FCode can't handle 64-bit virtual addresses... 10717c478bd9Sstevel@tonic-gate */ 107225cf1a30Sjl139090 if (&plat_startup_memlist) { 107325cf1a30Sjl139090 alloc_base = plat_startup_memlist(alloc_base); 10747c478bd9Sstevel@tonic-gate alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, 10757c478bd9Sstevel@tonic-gate ecache_alignsize); 10767c478bd9Sstevel@tonic-gate PRM_DEBUG(alloc_base); 10777c478bd9Sstevel@tonic-gate } 10787c478bd9Sstevel@tonic-gate 10797c478bd9Sstevel@tonic-gate /* 10807c478bd9Sstevel@tonic-gate * Save off where the contiguous allocations to date have ended 10817c478bd9Sstevel@tonic-gate * in econtig32. 10827c478bd9Sstevel@tonic-gate */ 10837c478bd9Sstevel@tonic-gate econtig32 = alloc_base; 10847c478bd9Sstevel@tonic-gate PRM_DEBUG(econtig32); 10857c478bd9Sstevel@tonic-gate if (econtig32 > (caddr_t)KERNEL_LIMIT32) 10867c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "econtig32 too big"); 10877c478bd9Sstevel@tonic-gate 1088*986fd29aSsetje pp_sz = calc_pp_sz(npages); 1089*986fd29aSsetje PRM_DEBUG(pp_sz); 1090*986fd29aSsetje if (kpm_enable) { 1091*986fd29aSsetje kpm_pp_sz = calc_kpmpp_sz(npages); 1092*986fd29aSsetje PRM_DEBUG(kpm_pp_sz); 1093*986fd29aSsetje } 1094*986fd29aSsetje 1095*986fd29aSsetje hmehash_sz = calc_hmehash_sz(npages); 1096*986fd29aSsetje PRM_DEBUG(hmehash_sz); 1097*986fd29aSsetje 1098*986fd29aSsetje pagehash_sz = calc_pagehash_sz(npages); 1099*986fd29aSsetje PRM_DEBUG(pagehash_sz); 1100*986fd29aSsetje 1101*986fd29aSsetje pagelist_sz = calc_free_pagelist_sz(); 1102*986fd29aSsetje PRM_DEBUG(pagelist_sz); 1103*986fd29aSsetje 1104*986fd29aSsetje #ifdef TRAPTRACE 1105*986fd29aSsetje tt_sz = calc_traptrace_sz(); 1106*986fd29aSsetje PRM_DEBUG(tt_sz); 1107*986fd29aSsetje #else 1108*986fd29aSsetje tt_sz = 0; 1109*986fd29aSsetje #endif /* TRAPTRACE */ 11107c478bd9Sstevel@tonic-gate 1111bb121940Sdp78419 /* 1112*986fd29aSsetje * Place the array that protects pp->p_selock in the kmem64 wad. 1113*986fd29aSsetje */ 1114*986fd29aSsetje pse_shift = size_pse_array(physmem, max_ncpus); 1115*986fd29aSsetje PRM_DEBUG(pse_shift); 1116*986fd29aSsetje pse_table_size = 1 << pse_shift; 1117*986fd29aSsetje PRM_DEBUG(pse_table_size); 1118*986fd29aSsetje psetable_sz = roundup( 1119*986fd29aSsetje pse_table_size * sizeof (pad_mutex_t), ecache_alignsize); 1120*986fd29aSsetje PRM_DEBUG(psetable_sz); 1121*986fd29aSsetje 1122*986fd29aSsetje /* 1123*986fd29aSsetje * Now allocate the whole wad 1124*986fd29aSsetje */ 1125*986fd29aSsetje kmem64_sz = pp_sz + kpm_pp_sz + hmehash_sz + pagehash_sz + 1126*986fd29aSsetje pagelist_sz + tt_sz + psetable_sz; 1127*986fd29aSsetje kmem64_sz = roundup(kmem64_sz, PAGESIZE); 1128*986fd29aSsetje kmem64_base = (caddr_t)syslimit; 1129*986fd29aSsetje kmem64_end = kmem64_base + kmem64_sz; 1130*986fd29aSsetje alloc_kmem64(kmem64_base, kmem64_end); 1131*986fd29aSsetje if (kmem64_aligned_end > (hole_start ? hole_start : kpm_vbase)) 1132*986fd29aSsetje cmn_err(CE_PANIC, "not enough kmem64 space"); 1133*986fd29aSsetje PRM_DEBUG(kmem64_base); 1134*986fd29aSsetje PRM_DEBUG(kmem64_end); 1135*986fd29aSsetje PRM_DEBUG(kmem64_aligned_end); 1136*986fd29aSsetje 1137*986fd29aSsetje /* 1138*986fd29aSsetje * ... and divy it up 1139bb121940Sdp78419 */ 1140bb121940Sdp78419 alloc_base = kmem64_base; 1141*986fd29aSsetje npages -= kmem64_sz / (PAGESIZE + sizeof (struct page)); 1142*986fd29aSsetje pp_base = (page_t *)alloc_base; 1143*986fd29aSsetje pp_sz = npages * sizeof (struct page); 1144*986fd29aSsetje alloc_base += pp_sz; 1145*986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1146*986fd29aSsetje PRM_DEBUG(pp_base); 11477c478bd9Sstevel@tonic-gate PRM_DEBUG(npages); 11487c478bd9Sstevel@tonic-gate 1149*986fd29aSsetje if (kpm_enable) { 1150*986fd29aSsetje kpm_pp_base = alloc_base; 1151*986fd29aSsetje if (kpm_smallpages == 0) { 1152*986fd29aSsetje /* kpm_npages based on physinstalled, don't reset */ 1153*986fd29aSsetje kpm_pp_sz = kpm_npages * sizeof (kpm_page_t); 1154*986fd29aSsetje } else { 1155*986fd29aSsetje kpm_npages = ptokpmpr(npages); 1156*986fd29aSsetje kpm_pp_sz = kpm_npages * sizeof (kpm_spage_t); 1157*986fd29aSsetje } 1158*986fd29aSsetje alloc_base += kpm_pp_sz; 1159*986fd29aSsetje alloc_base = 1160*986fd29aSsetje (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1161*986fd29aSsetje PRM_DEBUG(kpm_pp_base); 1162*986fd29aSsetje } 11637c478bd9Sstevel@tonic-gate 1164*986fd29aSsetje alloc_base = alloc_hmehash(alloc_base); 1165*986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1166*986fd29aSsetje PRM_DEBUG(alloc_base); 11677c478bd9Sstevel@tonic-gate 1168*986fd29aSsetje page_hash = (page_t **)alloc_base; 1169*986fd29aSsetje alloc_base += pagehash_sz; 1170*986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1171*986fd29aSsetje PRM_DEBUG(page_hash); 11727c478bd9Sstevel@tonic-gate 1173*986fd29aSsetje alloc_base = alloc_page_freelists(alloc_base); 1174*986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1175*986fd29aSsetje PRM_DEBUG(alloc_base); 11767c478bd9Sstevel@tonic-gate 1177*986fd29aSsetje #ifdef TRAPTRACE 1178*986fd29aSsetje ttrace_buf = alloc_base; 1179*986fd29aSsetje alloc_base += tt_sz; 1180*986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1181*986fd29aSsetje PRM_DEBUG(alloc_base); 1182*986fd29aSsetje #endif /* TRAPTRACE */ 11837c478bd9Sstevel@tonic-gate 1184*986fd29aSsetje pse_mutex = (pad_mutex_t *)alloc_base; 1185*986fd29aSsetje alloc_base += psetable_sz; 1186*986fd29aSsetje alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, ecache_alignsize); 1187*986fd29aSsetje PRM_DEBUG(alloc_base); 11887c478bd9Sstevel@tonic-gate 1189*986fd29aSsetje /* adjust kmem64_end to what we really allocated */ 1190*986fd29aSsetje kmem64_end = (caddr_t)roundup((uintptr_t)alloc_base, PAGESIZE); 1191*986fd29aSsetje kmem64_sz = kmem64_end - kmem64_base; 1192*986fd29aSsetje 1193*986fd29aSsetje if (&ecache_init_scrub_flush_area) { 1194*986fd29aSsetje alloc_base = ecache_init_scrub_flush_area(kmem64_aligned_end); 1195*986fd29aSsetje ASSERT(alloc_base <= (hole_start ? hole_start : kpm_vbase)); 11967c478bd9Sstevel@tonic-gate } 11977c478bd9Sstevel@tonic-gate 11987c478bd9Sstevel@tonic-gate /* 11997c478bd9Sstevel@tonic-gate * If physmem is patched to be non-zero, use it instead of 12007c478bd9Sstevel@tonic-gate * the monitor value unless physmem is larger than the total 12017c478bd9Sstevel@tonic-gate * amount of memory on hand. 12027c478bd9Sstevel@tonic-gate */ 12037c478bd9Sstevel@tonic-gate if (physmem == 0 || physmem > npages) 12047c478bd9Sstevel@tonic-gate physmem = npages; 12057c478bd9Sstevel@tonic-gate 12067c478bd9Sstevel@tonic-gate /* 1207*986fd29aSsetje * root_is_ramdisk is set via /etc/system when the ramdisk miniroot 1208*986fd29aSsetje * is mounted as root. This memory is held down by OBP and unlike 1209*986fd29aSsetje * the stub boot_archive is never released. 12107c478bd9Sstevel@tonic-gate * 1211*986fd29aSsetje * In order to get things sized correctly on lower memory 1212*986fd29aSsetje * machines (where the memory used by the ramdisk represents 1213*986fd29aSsetje * a significant portion of memory), physmem is adjusted. 1214*986fd29aSsetje * 1215*986fd29aSsetje * This is done by subtracting the ramdisk_size which is set 1216*986fd29aSsetje * to the size of the ramdisk (in Kb) in /etc/system at the 1217*986fd29aSsetje * time the miniroot archive is constructed. 12187c478bd9Sstevel@tonic-gate */ 1219*986fd29aSsetje if (root_is_ramdisk == B_TRUE) 1220*986fd29aSsetje physmem -= (ramdisk_size * 1024) / PAGESIZE; 12217c478bd9Sstevel@tonic-gate 1222*986fd29aSsetje if (kpm_enable && (ndata_alloc_kpm(&ndata, kpm_npages) != 0)) 1223*986fd29aSsetje cmn_err(CE_PANIC, "no more nucleus memory after kpm alloc"); 12247c478bd9Sstevel@tonic-gate 12257c478bd9Sstevel@tonic-gate /* 1226*986fd29aSsetje * Allocate space for the interrupt vector table. 12277c478bd9Sstevel@tonic-gate */ 1228*986fd29aSsetje memspace = prom_alloc((caddr_t)intr_vec_table, IVSIZE, MMU_PAGESIZE); 1229b0fc0e77Sgovinda if (memspace != (caddr_t)intr_vec_table) 1230bb121940Sdp78419 prom_panic("interrupt vector table allocation failure"); 12317c478bd9Sstevel@tonic-gate 12327c478bd9Sstevel@tonic-gate /* 12337c478bd9Sstevel@tonic-gate * Between now and when we finish copying in the memory lists, 12347c478bd9Sstevel@tonic-gate * allocations happen so the space gets fragmented and the 1235*986fd29aSsetje * lists longer. Leave enough space for lists twice as 1236*986fd29aSsetje * long as we have now; then roundup to a pagesize. 12377c478bd9Sstevel@tonic-gate */ 1238*986fd29aSsetje memlist_sz = sizeof (struct memlist) * (prom_phys_installed_len() + 1239*986fd29aSsetje prom_phys_avail_len() + prom_virt_avail_len()); 1240*986fd29aSsetje memlist_sz *= 2; 1241*986fd29aSsetje memlist_sz = roundup(memlist_sz, PAGESIZE); 1242*986fd29aSsetje memspace = ndata_alloc(&ndata, memlist_sz, ecache_alignsize); 12437c478bd9Sstevel@tonic-gate if (memspace == NULL) 1244*986fd29aSsetje cmn_err(CE_PANIC, "no more nucleus memory after memlist alloc"); 12457c478bd9Sstevel@tonic-gate 12467c478bd9Sstevel@tonic-gate memlist = (struct memlist *)memspace; 12477c478bd9Sstevel@tonic-gate memlist_end = (char *)memspace + memlist_sz; 12487c478bd9Sstevel@tonic-gate PRM_DEBUG(memlist); 12497c478bd9Sstevel@tonic-gate PRM_DEBUG(memlist_end); 1250*986fd29aSsetje 12517c478bd9Sstevel@tonic-gate PRM_DEBUG(sysbase); 12527c478bd9Sstevel@tonic-gate PRM_DEBUG(syslimit); 12537c478bd9Sstevel@tonic-gate kernelheap_init((void *)sysbase, (void *)syslimit, 12547c478bd9Sstevel@tonic-gate (caddr_t)sysbase + PAGESIZE, NULL, NULL); 12557c478bd9Sstevel@tonic-gate 12567c478bd9Sstevel@tonic-gate /* 12577c478bd9Sstevel@tonic-gate * Take the most current snapshot we can by calling mem-update. 12587c478bd9Sstevel@tonic-gate */ 12597c478bd9Sstevel@tonic-gate copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len, 12607c478bd9Sstevel@tonic-gate &boot_physavail, &boot_physavail_len, 12617c478bd9Sstevel@tonic-gate &boot_virtavail, &boot_virtavail_len); 12627c478bd9Sstevel@tonic-gate 12637c478bd9Sstevel@tonic-gate /* 1264*986fd29aSsetje * Remove the space used by prom_alloc from the kernel heap 12657c478bd9Sstevel@tonic-gate * plus the area actually used by the OBP (if any) 12667c478bd9Sstevel@tonic-gate * ignoring virtual addresses in virt_avail, above syslimit. 12677c478bd9Sstevel@tonic-gate */ 12687c478bd9Sstevel@tonic-gate virt_avail = memlist; 12697c478bd9Sstevel@tonic-gate copy_memlist(boot_virtavail, boot_virtavail_len, &memlist); 12707c478bd9Sstevel@tonic-gate 12717c478bd9Sstevel@tonic-gate for (cur = virt_avail; cur->next; cur = cur->next) { 12727c478bd9Sstevel@tonic-gate uint64_t range_base, range_size; 12737c478bd9Sstevel@tonic-gate 12747c478bd9Sstevel@tonic-gate if ((range_base = cur->address + cur->size) < (uint64_t)sysbase) 12757c478bd9Sstevel@tonic-gate continue; 12767c478bd9Sstevel@tonic-gate if (range_base >= (uint64_t)syslimit) 12777c478bd9Sstevel@tonic-gate break; 12787c478bd9Sstevel@tonic-gate /* 12797c478bd9Sstevel@tonic-gate * Limit the range to end at syslimit. 12807c478bd9Sstevel@tonic-gate */ 12817c478bd9Sstevel@tonic-gate range_size = MIN(cur->next->address, 12827c478bd9Sstevel@tonic-gate (uint64_t)syslimit) - range_base; 12837c478bd9Sstevel@tonic-gate (void) vmem_xalloc(heap_arena, (size_t)range_size, PAGESIZE, 12847c478bd9Sstevel@tonic-gate 0, 0, (void *)range_base, (void *)(range_base + range_size), 12857c478bd9Sstevel@tonic-gate VM_NOSLEEP | VM_BESTFIT | VM_PANIC); 12867c478bd9Sstevel@tonic-gate } 12877c478bd9Sstevel@tonic-gate 12887c478bd9Sstevel@tonic-gate phys_avail = memlist; 1289*986fd29aSsetje copy_memlist(boot_physavail, boot_physavail_len, &memlist); 12907c478bd9Sstevel@tonic-gate 12917c478bd9Sstevel@tonic-gate /* 12921e45ea5aSblakej * Add any extra memory at the end of the ndata region if there's at 12931e45ea5aSblakej * least a page to add. There might be a few more pages available in 12941e45ea5aSblakej * the middle of the ndata region, but for now they are ignored. 12957c478bd9Sstevel@tonic-gate */ 12961e45ea5aSblakej nalloc_base = ndata_extra_base(&ndata, MMU_PAGESIZE, nalloc_end); 12971e45ea5aSblakej if (nalloc_base == NULL) 12987c478bd9Sstevel@tonic-gate nalloc_base = nalloc_end; 12997c478bd9Sstevel@tonic-gate ndata_remain_sz = nalloc_end - nalloc_base; 13007c478bd9Sstevel@tonic-gate 1301*986fd29aSsetje /* 1302*986fd29aSsetje * Copy physinstalled list into kernel space. 1303*986fd29aSsetje */ 1304*986fd29aSsetje phys_install = memlist; 1305*986fd29aSsetje copy_memlist(boot_physinstalled, boot_physinstalled_len, &memlist); 13067c478bd9Sstevel@tonic-gate 1307*986fd29aSsetje /* 1308*986fd29aSsetje * Create list of physical addrs we don't need pp's for: 1309*986fd29aSsetje * kernel text 4M page 1310*986fd29aSsetje * kernel data 4M page - ndata_remain_sz 1311*986fd29aSsetje * kmem64 pages 1312*986fd29aSsetje * 1313*986fd29aSsetje * NB if adding any pages here, make sure no kpm page 1314*986fd29aSsetje * overlaps can occur (see ASSERTs in kphysm_memsegs) 1315*986fd29aSsetje */ 1316*986fd29aSsetje nopp_list = memlist; 1317*986fd29aSsetje memlist_new(va_to_pa(s_text), MMU_PAGESIZE4M, &memlist); 1318*986fd29aSsetje memlist_add(va_to_pa(s_data), MMU_PAGESIZE4M - ndata_remain_sz, 1319*986fd29aSsetje &memlist, &nopp_list); 1320*986fd29aSsetje memlist_add(kmem64_pabase, kmem64_sz, &memlist, &nopp_list); 13217c478bd9Sstevel@tonic-gate 13227c478bd9Sstevel@tonic-gate if ((caddr_t)memlist > (memspace + memlist_sz)) 1323bb121940Sdp78419 prom_panic("memlist overflow"); 13247c478bd9Sstevel@tonic-gate 13257c478bd9Sstevel@tonic-gate /* 13267c478bd9Sstevel@tonic-gate * Initialize the page structures from the memory lists. 13277c478bd9Sstevel@tonic-gate */ 1328*986fd29aSsetje kphysm_init(); 13297c478bd9Sstevel@tonic-gate 13307c478bd9Sstevel@tonic-gate availrmem_initial = availrmem = freemem; 13317c478bd9Sstevel@tonic-gate PRM_DEBUG(availrmem); 13327c478bd9Sstevel@tonic-gate 13337c478bd9Sstevel@tonic-gate /* 13347c478bd9Sstevel@tonic-gate * Some of the locks depend on page_hashsz being set! 13357c478bd9Sstevel@tonic-gate * kmem_init() depends on this; so, keep it here. 13367c478bd9Sstevel@tonic-gate */ 13377c478bd9Sstevel@tonic-gate page_lock_init(); 13387c478bd9Sstevel@tonic-gate 13397c478bd9Sstevel@tonic-gate /* 13407c478bd9Sstevel@tonic-gate * Initialize kernel memory allocator. 13417c478bd9Sstevel@tonic-gate */ 13427c478bd9Sstevel@tonic-gate kmem_init(); 13437c478bd9Sstevel@tonic-gate 13447c478bd9Sstevel@tonic-gate /* 1345932dc8e5Sdp78419 * Factor in colorequiv to check additional 'equivalent' bins 1346932dc8e5Sdp78419 */ 1347fe70c9cfSdp78419 if (&page_set_colorequiv_arr_cpu != NULL) 1348fe70c9cfSdp78419 page_set_colorequiv_arr_cpu(); 1349fe70c9cfSdp78419 else 1350932dc8e5Sdp78419 page_set_colorequiv_arr(); 1351932dc8e5Sdp78419 1352932dc8e5Sdp78419 /* 13537c478bd9Sstevel@tonic-gate * Initialize bp_mapin(). 13547c478bd9Sstevel@tonic-gate */ 13557c478bd9Sstevel@tonic-gate bp_init(shm_alignment, HAT_STRICTORDER); 13567c478bd9Sstevel@tonic-gate 13577c478bd9Sstevel@tonic-gate /* 1358bb57d1f5Sjc25722 * Reserve space for panicbuf, intr_vec_table, reserved interrupt 1359bb57d1f5Sjc25722 * vector data structures and MPO mblock structs from the 32-bit heap. 13607c478bd9Sstevel@tonic-gate */ 13617c478bd9Sstevel@tonic-gate (void) vmem_xalloc(heap32_arena, PANICBUFSIZE, PAGESIZE, 0, 0, 13627c478bd9Sstevel@tonic-gate panicbuf, panicbuf + PANICBUFSIZE, 13637c478bd9Sstevel@tonic-gate VM_NOSLEEP | VM_BESTFIT | VM_PANIC); 13647c478bd9Sstevel@tonic-gate 13657c478bd9Sstevel@tonic-gate (void) vmem_xalloc(heap32_arena, IVSIZE, PAGESIZE, 0, 0, 1366b0fc0e77Sgovinda intr_vec_table, (caddr_t)intr_vec_table + IVSIZE, 13677c478bd9Sstevel@tonic-gate VM_NOSLEEP | VM_BESTFIT | VM_PANIC); 13687c478bd9Sstevel@tonic-gate 1369bb57d1f5Sjc25722 if (mpo_heap32_bufsz > (size_t)0) { 1370bb57d1f5Sjc25722 (void) vmem_xalloc(heap32_arena, mpo_heap32_bufsz, 1371bb57d1f5Sjc25722 PAGESIZE, 0, 0, mpo_heap32_buf, 1372bb57d1f5Sjc25722 mpo_heap32_buf + mpo_heap32_bufsz, 1373bb57d1f5Sjc25722 VM_NOSLEEP | VM_BESTFIT | VM_PANIC); 1374bb57d1f5Sjc25722 } 13757c478bd9Sstevel@tonic-gate mem_config_init(); 13767c478bd9Sstevel@tonic-gate } 13777c478bd9Sstevel@tonic-gate 13787c478bd9Sstevel@tonic-gate static void 13797c478bd9Sstevel@tonic-gate startup_modules(void) 13807c478bd9Sstevel@tonic-gate { 1381*986fd29aSsetje int nhblk1, nhblk8; 13827c478bd9Sstevel@tonic-gate size_t nhblksz; 1383bb121940Sdp78419 pgcnt_t pages_per_hblk; 13847c478bd9Sstevel@tonic-gate size_t hme8blk_sz, hme1blk_sz; 13857c478bd9Sstevel@tonic-gate 13867c478bd9Sstevel@tonic-gate /* 13877c478bd9Sstevel@tonic-gate * Let the platforms have a chance to change default 13887c478bd9Sstevel@tonic-gate * values before reading system file. 13897c478bd9Sstevel@tonic-gate */ 13907c478bd9Sstevel@tonic-gate if (&set_platform_defaults) 13917c478bd9Sstevel@tonic-gate set_platform_defaults(); 13927c478bd9Sstevel@tonic-gate 13937c478bd9Sstevel@tonic-gate /* 13947c478bd9Sstevel@tonic-gate * Calculate default settings of system parameters based upon 13957c478bd9Sstevel@tonic-gate * maxusers, yet allow to be overridden via the /etc/system file. 13967c478bd9Sstevel@tonic-gate */ 13977c478bd9Sstevel@tonic-gate param_calc(0); 13987c478bd9Sstevel@tonic-gate 13997c478bd9Sstevel@tonic-gate mod_setup(); 14007c478bd9Sstevel@tonic-gate 14017c478bd9Sstevel@tonic-gate /* 14027c478bd9Sstevel@tonic-gate * If this is a positron, complain and halt. 14037c478bd9Sstevel@tonic-gate */ 14047c478bd9Sstevel@tonic-gate if (&iam_positron && iam_positron()) { 14057c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "This hardware platform is not supported" 14067c478bd9Sstevel@tonic-gate " by this release of Solaris.\n"); 14077c478bd9Sstevel@tonic-gate #ifdef DEBUG 14087c478bd9Sstevel@tonic-gate prom_enter_mon(); /* Type 'go' to resume */ 14097c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Booting an unsupported platform.\n"); 14107c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Booting with down-rev firmware.\n"); 14117c478bd9Sstevel@tonic-gate 14127c478bd9Sstevel@tonic-gate #else /* DEBUG */ 14137c478bd9Sstevel@tonic-gate halt(0); 14147c478bd9Sstevel@tonic-gate #endif /* DEBUG */ 14157c478bd9Sstevel@tonic-gate } 14167c478bd9Sstevel@tonic-gate 14177c478bd9Sstevel@tonic-gate /* 14187c478bd9Sstevel@tonic-gate * If we are running firmware that isn't 64-bit ready 14197c478bd9Sstevel@tonic-gate * then complain and halt. 14207c478bd9Sstevel@tonic-gate */ 14217c478bd9Sstevel@tonic-gate do_prom_version_check(); 14227c478bd9Sstevel@tonic-gate 14237c478bd9Sstevel@tonic-gate /* 14247c478bd9Sstevel@tonic-gate * Initialize system parameters 14257c478bd9Sstevel@tonic-gate */ 14267c478bd9Sstevel@tonic-gate param_init(); 14277c478bd9Sstevel@tonic-gate 14287c478bd9Sstevel@tonic-gate /* 14297c478bd9Sstevel@tonic-gate * maxmem is the amount of physical memory we're playing with. 14307c478bd9Sstevel@tonic-gate */ 14317c478bd9Sstevel@tonic-gate maxmem = physmem; 14327c478bd9Sstevel@tonic-gate 14337c478bd9Sstevel@tonic-gate /* Set segkp limits. */ 1434ae115bc7Smrj ncbase = kdi_segdebugbase; 1435ae115bc7Smrj ncend = kdi_segdebugbase; 14367c478bd9Sstevel@tonic-gate 14377c478bd9Sstevel@tonic-gate /* 14387c478bd9Sstevel@tonic-gate * Initialize the hat layer. 14397c478bd9Sstevel@tonic-gate */ 14407c478bd9Sstevel@tonic-gate hat_init(); 14417c478bd9Sstevel@tonic-gate 14427c478bd9Sstevel@tonic-gate /* 14437c478bd9Sstevel@tonic-gate * Initialize segment management stuff. 14447c478bd9Sstevel@tonic-gate */ 14457c478bd9Sstevel@tonic-gate seg_init(); 14467c478bd9Sstevel@tonic-gate 14477c478bd9Sstevel@tonic-gate /* 14487c478bd9Sstevel@tonic-gate * Create the va>tte handler, so the prom can understand 14497c478bd9Sstevel@tonic-gate * kernel translations. The handler is installed later, just 14507c478bd9Sstevel@tonic-gate * as we are about to take over the trap table from the prom. 14517c478bd9Sstevel@tonic-gate */ 14527c478bd9Sstevel@tonic-gate create_va_to_tte(); 14537c478bd9Sstevel@tonic-gate 14547c478bd9Sstevel@tonic-gate /* 14557c478bd9Sstevel@tonic-gate * Load the forthdebugger (optional) 14567c478bd9Sstevel@tonic-gate */ 14577c478bd9Sstevel@tonic-gate forthdebug_init(); 14587c478bd9Sstevel@tonic-gate 14597c478bd9Sstevel@tonic-gate /* 14607c478bd9Sstevel@tonic-gate * Create OBP node for console input callbacks 14617c478bd9Sstevel@tonic-gate * if it is needed. 14627c478bd9Sstevel@tonic-gate */ 1463fea9cb91Slq150181 startup_create_io_node(); 14647c478bd9Sstevel@tonic-gate 14657c478bd9Sstevel@tonic-gate if (modloadonly("fs", "specfs") == -1) 14667c478bd9Sstevel@tonic-gate halt("Can't load specfs"); 14677c478bd9Sstevel@tonic-gate 14687c478bd9Sstevel@tonic-gate if (modloadonly("fs", "devfs") == -1) 14697c478bd9Sstevel@tonic-gate halt("Can't load devfs"); 14707c478bd9Sstevel@tonic-gate 14717c478bd9Sstevel@tonic-gate if (modloadonly("misc", "swapgeneric") == -1) 14727c478bd9Sstevel@tonic-gate halt("Can't load swapgeneric"); 14737c478bd9Sstevel@tonic-gate 147445916cd2Sjpk (void) modloadonly("sys", "lbl_edition"); 147545916cd2Sjpk 14767c478bd9Sstevel@tonic-gate dispinit(); 14777c478bd9Sstevel@tonic-gate 14787c478bd9Sstevel@tonic-gate /* 14797c478bd9Sstevel@tonic-gate * Infer meanings to the members of the idprom buffer. 14807c478bd9Sstevel@tonic-gate */ 14817c478bd9Sstevel@tonic-gate parse_idprom(); 14827c478bd9Sstevel@tonic-gate 14837c478bd9Sstevel@tonic-gate /* Read cluster configuration data. */ 14847c478bd9Sstevel@tonic-gate clconf_init(); 14857c478bd9Sstevel@tonic-gate 14867c478bd9Sstevel@tonic-gate setup_ddi(); 14877c478bd9Sstevel@tonic-gate 14887c478bd9Sstevel@tonic-gate /* 14897c478bd9Sstevel@tonic-gate * Lets take this opportunity to load the root device. 14907c478bd9Sstevel@tonic-gate */ 14917c478bd9Sstevel@tonic-gate if (loadrootmodules() != 0) 14927c478bd9Sstevel@tonic-gate debug_enter("Can't load the root filesystem"); 14937c478bd9Sstevel@tonic-gate 14947c478bd9Sstevel@tonic-gate /* 14957c478bd9Sstevel@tonic-gate * Load tod driver module for the tod part found on this system. 14967c478bd9Sstevel@tonic-gate * Recompute the cpu frequency/delays based on tod as tod part 14977c478bd9Sstevel@tonic-gate * tends to keep time more accurately. 14987c478bd9Sstevel@tonic-gate */ 14997c478bd9Sstevel@tonic-gate if (&load_tod_module) 15007c478bd9Sstevel@tonic-gate load_tod_module(); 15017c478bd9Sstevel@tonic-gate 15027c478bd9Sstevel@tonic-gate /* 15037c478bd9Sstevel@tonic-gate * Allow platforms to load modules which might 15047c478bd9Sstevel@tonic-gate * be needed after bootops are gone. 15057c478bd9Sstevel@tonic-gate */ 15067c478bd9Sstevel@tonic-gate if (&load_platform_modules) 15077c478bd9Sstevel@tonic-gate load_platform_modules(); 15087c478bd9Sstevel@tonic-gate 15097c478bd9Sstevel@tonic-gate setcpudelay(); 15107c478bd9Sstevel@tonic-gate 15117c478bd9Sstevel@tonic-gate copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len, 15127c478bd9Sstevel@tonic-gate &boot_physavail, &boot_physavail_len, 15137c478bd9Sstevel@tonic-gate &boot_virtavail, &boot_virtavail_len); 15147c478bd9Sstevel@tonic-gate 15157c478bd9Sstevel@tonic-gate /* 15167c478bd9Sstevel@tonic-gate * Calculation and allocation of hmeblks needed to remap 1517bb121940Sdp78419 * the memory allocated by PROM till now. 1518bb121940Sdp78419 * Overestimate the number of hblk1 elements by assuming 1519bb121940Sdp78419 * worst case of TTE64K mappings. 1520bb121940Sdp78419 * sfmmu_hblk_alloc will panic if this calculation is wrong. 15217c478bd9Sstevel@tonic-gate */ 1522bb121940Sdp78419 bop_alloc_pages = btopr(kmem64_end - kmem64_base); 1523bb121940Sdp78419 pages_per_hblk = btop(HMEBLK_SPAN(TTE64K)); 1524bb121940Sdp78419 bop_alloc_pages = roundup(bop_alloc_pages, pages_per_hblk); 1525bb121940Sdp78419 nhblk1 = bop_alloc_pages / pages_per_hblk + hblk1_min; 15267c478bd9Sstevel@tonic-gate 1527bb121940Sdp78419 bop_alloc_pages = size_virtalloc(boot_virtavail, boot_virtavail_len); 1528bb121940Sdp78419 1529bb121940Sdp78419 /* sfmmu_init_nucleus_hblks expects properly aligned data structures */ 15307c478bd9Sstevel@tonic-gate hme8blk_sz = roundup(HME8BLK_SZ, sizeof (int64_t)); 15317c478bd9Sstevel@tonic-gate hme1blk_sz = roundup(HME1BLK_SZ, sizeof (int64_t)); 15327c478bd9Sstevel@tonic-gate 1533bb121940Sdp78419 bop_alloc_pages += btopr(nhblk1 * hme1blk_sz); 1534bb121940Sdp78419 15357c478bd9Sstevel@tonic-gate pages_per_hblk = btop(HMEBLK_SPAN(TTE8K)); 1536bb121940Sdp78419 nhblk8 = 0; 1537bb121940Sdp78419 while (bop_alloc_pages > 1) { 15387c478bd9Sstevel@tonic-gate bop_alloc_pages = roundup(bop_alloc_pages, pages_per_hblk); 1539bb121940Sdp78419 nhblk8 += bop_alloc_pages /= pages_per_hblk; 1540bb121940Sdp78419 bop_alloc_pages *= hme8blk_sz; 1541bb121940Sdp78419 bop_alloc_pages = btopr(bop_alloc_pages); 1542bb121940Sdp78419 } 1543bb121940Sdp78419 nhblk8 += 2; 15447c478bd9Sstevel@tonic-gate 15457c478bd9Sstevel@tonic-gate /* 15467c478bd9Sstevel@tonic-gate * Since hblk8's can hold up to 64k of mappings aligned on a 64k 15477c478bd9Sstevel@tonic-gate * boundary, the number of hblk8's needed to map the entries in the 15487c478bd9Sstevel@tonic-gate * boot_virtavail list needs to be adjusted to take this into 15497c478bd9Sstevel@tonic-gate * consideration. Thus, we need to add additional hblk8's since it 15507c478bd9Sstevel@tonic-gate * is possible that an hblk8 will not have all 8 slots used due to 15517c478bd9Sstevel@tonic-gate * alignment constraints. Since there were boot_virtavail_len entries 15527c478bd9Sstevel@tonic-gate * in that list, we need to add that many hblk8's to the number 15537c478bd9Sstevel@tonic-gate * already calculated to make sure we don't underestimate. 15547c478bd9Sstevel@tonic-gate */ 15557c478bd9Sstevel@tonic-gate nhblk8 += boot_virtavail_len; 15567c478bd9Sstevel@tonic-gate nhblksz = nhblk8 * hme8blk_sz + nhblk1 * hme1blk_sz; 15577c478bd9Sstevel@tonic-gate 15587c478bd9Sstevel@tonic-gate /* Allocate in pagesize chunks */ 15597c478bd9Sstevel@tonic-gate nhblksz = roundup(nhblksz, MMU_PAGESIZE); 15607c478bd9Sstevel@tonic-gate hblk_base = kmem_zalloc(nhblksz, KM_SLEEP); 15617c478bd9Sstevel@tonic-gate sfmmu_init_nucleus_hblks(hblk_base, nhblksz, nhblk8, nhblk1); 15627c478bd9Sstevel@tonic-gate } 15637c478bd9Sstevel@tonic-gate 15647c478bd9Sstevel@tonic-gate static void 15657c478bd9Sstevel@tonic-gate startup_bop_gone(void) 15667c478bd9Sstevel@tonic-gate { 15677c478bd9Sstevel@tonic-gate 15687c478bd9Sstevel@tonic-gate /* 15691ae08745Sheppo * Destroy the MD initialized at startup 15701ae08745Sheppo * The startup initializes the MD framework 15711ae08745Sheppo * using prom and BOP alloc free it now. 15721ae08745Sheppo */ 15731ae08745Sheppo mach_descrip_startup_fini(); 15741ae08745Sheppo 15751ae08745Sheppo /* 1576*986fd29aSsetje * We're done with prom allocations. 15777c478bd9Sstevel@tonic-gate */ 1578*986fd29aSsetje bop_fini(); 15797c478bd9Sstevel@tonic-gate 15807c478bd9Sstevel@tonic-gate copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len, 15817c478bd9Sstevel@tonic-gate &boot_physavail, &boot_physavail_len, 15827c478bd9Sstevel@tonic-gate &boot_virtavail, &boot_virtavail_len); 15837c478bd9Sstevel@tonic-gate 15847c478bd9Sstevel@tonic-gate /* 15857c478bd9Sstevel@tonic-gate * setup physically contiguous area twice as large as the ecache. 15867c478bd9Sstevel@tonic-gate * this is used while doing displacement flush of ecaches 15877c478bd9Sstevel@tonic-gate */ 15887c478bd9Sstevel@tonic-gate if (&ecache_flush_address) { 15897c478bd9Sstevel@tonic-gate ecache_flushaddr = ecache_flush_address(); 15907c478bd9Sstevel@tonic-gate if (ecache_flushaddr == (uint64_t)-1) { 15917c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, 15927c478bd9Sstevel@tonic-gate "startup: no memory to set ecache_flushaddr"); 15937c478bd9Sstevel@tonic-gate } 15947c478bd9Sstevel@tonic-gate } 15957c478bd9Sstevel@tonic-gate 15967c478bd9Sstevel@tonic-gate /* 15977c478bd9Sstevel@tonic-gate * Virtual available next. 15987c478bd9Sstevel@tonic-gate */ 15997c478bd9Sstevel@tonic-gate ASSERT(virt_avail != NULL); 16007c478bd9Sstevel@tonic-gate memlist_free_list(virt_avail); 16017c478bd9Sstevel@tonic-gate virt_avail = memlist; 16027c478bd9Sstevel@tonic-gate copy_memlist(boot_virtavail, boot_virtavail_len, &memlist); 16037c478bd9Sstevel@tonic-gate 16047c478bd9Sstevel@tonic-gate } 16057c478bd9Sstevel@tonic-gate 16067c478bd9Sstevel@tonic-gate 16077c478bd9Sstevel@tonic-gate /* 16087c478bd9Sstevel@tonic-gate * startup_fixup_physavail - called from mach_sfmmu.c after the final 16097c478bd9Sstevel@tonic-gate * allocations have been performed. We can't call it in startup_bop_gone 16107c478bd9Sstevel@tonic-gate * since later operations can cause obp to allocate more memory. 16117c478bd9Sstevel@tonic-gate */ 16127c478bd9Sstevel@tonic-gate void 16137c478bd9Sstevel@tonic-gate startup_fixup_physavail(void) 16147c478bd9Sstevel@tonic-gate { 16157c478bd9Sstevel@tonic-gate struct memlist *cur; 1616bb121940Sdp78419 size_t kmem64_overmap_size = kmem64_aligned_end - kmem64_end; 1617bb121940Sdp78419 1618bb121940Sdp78419 PRM_DEBUG(kmem64_overmap_size); 16197c478bd9Sstevel@tonic-gate 16207c478bd9Sstevel@tonic-gate /* 16217c478bd9Sstevel@tonic-gate * take the most current snapshot we can by calling mem-update 16227c478bd9Sstevel@tonic-gate */ 16237c478bd9Sstevel@tonic-gate copy_boot_memlists(&boot_physinstalled, &boot_physinstalled_len, 16247c478bd9Sstevel@tonic-gate &boot_physavail, &boot_physavail_len, 16257c478bd9Sstevel@tonic-gate &boot_virtavail, &boot_virtavail_len); 16267c478bd9Sstevel@tonic-gate 16277c478bd9Sstevel@tonic-gate /* 16287c478bd9Sstevel@tonic-gate * Copy phys_avail list, again. 16297c478bd9Sstevel@tonic-gate * Both the kernel/boot and the prom have been allocating 16307c478bd9Sstevel@tonic-gate * from the original list we copied earlier. 16317c478bd9Sstevel@tonic-gate */ 16327c478bd9Sstevel@tonic-gate cur = memlist; 1633*986fd29aSsetje copy_memlist(boot_physavail, boot_physavail_len, &memlist); 16347c478bd9Sstevel@tonic-gate 16357c478bd9Sstevel@tonic-gate /* 1636bb121940Sdp78419 * Add any unused kmem64 memory from overmapped page 1637bb121940Sdp78419 * (Note: va_to_pa does not work for kmem64_end) 1638bb121940Sdp78419 */ 1639bb121940Sdp78419 if (kmem64_overmap_size) { 1640bb121940Sdp78419 memlist_add(kmem64_pabase + (kmem64_end - kmem64_base), 1641*986fd29aSsetje kmem64_overmap_size, &memlist, &cur); 1642bb121940Sdp78419 } 1643bb121940Sdp78419 1644bb121940Sdp78419 /* 1645*986fd29aSsetje * Add any extra memory after e_data we added to the phys_avail list 16467c478bd9Sstevel@tonic-gate * back to the old list. 16477c478bd9Sstevel@tonic-gate */ 16487c478bd9Sstevel@tonic-gate if (ndata_remain_sz >= MMU_PAGESIZE) 16497c478bd9Sstevel@tonic-gate memlist_add(va_to_pa(nalloc_base), 16507c478bd9Sstevel@tonic-gate (uint64_t)ndata_remain_sz, &memlist, &cur); 16517c478bd9Sstevel@tonic-gate 16527c478bd9Sstevel@tonic-gate /* 16537c478bd9Sstevel@tonic-gate * There isn't any bounds checking on the memlist area 16547c478bd9Sstevel@tonic-gate * so ensure it hasn't overgrown. 16557c478bd9Sstevel@tonic-gate */ 16567c478bd9Sstevel@tonic-gate if ((caddr_t)memlist > (caddr_t)memlist_end) 16577c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "startup: memlist size exceeded"); 16587c478bd9Sstevel@tonic-gate 16597c478bd9Sstevel@tonic-gate /* 16607c478bd9Sstevel@tonic-gate * The kernel removes the pages that were allocated for it from 16617c478bd9Sstevel@tonic-gate * the freelist, but we now have to find any -extra- pages that 16627c478bd9Sstevel@tonic-gate * the prom has allocated for it's own book-keeping, and remove 16637c478bd9Sstevel@tonic-gate * them from the freelist too. sigh. 16647c478bd9Sstevel@tonic-gate */ 1665*986fd29aSsetje sync_memlists(phys_avail, cur); 16667c478bd9Sstevel@tonic-gate 16677c478bd9Sstevel@tonic-gate ASSERT(phys_avail != NULL); 16687c478bd9Sstevel@tonic-gate memlist_free_list(phys_avail); 16697c478bd9Sstevel@tonic-gate phys_avail = cur; 16707c478bd9Sstevel@tonic-gate 16717c478bd9Sstevel@tonic-gate } 16727c478bd9Sstevel@tonic-gate 16737c478bd9Sstevel@tonic-gate static void 16747c478bd9Sstevel@tonic-gate startup_vm(void) 16757c478bd9Sstevel@tonic-gate { 16767c478bd9Sstevel@tonic-gate size_t i; 16777c478bd9Sstevel@tonic-gate struct segmap_crargs a; 16787c478bd9Sstevel@tonic-gate struct segkpm_crargs b; 16797c478bd9Sstevel@tonic-gate 16807c478bd9Sstevel@tonic-gate uint64_t avmem; 16817c478bd9Sstevel@tonic-gate caddr_t va; 16827c478bd9Sstevel@tonic-gate pgcnt_t max_phys_segkp; 16837c478bd9Sstevel@tonic-gate int mnode; 16847c478bd9Sstevel@tonic-gate 1685ec25b48fSsusans extern int use_brk_lpg, use_stk_lpg; 1686beb1bda0Sdavemq 16877c478bd9Sstevel@tonic-gate /* 16887c478bd9Sstevel@tonic-gate * get prom's mappings, create hments for them and switch 16897c478bd9Sstevel@tonic-gate * to the kernel context. 16907c478bd9Sstevel@tonic-gate */ 16917c478bd9Sstevel@tonic-gate hat_kern_setup(); 16927c478bd9Sstevel@tonic-gate 16937c478bd9Sstevel@tonic-gate /* 16947c478bd9Sstevel@tonic-gate * Take over trap table 16957c478bd9Sstevel@tonic-gate */ 16967c478bd9Sstevel@tonic-gate setup_trap_table(); 16977c478bd9Sstevel@tonic-gate 16987c478bd9Sstevel@tonic-gate /* 16997c478bd9Sstevel@tonic-gate * Install the va>tte handler, so that the prom can handle 17007c478bd9Sstevel@tonic-gate * misses and understand the kernel table layout in case 17017c478bd9Sstevel@tonic-gate * we need call into the prom. 17027c478bd9Sstevel@tonic-gate */ 17037c478bd9Sstevel@tonic-gate install_va_to_tte(); 17047c478bd9Sstevel@tonic-gate 17057c478bd9Sstevel@tonic-gate /* 17067c478bd9Sstevel@tonic-gate * Set a flag to indicate that the tba has been taken over. 17077c478bd9Sstevel@tonic-gate */ 17087c478bd9Sstevel@tonic-gate tba_taken_over = 1; 17097c478bd9Sstevel@tonic-gate 17107c478bd9Sstevel@tonic-gate /* initialize MMU primary context register */ 17117c478bd9Sstevel@tonic-gate mmu_init_kcontext(); 17127c478bd9Sstevel@tonic-gate 17137c478bd9Sstevel@tonic-gate /* 17147c478bd9Sstevel@tonic-gate * The boot cpu can now take interrupts, x-calls, x-traps 17157c478bd9Sstevel@tonic-gate */ 17167c478bd9Sstevel@tonic-gate CPUSET_ADD(cpu_ready_set, CPU->cpu_id); 17177c478bd9Sstevel@tonic-gate CPU->cpu_flags |= (CPU_READY | CPU_ENABLE | CPU_EXISTS); 17187c478bd9Sstevel@tonic-gate 17197c478bd9Sstevel@tonic-gate /* 17207c478bd9Sstevel@tonic-gate * Set a flag to tell write_scb_int() that it can access V_TBR_WR_ADDR. 17217c478bd9Sstevel@tonic-gate */ 17227c478bd9Sstevel@tonic-gate tbr_wr_addr_inited = 1; 17237c478bd9Sstevel@tonic-gate 17247c478bd9Sstevel@tonic-gate /* 17257c478bd9Sstevel@tonic-gate * Initialize VM system, and map kernel address space. 17267c478bd9Sstevel@tonic-gate */ 17277c478bd9Sstevel@tonic-gate kvm_init(); 17287c478bd9Sstevel@tonic-gate 17297c478bd9Sstevel@tonic-gate /* 17307c478bd9Sstevel@tonic-gate * If the following is true, someone has patched 17317c478bd9Sstevel@tonic-gate * phsymem to be less than the number of pages that 17327c478bd9Sstevel@tonic-gate * the system actually has. Remove pages until system 17337c478bd9Sstevel@tonic-gate * memory is limited to the requested amount. Since we 17347c478bd9Sstevel@tonic-gate * have allocated page structures for all pages, we 17357c478bd9Sstevel@tonic-gate * correct the amount of memory we want to remove 17367c478bd9Sstevel@tonic-gate * by the size of the memory used to hold page structures 17377c478bd9Sstevel@tonic-gate * for the non-used pages. 17387c478bd9Sstevel@tonic-gate */ 17397c478bd9Sstevel@tonic-gate if (physmem < npages) { 17407c478bd9Sstevel@tonic-gate pgcnt_t diff, off; 17417c478bd9Sstevel@tonic-gate struct page *pp; 17427c478bd9Sstevel@tonic-gate struct seg kseg; 17437c478bd9Sstevel@tonic-gate 17447c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "limiting physmem to %ld pages", physmem); 17457c478bd9Sstevel@tonic-gate 17467c478bd9Sstevel@tonic-gate off = 0; 17477c478bd9Sstevel@tonic-gate diff = npages - physmem; 17487c478bd9Sstevel@tonic-gate diff -= mmu_btopr(diff * sizeof (struct page)); 17497c478bd9Sstevel@tonic-gate kseg.s_as = &kas; 17507c478bd9Sstevel@tonic-gate while (diff--) { 17517c478bd9Sstevel@tonic-gate pp = page_create_va(&unused_pages_vp, (offset_t)off, 17527c478bd9Sstevel@tonic-gate MMU_PAGESIZE, PG_WAIT | PG_EXCL, 17537c478bd9Sstevel@tonic-gate &kseg, (caddr_t)off); 17547c478bd9Sstevel@tonic-gate if (pp == NULL) 17557c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "limited physmem too much!"); 17567c478bd9Sstevel@tonic-gate page_io_unlock(pp); 17577c478bd9Sstevel@tonic-gate page_downgrade(pp); 17587c478bd9Sstevel@tonic-gate availrmem--; 17597c478bd9Sstevel@tonic-gate off += MMU_PAGESIZE; 17607c478bd9Sstevel@tonic-gate } 17617c478bd9Sstevel@tonic-gate } 17627c478bd9Sstevel@tonic-gate 17637c478bd9Sstevel@tonic-gate /* 17647c478bd9Sstevel@tonic-gate * When printing memory, show the total as physmem less 17657c478bd9Sstevel@tonic-gate * that stolen by a debugger. 17667c478bd9Sstevel@tonic-gate */ 17677c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?mem = %ldK (0x%lx000)\n", 17687c478bd9Sstevel@tonic-gate (ulong_t)(physinstalled) << (PAGESHIFT - 10), 17697c478bd9Sstevel@tonic-gate (ulong_t)(physinstalled) << (PAGESHIFT - 12)); 17707c478bd9Sstevel@tonic-gate 17717c478bd9Sstevel@tonic-gate avmem = (uint64_t)freemem << PAGESHIFT; 17727c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?avail mem = %lld\n", (unsigned long long)avmem); 17737c478bd9Sstevel@tonic-gate 1774ec25b48fSsusans /* 1775ec25b48fSsusans * For small memory systems disable automatic large pages. 1776ec25b48fSsusans */ 1777ec25b48fSsusans if (physmem < privm_lpg_min_physmem) { 1778beb1bda0Sdavemq use_brk_lpg = 0; 1779beb1bda0Sdavemq use_stk_lpg = 0; 1780beb1bda0Sdavemq } 1781beb1bda0Sdavemq 17827c478bd9Sstevel@tonic-gate /* 17837c478bd9Sstevel@tonic-gate * Perform platform specific freelist processing 17847c478bd9Sstevel@tonic-gate */ 17857c478bd9Sstevel@tonic-gate if (&plat_freelist_process) { 17867c478bd9Sstevel@tonic-gate for (mnode = 0; mnode < max_mem_nodes; mnode++) 17877c478bd9Sstevel@tonic-gate if (mem_node_config[mnode].exists) 17887c478bd9Sstevel@tonic-gate plat_freelist_process(mnode); 17897c478bd9Sstevel@tonic-gate } 17907c478bd9Sstevel@tonic-gate 17917c478bd9Sstevel@tonic-gate /* 17927c478bd9Sstevel@tonic-gate * Initialize the segkp segment type. We position it 17937c478bd9Sstevel@tonic-gate * after the configured tables and buffers (whose end 17947c478bd9Sstevel@tonic-gate * is given by econtig) and before V_WKBASE_ADDR. 17957c478bd9Sstevel@tonic-gate * Also in this area is segkmap (size SEGMAPSIZE). 17967c478bd9Sstevel@tonic-gate */ 17977c478bd9Sstevel@tonic-gate 17987c478bd9Sstevel@tonic-gate /* XXX - cache alignment? */ 17997c478bd9Sstevel@tonic-gate va = (caddr_t)SEGKPBASE; 18007c478bd9Sstevel@tonic-gate ASSERT(((uintptr_t)va & PAGEOFFSET) == 0); 18017c478bd9Sstevel@tonic-gate 18027c478bd9Sstevel@tonic-gate max_phys_segkp = (physmem * 2); 18037c478bd9Sstevel@tonic-gate 18047c478bd9Sstevel@tonic-gate if (segkpsize < btop(SEGKPMINSIZE) || segkpsize > btop(SEGKPMAXSIZE)) { 18057c478bd9Sstevel@tonic-gate segkpsize = btop(SEGKPDEFSIZE); 18067c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Illegal value for segkpsize. " 18077c478bd9Sstevel@tonic-gate "segkpsize has been reset to %ld pages", segkpsize); 18087c478bd9Sstevel@tonic-gate } 18097c478bd9Sstevel@tonic-gate 18107c478bd9Sstevel@tonic-gate i = ptob(MIN(segkpsize, max_phys_segkp)); 18117c478bd9Sstevel@tonic-gate 18127c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER); 18137c478bd9Sstevel@tonic-gate if (seg_attach(&kas, va, i, segkp) < 0) 18147c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "startup: cannot attach segkp"); 18157c478bd9Sstevel@tonic-gate if (segkp_create(segkp) != 0) 18167c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "startup: segkp_create failed"); 18177c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock); 18187c478bd9Sstevel@tonic-gate 18197c478bd9Sstevel@tonic-gate /* 18207c478bd9Sstevel@tonic-gate * kpm segment 18217c478bd9Sstevel@tonic-gate */ 18227c478bd9Sstevel@tonic-gate segmap_kpm = kpm_enable && 18237c478bd9Sstevel@tonic-gate segmap_kpm && PAGESIZE == MAXBSIZE; 18247c478bd9Sstevel@tonic-gate 18257c478bd9Sstevel@tonic-gate if (kpm_enable) { 18267c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER); 18277c478bd9Sstevel@tonic-gate 18287c478bd9Sstevel@tonic-gate /* 18297c478bd9Sstevel@tonic-gate * The segkpm virtual range range is larger than the 18307c478bd9Sstevel@tonic-gate * actual physical memory size and also covers gaps in 18317c478bd9Sstevel@tonic-gate * the physical address range for the following reasons: 18327c478bd9Sstevel@tonic-gate * . keep conversion between segkpm and physical addresses 18337c478bd9Sstevel@tonic-gate * simple, cheap and unambiguous. 18347c478bd9Sstevel@tonic-gate * . avoid extension/shrink of the the segkpm in case of DR. 18357c478bd9Sstevel@tonic-gate * . avoid complexity for handling of virtual addressed 18367c478bd9Sstevel@tonic-gate * caches, segkpm and the regular mapping scheme must be 18377c478bd9Sstevel@tonic-gate * kept in sync wrt. the virtual color of mapped pages. 18387c478bd9Sstevel@tonic-gate * Any accesses to virtual segkpm ranges not backed by 18397c478bd9Sstevel@tonic-gate * physical memory will fall through the memseg pfn hash 18407c478bd9Sstevel@tonic-gate * and will be handled in segkpm_fault. 18417c478bd9Sstevel@tonic-gate * Additional kpm_size spaces needed for vac alias prevention. 18427c478bd9Sstevel@tonic-gate */ 18437c478bd9Sstevel@tonic-gate if (seg_attach(&kas, kpm_vbase, kpm_size * vac_colors, 18447c478bd9Sstevel@tonic-gate segkpm) < 0) 18457c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "cannot attach segkpm"); 18467c478bd9Sstevel@tonic-gate 18477c478bd9Sstevel@tonic-gate b.prot = PROT_READ | PROT_WRITE; 18487c478bd9Sstevel@tonic-gate b.nvcolors = shm_alignment >> MMU_PAGESHIFT; 18497c478bd9Sstevel@tonic-gate 18507c478bd9Sstevel@tonic-gate if (segkpm_create(segkpm, (caddr_t)&b) != 0) 18517c478bd9Sstevel@tonic-gate panic("segkpm_create segkpm"); 18527c478bd9Sstevel@tonic-gate 18537c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock); 1854fedab560Sae112802 1855fedab560Sae112802 mach_kpm_init(); 18567c478bd9Sstevel@tonic-gate } 18577c478bd9Sstevel@tonic-gate 1858ad23a2dbSjohansen if (!segzio_fromheap) { 1859ad23a2dbSjohansen size_t size; 1860a778305aSjohansen size_t physmem_b = mmu_ptob(physmem); 1861ad23a2dbSjohansen 1862ad23a2dbSjohansen /* size is in bytes, segziosize is in pages */ 1863ad23a2dbSjohansen if (segziosize == 0) { 1864a778305aSjohansen size = physmem_b; 1865ad23a2dbSjohansen } else { 1866ad23a2dbSjohansen size = mmu_ptob(segziosize); 1867ad23a2dbSjohansen } 1868ad23a2dbSjohansen 1869ad23a2dbSjohansen if (size < SEGZIOMINSIZE) { 1870ad23a2dbSjohansen size = SEGZIOMINSIZE; 1871a778305aSjohansen } else if (size > SEGZIOMAXSIZE) { 1872a778305aSjohansen size = SEGZIOMAXSIZE; 1873a778305aSjohansen /* 1874a778305aSjohansen * On 64-bit x86, we only have 2TB of KVA. This exists 1875a778305aSjohansen * for parity with x86. 1876a778305aSjohansen * 1877a778305aSjohansen * SEGZIOMAXSIZE is capped at 512gb so that segzio 1878a778305aSjohansen * doesn't consume all of KVA. However, if we have a 1879a778305aSjohansen * system that has more thant 512gb of physical memory, 1880a778305aSjohansen * we can actually consume about half of the difference 1881a778305aSjohansen * between 512gb and the rest of the available physical 1882a778305aSjohansen * memory. 1883a778305aSjohansen */ 1884a778305aSjohansen if (physmem_b > SEGZIOMAXSIZE) { 1885a778305aSjohansen size += (physmem_b - SEGZIOMAXSIZE) / 2; 1886a778305aSjohansen } 1887ad23a2dbSjohansen } 1888ad23a2dbSjohansen segziosize = mmu_btop(roundup(size, MMU_PAGESIZE)); 1889ad23a2dbSjohansen /* put the base of the ZIO segment after the kpm segment */ 1890ad23a2dbSjohansen segzio_base = kpm_vbase + (kpm_size * vac_colors); 1891ad23a2dbSjohansen PRM_DEBUG(segziosize); 1892ad23a2dbSjohansen PRM_DEBUG(segzio_base); 1893ad23a2dbSjohansen 1894ad23a2dbSjohansen /* 1895ad23a2dbSjohansen * On some platforms, kvm_init is called after the kpm 1896ad23a2dbSjohansen * sizes have been determined. On SPARC, kvm_init is called 1897ad23a2dbSjohansen * before, so we have to attach the kzioseg after kvm is 1898ad23a2dbSjohansen * initialized, otherwise we'll try to allocate from the boot 1899ad23a2dbSjohansen * area since the kernel heap hasn't yet been configured. 1900ad23a2dbSjohansen */ 1901ad23a2dbSjohansen rw_enter(&kas.a_lock, RW_WRITER); 1902ad23a2dbSjohansen 1903ad23a2dbSjohansen (void) seg_attach(&kas, segzio_base, mmu_ptob(segziosize), 1904ad23a2dbSjohansen &kzioseg); 1905ad23a2dbSjohansen (void) segkmem_zio_create(&kzioseg); 1906ad23a2dbSjohansen 1907ad23a2dbSjohansen /* create zio area covering new segment */ 1908ad23a2dbSjohansen segkmem_zio_init(segzio_base, mmu_ptob(segziosize)); 1909ad23a2dbSjohansen 1910ad23a2dbSjohansen rw_exit(&kas.a_lock); 1911ad23a2dbSjohansen } 1912ad23a2dbSjohansen 1913ad23a2dbSjohansen 19147c478bd9Sstevel@tonic-gate /* 19157c478bd9Sstevel@tonic-gate * Now create generic mapping segment. This mapping 19167c478bd9Sstevel@tonic-gate * goes SEGMAPSIZE beyond SEGMAPBASE. But if the total 19177c478bd9Sstevel@tonic-gate * virtual address is greater than the amount of free 19187c478bd9Sstevel@tonic-gate * memory that is available, then we trim back the 19197c478bd9Sstevel@tonic-gate * segment size to that amount 19207c478bd9Sstevel@tonic-gate */ 19217c478bd9Sstevel@tonic-gate va = (caddr_t)SEGMAPBASE; 19227c478bd9Sstevel@tonic-gate 19237c478bd9Sstevel@tonic-gate /* 19247c478bd9Sstevel@tonic-gate * 1201049: segkmap base address must be MAXBSIZE aligned 19257c478bd9Sstevel@tonic-gate */ 19267c478bd9Sstevel@tonic-gate ASSERT(((uintptr_t)va & MAXBOFFSET) == 0); 19277c478bd9Sstevel@tonic-gate 19287c478bd9Sstevel@tonic-gate /* 19297c478bd9Sstevel@tonic-gate * Set size of segmap to percentage of freemem at boot, 19307c478bd9Sstevel@tonic-gate * but stay within the allowable range 19317c478bd9Sstevel@tonic-gate * Note we take percentage before converting from pages 19327c478bd9Sstevel@tonic-gate * to bytes to avoid an overflow on 32-bit kernels. 19337c478bd9Sstevel@tonic-gate */ 19347c478bd9Sstevel@tonic-gate i = mmu_ptob((freemem * segmap_percent) / 100); 19357c478bd9Sstevel@tonic-gate 19367c478bd9Sstevel@tonic-gate if (i < MINMAPSIZE) 19377c478bd9Sstevel@tonic-gate i = MINMAPSIZE; 19387c478bd9Sstevel@tonic-gate 19397c478bd9Sstevel@tonic-gate if (i > MIN(SEGMAPSIZE, mmu_ptob(freemem))) 19407c478bd9Sstevel@tonic-gate i = MIN(SEGMAPSIZE, mmu_ptob(freemem)); 19417c478bd9Sstevel@tonic-gate 19427c478bd9Sstevel@tonic-gate i &= MAXBMASK; /* 1201049: segkmap size must be MAXBSIZE aligned */ 19437c478bd9Sstevel@tonic-gate 19447c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER); 19457c478bd9Sstevel@tonic-gate if (seg_attach(&kas, va, i, segkmap) < 0) 19467c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "cannot attach segkmap"); 19477c478bd9Sstevel@tonic-gate 19487c478bd9Sstevel@tonic-gate a.prot = PROT_READ | PROT_WRITE; 19497c478bd9Sstevel@tonic-gate a.shmsize = shm_alignment; 19507c478bd9Sstevel@tonic-gate a.nfreelist = 0; /* use segmap driver defaults */ 19517c478bd9Sstevel@tonic-gate 19527c478bd9Sstevel@tonic-gate if (segmap_create(segkmap, (caddr_t)&a) != 0) 19537c478bd9Sstevel@tonic-gate panic("segmap_create segkmap"); 19547c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock); 19557c478bd9Sstevel@tonic-gate 19567c478bd9Sstevel@tonic-gate segdev_init(); 19577c478bd9Sstevel@tonic-gate } 19587c478bd9Sstevel@tonic-gate 19597c478bd9Sstevel@tonic-gate static void 19607c478bd9Sstevel@tonic-gate startup_end(void) 19617c478bd9Sstevel@tonic-gate { 19627c478bd9Sstevel@tonic-gate if ((caddr_t)memlist > (caddr_t)memlist_end) 19637c478bd9Sstevel@tonic-gate panic("memlist overflow 2"); 19647c478bd9Sstevel@tonic-gate memlist_free_block((caddr_t)memlist, 19657c478bd9Sstevel@tonic-gate ((caddr_t)memlist_end - (caddr_t)memlist)); 19667c478bd9Sstevel@tonic-gate memlist = NULL; 19677c478bd9Sstevel@tonic-gate 19687c478bd9Sstevel@tonic-gate /* enable page_relocation since OBP is now done */ 19697c478bd9Sstevel@tonic-gate page_relocate_ready = 1; 19707c478bd9Sstevel@tonic-gate 19717c478bd9Sstevel@tonic-gate /* 19727c478bd9Sstevel@tonic-gate * Perform tasks that get done after most of the VM 19737c478bd9Sstevel@tonic-gate * initialization has been done but before the clock 19747c478bd9Sstevel@tonic-gate * and other devices get started. 19757c478bd9Sstevel@tonic-gate */ 19767c478bd9Sstevel@tonic-gate kern_setup1(); 19777c478bd9Sstevel@tonic-gate 19787c478bd9Sstevel@tonic-gate /* 19797c478bd9Sstevel@tonic-gate * Intialize the VM arenas for allocating physically 19807c478bd9Sstevel@tonic-gate * contiguus memory chunk for interrupt queues snd 19817c478bd9Sstevel@tonic-gate * allocate/register boot cpu's queues, if any and 19827c478bd9Sstevel@tonic-gate * allocate dump buffer for sun4v systems to store 19837c478bd9Sstevel@tonic-gate * extra crash information during crash dump 19847c478bd9Sstevel@tonic-gate */ 19857c478bd9Sstevel@tonic-gate contig_mem_init(); 19867c478bd9Sstevel@tonic-gate mach_descrip_init(); 1987982b9107Sjb145095 1988982b9107Sjb145095 if (cpu_intrq_setup(CPU)) { 1989982b9107Sjb145095 cmn_err(CE_PANIC, "cpu%d: setup failed", CPU->cpu_id); 1990982b9107Sjb145095 } 19917c478bd9Sstevel@tonic-gate cpu_intrq_register(CPU); 1992db6d2ee3Ssvemuri mach_htraptrace_setup(CPU->cpu_id); 1993db6d2ee3Ssvemuri mach_htraptrace_configure(CPU->cpu_id); 19947c478bd9Sstevel@tonic-gate mach_dump_buffer_init(); 19957c478bd9Sstevel@tonic-gate 19967c478bd9Sstevel@tonic-gate /* 19977c478bd9Sstevel@tonic-gate * Initialize interrupt related stuff 19987c478bd9Sstevel@tonic-gate */ 1999100b72f4Sandrei cpu_intr_alloc(CPU, NINTR_THREADS); 20007c478bd9Sstevel@tonic-gate 20017c478bd9Sstevel@tonic-gate (void) splzs(); /* allow hi clock ints but not zs */ 20027c478bd9Sstevel@tonic-gate 20037c478bd9Sstevel@tonic-gate /* 20047c478bd9Sstevel@tonic-gate * Initialize errors. 20057c478bd9Sstevel@tonic-gate */ 20067c478bd9Sstevel@tonic-gate error_init(); 20077c478bd9Sstevel@tonic-gate 20087c478bd9Sstevel@tonic-gate /* 20097c478bd9Sstevel@tonic-gate * Note that we may have already used kernel bcopy before this 20107c478bd9Sstevel@tonic-gate * point - but if you really care about this, adb the use_hw_* 20117c478bd9Sstevel@tonic-gate * variables to 0 before rebooting. 20127c478bd9Sstevel@tonic-gate */ 20137c478bd9Sstevel@tonic-gate mach_hw_copy_limit(); 20147c478bd9Sstevel@tonic-gate 20157c478bd9Sstevel@tonic-gate /* 20167c478bd9Sstevel@tonic-gate * Install the "real" preemption guards before DDI services 20177c478bd9Sstevel@tonic-gate * are available. 20187c478bd9Sstevel@tonic-gate */ 20197c478bd9Sstevel@tonic-gate (void) prom_set_preprom(kern_preprom); 20207c478bd9Sstevel@tonic-gate (void) prom_set_postprom(kern_postprom); 20217c478bd9Sstevel@tonic-gate CPU->cpu_m.mutex_ready = 1; 20227c478bd9Sstevel@tonic-gate 20237c478bd9Sstevel@tonic-gate /* 20247c478bd9Sstevel@tonic-gate * Initialize segnf (kernel support for non-faulting loads). 20257c478bd9Sstevel@tonic-gate */ 20267c478bd9Sstevel@tonic-gate segnf_init(); 20277c478bd9Sstevel@tonic-gate 20287c478bd9Sstevel@tonic-gate /* 20297c478bd9Sstevel@tonic-gate * Configure the root devinfo node. 20307c478bd9Sstevel@tonic-gate */ 20317c478bd9Sstevel@tonic-gate configure(); /* set up devices */ 20327c478bd9Sstevel@tonic-gate mach_cpu_halt_idle(); 20337c478bd9Sstevel@tonic-gate } 20347c478bd9Sstevel@tonic-gate 20357c478bd9Sstevel@tonic-gate 20367c478bd9Sstevel@tonic-gate void 20377c478bd9Sstevel@tonic-gate post_startup(void) 20387c478bd9Sstevel@tonic-gate { 20397c478bd9Sstevel@tonic-gate #ifdef PTL1_PANIC_DEBUG 20407c478bd9Sstevel@tonic-gate extern void init_ptl1_thread(void); 20417c478bd9Sstevel@tonic-gate #endif /* PTL1_PANIC_DEBUG */ 20427c478bd9Sstevel@tonic-gate extern void abort_sequence_init(void); 20437c478bd9Sstevel@tonic-gate 20447c478bd9Sstevel@tonic-gate /* 20457c478bd9Sstevel@tonic-gate * Set the system wide, processor-specific flags to be passed 20467c478bd9Sstevel@tonic-gate * to userland via the aux vector for performance hints and 20477c478bd9Sstevel@tonic-gate * instruction set extensions. 20487c478bd9Sstevel@tonic-gate */ 20497c478bd9Sstevel@tonic-gate bind_hwcap(); 20507c478bd9Sstevel@tonic-gate 20517c478bd9Sstevel@tonic-gate /* 20527c478bd9Sstevel@tonic-gate * Startup memory scrubber (if any) 20537c478bd9Sstevel@tonic-gate */ 20547c478bd9Sstevel@tonic-gate mach_memscrub(); 20557c478bd9Sstevel@tonic-gate 20567c478bd9Sstevel@tonic-gate /* 20577c478bd9Sstevel@tonic-gate * Allocate soft interrupt to handle abort sequence. 20587c478bd9Sstevel@tonic-gate */ 20597c478bd9Sstevel@tonic-gate abort_sequence_init(); 20607c478bd9Sstevel@tonic-gate 20617c478bd9Sstevel@tonic-gate /* 20627c478bd9Sstevel@tonic-gate * Configure the rest of the system. 20637c478bd9Sstevel@tonic-gate * Perform forceloading tasks for /etc/system. 20647c478bd9Sstevel@tonic-gate */ 20657c478bd9Sstevel@tonic-gate (void) mod_sysctl(SYS_FORCELOAD, NULL); 20667c478bd9Sstevel@tonic-gate /* 20677c478bd9Sstevel@tonic-gate * ON4.0: Force /proc module in until clock interrupt handle fixed 20687c478bd9Sstevel@tonic-gate * ON4.0: This must be fixed or restated in /etc/systems. 20697c478bd9Sstevel@tonic-gate */ 20707c478bd9Sstevel@tonic-gate (void) modload("fs", "procfs"); 20717c478bd9Sstevel@tonic-gate 20721ae08745Sheppo /* load machine class specific drivers */ 20731ae08745Sheppo load_mach_drivers(); 20741ae08745Sheppo 20751ae08745Sheppo /* load platform specific drivers */ 20767c478bd9Sstevel@tonic-gate if (&load_platform_drivers) 20777c478bd9Sstevel@tonic-gate load_platform_drivers(); 20787c478bd9Sstevel@tonic-gate 20797c478bd9Sstevel@tonic-gate /* load vis simulation module, if we are running w/fpu off */ 20807c478bd9Sstevel@tonic-gate if (!fpu_exists) { 20817c478bd9Sstevel@tonic-gate if (modload("misc", "vis") == -1) 20827c478bd9Sstevel@tonic-gate halt("Can't load vis"); 20837c478bd9Sstevel@tonic-gate } 20847c478bd9Sstevel@tonic-gate 20857c478bd9Sstevel@tonic-gate mach_fpras(); 20867c478bd9Sstevel@tonic-gate 20877c478bd9Sstevel@tonic-gate maxmem = freemem; 20887c478bd9Sstevel@tonic-gate 20897c478bd9Sstevel@tonic-gate #ifdef PTL1_PANIC_DEBUG 20907c478bd9Sstevel@tonic-gate init_ptl1_thread(); 20917c478bd9Sstevel@tonic-gate #endif /* PTL1_PANIC_DEBUG */ 20921ae08745Sheppo 20931ae08745Sheppo if (&cif_init) 20941ae08745Sheppo cif_init(); 20957c478bd9Sstevel@tonic-gate } 20967c478bd9Sstevel@tonic-gate 20977c478bd9Sstevel@tonic-gate #ifdef PTL1_PANIC_DEBUG 20987c478bd9Sstevel@tonic-gate int ptl1_panic_test = 0; 20997c478bd9Sstevel@tonic-gate int ptl1_panic_xc_one_test = 0; 21007c478bd9Sstevel@tonic-gate int ptl1_panic_xc_all_test = 0; 21017c478bd9Sstevel@tonic-gate int ptl1_panic_xt_one_test = 0; 21027c478bd9Sstevel@tonic-gate int ptl1_panic_xt_all_test = 0; 21037c478bd9Sstevel@tonic-gate kthread_id_t ptl1_thread_p = NULL; 21047c478bd9Sstevel@tonic-gate kcondvar_t ptl1_cv; 21057c478bd9Sstevel@tonic-gate kmutex_t ptl1_mutex; 21067c478bd9Sstevel@tonic-gate int ptl1_recurse_count_threshold = 0x40; 21077c478bd9Sstevel@tonic-gate int ptl1_recurse_trap_threshold = 0x3d; 21087c478bd9Sstevel@tonic-gate extern void ptl1_recurse(int, int); 21097c478bd9Sstevel@tonic-gate extern void ptl1_panic_xt(int, int); 21107c478bd9Sstevel@tonic-gate 21117c478bd9Sstevel@tonic-gate /* 21127c478bd9Sstevel@tonic-gate * Called once per second by timeout() to wake up 21137c478bd9Sstevel@tonic-gate * the ptl1_panic thread to see if it should cause 21147c478bd9Sstevel@tonic-gate * a trap to the ptl1_panic() code. 21157c478bd9Sstevel@tonic-gate */ 21167c478bd9Sstevel@tonic-gate /* ARGSUSED */ 21177c478bd9Sstevel@tonic-gate static void 21187c478bd9Sstevel@tonic-gate ptl1_wakeup(void *arg) 21197c478bd9Sstevel@tonic-gate { 21207c478bd9Sstevel@tonic-gate mutex_enter(&ptl1_mutex); 21217c478bd9Sstevel@tonic-gate cv_signal(&ptl1_cv); 21227c478bd9Sstevel@tonic-gate mutex_exit(&ptl1_mutex); 21237c478bd9Sstevel@tonic-gate } 21247c478bd9Sstevel@tonic-gate 21257c478bd9Sstevel@tonic-gate /* 21267c478bd9Sstevel@tonic-gate * ptl1_panic cross call function: 21277c478bd9Sstevel@tonic-gate * Needed because xc_one() and xc_some() can pass 21287c478bd9Sstevel@tonic-gate * 64 bit args but ptl1_recurse() expects ints. 21297c478bd9Sstevel@tonic-gate */ 21307c478bd9Sstevel@tonic-gate static void 21317c478bd9Sstevel@tonic-gate ptl1_panic_xc(void) 21327c478bd9Sstevel@tonic-gate { 21337c478bd9Sstevel@tonic-gate ptl1_recurse(ptl1_recurse_count_threshold, 21347c478bd9Sstevel@tonic-gate ptl1_recurse_trap_threshold); 21357c478bd9Sstevel@tonic-gate } 21367c478bd9Sstevel@tonic-gate 21377c478bd9Sstevel@tonic-gate /* 21387c478bd9Sstevel@tonic-gate * The ptl1 thread waits for a global flag to be set 21397c478bd9Sstevel@tonic-gate * and uses the recurse thresholds to set the stack depth 21407c478bd9Sstevel@tonic-gate * to cause a ptl1_panic() directly via a call to ptl1_recurse 21417c478bd9Sstevel@tonic-gate * or indirectly via the cross call and cross trap functions. 21427c478bd9Sstevel@tonic-gate * 21437c478bd9Sstevel@tonic-gate * This is useful testing stack overflows and normal 21447c478bd9Sstevel@tonic-gate * ptl1_panic() states with a know stack frame. 21457c478bd9Sstevel@tonic-gate * 21467c478bd9Sstevel@tonic-gate * ptl1_recurse() is an asm function in ptl1_panic.s that 21477c478bd9Sstevel@tonic-gate * sets the {In, Local, Out, and Global} registers to a 21487c478bd9Sstevel@tonic-gate * know state on the stack and just prior to causing a 21497c478bd9Sstevel@tonic-gate * test ptl1_panic trap. 21507c478bd9Sstevel@tonic-gate */ 21517c478bd9Sstevel@tonic-gate static void 21527c478bd9Sstevel@tonic-gate ptl1_thread(void) 21537c478bd9Sstevel@tonic-gate { 21547c478bd9Sstevel@tonic-gate mutex_enter(&ptl1_mutex); 21557c478bd9Sstevel@tonic-gate while (ptl1_thread_p) { 21567c478bd9Sstevel@tonic-gate cpuset_t other_cpus; 21577c478bd9Sstevel@tonic-gate int cpu_id; 21587c478bd9Sstevel@tonic-gate int my_cpu_id; 21597c478bd9Sstevel@tonic-gate int target_cpu_id; 21607c478bd9Sstevel@tonic-gate int target_found; 21617c478bd9Sstevel@tonic-gate 21627c478bd9Sstevel@tonic-gate if (ptl1_panic_test) { 21637c478bd9Sstevel@tonic-gate ptl1_recurse(ptl1_recurse_count_threshold, 21647c478bd9Sstevel@tonic-gate ptl1_recurse_trap_threshold); 21657c478bd9Sstevel@tonic-gate } 21667c478bd9Sstevel@tonic-gate 21677c478bd9Sstevel@tonic-gate /* 21687c478bd9Sstevel@tonic-gate * Find potential targets for x-call and x-trap, 21697c478bd9Sstevel@tonic-gate * if any exist while preempt is disabled we 21707c478bd9Sstevel@tonic-gate * start a ptl1_panic if requested via a 21717c478bd9Sstevel@tonic-gate * globals. 21727c478bd9Sstevel@tonic-gate */ 21737c478bd9Sstevel@tonic-gate kpreempt_disable(); 21747c478bd9Sstevel@tonic-gate my_cpu_id = CPU->cpu_id; 21757c478bd9Sstevel@tonic-gate other_cpus = cpu_ready_set; 21767c478bd9Sstevel@tonic-gate CPUSET_DEL(other_cpus, CPU->cpu_id); 21777c478bd9Sstevel@tonic-gate target_found = 0; 21787c478bd9Sstevel@tonic-gate if (!CPUSET_ISNULL(other_cpus)) { 21797c478bd9Sstevel@tonic-gate /* 21807c478bd9Sstevel@tonic-gate * Pick the first one 21817c478bd9Sstevel@tonic-gate */ 21827c478bd9Sstevel@tonic-gate for (cpu_id = 0; cpu_id < NCPU; cpu_id++) { 21837c478bd9Sstevel@tonic-gate if (cpu_id == my_cpu_id) 21847c478bd9Sstevel@tonic-gate continue; 21857c478bd9Sstevel@tonic-gate 21867c478bd9Sstevel@tonic-gate if (CPU_XCALL_READY(cpu_id)) { 21877c478bd9Sstevel@tonic-gate target_cpu_id = cpu_id; 21887c478bd9Sstevel@tonic-gate target_found = 1; 21897c478bd9Sstevel@tonic-gate break; 21907c478bd9Sstevel@tonic-gate } 21917c478bd9Sstevel@tonic-gate } 21927c478bd9Sstevel@tonic-gate ASSERT(target_found); 21937c478bd9Sstevel@tonic-gate 21947c478bd9Sstevel@tonic-gate if (ptl1_panic_xc_one_test) { 21957c478bd9Sstevel@tonic-gate xc_one(target_cpu_id, 21967c478bd9Sstevel@tonic-gate (xcfunc_t *)ptl1_panic_xc, 0, 0); 21977c478bd9Sstevel@tonic-gate } 21987c478bd9Sstevel@tonic-gate if (ptl1_panic_xc_all_test) { 21997c478bd9Sstevel@tonic-gate xc_some(other_cpus, 22007c478bd9Sstevel@tonic-gate (xcfunc_t *)ptl1_panic_xc, 0, 0); 22017c478bd9Sstevel@tonic-gate } 22027c478bd9Sstevel@tonic-gate if (ptl1_panic_xt_one_test) { 22037c478bd9Sstevel@tonic-gate xt_one(target_cpu_id, 22047c478bd9Sstevel@tonic-gate (xcfunc_t *)ptl1_panic_xt, 0, 0); 22057c478bd9Sstevel@tonic-gate } 22067c478bd9Sstevel@tonic-gate if (ptl1_panic_xt_all_test) { 22077c478bd9Sstevel@tonic-gate xt_some(other_cpus, 22087c478bd9Sstevel@tonic-gate (xcfunc_t *)ptl1_panic_xt, 0, 0); 22097c478bd9Sstevel@tonic-gate } 22107c478bd9Sstevel@tonic-gate } 22117c478bd9Sstevel@tonic-gate kpreempt_enable(); 22127c478bd9Sstevel@tonic-gate (void) timeout(ptl1_wakeup, NULL, hz); 22137c478bd9Sstevel@tonic-gate (void) cv_wait(&ptl1_cv, &ptl1_mutex); 22147c478bd9Sstevel@tonic-gate } 22157c478bd9Sstevel@tonic-gate mutex_exit(&ptl1_mutex); 22167c478bd9Sstevel@tonic-gate } 22177c478bd9Sstevel@tonic-gate 22187c478bd9Sstevel@tonic-gate /* 22197c478bd9Sstevel@tonic-gate * Called during early startup to create the ptl1_thread 22207c478bd9Sstevel@tonic-gate */ 22217c478bd9Sstevel@tonic-gate void 22227c478bd9Sstevel@tonic-gate init_ptl1_thread(void) 22237c478bd9Sstevel@tonic-gate { 22247c478bd9Sstevel@tonic-gate ptl1_thread_p = thread_create(NULL, 0, ptl1_thread, NULL, 0, 22257c478bd9Sstevel@tonic-gate &p0, TS_RUN, 0); 22267c478bd9Sstevel@tonic-gate } 22277c478bd9Sstevel@tonic-gate #endif /* PTL1_PANIC_DEBUG */ 22287c478bd9Sstevel@tonic-gate 22297c478bd9Sstevel@tonic-gate 2230*986fd29aSsetje static void 2231*986fd29aSsetje memlist_new(uint64_t start, uint64_t len, struct memlist **memlistp) 2232*986fd29aSsetje { 2233*986fd29aSsetje struct memlist *new; 2234*986fd29aSsetje 2235*986fd29aSsetje new = *memlistp; 2236*986fd29aSsetje new->address = start; 2237*986fd29aSsetje new->size = len; 2238*986fd29aSsetje *memlistp = new + 1; 2239*986fd29aSsetje } 2240*986fd29aSsetje 22417c478bd9Sstevel@tonic-gate /* 22427c478bd9Sstevel@tonic-gate * Add to a memory list. 22437c478bd9Sstevel@tonic-gate * start = start of new memory segment 22447c478bd9Sstevel@tonic-gate * len = length of new memory segment in bytes 22457c478bd9Sstevel@tonic-gate * memlistp = pointer to array of available memory segment structures 22467c478bd9Sstevel@tonic-gate * curmemlistp = memory list to which to add segment. 22477c478bd9Sstevel@tonic-gate */ 22487c478bd9Sstevel@tonic-gate static void 22497c478bd9Sstevel@tonic-gate memlist_add(uint64_t start, uint64_t len, struct memlist **memlistp, 22507c478bd9Sstevel@tonic-gate struct memlist **curmemlistp) 22517c478bd9Sstevel@tonic-gate { 2252*986fd29aSsetje struct memlist *new = *memlistp; 22537c478bd9Sstevel@tonic-gate 2254*986fd29aSsetje memlist_new(start, len, memlistp); 22557c478bd9Sstevel@tonic-gate memlist_insert(new, curmemlistp); 22567c478bd9Sstevel@tonic-gate } 22577c478bd9Sstevel@tonic-gate 2258*986fd29aSsetje static int 2259*986fd29aSsetje ndata_alloc_memseg(struct memlist *ndata, size_t avail) 2260*986fd29aSsetje { 2261*986fd29aSsetje int nseg; 2262*986fd29aSsetje size_t memseg_sz; 2263*986fd29aSsetje struct memseg *msp; 2264*986fd29aSsetje 2265*986fd29aSsetje /* 2266*986fd29aSsetje * The memseg list is for the chunks of physical memory that 2267*986fd29aSsetje * will be managed by the vm system. The number calculated is 2268*986fd29aSsetje * a guess as boot may fragment it more when memory allocations 2269*986fd29aSsetje * are made before kphysm_init(). 2270*986fd29aSsetje */ 2271*986fd29aSsetje memseg_sz = (avail + 10) * sizeof (struct memseg); 2272*986fd29aSsetje memseg_sz = roundup(memseg_sz, PAGESIZE); 2273*986fd29aSsetje nseg = memseg_sz / sizeof (struct memseg); 2274*986fd29aSsetje msp = ndata_alloc(ndata, memseg_sz, ecache_alignsize); 2275*986fd29aSsetje if (msp == NULL) 2276*986fd29aSsetje return (1); 2277*986fd29aSsetje PRM_DEBUG(memseg_free); 2278*986fd29aSsetje 2279*986fd29aSsetje while (nseg--) { 2280*986fd29aSsetje msp->next = memseg_free; 2281*986fd29aSsetje memseg_free = msp; 2282*986fd29aSsetje msp++; 2283*986fd29aSsetje } 2284*986fd29aSsetje return (0); 2285*986fd29aSsetje } 2286*986fd29aSsetje 22877c478bd9Sstevel@tonic-gate /* 22887c478bd9Sstevel@tonic-gate * In the case of architectures that support dynamic addition of 22897c478bd9Sstevel@tonic-gate * memory at run-time there are two cases where memsegs need to 22907c478bd9Sstevel@tonic-gate * be initialized and added to the memseg list. 22917c478bd9Sstevel@tonic-gate * 1) memsegs that are constructed at startup. 22927c478bd9Sstevel@tonic-gate * 2) memsegs that are constructed at run-time on 22937c478bd9Sstevel@tonic-gate * hot-plug capable architectures. 22947c478bd9Sstevel@tonic-gate * This code was originally part of the function kphysm_init(). 22957c478bd9Sstevel@tonic-gate */ 22967c478bd9Sstevel@tonic-gate 22977c478bd9Sstevel@tonic-gate static void 22987c478bd9Sstevel@tonic-gate memseg_list_add(struct memseg *memsegp) 22997c478bd9Sstevel@tonic-gate { 23007c478bd9Sstevel@tonic-gate struct memseg **prev_memsegp; 23017c478bd9Sstevel@tonic-gate pgcnt_t num; 23027c478bd9Sstevel@tonic-gate 23037c478bd9Sstevel@tonic-gate /* insert in memseg list, decreasing number of pages order */ 23047c478bd9Sstevel@tonic-gate 23057c478bd9Sstevel@tonic-gate num = MSEG_NPAGES(memsegp); 23067c478bd9Sstevel@tonic-gate 23077c478bd9Sstevel@tonic-gate for (prev_memsegp = &memsegs; *prev_memsegp; 23087c478bd9Sstevel@tonic-gate prev_memsegp = &((*prev_memsegp)->next)) { 23097c478bd9Sstevel@tonic-gate if (num > MSEG_NPAGES(*prev_memsegp)) 23107c478bd9Sstevel@tonic-gate break; 23117c478bd9Sstevel@tonic-gate } 23127c478bd9Sstevel@tonic-gate 23137c478bd9Sstevel@tonic-gate memsegp->next = *prev_memsegp; 23147c478bd9Sstevel@tonic-gate *prev_memsegp = memsegp; 23157c478bd9Sstevel@tonic-gate 23167c478bd9Sstevel@tonic-gate if (kpm_enable) { 23177c478bd9Sstevel@tonic-gate memsegp->nextpa = (memsegp->next) ? 23187c478bd9Sstevel@tonic-gate va_to_pa(memsegp->next) : MSEG_NULLPTR_PA; 23197c478bd9Sstevel@tonic-gate 23207c478bd9Sstevel@tonic-gate if (prev_memsegp != &memsegs) { 23217c478bd9Sstevel@tonic-gate struct memseg *msp; 23227c478bd9Sstevel@tonic-gate msp = (struct memseg *)((caddr_t)prev_memsegp - 23237c478bd9Sstevel@tonic-gate offsetof(struct memseg, next)); 23247c478bd9Sstevel@tonic-gate msp->nextpa = va_to_pa(memsegp); 23257c478bd9Sstevel@tonic-gate } else { 23267c478bd9Sstevel@tonic-gate memsegspa = va_to_pa(memsegs); 23277c478bd9Sstevel@tonic-gate } 23287c478bd9Sstevel@tonic-gate } 23297c478bd9Sstevel@tonic-gate } 23307c478bd9Sstevel@tonic-gate 23317c478bd9Sstevel@tonic-gate /* 23327c478bd9Sstevel@tonic-gate * PSM add_physmem_cb(). US-II and newer processors have some 23337c478bd9Sstevel@tonic-gate * flavor of the prefetch capability implemented. We exploit 23347c478bd9Sstevel@tonic-gate * this capability for optimum performance. 23357c478bd9Sstevel@tonic-gate */ 23367c478bd9Sstevel@tonic-gate #define PREFETCH_BYTES 64 23377c478bd9Sstevel@tonic-gate 23387c478bd9Sstevel@tonic-gate void 23397c478bd9Sstevel@tonic-gate add_physmem_cb(page_t *pp, pfn_t pnum) 23407c478bd9Sstevel@tonic-gate { 23417c478bd9Sstevel@tonic-gate extern void prefetch_page_w(void *); 23427c478bd9Sstevel@tonic-gate 23437c478bd9Sstevel@tonic-gate pp->p_pagenum = pnum; 23447c478bd9Sstevel@tonic-gate 23457c478bd9Sstevel@tonic-gate /* 23467c478bd9Sstevel@tonic-gate * Prefetch one more page_t into E$. To prevent future 23477c478bd9Sstevel@tonic-gate * mishaps with the sizeof(page_t) changing on us, we 23487c478bd9Sstevel@tonic-gate * catch this on debug kernels if we can't bring in the 23497c478bd9Sstevel@tonic-gate * entire hpage with 2 PREFETCH_BYTES reads. See 23507c478bd9Sstevel@tonic-gate * also, sun4u/cpu/cpu_module.c 23517c478bd9Sstevel@tonic-gate */ 23527c478bd9Sstevel@tonic-gate /*LINTED*/ 23537c478bd9Sstevel@tonic-gate ASSERT(sizeof (page_t) <= 2*PREFETCH_BYTES); 23547c478bd9Sstevel@tonic-gate prefetch_page_w((char *)pp); 23557c478bd9Sstevel@tonic-gate } 23567c478bd9Sstevel@tonic-gate 23577c478bd9Sstevel@tonic-gate /* 2358*986fd29aSsetje * Find memseg with given pfn 2359*986fd29aSsetje */ 2360*986fd29aSsetje static struct memseg * 2361*986fd29aSsetje memseg_find(pfn_t base, pfn_t *next) 2362*986fd29aSsetje { 2363*986fd29aSsetje struct memseg *seg; 2364*986fd29aSsetje 2365*986fd29aSsetje if (next != NULL) 2366*986fd29aSsetje *next = LONG_MAX; 2367*986fd29aSsetje for (seg = memsegs; seg != NULL; seg = seg->next) { 2368*986fd29aSsetje if (base >= seg->pages_base && base < seg->pages_end) 2369*986fd29aSsetje return (seg); 2370*986fd29aSsetje if (next != NULL && seg->pages_base > base && 2371*986fd29aSsetje seg->pages_base < *next) 2372*986fd29aSsetje *next = seg->pages_base; 2373*986fd29aSsetje } 2374*986fd29aSsetje return (NULL); 2375*986fd29aSsetje } 2376*986fd29aSsetje 2377*986fd29aSsetje extern struct vnode prom_ppages; 2378*986fd29aSsetje 2379*986fd29aSsetje /* 2380*986fd29aSsetje * Put page allocated by OBP on prom_ppages 23817c478bd9Sstevel@tonic-gate */ 23827c478bd9Sstevel@tonic-gate static void 2383*986fd29aSsetje kphysm_erase(uint64_t addr, uint64_t len) 23847c478bd9Sstevel@tonic-gate { 2385*986fd29aSsetje struct page *pp; 2386*986fd29aSsetje struct memseg *seg; 2387*986fd29aSsetje pfn_t base = btop(addr), next; 2388*986fd29aSsetje pgcnt_t num = btop(len); 23897c478bd9Sstevel@tonic-gate 2390*986fd29aSsetje while (num != 0) { 2391*986fd29aSsetje pgcnt_t off, left; 23927c478bd9Sstevel@tonic-gate 2393*986fd29aSsetje seg = memseg_find(base, &next); 2394*986fd29aSsetje if (seg == NULL) { 2395*986fd29aSsetje if (next == LONG_MAX) 2396*986fd29aSsetje break; 2397*986fd29aSsetje left = MIN(next - base, num); 2398*986fd29aSsetje base += left, num -= left; 2399*986fd29aSsetje continue; 2400*986fd29aSsetje } 2401*986fd29aSsetje off = base - seg->pages_base; 2402*986fd29aSsetje pp = seg->pages + off; 2403*986fd29aSsetje left = num - MIN(num, (seg->pages_end - seg->pages_base) - off); 2404*986fd29aSsetje while (num != left) { 2405*986fd29aSsetje /* 2406*986fd29aSsetje * init it, lock it, and hashin on prom_pages vp. 2407*986fd29aSsetje * 2408*986fd29aSsetje * XXX vnode offsets on the prom_ppages vnode 2409*986fd29aSsetje * are page numbers (gack) for >32 bit 2410*986fd29aSsetje * physical memory machines. 2411*986fd29aSsetje */ 2412*986fd29aSsetje add_physmem_cb(pp, base); 2413*986fd29aSsetje if (page_trylock(pp, SE_EXCL) == 0) 2414*986fd29aSsetje cmn_err(CE_PANIC, "prom page locked"); 2415*986fd29aSsetje (void) page_hashin(pp, &prom_ppages, 2416*986fd29aSsetje (offset_t)base, NULL); 2417*986fd29aSsetje (void) page_pp_lock(pp, 0, 1); 2418*986fd29aSsetje pp++, base++, num--; 2419*986fd29aSsetje } 2420*986fd29aSsetje } 2421*986fd29aSsetje } 2422*986fd29aSsetje 2423*986fd29aSsetje static page_t *ppnext; 2424*986fd29aSsetje static pgcnt_t ppleft; 2425*986fd29aSsetje 2426*986fd29aSsetje static void *kpm_ppnext; 2427*986fd29aSsetje static pgcnt_t kpm_ppleft; 24287c478bd9Sstevel@tonic-gate 24297c478bd9Sstevel@tonic-gate /* 2430*986fd29aSsetje * Create a memseg 24317c478bd9Sstevel@tonic-gate */ 2432*986fd29aSsetje static void 2433*986fd29aSsetje kphysm_memseg(uint64_t addr, uint64_t len) 2434*986fd29aSsetje { 2435*986fd29aSsetje pfn_t base = btop(addr); 2436*986fd29aSsetje pgcnt_t num = btop(len); 2437*986fd29aSsetje struct memseg *seg; 24387c478bd9Sstevel@tonic-gate 2439*986fd29aSsetje seg = memseg_free; 2440*986fd29aSsetje memseg_free = seg->next; 2441*986fd29aSsetje ASSERT(seg != NULL); 2442*986fd29aSsetje 2443*986fd29aSsetje seg->pages = ppnext; 2444*986fd29aSsetje seg->epages = ppnext + num; 2445*986fd29aSsetje seg->pages_base = base; 2446*986fd29aSsetje seg->pages_end = base + num; 2447*986fd29aSsetje ppnext += num; 2448*986fd29aSsetje ppleft -= num; 24497c478bd9Sstevel@tonic-gate 24507c478bd9Sstevel@tonic-gate if (kpm_enable) { 2451*986fd29aSsetje pgcnt_t kpnum = ptokpmpr(num); 24527c478bd9Sstevel@tonic-gate 2453*986fd29aSsetje if (kpnum > kpm_ppleft) 2454*986fd29aSsetje panic("kphysm_memseg: kpm_pp overflow"); 2455*986fd29aSsetje seg->pagespa = va_to_pa(seg->pages); 2456*986fd29aSsetje seg->epagespa = va_to_pa(seg->epages); 2457*986fd29aSsetje seg->kpm_pbase = kpmptop(ptokpmp(base)); 2458*986fd29aSsetje seg->kpm_nkpmpgs = kpnum; 24597c478bd9Sstevel@tonic-gate /* 2460*986fd29aSsetje * In the kpm_smallpage case, the kpm array 2461*986fd29aSsetje * is 1-1 wrt the page array 24627c478bd9Sstevel@tonic-gate */ 2463*986fd29aSsetje if (kpm_smallpages) { 2464*986fd29aSsetje kpm_spage_t *kpm_pp = kpm_ppnext; 24657c478bd9Sstevel@tonic-gate 2466*986fd29aSsetje kpm_ppnext = kpm_pp + kpnum; 2467*986fd29aSsetje seg->kpm_spages = kpm_pp; 2468*986fd29aSsetje seg->kpm_pagespa = va_to_pa(seg->kpm_spages); 2469*986fd29aSsetje } else { 2470*986fd29aSsetje kpm_page_t *kpm_pp = kpm_ppnext; 2471*986fd29aSsetje 2472*986fd29aSsetje kpm_ppnext = kpm_pp + kpnum; 2473*986fd29aSsetje seg->kpm_pages = kpm_pp; 2474*986fd29aSsetje seg->kpm_pagespa = va_to_pa(seg->kpm_pages); 2475*986fd29aSsetje /* ASSERT no kpm overlaps */ 2476*986fd29aSsetje ASSERT( 2477*986fd29aSsetje memseg_find(base - pmodkpmp(base), NULL) == NULL); 2478*986fd29aSsetje ASSERT(memseg_find( 2479*986fd29aSsetje roundup(base + num, kpmpnpgs) - 1, NULL) == NULL); 2480*986fd29aSsetje } 2481*986fd29aSsetje kpm_ppleft -= num; 2482*986fd29aSsetje } 2483*986fd29aSsetje 2484*986fd29aSsetje memseg_list_add(seg); 2485*986fd29aSsetje } 2486*986fd29aSsetje 24877c478bd9Sstevel@tonic-gate /* 2488*986fd29aSsetje * Add range to free list 24897c478bd9Sstevel@tonic-gate */ 2490*986fd29aSsetje void 2491*986fd29aSsetje kphysm_add(uint64_t addr, uint64_t len, int reclaim) 2492*986fd29aSsetje { 2493*986fd29aSsetje struct page *pp; 2494*986fd29aSsetje struct memseg *seg; 2495*986fd29aSsetje pfn_t base = btop(addr); 2496*986fd29aSsetje pgcnt_t num = btop(len); 24977c478bd9Sstevel@tonic-gate 2498*986fd29aSsetje seg = memseg_find(base, NULL); 2499*986fd29aSsetje ASSERT(seg != NULL); 2500*986fd29aSsetje pp = seg->pages + (base - seg->pages_base); 25017c478bd9Sstevel@tonic-gate 2502*986fd29aSsetje if (reclaim) { 2503*986fd29aSsetje struct page *rpp = pp; 2504*986fd29aSsetje struct page *lpp = pp + num; 25057c478bd9Sstevel@tonic-gate 2506*986fd29aSsetje /* 2507*986fd29aSsetje * page should be locked on prom_ppages 2508*986fd29aSsetje * unhash and unlock it 2509*986fd29aSsetje */ 2510*986fd29aSsetje while (rpp < lpp) { 2511*986fd29aSsetje ASSERT(PAGE_EXCL(rpp) && rpp->p_vnode == &prom_ppages); 2512*986fd29aSsetje page_pp_unlock(rpp, 0, 1); 2513*986fd29aSsetje page_hashout(rpp, NULL); 2514*986fd29aSsetje page_unlock(rpp); 2515*986fd29aSsetje rpp++; 25167c478bd9Sstevel@tonic-gate } 2517*986fd29aSsetje } 25187c478bd9Sstevel@tonic-gate 25197c478bd9Sstevel@tonic-gate /* 25207c478bd9Sstevel@tonic-gate * add_physmem() initializes the PSM part of the page 25217c478bd9Sstevel@tonic-gate * struct by calling the PSM back with add_physmem_cb(). 25227c478bd9Sstevel@tonic-gate * In addition it coalesces pages into larger pages as 25237c478bd9Sstevel@tonic-gate * it initializes them. 25247c478bd9Sstevel@tonic-gate */ 25257c478bd9Sstevel@tonic-gate add_physmem(pp, num, base); 25267c478bd9Sstevel@tonic-gate } 25277c478bd9Sstevel@tonic-gate 2528*986fd29aSsetje /* 2529*986fd29aSsetje * kphysm_init() tackles the problem of initializing physical memory. 2530*986fd29aSsetje */ 2531*986fd29aSsetje static void 2532*986fd29aSsetje kphysm_init(void) 2533*986fd29aSsetje { 2534*986fd29aSsetje struct memlist *pmem; 2535*986fd29aSsetje 2536*986fd29aSsetje ASSERT(page_hash != NULL && page_hashsz != 0); 2537*986fd29aSsetje 2538*986fd29aSsetje ppnext = pp_base; 2539*986fd29aSsetje ppleft = npages; 2540*986fd29aSsetje kpm_ppnext = kpm_pp_base; 2541*986fd29aSsetje kpm_ppleft = kpm_npages; 2542*986fd29aSsetje 2543*986fd29aSsetje /* 2544*986fd29aSsetje * installed pages not on nopp_memlist go in memseg list 2545*986fd29aSsetje */ 2546*986fd29aSsetje diff_memlists(phys_install, nopp_list, kphysm_memseg); 2547*986fd29aSsetje 2548*986fd29aSsetje /* 2549*986fd29aSsetje * Free the avail list 2550*986fd29aSsetje */ 2551*986fd29aSsetje for (pmem = phys_avail; pmem != NULL; pmem = pmem->next) 2552*986fd29aSsetje kphysm_add(pmem->address, pmem->size, 0); 2553*986fd29aSsetje 2554*986fd29aSsetje /* 2555*986fd29aSsetje * Erase pages that aren't available 2556*986fd29aSsetje */ 2557*986fd29aSsetje diff_memlists(phys_install, phys_avail, kphysm_erase); 2558*986fd29aSsetje 25597c478bd9Sstevel@tonic-gate build_pfn_hash(); 25607c478bd9Sstevel@tonic-gate } 25617c478bd9Sstevel@tonic-gate 25627c478bd9Sstevel@tonic-gate /* 25637c478bd9Sstevel@tonic-gate * Kernel VM initialization. 25647c478bd9Sstevel@tonic-gate * Assumptions about kernel address space ordering: 25657c478bd9Sstevel@tonic-gate * (1) gap (user space) 25667c478bd9Sstevel@tonic-gate * (2) kernel text 25677c478bd9Sstevel@tonic-gate * (3) kernel data/bss 25687c478bd9Sstevel@tonic-gate * (4) gap 25697c478bd9Sstevel@tonic-gate * (5) kernel data structures 25707c478bd9Sstevel@tonic-gate * (6) gap 25717c478bd9Sstevel@tonic-gate * (7) debugger (optional) 25727c478bd9Sstevel@tonic-gate * (8) monitor 25737c478bd9Sstevel@tonic-gate * (9) gap (possibly null) 25747c478bd9Sstevel@tonic-gate * (10) dvma 25757c478bd9Sstevel@tonic-gate * (11) devices 25767c478bd9Sstevel@tonic-gate */ 25777c478bd9Sstevel@tonic-gate static void 25787c478bd9Sstevel@tonic-gate kvm_init(void) 25797c478bd9Sstevel@tonic-gate { 25807c478bd9Sstevel@tonic-gate /* 25817c478bd9Sstevel@tonic-gate * Put the kernel segments in kernel address space. 25827c478bd9Sstevel@tonic-gate */ 25837c478bd9Sstevel@tonic-gate rw_enter(&kas.a_lock, RW_WRITER); 25847c478bd9Sstevel@tonic-gate as_avlinit(&kas); 25857c478bd9Sstevel@tonic-gate 25867c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, (caddr_t)KERNELBASE, 25877c478bd9Sstevel@tonic-gate (size_t)(e_moddata - KERNELBASE), &ktextseg); 25887c478bd9Sstevel@tonic-gate (void) segkmem_create(&ktextseg); 25897c478bd9Sstevel@tonic-gate 25907c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, (caddr_t)(KERNELBASE + MMU_PAGESIZE4M), 25917c478bd9Sstevel@tonic-gate (size_t)(MMU_PAGESIZE4M), &ktexthole); 25927c478bd9Sstevel@tonic-gate (void) segkmem_create(&ktexthole); 25937c478bd9Sstevel@tonic-gate 25947c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, (caddr_t)valloc_base, 25957c478bd9Sstevel@tonic-gate (size_t)(econtig32 - valloc_base), &kvalloc); 25967c478bd9Sstevel@tonic-gate (void) segkmem_create(&kvalloc); 25977c478bd9Sstevel@tonic-gate 25987c478bd9Sstevel@tonic-gate if (kmem64_base) { 25997c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, (caddr_t)kmem64_base, 26007c478bd9Sstevel@tonic-gate (size_t)(kmem64_end - kmem64_base), &kmem64); 26017c478bd9Sstevel@tonic-gate (void) segkmem_create(&kmem64); 26027c478bd9Sstevel@tonic-gate } 26037c478bd9Sstevel@tonic-gate 26047c478bd9Sstevel@tonic-gate /* 26057c478bd9Sstevel@tonic-gate * We're about to map out /boot. This is the beginning of the 26067c478bd9Sstevel@tonic-gate * system resource management transition. We can no longer 26077c478bd9Sstevel@tonic-gate * call into /boot for I/O or memory allocations. 26087c478bd9Sstevel@tonic-gate */ 26097c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, kernelheap, ekernelheap - kernelheap, &kvseg); 26107c478bd9Sstevel@tonic-gate (void) segkmem_create(&kvseg); 26117c478bd9Sstevel@tonic-gate hblk_alloc_dynamic = 1; 26127c478bd9Sstevel@tonic-gate 26137c478bd9Sstevel@tonic-gate /* 26147c478bd9Sstevel@tonic-gate * we need to preallocate pages for DR operations before enabling large 26157c478bd9Sstevel@tonic-gate * page kernel heap because of memseg_remap_init() hat_unload() hack. 26167c478bd9Sstevel@tonic-gate */ 26177c478bd9Sstevel@tonic-gate memseg_remap_init(); 26187c478bd9Sstevel@tonic-gate 26197c478bd9Sstevel@tonic-gate /* at this point we are ready to use large page heap */ 26207c478bd9Sstevel@tonic-gate segkmem_heap_lp_init(); 26217c478bd9Sstevel@tonic-gate 26227c478bd9Sstevel@tonic-gate (void) seg_attach(&kas, (caddr_t)SYSBASE32, SYSLIMIT32 - SYSBASE32, 26237c478bd9Sstevel@tonic-gate &kvseg32); 26247c478bd9Sstevel@tonic-gate (void) segkmem_create(&kvseg32); 26257c478bd9Sstevel@tonic-gate 26267c478bd9Sstevel@tonic-gate /* 26277c478bd9Sstevel@tonic-gate * Create a segment for the debugger. 26287c478bd9Sstevel@tonic-gate */ 2629ae115bc7Smrj (void) seg_attach(&kas, kdi_segdebugbase, kdi_segdebugsize, &kdebugseg); 26307c478bd9Sstevel@tonic-gate (void) segkmem_create(&kdebugseg); 26317c478bd9Sstevel@tonic-gate 26327c478bd9Sstevel@tonic-gate rw_exit(&kas.a_lock); 26337c478bd9Sstevel@tonic-gate } 26347c478bd9Sstevel@tonic-gate 26357c478bd9Sstevel@tonic-gate char obp_tte_str[] = 26367c478bd9Sstevel@tonic-gate "h# %x constant MMU_PAGESHIFT " 26377c478bd9Sstevel@tonic-gate "h# %x constant TTE8K " 26387c478bd9Sstevel@tonic-gate "h# %x constant SFHME_SIZE " 26397c478bd9Sstevel@tonic-gate "h# %x constant SFHME_TTE " 26407c478bd9Sstevel@tonic-gate "h# %x constant HMEBLK_TAG " 26417c478bd9Sstevel@tonic-gate "h# %x constant HMEBLK_NEXT " 26427c478bd9Sstevel@tonic-gate "h# %x constant HMEBLK_MISC " 26437c478bd9Sstevel@tonic-gate "h# %x constant HMEBLK_HME1 " 26447c478bd9Sstevel@tonic-gate "h# %x constant NHMENTS " 26457c478bd9Sstevel@tonic-gate "h# %x constant HBLK_SZMASK " 26467c478bd9Sstevel@tonic-gate "h# %x constant HBLK_RANGE_SHIFT " 26477c478bd9Sstevel@tonic-gate "h# %x constant HMEBP_HBLK " 26487c478bd9Sstevel@tonic-gate "h# %x constant HMEBUCKET_SIZE " 26497c478bd9Sstevel@tonic-gate "h# %x constant HTAG_SFMMUPSZ " 265005d3dc4bSpaulsan "h# %x constant HTAG_BSPAGE_SHIFT " 265105d3dc4bSpaulsan "h# %x constant HTAG_REHASH_SHIFT " 265205d3dc4bSpaulsan "h# %x constant SFMMU_INVALID_SHMERID " 26537c478bd9Sstevel@tonic-gate "h# %x constant mmu_hashcnt " 26547c478bd9Sstevel@tonic-gate "h# %p constant uhme_hash " 26557c478bd9Sstevel@tonic-gate "h# %p constant khme_hash " 26567c478bd9Sstevel@tonic-gate "h# %x constant UHMEHASH_SZ " 26577c478bd9Sstevel@tonic-gate "h# %x constant KHMEHASH_SZ " 26581e2e7a75Shuah "h# %p constant KCONTEXT " 26597c478bd9Sstevel@tonic-gate "h# %p constant KHATID " 26607c478bd9Sstevel@tonic-gate "h# %x constant ASI_MEM " 26617c478bd9Sstevel@tonic-gate 26627c478bd9Sstevel@tonic-gate ": PHYS-X@ ( phys -- data ) " 26637c478bd9Sstevel@tonic-gate " ASI_MEM spacex@ " 26647c478bd9Sstevel@tonic-gate "; " 26657c478bd9Sstevel@tonic-gate 26667c478bd9Sstevel@tonic-gate ": PHYS-W@ ( phys -- data ) " 26677c478bd9Sstevel@tonic-gate " ASI_MEM spacew@ " 26687c478bd9Sstevel@tonic-gate "; " 26697c478bd9Sstevel@tonic-gate 26707c478bd9Sstevel@tonic-gate ": PHYS-L@ ( phys -- data ) " 26717c478bd9Sstevel@tonic-gate " ASI_MEM spaceL@ " 26727c478bd9Sstevel@tonic-gate "; " 26737c478bd9Sstevel@tonic-gate 26747c478bd9Sstevel@tonic-gate ": TTE_PAGE_SHIFT ( ttesz -- hmeshift ) " 26757c478bd9Sstevel@tonic-gate " 3 * MMU_PAGESHIFT + " 26767c478bd9Sstevel@tonic-gate "; " 26777c478bd9Sstevel@tonic-gate 26787c478bd9Sstevel@tonic-gate ": TTE_IS_VALID ( ttep -- flag ) " 26797c478bd9Sstevel@tonic-gate " PHYS-X@ 0< " 26807c478bd9Sstevel@tonic-gate "; " 26817c478bd9Sstevel@tonic-gate 26827c478bd9Sstevel@tonic-gate ": HME_HASH_SHIFT ( ttesz -- hmeshift ) " 26837c478bd9Sstevel@tonic-gate " dup TTE8K = if " 26847c478bd9Sstevel@tonic-gate " drop HBLK_RANGE_SHIFT " 26857c478bd9Sstevel@tonic-gate " else " 26867c478bd9Sstevel@tonic-gate " TTE_PAGE_SHIFT " 26877c478bd9Sstevel@tonic-gate " then " 26887c478bd9Sstevel@tonic-gate "; " 26897c478bd9Sstevel@tonic-gate 26907c478bd9Sstevel@tonic-gate ": HME_HASH_BSPAGE ( addr hmeshift -- bspage ) " 26917c478bd9Sstevel@tonic-gate " tuck >> swap MMU_PAGESHIFT - << " 26927c478bd9Sstevel@tonic-gate "; " 26937c478bd9Sstevel@tonic-gate 26947c478bd9Sstevel@tonic-gate ": HME_HASH_FUNCTION ( sfmmup addr hmeshift -- hmebp ) " 26957c478bd9Sstevel@tonic-gate " >> over xor swap ( hash sfmmup ) " 26967c478bd9Sstevel@tonic-gate " KHATID <> if ( hash ) " 26977c478bd9Sstevel@tonic-gate " UHMEHASH_SZ and ( bucket ) " 26987c478bd9Sstevel@tonic-gate " HMEBUCKET_SIZE * uhme_hash + ( hmebp ) " 26997c478bd9Sstevel@tonic-gate " else ( hash ) " 27007c478bd9Sstevel@tonic-gate " KHMEHASH_SZ and ( bucket ) " 27017c478bd9Sstevel@tonic-gate " HMEBUCKET_SIZE * khme_hash + ( hmebp ) " 27027c478bd9Sstevel@tonic-gate " then ( hmebp ) " 27037c478bd9Sstevel@tonic-gate "; " 27047c478bd9Sstevel@tonic-gate 27057c478bd9Sstevel@tonic-gate ": HME_HASH_TABLE_SEARCH " 27067c478bd9Sstevel@tonic-gate " ( sfmmup hmebp hblktag -- sfmmup null | sfmmup hmeblkp ) " 27077c478bd9Sstevel@tonic-gate " >r hmebp_hblk + phys-x@ begin ( sfmmup hmeblkp ) ( r: hblktag ) " 27087c478bd9Sstevel@tonic-gate " dup if ( sfmmup hmeblkp ) ( r: hblktag ) " 27097c478bd9Sstevel@tonic-gate " dup hmeblk_tag + phys-x@ r@ = if ( sfmmup hmeblkp ) " 27107c478bd9Sstevel@tonic-gate " dup hmeblk_tag + 8 + phys-x@ 2 pick = if " 27117c478bd9Sstevel@tonic-gate " true ( sfmmup hmeblkp true ) ( r: hblktag ) " 27127c478bd9Sstevel@tonic-gate " else " 27137c478bd9Sstevel@tonic-gate " hmeblk_next + phys-x@ false " 27147c478bd9Sstevel@tonic-gate " ( sfmmup hmeblkp false ) ( r: hblktag ) " 27157c478bd9Sstevel@tonic-gate " then " 27167c478bd9Sstevel@tonic-gate " else " 27177c478bd9Sstevel@tonic-gate " hmeblk_next + phys-x@ false " 27187c478bd9Sstevel@tonic-gate " ( sfmmup hmeblkp false ) ( r: hblktag ) " 27197c478bd9Sstevel@tonic-gate " then " 27207c478bd9Sstevel@tonic-gate " else " 27217c478bd9Sstevel@tonic-gate " true " 27227c478bd9Sstevel@tonic-gate " then " 27237c478bd9Sstevel@tonic-gate " until r> drop " 27247c478bd9Sstevel@tonic-gate "; " 27257c478bd9Sstevel@tonic-gate 27267c478bd9Sstevel@tonic-gate ": HME_HASH_TAG ( sfmmup rehash addr -- hblktag ) " 27277c478bd9Sstevel@tonic-gate " over HME_HASH_SHIFT HME_HASH_BSPAGE ( sfmmup rehash bspage ) " 272805d3dc4bSpaulsan " HTAG_BSPAGE_SHIFT << ( sfmmup rehash htag-bspage )" 272905d3dc4bSpaulsan " swap HTAG_REHASH_SHIFT << or ( sfmmup htag-bspage-rehash )" 273005d3dc4bSpaulsan " SFMMU_INVALID_SHMERID or nip ( hblktag ) " 27317c478bd9Sstevel@tonic-gate "; " 27327c478bd9Sstevel@tonic-gate 27337c478bd9Sstevel@tonic-gate ": HBLK_TO_TTEP ( hmeblkp addr -- ttep ) " 27347c478bd9Sstevel@tonic-gate " over HMEBLK_MISC + PHYS-L@ HBLK_SZMASK and ( hmeblkp addr ttesz ) " 27357c478bd9Sstevel@tonic-gate " TTE8K = if ( hmeblkp addr ) " 27367c478bd9Sstevel@tonic-gate " MMU_PAGESHIFT >> NHMENTS 1- and ( hmeblkp hme-index ) " 27377c478bd9Sstevel@tonic-gate " else ( hmeblkp addr ) " 27387c478bd9Sstevel@tonic-gate " drop 0 ( hmeblkp 0 ) " 27397c478bd9Sstevel@tonic-gate " then ( hmeblkp hme-index ) " 27407c478bd9Sstevel@tonic-gate " SFHME_SIZE * + HMEBLK_HME1 + ( hmep ) " 27417c478bd9Sstevel@tonic-gate " SFHME_TTE + ( ttep ) " 27427c478bd9Sstevel@tonic-gate "; " 27437c478bd9Sstevel@tonic-gate 27447c478bd9Sstevel@tonic-gate ": unix-tte ( addr cnum -- false | tte-data true ) " 27451e2e7a75Shuah " KCONTEXT = if ( addr ) " 27461e2e7a75Shuah " KHATID ( addr khatid ) " 27471e2e7a75Shuah " else ( addr ) " 27481e2e7a75Shuah " drop false exit ( false ) " 27491e2e7a75Shuah " then " 27501e2e7a75Shuah " ( addr khatid ) " 27517c478bd9Sstevel@tonic-gate " mmu_hashcnt 1+ 1 do ( addr sfmmup ) " 27527c478bd9Sstevel@tonic-gate " 2dup swap i HME_HASH_SHIFT " 27537c478bd9Sstevel@tonic-gate "( addr sfmmup sfmmup addr hmeshift ) " 27547c478bd9Sstevel@tonic-gate " HME_HASH_FUNCTION ( addr sfmmup hmebp ) " 27557c478bd9Sstevel@tonic-gate " over i 4 pick " 27567c478bd9Sstevel@tonic-gate "( addr sfmmup hmebp sfmmup rehash addr ) " 27577c478bd9Sstevel@tonic-gate " HME_HASH_TAG ( addr sfmmup hmebp hblktag ) " 27587c478bd9Sstevel@tonic-gate " HME_HASH_TABLE_SEARCH " 27597c478bd9Sstevel@tonic-gate "( addr sfmmup { null | hmeblkp } ) " 27607c478bd9Sstevel@tonic-gate " ?dup if ( addr sfmmup hmeblkp ) " 27617c478bd9Sstevel@tonic-gate " nip swap HBLK_TO_TTEP ( ttep ) " 27627c478bd9Sstevel@tonic-gate " dup TTE_IS_VALID if ( valid-ttep ) " 27637c478bd9Sstevel@tonic-gate " PHYS-X@ true ( tte-data true ) " 27647c478bd9Sstevel@tonic-gate " else ( invalid-tte ) " 27657c478bd9Sstevel@tonic-gate " drop false ( false ) " 27667c478bd9Sstevel@tonic-gate " then ( false | tte-data true ) " 27677c478bd9Sstevel@tonic-gate " unloop exit ( false | tte-data true ) " 27687c478bd9Sstevel@tonic-gate " then ( addr sfmmup ) " 27697c478bd9Sstevel@tonic-gate " loop ( addr sfmmup ) " 27707c478bd9Sstevel@tonic-gate " 2drop false ( false ) " 27717c478bd9Sstevel@tonic-gate "; " 27727c478bd9Sstevel@tonic-gate ; 27737c478bd9Sstevel@tonic-gate 27747c478bd9Sstevel@tonic-gate void 27757c478bd9Sstevel@tonic-gate create_va_to_tte(void) 27767c478bd9Sstevel@tonic-gate { 27777c478bd9Sstevel@tonic-gate char *bp; 27787c478bd9Sstevel@tonic-gate extern int khmehash_num, uhmehash_num; 27797c478bd9Sstevel@tonic-gate extern struct hmehash_bucket *khme_hash, *uhme_hash; 27807c478bd9Sstevel@tonic-gate 27817c478bd9Sstevel@tonic-gate #define OFFSET(type, field) ((uintptr_t)(&((type *)0)->field)) 27827c478bd9Sstevel@tonic-gate 27837c478bd9Sstevel@tonic-gate bp = (char *)kobj_zalloc(MMU_PAGESIZE, KM_SLEEP); 27847c478bd9Sstevel@tonic-gate 27857c478bd9Sstevel@tonic-gate /* 27867c478bd9Sstevel@tonic-gate * Teach obp how to parse our sw ttes. 27877c478bd9Sstevel@tonic-gate */ 27887c478bd9Sstevel@tonic-gate (void) sprintf(bp, obp_tte_str, 27897c478bd9Sstevel@tonic-gate MMU_PAGESHIFT, 27907c478bd9Sstevel@tonic-gate TTE8K, 27917c478bd9Sstevel@tonic-gate sizeof (struct sf_hment), 27927c478bd9Sstevel@tonic-gate OFFSET(struct sf_hment, hme_tte), 27937c478bd9Sstevel@tonic-gate OFFSET(struct hme_blk, hblk_tag), 27947c478bd9Sstevel@tonic-gate OFFSET(struct hme_blk, hblk_nextpa), 27957c478bd9Sstevel@tonic-gate OFFSET(struct hme_blk, hblk_misc), 27967c478bd9Sstevel@tonic-gate OFFSET(struct hme_blk, hblk_hme), 27977c478bd9Sstevel@tonic-gate NHMENTS, 27987c478bd9Sstevel@tonic-gate HBLK_SZMASK, 27997c478bd9Sstevel@tonic-gate HBLK_RANGE_SHIFT, 28007c478bd9Sstevel@tonic-gate OFFSET(struct hmehash_bucket, hmeh_nextpa), 28017c478bd9Sstevel@tonic-gate sizeof (struct hmehash_bucket), 28027c478bd9Sstevel@tonic-gate HTAG_SFMMUPSZ, 280305d3dc4bSpaulsan HTAG_BSPAGE_SHIFT, 280405d3dc4bSpaulsan HTAG_REHASH_SHIFT, 280505d3dc4bSpaulsan SFMMU_INVALID_SHMERID, 28067c478bd9Sstevel@tonic-gate mmu_hashcnt, 28077c478bd9Sstevel@tonic-gate (caddr_t)va_to_pa((caddr_t)uhme_hash), 28087c478bd9Sstevel@tonic-gate (caddr_t)va_to_pa((caddr_t)khme_hash), 28097c478bd9Sstevel@tonic-gate UHMEHASH_SZ, 28107c478bd9Sstevel@tonic-gate KHMEHASH_SZ, 28111e2e7a75Shuah KCONTEXT, 28127c478bd9Sstevel@tonic-gate KHATID, 28137c478bd9Sstevel@tonic-gate ASI_MEM); 28147c478bd9Sstevel@tonic-gate prom_interpret(bp, 0, 0, 0, 0, 0); 28157c478bd9Sstevel@tonic-gate 28167c478bd9Sstevel@tonic-gate kobj_free(bp, MMU_PAGESIZE); 28177c478bd9Sstevel@tonic-gate } 28187c478bd9Sstevel@tonic-gate 28197c478bd9Sstevel@tonic-gate void 28207c478bd9Sstevel@tonic-gate install_va_to_tte(void) 28217c478bd9Sstevel@tonic-gate { 28227c478bd9Sstevel@tonic-gate /* 28237c478bd9Sstevel@tonic-gate * advise prom that he can use unix-tte 28247c478bd9Sstevel@tonic-gate */ 28257c478bd9Sstevel@tonic-gate prom_interpret("' unix-tte is va>tte-data", 0, 0, 0, 0, 0); 28267c478bd9Sstevel@tonic-gate } 28277c478bd9Sstevel@tonic-gate 2828fea9cb91Slq150181 /* 28292d7b546fSlq150181 * Here we add "device-type=console" for /os-io node, for currently 28302d7b546fSlq150181 * our kernel console output only supports displaying text and 28312d7b546fSlq150181 * performing cursor-positioning operations (through kernel framebuffer 28322d7b546fSlq150181 * driver) and it doesn't support other functionalities required for a 28332d7b546fSlq150181 * standard "display" device as specified in 1275 spec. The main missing 28342d7b546fSlq150181 * interface defined by the 1275 spec is "draw-logo". 28352d7b546fSlq150181 * also see the comments above prom_stdout_is_framebuffer(). 2836fea9cb91Slq150181 */ 28377c478bd9Sstevel@tonic-gate static char *create_node = 283812ef07e9Slq150181 "\" /\" find-device " 28397c478bd9Sstevel@tonic-gate "new-device " 28407c478bd9Sstevel@tonic-gate "\" os-io\" device-name " 28412d7b546fSlq150181 "\" "OBP_DISPLAY_CONSOLE"\" device-type " 28427c478bd9Sstevel@tonic-gate ": cb-r/w ( adr,len method$ -- #read/#written ) " 28437c478bd9Sstevel@tonic-gate " 2>r swap 2 2r> ['] $callback catch if " 28447c478bd9Sstevel@tonic-gate " 2drop 3drop 0 " 28457c478bd9Sstevel@tonic-gate " then " 28467c478bd9Sstevel@tonic-gate "; " 28477c478bd9Sstevel@tonic-gate ": read ( adr,len -- #read ) " 28487c478bd9Sstevel@tonic-gate " \" read\" ['] cb-r/w catch if 2drop 2drop -2 exit then " 28497c478bd9Sstevel@tonic-gate " ( retN ... ret1 N ) " 28507c478bd9Sstevel@tonic-gate " ?dup if " 28517c478bd9Sstevel@tonic-gate " swap >r 1- 0 ?do drop loop r> " 28527c478bd9Sstevel@tonic-gate " else " 28537c478bd9Sstevel@tonic-gate " -2 " 285412ef07e9Slq150181 " then " 28557c478bd9Sstevel@tonic-gate "; " 28567c478bd9Sstevel@tonic-gate ": write ( adr,len -- #written ) " 28577c478bd9Sstevel@tonic-gate " \" write\" ['] cb-r/w catch if 2drop 2drop 0 exit then " 28587c478bd9Sstevel@tonic-gate " ( retN ... ret1 N ) " 28597c478bd9Sstevel@tonic-gate " ?dup if " 28607c478bd9Sstevel@tonic-gate " swap >r 1- 0 ?do drop loop r> " 28617c478bd9Sstevel@tonic-gate " else " 28627c478bd9Sstevel@tonic-gate " 0 " 28637c478bd9Sstevel@tonic-gate " then " 28647c478bd9Sstevel@tonic-gate "; " 28657c478bd9Sstevel@tonic-gate ": poll-tty ( -- ) ; " 28667c478bd9Sstevel@tonic-gate ": install-abort ( -- ) ['] poll-tty d# 10 alarm ; " 28677c478bd9Sstevel@tonic-gate ": remove-abort ( -- ) ['] poll-tty 0 alarm ; " 28687c478bd9Sstevel@tonic-gate ": cb-give/take ( $method -- ) " 28697c478bd9Sstevel@tonic-gate " 0 -rot ['] $callback catch ?dup if " 28707c478bd9Sstevel@tonic-gate " >r 2drop 2drop r> throw " 28717c478bd9Sstevel@tonic-gate " else " 28727c478bd9Sstevel@tonic-gate " 0 ?do drop loop " 28737c478bd9Sstevel@tonic-gate " then " 28747c478bd9Sstevel@tonic-gate "; " 28757c478bd9Sstevel@tonic-gate ": give ( -- ) \" exit-input\" cb-give/take ; " 28767c478bd9Sstevel@tonic-gate ": take ( -- ) \" enter-input\" cb-give/take ; " 28777c478bd9Sstevel@tonic-gate ": open ( -- ok? ) true ; " 28787c478bd9Sstevel@tonic-gate ": close ( -- ) ; " 28797c478bd9Sstevel@tonic-gate "finish-device " 28807c478bd9Sstevel@tonic-gate "device-end "; 28817c478bd9Sstevel@tonic-gate 28827c478bd9Sstevel@tonic-gate /* 2883fea9cb91Slq150181 * Create the OBP input/output node (FCode serial driver). 2884fea9cb91Slq150181 * It is needed for both USB console keyboard and for 2885fea9cb91Slq150181 * the kernel terminal emulator. It is too early to check for a 2886fea9cb91Slq150181 * kernel console compatible framebuffer now, so we create this 2887fea9cb91Slq150181 * so that we're ready if we need to enable kernel terminal emulation. 28887c478bd9Sstevel@tonic-gate * 2889fea9cb91Slq150181 * When the USB software takes over the input device at the time 2890fea9cb91Slq150181 * consconfig runs, OBP's stdin is redirected to this node. 2891fea9cb91Slq150181 * Whenever the FORTH user interface is used after this switch, 2892fea9cb91Slq150181 * the node will call back into the kernel for console input. 2893fea9cb91Slq150181 * If a serial device such as ttya or a UART with a Type 5 keyboard 2894fea9cb91Slq150181 * attached is used, OBP takes over the serial device when the system 2895fea9cb91Slq150181 * goes to the debugger after the system is booted. This sharing 2896fea9cb91Slq150181 * of the relatively simple serial device is difficult but possible. 2897fea9cb91Slq150181 * Sharing the USB host controller is impossible due its complexity. 2898fea9cb91Slq150181 * 2899fea9cb91Slq150181 * Similarly to USB keyboard input redirection, after consconfig_dacf 2900fea9cb91Slq150181 * configures a kernel console framebuffer as the standard output 2901fea9cb91Slq150181 * device, OBP's stdout is switched to to vector through the 2902fea9cb91Slq150181 * /os-io node into the kernel terminal emulator. 29037c478bd9Sstevel@tonic-gate */ 29047c478bd9Sstevel@tonic-gate static void 2905fea9cb91Slq150181 startup_create_io_node(void) 29067c478bd9Sstevel@tonic-gate { 29077c478bd9Sstevel@tonic-gate prom_interpret(create_node, 0, 0, 0, 0, 0); 29087c478bd9Sstevel@tonic-gate } 29097c478bd9Sstevel@tonic-gate 29107c478bd9Sstevel@tonic-gate 29117c478bd9Sstevel@tonic-gate static void 29127c478bd9Sstevel@tonic-gate do_prom_version_check(void) 29137c478bd9Sstevel@tonic-gate { 29147c478bd9Sstevel@tonic-gate int i; 2915fa9e4066Sahrens pnode_t node; 29167c478bd9Sstevel@tonic-gate char buf[64]; 29177c478bd9Sstevel@tonic-gate static char drev[] = "Down-rev firmware detected%s\n" 29187c478bd9Sstevel@tonic-gate "\tPlease upgrade to the following minimum version:\n" 29197c478bd9Sstevel@tonic-gate "\t\t%s\n"; 29207c478bd9Sstevel@tonic-gate 29217c478bd9Sstevel@tonic-gate i = prom_version_check(buf, sizeof (buf), &node); 29227c478bd9Sstevel@tonic-gate 29237c478bd9Sstevel@tonic-gate if (i == PROM_VER64_OK) 29247c478bd9Sstevel@tonic-gate return; 29257c478bd9Sstevel@tonic-gate 29267c478bd9Sstevel@tonic-gate if (i == PROM_VER64_UPGRADE) { 29277c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, drev, "", buf); 29287c478bd9Sstevel@tonic-gate 29297c478bd9Sstevel@tonic-gate #ifdef DEBUG 29307c478bd9Sstevel@tonic-gate prom_enter_mon(); /* Type 'go' to continue */ 29317c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Booting with down-rev firmware\n"); 29327c478bd9Sstevel@tonic-gate return; 29337c478bd9Sstevel@tonic-gate #else 29347c478bd9Sstevel@tonic-gate halt(0); 29357c478bd9Sstevel@tonic-gate #endif 29367c478bd9Sstevel@tonic-gate } 29377c478bd9Sstevel@tonic-gate 29387c478bd9Sstevel@tonic-gate /* 29397c478bd9Sstevel@tonic-gate * The other possibility is that this is a server running 29407c478bd9Sstevel@tonic-gate * good firmware, but down-rev firmware was detected on at 29417c478bd9Sstevel@tonic-gate * least one other cpu board. We just complain if we see 29427c478bd9Sstevel@tonic-gate * that. 29437c478bd9Sstevel@tonic-gate */ 29447c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, drev, " on one or more CPU boards", buf); 29457c478bd9Sstevel@tonic-gate } 29467c478bd9Sstevel@tonic-gate 29477c478bd9Sstevel@tonic-gate 29487c478bd9Sstevel@tonic-gate /* 29497c478bd9Sstevel@tonic-gate * Must be defined in platform dependent code. 29507c478bd9Sstevel@tonic-gate */ 29517c478bd9Sstevel@tonic-gate extern caddr_t modtext; 29527c478bd9Sstevel@tonic-gate extern size_t modtext_sz; 29537c478bd9Sstevel@tonic-gate extern caddr_t moddata; 29547c478bd9Sstevel@tonic-gate 29557c478bd9Sstevel@tonic-gate #define HEAPTEXT_ARENA(addr) \ 29567c478bd9Sstevel@tonic-gate ((uintptr_t)(addr) < KERNELBASE + 2 * MMU_PAGESIZE4M ? 0 : \ 29577c478bd9Sstevel@tonic-gate (((uintptr_t)(addr) - HEAPTEXT_BASE) / \ 29587c478bd9Sstevel@tonic-gate (HEAPTEXT_MAPPED + HEAPTEXT_UNMAPPED) + 1)) 29597c478bd9Sstevel@tonic-gate 29607c478bd9Sstevel@tonic-gate #define HEAPTEXT_OVERSIZED(addr) \ 29617c478bd9Sstevel@tonic-gate ((uintptr_t)(addr) >= HEAPTEXT_BASE + HEAPTEXT_SIZE - HEAPTEXT_OVERSIZE) 29627c478bd9Sstevel@tonic-gate 29637c478bd9Sstevel@tonic-gate vmem_t *texthole_source[HEAPTEXT_NARENAS]; 29647c478bd9Sstevel@tonic-gate vmem_t *texthole_arena[HEAPTEXT_NARENAS]; 29657c478bd9Sstevel@tonic-gate kmutex_t texthole_lock; 29667c478bd9Sstevel@tonic-gate 29677c478bd9Sstevel@tonic-gate char kern_bootargs[OBP_MAXPATHLEN]; 29687c478bd9Sstevel@tonic-gate 29697c478bd9Sstevel@tonic-gate void 29707c478bd9Sstevel@tonic-gate kobj_vmem_init(vmem_t **text_arena, vmem_t **data_arena) 29717c478bd9Sstevel@tonic-gate { 29727c478bd9Sstevel@tonic-gate uintptr_t addr, limit; 29737c478bd9Sstevel@tonic-gate 29747c478bd9Sstevel@tonic-gate addr = HEAPTEXT_BASE; 29757c478bd9Sstevel@tonic-gate limit = addr + HEAPTEXT_SIZE - HEAPTEXT_OVERSIZE; 29767c478bd9Sstevel@tonic-gate 29777c478bd9Sstevel@tonic-gate /* 29787c478bd9Sstevel@tonic-gate * Before we initialize the text_arena, we want to punch holes in the 29797c478bd9Sstevel@tonic-gate * underlying heaptext_arena. This guarantees that for any text 29807c478bd9Sstevel@tonic-gate * address we can find a text hole less than HEAPTEXT_MAPPED away. 29817c478bd9Sstevel@tonic-gate */ 29827c478bd9Sstevel@tonic-gate for (; addr + HEAPTEXT_UNMAPPED <= limit; 29837c478bd9Sstevel@tonic-gate addr += HEAPTEXT_MAPPED + HEAPTEXT_UNMAPPED) { 29847c478bd9Sstevel@tonic-gate (void) vmem_xalloc(heaptext_arena, HEAPTEXT_UNMAPPED, PAGESIZE, 29857c478bd9Sstevel@tonic-gate 0, 0, (void *)addr, (void *)(addr + HEAPTEXT_UNMAPPED), 29867c478bd9Sstevel@tonic-gate VM_NOSLEEP | VM_BESTFIT | VM_PANIC); 29877c478bd9Sstevel@tonic-gate } 29887c478bd9Sstevel@tonic-gate 29897c478bd9Sstevel@tonic-gate /* 29907c478bd9Sstevel@tonic-gate * Allocate one page at the oversize to break up the text region 29917c478bd9Sstevel@tonic-gate * from the oversized region. 29927c478bd9Sstevel@tonic-gate */ 29937c478bd9Sstevel@tonic-gate (void) vmem_xalloc(heaptext_arena, PAGESIZE, PAGESIZE, 0, 0, 29947c478bd9Sstevel@tonic-gate (void *)limit, (void *)(limit + PAGESIZE), 29957c478bd9Sstevel@tonic-gate VM_NOSLEEP | VM_BESTFIT | VM_PANIC); 29967c478bd9Sstevel@tonic-gate 299768d3ac02Skchow *text_arena = vmem_create("module_text", modtext_sz ? modtext : NULL, 299868d3ac02Skchow modtext_sz, sizeof (uintptr_t), segkmem_alloc, segkmem_free, 29997c478bd9Sstevel@tonic-gate heaptext_arena, 0, VM_SLEEP); 30007c478bd9Sstevel@tonic-gate *data_arena = vmem_create("module_data", moddata, MODDATA, 1, 30017c478bd9Sstevel@tonic-gate segkmem_alloc, segkmem_free, heap32_arena, 0, VM_SLEEP); 30027c478bd9Sstevel@tonic-gate } 30037c478bd9Sstevel@tonic-gate 30047c478bd9Sstevel@tonic-gate caddr_t 30057c478bd9Sstevel@tonic-gate kobj_text_alloc(vmem_t *arena, size_t size) 30067c478bd9Sstevel@tonic-gate { 30077c478bd9Sstevel@tonic-gate caddr_t rval, better; 30087c478bd9Sstevel@tonic-gate 30097c478bd9Sstevel@tonic-gate /* 30107c478bd9Sstevel@tonic-gate * First, try a sleeping allocation. 30117c478bd9Sstevel@tonic-gate */ 30127c478bd9Sstevel@tonic-gate rval = vmem_alloc(arena, size, VM_SLEEP | VM_BESTFIT); 30137c478bd9Sstevel@tonic-gate 30147c478bd9Sstevel@tonic-gate if (size >= HEAPTEXT_MAPPED || !HEAPTEXT_OVERSIZED(rval)) 30157c478bd9Sstevel@tonic-gate return (rval); 30167c478bd9Sstevel@tonic-gate 30177c478bd9Sstevel@tonic-gate /* 30187c478bd9Sstevel@tonic-gate * We didn't get the area that we wanted. We're going to try to do an 30197c478bd9Sstevel@tonic-gate * allocation with explicit constraints. 30207c478bd9Sstevel@tonic-gate */ 30217c478bd9Sstevel@tonic-gate better = vmem_xalloc(arena, size, sizeof (uintptr_t), 0, 0, NULL, 30227c478bd9Sstevel@tonic-gate (void *)(HEAPTEXT_BASE + HEAPTEXT_SIZE - HEAPTEXT_OVERSIZE), 30237c478bd9Sstevel@tonic-gate VM_NOSLEEP | VM_BESTFIT); 30247c478bd9Sstevel@tonic-gate 30257c478bd9Sstevel@tonic-gate if (better != NULL) { 30267c478bd9Sstevel@tonic-gate /* 30277c478bd9Sstevel@tonic-gate * That worked. Free our first attempt and return. 30287c478bd9Sstevel@tonic-gate */ 30297c478bd9Sstevel@tonic-gate vmem_free(arena, rval, size); 30307c478bd9Sstevel@tonic-gate return (better); 30317c478bd9Sstevel@tonic-gate } 30327c478bd9Sstevel@tonic-gate 30337c478bd9Sstevel@tonic-gate /* 30347c478bd9Sstevel@tonic-gate * That didn't work; we'll have to return our first attempt. 30357c478bd9Sstevel@tonic-gate */ 30367c478bd9Sstevel@tonic-gate return (rval); 30377c478bd9Sstevel@tonic-gate } 30387c478bd9Sstevel@tonic-gate 30397c478bd9Sstevel@tonic-gate caddr_t 30407c478bd9Sstevel@tonic-gate kobj_texthole_alloc(caddr_t addr, size_t size) 30417c478bd9Sstevel@tonic-gate { 30427c478bd9Sstevel@tonic-gate int arena = HEAPTEXT_ARENA(addr); 30437c478bd9Sstevel@tonic-gate char c[30]; 30447c478bd9Sstevel@tonic-gate uintptr_t base; 30457c478bd9Sstevel@tonic-gate 30467c478bd9Sstevel@tonic-gate if (HEAPTEXT_OVERSIZED(addr)) { 30477c478bd9Sstevel@tonic-gate /* 30487c478bd9Sstevel@tonic-gate * If this is an oversized allocation, there is no text hole 30497c478bd9Sstevel@tonic-gate * available for it; return NULL. 30507c478bd9Sstevel@tonic-gate */ 30517c478bd9Sstevel@tonic-gate return (NULL); 30527c478bd9Sstevel@tonic-gate } 30537c478bd9Sstevel@tonic-gate 30547c478bd9Sstevel@tonic-gate mutex_enter(&texthole_lock); 30557c478bd9Sstevel@tonic-gate 30567c478bd9Sstevel@tonic-gate if (texthole_arena[arena] == NULL) { 30577c478bd9Sstevel@tonic-gate ASSERT(texthole_source[arena] == NULL); 30587c478bd9Sstevel@tonic-gate 30597c478bd9Sstevel@tonic-gate if (arena == 0) { 30607c478bd9Sstevel@tonic-gate texthole_source[0] = vmem_create("module_text_holesrc", 30617c478bd9Sstevel@tonic-gate (void *)(KERNELBASE + MMU_PAGESIZE4M), 30627c478bd9Sstevel@tonic-gate MMU_PAGESIZE4M, PAGESIZE, NULL, NULL, NULL, 30637c478bd9Sstevel@tonic-gate 0, VM_SLEEP); 30647c478bd9Sstevel@tonic-gate } else { 30657c478bd9Sstevel@tonic-gate base = HEAPTEXT_BASE + 30667c478bd9Sstevel@tonic-gate (arena - 1) * (HEAPTEXT_MAPPED + HEAPTEXT_UNMAPPED); 30677c478bd9Sstevel@tonic-gate 30687c478bd9Sstevel@tonic-gate (void) snprintf(c, sizeof (c), 30697c478bd9Sstevel@tonic-gate "heaptext_holesrc_%d", arena); 30707c478bd9Sstevel@tonic-gate 30717c478bd9Sstevel@tonic-gate texthole_source[arena] = vmem_create(c, (void *)base, 30727c478bd9Sstevel@tonic-gate HEAPTEXT_UNMAPPED, PAGESIZE, NULL, NULL, NULL, 30737c478bd9Sstevel@tonic-gate 0, VM_SLEEP); 30747c478bd9Sstevel@tonic-gate } 30757c478bd9Sstevel@tonic-gate 30767c478bd9Sstevel@tonic-gate (void) snprintf(c, sizeof (c), "heaptext_hole_%d", arena); 30777c478bd9Sstevel@tonic-gate 30787c478bd9Sstevel@tonic-gate texthole_arena[arena] = vmem_create(c, NULL, 0, 30797c478bd9Sstevel@tonic-gate sizeof (uint32_t), segkmem_alloc_permanent, segkmem_free, 30807c478bd9Sstevel@tonic-gate texthole_source[arena], 0, VM_SLEEP); 30817c478bd9Sstevel@tonic-gate } 30827c478bd9Sstevel@tonic-gate 30837c478bd9Sstevel@tonic-gate mutex_exit(&texthole_lock); 30847c478bd9Sstevel@tonic-gate 30857c478bd9Sstevel@tonic-gate ASSERT(texthole_arena[arena] != NULL); 30867c478bd9Sstevel@tonic-gate ASSERT(arena >= 0 && arena < HEAPTEXT_NARENAS); 30877c478bd9Sstevel@tonic-gate return (vmem_alloc(texthole_arena[arena], size, 30887c478bd9Sstevel@tonic-gate VM_BESTFIT | VM_NOSLEEP)); 30897c478bd9Sstevel@tonic-gate } 30907c478bd9Sstevel@tonic-gate 30917c478bd9Sstevel@tonic-gate void 30927c478bd9Sstevel@tonic-gate kobj_texthole_free(caddr_t addr, size_t size) 30937c478bd9Sstevel@tonic-gate { 30947c478bd9Sstevel@tonic-gate int arena = HEAPTEXT_ARENA(addr); 30957c478bd9Sstevel@tonic-gate 30967c478bd9Sstevel@tonic-gate ASSERT(arena >= 0 && arena < HEAPTEXT_NARENAS); 30977c478bd9Sstevel@tonic-gate ASSERT(texthole_arena[arena] != NULL); 30987c478bd9Sstevel@tonic-gate vmem_free(texthole_arena[arena], addr, size); 30997c478bd9Sstevel@tonic-gate } 3100