Skip to contentSkip to conversation

PCI: mediatek: Correct type for virt_to_phys()

PATCH In review Andy Shevchenko 2 participants 4 messages Sep 14, 2023 – Sep 18, 2023

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 PCI: mediatek: Correct type for virt_to_phys()

virt_to_phys() takes a regular pointer, while driver supplies __iomem annotated one. Force type to void to make sparse happy, otherwise

pcie-mediatek.c:400:40: sparse: expected void volatile *address
pcie-mediatek.c:400:40: sparse: got void [noderef] __iomem *

pcie-mediatek.c:523:44: sparse: expected void volatile *address
pcie-mediatek.c:523:44: sparse: got void [noderef] __iomem *

---
 drivers/pci/controller/pcie-mediatek.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/controller/pcie-mediatek.c +2 -2
index 66a8f73296fc..5e795afd1cee 100644
@@ -397,7 +397,7 @@ static void mtk_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 	phys_addr_t addr;
 
 	/* MT2712/MT7622 only support 32-bit MSI addresses */
-	addr = virt_to_phys(port->base + PCIE_MSI_VECTOR);
+	addr = virt_to_phys((__force void *)port->base + PCIE_MSI_VECTOR);
 	msg->address_hi = 0;
 	msg->address_lo = lower_32_bits(addr);
 
@@ -520,7 +520,7 @@ static void mtk_pcie_enable_msi(struct mtk_pcie_port *port)
 	u32 val;
 	phys_addr_t msg_addr;
 
-	msg_addr = virt_to_phys(port->base + PCIE_MSI_VECTOR);
+	msg_addr = virt_to_phys((__force void *)port->base + PCIE_MSI_VECTOR);
 	val = lower_32_bits(msg_addr);
 	writel(val, port->base + PCIE_IMSI_ADDR);
 
Signature · 1 line
2.40.0.1.gaa8946217a0b
#1 lore raw
Quoted 22 lines · Andy Shevchenko

virt_to_phys() takes a regular pointer, while driver supplies __iomem annotated one. Force type to void to make sparse happy, otherwise

pcie-mediatek.c:400:40: sparse: expected void volatile *address
pcie-mediatek.c:400:40: sparse: got void [noderef] __iomem *

pcie-mediatek.c:523:44: sparse: expected void volatile *address
pcie-mediatek.c:523:44: sparse: got void [noderef] __iomem *

---
 drivers/pci/controller/pcie-mediatek.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/controller/pcie-mediatek.c +0 -0
index 66a8f73296fc..5e795afd1cee 100644

drivers/pci/controller/pcie-mediatek.c static void mtk_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) · line 400

Quoted 5 lines
drivers/pci/controller/pcie-mediatek.c +1 -1
@@ -397,7 +397,7 @@ static void mtk_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
 	phys_addr_t addr;
 
 	/* MT2712/MT7622 only support 32-bit MSI addresses */
-	addr = virt_to_phys(port->base + PCIE_MSI_VECTOR);
+	addr = virt_to_phys((__force void *)port->base + PCIE_MSI_VECTOR);

Lots of these drivers use either virt_to_phys() or platform_get_resource_byname() to get a physical address that they then use as the MSI target.

But I don't think that's quite right -- the MSI is a DMA transaction on PCI, and in general there's no guarantee that bus addresses are identical to CPU physical addresses, so shouldn't we use a dma_addr_t obtained from the DMA API?

dw_pcie_msi_host_init() has a complicated version of this that uses dmam_alloc_coherent().

Quoted 20 lines
drivers/pci/controller/pcie-mediatek.c +1 -1
 	msg->address_hi = 0;
 	msg->address_lo = lower_32_bits(addr);
 
@@ -520,7 +520,7 @@ static void mtk_pcie_enable_msi(struct mtk_pcie_port *port)
 	u32 val;
 	phys_addr_t msg_addr;
 
-	msg_addr = virt_to_phys(port->base + PCIE_MSI_VECTOR);
+	msg_addr = virt_to_phys((__force void *)port->base + PCIE_MSI_VECTOR);
 	val = lower_32_bits(msg_addr);
 	writel(val, port->base + PCIE_IMSI_ADDR);
 
Signature · 7 lines
2.40.0.1.gaa8946217a0b


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#2 lore raw
Quoted 1 line · Bjorn Helgaas

On Thu, Sep 14, 2023 at 10:23:24PM +0300, Andy Shevchenko wrote:

...

Quoted 7 lines

drivers/pci/controller/pcie-mediatek.c static void mtk_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) · line 400

Quoted 2 lines
drivers/pci/controller/pcie-mediatek.c +1 -1
-	addr = virt_to_phys(port->base + PCIE_MSI_VECTOR);
+	addr = virt_to_phys((__force void *)port->base + PCIE_MSI_VECTOR);

Lots of these drivers use either virt_to_phys() or platform_get_resource_byname() to get a physical address that they then use as the MSI target.

Quoted 7 lines

But I don't think that's quite right -- the MSI is a DMA transaction on PCI, and in general there's no guarantee that bus addresses are identical to CPU physical addresses, so shouldn't we use a dma_addr_t obtained from the DMA API?

dw_pcie_msi_host_init() has a complicated version of this that uses dmam_alloc_coherent().

Fair enough. I leave it to you then to get it fixed properly. Consider this as just a heads up for the old report.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 17 lines · Andy Shevchenko
Quoted 1 line · Bjorn Helgaas

On Thu, Sep 14, 2023 at 10:23:24PM +0300, Andy Shevchenko wrote:

...

Quoted 12 lines

drivers/pci/controller/pcie-mediatek.c static void mtk_compose_msi_msg(struct irq_data *data, struct msi_msg *msg) · line 400

Quoted 2 lines
drivers/pci/controller/pcie-mediatek.c +1 -1
-	addr = virt_to_phys(port->base + PCIE_MSI_VECTOR);
+	addr = virt_to_phys((__force void *)port->base + PCIE_MSI_VECTOR);

Lots of these drivers use either virt_to_phys() or platform_get_resource_byname() to get a physical address that they then use as the MSI target.

But I don't think that's quite right -- the MSI is a DMA transaction on PCI, and in general there's no guarantee that bus addresses are identical to CPU physical addresses, so shouldn't we use a dma_addr_t obtained from the DMA API?

Quoted 5 lines
Quoted 2 lines

dw_pcie_msi_host_init() has a complicated version of this that uses dmam_alloc_coherent().

Fair enough. I leave it to you then to get it fixed properly. Consider this as just a heads up for the old report.

Sounds good, thanks!

Bjorn