Lines Matching +full:bus +full:- +full:range

1 // SPDX-License-Identifier: GPL-2.0
17 #include <linux/dma-direct.h> /* for bus_dma_region */
31 while (na--) in of_dump_addr()
39 /* Callbacks for bus specific translators */
46 u64 (*map)(__be32 *addr, const __be32 *range,
54 * Default translator (generic bus)
66 static u64 of_bus_default_map(__be32 *addr, const __be32 *range, in of_bus_default_map() argument
71 cp = of_read_number(range, na); in of_bus_default_map()
72 s = of_read_number(range + na + pna, ns); in of_bus_default_map()
79 return da - cp; in of_bus_default_map()
88 addr[na - 2] = cpu_to_be32(a >> 32); in of_bus_default_translate()
89 addr[na - 1] = cpu_to_be32(a & 0xffffffffu); in of_bus_default_translate()
104 static u64 of_bus_default_flags_map(__be32 *addr, const __be32 *range, int na, in of_bus_default_flags_map() argument
110 if (*addr != *range) in of_bus_default_flags_map()
114 cp = of_read_number(range + 1, na - 1); in of_bus_default_flags_map()
115 s = of_read_number(range + na + pna, ns); in of_bus_default_flags_map()
116 da = of_read_number(addr + 1, na - 1); in of_bus_default_flags_map()
122 return da - cp; in of_bus_default_flags_map()
128 return of_bus_default_translate(addr + 1, offset, na - 1); in of_bus_default_flags_translate()
158 * PCI bus specific translator
175 * "vci" is for the /chaos bridge on 1st-gen PCI powermacs in of_bus_pci_match()
195 static u64 of_bus_pci_map(__be32 *addr, const __be32 *range, int na, int ns, in of_bus_pci_map() argument
202 rf = of_bus_pci_get_flags(range); in of_bus_pci_map()
209 cp = of_read_number(range + 1, na - 1); in of_bus_pci_map()
210 s = of_read_number(range + na + pna, ns); in of_bus_pci_map()
211 da = of_read_number(addr + 1, na - 1); in of_bus_pci_map()
217 return da - cp; in of_bus_pci_map()
223 * of_pci_range_to_resource - Create a resource from an of_pci_range
224 * @range: the PCI range that describes the resource
225 * @np: device node where the range belongs to
227 * reflect the values contained in the range.
229 * Returns -EINVAL if the range cannot be converted to resource.
231 * Note that if the range is an IO range, the resource will be converted
233 * if the range cannot be matched to any host bridge IO space (our case here).
234 * To guard against that we try to register the IO range first.
237 int of_pci_range_to_resource(struct of_pci_range *range, in of_pci_range_to_resource() argument
241 res->flags = range->flags; in of_pci_range_to_resource()
242 res->parent = res->child = res->sibling = NULL; in of_pci_range_to_resource()
243 res->name = np->full_name; in of_pci_range_to_resource()
245 if (res->flags & IORESOURCE_IO) { in of_pci_range_to_resource()
247 err = pci_register_io_range(&np->fwnode, range->cpu_addr, in of_pci_range_to_resource()
248 range->size); in of_pci_range_to_resource()
251 port = pci_address_to_pio(range->cpu_addr); in of_pci_range_to_resource()
252 if (port == (unsigned long)-1) { in of_pci_range_to_resource()
253 err = -EINVAL; in of_pci_range_to_resource()
256 res->start = port; in of_pci_range_to_resource()
259 upper_32_bits(range->cpu_addr)) { in of_pci_range_to_resource()
260 err = -EINVAL; in of_pci_range_to_resource()
264 res->start = range->cpu_addr; in of_pci_range_to_resource()
266 res->end = res->start + range->size - 1; in of_pci_range_to_resource()
270 res->start = (resource_size_t)OF_BAD_ADDR; in of_pci_range_to_resource()
271 res->end = (resource_size_t)OF_BAD_ADDR; in of_pci_range_to_resource()
277 * of_range_to_resource - Create a resource from a ranges entry
278 * @np: device node where the range belongs to
281 * reflect the values contained in the range.
283 * Returns ENOENT if the entry is not found or EINVAL if the range cannot be
290 struct of_range range; in of_range_to_resource() local
296 for_each_of_range(&parser, &range) in of_range_to_resource()
298 return of_pci_range_to_resource(&range, np, res); in of_range_to_resource()
300 return -ENOENT; in of_range_to_resource()
305 * ISA bus specific translator
322 static u64 of_bus_isa_map(__be32 *addr, const __be32 *range, int na, int ns, in of_bus_isa_map() argument
328 if ((addr[0] ^ range[0]) & cpu_to_be32(1)) in of_bus_isa_map()
332 cp = of_read_number(range + 1, na - 1); in of_bus_isa_map()
333 s = of_read_number(range + na + pna, ns); in of_bus_isa_map()
334 da = of_read_number(addr + 1, na - 1); in of_bus_isa_map()
340 return da - cp; in of_bus_isa_map()
361 * Array of bus specific translators
369 .addresses = "assigned-addresses",
391 .name = "default-flags",
427 static int quirk_state = -1; in of_empty_ranges_quirk()
429 /* PA-SEMI sdc DT bug */ in of_empty_ranges_quirk()
430 if (of_device_is_compatible(np, "1682m-sdc")) in of_empty_ranges_quirk()
443 static int of_translate_one(struct device_node *parent, struct of_bus *bus, in of_translate_one() argument
454 * crossing a non-translatable boundary, and thus the addresses in of_translate_one()
457 * what Apple understood, and they do have things like /uni-n or in of_translate_one()
463 * the first place. --BenH. in of_translate_one()
466 * This code is only enabled on powerpc. --gcl in of_translate_one()
468 * This quirk also applies for 'dma-ranges' which frequently exist in in of_translate_one()
469 * child nodes without 'dma-ranges' in the parent nodes. --RobH in of_translate_one()
473 strcmp(rprop, "dma-ranges")) { in of_translate_one()
480 memset(addr + pbus->flag_cells, 0, (pna - pbus->flag_cells) * 4); in of_translate_one()
490 for (; rlen >= rone; rlen -= rone, ranges += rone) { in of_translate_one()
491 offset = bus->map(addr, ranges, na, ns, pna); in of_translate_one()
505 /* Translate it into parent bus space */ in of_translate_one()
506 return pbus->translate(addr, offset, pna); in of_translate_one()
510 * Translate an address from the device-tree into a CPU physical address,
511 * this walks up the tree and applies the various bus mappings on the
514 * Note: We consider that crossing any level with #size-cells == 0 to mean
529 struct of_bus *bus, *pbus; in __of_translate_address() local
540 /* Get parent & match bus type */ in __of_translate_address()
544 bus = of_match_bus(parent); in __of_translate_address()
547 bus->count_cells(dev, &na, &ns); in __of_translate_address()
554 pr_debug("bus is %s (na=%d, ns=%d) on %pOF\n", in __of_translate_address()
555 bus->name, na, ns, parent); in __of_translate_address()
562 /* Switch to parent bus */ in __of_translate_address()
578 iorange = find_io_range_by_fwnode(&dev->fwnode); in __of_translate_address()
579 if (iorange && (iorange->flags != LOGIC_PIO_CPU_MMIO)) { in __of_translate_address()
580 result = of_read_number(addr + 1, na - 1); in __of_translate_address()
587 /* Get new parent bus and counts */ in __of_translate_address()
589 pbus->count_cells(dev, &pna, &pns); in __of_translate_address()
595 pr_debug("parent bus is %s (na=%d, ns=%d) on %pOF\n", in __of_translate_address()
596 pbus->name, pna, pns, parent); in __of_translate_address()
598 /* Apply bus translation */ in __of_translate_address()
599 if (of_translate_one(dev, bus, pbus, addr, na, ns, pna, rprop)) in __of_translate_address()
605 bus = pbus; in __of_translate_address()
638 index = of_property_match_string(np, "interconnect-names", "dma-mem"); in __of_get_dma_parent()
643 "#interconnect-cells", in __of_get_dma_parent()
668 in_addr, "dma-ranges", &host); in of_translate_dma_address()
680 * of_translate_dma_region - Translate device tree address and size tuple
683 * @start: return value for the start of the DMA range
684 * @length: return value for the length of the DMA range
726 struct of_bus *bus; in __of_get_address() local
729 /* Get parent & match bus type */ in __of_get_address()
733 bus = of_match_bus(parent); in __of_get_address()
734 if (strcmp(bus->name, "pci") && (bar_no >= 0)) { in __of_get_address()
738 bus->count_cells(dev, &na, &ns); in __of_get_address()
743 /* Get "reg" or "assigned-addresses" property */ in __of_get_address()
744 prop = of_get_property(dev, bus->addresses, &psize); in __of_get_address()
750 for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) { in __of_get_address()
752 /* PCI bus matches on BAR number instead of index */ in __of_get_address()
758 *flags = bus->get_flags(prop); in __of_get_address()
767 * of_property_read_reg - Retrieve the specified "reg" entry index without translating
773 * Returns -EINVAL if "reg" is not found. Returns 0 on success with addr and
781 return -EINVAL; in of_property_read_reg()
794 parser->node = node; in parser_init()
795 parser->pna = of_n_addr_cells(node); in parser_init()
796 parser->na = of_bus_n_addr_cells(node); in parser_init()
797 parser->ns = of_bus_n_size_cells(node); in parser_init()
798 parser->dma = !strcmp(name, "dma-ranges"); in parser_init()
799 parser->bus = of_match_bus(node); in parser_init()
801 parser->range = of_get_property(node, name, &rlen); in parser_init()
802 if (parser->range == NULL) in parser_init()
803 return -ENOENT; in parser_init()
805 parser->end = parser->range + rlen / sizeof(__be32); in parser_init()
820 return parser_init(parser, node, "dma-ranges"); in of_pci_dma_range_parser_init()
826 struct of_pci_range *range) in of_pci_range_parser_one() argument
828 int na = parser->na; in of_pci_range_parser_one()
829 int ns = parser->ns; in of_pci_range_parser_one()
830 int np = parser->pna + na + ns; in of_pci_range_parser_one()
831 int busflag_na = parser->bus->flag_cells; in of_pci_range_parser_one()
833 if (!range) in of_pci_range_parser_one()
836 if (!parser->range || parser->range + np > parser->end) in of_pci_range_parser_one()
839 range->flags = parser->bus->get_flags(parser->range); in of_pci_range_parser_one()
841 range->bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na); in of_pci_range_parser_one()
843 if (parser->dma) in of_pci_range_parser_one()
844 range->cpu_addr = of_translate_dma_address(parser->node, in of_pci_range_parser_one()
845 parser->range + na); in of_pci_range_parser_one()
847 range->cpu_addr = of_translate_address(parser->node, in of_pci_range_parser_one()
848 parser->range + na); in of_pci_range_parser_one()
849 range->size = of_read_number(parser->range + parser->pna + na, ns); in of_pci_range_parser_one()
851 parser->range += np; in of_pci_range_parser_one()
854 while (parser->range + np <= parser->end) { in of_pci_range_parser_one()
858 flags = parser->bus->get_flags(parser->range); in of_pci_range_parser_one()
859 bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na); in of_pci_range_parser_one()
860 if (parser->dma) in of_pci_range_parser_one()
861 cpu_addr = of_translate_dma_address(parser->node, in of_pci_range_parser_one()
862 parser->range + na); in of_pci_range_parser_one()
864 cpu_addr = of_translate_address(parser->node, in of_pci_range_parser_one()
865 parser->range + na); in of_pci_range_parser_one()
866 size = of_read_number(parser->range + parser->pna + na, ns); in of_pci_range_parser_one()
868 if (flags != range->flags) in of_pci_range_parser_one()
870 if (bus_addr != range->bus_addr + range->size || in of_pci_range_parser_one()
871 cpu_addr != range->cpu_addr + range->size) in of_pci_range_parser_one()
874 range->size += size; in of_pci_range_parser_one()
875 parser->range += np; in of_pci_range_parser_one()
878 return range; in of_pci_range_parser_one()
892 /* host-specific port access */ in of_translate_ioport()
893 port = logic_pio_trans_hwaddr(&host->fwnode, taddr, size); in of_translate_ioport()
896 /* memory-mapped I/O range */ in of_translate_ioport()
900 if (port == (unsigned long)-1) in of_translate_ioport()
908 * of_dma_get_range - Get DMA range info and put it into a map array
909 * @np: device node to get DMA range info
910 * @map: dma range structure to return
912 * Look in bottom up direction for the first "dma-ranges" property
915 * dma-ranges format:
920 * It returns -ENODEV if "dma-ranges" property was not found for this
929 struct of_range range; in of_dma_get_range() local
935 ranges = of_get_property(node, "dma-ranges", &len); in of_dma_get_range()
941 /* Once we find 'dma-ranges', then a missing one is an error */ in of_dma_get_range()
943 ret = -ENODEV; in of_dma_get_range()
952 pr_debug("no dma-ranges found for node(%pOF)\n", np); in of_dma_get_range()
953 ret = -ENODEV; in of_dma_get_range()
958 for_each_of_range(&parser, &range) { in of_dma_get_range()
959 if (range.cpu_addr == OF_BAD_ADDR) { in of_dma_get_range()
961 range.bus_addr, node); in of_dma_get_range()
968 ret = -EINVAL; in of_dma_get_range()
974 ret = -ENOMEM; in of_dma_get_range()
984 for_each_of_range(&parser, &range) { in of_dma_get_range()
986 range.bus_addr, range.cpu_addr, range.size); in of_dma_get_range()
987 if (range.cpu_addr == OF_BAD_ADDR) in of_dma_get_range()
989 r->cpu_start = range.cpu_addr; in of_dma_get_range()
990 r->dma_start = range.bus_addr; in of_dma_get_range()
991 r->size = range.size; in of_dma_get_range()
992 r->offset = range.cpu_addr - range.bus_addr; in of_dma_get_range()
1002 * of_dma_get_max_cpu_address - Gets highest CPU address suitable for DMA
1006 * in the sub-tree pointed by np, or the whole tree if NULL is passed. If no
1015 struct of_range range; in of_dma_get_max_cpu_address() local
1023 ranges = of_get_property(np, "dma-ranges", &len); in of_dma_get_max_cpu_address()
1026 for_each_of_range(&parser, &range) in of_dma_get_max_cpu_address()
1027 if (range.cpu_addr + range.size > cpu_end) in of_dma_get_max_cpu_address()
1028 cpu_end = range.cpu_addr + range.size - 1; in of_dma_get_max_cpu_address()
1044 * of_dma_is_coherent - Check if device is coherent
1047 * It returns true if "dma-coherent" property was found
1050 * "dma-noncoherent" property was found for this device.
1060 if (of_property_read_bool(node, "dma-coherent")) { in of_dma_is_coherent()
1064 if (of_property_read_bool(node, "dma-noncoherent")) { in of_dma_is_coherent()
1076 * of_mmio_is_nonposted - Check if device uses non-posted MMIO
1079 * Returns true if the "nonposted-mmio" property was found for
1080 * the device's bus.
1097 nonposted = of_property_read_bool(parent, "nonposted-mmio"); in of_mmio_is_nonposted()
1114 return -EINVAL; in __of_address_to_resource()
1116 /* Get optional "reg-names" property to add a name to a resource */ in __of_address_to_resource()
1118 of_property_read_string_index(dev, "reg-names", index, &name); in __of_address_to_resource()
1125 return -EINVAL; in __of_address_to_resource()
1128 return -EINVAL; in __of_address_to_resource()
1134 if (overflows_type(taddr, r->start)) in __of_address_to_resource()
1135 return -EOVERFLOW; in __of_address_to_resource()
1136 r->start = taddr; in __of_address_to_resource()
1137 if (overflows_type(taddr + size - 1, r->end)) in __of_address_to_resource()
1138 return -EOVERFLOW; in __of_address_to_resource()
1139 r->end = taddr + size - 1; in __of_address_to_resource()
1140 r->flags = flags; in __of_address_to_resource()
1141 r->name = name ? name : dev->full_name; in __of_address_to_resource()
1147 * of_address_to_resource - Translate device tree address and return as resource
1152 * Returns -EINVAL if the range cannot be converted to resource.
1162 return __of_address_to_resource(dev, index, -1, r); in of_address_to_resource()
1171 return -ENOSYS; in of_pci_address_to_resource()
1173 return __of_address_to_resource(dev, -1, bar, r); in of_pci_address_to_resource()
1178 * of_iomap - Maps the memory mapped IO for a given device_node
1179 * @np: the device whose io range will be mapped
1180 * @index: index of the io range
1199 * of_io_request_and_map - Requests a resource and maps the memory mapped IO
1201 * @device: the device whose io range will be mapped
1202 * @index: index of the io range
1219 return IOMEM_ERR_PTR(-EINVAL); in of_io_request_and_map()
1224 return IOMEM_ERR_PTR(-EBUSY); in of_io_request_and_map()
1233 return IOMEM_ERR_PTR(-ENOMEM); in of_io_request_and_map()