From 5d61b165c892853f2daf6220d2ec6577487e273a Mon Sep 17 00:00:00 2001 From: Stephen Warren Date: Wed, 25 Jul 2012 17:34:37 -0600 Subject: of: Allow busses with #size-cells=0 It's quite legitimate for a DT node to specify #size-cells=0. One example is a node that's used to collect a number of non-memory-mapped devices. In that scenario, there may be multiple child nodes with the same name (type) thus necessitating the use of unit addresses in node names, and reg properties: / { regulators { compatible = "simple-bus"; #address-cells = <1>; #size-cells = <0>; regulator@0 { compatible = "regulator-fixed"; reg = <0>; ... }; regulator@1 { compatible = "regulator-fixed"; reg = <1>; ... }; ... }; }; However, #size-cells=0 prevents translation of reg property values into the parent node's address space. In turn, this triggers the kernel to emit error messages during boot, such as: prom_parse: Bad cell count for /regulators/regulator@0 To prevent printing these error messages for legitimate DT content, a number of changes are made: 1) of_get_address()/of_get_pci_address() are modified only to validate the value of #address-cells, and not #size-cells. 2) of_can_translate_address() is added to indicate whether address translation is possible. 3) of_device_make_bus_id() is modified to name devices based on the translated address only where possible, and otherwise fall back to using the (first cell of the) raw untranslated address. 4) of_device_alloc() is modified to create memory resources for a device only if the address can be translated into the CPU's address space. Signed-off-by: Stephen Warren Signed-off-by: Rob Herring --- drivers/of/address.c | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) (limited to 'drivers/of/address.c') diff --git a/drivers/of/address.c b/drivers/of/address.c index 7e262a6..7a07751 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -9,8 +9,8 @@ /* Max address size we deal with */ #define OF_MAX_ADDR_CELLS 4 -#define OF_CHECK_COUNTS(na, ns) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS && \ - (ns) > 0) +#define OF_CHECK_ADDR_COUNT(na) ((na) > 0 && (na) <= OF_MAX_ADDR_CELLS) +#define OF_CHECK_COUNTS(na, ns) (OF_CHECK_ADDR_COUNT(na) && (ns) > 0) static struct of_bus *of_match_bus(struct device_node *np); static int __of_address_to_resource(struct device_node *dev, @@ -182,7 +182,7 @@ const __be32 *of_get_pci_address(struct device_node *dev, int bar_no, u64 *size, } bus->count_cells(dev, &na, &ns); of_node_put(parent); - if (!OF_CHECK_COUNTS(na, ns)) + if (!OF_CHECK_ADDR_COUNT(na)) return NULL; /* Get "reg" or "assigned-addresses" property */ @@ -490,6 +490,25 @@ u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr) } EXPORT_SYMBOL(of_translate_dma_address); +bool of_can_translate_address(struct device_node *dev) +{ + struct device_node *parent; + struct of_bus *bus; + int na, ns; + + parent = of_get_parent(dev); + if (parent == NULL) + return false; + + bus = of_match_bus(parent); + bus->count_cells(dev, &na, &ns); + + of_node_put(parent); + + return OF_CHECK_COUNTS(na, ns); +} +EXPORT_SYMBOL(of_can_translate_address); + const __be32 *of_get_address(struct device_node *dev, int index, u64 *size, unsigned int *flags) { @@ -506,7 +525,7 @@ const __be32 *of_get_address(struct device_node *dev, int index, u64 *size, bus = of_match_bus(parent); bus->count_cells(dev, &na, &ns); of_node_put(parent); - if (!OF_CHECK_COUNTS(na, ns)) + if (!OF_CHECK_ADDR_COUNT(na)) return NULL; /* Get "reg" or "assigned-addresses" property */ -- cgit v1.1 From e38c0a1fbc5803cbacdaac0557c70ac8ca5152e7 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 26 Jul 2012 21:55:10 +0200 Subject: of/address: Handle #address-cells > 2 specially When a bus specifies #address-cells > 2, of_bus_default_map() now assumes that the mapping isn't for a physical address but rather an identifier that needs to match exactly. This is required by bindings that use multiple cells to translate a resource to the parent bus (device index, type, ...). See here for the discussion: https://lists.ozlabs.org/pipermail/devicetree-discuss/2012-June/016577.html Originally-by: Arnd Bergmann Signed-off-by: Thierry Reding Signed-off-by: Rob Herring --- drivers/of/address.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'drivers/of/address.c') diff --git a/drivers/of/address.c b/drivers/of/address.c index 7a07751..72e496f 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -69,6 +69,14 @@ static u64 of_bus_default_map(u32 *addr, const __be32 *range, (unsigned long long)cp, (unsigned long long)s, (unsigned long long)da); + /* + * If the number of address cells is larger than 2 we assume the + * mapping doesn't specify a physical address. Rather, the address + * specifies an identifier that must match exactly. + */ + if (na > 2 && memcmp(range, addr, na * 4) != 0) + return OF_BAD_ADDR; + if (da < cp || da >= (cp + s)) return OF_BAD_ADDR; return da - cp; -- cgit v1.1