xref: /netbsd-src/sys/arch/riscv/include/vmparam.h (revision 627f7eb200a4419d89b531d55fccd2ee3ffdcde0)
1 /*	$NetBSD: vmparam.h,v 1.8 2021/02/26 02:18:29 simonb Exp $	*/
2 
3 /*-
4  * Copyright (c) 2014 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Matt Thomas of 3am Software Foundry.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #ifndef _RISCV_VMPARAM_H_
33 #define	_RISCV_VMPARAM_H_
34 
35 #include <riscv/param.h>
36 
37 #ifdef _KERNEL_OPT
38 #include "opt_multiprocessor.h"
39 #endif
40 
41 /*
42  * Machine dependent VM constants for RISCV.
43  */
44 
45 #define	PAGE_SHIFT	PGSHIFT
46 #define	PAGE_SIZE	(1 << PAGE_SHIFT)
47 #define	PAGE_MASK	(PAGE_SIZE - 1)
48 
49 /*
50  * USRSTACK is the top (end) of the user stack.
51  *
52  * USRSTACK needs to start a page below the maxuser address so that a memory
53  * access with a maximum displacement (0x7ff) won't cross into the kernel's
54  * address space.  We use PAGE_SIZE instead of 0x800 since these need to be
55  * page-aligned.
56  */
57 #define	USRSTACK	(VM_MAXUSER_ADDRESS-PAGE_SIZE) /* Start of user stack */
58 #define	USRSTACK32	((uint32_t)VM_MAXUSER_ADDRESS32-PAGE_SIZE)
59 
60 /*
61  * Virtual memory related constants, all in bytes
62  */
63 #ifndef MAXTSIZ
64 #define	MAXTSIZ		(128*1024*1024)		/* max text size */
65 #endif
66 #ifndef DFLDSIZ
67 #define	DFLDSIZ		(256*1024*1024)		/* initial data size limit */
68 #endif
69 #ifndef MAXDSIZ
70 #define	MAXDSIZ		(1536*1024*1024)	/* max data size */
71 #endif
72 #ifndef	DFLSSIZ
73 #define	DFLSSIZ		(4*1024*1024)		/* initial stack size limit */
74 #endif
75 #ifndef	MAXSSIZ
76 #define	MAXSSIZ		(120*1024*1024)		/* max stack size */
77 #endif
78 
79 /*
80  * Virtual memory related constants, all in bytes
81  */
82 #ifndef DFLDSIZ32
83 #define	DFLDSIZ32	DFLDSIZ			/* initial data size limit */
84 #endif
85 #ifndef MAXDSIZ32
86 #define	MAXDSIZ32	MAXDSIZ			/* max data size */
87 #endif
88 #ifndef	DFLSSIZ32
89 #define	DFLSSIZ32	DFLTSIZ			/* initial stack size limit */
90 #endif
91 #ifndef	MAXSSIZ32
92 #define	MAXSSIZ32	MAXSSIZ			/* max stack size */
93 #endif
94 
95 /*
96  * PTEs for mapping user space into the kernel for phyio operations.
97  * The default PTE number is enough to cover 8 disks * MAXBSIZE.
98  */
99 #ifndef USRIOSIZE
100 #define USRIOSIZE	(MAXBSIZE/PAGE_SIZE * 8)
101 #endif
102 
103 /*
104  * User/kernel map constants.
105  */
106 #define VM_MIN_ADDRESS		((vaddr_t)0x00000000)
107 #ifdef _LP64	/* Sv39 */
108 #define VM_MAXUSER_ADDRESS	((vaddr_t)0x0000004000000000 - 16 * PAGE_SIZE)
109 #define VM_MIN_KERNEL_ADDRESS	((vaddr_t)0xffffffc000000000)
110 #define VM_MAX_KERNEL_ADDRESS	((vaddr_t)0xffffffd000000000) /* MIN + 64GB */
111 #else		/* Sv32 */
112 #define VM_MAXUSER_ADDRESS	((vaddr_t)-0x7fffffff-1)/* 0xffffffff80000000 */
113 #define VM_MIN_KERNEL_ADDRESS	((vaddr_t)-0x7fffffff-1)/* 0xffffffff80000000 */
114 #define VM_MAX_KERNEL_ADDRESS	((vaddr_t)-0x40000000)	/* 0xffffffffc0000000 */
115 #endif
116 #define VM_MAX_ADDRESS		VM_MAXUSER_ADDRESS
117 #define VM_MAXUSER_ADDRESS32	((vaddr_t)(1UL << 31))/* 0x0000000080000000 */
118 
119 /*
120  * The address to which unspecified mapping requests default
121  */
122 #define __USE_TOPDOWN_VM
123 
124 #define VM_DEFAULT_ADDRESS_TOPDOWN(da, sz) \
125     trunc_page(USRSTACK - MAXSSIZ - (sz) - user_stack_guard_size)
126 #define VM_DEFAULT_ADDRESS_BOTTOMUP(da, sz) \
127     round_page((vaddr_t)(da) + (vsize_t)maxdmap)
128 
129 #define VM_DEFAULT_ADDRESS32_TOPDOWN(da, sz) \
130     trunc_page(USRSTACK32 - MAXSSIZ32 - (sz) - user_stack_guard_size)
131 #define VM_DEFAULT_ADDRESS32_BOTTOMUP(da, sz) \
132     round_page((vaddr_t)(da) + (vsize_t)MAXDSIZ32)
133 
134 /* virtual sizes (bytes) for various kernel submaps */
135 #define VM_PHYS_SIZE		(USRIOSIZE*PAGE_SIZE)
136 
137 /* VM_PHYSSEG_MAX defined by platform-dependent code. */
138 #ifndef VM_PHYSSEG_MAX
139 #define VM_PHYSSEG_MAX		1
140 #endif
141 #if VM_PHYSSEG_MAX == 1
142 #define	VM_PHYSSEG_STRAT	VM_PSTRAT_LINEAR
143 #else
144 #define	VM_PHYSSEG_STRAT	VM_PSTRAT_BSEARCH
145 #endif
146 #define	VM_PHYSSEG_NOADD	/* can add RAM after vm_mem_init */
147 
148 #ifndef VM_NFREELIST
149 #define	VM_NFREELIST		2	/* 2 distinct memory segments */
150 #define VM_FREELIST_DEFAULT	0
151 #define VM_FREELIST_DIRECTMAP	1
152 #endif
153 
154 #ifdef _KERNEL
155 #define	UVM_KM_VMFREELIST	riscv_poolpage_vmfreelist
156 extern int riscv_poolpage_vmfreelist;
157 
158 #ifdef _LP64
159 void *	cpu_uarea_alloc(bool);
160 bool	cpu_uarea_free(void *);
161 #endif
162 #endif
163 
164 #endif /* ! _RISCV_VMPARAM_H_ */
165