Skip to contentSkip to conversation

PCI/CardBus: Disable properly when CARDBUS=n & fix some issues along the way

PATCH New Ilpo Järvinen 2 participants 23 messages Nov 9

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

cover PCI/CardBus: Disable properly when CARDBUS=n & fix some issues along the way

Hi all,

When CARDBUS=n, there are still leftovers in the bridge setup code that add annoying corner cases by confusing CardBus bridges with normal PCI devices. This series attempts to truly disable CardBus bridges when config asks to do so as it seems the most reasonable way to prevent those corner cases. That is, this series removes ability to select only "partial CardBus support", full support for CardBus remains in kernel and can still be enabled with CONFIG_CARDBUS. The alternative to this would be to sprinkle pci_is_cardbus_bridge() everywhere to work around the corner case is not reasonable given CardBus is quite old and rarely used legacy technology.

Disabling CARDBUS also implies the entire Multi-Function Device is lost because CardBus bridge at Function 0 gates enumeration of the rest of the functions that are not CardBus related (multiple drivers affected). This is intentionally not addressed with Kconfig dependencies; see the changelogs for the rationale. Towards the end, part of the patches are marked as RFC because they might have an impact on existing configs for that reason.

The series first fixes a few issues in PCI core and CardBus integration (4 patches, the first one is totally unrelated to CardBus but CardBus integration will use the same label in a later change). The fixes can be applied on their own if needed. After that, there are some preparatory changes and the main move of CardBus setup into setup-cardbus.c. Finally, the series moves a few CardBus specific quirks and the resource name getter into setup-cardbus.c to keep them out of the other PCI core code.

Cc Adrian Hunter <[email protected]>
Cc Alex Dubov <[email protected]>
Cc Dominik Brodowski <[email protected]>
Cc "Maciej W. Rozycki" <[email protected]>
Cc Maxim Levitsky <[email protected]>
Cc Sascha Sommer <[email protected]>
Cc Takashi Sakamoto <[email protected]>
Cc Ulf Hansson <[email protected]>

Ilpo Järvinen (11):
PCI: Free device name when pci_setup_device() fails
PCI: Use Header Type in __pci_bridge_assign_resources()
PCI: Use Header Type to detect CardBus bridges in
pci_resource_alignment()
PCI: Fix off-by-one in CardBus resource names
PCI: Move pci_read_bases() wrapper with BUILD_BUG_ON() to pci.h
mmc: sdricoh_cs: Depend on CARDBUS
pcmcia: yenta_socket: Always select CARDBUS
PCI: Move CardBus device setup to setup-cardbus.c
PCI: Move CardBus legacy mode quirk to setup-cardbus.c
PCI: Move Ricoh RL5C476 MMC quirk to setup-cardbus.c
PCI: Move CardBus resource names to setup-cardbus.c

 drivers/mmc/host/Kconfig    |  2 +-
 drivers/pci/pci.c           | 25 +---------
 drivers/pci/pci.h           | 23 ++++++++-
 drivers/pci/probe.c         | 27 +++++-----
 drivers/pci/quirks.c        | 45 -----------------
 drivers/pci/setup-bus.c     |  6 +--
 drivers/pci/setup-cardbus.c | 99 +++++++++++++++++++++++++++++++++++++
 drivers/pci/setup-res.c     |  2 +-
 drivers/pcmcia/Kconfig      |  2 +-
 9 files changed, 144 insertions(+), 87 deletions(-)

base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4

Signature · 1 line
2.47.3
#1 lore raw

PATCH 1/11 PCI: Free device name when pci_setup_device() fails

pci_setup_device() calls dev_set_name(), which allocates the name, before it can fail on an unknown Header Type. Its callers then free the device with kfree() because device_initialize() has not yet been called, so the name is never freed.

Free the name in the error path of pci_setup_device().

Fixes 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")

---

CardBus disabled case will reuse the same label after the move, thus add the rollback path in this patch.

 drivers/pci/probe.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
