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.c29
1 files changed, 14 insertions, 15 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index df495300ce3d..d3eab057b2d3 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -551,7 +551,9 @@ static int pci_save_pcie_state(struct pci_dev *dev)
551 if (pos <= 0) 551 if (pos <= 0)
552 return 0; 552 return 0;
553 553
554 save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL); 554 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
555 if (!save_state)
556 save_state = kzalloc(sizeof(*save_state) + sizeof(u16) * 4, GFP_KERNEL);
555 if (!save_state) { 557 if (!save_state) {
556 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); 558 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
557 return -ENOMEM; 559 return -ENOMEM;
@@ -582,8 +584,6 @@ static void pci_restore_pcie_state(struct pci_dev *dev)
582 pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]); 584 pci_write_config_word(dev, pos + PCI_EXP_LNKCTL, cap[i++]);
583 pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]); 585 pci_write_config_word(dev, pos + PCI_EXP_SLTCTL, cap[i++]);
584 pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]); 586 pci_write_config_word(dev, pos + PCI_EXP_RTCTL, cap[i++]);
585 pci_remove_saved_cap(save_state);
586 kfree(save_state);
587} 587}
588 588
589 589
@@ -597,7 +597,9 @@ static int pci_save_pcix_state(struct pci_dev *dev)
597 if (pos <= 0) 597 if (pos <= 0)
598 return 0; 598 return 0;
599 599
600 save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL); 600 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_EXP);
601 if (!save_state)
602 save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL);
601 if (!save_state) { 603 if (!save_state) {
602 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n"); 604 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
603 return -ENOMEM; 605 return -ENOMEM;
@@ -622,8 +624,6 @@ static void pci_restore_pcix_state(struct pci_dev *dev)
622 cap = (u16 *)&save_state->data[0]; 624 cap = (u16 *)&save_state->data[0];
623 625
624 pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]); 626 pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]);
625 pci_remove_saved_cap(save_state);
626 kfree(save_state);
627} 627}
628 628
629 629
@@ -638,8 +638,6 @@ pci_save_state(struct pci_dev *dev)
638 /* XXX: 100% dword access ok here? */ 638 /* XXX: 100% dword access ok here? */
639 for (i = 0; i < 16; i++) 639 for (i = 0; i < 16; i++)
640 pci_read_config_dword(dev, i * 4,&dev->saved_config_space[i]); 640 pci_read_config_dword(dev, i * 4,&dev->saved_config_space[i]);
641 if ((i = pci_save_msi_state(dev)) != 0)
642 return i;
643 if ((i = pci_save_pcie_state(dev)) != 0) 641 if ((i = pci_save_pcie_state(dev)) != 0)
644 return i; 642 return i;
645 if ((i = pci_save_pcix_state(dev)) != 0) 643 if ((i = pci_save_pcix_state(dev)) != 0)
@@ -757,7 +755,8 @@ int pci_enable_device(struct pci_dev *dev)
757 * when a device is enabled using managed PCI device enable interface. 755 * when a device is enabled using managed PCI device enable interface.
758 */ 756 */
759struct pci_devres { 757struct pci_devres {
760 unsigned int disable:1; 758 unsigned int enabled:1;
759 unsigned int pinned:1;
761 unsigned int orig_intx:1; 760 unsigned int orig_intx:1;
762 unsigned int restore_intx:1; 761 unsigned int restore_intx:1;
763 u32 region_mask; 762 u32 region_mask;
@@ -781,7 +780,7 @@ static void pcim_release(struct device *gendev, void *res)
781 if (this->restore_intx) 780 if (this->restore_intx)
782 pci_intx(dev, this->orig_intx); 781 pci_intx(dev, this->orig_intx);
783 782
784 if (this->disable) 783 if (this->enabled && !this->pinned)
785 pci_disable_device(dev); 784 pci_disable_device(dev);
786} 785}
787 786
@@ -820,12 +819,12 @@ int pcim_enable_device(struct pci_dev *pdev)
820 dr = get_pci_dr(pdev); 819 dr = get_pci_dr(pdev);
821 if (unlikely(!dr)) 820 if (unlikely(!dr))
822 return -ENOMEM; 821 return -ENOMEM;
823 WARN_ON(!!dr->disable); 822 WARN_ON(!!dr->enabled);
824 823
825 rc = pci_enable_device(pdev); 824 rc = pci_enable_device(pdev);
826 if (!rc) { 825 if (!rc) {
827 pdev->is_managed = 1; 826 pdev->is_managed = 1;
828 dr->disable = 1; 827 dr->enabled = 1;
829 } 828 }
830 return rc; 829 return rc;
831} 830}
@@ -843,9 +842,9 @@ void pcim_pin_device(struct pci_dev *pdev)
843 struct pci_devres *dr; 842 struct pci_devres *dr;
844 843
845 dr = find_pci_dr(pdev); 844 dr = find_pci_dr(pdev);
846 WARN_ON(!dr || !dr->disable); 845 WARN_ON(!dr || !dr->enabled);
847 if (dr) 846 if (dr)
848 dr->disable = 0; 847 dr->pinned = 1;
849} 848}
850 849
851/** 850/**
@@ -876,7 +875,7 @@ pci_disable_device(struct pci_dev *dev)
876 875
877 dr = find_pci_dr(dev); 876 dr = find_pci_dr(dev);
878 if (dr) 877 if (dr)
879 dr->disable = 0; 878 dr->enabled = 0;
880 879
881 if (atomic_sub_return(1, &dev->enable_cnt) != 0) 880 if (atomic_sub_return(1, &dev->enable_cnt) != 0)
882 return; 881 return;