@@ -2078,24 +2078,8 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
2078
2078
struct io_pgtable_ops * pgtbl_ops ;
2079
2079
struct protection_domain * domain ;
2080
2080
int pgtable ;
2081
- int mode = DEFAULT_PGTABLE_LEVEL ;
2082
2081
int ret ;
2083
2082
2084
- /*
2085
- * Force IOMMU v1 page table when iommu=pt and
2086
- * when allocating domain for pass-through devices.
2087
- */
2088
- if (type == IOMMU_DOMAIN_IDENTITY ) {
2089
- pgtable = AMD_IOMMU_V1 ;
2090
- mode = PAGE_MODE_NONE ;
2091
- } else if (type == IOMMU_DOMAIN_UNMANAGED ) {
2092
- pgtable = AMD_IOMMU_V1 ;
2093
- } else if (type == IOMMU_DOMAIN_DMA || type == IOMMU_DOMAIN_DMA_FQ ) {
2094
- pgtable = amd_iommu_pgtable ;
2095
- } else {
2096
- return NULL ;
2097
- }
2098
-
2099
2083
domain = kzalloc (sizeof (* domain ), GFP_KERNEL );
2100
2084
if (!domain )
2101
2085
return NULL ;
@@ -2106,27 +2090,42 @@ static struct protection_domain *protection_domain_alloc(unsigned int type)
2106
2090
2107
2091
spin_lock_init (& domain -> lock );
2108
2092
INIT_LIST_HEAD (& domain -> dev_list );
2093
+ domain -> nid = NUMA_NO_NODE ;
2094
+
2095
+ switch (type ) {
2096
+ /* No need to allocate io pgtable ops in passthrough mode */
2097
+ case IOMMU_DOMAIN_IDENTITY :
2098
+ return domain ;
2099
+ case IOMMU_DOMAIN_DMA :
2100
+ case IOMMU_DOMAIN_DMA_FQ :
2101
+ pgtable = amd_iommu_pgtable ;
2102
+ break ;
2103
+ /*
2104
+ * Force IOMMU v1 page table when allocating
2105
+ * domain for pass-through devices.
2106
+ */
2107
+ case IOMMU_DOMAIN_UNMANAGED :
2108
+ pgtable = AMD_IOMMU_V1 ;
2109
+ break ;
2110
+ default :
2111
+ goto out_err ;
2112
+ }
2109
2113
2110
2114
switch (pgtable ) {
2111
2115
case AMD_IOMMU_V1 :
2112
- ret = protection_domain_init_v1 (domain , mode );
2116
+ ret = protection_domain_init_v1 (domain , DEFAULT_PGTABLE_LEVEL );
2113
2117
break ;
2114
2118
case AMD_IOMMU_V2 :
2115
2119
ret = protection_domain_init_v2 (domain );
2116
2120
break ;
2117
2121
default :
2118
2122
ret = - EINVAL ;
2123
+ break ;
2119
2124
}
2120
2125
2121
2126
if (ret )
2122
2127
goto out_err ;
2123
2128
2124
- /* No need to allocate io pgtable ops in passthrough mode */
2125
- if (type == IOMMU_DOMAIN_IDENTITY )
2126
- return domain ;
2127
-
2128
- domain -> nid = NUMA_NO_NODE ;
2129
-
2130
2129
pgtbl_ops = alloc_io_pgtable_ops (pgtable , & domain -> iop .pgtbl_cfg , domain );
2131
2130
if (!pgtbl_ops ) {
2132
2131
domain_id_free (domain -> id );
0 commit comments