2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
62 * Author: Avadis Tevanian, Jr.
65 * Machine address mapping definitions -- machine-independent
66 * section. [For machine-dependent section, see "machine/pmap.h".]
72 #include <mach/kern_return.h>
73 #include <mach/vm_param.h>
74 #include <mach/vm_types.h>
75 #include <mach/vm_attributes.h>
76 #include <mach/boolean.h>
77 #include <mach/vm_prot.h>
82 * The following is a description of the interface to the
83 * machine-dependent "physical map" data structure. The module
84 * must provide a "pmap_t" data type that represents the
85 * set of valid virtual-to-physical addresses for one user
86 * address space. [The kernel address space is represented
87 * by a distinguished "pmap_t".] The routines described manage
88 * this type, install and update virtual-to-physical mappings,
89 * and perform operations on physical addresses common to
90 * many address spaces.
93 /* Copy between a physical page and a virtual address */
94 /* LP64todo - switch to vm_map_offset_t when it grows */
95 extern kern_return_t
copypv(
108 #define cppvNoModSnk 16
109 #define cppvNoModSnkb 27
110 #define cppvNoRefSrc 32
111 #define cppvNoRefSrcb 26
112 #define cppvKmap 64 /* Use the kernel's vm_map */
115 #ifdef MACH_KERNEL_PRIVATE
117 #include <machine/pmap.h>
120 * Routines used for initialization.
121 * There is traditionally also a pmap_bootstrap,
122 * used very early by machine-dependent code,
123 * but it is not part of the interface.
126 * These interfaces are tied to the size of the
127 * kernel pmap - and therefore use the "local"
128 * vm_offset_t, etc... types.
131 extern void *pmap_steal_memory(vm_size_t size
);
132 /* During VM initialization,
133 * steal a chunk of memory.
135 extern unsigned int pmap_free_pages(void); /* During VM initialization,
136 * report remaining unused
139 extern void pmap_startup(
142 /* During VM initialization,
143 * use remaining physical pages
144 * to allocate page frames.
146 extern void pmap_init(void); /* Initialization,
151 extern void mapping_adjust(void); /* Adjust free mapping count */
153 extern void mapping_free_prime(void); /* Primes the mapping block release list */
155 #ifndef MACHINE_PAGES
157 * If machine/pmap.h defines MACHINE_PAGES, it must implement
158 * the above functions. The pmap module has complete control.
159 * Otherwise, it must implement
164 * and vm/vm_resident.c implements pmap_steal_memory and pmap_startup
165 * using pmap_free_pages, pmap_next_page, pmap_virtual_space,
166 * and pmap_enter. pmap_free_pages may over-estimate the number
167 * of unused physical pages, and pmap_next_page may return FALSE
168 * to indicate that there are no more unused pages to return.
169 * However, for best performance pmap_free_pages should be accurate.
172 extern boolean_t
pmap_next_page(ppnum_t
*pnum
);
173 /* During VM initialization,
174 * return the next unused
177 extern void pmap_virtual_space(
178 vm_offset_t
*virtual_start
,
179 vm_offset_t
*virtual_end
);
180 /* During VM initialization,
181 * report virtual space
182 * available for the kernel.
184 #endif /* MACHINE_PAGES */
187 * Routines to manage the physical map data structure.
189 extern pmap_t
pmap_create( /* Create a pmap_t. */
192 extern pmap_t (pmap_kernel
)(void); /* Return the kernel's pmap */
193 extern void pmap_reference(pmap_t pmap
); /* Gain a reference. */
194 extern void pmap_destroy(pmap_t pmap
); /* Release a reference. */
195 extern void pmap_switch(pmap_t
);
198 extern void pmap_enter( /* Enter a mapping */
206 extern void pmap_remove_some_phys(
212 * Routines that operate on physical addresses.
215 extern void pmap_page_protect( /* Restrict access to page. */
219 extern void (pmap_zero_page
)(
222 extern void (pmap_zero_part_page
)(
227 extern void (pmap_copy_page
)(
231 extern void (pmap_copy_part_page
)(
233 vm_offset_t src_offset
,
235 vm_offset_t dst_offset
,
238 extern void (pmap_copy_part_lpage
)(
241 vm_offset_t dst_offset
,
244 extern void (pmap_copy_part_rpage
)(
246 vm_offset_t src_offset
,
250 extern unsigned int (pmap_disconnect
)( /* disconnect mappings and return reference and change */
253 extern kern_return_t (pmap_attribute_cache_sync
)( /* Flush appropriate
255 * page number sent */
258 vm_machine_attribute_t attribute
,
259 vm_machine_attribute_val_t
* value
);
261 extern unsigned int (pmap_cache_attributes
)(
265 * debug/assertions. pmap_verify_free returns true iff
266 * the given physical page is mapped into no pmap.
268 extern boolean_t
pmap_verify_free(ppnum_t pn
);
271 * Statistics routines
273 extern int (pmap_resident_count
)(pmap_t pmap
);
276 * Sundry required (internal) routines
278 extern void pmap_collect(pmap_t pmap
);/* Perform garbage
279 * collection, if any */
284 extern void (pmap_copy
)( /* Copy range of mappings,
288 vm_map_offset_t dest_va
,
290 vm_map_offset_t source_va
);
292 extern kern_return_t (pmap_attribute
)( /* Get/Set special memory
297 vm_machine_attribute_t attribute
,
298 vm_machine_attribute_val_t
* value
);
301 * Routines defined as macros.
303 #ifndef PMAP_ACTIVATE_USER
304 #ifndef PMAP_ACTIVATE
305 #define PMAP_ACTIVATE_USER(thr, cpu)
306 #else /* PMAP_ACTIVATE */
307 #define PMAP_ACTIVATE_USER(thr, cpu) { \
310 pmap = (thr)->map->pmap; \
311 if (pmap != pmap_kernel()) \
312 PMAP_ACTIVATE(pmap, (thr), (cpu)); \
314 #endif /* PMAP_ACTIVATE */
315 #endif /* PMAP_ACTIVATE_USER */
317 #ifndef PMAP_DEACTIVATE_USER
318 #ifndef PMAP_DEACTIVATE
319 #define PMAP_DEACTIVATE_USER(thr, cpu)
320 #else /* PMAP_DEACTIVATE */
321 #define PMAP_DEACTIVATE_USER(thr, cpu) { \
324 pmap = (thr)->map->pmap; \
325 if ((pmap) != pmap_kernel()) \
326 PMAP_DEACTIVATE(pmap, (thr), (cpu)); \
328 #endif /* PMAP_DEACTIVATE */
329 #endif /* PMAP_DEACTIVATE_USER */
331 #ifndef PMAP_ACTIVATE_KERNEL
332 #ifndef PMAP_ACTIVATE
333 #define PMAP_ACTIVATE_KERNEL(cpu)
334 #else /* PMAP_ACTIVATE */
335 #define PMAP_ACTIVATE_KERNEL(cpu) \
336 PMAP_ACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
337 #endif /* PMAP_ACTIVATE */
338 #endif /* PMAP_ACTIVATE_KERNEL */
340 #ifndef PMAP_DEACTIVATE_KERNEL
341 #ifndef PMAP_DEACTIVATE
342 #define PMAP_DEACTIVATE_KERNEL(cpu)
343 #else /* PMAP_DEACTIVATE */
344 #define PMAP_DEACTIVATE_KERNEL(cpu) \
345 PMAP_DEACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
346 #endif /* PMAP_DEACTIVATE */
347 #endif /* PMAP_DEACTIVATE_KERNEL */
351 * Macro to be used in place of pmap_enter()
353 #define PMAP_ENTER(pmap, virtual_address, page, protection, flags, wired) \
355 pmap_t __pmap = (pmap); \
356 vm_page_t __page = (page); \
358 if (__pmap != kernel_pmap) { \
359 ASSERT_PAGE_DECRYPTED(__page); \
364 (protection) & ~__page->page_lock, \
368 #endif /* !PMAP_ENTER */
371 * Routines to manage reference/modify bits based on
372 * physical addresses, simulating them if not provided
375 /* Clear reference bit */
376 extern void pmap_clear_reference(ppnum_t pn
);
377 /* Return reference bit */
378 extern boolean_t (pmap_is_referenced
)(ppnum_t pn
);
380 extern void pmap_set_modify(ppnum_t pn
);
381 /* Clear modify bit */
382 extern void pmap_clear_modify(ppnum_t pn
);
383 /* Return modify bit */
384 extern boolean_t
pmap_is_modified(ppnum_t pn
);
385 /* Return modified and referenced bits */
386 extern unsigned int pmap_get_refmod(ppnum_t pn
);
387 /* Clear modified and referenced bits */
388 extern void pmap_clear_refmod(ppnum_t pn
, unsigned int mask
);
389 #define VM_MEM_MODIFIED 0x01 /* Modified bit */
390 #define VM_MEM_REFERENCED 0x02 /* Referenced bit */
393 * Routines that operate on ranges of virtual addresses.
395 extern void pmap_protect( /* Change protections. */
401 extern void (pmap_pageable
)(
403 vm_map_offset_t start
,
407 #endif /* MACH_KERNEL_PRIVATE */
410 * JMM - This portion is exported to other kernel components right now,
411 * but will be pulled back in the future when the needed functionality
412 * is provided in a cleaner manner.
415 extern pmap_t kernel_pmap
; /* The kernel's map */
416 #define pmap_kernel() (kernel_pmap)
418 /* machine independent WIMG bits */
420 #define VM_MEM_GUARDED 0x1 /* (G) Guarded Storage */
421 #define VM_MEM_COHERENT 0x2 /* (M) Memory Coherency */
422 #define VM_MEM_NOT_CACHEABLE 0x4 /* (I) Cache Inhibit */
423 #define VM_MEM_WRITE_THROUGH 0x8 /* (W) Write-Through */
425 #define VM_WIMG_MASK 0xFF
426 #define VM_WIMG_USE_DEFAULT 0x80000000
428 extern void pmap_modify_pages( /* Set modify bit for pages */
433 extern vm_offset_t
pmap_extract(pmap_t pmap
,
436 extern void pmap_change_wiring( /* Specify pageability */
441 /* LP64todo - switch to vm_map_offset_t when it grows */
442 extern void pmap_remove( /* Remove mappings. */
448 #endif /* KERNEL_PRIVATE */
450 #endif /* _VM_PMAP_H_ */