|
8 | 8 | #include <linux/logic_pio.h> |
9 | 9 | #include <linux/module.h> |
10 | 10 | #include <linux/of_address.h> |
| 11 | +#include <linux/of_reserved_mem.h> |
11 | 12 | #include <linux/pci.h> |
12 | 13 | #include <linux/pci_regs.h> |
13 | 14 | #include <linux/sizes.h> |
@@ -995,6 +996,38 @@ int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map) |
995 | 996 | of_node_put(node); |
996 | 997 | return ret; |
997 | 998 | } |
| 999 | + |
| 1000 | +int of_dma_set_restricted_buffer(struct device *dev, struct device_node *np) |
| 1001 | +{ |
| 1002 | + struct device_node *node, *of_node = dev->of_node; |
| 1003 | + int count, i; |
| 1004 | + |
| 1005 | + count = of_property_count_elems_of_size(of_node, "memory-region", |
| 1006 | + sizeof(u32)); |
| 1007 | + /* |
| 1008 | + * If dev->of_node doesn't exist or doesn't contain memory-region, try |
| 1009 | + * the OF node having DMA configuration. |
| 1010 | + */ |
| 1011 | + if (count <= 0) { |
| 1012 | + of_node = np; |
| 1013 | + count = of_property_count_elems_of_size( |
| 1014 | + of_node, "memory-region", sizeof(u32)); |
| 1015 | + } |
| 1016 | + |
| 1017 | + for (i = 0; i < count; i++) { |
| 1018 | + node = of_parse_phandle(of_node, "memory-region", i); |
| 1019 | + /* |
| 1020 | + * There might be multiple memory regions, but only one |
| 1021 | + * restricted-dma-pool region is allowed. |
| 1022 | + */ |
| 1023 | + if (of_device_is_compatible(node, "restricted-dma-pool") && |
| 1024 | + of_device_is_available(node)) |
| 1025 | + return of_reserved_mem_device_init_by_idx(dev, of_node, |
| 1026 | + i); |
| 1027 | + } |
| 1028 | + |
| 1029 | + return 0; |
| 1030 | +} |
998 | 1031 | #endif /* CONFIG_HAS_DMA */ |
999 | 1032 |
|
1000 | 1033 | /** |
|
0 commit comments