Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 316591
b: refs/heads/master
c: 9e971a0
h: refs/heads/master
i:
  316589: 9fd8a63
  316587: 074c614
  316583: 5a5394d
  316575: 5ac7f0e
v: v3
  • Loading branch information
Hiroshi DOYU authored and Joerg Roedel committed Jul 17, 2012
1 parent ec36e79 commit 10b6cf8
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 0bdbf4ccef4f87016e2fa0c0b34f7a025f364c3d
refs/heads/master: 9e971a03af736acc6f96c200c2626d3bcb3d6927
77 changes: 45 additions & 32 deletions trunk/drivers/iommu/tegra-smmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -555,28 +555,39 @@ static inline void put_signature(struct smmu_as *as,
/*
* Caller must lock/unlock as
*/
static int alloc_pdir(struct smmu_as *as)
static int alloc_pdir(struct smmu_as *as, unsigned long *flags)
{
unsigned long *pdir;
int pdn;
int pdn, err = 0;
u32 val;
struct smmu_device *smmu = as->smmu;
struct page *page;
unsigned int *cnt;

as->pte_count = devm_kzalloc(smmu->dev,
sizeof(as->pte_count[0]) * SMMU_PDIR_COUNT, GFP_KERNEL);
if (!as->pte_count) {
dev_err(smmu->dev,
"failed to allocate smmu_device PTE cunters\n");
return -ENOMEM;
/*
* do the allocation outside the as->lock
*/
spin_unlock_irqrestore(&as->lock, *flags);
cnt = devm_kzalloc(smmu->dev,
sizeof(cnt[0]) * SMMU_PDIR_COUNT, GFP_KERNEL);
page = alloc_page(GFP_KERNEL | __GFP_DMA);
spin_lock_irqsave(&as->lock, *flags);

if (as->pdir_page) {
/* We raced, free the redundant */
err = -EAGAIN;
goto err_out;
}
as->pdir_page = alloc_page(GFP_KERNEL | __GFP_DMA);
if (!as->pdir_page) {
dev_err(smmu->dev,
"failed to allocate smmu_device page directory\n");
devm_kfree(smmu->dev, as->pte_count);
as->pte_count = NULL;
return -ENOMEM;

if (!page || !cnt) {
dev_err(smmu->dev, "failed to allocate at %s\n", __func__);
err = -ENOMEM;
goto err_out;
}

as->pdir_page = page;
as->pte_count = cnt;

SetPageReserved(as->pdir_page);
pdir = page_address(as->pdir_page);

Expand All @@ -593,6 +604,12 @@ static int alloc_pdir(struct smmu_as *as)
FLUSH_SMMU_REGS(as->smmu);

return 0;

err_out:
devm_kfree(smmu->dev, cnt);
if (page)
__free_page(page);
return err;
}

static void __smmu_iommu_unmap(struct smmu_as *as, dma_addr_t iova)
Expand Down Expand Up @@ -784,29 +801,29 @@ static void smmu_iommu_detach_dev(struct iommu_domain *domain,

static int smmu_iommu_domain_init(struct iommu_domain *domain)
{
int i;
int i, err = -ENODEV;
unsigned long flags;
struct smmu_as *as;
struct smmu_device *smmu = smmu_handle;

/* Look for a free AS with lock held */
for (i = 0; i < smmu->num_as; i++) {
struct smmu_as *tmp = &smmu->as[i];

spin_lock_irqsave(&tmp->lock, flags);
if (!tmp->pdir_page) {
as = tmp;
goto found;
as = &smmu->as[i];
spin_lock_irqsave(&as->lock, flags);
if (!as->pdir_page) {
err = alloc_pdir(as, &flags);
if (!err)
goto found;
}
spin_unlock_irqrestore(&tmp->lock, flags);
spin_unlock_irqrestore(&as->lock, flags);
if (err != -EAGAIN)
break;
}
dev_err(smmu->dev, "no free AS\n");
return -ENODEV;
if (i == smmu->num_as)
dev_err(smmu->dev, "no free AS\n");
return err;

found:
if (alloc_pdir(as) < 0)
goto err_alloc_pdir;

spin_lock(&smmu->lock);

/* Update PDIR register */
Expand All @@ -822,10 +839,6 @@ static int smmu_iommu_domain_init(struct iommu_domain *domain)

dev_dbg(smmu->dev, "smmu_as@%p\n", as);
return 0;

err_alloc_pdir:
spin_unlock_irqrestore(&as->lock, flags);
return -ENODEV;
}

static void smmu_iommu_domain_destroy(struct iommu_domain *domain)
Expand Down

0 comments on commit 10b6cf8

Please sign in to comment.