2 * Copyright (c) 2000-2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
57 * Author: Avadis Tevanian, Jr.
60 * Machine address mapping definitions -- machine-independent
61 * section. [For machine-dependent section, see "machine/pmap.h".]
67 #include <sys/appleapiopts.h>
69 #ifdef __APPLE_API_PRIVATE
71 #include <mach/kern_return.h>
72 #include <mach/vm_param.h>
73 #include <mach/vm_types.h>
74 #include <mach/vm_attributes.h>
75 #include <mach/boolean.h>
76 #include <mach/vm_prot.h>
79 * The following is a description of the interface to the
80 * machine-dependent "physical map" data structure. The module
81 * must provide a "pmap_t" data type that represents the
82 * set of valid virtual-to-physical addresses for one user
83 * address space. [The kernel address space is represented
84 * by a distinguished "pmap_t".] The routines described manage
85 * this type, install and update virtual-to-physical mappings,
86 * and perform operations on physical addresses common to
87 * many address spaces.
90 /* Copy between a physical page and a virtual address */
91 extern kern_return_t
copypv(
100 #define cppvNoModSnk 16
101 #define cppvNoRefSrc 32
102 #define cppvKmap 64 /* User the kernel's vm_map */
104 #if !defined(MACH_KERNEL_PRIVATE)
106 typedef void *pmap_t
;
108 #else /* MACH_KERNEL_PRIVATE */
110 typedef struct pmap
*pmap_t
;
112 #include <machine/pmap.h>
115 * Routines used for initialization.
116 * There is traditionally also a pmap_bootstrap,
117 * used very early by machine-dependent code,
118 * but it is not part of the interface.
121 extern vm_offset_t
pmap_steal_memory(vm_size_t size
);
122 /* During VM initialization,
123 * steal a chunk of memory.
125 extern unsigned int pmap_free_pages(void); /* During VM initialization,
126 * report remaining unused
129 extern void pmap_startup(
132 /* During VM initialization,
133 * use remaining physical pages
134 * to allocate page frames.
136 extern void pmap_init(void); /* Initialization,
141 #ifndef MACHINE_PAGES
143 * If machine/pmap.h defines MACHINE_PAGES, it must implement
144 * the above functions. The pmap module has complete control.
145 * Otherwise, it must implement
150 * and vm/vm_resident.c implements pmap_steal_memory and pmap_startup
151 * using pmap_free_pages, pmap_next_page, pmap_virtual_space,
152 * and pmap_enter. pmap_free_pages may over-estimate the number
153 * of unused physical pages, and pmap_next_page may return FALSE
154 * to indicate that there are no more unused pages to return.
155 * However, for best performance pmap_free_pages should be accurate.
158 extern boolean_t
pmap_next_page(ppnum_t
*pnum
);
159 /* During VM initialization,
160 * return the next unused
163 extern void pmap_virtual_space(
164 vm_offset_t
*virtual_start
,
165 vm_offset_t
*virtual_end
);
166 /* During VM initialization,
167 * report virtual space
168 * available for the kernel.
170 #endif /* MACHINE_PAGES */
173 * Routines to manage the physical map data structure.
175 extern pmap_t
pmap_create(vm_size_t size
); /* Create a pmap_t. */
176 extern pmap_t (pmap_kernel
)(void); /* Return the kernel's pmap */
177 extern void pmap_reference(pmap_t pmap
); /* Gain a reference. */
178 extern void pmap_destroy(pmap_t pmap
); /* Release a reference. */
179 extern void pmap_switch(pmap_t
);
182 extern void pmap_enter( /* Enter a mapping */
190 extern void pmap_remove_some_phys(
196 * Routines that operate on physical addresses.
199 extern void pmap_page_protect( /* Restrict access to page. */
203 extern void (pmap_zero_page
)(
206 extern void (pmap_zero_part_page
)(
211 extern void (pmap_copy_page
)(
215 extern void (pmap_copy_part_page
)(
217 vm_offset_t src_offset
,
219 vm_offset_t dst_offset
,
222 extern void (pmap_copy_part_lpage
)(
225 vm_offset_t dst_offset
,
228 extern void (pmap_copy_part_rpage
)(
230 vm_offset_t src_offset
,
235 * debug/assertions. pmap_verify_free returns true iff
236 * the given physical page is mapped into no pmap.
238 extern boolean_t
pmap_verify_free(ppnum_t pn
);
241 * Statistics routines
243 extern int (pmap_resident_count
)(pmap_t pmap
);
246 * Sundry required (internal) routines
248 extern void pmap_collect(pmap_t pmap
);/* Perform garbage
249 * collection, if any */
252 extern vm_offset_t (pmap_phys_address
)( /* Transform address returned
253 * by device driver mapping
254 * function to physical address
255 * known to this module. */
258 extern int (pmap_phys_to_frame
)( /* Inverse of pmap_phys_addess,
259 * for use by device driver
260 * mapping function in
261 * machine-independent
268 extern void (pmap_copy
)( /* Copy range of mappings,
274 vm_offset_t source_va
);
276 extern kern_return_t (pmap_attribute
)( /* Get/Set special memory
281 vm_machine_attribute_t attribute
,
282 vm_machine_attribute_val_t
* value
);
284 extern kern_return_t (pmap_attribute_cache_sync
)( /* Flush appropriate
286 * page number sent */
289 vm_machine_attribute_t attribute
,
290 vm_machine_attribute_val_t
* value
);
293 * Routines defined as macros.
295 #ifndef PMAP_ACTIVATE_USER
296 #define PMAP_ACTIVATE_USER(act, cpu) { \
299 pmap = (act)->map->pmap; \
300 if (pmap != pmap_kernel()) \
301 PMAP_ACTIVATE(pmap, (act), (cpu)); \
303 #endif /* PMAP_ACTIVATE_USER */
305 #ifndef PMAP_DEACTIVATE_USER
306 #define PMAP_DEACTIVATE_USER(act, cpu) { \
309 pmap = (act)->map->pmap; \
310 if ((pmap) != pmap_kernel()) \
311 PMAP_DEACTIVATE(pmap, (act), (cpu)); \
313 #endif /* PMAP_DEACTIVATE_USER */
315 #ifndef PMAP_ACTIVATE_KERNEL
316 #define PMAP_ACTIVATE_KERNEL(cpu) \
317 PMAP_ACTIVATE(pmap_kernel(), THR_ACT_NULL, cpu)
318 #endif /* PMAP_ACTIVATE_KERNEL */
320 #ifndef PMAP_DEACTIVATE_KERNEL
321 #define PMAP_DEACTIVATE_KERNEL(cpu) \
322 PMAP_DEACTIVATE(pmap_kernel(), THR_ACT_NULL, cpu)
323 #endif /* PMAP_DEACTIVATE_KERNEL */
327 * Macro to be used in place of pmap_enter()
329 #define PMAP_ENTER(pmap, virtual_address, page, protection, flags, wired) \
335 (protection) & ~(page)->page_lock, \
340 #endif /* !PMAP_ENTER */
343 * Routines to manage reference/modify bits based on
344 * physical addresses, simulating them if not provided
347 /* Clear reference bit */
348 extern void pmap_clear_reference(ppnum_t pn
);
349 /* Return reference bit */
350 extern boolean_t (pmap_is_referenced
)(ppnum_t pn
);
352 extern void pmap_set_modify(ppnum_t pn
);
353 /* Clear modify bit */
354 extern void pmap_clear_modify(ppnum_t pn
);
355 /* Return modify bit */
356 extern boolean_t
pmap_is_modified(ppnum_t pn
);
359 * Routines that operate on ranges of virtual addresses.
361 extern void pmap_protect( /* Change protections. */
367 extern void (pmap_pageable
)(
373 #endif /* MACH_KERNEL_PRIVATE */
376 * JMM - This portion is exported to other kernel components right now,
377 * but will be pulled back in the future when the needed functionality
378 * is provided in a cleaner manner.
381 #define PMAP_NULL ((pmap_t) 0)
383 extern pmap_t kernel_pmap
; /* The kernel's map */
384 #define pmap_kernel() (kernel_pmap)
386 /* machine independent WIMG bits */
388 #define VM_MEM_GUARDED 0x1
389 #define VM_MEM_COHERENT 0x2
390 #define VM_MEM_NOT_CACHEABLE 0x4
391 #define VM_MEM_WRITE_THROUGH 0x8
393 #define VM_WIMG_MASK 0xFF
394 #define VM_WIMG_USE_DEFAULT 0x80000000
396 extern void pmap_modify_pages( /* Set modify bit for pages */
401 extern vm_offset_t
pmap_extract(pmap_t pmap
,
404 extern void pmap_change_wiring( /* Specify pageability */
409 extern void pmap_remove( /* Remove mappings. */
415 #endif /* __APPLE_API_PRIVATE */
417 #endif /* _VM_PMAP_H_ */