drivers/pci/probe.c +7 -2
index 9a178e0e5f7f..1c2caf3ce664 100644
@@ -2194,8 +2194,8 @@ int pci_setup_device(struct pci_dev *dev)
 	default:				    /* unknown header */
 		pci_err(dev, "unknown header type %02x, ignoring device\n",
 			dev->hdr_type);
-		pci_release_of_node(dev);
-		return -EIO;
+		err = -EIO;
+		goto free_name;
 
 	bad:
 		pci_err(dev, "ignoring class %#08x (doesn't match header type %02x)\n",
@@ -2205,6 +2205,11 @@ int pci_setup_device(struct pci_dev *dev)
 
 	/* We found a fine healthy device, go go go... */
 	return 0;
+
+free_name:
+	kfree_const(dev->dev.kobj.name);
+	pci_release_of_node(dev);
+	return err;
 }
 
 static void pci_configure_mps(struct pci_dev *dev)
Signature · 1 line
2.47.3
#2 lore raw

Re: [PATCH 01/11] PCI: Free device name when pci_setup_device() fails

Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

pci_setup_device() calls dev_set_name(), which allocates the name, before it can fail on an unknown Header Type. Its callers then free the device with kfree() because device_initialize() has not yet been called, so the name is never freed.

Free the name in the error path of pci_setup_device().

Fixes 1fa5ae857bb1 ("driver core: get rid of struct device's bus_id string array")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#3 lore raw

PATCH 2/11 PCI: Use Header Type in __pci_bridge_assign_resources()

In reply to Ilpo Järvinen

Commit b2fb5cc57469 ("PCI: Rely on config space header type, not class code") converted bridge window sizing and assignment to use the Header Type but __pci_bridge_assign_resources() still uses the Class Code to decide how to program the bridge windows. A Type 1 bridge whose Class Code is not PCI_CLASS_BRIDGE_PCI gets its windows sized and assigned but they are never programmed into the bridge.

Use the Header Type also in __pci_bridge_assign_resources().

---

