]> git.hungrycats.org Git - linux/commitdiff
[PATCH] PCI: Create new function to see if a pci device is present
authorGreg Kroah-Hartman <greg@kroah.com>
Wed, 6 Oct 2004 06:05:22 +0000 (23:05 -0700)
committerGreg Kroah-Hartman <greg@kroah.com>
Wed, 6 Oct 2004 06:05:22 +0000 (23:05 -0700)
This is needed to help get rid of the pci_find_device() usage in the tree.

Signed-off-by: Hanna Linder <hannal@us.ibm.com>
Signed-off-by: Greg Kroah-Hartman <greg@kroah.com>
drivers/pci/pci-driver.c
drivers/pci/pci.h
drivers/pci/search.c
include/linux/pci.h

index 0cf9f2d5129ec2645501d151c684442a144ce83f..807b1418a45a326287948f43a889d865c1d2060f 100644 (file)
  *  Registration of PCI drivers and handling of hot-pluggable devices.
  */
 
-/**
- * pci_match_one_device - Tell if a PCI device structure has a matching
- *                        PCI device id structure
- * @id: single PCI device id structure to match
- * @dev: the PCI device structure to match against
- * 
- * Returns the matching pci_device_id structure or %NULL if there is no match.
- */
-
-static inline const struct pci_device_id *
-pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
-{
-       if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) &&
-           (id->device == PCI_ANY_ID || id->device == dev->device) &&
-           (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
-           (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) &&
-           !((id->class ^ dev->class) & id->class_mask))
-               return id;
-       return NULL;
-}
-
 /*
  * Dynamic device IDs are disabled for !CONFIG_HOTPLUG
  */
index a9b243770580e9a6f071c6e8b03abbf7ba77b376..0c58b65e9c302bb1e20740fdbce7826555fc1b40 100644 (file)
@@ -63,3 +63,24 @@ extern spinlock_t pci_bus_lock;
 
 extern int pciehp_msi_quirk;
 extern struct device_attribute pci_dev_attrs[];
+
+/**
+ * pci_match_one_device - Tell if a PCI device structure has a matching
+ *                        PCI device id structure
+ * @id: single PCI device id structure to match
+ * @dev: the PCI device structure to match against
+ * 
+ * Returns the matching pci_device_id structure or %NULL if there is no match.
+ */
+static inline const struct pci_device_id *
+pci_match_one_device(const struct pci_device_id *id, const struct pci_dev *dev)
+{
+       if ((id->vendor == PCI_ANY_ID || id->vendor == dev->vendor) &&
+           (id->device == PCI_ANY_ID || id->device == dev->device) &&
+           (id->subvendor == PCI_ANY_ID || id->subvendor == dev->subsystem_vendor) &&
+           (id->subdevice == PCI_ANY_ID || id->subdevice == dev->subsystem_device) &&
+           !((id->class ^ dev->class) & id->class_mask))
+               return id;
+       return NULL;
+}
+
index 25e64650022f020d6fc6bad851aedd6489d4feff..a1fb8b57d62064322d0c460a8bbe79a5151251b4 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/pci.h>
 #include <linux/module.h>
 #include <linux/interrupt.h>
+#include "pci.h"
 
 spinlock_t pci_bus_lock = SPIN_LOCK_UNLOCKED;
 
@@ -344,6 +345,39 @@ exit:
        return dev;
 }
 
+/**
+ * pci_dev_present - Returns 1 if device matching the device list is present, 0 if not.
+ * @ids: A pointer to a null terminated list of struct pci_device_id structures
+ * that describe the type of PCI device the caller is trying to find.
+ *
+ * Obvious fact: You do not have a reference to any device that might be found
+ * by this function, so if that device is removed from the system right after
+ * this function is finished, the value will be stale.  Use this function to
+ * find devices that are usually built into a system, or for a general hint as
+ * to if another device happens to be present at this specific moment in time.
+ */
+int pci_dev_present(const struct pci_device_id *ids)
+{
+       struct pci_dev *dev;
+       int found = 0;
+
+       WARN_ON(in_interrupt());
+       spin_lock(&pci_bus_lock);
+       while (ids->vendor || ids->subvendor || ids->class_mask) {
+               list_for_each_entry(dev, &pci_devices, global_list) {
+                       if (pci_match_one_device(ids, dev)) {
+                               found = 1;
+                               goto exit;
+                       }
+               }
+               ids++;
+       }
+exit:                          
+       spin_unlock(&pci_bus_lock);
+       return found;
+}
+EXPORT_SYMBOL(pci_dev_present);
+
 EXPORT_SYMBOL(pci_find_bus);
 EXPORT_SYMBOL(pci_find_device);
 EXPORT_SYMBOL(pci_find_device_reverse);
index 169badd4917ed3ebc519ac6407515bda828efa91..eb0d2c81c36c4a2246d8bff97fcf16cbcfc78e51 100644 (file)
@@ -730,6 +730,7 @@ struct pci_dev *pci_get_subsys (unsigned int vendor, unsigned int device,
                                struct pci_dev *from);
 struct pci_dev *pci_get_slot (struct pci_bus *bus, unsigned int devfn);
 struct pci_dev *pci_get_class (unsigned int class, struct pci_dev *from);
+int pci_dev_present(const struct pci_device_id *ids);
 
 int pci_bus_read_config_byte (struct pci_bus *bus, unsigned int devfn, int where, u8 *val);
 int pci_bus_read_config_word (struct pci_bus *bus, unsigned int devfn, int where, u16 *val);
@@ -891,6 +892,8 @@ unsigned int ss_vendor, unsigned int ss_device, struct pci_dev *from)
 
 static inline struct pci_dev *pci_get_class(unsigned int class, struct pci_dev *from)
 { return NULL; }
+static inline int pci_dev_present(const struct pci_device_id *ids)
+{ return 0; }
 
 static inline void pci_set_master(struct pci_dev *dev) { }
 static inline int pci_enable_device(struct pci_dev *dev) { return -EIO; }