10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
51859Sha137994 * Common Development and Distribution License (the "License").
61859Sha137994 * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
228819SJason.Beloro@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
270Sstevel@tonic-gate /* All Rights Reserved */
280Sstevel@tonic-gate
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD
310Sstevel@tonic-gate * under license from the Regents of the University of California.
320Sstevel@tonic-gate */
330Sstevel@tonic-gate
340Sstevel@tonic-gate /*
350Sstevel@tonic-gate * UNIX machine dependent virtual memory support.
360Sstevel@tonic-gate */
370Sstevel@tonic-gate
380Sstevel@tonic-gate #include <sys/vm.h>
390Sstevel@tonic-gate #include <sys/exec.h>
400Sstevel@tonic-gate #include <sys/cmn_err.h>
410Sstevel@tonic-gate #include <sys/cpu_module.h>
420Sstevel@tonic-gate #include <sys/cpu.h>
430Sstevel@tonic-gate #include <sys/elf_SPARC.h>
440Sstevel@tonic-gate #include <sys/archsystm.h>
450Sstevel@tonic-gate #include <vm/hat_sfmmu.h>
460Sstevel@tonic-gate #include <sys/memnode.h>
470Sstevel@tonic-gate #include <sys/mem_cage.h>
480Sstevel@tonic-gate #include <vm/vm_dep.h>
490Sstevel@tonic-gate #include <sys/error.h>
500Sstevel@tonic-gate #include <sys/machsystm.h>
510Sstevel@tonic-gate #include <vm/seg_kmem.h>
523177Sdp78419 #include <sys/stack.h>
533177Sdp78419 #include <sys/atomic.h>
545648Ssetje #include <sys/promif.h>
550Sstevel@tonic-gate
560Sstevel@tonic-gate uint_t page_colors = 0;
570Sstevel@tonic-gate uint_t page_colors_mask = 0;
580Sstevel@tonic-gate uint_t page_coloring_shift = 0;
590Sstevel@tonic-gate int consistent_coloring;
604266Sdp78419 int update_proc_pgcolorbase_after_fork = 1;
610Sstevel@tonic-gate
620Sstevel@tonic-gate uint_t mmu_page_sizes = MMU_PAGE_SIZES;
630Sstevel@tonic-gate uint_t max_mmu_page_sizes = MMU_PAGE_SIZES;
640Sstevel@tonic-gate uint_t mmu_hashcnt = MAX_HASHCNT;
650Sstevel@tonic-gate uint_t max_mmu_hashcnt = MAX_HASHCNT;
660Sstevel@tonic-gate size_t mmu_ism_pagesize = DEFAULT_ISM_PAGESIZE;
670Sstevel@tonic-gate
680Sstevel@tonic-gate /*
690Sstevel@tonic-gate * A bitmask of the page sizes supported by hardware based upon szc.
700Sstevel@tonic-gate * The base pagesize (p_szc == 0) must always be supported by the hardware.
710Sstevel@tonic-gate */
720Sstevel@tonic-gate int mmu_exported_pagesize_mask;
730Sstevel@tonic-gate uint_t mmu_exported_page_sizes;
740Sstevel@tonic-gate
750Sstevel@tonic-gate uint_t szc_2_userszc[MMU_PAGE_SIZES];
760Sstevel@tonic-gate uint_t userszc_2_szc[MMU_PAGE_SIZES];
770Sstevel@tonic-gate
780Sstevel@tonic-gate extern uint_t vac_colors_mask;
790Sstevel@tonic-gate extern int vac_shift;
800Sstevel@tonic-gate
810Sstevel@tonic-gate hw_pagesize_t hw_page_array[] = {
822961Sdp78419 {MMU_PAGESIZE, MMU_PAGESHIFT, 0, MMU_PAGESIZE >> MMU_PAGESHIFT},
832961Sdp78419 {MMU_PAGESIZE64K, MMU_PAGESHIFT64K, 0,
842961Sdp78419 MMU_PAGESIZE64K >> MMU_PAGESHIFT},
852961Sdp78419 {MMU_PAGESIZE512K, MMU_PAGESHIFT512K, 0,
860Sstevel@tonic-gate MMU_PAGESIZE512K >> MMU_PAGESHIFT},
872961Sdp78419 {MMU_PAGESIZE4M, MMU_PAGESHIFT4M, 0, MMU_PAGESIZE4M >> MMU_PAGESHIFT},
882961Sdp78419 {MMU_PAGESIZE32M, MMU_PAGESHIFT32M, 0,
892961Sdp78419 MMU_PAGESIZE32M >> MMU_PAGESHIFT},
902961Sdp78419 {MMU_PAGESIZE256M, MMU_PAGESHIFT256M, 0,
910Sstevel@tonic-gate MMU_PAGESIZE256M >> MMU_PAGESHIFT},
922961Sdp78419 {0, 0, 0, 0}
930Sstevel@tonic-gate };
940Sstevel@tonic-gate
950Sstevel@tonic-gate /*
963764Sdp78419 * Maximum page size used to map 64-bit memory segment kmem64_base..kmem64_end
973764Sdp78419 */
983764Sdp78419 int max_bootlp_tteszc = TTE256M;
993764Sdp78419
1003764Sdp78419 /*
1012991Ssusans * Maximum and default segment size tunables for user heap, stack, private
1022991Ssusans * and shared anonymous memory, and user text and initialized data.
1030Sstevel@tonic-gate */
1042991Ssusans size_t max_uheap_lpsize = MMU_PAGESIZE64K;
1052991Ssusans size_t default_uheap_lpsize = MMU_PAGESIZE64K;
1062991Ssusans size_t max_ustack_lpsize = MMU_PAGESIZE64K;
1072991Ssusans size_t default_ustack_lpsize = MMU_PAGESIZE64K;
1082991Ssusans size_t max_privmap_lpsize = MMU_PAGESIZE64K;
1092991Ssusans size_t max_uidata_lpsize = MMU_PAGESIZE64K;
1102991Ssusans size_t max_utext_lpsize = MMU_PAGESIZE4M;
1112414Saguzovsk size_t max_shm_lpsize = MMU_PAGESIZE4M;
1122414Saguzovsk
1130Sstevel@tonic-gate /*
1144204Sha137994 * Contiguous memory allocator data structures and variables.
1154204Sha137994 *
1164204Sha137994 * The sun4v kernel must provide a means to allocate physically
1174204Sha137994 * contiguous, non-relocatable memory. The contig_mem_arena
1184204Sha137994 * and contig_mem_slab_arena exist for this purpose. Allocations
1194204Sha137994 * that require physically contiguous non-relocatable memory should
1204204Sha137994 * be made using contig_mem_alloc() or contig_mem_alloc_align()
1214204Sha137994 * which return memory from contig_mem_arena or contig_mem_reloc_arena.
1224204Sha137994 * These arenas import memory from the contig_mem_slab_arena one
1234204Sha137994 * contiguous chunk at a time.
1244204Sha137994 *
1254204Sha137994 * When importing slabs, an attempt is made to allocate a large page
1264204Sha137994 * to use as backing. As a result of the non-relocatable requirement,
1274204Sha137994 * slabs are allocated from the kernel cage freelists. If the cage does
1284204Sha137994 * not contain any free contiguous chunks large enough to satisfy the
1294204Sha137994 * slab allocation, the slab size will be downsized and the operation
1304204Sha137994 * retried. Large slab sizes are tried first to minimize cage
1314204Sha137994 * fragmentation. If the slab allocation is unsuccessful still, the slab
1324204Sha137994 * is allocated from outside the kernel cage. This is undesirable because,
1334204Sha137994 * until slabs are freed, it results in non-relocatable chunks scattered
1344204Sha137994 * throughout physical memory.
1354204Sha137994 *
1364204Sha137994 * Allocations from the contig_mem_arena are backed by slabs from the
1374204Sha137994 * cage. Allocations from the contig_mem_reloc_arena are backed by
1384204Sha137994 * slabs allocated outside the cage. Slabs are left share locked while
1394204Sha137994 * in use to prevent non-cage slabs from being relocated.
1404204Sha137994 *
1414204Sha137994 * Since there is no guarantee that large pages will be available in
1424204Sha137994 * the kernel cage, contiguous memory is reserved and added to the
1434204Sha137994 * contig_mem_arena at boot time, making it available for later
1444204Sha137994 * contiguous memory allocations. This reserve will be used to satisfy
1454204Sha137994 * contig_mem allocations first and it is only when the reserve is
1464204Sha137994 * completely allocated that new slabs will need to be imported.
1474204Sha137994 */
1484204Sha137994 static vmem_t *contig_mem_slab_arena;
1494204Sha137994 static vmem_t *contig_mem_arena;
1504204Sha137994 static vmem_t *contig_mem_reloc_arena;
1514204Sha137994 static kmutex_t contig_mem_lock;
1524204Sha137994 #define CONTIG_MEM_ARENA_QUANTUM 64
1534204Sha137994 #define CONTIG_MEM_SLAB_ARENA_QUANTUM MMU_PAGESIZE64K
1544204Sha137994
1554204Sha137994 /* contig_mem_arena import slab sizes, in decreasing size order */
1564204Sha137994 static size_t contig_mem_import_sizes[] = {
1574204Sha137994 MMU_PAGESIZE4M,
1584204Sha137994 MMU_PAGESIZE512K,
1594204Sha137994 MMU_PAGESIZE64K
1604204Sha137994 };
1614204Sha137994 #define NUM_IMPORT_SIZES \
1624204Sha137994 (sizeof (contig_mem_import_sizes) / sizeof (size_t))
1634204Sha137994 static size_t contig_mem_import_size_max = MMU_PAGESIZE4M;
1644204Sha137994 size_t contig_mem_slab_size = MMU_PAGESIZE4M;
1654204Sha137994
1664204Sha137994 /* Boot-time allocated buffer to pre-populate the contig_mem_arena */
1675631Swh94709 static size_t contig_mem_prealloc_size;
1685631Swh94709 static void *contig_mem_prealloc_buf;
1694204Sha137994
1704204Sha137994 /*
1710Sstevel@tonic-gate * map_addr_proc() is the routine called when the system is to
1720Sstevel@tonic-gate * choose an address for the user. We will pick an address
1730Sstevel@tonic-gate * range which is just below the current stack limit. The
1740Sstevel@tonic-gate * algorithm used for cache consistency on machines with virtual
1750Sstevel@tonic-gate * address caches is such that offset 0 in the vnode is always
1760Sstevel@tonic-gate * on a shm_alignment'ed aligned address. Unfortunately, this
1770Sstevel@tonic-gate * means that vnodes which are demand paged will not be mapped
1780Sstevel@tonic-gate * cache consistently with the executable images. When the
1790Sstevel@tonic-gate * cache alignment for a given object is inconsistent, the
1800Sstevel@tonic-gate * lower level code must manage the translations so that this
1810Sstevel@tonic-gate * is not seen here (at the cost of efficiency, of course).
1820Sstevel@tonic-gate *
1835668Smec * Every mapping will have a redzone of a single page on either side of
1845668Smec * the request. This is done to leave one page unmapped between segments.
1855668Smec * This is not required, but it's useful for the user because if their
1865668Smec * program strays across a segment boundary, it will catch a fault
1875668Smec * immediately making debugging a little easier. Currently the redzone
1885668Smec * is mandatory.
1895668Smec *
1900Sstevel@tonic-gate * addrp is a value/result parameter.
1910Sstevel@tonic-gate * On input it is a hint from the user to be used in a completely
1920Sstevel@tonic-gate * machine dependent fashion. For MAP_ALIGN, addrp contains the
1935668Smec * minimal alignment, which must be some "power of two" multiple of
1945668Smec * pagesize.
1950Sstevel@tonic-gate *
1960Sstevel@tonic-gate * On output it is NULL if no address can be found in the current
1970Sstevel@tonic-gate * processes address space or else an address that is currently
1980Sstevel@tonic-gate * not mapped for len bytes with a page of red zone on either side.
1990Sstevel@tonic-gate * If vacalign is true, then the selected address will obey the alignment
2000Sstevel@tonic-gate * constraints of a vac machine based on the given off value.
2010Sstevel@tonic-gate */
2020Sstevel@tonic-gate /*ARGSUSED3*/
2030Sstevel@tonic-gate void
map_addr_proc(caddr_t * addrp,size_t len,offset_t off,int vacalign,caddr_t userlimit,struct proc * p,uint_t flags)2040Sstevel@tonic-gate map_addr_proc(caddr_t *addrp, size_t len, offset_t off, int vacalign,
2050Sstevel@tonic-gate caddr_t userlimit, struct proc *p, uint_t flags)
2060Sstevel@tonic-gate {
2070Sstevel@tonic-gate struct as *as = p->p_as;
2080Sstevel@tonic-gate caddr_t addr;
2090Sstevel@tonic-gate caddr_t base;
2100Sstevel@tonic-gate size_t slen;
2110Sstevel@tonic-gate uintptr_t align_amount;
2120Sstevel@tonic-gate int allow_largepage_alignment = 1;
2130Sstevel@tonic-gate
2140Sstevel@tonic-gate base = p->p_brkbase;
2150Sstevel@tonic-gate if (userlimit < as->a_userlimit) {
2160Sstevel@tonic-gate /*
2170Sstevel@tonic-gate * This happens when a program wants to map something in
2180Sstevel@tonic-gate * a range that's accessible to a program in a smaller
2190Sstevel@tonic-gate * address space. For example, a 64-bit program might
2200Sstevel@tonic-gate * be calling mmap32(2) to guarantee that the returned
2210Sstevel@tonic-gate * address is below 4Gbytes.
2220Sstevel@tonic-gate */
2230Sstevel@tonic-gate ASSERT(userlimit > base);
2240Sstevel@tonic-gate slen = userlimit - base;
2250Sstevel@tonic-gate } else {
2268947SMichael.Corcoran@Sun.COM slen = p->p_usrstack - base -
2278947SMichael.Corcoran@Sun.COM ((p->p_stk_ctl + PAGEOFFSET) & PAGEMASK);
2280Sstevel@tonic-gate }
2295668Smec /* Make len be a multiple of PAGESIZE */
2300Sstevel@tonic-gate len = (len + PAGEOFFSET) & PAGEMASK;
2310Sstevel@tonic-gate
2320Sstevel@tonic-gate /*
2330Sstevel@tonic-gate * If the request is larger than the size of a particular
2340Sstevel@tonic-gate * mmu level, then we use that level to map the request.
2350Sstevel@tonic-gate * But this requires that both the virtual and the physical
2360Sstevel@tonic-gate * addresses be aligned with respect to that level, so we
2370Sstevel@tonic-gate * do the virtual bit of nastiness here.
2380Sstevel@tonic-gate *
2390Sstevel@tonic-gate * For 32-bit processes, only those which have specified
2400Sstevel@tonic-gate * MAP_ALIGN or an addr will be aligned on a page size > 4MB. Otherwise
2410Sstevel@tonic-gate * we can potentially waste up to 256MB of the 4G process address
2420Sstevel@tonic-gate * space just for alignment.
2430Sstevel@tonic-gate *
2440Sstevel@tonic-gate * XXXQ Should iterate trough hw_page_array here to catch
2450Sstevel@tonic-gate * all supported pagesizes
2460Sstevel@tonic-gate */
2470Sstevel@tonic-gate if (p->p_model == DATAMODEL_ILP32 && ((flags & MAP_ALIGN) == 0 ||
2480Sstevel@tonic-gate ((uintptr_t)*addrp) != 0)) {
2490Sstevel@tonic-gate allow_largepage_alignment = 0;
2500Sstevel@tonic-gate }
2510Sstevel@tonic-gate if ((mmu_page_sizes == max_mmu_page_sizes) &&
2520Sstevel@tonic-gate allow_largepage_alignment &&
2535631Swh94709 (len >= MMU_PAGESIZE256M)) { /* 256MB mappings */
2540Sstevel@tonic-gate align_amount = MMU_PAGESIZE256M;
2550Sstevel@tonic-gate } else if ((mmu_page_sizes == max_mmu_page_sizes) &&
2560Sstevel@tonic-gate allow_largepage_alignment &&
2575631Swh94709 (len >= MMU_PAGESIZE32M)) { /* 32MB mappings */
2580Sstevel@tonic-gate align_amount = MMU_PAGESIZE32M;
2590Sstevel@tonic-gate } else if (len >= MMU_PAGESIZE4M) { /* 4MB mappings */
2600Sstevel@tonic-gate align_amount = MMU_PAGESIZE4M;
2610Sstevel@tonic-gate } else if (len >= MMU_PAGESIZE512K) { /* 512KB mappings */
2620Sstevel@tonic-gate align_amount = MMU_PAGESIZE512K;
2630Sstevel@tonic-gate } else if (len >= MMU_PAGESIZE64K) { /* 64KB mappings */
2640Sstevel@tonic-gate align_amount = MMU_PAGESIZE64K;
2650Sstevel@tonic-gate } else {
2660Sstevel@tonic-gate /*
2670Sstevel@tonic-gate * Align virtual addresses on a 64K boundary to ensure
2680Sstevel@tonic-gate * that ELF shared libraries are mapped with the appropriate
2690Sstevel@tonic-gate * alignment constraints by the run-time linker.
2700Sstevel@tonic-gate */
2710Sstevel@tonic-gate align_amount = ELF_SPARC_MAXPGSZ;
2720Sstevel@tonic-gate if ((flags & MAP_ALIGN) && ((uintptr_t)*addrp != 0) &&
2735631Swh94709 ((uintptr_t)*addrp < align_amount))
2740Sstevel@tonic-gate align_amount = (uintptr_t)*addrp;
2750Sstevel@tonic-gate }
2760Sstevel@tonic-gate
2770Sstevel@tonic-gate /*
2780Sstevel@tonic-gate * 64-bit processes require 1024K alignment of ELF shared libraries.
2790Sstevel@tonic-gate */
2800Sstevel@tonic-gate if (p->p_model == DATAMODEL_LP64)
2810Sstevel@tonic-gate align_amount = MAX(align_amount, ELF_SPARCV9_MAXPGSZ);
2820Sstevel@tonic-gate #ifdef VAC
2830Sstevel@tonic-gate if (vac && vacalign && (align_amount < shm_alignment))
2840Sstevel@tonic-gate align_amount = shm_alignment;
2850Sstevel@tonic-gate #endif
2860Sstevel@tonic-gate
2870Sstevel@tonic-gate if ((flags & MAP_ALIGN) && ((uintptr_t)*addrp > align_amount)) {
2880Sstevel@tonic-gate align_amount = (uintptr_t)*addrp;
2890Sstevel@tonic-gate }
2905668Smec
2915668Smec ASSERT(ISP2(align_amount));
2925668Smec ASSERT(align_amount == 0 || align_amount >= PAGESIZE);
2930Sstevel@tonic-gate
2940Sstevel@tonic-gate /*
2950Sstevel@tonic-gate * Look for a large enough hole starting below the stack limit.
2965668Smec * After finding it, use the upper part.
2970Sstevel@tonic-gate */
2980Sstevel@tonic-gate as_purge(as);
2995668Smec off = off & (align_amount - 1);
3005668Smec if (as_gap_aligned(as, len, &base, &slen, AH_HI, NULL, align_amount,
3015668Smec PAGESIZE, off) == 0) {
3020Sstevel@tonic-gate caddr_t as_addr;
3030Sstevel@tonic-gate
3045668Smec /*
3055668Smec * addr is the highest possible address to use since we have
3065668Smec * a PAGESIZE redzone at the beginning and end.
3075668Smec */
3085668Smec addr = base + slen - (PAGESIZE + len);
3090Sstevel@tonic-gate as_addr = addr;
3100Sstevel@tonic-gate /*
3115668Smec * Round address DOWN to the alignment amount and
3125668Smec * add the offset in.
3135668Smec * If addr is greater than as_addr, len would not be large
3145668Smec * enough to include the redzone, so we must adjust down
3155668Smec * by the alignment amount.
3160Sstevel@tonic-gate */
3170Sstevel@tonic-gate addr = (caddr_t)((uintptr_t)addr & (~(align_amount - 1l)));
3185668Smec addr += (long)off;
3195668Smec if (addr > as_addr) {
3205668Smec addr -= align_amount;
3210Sstevel@tonic-gate }
3220Sstevel@tonic-gate
3235668Smec ASSERT(addr > base);
3245668Smec ASSERT(addr + len < base + slen);
3250Sstevel@tonic-gate ASSERT(((uintptr_t)addr & (align_amount - 1l)) ==
3265668Smec ((uintptr_t)(off)));
3270Sstevel@tonic-gate *addrp = addr;
3280Sstevel@tonic-gate
3290Sstevel@tonic-gate } else {
3300Sstevel@tonic-gate *addrp = NULL; /* no more virtual space */
3310Sstevel@tonic-gate }
3320Sstevel@tonic-gate }
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate /*
3350Sstevel@tonic-gate * Platform-dependent page scrub call.
3360Sstevel@tonic-gate * We call hypervisor to scrub the page.
3370Sstevel@tonic-gate */
3380Sstevel@tonic-gate void
pagescrub(page_t * pp,uint_t off,uint_t len)3390Sstevel@tonic-gate pagescrub(page_t *pp, uint_t off, uint_t len)
3400Sstevel@tonic-gate {
3410Sstevel@tonic-gate uint64_t pa, length;
3420Sstevel@tonic-gate
3430Sstevel@tonic-gate pa = (uint64_t)(pp->p_pagenum << MMU_PAGESHIFT + off);
3440Sstevel@tonic-gate length = (uint64_t)len;
3450Sstevel@tonic-gate
3460Sstevel@tonic-gate (void) mem_scrub(pa, length);
3470Sstevel@tonic-gate }
3480Sstevel@tonic-gate
3490Sstevel@tonic-gate void
sync_data_memory(caddr_t va,size_t len)3500Sstevel@tonic-gate sync_data_memory(caddr_t va, size_t len)
3510Sstevel@tonic-gate {
3520Sstevel@tonic-gate /* Call memory sync function */
3533199Sep32863 (void) mem_sync(va, len);
3540Sstevel@tonic-gate }
3550Sstevel@tonic-gate
3560Sstevel@tonic-gate size_t
mmu_get_kernel_lpsize(size_t lpsize)3570Sstevel@tonic-gate mmu_get_kernel_lpsize(size_t lpsize)
3580Sstevel@tonic-gate {
3590Sstevel@tonic-gate extern int mmu_exported_pagesize_mask;
3600Sstevel@tonic-gate uint_t tte;
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate if (lpsize == 0) {
3630Sstevel@tonic-gate /* no setting for segkmem_lpsize in /etc/system: use default */
3640Sstevel@tonic-gate if (mmu_exported_pagesize_mask & (1 << TTE256M)) {
3650Sstevel@tonic-gate lpsize = MMU_PAGESIZE256M;
3660Sstevel@tonic-gate } else if (mmu_exported_pagesize_mask & (1 << TTE4M)) {
3670Sstevel@tonic-gate lpsize = MMU_PAGESIZE4M;
3680Sstevel@tonic-gate } else if (mmu_exported_pagesize_mask & (1 << TTE64K)) {
3690Sstevel@tonic-gate lpsize = MMU_PAGESIZE64K;
3700Sstevel@tonic-gate } else {
3710Sstevel@tonic-gate lpsize = MMU_PAGESIZE;
3720Sstevel@tonic-gate }
3730Sstevel@tonic-gate
3740Sstevel@tonic-gate return (lpsize);
3750Sstevel@tonic-gate }
3760Sstevel@tonic-gate
3770Sstevel@tonic-gate for (tte = TTE8K; tte <= TTE256M; tte++) {
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate if ((mmu_exported_pagesize_mask & (1 << tte)) == 0)
3800Sstevel@tonic-gate continue;
3810Sstevel@tonic-gate
3820Sstevel@tonic-gate if (lpsize == TTEBYTES(tte))
3830Sstevel@tonic-gate return (lpsize);
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate
3860Sstevel@tonic-gate lpsize = TTEBYTES(TTE8K);
3870Sstevel@tonic-gate return (lpsize);
3880Sstevel@tonic-gate }
3890Sstevel@tonic-gate
3900Sstevel@tonic-gate void
mmu_init_kcontext()3910Sstevel@tonic-gate mmu_init_kcontext()
3920Sstevel@tonic-gate {
3930Sstevel@tonic-gate }
3940Sstevel@tonic-gate
3950Sstevel@tonic-gate /*ARGSUSED*/
3960Sstevel@tonic-gate void
mmu_init_kernel_pgsz(struct hat * hat)3970Sstevel@tonic-gate mmu_init_kernel_pgsz(struct hat *hat)
3980Sstevel@tonic-gate {
3990Sstevel@tonic-gate }
4000Sstevel@tonic-gate
4010Sstevel@tonic-gate static void *
contig_mem_span_alloc(vmem_t * vmp,size_t size,int vmflag)4020Sstevel@tonic-gate contig_mem_span_alloc(vmem_t *vmp, size_t size, int vmflag)
4030Sstevel@tonic-gate {
4040Sstevel@tonic-gate page_t *ppl;
4050Sstevel@tonic-gate page_t *rootpp;
4060Sstevel@tonic-gate caddr_t addr = NULL;
4070Sstevel@tonic-gate pgcnt_t npages = btopr(size);
4080Sstevel@tonic-gate page_t **ppa;
4090Sstevel@tonic-gate int pgflags;
4104204Sha137994 spgcnt_t i = 0;
4110Sstevel@tonic-gate
4120Sstevel@tonic-gate
4134204Sha137994 ASSERT(size <= contig_mem_import_size_max);
4144204Sha137994 ASSERT((size & (size - 1)) == 0);
4151859Sha137994
4160Sstevel@tonic-gate if ((addr = vmem_xalloc(vmp, size, size, 0, 0,
4170Sstevel@tonic-gate NULL, NULL, vmflag)) == NULL) {
4180Sstevel@tonic-gate return (NULL);
4190Sstevel@tonic-gate }
4200Sstevel@tonic-gate
4211859Sha137994 /* The address should be slab-size aligned. */
4224204Sha137994 ASSERT(((uintptr_t)addr & (size - 1)) == 0);
4230Sstevel@tonic-gate
4240Sstevel@tonic-gate if (page_resv(npages, vmflag & VM_KMFLAGS) == 0) {
4250Sstevel@tonic-gate vmem_xfree(vmp, addr, size);
4260Sstevel@tonic-gate return (NULL);
4270Sstevel@tonic-gate }
4280Sstevel@tonic-gate
4290Sstevel@tonic-gate pgflags = PG_EXCL;
4304204Sha137994 if (vmflag & VM_NORELOC)
4314204Sha137994 pgflags |= PG_NORELOC;
4320Sstevel@tonic-gate
4330Sstevel@tonic-gate ppl = page_create_va_large(&kvp, (u_offset_t)(uintptr_t)addr, size,
4340Sstevel@tonic-gate pgflags, &kvseg, addr, NULL);
4350Sstevel@tonic-gate
4360Sstevel@tonic-gate if (ppl == NULL) {
4370Sstevel@tonic-gate vmem_xfree(vmp, addr, size);
4380Sstevel@tonic-gate page_unresv(npages);
4390Sstevel@tonic-gate return (NULL);
4400Sstevel@tonic-gate }
4410Sstevel@tonic-gate
4420Sstevel@tonic-gate rootpp = ppl;
4430Sstevel@tonic-gate ppa = kmem_zalloc(npages * sizeof (page_t *), KM_SLEEP);
4440Sstevel@tonic-gate while (ppl != NULL) {
4450Sstevel@tonic-gate page_t *pp = ppl;
4460Sstevel@tonic-gate ppa[i++] = pp;
4470Sstevel@tonic-gate page_sub(&ppl, pp);
4480Sstevel@tonic-gate ASSERT(page_iolock_assert(pp));
4494204Sha137994 ASSERT(PAGE_EXCL(pp));
4500Sstevel@tonic-gate page_io_unlock(pp);
4510Sstevel@tonic-gate }
4520Sstevel@tonic-gate
4530Sstevel@tonic-gate /*
4540Sstevel@tonic-gate * Load the locked entry. It's OK to preload the entry into
4550Sstevel@tonic-gate * the TSB since we now support large mappings in the kernel TSB.
4560Sstevel@tonic-gate */
4570Sstevel@tonic-gate hat_memload_array(kas.a_hat, (caddr_t)rootpp->p_offset, size,
4580Sstevel@tonic-gate ppa, (PROT_ALL & ~PROT_USER) | HAT_NOSYNC, HAT_LOAD_LOCK);
4590Sstevel@tonic-gate
4604204Sha137994 ASSERT(i == page_get_pagecnt(ppa[0]->p_szc));
4610Sstevel@tonic-gate for (--i; i >= 0; --i) {
4624204Sha137994 ASSERT(ppa[i]->p_szc == ppa[0]->p_szc);
4634204Sha137994 ASSERT(page_pptonum(ppa[i]) == page_pptonum(ppa[0]) + i);
4640Sstevel@tonic-gate (void) page_pp_lock(ppa[i], 0, 1);
4654204Sha137994 /*
4664204Sha137994 * Leave the page share locked. For non-cage pages,
4674204Sha137994 * this would prevent memory DR if it were supported
4684204Sha137994 * on sun4v.
4694204Sha137994 */
4704204Sha137994 page_downgrade(ppa[i]);
4710Sstevel@tonic-gate }
4720Sstevel@tonic-gate
4730Sstevel@tonic-gate kmem_free(ppa, npages * sizeof (page_t *));
4740Sstevel@tonic-gate return (addr);
4750Sstevel@tonic-gate }
4760Sstevel@tonic-gate
4774204Sha137994 /*
4784204Sha137994 * Allocates a slab by first trying to use the largest slab size
4794204Sha137994 * in contig_mem_import_sizes and then falling back to smaller slab
4804204Sha137994 * sizes still large enough for the allocation. The sizep argument
4814204Sha137994 * is a pointer to the requested size. When a slab is successfully
4824204Sha137994 * allocated, the slab size, which must be >= *sizep and <=
4834204Sha137994 * contig_mem_import_size_max, is returned in the *sizep argument.
4844204Sha137994 * Returns the virtual address of the new slab.
4854204Sha137994 */
4864204Sha137994 static void *
span_alloc_downsize(vmem_t * vmp,size_t * sizep,size_t align,int vmflag)4874204Sha137994 span_alloc_downsize(vmem_t *vmp, size_t *sizep, size_t align, int vmflag)
4884204Sha137994 {
4894204Sha137994 int i;
4904204Sha137994
4914204Sha137994 ASSERT(*sizep <= contig_mem_import_size_max);
4924204Sha137994
4934204Sha137994 for (i = 0; i < NUM_IMPORT_SIZES; i++) {
4944204Sha137994 size_t page_size = contig_mem_import_sizes[i];
4954204Sha137994
4964204Sha137994 /*
4974204Sha137994 * Check that the alignment is also less than the
4984204Sha137994 * import (large page) size. In the case where the
4994204Sha137994 * alignment is larger than the size, a large page
5004204Sha137994 * large enough for the allocation is not necessarily
5014204Sha137994 * physical-address aligned to satisfy the requested
5024204Sha137994 * alignment. Since alignment is required to be a
5034204Sha137994 * power-of-2, any large page >= size && >= align will
5044204Sha137994 * suffice.
5054204Sha137994 */
5064204Sha137994 if (*sizep <= page_size && align <= page_size) {
5074204Sha137994 void *addr;
5084204Sha137994 addr = contig_mem_span_alloc(vmp, page_size, vmflag);
5094204Sha137994 if (addr == NULL)
5104204Sha137994 continue;
5114204Sha137994 *sizep = page_size;
5124204Sha137994 return (addr);
5134204Sha137994 }
5144204Sha137994 return (NULL);
5154204Sha137994 }
5164204Sha137994
5174204Sha137994 return (NULL);
5184204Sha137994 }
5194204Sha137994
5204204Sha137994 static void *
contig_mem_span_xalloc(vmem_t * vmp,size_t * sizep,size_t align,int vmflag)5214204Sha137994 contig_mem_span_xalloc(vmem_t *vmp, size_t *sizep, size_t align, int vmflag)
5224204Sha137994 {
5234204Sha137994 return (span_alloc_downsize(vmp, sizep, align, vmflag | VM_NORELOC));
5244204Sha137994 }
5254204Sha137994
5264204Sha137994 static void *
contig_mem_reloc_span_xalloc(vmem_t * vmp,size_t * sizep,size_t align,int vmflag)5274204Sha137994 contig_mem_reloc_span_xalloc(vmem_t *vmp, size_t *sizep, size_t align,
5284204Sha137994 int vmflag)
5294204Sha137994 {
5304204Sha137994 ASSERT((vmflag & VM_NORELOC) == 0);
5314204Sha137994 return (span_alloc_downsize(vmp, sizep, align, vmflag));
5324204Sha137994 }
5334204Sha137994
5344204Sha137994 /*
5354204Sha137994 * Free a span, which is always exactly one large page.
5364204Sha137994 */
5374204Sha137994 static void
contig_mem_span_free(vmem_t * vmp,void * inaddr,size_t size)5380Sstevel@tonic-gate contig_mem_span_free(vmem_t *vmp, void *inaddr, size_t size)
5390Sstevel@tonic-gate {
5400Sstevel@tonic-gate page_t *pp;
5410Sstevel@tonic-gate caddr_t addr = inaddr;
5420Sstevel@tonic-gate caddr_t eaddr;
5430Sstevel@tonic-gate pgcnt_t npages = btopr(size);
5440Sstevel@tonic-gate page_t *rootpp = NULL;
5450Sstevel@tonic-gate
5464204Sha137994 ASSERT(size <= contig_mem_import_size_max);
5474204Sha137994 /* All slabs should be size aligned */
5484204Sha137994 ASSERT(((uintptr_t)addr & (size - 1)) == 0);
5490Sstevel@tonic-gate
5500Sstevel@tonic-gate hat_unload(kas.a_hat, addr, size, HAT_UNLOAD_UNLOCK);
5510Sstevel@tonic-gate
5520Sstevel@tonic-gate for (eaddr = addr + size; addr < eaddr; addr += PAGESIZE) {
5534204Sha137994 pp = page_find(&kvp, (u_offset_t)(uintptr_t)addr);
5544204Sha137994 if (pp == NULL) {
5550Sstevel@tonic-gate panic("contig_mem_span_free: page not found");
5564204Sha137994 }
5574204Sha137994 if (!page_tryupgrade(pp)) {
5584204Sha137994 page_unlock(pp);
5594204Sha137994 pp = page_lookup(&kvp,
5604204Sha137994 (u_offset_t)(uintptr_t)addr, SE_EXCL);
5614204Sha137994 if (pp == NULL)
5624204Sha137994 panic("contig_mem_span_free: page not found");
5634204Sha137994 }
5640Sstevel@tonic-gate
5650Sstevel@tonic-gate ASSERT(PAGE_EXCL(pp));
5664204Sha137994 ASSERT(size == page_get_pagesize(pp->p_szc));
5674204Sha137994 ASSERT(rootpp == NULL || rootpp->p_szc == pp->p_szc);
5684204Sha137994 ASSERT(rootpp == NULL || (page_pptonum(rootpp) +
5694204Sha137994 (pgcnt_t)btop(addr - (caddr_t)inaddr) == page_pptonum(pp)));
5704204Sha137994
5710Sstevel@tonic-gate page_pp_unlock(pp, 0, 1);
5720Sstevel@tonic-gate
5730Sstevel@tonic-gate if (rootpp == NULL)
5740Sstevel@tonic-gate rootpp = pp;
5750Sstevel@tonic-gate }
5764204Sha137994 page_destroy_pages(rootpp);
5770Sstevel@tonic-gate page_unresv(npages);
5780Sstevel@tonic-gate
5790Sstevel@tonic-gate if (vmp != NULL)
5800Sstevel@tonic-gate vmem_xfree(vmp, inaddr, size);
5810Sstevel@tonic-gate }
5820Sstevel@tonic-gate
5830Sstevel@tonic-gate static void *
contig_vmem_xalloc_aligned_wrapper(vmem_t * vmp,size_t * sizep,size_t align,int vmflag)5844204Sha137994 contig_vmem_xalloc_aligned_wrapper(vmem_t *vmp, size_t *sizep, size_t align,
5854204Sha137994 int vmflag)
5860Sstevel@tonic-gate {
5874204Sha137994 ASSERT((align & (align - 1)) == 0);
5884204Sha137994 return (vmem_xalloc(vmp, *sizep, align, 0, 0, NULL, NULL, vmflag));
5890Sstevel@tonic-gate }
5900Sstevel@tonic-gate
591288Sarao /*
5924204Sha137994 * contig_mem_alloc, contig_mem_alloc_align
5934204Sha137994 *
5944204Sha137994 * Caution: contig_mem_alloc and contig_mem_alloc_align should be
5954204Sha137994 * used only when physically contiguous non-relocatable memory is
5964204Sha137994 * required. Furthermore, use of these allocation routines should be
5974204Sha137994 * minimized as well as should the allocation size. As described in the
5984204Sha137994 * contig_mem_arena comment block above, slab allocations fall back to
5994204Sha137994 * being outside of the cage. Therefore, overuse of these allocation
6004204Sha137994 * routines can lead to non-relocatable large pages being allocated
6014204Sha137994 * outside the cage. Such pages prevent the allocation of a larger page
6024204Sha137994 * occupying overlapping pages. This can impact performance for
6034204Sha137994 * applications that utilize e.g. 256M large pages.
604288Sarao */
605288Sarao
606288Sarao /*
6074204Sha137994 * Allocates size aligned contiguous memory up to contig_mem_import_size_max.
608288Sarao * Size must be a power of 2.
609288Sarao */
6100Sstevel@tonic-gate void *
contig_mem_alloc(size_t size)6110Sstevel@tonic-gate contig_mem_alloc(size_t size)
6120Sstevel@tonic-gate {
613288Sarao ASSERT((size & (size - 1)) == 0);
614288Sarao return (contig_mem_alloc_align(size, size));
6150Sstevel@tonic-gate }
6160Sstevel@tonic-gate
6174204Sha137994 /*
618*10271SJason.Beloro@Sun.COM * contig_mem_alloc_align allocates real contiguous memory with the
6198819SJason.Beloro@Sun.COM * specified alignment up to contig_mem_import_size_max. The alignment must
6208819SJason.Beloro@Sun.COM * be a power of 2 and no greater than contig_mem_import_size_max. We assert
6214204Sha137994 * the aligment is a power of 2. For non-debug, vmem_xalloc will panic
6224204Sha137994 * for non power of 2 alignments.
6234204Sha137994 */
624*10271SJason.Beloro@Sun.COM void *
contig_mem_alloc_align(size_t size,size_t align)625*10271SJason.Beloro@Sun.COM contig_mem_alloc_align(size_t size, size_t align)
6264204Sha137994 {
6274204Sha137994 void *buf;
6284204Sha137994
6294204Sha137994 ASSERT(size <= contig_mem_import_size_max);
6304204Sha137994 ASSERT(align <= contig_mem_import_size_max);
6314204Sha137994 ASSERT((align & (align - 1)) == 0);
6324204Sha137994
6334204Sha137994 if (align < CONTIG_MEM_ARENA_QUANTUM)
6344204Sha137994 align = CONTIG_MEM_ARENA_QUANTUM;
6354204Sha137994
6364204Sha137994 /*
6374204Sha137994 * We take the lock here to serialize span allocations.
6384204Sha137994 * We do not lose concurrency for the common case, since
6394204Sha137994 * allocations that don't require new span allocations
6404204Sha137994 * are serialized by vmem_xalloc. Serializing span
6414204Sha137994 * allocations also prevents us from trying to allocate
6428819SJason.Beloro@Sun.COM * more spans than necessary.
6434204Sha137994 */
644*10271SJason.Beloro@Sun.COM mutex_enter(&contig_mem_lock);
6454204Sha137994
6464204Sha137994 buf = vmem_xalloc(contig_mem_arena, size, align, 0, 0,
647*10271SJason.Beloro@Sun.COM NULL, NULL, VM_NOSLEEP | VM_NORELOC);
6484204Sha137994
6494204Sha137994 if ((buf == NULL) && (size <= MMU_PAGESIZE)) {
650*10271SJason.Beloro@Sun.COM mutex_exit(&contig_mem_lock);
6514204Sha137994 return (vmem_xalloc(static_alloc_arena, size, align, 0, 0,
652*10271SJason.Beloro@Sun.COM NULL, NULL, VM_NOSLEEP));
6534204Sha137994 }
6544204Sha137994
6554204Sha137994 if (buf == NULL) {
6564204Sha137994 buf = vmem_xalloc(contig_mem_reloc_arena, size, align, 0, 0,
657*10271SJason.Beloro@Sun.COM NULL, NULL, VM_NOSLEEP);
6584204Sha137994 }
6594204Sha137994
660*10271SJason.Beloro@Sun.COM mutex_exit(&contig_mem_lock);
6614204Sha137994
6624204Sha137994 return (buf);
6634204Sha137994 }
6644204Sha137994
6650Sstevel@tonic-gate void
contig_mem_free(void * vaddr,size_t size)6660Sstevel@tonic-gate contig_mem_free(void *vaddr, size_t size)
6670Sstevel@tonic-gate {
6684204Sha137994 if (vmem_contains(contig_mem_arena, vaddr, size)) {
6694204Sha137994 vmem_xfree(contig_mem_arena, vaddr, size);
6704204Sha137994 } else if (size > MMU_PAGESIZE) {
6714204Sha137994 vmem_xfree(contig_mem_reloc_arena, vaddr, size);
6724204Sha137994 } else {
6734204Sha137994 vmem_xfree(static_alloc_arena, vaddr, size);
6744204Sha137994 }
6750Sstevel@tonic-gate }
6760Sstevel@tonic-gate
6770Sstevel@tonic-gate /*
6780Sstevel@tonic-gate * We create a set of stacked vmem arenas to enable us to
6794204Sha137994 * allocate large >PAGESIZE chucks of contiguous Real Address space.
6804204Sha137994 * The vmem_xcreate interface is used to create the contig_mem_arena
6814204Sha137994 * allowing the import routine to downsize the requested slab size
6824204Sha137994 * and return a smaller slab.
6830Sstevel@tonic-gate */
6840Sstevel@tonic-gate void
contig_mem_init(void)6850Sstevel@tonic-gate contig_mem_init(void)
6860Sstevel@tonic-gate {
6874204Sha137994 mutex_init(&contig_mem_lock, NULL, MUTEX_DEFAULT, NULL);
6880Sstevel@tonic-gate
6894204Sha137994 contig_mem_slab_arena = vmem_xcreate("contig_mem_slab_arena", NULL, 0,
6904204Sha137994 CONTIG_MEM_SLAB_ARENA_QUANTUM, contig_vmem_xalloc_aligned_wrapper,
6914204Sha137994 vmem_xfree, heap_arena, 0, VM_SLEEP | VMC_XALIGN);
6920Sstevel@tonic-gate
6934204Sha137994 contig_mem_arena = vmem_xcreate("contig_mem_arena", NULL, 0,
6944204Sha137994 CONTIG_MEM_ARENA_QUANTUM, contig_mem_span_xalloc,
6954204Sha137994 contig_mem_span_free, contig_mem_slab_arena, 0,
6964204Sha137994 VM_SLEEP | VM_BESTFIT | VMC_XALIGN);
6970Sstevel@tonic-gate
6984204Sha137994 contig_mem_reloc_arena = vmem_xcreate("contig_mem_reloc_arena", NULL, 0,
6994204Sha137994 CONTIG_MEM_ARENA_QUANTUM, contig_mem_reloc_span_xalloc,
7004204Sha137994 contig_mem_span_free, contig_mem_slab_arena, 0,
7014204Sha137994 VM_SLEEP | VM_BESTFIT | VMC_XALIGN);
7024204Sha137994
7036661Sdavemq if (contig_mem_prealloc_buf == NULL || vmem_add(contig_mem_arena,
7046661Sdavemq contig_mem_prealloc_buf, contig_mem_prealloc_size, VM_SLEEP)
7056661Sdavemq == NULL) {
7066661Sdavemq cmn_err(CE_WARN, "Failed to pre-populate contig_mem_arena");
7076661Sdavemq }
7080Sstevel@tonic-gate }
7093177Sdp78419
7104204Sha137994 /*
7114204Sha137994 * In calculating how much memory to pre-allocate, we include a small
7124204Sha137994 * amount per-CPU to account for per-CPU buffers in line with measured
7135631Swh94709 * values for different size systems. contig_mem_prealloc_base_size is
7145631Swh94709 * a cpu specific amount to be pre-allocated before considering per-CPU
7155631Swh94709 * requirements and memory size. We always pre-allocate a minimum amount
7165631Swh94709 * of memory determined by PREALLOC_MIN. Beyond that, we take the minimum
7175631Swh94709 * of contig_mem_prealloc_base_size and a small percentage of physical
7185631Swh94709 * memory to prevent allocating too much on smaller systems.
7195631Swh94709 * contig_mem_prealloc_base_size is global, allowing for the CPU module
7205631Swh94709 * to increase its value if necessary.
7214204Sha137994 */
7224204Sha137994 #define PREALLOC_PER_CPU (256 * 1024) /* 256K */
7234204Sha137994 #define PREALLOC_PERCENT (4) /* 4% */
7244204Sha137994 #define PREALLOC_MIN (16 * 1024 * 1024) /* 16M */
7255631Swh94709 size_t contig_mem_prealloc_base_size = 0;
7264204Sha137994
7274204Sha137994 /*
7284204Sha137994 * Called at boot-time allowing pre-allocation of contiguous memory.
7294204Sha137994 * The argument 'alloc_base' is the requested base address for the
7304204Sha137994 * allocation and originates in startup_memlist.
7314204Sha137994 */
7324204Sha137994 caddr_t
contig_mem_prealloc(caddr_t alloc_base,pgcnt_t npages)7334204Sha137994 contig_mem_prealloc(caddr_t alloc_base, pgcnt_t npages)
7344204Sha137994 {
7356661Sdavemq caddr_t chunkp;
7366661Sdavemq
7375631Swh94709 contig_mem_prealloc_size = MIN((PREALLOC_PER_CPU * ncpu_guest_max) +
7385631Swh94709 contig_mem_prealloc_base_size,
7395631Swh94709 (ptob(npages) * PREALLOC_PERCENT) / 100);
7405631Swh94709 contig_mem_prealloc_size = MAX(contig_mem_prealloc_size, PREALLOC_MIN);
7415631Swh94709 contig_mem_prealloc_size = P2ROUNDUP(contig_mem_prealloc_size,
7425631Swh94709 MMU_PAGESIZE4M);
7434204Sha137994
7444204Sha137994 alloc_base = (caddr_t)roundup((uintptr_t)alloc_base, MMU_PAGESIZE4M);
7455648Ssetje if (prom_alloc(alloc_base, contig_mem_prealloc_size,
7466661Sdavemq MMU_PAGESIZE4M) != alloc_base) {
7476661Sdavemq
7486661Sdavemq /*
7496661Sdavemq * Failed. This may mean the physical memory has holes in it
7506661Sdavemq * and it will be more difficult to get large contiguous
7516661Sdavemq * pieces of memory. Since we only guarantee contiguous
7526661Sdavemq * pieces of memory contig_mem_import_size_max or smaller,
7536661Sdavemq * loop, getting contig_mem_import_size_max at a time, until
7546661Sdavemq * failure or contig_mem_prealloc_size is reached.
7556661Sdavemq */
7566661Sdavemq for (chunkp = alloc_base;
7576661Sdavemq (chunkp - alloc_base) < contig_mem_prealloc_size;
7586661Sdavemq chunkp += contig_mem_import_size_max) {
7595648Ssetje
7606661Sdavemq if (prom_alloc(chunkp, contig_mem_import_size_max,
7616661Sdavemq MMU_PAGESIZE4M) != chunkp) {
7626661Sdavemq break;
7636661Sdavemq }
7646661Sdavemq }
7656661Sdavemq contig_mem_prealloc_size = chunkp - alloc_base;
7666661Sdavemq ASSERT(contig_mem_prealloc_size != 0);
7676661Sdavemq }
7686661Sdavemq
7696661Sdavemq if (contig_mem_prealloc_size != 0) {
7706661Sdavemq contig_mem_prealloc_buf = alloc_base;
7716661Sdavemq } else {
7726661Sdavemq contig_mem_prealloc_buf = NULL;
7736661Sdavemq }
7745631Swh94709 alloc_base += contig_mem_prealloc_size;
7754204Sha137994
7764204Sha137994 return (alloc_base);
7774204Sha137994 }
7783177Sdp78419
7793177Sdp78419 static uint_t sp_color_stride = 16;
7803177Sdp78419 static uint_t sp_color_mask = 0x1f;
7813177Sdp78419 static uint_t sp_current_color = (uint_t)-1;
7823177Sdp78419
7833177Sdp78419 size_t
exec_get_spslew(void)7843177Sdp78419 exec_get_spslew(void)
7853177Sdp78419 {
7863177Sdp78419 uint_t spcolor = atomic_inc_32_nv(&sp_current_color);
7873177Sdp78419 return ((size_t)((spcolor & sp_color_mask) * SA(sp_color_stride)));
7883177Sdp78419 }
789