patch-2.3.39 linux/drivers/pci/pci.c

Next file: linux/drivers/pci/pcisyms.c
Previous file: linux/drivers/parport/parport_pc.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.38/linux/drivers/pci/pci.c linux/drivers/pci/pci.c
@@ -9,6 +9,7 @@
  *	Copyright 1997 -- 2000 Martin Mares <mj@suse.cz>
  */
 
+#include <linux/config.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <linux/pci.h>
@@ -193,6 +194,101 @@
 		return err;
 	pci_set_power_state(dev, 0);
 	return 0;
+}
+
+/*
+ *  Registration of PCI drivers and handling of hot-pluggable devices.
+ */
+
+static LIST_HEAD(pci_drivers);
+
+void
+pci_register_driver(struct pci_driver *drv)
+{
+	struct pci_dev *dev;
+
+	list_add_tail(&drv->node, &pci_drivers);
+	pci_for_each_dev(dev) {
+		if (!pci_dev_driver(dev) && drv->probe(dev))
+			dev->driver = drv;
+	}
+}
+
+void
+pci_unregister_driver(struct pci_driver *drv)
+{
+	struct pci_dev *dev;
+
+	list_del(&drv->node);
+	pci_for_each_dev(dev) {
+		if (dev->driver == drv) {
+			if (drv->remove)
+				drv->remove(dev);
+			dev->driver = NULL;
+		}
+	}
+}
+
+void
+pci_insert_device(struct pci_dev *dev, struct pci_bus *bus)
+{
+	struct list_head *ln;
+
+	list_add_tail(&dev->bus_list, &bus->devices);
+	list_add_tail(&dev->global_list, &pci_devices);
+#ifdef CONFIG_PROC_FS
+	pci_proc_attach_device(dev);
+#endif
+	for(ln=pci_drivers.next; ln != &pci_drivers; ln=ln->next) {
+		struct pci_driver *drv = list_entry(ln, struct pci_driver, node);
+		if (drv->probe(dev)) {
+			dev->driver = drv;
+			break;
+		}
+	}
+}
+
+static void pci_free_resources(struct pci_dev *dev)
+{
+	int i;
+
+	for (i = 0; i < PCI_NUM_RESOURCES; i++) {
+		struct resource *res = dev->resource + i;
+		if (res->parent)
+			release_resource(res);
+	}
+}
+
+void
+pci_remove_device(struct pci_dev *dev)
+{
+	if (dev->driver->remove)
+		dev->driver->remove(dev);
+	dev->driver = NULL;
+	list_del(&dev->bus_list);
+	list_del(&dev->global_list);
+	pci_free_resources(dev);
+#ifdef CONFIG_PROC_FS
+	pci_proc_detach_device(dev);
+#endif
+}
+
+static struct pci_driver pci_compat_driver = {
+	name: "compat"
+};
+
+struct pci_driver *
+pci_dev_driver(struct pci_dev *dev)
+{
+	if (dev->driver)
+		return dev->driver;
+	else {
+		int i;
+		for(i=0; i<=PCI_ROM_RESOURCE; i++)
+			if (dev->resource[i].flags & IORESOURCE_BUSY)
+				return &pci_compat_driver;
+	}
+	return NULL;
 }
 
 

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)