powerpc: Add of_find_next_cache_node()
authorNathan Lynch <ntl@pobox.com>
Wed, 10 Dec 2008 14:46:04 +0000 (14:46 +0000)
committerPaul Mackerras <paulus@samba.org>
Sun, 21 Dec 2008 03:21:14 +0000 (14:21 +1100)
We have more than one piece of code that looks up cache nodes manually
using the "l2-cache" property.  Add a common helper routine which does
this and handles ePAPR's "next-level-cache" property as well as
powermac.

Signed-off-by: Nathan Lynch <ntl@pobox.com>
Signed-off-by: Paul Mackerras <paulus@samba.org>
arch/powerpc/include/asm/prom.h
arch/powerpc/kernel/prom.c

index eb3bd2e..6ff0418 100644 (file)
@@ -253,6 +253,9 @@ extern void kdump_move_device_tree(void);
 /* CPU OF node matching */
 struct device_node *of_get_cpu_node(int cpu, unsigned int *thread);
 
+/* cache lookup */
+struct device_node *of_find_next_cache_node(struct device_node *np);
+
 /* Get the MAC address */
 extern const void *of_get_mac_address(struct device_node *np);
 
index 3a2dc7e..d8266dd 100644 (file)
@@ -1270,6 +1270,37 @@ struct device_node *of_find_node_by_phandle(phandle handle)
 }
 EXPORT_SYMBOL(of_find_node_by_phandle);
 
+/**
+ *     of_find_next_cache_node - Find a node's subsidiary cache
+ *     @np:    node of type "cpu" or "cache"
+ *
+ *     Returns a node pointer with refcount incremented, use
+ *     of_node_put() on it when done.  Caller should hold a reference
+ *     to np.
+ */
+struct device_node *of_find_next_cache_node(struct device_node *np)
+{
+       struct device_node *child;
+       const phandle *handle;
+
+       handle = of_get_property(np, "l2-cache", NULL);
+       if (!handle)
+               handle = of_get_property(np, "next-level-cache", NULL);
+
+       if (handle)
+               return of_find_node_by_phandle(*handle);
+
+       /* OF on pmac has nodes instead of properties named "l2-cache"
+        * beneath CPU nodes.
+        */
+       if (!strcmp(np->type, "cpu"))
+               for_each_child_of_node(np, child)
+                       if (!strcmp(child->type, "cache"))
+                               return child;
+
+       return NULL;
+}
+
 /**
  *     of_find_all_nodes - Get next node in global list
  *     @prev:  Previous node or NULL to start iteration