Skip to content

Commit 9b467a5

Browse files
ssuthiku-amdjoergroedel
authored andcommitted
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>
1 parent 11cfa78 commit 9b467a5

2 files changed

Lines changed: 22 additions & 6 deletions

File tree

drivers/iommu/amd/amd_iommu.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ void amd_iommu_domain_set_pgtable(struct protection_domain *domain,
190190
struct dev_table_entry *get_dev_table(struct amd_iommu *iommu);
191191
struct iommu_dev_data *search_dev_data(struct amd_iommu *iommu, u16 devid);
192192

193+
void amd_iommu_update_dte(struct amd_iommu *iommu,
194+
struct iommu_dev_data *dev_data,
195+
struct dev_table_entry *new);
196+
193197
static inline void
194198
amd_iommu_make_clear_dte(struct iommu_dev_data *dev_data, struct dev_table_entry *new)
195199
{

drivers/iommu/amd/iommu.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ static void set_dte_entry(struct amd_iommu *iommu,
7676
struct iommu_dev_data *dev_data,
7777
phys_addr_t top_paddr, unsigned int top_level);
7878

79+
static int device_flush_dte(struct iommu_dev_data *dev_data);
80+
7981
static void amd_iommu_change_top(struct pt_iommu *iommu_table,
8082
phys_addr_t top_paddr, unsigned int top_level);
8183

@@ -86,6 +88,10 @@ static bool amd_iommu_enforce_cache_coherency(struct iommu_domain *domain);
8688
static int amd_iommu_set_dirty_tracking(struct iommu_domain *domain,
8789
bool enable);
8890

91+
static void clone_aliases(struct amd_iommu *iommu, struct device *dev);
92+
93+
static int iommu_completion_wait(struct amd_iommu *iommu);
94+
8995
/****************************************************************************
9096
*
9197
* Helper functions
@@ -203,6 +209,16 @@ static void update_dte256(struct amd_iommu *iommu, struct iommu_dev_data *dev_da
203209
spin_unlock_irqrestore(&dev_data->dte_lock, flags);
204210
}
205211

212+
void amd_iommu_update_dte(struct amd_iommu *iommu,
213+
struct iommu_dev_data *dev_data,
214+
struct dev_table_entry *new)
215+
{
216+
update_dte256(iommu, dev_data, new);
217+
clone_aliases(iommu, dev_data->dev);
218+
device_flush_dte(dev_data);
219+
iommu_completion_wait(iommu);
220+
}
221+
206222
static void get_dte256(struct amd_iommu *iommu, struct iommu_dev_data *dev_data,
207223
struct dev_table_entry *dte)
208224
{
@@ -2127,7 +2143,7 @@ static void set_dte_entry(struct amd_iommu *iommu,
21272143

21282144
set_dte_gcr3_table(iommu, dev_data, &new);
21292145

2130-
update_dte256(iommu, dev_data, &new);
2146+
amd_iommu_update_dte(iommu, dev_data, &new);
21312147

21322148
/*
21332149
* 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_
21472163
struct dev_table_entry new = {};
21482164

21492165
amd_iommu_make_clear_dte(dev_data, &new);
2150-
update_dte256(iommu, dev_data, &new);
2166+
amd_iommu_update_dte(iommu, dev_data, &new);
21512167
}
21522168

21532169
/* 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)
21592175
set_dte_entry(iommu, dev_data, 0, 0);
21602176
else
21612177
clear_dte_entry(iommu, dev_data);
2162-
2163-
clone_aliases(iommu, dev_data->dev);
2164-
device_flush_dte(dev_data);
2165-
iommu_completion_wait(iommu);
21662178
}
21672179

21682180
/*

0 commit comments

Comments
 (0)