@@ -177,9 +177,6 @@ LIST_HEAD(amd_iommu_pci_seg_list); /* list of all PCI segments */
177177LIST_HEAD (amd_iommu_list ); /* list of all AMD IOMMUs in the
178178 system */
179179
180- /* Array to assign indices to IOMMUs*/
181- struct amd_iommu * amd_iommus [MAX_IOMMUS ];
182-
183180/* Number of IOMMUs present in the system */
184181static int amd_iommus_present ;
185182
@@ -194,12 +191,6 @@ bool amd_iommu_force_isolation __read_mostly;
194191
195192unsigned long amd_iommu_pgsize_bitmap __ro_after_init = AMD_IOMMU_PGSIZES ;
196193
197- /*
198- * AMD IOMMU allows up to 2^16 different protection domains. This is a bitmap
199- * to know which ones are already in use.
200- */
201- unsigned long * amd_iommu_pd_alloc_bitmap ;
202-
203194enum iommu_init_state {
204195 IOMMU_START_STATE ,
205196 IOMMU_IVRS_DETECTED ,
@@ -1082,7 +1073,12 @@ static bool __copy_device_table(struct amd_iommu *iommu)
10821073 if (dte_v && dom_id ) {
10831074 pci_seg -> old_dev_tbl_cpy [devid ].data [0 ] = old_devtb [devid ].data [0 ];
10841075 pci_seg -> old_dev_tbl_cpy [devid ].data [1 ] = old_devtb [devid ].data [1 ];
1085- __set_bit (dom_id , amd_iommu_pd_alloc_bitmap );
1076+ /* Reserve the Domain IDs used by previous kernel */
1077+ if (ida_alloc_range (& pdom_ids , dom_id , dom_id , GFP_ATOMIC ) != dom_id ) {
1078+ pr_err ("Failed to reserve domain ID 0x%x\n" , dom_id );
1079+ memunmap (old_devtb );
1080+ return false;
1081+ }
10861082 /* If gcr3 table existed, mask it out */
10871083 if (old_devtb [devid ].data [0 ] & DTE_FLAG_GV ) {
10881084 tmp = DTE_GCR3_VAL_B (~0ULL ) << DTE_GCR3_SHIFT_B ;
@@ -1744,9 +1740,6 @@ static int __init init_iommu_one(struct amd_iommu *iommu, struct ivhd_header *h,
17441740 return - ENOSYS ;
17451741 }
17461742
1747- /* Index is fine - add IOMMU to the array */
1748- amd_iommus [iommu -> index ] = iommu ;
1749-
17501743 /*
17511744 * Copy data from ACPI table entry to the iommu struct
17521745 */
@@ -2877,11 +2870,6 @@ static void enable_iommus_vapic(void)
28772870#endif
28782871}
28792872
2880- static void enable_iommus (void )
2881- {
2882- early_enable_iommus ();
2883- }
2884-
28852873static void disable_iommus (void )
28862874{
28872875 struct amd_iommu * iommu ;
@@ -2908,7 +2896,8 @@ static void amd_iommu_resume(void)
29082896 iommu_apply_resume_quirks (iommu );
29092897
29102898 /* re-load the hardware */
2911- enable_iommus ();
2899+ for_each_iommu (iommu )
2900+ early_enable_iommu (iommu );
29122901
29132902 amd_iommu_enable_interrupts ();
29142903}
@@ -2989,9 +2978,7 @@ static bool __init check_ioapic_information(void)
29892978
29902979static void __init free_dma_resources (void )
29912980{
2992- iommu_free_pages (amd_iommu_pd_alloc_bitmap ,
2993- get_order (MAX_DOMAIN_ID / 8 ));
2994- amd_iommu_pd_alloc_bitmap = NULL ;
2981+ ida_destroy (& pdom_ids );
29952982
29962983 free_unity_maps ();
29972984}
@@ -3059,20 +3046,6 @@ static int __init early_amd_iommu_init(void)
30593046 amd_iommu_target_ivhd_type = get_highest_supported_ivhd_type (ivrs_base );
30603047 DUMP_printk ("Using IVHD type %#x\n" , amd_iommu_target_ivhd_type );
30613048
3062- /* Device table - directly used by all IOMMUs */
3063- ret = - ENOMEM ;
3064-
3065- amd_iommu_pd_alloc_bitmap = iommu_alloc_pages (GFP_KERNEL ,
3066- get_order (MAX_DOMAIN_ID / 8 ));
3067- if (amd_iommu_pd_alloc_bitmap == NULL )
3068- goto out ;
3069-
3070- /*
3071- * never allocate domain 0 because its used as the non-allocated and
3072- * error value placeholder
3073- */
3074- __set_bit (0 , amd_iommu_pd_alloc_bitmap );
3075-
30763049 /*
30773050 * now the data structures are allocated and basically initialized
30783051 * start the real acpi table scan
0 commit comments