--- /dev/null
+/*
+ * SPU core dump code
+ *
+ * (C) Copyright 2006 IBM Corp.
+ *
+ * Author: Dwayne Grant McConnell <decimal@us.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.        See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/elf.h>
+#include <linux/file.h>
+#include <linux/fs.h>
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/syscalls.h>
+
+#include <asm/uaccess.h>
+
+#include "spufs.h"
+
+struct spufs_ctx_info {
+       struct list_head list;
+       int dfd;
+       int memsize; /* in bytes */
+       struct spu_context *ctx;
+};
+
+static LIST_HEAD(ctx_info_list);
+
+static ssize_t do_coredump_read(int num, struct spu_context *ctx, void __user *buffer,
+                               size_t size, loff_t *off)
+{
+       u64 data;
+       int ret;
+
+       if (spufs_coredump_read[num].read)
+               return spufs_coredump_read[num].read(ctx, buffer, size, off);
+
+       data = spufs_coredump_read[num].get(ctx);
+       ret = copy_to_user(buffer, &data, 8);
+       return ret ? -EFAULT : 8;
+}
+
+/*
+ * These are the only things you should do on a core-file: use only these
+ * functions to write out all the necessary info.
+ */
+static int spufs_dump_write(struct file *file, const void *addr, int nr)
+{
+       return file->f_op->write(file, addr, nr, &file->f_pos) == nr;
+}
+
+static int spufs_dump_seek(struct file *file, loff_t off)
+{
+       if (file->f_op->llseek) {
+               if (file->f_op->llseek(file, off, 0) != off)
+                       return 0;
+       } else
+               file->f_pos = off;
+       return 1;
+}
+
+static void spufs_fill_memsize(struct spufs_ctx_info *ctx_info)
+{
+       struct spu_context *ctx;
+       unsigned long long lslr;
+
+       ctx = ctx_info->ctx;
+       lslr = ctx->csa.priv2.spu_lslr_RW;
+       ctx_info->memsize = lslr + 1;
+}
+
+static int spufs_ctx_note_size(struct spufs_ctx_info *ctx_info)
+{
+       int dfd, memsize, i, sz, total = 0;
+       char *name;
+       char fullname[80];
+
+       dfd = ctx_info->dfd;
+       memsize = ctx_info->memsize;
+
+       for (i = 0; spufs_coredump_read[i].name; i++) {
+               name = spufs_coredump_read[i].name;
+               sz = spufs_coredump_read[i].size;
+
+               sprintf(fullname, "SPU/%d/%s", dfd, name);
+
+               total += sizeof(struct elf_note);
+               total += roundup(strlen(fullname) + 1, 4);
+               if (!strcmp(name, "mem"))
+                       total += roundup(memsize, 4);
+               else
+                       total += roundup(sz, 4);
+       }
+
+       return total;
+}
+
+static int spufs_add_one_context(struct file *file, int dfd)
+{
+       struct spu_context *ctx;
+       struct spufs_ctx_info *ctx_info;
+       int size;
+
+       ctx = SPUFS_I(file->f_dentry->d_inode)->i_ctx;
+       if (ctx->flags & SPU_CREATE_NOSCHED)
+               return 0;
+
+       ctx_info = kzalloc(sizeof(*ctx_info), GFP_KERNEL);
+       if (unlikely(!ctx_info))
+               return -ENOMEM;
+
+       ctx_info->dfd = dfd;
+       ctx_info->ctx = ctx;
+
+       spufs_fill_memsize(ctx_info);
+
+       size = spufs_ctx_note_size(ctx_info);
+       list_add(&ctx_info->list, &ctx_info_list);
+       return size;
+}
+
+/*
+ * The additional architecture-specific notes for Cell are various
+ * context files in the spu context.
+ *
+ * This function iterates over all open file descriptors and sees
+ * if they are a directory in spufs.  In that case we use spufs
+ * internal functionality to dump them without needing to actually
+ * open the files.
+ */
+static int spufs_arch_notes_size(void)
+{
+       struct fdtable *fdt = files_fdtable(current->files);
+       int size = 0, fd;
+
+       for (fd = 0; fd < fdt->max_fdset && fd < fdt->max_fds; fd++) {
+               if (FD_ISSET(fd, fdt->open_fds)) {
+                       struct file *file = fcheck(fd);
+
+                       if (file && file->f_op == &spufs_context_fops) {
+                               int rval = spufs_add_one_context(file, fd);
+                               if (rval < 0)
+                                       break;
+                               size += rval;
+                       }
+               }
+       }
+
+       return size;
+}
+
+static void spufs_arch_write_note(struct spufs_ctx_info *ctx_info, int i,
+                               struct file *file)
+{
+       struct spu_context *ctx;
+       loff_t pos = 0;
+       int sz, dfd, rc, total = 0;
+       const int bufsz = 4096;
+       char *name;
+       char fullname[80], *buf;
+       struct elf_note en;
+
+       buf = kmalloc(bufsz, GFP_KERNEL);
+       if (!buf)
+               return;
+
+       dfd = ctx_info->dfd;
+       name = spufs_coredump_read[i].name;
+
+       if (!strcmp(name, "mem"))
+               sz = ctx_info->memsize;
+       else
+               sz = spufs_coredump_read[i].size;
+
+       ctx = ctx_info->ctx;
+       if (!ctx) {
+               return;
+       }
+
+       sprintf(fullname, "SPU/%d/%s", dfd, name);
+       en.n_namesz = strlen(fullname) + 1;
+       en.n_descsz = sz;
+       en.n_type = NT_SPU;
+
+       if (!spufs_dump_write(file, &en, sizeof(en)))
+               return;
+       if (!spufs_dump_write(file, fullname, en.n_namesz))
+               return;
+       if (!spufs_dump_seek(file, roundup((unsigned long)file->f_pos, 4)))
+               return;
+
+       do {
+               rc = do_coredump_read(i, ctx, buf, bufsz, &pos);
+               if (rc > 0) {
+                       if (!spufs_dump_write(file, buf, rc))
+                               return;
+                       total += rc;
+               }
+       } while (rc == bufsz && total < sz);
+
+       spufs_dump_seek(file, roundup((unsigned long)file->f_pos
+                                               - total + sz, 4));
+}
+
+static void spufs_arch_write_notes(struct file *file)
+{
+       int j;
+       struct spufs_ctx_info *ctx_info, *next;
+
+       list_for_each_entry_safe(ctx_info, next, &ctx_info_list, list) {
+               spu_acquire_saved(ctx_info->ctx);
+               for (j = 0; j < spufs_coredump_num_notes; j++)
+                       spufs_arch_write_note(ctx_info, j, file);
+               spu_release(ctx_info->ctx);
+               list_del(&ctx_info->list);
+               kfree(ctx_info);
+       }
+}
+
+struct spu_coredump_calls spufs_coredump_calls = {
+       .arch_notes_size = spufs_arch_notes_size,
+       .arch_write_notes = spufs_arch_write_notes,
+       .owner = THIS_MODULE,
+};
 
 
 #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000)
 
