]> git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/memory_object_types.h
1c91b74148789028b96c718b6e511df752150393
[apple/xnu.git] / osfmk / mach / memory_object_types.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33 /*
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
36 * All Rights Reserved.
37 *
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.
43 *
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.
47 *
48 * Carnegie Mellon requests users of this software to return to
49 *
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
54 *
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
57 */
58 /*
59 */
60 /*
61 * File: memory_object.h
62 * Author: Michael Wayne Young
63 *
64 * External memory management interface definition.
65 */
66
67 #ifndef _MACH_MEMORY_OBJECT_TYPES_H_
68 #define _MACH_MEMORY_OBJECT_TYPES_H_
69
70 /*
71 * User-visible types used in the external memory
72 * management interface:
73 */
74
75 #include <mach/port.h>
76 #include <mach/message.h>
77 #include <mach/vm_types.h>
78 #include <mach/machine/vm_types.h>
79
80 #include <sys/cdefs.h>
81
82 #define VM_64_BIT_DATA_OBJECTS
83
84 typedef unsigned long long memory_object_offset_t;
85 typedef unsigned long long memory_object_size_t;
86
87 /*
88 * Temporary until real EMMI version gets re-implemented
89 */
90
91 #ifdef KERNEL_PRIVATE
92
93 typedef struct memory_object {
94 int *pager;
95 } *memory_object_t;
96
97 typedef struct memory_object_control {
98 struct vm_object *object;
99 } *memory_object_control_t;
100
101 #else /* KERNEL_PRIVATE */
102
103 typedef mach_port_t memory_object_t;
104 typedef mach_port_t memory_object_control_t;
105
106 #endif /* KERNEL_PRIVATE */
107
108 typedef memory_object_t *memory_object_array_t;
109 /* A memory object ... */
110 /* Used by the kernel to retrieve */
111 /* or store data */
112
113 typedef mach_port_t memory_object_name_t;
114 /* Used to describe the memory ... */
115 /* object in vm_regions() calls */
116
117 typedef mach_port_t memory_object_default_t;
118 /* Registered with the host ... */
119 /* for creating new internal objects */
120
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)
125
126
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.
136 */
137 #define MEMORY_OBJECT_COPY_TEMPORARY 3
138 /* ... Memory manager doesn't
139 * change data externally, and
140 * doesn't need to see changes.
141 */
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
147 * multiply mapped.
148 *
149 * XXX
150 * Not yet safe for non-kernel use.
151 */
152
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
160 * internal.
161 */
162
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. */
174
175 /*
176 * Data lock request flags
177 */
178
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
185
186 /*
187 * Types for the memory object flavor interfaces
188 */
189
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];
194
195
196 #define MEMORY_OBJECT_PERFORMANCE_INFO 11
197 #define MEMORY_OBJECT_ATTRIBUTE_INFO 14
198 #define MEMORY_OBJECT_BEHAVIOR_INFO 15
199
200 #ifdef PRIVATE
201
202 #define OLD_MEMORY_OBJECT_BEHAVIOR_INFO 10
203 #define OLD_MEMORY_OBJECT_ATTRIBUTE_INFO 12
204
205 struct old_memory_object_behave_info {
206 memory_object_copy_strategy_t copy_strategy;
207 boolean_t temporary;
208 boolean_t invalidate;
209 };
210
211 struct old_memory_object_attr_info { /* old attr list */
212 boolean_t object_ready;
213 boolean_t may_cache;
214 memory_object_copy_strategy_t copy_strategy;
215 };
216
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;
221
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)))
226
227 #ifdef KERNEL
228
229 __BEGIN_DECLS
230 extern void memory_object_reference(memory_object_t object);
231 extern void memory_object_deallocate(memory_object_t object);
232
233 extern void memory_object_default_reference(memory_object_default_t);
234 extern void memory_object_default_deallocate(memory_object_default_t);
235
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);
239 __END_DECLS
240
241 #endif /* KERNEL */
242
243 #endif /* PRIVATE */
244
245 typedef natural_t memory_object_cluster_size_t;
246
247 struct memory_object_perf_info {
248 memory_object_cluster_size_t cluster_size;
249 boolean_t may_cache;
250 };
251
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;
256 boolean_t temporary;
257 };
258
259 struct memory_object_behave_info {
260 memory_object_copy_strategy_t copy_strategy;
261 boolean_t temporary;
262 boolean_t invalidate;
263 boolean_t silent_overwrite;
264 boolean_t advisory_pageout;
265 };
266
267
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;
270
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;
273
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;
276
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)))
283
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)
290
291
292 /*
293 * Used to support options on memory_object_release_name call
294 */
295 #define MEMORY_OBJECT_TERMINATE_IDLE 0x1
296 #define MEMORY_OBJECT_RESPECT_CACHE 0x2
297 #define MEMORY_OBJECT_RELEASE_NO_OP 0x4
298
299
300 /* named entry processor mapping options */
301 /* enumerated */
302 #define MAP_MEM_NOOP 0
303 #define MAP_MEM_COPYBACK 1
304 #define MAP_MEM_IO 2
305 #define MAP_MEM_WTHRU 3
306 #define MAP_MEM_WCOMB 4 /* Write combining mode */
307 /* aka store gather */
308
309 #define GET_MAP_MEM(flags) \
310 ((((unsigned int)(flags)) >> 24) & 0xFF)
311
312 #define SET_MAP_MEM(caching, flags) \
313 ((flags) = ((((unsigned int)(caching)) << 24) \
314 & 0xFF000000) | ((flags) & 0xFFFFFF));
315
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 */
321
322 #ifdef KERNEL
323
324 /*
325 * Universal Page List data structures
326 *
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.
331 */
332 #ifdef PRIVATE
333 #define MAX_UPL_TRANSFER 256
334
335 struct upl_page_info {
336 ppnum_t phys_addr; /* physical page index number */
337 unsigned int
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 */
345 #else
346 opaque; /* use upl_page_xxx() accessor funcs */
347 #endif /* XNU_KERNEL_PRIVATE */
348 };
349
350 #else
351
352 struct upl_page_info {
353 unsigned int opaque[2]; /* use upl_page_xxx() accessor funcs */
354 };
355
356 #endif /* PRIVATE */
357
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;
361
362 typedef uint32_t upl_offset_t; /* page-aligned byte offset */
363 typedef uint32_t upl_size_t; /* page-aligned byte size */
364
365 /* upl invocation flags */
366 /* top nibble is used by super upl */
367
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... */
386
387 #define UPL_PAGE_TICKET_MASK 0x000F0000
388 #define UPL_PAGE_TICKET_SHIFT 16
389
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 */
395
396 /* UPL flags known by this kernel */
397 #define UPL_VALID_FLAGS 0x00FFFFFF
398
399
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
408
409 /* upl pages check flags */
410 #define UPL_CHECK_DIRTY 0x1
411
412
413 /*
414 * upl pagein/pageout flags
415 *
416 *
417 * when I/O is issued from this UPL it should be done synchronously
418 */
419 #define UPL_IOSYNC 0x1
420
421 /*
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.
425 */
426 #define UPL_NOCOMMIT 0x2
427
428 /*
429 * turn off any speculative read-ahead applied at the I/O layer
430 */
431 #define UPL_NORDAHEAD 0x4
432
433 /*
434 * pageout request is targeting a real file
435 * as opposed to a swap file.
436 */
437
438 #define UPL_VNODE_PAGER 0x8
439 /*
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.
443 */
444 #define UPL_MSYNC 0x10
445
446 /*
447 *
448 */
449 #ifdef MACH_KERNEL_PRIVATE
450 #define UPL_PAGING_ENCRYPTED 0x20
451 #endif /* MACH_KERNEL_PRIVATE */
452
453 /*
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
458 */
459 #define UPL_KEEPCACHED 0x40
460
461
462
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
470
471 /* flags for return of state from vm_map_get_upl, vm_upl address space */
472 /* based call */
473 #define UPL_DEV_MEMORY 0x1
474 #define UPL_PHYS_CONTIG 0x2
475
476
477 /*
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.
480 */
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
486
487 #define UPL_POP_PHYSICAL 0x10000000
488 #define UPL_POP_DUMP 0x20000000
489 #define UPL_POP_SET 0x40000000
490 #define UPL_POP_CLR 0x80000000
491
492 /*
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.
495 */
496 /*
497 * UPL_ROP_ABSENT: Returns the extent of the range presented which
498 * is absent, starting with the start address presented
499 */
500 #define UPL_ROP_ABSENT 0x01
501 /*
502 * UPL_ROP_PRESENT: Returns the extent of the range presented which
503 * is present (i.e. resident), starting with the start address presented
504 */
505 #define UPL_ROP_PRESENT 0x02
506 /*
507 * UPL_ROP_DUMP: Dump the pages which are found in the target object
508 * for the target range.
509 */
510 #define UPL_ROP_DUMP 0x04
511
512 #ifdef PRIVATE
513
514 /* access macros for upl_t */
515
516 #define UPL_DEVICE_PAGE(upl) \
517 (((upl)[(index)].phys_addr != 0) ? (!((upl)[0].device)) : FALSE)
518
519 #define UPL_PAGE_PRESENT(upl, index) \
520 ((upl)[(index)].phys_addr != 0)
521
522 #define UPL_PHYS_PAGE(upl, index) \
523 ((upl)[(index)].phys_addr)
524
525 #define UPL_DIRTY_PAGE(upl, index) \
526 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].dirty) : FALSE)
527
528 #define UPL_PRECIOUS_PAGE(upl, index) \
529 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].precious) : FALSE)
530
531 #define UPL_VALID_PAGE(upl, index) \
532 (((upl)[(index)].phys_addr != 0) ? (!((upl)[(index)].absent)) : FALSE)
533
534 #define UPL_PAGEOUT_PAGE(upl, index) \
535 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].pageout) : FALSE)
536
537 #define UPL_SET_PAGE_FREE_ON_COMMIT(upl, index) \
538 (((upl)[(index)].phys_addr != 0) ? \
539 ((upl)[(index)].pageout = TRUE) : FALSE)
540
541 #define UPL_CLR_PAGE_FREE_ON_COMMIT(upl, index) \
542 (((upl)[(index)].phys_addr != 0) ? \
543 ((upl)[(index)].pageout = FALSE) : FALSE)
544
545 /* The call prototyped below is used strictly by UPL_GET_INTERNAL_PAGE_LIST */
546
547 extern vm_size_t upl_offset_to_pagelist;
548 extern vm_size_t upl_get_internal_pagelist_offset(void);
549
550 /* UPL_GET_INTERNAL_PAGE_LIST is only valid on internal objects where the */
551 /* list request was made with the UPL_INTERNAL flag */
552
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))
557
558 __BEGIN_DECLS
559
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);
563
564 __END_DECLS
565
566 #endif /* PRIVATE */
567
568 __BEGIN_DECLS
569
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);
574
575 __END_DECLS
576
577 #endif /* KERNEL */
578
579 #endif /* _MACH_MEMORY_OBJECT_TYPES_H_ */