@@ -2002,6 +2002,21 @@ static void clear_dte_entry(struct amd_iommu *iommu, u16 devid)
2002
2002
amd_iommu_apply_erratum_63 (iommu , devid );
2003
2003
}
2004
2004
2005
+ /* Update and flush DTE for the given device */
2006
+ void amd_iommu_dev_update_dte (struct iommu_dev_data * dev_data , bool set )
2007
+ {
2008
+ struct amd_iommu * iommu = get_amd_iommu_from_dev (dev_data -> dev );
2009
+
2010
+ if (set )
2011
+ set_dte_entry (iommu , dev_data );
2012
+ else
2013
+ clear_dte_entry (iommu , dev_data -> devid );
2014
+
2015
+ clone_aliases (iommu , dev_data -> dev );
2016
+ device_flush_dte (dev_data );
2017
+ iommu_completion_wait (iommu );
2018
+ }
2019
+
2005
2020
static int do_attach (struct iommu_dev_data * dev_data ,
2006
2021
struct protection_domain * domain )
2007
2022
{
@@ -2036,10 +2051,7 @@ static int do_attach(struct iommu_dev_data *dev_data,
2036
2051
}
2037
2052
2038
2053
/* Update device table */
2039
- set_dte_entry (iommu , dev_data );
2040
- clone_aliases (iommu , dev_data -> dev );
2041
-
2042
- device_flush_dte (dev_data );
2054
+ amd_iommu_dev_update_dte (dev_data , true);
2043
2055
2044
2056
return ret ;
2045
2057
}
@@ -2058,11 +2070,9 @@ static void do_detach(struct iommu_dev_data *dev_data)
2058
2070
/* Update data structures */
2059
2071
dev_data -> domain = NULL ;
2060
2072
list_del (& dev_data -> list );
2061
- clear_dte_entry (iommu , dev_data -> devid );
2062
- clone_aliases (iommu , dev_data -> dev );
2063
2073
2064
- /* Flush the DTE entry */
2065
- device_flush_dte (dev_data );
2074
+ /* Clear DTE and flush the entry */
2075
+ amd_iommu_dev_update_dte (dev_data , false );
2066
2076
2067
2077
/* Flush IOTLB and wait for the flushes to finish */
2068
2078
amd_iommu_domain_flush_all (domain );
0 commit comments