-
 static int
 spufs_mem_open(struct inode *inode, struct file *file)
 {
        return 0;
 }
 
+static ssize_t
+__spufs_mem_read(struct spu_context *ctx, char __user *buffer,
+                       size_t size, loff_t *pos)
+{
+       char *local_store = ctx->ops->get_ls(ctx);
+       return simple_read_from_buffer(buffer, size, pos, local_store,
+                                       LS_SIZE);
+}
+
 static ssize_t
 spufs_mem_read(struct file *file, char __user *buffer,
                                size_t size, loff_t *pos)
 {
-       struct spu_context *ctx = file->private_data;
-       char *local_store;
        int ret;
+       struct spu_context *ctx = file->private_data;
 
        spu_acquire(ctx);
-
-       local_store = ctx->ops->get_ls(ctx);
-       ret = simple_read_from_buffer(buffer, size, pos, local_store, LS_SIZE);
-
+       ret = __spufs_mem_read(ctx, buffer, size, pos);
        spu_release(ctx);
        return ret;
 }
        return 0;
 }
 
+static ssize_t
+__spufs_regs_read(struct spu_context *ctx, char __user *buffer,
+                       size_t size, loff_t *pos)
+{
+       struct spu_lscsa *lscsa = ctx->csa.lscsa;
+       return simple_read_from_buffer(buffer, size, pos,
+                                     lscsa->gprs, sizeof lscsa->gprs);
+}
+
 static ssize_t
 spufs_regs_read(struct file *file, char __user *buffer,
                size_t size, loff_t *pos)
 {
-       struct spu_context *ctx = file->private_data;
-       struct spu_lscsa *lscsa = ctx->csa.lscsa;
        int ret;
+       struct spu_context *ctx = file->private_data;
 
        spu_acquire_saved(ctx);
-
-       ret = simple_read_from_buffer(buffer, size, pos,
-                                     lscsa->gprs, sizeof lscsa->gprs);
-
+       ret = __spufs_regs_read(ctx, buffer, size, pos);
        spu_release(ctx);
        return ret;
 }
        .llseek  = generic_file_llseek,
 };
 
