Initial cut of the open ath9k htc firmware.
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / target / buf_pool / buf_pool_dynamic.c
1 /*
2  * @File: 
3  * 
4  * @Abstract: Buf pool implementation: Dynamic version
5  * 
6  * @Notes: 
7  * 
8  * 
9  * Copyright (c) 2007 Atheros Communications Inc.
10  * All rights reserved.
11  *
12  */
13 #include <adf_os_mem.h>
14 #include <adf_os_module.h>
15 #include <osapi.h>
16 #include <Magpie_api.h> 
17 //#include <os/cmnos_api.h>
18 #include <buf_pool_api.h>
19  
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);
26        
27 typedef struct _POOL_CONFIG {
28     int nSize;
29 } POOL_CONFIG;
30        
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;
35
36 void buf_pool_module_install(struct buf_pool_api *pAPIs)
37 {   
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;
44 }
45  
46 LOCAL pool_handle_t _buf_pool_dynamic_init(adf_os_handle_t handle)
47 {
48     BUF_POOL_DYNAMIC_CONTEXT *ctx;
49     
50     ctx = (BUF_POOL_DYNAMIC_CONTEXT *)adf_os_mem_alloc(sizeof(BUF_POOL_DYNAMIC_CONTEXT));
51     ctx->OSHandle = handle;
52     
53     return ctx; 
54 }      
55     
56 LOCAL void _buf_pool_dynamic_shutdown(pool_handle_t handle) 
57 {
58     BUF_POOL_DYNAMIC_CONTEXT *ctx = (BUF_POOL_DYNAMIC_CONTEXT *)handle;
59     
60     adf_os_mem_free(ctx);
61 }
62
63 LOCAL void _buf_pool_dynamic_create_pool(pool_handle_t handle, BUF_POOL_ID poolId, int nItems, int nSize)
64 {
65     BUF_POOL_DYNAMIC_CONTEXT *ctx = (BUF_POOL_DYNAMIC_CONTEXT *)handle;
66     
67     ctx->poolConf[poolId].nSize = nSize;
68 }
69             
70 LOCAL adf_nbuf_t  _buf_pool_dynamic_alloc_buf(pool_handle_t handle, BUF_POOL_ID poolId, int reserve)
71 {
72     BUF_POOL_DYNAMIC_CONTEXT *ctx = (BUF_POOL_DYNAMIC_CONTEXT *)handle;
73     POOL_CONFIG *poolConf = &ctx->poolConf[poolId];
74             
75     return adf_nbuf_alloc(poolConf->nSize, 
76                           reserve, 0);
77
78 }
79     
80 LOCAL adf_nbuf_t  _buf_pool_dynamic_alloc_buf_align(pool_handle_t handle, BUF_POOL_ID poolId, int reserve, int align)
81 {
82     BUF_POOL_DYNAMIC_CONTEXT *ctx = (BUF_POOL_DYNAMIC_CONTEXT *)handle;
83     POOL_CONFIG *poolConf = &ctx->poolConf[poolId];
84
85     return adf_nbuf_alloc(poolConf->nSize, 
86                           reserve, align);
87
88 }
89
90 LOCAL void _buf_pool_dynamic_free_buf(pool_handle_t handle, BUF_POOL_ID poolId, adf_nbuf_t buf)
91 {
92     //BUF_POOL_DYNAMIC_CONTEXT *ctx = (BUF_POOL_DYNAMIC_CONTEXT *)handle;
93         
94     adf_nbuf_free(buf);
95 }
96
97 adf_os_export_symbol(buf_pool_module_install);