[RFC PATCH 08/11] PCI: Move CardBus device setup to setup-cardbus.c

From: Ilpo Järvinen

Date: Mon Nov 09 2026 - 16:11:18 EST


CardBus support can be disabled with CONFIG_CARDBUS, but
pci_setup_device() still sets up CardBus bridges regardless of it. This
inconsistency leads to a few corner cases in the resource sizing and
assignment algorithm where CardBus bridges are treated like normal PCI
devices.

Move the CardBus-specific part of pci_setup_device() into
pci_setup_cardbus_device() in setup-cardbus.c and ignore CardBus bridges
when CARDBUS is not set.

If a CardBus bridge that is Function 0 of a Multi-Function Device is
ignored, pci_scan_slot() does not enumerate the other Functions either.
Without CARDBUS, this makes the other Functions of CardBus combo chips
unusable, e.g., the SD controller of the Ricoh RL5C476 (sdhci-pci), and
the FireWire (firewire-ohci), Flash Media (tifm_7xx1), and SD
(sdhci-pci) controllers of the TI PCIxx21. Making those drivers depend
on CARDBUS would force CardBus also on users of chips without CardBus,
e.g., the SD controller of the Ricoh R5C832 family, where Function 0 is
a FireWire controller.

CARDBUS defaults to y if CONFIG_PCCARD is enabled and the yenta_socket
driver (CONFIG_YENTA) selects it, so CARDBUS=n on hardware with a
CardBus slot is most likely an intentional choice. It seems reasonable
to require users with such an exceptional config to enable CARDBUS to
keep using the drivers above with this legacy hardware.

Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
---

Cc: "Maciej W. Rozycki" <macro@xxxxxxxxxxx>
Cc: Dominik Brodowski <linux@xxxxxxxxxxxxxxxxxxxx>
Cc: Ulf Hansson <ulfh@xxxxxxxxxx>
Cc: Adrian Hunter <adrian.hunter@xxxxxxxxx>
Cc: Takashi Sakamoto <o-takashi@xxxxxxxxxxxxx>
Cc: Alex Dubov <oakad@xxxxxxxxx>
Cc: Maxim Levitsky <maximlevitsky@xxxxxxxxx>
Cc: linux-mmc@xxxxxxxxxxxxxxx
Cc: linux1394-devel@xxxxxxxxxxxxxxxxxxxxx

drivers/pci/pci.h | 6 ++++++
drivers/pci/probe.c | 13 +++++++------
drivers/pci/setup-cardbus.c | 13 +++++++++++++
3 files changed, 26 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
index 798b31c31ae4..057c8a2c7ee7 100644
--- a/drivers/pci/pci.h
+++ b/drivers/pci/pci.h
@@ -425,6 +425,7 @@ static inline bool pci_is_cardbus_bridge(const struct pci_dev *dev)
}
#ifdef CONFIG_CARDBUS
unsigned long pci_cardbus_resource_alignment(const struct resource *res);
+int pci_setup_cardbus_device(struct pci_dev *dev);
int pci_bus_size_cardbus_bridge(struct pci_bus *bus,
struct list_head *realloc_head);
int pci_cardbus_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
@@ -437,6 +438,10 @@ static inline unsigned long pci_cardbus_resource_alignment(const struct resource
{
return 0;
}
+static inline int pci_setup_cardbus_device(struct pci_dev *dev)
+{
+ return -EOPNOTSUPP;
+}
static inline int pci_bus_size_cardbus_bridge(struct pci_bus *bus,
struct list_head *realloc_head)
{
@@ -528,6 +533,7 @@ bool pci_bus_generic_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *pl,
int rrs_timeout);

int pci_setup_device(struct pci_dev *dev);
+void pci_read_irq(struct pci_dev *dev);
void __pci_size_stdbars(struct pci_dev *dev, int count,
unsigned int pos, u32 *sizes);
int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index a20ceaf7307a..f7afbaac723d 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -1599,7 +1599,7 @@ EXPORT_SYMBOL(pci_scan_bridge);
* Read interrupt line and base address registers.
* The architecture-dependent code can tweak these, of course.
*/
-static void pci_read_irq(struct pci_dev *dev)
+void pci_read_irq(struct pci_dev *dev)
{
unsigned char irq;

@@ -2180,12 +2180,13 @@ int pci_setup_device(struct pci_dev *dev)
break;

case PCI_HEADER_TYPE_CARDBUS: /* CardBus bridge header */
- if (class != PCI_CLASS_BRIDGE_CARDBUS)
+ err = pci_setup_cardbus_device(dev);
+ if (err == -EOPNOTSUPP) {
+ pci_err(dev, "CONFIG_CARDBUS not set, ignoring CardBus bridge\n");
+ goto free_name;
+ }
+ if (err)
goto bad;
- pci_read_irq(dev);
- pci_read_bases(dev, 1, 0);
- pci_read_config_word(dev, PCI_CB_SUBSYSTEM_VENDOR_ID, &dev->subsystem_vendor);
- pci_read_config_word(dev, PCI_CB_SUBSYSTEM_ID, &dev->subsystem_device);
break;

default: /* unknown header */
diff --git a/drivers/pci/setup-cardbus.c b/drivers/pci/setup-cardbus.c
index dcb8e2b3f73b..0de82d7fde68 100644
--- a/drivers/pci/setup-cardbus.c
+++ b/drivers/pci/setup-cardbus.c
@@ -31,6 +31,19 @@ unsigned long pci_cardbus_resource_alignment(const struct resource *res)
return 0;
}

+int pci_setup_cardbus_device(struct pci_dev *dev)
+{
+ if (dev->class >> 8 != PCI_CLASS_BRIDGE_CARDBUS)
+ return -EIO;
+
+ pci_read_irq(dev);
+ pci_read_bases(dev, 1, 0);
+ pci_read_config_word(dev, PCI_CB_SUBSYSTEM_VENDOR_ID, &dev->subsystem_vendor);
+ pci_read_config_word(dev, PCI_CB_SUBSYSTEM_ID, &dev->subsystem_device);
+
+ return 0;
+}
+
int pci_bus_size_cardbus_bridge(struct pci_bus *bus,
struct list_head *realloc_head)
{
--
2.47.3