Lines Matching +full:parent +full:- +full:child

1 // SPDX-License-Identifier: GPL-2.0+
14 #include <asm/pnv-pci.h>
15 #include <asm/ppc-pci.h>
22 ((sl)->pdev ? pci_warn((sl)->pdev, x) : dev_warn(&(sl)->bus->dev, x))
40 struct pci_dev *pdev = php_slot->pdev; in pnv_php_disable_irq()
41 int irq = php_slot->irq; in pnv_php_disable_irq()
44 if (php_slot->irq > 0) { in pnv_php_disable_irq()
51 free_irq(php_slot->irq, php_slot); in pnv_php_disable_irq()
52 php_slot->irq = 0; in pnv_php_disable_irq()
55 if (php_slot->wq) { in pnv_php_disable_irq()
56 destroy_workqueue(php_slot->wq); in pnv_php_disable_irq()
57 php_slot->wq = NULL; in pnv_php_disable_irq()
61 if (pdev->msix_enabled) in pnv_php_disable_irq()
63 else if (pdev->msi_enabled) in pnv_php_disable_irq()
75 WARN_ON(!list_empty(&php_slot->children)); in pnv_php_free_slot()
77 kfree(php_slot->name); in pnv_php_free_slot()
87 kref_put(&php_slot->kref, pnv_php_free_slot); in pnv_php_put_slot()
95 if (php_slot->dn == dn) { in pnv_php_match()
96 kref_get(&php_slot->kref); in pnv_php_match()
100 list_for_each_entry(tmp, &php_slot->children, link) { in pnv_php_match()
130 * The function should remove pdn in a depth-first manner.
134 struct device_node *child; in pnv_php_rmv_pdns() local
136 for_each_child_of_node(dn, child) { in pnv_php_rmv_pdns()
137 pnv_php_rmv_pdns(child); in pnv_php_rmv_pdns()
139 pci_remove_device_node_info(child); in pnv_php_rmv_pdns()
144 * Detach all child nodes of the indicated device nodes. The
145 * function should handle device nodes in depth-first manner.
154 static void pnv_php_detach_device_nodes(struct device_node *parent) in pnv_php_detach_device_nodes() argument
158 for_each_child_of_node(parent, dn) { in pnv_php_detach_device_nodes()
168 pnv_php_rmv_pdns(php_slot->dn); in pnv_php_rmv_devtree()
174 if (php_slot->fdt) in pnv_php_rmv_devtree()
175 of_changeset_destroy(&php_slot->ocs); in pnv_php_rmv_devtree()
176 pnv_php_detach_device_nodes(php_slot->dn); in pnv_php_rmv_devtree()
178 if (php_slot->fdt) { in pnv_php_rmv_devtree()
179 kfree(php_slot->dt); in pnv_php_rmv_devtree()
180 kfree(php_slot->fdt); in pnv_php_rmv_devtree()
181 php_slot->dt = NULL; in pnv_php_rmv_devtree()
182 php_slot->dn->child = NULL; in pnv_php_rmv_devtree()
183 php_slot->fdt = NULL; in pnv_php_rmv_devtree()
192 static void pnv_php_reverse_nodes(struct device_node *parent) in pnv_php_reverse_nodes() argument
194 struct device_node *child, *next; in pnv_php_reverse_nodes() local
196 /* In-depth first */ in pnv_php_reverse_nodes()
197 for_each_child_of_node(parent, child) in pnv_php_reverse_nodes()
198 pnv_php_reverse_nodes(child); in pnv_php_reverse_nodes()
200 /* Reverse the nodes in the child list */ in pnv_php_reverse_nodes()
201 child = parent->child; in pnv_php_reverse_nodes()
202 parent->child = NULL; in pnv_php_reverse_nodes()
203 while (child) { in pnv_php_reverse_nodes()
204 next = child->sibling; in pnv_php_reverse_nodes()
206 child->sibling = parent->child; in pnv_php_reverse_nodes()
207 parent->child = child; in pnv_php_reverse_nodes()
208 child = next; in pnv_php_reverse_nodes()
215 struct device_node *child; in pnv_php_populate_changeset() local
218 for_each_child_of_node(dn, child) { in pnv_php_populate_changeset()
219 ret = of_changeset_attach_node(ocs, child); in pnv_php_populate_changeset()
221 of_node_put(child); in pnv_php_populate_changeset()
225 ret = pnv_php_populate_changeset(ocs, child); in pnv_php_populate_changeset()
227 of_node_put(child); in pnv_php_populate_changeset()
242 return ERR_PTR(-ENOMEM); in pnv_php_add_one_pdn()
249 struct pci_controller *hose = pci_bus_to_host(slot->bus); in pnv_php_add_pdns()
251 pci_traverse_device_nodes(slot->dn, pnv_php_add_one_pdn, hose); in pnv_php_add_pdns()
265 ret = -ENOMEM; in pnv_php_add_devtree()
269 ret = pnv_pci_get_device_tree(php_slot->dn->phandle, fdt1, 0x10000); in pnv_php_add_devtree()
277 ret = -ENOMEM; in pnv_php_add_devtree()
282 dt = of_fdt_unflatten_tree(fdt, php_slot->dn, NULL); in pnv_php_add_devtree()
284 ret = -EINVAL; in pnv_php_add_devtree()
290 of_changeset_init(&php_slot->ocs); in pnv_php_add_devtree()
291 pnv_php_reverse_nodes(php_slot->dn); in pnv_php_add_devtree()
292 ret = pnv_php_populate_changeset(&php_slot->ocs, php_slot->dn); in pnv_php_add_devtree()
294 pnv_php_reverse_nodes(php_slot->dn); in pnv_php_add_devtree()
300 php_slot->dn->child = NULL; in pnv_php_add_devtree()
301 ret = of_changeset_apply(&php_slot->ocs); in pnv_php_add_devtree()
309 php_slot->fdt = fdt; in pnv_php_add_devtree()
310 php_slot->dt = dt; in pnv_php_add_devtree()
315 of_changeset_destroy(&php_slot->ocs); in pnv_php_add_devtree()
318 php_slot->dn->child = NULL; in pnv_php_add_devtree()
339 ret = pnv_pci_set_power_state(php_slot->id, state, &msg); in pnv_php_set_slot_power_state()
341 if (be64_to_cpu(msg.params[1]) != php_slot->dn->phandle || in pnv_php_set_slot_power_state()
347 return -ENOMSG; in pnv_php_set_slot_power_state()
350 ret = -ENODEV; in pnv_php_set_slot_power_state()
382 ret = pnv_pci_get_power_state(php_slot->id, &power_state); in pnv_php_get_power_state()
403 ret = pnv_pci_get_presence_state(php_slot->id, &presence); in pnv_php_get_adapter_state()
418 *state = php_slot->attention_state; in pnv_php_get_attention_state()
425 struct pci_dev *bridge = php_slot->pdev; in pnv_php_set_attention_state()
428 php_slot->attention_state = state; in pnv_php_set_attention_state()
446 struct hotplug_slot *slot = &php_slot->slot; in pnv_php_enable()
452 if (php_slot->state != PNV_PHP_STATE_REGISTERED) in pnv_php_enable()
467 if (!php_slot->power_state_check) { in pnv_php_enable()
468 php_slot->power_state_check = true; in pnv_php_enable()
484 * has its power off and non-empty slot has its power on. in pnv_php_enable()
486 if (!php_slot->power_state_check) { in pnv_php_enable()
487 php_slot->power_state_check = true; in pnv_php_enable()
514 pci_hp_add_devices(php_slot->bus); in pnv_php_enable()
518 /* Rescan for child hotpluggable slots */ in pnv_php_enable()
519 php_slot->state = PNV_PHP_STATE_POPULATED; in pnv_php_enable()
521 pnv_php_register(php_slot->dn); in pnv_php_enable()
523 php_slot->state = PNV_PHP_STATE_POPULATED; in pnv_php_enable()
532 struct pci_dev *bridge = php_slot->pdev; in pnv_php_reset_slot()
544 if (php_slot->irq > 0) in pnv_php_reset_slot()
545 disable_irq(php_slot->irq); in pnv_php_reset_slot()
550 pcie_capability_read_word(php_slot->pdev, PCI_EXP_SLTSTA, &sts); in pnv_php_reset_slot()
552 pcie_capability_write_word(php_slot->pdev, PCI_EXP_SLTSTA, sts); in pnv_php_reset_slot()
554 if (php_slot->irq > 0) in pnv_php_reset_slot()
555 enable_irq(php_slot->irq); in pnv_php_reset_slot()
577 if (php_slot->state != PNV_PHP_STATE_POPULATED && in pnv_php_disable_slot()
578 php_slot->state != PNV_PHP_STATE_REGISTERED) in pnv_php_disable_slot()
583 pci_hp_remove_devices(php_slot->bus); in pnv_php_disable_slot()
586 /* Detach the child hotpluggable slots */ in pnv_php_disable_slot()
587 pnv_php_unregister(php_slot->dn); in pnv_php_disable_slot()
592 php_slot->state = PNV_PHP_STATE_REGISTERED; in pnv_php_disable_slot()
610 /* Remove from global or child list */ in pnv_php_release()
612 list_del(&php_slot->link); in pnv_php_release()
615 /* Detach from parent */ in pnv_php_release()
617 pnv_php_put_slot(php_slot->parent); in pnv_php_release()
628 ret = of_property_read_string(dn, "ibm,slot-label", &label); in pnv_php_alloc_slot()
643 php_slot->name = kstrdup(label, GFP_KERNEL); in pnv_php_alloc_slot()
644 if (!php_slot->name) { in pnv_php_alloc_slot()
649 if (dn->child && PCI_DN(dn->child)) in pnv_php_alloc_slot()
650 php_slot->slot_no = PCI_SLOT(PCI_DN(dn->child)->devfn); in pnv_php_alloc_slot()
652 php_slot->slot_no = -1; /* Placeholder slot */ in pnv_php_alloc_slot()
654 kref_init(&php_slot->kref); in pnv_php_alloc_slot()
655 php_slot->state = PNV_PHP_STATE_INITIALIZED; in pnv_php_alloc_slot()
656 php_slot->dn = dn; in pnv_php_alloc_slot()
657 php_slot->pdev = bus->self; in pnv_php_alloc_slot()
658 php_slot->bus = bus; in pnv_php_alloc_slot()
659 php_slot->id = id; in pnv_php_alloc_slot()
660 php_slot->power_state_check = false; in pnv_php_alloc_slot()
661 php_slot->slot.ops = &php_slot_ops; in pnv_php_alloc_slot()
663 INIT_LIST_HEAD(&php_slot->children); in pnv_php_alloc_slot()
664 INIT_LIST_HEAD(&php_slot->link); in pnv_php_alloc_slot()
671 struct pnv_php_slot *parent; in pnv_php_register_slot() local
672 struct device_node *dn = php_slot->dn; in pnv_php_register_slot()
677 parent = pnv_php_find_slot(php_slot->dn); in pnv_php_register_slot()
678 if (parent) { in pnv_php_register_slot()
679 pnv_php_put_slot(parent); in pnv_php_register_slot()
680 return -EEXIST; in pnv_php_register_slot()
684 ret = pci_hp_register(&php_slot->slot, php_slot->bus, in pnv_php_register_slot()
685 php_slot->slot_no, php_slot->name); in pnv_php_register_slot()
691 /* Attach to the parent's child list or global list */ in pnv_php_register_slot()
698 parent = pnv_php_find_slot(dn); in pnv_php_register_slot()
699 if (parent) { in pnv_php_register_slot()
708 php_slot->parent = parent; in pnv_php_register_slot()
709 if (parent) in pnv_php_register_slot()
710 list_add_tail(&php_slot->link, &parent->children); in pnv_php_register_slot()
712 list_add_tail(&php_slot->link, &pnv_php_slot_list); in pnv_php_register_slot()
715 php_slot->state = PNV_PHP_STATE_REGISTERED; in pnv_php_register_slot()
721 struct pci_dev *pdev = php_slot->pdev; in pnv_php_enable_msix()
735 return -ERANGE; in pnv_php_enable_msix()
751 struct pnv_php_slot *php_slot = event->php_slot; in pnv_php_event_handler()
753 if (event->added) in pnv_php_event_handler()
754 pnv_php_enable_slot(&php_slot->slot); in pnv_php_event_handler()
756 pnv_php_disable_slot(&php_slot->slot); in pnv_php_event_handler()
764 struct pci_dev *pchild, *pdev = php_slot->pdev; in pnv_php_interrupt()
779 php_slot->name, in pnv_php_interrupt()
786 } else if (!(php_slot->flags & PNV_PHP_FLAG_BROKEN_PDC) && in pnv_php_interrupt()
788 ret = pnv_pci_get_presence_state(php_slot->id, &presence); in pnv_php_interrupt()
792 php_slot->name, ret, sts); in pnv_php_interrupt()
798 pci_dbg(pdev, "PCI slot [%s]: Spurious IRQ?\n", php_slot->name); in pnv_php_interrupt()
804 pchild = list_first_entry_or_null(&php_slot->bus->devices, in pnv_php_interrupt()
807 pe = edev ? edev->pe : NULL; in pnv_php_interrupt()
824 php_slot->name, sts); in pnv_php_interrupt()
829 php_slot->name, added ? "added" : "removed", irq); in pnv_php_interrupt()
830 INIT_WORK(&event->work, pnv_php_event_handler); in pnv_php_interrupt()
831 event->added = added; in pnv_php_interrupt()
832 event->php_slot = php_slot; in pnv_php_interrupt()
833 queue_work(php_slot->wq, &event->work); in pnv_php_interrupt()
840 struct pci_dev *pdev = php_slot->pdev; in pnv_php_init_irq()
846 php_slot->wq = alloc_workqueue("pciehp-%s", 0, 0, php_slot->name); in pnv_php_init_irq()
847 if (!php_slot->wq) { in pnv_php_init_irq()
854 ret = of_property_read_u32(php_slot->dn, "ibm,slot-broken-pdc", in pnv_php_init_irq()
857 php_slot->flags |= PNV_PHP_FLAG_BROKEN_PDC; in pnv_php_init_irq()
861 if (php_slot->flags & PNV_PHP_FLAG_BROKEN_PDC) in pnv_php_init_irq()
869 php_slot->name, php_slot); in pnv_php_init_irq()
878 if (php_slot->flags & PNV_PHP_FLAG_BROKEN_PDC) { in pnv_php_init_irq()
890 php_slot->irq = irq; in pnv_php_init_irq()
895 struct pci_dev *pdev = php_slot->pdev; in pnv_php_enable_irq()
926 if (!ret || pdev->irq) { in pnv_php_enable_irq()
927 irq = pdev->irq; in pnv_php_enable_irq()
939 ret = of_property_read_u32(dn, "ibm,slot-pluggable", &prop32); in pnv_php_register_one()
941 return -ENXIO; in pnv_php_register_one()
943 ret = of_property_read_u32(dn, "ibm,reset-by-firmware", &prop32); in pnv_php_register_one()
945 return -ENXIO; in pnv_php_register_one()
949 return -ENODEV; in pnv_php_register_one()
960 ret = of_property_read_u32(dn, "ibm,slot-surprise-pluggable", &prop32); in pnv_php_register_one()
967 pnv_php_unregister_one(php_slot->dn); in pnv_php_register_one()
975 struct device_node *child; in pnv_php_register() local
978 * The parent slots should be registered before their in pnv_php_register()
979 * child slots. in pnv_php_register()
981 for_each_child_of_node(dn, child) { in pnv_php_register()
982 pnv_php_register_one(child); in pnv_php_register()
983 pnv_php_register(child); in pnv_php_register()
995 php_slot->state = PNV_PHP_STATE_OFFLINE; in pnv_php_unregister_one()
996 pci_hp_deregister(&php_slot->slot); in pnv_php_unregister_one()
1003 struct device_node *child; in pnv_php_unregister() local
1005 /* The child slots should go before their parent slots */ in pnv_php_unregister()
1006 for_each_child_of_node(dn, child) { in pnv_php_unregister()
1007 pnv_php_unregister(child); in pnv_php_unregister()
1008 pnv_php_unregister_one(child); in pnv_php_unregister()
1017 for_each_compatible_node(dn, NULL, "ibm,ioda2-phb") in pnv_php_init()
1020 for_each_compatible_node(dn, NULL, "ibm,ioda3-phb") in pnv_php_init()
1023 for_each_compatible_node(dn, NULL, "ibm,ioda2-npu2-opencapi-phb") in pnv_php_init()
1032 for_each_compatible_node(dn, NULL, "ibm,ioda2-phb") in pnv_php_exit()
1035 for_each_compatible_node(dn, NULL, "ibm,ioda3-phb") in pnv_php_exit()
1038 for_each_compatible_node(dn, NULL, "ibm,ioda2-npu2-opencapi-phb") in pnv_php_exit()