I don't have known failure to point to with this, thus I've not added the Fixes tag (the commit ref is available in the changelog if it's needed).

 drivers/pci/setup-bus.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pci/setup-bus.c +3 -3
index ed16ef7c26fa..6209773a35f1 100644
@@ -1636,12 +1636,12 @@ static void __pci_bridge_assign_resources(struct pci_dev *bridge,
 
 	__pci_bus_assign_resources(b, add_list, fail_head);
 
-	switch (bridge->class >> 8) {
-	case PCI_CLASS_BRIDGE_PCI:
+	switch (bridge->hdr_type) {
+	case PCI_HEADER_TYPE_BRIDGE:
 		pci_setup_bridge(b);
 		break;
 
-	case PCI_CLASS_BRIDGE_CARDBUS:
+	case PCI_HEADER_TYPE_CARDBUS:
 		pci_setup_cardbus_bridge(b);
 		break;
 
Signature · 1 line
2.47.3
#4 lore raw

Re: [PATCH 02/11] PCI: Use Header Type in __pci_bridge_assign_resources()

Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

Commit b2fb5cc57469 ("PCI: Rely on config space header type, not class code") converted bridge window sizing and assignment to use the Header Type but __pci_bridge_assign_resources() still uses the Class Code to decide how to program the bridge windows. A Type 1 bridge whose Class Code is not PCI_CLASS_BRIDGE_PCI gets its windows sized and assigned but they are never programmed into the bridge.

Use the Header Type also in __pci_bridge_assign_resources().

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#5 lore raw

PATCH 3/11 PCI: Use Header Type to detect CardBus bridges in pci_resource_alignment()

In reply to Ilpo Järvinen

pci_resource_alignment() detects CardBus bridges by the Class Code while the rest of the PCI core uses the Header Type.

When CONFIG_CARDBUS is not set, pci_cardbus_resource_alignment() returns zero. A non-CardBus device that reports the CardBus Class Code then gets zero alignment for all its resources, and pbus_size_mem() calls __ffs() on it, which is undefined behavior. When CARDBUS is set, the device gets CardBus window alignment instead of its own alignment.

Use pci_is_cardbus_bridge() in pci_resource_alignment() and make it take a const pointer as pci_resource_alignment() has one.

Fixes fd29d4ea09ba ("PCI: Separate CardBus setup & build it only with CONFIG_CARDBUS")
---
 drivers/pci/pci.h       | 2 +-
 drivers/pci/setup-res.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pci.h +1 -1
index 77efa4c5c960..519918e24cc5 100644
@@ -419,7 +419,7 @@ extern unsigned long pci_hotplug_mmio_size;
 extern unsigned long pci_hotplug_mmio_pref_size;
 extern unsigned long pci_hotplug_bus_size;
 
-static inline bool pci_is_cardbus_bridge(struct pci_dev *dev)
+static inline bool pci_is_cardbus_bridge(const struct pci_dev *dev)
 {
 	return dev->hdr_type == PCI_HEADER_TYPE_CARDBUS;
 }
drivers/pci/setup-res.c +1 -1
index 376f09630a4a..d8d53861b4a6 100644
@@ -255,7 +255,7 @@ resource_size_t pci_resource_alignment(const struct pci_dev *dev,
 
 	if (pci_resource_is_iov(resno))
 		return pci_sriov_resource_alignment(dev, resno);
-	if (dev->class >> 8 == PCI_CLASS_BRIDGE_CARDBUS)
+	if (pci_is_cardbus_bridge(dev))
 		return pci_cardbus_resource_alignment(res);
 	return resource_alignment(res);
 }
Signature · 1 line
2.47.3
#6 lore raw

Re: [PATCH 03/11] PCI: Use Header Type to detect CardBus bridges in pci_resource_alignment()

Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

pci_resource_alignment() detects CardBus bridges by the Class Code while the rest of the PCI core uses the Header Type.

When CONFIG_CARDBUS is not set, pci_cardbus_resource_alignment() returns zero. A non-CardBus device that reports the CardBus Class Code then gets zero alignment for all its resources, and pbus_size_mem() calls __ffs() on it, which is undefined behavior. When CARDBUS is set, the device gets CardBus window alignment instead of its own alignment.

Quoted 5 lines

Use pci_is_cardbus_bridge() in pci_resource_alignment() and make it take a const pointer as pci_resource_alignment() has one.

Fixes fd29d4ea09ba ("PCI: Separate CardBus setup & build it only with CONFIG_CARDBUS")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
#7 lore raw

PATCH 4/11 PCI: Fix off-by-one in CardBus resource names

In reply to Ilpo Järvinen

cardbus_name[] in pci_resource_name() has no entry for resource index 6 (PCI_ROM_RESOURCE). As a result, all names after it are off by one: the last non-window resource is named "CardBus bridge window 0", each CardBus bridge window is given the name of the preceding window, and PCI_CB_BRIDGE_MEM_1_WINDOW falls outside the array.

Add the missing entry.

Fixes 65f8e0beac5a ("PCI: Update BAR # and window messages")
---
 drivers/pci/pci.c | 1 +
 1 file changed, 1 insertion(+)
drivers/pci/pci.c +1 -0
index 7c6f2aba8144..46da873c9aac 100644
@@ -839,6 +839,7 @@ const char *pci_resource_name(struct pci_dev *dev, unsigned int i)
 		"unknown",
 		"unknown",
 		"unknown",
+		"unknown",
 #ifdef CONFIG_PCI_IOV
 		"unknown",
 		"unknown",
Signature · 1 line
2.47.3
#8 lore raw

Re: [PATCH 04/11] PCI: Fix off-by-one in CardBus resource names

Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

cardbus_name[] in pci_resource_name() has no entry for resource index 6 (PCI_ROM_RESOURCE). As a result, all names after it are off by one: the last non-window resource is named "CardBus bridge window 0", each CardBus bridge window is given the name of the preceding window, and PCI_CB_BRIDGE_MEM_1_WINDOW falls outside the array.

Add the missing entry.

Fixes 65f8e0beac5a ("PCI: Update BAR # and window messages")

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
#9 lore raw

PATCH 5/11 PCI: Move pci_read_bases() wrapper with BUILD_BUG_ON() to pci.h

In reply to Ilpo Järvinen

pci_read_bases() is static in probe.c. An upcoming change moves CardBus device setup into setup-cardbus.c, which needs to read the CardBus BAR from outside probe.c.

Move the body of pci_read_bases() into __pci_read_bases() and keep the BUILD_BUG_ON() check in an __always_inline pci_read_bases() wrapper in pci.h so all callers retain the check.

---
 drivers/pci/pci.h   | 10 ++++++++++
 drivers/pci/probe.c |  5 +----
 2 files changed, 11 insertions(+), 4 deletions(-)
drivers/pci/pci.h +10 -0
index 519918e24cc5..798b31c31ae4 100644
@@ -532,6 +532,16 @@ 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,
 		    struct resource *res, unsigned int reg, u32 *sizes);
+void __pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom);
+
+static __always_inline void pci_read_bases(struct pci_dev *dev,
+					   unsigned int howmany, int rom)
+{
+	BUILD_BUG_ON(statically_true(howmany > PCI_STD_NUM_BARS));
+
+	__pci_read_bases(dev, howmany, rom);
+}
+
 void pci_configure_ari(struct pci_dev *dev);
 
 int pci_dev_res_add_to_list(struct list_head *head, struct pci_dev *dev,
drivers/pci/probe.c +1 -4
index 1c2caf3ce664..a20ceaf7307a 100644
@@ -322,15 +322,12 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 	return (res->flags & IORESOURCE_MEM_64) ? 1 : 0;
 }
 
-static __always_inline void pci_read_bases(struct pci_dev *dev,
-					   unsigned int howmany, int rom)
+void __pci_read_bases(struct pci_dev *dev, unsigned int howmany, int rom)
 {
 	u32 rombar, stdbars[PCI_STD_NUM_BARS];
 	unsigned int pos, reg;
 	u16 orig_cmd;
 
-	BUILD_BUG_ON(statically_true(howmany > PCI_STD_NUM_BARS));
-
 	if (dev->non_compliant_bars)
 		return;
 
Signature · 1 line
2.47.3
#10 lore raw

Re: [PATCH 05/11] PCI: Move pci_read_bases() wrapper with BUILD_BUG_ON() to pci.h

Sashiko has reviewed this patch and found no issues.
Quoted 9 lines

pci_read_bases() is static in probe.c. An upcoming change moves CardBus device setup into setup-cardbus.c, which needs to read the CardBus BAR from outside probe.c.

Move the body of pci_read_bases() into __pci_read_bases() and keep the BUILD_BUG_ON() check in an __always_inline pci_read_bases() wrapper in pci.h so all callers retain the check.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#11 lore raw

PATCH 6/11 mmc: sdricoh_cs: Depend on CARDBUS

In reply to Ilpo Järvinen

sdricoh_cs accesses the SD controller through the PCI device of the Ricoh RL5C476 CardBus bridge. An upcoming change makes the PCI core ignore CardBus bridges when CONFIG_CARDBUS is not set, so the driver would no longer find the controller.

Make MMC_SDRICOH_CS depend on CARDBUS.

---
Cc: Ulf Hansson <[email protected]>
Cc: Sascha Sommer <[email protected]>
Cc: Dominik Brodowski <[email protected]>
Cc: [email protected]

 drivers/mmc/host/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mmc/host/Kconfig +1 -1
index 79bfc425e7c7..6b18b66c10b4 100644
@@ -692,7 +692,7 @@ config MMC_SPI
 
 config MMC_SDRICOH_CS
 	tristate "MMC/SD driver for Ricoh Bay1Controllers"
-	depends on PCI && PCMCIA
+	depends on PCI && PCMCIA && CARDBUS
 	help
 	  Say Y here if your Notebook reports a Ricoh Bay1Controller PCMCIA
 	  card whenever you insert a MMC or SD card into the card slot.
Signature · 1 line
2.47.3
#12 lore raw

Re: [PATCH 06/11] mmc: sdricoh_cs: Depend on CARDBUS

Sashiko has reviewed this patch and found no issues.
Quoted 8 lines

sdricoh_cs accesses the SD controller through the PCI device of the Ricoh RL5C476 CardBus bridge. An upcoming change makes the PCI core ignore CardBus bridges when CONFIG_CARDBUS is not set, so the driver would no longer find the controller.

Make MMC_SDRICOH_CS depend on CARDBUS.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
#13 lore raw

RFC PATCH 7/11 pcmcia: yenta_socket: Always select CARDBUS

In reply to Ilpo Järvinen

YENTA selects CARDBUS unless EXPERT is set, so with EXPERT, yenta_socket can be used without CARDBUS to support 16-bit PC Cards in the slot of a CardBus bridge. An upcoming change makes the PCI core ignore CardBus bridges when CONFIG_CARDBUS is not set effectively removing "partial CardBus support" from kernel, which leaves yenta_socket with no device to bind to.

Select CARDBUS also when EXPERT is set.

---
Cc: Dominik Brodowski <[email protected]>
Cc: [email protected]

 drivers/pcmcia/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pcmcia/Kconfig +1 -1
index d1d25aa296ad..92c34553b1ba 100644
@@ -73,7 +73,7 @@ comment "PC-card bridges"
 config YENTA
 	tristate "CardBus yenta-compatible bridge support"
 	depends on PCI
-	select CARDBUS if !EXPERT
+	select CARDBUS
 	select PCCARD_NONSTATIC if PCMCIA != n
 	help
 	  This option enables support for CardBus host bridges.  Virtually
Signature · 1 line
2.47.3
#14 lore raw

Re: [RFC PATCH 07/11] pcmcia: yenta_socket: Always select CARDBUS

Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

YENTA selects CARDBUS unless EXPERT is set, so with EXPERT, yenta_socket can be used without CARDBUS to support 16-bit PC Cards in the slot of a CardBus bridge. An upcoming change makes the PCI core ignore CardBus bridges when CONFIG_CARDBUS is not set effectively removing "partial CardBus support" from kernel, which leaves yenta_socket with no device to bind to.

Select CARDBUS also when EXPERT is set.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=7
#15 lore raw

RFC PATCH 8/11 PCI: Move CardBus device setup to setup-cardbus.c

In reply to Ilpo Järvinen

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.

---

Cc "Maciej W. Rozycki" <[email protected]>
Cc Dominik Brodowski <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Adrian Hunter <[email protected]>
Cc Takashi Sakamoto <[email protected]>
Cc Alex Dubov <[email protected]>
Cc Maxim Levitsky <[email protected]>
 drivers/pci/pci.h           |  6 ++++++
 drivers/pci/probe.c         | 13 +++++++------
 drivers/pci/setup-cardbus.c | 13 +++++++++++++
 3 files changed, 26 insertions(+), 6 deletions(-)
drivers/pci/pci.h +6 -0
index 798b31c31ae4..057c8a2c7ee7 100644
@@ -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,
drivers/pci/probe.c +7 -6
index a20ceaf7307a..f7afbaac723d 100644
@@ -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 */
drivers/pci/setup-cardbus.c +13 -0
index dcb8e2b3f73b..0de82d7fde68 100644
@@ -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)
 {
Signature · 1 line
2.47.3
#16 lore raw

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

Sashiko has reviewed this patch and found no issues.
Quoted 20 lines

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.

Quoted 7 lines

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.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=8
#17 lore raw

PATCH 9/11 PCI: Move CardBus legacy mode quirk to setup-cardbus.c

In reply to Ilpo Järvinen

quirk_cardbus_legacy() disables the legacy i82365 mode of CardBus bridges. It was originally applied even without CardBus support to keep the i82365 driver away from CardBus bridges, but that driver was removed by commit b3c26ea81ccc ("pcmcia: remove obsolete host controller drivers").

CardBus bridges are no longer set up when CONFIG_CARDBUS is not set, so the quirk only matters with CARDBUS. Move it to setup-cardbus.c.

---

Cc Dominik Brodowski <[email protected]>
 drivers/pci/quirks.c        | 13 -------------
 drivers/pci/setup-cardbus.c | 15 +++++++++++++++
 2 files changed, 15 insertions(+), 13 deletions(-)
drivers/pci/quirks.c +0 -13
index 7f1f47ea2ee4..78f6df5d4d19 100644
@@ -1286,19 +1286,6 @@ static void quirk_vt82c598_id(struct pci_dev *dev)
 }
 DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA,	PCI_DEVICE_ID_VIA_82C597_0,	quirk_vt82c598_id);
 
-/*
- * CardBus controllers have a legacy base address that enables them to
- * respond as i82365 PCMCIA controllers.  We don't want them to do this.
- */
-static void quirk_cardbus_legacy(struct pci_dev *dev)
-{
-	pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0);
-}
-DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
-			PCI_CLASS_BRIDGE_CARDBUS, 8, quirk_cardbus_legacy);
-DECLARE_PCI_FIXUP_CLASS_RESUME_EARLY(PCI_ANY_ID, PCI_ANY_ID,
-			PCI_CLASS_BRIDGE_CARDBUS, 8, quirk_cardbus_legacy);
-
 /*
  * Following the PCI ordering rules is optional on the AMD762. I'm not sure
  * what the designers were smoking but let's not inhale...
drivers/pci/setup-cardbus.c +15 -0
index 0de82d7fde68..ef35393aca1b 100644
@@ -316,3 +316,18 @@ int pci_cardbus_scan_bridge_extend(struct pci_bus *bus, struct pci_dev *dev,
 
 	return max;
 }
+
+#ifdef CONFIG_PCI_QUIRKS
+/*
+ * CardBus controllers have a legacy base address that enables them to
+ * respond as i82365 PCMCIA controllers.  We don't want them to do this.
+ */
+static void quirk_cardbus_legacy(struct pci_dev *dev)
+{
+	pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0);
+}
+DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
+			PCI_CLASS_BRIDGE_CARDBUS, 8, quirk_cardbus_legacy);
+DECLARE_PCI_FIXUP_CLASS_RESUME_EARLY(PCI_ANY_ID, PCI_ANY_ID,
+			PCI_CLASS_BRIDGE_CARDBUS, 8, quirk_cardbus_legacy);
+#endif /* CONFIG_PCI_QUIRKS */
Signature · 1 line
2.47.3
#18 lore raw

