Skip to content

Commit 39bd5f8

Browse files
mindachen1987bjorn-helgaas
authored andcommitted
PCI: microchip: Move PLDA functions to pcie-plda-host.c
Move plda_pcie_setup_window() and plda_pcie_setup_iomems() to pcie-plda-host.c so they can be shared by all PLDA-based drivers. Link: https://lore.kernel.org/linux-pci/[email protected] Signed-off-by: Minda Chen <[email protected]> Signed-off-by: Krzysztof Wilczyński <[email protected]> Signed-off-by: Bjorn Helgaas <[email protected]> Reviewed-by: Conor Dooley <[email protected]>
1 parent ed18db1 commit 39bd5f8

File tree

6 files changed

+85
-60
lines changed

6 files changed

+85
-60
lines changed

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17224,6 +17224,7 @@ M: Daire McNamara <[email protected]>
1722417224
1722517225
S: Maintained
1722617226
F: Documentation/devicetree/bindings/pci/plda,xpressrich3-axi-common.yaml
17227+
F: drivers/pci/controller/plda/pcie-plda-host.c
1722717228
F: drivers/pci/controller/plda/pcie-plda.h
1722817229

1722917230
PCI DRIVER FOR RENESAS R-CAR

drivers/pci/controller/plda/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
menu "PLDA-based PCIe controllers"
44
depends on PCI
55

6+
config PCIE_PLDA_HOST
7+
bool
8+
69
config PCIE_MICROCHIP_HOST
710
tristate "Microchip AXI PCIe controller"
811
depends on PCI_MSI && OF
912
select PCI_HOST_COMMON
13+
select PCIE_PLDA_HOST
1014
help
1115
Say Y here if you want kernel to support the Microchip AXI PCIe
1216
Host Bridge driver.

drivers/pci/controller/plda/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
# SPDX-License-Identifier: GPL-2.0
2+
obj-$(CONFIG_PCIE_PLDA_HOST) += pcie-plda-host.o
23
obj-$(CONFIG_PCIE_MICROCHIP_HOST) += pcie-microchip-host.o

drivers/pci/controller/plda/pcie-microchip-host.c

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -838,66 +838,6 @@ static int mc_pcie_init_irq_domains(struct plda_pcie_rp *port)
838838
return mc_allocate_msi_domains(port);
839839
}
840840

