1df8bae1dSRodney W. Grimes /* 2df8bae1dSRodney W. Grimes * Copyright (c) 1991, 1993 3df8bae1dSRodney W. Grimes * The Regents of the University of California. All rights reserved. 4df8bae1dSRodney W. Grimes * 5df8bae1dSRodney W. Grimes * This code is derived from software contributed to Berkeley by 6df8bae1dSRodney W. Grimes * The Mach Operating System project at Carnegie-Mellon University. 7df8bae1dSRodney W. Grimes * 8df8bae1dSRodney W. Grimes * Redistribution and use in source and binary forms, with or without 9df8bae1dSRodney W. Grimes * modification, are permitted provided that the following conditions 10df8bae1dSRodney W. Grimes * are met: 11df8bae1dSRodney W. Grimes * 1. Redistributions of source code must retain the above copyright 12df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer. 13df8bae1dSRodney W. Grimes * 2. Redistributions in binary form must reproduce the above copyright 14df8bae1dSRodney W. Grimes * notice, this list of conditions and the following disclaimer in the 15df8bae1dSRodney W. Grimes * documentation and/or other materials provided with the distribution. 16df8bae1dSRodney W. Grimes * 3. All advertising materials mentioning features or use of this software 17df8bae1dSRodney W. Grimes * must display the following acknowledgement: 18df8bae1dSRodney W. Grimes * This product includes software developed by the University of 19df8bae1dSRodney W. Grimes * California, Berkeley and its contributors. 20df8bae1dSRodney W. Grimes * 4. Neither the name of the University nor the names of its contributors 21df8bae1dSRodney W. Grimes * may be used to endorse or promote products derived from this software 22df8bae1dSRodney W. Grimes * without specific prior written permission. 23df8bae1dSRodney W. Grimes * 24df8bae1dSRodney W. Grimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25df8bae1dSRodney W. Grimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26df8bae1dSRodney W. Grimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27df8bae1dSRodney W. Grimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28df8bae1dSRodney W. Grimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29df8bae1dSRodney W. Grimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30df8bae1dSRodney W. Grimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31df8bae1dSRodney W. Grimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32df8bae1dSRodney W. Grimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33df8bae1dSRodney W. Grimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34df8bae1dSRodney W. Grimes * SUCH DAMAGE. 35df8bae1dSRodney W. Grimes * 36df8bae1dSRodney W. Grimes * @(#)vm_param.h 8.1 (Berkeley) 6/11/93 37df8bae1dSRodney W. Grimes * 38df8bae1dSRodney W. Grimes * 39df8bae1dSRodney W. Grimes * Copyright (c) 1987, 1990 Carnegie-Mellon University. 40df8bae1dSRodney W. Grimes * All rights reserved. 41df8bae1dSRodney W. Grimes * 42df8bae1dSRodney W. Grimes * Authors: Avadis Tevanian, Jr., Michael Wayne Young 43df8bae1dSRodney W. Grimes * 44df8bae1dSRodney W. Grimes * Permission to use, copy, modify and distribute this software and 45df8bae1dSRodney W. Grimes * its documentation is hereby granted, provided that both the copyright 46df8bae1dSRodney W. Grimes * notice and this permission notice appear in all copies of the 47df8bae1dSRodney W. Grimes * software, derivative works or modified versions, and any portions 48df8bae1dSRodney W. Grimes * thereof, and that both notices appear in supporting documentation. 49df8bae1dSRodney W. Grimes * 50df8bae1dSRodney W. Grimes * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 51df8bae1dSRodney W. Grimes * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 52df8bae1dSRodney W. Grimes * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 53df8bae1dSRodney W. Grimes * 54df8bae1dSRodney W. Grimes * Carnegie Mellon requests users of this software to return to 55df8bae1dSRodney W. Grimes * 56df8bae1dSRodney W. Grimes * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 57df8bae1dSRodney W. Grimes * School of Computer Science 58df8bae1dSRodney W. Grimes * Carnegie Mellon University 59df8bae1dSRodney W. Grimes * Pittsburgh PA 15213-3890 60df8bae1dSRodney W. Grimes * 61df8bae1dSRodney W. Grimes * any improvements or extensions that they make and grant Carnegie the 62df8bae1dSRodney W. Grimes * rights to redistribute these changes. 63df8bae1dSRodney W. Grimes */ 64df8bae1dSRodney W. Grimes 65df8bae1dSRodney W. Grimes /* 66df8bae1dSRodney W. Grimes * Machine independent virtual memory parameters. 67df8bae1dSRodney W. Grimes */ 68df8bae1dSRodney W. Grimes 69df8bae1dSRodney W. Grimes #ifndef _VM_PARAM_ 70df8bae1dSRodney W. Grimes #define _VM_PARAM_ 71df8bae1dSRodney W. Grimes 72df8bae1dSRodney W. Grimes #include <machine/vmparam.h> 73df8bae1dSRodney W. Grimes 74df8bae1dSRodney W. Grimes /* 75df8bae1dSRodney W. Grimes * This belongs in types.h, but breaks too many existing programs. 76df8bae1dSRodney W. Grimes */ 77df8bae1dSRodney W. Grimes typedef int boolean_t; 78df8bae1dSRodney W. Grimes #define TRUE 1 79df8bae1dSRodney W. Grimes #define FALSE 0 80df8bae1dSRodney W. Grimes 81df8bae1dSRodney W. Grimes /* 82df8bae1dSRodney W. Grimes * The machine independent pages are refered to as PAGES. A page 83df8bae1dSRodney W. Grimes * is some number of hardware pages, depending on the target machine. 84df8bae1dSRodney W. Grimes */ 85df8bae1dSRodney W. Grimes #define DEFAULT_PAGE_SIZE 4096 86df8bae1dSRodney W. Grimes 87df8bae1dSRodney W. Grimes /* 88df8bae1dSRodney W. Grimes * All references to the size of a page should be done with PAGE_SIZE 89df8bae1dSRodney W. Grimes * or PAGE_SHIFT. The fact they are variables is hidden here so that 90df8bae1dSRodney W. Grimes * we can easily make them constant if we so desire. 91df8bae1dSRodney W. Grimes */ 92df8bae1dSRodney W. Grimes #define PAGE_SIZE cnt.v_page_size /* size of page */ 93df8bae1dSRodney W. Grimes #define PAGE_MASK page_mask /* size of page - 1 */ 94df8bae1dSRodney W. Grimes #define PAGE_SHIFT page_shift /* bits to shift for pages */ 95df8bae1dSRodney W. Grimes #ifdef KERNEL 96df8bae1dSRodney W. Grimes extern vm_size_t page_mask; 97df8bae1dSRodney W. Grimes extern int page_shift; 98df8bae1dSRodney W. Grimes #endif 99df8bae1dSRodney W. Grimes 100df8bae1dSRodney W. Grimes /* 101df8bae1dSRodney W. Grimes * CTL_VM identifiers 102df8bae1dSRodney W. Grimes */ 103df8bae1dSRodney W. Grimes #define VM_METER 1 /* struct vmmeter */ 104df8bae1dSRodney W. Grimes #define VM_LOADAVG 2 /* struct loadavg */ 105df8bae1dSRodney W. Grimes #define VM_MAXID 3 /* number of valid vm ids */ 106df8bae1dSRodney W. Grimes 107df8bae1dSRodney W. Grimes #define CTL_VM_NAMES { \ 108df8bae1dSRodney W. Grimes { 0, 0 }, \ 109df8bae1dSRodney W. Grimes { "vmmeter", CTLTYPE_STRUCT }, \ 110df8bae1dSRodney W. Grimes { "loadavg", CTLTYPE_STRUCT }, \ 111df8bae1dSRodney W. Grimes } 112df8bae1dSRodney W. Grimes 113df8bae1dSRodney W. Grimes /* 114df8bae1dSRodney W. Grimes * Return values from the VM routines. 115df8bae1dSRodney W. Grimes */ 116df8bae1dSRodney W. Grimes #define KERN_SUCCESS 0 117df8bae1dSRodney W. Grimes #define KERN_INVALID_ADDRESS 1 118df8bae1dSRodney W. Grimes #define KERN_PROTECTION_FAILURE 2 119df8bae1dSRodney W. Grimes #define KERN_NO_SPACE 3 120df8bae1dSRodney W. Grimes #define KERN_INVALID_ARGUMENT 4 121df8bae1dSRodney W. Grimes #define KERN_FAILURE 5 122df8bae1dSRodney W. Grimes #define KERN_RESOURCE_SHORTAGE 6 123df8bae1dSRodney W. Grimes #define KERN_NOT_RECEIVER 7 124df8bae1dSRodney W. Grimes #define KERN_NO_ACCESS 8 125df8bae1dSRodney W. Grimes 126df8bae1dSRodney W. Grimes #ifndef ASSEMBLER 127df8bae1dSRodney W. Grimes /* 128df8bae1dSRodney W. Grimes * Convert addresses to pages and vice versa. 129df8bae1dSRodney W. Grimes * No rounding is used. 130df8bae1dSRodney W. Grimes */ 131df8bae1dSRodney W. Grimes #ifdef KERNEL 132df8bae1dSRodney W. Grimes #define atop(x) (((unsigned)(x)) >> PAGE_SHIFT) 133df8bae1dSRodney W. Grimes #define ptoa(x) ((vm_offset_t)((x) << PAGE_SHIFT)) 134df8bae1dSRodney W. Grimes 135df8bae1dSRodney W. Grimes /* 136df8bae1dSRodney W. Grimes * Round off or truncate to the nearest page. These will work 137df8bae1dSRodney W. Grimes * for either addresses or counts (i.e., 1 byte rounds to 1 page). 138df8bae1dSRodney W. Grimes */ 139df8bae1dSRodney W. Grimes #define round_page(x) \ 140df8bae1dSRodney W. Grimes ((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) & ~PAGE_MASK)) 141df8bae1dSRodney W. Grimes #define trunc_page(x) \ 142df8bae1dSRodney W. Grimes ((vm_offset_t)(((vm_offset_t)(x)) & ~PAGE_MASK)) 143df8bae1dSRodney W. Grimes #define num_pages(x) \ 144df8bae1dSRodney W. Grimes ((vm_offset_t)((((vm_offset_t)(x)) + PAGE_MASK) >> PAGE_SHIFT)) 145df8bae1dSRodney W. Grimes 146df8bae1dSRodney W. Grimes extern vm_size_t mem_size; /* size of physical memory (bytes) */ 147df8bae1dSRodney W. Grimes extern vm_offset_t first_addr; /* first physical page */ 148df8bae1dSRodney W. Grimes extern vm_offset_t last_addr; /* last physical page */ 149df8bae1dSRodney W. Grimes 150df8bae1dSRodney W. Grimes #else 151df8bae1dSRodney W. Grimes /* out-of-kernel versions of round_page and trunc_page */ 152df8bae1dSRodney W. Grimes #define round_page(x) \ 153df8bae1dSRodney W. Grimes ((((vm_offset_t)(x) + (vm_page_size - 1)) / vm_page_size) * vm_page_size) 154df8bae1dSRodney W. Grimes #define trunc_page(x) \ 155df8bae1dSRodney W. Grimes ((((vm_offset_t)(x)) / vm_page_size) * vm_page_size) 156df8bae1dSRodney W. Grimes 157df8bae1dSRodney W. Grimes #endif /* KERNEL */ 158df8bae1dSRodney W. Grimes #endif /* ASSEMBLER */ 159df8bae1dSRodney W. Grimes #endif /* _VM_PARAM_ */ 160