include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[safe/jmp/linux-2.6] / arch / powerpc / platforms / cell / spufs / file.c
index b6f7b91..5c28082 100644 (file)
@@ -29,7 +29,7 @@
 #include <linux/poll.h>
 #include <linux/ptrace.h>
 #include <linux/seq_file.h>
-#include <linux/marker.h>
+#include <linux/slab.h>
 
 #include <asm/io.h>
 #include <asm/time.h>
@@ -38,6 +38,7 @@
 #include <asm/uaccess.h>
 
 #include "spufs.h"
+#include "sputrace.h"
 
 #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
 
@@ -147,7 +148,7 @@ static int __fops ## _open(struct inode *inode, struct file *file)  \
        __simple_attr_check_format(__fmt, 0ull);                        \
        return spufs_attr_open(inode, file, __get, __set, __fmt);       \
 }                                                                      \
-static struct file_operations __fops = {                               \
+static const struct file_operations __fops = {                         \
        .owner   = THIS_MODULE,                                         \
        .open    = __fops ## _open,                                     \
        .release = spufs_attr_release,                                  \
@@ -273,12 +274,10 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
                return VM_FAULT_NOPAGE;
 
        if (ctx->state == SPU_STATE_SAVED) {
-               vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
-                                                       & ~_PAGE_NO_CACHE);
+               vma->vm_page_prot = pgprot_cached(vma->vm_page_prot);
                pfn = vmalloc_to_pfn(ctx->csa.lscsa->ls + offset);
        } else {
-               vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
-                                            | _PAGE_NO_CACHE);
+               vma->vm_page_prot = pgprot_noncached_wc(vma->vm_page_prot);
                pfn = (ctx->spu->local_store_phys + offset) >> PAGE_SHIFT;
        }
        vm_insert_pfn(vma, address, pfn);
@@ -311,7 +310,7 @@ static int spufs_mem_mmap_access(struct vm_area_struct *vma,
        return len;
 }
 
-static struct vm_operations_struct spufs_mem_mmap_vmops = {
+static const struct vm_operations_struct spufs_mem_mmap_vmops = {
        .fault = spufs_mem_mmap_fault,
        .access = spufs_mem_mmap_access,
 };
@@ -338,8 +337,7 @@ static int spufs_mem_mmap(struct file *file, struct vm_area_struct *vma)
                return -EINVAL;
 
        vma->vm_flags |= VM_IO | VM_PFNMAP;
-       vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
-                                    | _PAGE_NO_CACHE);
+       vma->vm_page_prot = pgprot_noncached_wc(vma->vm_page_prot);
 
        vma->vm_ops = &spufs_mem_mmap_vmops;
        return 0;
