Lines Matching +full:bus +full:- +full:range
1 // SPDX-License-Identifier: GPL-2.0+
3 * PCI <-> OF mapping helpers
20 * pci_set_of_node - Find and set device's DT device_node
24 * 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 node = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn); in pci_set_of_node()
37 device_set_node(&dev->dev, of_fwnode_handle(node)); in pci_set_of_node()
43 of_node_put(dev->dev.of_node); in pci_release_of_node()
44 device_set_node(&dev->dev, NULL); in pci_release_of_node()
47 void pci_set_bus_of_node(struct pci_bus *bus) in pci_set_bus_of_node() argument
51 if (bus->self == NULL) { in pci_set_bus_of_node()
52 node = pcibios_get_phb_of_node(bus); in pci_set_bus_of_node()
54 node = of_node_get(bus->self->dev.of_node); in pci_set_bus_of_node()
55 if (node && of_property_read_bool(node, "external-facing")) in pci_set_bus_of_node()
56 bus->self->external_facing = true; in pci_set_bus_of_node()
59 device_set_node(&bus->dev, of_fwnode_handle(node)); in pci_set_bus_of_node()
62 void pci_release_bus_of_node(struct pci_bus *bus) in pci_release_bus_of_node() argument
64 of_node_put(bus->dev.of_node); in pci_release_bus_of_node()
65 device_set_node(&bus->dev, NULL); in pci_release_bus_of_node()
68 struct device_node * __weak pcibios_get_phb_of_node(struct pci_bus *bus) in pcibios_get_phb_of_node() argument
71 if (WARN_ON(bus->self || bus->parent)) in pcibios_get_phb_of_node()
76 * create above the root bus or its own parent. Normally only in pcibios_get_phb_of_node()
79 if (bus->bridge->of_node) in pcibios_get_phb_of_node()
80 return of_node_get(bus->bridge->of_node); in pcibios_get_phb_of_node()
81 if (bus->bridge->parent && bus->bridge->parent->of_node) in pcibios_get_phb_of_node()
82 return of_node_get(bus->bridge->parent->of_node); in pcibios_get_phb_of_node()
86 struct irq_domain *pci_host_bridge_of_msi_domain(struct pci_bus *bus) in pci_host_bridge_of_msi_domain() argument
91 if (!bus->dev.of_node) in pci_host_bridge_of_msi_domain()
95 d = of_msi_get_domain(&bus->dev, bus->dev.of_node, DOMAIN_BUS_PCI_MSI); in pci_host_bridge_of_msi_domain()
100 * If we don't have an msi-parent property, look for a domain in pci_host_bridge_of_msi_domain()
103 d = irq_find_matching_host(bus->dev.of_node, DOMAIN_BUS_PCI_MSI); in pci_host_bridge_of_msi_domain()
107 return irq_find_host(bus->dev.of_node); in pci_host_bridge_of_msi_domain()
115 if (dev && dev->of_node) in pci_host_of_has_msi_map()
116 return of_get_property(dev->of_node, "msi-map", NULL); in pci_host_of_has_msi_map()
141 * Some OFs create a parent node "multifunc-device" as in of_pci_find_child_device()
142 * a fake root for all functions of a multi-function in of_pci_find_child_device()
145 if (of_node_name_eq(node, "multifunc-device")) { in of_pci_find_child_device()
159 * of_pci_get_devfn() - Get device and function numbers for a device node
162 * Parses a standard 5-cell PCI resource and returns an 8-bit value that can
181 * of_pci_parse_bus_range() - parse the bus-range property of a PCI device
183 * @res: address to a struct resource to return the bus-range
185 * Returns 0 on success or a negative error-code on failure.
192 error = of_property_read_u32_array(node, "bus-range", bus_range, in of_pci_parse_bus_range()
197 res->name = node->name; in of_pci_parse_bus_range()
198 res->start = bus_range[0]; in of_pci_parse_bus_range()
199 res->end = bus_range[1]; in of_pci_parse_bus_range()
200 res->flags = IORESOURCE_BUS; in of_pci_parse_bus_range()
207 * of_get_pci_domain_nr - Find the host bridge domain number
212 * a property called "linux,pci-domain" of the given device node.
215 * * > 0 - On success, an associated domain number.
216 * * -EINVAL - The property "linux,pci-domain" does not exist.
217 * * -ENODATA - The linux,pci-domain" property does not have value.
218 * * -EOVERFLOW - Invalid "linux,pci-domain" property value.
220 * Returns the associated domain number from DT in the range [0-0xffff], or
228 error = of_property_read_u32(node, "linux,pci-domain", &domain); in of_get_pci_domain_nr()
237 * of_pci_check_probe_only - Setup probe only mode if linux,pci-probe-only
245 ret = of_property_read_u32(of_chosen, "linux,pci-probe-only", &val); in of_pci_check_probe_only()
247 if (ret == -ENODATA || ret == -EOVERFLOW) in of_pci_check_probe_only()
248 pr_warn("linux,pci-probe-only without valid value, ignoring\n"); in of_pci_check_probe_only()
262 * devm_of_pci_get_host_bridge_resources() - Resource-managed parsing of PCI
265 * @busno: bus number associated with the bridge root bus
267 * @resources: list where the range of resources will be added after DT parsing
268 * @ib_resources: list where the range of inbound resources (with addresses
269 * from 'dma-ranges') will be added after DT parsing
271 * address for the start of the I/O range. Can be NULL if the caller doesn't
278 * It returns zero if the range parsing has been successful or a standard error
287 struct device_node *dev_node = dev->of_node; in devm_of_pci_get_host_bridge_resources()
290 struct of_pci_range range; in devm_of_pci_get_host_bridge_resources() local
300 return -ENOMEM; in devm_of_pci_get_host_bridge_resources()
306 bus_range->start = busno; in devm_of_pci_get_host_bridge_resources()
307 bus_range->end = bus_max; in devm_of_pci_get_host_bridge_resources()
308 bus_range->flags = IORESOURCE_BUS; in devm_of_pci_get_host_bridge_resources()
309 dev_info(dev, " No bus range found for %pOF, using %pR\n", in devm_of_pci_get_host_bridge_resources()
312 if (bus_range->end > bus_range->start + bus_max) in devm_of_pci_get_host_bridge_resources()
313 bus_range->end = bus_range->start + bus_max; in devm_of_pci_get_host_bridge_resources()
323 for_each_of_pci_range(&parser, &range) { in devm_of_pci_get_host_bridge_resources()
325 if ((range.flags & IORESOURCE_TYPE_BITS) == IORESOURCE_IO) in devm_of_pci_get_host_bridge_resources()
327 else if ((range.flags & IORESOURCE_TYPE_BITS) == IORESOURCE_MEM) in devm_of_pci_get_host_bridge_resources()
331 dev_info(dev, " %6s %#012llx..%#012llx -> %#012llx\n", in devm_of_pci_get_host_bridge_resources()
332 range_type, range.cpu_addr, in devm_of_pci_get_host_bridge_resources()
333 range.cpu_addr + range.size - 1, range.pci_addr); in devm_of_pci_get_host_bridge_resources()
336 * If we failed translation or got a zero-sized region in devm_of_pci_get_host_bridge_resources()
337 * then skip this range in devm_of_pci_get_host_bridge_resources()
339 if (range.cpu_addr == OF_BAD_ADDR || range.size == 0) in devm_of_pci_get_host_bridge_resources()
342 err = of_pci_range_to_resource(&range, dev_node, &tmp_res); in devm_of_pci_get_host_bridge_resources()
348 err = -ENOMEM; in devm_of_pci_get_host_bridge_resources()
354 …dev_err(dev, "I/O range found for %pOF. Please provide an io_base pointer to save CPU base address… in devm_of_pci_get_host_bridge_resources()
356 err = -EINVAL; in devm_of_pci_get_host_bridge_resources()
360 …dev_warn(dev, "More than one I/O resource converted for %pOF. CPU base address for old range lost!… in devm_of_pci_get_host_bridge_resources()
362 *io_base = range.cpu_addr; in devm_of_pci_get_host_bridge_resources()
364 res->flags &= ~IORESOURCE_MEM_64; in devm_of_pci_get_host_bridge_resources()
367 pci_add_resource_offset(resources, res, res->start - range.pci_addr); in devm_of_pci_get_host_bridge_resources()
370 /* Check for dma-ranges property */ in devm_of_pci_get_host_bridge_resources()
377 dev_dbg(dev, "Parsing dma-ranges property...\n"); in devm_of_pci_get_host_bridge_resources()
378 for_each_of_pci_range(&parser, &range) { in devm_of_pci_get_host_bridge_resources()
380 * If we failed translation or got a zero-sized region in devm_of_pci_get_host_bridge_resources()
381 * then skip this range in devm_of_pci_get_host_bridge_resources()
383 if (((range.flags & IORESOURCE_TYPE_BITS) != IORESOURCE_MEM) || in devm_of_pci_get_host_bridge_resources()
384 range.cpu_addr == OF_BAD_ADDR || range.size == 0) in devm_of_pci_get_host_bridge_resources()
387 dev_info(dev, " %6s %#012llx..%#012llx -> %#012llx\n", in devm_of_pci_get_host_bridge_resources()
388 "IB MEM", range.cpu_addr, in devm_of_pci_get_host_bridge_resources()
389 range.cpu_addr + range.size - 1, range.pci_addr); in devm_of_pci_get_host_bridge_resources()
392 err = of_pci_range_to_resource(&range, dev_node, &tmp_res); in devm_of_pci_get_host_bridge_resources()
398 err = -ENOMEM; in devm_of_pci_get_host_bridge_resources()
403 res->start - range.pci_addr); in devm_of_pci_get_host_bridge_resources()
415 * of_irq_parse_pci - Resolve the interrupt for a PCI device
420 * device-node exists for a given pci_dev, it will use normal OF tree
422 * PCI tree until an device-node is found, at which point it will finish
446 * interrupt spec. we assume #interrupt-cells is 1, which is standard in of_irq_parse_pci()
454 return -ENODEV; in of_irq_parse_pci()
456 /* Local interrupt-map in the device node? Use it! */ in of_irq_parse_pci()
457 if (of_property_present(dn, "interrupt-map")) { in of_irq_parse_pci()
465 ppdev = pdev->bus->self; in of_irq_parse_pci()
469 ppnode = pci_bus_to_OF_node(pdev->bus); in of_irq_parse_pci()
473 rc = -EINVAL; in of_irq_parse_pci()
482 * Ok, we have found a parent with a device-node, hand over to in of_irq_parse_pci()
485 * resolution. Note that we use the linux bus number which may in of_irq_parse_pci()
486 * not match your firmware bus numbering. in of_irq_parse_pci()
487 * Fortunately, in most cases, interrupt-map-mask doesn't in of_irq_parse_pci()
488 * include the bus number as part of the matching. in of_irq_parse_pci()
504 out_irq->np = ppnode; in of_irq_parse_pci()
505 out_irq->args_count = 1; in of_irq_parse_pci()
506 out_irq->args[0] = pin; in of_irq_parse_pci()
507 laddr[0] = cpu_to_be32((pdev->bus->number << 16) | (pdev->devfn << 8)); in of_irq_parse_pci()
514 if (rc == -ENOENT) { in of_irq_parse_pci()
515 dev_warn(&pdev->dev, in of_irq_parse_pci()
516 "%s: no interrupt-map found, INTx interrupts not available\n", in of_irq_parse_pci()
521 dev_err(&pdev->dev, "%s: failed with rc=%d\n", __func__, rc); in of_irq_parse_pci()
527 * of_irq_parse_and_map_pci() - Decode a PCI IRQ from the device tree and map to a VIRQ
557 INIT_LIST_HEAD(&bridge->windows); in pci_parse_request_of_pci_ranges()
558 INIT_LIST_HEAD(&bridge->dma_ranges); in pci_parse_request_of_pci_ranges()
560 err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &bridge->windows, in pci_parse_request_of_pci_ranges()
561 &bridge->dma_ranges, &iobase); in pci_parse_request_of_pci_ranges()
565 err = devm_request_pci_bus_resources(dev, &bridge->windows); in pci_parse_request_of_pci_ranges()
569 resource_list_for_each_entry_safe(win, tmp, &bridge->windows) { in pci_parse_request_of_pci_ranges()
570 struct resource *res = win->res; in pci_parse_request_of_pci_ranges()
582 res_valid |= !(res->flags & IORESOURCE_PREFETCH); in pci_parse_request_of_pci_ranges()
584 if (!(res->flags & IORESOURCE_PREFETCH)) in pci_parse_request_of_pci_ranges()
593 dev_warn(dev, "non-prefetchable memory resource required\n"); in pci_parse_request_of_pci_ranges()
600 if (!dev->of_node) in devm_of_pci_bridge_init()
603 bridge->swizzle_irq = pci_common_swizzle; in devm_of_pci_bridge_init()
604 bridge->map_irq = of_irq_parse_and_map_pci; in devm_of_pci_bridge_init()
618 pdev->dev.of_node = NULL; in of_pci_remove_node()
620 of_changeset_revert(np->data); in of_pci_remove_node()
621 of_changeset_destroy(np->data); in of_pci_remove_node()
641 if (!pdev->bus->self) in of_pci_make_dev_node()
642 ppnode = pdev->bus->dev.of_node; in of_pci_make_dev_node()
644 ppnode = pdev->bus->self->dev.of_node; in of_pci_make_dev_node()
654 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn)); in of_pci_make_dev_node()
675 np->data = cset; in of_pci_make_dev_node()
676 pdev->dev.of_node = np; in of_pci_make_dev_node()
694 * of_pci_get_max_link_speed - Find the maximum link speed of the given device node.
698 * a property called "max-link-speed" of the given device node.
701 * * > 0 - On success, a maximum link speed.
702 * * -EINVAL - Invalid "max-link-speed" property value, or failure to access
712 if (of_property_read_u32(node, "max-link-speed", &max_link_speed) || in of_pci_get_max_link_speed()
714 return -EINVAL; in of_pci_get_max_link_speed()
721 * of_pci_get_slot_power_limit - Parses the "slot-power-limit-milliwatt"
731 * and @slot_power_limit_scale pointers are non-NULL, fills in the value and
743 if (of_property_read_u32(node, "slot-power-limit-milliwatt", in of_pci_get_slot_power_limit()
771 value = 0xF0 + (slot_power_limit_mw / 1000 - 250) / 25; in of_pci_get_slot_power_limit()