public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Filip Jensen <dev-Felipe.Jensen@duagon.com>
To: morbidrsa@gmail.com
Cc: linux-kernel@vger.kernel.org,
	Filip Jensen <dev-Felipe.Jensen@duagon.com>,
	Jose Javier Rodriguez Barbarin
	<dev-josejavier.rodriguez@duagon.com>
Subject: [PATCH v3 1/2] mcb: Use more than the first bar in pci devices
Date: Wed,  4 Mar 2026 14:26:49 +0100	[thread overview]
Message-ID: <20260304132650.140680-2-dev-Felipe.Jensen@duagon.com> (raw)
In-Reply-To: <20260304132650.140680-1-dev-Felipe.Jensen@duagon.com>

Currently The mcb driver in a PCI bus only uses the first BAR when
parsing the table of attached devices and thus cannot map devices
using other BARS («No BAR for 16z» error will be thrown in method
chameleon_parse_gdd if assigned to a bar higher than the first).

This patch allows the parsing of devices in BARS other than the first
using the standard PCI helpers for accessing PCI BAR info as described
in pci.h

Reviewed-by: Jose Javier Rodriguez Barbarin <dev-josejavier.rodriguez@duagon.com>
Signed-off-by: Filip Jensen <dev-Felipe.Jensen@duagon.com>
---
V2 -> V3: Move declaration of pci_dev inside the only block where it is needed
in function chameleon_get_bar.
V1 -> V2: No changes in this patch

V2: https://lore.kernel.org/lkml/20260302134703.29913-2-dev-Felipe.Jensen@duagon.com/
V1: https://lore.kernel.org/lkml/20260226151339.48800-2-dev-Felipe.Jensen@duagon.com/

 drivers/mcb/mcb-internal.h |  3 +--
 drivers/mcb/mcb-lpc.c      |  2 +-
 drivers/mcb/mcb-parse.c    | 22 +++++++++++++---------
 drivers/mcb/mcb-pci.c      |  2 +-
 4 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/drivers/mcb/mcb-internal.h b/drivers/mcb/mcb-internal.h
index 3602cb3b2021..180ba97cfc08 100644
--- a/drivers/mcb/mcb-internal.h
+++ b/drivers/mcb/mcb-internal.h
@@ -122,7 +122,6 @@ struct chameleon_bar {
 #define CHAMELEON_BAR_MAX	6
 #define BAR_DESC_SIZE(x)	((x) * sizeof(struct chameleon_bar) + sizeof(__le32))
 
-int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase,
-			  void __iomem *base);
+int chameleon_parse_cells(struct mcb_bus *bus, void __iomem *base);
 
 #endif
diff --git a/drivers/mcb/mcb-lpc.c b/drivers/mcb/mcb-lpc.c
index 070aa787abc6..d3f48e1ea08b 100644
--- a/drivers/mcb/mcb-lpc.c
+++ b/drivers/mcb/mcb-lpc.c
@@ -56,7 +56,7 @@ static int mcb_lpc_probe(struct platform_device *pdev)
 	if (IS_ERR(priv->bus))
 		return PTR_ERR(priv->bus);
 
-	ret = chameleon_parse_cells(priv->bus, priv->mem->start, priv->base);
+	ret = chameleon_parse_cells(priv->bus, priv->base);
 	if (ret < 0) {
 		goto out_mcb_bus;
 	}
diff --git a/drivers/mcb/mcb-parse.c b/drivers/mcb/mcb-parse.c
index 2b115cb0e5d9..529ac7fe2ca8 100644
--- a/drivers/mcb/mcb-parse.c
+++ b/drivers/mcb/mcb-parse.c
@@ -6,6 +6,7 @@
 #include <linux/io.h>
 #include <linux/mcb.h>
 
+#include <linux/pci.h>
 #include "mcb-internal.h"
 
 #define for_each_chameleon_cell(dtype, p)	\
@@ -123,8 +124,8 @@ static void chameleon_parse_bar(void __iomem *base,
 	}
 }
 
-static int chameleon_get_bar(void __iomem **base, phys_addr_t mapbase,
-			     struct chameleon_bar **cb)
+static int chameleon_get_bar(void __iomem **base, struct chameleon_bar **cb,
+			     struct device *dev)
 {
 	struct chameleon_bar *c;
 	int bar_count;
@@ -153,12 +154,16 @@ static int chameleon_get_bar(void __iomem **base, phys_addr_t mapbase,
 		chameleon_parse_bar(*base, c, bar_count);
 		*base += BAR_DESC_SIZE(bar_count);
 	} else {
-		c = kzalloc_obj(struct chameleon_bar);
+		struct pci_dev *pdev = to_pci_dev(dev);
+
+		bar_count = PCI_STD_NUM_BARS;
+		c = kzalloc_objs(struct chameleon_bar, bar_count);
 		if (!c)
 			return -ENOMEM;
-
-		bar_count = 1;
-		c->addr = mapbase;
+		for (int i = 0; i < bar_count; ++i) {
+			c[i].addr = pci_resource_start(pdev, i);
+			c[i].size = pci_resource_len(pdev, i);
+		}
 	}
 
 	*cb = c;
@@ -166,8 +171,7 @@ static int chameleon_get_bar(void __iomem **base, phys_addr_t mapbase,
 	return bar_count;
 }
 
-int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase,
-			void __iomem *base)
+int chameleon_parse_cells(struct mcb_bus *bus, void __iomem *base)
 {
 	struct chameleon_fpga_header *header;
 	struct chameleon_bar *cb;
@@ -203,7 +207,7 @@ int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase,
 	memcpy(bus->name, header->filename, CHAMELEON_FILENAME_LEN);
 	bus->name[CHAMELEON_FILENAME_LEN] = '\0';
 
-	bar_count = chameleon_get_bar(&p, mapbase, &cb);
+	bar_count = chameleon_get_bar(&p, &cb, bus->carrier);
 	if (bar_count < 0) {
 		ret = bar_count;
 		goto free_header;
diff --git a/drivers/mcb/mcb-pci.c b/drivers/mcb/mcb-pci.c
index f1353da6ef4f..2401c19a8830 100644
--- a/drivers/mcb/mcb-pci.c
+++ b/drivers/mcb/mcb-pci.c
@@ -86,7 +86,7 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	priv->bus->get_irq = mcb_pci_get_irq;
 
-	ret = chameleon_parse_cells(priv->bus, priv->mapbase, priv->base);
+	ret = chameleon_parse_cells(priv->bus, priv->base);
 	if (ret < 0)
 		goto out_mcb_bus;
 
-- 
2.34.1

  reply	other threads:[~2026-03-04 13:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-04 13:26 [PATCH v3 0/2] mcb: enable register PCI devices using any BAR Filip Jensen
2026-03-04 13:26 ` Filip Jensen [this message]
2026-03-04 13:26 ` [PATCH v3 2/2] mcb: refactor bus operations out of common code Filip Jensen
2026-04-24 11:12 ` [PATCH v3 0/2] mcb: enable register PCI devices using any BAR Johannes Thumshirn

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=20260304132650.140680-2-dev-Felipe.Jensen@duagon.com \
    --to=dev-felipe.jensen@duagon.com \
    --cc=dev-josejavier.rodriguez@duagon.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=morbidrsa@gmail.com \
    /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