+static ssize_t
+__spufs_fpcr_read(struct spu_context *ctx, char __user * buffer,
+                       size_t size, loff_t * pos)
+{
+       struct spu_lscsa *lscsa = ctx->csa.lscsa;
+       return simple_read_from_buffer(buffer, size, pos,
+                                     &lscsa->fpcr, sizeof(lscsa->fpcr));
+}
+
 static ssize_t
 spufs_fpcr_read(struct file *file, char __user * buffer,
                size_t size, loff_t * pos)
 {
-       struct spu_context *ctx = file->private_data;
-       struct spu_lscsa *lscsa = ctx->csa.lscsa;
        int ret;
+       struct spu_context *ctx = file->private_data;
 
        spu_acquire_saved(ctx);
-
-       ret = simple_read_from_buffer(buffer, size, pos,
-                                     &lscsa->fpcr, sizeof(lscsa->fpcr));
-
+       ret = __spufs_fpcr_read(ctx, buffer, size, pos);
        spu_release(ctx);
        return ret;
 }
        return nonseekable_open(inode, file);
 }
 
-static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
+static ssize_t __spufs_signal1_read(struct spu_context *ctx, char __user *buf,
                        size_t len, loff_t *pos)
 {
-       struct spu_context *ctx = file->private_data;
        int ret = 0;
        u32 data;
 
        if (len < 4)
                return -EINVAL;
 
-       spu_acquire_saved(ctx);
        if (ctx->csa.spu_chnlcnt_RW[3]) {
                data = ctx->csa.spu_chnldata_RW[3];
                ret = 4;
        }
-       spu_release(ctx);
 
        if (!ret)
                goto out;
        return ret;
 }
 
+static ssize_t spufs_signal1_read(struct file *file, char __user *buf,
+                       size_t len, loff_t *pos)
+{
+       int ret;
+       struct spu_context *ctx = file->private_data;
+
+       spu_acquire_saved(ctx);
+       ret = __spufs_signal1_read(ctx, buf, len, pos);
+       spu_release(ctx);
+
+       return ret;
+}
+
 static ssize_t spufs_signal1_write(struct file *file, const char __user *buf,
                        size_t len, loff_t *pos)
 {
        return nonseekable_open(inode, file);
 }
 
