Home | History | Annotate | Line # | Download | only in include
vmparam.h revision 1.4
      1  1.4    mrg /*	$NetBSD: vmparam.h,v 1.4 2018/05/31 22:26:36 mrg 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 /*
     46  1.1   matt  * We use a 8K page on RV64 and 4K on RV32 systems.
     47  1.1   matt  * Override PAGE_* definitions to compile-time constants.
     48  1.1   matt  */
     49  1.1   matt #define	PAGE_SHIFT	PGSHIFT
     50  1.1   matt #define	PAGE_SIZE	(1 << PAGE_SHIFT)
     51  1.1   matt #define	PAGE_MASK	(PAGE_SIZE - 1)
     52  1.1   matt 
     53  1.1   matt /*
     54  1.1   matt  * USRSTACK is the top (end) of the user stack.
     55  1.1   matt  *
     56  1.1   matt  * USRSTACK needs to start a page below the maxuser address so that a memory
     57  1.1   matt  * access with a maximum displacement (0x7ff) won't cross into the kernel's
     58  1.1   matt  * address space.  We use PAGE_SIZE instead of 0x800 since these need to be
     59  1.1   matt  * page-aligned.
     60  1.1   matt  */
     61  1.1   matt #define	USRSTACK	(VM_MAXUSER_ADDRESS-PAGE_SIZE) /* Start of user stack */
     62  1.4    mrg #define	USRSTACK32	((uint32_t)VM_MAXUSER_ADDRESS32-PAGE_SIZE)
     63  1.1   matt 
     64  1.1   matt /*
     65  1.1   matt  * Virtual memory related constants, all in bytes
     66  1.1   matt  */
     67  1.1   matt #ifndef MAXTSIZ
     68  1.1   matt #define	MAXTSIZ		(128*1024*1024)		/* max text size */
     69  1.1   matt #endif
     70  1.1   matt #ifndef DFLDSIZ
     71  1.1   matt #define	DFLDSIZ		(256*1024*1024)		/* initial data size limit */
     72  1.1   matt #endif
     73  1.1   matt #ifndef MAXDSIZ
     74  1.1   matt #define	MAXDSIZ		(1536*1024*1024)	/* max data size */
     75  1.1   matt #endif
     76  1.1   matt #ifndef	DFLSSIZ
     77  1.1   matt #define	DFLSSIZ		(16*1024*1024)		/* initial stack size limit */
     78  1.1   matt #endif
     79  1.1   matt #ifndef	MAXSSIZ
     80  1.1   matt #define	MAXSSIZ		(120*1024*1024)		/* max stack size */
     81  1.1   matt #endif
     82  1.1   matt 
     83  1.1   matt /*
     84  1.1   matt  * Virtual memory related constants, all in bytes
     85  1.1   matt  */
     86  1.1   matt #ifndef MAXTSIZ32
     87  1.1   matt #define	MAXTSIZ32	MAXTSIZ			/* max text size */
     88  1.1   matt #endif
     89  1.1   matt #ifndef DFLDSIZ32
     90  1.1   matt #define	DFLDSIZ32	DFLDSIZ			/* initial data size limit */
     91  1.1   matt #endif
     92  1.1   matt #ifndef MAXDSIZ32
     93  1.1   matt #define	MAXDSIZ32	MAXDSIZ			/* max data size */
     94  1.1   matt #endif
     95  1.1   matt #ifndef	DFLSSIZ32
     96  1.1   matt #define	DFLSSIZ32	DFLTSIZ			/* initial stack size limit */
     97  1.1   matt #endif
     98  1.1   matt #ifndef	MAXSSIZ32
     99  1.1   matt #define	MAXSSIZ32	MAXSSIZ			/* max stack size */
    100  1.1   matt #endif
    101  1.1   matt 
    102  1.1   matt /*
    103  1.1   matt  * PTEs for mapping user space into the kernel for phyio operations.
    104  1.1   matt  * The default PTE number is enough to cover 8 disks * MAXBSIZE.
    105  1.1   matt  */
    106  1.1   matt #ifndef USRIOSIZE
    107  1.1   matt #define USRIOSIZE	(MAXBSIZE/PAGE_SIZE * 8)
    108  1.1   matt #endif
    109  1.1   matt 
    110  1.1   matt // user/kernel map constants
    111  1.1   matt // These use negative addresses since RISCV addresses are signed.
    112  1.1   matt #define VM_MIN_ADDRESS		((vaddr_t)0x00000000)
    113  1.1   matt #ifdef _LP64
    114  1.1   matt #define VM_MAXUSER_ADDRESS	((vaddr_t) 1L << 42)	/* 0x0000040000000000 */
    115  1.1   matt // For 64-bit kernels, we could, in theory, have 8TB (42 (13+29) bits worth)
    116  1.1   matt // of KVA space.  We need to divide that between KVA for direct-mapped memory,
    117  1.1   matt // space for I/O devices (someday), the kernel's mapped space.  For now, we are
    118  1.1   matt // going to restrict ourselves to use highest 8GB of KVA. The highest 2GB of
    119  1.1   matt // that KVA will be used to direct map memory.
    120  1.1   matt #define VM_MAX_KERNEL_ADDRESS	((vaddr_t) -PAGE_SIZE << 18)
    121  1.1   matt 							/* 0xFFFFFFFF80000000 */
    122  1.1   matt #define VM_MIN_KERNEL_ADDRESS	((vaddr_t) -PAGE_SIZE << 20)
    123  1.1   matt 							/* 0xFFFFFFFE00000000 */
    124  1.1   matt #else
    125  1.1   matt #define VM_MAXUSER_ADDRESS	((vaddr_t)-0x7fffffff-1)/* 0xFFFFFFFF80000000 */
    126  1.1   matt // We reserve the bottom (nonnegative) address for user, then split the upper
    127  1.1   matt // 2GB into two 1GB, the lower for mapped KVA and the upper for direct-mapped.
    128  1.1   matt #define VM_MIN_KERNEL_ADDRESS	((vaddr_t)-0x7fffffff-1)/* 0xFFFFFFFF80000000 */
    129  1.1   matt #define VM_MAX_KERNEL_ADDRESS	((vaddr_t)-0x40000000)	/* 0xFFFFFFFFC0000000 */
    130  1.1   matt #endif
    131  1.1   matt #define VM_MAX_ADDRESS		VM_MAXUSER_ADDRESS
    132  1.4    mrg #define VM_MAXUSER_ADDRESS32	((vaddr_t)(1UL << 31))/* 0x0000000080000000 */
    133  1.1   matt 
    134  1.1   matt /*
    135  1.1   matt  * The address to which unspecified mapping requests default
    136  1.1   matt  */
    137  1.1   matt #define __USE_TOPDOWN_VM
    138  1.1   matt 
    139  1.1   matt #define VM_DEFAULT_ADDRESS_TOPDOWN(da, sz) \
    140  1.2  joerg     trunc_page(USRSTACK - MAXSSIZ - (sz) - user_stack_guard_size)
    141  1.1   matt #define VM_DEFAULT_ADDRESS_BOTTOMUP(da, sz) \
    142  1.1   matt     round_page((vaddr_t)(da) + (vsize_t)maxdmap)
    143  1.1   matt 
    144  1.1   matt #define VM_DEFAULT_ADDRESS32_TOPDOWN(da, sz) \
    145  1.3  joerg     trunc_page(USRSTACK32 - MAXSSIZ32 - (sz) - user_stack_guard_size)
    146  1.1   matt #define VM_DEFAULT_ADDRESS32_BOTTOMUP(da, sz) \
    147  1.1   matt     round_page((vaddr_t)(da) + (vsize_t)MAXDSIZ32)
    148  1.1   matt 
    149  1.1   matt /* virtual sizes (bytes) for various kernel submaps */
    150  1.1   matt #define VM_PHYS_SIZE		(USRIOSIZE*PAGE_SIZE)
    151  1.1   matt 
    152  1.1   matt /* VM_PHYSSEG_MAX defined by platform-dependent code. */
    153  1.1   matt #ifndef VM_PHYSSEG_MAX
    154  1.1   matt #define VM_PHYSSEG_MAX		1
    155  1.1   matt #endif
    156  1.1   matt #if VM_PHYSSEG_MAX == 1
    157  1.1   matt #define	VM_PHYSSEG_STRAT	VM_PSTRAT_LINEAR
    158  1.1   matt #else
    159  1.1   matt #define	VM_PHYSSEG_STRAT	VM_PSTRAT_BSEARCH
    160  1.1   matt #endif
    161  1.1   matt #define	VM_PHYSSEG_NOADD	/* can add RAM after vm_mem_init */
    162  1.1   matt 
    163  1.1   matt #ifndef VM_NFREELIST
    164  1.1   matt #define	VM_NFREELIST		2	/* 2 distinct memory segments */
    165  1.1   matt #define VM_FREELIST_DEFAULT	0
    166  1.1   matt #define VM_FREELIST_DIRECTMAP	1
    167  1.1   matt #endif
    168  1.1   matt 
    169  1.1   matt #ifdef _KERNEL
    170  1.1   matt #define	UVM_KM_VMFREELIST	riscv_poolpage_vmfreelist
    171  1.1   matt extern int riscv_poolpage_vmfreelist;
    172  1.1   matt 
    173  1.1   matt #ifdef _LP64
    174  1.1   matt void *	cpu_uarea_alloc(bool);
    175  1.1   matt bool	cpu_uarea_free(void *);
    176  1.1   matt #endif
    177  1.1   matt #endif
    178  1.1   matt 
    179  1.1   matt #endif /* ! _RISCV_VMPARAM_H_ */
    180