PCI: mediatek: Allocate MSI address with dmam_alloc_coherent
cover PCI: mediatek: Allocate MSI address with dmam_alloc_coherent
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(-)
Signature · 1 line
2.18.0
PATCH 1/2 PCI: mediatek: Allocate MSI address with dmam_alloc_coherent
Use 'dmam_alloc_coherent' to allocate the MSI address, instead of using 'virt_to_phys'.
--- drivers/pci/controller/pcie-mediatek.c | 29 ++++++++++++++++++-------- 1 file changed, 20 insertions(+), 9 deletions(-)
drivers/pci/controller/pcie-mediatek.c +20 -9
@@ -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) |
Signature · 1 line
2.18.0
PATCH 2/2 PCI: mediatek-gen3: Allocate MSI address with dmam_alloc_coherent
In reply to Jianjun WangUse 'dmam_alloc_coherent' to allocate the MSI address, instead of using static physical address.
--- drivers/pci/controller/pcie-mediatek-gen3.c | 30 +++++++++++---------- 1 file changed, 16 insertions(+), 14 deletions(-)
drivers/pci/controller/pcie-mediatek-gen3.c +16 -14
@@ -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);
Signature · 1 line
2.18.0
Quoted 2 lines · Jianjun Wang
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.
drivers/pci/controller/pcie-mediatek.c static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port) · line 746
Quoted 10 lines
drivers/pci/controller/pcie-mediatek.c +4
-2@@ -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
Hi Bjorn,
Quoted 15 lines · Bjorn Helgaas
Quoted 1 line · Jianjun Wang
Use '
dmam_alloc_coherent' to allocate the MSI address, instead ofusing
Quoted 1 line
'
virt_to_phys'.s/'dmam_alloc_coherent'/dmam_alloc_coherent()/
s/'virt_to_phys'/virt_to_phys()/In subject also.
Review static int mtk_pcie_startup_port_v2(struct
Quoted 1 line
(quoted diff) +0
-0@@ -732,8 +740,11 @@ static int mtk_pcie_startup_port_v2(struct
mtk_pcie_port*port)Quoted 3 lines
drivers/pci/controller/pcie-mediatek.c +0
-0val &= ~INTX_MASK ;writel (val, port->base +PCIE_INT_MASK );
Quoted 10 lines
drivers/pci/controller/pcie-mediatek.c static int mtk_pcie_startup_port_v2(struct mtk_pcie_port *port) · line 746
Quoted 6 lines
drivers/pci/controller/pcie-mediatek.c +4
-2-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.
Quoted 2 lines
Bjorn