mirror of
https://github.com/rd-stuffs/msm-4.14.git
synced 2025-02-20 11:45:48 +08:00
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>
This commit is contained in:
parent
0760e8faa9
commit
a3b2491545
@ -241,8 +241,6 @@ struct smmu_device {
|
|||||||
spinlock_t lock;
|
spinlock_t lock;
|
||||||
char *name;
|
char *name;
|
||||||
struct device *dev;
|
struct device *dev;
|
||||||
int num_as;
|
|
||||||
struct smmu_as *as; /* Run-time allocated array */
|
|
||||||
struct page *avp_vector_page; /* dummy page shared by all AS's */
|
struct page *avp_vector_page; /* dummy page shared by all AS's */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -254,6 +252,9 @@ struct smmu_device {
|
|||||||
unsigned long asid_security;
|
unsigned long asid_security;
|
||||||
|
|
||||||
struct device_node *ahb;
|
struct device_node *ahb;
|
||||||
|
|
||||||
|
int num_as;
|
||||||
|
struct smmu_as as[0]; /* Run-time allocated array */
|
||||||
};
|
};
|
||||||
|
|
||||||
static struct smmu_device *smmu_handle; /* unique for a system */
|
static struct smmu_device *smmu_handle; /* unique for a system */
|
||||||
@ -902,15 +903,18 @@ static int tegra_smmu_probe(struct platform_device *pdev)
|
|||||||
struct device *dev = &pdev->dev;
|
struct device *dev = &pdev->dev;
|
||||||
int i, asids, err = 0;
|
int i, asids, err = 0;
|
||||||
dma_addr_t base;
|
dma_addr_t base;
|
||||||
size_t size;
|
size_t bytes, size;
|
||||||
const void *prop;
|
|
||||||
|
|
||||||
if (smmu_handle)
|
if (smmu_handle)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
BUILD_BUG_ON(PAGE_SHIFT != SMMU_PAGE_SHIFT);
|
BUILD_BUG_ON(PAGE_SHIFT != SMMU_PAGE_SHIFT);
|
||||||
|
|
||||||
smmu = devm_kzalloc(dev, sizeof(*smmu), GFP_KERNEL);
|
if (of_property_read_u32(dev->of_node, "nvidia,#asids", &asids))
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
|
bytes = sizeof(*smmu) + asids * sizeof(*smmu->as);
|
||||||
|
smmu = devm_kzalloc(dev, bytes, GFP_KERNEL);
|
||||||
if (!smmu) {
|
if (!smmu) {
|
||||||
dev_err(dev, "failed to allocate smmu_device\n");
|
dev_err(dev, "failed to allocate smmu_device\n");
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
@ -938,13 +942,6 @@ static int tegra_smmu_probe(struct platform_device *pdev)
|
|||||||
if (!size)
|
if (!size)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
prop = of_get_property(dev->of_node, "nvidia,#asids", NULL);
|
|
||||||
if (!prop)
|
|
||||||
return -ENODEV;
|
|
||||||
asids = be32_to_cpup(prop);
|
|
||||||
if (!asids)
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
smmu->ahb = of_parse_phandle(dev->of_node, "nvidia,ahb", 0);
|
smmu->ahb = of_parse_phandle(dev->of_node, "nvidia,ahb", 0);
|
||||||
if (!smmu->ahb)
|
if (!smmu->ahb)
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
@ -959,14 +956,6 @@ static int tegra_smmu_probe(struct platform_device *pdev)
|
|||||||
smmu->translation_enable_2 = ~0;
|
smmu->translation_enable_2 = ~0;
|
||||||
smmu->asid_security = 0;
|
smmu->asid_security = 0;
|
||||||
|
|
||||||
smmu->as = devm_kzalloc(dev,
|
|
||||||
sizeof(smmu->as[0]) * smmu->num_as, GFP_KERNEL);
|
|
||||||
if (!smmu->as) {
|
|
||||||
dev_err(dev, "failed to allocate smmu_as\n");
|
|
||||||
err = -ENOMEM;
|
|
||||||
goto fail;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < smmu->num_as; i++) {
|
for (i = 0; i < smmu->num_as; i++) {
|
||||||
struct smmu_as *as = &smmu->as[i];
|
struct smmu_as *as = &smmu->as[i];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user