History

Merge branch 'remotes/lorenzo/pci/endpoint'

- Use memcpy_fromio()/memcpy_toio() instead of plain memcpy() in PCI endpoint framework (Wen Yang) - Add interface to discover supported endpoint features to replace a bitfield that wasn't flexible enough (Kishon Vijay Abraham I) - Implement the new supported-feature interface for designware-plat, dra7xx, rockchip, cadence (Kishon Vijay Abraham I) - Fix issues with 64-bit BAR in endpoints (Kishon Vijay Abraham I) - Add layerscape endpoint mode support (Xiaowei Bao) * remotes/lorenzo/pci/endpoint: misc: pci_endpoint_test: Add the layerscape EP device support PCI: layerscape: Add EP mode support arm64: dts: Add the PCIE EP node in dts dt-bindings: add DT binding for the layerscape PCIe controller with EP mode PCI: endpoint: Remove features member in struct pci_epc PCI: designware-plat: Remove setting epc->features in Designware plat EP driver PCI: rockchip: Remove pci_epf_linkup() from Rockchip EP driver PCI: cadence: Remove pci_epf_linkup() from Cadence EP driver PCI: pci-epf-test: Use pci_epc_get_features() to get EPC features PCI: pci-epf-test: Do not allocate next BARs memory if current BAR is 64Bit PCI: pci-epf-test: Remove setting epf_bar flags in function driver PCI: endpoint: Fix pci_epf_alloc_space() to set correct MEM TYPE flags PCI: endpoint: Add helper to get first unreserved BAR PCI: cadence: Populate ->get_features() cdns_pcie_epc_ops PCI: rockchip: Populate ->get_features() dw_pcie_ep_ops PCI: pci-dra7xx: Populate ->get_features() dw_pcie_ep_ops PCI: designware-plat: Populate ->get_features() dw_pcie_ep_ops PCI: dwc: Add ->get_features() callback function to dw_pcie_ep_ops PCI: endpoint: Add new pci_epc_ops to get EPC features PCI: endpoint: functions: Use memcpy_fromio()/memcpy_toio()

Bjorn Helgaas committed 7 years ago

Commit 7e5b22d2 parents 2506419 85cef3715 files · +397 −68Browse files

Unified · Split

15 files
  1. Documentation/devicetree/bindings/pci/layerscape-pci.txt +3 −0
  2. arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi +33 −1
  3. drivers/misc/pci_endpoint_test.c +1 −0
  4. drivers/pci/controller/dwc/Makefile +1 −1
  5. drivers/pci/controller/dwc/pci-dra7xx.c +13 −0
  6. drivers/pci/controller/dwc/pci-layerscape-ep.c +156 −0
  7. drivers/pci/controller/dwc/pcie-designware-ep.c +12 −0
  8. drivers/pci/controller/dwc/pcie-designware-plat.c +13 −4
  9. drivers/pci/controller/dwc/pcie-designware.h +1 −0
  10. drivers/pci/controller/pcie-cadence-ep.c +13 −12
  11. drivers/pci/controller/pcie-rockchip-ep.c +13 −3
  12. drivers/pci/endpoint/functions/pci-epf-test.c +59 −38
  13. drivers/pci/endpoint/pci-epc-core.c +53 −0
  14. drivers/pci/endpoint/pci-epf-core.c +3 −1
  15. include/linux/pci-epc.h +23 −8
