xref: /titanic_50/usr/src/uts/common/sys/vmem.h (revision 8883f1c270cc8e33c18dd088e744840092b47bbb)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_VMEM_H
27 #define	_SYS_VMEM_H
28 
29 #include <sys/types.h>
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 
36 /*
37  * Per-allocation flags
38  */
39 #define	VM_SLEEP	0x00000000	/* same as KM_SLEEP */
40 #define	VM_NOSLEEP	0x00000001	/* same as KM_NOSLEEP */
41 #define	VM_PANIC	0x00000002	/* same as KM_PANIC */
42 #define	VM_PUSHPAGE	0x00000004	/* same as KM_PUSHPAGE */
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 /*
78  * internal use only;	the import function uses the vmem_ximport_t interface
79  *			and may increase the request size if it so desires.
80  *			VMC_XALIGN, for use with vmem_xcreate, specifies that
81  *			the address returned by the import function will be
82  *			aligned according to the alignment argument.
83  */
84 #define	VMC_XALLOC	0x00080000
85 #define	VMC_XALIGN	0x00100000
86 #define	VMC_FLAGS	0xFFFF0000
87 
88 /*
89  * Public segment types
90  */
91 #define	VMEM_ALLOC	0x01
92 #define	VMEM_FREE	0x02
93 
94 /*
95  * Implementation-private segment types
96  */
97 #define	VMEM_SPAN	0x10
98 #define	VMEM_ROTOR	0x20
99 #define	VMEM_WALKER	0x40
100 
101 /*
102  * VMEM_REENTRANT indicates to vmem_walk() that the callback routine may
103  * call back into the arena being walked, so vmem_walk() must drop the
104  * arena lock before each callback.  The caveat is that since the arena
105  * isn't locked, its state can change.  Therefore it is up to the callback
106  * routine to handle cases where the segment isn't of the expected type.
107  * For example, we use this to walk heap_arena when generating a crash dump;
108  * see segkmem_dump() for sample usage.
109  */
110 #define	VMEM_REENTRANT	0x80000000
111 
112 typedef struct vmem vmem_t;
113 typedef void *(vmem_alloc_t)(vmem_t *, size_t, int);
114 typedef void (vmem_free_t)(vmem_t *, void *, size_t);
115 
116 /*
117  * Alternate import style; the requested size is passed in a pointer,
118  * which can be increased by the import function if desired.
119  */
120 typedef void *(vmem_ximport_t)(vmem_t *, size_t *, size_t, int);
121 
122 #ifdef _KERNEL
123 extern vmem_t *vmem_init(const char *, void *, size_t, size_t,
124     vmem_alloc_t *, vmem_free_t *);
125 extern void vmem_update(void *);
126 extern int vmem_is_populator();
127 extern size_t vmem_seg_size;
128 #endif
129 
130 extern vmem_t *vmem_create(const char *, void *, size_t, size_t,
131     vmem_alloc_t *, vmem_free_t *, vmem_t *, size_t, int);
132 extern vmem_t *vmem_xcreate(const char *, void *, size_t, size_t,
133     vmem_ximport_t *, vmem_free_t *, vmem_t *, size_t, int);
134 extern void vmem_destroy(vmem_t *);
135 extern void *vmem_alloc(vmem_t *, size_t, int);
136 extern void *vmem_xalloc(vmem_t *, size_t, size_t, size_t, size_t,
137     void *, void *, int);
138 extern void vmem_free(vmem_t *, void *, size_t);
139 extern void vmem_xfree(vmem_t *, void *, size_t);
140 extern void *vmem_add(vmem_t *, void *, size_t, int);
141 extern int vmem_contains(vmem_t *, void *, size_t);
142 extern void vmem_walk(vmem_t *, int, void (*)(void *, void *, size_t), void *);
143 extern size_t vmem_size(vmem_t *, int);
144 
145 #ifdef	__cplusplus
146 }
147 #endif
148 
149 #endif	/* _SYS_VMEM_H */
150