Skip to content

Commit

Permalink
x86/amd-iommu: Add per IOMMU reference counting
Browse files Browse the repository at this point in the history
This patch adds reference counting for protection domains
per IOMMU. This allows a smarter TLB flushing strategy.

Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
  • Loading branch information
Joerg Roedel committed Nov 27, 2009
1 parent bb52777 commit c459611
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 2 additions & 0 deletions arch/x86/include/asm/amd_iommu_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,9 @@ struct protection_domain {
unsigned long flags; /* flags to find out type of domain */
bool updated; /* complete domain flush required */
unsigned dev_cnt; /* devices assigned to this domain */
unsigned dev_iommu[MAX_IOMMUS]; /* per-IOMMU reference count */
void *priv; /* private data */

};

/*
Expand Down
12 changes: 9 additions & 3 deletions arch/x86/kernel/amd_iommu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,9 @@ static void __attach_device(struct amd_iommu *iommu,
/* update DTE entry */
set_dte_entry(devid, domain);

domain->dev_cnt += 1;
/* Do reference counting */
domain->dev_iommu[iommu->index] += 1;
domain->dev_cnt += 1;

/* ready */
spin_unlock(&domain->lock);
Expand Down Expand Up @@ -1209,6 +1211,9 @@ static void attach_device(struct amd_iommu *iommu,
*/
static void __detach_device(struct protection_domain *domain, u16 devid)
{
struct amd_iommu *iommu = amd_iommu_rlookup_table[devid];

BUG_ON(!iommu);

/* lock domain */
spin_lock(&domain->lock);
Expand All @@ -1223,8 +1228,9 @@ static void __detach_device(struct protection_domain *domain, u16 devid)

amd_iommu_apply_erratum_63(devid);

/* decrease reference counter */
domain->dev_cnt -= 1;
/* decrease reference counters */
domain->dev_iommu[iommu->index] -= 1;
domain->dev_cnt -= 1;

/* ready */
spin_unlock(&domain->lock);
Expand Down

0 comments on commit c459611

Please sign in to comment.