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> 26650f8b02SChristoph Hellwig #include <linux/mutex.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> 32b9e3bd77SDwayne Grant McConnell #include <asm/spu_info.h> 3367207b96SArnd Bergmann 3467207b96SArnd Bergmann /* The magic number for our file system */ 3567207b96SArnd Bergmann enum { 3667207b96SArnd Bergmann SPUFS_MAGIC = 0x23c9b64e, 3767207b96SArnd Bergmann }; 3867207b96SArnd Bergmann 398b3d6663SArnd Bergmann struct spu_context_ops; 406263203eSArnd Bergmann struct spu_gang; 416263203eSArnd Bergmann 4226bec673SChristoph Hellwig /* ctx->sched_flags */ 4326bec673SChristoph Hellwig enum { 4426bec673SChristoph Hellwig SPU_SCHED_WAKE = 0, 4526bec673SChristoph Hellwig }; 4626bec673SChristoph Hellwig 4767207b96SArnd Bergmann struct spu_context { 4867207b96SArnd Bergmann struct spu *spu; /* pointer to a physical SPU */ 495473af04SMark Nutter struct spu_state csa; /* SPU context save area. */ 5067207b96SArnd Bergmann spinlock_t mmio_lock; /* protects mmio access */ 516df10a82SMark Nutter struct address_space *local_store; /* local store mapping. */ 526df10a82SMark Nutter struct address_space *mfc; /* 'mfc' area mappings. */ 536df10a82SMark Nutter struct address_space *cntl; /* 'control' area mappings. */ 546df10a82SMark Nutter struct address_space *signal1; /* 'signal1' area mappings. */ 556df10a82SMark Nutter struct address_space *signal2; /* 'signal2' area mappings. */ 5617e0e270SBenjamin Herrenschmidt struct address_space *mss; /* 'mss' area mappings. */ 5717e0e270SBenjamin Herrenschmidt struct address_space *psmap; /* 'psmap' area mappings. */ 5886767277SArnd Bergmann u64 object_id; /* user space pointer for oprofile */ 598b3d6663SArnd Bergmann 608b3d6663SArnd Bergmann enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state; 61650f8b02SChristoph Hellwig struct mutex state_mutex; 625ef8224aSArnd Bergmann struct semaphore run_sema; 638b3d6663SArnd Bergmann 648b3d6663SArnd Bergmann struct mm_struct *owner; 6567207b96SArnd Bergmann 6667207b96SArnd Bergmann struct kref kref; 678b3d6663SArnd Bergmann wait_queue_head_t ibox_wq; 688b3d6663SArnd Bergmann wait_queue_head_t wbox_wq; 695110459fSArnd Bergmann wait_queue_head_t stop_wq; 70a33a7d73SArnd Bergmann wait_queue_head_t mfc_wq; 718b3d6663SArnd Bergmann struct fasync_struct *ibox_fasync; 728b3d6663SArnd Bergmann struct fasync_struct *wbox_fasync; 73a33a7d73SArnd Bergmann struct fasync_struct *mfc_fasync; 74a33a7d73SArnd Bergmann u32 tagwait; 758b3d6663SArnd Bergmann struct spu_context_ops *ops; 762a911f0bSArnd Bergmann struct work_struct reap_work; 779add11daSArnd Bergmann unsigned long flags; 789add11daSArnd Bergmann unsigned long event_return; 796263203eSArnd Bergmann 806263203eSArnd Bergmann struct list_head gang_list; 816263203eSArnd Bergmann struct spu_gang *gang; 828389998aSChristoph Hellwig 838389998aSChristoph Hellwig /* scheduler fields */ 84079cdb61SChristoph Hellwig struct list_head rq; 8526bec673SChristoph Hellwig unsigned long sched_flags; 8652f04fcfSChristoph Hellwig unsigned long rt_priority; 878389998aSChristoph Hellwig int prio; 886263203eSArnd Bergmann }; 896263203eSArnd Bergmann 906263203eSArnd Bergmann struct spu_gang { 916263203eSArnd Bergmann struct list_head list; 926263203eSArnd Bergmann struct mutex mutex; 936263203eSArnd Bergmann struct kref kref; 946263203eSArnd Bergmann int contexts; 9567207b96SArnd Bergmann }; 9667207b96SArnd Bergmann 97a33a7d73SArnd Bergmann struct mfc_dma_command { 98a33a7d73SArnd Bergmann int32_t pad; /* reserved */ 99a33a7d73SArnd Bergmann uint32_t lsa; /* local storage address */ 100a33a7d73SArnd Bergmann uint64_t ea; /* effective address */ 101a33a7d73SArnd Bergmann uint16_t size; /* transfer size */ 102a33a7d73SArnd Bergmann uint16_t tag; /* command tag */ 103a33a7d73SArnd Bergmann uint16_t class; /* class ID */ 104a33a7d73SArnd Bergmann uint16_t cmd; /* command opcode */ 105a33a7d73SArnd Bergmann }; 106a33a7d73SArnd Bergmann 107a33a7d73SArnd Bergmann 1088b3d6663SArnd Bergmann /* SPU context query/set operations. */ 1098b3d6663SArnd Bergmann struct spu_context_ops { 1108b3d6663SArnd Bergmann int (*mbox_read) (struct spu_context * ctx, u32 * data); 1118b3d6663SArnd Bergmann u32(*mbox_stat_read) (struct spu_context * ctx); 1123a843d7cSArnd Bergmann unsigned int (*mbox_stat_poll)(struct spu_context *ctx, 1133a843d7cSArnd Bergmann unsigned int events); 1148b3d6663SArnd Bergmann int (*ibox_read) (struct spu_context * ctx, u32 * data); 1158b3d6663SArnd Bergmann int (*wbox_write) (struct spu_context * ctx, u32 data); 1168b3d6663SArnd Bergmann u32(*signal1_read) (struct spu_context * ctx); 1178b3d6663SArnd Bergmann void (*signal1_write) (struct spu_context * ctx, u32 data); 1188b3d6663SArnd Bergmann u32(*signal2_read) (struct spu_context * ctx); 1198b3d6663SArnd Bergmann void (*signal2_write) (struct spu_context * ctx, u32 data); 1208b3d6663SArnd Bergmann void (*signal1_type_set) (struct spu_context * ctx, u64 val); 1218b3d6663SArnd Bergmann u64(*signal1_type_get) (struct spu_context * ctx); 1228b3d6663SArnd Bergmann void (*signal2_type_set) (struct spu_context * ctx, u64 val); 1238b3d6663SArnd Bergmann u64(*signal2_type_get) (struct spu_context * ctx); 1248b3d6663SArnd Bergmann u32(*npc_read) (struct spu_context * ctx); 1258b3d6663SArnd Bergmann void (*npc_write) (struct spu_context * ctx, u32 data); 1268b3d6663SArnd Bergmann u32(*status_read) (struct spu_context * ctx); 1278b3d6663SArnd Bergmann char*(*get_ls) (struct spu_context * ctx); 1283960c260SJeremy Kerr u32 (*runcntl_read) (struct spu_context * ctx); 1295110459fSArnd Bergmann void (*runcntl_write) (struct spu_context * ctx, u32 data); 130ee2d7340SArnd Bergmann void (*master_start) (struct spu_context * ctx); 131ee2d7340SArnd Bergmann void (*master_stop) (struct spu_context * ctx); 132a33a7d73SArnd Bergmann int (*set_mfc_query)(struct spu_context * ctx, u32 mask, u32 mode); 133a33a7d73SArnd Bergmann u32 (*read_mfc_tagstatus)(struct spu_context * ctx); 134a33a7d73SArnd Bergmann u32 (*get_mfc_free_elements)(struct spu_context *ctx); 135a33a7d73SArnd Bergmann int (*send_mfc_command)(struct spu_context * ctx, 136a33a7d73SArnd Bergmann struct mfc_dma_command * cmd); 137b9e3bd77SDwayne Grant McConnell void (*dma_info_read) (struct spu_context * ctx, 138b9e3bd77SDwayne Grant McConnell struct spu_dma_info * info); 139b9e3bd77SDwayne Grant McConnell void (*proxydma_info_read) (struct spu_context * ctx, 140b9e3bd77SDwayne Grant McConnell struct spu_proxydma_info * info); 1418b3d6663SArnd Bergmann }; 1428b3d6663SArnd Bergmann 1438b3d6663SArnd Bergmann extern struct spu_context_ops spu_hw_ops; 1448b3d6663SArnd Bergmann extern struct spu_context_ops spu_backing_ops; 1458b3d6663SArnd Bergmann 14667207b96SArnd Bergmann struct spufs_inode_info { 14767207b96SArnd Bergmann struct spu_context *i_ctx; 1486263203eSArnd Bergmann struct spu_gang *i_gang; 14967207b96SArnd Bergmann struct inode vfs_inode; 15067207b96SArnd Bergmann }; 15167207b96SArnd Bergmann #define SPUFS_I(inode) \ 15267207b96SArnd Bergmann container_of(inode, struct spufs_inode_info, vfs_inode) 15367207b96SArnd Bergmann 15467207b96SArnd Bergmann extern struct tree_descr spufs_dir_contents[]; 1555737edd1SMark Nutter extern struct tree_descr spufs_dir_nosched_contents[]; 15667207b96SArnd Bergmann 15767207b96SArnd Bergmann /* system call implementation */ 15867207b96SArnd Bergmann long spufs_run_spu(struct file *file, 15967207b96SArnd Bergmann struct spu_context *ctx, u32 *npc, u32 *status); 1606263203eSArnd Bergmann long spufs_create(struct nameidata *nd, 16167207b96SArnd Bergmann unsigned int flags, mode_t mode); 1629c2e08c5SArjan van de Ven extern const struct file_operations spufs_context_fops; 16367207b96SArnd Bergmann 1646263203eSArnd Bergmann /* gang management */ 1656263203eSArnd Bergmann struct spu_gang *alloc_spu_gang(void); 1666263203eSArnd Bergmann struct spu_gang *get_spu_gang(struct spu_gang *gang); 1676263203eSArnd Bergmann int put_spu_gang(struct spu_gang *gang); 1686263203eSArnd Bergmann void spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx); 1696263203eSArnd Bergmann void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx); 1706263203eSArnd Bergmann 17167207b96SArnd Bergmann /* context management */ 1726a0641e5SChristoph Hellwig static inline void spu_acquire(struct spu_context *ctx) 1736a0641e5SChristoph Hellwig { 1746a0641e5SChristoph Hellwig mutex_lock(&ctx->state_mutex); 1756a0641e5SChristoph Hellwig } 1766a0641e5SChristoph Hellwig 1776a0641e5SChristoph Hellwig static inline void spu_release(struct spu_context *ctx) 1786a0641e5SChristoph Hellwig { 1796a0641e5SChristoph Hellwig mutex_unlock(&ctx->state_mutex); 1806a0641e5SChristoph Hellwig } 1816a0641e5SChristoph Hellwig 1826263203eSArnd Bergmann struct spu_context * alloc_spu_context(struct spu_gang *gang); 18367207b96SArnd Bergmann void destroy_spu_context(struct kref *kref); 18467207b96SArnd Bergmann struct spu_context * get_spu_context(struct spu_context *ctx); 18567207b96SArnd Bergmann int put_spu_context(struct spu_context *ctx); 1865110459fSArnd Bergmann void spu_unmap_mappings(struct spu_context *ctx); 18767207b96SArnd Bergmann 1888b3d6663SArnd Bergmann void spu_forget(struct spu_context *ctx); 18926bec673SChristoph Hellwig int spu_acquire_runnable(struct spu_context *ctx, unsigned long flags); 19067207b96SArnd Bergmann void spu_acquire_saved(struct spu_context *ctx); 191099814bbSJeremy Kerr int spu_acquire_exclusive(struct spu_context *ctx); 19226bec673SChristoph Hellwig enum { 19326bec673SChristoph Hellwig SPU_ACTIVATE_NOWAKE = 1, 19426bec673SChristoph Hellwig }; 19526bec673SChristoph Hellwig int spu_activate(struct spu_context *ctx, unsigned long flags); 1968b3d6663SArnd Bergmann void spu_deactivate(struct spu_context *ctx); 1978b3d6663SArnd Bergmann void spu_yield(struct spu_context *ctx); 1988b3d6663SArnd Bergmann int __init spu_sched_init(void); 1998b3d6663SArnd Bergmann void __exit spu_sched_exit(void); 2008b3d6663SArnd Bergmann 201c6730ed4SJeremy Kerr extern char *isolated_loader; 202c6730ed4SJeremy Kerr 203ce8ab854SArnd Bergmann /* 204ce8ab854SArnd Bergmann * spufs_wait 205ce8ab854SArnd Bergmann * Same as wait_event_interruptible(), except that here 206ce8ab854SArnd Bergmann * we need to call spu_release(ctx) before sleeping, and 207ce8ab854SArnd Bergmann * then spu_acquire(ctx) when awoken. 208ce8ab854SArnd Bergmann */ 209ce8ab854SArnd Bergmann 210ce8ab854SArnd Bergmann #define spufs_wait(wq, condition) \ 211ce8ab854SArnd Bergmann ({ \ 212ce8ab854SArnd Bergmann int __ret = 0; \ 213ce8ab854SArnd Bergmann DEFINE_WAIT(__wait); \ 214ce8ab854SArnd Bergmann for (;;) { \ 215ce8ab854SArnd Bergmann prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE); \ 216ce8ab854SArnd Bergmann if (condition) \ 217ce8ab854SArnd Bergmann break; \ 218ce8ab854SArnd Bergmann if (!signal_pending(current)) { \ 219ce8ab854SArnd Bergmann spu_release(ctx); \ 220ce8ab854SArnd Bergmann schedule(); \ 221ce8ab854SArnd Bergmann spu_acquire(ctx); \ 222ce8ab854SArnd Bergmann continue; \ 223ce8ab854SArnd Bergmann } \ 224ce8ab854SArnd Bergmann __ret = -ERESTARTSYS; \ 225ce8ab854SArnd Bergmann break; \ 226ce8ab854SArnd Bergmann } \ 227ce8ab854SArnd Bergmann finish_wait(&(wq), &__wait); \ 228ce8ab854SArnd Bergmann __ret; \ 229ce8ab854SArnd Bergmann }) 230ce8ab854SArnd Bergmann 2318b3d6663SArnd Bergmann size_t spu_wbox_write(struct spu_context *ctx, u32 data); 2328b3d6663SArnd Bergmann size_t spu_ibox_read(struct spu_context *ctx, u32 *data); 2338b3d6663SArnd Bergmann 2348b3d6663SArnd Bergmann /* irq callback funcs. */ 2358b3d6663SArnd Bergmann void spufs_ibox_callback(struct spu *spu); 2368b3d6663SArnd Bergmann void spufs_wbox_callback(struct spu *spu); 2375110459fSArnd Bergmann void spufs_stop_callback(struct spu *spu); 238a33a7d73SArnd Bergmann void spufs_mfc_callback(struct spu *spu); 2399add11daSArnd Bergmann void spufs_dma_callback(struct spu *spu, int type); 2408b3d6663SArnd Bergmann 241bf1ab978SDwayne Grant McConnell extern struct spu_coredump_calls spufs_coredump_calls; 242bf1ab978SDwayne Grant McConnell struct spufs_coredump_reader { 243bf1ab978SDwayne Grant McConnell char *name; 244bf1ab978SDwayne Grant McConnell ssize_t (*read)(struct spu_context *ctx, 245bf1ab978SDwayne Grant McConnell char __user *buffer, size_t size, loff_t *pos); 246bf1ab978SDwayne Grant McConnell u64 (*get)(void *data); 247bf1ab978SDwayne Grant McConnell size_t size; 248bf1ab978SDwayne Grant McConnell }; 249bf1ab978SDwayne Grant McConnell extern struct spufs_coredump_reader spufs_coredump_read[]; 250bf1ab978SDwayne Grant McConnell extern int spufs_coredump_num_notes; 251bf1ab978SDwayne Grant McConnell 25267207b96SArnd Bergmann #endif 253