xref: /netbsd-src/sys/arch/arm/include/arm32/vmparam.h (revision 8469df929f4af7108beb12d564f7f89318e711ff)
1 /*	$NetBSD: vmparam.h,v 1.58 2024/09/07 06:17:37 andvar Exp $	*/
2 
3 /*
4  * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
5  * All rights reserved.
6  *
7  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed for the NetBSD Project by
20  *	Wasabi Systems, Inc.
21  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22  *    or promote products derived from this software without specific prior
23  *    written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  */
37 
38 #ifndef _ARM_ARM32_VMPARAM_H_
39 #define	_ARM_ARM32_VMPARAM_H_
40 
41 #if defined(_KERNEL_OPT)
42 #include "opt_kasan.h"
43 #endif
44 
45 /*
46  * Virtual Memory parameters common to all arm32 platforms.
47  */
48 
49 #include <sys/cdefs.h>
50 #include <arm/cpuconf.h>
51 #include <arm/arm32/param.h>
52 
53 #define	__USE_TOPDOWN_VM
54 #define	USRSTACK	VM_MAXUSER_ADDRESS
55 
56 /*
57  * ARMv4 systems are normally configured for 256MB KVA only, so restrict
58  * the size of the pager map to 4MB.
59  */
60 #ifndef _ARM_ARCH_5
61 #define PAGER_MAP_DEFAULT_SIZE          (4 * 1024 * 1024)
62 #endif
63 
64 /*
65  * Note that MAXTSIZ can't be larger than 32M, otherwise the compiler
66  * would have to be changed to not generate "bl" instructions.
67  */
68 #define	MAXTSIZ		(128*1024*1024)		/* max text size */
69 #ifndef	DFLDSIZ
70 #define	DFLDSIZ		(384*1024*1024)		/* initial data size limit */
71 #endif
72 #ifndef	MAXDSIZ
73 #define	MAXDSIZ		(1856*1024*1024)	/* max data size */
74 #endif
75 #ifndef	DFLSSIZ
76 #define	DFLSSIZ		(4*1024*1024)		/* initial stack size limit */
77 #endif
78 #ifndef	MAXSSIZ
79 #define	MAXSSIZ		(64*1024*1024)		/* max stack size */
80 #endif
81 
82 /*
83  * While the ARM architecture defines Section mappings, large pages,
84  * and small pages, the standard MMU page size is (and will always be) 4K.
85  */
86 #define	PAGE_SHIFT	PGSHIFT
87 #define	PAGE_SIZE	(1 << PAGE_SHIFT)
88 #define	PAGE_MASK	(PAGE_SIZE - 1)
89 
90 /*
91  * Mach derived constants
92  */
93 #define	VM_MIN_ADDRESS		((vaddr_t) PAGE_SIZE)
94 
95 #define	VM_MAXUSER_ADDRESS	((vaddr_t) KERNEL_BASE - PAGE_SIZE)
96 #define	VM_MAX_ADDRESS		VM_MAXUSER_ADDRESS
97 
98 #define	VM_MIN_KERNEL_ADDRESS	((vaddr_t) KERNEL_BASE)
99 #define	VM_MAX_KERNEL_ADDRESS	((vaddr_t) -(PAGE_SIZE+1))
100 
101 #if defined(_KERNEL)
102 // AddressSanitizer dedicates 1/8 of kernel memory to its shadow memory (e.g.
103 // 128MB to cover 1GB for ARM) and uses a special KVA range for the shadow
104 // address corresponding to a kernel memory address.
105 
106 /*
107  * kernel virtual space layout without direct map (common case)
108  *
109  *   0x8000_0000 -  256MB kernel text/data/bss
110  *   0x9000_0000 - 1536MB Kernel VM Space
111  *   0xf000_0000 -  256MB IO
112  *
113  * kernel virtual space layout with KASAN
114  *
115  *   0x8000_0000 -  256MB kernel text/data/bss
116  *   0x9000_0000 -  768MB Kernel VM Space
117  *   0xc000_0000 -  128MB (KASAN SHADOW MAP)
118  *   0xc800_0000 -  640MB (spare)
119  *   0xf000_0000 -  256MB IO
120  *
121  * kernel virtual space layout with direct map (1GB limited)
122  *   0x8000_0000 - 1024MB kernel text/data/bss and direct map start
123  *   0xc000_0000 -  768MB Kernel VM Space
124  *   0xf000_0000 -  256MB IO
125  *
126  */
127 
128 #ifdef KASAN
129 #define VM_KERNEL_KASAN_BASE	0xc0000000
130 #define VM_KERNEL_KASAN_SIZE	(VM_KERNEL_ADDR_SIZE >> KASAN_SHADOW_SCALE_SHIFT)
131 #define VM_KERNEL_KASAN_END	(VM_KERNEL_KASAN_BASE + VM_KERNEL_KASAN_SIZE)
132 #define VM_KERNEL_VM_END	VM_KERNEL_KASAN_BASE
133 #else
134 #define VM_KERNEL_VM_END	VM_KERNEL_IO_BASE
135 #endif
136 
137 #ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
138 #ifdef KASAN
139 #error KASAN and __HAVE_MM_MD_DIRECT_MAPPED_PHYS is unsupported
140 #endif
141 #define VM_KERNEL_VM_BASE	0xc0000000
142 #else
143 #define VM_KERNEL_VM_BASE	0x90000000
144 #endif
145 
146 #define VM_KERNEL_ADDR_SIZE	(VM_KERNEL_VM_END - KERNEL_BASE)
147 #define VM_KERNEL_VM_SIZE	(VM_KERNEL_VM_END - VM_KERNEL_VM_BASE)
148 
149 #define VM_KERNEL_IO_BASE	0xf0000000
150 #define VM_KERNEL_IO_SIZE	(VM_MAX_KERNEL_ADDRESS - VM_KERNEL_IO_BASE)
151 #endif
152 
153 #endif /* _ARM_ARM32_VMPARAM_H_ */
154