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