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(vm_map_size_t size
); /* Create a pmap_t. */
182 extern pmap_t (pmap_kernel
)(void); /* Return the kernel's pmap */
183 extern void pmap_reference(pmap_t pmap
); /* Gain a reference. */
184 extern void pmap_destroy(pmap_t pmap
); /* Release a reference. */
185 extern void pmap_switch(pmap_t
);
188 extern void pmap_enter( /* Enter a mapping */
196 extern void pmap_remove_some_phys(
202 * Routines that operate on physical addresses.
205 extern void pmap_page_protect( /* Restrict access to page. */
209 extern void (pmap_zero_page
)(
212 extern void (pmap_zero_part_page
)(
217 extern void (pmap_copy_page
)(
221 extern void (pmap_copy_part_page
)(
223 vm_offset_t src_offset
,
225 vm_offset_t dst_offset
,
228 extern void (pmap_copy_part_lpage
)(
231 vm_offset_t dst_offset
,
234 extern void (pmap_copy_part_rpage
)(
236 vm_offset_t src_offset
,
240 extern unsigned int (pmap_disconnect
)( /* disconnect mappings and return reference and change */
243 extern kern_return_t (pmap_attribute_cache_sync
)( /* Flush appropriate
245 * page number sent */
248 vm_machine_attribute_t attribute
,
249 vm_machine_attribute_val_t
* value
);
252 * debug/assertions. pmap_verify_free returns true iff
253 * the given physical page is mapped into no pmap.
255 extern boolean_t
pmap_verify_free(ppnum_t pn
);
258 * Statistics routines
260 extern int (pmap_resident_count
)(pmap_t pmap
);
263 * Sundry required (internal) routines
265 extern void pmap_collect(pmap_t pmap
);/* Perform garbage
266 * collection, if any */
271 extern void (pmap_copy
)( /* Copy range of mappings,
275 vm_map_offset_t dest_va
,
277 vm_map_offset_t source_va
);
279 extern kern_return_t (pmap_attribute
)( /* Get/Set special memory
284 vm_machine_attribute_t attribute
,
285 vm_machine_attribute_val_t
* value
);
288 * Routines defined as macros.
290 #ifndef PMAP_ACTIVATE_USER
291 #ifndef PMAP_ACTIVATE
292 #define PMAP_ACTIVATE_USER(thr, cpu)
293 #else /* PMAP_ACTIVATE */
294 #define PMAP_ACTIVATE_USER(thr, cpu) { \
297 pmap = (thr)->map->pmap; \
298 if (pmap != pmap_kernel()) \
299 PMAP_ACTIVATE(pmap, (thr), (cpu)); \
301 #endif /* PMAP_ACTIVATE */
302 #endif /* PMAP_ACTIVATE_USER */
304 #ifndef PMAP_DEACTIVATE_USER
305 #ifndef PMAP_DEACTIVATE
306 #define PMAP_DEACTIVATE_USER(thr, cpu)
307 #else /* PMAP_DEACTIVATE */
308 #define PMAP_DEACTIVATE_USER(thr, cpu) { \
311 pmap = (thr)->map->pmap; \
312 if ((pmap) != pmap_kernel()) \
313 PMAP_DEACTIVATE(pmap, (thr), (cpu)); \
315 #endif /* PMAP_DEACTIVATE */
316 #endif /* PMAP_DEACTIVATE_USER */
318 #ifndef PMAP_ACTIVATE_KERNEL
319 #ifndef PMAP_ACTIVATE
320 #define PMAP_ACTIVATE_KERNEL(cpu)
321 #else /* PMAP_ACTIVATE */
322 #define PMAP_ACTIVATE_KERNEL(cpu) \
323 PMAP_ACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
324 #endif /* PMAP_ACTIVATE */
325 #endif /* PMAP_ACTIVATE_KERNEL */
327 #ifndef PMAP_DEACTIVATE_KERNEL
328 #ifndef PMAP_DEACTIVATE
329 #define PMAP_DEACTIVATE_KERNEL(cpu)
330 #else /* PMAP_DEACTIVATE */
331 #define PMAP_DEACTIVATE_KERNEL(cpu) \
332 PMAP_DEACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
333 #endif /* PMAP_DEACTIVATE */
334 #endif /* PMAP_DEACTIVATE_KERNEL */
338 * Macro to be used in place of pmap_enter()
340 #define PMAP_ENTER(pmap, virtual_address, page, protection, flags, wired) \
342 pmap_t __pmap = (pmap); \
343 vm_page_t __page = (page); \
345 if (__pmap != kernel_pmap) { \
346 ASSERT_PAGE_DECRYPTED(__page); \
351 (protection) & ~__page->page_lock, \
355 #endif /* !PMAP_ENTER */
358 * Routines to manage reference/modify bits based on
359 * physical addresses, simulating them if not provided
362 /* Clear reference bit */
363 extern void pmap_clear_reference(ppnum_t pn
);
364 /* Return reference bit */
365 extern boolean_t (pmap_is_referenced
)(ppnum_t pn
);
367 extern void pmap_set_modify(ppnum_t pn
);
368 /* Clear modify bit */
369 extern void pmap_clear_modify(ppnum_t pn
);
370 /* Return modify bit */
371 extern boolean_t
pmap_is_modified(ppnum_t pn
);
372 /* Return modified and referenced bits */
373 extern unsigned int pmap_get_refmod(ppnum_t pn
);
374 /* Clear modified and referenced bits */
375 extern void pmap_clear_refmod(ppnum_t pn
, unsigned int mask
);
376 #define VM_MEM_MODIFIED 0x01 /* Modified bit */
377 #define VM_MEM_REFERENCED 0x02 /* Referenced bit */
380 * Routines that operate on ranges of virtual addresses.
382 extern void pmap_protect( /* Change protections. */
388 extern void (pmap_pageable
)(
390 vm_map_offset_t start
,
394 #endif /* MACH_KERNEL_PRIVATE */
397 * JMM - This portion is exported to other kernel components right now,
398 * but will be pulled back in the future when the needed functionality
399 * is provided in a cleaner manner.
402 extern pmap_t kernel_pmap
; /* The kernel's map */
403 #define pmap_kernel() (kernel_pmap)
405 /* machine independent WIMG bits */
407 #define VM_MEM_GUARDED 0x1 /* (G) Guarded Storage */
408 #define VM_MEM_COHERENT 0x2 /* (M) Memory Coherency */
409 #define VM_MEM_NOT_CACHEABLE 0x4 /* (I) Cache Inhibit */
410 #define VM_MEM_WRITE_THROUGH 0x8 /* (W) Write-Through */
412 #define VM_WIMG_MASK 0xFF
413 #define VM_WIMG_USE_DEFAULT 0x80000000
415 extern void pmap_modify_pages( /* Set modify bit for pages */
420 extern vm_offset_t
pmap_extract(pmap_t pmap
,
423 extern void pmap_change_wiring( /* Specify pageability */
428 /* LP64todo - switch to vm_map_offset_t when it grows */
429 extern void pmap_remove( /* Remove mappings. */
435 #endif /* KERNEL_PRIVATE */
437 #endif /* _VM_PMAP_H_ */