Skip to content

Commit ce5cb67

Browse files
willdeaconkonradwilk
authored andcommitted
of: Move of_dma_set_restricted_buffer() into device.c
Rob observes that: | of_dma_set_restricted_buffer() [...] should also be moved to | of/device.c. There's no reason for it to be in of/address.c. It has | nothing to do with address parsing. Move it to of/device.c, as he suggests. Cc: Claire Chang <[email protected]> Cc: Konrad Rzeszutek Wilk <[email protected]> Cc: Christoph Hellwig <[email protected]> Cc: Robin Murphy <[email protected]> Suggested-by: Rob Herring <[email protected]> Link: https://lore.kernel.org/r/CAL_JsqJ7ROWWJX84x2kEex9NQ8G+2=ybRuNOobX+j8bjZzSemQ@mail.gmail.com Signed-off-by: Will Deacon <[email protected]> Signed-off-by: Konrad Rzeszutek Wilk <[email protected]>
1 parent a449ffa commit ce5cb67

File tree

3 files changed

+34
-40
lines changed

3 files changed

+34
-40
lines changed

drivers/of/address.c

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <linux/logic_pio.h>
99
#include <linux/module.h>
1010
#include <linux/of_address.h>
11-
#include <linux/of_reserved_mem.h>
1211
#include <linux/pci.h>
1312
#include <linux/pci_regs.h>
1413
#include <linux/sizes.h>
@@ -996,38 +995,6 @@ int of_dma_get_range(struct device_node *np, const struct bus_dma_region **map)
996995
of_node_put(node);
997996
return ret;
998997
}
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-
}
1031998
#endif /* CONFIG_HAS_DMA */
1032999

10331000
/**

drivers/of/device.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <linux/of_device.h>
66
#include <linux/of_address.h>
77
#include <linux/of_iommu.h>
8+
#include <linux/of_reserved_mem.h>
89
#include <linux/dma-direct.h> /* for bus_dma_region */
910
#include <linux/dma-map-ops.h>
1011
#include <linux/init.h>
@@ -52,6 +53,39 @@ int of_device_add(struct platform_device *ofdev)
5253
return device_add(&ofdev->dev);
5354
}
5455

56+
static int
57+
of_dma_set_restricted_buffer(struct device *dev, struct device_node *np)
58+
{
59+
struct device_node *node, *of_node = dev->of_node;
60+
int count, i;
61+
62+
count = of_property_count_elems_of_size(of_node, "memory-region",
63+
sizeof(u32));
64+
/*
65+
* If dev->of_node doesn't exist or doesn't contain memory-region, try
66+
* the OF node having DMA configuration.
67+
*/
68+
if (count <= 0) {
69+
of_node = np;
70+
count = of_property_count_elems_of_size(
71+
of_node, "memory-region", sizeof(u32));
72+
}
73+
74+
for (i = 0; i < count; i++) {
75+
node = of_parse_phandle(of_node, "memory-region", i);
76+
/*
77+
* There might be multiple memory regions, but only one
78+
* restricted-dma-pool region is allowed.
79+
*/
80+
if (of_device_is_compatible(node, "restricted-dma-pool") &&
81+
of_device_is_available(node))
82+
return of_reserved_mem_device_init_by_idx(dev, of_node,
83+
i);
84+
}
85+
86+
return 0;
87+
}
88+
5589
/**
5690
* of_dma_configure_id - Setup DMA configuration
5791
* @dev: Device to apply DMA configuration

drivers/of/of_private.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,19 +163,12 @@ struct bus_dma_region;
163163
#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA)
164164
int of_dma_get_range(struct device_node *np,
165165
const struct bus_dma_region **map);
166-
int of_dma_set_restricted_buffer(struct device *dev, struct device_node *np);
167166
#else
168167
static inline int of_dma_get_range(struct device_node *np,
169168
const struct bus_dma_region **map)
170169
{
171170
return -ENODEV;
172171
}
173-
static inline int of_dma_set_restricted_buffer(struct device *dev,
174-
struct device_node *np)
175-
{
176-
/* Do nothing, successfully. */
177-
return 0;
178-
}
179172
#endif
180173

181174
void fdt_init_reserved_mem(void);

0 commit comments

Comments
 (0)