1 /* 2 * vendor/amlogic/media/common/ge2d/ge2d_dmabuf.h 3 * 4 * Copyright (C) 2017 Amlogic, Inc. All rights reserved. 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 * more details. 15 * 16 */ 17 18 #ifndef _GE2D_DMABUF_H_ 19 #define _GE2D_DMABUF_H_ 20 21 #include <linux/mm_types.h> 22 #include <linux/mutex.h> 23 #include <linux/dma-buf.h> 24 25 /* Amlogic Headers */ 26 #include <linux/amlogic/media/ge2d/ge2d.h> 27 28 #define AML_MAX_DMABUF 32 29 30 struct aml_dma_buf { 31 struct device *dev; 32 void *cookie; 33 void *vaddr; 34 unsigned int size; 35 enum dma_data_direction dma_dir; 36 unsigned long attrs; 37 unsigned int index; 38 dma_addr_t dma_addr; 39 atomic_t refcount; 40 /* DMABUF related */ 41 struct dma_buf_attachment *db_attach; 42 void *priv; 43 }; 44 45 struct aml_dma_buf_priv { 46 void *mem_priv; 47 int index; 48 int fd; 49 unsigned int alloc; 50 struct dma_buf *dbuf; 51 }; 52 53 struct aml_dma_buffer { 54 struct mutex lock; 55 struct aml_dma_buf_priv gd_buffer[AML_MAX_DMABUF]; 56 }; 57 58 struct aml_dma_cfg { 59 int fd; 60 void *dev; 61 void *vaddr; 62 struct dma_buf *dbuf; 63 struct dma_buf_attachment *attach; 64 struct sg_table *sg; 65 enum dma_data_direction dir; 66 }; 67 68 void *ge2d_dma_buffer_create(void); 69 void ge2d_dma_buffer_destroy(struct aml_dma_buffer *buffer); 70 int ge2d_dma_buffer_alloc(struct aml_dma_buffer *buffer, struct device *dev, struct ge2d_dmabuf_req_s *ge2d_req_buf); 71 int ge2d_dma_buffer_free(struct aml_dma_buffer *buffer, int index); 72 int ge2d_dma_buffer_export(struct aml_dma_buffer *buffer, struct ge2d_dmabuf_exp_s *ge2d_exp_buf); 73 int ge2d_dma_buffer_map(struct aml_dma_cfg *cfg); 74 void ge2d_dma_buffer_unmap(struct aml_dma_cfg *cfg); 75 int ge2d_dma_buffer_get_phys(struct aml_dma_buffer *buffer, struct aml_dma_cfg *cfg, unsigned long *addr); 76 int ge2d_dma_buffer_unmap_info(struct aml_dma_buffer *buffer, struct aml_dma_cfg *cfg); 77 void ge2d_dma_buffer_dma_flush(struct device *dev, int fd); 78 void ge2d_dma_buffer_cache_flush(struct device *dev, int fd); 79 #endif 80