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