Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iommu/omap: eliminate the public omap_find_iommu_device() method

Eliminate the public omap_find_iommu_device() method, and don't
expect clients to provide the omap_iommu handle anymore.

Instead, OMAP's iommu driver now utilizes dev_archdata's private iommu
extension to be able to access the required iommu information.

This way OMAP IOMMU users are now able to use the generic IOMMU API without
having to call any omap-specific binding method.

Update omap3isp appropriately.

Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
Acked-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Acked-by: Tony Lindgren <tony@atomide.com>
Cc: Hiroshi Doyu <hdoyu@nvidia.com>

+74 -94
+2 -3
arch/arm/plat-omap/include/plat/iommu.h
··· 189 189 void *priv), 190 190 void *isr_priv); 191 191 192 - extern void omap_iommu_save_ctx(struct omap_iommu *obj); 193 - extern void omap_iommu_restore_ctx(struct omap_iommu *obj); 192 + extern void omap_iommu_save_ctx(struct device *dev); 193 + extern void omap_iommu_restore_ctx(struct device *dev); 194 194 195 195 extern int omap_install_iommu_arch(const struct iommu_functions *ops); 196 196 extern void omap_uninstall_iommu_arch(const struct iommu_functions *ops); ··· 202 202 omap_iommu_dump_ctx(struct omap_iommu *obj, char *buf, ssize_t len); 203 203 extern size_t 204 204 omap_dump_tlb_entries(struct omap_iommu *obj, char *buf, ssize_t len); 205 - struct device *omap_find_iommu_device(const char *name); 206 205 207 206 #endif /* __MACH_IOMMU_H */
+6 -6
arch/arm/plat-omap/include/plat/iovmm.h
··· 72 72 #define IOVMF_DA_FIXED (1 << (4 + IOVMF_SW_SHIFT)) 73 73 74 74 75 - extern struct iovm_struct *omap_find_iovm_area(struct omap_iommu *obj, u32 da); 75 + extern struct iovm_struct *omap_find_iovm_area(struct device *dev, u32 da); 76 76 extern u32 77 - omap_iommu_vmap(struct iommu_domain *domain, struct omap_iommu *obj, u32 da, 77 + omap_iommu_vmap(struct iommu_domain *domain, struct device *dev, u32 da, 78 78 const struct sg_table *sgt, u32 flags); 79 79 extern struct sg_table *omap_iommu_vunmap(struct iommu_domain *domain, 80 - struct omap_iommu *obj, u32 da); 80 + struct device *dev, u32 da); 81 81 extern u32 82 - omap_iommu_vmalloc(struct iommu_domain *domain, struct omap_iommu *obj, 82 + omap_iommu_vmalloc(struct iommu_domain *domain, struct device *dev, 83 83 u32 da, size_t bytes, u32 flags); 84 84 extern void 85 - omap_iommu_vfree(struct iommu_domain *domain, struct omap_iommu *obj, 85 + omap_iommu_vfree(struct iommu_domain *domain, struct device *dev, 86 86 const u32 da); 87 - extern void *omap_da_to_va(struct omap_iommu *obj, u32 da); 87 + extern void *omap_da_to_va(struct device *dev, u32 da); 88 88 89 89 #endif /* __IOMMU_MMAP_H */
+26 -32
drivers/iommu/omap-iommu.c
··· 86 86 87 87 /** 88 88 * omap_iommu_save_ctx - Save registers for pm off-mode support 89 - * @obj: target iommu 89 + * @dev: client device 90 90 **/ 91 - void omap_iommu_save_ctx(struct omap_iommu *obj) 91 + void omap_iommu_save_ctx(struct device *dev) 92 92 { 93 + struct omap_iommu *obj = dev_to_omap_iommu(dev); 94 + 93 95 arch_iommu->save_ctx(obj); 94 96 } 95 97 EXPORT_SYMBOL_GPL(omap_iommu_save_ctx); 96 98 97 99 /** 98 100 * omap_iommu_restore_ctx - Restore registers for pm off-mode support 99 - * @obj: target iommu 101 + * @dev: client device 100 102 **/ 101 - void omap_iommu_restore_ctx(struct omap_iommu *obj) 103 + void omap_iommu_restore_ctx(struct device *dev) 102 104 { 105 + struct omap_iommu *obj = dev_to_omap_iommu(dev); 106 + 103 107 arch_iommu->restore_ctx(obj); 104 108 } 105 109 EXPORT_SYMBOL_GPL(omap_iommu_restore_ctx); ··· 824 820 } 825 821 826 822 /** 827 - * omap_find_iommu_device() - find an omap iommu device by name 828 - * @name: name of the iommu device 829 - * 830 - * The generic iommu API requires the caller to provide the device 831 - * he wishes to attach to a certain iommu domain. 832 - * 833 - * Drivers generally should not bother with this as it should just 834 - * be taken care of by the DMA-API using dev_archdata. 835 - * 836 - * This function is provided as an interim solution until the latter 837 - * materializes, and omap3isp is fully migrated to the DMA-API. 838 - */ 839 - struct device *omap_find_iommu_device(const char *name) 840 - { 841 - return driver_find_device(&omap_iommu_driver.driver, NULL, 842 - (void *)name, 843 - device_match_by_alias); 844 - } 845 - EXPORT_SYMBOL_GPL(omap_find_iommu_device); 846 - 847 - /** 848 823 * omap_iommu_attach() - attach iommu device to an iommu domain 849 - * @dev: target omap iommu device 824 + * @name: name of target omap iommu device 850 825 * @iopgd: page table 851 826 **/ 852 - static struct omap_iommu *omap_iommu_attach(struct device *dev, u32 *iopgd) 827 + static struct omap_iommu *omap_iommu_attach(const char *name, u32 *iopgd) 853 828 { 854 829 int err = -ENOMEM; 855 - struct omap_iommu *obj = to_iommu(dev); 830 + struct device *dev; 831 + struct omap_iommu *obj; 832 + 833 + dev = driver_find_device(&omap_iommu_driver.driver, NULL, 834 + (void *)name, 835 + device_match_by_alias); 836 + if (!dev) 837 + return NULL; 838 + 839 + obj = to_iommu(dev); 856 840 857 841 spin_lock(&obj->iommu_lock); 858 842 ··· 1061 1069 { 1062 1070 struct omap_iommu_domain *omap_domain = domain->priv; 1063 1071 struct omap_iommu *oiommu; 1072 + struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; 1064 1073 int ret = 0; 1065 1074 1066 1075 spin_lock(&omap_domain->lock); ··· 1074 1081 } 1075 1082 1076 1083 /* get a handle to and enable the omap iommu */ 1077 - oiommu = omap_iommu_attach(dev, omap_domain->pgtable); 1084 + oiommu = omap_iommu_attach(arch_data->name, omap_domain->pgtable); 1078 1085 if (IS_ERR(oiommu)) { 1079 1086 ret = PTR_ERR(oiommu); 1080 1087 dev_err(dev, "can't get omap iommu: %d\n", ret); 1081 1088 goto out; 1082 1089 } 1083 1090 1084 - omap_domain->iommu_dev = oiommu; 1091 + omap_domain->iommu_dev = arch_data->iommu_dev = oiommu; 1085 1092 oiommu->domain = domain; 1086 1093 1087 1094 out: ··· 1093 1100 struct device *dev) 1094 1101 { 1095 1102 struct omap_iommu_domain *omap_domain = domain->priv; 1096 - struct omap_iommu *oiommu = to_iommu(dev); 1103 + struct omap_iommu_arch_data *arch_data = dev->archdata.iommu; 1104 + struct omap_iommu *oiommu = dev_to_omap_iommu(dev); 1097 1105 1098 1106 spin_lock(&omap_domain->lock); 1099 1107 ··· 1108 1114 1109 1115 omap_iommu_detach(oiommu); 1110 1116 1111 - omap_domain->iommu_dev = NULL; 1117 + omap_domain->iommu_dev = arch_data->iommu_dev = NULL; 1112 1118 1113 1119 out: 1114 1120 spin_unlock(&omap_domain->lock);
+20 -11
drivers/iommu/omap-iovmm.c
··· 231 231 232 232 /** 233 233 * omap_find_iovm_area - find iovma which includes @da 234 + * @dev: client device 234 235 * @da: iommu device virtual address 235 236 * 236 237 * Find the existing iovma starting at @da 237 238 */ 238 - struct iovm_struct *omap_find_iovm_area(struct omap_iommu *obj, u32 da) 239 + struct iovm_struct *omap_find_iovm_area(struct device *dev, u32 da) 239 240 { 241 + struct omap_iommu *obj = dev_to_omap_iommu(dev); 240 242 struct iovm_struct *area; 241 243 242 244 mutex_lock(&obj->mmap_lock); ··· 345 343 346 344 /** 347 345 * omap_da_to_va - convert (d) to (v) 348 - * @obj: objective iommu 346 + * @dev: client device 349 347 * @da: iommu device virtual address 350 348 * @va: mpu virtual address 351 349 * 352 350 * Returns mpu virtual addr which corresponds to a given device virtual addr 353 351 */ 354 - void *omap_da_to_va(struct omap_iommu *obj, u32 da) 352 + void *omap_da_to_va(struct device *dev, u32 da) 355 353 { 354 + struct omap_iommu *obj = dev_to_omap_iommu(dev); 356 355 void *va = NULL; 357 356 struct iovm_struct *area; 358 357 ··· 585 582 586 583 /** 587 584 * omap_iommu_vmap - (d)-(p)-(v) address mapper 588 - * @obj: objective iommu 585 + * @domain: iommu domain 586 + * @dev: client device 589 587 * @sgt: address of scatter gather table 590 588 * @flags: iovma and page property 591 589 * 592 590 * Creates 1-n-1 mapping with given @sgt and returns @da. 593 591 * All @sgt element must be io page size aligned. 594 592 */ 595 - u32 omap_iommu_vmap(struct iommu_domain *domain, struct omap_iommu *obj, u32 da, 593 + u32 omap_iommu_vmap(struct iommu_domain *domain, struct device *dev, u32 da, 596 594 const struct sg_table *sgt, u32 flags) 597 595 { 596 + struct omap_iommu *obj = dev_to_omap_iommu(dev); 598 597 size_t bytes; 599 598 void *va = NULL; 600 599 ··· 627 622 628 623 /** 629 624 * omap_iommu_vunmap - release virtual mapping obtained by 'omap_iommu_vmap()' 630 - * @obj: objective iommu 625 + * @domain: iommu domain 626 + * @dev: client device 631 627 * @da: iommu device virtual address 632 628 * 633 629 * Free the iommu virtually contiguous memory area starting at 634 630 * @da, which was returned by 'omap_iommu_vmap()'. 635 631 */ 636 632 struct sg_table * 637 - omap_iommu_vunmap(struct iommu_domain *domain, struct omap_iommu *obj, u32 da) 633 + omap_iommu_vunmap(struct iommu_domain *domain, struct device *dev, u32 da) 638 634 { 635 + struct omap_iommu *obj = dev_to_omap_iommu(dev); 639 636 struct sg_table *sgt; 640 637 /* 641 638 * 'sgt' is allocated before 'omap_iommu_vmalloc()' is called. ··· 654 647 655 648 /** 656 649 * omap_iommu_vmalloc - (d)-(p)-(v) address allocator and mapper 657 - * @obj: objective iommu 650 + * @dev: client device 658 651 * @da: contiguous iommu virtual memory 659 652 * @bytes: allocation size 660 653 * @flags: iovma and page property ··· 663 656 * @da again, which might be adjusted if 'IOVMF_DA_FIXED' is not set. 664 657 */ 665 658 u32 666 - omap_iommu_vmalloc(struct iommu_domain *domain, struct omap_iommu *obj, u32 da, 659 + omap_iommu_vmalloc(struct iommu_domain *domain, struct device *dev, u32 da, 667 660 size_t bytes, u32 flags) 668 661 { 662 + struct omap_iommu *obj = dev_to_omap_iommu(dev); 669 663 void *va; 670 664 struct sg_table *sgt; 671 665 ··· 706 698 707 699 /** 708 700 * omap_iommu_vfree - release memory allocated by 'omap_iommu_vmalloc()' 709 - * @obj: objective iommu 701 + * @dev: client device 710 702 * @da: iommu device virtual address 711 703 * 712 704 * Frees the iommu virtually continuous memory area starting at 713 705 * @da, as obtained from 'omap_iommu_vmalloc()'. 714 706 */ 715 - void omap_iommu_vfree(struct iommu_domain *domain, struct omap_iommu *obj, 707 + void omap_iommu_vfree(struct iommu_domain *domain, struct device *dev, 716 708 const u32 da) 717 709 { 710 + struct omap_iommu *obj = dev_to_omap_iommu(dev); 718 711 struct sg_table *sgt; 719 712 720 713 sgt = unmap_vm_area(domain, obj, da, vfree,
+5 -25
drivers/media/video/omap3isp/isp.c
··· 80 80 #include "isph3a.h" 81 81 #include "isphist.h" 82 82 83 - /* 84 - * this is provided as an interim solution until omap3isp doesn't need 85 - * any omap-specific iommu API 86 - */ 87 - #define to_iommu(dev) \ 88 - (struct omap_iommu *)platform_get_drvdata(to_platform_device(dev)) 89 - 90 83 static unsigned int autoidle; 91 84 module_param(autoidle, int, 0444); 92 85 MODULE_PARM_DESC(autoidle, "Enable OMAP3ISP AUTOIDLE support"); ··· 1107 1114 static void isp_save_ctx(struct isp_device *isp) 1108 1115 { 1109 1116 isp_save_context(isp, isp_reg_list); 1110 - if (isp->iommu) 1111 - omap_iommu_save_ctx(isp->iommu); 1117 + omap_iommu_save_ctx(isp->dev); 1112 1118 } 1113 1119 1114 1120 /* ··· 1120 1128 static void isp_restore_ctx(struct isp_device *isp) 1121 1129 { 1122 1130 isp_restore_context(isp, isp_reg_list); 1123 - if (isp->iommu) 1124 - omap_iommu_restore_ctx(isp->iommu); 1131 + omap_iommu_restore_ctx(isp->dev); 1125 1132 omap3isp_ccdc_restore_context(isp); 1126 1133 omap3isp_preview_restore_context(isp); 1127 1134 } ··· 1974 1983 isp_cleanup_modules(isp); 1975 1984 1976 1985 omap3isp_get(isp); 1977 - iommu_detach_device(isp->domain, isp->iommu_dev); 1986 + iommu_detach_device(isp->domain, &pdev->dev); 1978 1987 iommu_domain_free(isp->domain); 1979 1988 omap3isp_put(isp); 1980 1989 ··· 2122 2131 } 2123 2132 } 2124 2133 2125 - /* IOMMU */ 2126 - isp->iommu_dev = omap_find_iommu_device("isp"); 2127 - if (!isp->iommu_dev) { 2128 - dev_err(isp->dev, "omap_find_iommu_device failed\n"); 2129 - ret = -ENODEV; 2130 - goto error_isp; 2131 - } 2132 - 2133 - /* to be removed once iommu migration is complete */ 2134 - isp->iommu = to_iommu(isp->iommu_dev); 2135 - 2136 2134 isp->domain = iommu_domain_alloc(pdev->dev.bus); 2137 2135 if (!isp->domain) { 2138 2136 dev_err(isp->dev, "can't alloc iommu domain\n"); ··· 2129 2149 goto error_isp; 2130 2150 } 2131 2151 2132 - ret = iommu_attach_device(isp->domain, isp->iommu_dev); 2152 + ret = iommu_attach_device(isp->domain, &pdev->dev); 2133 2153 if (ret) { 2134 2154 dev_err(&pdev->dev, "can't attach iommu device: %d\n", ret); 2135 2155 goto free_domain; ··· 2168 2188 error_irq: 2169 2189 free_irq(isp->irq_num, isp); 2170 2190 detach_dev: 2171 - iommu_detach_device(isp->domain, isp->iommu_dev); 2191 + iommu_detach_device(isp->domain, &pdev->dev); 2172 2192 free_domain: 2173 2193 iommu_domain_free(isp->domain); 2174 2194 error_isp:
-2
drivers/media/video/omap3isp/isp.h
··· 212 212 unsigned int sbl_resources; 213 213 unsigned int subclk_resources; 214 214 215 - struct omap_iommu *iommu; 216 215 struct iommu_domain *domain; 217 - struct device *iommu_dev; 218 216 219 217 struct isp_platform_callback platform_cb; 220 218 };
+9 -9
drivers/media/video/omap3isp/ispccdc.c
··· 366 366 dma_unmap_sg(isp->dev, req->iovm->sgt->sgl, 367 367 req->iovm->sgt->nents, DMA_TO_DEVICE); 368 368 if (req->table) 369 - omap_iommu_vfree(isp->domain, isp->iommu, req->table); 369 + omap_iommu_vfree(isp->domain, isp->dev, req->table); 370 370 kfree(req); 371 371 } 372 372 ··· 438 438 439 439 req->enable = 1; 440 440 441 - req->table = omap_iommu_vmalloc(isp->domain, isp->iommu, 0, 441 + req->table = omap_iommu_vmalloc(isp->domain, isp->dev, 0, 442 442 req->config.size, IOMMU_FLAG); 443 443 if (IS_ERR_VALUE(req->table)) { 444 444 req->table = 0; ··· 446 446 goto done; 447 447 } 448 448 449 - req->iovm = omap_find_iovm_area(isp->iommu, req->table); 449 + req->iovm = omap_find_iovm_area(isp->dev, req->table); 450 450 if (req->iovm == NULL) { 451 451 ret = -ENOMEM; 452 452 goto done; ··· 462 462 dma_sync_sg_for_cpu(isp->dev, req->iovm->sgt->sgl, 463 463 req->iovm->sgt->nents, DMA_TO_DEVICE); 464 464 465 - table = omap_da_to_va(isp->iommu, req->table); 465 + table = omap_da_to_va(isp->dev, req->table); 466 466 if (copy_from_user(table, config->lsc, req->config.size)) { 467 467 ret = -EFAULT; 468 468 goto done; ··· 734 734 * already done by omap_iommu_vmalloc(). 735 735 */ 736 736 size = ccdc->fpc.fpnum * 4; 737 - table_new = omap_iommu_vmalloc(isp->domain, isp->iommu, 737 + table_new = omap_iommu_vmalloc(isp->domain, isp->dev, 738 738 0, size, IOMMU_FLAG); 739 739 if (IS_ERR_VALUE(table_new)) 740 740 return -ENOMEM; 741 741 742 - if (copy_from_user(omap_da_to_va(isp->iommu, table_new), 742 + if (copy_from_user(omap_da_to_va(isp->dev, table_new), 743 743 (__force void __user *) 744 744 ccdc->fpc.fpcaddr, size)) { 745 - omap_iommu_vfree(isp->domain, isp->iommu, 745 + omap_iommu_vfree(isp->domain, isp->dev, 746 746 table_new); 747 747 return -EFAULT; 748 748 } ··· 753 753 754 754 ccdc_configure_fpc(ccdc); 755 755 if (table_old != 0) 756 - omap_iommu_vfree(isp->domain, isp->iommu, table_old); 756 + omap_iommu_vfree(isp->domain, isp->dev, table_old); 757 757 } 758 758 759 759 return ccdc_lsc_config(ccdc, ccdc_struct); ··· 2309 2309 ccdc_lsc_free_queue(ccdc, &ccdc->lsc.free_queue); 2310 2310 2311 2311 if (ccdc->fpc.fpcaddr != 0) 2312 - omap_iommu_vfree(isp->domain, isp->iommu, ccdc->fpc.fpcaddr); 2312 + omap_iommu_vfree(isp->domain, isp->dev, ccdc->fpc.fpcaddr); 2313 2313 2314 2314 mutex_destroy(&ccdc->ioctl_lock); 2315 2315 }
+4 -4
drivers/media/video/omap3isp/ispstat.c
··· 366 366 dma_unmap_sg(isp->dev, buf->iovm->sgt->sgl, 367 367 buf->iovm->sgt->nents, 368 368 DMA_FROM_DEVICE); 369 - omap_iommu_vfree(isp->domain, isp->iommu, 369 + omap_iommu_vfree(isp->domain, isp->dev, 370 370 buf->iommu_addr); 371 371 } else { 372 372 if (!buf->virt_addr) ··· 400 400 struct iovm_struct *iovm; 401 401 402 402 WARN_ON(buf->dma_addr); 403 - buf->iommu_addr = omap_iommu_vmalloc(isp->domain, isp->iommu, 0, 403 + buf->iommu_addr = omap_iommu_vmalloc(isp->domain, isp->dev, 0, 404 404 size, IOMMU_FLAG); 405 405 if (IS_ERR((void *)buf->iommu_addr)) { 406 406 dev_err(stat->isp->dev, ··· 410 410 return -ENOMEM; 411 411 } 412 412 413 - iovm = omap_find_iovm_area(isp->iommu, buf->iommu_addr); 413 + iovm = omap_find_iovm_area(isp->dev, buf->iommu_addr); 414 414 if (!iovm || 415 415 !dma_map_sg(isp->dev, iovm->sgt->sgl, iovm->sgt->nents, 416 416 DMA_FROM_DEVICE)) { ··· 419 419 } 420 420 buf->iovm = iovm; 421 421 422 - buf->virt_addr = omap_da_to_va(stat->isp->iommu, 422 + buf->virt_addr = omap_da_to_va(stat->isp->dev, 423 423 (u32)buf->iommu_addr); 424 424 buf->empty = 1; 425 425 dev_dbg(stat->isp->dev, "%s: buffer[%d] allocated."
+2 -2
drivers/media/video/omap3isp/ispvideo.c
··· 452 452 sgt->nents = sglen; 453 453 sgt->orig_nents = sglen; 454 454 455 - da = omap_iommu_vmap(isp->domain, isp->iommu, 0, sgt, IOMMU_FLAG); 455 + da = omap_iommu_vmap(isp->domain, isp->dev, 0, sgt, IOMMU_FLAG); 456 456 if (IS_ERR_VALUE(da)) 457 457 kfree(sgt); 458 458 ··· 468 468 { 469 469 struct sg_table *sgt; 470 470 471 - sgt = omap_iommu_vunmap(isp->domain, isp->iommu, (u32)da); 471 + sgt = omap_iommu_vunmap(isp->domain, isp->dev, (u32)da); 472 472 kfree(sgt); 473 473 } 474 474