2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
27 * Mach Operating System
28 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
29 * All Rights Reserved.
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.
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.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
55 * Author: Avadis Tevanian, Jr.
58 * Machine address mapping definitions -- machine-independent
59 * section. [For machine-dependent section, see "machine/pmap.h".]
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>
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.
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(
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 */
108 #ifdef MACH_KERNEL_PRIVATE
110 #include <machine/pmap.h>
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.
119 * These interfaces are tied to the size of the
120 * kernel pmap - and therefore use the "local"
121 * vm_offset_t, etc... types.
124 extern void *pmap_steal_memory(vm_size_t size
);
125 /* During VM initialization,
126 * steal a chunk of memory.
128 extern unsigned int pmap_free_pages(void); /* During VM initialization,
129 * report remaining unused
132 extern void pmap_startup(
135 /* During VM initialization,
136 * use remaining physical pages
137 * to allocate page frames.
139 extern void pmap_init(void); /* Initialization,
144 extern void mapping_adjust(void); /* Adjust free mapping count */
146 extern void mapping_free_prime(void); /* Primes the mapping block release list */
148 #ifndef MACHINE_PAGES
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
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.
165 extern boolean_t
pmap_next_page(ppnum_t
*pnum
);
166 /* During VM initialization,
167 * return the next unused
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.
177 #endif /* MACHINE_PAGES */
180 * Routines to manage the physical map data structure.
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
);
189 extern void pmap_enter( /* Enter a mapping */
197 extern void pmap_remove_some_phys(
203 * Routines that operate on physical addresses.
206 extern void pmap_page_protect( /* Restrict access to page. */
210 extern void (pmap_zero_page
)(
213 extern void (pmap_zero_part_page
)(
218 extern void (pmap_copy_page
)(
222 extern void (pmap_copy_part_page
)(
224 vm_offset_t src_offset
,
226 vm_offset_t dst_offset
,
229 extern void (pmap_copy_part_lpage
)(
232 vm_offset_t dst_offset
,
235 extern void (pmap_copy_part_rpage
)(
237 vm_offset_t src_offset
,
241 extern unsigned int (pmap_disconnect
)( /* disconnect mappings and return reference and change */
244 extern kern_return_t (pmap_attribute_cache_sync
)( /* Flush appropriate
246 * page number sent */
249 vm_machine_attribute_t attribute
,
250 vm_machine_attribute_val_t
* value
);
253 * debug/assertions. pmap_verify_free returns true iff
254 * the given physical page is mapped into no pmap.
256 extern boolean_t
pmap_verify_free(ppnum_t pn
);
259 * Statistics routines
261 extern int (pmap_resident_count
)(pmap_t pmap
);
264 * Sundry required (internal) routines
266 extern void pmap_collect(pmap_t pmap
);/* Perform garbage
267 * collection, if any */
272 extern void (pmap_copy
)( /* Copy range of mappings,
276 vm_map_offset_t dest_va
,
278 vm_map_offset_t source_va
);
280 extern kern_return_t (pmap_attribute
)( /* Get/Set special memory
285 vm_machine_attribute_t attribute
,
286 vm_machine_attribute_val_t
* value
);
289 * Routines defined as macros.
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) { \
298 pmap = (thr)->map->pmap; \
299 if (pmap != pmap_kernel()) \
300 PMAP_ACTIVATE(pmap, (thr), (cpu)); \
302 #endif /* PMAP_ACTIVATE */
303 #endif /* PMAP_ACTIVATE_USER */
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) { \
312 pmap = (thr)->map->pmap; \
313 if ((pmap) != pmap_kernel()) \
314 PMAP_DEACTIVATE(pmap, (thr), (cpu)); \
316 #endif /* PMAP_DEACTIVATE */
317 #endif /* PMAP_DEACTIVATE_USER */
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 */
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 */
339 * Macro to be used in place of pmap_enter()
341 #define PMAP_ENTER(pmap, virtual_address, page, protection, flags, wired) \
343 pmap_t __pmap = (pmap); \
344 vm_page_t __page = (page); \
346 if (__pmap != kernel_pmap) { \
347 ASSERT_PAGE_DECRYPTED(__page); \
352 (protection) & ~__page->page_lock, \
356 #endif /* !PMAP_ENTER */
359 * Routines to manage reference/modify bits based on
360 * physical addresses, simulating them if not provided
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
);
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 */
381 * Routines that operate on ranges of virtual addresses.
383 extern void pmap_protect( /* Change protections. */
389 extern void (pmap_pageable
)(
391 vm_map_offset_t start
,
395 #endif /* MACH_KERNEL_PRIVATE */
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.
403 extern pmap_t kernel_pmap
; /* The kernel's map */
404 #define pmap_kernel() (kernel_pmap)
406 /* machine independent WIMG bits */
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 */
413 #define VM_WIMG_MASK 0xFF
414 #define VM_WIMG_USE_DEFAULT 0x80000000
416 extern void pmap_modify_pages( /* Set modify bit for pages */
421 extern vm_offset_t
pmap_extract(pmap_t pmap
,
424 extern void pmap_change_wiring( /* Specify pageability */
429 /* LP64todo - switch to vm_map_offset_t when it grows */
430 extern void pmap_remove( /* Remove mappings. */
436 #endif /* KERNEL_PRIVATE */
438 #endif /* _VM_PMAP_H_ */