From 38cc13022ed3cea949722d5a6f49025da82c9fd0 Mon Sep 17 00:00:00 2001 From: Hidetoshi Seto Date: Mon, 18 Dec 2006 10:30:00 +0900 Subject: PCI : add extremely specialized __pci_reenable_device for default resume Original patch was posted as "PCI : Move pci_fixup_device and is_enabled". This 3 of 3 patches does: - add __pci_reenable_device (recover former change of 1st patch) Signed-off-by: Kenji Kaneshige Signed-off-by: Hidetoshi Seto Cc: Inaky Perez-Gonzalez Signed-off-by: Greg Kroah-Hartman --- drivers/pci/pci.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'drivers/pci/pci.c') diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c index 212acd2e1a84..287b685aaa5c 100644 --- a/drivers/pci/pci.c +++ b/drivers/pci/pci.c @@ -676,6 +676,36 @@ pci_restore_state(struct pci_dev *dev) return 0; } +static int do_pci_enable_device(struct pci_dev *dev, int bars) +{ + int err; + + err = pci_set_power_state(dev, PCI_D0); + if (err < 0 && err != -EIO) + return err; + err = pcibios_enable_device(dev, bars); + if (err < 0) + return err; + pci_fixup_device(pci_fixup_enable, dev); + + return 0; +} + +/** + * __pci_reenable_device - Resume abandoned device + * @dev: PCI device to be resumed + * + * Note this function is a backend of pci_default_resume and is not supposed + * to be called by normal code, write proper resume handler and use it instead. + */ +int +__pci_reenable_device(struct pci_dev *dev) +{ + if (atomic_read(&dev->enable_cnt)) + return do_pci_enable_device(dev, (1 << PCI_NUM_RESOURCES) - 1); + return 0; +} + /** * pci_enable_device_bars - Initialize some of a device for use * @dev: PCI device to be initialized @@ -693,16 +723,9 @@ pci_enable_device_bars(struct pci_dev *dev, int bars) if (atomic_add_return(1, &dev->enable_cnt) > 1) return 0; /* already enabled */ - err = pci_set_power_state(dev, PCI_D0); - if (err < 0 && err != -EIO) - goto err_out; - err = pcibios_enable_device(dev, bars); + err = do_pci_enable_device(dev, bars); if (err < 0) - goto err_out; - pci_fixup_device(pci_fixup_enable, dev); - -err_out: - atomic_dec(&dev->enable_cnt); + atomic_dec(&dev->enable_cnt); return err; } -- cgit v1.2.3