2 * Copyright (c) 2000-2001 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/vm_types.h>
69 #include <mach/machine/vm_types.h>
71 #define VM_64_BIT_DATA_OBJECTS
73 typedef unsigned long long memory_object_offset_t
;
74 typedef unsigned long long memory_object_size_t
;
77 * Temporary until real EMMI version gets re-implemented
80 typedef struct memory_object
{
84 typedef struct memory_object_control
{
85 struct vm_object
*object
;
86 } *memory_object_control_t
;
88 #else /* !KERNEL_PRIVATE */
90 typedef mach_port_t memory_object_t
;
91 typedef mach_port_t memory_object_control_t
;
93 #endif /* !KERNEL_PRIVATE */
95 typedef memory_object_t
*memory_object_array_t
;
96 /* A memory object ... */
97 /* Used by the kernel to retrieve */
100 typedef mach_port_t memory_object_name_t
;
101 /* Used to describe the memory ... */
102 /* object in vm_regions() calls */
104 typedef mach_port_t memory_object_default_t
;
105 /* Registered with the host ... */
106 /* for creating new internal objects */
108 #define MEMORY_OBJECT_NULL ((memory_object_t) 0)
109 #define MEMORY_OBJECT_CONTROL_NULL ((memory_object_control_t) 0)
110 #define MEMORY_OBJECT_NAME_NULL ((memory_object_name_t) 0)
111 #define MEMORY_OBJECT_DEFAULT_NULL ((memory_object_default_t) 0)
114 typedef int memory_object_copy_strategy_t
;
115 /* How memory manager handles copy: */
116 #define MEMORY_OBJECT_COPY_NONE 0
117 /* ... No special support */
118 #define MEMORY_OBJECT_COPY_CALL 1
119 /* ... Make call on memory manager */
120 #define MEMORY_OBJECT_COPY_DELAY 2
121 /* ... Memory manager doesn't
122 * change data externally.
124 #define MEMORY_OBJECT_COPY_TEMPORARY 3
125 /* ... Memory manager doesn't
126 * change data externally, and
127 * doesn't need to see changes.
129 #define MEMORY_OBJECT_COPY_SYMMETRIC 4
130 /* ... Memory manager doesn't
131 * change data externally,
132 * doesn't need to see changes,
133 * and object will not be
137 * Not yet safe for non-kernel use.
140 #define MEMORY_OBJECT_COPY_INVALID 5
141 /* ... An invalid copy strategy,
142 * for external objects which
143 * have not been initialized.
144 * Allows copy_strategy to be
145 * examined without also
146 * examining pager_ready and
150 typedef int memory_object_return_t
;
151 /* Which pages to return to manager
152 this time (lock_request) */
153 #define MEMORY_OBJECT_RETURN_NONE 0
154 /* ... don't return any. */
155 #define MEMORY_OBJECT_RETURN_DIRTY 1
156 /* ... only dirty pages. */
157 #define MEMORY_OBJECT_RETURN_ALL 2
158 /* ... dirty and precious pages. */
159 #define MEMORY_OBJECT_RETURN_ANYTHING 3
160 /* ... any resident page. */
163 * Data lock request flags
166 #define MEMORY_OBJECT_DATA_FLUSH 0x1
167 #define MEMORY_OBJECT_DATA_NO_CHANGE 0x2
168 #define MEMORY_OBJECT_DATA_PURGE 0x4
169 #define MEMORY_OBJECT_COPY_SYNC 0x8
170 #define MEMORY_OBJECT_DATA_SYNC 0x10
173 * Types for the memory object flavor interfaces
176 #define MEMORY_OBJECT_INFO_MAX (1024)
177 typedef int *memory_object_info_t
;
178 typedef int memory_object_flavor_t
;
179 typedef int memory_object_info_data_t
[MEMORY_OBJECT_INFO_MAX
];
182 #define OLD_MEMORY_OBJECT_BEHAVIOR_INFO 10
183 #define MEMORY_OBJECT_PERFORMANCE_INFO 11
184 #define OLD_MEMORY_OBJECT_ATTRIBUTE_INFO 12
185 #define MEMORY_OBJECT_ATTRIBUTE_INFO 14
186 #define MEMORY_OBJECT_BEHAVIOR_INFO 15
189 struct old_memory_object_behave_info
{
190 memory_object_copy_strategy_t copy_strategy
;
192 boolean_t invalidate
;
195 struct memory_object_perf_info
{
196 vm_size_t cluster_size
;
200 struct old_memory_object_attr_info
{ /* old attr list */
201 boolean_t object_ready
;
203 memory_object_copy_strategy_t copy_strategy
;
206 struct memory_object_attr_info
{
207 memory_object_copy_strategy_t copy_strategy
;
208 vm_offset_t cluster_size
;
209 boolean_t may_cache_object
;
213 struct memory_object_behave_info
{
214 memory_object_copy_strategy_t copy_strategy
;
216 boolean_t invalidate
;
217 boolean_t silent_overwrite
;
218 boolean_t advisory_pageout
;
221 typedef struct old_memory_object_behave_info
*old_memory_object_behave_info_t
;
222 typedef struct old_memory_object_behave_info old_memory_object_behave_info_data_t
;
224 typedef struct memory_object_behave_info
*memory_object_behave_info_t
;
225 typedef struct memory_object_behave_info memory_object_behave_info_data_t
;
227 typedef struct memory_object_perf_info
*memory_object_perf_info_t
;
228 typedef struct memory_object_perf_info memory_object_perf_info_data_t
;
230 typedef struct old_memory_object_attr_info
*old_memory_object_attr_info_t
;
231 typedef struct old_memory_object_attr_info old_memory_object_attr_info_data_t
;
233 typedef struct memory_object_attr_info
*memory_object_attr_info_t
;
234 typedef struct memory_object_attr_info memory_object_attr_info_data_t
;
236 #define OLD_MEMORY_OBJECT_BEHAVE_INFO_COUNT \
237 (sizeof(old_memory_object_behave_info_data_t)/sizeof(int))
238 #define MEMORY_OBJECT_BEHAVE_INFO_COUNT \
239 (sizeof(memory_object_behave_info_data_t)/sizeof(int))
240 #define MEMORY_OBJECT_PERF_INFO_COUNT \
241 (sizeof(memory_object_perf_info_data_t)/sizeof(int))
242 #define OLD_MEMORY_OBJECT_ATTR_INFO_COUNT \
243 (sizeof(old_memory_object_attr_info_data_t)/sizeof(int))
244 #define MEMORY_OBJECT_ATTR_INFO_COUNT \
245 (sizeof(memory_object_attr_info_data_t)/sizeof(int))
247 #define invalid_memory_object_flavor(f) \
248 (f != MEMORY_OBJECT_ATTRIBUTE_INFO && \
249 f != MEMORY_OBJECT_PERFORMANCE_INFO && \
250 f != OLD_MEMORY_OBJECT_BEHAVIOR_INFO && \
251 f != MEMORY_OBJECT_BEHAVIOR_INFO && \
252 f != OLD_MEMORY_OBJECT_ATTRIBUTE_INFO)
256 * Used to support options on memory_object_release_name call
258 #define MEMORY_OBJECT_TERMINATE_IDLE 0x1
259 #define MEMORY_OBJECT_RESPECT_CACHE 0x2
260 #define MEMORY_OBJECT_RELEASE_NO_OP 0x4
264 * Universal Page List data structures
267 #define MAX_UPL_TRANSFER 256
269 struct upl_page_info
{
270 vm_offset_t phys_addr
;
272 pageout
:1, /* page is to be removed on commit */
273 absent
:1, /* No valid data in this page */
274 dirty
:1, /* Page must be cleaned (O) */
275 precious
:1, /* must be cleaned, we have only copy */
276 device
:1, /* no page data, mapped dev memory */
277 :0; /* force to long boundary */
280 typedef struct upl_page_info upl_page_info_t
;
281 typedef upl_page_info_t
*upl_page_info_array_t
;
282 typedef upl_page_info_array_t upl_page_list_ptr_t
;
285 /* upl invocation flags */
287 #define UPL_FLAGS_NONE 0x0
288 #define UPL_COPYOUT_FROM 0x1
289 #define UPL_PRECIOUS 0x2
290 #define UPL_NO_SYNC 0x4
291 #define UPL_CLEAN_IN_PLACE 0x8
292 #define UPL_NOBLOCK 0x10
293 #define UPL_RET_ONLY_DIRTY 0x20
294 #define UPL_SET_INTERNAL 0x40
295 #define UPL_QUERY_OBJECT_TYPE 0x80
297 /* upl abort error flags */
298 #define UPL_ABORT_RESTART 0x1
299 #define UPL_ABORT_UNAVAILABLE 0x2
300 #define UPL_ABORT_ERROR 0x4
301 #define UPL_ABORT_FREE_ON_EMPTY 0x8 /* only implemented in wrappers */
302 #define UPL_ABORT_DUMP_PAGES 0x10
303 #define UPL_ABORT_NOTIFY_EMPTY 0x20
305 /* upl pages check flags */
306 #define UPL_CHECK_DIRTY 0x1
308 /* upl pagein/pageout flags */
309 #define UPL_IOSYNC 0x1
310 #define UPL_NOCOMMIT 0x2
311 #define UPL_NORDAHEAD 0x4
313 /* upl commit flags */
314 #define UPL_COMMIT_FREE_ON_EMPTY 0x1 /* only implemented in wrappers */
315 #define UPL_COMMIT_CLEAR_DIRTY 0x2
316 #define UPL_COMMIT_SET_DIRTY 0x4
317 #define UPL_COMMIT_INACTIVATE 0x8
318 #define UPL_COMMIT_NOTIFY_EMPTY 0x10
320 /* flags for return of state from vm_map_get_upl, vm_upl address space */
322 #define UPL_DEV_MEMORY 0x1
323 #define UPL_PHYS_CONTIG 0x2
326 /* access macros for upl_t */
328 #define UPL_DEVICE_PAGE(upl) \
329 (((upl)[(index)].phys_addr != 0) ? (!((upl)[0].device)) : FALSE)
331 #define UPL_PAGE_PRESENT(upl, index) \
332 ((upl)[(index)].phys_addr != 0)
334 #define UPL_PHYS_PAGE(upl, index) \
335 (((upl)[(index)].phys_addr != 0) ? \
336 ((upl)[(index)].phys_addr) : (vm_offset_t)NULL)
338 #define UPL_DIRTY_PAGE(upl, index) \
339 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].dirty) : FALSE)
341 #define UPL_PRECIOUS_PAGE(upl, index) \
342 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].precious) : FALSE)
344 #define UPL_VALID_PAGE(upl, index) \
345 (((upl)[(index)].phys_addr != 0) ? (!((upl)[(index)].absent)) : FALSE)
347 #define UPL_PAGEOUT_PAGE(upl, index) \
348 (((upl)[(index)].phys_addr != 0) ? ((upl)[(index)].pageout) : FALSE)
350 #define UPL_SET_PAGE_FREE_ON_COMMIT(upl, index) \
351 if ((upl)[(index)].phys_addr != 0) \
352 ((upl)[(index)].pageout) = TRUE
354 #define UPL_CLR_PAGE_FREE_ON_COMMIT(upl, index) \
355 if ((upl)[(index)].phys_addr != 0) \
356 ((upl)[(index)].pageout) = FALSE
360 * Flags for the UPL page ops routine. This routine is not exported
361 * out of the kernel at the moment and so the defs live here.
363 #define UPL_POP_DIRTY 0x1
364 #define UPL_POP_PAGEOUT 0x2
365 #define UPL_POP_PRECIOUS 0x4
366 #define UPL_POP_ABSENT 0x8
367 #define UPL_POP_BUSY 0x10
369 #define UPL_POP_PHYSICAL 0x10000000
370 #define UPL_POP_DUMP 0x20000000
371 #define UPL_POP_SET 0x40000000
372 #define UPL_POP_CLR 0x80000000
375 #ifdef KERNEL_PRIVATE
377 extern void memory_object_reference(memory_object_t object
);
378 extern void memory_object_deallocate(memory_object_t object
);
380 extern void memory_object_default_reference(memory_object_default_t
);
381 extern void memory_object_default_deallocate(memory_object_default_t
);
383 extern void memory_object_control_reference(memory_object_control_t control
);
384 extern void memory_object_control_deallocate(memory_object_control_t control
);
387 /* The call prototyped below is used strictly by UPL_GET_INTERNAL_PAGE_LIST */
389 extern vm_size_t upl_offset_to_pagelist
;
390 extern vm_size_t
upl_get_internal_pagelist_offset();
392 /* UPL_GET_INTERNAL_PAGE_LIST is only valid on internal objects where the */
393 /* list request was made with the UPL_INTERNAL flag */
395 #define UPL_GET_INTERNAL_PAGE_LIST(upl) \
396 ((upl_page_info_t *)((upl_offset_to_pagelist == 0) ? \
397 (unsigned int)upl + (unsigned int)(upl_offset_to_pagelist = upl_get_internal_pagelist_offset()): \
398 (unsigned int)upl + (unsigned int)upl_offset_to_pagelist))
400 extern boolean_t
upl_page_present(upl_page_info_t
*upl
, int index
);
402 extern boolean_t
upl_dirty_page(upl_page_info_t
*upl
, int index
);
404 extern boolean_t
upl_valid_page(upl_page_info_t
*upl
, int index
);
406 extern vm_offset_t
upl_phys_page(upl_page_info_t
*upl
, int index
);
408 extern void upl_set_dirty(upl_t upl
);
410 extern void upl_clear_dirty(upl_t upl
);
412 #endif /* KERNEL_PRIVATE */
414 #endif /* _MACH_MEMORY_OBJECT_TYPES_H_ */