Home | History | Annotate | Line # | Download | only in uvm
uvm_param.h revision 1.24
      1  1.23  uebayasi /*	$NetBSD: uvm_param.h,v 1.24 2010/11/14 04:25:16 uebayasi Exp $	*/
      2   1.1       mrg 
      3  1.10       chs /*
      4   1.1       mrg  * Copyright (c) 1991, 1993
      5   1.1       mrg  *	The Regents of the University of California.  All rights reserved.
      6   1.1       mrg  *
      7   1.1       mrg  * This code is derived from software contributed to Berkeley by
      8   1.1       mrg  * The Mach Operating System project at Carnegie-Mellon University.
      9   1.1       mrg  *
     10   1.1       mrg  * Redistribution and use in source and binary forms, with or without
     11   1.1       mrg  * modification, are permitted provided that the following conditions
     12   1.1       mrg  * are met:
     13   1.1       mrg  * 1. Redistributions of source code must retain the above copyright
     14   1.1       mrg  *    notice, this list of conditions and the following disclaimer.
     15   1.1       mrg  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1       mrg  *    notice, this list of conditions and the following disclaimer in the
     17   1.1       mrg  *    documentation and/or other materials provided with the distribution.
     18  1.18       agc  * 3. Neither the name of the University nor the names of its contributors
     19   1.1       mrg  *    may be used to endorse or promote products derived from this software
     20   1.1       mrg  *    without specific prior written permission.
     21   1.1       mrg  *
     22   1.1       mrg  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23   1.1       mrg  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24   1.1       mrg  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25   1.1       mrg  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26   1.1       mrg  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27   1.1       mrg  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28   1.1       mrg  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29   1.1       mrg  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30   1.1       mrg  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31   1.1       mrg  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32   1.1       mrg  * SUCH DAMAGE.
     33   1.1       mrg  *
     34   1.1       mrg  *	@(#)vm_param.h	8.2 (Berkeley) 1/9/95
     35   1.1       mrg  *
     36   1.1       mrg  *
     37   1.1       mrg  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
     38   1.1       mrg  * All rights reserved.
     39   1.1       mrg  *
     40   1.1       mrg  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
     41  1.10       chs  *
     42   1.1       mrg  * Permission to use, copy, modify and distribute this software and
     43   1.1       mrg  * its documentation is hereby granted, provided that both the copyright
     44   1.1       mrg  * notice and this permission notice appear in all copies of the
     45   1.1       mrg  * software, derivative works or modified versions, and any portions
     46   1.1       mrg  * thereof, and that both notices appear in supporting documentation.
     47  1.10       chs  *
     48  1.10       chs  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     49  1.10       chs  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     50   1.1       mrg  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     51  1.10       chs  *
     52   1.1       mrg  * Carnegie Mellon requests users of this software to return to
     53   1.1       mrg  *
     54   1.1       mrg  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     55   1.1       mrg  *  School of Computer Science
     56   1.1       mrg  *  Carnegie Mellon University
     57   1.1       mrg  *  Pittsburgh PA 15213-3890
     58   1.1       mrg  *
     59   1.1       mrg  * any improvements or extensions that they make and grant Carnegie the
     60   1.1       mrg  * rights to redistribute these changes.
     61   1.1       mrg  */
     62   1.1       mrg 
     63   1.1       mrg /*
     64   1.1       mrg  *	Machine independent virtual memory parameters.
     65   1.1       mrg  */
     66   1.1       mrg 
     67   1.1       mrg #ifndef	_VM_PARAM_
     68   1.1       mrg #define	_VM_PARAM_
     69   1.1       mrg 
     70  1.14    atatat #ifdef _KERNEL_OPT
     71  1.14    atatat #include "opt_uvm.h"
     72  1.14    atatat #endif
     73  1.12      matt #ifdef _KERNEL
     74  1.21        he #include <sys/types.h>
     75   1.1       mrg #include <machine/vmparam.h>
     76  1.19        pk #include <sys/resourcevar.h>
     77   1.1       mrg #endif
     78   1.1       mrg 
     79  1.16   thorpej #if defined(_KERNEL)
     80  1.16   thorpej 
     81  1.16   thorpej #if defined(PAGE_SIZE)
     82  1.16   thorpej 
     83   1.1       mrg /*
     84  1.16   thorpej  * If PAGE_SIZE is defined at this stage, it must be a constant.
     85   1.1       mrg  */
     86   1.1       mrg 
     87  1.16   thorpej #if PAGE_SIZE == 0
     88  1.16   thorpej #error Invalid PAGE_SIZE definition
     89  1.16   thorpej #endif
     90  1.16   thorpej 
     91   1.1       mrg /*
     92  1.16   thorpej  * If the platform does not need to support a variable PAGE_SIZE,
     93  1.16   thorpej  * then provide default values for MIN_PAGE_SIZE and MAX_PAGE_SIZE.
     94   1.1       mrg  */
     95  1.16   thorpej 
     96  1.16   thorpej #if !defined(MIN_PAGE_SIZE)
     97  1.16   thorpej #define	MIN_PAGE_SIZE	PAGE_SIZE
     98  1.16   thorpej #endif /* ! MIN_PAGE_SIZE */
     99  1.16   thorpej 
    100  1.16   thorpej #if !defined(MAX_PAGE_SIZE)
    101  1.16   thorpej #define	MAX_PAGE_SIZE	PAGE_SIZE
    102  1.16   thorpej #endif /* ! MAX_PAGE_SIZE */
    103  1.16   thorpej 
    104  1.16   thorpej #else /* ! PAGE_SIZE */
    105  1.16   thorpej 
    106  1.16   thorpej /*
    107  1.16   thorpej  * PAGE_SIZE is not a constant; MIN_PAGE_SIZE and MAX_PAGE_SIZE must
    108  1.16   thorpej  * be defined.
    109  1.16   thorpej  */
    110  1.16   thorpej 
    111  1.16   thorpej #if !defined(MIN_PAGE_SIZE)
    112  1.16   thorpej #error MIN_PAGE_SIZE not defined
    113  1.16   thorpej #endif
    114  1.16   thorpej 
    115  1.16   thorpej #if !defined(MAX_PAGE_SIZE)
    116  1.16   thorpej #error MAX_PAGE_SIZE not defined
    117  1.16   thorpej #endif
    118  1.16   thorpej 
    119  1.16   thorpej #endif /* PAGE_SIZE */
    120  1.16   thorpej 
    121  1.16   thorpej /*
    122  1.16   thorpej  * MIN_PAGE_SIZE and MAX_PAGE_SIZE must be constants.
    123  1.16   thorpej  */
    124  1.16   thorpej 
    125  1.16   thorpej #if MIN_PAGE_SIZE == 0
    126  1.16   thorpej #error Invalid MIN_PAGE_SIZE definition
    127  1.16   thorpej #endif
    128  1.16   thorpej 
    129  1.16   thorpej #if MAX_PAGE_SIZE == 0
    130  1.16   thorpej #error Invalid MAX_PAGE_SIZE definition
    131  1.16   thorpej #endif
    132  1.16   thorpej 
    133  1.16   thorpej /*
    134  1.16   thorpej  * If MIN_PAGE_SIZE and MAX_PAGE_SIZE are not equal, then we must use
    135  1.16   thorpej  * non-constant PAGE_SIZE, et al for LKMs.
    136  1.16   thorpej  */
    137  1.16   thorpej #if (MIN_PAGE_SIZE != MAX_PAGE_SIZE) && defined(_LKM)
    138  1.16   thorpej #undef PAGE_SIZE
    139  1.16   thorpej #undef PAGE_MASK
    140  1.16   thorpej #undef PAGE_SHIFT
    141  1.16   thorpej #endif
    142  1.16   thorpej 
    143  1.16   thorpej /*
    144  1.16   thorpej  * Now provide PAGE_SIZE, PAGE_MASK, and PAGE_SHIFT if we do not
    145  1.16   thorpej  * have ones that are compile-time constants.
    146  1.16   thorpej  */
    147  1.16   thorpej #if !defined(PAGE_SIZE)
    148  1.24  uebayasi extern int *uvmexp_pagesize;
    149  1.24  uebayasi extern int *uvmexp_pagemask;
    150  1.24  uebayasi extern int *uvmexp_pageshift;
    151  1.24  uebayasi #define	PAGE_SIZE	(*uvmexp_pagesize)	/* size of page */
    152  1.24  uebayasi #define	PAGE_MASK	(*uvmexp_pagemask)	/* size of page - 1 */
    153  1.24  uebayasi #define	PAGE_SHIFT	(*uvmexp_pageshift)	/* bits to shift for pages */
    154  1.16   thorpej #endif /* PAGE_SIZE */
    155  1.16   thorpej 
    156   1.1       mrg #endif /* _KERNEL */
    157   1.1       mrg 
    158   1.1       mrg /*
    159   1.1       mrg  * CTL_VM identifiers
    160   1.1       mrg  */
    161   1.1       mrg #define	VM_METER	1		/* struct vmmeter */
    162   1.1       mrg #define	VM_LOADAVG	2		/* struct loadavg */
    163   1.2    simonb #define	VM_UVMEXP	3		/* struct uvmexp */
    164   1.1       mrg #define	VM_NKMEMPAGES	4		/* kmem_map pages */
    165   1.2    simonb #define	VM_UVMEXP2	5		/* struct uvmexp_sysctl */
    166   1.5       chs #define	VM_ANONMIN	6
    167  1.13       chs #define	VM_EXECMIN	7
    168  1.13       chs #define	VM_FILEMIN	8
    169  1.11      matt #define	VM_MAXSLP	9
    170  1.11      matt #define	VM_USPACE	10
    171  1.13       chs #define	VM_ANONMAX	11
    172  1.13       chs #define	VM_EXECMAX	12
    173  1.13       chs #define	VM_FILEMAX	13
    174   1.5       chs 
    175  1.13       chs #define	VM_MAXID	14		/* number of valid vm ids */
    176   1.1       mrg 
    177   1.1       mrg #define	CTL_VM_NAMES { \
    178   1.1       mrg 	{ 0, 0 }, \
    179   1.1       mrg 	{ "vmmeter", CTLTYPE_STRUCT }, \
    180   1.1       mrg 	{ "loadavg", CTLTYPE_STRUCT }, \
    181   1.1       mrg 	{ "uvmexp", CTLTYPE_STRUCT }, \
    182   1.1       mrg 	{ "nkmempages", CTLTYPE_INT }, \
    183   1.2    simonb 	{ "uvmexp2", CTLTYPE_STRUCT }, \
    184   1.5       chs 	{ "anonmin", CTLTYPE_INT }, \
    185  1.13       chs 	{ "execmin", CTLTYPE_INT }, \
    186  1.13       chs 	{ "filemin", CTLTYPE_INT }, \
    187  1.11      matt 	{ "maxslp", CTLTYPE_INT }, \
    188  1.11      matt 	{ "uspace", CTLTYPE_INT }, \
    189  1.13       chs 	{ "anonmax", CTLTYPE_INT }, \
    190  1.13       chs 	{ "execmax", CTLTYPE_INT }, \
    191  1.13       chs 	{ "filemax", CTLTYPE_INT }, \
    192   1.1       mrg }
    193   1.1       mrg 
    194   1.1       mrg #ifndef ASSEMBLER
    195   1.1       mrg /*
    196   1.1       mrg  *	Convert addresses to pages and vice versa.
    197   1.1       mrg  *	No rounding is used.
    198   1.1       mrg  */
    199   1.1       mrg #ifdef _KERNEL
    200   1.4        pk #define	atop(x)		(((paddr_t)(x)) >> PAGE_SHIFT)
    201   1.1       mrg #define	ptoa(x)		((vaddr_t)((vaddr_t)(x) << PAGE_SHIFT))
    202   1.1       mrg 
    203   1.1       mrg /*
    204   1.1       mrg  * Round off or truncate to the nearest page.  These will work
    205   1.1       mrg  * for either addresses or counts (i.e., 1 byte rounds to 1 page).
    206   1.1       mrg  */
    207   1.1       mrg #define	round_page(x)	(((x) + PAGE_MASK) & ~PAGE_MASK)
    208   1.1       mrg #define	trunc_page(x)	((x) & ~PAGE_MASK)
    209  1.14    atatat 
    210  1.14    atatat /*
    211  1.14    atatat  * Set up the default mapping address (VM_DEFAULT_ADDRESS) according to:
    212  1.14    atatat  *
    213  1.14    atatat  * USE_TOPDOWN_VM:	a kernel option to enable on a per-kernel basis
    214  1.14    atatat  *			which only be used on ports that define...
    215  1.14    atatat  * __HAVE_TOPDOWN_VM:	a per-port option to offer the topdown option
    216  1.14    atatat  *
    217  1.14    atatat  * __USE_TOPDOWN_VM:	a per-port option to unconditionally use it
    218  1.14    atatat  *
    219  1.14    atatat  * if __USE_TOPDOWN_VM is defined, the port can specify a default vm
    220  1.14    atatat  * address, or we will use the topdown default from below.  If it is
    221  1.14    atatat  * NOT defined, then the port can offer topdown as an option, but it
    222  1.14    atatat  * MUST define the VM_DEFAULT_ADDRESS macro itself.
    223  1.14    atatat  */
    224  1.14    atatat #if defined(USE_TOPDOWN_VM) || defined(__USE_TOPDOWN_VM)
    225  1.14    atatat # if !defined(__HAVE_TOPDOWN_VM) && !defined(__USE_TOPDOWN_VM)
    226  1.14    atatat #  error "Top down memory allocation not enabled for this system"
    227  1.14    atatat # else /* !__HAVE_TOPDOWN_VM && !__USE_TOPDOWN_VM */
    228  1.14    atatat #  define __USING_TOPDOWN_VM
    229  1.14    atatat #  if !defined(VM_DEFAULT_ADDRESS)
    230  1.14    atatat #   if !defined(__USE_TOPDOWN_VM)
    231  1.14    atatat #    error "Top down memory allocation not configured for this system"
    232  1.14    atatat #   else /* !__USE_TOPDOWN_VM */
    233  1.14    atatat #    define VM_DEFAULT_ADDRESS(da, sz) \
    234  1.14    atatat 	trunc_page(VM_MAXUSER_ADDRESS - MAXSSIZ - (sz))
    235  1.14    atatat #   endif /* !__USE_TOPDOWN_VM */
    236  1.14    atatat #  endif /* !VM_DEFAULT_ADDRESS */
    237  1.14    atatat # endif /* !__HAVE_TOPDOWN_VM && !__USE_TOPDOWN_VM */
    238  1.14    atatat #endif /* USE_TOPDOWN_VM || __USE_TOPDOWN_VM */
    239  1.14    atatat 
    240  1.14    atatat #if !defined(__USING_TOPDOWN_VM)
    241  1.14    atatat # if defined(VM_DEFAULT_ADDRESS)
    242  1.14    atatat #  error "Default vm address should not be defined here"
    243  1.14    atatat # else /* VM_DEFAULT_ADDRESS */
    244  1.19        pk #  define VM_DEFAULT_ADDRESS(da, sz) round_page((vaddr_t)(da) + (vsize_t)maxdmap)
    245  1.14    atatat # endif /* VM_DEFAULT_ADDRESS */
    246  1.14    atatat #endif /* !__USING_TOPDOWN_VM */
    247   1.1       mrg 
    248   1.3       chs extern int		ubc_nwins;	/* number of UBC mapping windows */
    249   1.7       chs extern int		ubc_winshift;	/* shift for a UBC mapping window */
    250  1.22  kiyohara extern u_int		uvm_emap_size;	/* size of emap */
    251   1.1       mrg 
    252   1.1       mrg #else
    253   1.1       mrg /* out-of-kernel versions of round_page and trunc_page */
    254   1.1       mrg #define	round_page(x) \
    255   1.1       mrg 	((((vaddr_t)(x) + (vm_page_size - 1)) / vm_page_size) * \
    256   1.1       mrg 	    vm_page_size)
    257   1.1       mrg #define	trunc_page(x) \
    258   1.1       mrg 	((((vaddr_t)(x)) / vm_page_size) * vm_page_size)
    259   1.1       mrg 
    260   1.1       mrg #endif /* _KERNEL */
    261   1.1       mrg #endif /* ASSEMBLER */
    262   1.1       mrg #endif /* _VM_PARAM_ */
    263