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