Skip to content

Commit c7fe938

Browse files
sarunkodjoergroedel
authored andcommitted
amd/iommu: Make protection domain ID functions non-static
So that both iommu.c and init.c can utilize them. Also define a new function 'pdom_id_destroy()' to destroy 'pdom_ids' instead of directly calling ida functions. Signed-off-by: Sairaj Kodilkar <sarunkod@amd.com> Reviewed-by: Vasant Hegde <vasant.hegde@amd.com> Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
1 parent c2e8dc1 commit c7fe938

3 files changed

Lines changed: 25 additions & 14 deletions

File tree

drivers/iommu/amd/amd_iommu.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,11 @@ static inline struct protection_domain *to_pdomain(struct iommu_domain *dom)
173173
bool translation_pre_enabled(struct amd_iommu *iommu);
174174
int __init add_special_device(u8 type, u8 id, u32 *devid, bool cmd_line);
175175

176+
int amd_iommu_pdom_id_alloc(void);
177+
int amd_iommu_pdom_id_reserve(u16 id, gfp_t gfp);
178+
void amd_iommu_pdom_id_free(int id);
179+
void amd_iommu_pdom_id_destroy(void);
180+
176181
#ifdef CONFIG_DMI
177182
void amd_iommu_apply_ivrs_quirks(void);
178183
#else

drivers/iommu/amd/init.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,6 @@ static bool __reuse_device_table(struct amd_iommu *iommu)
11421142
u16 dom_id;
11431143
bool dte_v;
11441144
u64 entry;
1145-
int ret;
11461145

11471146
/* Each IOMMU use separate device table with the same size */
11481147
lo = readl(iommu->mmio_base + MMIO_DEV_TABLE_OFFSET);
@@ -1189,8 +1188,7 @@ static bool __reuse_device_table(struct amd_iommu *iommu)
11891188
* are multiple devices present in the same domain,
11901189
* hence check only for -ENOMEM.
11911190
*/
1192-
ret = ida_alloc_range(&pdom_ids, dom_id, dom_id, GFP_KERNEL);
1193-
if (ret == -ENOMEM)
1191+
if (amd_iommu_pdom_id_reserve(dom_id, GFP_KERNEL) == -ENOMEM)
11941192
return false;
11951193
}
11961194

@@ -3148,8 +3146,7 @@ static bool __init check_ioapic_information(void)
31483146

31493147
static void __init free_dma_resources(void)
31503148
{
3151-
ida_destroy(&pdom_ids);
3152-
3149+
amd_iommu_pdom_id_destroy();
31533150
free_unity_maps();
31543151
}
31553152

drivers/iommu/amd/iommu.c

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,17 +1811,26 @@ int amd_iommu_complete_ppr(struct device *dev, u32 pasid, int status, int tag)
18111811
* contain.
18121812
*
18131813
****************************************************************************/
1814-
1815-
static int pdom_id_alloc(void)
1814+
int amd_iommu_pdom_id_alloc(void)
18161815
{
18171816
return ida_alloc_range(&pdom_ids, 1, MAX_DOMAIN_ID - 1, GFP_ATOMIC);
18181817
}
18191818

1820-
static void pdom_id_free(int id)
1819+
int amd_iommu_pdom_id_reserve(u16 id, gfp_t gfp)
1820+
{
1821+
return ida_alloc_range(&pdom_ids, id, id, gfp);
1822+
}
1823+
1824+
void amd_iommu_pdom_id_free(int id)
18211825
{
18221826
ida_free(&pdom_ids, id);
18231827
}
18241828

1829+
void amd_iommu_pdom_id_destroy(void)
1830+
{
1831+
ida_destroy(&pdom_ids);
1832+
}
1833+
18251834
static void free_gcr3_tbl_level1(u64 *tbl)
18261835
{
18271836
u64 *ptr;
@@ -1864,7 +1873,7 @@ static void free_gcr3_table(struct gcr3_tbl_info *gcr3_info)
18641873
gcr3_info->glx = 0;
18651874

18661875
/* Free per device domain ID */
1867-
pdom_id_free(gcr3_info->domid);
1876+
amd_iommu_pdom_id_free(gcr3_info->domid);
18681877

18691878
iommu_free_pages(gcr3_info->gcr3_tbl);
18701879
gcr3_info->gcr3_tbl = NULL;
@@ -1900,14 +1909,14 @@ static int setup_gcr3_table(struct gcr3_tbl_info *gcr3_info,
19001909
return -EBUSY;
19011910

19021911
/* Allocate per device domain ID */
1903-
domid = pdom_id_alloc();
1912+
domid = amd_iommu_pdom_id_alloc();
19041913
if (domid <= 0)
19051914
return -ENOSPC;
19061915
gcr3_info->domid = domid;
19071916

19081917
gcr3_info->gcr3_tbl = iommu_alloc_pages_node_sz(nid, GFP_ATOMIC, SZ_4K);
19091918
if (gcr3_info->gcr3_tbl == NULL) {
1910-
pdom_id_free(domid);
1919+
amd_iommu_pdom_id_free(domid);
19111920
return -ENOMEM;
19121921
}
19131922

@@ -2503,7 +2512,7 @@ struct protection_domain *protection_domain_alloc(void)
25032512
if (!domain)
25042513
return NULL;
25052514

2506-
domid = pdom_id_alloc();
2515+
domid = amd_iommu_pdom_id_alloc();
25072516
if (domid <= 0) {
25082517
kfree(domain);
25092518
return NULL;
@@ -2802,7 +2811,7 @@ void amd_iommu_domain_free(struct iommu_domain *dom)
28022811

28032812
WARN_ON(!list_empty(&domain->dev_list));
28042813
pt_iommu_deinit(&domain->iommu);
2805-
pdom_id_free(domain->id);
2814+
amd_iommu_pdom_id_free(domain->id);
28062815
kfree(domain);
28072816
}
28082817

@@ -2853,7 +2862,7 @@ void amd_iommu_init_identity_domain(void)
28532862
domain->ops = &identity_domain_ops;
28542863
domain->owner = &amd_iommu_ops;
28552864

2856-
identity_domain.id = pdom_id_alloc();
2865+
identity_domain.id = amd_iommu_pdom_id_alloc();
28572866

28582867
protection_domain_init(&identity_domain);
28592868
}

0 commit comments

Comments
 (0)