Re: [PATCH 09/11] PCI: Move CardBus legacy mode quirk to setup-cardbus.c

Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

quirk_cardbus_legacy() disables the legacy i82365 mode of CardBus bridges. It was originally applied even without CardBus support to keep the i82365 driver away from CardBus bridges, but that driver was removed by commit b3c26ea81ccc ("pcmcia: remove obsolete host controller drivers").

CardBus bridges are no longer set up when CONFIG_CARDBUS is not set, so the quirk only matters with CARDBUS. Move it to setup-cardbus.c.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=9
#19 lore raw

RFC PATCH 10/11 PCI: Move Ricoh RL5C476 MMC quirk to setup-cardbus.c

In reply to Ilpo Järvinen

ricoh_mmc_fixup_rl5c476() disables the proprietary MMC controller of the Ricoh RL5C476 through Function 0 of the chip, which is a CardBus bridge. When CONFIG_CARDBUS is not set, CardBus bridges are ignored and, as Function 0 is then missing, pci_scan_slot() does not enumerate the other Functions of the chip either. The quirk has nothing to do in that case.

Move the quirk to setup-cardbus.c so it is only built with CARDBUS. CARDBUS defaults to y when CONFIG_PCCARD is enabled, so existing configs for systems with these chips should mostly keep the quirk.

