xref: /titanic_50/usr/src/uts/common/sys/vmem.h (revision 2df1fe9ca32bb227b9158c67f5c00b54c20b10fd)
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 2007 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 
33 #ifdef	__cplusplus
34 extern "C" {
35 #endif
36 
37 
38 /*
39  * Per-allocation flags
40  */
41 #define	VM_SLEEP	0x00000000	/* same as KM_SLEEP */
42 #define	VM_NOSLEEP	0x00000001	/* same as KM_NOSLEEP */
43 #define	VM_PANIC	0x00000002	/* same as KM_PANIC */
44 #define	VM_PUSHPAGE	0x00000004	/* same as KM_PUSHPAGE */
45 #define	VM_KMFLAGS	0x000000ff	/* flags that must match KM_* flags */
46 
47 #define	VM_BESTFIT	0x00000100
48 #define	VM_FIRSTFIT	0x00000200
49 #define	VM_NEXTFIT	0x00000400
50 
51 /*
52  * The following flags are restricted for use only within the kernel.
53  * VM_MEMLOAD is for use by the HAT to avoid infinite recursion.
54  * VM_NORELOC is used by the kernel when static VA->PA mappings are required.
55  */
56 #define	VM_MEMLOAD	0x00000800
57 #define	VM_NORELOC	0x00001000
58 /*
59  * VM_ABORT requests that vmem_alloc() *ignore* the VM_SLEEP/VM_NOSLEEP flags
60  * and forgo reaping if the allocation or attempted import, fails.  This
61  * flag is a segkmem-specific flag, and should not be used by anyone else.
62  */
63 #define	VM_ABORT	0x00002000
64 
65 #define	VM_FLAGS	0x0000FFFF
66 
67 /*
68  * Arena creation flags
69  */
70 #define	VMC_POPULATOR	0x00010000
71 #define	VMC_NO_QCACHE	0x00020000	/* cannot use quantum caches */
72 #define	VMC_IDENTIFIER	0x00040000	/* not backed by memory */
73 /*
74  * internal use only;	the import function uses the vmem_ximport_t interface
75  *			and may increase the request size if it so desires.
76  *			VMC_XALIGN, for use with vmem_xcreate, specifies that
77  *			the address returned by the import function will be
78  *			aligned according to the alignment argument.
79  */
80 #define	VMC_XALLOC	0x00080000
81 #define	VMC_XALIGN	0x00100000
82 #define	VMC_FLAGS	0xFFFF0000
83 
84 /*
85  * Public segment types
86  */
87 #define	VMEM_ALLOC	0x01
88 #define	VMEM_FREE	0x02
89 
90 /*
91  * Implementation-private segment types
92  */
93 #define	VMEM_SPAN	0x10
94 #define	VMEM_ROTOR	0x20
95 #define	VMEM_WALKER	0x40
96 
97 /*
98  * VMEM_REENTRANT indicates to vmem_walk() that the callback routine may
99  * call back into the arena being walked, so vmem_walk() must drop the
100  * arena lock before each callback.  The caveat is that since the arena
101  * isn't locked, its state can change.  Therefore it is up to the callback
102  * routine to handle cases where the segment isn't of the expected type.
103  * For example, we use this to walk heap_arena when generating a crash dump;
104  * see segkmem_dump() for sample usage.
105  */
106 #define	VMEM_REENTRANT	0x80000000
107 
108 typedef struct vmem vmem_t;
109 typedef void *(vmem_alloc_t)(vmem_t *, size_t, int);
110 typedef void (vmem_free_t)(vmem_t *, void *, size_t);
111 
112 /*
113  * Alternate import style; the requested size is passed in a pointer,
114  * which can be increased by the import function if desired.
115  */
116 typedef void *(vmem_ximport_t)(vmem_t *, size_t *, size_t, int);
117 
118 #ifdef _KERNEL
119 extern vmem_t *vmem_init(const char *, void *, size_t, size_t,
120     vmem_alloc_t *, vmem_free_t *);
121 extern void vmem_update(void *);
122 extern int vmem_is_populator();
123 extern size_t vmem_seg_size;
124 #endif
125 
126 extern vmem_t *vmem_create(const char *, void *, size_t, size_t,
127     vmem_alloc_t *, vmem_free_t *, vmem_t *, size_t, int);
128 extern vmem_t *vmem_xcreate(const char *, void *, size_t, size_t,
129     vmem_ximport_t *, vmem_free_t *, vmem_t *, size_t, int);
130 extern void vmem_destroy(vmem_t *);
131 extern void *vmem_alloc(vmem_t *, size_t, int);
132 extern void *vmem_xalloc(vmem_t *, size_t, size_t, size_t, size_t,
133     void *, void *, int);
134 extern void vmem_free(vmem_t *, void *, size_t);
135 extern void vmem_xfree(vmem_t *, void *, size_t);
136 extern void *vmem_add(vmem_t *, void *, size_t, int);
137 extern int vmem_contains(vmem_t *, void *, size_t);
138 extern void vmem_walk(vmem_t *, int, void (*)(void *, void *, size_t), void *);
139 extern size_t vmem_size(vmem_t *, int);
140 
141 #ifdef	__cplusplus
142 }
143 #endif
144 
145 #endif	/* _SYS_VMEM_H */
146