CHROMIUM: [media] rockchip-vpu: add dma-iommu support on arm64
authorJeffy Chen <jeffy.chen@rock-chips.com>
Wed, 1 Jun 2016 09:12:58 +0000 (17:12 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Thu, 30 Jun 2016 12:02:47 +0000 (20:02 +0800)
Change-Id: Ieeaed0320202a6d056b6c248d5b72df2419bf29c
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
Signed-off-by: Yakir Yang <ykk@rock-chips.com>
drivers/media/platform/rockchip-vpu/rk3288_vpu_common.h
drivers/media/platform/rockchip-vpu/rk3288_vpu_hw.c

index 5bafbc12b943d6955973f1eaa20b9ccd4dc84d64..3ff5c69992b6195d3559b85c79899867ce518d4c 100644 (file)
@@ -147,6 +147,7 @@ enum rk3288_vpu_state {
  * @enc_base:          Mapped address of VPU encoder register for convenience.
  * @dec_base:          Mapped address of VPU decoder register for convenience.
  * @mapping:           DMA IOMMU mapping.
  * @enc_base:          Mapped address of VPU encoder register for convenience.
  * @dec_base:          Mapped address of VPU decoder register for convenience.
  * @mapping:           DMA IOMMU mapping.
+ * @domain:            DMA IOMMU domain.
  * @vpu_mutex:         Mutex to synchronize V4L2 calls.
  * @irqlock:           Spinlock to synchronize access to data structures
  *                     shared with interrupt handlers.
  * @vpu_mutex:         Mutex to synchronize V4L2 calls.
  * @irqlock:           Spinlock to synchronize access to data structures
  *                     shared with interrupt handlers.
@@ -176,6 +177,7 @@ struct rk3288_vpu_dev {
        void __iomem *enc_base;
        void __iomem *dec_base;
        struct dma_iommu_mapping *mapping;
        void __iomem *enc_base;
        void __iomem *dec_base;
        struct dma_iommu_mapping *mapping;
+       struct iommu_domain *domain;
 
        struct mutex vpu_mutex; /* video_device lock */
        spinlock_t irqlock;
 
        struct mutex vpu_mutex; /* video_device lock */
        spinlock_t irqlock;
index 8ca8b9abd548cde9e974bf9ae0595ec6bab321b6..531fc523647db3ab10a80fc65f996964cb630615 100644 (file)
@@ -28,7 +28,7 @@
 #include <linux/of.h>
 #include <linux/of_platform.h>
 
 #include <linux/of.h>
 #include <linux/of_platform.h>
 
-#include <asm/dma-iommu.h>
+#include <linux/dma-iommu.h>
 
 #include "rk3288_vpu_regs.h"
 
 
 #include "rk3288_vpu_regs.h"
 
@@ -203,45 +203,57 @@ static int rk3288_vpu_iommu_init(struct rk3288_vpu_dev *vpu)
 {
        int ret;
 
 {
        int ret;
 
-       vpu->mapping = arm_iommu_create_mapping(&platform_bus_type,
-                                               0x10000000, SZ_2G);
-       if (IS_ERR(vpu->mapping)) {
-               ret = PTR_ERR(vpu->mapping);
-               return ret;
-       }
-
        vpu->dev->dma_parms = devm_kzalloc(vpu->dev,
        vpu->dev->dma_parms = devm_kzalloc(vpu->dev,
-                               sizeof(*vpu->dev->dma_parms), GFP_KERNEL);
+                                          sizeof(*vpu->dev->dma_parms),
+                                          GFP_KERNEL);
        if (!vpu->dev->dma_parms)
        if (!vpu->dev->dma_parms)
-               goto err_release_mapping;
+               return -ENOMEM;
 
 
-       dma_set_max_seg_size(vpu->dev, 0xffffffffu);
+       vpu->domain = iommu_domain_alloc(vpu->dev->bus);
+       if (!vpu->domain)
+               goto err_free_parms;
 
 
-       ret = arm_iommu_attach_device(vpu->dev, vpu->mapping);
+       ret = iommu_get_dma_cookie(vpu->domain);
        if (ret)
        if (ret)
-               goto err_release_mapping;
+               goto err_free_domain;
 
 
-       return 0;
+       ret = dma_set_coherent_mask(vpu->dev, DMA_BIT_MASK(32));
+       if (ret)
+               goto err_put_cookie;
 
 
-err_release_mapping:
-       arm_iommu_release_mapping(vpu->mapping);
+       dma_set_max_seg_size(vpu->dev, DMA_BIT_MASK(32));
+
+       ret = iommu_attach_device(vpu->domain, vpu->dev);
+       if (ret)
+               goto err_put_cookie;
+
+       common_iommu_setup_dma_ops(vpu->dev, 0x10000000, SZ_2G,
+                                  vpu->domain->ops);
+
+       return 0;
 
 
+err_put_cookie:
+       iommu_put_dma_cookie(vpu->domain);
+err_free_domain:
+       iommu_domain_free(vpu->domain);
+err_free_parms:
        return ret;
 }
 
 static void rk3288_vpu_iommu_cleanup(struct rk3288_vpu_dev *vpu)
 {
        return ret;
 }
 
 static void rk3288_vpu_iommu_cleanup(struct rk3288_vpu_dev *vpu)
 {
-       arm_iommu_detach_device(vpu->dev);
-       arm_iommu_release_mapping(vpu->mapping);
+       iommu_detach_device(vpu->domain, vpu->dev);
+       iommu_put_dma_cookie(vpu->domain);
+       iommu_domain_free(vpu->domain);
 }
 }
-#else
+#else /* CONFIG_ROCKCHIP_IOMMU */
 static inline int rk3288_vpu_iommu_init(struct rk3288_vpu_dev *vpu)
 {
        return 0;
 }
 
 static inline void rk3288_vpu_iommu_cleanup(struct rk3288_vpu_dev *vpu) { }
 static inline int rk3288_vpu_iommu_init(struct rk3288_vpu_dev *vpu)
 {
        return 0;
 }
 
 static inline void rk3288_vpu_iommu_cleanup(struct rk3288_vpu_dev *vpu) { }
-#endif
+#endif /* CONFIG_ROCKCHIP_IOMMU */
 
 int rk3288_vpu_hw_probe(struct rk3288_vpu_dev *vpu)
 {
 
 int rk3288_vpu_hw_probe(struct rk3288_vpu_dev *vpu)
 {