00001
00046 #ifndef DMAPOOL_H_INCLUDED
00047 #define DMAPOOL_H_INCLUDED
00048
00049 #include <cpu/dmapool.h>
00050
00051 void dma_pool_init_coherent_physmem(struct dma_pool *dmapool,
00052 struct physmem_pool *phys_pool, unsigned int nr_objects,
00053 size_t objsize, unsigned int align_order);
00054
00055 #ifdef CONFIG_DMAPOOL_GENERIC_POOLS
00056 #include <assert.h>
00057 #include <app/config_dmapool.h>
00058
00059 #ifdef CONFIG_DMAPOOL_SMALL_OBJ_SIZE
00060 extern struct dma_pool dmapool_size_small;
00061 #endif
00062 #ifdef CONFIG_DMAPOOL_LARGE_OBJ_SIZE
00063 extern struct dma_pool dmapool_size_large;
00064 #endif
00065
00066 static inline struct dma_pool *dmapool_find_pool(size_t alloc_size)
00067 {
00068 #ifdef CONFIG_DMAPOOL_SMALL_OBJ_SIZE
00069 if (alloc_size <= CONFIG_DMAPOOL_SMALL_OBJ_SIZE)
00070 return &dmapool_size_small;
00071 #endif
00072 #ifdef CONFIG_DMAPOOL_LARGE_OBJ_SIZE
00073 if (alloc_size <= CONFIG_DMAPOOL_LARGE_OBJ_SIZE)
00074 return &dmapool_size_large;
00075 #endif
00076
00077 return NULL;
00078 }
00079
00080 static inline void *dma_alloc_inline(phys_addr_t *paddr, size_t size)
00081 {
00082 struct dma_pool *pool;
00083
00084 pool = dmapool_find_pool(size);
00085 if (likely(pool))
00086 return dma_pool_alloc(pool, paddr);
00087 else
00088 return NULL;
00089 }
00090
00091 extern void *dma_alloc_noninline(phys_addr_t *paddr, size_t size);
00092
00107 static inline void *dma_alloc(phys_addr_t *paddr, size_t size)
00108 {
00109 if (is_constant(size))
00110 return dma_alloc_inline(paddr, size);
00111 else
00112 return dma_alloc_noninline(paddr, size);
00113 }
00114
00115 static inline void dma_free_inline(const void *obj, size_t size)
00116 {
00117 struct dma_pool *pool;
00118
00119 pool = dmapool_find_pool(size);
00120 assert(pool);
00121 dma_pool_free(pool, obj);
00122 }
00123
00124 extern void dma_free_noninline(const void *obj, size_t size);
00125
00136 static inline void dma_free(const void *obj, size_t size)
00137 {
00138 if (is_constant(size))
00139 dma_free_inline(obj, size);
00140 else
00141 dma_free_noninline(obj, size);
00142 }
00143
00144 extern void dma_pool_init(void);
00145
00146 #endif
00147
00148 #endif