4 * @Abstract: Buf pool implementation: Dynamic version
9 * Copyright (c) 2007 Atheros Communications Inc.
10 * All rights reserved.
13 #include <adf_os_mem.h>
14 #include <adf_os_module.h>
16 #include <Magpie_api.h>
17 //#include <os/cmnos_api.h>
18 #include <buf_pool_api.h>
20 LOCAL htc_handle_t _buf_pool_dynamic_init(adf_os_handle_t handle);
21 LOCAL void _buf_pool_dynamic_create_pool(pool_handle_t handle, BUF_POOL_ID poolId, int nItems, int nSize);
22 LOCAL adf_nbuf_t _buf_pool_dynamic_alloc_buf(pool_handle_t handle, BUF_POOL_ID poolId, int reserve);
23 LOCAL adf_nbuf_t _buf_pool_dynamic_alloc_buf_align(pool_handle_t handle, BUF_POOL_ID poolId, int reserve, int align);
24 LOCAL void _buf_pool_dynamic_free_buf(pool_handle_t handle, BUF_POOL_ID poolId, adf_nbuf_t buf);
25 LOCAL void _buf_pool_dynamic_shutdown(pool_handle_t handle);
27 typedef struct _POOL_CONFIG {
31 typedef struct _BUF_POOL_DYNAMIC_CONTEXT {
32 adf_os_handle_t OSHandle;
33 POOL_CONFIG poolConf[POOL_ID_MAX];
34 } BUF_POOL_DYNAMIC_CONTEXT;
36 void buf_pool_module_install(struct buf_pool_api *pAPIs)
38 pAPIs->_init = _buf_pool_dynamic_init;
39 pAPIs->_create_pool = _buf_pool_dynamic_create_pool;
40 pAPIs->_alloc_buf = _buf_pool_dynamic_alloc_buf;
41 pAPIs->_alloc_buf_align = _buf_pool_dynamic_alloc_buf_align;
42 pAPIs->_free_buf = _buf_pool_dynamic_free_buf;
43 pAPIs->_shutdown = _buf_pool_dynamic_shutdown;
46 LOCAL pool_handle_t _buf_pool_dynamic_init(adf_os_handle_t handle)
48 BUF_POOL_DYNAMIC_CONTEXT *ctx;
50 ctx = (BUF_POOL_DYNAMIC_CONTEXT *)adf_os_mem_alloc(sizeof(BUF_POOL_DYNAMIC_CONTEXT));
51 ctx->OSHandle = handle;
56 LOCAL void _buf_pool_dynamic_shutdown(pool_handle_t handle)
58 BUF_POOL_DYNAMIC_CONTEXT *ctx = (BUF_POOL_DYNAMIC_CONTEXT *)handle;
63 LOCAL void _buf_pool_dynamic_create_pool(pool_handle_t handle, BUF_POOL_ID poolId, int nItems, int nSize)
65 BUF_POOL_DYNAMIC_CONTEXT *ctx = (BUF_POOL_DYNAMIC_CONTEXT *)handle;
67 ctx->poolConf[poolId].nSize = nSize;
70 LOCAL adf_nbuf_t _buf_pool_dynamic_alloc_buf(pool_handle_t handle, BUF_POOL_ID poolId, int reserve)
72 BUF_POOL_DYNAMIC_CONTEXT *ctx = (BUF_POOL_DYNAMIC_CONTEXT *)handle;
73 POOL_CONFIG *poolConf = &ctx->poolConf[poolId];
75 return adf_nbuf_alloc(poolConf->nSize,
80 LOCAL adf_nbuf_t _buf_pool_dynamic_alloc_buf_align(pool_handle_t handle, BUF_POOL_ID poolId, int reserve, int align)
82 BUF_POOL_DYNAMIC_CONTEXT *ctx = (BUF_POOL_DYNAMIC_CONTEXT *)handle;
83 POOL_CONFIG *poolConf = &ctx->poolConf[poolId];
85 return adf_nbuf_alloc(poolConf->nSize,
90 LOCAL void _buf_pool_dynamic_free_buf(pool_handle_t handle, BUF_POOL_ID poolId, adf_nbuf_t buf)
92 //BUF_POOL_DYNAMIC_CONTEXT *ctx = (BUF_POOL_DYNAMIC_CONTEXT *)handle;
97 adf_os_export_symbol(buf_pool_module_install);