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

iommu/fsl_pamu: enable the liodn when attaching a device

Instead of a separate call to enable all devices from the list, just
enable the liodn once the device is attached to the iommu domain.

This also remove the DOMAIN_ATTR_FSL_PAMU_ENABLE iommu_attr.

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

authored by

Christoph Hellwig and committed by
Joerg Roedel
7d61cb6f 85e362ca

+3 -66
+3 -44
drivers/iommu/fsl_pamu_domain.c
··· 195 195 196 196 /* remove all the devices from the device list */ 197 197 detach_device(NULL, dma_domain); 198 - 199 - dma_domain->enabled = 0; 200 - 201 198 kmem_cache_free(fsl_pamu_domain_cache, dma_domain); 202 199 } 203 200 ··· 282 285 ret = pamu_set_liodn(dma_domain, dev, liodn[i]); 283 286 if (ret) 284 287 break; 288 + ret = pamu_enable_liodn(liodn[i]); 289 + if (ret) 290 + break; 285 291 } 286 292 spin_unlock_irqrestore(&dma_domain->domain_lock, flags); 287 293 return ret; ··· 337 337 } 338 338 ret = update_domain_stash(dma_domain, dma_domain->stash_id); 339 339 spin_unlock_irqrestore(&dma_domain->domain_lock, flags); 340 - 341 - return ret; 342 - } 343 - 344 - /* Configure domain dma state i.e. enable/disable DMA */ 345 - static int configure_domain_dma_state(struct fsl_dma_domain *dma_domain, bool enable) 346 - { 347 - struct device_domain_info *info; 348 - unsigned long flags; 349 - int ret; 350 - 351 - spin_lock_irqsave(&dma_domain->domain_lock, flags); 352 - dma_domain->enabled = enable; 353 - list_for_each_entry(info, &dma_domain->devices, link) { 354 - ret = (enable) ? pamu_enable_liodn(info->liodn) : 355 - pamu_disable_liodn(info->liodn); 356 - if (ret) 357 - pr_debug("Unable to set dma state for liodn %d", 358 - info->liodn); 359 - } 360 - spin_unlock_irqrestore(&dma_domain->domain_lock, flags); 361 - 362 - return 0; 363 - } 364 - 365 - static int fsl_pamu_set_domain_attr(struct iommu_domain *domain, 366 - enum iommu_attr attr_type, void *data) 367 - { 368 - struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 369 - int ret = 0; 370 - 371 - switch (attr_type) { 372 - case DOMAIN_ATTR_FSL_PAMU_ENABLE: 373 - ret = configure_domain_dma_state(dma_domain, *(int *)data); 374 - break; 375 - default: 376 - pr_debug("Unsupported attribute type\n"); 377 - ret = -EINVAL; 378 - break; 379 - } 380 340 381 341 return ret; 382 342 } ··· 465 505 .attach_dev = fsl_pamu_attach_device, 466 506 .detach_dev = fsl_pamu_detach_device, 467 507 .iova_to_phys = fsl_pamu_iova_to_phys, 468 - .domain_set_attr = fsl_pamu_set_domain_attr, 469 508 .probe_device = fsl_pamu_probe_device, 470 509 .release_device = fsl_pamu_release_device, 471 510 .device_group = fsl_pamu_device_group,
-10
drivers/iommu/fsl_pamu_domain.h
··· 12 12 struct fsl_dma_domain { 13 13 /* list of devices associated with the domain */ 14 14 struct list_head devices; 15 - /* dma_domain states: 16 - * enabled - DMA has been enabled for the given 17 - * domain. This translates to setting of the 18 - * valid bit for the primary PAACE in the PAMU 19 - * PAACT table. Domain geometry should be set and 20 - * it must have a valid mapping before DMA can be 21 - * enabled for it. 22 - * 23 - */ 24 - int enabled; 25 15 u32 stash_id; 26 16 u32 snoop_id; 27 17 struct iommu_domain iommu_domain;
-11
drivers/soc/fsl/qbman/qman_portal.c
··· 46 46 { 47 47 #ifdef CONFIG_FSL_PAMU 48 48 struct device *dev = pcfg->dev; 49 - int window_count = 1; 50 49 int ret; 51 50 52 51 pcfg->iommu_domain = iommu_domain_alloc(&platform_bus_type); ··· 65 66 ret); 66 67 goto out_domain_free; 67 68 } 68 - ret = iommu_domain_set_attr(pcfg->iommu_domain, 69 - DOMAIN_ATTR_FSL_PAMU_ENABLE, 70 - &window_count); 71 - if (ret < 0) { 72 - dev_err(dev, "%s(): iommu_domain_set_attr() = %d", __func__, 73 - ret); 74 - goto out_detach_device; 75 - } 76 69 77 70 no_iommu: 78 71 #endif ··· 73 82 return; 74 83 75 84 #ifdef CONFIG_FSL_PAMU 76 - out_detach_device: 77 - iommu_detach_device(pcfg->iommu_domain, NULL); 78 85 out_domain_free: 79 86 iommu_domain_free(pcfg->iommu_domain); 80 87 pcfg->iommu_domain = NULL;
-1
include/linux/iommu.h
··· 109 109 enum iommu_attr { 110 110 DOMAIN_ATTR_GEOMETRY, 111 111 DOMAIN_ATTR_PAGING, 112 - DOMAIN_ATTR_FSL_PAMU_ENABLE, 113 112 DOMAIN_ATTR_NESTING, /* two stages of translation */ 114 113 DOMAIN_ATTR_DMA_USE_FLUSH_QUEUE, 115 114 DOMAIN_ATTR_IO_PGTABLE_CFG,