Lines Matching +full:dma +full:- +full:noncoherent
1 // SPDX-License-Identifier: GPL-2.0
17 #include <linux/dma-direct.h> /* for bus_dma_region */
31 while (na--) in of_dump_addr()
71 cp = of_read_number(range + fna, na - fna); in of_bus_default_map()
73 da = of_read_number(addr + fna, na - fna); 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()
117 return of_bus_default_translate(addr + 1, offset, na - 1); in of_bus_default_flags_translate()
164 * "vci" is for the /chaos bridge on 1st-gen PCI powermacs in of_bus_pci_match()
205 if (overflows_type(start, r->start)) in __of_address_resource_bounds()
206 return -EOVERFLOW; in __of_address_resource_bounds()
207 if (size && check_add_overflow(end, size - 1, &end)) in __of_address_resource_bounds()
208 return -EOVERFLOW; in __of_address_resource_bounds()
209 if (overflows_type(end, r->end)) in __of_address_resource_bounds()
210 return -EOVERFLOW; in __of_address_resource_bounds()
212 r->start = start; in __of_address_resource_bounds()
213 r->end = end; in __of_address_resource_bounds()
219 * of_pci_range_to_resource - Create a resource from an of_pci_range
225 * Returns -EINVAL if the range cannot be converted to resource.
238 res->flags = range->flags; in of_pci_range_to_resource()
239 res->parent = res->child = res->sibling = NULL; in of_pci_range_to_resource()
240 res->name = np->full_name; in of_pci_range_to_resource()
242 if (res->flags & IORESOURCE_IO) { in of_pci_range_to_resource()
244 err = pci_register_io_range(&np->fwnode, range->cpu_addr, in of_pci_range_to_resource()
245 range->size); in of_pci_range_to_resource()
248 port = pci_address_to_pio(range->cpu_addr); in of_pci_range_to_resource()
249 if (port == (unsigned long)-1) { in of_pci_range_to_resource()
250 err = -EINVAL; in of_pci_range_to_resource()
255 start = range->cpu_addr; in of_pci_range_to_resource()
257 return __of_address_resource_bounds(res, start, range->size); in of_pci_range_to_resource()
260 res->start = (resource_size_t)OF_BAD_ADDR; in of_pci_range_to_resource()
261 res->end = (resource_size_t)OF_BAD_ADDR; in of_pci_range_to_resource()
267 * of_range_to_resource - Create a resource from a ranges entry
273 * Returns -ENOENT if the entry is not found or -EOVERFLOW if the range
290 return -ENOENT; in of_range_to_resource()
348 .addresses = "assigned-addresses",
370 .name = "default-flags",
406 static int quirk_state = -1; in of_empty_ranges_quirk()
408 /* PA-SEMI sdc DT bug */ in of_empty_ranges_quirk()
409 if (of_device_is_compatible(np, "1682m-sdc")) in of_empty_ranges_quirk()
433 * crossing a non-translatable boundary, and thus the addresses in of_translate_one()
436 * what Apple understood, and they do have things like /uni-n or in of_translate_one()
442 * the first place. --BenH. in of_translate_one()
445 * This code is only enabled on powerpc. --gcl in of_translate_one()
447 * This quirk also applies for 'dma-ranges' which frequently exist in in of_translate_one()
448 * child nodes without 'dma-ranges' in the parent nodes. --RobH in of_translate_one()
452 strcmp(rprop, "dma-ranges")) { in of_translate_one()
468 for (; rlen >= rone; rlen -= rone, ranges += rone) { in of_translate_one()
469 offset = bus->map(addr, ranges, na, ns, pna, bus->flag_cells); in of_translate_one()
484 return pbus->translate(addr, offset, pna); in of_translate_one()
488 * Translate an address from the device-tree into a CPU physical address,
492 * Note: We consider that crossing any level with #size-cells == 0 to mean
521 bus->count_cells(dev, &na, &ns); in __of_translate_address()
529 bus->name, na, ns, parent); in __of_translate_address()
551 iorange = find_io_range_by_fwnode(&dev->fwnode); in __of_translate_address()
552 if (iorange && (iorange->flags != LOGIC_PIO_CPU_MMIO)) { in __of_translate_address()
553 u64 result = of_read_number(addr + 1, na - 1); in __of_translate_address()
562 pbus->count_cells(dev, &pna, &pns); in __of_translate_address()
569 pbus->name, pna, pns, parent); in __of_translate_address()
608 index = of_property_match_string(np, "interconnect-names", "dma-mem"); in __of_get_dma_parent()
613 "#interconnect-cells", in __of_get_dma_parent()
638 in_addr, "dma-ranges", &host); in of_translate_dma_address()
650 * of_translate_dma_region - Translate device tree address and size tuple
653 * @start: return value for the start of the DMA range
654 * @length: return value for the length of the DMA range
656 * Returns a pointer to the cell immediately following the translated DMA region.
701 if (strcmp(bus->name, "pci") && (bar_no >= 0)) in __of_get_address()
704 bus->count_cells(dev, &na, &ns); in __of_get_address()
708 /* Get "reg" or "assigned-addresses" property */ in __of_get_address()
709 prop = of_get_property(dev, bus->addresses, &psize); in __of_get_address()
715 for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) { in __of_get_address()
723 *flags = bus->get_flags(prop); in __of_get_address()
732 * of_property_read_reg - Retrieve the specified "reg" entry index without translating
738 * Returns -EINVAL if "reg" is not found. Returns 0 on success with addr and
746 return -EINVAL; in of_property_read_reg()
759 parser->node = node; in parser_init()
760 parser->pna = of_n_addr_cells(node); in parser_init()
761 parser->na = of_bus_n_addr_cells(node); in parser_init()
762 parser->ns = of_bus_n_size_cells(node); in parser_init()
763 parser->dma = !strcmp(name, "dma-ranges"); in parser_init()
764 parser->bus = of_match_bus(node); in parser_init()
766 parser->range = of_get_property(node, name, &rlen); in parser_init()
767 if (parser->range == NULL) in parser_init()
768 return -ENOENT; in parser_init()
770 parser->end = parser->range + rlen / sizeof(__be32); in parser_init()
785 return parser_init(parser, node, "dma-ranges"); in of_pci_dma_range_parser_init()
793 int na = parser->na; in of_pci_range_parser_one()
794 int ns = parser->ns; in of_pci_range_parser_one()
795 int np = parser->pna + na + ns; in of_pci_range_parser_one()
796 int busflag_na = parser->bus->flag_cells; in of_pci_range_parser_one()
801 if (!parser->range || parser->range + np > parser->end) in of_pci_range_parser_one()
804 range->flags = parser->bus->get_flags(parser->range); in of_pci_range_parser_one()
806 range->bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na); in of_pci_range_parser_one()
808 if (parser->dma) in of_pci_range_parser_one()
809 range->cpu_addr = of_translate_dma_address(parser->node, in of_pci_range_parser_one()
810 parser->range + na); in of_pci_range_parser_one()
812 range->cpu_addr = of_translate_address(parser->node, in of_pci_range_parser_one()
813 parser->range + na); in of_pci_range_parser_one()
814 range->size = of_read_number(parser->range + parser->pna + na, ns); in of_pci_range_parser_one()
816 parser->range += np; in of_pci_range_parser_one()
819 while (parser->range + np <= parser->end) { in of_pci_range_parser_one()
823 flags = parser->bus->get_flags(parser->range); in of_pci_range_parser_one()
824 bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na); in of_pci_range_parser_one()
825 if (parser->dma) in of_pci_range_parser_one()
826 cpu_addr = of_translate_dma_address(parser->node, in of_pci_range_parser_one()
827 parser->range + na); in of_pci_range_parser_one()
829 cpu_addr = of_translate_address(parser->node, in of_pci_range_parser_one()
830 parser->range + na); in of_pci_range_parser_one()
831 size = of_read_number(parser->range + parser->pna + na, ns); in of_pci_range_parser_one()
833 if (flags != range->flags) in of_pci_range_parser_one()
835 if (bus_addr != range->bus_addr + range->size || in of_pci_range_parser_one()
836 cpu_addr != range->cpu_addr + range->size) in of_pci_range_parser_one()
839 range->size += size; in of_pci_range_parser_one()
840 parser->range += np; in of_pci_range_parser_one()
857 /* host-specific port access */ in of_translate_ioport()
858 port = logic_pio_trans_hwaddr(&host->fwnode, taddr, size); in of_translate_ioport()
861 /* memory-mapped I/O range */ in of_translate_ioport()
865 if (port == (unsigned long)-1) in of_translate_ioport()
873 * of_dma_get_range - Get DMA range info and put it into a map array
874 * @np: device node to get DMA range info
875 * @map: dma range structure to return
877 * Look in bottom up direction for the first "dma-ranges" property
878 * and parse it. Put the information into a DMA offset map array.
880 * dma-ranges format:
881 * DMA addr (dma_addr) : naddr cells
885 * It returns -ENODEV if "dma-ranges" property was not found for this
899 ranges = of_get_property(node, "dma-ranges", &len); in of_dma_get_range()
905 /* Once we find 'dma-ranges', then a missing one is an error */ in of_dma_get_range()
907 return -ENODEV; in of_dma_get_range()
915 pr_debug("no dma-ranges found for node(%pOF)\n", np); in of_dma_get_range()
916 return -ENODEV; in of_dma_get_range()
921 pr_err("translation of DMA address(%llx) to CPU address failed node(%pOF)\n", in of_dma_get_range()
929 return -EINVAL; in of_dma_get_range()
933 return -ENOMEM; in of_dma_get_range()
936 * Record all info in the generic DMA ranges array for struct device, in of_dma_get_range()
946 r->cpu_start = range.cpu_addr; in of_dma_get_range()
947 r->dma_start = range.bus_addr; in of_dma_get_range()
948 r->size = range.size; in of_dma_get_range()
956 * of_dma_get_max_cpu_address - Gets highest CPU address suitable for DMA
959 * Gets the highest CPU physical address that is addressable by all DMA masters
960 * in the sub-tree pointed by np, or the whole tree if NULL is passed. If no
961 * DMA constrained device is found, it returns PHYS_ADDR_MAX.
977 ranges = of_get_property(np, "dma-ranges", &len); in of_dma_get_max_cpu_address()
982 cpu_end = range.cpu_addr + range.size - 1; in of_dma_get_max_cpu_address()
998 * of_dma_is_coherent - Check if device is coherent
1001 * It returns true if "dma-coherent" property was found
1002 * for this device in the DT, or if DMA is coherent by
1004 * "dma-noncoherent" property was found for this device.
1011 if (of_property_read_bool(node, "dma-coherent")) in of_dma_is_coherent()
1014 if (of_property_read_bool(node, "dma-noncoherent")) in of_dma_is_coherent()
1024 * of_mmio_is_nonposted - Check if device uses non-posted MMIO
1027 * Returns true if the "nonposted-mmio" property was found for
1042 return of_property_read_bool(parent, "nonposted-mmio"); in of_mmio_is_nonposted()
1056 return -EINVAL; in __of_address_to_resource()
1058 /* Get optional "reg-names" property to add a name to a resource */ in __of_address_to_resource()
1060 of_property_read_string_index(dev, "reg-names", index, &name); in __of_address_to_resource()
1067 return -EINVAL; in __of_address_to_resource()
1070 return -EINVAL; in __of_address_to_resource()
1076 r->flags = flags; in __of_address_to_resource()
1077 r->name = name ? name : dev->full_name; in __of_address_to_resource()
1083 * of_address_to_resource - Translate device tree address and return as resource
1088 * Returns -EINVAL if the range cannot be converted to resource.
1098 return __of_address_to_resource(dev, index, -1, r); in of_address_to_resource()
1107 return -ENOSYS; in of_pci_address_to_resource()
1109 return __of_address_to_resource(dev, -1, bar, r); in of_pci_address_to_resource()
1114 * of_iomap - Maps the memory mapped IO for a given device_node
1135 * of_io_request_and_map - Requests a resource and maps the memory mapped IO
1155 return IOMEM_ERR_PTR(-EINVAL); in of_io_request_and_map()
1160 return IOMEM_ERR_PTR(-EBUSY); in of_io_request_and_map()
1169 return IOMEM_ERR_PTR(-ENOMEM); in of_io_request_and_map()