• Home
  • Raw
  • Download

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

1 // SPDX-License-Identifier: GPL-2.0
16 #include <linux/dma-direct.h> /* for bus_dma_region */
30 while (na--) in of_dump_addr()
38 /* Callbacks for bus specific translators */
45 u64 (*map)(__be32 *addr, const __be32 *range,
53 * Default translator (generic bus)
65 static u64 of_bus_default_map(__be32 *addr, const __be32 *range, in of_bus_default_map() argument
70 cp = of_read_number(range, na); in of_bus_default_map()
71 s = of_read_number(range + na + pna, ns); in of_bus_default_map()
78 return da - cp; in of_bus_default_map()
87 addr[na - 2] = cpu_to_be32(a >> 32); in of_bus_default_translate()
88 addr[na - 1] = cpu_to_be32(a & 0xffffffffu); in of_bus_default_translate()
103 static u64 of_bus_default_flags_map(__be32 *addr, const __be32 *range, int na, in of_bus_default_flags_map() argument
109 if (*addr != *range) in of_bus_default_flags_map()
113 cp = of_read_number(range + 1, na - 1); in of_bus_default_flags_map()
114 s = of_read_number(range + na + pna, ns); in of_bus_default_flags_map()
115 da = of_read_number(addr + 1, na - 1); in of_bus_default_flags_map()
121 return da - cp; in of_bus_default_flags_map()
127 return of_bus_default_translate(addr + 1, offset, na - 1); in of_bus_default_flags_translate()
157 * PCI bus specific translator
174 * "vci" is for the /chaos bridge on 1st-gen PCI powermacs in of_bus_pci_match()
194 static u64 of_bus_pci_map(__be32 *addr, const __be32 *range, int na, int ns, in of_bus_pci_map() argument
201 rf = of_bus_pci_get_flags(range); in of_bus_pci_map()
208 cp = of_read_number(range + 1, na - 1); in of_bus_pci_map()
209 s = of_read_number(range + na + pna, ns); in of_bus_pci_map()
210 da = of_read_number(addr + 1, na - 1); in of_bus_pci_map()
216 return da - cp; in of_bus_pci_map()
221 return of_bus_default_translate(addr + 1, offset, na - 1); in of_bus_pci_translate()
226 * of_pci_range_to_resource - Create a resource from an of_pci_range
227 * @range: the PCI range that describes the resource
228 * @np: device node where the range belongs to
230 * reflect the values contained in the range.
232 * Returns -EINVAL if the range cannot be converted to resource.
234 * Note that if the range is an IO range, the resource will be converted
236 * if the range cannot be matched to any host bridge IO space (our case here).
237 * To guard against that we try to register the IO range first.
240 int of_pci_range_to_resource(struct of_pci_range *range, in of_pci_range_to_resource() argument
244 res->flags = range->flags; in of_pci_range_to_resource()
245 res->parent = res->child = res->sibling = NULL; in of_pci_range_to_resource()
246 res->name = np->full_name; in of_pci_range_to_resource()
248 if (res->flags & IORESOURCE_IO) { in of_pci_range_to_resource()
250 err = pci_register_io_range(&np->fwnode, range->cpu_addr, in of_pci_range_to_resource()
251 range->size); in of_pci_range_to_resource()
254 port = pci_address_to_pio(range->cpu_addr); in of_pci_range_to_resource()
255 if (port == (unsigned long)-1) { in of_pci_range_to_resource()
256 err = -EINVAL; in of_pci_range_to_resource()
259 res->start = port; in of_pci_range_to_resource()
262 upper_32_bits(range->cpu_addr)) { in of_pci_range_to_resource()
263 err = -EINVAL; in of_pci_range_to_resource()
267 res->start = range->cpu_addr; in of_pci_range_to_resource()
269 res->end = res->start + range->size - 1; in of_pci_range_to_resource()
273 res->start = (resource_size_t)OF_BAD_ADDR; in of_pci_range_to_resource()
274 res->end = (resource_size_t)OF_BAD_ADDR; in of_pci_range_to_resource()
280 * of_range_to_resource - Create a resource from a ranges entry
281 * @np: device node where the range belongs to
284 * reflect the values contained in the range.
286 * Returns ENOENT if the entry is not found or EINVAL if the range cannot be
293 struct of_range range; in of_range_to_resource() local
299 for_each_of_range(&parser, &range) in of_range_to_resource()
301 return of_pci_range_to_resource(&range, np, res); in of_range_to_resource()
303 return -ENOENT; in of_range_to_resource()
308 * ISA bus specific translator
325 static u64 of_bus_isa_map(__be32 *addr, const __be32 *range, int na, int ns, in of_bus_isa_map() argument
331 if ((addr[0] ^ range[0]) & cpu_to_be32(1)) in of_bus_isa_map()
335 cp = of_read_number(range + 1, na - 1); in of_bus_isa_map()
336 s = of_read_number(range + na + pna, ns); in of_bus_isa_map()
337 da = of_read_number(addr + 1, na - 1); in of_bus_isa_map()
343 return da - cp; in of_bus_isa_map()
348 return of_bus_default_translate(addr + 1, offset, na - 1); in of_bus_isa_translate()
369 * Array of bus specific translators
377 .addresses = "assigned-addresses",
399 .name = "default-flags",
435 static int quirk_state = -1; in of_empty_ranges_quirk()
437 /* PA-SEMI sdc DT bug */ in of_empty_ranges_quirk()
438 if (of_device_is_compatible(np, "1682m-sdc")) in of_empty_ranges_quirk()
451 static int of_translate_one(struct device_node *parent, struct of_bus *bus, in of_translate_one() argument
462 * crossing a non-translatable boundary, and thus the addresses in of_translate_one()
465 * what Apple understood, and they do have things like /uni-n or in of_translate_one()
471 * the first place. --BenH. in of_translate_one()
474 * This code is only enabled on powerpc. --gcl in of_translate_one()
476 * This quirk also applies for 'dma-ranges' which frequently exist in in of_translate_one()
477 * child nodes without 'dma-ranges' in the parent nodes. --RobH in of_translate_one()
481 strcmp(rprop, "dma-ranges")) { in of_translate_one()
497 for (; rlen >= rone; rlen -= rone, ranges += rone) { in of_translate_one()
498 offset = bus->map(addr, ranges, na, ns, pna); in of_translate_one()
512 /* Translate it into parent bus space */ in of_translate_one()
513 return pbus->translate(addr, offset, pna); in of_translate_one()
517 * Translate an address from the device-tree into a CPU physical address,
518 * this walks up the tree and applies the various bus mappings on the
521 * Note: We consider that crossing any level with #size-cells == 0 to mean
536 struct of_bus *bus, *pbus; in __of_translate_address() local
547 /* Get parent & match bus type */ in __of_translate_address()
551 bus = of_match_bus(parent); in __of_translate_address()
554 bus->count_cells(dev, &na, &ns); in __of_translate_address()
561 pr_debug("bus is %s (na=%d, ns=%d) on %pOF\n", in __of_translate_address()
562 bus->name, na, ns, parent); in __of_translate_address()
569 /* Switch to parent bus */ in __of_translate_address()
585 iorange = find_io_range_by_fwnode(&dev->fwnode); in __of_translate_address()
586 if (iorange && (iorange->flags != LOGIC_PIO_CPU_MMIO)) { in __of_translate_address()
587 result = of_read_number(addr + 1, na - 1); in __of_translate_address()
594 /* Get new parent bus and counts */ in __of_translate_address()
596 pbus->count_cells(dev, &pna, &pns); in __of_translate_address()
602 pr_debug("parent bus is %s (na=%d, ns=%d) on %pOF\n", in __of_translate_address()
603 pbus->name, pna, pns, parent); in __of_translate_address()
605 /* Apply bus translation */ in __of_translate_address()
606 if (of_translate_one(dev, bus, pbus, addr, na, ns, pna, rprop)) in __of_translate_address()
612 bus = pbus; in __of_translate_address()
645 index = of_property_match_string(np, "interconnect-names", "dma-mem"); in __of_get_dma_parent()
650 "#interconnect-cells", in __of_get_dma_parent()
675 in_addr, "dma-ranges", &host); in of_translate_dma_address()
687 * of_translate_dma_region - Translate device tree address and size tuple
690 * @start: return value for the start of the DMA range
691 * @length: return value for the length of the DMA range
733 struct of_bus *bus; in __of_get_address() local
736 /* Get parent & match bus type */ in __of_get_address()
740 bus = of_match_bus(parent); in __of_get_address()
741 if (strcmp(bus->name, "pci") && (bar_no >= 0)) { in __of_get_address()
745 bus->count_cells(dev, &na, &ns); in __of_get_address()
750 /* Get "reg" or "assigned-addresses" property */ in __of_get_address()
751 prop = of_get_property(dev, bus->addresses, &psize); in __of_get_address()
757 for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) { in __of_get_address()
759 /* PCI bus matches on BAR number instead of index */ in __of_get_address()
765 *flags = bus->get_flags(prop); in __of_get_address()
774 * of_property_read_reg - Retrieve the specified "reg" entry index without translating
780 * Returns -EINVAL if "reg" is not found. Returns 0 on success with addr and
788 return -EINVAL; in of_property_read_reg()
801 parser->node = node; in parser_init()
802 parser->pna = of_n_addr_cells(node); in parser_init()
803 parser->na = of_bus_n_addr_cells(node); in parser_init()
804 parser->ns = of_bus_n_size_cells(node); in parser_init()
805 parser->dma = !strcmp(name, "dma-ranges"); in parser_init()
806 parser->bus = of_match_bus(node); in parser_init()
808 parser->range = of_get_property(node, name, &rlen); in parser_init()
809 if (parser->range == NULL) in parser_init()
810 return -ENOENT; in parser_init()
812 parser->end = parser->range + rlen / sizeof(__be32); in parser_init()
827 return parser_init(parser, node, "dma-ranges"); in of_pci_dma_range_parser_init()
833 struct of_pci_range *range) in of_pci_range_parser_one() argument
835 int na = parser->na; in of_pci_range_parser_one()
836 int ns = parser->ns; in of_pci_range_parser_one()
837 int np = parser->pna + na + ns; in of_pci_range_parser_one()
840 if (!range) in of_pci_range_parser_one()
843 if (!parser->range || parser->range + np > parser->end) in of_pci_range_parser_one()
846 range->flags = parser->bus->get_flags(parser->range); in of_pci_range_parser_one()
849 if (parser->bus->has_flags) in of_pci_range_parser_one()
852 range->bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na); in of_pci_range_parser_one()
854 if (parser->dma) in of_pci_range_parser_one()
855 range->cpu_addr = of_translate_dma_address(parser->node, in of_pci_range_parser_one()
856 parser->range + na); in of_pci_range_parser_one()
858 range->cpu_addr = of_translate_address(parser->node, in of_pci_range_parser_one()
859 parser->range + na); in of_pci_range_parser_one()
860 range->size = of_read_number(parser->range + parser->pna + na, ns); in of_pci_range_parser_one()
862 parser->range += np; in of_pci_range_parser_one()
865 while (parser->range + np <= parser->end) { in of_pci_range_parser_one()
869 flags = parser->bus->get_flags(parser->range); in of_pci_range_parser_one()
870 bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na); in of_pci_range_parser_one()
871 if (parser->dma) in of_pci_range_parser_one()
872 cpu_addr = of_translate_dma_address(parser->node, in of_pci_range_parser_one()
873 parser->range + na); in of_pci_range_parser_one()
875 cpu_addr = of_translate_address(parser->node, in of_pci_range_parser_one()
876 parser->range + na); in of_pci_range_parser_one()
877 size = of_read_number(parser->range + parser->pna + na, ns); in of_pci_range_parser_one()
879 if (flags != range->flags) in of_pci_range_parser_one()
881 if (bus_addr != range->bus_addr + range->size || in of_pci_range_parser_one()
882 cpu_addr != range->cpu_addr + range->size) in of_pci_range_parser_one()
885 range->size += size; in of_pci_range_parser_one()
886 parser->range += np; in of_pci_range_parser_one()
889 return range; in of_pci_range_parser_one()
903 /* host-specific port access */ in of_translate_ioport()
904 port = logic_pio_trans_hwaddr(&host->fwnode, taddr, size); in of_translate_ioport()
907 /* memory-mapped I/O range */ in of_translate_ioport()
911 if (port == (unsigned long)-1) in of_translate_ioport()
919 * of_dma_get_range - Get DMA range info and put it into a map array
920 * @np: device node to get DMA range info
921 * @map: dma range structure to return
923 * Look in bottom up direction for the first "dma-ranges" property
926 * dma-ranges format:
931 * It returns -ENODEV if "dma-ranges" property was not found for this
940 struct of_range range; in of_dma_get_range() local
946 ranges = of_get_property(node, "dma-ranges", &len); in of_dma_get_range()
952 /* Once we find 'dma-ranges', then a missing one is an error */ in of_dma_get_range()
954 ret = -ENODEV; in of_dma_get_range()
963 pr_debug("no dma-ranges found for node(%pOF)\n", np); in of_dma_get_range()
964 ret = -ENODEV; in of_dma_get_range()
969 for_each_of_range(&parser, &range) { in of_dma_get_range()
970 if (range.cpu_addr == OF_BAD_ADDR) { in of_dma_get_range()
972 range.bus_addr, node); in of_dma_get_range()
979 ret = -EINVAL; in of_dma_get_range()
985 ret = -ENOMEM; in of_dma_get_range()
995 for_each_of_range(&parser, &range) { in of_dma_get_range()
997 range.bus_addr, range.cpu_addr, range.size); in of_dma_get_range()
998 if (range.cpu_addr == OF_BAD_ADDR) in of_dma_get_range()
1000 r->cpu_start = range.cpu_addr; in of_dma_get_range()
1001 r->dma_start = range.bus_addr; in of_dma_get_range()
1002 r->size = range.size; in of_dma_get_range()
1003 r->offset = range.cpu_addr - range.bus_addr; in of_dma_get_range()
1013 * of_dma_get_max_cpu_address - Gets highest CPU address suitable for DMA
1017 * in the sub-tree pointed by np, or the whole tree if NULL is passed. If no
1026 struct of_range range; in of_dma_get_max_cpu_address() local
1034 ranges = of_get_property(np, "dma-ranges", &len); in of_dma_get_max_cpu_address()
1037 for_each_of_range(&parser, &range) in of_dma_get_max_cpu_address()
1038 if (range.cpu_addr + range.size > cpu_end) in of_dma_get_max_cpu_address()
1039 cpu_end = range.cpu_addr + range.size - 1; in of_dma_get_max_cpu_address()
1055 * of_dma_is_coherent - Check if device is coherent
1058 * It returns true if "dma-coherent" property was found
1061 * "dma-noncoherent" property was found for this device.
1071 if (of_property_read_bool(node, "dma-coherent")) { in of_dma_is_coherent()
1075 if (of_property_read_bool(node, "dma-noncoherent")) { in of_dma_is_coherent()
1087 * of_mmio_is_nonposted - Check if device uses non-posted MMIO
1090 * Returns true if the "nonposted-mmio" property was found for
1091 * the device's bus.
1108 nonposted = of_property_read_bool(parent, "nonposted-mmio"); in of_mmio_is_nonposted()
1125 return -EINVAL; in __of_address_to_resource()
1127 /* Get optional "reg-names" property to add a name to a resource */ in __of_address_to_resource()
1129 of_property_read_string_index(dev, "reg-names", index, &name); in __of_address_to_resource()
1136 return -EINVAL; in __of_address_to_resource()
1139 return -EINVAL; in __of_address_to_resource()
1145 r->start = taddr; in __of_address_to_resource()
1146 r->end = taddr + size - 1; in __of_address_to_resource()
1147 r->flags = flags; in __of_address_to_resource()
1148 r->name = name ? name : dev->full_name; in __of_address_to_resource()
1154 * of_address_to_resource - Translate device tree address and return as resource
1159 * Returns -EINVAL if the range cannot be converted to resource.
1169 return __of_address_to_resource(dev, index, -1, r); in of_address_to_resource()
1178 return -ENOSYS; in of_pci_address_to_resource()
1180 return __of_address_to_resource(dev, -1, bar, r); in of_pci_address_to_resource()
1185 * of_iomap - Maps the memory mapped IO for a given device_node
1186 * @np: the device whose io range will be mapped
1187 * @index: index of the io range
1206 * of_io_request_and_map - Requests a resource and maps the memory mapped IO
1208 * @device: the device whose io range will be mapped
1209 * @index: index of the io range
1226 return IOMEM_ERR_PTR(-EINVAL); in of_io_request_and_map()
1231 return IOMEM_ERR_PTR(-EBUSY); in of_io_request_and_map()
1240 return IOMEM_ERR_PTR(-ENOMEM); in of_io_request_and_map()