xref: /csrg-svn/sys/vm/vm_param.h (revision 68164)
145748Smckusick /*
263379Sbostic  * Copyright (c) 1991, 1993
363379Sbostic  *	The Regents of the University of California.  All rights reserved.
445748Smckusick  *
545748Smckusick  * This code is derived from software contributed to Berkeley by
645748Smckusick  * The Mach Operating System project at Carnegie-Mellon University.
745748Smckusick  *
848493Smckusick  * %sccs.include.redist.c%
945748Smckusick  *
10*68164Scgd  *	@(#)vm_param.h	8.2 (Berkeley) 01/09/95
1148493Smckusick  *
1248493Smckusick  *
1348493Smckusick  * Copyright (c) 1987, 1990 Carnegie-Mellon University.
1448493Smckusick  * All rights reserved.
1548493Smckusick  *
1648493Smckusick  * Authors: Avadis Tevanian, Jr., Michael Wayne Young
1748493Smckusick  *
1848493Smckusick  * Permission to use, copy, modify and distribute this software and
1948493Smckusick  * its documentation is hereby granted, provided that both the copyright
2048493Smckusick  * notice and this permission notice appear in all copies of the
2148493Smckusick  * software, derivative works or modified versions, and any portions
2248493Smckusick  * thereof, and that both notices appear in supporting documentation.
2348493Smckusick  *
2448493Smckusick  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
2548493Smckusick  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
2648493Smckusick  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
2748493Smckusick  *
2848493Smckusick  * Carnegie Mellon requests users of this software to return to
2948493Smckusick  *
3048493Smckusick  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
3148493Smckusick  *  School of Computer Science
3248493Smckusick  *  Carnegie Mellon University
3348493Smckusick  *  Pittsburgh PA 15213-3890
3448493Smckusick  *
3548493Smckusick  * any improvements or extensions that they make and grant Carnegie the
3648493Smckusick  * rights to redistribute these changes.
3745748Smckusick  */
3845748Smckusick 
3945748Smckusick /*
4045748Smckusick  *	Machine independent virtual memory parameters.
4145748Smckusick  */
4245748Smckusick 
4345748Smckusick #ifndef	_VM_PARAM_
4445748Smckusick #define	_VM_PARAM_
4545748Smckusick 
4645748Smckusick #include <machine/vmparam.h>
4745748Smckusick 
4845748Smckusick /*
4945748Smckusick  * This belongs in types.h, but breaks too many existing programs.
5045748Smckusick  */
5145748Smckusick typedef int	boolean_t;
5245748Smckusick #define	TRUE	1
5345748Smckusick #define	FALSE	0
5445748Smckusick 
5545748Smckusick /*
5645748Smckusick  *	The machine independent pages are refered to as PAGES.  A page
5745748Smckusick  *	is some number of hardware pages, depending on the target machine.
5845748Smckusick  */
59*68164Scgd #define	DEFAULT_PAGE_SIZE	4096
6045748Smckusick 
6145748Smckusick /*
6245748Smckusick  *	All references to the size of a page should be done with PAGE_SIZE
6345748Smckusick  *	or PAGE_SHIFT.  The fact they are variables is hidden here so that
6445748Smckusick  *	we can easily make them constant if we so desire.
6545748Smckusick  */
6650912Smckusick #define	PAGE_SIZE	cnt.v_page_size		/* size of page */
67*68164Scgd #define	PAGE_MASK	page_mask		/* size of page - 1 */
68*68164Scgd #define	PAGE_SHIFT	page_shift		/* bits to shift for pages */
6950929Smckusick #ifdef KERNEL
7050929Smckusick extern vm_size_t	page_mask;
7150929Smckusick extern int		page_shift;
7250929Smckusick #endif
7345748Smckusick 
7457845Smckusick /*
7557845Smckusick  * CTL_VM identifiers
7657845Smckusick  */
77*68164Scgd #define	VM_METER	1		/* struct vmmeter */
78*68164Scgd #define	VM_LOADAVG	2		/* struct loadavg */
79*68164Scgd #define	VM_MAXID	3		/* number of valid vm ids */
8050929Smckusick 
81*68164Scgd #define	CTL_VM_NAMES { \
8259139Smckusick 	{ 0, 0 }, \
8359139Smckusick 	{ "vmmeter", CTLTYPE_STRUCT }, \
8459139Smckusick 	{ "loadavg", CTLTYPE_STRUCT }, \
8557845Smckusick }
8657845Smckusick 
8745748Smckusick /*
8845748Smckusick  *	Return values from the VM routines.
8945748Smckusick  */
9045748Smckusick #define	KERN_SUCCESS		0
9145748Smckusick #define	KERN_INVALID_ADDRESS	1
9245748Smckusick #define	KERN_PROTECTION_FAILURE	2
9345748Smckusick #define	KERN_NO_SPACE		3
9445748Smckusick #define	KERN_INVALID_ARGUMENT	4
9545748Smckusick #define	KERN_FAILURE		5
9645748Smckusick #define	KERN_RESOURCE_SHORTAGE	6
9745748Smckusick #define	KERN_NOT_RECEIVER	7
9845748Smckusick #define	KERN_NO_ACCESS		8
9945748Smckusick 
10060337Storek #ifndef ASSEMBLER
10145748Smckusick /*
10245748Smckusick  *	Convert addresses to pages and vice versa.
10345748Smckusick  *	No rounding is used.
10445748Smckusick  */
10560337Storek #ifdef KERNEL
106*68164Scgd #define	atop(x)		(((unsigned long)(x)) >> PAGE_SHIFT)
10750929Smckusick #define	ptoa(x)		((vm_offset_t)((x) << PAGE_SHIFT))
10845748Smckusick 
10945748Smckusick /*
11060337Storek  * Round off or truncate to the nearest page.  These will work
11160337Storek  * for either addresses or counts (i.e., 1 byte rounds to 1 page).
11245748Smckusick  */
113*68164Scgd #define	round_page(x) \
11450929Smckusick 	((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) & ~PAGE_MASK))
115*68164Scgd #define	trunc_page(x) \
11650929Smckusick 	((vm_offset_t)(((vm_offset_t)(x)) & ~PAGE_MASK))
117*68164Scgd #define	num_pages(x) \
11850929Smckusick 	((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) >> PAGE_SHIFT))
11945748Smckusick 
12045748Smckusick extern vm_size_t	mem_size;	/* size of physical memory (bytes) */
12145748Smckusick extern vm_offset_t	first_addr;	/* first physical page */
12245748Smckusick extern vm_offset_t	last_addr;	/* last physical page */
12345748Smckusick 
12460337Storek #else
12560337Storek /* out-of-kernel versions of round_page and trunc_page */
12660337Storek #define	round_page(x) \
127*68164Scgd 	((((vm_offset_t)(x) + (vm_page_size - 1)) / vm_page_size) * \
128*68164Scgd 	    vm_page_size)
12960337Storek #define	trunc_page(x) \
13060337Storek 	((((vm_offset_t)(x)) / vm_page_size) * vm_page_size)
13145748Smckusick 
13260337Storek #endif /* KERNEL */
13360337Storek #endif /* ASSEMBLER */
13460337Storek #endif /* _VM_PARAM_ */
135