xref: /minix3/sys/uvm/uvm_param.h (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc /*	$NetBSD: uvm_param.h,v 1.35 2015/09/26 20:28:38 christos Exp $	*/
26c8f7fc3SBen Gras 
36c8f7fc3SBen Gras /*
46c8f7fc3SBen Gras  * Copyright (c) 1991, 1993
56c8f7fc3SBen Gras  *	The Regents of the University of California.  All rights reserved.
66c8f7fc3SBen Gras  *
76c8f7fc3SBen Gras  * This code is derived from software contributed to Berkeley by
86c8f7fc3SBen Gras  * The Mach Operating System project at Carnegie-Mellon University.
96c8f7fc3SBen Gras  *
106c8f7fc3SBen Gras  * Redistribution and use in source and binary forms, with or without
116c8f7fc3SBen Gras  * modification, are permitted provided that the following conditions
126c8f7fc3SBen Gras  * are met:
136c8f7fc3SBen Gras  * 1. Redistributions of source code must retain the above copyright
146c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer.
156c8f7fc3SBen Gras  * 2. Redistributions in binary form must reproduce the above copyright
166c8f7fc3SBen Gras  *    notice, this list of conditions and the following disclaimer in the
176c8f7fc3SBen Gras  *    documentation and/or other materials provided with the distribution.
186c8f7fc3SBen Gras  * 3. Neither the name of the University nor the names of its contributors
196c8f7fc3SBen Gras  *    may be used to endorse or promote products derived from this software
206c8f7fc3SBen Gras  *    without specific prior written permission.
216c8f7fc3SBen Gras  *
226c8f7fc3SBen Gras  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
236c8f7fc3SBen Gras  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
246c8f7fc3SBen Gras  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
256c8f7fc3SBen Gras  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
266c8f7fc3SBen Gras  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
276c8f7fc3SBen Gras  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
286c8f7fc3SBen Gras  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
296c8f7fc3SBen Gras  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
306c8f7fc3SBen Gras  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
316c8f7fc3SBen Gras  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
326c8f7fc3SBen Gras  * SUCH DAMAGE.
336c8f7fc3SBen Gras  *
346c8f7fc3SBen Gras  *	@(#)vm_param.h	8.2 (Berkeley) 1/9/95
356c8f7fc3SBen Gras  *
366c8f7fc3SBen Gras  *
376c8f7fc3SBen Gras  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
386c8f7fc3SBen Gras  * All rights reserved.
396c8f7fc3SBen Gras  *
406c8f7fc3SBen Gras  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
416c8f7fc3SBen Gras  *
426c8f7fc3SBen Gras  * Permission to use, copy, modify and distribute this software and
436c8f7fc3SBen Gras  * its documentation is hereby granted, provided that both the copyright
446c8f7fc3SBen Gras  * notice and this permission notice appear in all copies of the
456c8f7fc3SBen Gras  * software, derivative works or modified versions, and any portions
466c8f7fc3SBen Gras  * thereof, and that both notices appear in supporting documentation.
476c8f7fc3SBen Gras  *
486c8f7fc3SBen Gras  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
496c8f7fc3SBen Gras  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
506c8f7fc3SBen Gras  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
516c8f7fc3SBen Gras  *
526c8f7fc3SBen Gras  * Carnegie Mellon requests users of this software to return to
536c8f7fc3SBen Gras  *
546c8f7fc3SBen Gras  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
556c8f7fc3SBen Gras  *  School of Computer Science
566c8f7fc3SBen Gras  *  Carnegie Mellon University
576c8f7fc3SBen Gras  *  Pittsburgh PA 15213-3890
586c8f7fc3SBen Gras  *
596c8f7fc3SBen Gras  * any improvements or extensions that they make and grant Carnegie the
606c8f7fc3SBen Gras  * rights to redistribute these changes.
616c8f7fc3SBen Gras  */
626c8f7fc3SBen Gras 
636c8f7fc3SBen Gras /*
646c8f7fc3SBen Gras  *	Machine independent virtual memory parameters.
656c8f7fc3SBen Gras  */
666c8f7fc3SBen Gras 
676c8f7fc3SBen Gras #ifndef	_VM_PARAM_
686c8f7fc3SBen Gras #define	_VM_PARAM_
696c8f7fc3SBen Gras 
706c8f7fc3SBen Gras #ifdef _KERNEL_OPT
716c8f7fc3SBen Gras #include "opt_modular.h"
726c8f7fc3SBen Gras #include "opt_uvm.h"
736c8f7fc3SBen Gras #endif
746c8f7fc3SBen Gras #ifdef _KERNEL
756c8f7fc3SBen Gras #include <sys/types.h>
766c8f7fc3SBen Gras #include <machine/vmparam.h>
776c8f7fc3SBen Gras #include <sys/resourcevar.h>
786c8f7fc3SBen Gras #endif
796c8f7fc3SBen Gras 
806c8f7fc3SBen Gras #if defined(_KERNEL)
816c8f7fc3SBen Gras 
826c8f7fc3SBen Gras #if defined(PAGE_SIZE)
836c8f7fc3SBen Gras 
846c8f7fc3SBen Gras /*
856c8f7fc3SBen Gras  * If PAGE_SIZE is defined at this stage, it must be a constant.
866c8f7fc3SBen Gras  */
876c8f7fc3SBen Gras 
886c8f7fc3SBen Gras #if PAGE_SIZE == 0
896c8f7fc3SBen Gras #error Invalid PAGE_SIZE definition
906c8f7fc3SBen Gras #endif
916c8f7fc3SBen Gras 
926c8f7fc3SBen Gras /*
936c8f7fc3SBen Gras  * If the platform does not need to support a variable PAGE_SIZE,
946c8f7fc3SBen Gras  * then provide default values for MIN_PAGE_SIZE and MAX_PAGE_SIZE.
956c8f7fc3SBen Gras  */
966c8f7fc3SBen Gras 
976c8f7fc3SBen Gras #if !defined(MIN_PAGE_SIZE)
986c8f7fc3SBen Gras #define	MIN_PAGE_SIZE	PAGE_SIZE
996c8f7fc3SBen Gras #endif /* ! MIN_PAGE_SIZE */
1006c8f7fc3SBen Gras 
1016c8f7fc3SBen Gras #if !defined(MAX_PAGE_SIZE)
1026c8f7fc3SBen Gras #define	MAX_PAGE_SIZE	PAGE_SIZE
1036c8f7fc3SBen Gras #endif /* ! MAX_PAGE_SIZE */
1046c8f7fc3SBen Gras 
1056c8f7fc3SBen Gras #else /* ! PAGE_SIZE */
1066c8f7fc3SBen Gras 
1076c8f7fc3SBen Gras /*
1086c8f7fc3SBen Gras  * PAGE_SIZE is not a constant; MIN_PAGE_SIZE and MAX_PAGE_SIZE must
1096c8f7fc3SBen Gras  * be defined.
1106c8f7fc3SBen Gras  */
1116c8f7fc3SBen Gras 
1126c8f7fc3SBen Gras #if !defined(MIN_PAGE_SIZE)
1136c8f7fc3SBen Gras #error MIN_PAGE_SIZE not defined
1146c8f7fc3SBen Gras #endif
1156c8f7fc3SBen Gras 
1166c8f7fc3SBen Gras #if !defined(MAX_PAGE_SIZE)
1176c8f7fc3SBen Gras #error MAX_PAGE_SIZE not defined
1186c8f7fc3SBen Gras #endif
1196c8f7fc3SBen Gras 
1206c8f7fc3SBen Gras #endif /* PAGE_SIZE */
1216c8f7fc3SBen Gras 
1226c8f7fc3SBen Gras /*
1236c8f7fc3SBen Gras  * MIN_PAGE_SIZE and MAX_PAGE_SIZE must be constants.
1246c8f7fc3SBen Gras  */
1256c8f7fc3SBen Gras 
1266c8f7fc3SBen Gras #if MIN_PAGE_SIZE == 0
1276c8f7fc3SBen Gras #error Invalid MIN_PAGE_SIZE definition
1286c8f7fc3SBen Gras #endif
1296c8f7fc3SBen Gras 
1306c8f7fc3SBen Gras #if MAX_PAGE_SIZE == 0
1316c8f7fc3SBen Gras #error Invalid MAX_PAGE_SIZE definition
1326c8f7fc3SBen Gras #endif
1336c8f7fc3SBen Gras 
1346c8f7fc3SBen Gras /*
1356c8f7fc3SBen Gras  * If MIN_PAGE_SIZE and MAX_PAGE_SIZE are not equal, then we must use
1366c8f7fc3SBen Gras  * non-constant PAGE_SIZE, et al for LKMs.
1376c8f7fc3SBen Gras  */
1386c8f7fc3SBen Gras #if (MIN_PAGE_SIZE != MAX_PAGE_SIZE)
1396c8f7fc3SBen Gras #define	__uvmexp_pagesize
1406c8f7fc3SBen Gras #if defined(_LKM) || defined(_MODULE)
1416c8f7fc3SBen Gras #undef PAGE_SIZE
1426c8f7fc3SBen Gras #undef PAGE_MASK
1436c8f7fc3SBen Gras #undef PAGE_SHIFT
1446c8f7fc3SBen Gras #endif
1456c8f7fc3SBen Gras #endif
1466c8f7fc3SBen Gras 
1476c8f7fc3SBen Gras /*
1486c8f7fc3SBen Gras  * Now provide PAGE_SIZE, PAGE_MASK, and PAGE_SHIFT if we do not
1496c8f7fc3SBen Gras  * have ones that are compile-time constants.
1506c8f7fc3SBen Gras  */
1516c8f7fc3SBen Gras #if !defined(PAGE_SIZE)
1526c8f7fc3SBen Gras extern const int *const uvmexp_pagesize;
1536c8f7fc3SBen Gras extern const int *const uvmexp_pagemask;
1546c8f7fc3SBen Gras extern const int *const uvmexp_pageshift;
1556c8f7fc3SBen Gras #define	PAGE_SIZE	(*uvmexp_pagesize)	/* size of page */
1566c8f7fc3SBen Gras #define	PAGE_MASK	(*uvmexp_pagemask)	/* size of page - 1 */
1576c8f7fc3SBen Gras #define	PAGE_SHIFT	(*uvmexp_pageshift)	/* bits to shift for pages */
1586c8f7fc3SBen Gras #endif /* PAGE_SIZE */
1596c8f7fc3SBen Gras 
1606c8f7fc3SBen Gras #endif /* _KERNEL */
1616c8f7fc3SBen Gras 
1626c8f7fc3SBen Gras /*
1636c8f7fc3SBen Gras  * CTL_VM identifiers
1646c8f7fc3SBen Gras  */
1656c8f7fc3SBen Gras #define	VM_METER	1		/* struct vmmeter */
1666c8f7fc3SBen Gras #define	VM_LOADAVG	2		/* struct loadavg */
1676c8f7fc3SBen Gras #define	VM_UVMEXP	3		/* struct uvmexp */
1686c8f7fc3SBen Gras #define	VM_NKMEMPAGES	4		/* kmem_map pages */
1696c8f7fc3SBen Gras #define	VM_UVMEXP2	5		/* struct uvmexp_sysctl */
1706c8f7fc3SBen Gras #define	VM_ANONMIN	6
1716c8f7fc3SBen Gras #define	VM_EXECMIN	7
1726c8f7fc3SBen Gras #define	VM_FILEMIN	8
1736c8f7fc3SBen Gras #define	VM_MAXSLP	9
1746c8f7fc3SBen Gras #define	VM_USPACE	10
1756c8f7fc3SBen Gras #define	VM_ANONMAX	11
1766c8f7fc3SBen Gras #define	VM_EXECMAX	12
1776c8f7fc3SBen Gras #define	VM_FILEMAX	13
178*0a6a1f1dSLionel Sambuc #define	VM_MINADDRESS	14
179*0a6a1f1dSLionel Sambuc #define	VM_MAXADDRESS	15
180*0a6a1f1dSLionel Sambuc #define	VM_PROC		16		/* process information */
1816c8f7fc3SBen Gras 
182*0a6a1f1dSLionel Sambuc #define	VM_MAXID	17		/* number of valid vm ids */
183*0a6a1f1dSLionel Sambuc 
184*0a6a1f1dSLionel Sambuc #define VM_PROC_MAP	1		/* struct kinfo_vmentry */
1856c8f7fc3SBen Gras 
1866c8f7fc3SBen Gras #define	CTL_VM_NAMES { \
1876c8f7fc3SBen Gras 	{ 0, 0 }, \
1886c8f7fc3SBen Gras 	{ "vmmeter", CTLTYPE_STRUCT }, \
1896c8f7fc3SBen Gras 	{ "loadavg", CTLTYPE_STRUCT }, \
1906c8f7fc3SBen Gras 	{ "uvmexp", CTLTYPE_STRUCT }, \
1916c8f7fc3SBen Gras 	{ "nkmempages", CTLTYPE_INT }, \
1926c8f7fc3SBen Gras 	{ "uvmexp2", CTLTYPE_STRUCT }, \
1936c8f7fc3SBen Gras 	{ "anonmin", CTLTYPE_INT }, \
1946c8f7fc3SBen Gras 	{ "execmin", CTLTYPE_INT }, \
1956c8f7fc3SBen Gras 	{ "filemin", CTLTYPE_INT }, \
1966c8f7fc3SBen Gras 	{ "maxslp", CTLTYPE_INT }, \
1976c8f7fc3SBen Gras 	{ "uspace", CTLTYPE_INT }, \
1986c8f7fc3SBen Gras 	{ "anonmax", CTLTYPE_INT }, \
1996c8f7fc3SBen Gras 	{ "execmax", CTLTYPE_INT }, \
2006c8f7fc3SBen Gras 	{ "filemax", CTLTYPE_INT }, \
201*0a6a1f1dSLionel Sambuc 	{ "minaddress", CTLTYPE_LONG }, \
202*0a6a1f1dSLionel Sambuc 	{ "maxaddress", CTLTYPE_LONG }, \
203*0a6a1f1dSLionel Sambuc 	{ "proc", CTLTYPE_STRUCT }, \
2046c8f7fc3SBen Gras }
2056c8f7fc3SBen Gras 
2066c8f7fc3SBen Gras #ifndef ASSEMBLER
2076c8f7fc3SBen Gras /*
2086c8f7fc3SBen Gras  *	Convert addresses to pages and vice versa.
2096c8f7fc3SBen Gras  *	No rounding is used.
2106c8f7fc3SBen Gras  */
2116c8f7fc3SBen Gras #ifdef _KERNEL
2126c8f7fc3SBen Gras #define	atop(x)		(((paddr_t)(x)) >> PAGE_SHIFT)
2136c8f7fc3SBen Gras #define	ptoa(x)		(((paddr_t)(x)) << PAGE_SHIFT)
2146c8f7fc3SBen Gras 
2156c8f7fc3SBen Gras /*
2166c8f7fc3SBen Gras  * Round off or truncate to the nearest page.  These will work
2176c8f7fc3SBen Gras  * for either addresses or counts (i.e., 1 byte rounds to 1 page).
2186c8f7fc3SBen Gras  */
2196c8f7fc3SBen Gras #define	round_page(x)	(((x) + PAGE_MASK) & ~PAGE_MASK)
2206c8f7fc3SBen Gras #define	trunc_page(x)	((x) & ~PAGE_MASK)
2216c8f7fc3SBen Gras 
222*0a6a1f1dSLionel Sambuc #ifndef VM_DEFAULT_ADDRESS_BOTTOMUP
223*0a6a1f1dSLionel Sambuc #define VM_DEFAULT_ADDRESS_BOTTOMUP(da, sz) \
224*0a6a1f1dSLionel Sambuc     round_page((vaddr_t)(da) + (vsize_t)maxdmap)
225*0a6a1f1dSLionel Sambuc #endif
2266c8f7fc3SBen Gras 
227*0a6a1f1dSLionel Sambuc #ifndef VM_DEFAULT_ADDRESS_TOPDOWN
228*0a6a1f1dSLionel Sambuc #define VM_DEFAULT_ADDRESS_TOPDOWN(da, sz) \
229*0a6a1f1dSLionel Sambuc     trunc_page(VM_MAXUSER_ADDRESS - MAXSSIZ - (sz))
230*0a6a1f1dSLionel Sambuc #endif
2316c8f7fc3SBen Gras 
2326c8f7fc3SBen Gras extern int		ubc_nwins;	/* number of UBC mapping windows */
2336c8f7fc3SBen Gras extern int		ubc_winshift;	/* shift for a UBC mapping window */
2346c8f7fc3SBen Gras extern u_int		uvm_emap_size;	/* size of emap */
2356c8f7fc3SBen Gras 
2366c8f7fc3SBen Gras #else
2376c8f7fc3SBen Gras /* out-of-kernel versions of round_page and trunc_page */
23884d9c625SLionel Sambuc #if !defined(__minix)
2396c8f7fc3SBen Gras #define	round_page(x) \
2406c8f7fc3SBen Gras 	((((vaddr_t)(x) + (vm_page_size - 1)) / vm_page_size) * \
2416c8f7fc3SBen Gras 	    vm_page_size)
2426c8f7fc3SBen Gras #define	trunc_page(x) \
2436c8f7fc3SBen Gras 	((((vaddr_t)(x)) / vm_page_size) * vm_page_size)
24484d9c625SLionel Sambuc #else
24584d9c625SLionel Sambuc /* LSC: Minix always uses the same definition of those. */
24684d9c625SLionel Sambuc #define	round_page(x)	(((x) + PAGE_MASK) & ~PAGE_MASK)
24784d9c625SLionel Sambuc #define	trunc_page(x)	((x) & ~PAGE_MASK)
24884d9c625SLionel Sambuc #endif /* !defined(__minix) */
2496c8f7fc3SBen Gras 
2506c8f7fc3SBen Gras #endif /* _KERNEL */
2516c8f7fc3SBen Gras 
2526c8f7fc3SBen Gras /*
2536c8f7fc3SBen Gras  * typedefs, necessary for standard UVM headers.
2546c8f7fc3SBen Gras  */
2556c8f7fc3SBen Gras 
2566c8f7fc3SBen Gras typedef unsigned int uvm_flag_t;
2576c8f7fc3SBen Gras 
2586c8f7fc3SBen Gras typedef int vm_inherit_t;	/* XXX: inheritance codes */
2596c8f7fc3SBen Gras typedef off_t voff_t;		/* XXX: offset within a uvm_object */
2606c8f7fc3SBen Gras typedef voff_t pgoff_t;		/* XXX: number of pages within a uvm object */
2616c8f7fc3SBen Gras 
2626c8f7fc3SBen Gras #endif /* ASSEMBLER */
2636c8f7fc3SBen Gras #endif /* _VM_PARAM_ */
264