CONFIG_MMC_RICOH_MMC is an option of the SDHCI PCI card reader driver (CONFIG_MMC_SDHCI_PCI), which drives the SD controller of both the RL5C476 and the R5C832 family. On the R5C832 family, the MMC controller is disabled through the FireWire Function, which does not need CardBus. Thus, do not make MMC_RICOH_MMC depend on CARDBUS.

---

Cc Maxim Levitsky <[email protected]>
Cc Ulf Hansson <[email protected]>
Cc Adrian Hunter <[email protected]>
 drivers/pci/quirks.c        | 32 -----------------------------
 drivers/pci/setup-cardbus.c | 41 +++++++++++++++++++++++++++++++++++++
 2 files changed, 41 insertions(+), 32 deletions(-)
drivers/pci/quirks.c +0 -32
index 78f6df5d4d19..85b4c39617a6 100644
@@ -3320,38 +3320,6 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_HINT, 0x0020, quirk_hotplug_bridge);
  * #1, and this will confuse the PCI core.
  */
 #ifdef CONFIG_MMC_RICOH_MMC
-static void ricoh_mmc_fixup_rl5c476(struct pci_dev *dev)
-{
-	u8 write_enable;
-	u8 write_target;
-	u8 disable;
-
-	/*
-	 * Disable via CardBus interface
-	 *
-	 * This must be done via function #0
-	 */
-	if (PCI_FUNC(dev->devfn))
-		return;
-
-	pci_read_config_byte(dev, 0xB7, &disable);
-	if (disable & 0x02)
-		return;
-
-	pci_read_config_byte(dev, 0x8E, &write_enable);
-	pci_write_config_byte(dev, 0x8E, 0xAA);
-	pci_read_config_byte(dev, 0x8D, &write_target);
-	pci_write_config_byte(dev, 0x8D, 0xB7);
-	pci_write_config_byte(dev, 0xB7, disable | 0x02);
-	pci_write_config_byte(dev, 0x8E, write_enable);
-	pci_write_config_byte(dev, 0x8D, write_target);
-
-	pci_notice(dev, "proprietary Ricoh MMC controller disabled (via CardBus function)\n");
-	pci_notice(dev, "MMC cards are now supported by standard SDHCI controller\n");
-}
-DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, ricoh_mmc_fixup_rl5c476);
-DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, ricoh_mmc_fixup_rl5c476);
-
 static void ricoh_mmc_fixup_r5c832(struct pci_dev *dev)
 {
 	u8 write_enable;
drivers/pci/setup-cardbus.c +41 -0

45 lines not on this page · raw message

Signature · 1 line
2.47.3
#20 lore raw

Re: [RFC PATCH 10/11] PCI: Move Ricoh RL5C476 MMC quirk to setup-cardbus.c

Sashiko has reviewed this patch and found no issues.
Quoted 10 lines

ricoh_mmc_fixup_rl5c476() disables the proprietary MMC controller of the Ricoh RL5C476 through Function 0 of the chip, which is a CardBus bridge. When CONFIG_CARDBUS is not set, CardBus bridges are ignored and, as Function 0 is then missing, pci_scan_slot() does not enumerate the other Functions of the chip either. The quirk has nothing to do in that case.

Move the quirk to setup-cardbus.c so it is only built with CARDBUS. CARDBUS defaults to y when CONFIG_PCCARD is enabled, so existing configs for systems with these chips should mostly keep the quirk.

Quoted 7 lines

CONFIG_MMC_RICOH_MMC is an option of the SDHCI PCI card reader driver (CONFIG_MMC_SDHCI_PCI), which drives the SD controller of both the RL5C476 and the R5C832 family. On the R5C832 family, the MMC controller is disabled through the FireWire Function, which does not need CardBus. Thus, do not make MMC_RICOH_MMC depend on CARDBUS.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=10
#21 lore raw

PATCH 11/11 PCI: Move CardBus resource names to setup-cardbus.c

In reply to Ilpo Järvinen

pci_resource_name() contains a table of resource names specific to CardBus bridges. Move the CardBus-specific part into pci_cardbus_resource_name() in setup-cardbus.c to make the core code cleaner.

---
 drivers/pci/pci.c           | 26 ++------------------------
 drivers/pci/pci.h           |  5 +++++
 drivers/pci/setup-cardbus.c | 30 ++++++++++++++++++++++++++++++
 3 files changed, 37 insertions(+), 24 deletions(-)
drivers/pci/pci.c +2 -24
index 46da873c9aac..e6c5a2d28abf 100644
@@ -832,31 +832,9 @@ const char *pci_resource_name(struct pci_dev *dev, unsigned int i)
 		"bridge window",	/* "mem" included in %pR */
 		"bridge window",	/* "mem pref" included in %pR */
 	};
