xref: /titanic_50/usr/src/uts/common/sys/vmem.h (revision 3c112a2b34403220c06c3e2fcac403358cfba168)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
23  */
24 
25 #ifndef _SYS_VMEM_H
26 #define	_SYS_VMEM_H
27 
28 #include <sys/types.h>
29 
30 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 
35 /*
36  * Per-allocation flags
37  */
38 #define	VM_SLEEP	0x00000000	/* same as KM_SLEEP */
39 #define	VM_NOSLEEP	0x00000001	/* same as KM_NOSLEEP */
40 #define	VM_PANIC	0x00000002	/* same as KM_PANIC */
41 #define	VM_PUSHPAGE	0x00000004	/* same as KM_PUSHPAGE */
42 #define	VM_NORMALPRI	0x00000008	/* same as KM_NORMALPRI */
43 #define	VM_KMFLAGS	0x000000ff	/* flags that must match KM_* flags */
44 
45 #define	VM_BESTFIT	0x00000100
46 #define	VM_FIRSTFIT	0x00000200
47 #define	VM_NEXTFIT	0x00000400
48 
49 /*
50  * The following flags are restricted for use only within the kernel.
51  * VM_MEMLOAD is for use by the HAT to avoid infinite recursion.
52  * VM_NORELOC is used by the kernel when static VA->PA mappings are required.
53  */
54 #define	VM_MEMLOAD	0x00000800
55 #define	VM_NORELOC	0x00001000
56 /*
57  * VM_ABORT requests that vmem_alloc() *ignore* the VM_SLEEP/VM_NOSLEEP flags
58  * and forgo reaping if the allocation or attempted import, fails.  This
59  * flag is a segkmem-specific flag, and should not be used by anyone else.
60  */
61 #define	VM_ABORT	0x00002000
62 
63 /*
64  * VM_ENDALLOC requests that large addresses be preferred in allocations.
65  * Has no effect if VM_NEXTFIT is active.
66  */
67 #define	VM_ENDALLOC	0x00004000
68 
69 #define	VM_FLAGS	0x0000FFFF
70 
71 /*
72  * Arena creation flags
73  */
74 #define	VMC_POPULATOR	0x00010000
75 #define	VMC_NO_QCACHE	0x00020000	/* cannot use quantum caches */
76 #define	VMC_IDENTIFIER	0x00040000	/* not backed by memory */
77 #define	VMC_DUMPSAFE	0x00200000	/* can use alternate dump memory */
78 /*
79  * internal use only;	the import function uses the vmem_ximport_t interface
80  *			and may increase the request size if it so desires.
81  *			VMC_XALIGN, for use with vmem_xcreate, specifies that
82  *			the address returned by the import function will be
83  *			aligned according to the alignment argument.
84  */
85 #define	VMC_XALLOC	0x00080000
86 #define	VMC_XALIGN	0x00100000
87 #define	VMC_FLAGS	0xFFFF0000
88 
89 /*
90  * Public segment types
91  */
92 #define	VMEM_ALLOC	0x01
93 #define	VMEM_FREE	0x02
94 
95 /*
96  * Implementation-private segment types
97  */
98 #define	VMEM_SPAN	0x10
99 #define	VMEM_ROTOR	0x20
100 #define	VMEM_WALKER	0x40
101 
102 /*
103  * VMEM_REENTRANT indicates to vmem_walk() that the callback routine may
104  * call back into the arena being walked, so vmem_walk() must drop the
105  * arena lock before each callback.  The caveat is that since the arena
106  * isn't locked, its state can change.  Therefore it is up to the callback
107  * routine to handle cases where the segment isn't of the expected type.
108  * For example, we use this to walk heap_arena when generating a crash dump;
109  * see segkmem_dump() for sample usage.
110  */
111 #define	VMEM_REENTRANT	0x80000000
112 
113 typedef struct vmem vmem_t;
114 typedef void *(vmem_alloc_t)(vmem_t *, size_t, int);
115 typedef void (vmem_free_t)(vmem_t *, void *, size_t);
116 
117 /*
118  * Alternate import style; the requested size is passed in a pointer,
119  * which can be increased by the import function if desired.
120  */
121 typedef void *(vmem_ximport_t)(vmem_t *, size_t *, size_t, int);
122 
123 #ifdef _KERNEL
124 extern vmem_t *vmem_init(const char *, void *, size_t, size_t,
125     vmem_alloc_t *, vmem_free_t *);
126 extern void vmem_update(void *);
127 extern int vmem_is_populator();
128 extern size_t vmem_seg_size;
129 #endif
130 
131 extern vmem_t *vmem_create(const char *, void *, size_t, size_t,
132     vmem_alloc_t *, vmem_free_t *, vmem_t *, size_t, int);
133 extern vmem_t *vmem_xcreate(const char *, void *, size_t, size_t,
134     vmem_ximport_t *, vmem_free_t *, vmem_t *, size_t, int);
135 extern void vmem_destroy(vmem_t *);
136 extern void *vmem_alloc(vmem_t *, size_t, int);
137 extern void *vmem_xalloc(vmem_t *, size_t, size_t, size_t, size_t,
138     void *, void *, int);
139 extern void vmem_free(vmem_t *, void *, size_t);
140 extern void vmem_xfree(vmem_t *, void *, size_t);
141 extern void *vmem_add(vmem_t *, void *, size_t, int);
142 extern int vmem_contains(vmem_t *, void *, size_t);
143 extern void vmem_walk(vmem_t *, int, void (*)(void *, void *, size_t), void *);
144 extern size_t vmem_size(vmem_t *, int);
145 
146 #ifdef	__cplusplus
147 }
148 #endif
149 
150 #endif	/* _SYS_VMEM_H */
151