Lines Matching refs:pool
87 int gsi_trans_pool_init(struct gsi_trans_pool *pool, size_t size, u32 count,
100 /* By allocating a few extra entries in our pool (one less
103 * ever worrying about straddling the end of the pool array.
105 * we just allocate free entries from the beginning of the pool.
113 pool->base = virt;
115 pool->count = alloc_size / size;
116 pool->free = 0;
117 pool->max_alloc = max_alloc;
118 pool->size = size;
119 pool->addr = 0; /* Only used for DMA pools */
124 void gsi_trans_pool_exit(struct gsi_trans_pool *pool)
126 kfree(pool->base);
127 memset(pool, 0, sizeof(*pool));
130 /* Home-grown DMA pool. This way we can preallocate the pool, and guarantee
132 * require up to max_alloc elements from the pool. But we only allow
133 * allocation of a single element from a DMA pool at a time.
135 int gsi_trans_pool_init_dma(struct device *dev, struct gsi_trans_pool *pool,
165 pool->base = virt;
166 pool->count = total_size / size;
167 pool->free = 0;
168 pool->size = size;
169 pool->max_alloc = max_alloc;
170 pool->addr = addr;
175 void gsi_trans_pool_exit_dma(struct device *dev, struct gsi_trans_pool *pool)
177 size_t total_size = pool->count * pool->size;
179 dma_free_coherent(dev, total_size, pool->base, pool->addr);
180 memset(pool, 0, sizeof(*pool));
183 /* Return the byte offset of the next free entry in the pool */
184 static u32 gsi_trans_pool_alloc_common(struct gsi_trans_pool *pool, u32 count)
189 WARN_ON(count > pool->max_alloc);
192 if (count > pool->count - pool->free)
193 pool->free = 0;
195 offset = pool->free * pool->size;
196 pool->free += count;
197 memset(pool->base + offset, 0, count * pool->size);
202 /* Allocate a contiguous block of zeroed entries from a pool */
203 void *gsi_trans_pool_alloc(struct gsi_trans_pool *pool, u32 count)
205 return pool->base + gsi_trans_pool_alloc_common(pool, count);
208 /* Allocate a single zeroed entry from a DMA pool */
209 void *gsi_trans_pool_alloc_dma(struct gsi_trans_pool *pool, dma_addr_t *addr)
211 u32 offset = gsi_trans_pool_alloc_common(pool, 1);
213 *addr = pool->addr + offset;
215 return pool->base + offset;
416 * Their payloads come from a pool whose memory is allocated