blob: 4ddf769a64e589adbfdba180b86021b357730897 [file] [log] [blame]
arnd@arndb.de0afacde2006-10-24 18:31:18 +02001#define DEBUG
2
Arnd Bergmannce8ab852006-01-04 20:31:29 +01003#include <linux/wait.h>
4#include <linux/ptrace.h>
5
6#include <asm/spu.h>
Jeremy Kerrc6730ed2006-11-20 18:45:10 +01007#include <asm/spu_priv1.h>
8#include <asm/io.h>
Dave Jonescfff5b22006-03-31 23:53:09 -05009#include <asm/unistd.h>
Arnd Bergmannce8ab852006-01-04 20:31:29 +010010
11#include "spufs.h"
12
13/* interrupt-level stop callback function. */
Luke Browningf3d69e02008-04-27 18:41:55 +000014void spufs_stop_callback(struct spu *spu, int irq)
Arnd Bergmannce8ab852006-01-04 20:31:29 +010015{
16 struct spu_context *ctx = spu->ctx;
17
Jeremy Kerrd6ad39b2007-12-20 16:39:59 +090018 /*
19 * It should be impossible to preempt a context while an exception
20 * is being processed, since the context switch code is specially
21 * coded to deal with interrupts ... But, just in case, sanity check
22 * the context pointer. It is OK to return doing nothing since
23 * the exception will be regenerated when the context is resumed.
24 */
25 if (ctx) {
26 /* Copy exception arguments into module specific structure */
Luke Browningf3d69e02008-04-27 18:41:55 +000027 switch(irq) {
28 case 0 :
29 ctx->csa.class_0_pending = spu->class_0_pending;
Luke Browningf3d69e02008-04-27 18:41:55 +000030 ctx->csa.class_0_dar = spu->class_0_dar;
31 break;
32 case 1 :
33 ctx->csa.class_1_dsisr = spu->class_1_dsisr;
34 ctx->csa.class_1_dar = spu->class_1_dar;
35 break;
36 case 2 :
37 break;
38 }
Jeremy Kerrd6ad39b2007-12-20 16:39:59 +090039
40 /* ensure that the exception status has hit memory before a
41 * thread waiting on the context's stop queue is woken */
42 smp_wmb();
43
44 wake_up_all(&ctx->stop_wq);
45 }
Arnd Bergmannce8ab852006-01-04 20:31:29 +010046}
47
Luke Browninge65c2f62007-12-20 16:39:59 +090048int spu_stopped(struct spu_context *ctx, u32 *stat)
Arnd Bergmannce8ab852006-01-04 20:31:29 +010049{
Luke Browninge65c2f62007-12-20 16:39:59 +090050 u64 dsisr;
51 u32 stopped;
Arnd Bergmannce8ab852006-01-04 20:31:29 +010052
Luke Browninge65c2f62007-12-20 16:39:59 +090053 stopped = SPU_STATUS_INVALID_INSTR | SPU_STATUS_SINGLE_STEP |
54 SPU_STATUS_STOPPED_BY_HALT | SPU_STATUS_STOPPED_BY_STOP;
Luke Browningd84050f2008-05-29 17:46:10 -030055
56top:
57 *stat = ctx->ops->status_read(ctx);
58 if (*stat & stopped) {
59 /*
60 * If the spu hasn't finished stopping, we need to
61 * re-read the register to get the stopped value.
62 */
63 if (*stat & SPU_STATUS_RUNNING)
64 goto top;
65 return 1;
66 }
67
68 if (test_bit(SPU_SCHED_NOTIFY_ACTIVE, &ctx->sched_flags))
Luke Browninge65c2f62007-12-20 16:39:59 +090069 return 1;
70
Luke Browningf3d69e02008-04-27 18:41:55 +000071 dsisr = ctx->csa.class_1_dsisr;
Luke Browninge65c2f62007-12-20 16:39:59 +090072 if (dsisr & (MFC_DSISR_PTE_NOT_FOUND | MFC_DSISR_ACCESS_DENIED))
73 return 1;
74
75 if (ctx->csa.class_0_pending)
76 return 1;
77
78 return 0;
Arnd Bergmannce8ab852006-01-04 20:31:29 +010079}
80
Jeremy Kerrc6730ed2006-11-20 18:45:10 +010081static int spu_setup_isolated(struct spu_context *ctx)
82{
83 int ret;
84 u64 __iomem *mfc_cntl;
85 u64 sr1;
86 u32 status;
87 unsigned long timeout;
88 const u32 status_loading = SPU_STATUS_RUNNING
89 | SPU_STATUS_ISOLATED_STATE | SPU_STATUS_ISOLATED_LOAD_STATUS;
90
Christoph Hellwig7ec18ab2007-04-23 21:08:12 +020091 ret = -ENODEV;
Jeremy Kerrc6730ed2006-11-20 18:45:10 +010092 if (!isolated_loader)
Jeremy Kerrc6730ed2006-11-20 18:45:10 +010093 goto out;
94
Christoph Hellwig7ec18ab2007-04-23 21:08:12 +020095 /*
96 * We need to exclude userspace access to the context.
97 *
98 * To protect against memory access we invalidate all ptes
99 * and make sure the pagefault handlers block on the mutex.
100 */
101 spu_unmap_mappings(ctx);
102
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100103 mfc_cntl = &ctx->spu->priv2->mfc_control_RW;
104
105 /* purge the MFC DMA queue to ensure no spurious accesses before we
106 * enter kernel mode */
107 timeout = jiffies + HZ;
108 out_be64(mfc_cntl, MFC_CNTL_PURGE_DMA_REQUEST);
109 while ((in_be64(mfc_cntl) & MFC_CNTL_PURGE_DMA_STATUS_MASK)
110 != MFC_CNTL_PURGE_DMA_COMPLETE) {
111 if (time_after(jiffies, timeout)) {
112 printk(KERN_ERR "%s: timeout flushing MFC DMA queue\n",
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100113 __func__);
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100114 ret = -EIO;
Christoph Hellwig7ec18ab2007-04-23 21:08:12 +0200115 goto out;
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100116 }
117 cond_resched();
118 }
119
Jeremy Kerr3688b462009-02-17 11:44:14 +1100120 /* clear purge status */
121 out_be64(mfc_cntl, 0);
122
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100123 /* put the SPE in kernel mode to allow access to the loader */
124 sr1 = spu_mfc_sr1_get(ctx->spu);
125 sr1 &= ~MFC_STATE1_PROBLEM_STATE_MASK;
126 spu_mfc_sr1_set(ctx->spu, sr1);
127
128 /* start the loader */
129 ctx->ops->signal1_write(ctx, (unsigned long)isolated_loader >> 32);
130 ctx->ops->signal2_write(ctx,
131 (unsigned long)isolated_loader & 0xffffffff);
132
133 ctx->ops->runcntl_write(ctx,
134 SPU_RUNCNTL_RUNNABLE | SPU_RUNCNTL_ISOLATE);
135
136 ret = 0;
137 timeout = jiffies + HZ;
138 while (((status = ctx->ops->status_read(ctx)) & status_loading) ==
139 status_loading) {
140 if (time_after(jiffies, timeout)) {
141 printk(KERN_ERR "%s: timeout waiting for loader\n",
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100142 __func__);
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100143 ret = -EIO;
144 goto out_drop_priv;
145 }
146 cond_resched();
147 }
148
149 if (!(status & SPU_STATUS_RUNNING)) {
150 /* If isolated LOAD has failed: run SPU, we will get a stop-and
151 * signal later. */
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100152 pr_debug("%s: isolated LOAD failed\n", __func__);
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100153 ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_RUNNABLE);
154 ret = -EACCES;
Christoph Hellwig7ec18ab2007-04-23 21:08:12 +0200155 goto out_drop_priv;
156 }
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100157
Christoph Hellwig7ec18ab2007-04-23 21:08:12 +0200158 if (!(status & SPU_STATUS_ISOLATED_STATE)) {
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100159 /* This isn't allowed by the CBEA, but check anyway */
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100160 pr_debug("%s: SPU fell out of isolated mode?\n", __func__);
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100161 ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_STOP);
162 ret = -EINVAL;
Christoph Hellwig7ec18ab2007-04-23 21:08:12 +0200163 goto out_drop_priv;
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100164 }
165
166out_drop_priv:
167 /* Finished accessing the loader. Drop kernel mode */
168 sr1 |= MFC_STATE1_PROBLEM_STATE_MASK;
169 spu_mfc_sr1_set(ctx->spu, sr1);
170
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100171out:
172 return ret;
173}
174
Bob Nelson36aaccc2007-07-20 21:39:52 +0200175static int spu_run_init(struct spu_context *ctx, u32 *npc)
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100176{
Luke Browninge65c2f62007-12-20 16:39:59 +0900177 unsigned long runcntl = SPU_RUNCNTL_RUNNABLE;
Luke Browning91569532007-12-20 16:39:59 +0900178 int ret;
Luke Browningcc210b32007-12-20 16:39:59 +0900179
Andre Detsch27ec41d2007-07-20 21:39:33 +0200180 spuctx_switch_state(ctx, SPU_UTIL_SYSTEM);
181
Luke Browninge65c2f62007-12-20 16:39:59 +0900182 /*
183 * NOSCHED is synchronous scheduling with respect to the caller.
184 * The caller waits for the context to be loaded.
185 */
186 if (ctx->flags & SPU_CREATE_NOSCHED) {
Luke Browning91569532007-12-20 16:39:59 +0900187 if (ctx->state == SPU_STATE_SAVED) {
Luke Browning91569532007-12-20 16:39:59 +0900188 ret = spu_activate(ctx, 0);
Christoph Hellwig7ec18ab2007-04-23 21:08:12 +0200189 if (ret)
Christoph Hellwigaa45e252007-04-23 21:08:27 +0200190 return ret;
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100191 }
Luke Browninge65c2f62007-12-20 16:39:59 +0900192 }
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100193
Luke Browninge65c2f62007-12-20 16:39:59 +0900194 /*
195 * Apply special setup as required.
196 */
197 if (ctx->flags & SPU_CREATE_ISOLATE) {
Luke Browning91569532007-12-20 16:39:59 +0900198 if (!(ctx->ops->status_read(ctx) & SPU_STATUS_ISOLATED_STATE)) {
199 ret = spu_setup_isolated(ctx);
200 if (ret)
201 return ret;
202 }
203
204 /*
205 * If userspace has set the runcntrl register (eg, to
206 * issue an isolated exit), we need to re-set it here
207 */
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100208 runcntl = ctx->ops->runcntl_read(ctx) &
209 (SPU_RUNCNTL_RUNNABLE | SPU_RUNCNTL_ISOLATE);
210 if (runcntl == 0)
211 runcntl = SPU_RUNCNTL_RUNNABLE;
Christoph Hellwig2eb1b122007-02-13 21:54:29 +0100212 } else {
Luke Browningcc210b32007-12-20 16:39:59 +0900213 unsigned long privcntl;
214
Benjamin Herrenschmidt05169232007-06-04 15:15:37 +1000215 if (test_thread_flag(TIF_SINGLESTEP))
Luke Browningcc210b32007-12-20 16:39:59 +0900216 privcntl = SPU_PRIVCNTL_MODE_SINGLE_STEP;
217 else
218 privcntl = SPU_PRIVCNTL_MODE_NORMAL;
Luke Browningcc210b32007-12-20 16:39:59 +0900219
Luke Browningcc210b32007-12-20 16:39:59 +0900220 ctx->ops->privcntl_write(ctx, privcntl);
Jeremy Kerrd9dd4212008-08-13 11:29:31 +1000221 ctx->ops->npc_write(ctx, *npc);
222 }
223
224 ctx->ops->runcntl_write(ctx, runcntl);
225
226 if (ctx->flags & SPU_CREATE_NOSCHED) {
227 spuctx_switch_state(ctx, SPU_UTIL_USER);
228 } else {
Luke Browning91569532007-12-20 16:39:59 +0900229
230 if (ctx->state == SPU_STATE_SAVED) {
Luke Browning91569532007-12-20 16:39:59 +0900231 ret = spu_activate(ctx, 0);
232 if (ret)
233 return ret;
Luke Browninge65c2f62007-12-20 16:39:59 +0900234 } else {
235 spuctx_switch_state(ctx, SPU_UTIL_USER);
Luke Browning91569532007-12-20 16:39:59 +0900236 }
Christoph Hellwig2eb1b122007-02-13 21:54:29 +0100237 }
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100238
Jeremy Kerrce7c1912008-03-04 20:17:02 +1100239 set_bit(SPU_SCHED_SPU_RUN, &ctx->sched_flags);
Christoph Hellwigaa45e252007-04-23 21:08:27 +0200240 return 0;
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100241}
242
Bob Nelson36aaccc2007-07-20 21:39:52 +0200243static int spu_run_fini(struct spu_context *ctx, u32 *npc,
244 u32 *status)
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100245{
246 int ret = 0;
247
Luke Browninge65c2f62007-12-20 16:39:59 +0900248 spu_del_from_rq(ctx);
249
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100250 *status = ctx->ops->status_read(ctx);
251 *npc = ctx->ops->npc_read(ctx);
Andre Detsch27ec41d2007-07-20 21:39:33 +0200252
253 spuctx_switch_state(ctx, SPU_UTIL_IDLE_LOADED);
Jeremy Kerrce7c1912008-03-04 20:17:02 +1100254 clear_bit(SPU_SCHED_SPU_RUN, &ctx->sched_flags);
Jeremy Kerrf5ed0eb2008-10-16 10:03:46 +1100255 spu_switch_log_notify(NULL, ctx, SWITCH_LOG_EXIT, *status);
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100256 spu_release(ctx);
257
258 if (signal_pending(current))
259 ret = -ERESTARTSYS;
Masato Noguchi2ebb2472006-11-20 18:45:04 +0100260
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100261 return ret;
262}
263
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100264/*
265 * SPU syscall restarting is tricky because we violate the basic
266 * assumption that the signal handler is running on the interrupted
267 * thread. Here instead, the handler runs on PowerPC user space code,
268 * while the syscall was called from the SPU.
269 * This means we can only do a very rough approximation of POSIX
270 * signal semantics.
271 */
Sebastian Siewior12388192007-09-19 14:38:12 +1000272static int spu_handle_restartsys(struct spu_context *ctx, long *spu_ret,
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100273 unsigned int *npc)
274{
275 int ret;
276
277 switch (*spu_ret) {
278 case -ERESTARTSYS:
279 case -ERESTARTNOINTR:
280 /*
281 * Enter the regular syscall restarting for
282 * sys_spu_run, then restart the SPU syscall
283 * callback.
284 */
285 *npc -= 8;
286 ret = -ERESTARTSYS;
287 break;
288 case -ERESTARTNOHAND:
289 case -ERESTART_RESTARTBLOCK:
290 /*
291 * Restart block is too hard for now, just return -EINTR
292 * to the SPU.
293 * ERESTARTNOHAND comes from sys_pause, we also return
294 * -EINTR from there.
295 * Assume that we need to be restarted ourselves though.
296 */
297 *spu_ret = -EINTR;
298 ret = -ERESTARTSYS;
299 break;
300 default:
301 printk(KERN_WARNING "%s: unexpected return code %ld\n",
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100302 __func__, *spu_ret);
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100303 ret = 0;
304 }
305 return ret;
306}
307
Sebastian Siewior12388192007-09-19 14:38:12 +1000308static int spu_process_callback(struct spu_context *ctx)
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100309{
310 struct spu_syscall_block s;
311 u32 ls_pointer, npc;
Akinobu Mita9e2fe2c2007-04-23 21:08:22 +0200312 void __iomem *ls;
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100313 long spu_ret;
Jeremy Kerrd29694f2008-04-23 16:02:10 +1000314 int ret;
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100315
316 /* get syscall block from local store */
Akinobu Mita9e2fe2c2007-04-23 21:08:22 +0200317 npc = ctx->ops->npc_read(ctx) & ~3;
318 ls = (void __iomem *)ctx->ops->get_ls(ctx);
319 ls_pointer = in_be32(ls + npc);
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100320 if (ls_pointer > (LS_SIZE - sizeof(s)))
321 return -EFAULT;
Akinobu Mita9e2fe2c2007-04-23 21:08:22 +0200322 memcpy_fromio(&s, ls + ls_pointer, sizeof(s));
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100323
324 /* do actual syscall without pinning the spu */
325 ret = 0;
326 spu_ret = -ENOSYS;
327 npc += 4;
328
329 if (s.nr_ret < __NR_syscalls) {
330 spu_release(ctx);
331 /* do actual system call from here */
332 spu_ret = spu_sys_callback(&s);
333 if (spu_ret <= -ERESTARTSYS) {
334 ret = spu_handle_restartsys(ctx, &spu_ret, &npc);
335 }
Jeremy Kerrd29694f2008-04-23 16:02:10 +1000336 mutex_lock(&ctx->state_mutex);
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100337 if (ret == -ERESTARTSYS)
338 return ret;
339 }
340
Jeremy Kerr4eb5aef2008-03-25 13:32:03 +1100341 /* need to re-get the ls, as it may have changed when we released the
342 * spu */
343 ls = (void __iomem *)ctx->ops->get_ls(ctx);
344
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100345 /* write result, jump over indirect pointer */
Akinobu Mita9e2fe2c2007-04-23 21:08:22 +0200346 memcpy_toio(ls + ls_pointer, &spu_ret, sizeof(spu_ret));
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100347 ctx->ops->npc_write(ctx, npc);
348 ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_RUNNABLE);
349 return ret;
350}
351
Jeremy Kerr50af32a2007-07-20 21:39:42 +0200352long spufs_run_spu(struct spu_context *ctx, u32 *npc, u32 *event)
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100353{
354 int ret;
Bob Nelson36aaccc2007-07-20 21:39:52 +0200355 struct spu *spu;
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200356 u32 status;
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100357
Christoph Hellwige45d48a2007-04-23 21:08:17 +0200358 if (mutex_lock_interruptible(&ctx->run_mutex))
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100359 return -ERESTARTSYS;
360
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200361 ctx->event_return = 0;
Christoph Hellwigaa45e252007-04-23 21:08:27 +0200362
Christoph Hellwigc9101bd2007-12-20 16:39:59 +0900363 ret = spu_acquire(ctx);
364 if (ret)
365 goto out_unlock;
Christoph Hellwig2cf2b3b2007-06-29 10:57:55 +1000366
Jeremy Kerrc0bace52008-04-23 14:24:27 +1000367 spu_enable_spu(ctx);
368
Luke Browning91569532007-12-20 16:39:59 +0900369 spu_update_sched_info(ctx);
Christoph Hellwigaa45e252007-04-23 21:08:27 +0200370
371 ret = spu_run_init(ctx, npc);
372 if (ret) {
373 spu_release(ctx);
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100374 goto out;
Christoph Hellwigaa45e252007-04-23 21:08:27 +0200375 }
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100376
377 do {
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200378 ret = spufs_wait(ctx->stop_wq, spu_stopped(ctx, &status));
Christoph Hellwigeebead52008-02-08 15:50:41 +1100379 if (unlikely(ret)) {
380 /*
381 * This is nasty: we need the state_mutex for all the
382 * bookkeeping even if the syscall was interrupted by
383 * a signal. ewww.
384 */
385 mutex_lock(&ctx->state_mutex);
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100386 break;
Christoph Hellwigeebead52008-02-08 15:50:41 +1100387 }
Bob Nelson36aaccc2007-07-20 21:39:52 +0200388 spu = ctx->spu;
389 if (unlikely(test_and_clear_bit(SPU_SCHED_NOTIFY_ACTIVE,
390 &ctx->sched_flags))) {
391 if (!(status & SPU_STATUS_STOPPED_BY_STOP)) {
392 spu_switch_notify(spu, ctx);
393 continue;
394 }
395 }
Andre Detsch27ec41d2007-07-20 21:39:33 +0200396
397 spuctx_switch_state(ctx, SPU_UTIL_SYSTEM);
398
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200399 if ((status & SPU_STATUS_STOPPED_BY_STOP) &&
400 (status >> SPU_STOP_STATUS_SHIFT == 0x2104)) {
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100401 ret = spu_process_callback(ctx);
402 if (ret)
403 break;
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200404 status &= ~SPU_STATUS_STOPPED_BY_STOP;
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100405 }
Arnd Bergmann57dace22007-04-23 21:08:15 +0200406 ret = spufs_handle_class1(ctx);
407 if (ret)
408 break;
409
Jeremy Kerrd6ad39b2007-12-20 16:39:59 +0900410 ret = spufs_handle_class0(ctx);
411 if (ret)
412 break;
413
Jeremy Kerrd6ad39b2007-12-20 16:39:59 +0900414 if (signal_pending(current))
415 ret = -ERESTARTSYS;
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200416 } while (!ret && !(status & (SPU_STATUS_STOPPED_BY_STOP |
Benjamin Herrenschmidt05169232007-06-04 15:15:37 +1000417 SPU_STATUS_STOPPED_BY_HALT |
418 SPU_STATUS_SINGLE_STEP)));
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100419
Masato Noguchic25620d2007-12-05 13:49:31 +1100420 spu_disable_spu(ctx);
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200421 ret = spu_run_fini(ctx, npc, &status);
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100422 spu_yield(ctx);
423
Luke Browninge66686b42008-02-08 15:50:41 +1100424 if ((status & SPU_STATUS_STOPPED_BY_STOP) &&
425 (((status >> SPU_STOP_STATUS_SHIFT) & 0x3f00) == 0x2100))
426 ctx->stats.libassist++;
427
Masato Noguchi2ebb2472006-11-20 18:45:04 +0100428 if ((ret == 0) ||
429 ((ret == -ERESTARTSYS) &&
430 ((status & SPU_STATUS_STOPPED_BY_HALT) ||
Benjamin Herrenschmidt05169232007-06-04 15:15:37 +1000431 (status & SPU_STATUS_SINGLE_STEP) ||
Masato Noguchi2ebb2472006-11-20 18:45:04 +0100432 ((status & SPU_STATUS_STOPPED_BY_STOP) &&
433 (status >> SPU_STOP_STATUS_SHIFT != 0x2104)))))
434 ret = status;
435
Benjamin Herrenschmidt05169232007-06-04 15:15:37 +1000436 /* Note: we don't need to force_sig SIGTRAP on single-step
437 * since we have TIF_SINGLESTEP set, thus the kernel will do
438 * it upon return from the syscall anyawy
439 */
Jeremy Kerr60cf54d2008-01-11 15:03:26 +1100440 if (unlikely(status & SPU_STATUS_SINGLE_STEP))
441 ret = -ERESTARTSYS;
442
443 else if (unlikely((status & SPU_STATUS_STOPPED_BY_STOP)
444 && (status >> SPU_STOP_STATUS_SHIFT) == 0x3fff)) {
Arnd Bergmannc2b22262006-11-27 19:18:53 +0100445 force_sig(SIGTRAP, current);
446 ret = -ERESTARTSYS;
Masato Noguchi2ebb2472006-11-20 18:45:04 +0100447 }
448
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100449out:
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200450 *event = ctx->event_return;
Christoph Hellwigc9101bd2007-12-20 16:39:59 +0900451out_unlock:
Christoph Hellwige45d48a2007-04-23 21:08:17 +0200452 mutex_unlock(&ctx->run_mutex);
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100453 return ret;
454}