Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update rknpu 0.9.8-noble #36

Open
wants to merge 7 commits into
base: noble
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions drivers/cpufreq/rockchip-cpufreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ static const struct rockchip_opp_data rk3588_cpu_opp_data = {

static const struct rockchip_opp_data rk3576_cpu_opp_data = {
.set_read_margin = rk3576_cpu_set_read_margin,
.set_soc_info = rockchip_opp_set_low_length,
.config_regulators = cpu_opp_config_regulators,
};

Expand Down Expand Up @@ -570,6 +571,42 @@ static int rockchip_cpufreq_suspend(struct cpufreq_policy *policy)
return ret;
}

int rockchip_cpufreq_online(int cpu)
{
struct cluster_info *cluster;
struct rockchip_opp_info *opp_info;

cluster = rockchip_cluster_info_lookup(cpu);
if (!cluster)
return -EINVAL;
opp_info = &cluster->opp_info;

opp_info->is_runtime_active = true;
if (opp_info->data && opp_info->data->set_read_margin)
opp_info->data->set_read_margin(opp_info->dev, opp_info,
opp_info->target_rm);

return 0;
}
EXPORT_SYMBOL_GPL(rockchip_cpufreq_online);

int rockchip_cpufreq_offline(int cpu)
{
struct cluster_info *cluster;
struct rockchip_opp_info *opp_info;

cluster = rockchip_cluster_info_lookup(cpu);
if (!cluster)
return -EINVAL;
opp_info = &cluster->opp_info;

opp_info->is_runtime_active = false;
opp_info->current_rm = UINT_MAX;

return 0;
}
EXPORT_SYMBOL_GPL(rockchip_cpufreq_offline);

