1 /* 2 * Copyright (C) 2022 HiSilicon (Shanghai) Technologies CO., LIMITED. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU General Public License 6 * as published by the Free Software Foundation; either version 2 7 * of the License, or (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 17 */ 18 19 #ifndef __MEDIA_MEM_INTF_H__ 20 #define __MEDIA_MEM_INTF_H__ 21 22 #include <linux/version.h> 23 24 #include "hi_type.h" 25 26 typedef hi_u32 mmb_addr_t; 27 28 #define MMB_ADDR_INVALID (0) 29 30 mmb_addr_t new_mmb(const char *name, int size, unsigned int align, const char *zone_name); 31 void delete_mmb(mmb_addr_t addr, unsigned int iommu); 32 void *remap_mmb(mmb_addr_t addr, unsigned int iommu); 33 void *remap_mmb_cached(mmb_addr_t addr, unsigned int iommu); 34 #ifndef DMABUF_FLUSH_CACHE 35 int unmap_mmb(const void *mapped_addr); 36 #else 37 int unmap_mmb(void *mapped_addr); 38 #endif 39 mmb_addr_t cma_mapto_smmu(mmb_addr_t addr, int iommu); 40 int cma_unmapfrom_smmu(mmb_addr_t addr, int iommu); 41 mmb_addr_t get_phyaddr_byvirt(const void *mapped_addr, int iommu); 42 void flush_cache_kern(mmb_addr_t phyaddr, const void *viraddr, mmb_addr_t len, unsigned int iommu); 43 struct sg_table *get_meminfo(hi_u32 addr, hi_u32 iommu, hi_u32 *size, hi_u32 *base); 44 #if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0) 45 mmb_addr_t get_sec_smmu_by_nosmmu(HI_U32 nonsmmu); 46 mmb_addr_t get_sec_smmu_by_phys(HI_U32 phys_addr); 47 mmb_addr_t get_phys_by_secsmmu(HI_U32 sec_smmu); 48 mmb_addr_t get_nonsecsmmu_by_secsmmu(HI_U32 sec_smmu); 49 #endif 50 51 int mmb_buf_get(HI_U32 addr, HI_U32 iommu); 52 int mmb_buf_put(HI_U32 addr, HI_U32 iommu); 53 54 int mmb_buf_ref_query(HI_U32 addr, HI_U32 iommu, HI_U32 *ref); 55 int query_buffer_source(HI_U32 iommu_addr, HI_S32 *source); 56 int query_secure_buffer_source(HI_U32 sec_smmu, HI_S32 *source); 57 int dma_buf_export_fd(unsigned int phyaddr, unsigned int iommu); 58 #endif 59 60