Lines Matching +full:bus +full:- +full:range
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)
34 of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn);
41 dev->bus->dev.of_node_reused = true;
43 device_set_node(&dev->dev, of_fwnode_handle(no_free_ptr(node)));
49 of_node_put(dev->dev.of_node);
50 device_set_node(&dev->dev, NULL);
53 void pci_set_bus_of_node(struct pci_bus *bus)
57 if (bus->self == NULL) {
58 node = pcibios_get_phb_of_node(bus);
60 node = of_node_get(bus->self->dev.of_node);
61 if (node && of_property_read_bool(node, "external-facing"))
62 bus->self->external_facing = true;
65 device_set_node(&bus->dev, of_fwnode_handle(node));
68 void pci_release_bus_of_node(struct pci_bus *bus)
70 of_node_put(bus->dev.of_node);
71 device_set_node(&bus->dev, NULL);
74 struct device_node * __weak pcibios_get_phb_of_node(struct pci_bus *bus)
77 if (WARN_ON(bus->self || bus->parent))
82 * create above the root bus or its own parent. Normally only
85 if (bus->bridge->of_node)
86 return of_node_get(bus->bridge->of_node);
87 if (bus->bridge->parent && bus->bridge->parent->of_node)
88 return of_node_get(bus->bridge->parent->of_node);
92 struct irq_domain *pci_host_bridge_of_msi_domain(struct pci_bus *bus)
97 if (!bus->dev.of_node)
101 d = of_msi_get_domain(&bus->dev, bus->dev.of_node, DOMAIN_BUS_PCI_MSI);
106 * If we don't have an msi-parent property, look for a domain
109 d = irq_find_matching_host(bus->dev.of_node, DOMAIN_BUS_PCI_MSI);
113 return irq_find_host(bus->dev.of_node);
121 if (dev && dev->of_node)
122 return of_get_property(dev->of_node, "msi-map", NULL);
147 * Some OFs create a parent node "multifunc-device" as
148 * a fake root for all functions of a multi-function
151 if (of_node_name_eq(node, "multifunc-device")) {
165 * of_pci_get_devfn() - Get device and function numbers for a 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
189 * @res: address to a struct resource to return the bus-range
191 * Returns 0 on success or a negative error-code on failure.
199 error = of_property_read_u32_array(node, "bus-range", bus_range,
204 res->name = node->name;
205 res->start = bus_range[0];
206 res->end = bus_range[1];
207 res->flags = IORESOURCE_BUS;
213 * of_get_pci_domain_nr - Find the host bridge domain number
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
234 error = of_property_read_u32(node, "linux,pci-domain", &domain);
243 * of_pci_preserve_config - Return true if the boot configuration needs to
247 * Look for "linux,pci-probe-only" property for a given PCI controller's
266 ret = of_property_read_u32(node, "linux,pci-probe-only", &val);
268 if (ret == -ENODATA || ret == -EOVERFLOW) {
269 pr_warn("Incorrect value for linux,pci-probe-only in %pOF, ignoring\n",
273 if (ret == -EINVAL) {
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
305 * @resources: list where the range of resources will be added after DT parsing
306 * @ib_resources: list where the range of inbound resources (with addresses
307 * from 'dma-ranges') will be added after DT parsing
309 * address for the start of the I/O range. Can be NULL if the caller doesn't
316 * It returns zero if the range parsing has been successful or a standard error
324 struct device_node *dev_node = dev->of_node;
327 struct of_pci_range range;
337 return -ENOMEM;
343 bus_range->start = 0;
344 bus_range->end = 0xff;
345 bus_range->flags = IORESOURCE_BUS;
347 if (bus_range->end > 0xff) {
348 dev_warn(dev, " Invalid end bus number in %pR, defaulting to 0xff\n",
350 bus_range->end = 0xff;
361 for_each_of_pci_range(&parser, &range) {
363 if ((range.flags & IORESOURCE_TYPE_BITS) == IORESOURCE_IO)
365 else if ((range.flags & IORESOURCE_TYPE_BITS) == IORESOURCE_MEM)
369 dev_info(dev, " %6s %#012llx..%#012llx -> %#012llx\n",
370 range_type, range.cpu_addr,
371 range.cpu_addr + range.size - 1, range.pci_addr);
374 * If we failed translation or got a zero-sized region
375 * then skip this range
377 if (range.cpu_addr == OF_BAD_ADDR || range.size == 0)
380 err = of_pci_range_to_resource(&range, dev_node, &tmp_res);
386 err = -ENOMEM;
392 dev_err(dev, "I/O range found for %pOF. Please provide an io_base pointer to save CPU base address\n",
394 err = -EINVAL;
398 dev_warn(dev, "More than one I/O resource converted for %pOF. CPU base address for old range lost!\n",
400 *io_base = range.cpu_addr;
402 res->flags &= ~IORESOURCE_MEM_64;
405 pci_add_resource_offset(resources, res, res->start - range.pci_addr);
408 /* Check for dma-ranges property */
415 dev_dbg(dev, "Parsing dma-ranges property...\n");
416 for_each_of_pci_range(&parser, &range) {
418 * If we failed translation or got a zero-sized region
419 * then skip this range
421 if (((range.flags & IORESOURCE_TYPE_BITS) != IORESOURCE_MEM) ||
422 range.cpu_addr == OF_BAD_ADDR || range.size == 0)
425 dev_info(dev, " %6s %#012llx..%#012llx -> %#012llx\n",
426 "IB MEM", range.cpu_addr,
427 range.cpu_addr + range.size - 1, range.pci_addr);
430 err = of_pci_range_to_resource(&range, dev_node, &tmp_res);
436 err = -ENOMEM;
441 res->start - range.pci_addr);
453 * of_irq_parse_pci - Resolve the interrupt for a PCI device
484 * interrupt spec. we assume #interrupt-cells is 1, which is standard
492 return -ENODEV;
494 /* Local interrupt-map in the device node? Use it! */
495 if (of_property_present(dn, "interrupt-map")) {
503 ppdev = pdev->bus->self;
507 ppnode = pci_bus_to_OF_node(pdev->bus);
511 rc = -EINVAL;
524 * resolution. Note that we use the linux bus number which may
525 * not match your firmware bus numbering.
527 * Fortunately, in most cases, interrupt-map-mask doesn't
528 * include the bus number as part of the matching.
545 out_irq->np = ppnode;
546 out_irq->args_count = 1;
547 out_irq->args[0] = pin;
548 laddr[0] = cpu_to_be32((pdev->bus->number << 16) | (pdev->devfn << 8));
555 if (rc == -ENOENT) {
556 dev_warn(&pdev->dev,
557 "%s: no interrupt-map found, INTx interrupts not available\n",
562 dev_err(&pdev->dev, "%s: failed with rc=%d\n", __func__, rc);
568 * of_irq_parse_and_map_pci() - Decode a PCI IRQ from the device tree and map to a VIRQ
598 INIT_LIST_HEAD(&bridge->windows);
599 INIT_LIST_HEAD(&bridge->dma_ranges);
601 err = devm_of_pci_get_host_bridge_resources(dev, &bridge->windows,
602 &bridge->dma_ranges, &iobase);
606 err = devm_request_pci_bus_resources(dev, &bridge->windows);
610 resource_list_for_each_entry_safe(win, tmp, &bridge->windows) {
611 struct resource *res = win->res;
623 res_valid |= !(res->flags & IORESOURCE_PREFETCH);
625 if (!(res->flags & IORESOURCE_PREFETCH))
634 dev_warn(dev, "non-prefetchable memory resource required\n");
641 if (!dev->of_node)
644 bridge->swizzle_irq = pci_common_swizzle;
645 bridge->map_irq = of_irq_parse_and_map_pci;
660 device_remove_of_node(&pdev->dev);
661 of_changeset_revert(np->data);
662 of_changeset_destroy(np->data);
682 if (!pdev->bus->self)
683 ppnode = pdev->bus->dev.of_node;
685 ppnode = pdev->bus->self->dev.of_node;
695 PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn));
716 np->data = cset;
718 ret = device_add_of_node(&pdev->dev, np);
727 np->data = NULL;
742 np = pci_bus_to_OF_node(bridge->bus);
746 device_remove_of_node(&bridge->bus->dev);
747 device_remove_of_node(&bridge->dev);
748 of_changeset_revert(np->data);
749 of_changeset_destroy(np->data);
761 * If there is already a device tree node linked to the PCI bus handled
762 * by this bridge (i.e. the PCI root bus), nothing to do.
764 if (pci_bus_to_OF_node(bridge->bus))
768 * The root bus has no node. Check that the host bridge has no node
771 if (bridge->dev.of_node) {
772 dev_err(&bridge->dev, "PCI host bridge of_node already set");
782 name = kasprintf(GFP_KERNEL, "pci@%x,%x", pci_domain_nr(bridge->bus),
783 bridge->bus->number);
803 * bus. Avoid any new device creation.
806 np->fwnode.dev = &bridge->dev;
807 fwnode_dev_initialized(&np->fwnode, true);
813 np->data = cset;
815 /* Add the of_node to host bridge and the root bus */
816 ret = device_add_of_node(&bridge->dev, np);
820 ret = device_add_of_node(&bridge->bus->dev, np);
829 device_remove_of_node(&bridge->dev);
831 np->data = NULL;
845 * of_pci_supply_present() - Check if the power supply is present for the PCI
863 supply = strrchr(prop->name, '-');
864 if (supply && !strcmp(supply, "-supply"))
874 * of_pci_get_max_link_speed - Find the maximum link speed of the given device node.
878 * a property called "max-link-speed" of the given device node.
881 * * > 0 - On success, a maximum link speed.
882 * * -EINVAL - Invalid "max-link-speed" property value, or failure to access
892 if (of_property_read_u32(node, "max-link-speed", &max_link_speed) ||
894 return -EINVAL;
901 * of_pci_get_slot_power_limit - Parses the "slot-power-limit-milliwatt"
911 * and @slot_power_limit_scale pointers are non-NULL, fills in the value and
923 if (of_property_read_u32(node, "slot-power-limit-milliwatt",
951 value = 0xF0 + (slot_power_limit_mw / 1000 - 250) / 25;
971 * of_pci_get_equalization_presets - Parses the "eq-presets-Ngts" property.
990 presets->eq_presets_8gts[0] = PCI_EQ_RESV;
991 ret = of_property_read_u16_array(dev->of_node, "eq-presets-8gts",
992 presets->eq_presets_8gts, num_lanes);
993 if (ret && ret != -EINVAL) {
994 dev_err(dev, "Error reading eq-presets-8gts: %d\n", ret);
998 for (int i = 0; i < EQ_PRESET_TYPE_MAX - 1; i++) {
999 presets->eq_presets_Ngts[i][0] = PCI_EQ_RESV;
1000 snprintf(name, sizeof(name), "eq-presets-%dgts", 8 << (i + 1));
1001 ret = of_property_read_u8_array(dev->of_node, name,
1002 presets->eq_presets_Ngts[i],
1004 if (ret && ret != -EINVAL) {