10afacde3Sarnd@arndb.de #define DEBUG
20afacde3Sarnd@arndb.de 
3ce8ab854SArnd Bergmann #include <linux/wait.h>
4ce8ab854SArnd Bergmann #include <linux/ptrace.h>
5ce8ab854SArnd Bergmann 
6ce8ab854SArnd Bergmann #include <asm/spu.h>
7c6730ed4SJeremy Kerr #include <asm/spu_priv1.h>
8c6730ed4SJeremy Kerr #include <asm/io.h>
9cfff5b23SDave Jones #include <asm/unistd.h>
10ce8ab854SArnd Bergmann 
11ce8ab854SArnd Bergmann #include "spufs.h"
12ce8ab854SArnd Bergmann 
13ce8ab854SArnd Bergmann /* interrupt-level stop callback function. */
14ce8ab854SArnd Bergmann void spufs_stop_callback(struct spu *spu)
15ce8ab854SArnd Bergmann {
16ce8ab854SArnd Bergmann 	struct spu_context *ctx = spu->ctx;
17ce8ab854SArnd Bergmann 
18ce8ab854SArnd Bergmann 	wake_up_all(&ctx->stop_wq);
19ce8ab854SArnd Bergmann }
20ce8ab854SArnd Bergmann 
21ce8ab854SArnd Bergmann static inline int spu_stopped(struct spu_context *ctx, u32 * stat)
22ce8ab854SArnd Bergmann {
23ce8ab854SArnd Bergmann 	struct spu *spu;
24ce8ab854SArnd Bergmann 	u64 pte_fault;
25ce8ab854SArnd Bergmann 
26ce8ab854SArnd Bergmann 	*stat = ctx->ops->status_read(ctx);
27ce8ab854SArnd Bergmann 	if (ctx->state != SPU_STATE_RUNNABLE)
28ce8ab854SArnd Bergmann 		return 1;
29ce8ab854SArnd Bergmann 	spu = ctx->spu;
30ce8ab854SArnd Bergmann 	pte_fault = spu->dsisr &
31ce8ab854SArnd Bergmann 	    (MFC_DSISR_PTE_NOT_FOUND | MFC_DSISR_ACCESS_DENIED);
32ce8ab854SArnd Bergmann 	return (!(*stat & 0x1) || pte_fault || spu->class_0_pending) ? 1 : 0;
33ce8ab854SArnd Bergmann }
34ce8ab854SArnd Bergmann 
35c6730ed4SJeremy Kerr static int spu_setup_isolated(struct spu_context *ctx)
36c6730ed4SJeremy Kerr {
37c6730ed4SJeremy Kerr 	int ret;
38c6730ed4SJeremy Kerr 	u64 __iomem *mfc_cntl;
39c6730ed4SJeremy Kerr 	u64 sr1;
40c6730ed4SJeremy Kerr 	u32 status;
41c6730ed4SJeremy Kerr 	unsigned long timeout;
42c6730ed4SJeremy Kerr 	const u32 status_loading = SPU_STATUS_RUNNING
43c6730ed4SJeremy Kerr 		| SPU_STATUS_ISOLATED_STATE | SPU_STATUS_ISOLATED_LOAD_STATUS;
44c6730ed4SJeremy Kerr 
457ec18ab9SChristoph Hellwig 	ret = -ENODEV;
46c6730ed4SJeremy Kerr 	if (!isolated_loader)
47c6730ed4SJeremy Kerr 		goto out;
48c6730ed4SJeremy Kerr 
497ec18ab9SChristoph Hellwig 	/*
507ec18ab9SChristoph Hellwig 	 * We need to exclude userspace access to the context.
517ec18ab9SChristoph Hellwig 	 *
527ec18ab9SChristoph Hellwig 	 * To protect against memory access we invalidate all ptes
537ec18ab9SChristoph Hellwig 	 * and make sure the pagefault handlers block on the mutex.
547ec18ab9SChristoph Hellwig 	 */
557ec18ab9SChristoph Hellwig 	spu_unmap_mappings(ctx);
567ec18ab9SChristoph Hellwig 
57c6730ed4SJeremy Kerr 	mfc_cntl = &ctx->spu->priv2->mfc_control_RW;
58c6730ed4SJeremy Kerr 
59c6730ed4SJeremy Kerr 	/* purge the MFC DMA queue to ensure no spurious accesses before we
60c6730ed4SJeremy Kerr 	 * enter kernel mode */
61c6730ed4SJeremy Kerr 	timeout = jiffies + HZ;
62c6730ed4SJeremy Kerr 	out_be64(mfc_cntl, MFC_CNTL_PURGE_DMA_REQUEST);
63c6730ed4SJeremy Kerr 	while ((in_be64(mfc_cntl) & MFC_CNTL_PURGE_DMA_STATUS_MASK)
64c6730ed4SJeremy Kerr 			!= MFC_CNTL_PURGE_DMA_COMPLETE) {
65c6730ed4SJeremy Kerr 		if (time_after(jiffies, timeout)) {
66c6730ed4SJeremy Kerr 			printk(KERN_ERR "%s: timeout flushing MFC DMA queue\n",
67c6730ed4SJeremy Kerr 					__FUNCTION__);
68c6730ed4SJeremy Kerr 			ret = -EIO;
697ec18ab9SChristoph Hellwig 			goto out;
70c6730ed4SJeremy Kerr 		}
71c6730ed4SJeremy Kerr 		cond_resched();
72c6730ed4SJeremy Kerr 	}
73c6730ed4SJeremy Kerr 
74c6730ed4SJeremy Kerr 	/* put the SPE in kernel mode to allow access to the loader */
75c6730ed4SJeremy Kerr 	sr1 = spu_mfc_sr1_get(ctx->spu);
76c6730ed4SJeremy Kerr 	sr1 &= ~MFC_STATE1_PROBLEM_STATE_MASK;
77c6730ed4SJeremy Kerr 	spu_mfc_sr1_set(ctx->spu, sr1);
78c6730ed4SJeremy Kerr 
79c6730ed4SJeremy Kerr 	/* start the loader */
80c6730ed4SJeremy Kerr 	ctx->ops->signal1_write(ctx, (unsigned long)isolated_loader >> 32);
81c6730ed4SJeremy Kerr 	ctx->ops->signal2_write(ctx,
82c6730ed4SJeremy Kerr 			(unsigned long)isolated_loader & 0xffffffff);
83c6730ed4SJeremy Kerr 
84c6730ed4SJeremy Kerr 	ctx->ops->runcntl_write(ctx,
85c6730ed4SJeremy Kerr 			SPU_RUNCNTL_RUNNABLE | SPU_RUNCNTL_ISOLATE);
86c6730ed4SJeremy Kerr 
87c6730ed4SJeremy Kerr 	ret = 0;
88c6730ed4SJeremy Kerr 	timeout = jiffies + HZ;
89c6730ed4SJeremy Kerr 	while (((status = ctx->ops->status_read(ctx)) & status_loading) ==
90c6730ed4SJeremy Kerr 				status_loading) {
91c6730ed4SJeremy Kerr 		if (time_after(jiffies, timeout)) {
92c6730ed4SJeremy Kerr 			printk(KERN_ERR "%s: timeout waiting for loader\n",
93c6730ed4SJeremy Kerr 					__FUNCTION__);
94c6730ed4SJeremy Kerr 			ret = -EIO;
95c6730ed4SJeremy Kerr 			goto out_drop_priv;
96c6730ed4SJeremy Kerr 		}
97c6730ed4SJeremy Kerr 		cond_resched();
98c6730ed4SJeremy Kerr 	}
99c6730ed4SJeremy Kerr 
100c6730ed4SJeremy Kerr 	if (!(status & SPU_STATUS_RUNNING)) {
101c6730ed4SJeremy Kerr 		/* If isolated LOAD has failed: run SPU, we will get a stop-and
102c6730ed4SJeremy Kerr 		 * signal later. */
103c6730ed4SJeremy Kerr 		pr_debug("%s: isolated LOAD failed\n", __FUNCTION__);
104c6730ed4SJeremy Kerr 		ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_RUNNABLE);
105c6730ed4SJeremy Kerr 		ret = -EACCES;
1067ec18ab9SChristoph Hellwig 		goto out_drop_priv;
1077ec18ab9SChristoph Hellwig 	}
108c6730ed4SJeremy Kerr 
1097ec18ab9SChristoph Hellwig 	if (!(status & SPU_STATUS_ISOLATED_STATE)) {
110c6730ed4SJeremy Kerr 		/* This isn't allowed by the CBEA, but check anyway */
111c6730ed4SJeremy Kerr 		pr_debug("%s: SPU fell out of isolated mode?\n", __FUNCTION__);
112c6730ed4SJeremy Kerr 		ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_STOP);
113c6730ed4SJeremy Kerr 		ret = -EINVAL;
1147ec18ab9SChristoph Hellwig 		goto out_drop_priv;
115c6730ed4SJeremy Kerr 	}
116c6730ed4SJeremy Kerr 
117c6730ed4SJeremy Kerr out_drop_priv:
118c6730ed4SJeremy Kerr 	/* Finished accessing the loader. Drop kernel mode */
119c6730ed4SJeremy Kerr 	sr1 |= MFC_STATE1_PROBLEM_STATE_MASK;
120c6730ed4SJeremy Kerr 	spu_mfc_sr1_set(ctx->spu, sr1);
121c6730ed4SJeremy Kerr 
122c6730ed4SJeremy Kerr out:
123c6730ed4SJeremy Kerr 	return ret;
124c6730ed4SJeremy Kerr }
125c6730ed4SJeremy Kerr 
126aa45e256SChristoph Hellwig static int spu_run_init(struct spu_context *ctx, u32 * npc)
127ce8ab854SArnd Bergmann {
128aa45e256SChristoph Hellwig 	if (ctx->flags & SPU_CREATE_ISOLATE) {
129aa45e256SChristoph Hellwig 		unsigned long runcntl;
130ce8ab854SArnd Bergmann 
131aa45e256SChristoph Hellwig 		if (!(ctx->ops->status_read(ctx) & SPU_STATUS_ISOLATED_STATE)) {
132aa45e256SChristoph Hellwig 			int ret = spu_setup_isolated(ctx);
133c6730ed4SJeremy Kerr 			if (ret)
134ce8ab854SArnd Bergmann 				return ret;
1350afacde3Sarnd@arndb.de 		}
136c6730ed4SJeremy Kerr 
137c6730ed4SJeremy Kerr 		/* if userspace has set the runcntrl register (eg, to issue an
138c6730ed4SJeremy Kerr 		 * isolated exit), we need to re-set it here */
139c6730ed4SJeremy Kerr 		runcntl = ctx->ops->runcntl_read(ctx) &
140c6730ed4SJeremy Kerr 			(SPU_RUNCNTL_RUNNABLE | SPU_RUNCNTL_ISOLATE);
141c6730ed4SJeremy Kerr 		if (runcntl == 0)
142c6730ed4SJeremy Kerr 			runcntl = SPU_RUNCNTL_RUNNABLE;
143aa45e256SChristoph Hellwig 		ctx->ops->runcntl_write(ctx, runcntl);
1442eb1b120SChristoph Hellwig 	} else {
1452eb1b120SChristoph Hellwig 		spu_start_tick(ctx);
146c6730ed4SJeremy Kerr 		ctx->ops->npc_write(ctx, *npc);
147aa45e256SChristoph Hellwig 		ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_RUNNABLE);
1482eb1b120SChristoph Hellwig 	}
149c6730ed4SJeremy Kerr 
150aa45e256SChristoph Hellwig 	return 0;
151ce8ab854SArnd Bergmann }
152ce8ab854SArnd Bergmann 
153aa45e256SChristoph Hellwig static int spu_run_fini(struct spu_context *ctx, u32 * npc,
154ce8ab854SArnd Bergmann 			       u32 * status)
155ce8ab854SArnd Bergmann {
156ce8ab854SArnd Bergmann 	int ret = 0;
157ce8ab854SArnd Bergmann 
1582eb1b120SChristoph Hellwig 	spu_stop_tick(ctx);
159ce8ab854SArnd Bergmann 	*status = ctx->ops->status_read(ctx);
160ce8ab854SArnd Bergmann 	*npc = ctx->ops->npc_read(ctx);
161ce8ab854SArnd Bergmann 	spu_release(ctx);
162ce8ab854SArnd Bergmann 
163ce8ab854SArnd Bergmann 	if (signal_pending(current))
164ce8ab854SArnd Bergmann 		ret = -ERESTARTSYS;
1652ebb2477SMasato Noguchi 
166ce8ab854SArnd Bergmann 	return ret;
167ce8ab854SArnd Bergmann }
168ce8ab854SArnd Bergmann 
169aa45e256SChristoph Hellwig static int spu_reacquire_runnable(struct spu_context *ctx, u32 *npc,
170ce8ab854SArnd Bergmann 				         u32 *status)
171ce8ab854SArnd Bergmann {
172ce8ab854SArnd Bergmann 	int ret;
173ce8ab854SArnd Bergmann 
174aa45e256SChristoph Hellwig 	ret = spu_run_fini(ctx, npc, status);
175aa45e256SChristoph Hellwig 	if (ret)
176ce8ab854SArnd Bergmann 		return ret;
177aa45e256SChristoph Hellwig 
178aa45e256SChristoph Hellwig 	if (*status & (SPU_STATUS_STOPPED_BY_STOP | SPU_STATUS_STOPPED_BY_HALT))
179ce8ab854SArnd Bergmann 		return *status;
180aa45e256SChristoph Hellwig 
181aa45e256SChristoph Hellwig 	ret = spu_acquire_runnable(ctx, 0);
182aa45e256SChristoph Hellwig 	if (ret)
183ce8ab854SArnd Bergmann 		return ret;
184aa45e256SChristoph Hellwig 
185aa45e256SChristoph Hellwig 	ret = spu_run_init(ctx, npc);
186aa45e256SChristoph Hellwig 	if (ret) {
187aa45e256SChristoph Hellwig 		spu_release(ctx);
188aa45e256SChristoph Hellwig 		return ret;
189aa45e256SChristoph Hellwig 	}
190ce8ab854SArnd Bergmann 	return 0;
191ce8ab854SArnd Bergmann }
192ce8ab854SArnd Bergmann 
1932dd14934SArnd Bergmann /*
1942dd14934SArnd Bergmann  * SPU syscall restarting is tricky because we violate the basic
1952dd14934SArnd Bergmann  * assumption that the signal handler is running on the interrupted
1962dd14934SArnd Bergmann  * thread. Here instead, the handler runs on PowerPC user space code,
1972dd14934SArnd Bergmann  * while the syscall was called from the SPU.
1982dd14934SArnd Bergmann  * This means we can only do a very rough approximation of POSIX
1992dd14934SArnd Bergmann  * signal semantics.
2002dd14934SArnd Bergmann  */
2012dd14934SArnd Bergmann int spu_handle_restartsys(struct spu_context *ctx, long *spu_ret,
2022dd14934SArnd Bergmann 			  unsigned int *npc)
2032dd14934SArnd Bergmann {
2042dd14934SArnd Bergmann 	int ret;
2052dd14934SArnd Bergmann 
2062dd14934SArnd Bergmann 	switch (*spu_ret) {
2072dd14934SArnd Bergmann 	case -ERESTARTSYS:
2082dd14934SArnd Bergmann 	case -ERESTARTNOINTR:
2092dd14934SArnd Bergmann 		/*
2102dd14934SArnd Bergmann 		 * Enter the regular syscall restarting for
2112dd14934SArnd Bergmann 		 * sys_spu_run, then restart the SPU syscall
2122dd14934SArnd Bergmann 		 * callback.
2132dd14934SArnd Bergmann 		 */
2142dd14934SArnd Bergmann 		*npc -= 8;
2152dd14934SArnd Bergmann 		ret = -ERESTARTSYS;
2162dd14934SArnd Bergmann 		break;
2172dd14934SArnd Bergmann 	case -ERESTARTNOHAND:
2182dd14934SArnd Bergmann 	case -ERESTART_RESTARTBLOCK:
2192dd14934SArnd Bergmann 		/*
2202dd14934SArnd Bergmann 		 * Restart block is too hard for now, just return -EINTR
2212dd14934SArnd Bergmann 		 * to the SPU.
2222dd14934SArnd Bergmann 		 * ERESTARTNOHAND comes from sys_pause, we also return
2232dd14934SArnd Bergmann 		 * -EINTR from there.
2242dd14934SArnd Bergmann 		 * Assume that we need to be restarted ourselves though.
2252dd14934SArnd Bergmann 		 */
2262dd14934SArnd Bergmann 		*spu_ret = -EINTR;
2272dd14934SArnd Bergmann 		ret = -ERESTARTSYS;
2282dd14934SArnd Bergmann 		break;
2292dd14934SArnd Bergmann 	default:
2302dd14934SArnd Bergmann 		printk(KERN_WARNING "%s: unexpected return code %ld\n",
2312dd14934SArnd Bergmann 			__FUNCTION__, *spu_ret);
2322dd14934SArnd Bergmann 		ret = 0;
2332dd14934SArnd Bergmann 	}
2342dd14934SArnd Bergmann 	return ret;
2352dd14934SArnd Bergmann }
2362dd14934SArnd Bergmann 
2372dd14934SArnd Bergmann int spu_process_callback(struct spu_context *ctx)
2382dd14934SArnd Bergmann {
2392dd14934SArnd Bergmann 	struct spu_syscall_block s;
2402dd14934SArnd Bergmann 	u32 ls_pointer, npc;
2419e2fe2ceSAkinobu Mita 	void __iomem *ls;
2422dd14934SArnd Bergmann 	long spu_ret;
2432dd14934SArnd Bergmann 	int ret;
2442dd14934SArnd Bergmann 
2452dd14934SArnd Bergmann 	/* get syscall block from local store */
2469e2fe2ceSAkinobu Mita 	npc = ctx->ops->npc_read(ctx) & ~3;
2479e2fe2ceSAkinobu Mita 	ls = (void __iomem *)ctx->ops->get_ls(ctx);
2489e2fe2ceSAkinobu Mita 	ls_pointer = in_be32(ls + npc);
2492dd14934SArnd Bergmann 	if (ls_pointer > (LS_SIZE - sizeof(s)))
2502dd14934SArnd Bergmann 		return -EFAULT;
2519e2fe2ceSAkinobu Mita 	memcpy_fromio(&s, ls + ls_pointer, sizeof(s));
2522dd14934SArnd Bergmann 
2532dd14934SArnd Bergmann 	/* do actual syscall without pinning the spu */
2542dd14934SArnd Bergmann 	ret = 0;
2552dd14934SArnd Bergmann 	spu_ret = -ENOSYS;
2562dd14934SArnd Bergmann 	npc += 4;
2572dd14934SArnd Bergmann 
2582dd14934SArnd Bergmann 	if (s.nr_ret < __NR_syscalls) {
2592dd14934SArnd Bergmann 		spu_release(ctx);
2602dd14934SArnd Bergmann 		/* do actual system call from here */
2612dd14934SArnd Bergmann 		spu_ret = spu_sys_callback(&s);
2622dd14934SArnd Bergmann 		if (spu_ret <= -ERESTARTSYS) {
2632dd14934SArnd Bergmann 			ret = spu_handle_restartsys(ctx, &spu_ret, &npc);
2642dd14934SArnd Bergmann 		}
2652dd14934SArnd Bergmann 		spu_acquire(ctx);
2662dd14934SArnd Bergmann 		if (ret == -ERESTARTSYS)
2672dd14934SArnd Bergmann 			return ret;
2682dd14934SArnd Bergmann 	}
2692dd14934SArnd Bergmann 
2702dd14934SArnd Bergmann 	/* write result, jump over indirect pointer */
2719e2fe2ceSAkinobu Mita 	memcpy_toio(ls + ls_pointer, &spu_ret, sizeof(spu_ret));
2722dd14934SArnd Bergmann 	ctx->ops->npc_write(ctx, npc);
2732dd14934SArnd Bergmann 	ctx->ops->runcntl_write(ctx, SPU_RUNCNTL_RUNNABLE);
2742dd14934SArnd Bergmann 	return ret;
2752dd14934SArnd Bergmann }
2762dd14934SArnd Bergmann 
277ce8ab854SArnd Bergmann static inline int spu_process_events(struct spu_context *ctx)
278ce8ab854SArnd Bergmann {
279ce8ab854SArnd Bergmann 	struct spu *spu = ctx->spu;
280ce8ab854SArnd Bergmann 	int ret = 0;
281ce8ab854SArnd Bergmann 
282ce8ab854SArnd Bergmann 	if (spu->class_0_pending)
283ce8ab854SArnd Bergmann 		ret = spu_irq_class_0_bottom(spu);
284ce8ab854SArnd Bergmann 	if (!ret && signal_pending(current))
285ce8ab854SArnd Bergmann 		ret = -ERESTARTSYS;
286ce8ab854SArnd Bergmann 	return ret;
287ce8ab854SArnd Bergmann }
288ce8ab854SArnd Bergmann 
289ce8ab854SArnd Bergmann long spufs_run_spu(struct file *file, struct spu_context *ctx,
2909add11daSArnd Bergmann 		   u32 *npc, u32 *event)
291ce8ab854SArnd Bergmann {
292ce8ab854SArnd Bergmann 	int ret;
2939add11daSArnd Bergmann 	u32 status;
294ce8ab854SArnd Bergmann 
295e45d48a3SChristoph Hellwig 	if (mutex_lock_interruptible(&ctx->run_mutex))
296ce8ab854SArnd Bergmann 		return -ERESTARTSYS;
297ce8ab854SArnd Bergmann 
298ee2d7340SArnd Bergmann 	ctx->ops->master_start(ctx);
2999add11daSArnd Bergmann 	ctx->event_return = 0;
300aa45e256SChristoph Hellwig 
301aa45e256SChristoph Hellwig 	ret = spu_acquire_runnable(ctx, 0);
302ce8ab854SArnd Bergmann 	if (ret)
303aa45e256SChristoph Hellwig 		return ret;
304aa45e256SChristoph Hellwig 
305aa45e256SChristoph Hellwig 	ret = spu_run_init(ctx, npc);
306aa45e256SChristoph Hellwig 	if (ret) {
307aa45e256SChristoph Hellwig 		spu_release(ctx);
308ce8ab854SArnd Bergmann 		goto out;
309aa45e256SChristoph Hellwig 	}
310ce8ab854SArnd Bergmann 
311ce8ab854SArnd Bergmann 	do {
3129add11daSArnd Bergmann 		ret = spufs_wait(ctx->stop_wq, spu_stopped(ctx, &status));
313ce8ab854SArnd Bergmann 		if (unlikely(ret))
314ce8ab854SArnd Bergmann 			break;
3159add11daSArnd Bergmann 		if ((status & SPU_STATUS_STOPPED_BY_STOP) &&
3169add11daSArnd Bergmann 		    (status >> SPU_STOP_STATUS_SHIFT == 0x2104)) {
3172dd14934SArnd Bergmann 			ret = spu_process_callback(ctx);
3182dd14934SArnd Bergmann 			if (ret)
3192dd14934SArnd Bergmann 				break;
3209add11daSArnd Bergmann 			status &= ~SPU_STATUS_STOPPED_BY_STOP;
3212dd14934SArnd Bergmann 		}
32257dace23SArnd Bergmann 		ret = spufs_handle_class1(ctx);
32357dace23SArnd Bergmann 		if (ret)
32457dace23SArnd Bergmann 			break;
32557dace23SArnd Bergmann 
326ce8ab854SArnd Bergmann 		if (unlikely(ctx->state != SPU_STATE_RUNNABLE)) {
3279add11daSArnd Bergmann 			ret = spu_reacquire_runnable(ctx, npc, &status);
3282eb1b120SChristoph Hellwig 			if (ret) {
3292eb1b120SChristoph Hellwig 				spu_stop_tick(ctx);
3302ebb2477SMasato Noguchi 				goto out2;
3312eb1b120SChristoph Hellwig 			}
332ce8ab854SArnd Bergmann 			continue;
333ce8ab854SArnd Bergmann 		}
334ce8ab854SArnd Bergmann 		ret = spu_process_events(ctx);
335ce8ab854SArnd Bergmann 
3369add11daSArnd Bergmann 	} while (!ret && !(status & (SPU_STATUS_STOPPED_BY_STOP |
337ce8ab854SArnd Bergmann 				      SPU_STATUS_STOPPED_BY_HALT)));
338ce8ab854SArnd Bergmann 
339ee2d7340SArnd Bergmann 	ctx->ops->master_stop(ctx);
3409add11daSArnd Bergmann 	ret = spu_run_fini(ctx, npc, &status);
341ce8ab854SArnd Bergmann 	spu_yield(ctx);
342ce8ab854SArnd Bergmann 
3432ebb2477SMasato Noguchi out2:
3442ebb2477SMasato Noguchi 	if ((ret == 0) ||
3452ebb2477SMasato Noguchi 	    ((ret == -ERESTARTSYS) &&
3462ebb2477SMasato Noguchi 	     ((status & SPU_STATUS_STOPPED_BY_HALT) ||
3472ebb2477SMasato Noguchi 	      ((status & SPU_STATUS_STOPPED_BY_STOP) &&
3482ebb2477SMasato Noguchi 	       (status >> SPU_STOP_STATUS_SHIFT != 0x2104)))))
3492ebb2477SMasato Noguchi 		ret = status;
3502ebb2477SMasato Noguchi 
3512ebb2477SMasato Noguchi 	if ((status & SPU_STATUS_STOPPED_BY_STOP)
3522ebb2477SMasato Noguchi 	    && (status >> SPU_STOP_STATUS_SHIFT) == 0x3fff) {
3532ebb2477SMasato Noguchi 		force_sig(SIGTRAP, current);
3542ebb2477SMasato Noguchi 		ret = -ERESTARTSYS;
3552ebb2477SMasato Noguchi 	}
3562ebb2477SMasato Noguchi 
357ce8ab854SArnd Bergmann out:
3589add11daSArnd Bergmann 	*event = ctx->event_return;
359e45d48a3SChristoph Hellwig 	mutex_unlock(&ctx->run_mutex);
360ce8ab854SArnd Bergmann 	return ret;
361ce8ab854SArnd Bergmann }
362