Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[POWERPC] Generic OF platform driver for PCI host bridges.

When enabled in Kconfig, it will pick up any of_platform_device
matching it's match list (currently type "pci", "pcix", "pcie",
or "ht" and setup a PHB for it.

Platform must provide a ppc_md.pci_setup_phb() for it to work
(for doing the necessary initialisations specific to a given PHB
like setting up the config space ops).

It's currently only available on 64 bits as the 32 bits PCI code
can't quite cope with it in it's current form. I will fix that
later.

Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Paul Mackerras <paulus@samba.org>

authored by

Benjamin Herrenschmidt and committed by
Paul Mackerras
4c9d2800 803d4573

+134 -10
+6
arch/powerpc/Kconfig
··· 223 223 depends on PPC_DCR_NATIVE || PPC_DCR_MMIO 224 224 default y 225 225 226 + config PPC_OF_PLATFORM_PCI 227 + bool 228 + depends on PPC64 # not supported on 32 bits yet 229 + default n 230 + 226 231 config BOOKE 227 232 bool 228 233 depends on E200 || E500 ··· 474 469 bool 475 470 select PPC_CELL 476 471 select PPC_DCR_MMIO 472 + select PPC_OF_PLATFORM_PCI 477 473 select MPIC 478 474 default n 479 475
+103
arch/powerpc/kernel/of_platform.c
··· 1 1 /* 2 2 * Copyright (C) 2006 Benjamin Herrenschmidt, IBM Corp. 3 3 * <benh@kernel.crashing.org> 4 + * and Arnd Bergmann, IBM Corp. 4 5 * 5 6 * This program is free software; you can redistribute it and/or 6 7 * modify it under the terms of the GNU General Public License ··· 18 17 #include <linux/module.h> 19 18 #include <linux/mod_devicetable.h> 20 19 #include <linux/slab.h> 20 + #include <linux/pci.h> 21 21 22 22 #include <asm/errno.h> 23 23 #include <asm/dcr.h> 24 24 #include <asm/of_device.h> 25 25 #include <asm/of_platform.h> 26 26 #include <asm/topology.h> 27 + #include <asm/pci-bridge.h> 28 + #include <asm/ppc-pci.h> 27 29 28 30 /* 29 31 * The list of OF IDs below is used for matching bus types in the ··· 381 377 return NULL; 382 378 } 383 379 EXPORT_SYMBOL(of_find_device_by_phandle); 380 + 381 + 382 + #ifdef CONFIG_PPC_OF_PLATFORM_PCI 383 + 384 + /* The probing of PCI controllers from of_platform is currently 385 + * 64 bits only, mostly due to gratuitous differences between 386 + * the 32 and 64 bits PCI code on PowerPC and the 32 bits one 387 + * lacking some bits needed here. 388 + */ 389 + 390 + static int __devinit of_pci_phb_probe(struct of_device *dev, 391 + const struct of_device_id *match) 392 + { 393 + struct pci_controller *phb; 394 + 395 + /* Check if we can do that ... */ 396 + if (ppc_md.pci_setup_phb == NULL) 397 + return -ENODEV; 398 + 399 + printk(KERN_INFO "Setting up PCI bus %s\n", dev->node->full_name); 400 + 401 + /* Alloc and setup PHB data structure */ 402 + phb = pcibios_alloc_controller(dev->node); 403 + if (!phb) 404 + return -ENODEV; 405 + 406 + /* Setup parent in sysfs */ 407 + phb->parent = &dev->dev; 408 + 409 + /* Setup the PHB using arch provided callback */ 410 + if (ppc_md.pci_setup_phb(phb)) { 411 + pcibios_free_controller(phb); 412 + return -ENODEV; 413 + } 414 + 415 + /* Process "ranges" property */ 416 + pci_process_bridge_OF_ranges(phb, dev->node, 0); 417 + 418 + /* Setup IO space. 419 + * This will not work properly for ISA IOs, something needs to be done 420 + * about it if we ever generalize that way of probing PCI brigdes 421 + */ 422 + pci_setup_phb_io_dynamic(phb, 0); 423 + 424 + /* Init pci_dn data structures */ 425 + pci_devs_phb_init_dynamic(phb); 426 + 427 + /* Register devices with EEH */ 428 + #ifdef CONFIG_EEH 429 + if (dev->node->child) 430 + eeh_add_device_tree_early(dev->node); 431 + #endif /* CONFIG_EEH */ 432 + 433 + /* Scan the bus */ 434 + scan_phb(phb); 435 + 436 + /* Claim resources. This might need some rework as well depending 437 + * wether we are doing probe-only or not, like assigning unassigned 438 + * resources etc... 439 + */ 440 + pcibios_claim_one_bus(phb->bus); 441 + 442 + /* Finish EEH setup */ 443 + #ifdef CONFIG_EEH 444 + eeh_add_device_tree_late(phb->bus); 445 + #endif 446 + 447 + /* Add probed PCI devices to the device model */ 448 + pci_bus_add_devices(phb->bus); 449 + 450 + return 0; 451 + } 452 + 453 + static struct of_device_id of_pci_phb_ids[] = { 454 + { .type = "pci", }, 455 + { .type = "pcix", }, 456 + { .type = "pcie", }, 457 + { .type = "pciex", }, 458 + { .type = "ht", }, 459 + {} 460 + }; 461 + 462 + static struct of_platform_driver of_pci_phb_driver = { 463 + .name = "of-pci", 464 + .match_table = of_pci_phb_ids, 465 + .probe = of_pci_phb_probe, 466 + .driver = { 467 + .multithread_probe = 1, 468 + }, 469 + }; 470 + 471 + static __init int of_pci_phb_init(void) 472 + { 473 + return of_register_platform_driver(&of_pci_phb_driver); 474 + } 475 + 476 + device_initcall(of_pci_phb_init); 477 + 478 + #endif /* CONFIG_PPC_OF_PLATFORM_PCI */
+9
arch/powerpc/kernel/pci_64.c
··· 210 210 211 211 void pcibios_free_controller(struct pci_controller *phb) 212 212 { 213 + spin_lock(&hose_spinlock); 214 + list_del(&phb->list_node); 215 + spin_unlock(&hose_spinlock); 216 + 213 217 if (phb->is_dynamic) 214 218 kfree(phb); 215 219 } ··· 1246 1242 void __devinit pcibios_fixup_bus(struct pci_bus *bus) 1247 1243 { 1248 1244 struct pci_dev *dev = bus->self; 1245 + struct device_node *np; 1246 + 1247 + np = pci_bus_to_OF_node(bus); 1248 + 1249 + DBG("pcibios_fixup_bus(%s)\n", np ? np->full_name : "<???>"); 1249 1250 1250 1251 if (dev && pci_probe_only && 1251 1252 (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI) {
+4 -3
arch/powerpc/kernel/rtas_pci.c
··· 257 257 return 0; 258 258 } 259 259 260 - int __devinit setup_phb(struct device_node *dev, struct pci_controller *phb) 260 + int __devinit rtas_setup_phb(struct pci_controller *phb) 261 261 { 262 + struct device_node *dev = phb->arch_data; 263 + 262 264 if (is_python(dev)) 263 265 python_countermeasures(dev); 264 266 ··· 292 290 phb = pcibios_alloc_controller(node); 293 291 if (!phb) 294 292 continue; 295 - setup_phb(node, phb); 293 + rtas_setup_phb(phb); 296 294 pci_process_bridge_OF_ranges(phb, node, 0); 297 295 pci_setup_phb_io(phb, index == 0); 298 296 index++; ··· 364 362 } 365 363 } 366 364 367 - list_del(&phb->list_node); 368 365 pcibios_free_controller(phb); 369 366 370 367 return 0;
+1
arch/powerpc/platforms/cell/setup.c
··· 256 256 .check_legacy_ioport = cell_check_legacy_ioport, 257 257 .progress = cell_progress, 258 258 .init_IRQ = cell_init_irq, 259 + .pci_setup_phb = rtas_setup_phb, 259 260 #ifdef CONFIG_KEXEC 260 261 .machine_kexec = default_machine_kexec, 261 262 .machine_kexec_prepare = default_machine_kexec_prepare,
+1 -1
arch/powerpc/platforms/pseries/pci_dlpar.c
··· 195 195 phb = pcibios_alloc_controller(dn); 196 196 if (!phb) 197 197 return NULL; 198 - setup_phb(dn, phb); 198 + rtas_setup_phb(phb); 199 199 pci_process_bridge_OF_ranges(phb, dn, 0); 200 200 201 201 pci_setup_phb_io_dynamic(phb, primary);
+4
include/asm-powerpc/machdep.h
··· 26 26 struct iommu_table; 27 27 struct rtc_time; 28 28 struct file; 29 + struct pci_controller; 29 30 #ifdef CONFIG_KEXEC 30 31 struct kimage; 31 32 #endif ··· 107 106 void (*pcibios_fixup)(void); 108 107 int (*pci_probe_mode)(struct pci_bus *); 109 108 void (*pci_irq_fixup)(struct pci_dev *dev); 109 + 110 + /* To setup PHBs when using automatic OF platform driver for PCI */ 111 + int (*pci_setup_phb)(struct pci_controller *host); 110 112 111 113 void (*restart)(char *cmd); 112 114 void (*power_off)(void);
+6 -6
include/asm-powerpc/ppc-pci.h
··· 36 36 void *traverse_pci_devices(struct device_node *start, traverse_func pre, 37 37 void *data); 38 38 39 - void pci_devs_phb_init(void); 40 - void pci_devs_phb_init_dynamic(struct pci_controller *phb); 41 - int setup_phb(struct device_node *dev, struct pci_controller *phb); 42 - void __devinit scan_phb(struct pci_controller *hose); 39 + extern void pci_devs_phb_init(void); 40 + extern void pci_devs_phb_init_dynamic(struct pci_controller *phb); 41 + extern void scan_phb(struct pci_controller *hose); 43 42 44 43 /* From rtas_pci.h */ 45 - void init_pci_config_tokens (void); 46 - unsigned long get_phb_buid (struct device_node *); 44 + extern void init_pci_config_tokens (void); 45 + extern unsigned long get_phb_buid (struct device_node *); 46 + extern int rtas_setup_phb(struct pci_controller *phb); 47 47 48 48 /* From pSeries_pci.h */ 49 49 extern void pSeries_final_fixup(void);