Skip to content

Commit 63c83f1

Browse files
committed
Merge branch 'pci/controller/dwc-cpu-addr-fixup'
- Ioremap() msg_res region using res->start (the CPU address), not the ATU 'cpu_addr', which will be replaced with the ATU input address (which may not be the CPU address) (Frank Li) - Rename struct dw_pcie_ob_atu_cfg.cpu_addr to 'parent_bus_addr' (Frank Li) - Call devm_pci_alloc_host_bridge() early in dw_pcie_host_init() to keep devicetree-related code together (Frank Li) - Consolidate devicetree handling in dw_pcie_host_get_resources() (Bjorn Helgaas) - Add dw_pcie_parent_bus_offset() to look up the parent bus address of a specified 'reg' property and return the offset from the CPU physical address (Frank Li) - Add cross-checking with .cpu_addr_fixup() and debug logging to dw_pcie_parent_bus_offset() (Frank Li) - Use devicetree 'reg[config]' via dw_pcie_parent_bus_offset() to derive CPU -> ATU addr offset for host controller (Frank Li) - Call epc_create() early in dw_pcie_ep_init() to keep devicetree-related code together (Bjorn Helgaas) - Consolidate devicetree handling in dw_pcie_ep_get_resources() (Bjorn Helgaas) - Use devicetree 'reg[addr_space]' via dw_pcie_parent_bus_offset() to derive CPU -> ATU addr offset for endpoint controller (Frank Li) - Update dw_pcie_find_index() to remove assumption that ATU input address is non-zero (Frank Li) - Apply struct dw_pcie.parent_bus_offset in ATU users to remove use of .cpu_addr_fixup() when programming ATU (Frank Li) - Remove imx_pcie_cpu_addr_fixup() since dwc core can now derive the ATU input address (using parent_bus_offset) from devicetree (Frank Li) - Remove intel_pcie_cpu_addr() since dwc core can now derive the ATU input address (using parent_bus_offset) from devicetree (Frank Li) * pci/controller/dwc-cpu-addr-fixup: PCI: intel-gw: Remove intel_pcie_cpu_addr() PCI: imx6: Remove imx_pcie_cpu_addr_fixup() PCI: dwc: Use parent_bus_offset to remove need for .cpu_addr_fixup() PCI: dwc: ep: Ensure proper iteration over outbound map windows PCI: dwc: ep: Use devicetree 'reg[addr_space]' to derive CPU -> ATU addr offset PCI: dwc: ep: Consolidate devicetree handling in dw_pcie_ep_get_resources() PCI: dwc: ep: Call epc_create() early in dw_pcie_ep_init() PCI: dwc: Use devicetree 'reg[config]' to derive CPU -> ATU addr offset PCI: dwc: Add dw_pcie_parent_bus_offset() checking and debug PCI: dwc: Add dw_pcie_parent_bus_offset() PCI: dwc: Consolidate devicetree handling in dw_pcie_host_get_resources() PCI: dwc: Call devm_pci_alloc_host_bridge() early in dw_pcie_host_init() PCI: dwc: Rename cpu_addr to parent_bus_addr for ATU configuration PCI: dwc: Use resource start as ioremap() input in dw_pcie_pme_turn_off() # Conflicts: # drivers/pci/controller/dwc/pcie-designware.c # drivers/pci/controller/dwc/pcie-designware.h
2 parents 79e08f8 + 07ae413 commit 63c83f1

File tree

6 files changed

+186
-91
lines changed

6 files changed

+186
-91
lines changed

drivers/pci/controller/dwc/pci-imx6.c

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,22 +1214,6 @@ static void imx_pcie_host_exit(struct dw_pcie_rp *pp)
12141214
regulator_disable(imx_pcie->vpcie);
12151215
}
12161216

