@@ -667,7 +667,6 @@ struct arm_smmu_device {
667
667
668
668
#define ARM_SMMU_MAX_ASIDS (1 << 16)
669
669
unsigned int asid_bits ;
670
- DECLARE_BITMAP (asid_map , ARM_SMMU_MAX_ASIDS );
671
670
672
671
#define ARM_SMMU_MAX_VMIDS (1 << 16)
673
672
unsigned int vmid_bits ;
@@ -727,6 +726,8 @@ struct arm_smmu_option_prop {
727
726
const char * prop ;
728
727
};
729
728
729
+ static DEFINE_XARRAY_ALLOC1 (asid_xa );
730
+
730
731
static struct arm_smmu_option_prop arm_smmu_options [] = {
731
732
{ ARM_SMMU_OPT_SKIP_PREFETCH , "hisilicon,broken-prefetch-cmd" },
732
733
{ ARM_SMMU_OPT_PAGE0_REGS_ONLY , "cavium,cn9900-broken-page1-regspace" },
@@ -1765,6 +1766,14 @@ static void arm_smmu_free_cd_tables(struct arm_smmu_domain *smmu_domain)
1765
1766
cdcfg -> cdtab = NULL ;
1766
1767
}
1767
1768
1769
+ static void arm_smmu_free_asid (struct arm_smmu_ctx_desc * cd )
1770
+ {
1771
+ if (!cd -> asid )
1772
+ return ;
1773
+
1774
+ xa_erase (& asid_xa , cd -> asid );
1775
+ }
1776
+
1768
1777
/* Stream table manipulation functions */
1769
1778
static void
1770
1779
arm_smmu_write_strtab_l1_desc (__le64 * dst , struct arm_smmu_strtab_l1_desc * desc )
@@ -2450,10 +2459,9 @@ static void arm_smmu_domain_free(struct iommu_domain *domain)
2450
2459
if (smmu_domain -> stage == ARM_SMMU_DOMAIN_S1 ) {
2451
2460
struct arm_smmu_s1_cfg * cfg = & smmu_domain -> s1_cfg ;
2452
2461
2453
- if (cfg -> cdcfg .cdtab ) {
2462
+ if (cfg -> cdcfg .cdtab )
2454
2463
arm_smmu_free_cd_tables (smmu_domain );
2455
- arm_smmu_bitmap_free (smmu -> asid_map , cfg -> cd .asid );
2456
- }
2464
+ arm_smmu_free_asid (& cfg -> cd );
2457
2465
} else {
2458
2466
struct arm_smmu_s2_cfg * cfg = & smmu_domain -> s2_cfg ;
2459
2467
if (cfg -> vmid )
@@ -2468,14 +2476,15 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
2468
2476
struct io_pgtable_cfg * pgtbl_cfg )
2469
2477
{
2470
2478
int ret ;
2471
- int asid ;
2479
+ u32 asid ;
2472
2480
struct arm_smmu_device * smmu = smmu_domain -> smmu ;
2473
2481
struct arm_smmu_s1_cfg * cfg = & smmu_domain -> s1_cfg ;
2474
2482
typeof (& pgtbl_cfg -> arm_lpae_s1_cfg .tcr ) tcr = & pgtbl_cfg -> arm_lpae_s1_cfg .tcr ;
2475
2483
2476
- asid = arm_smmu_bitmap_alloc (smmu -> asid_map , smmu -> asid_bits );
2477
- if (asid < 0 )
2478
- return asid ;
2484
+ ret = xa_alloc (& asid_xa , & asid , & cfg -> cd ,
2485
+ XA_LIMIT (1 , (1 << smmu -> asid_bits ) - 1 ), GFP_KERNEL );
2486
+ if (ret )
2487
+ return ret ;
2479
2488
2480
2489
cfg -> s1cdmax = master -> ssid_bits ;
2481
2490
@@ -2508,7 +2517,7 @@ static int arm_smmu_domain_finalise_s1(struct arm_smmu_domain *smmu_domain,
2508
2517
out_free_cd_tables :
2509
2518
arm_smmu_free_cd_tables (smmu_domain );
2510
2519
out_free_asid :
2511
- arm_smmu_bitmap_free ( smmu -> asid_map , asid );
2520
+ arm_smmu_free_asid ( & cfg -> cd );
2512
2521
return ret ;
2513
2522
}
2514
2523
0 commit comments