vserver 1.9.5.x5
[linux-2.6.git] / drivers / pci / pci-driver.c
index 64195d6..8a09a95 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
  */
@@ -291,33 +270,30 @@ static int pci_device_remove(struct device * dev)
                        drv->remove(pci_dev);
                pci_dev->driver = NULL;
        }
+
+       /*
+        * We would love to complain here if pci_dev->is_enabled is set, that
+        * the driver should have called pci_disable_device(), but the
+        * unfortunate fact is there are too many odd BIOS and bridge setups
+        * that don't like drivers doing that all of the time.  
+        * Oh well, we can dream of sane hardware when we sleep, no matter how
+        * horrible the crap we have to deal with is when we are awake...
+        */
+
        pci_dev_put(pci_dev);
        return 0;
 }
 
-static int pci_device_suspend(struct device * dev, u32 state)
+static int pci_device_suspend(struct device * dev, pm_message_t state)
 {
        struct pci_dev * pci_dev = to_pci_dev(dev);
        struct pci_driver * drv = pci_dev->driver;
-       u32 dev_state;
        int i = 0;
 
-       /* Translate PM_SUSPEND_xx states to PCI device states */
-       static u32 state_conversion[] = {
-               [PM_SUSPEND_ON] = 0,
-               [PM_SUSPEND_STANDBY] = 1,
-               [PM_SUSPEND_MEM] = 3,
-               [PM_SUSPEND_DISK] = 3,
-       };
-
-       if (state >= sizeof(state_conversion) / sizeof(state_conversion[1]))
-               return -EINVAL;
-
-       dev_state = state_conversion[state];
        if (drv && drv->suspend)
-               i = drv->suspend(pci_dev, dev_state);
-               
-       pci_save_state(pci_dev, pci_dev->saved_config_space);
+               i = drv->suspend(pci_dev, state);
+       else
+               pci_save_state(pci_dev);
        return i;
 }
 
@@ -329,7 +305,7 @@ static int pci_device_suspend(struct device * dev, u32 state)
 static void pci_default_resume(struct pci_dev *pci_dev)
 {
        /* restore the PCI config space */
-       pci_restore_state(pci_dev, pci_dev->saved_config_space);
+       pci_restore_state(pci_dev);
        /* if the device was enabled before suspend, reenable */
        if (pci_dev->is_enabled)
                pci_enable_device(pci_dev);
@@ -404,30 +380,30 @@ pci_populate_driver_dir(struct pci_driver *drv)
  * @drv: the driver structure to register
  * 
  * Adds the driver structure to the list of registered drivers.
- * Returns a negative value on error. The driver remains registered
- * even if no device was claimed during registration.
+ * Returns a negative value on error, otherwise 0. 
+ * If no error occured, the driver remains registered even if 
+ * no device was claimed during registration.
  */
-int
-pci_register_driver(struct pci_driver *drv)
+int pci_register_driver(struct pci_driver *drv)
 {
-       int count = 0;
+       int error;
 
        /* initialize common driver fields */
        drv->driver.name = drv->name;
        drv->driver.bus = &pci_bus_type;
        drv->driver.probe = pci_device_probe;
        drv->driver.remove = pci_device_remove;
+       drv->driver.owner = drv->owner;
        drv->driver.kobj.ktype = &pci_driver_kobj_type;
        pci_init_dynids(&drv->dynids);
 
        /* register with core */
-       count = driver_register(&drv->driver);
+       error = driver_register(&drv->driver);
 
-       if (count >= 0) {
+       if (!error)
                pci_populate_driver_dir(drv);
-       }
 
-       return count ? count : 1;
+       return error;
 }
 
 /**
@@ -512,16 +488,9 @@ static int pci_bus_match(struct device * dev, struct device_driver * drv)
  */
 struct pci_dev *pci_dev_get(struct pci_dev *dev)
 {
-       struct device *tmp;
-
-       if (!dev)
-               return NULL;
-
-       tmp = get_device(&dev->dev);
-       if (tmp)        
-               return to_pci_dev(tmp);
-       else
-               return NULL;
+       if (dev)
+               get_device(&dev->dev);
+       return dev;
 }
 
 /**