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 #if !defined(MACH_KERNEL_PRIVATE)
94 #else /* MACH_KERNEL_PRIVATE */
96 typedef struct pmap
*pmap_t
;
98 #include <machine/pmap.h>
101 * Routines used for initialization.
102 * There is traditionally also a pmap_bootstrap,
103 * used very early by machine-dependent code,
104 * but it is not part of the interface.
107 extern vm_offset_t
pmap_steal_memory(vm_size_t size
);
108 /* During VM initialization,
109 * steal a chunk of memory.
111 extern unsigned int pmap_free_pages(void); /* During VM initialization,
112 * report remaining unused
115 extern void pmap_startup(
118 /* During VM initialization,
119 * use remaining physical pages
120 * to allocate page frames.
122 extern void pmap_init(void); /* Initialization,
127 #ifndef MACHINE_PAGES
129 * If machine/pmap.h defines MACHINE_PAGES, it must implement
130 * the above functions. The pmap module has complete control.
131 * Otherwise, it must implement
136 * and vm/vm_resident.c implements pmap_steal_memory and pmap_startup
137 * using pmap_free_pages, pmap_next_page, pmap_virtual_space,
138 * and pmap_enter. pmap_free_pages may over-estimate the number
139 * of unused physical pages, and pmap_next_page may return FALSE
140 * to indicate that there are no more unused pages to return.
141 * However, for best performance pmap_free_pages should be accurate.
144 extern boolean_t
pmap_next_page(vm_offset_t
*paddr
);
145 /* During VM initialization,
146 * return the next unused
149 extern void pmap_virtual_space(
150 vm_offset_t
*virtual_start
,
151 vm_offset_t
*virtual_end
);
152 /* During VM initialization,
153 * report virtual space
154 * available for the kernel.
156 #endif /* MACHINE_PAGES */
159 * Routines to manage the physical map data structure.
161 extern pmap_t
pmap_create(vm_size_t size
); /* Create a pmap_t. */
162 extern pmap_t (pmap_kernel
)(void); /* Return the kernel's pmap */
163 extern void pmap_reference(pmap_t pmap
); /* Gain a reference. */
164 extern void pmap_destroy(pmap_t pmap
); /* Release a reference. */
165 extern void pmap_switch(pmap_t
);
168 extern void pmap_enter( /* Enter a mapping */
176 extern void pmap_remove_some_phys(
182 * Routines that operate on physical addresses.
185 extern void pmap_page_protect( /* Restrict access to page. */
189 extern void (pmap_zero_page
)(
192 extern void (pmap_zero_part_page
)(
197 extern void (pmap_copy_page
)(
201 extern void (pmap_copy_part_page
)(
203 vm_offset_t src_offset
,
205 vm_offset_t dst_offset
,
208 extern void (pmap_copy_part_lpage
)(
211 vm_offset_t dst_offset
,
214 extern void (pmap_copy_part_rpage
)(
216 vm_offset_t src_offset
,
221 * debug/assertions. pmap_verify_free returns true iff
222 * the given physical page is mapped into no pmap.
224 extern boolean_t
pmap_verify_free(vm_offset_t paddr
);
227 * Statistics routines
229 extern int (pmap_resident_count
)(pmap_t pmap
);
232 * Sundry required (internal) routines
234 extern void pmap_collect(pmap_t pmap
);/* Perform garbage
235 * collection, if any */
238 extern vm_offset_t (pmap_phys_address
)( /* Transform address returned
239 * by device driver mapping
240 * function to physical address
241 * known to this module. */
244 extern int (pmap_phys_to_frame
)( /* Inverse of pmap_phys_addess,
245 * for use by device driver
246 * mapping function in
247 * machine-independent
254 extern void (pmap_copy
)( /* Copy range of mappings,
260 vm_offset_t source_va
);
262 extern kern_return_t (pmap_attribute
)( /* Get/Set special memory
267 vm_machine_attribute_t attribute
,
268 vm_machine_attribute_val_t
* value
);
270 extern kern_return_t (pmap_attribute_cache_sync
)( /* Flush appropriate
275 vm_machine_attribute_t attribute
,
276 vm_machine_attribute_val_t
* value
);
279 * Routines defined as macros.
281 #ifndef PMAP_ACTIVATE_USER
282 #define PMAP_ACTIVATE_USER(act, cpu) { \
285 pmap = (act)->map->pmap; \
286 if (pmap != pmap_kernel()) \
287 PMAP_ACTIVATE(pmap, (act), (cpu)); \
289 #endif /* PMAP_ACTIVATE_USER */
291 #ifndef PMAP_DEACTIVATE_USER
292 #define PMAP_DEACTIVATE_USER(act, cpu) { \
295 pmap = (act)->map->pmap; \
296 if ((pmap) != pmap_kernel()) \
297 PMAP_DEACTIVATE(pmap, (act), (cpu)); \
299 #endif /* PMAP_DEACTIVATE_USER */
301 #ifndef PMAP_ACTIVATE_KERNEL
302 #define PMAP_ACTIVATE_KERNEL(cpu) \
303 PMAP_ACTIVATE(pmap_kernel(), THR_ACT_NULL, cpu)
304 #endif /* PMAP_ACTIVATE_KERNEL */
306 #ifndef PMAP_DEACTIVATE_KERNEL
307 #define PMAP_DEACTIVATE_KERNEL(cpu) \
308 PMAP_DEACTIVATE(pmap_kernel(), THR_ACT_NULL, cpu)
309 #endif /* PMAP_DEACTIVATE_KERNEL */
313 * Macro to be used in place of pmap_enter()
315 #define PMAP_ENTER(pmap, virtual_address, page, protection, flags, wired) \
321 (protection) & ~(page)->page_lock, \
326 #endif /* !PMAP_ENTER */
329 * Routines to manage reference/modify bits based on
330 * physical addresses, simulating them if not provided
333 /* Clear reference bit */
334 extern void pmap_clear_reference(vm_offset_t paddr
);
335 /* Return reference bit */
336 extern boolean_t (pmap_is_referenced
)(vm_offset_t paddr
);
338 extern void pmap_set_modify(vm_offset_t paddr
);
339 /* Clear modify bit */
340 extern void pmap_clear_modify(vm_offset_t paddr
);
341 /* Return modify bit */
342 extern boolean_t
pmap_is_modified(vm_offset_t paddr
);
345 * Routines that operate on ranges of virtual addresses.
347 extern void pmap_protect( /* Change protections. */
353 extern void (pmap_pageable
)(
359 #endif /* MACH_KERNEL_PRIVATE */
362 * JMM - This portion is exported to other kernel components right now,
363 * but will be pulled back in the future when the needed functionality
364 * is provided in a cleaner manner.
367 #define PMAP_NULL ((pmap_t) 0)
369 extern pmap_t kernel_pmap
; /* The kernel's map */
370 #define pmap_kernel() (kernel_pmap)
372 /* machine independent WIMG bits */
374 #define VM_MEM_GUARDED 0x1
375 #define VM_MEM_COHERENT 0x2
376 #define VM_MEM_NOT_CACHEABLE 0x4
377 #define VM_MEM_WRITE_THROUGH 0x8
379 #define VM_WIMG_MASK 0xFF
380 #define VM_WIMG_USE_DEFAULT 0x80000000
382 extern void pmap_modify_pages( /* Set modify bit for pages */
387 extern vm_offset_t
pmap_extract(pmap_t pmap
,
390 extern void pmap_change_wiring( /* Specify pageability */
395 extern void pmap_remove( /* Remove mappings. */
400 #endif /* __APPLE_API_PRIVATE */
402 #endif /* _VM_PMAP_H_ */