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.c123
1 files changed, 102 insertions, 21 deletions
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index a544997399b3..5a14b73cf3a1 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -490,6 +490,47 @@ static void pci_restore_pcie_state(struct pci_dev *dev)
490 kfree(save_state); 490 kfree(save_state);
491} 491}
492 492
493
494static int pci_save_pcix_state(struct pci_dev *dev)
495{
496 int pos, i = 0;
497 struct pci_cap_saved_state *save_state;
498 u16 *cap;
499
500 pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
501 if (pos <= 0)
502 return 0;
503
504 save_state = kzalloc(sizeof(*save_state) + sizeof(u16), GFP_KERNEL);
505 if (!save_state) {
506 dev_err(&dev->dev, "Out of memory in pci_save_pcie_state\n");
507 return -ENOMEM;
508 }
509 cap = (u16 *)&save_state->data[0];
510
511 pci_read_config_word(dev, pos + PCI_X_CMD, &cap[i++]);
512 pci_add_saved_cap(dev, save_state);
513 return 0;
514}
515
516static void pci_restore_pcix_state(struct pci_dev *dev)
517{
518 int i = 0, pos;
519 struct pci_cap_saved_state *save_state;
520 u16 *cap;
521
522 save_state = pci_find_saved_cap(dev, PCI_CAP_ID_PCIX);
523 pos = pci_find_capability(dev, PCI_CAP_ID_PCIX);
524 if (!save_state || pos <= 0)
525 return;
526 cap = (u16 *)&save_state->data[0];
527
528 pci_write_config_word(dev, pos + PCI_X_CMD, cap[i++]);
529 pci_remove_saved_cap(save_state);
530 kfree(save_state);
531}
532
533
493/** 534/**
494 * pci_save_state - save the PCI configuration space of a device before suspending 535 * pci_save_state - save the PCI configuration space of a device before suspending
495 * @dev: - PCI device that we're dealing with 536 * @dev: - PCI device that we're dealing with
@@ -507,6 +548,8 @@ pci_save_state(struct pci_dev *dev)
507 return i; 548 return i;
508 if ((i = pci_save_pcie_state(dev)) != 0) 549 if ((i = pci_save_pcie_state(dev)) != 0)
509 return i; 550 return i;
551 if ((i = pci_save_pcix_state(dev)) != 0)
552 return i;
510 return 0; 553 return 0;
511} 554}
512 555
@@ -538,6 +581,7 @@ pci_restore_state(struct pci_dev *dev)
538 dev->saved_config_space[i]); 581 dev->saved_config_space[i]);
539 } 582 }
540 } 583 }
584 pci_restore_pcix_state(dev);
541 pci_restore_msi_state(dev); 585 pci_restore_msi_state(dev);
542 pci_restore_msix_state(dev); 586 pci_restore_msix_state(dev);
543 return 0; 587 return 0;
@@ -568,30 +612,51 @@ pci_enable_device_bars(struct pci_dev *dev, int bars)
568} 612}
569 613
570/** 614/**
571 * pci_enable_device - Initialize device before it's used by a driver. 615 * __pci_enable_device - Initialize device before it's used by a driver.
572 * @dev: PCI device to be initialized 616 * @dev: PCI device to be initialized
573 * 617 *
574 * Initialize device before it's used by a driver. Ask low-level code 618 * Initialize device before it's used by a driver. Ask low-level code
575 * to enable I/O and memory. Wake up the device if it was suspended. 619 * to enable I/O and memory. Wake up the device if it was suspended.
576 * Beware, this function can fail. 620 * Beware, this function can fail.
621 *
622 * Note this function is a backend and is not supposed to be called by
623 * normal code, use pci_enable_device() instead.
577 */ 624 */
578int 625int
579pci_enable_device(struct pci_dev *dev) 626__pci_enable_device(struct pci_dev *dev)
580{ 627{
581 int err; 628 int err;
582 629
583 if (dev->is_enabled)
584 return 0;
585
586 err = pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1); 630 err = pci_enable_device_bars(dev, (1 << PCI_NUM_RESOURCES) - 1);
587 if (err) 631 if (err)
588 return err; 632 return err;
589 pci_fixup_device(pci_fixup_enable, dev); 633 pci_fixup_device(pci_fixup_enable, dev);
590 dev->is_enabled = 1;
591 return 0; 634 return 0;
592} 635}
593 636
594/** 637/**
638 * pci_enable_device - Initialize device before it's used by a driver.
639 * @dev: PCI device to be initialized
640 *
641 * Initialize device before it's used by a driver. Ask low-level code
642 * to enable I/O and memory. Wake up the device if it was suspended.
643 * Beware, this function can fail.
644 *
645 * Note we don't actually enable the device many times if we call
646 * this function repeatedly (we just increment the count).
647 */
648int pci_enable_device(struct pci_dev *dev)
649{
650 int result;
651 if (atomic_add_return(1, &dev->enable_cnt) > 1)
652 return 0; /* already enabled */
653 result = __pci_enable_device(dev);
654 if (result < 0)
655 atomic_dec(&dev->enable_cnt);
656 return result;
657}
658
659/**
595 * pcibios_disable_device - disable arch specific PCI resources for device dev 660 * pcibios_disable_device - disable arch specific PCI resources for device dev
596 * @dev: the PCI device to disable 661 * @dev: the PCI device to disable
597 * 662 *
@@ -607,12 +672,18 @@ void __attribute__ ((weak)) pcibios_disable_device (struct pci_dev *dev) {}
607 * 672 *
608 * Signal to the system that the PCI device is not in use by the system 673 * Signal to the system that the PCI device is not in use by the system
609 * anymore. This only involves disabling PCI bus-mastering, if active. 674 * anymore. This only involves disabling PCI bus-mastering, if active.
675 *
676 * Note we don't actually disable the device until all callers of
677 * pci_device_enable() have called pci_device_disable().
610 */ 678 */
611void 679void
612pci_disable_device(struct pci_dev *dev) 680pci_disable_device(struct pci_dev *dev)
613{ 681{
614 u16 pci_command; 682 u16 pci_command;
615 683
684 if (atomic_sub_return(1, &dev->enable_cnt) != 0)
685 return;
686
616 if (dev->msi_enabled) 687 if (dev->msi_enabled)
617 disable_msi_mode(dev, pci_find_capability(dev, PCI_CAP_ID_MSI), 688 disable_msi_mode(dev, pci_find_capability(dev, PCI_CAP_ID_MSI),
618 PCI_CAP_ID_MSI); 689 PCI_CAP_ID_MSI);
@@ -628,7 +699,6 @@ pci_disable_device(struct pci_dev *dev)
628 dev->is_busmaster = 0; 699 dev->is_busmaster = 0;
629 700
630 pcibios_disable_device(dev); 701 pcibios_disable_device(dev);
631 dev->is_enabled = 0;
632} 702}
633 703
634/** 704/**
@@ -831,22 +901,38 @@ pci_set_master(struct pci_dev *dev)
831 pcibios_set_master(dev); 901 pcibios_set_master(dev);
832} 902}
833 903
834#ifndef HAVE_ARCH_PCI_MWI 904#ifdef PCI_DISABLE_MWI
905int pci_set_mwi(struct pci_dev *dev)
906{
907 return 0;
908}
909
910void pci_clear_mwi(struct pci_dev *dev)
911{
912}
913
914#else
915
916#ifndef PCI_CACHE_LINE_BYTES
917#define PCI_CACHE_LINE_BYTES L1_CACHE_BYTES
918#endif
919
835/* This can be overridden by arch code. */ 920/* This can be overridden by arch code. */
836u8 pci_cache_line_size = L1_CACHE_BYTES >> 2; 921/* Don't forget this is measured in 32-bit words, not bytes */
922u8 pci_cache_line_size = PCI_CACHE_LINE_BYTES / 4;
837 923
838/** 924/**
839 * pci_generic_prep_mwi - helper function for pci_set_mwi 925 * pci_set_cacheline_size - ensure the CACHE_LINE_SIZE register is programmed
840 * @dev: the PCI device for which MWI is enabled 926 * @dev: the PCI device for which MWI is to be enabled
841 * 927 *
842 * Helper function for generic implementation of pcibios_prep_mwi 928 * Helper function for pci_set_mwi.
843 * function. Originally copied from drivers/net/acenic.c. 929 * Originally copied from drivers/net/acenic.c.
844 * Copyright 1998-2001 by Jes Sorensen, <jes@trained-monkey.org>. 930 * Copyright 1998-2001 by Jes Sorensen, <jes@trained-monkey.org>.
845 * 931 *
846 * RETURNS: An appropriate -ERRNO error value on error, or zero for success. 932 * RETURNS: An appropriate -ERRNO error value on error, or zero for success.
847 */ 933 */
848static int 934static int
849pci_generic_prep_mwi(struct pci_dev *dev) 935pci_set_cacheline_size(struct pci_dev *dev)
850{ 936{
851 u8 cacheline_size; 937 u8 cacheline_size;
852 938
@@ -872,7 +958,6 @@ pci_generic_prep_mwi(struct pci_dev *dev)
872 958
873 return -EINVAL; 959 return -EINVAL;
874} 960}
875#endif /* !HAVE_ARCH_PCI_MWI */
876 961
877/** 962/**
878 * pci_set_mwi - enables memory-write-invalidate PCI transaction 963 * pci_set_mwi - enables memory-write-invalidate PCI transaction
@@ -890,12 +975,7 @@ pci_set_mwi(struct pci_dev *dev)
890 int rc; 975 int rc;
891 u16 cmd; 976 u16 cmd;
892 977
893#ifdef HAVE_ARCH_PCI_MWI 978 rc = pci_set_cacheline_size(dev);
894 rc = pcibios_prep_mwi(dev);
895#else
896 rc = pci_generic_prep_mwi(dev);
897#endif
898
899 if (rc) 979 if (rc)
900 return rc; 980 return rc;
901 981
@@ -926,6 +1006,7 @@ pci_clear_mwi(struct pci_dev *dev)
926 pci_write_config_word(dev, PCI_COMMAND, cmd); 1006 pci_write_config_word(dev, PCI_COMMAND, cmd);
927 } 1007 }
928} 1008}
1009#endif /* ! PCI_DISABLE_MWI */
929 1010
930/** 1011/**
931 * pci_intx - enables/disables PCI INTx for device dev 1012 * pci_intx - enables/disables PCI INTx for device dev