xref: /netbsd/sys/uvm/uvm_param.h (revision bf9ec67e)
1 /*	$NetBSD: uvm_param.h,v 1.13 2001/12/09 03:07:19 chs 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@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
75 #include <machine/vmparam.h>
76 #endif
77 
78 /*
79  * This belongs in types.h, but breaks too many existing programs.
80  */
81 typedef int	boolean_t;
82 #ifndef TRUE
83 #define	TRUE	1
84 #endif
85 #ifndef FALSE
86 #define	FALSE	0
87 #endif
88 
89 /*
90  *	The machine independent pages are refered to as PAGES.  A page
91  *	is some number of hardware pages, depending on the target machine.
92  */
93 #define	DEFAULT_PAGE_SIZE	4096
94 
95 #if defined(_KERNEL) && !defined(PAGE_SIZE)
96 /*
97  *	All references to the size of a page should be done with PAGE_SIZE
98  *	or PAGE_SHIFT.  The fact they are variables is hidden here so that
99  *	we can easily make them constant if we so desire.
100  */
101 #define	PAGE_SIZE	uvmexp.pagesize		/* size of page */
102 #define	PAGE_MASK	uvmexp.pagemask		/* size of page - 1 */
103 #define	PAGE_SHIFT	uvmexp.pageshift	/* bits to shift for pages */
104 #endif /* _KERNEL */
105 
106 /*
107  * CTL_VM identifiers
108  */
109 #define	VM_METER	1		/* struct vmmeter */
110 #define	VM_LOADAVG	2		/* struct loadavg */
111 #define	VM_UVMEXP	3		/* struct uvmexp */
112 #define	VM_NKMEMPAGES	4		/* kmem_map pages */
113 #define	VM_UVMEXP2	5		/* struct uvmexp_sysctl */
114 #define	VM_ANONMIN	6
115 #define	VM_EXECMIN	7
116 #define	VM_FILEMIN	8
117 #define	VM_MAXSLP	9
118 #define	VM_USPACE	10
119 #define	VM_ANONMAX	11
120 #define	VM_EXECMAX	12
121 #define	VM_FILEMAX	13
122 
123 #define	VM_MAXID	14		/* number of valid vm ids */
124 
125 #define	CTL_VM_NAMES { \
126 	{ 0, 0 }, \
127 	{ "vmmeter", CTLTYPE_STRUCT }, \
128 	{ "loadavg", CTLTYPE_STRUCT }, \
129 	{ "uvmexp", CTLTYPE_STRUCT }, \
130 	{ "nkmempages", CTLTYPE_INT }, \
131 	{ "uvmexp2", CTLTYPE_STRUCT }, \
132 	{ "anonmin", CTLTYPE_INT }, \
133 	{ "execmin", CTLTYPE_INT }, \
134 	{ "filemin", CTLTYPE_INT }, \
135 	{ "maxslp", CTLTYPE_INT }, \
136 	{ "uspace", CTLTYPE_INT }, \
137 	{ "anonmax", CTLTYPE_INT }, \
138 	{ "execmax", CTLTYPE_INT }, \
139 	{ "filemax", CTLTYPE_INT }, \
140 }
141 
142 #ifndef ASSEMBLER
143 /*
144  *	Convert addresses to pages and vice versa.
145  *	No rounding is used.
146  */
147 #ifdef _KERNEL
148 #define	atop(x)		(((paddr_t)(x)) >> PAGE_SHIFT)
149 #define	ptoa(x)		((vaddr_t)((vaddr_t)(x) << PAGE_SHIFT))
150 
151 /*
152  * Round off or truncate to the nearest page.  These will work
153  * for either addresses or counts (i.e., 1 byte rounds to 1 page).
154  */
155 #define	round_page(x)	(((x) + PAGE_MASK) & ~PAGE_MASK)
156 #define	trunc_page(x)	((x) & ~PAGE_MASK)
157 
158 extern psize_t		mem_size;	/* size of physical memory (bytes) */
159 extern int		ubc_nwins;	/* number of UBC mapping windows */
160 extern int		ubc_winshift;	/* shift for a UBC mapping window */
161 
162 #else
163 /* out-of-kernel versions of round_page and trunc_page */
164 #define	round_page(x) \
165 	((((vaddr_t)(x) + (vm_page_size - 1)) / vm_page_size) * \
166 	    vm_page_size)
167 #define	trunc_page(x) \
168 	((((vaddr_t)(x)) / vm_page_size) * vm_page_size)
169 
170 #endif /* _KERNEL */
171 #endif /* ASSEMBLER */
172 #endif /* _VM_PARAM_ */
173