- Main Page
- Related Pages
- Data Structures
- Files

- File List
- Globals

# lib/buffer.c

    00001 #include <buffer.h>
    00002 #include <mempool.h>
    00003 #include <dmapool.h>
    00004 #include <physmem.h>
    00005
    00006 #ifdef CONFIG_NR_BUFFERS
    00007 struct mem_pool buffer_pool;
    00008
    00014 struct buffer *buffer_alloc(void)
    00015 {
    00016         struct buffer   *buf;
    00017
    00018         buf = mem_pool_alloc(&buffer_pool);
    00019         dbg_printf("buffer_alloc: %p\n", buf);
    00020         buf->dma_desc = NULL;
    00021
    00022         return buf;
    00023 }
    00024
    00028 void buffer_free(struct buffer *buf)
    00029 {
    00030         dbg_printf("buffer_free: %p\n", buf);
    00031
    00032         mem_pool_free(&buffer_pool, buf);
    00033 }
    00034
    00039 void buffer_resize(struct buffer *buf, size_t new_size)
    00040 {
    00041         assert(buf);
    00042
    00043         buf->len = new_size;
    00044 }
    00045
    00046 #ifdef CONFIG_DMAPOOL_GENERIC_POOLS
    00047
    00057 struct buffer *buffer_dma_alloc(size_t size)
    00058 {
    00059         struct buffer   *buf;
    00060         void            *dma_data;
    00061         phys_addr_t     dma_phys;
    00062
    00063         buf = buffer_alloc();
    00064         if (buf == NULL)
    00065                 return NULL;
    00066
    00067         dma_data = dma_alloc(&dma_phys, size);
    00068         if (dma_data == NULL) {
    00069                 buffer_free(buf);
    00070                 return NULL;
    00071         }
    00072
    00073         buf->addr.ptr = dma_data;
    00074         buf->addr.phys = dma_phys;
    00075         buf->len = size;
    00076
    00077         return buf;
    00078 }
    00079
    00083 void buffer_dma_free(struct buffer *buf, size_t size)
    00084 {
    00085         dma_free(buf->addr.ptr, size);
    00086         buffer_free(buf);
    00087 }
    00088 #endif /* CONFIG_DMAPOOL_GENERIC_POOLS */
    00089
    00096 void buffer_pool_init(void)
    00097 {
    00098         mem_pool_init_physmem(&buffer_pool, &cpu_sram_pool,
    00099                         CONFIG_NR_BUFFERS, sizeof(struct buffer), 2);
    00100 }
    00101 #endif