Skip to content

Commit 913432f

Browse files
LuBaolujoergroedel
authored andcommitted
iommu/vt-d: Use IDA interface to manage iommu sequence id
Switch dmar unit sequence id allocation and release from bitmap to IDA interface. Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Reviewed-by: Steve Wahl <steve.wahl@hpe.com> Link: https://lore.kernel.org/r/20220702015610.2849494-3-baolu.lu@linux.intel.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent c3f27c8 commit 913432f

1 file changed

Lines changed: 8 additions & 27 deletions

File tree

drivers/iommu/intel/dmar.c

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ LIST_HEAD(dmar_drhd_units);
6060

6161
struct acpi_table_header * __initdata dmar_tbl;
6262
static int dmar_dev_scope_status = 1;
63-
static unsigned long dmar_seq_ids[BITS_TO_LONGS(DMAR_UNITS_SUPPORTED)];
63+
static DEFINE_IDA(dmar_seq_ids);
6464

6565
static int alloc_iommu(struct dmar_drhd_unit *drhd);
6666
static void free_iommu(struct intel_iommu *iommu);
@@ -1023,28 +1023,6 @@ static int map_iommu(struct intel_iommu *iommu, u64 phys_addr)
10231023
return err;
10241024
}
10251025

1026-
static int dmar_alloc_seq_id(struct intel_iommu *iommu)
1027-
{
1028-
iommu->seq_id = find_first_zero_bit(dmar_seq_ids,
1029-
DMAR_UNITS_SUPPORTED);
1030-
if (iommu->seq_id >= DMAR_UNITS_SUPPORTED) {
1031-
iommu->seq_id = -1;
1032-
} else {
1033-
set_bit(iommu->seq_id, dmar_seq_ids);
1034-
sprintf(iommu->name, "dmar%d", iommu->seq_id);
1035-
}
1036-
1037-
return iommu->seq_id;
1038-
}
1039-
1040-
static void dmar_free_seq_id(struct intel_iommu *iommu)
1041-
{
1042-
if (iommu->seq_id >= 0) {
1043-
clear_bit(iommu->seq_id, dmar_seq_ids);
1044-
iommu->seq_id = -1;
1045-
}
1046-
}
1047-
10481026
static int alloc_iommu(struct dmar_drhd_unit *drhd)
10491027
{
10501028
struct intel_iommu *iommu;
@@ -1062,11 +1040,14 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd)
10621040
if (!iommu)
10631041
return -ENOMEM;
10641042

1065-
if (dmar_alloc_seq_id(iommu) < 0) {
1043+
iommu->seq_id = ida_alloc_range(&dmar_seq_ids, 0,
1044+
DMAR_UNITS_SUPPORTED - 1, GFP_KERNEL);
1045+
if (iommu->seq_id < 0) {
10661046
pr_err("Failed to allocate seq_id\n");
1067-
err = -ENOSPC;
1047+
err = iommu->seq_id;
10681048
goto error;
10691049
}
1050+
sprintf(iommu->name, "dmar%d", iommu->seq_id);
10701051

10711052
err = map_iommu(iommu, drhd->reg_base_addr);
10721053
if (err) {
@@ -1150,7 +1131,7 @@ static int alloc_iommu(struct dmar_drhd_unit *drhd)
11501131
err_unmap:
11511132
unmap_iommu(iommu);
11521133
error_free_seq_id:
1153-
dmar_free_seq_id(iommu);
1134+
ida_free(&dmar_seq_ids, iommu->seq_id);
11541135
error:
11551136
kfree(iommu);
11561137
return err;
@@ -1183,7 +1164,7 @@ static void free_iommu(struct intel_iommu *iommu)
11831164
if (iommu->reg)
11841165
unmap_iommu(iommu);
11851166

1186-
dmar_free_seq_id(iommu);
1167+
ida_free(&dmar_seq_ids, iommu->seq_id);
11871168
kfree(iommu);
11881169
}
11891170

0 commit comments

Comments
 (0)