]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blobdiff - arch/powerpc/platforms/cell/spu_base.c
[PATCH] spufs: fix for CONFIG_NUMA
[mirror_ubuntu-zesty-kernel.git] / arch / powerpc / platforms / cell / spu_base.c
index 081b3dcbaf1405f2a0d30e6797d6f51ddfb6c8cb..b788e165c557254fd3c3fde11ba594c6cf153d43 100644 (file)
@@ -32,7 +32,7 @@
 
 #include <asm/io.h>
 #include <asm/prom.h>
-#include <asm/semaphore.h>
+#include <linux/mutex.h>
 #include <asm/spu.h>
 #include <asm/mmu_context.h>
 
@@ -111,7 +111,7 @@ static int __spu_trap_data_seg(struct spu *spu, unsigned long ea)
 extern int hash_page(unsigned long ea, unsigned long access, unsigned long trap); //XXX
 static int __spu_trap_data_map(struct spu *spu, unsigned long ea, u64 dsisr)
 {
-       pr_debug("%s\n", __FUNCTION__);
+       pr_debug("%s, %lx, %lx\n", __FUNCTION__, dsisr, ea);
 
        /* Handle kernel space hash faults immediately.
           User hash faults need to be deferred to process context. */
@@ -168,7 +168,7 @@ static int __spu_trap_halt(struct spu *spu)
 static int __spu_trap_tag_group(struct spu *spu)
 {
        pr_debug("%s\n", __FUNCTION__);
-       /* wake_up(&spu->dma_wq); */
+       spu->mfc_callback(spu);
        return 0;
 }
 
@@ -242,6 +242,8 @@ spu_irq_class_1(int irq, void *data, struct pt_regs *regs)
                spu_mfc_dsisr_set(spu, 0ul);
        spu_int_stat_clear(spu, 1, stat);
        spin_unlock(&spu->register_lock);
+       pr_debug("%s: %lx %lx %lx %lx\n", __FUNCTION__, mask, stat,
+                       dar, dsisr);
 
        if (stat & 1) /* segment fault */
                __spu_trap_data_seg(spu, dar);
@@ -304,19 +306,19 @@ spu_request_irqs(struct spu *spu)
 
        snprintf(spu->irq_c0, sizeof (spu->irq_c0), "spe%02d.0", spu->number);
        ret = request_irq(irq_base + spu->isrc,
-                spu_irq_class_0, 0, spu->irq_c0, spu);
+                spu_irq_class_0, SA_INTERRUPT, spu->irq_c0, spu);
        if (ret)
                goto out;
 
        snprintf(spu->irq_c1, sizeof (spu->irq_c1), "spe%02d.1", spu->number);
        ret = request_irq(irq_base + IIC_CLASS_STRIDE + spu->isrc,
-                spu_irq_class_1, 0, spu->irq_c1, spu);
+                spu_irq_class_1, SA_INTERRUPT, spu->irq_c1, spu);
        if (ret)
                goto out1;
 
        snprintf(spu->irq_c2, sizeof (spu->irq_c2), "spe%02d.2", spu->number);
        ret = request_irq(irq_base + 2*IIC_CLASS_STRIDE + spu->isrc,
-                spu_irq_class_2, 0, spu->irq_c2, spu);
+                spu_irq_class_2, SA_INTERRUPT, spu->irq_c2, spu);
        if (ret)
                goto out2;
        goto out;
@@ -342,7 +344,7 @@ spu_free_irqs(struct spu *spu)
 }
 
 static LIST_HEAD(spu_list);
-static DECLARE_MUTEX(spu_mutex);
+static DEFINE_MUTEX(spu_mutex);
 
 static void spu_init_channels(struct spu *spu)
 {
@@ -357,7 +359,7 @@ static void spu_init_channels(struct spu *spu)
                { 0x17, 1, }, { 0x18, 0, }, { 0x19, 0, }, { 0x1b, 0, },
                { 0x1c, 1, }, { 0x1d, 0, }, { 0x1e, 1, },
        };
