Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *    Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
0004  *           <benh@kernel.crashing.org>
0005  *    and        Arnd Bergmann, IBM Corp.
0006  */
0007 
0008 #undef DEBUG
0009 
0010 #include <linux/string.h>
0011 #include <linux/kernel.h>
0012 #include <linux/init.h>
0013 #include <linux/export.h>
0014 #include <linux/mod_devicetable.h>
0015 #include <linux/pci.h>
0016 #include <linux/of.h>
0017 #include <linux/of_device.h>
0018 #include <linux/of_platform.h>
0019 #include <linux/atomic.h>
0020 
0021 #include <asm/errno.h>
0022 #include <asm/topology.h>
0023 #include <asm/pci-bridge.h>
0024 #include <asm/ppc-pci.h>
0025 #include <asm/eeh.h>
0026 
0027 #ifdef CONFIG_PPC_OF_PLATFORM_PCI
0028 
0029 /* The probing of PCI controllers from of_platform is currently
0030  * 64 bits only, mostly due to gratuitous differences between
0031  * the 32 and 64 bits PCI code on PowerPC and the 32 bits one
0032  * lacking some bits needed here.
0033  */
0034 
0035 static int of_pci_phb_probe(struct platform_device *dev)
0036 {
0037     struct pci_controller *phb;
0038 
0039     /* Check if we can do that ... */
0040     if (ppc_md.pci_setup_phb == NULL)
0041         return -ENODEV;
0042 
0043     pr_info("Setting up PCI bus %pOF\n", dev->dev.of_node);
0044 
0045     /* Alloc and setup PHB data structure */
0046     phb = pcibios_alloc_controller(dev->dev.of_node);
0047     if (!phb)
0048         return -ENODEV;
0049 
0050     /* Setup parent in sysfs */
0051     phb->parent = &dev->dev;
0052 
0053     /* Setup the PHB using arch provided callback */
0054     if (ppc_md.pci_setup_phb(phb)) {
0055         pcibios_free_controller(phb);
0056         return -ENODEV;
0057     }
0058 
0059     /* Process "ranges" property */
0060     pci_process_bridge_OF_ranges(phb, dev->dev.of_node, 0);
0061 
0062     /* Init pci_dn data structures */
0063     pci_devs_phb_init_dynamic(phb);
0064 
0065     /* Create EEH PE for the PHB */
0066     eeh_phb_pe_create(phb);
0067 
0068     /* Scan the bus */
0069     pcibios_scan_phb(phb);
0070     if (phb->bus == NULL)
0071         return -ENXIO;
0072 
0073     /* Claim resources. This might need some rework as well depending
0074      * whether we are doing probe-only or not, like assigning unassigned
0075      * resources etc...
0076      */
0077     pcibios_claim_one_bus(phb->bus);
0078 
0079     /* Add probed PCI devices to the device model */
0080     pci_bus_add_devices(phb->bus);
0081 
0082     return 0;
0083 }
0084 
0085 static const struct of_device_id of_pci_phb_ids[] = {
0086     { .type = "pci", },
0087     { .type = "pcix", },
0088     { .type = "pcie", },
0089     { .type = "pciex", },
0090     { .type = "ht", },
0091     {}
0092 };
0093 
0094 static struct platform_driver of_pci_phb_driver = {
0095     .probe = of_pci_phb_probe,
0096     .driver = {
0097         .name = "of-pci",
0098         .of_match_table = of_pci_phb_ids,
0099     },
0100 };
0101 
0102 builtin_platform_driver(of_pci_phb_driver);
0103 
0104 #endif /* CONFIG_PPC_OF_PLATFORM_PCI */