1 #include <linux/wait.h>
2 #include <linux/ptrace.h>
8 /* interrupt-level stop callback function. */
9 void spufs_stop_callback(struct spu *spu)
11 struct spu_context *ctx = spu->ctx;
13 wake_up_all(&ctx->stop_wq);
16 static inline int spu_stopped(struct spu_context *ctx, u32 * stat)
21 *stat = ctx->ops->status_read(ctx);
22 if (ctx->state != SPU_STATE_RUNNABLE)
25 pte_fault = spu->dsisr &
26 (MFC_DSISR_PTE_NOT_FOUND | MFC_DSISR_ACCESS_DENIED);
27 return (!(*stat & 0x1) || pte_fault || spu->class_0_pending) ? 1 : 0;
30 static inline int spu_run_init(struct spu_context *ctx, u32 * npc,
35 if ((ret = spu_acquire_runnable(ctx)) != 0)
37 ctx->ops->npc_write(ctx, *npc);
38 ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_RUNNABLE);
42 static inline int spu_run_fini(struct spu_context *ctx, u32 * npc,
47 *status = ctx->ops->status_read(ctx);
48 *npc = ctx->ops->npc_read(ctx);
51 if (signal_pending(current))
53 if (unlikely(current->ptrace & PT_PTRACED)) {
54 if ((*status & SPU_STATUS_STOPPED_BY_STOP)
55 && (*status >> SPU_STOP_STATUS_SHIFT) == 0x3fff) {
56 force_sig(SIGTRAP, current);
63 static inline int spu_reacquire_runnable(struct spu_context *ctx, u32 *npc,
68 if ((ret = spu_run_fini(ctx, npc, status)) != 0)
70 if (*status & (SPU_STATUS_STOPPED_BY_STOP |
71 SPU_STATUS_STOPPED_BY_HALT)) {
74 if ((ret = spu_run_init(ctx, npc, status)) != 0)
79 static inline int spu_process_events(struct spu_context *ctx)
81 struct spu *spu = ctx->spu;
82 u64 pte_fault = MFC_DSISR_PTE_NOT_FOUND | MFC_DSISR_ACCESS_DENIED;
85 if (spu->dsisr & pte_fault)
86 ret = spu_irq_class_1_bottom(spu);
87 if (spu->class_0_pending)
88 ret = spu_irq_class_0_bottom(spu);
89 if (!ret && signal_pending(current))
94 long spufs_run_spu(struct file *file, struct spu_context *ctx,
95 u32 * npc, u32 * status)
99 if (down_interruptible(&ctx->run_sema))
102 ret = spu_run_init(ctx, npc, status);
107 ret = spufs_wait(ctx->stop_wq, spu_stopped(ctx, status));
110 if (unlikely(ctx->state != SPU_STATE_RUNNABLE)) {
111 ret = spu_reacquire_runnable(ctx, npc, status);
116 ret = spu_process_events(ctx);
118 } while (!ret && !(*status & (SPU_STATUS_STOPPED_BY_STOP |
119 SPU_STATUS_STOPPED_BY_HALT)));
121 ctx->ops->runcntl_stop(ctx);
122 ret = spu_run_fini(ctx, npc, status);