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> 29ea1ae594SChristoph Hellwig #include <linux/cpumask.h> 3067207b96SArnd Bergmann 3167207b96SArnd Bergmann #include <asm/spu.h> 325473af04SMark Nutter #include <asm/spu_csa.h> 33b9e3bd77SDwayne Grant McConnell #include <asm/spu_info.h> 3467207b96SArnd Bergmann 3567207b96SArnd Bergmann /* The magic number for our file system */ 3667207b96SArnd Bergmann enum { 3767207b96SArnd Bergmann SPUFS_MAGIC = 0x23c9b64e, 3867207b96SArnd Bergmann }; 3967207b96SArnd Bergmann 408b3d6663SArnd Bergmann struct spu_context_ops; 416263203eSArnd Bergmann struct spu_gang; 426263203eSArnd 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 */ 476df10a82SMark Nutter struct address_space *local_store; /* local store mapping. */ 486df10a82SMark Nutter struct address_space *mfc; /* 'mfc' area mappings. */ 496df10a82SMark Nutter struct address_space *cntl; /* 'control' area mappings. */ 506df10a82SMark Nutter struct address_space *signal1; /* 'signal1' area mappings. */ 516df10a82SMark Nutter struct address_space *signal2; /* 'signal2' area mappings. */ 5217e0e270SBenjamin Herrenschmidt struct address_space *mss; /* 'mss' area mappings. */ 5317e0e270SBenjamin Herrenschmidt struct address_space *psmap; /* 'psmap' area mappings. */ 5447d3a5faSChristoph Hellwig struct mutex mapping_lock; 5586767277SArnd Bergmann u64 object_id; /* user space pointer for oprofile */ 568b3d6663SArnd Bergmann 578b3d6663SArnd Bergmann enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state; 58650f8b02SChristoph Hellwig struct mutex state_mutex; 59e45d48a3SChristoph Hellwig struct mutex run_mutex; 608b3d6663SArnd Bergmann 618b3d6663SArnd Bergmann struct mm_struct *owner; 6267207b96SArnd Bergmann 6367207b96SArnd Bergmann struct kref kref; 648b3d6663SArnd Bergmann wait_queue_head_t ibox_wq; 658b3d6663SArnd Bergmann wait_queue_head_t wbox_wq; 665110459fSArnd Bergmann wait_queue_head_t stop_wq; 67a33a7d73SArnd Bergmann wait_queue_head_t mfc_wq; 688b3d6663SArnd Bergmann struct fasync_struct *ibox_fasync; 698b3d6663SArnd Bergmann struct fasync_struct *wbox_fasync; 70a33a7d73SArnd Bergmann struct fasync_struct *mfc_fasync; 71a33a7d73SArnd Bergmann u32 tagwait; 728b3d6663SArnd Bergmann struct spu_context_ops *ops; 732a911f0bSArnd Bergmann struct work_struct reap_work; 749add11daSArnd Bergmann unsigned long flags; 759add11daSArnd Bergmann unsigned long event_return; 766263203eSArnd Bergmann 776263203eSArnd Bergmann struct list_head gang_list; 786263203eSArnd Bergmann struct spu_gang *gang; 798389998aSChristoph Hellwig 80476273adSChristoph Hellwig /* owner thread */ 81476273adSChristoph Hellwig pid_t tid; 82476273adSChristoph Hellwig 838389998aSChristoph Hellwig /* scheduler fields */ 84079cdb61SChristoph Hellwig struct list_head rq; 8537901802SChristoph Hellwig unsigned int time_slice; 8626bec673SChristoph Hellwig unsigned long sched_flags; 87ea1ae594SChristoph Hellwig cpumask_t cpus_allowed; 882eb1b120SChristoph Hellwig int policy; 898389998aSChristoph Hellwig int prio; 906263203eSArnd Bergmann }; 916263203eSArnd Bergmann 926263203eSArnd Bergmann struct spu_gang { 936263203eSArnd Bergmann struct list_head list; 946263203eSArnd Bergmann struct mutex mutex; 956263203eSArnd Bergmann struct kref kref; 966263203eSArnd Bergmann int contexts; 9767207b96SArnd Bergmann }; 9867207b96SArnd Bergmann 99a33a7d73SArnd Bergmann struct mfc_dma_command { 100a33a7d73SArnd Bergmann int32_t pad; /* reserved */ 101a33a7d73SArnd Bergmann uint32_t lsa; /* local storage address */ 102a33a7d73SArnd Bergmann uint64_t ea; /* effective address */ 103a33a7d73SArnd Bergmann uint16_t size; /* transfer size */ 104a33a7d73SArnd Bergmann uint16_t tag; /* command tag */ 105a33a7d73SArnd Bergmann uint16_t class; /* class ID */ 106a33a7d73SArnd Bergmann uint16_t cmd; /* command opcode */ 107a33a7d73SArnd Bergmann }; 108a33a7d73SArnd Bergmann 109a33a7d73SArnd Bergmann 1108b3d6663SArnd Bergmann /* SPU context query/set operations. */ 1118b3d6663SArnd Bergmann struct spu_context_ops { 1128b3d6663SArnd Bergmann int (*mbox_read) (struct spu_context * ctx, u32 * data); 1138b3d6663SArnd Bergmann u32(*mbox_stat_read) (struct spu_context * ctx); 1143a843d7cSArnd Bergmann unsigned int (*mbox_stat_poll)(struct spu_context *ctx, 1153a843d7cSArnd Bergmann unsigned int events); 1168b3d6663SArnd Bergmann int (*ibox_read) (struct spu_context * ctx, u32 * data); 1178b3d6663SArnd Bergmann int (*wbox_write) (struct spu_context * ctx, u32 data); 1188b3d6663SArnd Bergmann u32(*signal1_read) (struct spu_context * ctx); 1198b3d6663SArnd Bergmann void (*signal1_write) (struct spu_context * ctx, u32 data); 1208b3d6663SArnd Bergmann u32(*signal2_read) (struct spu_context * ctx); 1218b3d6663SArnd Bergmann void (*signal2_write) (struct spu_context * ctx, u32 data); 1228b3d6663SArnd Bergmann void (*signal1_type_set) (struct spu_context * ctx, u64 val); 1238b3d6663SArnd Bergmann u64(*signal1_type_get) (struct spu_context * ctx); 1248b3d6663SArnd Bergmann void (*signal2_type_set) (struct spu_context * ctx, u64 val); 1258b3d6663SArnd Bergmann u64(*signal2_type_get) (struct spu_context * ctx); 1268b3d6663SArnd Bergmann u32(*npc_read) (struct spu_context * ctx); 1278b3d6663SArnd Bergmann void (*npc_write) (struct spu_context * ctx, u32 data); 1288b3d6663SArnd Bergmann u32(*status_read) (struct spu_context * ctx); 1298b3d6663SArnd Bergmann char*(*get_ls) (struct spu_context * ctx); 1303960c260SJeremy Kerr u32 (*runcntl_read) (struct spu_context * ctx); 1315110459fSArnd Bergmann void (*runcntl_write) (struct spu_context * ctx, u32 data); 132ee2d7340SArnd Bergmann void (*master_start) (struct spu_context * ctx); 133ee2d7340SArnd Bergmann void (*master_stop) (struct spu_context * ctx); 134a33a7d73SArnd Bergmann int (*set_mfc_query)(struct spu_context * ctx, u32 mask, u32 mode); 135a33a7d73SArnd Bergmann u32 (*read_mfc_tagstatus)(struct spu_context * ctx); 136a33a7d73SArnd Bergmann u32 (*get_mfc_free_elements)(struct spu_context *ctx); 137a33a7d73SArnd Bergmann int (*send_mfc_command)(struct spu_context * ctx, 138a33a7d73SArnd Bergmann struct mfc_dma_command * cmd); 139b9e3bd77SDwayne Grant McConnell void (*dma_info_read) (struct spu_context * ctx, 140b9e3bd77SDwayne Grant McConnell struct spu_dma_info * info); 141b9e3bd77SDwayne Grant McConnell void (*proxydma_info_read) (struct spu_context * ctx, 142b9e3bd77SDwayne Grant McConnell struct spu_proxydma_info * info); 14357dace23SArnd Bergmann void (*restart_dma)(struct spu_context *ctx); 1448b3d6663SArnd Bergmann }; 1458b3d6663SArnd Bergmann 1468b3d6663SArnd Bergmann extern struct spu_context_ops spu_hw_ops; 1478b3d6663SArnd Bergmann extern struct spu_context_ops spu_backing_ops; 1488b3d6663SArnd Bergmann 14967207b96SArnd Bergmann struct spufs_inode_info { 15067207b96SArnd Bergmann struct spu_context *i_ctx; 1516263203eSArnd Bergmann struct spu_gang *i_gang; 15267207b96SArnd Bergmann struct inode vfs_inode; 15343c2bbd9SChristoph Hellwig int i_openers; 15467207b96SArnd Bergmann }; 15567207b96SArnd Bergmann #define SPUFS_I(inode) \ 15667207b96SArnd Bergmann container_of(inode, struct spufs_inode_info, vfs_inode) 15767207b96SArnd Bergmann 15867207b96SArnd Bergmann extern struct tree_descr spufs_dir_contents[]; 1595737edd1SMark Nutter extern struct tree_descr spufs_dir_nosched_contents[]; 16067207b96SArnd Bergmann 16167207b96SArnd Bergmann /* system call implementation */ 16267207b96SArnd Bergmann long spufs_run_spu(struct file *file, 16367207b96SArnd Bergmann struct spu_context *ctx, u32 *npc, u32 *status); 1646263203eSArnd Bergmann long spufs_create(struct nameidata *nd, 16567207b96SArnd Bergmann unsigned int flags, mode_t mode); 1669c2e08c5SArjan van de Ven extern const struct file_operations spufs_context_fops; 16767207b96SArnd Bergmann 1686263203eSArnd Bergmann /* gang management */ 1696263203eSArnd Bergmann struct spu_gang *alloc_spu_gang(void); 1706263203eSArnd Bergmann struct spu_gang *get_spu_gang(struct spu_gang *gang); 1716263203eSArnd Bergmann int put_spu_gang(struct spu_gang *gang); 1726263203eSArnd Bergmann void spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx); 1736263203eSArnd Bergmann void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx); 1746263203eSArnd Bergmann 17557dace23SArnd Bergmann /* fault handling */ 17657dace23SArnd Bergmann int spufs_handle_class1(struct spu_context *ctx); 17757dace23SArnd Bergmann 17867207b96SArnd Bergmann /* context management */ 1796a0641e5SChristoph Hellwig static inline void spu_acquire(struct spu_context *ctx) 1806a0641e5SChristoph Hellwig { 1816a0641e5SChristoph Hellwig mutex_lock(&ctx->state_mutex); 1826a0641e5SChristoph Hellwig } 1836a0641e5SChristoph Hellwig 1846a0641e5SChristoph Hellwig static inline void spu_release(struct spu_context *ctx) 1856a0641e5SChristoph Hellwig { 1866a0641e5SChristoph Hellwig mutex_unlock(&ctx->state_mutex); 1876a0641e5SChristoph Hellwig } 1886a0641e5SChristoph Hellwig 1896263203eSArnd Bergmann struct spu_context * alloc_spu_context(struct spu_gang *gang); 19067207b96SArnd Bergmann void destroy_spu_context(struct kref *kref); 19167207b96SArnd Bergmann struct spu_context * get_spu_context(struct spu_context *ctx); 19267207b96SArnd Bergmann int put_spu_context(struct spu_context *ctx); 1935110459fSArnd Bergmann void spu_unmap_mappings(struct spu_context *ctx); 19467207b96SArnd Bergmann 1958b3d6663SArnd Bergmann void spu_forget(struct spu_context *ctx); 19626bec673SChristoph Hellwig int spu_acquire_runnable(struct spu_context *ctx, unsigned long flags); 19767207b96SArnd Bergmann void spu_acquire_saved(struct spu_context *ctx); 19850b520d4SChristoph Hellwig 19926bec673SChristoph Hellwig int spu_activate(struct spu_context *ctx, unsigned long flags); 2008b3d6663SArnd Bergmann void spu_deactivate(struct spu_context *ctx); 2018b3d6663SArnd Bergmann void spu_yield(struct spu_context *ctx); 202fe443ef2SChristoph Hellwig void spu_set_timeslice(struct spu_context *ctx); 2032cf2b3b4SChristoph Hellwig void spu_update_sched_info(struct spu_context *ctx); 2042cf2b3b4SChristoph Hellwig void __spu_update_sched_info(struct spu_context *ctx); 2058b3d6663SArnd Bergmann int __init spu_sched_init(void); 2068b3d6663SArnd Bergmann void __exit spu_sched_exit(void); 2078b3d6663SArnd Bergmann 208c6730ed4SJeremy Kerr extern char *isolated_loader; 209c6730ed4SJeremy Kerr 210ce8ab854SArnd Bergmann /* 211ce8ab854SArnd Bergmann * spufs_wait 212ce8ab854SArnd Bergmann * Same as wait_event_interruptible(), except that here 213ce8ab854SArnd Bergmann * we need to call spu_release(ctx) before sleeping, and 214ce8ab854SArnd Bergmann * then spu_acquire(ctx) when awoken. 215ce8ab854SArnd Bergmann */ 216ce8ab854SArnd Bergmann 217ce8ab854SArnd Bergmann #define spufs_wait(wq, condition) \ 218ce8ab854SArnd Bergmann ({ \ 219ce8ab854SArnd Bergmann int __ret = 0; \ 220ce8ab854SArnd Bergmann DEFINE_WAIT(__wait); \ 221ce8ab854SArnd Bergmann for (;;) { \ 222ce8ab854SArnd Bergmann prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE); \ 223ce8ab854SArnd Bergmann if (condition) \ 224ce8ab854SArnd Bergmann break; \ 225d3764397SJeremy Kerr if (signal_pending(current)) { \ 226d3764397SJeremy Kerr __ret = -ERESTARTSYS; \ 227d3764397SJeremy Kerr break; \ 228d3764397SJeremy Kerr } \ 229ce8ab854SArnd Bergmann spu_release(ctx); \ 230ce8ab854SArnd Bergmann schedule(); \ 231ce8ab854SArnd Bergmann spu_acquire(ctx); \ 232ce8ab854SArnd Bergmann } \ 233ce8ab854SArnd Bergmann finish_wait(&(wq), &__wait); \ 234ce8ab854SArnd Bergmann __ret; \ 235ce8ab854SArnd Bergmann }) 236ce8ab854SArnd Bergmann 2378b3d6663SArnd Bergmann size_t spu_wbox_write(struct spu_context *ctx, u32 data); 2388b3d6663SArnd Bergmann size_t spu_ibox_read(struct spu_context *ctx, u32 *data); 2398b3d6663SArnd Bergmann 2408b3d6663SArnd Bergmann /* irq callback funcs. */ 2418b3d6663SArnd Bergmann void spufs_ibox_callback(struct spu *spu); 2428b3d6663SArnd Bergmann void spufs_wbox_callback(struct spu *spu); 2435110459fSArnd Bergmann void spufs_stop_callback(struct spu *spu); 244a33a7d73SArnd Bergmann void spufs_mfc_callback(struct spu *spu); 2459add11daSArnd Bergmann void spufs_dma_callback(struct spu *spu, int type); 2468b3d6663SArnd Bergmann 247bf1ab978SDwayne Grant McConnell extern struct spu_coredump_calls spufs_coredump_calls; 248bf1ab978SDwayne Grant McConnell struct spufs_coredump_reader { 249bf1ab978SDwayne Grant McConnell char *name; 250bf1ab978SDwayne Grant McConnell ssize_t (*read)(struct spu_context *ctx, 251bf1ab978SDwayne Grant McConnell char __user *buffer, size_t size, loff_t *pos); 252bf1ab978SDwayne Grant McConnell u64 (*get)(void *data); 253bf1ab978SDwayne Grant McConnell size_t size; 254bf1ab978SDwayne Grant McConnell }; 255bf1ab978SDwayne Grant McConnell extern struct spufs_coredump_reader spufs_coredump_read[]; 256bf1ab978SDwayne Grant McConnell extern int spufs_coredump_num_notes; 257bf1ab978SDwayne Grant McConnell 25867207b96SArnd Bergmann #endif 259