2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
61 * File: memory_object.h
62 * Author: Michael Wayne Young
64 * External memory management interface definition.
67 #ifndef _MACH_MEMORY_OBJECT_TYPES_H_
68 #define _MACH_MEMORY_OBJECT_TYPES_H_
71 * User-visible types used in the external memory
72 * management interface:
75 #include <mach/port.h>
76 #include <mach/message.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
;
88 * Temporary until real EMMI version gets re-implemented
93 typedef struct memory_object
{
97 typedef struct memory_object_control
{
98 struct vm_object
*object
;
99 } *memory_object_control_t
;
101 #else /* KERNEL_PRIVATE */
103 typedef mach_port_t memory_object_t
;
104 typedef mach_port_t memory_object_control_t
;
106 #endif /* KERNEL_PRIVATE */
108 typedef memory_object_t
*memory_object_array_t
;
109 /* A memory object ... */
110 /* Used by the kernel to retrieve */
113 typedef mach_port_t memory_object_name_t
;
114 /* Used to describe the memory ... */
115 /* object in vm_regions() calls */
117 typedef mach_port_t memory_object_default_t
;
118 /* Registered with the host ... */
119 /* for creating new internal objects */
121 #define MEMORY_OBJECT_NULL ((memory_object_t) 0)
122 #define MEMORY_OBJECT_CONTROL_NULL ((memory_object_control_t) 0)
123 #define MEMORY_OBJECT_NAME_NULL ((memory_object_name_t) 0)
124 #define MEMORY_OBJECT_DEFAULT_NULL ((memory_object_default_t) 0)
127 typedef int memory_object_copy_strategy_t
;
128 /* How memory manager handles copy: */
129 #define MEMORY_OBJECT_COPY_NONE 0
130 /* ... No special support */
131 #define MEMORY_OBJECT_COPY_CALL 1
132 /* ... Make call on memory manager */
133 #define MEMORY_OBJECT_COPY_DELAY 2
134 /* ... Memory manager doesn't
135 * change data externally.
137 #define MEMORY_OBJECT_COPY_TEMPORARY 3
138 /* ... Memory manager doesn't
139 * change data externally, and
140 * doesn't need to see changes.
142 #define MEMORY_OBJECT_COPY_SYMMETRIC 4
143 /* ... Memory manager doesn't
144 * change data externally,
145 * doesn't need to see changes,
146 * and object will not be
150 * Not yet safe for non-kernel use.
153 #define MEMORY_OBJECT_COPY_INVALID 5
154 /* ... An invalid copy strategy,
155 * for external objects which
156 * have not been initialized.
157 * Allows copy_strategy to be
158 * examined without also
159 * examining pager_ready and
163 typedef int memory_object_return_t
;
164 /* Which pages to return to manager
165 this time (lock_request) */
166 #define MEMORY_OBJECT_RETURN_NONE 0
167 /* ... don't return any. */
168 #define MEMORY_OBJECT_RETURN_DIRTY 1
169 /* ... only dirty pages. */
170 #define MEMORY_OBJECT_RETURN_ALL 2
171 /* ... dirty and precious pages. */
172 #define MEMORY_OBJECT_RETURN_ANYTHING 3
173 /* ... any resident page. */
176 * Data lock request flags
179 #define MEMORY_OBJECT_DATA_FLUSH 0x1
180 #define MEMORY_OBJECT_DATA_NO_CHANGE 0x2
181 #define MEMORY_OBJECT_DATA_PURGE 0x4
182 #define MEMORY_OBJECT_COPY_SYNC 0x8
183 #define MEMORY_OBJECT_DATA_SYNC 0x10
184 #define MEMORY_OBJECT_IO_SYNC 0x20
187 * Types for the memory object flavor interfaces
190 #define MEMORY_OBJECT_INFO_MAX (1024)
191 typedef int *memory_object_info_t
;
192 typedef int memory_object_flavor_t
;
193 typedef int memory_object_info_data_t
[MEMORY_OBJECT_INFO_MAX
];
196 #define MEMORY_OBJECT_PERFORMANCE_INFO 11
197 #define MEMORY_OBJECT_ATTRIBUTE_INFO 14
198 #define MEMORY_OBJECT_BEHAVIOR_INFO 15
202 #define OLD_MEMORY_OBJECT_BEHAVIOR_INFO 10
203 #define OLD_MEMORY_OBJECT_ATTRIBUTE_INFO 12
205 struct old_memory_object_behave_info
{
206 memory_object_copy_strategy_t copy_strategy
;
208 boolean_t invalidate
;
211 struct old_memory_object_attr_info
{ /* old attr list */
212 boolean_t object_ready
;
214 memory_object_copy_strategy_t copy_strategy
;
217 typedef struct old_memory_object_behave_info
*old_memory_object_behave_info_t
;
218 typedef struct old_memory_object_behave_info old_memory_object_behave_info_data_t
;
219 typedef struct old_memory_object_attr_info
*old_memory_object_attr_info_t
;
220 typedef struct old_memory_object_attr_info old_memory_object_attr_info_data_t
;
222 #define OLD_MEMORY_OBJECT_BEHAVE_INFO_COUNT ((mach_msg_type_number_t) \
223 (sizeof(old_memory_object_behave_info_data_t)/sizeof(int)))
224 #define OLD_MEMORY_OBJECT_ATTR_INFO_COUNT ((mach_msg_type_number_t) \
225 (sizeof(old_memory_object_attr_info_data_t)/sizeof(int)))
230 extern void memory_object_reference(memory_object_t object
);
231 extern void memory_object_deallocate(memory_object_t object
);
233 extern void memory_object_default_reference(memory_object_default_t
);
234 extern void memory_object_default_deallocate(memory_object_default_t
);
236 extern void memory_object_control_reference(memory_object_control_t control
);
237 extern void memory_object_control_deallocate(memory_object_control_t control
);
238 extern int memory_object_control_uiomove(memory_object_control_t
, memory_object_offset_t
, void *, int, int, int);
245 typedef natural_t memory_object_cluster_size_t
;
247 struct memory_object_perf_info
{
248 memory_object_cluster_size_t cluster_size
;
252 struct memory_object_attr_info
{
253 memory_object_copy_strategy_t copy_strategy
;
254 memory_object_cluster_size_t cluster_size
;
255 boolean_t may_cache_object
;
259 struct memory_object_behave_info
{
260 memory_object_copy_strategy_t copy_strategy
;
262 boolean_t invalidate
;
263 boolean_t silent_overwrite
;
264 boolean_t advisory_pageout
;
268 typedef struct memory_object_behave_info
*memory_object_behave_info_t
;
269 typedef struct memory_object_behave_info memory_object_behave_info_data_t
;
271 typedef struct memory_object_perf_info
*memory_object_perf_info_t
;
272 typedef struct memory_object_perf_info memory_object_perf_info_data_t
;
274 typedef struct memory_object_attr_info
*memory_object_attr_info_t
;
275 typedef struct memory_object_attr_info memory_object_attr_info_data_t
;
277 #define MEMORY_OBJECT_BEHAVE_INFO_COUNT ((mach_msg_type_number_t) \
278 (sizeof(memory_object_behave_info_data_t)/sizeof(int)))
279 #define MEMORY_OBJECT_PERF_INFO_COUNT ((mach_msg_type_number_t) \
280 (sizeof(memory_object_perf_info_data_t)/sizeof(int)))
281 #define MEMORY_OBJECT_ATTR_INFO_COUNT ((mach_msg_type_number_t) \
282 (sizeof(memory_object_attr_info_data_t)/sizeof(int)))
284 #define invalid_memory_object_flavor(f) \
285 (f != MEMORY_OBJECT_ATTRIBUTE_INFO && \
286 f != MEMORY_OBJECT_PERFORMANCE_INFO && \
287 f != OLD_MEMORY_OBJECT_BEHAVIOR_INFO && \
288 f != MEMORY_OBJECT_BEHAVIOR_INFO && \
289 f != OLD_MEMORY_OBJECT_ATTRIBUTE_INFO)
293 * Used to support options on memory_object_release_name call
295 #define MEMORY_OBJECT_TERMINATE_IDLE 0x1
296 #define MEMORY_OBJECT_RESPECT_CACHE 0x2
297 #define MEMORY_OBJECT_RELEASE_NO_OP 0x4
300 /* named entry processor mapping options */
302 #define MAP_MEM_NOOP 0
303 #define MAP_MEM_COPYBACK 1
305 #define MAP_MEM_WTHRU 3
306 #define MAP_MEM_WCOMB 4 /* Write combining mode */
307 /* aka store gather */
309 #define GET_MAP_MEM(flags) \
310 ((((unsigned int)(flags)) >> 24) & 0xFF)
312 #define SET_MAP_MEM(caching, flags) \
313 ((flags) = ((((unsigned int)(caching)) << 24) \
314 & 0xFF000000) | ((flags) & 0xFFFFFF));
316 /* leave room for vm_prot bits */
317 #define MAP_MEM_ONLY 0x10000 /* change processor caching */
318 #define MAP_MEM_NAMED_CREATE 0x20000 /* create extant object */
319 #define MAP_MEM_PURGABLE 0x40000 /* create a purgable VM object */
320 #define MAP_MEM_NAMED_REUSE 0x80000 /* reuse provided entry if identical */
325 * Universal Page List data structures
327 * A UPL describes a bounded set of physical pages
328 * associated with some range of an object or map
329 * and a snapshot of the attributes associated with
330 * each of those pages.
333 #define MAX_UPL_TRANSFER 256
335 struct upl_page_info
{
336 ppnum_t phys_addr
; /* physical page index number */
338 #ifdef XNU_KERNEL_PRIVATE
339 pageout
:1, /* page is to be removed on commit */
340 absent
:1, /* No valid data in this page */
341 dirty
:1, /* Page must be cleaned (O) */
342 precious
:1, /* must be cleaned, we have only copy */
343 device
:1, /* no page data, mapped dev memory */
344 :0; /* force to long boundary */
346 opaque
; /* use upl_page_xxx() accessor funcs */
347 #endif /* XNU_KERNEL_PRIVATE */
352 struct upl_page_info
{
353 unsigned int opaque
[2]; /* use upl_page_xxx() accessor funcs */
358 typedef struct upl_page_info upl_page_info_t
;
359 typedef upl_page_info_t
*upl_page_info_array_t
;
360 typedef upl_page_info_array_t upl_page_list_ptr_t
;
362 typedef uint32_t upl_offset_t
; /* page-aligned byte offset */
363 typedef uint32_t upl_size_t
; /* page-aligned byte size */
365 /* upl invocation flags */
366 /* top nibble is used by super upl */
368 #define UPL_FLAGS_NONE 0x00000000
369 #define UPL_COPYOUT_FROM 0x00000001
370 #define UPL_PRECIOUS 0x00000002
371 #define UPL_NO_SYNC 0x00000004
372 #define UPL_CLEAN_IN_PLACE 0x00000008
373 #define UPL_NOBLOCK 0x00000010
374 #define UPL_RET_ONLY_DIRTY 0x00000020
375 #define UPL_SET_INTERNAL 0x00000040
376 #define UPL_QUERY_OBJECT_TYPE 0x00000080
377 #define UPL_RET_ONLY_ABSENT 0x00000100 /* used only for COPY_FROM = FALSE */
378 #define UPL_FILE_IO 0x00000200
379 #define UPL_SET_LITE 0x00000400
380 #define UPL_SET_INTERRUPTIBLE 0x00000800
381 #define UPL_SET_IO_WIRE 0x00001000
382 #define UPL_FOR_PAGEOUT 0x00002000
383 #define UPL_WILL_BE_DUMPED 0x00004000
384 #define UPL_FORCE_DATA_SYNC 0x00008000
385 /* continued after the ticket bits... */
387 #define UPL_PAGE_TICKET_MASK 0x000F0000
388 #define UPL_PAGE_TICKET_SHIFT 16
390 /* ... flags resume here */
391 #define UPL_BLOCK_ACCESS 0x00100000
392 #define UPL_ENCRYPT 0x00200000
393 #define UPL_NOZEROFILL 0x00400000
394 #define UPL_WILL_MODIFY 0x00800000 /* caller will modify the pages */
396 /* UPL flags known by this kernel */
397 #define UPL_VALID_FLAGS 0x00FFFFFF
400 /* upl abort error flags */
401 #define UPL_ABORT_RESTART 0x1
402 #define UPL_ABORT_UNAVAILABLE 0x2
403 #define UPL_ABORT_ERROR 0x4
404 #define UPL_ABORT_FREE_ON_EMPTY 0x8 /* only implemented in wrappers */
405 #define UPL_ABORT_DUMP_PAGES 0x10
406 #define UPL_ABORT_NOTIFY_EMPTY 0x20
407 #define UPL_ABORT_ALLOW_ACCESS 0x40
409 /* upl pages check flags */
410 #define UPL_CHECK_DIRTY 0x1
414 * upl pagein/pageout flags
417 * when I/O is issued from this UPL it should be done synchronously
419 #define UPL_IOSYNC 0x1
422 * the passed in UPL should not have either a commit or abort
423 * applied to it by the underlying layers... the site that
424 * created the UPL is responsible for cleaning it up.
426 #define UPL_NOCOMMIT 0x2
429 * turn off any speculative read-ahead applied at the I/O layer
431 #define UPL_NORDAHEAD 0x4
434 * pageout request is targeting a real file
435 * as opposed to a swap file.
438 #define UPL_VNODE_PAGER 0x8
440 * this pageout is being originated as part of an explicit
441 * memory synchronization operation... no speculative clustering
442 * should be applied, only the range specified should be pushed.
444 #define UPL_MSYNC 0x10
449 #ifdef MACH_KERNEL_PRIVATE
450 #define UPL_PAGING_ENCRYPTED 0x20
451 #endif /* MACH_KERNEL_PRIVATE */
454 * this pageout is being originated as part of an explicit
455 * memory synchronization operation that is checking for I/O
456 * errors and taking it's own action... if an error occurs,
457 * just abort the pages back into the cache unchanged
459 #define UPL_KEEPCACHED 0x40
463 /* upl commit flags */
464 #define UPL_COMMIT_FREE_ON_EMPTY 0x1 /* only implemented in wrappers */
465 #define UPL_COMMIT_CLEAR_DIRTY 0x2
466 #define UPL_COMMIT_SET_DIRTY 0x4
467 #define UPL_COMMIT_INACTIVATE 0x8
468 #define UPL_COMMIT_NOTIFY_EMPTY 0x10
469 #define UPL_COMMIT_ALLOW_ACCESS 0x20
471 /* flags for return of state from vm_map_get_upl, vm_upl address space */
473 #define UPL_DEV_MEMORY 0x1
474 #define UPL_PHYS_CONTIG 0x2
478 * Flags for the UPL page ops routine. This routine is not exported
479 * out of the kernel at the moment and so the defs live here.
481 #define UPL_POP_DIRTY 0x1
482 #define UPL_POP_PAGEOUT 0x2
483 #define UPL_POP_PRECIOUS 0x4
484 #define UPL_POP_ABSENT 0x8
485 #define UPL_POP_BUSY 0x10
487 #define UPL_POP_PHYSICAL 0x10000000
488 #define UPL_POP_DUMP 0x20000000
489 #define UPL_POP_SET 0x40000000
490 #define UPL_POP_CLR 0x80000000
493 * Flags for the UPL range op routine. This routine is not exported
494 * out of the kernel at the moemet and so the defs live here.
497 * UPL_ROP_ABSENT: Returns the extent of the range presented which
498 * is absent, starting with the start address presented
500 #define UPL_ROP_ABSENT 0x01
502 * UPL_ROP_PRESENT: Returns the extent of the range presented which
503 * is present (i.e. resident), starting with the start address presented
505 #define UPL_ROP_PRESENT 0x02
507 * UPL_ROP_DUMP: Dump the pages which are found in the target object
508 * for the target range.
510 #define UPL_ROP_DUMP 0x04
514 /* access macros for upl_t */
516 #define UPL_DEVICE_PAGE(upl) \
517 (((upl)[(index)].phys_addr != 0) ? (!((upl)[0].device)) : FALSE)
519 #define UPL_PAGE_PRESENT(upl, index) \
520 ((upl)[(index)].phys_addr != 0)
522 #define UPL_PHYS_PAGE(upl, index) \
523 ((upl)[(index)].phys_addr)
525 #define UPL_DIRTY_PAGE(upl, index) \
526 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].dirty) : FALSE)
528 #define UPL_PRECIOUS_PAGE(upl, index) \
529 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].precious) : FALSE)
531 #define UPL_VALID_PAGE(upl, index) \
532 (((upl)[(index)].phys_addr != 0) ? (!((upl)[(index)].absent)) : FALSE)
534 #define UPL_PAGEOUT_PAGE(upl, index) \
535 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].pageout) : FALSE)
537 #define UPL_SET_PAGE_FREE_ON_COMMIT(upl, index) \
538 (((upl)[(index)].phys_addr != 0) ? \
539 ((upl)[(index)].pageout = TRUE) : FALSE)
541 #define UPL_CLR_PAGE_FREE_ON_COMMIT(upl, index) \
542 (((upl)[(index)].phys_addr != 0) ? \
543 ((upl)[(index)].pageout = FALSE) : FALSE)
545 /* The call prototyped below is used strictly by UPL_GET_INTERNAL_PAGE_LIST */
547 extern vm_size_t upl_offset_to_pagelist
;
548 extern vm_size_t
upl_get_internal_pagelist_offset(void);
550 /* UPL_GET_INTERNAL_PAGE_LIST is only valid on internal objects where the */
551 /* list request was made with the UPL_INTERNAL flag */
553 #define UPL_GET_INTERNAL_PAGE_LIST(upl) \
554 ((upl_page_info_t *)((upl_offset_to_pagelist == 0) ? \
555 (unsigned int)upl + (unsigned int)(upl_offset_to_pagelist = upl_get_internal_pagelist_offset()): \
556 (unsigned int)upl + (unsigned int)upl_offset_to_pagelist))
560 extern ppnum_t
upl_phys_page(upl_page_info_t
*upl
, int index
);
561 extern void upl_set_dirty(upl_t upl
);
562 extern void upl_clear_dirty(upl_t upl
);
570 extern boolean_t
upl_page_present(upl_page_info_t
*upl
, int index
);
571 extern boolean_t
upl_dirty_page(upl_page_info_t
*upl
, int index
);
572 extern boolean_t
upl_valid_page(upl_page_info_t
*upl
, int index
);
573 extern void upl_deallocate(upl_t upl
);
579 #endif /* _MACH_MEMORY_OBJECT_TYPES_H_ */