[PATCH 2/2] PCI: endpoint: pci-epf-test: Add support for controller with fixed addr BARs

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch demonstates how the new 'get_bar' API for fixed address
PCI BARs is used alongside the previous 'pci_epf_alloa_space' and
'set_bar'.

Signed-off-by: Rick Wertenbroek <rick.wertenbroek@xxxxxxxxx>
---
 drivers/pci/endpoint/functions/pci-epf-test.c | 38 +++++++++++++++++--
 1 file changed, 34 insertions(+), 4 deletions(-)

diff --git a/drivers/pci/endpoint/functions/pci-epf-test.c b/drivers/pci/endpoint/functions/pci-epf-test.c
index 7c2ed6eae53a..c6622894091c 100644
--- a/drivers/pci/endpoint/functions/pci-epf-test.c
+++ b/drivers/pci/endpoint/functions/pci-epf-test.c
@@ -698,6 +698,9 @@ static int pci_epf_test_set_bar(struct pci_epf *epf)
 		if (!epf_test->reg[bar])
 			continue;
 
+		if (epf_test->epc_features->bar[bar].fixed_addr)
+			continue;
+
 		ret = pci_epc_set_bar(epc, epf->func_no, epf->vfunc_no,
 				      &epf->bar[bar]);
 		if (ret) {
@@ -722,6 +725,9 @@ static void pci_epf_test_clear_bar(struct pci_epf *epf)
 		if (!epf_test->reg[bar])
 			continue;
 
+		if (epf_test->epc_features->bar[bar].fixed_addr)
+			continue;
+
 		pci_epc_clear_bar(epc, epf->func_no, epf->vfunc_no,
 				  &epf->bar[bar]);
 	}
@@ -829,6 +835,7 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
 	enum pci_barno bar;
 	const struct pci_epc_features *epc_features = epf_test->epc_features;
 	size_t test_reg_size;
+	int ret;
 
 	test_reg_bar_size = ALIGN(sizeof(struct pci_epf_test_reg), 128);
 
@@ -840,8 +847,19 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
 	}
 	test_reg_size = test_reg_bar_size + msix_table_size + pba_size;
 
-	base = pci_epf_alloc_space(epf, test_reg_size, test_reg_bar,
-				   epc_features, PRIMARY_INTERFACE);
+	if (!epc_features->bar[test_reg_bar].fixed_addr)
+		base = pci_epf_alloc_space(epf, test_reg_size, test_reg_bar,
+					   epc_features, PRIMARY_INTERFACE);
+	else {
+		ret = pci_epc_get_bar(epf->epc, epf->func_no, epf->vfunc_no,
+				      test_reg_bar, &epf->bar[test_reg_bar]);
+		if (ret < 0) {
+			dev_err(dev, "Failed to get fixed address BAR\n");
+			return ret;
+		}
+		base = epf->bar[test_reg_bar].addr;
+	}
+
 	if (!base) {
 		dev_err(dev, "Failed to allocated register space\n");
 		return -ENOMEM;
@@ -856,8 +874,20 @@ static int pci_epf_test_alloc_space(struct pci_epf *epf)
 		if (bar == test_reg_bar)
 			continue;
 
-		base = pci_epf_alloc_space(epf, bar_size[bar], bar,
-					   epc_features, PRIMARY_INTERFACE);
+		if (!epc_features->bar[bar].fixed_addr)
+			base = pci_epf_alloc_space(epf, bar_size[bar], bar,
+						   epc_features,
+						   PRIMARY_INTERFACE);
+		else {
+			ret = pci_epc_get_bar(epf->epc, epf->func_no,
+					      epf->vfunc_no, bar,
+					      &epf->bar[bar]);
+			if (ret < 0)
+				base = NULL;
+			else
+				base = epf->bar[bar].addr;
+		}
+
 		if (!base)
 			dev_err(dev, "Failed to allocate space for BAR%d\n",
 				bar);
-- 
2.25.1





[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux