1 /* $NetBSD: uvm_param.h,v 1.35 2015/09/26 20:28:38 christos Exp $ */
4 * Copyright (c) 1991, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * The Mach Operating System project at Carnegie-Mellon University.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)vm_param.h 8.2 (Berkeley) 1/9/95
37 * Copyright (c) 1987, 1990 Carnegie-Mellon University.
38 * All rights reserved.
40 * Authors: Avadis Tevanian, Jr., Michael Wayne Young
42 * Permission to use, copy, modify and distribute this software and
43 * its documentation is hereby granted, provided that both the copyright
44 * notice and this permission notice appear in all copies of the
45 * software, derivative works or modified versions, and any portions
46 * thereof, and that both notices appear in supporting documentation.
48 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
49 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
50 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
52 * Carnegie Mellon requests users of this software to return to
54 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
55 * School of Computer Science
56 * Carnegie Mellon University
57 * Pittsburgh PA 15213-3890
59 * any improvements or extensions that they make and grant Carnegie the
60 * rights to redistribute these changes.
64 * Machine independent virtual memory parameters.
71 #include "opt_modular.h"
75 #include <sys/types.h>
76 #include <machine/vmparam.h>
77 #include <sys/resourcevar.h>
82 #if defined(PAGE_SIZE)
85 * If PAGE_SIZE is defined at this stage, it must be a constant.
89 #error Invalid PAGE_SIZE definition
93 * If the platform does not need to support a variable PAGE_SIZE,
94 * then provide default values for MIN_PAGE_SIZE and MAX_PAGE_SIZE.
97 #if !defined(MIN_PAGE_SIZE)
98 #define MIN_PAGE_SIZE PAGE_SIZE
99 #endif /* ! MIN_PAGE_SIZE */
101 #if !defined(MAX_PAGE_SIZE)
102 #define MAX_PAGE_SIZE PAGE_SIZE
103 #endif /* ! MAX_PAGE_SIZE */
105 #else /* ! PAGE_SIZE */
108 * PAGE_SIZE is not a constant; MIN_PAGE_SIZE and MAX_PAGE_SIZE must
112 #if !defined(MIN_PAGE_SIZE)
113 #error MIN_PAGE_SIZE not defined
116 #if !defined(MAX_PAGE_SIZE)
117 #error MAX_PAGE_SIZE not defined
120 #endif /* PAGE_SIZE */
123 * MIN_PAGE_SIZE and MAX_PAGE_SIZE must be constants.
126 #if MIN_PAGE_SIZE == 0
127 #error Invalid MIN_PAGE_SIZE definition
130 #if MAX_PAGE_SIZE == 0
131 #error Invalid MAX_PAGE_SIZE definition
135 * If MIN_PAGE_SIZE and MAX_PAGE_SIZE are not equal, then we must use
136 * non-constant PAGE_SIZE, et al for LKMs.
138 #if (MIN_PAGE_SIZE != MAX_PAGE_SIZE)
139 #define __uvmexp_pagesize
140 #if defined(_LKM) || defined(_MODULE)
148 * Now provide PAGE_SIZE, PAGE_MASK, and PAGE_SHIFT if we do not
149 * have ones that are compile-time constants.
151 #if !defined(PAGE_SIZE)
152 extern const int *const uvmexp_pagesize
;
153 extern const int *const uvmexp_pagemask
;
154 extern const int *const uvmexp_pageshift
;
155 #define PAGE_SIZE (*uvmexp_pagesize) /* size of page */
156 #define PAGE_MASK (*uvmexp_pagemask) /* size of page - 1 */
157 #define PAGE_SHIFT (*uvmexp_pageshift) /* bits to shift for pages */
158 #endif /* PAGE_SIZE */
165 #define VM_METER 1 /* struct vmmeter */
166 #define VM_LOADAVG 2 /* struct loadavg */
167 #define VM_UVMEXP 3 /* struct uvmexp */
168 #define VM_NKMEMPAGES 4 /* kmem_map pages */
169 #define VM_UVMEXP2 5 /* struct uvmexp_sysctl */
175 #define VM_ANONMAX 11
176 #define VM_EXECMAX 12
177 #define VM_FILEMAX 13
178 #define VM_MINADDRESS 14
179 #define VM_MAXADDRESS 15
180 #define VM_PROC 16 /* process information */
182 #define VM_MAXID 17 /* number of valid vm ids */
184 #define VM_PROC_MAP 1 /* struct kinfo_vmentry */
186 #define CTL_VM_NAMES { \
188 { "vmmeter", CTLTYPE_STRUCT }, \
189 { "loadavg", CTLTYPE_STRUCT }, \
190 { "uvmexp", CTLTYPE_STRUCT }, \
191 { "nkmempages", CTLTYPE_INT }, \
192 { "uvmexp2", CTLTYPE_STRUCT }, \
193 { "anonmin", CTLTYPE_INT }, \
194 { "execmin", CTLTYPE_INT }, \
195 { "filemin", CTLTYPE_INT }, \
196 { "maxslp", CTLTYPE_INT }, \
197 { "uspace", CTLTYPE_INT }, \
198 { "anonmax", CTLTYPE_INT }, \
199 { "execmax", CTLTYPE_INT }, \
200 { "filemax", CTLTYPE_INT }, \
201 { "minaddress", CTLTYPE_LONG }, \
202 { "maxaddress", CTLTYPE_LONG }, \
203 { "proc", CTLTYPE_STRUCT }, \
208 * Convert addresses to pages and vice versa.
209 * No rounding is used.
212 #define atop(x) (((paddr_t)(x)) >> PAGE_SHIFT)
213 #define ptoa(x) (((paddr_t)(x)) << PAGE_SHIFT)
216 * Round off or truncate to the nearest page. These will work
217 * for either addresses or counts (i.e., 1 byte rounds to 1 page).
219 #define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK)
220 #define trunc_page(x) ((x) & ~PAGE_MASK)
222 #ifndef VM_DEFAULT_ADDRESS_BOTTOMUP
223 #define VM_DEFAULT_ADDRESS_BOTTOMUP(da, sz) \
224 round_page((vaddr_t)(da) + (vsize_t)maxdmap)
227 #ifndef VM_DEFAULT_ADDRESS_TOPDOWN
228 #define VM_DEFAULT_ADDRESS_TOPDOWN(da, sz) \
229 trunc_page(VM_MAXUSER_ADDRESS - MAXSSIZ - (sz))
232 extern int ubc_nwins
; /* number of UBC mapping windows */
233 extern int ubc_winshift
; /* shift for a UBC mapping window */
234 extern u_int uvm_emap_size
; /* size of emap */
237 /* out-of-kernel versions of round_page and trunc_page */
238 #if !defined(__minix)
239 #define round_page(x) \
240 ((((vaddr_t)(x) + (vm_page_size - 1)) / vm_page_size) * \
242 #define trunc_page(x) \
243 ((((vaddr_t)(x)) / vm_page_size) * vm_page_size)
245 /* LSC: Minix always uses the same definition of those. */
246 #define round_page(x) (((x) + PAGE_MASK) & ~PAGE_MASK)
247 #define trunc_page(x) ((x) & ~PAGE_MASK)
248 #endif /* !defined(__minix) */
253 * typedefs, necessary for standard UVM headers.
256 typedef unsigned int uvm_flag_t
;
258 typedef int vm_inherit_t
; /* XXX: inheritance codes */
259 typedef off_t voff_t
; /* XXX: offset within a uvm_object */
260 typedef voff_t pgoff_t
; /* XXX: number of pages within a uvm object */
262 #endif /* ASSEMBLER */
263 #endif /* _VM_PARAM_ */