xref: /csrg-svn/sys/vm/vm_param.h (revision 45748)
1 /*
2  * Copyright (c) 1985, Avadis Tevanian, Jr., Michael Wayne Young
3  * Copyright (c) 1987 Carnegie-Mellon University
4  * Copyright (c) 1991 Regents of the University of California.
5  * 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  * The CMU software License Agreement specifies the terms and conditions
11  * for use and redistribution.
12  *
13  *	@(#)vm_param.h	7.1 (Berkeley) 12/05/90
14  */
15 
16 /*
17  *	Machine independent virtual memory parameters.
18  */
19 
20 #ifndef	_VM_PARAM_
21 #define	_VM_PARAM_
22 
23 #ifdef KERNEL
24 #include "machine/vmparam.h"
25 #else
26 #include <machine/vmparam.h>
27 #endif
28 
29 /*
30  * This belongs in types.h, but breaks too many existing programs.
31  */
32 typedef int	boolean_t;
33 #define	TRUE	1
34 #define	FALSE	0
35 
36 /*
37  *	The machine independent pages are refered to as PAGES.  A page
38  *	is some number of hardware pages, depending on the target machine.
39  */
40 
41 /*
42  *	All references to the size of a page should be done with PAGE_SIZE
43  *	or PAGE_SHIFT.  The fact they are variables is hidden here so that
44  *	we can easily make them constant if we so desire.
45  */
46 
47 #define	PAGE_SIZE	page_size	/* size of page in addressible units */
48 #define PAGE_SHIFT	page_shift	/* number of bits to shift for pages */
49 
50 /*
51  *	Return values from the VM routines.
52  */
53 #define	KERN_SUCCESS		0
54 #define	KERN_INVALID_ADDRESS	1
55 #define	KERN_PROTECTION_FAILURE	2
56 #define	KERN_NO_SPACE		3
57 #define	KERN_INVALID_ARGUMENT	4
58 #define	KERN_FAILURE		5
59 #define	KERN_RESOURCE_SHORTAGE	6
60 #define	KERN_NOT_RECEIVER	7
61 #define	KERN_NO_ACCESS		8
62 
63 #ifdef	ASSEMBLER
64 #else	ASSEMBLER
65 /*
66  *	Convert addresses to pages and vice versa.
67  *	No rounding is used.
68  */
69 
70 #ifdef	KERNEL
71 #define	atop(x)		(((unsigned)(x)) >> page_shift)
72 #define	ptoa(x)		((vm_offset_t)((x) << page_shift))
73 #endif	KERNEL
74 
75 /*
76  *	Round off or truncate to the nearest page.  These will work
77  *	for either addresses or counts.  (i.e. 1 byte rounds to 1 page
78  *	bytes.
79  */
80 
81 #ifdef	KERNEL
82 #define round_page(x)	((vm_offset_t)((((vm_offset_t)(x)) + page_mask) & ~page_mask))
83 #define trunc_page(x)	((vm_offset_t)(((vm_offset_t)(x)) & ~page_mask))
84 #else	KERNEL
85 #define	round_page(x)	((((vm_offset_t)(x) + (vm_page_size - 1)) / vm_page_size) * vm_page_size)
86 #define	trunc_page(x)	((((vm_offset_t)(x)) / vm_page_size) * vm_page_size)
87 #endif	KERNEL
88 
89 #ifdef	KERNEL
90 extern vm_size_t	page_size;	/* machine independent page size */
91 extern vm_size_t	page_mask;	/* page_size - 1; mask for
92 						   offset within page */
93 extern int		page_shift;	/* shift to use for page size */
94 
95 extern vm_size_t	mem_size;	/* size of physical memory (bytes) */
96 extern vm_offset_t	first_addr;	/* first physical page */
97 extern vm_offset_t	last_addr;	/* last physical page */
98 #endif	KERNEL
99 
100 #endif	ASSEMBLER
101 
102 #endif	_VM_PARAM_
103