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"
21 if (!dev->bus->dev.of_node) in pci_set_of_node()
23 dev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node, in pci_set_of_node()
24 dev->devfn); in pci_set_of_node()
25 if (dev->dev.of_node) in pci_set_of_node()
26 dev->dev.fwnode = &dev->dev.of_node->fwnode; in pci_set_of_node()
31 of_node_put(dev->dev.of_node); in pci_release_of_node()
32 dev->dev.of_node = NULL; in pci_release_of_node()
33 dev->dev.fwnode = NULL; in pci_release_of_node()
40 if (bus->self == NULL) { in pci_set_bus_of_node()
43 node = of_node_get(bus->self->dev.of_node); in pci_set_bus_of_node()
44 if (node && of_property_read_bool(node, "external-facing")) in pci_set_bus_of_node()
45 bus->self->external_facing = true; in pci_set_bus_of_node()
48 bus->dev.of_node = node; in pci_set_bus_of_node()
50 if (bus->dev.of_node) in pci_set_bus_of_node()
51 bus->dev.fwnode = &bus->dev.of_node->fwnode; in pci_set_bus_of_node()
56 of_node_put(bus->dev.of_node); in pci_release_bus_of_node()
57 bus->dev.of_node = NULL; in pci_release_bus_of_node()
58 bus->dev.fwnode = NULL; in pci_release_bus_of_node()
64 if (WARN_ON(bus->self || bus->parent)) in pcibios_get_phb_of_node()
72 if (bus->bridge->of_node) in pcibios_get_phb_of_node()
73 return of_node_get(bus->bridge->of_node); in pcibios_get_phb_of_node()
74 if (bus->bridge->parent && bus->bridge->parent->of_node) in pcibios_get_phb_of_node()
75 return of_node_get(bus->bridge->parent->of_node); in pcibios_get_phb_of_node()
84 if (!bus->dev.of_node) in pci_host_bridge_of_msi_domain()
88 d = of_msi_get_domain(&bus->dev, bus->dev.of_node, DOMAIN_BUS_PCI_MSI); in pci_host_bridge_of_msi_domain()
93 * If we don't have an msi-parent property, look for a domain in pci_host_bridge_of_msi_domain()
96 d = irq_find_matching_host(bus->dev.of_node, DOMAIN_BUS_PCI_MSI); in pci_host_bridge_of_msi_domain()
100 return irq_find_host(bus->dev.of_node); in pci_host_bridge_of_msi_domain()
127 * Some OFs create a parent node "multifunc-device" as in of_pci_find_child_device()
128 * a fake root for all functions of a multi-function in of_pci_find_child_device()
131 if (of_node_name_eq(node, "multifunc-device")) { in of_pci_find_child_device()
145 * of_pci_get_devfn() - Get device and function numbers for a device node
148 * Parses a standard 5-cell PCI resource and returns an 8-bit value that can
167 * of_pci_parse_bus_range() - parse the bus-range property of a PCI device
169 * @res: address to a struct resource to return the bus-range
171 * Returns 0 on success or a negative error-code on failure.
178 error = of_property_read_u32_array(node, "bus-range", bus_range, in of_pci_parse_bus_range()
183 res->name = node->name; in of_pci_parse_bus_range()
184 res->start = bus_range[0]; in of_pci_parse_bus_range()
185 res->end = bus_range[1]; in of_pci_parse_bus_range()
186 res->flags = IORESOURCE_BUS; in of_pci_parse_bus_range()
193 * This function will try to obtain the host bridge domain number by
194 * finding a property called "linux,pci-domain" of the given device node.
196 * @node: device tree node with the domain information
198 * Returns the associated domain number from DT in the range [0-0xffff], or
203 u32 domain; in of_get_pci_domain_nr() local
206 error = of_property_read_u32(node, "linux,pci-domain", &domain); in of_get_pci_domain_nr()
210 return (u16)domain; in of_get_pci_domain_nr()
215 * of_pci_check_probe_only - Setup probe only mode if linux,pci-probe-only
223 ret = of_property_read_u32(of_chosen, "linux,pci-probe-only", &val); in of_pci_check_probe_only()
225 if (ret == -ENODATA || ret == -EOVERFLOW) in of_pci_check_probe_only()
226 pr_warn("linux,pci-probe-only without valid value, ignoring\n"); in of_pci_check_probe_only()
240 * devm_of_pci_get_host_bridge_resources() - Resource-managed parsing of PCI
247 * from 'dma-ranges') will be added after DT parsing
252 * This function will parse the "ranges" property of a PCI host bridge device
265 struct device_node *dev_node = dev->of_node; in devm_of_pci_get_host_bridge_resources()
278 return -ENOMEM; in devm_of_pci_get_host_bridge_resources()
284 bus_range->start = busno; in devm_of_pci_get_host_bridge_resources()
285 bus_range->end = bus_max; in devm_of_pci_get_host_bridge_resources()
286 bus_range->flags = IORESOURCE_BUS; in devm_of_pci_get_host_bridge_resources()
290 if (bus_range->end > bus_range->start + bus_max) in devm_of_pci_get_host_bridge_resources()
291 bus_range->end = bus_range->start + bus_max; in devm_of_pci_get_host_bridge_resources()
309 dev_info(dev, " %6s %#012llx..%#012llx -> %#012llx\n", in devm_of_pci_get_host_bridge_resources()
311 range.cpu_addr + range.size - 1, range.pci_addr); in devm_of_pci_get_host_bridge_resources()
314 * If we failed translation or got a zero-sized region in devm_of_pci_get_host_bridge_resources()
326 err = -ENOMEM; in devm_of_pci_get_host_bridge_resources()
334 err = -EINVAL; in devm_of_pci_get_host_bridge_resources()
343 pci_add_resource_offset(resources, res, res->start - range.pci_addr); in devm_of_pci_get_host_bridge_resources()
346 /* Check for dma-ranges property */ in devm_of_pci_get_host_bridge_resources()
353 dev_dbg(dev, "Parsing dma-ranges property...\n"); in devm_of_pci_get_host_bridge_resources()
357 * If we failed translation or got a zero-sized region in devm_of_pci_get_host_bridge_resources()
364 dev_info(dev, " %6s %#012llx..%#012llx -> %#012llx\n", in devm_of_pci_get_host_bridge_resources()
366 range.cpu_addr + range.size - 1, range.pci_addr); in devm_of_pci_get_host_bridge_resources()
375 err = -ENOMEM; in devm_of_pci_get_host_bridge_resources()
381 if (entry->res->start > res->start) in devm_of_pci_get_host_bridge_resources()
384 pci_add_resource_offset(&entry->node, res, in devm_of_pci_get_host_bridge_resources()
385 res->start - range.pci_addr); in devm_of_pci_get_host_bridge_resources()
397 * of_irq_parse_pci - Resolve the interrupt for a PCI device
401 * This function resolves the PCI interrupt for a given PCI device. If a
402 * device-node exists for a given pci_dev, it will use normal OF tree
404 * PCI tree until an device-node is found, at which point it will finish
428 * interrupt spec. we assume #interrupt-cells is 1, which is standard in of_irq_parse_pci()
429 * for PCI. If you do different, then don't use that routine. in of_irq_parse_pci()
436 return -ENODEV; in of_irq_parse_pci()
438 /* Now we walk up the PCI tree */ in of_irq_parse_pci()
441 ppdev = pdev->bus->self; in of_irq_parse_pci()
445 ppnode = pci_bus_to_OF_node(pdev->bus); in of_irq_parse_pci()
449 rc = -EINVAL; in of_irq_parse_pci()
458 * Ok, we have found a parent with a device-node, hand over to in of_irq_parse_pci()
463 * Fortunately, in most cases, interrupt-map-mask doesn't in of_irq_parse_pci()
467 * create device nodes for all PCI devices). in of_irq_parse_pci()
480 out_irq->np = ppnode; in of_irq_parse_pci()
481 out_irq->args_count = 1; in of_irq_parse_pci()
482 out_irq->args[0] = pin; in of_irq_parse_pci()
483 laddr[0] = cpu_to_be32((pdev->bus->number << 16) | (pdev->devfn << 8)); in of_irq_parse_pci()
490 if (rc == -ENOENT) { in of_irq_parse_pci()
491 dev_warn(&pdev->dev, in of_irq_parse_pci()
492 "%s: no interrupt-map found, INTx interrupts not available\n", in of_irq_parse_pci()
494 pr_warn_once("%s: possibly some PCI slots don't have level triggered interrupts capability\n", in of_irq_parse_pci()
497 dev_err(&pdev->dev, "%s: failed with rc=%d\n", __func__, rc); in of_irq_parse_pci()
503 * of_irq_parse_and_map_pci() - Decode a PCI IRQ from the device tree and map to a VIRQ
504 * @dev: The PCI device needing an IRQ
505 * @slot: PCI slot number; passed when used as map_irq callback. Unused
506 * @pin: PCI IRQ pin number; passed when used as map_irq callback. Unused
533 INIT_LIST_HEAD(&bridge->windows); in pci_parse_request_of_pci_ranges()
534 INIT_LIST_HEAD(&bridge->dma_ranges); in pci_parse_request_of_pci_ranges()
536 err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &bridge->windows, in pci_parse_request_of_pci_ranges()
537 &bridge->dma_ranges, &iobase); in pci_parse_request_of_pci_ranges()
541 err = devm_request_pci_bus_resources(dev, &bridge->windows); in pci_parse_request_of_pci_ranges()
545 resource_list_for_each_entry_safe(win, tmp, &bridge->windows) { in pci_parse_request_of_pci_ranges()
546 struct resource *res = win->res; in pci_parse_request_of_pci_ranges()
558 res_valid |= !(res->flags & IORESOURCE_PREFETCH); in pci_parse_request_of_pci_ranges()
564 dev_warn(dev, "non-prefetchable memory resource required\n"); in pci_parse_request_of_pci_ranges()
571 if (!dev->of_node) in devm_of_pci_bridge_init()
574 bridge->swizzle_irq = pci_common_swizzle; in devm_of_pci_bridge_init()
575 bridge->map_irq = of_irq_parse_and_map_pci; in devm_of_pci_bridge_init()
584 * a property called "max-link-speed" of the given device node.
595 if (of_property_read_u32(node, "max-link-speed", &max_link_speed) || in of_pci_get_max_link_speed()
597 return -EINVAL; in of_pci_get_max_link_speed()