-	static const char * const cardbus_name[] = {
-		"BAR 1",
-		"unknown",
-		"unknown",
-		"unknown",
-		"unknown",
-		"unknown",
-		"unknown",
-#ifdef CONFIG_PCI_IOV
-		"unknown",
-		"unknown",
-		"unknown",
-		"unknown",
-		"unknown",
-		"unknown",
-#endif
-		"CardBus bridge window 0",	/* I/O */
-		"CardBus bridge window 1",	/* I/O */
-		"CardBus bridge window 0",	/* mem */
-		"CardBus bridge window 1",	/* mem */
-	};
 
-	if (dev->hdr_type == PCI_HEADER_TYPE_CARDBUS &&
-	    i < ARRAY_SIZE(cardbus_name))
-		return cardbus_name[i];
+	if (pci_is_cardbus_bridge(dev))
+		return pci_cardbus_resource_name(i);
 
 	if (i < ARRAY_SIZE(bar_name))
 		return bar_name[i];
drivers/pci/pci.h +5 -0
index 057c8a2c7ee7..eefa5a2937c1 100644
@@ -426,6 +426,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);
+const char *pci_cardbus_resource_name(unsigned int resno);
 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,
@@ -442,6 +443,10 @@ static inline int pci_setup_cardbus_device(struct pci_dev *dev)
 {
 	return -EOPNOTSUPP;
 }
