1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright (C) Rockchip Electronics Co.Ltd 4 * Author: Felix Zeng <felix.zeng@rock-chips.com> 5 */ 6 7 #ifndef __LINUX_RKNPU_IOMMU_H 8 #define __LINUX_RKNPU_IOMMU_H 9 10 #include <linux/mutex.h> 11 #include <linux/seq_file.h> 12 #include <linux/iommu.h> 13 #include <linux/iova.h> 14 #include <linux/version.h> 15 16 #if KERNEL_VERSION(6, 1, 0) > LINUX_VERSION_CODE 17 #include <linux/dma-iommu.h> 18 #endif 19 20 #include "rknpu_drv.h" 21 22 enum iommu_dma_cookie_type { 23 IOMMU_DMA_IOVA_COOKIE, 24 IOMMU_DMA_MSI_COOKIE, 25 }; 26 27 struct rknpu_iommu_dma_cookie { 28 enum iommu_dma_cookie_type type; 29 30 /* Full allocator for IOMMU_DMA_IOVA_COOKIE */ 31 struct iova_domain iovad; 32 }; 33 34 dma_addr_t rknpu_iommu_dma_alloc_iova(struct iommu_domain *domain, size_t size, 35 u64 dma_limit, struct device *dev); 36 37 void rknpu_iommu_dma_free_iova(struct rknpu_iommu_dma_cookie *cookie, 38 dma_addr_t iova, size_t size); 39 40 #endif 41