mirror of https://lore.kernel.org/lkml/
 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 2/3] mcb: Fix detection of iomapped pci devices
Date: Thu, 26 Feb 2026 16:13:38 +0100	[thread overview]
Message-ID: <20260226151339.48800-3-dev-Felipe.Jensen@duagon.com> (raw)
In-Reply-To: <20260226151339.48800-1-dev-Felipe.Jensen@duagon.com>

The mcb driver in a PCI bus is not detecting if an attached device has
an iomapped or a memory mapped BAR, as all the addresses returned by
pci_resource_start end in 0.

Instead of the low level approach, which is still valid for lpc buses,
here it will be used the standard PCI helper pci_resource_flags for
checking if the PCI BAR is IO mapped (as it is done in mcb_pci_probe)

Reviewed-by: Jose Javier Rodriguez Barbarin <dev-josejavier.rodriguez@duagon.com>
Signed-off-by: Filip Jensen <dev-Felipe.Jensen@duagon.com>
---
 drivers/mcb/mcb-parse.c | 25 +++++++++++++++++--------
 1 file changed, 17 insertions(+), 8 deletions(-)

diff --git a/drivers/mcb/mcb-parse.c b/drivers/mcb/mcb-parse.c
index 806be67b960d..251be2428873 100644
--- a/drivers/mcb/mcb-parse.c
+++ b/drivers/mcb/mcb-parse.c
@@ -29,9 +29,9 @@ static int chameleon_parse_bdd(struct mcb_bus *bus,
 	return 0;
 }
 
-static int chameleon_parse_gdd(struct mcb_bus *bus,
-			struct chameleon_bar *cb,
-			void __iomem *base, int bar_count)
+static int chameleon_parse_gdd(struct mcb_bus *bus, struct chameleon_bar *cb,
+			       void __iomem *base, int bar_count,
+			       bool mcb_is_pci_device)
 {
 	struct chameleon_gdd __iomem *gdd =
 		(struct chameleon_gdd __iomem *) base;
@@ -76,8 +76,12 @@ static int chameleon_parse_gdd(struct mcb_bus *bus,
 		ret = 0;
 		goto err;
 	}
-
-	if (dev_mapbase & 0x01) {
+	if (mcb_is_pci_device) {
+		if (pci_resource_flags(to_pci_dev(bus->carrier), mdev->bar) &
+		    IORESOURCE_IO)
+			goto io_unsupported;
+	} else if (dev_mapbase & 0x01) {
+io_unsupported:
 		pr_info("IO mapped Device (16z%03d) not yet supported\n",
 			mdev->id);
 		ret = 0;
@@ -125,7 +129,7 @@ static void chameleon_parse_bar(void __iomem *base,
 }
 
 static int chameleon_get_bar(void __iomem **base, struct chameleon_bar **cb,
-			     struct device *dev)
+			     struct device *dev, bool *mcb_is_pci_device)
 {
 	struct chameleon_bar *c;
 	int bar_count;
@@ -154,6 +158,7 @@ static int chameleon_get_bar(void __iomem **base, struct chameleon_bar **cb,
 
 		chameleon_parse_bar(*base, c, bar_count);
 		*base += BAR_DESC_SIZE(bar_count);
+		*mcb_is_pci_device = false;
 	} else {
 		pdev = to_pci_dev(dev);
 		bar_count = PCI_STD_NUM_BARS;
@@ -164,6 +169,7 @@ static int chameleon_get_bar(void __iomem **base, struct chameleon_bar **cb,
 			c[i].addr = pci_resource_start(pdev, i);
 			c[i].size = pci_resource_len(pdev, i);
 		}
+		*mcb_is_pci_device = true;
 	}
 
 	*cb = c;
@@ -182,6 +188,7 @@ int chameleon_parse_cells(struct mcb_bus *bus, void __iomem *base)
 	int ret;
 	u32 hsize;
 	u32 table_size;
+	bool mcb_is_pci_device;
 
 	hsize = sizeof(struct chameleon_fpga_header);
 
@@ -207,7 +214,8 @@ int chameleon_parse_cells(struct mcb_bus *bus, void __iomem *base)
 	memcpy(bus->name, header->filename, CHAMELEON_FILENAME_LEN);
 	bus->name[CHAMELEON_FILENAME_LEN] = '\0';
 
-	bar_count = chameleon_get_bar(&p, &cb, bus->carrier);
+	bar_count =
+		chameleon_get_bar(&p, &cb, bus->carrier, &mcb_is_pci_device);
 	if (bar_count < 0) {
 		ret = bar_count;
 		goto free_header;
@@ -216,7 +224,8 @@ int chameleon_parse_cells(struct mcb_bus *bus, void __iomem *base)
 	for_each_chameleon_cell(dtype, p) {
 		switch (dtype) {
 		case CHAMELEON_DTYPE_GENERAL:
-			ret = chameleon_parse_gdd(bus, cb, p, bar_count);
+			ret = chameleon_parse_gdd(bus, cb, p, bar_count,
+						  mcb_is_pci_device);
 			if (ret < 0)
 				goto free_bar;
 			p += sizeof(struct chameleon_gdd);
-- 
2.34.1

  parent reply	other threads:[~2026-02-26 15:14 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-26 15:13 [PATCH 0/3] mcb: enable register PCI devices using any BAR Filip Jensen
2026-02-26 15:13 ` [PATCH 1/3] mcb: Use more than the first bar in pci devices Filip Jensen
2026-02-26 15:13 ` Filip Jensen [this message]
2026-02-27 13:57   ` [PATCH 2/3] mcb: Fix detection of iomapped " Johannes Thumshirn
2026-02-26 15:13 ` [PATCH 3/3] mcb: refactor the bus operations out of the common code Filip Jensen

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=20260226151339.48800-3-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

all inboxes | Powered by JetHome®