Path: blob/master/arch/powerpc/platforms/cell/spufs/spufs.h
26498 views
/* SPDX-License-Identifier: GPL-2.0-or-later */1/*2* SPU file system3*4* (C) Copyright IBM Deutschland Entwicklung GmbH 20055*6* Author: Arnd Bergmann <[email protected]>7*/8#ifndef SPUFS_H9#define SPUFS_H1011#include <linux/kref.h>12#include <linux/mutex.h>13#include <linux/spinlock.h>14#include <linux/fs.h>15#include <linux/cpumask.h>16#include <linux/sched/signal.h>1718#include <asm/spu.h>19#include <asm/spu_csa.h>20#include <asm/spu_info.h>2122#define SPUFS_PS_MAP_SIZE 0x2000023#define SPUFS_MFC_MAP_SIZE 0x100024#define SPUFS_CNTL_MAP_SIZE 0x100025#define SPUFS_SIGNAL_MAP_SIZE PAGE_SIZE26#define SPUFS_MSS_MAP_SIZE 0x10002728/* The magic number for our file system */29enum {30SPUFS_MAGIC = 0x23c9b64e,31};3233struct spu_context_ops;34struct spu_gang;3536/* ctx->sched_flags */37enum {38SPU_SCHED_NOTIFY_ACTIVE,39SPU_SCHED_WAS_ACTIVE, /* was active upon spu_acquire_saved() */40SPU_SCHED_SPU_RUN, /* context is within spu_run */41};4243enum {44SWITCH_LOG_BUFSIZE = 4096,45};4647enum {48SWITCH_LOG_START,49SWITCH_LOG_STOP,50SWITCH_LOG_EXIT,51};5253struct switch_log {54wait_queue_head_t wait;55unsigned long head;56unsigned long tail;57struct switch_log_entry {58struct timespec64 tstamp;59s32 spu_id;60u32 type;61u32 val;62u64 timebase;63} log[];64};6566struct spu_context {67struct spu *spu; /* pointer to a physical SPU */68struct spu_state csa; /* SPU context save area. */69spinlock_t mmio_lock; /* protects mmio access */70struct address_space *local_store; /* local store mapping. */71struct address_space *mfc; /* 'mfc' area mappings. */72struct address_space *cntl; /* 'control' area mappings. */73struct address_space *signal1; /* 'signal1' area mappings. */74struct address_space *signal2; /* 'signal2' area mappings. */75struct address_space *mss; /* 'mss' area mappings. */76struct address_space *psmap; /* 'psmap' area mappings. */77struct mutex mapping_lock;78u64 object_id; /* user space pointer for GNU Debugger */7980enum { SPU_STATE_RUNNABLE, SPU_STATE_SAVED } state;81struct mutex state_mutex;82struct mutex run_mutex;8384struct mm_struct *owner;8586struct kref kref;87wait_queue_head_t ibox_wq;88wait_queue_head_t wbox_wq;89wait_queue_head_t stop_wq;90wait_queue_head_t mfc_wq;91wait_queue_head_t run_wq;92u32 tagwait;93struct spu_context_ops *ops;94struct work_struct reap_work;95unsigned long flags;96unsigned long event_return;9798struct list_head gang_list;99struct spu_gang *gang;100struct kref *prof_priv_kref;101void ( * prof_priv_release) (struct kref *kref);102103/* owner thread */104pid_t tid;105106/* scheduler fields */107struct list_head rq;108unsigned int time_slice;109unsigned long sched_flags;110cpumask_t cpus_allowed;111int policy;112int prio;113int last_ran;114115/* statistics */116struct {117/* updates protected by ctx->state_mutex */118enum spu_utilization_state util_state;119unsigned long long tstamp; /* time of last state switch */120unsigned long long times[SPU_UTIL_MAX];121unsigned long long vol_ctx_switch;122unsigned long long invol_ctx_switch;123unsigned long long min_flt;124unsigned long long maj_flt;125unsigned long long hash_flt;126unsigned long long slb_flt;127unsigned long long slb_flt_base; /* # at last ctx switch */128unsigned long long class2_intr;129unsigned long long class2_intr_base; /* # at last ctx switch */130unsigned long long libassist;131} stats;132133/* context switch log */134struct switch_log *switch_log;135136struct list_head aff_list;137int aff_head;138int aff_offset;139};140141struct spu_gang {142struct list_head list;143struct mutex mutex;144struct kref kref;145int contexts;146147struct spu_context *aff_ref_ctx;148struct list_head aff_list_head;149struct mutex aff_mutex;150int aff_flags;151struct spu *aff_ref_spu;152atomic_t aff_sched_count;153154int alive;155};156157/* Flag bits for spu_gang aff_flags */158#define AFF_OFFSETS_SET 1159#define AFF_MERGED 2160161struct mfc_dma_command {162int32_t pad; /* reserved */163uint32_t lsa; /* local storage address */164uint64_t ea; /* effective address */165uint16_t size; /* transfer size */166uint16_t tag; /* command tag */167uint16_t class; /* class ID */168uint16_t cmd; /* command opcode */169};170171172/* SPU context query/set operations. */173struct spu_context_ops {174int (*mbox_read) (struct spu_context * ctx, u32 * data);175u32(*mbox_stat_read) (struct spu_context * ctx);176__poll_t (*mbox_stat_poll)(struct spu_context *ctx, __poll_t events);177int (*ibox_read) (struct spu_context * ctx, u32 * data);178int (*wbox_write) (struct spu_context * ctx, u32 data);179u32(*signal1_read) (struct spu_context * ctx);180void (*signal1_write) (struct spu_context * ctx, u32 data);181u32(*signal2_read) (struct spu_context * ctx);182void (*signal2_write) (struct spu_context * ctx, u32 data);183void (*signal1_type_set) (struct spu_context * ctx, u64 val);184u64(*signal1_type_get) (struct spu_context * ctx);185void (*signal2_type_set) (struct spu_context * ctx, u64 val);186u64(*signal2_type_get) (struct spu_context * ctx);187u32(*npc_read) (struct spu_context * ctx);188void (*npc_write) (struct spu_context * ctx, u32 data);189u32(*status_read) (struct spu_context * ctx);190char*(*get_ls) (struct spu_context * ctx);191void (*privcntl_write) (struct spu_context *ctx, u64 data);192u32 (*runcntl_read) (struct spu_context * ctx);193void (*runcntl_write) (struct spu_context * ctx, u32 data);194void (*runcntl_stop) (struct spu_context * ctx);195void (*master_start) (struct spu_context * ctx);196void (*master_stop) (struct spu_context * ctx);197int (*set_mfc_query)(struct spu_context * ctx, u32 mask, u32 mode);198u32 (*read_mfc_tagstatus)(struct spu_context * ctx);199u32 (*get_mfc_free_elements)(struct spu_context *ctx);200int (*send_mfc_command)(struct spu_context * ctx,201struct mfc_dma_command * cmd);202void (*dma_info_read) (struct spu_context * ctx,203struct spu_dma_info * info);204void (*proxydma_info_read) (struct spu_context * ctx,205struct spu_proxydma_info * info);206void (*restart_dma)(struct spu_context *ctx);207};208209extern struct spu_context_ops spu_hw_ops;210extern struct spu_context_ops spu_backing_ops;211212struct spufs_inode_info {213struct spu_context *i_ctx;214struct spu_gang *i_gang;215struct inode vfs_inode;216int i_openers;217};218#define SPUFS_I(inode) \219container_of(inode, struct spufs_inode_info, vfs_inode)220221struct spufs_tree_descr {222const char *name;223const struct file_operations *ops;224umode_t mode;225size_t size;226};227228extern const struct spufs_tree_descr spufs_dir_contents[];229extern const struct spufs_tree_descr spufs_dir_nosched_contents[];230extern const struct spufs_tree_descr spufs_dir_debug_contents[];231232/* system call implementation */233extern struct spufs_calls spufs_calls;234struct coredump_params;235long spufs_run_spu(struct spu_context *ctx, u32 *npc, u32 *status);236long spufs_create(const struct path *nd, struct dentry *dentry, unsigned int flags,237umode_t mode, struct file *filp);238/* ELF coredump callbacks for writing SPU ELF notes */239extern int spufs_coredump_extra_notes_size(void);240extern int spufs_coredump_extra_notes_write(struct coredump_params *cprm);241242extern const struct file_operations spufs_context_fops;243244/* gang management */245struct spu_gang *alloc_spu_gang(void);246struct spu_gang *get_spu_gang(struct spu_gang *gang);247int put_spu_gang(struct spu_gang *gang);248void spu_gang_remove_ctx(struct spu_gang *gang, struct spu_context *ctx);249void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx);250251/* fault handling */252int spufs_handle_class1(struct spu_context *ctx);253int spufs_handle_class0(struct spu_context *ctx);254255/* affinity */256struct spu *affinity_check(struct spu_context *ctx);257258/* context management */259extern atomic_t nr_spu_contexts;260static inline int __must_check spu_acquire(struct spu_context *ctx)261{262return mutex_lock_interruptible(&ctx->state_mutex);263}264265static inline void spu_release(struct spu_context *ctx)266{267mutex_unlock(&ctx->state_mutex);268}269270struct spu_context * alloc_spu_context(struct spu_gang *gang);271void destroy_spu_context(struct kref *kref);272struct spu_context * get_spu_context(struct spu_context *ctx);273int put_spu_context(struct spu_context *ctx);274void spu_unmap_mappings(struct spu_context *ctx);275276void spu_forget(struct spu_context *ctx);277int __must_check spu_acquire_saved(struct spu_context *ctx);278void spu_release_saved(struct spu_context *ctx);279280int spu_stopped(struct spu_context *ctx, u32 * stat);281void spu_del_from_rq(struct spu_context *ctx);282int spu_activate(struct spu_context *ctx, unsigned long flags);283void spu_deactivate(struct spu_context *ctx);284void spu_yield(struct spu_context *ctx);285void spu_switch_log_notify(struct spu *spu, struct spu_context *ctx,286u32 type, u32 val);287void spu_set_timeslice(struct spu_context *ctx);288void spu_update_sched_info(struct spu_context *ctx);289void __spu_update_sched_info(struct spu_context *ctx);290int __init spu_sched_init(void);291void spu_sched_exit(void);292293extern char *isolated_loader;294295/*296* spufs_wait297* Same as wait_event_interruptible(), except that here298* we need to call spu_release(ctx) before sleeping, and299* then spu_acquire(ctx) when awoken.300*301* Returns with state_mutex re-acquired when successful or302* with -ERESTARTSYS and the state_mutex dropped when interrupted.303*/304305#define spufs_wait(wq, condition) \306({ \307int __ret = 0; \308DEFINE_WAIT(__wait); \309for (;;) { \310prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE); \311if (condition) \312break; \313spu_release(ctx); \314if (signal_pending(current)) { \315__ret = -ERESTARTSYS; \316break; \317} \318schedule(); \319__ret = spu_acquire(ctx); \320if (__ret) \321break; \322} \323finish_wait(&(wq), &__wait); \324__ret; \325})326327size_t spu_wbox_write(struct spu_context *ctx, u32 data);328size_t spu_ibox_read(struct spu_context *ctx, u32 *data);329330/* irq callback funcs. */331void spufs_ibox_callback(struct spu *spu);332void spufs_wbox_callback(struct spu *spu);333void spufs_stop_callback(struct spu *spu, int irq);334void spufs_mfc_callback(struct spu *spu);335void spufs_dma_callback(struct spu *spu, int type);336337struct spufs_coredump_reader {338char *name;339ssize_t (*dump)(struct spu_context *ctx, struct coredump_params *cprm);340u64 (*get)(struct spu_context *ctx);341size_t size;342};343extern const struct spufs_coredump_reader spufs_coredump_read[];344345extern int spu_init_csa(struct spu_state *csa);346extern void spu_fini_csa(struct spu_state *csa);347extern int spu_save(struct spu_state *prev, struct spu *spu);348extern int spu_restore(struct spu_state *new, struct spu *spu);349extern int spu_switch(struct spu_state *prev, struct spu_state *new,350struct spu *spu);351extern int spu_alloc_lscsa(struct spu_state *csa);352extern void spu_free_lscsa(struct spu_state *csa);353354extern void spuctx_switch_state(struct spu_context *ctx,355enum spu_utilization_state new_state);356357#endif358359360