2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
59 * File: memory_object.h
60 * Author: Michael Wayne Young
62 * External memory management interface definition.
65 #ifndef _MACH_MEMORY_OBJECT_TYPES_H_
66 #define _MACH_MEMORY_OBJECT_TYPES_H_
69 * User-visible types used in the external memory
70 * management interface:
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>
80 #include <sys/cdefs.h>
82 #define VM_64_BIT_DATA_OBJECTS
84 typedef unsigned long long memory_object_offset_t
;
85 typedef unsigned long long memory_object_size_t
;
86 typedef natural_t memory_object_cluster_size_t
;
87 typedef natural_t
* memory_object_fault_info_t
;
91 * Temporary until real EMMI version gets re-implemented
96 struct memory_object_pager_ops
; /* forward declaration */
98 typedef struct memory_object
{
99 const struct memory_object_pager_ops
*mo_pager_ops
;
102 typedef struct memory_object_control
{
103 struct vm_object
*moc_object
;
104 unsigned int moc_ikot
; /* XXX fake ip_kotype */
105 } *memory_object_control_t
;
107 typedef const struct memory_object_pager_ops
{
108 void (*memory_object_reference
)(
109 memory_object_t mem_obj
);
110 void (*memory_object_deallocate
)(
111 memory_object_t mem_obj
);
112 kern_return_t (*memory_object_init
)(
113 memory_object_t mem_obj
,
114 memory_object_control_t mem_control
,
115 memory_object_cluster_size_t size
);
116 kern_return_t (*memory_object_terminate
)(
117 memory_object_t mem_obj
);
118 kern_return_t (*memory_object_data_request
)(
119 memory_object_t mem_obj
,
120 memory_object_offset_t offset
,
121 memory_object_cluster_size_t length
,
122 vm_prot_t desired_access
,
123 memory_object_fault_info_t fault_info
);
124 kern_return_t (*memory_object_data_return
)(
125 memory_object_t mem_obj
,
126 memory_object_offset_t offset
,
128 memory_object_offset_t
*resid_offset
,
131 boolean_t kernel_copy
,
133 kern_return_t (*memory_object_data_initialize
)(
134 memory_object_t mem_obj
,
135 memory_object_offset_t offset
,
137 kern_return_t (*memory_object_data_unlock
)(
138 memory_object_t mem_obj
,
139 memory_object_offset_t offset
,
141 vm_prot_t desired_access
);
142 kern_return_t (*memory_object_synchronize
)(
143 memory_object_t mem_obj
,
144 memory_object_offset_t offset
,
146 vm_sync_t sync_flags
);
147 kern_return_t (*memory_object_unmap
)(
148 memory_object_t mem_obj
);
149 const char *memory_object_pager_name
;
150 } * memory_object_pager_ops_t
;
152 #else /* KERNEL_PRIVATE */
154 typedef mach_port_t memory_object_t
;
155 typedef mach_port_t memory_object_control_t
;
157 #endif /* KERNEL_PRIVATE */
159 typedef memory_object_t
*memory_object_array_t
;
160 /* A memory object ... */
161 /* Used by the kernel to retrieve */
164 typedef mach_port_t memory_object_name_t
;
165 /* Used to describe the memory ... */
166 /* object in vm_regions() calls */
168 typedef mach_port_t memory_object_default_t
;
169 /* Registered with the host ... */
170 /* for creating new internal objects */
172 #define MEMORY_OBJECT_NULL ((memory_object_t) 0)
173 #define MEMORY_OBJECT_CONTROL_NULL ((memory_object_control_t) 0)
174 #define MEMORY_OBJECT_NAME_NULL ((memory_object_name_t) 0)
175 #define MEMORY_OBJECT_DEFAULT_NULL ((memory_object_default_t) 0)
178 typedef int memory_object_copy_strategy_t
;
179 /* How memory manager handles copy: */
180 #define MEMORY_OBJECT_COPY_NONE 0
181 /* ... No special support */
182 #define MEMORY_OBJECT_COPY_CALL 1
183 /* ... Make call on memory manager */
184 #define MEMORY_OBJECT_COPY_DELAY 2
185 /* ... Memory manager doesn't
186 * change data externally.
188 #define MEMORY_OBJECT_COPY_TEMPORARY 3
189 /* ... Memory manager doesn't
190 * change data externally, and
191 * doesn't need to see changes.
193 #define MEMORY_OBJECT_COPY_SYMMETRIC 4
194 /* ... Memory manager doesn't
195 * change data externally,
196 * doesn't need to see changes,
197 * and object will not be
201 * Not yet safe for non-kernel use.
204 #define MEMORY_OBJECT_COPY_INVALID 5
205 /* ... An invalid copy strategy,
206 * for external objects which
207 * have not been initialized.
208 * Allows copy_strategy to be
209 * examined without also
210 * examining pager_ready and
214 typedef int memory_object_return_t
;
215 /* Which pages to return to manager
216 this time (lock_request) */
217 #define MEMORY_OBJECT_RETURN_NONE 0
218 /* ... don't return any. */
219 #define MEMORY_OBJECT_RETURN_DIRTY 1
220 /* ... only dirty pages. */
221 #define MEMORY_OBJECT_RETURN_ALL 2
222 /* ... dirty and precious pages. */
223 #define MEMORY_OBJECT_RETURN_ANYTHING 3
224 /* ... any resident page. */
227 * Data lock request flags
230 #define MEMORY_OBJECT_DATA_FLUSH 0x1
231 #define MEMORY_OBJECT_DATA_NO_CHANGE 0x2
232 #define MEMORY_OBJECT_DATA_PURGE 0x4
233 #define MEMORY_OBJECT_COPY_SYNC 0x8
234 #define MEMORY_OBJECT_DATA_SYNC 0x10
235 #define MEMORY_OBJECT_IO_SYNC 0x20
238 * Types for the memory object flavor interfaces
241 #define MEMORY_OBJECT_INFO_MAX (1024)
242 typedef int *memory_object_info_t
;
243 typedef int memory_object_flavor_t
;
244 typedef int memory_object_info_data_t
[MEMORY_OBJECT_INFO_MAX
];
247 #define MEMORY_OBJECT_PERFORMANCE_INFO 11
248 #define MEMORY_OBJECT_ATTRIBUTE_INFO 14
249 #define MEMORY_OBJECT_BEHAVIOR_INFO 15
253 #define OLD_MEMORY_OBJECT_BEHAVIOR_INFO 10
254 #define OLD_MEMORY_OBJECT_ATTRIBUTE_INFO 12
256 struct old_memory_object_behave_info
{
257 memory_object_copy_strategy_t copy_strategy
;
259 boolean_t invalidate
;
262 struct old_memory_object_attr_info
{ /* old attr list */
263 boolean_t object_ready
;
265 memory_object_copy_strategy_t copy_strategy
;
268 typedef struct old_memory_object_behave_info
*old_memory_object_behave_info_t
;
269 typedef struct old_memory_object_behave_info old_memory_object_behave_info_data_t
;
270 typedef struct old_memory_object_attr_info
*old_memory_object_attr_info_t
;
271 typedef struct old_memory_object_attr_info old_memory_object_attr_info_data_t
;
273 #define OLD_MEMORY_OBJECT_BEHAVE_INFO_COUNT ((mach_msg_type_number_t) \
274 (sizeof(old_memory_object_behave_info_data_t)/sizeof(int)))
275 #define OLD_MEMORY_OBJECT_ATTR_INFO_COUNT ((mach_msg_type_number_t) \
276 (sizeof(old_memory_object_attr_info_data_t)/sizeof(int)))
281 extern void memory_object_reference(memory_object_t object
);
282 extern void memory_object_deallocate(memory_object_t object
);
284 extern void memory_object_default_reference(memory_object_default_t
);
285 extern void memory_object_default_deallocate(memory_object_default_t
);
287 extern void memory_object_control_reference(memory_object_control_t control
);
288 extern void memory_object_control_deallocate(memory_object_control_t control
);
289 extern int memory_object_control_uiomove(memory_object_control_t
, memory_object_offset_t
, void *, int, int, int, int);
296 struct memory_object_perf_info
{
297 memory_object_cluster_size_t cluster_size
;
301 struct memory_object_attr_info
{
302 memory_object_copy_strategy_t copy_strategy
;
303 memory_object_cluster_size_t cluster_size
;
304 boolean_t may_cache_object
;
308 struct memory_object_behave_info
{
309 memory_object_copy_strategy_t copy_strategy
;
311 boolean_t invalidate
;
312 boolean_t silent_overwrite
;
313 boolean_t advisory_pageout
;
317 typedef struct memory_object_behave_info
*memory_object_behave_info_t
;
318 typedef struct memory_object_behave_info memory_object_behave_info_data_t
;
320 typedef struct memory_object_perf_info
*memory_object_perf_info_t
;
321 typedef struct memory_object_perf_info memory_object_perf_info_data_t
;
323 typedef struct memory_object_attr_info
*memory_object_attr_info_t
;
324 typedef struct memory_object_attr_info memory_object_attr_info_data_t
;
326 #define MEMORY_OBJECT_BEHAVE_INFO_COUNT ((mach_msg_type_number_t) \
327 (sizeof(memory_object_behave_info_data_t)/sizeof(int)))
328 #define MEMORY_OBJECT_PERF_INFO_COUNT ((mach_msg_type_number_t) \
329 (sizeof(memory_object_perf_info_data_t)/sizeof(int)))
330 #define MEMORY_OBJECT_ATTR_INFO_COUNT ((mach_msg_type_number_t) \
331 (sizeof(memory_object_attr_info_data_t)/sizeof(int)))
333 #define invalid_memory_object_flavor(f) \
334 (f != MEMORY_OBJECT_ATTRIBUTE_INFO && \
335 f != MEMORY_OBJECT_PERFORMANCE_INFO && \
336 f != OLD_MEMORY_OBJECT_BEHAVIOR_INFO && \
337 f != MEMORY_OBJECT_BEHAVIOR_INFO && \
338 f != OLD_MEMORY_OBJECT_ATTRIBUTE_INFO)
342 * Used to support options on memory_object_release_name call
344 #define MEMORY_OBJECT_TERMINATE_IDLE 0x1
345 #define MEMORY_OBJECT_RESPECT_CACHE 0x2
346 #define MEMORY_OBJECT_RELEASE_NO_OP 0x4
349 /* named entry processor mapping options */
351 #define MAP_MEM_NOOP 0
352 #define MAP_MEM_COPYBACK 1
354 #define MAP_MEM_WTHRU 3
355 #define MAP_MEM_WCOMB 4 /* Write combining mode */
356 /* aka store gather */
358 #define GET_MAP_MEM(flags) \
359 ((((unsigned int)(flags)) >> 24) & 0xFF)
361 #define SET_MAP_MEM(caching, flags) \
362 ((flags) = ((((unsigned int)(caching)) << 24) \
363 & 0xFF000000) | ((flags) & 0xFFFFFF));
365 /* leave room for vm_prot bits */
366 #define MAP_MEM_ONLY 0x10000 /* change processor caching */
367 #define MAP_MEM_NAMED_CREATE 0x20000 /* create extant object */
368 #define MAP_MEM_PURGABLE 0x40000 /* create a purgable VM object */
369 #define MAP_MEM_NAMED_REUSE 0x80000 /* reuse provided entry if identical */
374 * Universal Page List data structures
376 * A UPL describes a bounded set of physical pages
377 * associated with some range of an object or map
378 * and a snapshot of the attributes associated with
379 * each of those pages.
382 #define MAX_UPL_TRANSFER 256
383 #define MAX_UPL_SIZE 4096
385 struct upl_page_info
{
386 ppnum_t phys_addr
; /* physical page index number */
388 #ifdef XNU_KERNEL_PRIVATE
389 pageout
:1, /* page is to be removed on commit */
390 absent
:1, /* No valid data in this page */
391 dirty
:1, /* Page must be cleaned (O) */
392 precious
:1, /* must be cleaned, we have only copy */
393 device
:1, /* no page data, mapped dev memory */
394 speculative
:1, /* page is valid, but not yet accessed */
395 :0; /* force to long boundary */
397 opaque
; /* use upl_page_xxx() accessor funcs */
398 #endif /* XNU_KERNEL_PRIVATE */
403 struct upl_page_info
{
404 unsigned int opaque
[2]; /* use upl_page_xxx() accessor funcs */
409 typedef struct upl_page_info upl_page_info_t
;
410 typedef upl_page_info_t
*upl_page_info_array_t
;
411 typedef upl_page_info_array_t upl_page_list_ptr_t
;
413 typedef uint32_t upl_offset_t
; /* page-aligned byte offset */
414 typedef uint32_t upl_size_t
; /* page-aligned byte size */
416 /* upl invocation flags */
417 /* top nibble is used by super upl */
419 #define UPL_FLAGS_NONE 0x00000000
420 #define UPL_COPYOUT_FROM 0x00000001
421 #define UPL_PRECIOUS 0x00000002
422 #define UPL_NO_SYNC 0x00000004
423 #define UPL_CLEAN_IN_PLACE 0x00000008
424 #define UPL_NOBLOCK 0x00000010
425 #define UPL_RET_ONLY_DIRTY 0x00000020
426 #define UPL_SET_INTERNAL 0x00000040
427 #define UPL_QUERY_OBJECT_TYPE 0x00000080
428 #define UPL_RET_ONLY_ABSENT 0x00000100 /* used only for COPY_FROM = FALSE */
429 #define UPL_FILE_IO 0x00000200
430 #define UPL_SET_LITE 0x00000400
431 #define UPL_SET_INTERRUPTIBLE 0x00000800
432 #define UPL_SET_IO_WIRE 0x00001000
433 #define UPL_FOR_PAGEOUT 0x00002000
434 #define UPL_WILL_BE_DUMPED 0x00004000
435 #define UPL_FORCE_DATA_SYNC 0x00008000
436 /* continued after the ticket bits... */
438 #define UPL_PAGE_TICKET_MASK 0x000F0000
439 #define UPL_PAGE_TICKET_SHIFT 16
441 /* ... flags resume here */
442 #define UPL_BLOCK_ACCESS 0x00100000
443 #define UPL_ENCRYPT 0x00200000
444 #define UPL_NOZEROFILL 0x00400000
445 #define UPL_WILL_MODIFY 0x00800000 /* caller will modify the pages */
447 #define UPL_NEED_32BIT_ADDR 0x01000000
449 /* UPL flags known by this kernel */
450 #define UPL_VALID_FLAGS 0x01FFFFFF
453 /* upl abort error flags */
454 #define UPL_ABORT_RESTART 0x1
455 #define UPL_ABORT_UNAVAILABLE 0x2
456 #define UPL_ABORT_ERROR 0x4
457 #define UPL_ABORT_FREE_ON_EMPTY 0x8 /* only implemented in wrappers */
458 #define UPL_ABORT_DUMP_PAGES 0x10
459 #define UPL_ABORT_NOTIFY_EMPTY 0x20
460 #define UPL_ABORT_ALLOW_ACCESS 0x40
461 #define UPL_ABORT_REFERENCE 0x80
463 /* upl pages check flags */
464 #define UPL_CHECK_DIRTY 0x1
468 * upl pagein/pageout flags
471 * when I/O is issued from this UPL it should be done synchronously
473 #define UPL_IOSYNC 0x1
476 * the passed in UPL should not have either a commit or abort
477 * applied to it by the underlying layers... the site that
478 * created the UPL is responsible for cleaning it up.
480 #define UPL_NOCOMMIT 0x2
483 * turn off any speculative read-ahead applied at the I/O layer
485 #define UPL_NORDAHEAD 0x4
488 * pageout request is targeting a real file
489 * as opposed to a swap file.
492 #define UPL_VNODE_PAGER 0x8
494 * this pageout is being originated as part of an explicit
495 * memory synchronization operation... no speculative clustering
496 * should be applied, only the range specified should be pushed.
498 #define UPL_MSYNC 0x10
503 #ifdef MACH_KERNEL_PRIVATE
504 #define UPL_PAGING_ENCRYPTED 0x20
505 #endif /* MACH_KERNEL_PRIVATE */
508 * this pageout is being originated as part of an explicit
509 * memory synchronization operation that is checking for I/O
510 * errors and taking it's own action... if an error occurs,
511 * just abort the pages back into the cache unchanged
513 #define UPL_KEEPCACHED 0x40
516 * this pageout originated from within cluster_io to deal
517 * with a dirty page that hasn't yet been seen by the FS
518 * that backs it... tag it so that the FS can take the
519 * appropriate action w/r to its locking model since the
520 * pageout will reenter the FS for the same file currently
521 * being handled in this context.
524 #define UPL_NESTED_PAGEOUT 0x80
528 /* upl commit flags */
529 #define UPL_COMMIT_FREE_ON_EMPTY 0x1 /* only implemented in wrappers */
530 #define UPL_COMMIT_CLEAR_DIRTY 0x2
531 #define UPL_COMMIT_SET_DIRTY 0x4
532 #define UPL_COMMIT_INACTIVATE 0x8
533 #define UPL_COMMIT_NOTIFY_EMPTY 0x10
534 #define UPL_COMMIT_ALLOW_ACCESS 0x20
536 /* flags for return of state from vm_map_get_upl, vm_upl address space */
538 #define UPL_DEV_MEMORY 0x1
539 #define UPL_PHYS_CONTIG 0x2
543 * Flags for the UPL page ops routine. This routine is not exported
544 * out of the kernel at the moment and so the defs live here.
546 #define UPL_POP_DIRTY 0x1
547 #define UPL_POP_PAGEOUT 0x2
548 #define UPL_POP_PRECIOUS 0x4
549 #define UPL_POP_ABSENT 0x8
550 #define UPL_POP_BUSY 0x10
552 #define UPL_POP_PHYSICAL 0x10000000
553 #define UPL_POP_DUMP 0x20000000
554 #define UPL_POP_SET 0x40000000
555 #define UPL_POP_CLR 0x80000000
558 * Flags for the UPL range op routine. This routine is not exported
559 * out of the kernel at the moemet and so the defs live here.
562 * UPL_ROP_ABSENT: Returns the extent of the range presented which
563 * is absent, starting with the start address presented
565 #define UPL_ROP_ABSENT 0x01
567 * UPL_ROP_PRESENT: Returns the extent of the range presented which
568 * is present (i.e. resident), starting with the start address presented
570 #define UPL_ROP_PRESENT 0x02
572 * UPL_ROP_DUMP: Dump the pages which are found in the target object
573 * for the target range.
575 #define UPL_ROP_DUMP 0x04
579 /* access macros for upl_t */
581 #define UPL_DEVICE_PAGE(upl) \
582 (((upl)[0].phys_addr != 0) ? ((upl)[0].device) : FALSE)
584 #define UPL_PAGE_PRESENT(upl, index) \
585 ((upl)[(index)].phys_addr != 0)
587 #define UPL_PHYS_PAGE(upl, index) \
588 ((upl)[(index)].phys_addr)
590 #define UPL_SPECULATIVE_PAGE(upl, index) \
591 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].speculative) : FALSE)
593 #define UPL_DIRTY_PAGE(upl, index) \
594 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].dirty) : FALSE)
596 #define UPL_PRECIOUS_PAGE(upl, index) \
597 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].precious) : FALSE)
599 #define UPL_VALID_PAGE(upl, index) \
600 (((upl)[(index)].phys_addr != 0) ? (!((upl)[(index)].absent)) : FALSE)
602 #define UPL_PAGEOUT_PAGE(upl, index) \
603 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].pageout) : FALSE)
605 #define UPL_SET_PAGE_FREE_ON_COMMIT(upl, index) \
606 (((upl)[(index)].phys_addr != 0) ? \
607 ((upl)[(index)].pageout = TRUE) : FALSE)
609 #define UPL_CLR_PAGE_FREE_ON_COMMIT(upl, index) \
610 (((upl)[(index)].phys_addr != 0) ? \
611 ((upl)[(index)].pageout = FALSE) : FALSE)
613 /* The call prototyped below is used strictly by UPL_GET_INTERNAL_PAGE_LIST */
615 extern vm_size_t upl_offset_to_pagelist
;
616 extern vm_size_t
upl_get_internal_pagelist_offset(void);
618 /* UPL_GET_INTERNAL_PAGE_LIST is only valid on internal objects where the */
619 /* list request was made with the UPL_INTERNAL flag */
621 #define UPL_GET_INTERNAL_PAGE_LIST(upl) \
622 ((upl_page_info_t *)((upl_offset_to_pagelist == 0) ? \
623 (unsigned int)upl + (unsigned int)(upl_offset_to_pagelist = upl_get_internal_pagelist_offset()): \
624 (unsigned int)upl + (unsigned int)upl_offset_to_pagelist))
628 extern ppnum_t
upl_phys_page(upl_page_info_t
*upl
, int index
);
629 extern boolean_t
upl_device_page(upl_page_info_t
*upl
);
630 extern boolean_t
upl_speculative_page(upl_page_info_t
*upl
, int index
);
631 extern void upl_clear_dirty(upl_t upl
, boolean_t value
);
639 extern boolean_t
upl_page_present(upl_page_info_t
*upl
, int index
);
640 extern boolean_t
upl_dirty_page(upl_page_info_t
*upl
, int index
);
641 extern boolean_t
upl_valid_page(upl_page_info_t
*upl
, int index
);
642 extern void upl_deallocate(upl_t upl
);
648 #endif /* _MACH_MEMORY_OBJECT_TYPES_H_ */