2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
53 * File: memory_object.h
54 * Author: Michael Wayne Young
56 * External memory management interface definition.
59 #ifndef _MACH_MEMORY_OBJECT_TYPES_H_
60 #define _MACH_MEMORY_OBJECT_TYPES_H_
63 * User-visible types used in the external memory
64 * management interface:
67 #include <mach/port.h>
68 #include <mach/message.h>
69 #include <mach/vm_types.h>
70 #include <mach/machine/vm_types.h>
72 #include <sys/cdefs.h>
74 #define VM_64_BIT_DATA_OBJECTS
76 typedef unsigned long long memory_object_offset_t
;
77 typedef unsigned long long memory_object_size_t
;
80 * Temporary until real EMMI version gets re-implemented
85 typedef struct memory_object
{
89 typedef struct memory_object_control
{
90 struct vm_object
*object
;
91 } *memory_object_control_t
;
93 #else /* KERNEL_PRIVATE */
95 typedef mach_port_t memory_object_t
;
96 typedef mach_port_t memory_object_control_t
;
98 #endif /* KERNEL_PRIVATE */
100 typedef memory_object_t
*memory_object_array_t
;
101 /* A memory object ... */
102 /* Used by the kernel to retrieve */
105 typedef mach_port_t memory_object_name_t
;
106 /* Used to describe the memory ... */
107 /* object in vm_regions() calls */
109 typedef mach_port_t memory_object_default_t
;
110 /* Registered with the host ... */
111 /* for creating new internal objects */
113 #define MEMORY_OBJECT_NULL ((memory_object_t) 0)
114 #define MEMORY_OBJECT_CONTROL_NULL ((memory_object_control_t) 0)
115 #define MEMORY_OBJECT_NAME_NULL ((memory_object_name_t) 0)
116 #define MEMORY_OBJECT_DEFAULT_NULL ((memory_object_default_t) 0)
119 typedef int memory_object_copy_strategy_t
;
120 /* How memory manager handles copy: */
121 #define MEMORY_OBJECT_COPY_NONE 0
122 /* ... No special support */
123 #define MEMORY_OBJECT_COPY_CALL 1
124 /* ... Make call on memory manager */
125 #define MEMORY_OBJECT_COPY_DELAY 2
126 /* ... Memory manager doesn't
127 * change data externally.
129 #define MEMORY_OBJECT_COPY_TEMPORARY 3
130 /* ... Memory manager doesn't
131 * change data externally, and
132 * doesn't need to see changes.
134 #define MEMORY_OBJECT_COPY_SYMMETRIC 4
135 /* ... Memory manager doesn't
136 * change data externally,
137 * doesn't need to see changes,
138 * and object will not be
142 * Not yet safe for non-kernel use.
145 #define MEMORY_OBJECT_COPY_INVALID 5
146 /* ... An invalid copy strategy,
147 * for external objects which
148 * have not been initialized.
149 * Allows copy_strategy to be
150 * examined without also
151 * examining pager_ready and
155 typedef int memory_object_return_t
;
156 /* Which pages to return to manager
157 this time (lock_request) */
158 #define MEMORY_OBJECT_RETURN_NONE 0
159 /* ... don't return any. */
160 #define MEMORY_OBJECT_RETURN_DIRTY 1
161 /* ... only dirty pages. */
162 #define MEMORY_OBJECT_RETURN_ALL 2
163 /* ... dirty and precious pages. */
164 #define MEMORY_OBJECT_RETURN_ANYTHING 3
165 /* ... any resident page. */
168 * Data lock request flags
171 #define MEMORY_OBJECT_DATA_FLUSH 0x1
172 #define MEMORY_OBJECT_DATA_NO_CHANGE 0x2
173 #define MEMORY_OBJECT_DATA_PURGE 0x4
174 #define MEMORY_OBJECT_COPY_SYNC 0x8
175 #define MEMORY_OBJECT_DATA_SYNC 0x10
176 #define MEMORY_OBJECT_IO_SYNC 0x20
179 * Types for the memory object flavor interfaces
182 #define MEMORY_OBJECT_INFO_MAX (1024)
183 typedef int *memory_object_info_t
;
184 typedef int memory_object_flavor_t
;
185 typedef int memory_object_info_data_t
[MEMORY_OBJECT_INFO_MAX
];
188 #define MEMORY_OBJECT_PERFORMANCE_INFO 11
189 #define MEMORY_OBJECT_ATTRIBUTE_INFO 14
190 #define MEMORY_OBJECT_BEHAVIOR_INFO 15
194 #define OLD_MEMORY_OBJECT_BEHAVIOR_INFO 10
195 #define OLD_MEMORY_OBJECT_ATTRIBUTE_INFO 12
197 struct old_memory_object_behave_info
{
198 memory_object_copy_strategy_t copy_strategy
;
200 boolean_t invalidate
;
203 struct old_memory_object_attr_info
{ /* old attr list */
204 boolean_t object_ready
;
206 memory_object_copy_strategy_t copy_strategy
;
209 typedef struct old_memory_object_behave_info
*old_memory_object_behave_info_t
;
210 typedef struct old_memory_object_behave_info old_memory_object_behave_info_data_t
;
211 typedef struct old_memory_object_attr_info
*old_memory_object_attr_info_t
;
212 typedef struct old_memory_object_attr_info old_memory_object_attr_info_data_t
;
214 #define OLD_MEMORY_OBJECT_BEHAVE_INFO_COUNT ((mach_msg_type_number_t) \
215 (sizeof(old_memory_object_behave_info_data_t)/sizeof(int)))
216 #define OLD_MEMORY_OBJECT_ATTR_INFO_COUNT ((mach_msg_type_number_t) \
217 (sizeof(old_memory_object_attr_info_data_t)/sizeof(int)))
222 extern void memory_object_reference(memory_object_t object
);
223 extern void memory_object_deallocate(memory_object_t object
);
225 extern void memory_object_default_reference(memory_object_default_t
);
226 extern void memory_object_default_deallocate(memory_object_default_t
);
228 extern void memory_object_control_reference(memory_object_control_t control
);
229 extern void memory_object_control_deallocate(memory_object_control_t control
);
230 extern int memory_object_control_uiomove(memory_object_control_t
, memory_object_offset_t
, void *, int, int, int);
237 typedef natural_t memory_object_cluster_size_t
;
239 struct memory_object_perf_info
{
240 memory_object_cluster_size_t cluster_size
;
244 struct memory_object_attr_info
{
245 memory_object_copy_strategy_t copy_strategy
;
246 memory_object_cluster_size_t cluster_size
;
247 boolean_t may_cache_object
;
251 struct memory_object_behave_info
{
252 memory_object_copy_strategy_t copy_strategy
;
254 boolean_t invalidate
;
255 boolean_t silent_overwrite
;
256 boolean_t advisory_pageout
;
260 typedef struct memory_object_behave_info
*memory_object_behave_info_t
;
261 typedef struct memory_object_behave_info memory_object_behave_info_data_t
;
263 typedef struct memory_object_perf_info
*memory_object_perf_info_t
;
264 typedef struct memory_object_perf_info memory_object_perf_info_data_t
;
266 typedef struct memory_object_attr_info
*memory_object_attr_info_t
;
267 typedef struct memory_object_attr_info memory_object_attr_info_data_t
;
269 #define MEMORY_OBJECT_BEHAVE_INFO_COUNT ((mach_msg_type_number_t) \
270 (sizeof(memory_object_behave_info_data_t)/sizeof(int)))
271 #define MEMORY_OBJECT_PERF_INFO_COUNT ((mach_msg_type_number_t) \
272 (sizeof(memory_object_perf_info_data_t)/sizeof(int)))
273 #define MEMORY_OBJECT_ATTR_INFO_COUNT ((mach_msg_type_number_t) \
274 (sizeof(memory_object_attr_info_data_t)/sizeof(int)))
276 #define invalid_memory_object_flavor(f) \
277 (f != MEMORY_OBJECT_ATTRIBUTE_INFO && \
278 f != MEMORY_OBJECT_PERFORMANCE_INFO && \
279 f != OLD_MEMORY_OBJECT_BEHAVIOR_INFO && \
280 f != MEMORY_OBJECT_BEHAVIOR_INFO && \
281 f != OLD_MEMORY_OBJECT_ATTRIBUTE_INFO)
285 * Used to support options on memory_object_release_name call
287 #define MEMORY_OBJECT_TERMINATE_IDLE 0x1
288 #define MEMORY_OBJECT_RESPECT_CACHE 0x2
289 #define MEMORY_OBJECT_RELEASE_NO_OP 0x4
292 /* named entry processor mapping options */
294 #define MAP_MEM_NOOP 0
295 #define MAP_MEM_COPYBACK 1
297 #define MAP_MEM_WTHRU 3
298 #define MAP_MEM_WCOMB 4 /* Write combining mode */
299 /* aka store gather */
301 #define GET_MAP_MEM(flags) \
302 ((((unsigned int)(flags)) >> 24) & 0xFF)
304 #define SET_MAP_MEM(caching, flags) \
305 ((flags) = ((((unsigned int)(caching)) << 24) \
306 & 0xFF000000) | ((flags) & 0xFFFFFF));
308 /* leave room for vm_prot bits */
309 #define MAP_MEM_ONLY 0x10000 /* change processor caching */
310 #define MAP_MEM_NAMED_CREATE 0x20000 /* create extant object */
311 #define MAP_MEM_PURGABLE 0x40000 /* create a purgable VM object */
312 #define MAP_MEM_NAMED_REUSE 0x80000 /* reuse provided entry if identical */
317 * Universal Page List data structures
319 * A UPL describes a bounded set of physical pages
320 * associated with some range of an object or map
321 * and a snapshot of the attributes associated with
322 * each of those pages.
325 #define MAX_UPL_TRANSFER 256
327 struct upl_page_info
{
328 ppnum_t phys_addr
; /* physical page index number */
330 #ifdef XNU_KERNEL_PRIVATE
331 pageout
:1, /* page is to be removed on commit */
332 absent
:1, /* No valid data in this page */
333 dirty
:1, /* Page must be cleaned (O) */
334 precious
:1, /* must be cleaned, we have only copy */
335 device
:1, /* no page data, mapped dev memory */
336 :0; /* force to long boundary */
338 opaque
; /* use upl_page_xxx() accessor funcs */
339 #endif /* XNU_KERNEL_PRIVATE */
344 struct upl_page_info
{
345 unsigned int opaque
[2]; /* use upl_page_xxx() accessor funcs */
350 typedef struct upl_page_info upl_page_info_t
;
351 typedef upl_page_info_t
*upl_page_info_array_t
;
352 typedef upl_page_info_array_t upl_page_list_ptr_t
;
354 typedef uint32_t upl_offset_t
; /* page-aligned byte offset */
355 typedef uint32_t upl_size_t
; /* page-aligned byte size */
357 /* upl invocation flags */
358 /* top nibble is used by super upl */
360 #define UPL_FLAGS_NONE 0x00000000
361 #define UPL_COPYOUT_FROM 0x00000001
362 #define UPL_PRECIOUS 0x00000002
363 #define UPL_NO_SYNC 0x00000004
364 #define UPL_CLEAN_IN_PLACE 0x00000008
365 #define UPL_NOBLOCK 0x00000010
366 #define UPL_RET_ONLY_DIRTY 0x00000020
367 #define UPL_SET_INTERNAL 0x00000040
368 #define UPL_QUERY_OBJECT_TYPE 0x00000080
369 #define UPL_RET_ONLY_ABSENT 0x00000100 /* used only for COPY_FROM = FALSE */
370 #define UPL_FILE_IO 0x00000200
371 #define UPL_SET_LITE 0x00000400
372 #define UPL_SET_INTERRUPTIBLE 0x00000800
373 #define UPL_SET_IO_WIRE 0x00001000
374 #define UPL_FOR_PAGEOUT 0x00002000
375 #define UPL_WILL_BE_DUMPED 0x00004000
376 #define UPL_FORCE_DATA_SYNC 0x00008000
377 /* continued after the ticket bits... */
379 #define UPL_PAGE_TICKET_MASK 0x000F0000
380 #define UPL_PAGE_TICKET_SHIFT 16
382 /* ... flags resume here */
383 #define UPL_BLOCK_ACCESS 0x00100000
384 #define UPL_ENCRYPT 0x00200000
385 #define UPL_NOZEROFILL 0x00400000
386 #define UPL_WILL_MODIFY 0x00800000 /* caller will modify the pages */
388 /* UPL flags known by this kernel */
389 #define UPL_VALID_FLAGS 0x00FFFFFF
392 /* upl abort error flags */
393 #define UPL_ABORT_RESTART 0x1
394 #define UPL_ABORT_UNAVAILABLE 0x2
395 #define UPL_ABORT_ERROR 0x4
396 #define UPL_ABORT_FREE_ON_EMPTY 0x8 /* only implemented in wrappers */
397 #define UPL_ABORT_DUMP_PAGES 0x10
398 #define UPL_ABORT_NOTIFY_EMPTY 0x20
399 #define UPL_ABORT_ALLOW_ACCESS 0x40
401 /* upl pages check flags */
402 #define UPL_CHECK_DIRTY 0x1
406 * upl pagein/pageout flags
409 * when I/O is issued from this UPL it should be done synchronously
411 #define UPL_IOSYNC 0x1
414 * the passed in UPL should not have either a commit or abort
415 * applied to it by the underlying layers... the site that
416 * created the UPL is responsible for cleaning it up.
418 #define UPL_NOCOMMIT 0x2
421 * turn off any speculative read-ahead applied at the I/O layer
423 #define UPL_NORDAHEAD 0x4
426 * pageout request is targeting a real file
427 * as opposed to a swap file.
430 #define UPL_VNODE_PAGER 0x8
432 * this pageout is being originated as part of an explicit
433 * memory synchronization operation... no speculative clustering
434 * should be applied, only the range specified should be pushed.
436 #define UPL_MSYNC 0x10
441 #ifdef MACH_KERNEL_PRIVATE
442 #define UPL_PAGING_ENCRYPTED 0x20
443 #endif /* MACH_KERNEL_PRIVATE */
446 * this pageout is being originated as part of an explicit
447 * memory synchronization operation that is checking for I/O
448 * errors and taking it's own action... if an error occurs,
449 * just abort the pages back into the cache unchanged
451 #define UPL_KEEPCACHED 0x40
455 /* upl commit flags */
456 #define UPL_COMMIT_FREE_ON_EMPTY 0x1 /* only implemented in wrappers */
457 #define UPL_COMMIT_CLEAR_DIRTY 0x2
458 #define UPL_COMMIT_SET_DIRTY 0x4
459 #define UPL_COMMIT_INACTIVATE 0x8
460 #define UPL_COMMIT_NOTIFY_EMPTY 0x10
461 #define UPL_COMMIT_ALLOW_ACCESS 0x20
463 /* flags for return of state from vm_map_get_upl, vm_upl address space */
465 #define UPL_DEV_MEMORY 0x1
466 #define UPL_PHYS_CONTIG 0x2
470 * Flags for the UPL page ops routine. This routine is not exported
471 * out of the kernel at the moment and so the defs live here.
473 #define UPL_POP_DIRTY 0x1
474 #define UPL_POP_PAGEOUT 0x2
475 #define UPL_POP_PRECIOUS 0x4
476 #define UPL_POP_ABSENT 0x8
477 #define UPL_POP_BUSY 0x10
479 #define UPL_POP_PHYSICAL 0x10000000
480 #define UPL_POP_DUMP 0x20000000
481 #define UPL_POP_SET 0x40000000
482 #define UPL_POP_CLR 0x80000000
485 * Flags for the UPL range op routine. This routine is not exported
486 * out of the kernel at the moemet and so the defs live here.
489 * UPL_ROP_ABSENT: Returns the extent of the range presented which
490 * is absent, starting with the start address presented
492 #define UPL_ROP_ABSENT 0x01
494 * UPL_ROP_PRESENT: Returns the extent of the range presented which
495 * is present (i.e. resident), starting with the start address presented
497 #define UPL_ROP_PRESENT 0x02
499 * UPL_ROP_DUMP: Dump the pages which are found in the target object
500 * for the target range.
502 #define UPL_ROP_DUMP 0x04
506 /* access macros for upl_t */
508 #define UPL_DEVICE_PAGE(upl) \
509 (((upl)[(index)].phys_addr != 0) ? (!((upl)[0].device)) : FALSE)
511 #define UPL_PAGE_PRESENT(upl, index) \
512 ((upl)[(index)].phys_addr != 0)
514 #define UPL_PHYS_PAGE(upl, index) \
515 ((upl)[(index)].phys_addr)
517 #define UPL_DIRTY_PAGE(upl, index) \
518 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].dirty) : FALSE)
520 #define UPL_PRECIOUS_PAGE(upl, index) \
521 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].precious) : FALSE)
523 #define UPL_VALID_PAGE(upl, index) \
524 (((upl)[(index)].phys_addr != 0) ? (!((upl)[(index)].absent)) : FALSE)
526 #define UPL_PAGEOUT_PAGE(upl, index) \
527 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].pageout) : FALSE)
529 #define UPL_SET_PAGE_FREE_ON_COMMIT(upl, index) \
530 (((upl)[(index)].phys_addr != 0) ? \
531 ((upl)[(index)].pageout = TRUE) : FALSE)
533 #define UPL_CLR_PAGE_FREE_ON_COMMIT(upl, index) \
534 (((upl)[(index)].phys_addr != 0) ? \
535 ((upl)[(index)].pageout = FALSE) : FALSE)
537 /* The call prototyped below is used strictly by UPL_GET_INTERNAL_PAGE_LIST */
539 extern vm_size_t upl_offset_to_pagelist
;
540 extern vm_size_t
upl_get_internal_pagelist_offset(void);
542 /* UPL_GET_INTERNAL_PAGE_LIST is only valid on internal objects where the */
543 /* list request was made with the UPL_INTERNAL flag */
545 #define UPL_GET_INTERNAL_PAGE_LIST(upl) \
546 ((upl_page_info_t *)((upl_offset_to_pagelist == 0) ? \
547 (unsigned int)upl + (unsigned int)(upl_offset_to_pagelist = upl_get_internal_pagelist_offset()): \
548 (unsigned int)upl + (unsigned int)upl_offset_to_pagelist))
552 extern ppnum_t
upl_phys_page(upl_page_info_t
*upl
, int index
);
553 extern void upl_set_dirty(upl_t upl
);
554 extern void upl_clear_dirty(upl_t upl
);
562 extern boolean_t
upl_page_present(upl_page_info_t
*upl
, int index
);
563 extern boolean_t
upl_dirty_page(upl_page_info_t
*upl
, int index
);
564 extern boolean_t
upl_valid_page(upl_page_info_t
*upl
, int index
);
565 extern void upl_deallocate(upl_t upl
);
571 #endif /* _MACH_MEMORY_OBJECT_TYPES_H_ */