2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
27 * Mach Operating System
28 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
29 * All Rights Reserved.
31 * Permission to use, copy, modify and distribute this software and its
32 * documentation is hereby granted, provided that both the copyright
33 * notice and this permission notice appear in all copies of the
34 * software, derivative works or modified versions, and any portions
35 * thereof, and that both notices appear in supporting documentation.
37 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
38 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
39 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
41 * Carnegie Mellon requests users of this software to return to
43 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
44 * School of Computer Science
45 * Carnegie Mellon University
46 * Pittsburgh PA 15213-3890
48 * any improvements or extensions that they make and grant Carnegie Mellon
49 * the rights to redistribute these changes.
54 * File: memory_object.h
55 * Author: Michael Wayne Young
57 * External memory management interface definition.
60 #ifndef _MACH_MEMORY_OBJECT_TYPES_H_
61 #define _MACH_MEMORY_OBJECT_TYPES_H_
64 * User-visible types used in the external memory
65 * management interface:
68 #include <mach/port.h>
69 #include <mach/message.h>
70 #include <mach/vm_types.h>
71 #include <mach/machine/vm_types.h>
73 #include <sys/cdefs.h>
75 #define VM_64_BIT_DATA_OBJECTS
77 typedef unsigned long long memory_object_offset_t
;
78 typedef unsigned long long memory_object_size_t
;
81 * Temporary until real EMMI version gets re-implemented
86 typedef struct memory_object
{
90 typedef struct memory_object_control
{
91 struct vm_object
*object
;
92 } *memory_object_control_t
;
94 #else /* KERNEL_PRIVATE */
96 typedef mach_port_t memory_object_t
;
97 typedef mach_port_t memory_object_control_t
;
99 #endif /* KERNEL_PRIVATE */
101 typedef memory_object_t
*memory_object_array_t
;
102 /* A memory object ... */
103 /* Used by the kernel to retrieve */
106 typedef mach_port_t memory_object_name_t
;
107 /* Used to describe the memory ... */
108 /* object in vm_regions() calls */
110 typedef mach_port_t memory_object_default_t
;
111 /* Registered with the host ... */
112 /* for creating new internal objects */
114 #define MEMORY_OBJECT_NULL ((memory_object_t) 0)
115 #define MEMORY_OBJECT_CONTROL_NULL ((memory_object_control_t) 0)
116 #define MEMORY_OBJECT_NAME_NULL ((memory_object_name_t) 0)
117 #define MEMORY_OBJECT_DEFAULT_NULL ((memory_object_default_t) 0)
120 typedef int memory_object_copy_strategy_t
;
121 /* How memory manager handles copy: */
122 #define MEMORY_OBJECT_COPY_NONE 0
123 /* ... No special support */
124 #define MEMORY_OBJECT_COPY_CALL 1
125 /* ... Make call on memory manager */
126 #define MEMORY_OBJECT_COPY_DELAY 2
127 /* ... Memory manager doesn't
128 * change data externally.
130 #define MEMORY_OBJECT_COPY_TEMPORARY 3
131 /* ... Memory manager doesn't
132 * change data externally, and
133 * doesn't need to see changes.
135 #define MEMORY_OBJECT_COPY_SYMMETRIC 4
136 /* ... Memory manager doesn't
137 * change data externally,
138 * doesn't need to see changes,
139 * and object will not be
143 * Not yet safe for non-kernel use.
146 #define MEMORY_OBJECT_COPY_INVALID 5
147 /* ... An invalid copy strategy,
148 * for external objects which
149 * have not been initialized.
150 * Allows copy_strategy to be
151 * examined without also
152 * examining pager_ready and
156 typedef int memory_object_return_t
;
157 /* Which pages to return to manager
158 this time (lock_request) */
159 #define MEMORY_OBJECT_RETURN_NONE 0
160 /* ... don't return any. */
161 #define MEMORY_OBJECT_RETURN_DIRTY 1
162 /* ... only dirty pages. */
163 #define MEMORY_OBJECT_RETURN_ALL 2
164 /* ... dirty and precious pages. */
165 #define MEMORY_OBJECT_RETURN_ANYTHING 3
166 /* ... any resident page. */
169 * Data lock request flags
172 #define MEMORY_OBJECT_DATA_FLUSH 0x1
173 #define MEMORY_OBJECT_DATA_NO_CHANGE 0x2
174 #define MEMORY_OBJECT_DATA_PURGE 0x4
175 #define MEMORY_OBJECT_COPY_SYNC 0x8
176 #define MEMORY_OBJECT_DATA_SYNC 0x10
177 #define MEMORY_OBJECT_IO_SYNC 0x20
180 * Types for the memory object flavor interfaces
183 #define MEMORY_OBJECT_INFO_MAX (1024)
184 typedef int *memory_object_info_t
;
185 typedef int memory_object_flavor_t
;
186 typedef int memory_object_info_data_t
[MEMORY_OBJECT_INFO_MAX
];
189 #define MEMORY_OBJECT_PERFORMANCE_INFO 11
190 #define MEMORY_OBJECT_ATTRIBUTE_INFO 14
191 #define MEMORY_OBJECT_BEHAVIOR_INFO 15
195 #define OLD_MEMORY_OBJECT_BEHAVIOR_INFO 10
196 #define OLD_MEMORY_OBJECT_ATTRIBUTE_INFO 12
198 struct old_memory_object_behave_info
{
199 memory_object_copy_strategy_t copy_strategy
;
201 boolean_t invalidate
;
204 struct old_memory_object_attr_info
{ /* old attr list */
205 boolean_t object_ready
;
207 memory_object_copy_strategy_t copy_strategy
;
210 typedef struct old_memory_object_behave_info
*old_memory_object_behave_info_t
;
211 typedef struct old_memory_object_behave_info old_memory_object_behave_info_data_t
;
212 typedef struct old_memory_object_attr_info
*old_memory_object_attr_info_t
;
213 typedef struct old_memory_object_attr_info old_memory_object_attr_info_data_t
;
215 #define OLD_MEMORY_OBJECT_BEHAVE_INFO_COUNT ((mach_msg_type_number_t) \
216 (sizeof(old_memory_object_behave_info_data_t)/sizeof(int)))
217 #define OLD_MEMORY_OBJECT_ATTR_INFO_COUNT ((mach_msg_type_number_t) \
218 (sizeof(old_memory_object_attr_info_data_t)/sizeof(int)))
223 extern void memory_object_reference(memory_object_t object
);
224 extern void memory_object_deallocate(memory_object_t object
);
226 extern void memory_object_default_reference(memory_object_default_t
);
227 extern void memory_object_default_deallocate(memory_object_default_t
);
229 extern void memory_object_control_reference(memory_object_control_t control
);
230 extern void memory_object_control_deallocate(memory_object_control_t control
);
231 extern int memory_object_control_uiomove(memory_object_control_t
, memory_object_offset_t
, void *, int, int, int);
238 typedef natural_t memory_object_cluster_size_t
;
240 struct memory_object_perf_info
{
241 memory_object_cluster_size_t cluster_size
;
245 struct memory_object_attr_info
{
246 memory_object_copy_strategy_t copy_strategy
;
247 memory_object_cluster_size_t cluster_size
;
248 boolean_t may_cache_object
;
252 struct memory_object_behave_info
{
253 memory_object_copy_strategy_t copy_strategy
;
255 boolean_t invalidate
;
256 boolean_t silent_overwrite
;
257 boolean_t advisory_pageout
;
261 typedef struct memory_object_behave_info
*memory_object_behave_info_t
;
262 typedef struct memory_object_behave_info memory_object_behave_info_data_t
;
264 typedef struct memory_object_perf_info
*memory_object_perf_info_t
;
265 typedef struct memory_object_perf_info memory_object_perf_info_data_t
;
267 typedef struct memory_object_attr_info
*memory_object_attr_info_t
;
268 typedef struct memory_object_attr_info memory_object_attr_info_data_t
;
270 #define MEMORY_OBJECT_BEHAVE_INFO_COUNT ((mach_msg_type_number_t) \
271 (sizeof(memory_object_behave_info_data_t)/sizeof(int)))
272 #define MEMORY_OBJECT_PERF_INFO_COUNT ((mach_msg_type_number_t) \
273 (sizeof(memory_object_perf_info_data_t)/sizeof(int)))
274 #define MEMORY_OBJECT_ATTR_INFO_COUNT ((mach_msg_type_number_t) \
275 (sizeof(memory_object_attr_info_data_t)/sizeof(int)))
277 #define invalid_memory_object_flavor(f) \
278 (f != MEMORY_OBJECT_ATTRIBUTE_INFO && \
279 f != MEMORY_OBJECT_PERFORMANCE_INFO && \
280 f != OLD_MEMORY_OBJECT_BEHAVIOR_INFO && \
281 f != MEMORY_OBJECT_BEHAVIOR_INFO && \
282 f != OLD_MEMORY_OBJECT_ATTRIBUTE_INFO)
286 * Used to support options on memory_object_release_name call
288 #define MEMORY_OBJECT_TERMINATE_IDLE 0x1
289 #define MEMORY_OBJECT_RESPECT_CACHE 0x2
290 #define MEMORY_OBJECT_RELEASE_NO_OP 0x4
293 /* named entry processor mapping options */
295 #define MAP_MEM_NOOP 0
296 #define MAP_MEM_COPYBACK 1
298 #define MAP_MEM_WTHRU 3
299 #define MAP_MEM_WCOMB 4 /* Write combining mode */
300 /* aka store gather */
302 #define GET_MAP_MEM(flags) \
303 ((((unsigned int)(flags)) >> 24) & 0xFF)
305 #define SET_MAP_MEM(caching, flags) \
306 ((flags) = ((((unsigned int)(caching)) << 24) \
307 & 0xFF000000) | ((flags) & 0xFFFFFF));
309 /* leave room for vm_prot bits */
310 #define MAP_MEM_ONLY 0x10000 /* change processor caching */
311 #define MAP_MEM_NAMED_CREATE 0x20000 /* create extant object */
312 #define MAP_MEM_PURGABLE 0x40000 /* create a purgable VM object */
313 #define MAP_MEM_NAMED_REUSE 0x80000 /* reuse provided entry if identical */
318 * Universal Page List data structures
320 * A UPL describes a bounded set of physical pages
321 * associated with some range of an object or map
322 * and a snapshot of the attributes associated with
323 * each of those pages.
326 #define MAX_UPL_TRANSFER 256
328 struct upl_page_info
{
329 ppnum_t phys_addr
; /* physical page index number */
331 #ifdef XNU_KERNEL_PRIVATE
332 pageout
:1, /* page is to be removed on commit */
333 absent
:1, /* No valid data in this page */
334 dirty
:1, /* Page must be cleaned (O) */
335 precious
:1, /* must be cleaned, we have only copy */
336 device
:1, /* no page data, mapped dev memory */
337 :0; /* force to long boundary */
339 opaque
; /* use upl_page_xxx() accessor funcs */
340 #endif /* XNU_KERNEL_PRIVATE */
345 struct upl_page_info
{
346 unsigned int opaque
[2]; /* use upl_page_xxx() accessor funcs */
351 typedef struct upl_page_info upl_page_info_t
;
352 typedef upl_page_info_t
*upl_page_info_array_t
;
353 typedef upl_page_info_array_t upl_page_list_ptr_t
;
355 typedef uint32_t upl_offset_t
; /* page-aligned byte offset */
356 typedef uint32_t upl_size_t
; /* page-aligned byte size */
358 /* upl invocation flags */
359 /* top nibble is used by super upl */
361 #define UPL_FLAGS_NONE 0x00000000
362 #define UPL_COPYOUT_FROM 0x00000001
363 #define UPL_PRECIOUS 0x00000002
364 #define UPL_NO_SYNC 0x00000004
365 #define UPL_CLEAN_IN_PLACE 0x00000008
366 #define UPL_NOBLOCK 0x00000010
367 #define UPL_RET_ONLY_DIRTY 0x00000020
368 #define UPL_SET_INTERNAL 0x00000040
369 #define UPL_QUERY_OBJECT_TYPE 0x00000080
370 #define UPL_RET_ONLY_ABSENT 0x00000100 /* used only for COPY_FROM = FALSE */
371 #define UPL_FILE_IO 0x00000200
372 #define UPL_SET_LITE 0x00000400
373 #define UPL_SET_INTERRUPTIBLE 0x00000800
374 #define UPL_SET_IO_WIRE 0x00001000
375 #define UPL_FOR_PAGEOUT 0x00002000
376 #define UPL_WILL_BE_DUMPED 0x00004000
377 #define UPL_FORCE_DATA_SYNC 0x00008000
378 /* continued after the ticket bits... */
380 #define UPL_PAGE_TICKET_MASK 0x000F0000
381 #define UPL_PAGE_TICKET_SHIFT 16
383 /* ... flags resume here */
384 #define UPL_BLOCK_ACCESS 0x00100000
385 #define UPL_ENCRYPT 0x00200000
386 #define UPL_NOZEROFILL 0x00400000
387 #define UPL_WILL_MODIFY 0x00800000 /* caller will modify the pages */
389 /* UPL flags known by this kernel */
390 #define UPL_VALID_FLAGS 0x00FFFFFF
393 /* upl abort error flags */
394 #define UPL_ABORT_RESTART 0x1
395 #define UPL_ABORT_UNAVAILABLE 0x2
396 #define UPL_ABORT_ERROR 0x4
397 #define UPL_ABORT_FREE_ON_EMPTY 0x8 /* only implemented in wrappers */
398 #define UPL_ABORT_DUMP_PAGES 0x10
399 #define UPL_ABORT_NOTIFY_EMPTY 0x20
400 #define UPL_ABORT_ALLOW_ACCESS 0x40
402 /* upl pages check flags */
403 #define UPL_CHECK_DIRTY 0x1
407 * upl pagein/pageout flags
410 * when I/O is issued from this UPL it should be done synchronously
412 #define UPL_IOSYNC 0x1
415 * the passed in UPL should not have either a commit or abort
416 * applied to it by the underlying layers... the site that
417 * created the UPL is responsible for cleaning it up.
419 #define UPL_NOCOMMIT 0x2
422 * turn off any speculative read-ahead applied at the I/O layer
424 #define UPL_NORDAHEAD 0x4
427 * pageout request is targeting a real file
428 * as opposed to a swap file.
431 #define UPL_VNODE_PAGER 0x8
433 * this pageout is being originated as part of an explicit
434 * memory synchronization operation... no speculative clustering
435 * should be applied, only the range specified should be pushed.
437 #define UPL_MSYNC 0x10
442 #ifdef MACH_KERNEL_PRIVATE
443 #define UPL_PAGING_ENCRYPTED 0x20
444 #endif /* MACH_KERNEL_PRIVATE */
447 * this pageout is being originated as part of an explicit
448 * memory synchronization operation that is checking for I/O
449 * errors and taking it's own action... if an error occurs,
450 * just abort the pages back into the cache unchanged
452 #define UPL_KEEPCACHED 0x40
456 /* upl commit flags */
457 #define UPL_COMMIT_FREE_ON_EMPTY 0x1 /* only implemented in wrappers */
458 #define UPL_COMMIT_CLEAR_DIRTY 0x2
459 #define UPL_COMMIT_SET_DIRTY 0x4
460 #define UPL_COMMIT_INACTIVATE 0x8
461 #define UPL_COMMIT_NOTIFY_EMPTY 0x10
462 #define UPL_COMMIT_ALLOW_ACCESS 0x20
464 /* flags for return of state from vm_map_get_upl, vm_upl address space */
466 #define UPL_DEV_MEMORY 0x1
467 #define UPL_PHYS_CONTIG 0x2
471 * Flags for the UPL page ops routine. This routine is not exported
472 * out of the kernel at the moment and so the defs live here.
474 #define UPL_POP_DIRTY 0x1
475 #define UPL_POP_PAGEOUT 0x2
476 #define UPL_POP_PRECIOUS 0x4
477 #define UPL_POP_ABSENT 0x8
478 #define UPL_POP_BUSY 0x10
480 #define UPL_POP_PHYSICAL 0x10000000
481 #define UPL_POP_DUMP 0x20000000
482 #define UPL_POP_SET 0x40000000
483 #define UPL_POP_CLR 0x80000000
486 * Flags for the UPL range op routine. This routine is not exported
487 * out of the kernel at the moemet and so the defs live here.
490 * UPL_ROP_ABSENT: Returns the extent of the range presented which
491 * is absent, starting with the start address presented
493 #define UPL_ROP_ABSENT 0x01
495 * UPL_ROP_PRESENT: Returns the extent of the range presented which
496 * is present (i.e. resident), starting with the start address presented
498 #define UPL_ROP_PRESENT 0x02
500 * UPL_ROP_DUMP: Dump the pages which are found in the target object
501 * for the target range.
503 #define UPL_ROP_DUMP 0x04
507 /* access macros for upl_t */
509 #define UPL_DEVICE_PAGE(upl) \
510 (((upl)[(index)].phys_addr != 0) ? (!((upl)[0].device)) : FALSE)
512 #define UPL_PAGE_PRESENT(upl, index) \
513 ((upl)[(index)].phys_addr != 0)
515 #define UPL_PHYS_PAGE(upl, index) \
516 ((upl)[(index)].phys_addr)
518 #define UPL_DIRTY_PAGE(upl, index) \
519 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].dirty) : FALSE)
521 #define UPL_PRECIOUS_PAGE(upl, index) \
522 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].precious) : FALSE)
524 #define UPL_VALID_PAGE(upl, index) \
525 (((upl)[(index)].phys_addr != 0) ? (!((upl)[(index)].absent)) : FALSE)
527 #define UPL_PAGEOUT_PAGE(upl, index) \
528 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].pageout) : FALSE)
530 #define UPL_SET_PAGE_FREE_ON_COMMIT(upl, index) \
531 (((upl)[(index)].phys_addr != 0) ? \
532 ((upl)[(index)].pageout = TRUE) : FALSE)
534 #define UPL_CLR_PAGE_FREE_ON_COMMIT(upl, index) \
535 (((upl)[(index)].phys_addr != 0) ? \
536 ((upl)[(index)].pageout = FALSE) : FALSE)
538 /* The call prototyped below is used strictly by UPL_GET_INTERNAL_PAGE_LIST */
540 extern vm_size_t upl_offset_to_pagelist
;
541 extern vm_size_t
upl_get_internal_pagelist_offset(void);
543 /* UPL_GET_INTERNAL_PAGE_LIST is only valid on internal objects where the */
544 /* list request was made with the UPL_INTERNAL flag */
546 #define UPL_GET_INTERNAL_PAGE_LIST(upl) \
547 ((upl_page_info_t *)((upl_offset_to_pagelist == 0) ? \
548 (unsigned int)upl + (unsigned int)(upl_offset_to_pagelist = upl_get_internal_pagelist_offset()): \
549 (unsigned int)upl + (unsigned int)upl_offset_to_pagelist))
553 extern ppnum_t
upl_phys_page(upl_page_info_t
*upl
, int index
);
554 extern void upl_set_dirty(upl_t upl
);
555 extern void upl_clear_dirty(upl_t upl
);
563 extern boolean_t
upl_page_present(upl_page_info_t
*upl
, int index
);
564 extern boolean_t
upl_dirty_page(upl_page_info_t
*upl
, int index
);
565 extern boolean_t
upl_valid_page(upl_page_info_t
*upl
, int index
);
566 extern void upl_deallocate(upl_t upl
);
572 #endif /* _MACH_MEMORY_OBJECT_TYPES_H_ */