xref: /openbsd-src/sys/arch/riscv64/include/vmparam.h (revision 975217253947622c32c832a3f219d28791e91461)
1*97521725Sjsg /*	$OpenBSD: vmparam.h,v 1.9 2023/11/28 09:10:18 jsg Exp $	*/
2380aa7b9Sjsg 
3baed8f06Sdrahn /*-
4baed8f06Sdrahn  * Copyright (c) 1990 The Regents of the University of California.
5baed8f06Sdrahn  * All rights reserved.
6baed8f06Sdrahn  *
7baed8f06Sdrahn  * This code is derived from software contributed to Berkeley by
8baed8f06Sdrahn  * William Jolitz.
9baed8f06Sdrahn  *
10baed8f06Sdrahn  * Redistribution and use in source and binary forms, with or without
11baed8f06Sdrahn  * modification, are permitted provided that the following conditions
12baed8f06Sdrahn  * are met:
13baed8f06Sdrahn  * 1. Redistributions of source code must retain the above copyright
14baed8f06Sdrahn  *    notice, this list of conditions and the following disclaimer.
15baed8f06Sdrahn  * 2. Redistributions in binary form must reproduce the above copyright
16baed8f06Sdrahn  *    notice, this list of conditions and the following disclaimer in the
17baed8f06Sdrahn  *    documentation and/or other materials provided with the distribution.
18baed8f06Sdrahn  * 3. Neither the name of the University nor the names of its contributors
19baed8f06Sdrahn  *    may be used to endorse or promote products derived from this software
20baed8f06Sdrahn  *    without specific prior written permission.
21baed8f06Sdrahn  *
22baed8f06Sdrahn  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23baed8f06Sdrahn  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24baed8f06Sdrahn  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25baed8f06Sdrahn  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26baed8f06Sdrahn  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27baed8f06Sdrahn  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28baed8f06Sdrahn  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29baed8f06Sdrahn  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30baed8f06Sdrahn  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31baed8f06Sdrahn  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32baed8f06Sdrahn  * SUCH DAMAGE.
33baed8f06Sdrahn  *
34baed8f06Sdrahn  *	@(#)vmparam.h	5.9 (Berkeley) 5/12/91
35baed8f06Sdrahn  */
36baed8f06Sdrahn 
37baed8f06Sdrahn #ifndef _MACHINE_VMPARAM_H_
38baed8f06Sdrahn #define _MACHINE_VMPARAM_H_
39baed8f06Sdrahn 
40baed8f06Sdrahn /*
41baed8f06Sdrahn  * Machine dependent constants for riscv64.
42baed8f06Sdrahn  */
43baed8f06Sdrahn 
44baed8f06Sdrahn #define	USRSTACK	VM_MAXUSER_ADDRESS
45baed8f06Sdrahn 
46baed8f06Sdrahn /*
47baed8f06Sdrahn  * Virtual memory related constants, all in bytes
48baed8f06Sdrahn  */
49baed8f06Sdrahn #ifndef MAXTSIZ
50baed8f06Sdrahn #define	MAXTSIZ		((paddr_t)1*1024*1024*1024)	/* max text size */
51baed8f06Sdrahn #endif
52baed8f06Sdrahn #ifndef DFLDSIZ
53baed8f06Sdrahn #define	DFLDSIZ		((paddr_t)128*1024*1024)	/* initial data size limit */
54baed8f06Sdrahn #endif
55baed8f06Sdrahn #ifndef MAXDSIZ
56b5b244d4Smatthieu #define	MAXDSIZ		((paddr_t)16*1024*1024*1024)	/* max data size */
57baed8f06Sdrahn #endif
58baed8f06Sdrahn #ifndef BRKSIZ
59baed8f06Sdrahn #define	BRKSIZ		((paddr_t)1*1024*1024*1024)	/* heap gap size */
60baed8f06Sdrahn #endif
61baed8f06Sdrahn #ifndef	DFLSSIZ
62baed8f06Sdrahn #define	DFLSSIZ		((paddr_t)128*1024*1024)	/* initial stack size limit */
63baed8f06Sdrahn #endif
64baed8f06Sdrahn #ifndef	MAXSSIZ
65baed8f06Sdrahn #define	MAXSSIZ		((paddr_t)1*1024*1024*1024)	/* max stack size */
66baed8f06Sdrahn #endif
67baed8f06Sdrahn 
68baed8f06Sdrahn #define	STACKGAP_RANDOM	256*1024
69baed8f06Sdrahn 
70baed8f06Sdrahn /*
71baed8f06Sdrahn  * Size of shared memory map
72baed8f06Sdrahn  */
73baed8f06Sdrahn #ifndef	SHMMAXPGS
74baed8f06Sdrahn #define	SHMMAXPGS	1024
75baed8f06Sdrahn #endif
76baed8f06Sdrahn 
77baed8f06Sdrahn /*
78baed8f06Sdrahn  * Size of User Raw I/O map
79baed8f06Sdrahn  */
80baed8f06Sdrahn #define	USRIOSIZE	300
81baed8f06Sdrahn 
82baed8f06Sdrahn /**
83baed8f06Sdrahn  * Address space layout.
84baed8f06Sdrahn  *
85baed8f06Sdrahn  * RISC-V implements multiple paging modes with different virtual address space
86baed8f06Sdrahn  * sizes: SV32, SV39 and SV48.  SV39 permits a virtual address space size of
87baed8f06Sdrahn  * 512GB and uses a three-level page table.  Since this is large enough for most
88baed8f06Sdrahn  * purposes, we currently use SV39 for both userland and the kernel, avoiding
89baed8f06Sdrahn  * the extra translation step required by SV48.
90baed8f06Sdrahn  *
91baed8f06Sdrahn  * The address space is split into two regions at each end of the 64-bit address
92baed8f06Sdrahn  * space:
93baed8f06Sdrahn  *
94baed8f06Sdrahn  * 0x0000000000000000 - 0x0000003fffffffff    256GB user map
95baed8f06Sdrahn  * 0x0000004000000000 - 0xffffffbfffffffff    unmappable
96baed8f06Sdrahn  * 0xffffffc000000000 - 0xffffffc7ffffffff    32GB kernel map
97baed8f06Sdrahn  * 0xffffffc800000000 - 0xffffffcfffffffff    32GB unused
98baed8f06Sdrahn  * 0xffffffd000000000 - 0xffffffefffffffff    128GB direct map
99baed8f06Sdrahn  * 0xfffffff000000000 - 0xffffffffffffffff    64GB unused
100baed8f06Sdrahn  *
101baed8f06Sdrahn  * The kernel is loaded at the beginning of the kernel map.
102baed8f06Sdrahn  *
103baed8f06Sdrahn  * We define some interesting address constants:
104baed8f06Sdrahn  *
105baed8f06Sdrahn  * VM_MIN_ADDRESS and VM_MAX_ADDRESS define the start and end of the entire
106baed8f06Sdrahn  * 64 bit address space, mostly just for convenience.
107baed8f06Sdrahn  *
108baed8f06Sdrahn  * VM_MIN_KERNEL_ADDRESS and VM_MAX_KERNEL_ADDRESS define the start and end of
109baed8f06Sdrahn  * mappable kernel virtual address space.
110baed8f06Sdrahn  *
111*97521725Sjsg  * VM_MIN_ADDRESS and VM_MAXUSER_ADDRESS define the start and end of the
112baed8f06Sdrahn  * user address space.
113baed8f06Sdrahn  */
114e9455850Smiod #define	VM_MIN_ADDRESS		((vaddr_t)PAGE_SIZE)
115baed8f06Sdrahn #define	VM_MAX_ADDRESS		(0xffffffffffffffffUL)
116baed8f06Sdrahn 
117baed8f06Sdrahn #define	VM_MIN_KERNEL_ADDRESS	(0xffffffc000000000UL)
118baed8f06Sdrahn #define	VM_MAX_KERNEL_ADDRESS	(0xffffffc800000000UL)
119baed8f06Sdrahn 
120*97521725Sjsg /* Kernel L1 Page Table Range */
121baed8f06Sdrahn #define	L1_KERN_BASE		(256)
122baed8f06Sdrahn #define	L1_KERN_ENTRIES		(288 - L1_KERN_BASE)
123baed8f06Sdrahn 
124baed8f06Sdrahn #define	DMAP_MIN_ADDRESS	(0xffffffd000000000UL)
125baed8f06Sdrahn #define	DMAP_MAX_ADDRESS	(0xfffffff000000000UL)
126baed8f06Sdrahn 
127*97521725Sjsg /* DMAP L1 Page Table Range */
128baed8f06Sdrahn #define	L1_DMAP_BASE		(320)
129baed8f06Sdrahn #define	L1_DMAP_ENTRIES		(448 - L1_DMAP_BASE)
130baed8f06Sdrahn 
131*97521725Sjsg #define	VM_MAXUSER_ADDRESS	(0x0000004000000000UL)  /* 39 bits */
132baed8f06Sdrahn 
133e8dad7d8Skettenis #ifdef _KERNEL
134e8dad7d8Skettenis #define	VM_MIN_STACK_ADDRESS	(VM_MAXUSER_ADDRESS * 3 / 4)
135e8dad7d8Skettenis #endif
136baed8f06Sdrahn 
137baed8f06Sdrahn #define	KERNBASE		(VM_MIN_KERNEL_ADDRESS)
138baed8f06Sdrahn 
139baed8f06Sdrahn #ifndef _LOCORE
140baed8f06Sdrahn extern paddr_t dmap_phys_base;
141baed8f06Sdrahn #endif
142baed8f06Sdrahn 
143baed8f06Sdrahn /* virtual sizes (bytes) for various kernel submaps */
144baed8f06Sdrahn #define	VM_PHYS_SIZE		(USRIOSIZE*PAGE_SIZE)
145baed8f06Sdrahn 
146baed8f06Sdrahn #define	VM_PHYSSEG_MAX		32
147baed8f06Sdrahn #define	VM_PHYSSEG_STRAT	VM_PSTRAT_BSEARCH
148baed8f06Sdrahn #define	VM_PHYSSEG_NOADD	/* can't add RAM after vm_mem_init */
149baed8f06Sdrahn 
150baed8f06Sdrahn #endif /* _MACHINE_VMPARAM_H_ */
151