145748Smckusick /* 245748Smckusick * Copyright (c) 1991 Regents of the University of California. 345748Smckusick * 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*50929Smckusick * @(#)vm_param.h 7.5 (Berkeley) 08/28/91 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 #ifdef KERNEL 4745748Smckusick #include "machine/vmparam.h" 4845748Smckusick #else 4945748Smckusick #include <machine/vmparam.h> 5045748Smckusick #endif 5145748Smckusick 5245748Smckusick /* 5345748Smckusick * This belongs in types.h, but breaks too many existing programs. 5445748Smckusick */ 5545748Smckusick typedef int boolean_t; 5645748Smckusick #define TRUE 1 5745748Smckusick #define FALSE 0 5845748Smckusick 5945748Smckusick /* 6045748Smckusick * The machine independent pages are refered to as PAGES. A page 6145748Smckusick * is some number of hardware pages, depending on the target machine. 6245748Smckusick */ 6350547Smckusick #define DEFAULT_PAGE_SIZE 4096 6445748Smckusick 6545748Smckusick /* 6645748Smckusick * All references to the size of a page should be done with PAGE_SIZE 6745748Smckusick * or PAGE_SHIFT. The fact they are variables is hidden here so that 6845748Smckusick * we can easily make them constant if we so desire. 6945748Smckusick */ 7050912Smckusick #define PAGE_SIZE cnt.v_page_size /* size of page */ 71*50929Smckusick #define PAGE_MASK page_mask /* size of page - 1 */ 7250547Smckusick #define PAGE_SHIFT page_shift /* bits to shift for pages */ 73*50929Smckusick #ifdef KERNEL 74*50929Smckusick extern vm_size_t page_mask; 75*50929Smckusick extern int page_shift; 76*50929Smckusick #endif 7745748Smckusick 78*50929Smckusick 7945748Smckusick /* 8045748Smckusick * Return values from the VM routines. 8145748Smckusick */ 8245748Smckusick #define KERN_SUCCESS 0 8345748Smckusick #define KERN_INVALID_ADDRESS 1 8445748Smckusick #define KERN_PROTECTION_FAILURE 2 8545748Smckusick #define KERN_NO_SPACE 3 8645748Smckusick #define KERN_INVALID_ARGUMENT 4 8745748Smckusick #define KERN_FAILURE 5 8845748Smckusick #define KERN_RESOURCE_SHORTAGE 6 8945748Smckusick #define KERN_NOT_RECEIVER 7 9045748Smckusick #define KERN_NO_ACCESS 8 9145748Smckusick 9245748Smckusick #ifdef ASSEMBLER 9345748Smckusick #else ASSEMBLER 9445748Smckusick /* 9545748Smckusick * Convert addresses to pages and vice versa. 9645748Smckusick * No rounding is used. 9745748Smckusick */ 9845748Smckusick 9945748Smckusick #ifdef KERNEL 100*50929Smckusick #define atop(x) (((unsigned)(x)) >> PAGE_SHIFT) 101*50929Smckusick #define ptoa(x) ((vm_offset_t)((x) << PAGE_SHIFT)) 10245748Smckusick #endif KERNEL 10345748Smckusick 10445748Smckusick /* 10545748Smckusick * Round off or truncate to the nearest page. These will work 10645748Smckusick * for either addresses or counts. (i.e. 1 byte rounds to 1 page 10745748Smckusick * bytes. 10845748Smckusick */ 10945748Smckusick 11045748Smckusick #ifdef KERNEL 111*50929Smckusick #define round_page(x) \ 112*50929Smckusick ((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) & ~PAGE_MASK)) 113*50929Smckusick #define trunc_page(x) \ 114*50929Smckusick ((vm_offset_t)(((vm_offset_t)(x)) & ~PAGE_MASK)) 115*50929Smckusick #define num_pages(x) \ 116*50929Smckusick ((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) >> PAGE_SHIFT)) 11745748Smckusick #else KERNEL 118*50929Smckusick #define round_page(x) \ 119*50929Smckusick ((((vm_offset_t)(x) + (vm_page_size - 1)) / vm_page_size) * vm_page_size) 120*50929Smckusick #define trunc_page(x) \ 121*50929Smckusick ((((vm_offset_t)(x)) / vm_page_size) * vm_page_size) 12245748Smckusick #endif KERNEL 12345748Smckusick 12445748Smckusick #ifdef KERNEL 12545748Smckusick extern vm_size_t mem_size; /* size of physical memory (bytes) */ 12645748Smckusick extern vm_offset_t first_addr; /* first physical page */ 12745748Smckusick extern vm_offset_t last_addr; /* last physical page */ 12845748Smckusick #endif KERNEL 12945748Smckusick 13045748Smckusick #endif ASSEMBLER 13145748Smckusick 13245748Smckusick #endif _VM_PARAM_ 133