diff --git a/drivers/rknpu/rknpu_drv.c b/drivers/rknpu/rknpu_drv.c index 9e6f1d28a55c..a0af79b23409 100644 --- a/drivers/rknpu/rknpu_drv.c +++ b/drivers/rknpu/rknpu_drv.c @@ -759,7 +759,8 @@ static struct drm_driver rknpu_drm_driver = { .gem_prime_import = drm_gem_prime_import, #endif .gem_prime_import_sg_table = rknpu_gem_prime_import_sg_table, -#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE +#if KERNEL_VERSION(6, 6, 0) <= LINUX_VERSION_CODE +#elif KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE .gem_prime_mmap = drm_gem_prime_mmap, #else .gem_prime_mmap = rknpu_gem_prime_mmap, diff --git a/drivers/rknpu/rknpu_gem.c b/drivers/rknpu/rknpu_gem.c index f1346f98fff6..136a2a6c1795 100644 --- a/drivers/rknpu/rknpu_gem.c +++ b/drivers/rknpu/rknpu_gem.c @@ -18,6 +18,7 @@ #include #include #include +#include #if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE #include @@ -447,8 +448,13 @@ static int rknpu_iommu_map_with_cache_sgt(struct iommu_domain *domain, for_each_sgtable_sg(rknpu_dev->cache_sgt[index], s, i) { cache_start = rknpu_dev->nbuf_start + s->offset; size = length < s->length ? length : s->length; +#if KERNEL_VERSION(6, 3, 0) <= LINUX_VERSION_CODE + ret = iommu_map(domain, iova_start, cache_start, size, + IOMMU_READ | IOMMU_WRITE, GFP_KERNEL); +#else ret = iommu_map(domain, iova_start, cache_start, size, IOMMU_READ | IOMMU_WRITE); +#endif if (ret) { LOG_ERROR("cache iommu_map error: %d\n", ret); return ret; @@ -546,9 +552,15 @@ static int rknpu_gem_alloc_buf_with_cache(struct rknpu_gem_object *rknpu_obj, * */ if (!rknpu_obj->cache_with_sgt) +#if KERNEL_VERSION(6, 3, 0) <= LINUX_VERSION_CODE + ret = iommu_map(domain, rknpu_obj->iova_start, + cache_start + cache_offset, cache_size, + IOMMU_READ | IOMMU_WRITE, GFP_KERNEL); +#else ret = iommu_map(domain, rknpu_obj->iova_start, cache_start + cache_offset, cache_size, IOMMU_READ | IOMMU_WRITE); +#endif else ret = rknpu_iommu_map_with_cache_sgt(domain, rknpu_dev, rknpu_obj, cache_size); @@ -593,8 +605,13 @@ static int rknpu_gem_alloc_buf_with_cache(struct rknpu_gem_object *rknpu_obj, for_each_sg(rknpu_obj->sgt->sgl, s, rknpu_obj->sgt->nents, i) { size = (length < s->length) ? length : s->length; +#if KERNEL_VERSION(6, 3, 0) <= LINUX_VERSION_CODE + ret = iommu_map(domain, offset, sg_phys(s), size, + IOMMU_READ | IOMMU_WRITE, GFP_KERNEL); +#else ret = iommu_map(domain, offset, sg_phys(s), size, IOMMU_READ | IOMMU_WRITE); +#endif if (ret) { LOG_ERROR("ddr iommu_map error: %d\n", ret); goto sgl_unmap; diff --git a/drivers/rknpu/rknpu_iommu.c b/drivers/rknpu/rknpu_iommu.c index a3efb1ef0273..5b5755fc9118 100644 --- a/drivers/rknpu/rknpu_iommu.c +++ b/drivers/rknpu/rknpu_iommu.c @@ -7,11 +7,16 @@ #include #include #include +#include #include "rknpu_iommu.h" #define RKNPU_SWITCH_DOMAIN_WAIT_TIME_MS 6000 +#if KERNEL_VERSION(6, 5, 0) <= LINUX_VERSION_CODE +#define sg_is_dma_bus_address(sg) sg_dma_is_bus_address(sg) +#endif + dma_addr_t rknpu_iommu_dma_alloc_iova(struct iommu_domain *domain, size_t size, u64 dma_limit, struct device *dev, bool size_aligned) @@ -274,7 +279,11 @@ int rknpu_iommu_dma_map_sg(struct device *dev, struct scatterlist *sg, goto out_restore_sg; } +#if KERNEL_VERSION(6, 3, 0) <= LINUX_VERSION_CODE + ret = iommu_map_sg(domain, iova, sg, nents, prot, GFP_KERNEL); +#else ret = iommu_map_sg(domain, iova, sg, nents, prot); +#endif if (ret < 0 || ret < iova_len) { LOG_ERROR("failed to map SG: %zd\n", ret); goto out_free_iova; @@ -419,7 +428,7 @@ int rknpu_iommu_switch_domain(struct rknpu_device *rknpu_dev, int domain_id) { struct iommu_domain *src_domain = NULL; struct iommu_domain *dst_domain = NULL; - struct bus_type *bus = NULL; + const struct bus_type *bus = NULL; int src_domain_id = 0; int ret = -EINVAL; @@ -470,8 +479,6 @@ int rknpu_iommu_switch_domain(struct rknpu_device *rknpu_dev, int domain_id) } rknpu_dev->iommu_domain_id = domain_id; } else { - uint64_t dma_limit = 1ULL << 32; - dst_domain = iommu_domain_alloc(bus); if (!dst_domain) { LOG_DEV_ERROR(rknpu_dev->dev, @@ -495,7 +502,9 @@ int rknpu_iommu_switch_domain(struct rknpu_device *rknpu_dev, int domain_id) // set domain type to dma domain dst_domain->type |= __IOMMU_DOMAIN_DMA_API; // iommu dma init domain - iommu_setup_dma_ops(rknpu_dev->dev, 0, dma_limit); +#if KERNEL_VERSION(6, 10, 0) > LINUX_VERSION_CODE + iommu_setup_dma_ops(rknpu_dev->dev, 0, 1ULL << 32); +#endif rknpu_dev->iommu_domain_id = domain_id; rknpu_dev->iommu_domains[domain_id] = dst_domain;