xref: /titanic_50/usr/src/uts/common/sys/vmem.h (revision 0616c1c344750b61fbfd80b1185254b28a9fe60d)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5aaa10e67Sha137994  * Common Development and Distribution License (the "License").
6aaa10e67Sha137994  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*0616c1c3SMichael Corcoran  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #ifndef _SYS_VMEM_H
277c478bd9Sstevel@tonic-gate #define	_SYS_VMEM_H
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #include <sys/types.h>
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
327c478bd9Sstevel@tonic-gate extern "C" {
337c478bd9Sstevel@tonic-gate #endif
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate /*
377c478bd9Sstevel@tonic-gate  * Per-allocation flags
387c478bd9Sstevel@tonic-gate  */
397c478bd9Sstevel@tonic-gate #define	VM_SLEEP	0x00000000	/* same as KM_SLEEP */
407c478bd9Sstevel@tonic-gate #define	VM_NOSLEEP	0x00000001	/* same as KM_NOSLEEP */
417c478bd9Sstevel@tonic-gate #define	VM_PANIC	0x00000002	/* same as KM_PANIC */
427c478bd9Sstevel@tonic-gate #define	VM_PUSHPAGE	0x00000004	/* same as KM_PUSHPAGE */
437c478bd9Sstevel@tonic-gate #define	VM_KMFLAGS	0x000000ff	/* flags that must match KM_* flags */
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate #define	VM_BESTFIT	0x00000100
467c478bd9Sstevel@tonic-gate #define	VM_FIRSTFIT	0x00000200
477c478bd9Sstevel@tonic-gate #define	VM_NEXTFIT	0x00000400
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate /*
507c478bd9Sstevel@tonic-gate  * The following flags are restricted for use only within the kernel.
517c478bd9Sstevel@tonic-gate  * VM_MEMLOAD is for use by the HAT to avoid infinite recursion.
527c478bd9Sstevel@tonic-gate  * VM_NORELOC is used by the kernel when static VA->PA mappings are required.
537c478bd9Sstevel@tonic-gate  */
547c478bd9Sstevel@tonic-gate #define	VM_MEMLOAD	0x00000800
557c478bd9Sstevel@tonic-gate #define	VM_NORELOC	0x00001000
567c478bd9Sstevel@tonic-gate /*
577c478bd9Sstevel@tonic-gate  * VM_ABORT requests that vmem_alloc() *ignore* the VM_SLEEP/VM_NOSLEEP flags
587c478bd9Sstevel@tonic-gate  * and forgo reaping if the allocation or attempted import, fails.  This
597c478bd9Sstevel@tonic-gate  * flag is a segkmem-specific flag, and should not be used by anyone else.
607c478bd9Sstevel@tonic-gate  */
617c478bd9Sstevel@tonic-gate #define	VM_ABORT	0x00002000
627c478bd9Sstevel@tonic-gate 
63*0616c1c3SMichael Corcoran /*
64*0616c1c3SMichael Corcoran  * VM_ENDALLOC requests that large addresses be preferred in allocations.
65*0616c1c3SMichael Corcoran  * Has no effect if VM_NEXTFIT is active.
66*0616c1c3SMichael Corcoran  */
67*0616c1c3SMichael Corcoran #define	VM_ENDALLOC	0x00004000
68*0616c1c3SMichael Corcoran 
697c478bd9Sstevel@tonic-gate #define	VM_FLAGS	0x0000FFFF
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * Arena creation flags
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate #define	VMC_POPULATOR	0x00010000
757c478bd9Sstevel@tonic-gate #define	VMC_NO_QCACHE	0x00020000	/* cannot use quantum caches */
767c478bd9Sstevel@tonic-gate #define	VMC_IDENTIFIER	0x00040000	/* not backed by memory */
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * internal use only;	the import function uses the vmem_ximport_t interface
79aaa10e67Sha137994  *			and may increase the request size if it so desires.
80aaa10e67Sha137994  *			VMC_XALIGN, for use with vmem_xcreate, specifies that
81aaa10e67Sha137994  *			the address returned by the import function will be
82aaa10e67Sha137994  *			aligned according to the alignment argument.
837c478bd9Sstevel@tonic-gate  */
847c478bd9Sstevel@tonic-gate #define	VMC_XALLOC	0x00080000
85aaa10e67Sha137994 #define	VMC_XALIGN	0x00100000
867c478bd9Sstevel@tonic-gate #define	VMC_FLAGS	0xFFFF0000
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * Public segment types
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate #define	VMEM_ALLOC	0x01
927c478bd9Sstevel@tonic-gate #define	VMEM_FREE	0x02
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * Implementation-private segment types
967c478bd9Sstevel@tonic-gate  */
977c478bd9Sstevel@tonic-gate #define	VMEM_SPAN	0x10
987c478bd9Sstevel@tonic-gate #define	VMEM_ROTOR	0x20
997c478bd9Sstevel@tonic-gate #define	VMEM_WALKER	0x40
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  * VMEM_REENTRANT indicates to vmem_walk() that the callback routine may
1037c478bd9Sstevel@tonic-gate  * call back into the arena being walked, so vmem_walk() must drop the
1047c478bd9Sstevel@tonic-gate  * arena lock before each callback.  The caveat is that since the arena
1057c478bd9Sstevel@tonic-gate  * isn't locked, its state can change.  Therefore it is up to the callback
1067c478bd9Sstevel@tonic-gate  * routine to handle cases where the segment isn't of the expected type.
1077c478bd9Sstevel@tonic-gate  * For example, we use this to walk heap_arena when generating a crash dump;
1087c478bd9Sstevel@tonic-gate  * see segkmem_dump() for sample usage.
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate #define	VMEM_REENTRANT	0x80000000
1117c478bd9Sstevel@tonic-gate 
1127c478bd9Sstevel@tonic-gate typedef struct vmem vmem_t;
1137c478bd9Sstevel@tonic-gate typedef void *(vmem_alloc_t)(vmem_t *, size_t, int);
1147c478bd9Sstevel@tonic-gate typedef void (vmem_free_t)(vmem_t *, void *, size_t);
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * Alternate import style; the requested size is passed in a pointer,
1187c478bd9Sstevel@tonic-gate  * which can be increased by the import function if desired.
1197c478bd9Sstevel@tonic-gate  */
120aaa10e67Sha137994 typedef void *(vmem_ximport_t)(vmem_t *, size_t *, size_t, int);
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1237c478bd9Sstevel@tonic-gate extern vmem_t *vmem_init(const char *, void *, size_t, size_t,
1247c478bd9Sstevel@tonic-gate     vmem_alloc_t *, vmem_free_t *);
1257c478bd9Sstevel@tonic-gate extern void vmem_update(void *);
1267c478bd9Sstevel@tonic-gate extern int vmem_is_populator();
1277c478bd9Sstevel@tonic-gate extern size_t vmem_seg_size;
1287c478bd9Sstevel@tonic-gate #endif
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate extern vmem_t *vmem_create(const char *, void *, size_t, size_t,
1317c478bd9Sstevel@tonic-gate     vmem_alloc_t *, vmem_free_t *, vmem_t *, size_t, int);
1327c478bd9Sstevel@tonic-gate extern vmem_t *vmem_xcreate(const char *, void *, size_t, size_t,
1337c478bd9Sstevel@tonic-gate     vmem_ximport_t *, vmem_free_t *, vmem_t *, size_t, int);
1347c478bd9Sstevel@tonic-gate extern void vmem_destroy(vmem_t *);
1357c478bd9Sstevel@tonic-gate extern void *vmem_alloc(vmem_t *, size_t, int);
1367c478bd9Sstevel@tonic-gate extern void *vmem_xalloc(vmem_t *, size_t, size_t, size_t, size_t,
1377c478bd9Sstevel@tonic-gate     void *, void *, int);
1387c478bd9Sstevel@tonic-gate extern void vmem_free(vmem_t *, void *, size_t);
1397c478bd9Sstevel@tonic-gate extern void vmem_xfree(vmem_t *, void *, size_t);
1407c478bd9Sstevel@tonic-gate extern void *vmem_add(vmem_t *, void *, size_t, int);
1417c478bd9Sstevel@tonic-gate extern int vmem_contains(vmem_t *, void *, size_t);
1427c478bd9Sstevel@tonic-gate extern void vmem_walk(vmem_t *, int, void (*)(void *, void *, size_t), void *);
1437c478bd9Sstevel@tonic-gate extern size_t vmem_size(vmem_t *, int);
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1467c478bd9Sstevel@tonic-gate }
1477c478bd9Sstevel@tonic-gate #endif
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate #endif	/* _SYS_VMEM_H */
150