Skip to contentSkip to conversation

PCI: Move no_pci_devices() to the only driver using it

PATCH In review Ilpo Järvinen 3 participants 3 messages Oct 9, 2024 – Oct 22, 2024

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

PATCH 1/1 PCI: Move no_pci_devices() to the only driver using it

Core PCI code provides no_pci_devices() that is only used in the pc110pad driver during init to detect cases when PC110 definitely cannot be present. Move this legacy detection trickery/hack into the pc110pad driver.

---
 drivers/input/mouse/pc110pad.c | 19 +++++++++++++++++++
 drivers/pci/probe.c            | 17 -----------------
 include/linux/pci.h            |  3 ---
 3 files changed, 19 insertions(+), 20 deletions(-)
drivers/input/mouse/pc110pad.c +19 -0
index efa58049f746..f4167a7e71c8 100644
@@ -87,6 +87,25 @@ static int pc110pad_open(struct input_dev *dev)
  * that the PC110 is not a PCI system. So if we find any
  * PCI devices in the machine, we don't have a PC110.
  */
+#ifdef CONFIG_PCI
+static int __init no_pci_devices(void)
+{
+	struct device *dev;
+	int no_devices;
+
+	dev = bus_find_next_device(&pci_bus_type, NULL);
+	no_devices = (dev == NULL);
+	put_device(dev);
+	return no_devices;
+}
+#else
+static int __init no_pci_devices(void)
+{
+	return 1;
+}
+#endif
+
+
 static int __init pc110pad_init(void)
 {
 	int err;
drivers/pci/probe.c +0 -17
index 4f68414c3086..2704503fa8fb 100644
@@ -65,23 +65,6 @@ static struct resource *get_pci_domain_busn_res(int domain_nr)
 	return &r->res;
 }
 
-/*
- * Some device drivers need know if PCI is initiated.
- * Basically, we think PCI is not initiated when there
- * is no device to be found on the pci_bus_type.
- */
-int no_pci_devices(void)
-{
-	struct device *dev;
-	int no_devices;
-
-	dev = bus_find_next_device(&pci_bus_type, NULL);
-	no_devices = (dev == NULL);
-	put_device(dev);
-	return no_devices;
-}
-EXPORT_SYMBOL(no_pci_devices);
-
 /*
  * PCI Bus Class
  */
include/linux/pci.h +0 -3
index 573b4c4c2be6..4757ce7ccd53 100644
@@ -1107,8 +1107,6 @@ extern const struct bus_type pci_bus_type;
 /* Do NOT directly access these two variables, unless you are arch-specific PCI
  * code, or PCI core code. */
 extern struct list_head pci_root_buses;	/* List of all known PCI buses */
-/* Some device drivers need know if PCI is initiated */
-int no_pci_devices(void);
 
 void pcibios_resource_survey_bus(struct pci_bus *bus);
 void pcibios_bus_add_device(struct pci_dev *pdev);
@@ -1969,7 +1967,6 @@ static inline struct pci_dev *pci_get_base_class(unsigned int class,
 static inline int pci_dev_present(const struct pci_device_id *ids)
 { return 0; }
 
-#define no_pci_devices()	(1)
 #define pci_dev_put(dev)	do { } while (0)
 
 static inline void pci_set_master(struct pci_dev *dev) { }
Signature · 1 line
2.39.5
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Ilpo Järvinen

Core PCI code provides no_pci_devices() that is only used in the pc110pad driver during init to detect cases when PC110 definitely cannot be present. Move this legacy detection trickery/hack into the pc110pad driver.

Thanks, this is indeed a gross hack, and I'd be glad to eradicate it from PCI.

Quoted 88 lines
---
 drivers/input/mouse/pc110pad.c | 19 +++++++++++++++++++
 drivers/pci/probe.c            | 17 -----------------
 include/linux/pci.h            |  3 ---
 3 files changed, 19 insertions(+), 20 deletions(-)
drivers/input/mouse/pc110pad.c +19 -0
index efa58049f746..f4167a7e71c8 100644
@@ -87,6 +87,25 @@ static int pc110pad_open(struct input_dev *dev)
  * that the PC110 is not a PCI system. So if we find any
  * PCI devices in the machine, we don't have a PC110.
  */
+#ifdef CONFIG_PCI
+static int __init no_pci_devices(void)
+{
+	struct device *dev;
+	int no_devices;
+
+	dev = bus_find_next_device(&pci_bus_type, NULL);
+	no_devices = (dev == NULL);
+	put_device(dev);
+	return no_devices;
+}
+#else
+static int __init no_pci_devices(void)
+{
+	return 1;
+}
+#endif
+
+
 static int __init pc110pad_init(void)
 {
 	int err;
drivers/pci/probe.c +0 -17
index 4f68414c3086..2704503fa8fb 100644
@@ -65,23 +65,6 @@ static struct resource *get_pci_domain_busn_res(int domain_nr)
 	return &r->res;
 }
 
-/*
- * Some device drivers need know if PCI is initiated.
- * Basically, we think PCI is not initiated when there
- * is no device to be found on the pci_bus_type.
- */
-int no_pci_devices(void)
-{
-	struct device *dev;
-	int no_devices;
-
-	dev = bus_find_next_device(&pci_bus_type, NULL);
-	no_devices = (dev == NULL);
-	put_device(dev);
-	return no_devices;
-}
-EXPORT_SYMBOL(no_pci_devices);
-
 /*
  * PCI Bus Class
  */
include/linux/pci.h +0 -3
index 573b4c4c2be6..4757ce7ccd53 100644
@@ -1107,8 +1107,6 @@ extern const struct bus_type pci_bus_type;
 /* Do NOT directly access these two variables, unless you are arch-specific PCI
  * code, or PCI core code. */
 extern struct list_head pci_root_buses;	/* List of all known PCI buses */
-/* Some device drivers need know if PCI is initiated */
-int no_pci_devices(void);
 
 void pcibios_resource_survey_bus(struct pci_bus *bus);
 void pcibios_bus_add_device(struct pci_dev *pdev);
@@ -1969,7 +1967,6 @@ static inline struct pci_dev *pci_get_base_class(unsigned int class,
 static inline int pci_dev_present(const struct pci_device_id *ids)
 { return 0; }
 
-#define no_pci_devices()	(1)
 #define pci_dev_put(dev)	do { } while (0)
 
 static inline void pci_set_master(struct pci_dev *dev) { }
Signature · 1 line
2.39.5
maintainer
#2 lore raw

Hi Bjorn, Ilpo,

Quoted 6 lines · Bjorn Helgaas
Quoted 5 lines · Ilpo Järvinen

Core PCI code provides no_pci_devices() that is only used in the pc110pad driver during init to detect cases when PC110 definitely cannot be present. Move this legacy detection trickery/hack into the pc110pad driver.

Quoted 6 lines
Quoted 1 line

Thanks, this is indeed a gross hack, and I'd be glad to eradicate it from PCI.

I would much rather remove pc110_pad altogether. If I can get a "Reviewed-by" on [1] that would be great.

[1] https://lore.kernel.org/all/[email protected]/

Thanks.

Signature · 1 line
Dmitry