hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/arch/powerpc/kernel/pci_of_scan.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Helper routines to scan the device tree for PCI devices and busses
34 *
....@@ -8,10 +9,6 @@
89 * Copyright (C) 2003 Anton Blanchard <anton@au.ibm.com>, IBM
910 * Rework, based on alpha PCI code.
1011 * Copyright (c) 2009 Secret Lab Technologies Ltd.
11
- *
12
- * This program is free software; you can redistribute it and/or
13
- * modify it under the terms of the GNU General Public License
14
- * version 2 as published by the Free Software Foundation.
1512 */
1613
1714 #include <linux/pci.h>
....@@ -37,31 +34,75 @@
3734 * pci_parse_of_flags - Parse the flags cell of a device tree PCI address
3835 * @addr0: value of 1st cell of a device tree PCI address.
3936 * @bridge: Set this flag if the address is from a bridge 'ranges' property
37
+ *
38
+ * PCI Bus Binding to IEEE Std 1275-1994
39
+ *
40
+ * Bit# 33222222 22221111 11111100 00000000
41
+ * 10987654 32109876 54321098 76543210
42
+ * phys.hi cell: npt000ss bbbbbbbb dddddfff rrrrrrrr
43
+ * phys.mid cell: hhhhhhhh hhhhhhhh hhhhhhhh hhhhhhhh
44
+ * phys.lo cell: llllllll llllllll llllllll llllllll
45
+ *
46
+ * where:
47
+ * n is 0 if the address is relocatable, 1 otherwise
48
+ * p is 1 if the addressable region is "prefetchable", 0 otherwise
49
+ * t is 1 if the address is aliased (for non-relocatable I/O),
50
+ * below 1 MB (for Memory),or below 64 KB (for relocatable I/O).
51
+ * ss is the space code, denoting the address space:
52
+ * 00 denotes Configuration Space
53
+ * 01 denotes I/O Space
54
+ * 10 denotes 32-bit-address Memory Space
55
+ * 11 denotes 64-bit-address Memory Space
56
+ * bbbbbbbb is the 8-bit Bus Number
57
+ * ddddd is the 5-bit Device Number
58
+ * fff is the 3-bit Function Number
59
+ * rrrrrrrr is the 8-bit Register Number
4060 */
61
+#define OF_PCI_ADDR0_SPACE(ss) (((ss)&3)<<24)
62
+#define OF_PCI_ADDR0_SPACE_CFG OF_PCI_ADDR0_SPACE(0)
63
+#define OF_PCI_ADDR0_SPACE_IO OF_PCI_ADDR0_SPACE(1)
64
+#define OF_PCI_ADDR0_SPACE_MMIO32 OF_PCI_ADDR0_SPACE(2)
65
+#define OF_PCI_ADDR0_SPACE_MMIO64 OF_PCI_ADDR0_SPACE(3)
66
+#define OF_PCI_ADDR0_SPACE_MASK OF_PCI_ADDR0_SPACE(3)
67
+#define OF_PCI_ADDR0_RELOC (1UL<<31)
68
+#define OF_PCI_ADDR0_PREFETCH (1UL<<30)
69
+#define OF_PCI_ADDR0_ALIAS (1UL<<29)
70
+#define OF_PCI_ADDR0_BUS 0x00FF0000UL
71
+#define OF_PCI_ADDR0_DEV 0x0000F800UL
72
+#define OF_PCI_ADDR0_FN 0x00000700UL
73
+#define OF_PCI_ADDR0_BARREG 0x000000FFUL
74
+
4175 unsigned int pci_parse_of_flags(u32 addr0, int bridge)
4276 {
43
- unsigned int flags = 0;
77
+ unsigned int flags = 0, as = addr0 & OF_PCI_ADDR0_SPACE_MASK;
4478
45
- if (addr0 & 0x02000000) {
79
+ if (as == OF_PCI_ADDR0_SPACE_MMIO32 || as == OF_PCI_ADDR0_SPACE_MMIO64) {
4680 flags = IORESOURCE_MEM | PCI_BASE_ADDRESS_SPACE_MEMORY;
47
- flags |= (addr0 >> 22) & PCI_BASE_ADDRESS_MEM_TYPE_64;
48
- if (flags & PCI_BASE_ADDRESS_MEM_TYPE_64)
49
- flags |= IORESOURCE_MEM_64;
50
- flags |= (addr0 >> 28) & PCI_BASE_ADDRESS_MEM_TYPE_1M;
51
- if (addr0 & 0x40000000)
52
- flags |= IORESOURCE_PREFETCH
53
- | PCI_BASE_ADDRESS_MEM_PREFETCH;
81
+
82
+ if (as == OF_PCI_ADDR0_SPACE_MMIO64)
83
+ flags |= PCI_BASE_ADDRESS_MEM_TYPE_64 | IORESOURCE_MEM_64;
84
+
85
+ if (addr0 & OF_PCI_ADDR0_ALIAS)
86
+ flags |= PCI_BASE_ADDRESS_MEM_TYPE_1M;
87
+
88
+ if (addr0 & OF_PCI_ADDR0_PREFETCH)
89
+ flags |= IORESOURCE_PREFETCH |
90
+ PCI_BASE_ADDRESS_MEM_PREFETCH;
91
+
5492 /* Note: We don't know whether the ROM has been left enabled
5593 * by the firmware or not. We mark it as disabled (ie, we do
5694 * not set the IORESOURCE_ROM_ENABLE flag) for now rather than
5795 * do a config space read, it will be force-enabled if needed
5896 */
59
- if (!bridge && (addr0 & 0xff) == 0x30)
97
+ if (!bridge && (addr0 & OF_PCI_ADDR0_BARREG) == PCI_ROM_ADDRESS)
6098 flags |= IORESOURCE_READONLY;
61
- } else if (addr0 & 0x01000000)
99
+
100
+ } else if (as == OF_PCI_ADDR0_SPACE_IO)
62101 flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO;
102
+
63103 if (flags)
64104 flags |= IORESOURCE_SIZEALIGN;
105
+
65106 return flags;
66107 }
67108
....@@ -135,16 +176,13 @@
135176 struct pci_bus *bus, int devfn)
136177 {
137178 struct pci_dev *dev;
138
- const char *type;
139179
140180 dev = pci_alloc_dev(bus);
141181 if (!dev)
142182 return NULL;
143
- type = of_get_property(node, "device_type", NULL);
144
- if (type == NULL)
145
- type = "";
146183
147
- pr_debug(" create device, devfn: %x, type: %s\n", devfn, type);
184
+ pr_debug(" create device, devfn: %x, type: %s\n", devfn,
185
+ of_node_get_device_type(node));
148186
149187 dev->dev.of_node = of_node_get(node);
150188 dev->dev.parent = bus->bridge;
....@@ -177,12 +215,12 @@
177215 /* Early fixups, before probing the BARs */
178216 pci_fixup_device(pci_fixup_early, dev);
179217
180
- if (!strcmp(type, "pci") || !strcmp(type, "pciex")) {
218
+ if (of_node_is_type(node, "pci") || of_node_is_type(node, "pciex")) {
181219 /* a PCI-PCI bridge */
182220 dev->hdr_type = PCI_HEADER_TYPE_BRIDGE;
183221 dev->rom_base_reg = PCI_ROM_ADDRESS1;
184222 set_pcie_hotplug_bridge(dev);
185
- } else if (!strcmp(type, "cardbus")) {
223
+ } else if (of_node_is_type(node, "cardbus")) {
186224 dev->hdr_type = PCI_HEADER_TYPE_CARDBUS;
187225 } else {
188226 dev->hdr_type = PCI_HEADER_TYPE_NORMAL;
....@@ -376,7 +414,6 @@
376414 */
377415 if (!rescan_existing)
378416 pcibios_setup_bus_self(bus);
379
- pcibios_setup_bus_devices(bus);
380417
381418 /* Now scan child busses */
382419 for_each_pci_bridge(dev, bus)