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