]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/pmap.h
xnu-792.6.56.tar.gz
[apple/xnu.git] / osfmk / vm / pmap.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23 /*
24 * @OSF_COPYRIGHT@
25 */
26 /*
27 * Mach Operating System
28 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
29 * All Rights Reserved.
30 *
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
36 *
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 *
41 * Carnegie Mellon requests users of this software to return to
42 *
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
47 *
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
50 */
51 /*
52 */
53 /*
54 * File: vm/pmap.h
55 * Author: Avadis Tevanian, Jr.
56 * Date: 1985
57 *
58 * Machine address mapping definitions -- machine-independent
59 * section. [For machine-dependent section, see "machine/pmap.h".]
60 */
61
62 #ifndef _VM_PMAP_H_
63 #define _VM_PMAP_H_
64
65 #include <mach/kern_return.h>
66 #include <mach/vm_param.h>
67 #include <mach/vm_types.h>
68 #include <mach/vm_attributes.h>
69 #include <mach/boolean.h>
70 #include <mach/vm_prot.h>
71
72 #ifdef KERNEL_PRIVATE
73
74 /*
75 * The following is a description of the interface to the
76 * machine-dependent "physical map" data structure. The module
77 * must provide a "pmap_t" data type that represents the
78 * set of valid virtual-to-physical addresses for one user
79 * address space. [The kernel address space is represented
80 * by a distinguished "pmap_t".] The routines described manage
81 * this type, install and update virtual-to-physical mappings,
82 * and perform operations on physical addresses common to
83 * many address spaces.
84 */
85
86 /* Copy between a physical page and a virtual address */
87 /* LP64todo - switch to vm_map_offset_t when it grows */
88 extern kern_return_t copypv(
89 addr64_t source,
90 addr64_t sink,
91 unsigned int size,
92 int which);
93 #define cppvPsnk 1
94 #define cppvPsnkb 31
95 #define cppvPsrc 2
96 #define cppvPsrcb 30
97 #define cppvFsnk 4
98 #define cppvFsnkb 29
99 #define cppvFsrc 8
100 #define cppvFsrcb 28
101 #define cppvNoModSnk 16
102 #define cppvNoModSnkb 27
103 #define cppvNoRefSrc 32
104 #define cppvNoRefSrcb 26
105 #define cppvKmap 64 /* Use the kernel's vm_map */
106 #define cppvKmapb 25
107
108 #ifdef MACH_KERNEL_PRIVATE
109
110 #include <machine/pmap.h>
111
112 /*
113 * Routines used for initialization.
114 * There is traditionally also a pmap_bootstrap,
115 * used very early by machine-dependent code,
116 * but it is not part of the interface.
117 *
118 * LP64todo -
119 * These interfaces are tied to the size of the
120 * kernel pmap - and therefore use the "local"
121 * vm_offset_t, etc... types.
122 */
123
124 extern void *pmap_steal_memory(vm_size_t size);
125 /* During VM initialization,
126 * steal a chunk of memory.
127 */
128 extern unsigned int pmap_free_pages(void); /* During VM initialization,
129 * report remaining unused
130 * physical pages.
131 */
132 extern void pmap_startup(
133 vm_offset_t *startp,
134 vm_offset_t *endp);
135 /* During VM initialization,
136 * use remaining physical pages
137 * to allocate page frames.
138 */
139 extern void pmap_init(void); /* Initialization,
140 * after kernel runs
141 * in virtual memory.
142 */
143
144 extern void mapping_adjust(void); /* Adjust free mapping count */
145
146 extern void mapping_free_prime(void); /* Primes the mapping block release list */
147
148 #ifndef MACHINE_PAGES
149 /*
150 * If machine/pmap.h defines MACHINE_PAGES, it must implement
151 * the above functions. The pmap module has complete control.
152 * Otherwise, it must implement
153 * pmap_free_pages
154 * pmap_virtual_space
155 * pmap_next_page
156 * pmap_init
157 * and vm/vm_resident.c implements pmap_steal_memory and pmap_startup
158 * using pmap_free_pages, pmap_next_page, pmap_virtual_space,
159 * and pmap_enter. pmap_free_pages may over-estimate the number
160 * of unused physical pages, and pmap_next_page may return FALSE
161 * to indicate that there are no more unused pages to return.
162 * However, for best performance pmap_free_pages should be accurate.
163 */
164
165 extern boolean_t pmap_next_page(ppnum_t *pnum);
166 /* During VM initialization,
167 * return the next unused
168 * physical page.
169 */
170 extern void pmap_virtual_space(
171 vm_offset_t *virtual_start,
172 vm_offset_t *virtual_end);
173 /* During VM initialization,
174 * report virtual space
175 * available for the kernel.
176 */
177 #endif /* MACHINE_PAGES */
178
179 /*
180 * Routines to manage the physical map data structure.
181 */
182 extern pmap_t pmap_create(vm_map_size_t size); /* Create a pmap_t. */
183 extern pmap_t (pmap_kernel)(void); /* Return the kernel's pmap */
184 extern void pmap_reference(pmap_t pmap); /* Gain a reference. */
185 extern void pmap_destroy(pmap_t pmap); /* Release a reference. */
186 extern void pmap_switch(pmap_t);
187
188
189 extern void pmap_enter( /* Enter a mapping */
190 pmap_t pmap,
191 vm_map_offset_t v,
192 ppnum_t pn,
193 vm_prot_t prot,
194 unsigned int flags,
195 boolean_t wired);
196
197 extern void pmap_remove_some_phys(
198 pmap_t pmap,
199 ppnum_t pn);
200
201
202 /*
203 * Routines that operate on physical addresses.
204 */
205
206 extern void pmap_page_protect( /* Restrict access to page. */
207 ppnum_t phys,
208 vm_prot_t prot);
209
210 extern void (pmap_zero_page)(
211 ppnum_t pn);
212
213 extern void (pmap_zero_part_page)(
214 ppnum_t pn,
215 vm_offset_t offset,
216 vm_size_t len);
217
218 extern void (pmap_copy_page)(
219 ppnum_t src,
220 ppnum_t dest);
221
222 extern void (pmap_copy_part_page)(
223 ppnum_t src,
224 vm_offset_t src_offset,
225 ppnum_t dst,
226 vm_offset_t dst_offset,
227 vm_size_t len);
228
229 extern void (pmap_copy_part_lpage)(
230 vm_offset_t src,
231 ppnum_t dst,
232 vm_offset_t dst_offset,
233 vm_size_t len);
234
235 extern void (pmap_copy_part_rpage)(
236 ppnum_t src,
237 vm_offset_t src_offset,
238 vm_offset_t dst,
239 vm_size_t len);
240
241 extern unsigned int (pmap_disconnect)( /* disconnect mappings and return reference and change */
242 ppnum_t phys);
243
244 extern kern_return_t (pmap_attribute_cache_sync)( /* Flush appropriate
245 * cache based on
246 * page number sent */
247 ppnum_t pn,
248 vm_size_t size,
249 vm_machine_attribute_t attribute,
250 vm_machine_attribute_val_t* value);
251
252 /*
253 * debug/assertions. pmap_verify_free returns true iff
254 * the given physical page is mapped into no pmap.
255 */
256 extern boolean_t pmap_verify_free(ppnum_t pn);
257
258 /*
259 * Statistics routines
260 */
261 extern int (pmap_resident_count)(pmap_t pmap);
262
263 /*
264 * Sundry required (internal) routines
265 */
266 extern void pmap_collect(pmap_t pmap);/* Perform garbage
267 * collection, if any */
268
269 /*
270 * Optional routines
271 */
272 extern void (pmap_copy)( /* Copy range of mappings,
273 * if desired. */
274 pmap_t dest,
275 pmap_t source,
276 vm_map_offset_t dest_va,
277 vm_map_size_t size,
278 vm_map_offset_t source_va);
279
280 extern kern_return_t (pmap_attribute)( /* Get/Set special memory
281 * attributes */
282 pmap_t pmap,
283 vm_map_offset_t va,
284 vm_map_size_t size,
285 vm_machine_attribute_t attribute,
286 vm_machine_attribute_val_t* value);
287
288 /*
289 * Routines defined as macros.
290 */
291 #ifndef PMAP_ACTIVATE_USER
292 #ifndef PMAP_ACTIVATE
293 #define PMAP_ACTIVATE_USER(thr, cpu)
294 #else /* PMAP_ACTIVATE */
295 #define PMAP_ACTIVATE_USER(thr, cpu) { \
296 pmap_t pmap; \
297 \
298 pmap = (thr)->map->pmap; \
299 if (pmap != pmap_kernel()) \
300 PMAP_ACTIVATE(pmap, (thr), (cpu)); \
301 }
302 #endif /* PMAP_ACTIVATE */
303 #endif /* PMAP_ACTIVATE_USER */
304
305 #ifndef PMAP_DEACTIVATE_USER
306 #ifndef PMAP_DEACTIVATE
307 #define PMAP_DEACTIVATE_USER(thr, cpu)
308 #else /* PMAP_DEACTIVATE */
309 #define PMAP_DEACTIVATE_USER(thr, cpu) { \
310 pmap_t pmap; \
311 \
312 pmap = (thr)->map->pmap; \
313 if ((pmap) != pmap_kernel()) \
314 PMAP_DEACTIVATE(pmap, (thr), (cpu)); \
315 }
316 #endif /* PMAP_DEACTIVATE */
317 #endif /* PMAP_DEACTIVATE_USER */
318
319 #ifndef PMAP_ACTIVATE_KERNEL
320 #ifndef PMAP_ACTIVATE
321 #define PMAP_ACTIVATE_KERNEL(cpu)
322 #else /* PMAP_ACTIVATE */
323 #define PMAP_ACTIVATE_KERNEL(cpu) \
324 PMAP_ACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
325 #endif /* PMAP_ACTIVATE */
326 #endif /* PMAP_ACTIVATE_KERNEL */
327
328 #ifndef PMAP_DEACTIVATE_KERNEL
329 #ifndef PMAP_DEACTIVATE
330 #define PMAP_DEACTIVATE_KERNEL(cpu)
331 #else /* PMAP_DEACTIVATE */
332 #define PMAP_DEACTIVATE_KERNEL(cpu) \
333 PMAP_DEACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
334 #endif /* PMAP_DEACTIVATE */
335 #endif /* PMAP_DEACTIVATE_KERNEL */
336
337 #ifndef PMAP_ENTER
338 /*
339 * Macro to be used in place of pmap_enter()
340 */
341 #define PMAP_ENTER(pmap, virtual_address, page, protection, flags, wired) \
342 MACRO_BEGIN \
343 pmap_t __pmap = (pmap); \
344 vm_page_t __page = (page); \
345 \
346 if (__pmap != kernel_pmap) { \
347 ASSERT_PAGE_DECRYPTED(__page); \
348 } \
349 pmap_enter(__pmap, \
350 (virtual_address), \
351 __page->phys_page, \
352 (protection) & ~__page->page_lock, \
353 (flags), \
354 (wired)); \
355 MACRO_END
356 #endif /* !PMAP_ENTER */
357
358 /*
359 * Routines to manage reference/modify bits based on
360 * physical addresses, simulating them if not provided
361 * by the hardware.
362 */
363 /* Clear reference bit */
364 extern void pmap_clear_reference(ppnum_t pn);
365 /* Return reference bit */
366 extern boolean_t (pmap_is_referenced)(ppnum_t pn);
367 /* Set modify bit */
368 extern void pmap_set_modify(ppnum_t pn);
369 /* Clear modify bit */
370 extern void pmap_clear_modify(ppnum_t pn);
371 /* Return modify bit */
372 extern boolean_t pmap_is_modified(ppnum_t pn);
373 /* Return modified and referenced bits */
374 extern unsigned int pmap_get_refmod(ppnum_t pn);
375 /* Clear modified and referenced bits */
376 extern void pmap_clear_refmod(ppnum_t pn, unsigned int mask);
377 #define VM_MEM_MODIFIED 0x01 /* Modified bit */
378 #define VM_MEM_REFERENCED 0x02 /* Referenced bit */
379
380 /*
381 * Routines that operate on ranges of virtual addresses.
382 */
383 extern void pmap_protect( /* Change protections. */
384 pmap_t map,
385 vm_map_offset_t s,
386 vm_map_offset_t e,
387 vm_prot_t prot);
388
389 extern void (pmap_pageable)(
390 pmap_t pmap,
391 vm_map_offset_t start,
392 vm_map_offset_t end,
393 boolean_t pageable);
394
395 #endif /* MACH_KERNEL_PRIVATE */
396
397 /*
398 * JMM - This portion is exported to other kernel components right now,
399 * but will be pulled back in the future when the needed functionality
400 * is provided in a cleaner manner.
401 */
402
403 extern pmap_t kernel_pmap; /* The kernel's map */
404 #define pmap_kernel() (kernel_pmap)
405
406 /* machine independent WIMG bits */
407
408 #define VM_MEM_GUARDED 0x1 /* (G) Guarded Storage */
409 #define VM_MEM_COHERENT 0x2 /* (M) Memory Coherency */
410 #define VM_MEM_NOT_CACHEABLE 0x4 /* (I) Cache Inhibit */
411 #define VM_MEM_WRITE_THROUGH 0x8 /* (W) Write-Through */
412
413 #define VM_WIMG_MASK 0xFF
414 #define VM_WIMG_USE_DEFAULT 0x80000000
415
416 extern void pmap_modify_pages( /* Set modify bit for pages */
417 pmap_t map,
418 vm_map_offset_t s,
419 vm_map_offset_t e);
420
421 extern vm_offset_t pmap_extract(pmap_t pmap,
422 vm_map_offset_t va);
423
424 extern void pmap_change_wiring( /* Specify pageability */
425 pmap_t pmap,
426 vm_map_offset_t va,
427 boolean_t wired);
428
429 /* LP64todo - switch to vm_map_offset_t when it grows */
430 extern void pmap_remove( /* Remove mappings. */
431 pmap_t map,
432 addr64_t s,
433 addr64_t e);
434
435
436 #endif /* KERNEL_PRIVATE */
437
438 #endif /* _VM_PMAP_H_ */