Skip to content

Commit 9349887

Browse files
committed
genirq/msi: Refactor iommu_dma_compose_msi_msg()
The two-step process to translate the MSI address involves two functions, iommu_dma_prepare_msi() and iommu_dma_compose_msi_msg(). Previously iommu_dma_compose_msi_msg() needed to be in the iommu layer as it had to dereference the opaque cookie pointer. Now, the previous patch changed the cookie pointer into an integer so there is no longer any need for the iommu layer to be involved. Further, the call sites of iommu_dma_compose_msi_msg() all follow the same pattern of setting an MSI message address_hi/lo to non-translated and then immediately calling iommu_dma_compose_msi_msg(). Refactor iommu_dma_compose_msi_msg() into msi_msg_set_addr() that directly accepts the u64 version of the address and simplifies all the callers. Move the new helper to linux/msi.h since it has nothing to do with iommu. Aside from refactoring, this logically prepares for the next patch, which allows multiple implementation options for iommu_dma_prepare_msi(). So, it does not make sense to have the iommu_dma_compose_msi_msg() in dma-iommu.c as it no longer provides the only iommu_dma_prepare_msi() implementation. Link: https://patch.msgid.link/r/eda62a9bafa825e9cdabd7ddc61ad5a21c32af24.1740014950.git.nicolinc@nvidia.com Signed-off-by: Nicolin Chen <[email protected]> Reviewed-by: Thomas Gleixner <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 1f7df3a commit 9349887

File tree

7 files changed

+38
-49
lines changed

7 files changed

+38
-49
lines changed

drivers/iommu/dma-iommu.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,24 +1836,6 @@ int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr)
18361836
return 0;
18371837
}
18381838

1839-
/**
1840-
* iommu_dma_compose_msi_msg() - Apply translation to an MSI message
1841-
* @desc: MSI descriptor prepared by iommu_dma_prepare_msi()
1842-
* @msg: MSI message containing target physical address
1843-
*/
1844-
void iommu_dma_compose_msi_msg(struct msi_desc *desc, struct msi_msg *msg)
1845-
{
1846-
#ifdef CONFIG_IRQ_MSI_IOMMU
1847-
if (desc->iommu_msi_shift) {
1848-
u64 msi_iova = desc->iommu_msi_iova << desc->iommu_msi_shift;
1849-
1850-
msg->address_hi = upper_32_bits(msi_iova);
1851-
msg->address_lo = lower_32_bits(msi_iova) |
1852-
(msg->address_lo & ((1 << desc->iommu_msi_shift) - 1));
1853-
}
1854-
#endif
1855-
}
1856-
18571839
static int iommu_dma_init(void)
18581840
{
18591841
if (is_kdump_kernel())

drivers/irqchip/irq-gic-v2m.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,17 +87,14 @@ static void gicv2m_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
8787
struct v2m_data *v2m = irq_data_get_irq_chip_data(data);
8888
phys_addr_t addr = gicv2m_get_msi_addr(v2m, data->hwirq);
8989

90-
msg->address_hi = upper_32_bits(addr);
91-
msg->address_lo = lower_32_bits(addr);
92-
9390
if (v2m->flags & GICV2M_GRAVITON_ADDRESS_ONLY)
9491
msg->data = 0;
9592
else
9693
msg->data = data->hwirq;
9794
if (v2m->flags & GICV2M_NEEDS_SPI_OFFSET)
9895
msg->data -= v2m->spi_offset;
9996

100-
iommu_dma_compose_msi_msg(irq_data_get_msi_desc(data), msg);
97+
msi_msg_set_addr(irq_data_get_msi_desc(data), msg, addr);
10198
}
10299

