Commit 9ca17af5 authored by Rob Herring's avatar Rob Herring Committed by Lorenzo Pieralisi

PCI: dwc: Move inbound and outbound windows to common struct

The number of inbound and outbound windows are defined by the h/w and
apply to both RC and EP modes, so move them to the appropriate struct.

Link: https://lore.kernel.org/r/20201105211159.1814485-16-robh@kernel.orgTested-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Signed-off-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarLorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Jingoo Han <jingoohan1@gmail.com>
Cc: Gustavo Pimentel <gustavo.pimentel@synopsys.com>
Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
Cc: Bjorn Helgaas <bhelgaas@google.com>
parent fcde3974
...@@ -161,8 +161,8 @@ static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, u8 func_no, ...@@ -161,8 +161,8 @@ static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, u8 func_no,
u32 free_win; u32 free_win;
struct dw_pcie *pci = to_dw_pcie_from_ep(ep); struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
free_win = find_first_zero_bit(ep->ib_window_map, ep->num_ib_windows); free_win = find_first_zero_bit(ep->ib_window_map, pci->num_ib_windows);
if (free_win >= ep->num_ib_windows) { if (free_win >= pci->num_ib_windows) {
dev_err(pci->dev, "No free inbound window\n"); dev_err(pci->dev, "No free inbound window\n");
return -EINVAL; return -EINVAL;
} }
...@@ -187,8 +187,8 @@ static int dw_pcie_ep_outbound_atu(struct dw_pcie_ep *ep, u8 func_no, ...@@ -187,8 +187,8 @@ static int dw_pcie_ep_outbound_atu(struct dw_pcie_ep *ep, u8 func_no,
u32 free_win; u32 free_win;
struct dw_pcie *pci = to_dw_pcie_from_ep(ep); struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
free_win = find_first_zero_bit(ep->ob_window_map, ep->num_ob_windows); free_win = find_first_zero_bit(ep->ob_window_map, pci->num_ob_windows);
if (free_win >= ep->num_ob_windows) { if (free_win >= pci->num_ob_windows) {
dev_err(pci->dev, "No free outbound window\n"); dev_err(pci->dev, "No free outbound window\n");
return -EINVAL; return -EINVAL;
} }
...@@ -264,8 +264,9 @@ static int dw_pcie_find_index(struct dw_pcie_ep *ep, phys_addr_t addr, ...@@ -264,8 +264,9 @@ static int dw_pcie_find_index(struct dw_pcie_ep *ep, phys_addr_t addr,
u32 *atu_index) u32 *atu_index)
{ {
u32 index; u32 index;
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
for (index = 0; index < ep->num_ob_windows; index++) { for (index = 0; index < pci->num_ob_windows; index++) {
if (ep->outbound_addr[index] != addr) if (ep->outbound_addr[index] != addr)
continue; continue;
*atu_index = index; *atu_index = index;
...@@ -713,41 +714,41 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep) ...@@ -713,41 +714,41 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
ep->phys_base = res->start; ep->phys_base = res->start;
ep->addr_size = resource_size(res); ep->addr_size = resource_size(res);
ret = of_property_read_u32(np, "num-ib-windows", &ep->num_ib_windows); ret = of_property_read_u32(np, "num-ib-windows", &pci->num_ib_windows);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "Unable to read *num-ib-windows* property\n"); dev_err(dev, "Unable to read *num-ib-windows* property\n");
return ret; return ret;
} }
if (ep->num_ib_windows > MAX_IATU_IN) { if (pci->num_ib_windows > MAX_IATU_IN) {
dev_err(dev, "Invalid *num-ib-windows*\n"); dev_err(dev, "Invalid *num-ib-windows*\n");
return -EINVAL; return -EINVAL;
} }
ret = of_property_read_u32(np, "num-ob-windows", &ep->num_ob_windows); ret = of_property_read_u32(np, "num-ob-windows", &pci->num_ob_windows);
if (ret < 0) { if (ret < 0) {
dev_err(dev, "Unable to read *num-ob-windows* property\n"); dev_err(dev, "Unable to read *num-ob-windows* property\n");
return ret; return ret;
} }
if (ep->num_ob_windows > MAX_IATU_OUT) { if (pci->num_ob_windows > MAX_IATU_OUT) {
dev_err(dev, "Invalid *num-ob-windows*\n"); dev_err(dev, "Invalid *num-ob-windows*\n");
return -EINVAL; return -EINVAL;
} }
ep->ib_window_map = devm_kcalloc(dev, ep->ib_window_map = devm_kcalloc(dev,
BITS_TO_LONGS(ep->num_ib_windows), BITS_TO_LONGS(pci->num_ib_windows),
sizeof(long), sizeof(long),
GFP_KERNEL); GFP_KERNEL);
if (!ep->ib_window_map) if (!ep->ib_window_map)
return -ENOMEM; return -ENOMEM;
ep->ob_window_map = devm_kcalloc(dev, ep->ob_window_map = devm_kcalloc(dev,
BITS_TO_LONGS(ep->num_ob_windows), BITS_TO_LONGS(pci->num_ob_windows),
sizeof(long), sizeof(long),
GFP_KERNEL); GFP_KERNEL);
if (!ep->ob_window_map) if (!ep->ob_window_map)
return -ENOMEM; return -ENOMEM;
addr = devm_kcalloc(dev, ep->num_ob_windows, sizeof(phys_addr_t), addr = devm_kcalloc(dev, pci->num_ob_windows, sizeof(phys_addr_t),
GFP_KERNEL); GFP_KERNEL);
if (!addr) if (!addr)
return -ENOMEM; return -ENOMEM;
......
...@@ -237,8 +237,6 @@ struct dw_pcie_ep { ...@@ -237,8 +237,6 @@ struct dw_pcie_ep {
phys_addr_t *outbound_addr; phys_addr_t *outbound_addr;
unsigned long *ib_window_map; unsigned long *ib_window_map;
unsigned long *ob_window_map; unsigned long *ob_window_map;
u32 num_ib_windows;
u32 num_ob_windows;
void __iomem *msi_mem; void __iomem *msi_mem;
phys_addr_t msi_mem_phys; phys_addr_t msi_mem_phys;
struct pci_epf_bar *epf_bar[PCI_STD_NUM_BARS]; struct pci_epf_bar *epf_bar[PCI_STD_NUM_BARS];
...@@ -264,6 +262,8 @@ struct dw_pcie { ...@@ -264,6 +262,8 @@ struct dw_pcie {
/* Used when iatu_unroll_enabled is true */ /* Used when iatu_unroll_enabled is true */
void __iomem *atu_base; void __iomem *atu_base;
u32 num_viewport; u32 num_viewport;
u32 num_ib_windows;
u32 num_ob_windows;
struct pcie_port pp; struct pcie_port pp;
struct dw_pcie_ep ep; struct dw_pcie_ep ep;
const struct dw_pcie_ops *ops; const struct dw_pcie_ops *ops;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment