aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2011-02-04 13:24:11 -0500
committerGrant Likely <grant.likely@secretlab.ca>2011-02-04 13:46:51 -0500
commitb5d937de0367d26f65b9af1aef5f2c34c1939be0 (patch)
treee91eaaa72ef1aae543a1fa494171f7e3c0c14d94 /arch
parent04bea68b2f0eeebb089ecc67b618795925268b4a (diff)
powerpc/pci: Make both ppc32 and ppc64 use sysdata for pci_controller
Currently, ppc32 uses sysdata for the pci_controller pointer, and ppc64 uses it to hold the device_node pointer. This patch moves the of_node pointer into (struct pci_bus*)->dev.of_node and (struct pci_dev*)->dev.of_node so that sysdata can be converted to always use the pci_controller pointer instead. It also fixes up the allocating of pci devices so that the of_node pointer gets assigned consistently and increments the ref count. Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'arch')
-rw-r--r--arch/microblaze/pci/pci_32.c1
-rw-r--r--arch/powerpc/include/asm/pci-bridge.h27
-rw-r--r--arch/powerpc/include/asm/pci.h2
-rw-r--r--arch/powerpc/kernel/of_platform.c2
-rw-r--r--arch/powerpc/kernel/pci-common.c11
-rw-r--r--arch/powerpc/kernel/pci_32.c2
-rw-r--r--arch/powerpc/kernel/pci_64.c6
-rw-r--r--arch/powerpc/kernel/pci_dn.c9
-rw-r--r--arch/powerpc/kernel/pci_of_scan.c4
-rw-r--r--arch/powerpc/platforms/pseries/pci_dlpar.c2
10 files changed, 24 insertions, 42 deletions
diff --git a/arch/microblaze/pci/pci_32.c b/arch/microblaze/pci/pci_32.c
index 3c3d808d7ce0..92728a6cfd80 100644
--- a/arch/microblaze/pci/pci_32.c
+++ b/arch/microblaze/pci/pci_32.c
@@ -332,6 +332,7 @@ static void __devinit pcibios_scan_phb(struct pci_controller *hose)
332 hose->global_number); 332 hose->global_number);
333 return; 333 return;
334 } 334 }
335 bus.dev->of_node = of_node_get(node);
335 bus->secondary = hose->first_busno; 336 bus->secondary = hose->first_busno;
336 hose->bus = bus; 337 hose->bus = bus;
337 338
diff --git a/arch/powerpc/include/asm/pci-bridge.h b/arch/powerpc/include/asm/pci-bridge.h
index edeb80fdd2c3..5e156e034fe2 100644
--- a/arch/powerpc/include/asm/pci-bridge.h
+++ b/arch/powerpc/include/asm/pci-bridge.h
@@ -164,13 +164,13 @@ extern void setup_indirect_pci(struct pci_controller* hose,
164 resource_size_t cfg_addr, 164 resource_size_t cfg_addr,
165 resource_size_t cfg_data, u32 flags); 165 resource_size_t cfg_data, u32 flags);
166 166
167#ifndef CONFIG_PPC64
168
169static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus) 167static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
170{ 168{
171 return bus->sysdata; 169 return bus->sysdata;
172} 170}
173 171
172#ifndef CONFIG_PPC64
173
174static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus) 174static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
175{ 175{
176 struct pci_controller *host; 176 struct pci_controller *host;
@@ -228,19 +228,10 @@ extern void * update_dn_pci_info(struct device_node *dn, void *data);
228 228
229/* Get a device_node from a pci_dev. This code must be fast except 229/* Get a device_node from a pci_dev. This code must be fast except
230 * in the case where the sysdata is incorrect and needs to be fixed 230 * in the case where the sysdata is incorrect and needs to be fixed
231 * up (this will only happen once). 231 * up (this will only happen once). */
232 * In this case the sysdata will have been inherited from a PCI host
233 * bridge or a PCI-PCI bridge further up the tree, so it will point
234 * to a valid struct pci_dn, just not the one we want.
235 */
236static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev) 232static inline struct device_node *pci_device_to_OF_node(struct pci_dev *dev)
237{ 233{
238 struct device_node *dn = dev->sysdata; 234 return dev->dev.of_node ? dev->dev.of_node : fetch_dev_dn(dev);
239 struct pci_dn *pdn = dn->data;
240
241 if (pdn && pdn->devfn == dev->devfn && pdn->busno == dev->bus->number)
242 return dn; /* fast path. sysdata is good */
243 return fetch_dev_dn(dev);
244} 235}
245 236
246static inline int pci_device_from_OF_node(struct device_node *np, 237static inline int pci_device_from_OF_node(struct device_node *np,
@@ -258,7 +249,7 @@ static inline struct device_node *pci_bus_to_OF_node(struct pci_bus *bus)
258 if (bus->self) 249 if (bus->self)
259 return pci_device_to_OF_node(bus->self); 250 return pci_device_to_OF_node(bus->self);
260 else 251 else
261 return bus->sysdata; /* Must be root bus (PHB) */ 252 return bus->dev.of_node; /* Must be root bus (PHB) */
262} 253}
263 254
264/** Find the bus corresponding to the indicated device node */ 255/** Find the bus corresponding to the indicated device node */
@@ -270,14 +261,6 @@ extern void pcibios_remove_pci_devices(struct pci_bus *bus);
270/** Discover new pci devices under this bus, and add them */ 261/** Discover new pci devices under this bus, and add them */
271extern void pcibios_add_pci_devices(struct pci_bus *bus); 262extern void pcibios_add_pci_devices(struct pci_bus *bus);
272 263
273static inline struct pci_controller *pci_bus_to_host(const struct pci_bus *bus)
274{
275 struct device_node *busdn = bus->sysdata;
276
277 BUG_ON(busdn == NULL);
278 return PCI_DN(busdn)->phb;
279}
280
281 264
282extern void isa_bridge_find_early(struct pci_controller *hose); 265extern void isa_bridge_find_early(struct pci_controller *hose);
283 266
diff --git a/arch/powerpc/include/asm/pci.h b/arch/powerpc/include/asm/pci.h
index a20a9ad2258b..7d7790954e02 100644
--- a/arch/powerpc/include/asm/pci.h
+++ b/arch/powerpc/include/asm/pci.h
@@ -201,7 +201,7 @@ extern void pci_resource_to_user(const struct pci_dev *dev, int bar,
201extern void pcibios_setup_bus_devices(struct pci_bus *bus); 201extern void pcibios_setup_bus_devices(struct pci_bus *bus);
202extern void pcibios_setup_bus_self(struct pci_bus *bus); 202extern void pcibios_setup_bus_self(struct pci_bus *bus);
203extern void pcibios_setup_phb_io_space(struct pci_controller *hose); 203extern void pcibios_setup_phb_io_space(struct pci_controller *hose);
204extern void pcibios_scan_phb(struct pci_controller *hose, void *sysdata); 204extern void pcibios_scan_phb(struct pci_controller *hose);
205 205
206#endif /* __KERNEL__ */ 206#endif /* __KERNEL__ */
207#endif /* __ASM_POWERPC_PCI_H */ 207#endif /* __ASM_POWERPC_PCI_H */
diff --git a/arch/powerpc/kernel/of_platform.c b/arch/powerpc/kernel/of_platform.c
index b2c363ef38ad..9bd951c67767 100644
--- a/arch/powerpc/kernel/of_platform.c
+++ b/arch/powerpc/kernel/of_platform.c
@@ -74,7 +74,7 @@ static int __devinit of_pci_phb_probe(struct platform_device *dev,
74#endif /* CONFIG_EEH */ 74#endif /* CONFIG_EEH */
75 75
76 /* Scan the bus */ 76 /* Scan the bus */
77 pcibios_scan_phb(phb, dev->dev.of_node); 77 pcibios_scan_phb(phb);
78 if (phb->bus == NULL) 78 if (phb->bus == NULL)
79 return -ENXIO; 79 return -ENXIO;
80 80
diff --git a/arch/powerpc/kernel/pci-common.c b/arch/powerpc/kernel/pci-common.c
index eb341be9a4d9..3cd85faa8ac6 100644
--- a/arch/powerpc/kernel/pci-common.c
+++ b/arch/powerpc/kernel/pci-common.c
@@ -1688,13 +1688,8 @@ int early_find_capability(struct pci_controller *hose, int bus, int devfn,
1688/** 1688/**
1689 * pci_scan_phb - Given a pci_controller, setup and scan the PCI bus 1689 * pci_scan_phb - Given a pci_controller, setup and scan the PCI bus
1690 * @hose: Pointer to the PCI host controller instance structure 1690 * @hose: Pointer to the PCI host controller instance structure
1691 * @sysdata: value to use for sysdata pointer. ppc32 and ppc64 differ here
1692 *
1693 * Note: the 'data' pointer is a temporary measure. As 32 and 64 bit
1694 * pci code gets merged, this parameter should become unnecessary because
1695 * both will use the same value.
1696 */ 1691 */
1697void __devinit pcibios_scan_phb(struct pci_controller *hose, void *sysdata) 1692void __devinit pcibios_scan_phb(struct pci_controller *hose)
1698{ 1693{
1699 struct pci_bus *bus; 1694 struct pci_bus *bus;
1700 struct device_node *node = hose->dn; 1695 struct device_node *node = hose->dn;
@@ -1704,13 +1699,13 @@ void __devinit pcibios_scan_phb(struct pci_controller *hose, void *sysdata)
1704 node ? node->full_name : "<NO NAME>"); 1699 node ? node->full_name : "<NO NAME>");
1705 1700
1706 /* Create an empty bus for the toplevel */ 1701 /* Create an empty bus for the toplevel */
1707 bus = pci_create_bus(hose->parent, hose->first_busno, hose->ops, 1702 bus = pci_create_bus(hose->parent, hose->first_busno, hose->ops, hose);
1708 sysdata);
1709 if (bus == NULL) { 1703 if (bus == NULL) {
1710 pr_err("Failed to create bus for PCI domain %04x\n", 1704 pr_err("Failed to create bus for PCI domain %04x\n",
1711 hose->global_number); 1705 hose->global_number);
1712 return; 1706 return;
1713 } 1707 }
1708 bus->dev.of_node = of_node_get(node);
1714 bus->secondary = hose->first_busno; 1709 bus->secondary = hose->first_busno;
1715 hose->bus = bus; 1710 hose->bus = bus;
1716 1711
diff --git a/arch/powerpc/kernel/pci_32.c b/arch/powerpc/kernel/pci_32.c
index e7db5b48004a..bedb370459f2 100644
--- a/arch/powerpc/kernel/pci_32.c
+++ b/arch/powerpc/kernel/pci_32.c
@@ -381,7 +381,7 @@ static int __init pcibios_init(void)
381 if (pci_assign_all_buses) 381 if (pci_assign_all_buses)
382 hose->first_busno = next_busno; 382 hose->first_busno = next_busno;
383 hose->last_busno = 0xff; 383 hose->last_busno = 0xff;
384 pcibios_scan_phb(hose, hose); 384 pcibios_scan_phb(hose);
385 pci_bus_add_devices(hose->bus); 385 pci_bus_add_devices(hose->bus);
386 if (pci_assign_all_buses || next_busno <= hose->last_busno) 386 if (pci_assign_all_buses || next_busno <= hose->last_busno)
387 next_busno = hose->last_busno + pcibios_assign_bus_offset; 387 next_busno = hose->last_busno + pcibios_assign_bus_offset;
diff --git a/arch/powerpc/kernel/pci_64.c b/arch/powerpc/kernel/pci_64.c
index 851577608a78..fc6452b6be9f 100644
--- a/arch/powerpc/kernel/pci_64.c
+++ b/arch/powerpc/kernel/pci_64.c
@@ -64,7 +64,7 @@ static int __init pcibios_init(void)
64 64
65 /* Scan all of the recorded PCI controllers. */ 65 /* Scan all of the recorded PCI controllers. */
66 list_for_each_entry_safe(hose, tmp, &hose_list, list_node) { 66 list_for_each_entry_safe(hose, tmp, &hose_list, list_node) {
67 pcibios_scan_phb(hose, hose->dn); 67 pcibios_scan_phb(hose);
68 pci_bus_add_devices(hose->bus); 68 pci_bus_add_devices(hose->bus);
69 } 69 }
70 70
@@ -242,10 +242,10 @@ long sys_pciconfig_iobase(long which, unsigned long in_bus,
242 break; 242 break;
243 bus = NULL; 243 bus = NULL;
244 } 244 }
245 if (bus == NULL || bus->sysdata == NULL) 245 if (bus == NULL || bus->dev.of_node == NULL)
246 return -ENODEV; 246 return -ENODEV;
247 247
248 hose_node = (struct device_node *)bus->sysdata; 248 hose_node = bus->dev.of_node;
249 hose = PCI_DN(hose_node)->phb; 249 hose = PCI_DN(hose_node)->phb;
250 250
251 switch (which) { 251 switch (which) {
diff --git a/arch/powerpc/kernel/pci_dn.c b/arch/powerpc/kernel/pci_dn.c
index d56b35ee7f74..29852688ceaa 100644
--- a/arch/powerpc/kernel/pci_dn.c
+++ b/arch/powerpc/kernel/pci_dn.c
@@ -161,7 +161,7 @@ static void *is_devfn_node(struct device_node *dn, void *data)
161/* 161/*
162 * This is the "slow" path for looking up a device_node from a 162 * This is the "slow" path for looking up a device_node from a
163 * pci_dev. It will hunt for the device under its parent's 163 * pci_dev. It will hunt for the device under its parent's
164 * phb and then update sysdata for a future fastpath. 164 * phb and then update of_node pointer.
165 * 165 *
166 * It may also do fixups on the actual device since this happens 166 * It may also do fixups on the actual device since this happens
167 * on the first read/write. 167 * on the first read/write.
@@ -170,16 +170,19 @@ static void *is_devfn_node(struct device_node *dn, void *data)
170 * In this case it may probe for real hardware ("just in case") 170 * In this case it may probe for real hardware ("just in case")
171 * and add a device_node to the device tree if necessary. 171 * and add a device_node to the device tree if necessary.
172 * 172 *
173 * Is this function necessary anymore now that dev->dev.of_node is
174 * used to store the node pointer?
175 *
173 */ 176 */
174struct device_node *fetch_dev_dn(struct pci_dev *dev) 177struct device_node *fetch_dev_dn(struct pci_dev *dev)
175{ 178{
176 struct device_node *orig_dn = dev->sysdata; 179 struct device_node *orig_dn = dev->dev.of_node;
177 struct device_node *dn; 180 struct device_node *dn;
178 unsigned long searchval = (dev->bus->number << 8) | dev->devfn; 181 unsigned long searchval = (dev->bus->number << 8) | dev->devfn;
179 182
180 dn = traverse_pci_devices(orig_dn, is_devfn_node, (void *)searchval); 183 dn = traverse_pci_devices(orig_dn, is_devfn_node, (void *)searchval);
181 if (dn) 184 if (dn)
182 dev->sysdata = dn; 185 dev->dev.of_node = dn;
183 return dn; 186 return dn;
184} 187}
185EXPORT_SYMBOL(fetch_dev_dn); 188EXPORT_SYMBOL(fetch_dev_dn);
diff --git a/arch/powerpc/kernel/pci_of_scan.c b/arch/powerpc/kernel/pci_of_scan.c
index e751506323b4..1e89a72fd030 100644
--- a/arch/powerpc/kernel/pci_of_scan.c
+++ b/arch/powerpc/kernel/pci_of_scan.c
@@ -135,7 +135,7 @@ struct pci_dev *of_create_pci_dev(struct device_node *node,
135 pr_debug(" create device, devfn: %x, type: %s\n", devfn, type); 135 pr_debug(" create device, devfn: %x, type: %s\n", devfn, type);
136 136
137 dev->bus = bus; 137 dev->bus = bus;
138 dev->sysdata = node; 138 dev->dev.of_node = of_node_get(node);
139 dev->dev.parent = bus->bridge; 139 dev->dev.parent = bus->bridge;
140 dev->dev.bus = &pci_bus_type; 140 dev->dev.bus = &pci_bus_type;
141 dev->devfn = devfn; 141 dev->devfn = devfn;
@@ -238,7 +238,7 @@ void __devinit of_scan_pci_bridge(struct device_node *node,
238 bus->primary = dev->bus->number; 238 bus->primary = dev->bus->number;
239 bus->subordinate = busrange[1]; 239 bus->subordinate = busrange[1];
240 bus->bridge_ctl = 0; 240 bus->bridge_ctl = 0;
241 bus->sysdata = node; 241 bus->dev.of_node = of_node_get(node);
242 242
243 /* parse ranges property */ 243 /* parse ranges property */
244 /* PCI #address-cells == 3 and #size-cells == 2 always */ 244 /* PCI #address-cells == 3 and #size-cells == 2 always */
diff --git a/arch/powerpc/platforms/pseries/pci_dlpar.c b/arch/powerpc/platforms/pseries/pci_dlpar.c
index 5fcc92a12d3e..3bf4488aaec6 100644
--- a/arch/powerpc/platforms/pseries/pci_dlpar.c
+++ b/arch/powerpc/platforms/pseries/pci_dlpar.c
@@ -149,7 +149,7 @@ struct pci_controller * __devinit init_phb_dynamic(struct device_node *dn)
149 if (dn->child) 149 if (dn->child)
150 eeh_add_device_tree_early(dn); 150 eeh_add_device_tree_early(dn);
151 151
152 pcibios_scan_phb(phb, dn); 152 pcibios_scan_phb(phb);
153 pcibios_finish_adding_to_bus(phb->bus); 153 pcibios_finish_adding_to_bus(phb->bus);
154 154
155 return phb; 155 return phb;