103100
static struct irq_chip gicv2m_irq_chip = {

drivers/irqchip/irq-gic-v3-its.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1809,17 +1809,10 @@ static u64 its_irq_get_msi_base(struct its_device *its_dev)
18091809
static void its_irq_compose_msi_msg(struct irq_data *d, struct msi_msg *msg)
18101810
{
18111811
struct its_device *its_dev = irq_data_get_irq_chip_data(d);
1812-
struct its_node *its;
1813-
u64 addr;
1814-
1815-
its = its_dev->its;
1816-
addr = its->get_msi_base(its_dev);
1817-
1818-
msg->address_lo = lower_32_bits(addr);
1819-
msg->address_hi = upper_32_bits(addr);
1820-
msg->data = its_get_event_id(d);
18211812

1822-
iommu_dma_compose_msi_msg(irq_data_get_msi_desc(d), msg);
1813+
msg->data = its_get_event_id(d);
1814+
msi_msg_set_addr(irq_data_get_msi_desc(d), msg,
1815+
its_dev->its->get_msi_base(its_dev));
18231816
}
18241817

18251818
static int its_irq_set_irqchip_state(struct irq_data *d,

drivers/irqchip/irq-gic-v3-mbi.c

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -147,22 +147,18 @@ static const struct irq_domain_ops mbi_domain_ops = {
147147

148148
static void mbi_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
149149
{
150-
msg[0].address_hi = upper_32_bits(mbi_phys_base + GICD_SETSPI_NSR);
151-
msg[0].address_lo = lower_32_bits(mbi_phys_base + GICD_SETSPI_NSR);
152150
msg[0].data = data->parent_data->hwirq;
153-
154-
iommu_dma_compose_msi_msg(irq_data_get_msi_desc(data), msg);
151+
msi_msg_set_addr(irq_data_get_msi_desc(data), &msg[0],
152+
mbi_phys_base + GICD_SETSPI_NSR);
155153
}
156154

157155
static void mbi_compose_mbi_msg(struct irq_data *data, struct msi_msg *msg)
158156
{
159157
mbi_compose_msi_msg(data, msg);
160158

161-
msg[1].address_hi = upper_32_bits(mbi_phys_base + GICD_CLRSPI_NSR);
162-
msg[1].address_lo = lower_32_bits(mbi_phys_base + GICD_CLRSPI_NSR);
163159
msg[1].data = data->parent_data->hwirq;
164-
165-
iommu_dma_compose_msi_msg(irq_data_get_msi_desc(data), &msg[1]);
160+
msi_msg_set_addr(irq_data_get_msi_desc(data), &msg[1],
161+
mbi_phys_base + GICD_CLRSPI_NSR);
166162
}
167163

168164
static bool mbi_init_dev_msi_info(struct device *dev, struct irq_domain *domain,

drivers/irqchip/irq-ls-scfg-msi.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ static void ls_scfg_msi_compose_msg(struct irq_data *data, struct msi_msg *msg)
8787
{
8888
struct ls_scfg_msi *msi_data = irq_data_get_irq_chip_data(data);
8989

90-
msg->address_hi = upper_32_bits(msi_data->msiir_addr);
91-
msg->address_lo = lower_32_bits(msi_data->msiir_addr);
9290
msg->data = data->hwirq;
9391

9492
if (msi_affinity_flag) {
@@ -98,7 +96,8 @@ static void ls_scfg_msi_compose_msg(struct irq_data *data, struct msi_msg *msg)
9896
msg->data |= cpumask_first(mask);
9997
}
10098

101-
iommu_dma_compose_msi_msg(irq_data_get_msi_desc(data), msg);
99+
msi_msg_set_addr(irq_data_get_msi_desc(data), msg,
100+
msi_data->msiir_addr);
102101
}
103102

104103
static int ls_scfg_msi_set_affinity(struct irq_data *irq_data,

include/linux/iommu.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1508,7 +1508,6 @@ static inline void iommu_debugfs_setup(void) {}
15081508
int iommu_get_msi_cookie(struct iommu_domain *domain, dma_addr_t base);
15091509

15101510
int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_addr);
1511-
void iommu_dma_compose_msi_msg(struct msi_desc *desc, struct msi_msg *msg);
15121511

15131512
#else /* CONFIG_IOMMU_DMA */
15141513

@@ -1524,11 +1523,6 @@ static inline int iommu_dma_prepare_msi(struct msi_desc *desc, phys_addr_t msi_a
15241523
{
15251524
return 0;
15261525
}
1527-
1528-
static inline void iommu_dma_compose_msi_msg(struct msi_desc *desc, struct msi_msg *msg)
1529-
{
1530-
}
1531-
15321526
#endif /* CONFIG_IOMMU_DMA */
15331527

15341528
/*

include/linux/msi.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,34 @@ static inline void msi_desc_set_iommu_msi_iova(struct msi_desc *desc, u64 msi_io
299299
#endif
300300
}
301301

302+
/**
303+
* msi_msg_set_addr() - Set MSI address in an MSI message
304+
*
305+
* @desc: MSI descriptor that may carry an IOVA base address for MSI via @iommu_msi_iova/shift
306+
* @msg: Target MSI message to set its address_hi and address_lo
307+
* @msi_addr: Physical address to set the MSI message
308+
*
309+
* Notes:
310+
* - Override @msi_addr using the IOVA base address in the @desc if @iommu_msi_shift is set
311+
* - Otherwise, simply set @msi_addr to @msg
312+
*/
313+
static inline void msi_msg_set_addr(struct msi_desc *desc, struct msi_msg *msg,
314+
phys_addr_t msi_addr)
315+
{
316+
#ifdef CONFIG_IRQ_MSI_IOMMU
317+
if (desc->iommu_msi_shift) {
318+
u64 msi_iova = desc->iommu_msi_iova << desc->iommu_msi_shift;
319+
320+
msg->address_hi = upper_32_bits(msi_iova);
321+
msg->address_lo = lower_32_bits(msi_iova) |
322+
(msi_addr & ((1 << desc->iommu_msi_shift) - 1));
323+
return;
324+
}
325+
#endif
326+
msg->address_hi = upper_32_bits(msi_addr);
327+
msg->address_lo = lower_32_bits(msi_addr);
328+
}
329+
302330
int msi_domain_insert_msi_desc(struct device *dev, unsigned int domid,
303331
struct msi_desc *init_desc);
304332
/**

0 commit comments

Comments
 (0)