static int rockchip_cpufreq_add_monitor(struct cluster_info *cluster,
struct cpufreq_policy *policy)
{
Expand Down
24 changes: 9 additions & 15 deletions drivers/gpu/arm/bifrost/platform/rk/mali_kbase_config_rk.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ struct kbase_platform_funcs_conf platform_funcs = {

/*---------------------------------------------------------------------------*/

static int rk_pm_callback_runtime_on(struct kbase_device *kbdev)
static __maybe_unused int rk_pm_callback_runtime_on(struct kbase_device *kbdev)
{
struct rockchip_opp_info *opp_info = &kbdev->opp_info;
int ret = 0;
Expand All @@ -226,7 +226,7 @@ static int rk_pm_callback_runtime_on(struct kbase_device *kbdev)
return 0;
}

static void rk_pm_callback_runtime_off(struct kbase_device *kbdev)
static __maybe_unused void rk_pm_callback_runtime_off(struct kbase_device *kbdev)
{
struct rockchip_opp_info *opp_info = &kbdev->opp_info;

Expand Down Expand Up @@ -310,29 +310,22 @@ static void rk_pm_callback_power_off(struct kbase_device *kbdev)
msecs_to_jiffies(platform->delay_ms));
}

static int rk_kbase_device_runtime_init(struct kbase_device *kbdev)
static __maybe_unused int rk_kbase_device_runtime_init(struct kbase_device *kbdev)
{
return 0;
}

static void rk_kbase_device_runtime_disable(struct kbase_device *kbdev)
static __maybe_unused void rk_kbase_device_runtime_disable(struct kbase_device *kbdev)
{
}

struct kbase_pm_callback_conf pm_callbacks = {
.power_on_callback = rk_pm_callback_power_on,
.power_off_callback = rk_pm_callback_power_off,
#ifdef CONFIG_PM
.power_runtime_init_callback = rk_kbase_device_runtime_init,
.power_runtime_term_callback = rk_kbase_device_runtime_disable,
.power_runtime_on_callback = rk_pm_callback_runtime_on,
.power_runtime_off_callback = rk_pm_callback_runtime_off,
#else /* CONFIG_PM */
.power_runtime_init_callback = NULL,
.power_runtime_term_callback = NULL,
.power_runtime_on_callback = NULL,
.power_runtime_off_callback = NULL,
#endif /* CONFIG_PM */
.power_runtime_init_callback = pm_ptr(rk_kbase_device_runtime_init),
.power_runtime_term_callback = pm_ptr(rk_kbase_device_runtime_disable),
.power_runtime_on_callback = pm_ptr(rk_pm_callback_runtime_on),
.power_runtime_off_callback = pm_ptr(rk_pm_callback_runtime_off),
};

/*---------------------------------------------------------------------------*/
Expand Down Expand Up @@ -647,6 +640,7 @@ static int gpu_opp_config_clks(struct device *dev, struct opp_table *opp_table,

static const struct rockchip_opp_data rk3576_gpu_opp_data = {
.set_read_margin = rk3576_gpu_set_read_margin,
.set_soc_info = rockchip_opp_set_low_length,
.config_regulators = gpu_opp_config_regulators,
.config_clks = gpu_opp_config_clks,
};
Expand Down
5 changes: 3 additions & 2 deletions drivers/rknpu/include/rknpu_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@

#define DRIVER_NAME "rknpu"
#define DRIVER_DESC "RKNPU driver"
#define DRIVER_DATE "20240424"
#define DRIVER_DATE "20240828"
#define DRIVER_MAJOR 0
#define DRIVER_MINOR 9
#define DRIVER_PATCHLEVEL 7
#define DRIVER_PATCHLEVEL 8

#define LOG_TAG "RKNPU"

Expand Down Expand Up @@ -174,6 +174,7 @@ struct rknpu_device {
int iommu_domain_id;
struct iommu_domain *iommu_domains[RKNPU_MAX_IOMMU_DOMAIN_NUM];
struct sg_table *cache_sgt[RKNPU_CACHE_SG_TABLE_NUM];
atomic_t iommu_domain_refcount;
};

struct rknpu_session {
Expand Down
3 changes: 3 additions & 0 deletions drivers/rknpu/include/rknpu_iommu.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ void rknpu_iommu_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
int rknpu_iommu_init_domain(struct rknpu_device *rknpu_dev);
int rknpu_iommu_switch_domain(struct rknpu_device *rknpu_dev, int domain_id);
void rknpu_iommu_free_domains(struct rknpu_device *rknpu_dev);
int rknpu_iommu_domain_get_and_switch(struct rknpu_device *rknpu_dev,
int domain_id);
int rknpu_iommu_domain_put(struct rknpu_device *rknpu_dev);

#if KERNEL_VERSION(5, 10, 0) < LINUX_VERSION_CODE
int iommu_get_dma_cookie(struct iommu_domain *domain);
Expand Down
1 change: 1 addition & 0 deletions drivers/rknpu/rknpu_devfreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ static int npu_opp_config_clks(struct device *dev, struct opp_table *opp_table,

static const struct rockchip_opp_data rk3576_npu_opp_data = {
.set_read_margin = rk3576_npu_set_read_margin,
.set_soc_info = rockchip_opp_set_low_length,
#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE
.config_regulators = npu_opp_config_regulators,
.config_clks = npu_opp_config_clks,
Expand Down
8 changes: 6 additions & 2 deletions drivers/rknpu/rknpu_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,11 @@ static int rknpu_action(struct rknpu_device *rknpu_dev,
ret = 0;
break;
case RKNPU_SET_IOMMU_DOMAIN_ID: {
ret = rknpu_iommu_switch_domain(rknpu_dev,
*(int32_t *)&args->value);
ret = rknpu_iommu_domain_get_and_switch(
rknpu_dev, *(int32_t *)&args->value);
if (ret)
break;
rknpu_iommu_domain_put(rknpu_dev);
break;
}
default:
Expand Down Expand Up @@ -1497,6 +1500,7 @@ static int rknpu_probe(struct platform_device *pdev)
rknpu_power_off(rknpu_dev);
atomic_set(&rknpu_dev->power_refcount, 0);
atomic_set(&rknpu_dev->cmdline_power_refcount, 0);
atomic_set(&rknpu_dev->iommu_domain_refcount, 0);

rknpu_debugger_init(rknpu_dev);
rknpu_init_timer(rknpu_dev);
Expand Down
57 changes: 51 additions & 6 deletions drivers/rknpu/rknpu_gem.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <drm/drm_file.h>
#include <drm/drm_drv.h>

#include <linux/delay.h>
#include <linux/shmem_fs.h>
#include <linux/dma-buf.h>
#include <linux/iommu.h>
Expand Down Expand Up @@ -695,8 +696,13 @@ rknpu_gem_object_create(struct drm_device *drm, unsigned int flags,
if (IS_ERR(rknpu_obj))
return rknpu_obj;

if (!rknpu_iommu_switch_domain(rknpu_dev, iommu_domain_id))
rknpu_obj->iommu_domain_id = iommu_domain_id;
if (rknpu_iommu_domain_get_and_switch(rknpu_dev, iommu_domain_id)) {
LOG_DEV_ERROR(rknpu_dev->dev, "%s error\n", __func__);
rknpu_gem_release(rknpu_obj);
return ERR_PTR(-EINVAL);
}

rknpu_obj->iommu_domain_id = iommu_domain_id;

if (!rknpu_dev->iommu_en && (flags & RKNPU_MEM_NON_CONTIGUOUS)) {
/*
Expand Down Expand Up @@ -788,6 +794,8 @@ rknpu_gem_object_create(struct drm_device *drm, unsigned int flags,
goto gem_release;
}

rknpu_iommu_domain_put(rknpu_dev);

LOG_DEBUG(
"created dma addr: %pad, cookie: %p, ddr size: %lu, sram size: %lu, nbuf size: %lu, attrs: %#lx, flags: %#x, iommu domain id: %d\n",
&rknpu_obj->dma_addr, rknpu_obj->cookie, rknpu_obj->size,
Expand All @@ -805,20 +813,35 @@ rknpu_gem_object_create(struct drm_device *drm, unsigned int flags,
gem_release:
rknpu_gem_release(rknpu_obj);

rknpu_iommu_domain_put(rknpu_dev);

return ERR_PTR(ret);
}

void rknpu_gem_object_destroy(struct rknpu_gem_object *rknpu_obj)
{
struct drm_gem_object *obj = &rknpu_obj->base;
struct rknpu_device *rknpu_dev = obj->dev->dev_private;
int wait_count = 0;
int ret = -EINVAL;

LOG_DEBUG(
"destroy dma addr: %pad, cookie: %p, size: %lu, attrs: %#lx, flags: %#x, handle count: %d\n",
&rknpu_obj->dma_addr, rknpu_obj->cookie, rknpu_obj->size,
rknpu_obj->dma_attrs, rknpu_obj->flags, obj->handle_count);

rknpu_iommu_switch_domain(rknpu_dev, rknpu_obj->iommu_domain_id);
do {
ret = rknpu_iommu_domain_get_and_switch(
rknpu_dev, rknpu_obj->iommu_domain_id);

if (ret && ++wait_count >= 3) {
LOG_DEV_ERROR(
rknpu_dev->dev,
"failed to destroy dma addr: %pad, size: %lu\n",
&rknpu_obj->dma_addr, rknpu_obj->size);
return;
}
} while (ret);

/*
* do not release memory region from exporter.
Expand Down Expand Up @@ -847,6 +870,7 @@ void rknpu_gem_object_destroy(struct rknpu_gem_object *rknpu_obj)
}

rknpu_gem_release(rknpu_obj);
rknpu_iommu_domain_put(rknpu_dev);
}

int rknpu_gem_create_ioctl(struct drm_device *drm, void *data,
Expand Down Expand Up @@ -903,16 +927,29 @@ int rknpu_gem_destroy_ioctl(struct drm_device *drm, void *data,
struct rknpu_device *rknpu_dev = drm->dev_private;
struct rknpu_gem_object *rknpu_obj = NULL;
struct rknpu_mem_destroy *args = data;
int ret = 0;
int wait_count = 0;

rknpu_obj = rknpu_gem_object_find(file_priv, args->handle);
if (!rknpu_obj)
return -EINVAL;

rknpu_iommu_switch_domain(rknpu_dev, rknpu_obj->iommu_domain_id);
do {
ret = rknpu_iommu_domain_get_and_switch(
rknpu_dev, rknpu_obj->iommu_domain_id);

// rknpu_gem_object_put(&rknpu_obj->base);
if (ret && ++wait_count >= 3) {
LOG_DEV_ERROR(rknpu_dev->dev,
"failed to destroy memory\n");
return ret;
}
} while (ret);

ret = rknpu_gem_handle_destroy(file_priv, args->handle);

return rknpu_gem_handle_destroy(file_priv, args->handle);
rknpu_iommu_domain_put(rknpu_dev);

return ret;
}

#if RKNPU_GEM_ALLOC_FROM_PAGES
Expand Down Expand Up @@ -1647,6 +1684,12 @@ int rknpu_gem_sync_ioctl(struct drm_device *dev, void *data,
if (!(rknpu_obj->flags & RKNPU_MEM_CACHEABLE))
return -EINVAL;

if (rknpu_iommu_domain_get_and_switch(rknpu_dev,
rknpu_obj->iommu_domain_id)) {
LOG_DEV_ERROR(rknpu_dev->dev, "%s error\n", __func__);
return -EINVAL;
}

if (!(rknpu_obj->flags & RKNPU_MEM_NON_CONTIGUOUS)) {
if (args->flags & RKNPU_MEM_SYNC_TO_DEVICE) {
dma_sync_single_range_for_device(
Expand Down Expand Up @@ -1708,5 +1751,7 @@ int rknpu_gem_sync_ioctl(struct drm_device *dev, void *data,
}
}

rknpu_iommu_domain_put(rknpu_dev);

return 0;
}
Loading