@@ -390,6 +388,9 @@ static int spufs_ps_fault(struct vm_area_struct *vma,
        if (offset >= ps_size)
                return VM_FAULT_SIGBUS;
 
+       if (fatal_signal_pending(current))
+               return VM_FAULT_SIGBUS;
+
        /*
         * Because we release the mmap_sem, the context may be destroyed while
         * we're in spu_wait. Grab an extra reference so it isn't destroyed
@@ -436,7 +437,7 @@ static int spufs_cntl_mmap_fault(struct vm_area_struct *vma,
        return spufs_ps_fault(vma, vmf, 0x4000, SPUFS_CNTL_MAP_SIZE);
 }
 
-static struct vm_operations_struct spufs_cntl_mmap_vmops = {
+static const struct vm_operations_struct spufs_cntl_mmap_vmops = {
        .fault = spufs_cntl_mmap_fault,
 };
 
@@ -449,8 +450,7 @@ static int spufs_cntl_mmap(struct file *file, struct vm_area_struct *vma)
                return -EINVAL;
 
        vma->vm_flags |= VM_IO | VM_PFNMAP;
-       vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
-                                    | _PAGE_NO_CACHE | _PAGE_GUARDED);
+       vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
        vma->vm_ops = &spufs_cntl_mmap_vmops;
        return 0;
@@ -569,16 +569,17 @@ spufs_regs_write(struct file *file, const char __user *buffer,
        struct spu_lscsa *lscsa = ctx->csa.lscsa;
        int ret;
 
-       size = min_t(ssize_t, sizeof lscsa->gprs - *pos, size);
-       if (size <= 0)
+       if (*pos >= sizeof(lscsa->gprs))
                return -EFBIG;
+
+       size = min_t(ssize_t, sizeof(lscsa->gprs) - *pos, size);
        *pos += size;
 
        ret = spu_acquire_saved(ctx);
        if (ret)
                return ret;
 
-       ret = copy_from_user(lscsa->gprs + *pos - size,
+       ret = copy_from_user((char *)lscsa->gprs + *pos - size,
                             buffer, size) ? -EFAULT : size;
 
        spu_release_saved(ctx);
@@ -624,10 +625,11 @@ spufs_fpcr_write(struct file *file, const char __user * buffer,
        struct spu_lscsa *lscsa = ctx->csa.lscsa;
        int ret;
 
-       size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
-       if (size <= 0)
+       if (*pos >= sizeof(lscsa->fpcr))
                return -EFBIG;
 
+       size = min_t(ssize_t, sizeof(lscsa->fpcr) - *pos, size);
+
        ret = spu_acquire_saved(ctx);
        if (ret)
                return ret;
@@ -1142,7 +1144,7 @@ spufs_signal1_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 #endif
 }
 
-static struct vm_operations_struct spufs_signal1_mmap_vmops = {
+static const struct vm_operations_struct spufs_signal1_mmap_vmops = {
        .fault = spufs_signal1_mmap_fault,
 };
 
@@ -1152,8 +1154,7 @@ static int spufs_signal1_mmap(struct file *file, struct vm_area_struct *vma)
                return -EINVAL;
 
        vma->vm_flags |= VM_IO | VM_PFNMAP;
-       vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
-                                    | _PAGE_NO_CACHE | _PAGE_GUARDED);
+       vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
        vma->vm_ops = &spufs_signal1_mmap_vmops;
        return 0;
@@ -1279,7 +1280,7 @@ spufs_signal2_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
 #endif
 }
 
-static struct vm_operations_struct spufs_signal2_mmap_vmops = {
+static const struct vm_operations_struct spufs_signal2_mmap_vmops = {
        .fault = spufs_signal2_mmap_fault,
 };
 
@@ -1289,8 +1290,7 @@ static int spufs_signal2_mmap(struct file *file, struct vm_area_struct *vma)
                return -EINVAL;
 
        vma->vm_flags |= VM_IO | VM_PFNMAP;
-       vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
-                                    | _PAGE_NO_CACHE | _PAGE_GUARDED);
+       vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
        vma->vm_ops = &spufs_signal2_mmap_vmops;
        return 0;
@@ -1398,7 +1398,7 @@ spufs_mss_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
        return spufs_ps_fault(vma, vmf, 0x0000, SPUFS_MSS_MAP_SIZE);
 }
 
-static struct vm_operations_struct spufs_mss_mmap_vmops = {
+static const struct vm_operations_struct spufs_mss_mmap_vmops = {
        .fault = spufs_mss_mmap_fault,
 };
 
@@ -1411,8 +1411,7 @@ static int spufs_mss_mmap(struct file *file, struct vm_area_struct *vma)
                return -EINVAL;
 
        vma->vm_flags |= VM_IO | VM_PFNMAP;
-       vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
-                                    | _PAGE_NO_CACHE | _PAGE_GUARDED);
+       vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
        vma->vm_ops = &spufs_mss_mmap_vmops;
        return 0;
@@ -1460,7 +1459,7 @@ spufs_psmap_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
        return spufs_ps_fault(vma, vmf, 0x0000, SPUFS_PS_MAP_SIZE);
 }
 
-static struct vm_operations_struct spufs_psmap_mmap_vmops = {
+static const struct vm_operations_struct spufs_psmap_mmap_vmops = {
        .fault = spufs_psmap_mmap_fault,
 };
 
@@ -1473,8 +1472,7 @@ static int spufs_psmap_mmap(struct file *file, struct vm_area_struct *vma)
                return -EINVAL;
 
        vma->vm_flags |= VM_IO | VM_PFNMAP;
-       vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
-                                    | _PAGE_NO_CACHE | _PAGE_GUARDED);
+       vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
        vma->vm_ops = &spufs_psmap_mmap_vmops;
        return 0;
@@ -1520,7 +1518,7 @@ spufs_mfc_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
        return spufs_ps_fault(vma, vmf, 0x3000, SPUFS_MFC_MAP_SIZE);
 }
 
-static struct vm_operations_struct spufs_mfc_mmap_vmops = {
+static const struct vm_operations_struct spufs_mfc_mmap_vmops = {
        .fault = spufs_mfc_mmap_fault,
 };
 
@@ -1533,8 +1531,7 @@ static int spufs_mfc_mmap(struct file *file, struct vm_area_struct *vma)
                return -EINVAL;
 
        vma->vm_flags |= VM_IO | VM_PFNMAP;
-       vma->vm_page_prot = __pgprot(pgprot_val(vma->vm_page_prot)
-                                    | _PAGE_NO_CACHE | _PAGE_GUARDED);
+       vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot);
 
        vma->vm_ops = &spufs_mfc_mmap_vmops;
        return 0;
@@ -1660,7 +1657,7 @@ out:
 
 static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
 {
-       pr_debug("queueing DMA %x %lx %x %x %x\n", cmd->lsa,
+       pr_debug("queueing DMA %x %llx %x %x %x\n", cmd->lsa,
                 cmd->ea, cmd->size, cmd->tag, cmd->cmd);
 
        switch (cmd->cmd) {
@@ -1677,7 +1674,7 @@ static int spufs_check_valid_dma(struct mfc_dma_command *cmd)
        }
 
        if ((cmd->lsa & 0xf) != (cmd->ea &0xf)) {
-               pr_debug("invalid DMA alignment, ea %lx lsa %x\n",
+               pr_debug("invalid DMA alignment, ea %llx lsa %x\n",
                                cmd->ea, cmd->lsa);
                return -EIO;
        }
@@ -2442,7 +2439,7 @@ static int spufs_switch_log_open(struct inode *inode, struct file *file)
                goto out;
        }
 
-       ctx->switch_log = kzalloc(sizeof(struct switch_log) +
+       ctx->switch_log = kmalloc(sizeof(struct switch_log) +
                SWITCH_LOG_BUFSIZE * sizeof(struct switch_log_entry),
                GFP_KERNEL);
 
@@ -2451,6 +2448,7 @@ static int spufs_switch_log_open(struct inode *inode, struct file *file)
                goto out;
        }
 
+       ctx->switch_log->head = ctx->switch_log->tail = 0;
        init_waitqueue_head(&ctx->switch_log->wait);
        rc = 0;
 
@@ -2497,7 +2495,7 @@ static ssize_t spufs_switch_log_read(struct file *file, char __user *buf,
        struct spu_context *ctx = SPUFS_I(inode)->i_ctx;
        int error = 0, cnt = 0;
 
-       if (!buf || len < 0)
+       if (!buf)
                return -EINVAL;
 
        error = spu_acquire(ctx);
@@ -2638,7 +2636,7 @@ static int spufs_show_ctx(struct seq_file *s, void *private)
        }
 
        seq_printf(s, "%c flgs(%lx) sflgs(%lx) pri(%d) ts(%d) spu(%02d)"
-               " %c %lx %lx %lx %lx %x %x\n",
+               " %c %llx %llx %llx %llx %x %x\n",
                ctx->state == SPU_STATE_SAVED ? 'S' : 'R',
                ctx->flags,
                ctx->sched_flags,
@@ -2670,7 +2668,7 @@ static const struct file_operations spufs_ctx_fops = {
        .release        = single_release,
 };
 
-struct spufs_tree_descr spufs_dir_contents[] = {
+const struct spufs_tree_descr spufs_dir_contents[] = {
        { "capabilities", &spufs_caps_fops, 0444, },
        { "mem",  &spufs_mem_fops,  0666, LS_SIZE, },
        { "regs", &spufs_regs_fops,  0666, sizeof(struct spu_reg128[128]), },
@@ -2711,7 +2709,7 @@ struct spufs_tree_descr spufs_dir_contents[] = {
        {},
 };
 
-struct spufs_tree_descr spufs_dir_nosched_contents[] = {
+const struct spufs_tree_descr spufs_dir_nosched_contents[] = {
        { "capabilities", &spufs_caps_fops, 0444, },
        { "mem",  &spufs_mem_fops,  0666, LS_SIZE, },
        { "mbox", &spufs_mbox_fops, 0444, },
@@ -2736,12 +2734,12 @@ struct spufs_tree_descr spufs_dir_nosched_contents[] = {
        {},
 };
 
-struct spufs_tree_descr spufs_dir_debug_contents[] = {
+const struct spufs_tree_descr spufs_dir_debug_contents[] = {
        { ".ctx", &spufs_ctx_fops, 0444, },
        {},
 };
 
-struct spufs_coredump_reader spufs_coredump_read[] = {
+const struct spufs_coredump_reader spufs_coredump_read[] = {
        { "regs", __spufs_regs_read, NULL, sizeof(struct spu_reg128[128])},
        { "fpcr", __spufs_fpcr_read, NULL, sizeof(struct spu_reg128) },
        { "lslr", NULL, spufs_lslr_get, 19 },