-static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
+static ssize_t __spufs_signal2_read(struct spu_context *ctx, char __user *buf,
                        size_t len, loff_t *pos)
 {
-       struct spu_context *ctx = file->private_data;
        int ret = 0;
        u32 data;
 
        if (len < 4)
                return -EINVAL;
 
-       spu_acquire_saved(ctx);
        if (ctx->csa.spu_chnlcnt_RW[4]) {
                data =  ctx->csa.spu_chnldata_RW[4];
                ret = 4;
        }
-       spu_release(ctx);
 
        if (!ret)
                goto out;
                return -EFAULT;
 
 out:
-       return 4;
+       return ret;
+}
+
+static ssize_t spufs_signal2_read(struct file *file, char __user *buf,
+                       size_t len, loff_t *pos)
+{
+       struct spu_context *ctx = file->private_data;
+       int ret;
+
+       spu_acquire_saved(ctx);
+       ret = __spufs_signal2_read(ctx, buf, len, pos);
+       spu_release(ctx);
+
+       return ret;
 }
 
 static ssize_t spufs_signal2_write(struct file *file, const char __user *buf,
        spu_release(ctx);
 }
 
+static u64 __spufs_signal1_type_get(void *data)
+{
+       struct spu_context *ctx = data;
+       return ctx->ops->signal1_type_get(ctx);
+}
+
 static u64 spufs_signal1_type_get(void *data)
 {
        struct spu_context *ctx = data;
        u64 ret;
 
        spu_acquire(ctx);
-       ret = ctx->ops->signal1_type_get(ctx);
+       ret = __spufs_signal1_type_get(data);
        spu_release(ctx);
 
        return ret;
        spu_release(ctx);
 }
 
+static u64 __spufs_signal2_type_get(void *data)
+{
+       struct spu_context *ctx = data;
+       return ctx->ops->signal2_type_get(ctx);
+}
+
 static u64 spufs_signal2_type_get(void *data)
 {
        struct spu_context *ctx = data;
        u64 ret;
 
        spu_acquire(ctx);
-       ret = ctx->ops->signal2_type_get(ctx);
+       ret = __spufs_signal2_type_get(data);
        spu_release(ctx);
 
        return ret;
        spu_release(ctx);
 }
 
-static u64 spufs_decr_get(void *data)
+static u64 __spufs_decr_get(void *data)
 {
        struct spu_context *ctx = data;
        struct spu_lscsa *lscsa = ctx->csa.lscsa;
+       return lscsa->decr.slot[0];
+}
+
+static u64 spufs_decr_get(void *data)
+{
+       struct spu_context *ctx = data;
        u64 ret;
        spu_acquire_saved(ctx);
-       ret = lscsa->decr.slot[0];
+       ret = __spufs_decr_get(data);
        spu_release(ctx);
        return ret;
 }
        spu_release(ctx);
 }
 
-static u64 spufs_decr_status_get(void *data)
+static u64 __spufs_decr_status_get(void *data)
 {
        struct spu_context *ctx = data;
        struct spu_lscsa *lscsa = ctx->csa.lscsa;
+       return lscsa->decr_status.slot[0];
+}
+
+static u64 spufs_decr_status_get(void *data)
+{
+       struct spu_context *ctx = data;
        u64 ret;
        spu_acquire_saved(ctx);
-       ret = lscsa->decr_status.slot[0];
+       ret = __spufs_decr_status_get(data);
        spu_release(ctx);
        return ret;
 }
        spu_release(ctx);
 }
 
-static u64 spufs_event_mask_get(void *data)
+static u64 __spufs_event_mask_get(void *data)
 {
        struct spu_context *ctx = data;
        struct spu_lscsa *lscsa = ctx->csa.lscsa;
+       return lscsa->event_mask.slot[0];
+}
+
+static u64 spufs_event_mask_get(void *data)
+{
+       struct spu_context *ctx = data;
        u64 ret;
        spu_acquire_saved(ctx);
-       ret = lscsa->event_mask.slot[0];
+       ret = __spufs_event_mask_get(data);
        spu_release(ctx);
        return ret;
 }
 DEFINE_SIMPLE_ATTRIBUTE(spufs_event_mask_ops, spufs_event_mask_get,
                        spufs_event_mask_set, "0x%llx\n")
 
