xref: /onnv-gate/usr/src/uts/common/sys/vmem.h (revision 12156:3c537b2a7425)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
54204Sha137994  * Common Development and Distribution License (the "License").
64204Sha137994  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*12156SStan.Studzinski@Sun.COM  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
230Sstevel@tonic-gate  */
240Sstevel@tonic-gate 
250Sstevel@tonic-gate #ifndef _SYS_VMEM_H
260Sstevel@tonic-gate #define	_SYS_VMEM_H
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #ifdef	__cplusplus
310Sstevel@tonic-gate extern "C" {
320Sstevel@tonic-gate #endif
330Sstevel@tonic-gate 
340Sstevel@tonic-gate 
350Sstevel@tonic-gate /*
360Sstevel@tonic-gate  * Per-allocation flags
370Sstevel@tonic-gate  */
380Sstevel@tonic-gate #define	VM_SLEEP	0x00000000	/* same as KM_SLEEP */
390Sstevel@tonic-gate #define	VM_NOSLEEP	0x00000001	/* same as KM_NOSLEEP */
400Sstevel@tonic-gate #define	VM_PANIC	0x00000002	/* same as KM_PANIC */
410Sstevel@tonic-gate #define	VM_PUSHPAGE	0x00000004	/* same as KM_PUSHPAGE */
42*12156SStan.Studzinski@Sun.COM #define	VM_NORMALPRI	0x00000008	/* same as KM_NORMALPRI */
430Sstevel@tonic-gate #define	VM_KMFLAGS	0x000000ff	/* flags that must match KM_* flags */
440Sstevel@tonic-gate 
450Sstevel@tonic-gate #define	VM_BESTFIT	0x00000100
460Sstevel@tonic-gate #define	VM_FIRSTFIT	0x00000200
470Sstevel@tonic-gate #define	VM_NEXTFIT	0x00000400
480Sstevel@tonic-gate 
490Sstevel@tonic-gate /*
500Sstevel@tonic-gate  * The following flags are restricted for use only within the kernel.
510Sstevel@tonic-gate  * VM_MEMLOAD is for use by the HAT to avoid infinite recursion.
520Sstevel@tonic-gate  * VM_NORELOC is used by the kernel when static VA->PA mappings are required.
530Sstevel@tonic-gate  */
540Sstevel@tonic-gate #define	VM_MEMLOAD	0x00000800
550Sstevel@tonic-gate #define	VM_NORELOC	0x00001000
560Sstevel@tonic-gate /*
570Sstevel@tonic-gate  * VM_ABORT requests that vmem_alloc() *ignore* the VM_SLEEP/VM_NOSLEEP flags
580Sstevel@tonic-gate  * and forgo reaping if the allocation or attempted import, fails.  This
590Sstevel@tonic-gate  * flag is a segkmem-specific flag, and should not be used by anyone else.
600Sstevel@tonic-gate  */
610Sstevel@tonic-gate #define	VM_ABORT	0x00002000
620Sstevel@tonic-gate 
638212SMichael.Corcoran@Sun.COM /*
648212SMichael.Corcoran@Sun.COM  * VM_ENDALLOC requests that large addresses be preferred in allocations.
658212SMichael.Corcoran@Sun.COM  * Has no effect if VM_NEXTFIT is active.
668212SMichael.Corcoran@Sun.COM  */
678212SMichael.Corcoran@Sun.COM #define	VM_ENDALLOC	0x00004000
688212SMichael.Corcoran@Sun.COM 
690Sstevel@tonic-gate #define	VM_FLAGS	0x0000FFFF
700Sstevel@tonic-gate 
710Sstevel@tonic-gate /*
720Sstevel@tonic-gate  * Arena creation flags
730Sstevel@tonic-gate  */
740Sstevel@tonic-gate #define	VMC_POPULATOR	0x00010000
750Sstevel@tonic-gate #define	VMC_NO_QCACHE	0x00020000	/* cannot use quantum caches */
760Sstevel@tonic-gate #define	VMC_IDENTIFIER	0x00040000	/* not backed by memory */
7711178SDave.Plauger@Sun.COM #define	VMC_DUMPSAFE	0x00200000	/* can use alternate dump memory */
780Sstevel@tonic-gate /*
790Sstevel@tonic-gate  * internal use only;	the import function uses the vmem_ximport_t interface
804204Sha137994  *			and may increase the request size if it so desires.
814204Sha137994  *			VMC_XALIGN, for use with vmem_xcreate, specifies that
824204Sha137994  *			the address returned by the import function will be
834204Sha137994  *			aligned according to the alignment argument.
840Sstevel@tonic-gate  */
850Sstevel@tonic-gate #define	VMC_XALLOC	0x00080000
864204Sha137994 #define	VMC_XALIGN	0x00100000
870Sstevel@tonic-gate #define	VMC_FLAGS	0xFFFF0000
880Sstevel@tonic-gate 
890Sstevel@tonic-gate /*
900Sstevel@tonic-gate  * Public segment types
910Sstevel@tonic-gate  */
920Sstevel@tonic-gate #define	VMEM_ALLOC	0x01
930Sstevel@tonic-gate #define	VMEM_FREE	0x02
940Sstevel@tonic-gate 
950Sstevel@tonic-gate /*
960Sstevel@tonic-gate  * Implementation-private segment types
970Sstevel@tonic-gate  */
980Sstevel@tonic-gate #define	VMEM_SPAN	0x10
990Sstevel@tonic-gate #define	VMEM_ROTOR	0x20
1000Sstevel@tonic-gate #define	VMEM_WALKER	0x40
1010Sstevel@tonic-gate 
1020Sstevel@tonic-gate /*
1030Sstevel@tonic-gate  * VMEM_REENTRANT indicates to vmem_walk() that the callback routine may
1040Sstevel@tonic-gate  * call back into the arena being walked, so vmem_walk() must drop the
1050Sstevel@tonic-gate  * arena lock before each callback.  The caveat is that since the arena
1060Sstevel@tonic-gate  * isn't locked, its state can change.  Therefore it is up to the callback
1070Sstevel@tonic-gate  * routine to handle cases where the segment isn't of the expected type.
1080Sstevel@tonic-gate  * For example, we use this to walk heap_arena when generating a crash dump;
1090Sstevel@tonic-gate  * see segkmem_dump() for sample usage.
1100Sstevel@tonic-gate  */
1110Sstevel@tonic-gate #define	VMEM_REENTRANT	0x80000000
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate typedef struct vmem vmem_t;
1140Sstevel@tonic-gate typedef void *(vmem_alloc_t)(vmem_t *, size_t, int);
1150Sstevel@tonic-gate typedef void (vmem_free_t)(vmem_t *, void *, size_t);
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate /*
1180Sstevel@tonic-gate  * Alternate import style; the requested size is passed in a pointer,
1190Sstevel@tonic-gate  * which can be increased by the import function if desired.
1200Sstevel@tonic-gate  */
1214204Sha137994 typedef void *(vmem_ximport_t)(vmem_t *, size_t *, size_t, int);
1220Sstevel@tonic-gate 
1230Sstevel@tonic-gate #ifdef _KERNEL
1240Sstevel@tonic-gate extern vmem_t *vmem_init(const char *, void *, size_t, size_t,
1250Sstevel@tonic-gate     vmem_alloc_t *, vmem_free_t *);
1260Sstevel@tonic-gate extern void vmem_update(void *);
1270Sstevel@tonic-gate extern int vmem_is_populator();
1280Sstevel@tonic-gate extern size_t vmem_seg_size;
1290Sstevel@tonic-gate #endif
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate extern vmem_t *vmem_create(const char *, void *, size_t, size_t,
1320Sstevel@tonic-gate     vmem_alloc_t *, vmem_free_t *, vmem_t *, size_t, int);
1330Sstevel@tonic-gate extern vmem_t *vmem_xcreate(const char *, void *, size_t, size_t,
1340Sstevel@tonic-gate     vmem_ximport_t *, vmem_free_t *, vmem_t *, size_t, int);
1350Sstevel@tonic-gate extern void vmem_destroy(vmem_t *);
1360Sstevel@tonic-gate extern void *vmem_alloc(vmem_t *, size_t, int);
1370Sstevel@tonic-gate extern void *vmem_xalloc(vmem_t *, size_t, size_t, size_t, size_t,
1380Sstevel@tonic-gate     void *, void *, int);
1390Sstevel@tonic-gate extern void vmem_free(vmem_t *, void *, size_t);
1400Sstevel@tonic-gate extern void vmem_xfree(vmem_t *, void *, size_t);
1410Sstevel@tonic-gate extern void *vmem_add(vmem_t *, void *, size_t, int);
1420Sstevel@tonic-gate extern int vmem_contains(vmem_t *, void *, size_t);
1430Sstevel@tonic-gate extern void vmem_walk(vmem_t *, int, void (*)(void *, void *, size_t), void *);
1440Sstevel@tonic-gate extern size_t vmem_size(vmem_t *, int);
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate #ifdef	__cplusplus
1470Sstevel@tonic-gate }
1480Sstevel@tonic-gate #endif
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate #endif	/* _SYS_VMEM_H */
151