diff options
| author | Suravee Suthikulpanit <suravee.suthikulpanit@amd.com> | 2026-01-15 09:08:05 +0300 |
|---|---|---|
| committer | Joerg Roedel <joerg.roedel@amd.com> | 2026-01-18 12:56:11 +0300 |
| commit | 9b467a5af856dce9aba17bb6db3ed34ed79f5d90 (patch) | |
| tree | c8b4770946eaf435542732ee1c2deb25dcd91693 | |
| parent | 11cfa782f01b2d988175011c19906180a62dd893 (diff) | |
| download | linux-9b467a5af856dce9aba17bb6db3ed34ed79f5d90.tar.xz | |
iommu/amd: Introduce helper function amd_iommu_update_dte()
Which includes DTE update, clone_aliases, DTE flush and completion-wait
commands to avoid code duplication when reuse to setup DTE for nested
translation.
Also, make amd_iommu_update_dte() non-static to reuse in
in a new nested.c file for nested translation.
Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Suravee Suthikulpanit <suravee.suthikulpanit@amd.com>
Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
| -rw-r--r-- | drivers/iommu/amd/amd_iommu.h | 4 | ||||
| -rw-r--r-- | drivers/iommu/amd/iommu.c | 24 |
2 files changed, 22 insertions, 6 deletions
diff --git a/drivers/iommu/amd/amd_iommu.h b/drivers/iommu/amd/amd_iommu.h index 8eb5e9857079..d97b9b6d76d3 100644 --- a/drivers/iommu/amd/amd_iommu.h +++ b/drivers/iommu/amd/amd_iommu.h @@ -190,6 +190,10 @@ void amd_iommu_domain_set_pgtable(struct protection_domain *domain, struct dev_table_entry *get_dev_table(struct amd_iommu *iommu); struct iommu_dev_data *search_dev_data(struct amd_iommu *iommu, u16 devid); +void amd_iommu_update_dte(struct amd_iommu *iommu, + struct iommu_dev_data *dev_data, + struct dev_table_entry *new); + static inline void amd_iommu_make_clear_dte(struct iommu_dev_data *dev_data, struct dev_table_entry *new) { diff --git a/drivers/iommu/amd/iommu.c b/drivers/iommu/amd/iommu.c index ae26fbe09023..2b7099e09852 100644 --- a/drivers/iommu/amd/iommu.c +++ b/drivers/iommu/amd/iommu.c @@ -76,6 +76,8 @@ static void set_dte_entry(struct amd_iommu *iommu, struct iommu_dev_data *dev_data, phys_addr_t top_paddr, unsigned int top_level); +static int device_flush_dte(struct iommu_dev_data *dev_data); + static void amd_iommu_change_top(struct pt_iommu *iommu_table, phys_addr_t top_paddr, unsigned int top_level); @@ -86,6 +88,10 @@ static bool amd_iommu_enforce_cache_coherency(struct iommu_domain *domain); static int amd_iommu_set_dirty_tracking(struct iommu_domain *domain, bool enable); +static void clone_aliases(struct amd_iommu *iommu, struct device *dev); + +static int iommu_completion_wait(struct amd_iommu *iommu); + /**************************************************************************** * * Helper functions @@ -203,6 +209,16 @@ static void update_dte256(struct amd_iommu *iommu, struct iommu_dev_data *dev_da spin_unlock_irqrestore(&dev_data->dte_lock, flags); } +void amd_iommu_update_dte(struct amd_iommu *iommu, + struct iommu_dev_data *dev_data, + struct dev_table_entry *new) +{ + update_dte256(iommu, dev_data, new); + clone_aliases(iommu, dev_data->dev); + device_flush_dte(dev_data); + iommu_completion_wait(iommu); +} + static void get_dte256(struct amd_iommu *iommu, struct iommu_dev_data *dev_data, struct dev_table_entry *dte) { @@ -2127,7 +2143,7 @@ static void set_dte_entry(struct amd_iommu *iommu, set_dte_gcr3_table(iommu, dev_data, &new); - update_dte256(iommu, dev_data, &new); + amd_iommu_update_dte(iommu, dev_data, &new); /* * A kdump kernel might be replacing a domain ID that was copied from @@ -2147,7 +2163,7 @@ static void clear_dte_entry(struct amd_iommu *iommu, struct iommu_dev_data *dev_ struct dev_table_entry new = {}; amd_iommu_make_clear_dte(dev_data, &new); - update_dte256(iommu, dev_data, &new); + amd_iommu_update_dte(iommu, dev_data, &new); } /* Update and flush DTE for the given device */ @@ -2159,10 +2175,6 @@ static void dev_update_dte(struct iommu_dev_data *dev_data, bool set) set_dte_entry(iommu, dev_data, 0, 0); else clear_dte_entry(iommu, dev_data); - - clone_aliases(iommu, dev_data->dev); - device_flush_dte(dev_data); - iommu_completion_wait(iommu); } /* |