-static u64 spufs_event_status_get(void *data)
+static u64 __spufs_event_status_get(void *data)
 {
        struct spu_context *ctx = data;
        struct spu_state *state = &ctx->csa;
-       u64 ret = 0;
        u64 stat;
-
-       spu_acquire_saved(ctx);
        stat = state->spu_chnlcnt_RW[0];
        if (stat)
-               ret = state->spu_chnldata_RW[0];
+               return state->spu_chnldata_RW[0];
+       return 0;
+}
+
+static u64 spufs_event_status_get(void *data)
+{
+       struct spu_context *ctx = data;
+       u64 ret = 0;
+
+       spu_acquire_saved(ctx);
+       ret = __spufs_event_status_get(data);
        spu_release(ctx);
        return ret;
 }
 }
 DEFINE_SIMPLE_ATTRIBUTE(spufs_id_ops, spufs_id_get, NULL, "0x%llx\n")
 
-static u64 spufs_object_id_get(void *data)
+static u64 __spufs_object_id_get(void *data)
 {
        struct spu_context *ctx = data;
        return ctx->object_id;
 }
 
+static u64 spufs_object_id_get(void *data)
+{
+       /* FIXME: Should there really be no locking here? */
+       return __spufs_object_id_get(data);
+}
+
 static void spufs_object_id_set(void *data, u64 id)
 {
        struct spu_context *ctx = data;
 DEFINE_SIMPLE_ATTRIBUTE(spufs_object_id_ops, spufs_object_id_get,
                spufs_object_id_set, "0x%llx\n");
 
+static u64 __spufs_lslr_get(void *data)
+{
+       struct spu_context *ctx = data;
+       return ctx->csa.priv2.spu_lslr_RW;
+}
+
 static u64 spufs_lslr_get(void *data)
 {
        struct spu_context *ctx = data;
        u64 ret;
 
        spu_acquire_saved(ctx);
-       ret = ctx->csa.priv2.spu_lslr_RW;
+       ret = __spufs_lslr_get(data);
        spu_release(ctx);
 
        return ret;
        return 0;
 }
 
+static ssize_t __spufs_mbox_info_read(struct spu_context *ctx,
+                       char __user *buf, size_t len, loff_t *pos)
+{
+       u32 mbox_stat;
+       u32 data;
+
+       mbox_stat = ctx->csa.prob.mb_stat_R;
+       if (mbox_stat & 0x0000ff) {
+               data = ctx->csa.prob.pu_mb_R;
+       }
+
+       return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
+}
+
 static ssize_t spufs_mbox_info_read(struct file *file, char __user *buf,
                                   size_t len, loff_t *pos)
 {
+       int ret;
        struct spu_context *ctx = file->private_data;
-       u32 mbox_stat;
-       u32 data;
 
        if (!access_ok(VERIFY_WRITE, buf, len))
                return -EFAULT;
 
        spu_acquire_saved(ctx);
        spin_lock(&ctx->csa.register_lock);
-       mbox_stat = ctx->csa.prob.mb_stat_R;
-       if (mbox_stat & 0x0000ff) {
-               data = ctx->csa.prob.pu_mb_R;
-       }
+       ret = __spufs_mbox_info_read(ctx, buf, len, pos);
        spin_unlock(&ctx->csa.register_lock);
        spu_release(ctx);
 
-       return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
+       return ret;
 }
 
 static struct file_operations spufs_mbox_info_fops = {
        .llseek  = generic_file_llseek,
 };
 
+static ssize_t __spufs_ibox_info_read(struct spu_context *ctx,
+                               char __user *buf, size_t len, loff_t *pos)
+{
+       u32 ibox_stat;
+       u32 data;
+
+       ibox_stat = ctx->csa.prob.mb_stat_R;
+       if (ibox_stat & 0xff0000) {
+               data = ctx->csa.priv2.puint_mb_R;
+       }
+
+       return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
+}
+
 static ssize_t spufs_ibox_info_read(struct file *file, char __user *buf,
                                   size_t len, loff_t *pos)
 {
        struct spu_context *ctx = file->private_data;
-       u32 ibox_stat;
-       u32 data;
+       int ret;
 
        if (!access_ok(VERIFY_WRITE, buf, len))
                return -EFAULT;
 
        spu_acquire_saved(ctx);
        spin_lock(&ctx->csa.register_lock);
-       ibox_stat = ctx->csa.prob.mb_stat_R;
-       if (ibox_stat & 0xff0000) {
-               data = ctx->csa.priv2.puint_mb_R;
-       }
+       ret = __spufs_ibox_info_read(ctx, buf, len, pos);
        spin_unlock(&ctx->csa.register_lock);
        spu_release(ctx);
 
-       return simple_read_from_buffer(buf, len, pos, &data, sizeof data);
+       return ret;
 }
 
 static struct file_operations spufs_ibox_info_fops = {
        .llseek  = generic_file_llseek,
 };
 
-static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
-                                  size_t len, loff_t *pos)
+static ssize_t __spufs_wbox_info_read(struct spu_context *ctx,
+                       char __user *buf, size_t len, loff_t *pos)
 {
-       struct spu_context *ctx = file->private_data;
        int i, cnt;
        u32 data[4];
        u32 wbox_stat;
 
+       wbox_stat = ctx->csa.prob.mb_stat_R;
+       cnt = 4 - ((wbox_stat & 0x00ff00) >> 8);
+       for (i = 0; i < cnt; i++) {
+               data[i] = ctx->csa.spu_mailbox_data[i];
+       }
+
+       return simple_read_from_buffer(buf, len, pos, &data,
+                               cnt * sizeof(u32));
+}
+
+static ssize_t spufs_wbox_info_read(struct file *file, char __user *buf,
+                                  size_t len, loff_t *pos)
+{
+       struct spu_context *ctx = file->private_data;
+       int ret;
+
        if (!access_ok(VERIFY_WRITE, buf, len))
                return -EFAULT;
 
        spu_acquire_saved(ctx);
        spin_lock(&ctx->csa.register_lock);
-       wbox_stat = ctx->csa.prob.mb_stat_R;
-       cnt = (wbox_stat & 0x00ff00) >> 8;
-       for (i = 0; i < cnt; i++) {
-               data[i] = ctx->csa.spu_mailbox_data[i];
-       }
+       ret = __spufs_wbox_info_read(ctx, buf, len, pos);
        spin_unlock(&ctx->csa.register_lock);
        spu_release(ctx);
 
-       return simple_read_from_buffer(buf, len, pos, &data,
-                               cnt * sizeof(u32));
+       return ret;
 }
 
 static struct file_operations spufs_wbox_info_fops = {
        .llseek  = generic_file_llseek,
 };
 
