2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
28 * All Rights Reserved.
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.
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.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
54 * Author: Avadis Tevanian, Jr.
57 * Machine address mapping definitions -- machine-independent
58 * section. [For machine-dependent section, see "machine/pmap.h".]
64 #include <mach/kern_return.h>
65 #include <mach/vm_param.h>
66 #include <mach/vm_types.h>
67 #include <mach/vm_attributes.h>
68 #include <mach/boolean.h>
69 #include <mach/vm_prot.h>
74 * The following is a description of the interface to the
75 * machine-dependent "physical map" data structure. The module
76 * must provide a "pmap_t" data type that represents the
77 * set of valid virtual-to-physical addresses for one user
78 * address space. [The kernel address space is represented
79 * by a distinguished "pmap_t".] The routines described manage
80 * this type, install and update virtual-to-physical mappings,
81 * and perform operations on physical addresses common to
82 * many address spaces.
85 /* Copy between a physical page and a virtual address */
86 /* LP64todo - switch to vm_map_offset_t when it grows */
87 extern kern_return_t
copypv(
100 #define cppvNoModSnk 16
101 #define cppvNoModSnkb 27
102 #define cppvNoRefSrc 32
103 #define cppvNoRefSrcb 26
104 #define cppvKmap 64 /* Use the kernel's vm_map */
107 #ifdef MACH_KERNEL_PRIVATE
109 #include <machine/pmap.h>
112 * Routines used for initialization.
113 * There is traditionally also a pmap_bootstrap,
114 * used very early by machine-dependent code,
115 * but it is not part of the interface.
118 * These interfaces are tied to the size of the
119 * kernel pmap - and therefore use the "local"
120 * vm_offset_t, etc... types.
123 extern void *pmap_steal_memory(vm_size_t size
);
124 /* During VM initialization,
125 * steal a chunk of memory.
127 extern unsigned int pmap_free_pages(void); /* During VM initialization,
128 * report remaining unused
131 extern void pmap_startup(
134 /* During VM initialization,
135 * use remaining physical pages
136 * to allocate page frames.
138 extern void pmap_init(void); /* Initialization,
143 extern void mapping_adjust(void); /* Adjust free mapping count */
145 extern void mapping_free_prime(void); /* Primes the mapping block release list */
147 #ifndef MACHINE_PAGES
149 * If machine/pmap.h defines MACHINE_PAGES, it must implement
150 * the above functions. The pmap module has complete control.
151 * Otherwise, it must implement
156 * and vm/vm_resident.c implements pmap_steal_memory and pmap_startup
157 * using pmap_free_pages, pmap_next_page, pmap_virtual_space,
158 * and pmap_enter. pmap_free_pages may over-estimate the number
159 * of unused physical pages, and pmap_next_page may return FALSE
160 * to indicate that there are no more unused pages to return.
161 * However, for best performance pmap_free_pages should be accurate.
164 extern boolean_t
pmap_next_page(ppnum_t
*pnum
);
165 /* During VM initialization,
166 * return the next unused
169 extern void pmap_virtual_space(
170 vm_offset_t
*virtual_start
,
171 vm_offset_t
*virtual_end
);
172 /* During VM initialization,
173 * report virtual space
174 * available for the kernel.
176 #endif /* MACHINE_PAGES */
179 * Routines to manage the physical map data structure.
181 extern pmap_t
pmap_create( /* Create a pmap_t. */
184 extern pmap_t (pmap_kernel
)(void); /* Return the kernel's pmap */
185 extern void pmap_reference(pmap_t pmap
); /* Gain a reference. */
186 extern void pmap_destroy(pmap_t pmap
); /* Release a reference. */
187 extern void pmap_switch(pmap_t
);
190 extern void pmap_enter( /* Enter a mapping */
198 extern void pmap_remove_some_phys(
204 * Routines that operate on physical addresses.
207 extern void pmap_page_protect( /* Restrict access to page. */
211 extern void (pmap_zero_page
)(
214 extern void (pmap_zero_part_page
)(
219 extern void (pmap_copy_page
)(
223 extern void (pmap_copy_part_page
)(
225 vm_offset_t src_offset
,
227 vm_offset_t dst_offset
,
230 extern void (pmap_copy_part_lpage
)(
233 vm_offset_t dst_offset
,
236 extern void (pmap_copy_part_rpage
)(
238 vm_offset_t src_offset
,
242 extern unsigned int (pmap_disconnect
)( /* disconnect mappings and return reference and change */
245 extern kern_return_t (pmap_attribute_cache_sync
)( /* Flush appropriate
247 * page number sent */
250 vm_machine_attribute_t attribute
,
251 vm_machine_attribute_val_t
* value
);
253 extern unsigned int (pmap_cache_attributes
)(
257 * debug/assertions. pmap_verify_free returns true iff
258 * the given physical page is mapped into no pmap.
260 extern boolean_t
pmap_verify_free(ppnum_t pn
);
263 * Statistics routines
265 extern int (pmap_resident_count
)(pmap_t pmap
);
268 * Sundry required (internal) routines
270 extern void pmap_collect(pmap_t pmap
);/* Perform garbage
271 * collection, if any */
276 extern void (pmap_copy
)( /* Copy range of mappings,
280 vm_map_offset_t dest_va
,
282 vm_map_offset_t source_va
);
284 extern kern_return_t (pmap_attribute
)( /* Get/Set special memory
289 vm_machine_attribute_t attribute
,
290 vm_machine_attribute_val_t
* value
);
293 * Routines defined as macros.
295 #ifndef PMAP_ACTIVATE_USER
296 #ifndef PMAP_ACTIVATE
297 #define PMAP_ACTIVATE_USER(thr, cpu)
298 #else /* PMAP_ACTIVATE */
299 #define PMAP_ACTIVATE_USER(thr, cpu) { \
302 pmap = (thr)->map->pmap; \
303 if (pmap != pmap_kernel()) \
304 PMAP_ACTIVATE(pmap, (thr), (cpu)); \
306 #endif /* PMAP_ACTIVATE */
307 #endif /* PMAP_ACTIVATE_USER */
309 #ifndef PMAP_DEACTIVATE_USER
310 #ifndef PMAP_DEACTIVATE
311 #define PMAP_DEACTIVATE_USER(thr, cpu)
312 #else /* PMAP_DEACTIVATE */
313 #define PMAP_DEACTIVATE_USER(thr, cpu) { \
316 pmap = (thr)->map->pmap; \
317 if ((pmap) != pmap_kernel()) \
318 PMAP_DEACTIVATE(pmap, (thr), (cpu)); \
320 #endif /* PMAP_DEACTIVATE */
321 #endif /* PMAP_DEACTIVATE_USER */
323 #ifndef PMAP_ACTIVATE_KERNEL
324 #ifndef PMAP_ACTIVATE
325 #define PMAP_ACTIVATE_KERNEL(cpu)
326 #else /* PMAP_ACTIVATE */
327 #define PMAP_ACTIVATE_KERNEL(cpu) \
328 PMAP_ACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
329 #endif /* PMAP_ACTIVATE */
330 #endif /* PMAP_ACTIVATE_KERNEL */
332 #ifndef PMAP_DEACTIVATE_KERNEL
333 #ifndef PMAP_DEACTIVATE
334 #define PMAP_DEACTIVATE_KERNEL(cpu)
335 #else /* PMAP_DEACTIVATE */
336 #define PMAP_DEACTIVATE_KERNEL(cpu) \
337 PMAP_DEACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
338 #endif /* PMAP_DEACTIVATE */
339 #endif /* PMAP_DEACTIVATE_KERNEL */
343 * Macro to be used in place of pmap_enter()
345 #define PMAP_ENTER(pmap, virtual_address, page, protection, flags, wired) \
347 pmap_t __pmap = (pmap); \
348 vm_page_t __page = (page); \
350 if (__pmap != kernel_pmap) { \
351 ASSERT_PAGE_DECRYPTED(__page); \
356 (protection) & ~__page->page_lock, \
360 #endif /* !PMAP_ENTER */
363 * Routines to manage reference/modify bits based on
364 * physical addresses, simulating them if not provided
367 /* Clear reference bit */
368 extern void pmap_clear_reference(ppnum_t pn
);
369 /* Return reference bit */
370 extern boolean_t (pmap_is_referenced
)(ppnum_t pn
);
372 extern void pmap_set_modify(ppnum_t pn
);
373 /* Clear modify bit */
374 extern void pmap_clear_modify(ppnum_t pn
);
375 /* Return modify bit */
376 extern boolean_t
pmap_is_modified(ppnum_t pn
);
377 /* Return modified and referenced bits */
378 extern unsigned int pmap_get_refmod(ppnum_t pn
);
379 /* Clear modified and referenced bits */
380 extern void pmap_clear_refmod(ppnum_t pn
, unsigned int mask
);
381 #define VM_MEM_MODIFIED 0x01 /* Modified bit */
382 #define VM_MEM_REFERENCED 0x02 /* Referenced bit */
385 * Routines that operate on ranges of virtual addresses.
387 extern void pmap_protect( /* Change protections. */
393 extern void (pmap_pageable
)(
395 vm_map_offset_t start
,
399 #endif /* MACH_KERNEL_PRIVATE */
402 * JMM - This portion is exported to other kernel components right now,
403 * but will be pulled back in the future when the needed functionality
404 * is provided in a cleaner manner.
407 extern pmap_t kernel_pmap
; /* The kernel's map */
408 #define pmap_kernel() (kernel_pmap)
410 /* machine independent WIMG bits */
412 #define VM_MEM_GUARDED 0x1 /* (G) Guarded Storage */
413 #define VM_MEM_COHERENT 0x2 /* (M) Memory Coherency */
414 #define VM_MEM_NOT_CACHEABLE 0x4 /* (I) Cache Inhibit */
415 #define VM_MEM_WRITE_THROUGH 0x8 /* (W) Write-Through */
417 #define VM_WIMG_MASK 0xFF
418 #define VM_WIMG_USE_DEFAULT 0x80000000
420 extern void pmap_modify_pages( /* Set modify bit for pages */
425 extern vm_offset_t
pmap_extract(pmap_t pmap
,
428 extern void pmap_change_wiring( /* Specify pageability */
433 /* LP64todo - switch to vm_map_offset_t when it grows */
434 extern void pmap_remove( /* Remove mappings. */
440 #endif /* KERNEL_PRIVATE */
442 #endif /* _VM_PMAP_H_ */