blob: f7edba6cb795d55944009cc376ff171cdddefa09 [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
120 /* put the SPE in kernel mode to allow access to the loader */
121 sr1 = spu_mfc_sr1_get(ctx->spu);
122 sr1 &= ~MFC_STATE1_PROBLEM_STATE_MASK;
123 spu_mfc_sr1_set(ctx->spu, sr1);
124
125 /* start the loader */
126 ctx->ops->signal1_write(ctx, (unsigned long)isolated_loader >> 32);
127 ctx->ops->signal2_write(ctx,
128 (unsigned long)isolated_loader & 0xffffffff);
129
130 ctx->ops->runcntl_write(ctx,
131 SPU_RUNCNTL_RUNNABLE | SPU_RUNCNTL_ISOLATE);
132
133 ret = 0;
134 timeout = jiffies + HZ;
135 while (((status = ctx->ops->status_read(ctx)) & status_loading) ==
136 status_loading) {
137 if (time_after(jiffies, timeout)) {
138 printk(KERN_ERR "%s: timeout waiting for loader\n",
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100139 __func__);
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100140 ret = -EIO;
141 goto out_drop_priv;
142 }
143 cond_resched();
144 }
145
146 if (!(status & SPU_STATUS_RUNNING)) {
147 /* If isolated LOAD has failed: run SPU, we will get a stop-and
148 * signal later. */
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100149 pr_debug("%s: isolated LOAD failed\n", __func__);
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100150 ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_RUNNABLE);
151 ret = -EACCES;
Christoph Hellwig7ec18ab2007-04-23 21:08:12 +0200152 goto out_drop_priv;
153 }
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100154
Christoph Hellwig7ec18ab2007-04-23 21:08:12 +0200155 if (!(status & SPU_STATUS_ISOLATED_STATE)) {
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100156 /* This isn't allowed by the CBEA, but check anyway */
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100157 pr_debug("%s: SPU fell out of isolated mode?\n", __func__);
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100158 ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_STOP);
159 ret = -EINVAL;
Christoph Hellwig7ec18ab2007-04-23 21:08:12 +0200160 goto out_drop_priv;
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100161 }
162
163out_drop_priv:
164 /* Finished accessing the loader. Drop kernel mode */
165 sr1 |= MFC_STATE1_PROBLEM_STATE_MASK;
166 spu_mfc_sr1_set(ctx->spu, sr1);
167
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100168out:
169 return ret;
170}
171
Bob Nelson36aaccc2007-07-20 21:39:52 +0200172static int spu_run_init(struct spu_context *ctx, u32 *npc)
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100173{
Luke Browninge65c2f62007-12-20 16:39:59 +0900174 unsigned long runcntl = SPU_RUNCNTL_RUNNABLE;
Luke Browning91569532007-12-20 16:39:59 +0900175 int ret;
Luke Browningcc210b32007-12-20 16:39:59 +0900176
Andre Detsch27ec41d2007-07-20 21:39:33 +0200177 spuctx_switch_state(ctx, SPU_UTIL_SYSTEM);
178
Luke Browninge65c2f62007-12-20 16:39:59 +0900179 /*
180 * NOSCHED is synchronous scheduling with respect to the caller.
181 * The caller waits for the context to be loaded.
182 */
183 if (ctx->flags & SPU_CREATE_NOSCHED) {
Luke Browning91569532007-12-20 16:39:59 +0900184 if (ctx->state == SPU_STATE_SAVED) {
Luke Browning91569532007-12-20 16:39:59 +0900185 ret = spu_activate(ctx, 0);
Christoph Hellwig7ec18ab2007-04-23 21:08:12 +0200186 if (ret)
Christoph Hellwigaa45e252007-04-23 21:08:27 +0200187 return ret;
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100188 }
Luke Browninge65c2f62007-12-20 16:39:59 +0900189 }
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100190
Luke Browninge65c2f62007-12-20 16:39:59 +0900191 /*
192 * Apply special setup as required.
193 */
194 if (ctx->flags & SPU_CREATE_ISOLATE) {
Luke Browning91569532007-12-20 16:39:59 +0900195 if (!(ctx->ops->status_read(ctx) & SPU_STATUS_ISOLATED_STATE)) {
196 ret = spu_setup_isolated(ctx);
197 if (ret)
198 return ret;
199 }
200
201 /*
202 * If userspace has set the runcntrl register (eg, to
203 * issue an isolated exit), we need to re-set it here
204 */
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100205 runcntl = ctx->ops->runcntl_read(ctx) &
206 (SPU_RUNCNTL_RUNNABLE | SPU_RUNCNTL_ISOLATE);
207 if (runcntl == 0)
208 runcntl = SPU_RUNCNTL_RUNNABLE;
Luke Browninge65c2f62007-12-20 16:39:59 +0900209 }
Luke Browning91569532007-12-20 16:39:59 +0900210
Luke Browninge65c2f62007-12-20 16:39:59 +0900211 if (ctx->flags & SPU_CREATE_NOSCHED) {
Luke Browning91569532007-12-20 16:39:59 +0900212 spuctx_switch_state(ctx, SPU_UTIL_USER);
213 ctx->ops->runcntl_write(ctx, runcntl);
Christoph Hellwig2eb1b122007-02-13 21:54:29 +0100214 } else {
Luke Browningcc210b32007-12-20 16:39:59 +0900215 unsigned long privcntl;
216
Benjamin Herrenschmidt05169232007-06-04 15:15:37 +1000217 if (test_thread_flag(TIF_SINGLESTEP))
Luke Browningcc210b32007-12-20 16:39:59 +0900218 privcntl = SPU_PRIVCNTL_MODE_SINGLE_STEP;
219 else
220 privcntl = SPU_PRIVCNTL_MODE_NORMAL;
Luke Browningcc210b32007-12-20 16:39:59 +0900221
222 ctx->ops->npc_write(ctx, *npc);
223 ctx->ops->privcntl_write(ctx, privcntl);
Luke Browninge65c2f62007-12-20 16:39:59 +0900224 ctx->ops->runcntl_write(ctx, runcntl);
Luke Browning91569532007-12-20 16:39:59 +0900225
226 if (ctx->state == SPU_STATE_SAVED) {
Luke Browning91569532007-12-20 16:39:59 +0900227 ret = spu_activate(ctx, 0);
228 if (ret)
229 return ret;
Luke Browninge65c2f62007-12-20 16:39:59 +0900230 } else {
231 spuctx_switch_state(ctx, SPU_UTIL_USER);
Luke Browning91569532007-12-20 16:39:59 +0900232 }
Christoph Hellwig2eb1b122007-02-13 21:54:29 +0100233 }
Jeremy Kerrc6730ed2006-11-20 18:45:10 +0100234
Jeremy Kerrce7c1912008-03-04 20:17:02 +1100235 set_bit(SPU_SCHED_SPU_RUN, &ctx->sched_flags);
Christoph Hellwigaa45e252007-04-23 21:08:27 +0200236 return 0;
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100237}
238
Bob Nelson36aaccc2007-07-20 21:39:52 +0200239static int spu_run_fini(struct spu_context *ctx, u32 *npc,
240 u32 *status)
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100241{
242 int ret = 0;
243
Luke Browninge65c2f62007-12-20 16:39:59 +0900244 spu_del_from_rq(ctx);
245
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100246 *status = ctx->ops->status_read(ctx);
247 *npc = ctx->ops->npc_read(ctx);
Andre Detsch27ec41d2007-07-20 21:39:33 +0200248
249 spuctx_switch_state(ctx, SPU_UTIL_IDLE_LOADED);
Jeremy Kerrce7c1912008-03-04 20:17:02 +1100250 clear_bit(SPU_SCHED_SPU_RUN, &ctx->sched_flags);
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100251 spu_release(ctx);
252
253 if (signal_pending(current))
254 ret = -ERESTARTSYS;
Masato Noguchi2ebb2472006-11-20 18:45:04 +0100255
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100256 return ret;
257}
258
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100259/*
260 * SPU syscall restarting is tricky because we violate the basic
261 * assumption that the signal handler is running on the interrupted
262 * thread. Here instead, the handler runs on PowerPC user space code,
263 * while the syscall was called from the SPU.
264 * This means we can only do a very rough approximation of POSIX
265 * signal semantics.
266 */
Sebastian Siewior12388192007-09-19 14:38:12 +1000267static int spu_handle_restartsys(struct spu_context *ctx, long *spu_ret,
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100268 unsigned int *npc)
269{
270 int ret;
271
272 switch (*spu_ret) {
273 case -ERESTARTSYS:
274 case -ERESTARTNOINTR:
275 /*
276 * Enter the regular syscall restarting for
277 * sys_spu_run, then restart the SPU syscall
278 * callback.
279 */
280 *npc -= 8;
281 ret = -ERESTARTSYS;
282 break;
283 case -ERESTARTNOHAND:
284 case -ERESTART_RESTARTBLOCK:
285 /*
286 * Restart block is too hard for now, just return -EINTR
287 * to the SPU.
288 * ERESTARTNOHAND comes from sys_pause, we also return
289 * -EINTR from there.
290 * Assume that we need to be restarted ourselves though.
291 */
292 *spu_ret = -EINTR;
293 ret = -ERESTARTSYS;
294 break;
295 default:
296 printk(KERN_WARNING "%s: unexpected return code %ld\n",
Harvey Harrisone48b1b42008-03-29 08:21:07 +1100297 __func__, *spu_ret);
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100298 ret = 0;
299 }
300 return ret;
301}
302
Sebastian Siewior12388192007-09-19 14:38:12 +1000303static int spu_process_callback(struct spu_context *ctx)
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100304{
305 struct spu_syscall_block s;
306 u32 ls_pointer, npc;
Akinobu Mita9e2fe2c2007-04-23 21:08:22 +0200307 void __iomem *ls;
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100308 long spu_ret;
Jeremy Kerrd29694f2008-04-23 16:02:10 +1000309 int ret;
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100310
311 /* get syscall block from local store */
Akinobu Mita9e2fe2c2007-04-23 21:08:22 +0200312 npc = ctx->ops->npc_read(ctx) & ~3;
313 ls = (void __iomem *)ctx->ops->get_ls(ctx);
314 ls_pointer = in_be32(ls + npc);
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100315 if (ls_pointer > (LS_SIZE - sizeof(s)))
316 return -EFAULT;
Akinobu Mita9e2fe2c2007-04-23 21:08:22 +0200317 memcpy_fromio(&s, ls + ls_pointer, sizeof(s));
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100318
319 /* do actual syscall without pinning the spu */
320 ret = 0;
321 spu_ret = -ENOSYS;
322 npc += 4;
323
324 if (s.nr_ret < __NR_syscalls) {
325 spu_release(ctx);
326 /* do actual system call from here */
327 spu_ret = spu_sys_callback(&s);
328 if (spu_ret <= -ERESTARTSYS) {
329 ret = spu_handle_restartsys(ctx, &spu_ret, &npc);
330 }
Jeremy Kerrd29694f2008-04-23 16:02:10 +1000331 mutex_lock(&ctx->state_mutex);
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100332 if (ret == -ERESTARTSYS)
333 return ret;
334 }
335
Jeremy Kerr4eb5aef2008-03-25 13:32:03 +1100336 /* need to re-get the ls, as it may have changed when we released the
337 * spu */
338 ls = (void __iomem *)ctx->ops->get_ls(ctx);
339
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100340 /* write result, jump over indirect pointer */
Akinobu Mita9e2fe2c2007-04-23 21:08:22 +0200341 memcpy_toio(ls + ls_pointer, &spu_ret, sizeof(spu_ret));
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100342 ctx->ops->npc_write(ctx, npc);
343 ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_RUNNABLE);
344 return ret;
345}
346
Jeremy Kerr50af32a2007-07-20 21:39:42 +0200347long spufs_run_spu(struct spu_context *ctx, u32 *npc, u32 *event)
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100348{
349 int ret;
Bob Nelson36aaccc2007-07-20 21:39:52 +0200350 struct spu *spu;
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200351 u32 status;
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100352
Christoph Hellwige45d48a2007-04-23 21:08:17 +0200353 if (mutex_lock_interruptible(&ctx->run_mutex))
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100354 return -ERESTARTSYS;
355
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200356 ctx->event_return = 0;
Christoph Hellwigaa45e252007-04-23 21:08:27 +0200357
Christoph Hellwigc9101bd2007-12-20 16:39:59 +0900358 ret = spu_acquire(ctx);
359 if (ret)
360 goto out_unlock;
Christoph Hellwig2cf2b3b2007-06-29 10:57:55 +1000361
Jeremy Kerrc0bace52008-04-23 14:24:27 +1000362 spu_enable_spu(ctx);
363
Luke Browning91569532007-12-20 16:39:59 +0900364 spu_update_sched_info(ctx);
Christoph Hellwigaa45e252007-04-23 21:08:27 +0200365
366 ret = spu_run_init(ctx, npc);
367 if (ret) {
368 spu_release(ctx);
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100369 goto out;
Christoph Hellwigaa45e252007-04-23 21:08:27 +0200370 }
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100371
372 do {
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200373 ret = spufs_wait(ctx->stop_wq, spu_stopped(ctx, &status));
Christoph Hellwigeebead52008-02-08 15:50:41 +1100374 if (unlikely(ret)) {
375 /*
376 * This is nasty: we need the state_mutex for all the
377 * bookkeeping even if the syscall was interrupted by
378 * a signal. ewww.
379 */
380 mutex_lock(&ctx->state_mutex);
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100381 break;
Christoph Hellwigeebead52008-02-08 15:50:41 +1100382 }
Bob Nelson36aaccc2007-07-20 21:39:52 +0200383 spu = ctx->spu;
384 if (unlikely(test_and_clear_bit(SPU_SCHED_NOTIFY_ACTIVE,
385 &ctx->sched_flags))) {
386 if (!(status & SPU_STATUS_STOPPED_BY_STOP)) {
387 spu_switch_notify(spu, ctx);
388 continue;
389 }
390 }
Andre Detsch27ec41d2007-07-20 21:39:33 +0200391
392 spuctx_switch_state(ctx, SPU_UTIL_SYSTEM);
393
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200394 if ((status & SPU_STATUS_STOPPED_BY_STOP) &&
395 (status >> SPU_STOP_STATUS_SHIFT == 0x2104)) {
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100396 ret = spu_process_callback(ctx);
397 if (ret)
398 break;
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200399 status &= ~SPU_STATUS_STOPPED_BY_STOP;
Arnd Bergmann2dd14932006-03-23 00:00:09 +0100400 }
Arnd Bergmann57dace22007-04-23 21:08:15 +0200401 ret = spufs_handle_class1(ctx);
402 if (ret)
403 break;
404
Jeremy Kerrd6ad39b2007-12-20 16:39:59 +0900405 ret = spufs_handle_class0(ctx);
406 if (ret)
407 break;
408
Jeremy Kerrd6ad39b2007-12-20 16:39:59 +0900409 if (signal_pending(current))
410 ret = -ERESTARTSYS;
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200411 } while (!ret && !(status & (SPU_STATUS_STOPPED_BY_STOP |
Benjamin Herrenschmidt05169232007-06-04 15:15:37 +1000412 SPU_STATUS_STOPPED_BY_HALT |
413 SPU_STATUS_SINGLE_STEP)));
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100414
Masato Noguchic25620d2007-12-05 13:49:31 +1100415 spu_disable_spu(ctx);
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200416 ret = spu_run_fini(ctx, npc, &status);
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100417 spu_yield(ctx);
418
Christoph Hellwig5158e9b2008-04-29 17:08:38 +1000419 spu_switch_log_notify(NULL, ctx, SWITCH_LOG_EXIT, status);
420
Luke Browninge66686b42008-02-08 15:50:41 +1100421 if ((status & SPU_STATUS_STOPPED_BY_STOP) &&
422 (((status >> SPU_STOP_STATUS_SHIFT) & 0x3f00) == 0x2100))
423 ctx->stats.libassist++;
424
Masato Noguchi2ebb2472006-11-20 18:45:04 +0100425 if ((ret == 0) ||
426 ((ret == -ERESTARTSYS) &&
427 ((status & SPU_STATUS_STOPPED_BY_HALT) ||
Benjamin Herrenschmidt05169232007-06-04 15:15:37 +1000428 (status & SPU_STATUS_SINGLE_STEP) ||
Masato Noguchi2ebb2472006-11-20 18:45:04 +0100429 ((status & SPU_STATUS_STOPPED_BY_STOP) &&
430 (status >> SPU_STOP_STATUS_SHIFT != 0x2104)))))
431 ret = status;
432
Benjamin Herrenschmidt05169232007-06-04 15:15:37 +1000433 /* Note: we don't need to force_sig SIGTRAP on single-step
434 * since we have TIF_SINGLESTEP set, thus the kernel will do
435 * it upon return from the syscall anyawy
436 */
Jeremy Kerr60cf54d2008-01-11 15:03:26 +1100437 if (unlikely(status & SPU_STATUS_SINGLE_STEP))
438 ret = -ERESTARTSYS;
439
440 else if (unlikely((status & SPU_STATUS_STOPPED_BY_STOP)
441 && (status >> SPU_STOP_STATUS_SHIFT) == 0x3fff)) {
Arnd Bergmannc2b22262006-11-27 19:18:53 +0100442 force_sig(SIGTRAP, current);
443 ret = -ERESTARTSYS;
Masato Noguchi2ebb2472006-11-20 18:45:04 +0100444 }
445
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100446out:
Arnd Bergmann9add11d2006-10-04 17:26:14 +0200447 *event = ctx->event_return;
Christoph Hellwigc9101bd2007-12-20 16:39:59 +0900448out_unlock:
Christoph Hellwige45d48a2007-04-23 21:08:17 +0200449 mutex_unlock(&ctx->run_mutex);
Arnd Bergmannce8ab852006-01-04 20:31:29 +0100450 return ret;
451}