Commit 89897f73 authored by Hector Martin's avatar Hector Martin

of/address: Add infrastructure to declare MMIO as non-posted

This implements the 'nonposted-mmio' boolean property. Placing this
property in a bus marks all direct child devices as requiring
non-posted MMIO mappings. If no such property is found, the default
is posted MMIO.

of_mmio_is_nonposted() performs this check to determine if a given
device has requested non-posted MMIO.

of_address_to_resource() uses this to set the IORESOURCE_MEM_NONPOSTED
flag on resources that require non-posted MMIO.

of_iomap() and of_io_request_and_map() then use this flag to pick the
correct ioremap() variant.

This mechanism is currently restricted to builds that support Apple ARM
platforms, as an optimization.
Reviewed-by: default avatarLinus Walleij <linus.walleij@linaro.org>
Reviewed-by: default avatarRob Herring <robh@kernel.org>
Signed-off-by: default avatarHector Martin <marcan@marcan.st>
parent b10eb2d5
...@@ -26,6 +26,7 @@ static struct of_bus *of_match_bus(struct device_node *np); ...@@ -26,6 +26,7 @@ static struct of_bus *of_match_bus(struct device_node *np);
static int __of_address_to_resource(struct device_node *dev, static int __of_address_to_resource(struct device_node *dev,
const __be32 *addrp, u64 size, unsigned int flags, const __be32 *addrp, u64 size, unsigned int flags,
const char *name, struct resource *r); const char *name, struct resource *r);
static bool of_mmio_is_nonposted(struct device_node *np);
/* Debug utility */ /* Debug utility */
#ifdef DEBUG #ifdef DEBUG
...@@ -847,6 +848,9 @@ static int __of_address_to_resource(struct device_node *dev, ...@@ -847,6 +848,9 @@ static int __of_address_to_resource(struct device_node *dev,
return -EINVAL; return -EINVAL;
memset(r, 0, sizeof(struct resource)); memset(r, 0, sizeof(struct resource));
if (of_mmio_is_nonposted(dev))
flags |= IORESOURCE_MEM_NONPOSTED;
r->start = taddr; r->start = taddr;
r->end = taddr + size - 1; r->end = taddr + size - 1;
r->flags = flags; r->flags = flags;
...@@ -896,7 +900,10 @@ void __iomem *of_iomap(struct device_node *np, int index) ...@@ -896,7 +900,10 @@ void __iomem *of_iomap(struct device_node *np, int index)
if (of_address_to_resource(np, index, &res)) if (of_address_to_resource(np, index, &res))
return NULL; return NULL;
return ioremap(res.start, resource_size(&res)); if (res.flags & IORESOURCE_MEM_NONPOSTED)
return ioremap_np(res.start, resource_size(&res));
else
return ioremap(res.start, resource_size(&res));
} }
EXPORT_SYMBOL(of_iomap); EXPORT_SYMBOL(of_iomap);
...@@ -928,7 +935,11 @@ void __iomem *of_io_request_and_map(struct device_node *np, int index, ...@@ -928,7 +935,11 @@ void __iomem *of_io_request_and_map(struct device_node *np, int index,
if (!request_mem_region(res.start, resource_size(&res), name)) if (!request_mem_region(res.start, resource_size(&res), name))
return IOMEM_ERR_PTR(-EBUSY); return IOMEM_ERR_PTR(-EBUSY);
mem = ioremap(res.start, resource_size(&res)); if (res.flags & IORESOURCE_MEM_NONPOSTED)
mem = ioremap_np(res.start, resource_size(&res));
else
mem = ioremap(res.start, resource_size(&res));
if (!mem) { if (!mem) {
release_mem_region(res.start, resource_size(&res)); release_mem_region(res.start, resource_size(&res));
return IOMEM_ERR_PTR(-ENOMEM); return IOMEM_ERR_PTR(-ENOMEM);
...@@ -1094,3 +1105,31 @@ bool of_dma_is_coherent(struct device_node *np) ...@@ -1094,3 +1105,31 @@ bool of_dma_is_coherent(struct device_node *np)
return false; return false;
} }
EXPORT_SYMBOL_GPL(of_dma_is_coherent); EXPORT_SYMBOL_GPL(of_dma_is_coherent);
/**
* of_mmio_is_nonposted - Check if device uses non-posted MMIO
* @np: device node
*
* Returns true if the "nonposted-mmio" property was found for
* the device's bus.
*
* This is currently only enabled on builds that support Apple ARM devices, as
* an optimization.
*/
static bool of_mmio_is_nonposted(struct device_node *np)
{
struct device_node *parent;
bool nonposted;
if (!IS_ENABLED(CONFIG_ARCH_APPLE))
return false;
parent = of_get_parent(np);
if (!parent)
return false;
nonposted = of_property_read_bool(parent, "nonposted-mmio");
of_node_put(parent);
return nonposted;
}
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