+static inline const char *pci_cardbus_resource_name(unsigned int resno)
+{
+	return "unsupported";
+}
 static inline int pci_bus_size_cardbus_bridge(struct pci_bus *bus,
 					      struct list_head *realloc_head)
 {
drivers/pci/setup-cardbus.c +30 -0
index 33aca7b28354..9acbf299c3a3 100644
@@ -44,6 +44,36 @@ int pci_setup_cardbus_device(struct pci_dev *dev)
 	return 0;
 }
 
+const char *pci_cardbus_resource_name(unsigned int resno)
+{
+	static const char * const cardbus_name[] = {
+		"BAR 1",
+		"unknown",
+		"unknown",
+		"unknown",
+		"unknown",
+		"unknown",
+		"unknown",
+#ifdef CONFIG_PCI_IOV
+		"unknown",
+		"unknown",
+		"unknown",
+		"unknown",
+		"unknown",
+		"unknown",
+#endif
+		"CardBus bridge window 0",	/* I/O */
+		"CardBus bridge window 1",	/* I/O */
+		"CardBus bridge window 0",	/* mem */
+		"CardBus bridge window 1",	/* mem */
+	};
+
+	if (resno < ARRAY_SIZE(cardbus_name))
+		return cardbus_name[resno];
+
+	return "unknown";
+}
+
 int pci_bus_size_cardbus_bridge(struct pci_bus *bus,
 				struct list_head *realloc_head)
 {
Signature · 1 line
2.47.3
#22 lore raw

Re: [PATCH 11/11] PCI: Move CardBus resource names to setup-cardbus.c

Sashiko has reviewed this patch and found no issues.
Quoted 6 lines

pci_resource_name() contains a table of resource names specific to CardBus bridges. Move the CardBus-specific part into pci_cardbus_resource_name() in setup-cardbus.c to make the core code cleaner.

Sashiko has reviewed this patch and found no issues.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=11