]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/vm_param.h
xnu-517.7.7.tar.gz
[apple/xnu.git] / osfmk / mach / vm_param.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25 /*
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
29 *
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
35 *
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52 /*
53 * File: mach/vm_param.h
54 * Author: Avadis Tevanian, Jr., Michael Wayne Young
55 * Date: 1985
56 *
57 * Machine independent virtual memory parameters.
58 *
59 */
60
61 #ifndef _MACH_VM_PARAM_H_
62 #define _MACH_VM_PARAM_H_
63
64 #ifndef KERNEL_PRIVATE
65
66 #error YOU HAVE MADE A MISTAKE BY INCLUDING THIS FILE;
67 #error
68 #error THIS FILE SHOULD NOT BE VISIBLE TO USER PROGRAMS.
69 #error
70 #error USE <mach/machine/vm_param.h> TO GET MACHINE-DEPENDENT ADDRESS
71 #error SPACE AND PAGE SIZE ITEMS.
72 #error
73 #error USE <mach/machine/vm_types.h> TO GET TYPE DECLARATIONS USED IN
74 #error THE MACH KERNEL INTERFACE.
75 #error
76 #error IN ALL PROBABILITY, YOU SHOULD GET ALL OF THE TYPES USED IN THE
77 #error INTERFACE FROM <mach/mach_types.h>
78
79 #endif /* KERNEL_PRIVATE */
80
81 #include <mach/machine/vm_param.h>
82
83 #ifndef ASSEMBLER
84 #include <mach/vm_types.h>
85 #endif /* ASSEMBLER */
86
87 /*
88 * The machine independent pages are refered to as PAGES. A page
89 * is some number of hardware pages, depending on the target machine.
90 */
91
92 /*
93 * All references to the size of a page should be done with PAGE_SIZE
94 * or PAGE_SHIFT. The fact they are variables is hidden here so that
95 * we can easily make them constant if we so desire.
96 */
97
98 /*
99 * Regardless whether it is implemented with a constant or a variable,
100 * the PAGE_SIZE is assumed to be a power of two throughout the
101 * virtual memory system implementation.
102 */
103
104 #ifdef PAGE_SIZE_FIXED
105 #define PAGE_SIZE 4096
106 #define PAGE_SHIFT 12
107 #define PAGE_MASK (PAGE_SIZE-1)
108 #endif /* PAGE_SIZE_FIXED */
109
110 #ifndef ASSEMBLER
111
112 extern vm_size_t page_size;
113 extern vm_size_t page_mask;
114 extern int page_shift;
115
116 #ifndef PAGE_SIZE_FIXED
117 #define PAGE_SIZE page_size /* pagesize in addr units */
118 #define PAGE_SHIFT page_shift /* number of bits to shift for pages */
119 #define PAGE_MASK page_mask /* mask for off in page */
120
121 #define PAGE_SIZE_64 (unsigned long long)page_size /* pagesize in addr units */
122 #define PAGE_MASK_64 (unsigned long long)page_mask /* mask for off in page */
123 #else /* PAGE_SIZE_FIXED */
124
125 #define PAGE_SIZE_64 (unsigned long long)4096
126 #define PAGE_MASK_64 (PAGE_SIZE_64-1)
127 #endif /* PAGE_SIZE_FIXED */
128
129 /*
130 * Convert addresses to pages and vice versa. No rounding is used.
131 * The atop_32 and ptoa_32 macros should not be use on 64 bit types.
132 * The round_page_64 and trunc_page_64 macros should be used instead.
133 */
134
135 #define atop_32(x) ((uint32_t)(x) >> PAGE_SHIFT)
136 #define ptoa_32(x) ((uint32_t)(x) << PAGE_SHIFT)
137 #define atop_64(x) ((uint64_t)(x) >> PAGE_SHIFT)
138 #define ptoa_64(x) ((uint64_t)(x) << PAGE_SHIFT)
139
140 /*
141 * While the following block is enabled, the legacy atop and ptoa
142 * macros will behave correctly. If not, they will generate
143 * invalid lvalue errors.
144 */
145
146 #if 1
147 #define atop(x) ((uint32_t)(x) >> PAGE_SHIFT)
148 #define ptoa(x) ((uint32_t)(x) << PAGE_SHIFT)
149 #else
150 #define atop(x) (0UL = 0)
151 #define ptoa(x) (0UL = 0)
152 #endif
153
154
155 /*
156 * Round off or truncate to the nearest page. These will work
157 * for either addresses or counts. (i.e. 1 byte rounds to 1 page
158 * bytes. The round_page_32 and trunc_page_32 macros should not be
159 * use on 64 bit types. The round_page_64 and trunc_page_64 macros
160 * should be used instead.
161 */
162
163 #define round_page_32(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
164 #define trunc_page_32(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
165 #define round_page_64(x) (((uint64_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
166 #define trunc_page_64(x) ((uint64_t)(x) & ~((signed)PAGE_MASK))
167
168
169 /*
170 * While the following block is enabled, the legacy round_page
171 * and trunc_page macros will behave correctly. If not, they will
172 * generate invalid lvalue errors.
173 */
174
175 #if 1
176 #define round_page(x) (((uint32_t)(x) + PAGE_MASK) & ~((signed)PAGE_MASK))
177 #define trunc_page(x) ((uint32_t)(x) & ~((signed)PAGE_MASK))
178 #else
179 #define round_page(x) (0UL = 0)
180 #define trunc_page(x) (0UL = 0)
181 #endif
182
183 /*
184 * Enable the following block to find uses of xxx_32 macros that should
185 * be xxx_64. These macros only work in C code, not C++. The resulting
186 * binaries are not functional. Look for invalid lvalue errors in
187 * the compiler output.
188 *
189 * Enabling the following block will also find use of the xxx_64 macros
190 * that have been passed pointers. The parameters should be case to an
191 * unsigned long type first. Look for invalid operands to binary + error
192 * in the compiler output.
193 */
194
195 #if 0
196 #undef atop_32
197 #undef ptoa_32
198 #undef round_page_32
199 #undef trunc_page_32
200 #undef atop_64
201 #undef ptoa_64
202 #undef round_page_64
203 #undef trunc_page_64
204
205 #ifndef __cplusplus
206
207 #define atop_32(x) \
208 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
209 (*(long *)0), \
210 (0UL)) = 0)
211
212 #define ptoa_32(x) \
213 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
214 (*(long *)0), \
215 (0UL)) = 0)
216
217 #define round_page_32(x) \
218 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
219 (*(long *)0), \
220 (0UL)) = 0)
221
222 #define trunc_page_32(x) \
223 (__builtin_choose_expr (sizeof(x) != sizeof(uint64_t), \
224 (*(long *)0), \
225 (0UL)) = 0)
226 #else
227
228 #define atop_32(x) (0)
229 #define ptoa_32(x) (0)
230 #define round_page_32(x) (0)
231 #define trunc_page_32(x) (0)
232
233 #endif /* ! __cplusplus */
234
235 #define atop_64(x) ((uint64_t)((x) + (uint8_t *)0))
236 #define ptoa_64(x) ((uint64_t)((x) + (uint8_t *)0))
237 #define round_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
238 #define trunc_page_64(x) ((uint64_t)((x) + (uint8_t *)0))
239
240 #endif
241
242 /*
243 * Determine whether an address is page-aligned, or a count is
244 * an exact page multiple.
245 */
246
247 #define page_aligned(x) ((((vm_object_offset_t) (x)) & PAGE_MASK) == 0)
248
249 extern vm_size_t mem_size; /* 32-bit size of memory - limited by maxmem - deprecated */
250 extern uint64_t max_mem; /* 64-bit size of memory - limited by maxmem */
251 extern uint64_t mem_actual; /* 64-bit size of memory - not limited by maxmem */
252 extern uint64_t sane_size; /* Memory size to use for defaults calculations */
253 extern addr64_t vm_last_addr; /* Highest kernel virtual address known to the VM system */
254
255 /* We need a way to get rid of compiler warnings when we cast from */
256 /* a 64 bit value to an address that is 32 bits. */
257 /* We know at this point the cast is harmless but sometime in */
258 /* the future it may not be. */
259 /* When size of an int is no longer equal to size of uintptr_t then */
260 /* the compile will fail and we know we need to fix our cast. */
261 #include <stdint.h>
262 #ifndef __CAST_DOWN_CHECK
263 #define __CAST_DOWN_CHECK
264 typedef char __NEED_TO_CHANGE_CAST_DOWN[ sizeof(uintptr_t) == sizeof(int) ? 0 : -1 ];
265 #define CAST_DOWN( type, addr ) ( ((type)((uintptr_t) (addr))) )
266 #endif /* __CAST_DOWN_CHECK */
267
268 #endif /* ASSEMBLER */
269 #endif /* _MACH_VM_PARAM_H_ */