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