diff options
-rw-r--r-- | drivers/iommu/ipmmu-vmsa.c | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/drivers/iommu/ipmmu-vmsa.c b/drivers/iommu/ipmmu-vmsa.c index 6e6a86f3c375..fd05a5f5a47e 100644 --- a/drivers/iommu/ipmmu-vmsa.c +++ b/drivers/iommu/ipmmu-vmsa.c | |||
@@ -58,16 +58,12 @@ struct ipmmu_vmsa_domain { | |||
58 | spinlock_t lock; /* Protects mappings */ | 58 | spinlock_t lock; /* Protects mappings */ |
59 | }; | 59 | }; |
60 | 60 | ||
61 | struct ipmmu_vmsa_iommu_priv { | ||
62 | struct ipmmu_vmsa_device *mmu; | ||
63 | }; | ||
64 | |||
65 | static struct ipmmu_vmsa_domain *to_vmsa_domain(struct iommu_domain *dom) | 61 | static struct ipmmu_vmsa_domain *to_vmsa_domain(struct iommu_domain *dom) |
66 | { | 62 | { |
67 | return container_of(dom, struct ipmmu_vmsa_domain, io_domain); | 63 | return container_of(dom, struct ipmmu_vmsa_domain, io_domain); |
68 | } | 64 | } |
69 | 65 | ||
70 | static struct ipmmu_vmsa_iommu_priv *to_priv(struct device *dev) | 66 | static struct ipmmu_vmsa_device *to_ipmmu(struct device *dev) |
71 | { | 67 | { |
72 | return dev->iommu_fwspec ? dev->iommu_fwspec->iommu_priv : NULL; | 68 | return dev->iommu_fwspec ? dev->iommu_fwspec->iommu_priv : NULL; |
73 | } | 69 | } |
@@ -565,15 +561,14 @@ static void ipmmu_domain_free(struct iommu_domain *io_domain) | |||
565 | static int ipmmu_attach_device(struct iommu_domain *io_domain, | 561 | static int ipmmu_attach_device(struct iommu_domain *io_domain, |
566 | struct device *dev) | 562 | struct device *dev) |
567 | { | 563 | { |
568 | struct ipmmu_vmsa_iommu_priv *priv = to_priv(dev); | ||
569 | struct iommu_fwspec *fwspec = dev->iommu_fwspec; | 564 | struct iommu_fwspec *fwspec = dev->iommu_fwspec; |
570 | struct ipmmu_vmsa_device *mmu = priv->mmu; | 565 | struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); |
571 | struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); | 566 | struct ipmmu_vmsa_domain *domain = to_vmsa_domain(io_domain); |
572 | unsigned long flags; | 567 | unsigned long flags; |
573 | unsigned int i; | 568 | unsigned int i; |
574 | int ret = 0; | 569 | int ret = 0; |
575 | 570 | ||
576 | if (!priv || !priv->mmu) { | 571 | if (!mmu) { |
577 | dev_err(dev, "Cannot attach to IPMMU\n"); | 572 | dev_err(dev, "Cannot attach to IPMMU\n"); |
578 | return -ENXIO; | 573 | return -ENXIO; |
579 | } | 574 | } |
@@ -662,18 +657,12 @@ static int ipmmu_init_platform_device(struct device *dev, | |||
662 | struct of_phandle_args *args) | 657 | struct of_phandle_args *args) |
663 | { | 658 | { |
664 | struct platform_device *ipmmu_pdev; | 659 | struct platform_device *ipmmu_pdev; |
665 | struct ipmmu_vmsa_iommu_priv *priv; | ||
666 | 660 | ||
667 | ipmmu_pdev = of_find_device_by_node(args->np); | 661 | ipmmu_pdev = of_find_device_by_node(args->np); |
668 | if (!ipmmu_pdev) | 662 | if (!ipmmu_pdev) |
669 | return -ENODEV; | 663 | return -ENODEV; |
670 | 664 | ||
671 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | 665 | dev->iommu_fwspec->iommu_priv = platform_get_drvdata(ipmmu_pdev); |
672 | if (!priv) | ||
673 | return -ENOMEM; | ||
674 | |||
675 | priv->mmu = platform_get_drvdata(ipmmu_pdev); | ||
676 | dev->iommu_fwspec->iommu_priv = priv; | ||
677 | return 0; | 666 | return 0; |
678 | } | 667 | } |
679 | 668 | ||
@@ -683,7 +672,7 @@ static int ipmmu_of_xlate(struct device *dev, | |||
683 | iommu_fwspec_add_ids(dev, spec->args, 1); | 672 | iommu_fwspec_add_ids(dev, spec->args, 1); |
684 | 673 | ||
685 | /* Initialize once - xlate() will call multiple times */ | 674 | /* Initialize once - xlate() will call multiple times */ |
686 | if (to_priv(dev)) | 675 | if (to_ipmmu(dev)) |
687 | return 0; | 676 | return 0; |
688 | 677 | ||
689 | return ipmmu_init_platform_device(dev, spec); | 678 | return ipmmu_init_platform_device(dev, spec); |
@@ -693,14 +682,14 @@ static int ipmmu_of_xlate(struct device *dev, | |||
693 | 682 | ||
694 | static int ipmmu_add_device(struct device *dev) | 683 | static int ipmmu_add_device(struct device *dev) |
695 | { | 684 | { |
696 | struct ipmmu_vmsa_device *mmu = NULL; | 685 | struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); |
697 | struct iommu_group *group; | 686 | struct iommu_group *group; |
698 | int ret; | 687 | int ret; |
699 | 688 | ||
700 | /* | 689 | /* |
701 | * Only let through devices that have been verified in xlate() | 690 | * Only let through devices that have been verified in xlate() |
702 | */ | 691 | */ |
703 | if (!to_priv(dev)) | 692 | if (!mmu) |
704 | return -ENODEV; | 693 | return -ENODEV; |
705 | 694 | ||
706 | /* Create a device group and add the device to it. */ | 695 | /* Create a device group and add the device to it. */ |
@@ -729,7 +718,6 @@ static int ipmmu_add_device(struct device *dev) | |||
729 | * - Make the mapping size configurable ? We currently use a 2GB mapping | 718 | * - Make the mapping size configurable ? We currently use a 2GB mapping |
730 | * at a 1GB offset to ensure that NULL VAs will fault. | 719 | * at a 1GB offset to ensure that NULL VAs will fault. |
731 | */ | 720 | */ |
732 | mmu = to_priv(dev)->mmu; | ||
733 | if (!mmu->mapping) { | 721 | if (!mmu->mapping) { |
734 | struct dma_iommu_mapping *mapping; | 722 | struct dma_iommu_mapping *mapping; |
735 | 723 | ||
@@ -795,7 +783,7 @@ static int ipmmu_add_device_dma(struct device *dev) | |||
795 | /* | 783 | /* |
796 | * Only let through devices that have been verified in xlate() | 784 | * Only let through devices that have been verified in xlate() |
797 | */ | 785 | */ |
798 | if (!to_priv(dev)) | 786 | if (!to_ipmmu(dev)) |
799 | return -ENODEV; | 787 | return -ENODEV; |
800 | 788 | ||
801 | group = iommu_group_get_for_dev(dev); | 789 | group = iommu_group_get_for_dev(dev); |
@@ -812,15 +800,15 @@ static void ipmmu_remove_device_dma(struct device *dev) | |||
812 | 800 | ||
813 | static struct iommu_group *ipmmu_find_group(struct device *dev) | 801 | static struct iommu_group *ipmmu_find_group(struct device *dev) |
814 | { | 802 | { |
815 | struct ipmmu_vmsa_iommu_priv *priv = to_priv(dev); | 803 | struct ipmmu_vmsa_device *mmu = to_ipmmu(dev); |
816 | struct iommu_group *group; | 804 | struct iommu_group *group; |
817 | 805 | ||
818 | if (priv->mmu->group) | 806 | if (mmu->group) |
819 | return iommu_group_ref_get(priv->mmu->group); | 807 | return iommu_group_ref_get(mmu->group); |
820 | 808 | ||
821 | group = iommu_group_alloc(); | 809 | group = iommu_group_alloc(); |
822 | if (!IS_ERR(group)) | 810 | if (!IS_ERR(group)) |
823 | priv->mmu->group = group; | 811 | mmu->group = group; |
824 | 812 | ||
825 | return group; | 813 | return group; |
826 | } | 814 | } |