Skip to content

Commit 92ea637

Browse files
author
Santosh Shilimkar
committed
of: introduce of_dma_is_coherent() helper
The of_dma_is_coherent() helper parses the given DT device node to see if the "dma-coherent" property is supported and returns true or false accordingly. If the arch is always coherent or always noncoherent, then the default DMA ops has to be specified accordingly. Cc: Greg Kroah-Hartman <[email protected]> Cc: Russell King <[email protected]> Cc: Arnd Bergmann <[email protected]> Cc: Olof Johansson <[email protected]> Cc: Grant Likely <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Linus Walleij <[email protected]> Reviewed-by: Rob Herring <[email protected]> Signed-off-by: Santosh Shilimkar <[email protected]> Signed-off-by: Grygorii Strashko <[email protected]>
1 parent 18308c9 commit 92ea637

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

drivers/of/address.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,3 +808,26 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz
808808
return ret;
809809
}
810810
EXPORT_SYMBOL_GPL(of_dma_get_range);
811+
812+
/**
813+
* of_dma_is_coherent - Check if device is coherent
814+
* @np: device node
815+
*
816+
* It returns true if "dma-coherent" property was found
817+
* for this device in DT.
818+
*/
819+
bool of_dma_is_coherent(struct device_node *np)
820+
{
821+
struct device_node *node = of_node_get(np);
822+
823+
while (node) {
824+
if (of_property_read_bool(node, "dma-coherent")) {
825+
of_node_put(node);
826+
return true;
827+
}
828+
node = of_get_next_parent(node);
829+
}
830+
of_node_put(node);
831+
return false;
832+
}
833+
EXPORT_SYMBOL_GPL(of_dma_is_coherent);

include/linux/of_address.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ extern struct of_pci_range *of_pci_range_parser_one(
6565
struct of_pci_range *range);
6666
extern int of_dma_get_range(struct device_node *np, u64 *dma_addr,
6767
u64 *paddr, u64 *size);
68+
extern bool of_dma_is_coherent(struct device_node *np);
6869
#else /* CONFIG_OF_ADDRESS */
6970
static inline struct device_node *of_find_matching_node_by_address(
7071
struct device_node *from,
@@ -98,6 +99,11 @@ static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr,
9899
{
99100
return -ENODEV;
100101
}
102+
103+
static inline bool of_dma_is_coherent(struct device_node *np)
104+
{
105+
return false;
106+
}
101107
#endif /* CONFIG_OF_ADDRESS */
102108

103109
#ifdef CONFIG_OF

0 commit comments

Comments
 (0)