Skip to content

Commit f1ad533

Browse files
rmurphy-armrobherring
authored andcommitted
of: Fix "dma-ranges" handling for bus controllers
Commit 951d488 ("of: Make of_dma_get_range() work on bus nodes") relaxed the handling of "dma-ranges" for any leaf node on the assumption that it would still represent a usage error for the property to be present on a non-bus leaf node. However there turns out to be a fiddly case where a bus also represents a DMA-capable device in its own right, such as a PCIe root complex with an integrated DMA engine on its platform side. In such cases, "dma-ranges" translation is entirely valid for devices discovered behind the bus, but should not be erroneously applied to the bus controller device itself which operates in its parent's address space. Fix this by restoring the previous behaviour for the specific case where a device is configured via its own OF node, since it is logical to assume that a device should never represent its own parent bus. Reported-by: Serge Semin <[email protected]> Signed-off-by: Robin Murphy <[email protected]> Link: https://lore.kernel.org/r/112e8f3d3e7c054ecf5e12b5ac0aa5596ec00681.1664455433.git.robin.murphy@arm.com Signed-off-by: Rob Herring <[email protected]>
1 parent 1700560 commit f1ad533

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

drivers/of/address.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,8 @@ u64 of_translate_address(struct device_node *dev, const __be32 *in_addr)
579579
}
580580
EXPORT_SYMBOL(of_translate_address);
581581

582-
static struct device_node *__of_get_dma_parent(const struct device_node *np)
582+
#ifdef CONFIG_HAS_DMA
583+
struct device_node *__of_get_dma_parent(const struct device_node *np)
583584
{
584585
struct of_phandle_args args;
585586
int ret, index;
@@ -596,6 +597,7 @@ static struct device_node *__of_get_dma_parent(const struct device_node *np)
596597

597598
return of_node_get(args.np);
598599
}
600+
#endif
599601

600602
static struct device_node *of_get_next_dma_parent(struct device_node *np)
601603
{

drivers/of/device.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,12 +116,19 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
116116
{
117117
const struct iommu_ops *iommu;
118118
const struct bus_dma_region *map = NULL;
119+
struct device_node *bus_np;
119120
u64 dma_start = 0;
120121
u64 mask, end, size = 0;
121122
bool coherent;
122123
int ret;
123124

124-
ret = of_dma_get_range(np, &map);
125+
if (np == dev->of_node)
126+
bus_np = __of_get_dma_parent(np);
127+
else
128+
bus_np = of_node_get(np);
129+
130+
ret = of_dma_get_range(bus_np, &map);
131+
of_node_put(bus_np);
125132
if (ret < 0) {
126133
/*
127134
* For legacy reasons, we have to assume some devices need

drivers/of/of_private.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,17 @@ struct bus_dma_region;
155155
#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA)
156156
int of_dma_get_range(struct device_node *np,
157157
const struct bus_dma_region **map);
158+
struct device_node *__of_get_dma_parent(const struct device_node *np);
158159
#else
159160
static inline int of_dma_get_range(struct device_node *np,
160161
const struct bus_dma_region **map)
161162
{
162163
return -ENODEV;
163164
}
165+
static inline struct device_node *__of_get_dma_parent(const struct device_node *np)
166+
{
167+
return of_get_parent(np);
168+
}
164169
#endif
165170

166171
void fdt_init_reserved_mem(void);

0 commit comments

Comments
 (0)