* [PATCH 0/2] PCI: mediatek: Allocate MSI address with dmam_alloc_coherent
@ 2023-12-06 8:37 Jianjun Wang
2023-12-06 8:37 ` [PATCH 1/2] " Jianjun Wang
2023-12-06 8:37 ` [PATCH 2/2] PCI: mediatek-gen3: " Jianjun Wang
0 siblings, 2 replies; 5+ messages in thread
From: Jianjun Wang @ 2023-12-06 8:37 UTC (permalink / raw)
To: Lorenzo Pieralisi, Krzysztof Wilczyński, Rob Herring,
Bjorn Helgaas, Matthias Brugger, AngeloGioacchino Del Regno
Cc: Ryder Lee, Jianjun Wang, linux-pci, linux-mediatek, linux-kernel,
linux-arm-kernel, jieyy.yang, chuanjia.liu, qizhong.cheng,
jian.yang, jianguo.zhang
These series of patches change the allocation of MSI address on MediaTek
platform, which uses 'dmam_alloc_coherent' to allocate the MSI address.
Jianjun Wang (2):
PCI: mediatek: Allocate MSI address with dmam_alloc_coherent
PCI: mediatek-gen3: Allocate MSI address with dmam_alloc_coherent
drivers/pci/controller/pcie-mediatek-gen3.c | 30 +++++++++++----------
drivers/pci/controller/pcie-mediatek.c | 29 +++++++++++++-------
2 files changed, 36 insertions(+), 23 deletions(-)
--
2.18.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] PCI: mediatek: Allocate MSI address with dmam_alloc_coherent
2023-12-06 8:37 [PATCH 0/2] PCI: mediatek: Allocate MSI address with dmam_alloc_coherent Jianjun Wang
@ 2023-12-06 8:37 ` Jianjun Wang
2023-12-06 17:07 ` Bjorn Helgaas
2023-12-06 8:37 ` [PATCH 2/2] PCI: mediatek-gen3: " Jianjun Wang
1 sibling, 1 reply; 5+ messages in thread
From: Jianjun Wang @ 2023-12-06 8:37 UTC (permalink / raw)
To: Lorenzo Pieralisi, Krzysztof Wilczyński, Rob Herring,
Bjorn Helgaas, Matthias Brugger, AngeloGioacchino Del Regno
Cc: Ryder Lee, Jianjun Wang, linux-pci, linux-mediatek, linux-kernel,
linux-arm-kernel, jieyy.yang, chuanjia.liu, qizhong.cheng,
jian.yang, jianguo.zhang
Use 'dmam_alloc_coherent' to allocate the MSI address, instead of using
'virt_to_phys'.
Signed-off-by: Jianjun Wang <jianjun.wang@mediatek.com>
---
drivers/pci/controller/pcie-mediatek.c | 29 ++++++++++++++++++--------
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/drivers/pci/controller/pcie-mediatek.c b/drivers/pci/controller/pcie-mediatek.c
index 66a8f73296fc..b080f7ca6da0 100644
--- a/drivers/pci/controller/pcie-mediatek.c
+++ b/drivers/pci/controller/pcie-mediatek.c
@@ -178,6 +178,7 @@ struct mtk_pcie_soc {
* @phy: pointer to PHY control block
* @slot: port slot
* @irq: GIC irq
+ * @msg_addr: MSI message address
* @irq_domain: legacy INTx IRQ domain
* @inner_domain: inner IRQ domain
* @msi_domain: MSI IRQ domain
@@ -198,6 +199,7 @@ struct mtk_pcie_port {
struct phy *phy;
u32 slot;
int irq;
+ dma_addr_t msg_addr;
struct irq_domain *irq_domain;
struct irq_domain *inner_domain;
struct irq_domain *msi_domain;
@@ -394,12 +396,10 @@ static struct pci_ops mtk_pcie_ops_v2 = {
static void mtk_compose_msi_msg(struct irq_data *data, struct msi_msg *msg)
{
struct mtk_pcie_port *port = irq_data_get_irq_chip_data(data);
- phys_addr_t addr;
/* MT2712/MT7622 only support 32-bit MSI addresses */
- addr = virt_to_phys(port->base + PCIE_MSI_VECTOR);
msg->address_hi = 0;
- msg->address_lo = lower_32_bits(addr);
+ msg->address_lo = lower_32_bits(port->msg_addr);
msg->data = data->hwirq;
@@ -515,18 +515,26 @@ static int mtk_pcie_allocate_msi_domains(struct mtk_pcie_port *port)
return 0;
}
-static void mtk_pcie_enable_msi(struct mtk_pcie_port *port)
+static int mtk_pcie_enable_msi(struct mtk_pcie_port *port)
{
u32 val;
- phys_addr_t msg_addr;
+ void *msi_vaddr;
- msg_addr = virt_to_phys(port->base + PCIE_MSI_VECTOR);
- val = lower_32_bits(msg_addr);
+ msi_vaddr = dmam_alloc_coherent(port->pcie->dev, sizeof(dma_addr_t), &port->msg_addr,
+ GFP_KERNEL);
+ if (!msi_vaddr) {
+ dev_err(port->pcie->dev, "failed to alloc and map MSI data\n");
+ return -ENOMEM;
+ }
+
+ val = lower_32_bits(port->msg_addr);
writel(val, port->base + PCIE_IMSI_ADDR);
val = readl(port->base + PCIE_INT_MASK);
val &= ~MSI_MASK;
writel(val, port->base + PCIE_INT_MASK);
+
+ return 0;
}
static void mtk_pcie_irq_teardown(struct mtk_pcie *pcie)
@@ -732,8 +740,11 @@ static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port)
val &= ~INTX_MASK;
writel(val, port->base + PCIE_INT_MASK);
- if (IS_ENABLED(CONFIG_PCI_MSI))
- mtk_pcie_enable_msi(port);
+ if (IS_ENABLED(CONFIG_PCI_MSI)) {
+ err = mtk_pcie_enable_msi(port);
+ if (err)
+ return err;
+ }
/* Set AHB to PCIe translation windows */
val = lower_32_bits(mem->start) |
--
2.18.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] PCI: mediatek-gen3: Allocate MSI address with dmam_alloc_coherent
2023-12-06 8:37 [PATCH 0/2] PCI: mediatek: Allocate MSI address with dmam_alloc_coherent Jianjun Wang
2023-12-06 8:37 ` [PATCH 1/2] " Jianjun Wang
@ 2023-12-06 8:37 ` Jianjun Wang
1 sibling, 0 replies; 5+ messages in thread
From: Jianjun Wang @ 2023-12-06 8:37 UTC (permalink / raw)
To: Lorenzo Pieralisi, Krzysztof Wilczyński, Rob Herring,
Bjorn Helgaas, Matthias Brugger, AngeloGioacchino Del Regno
Cc: Ryder Lee, Jianjun Wang, linux-pci, linux-mediatek, linux-kernel,
linux-arm-kernel, jieyy.yang, chuanjia.liu, qizhong.cheng,
jian.yang, jianguo.zhang
Use 'dmam_alloc_coherent' to allocate the MSI address, instead of using
static physical address.
Signed-off-by: Jianjun Wang <jianjun.wang@mediatek.com>
---
drivers/pci/controller/pcie-mediatek-gen3.c | 30 +++++++++++----------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/drivers/pci/controller/pcie-mediatek-gen3.c b/drivers/pci/controller/pcie-mediatek-gen3.c
index e0e27645fdf4..0b1b5c8e5288 100644
--- a/drivers/pci/controller/pcie-mediatek-gen3.c
+++ b/drivers/pci/controller/pcie-mediatek-gen3.c
@@ -108,7 +108,7 @@
*/
struct mtk_msi_set {
void __iomem *base;
- phys_addr_t msg_addr;
+ dma_addr_t msg_addr;
u32 saved_irq_state;
};
@@ -116,7 +116,6 @@ struct mtk_msi_set {
* struct mtk_gen3_pcie - PCIe port information
* @dev: pointer to PCIe device
* @base: IO mapped register base
- * @reg_base: physical register base
* @mac_reset: MAC reset control
* @phy_reset: PHY reset control
* @phy: PHY controller block
@@ -135,7 +134,6 @@ struct mtk_msi_set {
struct mtk_gen3_pcie {
struct device *dev;
void __iomem *base;
- phys_addr_t reg_base;
struct reset_control *mac_reset;
struct reset_control *phy_reset;
struct phy *phy;
@@ -278,18 +276,24 @@ static int mtk_pcie_set_trans_table(struct mtk_gen3_pcie *pcie,
return 0;
}
-static void mtk_pcie_enable_msi(struct mtk_gen3_pcie *pcie)
+static int mtk_pcie_enable_msi(struct mtk_gen3_pcie *pcie)
{
int i;
u32 val;
+ void *msi_vaddr;
for (i = 0; i < PCIE_MSI_SET_NUM; i++) {
struct mtk_msi_set *msi_set = &pcie->msi_sets[i];
msi_set->base = pcie->base + PCIE_MSI_SET_BASE_REG +
i * PCIE_MSI_SET_OFFSET;
- msi_set->msg_addr = pcie->reg_base + PCIE_MSI_SET_BASE_REG +
- i * PCIE_MSI_SET_OFFSET;
+
+ msi_vaddr = dmam_alloc_coherent(pcie->dev, sizeof(dma_addr_t), &msi_set->msg_addr,
+ GFP_KERNEL);
+ if (!msi_vaddr) {
+ dev_err(pcie->dev, "failed to alloc and map MSI data for set %d\n", i);
+ return -ENOMEM;
+ }
/* Configure the MSI capture address */
writel_relaxed(lower_32_bits(msi_set->msg_addr), msi_set->base);
@@ -305,6 +309,8 @@ static void mtk_pcie_enable_msi(struct mtk_gen3_pcie *pcie)
val = readl_relaxed(pcie->base + PCIE_INT_ENABLE_REG);
val |= PCIE_MSI_ENABLE;
writel_relaxed(val, pcie->base + PCIE_INT_ENABLE_REG);
+
+ return 0;
}
static int mtk_pcie_startup_port(struct mtk_gen3_pcie *pcie)
@@ -371,7 +377,9 @@ static int mtk_pcie_startup_port(struct mtk_gen3_pcie *pcie)
return err;
}
- mtk_pcie_enable_msi(pcie);
+ err = mtk_pcie_enable_msi(pcie);
+ if (err)
+ return err;
/* Set PCIe translation windows */
resource_list_for_each_entry(entry, &host->windows) {
@@ -762,20 +770,14 @@ static int mtk_pcie_parse_port(struct mtk_gen3_pcie *pcie)
{
struct device *dev = pcie->dev;
struct platform_device *pdev = to_platform_device(dev);
- struct resource *regs;
int ret;
- regs = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pcie-mac");
- if (!regs)
- return -EINVAL;
- pcie->base = devm_ioremap_resource(dev, regs);
+ pcie->base = devm_platform_ioremap_resource_byname(pdev, "pcie-mac");
if (IS_ERR(pcie->base)) {
dev_err(dev, "failed to map register base\n");
return PTR_ERR(pcie->base);
}
- pcie->reg_base = regs->start;
-
pcie->phy_reset = devm_reset_control_get_optional_exclusive(dev, "phy");
if (IS_ERR(pcie->phy_reset)) {
ret = PTR_ERR(pcie->phy_reset);
--
2.18.0
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] PCI: mediatek: Allocate MSI address with dmam_alloc_coherent
2023-12-06 8:37 ` [PATCH 1/2] " Jianjun Wang
@ 2023-12-06 17:07 ` Bjorn Helgaas
2023-12-07 8:18 ` Jianjun Wang (王建军)
0 siblings, 1 reply; 5+ messages in thread
From: Bjorn Helgaas @ 2023-12-06 17:07 UTC (permalink / raw)
To: Jianjun Wang
Cc: Lorenzo Pieralisi, Krzysztof Wilczyński, Rob Herring,
Bjorn Helgaas, Matthias Brugger, AngeloGioacchino Del Regno,
Ryder Lee, linux-pci, linux-mediatek, linux-kernel,
linux-arm-kernel, jieyy.yang, chuanjia.liu, qizhong.cheng,
jian.yang, jianguo.zhang
On Wed, Dec 06, 2023 at 04:37:52PM +0800, Jianjun Wang wrote:
> Use 'dmam_alloc_coherent' to allocate the MSI address, instead of using
> 'virt_to_phys'.
s/'dmam_alloc_coherent'/dmam_alloc_coherent()/
s/'virt_to_phys'/virt_to_phys()/
In subject also.
> @@ -732,8 +740,11 @@ static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port)
> val &= ~INTX_MASK;
> writel(val, port->base + PCIE_INT_MASK);
>
> - if (IS_ENABLED(CONFIG_PCI_MSI))
> - mtk_pcie_enable_msi(port);
> + if (IS_ENABLED(CONFIG_PCI_MSI)) {
> + err = mtk_pcie_enable_msi(port);
> + if (err)
> + return err;
Is failure to enable MSI a fatal issue? It looks like this will make
the host controller completely unusable if we can't set up MSI, even
if downstream PCI devices could use INTx and get along without MSI.
Bjorn
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/2] PCI: mediatek: Allocate MSI address with dmam_alloc_coherent
2023-12-06 17:07 ` Bjorn Helgaas
@ 2023-12-07 8:18 ` Jianjun Wang (王建军)
0 siblings, 0 replies; 5+ messages in thread
From: Jianjun Wang (王建军) @ 2023-12-07 8:18 UTC (permalink / raw)
To: helgaas@kernel.org
Cc: linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
Jieyy Yang (杨洁),
Chuanjia Liu (柳传嘉),
Jian Yang (杨戬),
Qizhong Cheng (程啟忠), robh@kernel.org,
kw@linux.com, linux-arm-kernel@lists.infradead.org,
matthias.bgg@gmail.com, bhelgaas@google.com,
lpieralisi@kernel.org, linux-pci@vger.kernel.org,
angelogioacchino.delregno@collabora.com,
Jianguo Zhang (张建国), Ryder Lee
Hi Bjorn,
On Wed, 2023-12-06 at 11:07 -0600, Bjorn Helgaas wrote:
> On Wed, Dec 06, 2023 at 04:37:52PM +0800, Jianjun Wang wrote:
> > Use 'dmam_alloc_coherent' to allocate the MSI address, instead of
> using
> > 'virt_to_phys'.
>
> s/'dmam_alloc_coherent'/dmam_alloc_coherent()/
> s/'virt_to_phys'/virt_to_phys()/
>
> In subject also.
>
> > @@ -732,8 +740,11 @@ static int mtk_pcie_startup_port_v2(struct
> mtk_pcie_port *port)
> > val &= ~INTX_MASK;
> > writel(val, port->base + PCIE_INT_MASK);
> >
> > -if (IS_ENABLED(CONFIG_PCI_MSI))
> > -mtk_pcie_enable_msi(port);
> > +if (IS_ENABLED(CONFIG_PCI_MSI)) {
> > +err = mtk_pcie_enable_msi(port);
> > +if (err)
> > +return err;
>
> Is failure to enable MSI a fatal issue? It looks like this will make
> the host controller completely unusable if we can't set up MSI, even
> if downstream PCI devices could use INTx and get along without MSI.
This shouldn't be a fatal issue, we can still use INTx, I'll fix them
in the next version, thanks for your review.
Thanks.
>
> Bjorn
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-12-07 8:20 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-06 8:37 [PATCH 0/2] PCI: mediatek: Allocate MSI address with dmam_alloc_coherent Jianjun Wang
2023-12-06 8:37 ` [PATCH 1/2] " Jianjun Wang
2023-12-06 17:07 ` Bjorn Helgaas
2023-12-07 8:18 ` Jianjun Wang (王建军)
2023-12-06 8:37 ` [PATCH 2/2] PCI: mediatek-gen3: " Jianjun Wang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).