-static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
-                             size_t len, loff_t *pos)
+static ssize_t __spufs_dma_info_read(struct spu_context *ctx,
+                       char __user *buf, size_t len, loff_t *pos)
 {
-       struct spu_context *ctx = file->private_data;
        struct spu_dma_info info;
        struct mfc_cq_sr *qp, *spuqp;
        int i;
 
-       if (!access_ok(VERIFY_WRITE, buf, len))
-               return -EFAULT;
-
-       spu_acquire_saved(ctx);
-       spin_lock(&ctx->csa.register_lock);
        info.dma_info_type = ctx->csa.priv2.spu_tag_status_query_RW;
        info.dma_info_mask = ctx->csa.lscsa->tag_mask.slot[0];
        info.dma_info_status = ctx->csa.spu_chnldata_RW[24];
                qp->mfc_cq_data2_RW = spuqp->mfc_cq_data2_RW;
                qp->mfc_cq_data3_RW = spuqp->mfc_cq_data3_RW;
        }
-       spin_unlock(&ctx->csa.register_lock);
-       spu_release(ctx);
 
        return simple_read_from_buffer(buf, len, pos, &info,
                                sizeof info);
 }
 
+static ssize_t spufs_dma_info_read(struct file *file, char __user *buf,
+                             size_t len, loff_t *pos)
+{
+       struct spu_context *ctx = file->private_data;
+       int ret;
+
+       if (!access_ok(VERIFY_WRITE, buf, len))
+               return -EFAULT;
+
+       spu_acquire_saved(ctx);
+       spin_lock(&ctx->csa.register_lock);
+       ret = __spufs_dma_info_read(ctx, buf, len, pos);
+       spin_unlock(&ctx->csa.register_lock);
+       spu_release(ctx);
+
+       return ret;
+}
+
 static struct file_operations spufs_dma_info_fops = {
        .open = spufs_info_open,
        .read = spufs_dma_info_read,
 };
 
