@@ -101,7 +101,6 @@ struct iommu_cmd {
101
101
struct kmem_cache * amd_iommu_irq_cache ;
102
102
103
103
static void update_domain (struct protection_domain * domain );
104
- static int protection_domain_init (struct protection_domain * domain , int mode );
105
104
static void detach_device (struct device * dev );
106
105
static void update_and_flush_device_table (struct protection_domain * domain ,
107
106
struct domain_pgtable * pgtable );
@@ -1818,58 +1817,6 @@ static void free_gcr3_table(struct protection_domain *domain)
1818
1817
free_page ((unsigned long )domain -> gcr3_tbl );
1819
1818
}
1820
1819
1821
- /*
1822
- * Free a domain, only used if something went wrong in the
1823
- * allocation path and we need to free an already allocated page table
1824
- */
1825
- static void dma_ops_domain_free (struct protection_domain * domain )
1826
- {
1827
- struct domain_pgtable pgtable ;
1828
-
1829
- if (!domain )
1830
- return ;
1831
-
1832
- iommu_put_dma_cookie (& domain -> domain );
1833
-
1834
- amd_iommu_domain_get_pgtable (domain , & pgtable );
1835
- atomic64_set (& domain -> pt_root , 0 );
1836
- free_pagetable (& pgtable );
1837
-
1838
- if (domain -> id )
1839
- domain_id_free (domain -> id );
1840
-
1841
- kfree (domain );
1842
- }
1843
-
1844
- /*
1845
- * Allocates a new protection domain usable for the dma_ops functions.
1846
- * It also initializes the page table and the address allocator data
1847
- * structures required for the dma_ops interface
1848
- */
1849
- static struct protection_domain * dma_ops_domain_alloc (void )
1850
- {
1851
- struct protection_domain * domain ;
1852
-
1853
- domain = kzalloc (sizeof (struct protection_domain ), GFP_KERNEL );
1854
- if (!domain )
1855
- return NULL ;
1856
-
1857
- if (protection_domain_init (domain , DEFAULT_PGTABLE_LEVEL ))
1858
- goto free_domain ;
1859
-
1860
- domain -> flags = PD_DMA_OPS_MASK ;
1861
-
1862
- if (iommu_get_dma_cookie (& domain -> domain ) == - ENOMEM )
1863
- goto free_domain ;
1864
-
1865
- return domain ;
1866
-
1867
- free_domain :
1868
- dma_ops_domain_free (domain );
1869
-
1870
- return NULL ;
1871
- }
1872
-
1873
1820
/*
1874
1821
* little helper function to check whether a given protection domain is a
1875
1822
* dma_ops domain
@@ -2447,36 +2394,32 @@ static struct protection_domain *protection_domain_alloc(int mode)
2447
2394
2448
2395
static struct iommu_domain * amd_iommu_domain_alloc (unsigned type )
2449
2396
{
2450
- struct protection_domain * pdomain ;
2451
-
2452
- switch (type ) {
2453
- case IOMMU_DOMAIN_UNMANAGED :
2454
- pdomain = protection_domain_alloc (DEFAULT_PGTABLE_LEVEL );
2455
- if (!pdomain )
2456
- return NULL ;
2397
+ struct protection_domain * domain ;
2398
+ int mode = DEFAULT_PGTABLE_LEVEL ;
2457
2399
2458
- pdomain -> domain .geometry .aperture_start = 0 ;
2459
- pdomain -> domain .geometry .aperture_end = ~0ULL ;
2460
- pdomain -> domain .geometry .force_aperture = true;
2400
+ if (type == IOMMU_DOMAIN_IDENTITY )
2401
+ mode = PAGE_MODE_NONE ;
2461
2402
2462
- break ;
2463
- case IOMMU_DOMAIN_DMA :
2464
- pdomain = dma_ops_domain_alloc ();
2465
- if (!pdomain ) {
2466
- pr_err ("Failed to allocate\n" );
2467
- return NULL ;
2468
- }
2469
- break ;
2470
- case IOMMU_DOMAIN_IDENTITY :
2471
- pdomain = protection_domain_alloc (PAGE_MODE_NONE );
2472
- if (!pdomain )
2473
- return NULL ;
2474
- break ;
2475
- default :
2403
+ domain = protection_domain_alloc (mode );
2404
+ if (!domain )
2476
2405
return NULL ;
2406
+
2407
+ domain -> domain .geometry .aperture_start = 0 ;
2408
+ domain -> domain .geometry .aperture_end = ~0ULL ;
2409
+ domain -> domain .geometry .force_aperture = true;
2410
+
2411
+ if (type == IOMMU_DOMAIN_DMA ) {
2412
+ if (iommu_get_dma_cookie (& domain -> domain ) == - ENOMEM )
2413
+ goto free_domain ;
2414
+ domain -> flags = PD_DMA_OPS_MASK ;
2477
2415
}
2478
2416
2479
- return & pdomain -> domain ;
2417
+ return & domain -> domain ;
2418
+
2419
+ free_domain :
2420
+ protection_domain_free (domain );
2421
+
2422
+ return NULL ;
2480
2423
}
2481
2424
2482
2425
static void amd_iommu_domain_free (struct iommu_domain * dom )
@@ -2493,18 +2436,13 @@ static void amd_iommu_domain_free(struct iommu_domain *dom)
2493
2436
if (!dom )
2494
2437
return ;
2495
2438
2496
- switch (dom -> type ) {
2497
- case IOMMU_DOMAIN_DMA :
2498
- /* Now release the domain */
2499
- dma_ops_domain_free (domain );
2500
- break ;
2501
- default :
2502
- if (domain -> flags & PD_IOMMUV2_MASK )
2503
- free_gcr3_table (domain );
2439
+ if (dom -> type == IOMMU_DOMAIN_DMA )
2440
+ iommu_put_dma_cookie (& domain -> domain );
2504
2441
2505
- protection_domain_free (domain );
2506
- break ;
2507
- }
2442
+ if (domain -> flags & PD_IOMMUV2_MASK )
2443
+ free_gcr3_table (domain );
2444
+
2445
+ protection_domain_free (domain );
2508
2446
}
2509
2447
2510
2448
static void amd_iommu_detach_device (struct iommu_domain * dom ,
0 commit comments