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