2626#include <linux/list.h>
2727#include <linux/module.h>
2828#include <linux/msi.h>
29- #include <linux/notifier.h>
3029#include <linux/of_irq.h>
3130#include <linux/pci-ecam.h>
3231
@@ -667,12 +666,16 @@ static struct apple_pcie_port *apple_pcie_get_port(struct pci_dev *pdev)
667666 return NULL ;
668667}
669668
670- static int apple_pcie_add_device (struct apple_pcie_port * port ,
671- struct pci_dev * pdev )
669+ static int apple_pcie_enable_device (struct pci_host_bridge * bridge , struct pci_dev * pdev )
672670{
673671 u32 sid , rid = pci_dev_id (pdev );
672+ struct apple_pcie_port * port ;
674673 int idx , err ;
675674
675+ port = apple_pcie_get_port (pdev );
676+ if (!port )
677+ return 0 ;
678+
676679 dev_dbg (& pdev -> dev , "added to bus %s, index %d\n" ,
677680 pci_name (pdev -> bus -> self ), port -> idx );
678681
@@ -698,12 +701,16 @@ static int apple_pcie_add_device(struct apple_pcie_port *port,
698701 return idx >= 0 ? 0 : - ENOSPC ;
699702}
700703
701- static void apple_pcie_release_device (struct apple_pcie_port * port ,
702- struct pci_dev * pdev )
704+ static void apple_pcie_disable_device (struct pci_host_bridge * bridge , struct pci_dev * pdev )
703705{
706+ struct apple_pcie_port * port ;
704707 u32 rid = pci_dev_id (pdev );
705708 int idx ;
706709
710+ port = apple_pcie_get_port (pdev );
711+ if (!port )
712+ return ;
713+
707714 mutex_lock (& port -> pcie -> lock );
708715
709716 for_each_set_bit (idx , port -> sid_map , port -> sid_map_sz ) {
@@ -721,45 +728,6 @@ static void apple_pcie_release_device(struct apple_pcie_port *port,
721728 mutex_unlock (& port -> pcie -> lock );
722729}
723730
724- static int apple_pcie_bus_notifier (struct notifier_block * nb ,
725- unsigned long action ,
726- void * data )
727- {
728- struct device * dev = data ;
729- struct pci_dev * pdev = to_pci_dev (dev );
730- struct apple_pcie_port * port ;
731- int err ;
732-
733- /*
734- * This is a bit ugly. We assume that if we get notified for
735- * any PCI device, we must be in charge of it, and that there
736- * is no other PCI controller in the whole system. It probably
737- * holds for now, but who knows for how long?
738- */
739- port = apple_pcie_get_port (pdev );
740- if (!port )
741- return NOTIFY_DONE ;
742-
743- switch (action ) {
744- case BUS_NOTIFY_ADD_DEVICE :
745- err = apple_pcie_add_device (port , pdev );
746- if (err )
747- return notifier_from_errno (err );
748- break ;
749- case BUS_NOTIFY_DEL_DEVICE :
750- apple_pcie_release_device (port , pdev );
751- break ;
752- default :
753- return NOTIFY_DONE ;
754- }
755-
756- return NOTIFY_OK ;
757- }
758-
759- static struct notifier_block apple_pcie_nb = {
760- .notifier_call = apple_pcie_bus_notifier ,
761- };
762-
763731static int apple_pcie_init (struct pci_config_window * cfg )
764732{
765733 struct device * dev = cfg -> parent ;
@@ -799,23 +767,10 @@ static int apple_pcie_init(struct pci_config_window *cfg)
799767 return 0 ;
800768}
801769
802- static int apple_pcie_probe (struct platform_device * pdev )
803- {
804- int ret ;
805-
806- ret = bus_register_notifier (& pci_bus_type , & apple_pcie_nb );
807- if (ret )
808- return ret ;
809-
810- ret = pci_host_common_probe (pdev );
811- if (ret )
812- bus_unregister_notifier (& pci_bus_type , & apple_pcie_nb );
813-
814- return ret ;
815- }
816-
817770static const struct pci_ecam_ops apple_pcie_cfg_ecam_ops = {
818771 .init = apple_pcie_init ,
772+ .enable_device = apple_pcie_enable_device ,
773+ .disable_device = apple_pcie_disable_device ,
819774 .pci_ops = {
820775 .map_bus = pci_ecam_map_bus ,
821776 .read = pci_generic_config_read ,
@@ -830,7 +785,7 @@ static const struct of_device_id apple_pcie_of_match[] = {
830785MODULE_DEVICE_TABLE (of , apple_pcie_of_match );
831786
832787static struct platform_driver apple_pcie_driver = {
833- .probe = apple_pcie_probe ,
788+ .probe = pci_host_common_probe ,
834789 .driver = {
835790 .name = "pcie-apple" ,
836791 .of_match_table = apple_pcie_of_match ,
0 commit comments