/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* bos72Q src/bos/kernel/pile/pile.h 1.3.1.1                              */
/*                                                                        */
/* Licensed Materials - Property of IBM                                   */
/*                                                                        */
/* Restricted Materials of IBM                                            */
/*                                                                        */
/* COPYRIGHT International Business Machines Corp. 2002,2019              */
/* All Rights Reserved                                                    */
/*                                                                        */
/* US Government Users Restricted Rights - Use, duplication or            */
/* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.      */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */
/* @(#)31     1.3.1.1  src/bos/kernel/pile/pile.h, syslfs, bos72Q, q2019_13A4 2/6/19 00:40:51 */
/*
 * COMPONENT_NAME: (SYSLFS) Logical File System
 *
 * FUNCTIONS: pile_* 
 *
 * Squeezable slab allocator
 */

#ifndef _H_PILE
#define _H_PILE
#ifdef _KERNSYS
#include <sys/pile_internal.h>
#endif /* _KERNSYS */

#include <sys/lock_def.h>
#include <sys/malloc.h>

#ifdef __cplusplus
extern "C" {
#endif

typedef void (*pile_handler_t)( void *cookie, void *obj );
typedef struct pile pile_t;

/* ===== User-visible pile flags =====
 * Note: please see pile_internal.h before adding flags
 */

/* pile_alloc/free flags: */
#define PILE_NOSHRINK		0x00000002
#define PILE_NOGROW		0x00000004

/* 
 * PILE_PINNED -
 *
 * Slab and control info stay pinned (use if allocation at interrupt
 * level must be possible). Note that this means the objects within
 * and the entire range of each slab must stay pinned, otherwise newly
 * allocated objects might fault.
 *
 * If allocation at interrupt level is required, do 
 * not allow the pile to grow. Configure with min==max
 * and reconfigure the pile when you need it to grow. 
 */
#define PILE_PINNED		0x00000001

/* 
 * PILE_SLAB_PINNED -
 *
 * Each slab will be pinned on the first reference to that slab and
 * unpinned when the slab drops to 0 refs. This is a compromise from a
 * fully PILE_PINNED pile for piles with large min_total_pages.
 *
 * Note that this doesn't allowed for allocation at interrupt level at
 * all, but objects are automatically pinned in nice slabs.
 * (allocation can't occur because the slab list might fault)
 */
#define PILE_SLAB_PINNED	0x00000002

/*
 * PILE_ZEROED -
 *
 * Slab is zeroed out before it's split up.
 */
#define PILE_ZEROED		0x00000004

/*
 * PILE_NO_GC -
 *
 * pile is not garbage collected
 */
#define PILE_NO_GC		0x00000080

/* User-visible pile operations */

pile_t 	*pile_init( uint16_t obj_size, uint16_t alignment, uint16_t slab_size,
		heapaddr_t heap, int heap_kkey, uint16_t int_pri,
		uint32_t flags, char *name);
int 	pile_destroy( pile_t *pile );
void   	*pile_alloc( pile_t *pile, uint32_t flags ); 
int   	pile_free(  void *obj, uint32_t flags );
int    	pile_config_reconfig_handler( pile_t *pile,
		pile_handler_t handler, void *cookie, uint32_t flags );
int	pile_config_init_handler( pile_t *pile, pile_handler_t handler,
		void *cookie, uint32_t flags );
int     pile_config_free_handler( pile_t *pile, pile_handler_t handler,
		void *cookie, uint32_t flags );
int     pile_config_max_pages( pile_t *pile, uint64_t max_total_pages,
		uint32_t flags );
int	pile_config_min_pages( pile_t *pile, uint64_t min_total_pages,
		uint32_t flags );
void	pile_wait_gc( void );

#ifdef __cplusplus
}
#endif

#endif /* _H_PILE */