Home | History | Annotate | Line # | Download | only in include
vmparam.h revision 1.10
      1 /*	$NetBSD: vmparam.h,v 1.10 2022/09/20 07:18:23 skrll Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2014, 2020 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, and Nick Hudson.
      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 _RISCV_VMPARAM_H_
     33 #define	_RISCV_VMPARAM_H_
     34 
     35 #include <riscv/param.h>
     36 
     37 #ifdef _KERNEL_OPT
     38 #include "opt_multiprocessor.h"
     39 #endif
     40 
     41 /*
     42  * Machine dependent VM constants for RISCV.
     43  */
     44 
     45 /*
     46  * We use a 4K page on both RV64 and RV32 systems.
     47  * Override PAGE_* definitions to compile-time constants.
     48  */
     49 #define	PAGE_SHIFT	PGSHIFT
     50 #define	PAGE_SIZE	(1 << PAGE_SHIFT)
     51 #define	PAGE_MASK	(PAGE_SIZE - 1)
     52 
     53 /*
     54  * USRSTACK is the top (end) of the user stack.
     55  *
     56  * USRSTACK needs to start a page below the maxuser address so that a memory
     57  * access with a maximum displacement (0x7ff) won't cross into the kernel's
     58  * address space.  We use PAGE_SIZE instead of 0x800 since these need to be
     59  * page-aligned.
     60  */
     61 #define	USRSTACK	(VM_MAXUSER_ADDRESS-PAGE_SIZE) /* Start of user stack */
     62 #define	USRSTACK32	((uint32_t)VM_MAXUSER_ADDRESS32-PAGE_SIZE)
     63 
     64 /*
     65  * Virtual memory related constants, all in bytes
     66  */
     67 #ifndef MAXTSIZ
     68 #define	MAXTSIZ		(128*1024*1024)		/* max text size */
     69 #endif
     70 #ifndef DFLDSIZ
     71 #define	DFLDSIZ		(256*1024*1024)		/* initial data size limit */
     72 #endif
     73 #ifndef MAXDSIZ
     74 #define	MAXDSIZ		(1536*1024*1024)	/* max data size */
     75 #endif
     76 #ifndef	DFLSSIZ
     77 #define	DFLSSIZ		(4*1024*1024)		/* initial stack size limit */
     78 #endif
     79 #ifndef	MAXSSIZ
     80 #define	MAXSSIZ		(120*1024*1024)		/* max stack size */
     81 #endif
     82 
     83 /*
     84  * Virtual memory related constants, all in bytes
     85  */
     86 #ifndef DFLDSIZ32
     87 #define	DFLDSIZ32	DFLDSIZ			/* initial data size limit */
     88 #endif
     89 #ifndef MAXDSIZ32
     90 #define	MAXDSIZ32	MAXDSIZ			/* max data size */
     91 #endif
     92 #ifndef	DFLSSIZ32
     93 #define	DFLSSIZ32	DFLTSIZ			/* initial stack size limit */
     94 #endif
     95 #ifndef	MAXSSIZ32
     96 #define	MAXSSIZ32	MAXSSIZ			/* max stack size */
     97 #endif
     98 
     99 /*
    100  * PTEs for mapping user space into the kernel for phyio operations.
    101  * The default PTE number is enough to cover 8 disks * MAXBSIZE.
    102  */
    103 #ifndef USRIOSIZE
    104 #define USRIOSIZE	(MAXBSIZE/PAGE_SIZE * 8)
    105 #endif
    106 
    107 /*
    108  * User/kernel map constants.
    109  */
    110 #define VM_MIN_ADDRESS		((vaddr_t)0x00000000)
    111 #ifdef _LP64	/* Sv39 */
    112 /*
    113  * kernel virtual space layout:
    114  *   0xffff_ffc0_0000_0000  -   64GiB  KERNEL VM Space (inc. text/data/bss)
    115  *  (0xffff_ffc0_4000_0000      +1GiB) KERNEL VM start of KVA
    116  *  (0xffff_ffd0_0000_0000      64GiB) reserved
    117  *   0xffff_ffe0_0000_0000  -  128GiB  direct mapping
    118  */
    119 #define VM_MAXUSER_ADDRESS	((vaddr_t)0x0000004000000000 - 16 * PAGE_SIZE)
    120 #define VM_MIN_KERNEL_ADDRESS	((vaddr_t)0xffffffc000000000)
    121 #define VM_MAX_KERNEL_ADDRESS	((vaddr_t)0xffffffd000000000)
    122 
    123 #else		/* Sv32 */
    124 #define VM_MAXUSER_ADDRESS	((vaddr_t)-0x7fffffff-1)/* 0xffffffff80000000 */
    125 #define VM_MIN_KERNEL_ADDRESS	((vaddr_t)-0x7fffffff-1)/* 0xffffffff80000000 */
    126 #define VM_MAX_KERNEL_ADDRESS	((vaddr_t)-0x40000000)	/* 0xffffffffc0000000 */
    127 
    128 #endif
    129 #define VM_KERNEL_BASE		VM_MIN_KERNEL_ADDRESS
    130 #define VM_KERNEL_SIZE		0x2000000	/* 32 MiB (8 / 16 megapages) */
    131 #define VM_KERNEL_DTB_BASE	(VM_KERNEL_BASE + VM_KERNEL_SIZE)
    132 #define VM_KERNEL_DTB_SIZE	0x2000000	/* 32 MiB (8 / 16 megapages) */
    133 
    134 #define VM_KERNEL_RESERVED	(VM_KERNEL_SIZE + VM_KERNEL_DTB_SIZE)
    135 
    136 #define VM_KERNEL_VM_BASE	(VM_MIN_KERNEL_ADDRESS + VM_KERNEL_RESERVED)
    137 #define VM_KERNEL_VM_SIZE	(VM_MAX_KERNEL_ADDRESS - VM_KERNEL_VM_BASE)
    138 
    139 #define VM_MAX_ADDRESS		VM_MAXUSER_ADDRESS
    140 #define VM_MAXUSER_ADDRESS32	((vaddr_t)(1UL << 31))/* 0x0000000080000000 */
    141 
    142 #ifdef _LP64
    143 /*
    144  * Since we have the address space, we map all of physical memory (RAM)
    145  * using block page table entries.
    146  */
    147 #define RISCV_DIRECTMAP_MASK	((vaddr_t) 0xffffffe000000000L)
    148 #define RISCV_DIRECTMAP_SIZE	(-RISCV_DIRECTMAP_MASK)	/* 128GiB */
    149 #define RISCV_DIRECTMAP_START	RISCV_DIRECTMAP_MASK
    150 #define RISCV_DIRECTMAP_END	(RISCV_DIRECTMAP_START + RISCV_DIRECTMAP_SIZE)
    151 #define RISCV_KVA_P(va)	(((vaddr_t) (va) & RISCV_DIRECTMAP_MASK) != 0)
    152 #define RISCV_PA_TO_KVA(pa)	((vaddr_t) ((pa) | RISCV_DIRECTMAP_START))
    153 #define RISCV_KVA_TO_PA(va)	((paddr_t) ((va) & ~RISCV_DIRECTMAP_MASK))
    154 #endif
    155 
    156 /*
    157  * The address to which unspecified mapping requests default
    158  */
    159 #define __USE_TOPDOWN_VM
    160 
    161 #define VM_DEFAULT_ADDRESS_TOPDOWN(da, sz) \
    162     trunc_page(USRSTACK - MAXSSIZ - (sz) - user_stack_guard_size)
    163 #define VM_DEFAULT_ADDRESS_BOTTOMUP(da, sz) \
    164     round_page((vaddr_t)(da) + (vsize_t)maxdmap)
    165 
    166 #define VM_DEFAULT_ADDRESS32_TOPDOWN(da, sz) \
    167     trunc_page(USRSTACK32 - MAXSSIZ32 - (sz) - user_stack_guard_size)
    168 #define VM_DEFAULT_ADDRESS32_BOTTOMUP(da, sz) \
    169     round_page((vaddr_t)(da) + (vsize_t)MAXDSIZ32)
    170 
    171 /* virtual sizes (bytes) for various kernel submaps */
    172 #define VM_PHYS_SIZE		(USRIOSIZE*PAGE_SIZE)
    173 
    174 /* VM_PHYSSEG_MAX defined by platform-dependent code. */
    175 #ifndef VM_PHYSSEG_MAX
    176 #define VM_PHYSSEG_MAX		1
    177 #endif
    178 #if VM_PHYSSEG_MAX == 1
    179 #define	VM_PHYSSEG_STRAT	VM_PSTRAT_BIGFIRST
    180 #else
    181 #define	VM_PHYSSEG_STRAT	VM_PSTRAT_BSEARCH
    182 #endif
    183 #define	VM_PHYSSEG_NOADD	/* can add RAM after vm_mem_init */
    184 
    185 #ifndef VM_NFREELIST
    186 #define	VM_NFREELIST		2	/* 2 distinct memory segments */
    187 #define VM_FREELIST_DEFAULT	0
    188 #define VM_FREELIST_DIRECTMAP	1
    189 #endif
    190 
    191 #ifdef _KERNEL
    192 #define	UVM_KM_VMFREELIST	riscv_poolpage_vmfreelist
    193 extern int riscv_poolpage_vmfreelist;
    194 
    195 #ifdef _LP64
    196 void *	cpu_uarea_alloc(bool);
    197 bool	cpu_uarea_free(void *);
    198 #endif
    199 #endif
    200 
    201 #endif /* ! _RISCV_VMPARAM_H_ */
    202