1 #include "cmem_buf.h"
2 #include <stdio.h>
3 #include <unistd.h>
4 #include <ti/cmem.h>
5 #include <linux/dma-buf.h>
6 #include <sys/ioctl.h>
8 #define CMEM_BLOCKID CMEM_CMABLOCKID
10 CMEM_AllocParams cmem_alloc_params = {
11 CMEM_HEAP, /* type */
12 CMEM_CACHED, /* flags */
13 1 /* alignment */
14 };
16 void init_cmem()
17 {
18 CMEM_init();
19 }
21 int alloc_cmem_buffer(unsigned int size, unsigned int align, void **cmem_buf)
22 {
23 cmem_alloc_params.alignment = align;
25 *cmem_buf = CMEM_alloc2(CMEM_BLOCKID, size,
26 &cmem_alloc_params);
28 if(*cmem_buf == NULL){
29 printf("CMEM allocation failed");
30 return -1;
31 }
32 printf("CMEM buffer pointer is 0x%x\n",(uint32_t) *cmem_buf );
33 return CMEM_export_dmabuf(*cmem_buf);
34 }
36 void free_cmem_buffer(void *cmem_buffer)
37 {
38 CMEM_free(cmem_buffer, &cmem_alloc_params);
39 }
41 int dma_buf_do_cache_operation(int dma_buf_fd, uint32_t cache_operation)
42 {
43 int ret;
44 struct dma_buf_sync sync;
45 sync.flags = cache_operation;
47 ret = ioctl(dma_buf_fd, DMA_BUF_IOCTL_SYNC, &sync);
49 return ret;
50 }