Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 125606
b: refs/heads/master
c: 5b28df6
h: refs/heads/master
v: v3
  • Loading branch information
Joerg Roedel committed Jan 3, 2009
1 parent 8f4318c commit cba96f8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 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: 9fdb19d64c0247f23343b51fc85f438f8e7a2f3c
refs/heads/master: 5b28df6f43ac9878f310ad0cb7f11ddb262a7ac6
41 changes: 35 additions & 6 deletions trunk/arch/x86/kernel/amd_iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,15 @@ static struct dma_ops_domain *dma_ops_domain_alloc(struct amd_iommu *iommu,
return NULL;
}

/*
* little helper function to check whether a given protection domain is a
* dma_ops domain
*/
static bool dma_ops_domain(struct protection_domain *domain)
{
return domain->flags & PD_DMA_OPS_MASK;
}

/*
* Find out the protection domain structure for a given PCI device. This
* will give us the pointer to the page table root for example.
Expand Down Expand Up @@ -1096,6 +1105,9 @@ static dma_addr_t map_single(struct device *dev, phys_addr_t paddr,
/* device not handled by any AMD IOMMU */
return (dma_addr_t)paddr;

if (!dma_ops_domain(domain))
return bad_dma_address;

spin_lock_irqsave(&domain->lock, flags);
addr = __map_single(dev, iommu, domain->priv, paddr, size, dir, false,
dma_mask);
Expand Down Expand Up @@ -1126,6 +1138,9 @@ static void unmap_single(struct device *dev, dma_addr_t dma_addr,
/* device not handled by any AMD IOMMU */
return;

if (!dma_ops_domain(domain))
return;

spin_lock_irqsave(&domain->lock, flags);

__unmap_single(iommu, domain->priv, dma_addr, size, dir);
Expand Down Expand Up @@ -1180,6 +1195,9 @@ static int map_sg(struct device *dev, struct scatterlist *sglist,
if (!iommu || !domain)
return map_sg_no_iommu(dev, sglist, nelems, dir);

if (!dma_ops_domain(domain))
return 0;

spin_lock_irqsave(&domain->lock, flags);

for_each_sg(sglist, s, nelems, i) {
Expand Down Expand Up @@ -1233,6 +1251,9 @@ static void unmap_sg(struct device *dev, struct scatterlist *sglist,
!get_device_resources(dev, &iommu, &domain, &devid))
return;

if (!dma_ops_domain(domain))
return;

spin_lock_irqsave(&domain->lock, flags);

for_each_sg(sglist, s, nelems, i) {
Expand Down Expand Up @@ -1278,6 +1299,9 @@ static void *alloc_coherent(struct device *dev, size_t size,
return virt_addr;
}

if (!dma_ops_domain(domain))
goto out_free;

if (!dma_mask)
dma_mask = *dev->dma_mask;

Expand All @@ -1286,18 +1310,20 @@ static void *alloc_coherent(struct device *dev, size_t size,
*dma_addr = __map_single(dev, iommu, domain->priv, paddr,
size, DMA_BIDIRECTIONAL, true, dma_mask);

if (*dma_addr == bad_dma_address) {
free_pages((unsigned long)virt_addr, get_order(size));
virt_addr = NULL;
goto out;
}
if (*dma_addr == bad_dma_address)
goto out_free;

iommu_completion_wait(iommu);

out:
spin_unlock_irqrestore(&domain->lock, flags);

return virt_addr;

out_free:

free_pages((unsigned long)virt_addr, get_order(size));

return NULL;
}

/*
Expand All @@ -1319,6 +1345,9 @@ static void free_coherent(struct device *dev, size_t size,
if (!iommu || !domain)
goto free_mem;

if (!dma_ops_domain(domain))
goto free_mem;

spin_lock_irqsave(&domain->lock, flags);

__unmap_single(iommu, domain->priv, dma_addr, size, DMA_BIDIRECTIONAL);
Expand Down

0 comments on commit cba96f8

Please sign in to comment.