xref: /xnu-8019.80.24/osfmk/mach/memory_object_types.h (revision a325d9c4a84054e40bbe985afedcb50ab80993ea)
1 /*
2  * Copyright (c) 2000-2016 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 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  [email protected]
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:	memory_object.h
60  *	Author:	Michael Wayne Young
61  *
62  *	External memory management interface definition.
63  */
64 
65 #ifndef _MACH_MEMORY_OBJECT_TYPES_H_
66 #define _MACH_MEMORY_OBJECT_TYPES_H_
67 
68 /*
69  *	User-visible types used in the external memory
70  *	management interface:
71  */
72 
73 #include <mach/port.h>
74 #include <mach/message.h>
75 #include <mach/vm_prot.h>
76 #include <mach/vm_sync.h>
77 #include <mach/vm_types.h>
78 #include <mach/machine/vm_types.h>
79 
80 #include <sys/cdefs.h>
81 
82 #if XNU_KERNEL_PRIVATE
83 #include <os/refcnt.h>
84 #if __LP64__
85 #define MEMORY_OBJECT_HAS_REFCOUNT 1
86 #else
87 #define MEMORY_OBJECT_HAS_REFCOUNT 0
88 #endif
89 #endif /* XNU_KERNEL_PRIVATE */
90 
91 #define VM_64_BIT_DATA_OBJECTS
92 
93 typedef unsigned long long      memory_object_offset_t;
94 typedef unsigned long long      memory_object_size_t;
95 typedef natural_t               memory_object_cluster_size_t;
96 typedef natural_t *             memory_object_fault_info_t;
97 
98 typedef unsigned long long      vm_object_id_t;
99 
100 
101 /*
102  * Temporary until real EMMI version gets re-implemented
103  */
104 
105 #ifdef  KERNEL_PRIVATE
106 
107 /* IMPORTANT: this type must match "ipc_object_bits_t" from ipc/ipc_port.h */
108 typedef natural_t mo_ipc_object_bits_t;
109 
110 struct memory_object_pager_ops; /* forward declaration */
111 
112 typedef struct vm_object       *memory_object_control_t;
113 /*
114  * "memory_object" used to be a Mach port in user space and could be passed
115  * as such to some kernel APIs.
116  *
117  * Its first field must match the "io_bits" field of a
118  * "struct ipc_object" to identify them as a "IKOT_MEMORY_OBJECT".
119  */
120 typedef struct memory_object {
121 	mo_ipc_object_bits_t                    mo_ikot; /* DO NOT CHANGE */
122 #if __LP64__
123 #if XNU_KERNEL_PRIVATE
124 	/*
125 	 * On LP64 there's a 4 byte hole that is perfect for a refcount.
126 	 * Expose it so that all pagers can take advantage of it.
127 	 */
128 	os_ref_atomic_t                         mo_ref;
129 #else
130 	unsigned int                            __mo_padding;
131 #endif /* XNU_KERNEL_PRIVATE */
132 #endif /* __LP64__ */
133 	const struct memory_object_pager_ops    *mo_pager_ops;
134 	memory_object_control_t                 mo_control;
135 } *memory_object_t;
136 
137 typedef const struct memory_object_pager_ops {
138 	void (*memory_object_reference)(
139 		memory_object_t mem_obj);
140 	void (*memory_object_deallocate)(
141 		memory_object_t mem_obj);
142 	kern_return_t (*memory_object_init)(
143 		memory_object_t mem_obj,
144 		memory_object_control_t mem_control,
145 		memory_object_cluster_size_t size);
146 	kern_return_t (*memory_object_terminate)(
147 		memory_object_t mem_obj);
148 	kern_return_t (*memory_object_data_request)(
149 		memory_object_t mem_obj,
150 		memory_object_offset_t offset,
151 		memory_object_cluster_size_t length,
152 		vm_prot_t desired_access,
153 		memory_object_fault_info_t fault_info);
154 	kern_return_t (*memory_object_data_return)(
155 		memory_object_t mem_obj,
156 		memory_object_offset_t offset,
157 		memory_object_cluster_size_t size,
158 		memory_object_offset_t *resid_offset,
159 		int *io_error,
160 		boolean_t dirty,
161 		boolean_t kernel_copy,
162 		int upl_flags);
163 	kern_return_t (*memory_object_data_initialize)(
164 		memory_object_t mem_obj,
165 		memory_object_offset_t offset,
166 		memory_object_cluster_size_t size);
167 	kern_return_t (*memory_object_data_unlock)(
168 		memory_object_t mem_obj,
169 		memory_object_offset_t offset,
170 		memory_object_size_t size,
171 		vm_prot_t desired_access);
172 	kern_return_t (*memory_object_synchronize)(
173 		memory_object_t mem_obj,
174 		memory_object_offset_t offset,
175 		memory_object_size_t size,
176 		vm_sync_t sync_flags);
177 	kern_return_t (*memory_object_map)(
178 		memory_object_t mem_obj,
179 		vm_prot_t prot);
180 	kern_return_t (*memory_object_last_unmap)(
181 		memory_object_t mem_obj);
182 	kern_return_t (*memory_object_data_reclaim)(
183 		memory_object_t mem_obj,
184 		boolean_t reclaim_backing_store);
185 	boolean_t (*memory_object_backing_object)(
186 		memory_object_t mem_obj,
187 		memory_object_offset_t mem_obj_offset,
188 		vm_object_t *backing_object,
189 		vm_object_offset_t *backing_offset);
190 	const char *memory_object_pager_name;
191 } * memory_object_pager_ops_t;
192 
193 #else   /* KERNEL_PRIVATE */
194 
195 typedef mach_port_t     memory_object_t;
196 /*
197  * vestigial, maintained for source compatibility,
198  * no MIG interface will accept or return non NULL
199  * objects for those.
200  */
201 typedef mach_port_t     memory_object_control_t;
202 
203 #endif  /* KERNEL_PRIVATE */
204 
205 typedef memory_object_t *memory_object_array_t;
206 /* A memory object ... */
207 /*  Used by the kernel to retrieve */
208 /*  or store data */
209 
210 typedef mach_port_t     memory_object_name_t;
211 /* Used to describe the memory ... */
212 /*  object in vm_regions() calls */
213 
214 typedef mach_port_t     memory_object_default_t;
215 /* Registered with the host ... */
216 /*  for creating new internal objects */
217 
218 #define MEMORY_OBJECT_NULL              ((memory_object_t) 0)
219 #define MEMORY_OBJECT_CONTROL_NULL      ((memory_object_control_t) 0)
220 #define MEMORY_OBJECT_NAME_NULL         ((memory_object_name_t) 0)
221 #define MEMORY_OBJECT_DEFAULT_NULL      ((memory_object_default_t) 0)
222 
223 
224 typedef int             memory_object_copy_strategy_t;
225 /* How memory manager handles copy: */
226 #define         MEMORY_OBJECT_COPY_NONE         0
227 /* ... No special support */
228 #define         MEMORY_OBJECT_COPY_CALL         1
229 /* ... Make call on memory manager */
230 #define         MEMORY_OBJECT_COPY_DELAY        2
231 /* ... Memory manager doesn't
232  *     change data externally.
233  */
234 #define         MEMORY_OBJECT_COPY_TEMPORARY    3
235 /* ... Memory manager doesn't
236  *     change data externally, and
237  *     doesn't need to see changes.
238  */
239 #define         MEMORY_OBJECT_COPY_SYMMETRIC    4
240 /* ... Memory manager doesn't
241  *     change data externally,
242  *     doesn't need to see changes,
243  *     and object will not be
244  *     multiply mapped.
245  *
246  *     XXX
247  *     Not yet safe for non-kernel use.
248  */
249 
250 #define         MEMORY_OBJECT_COPY_INVALID      5
251 /* ...	An invalid copy strategy,
252  *	for external objects which
253  *	have not been initialized.
254  *	Allows copy_strategy to be
255  *	examined without also
256  *	examining pager_ready and
257  *	internal.
258  */
259 
260 typedef int             memory_object_return_t;
261 /* Which pages to return to manager
262  *  this time (lock_request) */
263 #define         MEMORY_OBJECT_RETURN_NONE       0
264 /* ... don't return any. */
265 #define         MEMORY_OBJECT_RETURN_DIRTY      1
266 /* ... only dirty pages. */
267 #define         MEMORY_OBJECT_RETURN_ALL        2
268 /* ... dirty and precious pages. */
269 #define         MEMORY_OBJECT_RETURN_ANYTHING   3
270 /* ... any resident page. */
271 
272 /*
273  *	Data lock request flags
274  */
275 
276 #define         MEMORY_OBJECT_DATA_FLUSH        0x1
277 #define         MEMORY_OBJECT_DATA_NO_CHANGE    0x2
278 #define         MEMORY_OBJECT_DATA_PURGE        0x4
279 #define         MEMORY_OBJECT_COPY_SYNC         0x8
280 #define         MEMORY_OBJECT_DATA_SYNC         0x10
281 #define         MEMORY_OBJECT_IO_SYNC           0x20
282 #define         MEMORY_OBJECT_DATA_FLUSH_ALL    0x40
283 
284 /*
285  *	Types for the memory object flavor interfaces
286  */
287 
288 #define MEMORY_OBJECT_INFO_MAX      (1024)
289 typedef int     *memory_object_info_t;
290 typedef int      memory_object_flavor_t;
291 typedef int      memory_object_info_data_t[MEMORY_OBJECT_INFO_MAX];
292 
293 
294 #define MEMORY_OBJECT_PERFORMANCE_INFO  11
295 #define MEMORY_OBJECT_ATTRIBUTE_INFO    14
296 #define MEMORY_OBJECT_BEHAVIOR_INFO     15
297 
298 #ifdef  PRIVATE
299 
300 #define OLD_MEMORY_OBJECT_BEHAVIOR_INFO         10
301 #define OLD_MEMORY_OBJECT_ATTRIBUTE_INFO        12
302 
303 struct old_memory_object_behave_info {
304 	memory_object_copy_strategy_t   copy_strategy;
305 	boolean_t                       temporary;
306 	boolean_t                       invalidate;
307 };
308 
309 struct old_memory_object_attr_info {                    /* old attr list */
310 	boolean_t                       object_ready;
311 	boolean_t                       may_cache;
312 	memory_object_copy_strategy_t   copy_strategy;
313 };
314 
315 typedef struct old_memory_object_behave_info *old_memory_object_behave_info_t;
316 typedef struct old_memory_object_behave_info old_memory_object_behave_info_data_t;
317 typedef struct old_memory_object_attr_info *old_memory_object_attr_info_t;
318 typedef struct old_memory_object_attr_info old_memory_object_attr_info_data_t;
319 
320 #define OLD_MEMORY_OBJECT_BEHAVE_INFO_COUNT     ((mach_msg_type_number_t) \
321 	        (sizeof(old_memory_object_behave_info_data_t)/sizeof(int)))
322 #define OLD_MEMORY_OBJECT_ATTR_INFO_COUNT       ((mach_msg_type_number_t) \
323 	        (sizeof(old_memory_object_attr_info_data_t)/sizeof(int)))
324 
325 #ifdef KERNEL
326 
327 __BEGIN_DECLS
328 extern void memory_object_reference(memory_object_t object);
329 extern void memory_object_deallocate(memory_object_t object);
330 extern boolean_t memory_object_backing_object(
331 	memory_object_t mem_obj,
332 	memory_object_offset_t offset,
333 	vm_object_t *backing_object,
334 	vm_object_offset_t *backing_offset);
335 
336 extern void memory_object_control_reference(memory_object_control_t control);
337 extern void memory_object_control_deallocate(memory_object_control_t control);
338 extern int  memory_object_control_uiomove(memory_object_control_t, memory_object_offset_t, void *, int, int, int, int);
339 __END_DECLS
340 
341 #endif  /* KERNEL */
342 
343 #endif  /* PRIVATE */
344 
345 struct memory_object_perf_info {
346 	memory_object_cluster_size_t    cluster_size;
347 	boolean_t                       may_cache;
348 };
349 
350 struct memory_object_attr_info {
351 	memory_object_copy_strategy_t   copy_strategy;
352 	memory_object_cluster_size_t    cluster_size;
353 	boolean_t                       may_cache_object;
354 	boolean_t                       temporary;
355 };
356 
357 struct memory_object_behave_info {
358 	memory_object_copy_strategy_t   copy_strategy;
359 	boolean_t                       temporary;
360 	boolean_t                       invalidate;
361 	boolean_t                       silent_overwrite;
362 	boolean_t                       advisory_pageout;
363 };
364 
365 
366 typedef struct memory_object_behave_info *memory_object_behave_info_t;
367 typedef struct memory_object_behave_info memory_object_behave_info_data_t;
368 
369 typedef struct memory_object_perf_info  *memory_object_perf_info_t;
370 typedef struct memory_object_perf_info  memory_object_perf_info_data_t;
371 
372 typedef struct memory_object_attr_info  *memory_object_attr_info_t;
373 typedef struct memory_object_attr_info  memory_object_attr_info_data_t;
374 
375 #define MEMORY_OBJECT_BEHAVE_INFO_COUNT ((mach_msg_type_number_t)       \
376 	        (sizeof(memory_object_behave_info_data_t)/sizeof(int)))
377 #define MEMORY_OBJECT_PERF_INFO_COUNT   ((mach_msg_type_number_t)       \
378 	        (sizeof(memory_object_perf_info_data_t)/sizeof(int)))
379 #define MEMORY_OBJECT_ATTR_INFO_COUNT   ((mach_msg_type_number_t)       \
380 	        (sizeof(memory_object_attr_info_data_t)/sizeof(int)))
381 
382 #define invalid_memory_object_flavor(f)                                 \
383 	(f != MEMORY_OBJECT_ATTRIBUTE_INFO &&                           \
384 	 f != MEMORY_OBJECT_PERFORMANCE_INFO &&                         \
385 	 f != OLD_MEMORY_OBJECT_BEHAVIOR_INFO &&                        \
386 	 f != MEMORY_OBJECT_BEHAVIOR_INFO &&                            \
387 	 f != OLD_MEMORY_OBJECT_ATTRIBUTE_INFO)
388 
389 
390 /*
391  * Used to support options on memory_object_release_name call
392  */
393 #define MEMORY_OBJECT_TERMINATE_IDLE    0x1
394 #define MEMORY_OBJECT_RESPECT_CACHE     0x2
395 #define MEMORY_OBJECT_RELEASE_NO_OP     0x4
396 
397 
398 /* named entry processor mapping options */
399 /* enumerated */
400 #define MAP_MEM_NOOP                      0
401 #define MAP_MEM_COPYBACK                  1
402 #define MAP_MEM_IO                        2
403 #define MAP_MEM_WTHRU                     3
404 #define MAP_MEM_WCOMB                     4       /* Write combining mode */
405                                                   /* aka store gather     */
406 #define MAP_MEM_INNERWBACK                5
407 #define MAP_MEM_POSTED                    6
408 #define MAP_MEM_RT                        7
409 #define MAP_MEM_POSTED_REORDERED          8
410 #define MAP_MEM_POSTED_COMBINED_REORDERED 9
411 
412 #define GET_MAP_MEM(flags)      \
413 	((((unsigned int)(flags)) >> 24) & 0xFF)
414 
415 #define SET_MAP_MEM(caching, flags)     \
416 	((flags) = ((((unsigned int)(caching)) << 24) \
417 	                & 0xFF000000) | ((flags) & 0xFFFFFF));
418 
419 /* leave room for vm_prot bits (0xFF ?) */
420 #define MAP_MEM_LEDGER_TAGGED        0x002000 /* object owned by a specific task and ledger */
421 #define MAP_MEM_PURGABLE_KERNEL_ONLY 0x004000 /* volatility controlled by kernel */
422 #define MAP_MEM_GRAB_SECLUDED   0x008000 /* can grab secluded pages */
423 #define MAP_MEM_ONLY            0x010000 /* change processor caching  */
424 #define MAP_MEM_NAMED_CREATE    0x020000 /* create extant object      */
425 #define MAP_MEM_PURGABLE        0x040000 /* create a purgable VM object */
426 #define MAP_MEM_NAMED_REUSE     0x080000 /* reuse provided entry if identical */
427 #define MAP_MEM_USE_DATA_ADDR   0x100000 /* preserve address of data, rather than base of page */
428 #define MAP_MEM_VM_COPY         0x200000 /* make a copy of a VM range */
429 #define MAP_MEM_VM_SHARE        0x400000 /* extract a VM range for remap */
430 #define MAP_MEM_4K_DATA_ADDR    0x800000 /* preserve 4K aligned address of data */
431 
432 #define MAP_MEM_FLAGS_MASK 0x00FFFF00
433 #define MAP_MEM_FLAGS_USER (                               \
434 	MAP_MEM_PURGABLE_KERNEL_ONLY |                     \
435 	MAP_MEM_GRAB_SECLUDED |                            \
436 	MAP_MEM_ONLY |                                     \
437 	MAP_MEM_NAMED_CREATE |                             \
438 	MAP_MEM_PURGABLE |                                 \
439 	MAP_MEM_NAMED_REUSE |                              \
440 	MAP_MEM_USE_DATA_ADDR |                            \
441 	MAP_MEM_VM_COPY |                                  \
442 	MAP_MEM_VM_SHARE |                                 \
443 	MAP_MEM_LEDGER_TAGGED |                            \
444 	MAP_MEM_4K_DATA_ADDR)
445 #define MAP_MEM_FLAGS_ALL (                     \
446 	MAP_MEM_FLAGS_USER)
447 
448 #ifdef KERNEL
449 
450 /*
451  *  Universal Page List data structures
452  *
453  *  A UPL describes a bounded set of physical pages
454  *  associated with some range of an object or map
455  *  and a snapshot of the attributes associated with
456  *  each of those pages.
457  */
458 #ifdef PRIVATE
459 #define MAX_UPL_TRANSFER_BYTES  (1024 * 1024)
460 #define MAX_UPL_SIZE_BYTES      (1024 * 1024 * 64)
461 
462 #define MAX_UPL_SIZE            (MAX_UPL_SIZE_BYTES / PAGE_SIZE)
463 #define MAX_UPL_TRANSFER        (MAX_UPL_TRANSFER_BYTES / PAGE_SIZE)
464 
465 struct upl_page_info {
466 	ppnum_t         phys_addr;      /* physical page index number */
467 	unsigned int
468 #ifdef  XNU_KERNEL_PRIVATE
469 	    free_when_done:1,    /* page is to be freed on commit */
470 	    absent:1,           /* No valid data in this page */
471 	    dirty:1,            /* Page must be cleaned (O) */
472 	    precious:1,         /* must be cleaned, we have only copy */
473 	    device:1,           /* no page data, mapped dev memory */
474 	    speculative:1,      /* page is valid, but not yet accessed */
475 #define VMP_CS_BITS 4
476 #define VMP_CS_ALL_FALSE 0x0
477 #define VMP_CS_ALL_TRUE 0xF
478 	cs_validated:VMP_CS_BITS,     /* CODE SIGNING: page was validated */
479 	    cs_tainted:VMP_CS_BITS,   /* CODE SIGNING: page is tainted */
480 	    cs_nx:VMP_CS_BITS,        /* CODE SIGNING: page is NX */
481 
482 	    needed:1,           /* page should be left in cache on abort */
483 	    mark:1,             /* a mark flag for the creator to use as they wish */
484 	:0;                     /* force to long boundary */
485 #else
486 	opaque;                 /* use upl_page_xxx() accessor funcs */
487 #endif /* XNU_KERNEL_PRIVATE */
488 };
489 
490 #else
491 
492 struct upl_page_info {
493 	unsigned int    opaque[2];      /* use upl_page_xxx() accessor funcs */
494 };
495 
496 #endif /* PRIVATE */
497 
498 typedef struct upl_page_info    upl_page_info_t;
499 typedef upl_page_info_t         *upl_page_info_array_t;
500 typedef upl_page_info_array_t   upl_page_list_ptr_t;
501 
502 typedef uint32_t        upl_offset_t;   /* page-aligned byte offset */
503 typedef uint32_t        upl_size_t;     /* page-aligned byte size */
504 
505 /* upl invocation flags */
506 /* top nibble is used by super upl */
507 
508 typedef uint64_t upl_control_flags_t;
509 
510 #define UPL_FLAGS_NONE          0x00000000ULL
511 #define UPL_COPYOUT_FROM        0x00000001ULL
512 #define UPL_PRECIOUS            0x00000002ULL
513 #define UPL_NO_SYNC             0x00000004ULL
514 #define UPL_CLEAN_IN_PLACE      0x00000008ULL
515 #define UPL_NOBLOCK             0x00000010ULL
516 #define UPL_RET_ONLY_DIRTY      0x00000020ULL
517 #define UPL_SET_INTERNAL        0x00000040ULL
518 #define UPL_QUERY_OBJECT_TYPE   0x00000080ULL
519 #define UPL_RET_ONLY_ABSENT     0x00000100ULL /* used only for COPY_FROM = FALSE */
520 #define UPL_FILE_IO             0x00000200ULL
521 #define UPL_SET_LITE            0x00000400ULL
522 #define UPL_SET_INTERRUPTIBLE   0x00000800ULL
523 #define UPL_SET_IO_WIRE         0x00001000ULL
524 #define UPL_FOR_PAGEOUT         0x00002000ULL
525 #define UPL_WILL_BE_DUMPED      0x00004000ULL
526 #define UPL_FORCE_DATA_SYNC     0x00008000ULL
527 /* continued after the ticket bits... */
528 
529 #define UPL_PAGE_TICKET_MASK    0x000F0000ULL
530 #define UPL_PAGE_TICKET_SHIFT   16
531 
532 /* ... flags resume here */
533 #define UPL_BLOCK_ACCESS        0x00100000ULL
534 #define UPL_ENCRYPT             0x00200000ULL
535 #define UPL_NOZEROFILL          0x00400000ULL
536 #define UPL_WILL_MODIFY         0x00800000ULL /* caller will modify the pages */
537 
538 #define UPL_NEED_32BIT_ADDR     0x01000000ULL
539 #define UPL_UBC_MSYNC           0x02000000ULL
540 #define UPL_UBC_PAGEOUT         0x04000000ULL
541 #define UPL_UBC_PAGEIN          0x08000000ULL
542 #define UPL_REQUEST_SET_DIRTY   0x10000000ULL
543 #define UPL_REQUEST_NO_FAULT    0x20000000ULL /* fail if pages not all resident */
544 #define UPL_NOZEROFILLIO        0x40000000ULL /* allow non zerofill pages present */
545 #define UPL_REQUEST_FORCE_COHERENCY     0x80000000ULL
546 
547 /* UPL flags known by this kernel */
548 #define UPL_VALID_FLAGS         0xFFFFFFFFFFULL
549 
550 
551 /* upl abort error flags */
552 #define UPL_ABORT_RESTART               0x1
553 #define UPL_ABORT_UNAVAILABLE   0x2
554 #define UPL_ABORT_ERROR         0x4
555 #define UPL_ABORT_FREE_ON_EMPTY 0x8  /* only implemented in wrappers */
556 #define UPL_ABORT_DUMP_PAGES    0x10
557 #define UPL_ABORT_NOTIFY_EMPTY  0x20
558 /* deprecated: #define UPL_ABORT_ALLOW_ACCESS	0x40 */
559 #define UPL_ABORT_REFERENCE     0x80
560 
561 /* upl pages check flags */
562 #define UPL_CHECK_DIRTY         0x1
563 
564 
565 /*
566  *  upl pagein/pageout  flags
567  *
568  *
569  * when I/O is issued from this UPL it should be done synchronously
570  */
571 #define UPL_IOSYNC      0x1
572 
573 /*
574  * the passed in UPL should not have either a commit or abort
575  * applied to it by the underlying layers... the site that
576  * created the UPL is responsible for cleaning it up.
577  */
578 #define UPL_NOCOMMIT    0x2
579 
580 /*
581  * turn off any speculative read-ahead applied at the I/O layer
582  */
583 #define UPL_NORDAHEAD   0x4
584 
585 /*
586  * pageout request is targeting a real file
587  * as opposed to a swap file.
588  */
589 
590 #define UPL_VNODE_PAGER 0x8
591 /*
592  * this pageout is being originated as part of an explicit
593  * memory synchronization operation... no speculative clustering
594  * should be applied, only the range specified should be pushed.
595  */
596 #define UPL_MSYNC               0x10
597 
598 /*
599  *
600  */
601 #define UPL_PAGING_ENCRYPTED    0x20
602 
603 /*
604  * this pageout is being originated as part of an explicit
605  * memory synchronization operation that is checking for I/O
606  * errors and taking it's own action... if an error occurs,
607  * just abort the pages back into the cache unchanged
608  */
609 #define UPL_KEEPCACHED          0x40
610 
611 /*
612  * this pageout originated from within cluster_io to deal
613  * with a dirty page that hasn't yet been seen by the FS
614  * that backs it... tag it so that the FS can take the
615  * appropriate action w/r to its locking model since the
616  * pageout will reenter the FS for the same file currently
617  * being handled in this context.
618  */
619 #define UPL_NESTED_PAGEOUT      0x80
620 
621 /*
622  * we've detected a sequential access pattern and
623  * we are speculatively and aggressively pulling
624  * pages in... do not count these as real PAGEINs
625  * w/r to our hard throttle maintenance
626  */
627 #define UPL_IOSTREAMING         0x100
628 
629 /*
630  * Currently, it's only used for the swap pagein path.
631  * Since the swap + compressed pager layer manage their
632  * pages, these pages are not marked "absent" i.e. these
633  * are "valid" pages. The pagein path will _not_ issue an
634  * I/O (correctly) for valid pages. So, this flag is used
635  * to override that logic in the vnode I/O path.
636  */
637 #define UPL_IGNORE_VALID_PAGE_CHECK     0x200
638 
639 
640 
641 /* upl commit flags */
642 #define UPL_COMMIT_FREE_ON_EMPTY        0x1 /* only implemented in wrappers */
643 #define UPL_COMMIT_CLEAR_DIRTY          0x2
644 #define UPL_COMMIT_SET_DIRTY            0x4
645 #define UPL_COMMIT_INACTIVATE           0x8
646 #define UPL_COMMIT_NOTIFY_EMPTY         0x10
647 /* deprecated: #define UPL_COMMIT_ALLOW_ACCESS		0x20 */
648 #define UPL_COMMIT_CS_VALIDATED         0x40
649 #define UPL_COMMIT_CLEAR_PRECIOUS       0x80
650 #define UPL_COMMIT_SPECULATE            0x100
651 #define UPL_COMMIT_FREE_ABSENT          0x200
652 #define UPL_COMMIT_WRITTEN_BY_KERNEL    0x400
653 
654 #define UPL_COMMIT_KERNEL_ONLY_FLAGS    (UPL_COMMIT_CS_VALIDATED | UPL_COMMIT_FREE_ABSENT)
655 
656 /* flags for return of state from vm_map_get_upl,  vm_upl address space */
657 /* based call */
658 #define UPL_DEV_MEMORY                  0x1
659 #define UPL_PHYS_CONTIG                 0x2
660 
661 
662 /*
663  * Flags for the UPL page ops routine.  This routine is not exported
664  * out of the kernel at the moment and so the defs live here.
665  */
666 #define UPL_POP_DIRTY           0x1
667 #define UPL_POP_PAGEOUT         0x2
668 #define UPL_POP_PRECIOUS                0x4
669 #define UPL_POP_ABSENT          0x8
670 #define UPL_POP_BUSY                    0x10
671 
672 #define UPL_POP_PHYSICAL        0x10000000
673 #define UPL_POP_DUMP            0x20000000
674 #define UPL_POP_SET             0x40000000
675 #define UPL_POP_CLR             0x80000000
676 
677 /*
678  * Flags for the UPL range op routine.  This routine is not exported
679  * out of the kernel at the moemet and so the defs live here.
680  */
681 /*
682  * UPL_ROP_ABSENT: Returns the extent of the range presented which
683  * is absent, starting with the start address presented
684  */
685 #define UPL_ROP_ABSENT          0x01
686 /*
687  * UPL_ROP_PRESENT: Returns the extent of the range presented which
688  * is present (i.e. resident), starting with the start address presented
689  */
690 #define UPL_ROP_PRESENT         0x02
691 /*
692  * UPL_ROP_DUMP: Dump the pages which are found in the target object
693  * for the target range.
694  */
695 #define UPL_ROP_DUMP                    0x04
696 
697 #ifdef  PRIVATE
698 
699 #define UPL_REPRIO_INFO_MASK    (0xFFFFFFFF)
700 #define UPL_REPRIO_INFO_SHIFT   32
701 
702 /* access macros for upl_t */
703 
704 #define UPL_DEVICE_PAGE(upl) \
705 	(((upl)[0].phys_addr != 0) ? ((upl)[0].device) : FALSE)
706 
707 #define UPL_PAGE_PRESENT(upl, index) \
708 	((upl)[(index)].phys_addr != 0)
709 
710 #define UPL_PHYS_PAGE(upl, index) \
711 	((upl)[(index)].phys_addr)
712 
713 #define UPL_SPECULATIVE_PAGE(upl, index) \
714 	(((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].speculative) : FALSE)
715 
716 #define UPL_DIRTY_PAGE(upl, index) \
717 	(((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].dirty) : FALSE)
718 
719 #define UPL_PRECIOUS_PAGE(upl, index) \
720 	(((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].precious) : FALSE)
721 
722 #define UPL_VALID_PAGE(upl, index) \
723 	(((upl)[(index)].phys_addr != 0) ? (!((upl)[(index)].absent)) : FALSE)
724 
725 #define UPL_PAGEOUT_PAGE(upl, index) \
726 	(((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].free_when_done) : FALSE)
727 
728 #define UPL_SET_PAGE_FREE_ON_COMMIT(upl, index) \
729 	(((upl)[(index)].phys_addr != 0) ?            \
730 	 ((upl)[(index)].free_when_done = TRUE) : FALSE)
731 
732 #define UPL_CLR_PAGE_FREE_ON_COMMIT(upl, index) \
733 	(((upl)[(index)].phys_addr != 0) ?       \
734 	 ((upl)[(index)].free_when_done = FALSE) : FALSE)
735 
736 #define UPL_REPRIO_INFO_BLKNO(upl, index) \
737 	(((upl)->upl_reprio_info[(index)]) & UPL_REPRIO_INFO_MASK)
738 
739 #define UPL_REPRIO_INFO_LEN(upl, index) \
740 	((((upl)->upl_reprio_info[(index)]) >> UPL_REPRIO_INFO_SHIFT) & UPL_REPRIO_INFO_MASK)
741 
742 /* modifier macros for upl_t */
743 
744 #define UPL_SET_CS_VALIDATED(upl, index, value) \
745 	((upl)[(index)].cs_validated = (value))
746 
747 #define UPL_SET_CS_TAINTED(upl, index, value) \
748 	((upl)[(index)].cs_tainted = (value))
749 
750 #define UPL_SET_CS_NX(upl, index, value) \
751 	((upl)[(index)].cs_nx = (value))
752 
753 #define UPL_SET_REPRIO_INFO(upl, index, blkno, len) \
754 	((upl)->upl_reprio_info[(index)]) = (((uint64_t)(blkno) & UPL_REPRIO_INFO_MASK) | \
755 	(((uint64_t)(len) & UPL_REPRIO_INFO_MASK) << UPL_REPRIO_INFO_SHIFT))
756 
757 /* The call prototyped below is used strictly by UPL_GET_INTERNAL_PAGE_LIST */
758 
759 __BEGIN_DECLS
760 
761 extern vm_size_t        upl_offset_to_pagelist;
762 extern vm_size_t        upl_get_internal_pagelist_offset(void);
763 extern void*            upl_get_internal_vectorupl(upl_t);
764 extern upl_page_info_t*         upl_get_internal_vectorupl_pagelist(upl_t);
765 
766 __END_DECLS
767 
768 /*Use this variant to get the UPL's page list iff:*/
769 /*- the upl being passed in is already part of a vector UPL*/
770 /*- the page list you want is that of this "sub-upl" and not that of the entire vector-upl*/
771 
772 #define UPL_GET_INTERNAL_PAGE_LIST_SIMPLE(upl) \
773 	((upl_page_info_t *)((upl_offset_to_pagelist == 0) ?  \
774 	(uintptr_t)upl + (unsigned int)(upl_offset_to_pagelist = upl_get_internal_pagelist_offset()): \
775 	(uintptr_t)upl + (unsigned int)upl_offset_to_pagelist))
776 
777 /* UPL_GET_INTERNAL_PAGE_LIST is only valid on internal objects where the */
778 /* list request was made with the UPL_INTERNAL flag */
779 
780 
781 #define UPL_GET_INTERNAL_PAGE_LIST(upl) \
782 	((upl_get_internal_vectorupl(upl) != NULL ) ? (upl_get_internal_vectorupl_pagelist(upl)) : \
783 	((upl_page_info_t *)((upl_offset_to_pagelist == 0) ?  \
784 	(uintptr_t)upl + (unsigned int)(upl_offset_to_pagelist = upl_get_internal_pagelist_offset()): \
785 	(uintptr_t)upl + (unsigned int)upl_offset_to_pagelist)))
786 
787 __BEGIN_DECLS
788 
789 extern ppnum_t  upl_phys_page(upl_page_info_t *upl, int index);
790 extern boolean_t        upl_device_page(upl_page_info_t *upl);
791 extern boolean_t        upl_speculative_page(upl_page_info_t *upl, int index);
792 extern void     upl_clear_dirty(upl_t upl, boolean_t value);
793 extern void     upl_set_referenced(upl_t upl, boolean_t value);
794 extern void     upl_range_needed(upl_t upl, int index, int count);
795 #if CONFIG_IOSCHED
796 extern int64_t upl_blkno(upl_page_info_t *upl, int index);
797 extern void     upl_set_blkno(upl_t upl, vm_offset_t upl_offset, int size, int64_t blkno);
798 #endif
799 
800 __END_DECLS
801 
802 #endif /* PRIVATE */
803 
804 __BEGIN_DECLS
805 
806 extern boolean_t        upl_page_present(upl_page_info_t *upl, int index);
807 extern boolean_t        upl_dirty_page(upl_page_info_t *upl, int index);
808 extern boolean_t        upl_valid_page(upl_page_info_t *upl, int index);
809 extern void             upl_deallocate(upl_t upl);
810 extern void             upl_mark_decmp(upl_t upl);
811 extern void             upl_unmark_decmp(upl_t upl);
812 
813 #ifdef KERNEL_PRIVATE
814 
815 void upl_page_set_mark(upl_page_info_t *upl, int index, boolean_t v);
816 boolean_t upl_page_get_mark(upl_page_info_t *upl, int index);
817 
818 #endif // KERNEL_PRIVATE
819 
820 __END_DECLS
821 
822 #endif  /* KERNEL */
823 
824 #endif  /* _MACH_MEMORY_OBJECT_TYPES_H_ */
825