Lines Matching +full:pci +full:- +full:domain
1 // SPDX-License-Identifier: GPL-2.0+
3 * PCI <-> OF mapping helpers
7 #define pr_fmt(fmt) "PCI: OF: " fmt
11 #include <linux/pci.h>
16 #include "pci.h"
20 * pci_set_of_node - Find and set device's DT device_node
21 * @dev: the PCI device structure to fill
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()
51 if (bus->self == NULL) { 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()
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()
71 if (WARN_ON(bus->self || bus->parent)) 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()
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
209 * @node: Device tree node with the domain information.
211 * This function will try to obtain the host bridge domain number by finding
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
225 u32 domain; in of_get_pci_domain_nr() local
228 error = of_property_read_u32(node, "linux,pci-domain", &domain); in of_get_pci_domain_nr()
232 return (u16)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
269 * from 'dma-ranges') will be added after DT parsing
274 * This function will parse the "ranges" property of a PCI host bridge device
287 struct device_node *dev_node = dev->of_node; in devm_of_pci_get_host_bridge_resources()
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()
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()
331 dev_info(dev, " %6s %#012llx..%#012llx -> %#012llx\n", 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()
348 err = -ENOMEM; in devm_of_pci_get_host_bridge_resources()
356 err = -EINVAL; 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()
380 * If we failed translation or got a zero-sized region 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()
389 range.cpu_addr + range.size - 1, range.pci_addr); 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
419 * This function resolves the PCI interrupt for a given PCI device. If a
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()
447 * for PCI. If you do different, then don't use that routine. 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()
462 /* Now we walk up the PCI tree */ 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()
487 * Fortunately, in most cases, interrupt-map-mask doesn't in of_irq_parse_pci()
491 * create device nodes for all PCI devices). 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()
518 pr_warn_once("%s: possibly some PCI slots don't have level triggered interrupts capability\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
528 * @dev: The PCI device needing an IRQ
529 * @slot: PCI slot number; passed when used as map_irq callback. Unused
530 * @pin: PCI IRQ pin number; passed when used as map_irq callback. Unused
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()
649 pci_type = "pci"; 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()