Subject: spufs: Add a "capabilities" file to spu contexts From: Benjamin Herrenschmidt This adds a "capabilities" file to spu contexts consisting of a list of space separated capability names. The current exposed capabilities are "sched" (the context is scheduleable) and "step" (the context supports single stepping). Signed-off-by: Benjamin Herrenschmidt Signed-off-by: Arnd Bergmann --- --- arch/powerpc/platforms/cell/spufs/file.c | 32 +++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) Index: linux-2.6/arch/powerpc/platforms/cell/spufs/file.c =================================================================== --- linux-2.6.orig/arch/powerpc/platforms/cell/spufs/file.c +++ linux-2.6/arch/powerpc/platforms/cell/spufs/file.c @@ -40,6 +40,7 @@ #define SPUFS_MMAP_4K (PAGE_SIZE == 0x1000) + static int spufs_mem_open(struct inode *inode, struct file *file) { @@ -1798,6 +1799,35 @@ static int spufs_info_open(struct inode return 0; } +#define CAPS_BUF_LEN 64 +#define ADD_ONE_CAP(name) \ + do { p += snprintf(p, CAPS_BUF_LEN - 3 - (p - buffer), "%s ", #name); \ + } while(0) + +static ssize_t spufs_caps_read(struct file *file, char __user *buf, + size_t len, loff_t *pos) +{ + struct spu_context *ctx = file->private_data; + char buffer[CAPS_BUF_LEN]; + char *p = buffer; + + if (!(ctx->flags & SPU_CREATE_NOSCHED)) + ADD_ONE_CAP(sched); + if (!(ctx->flags & SPU_CREATE_ISOLATE)) + ADD_ONE_CAP(step); + + /* remove last space and add newline */ + if (p != buffer) + p--; + *(p++) = '\n'; + return simple_read_from_buffer(buf, len, pos, buffer, p - buffer); +} + +static const struct file_operations spufs_caps_fops = { + .open = spufs_info_open, + .read = spufs_caps_read, +}; + static ssize_t __spufs_mbox_info_read(struct spu_context *ctx, char __user *buf, size_t len, loff_t *pos) { @@ -2036,6 +2066,7 @@ static const struct file_operations spuf }; struct tree_descr spufs_dir_contents[] = { + { "capabilities", &spufs_caps_fops, 0444, }, { "mem", &spufs_mem_fops, 0666, }, { "regs", &spufs_regs_fops, 0666, }, { "mbox", &spufs_mbox_fops, 0444, }, @@ -2072,6 +2103,7 @@ struct tree_descr spufs_dir_contents[] = }; struct tree_descr spufs_dir_nosched_contents[] = { + { "capabilities", &spufs_caps_fops, 0444, }, { "mem", &spufs_mem_fops, 0666, }, { "mbox", &spufs_mbox_fops, 0444, }, { "ibox", &spufs_ibox_fops, 0444, },