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
1313
1414 Required properties:
1515 - compatible: should contain the platform identifier such as:
16+ RC mode:
1617 "fsl,ls1021a-pcie"
1718 "fsl,ls2080a-pcie", "fsl,ls2085a-pcie"
1819 "fsl,ls2088a-pcie"
@@ -20,6 +21,8 @@ Required properties: · 1 unmodified line
2021 "fsl,ls1046a-pcie"
2122 "fsl,ls1043a-pcie"
2223 "fsl,ls1012a-pcie"
24+ EP mode:
25+ "fsl,ls1046a-pcie-ep", "fsl,ls-pcie-ep"
2326 - reg: base addresses and lengths of the PCIe controller register blocks.
2427 - interrupts: A list of interrupt outputs of the controller. Must contain an
2528 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
657657 status = "disabled";
658658 };
659659
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+
660671 pcie@3500000 {
661672 compatible = "fsl,ls1046a-pcie";
662673 reg = <0x00 0x03500000 0x0 0x00100000 /* controller registers */
@@ -683,6 +694,17 @@ · 20 unmodified lines
683694 status = "disabled";
684695 };
685696
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+
686708 pcie@3600000 {
687709 compatible = "fsl,ls1046a-pcie";
688710 reg = <0x00 0x03600000 0x0 0x00100000 /* controller registers */
@@ -709,6 +731,17 @@ · 20 unmodified lines
709731 status = "disabled";
710732 };
711733
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+
712745 qdma: dma-controller@8380000 {
713746 compatible = "fsl,ls1046a-qdma", "fsl,ls1021a-qdma";
714747 reg = <0x0 0x8380000 0x0 0x1000>, /* Controller regs */
@@ -729,7 +762,6 @@ · 14 unmodified lines
729762 queue-sizes = <64 64>;
730763 big-endian;
731764 };
732−
733765 };
734766
735767 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
788788 static const struct pci_device_id pci_endpoint_test_tbl[] = {
789789 { PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA74x) },
790790 { PCI_DEVICE(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_DRA72x) },
791+ { PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, 0x81c0) },
791792 { PCI_DEVICE(PCI_VENDOR_ID_SYNOPSYS, 0xedda) },
792793 { }
793794 };
drivers/pci/controller/dwc/Makefile+1−1
@@ -8,7 +8,7 @@ obj-$(CONFIG_PCI_EXYNOS) += pci-exynos.o · 7 unmodified lines
88 obj-$(CONFIG_PCI_IMX6) += pci-imx6.o
99 obj-$(CONFIG_PCIE_SPEAR13XX) += pcie-spear13xx.o
1010 obj-$(CONFIG_PCI_KEYSTONE) += pci-keystone.o
11−obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o
11+obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o pci-layerscape-ep.o
1212 obj-$(CONFIG_PCIE_QCOM) += pcie-qcom.o
1313 obj-$(CONFIG_PCIE_ARMADA_8K) += pcie-armada8k.o
1414 obj-$(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
394394 return 0;
395395 }
396396
397+static const struct pci_epc_features dra7xx_pcie_epc_features = {
398+ .linkup_notifier = true,
399+ .msi_capable = true,
400+ .msix_capable = false,
401+};
402+
403+static const struct pci_epc_features*
404+dra7xx_pcie_get_features(struct dw_pcie_ep *ep)
405+{
406+ return &dra7xx_pcie_epc_features;
407+}
408+
397409 static struct dw_pcie_ep_ops pcie_ep_ops = {
398410 .ep_init = dra7xx_pcie_ep_init,
399411 .raise_irq = dra7xx_pcie_raise_irq,
412+ .get_features = dra7xx_pcie_get_features,
400413 };
401414
402415 static 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+
23+struct ls_pcie_ep {
24+ struct dw_pcie *pci;
25+};
26+
27+#define to_ls_pcie_ep(x) dev_get_drvdata((x)->dev)
28+
29+static int ls_pcie_establish_link(struct dw_pcie *pci)
30+{
31+ return 0;
32+}
33+
34+static const struct dw_pcie_ops ls_pcie_ep_ops = {
35+ .start_link = ls_pcie_establish_link,
36+};
37+
38+static const struct of_device_id ls_pcie_ep_of_match[] = {
39+ { .compatible = "fsl,ls-pcie-ep",},
40+ { },
41+};
42+
43+static const struct pci_epc_features ls_pcie_epc_features = {
44+ .linkup_notifier = false,
45+ .msi_capable = true,
46+ .msix_capable = false,
47+};
48+
49+static const struct pci_epc_features*
50+ls_pcie_ep_get_features(struct dw_pcie_ep *ep)
51+{
52+ return &ls_pcie_epc_features;
53+}
54+
55+static 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+
64+static 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+
82+static 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+
88+static 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+
116+static 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+
149+static 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+};
156+builtin_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
355355 return pci->ops->start_link(pci);
356356 }
357357
358+static const struct pci_epc_features*
359+dw_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+
358369 static const struct pci_epc_ops epc_ops = {
359370 .write_header = dw_pcie_ep_write_header,
360371 .set_bar = dw_pcie_ep_set_bar,
@@ -368,6 +379,7 @@ static const struct pci_epc_ops epc_ops = { · 7 unmodified lines
368379 .raise_irq = dw_pcie_ep_raise_irq,
369380 .start = dw_pcie_ep_start,
370381 .stop = dw_pcie_ep_stop,
382+ .get_features = dw_pcie_ep_get_features,
371383 };
372384
373385 int 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
6868 static void dw_plat_pcie_ep_init(struct dw_pcie_ep *ep)
6969 {
7070 struct dw_pcie *pci = to_dw_pcie_from_ep(ep);
71− struct pci_epc *epc = ep->epc;
7271 enum pci_barno bar;
7372
7473 for (bar = BAR_0; bar <= BAR_5; bar++)
7574 dw_pcie_ep_reset_bar(pci, bar);
76−
77− epc->features |= EPC_FEATURE_NO_LINKUP_NOTIFIER;
78− epc->features |= EPC_FEATURE_MSIX_AVAILABLE;
7975 }
8076
8177 static 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
9894 return 0;
9995 }
10096
97+static const struct pci_epc_features dw_plat_pcie_epc_features = {
98+ .linkup_notifier = false,
99+ .msi_capable = true,
100+ .msix_capable = true,
101+};
102+
103+static const struct pci_epc_features*
104+dw_plat_pcie_get_features(struct dw_pcie_ep *ep)
105+{
106+ return &dw_plat_pcie_epc_features;
107+}
108+
101109 static struct dw_pcie_ep_ops pcie_ep_ops = {
102110 .ep_init = dw_plat_pcie_ep_init,
103111 .raise_irq = dw_plat_pcie_ep_raise_irq,
112+ .get_features = dw_plat_pcie_get_features,
104113 };
105114
106115 static 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
195195 void (*ep_init)(struct dw_pcie_ep *ep);
196196 int (*raise_irq)(struct dw_pcie_ep *ep, u8 func_no,
197197 enum pci_epc_irq_type type, u16 interrupt_num);
198+ const struct pci_epc_features* (*get_features)(struct dw_pcie_ep *ep);
198199 };
199200
200201 struct 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
396396 cfg |= BIT(epf->func_no);
397397 cdns_pcie_writel(pcie, CDNS_PCIE_LM_EP_FUNC_CFG, cfg);
398398
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−
411399 return 0;
412400 }
413401
402+static const struct pci_epc_features cdns_pcie_epc_features = {
403+ .linkup_notifier = false,
404+ .msi_capable = true,
405+ .msix_capable = false,
406+};
407+
408+static const struct pci_epc_features*
409+cdns_pcie_ep_get_features(struct pci_epc *epc, u8 func_no)
410+{
411+ return &cdns_pcie_epc_features;
412+}
413+
414414 static const struct pci_epc_ops cdns_pcie_epc_ops = {
415415 .write_header = cdns_pcie_ep_write_header,
416416 .set_bar = cdns_pcie_ep_set_bar,
@@ -421,6 +421,7 @@ static const struct pci_epc_ops cdns_pcie_epc_ops = { · 4 unmodified lines
421421 .get_msi = cdns_pcie_ep_get_msi,
422422 .raise_irq = cdns_pcie_ep_raise_irq,
423423 .start = cdns_pcie_ep_start,
424+ .get_features = cdns_pcie_ep_get_features,
424425 };
425426
426427 static 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
499499
500500 rockchip_pcie_write(rockchip, cfg, PCIE_CORE_PHY_FUNC_CFG);
501501
502− list_for_each_entry(epf, &epc->pci_epf, list)
503− pci_epf_linkup(epf);
504−
505502 return 0;
506503 }
507504
505+static const struct pci_epc_features rockchip_pcie_epc_features = {
506+ .linkup_notifier = false,
507+ .msi_capable = true,
508+ .msix_capable = false,
509+};
510+
511+static const struct pci_epc_features*
512+rockchip_pcie_ep_get_features(struct pci_epc *epc, u8 func_no)
513+{
514+ return &rockchip_pcie_epc_features;
515+}
516+
508517 static const struct pci_epc_ops rockchip_pcie_epc_ops = {
509518 .write_header = rockchip_pcie_ep_write_header,
510519 .set_bar = rockchip_pcie_ep_set_bar,
@@ -515,6 +524,7 @@ static const struct pci_epc_ops rockchip_pcie_epc_ops = { · 4 unmodified lines
515524 .get_msi = rockchip_pcie_ep_get_msi,
516525 .raise_irq = rockchip_pcie_ep_raise_irq,
517526 .start = rockchip_pcie_ep_start,
527+ .get_features = rockchip_pcie_ep_get_features,
518528 };
519529
520530 static 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
4747 void *reg[6];
4848 struct pci_epf *epf;
4949 enum pci_barno test_reg_bar;
50− bool linkup_notifier;
51− bool msix_available;
5250 struct delayed_work cmd_handler;
51+ const struct pci_epc_features *epc_features;
5352 };
5453
5554 struct pci_epf_test_reg {
@@ -71,11 +70,6 @@ static struct pci_epf_header test_header = { · 15 unmodified lines
7170 .interrupt_pin = PCI_INTERRUPT_INTA,
7271 };
7372
74−struct pci_epf_test_data {
75− enum pci_barno test_reg_bar;
76− bool linkup_notifier;
77−};
78−
7973 static size_t bar_size[] = { 512, 512, 1024, 16384, 131072, 1048576 };
8074
8175 static 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
175169 goto err_map_addr;
176170 }
177171
178− memcpy(buf, src_addr, reg->size);
172+ memcpy_fromio(buf, src_addr, reg->size);
179173
180174 crc32 = crc32_le(~0, buf, reg->size);
181175 if (crc32 != reg->checksum)
@@ -230,7 +224,7 @@ static int pci_epf_test_write(struct pci_epf_test *epf_test) · 48 unmodified lines
230224 get_random_bytes(buf, reg->size);
231225 reg->checksum = crc32_le(~0, buf, reg->size);
232226
233− memcpy(dst_addr, buf, reg->size);
227+ memcpy_toio(dst_addr, buf, reg->size);
234228
235229 /*
236230 * 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
402396 struct device *dev = &epf->dev;
403397 struct pci_epf_test *epf_test = epf_get_drvdata(epf);
404398 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;
405402
406403 for (bar = BAR_0; bar <= BAR_5; bar++) {
407404 epf_bar = &epf->bar[bar];
408405
409− epf_bar->flags |= upper_32_bits(epf_bar->size) ?
410− PCI_BASE_ADDRESS_MEM_TYPE_64 :
411− PCI_BASE_ADDRESS_MEM_TYPE_32;
406+ if (!!(epc_features->reserved_bar & (1 << bar)))
407+ continue;
412408
413409 ret = pci_epc_set_bar(epc, epf->func_no, epf_bar);
414410 if (ret) {
@@ -433,9 +429,13 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) · 18 unmodified lines
433429 {
434430 struct pci_epf_test *epf_test = epf_get_drvdata(epf);
435431 struct device *dev = &epf->dev;
432+ struct pci_epf_bar *epf_bar;
436433 void *base;
437434 int bar;
438435 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;
439439
440440 base = pci_epf_alloc_space(epf, sizeof(struct pci_epf_test_reg),
441441 test_reg_bar);
@@ -446,37 +446,69 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf) · 4 unmodified lines
446446 epf_test->reg[test_reg_bar] = base;
447447
448448 for (bar = BAR_0; bar <= BAR_5; bar++) {
449+ epf_bar = &epf->bar[bar];
449450 if (bar == test_reg_bar)
450451 continue;
452+
453+ if (!!(epc_features->reserved_bar & (1 << bar)))
454+ continue;
455+
451456 base = pci_epf_alloc_space(epf, bar_size[bar], bar);
452457 if (!base)
453458 dev_err(dev, "Failed to allocate space for BAR%d\n",
454459 bar);
455460 epf_test->reg[bar] = base;
461+ if (epf_bar->flags & PCI_BASE_ADDRESS_MEM_TYPE_64)
462+ bar++;
456463 }
457464
458465 return 0;
459466 }
460467
468+static 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+
461485 static int pci_epf_test_bind(struct pci_epf *epf)
462486 {
463487 int ret;
464488 struct pci_epf_test *epf_test = epf_get_drvdata(epf);
465489 struct pci_epf_header *header = epf->header;
490+ const struct pci_epc_features *epc_features;
491+ enum pci_barno test_reg_bar = BAR_0;
466492 struct pci_epc *epc = epf->epc;
467493 struct device *dev = &epf->dev;
494+ bool linkup_notifier = false;
495+ bool msix_capable = false;
496+ bool msi_capable = true;
468497
469498 if (WARN_ON_ONCE(!epc))
470499 return -EINVAL;
471500
472− if (epc->features & EPC_FEATURE_NO_LINKUP_NOTIFIER)
473− epf_test->linkup_notifier = false;
474− else
475− epf_test->linkup_notifier = true;
476−
477− epf_test->msix_available = epc->features & EPC_FEATURE_MSIX_AVAILABLE;
501+ epc_features = pci_epc_get_features(epc, epf->func_no);
502+ if (epc_features) {
503+ linkup_notifier = epc_features->linkup_notifier;
504+ msix_capable = epc_features->msix_capable;
505+ msi_capable = epc_features->msi_capable;
506+ test_reg_bar = pci_epc_get_first_free_bar(epc_features);
507+ pci_epf_configure_bar(epf, epc_features);
508+ }
478509
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;
480512
481513 ret = pci_epc_write_header(epc, epf->func_no, header);
482514 if (ret) {
@@ -492,13 +524,15 @@ static int pci_epf_test_bind(struct pci_epf *epf) · 9 unmodified lines
492524 if (ret)
493525 return ret;
494526
495− ret = pci_epc_set_msi(epc, epf->func_no, epf->msi_interrupts);
496− if (ret) {
497− dev_err(dev, "MSI configuration failed\n");
498− return ret;
527+ if (msi_capable) {
528+ ret = pci_epc_set_msi(epc, epf->func_no, epf->msi_interrupts);
529+ if (ret) {
530+ dev_err(dev, "MSI configuration failed\n");
531+ return ret;
532+ }
499533 }
500534
501− if (epf_test->msix_available) {
535+ if (msix_capable) {
502536 ret = pci_epc_set_msix(epc, epf->func_no, epf->msix_interrupts);
503537 if (ret) {
504538 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
506540 }
507541 }
508542
509− if (!epf_test->linkup_notifier)
543+ if (!linkup_notifier)
510544 queue_work(kpcitest_workqueue, &epf_test->cmd_handler.work);
511545
512546 return 0;
@@ -523,17 +557,6 @@ static int pci_epf_test_probe(struct pci_epf *epf) · 10 unmodified lines
523557 {
524558 struct pci_epf_test *epf_test;
525559 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− }
537560
538561 epf_test = devm_kzalloc(dev, sizeof(*epf_test), GFP_KERNEL);
539562 if (!epf_test)
@@ -541,8 +564,6 @@ static int pci_epf_test_probe(struct pci_epf *epf) · 1 unmodified line
541564
542565 epf->header = &test_header;
543566 epf_test->epf = epf;
544− epf_test->test_reg_bar = test_reg_bar;
545− epf_test->linkup_notifier = linkup_notifier;
546567
547568 INIT_DELAYED_WORK(&epf_test->cmd_handler, pci_epf_test_cmd_handler);
548569
drivers/pci/endpoint/pci-epc-core.c+53−0
@@ -83,6 +83,59 @@ err: · 82 unmodified lines
8383 }
8484 EXPORT_SYMBOL_GPL(pci_epc_get);
8585
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+ */
93+unsigned 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+}
107+EXPORT_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+ */
119+const 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+}
137+EXPORT_SYMBOL_GPL(pci_epc_get_features);
138+
86139 /**
87140 * pci_epc_stop() - stop the PCI link
88141 * @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
131131 epf->bar[bar].phys_addr = phys_addr;
132132 epf->bar[bar].size = size;
133133 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;
135137
136138 return space;
137139 }
include/linux/pci-epc.h+23−8
@@ -59,6 +59,8 @@ struct pci_epc_ops { · 58 unmodified lines
5959 enum pci_epc_irq_type type, u16 interrupt_num);
6060 int (*start)(struct pci_epc *epc);
6161 void (*stop)(struct pci_epc *epc);
62+ const struct pci_epc_features* (*get_features)(struct pci_epc *epc,
63+ u8 func_no);
6264 struct module *owner;
6365 };
6466
@@ -97,16 +99,25 @@ struct pci_epc { · 32 unmodified lines
9799 struct config_group *group;
98100 /* spinlock to protect against concurrent access of EP controller */
99101 spinlock_t lock;
100− unsigned int features;
101102 };
102103
103−#define EPC_FEATURE_NO_LINKUP_NOTIFIER BIT(0)
104−#define EPC_FEATURE_BAR_MASK (BIT(1) | BIT(2) | BIT(3))
105−#define EPC_FEATURE_MSIX_AVAILABLE BIT(4)
106−#define EPC_FEATURE_SET_BAR(features, bar) \
107− (features |= (EPC_FEATURE_BAR_MASK & (bar << 1)))
108−#define EPC_FEATURE_GET_BAR(features) \
109− ((features & EPC_FEATURE_BAR_MASK) >> 1)
104+/**
105+ * struct pci_epc_features - features supported by a EPC device per function
106+ * @linkup_notifier: indicate if the EPC device can notify EPF driver on link up
107+ * @msi_capable: indicate if the endpoint function has MSI capability
108+ * @msix_capable: indicate if the endpoint function has MSI-X capability
109+ * @reserved_bar: bitmap to indicate reserved BAR unavailable to function driver
110+ * @bar_fixed_64bit: bitmap to indicate fixed 64bit BARs
111+ * @bar_fixed_size: Array specifying the size supported by each BAR
112+ */
113+struct 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+};
110121
111122 #define to_pci_epc(device) container_of((device), struct pci_epc, dev)
112123
@@ -158,6 +169,10 @@ int pci_epc_raise_irq(struct pci_epc *epc, u8 func_no, · 45 unmodified lines
158169 enum pci_epc_irq_type type, u16 interrupt_num);
159170 int pci_epc_start(struct pci_epc *epc);
160171 void pci_epc_stop(struct pci_epc *epc);
172+const struct pci_epc_features *pci_epc_get_features(struct pci_epc *epc,
173+ u8 func_no);
174+unsigned int pci_epc_get_first_free_bar(const struct pci_epc_features
175+ *epc_features);
161176 struct pci_epc *pci_epc_get(const char *epc_name);
162177 void pci_epc_put(struct pci_epc *epc);
163178

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