Update to handle fragments correctly (set bsize to be fragment
[unix-history] / usr / src / sys / vm / vm_param.h
CommitLineData
175f072e 1/*
ad0f93d2
KB
2 * Copyright (c) 1991, 1993
3 * The Regents of the University of California. All rights reserved.
175f072e
KM
4 *
5 * This code is derived from software contributed to Berkeley by
6 * The Mach Operating System project at Carnegie-Mellon University.
7 *
0e24ad83 8 * %sccs.include.redist.c%
175f072e 9 *
70b9635a 10 * @(#)vm_param.h 8.2 (Berkeley) %G%
0e24ad83
KM
11 *
12 *
13 * Copyright (c) 1987, 1990 Carnegie-Mellon University.
14 * All rights reserved.
15 *
16 * Authors: Avadis Tevanian, Jr., Michael Wayne Young
17 *
18 * Permission to use, copy, modify and distribute this software and
19 * its documentation is hereby granted, provided that both the copyright
20 * notice and this permission notice appear in all copies of the
21 * software, derivative works or modified versions, and any portions
22 * thereof, and that both notices appear in supporting documentation.
23 *
24 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
25 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
26 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
27 *
28 * Carnegie Mellon requests users of this software to return to
29 *
30 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
31 * School of Computer Science
32 * Carnegie Mellon University
33 * Pittsburgh PA 15213-3890
34 *
35 * any improvements or extensions that they make and grant Carnegie the
36 * rights to redistribute these changes.
175f072e
KM
37 */
38
39/*
40 * Machine independent virtual memory parameters.
41 */
42
43#ifndef _VM_PARAM_
44#define _VM_PARAM_
45
175f072e 46#include <machine/vmparam.h>
175f072e
KM
47
48/*
49 * This belongs in types.h, but breaks too many existing programs.
50 */
51typedef int boolean_t;
52#define TRUE 1
53#define FALSE 0
54
55/*
56 * The machine independent pages are refered to as PAGES. A page
57 * is some number of hardware pages, depending on the target machine.
58 */
70b9635a 59#define DEFAULT_PAGE_SIZE 4096
175f072e
KM
60
61/*
62 * All references to the size of a page should be done with PAGE_SIZE
63 * or PAGE_SHIFT. The fact they are variables is hidden here so that
64 * we can easily make them constant if we so desire.
65 */
f92ce83a 66#define PAGE_SIZE cnt.v_page_size /* size of page */
70b9635a
CD
67#define PAGE_MASK page_mask /* size of page - 1 */
68#define PAGE_SHIFT page_shift /* bits to shift for pages */
9e46e59c
KM
69#ifdef KERNEL
70extern vm_size_t page_mask;
71extern int page_shift;
72#endif
73
0cac6ddf
KM
74/*
75 * CTL_VM identifiers
76 */
70b9635a
CD
77#define VM_METER 1 /* struct vmmeter */
78#define VM_LOADAVG 2 /* struct loadavg */
79#define VM_MAXID 3 /* number of valid vm ids */
0cac6ddf 80
70b9635a 81#define CTL_VM_NAMES { \
99f898ca
KM
82 { 0, 0 }, \
83 { "vmmeter", CTLTYPE_STRUCT }, \
84 { "loadavg", CTLTYPE_STRUCT }, \
0cac6ddf 85}
175f072e
KM
86
87/*
88 * Return values from the VM routines.
89 */
90#define KERN_SUCCESS 0
91#define KERN_INVALID_ADDRESS 1
92#define KERN_PROTECTION_FAILURE 2
93#define KERN_NO_SPACE 3
94#define KERN_INVALID_ARGUMENT 4
95#define KERN_FAILURE 5
96#define KERN_RESOURCE_SHORTAGE 6
97#define KERN_NOT_RECEIVER 7
98#define KERN_NO_ACCESS 8
99
b73f8487 100#ifndef ASSEMBLER
175f072e
KM
101/*
102 * Convert addresses to pages and vice versa.
103 * No rounding is used.
104 */
b73f8487 105#ifdef KERNEL
70b9635a 106#define atop(x) (((unsigned long)(x)) >> PAGE_SHIFT)
9e46e59c 107#define ptoa(x) ((vm_offset_t)((x) << PAGE_SHIFT))
175f072e
KM
108
109/*
b73f8487
CT
110 * Round off or truncate to the nearest page. These will work
111 * for either addresses or counts (i.e., 1 byte rounds to 1 page).
175f072e 112 */
70b9635a 113#define round_page(x) \
9e46e59c 114 ((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) & ~PAGE_MASK))
70b9635a 115#define trunc_page(x) \
9e46e59c 116 ((vm_offset_t)(((vm_offset_t)(x)) & ~PAGE_MASK))
70b9635a 117#define num_pages(x) \
9e46e59c 118 ((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) >> PAGE_SHIFT))
175f072e 119
175f072e
KM
120extern vm_size_t mem_size; /* size of physical memory (bytes) */
121extern vm_offset_t first_addr; /* first physical page */
122extern vm_offset_t last_addr; /* last physical page */
175f072e 123
b73f8487
CT
124#else
125/* out-of-kernel versions of round_page and trunc_page */
126#define round_page(x) \
70b9635a
CD
127 ((((vm_offset_t)(x) + (vm_page_size - 1)) / vm_page_size) * \
128 vm_page_size)
b73f8487
CT
129#define trunc_page(x) \
130 ((((vm_offset_t)(x)) / vm_page_size) * vm_page_size)
175f072e 131
b73f8487
CT
132#endif /* KERNEL */
133#endif /* ASSEMBLER */
134#endif /* _VM_PARAM_ */