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

iommu/fsl: Make use of domain_alloc and domain_free

Implement domain_alloc and domain_free iommu-ops as a
replacement for domain_init/domain_destroy.

Signed-off-by: Joerg Roedel <jroedel@suse.de>

+33 -29
+32 -28
drivers/iommu/fsl_pamu_domain.c
··· 33 33 static struct kmem_cache *iommu_devinfo_cache; 34 34 static DEFINE_SPINLOCK(device_domain_lock); 35 35 36 + static struct fsl_dma_domain *to_fsl_dma_domain(struct iommu_domain *dom) 37 + { 38 + return container_of(dom, struct fsl_dma_domain, iommu_domain); 39 + } 40 + 36 41 static int __init iommu_init_mempool(void) 37 42 { 38 43 fsl_pamu_domain_cache = kmem_cache_create("fsl_pamu_domain", ··· 70 65 struct dma_window *win_ptr = &dma_domain->win_arr[0]; 71 66 struct iommu_domain_geometry *geom; 72 67 73 - geom = &dma_domain->iommu_domain->geometry; 68 + geom = &dma_domain->iommu_domain.geometry; 74 69 75 70 if (!win_cnt || !dma_domain->geom_size) { 76 71 pr_debug("Number of windows/geometry not configured for the domain\n"); ··· 128 123 { 129 124 int ret; 130 125 struct dma_window *wnd = &dma_domain->win_arr[0]; 131 - phys_addr_t wnd_addr = dma_domain->iommu_domain->geometry.aperture_start; 126 + phys_addr_t wnd_addr = dma_domain->iommu_domain.geometry.aperture_start; 132 127 unsigned long flags; 133 128 134 129 spin_lock_irqsave(&iommu_lock, flags); ··· 177 172 } else { 178 173 phys_addr_t wnd_addr; 179 174 180 - wnd_addr = dma_domain->iommu_domain->geometry.aperture_start; 175 + wnd_addr = dma_domain->iommu_domain.geometry.aperture_start; 181 176 182 177 ret = pamu_config_ppaace(liodn, wnd_addr, 183 178 wnd->size, ··· 389 384 static phys_addr_t fsl_pamu_iova_to_phys(struct iommu_domain *domain, 390 385 dma_addr_t iova) 391 386 { 392 - struct fsl_dma_domain *dma_domain = domain->priv; 387 + struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 393 388 394 389 if (iova < domain->geometry.aperture_start || 395 390 iova > domain->geometry.aperture_end) ··· 403 398 return cap == IOMMU_CAP_CACHE_COHERENCY; 404 399 } 405 400 406 - static void fsl_pamu_domain_destroy(struct iommu_domain *domain) 401 + static void fsl_pamu_domain_free(struct iommu_domain *domain) 407 402 { 408 - struct fsl_dma_domain *dma_domain = domain->priv; 409 - 410 - domain->priv = NULL; 403 + struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 411 404 412 405 /* remove all the devices from the device list */ 413 406 detach_device(NULL, dma_domain); ··· 416 413 kmem_cache_free(fsl_pamu_domain_cache, dma_domain); 417 414 } 418 415 419 - static int fsl_pamu_domain_init(struct iommu_domain *domain) 416 + static struct iommu_domain *fsl_pamu_domain_alloc(unsigned type) 420 417 { 421 418 struct fsl_dma_domain *dma_domain; 419 + 420 + if (type != IOMMU_DOMAIN_UNMANAGED) 421 + return NULL; 422 422 423 423 dma_domain = iommu_alloc_dma_domain(); 424 424 if (!dma_domain) { 425 425 pr_debug("dma_domain allocation failed\n"); 426 - return -ENOMEM; 426 + return NULL; 427 427 } 428 - domain->priv = dma_domain; 429 - dma_domain->iommu_domain = domain; 430 428 /* defaul geometry 64 GB i.e. maximum system address */ 431 - domain->geometry.aperture_start = 0; 432 - domain->geometry.aperture_end = (1ULL << 36) - 1; 433 - domain->geometry.force_aperture = true; 429 + dma_domain->iommu_domain. geometry.aperture_start = 0; 430 + dma_domain->iommu_domain.geometry.aperture_end = (1ULL << 36) - 1; 431 + dma_domain->iommu_domain.geometry.force_aperture = true; 434 432 435 - return 0; 433 + return &dma_domain->iommu_domain; 436 434 } 437 435 438 436 /* Configure geometry settings for all LIODNs associated with domain */ ··· 503 499 504 500 static void fsl_pamu_window_disable(struct iommu_domain *domain, u32 wnd_nr) 505 501 { 506 - struct fsl_dma_domain *dma_domain = domain->priv; 502 + struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 507 503 unsigned long flags; 508 504 int ret; 509 505 ··· 534 530 static int fsl_pamu_window_enable(struct iommu_domain *domain, u32 wnd_nr, 535 531 phys_addr_t paddr, u64 size, int prot) 536 532 { 537 - struct fsl_dma_domain *dma_domain = domain->priv; 533 + struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 538 534 struct dma_window *wnd; 539 535 int pamu_prot = 0; 540 536 int ret; ··· 611 607 int num) 612 608 { 613 609 unsigned long flags; 614 - struct iommu_domain *domain = dma_domain->iommu_domain; 610 + struct iommu_domain *domain = &dma_domain->iommu_domain; 615 611 int ret = 0; 616 612 int i; 617 613 ··· 657 653 static int fsl_pamu_attach_device(struct iommu_domain *domain, 658 654 struct device *dev) 659 655 { 660 - struct fsl_dma_domain *dma_domain = domain->priv; 656 + struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 661 657 const u32 *liodn; 662 658 u32 liodn_cnt; 663 659 int len, ret = 0; ··· 695 691 static void fsl_pamu_detach_device(struct iommu_domain *domain, 696 692 struct device *dev) 697 693 { 698 - struct fsl_dma_domain *dma_domain = domain->priv; 694 + struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 699 695 const u32 *prop; 700 696 int len; 701 697 struct pci_dev *pdev = NULL; ··· 727 723 static int configure_domain_geometry(struct iommu_domain *domain, void *data) 728 724 { 729 725 struct iommu_domain_geometry *geom_attr = data; 730 - struct fsl_dma_domain *dma_domain = domain->priv; 726 + struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 731 727 dma_addr_t geom_size; 732 728 unsigned long flags; 733 729 ··· 817 813 static int fsl_pamu_set_domain_attr(struct iommu_domain *domain, 818 814 enum iommu_attr attr_type, void *data) 819 815 { 820 - struct fsl_dma_domain *dma_domain = domain->priv; 816 + struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 821 817 int ret = 0; 822 818 823 819 switch (attr_type) { ··· 842 838 static int fsl_pamu_get_domain_attr(struct iommu_domain *domain, 843 839 enum iommu_attr attr_type, void *data) 844 840 { 845 - struct fsl_dma_domain *dma_domain = domain->priv; 841 + struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 846 842 int ret = 0; 847 843 848 844 switch (attr_type) { ··· 1003 999 1004 1000 static int fsl_pamu_set_windows(struct iommu_domain *domain, u32 w_count) 1005 1001 { 1006 - struct fsl_dma_domain *dma_domain = domain->priv; 1002 + struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 1007 1003 unsigned long flags; 1008 1004 int ret; 1009 1005 ··· 1052 1048 1053 1049 static u32 fsl_pamu_get_windows(struct iommu_domain *domain) 1054 1050 { 1055 - struct fsl_dma_domain *dma_domain = domain->priv; 1051 + struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain); 1056 1052 1057 1053 return dma_domain->win_cnt; 1058 1054 } 1059 1055 1060 1056 static const struct iommu_ops fsl_pamu_ops = { 1061 1057 .capable = fsl_pamu_capable, 1062 - .domain_init = fsl_pamu_domain_init, 1063 - .domain_destroy = fsl_pamu_domain_destroy, 1058 + .domain_alloc = fsl_pamu_domain_alloc, 1059 + .domain_free = fsl_pamu_domain_free, 1064 1060 .attach_dev = fsl_pamu_attach_device, 1065 1061 .detach_dev = fsl_pamu_detach_device, 1066 1062 .domain_window_enable = fsl_pamu_window_enable,
+1 -1
drivers/iommu/fsl_pamu_domain.h
··· 71 71 u32 stash_id; 72 72 struct pamu_stash_attribute dma_stash; 73 73 u32 snoop_id; 74 - struct iommu_domain *iommu_domain; 74 + struct iommu_domain iommu_domain; 75 75 spinlock_t domain_lock; 76 76 }; 77 77