Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 154774
b: refs/heads/master
c: 61df744
h: refs/heads/master
v: v3
  • Loading branch information
David Woodhouse authored and David Woodhouse committed Jun 29, 2009
1 parent fcaede0 commit cc20efc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 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: 1c5a46ed49e37f56f8aa9000bb1c2ac59670c372
refs/heads/master: 61df744314079e8cb8cdec75f517cf0e704e41ef
38 changes: 24 additions & 14 deletions trunk/drivers/pci/intel-iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1643,40 +1643,48 @@ static int domain_context_mapped(struct pci_dev *pdev)
tmp->devfn);
}

static int
domain_page_mapping(struct dmar_domain *domain, dma_addr_t iova,
u64 hpa, size_t size, int prot)
static int domain_pfn_mapping(struct dmar_domain *domain, unsigned long iov_pfn,
unsigned long phys_pfn, unsigned long nr_pages,
int prot)
{
unsigned long start_pfn = hpa >> VTD_PAGE_SHIFT;
unsigned long last_pfn = (hpa + size - 1) >> VTD_PAGE_SHIFT;
struct dma_pte *pte;
int index = 0;
int addr_width = agaw_to_width(domain->agaw) - VTD_PAGE_SHIFT;

BUG_ON(addr_width < BITS_PER_LONG && last_pfn >> addr_width);
BUG_ON(addr_width < BITS_PER_LONG && (iov_pfn + nr_pages - 1) >> addr_width);

if ((prot & (DMA_PTE_READ|DMA_PTE_WRITE)) == 0)
return -EINVAL;

while (start_pfn <= last_pfn) {
pte = pfn_to_dma_pte(domain, (iova >> VTD_PAGE_SHIFT) + index);
while (nr_pages--) {
pte = pfn_to_dma_pte(domain, iov_pfn);
if (!pte)
return -ENOMEM;
/* We don't need lock here, nobody else
* touches the iova range
*/
BUG_ON(dma_pte_addr(pte));
dma_set_pte_pfn(pte, start_pfn);
dma_set_pte_pfn(pte, phys_pfn);
dma_set_pte_prot(pte, prot);
if (prot & DMA_PTE_SNP)
dma_set_pte_snp(pte);
domain_flush_cache(domain, pte, sizeof(*pte));
start_pfn++;
index++;
iov_pfn++;
phys_pfn++;
}
return 0;
}

static int domain_page_mapping(struct dmar_domain *domain, dma_addr_t iova,
u64 hpa, size_t size, int prot)
{
unsigned long first_pfn = hpa >> VTD_PAGE_SHIFT;
unsigned long last_pfn = (hpa + size - 1) >> VTD_PAGE_SHIFT;

return domain_pfn_mapping(domain, iova >> VTD_PAGE_SHIFT, first_pfn,
last_pfn - first_pfn + 1, prot);

}

static void iommu_detach_dev(struct intel_iommu *iommu, u8 bus, u8 devfn)
{
if (!iommu)
Expand Down Expand Up @@ -1893,8 +1901,10 @@ static int iommu_domain_identity_map(struct dmar_domain *domain,
dma_pte_clear_range(domain, base >> VTD_PAGE_SHIFT,
(base + size - 1) >> VTD_PAGE_SHIFT);

return domain_page_mapping(domain, base, base, size,
DMA_PTE_READ|DMA_PTE_WRITE);
return domain_pfn_mapping(domain, base >> VTD_PAGE_SHIFT,
base >> VTD_PAGE_SHIFT,
size >> VTD_PAGE_SHIFT,
DMA_PTE_READ|DMA_PTE_WRITE);
}

static int iommu_prepare_identity_map(struct pci_dev *pdev,
Expand Down

0 comments on commit cc20efc

Please sign in to comment.