blob: 2fb6a009911220d46df6db20bffd4bc0c41049bd [file] [log] [blame]
Arnd Bergmann67207b92005-11-15 15:53:48 -05001/*
2 * SPU file system
3 *
4 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
5 *
6 * Author: Arnd Bergmann <arndb@de.ibm.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22#ifndef SPUFS_H
23#define SPUFS_H
24
25#include <linux/kref.h>
26#include <linux/rwsem.h>
27#include <linux/spinlock.h>
28#include <linux/fs.h>
29
30#include <asm/spu.h>
Mark Nutter5473af02005-11-15 15:53:49 -050031#include <asm/spu_csa.h>
Arnd Bergmann67207b92005-11-15 15:53:48 -050032
33/* The magic number for our file system */
34enum {
35 SPUFS_MAGIC = 0x23c9b64e,
36};
37
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050038struct spu_context_ops;
39
Arnd Bergmann8837d922006-01-04 20:31:28 +010040#define SPU_CONTEXT_PREEMPT 0UL
Arnd Bergmann2a911f02005-12-05 22:52:26 -050041
Arnd Bergmann67207b92005-11-15 15:53:48 -050042struct spu_context {
43 struct spu *spu; /* pointer to a physical SPU */
Mark Nutter5473af02005-11-15 15:53:49 -050044 struct spu_state csa; /* SPU context save area. */
Arnd Bergmann67207b92005-11-15 15:53:48 -050045 spinlock_t mmio_lock; /* protects mmio access */
Mark Nutter6df10a82006-03-23 00:00:12 +010046 struct address_space *local_store; /* local store mapping. */
47 struct address_space *mfc; /* 'mfc' area mappings. */
48 struct address_space *cntl; /* 'control' area mappings. */
49 struct address_space *signal1; /* 'signal1' area mappings. */
50 struct address_space *signal2; /* 'signal2' area mappings. */
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050051
52 enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state;
53 struct rw_semaphore state_sema;
Arnd Bergmann5ef82242006-01-04 20:31:24 +010054 struct semaphore run_sema;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050055
56 struct mm_struct *owner;
Arnd Bergmann67207b92005-11-15 15:53:48 -050057
58 struct kref kref;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050059 wait_queue_head_t ibox_wq;
60 wait_queue_head_t wbox_wq;
Arnd Bergmann51104592005-12-05 22:52:25 -050061 wait_queue_head_t stop_wq;
Arnd Bergmanna33a7d72006-03-23 00:00:11 +010062 wait_queue_head_t mfc_wq;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050063 struct fasync_struct *ibox_fasync;
64 struct fasync_struct *wbox_fasync;
Arnd Bergmanna33a7d72006-03-23 00:00:11 +010065 struct fasync_struct *mfc_fasync;
66 u32 tagwait;
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050067 struct spu_context_ops *ops;
Arnd Bergmann2a911f02005-12-05 22:52:26 -050068 struct work_struct reap_work;
Arnd Bergmann9add11d2006-10-04 17:26:14 +020069 unsigned long flags;
70 unsigned long event_return;
Arnd Bergmann67207b92005-11-15 15:53:48 -050071};
72
Arnd Bergmanna33a7d72006-03-23 00:00:11 +010073struct mfc_dma_command {
74 int32_t pad; /* reserved */
75 uint32_t lsa; /* local storage address */
76 uint64_t ea; /* effective address */
77 uint16_t size; /* transfer size */
78 uint16_t tag; /* command tag */
79 uint16_t class; /* class ID */
80 uint16_t cmd; /* command opcode */
81};
82
83
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050084/* SPU context query/set operations. */
85struct spu_context_ops {
86 int (*mbox_read) (struct spu_context * ctx, u32 * data);
87 u32(*mbox_stat_read) (struct spu_context * ctx);
Arnd Bergmann3a843d72005-12-05 22:52:27 -050088 unsigned int (*mbox_stat_poll)(struct spu_context *ctx,
89 unsigned int events);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -050090 int (*ibox_read) (struct spu_context * ctx, u32 * data);
91 int (*wbox_write) (struct spu_context * ctx, u32 data);
92 u32(*signal1_read) (struct spu_context * ctx);
93 void (*signal1_write) (struct spu_context * ctx, u32 data);
94 u32(*signal2_read) (struct spu_context * ctx);
95 void (*signal2_write) (struct spu_context * ctx, u32 data);
96 void (*signal1_type_set) (struct spu_context * ctx, u64 val);
97 u64(*signal1_type_get) (struct spu_context * ctx);
98 void (*signal2_type_set) (struct spu_context * ctx, u64 val);
99 u64(*signal2_type_get) (struct spu_context * ctx);
100 u32(*npc_read) (struct spu_context * ctx);
101 void (*npc_write) (struct spu_context * ctx, u32 data);
102 u32(*status_read) (struct spu_context * ctx);
103 char*(*get_ls) (struct spu_context * ctx);
Arnd Bergmann51104592005-12-05 22:52:25 -0500104 void (*runcntl_write) (struct spu_context * ctx, u32 data);
105 void (*runcntl_stop) (struct spu_context * ctx);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +0100106 int (*set_mfc_query)(struct spu_context * ctx, u32 mask, u32 mode);
107 u32 (*read_mfc_tagstatus)(struct spu_context * ctx);
108 u32 (*get_mfc_free_elements)(struct spu_context *ctx);
109 int (*send_mfc_command)(struct spu_context *ctx,
110 struct mfc_dma_command *cmd);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500111};
112
113extern struct spu_context_ops spu_hw_ops;
114extern struct spu_context_ops spu_backing_ops;
115
Arnd Bergmann67207b92005-11-15 15:53:48 -0500116struct spufs_inode_info {
117 struct spu_context *i_ctx;
118 struct inode vfs_inode;
119};
120#define SPUFS_I(inode) \
121 container_of(inode, struct spufs_inode_info, vfs_inode)
122
123extern struct tree_descr spufs_dir_contents[];
124
125/* system call implementation */
126long spufs_run_spu(struct file *file,
127 struct spu_context *ctx, u32 *npc, u32 *status);
Arnd Bergmann6ff730c2006-01-04 20:31:31 +0100128long spufs_create_thread(struct nameidata *nd,
Arnd Bergmann67207b92005-11-15 15:53:48 -0500129 unsigned int flags, mode_t mode);
Arnd Bergmanne80358a2006-01-04 20:31:23 +0100130extern struct file_operations spufs_context_fops;
Arnd Bergmann67207b92005-11-15 15:53:48 -0500131
132/* context management */
Mark Nutter6df10a82006-03-23 00:00:12 +0100133struct spu_context * alloc_spu_context(void);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500134void destroy_spu_context(struct kref *kref);
135struct spu_context * get_spu_context(struct spu_context *ctx);
136int put_spu_context(struct spu_context *ctx);
Arnd Bergmann51104592005-12-05 22:52:25 -0500137void spu_unmap_mappings(struct spu_context *ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500138
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500139void spu_forget(struct spu_context *ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500140void spu_acquire(struct spu_context *ctx);
141void spu_release(struct spu_context *ctx);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500142int spu_acquire_runnable(struct spu_context *ctx);
Arnd Bergmann67207b92005-11-15 15:53:48 -0500143void spu_acquire_saved(struct spu_context *ctx);
144
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500145int spu_activate(struct spu_context *ctx, u64 flags);
146void spu_deactivate(struct spu_context *ctx);
147void spu_yield(struct spu_context *ctx);
148int __init spu_sched_init(void);
149void __exit spu_sched_exit(void);
150
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100151/*
152 * spufs_wait
153 * Same as wait_event_interruptible(), except that here
154 * we need to call spu_release(ctx) before sleeping, and
155 * then spu_acquire(ctx) when awoken.
156 */
157
158#define spufs_wait(wq, condition) \
159({ \
160 int __ret = 0; \
161 DEFINE_WAIT(__wait); \
162 for (;;) { \
163 prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE); \
164 if (condition) \
165 break; \
166 if (!signal_pending(current)) { \
167 spu_release(ctx); \
168 schedule(); \
169 spu_acquire(ctx); \
170 continue; \
171 } \
172 __ret = -ERESTARTSYS; \
173 break; \
174 } \
175 finish_wait(&(wq), &__wait); \
176 __ret; \
177})
178
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500179size_t spu_wbox_write(struct spu_context *ctx, u32 data);
180size_t spu_ibox_read(struct spu_context *ctx, u32 *data);
181
182/* irq callback funcs. */
183void spufs_ibox_callback(struct spu *spu);
184void spufs_wbox_callback(struct spu *spu);
Arnd Bergmann51104592005-12-05 22:52:25 -0500185void spufs_stop_callback(struct spu *spu);
Arnd Bergmanna33a7d72006-03-23 00:00:11 +0100186void spufs_mfc_callback(struct spu *spu);
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200187void spufs_dma_callback(struct spu *spu, int type);
Arnd Bergmann8b3d6662005-11-15 15:53:52 -0500188
Arnd Bergmann67207b92005-11-15 15:53:48 -0500189#endif