[RFC PATCH 08/14] IOMMU: iommu_unique_seq_id()

Yinghai Lu
2012-04-03T02:20:25Z

So for hot-remove/hot-add will reuse seq_id.

Signed-off-by: Yinghai Lu <yinghai@kernel.org>
---
drivers/iommu/dmar.c | 16 ++++++++++++++--
1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/drivers/iommu/dmar.c b/drivers/iommu/dmar.c
index fde4991..043192e 100644
--- a/drivers/iommu/dmar.c
+++ b/drivers/iommu/dmar.c
@@ -707,13 +707,23 @@ int __init detect_intel_iommu(void)
return ret ? 1 : -ENODEV;
}

+static DECLARE_BITMAP(iommu_allocated, 1024);
+
+static int iommu_unique_seq_id(void)
+{
+ int id;
+
+ id = find_first_zero_bit(iommu_allocated, 1024);
+ __set_bit(id, iommu_allocated);
+
+ return id;
+}

int alloc_iommu(struct dmar_drhd_unit *drhd)
{
struct intel_iommu *iommu;
int map_size;
u32 ver;
- static int iommu_allocated = 0;
int agaw = 0;
int msagaw = 0;

@@ -726,7 +736,7 @@ int alloc_iommu(struct dmar_drhd_unit *drhd)
if (!iommu)
return -ENOMEM;

- iommu->seq_id = iommu_allocated++;
+ iommu->seq_id = iommu_unique_seq_id();
sprintf (iommu->name, "dmar%d", iommu->seq_id);

iommu->reg = ioremap(drhd->reg_base_addr, VTD_PAGE_SIZE);
@@ -790,6 +800,7 @@ int alloc_iommu(struct dmar_drhd_unit *drhd)
err_unmap:
iounmap(iommu->reg);
error:
+ __clear_bit(iommu->seq_id, iommu_allocated);
kfree(iommu);
return -1;
}
@@ -803,6 +814,7 @@ void free_iommu(struct intel_iommu *iommu)

if (iommu->reg)
iounmap(iommu->reg);
+ __clear_bit(iommu->seq_id, iommu_allocated);
kfree(iommu);
}

--
1.7.7