@@ -452,6 +452,7 @@ static int sun50i_iommu_enable(struct sun50i_iommu *iommu)
452452 IOMMU_TLB_PREFETCH_MASTER_ENABLE (3 ) |
453453 IOMMU_TLB_PREFETCH_MASTER_ENABLE (4 ) |
454454 IOMMU_TLB_PREFETCH_MASTER_ENABLE (5 ));
455+ iommu_write (iommu , IOMMU_BYPASS_REG , 0 );
455456 iommu_write (iommu , IOMMU_INT_ENABLE_REG , IOMMU_INT_MASK );
456457 iommu_write (iommu , IOMMU_DM_AUT_CTRL_REG (SUN50I_IOMMU_ACI_NONE ),
457458 IOMMU_DM_AUT_CTRL_RD_UNAVAIL (SUN50I_IOMMU_ACI_NONE , 0 ) |
@@ -601,6 +602,14 @@ static int sun50i_iommu_map(struct iommu_domain *domain, unsigned long iova,
601602 u32 * page_table , * pte_addr ;
602603 int ret = 0 ;
603604
605+ /* the IOMMU can only handle 32-bit addresses, both input and output */
606+ if ((uint64_t )paddr >> 32 ) {
607+ ret = - EINVAL ;
608+ dev_warn_once (iommu -> dev ,
609+ "attempt to map address beyond 4GB\n" );
610+ goto out ;
611+ }
612+
604613 page_table = sun50i_dte_get_page_table (sun50i_domain , iova , gfp );
605614 if (IS_ERR (page_table )) {
606615 ret = PTR_ERR (page_table );
@@ -681,7 +690,8 @@ sun50i_iommu_domain_alloc_paging(struct device *dev)
681690 if (!sun50i_domain )
682691 return NULL ;
683692
684- sun50i_domain -> dt = iommu_alloc_pages (GFP_KERNEL , get_order (DT_SIZE ));
693+ sun50i_domain -> dt = iommu_alloc_pages (GFP_KERNEL | GFP_DMA32 ,
694+ get_order (DT_SIZE ));
685695 if (!sun50i_domain -> dt )
686696 goto err_free_domain ;
687697
@@ -996,7 +1006,7 @@ static int sun50i_iommu_probe(struct platform_device *pdev)
9961006
9971007 iommu -> pt_pool = kmem_cache_create (dev_name (& pdev -> dev ),
9981008 PT_SIZE , PT_SIZE ,
999- SLAB_HWCACHE_ALIGN ,
1009+ SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA32 ,
10001010 NULL );
10011011 if (!iommu -> pt_pool )
10021012 return - ENOMEM ;
@@ -1057,6 +1067,7 @@ static int sun50i_iommu_probe(struct platform_device *pdev)
10571067
10581068static const struct of_device_id sun50i_iommu_dt [] = {
10591069 { .compatible = "allwinner,sun50i-h6-iommu" , },
1070+ { .compatible = "allwinner,sun50i-h616-iommu" , },
10601071 { /* sentinel */ },
10611072};
10621073MODULE_DEVICE_TABLE (of , sun50i_iommu_dt );
0 commit comments