]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - drivers/of/address.c
of/address: Handle #address-cells > 2 specially
[karo-tx-linux.git] / drivers / of / address.c
index 7e262a6124c5919a495545bb1f7402ae4350295a..72e496f1e9b082d576f439c442a07721330f1928 100644 (file)
@@ -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,
@@ -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;
@@ -182,7 +190,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 +498,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 +533,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 */