2 * Copyright (c) 2002-2007 Neterion, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 #include <dev/nxge/include/xge-os-pal.h>
33 #include <dev/nxge/include/xge-debug.h>
34 #include <dev/nxge/include/xgehal-types.h>
35 #include <dev/nxge/include/xgehal-driver.h>
39 typedef void* xge_hal_mempool_h;
42 * struct xge_hal_mempool_dma_t - Represents DMA objects passed to the
45 typedef struct xge_hal_mempool_dma_t {
48 pci_dma_acc_h acc_handle;
49 } xge_hal_mempool_dma_t;
52 * xge_hal_mempool_item_f - Mempool item alloc/free callback
53 * @mempoolh: Memory pool handle.
54 * @item: Item that gets allocated or freed.
55 * @index: Item's index in the memory pool.
56 * @is_last: True, if this item is the last one in the pool; false - otherwise.
57 * userdat: Per-pool user context.
59 * Memory pool allocation/deallocation callback.
61 typedef xge_hal_status_e (*xge_hal_mempool_item_f) (xge_hal_mempool_h mempoolh,
62 void *memblock, int memblock_index,
63 xge_hal_mempool_dma_t *dma_object, void *item,
64 int index, int is_last, void *userdata);
67 * struct xge_hal_mempool_t - Memory pool.
69 typedef struct xge_hal_mempool_t {
70 xge_hal_mempool_item_f item_func_alloc;
71 xge_hal_mempool_item_f item_func_free;
74 void **memblocks_priv_arr;
75 xge_hal_mempool_dma_t *memblocks_dma_arr;
79 int memblocks_allocated;
84 int items_per_memblock;
86 void **shadow_items_arr;
91 * __hal_mempool_item - Returns pointer to the item in the mempool
95 __hal_mempool_item(xge_hal_mempool_t *mempool, int index)
97 return mempool->items_arr[index];
101 * __hal_mempool_item_priv - will return pointer on per item private space
104 __hal_mempool_item_priv(xge_hal_mempool_t *mempool, int memblock_idx,
105 void *item, int *memblock_item_idx)
108 void *memblock = mempool->memblocks_arr[memblock_idx];
110 xge_assert(memblock);
112 offset = (int)((char * )item - (char *)memblock);
113 xge_assert(offset >= 0 && offset < mempool->memblock_size);
115 (*memblock_item_idx) = (int) offset / mempool->item_size;
116 xge_assert((*memblock_item_idx) < mempool->items_per_memblock);
118 return (char*)mempool->memblocks_priv_arr[memblock_idx] +
119 (*memblock_item_idx) * mempool->items_priv_size;
123 * __hal_mempool_items_arr - will return pointer to the items array in the
127 __hal_mempool_items_arr(xge_hal_mempool_t *mempool)
129 return mempool->items_arr;
133 * __hal_mempool_memblock - will return pointer to the memblock in the
134 * mempool memblocks array.
137 __hal_mempool_memblock(xge_hal_mempool_t *mempool, int memblock_idx)
139 xge_assert(mempool->memblocks_arr[memblock_idx]);
140 return mempool->memblocks_arr[memblock_idx];
144 * __hal_mempool_memblock_dma - will return pointer to the dma block
145 * corresponds to the memblock(identified by memblock_idx) in the mempool.
147 static inline xge_hal_mempool_dma_t*
148 __hal_mempool_memblock_dma(xge_hal_mempool_t *mempool, int memblock_idx)
150 return mempool->memblocks_dma_arr + memblock_idx;
153 xge_hal_status_e __hal_mempool_grow(xge_hal_mempool_t *mempool,
154 int num_allocate, int *num_allocated);
156 xge_hal_mempool_t* __hal_mempool_create(pci_dev_h pdev, int memblock_size,
157 int item_size, int private_size, int items_initial,
158 int items_max, xge_hal_mempool_item_f item_func_alloc,
159 xge_hal_mempool_item_f item_func_free, void *userdata);
161 void __hal_mempool_destroy(xge_hal_mempool_t *mempool);
166 #endif /* XGE_HAL_MM_H */