1217-
static u64 imx_pcie_cpu_addr_fixup(struct dw_pcie *pcie, u64 cpu_addr)
1218-
{
1219-
struct imx_pcie *imx_pcie = to_imx_pcie(pcie);
1220-
struct dw_pcie_rp *pp = &pcie->pp;
1221-
struct resource_entry *entry;
1222-
1223-
if (!(imx_pcie->drvdata->flags & IMX_PCIE_FLAG_CPU_ADDR_FIXUP))
1224-
return cpu_addr;
1225-
1226-
entry = resource_list_first_type(&pp->bridge->windows, IORESOURCE_MEM);
1227-
if (!entry)
1228-
return cpu_addr;
1229-
1230-
return cpu_addr - entry->offset;
1231-
}
1232-
12331217
/*
12341218
* In old DWC implementations, PCIE_ATU_INHIBIT_PAYLOAD in iATU Ctrl2
12351219
* register is reserved, so the generic DWC implementation of sending the
@@ -1260,7 +1244,6 @@ static const struct dw_pcie_host_ops imx_pcie_host_dw_pme_ops = {
12601244
static const struct dw_pcie_ops dw_pcie_ops = {
12611245
.start_link = imx_pcie_start_link,
12621246
.stop_link = imx_pcie_stop_link,
1263-
.cpu_addr_fixup = imx_pcie_cpu_addr_fixup,
12641247
};
12651248

12661249
static void imx_pcie_ep_init(struct dw_pcie_ep *ep)
@@ -1631,6 +1614,7 @@ static int imx_pcie_probe(struct platform_device *pdev)
16311614
if (ret)
16321615
return ret;
16331616

1617+
pci->use_parent_dt_ranges = true;
16341618
if (imx_pcie->drvdata->mode == DW_PCIE_EP_TYPE) {
16351619
ret = imx_add_pcie_ep(imx_pcie, pdev);
16361620
if (ret < 0)

drivers/pci/controller/dwc/pcie-designware-ep.c

Lines changed: 48 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ static int dw_pcie_ep_write_header(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
167167
}
168168

169169
static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, u8 func_no, int type,
170-
dma_addr_t cpu_addr, enum pci_barno bar,
170+
dma_addr_t parent_bus_addr, enum pci_barno bar,
171171
size_t size)
172172
{
173173
int ret;
@@ -185,7 +185,7 @@ static int dw_pcie_ep_inbound_atu(struct dw_pcie_ep *ep, u8 func_no, int type,
185185
}
186186

187187
ret = dw_pcie_prog_ep_inbound_atu(pci, func_no, free_win, type,
188-
cpu_addr, bar, size);
188+
parent_bus_addr, bar, size);
189189
if (ret < 0) {
190190
dev_err(pci->dev, "Failed to program IB window\n");
191191
return ret;
@@ -220,7 +220,7 @@ static int dw_pcie_ep_outbound_atu(struct dw_pcie_ep *ep,
220220
return ret;
221221

222222
set_bit(free_win, ep->ob_window_map);
223-
ep->outbound_addr[free_win] = atu->cpu_addr;
223+
ep->outbound_addr[free_win] = atu->parent_bus_addr;
224224

225225
return 0;
226226
}
@@ -451,7 +451,7 @@ static int dw_pcie_find_index(struct dw_pcie_ep *ep, phys_addr_t addr,
451451
u32 index;
452452
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
453453

454-
for (index = 0; index < pci->num_ob_windows; index++) {
454+
for_each_set_bit(index, ep->ob_window_map, pci->num_ob_windows) {
455455
if (ep->outbound_addr[index] != addr)
456456
continue;
457457
*atu_index = index;
@@ -483,7 +483,8 @@ static void dw_pcie_ep_unmap_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
483483
struct dw_pcie_ep *ep = epc_get_drvdata(epc);
484484
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
485485

486-
ret = dw_pcie_find_index(ep, addr, &atu_index);
486+
ret = dw_pcie_find_index(ep, addr - pci->parent_bus_offset,
487+
&atu_index);
487488
if (ret < 0)
488489
return;
489490

@@ -502,7 +503,7 @@ static int dw_pcie_ep_map_addr(struct pci_epc *epc, u8 func_no, u8 vfunc_no,
502503

503504
atu.func_no = func_no;
504505
atu.type = PCIE_ATU_TYPE_MEM;
505-
atu.cpu_addr = addr;
506+
atu.parent_bus_addr = addr - pci->parent_bus_offset;
506507
atu.pci_addr = pci_addr;
507508
atu.size = size;
508509
ret = dw_pcie_ep_outbound_atu(ep, &atu);
@@ -1060,26 +1061,15 @@ void dw_pcie_ep_linkdown(struct dw_pcie_ep *ep)
10601061
}
10611062
EXPORT_SYMBOL_GPL(dw_pcie_ep_linkdown);
10621063

1063-
/**
1064-
* dw_pcie_ep_init - Initialize the endpoint device
1065-
* @ep: DWC EP device
1066-
*
1067-
* Initialize the endpoint device. Allocate resources and create the EPC
1068-
* device with the endpoint framework.
1069-
*
1070-
* Return: 0 if success, errno otherwise.
1071-
*/
1072-
int dw_pcie_ep_init(struct dw_pcie_ep *ep)
1064+
static int dw_pcie_ep_get_resources(struct dw_pcie_ep *ep)
10731065
{
1074-
int ret;
1075-
struct resource *res;
1076-
struct pci_epc *epc;
10771066
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
10781067
struct device *dev = pci->dev;
10791068
struct platform_device *pdev = to_platform_device(dev);
10801069
struct device_node *np = dev->of_node;
1081-
1082-
INIT_LIST_HEAD(&ep->func_list);
1070+
struct pci_epc *epc = ep->epc;
1071+
struct resource *res;
1072+
int ret;
10831073

10841074
ret = dw_pcie_get_resources(pci);
10851075
if (ret)
@@ -1092,8 +1082,37 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
10921082
ep->phys_base = res->start;
10931083
ep->addr_size = resource_size(res);
10941084

1095-
if (ep->ops->pre_init)
1096-
ep->ops->pre_init(ep);
1085+
/*
1086+
* artpec6_pcie_cpu_addr_fixup() uses ep->phys_base, so call
1087+
* dw_pcie_parent_bus_offset() after setting ep->phys_base.
1088+
*/
1089+
pci->parent_bus_offset = dw_pcie_parent_bus_offset(pci, "addr_space",
1090+
ep->phys_base);
1091+
1092+
ret = of_property_read_u8(np, "max-functions", &epc->max_functions);
1093+
if (ret < 0)
1094+
epc->max_functions = 1;
1095+
1096+
return 0;
1097+
}
1098+
1099+
/**
1100+
* dw_pcie_ep_init - Initialize the endpoint device
1101+
* @ep: DWC EP device
1102+
*
1103+
* Initialize the endpoint device. Allocate resources and create the EPC
1104+
* device with the endpoint framework.
1105+
*
1106+
* Return: 0 if success, errno otherwise.
1107+
*/
1108+
int dw_pcie_ep_init(struct dw_pcie_ep *ep)
1109+
{
1110+
int ret;
1111+
struct pci_epc *epc;
1112+
struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
1113+
struct device *dev = pci->dev;
1114+
1115+
INIT_LIST_HEAD(&ep->func_list);
10971116

10981117
epc = devm_pci_epc_create(dev, &epc_ops);
10991118
if (IS_ERR(epc)) {
@@ -1104,9 +1123,12 @@ int dw_pcie_ep_init(struct dw_pcie_ep *ep)
11041123
ep->epc = epc;
11051124
epc_set_drvdata(epc, ep);
11061125

1107-
ret = of_property_read_u8(np, "max-functions", &epc->max_functions);
1108-
if (ret < 0)
1109-
epc->max_functions = 1;
1126+
ret = dw_pcie_ep_get_resources(ep);
1127+
if (ret)
1128+
return ret;
1129+
1130+
if (ep->ops->pre_init)
1131+
ep->ops->pre_init(ep);
11101132

11111133
ret = pci_epc_mem_init(epc, ep->phys_base, ep->addr_size,
11121134
ep->page_size);

drivers/pci/controller/dwc/pcie-designware-host.c

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -418,19 +418,15 @@ static void dw_pcie_host_request_msg_tlp_res(struct dw_pcie_rp *pp)
418418
}
419419
}
420420

