xref: /titanic_50/usr/src/uts/common/sys/vmem.h (revision 23a80de1aec78d238d06caf311eaceb81dd5a440)
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*23a80de1SStan Studzinski  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
237c478bd9Sstevel@tonic-gate  */
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate #ifndef _SYS_VMEM_H
267c478bd9Sstevel@tonic-gate #define	_SYS_VMEM_H
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <sys/types.h>
297c478bd9Sstevel@tonic-gate 
307c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
317c478bd9Sstevel@tonic-gate extern "C" {
327c478bd9Sstevel@tonic-gate #endif
337c478bd9Sstevel@tonic-gate 
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate /*
367c478bd9Sstevel@tonic-gate  * Per-allocation flags
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate #define	VM_SLEEP	0x00000000	/* same as KM_SLEEP */
397c478bd9Sstevel@tonic-gate #define	VM_NOSLEEP	0x00000001	/* same as KM_NOSLEEP */
407c478bd9Sstevel@tonic-gate #define	VM_PANIC	0x00000002	/* same as KM_PANIC */
417c478bd9Sstevel@tonic-gate #define	VM_PUSHPAGE	0x00000004	/* same as KM_PUSHPAGE */
42*23a80de1SStan Studzinski #define	VM_NORMALPRI	0x00000008	/* same as KM_NORMALPRI */
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 
630616c1c3SMichael Corcoran /*
640616c1c3SMichael Corcoran  * VM_ENDALLOC requests that large addresses be preferred in allocations.
650616c1c3SMichael Corcoran  * Has no effect if VM_NEXTFIT is active.
660616c1c3SMichael Corcoran  */
670616c1c3SMichael Corcoran #define	VM_ENDALLOC	0x00004000
680616c1c3SMichael 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 */
779dd77bc8SDave Plauger #define	VMC_DUMPSAFE	0x00200000	/* can use alternate dump memory */
787c478bd9Sstevel@tonic-gate /*
797c478bd9Sstevel@tonic-gate  * internal use only;	the import function uses the vmem_ximport_t interface
80aaa10e67Sha137994  *			and may increase the request size if it so desires.
81aaa10e67Sha137994  *			VMC_XALIGN, for use with vmem_xcreate, specifies that
82aaa10e67Sha137994  *			the address returned by the import function will be
83aaa10e67Sha137994  *			aligned according to the alignment argument.
847c478bd9Sstevel@tonic-gate  */
857c478bd9Sstevel@tonic-gate #define	VMC_XALLOC	0x00080000
86aaa10e67Sha137994 #define	VMC_XALIGN	0x00100000
877c478bd9Sstevel@tonic-gate #define	VMC_FLAGS	0xFFFF0000
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate /*
907c478bd9Sstevel@tonic-gate  * Public segment types
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate #define	VMEM_ALLOC	0x01
937c478bd9Sstevel@tonic-gate #define	VMEM_FREE	0x02
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate /*
967c478bd9Sstevel@tonic-gate  * Implementation-private segment types
977c478bd9Sstevel@tonic-gate  */
987c478bd9Sstevel@tonic-gate #define	VMEM_SPAN	0x10
997c478bd9Sstevel@tonic-gate #define	VMEM_ROTOR	0x20
1007c478bd9Sstevel@tonic-gate #define	VMEM_WALKER	0x40
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate /*
1037c478bd9Sstevel@tonic-gate  * VMEM_REENTRANT indicates to vmem_walk() that the callback routine may
1047c478bd9Sstevel@tonic-gate  * call back into the arena being walked, so vmem_walk() must drop the
1057c478bd9Sstevel@tonic-gate  * arena lock before each callback.  The caveat is that since the arena
1067c478bd9Sstevel@tonic-gate  * isn't locked, its state can change.  Therefore it is up to the callback
1077c478bd9Sstevel@tonic-gate  * routine to handle cases where the segment isn't of the expected type.
1087c478bd9Sstevel@tonic-gate  * For example, we use this to walk heap_arena when generating a crash dump;
1097c478bd9Sstevel@tonic-gate  * see segkmem_dump() for sample usage.
1107c478bd9Sstevel@tonic-gate  */
1117c478bd9Sstevel@tonic-gate #define	VMEM_REENTRANT	0x80000000
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate typedef struct vmem vmem_t;
1147c478bd9Sstevel@tonic-gate typedef void *(vmem_alloc_t)(vmem_t *, size_t, int);
1157c478bd9Sstevel@tonic-gate typedef void (vmem_free_t)(vmem_t *, void *, size_t);
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate /*
1187c478bd9Sstevel@tonic-gate  * Alternate import style; the requested size is passed in a pointer,
1197c478bd9Sstevel@tonic-gate  * which can be increased by the import function if desired.
1207c478bd9Sstevel@tonic-gate  */
121aaa10e67Sha137994 typedef void *(vmem_ximport_t)(vmem_t *, size_t *, size_t, int);
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate #ifdef _KERNEL
1247c478bd9Sstevel@tonic-gate extern vmem_t *vmem_init(const char *, void *, size_t, size_t,
1257c478bd9Sstevel@tonic-gate     vmem_alloc_t *, vmem_free_t *);
1267c478bd9Sstevel@tonic-gate extern void vmem_update(void *);
1277c478bd9Sstevel@tonic-gate extern int vmem_is_populator();
1287c478bd9Sstevel@tonic-gate extern size_t vmem_seg_size;
1297c478bd9Sstevel@tonic-gate #endif
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate extern vmem_t *vmem_create(const char *, void *, size_t, size_t,
1327c478bd9Sstevel@tonic-gate     vmem_alloc_t *, vmem_free_t *, vmem_t *, size_t, int);
1337c478bd9Sstevel@tonic-gate extern vmem_t *vmem_xcreate(const char *, void *, size_t, size_t,
1347c478bd9Sstevel@tonic-gate     vmem_ximport_t *, vmem_free_t *, vmem_t *, size_t, int);
1357c478bd9Sstevel@tonic-gate extern void vmem_destroy(vmem_t *);
1367c478bd9Sstevel@tonic-gate extern void *vmem_alloc(vmem_t *, size_t, int);
1377c478bd9Sstevel@tonic-gate extern void *vmem_xalloc(vmem_t *, size_t, size_t, size_t, size_t,
1387c478bd9Sstevel@tonic-gate     void *, void *, int);
1397c478bd9Sstevel@tonic-gate extern void vmem_free(vmem_t *, void *, size_t);
1407c478bd9Sstevel@tonic-gate extern void vmem_xfree(vmem_t *, void *, size_t);
1417c478bd9Sstevel@tonic-gate extern void *vmem_add(vmem_t *, void *, size_t, int);
1427c478bd9Sstevel@tonic-gate extern int vmem_contains(vmem_t *, void *, size_t);
1437c478bd9Sstevel@tonic-gate extern void vmem_walk(vmem_t *, int, void (*)(void *, void *, size_t), void *);
1447c478bd9Sstevel@tonic-gate extern size_t vmem_size(vmem_t *, int);
1457c478bd9Sstevel@tonic-gate 
1467c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
1477c478bd9Sstevel@tonic-gate }
1487c478bd9Sstevel@tonic-gate #endif
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate #endif	/* _SYS_VMEM_H */
151