blob: f89376ff633e7d4871bfce755025656f2eb24117 [file] [log] [blame]
Thomas Gleixner2874c5f2019-05-27 08:55:01 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Benjamin Herrenschmidt7eebde72006-11-11 17:24:59 +11002/*
3 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp.
4 * <benh@kernel.crashing.org>
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +11005 * and Arnd Bergmann, IBM Corp.
Benjamin Herrenschmidt7eebde72006-11-11 17:24:59 +11006 */
7
8#undef DEBUG
9
10#include <linux/string.h>
11#include <linux/kernel.h>
12#include <linux/init.h>
Paul Gortmaker4b16f8e2011-07-22 18:24:23 -040013#include <linux/export.h>
Benjamin Herrenschmidt7eebde72006-11-11 17:24:59 +110014#include <linux/mod_devicetable.h>
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110015#include <linux/pci.h>
Grant Likely283029d2008-01-09 06:20:40 +110016#include <linux/of.h>
Stephen Rothwellcd6eed32007-09-21 18:08:17 +100017#include <linux/of_device.h>
18#include <linux/of_platform.h>
Gavin Shaneb740b52012-02-27 20:04:04 +000019#include <linux/atomic.h>
Benjamin Herrenschmidt7eebde72006-11-11 17:24:59 +110020
21#include <asm/errno.h>
Benjamin Herrenschmidt12d04ee2006-11-11 17:25:02 +110022#include <asm/topology.h>
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110023#include <asm/pci-bridge.h>
24#include <asm/ppc-pci.h>
Gavin Shaneb740b52012-02-27 20:04:04 +000025#include <asm/eeh.h>
Benjamin Herrenschmidt93091802006-11-21 14:56:37 +110026
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110027#ifdef CONFIG_PPC_OF_PLATFORM_PCI
28
29/* The probing of PCI controllers from of_platform is currently
30 * 64 bits only, mostly due to gratuitous differences between
31 * the 32 and 64 bits PCI code on PowerPC and the 32 bits one
32 * lacking some bits needed here.
33 */
34
Greg Kroah-Hartmancad5cef2012-12-21 14:04:10 -080035static int of_pci_phb_probe(struct platform_device *dev)
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110036{
37 struct pci_controller *phb;
38
39 /* Check if we can do that ... */
40 if (ppc_md.pci_setup_phb == NULL)
41 return -ENODEV;
42
Rob Herringb7c670d2017-08-21 10:16:47 -050043 pr_info("Setting up PCI bus %pOF\n", dev->dev.of_node);
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110044
45 /* Alloc and setup PHB data structure */
Grant Likely61c7a082010-04-13 16:12:29 -070046 phb = pcibios_alloc_controller(dev->dev.of_node);
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110047 if (!phb)
48 return -ENODEV;
49
50 /* Setup parent in sysfs */
51 phb->parent = &dev->dev;
52
53 /* Setup the PHB using arch provided callback */
54 if (ppc_md.pci_setup_phb(phb)) {
55 pcibios_free_controller(phb);
56 return -ENODEV;
57 }
58
59 /* Process "ranges" property */
Grant Likely61c7a082010-04-13 16:12:29 -070060 pci_process_bridge_OF_ranges(phb, dev->dev.of_node, 0);
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110061
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110062 /* Init pci_dn data structures */
63 pci_devs_phb_init_dynamic(phb);
64
Oliver O'Halloran475028e2020-07-25 18:12:18 +100065 /* Create EEH PE for the PHB */
66 eeh_phb_pe_create(phb);
Gavin Shaneb740b52012-02-27 20:04:04 +000067
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110068 /* Scan the bus */
Grant Likelyb5d937d2011-02-04 11:24:11 -070069 pcibios_scan_phb(phb);
Ishizaki Kou7cfb62a2008-04-24 19:21:10 +100070 if (phb->bus == NULL)
71 return -ENXIO;
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110072
73 /* Claim resources. This might need some rework as well depending
Adam Buchbinder48fc7f72012-09-19 21:48:00 -040074 * whether we are doing probe-only or not, like assigning unassigned
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110075 * resources etc...
76 */
77 pcibios_claim_one_bus(phb->bus);
78
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110079 /* Add probed PCI devices to the device model */
80 pci_bus_add_devices(phb->bus);
81
82 return 0;
83}
84
Uwe Kleine-Königce6d73c2014-09-10 21:56:38 +020085static const struct of_device_id of_pci_phb_ids[] = {
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +110086 { .type = "pci", },
87 { .type = "pcix", },
88 { .type = "pcie", },
89 { .type = "pciex", },
90 { .type = "ht", },
91 {}
92};
93
Grant Likely00006122011-02-22 19:59:54 -070094static struct platform_driver of_pci_phb_driver = {
Stephen Rothwellcd6eed32007-09-21 18:08:17 +100095 .probe = of_pci_phb_probe,
96 .driver = {
97 .name = "of-pci",
Grant Likely40182942010-04-13 16:13:02 -070098 .of_match_table = of_pci_phb_ids,
Stephen Rothwellcd6eed32007-09-21 18:08:17 +100099 },
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +1100100};
101
Geliang Tangebb242d2016-11-23 22:58:56 +0800102builtin_platform_driver(of_pci_phb_driver);
Benjamin Herrenschmidt4c9d2802006-11-11 17:25:08 +1100103
104#endif /* CONFIG_PPC_OF_PLATFORM_PCI */