mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Rick Wertenbroek <rick.wertenbroek@gmail.com>
To: rick.wertenbroek@heig-vd.ch
Cc: damien.lemoal@kernel.org, alberto.dassatti@heig-vd.ch,
	"Rick Wertenbroek" <rick.wertenbroek@gmail.com>,
	"Manivannan Sadhasivam" <manivannan.sadhasivam@linaro.org>,
	"Krzysztof Wilczyński" <kw@linux.com>,
	"Kishon Vijay Abraham I" <kishon@kernel.org>,
	"Bjorn Helgaas" <bhelgaas@google.com>,
	"Niklas Cassel" <cassel@kernel.org>,
	"Frank Li" <Frank.Li@nxp.com>,
	"Damien Le Moal" <dlemoal@kernel.org>,
	"Lars-Peter Clausen" <lars@metafoo.de>,
	linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] PCI: endpoint: pci-epf-test: Add support for controller with fixed addr BARs
Date: Fri, 19 Jul 2024 13:57:39 +0200	[thread overview]
Message-ID: <20240719115741.3694893-3-rick.wertenbroek@gmail.com> (raw)
In-Reply-To: <20240719115741.3694893-1-rick.wertenbroek@gmail.com>

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@gmail.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


      parent reply	other threads:[~2024-07-19 11:58 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-19 11:57 [PATCH 0/2] PCI: endpoint: Introduce 'get_bar' to map fixed address BARs in EPC Rick Wertenbroek
2024-07-19 11:57 ` [PATCH 1/2] " Rick Wertenbroek
2024-07-23  0:03   ` Damien Le Moal
2024-07-23  7:06     ` Rick Wertenbroek
2024-07-23  7:16       ` Damien Le Moal
2024-07-23  7:41         ` Rick Wertenbroek
2024-07-23 14:05           ` Niklas Cassel
2024-07-23 14:17   ` Niklas Cassel
2024-07-23 16:06     ` Rick Wertenbroek
2024-07-23 16:48       ` Niklas Cassel
2024-07-25  5:33         ` Manivannan Sadhasivam
2024-07-25  6:30           ` Damien Le Moal
2024-07-25  7:40             ` Manivannan Sadhasivam
2024-07-25  8:13               ` Damien Le Moal
2024-07-25  8:06           ` Rick Wertenbroek
2024-07-25  8:20             ` Damien Le Moal
2024-07-25 14:07               ` Manivannan Sadhasivam
2024-07-25 13:53             ` Manivannan Sadhasivam
2024-07-25 14:17             ` Niklas Cassel
2024-07-25 16:36               ` Manivannan Sadhasivam
2024-07-25 21:52                 ` Niklas Cassel
2024-07-25 22:53                   ` Damien Le Moal
2024-07-26 11:21                     ` Rick Wertenbroek
2024-07-26 13:41                       ` Niklas Cassel
2024-07-29 16:42                         ` Manivannan Sadhasivam
2024-07-19 11:57 ` Rick Wertenbroek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240719115741.3694893-3-rick.wertenbroek@gmail.com \
    --to=rick.wertenbroek@gmail.com \
    --cc=Frank.Li@nxp.com \
    --cc=alberto.dassatti@heig-vd.ch \
    --cc=bhelgaas@google.com \
    --cc=cassel@kernel.org \
    --cc=damien.lemoal@kernel.org \
    --cc=dlemoal@kernel.org \
    --cc=kishon@kernel.org \
    --cc=kw@linux.com \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=rick.wertenbroek@heig-vd.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®