]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/pmap.h
xnu-792.21.3.tar.gz
[apple/xnu.git] / osfmk / vm / pmap.h
1 /*
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * @OSF_COPYRIGHT@
30 */
31 /*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988,1987 Carnegie Mellon University
34 * All Rights Reserved.
35 *
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
41 *
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
56 /*
57 */
58 /*
59 * File: vm/pmap.h
60 * Author: Avadis Tevanian, Jr.
61 * Date: 1985
62 *
63 * Machine address mapping definitions -- machine-independent
64 * section. [For machine-dependent section, see "machine/pmap.h".]
65 */
66
67 #ifndef _VM_PMAP_H_
68 #define _VM_PMAP_H_
69
70 #include <mach/kern_return.h>
71 #include <mach/vm_param.h>
72 #include <mach/vm_types.h>
73 #include <mach/vm_attributes.h>
74 #include <mach/boolean.h>
75 #include <mach/vm_prot.h>
76
77 #ifdef KERNEL_PRIVATE
78
79 /*
80 * The following is a description of the interface to the
81 * machine-dependent "physical map" data structure. The module
82 * must provide a "pmap_t" data type that represents the
83 * set of valid virtual-to-physical addresses for one user
84 * address space. [The kernel address space is represented
85 * by a distinguished "pmap_t".] The routines described manage
86 * this type, install and update virtual-to-physical mappings,
87 * and perform operations on physical addresses common to
88 * many address spaces.
89 */
90
91 /* Copy between a physical page and a virtual address */
92 /* LP64todo - switch to vm_map_offset_t when it grows */
93 extern kern_return_t copypv(
94 addr64_t source,
95 addr64_t sink,
96 unsigned int size,
97 int which);
98 #define cppvPsnk 1
99 #define cppvPsnkb 31
100 #define cppvPsrc 2
101 #define cppvPsrcb 30
102 #define cppvFsnk 4
103 #define cppvFsnkb 29
104 #define cppvFsrc 8
105 #define cppvFsrcb 28
106 #define cppvNoModSnk 16
107 #define cppvNoModSnkb 27
108 #define cppvNoRefSrc 32
109 #define cppvNoRefSrcb 26
110 #define cppvKmap 64 /* Use the kernel's vm_map */
111 #define cppvKmapb 25
112
113 #ifdef MACH_KERNEL_PRIVATE
114
115 #include <machine/pmap.h>
116
117 /*
118 * Routines used for initialization.
119 * There is traditionally also a pmap_bootstrap,
120 * used very early by machine-dependent code,
121 * but it is not part of the interface.
122 *
123 * LP64todo -
124 * These interfaces are tied to the size of the
125 * kernel pmap - and therefore use the "local"
126 * vm_offset_t, etc... types.
127 */
128
129 extern void *pmap_steal_memory(vm_size_t size);
130 /* During VM initialization,
131 * steal a chunk of memory.
132 */
133 extern unsigned int pmap_free_pages(void); /* During VM initialization,
134 * report remaining unused
135 * physical pages.
136 */
137 extern void pmap_startup(
138 vm_offset_t *startp,
139 vm_offset_t *endp);
140 /* During VM initialization,
141 * use remaining physical pages
142 * to allocate page frames.
143 */
144 extern void pmap_init(void); /* Initialization,
145 * after kernel runs
146 * in virtual memory.
147 */
148
149 extern void mapping_adjust(void); /* Adjust free mapping count */
150
151 extern void mapping_free_prime(void); /* Primes the mapping block release list */
152
153 #ifndef MACHINE_PAGES
154 /*
155 * If machine/pmap.h defines MACHINE_PAGES, it must implement
156 * the above functions. The pmap module has complete control.
157 * Otherwise, it must implement
158 * pmap_free_pages
159 * pmap_virtual_space
160 * pmap_next_page
161 * pmap_init
162 * and vm/vm_resident.c implements pmap_steal_memory and pmap_startup
163 * using pmap_free_pages, pmap_next_page, pmap_virtual_space,
164 * and pmap_enter. pmap_free_pages may over-estimate the number
165 * of unused physical pages, and pmap_next_page may return FALSE
166 * to indicate that there are no more unused pages to return.
167 * However, for best performance pmap_free_pages should be accurate.
168 */
169
170 extern boolean_t pmap_next_page(ppnum_t *pnum);
171 /* During VM initialization,
172 * return the next unused
173 * physical page.
174 */
175 extern void pmap_virtual_space(
176 vm_offset_t *virtual_start,
177 vm_offset_t *virtual_end);
178 /* During VM initialization,
179 * report virtual space
180 * available for the kernel.
181 */
182 #endif /* MACHINE_PAGES */
183
184 /*
185 * Routines to manage the physical map data structure.
186 */
187 extern pmap_t pmap_create(vm_map_size_t size); /* Create a pmap_t. */
188 extern pmap_t (pmap_kernel)(void); /* Return the kernel's pmap */
189 extern void pmap_reference(pmap_t pmap); /* Gain a reference. */
190 extern void pmap_destroy(pmap_t pmap); /* Release a reference. */
191 extern void pmap_switch(pmap_t);
192
193
194 extern void pmap_enter( /* Enter a mapping */
195 pmap_t pmap,
196 vm_map_offset_t v,
197 ppnum_t pn,
198 vm_prot_t prot,
199 unsigned int flags,
200 boolean_t wired);
201
202 extern void pmap_remove_some_phys(
203 pmap_t pmap,
204 ppnum_t pn);
205
206
207 /*
208 * Routines that operate on physical addresses.
209 */
210
211 extern void pmap_page_protect( /* Restrict access to page. */
212 ppnum_t phys,
213 vm_prot_t prot);
214
215 extern void (pmap_zero_page)(
216 ppnum_t pn);
217
218 extern void (pmap_zero_part_page)(
219 ppnum_t pn,
220 vm_offset_t offset,
221 vm_size_t len);
222
223 extern void (pmap_copy_page)(
224 ppnum_t src,
225 ppnum_t dest);
226
227 extern void (pmap_copy_part_page)(
228 ppnum_t src,
229 vm_offset_t src_offset,
230 ppnum_t dst,
231 vm_offset_t dst_offset,
232 vm_size_t len);
233
234 extern void (pmap_copy_part_lpage)(
235 vm_offset_t src,
236 ppnum_t dst,
237 vm_offset_t dst_offset,
238 vm_size_t len);
239
240 extern void (pmap_copy_part_rpage)(
241 ppnum_t src,
242 vm_offset_t src_offset,
243 vm_offset_t dst,
244 vm_size_t len);
245
246 extern unsigned int (pmap_disconnect)( /* disconnect mappings and return reference and change */
247 ppnum_t phys);
248
249 extern kern_return_t (pmap_attribute_cache_sync)( /* Flush appropriate
250 * cache based on
251 * page number sent */
252 ppnum_t pn,
253 vm_size_t size,
254 vm_machine_attribute_t attribute,
255 vm_machine_attribute_val_t* value);
256
257 /*
258 * debug/assertions. pmap_verify_free returns true iff
259 * the given physical page is mapped into no pmap.
260 */
261 extern boolean_t pmap_verify_free(ppnum_t pn);
262
263 /*
264 * Statistics routines
265 */
266 extern int (pmap_resident_count)(pmap_t pmap);
267
268 /*
269 * Sundry required (internal) routines
270 */
271 extern void pmap_collect(pmap_t pmap);/* Perform garbage
272 * collection, if any */
273
274 /*
275 * Optional routines
276 */
277 extern void (pmap_copy)( /* Copy range of mappings,
278 * if desired. */
279 pmap_t dest,
280 pmap_t source,
281 vm_map_offset_t dest_va,
282 vm_map_size_t size,
283 vm_map_offset_t source_va);
284
285 extern kern_return_t (pmap_attribute)( /* Get/Set special memory
286 * attributes */
287 pmap_t pmap,
288 vm_map_offset_t va,
289 vm_map_size_t size,
290 vm_machine_attribute_t attribute,
291 vm_machine_attribute_val_t* value);
292
293 /*
294 * Routines defined as macros.
295 */
296 #ifndef PMAP_ACTIVATE_USER
297 #ifndef PMAP_ACTIVATE
298 #define PMAP_ACTIVATE_USER(thr, cpu)
299 #else /* PMAP_ACTIVATE */
300 #define PMAP_ACTIVATE_USER(thr, cpu) { \
301 pmap_t pmap; \
302 \
303 pmap = (thr)->map->pmap; \
304 if (pmap != pmap_kernel()) \
305 PMAP_ACTIVATE(pmap, (thr), (cpu)); \
306 }
307 #endif /* PMAP_ACTIVATE */
308 #endif /* PMAP_ACTIVATE_USER */
309
310 #ifndef PMAP_DEACTIVATE_USER
311 #ifndef PMAP_DEACTIVATE
312 #define PMAP_DEACTIVATE_USER(thr, cpu)
313 #else /* PMAP_DEACTIVATE */
314 #define PMAP_DEACTIVATE_USER(thr, cpu) { \
315 pmap_t pmap; \
316 \
317 pmap = (thr)->map->pmap; \
318 if ((pmap) != pmap_kernel()) \
319 PMAP_DEACTIVATE(pmap, (thr), (cpu)); \
320 }
321 #endif /* PMAP_DEACTIVATE */
322 #endif /* PMAP_DEACTIVATE_USER */
323
324 #ifndef PMAP_ACTIVATE_KERNEL
325 #ifndef PMAP_ACTIVATE
326 #define PMAP_ACTIVATE_KERNEL(cpu)
327 #else /* PMAP_ACTIVATE */
328 #define PMAP_ACTIVATE_KERNEL(cpu) \
329 PMAP_ACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
330 #endif /* PMAP_ACTIVATE */
331 #endif /* PMAP_ACTIVATE_KERNEL */
332
333 #ifndef PMAP_DEACTIVATE_KERNEL
334 #ifndef PMAP_DEACTIVATE
335 #define PMAP_DEACTIVATE_KERNEL(cpu)
336 #else /* PMAP_DEACTIVATE */
337 #define PMAP_DEACTIVATE_KERNEL(cpu) \
338 PMAP_DEACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
339 #endif /* PMAP_DEACTIVATE */
340 #endif /* PMAP_DEACTIVATE_KERNEL */
341
342 #ifndef PMAP_ENTER
343 /*
344 * Macro to be used in place of pmap_enter()
345 */
346 #define PMAP_ENTER(pmap, virtual_address, page, protection, flags, wired) \
347 MACRO_BEGIN \
348 pmap_t __pmap = (pmap); \
349 vm_page_t __page = (page); \
350 \
351 if (__pmap != kernel_pmap) { \
352 ASSERT_PAGE_DECRYPTED(__page); \
353 } \
354 pmap_enter(__pmap, \
355 (virtual_address), \
356 __page->phys_page, \
357 (protection) & ~__page->page_lock, \
358 (flags), \
359 (wired)); \
360 MACRO_END
361 #endif /* !PMAP_ENTER */
362
363 /*
364 * Routines to manage reference/modify bits based on
365 * physical addresses, simulating them if not provided
366 * by the hardware.
367 */
368 /* Clear reference bit */
369 extern void pmap_clear_reference(ppnum_t pn);
370 /* Return reference bit */
371 extern boolean_t (pmap_is_referenced)(ppnum_t pn);
372 /* Set modify bit */
373 extern void pmap_set_modify(ppnum_t pn);
374 /* Clear modify bit */
375 extern void pmap_clear_modify(ppnum_t pn);
376 /* Return modify bit */
377 extern boolean_t pmap_is_modified(ppnum_t pn);
378 /* Return modified and referenced bits */
379 extern unsigned int pmap_get_refmod(ppnum_t pn);
380 /* Clear modified and referenced bits */
381 extern void pmap_clear_refmod(ppnum_t pn, unsigned int mask);
382 #define VM_MEM_MODIFIED 0x01 /* Modified bit */
383 #define VM_MEM_REFERENCED 0x02 /* Referenced bit */
384
385 /*
386 * Routines that operate on ranges of virtual addresses.
387 */
388 extern void pmap_protect( /* Change protections. */
389 pmap_t map,
390 vm_map_offset_t s,
391 vm_map_offset_t e,
392 vm_prot_t prot);
393
394 extern void (pmap_pageable)(
395 pmap_t pmap,
396 vm_map_offset_t start,
397 vm_map_offset_t end,
398 boolean_t pageable);
399
400 #endif /* MACH_KERNEL_PRIVATE */
401
402 /*
403 * JMM - This portion is exported to other kernel components right now,
404 * but will be pulled back in the future when the needed functionality
405 * is provided in a cleaner manner.
406 */
407
408 extern pmap_t kernel_pmap; /* The kernel's map */
409 #define pmap_kernel() (kernel_pmap)
410
411 /* machine independent WIMG bits */
412
413 #define VM_MEM_GUARDED 0x1 /* (G) Guarded Storage */
414 #define VM_MEM_COHERENT 0x2 /* (M) Memory Coherency */
415 #define VM_MEM_NOT_CACHEABLE 0x4 /* (I) Cache Inhibit */
416 #define VM_MEM_WRITE_THROUGH 0x8 /* (W) Write-Through */
417
418 #define VM_WIMG_MASK 0xFF
419 #define VM_WIMG_USE_DEFAULT 0x80000000
420
421 extern void pmap_modify_pages( /* Set modify bit for pages */
422 pmap_t map,
423 vm_map_offset_t s,
424 vm_map_offset_t e);
425
426 extern vm_offset_t pmap_extract(pmap_t pmap,
427 vm_map_offset_t va);
428
429 extern void pmap_change_wiring( /* Specify pageability */
430 pmap_t pmap,
431 vm_map_offset_t va,
432 boolean_t wired);
433
434 /* LP64todo - switch to vm_map_offset_t when it grows */
435 extern void pmap_remove( /* Remove mappings. */
436 pmap_t map,
437 addr64_t s,
438 addr64_t e);
439
440
441 #endif /* KERNEL_PRIVATE */
442
443 #endif /* _VM_PMAP_H_ */