421-
int dw_pcie_host_init(struct dw_pcie_rp *pp)
421+
static int dw_pcie_host_get_resources(struct dw_pcie_rp *pp)
422422
{
423423
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
424424
struct device *dev = pci->dev;
425-
struct device_node *np = dev->of_node;
426425
struct platform_device *pdev = to_platform_device(dev);
427426
struct resource_entry *win;
428-
struct pci_host_bridge *bridge;
429427
struct resource *res;
430428
int ret;
431429

432-
raw_spin_lock_init(&pp->lock);
433-
434430
ret = dw_pcie_get_resources(pci);
435431
if (ret)
436432
return ret;
@@ -448,20 +444,43 @@ int dw_pcie_host_init(struct dw_pcie_rp *pp)
448444
if (IS_ERR(pp->va_cfg0_base))
449445
return PTR_ERR(pp->va_cfg0_base);
450446

451-
bridge = devm_pci_alloc_host_bridge(dev, 0);
452-
if (!bridge)
453-
return -ENOMEM;
454-
455-
pp->bridge = bridge;
456-
457447
/* Get the I/O range from DT */
458-
win = resource_list_first_type(&bridge->windows, IORESOURCE_IO);
448+
win = resource_list_first_type(&pp->bridge->windows, IORESOURCE_IO);
459449
if (win) {
460450
pp->io_size = resource_size(win->res);
461451
pp->io_bus_addr = win->res->start - win->offset;
462452
pp->io_base = pci_pio_to_address(win->res->start);
463453
}
464454

455+
/*
456+
* visconti_pcie_cpu_addr_fixup() uses pp->io_base, so we have to
457+
* call dw_pcie_parent_bus_offset() after setting pp->io_base.
458+
*/
459+
pci->parent_bus_offset = dw_pcie_parent_bus_offset(pci, "config",
460+
pp->cfg0_base);
461+
return 0;
462+
}
463+
464+
int dw_pcie_host_init(struct dw_pcie_rp *pp)
465+
{
466+
struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
467+
struct device *dev = pci->dev;
468+
struct device_node *np = dev->of_node;
469+
struct pci_host_bridge *bridge;
470+
int ret;
471+
472+
raw_spin_lock_init(&pp->lock);
473+
474+
bridge = devm_pci_alloc_host_bridge(dev, 0);
475+
if (!bridge)
476+
return -ENOMEM;
477+
478+
pp->bridge = bridge;
479+
480+
ret = dw_pcie_host_get_resources(pp);
481+
if (ret)
482+
return ret;
483+
465484
/* Set default bus ops */
466485
bridge->ops = &dw_pcie_ops;
467486
bridge->child_ops = &dw_child_pcie_ops;
@@ -620,7 +639,7 @@ static void __iomem *dw_pcie_other_conf_map_bus(struct pci_bus *bus,
620639
type = PCIE_ATU_TYPE_CFG1;
621640

622641
atu.type = type;
623-
atu.cpu_addr = pp->cfg0_base;
642+
atu.parent_bus_addr = pp->cfg0_base - pci->parent_bus_offset;
624643
atu.pci_addr = busdev;
625644
atu.size = pp->cfg0_size;
626645

@@ -645,7 +664,7 @@ static int dw_pcie_rd_other_conf(struct pci_bus *bus, unsigned int devfn,
645664

646665
if (pp->cfg0_io_shared) {
647666
atu.type = PCIE_ATU_TYPE_IO;
648-
atu.cpu_addr = pp->io_base;
667+
atu.parent_bus_addr = pp->io_base - pci->parent_bus_offset;
649668
atu.pci_addr = pp->io_bus_addr;
650669
atu.size = pp->io_size;
651670

@@ -671,7 +690,7 @@ static int dw_pcie_wr_other_conf(struct pci_bus *bus, unsigned int devfn,
671690

672691
if (pp->cfg0_io_shared) {
673692
atu.type = PCIE_ATU_TYPE_IO;
674-
atu.cpu_addr = pp->io_base;
693+
atu.parent_bus_addr = pp->io_base - pci->parent_bus_offset;
675694
atu.pci_addr = pp->io_bus_addr;
676695
atu.size = pp->io_size;
677696

@@ -740,7 +759,7 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp)
740759

741760
atu.index = i;
742761
atu.type = PCIE_ATU_TYPE_MEM;
743-
atu.cpu_addr = entry->res->start;
762+
atu.parent_bus_addr = entry->res->start - pci->parent_bus_offset;
744763
atu.pci_addr = entry->res->start - entry->offset;
745764

746765
/* Adjust iATU size if MSG TLP region was allocated before */
@@ -762,7 +781,7 @@ static int dw_pcie_iatu_setup(struct dw_pcie_rp *pp)
762781
if (pci->num_ob_windows > ++i) {
763782
atu.index = i;
764783
atu.type = PCIE_ATU_TYPE_IO;
765-
atu.cpu_addr = pp->io_base;
784+
atu.parent_bus_addr = pp->io_base - pci->parent_bus_offset;
766785
atu.pci_addr = pp->io_bus_addr;
767786
atu.size = pp->io_size;
768787

@@ -906,13 +925,13 @@ static int dw_pcie_pme_turn_off(struct dw_pcie *pci)
906925
atu.size = resource_size(pci->pp.msg_res);
907926
atu.index = pci->pp.msg_atu_index;
908927

909-
atu.cpu_addr = pci->pp.msg_res->start;
928+
atu.parent_bus_addr = pci->pp.msg_res->start - pci->parent_bus_offset;
910929

911930
ret = dw_pcie_prog_outbound_atu(pci, &atu);
912931
if (ret)
913932
return ret;
914933

915-
mem = ioremap(atu.cpu_addr, pci->region_align);
934+
mem = ioremap(pci->pp.msg_res->start, pci->region_align);
916935
if (!mem)
917936
return -ENOMEM;
918937

0 commit comments

Comments
 (0)