Commit f1ad5338 authored by Robin Murphy's avatar Robin Murphy Committed by Rob Herring

of: Fix "dma-ranges" handling for bus controllers

Commit 951d4885 ("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: default avatarSerge Semin <Sergey.Semin@baikalelectronics.ru>
Signed-off-by: default avatarRobin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/112e8f3d3e7c054ecf5e12b5ac0aa5596ec00681.1664455433.git.robin.murphy@arm.comSigned-off-by: default avatarRob Herring <robh@kernel.org>
parent 17005609
...@@ -579,7 +579,8 @@ u64 of_translate_address(struct device_node *dev, const __be32 *in_addr) ...@@ -579,7 +579,8 @@ u64 of_translate_address(struct device_node *dev, const __be32 *in_addr)
} }
EXPORT_SYMBOL(of_translate_address); EXPORT_SYMBOL(of_translate_address);
static struct device_node *__of_get_dma_parent(const struct device_node *np) #ifdef CONFIG_HAS_DMA
struct device_node *__of_get_dma_parent(const struct device_node *np)
{ {
struct of_phandle_args args; struct of_phandle_args args;
int ret, index; int ret, index;
...@@ -596,6 +597,7 @@ static struct device_node *__of_get_dma_parent(const struct device_node *np) ...@@ -596,6 +597,7 @@ static struct device_node *__of_get_dma_parent(const struct device_node *np)
return of_node_get(args.np); return of_node_get(args.np);
} }
#endif
static struct device_node *of_get_next_dma_parent(struct device_node *np) static struct device_node *of_get_next_dma_parent(struct device_node *np)
{ {
......
...@@ -116,12 +116,19 @@ int of_dma_configure_id(struct device *dev, struct device_node *np, ...@@ -116,12 +116,19 @@ int of_dma_configure_id(struct device *dev, struct device_node *np,
{ {
const struct iommu_ops *iommu; const struct iommu_ops *iommu;
const struct bus_dma_region *map = NULL; const struct bus_dma_region *map = NULL;
struct device_node *bus_np;
u64 dma_start = 0; u64 dma_start = 0;
u64 mask, end, size = 0; u64 mask, end, size = 0;
bool coherent; bool coherent;
int ret; int ret;
ret = of_dma_get_range(np, &map); if (np == dev->of_node)
bus_np = __of_get_dma_parent(np);
else
bus_np = of_node_get(np);
ret = of_dma_get_range(bus_np, &map);
of_node_put(bus_np);
if (ret < 0) { if (ret < 0) {
/* /*
* For legacy reasons, we have to assume some devices need * For legacy reasons, we have to assume some devices need
......
...@@ -155,12 +155,17 @@ struct bus_dma_region; ...@@ -155,12 +155,17 @@ struct bus_dma_region;
#if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA) #if defined(CONFIG_OF_ADDRESS) && defined(CONFIG_HAS_DMA)
int of_dma_get_range(struct device_node *np, int of_dma_get_range(struct device_node *np,
const struct bus_dma_region **map); const struct bus_dma_region **map);
struct device_node *__of_get_dma_parent(const struct device_node *np);
#else #else
static inline int of_dma_get_range(struct device_node *np, static inline int of_dma_get_range(struct device_node *np,
const struct bus_dma_region **map) const struct bus_dma_region **map)
{ {
return -ENODEV; return -ENODEV;
} }
static inline struct device_node *__of_get_dma_parent(const struct device_node *np)
{
return of_get_parent(np);
}
#endif #endif
void fdt_init_reserved_mem(void); void fdt_init_reserved_mem(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment