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 5*aaa10e67Sha137994 * Common Development and Distribution License (the "License"). 6*aaa10e67Sha137994 * 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*aaa10e67Sha137994 * Copyright 2007 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 #pragma ident "%Z%%M% %I% %E% SMI" 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #include <sys/types.h> 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #ifdef __cplusplus 347c478bd9Sstevel@tonic-gate extern "C" { 357c478bd9Sstevel@tonic-gate #endif 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* 397c478bd9Sstevel@tonic-gate * Per-allocation flags 407c478bd9Sstevel@tonic-gate */ 417c478bd9Sstevel@tonic-gate #define VM_SLEEP 0x00000000 /* same as KM_SLEEP */ 427c478bd9Sstevel@tonic-gate #define VM_NOSLEEP 0x00000001 /* same as KM_NOSLEEP */ 437c478bd9Sstevel@tonic-gate #define VM_PANIC 0x00000002 /* same as KM_PANIC */ 447c478bd9Sstevel@tonic-gate #define VM_PUSHPAGE 0x00000004 /* same as KM_PUSHPAGE */ 457c478bd9Sstevel@tonic-gate #define VM_KMFLAGS 0x000000ff /* flags that must match KM_* flags */ 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #define VM_BESTFIT 0x00000100 487c478bd9Sstevel@tonic-gate #define VM_FIRSTFIT 0x00000200 497c478bd9Sstevel@tonic-gate #define VM_NEXTFIT 0x00000400 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate /* 527c478bd9Sstevel@tonic-gate * The following flags are restricted for use only within the kernel. 537c478bd9Sstevel@tonic-gate * VM_MEMLOAD is for use by the HAT to avoid infinite recursion. 547c478bd9Sstevel@tonic-gate * VM_NORELOC is used by the kernel when static VA->PA mappings are required. 557c478bd9Sstevel@tonic-gate */ 567c478bd9Sstevel@tonic-gate #define VM_MEMLOAD 0x00000800 577c478bd9Sstevel@tonic-gate #define VM_NORELOC 0x00001000 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * VM_ABORT requests that vmem_alloc() *ignore* the VM_SLEEP/VM_NOSLEEP flags 607c478bd9Sstevel@tonic-gate * and forgo reaping if the allocation or attempted import, fails. This 617c478bd9Sstevel@tonic-gate * flag is a segkmem-specific flag, and should not be used by anyone else. 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate #define VM_ABORT 0x00002000 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate #define VM_FLAGS 0x0000FFFF 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * Arena creation flags 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate #define VMC_POPULATOR 0x00010000 717c478bd9Sstevel@tonic-gate #define VMC_NO_QCACHE 0x00020000 /* cannot use quantum caches */ 727c478bd9Sstevel@tonic-gate #define VMC_IDENTIFIER 0x00040000 /* not backed by memory */ 737c478bd9Sstevel@tonic-gate /* 747c478bd9Sstevel@tonic-gate * internal use only; the import function uses the vmem_ximport_t interface 75*aaa10e67Sha137994 * and may increase the request size if it so desires. 76*aaa10e67Sha137994 * VMC_XALIGN, for use with vmem_xcreate, specifies that 77*aaa10e67Sha137994 * the address returned by the import function will be 78*aaa10e67Sha137994 * aligned according to the alignment argument. 797c478bd9Sstevel@tonic-gate */ 807c478bd9Sstevel@tonic-gate #define VMC_XALLOC 0x00080000 81*aaa10e67Sha137994 #define VMC_XALIGN 0x00100000 827c478bd9Sstevel@tonic-gate #define VMC_FLAGS 0xFFFF0000 837c478bd9Sstevel@tonic-gate 847c478bd9Sstevel@tonic-gate /* 857c478bd9Sstevel@tonic-gate * Public segment types 867c478bd9Sstevel@tonic-gate */ 877c478bd9Sstevel@tonic-gate #define VMEM_ALLOC 0x01 887c478bd9Sstevel@tonic-gate #define VMEM_FREE 0x02 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate /* 917c478bd9Sstevel@tonic-gate * Implementation-private segment types 927c478bd9Sstevel@tonic-gate */ 937c478bd9Sstevel@tonic-gate #define VMEM_SPAN 0x10 947c478bd9Sstevel@tonic-gate #define VMEM_ROTOR 0x20 957c478bd9Sstevel@tonic-gate #define VMEM_WALKER 0x40 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate /* 987c478bd9Sstevel@tonic-gate * VMEM_REENTRANT indicates to vmem_walk() that the callback routine may 997c478bd9Sstevel@tonic-gate * call back into the arena being walked, so vmem_walk() must drop the 1007c478bd9Sstevel@tonic-gate * arena lock before each callback. The caveat is that since the arena 1017c478bd9Sstevel@tonic-gate * isn't locked, its state can change. Therefore it is up to the callback 1027c478bd9Sstevel@tonic-gate * routine to handle cases where the segment isn't of the expected type. 1037c478bd9Sstevel@tonic-gate * For example, we use this to walk heap_arena when generating a crash dump; 1047c478bd9Sstevel@tonic-gate * see segkmem_dump() for sample usage. 1057c478bd9Sstevel@tonic-gate */ 1067c478bd9Sstevel@tonic-gate #define VMEM_REENTRANT 0x80000000 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate typedef struct vmem vmem_t; 1097c478bd9Sstevel@tonic-gate typedef void *(vmem_alloc_t)(vmem_t *, size_t, int); 1107c478bd9Sstevel@tonic-gate typedef void (vmem_free_t)(vmem_t *, void *, size_t); 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate /* 1137c478bd9Sstevel@tonic-gate * Alternate import style; the requested size is passed in a pointer, 1147c478bd9Sstevel@tonic-gate * which can be increased by the import function if desired. 1157c478bd9Sstevel@tonic-gate */ 116*aaa10e67Sha137994 typedef void *(vmem_ximport_t)(vmem_t *, size_t *, size_t, int); 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate #ifdef _KERNEL 1197c478bd9Sstevel@tonic-gate extern vmem_t *vmem_init(const char *, void *, size_t, size_t, 1207c478bd9Sstevel@tonic-gate vmem_alloc_t *, vmem_free_t *); 1217c478bd9Sstevel@tonic-gate extern void vmem_update(void *); 1227c478bd9Sstevel@tonic-gate extern int vmem_is_populator(); 1237c478bd9Sstevel@tonic-gate extern size_t vmem_seg_size; 1247c478bd9Sstevel@tonic-gate #endif 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate extern vmem_t *vmem_create(const char *, void *, size_t, size_t, 1277c478bd9Sstevel@tonic-gate vmem_alloc_t *, vmem_free_t *, vmem_t *, size_t, int); 1287c478bd9Sstevel@tonic-gate extern vmem_t *vmem_xcreate(const char *, void *, size_t, size_t, 1297c478bd9Sstevel@tonic-gate vmem_ximport_t *, vmem_free_t *, vmem_t *, size_t, int); 1307c478bd9Sstevel@tonic-gate extern void vmem_destroy(vmem_t *); 1317c478bd9Sstevel@tonic-gate extern void *vmem_alloc(vmem_t *, size_t, int); 1327c478bd9Sstevel@tonic-gate extern void *vmem_xalloc(vmem_t *, size_t, size_t, size_t, size_t, 1337c478bd9Sstevel@tonic-gate void *, void *, int); 1347c478bd9Sstevel@tonic-gate extern void vmem_free(vmem_t *, void *, size_t); 1357c478bd9Sstevel@tonic-gate extern void vmem_xfree(vmem_t *, void *, size_t); 1367c478bd9Sstevel@tonic-gate extern void *vmem_add(vmem_t *, void *, size_t, int); 1377c478bd9Sstevel@tonic-gate extern int vmem_contains(vmem_t *, void *, size_t); 1387c478bd9Sstevel@tonic-gate extern void vmem_walk(vmem_t *, int, void (*)(void *, void *, size_t), void *); 1397c478bd9Sstevel@tonic-gate extern size_t vmem_size(vmem_t *, int); 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate #ifdef __cplusplus 1427c478bd9Sstevel@tonic-gate } 1437c478bd9Sstevel@tonic-gate #endif 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate #endif /* _SYS_VMEM_H */ 146