-       struct spu_priv2 *priv2;
+       struct spu_priv2 __iomem *priv2;
        int i;
 
        priv2 = spu->priv2;
@@ -382,7 +384,7 @@ struct spu *spu_alloc(void)
 {
        struct spu *spu;
 
-       down(&spu_mutex);
+       mutex_lock(&spu_mutex);
        if (!list_empty(&spu_list)) {
                spu = list_entry(spu_list.next, struct spu, list);
                list_del_init(&spu->list);
@@ -391,7 +393,7 @@ struct spu *spu_alloc(void)
                pr_debug("No SPU left\n");
                spu = NULL;
        }
-       up(&spu_mutex);
+       mutex_unlock(&spu_mutex);
 
        if (spu)
                spu_init_channels(spu);
@@ -402,9 +404,9 @@ EXPORT_SYMBOL_GPL(spu_alloc);
 
 void spu_free(struct spu *spu)
 {
-       down(&spu_mutex);
+       mutex_lock(&spu_mutex);
        list_add_tail(&spu->list, &spu_list);
-       up(&spu_mutex);
+       mutex_unlock(&spu_mutex);
 }
 EXPORT_SYMBOL_GPL(spu_free);
 
@@ -484,14 +486,17 @@ int spu_irq_class_1_bottom(struct spu *spu)
 
        ea = spu->dar;
        dsisr = spu->dsisr;
-       if (dsisr & MFC_DSISR_PTE_NOT_FOUND) {
+       if (dsisr & (MFC_DSISR_PTE_NOT_FOUND | MFC_DSISR_ACCESS_DENIED)) {
+               u64 flags;
+
                access = (_PAGE_PRESENT | _PAGE_USER);
                access |= (dsisr & MFC_DSISR_ACCESS_PUT) ? _PAGE_RW : 0UL;
+               local_irq_save(flags);
                if (hash_page(ea, access, 0x300) != 0)
                        error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
+               local_irq_restore(flags);
        }
-       if ((error & CLASS1_ENABLE_STORAGE_FAULT_INTR) ||
-           (dsisr & MFC_DSISR_ACCESS_DENIED)) {
+       if (error & CLASS1_ENABLE_STORAGE_FAULT_INTR) {
                if ((ret = spu_handle_mm_fault(spu)) != 0)
                        error |= CLASS1_ENABLE_STORAGE_FAULT_INTR;
                else
@@ -507,6 +512,64 @@ int spu_irq_class_1_bottom(struct spu *spu)
        return ret;
 }
 
+void spu_irq_setaffinity(struct spu *spu, int cpu)
+{
+       u64 target = iic_get_target_id(cpu);
+       u64 route = target << 48 | target << 32 | target << 16;
+       spu_int_route_set(spu, route);
+}
+EXPORT_SYMBOL_GPL(spu_irq_setaffinity);
+
+static int __init find_spu_node_id(struct device_node *spe)
+{
+       unsigned int *id;
+       struct device_node *cpu;
+       cpu = spe->parent->parent;
+       id = (unsigned int *)get_property(cpu, "node-id", NULL);
+       return id ? *id : 0;
+}
+
+static int __init cell_spuprop_present(struct device_node *spe,
+                                       const char *prop)
+{
+       static DEFINE_MUTEX(add_spumem_mutex);
+
+       struct address_prop {
+               unsigned long address;
+               unsigned int len;
+       } __attribute__((packed)) *p;
+       int proplen;
+
+       unsigned long start_pfn, nr_pages;
+       int node_id;
+       struct pglist_data *pgdata;
+       struct zone *zone;
+       int ret;
+
+       p = (void*)get_property(spe, prop, &proplen);
+       WARN_ON(proplen != sizeof (*p));
+
+       start_pfn = p->address >> PAGE_SHIFT;
+       nr_pages = ((unsigned long)p->len + PAGE_SIZE - 1) >> PAGE_SHIFT;
+
+       /*
+        * XXX need to get the correct NUMA node in here. This may
+        * be different from the spe::node_id property, e.g. when
+        * the host firmware is not NUMA aware.
+        */
+       node_id = 0;
+
+       pgdata = NODE_DATA(node_id);
+       zone = pgdata->node_zones;
+
+       /* XXX rethink locking here */
+       mutex_lock(&add_spumem_mutex);
+       ret = __add_pages(zone, start_pfn, nr_pages);
+       mutex_unlock(&add_spumem_mutex);
+
+       return ret;
+}
+
 static void __iomem * __init map_spe_prop(struct device_node *n,
                                                 const char *name)
 {
@@ -517,6 +580,8 @@ static void __iomem * __init map_spe_prop(struct device_node *n,
 
        void *p;
        int proplen;
+       void* ret = NULL;
+       int err = 0;
 
        p = get_property(n, name, &proplen);
        if (proplen != sizeof (struct address_prop))
@@ -524,7 +589,14 @@ static void __iomem * __init map_spe_prop(struct device_node *n,
 
        prop = p;
 
-       return ioremap(prop->address, prop->len);
+       err = cell_spuprop_present(n, name);
+       if (err && (err != -EEXIST))
+               goto out;
+
+       ret = ioremap(prop->address, prop->len);
+
+ out:
+       return ret;
 }
 
 static void spu_unmap(struct spu *spu)
@@ -560,6 +632,11 @@ static int __init spu_map_device(struct spu *spu, struct device_node *spe)
        if (!spu->local_store)
                goto out;
 
+       prop = get_property(spe, "problem", NULL);
+       if (!prop)
+               goto out_unmap;
+       spu->problem_phys = *(unsigned long *)prop;
+
        spu->problem= map_spe_prop(spe, "problem");
        if (!spu->problem)
                goto out_unmap;
@@ -579,17 +656,6 @@ out:
        return ret;
 }
 
-static int __init find_spu_node_id(struct device_node *spe)
-{
-       unsigned int *id;
-       struct device_node *cpu;
-
-       cpu = spe->parent->parent;
-       id = (unsigned int *)get_property(cpu, "node-id", NULL);
-
-       return id ? *id : 0;
-}
-
 static int __init create_spu(struct device_node *spe)
 {
        struct spu *spu;
@@ -624,15 +690,16 @@ static int __init create_spu(struct device_node *spe)
        spu->ibox_callback = NULL;
        spu->wbox_callback = NULL;
        spu->stop_callback = NULL;
+       spu->mfc_callback = NULL;
 
-       down(&spu_mutex);
+       mutex_lock(&spu_mutex);
        spu->number = number++;
        ret = spu_request_irqs(spu);
        if (ret)
                goto out_unmap;
 
        list_add(&spu->list, &spu_list);
-       up(&spu_mutex);
+       mutex_unlock(&spu_mutex);
 
        pr_debug(KERN_DEBUG "Using SPE %s %02x %p %p %p %p %d\n",
                spu->name, spu->isrc, spu->local_store,
@@ -640,7 +707,7 @@ static int __init create_spu(struct device_node *spe)
        goto out;
 
 out_unmap:
-       up(&spu_mutex);
+       mutex_unlock(&spu_mutex);
        spu_unmap(spu);
 out_free:
        kfree(spu);
@@ -660,10 +727,10 @@ static void destroy_spu(struct spu *spu)
 static void cleanup_spu_base(void)
 {
        struct spu *spu, *tmp;
-       down(&spu_mutex);
+       mutex_lock(&spu_mutex);
        list_for_each_entry_safe(spu, tmp, &spu_list, list)
                destroy_spu(spu);
-       up(&spu_mutex);
+       mutex_unlock(&spu_mutex);
 }
 module_exit(cleanup_spu_base);