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

iommu/fsl_pamu: merge pamu_set_liodn and map_liodn

Merge the two fuctions that configure the ppaace into a single coherent
function. I somehow doubt we need the two pamu_config_ppaace calls,
but keep the existing behavior just to be on the safe side.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Li Yang <leoyang.li@nxp.com>
Link: https://lore.kernel.org/r/20210401155256.298656-9-hch@lst.de
Signed-off-by: Joerg Roedel <jroedel@suse.de>

authored by

Christoph Hellwig and committed by
Joerg Roedel
dae7747a 4eeb96f6

+17 -48
+17 -48
drivers/iommu/fsl_pamu_domain.c
··· 54 54 return 0; 55 55 } 56 56 57 - /* Map the DMA window corresponding to the LIODN */ 58 - static int map_liodn(int liodn, struct fsl_dma_domain *dma_domain) 59 - { 60 - int ret; 61 - struct iommu_domain_geometry *geom = &dma_domain->iommu_domain.geometry; 62 - unsigned long flags; 63 - 64 - spin_lock_irqsave(&iommu_lock, flags); 65 - ret = pamu_config_ppaace(liodn, geom->aperture_start, 66 - geom->aperture_end + 1, ~(u32)0, 67 - 0, dma_domain->snoop_id, dma_domain->stash_id, 68 - PAACE_AP_PERMS_QUERY | PAACE_AP_PERMS_UPDATE); 69 - spin_unlock_irqrestore(&iommu_lock, flags); 70 - if (ret) 71 - pr_debug("PAACE configuration failed for liodn %d\n", liodn); 72 - 73 - return ret; 74 - } 75 - 76 57 static int update_liodn_stash(int liodn, struct fsl_dma_domain *dma_domain, 77 58 u32 val) 78 59 { ··· 75 94 } 76 95 77 96 /* Set the geometry parameters for a LIODN */ 78 - static int pamu_set_liodn(int liodn, struct device *dev, 79 - struct fsl_dma_domain *dma_domain, 80 - struct iommu_domain_geometry *geom_attr) 97 + static int pamu_set_liodn(struct fsl_dma_domain *dma_domain, struct device *dev, 98 + int liodn) 81 99 { 82 - phys_addr_t window_addr, window_size; 100 + struct iommu_domain *domain = &dma_domain->iommu_domain; 101 + struct iommu_domain_geometry *geom = &domain->geometry; 83 102 u32 omi_index = ~(u32)0; 84 103 unsigned long flags; 85 104 int ret; ··· 91 110 */ 92 111 get_ome_index(&omi_index, dev); 93 112 94 - window_addr = geom_attr->aperture_start; 95 - window_size = geom_attr->aperture_end + 1; 96 - 97 113 spin_lock_irqsave(&iommu_lock, flags); 98 114 ret = pamu_disable_liodn(liodn); 99 - if (!ret) 100 - ret = pamu_config_ppaace(liodn, window_addr, window_size, omi_index, 101 - 0, dma_domain->snoop_id, 102 - dma_domain->stash_id, 0); 115 + if (ret) 116 + goto out_unlock; 117 + ret = pamu_config_ppaace(liodn, geom->aperture_start, 118 + geom->aperture_end + 1, omi_index, 0, 119 + dma_domain->snoop_id, dma_domain->stash_id, 0); 120 + if (ret) 121 + goto out_unlock; 122 + ret = pamu_config_ppaace(liodn, geom->aperture_start, 123 + geom->aperture_end + 1, ~(u32)0, 124 + 0, dma_domain->snoop_id, dma_domain->stash_id, 125 + PAACE_AP_PERMS_QUERY | PAACE_AP_PERMS_UPDATE); 126 + out_unlock: 103 127 spin_unlock_irqrestore(&iommu_lock, flags); 104 128 if (ret) { 105 129 pr_debug("PAACE configuration failed for liodn %d\n", 106 130 liodn); 107 - return ret; 108 131 } 109 - 110 132 return ret; 111 133 } 112 134 ··· 249 265 int num) 250 266 { 251 267 unsigned long flags; 252 - struct iommu_domain *domain = &dma_domain->iommu_domain; 253 268 int ret = 0; 254 269 int i; 255 270 ··· 263 280 } 264 281 265 282 attach_device(dma_domain, liodn[i], dev); 266 - /* 267 - * Check if geometry has already been configured 268 - * for the domain. If yes, set the geometry for 269 - * the LIODN. 270 - */ 271 - ret = pamu_set_liodn(liodn[i], dev, dma_domain, 272 - &domain->geometry); 273 - if (ret) 274 - break; 275 - 276 - /* 277 - * Create window/subwindow mapping for 278 - * the LIODN. 279 - */ 280 - ret = map_liodn(liodn[i], dma_domain); 283 + ret = pamu_set_liodn(dma_domain, dev, liodn[i]); 281 284 if (ret) 282 285 break; 283 286 }