hc
2024-05-10 cde9070d9970eef1f7ec2360586c802a16230ad8
kernel/arch/powerpc/kernel/pci-common.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Contains common pci routines for ALL ppc platform
34 * (based on pci_32.c and pci_64.c)
....@@ -9,11 +10,6 @@
910 * Rework, based on alpha PCI code.
1011 *
1112 * Common pmac/prep/chrp pci routines. -- Cort
12
- *
13
- * This program is free software; you can redistribute it and/or
14
- * modify it under the terms of the GNU General Public License
15
- * as published by the Free Software Foundation; either version
16
- * 2 of the License, or (at your option) any later version.
1713 */
1814
1915 #include <linux/kernel.h>
....@@ -32,6 +28,7 @@
3228 #include <linux/vmalloc.h>
3329 #include <linux/slab.h>
3430 #include <linux/vgaarb.h>
31
+#include <linux/numa.h>
3532
3633 #include <asm/processor.h>
3734 #include <asm/io.h>
....@@ -62,36 +59,42 @@
6259 EXPORT_SYMBOL(isa_mem_base);
6360
6461
65
-static const struct dma_map_ops *pci_dma_ops = &dma_nommu_ops;
62
+static const struct dma_map_ops *pci_dma_ops;
6663
6764 void set_pci_dma_ops(const struct dma_map_ops *dma_ops)
6865 {
6966 pci_dma_ops = dma_ops;
7067 }
7168
72
-const struct dma_map_ops *get_pci_dma_ops(void)
73
-{
74
- return pci_dma_ops;
75
-}
76
-EXPORT_SYMBOL(get_pci_dma_ops);
77
-
78
-/*
79
- * This function should run under locking protection, specifically
80
- * hose_spinlock.
81
- */
8269 static int get_phb_number(struct device_node *dn)
8370 {
8471 int ret, phb_id = -1;
85
- u32 prop_32;
8672 u64 prop;
8773
8874 /*
8975 * Try fixed PHB numbering first, by checking archs and reading
90
- * the respective device-tree properties. Firstly, try powernv by
91
- * reading "ibm,opal-phbid", only present in OPAL environment.
76
+ * the respective device-tree properties. Firstly, try reading
77
+ * standard "linux,pci-domain", then try reading "ibm,opal-phbid"
78
+ * (only present in powernv OPAL environment), then try device-tree
79
+ * alias and as the last try to use lower bits of "reg" property.
9280 */
93
- ret = of_property_read_u64(dn, "ibm,opal-phbid", &prop);
81
+ ret = of_get_pci_domain_nr(dn);
82
+ if (ret >= 0) {
83
+ prop = ret;
84
+ ret = 0;
85
+ }
86
+ if (ret)
87
+ ret = of_property_read_u64(dn, "ibm,opal-phbid", &prop);
88
+
9489 if (ret) {
90
+ ret = of_alias_get_id(dn, "pci");
91
+ if (ret >= 0) {
92
+ prop = ret;
93
+ ret = 0;
94
+ }
95
+ }
96
+ if (ret) {
97
+ u32 prop_32;
9598 ret = of_property_read_u32_index(dn, "reg", 1, &prop_32);
9699 prop = prop_32;
97100 }
....@@ -99,17 +102,19 @@
99102 if (!ret)
100103 phb_id = (int)(prop & (MAX_PHBS - 1));
101104
105
+ spin_lock(&hose_spinlock);
106
+
102107 /* We need to be sure to not use the same PHB number twice. */
103108 if ((phb_id >= 0) && !test_and_set_bit(phb_id, phb_bitmap))
104
- return phb_id;
109
+ goto out_unlock;
105110
106
- /*
107
- * If not pseries nor powernv, or if fixed PHB numbering tried to add
108
- * the same PHB number twice, then fallback to dynamic PHB numbering.
109
- */
111
+ /* If everything fails then fallback to dynamic PHB numbering. */
110112 phb_id = find_first_zero_bit(phb_bitmap, MAX_PHBS);
111113 BUG_ON(phb_id >= MAX_PHBS);
112114 set_bit(phb_id, phb_bitmap);
115
+
116
+out_unlock:
117
+ spin_unlock(&hose_spinlock);
113118
114119 return phb_id;
115120 }
....@@ -121,10 +126,13 @@
121126 phb = zalloc_maybe_bootmem(sizeof(struct pci_controller), GFP_KERNEL);
122127 if (phb == NULL)
123128 return NULL;
124
- spin_lock(&hose_spinlock);
129
+
125130 phb->global_number = get_phb_number(dev);
131
+
132
+ spin_lock(&hose_spinlock);
126133 list_add_tail(&phb->list_node, &hose_list);
127134 spin_unlock(&hose_spinlock);
135
+
128136 phb->dn = dev;
129137 phb->is_dynamic = slab_is_available();
130138 #ifdef CONFIG_PPC64
....@@ -132,7 +140,7 @@
132140 int nid = of_node_to_nid(dev);
133141
134142 if (nid < 0 || !node_online(nid))
135
- nid = -1;
143
+ nid = NUMA_NO_NODE;
136144
137145 PHB_SET_NODE(phb, nid);
138146 }
....@@ -270,12 +278,6 @@
270278
271279 #endif /* CONFIG_PCI_IOV */
272280
273
-void pcibios_bus_add_device(struct pci_dev *pdev)
274
-{
275
- if (ppc_md.pcibios_bus_add_device)
276
- ppc_md.pcibios_bus_add_device(pdev);
277
-}
278
-
279281 static resource_size_t pcibios_io_size(const struct pci_controller *hose)
280282 {
281283 #ifdef CONFIG_PPC64
....@@ -354,6 +356,17 @@
354356 return hose;
355357 node = node->parent;
356358 }
359
+ return NULL;
360
+}
361
+
362
+struct pci_controller *pci_find_controller_for_domain(int domain_nr)
363
+{
364
+ struct pci_controller *hose;
365
+
366
+ list_for_each_entry(hose, &hose_list, list_node)
367
+ if (hose->global_number == domain_nr)
368
+ return hose;
369
+
357370 return NULL;
358371 }
359372
....@@ -732,7 +745,7 @@
732745 " MEM 0x%016llx..0x%016llx -> 0x%016llx %s\n",
733746 range.cpu_addr, range.cpu_addr + range.size - 1,
734747 range.pci_addr,
735
- (range.pci_space & 0x40000000) ?
748
+ (range.flags & IORESOURCE_PREFETCH) ?
736749 "Prefetch" : "");
737750
738751 /* We support only 3 memory ranges */
....@@ -962,7 +975,7 @@
962975 phb->controller_ops.dma_bus_setup(bus);
963976 }
964977
965
-static void pcibios_setup_device(struct pci_dev *dev)
978
+void pcibios_bus_add_device(struct pci_dev *dev)
966979 {
967980 struct pci_controller *phb;
968981 /* Fixup NUMA node as it may not be setup yet by the generic
....@@ -972,7 +985,7 @@
972985
973986 /* Hook up default DMA ops */
974987 set_dma_ops(&dev->dev, pci_dma_ops);
975
- set_dma_offset(&dev->dev, PCI_DRAM_OFFSET);
988
+ dev->dev.archdata.dma_offset = PCI_DRAM_OFFSET;
976989
977990 /* Additional platform DMA/iommu setup */
978991 phb = pci_bus_to_host(dev->bus);
....@@ -983,41 +996,19 @@
983996 pci_read_irq_line(dev);
984997 if (ppc_md.pci_irq_fixup)
985998 ppc_md.pci_irq_fixup(dev);
999
+
1000
+ if (ppc_md.pcibios_bus_add_device)
1001
+ ppc_md.pcibios_bus_add_device(dev);
9861002 }
9871003
9881004 int pcibios_add_device(struct pci_dev *dev)
9891005 {
990
- /*
991
- * We can only call pcibios_setup_device() after bus setup is complete,
992
- * since some of the platform specific DMA setup code depends on it.
993
- */
994
- if (dev->bus->is_added)
995
- pcibios_setup_device(dev);
996
-
9971006 #ifdef CONFIG_PCI_IOV
9981007 if (ppc_md.pcibios_fixup_sriov)
9991008 ppc_md.pcibios_fixup_sriov(dev);
10001009 #endif /* CONFIG_PCI_IOV */
10011010
10021011 return 0;
1003
-}
1004
-
1005
-void pcibios_setup_bus_devices(struct pci_bus *bus)
1006
-{
1007
- struct pci_dev *dev;
1008
-
1009
- pr_debug("PCI: Fixup bus devices %d (%s)\n",
1010
- bus->number, bus->self ? pci_name(bus->self) : "PHB");
1011
-
1012
- list_for_each_entry(dev, &bus->devices, bus_list) {
1013
- /* Cardbus can call us to add new devices to a bus, so ignore
1014
- * those who are already fully discovered
1015
- */
1016
- if (pci_dev_is_added(dev))
1017
- continue;
1018
-
1019
- pcibios_setup_device(dev);
1020
- }
10211012 }
10221013
10231014 void pcibios_set_master(struct pci_dev *dev)
....@@ -1035,18 +1026,8 @@
10351026
10361027 /* Now fixup the bus bus */
10371028 pcibios_setup_bus_self(bus);
1038
-
1039
- /* Now fixup devices on that bus */
1040
- pcibios_setup_bus_devices(bus);
10411029 }
10421030 EXPORT_SYMBOL(pcibios_fixup_bus);
1043
-
1044
-void pci_fixup_cardbus(struct pci_bus *bus)
1045
-{
1046
- /* Now fixup devices on that bus */
1047
- pcibios_setup_bus_devices(bus);
1048
-}
1049
-
10501031
10511032 static int skip_isa_ioresource_align(struct pci_dev *dev)
10521033 {
....@@ -1377,10 +1358,6 @@
13771358 pr_debug("PCI: Assigning unassigned resources...\n");
13781359 pci_assign_unassigned_resources();
13791360 }
1380
-
1381
- /* Call machine dependent fixup */
1382
- if (ppc_md.pcibios_fixup)
1383
- ppc_md.pcibios_fixup();
13841361 }
13851362
13861363 /* This is used by the PCI hotplug driver to allocate resource
....@@ -1439,14 +1416,8 @@
14391416 pci_assign_unassigned_bus_resources(bus);
14401417 }
14411418
1442
- /* Fixup EEH */
1443
- eeh_add_device_tree_late(bus);
1444
-
14451419 /* Add new devices to global lists. Register in proc, sysfs. */
14461420 pci_bus_add_devices(bus);
1447
-
1448
- /* sysfs files should only be added after devices are added */
1449
- eeh_add_sysfs_files(bus);
14501421 }
14511422 EXPORT_SYMBOL_GPL(pcibios_finish_adding_to_bus);
14521423