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_prot.h>
70 #include <mach/vm_sync.h>
71 #include <mach/vm_types.h>
72 #include <mach/machine/vm_types.h>
74 #include <sys/cdefs.h>
76 #define VM_64_BIT_DATA_OBJECTS
78 typedef unsigned long long memory_object_offset_t
;
79 typedef unsigned long long memory_object_size_t
;
80 typedef natural_t memory_object_cluster_size_t
;
84 * Temporary until real EMMI version gets re-implemented
89 struct memory_object_pager_ops
; /* forward declaration */
91 typedef struct memory_object
{
92 const struct memory_object_pager_ops
*mo_pager_ops
;
95 typedef struct memory_object_control
{
96 struct vm_object
*moc_object
;
97 unsigned int moc_ikot
; /* XXX fake ip_kotype */
98 } *memory_object_control_t
;
100 typedef const struct memory_object_pager_ops
{
101 void (*memory_object_reference
)(
102 memory_object_t mem_obj
);
103 void (*memory_object_deallocate
)(
104 memory_object_t mem_obj
);
105 kern_return_t (*memory_object_init
)(
106 memory_object_t mem_obj
,
107 memory_object_control_t mem_control
,
108 memory_object_cluster_size_t size
);
109 kern_return_t (*memory_object_terminate
)(
110 memory_object_t mem_obj
);
111 kern_return_t (*memory_object_data_request
)(
112 memory_object_t mem_obj
,
113 memory_object_offset_t offset
,
114 memory_object_cluster_size_t length
,
115 vm_prot_t desired_access
);
116 kern_return_t (*memory_object_data_return
)(
117 memory_object_t mem_obj
,
118 memory_object_offset_t offset
,
120 memory_object_offset_t
*resid_offset
,
123 boolean_t kernel_copy
,
125 kern_return_t (*memory_object_data_initialize
)(
126 memory_object_t mem_obj
,
127 memory_object_offset_t offset
,
129 kern_return_t (*memory_object_data_unlock
)(
130 memory_object_t mem_obj
,
131 memory_object_offset_t offset
,
133 vm_prot_t desired_access
);
134 kern_return_t (*memory_object_synchronize
)(
135 memory_object_t mem_obj
,
136 memory_object_offset_t offset
,
138 vm_sync_t sync_flags
);
139 kern_return_t (*memory_object_unmap
)(
140 memory_object_t mem_obj
);
141 const char *memory_object_pager_name
;
142 } * memory_object_pager_ops_t
;
144 #else /* KERNEL_PRIVATE */
146 typedef mach_port_t memory_object_t
;
147 typedef mach_port_t memory_object_control_t
;
149 #endif /* KERNEL_PRIVATE */
151 typedef memory_object_t
*memory_object_array_t
;
152 /* A memory object ... */
153 /* Used by the kernel to retrieve */
156 typedef mach_port_t memory_object_name_t
;
157 /* Used to describe the memory ... */
158 /* object in vm_regions() calls */
160 typedef mach_port_t memory_object_default_t
;
161 /* Registered with the host ... */
162 /* for creating new internal objects */
164 #define MEMORY_OBJECT_NULL ((memory_object_t) 0)
165 #define MEMORY_OBJECT_CONTROL_NULL ((memory_object_control_t) 0)
166 #define MEMORY_OBJECT_NAME_NULL ((memory_object_name_t) 0)
167 #define MEMORY_OBJECT_DEFAULT_NULL ((memory_object_default_t) 0)
170 typedef int memory_object_copy_strategy_t
;
171 /* How memory manager handles copy: */
172 #define MEMORY_OBJECT_COPY_NONE 0
173 /* ... No special support */
174 #define MEMORY_OBJECT_COPY_CALL 1
175 /* ... Make call on memory manager */
176 #define MEMORY_OBJECT_COPY_DELAY 2
177 /* ... Memory manager doesn't
178 * change data externally.
180 #define MEMORY_OBJECT_COPY_TEMPORARY 3
181 /* ... Memory manager doesn't
182 * change data externally, and
183 * doesn't need to see changes.
185 #define MEMORY_OBJECT_COPY_SYMMETRIC 4
186 /* ... Memory manager doesn't
187 * change data externally,
188 * doesn't need to see changes,
189 * and object will not be
193 * Not yet safe for non-kernel use.
196 #define MEMORY_OBJECT_COPY_INVALID 5
197 /* ... An invalid copy strategy,
198 * for external objects which
199 * have not been initialized.
200 * Allows copy_strategy to be
201 * examined without also
202 * examining pager_ready and
206 typedef int memory_object_return_t
;
207 /* Which pages to return to manager
208 this time (lock_request) */
209 #define MEMORY_OBJECT_RETURN_NONE 0
210 /* ... don't return any. */
211 #define MEMORY_OBJECT_RETURN_DIRTY 1
212 /* ... only dirty pages. */
213 #define MEMORY_OBJECT_RETURN_ALL 2
214 /* ... dirty and precious pages. */
215 #define MEMORY_OBJECT_RETURN_ANYTHING 3
216 /* ... any resident page. */
219 * Data lock request flags
222 #define MEMORY_OBJECT_DATA_FLUSH 0x1
223 #define MEMORY_OBJECT_DATA_NO_CHANGE 0x2
224 #define MEMORY_OBJECT_DATA_PURGE 0x4
225 #define MEMORY_OBJECT_COPY_SYNC 0x8
226 #define MEMORY_OBJECT_DATA_SYNC 0x10
227 #define MEMORY_OBJECT_IO_SYNC 0x20
230 * Types for the memory object flavor interfaces
233 #define MEMORY_OBJECT_INFO_MAX (1024)
234 typedef int *memory_object_info_t
;
235 typedef int memory_object_flavor_t
;
236 typedef int memory_object_info_data_t
[MEMORY_OBJECT_INFO_MAX
];
239 #define MEMORY_OBJECT_PERFORMANCE_INFO 11
240 #define MEMORY_OBJECT_ATTRIBUTE_INFO 14
241 #define MEMORY_OBJECT_BEHAVIOR_INFO 15
245 #define OLD_MEMORY_OBJECT_BEHAVIOR_INFO 10
246 #define OLD_MEMORY_OBJECT_ATTRIBUTE_INFO 12
248 struct old_memory_object_behave_info
{
249 memory_object_copy_strategy_t copy_strategy
;
251 boolean_t invalidate
;
254 struct old_memory_object_attr_info
{ /* old attr list */
255 boolean_t object_ready
;
257 memory_object_copy_strategy_t copy_strategy
;
260 typedef struct old_memory_object_behave_info
*old_memory_object_behave_info_t
;
261 typedef struct old_memory_object_behave_info old_memory_object_behave_info_data_t
;
262 typedef struct old_memory_object_attr_info
*old_memory_object_attr_info_t
;
263 typedef struct old_memory_object_attr_info old_memory_object_attr_info_data_t
;
265 #define OLD_MEMORY_OBJECT_BEHAVE_INFO_COUNT ((mach_msg_type_number_t) \
266 (sizeof(old_memory_object_behave_info_data_t)/sizeof(int)))
267 #define OLD_MEMORY_OBJECT_ATTR_INFO_COUNT ((mach_msg_type_number_t) \
268 (sizeof(old_memory_object_attr_info_data_t)/sizeof(int)))
273 extern void memory_object_reference(memory_object_t object
);
274 extern void memory_object_deallocate(memory_object_t object
);
276 extern void memory_object_default_reference(memory_object_default_t
);
277 extern void memory_object_default_deallocate(memory_object_default_t
);
279 extern void memory_object_control_reference(memory_object_control_t control
);
280 extern void memory_object_control_deallocate(memory_object_control_t control
);
281 extern int memory_object_control_uiomove(memory_object_control_t
, memory_object_offset_t
, void *, int, int, int);
288 struct memory_object_perf_info
{
289 memory_object_cluster_size_t cluster_size
;
293 struct memory_object_attr_info
{
294 memory_object_copy_strategy_t copy_strategy
;
295 memory_object_cluster_size_t cluster_size
;
296 boolean_t may_cache_object
;
300 struct memory_object_behave_info
{
301 memory_object_copy_strategy_t copy_strategy
;
303 boolean_t invalidate
;
304 boolean_t silent_overwrite
;
305 boolean_t advisory_pageout
;
309 typedef struct memory_object_behave_info
*memory_object_behave_info_t
;
310 typedef struct memory_object_behave_info memory_object_behave_info_data_t
;
312 typedef struct memory_object_perf_info
*memory_object_perf_info_t
;
313 typedef struct memory_object_perf_info memory_object_perf_info_data_t
;
315 typedef struct memory_object_attr_info
*memory_object_attr_info_t
;
316 typedef struct memory_object_attr_info memory_object_attr_info_data_t
;
318 #define MEMORY_OBJECT_BEHAVE_INFO_COUNT ((mach_msg_type_number_t) \
319 (sizeof(memory_object_behave_info_data_t)/sizeof(int)))
320 #define MEMORY_OBJECT_PERF_INFO_COUNT ((mach_msg_type_number_t) \
321 (sizeof(memory_object_perf_info_data_t)/sizeof(int)))
322 #define MEMORY_OBJECT_ATTR_INFO_COUNT ((mach_msg_type_number_t) \
323 (sizeof(memory_object_attr_info_data_t)/sizeof(int)))
325 #define invalid_memory_object_flavor(f) \
326 (f != MEMORY_OBJECT_ATTRIBUTE_INFO && \
327 f != MEMORY_OBJECT_PERFORMANCE_INFO && \
328 f != OLD_MEMORY_OBJECT_BEHAVIOR_INFO && \
329 f != MEMORY_OBJECT_BEHAVIOR_INFO && \
330 f != OLD_MEMORY_OBJECT_ATTRIBUTE_INFO)
334 * Used to support options on memory_object_release_name call
336 #define MEMORY_OBJECT_TERMINATE_IDLE 0x1
337 #define MEMORY_OBJECT_RESPECT_CACHE 0x2
338 #define MEMORY_OBJECT_RELEASE_NO_OP 0x4
341 /* named entry processor mapping options */
343 #define MAP_MEM_NOOP 0
344 #define MAP_MEM_COPYBACK 1
346 #define MAP_MEM_WTHRU 3
347 #define MAP_MEM_WCOMB 4 /* Write combining mode */
348 /* aka store gather */
350 #define GET_MAP_MEM(flags) \
351 ((((unsigned int)(flags)) >> 24) & 0xFF)
353 #define SET_MAP_MEM(caching, flags) \
354 ((flags) = ((((unsigned int)(caching)) << 24) \
355 & 0xFF000000) | ((flags) & 0xFFFFFF));
357 /* leave room for vm_prot bits */
358 #define MAP_MEM_ONLY 0x10000 /* change processor caching */
359 #define MAP_MEM_NAMED_CREATE 0x20000 /* create extant object */
360 #define MAP_MEM_PURGABLE 0x40000 /* create a purgable VM object */
361 #define MAP_MEM_NAMED_REUSE 0x80000 /* reuse provided entry if identical */
366 * Universal Page List data structures
368 * A UPL describes a bounded set of physical pages
369 * associated with some range of an object or map
370 * and a snapshot of the attributes associated with
371 * each of those pages.
374 #define MAX_UPL_TRANSFER 256
376 struct upl_page_info
{
377 ppnum_t phys_addr
; /* physical page index number */
379 #ifdef XNU_KERNEL_PRIVATE
380 pageout
:1, /* page is to be removed on commit */
381 absent
:1, /* No valid data in this page */
382 dirty
:1, /* Page must be cleaned (O) */
383 precious
:1, /* must be cleaned, we have only copy */
384 device
:1, /* no page data, mapped dev memory */
385 :0; /* force to long boundary */
387 opaque
; /* use upl_page_xxx() accessor funcs */
388 #endif /* XNU_KERNEL_PRIVATE */
393 struct upl_page_info
{
394 unsigned int opaque
[2]; /* use upl_page_xxx() accessor funcs */
399 typedef struct upl_page_info upl_page_info_t
;
400 typedef upl_page_info_t
*upl_page_info_array_t
;
401 typedef upl_page_info_array_t upl_page_list_ptr_t
;
403 typedef uint32_t upl_offset_t
; /* page-aligned byte offset */
404 typedef uint32_t upl_size_t
; /* page-aligned byte size */
406 /* upl invocation flags */
407 /* top nibble is used by super upl */
409 #define UPL_FLAGS_NONE 0x00000000
410 #define UPL_COPYOUT_FROM 0x00000001
411 #define UPL_PRECIOUS 0x00000002
412 #define UPL_NO_SYNC 0x00000004
413 #define UPL_CLEAN_IN_PLACE 0x00000008
414 #define UPL_NOBLOCK 0x00000010
415 #define UPL_RET_ONLY_DIRTY 0x00000020
416 #define UPL_SET_INTERNAL 0x00000040
417 #define UPL_QUERY_OBJECT_TYPE 0x00000080
418 #define UPL_RET_ONLY_ABSENT 0x00000100 /* used only for COPY_FROM = FALSE */
419 #define UPL_FILE_IO 0x00000200
420 #define UPL_SET_LITE 0x00000400
421 #define UPL_SET_INTERRUPTIBLE 0x00000800
422 #define UPL_SET_IO_WIRE 0x00001000
423 #define UPL_FOR_PAGEOUT 0x00002000
424 #define UPL_WILL_BE_DUMPED 0x00004000
425 #define UPL_FORCE_DATA_SYNC 0x00008000
426 /* continued after the ticket bits... */
428 #define UPL_PAGE_TICKET_MASK 0x000F0000
429 #define UPL_PAGE_TICKET_SHIFT 16
431 /* ... flags resume here */
432 #define UPL_BLOCK_ACCESS 0x00100000
433 #define UPL_ENCRYPT 0x00200000
434 #define UPL_NOZEROFILL 0x00400000
435 #define UPL_WILL_MODIFY 0x00800000 /* caller will modify the pages */
437 #define UPL_NEED_32BIT_ADDR 0x01000000
439 /* UPL flags known by this kernel */
440 #define UPL_VALID_FLAGS 0x01FFFFFF
443 /* upl abort error flags */
444 #define UPL_ABORT_RESTART 0x1
445 #define UPL_ABORT_UNAVAILABLE 0x2
446 #define UPL_ABORT_ERROR 0x4
447 #define UPL_ABORT_FREE_ON_EMPTY 0x8 /* only implemented in wrappers */
448 #define UPL_ABORT_DUMP_PAGES 0x10
449 #define UPL_ABORT_NOTIFY_EMPTY 0x20
450 #define UPL_ABORT_ALLOW_ACCESS 0x40
452 /* upl pages check flags */
453 #define UPL_CHECK_DIRTY 0x1
457 * upl pagein/pageout flags
460 * when I/O is issued from this UPL it should be done synchronously
462 #define UPL_IOSYNC 0x1
465 * the passed in UPL should not have either a commit or abort
466 * applied to it by the underlying layers... the site that
467 * created the UPL is responsible for cleaning it up.
469 #define UPL_NOCOMMIT 0x2
472 * turn off any speculative read-ahead applied at the I/O layer
474 #define UPL_NORDAHEAD 0x4
477 * pageout request is targeting a real file
478 * as opposed to a swap file.
481 #define UPL_VNODE_PAGER 0x8
483 * this pageout is being originated as part of an explicit
484 * memory synchronization operation... no speculative clustering
485 * should be applied, only the range specified should be pushed.
487 #define UPL_MSYNC 0x10
492 #ifdef MACH_KERNEL_PRIVATE
493 #define UPL_PAGING_ENCRYPTED 0x20
494 #endif /* MACH_KERNEL_PRIVATE */
497 * this pageout is being originated as part of an explicit
498 * memory synchronization operation that is checking for I/O
499 * errors and taking it's own action... if an error occurs,
500 * just abort the pages back into the cache unchanged
502 #define UPL_KEEPCACHED 0x40
506 /* upl commit flags */
507 #define UPL_COMMIT_FREE_ON_EMPTY 0x1 /* only implemented in wrappers */
508 #define UPL_COMMIT_CLEAR_DIRTY 0x2
509 #define UPL_COMMIT_SET_DIRTY 0x4
510 #define UPL_COMMIT_INACTIVATE 0x8
511 #define UPL_COMMIT_NOTIFY_EMPTY 0x10
512 #define UPL_COMMIT_ALLOW_ACCESS 0x20
514 /* flags for return of state from vm_map_get_upl, vm_upl address space */
516 #define UPL_DEV_MEMORY 0x1
517 #define UPL_PHYS_CONTIG 0x2
521 * Flags for the UPL page ops routine. This routine is not exported
522 * out of the kernel at the moment and so the defs live here.
524 #define UPL_POP_DIRTY 0x1
525 #define UPL_POP_PAGEOUT 0x2
526 #define UPL_POP_PRECIOUS 0x4
527 #define UPL_POP_ABSENT 0x8
528 #define UPL_POP_BUSY 0x10
530 #define UPL_POP_PHYSICAL 0x10000000
531 #define UPL_POP_DUMP 0x20000000
532 #define UPL_POP_SET 0x40000000
533 #define UPL_POP_CLR 0x80000000
536 * Flags for the UPL range op routine. This routine is not exported
537 * out of the kernel at the moemet and so the defs live here.
540 * UPL_ROP_ABSENT: Returns the extent of the range presented which
541 * is absent, starting with the start address presented
543 #define UPL_ROP_ABSENT 0x01
545 * UPL_ROP_PRESENT: Returns the extent of the range presented which
546 * is present (i.e. resident), starting with the start address presented
548 #define UPL_ROP_PRESENT 0x02
550 * UPL_ROP_DUMP: Dump the pages which are found in the target object
551 * for the target range.
553 #define UPL_ROP_DUMP 0x04
557 /* access macros for upl_t */
559 #define UPL_DEVICE_PAGE(upl) \
560 (((upl)[(index)].phys_addr != 0) ? (!((upl)[0].device)) : FALSE)
562 #define UPL_PAGE_PRESENT(upl, index) \
563 ((upl)[(index)].phys_addr != 0)
565 #define UPL_PHYS_PAGE(upl, index) \
566 ((upl)[(index)].phys_addr)
568 #define UPL_DIRTY_PAGE(upl, index) \
569 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].dirty) : FALSE)
571 #define UPL_PRECIOUS_PAGE(upl, index) \
572 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].precious) : FALSE)
574 #define UPL_VALID_PAGE(upl, index) \
575 (((upl)[(index)].phys_addr != 0) ? (!((upl)[(index)].absent)) : FALSE)
577 #define UPL_PAGEOUT_PAGE(upl, index) \
578 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].pageout) : FALSE)
580 #define UPL_SET_PAGE_FREE_ON_COMMIT(upl, index) \
581 (((upl)[(index)].phys_addr != 0) ? \
582 ((upl)[(index)].pageout = TRUE) : FALSE)
584 #define UPL_CLR_PAGE_FREE_ON_COMMIT(upl, index) \
585 (((upl)[(index)].phys_addr != 0) ? \
586 ((upl)[(index)].pageout = FALSE) : FALSE)
588 /* The call prototyped below is used strictly by UPL_GET_INTERNAL_PAGE_LIST */
590 extern vm_size_t upl_offset_to_pagelist
;
591 extern vm_size_t
upl_get_internal_pagelist_offset(void);
593 /* UPL_GET_INTERNAL_PAGE_LIST is only valid on internal objects where the */
594 /* list request was made with the UPL_INTERNAL flag */
596 #define UPL_GET_INTERNAL_PAGE_LIST(upl) \
597 ((upl_page_info_t *)((upl_offset_to_pagelist == 0) ? \
598 (unsigned int)upl + (unsigned int)(upl_offset_to_pagelist = upl_get_internal_pagelist_offset()): \
599 (unsigned int)upl + (unsigned int)upl_offset_to_pagelist))
603 extern ppnum_t
upl_phys_page(upl_page_info_t
*upl
, int index
);
604 extern void upl_clear_dirty(upl_t upl
, boolean_t value
);
612 extern boolean_t
upl_page_present(upl_page_info_t
*upl
, int index
);
613 extern boolean_t
upl_dirty_page(upl_page_info_t
*upl
, int index
);
614 extern boolean_t
upl_valid_page(upl_page_info_t
*upl
, int index
);
615 extern void upl_deallocate(upl_t upl
);
621 #endif /* _MACH_MEMORY_OBJECT_TYPES_H_ */