lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240719115741.3694893-3-rick.wertenbroek@gmail.com>
Date: Fri, 19 Jul 2024 13:57:39 +0200
From: Rick Wertenbroek <rick.wertenbroek@...il.com>
To: rick.wertenbroek@...g-vd.ch
Cc: damien.lemoal@...nel.org,
	alberto.dassatti@...g-vd.ch,
	Rick Wertenbroek <rick.wertenbroek@...il.com>,
	Manivannan Sadhasivam <manivannan.sadhasivam@...aro.org>,
	Krzysztof WilczyƄski <kw@...ux.com>,
	Kishon Vijay Abraham I <kishon@...nel.org>,
	Bjorn Helgaas <bhelgaas@...gle.com>,
	Niklas Cassel <cassel@...nel.org>,
	Frank Li <Frank.Li@....com>,
	Damien Le Moal <dlemoal@...nel.org>,
	Lars-Peter Clausen <lars@...afoo.de>,
	linux-pci@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH 2/2] PCI: endpoint: pci-epf-test: Add support for controller with fixed addr BARs

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@...il.com>
---
 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


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