1 // SPDX-License-Identifier: GPL-2.0
2 #define pr_fmt(fmt) "OF: " fmt
4 #include <linux/device.h>
5 #include <linux/fwnode.h>
7 #include <linux/ioport.h>
8 #include <linux/logic_pio.h>
9 #include <linux/module.h>
10 #include <linux/of_address.h>
11 #include <linux/pci.h>
12 #include <linux/pci_regs.h>
13 #include <linux/sizes.h>
14 #include <linux/slab.h>
15 #include <linux/string.h>
17 #include "of_private.h"
19 /* Max address size we deal with */
20 #define OF_MAX_ADDR_CELLS 4
21 #define OF_CHECK_ADDR_COUNT(na) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS)
22 #define OF_CHECK_COUNTS(na, ns) (OF_CHECK_ADDR_COUNT(na) && (ns) > 0)
24 static struct of_bus *of_match_bus(struct device_node *np);
25 static int __of_address_to_resource(struct device_node *dev,
26 const __be32 *addrp, u64 size, unsigned int flags,
27 const char *name, struct resource *r);
31 static void of_dump_addr(const char *s, const __be32 *addr, int na)
35 pr_cont(" %08x", be32_to_cpu(*(addr++)));
39 static void of_dump_addr(const char *s, const __be32 *addr, int na) { }
42 /* Callbacks for bus specific translators */
45 const char *addresses;
46 int (*match)(struct device_node *parent);
47 void (*count_cells)(struct device_node *child,
48 int *addrc, int *sizec);
49 u64 (*map)(__be32 *addr, const __be32 *range,
50 int na, int ns, int pna);
51 int (*translate)(__be32 *addr, u64 offset, int na);
53 unsigned int (*get_flags)(const __be32 *addr);
57 * Default translator (generic bus)
60 static void of_bus_default_count_cells(struct device_node *dev,
61 int *addrc, int *sizec)
64 *addrc = of_n_addr_cells(dev);
66 *sizec = of_n_size_cells(dev);
69 static u64 of_bus_default_map(__be32 *addr, const __be32 *range,
70 int na, int ns, int pna)
74 cp = of_read_number(range, na);
75 s = of_read_number(range + na + pna, ns);
76 da = of_read_number(addr, na);
78 pr_debug("default map, cp=%llx, s=%llx, da=%llx\n",
79 (unsigned long long)cp, (unsigned long long)s,
80 (unsigned long long)da);
82 if (da < cp || da >= (cp + s))
87 static int of_bus_default_translate(__be32 *addr, u64 offset, int na)
89 u64 a = of_read_number(addr, na);
90 memset(addr, 0, na * 4);
93 addr[na - 2] = cpu_to_be32(a >> 32);
94 addr[na - 1] = cpu_to_be32(a & 0xffffffffu);
99 static unsigned int of_bus_default_get_flags(const __be32 *addr)
101 return IORESOURCE_MEM;
105 static unsigned int of_bus_pci_get_flags(const __be32 *addr)
107 unsigned int flags = 0;
108 u32 w = be32_to_cpup(addr);
110 if (!IS_ENABLED(CONFIG_PCI))
113 switch((w >> 24) & 0x03) {
115 flags |= IORESOURCE_IO;
117 case 0x02: /* 32 bits */
118 case 0x03: /* 64 bits */
119 flags |= IORESOURCE_MEM;
123 flags |= IORESOURCE_PREFETCH;
128 * PCI bus specific translator
131 static int of_bus_pci_match(struct device_node *np)
134 * "pciex" is PCI Express
135 * "vci" is for the /chaos bridge on 1st-gen PCI powermacs
136 * "ht" is hypertransport
138 return of_node_is_type(np, "pci") || of_node_is_type(np, "pciex") ||
139 of_node_is_type(np, "vci") || of_node_is_type(np, "ht");
142 static void of_bus_pci_count_cells(struct device_node *np,
143 int *addrc, int *sizec)
151 static u64 of_bus_pci_map(__be32 *addr, const __be32 *range, int na, int ns,
157 af = of_bus_pci_get_flags(addr);
158 rf = of_bus_pci_get_flags(range);
160 /* Check address type match */
161 if ((af ^ rf) & (IORESOURCE_MEM | IORESOURCE_IO))
164 /* Read address values, skipping high cell */
165 cp = of_read_number(range + 1, na - 1);
166 s = of_read_number(range + na + pna, ns);
167 da = of_read_number(addr + 1, na - 1);
169 pr_debug("PCI map, cp=%llx, s=%llx, da=%llx\n",
170 (unsigned long long)cp, (unsigned long long)s,
171 (unsigned long long)da);
173 if (da < cp || da >= (cp + s))
178 static int of_bus_pci_translate(__be32 *addr, u64 offset, int na)
180 return of_bus_default_translate(addr + 1, offset, na - 1);
183 const __be32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size,
188 struct device_node *parent;
190 int onesize, i, na, ns;
192 /* Get parent & match bus type */
193 parent = of_get_parent(dev);
196 bus = of_match_bus(parent);
197 if (strcmp(bus->name, "pci")) {
201 bus->count_cells(dev, &na, &ns);
203 if (!OF_CHECK_ADDR_COUNT(na))
206 /* Get "reg" or "assigned-addresses" property */
207 prop = of_get_property(dev, bus->addresses, &psize);
213 for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++) {
214 u32 val = be32_to_cpu(prop[0]);
215 if ((val & 0xff) == ((bar_no * 4) + PCI_BASE_ADDRESS_0)) {
217 *size = of_read_number(prop + na, ns);
219 *flags = bus->get_flags(prop);
225 EXPORT_SYMBOL(of_get_pci_address);
227 int of_pci_address_to_resource(struct device_node *dev, int bar,
234 addrp = of_get_pci_address(dev, bar, &size, &flags);
237 return __of_address_to_resource(dev, addrp, size, flags, NULL, r);
239 EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
242 * of_pci_range_to_resource - Create a resource from an of_pci_range
243 * @range: the PCI range that describes the resource
244 * @np: device node where the range belongs to
245 * @res: pointer to a valid resource that will be updated to
246 * reflect the values contained in the range.
248 * Returns EINVAL if the range cannot be converted to resource.
250 * Note that if the range is an IO range, the resource will be converted
251 * using pci_address_to_pio() which can fail if it is called too early or
252 * if the range cannot be matched to any host bridge IO space (our case here).
253 * To guard against that we try to register the IO range first.
254 * If that fails we know that pci_address_to_pio() will do too.
256 int of_pci_range_to_resource(struct of_pci_range *range,
257 struct device_node *np, struct resource *res)
260 res->flags = range->flags;
261 res->parent = res->child = res->sibling = NULL;
262 res->name = np->full_name;
264 if (res->flags & IORESOURCE_IO) {
266 err = pci_register_io_range(&np->fwnode, range->cpu_addr,
270 port = pci_address_to_pio(range->cpu_addr);
271 if (port == (unsigned long)-1) {
277 if ((sizeof(resource_size_t) < 8) &&
278 upper_32_bits(range->cpu_addr)) {
283 res->start = range->cpu_addr;
285 res->end = res->start + range->size - 1;
289 res->start = (resource_size_t)OF_BAD_ADDR;
290 res->end = (resource_size_t)OF_BAD_ADDR;
293 EXPORT_SYMBOL(of_pci_range_to_resource);
294 #endif /* CONFIG_PCI */
297 * ISA bus specific translator
300 static int of_bus_isa_match(struct device_node *np)
302 return of_node_name_eq(np, "isa");
305 static void of_bus_isa_count_cells(struct device_node *child,
306 int *addrc, int *sizec)
314 static u64 of_bus_isa_map(__be32 *addr, const __be32 *range, int na, int ns,
319 /* Check address type match */
320 if ((addr[0] ^ range[0]) & cpu_to_be32(1))
323 /* Read address values, skipping high cell */
324 cp = of_read_number(range + 1, na - 1);
325 s = of_read_number(range + na + pna, ns);
326 da = of_read_number(addr + 1, na - 1);
328 pr_debug("ISA map, cp=%llx, s=%llx, da=%llx\n",
329 (unsigned long long)cp, (unsigned long long)s,
330 (unsigned long long)da);
332 if (da < cp || da >= (cp + s))
337 static int of_bus_isa_translate(__be32 *addr, u64 offset, int na)
339 return of_bus_default_translate(addr + 1, offset, na - 1);
342 static unsigned int of_bus_isa_get_flags(const __be32 *addr)
344 unsigned int flags = 0;
345 u32 w = be32_to_cpup(addr);
348 flags |= IORESOURCE_IO;
350 flags |= IORESOURCE_MEM;
355 * Array of bus specific translators
358 static struct of_bus of_busses[] = {
363 .addresses = "assigned-addresses",
364 .match = of_bus_pci_match,
365 .count_cells = of_bus_pci_count_cells,
366 .map = of_bus_pci_map,
367 .translate = of_bus_pci_translate,
369 .get_flags = of_bus_pci_get_flags,
371 #endif /* CONFIG_PCI */
376 .match = of_bus_isa_match,
377 .count_cells = of_bus_isa_count_cells,
378 .map = of_bus_isa_map,
379 .translate = of_bus_isa_translate,
381 .get_flags = of_bus_isa_get_flags,
388 .count_cells = of_bus_default_count_cells,
389 .map = of_bus_default_map,
390 .translate = of_bus_default_translate,
391 .get_flags = of_bus_default_get_flags,
395 static struct of_bus *of_match_bus(struct device_node *np)
399 for (i = 0; i < ARRAY_SIZE(of_busses); i++)
400 if (!of_busses[i].match || of_busses[i].match(np))
401 return &of_busses[i];
406 static int of_empty_ranges_quirk(struct device_node *np)
408 if (IS_ENABLED(CONFIG_PPC)) {
409 /* To save cycles, we cache the result for global "Mac" setting */
410 static int quirk_state = -1;
412 /* PA-SEMI sdc DT bug */
413 if (of_device_is_compatible(np, "1682m-sdc"))
416 /* Make quirk cached */
419 of_machine_is_compatible("Power Macintosh") ||
420 of_machine_is_compatible("MacRISC");
426 static int of_translate_one(struct device_node *parent, struct of_bus *bus,
427 struct of_bus *pbus, __be32 *addr,
428 int na, int ns, int pna, const char *rprop)
430 const __be32 *ranges;
433 u64 offset = OF_BAD_ADDR;
436 * Normally, an absence of a "ranges" property means we are
437 * crossing a non-translatable boundary, and thus the addresses
438 * below the current cannot be converted to CPU physical ones.
439 * Unfortunately, while this is very clear in the spec, it's not
440 * what Apple understood, and they do have things like /uni-n or
441 * /ht nodes with no "ranges" property and a lot of perfectly
442 * useable mapped devices below them. Thus we treat the absence of
443 * "ranges" as equivalent to an empty "ranges" property which means
444 * a 1:1 translation at that level. It's up to the caller not to try
445 * to translate addresses that aren't supposed to be translated in
446 * the first place. --BenH.
448 * As far as we know, this damage only exists on Apple machines, so
449 * This code is only enabled on powerpc. --gcl
451 * This quirk also applies for 'dma-ranges' which frequently exist in
452 * child nodes without 'dma-ranges' in the parent nodes. --RobH
454 ranges = of_get_property(parent, rprop, &rlen);
455 if (ranges == NULL && !of_empty_ranges_quirk(parent) &&
456 strcmp(rprop, "dma-ranges")) {
457 pr_debug("no ranges; cannot translate\n");
460 if (ranges == NULL || rlen == 0) {
461 offset = of_read_number(addr, na);
462 memset(addr, 0, pna * 4);
463 pr_debug("empty ranges; 1:1 translation\n");
467 pr_debug("walking ranges...\n");
469 /* Now walk through the ranges */
471 rone = na + pna + ns;
472 for (; rlen >= rone; rlen -= rone, ranges += rone) {
473 offset = bus->map(addr, ranges, na, ns, pna);
474 if (offset != OF_BAD_ADDR)
477 if (offset == OF_BAD_ADDR) {
478 pr_debug("not found !\n");
481 memcpy(addr, ranges + na, 4 * pna);
484 of_dump_addr("parent translation for:", addr, pna);
485 pr_debug("with offset: %llx\n", (unsigned long long)offset);
487 /* Translate it into parent bus space */
488 return pbus->translate(addr, offset, pna);
492 * Translate an address from the device-tree into a CPU physical address,
493 * this walks up the tree and applies the various bus mappings on the
496 * Note: We consider that crossing any level with #size-cells == 0 to mean
497 * that translation is impossible (that is we are not dealing with a value
498 * that can be mapped to a cpu physical address). This is not really specified
499 * that way, but this is traditionally the way IBM at least do things
501 * Whenever the translation fails, the *host pointer will be set to the
502 * device that had registered logical PIO mapping, and the return code is
503 * relative to that node.
505 static u64 __of_translate_address(struct device_node *dev,
506 struct device_node *(*get_parent)(const struct device_node *),
507 const __be32 *in_addr, const char *rprop,
508 struct device_node **host)
510 struct device_node *parent = NULL;
511 struct of_bus *bus, *pbus;
512 __be32 addr[OF_MAX_ADDR_CELLS];
513 int na, ns, pna, pns;
514 u64 result = OF_BAD_ADDR;
516 pr_debug("** translation for device %pOF **\n", dev);
518 /* Increase refcount at current level */
522 /* Get parent & match bus type */
523 parent = get_parent(dev);
526 bus = of_match_bus(parent);
528 /* Count address cells & copy address locally */
529 bus->count_cells(dev, &na, &ns);
530 if (!OF_CHECK_COUNTS(na, ns)) {
531 pr_debug("Bad cell count for %pOF\n", dev);
534 memcpy(addr, in_addr, na * 4);
536 pr_debug("bus is %s (na=%d, ns=%d) on %pOF\n",
537 bus->name, na, ns, parent);
538 of_dump_addr("translating address:", addr, na);
542 struct logic_pio_hwaddr *iorange;
544 /* Switch to parent bus */
547 parent = get_parent(dev);
549 /* If root, we have finished */
550 if (parent == NULL) {
551 pr_debug("reached root node\n");
552 result = of_read_number(addr, na);
557 * For indirectIO device which has no ranges property, get
558 * the address from reg directly.
560 iorange = find_io_range_by_fwnode(&dev->fwnode);
561 if (iorange && (iorange->flags != LOGIC_PIO_CPU_MMIO)) {
562 result = of_read_number(addr + 1, na - 1);
563 pr_debug("indirectIO matched(%pOF) 0x%llx\n",
565 *host = of_node_get(dev);
569 /* Get new parent bus and counts */
570 pbus = of_match_bus(parent);
571 pbus->count_cells(dev, &pna, &pns);
572 if (!OF_CHECK_COUNTS(pna, pns)) {
573 pr_err("Bad cell count for %pOF\n", dev);
577 pr_debug("parent bus is %s (na=%d, ns=%d) on %pOF\n",
578 pbus->name, pna, pns, parent);
580 /* Apply bus translation */
581 if (of_translate_one(dev, bus, pbus, addr, na, ns, pna, rprop))
584 /* Complete the move up one level */
589 of_dump_addr("one level translation:", addr, na);
598 u64 of_translate_address(struct device_node *dev, const __be32 *in_addr)
600 struct device_node *host;
603 ret = __of_translate_address(dev, of_get_parent,
604 in_addr, "ranges", &host);
612 EXPORT_SYMBOL(of_translate_address);
614 static struct device_node *__of_get_dma_parent(const struct device_node *np)
616 struct of_phandle_args args;
619 index = of_property_match_string(np, "interconnect-names", "dma-mem");
621 return of_get_parent(np);
623 ret = of_parse_phandle_with_args(np, "interconnects",
624 "#interconnect-cells",
627 return of_get_parent(np);
629 return of_node_get(args.np);
632 static struct device_node *of_get_next_dma_parent(struct device_node *np)
634 struct device_node *parent;
636 parent = __of_get_dma_parent(np);
642 u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr)
644 struct device_node *host;
647 ret = __of_translate_address(dev, __of_get_dma_parent,
648 in_addr, "dma-ranges", &host);
657 EXPORT_SYMBOL(of_translate_dma_address);
659 const __be32 *of_get_address(struct device_node *dev, int index, u64 *size,
664 struct device_node *parent;
666 int onesize, i, na, ns;
668 /* Get parent & match bus type */
669 parent = of_get_parent(dev);
672 bus = of_match_bus(parent);
673 bus->count_cells(dev, &na, &ns);
675 if (!OF_CHECK_ADDR_COUNT(na))
678 /* Get "reg" or "assigned-addresses" property */
679 prop = of_get_property(dev, bus->addresses, &psize);
685 for (i = 0; psize >= onesize; psize -= onesize, prop += onesize, i++)
688 *size = of_read_number(prop + na, ns);
690 *flags = bus->get_flags(prop);
695 EXPORT_SYMBOL(of_get_address);
697 static int parser_init(struct of_pci_range_parser *parser,
698 struct device_node *node, const char *name)
703 parser->pna = of_n_addr_cells(node);
704 parser->na = of_bus_n_addr_cells(node);
705 parser->ns = of_bus_n_size_cells(node);
706 parser->dma = !strcmp(name, "dma-ranges");
707 parser->bus = of_match_bus(node);
709 parser->range = of_get_property(node, name, &rlen);
710 if (parser->range == NULL)
713 parser->end = parser->range + rlen / sizeof(__be32);
718 int of_pci_range_parser_init(struct of_pci_range_parser *parser,
719 struct device_node *node)
721 return parser_init(parser, node, "ranges");
723 EXPORT_SYMBOL_GPL(of_pci_range_parser_init);
725 int of_pci_dma_range_parser_init(struct of_pci_range_parser *parser,
726 struct device_node *node)
728 return parser_init(parser, node, "dma-ranges");
730 EXPORT_SYMBOL_GPL(of_pci_dma_range_parser_init);
731 #define of_dma_range_parser_init of_pci_dma_range_parser_init
733 struct of_pci_range *of_pci_range_parser_one(struct of_pci_range_parser *parser,
734 struct of_pci_range *range)
738 int np = parser->pna + na + ns;
744 if (!parser->range || parser->range + np > parser->end)
747 range->flags = parser->bus->get_flags(parser->range);
749 /* A extra cell for resource flags */
750 if (parser->bus->has_flags)
753 range->bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na);
756 range->cpu_addr = of_translate_dma_address(parser->node,
759 range->cpu_addr = of_translate_address(parser->node,
761 range->size = of_read_number(parser->range + parser->pna + na, ns);
765 /* Now consume following elements while they are contiguous */
766 while (parser->range + np <= parser->end) {
768 u64 bus_addr, cpu_addr, size;
770 flags = parser->bus->get_flags(parser->range);
771 bus_addr = of_read_number(parser->range + busflag_na, na - busflag_na);
773 cpu_addr = of_translate_dma_address(parser->node,
776 cpu_addr = of_translate_address(parser->node,
778 size = of_read_number(parser->range + parser->pna + na, ns);
780 if (flags != range->flags)
782 if (bus_addr != range->bus_addr + range->size ||
783 cpu_addr != range->cpu_addr + range->size)
792 EXPORT_SYMBOL_GPL(of_pci_range_parser_one);
794 static u64 of_translate_ioport(struct device_node *dev, const __be32 *in_addr,
799 struct device_node *host;
801 taddr = __of_translate_address(dev, of_get_parent,
802 in_addr, "ranges", &host);
804 /* host-specific port access */
805 port = logic_pio_trans_hwaddr(&host->fwnode, taddr, size);
808 /* memory-mapped I/O range */
809 port = pci_address_to_pio(taddr);
812 if (port == (unsigned long)-1)
818 static int __of_address_to_resource(struct device_node *dev,
819 const __be32 *addrp, u64 size, unsigned int flags,
820 const char *name, struct resource *r)
824 if (flags & IORESOURCE_MEM)
825 taddr = of_translate_address(dev, addrp);
826 else if (flags & IORESOURCE_IO)
827 taddr = of_translate_ioport(dev, addrp, size);
831 if (taddr == OF_BAD_ADDR)
833 memset(r, 0, sizeof(struct resource));
836 r->end = taddr + size - 1;
838 r->name = name ? name : dev->full_name;
844 * of_address_to_resource - Translate device tree address and return as resource
846 * Note that if your address is a PIO address, the conversion will fail if
847 * the physical address can't be internally converted to an IO token with
848 * pci_address_to_pio(), that is because it's either called too early or it
849 * can't be matched to any host bridge IO space
851 int of_address_to_resource(struct device_node *dev, int index,
857 const char *name = NULL;
859 addrp = of_get_address(dev, index, &size, &flags);
863 /* Get optional "reg-names" property to add a name to a resource */
864 of_property_read_string_index(dev, "reg-names", index, &name);
866 return __of_address_to_resource(dev, addrp, size, flags, name, r);
868 EXPORT_SYMBOL_GPL(of_address_to_resource);
871 * of_iomap - Maps the memory mapped IO for a given device_node
872 * @device: the device whose io range will be mapped
873 * @index: index of the io range
875 * Returns a pointer to the mapped memory
877 void __iomem *of_iomap(struct device_node *np, int index)
881 if (of_address_to_resource(np, index, &res))
884 return ioremap(res.start, resource_size(&res));
886 EXPORT_SYMBOL(of_iomap);
889 * of_io_request_and_map - Requests a resource and maps the memory mapped IO
890 * for a given device_node
891 * @device: the device whose io range will be mapped
892 * @index: index of the io range
893 * @name: name "override" for the memory region request or NULL
895 * Returns a pointer to the requested and mapped memory or an ERR_PTR() encoded
896 * error code on failure. Usage example:
898 * base = of_io_request_and_map(node, 0, "foo");
900 * return PTR_ERR(base);
902 void __iomem *of_io_request_and_map(struct device_node *np, int index,
908 if (of_address_to_resource(np, index, &res))
909 return IOMEM_ERR_PTR(-EINVAL);
913 if (!request_mem_region(res.start, resource_size(&res), name))
914 return IOMEM_ERR_PTR(-EBUSY);
916 mem = ioremap(res.start, resource_size(&res));
918 release_mem_region(res.start, resource_size(&res));
919 return IOMEM_ERR_PTR(-ENOMEM);
924 EXPORT_SYMBOL(of_io_request_and_map);
927 * of_dma_get_range - Get DMA range info
928 * @np: device node to get DMA range info
929 * @dma_addr: pointer to store initial DMA address of DMA range
930 * @paddr: pointer to store initial CPU address of DMA range
931 * @size: pointer to store size of DMA range
933 * Look in bottom up direction for the first "dma-ranges" property
936 * DMA addr (dma_addr) : naddr cells
937 * CPU addr (phys_addr_t) : pna cells
940 * It returns -ENODEV if "dma-ranges" property was not found
941 * for this device in DT.
943 int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *size)
945 struct device_node *node = of_node_get(np);
946 const __be32 *ranges = NULL;
949 bool found_dma_ranges = false;
950 struct of_range_parser parser;
951 struct of_range range;
952 u64 dma_start = U64_MAX, dma_end = 0, dma_offset = 0;
955 ranges = of_get_property(node, "dma-ranges", &len);
957 /* Ignore empty ranges, they imply no translation required */
958 if (ranges && len > 0)
961 /* Once we find 'dma-ranges', then a missing one is an error */
962 if (found_dma_ranges && !ranges) {
966 found_dma_ranges = true;
968 node = of_get_next_dma_parent(node);
971 if (!node || !ranges) {
972 pr_debug("no dma-ranges found for node(%pOF)\n", np);
977 of_dma_range_parser_init(&parser, node);
979 for_each_of_range(&parser, &range) {
980 pr_debug("dma_addr(%llx) cpu_addr(%llx) size(%llx)\n",
981 range.bus_addr, range.cpu_addr, range.size);
983 if (dma_offset && range.cpu_addr - range.bus_addr != dma_offset) {
984 pr_warn("Can't handle multiple dma-ranges with different offsets on node(%pOF)\n", node);
985 /* Don't error out as we'd break some existing DTs */
988 dma_offset = range.cpu_addr - range.bus_addr;
990 /* Take lower and upper limits */
991 if (range.bus_addr < dma_start)
992 dma_start = range.bus_addr;
993 if (range.bus_addr + range.size > dma_end)
994 dma_end = range.bus_addr + range.size;
997 if (dma_start >= dma_end) {
999 pr_debug("Invalid DMA ranges configuration on node(%pOF)\n",
1004 *dma_addr = dma_start;
1005 *size = dma_end - dma_start;
1006 *paddr = dma_start + dma_offset;
1008 pr_debug("final: dma_addr(%llx) cpu_addr(%llx) size(%llx)\n",
1009 *dma_addr, *paddr, *size);
1018 * of_dma_is_coherent - Check if device is coherent
1021 * It returns true if "dma-coherent" property was found
1022 * for this device in the DT, or if DMA is coherent by
1023 * default for OF devices on the current platform.
1025 bool of_dma_is_coherent(struct device_node *np)
1027 struct device_node *node = of_node_get(np);
1029 if (IS_ENABLED(CONFIG_OF_DMA_DEFAULT_COHERENT))
1033 if (of_property_read_bool(node, "dma-coherent")) {
1037 node = of_get_next_dma_parent(node);
1042 EXPORT_SYMBOL_GPL(of_dma_is_coherent);