2 * Copyright(c) 2002-2011 Exar Corp.
5 * Redistribution and use in source and binary forms, with or without
6 * modification are permitted provided the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Exar Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
38 typedef void *vxge_hal_mempool_h;
41 * struct vxge_hal_mempool_dma_t - Represents DMA objects passed to the
44 typedef struct vxge_hal_mempool_dma_t {
47 pci_dma_acc_h acc_handle;
48 } vxge_hal_mempool_dma_t;
51 * vxge_hal_mempool_item_f - Mempool item alloc/free callback
52 * @mempoolh: Memory pool handle.
53 * @memblock: Address of memory block
54 * @memblock_index: Index of memory block
55 * @item: Item that gets allocated or freed.
56 * @index: Item's index in the memory pool.
57 * @is_last: True, if this item is the last one in the pool; false - otherwise.
58 * userdata: Per-pool user context.
60 * Memory pool allocation/deallocation callback.
62 typedef vxge_hal_status_e (*vxge_hal_mempool_item_f) (
63 vxge_hal_mempool_h mempoolh,
66 vxge_hal_mempool_dma_t *dma_object,
73 * struct vxge_hal_mempool_t - Memory pool.
75 typedef struct vxge_hal_mempool_t {
76 vxge_hal_mempool_item_f item_func_alloc;
77 vxge_hal_mempool_item_f item_func_free;
80 void **memblocks_priv_arr;
81 vxge_hal_mempool_dma_t *memblocks_dma_arr;
82 vxge_hal_device_h devh;
85 u32 memblocks_allocated;
90 u32 items_per_memblock;
93 void **shadow_items_arr;
98 * __hal_mempool_item_count - Returns number of items in the mempool
102 __hal_mempool_item_count(
103 vxge_hal_mempool_t *mempool)
105 return (mempool->items_current);
109 * __hal_mempool_item - Returns pointer to the item in the mempool
115 vxge_hal_mempool_t *mempool,
118 return (mempool->items_arr[items_index]);
122 * __hal_mempool_item_priv - will return pointer on per item private space
126 __hal_mempool_item_priv(
127 vxge_hal_mempool_t *mempool,
130 u32 *memblock_item_idx)
133 void *memblock = mempool->memblocks_arr[memblock_idx];
135 vxge_assert(memblock);
138 offset = (u32) ((u8 *) item - (u8 *) memblock);
139 vxge_assert(offset >= 0 && (u32) offset < mempool->memblock_size);
141 (*memblock_item_idx) = (u32) offset / mempool->item_size;
142 vxge_assert((*memblock_item_idx) < mempool->items_per_memblock);
144 return ((u8 *) mempool->memblocks_priv_arr[memblock_idx] +
145 (*memblock_item_idx) * mempool->items_priv_size);
149 * __hal_mempool_items_arr - will return pointer to the items array in the
154 __hal_mempool_items_arr(
155 vxge_hal_mempool_t *mempool)
157 return (mempool->items_arr);
161 * __hal_mempool_memblock - will return pointer to the memblock in the
162 * mempool memblocks array.
166 __hal_mempool_memblock(
167 vxge_hal_mempool_t *mempool,
170 vxge_assert(mempool->memblocks_arr[memblock_idx]);
171 return (mempool->memblocks_arr[memblock_idx]);
175 * __hal_mempool_memblock_dma - will return pointer to the dma block
176 * corresponds to the memblock(identified by memblock_idx) in the mempool.
178 static inline vxge_hal_mempool_dma_t *
180 __hal_mempool_memblock_dma(
181 vxge_hal_mempool_t *mempool,
184 return (mempool->memblocks_dma_arr + memblock_idx);
188 vxge_hal_mempool_create(
189 vxge_hal_device_h devh,
195 vxge_hal_mempool_item_f item_func_alloc,
196 vxge_hal_mempool_item_f item_func_free,
200 vxge_hal_mempool_destroy(
201 vxge_hal_mempool_t *mempool);
206 #endif /* VXGE_HAL_MM_H */