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

iommu/fsl_pamu: remove ->domain_window_enable

The only thing that fsl_pamu_window_enable does for the current caller
is to fill in the prot value in the only dma_window structure, and to
propagate a few values from the iommu_domain_geometry struture into the
dma_window. Remove the dma_window entirely, hardcode the prot value and
otherwise use the iommu_domain_geometry structure instead.

Remove the now unused ->domain_window_enable iommu method.

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

authored by

Christoph Hellwig and committed by
Joerg Roedel
376dfd2a ba58d121

+14 -218
+14 -168
drivers/iommu/fsl_pamu_domain.c
··· 54 54 return 0; 55 55 } 56 56 57 - static phys_addr_t get_phys_addr(struct fsl_dma_domain *dma_domain, dma_addr_t iova) 58 - { 59 - struct dma_window *win_ptr = &dma_domain->win_arr[0]; 60 - struct iommu_domain_geometry *geom; 61 - 62 - geom = &dma_domain->iommu_domain.geometry; 63 - 64 - if (win_ptr->valid) 65 - return win_ptr->paddr + (iova & (win_ptr->size - 1)); 66 - 67 - return 0; 68 - } 69 - 70 57 /* Map the DMA window corresponding to the LIODN */ 71 58 static int map_liodn(int liodn, struct fsl_dma_domain *dma_domain) 72 59 { 73 60 int ret; 74 - struct dma_window *wnd = &dma_domain->win_arr[0]; 75 - phys_addr_t wnd_addr = dma_domain->iommu_domain.geometry.aperture_start; 61 + struct iommu_domain_geometry *geom = &dma_domain->iommu_domain.geometry; 76 62 unsigned long flags; 77 63 78 64 spin_lock_irqsave(&iommu_lock, flags); 79 - ret = pamu_config_ppaace(liodn, wnd_addr, 80 - wnd->size, 81 - ~(u32)0, 82 - wnd->paddr >> PAMU_PAGE_SHIFT, 83 - dma_domain->snoop_id, dma_domain->stash_id, 84 - wnd->prot); 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); 85 69 spin_unlock_irqrestore(&iommu_lock, flags); 86 70 if (ret) 87 71 pr_debug("PAACE configuration failed for liodn %d\n", liodn); 88 - 89 - return ret; 90 - } 91 - 92 - /* Update window/subwindow mapping for the LIODN */ 93 - static int update_liodn(int liodn, struct fsl_dma_domain *dma_domain, u32 wnd_nr) 94 - { 95 - int ret; 96 - struct dma_window *wnd = &dma_domain->win_arr[wnd_nr]; 97 - phys_addr_t wnd_addr; 98 - unsigned long flags; 99 - 100 - spin_lock_irqsave(&iommu_lock, flags); 101 - 102 - wnd_addr = dma_domain->iommu_domain.geometry.aperture_start; 103 - 104 - ret = pamu_config_ppaace(liodn, wnd_addr, 105 - wnd->size, 106 - ~(u32)0, 107 - wnd->paddr >> PAMU_PAGE_SHIFT, 108 - dma_domain->snoop_id, dma_domain->stash_id, 109 - wnd->prot); 110 - if (ret) 111 - pr_debug("Window reconfiguration failed for liodn %d\n", 112 - liodn); 113 - 114 - spin_unlock_irqrestore(&iommu_lock, flags); 115 72 116 73 return ret; 117 74 } ··· 127 170 } 128 171 129 172 return ret; 130 - } 131 - 132 - static int check_size(u64 size, dma_addr_t iova) 133 - { 134 - /* 135 - * Size must be a power of two and at least be equal 136 - * to PAMU page size. 137 - */ 138 - if ((size & (size - 1)) || size < PAMU_PAGE_SIZE) { 139 - pr_debug("Size too small or not a power of two\n"); 140 - return -EINVAL; 141 - } 142 - 143 - /* iova must be page size aligned */ 144 - if (iova & (size - 1)) { 145 - pr_debug("Address is not aligned with window size\n"); 146 - return -EINVAL; 147 - } 148 - 149 - return 0; 150 173 } 151 174 152 175 static void remove_device_ref(struct device_domain_info *info) ··· 194 257 static phys_addr_t fsl_pamu_iova_to_phys(struct iommu_domain *domain, 195 258 dma_addr_t iova) 196 259 { 197 - struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 198 - 199 260 if (iova < domain->geometry.aperture_start || 200 261 iova > domain->geometry.aperture_end) 201 262 return 0; 202 - 203 - return get_phys_addr(dma_domain, iova); 263 + return iova; 204 264 } 205 265 206 266 static bool fsl_pamu_capable(enum iommu_cap cap) ··· 213 279 detach_device(NULL, dma_domain); 214 280 215 281 dma_domain->enabled = 0; 216 - dma_domain->mapped = 0; 217 282 218 283 kmem_cache_free(fsl_pamu_domain_cache, dma_domain); 219 284 } ··· 256 323 return ret; 257 324 } 258 325 259 - /* Update domain mappings for all LIODNs associated with the domain */ 260 - static int update_domain_mapping(struct fsl_dma_domain *dma_domain, u32 wnd_nr) 261 - { 262 - struct device_domain_info *info; 263 - int ret = 0; 264 - 265 - list_for_each_entry(info, &dma_domain->devices, link) { 266 - ret = update_liodn(info->liodn, dma_domain, wnd_nr); 267 - if (ret) 268 - break; 269 - } 270 - return ret; 271 - } 272 - 273 - 274 - static int fsl_pamu_window_enable(struct iommu_domain *domain, u32 wnd_nr, 275 - phys_addr_t paddr, u64 size, int prot) 276 - { 277 - struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 278 - struct dma_window *wnd; 279 - int pamu_prot = 0; 280 - int ret; 281 - unsigned long flags; 282 - u64 win_size; 283 - 284 - if (prot & IOMMU_READ) 285 - pamu_prot |= PAACE_AP_PERMS_QUERY; 286 - if (prot & IOMMU_WRITE) 287 - pamu_prot |= PAACE_AP_PERMS_UPDATE; 288 - 289 - spin_lock_irqsave(&dma_domain->domain_lock, flags); 290 - if (wnd_nr > 0) { 291 - pr_debug("Invalid window index\n"); 292 - spin_unlock_irqrestore(&dma_domain->domain_lock, flags); 293 - return -EINVAL; 294 - } 295 - 296 - win_size = (domain->geometry.aperture_end + 1) >> ilog2(1); 297 - if (size > win_size) { 298 - pr_debug("Invalid window size\n"); 299 - spin_unlock_irqrestore(&dma_domain->domain_lock, flags); 300 - return -EINVAL; 301 - } 302 - 303 - if (dma_domain->enabled) { 304 - pr_debug("Disable the window before updating the mapping\n"); 305 - spin_unlock_irqrestore(&dma_domain->domain_lock, flags); 306 - return -EBUSY; 307 - } 308 - 309 - ret = check_size(size, domain->geometry.aperture_start); 310 - if (ret) { 311 - pr_debug("Aperture start not aligned to the size\n"); 312 - spin_unlock_irqrestore(&dma_domain->domain_lock, flags); 313 - return -EINVAL; 314 - } 315 - 316 - wnd = &dma_domain->win_arr[wnd_nr]; 317 - if (!wnd->valid) { 318 - wnd->paddr = paddr; 319 - wnd->size = size; 320 - wnd->prot = pamu_prot; 321 - 322 - ret = update_domain_mapping(dma_domain, wnd_nr); 323 - if (!ret) { 324 - wnd->valid = 1; 325 - dma_domain->mapped++; 326 - } 327 - } else { 328 - pr_debug("Disable the window before updating the mapping\n"); 329 - ret = -EBUSY; 330 - } 331 - 332 - spin_unlock_irqrestore(&dma_domain->domain_lock, flags); 333 - 334 - return ret; 335 - } 336 - 337 326 /* 338 327 * Attach the LIODN to the DMA domain and configure the geometry 339 328 * and window mappings. ··· 289 434 &domain->geometry); 290 435 if (ret) 291 436 break; 292 - if (dma_domain->mapped) { 293 - /* 294 - * Create window/subwindow mapping for 295 - * the LIODN. 296 - */ 297 - ret = map_liodn(liodn[i], dma_domain); 298 - if (ret) 299 - break; 300 - } 437 + 438 + /* 439 + * Create window/subwindow mapping for 440 + * the LIODN. 441 + */ 442 + ret = map_liodn(liodn[i], dma_domain); 443 + if (ret) 444 + break; 301 445 } 302 446 spin_unlock_irqrestore(&dma_domain->domain_lock, flags); 303 447 ··· 406 552 int ret; 407 553 408 554 spin_lock_irqsave(&dma_domain->domain_lock, flags); 409 - 410 - if (enable && !dma_domain->mapped) { 411 - pr_debug("Can't enable DMA domain without valid mapping\n"); 412 - spin_unlock_irqrestore(&dma_domain->domain_lock, flags); 413 - return -ENODEV; 414 - } 415 - 416 555 dma_domain->enabled = enable; 417 556 list_for_each_entry(info, &dma_domain->devices, link) { 418 557 ret = (enable) ? pamu_enable_liodn(info->liodn) : ··· 564 717 .domain_free = fsl_pamu_domain_free, 565 718 .attach_dev = fsl_pamu_attach_device, 566 719 .detach_dev = fsl_pamu_detach_device, 567 - .domain_window_enable = fsl_pamu_window_enable, 568 720 .iova_to_phys = fsl_pamu_iova_to_phys, 569 721 .domain_set_attr = fsl_pamu_set_domain_attr, 570 722 .probe_device = fsl_pamu_probe_device,
-15
drivers/iommu/fsl_pamu_domain.h
··· 9 9 10 10 #include "fsl_pamu.h" 11 11 12 - struct dma_window { 13 - phys_addr_t paddr; 14 - u64 size; 15 - int valid; 16 - int prot; 17 - }; 18 - 19 12 struct fsl_dma_domain { 20 - /* 21 - * win_arr contains information of the configured 22 - * windows for a domain. 23 - */ 24 - struct dma_window win_arr[1]; 25 13 /* list of devices associated with the domain */ 26 14 struct list_head devices; 27 15 /* dma_domain states: 28 - * mapped - A particular mapping has been created 29 - * within the configured geometry. 30 16 * enabled - DMA has been enabled for the given 31 17 * domain. This translates to setting of the 32 18 * valid bit for the primary PAACE in the PAMU ··· 21 35 * enabled for it. 22 36 * 23 37 */ 24 - int mapped; 25 38 int enabled; 26 39 /* stash_id obtained from the stash attribute details */ 27 40 u32 stash_id;
-11
drivers/iommu/iommu.c
··· 2610 2610 return __iommu_map_sg(domain, iova, sg, nents, prot, GFP_ATOMIC); 2611 2611 } 2612 2612 2613 - int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr, 2614 - phys_addr_t paddr, u64 size, int prot) 2615 - { 2616 - if (unlikely(domain->ops->domain_window_enable == NULL)) 2617 - return -ENODEV; 2618 - 2619 - return domain->ops->domain_window_enable(domain, wnd_nr, paddr, size, 2620 - prot); 2621 - } 2622 - EXPORT_SYMBOL_GPL(iommu_domain_window_enable); 2623 - 2624 2613 /** 2625 2614 * report_iommu_fault() - report about an IOMMU fault to the IOMMU framework 2626 2615 * @domain: the iommu domain where the fault has happened
-7
drivers/soc/fsl/qbman/qman_portal.c
··· 65 65 __func__, ret); 66 66 goto out_domain_free; 67 67 } 68 - ret = iommu_domain_window_enable(pcfg->iommu_domain, 0, 0, 1ULL << 36, 69 - IOMMU_READ | IOMMU_WRITE); 70 - if (ret < 0) { 71 - dev_err(dev, "%s(): iommu_domain_window_enable() = %d", 72 - __func__, ret); 73 - goto out_domain_free; 74 - } 75 68 ret = iommu_attach_device(pcfg->iommu_domain, dev); 76 69 if (ret < 0) { 77 70 dev_err(dev, "%s(): iommu_device_attach() = %d", __func__,
-17
include/linux/iommu.h
··· 217 217 * @get_resv_regions: Request list of reserved regions for a device 218 218 * @put_resv_regions: Free list of reserved regions for a device 219 219 * @apply_resv_region: Temporary helper call-back for iova reserved ranges 220 - * @domain_window_enable: Configure and enable a particular window for a domain 221 220 * @of_xlate: add OF master IDs to iommu grouping 222 221 * @is_attach_deferred: Check if domain attach should be deferred from iommu 223 222 * driver init to device driver init (default no) ··· 273 274 void (*apply_resv_region)(struct device *dev, 274 275 struct iommu_domain *domain, 275 276 struct iommu_resv_region *region); 276 - 277 - /* Window handling functions */ 278 - int (*domain_window_enable)(struct iommu_domain *domain, u32 wnd_nr, 279 - phys_addr_t paddr, u64 size, int prot); 280 277 281 278 int (*of_xlate)(struct device *dev, struct of_phandle_args *args); 282 279 bool (*is_attach_deferred)(struct iommu_domain *domain, struct device *dev); ··· 516 521 extern int iommu_domain_set_attr(struct iommu_domain *domain, enum iommu_attr, 517 522 void *data); 518 523 519 - /* Window handling function prototypes */ 520 - extern int iommu_domain_window_enable(struct iommu_domain *domain, u32 wnd_nr, 521 - phys_addr_t offset, u64 size, 522 - int prot); 523 - 524 524 extern int report_iommu_fault(struct iommu_domain *domain, struct device *dev, 525 525 unsigned long iova, int flags); 526 526 ··· 737 747 static inline void iommu_iotlb_sync(struct iommu_domain *domain, 738 748 struct iommu_iotlb_gather *iotlb_gather) 739 749 { 740 - } 741 - 742 - static inline int iommu_domain_window_enable(struct iommu_domain *domain, 743 - u32 wnd_nr, phys_addr_t paddr, 744 - u64 size, int prot) 745 - { 746 - return -ENODEV; 747 750 } 748 751 749 752 static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, dma_addr_t iova)