Skip to content

Commit

Permalink
Updated driver to version 0.9.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Pelochus authored Apr 20, 2024
1 parent 13d1baf commit c0fc087
Show file tree
Hide file tree
Showing 7 changed files with 369 additions and 54 deletions.
31 changes: 31 additions & 0 deletions drivers/rknpu/rknpu.mod.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <linux/module.h>
#define INCLUDE_VERMAGIC
#include <linux/build-salt.h>
#include <linux/vermagic.h>
#include <linux/compiler.h>

BUILD_SALT;

MODULE_INFO(vermagic, VERMAGIC_STRING);
MODULE_INFO(name, KBUILD_MODNAME);

__visible struct module __this_module
__section(".gnu.linkonce.this_module") = {
.name = KBUILD_MODNAME,
.init = init_module,
#ifdef CONFIG_MODULE_UNLOAD
.exit = cleanup_module,
#endif
.arch = MODULE_ARCH_INIT,
};

MODULE_INFO(intree, "Y");

#ifdef CONFIG_RETPOLINE
MODULE_INFO(retpoline, "Y");
#endif

MODULE_INFO(depends, "");


MODULE_INFO(srcversion, "3F8407365EF7935915D4CC3");
31 changes: 31 additions & 0 deletions drivers/rknpu/rknpu_devfreq.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ static struct devfreq_governor devfreq_rknpu_ondemand = {
.event_handler = devfreq_rknpu_ondemand_handler,
};

static int rk3576_npu_set_read_margin(struct device *dev,
struct rockchip_opp_info *opp_info,
u32 rm)
{
if (!opp_info->grf || !opp_info->volt_rm_tbl)
return 0;

if (rm == opp_info->current_rm || rm == UINT_MAX)
return 0;

LOG_DEV_DEBUG(dev, "set rm to %d\n", rm);

regmap_write(opp_info->grf, 0x08, 0x001c0000 | (rm << 2));
regmap_write(opp_info->grf, 0x0c, 0x003c0000 | (rm << 2));
regmap_write(opp_info->grf, 0x10, 0x001c0000 | (rm << 2));

return 0;
}

