vmparam.h revision 1.17 1 1.17 skrll /* $NetBSD: vmparam.h,v 1.17 2020/11/10 07:51:19 skrll Exp $ */
2 1.1 matt
3 1.1 matt /*-
4 1.1 matt * Copyright (c) 2014 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.1 matt * by Matt Thomas of 3am Software Foundry.
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 _AARCH64_VMPARAM_H_
33 1.1 matt #define _AARCH64_VMPARAM_H_
34 1.1 matt
35 1.1 matt #ifdef __aarch64__
36 1.1 matt
37 1.3 ryo #define __USE_TOPDOWN_VM
38 1.3 ryo
39 1.1 matt /*
40 1.4 jmcneill * Default pager_map of 16MB is small and we have plenty of VA to burn.
41 1.4 jmcneill */
42 1.4 jmcneill #define PAGER_MAP_DEFAULT_SIZE (512 * 1024 * 1024)
43 1.4 jmcneill
44 1.4 jmcneill /*
45 1.10 ad * Defaults for Unified Buffer Cache parameters.
46 1.10 ad */
47 1.10 ad
48 1.10 ad #ifndef UBC_WINSHIFT
49 1.10 ad #define UBC_WINSHIFT 16 /* 64kB */
50 1.10 ad #endif
51 1.10 ad #ifndef UBC_NWINS
52 1.10 ad #define UBC_NWINS 4096 /* 256MB */
53 1.10 ad #endif
54 1.10 ad
55 1.10 ad /*
56 1.1 matt * AARCH64 supports 3 page sizes: 4KB, 16KB, 64KB. Each page table can
57 1.1 matt * even have its own page size.
58 1.1 matt */
59 1.1 matt
60 1.1 matt #ifdef AARCH64_PAGE_SHIFT
61 1.1 matt #if (1 << AARCH64_PAGE_SHIFT) & ~0x141000
62 1.1 matt #error AARCH64_PAGE_SHIFT contains an unsupported value.
63 1.1 matt #endif
64 1.1 matt #define PAGE_SHIFT AARCH64_PAGE_SHIFT
65 1.1 matt #else
66 1.1 matt #define PAGE_SHIFT 12
67 1.1 matt #endif
68 1.1 matt #define PAGE_SIZE (1 << PAGE_SHIFT)
69 1.1 matt #define PAGE_MASK (PAGE_SIZE - 1)
70 1.1 matt
71 1.1 matt #if PAGE_SHIFT <= 14
72 1.3 ryo #define USPACE 32768
73 1.1 matt #else
74 1.1 matt #define USPACE 65536
75 1.1 matt #endif
76 1.1 matt #define UPAGES (USPACE >> PAGE_SHIFT)
77 1.1 matt
78 1.1 matt /*
79 1.1 matt * USRSTACK is the top (end) of the user stack. The user VA space is a
80 1.1 matt * 48-bit address space starting at 0. Place the stack at its top end.
81 1.1 matt */
82 1.3 ryo #define USRSTACK VM_MAXUSER_ADDRESS
83 1.1 matt
84 1.1 matt #ifndef MAXTSIZ
85 1.1 matt #define MAXTSIZ (1L << 30) /* max text size (1GB) */
86 1.1 matt #endif
87 1.1 matt
88 1.1 matt #ifndef MAXDSIZ
89 1.1 matt #define MAXDSIZ (1L << 36) /* max data size (64GB) */
90 1.1 matt #endif
91 1.1 matt
92 1.1 matt #ifndef MAXSSIZ
93 1.1 matt #define MAXSSIZ (1L << 26) /* max stack size (64MB) */
94 1.1 matt #endif
95 1.1 matt
96 1.1 matt #ifndef DFLDSIZ
97 1.1 matt #define DFLDSIZ (1L << 32) /* default data size (4GB) */
98 1.1 matt #endif
99 1.1 matt
100 1.3 ryo #ifndef DFLSSIZ
101 1.3 ryo #define DFLSSIZ (1L << 23) /* default stack size (8MB) */
102 1.3 ryo #endif
103 1.3 ryo
104 1.3 ryo #define USRSTACK32 VM_MAXUSER_ADDRESS32
105 1.3 ryo
106 1.3 ryo #ifndef MAXDSIZ32
107 1.7 ryo #define MAXDSIZ32 (3U*1024*1024*1024) /* max data size */
108 1.3 ryo #endif
109 1.3 ryo
110 1.3 ryo #ifndef MAXSSIZ32
111 1.3 ryo #define MAXSSIZ32 (64*1024*1024) /* max stack size */
112 1.3 ryo #endif
113 1.3 ryo
114 1.1 matt #ifndef DFLDSIZ32
115 1.1 matt #define DFLDSIZ32 (1L << 27) /* 32bit default data size (128MB) */
116 1.1 matt #endif
117 1.1 matt
118 1.1 matt #ifndef DFLSSIZ32
119 1.1 matt #define DFLSSIZ32 (1L << 21) /* 32bit default stack size (2MB) */
120 1.1 matt #endif
121 1.1 matt
122 1.1 matt #define VM_MIN_ADDRESS ((vaddr_t) 0x0)
123 1.1 matt #define VM_MAXUSER_ADDRESS ((vaddr_t) (1L << 48) - PAGE_SIZE)
124 1.1 matt #define VM_MAX_ADDRESS VM_MAXUSER_ADDRESS
125 1.1 matt
126 1.7 ryo #define VM_MAXUSER_ADDRESS32 ((vaddr_t) 0xfffff000)
127 1.1 matt
128 1.1 matt /*
129 1.11 ryo * kernel virtual space layout:
130 1.17 skrll * 0xffff_0000_0000_0000 - 64T direct mapping
131 1.15 skrll * 0xffff_4000_0000_0000 - 32T (KASAN SHADOW MAP)
132 1.15 skrll * 0xffff_6000_0000_0000 - 32T (not used)
133 1.15 skrll * 0xffff_8000_0000_0000 - 1G EFI_RUNTIME
134 1.15 skrll * 0xffff_8000_4000_0000 - 64T (not used)
135 1.15 skrll * 0xffff_c000_0000_0000 - 64T KERNEL VM Space (including text/data/bss)
136 1.15 skrll * 0xffff_ffff_f000_0000 - 254M KERNEL_IO for pmap_devmap
137 1.15 skrll * 0xffff_ffff_ffe0_0000 - 2M RESERVED
138 1.1 matt */
139 1.11 ryo #define VM_MIN_KERNEL_ADDRESS ((vaddr_t) 0xffffc00000000000L)
140 1.3 ryo #define VM_MAX_KERNEL_ADDRESS ((vaddr_t) 0xffffffffffe00000L)
141 1.3 ryo
142 1.3 ryo /*
143 1.3 ryo * last 254MB of kernel vm area (0xfffffffff0000000-0xffffffffffe00000)
144 1.12 skrll * may be used for devmap. see aarch64/pmap.c:pmap_devmap_*
145 1.3 ryo */
146 1.3 ryo #define VM_KERNEL_IO_ADDRESS 0xfffffffff0000000L
147 1.6 ryo #define VM_KERNEL_IO_SIZE (VM_MAX_KERNEL_ADDRESS - VM_KERNEL_IO_ADDRESS)
148 1.1 matt
149 1.14 skrll #define VM_KERNEL_VM_BASE VM_MIN_KERNEL_ADDRESS
150 1.14 skrll #define VM_KERNEL_VM_SIZE (VM_MAX_KERNEL_ADDRESS - VM_KERNEL_VM_BASE)
151 1.14 skrll
152 1.8 jmcneill /*
153 1.8 jmcneill * Reserved space for EFI runtime services
154 1.8 jmcneill */
155 1.8 jmcneill #define EFI_RUNTIME_VA 0xffff800000000000L
156 1.8 jmcneill #define EFI_RUNTIME_SIZE 0x0000000040000000L
157 1.8 jmcneill
158 1.1 matt /* virtual sizes (bytes) for various kernel submaps */
159 1.1 matt #define USRIOSIZE (PAGE_SIZE / 8)
160 1.1 matt #define VM_PHYS_SIZE (USRIOSIZE * PAGE_SIZE)
161 1.1 matt
162 1.7 ryo #define VM_DEFAULT_ADDRESS32_TOPDOWN(da, sz) \
163 1.7 ryo trunc_page(USRSTACK32 - MAXSSIZ32 - (sz) - user_stack_guard_size)
164 1.7 ryo #define VM_DEFAULT_ADDRESS32_BOTTOMUP(da, sz) \
165 1.7 ryo round_page((vaddr_t)(da) + (vsize_t)MAXDSIZ32)
166 1.7 ryo
167 1.1 matt /*
168 1.1 matt * Since we have the address space, we map all of physical memory (RAM)
169 1.1 matt * using block page table entries.
170 1.1 matt */
171 1.17 skrll #define AARCH64_DIRECTMAP_MASK ((vaddr_t) 0xffff000000000000L)
172 1.17 skrll #define AARCH64_DIRECTMAP_SIZE (1UL << 46) /* 64TB */
173 1.17 skrll #define AARCH64_DIRECTMAP_START AARCH64_DIRECTMAP_MASK
174 1.17 skrll #define AARCH64_DIRECTMAP_END (AARCH64_DIRECTMAP_START + AARCH64_DIRECTMAP_SIZE)
175 1.17 skrll #define AARCH64_KVA_P(va) (((vaddr_t) (va) & AARCH64_DIRECTMAP_MASK) != 0)
176 1.17 skrll #define AARCH64_PA_TO_KVA(pa) ((vaddr_t) ((pa) | AARCH64_DIRECTMAP_START))
177 1.17 skrll #define AARCH64_KVA_TO_PA(va) ((paddr_t) ((va) & ~AARCH64_DIRECTMAP_MASK))
178 1.1 matt
179 1.1 matt /* */
180 1.5 jmcneill #define VM_PHYSSEG_MAX 64 /* XXX */
181 1.1 matt #define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH
182 1.1 matt
183 1.9 jmcneill #define VM_NFREELIST 1
184 1.3 ryo #define VM_FREELIST_DEFAULT 0
185 1.1 matt
186 1.1 matt #elif defined(__arm__)
187 1.1 matt
188 1.1 matt #include <arm/vmparam.h>
189 1.1 matt
190 1.1 matt #endif /* __aarch64__/__arm__ */
191 1.1 matt
192 1.1 matt #endif /* _AARCH64_VMPARAM_H_ */
193