Home | History | Annotate | Line # | Download | only in include
vmparam.h revision 1.8
      1  1.8  simonb /*	$NetBSD: vmparam.h,v 1.8 2021/02/26 02:18:29 simonb Exp $	*/
      2  1.1    matt 
      3  1.1    matt /*-
      4  1.1    matt  * Copyright (c) 2014 The NetBSD Foundation, Inc.
      5  1.1    matt  * All rights reserved.
      6  1.1    matt  *
      7  1.1    matt  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1    matt  * by Matt Thomas of 3am Software Foundry.
      9  1.1    matt  *
     10  1.1    matt  * Redistribution and use in source and binary forms, with or without
     11  1.1    matt  * modification, are permitted provided that the following conditions
     12  1.1    matt  * are met:
     13  1.1    matt  * 1. Redistributions of source code must retain the above copyright
     14  1.1    matt  *    notice, this list of conditions and the following disclaimer.
     15  1.1    matt  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1    matt  *    notice, this list of conditions and the following disclaimer in the
     17  1.1    matt  *    documentation and/or other materials provided with the distribution.
     18  1.1    matt  *
     19  1.1    matt  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  1.1    matt  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  1.1    matt  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  1.1    matt  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  1.1    matt  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  1.1    matt  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  1.1    matt  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  1.1    matt  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  1.1    matt  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  1.1    matt  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  1.1    matt  * POSSIBILITY OF SUCH DAMAGE.
     30  1.1    matt  */
     31  1.1    matt 
     32  1.1    matt #ifndef _RISCV_VMPARAM_H_
     33  1.1    matt #define	_RISCV_VMPARAM_H_
     34  1.1    matt 
     35  1.1    matt #include <riscv/param.h>
     36  1.1    matt 
     37  1.1    matt #ifdef _KERNEL_OPT
     38  1.1    matt #include "opt_multiprocessor.h"
     39  1.1    matt #endif
     40  1.1    matt 
     41  1.1    matt /*
     42  1.1    matt  * Machine dependent VM constants for RISCV.
     43  1.1    matt  */
     44  1.1    matt 
     45  1.1    matt #define	PAGE_SHIFT	PGSHIFT
     46  1.1    matt #define	PAGE_SIZE	(1 << PAGE_SHIFT)
     47  1.1    matt #define	PAGE_MASK	(PAGE_SIZE - 1)
     48  1.1    matt 
     49  1.1    matt /*
     50  1.1    matt  * USRSTACK is the top (end) of the user stack.
     51  1.1    matt  *
     52  1.1    matt  * USRSTACK needs to start a page below the maxuser address so that a memory
     53  1.1    matt  * access with a maximum displacement (0x7ff) won't cross into the kernel's
     54  1.1    matt  * address space.  We use PAGE_SIZE instead of 0x800 since these need to be
     55  1.1    matt  * page-aligned.
     56  1.1    matt  */
     57  1.1    matt #define	USRSTACK	(VM_MAXUSER_ADDRESS-PAGE_SIZE) /* Start of user stack */
     58  1.4     mrg #define	USRSTACK32	((uint32_t)VM_MAXUSER_ADDRESS32-PAGE_SIZE)
     59  1.1    matt 
     60  1.1    matt /*
     61  1.1    matt  * Virtual memory related constants, all in bytes
     62  1.1    matt  */
     63  1.1    matt #ifndef MAXTSIZ
     64  1.1    matt #define	MAXTSIZ		(128*1024*1024)		/* max text size */
     65  1.1    matt #endif
     66  1.1    matt #ifndef DFLDSIZ
     67  1.1    matt #define	DFLDSIZ		(256*1024*1024)		/* initial data size limit */
     68  1.1    matt #endif
     69  1.1    matt #ifndef MAXDSIZ
     70  1.1    matt #define	MAXDSIZ		(1536*1024*1024)	/* max data size */
     71  1.1    matt #endif
     72  1.1    matt #ifndef	DFLSSIZ
     73  1.8  simonb #define	DFLSSIZ		(4*1024*1024)		/* initial stack size limit */
     74  1.1    matt #endif
     75  1.1    matt #ifndef	MAXSSIZ
     76  1.1    matt #define	MAXSSIZ		(120*1024*1024)		/* max stack size */
     77  1.1    matt #endif
     78  1.1    matt 
     79  1.1    matt /*
     80  1.1    matt  * Virtual memory related constants, all in bytes
     81  1.1    matt  */
     82  1.1    matt #ifndef DFLDSIZ32
     83  1.1    matt #define	DFLDSIZ32	DFLDSIZ			/* initial data size limit */
     84  1.1    matt #endif
     85  1.1    matt #ifndef MAXDSIZ32
     86  1.1    matt #define	MAXDSIZ32	MAXDSIZ			/* max data size */
     87  1.1    matt #endif
     88  1.1    matt #ifndef	DFLSSIZ32
     89  1.1    matt #define	DFLSSIZ32	DFLTSIZ			/* initial stack size limit */
     90  1.1    matt #endif
     91  1.1    matt #ifndef	MAXSSIZ32
     92  1.1    matt #define	MAXSSIZ32	MAXSSIZ			/* max stack size */
     93  1.1    matt #endif
     94  1.1    matt 
     95  1.1    matt /*
     96  1.1    matt  * PTEs for mapping user space into the kernel for phyio operations.
     97  1.1    matt  * The default PTE number is enough to cover 8 disks * MAXBSIZE.
     98  1.1    matt  */
     99  1.1    matt #ifndef USRIOSIZE
    100  1.1    matt #define USRIOSIZE	(MAXBSIZE/PAGE_SIZE * 8)
    101  1.1    matt #endif
    102  1.1    matt 
    103  1.5    maxv /*
    104  1.5    maxv  * User/kernel map constants.
    105  1.5    maxv  */
    106  1.1    matt #define VM_MIN_ADDRESS		((vaddr_t)0x00000000)
    107  1.5    maxv #ifdef _LP64	/* Sv39 */
    108  1.5    maxv #define VM_MAXUSER_ADDRESS	((vaddr_t)0x0000004000000000 - 16 * PAGE_SIZE)
    109  1.7   skrll #define VM_MIN_KERNEL_ADDRESS	((vaddr_t)0xffffffc000000000)
    110  1.7   skrll #define VM_MAX_KERNEL_ADDRESS	((vaddr_t)0xffffffd000000000) /* MIN + 64GB */
    111  1.5    maxv #else		/* Sv32 */
    112  1.7   skrll #define VM_MAXUSER_ADDRESS	((vaddr_t)-0x7fffffff-1)/* 0xffffffff80000000 */
    113  1.7   skrll #define VM_MIN_KERNEL_ADDRESS	((vaddr_t)-0x7fffffff-1)/* 0xffffffff80000000 */
    114  1.7   skrll #define VM_MAX_KERNEL_ADDRESS	((vaddr_t)-0x40000000)	/* 0xffffffffc0000000 */
    115  1.1    matt #endif
    116  1.1    matt #define VM_MAX_ADDRESS		VM_MAXUSER_ADDRESS
    117  1.4     mrg #define VM_MAXUSER_ADDRESS32	((vaddr_t)(1UL << 31))/* 0x0000000080000000 */
    118  1.1    matt 
    119  1.1    matt /*
    120  1.1    matt  * The address to which unspecified mapping requests default
    121  1.1    matt  */
    122  1.1    matt #define __USE_TOPDOWN_VM
    123  1.1    matt 
    124  1.1    matt #define VM_DEFAULT_ADDRESS_TOPDOWN(da, sz) \
    125  1.2   joerg     trunc_page(USRSTACK - MAXSSIZ - (sz) - user_stack_guard_size)
    126  1.1    matt #define VM_DEFAULT_ADDRESS_BOTTOMUP(da, sz) \
    127  1.1    matt     round_page((vaddr_t)(da) + (vsize_t)maxdmap)
    128  1.1    matt 
    129  1.1    matt #define VM_DEFAULT_ADDRESS32_TOPDOWN(da, sz) \
    130  1.3   joerg     trunc_page(USRSTACK32 - MAXSSIZ32 - (sz) - user_stack_guard_size)
    131  1.1    matt #define VM_DEFAULT_ADDRESS32_BOTTOMUP(da, sz) \
    132  1.1    matt     round_page((vaddr_t)(da) + (vsize_t)MAXDSIZ32)
    133  1.1    matt 
    134  1.1    matt /* virtual sizes (bytes) for various kernel submaps */
    135  1.1    matt #define VM_PHYS_SIZE		(USRIOSIZE*PAGE_SIZE)
    136  1.1    matt 
    137  1.1    matt /* VM_PHYSSEG_MAX defined by platform-dependent code. */
    138  1.1    matt #ifndef VM_PHYSSEG_MAX
    139  1.1    matt #define VM_PHYSSEG_MAX		1
    140  1.1    matt #endif
    141  1.1    matt #if VM_PHYSSEG_MAX == 1
    142  1.1    matt #define	VM_PHYSSEG_STRAT	VM_PSTRAT_LINEAR
    143  1.1    matt #else
    144  1.1    matt #define	VM_PHYSSEG_STRAT	VM_PSTRAT_BSEARCH
    145  1.1    matt #endif
    146  1.1    matt #define	VM_PHYSSEG_NOADD	/* can add RAM after vm_mem_init */
    147  1.1    matt 
    148  1.1    matt #ifndef VM_NFREELIST
    149  1.1    matt #define	VM_NFREELIST		2	/* 2 distinct memory segments */
    150  1.1    matt #define VM_FREELIST_DEFAULT	0
    151  1.1    matt #define VM_FREELIST_DIRECTMAP	1
    152  1.1    matt #endif
    153  1.1    matt 
    154  1.1    matt #ifdef _KERNEL
    155  1.1    matt #define	UVM_KM_VMFREELIST	riscv_poolpage_vmfreelist
    156  1.1    matt extern int riscv_poolpage_vmfreelist;
    157  1.1    matt 
    158  1.1    matt #ifdef _LP64
    159  1.1    matt void *	cpu_uarea_alloc(bool);
    160  1.1    matt bool	cpu_uarea_free(void *);
    161  1.1    matt #endif
    162  1.1    matt #endif
    163  1.1    matt 
    164  1.1    matt #endif /* ! _RISCV_VMPARAM_H_ */
    165