167207b96SArnd Bergmann /* 267207b96SArnd Bergmann * SPU file system 367207b96SArnd Bergmann * 467207b96SArnd Bergmann * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 567207b96SArnd Bergmann * 667207b96SArnd Bergmann * Author: Arnd Bergmann <arndb@de.ibm.com> 767207b96SArnd Bergmann * 867207b96SArnd Bergmann * This program is free software; you can redistribute it and/or modify 967207b96SArnd Bergmann * it under the terms of the GNU General Public License as published by 1067207b96SArnd Bergmann * the Free Software Foundation; either version 2, or (at your option) 1167207b96SArnd Bergmann * any later version. 1267207b96SArnd Bergmann * 1367207b96SArnd Bergmann * This program is distributed in the hope that it will be useful, 1467207b96SArnd Bergmann * but WITHOUT ANY WARRANTY; without even the implied warranty of 1567207b96SArnd Bergmann * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1667207b96SArnd Bergmann * GNU General Public License for more details. 1767207b96SArnd Bergmann * 1867207b96SArnd Bergmann * You should have received a copy of the GNU General Public License 1967207b96SArnd Bergmann * along with this program; if not, write to the Free Software 2067207b96SArnd Bergmann * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 2167207b96SArnd Bergmann */ 2267207b96SArnd Bergmann #ifndef SPUFS_H 2367207b96SArnd Bergmann #define SPUFS_H 2467207b96SArnd Bergmann 2567207b96SArnd Bergmann #include <linux/kref.h> 2667207b96SArnd Bergmann #include <linux/rwsem.h> 2767207b96SArnd Bergmann #include <linux/spinlock.h> 2867207b96SArnd Bergmann #include <linux/fs.h> 2967207b96SArnd Bergmann 3067207b96SArnd Bergmann #include <asm/spu.h> 315473af04SMark Nutter #include <asm/spu_csa.h> 3267207b96SArnd Bergmann 3367207b96SArnd Bergmann /* The magic number for our file system */ 3467207b96SArnd Bergmann enum { 3567207b96SArnd Bergmann SPUFS_MAGIC = 0x23c9b64e, 3667207b96SArnd Bergmann }; 3767207b96SArnd Bergmann 388b3d6663SArnd Bergmann struct spu_context_ops; 398b3d6663SArnd Bergmann 402a911f0bSArnd Bergmann #define SPU_CONTEXT_PREEMPT_nr 0UL 412a911f0bSArnd Bergmann #define SPU_CONTEXT_PREEMPT (1UL << SPU_CONTEXT_PREEMPT_nr) 422a911f0bSArnd Bergmann 4367207b96SArnd Bergmann struct spu_context { 4467207b96SArnd Bergmann struct spu *spu; /* pointer to a physical SPU */ 455473af04SMark Nutter struct spu_state csa; /* SPU context save area. */ 4667207b96SArnd Bergmann spinlock_t mmio_lock; /* protects mmio access */ 478b3d6663SArnd Bergmann struct address_space *local_store;/* local store backing store */ 488b3d6663SArnd Bergmann 498b3d6663SArnd Bergmann enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state; 508b3d6663SArnd Bergmann struct rw_semaphore state_sema; 518b3d6663SArnd Bergmann 528b3d6663SArnd Bergmann struct mm_struct *owner; 5367207b96SArnd Bergmann 5467207b96SArnd Bergmann struct kref kref; 558b3d6663SArnd Bergmann wait_queue_head_t ibox_wq; 568b3d6663SArnd Bergmann wait_queue_head_t wbox_wq; 575110459fSArnd Bergmann wait_queue_head_t stop_wq; 588b3d6663SArnd Bergmann struct fasync_struct *ibox_fasync; 598b3d6663SArnd Bergmann struct fasync_struct *wbox_fasync; 608b3d6663SArnd Bergmann struct spu_context_ops *ops; 612a911f0bSArnd Bergmann struct work_struct reap_work; 622a911f0bSArnd Bergmann u64 flags; 6367207b96SArnd Bergmann }; 6467207b96SArnd Bergmann 658b3d6663SArnd Bergmann /* SPU context query/set operations. */ 668b3d6663SArnd Bergmann struct spu_context_ops { 678b3d6663SArnd Bergmann int (*mbox_read) (struct spu_context * ctx, u32 * data); 688b3d6663SArnd Bergmann u32(*mbox_stat_read) (struct spu_context * ctx); 693a843d7cSArnd Bergmann unsigned int (*mbox_stat_poll)(struct spu_context *ctx, 703a843d7cSArnd Bergmann unsigned int events); 718b3d6663SArnd Bergmann int (*ibox_read) (struct spu_context * ctx, u32 * data); 728b3d6663SArnd Bergmann int (*wbox_write) (struct spu_context * ctx, u32 data); 738b3d6663SArnd Bergmann u32(*signal1_read) (struct spu_context * ctx); 748b3d6663SArnd Bergmann void (*signal1_write) (struct spu_context * ctx, u32 data); 758b3d6663SArnd Bergmann u32(*signal2_read) (struct spu_context * ctx); 768b3d6663SArnd Bergmann void (*signal2_write) (struct spu_context * ctx, u32 data); 778b3d6663SArnd Bergmann void (*signal1_type_set) (struct spu_context * ctx, u64 val); 788b3d6663SArnd Bergmann u64(*signal1_type_get) (struct spu_context * ctx); 798b3d6663SArnd Bergmann void (*signal2_type_set) (struct spu_context * ctx, u64 val); 808b3d6663SArnd Bergmann u64(*signal2_type_get) (struct spu_context * ctx); 818b3d6663SArnd Bergmann u32(*npc_read) (struct spu_context * ctx); 828b3d6663SArnd Bergmann void (*npc_write) (struct spu_context * ctx, u32 data); 838b3d6663SArnd Bergmann u32(*status_read) (struct spu_context * ctx); 848b3d6663SArnd Bergmann char*(*get_ls) (struct spu_context * ctx); 855110459fSArnd Bergmann void (*runcntl_write) (struct spu_context * ctx, u32 data); 865110459fSArnd Bergmann void (*runcntl_stop) (struct spu_context * ctx); 878b3d6663SArnd Bergmann }; 888b3d6663SArnd Bergmann 898b3d6663SArnd Bergmann extern struct spu_context_ops spu_hw_ops; 908b3d6663SArnd Bergmann extern struct spu_context_ops spu_backing_ops; 918b3d6663SArnd Bergmann 9267207b96SArnd Bergmann struct spufs_inode_info { 9367207b96SArnd Bergmann struct spu_context *i_ctx; 9467207b96SArnd Bergmann struct inode vfs_inode; 9567207b96SArnd Bergmann }; 9667207b96SArnd Bergmann #define SPUFS_I(inode) \ 9767207b96SArnd Bergmann container_of(inode, struct spufs_inode_info, vfs_inode) 9867207b96SArnd Bergmann 9967207b96SArnd Bergmann extern struct tree_descr spufs_dir_contents[]; 10067207b96SArnd Bergmann 10167207b96SArnd Bergmann /* system call implementation */ 10267207b96SArnd Bergmann long spufs_run_spu(struct file *file, 10367207b96SArnd Bergmann struct spu_context *ctx, u32 *npc, u32 *status); 10467207b96SArnd Bergmann long spufs_create_thread(struct nameidata *nd, const char *name, 10567207b96SArnd Bergmann unsigned int flags, mode_t mode); 10667207b96SArnd Bergmann 10767207b96SArnd Bergmann /* context management */ 1088b3d6663SArnd Bergmann struct spu_context * alloc_spu_context(struct address_space *local_store); 10967207b96SArnd Bergmann void destroy_spu_context(struct kref *kref); 11067207b96SArnd Bergmann struct spu_context * get_spu_context(struct spu_context *ctx); 11167207b96SArnd Bergmann int put_spu_context(struct spu_context *ctx); 1125110459fSArnd Bergmann void spu_unmap_mappings(struct spu_context *ctx); 11367207b96SArnd Bergmann 1148b3d6663SArnd Bergmann void spu_forget(struct spu_context *ctx); 11567207b96SArnd Bergmann void spu_acquire(struct spu_context *ctx); 11667207b96SArnd Bergmann void spu_release(struct spu_context *ctx); 1178b3d6663SArnd Bergmann int spu_acquire_runnable(struct spu_context *ctx); 11867207b96SArnd Bergmann void spu_acquire_saved(struct spu_context *ctx); 11967207b96SArnd Bergmann 1208b3d6663SArnd Bergmann int spu_activate(struct spu_context *ctx, u64 flags); 1218b3d6663SArnd Bergmann void spu_deactivate(struct spu_context *ctx); 1228b3d6663SArnd Bergmann void spu_yield(struct spu_context *ctx); 1238b3d6663SArnd Bergmann int __init spu_sched_init(void); 1248b3d6663SArnd Bergmann void __exit spu_sched_exit(void); 1258b3d6663SArnd Bergmann 1268b3d6663SArnd Bergmann size_t spu_wbox_write(struct spu_context *ctx, u32 data); 1278b3d6663SArnd Bergmann size_t spu_ibox_read(struct spu_context *ctx, u32 *data); 1288b3d6663SArnd Bergmann 1298b3d6663SArnd Bergmann /* irq callback funcs. */ 1308b3d6663SArnd Bergmann void spufs_ibox_callback(struct spu *spu); 1318b3d6663SArnd Bergmann void spufs_wbox_callback(struct spu *spu); 1325110459fSArnd Bergmann void spufs_stop_callback(struct spu *spu); 1338b3d6663SArnd Bergmann 13467207b96SArnd Bergmann #endif 135