of: unify phandle name in struct device_node
[safe/jmp/linux-2.6] / arch / powerpc / platforms / cell / spu_manage.c
index 5eb8834..891f18e 100644 (file)
@@ -35,6 +35,7 @@
 #include <asm/firmware.h>
 #include <asm/prom.h>
 
+#include "spufs/spufs.h"
 #include "interrupt.h"
 
 struct device_node *spu_devnode(struct spu *spu)
@@ -48,10 +49,18 @@ static u64 __init find_spu_unit_number(struct device_node *spe)
 {
        const unsigned int *prop;
        int proplen;
+
+       /* new device trees should provide the physical-id attribute */
+       prop = of_get_property(spe, "physical-id", &proplen);
+       if (proplen == 4)
+               return (u64)*prop;
+
+       /* celleb device tree provides the unit-id */
        prop = of_get_property(spe, "unit-id", &proplen);
        if (proplen == 4)
                return (u64)*prop;
 
+       /* legacy device trees provide the id in the reg attribute */
        prop = of_get_property(spe, "reg", &proplen);
        if (proplen == 4)
                return (u64)*prop;
@@ -83,7 +92,7 @@ static int __init spu_map_interrupts_old(struct spu *spu,
 
        tmp = of_get_property(np->parent->parent, "node-id", NULL);
        if (!tmp) {
-               printk(KERN_WARNING "%s: can't find node-id\n", __FUNCTION__);
+               printk(KERN_WARNING "%s: can't find node-id\n", __func__);
                nid = spu->node;
        } else
                nid = tmp[0];
@@ -287,7 +296,7 @@ static int __init of_enumerate_spus(int (*fn)(void *data))
                ret = fn(node);
                if (ret) {
                        printk(KERN_WARNING "%s: Error initializing %s\n",
-                               __FUNCTION__, node->name);
+                               __func__, node->name);
                        break;
                }
                n++;
@@ -318,7 +327,7 @@ static int __init of_create_spu(struct spu *spu, void *data)
                if (!legacy_map) {
                        legacy_map = 1;
                        printk(KERN_WARNING "%s: Legacy device tree found, "
-                               "trying to map old style\n", __FUNCTION__);
+                               "trying to map old style\n", __func__);
                }
                ret = spu_map_device_old(spu);
                if (ret) {
@@ -333,11 +342,11 @@ static int __init of_create_spu(struct spu *spu, void *data)
                if (!legacy_irq) {
                        legacy_irq = 1;
                        printk(KERN_WARNING "%s: Legacy device tree found, "
-                               "trying old style irq\n", __FUNCTION__);
+                               "trying old style irq\n", __func__);
                }
                ret = spu_map_interrupts_old(spu, spe);
                if (ret) {
-                       printk(KERN_ERR "%s: could not map interrupts",
+                       printk(KERN_ERR "%s: could not map interrupts\n",
                                spu->name);
                        goto out_unmap;
                }
@@ -361,6 +370,16 @@ static int of_destroy_spu(struct spu *spu)
        return 0;
 }
 
+static void enable_spu_by_master_run(struct spu_context *ctx)
+{
+       ctx->ops->master_start(ctx);
+}
+
+static void disable_spu_by_master_run(struct spu_context *ctx)
+{
+       ctx->ops->master_stop(ctx);
+}
+
 /* Hardcoded affinity idxs for qs20 */
 #define QS20_SPES_PER_BE 8
 static int qs20_reg_idxs[QS20_SPES_PER_BE] =   { 0, 2, 4, 6, 7, 5, 3, 1 };
@@ -369,10 +388,10 @@ static int qs20_reg_memory[QS20_SPES_PER_BE] = { 1, 1, 0, 0, 0, 0, 0, 0 };
 static struct spu *spu_lookup_reg(int node, u32 reg)
 {
        struct spu *spu;
-       u32 *spu_reg;
+       const u32 *spu_reg;
 
        list_for_each_entry(spu, &cbe_spu_info[node].spus, cbe_list) {
-               spu_reg = (u32*)of_get_property(spu_devnode(spu), "reg", NULL);
+               spu_reg = of_get_property(spu_devnode(spu), "reg", NULL);
                if (*spu_reg == reg)
                        return spu;
        }
@@ -403,10 +422,15 @@ static void init_affinity_qs20_harcoded(void)
 
 static int of_has_vicinity(void)
 {
-       struct spu* spu;
+       struct device_node *dn;
 
-       spu = list_first_entry(&cbe_spu_info[0].spus, struct spu, cbe_list);
-       return of_find_property(spu_devnode(spu), "vicinity", NULL) != NULL;
+       for_each_node_by_type(dn, "spe") {
+               if (of_find_property(dn, "vicinity", NULL))  {
+                       of_node_put(dn);
+                       return 1;
+               }
+       }
+       return 0;
 }
 
 static struct spu *devnode_spu(int cbe, struct device_node *dn)
@@ -433,7 +457,7 @@ neighbour_spu(int cbe, struct device_node *target, struct device_node *avoid)
                        continue;
                vic_handles = of_get_property(spu_dn, "vicinity", &lenp);
                for (i=0; i < (lenp / sizeof(phandle)); i++) {
-                       if (vic_handles[i] == target->linux_phandle)
+                       if (vic_handles[i] == target->phandle)
                                return spu;
                }
        }
@@ -475,7 +499,7 @@ static void init_affinity_node(int cbe)
 
                        if (strcmp(name, "spe") == 0) {
                                spu = devnode_spu(cbe, vic_dn);
-                               avoid_ph = last_spu_dn->linux_phandle;
+                               avoid_ph = last_spu_dn->phandle;
                        } else {
                                /*
                                 * "mic-tm" and "bif0" nodes do not have
@@ -490,7 +514,7 @@ static void init_affinity_node(int cbe)
                                        last_spu->has_mem_affinity = 1;
                                        spu->has_mem_affinity = 1;
                                }
-                               avoid_ph = vic_dn->linux_phandle;
+                               avoid_ph = vic_dn->phandle;
                        }
 
                        list_add_tail(&spu->aff_list, &last_spu->aff_list);
@@ -517,7 +541,7 @@ static int __init init_affinity(void)
                if (of_flat_dt_is_compatible(root, "IBM,CPBW-1.0"))
                        init_affinity_qs20_harcoded();
                else
-                       printk("No affinity configuration found");
+                       printk("No affinity configuration found\n");
        }
 
        return 0;
@@ -527,5 +551,7 @@ const struct spu_management_ops spu_management_of_ops = {
        .enumerate_spus = of_enumerate_spus,
        .create_spu = of_create_spu,
        .destroy_spu = of_destroy_spu,
+       .enable_spu = enable_spu_by_master_run,
+       .disable_spu = disable_spu_by_master_run,
        .init_affinity = init_affinity,
 };