Lines Matching +full:dt +full:- +full:node
1 // SPDX-License-Identifier: GPL-2.0+
3 * PCI <-> OF mapping helpers
22 * pci_set_of_node - Find and set device's DT device_node
26 * DT. Returns -ENODEV if the device is present, but disabled in the DT.
30 if (!dev->bus->dev.of_node) in pci_set_of_node()
33 struct device_node *node __free(device_node) = in pci_set_of_node()
34 of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn); in pci_set_of_node()
35 if (!node) in pci_set_of_node()
39 bus_find_device_by_of_node(&platform_bus_type, node); in pci_set_of_node()
41 dev->bus->dev.of_node_reused = true; in pci_set_of_node()
43 device_set_node(&dev->dev, of_fwnode_handle(no_free_ptr(node))); in pci_set_of_node()
49 of_node_put(dev->dev.of_node); in pci_release_of_node()
50 device_set_node(&dev->dev, NULL); in pci_release_of_node()
55 struct device_node *node; in pci_set_bus_of_node() local
57 if (bus->self == NULL) { in pci_set_bus_of_node()
58 node = pcibios_get_phb_of_node(bus); in pci_set_bus_of_node()
60 node = of_node_get(bus->self->dev.of_node); in pci_set_bus_of_node()
61 if (node && of_property_read_bool(node, "external-facing")) in pci_set_bus_of_node()
62 bus->self->external_facing = true; in pci_set_bus_of_node()
65 device_set_node(&bus->dev, of_fwnode_handle(node)); in pci_set_bus_of_node()
70 of_node_put(bus->dev.of_node); in pci_release_bus_of_node()
71 device_set_node(&bus->dev, NULL); in pci_release_bus_of_node()
77 if (WARN_ON(bus->self || bus->parent)) in pcibios_get_phb_of_node()
81 * Look for a node pointer in either the intermediary device we in pcibios_get_phb_of_node()
85 if (bus->bridge->of_node) in pcibios_get_phb_of_node()
86 return of_node_get(bus->bridge->of_node); in pcibios_get_phb_of_node()
87 if (bus->bridge->parent && bus->bridge->parent->of_node) in pcibios_get_phb_of_node()
88 return of_node_get(bus->bridge->parent->of_node); in pcibios_get_phb_of_node()
97 if (!bus->dev.of_node) in pci_host_bridge_of_msi_domain()
101 d = of_msi_get_domain(&bus->dev, bus->dev.of_node, DOMAIN_BUS_PCI_MSI); in pci_host_bridge_of_msi_domain()
106 * If we don't have an msi-parent property, look for a domain in pci_host_bridge_of_msi_domain()
109 d = irq_find_matching_host(bus->dev.of_node, DOMAIN_BUS_PCI_MSI); in pci_host_bridge_of_msi_domain()
113 return irq_find_host(bus->dev.of_node); in pci_host_bridge_of_msi_domain()
121 if (dev && dev->of_node) in pci_host_of_has_msi_map()
122 return of_get_property(dev->of_node, "msi-map", NULL); in pci_host_of_has_msi_map()
126 static inline int __of_pci_pci_compare(struct device_node *node, in __of_pci_pci_compare() argument
131 devfn = of_pci_get_devfn(node); in __of_pci_pci_compare()
141 struct device_node *node, *node2; in of_pci_find_child_device() local
143 for_each_child_of_node(parent, node) { in of_pci_find_child_device()
144 if (__of_pci_pci_compare(node, devfn)) in of_pci_find_child_device()
145 return node; in of_pci_find_child_device()
147 * Some OFs create a parent node "multifunc-device" as in of_pci_find_child_device()
148 * a fake root for all functions of a multi-function in of_pci_find_child_device()
151 if (of_node_name_eq(node, "multifunc-device")) { in of_pci_find_child_device()
152 for_each_child_of_node(node, node2) { in of_pci_find_child_device()
154 of_node_put(node); in of_pci_find_child_device()
165 * of_pci_get_devfn() - Get device and function numbers for a device node
166 * @np: device node
168 * Parses a standard 5-cell PCI resource and returns an 8-bit value that can
187 * of_pci_parse_bus_range() - parse the bus-range property of a PCI device
188 * @node: device node
189 * @res: address to a struct resource to return the bus-range
191 * Returns 0 on success or a negative error-code on failure.
193 int of_pci_parse_bus_range(struct device_node *node, struct resource *res) in of_pci_parse_bus_range() argument
198 error = of_property_read_u32_array(node, "bus-range", bus_range, in of_pci_parse_bus_range()
203 res->name = node->name; in of_pci_parse_bus_range()
204 res->start = bus_range[0]; in of_pci_parse_bus_range()
205 res->end = bus_range[1]; in of_pci_parse_bus_range()
206 res->flags = IORESOURCE_BUS; in of_pci_parse_bus_range()
213 * of_get_pci_domain_nr - Find the host bridge domain number
214 * of the given device node.
215 * @node: Device tree node with the domain information.
218 * a property called "linux,pci-domain" of the given device node.
221 * * > 0 - On success, an associated domain number.
222 * * -EINVAL - The property "linux,pci-domain" does not exist.
223 * * -ENODATA - The linux,pci-domain" property does not have value.
224 * * -EOVERFLOW - Invalid "linux,pci-domain" property value.
226 * Returns the associated domain number from DT in the range [0-0xffff], or
229 int of_get_pci_domain_nr(struct device_node *node) in of_get_pci_domain_nr() argument
234 error = of_property_read_u32(node, "linux,pci-domain", &domain); in of_get_pci_domain_nr()
243 * of_pci_preserve_config - Return true if the boot configuration needs to
245 * @node: Device tree node.
247 * Look for "linux,pci-probe-only" property for a given PCI controller's
248 * node and return true if found. Also look in the chosen node if the
249 * property is not found in the given controller's node. Having this
255 bool of_pci_preserve_config(struct device_node *node) in of_pci_preserve_config() argument
260 if (!node) { in of_pci_preserve_config()
261 pr_warn("device node is NULL, trying with of_chosen\n"); in of_pci_preserve_config()
262 node = of_chosen; in of_pci_preserve_config()
266 ret = of_property_read_u32(node, "linux,pci-probe-only", &val); in of_pci_preserve_config()
268 if (ret == -ENODATA || ret == -EOVERFLOW) { in of_pci_preserve_config()
269 pr_warn("Incorrect value for linux,pci-probe-only in %pOF, ignoring\n", in of_pci_preserve_config()
270 node); in of_pci_preserve_config()
273 if (ret == -EINVAL) { in of_pci_preserve_config()
274 if (node == of_chosen) in of_pci_preserve_config()
277 node = of_chosen; in of_pci_preserve_config()
289 * of_pci_check_probe_only - Setup probe only mode if linux,pci-probe-only
302 * devm_of_pci_get_host_bridge_resources() - Resource-managed parsing of PCI
303 * host bridge resources from DT
307 * @resources: list where the range of resources will be added after DT parsing
309 * from 'dma-ranges') will be added after DT parsing
315 * node and setup the resource mapping based on its content. It is expected
327 struct device_node *dev_node = dev->of_node; in devm_of_pci_get_host_bridge_resources()
340 return -ENOMEM; in devm_of_pci_get_host_bridge_resources()
346 bus_range->start = busno; in devm_of_pci_get_host_bridge_resources()
347 bus_range->end = bus_max; in devm_of_pci_get_host_bridge_resources()
348 bus_range->flags = IORESOURCE_BUS; in devm_of_pci_get_host_bridge_resources()
352 if (bus_range->end > bus_range->start + bus_max) in devm_of_pci_get_host_bridge_resources()
353 bus_range->end = bus_range->start + bus_max; in devm_of_pci_get_host_bridge_resources()
371 dev_info(dev, " %6s %#012llx..%#012llx -> %#012llx\n", in devm_of_pci_get_host_bridge_resources()
373 range.cpu_addr + range.size - 1, range.pci_addr); in devm_of_pci_get_host_bridge_resources()
376 * If we failed translation or got a zero-sized region in devm_of_pci_get_host_bridge_resources()
388 err = -ENOMEM; in devm_of_pci_get_host_bridge_resources()
396 err = -EINVAL; in devm_of_pci_get_host_bridge_resources()
404 res->flags &= ~IORESOURCE_MEM_64; in devm_of_pci_get_host_bridge_resources()
407 pci_add_resource_offset(resources, res, res->start - range.pci_addr); in devm_of_pci_get_host_bridge_resources()
410 /* Check for dma-ranges property */ in devm_of_pci_get_host_bridge_resources()
417 dev_dbg(dev, "Parsing dma-ranges property...\n"); in devm_of_pci_get_host_bridge_resources()
420 * If we failed translation or got a zero-sized region in devm_of_pci_get_host_bridge_resources()
427 dev_info(dev, " %6s %#012llx..%#012llx -> %#012llx\n", in devm_of_pci_get_host_bridge_resources()
429 range.cpu_addr + range.size - 1, range.pci_addr); in devm_of_pci_get_host_bridge_resources()
438 err = -ENOMEM; in devm_of_pci_get_host_bridge_resources()
443 res->start - range.pci_addr); in devm_of_pci_get_host_bridge_resources()
455 * of_irq_parse_pci - Resolve the interrupt for a PCI device
460 * device-node exists for a given pci_dev, it will use normal OF tree
462 * PCI tree until an device-node is found, at which point it will finish
474 * Check if we have a device node, if yes, fallback to standard in of_irq_parse_pci()
486 * interrupt spec. we assume #interrupt-cells is 1, which is standard in of_irq_parse_pci()
494 return -ENODEV; in of_irq_parse_pci()
496 /* Local interrupt-map in the device node? Use it! */ in of_irq_parse_pci()
497 if (of_property_present(dn, "interrupt-map")) { in of_irq_parse_pci()
505 ppdev = pdev->bus->self; in of_irq_parse_pci()
509 ppnode = pci_bus_to_OF_node(pdev->bus); in of_irq_parse_pci()
511 /* No node for host bridge ? give up */ in of_irq_parse_pci()
513 rc = -EINVAL; in of_irq_parse_pci()
517 /* We found a P2P bridge, check if it has a node */ in of_irq_parse_pci()
522 * Ok, we have found a parent with a device-node, hand over to in of_irq_parse_pci()
527 * Fortunately, in most cases, interrupt-map-mask doesn't in of_irq_parse_pci()
537 * We can only get here if we hit a P2P bridge with no node; in of_irq_parse_pci()
544 out_irq->np = ppnode; in of_irq_parse_pci()
545 out_irq->args_count = 1; in of_irq_parse_pci()
546 out_irq->args[0] = pin; in of_irq_parse_pci()
547 laddr[0] = cpu_to_be32((pdev->bus->number << 16) | (pdev->devfn << 8)); in of_irq_parse_pci()
554 if (rc == -ENOENT) { in of_irq_parse_pci()
555 dev_warn(&pdev->dev, in of_irq_parse_pci()
556 "%s: no interrupt-map found, INTx interrupts not available\n", in of_irq_parse_pci()
561 dev_err(&pdev->dev, "%s: failed with rc=%d\n", __func__, rc); in of_irq_parse_pci()
567 * of_irq_parse_and_map_pci() - Decode a PCI IRQ from the device tree and map to a VIRQ
597 INIT_LIST_HEAD(&bridge->windows); in pci_parse_request_of_pci_ranges()
598 INIT_LIST_HEAD(&bridge->dma_ranges); in pci_parse_request_of_pci_ranges()
600 err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &bridge->windows, in pci_parse_request_of_pci_ranges()
601 &bridge->dma_ranges, &iobase); in pci_parse_request_of_pci_ranges()
605 err = devm_request_pci_bus_resources(dev, &bridge->windows); in pci_parse_request_of_pci_ranges()
609 resource_list_for_each_entry_safe(win, tmp, &bridge->windows) { in pci_parse_request_of_pci_ranges()
610 struct resource *res = win->res; in pci_parse_request_of_pci_ranges()
622 res_valid |= !(res->flags & IORESOURCE_PREFETCH); in pci_parse_request_of_pci_ranges()
624 if (!(res->flags & IORESOURCE_PREFETCH)) in pci_parse_request_of_pci_ranges()
633 dev_warn(dev, "non-prefetchable memory resource required\n"); in pci_parse_request_of_pci_ranges()
640 if (!dev->of_node) in devm_of_pci_bridge_init()
643 bridge->swizzle_irq = pci_common_swizzle; in devm_of_pci_bridge_init()
644 bridge->map_irq = of_irq_parse_and_map_pci; in devm_of_pci_bridge_init()
658 pdev->dev.of_node = NULL; in of_pci_remove_node()
660 of_changeset_revert(np->data); in of_pci_remove_node()
661 of_changeset_destroy(np->data); in of_pci_remove_node()
674 * If there is already a device tree node linked to this device, in of_pci_make_dev_node()
680 /* Check if there is device tree node for parent device */ in of_pci_make_dev_node()
681 if (!pdev->bus->self) in of_pci_make_dev_node()
682 ppnode = pdev->bus->dev.of_node; in of_pci_make_dev_node()
684 ppnode = pdev->bus->self->dev.of_node; in of_pci_make_dev_node()
694 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); in of_pci_make_dev_node()
715 np->data = cset; in of_pci_make_dev_node()
716 pdev->dev.of_node = np; in of_pci_make_dev_node()
734 * of_pci_get_max_link_speed - Find the maximum link speed of the given device node.
735 * @node: Device tree node with the maximum link speed information.
738 * a property called "max-link-speed" of the given device node.
741 * * > 0 - On success, a maximum link speed.
742 * * -EINVAL - Invalid "max-link-speed" property value, or failure to access
743 * the property of the device tree node.
745 * Returns the associated max link speed from DT, or a negative value if the
748 int of_pci_get_max_link_speed(struct device_node *node) in of_pci_get_max_link_speed() argument
752 if (of_property_read_u32(node, "max-link-speed", &max_link_speed) || in of_pci_get_max_link_speed()
754 return -EINVAL; in of_pci_get_max_link_speed()
761 * of_pci_get_slot_power_limit - Parses the "slot-power-limit-milliwatt"
764 * @node: device tree node with the slot power limit information
771 * and @slot_power_limit_scale pointers are non-NULL, fills in the value and
776 u32 of_pci_get_slot_power_limit(struct device_node *node, in of_pci_get_slot_power_limit() argument
783 if (of_property_read_u32(node, "slot-power-limit-milliwatt", in of_pci_get_slot_power_limit()
811 value = 0xF0 + (slot_power_limit_mw / 1000 - 250) / 25; in of_pci_get_slot_power_limit()