Skip to content

Commit 06d54f0

Browse files
nicolincjgunthorpe
authored andcommitted
iommu: Drop sw_msi from iommu_domain
There are only two sw_msi implementations in the entire system, thus it's not very necessary to have an sw_msi pointer. Instead, check domain->cookie_type to call the two sw_msi implementations directly from the core code. Link: https://patch.msgid.link/r/7ded87c871afcbaac665b71354de0a335087bf0f.1742871535.git.nicolinc@nvidia.com Suggested-by: Robin Murphy <robin.murphy@arm.com> Reviewed-by: Robin Murphy <robin.murphy@arm.com> Reviewed-by: Kevin Tian <kevin.tian@intel.com> Signed-off-by: Nicolin Chen <nicolinc@nvidia.com> Reviewed-by: Jason Gunthorpe <jgg@nvidia.com> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
1 parent ec031e1 commit 06d54f0

5 files changed

Lines changed: 27 additions & 32 deletions

File tree

drivers/iommu/dma-iommu.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,6 @@ static int __init iommu_dma_forcedac_setup(char *str)
9494
}
9595
early_param("iommu.forcedac", iommu_dma_forcedac_setup);
9696

97-
static int iommu_dma_sw_msi(struct iommu_domain *domain, struct msi_desc *desc,
98-
phys_addr_t msi_addr);
99-
10097
/* Number of entries per flush queue */
10198
#define IOVA_DEFAULT_FQ_SIZE 256
10299
#define IOVA_SINGLE_FQ_SIZE 32768
@@ -377,7 +374,6 @@ int iommu_get_dma_cookie(struct iommu_domain *domain)
377374

378375
mutex_init(&cookie->mutex);
379376
INIT_LIST_HEAD(&cookie->msi_page_list);
380-
iommu_domain_set_sw_msi(domain, iommu_dma_sw_msi);
381377
domain->cookie_type = IOMMU_COOKIE_DMA_IOVA;
382378
domain->iova_cookie = cookie;
383379
return 0;
@@ -411,7 +407,6 @@ int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base)
411407

412408
cookie->msi_iova = base;
413409
INIT_LIST_HEAD(&cookie->msi_page_list);
414-
iommu_domain_set_sw_msi(domain, iommu_dma_sw_msi);
415410
domain->cookie_type = IOMMU_COOKIE_DMA_MSI;
416411
domain->msi_cookie = cookie;
417412
return 0;
@@ -427,11 +422,6 @@ void iommu_put_dma_cookie(struct iommu_domain *domain)
427422
struct iommu_dma_cookie *cookie = domain->iova_cookie;
428423
struct iommu_dma_msi_page *msi, *tmp;
429424

