2 * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
29 * Mach Operating System
30 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
31 * All Rights Reserved.
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
43 * Carnegie Mellon requests users of this software to return to
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
56 * File: memory_object.h
57 * Author: Michael Wayne Young
59 * External memory management interface definition.
62 #ifndef _MACH_MEMORY_OBJECT_TYPES_H_
63 #define _MACH_MEMORY_OBJECT_TYPES_H_
66 * User-visible types used in the external memory
67 * management interface:
70 #include <mach/port.h>
71 #include <mach/vm_types.h>
72 #include <mach/machine/vm_types.h>
74 #include <sys/appleapiopts.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
;
81 #ifdef __APPLE_API_EVOLVING
83 * 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
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
192 #ifdef __APPLE_API_UNSTABLE
193 #define OLD_MEMORY_OBJECT_BEHAVIOR_INFO 10
194 #define OLD_MEMORY_OBJECT_ATTRIBUTE_INFO 12
196 struct old_memory_object_behave_info
{
197 memory_object_copy_strategy_t copy_strategy
;
199 boolean_t invalidate
;
202 struct old_memory_object_attr_info
{ /* old attr list */
203 boolean_t object_ready
;
205 memory_object_copy_strategy_t copy_strategy
;
208 typedef struct old_memory_object_behave_info
*old_memory_object_behave_info_t
;
209 typedef struct old_memory_object_behave_info old_memory_object_behave_info_data_t
;
210 typedef struct old_memory_object_attr_info
*old_memory_object_attr_info_t
;
211 typedef struct old_memory_object_attr_info old_memory_object_attr_info_data_t
;
213 #define OLD_MEMORY_OBJECT_BEHAVE_INFO_COUNT \
214 (sizeof(old_memory_object_behave_info_data_t)/sizeof(int))
215 #define OLD_MEMORY_OBJECT_ATTR_INFO_COUNT \
216 (sizeof(old_memory_object_attr_info_data_t)/sizeof(int))
217 #endif /* __APPLE_API_UNSTABLE */
219 struct memory_object_perf_info
{
220 vm_size_t cluster_size
;
224 struct memory_object_attr_info
{
225 memory_object_copy_strategy_t copy_strategy
;
226 vm_offset_t cluster_size
;
227 boolean_t may_cache_object
;
231 struct memory_object_behave_info
{
232 memory_object_copy_strategy_t copy_strategy
;
234 boolean_t invalidate
;
235 boolean_t silent_overwrite
;
236 boolean_t advisory_pageout
;
240 typedef struct memory_object_behave_info
*memory_object_behave_info_t
;
241 typedef struct memory_object_behave_info memory_object_behave_info_data_t
;
243 typedef struct memory_object_perf_info
*memory_object_perf_info_t
;
244 typedef struct memory_object_perf_info memory_object_perf_info_data_t
;
246 typedef struct memory_object_attr_info
*memory_object_attr_info_t
;
247 typedef struct memory_object_attr_info memory_object_attr_info_data_t
;
249 #define MEMORY_OBJECT_BEHAVE_INFO_COUNT \
250 (sizeof(memory_object_behave_info_data_t)/sizeof(int))
251 #define MEMORY_OBJECT_PERF_INFO_COUNT \
252 (sizeof(memory_object_perf_info_data_t)/sizeof(int))
253 #define MEMORY_OBJECT_ATTR_INFO_COUNT \
254 (sizeof(memory_object_attr_info_data_t)/sizeof(int))
256 #define invalid_memory_object_flavor(f) \
257 (f != MEMORY_OBJECT_ATTRIBUTE_INFO && \
258 f != MEMORY_OBJECT_PERFORMANCE_INFO && \
259 f != OLD_MEMORY_OBJECT_BEHAVIOR_INFO && \
260 f != MEMORY_OBJECT_BEHAVIOR_INFO && \
261 f != OLD_MEMORY_OBJECT_ATTRIBUTE_INFO)
265 * Used to support options on memory_object_release_name call
267 #define MEMORY_OBJECT_TERMINATE_IDLE 0x1
268 #define MEMORY_OBJECT_RESPECT_CACHE 0x2
269 #define MEMORY_OBJECT_RELEASE_NO_OP 0x4
273 * Universal Page List data structures
276 #define MAX_UPL_TRANSFER 256
278 struct upl_page_info
{
279 vm_offset_t phys_addr
;
281 pageout
:1, /* page is to be removed on commit */
282 absent
:1, /* No valid data in this page */
283 dirty
:1, /* Page must be cleaned (O) */
284 precious
:1, /* must be cleaned, we have only copy */
285 device
:1, /* no page data, mapped dev memory */
286 :0; /* force to long boundary */
289 typedef struct upl_page_info upl_page_info_t
;
290 typedef upl_page_info_t
*upl_page_info_array_t
;
291 typedef upl_page_info_array_t upl_page_list_ptr_t
;
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 */
313 /* upl invocation flags */
314 /* top nibble is used by super upl */
316 #define UPL_FLAGS_NONE 0x0
317 #define UPL_COPYOUT_FROM 0x1
318 #define UPL_PRECIOUS 0x2
319 #define UPL_NO_SYNC 0x4
320 #define UPL_CLEAN_IN_PLACE 0x8
321 #define UPL_NOBLOCK 0x10
322 #define UPL_RET_ONLY_DIRTY 0x20
323 #define UPL_SET_INTERNAL 0x40
324 #define UPL_QUERY_OBJECT_TYPE 0x80
325 #define UPL_RET_ONLY_ABSENT 0x100 /* used only for COPY_FROM = FALSE */
326 #define UPL_FILE_IO 0x200
327 #define UPL_SET_LITE 0x400
328 #define UPL_SET_INTERRUPTIBLE 0x800
329 #define UPL_SET_IO_WIRE 0x1000
330 #define UPL_FOR_PAGEOUT 0x2000
332 /* upl abort error flags */
333 #define UPL_ABORT_RESTART 0x1
334 #define UPL_ABORT_UNAVAILABLE 0x2
335 #define UPL_ABORT_ERROR 0x4
336 #define UPL_ABORT_FREE_ON_EMPTY 0x8 /* only implemented in wrappers */
337 #define UPL_ABORT_DUMP_PAGES 0x10
338 #define UPL_ABORT_NOTIFY_EMPTY 0x20
340 /* upl pages check flags */
341 #define UPL_CHECK_DIRTY 0x1
343 /* upl pagein/pageout flags */
344 #define UPL_IOSYNC 0x1
345 #define UPL_NOCOMMIT 0x2
346 #define UPL_NORDAHEAD 0x4
348 /* upl commit flags */
349 #define UPL_COMMIT_FREE_ON_EMPTY 0x1 /* only implemented in wrappers */
350 #define UPL_COMMIT_CLEAR_DIRTY 0x2
351 #define UPL_COMMIT_SET_DIRTY 0x4
352 #define UPL_COMMIT_INACTIVATE 0x8
353 #define UPL_COMMIT_NOTIFY_EMPTY 0x10
355 /* flags for return of state from vm_map_get_upl, vm_upl address space */
357 #define UPL_DEV_MEMORY 0x1
358 #define UPL_PHYS_CONTIG 0x2
361 /* access macros for upl_t */
363 #define UPL_DEVICE_PAGE(upl) \
364 (((upl)[(index)].phys_addr != 0) ? (!((upl)[0].device)) : FALSE)
366 #define UPL_PAGE_PRESENT(upl, index) \
367 ((upl)[(index)].phys_addr != 0)
369 #define UPL_PHYS_PAGE(upl, index) \
370 (((upl)[(index)].phys_addr != 0) ? \
371 ((upl)[(index)].phys_addr) : (vm_offset_t)NULL)
373 #define UPL_DIRTY_PAGE(upl, index) \
374 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].dirty) : FALSE)
376 #define UPL_PRECIOUS_PAGE(upl, index) \
377 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].precious) : FALSE)
379 #define UPL_VALID_PAGE(upl, index) \
380 (((upl)[(index)].phys_addr != 0) ? (!((upl)[(index)].absent)) : FALSE)
382 #define UPL_PAGEOUT_PAGE(upl, index) \
383 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].pageout) : FALSE)
385 #define UPL_SET_PAGE_FREE_ON_COMMIT(upl, index) \
386 if ((upl)[(index)].phys_addr != 0) \
387 ((upl)[(index)].pageout) = TRUE
389 #define UPL_CLR_PAGE_FREE_ON_COMMIT(upl, index) \
390 if ((upl)[(index)].phys_addr != 0) \
391 ((upl)[(index)].pageout) = FALSE
395 * Flags for the UPL page ops routine. This routine is not exported
396 * out of the kernel at the moment and so the defs live here.
398 #define UPL_POP_DIRTY 0x1
399 #define UPL_POP_PAGEOUT 0x2
400 #define UPL_POP_PRECIOUS 0x4
401 #define UPL_POP_ABSENT 0x8
402 #define UPL_POP_BUSY 0x10
404 #define UPL_POP_PHYSICAL 0x10000000
405 #define UPL_POP_DUMP 0x20000000
406 #define UPL_POP_SET 0x40000000
407 #define UPL_POP_CLR 0x80000000
411 #ifdef KERNEL_PRIVATE
413 extern void memory_object_reference(memory_object_t object
);
414 extern void memory_object_deallocate(memory_object_t object
);
416 extern void memory_object_default_reference(memory_object_default_t
);
417 extern void memory_object_default_deallocate(memory_object_default_t
);
419 extern void memory_object_control_reference(memory_object_control_t control
);
420 extern void memory_object_control_deallocate(memory_object_control_t control
);
423 /* The call prototyped below is used strictly by UPL_GET_INTERNAL_PAGE_LIST */
425 extern vm_size_t upl_offset_to_pagelist
;
426 extern vm_size_t
upl_get_internal_pagelist_offset();
428 /* UPL_GET_INTERNAL_PAGE_LIST is only valid on internal objects where the */
429 /* list request was made with the UPL_INTERNAL flag */
431 #define UPL_GET_INTERNAL_PAGE_LIST(upl) \
432 ((upl_page_info_t *)((upl_offset_to_pagelist == 0) ? \
433 (unsigned int)upl + (unsigned int)(upl_offset_to_pagelist = upl_get_internal_pagelist_offset()): \
434 (unsigned int)upl + (unsigned int)upl_offset_to_pagelist))
436 extern boolean_t
upl_page_present(upl_page_info_t
*upl
, int index
);
438 extern boolean_t
upl_dirty_page(upl_page_info_t
*upl
, int index
);
440 extern boolean_t
upl_valid_page(upl_page_info_t
*upl
, int index
);
442 extern vm_offset_t
upl_phys_page(upl_page_info_t
*upl
, int index
);
444 extern void upl_set_dirty(upl_t upl
);
446 extern void upl_clear_dirty(upl_t upl
);
450 * The following interface definitions should be generated automatically
451 * through Mig definitions or whatever follows the MIG tool as part of the
452 * component API. Until this is up and running however this explicit
453 * description will do.
456 #include <mach/message.h>
458 /* supply a map and a range, a upl will be returned. */
459 extern int kernel_vm_map_get_upl(
464 upl_page_info_array_t page_list
,
467 int force_data_sync
);
469 extern int kernel_upl_map(
472 vm_offset_t
*dst_addr
);
474 extern int kernel_upl_unmap(
478 extern int kernel_upl_commit(
481 mach_msg_type_number_t count
);
483 extern int kernel_upl_commit_range(
488 upl_page_info_array_t pl
,
489 mach_msg_type_number_t count
);
491 extern int kernel_upl_abort(
495 extern int kernel_upl_abort_range(
502 #endif /* KERNEL_PRIVATE */
504 #endif /* __APPLE_API_EVOLVING */
506 #endif /* _MACH_MEMORY_OBJECT_TYPES_H_ */