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

powerpc/pci: Delay populating pdn

The pdn (struct pci_dn) instances are allocated from memblock or
bootmem when creating PCI controller (hoses) in setup_arch(). PCI
hotplug, which will be supported by proceeding patches, releases
PCI device nodes and their corresponding pdn on unplugging event.
The memory chunks for pdn instances allocated from memblock or
bootmem are hard to reused after being released.

This delays creating pdn by pci_devs_phb_init() from setup_arch()
to core_initcall() so that they are allocated from slab. The memory
consumed by pdn can be released to system without problem during
PCI unplugging time. It indicates that pci_dn is unavailable in
setup_arch() and the the fixup on pdn (like AGP's) can't be carried
out that time. We have to do that in pcibios_root_bridge_prepare()
on maple/pasemi/powermac platforms where/when the pdn is available.
pcibios_root_bridge_prepare is called from subsys_initcall() which
is executed after core_initcall() so the code flow does not change.

At the mean while, the EEH device is created when pdn is populated,
meaning pdn and EEH device have same life cycle. In turn, we needn't
call eeh_dev_init() to create EEH device explicitly.

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Reviewed-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Gavin Shan and committed by
Michael Ellerman
8cc7581c 7415c14c

+69 -59
+1 -1
arch/powerpc/include/asm/eeh.h
··· 274 274 const char *eeh_pe_loc_get(struct eeh_pe *pe); 275 275 struct pci_bus *eeh_pe_bus_get(struct eeh_pe *pe); 276 276 277 - void *eeh_dev_init(struct pci_dn *pdn, void *data); 277 + struct eeh_dev *eeh_dev_init(struct pci_dn *pdn); 278 278 void eeh_dev_phb_init_dynamic(struct pci_controller *phb); 279 279 int eeh_init(void); 280 280 int __init eeh_ops_register(struct eeh_ops *ops);
-2
arch/powerpc/include/asm/ppc-pci.h
··· 39 39 void *traverse_pci_dn(struct pci_dn *root, 40 40 void *(*fn)(struct pci_dn *, void *), 41 41 void *data); 42 - 43 - extern void pci_devs_phb_init(void); 44 42 extern void pci_devs_phb_init_dynamic(struct pci_controller *phb); 45 43 46 44 /* From rtas_pci.h */
+3 -14
arch/powerpc/kernel/eeh_dev.c
··· 44 44 /** 45 45 * eeh_dev_init - Create EEH device according to OF node 46 46 * @pdn: PCI device node 47 - * @data: PHB 48 47 * 49 48 * It will create EEH device according to the given OF node. The function 50 49 * might be called by PCI emunation, DR, PHB hotplug. 51 50 */ 52 - void *eeh_dev_init(struct pci_dn *pdn, void *data) 51 + struct eeh_dev *eeh_dev_init(struct pci_dn *pdn) 53 52 { 54 - struct pci_controller *phb = data; 53 + struct pci_controller *phb = pdn->phb; 55 54 struct eeh_dev *edev; 56 55 57 56 /* Allocate EEH device */ ··· 68 69 INIT_LIST_HEAD(&edev->list); 69 70 INIT_LIST_HEAD(&edev->rmv_list); 70 71 71 - return NULL; 72 + return edev; 72 73 } 73 74 74 75 /** ··· 80 81 */ 81 82 void eeh_dev_phb_init_dynamic(struct pci_controller *phb) 82 83 { 83 - struct pci_dn *root = phb->pci_data; 84 - 85 84 /* EEH PE for PHB */ 86 85 eeh_phb_pe_create(phb); 87 - 88 - /* EEH device for PHB */ 89 - eeh_dev_init(root, phb); 90 - 91 - /* EEH devices for children OF nodes */ 92 - traverse_pci_dn(root, eeh_dev_init, phb); 93 86 } 94 87 95 88 /** ··· 96 105 97 106 list_for_each_entry_safe(phb, tmp, &hose_list, list_node) 98 107 eeh_dev_phb_init_dynamic(phb); 99 - 100 - pr_info("EEH: devices created\n"); 101 108 102 109 return 0; 103 110 }
+19 -4
arch/powerpc/kernel/pci_dn.c
··· 212 212 213 213 #ifdef CONFIG_EEH 214 214 /* Create the EEH device for the VF */ 215 - eeh_dev_init(pdn, pci_bus_to_host(pdev->bus)); 216 - edev = pdn_to_eeh_dev(pdn); 215 + edev = eeh_dev_init(pdn); 217 216 BUG_ON(!edev); 218 217 edev->physfn = pdev; 219 218 #endif /* CONFIG_EEH */ ··· 294 295 const __be32 *regs; 295 296 struct device_node *parent; 296 297 struct pci_dn *pdn; 298 + #ifdef CONFIG_EEH 299 + struct eeh_dev *edev; 300 + #endif 297 301 298 - pdn = zalloc_maybe_bootmem(sizeof(*pdn), GFP_KERNEL); 302 + pdn = kzalloc(sizeof(*pdn), GFP_KERNEL); 299 303 if (pdn == NULL) 300 304 return NULL; 301 305 dn->data = pdn; ··· 326 324 327 325 /* Extended config space */ 328 326 pdn->pci_ext_config_space = (type && of_read_number(type, 1) == 1); 327 + 328 + /* Create EEH device */ 329 + #ifdef CONFIG_EEH 330 + edev = eeh_dev_init(pdn); 331 + if (!edev) { 332 + kfree(pdn); 333 + return NULL; 334 + } 335 + #endif 329 336 330 337 /* Attach to parent node */ 331 338 INIT_LIST_HEAD(&pdn->child_list); ··· 521 510 * pci device found underneath. This routine runs once, 522 511 * early in the boot sequence. 523 512 */ 524 - void __init pci_devs_phb_init(void) 513 + static int __init pci_devs_phb_init(void) 525 514 { 526 515 struct pci_controller *phb, *tmp; 527 516 528 517 /* This must be done first so the device nodes have valid pci info! */ 529 518 list_for_each_entry_safe(phb, tmp, &hose_list, list_node) 530 519 pci_devs_phb_init_dynamic(phb); 520 + 521 + return 0; 531 522 } 523 + 524 + core_initcall(pci_devs_phb_init); 532 525 533 526 static void pci_dev_pdn_setup(struct pci_dev *pdev) 534 527 {
+21 -13
arch/powerpc/platforms/maple/pci.c
··· 568 568 DBG(" <- maple_pci_irq_fixup\n"); 569 569 } 570 570 571 + static int maple_pci_root_bridge_prepare(struct pci_host_bridge *bridge) 572 + { 573 + struct pci_controller *hose = pci_bus_to_host(bridge->bus); 574 + struct device_node *np, *child; 575 + 576 + if (hose != u3_agp) 577 + return 0; 578 + 579 + /* Fixup the PCI<->OF mapping for U3 AGP due to bus renumbering. We 580 + * assume there is no P2P bridge on the AGP bus, which should be a 581 + * safe assumptions hopefully. 582 + */ 583 + np = hose->dn; 584 + PCI_DN(np)->busno = 0xf0; 585 + for_each_child_of_node(np, child) 586 + PCI_DN(child)->busno = 0xf0; 587 + 588 + return 0; 589 + } 590 + 571 591 void __init maple_pci_init(void) 572 592 { 573 593 struct device_node *np, *root; ··· 625 605 if (ht && maple_add_bridge(ht) != 0) 626 606 of_node_put(ht); 627 607 628 - /* Setup the linkage between OF nodes and PHBs */ 629 - pci_devs_phb_init(); 630 - 631 - /* Fixup the PCI<->OF mapping for U3 AGP due to bus renumbering. We 632 - * assume there is no P2P bridge on the AGP bus, which should be a 633 - * safe assumptions hopefully. 634 - */ 635 - if (u3_agp) { 636 - struct device_node *np = u3_agp->dn; 637 - PCI_DN(np)->busno = 0xf0; 638 - for (np = np->child; np; np = np->sibling) 639 - PCI_DN(np)->busno = 0xf0; 640 - } 608 + ppc_md.pcibios_root_bridge_prepare = maple_pci_root_bridge_prepare; 641 609 642 610 /* Tell pci.c to not change any resource allocations. */ 643 611 pci_add_flags(PCI_PROBE_ONLY);
-3
arch/powerpc/platforms/pasemi/pci.c
··· 229 229 of_node_get(np); 230 230 231 231 of_node_put(root); 232 - 233 - /* Setup the linkage between OF nodes and PHBs */ 234 - pci_devs_phb_init(); 235 232 } 236 233 237 234 void __iomem *pasemi_pci_getcfgaddr(struct pci_dev *dev, int offset)
+24 -14
arch/powerpc/platforms/powermac/pci.c
··· 878 878 #endif /* CONFIG_PPC32 */ 879 879 } 880 880 881 + #ifdef CONFIG_PPC64 882 + static int pmac_pci_root_bridge_prepare(struct pci_host_bridge *bridge) 883 + { 884 + struct pci_controller *hose = pci_bus_to_host(bridge->bus); 885 + struct device_node *np, *child; 886 + 887 + if (hose != u3_agp) 888 + return 0; 889 + 890 + /* Fixup the PCI<->OF mapping for U3 AGP due to bus renumbering. We 891 + * assume there is no P2P bridge on the AGP bus, which should be a 892 + * safe assumptions for now. We should do something better in the 893 + * future though 894 + */ 895 + np = hose->dn; 896 + PCI_DN(np)->busno = 0xf0; 897 + for_each_child_of_node(np, child) 898 + PCI_DN(child)->busno = 0xf0; 899 + 900 + return 0; 901 + } 902 + #endif /* CONFIG_PPC64 */ 903 + 881 904 void __init pmac_pci_init(void) 882 905 { 883 906 struct device_node *np, *root; ··· 937 914 if (ht && pmac_add_bridge(ht) != 0) 938 915 of_node_put(ht); 939 916 940 - /* Setup the linkage between OF nodes and PHBs */ 941 - pci_devs_phb_init(); 942 - 943 - /* Fixup the PCI<->OF mapping for U3 AGP due to bus renumbering. We 944 - * assume there is no P2P bridge on the AGP bus, which should be a 945 - * safe assumptions for now. We should do something better in the 946 - * future though 947 - */ 948 - if (u3_agp) { 949 - struct device_node *np = u3_agp->dn; 950 - PCI_DN(np)->busno = 0xf0; 951 - for (np = np->child; np; np = np->sibling) 952 - PCI_DN(np)->busno = 0xf0; 953 - } 917 + ppc_md.pcibios_root_bridge_prepare = pmac_pci_root_bridge_prepare; 954 918 /* pmac_check_ht_link(); */ 955 919 956 920 #else /* CONFIG_PPC64 */
-3
arch/powerpc/platforms/powernv/pci.c
··· 816 816 for_each_compatible_node(np, NULL, "ibm,ioda2-npu-phb") 817 817 pnv_pci_init_npu_phb(np); 818 818 819 - /* Setup the linkage between OF nodes and PHBs */ 820 - pci_devs_phb_init(); 821 - 822 819 /* Configure IOMMU DMA hooks */ 823 820 set_pci_dma_ops(&dma_iommu_ops); 824 821 }
+1 -5
arch/powerpc/platforms/pseries/setup.c
··· 195 195 case OF_RECONFIG_ATTACH_NODE: 196 196 parent = of_get_parent(np); 197 197 pdn = parent ? PCI_DN(parent) : NULL; 198 - if (pdn) { 199 - /* Create pdn and EEH device */ 198 + if (pdn) 200 199 pci_add_device_node_info(pdn->phb, np); 201 - eeh_dev_init(PCI_DN(np), pdn->phb); 202 - } 203 200 204 201 of_node_put(parent); 205 202 break; ··· 419 422 } 420 423 421 424 of_node_put(root); 422 - pci_devs_phb_init(); 423 425 424 426 /* 425 427 * PCI_PROBE_ONLY and PCI_REASSIGN_ALL_BUS can be set via properties