From 1208acba8a05d0521c9fbd8a7ee02af8ba6badbd Mon Sep 17 00:00:00 2001 From: ljf Date: Thu, 15 May 2014 09:58:53 +0800 Subject: [PATCH] rk3288: enable iep iommu mode when iommu driver available --- drivers/video/rockchip/iep/hw_iep_reg.c | 62 +++++++++---------------- drivers/video/rockchip/iep/iep_drv.c | 20 ++++++-- drivers/video/rockchip/iep/iep_drv.h | 2 +- 3 files changed, 39 insertions(+), 45 deletions(-) diff --git a/drivers/video/rockchip/iep/hw_iep_reg.c b/drivers/video/rockchip/iep/hw_iep_reg.c index 175ae424e9c1..0552a3984fe7 100755 --- a/drivers/video/rockchip/iep/hw_iep_reg.c +++ b/drivers/video/rockchip/iep/hw_iep_reg.c @@ -1128,16 +1128,12 @@ static int iep_bufid_to_iova(iep_service_info *pservice, u8 *tbl, int size, stru } for (i=0; ireg[addr_tbl_vpu_dec[i]], sizeof(usr_fd))) - return -EFAULT; -#else usr_fd = reg->reg[tbl[i]] & 0x3FF; offset = reg->reg[tbl[i]] >> 10; - -#endif if (usr_fd != 0) { struct ion_handle *hdl; + int ret; + struct iep_mem_region *mem_region; hdl = ion_import_dma_buf(pservice->ion_client, usr_fd); if (IS_ERR(hdl)) { @@ -1145,43 +1141,27 @@ static int iep_bufid_to_iova(iep_service_info *pservice, u8 *tbl, int size, stru return PTR_ERR(hdl); } -#if 0 - { - ion_phys_addr_t phy_addr; - size_t len; - ion_phys(pservice->ion_client, hdl, &phy_addr, &len); - - reg->reg[tbl[i]] = phy_addr + offset; - + mem_region = kzalloc(sizeof(struct iep_mem_region), GFP_KERNEL); + + if (mem_region == NULL) { + dev_err(pservice->iommu_dev, "allocate memory for iommu memory region failed\n"); ion_free(pservice->ion_client, hdl); + return -1; } -#else - { - int ret; - struct iep_mem_region *mem_region; - mem_region = kzalloc(sizeof(struct iep_mem_region), GFP_KERNEL); - - if (mem_region == NULL) { - dev_err(pservice->iommu_dev, "allocate memory for iommu memory region failed\n"); - ion_free(pservice->ion_client, hdl); - return -1; - } - - mem_region->hdl = hdl; - - ret = ion_map_iommu(pservice->iommu_dev, pservice->ion_client, mem_region->hdl, &mem_region->iova, &mem_region->len); - if (ret < 0) { - dev_err(pservice->iommu_dev, "ion map iommu failed\n"); - kfree(mem_region); - ion_free(pservice->ion_client, hdl); - return ret; - } - - reg->reg[tbl[i]] = mem_region->iova + offset; - INIT_LIST_HEAD(&mem_region->reg_lnk); - list_add_tail(&mem_region->reg_lnk, ®->mem_region_list); + + mem_region->hdl = hdl; + + ret = ion_map_iommu(pservice->iommu_dev, pservice->ion_client, mem_region->hdl, &mem_region->iova, &mem_region->len); + if (ret < 0) { + dev_err(pservice->iommu_dev, "ion map iommu failed\n"); + kfree(mem_region); + ion_free(pservice->ion_client, hdl); + return ret; } -#endif + + reg->reg[tbl[i]] = mem_region->iova + offset; + INIT_LIST_HEAD(&mem_region->reg_lnk); + list_add_tail(&mem_region->reg_lnk, ®->mem_region_list); } } @@ -1270,7 +1250,7 @@ void iep_config(iep_session *session, IEP_MSG *iep_msg) #if defined(CONFIG_IEP_IOMMU) if (0 > iep_reg_address_translate(&iep_service, reg)) { - pr_err("error: translate reg address failed\n"); + IEP_ERR("error: translate reg address failed\n"); kfree(reg); return; } diff --git a/drivers/video/rockchip/iep/iep_drv.c b/drivers/video/rockchip/iep/iep_drv.c index 7135b7bd0ca3..d5c8d96b1025 100755 --- a/drivers/video/rockchip/iep/iep_drv.c +++ b/drivers/video/rockchip/iep/iep_drv.c @@ -218,6 +218,13 @@ static void iep_power_on(void) #endif wake_lock(&iep_drvdata1->wake_lock); + +#if defined(CONFIG_IEP_IOMMU) + if (iep_service.iommu_dev) { + iovmm_activate(iep_service.iommu_dev); + } +#endif + iep_service.enable = true; } @@ -238,6 +245,12 @@ static void iep_power_off(void) IEP_WARNING("delay 50 ms for running task\n"); iep_dump(); } + +#if defined(CONFIG_IEP_IOMMU) + if (iep_service.iommu_dev) { + iovmm_deactivate(iep_service.iommu_dev); + } +#endif #ifdef IEP_CLK_ENABLE clk_disable_unprepare(iep_drvdata1->aclk_iep); @@ -870,16 +883,17 @@ static int iep_drv_probe(struct platform_device *pdev) } #if defined(CONFIG_IEP_IOMMU) + iep_service.iommu_dev = NULL; iep_power_on(); iep_service.ion_client = rockchip_ion_client_create("iep"); if (IS_ERR(iep_service.ion_client)) { - dev_err(&pdev->dev, "failed to create ion client for vcodec"); + IEP_ERR("failed to create ion client for vcodec"); return PTR_ERR(iep_service.ion_client); } else { - dev_info(&pdev->dev, "vcodec ion client create success!\n"); + IEP_INFO("iep ion client create success!\n"); } - mmu_dev = rockchip_get_sysmmu_device_by_compatible("iommu,iep"); + mmu_dev = rockchip_get_sysmmu_device_by_compatible("iommu,iep_mmu"); if (mmu_dev) { platform_set_sysmmu(mmu_dev, &pdev->dev); diff --git a/drivers/video/rockchip/iep/iep_drv.h b/drivers/video/rockchip/iep/iep_drv.h index 39c650a6a4fd..e0e40baccf91 100755 --- a/drivers/video/rockchip/iep/iep_drv.h +++ b/drivers/video/rockchip/iep/iep_drv.h @@ -6,7 +6,7 @@ #include #if defined(CONFIG_ROCKCHIP_IOMMU) && defined(CONFIG_ION_ROCKCHIP) -//#define CONFIG_IEP_IOMMU +#define CONFIG_IEP_IOMMU #endif #ifdef CONFIG_IEP_IOMMU -- 2.34.1