driver: rknpu: Add compatibility for Linux kernel 6.12

Change-Id: If6799f454820cec3c9a4457edf4c88c5d55605c7
Signed-off-by: Shuangjie Lin <shuangjie.lin@rock-chips.com>
This commit is contained in:
Shuangjie Lin
2025-06-14 16:29:38 +08:00
committed by Tao Huang
parent 56ab425cad
commit 1843e14f39
3 changed files with 32 additions and 5 deletions

View File

@@ -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,

View File

@@ -18,6 +18,7 @@
#include <linux/version.h>
#include <linux/version_compat_defs.h>
#include <asm/cacheflush.h>
#include <linux/vmalloc.h>
#if KERNEL_VERSION(5, 10, 0) <= LINUX_VERSION_CODE
#include <linux/dma-map-ops.h>
@@ -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;

View File

@@ -7,11 +7,16 @@
#include <linux/dma-map-ops.h>
#include <linux/delay.h>
#include <linux/jiffies.h>
#include <linux/scatterlist.h>
#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;