xref: /freebsd/sys/riscv/include/vmparam.h (revision 02a371289a3766de9d06a7791357921aba4606a9)
18d7e7a98SRuslan Bukin /*-
28d7e7a98SRuslan Bukin  * Copyright (c) 1990 The Regents of the University of California.
38d7e7a98SRuslan Bukin  * All rights reserved.
48d7e7a98SRuslan Bukin  * Copyright (c) 1994 John S. Dyson
58d7e7a98SRuslan Bukin  * All rights reserved.
68d7e7a98SRuslan Bukin  *
78d7e7a98SRuslan Bukin  * This code is derived from software contributed to Berkeley by
88d7e7a98SRuslan Bukin  * William Jolitz.
98d7e7a98SRuslan Bukin  *
108d7e7a98SRuslan Bukin  * Redistribution and use in source and binary forms, with or without
118d7e7a98SRuslan Bukin  * modification, are permitted provided that the following conditions
128d7e7a98SRuslan Bukin  * are met:
138d7e7a98SRuslan Bukin  * 1. Redistributions of source code must retain the above copyright
148d7e7a98SRuslan Bukin  *    notice, this list of conditions and the following disclaimer.
158d7e7a98SRuslan Bukin  * 2. Redistributions in binary form must reproduce the above copyright
168d7e7a98SRuslan Bukin  *    notice, this list of conditions and the following disclaimer in the
178d7e7a98SRuslan Bukin  *    documentation and/or other materials provided with the distribution.
188d7e7a98SRuslan Bukin  * 3. Neither the name of the University nor the names of its contributors
198d7e7a98SRuslan Bukin  *    may be used to endorse or promote products derived from this software
208d7e7a98SRuslan Bukin  *    without specific prior written permission.
218d7e7a98SRuslan Bukin  *
228d7e7a98SRuslan Bukin  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
238d7e7a98SRuslan Bukin  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
248d7e7a98SRuslan Bukin  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
258d7e7a98SRuslan Bukin  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
268d7e7a98SRuslan Bukin  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
278d7e7a98SRuslan Bukin  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
288d7e7a98SRuslan Bukin  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
298d7e7a98SRuslan Bukin  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
308d7e7a98SRuslan Bukin  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
318d7e7a98SRuslan Bukin  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
328d7e7a98SRuslan Bukin  * SUCH DAMAGE.
338d7e7a98SRuslan Bukin  *
348d7e7a98SRuslan Bukin  *	from: @(#)vmparam.h     5.9 (Berkeley) 5/12/91
358d7e7a98SRuslan Bukin  *	from: FreeBSD: src/sys/i386/include/vmparam.h,v 1.33 2000/03/30
368d7e7a98SRuslan Bukin  * $FreeBSD$
378d7e7a98SRuslan Bukin  */
388d7e7a98SRuslan Bukin 
398d7e7a98SRuslan Bukin #ifndef	_MACHINE_VMPARAM_H_
408d7e7a98SRuslan Bukin #define	_MACHINE_VMPARAM_H_
418d7e7a98SRuslan Bukin 
428d7e7a98SRuslan Bukin /*
438d7e7a98SRuslan Bukin  * Virtual memory related constants, all in bytes
448d7e7a98SRuslan Bukin  */
458d7e7a98SRuslan Bukin #ifndef MAXTSIZ
46229f3f0dSRuslan Bukin #define	MAXTSIZ		(1*1024*1024*1024)	/* max text size */
478d7e7a98SRuslan Bukin #endif
488d7e7a98SRuslan Bukin #ifndef DFLDSIZ
498d7e7a98SRuslan Bukin #define	DFLDSIZ		(128*1024*1024)		/* initial data size limit */
508d7e7a98SRuslan Bukin #endif
518d7e7a98SRuslan Bukin #ifndef MAXDSIZ
52229f3f0dSRuslan Bukin #define	MAXDSIZ		(1*1024*1024*1024)	/* max data size */
538d7e7a98SRuslan Bukin #endif
548d7e7a98SRuslan Bukin #ifndef DFLSSIZ
55229f3f0dSRuslan Bukin #define	DFLSSIZ		(128*1024*1024)		/* initial stack size limit */
568d7e7a98SRuslan Bukin #endif
578d7e7a98SRuslan Bukin #ifndef MAXSSIZ
58229f3f0dSRuslan Bukin #define	MAXSSIZ		(1*1024*1024*1024)	/* max stack size */
598d7e7a98SRuslan Bukin #endif
608d7e7a98SRuslan Bukin #ifndef SGROWSIZ
618d7e7a98SRuslan Bukin #define	SGROWSIZ	(128*1024)		/* amount to grow stack */
628d7e7a98SRuslan Bukin #endif
638d7e7a98SRuslan Bukin 
648d7e7a98SRuslan Bukin /*
658d7e7a98SRuslan Bukin  * The physical address space is sparsely populated.
668d7e7a98SRuslan Bukin  */
678d7e7a98SRuslan Bukin #define	VM_PHYSSEG_SPARSE
688d7e7a98SRuslan Bukin 
698d7e7a98SRuslan Bukin /*
708d7e7a98SRuslan Bukin  * The number of PHYSSEG entries must be one greater than the number
718d7e7a98SRuslan Bukin  * of phys_avail entries because the phys_avail entry that spans the
728d7e7a98SRuslan Bukin  * largest physical address that is accessible by ISA DMA is split
738d7e7a98SRuslan Bukin  * into two PHYSSEG entries.
748d7e7a98SRuslan Bukin  */
758d7e7a98SRuslan Bukin #define	VM_PHYSSEG_MAX		64
768d7e7a98SRuslan Bukin 
778d7e7a98SRuslan Bukin /*
788d7e7a98SRuslan Bukin  * Create two free page pools: VM_FREEPOOL_DEFAULT is the default pool
798d7e7a98SRuslan Bukin  * from which physical pages are allocated and VM_FREEPOOL_DIRECT is
808d7e7a98SRuslan Bukin  * the pool from which physical pages for small UMA objects are
818d7e7a98SRuslan Bukin  * allocated.
828d7e7a98SRuslan Bukin  */
838d7e7a98SRuslan Bukin #define	VM_NFREEPOOL		2
848d7e7a98SRuslan Bukin #define	VM_FREEPOOL_DEFAULT	0
858d7e7a98SRuslan Bukin #define	VM_FREEPOOL_DIRECT	1
868d7e7a98SRuslan Bukin 
878d7e7a98SRuslan Bukin /*
888d7e7a98SRuslan Bukin  * Create two free page lists: VM_FREELIST_DEFAULT is for physical
898d7e7a98SRuslan Bukin  * pages that are above the largest physical address that is
908d7e7a98SRuslan Bukin  * accessible by ISA DMA and VM_FREELIST_ISADMA is for physical pages
918d7e7a98SRuslan Bukin  * that are below that address.
928d7e7a98SRuslan Bukin  */
938d7e7a98SRuslan Bukin #define	VM_NFREELIST		2
948d7e7a98SRuslan Bukin #define	VM_FREELIST_DEFAULT	0
958d7e7a98SRuslan Bukin #define	VM_FREELIST_ISADMA	1
968d7e7a98SRuslan Bukin 
978d7e7a98SRuslan Bukin /*
988d7e7a98SRuslan Bukin  * An allocation size of 16MB is supported in order to optimize the
998d7e7a98SRuslan Bukin  * use of the direct map by UMA.  Specifically, a cache line contains
1008d7e7a98SRuslan Bukin  * at most four TTEs, collectively mapping 16MB of physical memory.
1018d7e7a98SRuslan Bukin  * By reducing the number of distinct 16MB "pages" that are used by UMA,
1028d7e7a98SRuslan Bukin  * the physical memory allocator reduces the likelihood of both 4MB
1038d7e7a98SRuslan Bukin  * page TLB misses and cache misses caused by 4MB page TLB misses.
1048d7e7a98SRuslan Bukin  */
1058d7e7a98SRuslan Bukin #define	VM_NFREEORDER		12
1068d7e7a98SRuslan Bukin 
1078d7e7a98SRuslan Bukin /*
1088d7e7a98SRuslan Bukin  * Enable superpage reservations: 1 level.
1098d7e7a98SRuslan Bukin  */
1108d7e7a98SRuslan Bukin #ifndef	VM_NRESERVLEVEL
1118d7e7a98SRuslan Bukin #define	VM_NRESERVLEVEL		1
1128d7e7a98SRuslan Bukin #endif
1138d7e7a98SRuslan Bukin 
1148d7e7a98SRuslan Bukin /*
1158d7e7a98SRuslan Bukin  * Level 0 reservations consist of 512 pages.
1168d7e7a98SRuslan Bukin  */
1178d7e7a98SRuslan Bukin #ifndef	VM_LEVEL_0_ORDER
1188d7e7a98SRuslan Bukin #define	VM_LEVEL_0_ORDER	9
1198d7e7a98SRuslan Bukin #endif
1208d7e7a98SRuslan Bukin 
1218d7e7a98SRuslan Bukin /**
1228d7e7a98SRuslan Bukin  * Address space layout.
1238d7e7a98SRuslan Bukin  *
1248d7e7a98SRuslan Bukin  * RISC-V implements up to a 48 bit virtual address space. The address space is
1258d7e7a98SRuslan Bukin  * split into 2 regions at each end of the 64 bit address space, with an
1268d7e7a98SRuslan Bukin  * out of range "hole" in the middle.
1278d7e7a98SRuslan Bukin  *
1288d7e7a98SRuslan Bukin  * We limit the size of the two spaces to 39 bits each.
1298d7e7a98SRuslan Bukin  *
1308d7e7a98SRuslan Bukin  * Upper region:	0xffffffffffffffff
131229f3f0dSRuslan Bukin  *			0xffffff8000000000
1328d7e7a98SRuslan Bukin  *
133229f3f0dSRuslan Bukin  * Hole:		0xffffff7fffffffff
134229f3f0dSRuslan Bukin  *			0x0000008000000000
1358d7e7a98SRuslan Bukin  *
136229f3f0dSRuslan Bukin  * Lower region:	0x0000007fffffffff
1378d7e7a98SRuslan Bukin  *			0x0000000000000000
1388d7e7a98SRuslan Bukin  *
1398d7e7a98SRuslan Bukin  * We use the upper region for the kernel, and the lower region for userland.
1408d7e7a98SRuslan Bukin  *
1418d7e7a98SRuslan Bukin  * We define some interesting address constants:
1428d7e7a98SRuslan Bukin  *
1438d7e7a98SRuslan Bukin  * VM_MIN_ADDRESS and VM_MAX_ADDRESS define the start and end of the entire
1448d7e7a98SRuslan Bukin  * 64 bit address space, mostly just for convenience.
1458d7e7a98SRuslan Bukin  *
1468d7e7a98SRuslan Bukin  * VM_MIN_KERNEL_ADDRESS and VM_MAX_KERNEL_ADDRESS define the start and end of
1478d7e7a98SRuslan Bukin  * mappable kernel virtual address space.
1488d7e7a98SRuslan Bukin  *
1498d7e7a98SRuslan Bukin  * VM_MIN_USER_ADDRESS and VM_MAX_USER_ADDRESS define the start and end of the
1508d7e7a98SRuslan Bukin  * user address space.
1518d7e7a98SRuslan Bukin  */
1528d7e7a98SRuslan Bukin #define	VM_MIN_ADDRESS		(0x0000000000000000UL)
1538d7e7a98SRuslan Bukin #define	VM_MAX_ADDRESS		(0xffffffffffffffffUL)
1548d7e7a98SRuslan Bukin 
155229f3f0dSRuslan Bukin /* 32 GiB of kernel addresses */
156*02a37128SRuslan Bukin #define	VM_MIN_KERNEL_ADDRESS	(0xffffffc000000000UL)
157*02a37128SRuslan Bukin #define	VM_MAX_KERNEL_ADDRESS	(0xffffffc800000000UL)
1588d7e7a98SRuslan Bukin 
159229f3f0dSRuslan Bukin /* Direct Map for 128 GiB of PA: 0x0 - 0x1fffffffff */
160*02a37128SRuslan Bukin #define	DMAP_MIN_ADDRESS	(0xffffffd000000000UL)
161*02a37128SRuslan Bukin #define	DMAP_MAX_ADDRESS	(0xffffffefffffffffUL)
1628d7e7a98SRuslan Bukin 
1638d7e7a98SRuslan Bukin #define	DMAP_MIN_PHYSADDR	(0x0000000000000000UL)
1648d7e7a98SRuslan Bukin #define	DMAP_MAX_PHYSADDR	(DMAP_MAX_ADDRESS - DMAP_MIN_ADDRESS)
1658d7e7a98SRuslan Bukin 
1668d7e7a98SRuslan Bukin /* True if pa is in the dmap range */
167229f3f0dSRuslan Bukin #define	PHYS_IN_DMAP(pa)	((pa) >= DMAP_MIN_PHYSADDR && \
168229f3f0dSRuslan Bukin     (pa) <= DMAP_MAX_PHYSADDR)
1698d7e7a98SRuslan Bukin /* True if va is in the dmap range */
1708d7e7a98SRuslan Bukin #define	VIRT_IN_DMAP(va)	((va) >= DMAP_MIN_ADDRESS && \
1718d7e7a98SRuslan Bukin     (va) <= DMAP_MAX_ADDRESS)
1728d7e7a98SRuslan Bukin 
1738d7e7a98SRuslan Bukin #define	PHYS_TO_DMAP(pa)						\
1748d7e7a98SRuslan Bukin ({									\
1758d7e7a98SRuslan Bukin 	KASSERT(PHYS_IN_DMAP(pa),					\
1768d7e7a98SRuslan Bukin 	    ("%s: PA out of range, PA: 0x%lx", __func__,		\
1778d7e7a98SRuslan Bukin 	    (vm_paddr_t)(pa)));						\
1788d7e7a98SRuslan Bukin 	(pa) | DMAP_MIN_ADDRESS;					\
1798d7e7a98SRuslan Bukin })
1808d7e7a98SRuslan Bukin 
1818d7e7a98SRuslan Bukin #define	DMAP_TO_PHYS(va)						\
1828d7e7a98SRuslan Bukin ({									\
1838d7e7a98SRuslan Bukin 	KASSERT(VIRT_IN_DMAP(va),					\
1848d7e7a98SRuslan Bukin 	    ("%s: VA out of range, VA: 0x%lx", __func__,		\
1858d7e7a98SRuslan Bukin 	    (vm_offset_t)(va)));					\
1868d7e7a98SRuslan Bukin 	(va) & ~DMAP_MIN_ADDRESS;					\
1878d7e7a98SRuslan Bukin })
1888d7e7a98SRuslan Bukin 
1898d7e7a98SRuslan Bukin #define	VM_MIN_USER_ADDRESS	(0x0000000000000000UL)
190*02a37128SRuslan Bukin #define	VM_MAX_USER_ADDRESS	(0x0000004000000000UL)
1918d7e7a98SRuslan Bukin 
1928d7e7a98SRuslan Bukin #define	VM_MINUSER_ADDRESS	(VM_MIN_USER_ADDRESS)
1938d7e7a98SRuslan Bukin #define	VM_MAXUSER_ADDRESS	(VM_MAX_USER_ADDRESS)
1948d7e7a98SRuslan Bukin 
1958d7e7a98SRuslan Bukin #define	KERNBASE		(VM_MIN_KERNEL_ADDRESS)
196229f3f0dSRuslan Bukin #define	SHAREDPAGE		(VM_MAXUSER_ADDRESS - PAGE_SIZE)
197229f3f0dSRuslan Bukin #define	USRSTACK		SHAREDPAGE
198229f3f0dSRuslan Bukin 
1998d7e7a98SRuslan Bukin #define	KERNENTRY		(0x200)
2008d7e7a98SRuslan Bukin 
2018d7e7a98SRuslan Bukin /*
2028d7e7a98SRuslan Bukin  * How many physical pages per kmem arena virtual page.
2038d7e7a98SRuslan Bukin  */
2048d7e7a98SRuslan Bukin #ifndef VM_KMEM_SIZE_SCALE
2058d7e7a98SRuslan Bukin #define	VM_KMEM_SIZE_SCALE	(3)
2068d7e7a98SRuslan Bukin #endif
2078d7e7a98SRuslan Bukin 
2088d7e7a98SRuslan Bukin /*
2098d7e7a98SRuslan Bukin  * Optional floor (in bytes) on the size of the kmem arena.
2108d7e7a98SRuslan Bukin  */
2118d7e7a98SRuslan Bukin #ifndef VM_KMEM_SIZE_MIN
2128d7e7a98SRuslan Bukin #define	VM_KMEM_SIZE_MIN	(16 * 1024 * 1024)
2138d7e7a98SRuslan Bukin #endif
2148d7e7a98SRuslan Bukin 
2158d7e7a98SRuslan Bukin /*
2168d7e7a98SRuslan Bukin  * Optional ceiling (in bytes) on the size of the kmem arena: 60% of the
2178d7e7a98SRuslan Bukin  * kernel map.
2188d7e7a98SRuslan Bukin  */
2198d7e7a98SRuslan Bukin #ifndef VM_KMEM_SIZE_MAX
2208d7e7a98SRuslan Bukin #define	VM_KMEM_SIZE_MAX	((VM_MAX_KERNEL_ADDRESS - \
2218d7e7a98SRuslan Bukin     VM_MIN_KERNEL_ADDRESS + 1) * 3 / 5)
2228d7e7a98SRuslan Bukin #endif
2238d7e7a98SRuslan Bukin 
2248d7e7a98SRuslan Bukin /*
2258d7e7a98SRuslan Bukin  * Initial pagein size of beginning of executable file.
2268d7e7a98SRuslan Bukin  */
2278d7e7a98SRuslan Bukin #ifndef	VM_INITIAL_PAGEIN
2288d7e7a98SRuslan Bukin #define	VM_INITIAL_PAGEIN	16
2298d7e7a98SRuslan Bukin #endif
2308d7e7a98SRuslan Bukin 
2318d7e7a98SRuslan Bukin /*
2328d7e7a98SRuslan Bukin  * RISCVTODO
2338d7e7a98SRuslan Bukin  * #define	UMA_MD_SMALL_ALLOC
2348d7e7a98SRuslan Bukin  */
2358d7e7a98SRuslan Bukin 
2368d7e7a98SRuslan Bukin extern u_int tsb_kernel_ldd_phys;
2378d7e7a98SRuslan Bukin extern vm_offset_t vm_max_kernel_address;
2388d7e7a98SRuslan Bukin extern vm_offset_t init_pt_va;
2398d7e7a98SRuslan Bukin 
2408d7e7a98SRuslan Bukin #define	ZERO_REGION_SIZE	(64 * 1024)	/* 64KB */
2418d7e7a98SRuslan Bukin 
2428d7e7a98SRuslan Bukin #endif /* !_MACHINE_VMPARAM_H_ */
243