18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * SPU file system
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * (C) Copyright IBM Deutschland Entwicklung GmbH 2005
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Author: Arnd Bergmann <arndb@de.ibm.com>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci#ifndef SPUFS_H
108c2ecf20Sopenharmony_ci#define SPUFS_H
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include <linux/kref.h>
138c2ecf20Sopenharmony_ci#include <linux/mutex.h>
148c2ecf20Sopenharmony_ci#include <linux/spinlock.h>
158c2ecf20Sopenharmony_ci#include <linux/fs.h>
168c2ecf20Sopenharmony_ci#include <linux/cpumask.h>
178c2ecf20Sopenharmony_ci#include <linux/sched/signal.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <asm/spu.h>
208c2ecf20Sopenharmony_ci#include <asm/spu_csa.h>
218c2ecf20Sopenharmony_ci#include <asm/spu_info.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#define SPUFS_PS_MAP_SIZE	0x20000
248c2ecf20Sopenharmony_ci#define SPUFS_MFC_MAP_SIZE	0x1000
258c2ecf20Sopenharmony_ci#define SPUFS_CNTL_MAP_SIZE	0x1000
268c2ecf20Sopenharmony_ci#define SPUFS_SIGNAL_MAP_SIZE	PAGE_SIZE
278c2ecf20Sopenharmony_ci#define SPUFS_MSS_MAP_SIZE	0x1000
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_ci/* The magic number for our file system */
308c2ecf20Sopenharmony_cienum {
318c2ecf20Sopenharmony_ci	SPUFS_MAGIC = 0x23c9b64e,
328c2ecf20Sopenharmony_ci};
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistruct spu_context_ops;
358c2ecf20Sopenharmony_cistruct spu_gang;
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/* ctx->sched_flags */
388c2ecf20Sopenharmony_cienum {
398c2ecf20Sopenharmony_ci	SPU_SCHED_NOTIFY_ACTIVE,
408c2ecf20Sopenharmony_ci	SPU_SCHED_WAS_ACTIVE,	/* was active upon spu_acquire_saved()  */
418c2ecf20Sopenharmony_ci	SPU_SCHED_SPU_RUN,	/* context is within spu_run */
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_cienum {
458c2ecf20Sopenharmony_ci	SWITCH_LOG_BUFSIZE = 4096,
468c2ecf20Sopenharmony_ci};
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cienum {
498c2ecf20Sopenharmony_ci	SWITCH_LOG_START,
508c2ecf20Sopenharmony_ci	SWITCH_LOG_STOP,
518c2ecf20Sopenharmony_ci	SWITCH_LOG_EXIT,
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistruct switch_log {
558c2ecf20Sopenharmony_ci	wait_queue_head_t	wait;
568c2ecf20Sopenharmony_ci	unsigned long		head;
578c2ecf20Sopenharmony_ci	unsigned long		tail;
588c2ecf20Sopenharmony_ci	struct switch_log_entry {
598c2ecf20Sopenharmony_ci		struct timespec64 tstamp;
608c2ecf20Sopenharmony_ci		s32		spu_id;
618c2ecf20Sopenharmony_ci		u32		type;
628c2ecf20Sopenharmony_ci		u32		val;
638c2ecf20Sopenharmony_ci		u64		timebase;
648c2ecf20Sopenharmony_ci	} log[];
658c2ecf20Sopenharmony_ci};
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_cistruct spu_context {
688c2ecf20Sopenharmony_ci	struct spu *spu;		  /* pointer to a physical SPU */
698c2ecf20Sopenharmony_ci	struct spu_state csa;		  /* SPU context save area. */
708c2ecf20Sopenharmony_ci	spinlock_t mmio_lock;		  /* protects mmio access */
718c2ecf20Sopenharmony_ci	struct address_space *local_store; /* local store mapping.  */
728c2ecf20Sopenharmony_ci	struct address_space *mfc;	   /* 'mfc' area mappings. */
738c2ecf20Sopenharmony_ci	struct address_space *cntl;	   /* 'control' area mappings. */
748c2ecf20Sopenharmony_ci	struct address_space *signal1;	   /* 'signal1' area mappings. */
758c2ecf20Sopenharmony_ci	struct address_space *signal2;	   /* 'signal2' area mappings. */
768c2ecf20Sopenharmony_ci	struct address_space *mss;	   /* 'mss' area mappings. */
778c2ecf20Sopenharmony_ci	struct address_space *psmap;	   /* 'psmap' area mappings. */
788c2ecf20Sopenharmony_ci	struct mutex mapping_lock;
798c2ecf20Sopenharmony_ci	u64 object_id;		   /* user space pointer for oprofile */
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state;
828c2ecf20Sopenharmony_ci	struct mutex state_mutex;
838c2ecf20Sopenharmony_ci	struct mutex run_mutex;
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	struct mm_struct *owner;
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci	struct kref kref;
888c2ecf20Sopenharmony_ci	wait_queue_head_t ibox_wq;
898c2ecf20Sopenharmony_ci	wait_queue_head_t wbox_wq;
908c2ecf20Sopenharmony_ci	wait_queue_head_t stop_wq;
918c2ecf20Sopenharmony_ci	wait_queue_head_t mfc_wq;
928c2ecf20Sopenharmony_ci	wait_queue_head_t run_wq;
938c2ecf20Sopenharmony_ci	u32 tagwait;
948c2ecf20Sopenharmony_ci	struct spu_context_ops *ops;
958c2ecf20Sopenharmony_ci	struct work_struct reap_work;
968c2ecf20Sopenharmony_ci	unsigned long flags;
978c2ecf20Sopenharmony_ci	unsigned long event_return;
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci	struct list_head gang_list;
1008c2ecf20Sopenharmony_ci	struct spu_gang *gang;
1018c2ecf20Sopenharmony_ci	struct kref *prof_priv_kref;
1028c2ecf20Sopenharmony_ci	void ( * prof_priv_release) (struct kref *kref);
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_ci	/* owner thread */
1058c2ecf20Sopenharmony_ci	pid_t tid;
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_ci	/* scheduler fields */
1088c2ecf20Sopenharmony_ci	struct list_head rq;
1098c2ecf20Sopenharmony_ci	unsigned int time_slice;
1108c2ecf20Sopenharmony_ci	unsigned long sched_flags;
1118c2ecf20Sopenharmony_ci	cpumask_t cpus_allowed;
1128c2ecf20Sopenharmony_ci	int policy;
1138c2ecf20Sopenharmony_ci	int prio;
1148c2ecf20Sopenharmony_ci	int last_ran;
1158c2ecf20Sopenharmony_ci
1168c2ecf20Sopenharmony_ci	/* statistics */
1178c2ecf20Sopenharmony_ci	struct {
1188c2ecf20Sopenharmony_ci		/* updates protected by ctx->state_mutex */
1198c2ecf20Sopenharmony_ci		enum spu_utilization_state util_state;
1208c2ecf20Sopenharmony_ci		unsigned long long tstamp;	/* time of last state switch */
1218c2ecf20Sopenharmony_ci		unsigned long long times[SPU_UTIL_MAX];
1228c2ecf20Sopenharmony_ci		unsigned long long vol_ctx_switch;
1238c2ecf20Sopenharmony_ci		unsigned long long invol_ctx_switch;
1248c2ecf20Sopenharmony_ci		unsigned long long min_flt;
1258c2ecf20Sopenharmony_ci		unsigned long long maj_flt;
1268c2ecf20Sopenharmony_ci		unsigned long long hash_flt;
1278c2ecf20Sopenharmony_ci		unsigned long long slb_flt;
1288c2ecf20Sopenharmony_ci		unsigned long long slb_flt_base; /* # at last ctx switch */
1298c2ecf20Sopenharmony_ci		unsigned long long class2_intr;
1308c2ecf20Sopenharmony_ci		unsigned long long class2_intr_base; /* # at last ctx switch */
1318c2ecf20Sopenharmony_ci		unsigned long long libassist;
1328c2ecf20Sopenharmony_ci	} stats;
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	/* context switch log */
1358c2ecf20Sopenharmony_ci	struct switch_log *switch_log;
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ci	struct list_head aff_list;
1388c2ecf20Sopenharmony_ci	int aff_head;
1398c2ecf20Sopenharmony_ci	int aff_offset;
1408c2ecf20Sopenharmony_ci};
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_cistruct spu_gang {
1438c2ecf20Sopenharmony_ci	struct list_head list;
1448c2ecf20Sopenharmony_ci	struct mutex mutex;
1458c2ecf20Sopenharmony_ci	struct kref kref;
1468c2ecf20Sopenharmony_ci	int contexts;
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci	struct spu_context *aff_ref_ctx;
1498c2ecf20Sopenharmony_ci	struct list_head aff_list_head;
1508c2ecf20Sopenharmony_ci	struct mutex aff_mutex;
1518c2ecf20Sopenharmony_ci	int aff_flags;
1528c2ecf20Sopenharmony_ci	struct spu *aff_ref_spu;
1538c2ecf20Sopenharmony_ci	atomic_t aff_sched_count;
1548c2ecf20Sopenharmony_ci};
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/* Flag bits for spu_gang aff_flags */
1578c2ecf20Sopenharmony_ci#define AFF_OFFSETS_SET		1
1588c2ecf20Sopenharmony_ci#define AFF_MERGED		2
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_cistruct mfc_dma_command {
1618c2ecf20Sopenharmony_ci	int32_t pad;	/* reserved */
1628c2ecf20Sopenharmony_ci	uint32_t lsa;	/* local storage address */
1638c2ecf20Sopenharmony_ci	uint64_t ea;	/* effective address */
1648c2ecf20Sopenharmony_ci	uint16_t size;	/* transfer size */
1658c2ecf20Sopenharmony_ci	uint16_t tag;	/* command tag */
1668c2ecf20Sopenharmony_ci	uint16_t class;	/* class ID */
1678c2ecf20Sopenharmony_ci	uint16_t cmd;	/* command opcode */
1688c2ecf20Sopenharmony_ci};
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci/* SPU context query/set operations. */
1728c2ecf20Sopenharmony_cistruct spu_context_ops {
1738c2ecf20Sopenharmony_ci	int (*mbox_read) (struct spu_context * ctx, u32 * data);
1748c2ecf20Sopenharmony_ci	 u32(*mbox_stat_read) (struct spu_context * ctx);
1758c2ecf20Sopenharmony_ci	__poll_t (*mbox_stat_poll)(struct spu_context *ctx, __poll_t events);
1768c2ecf20Sopenharmony_ci	int (*ibox_read) (struct spu_context * ctx, u32 * data);
1778c2ecf20Sopenharmony_ci	int (*wbox_write) (struct spu_context * ctx, u32 data);
1788c2ecf20Sopenharmony_ci	 u32(*signal1_read) (struct spu_context * ctx);
1798c2ecf20Sopenharmony_ci	void (*signal1_write) (struct spu_context * ctx, u32 data);
1808c2ecf20Sopenharmony_ci	 u32(*signal2_read) (struct spu_context * ctx);
1818c2ecf20Sopenharmony_ci	void (*signal2_write) (struct spu_context * ctx, u32 data);
1828c2ecf20Sopenharmony_ci	void (*signal1_type_set) (struct spu_context * ctx, u64 val);
1838c2ecf20Sopenharmony_ci	 u64(*signal1_type_get) (struct spu_context * ctx);
1848c2ecf20Sopenharmony_ci	void (*signal2_type_set) (struct spu_context * ctx, u64 val);
1858c2ecf20Sopenharmony_ci	 u64(*signal2_type_get) (struct spu_context * ctx);
1868c2ecf20Sopenharmony_ci	 u32(*npc_read) (struct spu_context * ctx);
1878c2ecf20Sopenharmony_ci	void (*npc_write) (struct spu_context * ctx, u32 data);
1888c2ecf20Sopenharmony_ci	 u32(*status_read) (struct spu_context * ctx);
1898c2ecf20Sopenharmony_ci	char*(*get_ls) (struct spu_context * ctx);
1908c2ecf20Sopenharmony_ci	void (*privcntl_write) (struct spu_context *ctx, u64 data);
1918c2ecf20Sopenharmony_ci	 u32 (*runcntl_read) (struct spu_context * ctx);
1928c2ecf20Sopenharmony_ci	void (*runcntl_write) (struct spu_context * ctx, u32 data);
1938c2ecf20Sopenharmony_ci	void (*runcntl_stop) (struct spu_context * ctx);
1948c2ecf20Sopenharmony_ci	void (*master_start) (struct spu_context * ctx);
1958c2ecf20Sopenharmony_ci	void (*master_stop) (struct spu_context * ctx);
1968c2ecf20Sopenharmony_ci	int (*set_mfc_query)(struct spu_context * ctx, u32 mask, u32 mode);
1978c2ecf20Sopenharmony_ci	u32 (*read_mfc_tagstatus)(struct spu_context * ctx);
1988c2ecf20Sopenharmony_ci	u32 (*get_mfc_free_elements)(struct spu_context *ctx);
1998c2ecf20Sopenharmony_ci	int (*send_mfc_command)(struct spu_context * ctx,
2008c2ecf20Sopenharmony_ci				struct mfc_dma_command * cmd);
2018c2ecf20Sopenharmony_ci	void (*dma_info_read) (struct spu_context * ctx,
2028c2ecf20Sopenharmony_ci			       struct spu_dma_info * info);
2038c2ecf20Sopenharmony_ci	void (*proxydma_info_read) (struct spu_context * ctx,
2048c2ecf20Sopenharmony_ci				    struct spu_proxydma_info * info);
2058c2ecf20Sopenharmony_ci	void (*restart_dma)(struct spu_context *ctx);
2068c2ecf20Sopenharmony_ci};
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ciextern struct spu_context_ops spu_hw_ops;
2098c2ecf20Sopenharmony_ciextern struct spu_context_ops spu_backing_ops;
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_cistruct spufs_inode_info {
2128c2ecf20Sopenharmony_ci	struct spu_context *i_ctx;
2138c2ecf20Sopenharmony_ci	struct spu_gang *i_gang;
2148c2ecf20Sopenharmony_ci	struct inode vfs_inode;
2158c2ecf20Sopenharmony_ci	int i_openers;
2168c2ecf20Sopenharmony_ci};
2178c2ecf20Sopenharmony_ci#define SPUFS_I(inode) \
2188c2ecf20Sopenharmony_ci	container_of(inode, struct spufs_inode_info, vfs_inode)
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistruct spufs_tree_descr {
2218c2ecf20Sopenharmony_ci	const char *name;
2228c2ecf20Sopenharmony_ci	const struct file_operations *ops;
2238c2ecf20Sopenharmony_ci	umode_t mode;
2248c2ecf20Sopenharmony_ci	size_t size;
2258c2ecf20Sopenharmony_ci};
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_ciextern const struct spufs_tree_descr spufs_dir_contents[];
2288c2ecf20Sopenharmony_ciextern const struct spufs_tree_descr spufs_dir_nosched_contents[];
2298c2ecf20Sopenharmony_ciextern const struct spufs_tree_descr spufs_dir_debug_contents[];
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci/* system call implementation */
2328c2ecf20Sopenharmony_ciextern struct spufs_calls spufs_calls;
2338c2ecf20Sopenharmony_cistruct coredump_params;
2348c2ecf20Sopenharmony_cilong spufs_run_spu(struct spu_context *ctx, u32 *npc, u32 *status);
2358c2ecf20Sopenharmony_cilong spufs_create(struct path *nd, struct dentry *dentry, unsigned int flags,
2368c2ecf20Sopenharmony_ci			umode_t mode, struct file *filp);
2378c2ecf20Sopenharmony_ci/* ELF coredump callbacks for writing SPU ELF notes */
2388c2ecf20Sopenharmony_ciextern int spufs_coredump_extra_notes_size(void);
2398c2ecf20Sopenharmony_ciextern int spufs_coredump_extra_notes_write(struct coredump_params *cprm);
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ciextern const struct file_operations spufs_context_fops;
2428c2ecf20Sopenharmony_ci
2438c2ecf20Sopenharmony_ci/* gang management */
2448c2ecf20Sopenharmony_cistruct spu_gang *alloc_spu_gang(void);
2458c2ecf20Sopenharmony_cistruct spu_gang *get_spu_gang(struct spu_gang *gang);
2468c2ecf20Sopenharmony_ciint put_spu_gang(struct spu_gang *gang);
2478c2ecf20Sopenharmony_civoid spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx);
2488c2ecf20Sopenharmony_civoid spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx);
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_ci/* fault handling */
2518c2ecf20Sopenharmony_ciint spufs_handle_class1(struct spu_context *ctx);
2528c2ecf20Sopenharmony_ciint spufs_handle_class0(struct spu_context *ctx);
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ci/* affinity */
2558c2ecf20Sopenharmony_cistruct spu *affinity_check(struct spu_context *ctx);
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci/* context management */
2588c2ecf20Sopenharmony_ciextern atomic_t nr_spu_contexts;
2598c2ecf20Sopenharmony_cistatic inline int __must_check spu_acquire(struct spu_context *ctx)
2608c2ecf20Sopenharmony_ci{
2618c2ecf20Sopenharmony_ci	return mutex_lock_interruptible(&ctx->state_mutex);
2628c2ecf20Sopenharmony_ci}
2638c2ecf20Sopenharmony_ci
2648c2ecf20Sopenharmony_cistatic inline void spu_release(struct spu_context *ctx)
2658c2ecf20Sopenharmony_ci{
2668c2ecf20Sopenharmony_ci	mutex_unlock(&ctx->state_mutex);
2678c2ecf20Sopenharmony_ci}
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_cistruct spu_context * alloc_spu_context(struct spu_gang *gang);
2708c2ecf20Sopenharmony_civoid destroy_spu_context(struct kref *kref);
2718c2ecf20Sopenharmony_cistruct spu_context * get_spu_context(struct spu_context *ctx);
2728c2ecf20Sopenharmony_ciint put_spu_context(struct spu_context *ctx);
2738c2ecf20Sopenharmony_civoid spu_unmap_mappings(struct spu_context *ctx);
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_civoid spu_forget(struct spu_context *ctx);
2768c2ecf20Sopenharmony_ciint __must_check spu_acquire_saved(struct spu_context *ctx);
2778c2ecf20Sopenharmony_civoid spu_release_saved(struct spu_context *ctx);
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ciint spu_stopped(struct spu_context *ctx, u32 * stat);
2808c2ecf20Sopenharmony_civoid spu_del_from_rq(struct spu_context *ctx);
2818c2ecf20Sopenharmony_ciint spu_activate(struct spu_context *ctx, unsigned long flags);
2828c2ecf20Sopenharmony_civoid spu_deactivate(struct spu_context *ctx);
2838c2ecf20Sopenharmony_civoid spu_yield(struct spu_context *ctx);
2848c2ecf20Sopenharmony_civoid spu_switch_notify(struct spu *spu, struct spu_context *ctx);
2858c2ecf20Sopenharmony_civoid spu_switch_log_notify(struct spu *spu, struct spu_context *ctx,
2868c2ecf20Sopenharmony_ci		u32 type, u32 val);
2878c2ecf20Sopenharmony_civoid spu_set_timeslice(struct spu_context *ctx);
2888c2ecf20Sopenharmony_civoid spu_update_sched_info(struct spu_context *ctx);
2898c2ecf20Sopenharmony_civoid __spu_update_sched_info(struct spu_context *ctx);
2908c2ecf20Sopenharmony_ciint __init spu_sched_init(void);
2918c2ecf20Sopenharmony_civoid spu_sched_exit(void);
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_ciextern char *isolated_loader;
2948c2ecf20Sopenharmony_ci
2958c2ecf20Sopenharmony_ci/*
2968c2ecf20Sopenharmony_ci * spufs_wait
2978c2ecf20Sopenharmony_ci *	Same as wait_event_interruptible(), except that here
2988c2ecf20Sopenharmony_ci *	we need to call spu_release(ctx) before sleeping, and
2998c2ecf20Sopenharmony_ci *	then spu_acquire(ctx) when awoken.
3008c2ecf20Sopenharmony_ci *
3018c2ecf20Sopenharmony_ci * 	Returns with state_mutex re-acquired when successful or
3028c2ecf20Sopenharmony_ci * 	with -ERESTARTSYS and the state_mutex dropped when interrupted.
3038c2ecf20Sopenharmony_ci */
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci#define spufs_wait(wq, condition)					\
3068c2ecf20Sopenharmony_ci({									\
3078c2ecf20Sopenharmony_ci	int __ret = 0;							\
3088c2ecf20Sopenharmony_ci	DEFINE_WAIT(__wait);						\
3098c2ecf20Sopenharmony_ci	for (;;) {							\
3108c2ecf20Sopenharmony_ci		prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE);	\
3118c2ecf20Sopenharmony_ci		if (condition)						\
3128c2ecf20Sopenharmony_ci			break;						\
3138c2ecf20Sopenharmony_ci		spu_release(ctx);					\
3148c2ecf20Sopenharmony_ci		if (signal_pending(current)) {				\
3158c2ecf20Sopenharmony_ci			__ret = -ERESTARTSYS;				\
3168c2ecf20Sopenharmony_ci			break;						\
3178c2ecf20Sopenharmony_ci		}							\
3188c2ecf20Sopenharmony_ci		schedule();						\
3198c2ecf20Sopenharmony_ci		__ret = spu_acquire(ctx);				\
3208c2ecf20Sopenharmony_ci		if (__ret)						\
3218c2ecf20Sopenharmony_ci			break;						\
3228c2ecf20Sopenharmony_ci	}								\
3238c2ecf20Sopenharmony_ci	finish_wait(&(wq), &__wait);					\
3248c2ecf20Sopenharmony_ci	__ret;								\
3258c2ecf20Sopenharmony_ci})
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_cisize_t spu_wbox_write(struct spu_context *ctx, u32 data);
3288c2ecf20Sopenharmony_cisize_t spu_ibox_read(struct spu_context *ctx, u32 *data);
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci/* irq callback funcs. */
3318c2ecf20Sopenharmony_civoid spufs_ibox_callback(struct spu *spu);
3328c2ecf20Sopenharmony_civoid spufs_wbox_callback(struct spu *spu);
3338c2ecf20Sopenharmony_civoid spufs_stop_callback(struct spu *spu, int irq);
3348c2ecf20Sopenharmony_civoid spufs_mfc_callback(struct spu *spu);
3358c2ecf20Sopenharmony_civoid spufs_dma_callback(struct spu *spu, int type);
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_ciextern struct spu_coredump_calls spufs_coredump_calls;
3388c2ecf20Sopenharmony_cistruct spufs_coredump_reader {
3398c2ecf20Sopenharmony_ci	char *name;
3408c2ecf20Sopenharmony_ci	ssize_t (*dump)(struct spu_context *ctx, struct coredump_params *cprm);
3418c2ecf20Sopenharmony_ci	u64 (*get)(struct spu_context *ctx);
3428c2ecf20Sopenharmony_ci	size_t size;
3438c2ecf20Sopenharmony_ci};
3448c2ecf20Sopenharmony_ciextern const struct spufs_coredump_reader spufs_coredump_read[];
3458c2ecf20Sopenharmony_ciextern int spufs_coredump_num_notes;
3468c2ecf20Sopenharmony_ci
3478c2ecf20Sopenharmony_ciextern int spu_init_csa(struct spu_state *csa);
3488c2ecf20Sopenharmony_ciextern void spu_fini_csa(struct spu_state *csa);
3498c2ecf20Sopenharmony_ciextern int spu_save(struct spu_state *prev, struct spu *spu);
3508c2ecf20Sopenharmony_ciextern int spu_restore(struct spu_state *new, struct spu *spu);
3518c2ecf20Sopenharmony_ciextern int spu_switch(struct spu_state *prev, struct spu_state *new,
3528c2ecf20Sopenharmony_ci		      struct spu *spu);
3538c2ecf20Sopenharmony_ciextern int spu_alloc_lscsa(struct spu_state *csa);
3548c2ecf20Sopenharmony_ciextern void spu_free_lscsa(struct spu_state *csa);
3558c2ecf20Sopenharmony_ci
3568c2ecf20Sopenharmony_ciextern void spuctx_switch_state(struct spu_context *ctx,
3578c2ecf20Sopenharmony_ci		enum spu_utilization_state new_state);
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci#endif
360