.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
---|
1 | 2 | /* |
---|
2 | 3 | * Contains common pci routines for ALL ppc platform |
---|
3 | 4 | * (based on pci_32.c and pci_64.c) |
---|
.. | .. |
---|
9 | 10 | * Rework, based on alpha PCI code. |
---|
10 | 11 | * |
---|
11 | 12 | * 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. |
---|
17 | 13 | */ |
---|
18 | 14 | |
---|
19 | 15 | #include <linux/kernel.h> |
---|
.. | .. |
---|
32 | 28 | #include <linux/vmalloc.h> |
---|
33 | 29 | #include <linux/slab.h> |
---|
34 | 30 | #include <linux/vgaarb.h> |
---|
| 31 | +#include <linux/numa.h> |
---|
35 | 32 | |
---|
36 | 33 | #include <asm/processor.h> |
---|
37 | 34 | #include <asm/io.h> |
---|
.. | .. |
---|
62 | 59 | EXPORT_SYMBOL(isa_mem_base); |
---|
63 | 60 | |
---|
64 | 61 | |
---|
65 | | -static const struct dma_map_ops *pci_dma_ops = &dma_nommu_ops; |
---|
| 62 | +static const struct dma_map_ops *pci_dma_ops; |
---|
66 | 63 | |
---|
67 | 64 | void set_pci_dma_ops(const struct dma_map_ops *dma_ops) |
---|
68 | 65 | { |
---|
69 | 66 | pci_dma_ops = dma_ops; |
---|
70 | 67 | } |
---|
71 | 68 | |
---|
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 | | - */ |
---|
82 | 69 | static int get_phb_number(struct device_node *dn) |
---|
83 | 70 | { |
---|
84 | 71 | int ret, phb_id = -1; |
---|
85 | | - u32 prop_32; |
---|
86 | 72 | u64 prop; |
---|
87 | 73 | |
---|
88 | 74 | /* |
---|
89 | 75 | * 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. |
---|
92 | 80 | */ |
---|
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 | + |
---|
94 | 89 | 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; |
---|
95 | 98 | ret = of_property_read_u32_index(dn, "reg", 1, &prop_32); |
---|
96 | 99 | prop = prop_32; |
---|
97 | 100 | } |
---|
.. | .. |
---|
99 | 102 | if (!ret) |
---|
100 | 103 | phb_id = (int)(prop & (MAX_PHBS - 1)); |
---|
101 | 104 | |
---|
| 105 | + spin_lock(&hose_spinlock); |
---|
| 106 | + |
---|
102 | 107 | /* We need to be sure to not use the same PHB number twice. */ |
---|
103 | 108 | if ((phb_id >= 0) && !test_and_set_bit(phb_id, phb_bitmap)) |
---|
104 | | - return phb_id; |
---|
| 109 | + goto out_unlock; |
---|
105 | 110 | |
---|
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. */ |
---|
110 | 112 | phb_id = find_first_zero_bit(phb_bitmap, MAX_PHBS); |
---|
111 | 113 | BUG_ON(phb_id >= MAX_PHBS); |
---|
112 | 114 | set_bit(phb_id, phb_bitmap); |
---|
| 115 | + |
---|
| 116 | +out_unlock: |
---|
| 117 | + spin_unlock(&hose_spinlock); |
---|
113 | 118 | |
---|
114 | 119 | return phb_id; |
---|
115 | 120 | } |
---|
.. | .. |
---|
121 | 126 | phb = zalloc_maybe_bootmem(sizeof(struct pci_controller), GFP_KERNEL); |
---|
122 | 127 | if (phb == NULL) |
---|
123 | 128 | return NULL; |
---|
124 | | - spin_lock(&hose_spinlock); |
---|
| 129 | + |
---|
125 | 130 | phb->global_number = get_phb_number(dev); |
---|
| 131 | + |
---|
| 132 | + spin_lock(&hose_spinlock); |
---|
126 | 133 | list_add_tail(&phb->list_node, &hose_list); |
---|
127 | 134 | spin_unlock(&hose_spinlock); |
---|
| 135 | + |
---|
128 | 136 | phb->dn = dev; |
---|
129 | 137 | phb->is_dynamic = slab_is_available(); |
---|
130 | 138 | #ifdef CONFIG_PPC64 |
---|
.. | .. |
---|
132 | 140 | int nid = of_node_to_nid(dev); |
---|
133 | 141 | |
---|
134 | 142 | if (nid < 0 || !node_online(nid)) |
---|
135 | | - nid = -1; |
---|
| 143 | + nid = NUMA_NO_NODE; |
---|
136 | 144 | |
---|
137 | 145 | PHB_SET_NODE(phb, nid); |
---|
138 | 146 | } |
---|
.. | .. |
---|
270 | 278 | |
---|
271 | 279 | #endif /* CONFIG_PCI_IOV */ |
---|
272 | 280 | |
---|
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 | | - |
---|
279 | 281 | static resource_size_t pcibios_io_size(const struct pci_controller *hose) |
---|
280 | 282 | { |
---|
281 | 283 | #ifdef CONFIG_PPC64 |
---|
.. | .. |
---|
354 | 356 | return hose; |
---|
355 | 357 | node = node->parent; |
---|
356 | 358 | } |
---|
| 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 | + |
---|
357 | 370 | return NULL; |
---|
358 | 371 | } |
---|
359 | 372 | |
---|
.. | .. |
---|
732 | 745 | " MEM 0x%016llx..0x%016llx -> 0x%016llx %s\n", |
---|
733 | 746 | range.cpu_addr, range.cpu_addr + range.size - 1, |
---|
734 | 747 | range.pci_addr, |
---|
735 | | - (range.pci_space & 0x40000000) ? |
---|
| 748 | + (range.flags & IORESOURCE_PREFETCH) ? |
---|
736 | 749 | "Prefetch" : ""); |
---|
737 | 750 | |
---|
738 | 751 | /* We support only 3 memory ranges */ |
---|
.. | .. |
---|
962 | 975 | phb->controller_ops.dma_bus_setup(bus); |
---|
963 | 976 | } |
---|
964 | 977 | |
---|
965 | | -static void pcibios_setup_device(struct pci_dev *dev) |
---|
| 978 | +void pcibios_bus_add_device(struct pci_dev *dev) |
---|
966 | 979 | { |
---|
967 | 980 | struct pci_controller *phb; |
---|
968 | 981 | /* Fixup NUMA node as it may not be setup yet by the generic |
---|
.. | .. |
---|
972 | 985 | |
---|
973 | 986 | /* Hook up default DMA ops */ |
---|
974 | 987 | 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; |
---|
976 | 989 | |
---|
977 | 990 | /* Additional platform DMA/iommu setup */ |
---|
978 | 991 | phb = pci_bus_to_host(dev->bus); |
---|
.. | .. |
---|
983 | 996 | pci_read_irq_line(dev); |
---|
984 | 997 | if (ppc_md.pci_irq_fixup) |
---|
985 | 998 | ppc_md.pci_irq_fixup(dev); |
---|
| 999 | + |
---|
| 1000 | + if (ppc_md.pcibios_bus_add_device) |
---|
| 1001 | + ppc_md.pcibios_bus_add_device(dev); |
---|
986 | 1002 | } |
---|
987 | 1003 | |
---|
988 | 1004 | int pcibios_add_device(struct pci_dev *dev) |
---|
989 | 1005 | { |
---|
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 | | - |
---|
997 | 1006 | #ifdef CONFIG_PCI_IOV |
---|
998 | 1007 | if (ppc_md.pcibios_fixup_sriov) |
---|
999 | 1008 | ppc_md.pcibios_fixup_sriov(dev); |
---|
1000 | 1009 | #endif /* CONFIG_PCI_IOV */ |
---|
1001 | 1010 | |
---|
1002 | 1011 | 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 | | - } |
---|
1021 | 1012 | } |
---|
1022 | 1013 | |
---|
1023 | 1014 | void pcibios_set_master(struct pci_dev *dev) |
---|
.. | .. |
---|
1035 | 1026 | |
---|
1036 | 1027 | /* Now fixup the bus bus */ |
---|
1037 | 1028 | pcibios_setup_bus_self(bus); |
---|
1038 | | - |
---|
1039 | | - /* Now fixup devices on that bus */ |
---|
1040 | | - pcibios_setup_bus_devices(bus); |
---|
1041 | 1029 | } |
---|
1042 | 1030 | 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 | | - |
---|
1050 | 1031 | |
---|
1051 | 1032 | static int skip_isa_ioresource_align(struct pci_dev *dev) |
---|
1052 | 1033 | { |
---|
.. | .. |
---|
1377 | 1358 | pr_debug("PCI: Assigning unassigned resources...\n"); |
---|
1378 | 1359 | pci_assign_unassigned_resources(); |
---|
1379 | 1360 | } |
---|
1380 | | - |
---|
1381 | | - /* Call machine dependent fixup */ |
---|
1382 | | - if (ppc_md.pcibios_fixup) |
---|
1383 | | - ppc_md.pcibios_fixup(); |
---|
1384 | 1361 | } |
---|
1385 | 1362 | |
---|
1386 | 1363 | /* This is used by the PCI hotplug driver to allocate resource |
---|
.. | .. |
---|
1439 | 1416 | pci_assign_unassigned_bus_resources(bus); |
---|
1440 | 1417 | } |
---|
1441 | 1418 | |
---|
1442 | | - /* Fixup EEH */ |
---|
1443 | | - eeh_add_device_tree_late(bus); |
---|
1444 | | - |
---|
1445 | 1419 | /* Add new devices to global lists. Register in proc, sysfs. */ |
---|
1446 | 1420 | pci_bus_add_devices(bus); |
---|
1447 | | - |
---|
1448 | | - /* sysfs files should only be added after devices are added */ |
---|
1449 | | - eeh_add_sysfs_files(bus); |
---|
1450 | 1421 | } |
---|
1451 | 1422 | EXPORT_SYMBOL_GPL(pcibios_finish_adding_to_bus); |
---|
1452 | 1423 | |
---|