4 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
6 * Author: Arnd Bergmann <arndb@de.ibm.com>
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)
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.
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.
25 #include <linux/kref.h>
26 #include <linux/mutex.h>
27 #include <linux/spinlock.h>
29 #include <linux/cpumask.h>
32 #include <asm/spu_csa.h>
33 #include <asm/spu_info.h>
35 /* The magic number for our file system */
37 SPUFS_MAGIC
= 0x23c9b64e,
40 struct spu_context_ops
;
44 struct spu
*spu
; /* pointer to a physical SPU */
45 struct spu_state csa
; /* SPU context save area. */
46 spinlock_t mmio_lock
; /* protects mmio access */
47 struct address_space
*local_store
; /* local store mapping. */
48 struct address_space
*mfc
; /* 'mfc' area mappings. */
49 struct address_space
*cntl
; /* 'control' area mappings. */
50 struct address_space
*signal1
; /* 'signal1' area mappings. */
51 struct address_space
*signal2
; /* 'signal2' area mappings. */
52 struct address_space
*mss
; /* 'mss' area mappings. */
53 struct address_space
*psmap
; /* 'psmap' area mappings. */
54 struct mutex mapping_lock
;
55 u64 object_id
; /* user space pointer for oprofile */
57 enum { SPU_STATE_RUNNABLE
, SPU_STATE_SAVED
} state
;
58 struct mutex state_mutex
;
59 struct mutex run_mutex
;
61 struct mm_struct
*owner
;
64 wait_queue_head_t ibox_wq
;
65 wait_queue_head_t wbox_wq
;
66 wait_queue_head_t stop_wq
;
67 wait_queue_head_t mfc_wq
;
68 struct fasync_struct
*ibox_fasync
;
69 struct fasync_struct
*wbox_fasync
;
70 struct fasync_struct
*mfc_fasync
;
72 struct spu_context_ops
*ops
;
73 struct work_struct reap_work
;
75 unsigned long event_return
;
77 struct list_head gang_list
;
78 struct spu_gang
*gang
;
80 /* scheduler fields */
82 unsigned int time_slice
;
83 unsigned long sched_flags
;
84 cpumask_t cpus_allowed
;
90 struct list_head list
;
96 struct mfc_dma_command
{
97 int32_t pad
; /* reserved */
98 uint32_t lsa
; /* local storage address */
99 uint64_t ea
; /* effective address */
100 uint16_t size
; /* transfer size */
101 uint16_t tag
; /* command tag */
102 uint16_t class; /* class ID */
103 uint16_t cmd
; /* command opcode */
107 /* SPU context query/set operations. */
108 struct spu_context_ops
{
109 int (*mbox_read
) (struct spu_context
* ctx
, u32
* data
);
110 u32(*mbox_stat_read
) (struct spu_context
* ctx
);
111 unsigned int (*mbox_stat_poll
)(struct spu_context
*ctx
,
112 unsigned int events
);
113 int (*ibox_read
) (struct spu_context
* ctx
, u32
* data
);
114 int (*wbox_write
) (struct spu_context
* ctx
, u32 data
);
115 u32(*signal1_read
) (struct spu_context
* ctx
);
116 void (*signal1_write
) (struct spu_context
* ctx
, u32 data
);
117 u32(*signal2_read
) (struct spu_context
* ctx
);
118 void (*signal2_write
) (struct spu_context
* ctx
, u32 data
);
119 void (*signal1_type_set
) (struct spu_context
* ctx
, u64 val
);
120 u64(*signal1_type_get
) (struct spu_context
* ctx
);
121 void (*signal2_type_set
) (struct spu_context
* ctx
, u64 val
);
122 u64(*signal2_type_get
) (struct spu_context
* ctx
);
123 u32(*npc_read
) (struct spu_context
* ctx
);
124 void (*npc_write
) (struct spu_context
* ctx
, u32 data
);
125 u32(*status_read
) (struct spu_context
* ctx
);
126 char*(*get_ls
) (struct spu_context
* ctx
);
127 u32 (*runcntl_read
) (struct spu_context
* ctx
);
128 void (*runcntl_write
) (struct spu_context
* ctx
, u32 data
);
129 void (*master_start
) (struct spu_context
* ctx
);
130 void (*master_stop
) (struct spu_context
* ctx
);
131 int (*set_mfc_query
)(struct spu_context
* ctx
, u32 mask
, u32 mode
);
132 u32 (*read_mfc_tagstatus
)(struct spu_context
* ctx
);
133 u32 (*get_mfc_free_elements
)(struct spu_context
*ctx
);
134 int (*send_mfc_command
)(struct spu_context
* ctx
,
135 struct mfc_dma_command
* cmd
);
136 void (*dma_info_read
) (struct spu_context
* ctx
,
137 struct spu_dma_info
* info
);
138 void (*proxydma_info_read
) (struct spu_context
* ctx
,
139 struct spu_proxydma_info
* info
);
140 void (*restart_dma
)(struct spu_context
*ctx
);
143 extern struct spu_context_ops spu_hw_ops
;
144 extern struct spu_context_ops spu_backing_ops
;
146 struct spufs_inode_info
{
147 struct spu_context
*i_ctx
;
148 struct spu_gang
*i_gang
;
149 struct inode vfs_inode
;
152 #define SPUFS_I(inode) \
153 container_of(inode, struct spufs_inode_info, vfs_inode)
155 extern struct tree_descr spufs_dir_contents
[];
156 extern struct tree_descr spufs_dir_nosched_contents
[];
158 /* system call implementation */
159 long spufs_run_spu(struct file
*file
,
160 struct spu_context
*ctx
, u32
*npc
, u32
*status
);
161 long spufs_create(struct nameidata
*nd
,
162 unsigned int flags
, mode_t mode
);
163 extern const struct file_operations spufs_context_fops
;
165 /* gang management */
166 struct spu_gang
*alloc_spu_gang(void);
167 struct spu_gang
*get_spu_gang(struct spu_gang
*gang
);
168 int put_spu_gang(struct spu_gang
*gang
);
169 void spu_gang_remove_ctx(struct spu_gang
*gang
, struct spu_context
*ctx
);
170 void spu_gang_add_ctx(struct spu_gang
*gang
, struct spu_context
*ctx
);
173 int spufs_handle_class1(struct spu_context
*ctx
);
175 /* context management */
176 static inline void spu_acquire(struct spu_context
*ctx
)
178 mutex_lock(&ctx
->state_mutex
);
181 static inline void spu_release(struct spu_context
*ctx
)
183 mutex_unlock(&ctx
->state_mutex
);
186 struct spu_context
* alloc_spu_context(struct spu_gang
*gang
);
187 void destroy_spu_context(struct kref
*kref
);
188 struct spu_context
* get_spu_context(struct spu_context
*ctx
);
189 int put_spu_context(struct spu_context
*ctx
);
190 void spu_unmap_mappings(struct spu_context
*ctx
);
192 void spu_forget(struct spu_context
*ctx
);
193 int spu_acquire_runnable(struct spu_context
*ctx
, unsigned long flags
);
194 void spu_acquire_saved(struct spu_context
*ctx
);
196 int spu_activate(struct spu_context
*ctx
, unsigned long flags
);
197 void spu_deactivate(struct spu_context
*ctx
);
198 void spu_yield(struct spu_context
*ctx
);
199 void spu_set_timeslice(struct spu_context
*ctx
);
200 void spu_update_sched_info(struct spu_context
*ctx
);
201 void __spu_update_sched_info(struct spu_context
*ctx
);
202 int __init
spu_sched_init(void);
203 void __exit
spu_sched_exit(void);
205 extern char *isolated_loader
;
209 * Same as wait_event_interruptible(), except that here
210 * we need to call spu_release(ctx) before sleeping, and
211 * then spu_acquire(ctx) when awoken.
214 #define spufs_wait(wq, condition) \
217 DEFINE_WAIT(__wait); \
219 prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE); \
222 if (signal_pending(current)) { \
223 __ret = -ERESTARTSYS; \
230 finish_wait(&(wq), &__wait); \
234 size_t spu_wbox_write(struct spu_context
*ctx
, u32 data
);
235 size_t spu_ibox_read(struct spu_context
*ctx
, u32
*data
);
237 /* irq callback funcs. */
238 void spufs_ibox_callback(struct spu
*spu
);
239 void spufs_wbox_callback(struct spu
*spu
);
240 void spufs_stop_callback(struct spu
*spu
);
241 void spufs_mfc_callback(struct spu
*spu
);
242 void spufs_dma_callback(struct spu
*spu
, int type
);
244 extern struct spu_coredump_calls spufs_coredump_calls
;
245 struct spufs_coredump_reader
{
247 ssize_t (*read
)(struct spu_context
*ctx
,
248 char __user
*buffer
, size_t size
, loff_t
*pos
);
249 u64 (*get
)(void *data
);
252 extern struct spufs_coredump_reader spufs_coredump_read
[];
253 extern int spufs_coredump_num_notes
;