[PATCH v3 1/2] mcb: Use more than the first bar in pci devices

From: Filip Jensen

Date: Wed Mar 04 2026 - 08:28:27 EST


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@xxxxxxxxxx>
Signed-off-by: Filip Jensen <dev-Felipe.Jensen@xxxxxxxxxx>
---
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@xxxxxxxxxx/
V1: https://lore.kernel.org/lkml/20260226151339.48800-2-dev-Felipe.Jensen@xxxxxxxxxx/

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