static int rk3588_npu_get_soc_info(struct device *dev, struct device_node *np,
int *bin, int *process)
{
Expand Down Expand Up @@ -213,6 +232,14 @@ static int npu_opp_config_clks(struct device *dev, struct opp_table *opp_table,
}
#endif

static const struct rockchip_opp_data rk3576_npu_opp_data = {
.set_read_margin = rk3576_npu_set_read_margin,
#if KERNEL_VERSION(6, 1, 0) <= LINUX_VERSION_CODE
.config_regulators = npu_opp_config_regulators,
.config_clks = npu_opp_config_clks,
#endif
};

static const struct rockchip_opp_data rk3588_npu_opp_data = {
.get_soc_info = rk3588_npu_get_soc_info,
.set_soc_info = rk3588_npu_set_soc_info,
Expand All @@ -224,6 +251,10 @@ static const struct rockchip_opp_data rk3588_npu_opp_data = {
};

static const struct of_device_id rockchip_npu_of_match[] = {
{
.compatible = "rockchip,rk3576",
.data = (void *)&rk3576_npu_opp_data,
},
{
.compatible = "rockchip,rk3588",
.data = (void *)&rk3588_npu_opp_data,
Expand Down
77 changes: 64 additions & 13 deletions drivers/rknpu/rknpu_drv.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "rknpu_drv.h"
#include "rknpu_gem.h"
#include "rknpu_devfreq.h"
#include "rknpu_iommu.h"

#ifdef CONFIG_ROCKCHIP_RKNPU_DRM_GEM
#include <drm/drm_device.h>
Expand Down Expand Up @@ -75,6 +76,11 @@ static const struct rknpu_irqs_data rknpu_irqs[] = {
{ "npu_irq", rknpu_core0_irq_handler }
};

static const struct rknpu_irqs_data rk3576_npu_irqs[] = {
{ "npu0_irq", rknpu_core0_irq_handler },
{ "npu1_irq", rknpu_core1_irq_handler }
};

static const struct rknpu_irqs_data rk3588_npu_irqs[] = {
{ "npu0_irq", rknpu_core0_irq_handler },
{ "npu1_irq", rknpu_core1_irq_handler },
Expand Down Expand Up @@ -197,6 +203,25 @@ static const struct rknpu_config rk3562_rknpu_config = {
.amount_core = NULL,
};

static const struct rknpu_config rk3576_rknpu_config = {
.bw_priority_addr = 0x0,
.bw_priority_length = 0x0,
.dma_mask = DMA_BIT_MASK(40),
.pc_data_amount_scale = 2,
.pc_task_number_bits = 16,
.pc_task_number_mask = 0xffff,
.pc_task_status_offset = 0x48,
.pc_dma_ctrl = 1,
.irqs = rk3576_npu_irqs,
.num_irqs = ARRAY_SIZE(rk3576_npu_irqs),
.nbuf_phyaddr = 0x3fe80000,
.nbuf_size = 1024 * 1024,
.max_submit_number = (1 << 16) - 1,
.core_mask = 0x3,
.amount_top = &rknpu_top_amount,
.amount_core = &rknpu_core_amount,
};

/* driver probe and init */
static const struct of_device_id rknpu_of_match[] = {
{
Expand All @@ -219,6 +244,10 @@ static const struct of_device_id rknpu_of_match[] = {
.compatible = "rockchip,rk3562-rknpu",
.data = &rk3562_rknpu_config,
},
{
.compatible = "rockchip,rk3576-rknpu",
.data = &rk3576_rknpu_config,
},
{},
};

Expand Down Expand Up @@ -375,6 +404,15 @@ static int rknpu_action(struct rknpu_device *rknpu_dev,
args->value = 0;
ret = 0;
break;
case RKNPU_GET_IOMMU_DOMAIN_ID:
args->value = rknpu_dev->iommu_domain_id;
ret = 0;
break;
case RKNPU_SET_IOMMU_DOMAIN_ID: {
ret = rknpu_iommu_switch_domain(rknpu_dev,
*(int32_t *)&args->value);
break;
}
default:
ret = -EINVAL;
break;
Expand Down Expand Up @@ -464,7 +502,7 @@ static int rknpu_action_ioctl(struct rknpu_device *rknpu_dev,
return ret;
}

static long rknpu_ioctl(struct file *file, uint32_t cmd, unsigned long arg)
static long rknpu_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
long ret = -EINVAL;
struct rknpu_device *rknpu_dev = NULL;
Expand All @@ -476,22 +514,22 @@ static long rknpu_ioctl(struct file *file, uint32_t cmd, unsigned long arg)

rknpu_power_get(rknpu_dev);

switch (cmd) {
case IOCTL_RKNPU_ACTION:
switch (_IOC_NR(cmd)) {
case RKNPU_ACTION:
ret = rknpu_action_ioctl(rknpu_dev, arg);
break;
case IOCTL_RKNPU_SUBMIT:
case RKNPU_SUBMIT:
ret = rknpu_submit_ioctl(rknpu_dev, arg);
break;
case IOCTL_RKNPU_MEM_CREATE:
ret = rknpu_mem_create_ioctl(rknpu_dev, arg, file);
case RKNPU_MEM_CREATE:
ret = rknpu_mem_create_ioctl(rknpu_dev, file, cmd, arg);
break;
case RKNPU_MEM_MAP:
break;
case IOCTL_RKNPU_MEM_DESTROY:
ret = rknpu_mem_destroy_ioctl(rknpu_dev, arg, file);
case RKNPU_MEM_DESTROY:
ret = rknpu_mem_destroy_ioctl(rknpu_dev, file, arg);
break;
case IOCTL_RKNPU_MEM_SYNC:
case RKNPU_MEM_SYNC:
ret = rknpu_mem_sync_ioctl(rknpu_dev, arg);
break;
default:
Expand Down Expand Up @@ -1171,7 +1209,11 @@ static int rknpu_probe(struct platform_device *pdev)
rknpu_dev->dev = dev;

rknpu_dev->iommu_en = rknpu_is_iommu_enable(dev);
if (!rknpu_dev->iommu_en) {
if (rknpu_dev->iommu_en) {
rknpu_dev->iommu_group = iommu_group_get(dev);
if (!rknpu_dev->iommu_group)
return -EINVAL;
} else {
/* Initialize reserved memory resources */
ret = of_reserved_mem_device_init(dev);
if (!ret) {
Expand Down Expand Up @@ -1226,6 +1268,7 @@ static int rknpu_probe(struct platform_device *pdev)
spin_lock_init(&rknpu_dev->irq_lock);
mutex_init(&rknpu_dev->power_lock);
mutex_init(&rknpu_dev->reset_lock);
mutex_init(&rknpu_dev->domain_lock);
for (i = 0; i < config->num_irqs; i++) {
INIT_LIST_HEAD(&rknpu_dev->subcore_datas[i].todo_list);
init_waitqueue_head(&rknpu_dev->subcore_datas[i].job_done_wq);
Expand Down Expand Up @@ -1365,6 +1408,9 @@ static int rknpu_probe(struct platform_device *pdev)
rknpu_dev->config->nbuf_size > 0)
rknpu_find_nbuf_resource(rknpu_dev);

if (rknpu_dev->iommu_en)
rknpu_iommu_init_domain(rknpu_dev);

rknpu_power_off(rknpu_dev);
atomic_set(&rknpu_dev->power_refcount, 0);
atomic_set(&rknpu_dev->cmdline_power_refcount, 0);
Expand Down Expand Up @@ -1401,9 +1447,6 @@ static int rknpu_remove(struct platform_device *pdev)
cancel_delayed_work_sync(&rknpu_dev->power_off_work);
destroy_workqueue(rknpu_dev->power_off_wq);

if (IS_ENABLED(CONFIG_ROCKCHIP_RKNPU_SRAM) && rknpu_dev->sram_mm)
rknpu_mm_destroy(rknpu_dev->sram_mm);

rknpu_debugger_remove(rknpu_dev);
rknpu_cancel_timer(rknpu_dev);

Expand All @@ -1412,6 +1455,14 @@ static int rknpu_remove(struct platform_device *pdev)
WARN_ON(!list_empty(&rknpu_dev->subcore_datas[i].todo_list));
}

if (IS_ENABLED(CONFIG_ROCKCHIP_RKNPU_SRAM) && rknpu_dev->sram_mm)
rknpu_mm_destroy(rknpu_dev->sram_mm);

if (rknpu_dev->iommu_en) {
rknpu_iommu_free_domains(rknpu_dev);
iommu_group_put(rknpu_dev->iommu_group);
}

#ifdef CONFIG_ROCKCHIP_RKNPU_DRM_GEM
rknpu_drm_remove(rknpu_dev);
#endif
Expand Down
Loading

0 comments on commit c0fc087

Please sign in to comment.