]> git.saurik.com Git - apple/xnu.git/blame - osfmk/vm/pmap.h
xnu-1504.15.3.tar.gz
[apple/xnu.git] / osfmk / vm / pmap.h
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2007 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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
91447636
A
77#ifdef KERNEL_PRIVATE
78
1c79356b
A
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
55e303ae 91/* Copy between a physical page and a virtual address */
91447636 92/* LP64todo - switch to vm_map_offset_t when it grows */
55e303ae
A
93extern kern_return_t copypv(
94 addr64_t source,
95 addr64_t sink,
96 unsigned int size,
97 int which);
91447636
A
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
55e303ae 106#define cppvNoModSnk 16
91447636 107#define cppvNoModSnkb 27
55e303ae 108#define cppvNoRefSrc 32
91447636
A
109#define cppvNoRefSrcb 26
110#define cppvKmap 64 /* Use the kernel's vm_map */
111#define cppvKmapb 25
1c79356b 112
91447636 113#ifdef MACH_KERNEL_PRIVATE
1c79356b
A
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.
91447636
A
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.
1c79356b
A
127 */
128
91447636 129extern void *pmap_steal_memory(vm_size_t size);
1c79356b
A
130 /* During VM initialization,
131 * steal a chunk of memory.
132 */
133extern unsigned int pmap_free_pages(void); /* During VM initialization,
134 * report remaining unused
135 * physical pages.
136 */
137extern 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 */
2d21ac55
A
144extern void pmap_init(void) __attribute__((section("__TEXT, initcode")));
145 /* Initialization,
1c79356b
A
146 * after kernel runs
147 * in virtual memory.
148 */
149
91447636
A
150extern void mapping_adjust(void); /* Adjust free mapping count */
151
152extern void mapping_free_prime(void); /* Primes the mapping block release list */
153
1c79356b
A
154#ifndef MACHINE_PAGES
155/*
156 * If machine/pmap.h defines MACHINE_PAGES, it must implement
157 * the above functions. The pmap module has complete control.
158 * Otherwise, it must implement
159 * pmap_free_pages
160 * pmap_virtual_space
161 * pmap_next_page
162 * pmap_init
163 * and vm/vm_resident.c implements pmap_steal_memory and pmap_startup
164 * using pmap_free_pages, pmap_next_page, pmap_virtual_space,
165 * and pmap_enter. pmap_free_pages may over-estimate the number
166 * of unused physical pages, and pmap_next_page may return FALSE
167 * to indicate that there are no more unused pages to return.
168 * However, for best performance pmap_free_pages should be accurate.
169 */
170
55e303ae 171extern boolean_t pmap_next_page(ppnum_t *pnum);
0b4c1975 172extern boolean_t pmap_next_page_hi(ppnum_t *pnum);
1c79356b
A
173 /* During VM initialization,
174 * return the next unused
175 * physical page.
176 */
177extern void pmap_virtual_space(
178 vm_offset_t *virtual_start,
179 vm_offset_t *virtual_end);
180 /* During VM initialization,
181 * report virtual space
182 * available for the kernel.
183 */
184#endif /* MACHINE_PAGES */
185
186/*
187 * Routines to manage the physical map data structure.
188 */
0c530ab8
A
189extern pmap_t pmap_create( /* Create a pmap_t. */
190 vm_map_size_t size,
2d21ac55 191#ifdef __i386__
0c530ab8 192 boolean_t is_64bit);
2d21ac55
A
193#else
194 __unused boolean_t is_64bit);
195#endif
1c79356b
A
196extern pmap_t (pmap_kernel)(void); /* Return the kernel's pmap */
197extern void pmap_reference(pmap_t pmap); /* Gain a reference. */
198extern void pmap_destroy(pmap_t pmap); /* Release a reference. */
199extern void pmap_switch(pmap_t);
200
201
202extern void pmap_enter( /* Enter a mapping */
203 pmap_t pmap,
91447636 204 vm_map_offset_t v,
55e303ae 205 ppnum_t pn,
1c79356b 206 vm_prot_t prot,
9bccf70c 207 unsigned int flags,
1c79356b
A
208 boolean_t wired);
209
d1ecb069
A
210extern kern_return_t pmap_enter_options(
211 pmap_t pmap,
212 vm_map_offset_t v,
213 ppnum_t pn,
214 vm_prot_t prot,
215 unsigned int flags,
216 boolean_t wired,
217 unsigned int options);
218
0b4e3aa0
A
219extern void pmap_remove_some_phys(
220 pmap_t pmap,
55e303ae 221 ppnum_t pn);
0b4e3aa0 222
1c79356b
A
223
224/*
225 * Routines that operate on physical addresses.
226 */
0b4e3aa0 227
1c79356b 228extern void pmap_page_protect( /* Restrict access to page. */
55e303ae 229 ppnum_t phys,
1c79356b
A
230 vm_prot_t prot);
231
232extern void (pmap_zero_page)(
55e303ae 233 ppnum_t pn);
1c79356b
A
234
235extern void (pmap_zero_part_page)(
55e303ae 236 ppnum_t pn,
1c79356b
A
237 vm_offset_t offset,
238 vm_size_t len);
239
240extern void (pmap_copy_page)(
55e303ae
A
241 ppnum_t src,
242 ppnum_t dest);
1c79356b
A
243
244extern void (pmap_copy_part_page)(
55e303ae 245 ppnum_t src,
1c79356b 246 vm_offset_t src_offset,
55e303ae 247 ppnum_t dst,
1c79356b
A
248 vm_offset_t dst_offset,
249 vm_size_t len);
250
251extern void (pmap_copy_part_lpage)(
252 vm_offset_t src,
55e303ae 253 ppnum_t dst,
1c79356b
A
254 vm_offset_t dst_offset,
255 vm_size_t len);
256
257extern void (pmap_copy_part_rpage)(
55e303ae 258 ppnum_t src,
1c79356b
A
259 vm_offset_t src_offset,
260 vm_offset_t dst,
261 vm_size_t len);
91447636
A
262
263extern unsigned int (pmap_disconnect)( /* disconnect mappings and return reference and change */
264 ppnum_t phys);
265
266extern kern_return_t (pmap_attribute_cache_sync)( /* Flush appropriate
267 * cache based on
268 * page number sent */
269 ppnum_t pn,
270 vm_size_t size,
271 vm_machine_attribute_t attribute,
272 vm_machine_attribute_val_t* value);
1c79356b 273
0c530ab8
A
274extern unsigned int (pmap_cache_attributes)(
275 ppnum_t pn);
276
2d21ac55
A
277extern void pmap_sync_page_data_phys(ppnum_t pa);
278extern void pmap_sync_page_attributes_phys(ppnum_t pa);
279
1c79356b
A
280/*
281 * debug/assertions. pmap_verify_free returns true iff
282 * the given physical page is mapped into no pmap.
283 */
55e303ae 284extern boolean_t pmap_verify_free(ppnum_t pn);
1c79356b
A
285
286/*
287 * Statistics routines
288 */
289extern int (pmap_resident_count)(pmap_t pmap);
2d21ac55 290extern int (pmap_resident_max)(pmap_t pmap);
1c79356b
A
291
292/*
293 * Sundry required (internal) routines
294 */
2d21ac55 295#ifdef CURRENTLY_UNUSED_AND_UNTESTED
1c79356b
A
296extern void pmap_collect(pmap_t pmap);/* Perform garbage
297 * collection, if any */
2d21ac55 298#endif
1c79356b
A
299/*
300 * Optional routines
301 */
302extern void (pmap_copy)( /* Copy range of mappings,
303 * if desired. */
304 pmap_t dest,
305 pmap_t source,
91447636
A
306 vm_map_offset_t dest_va,
307 vm_map_size_t size,
308 vm_map_offset_t source_va);
1c79356b
A
309
310extern kern_return_t (pmap_attribute)( /* Get/Set special memory
311 * attributes */
312 pmap_t pmap,
91447636
A
313 vm_map_offset_t va,
314 vm_map_size_t size,
1c79356b
A
315 vm_machine_attribute_t attribute,
316 vm_machine_attribute_val_t* value);
317
318/*
319 * Routines defined as macros.
320 */
321#ifndef PMAP_ACTIVATE_USER
91447636
A
322#ifndef PMAP_ACTIVATE
323#define PMAP_ACTIVATE_USER(thr, cpu)
324#else /* PMAP_ACTIVATE */
325#define PMAP_ACTIVATE_USER(thr, cpu) { \
1c79356b
A
326 pmap_t pmap; \
327 \
91447636 328 pmap = (thr)->map->pmap; \
1c79356b 329 if (pmap != pmap_kernel()) \
91447636 330 PMAP_ACTIVATE(pmap, (thr), (cpu)); \
1c79356b 331}
91447636 332#endif /* PMAP_ACTIVATE */
1c79356b
A
333#endif /* PMAP_ACTIVATE_USER */
334
335#ifndef PMAP_DEACTIVATE_USER
91447636
A
336#ifndef PMAP_DEACTIVATE
337#define PMAP_DEACTIVATE_USER(thr, cpu)
338#else /* PMAP_DEACTIVATE */
339#define PMAP_DEACTIVATE_USER(thr, cpu) { \
1c79356b
A
340 pmap_t pmap; \
341 \
91447636
A
342 pmap = (thr)->map->pmap; \
343 if ((pmap) != pmap_kernel()) \
344 PMAP_DEACTIVATE(pmap, (thr), (cpu)); \
1c79356b 345}
91447636 346#endif /* PMAP_DEACTIVATE */
1c79356b
A
347#endif /* PMAP_DEACTIVATE_USER */
348
349#ifndef PMAP_ACTIVATE_KERNEL
91447636
A
350#ifndef PMAP_ACTIVATE
351#define PMAP_ACTIVATE_KERNEL(cpu)
352#else /* PMAP_ACTIVATE */
1c79356b 353#define PMAP_ACTIVATE_KERNEL(cpu) \
91447636
A
354 PMAP_ACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
355#endif /* PMAP_ACTIVATE */
1c79356b
A
356#endif /* PMAP_ACTIVATE_KERNEL */
357
358#ifndef PMAP_DEACTIVATE_KERNEL
91447636
A
359#ifndef PMAP_DEACTIVATE
360#define PMAP_DEACTIVATE_KERNEL(cpu)
361#else /* PMAP_DEACTIVATE */
1c79356b 362#define PMAP_DEACTIVATE_KERNEL(cpu) \
91447636
A
363 PMAP_DEACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
364#endif /* PMAP_DEACTIVATE */
1c79356b
A
365#endif /* PMAP_DEACTIVATE_KERNEL */
366
367#ifndef PMAP_ENTER
368/*
369 * Macro to be used in place of pmap_enter()
370 */
9bccf70c 371#define PMAP_ENTER(pmap, virtual_address, page, protection, flags, wired) \
91447636
A
372 MACRO_BEGIN \
373 pmap_t __pmap = (pmap); \
374 vm_page_t __page = (page); \
375 \
d1ecb069
A
376 PMAP_ENTER_CHECK(__pmap, __page) \
377 pmap_enter(__pmap, \
378 (virtual_address), \
379 __page->phys_page, \
380 (protection), \
381 (flags), \
382 (wired)); \
383 MACRO_END
384#endif /* !PMAP_ENTER */
385
386#ifndef PMAP_ENTER_OPTIONS
387#define PMAP_ENTER_OPTIONS(pmap, virtual_address, page, protection, \
388 flags, wired, options, result) \
389 MACRO_BEGIN \
390 pmap_t __pmap = (pmap); \
391 vm_page_t __page = (page); \
392 \
393 PMAP_ENTER_CHECK(__pmap, __page) \
394 result = pmap_enter_options(__pmap, \
395 (virtual_address), \
396 __page->phys_page, \
397 (protection), \
398 (flags), \
399 (wired), \
400 options); \
401 MACRO_END
402#endif /* !PMAP_ENTER_OPTIONS */
403
404#define PMAP_ENTER_CHECK(pmap, page) \
405{ \
406 if ((pmap) != kernel_pmap) { \
407 ASSERT_PAGE_DECRYPTED(page); \
91447636 408 } \
d1ecb069 409 if ((page)->error) { \
2d21ac55 410 panic("VM page %p should not have an error\n", \
d1ecb069 411 (page)); \
2d21ac55 412 } \
d1ecb069 413}
1c79356b 414
1c79356b
A
415/*
416 * Routines to manage reference/modify bits based on
417 * physical addresses, simulating them if not provided
418 * by the hardware.
419 */
420 /* Clear reference bit */
55e303ae 421extern void pmap_clear_reference(ppnum_t pn);
1c79356b 422 /* Return reference bit */
55e303ae 423extern boolean_t (pmap_is_referenced)(ppnum_t pn);
1c79356b 424 /* Set modify bit */
55e303ae 425extern void pmap_set_modify(ppnum_t pn);
1c79356b 426 /* Clear modify bit */
55e303ae 427extern void pmap_clear_modify(ppnum_t pn);
1c79356b 428 /* Return modify bit */
55e303ae 429extern boolean_t pmap_is_modified(ppnum_t pn);
91447636
A
430 /* Return modified and referenced bits */
431extern unsigned int pmap_get_refmod(ppnum_t pn);
432 /* Clear modified and referenced bits */
433extern void pmap_clear_refmod(ppnum_t pn, unsigned int mask);
434#define VM_MEM_MODIFIED 0x01 /* Modified bit */
435#define VM_MEM_REFERENCED 0x02 /* Referenced bit */
1c79356b
A
436
437/*
438 * Routines that operate on ranges of virtual addresses.
439 */
1c79356b
A
440extern void pmap_protect( /* Change protections. */
441 pmap_t map,
91447636
A
442 vm_map_offset_t s,
443 vm_map_offset_t e,
1c79356b
A
444 vm_prot_t prot);
445
446extern void (pmap_pageable)(
447 pmap_t pmap,
91447636
A
448 vm_map_offset_t start,
449 vm_map_offset_t end,
1c79356b
A
450 boolean_t pageable);
451
b0d623f7 452
2d21ac55
A
453extern uint64_t pmap_nesting_size_min;
454extern uint64_t pmap_nesting_size_max;
b0d623f7 455
2d21ac55
A
456extern kern_return_t pmap_nest(pmap_t grand,
457 pmap_t subord,
458 addr64_t vstart,
459 addr64_t nstart,
460 uint64_t size);
461extern kern_return_t pmap_unnest(pmap_t grand,
462 addr64_t vaddr,
463 uint64_t size);
b0d623f7 464extern boolean_t pmap_adjust_unnest_parameters(pmap_t, vm_map_offset_t *, vm_map_offset_t *);
91447636 465#endif /* MACH_KERNEL_PRIVATE */
9bccf70c 466
0b4c1975
A
467extern boolean_t pmap_is_noencrypt(ppnum_t);
468extern void pmap_set_noencrypt(ppnum_t pn);
469extern void pmap_clear_noencrypt(ppnum_t pn);
470
9bccf70c
A
471/*
472 * JMM - This portion is exported to other kernel components right now,
473 * but will be pulled back in the future when the needed functionality
474 * is provided in a cleaner manner.
475 */
476
9bccf70c
A
477extern pmap_t kernel_pmap; /* The kernel's map */
478#define pmap_kernel() (kernel_pmap)
479
480/* machine independent WIMG bits */
481
91447636
A
482#define VM_MEM_GUARDED 0x1 /* (G) Guarded Storage */
483#define VM_MEM_COHERENT 0x2 /* (M) Memory Coherency */
484#define VM_MEM_NOT_CACHEABLE 0x4 /* (I) Cache Inhibit */
485#define VM_MEM_WRITE_THROUGH 0x8 /* (W) Write-Through */
9bccf70c
A
486
487#define VM_WIMG_MASK 0xFF
488#define VM_WIMG_USE_DEFAULT 0x80000000
489
b0d623f7 490#define VM_MEM_SUPERPAGE 0x100 /* map a superpage instead of a base page */
d1ecb069
A
491
492#define PMAP_OPTIONS_NOWAIT 0x1 /* don't block, return
493 * KERN_RESOURCE_SHORTAGE
494 * instead */
495
b0d623f7 496#if !defined(__LP64__)
1c79356b 497extern vm_offset_t pmap_extract(pmap_t pmap,
91447636 498 vm_map_offset_t va);
b0d623f7 499#endif
1c79356b
A
500extern void pmap_change_wiring( /* Specify pageability */
501 pmap_t pmap,
91447636 502 vm_map_offset_t va,
1c79356b 503 boolean_t wired);
9bccf70c 504
91447636 505/* LP64todo - switch to vm_map_offset_t when it grows */
9bccf70c
A
506extern void pmap_remove( /* Remove mappings. */
507 pmap_t map,
2d21ac55
A
508 vm_map_offset_t s,
509 vm_map_offset_t e);
510
511extern void fillPage(ppnum_t pa, unsigned int fill);
55e303ae 512
2d21ac55
A
513extern void pmap_map_sharedpage(task_t task, pmap_t pmap);
514extern void pmap_unmap_sharedpage(pmap_t pmap);
9bccf70c 515
b0d623f7
A
516#if defined(__LP64__)
517void pmap_pre_expand(pmap_t pmap, vm_map_offset_t vaddr);
518#endif
519
91447636 520#endif /* KERNEL_PRIVATE */
9bccf70c 521
1c79356b 522#endif /* _VM_PMAP_H_ */