Documentation/devicetree/bindings/pci/layerscape-pci.txt+3−0
@@ -13,6 +13,7 @@ information. · 12 unmodified lines
13 13
14Required properties:14Required properties:
15- compatible: should contain the platform identifier such as:15- compatible: should contain the platform identifier such as:
16 RC mode:
16 "fsl,ls1021a-pcie"17 "fsl,ls1021a-pcie"
17 "fsl,ls2080a-pcie", "fsl,ls2085a-pcie"18 "fsl,ls2080a-pcie", "fsl,ls2085a-pcie"
18 "fsl,ls2088a-pcie"19 "fsl,ls2088a-pcie"
@@ -20,6 +21,8 @@ Required properties: · 1 unmodified line
20 "fsl,ls1046a-pcie"21 "fsl,ls1046a-pcie"
21 "fsl,ls1043a-pcie"22 "fsl,ls1043a-pcie"
22 "fsl,ls1012a-pcie"23 "fsl,ls1012a-pcie"
24 EP mode:
25 "fsl,ls1046a-pcie-ep", "fsl,ls-pcie-ep"
23- reg: base addresses and lengths of the PCIe controller register blocks.26- reg: base addresses and lengths of the PCIe controller register blocks.
24- interrupts: A list of interrupt outputs of the controller. Must contain an27- interrupts: A list of interrupt outputs of the controller. Must contain an
25 entry for each entry in the interrupt-names property.28 entry for each entry in the interrupt-names property.
arch/arm64/boot/dts/freescale/fsl-ls1046a.dtsi+33−1
@@ -657,6 +657,17 @@ · 656 unmodified lines
657 status = "disabled";657 status = "disabled";
658 };658 };
659 659
660 pcie_ep@3400000 {
661 compatible = "fsl,ls1046a-pcie-ep","fsl,ls-pcie-ep";
662 reg = <0x00 0x03400000 0x0 0x00100000
663 0x40 0x00000000 0x8 0x00000000>;
664 reg-names = "regs", "addr_space";
665 num-ib-windows = <6>;
666 num-ob-windows = <8>;
667 num-lanes = <2>;
668 status = "disabled";
669 };
670
660 pcie@3500000 {671 pcie@3500000 {
661 compatible = "fsl,ls1046a-pcie";672 compatible = "fsl,ls1046a-pcie";
662 reg = <0x00 0x03500000 0x0 0x00100000 /* controller registers */673 reg = <0x00 0x03500000 0x0 0x00100000 /* controller registers */
@@ -683,6 +694,17 @@ · 20 unmodified lines
683 status = "disabled";694 status = "disabled";
684 };695 };
685 696
697 pcie_ep@3500000 {
698 compatible = "fsl,ls1046a-pcie-ep","fsl,ls-pcie-ep";
699 reg = <0x00 0x03500000 0x0 0x00100000
700 0x48 0x00000000 0x8 0x00000000>;
701 reg-names = "regs", "addr_space";
702 num-ib-windows = <6>;
703 num-ob-windows = <8>;
704 num-lanes = <2>;
705 status = "disabled";
706 };
707
686 pcie@3600000 {708 pcie@3600000 {
687 compatible = "fsl,ls1046a-pcie";709 compatible = "fsl,ls1046a-pcie";
688 reg = <0x00 0x03600000 0x0 0x00100000 /* controller registers */710 reg = <0x00 0x03600000 0x0 0x00100000 /* controller registers */
@@ -709,6 +731,17 @@ · 20 unmodified lines
709 status = "disabled";731 status = "disabled";
710 };732 };
711 733
734 pcie_ep@3600000 {
735 compatible = "fsl,ls1046a-pcie-ep", "fsl,ls-pcie-ep";
736 reg = <0x00 0x03600000 0x0 0x00100000
737 0x50 0x00000000 0x8 0x00000000>;
738 reg-names = "regs", "addr_space";
739 num-ib-windows = <6>;
740 num-ob-windows = <8>;
741 num-lanes = <2>;
742 status = "disabled";
743 };
744
712 qdma: dma-controller@8380000 {745 qdma: dma-controller@8380000 {
713 compatible = "fsl,ls1046a-qdma", "fsl,ls1021a-qdma";746 compatible = "fsl,ls1046a-qdma", "fsl,ls1021a-qdma";
714 reg = <0x0 0x8380000 0x0 0x1000>, /* Controller regs */747 reg = <0x0 0x8380000 0x0 0x1000>, /* Controller regs */
@@ -729,7 +762,6 @@ · 14 unmodified lines
729 queue-sizes = <64 64>;762 queue-sizes = <64 64>;
730 big-endian;763 big-endian;
731 };764 };
732
733 };765 };
734 766
735 reserved-memory {767 reserved-memory {
drivers/misc/pci_endpoint_test.c+1−0
@@ -788,6 +788,7 @@ static void pci_endpoint_test_remove(struct pci_dev *pdev) · 787 unmodified lines
788static const struct pci_device_id pci_endpoint_test_tbl[] = {788static const struct pci_device_id pci_endpoint_test_tbl[] = {
789 { PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA74x) },789 { PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA74x) },
790 { PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA72x) },790 { PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA72x) },
791 { PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, 0x81c0) },
791 { PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 0xedda) },792 { PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 0xedda) },
792 { }793 { }
793};794};
drivers/pci/controller/dwc/Makefile+1−1
@@ -8,7 +8,7 @@ obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o · 7 unmodified lines
8obj-$(CONFIG_PCI_IMX6) += pci-imx6.o8obj-$(CONFIG_PCI_IMX6) += pci-imx6.o
9obj-$(CONFIG_PCIE_SPEAR13XX) += pcie-spear13xx.o9obj-$(CONFIG_PCIE_SPEAR13XX) += pcie-spear13xx.o
10obj-$(CONFIG_PCI_KEYSTONE) += pci-keystone.o10obj-$(CONFIG_PCI_KEYSTONE) += pci-keystone.o
11obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o11obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o pci-layerscape-ep.o
12obj-$(CONFIG_PCIE_QCOM) += pcie-qcom.o12obj-$(CONFIG_PCIE_QCOM) += pcie-qcom.o
13obj-$(CONFIG_PCIE_ARMADA_8K) += pcie-armada8k.o13obj-$(CONFIG_PCIE_ARMADA_8K) += pcie-armada8k.o
14obj-$(CONFIG_PCIE_ARTPEC6) += pcie-artpec6.o14obj-$(CONFIG_PCIE_ARTPEC6) += pcie-artpec6.o
drivers/pci/controller/dwc/pci-dra7xx.c+13−0
@@ -394,9 +394,22 @@ static int dra7xx_pcie_raise_irq(struct dw_pcie_ep *ep, u8 func_no, · 393 unmodified lines
394 return 0;394 return 0;
395}395}
396 396
397static const struct pci_epc_features dra7xx_pcie_epc_features = {
398 .linkup_notifier = true,
399 .msi_capable = true,
400 .msix_capable = false,
401};
402
403static const struct pci_epc_features*
404dra7xx_pcie_get_features(struct dw_pcie_ep *ep)
405{
406 return &dra7xx_pcie_epc_features;
407}
408
397static struct dw_pcie_ep_ops pcie_ep_ops = {409static struct dw_pcie_ep_ops pcie_ep_ops = {
398 .ep_init = dra7xx_pcie_ep_init,410 .ep_init = dra7xx_pcie_ep_init,
399 .raise_irq = dra7xx_pcie_raise_irq,411 .raise_irq = dra7xx_pcie_raise_irq,
412 .get_features = dra7xx_pcie_get_features,
400};413};
401 414
402static int __init dra7xx_add_pcie_ep(struct dra7xx_pcie *dra7xx,415static int __init dra7xx_add_pcie_ep(struct dra7xx_pcie *dra7xx,
drivers/pci/controller/dwc/pci-layerscape-ep.c+156−0
@@ -0,0 +1,156 @@
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * PCIe controller EP driver for Freescale Layerscape SoCs
4 *
5 * Copyright (C) 2018 NXP Semiconductor.
6 *
7 * Author: Xiaowei Bao <xiaowei.bao@nxp.com>
8 */
9
10#include <linux/kernel.h>
11#include <linux/init.h>
12#include <linux/of_pci.h>
13#include <linux/of_platform.h>
14#include <linux/of_address.h>
15#include <linux/pci.h>
16#include <linux/platform_device.h>
17#include <linux/resource.h>
18
19#include "pcie-designware.h"
20
21#define PCIE_DBI2_OFFSET 0x1000 /* DBI2 base address*/
22
23struct ls_pcie_ep {
24 struct dw_pcie *pci;
25};
26
27#define to_ls_pcie_ep(x) dev_get_drvdata((x)->dev)
28
29static int ls_pcie_establish_link(struct dw_pcie *pci)
30{
31 return 0;
32}
33
34static const struct dw_pcie_ops ls_pcie_ep_ops = {
35 .start_link = ls_pcie_establish_link,
36};
37
38static const struct of_device_id ls_pcie_ep_of_match[] = {
39 { .compatible = "fsl,ls-pcie-ep",},
40 { },
41};
42
43static const struct pci_epc_features ls_pcie_epc_features = {
44 .linkup_notifier = false,
45 .msi_capable = true,
46 .msix_capable = false,
47};
48
49static const struct pci_epc_features*
50ls_pcie_ep_get_features(struct dw_pcie_ep *ep)
51{
52 return &ls_pcie_epc_features;
53}
54
55static void ls_pcie_ep_init(struct dw_pcie_ep *ep)
56{
57 struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
58 enum pci_barno bar;
59
60 for (bar = BAR_0; bar <= BAR_5; bar++)
61 dw_pcie_ep_reset_bar(pci, bar);
62}
63
64static int ls_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
65 enum pci_epc_irq_type type, u16 interrupt_num)
66{
67 struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
68
69 switch (type) {
70 case PCI_EPC_IRQ_LEGACY:
71 return dw_pcie_ep_raise_legacy_irq(ep, func_no);
72 case PCI_EPC_IRQ_MSI:
73 return dw_pcie_ep_raise_msi_irq(ep, func_no, interrupt_num);
74 case PCI_EPC_IRQ_MSIX:
75 return dw_pcie_ep_raise_msix_irq(ep, func_no, interrupt_num);
76 default:
77 dev_err(pci->dev, "UNKNOWN IRQ type\n");
78 return -EINVAL;
79 }
80}
81
82static struct dw_pcie_ep_ops pcie_ep_ops = {
83 .ep_init = ls_pcie_ep_init,
84 .raise_irq = ls_pcie_ep_raise_irq,
85 .get_features = ls_pcie_ep_get_features,
86};
87
88static int __init ls_add_pcie_ep(struct ls_pcie_ep *pcie,
89 struct platform_device *pdev)
90{
91 struct dw_pcie *pci = pcie->pci;
92 struct device *dev = pci->dev;
93 struct dw_pcie_ep *ep;
94 struct resource *res;
95 int ret;
96
97 ep = &pci->ep;
98 ep->ops = &pcie_ep_ops;
99
100 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "addr_space");
101 if (!res)
102 return -EINVAL;
103
104 ep->phys_base = res->start;
105 ep->addr_size = resource_size(res);
106
107 ret = dw_pcie_ep_init(ep);
108 if (ret) {
109 dev_err(dev, "failed to initialize endpoint\n");
110 return ret;
111 }
112
113 return 0;
114}
115
116static int __init ls_pcie_ep_probe(struct platform_device *pdev)
117{
118 struct device *dev = &pdev->dev;
119 struct dw_pcie *pci;
120 struct ls_pcie_ep *pcie;
121 struct resource *dbi_base;
122 int ret;
123
124 pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
125 if (!pcie)
126 return -ENOMEM;
127
128 pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
129 if (!pci)
130 return -ENOMEM;
131
132 dbi_base = platform_get_resource_byname(pdev, IORESOURCE_MEM, "regs");
133 pci->dbi_base = devm_pci_remap_cfg_resource(dev, dbi_base);
134 if (IS_ERR(pci->dbi_base))
135 return PTR_ERR(pci->dbi_base);
136
137 pci->dbi_base2 = pci->dbi_base + PCIE_DBI2_OFFSET;
138 pci->dev = dev;
139 pci->ops = &ls_pcie_ep_ops;
140 pcie->pci = pci;
141
142 platform_set_drvdata(pdev, pcie);
143
144 ret = ls_add_pcie_ep(pcie, pdev);
145
146 return ret;
147}
148
149static struct platform_driver ls_pcie_ep_driver = {
150 .driver = {
151 .name = "layerscape-pcie-ep",
152 .of_match_table = ls_pcie_ep_of_match,
153 .suppress_bind_attrs = true,
154 },
155};
156builtin_platform_driver_probe(ls_pcie_ep_driver, ls_pcie_ep_probe);
drivers/pci/controller/dwc/pcie-designware-ep.c+12−0
@@ -355,6 +355,17 @@ static int dw_pcie_ep_start(struct pci_epc *epc) · 354 unmodified lines
355 return pci->ops->start_link(pci);355 return pci->ops->start_link(pci);
356}356}
357 357
358static const struct pci_epc_features*
359dw_pcie_ep_get_features(struct pci_epc *epc, u8 func_no)
360{
361 struct dw_pcie_ep *ep = epc_get_drvdata(epc);
362
363 if (!ep->ops->get_features)
364 return NULL;
365
366 return ep->ops->get_features(ep);
367}
368
358static const struct pci_epc_ops epc_ops = {369static const struct pci_epc_ops epc_ops = {
359 .write_header = dw_pcie_ep_write_header,370 .write_header = dw_pcie_ep_write_header,
360 .set_bar = dw_pcie_ep_set_bar,371 .set_bar = dw_pcie_ep_set_bar,
@@ -368,6 +379,7 @@ static const struct pci_epc_ops epc_ops = { · 7 unmodified lines
368 .raise_irq = dw_pcie_ep_raise_irq,379 .raise_irq = dw_pcie_ep_raise_irq,
369 .start = dw_pcie_ep_start,380 .start = dw_pcie_ep_start,
370 .stop = dw_pcie_ep_stop,381 .stop = dw_pcie_ep_stop,
382 .get_features = dw_pcie_ep_get_features,
371};383};
372 384
373int dw_pcie_ep_raise_legacy_irq(struct dw_pcie_ep *ep, u8 func_no)385int dw_pcie_ep_raise_legacy_irq(struct dw_pcie_ep *ep, u8 func_no)
drivers/pci/controller/dwc/pcie-designware-plat.c+13−4
@@ -68,14 +68,10 @@ static const struct dw_pcie_ops dw_pcie_ops = { · 67 unmodified lines
68static void dw_plat_pcie_ep_init(struct dw_pcie_ep *ep)68static void dw_plat_pcie_ep_init(struct dw_pcie_ep *ep)
69{69{
70 struct dw_pcie *pci = to_dw_pcie_from_ep(ep);70 struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
71 struct pci_epc *epc = ep->epc;
72 enum pci_barno bar;71 enum pci_barno bar;
73 72
74 for (bar = BAR_0; bar <= BAR_5; bar++)73 for (bar = BAR_0; bar <= BAR_5; bar++)
75 dw_pcie_ep_reset_bar(pci, bar);74 dw_pcie_ep_reset_bar(pci, bar);
76
77 epc->features |= EPC_FEATURE_NO_LINKUP_NOTIFIER;
78 epc->features |= EPC_FEATURE_MSIX_AVAILABLE;
79}75}
80 76
81static int dw_plat_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,77static int dw_plat_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no,
@@ -98,9 +94,22 @@ static int dw_plat_pcie_ep_raise_irq(struct dw_pcie_ep *ep, u8 func_no, · 16 unmodified lines
98 return 0;94 return 0;
99}95}
100 96
97static const struct pci_epc_features dw_plat_pcie_epc_features = {
98 .linkup_notifier = false,
99 .msi_capable = true,
100 .msix_capable = true,
101};
102
103static const struct pci_epc_features*
104dw_plat_pcie_get_features(struct dw_pcie_ep *ep)
105{
106 return &dw_plat_pcie_epc_features;
107}
108
101static struct dw_pcie_ep_ops pcie_ep_ops = {109static struct dw_pcie_ep_ops pcie_ep_ops = {
102 .ep_init = dw_plat_pcie_ep_init,110 .ep_init = dw_plat_pcie_ep_init,
103 .raise_irq = dw_plat_pcie_ep_raise_irq,111 .raise_irq = dw_plat_pcie_ep_raise_irq,
112 .get_features = dw_plat_pcie_get_features,
104};113};
105 114
106static int dw_plat_add_pcie_port(struct dw_plat_pcie *dw_plat_pcie,115static int dw_plat_add_pcie_port(struct dw_plat_pcie *dw_plat_pcie,
drivers/pci/controller/dwc/pcie-designware.h+1−0
@@ -195,6 +195,7 @@ struct dw_pcie_ep_ops { · 194 unmodified lines
195 void (*ep_init)(struct dw_pcie_ep *ep);195 void (*ep_init)(struct dw_pcie_ep *ep);
196 int (*raise_irq)(struct dw_pcie_ep *ep, u8 func_no,196 int (*raise_irq)(struct dw_pcie_ep *ep, u8 func_no,
197 enum pci_epc_irq_type type, u16 interrupt_num);197 enum pci_epc_irq_type type, u16 interrupt_num);
198 const struct pci_epc_features* (*get_features)(struct dw_pcie_ep *ep);
198};199};
199 200
200struct dw_pcie_ep {201struct dw_pcie_ep {
drivers/pci/controller/pcie-cadence-ep.c+13−12
@@ -396,21 +396,21 @@ static int cdns_pcie_ep_start(struct pci_epc *epc) · 395 unmodified lines
396 cfg |= BIT(epf->func_no);396 cfg |= BIT(epf->func_no);
397 cdns_pcie_writel(pcie, CDNS_PCIE_LM_EP_FUNC_CFG, cfg);397 cdns_pcie_writel(pcie, CDNS_PCIE_LM_EP_FUNC_CFG, cfg);
398 398
399 /*
400 * The PCIe links are automatically established by the controller
401 * once for all at powerup: the software can neither start nor stop
402 * those links later at runtime.
403 *
404 * Then we only have to notify the EP core that our links are already
405 * established. However we don't call directly pci_epc_linkup() because
406 * we've already locked the epc->lock.
407 */
408 list_for_each_entry(epf, &epc->pci_epf, list)
409 pci_epf_linkup(epf);
410
411 return 0;399 return 0;
412}400}
413 401
402static const struct pci_epc_features cdns_pcie_epc_features = {
403 .linkup_notifier = false,
404 .msi_capable = true,
405 .msix_capable = false,
406};
407
408static const struct pci_epc_features*
409cdns_pcie_ep_get_features(struct pci_epc *epc, u8 func_no)
410{
411 return &cdns_pcie_epc_features;
412}
413
414static const struct pci_epc_ops cdns_pcie_epc_ops = {414static const struct pci_epc_ops cdns_pcie_epc_ops = {
415 .write_header = cdns_pcie_ep_write_header,415 .write_header = cdns_pcie_ep_write_header,
416 .set_bar = cdns_pcie_ep_set_bar,416 .set_bar = cdns_pcie_ep_set_bar,
@@ -421,6 +421,7 @@ static const struct pci_epc_ops cdns_pcie_epc_ops = { · 4 unmodified lines
421 .get_msi = cdns_pcie_ep_get_msi,421 .get_msi = cdns_pcie_ep_get_msi,
422 .raise_irq = cdns_pcie_ep_raise_irq,422 .raise_irq = cdns_pcie_ep_raise_irq,
423 .start = cdns_pcie_ep_start,423 .start = cdns_pcie_ep_start,
424 .get_features = cdns_pcie_ep_get_features,
424};425};
425 426
426static const struct of_device_id cdns_pcie_ep_of_match[] = {427static const struct of_device_id cdns_pcie_ep_of_match[] = {
drivers/pci/controller/pcie-rockchip-ep.c+13−3
@@ -499,12 +499,21 @@ static int rockchip_pcie_ep_start(struct pci_epc *epc) · 498 unmodified lines
499 499
500 rockchip_pcie_write(rockchip, cfg, PCIE_CORE_PHY_FUNC_CFG);500 rockchip_pcie_write(rockchip, cfg, PCIE_CORE_PHY_FUNC_CFG);
501 501
502 list_for_each_entry(epf, &epc->pci_epf, list)
503 pci_epf_linkup(epf);
504
505 return 0;502 return 0;
506}503}
507 504
505static const struct pci_epc_features rockchip_pcie_epc_features = {
506 .linkup_notifier = false,
507 .msi_capable = true,
508 .msix_capable = false,
509};
510
511static const struct pci_epc_features*
512rockchip_pcie_ep_get_features(struct pci_epc *epc, u8 func_no)
513{
514 return &rockchip_pcie_epc_features;
515}
516
508static const struct pci_epc_ops rockchip_pcie_epc_ops = {517static const struct pci_epc_ops rockchip_pcie_epc_ops = {
509 .write_header = rockchip_pcie_ep_write_header,518 .write_header = rockchip_pcie_ep_write_header,
510 .set_bar = rockchip_pcie_ep_set_bar,519 .set_bar = rockchip_pcie_ep_set_bar,
@@ -515,6 +524,7 @@ static const struct pci_epc_ops rockchip_pcie_epc_ops = { · 4 unmodified lines
515 .get_msi = rockchip_pcie_ep_get_msi,524 .get_msi = rockchip_pcie_ep_get_msi,
516 .raise_irq = rockchip_pcie_ep_raise_irq,525 .raise_irq = rockchip_pcie_ep_raise_irq,
517 .start = rockchip_pcie_ep_start,526 .start = rockchip_pcie_ep_start,
527 .get_features = rockchip_pcie_ep_get_features,
518};528};
519 529
520static int rockchip_pcie_parse_ep_dt(struct rockchip_pcie *rockchip,530static int rockchip_pcie_parse_ep_dt(struct rockchip_pcie *rockchip,
drivers/pci/endpoint/functions/pci-epf-test.c+59−38
@@ -47,9 +47,8 @@ struct pci_epf_test { · 46 unmodified lines
47 void *reg[6];47 void *reg[6];
48 struct pci_epf *epf;48 struct pci_epf *epf;
49 enum pci_barno test_reg_bar;49 enum pci_barno test_reg_bar;
50 bool linkup_notifier;
51 bool msix_available;
52 struct delayed_work cmd_handler;50 struct delayed_work cmd_handler;
51 const struct pci_epc_features *epc_features;
53};52};
54 53
55struct pci_epf_test_reg {54struct pci_epf_test_reg {
@@ -71,11 +70,6 @@ static struct pci_epf_header test_header = { · 15 unmodified lines
71 .interrupt_pin = PCI_INTERRUPT_INTA,70 .interrupt_pin = PCI_INTERRUPT_INTA,
72};71};
73 72
74struct pci_epf_test_data {
75 enum pci_barno test_reg_bar;
76 bool linkup_notifier;
77};
78
79static size_t bar_size[] = { 512, 512, 1024, 16384, 131072, 1048576 };73static size_t bar_size[] = { 512, 512, 1024, 16384, 131072, 1048576 };
80 74
81static int pci_epf_test_copy(struct pci_epf_test *epf_test)75static int pci_epf_test_copy(struct pci_epf_test *epf_test)
@@ -175,7 +169,7 @@ static int pci_epf_test_read(struct pci_epf_test *epf_test) · 93 unmodified lines
175 goto err_map_addr;169 goto err_map_addr;
176 }170 }
177 171
178 memcpy(buf, src_addr, reg->size);172 memcpy_fromio(buf, src_addr, reg->size);
179 173
180 crc32 = crc32_le(~0, buf, reg->size);174 crc32 = crc32_le(~0, buf, reg->size);
181 if (crc32 != reg->checksum)175 if (crc32 != reg->checksum)
@@ -230,7 +224,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) · 48 unmodified lines
230 get_random_bytes(buf, reg->size);224 get_random_bytes(buf, reg->size);
231 reg->checksum = crc32_le(~0, buf, reg->size);225 reg->checksum = crc32_le(~0, buf, reg->size);
232 226
233 memcpy(dst_addr, buf, reg->size);227 memcpy_toio(dst_addr, buf, reg->size);
234 228
235 /*229 /*
236 * wait 1ms inorder for the write to complete. Without this delay L3230 * wait 1ms inorder for the write to complete. Without this delay L3
@@ -402,13 +396,15 @@ static int pci_epf_test_set_bar(struct pci_epf *epf) · 165 unmodified lines
402 struct device *dev = &epf->dev;396 struct device *dev = &epf->dev;
403 struct pci_epf_test *epf_test = epf_get_drvdata(epf);397 struct pci_epf_test *epf_test = epf_get_drvdata(epf);
404 enum pci_barno test_reg_bar = epf_test->test_reg_bar;398 enum pci_barno test_reg_bar = epf_test->test_reg_bar;
399 const struct pci_epc_features *epc_features;
400
401 epc_features = epf_test->epc_features;
405 402
406 for (bar = BAR_0; bar <= BAR_5; bar++) {403 for (bar = BAR_0; bar <= BAR_5; bar++) {
407 epf_bar = &epf->bar[bar];404 epf_bar = &epf->bar[bar];
408 405
409 epf_bar->flags |= upper_32_bits(epf_bar->size) ?406 if (!!(epc_features->reserved_bar & (1 << bar)))
410 PCI_BASE_ADDRESS_MEM_TYPE_64 :407 continue;
411 PCI_BASE_ADDRESS_MEM_TYPE_32;
412 408
413 ret = pci_epc_set_bar(epc, epf->func_no, epf_bar);409 ret = pci_epc_set_bar(epc, epf->func_no, epf_bar);
414 if (ret) {410 if (ret) {
@@ -433,9 +429,13 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) · 18 unmodified lines
433{429{
434 struct pci_epf_test *epf_test = epf_get_drvdata(epf);430 struct pci_epf_test *epf_test = epf_get_drvdata(epf);
435 struct device *dev = &epf->dev;431 struct device *dev = &epf->dev;
432 struct pci_epf_bar *epf_bar;
436 void *base;433 void *base;
437 int bar;434 int bar;
438 enum pci_barno test_reg_bar = epf_test->test_reg_bar;435 enum pci_barno test_reg_bar = epf_test->test_reg_bar;
436 const struct pci_epc_features *epc_features;
437
438 epc_features = epf_test->epc_features;
439 439
440 base = pci_epf_alloc_space(epf, sizeof(struct pci_epf_test_reg),440 base = pci_epf_alloc_space(epf, sizeof(struct pci_epf_test_reg),
441 test_reg_bar);441 test_reg_bar);
@@ -446,37 +446,69 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) · 4 unmodified lines
446 epf_test->reg[test_reg_bar] = base;446 epf_test->reg[test_reg_bar] = base;
447 447
448 for (bar = BAR_0; bar <= BAR_5; bar++) {448 for (bar = BAR_0; bar <= BAR_5; bar++) {
449 epf_bar = &epf->bar[bar];
449 if (bar == test_reg_bar)450 if (bar == test_reg_bar)
450 continue;451 continue;
452
453 if (!!(epc_features->reserved_bar & (1 << bar)))
454 continue;
455
451 base = pci_epf_alloc_space(epf, bar_size[bar], bar);456 base = pci_epf_alloc_space(epf, bar_size[bar], bar);
452 if (!base)457 if (!base)
453 dev_err(dev, "Failed to allocate space for BAR%d\n",458 dev_err(dev, "Failed to allocate space for BAR%d\n",
454 bar);459 bar);
455 epf_test->reg[bar] = base;460 epf_test->reg[bar] = base;
461 if (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64)
462 bar++;
456 }463 }
457 464
458 return 0;465 return 0;
459}466}
460 467
468static void pci_epf_configure_bar(struct pci_epf *epf,
469 const struct pci_epc_features *epc_features)
470{
471 struct pci_epf_bar *epf_bar;
472 bool bar_fixed_64bit;
473 int i;
474
475 for (i = BAR_0; i <= BAR_5; i++) {
476 epf_bar = &epf->bar[i];
477 bar_fixed_64bit = !!(epc_features->bar_fixed_64bit & (1 << i));
478 if (bar_fixed_64bit)
479 epf_bar->flags |= PCI_BASE_ADDRESS_MEM_TYPE_64;
480 if (epc_features->bar_fixed_size[i])
481 bar_size[i] = epc_features->bar_fixed_size[i];
482 }
483}
484
461static int pci_epf_test_bind(struct pci_epf *epf)485static int pci_epf_test_bind(struct pci_epf *epf)
462{486{
463 int ret;487 int ret;
464 struct pci_epf_test *epf_test = epf_get_drvdata(epf);488 struct pci_epf_test *epf_test = epf_get_drvdata(epf);
465 struct pci_epf_header *header = epf->header;489 struct pci_epf_header *header = epf->header;
490 const struct pci_epc_features *epc_features;
491 enum pci_barno test_reg_bar = BAR_0;
466 struct pci_epc *epc = epf->epc;492 struct pci_epc *epc = epf->epc;
467 struct device *dev = &epf->dev;493 struct device *dev = &epf->dev;
494 bool linkup_notifier = false;
495 bool msix_capable = false;
496 bool msi_capable = true;
468 497
469 if (WARN_ON_ONCE(!epc))498 if (WARN_ON_ONCE(!epc))
470 return -EINVAL;499 return -EINVAL;
471 500
472 if (epc->features & EPC_FEATURE_NO_LINKUP_NOTIFIER)501 epc_features = pci_epc_get_features(epc, epf->func_no);
473 epf_test->linkup_notifier = false;502 if (epc_features) {
474 else503 linkup_notifier = epc_features->linkup_notifier;
475 epf_test->linkup_notifier = true;504 msix_capable = epc_features->msix_capable;
476 505 msi_capable = epc_features->msi_capable;
477 epf_test->msix_available = epc->features & EPC_FEATURE_MSIX_AVAILABLE;506 test_reg_bar = pci_epc_get_first_free_bar(epc_features);
507 pci_epf_configure_bar(epf, epc_features);
508 }
478 509
479 epf_test->test_reg_bar = EPC_FEATURE_GET_BAR(epc->features);510 epf_test->test_reg_bar = test_reg_bar;
511 epf_test->epc_features = epc_features;
480 512
481 ret = pci_epc_write_header(epc, epf->func_no, header);513 ret = pci_epc_write_header(epc, epf->func_no, header);
482 if (ret) {514 if (ret) {
@@ -492,13 +524,15 @@ static int pci_epf_test_bind(struct pci_epf *epf) · 9 unmodified lines
492 if (ret)524 if (ret)
493 return ret;525 return ret;
494 526
495 ret = pci_epc_set_msi(epc, epf->func_no, epf->msi_interrupts);527 if (msi_capable) {
496 if (ret) {528 ret = pci_epc_set_msi(epc, epf->func_no, epf->msi_interrupts);
497 dev_err(dev, "MSI configuration failed\n");529 if (ret) {
498 return ret;530 dev_err(dev, "MSI configuration failed\n");
531 return ret;
532 }
499 }533 }
500 534
501 if (epf_test->msix_available) {535 if (msix_capable) {
502 ret = pci_epc_set_msix(epc, epf->func_no, epf->msix_interrupts);536 ret = pci_epc_set_msix(epc, epf->func_no, epf->msix_interrupts);
503 if (ret) {537 if (ret) {
504 dev_err(dev, "MSI-X configuration failed\n");538 dev_err(dev, "MSI-X configuration failed\n");
@@ -506,7 +540,7 @@ static int pci_epf_test_bind(struct pci_epf *epf) · 1 unmodified line
506 }540 }
507 }541 }
508 542
509 if (!epf_test->linkup_notifier)543 if (!linkup_notifier)
510 queue_work(kpcitest_workqueue, &epf_test->cmd_handler.work);544 queue_work(kpcitest_workqueue, &epf_test->cmd_handler.work);
511 545
512 return 0;546 return 0;
@@ -523,17 +557,6 @@ static int pci_epf_test_probe(struct pci_epf *epf) · 10 unmodified lines
523{557{
524 struct pci_epf_test *epf_test;558 struct pci_epf_test *epf_test;
525 struct device *dev = &epf->dev;559 struct device *dev = &epf->dev;
526 const struct pci_epf_device_id *match;
527 struct pci_epf_test_data *data;
528 enum pci_barno test_reg_bar = BAR_0;
529 bool linkup_notifier = true;
530
531 match = pci_epf_match_device(pci_epf_test_ids, epf);
532 data = (struct pci_epf_test_data *)match->driver_data;
533 if (data) {
534 test_reg_bar = data->test_reg_bar;
535 linkup_notifier = data->linkup_notifier;
536 }
537 560
538 epf_test = devm_kzalloc(dev, sizeof(*epf_test), GFP_KERNEL);561 epf_test = devm_kzalloc(dev, sizeof(*epf_test), GFP_KERNEL);
539 if (!epf_test)562 if (!epf_test)
@@ -541,8 +564,6 @@ static int pci_epf_test_probe(struct pci_epf *epf) · 1 unmodified line
541 564
542 epf->header = &test_header;565 epf->header = &test_header;
543 epf_test->epf = epf;566 epf_test->epf = epf;
544 epf_test->test_reg_bar = test_reg_bar;
545 epf_test->linkup_notifier = linkup_notifier;
546 567
547 INIT_DELAYED_WORK(&epf_test->cmd_handler, pci_epf_test_cmd_handler);568 INIT_DELAYED_WORK(&epf_test->cmd_handler, pci_epf_test_cmd_handler);
548 569
drivers/pci/endpoint/pci-epc-core.c+53−0
@@ -83,6 +83,59 @@ err: · 82 unmodified lines
83}83}
84EXPORT_SYMBOL_GPL(pci_epc_get);84EXPORT_SYMBOL_GPL(pci_epc_get);
85 85
86/**
87 * pci_epc_get_first_free_bar() - helper to get first unreserved BAR
88 * @epc_features: pci_epc_features structure that holds the reserved bar bitmap
89 *
90 * Invoke to get the first unreserved BAR that can be used for endpoint
91 * function. For any incorrect value in reserved_bar return '0'.
92 */
93unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features
94 *epc_features)
95{
96 int free_bar;
97
98 if (!epc_features)
99 return 0;
100
101 free_bar = ffz(epc_features->reserved_bar);
102 if (free_bar > 5)
103 return 0;
104
105 return free_bar;
106}
107EXPORT_SYMBOL_GPL(pci_epc_get_first_free_bar);
108
109/**
110 * pci_epc_get_features() - get the features supported by EPC
111 * @epc: the features supported by *this* EPC device will be returned
112 * @func_no: the features supported by the EPC device specific to the
113 * endpoint function with func_no will be returned
114 *
115 * Invoke to get the features provided by the EPC which may be
116 * specific to an endpoint function. Returns pci_epc_features on success
117 * and NULL for any failures.
118 */
119const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
120 u8 func_no)
121{
122 const struct pci_epc_features *epc_features;
123 unsigned long flags;
124
125 if (IS_ERR_OR_NULL(epc) || func_no >= epc->max_functions)
126 return NULL;
127
128 if (!epc->ops->get_features)
129 return NULL;
130
131 spin_lock_irqsave(&epc->lock, flags);
132 epc_features = epc->ops->get_features(epc, func_no);
133 spin_unlock_irqrestore(&epc->lock, flags);
134
135 return epc_features;
136}
137EXPORT_SYMBOL_GPL(pci_epc_get_features);
138
86/**139/**
87 * pci_epc_stop() - stop the PCI link140 * pci_epc_stop() - stop the PCI link
88 * @epc: the link of the EPC device that has to be stopped141 * @epc: the link of the EPC device that has to be stopped
drivers/pci/endpoint/pci-epf-core.c+3−1
@@ -131,7 +131,9 @@ void *pci_epf_alloc_space(struct pci_epf *epf, size_t size, enum pci_barno bar) · 130 unmodified lines
131 epf->bar[bar].phys_addr = phys_addr;131 epf->bar[bar].phys_addr = phys_addr;
132 epf->bar[bar].size = size;132 epf->bar[bar].size = size;
133 epf->bar[bar].barno = bar;133 epf->bar[bar].barno = bar;
134 epf->bar[bar].flags = PCI_BASE_ADDRESS_SPACE_MEMORY;134 epf->bar[bar].flags |= upper_32_bits(size) ?
135 PCI_BASE_ADDRESS_MEM_TYPE_64 :
136 PCI_BASE_ADDRESS_MEM_TYPE_32;
135 137
136 return space;138 return space;
137}139}
include/linux/pci-epc.h+23−8
@@ -59,6 +59,8 @@ struct pci_epc_ops { · 58 unmodified lines
59 enum pci_epc_irq_type type, u16 interrupt_num);59 enum pci_epc_irq_type type, u16 interrupt_num);
60 int (*start)(struct pci_epc *epc);60 int (*start)(struct pci_epc *epc);
61 void (*stop)(struct pci_epc *epc);61 void (*stop)(struct pci_epc *epc);
62 const struct pci_epc_features* (*get_features)(struct pci_epc *epc,
63 u8 func_no);
62 struct module *owner;64 struct module *owner;
63};65};
64 66
@@ -97,16 +99,25 @@ struct pci_epc { · 32 unmodified lines
97 struct config_group *group;99 struct config_group *group;
98 /* spinlock to protect against concurrent access of EP controller */100 /* spinlock to protect against concurrent access of EP controller */
99 spinlock_t lock;101 spinlock_t lock;
100 unsigned int features;
101};102};
102 103
103#define EPC_FEATURE_NO_LINKUP_NOTIFIER BIT(0)104/**
104#define EPC_FEATURE_BAR_MASK (BIT(1) | BIT(2) | BIT(3))105 * struct pci_epc_features - features supported by a EPC device per function
105#define EPC_FEATURE_MSIX_AVAILABLE BIT(4)106 * @linkup_notifier: indicate if the EPC device can notify EPF driver on link up
106#define EPC_FEATURE_SET_BAR(features, bar) \107 * @msi_capable: indicate if the endpoint function has MSI capability
107 (features |= (EPC_FEATURE_BAR_MASK & (bar << 1)))108 * @msix_capable: indicate if the endpoint function has MSI-X capability
108#define EPC_FEATURE_GET_BAR(features) \109 * @reserved_bar: bitmap to indicate reserved BAR unavailable to function driver
109 ((features & EPC_FEATURE_BAR_MASK) >> 1)110 * @bar_fixed_64bit: bitmap to indicate fixed 64bit BARs
111 * @bar_fixed_size: Array specifying the size supported by each BAR
112 */
113struct pci_epc_features {
114 unsigned int linkup_notifier : 1;
115 unsigned int msi_capable : 1;
116 unsigned int msix_capable : 1;
117 u8 reserved_bar;
118 u8 bar_fixed_64bit;
119 u64 bar_fixed_size[BAR_5 + 1];
120};
110 121
111#define to_pci_epc(device) container_of((device), struct pci_epc, dev)122#define to_pci_epc(device) container_of((device), struct pci_epc, dev)
112 123
@@ -158,6 +169,10 @@ int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, · 45 unmodified lines
158 enum pci_epc_irq_type type, u16 interrupt_num);169 enum pci_epc_irq_type type, u16 interrupt_num);
159int pci_epc_start(struct pci_epc *epc);170int pci_epc_start(struct pci_epc *epc);
160void pci_epc_stop(struct pci_epc *epc);171void pci_epc_stop(struct pci_epc *epc);
172const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
173 u8 func_no);
174unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features
175 *epc_features);
161struct pci_epc *pci_epc_get(const char *epc_name);176struct pci_epc *pci_epc_get(const char *epc_name);
162void pci_epc_put(struct pci_epc *epc);177void pci_epc_put(struct pci_epc *epc);
163 178

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t