-static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
-                                  size_t len, loff_t *pos)
+static ssize_t __spufs_proxydma_info_read(struct spu_context *ctx,
+                       char __user *buf, size_t len, loff_t *pos)
 {
-       struct spu_context *ctx = file->private_data;
        struct spu_proxydma_info info;
-       int ret = sizeof info;
        struct mfc_cq_sr *qp, *puqp;
+       int ret = sizeof info;
        int i;
 
        if (len < ret)
        if (!access_ok(VERIFY_WRITE, buf, len))
                return -EFAULT;
 
-       spu_acquire_saved(ctx);
-       spin_lock(&ctx->csa.register_lock);
        info.proxydma_info_type = ctx->csa.prob.dma_querytype_RW;
        info.proxydma_info_mask = ctx->csa.prob.dma_querymask_RW;
        info.proxydma_info_status = ctx->csa.prob.dma_tagstatus_R;
                qp->mfc_cq_data2_RW = puqp->mfc_cq_data2_RW;
                qp->mfc_cq_data3_RW = puqp->mfc_cq_data3_RW;
        }
+
+       return simple_read_from_buffer(buf, len, pos, &info,
+                               sizeof info);
+}
+
+static ssize_t spufs_proxydma_info_read(struct file *file, char __user *buf,
+                                  size_t len, loff_t *pos)
+{
+       struct spu_context *ctx = file->private_data;
+       int ret;
+
+       spu_acquire_saved(ctx);
+       spin_lock(&ctx->csa.register_lock);
+       ret = __spufs_proxydma_info_read(ctx, buf, len, pos);
        spin_unlock(&ctx->csa.register_lock);
        spu_release(ctx);
 
-       if (copy_to_user(buf, &info, sizeof info))
-               ret = -EFAULT;
-
        return ret;
 }
 
        { "object-id", &spufs_object_id_ops, 0666, },
        {},
 };
+
+struct spufs_coredump_reader spufs_coredump_read[] = {
+       { "regs", __spufs_regs_read, NULL, 128 * 16 },
+       { "fpcr", __spufs_fpcr_read, NULL, 16 },
+       { "lslr", NULL, __spufs_lslr_get, 11 },
+       { "decr", NULL, __spufs_decr_get, 11 },
+       { "decr_status", NULL, __spufs_decr_status_get, 11 },
+       { "mem", __spufs_mem_read, NULL, 256 * 1024, },
+       { "signal1", __spufs_signal1_read, NULL, 4 },
+       { "signal1_type", NULL, __spufs_signal1_type_get, 2 },
+       { "signal2", __spufs_signal2_read, NULL, 4 },
+       { "signal2_type", NULL, __spufs_signal2_type_get, 2 },
+       { "event_mask", NULL, __spufs_event_mask_get, 8 },
+       { "event_status", NULL, __spufs_event_status_get, 8 },
+       { "mbox_info", __spufs_mbox_info_read, NULL, 4 },
+       { "ibox_info", __spufs_ibox_info_read, NULL, 4 },
+       { "wbox_info", __spufs_wbox_info_read, NULL, 16 },
+       { "dma_info", __spufs_dma_info_read, NULL, 69 * 8 },
+       { "proxydma_info", __spufs_proxydma_info_read, NULL, 35 * 8 },
+       { "object-id", NULL, __spufs_object_id_get, 19 },
+       { },
+};
+int spufs_coredump_num_notes = ARRAY_SIZE(spufs_coredump_read) - 1;
+