31
31
#include <linux/irqdomain.h>
32
32
#include <linux/percpu.h>
33
33
#include <linux/iova.h>
34
+ #include <linux/io-pgtable.h>
34
35
#include <asm/irq_remapping.h>
35
36
#include <asm/io_apic.h>
36
37
#include <asm/apic.h>
@@ -1900,7 +1901,7 @@ static void protection_domain_free(struct protection_domain *domain)
1900
1901
kfree (domain );
1901
1902
}
1902
1903
1903
- static int protection_domain_init (struct protection_domain * domain , int mode )
1904
+ static int protection_domain_init_v1 (struct protection_domain * domain , int mode )
1904
1905
{
1905
1906
u64 * pt_root = NULL ;
1906
1907
@@ -1923,34 +1924,55 @@ static int protection_domain_init(struct protection_domain *domain, int mode)
1923
1924
return 0 ;
1924
1925
}
1925
1926
1926
- static struct protection_domain * protection_domain_alloc (int mode )
1927
+ static struct protection_domain * protection_domain_alloc (unsigned int type )
1927
1928
{
1929
+ struct io_pgtable_ops * pgtbl_ops ;
1928
1930
struct protection_domain * domain ;
1931
+ int pgtable = amd_iommu_pgtable ;
1932
+ int mode = DEFAULT_PGTABLE_LEVEL ;
1933
+ int ret ;
1929
1934
1930
1935
domain = kzalloc (sizeof (* domain ), GFP_KERNEL );
1931
1936
if (!domain )
1932
1937
return NULL ;
1933
1938
1934
- if (protection_domain_init (domain , mode ))
1939
+ /*
1940
+ * Force IOMMU v1 page table when iommu=pt and
1941
+ * when allocating domain for pass-through devices.
1942
+ */
1943
+ if (type == IOMMU_DOMAIN_IDENTITY ) {
1944
+ pgtable = AMD_IOMMU_V1 ;
1945
+ mode = PAGE_MODE_NONE ;
1946
+ } else if (type == IOMMU_DOMAIN_UNMANAGED ) {
1947
+ pgtable = AMD_IOMMU_V1 ;
1948
+ }
1949
+
1950
+ switch (pgtable ) {
1951
+ case AMD_IOMMU_V1 :
1952
+ ret = protection_domain_init_v1 (domain , mode );
1953
+ break ;
1954
+ default :
1955
+ ret = - EINVAL ;
1956
+ }
1957
+
1958
+ if (ret )
1935
1959
goto out_err ;
1936
1960
1937
- return domain ;
1961
+ pgtbl_ops = alloc_io_pgtable_ops (pgtable , & domain -> iop .pgtbl_cfg , domain );
1962
+ if (!pgtbl_ops )
1963
+ goto out_err ;
1938
1964
1965
+ return domain ;
1939
1966
out_err :
1940
1967
kfree (domain );
1941
-
1942
1968
return NULL ;
1943
1969
}
1944
1970
1945
1971
static struct iommu_domain * amd_iommu_domain_alloc (unsigned type )
1946
1972
{
1947
1973
struct protection_domain * domain ;
1948
- int mode = DEFAULT_PGTABLE_LEVEL ;
1949
-
1950
- if (type == IOMMU_DOMAIN_IDENTITY )
1951
- mode = PAGE_MODE_NONE ;
1952
1974
1953
- domain = protection_domain_alloc (mode );
1975
+ domain = protection_domain_alloc (type );
1954
1976
if (!domain )
1955
1977
return NULL ;
1956
1978
@@ -2069,7 +2091,8 @@ static int amd_iommu_map(struct iommu_domain *dom, unsigned long iova,
2069
2091
int prot = 0 ;
2070
2092
int ret = - EINVAL ;
2071
2093
2072
- if (domain -> iop .mode == PAGE_MODE_NONE )
2094
+ if ((amd_iommu_pgtable == AMD_IOMMU_V1 ) &&
2095
+ (domain -> iop .mode == PAGE_MODE_NONE ))
2073
2096
return - EINVAL ;
2074
2097
2075
2098
if (iommu_prot & IOMMU_READ )
@@ -2092,7 +2115,8 @@ static size_t amd_iommu_unmap(struct iommu_domain *dom, unsigned long iova,
2092
2115
struct protection_domain * domain = to_pdomain (dom );
2093
2116
struct io_pgtable_ops * ops = & domain -> iop .iop .ops ;
2094
2117
2095
- if (domain -> iop .mode == PAGE_MODE_NONE )
2118
+ if ((amd_iommu_pgtable == AMD_IOMMU_V1 ) &&
2119
+ (domain -> iop .mode == PAGE_MODE_NONE ))
2096
2120
return 0 ;
2097
2121
2098
2122
return (ops -> unmap ) ? ops -> unmap (ops , iova , page_size , gather ) : 0 ;
0 commit comments