841-
static void plda_pcie_setup_window(void __iomem *bridge_base_addr, u32 index,
842-
phys_addr_t axi_addr, phys_addr_t pci_addr,
843-
size_t size)
844-
{
845-
u32 atr_sz = ilog2(size) - 1;
846-
u32 val;
847-
848-
if (index == 0)
849-
val = PCIE_CONFIG_INTERFACE;
850-
else
851-
val = PCIE_TX_RX_INTERFACE;
852-
853-
writel(val, bridge_base_addr + (index * ATR_ENTRY_SIZE) +
854-
ATR0_AXI4_SLV0_TRSL_PARAM);
855-
856-
val = lower_32_bits(axi_addr) | (atr_sz << ATR_SIZE_SHIFT) |
857-
ATR_IMPL_ENABLE;
858-
writel(val, bridge_base_addr + (index * ATR_ENTRY_SIZE) +
859-
ATR0_AXI4_SLV0_SRCADDR_PARAM);
860-
861-
val = upper_32_bits(axi_addr);
862-
writel(val, bridge_base_addr + (index * ATR_ENTRY_SIZE) +
863-
ATR0_AXI4_SLV0_SRC_ADDR);
864-
865-
val = lower_32_bits(pci_addr);
866-
writel(val, bridge_base_addr + (index * ATR_ENTRY_SIZE) +
867-
ATR0_AXI4_SLV0_TRSL_ADDR_LSB);
868-
869-
val = upper_32_bits(pci_addr);
870-
writel(val, bridge_base_addr + (index * ATR_ENTRY_SIZE) +
871-
ATR0_AXI4_SLV0_TRSL_ADDR_UDW);
872-
873-
val = readl(bridge_base_addr + ATR0_PCIE_WIN0_SRCADDR_PARAM);
874-
val |= (ATR0_PCIE_ATR_SIZE << ATR0_PCIE_ATR_SIZE_SHIFT);
875-
writel(val, bridge_base_addr + ATR0_PCIE_WIN0_SRCADDR_PARAM);
876-
writel(0, bridge_base_addr + ATR0_PCIE_WIN0_SRC_ADDR);
877-
}
878-
879-
static int plda_pcie_setup_iomems(struct platform_device *pdev,
880-
struct plda_pcie_rp *port)
881-
{
882-
void __iomem *bridge_base_addr = port->bridge_addr;
883-
struct pci_host_bridge *bridge = platform_get_drvdata(pdev);
884-
struct resource_entry *entry;
885-
u64 pci_addr;
886-
u32 index = 1;
887-
888-
resource_list_for_each_entry(entry, &bridge->windows) {
889-
if (resource_type(entry->res) == IORESOURCE_MEM) {
890-
pci_addr = entry->res->start - entry->offset;
891-
plda_pcie_setup_window(bridge_base_addr, index,
892-
entry->res->start, pci_addr,
893-
resource_size(entry->res));
894-
index++;
895-
}
896-
}
897-
898-
return 0;
899-
}
900-
901841
static inline void mc_clear_secs(struct mc_pcie *port)
902842
{
903843
void __iomem *ctrl_base_addr = port->axi_base_addr + MC_PCIE_CTRL_ADDR;
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* PLDA PCIe XpressRich host controller driver
4+
*
5+
* Copyright (C) 2023 Microchip Co. Ltd
6+
*
7+
* Author: Daire McNamara <[email protected]>
8+
*/
9+
10+
#include <linux/pci-ecam.h>
11+
12+
#include "pcie-plda.h"
13+
14+
void plda_pcie_setup_window(void __iomem *bridge_base_addr, u32 index,
15+
phys_addr_t axi_addr, phys_addr_t pci_addr,
16+
size_t size)
17+
{
18+
u32 atr_sz = ilog2(size) - 1;
19+
u32 val;
20+
21+
if (index == 0)
22+
val = PCIE_CONFIG_INTERFACE;
23+
else
24+
val = PCIE_TX_RX_INTERFACE;
25+
26+
writel(val, bridge_base_addr + (index * ATR_ENTRY_SIZE) +
27+
ATR0_AXI4_SLV0_TRSL_PARAM);
28+
29+
val = lower_32_bits(axi_addr) | (atr_sz << ATR_SIZE_SHIFT) |
30+
ATR_IMPL_ENABLE;
31+
writel(val, bridge_base_addr + (index * ATR_ENTRY_SIZE) +
32+
ATR0_AXI4_SLV0_SRCADDR_PARAM);
33+
34+
val = upper_32_bits(axi_addr);
35+
writel(val, bridge_base_addr + (index * ATR_ENTRY_SIZE) +
36+
ATR0_AXI4_SLV0_SRC_ADDR);
37+
38+
val = lower_32_bits(pci_addr);
39+
writel(val, bridge_base_addr + (index * ATR_ENTRY_SIZE) +
40+
ATR0_AXI4_SLV0_TRSL_ADDR_LSB);
41+
42+
val = upper_32_bits(pci_addr);
43+
writel(val, bridge_base_addr + (index * ATR_ENTRY_SIZE) +
44+
ATR0_AXI4_SLV0_TRSL_ADDR_UDW);
45+
46+
val = readl(bridge_base_addr + ATR0_PCIE_WIN0_SRCADDR_PARAM);
47+
val |= (ATR0_PCIE_ATR_SIZE << ATR0_PCIE_ATR_SIZE_SHIFT);
48+
writel(val, bridge_base_addr + ATR0_PCIE_WIN0_SRCADDR_PARAM);
49+
writel(0, bridge_base_addr + ATR0_PCIE_WIN0_SRC_ADDR);
50+
}
51+
EXPORT_SYMBOL_GPL(plda_pcie_setup_window);
52+
53+
int plda_pcie_setup_iomems(struct platform_device *pdev,
54+
struct plda_pcie_rp *port)
55+
{
56+
void __iomem *bridge_base_addr = port->bridge_addr;
57+
struct pci_host_bridge *bridge = platform_get_drvdata(pdev);
58+
struct resource_entry *entry;
59+
u64 pci_addr;
60+
u32 index = 1;
61+
62+
resource_list_for_each_entry(entry, &bridge->windows) {
63+
if (resource_type(entry->res) == IORESOURCE_MEM) {
64+
pci_addr = entry->res->start - entry->offset;
65+
plda_pcie_setup_window(bridge_base_addr, index,
66+
entry->res->start, pci_addr,
67+
resource_size(entry->res));
68+
index++;
69+
}
70+
}
71+
72+
return 0;
73+
}
74+
EXPORT_SYMBOL_GPL(plda_pcie_setup_iomems);

drivers/pci/controller/plda/pcie-plda.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,9 @@ struct plda_pcie_rp {
126126
void __iomem *bridge_addr;
127127
};
128128

129+
void plda_pcie_setup_window(void __iomem *bridge_base_addr, u32 index,
130+
phys_addr_t axi_addr, phys_addr_t pci_addr,
131+
size_t size);
132+
int plda_pcie_setup_iomems(struct platform_device *pdev,
133+
struct plda_pcie_rp *port);
129134
#endif

0 commit comments

Comments
 (0)