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