430-
#if IS_ENABLED(CONFIG_IRQ_MSI_IOMMU)
431-
if (domain->sw_msi != iommu_dma_sw_msi)
432-
return;
433-
#endif
434-
435425
if (cookie->iovad.granule) {
436426
iommu_dma_free_fq(cookie);
437427
put_iova_domain(&cookie->iovad);
@@ -1826,8 +1816,8 @@ static struct iommu_dma_msi_page *iommu_dma_get_msi_page(struct device *dev,
18261816
return NULL;
18271817
}
18281818

1829-
static int iommu_dma_sw_msi(struct iommu_domain *domain, struct msi_desc *desc,
1830-
phys_addr_t msi_addr)
1819+
int iommu_dma_sw_msi(struct iommu_domain *domain, struct msi_desc *desc,
1820+
phys_addr_t msi_addr)
18311821
{
18321822
struct device *dev = msi_desc_to_dev(desc);
18331823
const struct iommu_dma_msi_page *msi_page;

drivers/iommu/dma-iommu.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ int iommu_dma_init_fq(struct iommu_domain *domain);
1919

2020
void iommu_dma_get_resv_regions(struct device *dev, struct list_head *list);
2121

22+
int iommu_dma_sw_msi(struct iommu_domain *domain, struct msi_desc *desc,
23+
phys_addr_t msi_addr);
24+
2225
extern bool iommu_dma_forcedac;
2326

2427
#else /* CONFIG_IOMMU_DMA */
@@ -49,5 +52,11 @@ static inline void iommu_dma_get_resv_regions(struct device *dev, struct list_he
4952
{
5053
}
5154

55+
static inline int iommu_dma_sw_msi(struct iommu_domain *domain,
56+
struct msi_desc *desc, phys_addr_t msi_addr)
57+
{
58+
return -ENODEV;
59+
}
60+
5261
#endif /* CONFIG_IOMMU_DMA */
5362
#endif /* __DMA_IOMMU_H */

drivers/iommu/iommu.c

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include <linux/errno.h>
1919
#include <linux/host1x_context_bus.h>
2020
#include <linux/iommu.h>
21+
#include <linux/iommufd.h>
2122
#include <linux/idr.h>
2223
#include <linux/err.h>
2324
#include <linux/pci.h>
@@ -3650,8 +3651,21 @@ int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr)
36503651
return 0;
36513652

36523653
mutex_lock(&group->mutex);
3653-
if (group->domain && group->domain->sw_msi)
3654-
ret = group->domain->sw_msi(group->domain, desc, msi_addr);
3654+
/* An IDENTITY domain must pass through */
3655+
if (group->domain && group->domain->type != IOMMU_DOMAIN_IDENTITY) {
3656+
switch (group->domain->cookie_type) {
3657+
case IOMMU_COOKIE_DMA_MSI:
3658+
case IOMMU_COOKIE_DMA_IOVA:
3659+
ret = iommu_dma_sw_msi(group->domain, desc, msi_addr);
3660+
break;
3661+
case IOMMU_COOKIE_IOMMUFD:
3662+
ret = iommufd_sw_msi(group->domain, desc, msi_addr);
3663+
break;
3664+
default:
3665+
ret = -EOPNOTSUPP;
3666+
break;
3667+
}
3668+
}
36553669
mutex_unlock(&group->mutex);
36563670
return ret;
36573671
}

drivers/iommu/iommufd/hw_pagetable.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ iommufd_hwpt_paging_alloc(struct iommufd_ctx *ictx, struct iommufd_ioas *ioas,
161161
}
162162
hwpt->domain->iommufd_hwpt = hwpt;
163163
hwpt->domain->cookie_type = IOMMU_COOKIE_IOMMUFD;
164-
iommu_domain_set_sw_msi(hwpt->domain, iommufd_sw_msi);
165164

166165
/*
167166
* Set the coherency mode before we do iopt_table_add_domain() as some
@@ -259,7 +258,6 @@ iommufd_hwpt_nested_alloc(struct iommufd_ctx *ictx,
259258
hwpt->domain->owner = ops;
260259
hwpt->domain->iommufd_hwpt = hwpt;
261260
hwpt->domain->cookie_type = IOMMU_COOKIE_IOMMUFD;
262-
iommu_domain_set_sw_msi(hwpt->domain, iommufd_sw_msi);
263261

264262
if (WARN_ON_ONCE(hwpt->domain->type != IOMMU_DOMAIN_NESTED)) {
265263
rc = -EINVAL;
@@ -318,7 +316,6 @@ iommufd_viommu_alloc_hwpt_nested(struct iommufd_viommu *viommu, u32 flags,
318316
hwpt->domain->iommufd_hwpt = hwpt;
319317
hwpt->domain->owner = viommu->iommu_dev->ops;
320318
hwpt->domain->cookie_type = IOMMU_COOKIE_IOMMUFD;
321-
iommu_domain_set_sw_msi(hwpt->domain, iommufd_sw_msi);
322319

323320
if (WARN_ON_ONCE(hwpt->domain->type != IOMMU_DOMAIN_NESTED)) {
324321
rc = -EINVAL;

include/linux/iommu.h

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,6 @@ struct iommu_domain {
229229
struct iommu_domain_geometry geometry;
230230
int (*iopf_handler)(struct iopf_group *group);
231231

232-
#if IS_ENABLED(CONFIG_IRQ_MSI_IOMMU)
233-
int (*sw_msi)(struct iommu_domain *domain, struct msi_desc *desc,
234-
phys_addr_t msi_addr);
235-
#endif
236-
237232
union { /* cookie */
238233
struct iommu_dma_cookie *iova_cookie;
239234
struct iommu_dma_msi_cookie *msi_cookie;
@@ -254,16 +249,6 @@ struct iommu_domain {
254249
};
255250
};
256251

257-
static inline void iommu_domain_set_sw_msi(
258-
struct iommu_domain *domain,
259-
int (*sw_msi)(struct iommu_domain *domain, struct msi_desc *desc,
260-
phys_addr_t msi_addr))
261-
{
262-
#if IS_ENABLED(CONFIG_IRQ_MSI_IOMMU)
263-
domain->sw_msi = sw_msi;
264-
#endif
265-
}
266-
267252
static inline bool iommu_is_dma_domain(struct iommu_domain *domain)
268253
{
269254
return domain->type & __IOMMU_DOMAIN_DMA_API;

0 commit comments

Comments
 (0)