aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iommu
diff options
context:
space:
mode:
authorHiroshi Doyu <hdoyu@nvidia.com>2012-06-25 07:23:56 -0400
committerJoerg Roedel <joerg.roedel@amd.com>2012-06-25 07:50:43 -0400
commita3b24915456b63c9002e94152e122b07de5566f2 (patch)
treeef3cedd11e82d15e652fd5bcdd5dffd2db7dd18c /drivers/iommu
parent0760e8faa960f8ee991fa4acb802db4e20661281 (diff)
iommu/tegra: smmu: Simplify allocation at once
To simplify the code, alloc necessary data at once. Signed-off-by: Hiroshi DOYU <hdoyu@nvidia.com> Acked-by: Stephen Warren <swarren@wwwdotorg.org> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
Diffstat (limited to 'drivers/iommu')
-rw-r--r--drivers/iommu/tegra-smmu.c29
1 files changed, 9 insertions, 20 deletions
diff --git a/drivers/iommu/tegra-smmu.c b/drivers/iommu/tegra-smmu.c
index 2c92b8c3514e..98fcc7268eaf 100644
--- a/drivers/iommu/tegra-smmu.c
+++ b/drivers/iommu/tegra-smmu.c
@@ -241,8 +241,6 @@ struct smmu_device {
241 spinlock_t lock; 241 spinlock_t lock;
242 char *name; 242 char *name;
243 struct device *dev; 243 struct device *dev;
244 int num_as;
245 struct smmu_as *as; /* Run-time allocated array */
246 struct page *avp_vector_page; /* dummy page shared by all AS's */ 244 struct page *avp_vector_page; /* dummy page shared by all AS's */
247 245
248 /* 246 /*
@@ -254,6 +252,9 @@ struct smmu_device {
254 unsigned long asid_security; 252 unsigned long asid_security;
255 253
256 struct device_node *ahb; 254 struct device_node *ahb;
255
256 int num_as;
257 struct smmu_as as[0]; /* Run-time allocated array */
257}; 258};
258 259
259static struct smmu_device *smmu_handle; /* unique for a system */ 260static struct smmu_device *smmu_handle; /* unique for a system */
@@ -902,15 +903,18 @@ static int tegra_smmu_probe(struct platform_device *pdev)
902 struct device *dev = &pdev->dev; 903 struct device *dev = &pdev->dev;
903 int i, asids, err = 0; 904 int i, asids, err = 0;
904 dma_addr_t base; 905 dma_addr_t base;
905 size_t size; 906 size_t bytes, size;
906 const void *prop;
907 907
908 if (smmu_handle) 908 if (smmu_handle)
909 return -EIO; 909 return -EIO;
910 910
911 BUILD_BUG_ON(PAGE_SHIFT != SMMU_PAGE_SHIFT); 911 BUILD_BUG_ON(PAGE_SHIFT != SMMU_PAGE_SHIFT);
912 912
913 smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL); 913 if (of_property_read_u32(dev->of_node, "nvidia,#asids", &asids))
914 return -ENODEV;
915
916 bytes = sizeof(*smmu) + asids * sizeof(*smmu->as);
917 smmu = devm_kzalloc(dev, bytes, GFP_KERNEL);
914 if (!smmu) { 918 if (!smmu) {
915 dev_err(dev, "failed to allocate smmu_device\n"); 919 dev_err(dev, "failed to allocate smmu_device\n");
916 return -ENOMEM; 920 return -ENOMEM;
@@ -938,13 +942,6 @@ static int tegra_smmu_probe(struct platform_device *pdev)
938 if (!size) 942 if (!size)
939 return -EINVAL; 943 return -EINVAL;
940 944
941 prop = of_get_property(dev->of_node, "nvidia,#asids", NULL);
942 if (!prop)
943 return -ENODEV;
944 asids = be32_to_cpup(prop);
945 if (!asids)
946 return -ENODEV;
947
948 smmu->ahb = of_parse_phandle(dev->of_node, "nvidia,ahb", 0); 945 smmu->ahb = of_parse_phandle(dev->of_node, "nvidia,ahb", 0);
949 if (!smmu->ahb) 946 if (!smmu->ahb)
950 return -ENODEV; 947 return -ENODEV;
@@ -959,14 +956,6 @@ static int tegra_smmu_probe(struct platform_device *pdev)
959 smmu->translation_enable_2 = ~0; 956 smmu->translation_enable_2 = ~0;
960 smmu->asid_security = 0; 957 smmu->asid_security = 0;
961 958
962 smmu->as = devm_kzalloc(dev,
963 sizeof(smmu->as[0]) * smmu->num_as, GFP_KERNEL);
964 if (!smmu->as) {
965 dev_err(dev, "failed to allocate smmu_as\n");
966 err = -ENOMEM;
967 goto fail;
968 }
969
970 for (i = 0; i < smmu->num_as; i++) { 959 for (i = 0; i < smmu->num_as; i++) {
971 struct smmu_as *as = &smmu->as[i]; 960 struct smmu_as *as = &smmu->as[i];
972 961