aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pci/pci.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/pci/pci.c')
-rw-r--r--drivers/pci/pci.c24
1 files changed, 12 insertions, 12 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index d20d3983bbd6..212acd2e1a84 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -682,22 +682,28 @@ pci_restore_state(struct pci_dev *dev)
682 * @bars: bitmask of BAR's that must be configured 682 * @bars: bitmask of BAR's that must be configured
683 * 683 *
684 * Initialize device before it's used by a driver. Ask low-level code 684 * Initialize device before it's used by a driver. Ask low-level code
685 * to enable selected I/O and memory resources. Wake up the device if it 685 * to enable selected I/O and memory resources. Wake up the device if it
686 * was suspended. Beware, this function can fail. 686 * was suspended. Beware, this function can fail.
687 */ 687 */
688
689int 688int
690pci_enable_device_bars(struct pci_dev *dev, int bars) 689pci_enable_device_bars(struct pci_dev *dev, int bars)
691{ 690{
692 int err; 691 int err;
693 692
693 if (atomic_add_return(1, &dev->enable_cnt) > 1)
694 return 0; /* already enabled */
695
694 err = pci_set_power_state(dev, PCI_D0); 696 err = pci_set_power_state(dev, PCI_D0);
695 if (err < 0 && err != -EIO) 697 if (err < 0 && err != -EIO)
696 return err; 698 goto err_out;
697 err = pcibios_enable_device(dev, bars); 699 err = pcibios_enable_device(dev, bars);
698 if (err < 0) 700 if (err < 0)
699 return err; 701 goto err_out;
700 return 0; 702 pci_fixup_device(pci_fixup_enable, dev);
703
704err_out:
705 atomic_dec(&dev->enable_cnt);
706 return err;
701} 707}
702 708
703/** 709/**
@@ -713,13 +719,7 @@ pci_enable_device_bars(struct pci_dev *dev, int bars)
713 */ 719 */
714int pci_enable_device(struct pci_dev *dev) 720int pci_enable_device(struct pci_dev *dev)
715{ 721{
716 int result; 722 return pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1);
717 if (atomic_add_return(1, &dev->enable_cnt) > 1)
718 return 0; /* already enabled */
719 result = __pci_enable_device(dev);
720 if (result < 0)
721 atomic_dec(&dev->enable_cnt);
722 return result;
723} 723}
724 724
725/** 725/**