hc
2023-12-06 08f87f769b595151be1afeff53e144f543faa614
kernel/drivers/video/rockchip/mpp/mpp_vdpu2.c
....@@ -20,8 +20,6 @@
2020 #include <linux/uaccess.h>
2121 #include <linux/regmap.h>
2222 #include <linux/proc_fs.h>
23
-#include <linux/mfd/syscon.h>
24
-#include <linux/rockchip/cpu.h>
2523 #include <soc/rockchip/pm_domains.h>
2624
2725 #include "mpp_debug.h"
....@@ -113,7 +111,6 @@
113111 #endif
114112 struct reset_control *rst_a;
115113 struct reset_control *rst_h;
116
- struct regmap *grf;
117114 };
118115
119116 static struct mpp_hw_info vdpu_v2_hw_info = {
....@@ -230,8 +227,11 @@
230227 offset = task->reg[idx] >> 10 << 4;
231228 }
232229 mem_region = mpp_task_attach_fd(&task->mpp_task, fd);
233
- if (IS_ERR(mem_region))
230
+ if (IS_ERR(mem_region)) {
231
+ mpp_err("reg[%3d]: %08x fd %d attach failed\n",
232
+ idx, task->reg[idx], fd);
234233 return -EFAULT;
234
+ }
235235
236236 iova = mem_region->iova;
237237 mpp_debug(DEBUG_IOMMU, "DMV[%3d]: %3d => %pad + offset %10d\n",
....@@ -380,6 +380,13 @@
380380 mpp_debug_leave();
381381
382382 return 0;
383
+}
384
+
385
+static int vdpu_px30_run(struct mpp_dev *mpp,
386
+ struct mpp_task *mpp_task)
387
+{
388
+ mpp_iommu_flush_tlb(mpp->iommu_info);
389
+ return vdpu_run(mpp, mpp_task);
383390 }
384391
385392 static int vdpu_finish(struct mpp_dev *mpp,
....@@ -619,12 +626,12 @@
619626 static int vdpu_soft_reset(struct mpp_dev *mpp)
620627 {
621628 u32 val;
629
+ u32 ret;
622630
623631 mpp_write(mpp, VDPU2_REG_SOFT_RESET, 1);
624
- udelay(2);
625
- val = mpp_read(mpp, VDPU2_REG_SOFT_RESET);
626
-
627
- return val;
632
+ ret = readl_relaxed_poll_timeout(mpp->reg_base + VDPU2_REG_SOFT_RESET,
633
+ val, !val, 0, 5);
634
+ return ret;
628635 }
629636
630637 static int vdpu_reset(struct mpp_dev *mpp)
....@@ -639,6 +646,7 @@
639646 ret = vdpu_soft_reset(mpp);
640647 if (ret && dec->rst_a && dec->rst_h) {
641648 /* Don't skip this or iommu won't work after reset */
649
+ mpp_err("soft reset failed, use cru reset!\n");
642650 mpp_debug(DEBUG_RESET, "reset in\n");
643651 mpp_pmu_idle_request(mpp, true);
644652 mpp_safe_reset(dec->rst_a);
....@@ -682,6 +690,16 @@
682690 .free_task = vdpu_free_task,
683691 };
684692
693
+static struct mpp_dev_ops vdpu_px30_dev_ops = {
694
+ .alloc_task = vdpu_alloc_task,
695
+ .run = vdpu_px30_run,
696
+ .irq = vdpu_irq,
697
+ .isr = vdpu_isr,
698
+ .finish = vdpu_finish,
699
+ .result = vdpu_result,
700
+ .free_task = vdpu_free_task,
701
+};
702
+
685703 static const struct mpp_dev_var vdpu_v2_data = {
686704 .device_type = MPP_DEVICE_VDPU2,
687705 .hw_info = &vdpu_v2_hw_info,
....@@ -695,7 +713,7 @@
695713 .hw_info = &vdpu_v2_hw_info,
696714 .trans_info = vdpu_v2_trans,
697715 .hw_ops = &vdpu_px30_hw_ops,
698
- .dev_ops = &vdpu_v2_dev_ops,
716
+ .dev_ops = &vdpu_px30_dev_ops,
699717 };
700718
701719 static const struct of_device_id mpp_vdpu2_dt_match[] = {
....@@ -724,15 +742,16 @@
724742 dec = devm_kzalloc(dev, sizeof(struct vdpu_dev), GFP_KERNEL);
725743 if (!dec)
726744 return -ENOMEM;
727
- platform_set_drvdata(pdev, dec);
728
-
729745 mpp = &dec->mpp;
746
+ platform_set_drvdata(pdev, mpp);
730747
731748 if (pdev->dev.of_node) {
732749 match = of_match_node(mpp_vdpu2_dt_match,
733750 pdev->dev.of_node);
734751 if (match)
735752 mpp->var = (struct mpp_dev_var *)match->data;
753
+
754
+ mpp->core_id = of_alias_get_id(pdev->dev.of_node, "vdpu");
736755 }
737756
738757 ret = mpp_dev_probe(mpp, pdev);
....@@ -768,80 +787,21 @@
768787 static int vdpu_remove(struct platform_device *pdev)
769788 {
770789 struct device *dev = &pdev->dev;
771
- struct vdpu_dev *dec = platform_get_drvdata(pdev);
790
+ struct mpp_dev *mpp = dev_get_drvdata(dev);
772791
773792 dev_info(dev, "remove device\n");
774
- mpp_dev_remove(&dec->mpp);
775
- vdpu_procfs_remove(&dec->mpp);
793
+ mpp_dev_remove(mpp);
794
+ vdpu_procfs_remove(mpp);
776795
777796 return 0;
778797 }
779
-
780
-static void vdpu_shutdown(struct platform_device *pdev)
781
-{
782
- int ret;
783
- int val;
784
- struct device *dev = &pdev->dev;
785
- struct vdpu_dev *dec = platform_get_drvdata(pdev);
786
- struct mpp_dev *mpp = &dec->mpp;
787
-
788
- dev_info(dev, "shutdown device\n");
789
-
790
- atomic_inc(&mpp->srv->shutdown_request);
791
- ret = readx_poll_timeout(atomic_read,
792
- &mpp->task_count,
793
- val, val == 0, 20000, 200000);
794
- if (ret == -ETIMEDOUT)
795
- dev_err(dev, "wait total running time out\n");
796
-}
797
-
798
-static int vdpu_runtime_suspend(struct device *dev)
799
-{
800
- struct mpp_dev *mpp = dev_get_drvdata(dev);
801
- struct mpp_grf_info *info = mpp->grf_info;
802
- struct mpp_taskqueue *queue = mpp->queue;
803
-
804
- if (cpu_is_rk3528() && info && info->mem_offset) {
805
- mutex_lock(&queue->ref_lock);
806
- if (!atomic_dec_if_positive(&queue->runtime_cnt)) {
807
- regmap_write(info->grf, info->mem_offset,
808
- info->val_mem_off);
809
- }
810
- mutex_unlock(&queue->ref_lock);
811
- }
812
-
813
- return 0;
814
-}
815
-
816
-static int vdpu_runtime_resume(struct device *dev)
817
-{
818
- struct mpp_dev *mpp = dev_get_drvdata(dev);
819
- struct mpp_grf_info *info = mpp->grf_info;
820
- struct mpp_taskqueue *queue = mpp->queue;
821
-
822
- if (cpu_is_rk3528() && info && info->mem_offset) {
823
- mutex_lock(&queue->ref_lock);
824
- regmap_write(info->grf, info->mem_offset,
825
- info->val_mem_on);
826
- atomic_inc(&queue->runtime_cnt);
827
- mutex_unlock(&queue->ref_lock);
828
- }
829
-
830
- return 0;
831
-}
832
-
833
-static const struct dev_pm_ops vdpu_pm_ops = {
834
- .runtime_suspend = vdpu_runtime_suspend,
835
- .runtime_resume = vdpu_runtime_resume,
836
-};
837798
838799 struct platform_driver rockchip_vdpu2_driver = {
839800 .probe = vdpu_probe,
840801 .remove = vdpu_remove,
841
- .shutdown = vdpu_shutdown,
802
+ .shutdown = mpp_dev_shutdown,
842803 .driver = {
843804 .name = VDPU2_DRIVER_NAME,
844
- .pm = &vdpu_pm_ops,
845805 .of_match_table = of_match_ptr(mpp_vdpu2_dt_match),
846806 },
847807 };