powerpc/spufs: Constify context contents and coredump callback constants
[safe/jmp/linux-2.6] / arch / powerpc / platforms / cell / spufs / spufs.h
index fcab150..ae31573 100644 (file)
 #include <asm/spu_csa.h>
 #include <asm/spu_info.h>
 
+#define SPUFS_PS_MAP_SIZE      0x20000
+#define SPUFS_MFC_MAP_SIZE     0x1000
+#define SPUFS_CNTL_MAP_SIZE    0x1000
+#define SPUFS_CNTL_MAP_SIZE    0x1000
+#define SPUFS_SIGNAL_MAP_SIZE  PAGE_SIZE
+#define SPUFS_MSS_MAP_SIZE     0x1000
+
 /* The magic number for our file system */
 enum {
        SPUFS_MAGIC = 0x23c9b64e,
@@ -44,6 +51,30 @@ struct spu_gang;
 enum {
        SPU_SCHED_NOTIFY_ACTIVE,
        SPU_SCHED_WAS_ACTIVE,   /* was active upon spu_acquire_saved()  */
+       SPU_SCHED_SPU_RUN,      /* context is within spu_run */
+};
+
+enum {
+       SWITCH_LOG_BUFSIZE = 4096,
+};
+
+enum {
+       SWITCH_LOG_START,
+       SWITCH_LOG_STOP,
+       SWITCH_LOG_EXIT,
+};
+
+struct switch_log {
+       wait_queue_head_t       wait;
+       unsigned long           head;
+       unsigned long           tail;
+       struct switch_log_entry {
+               struct timespec tstamp;
+               s32             spu_id;
+               u32             type;
+               u32             val;
+               u64             timebase;
+       } log[];
 };
 
 struct spu_context {
@@ -96,6 +127,7 @@ struct spu_context {
        cpumask_t cpus_allowed;
        int policy;
        int prio;
+       int last_ran;
 
        /* statistics */
        struct {
@@ -115,6 +147,9 @@ struct spu_context {
                unsigned long long libassist;
        } stats;
 
+       /* context switch log */
+       struct switch_log *switch_log;
+
        struct list_head aff_list;
        int aff_head;
        int aff_offset;
@@ -169,6 +204,7 @@ struct spu_context_ops {
        void (*npc_write) (struct spu_context * ctx, u32 data);
         u32(*status_read) (struct spu_context * ctx);
        char*(*get_ls) (struct spu_context * ctx);
+       void (*privcntl_write) (struct spu_context *ctx, u64 data);
         u32 (*runcntl_read) (struct spu_context * ctx);
        void (*runcntl_write) (struct spu_context * ctx, u32 data);
        void (*runcntl_stop) (struct spu_context * ctx);
@@ -198,8 +234,16 @@ struct spufs_inode_info {
 #define SPUFS_I(inode) \
        container_of(inode, struct spufs_inode_info, vfs_inode)
 
-extern struct tree_descr spufs_dir_contents[];
-extern struct tree_descr spufs_dir_nosched_contents[];
+struct spufs_tree_descr {
+       const char *name;
+       const struct file_operations *ops;
+       int mode;
+       size_t size;
+};
+
+extern const struct spufs_tree_descr spufs_dir_contents[];
+extern const struct spufs_tree_descr spufs_dir_nosched_contents[];
+extern const struct spufs_tree_descr spufs_dir_debug_contents[];
 
 /* system call implementation */
 extern struct spufs_calls spufs_calls;
@@ -221,15 +265,16 @@ void spu_gang_add_ctx(struct spu_gang *gang, struct spu_context *ctx);
 
 /* fault handling */
 int spufs_handle_class1(struct spu_context *ctx);
+int spufs_handle_class0(struct spu_context *ctx);
 
 /* affinity */
 struct spu *affinity_check(struct spu_context *ctx);
 
 /* context management */
 extern atomic_t nr_spu_contexts;
-static inline void spu_acquire(struct spu_context *ctx)
+static inline int __must_check spu_acquire(struct spu_context *ctx)
 {
-       mutex_lock(&ctx->state_mutex);
+       return mutex_lock_interruptible(&ctx->state_mutex);
 }
 
 static inline void spu_release(struct spu_context *ctx)
@@ -244,14 +289,17 @@ int put_spu_context(struct spu_context *ctx);
 void spu_unmap_mappings(struct spu_context *ctx);
 
 void spu_forget(struct spu_context *ctx);
-int spu_acquire_runnable(struct spu_context *ctx, unsigned long flags);
-void spu_acquire_saved(struct spu_context *ctx);
+int __must_check spu_acquire_saved(struct spu_context *ctx);
 void spu_release_saved(struct spu_context *ctx);
 
+int spu_stopped(struct spu_context *ctx, u32 * stat);
+void spu_del_from_rq(struct spu_context *ctx);
 int spu_activate(struct spu_context *ctx, unsigned long flags);
 void spu_deactivate(struct spu_context *ctx);
 void spu_yield(struct spu_context *ctx);
 void spu_switch_notify(struct spu *spu, struct spu_context *ctx);
+void spu_switch_log_notify(struct spu *spu, struct spu_context *ctx,
+               u32 type, u32 val);
 void spu_set_timeslice(struct spu_context *ctx);
 void spu_update_sched_info(struct spu_context *ctx);
 void __spu_update_sched_info(struct spu_context *ctx);
@@ -265,6 +313,9 @@ extern char *isolated_loader;
  *     Same as wait_event_interruptible(), except that here
  *     we need to call spu_release(ctx) before sleeping, and
  *     then spu_acquire(ctx) when awoken.
+ *
+ *     Returns with state_mutex re-acquired when successful or
+ *     with -ERESTARTSYS and the state_mutex dropped when interrupted.
  */
 
 #define spufs_wait(wq, condition)                                      \
@@ -275,13 +326,15 @@ extern char *isolated_loader;
                prepare_to_wait(&(wq), &__wait, TASK_INTERRUPTIBLE);    \
                if (condition)                                          \
                        break;                                          \
+               spu_release(ctx);                                       \
                if (signal_pending(current)) {                          \
                        __ret = -ERESTARTSYS;                           \
                        break;                                          \
                }                                                       \
-               spu_release(ctx);                                       \
                schedule();                                             \
-               spu_acquire(ctx);                                       \
+               __ret = spu_acquire(ctx);                               \
+               if (__ret)                                              \
+                       break;                                          \
        }                                                               \
        finish_wait(&(wq), &__wait);                                    \
        __ret;                                                          \
@@ -293,7 +346,7 @@ size_t spu_ibox_read(struct spu_context *ctx, u32 *data);
 /* irq callback funcs. */
 void spufs_ibox_callback(struct spu *spu);
 void spufs_wbox_callback(struct spu *spu);
-void spufs_stop_callback(struct spu *spu);
+void spufs_stop_callback(struct spu *spu, int irq);
 void spufs_mfc_callback(struct spu *spu);
 void spufs_dma_callback(struct spu *spu, int type);
 
@@ -305,7 +358,7 @@ struct spufs_coredump_reader {
        u64 (*get)(struct spu_context *ctx);
        size_t size;
 };
-extern struct spufs_coredump_reader spufs_coredump_read[];
+extern const struct spufs_coredump_reader spufs_coredump_read[];
 extern int spufs_coredump_num_notes;
 
 extern int spu_init_csa(struct spu_state *csa);
@@ -320,4 +373,9 @@ extern void spu_free_lscsa(struct spu_state *csa);
 extern void spuctx_switch_state(struct spu_context *ctx,
                enum spu_utilization_state new_state);
 
+#define spu_context_trace(name, ctx, spu) \
+       trace_mark(name, "ctx %p spu %p", ctx, spu);
+#define spu_context_nospu_trace(name, ctx) \
+       trace_mark(name, "ctx %p", ctx);
+
 #endif