]> git.saurik.com Git - apple/xnu.git/blob - osfmk/vm/pmap.h
xnu-6153.121.1.tar.gz
[apple/xnu.git] / osfmk / vm / pmap.h
1 /*
2 * Copyright (c) 2000-2012 Apple 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 #include <kern/trustcache.h>
78
79 #ifdef KERNEL_PRIVATE
80
81 /*
82 * The following is a description of the interface to the
83 * machine-dependent "physical map" data structure. The module
84 * must provide a "pmap_t" data type that represents the
85 * set of valid virtual-to-physical addresses for one user
86 * address space. [The kernel address space is represented
87 * by a distinguished "pmap_t".] The routines described manage
88 * this type, install and update virtual-to-physical mappings,
89 * and perform operations on physical addresses common to
90 * many address spaces.
91 */
92
93 /* Copy between a physical page and a virtual address */
94 /* LP64todo - switch to vm_map_offset_t when it grows */
95 extern kern_return_t copypv(
96 addr64_t source,
97 addr64_t sink,
98 unsigned int size,
99 int which);
100 #define cppvPsnk 1
101 #define cppvPsnkb 31
102 #define cppvPsrc 2
103 #define cppvPsrcb 30
104 #define cppvFsnk 4
105 #define cppvFsnkb 29
106 #define cppvFsrc 8
107 #define cppvFsrcb 28
108 #define cppvNoModSnk 16
109 #define cppvNoModSnkb 27
110 #define cppvNoRefSrc 32
111 #define cppvNoRefSrcb 26
112 #define cppvKmap 64 /* Use the kernel's vm_map */
113 #define cppvKmapb 25
114
115 extern boolean_t pmap_has_managed_page(ppnum_t first, ppnum_t last);
116
117 #ifdef MACH_KERNEL_PRIVATE
118
119 #include <mach_assert.h>
120
121 #include <machine/pmap.h>
122 #include <vm/memory_types.h>
123
124 /*
125 * Routines used for initialization.
126 * There is traditionally also a pmap_bootstrap,
127 * used very early by machine-dependent code,
128 * but it is not part of the interface.
129 *
130 * LP64todo -
131 * These interfaces are tied to the size of the
132 * kernel pmap - and therefore use the "local"
133 * vm_offset_t, etc... types.
134 */
135
136 extern void *pmap_steal_memory(vm_size_t size); /* Early memory allocation */
137 extern void *pmap_steal_freeable_memory(vm_size_t size); /* Early memory allocation */
138
139 extern uint_t pmap_free_pages(void); /* report remaining unused physical pages */
140
141 extern void pmap_startup(vm_offset_t *startp, vm_offset_t *endp); /* allocate vm_page structs */
142
143 extern void pmap_init(void); /* Initialization, once we have kernel virtual memory. */
144
145 extern void mapping_adjust(void); /* Adjust free mapping count */
146
147 extern void mapping_free_prime(void); /* Primes the mapping block release list */
148
149 #ifndef MACHINE_PAGES
150 /*
151 * If machine/pmap.h defines MACHINE_PAGES, it must implement
152 * the above functions. The pmap module has complete control.
153 * Otherwise, it must implement the following functions:
154 * pmap_free_pages
155 * pmap_virtual_space
156 * pmap_next_page
157 * pmap_init
158 * and vm/vm_resident.c implements pmap_steal_memory and pmap_startup
159 * using pmap_free_pages, pmap_next_page, pmap_virtual_space,
160 * and pmap_enter. pmap_free_pages may over-estimate the number
161 * of unused physical pages, and pmap_next_page may return FALSE
162 * to indicate that there are no more unused pages to return.
163 * However, for best performance pmap_free_pages should be accurate.
164 */
165
166 /*
167 * Routines to return the next unused physical page.
168 */
169 extern boolean_t pmap_next_page(ppnum_t *pnum);
170 extern boolean_t pmap_next_page_hi(ppnum_t *pnum, boolean_t might_free);
171 #ifdef __x86_64__
172 extern kern_return_t pmap_next_page_large(ppnum_t *pnum);
173 extern void pmap_hi_pages_done(void);
174 #endif
175
176 /*
177 * Report virtual space available for the kernel.
178 */
179 extern void pmap_virtual_space(
180 vm_offset_t *virtual_start,
181 vm_offset_t *virtual_end);
182 #endif /* MACHINE_PAGES */
183
184 /*
185 * Routines to manage the physical map data structure.
186 */
187 extern pmap_t pmap_create_options( /* Create a pmap_t. */
188 ledger_t ledger,
189 vm_map_size_t size,
190 unsigned int flags);
191
192 extern pmap_t(pmap_kernel)(void); /* Return the kernel's pmap */
193 extern void pmap_reference(pmap_t pmap); /* Gain a reference. */
194 extern void pmap_destroy(pmap_t pmap); /* Release a reference. */
195 extern void pmap_switch(pmap_t);
196
197 #if MACH_ASSERT
198 extern void pmap_set_process(pmap_t pmap,
199 int pid,
200 char *procname);
201 #endif /* MACH_ASSERT */
202
203 extern kern_return_t pmap_enter( /* Enter a mapping */
204 pmap_t pmap,
205 vm_map_offset_t v,
206 ppnum_t pn,
207 vm_prot_t prot,
208 vm_prot_t fault_type,
209 unsigned int flags,
210 boolean_t wired);
211
212 extern kern_return_t pmap_enter_options(
213 pmap_t pmap,
214 vm_map_offset_t v,
215 ppnum_t pn,
216 vm_prot_t prot,
217 vm_prot_t fault_type,
218 unsigned int flags,
219 boolean_t wired,
220 unsigned int options,
221 void *arg);
222
223 extern void pmap_remove_some_phys(
224 pmap_t pmap,
225 ppnum_t pn);
226
227 extern void pmap_lock_phys_page(
228 ppnum_t pn);
229
230 extern void pmap_unlock_phys_page(
231 ppnum_t pn);
232
233
234 /*
235 * Routines that operate on physical addresses.
236 */
237
238 extern void pmap_page_protect( /* Restrict access to page. */
239 ppnum_t phys,
240 vm_prot_t prot);
241
242 extern void pmap_page_protect_options( /* Restrict access to page. */
243 ppnum_t phys,
244 vm_prot_t prot,
245 unsigned int options,
246 void *arg);
247
248 extern void(pmap_zero_page)(
249 ppnum_t pn);
250
251 extern void(pmap_zero_part_page)(
252 ppnum_t pn,
253 vm_offset_t offset,
254 vm_size_t len);
255
256 extern void(pmap_copy_page)(
257 ppnum_t src,
258 ppnum_t dest);
259
260 extern void(pmap_copy_part_page)(
261 ppnum_t src,
262 vm_offset_t src_offset,
263 ppnum_t dst,
264 vm_offset_t dst_offset,
265 vm_size_t len);
266
267 extern void(pmap_copy_part_lpage)(
268 vm_offset_t src,
269 ppnum_t dst,
270 vm_offset_t dst_offset,
271 vm_size_t len);
272
273 extern void(pmap_copy_part_rpage)(
274 ppnum_t src,
275 vm_offset_t src_offset,
276 vm_offset_t dst,
277 vm_size_t len);
278
279 extern unsigned int(pmap_disconnect)( /* disconnect mappings and return reference and change */
280 ppnum_t phys);
281
282 extern unsigned int(pmap_disconnect_options)( /* disconnect mappings and return reference and change */
283 ppnum_t phys,
284 unsigned int options,
285 void *arg);
286
287 extern kern_return_t(pmap_attribute_cache_sync)( /* Flush appropriate
288 * cache based on
289 * page number sent */
290 ppnum_t pn,
291 vm_size_t size,
292 vm_machine_attribute_t attribute,
293 vm_machine_attribute_val_t* value);
294
295 extern unsigned int(pmap_cache_attributes)(
296 ppnum_t pn);
297
298 /*
299 * Set (override) cache attributes for the specified physical page
300 */
301 extern void pmap_set_cache_attributes(
302 ppnum_t,
303 unsigned int);
304
305 extern void *pmap_map_compressor_page(
306 ppnum_t);
307
308 extern void pmap_unmap_compressor_page(
309 ppnum_t,
310 void*);
311
312 #if defined(__arm__) || defined(__arm64__)
313 /* ARM64_TODO */
314 extern boolean_t pmap_batch_set_cache_attributes(
315 ppnum_t,
316 unsigned int,
317 unsigned int,
318 unsigned int,
319 boolean_t,
320 unsigned int*);
321 #endif
322 extern void pmap_sync_page_data_phys(ppnum_t pa);
323 extern void pmap_sync_page_attributes_phys(ppnum_t pa);
324
325 /*
326 * debug/assertions. pmap_verify_free returns true iff
327 * the given physical page is mapped into no pmap.
328 * pmap_assert_free() will panic() if pn is not free.
329 */
330 extern boolean_t pmap_verify_free(ppnum_t pn);
331 #if MACH_ASSERT
332 extern void pmap_assert_free(ppnum_t pn);
333 #endif
334
335 /*
336 * Statistics routines
337 */
338 extern int(pmap_compressed)(pmap_t pmap);
339 extern int(pmap_resident_count)(pmap_t pmap);
340 extern int(pmap_resident_max)(pmap_t pmap);
341
342 /*
343 * Sundry required (internal) routines
344 */
345 #ifdef CURRENTLY_UNUSED_AND_UNTESTED
346 extern void pmap_collect(pmap_t pmap);/* Perform garbage
347 * collection, if any */
348 #endif
349 /*
350 * Optional routines
351 */
352 extern void(pmap_copy)( /* Copy range of mappings,
353 * if desired. */
354 pmap_t dest,
355 pmap_t source,
356 vm_map_offset_t dest_va,
357 vm_map_size_t size,
358 vm_map_offset_t source_va);
359
360 extern kern_return_t(pmap_attribute)( /* Get/Set special memory
361 * attributes */
362 pmap_t pmap,
363 vm_map_offset_t va,
364 vm_map_size_t size,
365 vm_machine_attribute_t attribute,
366 vm_machine_attribute_val_t* value);
367
368 /*
369 * Routines defined as macros.
370 */
371 #ifndef PMAP_ACTIVATE_USER
372 #ifndef PMAP_ACTIVATE
373 #define PMAP_ACTIVATE_USER(thr, cpu)
374 #else /* PMAP_ACTIVATE */
375 #define PMAP_ACTIVATE_USER(thr, cpu) { \
376 pmap_t pmap; \
377 \
378 pmap = (thr)->map->pmap; \
379 if (pmap != pmap_kernel()) \
380 PMAP_ACTIVATE(pmap, (thr), (cpu)); \
381 }
382 #endif /* PMAP_ACTIVATE */
383 #endif /* PMAP_ACTIVATE_USER */
384
385 #ifndef PMAP_DEACTIVATE_USER
386 #ifndef PMAP_DEACTIVATE
387 #define PMAP_DEACTIVATE_USER(thr, cpu)
388 #else /* PMAP_DEACTIVATE */
389 #define PMAP_DEACTIVATE_USER(thr, cpu) { \
390 pmap_t pmap; \
391 \
392 pmap = (thr)->map->pmap; \
393 if ((pmap) != pmap_kernel()) \
394 PMAP_DEACTIVATE(pmap, (thr), (cpu)); \
395 }
396 #endif /* PMAP_DEACTIVATE */
397 #endif /* PMAP_DEACTIVATE_USER */
398
399 #ifndef PMAP_ACTIVATE_KERNEL
400 #ifndef PMAP_ACTIVATE
401 #define PMAP_ACTIVATE_KERNEL(cpu)
402 #else /* PMAP_ACTIVATE */
403 #define PMAP_ACTIVATE_KERNEL(cpu) \
404 PMAP_ACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
405 #endif /* PMAP_ACTIVATE */
406 #endif /* PMAP_ACTIVATE_KERNEL */
407
408 #ifndef PMAP_DEACTIVATE_KERNEL
409 #ifndef PMAP_DEACTIVATE
410 #define PMAP_DEACTIVATE_KERNEL(cpu)
411 #else /* PMAP_DEACTIVATE */
412 #define PMAP_DEACTIVATE_KERNEL(cpu) \
413 PMAP_DEACTIVATE(pmap_kernel(), THREAD_NULL, cpu)
414 #endif /* PMAP_DEACTIVATE */
415 #endif /* PMAP_DEACTIVATE_KERNEL */
416
417 #ifndef PMAP_ENTER
418 /*
419 * Macro to be used in place of pmap_enter()
420 */
421 #define PMAP_ENTER(pmap, virtual_address, page, protection, fault_type, \
422 flags, wired, result) \
423 MACRO_BEGIN \
424 pmap_t __pmap = (pmap); \
425 vm_page_t __page = (page); \
426 int __options = 0; \
427 vm_object_t __obj; \
428 \
429 PMAP_ENTER_CHECK(__pmap, __page) \
430 __obj = VM_PAGE_OBJECT(__page); \
431 if (__obj->internal) { \
432 __options |= PMAP_OPTIONS_INTERNAL; \
433 } \
434 if (__page->vmp_reusable || __obj->all_reusable) { \
435 __options |= PMAP_OPTIONS_REUSABLE; \
436 } \
437 result = pmap_enter_options(__pmap, \
438 (virtual_address), \
439 VM_PAGE_GET_PHYS_PAGE(__page), \
440 (protection), \
441 (fault_type), \
442 (flags), \
443 (wired), \
444 __options, \
445 NULL); \
446 MACRO_END
447 #endif /* !PMAP_ENTER */
448
449 #ifndef PMAP_ENTER_OPTIONS
450 #define PMAP_ENTER_OPTIONS(pmap, virtual_address, page, protection, \
451 fault_type, flags, wired, options, result) \
452 MACRO_BEGIN \
453 pmap_t __pmap = (pmap); \
454 vm_page_t __page = (page); \
455 int __extra_options = 0; \
456 vm_object_t __obj; \
457 \
458 PMAP_ENTER_CHECK(__pmap, __page) \
459 __obj = VM_PAGE_OBJECT(__page); \
460 if (__obj->internal) { \
461 __extra_options |= PMAP_OPTIONS_INTERNAL; \
462 } \
463 if (__page->vmp_reusable || __obj->all_reusable) { \
464 __extra_options |= PMAP_OPTIONS_REUSABLE; \
465 } \
466 result = pmap_enter_options(__pmap, \
467 (virtual_address), \
468 VM_PAGE_GET_PHYS_PAGE(__page), \
469 (protection), \
470 (fault_type), \
471 (flags), \
472 (wired), \
473 (options) | __extra_options, \
474 NULL); \
475 MACRO_END
476 #endif /* !PMAP_ENTER_OPTIONS */
477
478 #ifndef PMAP_SET_CACHE_ATTR
479 #define PMAP_SET_CACHE_ATTR(mem, object, cache_attr, batch_pmap_op) \
480 MACRO_BEGIN \
481 if (!batch_pmap_op) { \
482 pmap_set_cache_attributes(VM_PAGE_GET_PHYS_PAGE(mem), cache_attr); \
483 object->set_cache_attr = TRUE; \
484 } \
485 MACRO_END
486 #endif /* PMAP_SET_CACHE_ATTR */
487
488 #ifndef PMAP_BATCH_SET_CACHE_ATTR
489 #if defined(__arm__) || defined(__arm64__)
490 #define PMAP_BATCH_SET_CACHE_ATTR(object, user_page_list, \
491 cache_attr, num_pages, batch_pmap_op) \
492 MACRO_BEGIN \
493 if ((batch_pmap_op)) { \
494 unsigned int __page_idx=0; \
495 unsigned int res=0; \
496 boolean_t batch=TRUE; \
497 while (__page_idx < (num_pages)) { \
498 if (!pmap_batch_set_cache_attributes( \
499 user_page_list[__page_idx].phys_addr, \
500 (cache_attr), \
501 (num_pages), \
502 (__page_idx), \
503 FALSE, \
504 (&res))) { \
505 batch = FALSE; \
506 break; \
507 } \
508 __page_idx++; \
509 } \
510 __page_idx=0; \
511 res=0; \
512 while (__page_idx < (num_pages)) { \
513 if (batch) \
514 (void)pmap_batch_set_cache_attributes( \
515 user_page_list[__page_idx].phys_addr, \
516 (cache_attr), \
517 (num_pages), \
518 (__page_idx), \
519 TRUE, \
520 (&res)); \
521 else \
522 pmap_set_cache_attributes( \
523 user_page_list[__page_idx].phys_addr, \
524 (cache_attr)); \
525 __page_idx++; \
526 } \
527 (object)->set_cache_attr = TRUE; \
528 } \
529 MACRO_END
530 #else
531 #define PMAP_BATCH_SET_CACHE_ATTR(object, user_page_list, \
532 cache_attr, num_pages, batch_pmap_op) \
533 MACRO_BEGIN \
534 if ((batch_pmap_op)) { \
535 unsigned int __page_idx=0; \
536 while (__page_idx < (num_pages)) { \
537 pmap_set_cache_attributes( \
538 user_page_list[__page_idx].phys_addr, \
539 (cache_attr)); \
540 __page_idx++; \
541 } \
542 (object)->set_cache_attr = TRUE; \
543 } \
544 MACRO_END
545 #endif
546 #endif /* PMAP_BATCH_SET_CACHE_ATTR */
547
548 #define PMAP_ENTER_CHECK(pmap, page) \
549 { \
550 if ((page)->vmp_error) { \
551 panic("VM page %p should not have an error\n", \
552 (page)); \
553 } \
554 }
555
556 /*
557 * Routines to manage reference/modify bits based on
558 * physical addresses, simulating them if not provided
559 * by the hardware.
560 */
561 struct pfc {
562 long pfc_cpus;
563 long pfc_invalid_global;
564 };
565
566 typedef struct pfc pmap_flush_context;
567
568 /* Clear reference bit */
569 extern void pmap_clear_reference(ppnum_t pn);
570 /* Return reference bit */
571 extern boolean_t(pmap_is_referenced)(ppnum_t pn);
572 /* Set modify bit */
573 extern void pmap_set_modify(ppnum_t pn);
574 /* Clear modify bit */
575 extern void pmap_clear_modify(ppnum_t pn);
576 /* Return modify bit */
577 extern boolean_t pmap_is_modified(ppnum_t pn);
578 /* Return modified and referenced bits */
579 extern unsigned int pmap_get_refmod(ppnum_t pn);
580 /* Clear modified and referenced bits */
581 extern void pmap_clear_refmod(ppnum_t pn, unsigned int mask);
582 #define VM_MEM_MODIFIED 0x01 /* Modified bit */
583 #define VM_MEM_REFERENCED 0x02 /* Referenced bit */
584 extern void pmap_clear_refmod_options(ppnum_t pn, unsigned int mask, unsigned int options, void *);
585
586
587 extern void pmap_flush_context_init(pmap_flush_context *);
588 extern void pmap_flush(pmap_flush_context *);
589
590 /*
591 * Routines that operate on ranges of virtual addresses.
592 */
593 extern void pmap_protect( /* Change protections. */
594 pmap_t map,
595 vm_map_offset_t s,
596 vm_map_offset_t e,
597 vm_prot_t prot);
598
599 extern void pmap_protect_options( /* Change protections. */
600 pmap_t map,
601 vm_map_offset_t s,
602 vm_map_offset_t e,
603 vm_prot_t prot,
604 unsigned int options,
605 void *arg);
606
607 extern void(pmap_pageable)(
608 pmap_t pmap,
609 vm_map_offset_t start,
610 vm_map_offset_t end,
611 boolean_t pageable);
612
613
614 extern uint64_t pmap_nesting_size_min;
615 extern uint64_t pmap_nesting_size_max;
616
617 extern kern_return_t pmap_nest(pmap_t,
618 pmap_t,
619 addr64_t,
620 addr64_t,
621 uint64_t);
622 extern kern_return_t pmap_unnest(pmap_t,
623 addr64_t,
624 uint64_t);
625
626 #define PMAP_UNNEST_CLEAN 1
627
628 extern kern_return_t pmap_unnest_options(pmap_t,
629 addr64_t,
630 uint64_t,
631 unsigned int);
632 extern boolean_t pmap_adjust_unnest_parameters(pmap_t, vm_map_offset_t *, vm_map_offset_t *);
633 extern void pmap_advise_pagezero_range(pmap_t, uint64_t);
634 #endif /* MACH_KERNEL_PRIVATE */
635
636 extern boolean_t pmap_is_noencrypt(ppnum_t);
637 extern void pmap_set_noencrypt(ppnum_t pn);
638 extern void pmap_clear_noencrypt(ppnum_t pn);
639
640 /*
641 * JMM - This portion is exported to other kernel components right now,
642 * but will be pulled back in the future when the needed functionality
643 * is provided in a cleaner manner.
644 */
645
646 extern pmap_t kernel_pmap; /* The kernel's map */
647 #define pmap_kernel() (kernel_pmap)
648
649 #define VM_MEM_SUPERPAGE 0x100 /* map a superpage instead of a base page */
650 #define VM_MEM_STACK 0x200
651
652 /* N.B. These use the same numerical space as the PMAP_EXPAND_OPTIONS
653 * definitions in i386/pmap_internal.h
654 */
655 #define PMAP_CREATE_64BIT 0x1
656 #if __x86_64__
657 #define PMAP_CREATE_EPT 0x2
658 #define PMAP_CREATE_KNOWN_FLAGS (PMAP_CREATE_64BIT | PMAP_CREATE_EPT)
659 #endif
660
661 #define PMAP_OPTIONS_NOWAIT 0x1 /* don't block, return
662 * KERN_RESOURCE_SHORTAGE
663 * instead */
664 #define PMAP_OPTIONS_NOENTER 0x2 /* expand pmap if needed
665 * but don't enter mapping
666 */
667 #define PMAP_OPTIONS_COMPRESSOR 0x4 /* credit the compressor for
668 * this operation */
669 #define PMAP_OPTIONS_INTERNAL 0x8 /* page from internal object */
670 #define PMAP_OPTIONS_REUSABLE 0x10 /* page is "reusable" */
671 #define PMAP_OPTIONS_NOFLUSH 0x20 /* delay flushing of pmap */
672 #define PMAP_OPTIONS_NOREFMOD 0x40 /* don't need ref/mod on disconnect */
673 #define PMAP_OPTIONS_ALT_ACCT 0x80 /* use alternate accounting scheme for page */
674 #define PMAP_OPTIONS_REMOVE 0x100 /* removing a mapping */
675 #define PMAP_OPTIONS_SET_REUSABLE 0x200 /* page is now "reusable" */
676 #define PMAP_OPTIONS_CLEAR_REUSABLE 0x400 /* page no longer "reusable" */
677 #define PMAP_OPTIONS_COMPRESSOR_IFF_MODIFIED 0x800 /* credit the compressor
678 * iff page was modified */
679 #define PMAP_OPTIONS_PROTECT_IMMEDIATE 0x1000 /* allow protections to be
680 * be upgraded */
681 #define PMAP_OPTIONS_CLEAR_WRITE 0x2000
682
683
684 #if !defined(__LP64__)
685 extern vm_offset_t pmap_extract(pmap_t pmap,
686 vm_map_offset_t va);
687 #endif
688 extern void pmap_change_wiring( /* Specify pageability */
689 pmap_t pmap,
690 vm_map_offset_t va,
691 boolean_t wired);
692
693 /* LP64todo - switch to vm_map_offset_t when it grows */
694 extern void pmap_remove( /* Remove mappings. */
695 pmap_t map,
696 vm_map_offset_t s,
697 vm_map_offset_t e);
698
699 extern void pmap_remove_options( /* Remove mappings. */
700 pmap_t map,
701 vm_map_offset_t s,
702 vm_map_offset_t e,
703 int options);
704
705 extern void fillPage(ppnum_t pa, unsigned int fill);
706
707 #if defined(__LP64__)
708 extern void pmap_pre_expand(pmap_t pmap, vm_map_offset_t vaddr);
709 extern kern_return_t pmap_pre_expand_large(pmap_t pmap, vm_map_offset_t vaddr);
710 extern vm_size_t pmap_query_pagesize(pmap_t map, vm_map_offset_t vaddr);
711 #endif
712
713 mach_vm_size_t pmap_query_resident(pmap_t pmap,
714 vm_map_offset_t s,
715 vm_map_offset_t e,
716 mach_vm_size_t *compressed_bytes_p);
717
718 /* Inform the pmap layer that there is a JIT entry in this map. */
719 extern void pmap_set_jit_entitled(pmap_t pmap);
720
721 /*
722 * Tell the pmap layer what range within the nested region the VM intends to
723 * use.
724 */
725 extern void pmap_trim(pmap_t grand, pmap_t subord, addr64_t vstart, addr64_t nstart, uint64_t size);
726
727 /*
728 * Dump page table contents into the specified buffer. Returns the number of
729 * bytes copied, 0 if insufficient space, (size_t)-1 if unsupported.
730 * This is expected to only be called from kernel debugger context,
731 * so synchronization is not required.
732 */
733
734 extern size_t pmap_dump_page_tables(pmap_t pmap, void *bufp, void *buf_end);
735
736 /*
737 * Indicates if any special policy is applied to this protection by the pmap
738 * layer.
739 */
740 bool pmap_has_prot_policy(vm_prot_t prot);
741
742 /*
743 * Causes the pmap to return any available pages that it can return cheaply to
744 * the VM.
745 */
746 uint64_t pmap_release_pages_fast(void);
747
748 #define PMAP_QUERY_PAGE_PRESENT 0x01
749 #define PMAP_QUERY_PAGE_REUSABLE 0x02
750 #define PMAP_QUERY_PAGE_INTERNAL 0x04
751 #define PMAP_QUERY_PAGE_ALTACCT 0x08
752 #define PMAP_QUERY_PAGE_COMPRESSED 0x10
753 #define PMAP_QUERY_PAGE_COMPRESSED_ALTACCT 0x20
754 extern kern_return_t pmap_query_page_info(
755 pmap_t pmap,
756 vm_map_offset_t va,
757 int *disp);
758
759 #if CONFIG_PGTRACE
760 int pmap_pgtrace_add_page(pmap_t pmap, vm_map_offset_t start, vm_map_offset_t end);
761 int pmap_pgtrace_delete_page(pmap_t pmap, vm_map_offset_t start, vm_map_offset_t end);
762 kern_return_t pmap_pgtrace_fault(pmap_t pmap, vm_map_offset_t va, arm_saved_state_t *ss);
763 #endif
764
765
766 #ifdef PLATFORM_BridgeOS
767 struct pmap_legacy_trust_cache {
768 struct pmap_legacy_trust_cache *next;
769 uuid_t uuid;
770 uint32_t num_hashes;
771 uint8_t hashes[][CS_CDHASH_LEN];
772 };
773 #else
774 struct pmap_legacy_trust_cache;
775 #endif
776
777 extern kern_return_t pmap_load_legacy_trust_cache(struct pmap_legacy_trust_cache *trust_cache,
778 const vm_size_t trust_cache_len);
779
780 struct pmap_image4_trust_cache {
781 // Filled by pmap layer.
782 struct pmap_image4_trust_cache const *next; // linked list linkage
783 struct trust_cache_module1 const *module; // pointer into module (within data below)
784
785 // Filled by caller.
786 // data is either an image4,
787 // or just the trust cache payload itself if the image4 manifest is external.
788 size_t data_len;
789 uint8_t const data[];
790 };
791
792 typedef enum {
793 PMAP_TC_SUCCESS = 0,
794 PMAP_TC_UNKNOWN_FORMAT = -1,
795 PMAP_TC_TOO_SMALL_FOR_HEADER = -2,
796 PMAP_TC_TOO_SMALL_FOR_ENTRIES = -3,
797 PMAP_TC_UNKNOWN_VERSION = -4,
798 PMAP_TC_ALREADY_LOADED = -5,
799 PMAP_TC_TOO_BIG = -6,
800 PMAP_TC_RESOURCE_SHORTAGE = -7,
801 PMAP_TC_MANIFEST_TOO_BIG = -8,
802 } pmap_tc_ret_t;
803
804 extern pmap_tc_ret_t pmap_load_image4_trust_cache(
805 struct pmap_image4_trust_cache *trust_cache, vm_size_t trust_cache_len,
806 uint8_t const *img4_manifest,
807 vm_size_t img4_manifest_buffer_len,
808 vm_size_t img4_manifest_actual_len,
809 bool dry_run);
810
811 extern bool pmap_is_trust_cache_loaded(const uuid_t uuid);
812 extern uint32_t pmap_lookup_in_static_trust_cache(const uint8_t cdhash[CS_CDHASH_LEN]);
813 extern bool pmap_lookup_in_loaded_trust_caches(const uint8_t cdhash[CS_CDHASH_LEN]);
814
815 extern bool pmap_in_ppl(void);
816
817 extern void *pmap_claim_reserved_ppl_page(void);
818 extern void pmap_free_reserved_ppl_page(void *kva);
819
820 extern void pmap_ledger_alloc_init(size_t);
821 extern ledger_t pmap_ledger_alloc(void);
822 extern void pmap_ledger_free(ledger_t);
823
824 #endif /* KERNEL_PRIVATE */
825
826 #endif /* _VM_PMAP_H_ */