d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * CDDL HEADER START
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * The contents of this file are subject to the terms of the
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Common Development and Distribution License (the "License").
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * You may not use this file except in compliance with the License.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * See the License for the specific language governing permissions
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * and limitations under the License.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * When distributing Covered Code, include this CDDL HEADER in each
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * If applicable, add the following below this CDDL HEADER, with the
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * fields enclosed by brackets "[]" replaced with your own identifying
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * information: Portions Copyright [yyyy] [name of copyright owner]
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * CDDL HEADER END
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Use is subject to license terms.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayanextern "C" {
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Helper routines for the Logical Domains (LDoms) drivers
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * Note: The contents of this file are private to the implementation of the
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm * LDoms drivers and are subject to change at any time without notice.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * A message is composed of three structures. A message block (mblk_t), a
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * data block to which it points and a data buffer. desballoc(9F) allows
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * the caller to specify the data buffer and a free function which will
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * be invoked when freeb(9F) is called to free the message. This allows
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * the user to reclaim and reuse the data buffer, as opposed to using
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * allocb(9F) where the message block, data block and data buffer are
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * all destroyed by freeb().
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Note that even with desballoc the message and data blocks are destroyed
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * by freeb() and must be recreated. It is only the data buffer which is
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * preserved.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * The caller first creates a pool of vio_mblk_t's by invoking
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * vio_create_mblks() and specifying the number of mblks and the size of the
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * associated data buffers. Each vio_mblk_t contains a pointer to the
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * mblk_t, a pointer to the data buffer and a function pointer to the
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * reclaim function. The caller is returned a pointer to the pool which is
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * used in subsequent allocation/destroy requests.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * The pool is managed as a circular queue with a head and tail pointer.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * Allocation requests result in the head index being incremented, mblks
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * being returned to the pool result in the tail pointer being incremented.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * The pool can only be destroyed when all the mblks have been returned. It
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * is the responsibility of the caller to ensure that all vio_allocb()
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * requests have been completed before the pool is destroyed.
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * vio_mblk_pool_t
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * +-------------+
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * | tail |--------------------------------+
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * +-------------+ |
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * | head |--------+ |
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * +-------------+ | |
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * ............... V V
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * +-------------+ +-------+-------+-------+-------+
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * | quep |---->| vmp_t | vmp_t | vmp_t | vmp_t |
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * +-------------+ +-------+-------+-------+-------+
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * | | | | | |
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * ... | | | | +------------+
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * | | | +-->| data block |
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * | | | +------------+
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * | | | +------------+
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * | | +-->| data block |
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * | | +------------+
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * | | +------------+
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * | +-->| data block |
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * | +------------+
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * | +------------+
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * +-->| data block |
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan * +------------+
3af08d828975d7e2581b6829e0eecff14d87a483lm/* mblk pool flags */
3af08d828975d7e2581b6829e0eecff14d87a483lm#define VMPL_FLAG_DESTROYING 0x1 /* pool is being destroyed */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna#define VMPL_FLAG_CLIENT_DATA 0x2 /* pool data area provided by client */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna/* VIO mblk states */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna VIO_MBLK_FREE = 0x1, /* free to use */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna VIO_MBLK_BOUND = 0x2, /* allocated/bound to a descriptor */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna VIO_MBLK_HAS_DATA = 0x4 /* contains valid data */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan struct vio_mblk_pool *vmplp; /* pointer to parent pool */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna vio_mblk_state_t state; /* state flags */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan vio_mblk_t *basep; /* base pointer to pool of vio_mblks */
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna#define VIO_MBLK_DATA_OFF(vmp) ((vmp)->datap - ((vmp)->vmplp)->datap)
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatna size_t mblk_size, uint8_t *mblk_datap,
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatnavio_mblk_t *vio_allocb(vio_mblk_pool_t *);
844e62a3ec8c8ff5175bb35d1c38446e060730f6raghuramint vio_init_multipools(vio_multi_pool_t *vmultip, int num_pools, ...);
844e62a3ec8c8ff5175bb35d1c38446e060730f6raghuramvoid vio_destroy_multipools(vio_multi_pool_t *vmultip, vio_mblk_pool_t **fvmp);
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatnavio_mblk_t *vio_multipool_allocb(vio_multi_pool_t *vmultip, size_t size);
6f09f0fef8e4582cfa771d87fe2a1f777bfb5cf0WENTAO YANGint vio_check_pending_pools(vio_multi_pool_t *vmultip);
7bd3a2e26cc8569257b88c1691d559138e1d32d0Sriharsha Basavapatnavoid vio_clobber_pool(vio_mblk_pool_t *vmplp);
17cadca83cc82e37ff517ea2783eb4bfcc07b950lm/* VIO versioning helpers */
17cadca83cc82e37ff517ea2783eb4bfcc07b950lmboolean_t vio_ver_is_supported(vio_ver_t ver, uint16_t maj, uint16_t min);
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan#endif /* _VIO_UTIL_H */