mcb: enable register PCI devices using any BAR
v2 cover mcb: enable register PCI devices using any BAR
V1 -> V2: Thanks to the review from Johannes Thumshirn, the patch 2/3 of the first version has been removed and the cleaner solution from patch 3/3 is then kept.
The PCI mcb driver is currently only able to register devices that use the first PCI BAR. That is hardcoded in mcb-parse.c in lines 156-161:
c = kzalloc_obj(struct chameleon_bar); if (!c) return -ENOMEM; bar_count = 1; c->addr = mapbase;
However, mcb devices can use other indexes of the 6 PCI BARs. This serie of patches allows to use these devices by adding the relevant PCI BAR info to the chameleon table. As this code must also work for lpc devices, it has been done a refactoring in order to keep the two buses dependent operations regarding bars (get_bar and is_io_mapped_bar) outside of the common parsing code. These callback operations are stored in a structure and passed over to the parser, thus rendering each module, the mcb-lpc and mcb-pci, only with their own bus relevant logic.
This patch depends on the previously accepted patch:
Filip Jensen (2):
mcb: Use more than the first bar in pci devices
mcb: refactor the bus operations out of the common code
drivers/mcb/mcb-internal.h | 10 ++++- drivers/mcb/mcb-lpc.c | 56 ++++++++++++++++++++++++++- drivers/mcb/mcb-parse.c | 77 +++++--------------------------------- drivers/mcb/mcb-pci.c | 40 +++++++++++++++++++- 4 files changed, 111 insertions(+), 72 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/2 mcb: Use more than the first bar in pci devices
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
---
V1 -> V2: No changes in this patch
V1: https://lore.kernel.org/lkml/[email protected]/
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(-)
drivers/mcb/mcb-internal.h +1 -2
@@ -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
drivers/mcb/mcb-lpc.c +1 -1
@@ -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; }
drivers/mcb/mcb-parse.c +13 -9
@@ -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,13 +124,14 @@ 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;__le32 reg;u32 dtype; +struct pci_dev *pdev;/* * For those devices which are not connected
@@ -153,12 +155,15 @@ 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); + 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;
drivers/mcb/mcb-pci.c +1 -1
@@ -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;
Signature · 1 line
2.34.1
Johannes Thumshirn
maintainerRe: [PATCH v2 1/2] mcb: Use more than the first bar in pci devices
Filip Jensen @ 2026-03-02 14:47 :
drivers/mcb/mcb-parse.c static void chameleon_parse_bar(void __iomem *base, · line 134
Quoted 8 lines
drivers/mcb/mcb-parse.c +3
-0+static int chameleon_get_bar (void __iomem **base,struct chameleon_bar **cb, +struct device *dev) {struct chameleon_bar *c;int bar_count;__le32 reg;u32 dtype; +struct pci_dev *pdev;
Sorry for not having noticed this in v1 but this...
drivers/mcb/mcb-parse.c static int chameleon_get_bar(void __iomem **base, phys_addr_t mapbase, · line 157
Quoted 6 lines
drivers/mcb/mcb-parse.c +0
-0/* * For those devices which are not connected @@ -153,12 +155,15 @@ 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 {
can be declared here, as it's not used outside of this block.
Quoted 14 lines
drivers/mcb/mcb-parse.c +7
-4- c = kzalloc_obj(struct chameleon_bar); + 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); + } }
PATCH v2 2/2 mcb: refactor the bus operations out of the common code
In reply to Filip JensenTwo operations can be identified that are bus dependent and are needed in both modules mcb-pci and mcb-lpc. In order to avoid having info of both buses in common code, two callbacks operations (is_bar_iomapped and get_bars) are defined and passed as parameters to the mcb-parser.
---
V1 -> V2: Patch V1 2/3 is removed as its changes were removed in V1 3/3. V2 has the refactor of the previous V1 3/3
V1: https://lore.kernel.org/lkml/[email protected]/
drivers/mcb/mcb-internal.h | 9 ++++- drivers/mcb/mcb-lpc.c | 56 +++++++++++++++++++++++++- drivers/mcb/mcb-parse.c | 81 +++++--------------------------------- drivers/mcb/mcb-pci.c | 40 ++++++++++++++++++- 4 files changed, 111 insertions(+), 75 deletions(-)
drivers/mcb/mcb-internal.h +8 -1
@@ -122,6 +122,13 @@ 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,void __iomem *base); +struct chameleon_parse_ops { +bool (*is_bar_iomapped)(struct device *dev,struct chameleon_bar *cb, +int bar); +int (*get_bars)(void __iomem **base,struct chameleon_bar **cb, +struct device *dev); +}; +int chameleon_parse_cells (struct mcb_bus *bus,void __iomem *base, +struct chameleon_parse_ops *cham_bus_ops);#endif
drivers/mcb/mcb-lpc.c +55 -1
68 lines not on this page · raw message
drivers/mcb/mcb-parse.c +9 -72
117 lines not on this page · raw message
drivers/mcb/mcb-pci.c +39 -1
@@ -18,6 +18,44 @@ struct priv {void __iomem *base; }; +static int pci_get_bars (void __iomem **base,struct chameleon_bar **cb, +struct device *dev) +{ +struct pci_dev *pdev; +struct chameleon_bar *c; +int bar_count; + + pdev =to_pci_dev (dev); + bar_count =PCI_STD_NUM_BARS ; + c = kzalloc_objs(struct chameleon_bar, bar_count); +if (!c) +return -ENOMEM ; +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; + +return bar_count; +} + +static bool is_pci_bar_iomapped (struct device *dev,struct chameleon_bar *cb, +int bar) +{ +struct pci_dev *pdev; + + pdev =to_pci_dev (dev); +if (pci_resource_flags (pdev, bar) &IORESOURCE_IO ) +return true; +return false; +} + +static struct chameleon_parse_ops cham_pci_ops = { + .is_bar_iomapped = is_pci_bar_iomapped, + .get_bars = pci_get_bars, +}; +static int mcb_pci_get_irq (struct mcb_device *mdev) {struct mcb_bus *mbus = mdev->bus;
@@ -86,7 +124,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->base); + ret =chameleon_parse_cells (priv->bus, priv->base, &cham_pci_ops);if (ret <0 ) goto out_mcb_bus;
Signature · 1 line
2.34.1